[media] tua9001: use regmap for I2C register access
authorAntti Palosaari <crope@iki.fi>
Wed, 15 Apr 2015 23:38:43 +0000 (20:38 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Mon, 18 May 2015 18:54:46 +0000 (15:54 -0300)
Use regmap for I2C register access.

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

index 0408745778e82bd13d6dd38170b63d69e91ea5cb..8294af90917475587f1835455eb9756b46816bbb 100644 (file)
@@ -236,6 +236,7 @@ config MEDIA_TUNER_M88RS6000T
 config MEDIA_TUNER_TUA9001
        tristate "Infineon TUA9001 silicon tuner"
        depends on MEDIA_SUPPORT && I2C
+       select REGMAP_I2C
        default m if !MEDIA_SUBDRV_AUTOSELECT
        help
          Infineon TUA 9001 silicon tuner driver.
index fe778cd39c2e6326666dd01d5f15119c3e1e5c5f..09a10349dd573e60b59afc9ab33486db1cb27568 100644 (file)
 
 #include "tua9001_priv.h"
 
-/* write register */
-static int tua9001_wr_reg(struct tua9001_dev *dev, u8 reg, u16 val)
-{
-       struct i2c_client *client = dev->client;
-       int ret;
-       u8 buf[3] = { reg, (val >> 8) & 0xff, (val >> 0) & 0xff };
-       struct i2c_msg msg[1] = {
-               {
-                       .addr = client->addr,
-                       .flags = 0,
-                       .len = sizeof(buf),
-                       .buf = buf,
-               }
-       };
-
-       ret = i2c_transfer(client->adapter, msg, 1);
-       if (ret == 1) {
-               ret = 0;
-       } else {
-               dev_warn(&client->dev, "i2c wr failed=%d reg=%02x\n", ret, reg);
-               ret = -EREMOTEIO;
-       }
-
-       return ret;
-}
-
 static int tua9001_init(struct dvb_frontend *fe)
 {
        struct tua9001_dev *dev = fe->tuner_priv;
@@ -76,7 +50,7 @@ static int tua9001_init(struct dvb_frontend *fe)
        }
 
        for (i = 0; i < ARRAY_SIZE(data); i++) {
-               ret = tua9001_wr_reg(dev, data[i].reg, data[i].val);
+               ret = regmap_write(dev->regmap, data[i].reg, data[i].val);
                if (ret)
                        goto err;
        }
@@ -166,7 +140,7 @@ static int tua9001_set_params(struct dvb_frontend *fe)
        }
 
        for (i = 0; i < ARRAY_SIZE(data); i++) {
-               ret = tua9001_wr_reg(dev, data[i].reg, data[i].val);
+               ret = regmap_write(dev->regmap, data[i].reg, data[i].val);
                if (ret)
                        goto err;
        }
@@ -216,6 +190,10 @@ static int tua9001_probe(struct i2c_client *client,
        struct tua9001_platform_data *pdata = client->dev.platform_data;
        struct dvb_frontend *fe = pdata->dvb_frontend;
        int ret;
+       static const struct regmap_config regmap_config = {
+               .reg_bits =  8,
+               .val_bits = 16,
+       };
 
        dev = kzalloc(sizeof(*dev), GFP_KERNEL);
        if (!dev) {
@@ -223,8 +201,13 @@ static int tua9001_probe(struct i2c_client *client,
                goto err;
        }
 
-       dev->client = client;
        dev->fe = pdata->dvb_frontend;
+       dev->client = client;
+       dev->regmap = devm_regmap_init_i2c(client, &regmap_config);
+       if (IS_ERR(dev->regmap)) {
+               ret = PTR_ERR(dev->regmap);
+               goto err_kfree;
+       }
 
        if (fe->callback) {
                ret = fe->callback(client->adapter,
index e24d8430703559ff1a320065671b62a66bc67f4a..327ead9ea2ba5c832a26f05ed6569c47d00f1d90 100644 (file)
@@ -18,6 +18,7 @@
 #define TUA9001_PRIV_H
 
 #include "tua9001.h"
+#include <linux/regmap.h>
 
 struct tua9001_reg_val {
        u8 reg;
@@ -27,6 +28,7 @@ struct tua9001_reg_val {
 struct tua9001_dev {
        struct dvb_frontend *fe;
        struct i2c_client *client;
+       struct regmap *regmap;
 };
 
 #endif