Path: blob/master/drivers/media/dvb/b2c2/flexcop-eeprom.c
15111 views
/*1* Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III2* flexcop-eeprom.c - eeprom access methods (currently only MAC address reading)3* see flexcop.c for copyright information4*/5#include "flexcop.h"67#if 08/*EEPROM (Skystar2 has one "24LC08B" chip on board) */9static int eeprom_write(struct adapter *adapter, u16 addr, u8 *buf, u16 len)10{11return flex_i2c_write(adapter, 0x20000000, 0x50, addr, buf, len);12}1314static int eeprom_lrc_write(struct adapter *adapter, u32 addr,15u32 len, u8 *wbuf, u8 *rbuf, int retries)16{17int i;1819for (i = 0; i < retries; i++) {20if (eeprom_write(adapter, addr, wbuf, len) == len) {21if (eeprom_lrc_read(adapter, addr, len, rbuf, retries) == 1)22return 1;23}24}25return 0;26}2728/* These functions could be used to unlock SkyStar2 cards. */2930static int eeprom_writeKey(struct adapter *adapter, u8 *key, u32 len)31{32u8 rbuf[20];33u8 wbuf[20];3435if (len != 16)36return 0;3738memcpy(wbuf, key, len);39wbuf[16] = 0;40wbuf[17] = 0;41wbuf[18] = 0;42wbuf[19] = calc_lrc(wbuf, 19);43return eeprom_lrc_write(adapter, 0x3e4, 20, wbuf, rbuf, 4);44}4546static int eeprom_readKey(struct adapter *adapter, u8 *key, u32 len)47{48u8 buf[20];4950if (len != 16)51return 0;5253if (eeprom_lrc_read(adapter, 0x3e4, 20, buf, 4) == 0)54return 0;5556memcpy(key, buf, len);57return 1;58}5960static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 *mac)61{62u8 tmp[8];6364if (type != 0) {65tmp[0] = mac[0];66tmp[1] = mac[1];67tmp[2] = mac[2];68tmp[3] = mac[5];69tmp[4] = mac[6];70tmp[5] = mac[7];71} else {72tmp[0] = mac[0];73tmp[1] = mac[1];74tmp[2] = mac[2];75tmp[3] = mac[3];76tmp[4] = mac[4];77tmp[5] = mac[5];78}7980tmp[6] = 0;81tmp[7] = calc_lrc(tmp, 7);8283if (eeprom_write(adapter, 0x3f8, tmp, 8) == 8)84return 1;85return 0;86}8788static int flexcop_eeprom_read(struct flexcop_device *fc,89u16 addr, u8 *buf, u16 len)90{91return fc->i2c_request(fc,FC_READ,FC_I2C_PORT_EEPROM,0x50,addr,buf,len);92}9394#endif9596static u8 calc_lrc(u8 *buf, int len)97{98int i;99u8 sum = 0;100for (i = 0; i < len; i++)101sum = sum ^ buf[i];102return sum;103}104105static int flexcop_eeprom_request(struct flexcop_device *fc,106flexcop_access_op_t op, u16 addr, u8 *buf, u16 len, int retries)107{108int i,ret = 0;109u8 chipaddr = 0x50 | ((addr >> 8) & 3);110for (i = 0; i < retries; i++) {111ret = fc->i2c_request(&fc->fc_i2c_adap[1], op, chipaddr,112addr & 0xff, buf, len);113if (ret == 0)114break;115}116return ret;117}118119static int flexcop_eeprom_lrc_read(struct flexcop_device *fc, u16 addr,120u8 *buf, u16 len, int retries)121{122int ret = flexcop_eeprom_request(fc, FC_READ, addr, buf, len, retries);123if (ret == 0)124if (calc_lrc(buf, len - 1) != buf[len - 1])125ret = -EINVAL;126return ret;127}128129/* JJ's comment about extended == 1: it is not presently used anywhere but was130* added to the low-level functions for possible support of EUI64 */131int flexcop_eeprom_check_mac_addr(struct flexcop_device *fc, int extended)132{133u8 buf[8];134int ret = 0;135136if ((ret = flexcop_eeprom_lrc_read(fc,0x3f8,buf,8,4)) == 0) {137if (extended != 0) {138err("TODO: extended (EUI64) MAC addresses aren't "139"completely supported yet");140ret = -EINVAL;141} else142memcpy(fc->dvb_adapter.proposed_mac,buf,6);143}144return ret;145}146EXPORT_SYMBOL(flexcop_eeprom_check_mac_addr);147148149