diff options
author | Jiri Slaby <jslaby@suse.cz> | 2010-01-22 10:10:52 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-02-26 13:10:52 -0500 |
commit | 6c614044ff00bf3e7403ac6c4ed4e53db8c349f3 (patch) | |
tree | 52ea3e4cdeae03ae444cd155ab96cf87e94c04c4 | |
parent | 0b32d65cd7938d31eebd9c62aab6a59a3c4cf0f8 (diff) |
V4L/DVB: media: dvb/af9015, implement eeprom hashing
This will be useful for matching of IR tables later.
We read the eeprom anyway for dumping. Switch the dumping to
print_hex_dump_bytes and compute hash above that by
hash = 0;
for (u32 VAL) in (eeprom):
hash *= GOLDEN_RATIO_PRIME_32
hash += VAL; // while preserving endinaness
The computation is moved earlier to the flow, namely from
af9015_af9013_frontend_attach to af9015_read_config, so that
we can access the sum in af9015_read_config already.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Acked-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/dvb/dvb-usb/af9015.c | 65 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/af9015.h | 1 |
2 files changed, 44 insertions, 22 deletions
diff --git a/drivers/media/dvb/dvb-usb/af9015.c b/drivers/media/dvb/dvb-usb/af9015.c index 8b60a601fb82..9f8370f4cc81 100644 --- a/drivers/media/dvb/dvb-usb/af9015.c +++ b/drivers/media/dvb/dvb-usb/af9015.c | |||
@@ -21,6 +21,8 @@ | |||
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/hash.h> | ||
25 | |||
24 | #include "af9015.h" | 26 | #include "af9015.h" |
25 | #include "af9013.h" | 27 | #include "af9013.h" |
26 | #include "mt2060.h" | 28 | #include "mt2060.h" |
@@ -553,26 +555,45 @@ exit: | |||
553 | return ret; | 555 | return ret; |
554 | } | 556 | } |
555 | 557 | ||
556 | /* dump eeprom */ | 558 | /* hash (and dump) eeprom */ |
557 | static int af9015_eeprom_dump(struct dvb_usb_device *d) | 559 | static int af9015_eeprom_hash(struct usb_device *udev) |
558 | { | 560 | { |
559 | u8 reg, val; | 561 | static const unsigned int eeprom_size = 256; |
562 | unsigned int reg; | ||
563 | int ret; | ||
564 | u8 val, *eeprom; | ||
565 | struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val}; | ||
560 | 566 | ||
561 | for (reg = 0; ; reg++) { | 567 | eeprom = kmalloc(eeprom_size, GFP_KERNEL); |
562 | if (reg % 16 == 0) { | 568 | if (eeprom == NULL) |
563 | if (reg) | 569 | return -ENOMEM; |
564 | deb_info(KERN_CONT "\n"); | 570 | |
565 | deb_info(KERN_DEBUG "%02x:", reg); | 571 | for (reg = 0; reg < eeprom_size; reg++) { |
566 | } | 572 | req.addr = reg; |
567 | if (af9015_read_reg_i2c(d, AF9015_I2C_EEPROM, reg, &val) == 0) | 573 | ret = af9015_rw_udev(udev, &req); |
568 | deb_info(KERN_CONT " %02x", val); | 574 | if (ret) |
569 | else | 575 | goto free; |
570 | deb_info(KERN_CONT " --"); | 576 | eeprom[reg] = val; |
571 | if (reg == 0xff) | ||
572 | break; | ||
573 | } | 577 | } |
574 | deb_info(KERN_CONT "\n"); | 578 | |
575 | return 0; | 579 | if (dvb_usb_af9015_debug & 0x01) |
580 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, eeprom, | ||
581 | eeprom_size); | ||
582 | |||
583 | BUG_ON(eeprom_size % 4); | ||
584 | |||
585 | af9015_config.eeprom_sum = 0; | ||
586 | for (reg = 0; reg < eeprom_size / sizeof(u32); reg++) { | ||
587 | af9015_config.eeprom_sum *= GOLDEN_RATIO_PRIME_32; | ||
588 | af9015_config.eeprom_sum += le32_to_cpu(((u32 *)eeprom)[reg]); | ||
589 | } | ||
590 | |||
591 | deb_info("%s: eeprom sum=%.8x\n", __func__, af9015_config.eeprom_sum); | ||
592 | |||
593 | ret = 0; | ||
594 | free: | ||
595 | kfree(eeprom); | ||
596 | return ret; | ||
576 | } | 597 | } |
577 | 598 | ||
578 | static int af9015_download_ir_table(struct dvb_usb_device *d) | 599 | static int af9015_download_ir_table(struct dvb_usb_device *d) |
@@ -728,6 +749,11 @@ static int af9015_read_config(struct usb_device *udev) | |||
728 | } | 749 | } |
729 | if (ret) | 750 | if (ret) |
730 | goto error; | 751 | goto error; |
752 | |||
753 | ret = af9015_eeprom_hash(udev); | ||
754 | if (ret) | ||
755 | goto error; | ||
756 | |||
731 | deb_info("%s: IR mode:%d\n", __func__, val); | 757 | deb_info("%s: IR mode:%d\n", __func__, val); |
732 | for (i = 0; i < af9015_properties_count; i++) { | 758 | for (i = 0; i < af9015_properties_count; i++) { |
733 | if (val == AF9015_IR_MODE_DISABLED) { | 759 | if (val == AF9015_IR_MODE_DISABLED) { |
@@ -1125,11 +1151,6 @@ static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap) | |||
1125 | 1151 | ||
1126 | deb_info("%s: init I2C\n", __func__); | 1152 | deb_info("%s: init I2C\n", __func__); |
1127 | ret = af9015_i2c_init(adap->dev); | 1153 | ret = af9015_i2c_init(adap->dev); |
1128 | |||
1129 | /* dump eeprom (debug) */ | ||
1130 | ret = af9015_eeprom_dump(adap->dev); | ||
1131 | if (ret) | ||
1132 | return ret; | ||
1133 | } else { | 1154 | } else { |
1134 | /* select I2C adapter */ | 1155 | /* select I2C adapter */ |
1135 | i2c_adap = &state->i2c_adap; | 1156 | i2c_adap = &state->i2c_adap; |
diff --git a/drivers/media/dvb/dvb-usb/af9015.h b/drivers/media/dvb/dvb-usb/af9015.h index 931c8515830d..ef36b1831490 100644 --- a/drivers/media/dvb/dvb-usb/af9015.h +++ b/drivers/media/dvb/dvb-usb/af9015.h | |||
@@ -107,6 +107,7 @@ struct af9015_config { | |||
107 | u16 mt2060_if1[2]; | 107 | u16 mt2060_if1[2]; |
108 | u16 firmware_size; | 108 | u16 firmware_size; |
109 | u16 firmware_checksum; | 109 | u16 firmware_checksum; |
110 | u32 eeprom_sum; | ||
110 | u8 *ir_table; | 111 | u8 *ir_table; |
111 | u16 ir_table_size; | 112 | u16 ir_table_size; |
112 | }; | 113 | }; |