aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/common/tuners
diff options
context:
space:
mode:
authorDmitri Belimov <d.belimov@gmail.com>2010-05-18 03:30:11 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-08-02 14:29:10 -0400
commit4743319fb0d2a808a5e3eeb778a9666daf9da51d (patch)
tree048fe72e763e67cefbf6002cae3d94586a523792 /drivers/media/common/tuners
parente252984c5279dde24fbd6d3efe7fe13dc642e714 (diff)
V4L/DVB: xc5000, rework xc_write_reg
Rework xc_write_reg function for correct read register of the xc5000. It is very useful for tm6000. Tested for tm6000 and for saa7134 works well. Signed-off-by: Beholder Intl. Ltd. Dmitry Belimov <d.belimov@gmail.com> Acked-by: Devin Heitmueller <dheitmueller@kernellabs.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/common/tuners')
-rw-r--r--drivers/media/common/tuners/xc5000.c57
1 files changed, 26 insertions, 31 deletions
diff --git a/drivers/media/common/tuners/xc5000.c b/drivers/media/common/tuners/xc5000.c
index 432003dded7c..215dad07f060 100644
--- a/drivers/media/common/tuners/xc5000.c
+++ b/drivers/media/common/tuners/xc5000.c
@@ -232,6 +232,26 @@ static int xc_read_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
232 return 0; 232 return 0;
233} 233}
234 234
235static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
236{
237 u8 buf[2] = { reg >> 8, reg & 0xff };
238 u8 bval[2] = { 0, 0 };
239 struct i2c_msg msg[2] = {
240 { .addr = priv->i2c_props.addr,
241 .flags = 0, .buf = &buf[0], .len = 2 },
242 { .addr = priv->i2c_props.addr,
243 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
244 };
245
246 if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
247 printk(KERN_WARNING "xc5000: I2C read failed\n");
248 return -EREMOTEIO;
249 }
250
251 *val = (bval[0] << 8) | bval[1];
252 return XC_RESULT_SUCCESS;
253}
254
235static void xc_wait(int wait_ms) 255static void xc_wait(int wait_ms)
236{ 256{
237 msleep(wait_ms); 257 msleep(wait_ms);
@@ -275,20 +295,14 @@ static int xc_write_reg(struct xc5000_priv *priv, u16 regAddr, u16 i2cData)
275 if (result == XC_RESULT_SUCCESS) { 295 if (result == XC_RESULT_SUCCESS) {
276 /* wait for busy flag to clear */ 296 /* wait for busy flag to clear */
277 while ((WatchDogTimer > 0) && (result == XC_RESULT_SUCCESS)) { 297 while ((WatchDogTimer > 0) && (result == XC_RESULT_SUCCESS)) {
278 buf[0] = 0; 298 result = xc5000_readreg(priv, XREG_BUSY, buf);
279 buf[1] = XREG_BUSY;
280
281 result = xc_send_i2c_data(priv, buf, 2);
282 if (result == XC_RESULT_SUCCESS) { 299 if (result == XC_RESULT_SUCCESS) {
283 result = xc_read_i2c_data(priv, buf, 2); 300 if ((buf[0] == 0) && (buf[1] == 0)) {
284 if (result == XC_RESULT_SUCCESS) { 301 /* busy flag cleared */
285 if ((buf[0] == 0) && (buf[1] == 0)) {
286 /* busy flag cleared */
287 break; 302 break;
288 } else { 303 } else {
289 xc_wait(5); /* wait 5 ms */ 304 xc_wait(5); /* wait 5 ms */
290 WatchDogTimer--; 305 WatchDogTimer--;
291 }
292 } 306 }
293 } 307 }
294 } 308 }
@@ -526,25 +540,6 @@ static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz, int mode)
526 return found; 540 return found;
527} 541}
528 542
529static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
530{
531 u8 buf[2] = { reg >> 8, reg & 0xff };
532 u8 bval[2] = { 0, 0 };
533 struct i2c_msg msg[2] = {
534 { .addr = priv->i2c_props.addr,
535 .flags = 0, .buf = &buf[0], .len = 2 },
536 { .addr = priv->i2c_props.addr,
537 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
538 };
539
540 if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
541 printk(KERN_WARNING "xc5000: I2C read failed\n");
542 return -EREMOTEIO;
543 }
544
545 *val = (bval[0] << 8) | bval[1];
546 return XC_RESULT_SUCCESS;
547}
548 543
549static int xc5000_fwupload(struct dvb_frontend *fe) 544static int xc5000_fwupload(struct dvb_frontend *fe)
550{ 545{