提交 2e35c66f 编写于 作者: A Antti Palosaari 提交者: Mauro Carvalho Chehab

[media] af9015: improve af9015_eeprom_hash()

Signed-off-by: NAntti Palosaari <crope@iki.fi>
Signed-off-by: NMauro Carvalho Chehab <mchehab@redhat.com>
上级 f224749b
...@@ -398,43 +398,34 @@ static int af9015_download_firmware(struct dvb_usb_device *d, ...@@ -398,43 +398,34 @@ static int af9015_download_firmware(struct dvb_usb_device *d,
static int af9015_eeprom_hash(struct dvb_usb_device *d) static int af9015_eeprom_hash(struct dvb_usb_device *d)
{ {
struct af9015_state *state = d_to_priv(d); struct af9015_state *state = d_to_priv(d);
int ret; int ret, i;
static const unsigned int eeprom_size = 256; static const unsigned int AF9015_EEPROM_SIZE = 256;
unsigned int reg; u8 buf[AF9015_EEPROM_SIZE];
u8 val, *eeprom; struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, NULL};
struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
/* read eeprom */
eeprom = kmalloc(eeprom_size, GFP_KERNEL); for (i = 0; i < AF9015_EEPROM_SIZE; i++) {
if (eeprom == NULL) req.addr = i;
return -ENOMEM; req.data = &buf[i];
for (reg = 0; reg < eeprom_size; reg++) {
req.addr = reg;
ret = af9015_ctrl_msg(d, &req); ret = af9015_ctrl_msg(d, &req);
if (ret) if (ret < 0)
goto free; goto err;
eeprom[reg] = val;
} }
for (reg = 0; reg < eeprom_size; reg += 16) /* calculate checksum */
dev_dbg(&d->udev->dev, "%s: %*ph\n", __func__, 16, for (i = 0; i < AF9015_EEPROM_SIZE / sizeof(u32); i++) {
eeprom + reg);
BUG_ON(eeprom_size % 4);
state->eeprom_sum = 0;
for (reg = 0; reg < eeprom_size / sizeof(u32); reg++) {
state->eeprom_sum *= GOLDEN_RATIO_PRIME_32; state->eeprom_sum *= GOLDEN_RATIO_PRIME_32;
state->eeprom_sum += le32_to_cpu(((u32 *)eeprom)[reg]); state->eeprom_sum += le32_to_cpu(((u32 *)buf)[i]);
} }
for (i = 0; i < AF9015_EEPROM_SIZE; i += 16)
dev_dbg(&d->udev->dev, "%s: %*ph\n", __func__, 16, buf + i);
dev_dbg(&d->udev->dev, "%s: eeprom sum=%.8x\n", dev_dbg(&d->udev->dev, "%s: eeprom sum=%.8x\n",
__func__, state->eeprom_sum); __func__, state->eeprom_sum);
return 0;
ret = 0; err:
free: dev_err(&d->udev->dev, "%s: eeprom failed=%d\n", KBUILD_MODNAME, ret);
kfree(eeprom);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册