[media] mt2060: add i2c bindings
authorAntti Palosaari <crope@iki.fi>
Sun, 26 Jul 2015 21:45:05 +0000 (18:45 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Fri, 3 Feb 2017 08:16:18 +0000 (06:16 -0200)
Add proper i2c driver model bindings.

Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/tuners/mt2060.c
drivers/media/tuners/mt2060.h
drivers/media/tuners/mt2060_priv.h

index 6f94e171513eb38e91ea7327f0b3c0af651cbc36..b8acfa27e84241c002e965f3870eeea835ff402d 100644 (file)
@@ -392,6 +392,89 @@ struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter
 }
 EXPORT_SYMBOL(mt2060_attach);
 
+static int mt2060_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
+{
+       struct mt2060_platform_data *pdata = client->dev.platform_data;
+       struct dvb_frontend *fe;
+       struct mt2060_priv *dev;
+       int ret;
+       u8 chip_id;
+
+       dev_dbg(&client->dev, "\n");
+
+       if (!pdata) {
+               dev_err(&client->dev, "Cannot proceed without platform data\n");
+               ret = -EINVAL;
+               goto err;
+       }
+
+       dev = devm_kzalloc(&client->dev, sizeof(*dev), GFP_KERNEL);
+       if (!dev) {
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       fe = pdata->dvb_frontend;
+       dev->config.i2c_address = client->addr;
+       dev->config.clock_out = pdata->clock_out;
+       dev->cfg = &dev->config;
+       dev->i2c = client->adapter;
+       dev->if1_freq = pdata->if1 ? pdata->if1 : 1220;
+       dev->client = client;
+
+       ret = mt2060_readreg(dev, REG_PART_REV, &chip_id);
+       if (ret) {
+               ret = -ENODEV;
+               goto err;
+       }
+
+       dev_dbg(&client->dev, "chip id=%02x\n", chip_id);
+
+       if (chip_id != PART_REV) {
+               ret = -ENODEV;
+               goto err;
+       }
+
+       dev_info(&client->dev, "Microtune MT2060 successfully identified\n");
+       memcpy(&fe->ops.tuner_ops, &mt2060_tuner_ops, sizeof(fe->ops.tuner_ops));
+       fe->ops.tuner_ops.release = NULL;
+       fe->tuner_priv = dev;
+       i2c_set_clientdata(client, dev);
+
+       mt2060_calibrate(dev);
+
+       return 0;
+err:
+       dev_dbg(&client->dev, "failed=%d\n", ret);
+       return ret;
+}
+
+static int mt2060_remove(struct i2c_client *client)
+{
+       dev_dbg(&client->dev, "\n");
+
+       return 0;
+}
+
+static const struct i2c_device_id mt2060_id_table[] = {
+       {"mt2060", 0},
+       {}
+};
+MODULE_DEVICE_TABLE(i2c, mt2060_id_table);
+
+static struct i2c_driver mt2060_driver = {
+       .driver = {
+               .name = "mt2060",
+               .suppress_bind_attrs = true,
+       },
+       .probe          = mt2060_probe,
+       .remove         = mt2060_remove,
+       .id_table       = mt2060_id_table,
+};
+
+module_i2c_driver(mt2060_driver);
+
 MODULE_AUTHOR("Olivier DANET");
 MODULE_DESCRIPTION("Microtune MT2060 silicon tuner driver");
 MODULE_LICENSE("GPL");
index 0ef460146c136c817e910619b06c95a7c6a3a260..41feb2c1d2cd34b043ffdc29d5cb121c917f502d 100644 (file)
 struct dvb_frontend;
 struct i2c_adapter;
 
+/*
+ * I2C address
+ * 0x60, ...
+ */
+
+/**
+ * struct mt2060_platform_data - Platform data for the mt2060 driver
+ * @clock_out: Clock output setting. 0 = off, 1 = CLK/4, 2 = CLK/2, 3 = CLK/1.
+ * @if1: First IF used [MHz]. 0 defaults to 1220.
+ * @dvb_frontend: DVB frontend.
+ */
+
+struct mt2060_platform_data {
+       u8 clock_out;
+       u16 if1;
+       struct dvb_frontend *dvb_frontend;
+};
+
+
+/* configuration struct for mt2060_attach() */
 struct mt2060_config {
        u8 i2c_address;
        u8 clock_out; /* 0 = off, 1 = CLK/4, 2 = CLK/2, 3 = CLK/1 */
index 8397697cece964e91d5f3bfffc0bf72bdcac9ae5..af677b24528678a5b9552f7bb1549902cdd22b16 100644 (file)
@@ -91,6 +91,8 @@
 struct mt2060_priv {
        struct mt2060_config *cfg;
        struct i2c_adapter   *i2c;
+       struct i2c_client *client;
+       struct mt2060_config config;
 
        u32 frequency;
        u16 if1_freq;