Skip to content

Commit

Permalink
[media] hdpvr: fix up i2c device registration
Browse files Browse the repository at this point in the history
We have to actually call i2c_new_device() once for each of the rx and tx
addresses. Also improve error-handling and device remove i2c cleanup.

Reviewed-by: Andy Walls <awalls@md.metrocast.net>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Jarod Wilson authored and Mauro Carvalho Chehab committed Jan 31, 2011
1 parent 86ee659 commit 7f2a06d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
24 changes: 20 additions & 4 deletions drivers/media/video/hdpvr/hdpvr-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ static int hdpvr_probe(struct usb_interface *interface,
struct hdpvr_device *dev;
struct usb_host_interface *iface_desc;
struct usb_endpoint_descriptor *endpoint;
struct i2c_client *client;
size_t buffer_size;
int i;
int retval = -ENOMEM;
Expand Down Expand Up @@ -381,20 +382,32 @@ static int hdpvr_probe(struct usb_interface *interface,
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
retval = hdpvr_register_i2c_adapter(dev);
if (retval < 0) {
v4l2_err(&dev->v4l2_dev, "registering i2c adapter failed\n");
v4l2_err(&dev->v4l2_dev, "i2c adapter register failed\n");
goto error;
}

retval = hdpvr_register_i2c_ir(dev);
if (retval < 0)
v4l2_err(&dev->v4l2_dev, "registering i2c IR devices failed\n");
client = hdpvr_register_ir_rx_i2c(dev);
if (!client) {
v4l2_err(&dev->v4l2_dev, "i2c IR RX device register failed\n");
goto reg_fail;
}

client = hdpvr_register_ir_tx_i2c(dev);
if (!client) {
v4l2_err(&dev->v4l2_dev, "i2c IR TX device register failed\n");
goto reg_fail;
}
#endif

/* let the user know what node this device is now attached to */
v4l2_info(&dev->v4l2_dev, "device now attached to %s\n",
video_device_node_name(dev->video_dev));
return 0;

reg_fail:
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
i2c_del_adapter(&dev->i2c_adapter);
#endif
error:
if (dev) {
/* Destroy single thread */
Expand Down Expand Up @@ -424,6 +437,9 @@ static void hdpvr_disconnect(struct usb_interface *interface)
mutex_lock(&dev->io_mutex);
hdpvr_cancel_queue(dev);
mutex_unlock(&dev->io_mutex);
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
i2c_del_adapter(&dev->i2c_adapter);
#endif
video_unregister_device(dev->video_dev);
atomic_dec(&dev_nr);
}
Expand Down
30 changes: 19 additions & 11 deletions drivers/media/video/hdpvr/hdpvr-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,34 @@
#define Z8F0811_IR_RX_I2C_ADDR 0x71


static struct i2c_board_info hdpvr_i2c_board_info = {
I2C_BOARD_INFO("ir_tx_z8f0811_hdpvr", Z8F0811_IR_TX_I2C_ADDR),
I2C_BOARD_INFO("ir_rx_z8f0811_hdpvr", Z8F0811_IR_RX_I2C_ADDR),
};
struct i2c_client *hdpvr_register_ir_tx_i2c(struct hdpvr_device *dev)
{
struct IR_i2c_init_data *init_data = &dev->ir_i2c_init_data;
struct i2c_board_info hdpvr_ir_tx_i2c_board_info = {
I2C_BOARD_INFO("ir_tx_z8f0811_hdpvr", Z8F0811_IR_TX_I2C_ADDR),
};

init_data->name = "HD-PVR";
hdpvr_ir_tx_i2c_board_info.platform_data = init_data;

int hdpvr_register_i2c_ir(struct hdpvr_device *dev)
return i2c_new_device(&dev->i2c_adapter, &hdpvr_ir_tx_i2c_board_info);
}

struct i2c_client *hdpvr_register_ir_rx_i2c(struct hdpvr_device *dev)
{
struct i2c_client *c;
struct IR_i2c_init_data *init_data = &dev->ir_i2c_init_data;
struct i2c_board_info hdpvr_ir_rx_i2c_board_info = {
I2C_BOARD_INFO("ir_rx_z8f0811_hdpvr", Z8F0811_IR_RX_I2C_ADDR),
};

/* Our default information for ir-kbd-i2c.c to use */
init_data->ir_codes = RC_MAP_HAUPPAUGE_NEW;
init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
init_data->type = RC_TYPE_RC5;
init_data->name = "HD PVR";
hdpvr_i2c_board_info.platform_data = init_data;

c = i2c_new_device(&dev->i2c_adapter, &hdpvr_i2c_board_info);
init_data->name = "HD-PVR";
hdpvr_ir_rx_i2c_board_info.platform_data = init_data;

return (c == NULL) ? -ENODEV : 0;
return i2c_new_device(&dev->i2c_adapter, &hdpvr_ir_rx_i2c_board_info);
}

static int hdpvr_i2c_read(struct hdpvr_device *dev, int bus,
Expand Down
3 changes: 2 additions & 1 deletion drivers/media/video/hdpvr/hdpvr.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ int hdpvr_cancel_queue(struct hdpvr_device *dev);
/* i2c adapter registration */
int hdpvr_register_i2c_adapter(struct hdpvr_device *dev);

int hdpvr_register_i2c_ir(struct hdpvr_device *dev);
struct i2c_client *hdpvr_register_ir_rx_i2c(struct hdpvr_device *dev);
struct i2c_client *hdpvr_register_ir_tx_i2c(struct hdpvr_device *dev);

/*========================================================================*/
/* buffer management */
Expand Down

0 comments on commit 7f2a06d

Please sign in to comment.