[media] tua9001: add I2C bindings
authorAntti Palosaari <crope@iki.fi>
Wed, 15 Apr 2015 22:12:34 +0000 (19:12 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Mon, 18 May 2015 18:51:54 +0000 (15:51 -0300)
Add I2C bindings.

Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/tuners/tua9001.c
drivers/media/tuners/tua9001.h
drivers/media/tuners/tua9001_priv.h

index 83a6240f64d3d17b1a486bb7dbddac50864ee490..55cac20ae0340a8038660ab91936a18f85398d68 100644 (file)
@@ -28,7 +28,7 @@ static int tua9001_wr_reg(struct tua9001_priv *priv, u8 reg, u16 val)
        u8 buf[3] = { reg, (val >> 8) & 0xff, (val >> 0) & 0xff };
        struct i2c_msg msg[1] = {
                {
-                       .addr = priv->cfg->i2c_addr,
+                       .addr = priv->i2c_addr,
                        .flags = 0,
                        .len = sizeof(buf),
                        .buf = buf,
@@ -253,7 +253,7 @@ struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe,
        if (priv == NULL)
                return NULL;
 
-       priv->cfg = cfg;
+       priv->i2c_addr = cfg->i2c_addr;
        priv->i2c = i2c;
 
        if (fe->callback) {
@@ -289,6 +289,102 @@ err:
 }
 EXPORT_SYMBOL(tua9001_attach);
 
+static int tua9001_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
+{
+       struct tua9001_priv *dev;
+       struct tua9001_platform_data *pdata = client->dev.platform_data;
+       struct dvb_frontend *fe = pdata->dvb_frontend;
+       int ret;
+
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+       if (!dev) {
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       dev->client = client;
+       dev->i2c_addr = client->addr;
+       dev->i2c = client->adapter;
+       dev->fe = pdata->dvb_frontend;
+
+       if (fe->callback) {
+               ret = fe->callback(client->adapter,
+                                  DVB_FRONTEND_COMPONENT_TUNER,
+                                  TUA9001_CMD_CEN, 1);
+               if (ret)
+                       goto err_kfree;
+
+               ret = fe->callback(client->adapter,
+                                  DVB_FRONTEND_COMPONENT_TUNER,
+                                  TUA9001_CMD_RXEN, 0);
+               if (ret)
+                       goto err_kfree;
+
+               ret = fe->callback(client->adapter,
+                                  DVB_FRONTEND_COMPONENT_TUNER,
+                                  TUA9001_CMD_RESETN, 1);
+               if (ret)
+                       goto err_kfree;
+       }
+
+       fe->tuner_priv = dev;
+       memcpy(&fe->ops.tuner_ops, &tua9001_tuner_ops,
+                       sizeof(struct dvb_tuner_ops));
+       fe->ops.tuner_ops.release = NULL;
+       i2c_set_clientdata(client, dev);
+
+       dev_info(&client->dev, "Infineon TUA 9001 successfully attached\n");
+       return 0;
+err_kfree:
+       kfree(dev);
+err:
+       dev_dbg(&client->dev, "failed=%d\n", ret);
+       return ret;
+}
+
+static int tua9001_remove(struct i2c_client *client)
+{
+       struct tua9001_priv *dev = i2c_get_clientdata(client);
+       struct dvb_frontend *fe = dev->fe;
+       int ret;
+
+       dev_dbg(&client->dev, "\n");
+
+       if (fe->callback) {
+               ret = fe->callback(client->adapter,
+                                  DVB_FRONTEND_COMPONENT_TUNER,
+                                  TUA9001_CMD_CEN, 0);
+               if (ret)
+                       goto err_kfree;
+       }
+       kfree(dev);
+       return 0;
+err_kfree:
+       kfree(dev);
+       dev_dbg(&client->dev, "failed=%d\n", ret);
+       return ret;
+}
+
+static const struct i2c_device_id tua9001_id_table[] = {
+       {"tua9001", 0},
+       {}
+};
+MODULE_DEVICE_TABLE(i2c, tua9001_id_table);
+
+static struct i2c_driver tua9001_driver = {
+       .driver = {
+               .owner  = THIS_MODULE,
+               .name   = "tua9001",
+               .suppress_bind_attrs = true,
+       },
+       .probe          = tua9001_probe,
+       .remove         = tua9001_remove,
+       .id_table       = tua9001_id_table,
+};
+
+module_i2c_driver(tua9001_driver);
+
 MODULE_DESCRIPTION("Infineon TUA 9001 silicon tuner driver");
 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
 MODULE_LICENSE("GPL");
index 2c3375c7aeb9eaf8677b7fd9d81f28cfeb33aaf5..0b4fc8d26f5232d8b12af7591208b64e2fc1d29f 100644 (file)
 #include <linux/kconfig.h>
 #include "dvb_frontend.h"
 
+/*
+ * I2C address
+ * 0x60,
+ */
+
+/**
+ * struct tua9001_platform_data - Platform data for the tua9001 driver
+ * @dvb_frontend: DVB frontend.
+ */
+struct tua9001_platform_data {
+       struct dvb_frontend *dvb_frontend;
+};
+
 struct tua9001_config {
        /*
         * I2C address
index 73cc1ce0575c65117517907e611adf69288bbb44..3282a1a12e8630150419278af7e25d5065274377 100644 (file)
@@ -27,8 +27,10 @@ struct reg_val {
 };
 
 struct tua9001_priv {
-       struct tua9001_config *cfg;
+       struct i2c_client *client;
        struct i2c_adapter *i2c;
+       u8 i2c_addr;
+       struct dvb_frontend *fe;
 };
 
 #endif