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

[media] af9013: move config values directly under driver state

It shorten, as typed chars, access to config values as there is one
pointer less. Also, when config/platform data is passed to driver there
could be some values that are not relevant to store state as such or
not needed to store at all.
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 5ded0eb7
...@@ -26,7 +26,14 @@ ...@@ -26,7 +26,14 @@
struct af9013_state { struct af9013_state {
struct i2c_adapter *i2c; struct i2c_adapter *i2c;
struct dvb_frontend fe; struct dvb_frontend fe;
struct af9013_config config; u8 i2c_addr;
u32 clk;
u8 tuner;
u32 if_frequency;
u8 ts_mode;
bool spec_inv;
u8 api_version[4];
u8 gpio[4];
/* tuner/demod RF and IF AGC limits used for signal strength calc */ /* tuner/demod RF and IF AGC limits used for signal strength calc */
u8 signal_strength_en, rf_50, rf_80, if_50, if_80; u8 signal_strength_en, rf_50, rf_80, if_50, if_80;
...@@ -52,7 +59,7 @@ static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg, ...@@ -52,7 +59,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->config.i2c_addr, .addr = priv->i2c_addr,
.flags = 0, .flags = 0,
.len = 3 + len, .len = 3 + len,
.buf = buf, .buf = buf,
...@@ -90,12 +97,12 @@ static int af9013_rd_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg, ...@@ -90,12 +97,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->config.i2c_addr, .addr = priv->i2c_addr,
.flags = 0, .flags = 0,
.len = 3, .len = 3,
.buf = buf, .buf = buf,
}, { }, {
.addr = priv->config.i2c_addr, .addr = priv->i2c_addr,
.flags = I2C_M_RD, .flags = I2C_M_RD,
.len = len, .len = len,
.buf = val, .buf = val,
...@@ -124,7 +131,7 @@ static int af9013_wr_regs(struct af9013_state *priv, u16 reg, const u8 *val, ...@@ -124,7 +131,7 @@ static int af9013_wr_regs(struct af9013_state *priv, u16 reg, const u8 *val,
int ret, i; int ret, i;
u8 mbox = (0 << 7)|(0 << 6)|(1 << 1)|(1 << 0); u8 mbox = (0 << 7)|(0 << 6)|(1 << 1)|(1 << 0);
if ((priv->config.ts_mode == AF9013_TS_USB) && if ((priv->ts_mode == AF9013_TS_USB) &&
((reg & 0xff00) != 0xff00) && ((reg & 0xff00) != 0xae00)) { ((reg & 0xff00) != 0xff00) && ((reg & 0xff00) != 0xae00)) {
mbox |= ((len - 1) << 2); mbox |= ((len - 1) << 2);
ret = af9013_wr_regs_i2c(priv, mbox, reg, val, len); ret = af9013_wr_regs_i2c(priv, mbox, reg, val, len);
...@@ -146,7 +153,7 @@ static int af9013_rd_regs(struct af9013_state *priv, u16 reg, u8 *val, int len) ...@@ -146,7 +153,7 @@ static int af9013_rd_regs(struct af9013_state *priv, u16 reg, u8 *val, int len)
int ret, i; int ret, i;
u8 mbox = (0 << 7)|(0 << 6)|(1 << 1)|(0 << 0); u8 mbox = (0 << 7)|(0 << 6)|(1 << 1)|(0 << 0);
if ((priv->config.ts_mode == AF9013_TS_USB) && if ((priv->ts_mode == AF9013_TS_USB) &&
((reg & 0xff00) != 0xff00) && ((reg & 0xff00) != 0xae00)) { ((reg & 0xff00) != 0xff00) && ((reg & 0xff00) != 0xae00)) {
mbox |= ((len - 1) << 2); mbox |= ((len - 1) << 2);
ret = af9013_rd_regs_i2c(priv, mbox, reg, val, len); ret = af9013_rd_regs_i2c(priv, mbox, reg, val, len);
...@@ -596,7 +603,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -596,7 +603,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
/* program CFOE coefficients */ /* program CFOE coefficients */
if (c->bandwidth_hz != state->bandwidth_hz) { if (c->bandwidth_hz != state->bandwidth_hz) {
for (i = 0; i < ARRAY_SIZE(coeff_lut); i++) { for (i = 0; i < ARRAY_SIZE(coeff_lut); i++) {
if (coeff_lut[i].clock == state->config.clock && if (coeff_lut[i].clock == state->clk &&
coeff_lut[i].bandwidth_hz == c->bandwidth_hz) { coeff_lut[i].bandwidth_hz == c->bandwidth_hz) {
break; break;
} }
...@@ -618,24 +625,24 @@ static int af9013_set_frontend(struct dvb_frontend *fe) ...@@ -618,24 +625,24 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
if (fe->ops.tuner_ops.get_if_frequency) if (fe->ops.tuner_ops.get_if_frequency)
fe->ops.tuner_ops.get_if_frequency(fe, &if_frequency); fe->ops.tuner_ops.get_if_frequency(fe, &if_frequency);
else else
if_frequency = state->config.if_frequency; if_frequency = state->if_frequency;
dev_dbg(&state->i2c->dev, "%s: if_frequency=%d\n", dev_dbg(&state->i2c->dev, "%s: if_frequency=%d\n",
__func__, if_frequency); __func__, if_frequency);
sampling_freq = if_frequency; sampling_freq = if_frequency;
while (sampling_freq > (state->config.clock / 2)) while (sampling_freq > (state->clk / 2))
sampling_freq -= state->config.clock; sampling_freq -= state->clk;
if (sampling_freq < 0) { if (sampling_freq < 0) {
sampling_freq *= -1; sampling_freq *= -1;
spec_inv = state->config.spec_inv; spec_inv = state->spec_inv;
} else { } else {
spec_inv = !state->config.spec_inv; spec_inv = !state->spec_inv;
} }
freq_cw = af9013_div(state, sampling_freq, state->config.clock, freq_cw = af9013_div(state, sampling_freq, state->clk,
23); 23);
if (spec_inv) if (spec_inv)
...@@ -1081,12 +1088,12 @@ static int af9013_init(struct dvb_frontend *fe) ...@@ -1081,12 +1088,12 @@ static int af9013_init(struct dvb_frontend *fe)
goto err; goto err;
/* write API version to firmware */ /* write API version to firmware */
ret = af9013_wr_regs(state, 0x9bf2, state->config.api_version, 4); ret = af9013_wr_regs(state, 0x9bf2, state->api_version, 4);
if (ret) if (ret)
goto err; goto err;
/* program ADC control */ /* program ADC control */
switch (state->config.clock) { switch (state->clk) {
case 28800000: /* 28.800 MHz */ case 28800000: /* 28.800 MHz */
tmp = 0; tmp = 0;
break; break;
...@@ -1105,7 +1112,7 @@ static int af9013_init(struct dvb_frontend *fe) ...@@ -1105,7 +1112,7 @@ static int af9013_init(struct dvb_frontend *fe)
return -EINVAL; return -EINVAL;
} }
adc_cw = af9013_div(state, state->config.clock, 1000000ul, 19); adc_cw = af9013_div(state, state->clk, 1000000ul, 19);
buf[0] = (adc_cw >> 0) & 0xff; buf[0] = (adc_cw >> 0) & 0xff;
buf[1] = (adc_cw >> 8) & 0xff; buf[1] = (adc_cw >> 8) & 0xff;
buf[2] = (adc_cw >> 16) & 0xff; buf[2] = (adc_cw >> 16) & 0xff;
...@@ -1139,7 +1146,7 @@ static int af9013_init(struct dvb_frontend *fe) ...@@ -1139,7 +1146,7 @@ static int af9013_init(struct dvb_frontend *fe)
goto err; goto err;
/* settings for mp2if */ /* settings for mp2if */
if (state->config.ts_mode == AF9013_TS_USB) { if (state->ts_mode == AF9013_TS_USB) {
/* AF9015 split PSB to 1.5k + 0.5k */ /* AF9015 split PSB to 1.5k + 0.5k */
ret = af9013_wr_reg_bits(state, 0xd50b, 2, 1, 1); ret = af9013_wr_reg_bits(state, 0xd50b, 2, 1, 1);
if (ret) if (ret)
...@@ -1174,7 +1181,7 @@ static int af9013_init(struct dvb_frontend *fe) ...@@ -1174,7 +1181,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->i2c->dev, "%s: load tuner specific settings\n",
__func__); __func__);
switch (state->config.tuner) { switch (state->tuner) {
case AF9013_TUNER_MXL5003D: case AF9013_TUNER_MXL5003D:
len = ARRAY_SIZE(tuner_init_mxl5003d); len = ARRAY_SIZE(tuner_init_mxl5003d);
init = tuner_init_mxl5003d; init = tuner_init_mxl5003d;
...@@ -1226,7 +1233,7 @@ static int af9013_init(struct dvb_frontend *fe) ...@@ -1226,7 +1233,7 @@ static int af9013_init(struct dvb_frontend *fe)
} }
/* TS mode */ /* TS mode */
ret = af9013_wr_reg_bits(state, 0xd500, 1, 2, state->config.ts_mode); ret = af9013_wr_reg_bits(state, 0xd500, 1, 2, state->ts_mode);
if (ret) if (ret)
goto err; goto err;
...@@ -1325,7 +1332,7 @@ static int af9013_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) ...@@ -1325,7 +1332,7 @@ static int af9013_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
if (state->i2c_gate_state == enable) if (state->i2c_gate_state == enable)
return 0; return 0;
if (state->config.ts_mode == AF9013_TS_USB) if (state->ts_mode == AF9013_TS_USB)
ret = af9013_wr_reg_bits(state, 0xd417, 3, 1, enable); ret = af9013_wr_reg_bits(state, 0xd417, 3, 1, enable);
else else
ret = af9013_wr_reg_bits(state, 0xd607, 2, 1, enable); ret = af9013_wr_reg_bits(state, 0xd607, 2, 1, enable);
...@@ -1477,10 +1484,17 @@ struct dvb_frontend *af9013_attach(const struct af9013_config *config, ...@@ -1477,10 +1484,17 @@ struct dvb_frontend *af9013_attach(const struct af9013_config *config,
/* setup the state */ /* setup the state */
state->i2c = i2c; state->i2c = i2c;
memcpy(&state->config, config, sizeof(struct af9013_config)); state->i2c_addr = config->i2c_addr;
state->clk = config->clock;
state->tuner = config->tuner;
state->if_frequency = config->if_frequency;
state->ts_mode = config->ts_mode;
state->spec_inv = config->spec_inv;
memcpy(&state->api_version, config->api_version, sizeof(state->api_version));
memcpy(&state->gpio, config->gpio, sizeof(state->gpio));
/* download firmware */ /* download firmware */
if (state->config.ts_mode != AF9013_TS_USB) { if (state->ts_mode != AF9013_TS_USB) {
ret = af9013_download_firmware(state); ret = af9013_download_firmware(state);
if (ret) if (ret)
goto err; goto err;
...@@ -1495,8 +1509,8 @@ struct dvb_frontend *af9013_attach(const struct af9013_config *config, ...@@ -1495,8 +1509,8 @@ struct dvb_frontend *af9013_attach(const struct af9013_config *config,
KBUILD_MODNAME, buf[0], buf[1], buf[2], buf[3]); KBUILD_MODNAME, buf[0], buf[1], buf[2], buf[3]);
/* set GPIOs */ /* set GPIOs */
for (i = 0; i < sizeof(state->config.gpio); i++) { for (i = 0; i < sizeof(state->gpio); i++) {
ret = af9013_set_gpio(state, i, state->config.gpio[i]); ret = af9013_set_gpio(state, i, state->gpio[i]);
if (ret) if (ret)
goto err; goto err;
} }
......
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