Commit 82d1ce3e authored by Antti Palosaari's avatar Antti Palosaari Committed by Mauro Carvalho Chehab

[media] af9013: add i2c client bindings

Add kernel i2c driver bindings.
That allows dev_* logging, regmap and more.
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent a4e2b6fe
...@@ -24,9 +24,8 @@ ...@@ -24,9 +24,8 @@
#define MAX_XFER_SIZE 64 #define MAX_XFER_SIZE 64
struct af9013_state { struct af9013_state {
struct i2c_adapter *i2c; struct i2c_client *client;
struct dvb_frontend fe; struct dvb_frontend fe;
u8 i2c_addr;
u32 clk; u32 clk;
u8 tuner; u8 tuner;
u32 if_frequency; u32 if_frequency;
...@@ -59,7 +58,7 @@ static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg, ...@@ -59,7 +58,7 @@ static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg,
u8 buf[MAX_XFER_SIZE]; u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[1] = { struct i2c_msg msg[1] = {
{ {
.addr = priv->i2c_addr, .addr = priv->client->addr,
.flags = 0, .flags = 0,
.len = 3 + len, .len = 3 + len,
.buf = buf, .buf = buf,
...@@ -67,7 +66,7 @@ static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg, ...@@ -67,7 +66,7 @@ static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg,
}; };
if (3 + len > sizeof(buf)) { if (3 + len > sizeof(buf)) {
dev_warn(&priv->i2c->dev, dev_warn(&priv->client->dev,
"%s: i2c wr reg=%04x: len=%d is too big!\n", "%s: i2c wr reg=%04x: len=%d is too big!\n",
KBUILD_MODNAME, reg, len); KBUILD_MODNAME, reg, len);
return -EINVAL; return -EINVAL;
...@@ -78,11 +77,11 @@ static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg, ...@@ -78,11 +77,11 @@ static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg,
buf[2] = mbox; buf[2] = mbox;
memcpy(&buf[3], val, len); memcpy(&buf[3], val, len);
ret = i2c_transfer(priv->i2c, msg, 1); ret = i2c_transfer(priv->client->adapter, msg, 1);
if (ret == 1) { if (ret == 1) {
ret = 0; ret = 0;
} else { } else {
dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%04x " \ dev_warn(&priv->client->dev, "%s: i2c wr failed=%d reg=%04x " \
"len=%d\n", KBUILD_MODNAME, ret, reg, len); "len=%d\n", KBUILD_MODNAME, ret, reg, len);
ret = -EREMOTEIO; ret = -EREMOTEIO;
} }
...@@ -97,12 +96,12 @@ static int af9013_rd_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg, ...@@ -97,12 +96,12 @@ static int af9013_rd_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg,
u8 buf[3]; u8 buf[3];
struct i2c_msg msg[2] = { struct i2c_msg msg[2] = {
{ {
.addr = priv->i2c_addr, .addr = priv->client->addr,
.flags = 0, .flags = 0,
.len = 3, .len = 3,
.buf = buf, .buf = buf,
}, { }, {
.addr = priv->i2c_addr, .addr = priv->client->addr,
.flags = I2C_M_RD, .flags = I2C_M_RD,
.len = len, .len = len,
.buf = val, .buf = val,
...@@ -113,11 +112,11 @@ static int af9013_rd_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg, ...@@ -113,11 +112,11 @@ static int af9013_rd_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg,
buf[1] = (reg >> 0) & 0xff; buf[1] = (reg >> 0) & 0xff;
buf[2] = mbox; buf[2] = mbox;
ret = i2c_transfer(priv->i2c, msg, 2); ret = i2c_transfer(priv->client->adapter, msg, 2);
if (ret == 2) { if (ret == 2) {
ret = 0; ret = 0;
} else { } else {
dev_warn(&priv->i2c->dev, "%s: i2c rd failed=%d reg=%04x " \ dev_warn(&priv->client->dev, "%s: i2c rd failed=%d reg=%04x " \
"len=%d\n", KBUILD_MODNAME, ret, reg, len); "len=%d\n", KBUILD_MODNAME, ret, reg, len);
ret = -EREMOTEIO; ret = -EREMOTEIO;
} }
...@@ -231,7 +230,7 @@ static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval) ...@@ -231,7 +230,7 @@ static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval)
u8 pos; u8 pos;
u16 addr; u16 addr;
dev_dbg(&state->i2c->dev, "%s: gpio=%d gpioval=%02x\n", dev_dbg(&state->client->dev, "%s: gpio=%d gpioval=%02x\n",
__func__, gpio, gpioval); __func__, gpio, gpioval);
/* /*
...@@ -250,7 +249,7 @@ static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval) ...@@ -250,7 +249,7 @@ static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval)
break; break;
default: default:
dev_err(&state->i2c->dev, "%s: invalid gpio=%d\n", dev_err(&state->client->dev, "%s: invalid gpio=%d\n",
KBUILD_MODNAME, gpio); KBUILD_MODNAME, gpio);
ret = -EINVAL; ret = -EINVAL;
goto err; goto err;
...@@ -274,7 +273,7 @@ static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval) ...@@ -274,7 +273,7 @@ static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -282,7 +281,7 @@ static u32 af9013_div(struct af9013_state *state, u32 a, u32 b, u32 x) ...@@ -282,7 +281,7 @@ static u32 af9013_div(struct af9013_state *state, u32 a, u32 b, u32 x)
{ {
u32 r = 0, c = 0, i; u32 r = 0, c = 0, i;
dev_dbg(&state->i2c->dev, "%s: a=%d b=%d x=%d\n", __func__, a, b, x); dev_dbg(&state->client->dev, "%s: a=%d b=%d x=%d\n", __func__, a, b, x);
if (a > b) { if (a > b) {
c = a / b; c = a / b;
...@@ -299,7 +298,7 @@ static u32 af9013_div(struct af9013_state *state, u32 a, u32 b, u32 x) ...@@ -299,7 +298,7 @@ static u32 af9013_div(struct af9013_state *state, u32 a, u32 b, u32 x)
} }
r = (c << (u32)x) + r; r = (c << (u32)x) + r;
dev_dbg(&state->i2c->dev, "%s: a=%d b=%d x=%d r=%d r=%x\n", dev_dbg(&state->client->dev, "%s: a=%d b=%d x=%d r=%d r=%x\n",
__func__, a, b, x, r, r); __func__, a, b, x, r, r);
return r; return r;
...@@ -310,7 +309,7 @@ static int af9013_power_ctrl(struct af9013_state *state, u8 onoff) ...@@ -310,7 +309,7 @@ static int af9013_power_ctrl(struct af9013_state *state, u8 onoff)
int ret, i; int ret, i;
u8 tmp; u8 tmp;
dev_dbg(&state->i2c->dev, "%s: onoff=%d\n", __func__, onoff); dev_dbg(&state->client->dev, "%s: onoff=%d\n", __func__, onoff);
/* enable reset */ /* enable reset */
ret = af9013_wr_reg_bits(state, 0xd417, 4, 1, 1); ret = af9013_wr_reg_bits(state, 0xd417, 4, 1, 1);
...@@ -355,7 +354,7 @@ static int af9013_power_ctrl(struct af9013_state *state, u8 onoff) ...@@ -355,7 +354,7 @@ static int af9013_power_ctrl(struct af9013_state *state, u8 onoff)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -364,7 +363,7 @@ static int af9013_statistics_ber_unc_start(struct dvb_frontend *fe) ...@@ -364,7 +363,7 @@ static int af9013_statistics_ber_unc_start(struct dvb_frontend *fe)
struct af9013_state *state = fe->demodulator_priv; struct af9013_state *state = fe->demodulator_priv;
int ret; int ret;
dev_dbg(&state->i2c->dev, "%s:\n", __func__); dev_dbg(&state->client->dev, "%s:\n", __func__);
/* reset and start BER counter */ /* reset and start BER counter */
ret = af9013_wr_reg_bits(state, 0xd391, 4, 1, 1); ret = af9013_wr_reg_bits(state, 0xd391, 4, 1, 1);
...@@ -373,7 +372,7 @@ static int af9013_statistics_ber_unc_start(struct dvb_frontend *fe) ...@@ -373,7 +372,7 @@ static int af9013_statistics_ber_unc_start(struct dvb_frontend *fe)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -383,7 +382,7 @@ static int af9013_statistics_ber_unc_result(struct dvb_frontend *fe) ...@@ -383,7 +382,7 @@ static int af9013_statistics_ber_unc_result(struct dvb_frontend *fe)
int ret; int ret;
u8 buf[5]; u8 buf[5];
dev_dbg(&state->i2c->dev, "%s:\n", __func__); dev_dbg(&state->client->dev, "%s:\n", __func__);
/* check if error bit count is ready */ /* check if error bit count is ready */
ret = af9013_rd_reg_bits(state, 0xd391, 4, 1, &buf[0]); ret = af9013_rd_reg_bits(state, 0xd391, 4, 1, &buf[0]);
...@@ -391,7 +390,7 @@ static int af9013_statistics_ber_unc_result(struct dvb_frontend *fe) ...@@ -391,7 +390,7 @@ static int af9013_statistics_ber_unc_result(struct dvb_frontend *fe)
goto err; goto err;
if (!buf[0]) { if (!buf[0]) {
dev_dbg(&state->i2c->dev, "%s: not ready\n", __func__); dev_dbg(&state->client->dev, "%s: not ready\n", __func__);
return 0; return 0;
} }
...@@ -404,7 +403,7 @@ static int af9013_statistics_ber_unc_result(struct dvb_frontend *fe) ...@@ -404,7 +403,7 @@ static int af9013_statistics_ber_unc_result(struct dvb_frontend *fe)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -413,7 +412,7 @@ static int af9013_statistics_snr_start(struct dvb_frontend *fe) ...@@ -413,7 +412,7 @@ static int af9013_statistics_snr_start(struct dvb_frontend *fe)
struct af9013_state *state = fe->demodulator_priv; struct af9013_state *state = fe->demodulator_priv;
int ret; int ret;
dev_dbg(&state->i2c->dev, "%s:\n", __func__); dev_dbg(&state->client->dev, "%s:\n", __func__);
/* start SNR meas */ /* start SNR meas */
ret = af9013_wr_reg_bits(state, 0xd2e1, 3, 1, 1); ret = af9013_wr_reg_bits(state, 0xd2e1, 3, 1, 1);
...@@ -422,7 +421,7 @@ static int af9013_statistics_snr_start(struct dvb_frontend *fe) ...@@ -422,7 +421,7 @@ static int af9013_statistics_snr_start(struct dvb_frontend *fe)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -434,7 +433,7 @@ static int af9013_statistics_snr_result(struct dvb_frontend *fe) ...@@ -434,7 +433,7 @@ static int af9013_statistics_snr_result(struct dvb_frontend *fe)
u32 snr_val; u32 snr_val;
const struct af9013_snr *uninitialized_var(snr_lut); const struct af9013_snr *uninitialized_var(snr_lut);
dev_dbg(&state->i2c->dev, "%s:\n", __func__); dev_dbg(&state->client->dev, "%s:\n", __func__);
/* check if SNR ready */ /* check if SNR ready */
ret = af9013_rd_reg_bits(state, 0xd2e1, 3, 1, &tmp); ret = af9013_rd_reg_bits(state, 0xd2e1, 3, 1, &tmp);
...@@ -442,7 +441,7 @@ static int af9013_statistics_snr_result(struct dvb_frontend *fe) ...@@ -442,7 +441,7 @@ static int af9013_statistics_snr_result(struct dvb_frontend *fe)
goto err; goto err;
if (!tmp) { if (!tmp) {
dev_dbg(&state->i2c->dev, "%s: not ready\n", __func__); dev_dbg(&state->client->dev, "%s: not ready\n", __func__);
return 0; return 0;
} }
...@@ -485,7 +484,7 @@ static int af9013_statistics_snr_result(struct dvb_frontend *fe) ...@@ -485,7 +484,7 @@ static int af9013_statistics_snr_result(struct dvb_frontend *fe)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -496,7 +495,7 @@ static int af9013_statistics_signal_strength(struct dvb_frontend *fe) ...@@ -496,7 +495,7 @@ static int af9013_statistics_signal_strength(struct dvb_frontend *fe)
u8 buf[2], rf_gain, if_gain; u8 buf[2], rf_gain, if_gain;
int signal_strength; int signal_strength;
dev_dbg(&state->i2c->dev, "%s:\n", __func__); dev_dbg(&state->client->dev, "%s:\n", __func__);
if (!state->signal_strength_en) if (!state->signal_strength_en)
return 0; return 0;
...@@ -522,7 +521,7 @@ static int af9013_statistics_signal_strength(struct dvb_frontend *fe) ...@@ -522,7 +521,7 @@ static int af9013_statistics_signal_strength(struct dvb_frontend *fe)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -593,7 +592,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -593,7 +592,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
u8 buf[6]; u8 buf[6];
u32 if_frequency, freq_cw; u32 if_frequency, freq_cw;
dev_dbg(&state->i2c->dev, "%s: frequency=%d bandwidth_hz=%d\n", dev_dbg(&state->client->dev, "%s: frequency=%d bandwidth_hz=%d\n",
__func__, c->frequency, c->bandwidth_hz); __func__, c->frequency, c->bandwidth_hz);
/* program tuner */ /* program tuner */
...@@ -627,7 +626,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -627,7 +626,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
else else
if_frequency = state->if_frequency; if_frequency = state->if_frequency;
dev_dbg(&state->i2c->dev, "%s: if_frequency=%d\n", dev_dbg(&state->client->dev, "%s: if_frequency=%d\n",
__func__, if_frequency); __func__, if_frequency);
sampling_freq = if_frequency; sampling_freq = if_frequency;
...@@ -701,7 +700,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -701,7 +700,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
buf[0] |= (1 << 0); buf[0] |= (1 << 0);
break; break;
default: default:
dev_dbg(&state->i2c->dev, "%s: invalid transmission_mode\n", dev_dbg(&state->client->dev, "%s: invalid transmission_mode\n",
__func__); __func__);
auto_mode = true; auto_mode = true;
} }
...@@ -722,7 +721,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -722,7 +721,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
buf[0] |= (3 << 2); buf[0] |= (3 << 2);
break; break;
default: default:
dev_dbg(&state->i2c->dev, "%s: invalid guard_interval\n", dev_dbg(&state->client->dev, "%s: invalid guard_interval\n",
__func__); __func__);
auto_mode = true; auto_mode = true;
} }
...@@ -743,7 +742,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -743,7 +742,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
buf[0] |= (3 << 4); buf[0] |= (3 << 4);
break; break;
default: default:
dev_dbg(&state->i2c->dev, "%s: invalid hierarchy\n", __func__); dev_dbg(&state->client->dev, "%s: invalid hierarchy\n", __func__);
auto_mode = true; auto_mode = true;
} }
...@@ -760,7 +759,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -760,7 +759,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
buf[1] |= (2 << 6); buf[1] |= (2 << 6);
break; break;
default: default:
dev_dbg(&state->i2c->dev, "%s: invalid modulation\n", __func__); dev_dbg(&state->client->dev, "%s: invalid modulation\n", __func__);
auto_mode = true; auto_mode = true;
} }
...@@ -786,7 +785,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -786,7 +785,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
buf[2] |= (4 << 0); buf[2] |= (4 << 0);
break; break;
default: default:
dev_dbg(&state->i2c->dev, "%s: invalid code_rate_HP\n", dev_dbg(&state->client->dev, "%s: invalid code_rate_HP\n",
__func__); __func__);
auto_mode = true; auto_mode = true;
} }
...@@ -812,7 +811,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -812,7 +811,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
case FEC_NONE: case FEC_NONE:
break; break;
default: default:
dev_dbg(&state->i2c->dev, "%s: invalid code_rate_LP\n", dev_dbg(&state->client->dev, "%s: invalid code_rate_LP\n",
__func__); __func__);
auto_mode = true; auto_mode = true;
} }
...@@ -827,7 +826,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -827,7 +826,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
buf[1] |= (2 << 2); buf[1] |= (2 << 2);
break; break;
default: default:
dev_dbg(&state->i2c->dev, "%s: invalid bandwidth_hz\n", dev_dbg(&state->client->dev, "%s: invalid bandwidth_hz\n",
__func__); __func__);
ret = -EINVAL; ret = -EINVAL;
goto err; goto err;
...@@ -843,7 +842,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -843,7 +842,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
if (ret) if (ret)
goto err; goto err;
dev_dbg(&state->i2c->dev, "%s: auto params\n", __func__); dev_dbg(&state->client->dev, "%s: auto params\n", __func__);
} else { } else {
/* set easy mode flag */ /* set easy mode flag */
ret = af9013_wr_reg(state, 0xaefd, 1); ret = af9013_wr_reg(state, 0xaefd, 1);
...@@ -854,7 +853,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -854,7 +853,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
if (ret) if (ret)
goto err; goto err;
dev_dbg(&state->i2c->dev, "%s: manual params\n", __func__); dev_dbg(&state->client->dev, "%s: manual params\n", __func__);
} }
/* tune */ /* tune */
...@@ -868,7 +867,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -868,7 +867,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -879,7 +878,7 @@ static int af9013_get_frontend(struct dvb_frontend *fe, ...@@ -879,7 +878,7 @@ static int af9013_get_frontend(struct dvb_frontend *fe,
int ret; int ret;
u8 buf[3]; u8 buf[3];
dev_dbg(&state->i2c->dev, "%s:\n", __func__); dev_dbg(&state->client->dev, "%s:\n", __func__);
ret = af9013_rd_regs(state, 0xd3c0, buf, 3); ret = af9013_rd_regs(state, 0xd3c0, buf, 3);
if (ret) if (ret)
...@@ -985,7 +984,7 @@ static int af9013_get_frontend(struct dvb_frontend *fe, ...@@ -985,7 +984,7 @@ static int af9013_get_frontend(struct dvb_frontend *fe,
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -1035,7 +1034,7 @@ static int af9013_read_status(struct dvb_frontend *fe, enum fe_status *status) ...@@ -1035,7 +1034,7 @@ static int af9013_read_status(struct dvb_frontend *fe, enum fe_status *status)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -1075,7 +1074,7 @@ static int af9013_init(struct dvb_frontend *fe) ...@@ -1075,7 +1074,7 @@ static int af9013_init(struct dvb_frontend *fe)
u32 adc_cw; u32 adc_cw;
const struct af9013_reg_bit *init; const struct af9013_reg_bit *init;
dev_dbg(&state->i2c->dev, "%s:\n", __func__); dev_dbg(&state->client->dev, "%s:\n", __func__);
/* power on */ /* power on */
ret = af9013_power_ctrl(state, 1); ret = af9013_power_ctrl(state, 1);
...@@ -1107,7 +1106,7 @@ static int af9013_init(struct dvb_frontend *fe) ...@@ -1107,7 +1106,7 @@ static int af9013_init(struct dvb_frontend *fe)
tmp = 3; tmp = 3;
break; break;
default: default:
dev_err(&state->i2c->dev, "%s: invalid clock\n", dev_err(&state->client->dev, "%s: invalid clock\n",
KBUILD_MODNAME); KBUILD_MODNAME);
return -EINVAL; return -EINVAL;
} }
...@@ -1168,7 +1167,7 @@ static int af9013_init(struct dvb_frontend *fe) ...@@ -1168,7 +1167,7 @@ static int af9013_init(struct dvb_frontend *fe)
goto err; goto err;
/* load OFSM settings */ /* load OFSM settings */
dev_dbg(&state->i2c->dev, "%s: load ofsm settings\n", __func__); dev_dbg(&state->client->dev, "%s: load ofsm settings\n", __func__);
len = ARRAY_SIZE(ofsm_init); len = ARRAY_SIZE(ofsm_init);
init = ofsm_init; init = ofsm_init;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
...@@ -1179,7 +1178,7 @@ static int af9013_init(struct dvb_frontend *fe) ...@@ -1179,7 +1178,7 @@ static int af9013_init(struct dvb_frontend *fe)
} }
/* load tuner specific settings */ /* load tuner specific settings */
dev_dbg(&state->i2c->dev, "%s: load tuner specific settings\n", dev_dbg(&state->client->dev, "%s: load tuner specific settings\n",
__func__); __func__);
switch (state->tuner) { switch (state->tuner) {
case AF9013_TUNER_MXL5003D: case AF9013_TUNER_MXL5003D:
...@@ -1291,7 +1290,7 @@ static int af9013_init(struct dvb_frontend *fe) ...@@ -1291,7 +1290,7 @@ static int af9013_init(struct dvb_frontend *fe)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -1300,7 +1299,7 @@ static int af9013_sleep(struct dvb_frontend *fe) ...@@ -1300,7 +1299,7 @@ static int af9013_sleep(struct dvb_frontend *fe)
struct af9013_state *state = fe->demodulator_priv; struct af9013_state *state = fe->demodulator_priv;
int ret; int ret;
dev_dbg(&state->i2c->dev, "%s:\n", __func__); dev_dbg(&state->client->dev, "%s:\n", __func__);
/* stop statistics polling */ /* stop statistics polling */
cancel_delayed_work_sync(&state->statistics_work); cancel_delayed_work_sync(&state->statistics_work);
...@@ -1317,7 +1316,7 @@ static int af9013_sleep(struct dvb_frontend *fe) ...@@ -1317,7 +1316,7 @@ static int af9013_sleep(struct dvb_frontend *fe)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
...@@ -1326,7 +1325,7 @@ static int af9013_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) ...@@ -1326,7 +1325,7 @@ static int af9013_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
int ret; int ret;
struct af9013_state *state = fe->demodulator_priv; struct af9013_state *state = fe->demodulator_priv;
dev_dbg(&state->i2c->dev, "%s: enable=%d\n", __func__, enable); dev_dbg(&state->client->dev, "%s: enable=%d\n", __func__, enable);
/* gate already open or close */ /* gate already open or close */
if (state->i2c_gate_state == enable) if (state->i2c_gate_state == enable)
...@@ -1343,18 +1342,16 @@ static int af9013_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) ...@@ -1343,18 +1342,16 @@ static int af9013_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
return ret; return ret;
err: err:
dev_dbg(&state->i2c->dev, "%s: failed=%d\n", __func__, ret); dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
return ret; return ret;
} }
static void af9013_release(struct dvb_frontend *fe) static void af9013_release(struct dvb_frontend *fe)
{ {
struct af9013_state *state = fe->demodulator_priv; struct af9013_state *state = fe->demodulator_priv;
struct i2c_client *client = state->client;
/* stop statistics polling */ i2c_unregister_device(client);
cancel_delayed_work_sync(&state->statistics_work);
kfree(state);
} }
static const struct dvb_frontend_ops af9013_ops; static const struct dvb_frontend_ops af9013_ops;
...@@ -1374,27 +1371,27 @@ static int af9013_download_firmware(struct af9013_state *state) ...@@ -1374,27 +1371,27 @@ static int af9013_download_firmware(struct af9013_state *state)
if (ret) if (ret)
goto err; goto err;
else else
dev_dbg(&state->i2c->dev, "%s: firmware status=%02x\n", dev_dbg(&state->client->dev, "%s: firmware status=%02x\n",
__func__, val); __func__, val);
if (val == 0x0c) /* fw is running, no need for download */ if (val == 0x0c) /* fw is running, no need for download */
goto exit; goto exit;
dev_info(&state->i2c->dev, "%s: found a '%s' in cold state, will try " \ dev_info(&state->client->dev, "%s: found a '%s' in cold state, will try " \
"to load a firmware\n", "to load a firmware\n",
KBUILD_MODNAME, af9013_ops.info.name); KBUILD_MODNAME, af9013_ops.info.name);
/* request the firmware, this will block and timeout */ /* request the firmware, this will block and timeout */
ret = request_firmware(&fw, fw_file, state->i2c->dev.parent); ret = request_firmware(&fw, fw_file, &state->client->dev);
if (ret) { if (ret) {
dev_info(&state->i2c->dev, "%s: did not find the firmware " \ dev_info(&state->client->dev, "%s: did not find the firmware " \
"file. (%s) Please see linux/Documentation/dvb/ for " \ "file. (%s) Please see linux/Documentation/dvb/ for " \
"more details on firmware-problems. (%d)\n", "more details on firmware-problems. (%d)\n",
KBUILD_MODNAME, fw_file, ret); KBUILD_MODNAME, fw_file, ret);
goto err; goto err;
} }
dev_info(&state->i2c->dev, "%s: downloading firmware from file '%s'\n", dev_info(&state->client->dev, "%s: downloading firmware from file '%s'\n",
KBUILD_MODNAME, fw_file); KBUILD_MODNAME, fw_file);
/* calc checksum */ /* calc checksum */
...@@ -1423,7 +1420,7 @@ static int af9013_download_firmware(struct af9013_state *state) ...@@ -1423,7 +1420,7 @@ static int af9013_download_firmware(struct af9013_state *state)
FW_ADDR + fw->size - remaining, FW_ADDR + fw->size - remaining,
(u8 *) &fw->data[fw->size - remaining], len); (u8 *) &fw->data[fw->size - remaining], len);
if (ret) { if (ret) {
dev_err(&state->i2c->dev, dev_err(&state->client->dev,
"%s: firmware download failed=%d\n", "%s: firmware download failed=%d\n",
KBUILD_MODNAME, ret); KBUILD_MODNAME, ret);
goto err_release; goto err_release;
...@@ -1443,7 +1440,7 @@ static int af9013_download_firmware(struct af9013_state *state) ...@@ -1443,7 +1440,7 @@ static int af9013_download_firmware(struct af9013_state *state)
if (ret) if (ret)
goto err_release; goto err_release;
dev_dbg(&state->i2c->dev, "%s: firmware status=%02x\n", dev_dbg(&state->client->dev, "%s: firmware status=%02x\n",
__func__, val); __func__, val);
if (val == 0x0c || val == 0x04) /* success or fail */ if (val == 0x0c || val == 0x04) /* success or fail */
...@@ -1451,11 +1448,11 @@ static int af9013_download_firmware(struct af9013_state *state) ...@@ -1451,11 +1448,11 @@ static int af9013_download_firmware(struct af9013_state *state)
} }
if (val == 0x04) { if (val == 0x04) {
dev_err(&state->i2c->dev, "%s: firmware did not run\n", dev_err(&state->client->dev, "%s: firmware did not run\n",
KBUILD_MODNAME); KBUILD_MODNAME);
ret = -ENODEV; ret = -ENODEV;
} else if (val != 0x0c) { } else if (val != 0x0c) {
dev_err(&state->i2c->dev, "%s: firmware boot timeout\n", dev_err(&state->client->dev, "%s: firmware boot timeout\n",
KBUILD_MODNAME); KBUILD_MODNAME);
ret = -ENODEV; ret = -ENODEV;
} }
...@@ -1465,67 +1462,41 @@ static int af9013_download_firmware(struct af9013_state *state) ...@@ -1465,67 +1462,41 @@ static int af9013_download_firmware(struct af9013_state *state)
err: err:
exit: exit:
if (!ret) if (!ret)
dev_info(&state->i2c->dev, "%s: found a '%s' in warm state\n", dev_info(&state->client->dev, "%s: found a '%s' in warm state\n",
KBUILD_MODNAME, af9013_ops.info.name); KBUILD_MODNAME, af9013_ops.info.name);
return ret; return ret;
} }
/*
* XXX: That is wrapper to af9013_probe() via driver core in order to provide
* proper I2C client for legacy media attach binding.
* New users must use I2C client binding directly!
*/
struct dvb_frontend *af9013_attach(const struct af9013_config *config, struct dvb_frontend *af9013_attach(const struct af9013_config *config,
struct i2c_adapter *i2c) struct i2c_adapter *i2c)
{ {
int ret; struct i2c_client *client;
struct af9013_state *state = NULL; struct i2c_board_info board_info;
u8 buf[4], i; struct af9013_platform_data pdata;
/* allocate memory for the internal state */ pdata.clk = config->clock;
state = kzalloc(sizeof(struct af9013_state), GFP_KERNEL); pdata.tuner = config->tuner;
if (state == NULL) pdata.if_frequency = config->if_frequency;
goto err; pdata.ts_mode = config->ts_mode;
pdata.spec_inv = config->spec_inv;
/* setup the state */ memcpy(&pdata.api_version, config->api_version, sizeof(pdata.api_version));
state->i2c = i2c; memcpy(&pdata.gpio, config->gpio, sizeof(pdata.gpio));
state->i2c_addr = config->i2c_addr; pdata.attach_in_use = true;
state->clk = config->clock;
state->tuner = config->tuner; memset(&board_info, 0, sizeof(board_info));
state->if_frequency = config->if_frequency; strlcpy(board_info.type, "af9013", sizeof(board_info.type));
state->ts_mode = config->ts_mode; board_info.addr = config->i2c_addr;
state->spec_inv = config->spec_inv; board_info.platform_data = &pdata;
memcpy(&state->api_version, config->api_version, sizeof(state->api_version)); client = i2c_new_device(i2c, &board_info);
memcpy(&state->gpio, config->gpio, sizeof(state->gpio)); if (!client || !client->dev.driver)
/* download firmware */
if (state->ts_mode != AF9013_TS_USB) {
ret = af9013_download_firmware(state);
if (ret)
goto err;
}
/* firmware version */
ret = af9013_rd_regs(state, 0x5103, buf, 4);
if (ret)
goto err;
dev_info(&state->i2c->dev, "%s: firmware version %d.%d.%d.%d\n",
KBUILD_MODNAME, buf[0], buf[1], buf[2], buf[3]);
/* set GPIOs */
for (i = 0; i < sizeof(state->gpio); i++) {
ret = af9013_set_gpio(state, i, state->gpio[i]);
if (ret)
goto err;
}
/* create dvb_frontend */
memcpy(&state->fe.ops, &af9013_ops,
sizeof(struct dvb_frontend_ops));
state->fe.demodulator_priv = state;
INIT_DELAYED_WORK(&state->statistics_work, af9013_statistics_work);
return &state->fe;
err:
kfree(state);
return NULL; return NULL;
return pdata.get_dvb_frontend(client);
} }
EXPORT_SYMBOL(af9013_attach); EXPORT_SYMBOL(af9013_attach);
...@@ -1572,6 +1543,114 @@ static const struct dvb_frontend_ops af9013_ops = { ...@@ -1572,6 +1543,114 @@ static const struct dvb_frontend_ops af9013_ops = {
.i2c_gate_ctrl = af9013_i2c_gate_ctrl, .i2c_gate_ctrl = af9013_i2c_gate_ctrl,
}; };
static struct dvb_frontend *af9013_get_dvb_frontend(struct i2c_client *client)
{
struct af9013_state *state = i2c_get_clientdata(client);
dev_dbg(&client->dev, "\n");
return &state->fe;
}
static int af9013_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct af9013_state *state;
struct af9013_platform_data *pdata = client->dev.platform_data;
int ret, i;
u8 firmware_version[4];
state = kzalloc(sizeof(*state), GFP_KERNEL);
if (!state) {
ret = -ENOMEM;
goto err;
}
/* Setup the state */
state->client = client;
i2c_set_clientdata(client, state);
state->clk = pdata->clk;
state->tuner = pdata->tuner;
state->if_frequency = pdata->if_frequency;
state->ts_mode = pdata->ts_mode;
state->spec_inv = pdata->spec_inv;
memcpy(&state->api_version, pdata->api_version, sizeof(state->api_version));
memcpy(&state->gpio, pdata->gpio, sizeof(state->gpio));
INIT_DELAYED_WORK(&state->statistics_work, af9013_statistics_work);
/* Download firmware */
if (state->ts_mode != AF9013_TS_USB) {
ret = af9013_download_firmware(state);
if (ret)
goto err_kfree;
}
/* Firmware version */
ret = af9013_rd_regs(state, 0x5103, firmware_version,
sizeof(firmware_version));
if (ret)
goto err_kfree;
/* Set GPIOs */
for (i = 0; i < sizeof(state->gpio); i++) {
ret = af9013_set_gpio(state, i, state->gpio[i]);
if (ret)
goto err_kfree;
}
/* Create dvb frontend */
memcpy(&state->fe.ops, &af9013_ops, sizeof(state->fe.ops));
if (!pdata->attach_in_use)
state->fe.ops.release = NULL;
state->fe.demodulator_priv = state;
/* Setup callbacks */
pdata->get_dvb_frontend = af9013_get_dvb_frontend;
dev_info(&client->dev, "Afatech AF9013 successfully attached\n");
dev_info(&client->dev, "firmware version: %d.%d.%d.%d\n",
firmware_version[0], firmware_version[1],
firmware_version[2], firmware_version[3]);
return 0;
err_kfree:
kfree(state);
err:
dev_dbg(&client->dev, "failed %d\n", ret);
return ret;
}
static int af9013_remove(struct i2c_client *client)
{
struct af9013_state *state = i2c_get_clientdata(client);
dev_dbg(&client->dev, "\n");
/* Stop statistics polling */
cancel_delayed_work_sync(&state->statistics_work);
kfree(state);
return 0;
}
static const struct i2c_device_id af9013_id_table[] = {
{"af9013", 0},
{}
};
MODULE_DEVICE_TABLE(i2c, af9013_id_table);
static struct i2c_driver af9013_driver = {
.driver = {
.name = "af9013",
.suppress_bind_attrs = true,
},
.probe = af9013_probe,
.remove = af9013_remove,
.id_table = af9013_id_table,
};
module_i2c_driver(af9013_driver);
MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
MODULE_DESCRIPTION("Afatech AF9013 DVB-T demodulator driver"); MODULE_DESCRIPTION("Afatech AF9013 DVB-T demodulator driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
...@@ -23,29 +23,26 @@ ...@@ -23,29 +23,26 @@
#include <linux/dvb/frontend.h> #include <linux/dvb/frontend.h>
/* AF9013/5 GPIOs (mostly guessed) /*
demod#1-gpio#0 - set demod#2 i2c-addr for dual devices * I2C address: 0x1c, 0x1d
demod#1-gpio#1 - xtal setting (?)
demod#1-gpio#3 - tuner#1
demod#2-gpio#0 - tuner#2
demod#2-gpio#1 - xtal setting (?)
*/
struct af9013_config {
/*
* I2C address
*/ */
u8 i2c_addr;
/* /**
* clock * struct af9013_platform_data - Platform data for the af9013 driver
* 20480000, 25000000, 28000000, 28800000 * @clk: Clock frequency.
* @tuner: Used tuner model.
* @if_frequency: IF frequency.
* @ts_mode: TS mode.
* @spec_inv: Input spectrum inverted.
* @api_version: Firmware API version.
* @gpio: GPIOs.
* @get_dvb_frontend: Get DVB frontend callback.
*/ */
u32 clock; struct af9013_platform_data {
/* /*
* tuner * 20480000, 25000000, 28000000, 28800000
*/ */
u32 clk;
#define AF9013_TUNER_MXL5003D 3 /* MaxLinear */ #define AF9013_TUNER_MXL5003D 3 /* MaxLinear */
#define AF9013_TUNER_MXL5005D 13 /* MaxLinear */ #define AF9013_TUNER_MXL5005D 13 /* MaxLinear */
#define AF9013_TUNER_MXL5005R 30 /* MaxLinear */ #define AF9013_TUNER_MXL5005R 30 /* MaxLinear */
...@@ -60,33 +57,13 @@ struct af9013_config { ...@@ -60,33 +57,13 @@ struct af9013_config {
#define AF9013_TUNER_MXL5007T 177 /* MaxLinear */ #define AF9013_TUNER_MXL5007T 177 /* MaxLinear */
#define AF9013_TUNER_TDA18218 179 /* NXP */ #define AF9013_TUNER_TDA18218 179 /* NXP */
u8 tuner; u8 tuner;
/*
* IF frequency
*/
u32 if_frequency; u32 if_frequency;
#define AF9013_TS_MODE_USB 0
/* #define AF9013_TS_MODE_PARALLEL 1
* TS settings #define AF9013_TS_MODE_SERIAL 2
*/ u8 ts_mode;
#define AF9013_TS_USB 0
#define AF9013_TS_PARALLEL 1
#define AF9013_TS_SERIAL 2
u8 ts_mode:2;
/*
* input spectrum inversion
*/
bool spec_inv; bool spec_inv;
/*
* firmware API version
*/
u8 api_version[4]; u8 api_version[4];
/*
* GPIOs
*/
#define AF9013_GPIO_ON (1 << 0) #define AF9013_GPIO_ON (1 << 0)
#define AF9013_GPIO_EN (1 << 1) #define AF9013_GPIO_EN (1 << 1)
#define AF9013_GPIO_O (1 << 2) #define AF9013_GPIO_O (1 << 2)
...@@ -96,8 +73,29 @@ struct af9013_config { ...@@ -96,8 +73,29 @@ struct af9013_config {
#define AF9013_GPIO_TUNER_ON (AF9013_GPIO_ON|AF9013_GPIO_EN) #define AF9013_GPIO_TUNER_ON (AF9013_GPIO_ON|AF9013_GPIO_EN)
#define AF9013_GPIO_TUNER_OFF (AF9013_GPIO_ON|AF9013_GPIO_EN|AF9013_GPIO_O) #define AF9013_GPIO_TUNER_OFF (AF9013_GPIO_ON|AF9013_GPIO_EN|AF9013_GPIO_O)
u8 gpio[4]; u8 gpio[4];
struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
/* private: For legacy media attach wrapper. Do not set value. */
bool attach_in_use;
u8 i2c_addr;
u32 clock;
}; };
#define af9013_config af9013_platform_data
#define AF9013_TS_USB AF9013_TS_MODE_USB
#define AF9013_TS_PARALLEL AF9013_TS_MODE_PARALLEL
#define AF9013_TS_SERIAL AF9013_TS_MODE_SERIAL
/*
* AF9013/5 GPIOs (mostly guessed)
* demod#1-gpio#0 - set demod#2 i2c-addr for dual devices
* demod#1-gpio#1 - xtal setting (?)
* demod#1-gpio#3 - tuner#1
* demod#2-gpio#0 - tuner#2
* demod#2-gpio#1 - xtal setting (?)
*/
#if IS_REACHABLE(CONFIG_DVB_AF9013) #if IS_REACHABLE(CONFIG_DVB_AF9013)
extern struct dvb_frontend *af9013_attach(const struct af9013_config *config, extern struct dvb_frontend *af9013_attach(const struct af9013_config *config,
struct i2c_adapter *i2c); struct i2c_adapter *i2c);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment