RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / media / dvb / b2c2 / flexcop-eeprom.c
blob356f90068613a9cf0eaa4cfc686dcde02dea8072
1 /*
2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * flexcop-eeprom.c - eeprom access methods (currently only MAC address reading)
4 * see flexcop.c for copyright information
5 */
6 #include "flexcop.h"
9 static u8 calc_lrc(u8 *buf, int len)
11 int i;
12 u8 sum = 0;
13 for (i = 0; i < len; i++)
14 sum = sum ^ buf[i];
15 return sum;
18 static int flexcop_eeprom_request(struct flexcop_device *fc,
19 flexcop_access_op_t op, u16 addr, u8 *buf, u16 len, int retries)
21 int i,ret = 0;
22 u8 chipaddr = 0x50 | ((addr >> 8) & 3);
23 for (i = 0; i < retries; i++) {
24 ret = fc->i2c_request(&fc->fc_i2c_adap[1], op, chipaddr,
25 addr & 0xff, buf, len);
26 if (ret == 0)
27 break;
29 return ret;
32 static int flexcop_eeprom_lrc_read(struct flexcop_device *fc, u16 addr,
33 u8 *buf, u16 len, int retries)
35 int ret = flexcop_eeprom_request(fc, FC_READ, addr, buf, len, retries);
36 if (ret == 0)
37 if (calc_lrc(buf, len - 1) != buf[len - 1])
38 ret = -EINVAL;
39 return ret;
42 /* JJ's comment about extended == 1: it is not presently used anywhere but was
43 * added to the low-level functions for possible support of EUI64 */
44 int flexcop_eeprom_check_mac_addr(struct flexcop_device *fc, int extended)
46 u8 buf[8];
47 int ret = 0;
49 if ((ret = flexcop_eeprom_lrc_read(fc,0x3f8,buf,8,4)) == 0) {
50 if (extended != 0) {
51 err("TODO: extended (EUI64) MAC addresses aren't "
52 "completely supported yet");
53 ret = -EINVAL;
54 } else
55 memcpy(fc->dvb_adapter.proposed_mac,buf,6);
57 return ret;
59 EXPORT_SYMBOL(flexcop_eeprom_check_mac_addr);