Commit c7a45e5b authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

[media] em28xx: Prepare to support 2 different I2C buses

Newer em28xx devices have 2 buses. Change the logic to allow
using both buses.
This patch was generated by this small script:
for i in drivers/media/usb/em28xx/*.c; do
	sed 's,->i2c_adap,->i2c_adap[dev->def_i2c_bus],g;s,->i2c_client,->i2c_client[dev->def_i2c_bus],'
done
Of course, em28xx.h needed manual edit.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent da508f57
......@@ -2249,7 +2249,7 @@ static int em28xx_initialize_mt9m111(struct em28xx *dev)
};
for (i = 0; i < ARRAY_SIZE(regs); i++)
i2c_master_send(&dev->i2c_client, &regs[i][0], 3);
i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], &regs[i][0], 3);
return 0;
}
......@@ -2276,7 +2276,7 @@ static int em28xx_initialize_mt9m001(struct em28xx *dev)
};
for (i = 0; i < ARRAY_SIZE(regs); i++)
i2c_master_send(&dev->i2c_client, &regs[i][0], 3);
i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], &regs[i][0], 3);
return 0;
}
......@@ -2294,10 +2294,10 @@ static int em28xx_hint_sensor(struct em28xx *dev)
u16 version;
/* Micron sensor detection */
dev->i2c_client.addr = 0xba >> 1;
dev->i2c_client[dev->def_i2c_bus].addr = 0xba >> 1;
cmd = 0;
i2c_master_send(&dev->i2c_client, &cmd, 1);
rc = i2c_master_recv(&dev->i2c_client, (char *)&version_be, 2);
i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], &cmd, 1);
rc = i2c_master_recv(&dev->i2c_client[dev->def_i2c_bus], (char *)&version_be, 2);
if (rc != 2)
return -EINVAL;
......@@ -2748,8 +2748,8 @@ static void em28xx_card_setup(struct em28xx *dev)
#endif
/* Call first TVeeprom */
dev->i2c_client.addr = 0xa0 >> 1;
tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
dev->i2c_client[dev->def_i2c_bus].addr = 0xa0 >> 1;
tveeprom_hauppauge_analog(&dev->i2c_client[dev->def_i2c_bus], &tv, dev->eedata);
dev->tuner_type = tv.tuner_type;
......@@ -2841,15 +2841,15 @@ static void em28xx_card_setup(struct em28xx *dev)
/* request some modules */
if (dev->board.has_msp34xx)
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
"msp3400", 0, msp3400_addrs);
if (dev->board.decoder == EM28XX_SAA711X)
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
"saa7115_auto", 0, saa711x_addrs);
if (dev->board.decoder == EM28XX_TVP5150)
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
"tvp5150", 0, tvp5150_addrs);
if (dev->em28xx_sensor == EM28XX_MT9V011) {
......@@ -2861,25 +2861,25 @@ static void em28xx_card_setup(struct em28xx *dev)
};
pdata.xtal = dev->sensor_xtal;
v4l2_i2c_new_subdev_board(&dev->v4l2_dev, &dev->i2c_adap,
v4l2_i2c_new_subdev_board(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
&mt9v011_info, NULL);
}
if (dev->board.adecoder == EM28XX_TVAUDIO)
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
"tvaudio", dev->board.tvaudio_addr, NULL);
if (dev->board.tuner_type != TUNER_ABSENT) {
int has_demod = (dev->tda9887_conf & TDA9887_PRESENT);
if (dev->board.radio.type)
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
"tuner", dev->board.radio_addr, NULL);
if (has_demod)
v4l2_i2c_new_subdev(&dev->v4l2_dev,
&dev->i2c_adap, "tuner",
&dev->i2c_adap[dev->def_i2c_bus], "tuner",
0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
if (dev->tuner_addr == 0) {
enum v4l2_i2c_tuner_type type =
......@@ -2887,13 +2887,13 @@ static void em28xx_card_setup(struct em28xx *dev)
struct v4l2_subdev *sd;
sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
&dev->i2c_adap, "tuner",
&dev->i2c_adap[dev->def_i2c_bus], "tuner",
0, v4l2_i2c_tuner_addrs(type));
if (sd)
dev->tuner_addr = v4l2_i2c_subdev_addr(sd);
} else {
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap[dev->def_i2c_bus],
"tuner", dev->tuner_addr, NULL);
}
}
......
This diff is collapsed.
......@@ -384,7 +384,7 @@ static int em28xx_i2c_read_block(struct em28xx *dev, u16 addr, bool addr_w16,
/* Select address */
buf[0] = addr >> 8;
buf[1] = addr & 0xff;
ret = i2c_master_send(&dev->i2c_client, buf + !addr_w16, 1 + addr_w16);
ret = i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], buf + !addr_w16, 1 + addr_w16);
if (ret < 0)
return ret;
/* Read data */
......@@ -398,7 +398,7 @@ static int em28xx_i2c_read_block(struct em28xx *dev, u16 addr, bool addr_w16,
else
rsize = remain;
ret = i2c_master_recv(&dev->i2c_client, data, rsize);
ret = i2c_master_recv(&dev->i2c_client[dev->def_i2c_bus], data, rsize);
if (ret < 0)
return ret;
......@@ -422,10 +422,10 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, u8 **eedata, u16 *eedata_len)
*eedata = NULL;
*eedata_len = 0;
dev->i2c_client.addr = 0xa0 >> 1;
dev->i2c_client[dev->def_i2c_bus].addr = 0xa0 >> 1;
/* Check if board has eeprom */
err = i2c_master_recv(&dev->i2c_client, &buf, 0);
err = i2c_master_recv(&dev->i2c_client[dev->def_i2c_bus], &buf, 0);
if (err < 0) {
em28xx_info("board has no eeprom\n");
return -ENODEV;
......@@ -652,8 +652,8 @@ void em28xx_do_i2c_scan(struct em28xx *dev)
memset(i2c_devicelist, 0, ARRAY_SIZE(i2c_devicelist));
for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) {
dev->i2c_client.addr = i;
rc = i2c_master_recv(&dev->i2c_client, &buf, 0);
dev->i2c_client[dev->def_i2c_bus].addr = i;
rc = i2c_master_recv(&dev->i2c_client[dev->def_i2c_bus], &buf, 0);
if (rc < 0)
continue;
i2c_devicelist[i] = i;
......@@ -675,21 +675,21 @@ int em28xx_i2c_register(struct em28xx *dev)
BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg);
BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req);
dev->i2c_adap = em28xx_adap_template;
dev->i2c_adap.dev.parent = &dev->udev->dev;
strcpy(dev->i2c_adap.name, dev->name);
dev->i2c_adap.algo_data = dev;
i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
dev->i2c_adap[dev->def_i2c_bus] = em28xx_adap_template;
dev->i2c_adap[dev->def_i2c_bus].dev.parent = &dev->udev->dev;
strcpy(dev->i2c_adap[dev->def_i2c_bus].name, dev->name);
dev->i2c_adap[dev->def_i2c_bus].algo_data = dev;
i2c_set_adapdata(&dev->i2c_adap[dev->def_i2c_bus], &dev->v4l2_dev);
retval = i2c_add_adapter(&dev->i2c_adap);
retval = i2c_add_adapter(&dev->i2c_adap[dev->def_i2c_bus]);
if (retval < 0) {
em28xx_errdev("%s: i2c_add_adapter failed! retval [%d]\n",
__func__, retval);
return retval;
}
dev->i2c_client = em28xx_client_template;
dev->i2c_client.adapter = &dev->i2c_adap;
dev->i2c_client[dev->def_i2c_bus] = em28xx_client_template;
dev->i2c_client[dev->def_i2c_bus].adapter = &dev->i2c_adap[dev->def_i2c_bus];
retval = em28xx_i2c_eeprom(dev, &dev->eedata, &dev->eedata_len);
if ((retval < 0) && (retval != -ENODEV)) {
......@@ -711,6 +711,6 @@ int em28xx_i2c_register(struct em28xx *dev)
*/
int em28xx_i2c_unregister(struct em28xx *dev)
{
i2c_del_adapter(&dev->i2c_adap);
i2c_del_adapter(&dev->i2c_adap[dev->def_i2c_bus]);
return 0;
}
......@@ -280,11 +280,12 @@ static int em2874_polling_getkey(struct em28xx_IR *ir,
static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir)
{
struct em28xx *dev = ir->dev;
static u32 ir_key;
int rc;
struct i2c_client client;
client.adapter = &ir->dev->i2c_adap;
client.adapter = &ir->dev->i2c_adap[dev->def_i2c_bus];
client.addr = ir->i2c_dev_addr;
rc = ir->get_key_i2c(&client, &ir_key);
......@@ -461,7 +462,7 @@ static int em28xx_probe_i2c_ir(struct em28xx *dev)
};
while (addr_list[i] != I2C_CLIENT_END) {
if (i2c_probe_func_quick_read(&dev->i2c_adap, addr_list[i]) == 1)
if (i2c_probe_func_quick_read(&dev->i2c_adap[dev->def_i2c_bus], addr_list[i]) == 1)
return addr_list[i];
i++;
}
......
......@@ -157,6 +157,9 @@
#define EM28XX_NUM_BUFS 5
#define EM28XX_DVB_NUM_BUFS 5
/* max number of I2C buses on em28xx devices */
#define NUM_I2C_BUSES 2
/* isoc transfers: number of packets for each buffer
windows requests only 64 packets .. so we better do the same
this is what I found out for all alternate numbers there!
......@@ -507,10 +510,13 @@ struct em28xx {
int tuner_type; /* type of the tuner */
int tuner_addr; /* tuner address */
int tda9887_conf;
/* i2c i/o */
struct i2c_adapter i2c_adap;
struct i2c_client i2c_client;
struct i2c_adapter i2c_adap[NUM_I2C_BUSES];
struct i2c_client i2c_client[NUM_I2C_BUSES];
unsigned char eeprom_addrwidth_16bit:1;
int def_i2c_bus; /* Default I2C bus */
/* video for linux */
int users; /* user count for exclusive use */
int streaming_users; /* Number of actively streaming users */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment