aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/saa7115.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2007-09-13 10:19:39 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-01-25 16:01:20 -0500
commitfbaa3d0db482ae55fc054b9446c1ecf699754054 (patch)
tree11b2d4595daa70edefb6cbca8c24e3722711517b /drivers/media/video/saa7115.c
parent45eea27624d4dacd36c2167f75e2510ee5d4ab26 (diff)
V4L/DVB (6455): saa7115: convert to bus-based I2C API
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/saa7115.c')
-rw-r--r--drivers/media/video/saa7115.c76
1 files changed, 16 insertions, 60 deletions
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index 2d18f0069821..ad60335544ff 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -46,6 +46,7 @@
46#include <linux/videodev2.h> 46#include <linux/videodev2.h>
47#include <media/v4l2-common.h> 47#include <media/v4l2-common.h>
48#include <media/v4l2-chip-ident.h> 48#include <media/v4l2-chip-ident.h>
49#include <media/v4l2-i2c-drv-legacy.h>
49#include <media/saa7115.h> 50#include <media/saa7115.h>
50#include <asm/div64.h> 51#include <asm/div64.h>
51 52
@@ -1230,7 +1231,7 @@ static void saa711x_decode_vbi_line(struct i2c_client *client,
1230 1231
1231/* ============ SAA7115 AUDIO settings (end) ============= */ 1232/* ============ SAA7115 AUDIO settings (end) ============= */
1232 1233
1233static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *arg) 1234static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *arg)
1234{ 1235{
1235 struct saa711x_state *state = i2c_get_clientdata(client); 1236 struct saa711x_state *state = i2c_get_clientdata(client);
1236 1237
@@ -1449,26 +1450,17 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
1449 1450
1450/* ----------------------------------------------------------------------- */ 1451/* ----------------------------------------------------------------------- */
1451 1452
1452static struct i2c_driver i2c_driver_saa711x; 1453static int saa7115_probe(struct i2c_client *client)
1453
1454static int saa711x_attach(struct i2c_adapter *adapter, int address, int kind)
1455{ 1454{
1456 struct i2c_client *client;
1457 struct saa711x_state *state; 1455 struct saa711x_state *state;
1458 int i; 1456 int i;
1459 char name[17]; 1457 char name[17];
1460 u8 chip_id; 1458 u8 chip_id;
1461 1459
1462 /* Check if the adapter supports the needed features */ 1460 /* Check if the adapter supports the needed features */
1463 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1461 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1464 return 0; 1462 return 0;
1465 1463
1466 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
1467 if (client == 0)
1468 return -ENOMEM;
1469 client->addr = address;
1470 client->adapter = adapter;
1471 client->driver = &i2c_driver_saa711x;
1472 snprintf(client->name, sizeof(client->name) - 1, "saa7115"); 1464 snprintf(client->name, sizeof(client->name) - 1, "saa7115");
1473 1465
1474 for (i = 0; i < 0x0f; i++) { 1466 for (i = 0; i < 0x0f; i++) {
@@ -1485,18 +1477,16 @@ static int saa711x_attach(struct i2c_adapter *adapter, int address, int kind)
1485 /* Check whether this chip is part of the saa711x series */ 1477 /* Check whether this chip is part of the saa711x series */
1486 if (memcmp(name, "1f711", 5)) { 1478 if (memcmp(name, "1f711", 5)) {
1487 v4l_dbg(1, debug, client, "chip found @ 0x%x (ID %s) does not match a known saa711x chip.\n", 1479 v4l_dbg(1, debug, client, "chip found @ 0x%x (ID %s) does not match a known saa711x chip.\n",
1488 address << 1, name); 1480 client->addr << 1, name);
1489 kfree(client);
1490 return 0; 1481 return 0;
1491 } 1482 }
1492 1483
1493 snprintf(client->name, sizeof(client->name) - 1, "saa711%d",chip_id); 1484 snprintf(client->name, sizeof(client->name) - 1, "saa711%d",chip_id);
1494 v4l_info(client, "saa711%d found (%s) @ 0x%x (%s)\n", chip_id, name, address << 1, adapter->name); 1485 v4l_info(client, "saa711%d found (%s) @ 0x%x (%s)\n", chip_id, name, client->addr << 1, client->adapter->name);
1495 1486
1496 state = kzalloc(sizeof(struct saa711x_state), GFP_KERNEL); 1487 state = kzalloc(sizeof(struct saa711x_state), GFP_KERNEL);
1497 i2c_set_clientdata(client, state); 1488 i2c_set_clientdata(client, state);
1498 if (state == NULL) { 1489 if (state == NULL) {
1499 kfree(client);
1500 return -ENOMEM; 1490 return -ENOMEM;
1501 } 1491 }
1502 state->input = -1; 1492 state->input = -1;
@@ -1549,59 +1539,25 @@ static int saa711x_attach(struct i2c_adapter *adapter, int address, int kind)
1549 saa711x_writeregs(client, saa7115_init_misc); 1539 saa711x_writeregs(client, saa7115_init_misc);
1550 saa711x_set_v4lstd(client, V4L2_STD_NTSC); 1540 saa711x_set_v4lstd(client, V4L2_STD_NTSC);
1551 1541
1552 i2c_attach_client(client);
1553
1554 v4l_dbg(1, debug, client, "status: (1E) 0x%02x, (1F) 0x%02x\n", 1542 v4l_dbg(1, debug, client, "status: (1E) 0x%02x, (1F) 0x%02x\n",
1555 saa711x_read(client, R_1E_STATUS_BYTE_1_VD_DEC), saa711x_read(client, R_1F_STATUS_BYTE_2_VD_DEC)); 1543 saa711x_read(client, R_1E_STATUS_BYTE_1_VD_DEC), saa711x_read(client, R_1F_STATUS_BYTE_2_VD_DEC));
1556
1557 return 0; 1544 return 0;
1558} 1545}
1559 1546
1560static int saa711x_probe(struct i2c_adapter *adapter) 1547/* ----------------------------------------------------------------------- */
1561{
1562 if (adapter->class & I2C_CLASS_TV_ANALOG || adapter->class & I2C_CLASS_TV_DIGITAL)
1563 return i2c_probe(adapter, &addr_data, &saa711x_attach);
1564 return 0;
1565}
1566 1548
1567static int saa711x_detach(struct i2c_client *client) 1549static int saa7115_remove(struct i2c_client *client)
1568{ 1550{
1569 struct saa711x_state *state = i2c_get_clientdata(client); 1551 kfree(i2c_get_clientdata(client));
1570 int err;
1571
1572 err = i2c_detach_client(client);
1573 if (err) {
1574 return err;
1575 }
1576
1577 kfree(state);
1578 kfree(client);
1579 return 0; 1552 return 0;
1580} 1553}
1581 1554
1582/* ----------------------------------------------------------------------- */ 1555static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1583 1556 .name = "saa7115",
1584/* i2c implementation */ 1557 .driverid = I2C_DRIVERID_SAA711X,
1585static struct i2c_driver i2c_driver_saa711x = { 1558 .command = saa7115_command,
1586 .driver = { 1559 .probe = saa7115_probe,
1587 .name = "saa7115", 1560 .remove = saa7115_remove,
1588 }, 1561 .legacy_class = I2C_CLASS_TV_ANALOG | I2C_CLASS_TV_DIGITAL,
1589 .id = I2C_DRIVERID_SAA711X,
1590 .attach_adapter = saa711x_probe,
1591 .detach_client = saa711x_detach,
1592 .command = saa711x_command,
1593}; 1562};
1594 1563
1595
1596static int __init saa711x_init_module(void)
1597{
1598 return i2c_add_driver(&i2c_driver_saa711x);
1599}
1600
1601static void __exit saa711x_cleanup_module(void)
1602{
1603 i2c_del_driver(&i2c_driver_saa711x);
1604}
1605
1606module_init(saa711x_init_module);
1607module_exit(saa711x_cleanup_module);