aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2014-08-26 20:45:33 -0400
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2014-09-21 17:23:27 -0400
commitd2dbc00cea35081b9f998a0985d151f60ce37835 (patch)
tree168570650e7fe6d048e752b4215c1db0f27027e5
parenta71b65e8c545f5a72c1c227eae8a6df1d68f3f24 (diff)
[media] it913x: convert to RegMap API
Use RegMap API to cover I2C register access routines. Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
-rw-r--r--drivers/media/tuners/Kconfig1
-rw-r--r--drivers/media/tuners/it913x.c137
-rw-r--r--drivers/media/tuners/it913x_priv.h1
3 files changed, 34 insertions, 105 deletions
diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index 83199964b54e..48bff2e23d93 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -248,6 +248,7 @@ config MEDIA_TUNER_SI2157
248config MEDIA_TUNER_IT913X 248config MEDIA_TUNER_IT913X
249 tristate "ITE Tech IT913x silicon tuner" 249 tristate "ITE Tech IT913x silicon tuner"
250 depends on MEDIA_SUPPORT && I2C 250 depends on MEDIA_SUPPORT && I2C
251 select REGMAP_I2C
251 default m if !MEDIA_SUBDRV_AUTOSELECT 252 default m if !MEDIA_SUBDRV_AUTOSELECT
252 help 253 help
253 ITE Tech IT913x silicon tuner driver. 254 ITE Tech IT913x silicon tuner driver.
diff --git a/drivers/media/tuners/it913x.c b/drivers/media/tuners/it913x.c
index cc959c111a62..f3e212c127c8 100644
--- a/drivers/media/tuners/it913x.c
+++ b/drivers/media/tuners/it913x.c
@@ -24,6 +24,7 @@
24 24
25struct it913x_dev { 25struct it913x_dev {
26 struct i2c_client *client; 26 struct i2c_client *client;
27 struct regmap *regmap;
27 struct dvb_frontend *fe; 28 struct dvb_frontend *fe;
28 u8 chip_ver; 29 u8 chip_ver;
29 u8 firmware_ver; 30 u8 firmware_ver;
@@ -33,92 +34,6 @@ struct it913x_dev {
33 u32 tun_fn_min; 34 u32 tun_fn_min;
34}; 35};
35 36
36/* read multiple registers */
37static int it913x_rd_regs(struct it913x_dev *dev,
38 u32 reg, u8 *data, u8 count)
39{
40 int ret;
41 u8 b[3];
42 struct i2c_msg msg[2] = {
43 { .addr = dev->client->addr, .flags = 0,
44 .buf = b, .len = sizeof(b) },
45 { .addr = dev->client->addr, .flags = I2C_M_RD,
46 .buf = data, .len = count }
47 };
48
49 b[0] = (u8)(reg >> 16) & 0xff;
50 b[1] = (u8)(reg >> 8) & 0xff;
51 b[2] = (u8) reg & 0xff;
52
53 ret = i2c_transfer(dev->client->adapter, msg, 2);
54
55 return ret;
56}
57
58/* read single register */
59static int it913x_rd_reg(struct it913x_dev *dev, u32 reg, u8 *val)
60{
61 int ret;
62 u8 b[1];
63
64 ret = it913x_rd_regs(dev, reg, &b[0], sizeof(b));
65 if (ret < 0)
66 return -ENODEV;
67 *val = b[0];
68 return 0;
69}
70
71/* write multiple registers */
72static int it913x_wr_regs(struct it913x_dev *dev,
73 u32 reg, u8 buf[], u8 count)
74{
75 u8 b[256];
76 struct i2c_msg msg[1] = {
77 { .addr = dev->client->addr, .flags = 0,
78 .buf = b, .len = 3 + count }
79 };
80 int ret;
81
82 b[0] = (u8)(reg >> 16) & 0xff;
83 b[1] = (u8)(reg >> 8) & 0xff;
84 b[2] = (u8) reg & 0xff;
85 memcpy(&b[3], buf, count);
86
87 ret = i2c_transfer(dev->client->adapter, msg, 1);
88
89 if (ret < 0)
90 return -EIO;
91
92 return 0;
93}
94
95/* write single register */
96static int it913x_wr_reg(struct it913x_dev *dev,
97 u32 reg, u32 data)
98{
99 int ret;
100 u8 b[4];
101 u8 len;
102
103 b[0] = data >> 24;
104 b[1] = (data >> 16) & 0xff;
105 b[2] = (data >> 8) & 0xff;
106 b[3] = data & 0xff;
107 /* expand write as needed */
108 if (data < 0x100)
109 len = 3;
110 else if (data < 0x1000)
111 len = 2;
112 else if (data < 0x100000)
113 len = 1;
114 else
115 len = 0;
116
117 ret = it913x_wr_regs(dev, reg, &b[len], sizeof(b) - len);
118
119 return ret;
120}
121
122static int it913x_script_loader(struct it913x_dev *dev, 37static int it913x_script_loader(struct it913x_dev *dev,
123 struct it913xset *loadscript) 38 struct it913xset *loadscript)
124{ 39{
@@ -130,8 +45,7 @@ static int it913x_script_loader(struct it913x_dev *dev,
130 for (i = 0; i < 1000; ++i) { 45 for (i = 0; i < 1000; ++i) {
131 if (loadscript[i].address == 0x000000) 46 if (loadscript[i].address == 0x000000)
132 break; 47 break;
133 ret = it913x_wr_regs(dev, 48 ret = regmap_bulk_write(dev->regmap, loadscript[i].address,
134 loadscript[i].address,
135 loadscript[i].reg, loadscript[i].count); 49 loadscript[i].reg, loadscript[i].count);
136 if (ret < 0) 50 if (ret < 0)
137 return -ENODEV; 51 return -ENODEV;
@@ -143,12 +57,12 @@ static int it913x_init(struct dvb_frontend *fe)
143{ 57{
144 struct it913x_dev *dev = fe->tuner_priv; 58 struct it913x_dev *dev = fe->tuner_priv;
145 int ret, i; 59 int ret, i;
146 u8 reg = 0; 60 unsigned int reg;
147 u8 val, nv_val; 61 u8 val, nv_val;
148 u8 nv[] = {48, 32, 24, 16, 12, 8, 6, 4, 2}; 62 u8 nv[] = {48, 32, 24, 16, 12, 8, 6, 4, 2};
149 u8 b[2]; 63 u8 b[2];
150 64
151 ret = it913x_rd_reg(dev, 0x80ec86, &reg); 65 ret = regmap_read(dev->regmap, 0x80ec86, &reg);
152 switch (reg) { 66 switch (reg) {
153 case 0: 67 case 0:
154 dev->tun_clk_mode = reg; 68 dev->tun_clk_mode = reg;
@@ -165,7 +79,7 @@ static int it913x_init(struct dvb_frontend *fe)
165 break; 79 break;
166 } 80 }
167 81
168 ret = it913x_rd_reg(dev, 0x80ed03, &reg); 82 ret = regmap_read(dev->regmap, 0x80ed03, &reg);
169 83
170 if (reg < 0) 84 if (reg < 0)
171 return -ENODEV; 85 return -ENODEV;
@@ -175,11 +89,11 @@ static int it913x_init(struct dvb_frontend *fe)
175 nv_val = 2; 89 nv_val = 2;
176 90
177 for (i = 0; i < 50; i++) { 91 for (i = 0; i < 50; i++) {
178 ret = it913x_rd_regs(dev, 0x80ed23, &b[0], sizeof(b)); 92 ret = regmap_bulk_read(dev->regmap, 0x80ed23, &b[0], sizeof(b));
179 reg = (b[1] << 8) + b[0]; 93 reg = (b[1] << 8) + b[0];
180 if (reg > 0) 94 if (reg > 0)
181 break; 95 break;
182 if (ret < 0) 96 if (ret)
183 return -ENODEV; 97 return -ENODEV;
184 udelay(2000); 98 udelay(2000);
185 } 99 }
@@ -191,7 +105,7 @@ static int it913x_init(struct dvb_frontend *fe)
191 msleep(50); 105 msleep(50);
192 else { 106 else {
193 for (i = 0; i < 50; i++) { 107 for (i = 0; i < 50; i++) {
194 ret = it913x_rd_reg(dev, 0x80ec82, &reg); 108 ret = regmap_read(dev->regmap, 0x80ec82, &reg);
195 if (ret < 0) 109 if (ret < 0)
196 return -ENODEV; 110 return -ENODEV;
197 if (reg > 0) 111 if (reg > 0)
@@ -201,11 +115,11 @@ static int it913x_init(struct dvb_frontend *fe)
201 } 115 }
202 116
203 /* Power Up Tuner - common all versions */ 117 /* Power Up Tuner - common all versions */
204 ret = it913x_wr_reg(dev, 0x80ec40, 0x1); 118 ret = regmap_write(dev->regmap, 0x80ec40, 0x1);
205 ret |= it913x_wr_reg(dev, 0x80ec57, 0x0); 119 ret |= regmap_write(dev->regmap, 0x80ec57, 0x0);
206 ret |= it913x_wr_reg(dev, 0x80ec58, 0x0); 120 ret |= regmap_write(dev->regmap, 0x80ec58, 0x0);
207 121
208 return it913x_wr_reg(dev, 0x80ed81, val); 122 return regmap_write(dev->regmap, 0x80ed81, val);
209} 123}
210 124
211static int it9137_set_params(struct dvb_frontend *fe) 125static int it9137_set_params(struct dvb_frontend *fe)
@@ -216,7 +130,7 @@ static int it9137_set_params(struct dvb_frontend *fe)
216 u32 bandwidth = p->bandwidth_hz; 130 u32 bandwidth = p->bandwidth_hz;
217 u32 frequency_m = p->frequency; 131 u32 frequency_m = p->frequency;
218 int ret; 132 int ret;
219 u8 reg = 0; 133 unsigned int reg;
220 u32 frequency = frequency_m / 1000; 134 u32 frequency = frequency_m / 1000;
221 u32 freq, temp_f, tmp; 135 u32 freq, temp_f, tmp;
222 u16 iqik_m_cal; 136 u16 iqik_m_cal;
@@ -317,7 +231,7 @@ static int it9137_set_params(struct dvb_frontend *fe)
317 } else 231 } else
318 return -EINVAL; 232 return -EINVAL;
319 233
320 ret = it913x_rd_reg(dev, 0x80ed81, &reg); 234 ret = regmap_read(dev->regmap, 0x80ed81, &reg);
321 iqik_m_cal = (u16)reg * n_div; 235 iqik_m_cal = (u16)reg * n_div;
322 236
323 if (reg < 0x20) { 237 if (reg < 0x20) {
@@ -394,6 +308,10 @@ static int it913x_probe(struct i2c_client *client,
394 struct it913x_dev *dev; 308 struct it913x_dev *dev;
395 int ret; 309 int ret;
396 char *chip_ver_str; 310 char *chip_ver_str;
311 static const struct regmap_config regmap_config = {
312 .reg_bits = 24,
313 .val_bits = 8,
314 };
397 315
398 dev = kzalloc(sizeof(struct it913x_dev), GFP_KERNEL); 316 dev = kzalloc(sizeof(struct it913x_dev), GFP_KERNEL);
399 if (dev == NULL) { 317 if (dev == NULL) {
@@ -406,11 +324,16 @@ static int it913x_probe(struct i2c_client *client,
406 dev->fe = cfg->fe; 324 dev->fe = cfg->fe;
407 dev->chip_ver = cfg->chip_ver; 325 dev->chip_ver = cfg->chip_ver;
408 dev->firmware_ver = 1; 326 dev->firmware_ver = 1;
327 dev->regmap = regmap_init_i2c(client, &regmap_config);
328 if (IS_ERR(dev->regmap)) {
329 ret = PTR_ERR(dev->regmap);
330 goto err_kfree;
331 }
409 332
410 /* tuner RF initial */ 333 /* tuner RF initial */
411 ret = it913x_wr_reg(dev, 0x80ec4c, 0x68); 334 ret = regmap_write(dev->regmap, 0x80ec4c, 0x68);
412 if (ret < 0) 335 if (ret)
413 goto err; 336 goto err_regmap_exit;
414 337
415 fe->tuner_priv = dev; 338 fe->tuner_priv = dev;
416 memcpy(&fe->ops.tuner_ops, &it913x_tuner_ops, 339 memcpy(&fe->ops.tuner_ops, &it913x_tuner_ops,
@@ -428,10 +351,13 @@ static int it913x_probe(struct i2c_client *client,
428 chip_ver_str); 351 chip_ver_str);
429 dev_dbg(&dev->client->dev, "chip_ver=%02x\n", dev->chip_ver); 352 dev_dbg(&dev->client->dev, "chip_ver=%02x\n", dev->chip_ver);
430 return 0; 353 return 0;
354
355err_regmap_exit:
356 regmap_exit(dev->regmap);
357err_kfree:
358 kfree(dev);
431err: 359err:
432 dev_dbg(&client->dev, "failed %d\n", ret); 360 dev_dbg(&client->dev, "failed %d\n", ret);
433 kfree(dev);
434
435 return ret; 361 return ret;
436} 362}
437 363
@@ -444,6 +370,7 @@ static int it913x_remove(struct i2c_client *client)
444 370
445 memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); 371 memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops));
446 fe->tuner_priv = NULL; 372 fe->tuner_priv = NULL;
373 regmap_exit(dev->regmap);
447 kfree(dev); 374 kfree(dev);
448 375
449 return 0; 376 return 0;
diff --git a/drivers/media/tuners/it913x_priv.h b/drivers/media/tuners/it913x_priv.h
index 32af24c69cbb..3ed2d3c0fe55 100644
--- a/drivers/media/tuners/it913x_priv.h
+++ b/drivers/media/tuners/it913x_priv.h
@@ -24,6 +24,7 @@
24#define IT913X_PRIV_H 24#define IT913X_PRIV_H
25 25
26#include "it913x.h" 26#include "it913x.h"
27#include <linux/regmap.h>
27 28
28#define TRIGGER_OFSM 0x0000 29#define TRIGGER_OFSM 0x0000
29 30