Commit f2a01a00 authored by Douglas Schilling Landgraf's avatar Douglas Schilling Landgraf Committed by Mauro Carvalho Chehab

V4L/DVB (8937): em28xx: Fix and add some validations

Fixed and Added some validations
Signed-off-by: default avatarDouglas Schilling Landgraf <dougsland@linuxtv.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent a50f4a44
...@@ -336,8 +336,11 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len) ...@@ -336,8 +336,11 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
/* Check if board has eeprom */ /* Check if board has eeprom */
err = i2c_master_recv(&dev->i2c_client, &buf, 0); err = i2c_master_recv(&dev->i2c_client, &buf, 0);
if (err < 0) if (err < 0) {
return -1; em28xx_errdev("%s: i2c_master_recv failed! err [%d]\n",
__func__, err);
return err;
}
buf = 0; buf = 0;
...@@ -345,7 +348,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len) ...@@ -345,7 +348,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
if (err != 1) { if (err != 1) {
printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n", printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n",
dev->name, err); dev->name, err);
return -1; return err;
} }
while (size > 0) { while (size > 0) {
if (size > 16) if (size > 16)
...@@ -358,7 +361,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len) ...@@ -358,7 +361,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
printk(KERN_WARNING printk(KERN_WARNING
"%s: i2c eeprom read error (err=%d)\n", "%s: i2c eeprom read error (err=%d)\n",
dev->name, err); dev->name, err);
return -1; return err;
} }
size -= block; size -= block;
p += block; p += block;
...@@ -586,18 +589,31 @@ void em28xx_i2c_call_clients(struct em28xx *dev, unsigned int cmd, void *arg) ...@@ -586,18 +589,31 @@ void em28xx_i2c_call_clients(struct em28xx *dev, unsigned int cmd, void *arg)
*/ */
int em28xx_i2c_register(struct em28xx *dev) int em28xx_i2c_register(struct em28xx *dev)
{ {
int retval;
BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg); BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg);
BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req); BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req);
dev->i2c_adap = em28xx_adap_template; dev->i2c_adap = em28xx_adap_template;
dev->i2c_adap.dev.parent = &dev->udev->dev; dev->i2c_adap.dev.parent = &dev->udev->dev;
strcpy(dev->i2c_adap.name, dev->name); strcpy(dev->i2c_adap.name, dev->name);
dev->i2c_adap.algo_data = dev; dev->i2c_adap.algo_data = dev;
i2c_add_adapter(&dev->i2c_adap);
retval = i2c_add_adapter(&dev->i2c_adap);
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 = em28xx_client_template;
dev->i2c_client.adapter = &dev->i2c_adap; dev->i2c_client.adapter = &dev->i2c_adap;
em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata)); retval = em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata));
if (retval < 0) {
em28xx_errdev("%s: em28xx_i2_eeprom failed! retval [%d]\n",
__func__, retval);
return retval;
}
if (i2c_scan) if (i2c_scan)
em28xx_do_i2c_scan(dev); em28xx_do_i2c_scan(dev);
......
...@@ -513,10 +513,17 @@ static struct videobuf_queue_ops em28xx_video_qops = { ...@@ -513,10 +513,17 @@ static struct videobuf_queue_ops em28xx_video_qops = {
*/ */
static int em28xx_config(struct em28xx *dev) static int em28xx_config(struct em28xx *dev)
{ {
int retval;
/* Sets I2C speed to 100 KHz */ /* Sets I2C speed to 100 KHz */
if (!dev->is_em2800) if (!dev->is_em2800) {
em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1); retval = em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1);
if (retval < 0) {
em28xx_errdev("%s: em28xx_write_regs_req failed! retval [%d]\n",
__func__, retval);
return retval;
}
}
/* enable vbi capturing */ /* enable vbi capturing */
...@@ -1953,13 +1960,23 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, ...@@ -1953,13 +1960,23 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
} }
/* register i2c bus */ /* register i2c bus */
em28xx_i2c_register(dev); errCode = em28xx_i2c_register(dev);
if (errCode < 0) {
em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n",
__func__, errCode);
return errCode;
}
/* Do board specific init and eeprom reading */ /* Do board specific init and eeprom reading */
em28xx_card_setup(dev); em28xx_card_setup(dev);
/* Configure audio */ /* Configure audio */
em28xx_audio_analog_set(dev); errCode = em28xx_audio_analog_set(dev);
if (errCode < 0) {
em28xx_errdev("%s: em28xx_audio_analog_set - errCode [%d]!\n",
__func__, errCode);
return errCode;
}
/* configure the device */ /* configure the device */
em28xx_config_i2c(dev); em28xx_config_i2c(dev);
...@@ -1979,6 +1996,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, ...@@ -1979,6 +1996,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
dev->ctl_input = 2; dev->ctl_input = 2;
errCode = em28xx_config(dev); errCode = em28xx_config(dev);
if (errCode < 0) {
em28xx_errdev("%s: em28xx_config - errCode [%d]!\n",
__func__, errCode);
return errCode;
}
list_add_tail(&dev->devlist, &em28xx_devlist); list_add_tail(&dev->devlist, &em28xx_devlist);
...@@ -2031,9 +2053,20 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, ...@@ -2031,9 +2053,20 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
if (dev->has_msp34xx) { if (dev->has_msp34xx) {
/* Send a reset to other chips via gpio */ /* Send a reset to other chips via gpio */
em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1); errCode = em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
if (errCode < 0) {
em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(1) failed! errCode [%d]\n",
__func__, errCode);
return errCode;
}
msleep(3); msleep(3);
em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
errCode = em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
if (errCode < 0) {
em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(2) failed! errCode [%d]\n",
__func__, errCode);
return errCode;
}
msleep(3); msleep(3);
} }
......
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