1 // SPDX-License-Identifier: GPL-2.0
3 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
4 * flexcop-eeprom.c - eeprom access methods (currently only MAC address reading)
5 * see flexcop.c for copyright information
10 /*EEPROM (Skystar2 has one "24LC08B" chip on board) */
11 static int eeprom_write(struct adapter *adapter, u16 addr, u8 *buf, u16 len)
13 return flex_i2c_write(adapter, 0x20000000, 0x50, addr, buf, len);
16 static int eeprom_lrc_write(struct adapter *adapter, u32 addr,
17 u32 len, u8 *wbuf, u8 *rbuf, int retries)
21 for (i = 0; i < retries; i++) {
22 if (eeprom_write(adapter, addr, wbuf, len) == len) {
23 if (eeprom_lrc_read(adapter, addr, len, rbuf, retries) == 1)
30 /* These functions could be used to unlock SkyStar2 cards. */
32 static int eeprom_writeKey(struct adapter *adapter, u8 *key, u32 len)
40 memcpy(wbuf, key, len);
44 wbuf[19] = calc_lrc(wbuf, 19);
45 return eeprom_lrc_write(adapter, 0x3e4, 20, wbuf, rbuf, 4);
48 static int eeprom_readKey(struct adapter *adapter, u8 *key, u32 len)
55 if (eeprom_lrc_read(adapter, 0x3e4, 20, buf, 4) == 0)
58 memcpy(key, buf, len);
62 static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 *mac)
83 tmp[7] = calc_lrc(tmp, 7);
85 if (eeprom_write(adapter, 0x3f8, tmp, 8) == 8)
90 static int flexcop_eeprom_read(struct flexcop_device *fc,
91 u16 addr, u8 *buf, u16 len)
93 return fc->i2c_request(fc,FC_READ,FC_I2C_PORT_EEPROM,0x50,addr,buf,len);
98 static u8 calc_lrc(u8 *buf, int len)
102 for (i = 0; i < len; i++)
107 static int flexcop_eeprom_request(struct flexcop_device *fc,
108 flexcop_access_op_t op, u16 addr, u8 *buf, u16 len, int retries)
111 u8 chipaddr = 0x50 | ((addr >> 8) & 3);
112 for (i = 0; i < retries; i++) {
113 ret = fc->i2c_request(&fc->fc_i2c_adap[1], op, chipaddr,
114 addr & 0xff, buf, len);
121 static int flexcop_eeprom_lrc_read(struct flexcop_device *fc, u16 addr,
122 u8 *buf, u16 len, int retries)
124 int ret = flexcop_eeprom_request(fc, FC_READ, addr, buf, len, retries);
126 if (calc_lrc(buf, len - 1) != buf[len - 1])
131 /* JJ's comment about extended == 1: it is not presently used anywhere but was
132 * added to the low-level functions for possible support of EUI64 */
133 int flexcop_eeprom_check_mac_addr(struct flexcop_device *fc, int extended)
138 if ((ret = flexcop_eeprom_lrc_read(fc,0x3f8,buf,8,4)) == 0) {
140 err("TODO: extended (EUI64) MAC addresses aren't completely supported yet");
143 memcpy(fc->dvb_adapter.proposed_mac,buf,6);
147 EXPORT_SYMBOL(flexcop_eeprom_check_mac_addr);