[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>
diff --git a/drivers/media/tuners/it913x.c b/drivers/media/tuners/it913x.c
index 4627925..72fefb7 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 @@
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 @@
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 @@
{
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 @@
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 @@
}
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 @@
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 @@
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 @@
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 @@
.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);
- 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);
+ if (state->chip_ver == 1)
+ chip_ver_str = "AX";
+ else if (state->chip_ver == 2)
+ chip_ver_str = "BX";
+ else
+ chip_ver_str = "??";
- return fe;
-error:
+ 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);
- return NULL;
+
+ return ret;
}
-EXPORT_SYMBOL(it913x_attach);
+
+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 0;
+}
+
+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>");