diff options
author | Antti Palosaari <crope@iki.fi> | 2014-08-26 17:14:16 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2014-09-21 17:48:23 -0300 |
commit | 3b2a5e8c080da37be6135f44d236fe6b796666d9 (patch) | |
tree | 7e299163b51e52afae4717eabc6fef86adfc41d8 /drivers/media/tuners/it913x.c | |
parent | c2ba9726c342d113bdc36cfd8e984e30498037c6 (diff) |
[media] it913x: convert to I2C driver
Change the it913x driver to use the I2C high lever tuner
binding model. As af9035 depends on it, add a code there
to do the binding.
[mchehab@osg.samsung.com: Merge 3 patches into one, because
we don't want to break bisect due to the conversion]
Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/tuners/it913x.c')
-rw-r--r-- | drivers/media/tuners/it913x.c | 133 |
1 files changed, 73 insertions, 60 deletions
diff --git a/drivers/media/tuners/it913x.c b/drivers/media/tuners/it913x.c index 4627925ed117..72fefb753af1 100644 --- a/drivers/media/tuners/it913x.c +++ b/drivers/media/tuners/it913x.c @@ -23,10 +23,9 @@ #include "it913x_priv.h" struct it913x_state { - struct i2c_adapter *i2c_adap; - u8 i2c_addr; + struct i2c_client *client; + struct dvb_frontend *fe; u8 chip_ver; - u8 tuner_type; u8 firmware_ver; u16 tun_xtal; u8 tun_fdiv; @@ -41,9 +40,9 @@ static int it913x_rd_regs(struct it913x_state *state, int ret; u8 b[3]; struct i2c_msg msg[2] = { - { .addr = state->i2c_addr, .flags = 0, + { .addr = state->client->addr, .flags = 0, .buf = b, .len = sizeof(b) }, - { .addr = state->i2c_addr, .flags = I2C_M_RD, + { .addr = state->client->addr, .flags = I2C_M_RD, .buf = data, .len = count } }; @@ -52,7 +51,7 @@ static int it913x_rd_regs(struct it913x_state *state, b[2] = (u8) reg & 0xff; b[0] |= 0x80; /* All reads from demodulator */ - ret = i2c_transfer(state->i2c_adap, msg, 2); + ret = i2c_transfer(state->client->adapter, msg, 2); return ret; } @@ -73,7 +72,7 @@ static int it913x_wr_regs(struct it913x_state *state, { u8 b[256]; struct i2c_msg msg[1] = { - { .addr = state->i2c_addr, .flags = 0, + { .addr = state->client->addr, .flags = 0, .buf = b, .len = 3 + count } }; int ret; @@ -86,7 +85,7 @@ static int it913x_wr_regs(struct it913x_state *state, if (pro == PRO_DMOD) b[0] |= 0x80; - ret = i2c_transfer(state->i2c_adap, msg, 1); + ret = i2c_transfer(state->client->adapter, msg, 1); if (ret < 0) return -EIO; @@ -191,8 +190,7 @@ static int it913x_init(struct dvb_frontend *fe) } state->tun_fn_min = state->tun_xtal * reg; state->tun_fn_min /= (state->tun_fdiv * nv_val); - dev_dbg(&state->i2c_adap->dev, "%s: Tuner fn_min %d\n", __func__, - state->tun_fn_min); + dev_dbg(&state->client->dev, "Tuner fn_min %d\n", state->tun_fn_min); if (state->chip_ver > 1) msleep(50); @@ -237,8 +235,8 @@ static int it9137_set_params(struct dvb_frontend *fe) else set_tuner = set_it9137_template; - dev_dbg(&state->i2c_adap->dev, "%s: Tuner Frequency %d Bandwidth %d\n", - __func__, frequency, bandwidth); + dev_dbg(&state->client->dev, "Tuner Frequency %d Bandwidth %d\n", + frequency, bandwidth); if (frequency >= 51000 && frequency <= 440000) { l_band = 0; @@ -353,15 +351,13 @@ static int it9137_set_params(struct dvb_frontend *fe) set_tuner[3].reg[0] = temp_f & 0xff; set_tuner[4].reg[0] = (temp_f >> 8) & 0xff; - dev_dbg(&state->i2c_adap->dev, "%s: High Frequency = %04x\n", - __func__, temp_f); + dev_dbg(&state->client->dev, "High Frequency = %04x\n", temp_f); /* Lower frequency */ set_tuner[5].reg[0] = freq & 0xff; set_tuner[6].reg[0] = (freq >> 8) & 0xff; - dev_dbg(&state->i2c_adap->dev, "%s: low Frequency = %04x\n", - __func__, freq); + dev_dbg(&state->client->dev, "low Frequency = %04x\n", freq); ret = it913x_script_loader(state, set_tuner); @@ -382,12 +378,6 @@ static int it913x_sleep(struct dvb_frontend *fe) return it913x_script_loader(state, it9137_tuner_off); } -static int it913x_release(struct dvb_frontend *fe) -{ - kfree(fe->tuner_priv); - return 0; -} - static const struct dvb_tuner_ops it913x_tuner_ops = { .info = { .name = "ITE Tech IT913X", @@ -395,68 +385,91 @@ static const struct dvb_tuner_ops it913x_tuner_ops = { .frequency_max = 862000000, }, - .release = it913x_release, - .init = it913x_init, .sleep = it913x_sleep, .set_params = it9137_set_params, }; -struct dvb_frontend *it913x_attach(struct dvb_frontend *fe, - struct i2c_adapter *i2c_adap, u8 i2c_addr, u8 config) +static int it913x_probe(struct i2c_client *client, + const struct i2c_device_id *id) { - struct it913x_state *state = NULL; + struct it913x_config *cfg = client->dev.platform_data; + struct dvb_frontend *fe = cfg->fe; + struct it913x_state *state; int ret; + char *chip_ver_str; - /* allocate memory for the internal state */ state = kzalloc(sizeof(struct it913x_state), GFP_KERNEL); - if (state == NULL) - return NULL; - - state->i2c_adap = i2c_adap; - state->i2c_addr = i2c_addr; - - switch (config) { - case AF9033_TUNER_IT9135_38: - case AF9033_TUNER_IT9135_51: - case AF9033_TUNER_IT9135_52: - state->chip_ver = 0x01; - break; - case AF9033_TUNER_IT9135_60: - case AF9033_TUNER_IT9135_61: - case AF9033_TUNER_IT9135_62: - state->chip_ver = 0x02; - break; - default: - dev_dbg(&i2c_adap->dev, - "%s: invalid config=%02x\n", __func__, config); - goto error; + if (state == NULL) { + ret = -ENOMEM; + dev_err(&client->dev, "kzalloc() failed\n"); + goto err; } - state->tuner_type = config; + state->client = client; + state->fe = cfg->fe; + state->chip_ver = cfg->chip_ver; state->firmware_ver = 1; /* tuner RF initial */ ret = it913x_wr_reg(state, PRO_DMOD, 0xec4c, 0x68); if (ret < 0) - goto error; + goto err; fe->tuner_priv = state; memcpy(&fe->ops.tuner_ops, &it913x_tuner_ops, sizeof(struct dvb_tuner_ops)); + i2c_set_clientdata(client, state); + + if (state->chip_ver == 1) + chip_ver_str = "AX"; + else if (state->chip_ver == 2) + chip_ver_str = "BX"; + else + chip_ver_str = "??"; + + dev_info(&state->client->dev, "ITE IT913X %s successfully attached\n", + chip_ver_str); + dev_dbg(&state->client->dev, "chip_ver=%02x\n", state->chip_ver); + return 0; +err: + dev_dbg(&client->dev, "failed %d\n", ret); + kfree(state); - dev_info(&i2c_adap->dev, - "%s: ITE Tech IT913X successfully attached\n", - KBUILD_MODNAME); - dev_dbg(&i2c_adap->dev, "%s: config=%02x chip_ver=%02x\n", - __func__, config, state->chip_ver); + return ret; +} - return fe; -error: +static int it913x_remove(struct i2c_client *client) +{ + struct it913x_state *state = i2c_get_clientdata(client); + struct dvb_frontend *fe = state->fe; + + dev_dbg(&client->dev, "\n"); + + memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); + fe->tuner_priv = NULL; kfree(state); - return NULL; + + return 0; } -EXPORT_SYMBOL(it913x_attach); + +static const struct i2c_device_id it913x_id_table[] = { + {"it913x", 0}, + {} +}; +MODULE_DEVICE_TABLE(i2c, it913x_id_table); + +static struct i2c_driver it913x_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "it913x", + }, + .probe = it913x_probe, + .remove = it913x_remove, + .id_table = it913x_id_table, +}; + +module_i2c_driver(it913x_driver); MODULE_DESCRIPTION("ITE Tech IT913X silicon tuner driver"); MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |