aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/usb/dvb-usb-v2
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2012-09-12 19:23:51 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-09-23 19:48:41 -0400
commit2e35c66f138c6a4f50da863a82983a541f1c2a24 (patch)
tree78f30199400f681efb8fff3d3bc4506283127754 /drivers/media/usb/dvb-usb-v2
parentf224749b68034619ff722576f46e4a4932d69d27 (diff)
[media] af9015: improve af9015_eeprom_hash()
Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/usb/dvb-usb-v2')
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9015.c49
1 files changed, 20 insertions, 29 deletions
diff --git a/drivers/media/usb/dvb-usb-v2/af9015.c b/drivers/media/usb/dvb-usb-v2/af9015.c
index c429da7da95d..a4be303edb4f 100644
--- a/drivers/media/usb/dvb-usb-v2/af9015.c
+++ b/drivers/media/usb/dvb-usb-v2/af9015.c
@@ -398,43 +398,34 @@ error:
398static int af9015_eeprom_hash(struct dvb_usb_device *d) 398static int af9015_eeprom_hash(struct dvb_usb_device *d)
399{ 399{
400 struct af9015_state *state = d_to_priv(d); 400 struct af9015_state *state = d_to_priv(d);
401 int ret; 401 int ret, i;
402 static const unsigned int eeprom_size = 256; 402 static const unsigned int AF9015_EEPROM_SIZE = 256;
403 unsigned int reg; 403 u8 buf[AF9015_EEPROM_SIZE];
404 u8 val, *eeprom; 404 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, NULL};
405 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val}; 405
406 406 /* read eeprom */
407 eeprom = kmalloc(eeprom_size, GFP_KERNEL); 407 for (i = 0; i < AF9015_EEPROM_SIZE; i++) {
408 if (eeprom == NULL) 408 req.addr = i;
409 return -ENOMEM; 409 req.data = &buf[i];
410
411 for (reg = 0; reg < eeprom_size; reg++) {
412 req.addr = reg;
413 ret = af9015_ctrl_msg(d, &req); 410 ret = af9015_ctrl_msg(d, &req);
414 if (ret) 411 if (ret < 0)
415 goto free; 412 goto err;
416
417 eeprom[reg] = val;
418 } 413 }
419 414
420 for (reg = 0; reg < eeprom_size; reg += 16) 415 /* calculate checksum */
421 dev_dbg(&d->udev->dev, "%s: %*ph\n", __func__, 16, 416 for (i = 0; i < AF9015_EEPROM_SIZE / sizeof(u32); i++) {
422 eeprom + reg);
423
424 BUG_ON(eeprom_size % 4);
425
426 state->eeprom_sum = 0;
427 for (reg = 0; reg < eeprom_size / sizeof(u32); reg++) {
428 state->eeprom_sum *= GOLDEN_RATIO_PRIME_32; 417 state->eeprom_sum *= GOLDEN_RATIO_PRIME_32;
429 state->eeprom_sum += le32_to_cpu(((u32 *)eeprom)[reg]); 418 state->eeprom_sum += le32_to_cpu(((u32 *)buf)[i]);
430 } 419 }
431 420
421 for (i = 0; i < AF9015_EEPROM_SIZE; i += 16)
422 dev_dbg(&d->udev->dev, "%s: %*ph\n", __func__, 16, buf + i);
423
432 dev_dbg(&d->udev->dev, "%s: eeprom sum=%.8x\n", 424 dev_dbg(&d->udev->dev, "%s: eeprom sum=%.8x\n",
433 __func__, state->eeprom_sum); 425 __func__, state->eeprom_sum);
434 426 return 0;
435 ret = 0; 427err:
436free: 428 dev_err(&d->udev->dev, "%s: eeprom failed=%d\n", KBUILD_MODNAME, ret);
437 kfree(eeprom);
438 return ret; 429 return ret;
439} 430}
440 431