0001
0002
0003
0004
0005
0006
0007 #include "flexcop.h"
0008
0009 #if 0
0010
0011 static int eeprom_write(struct adapter *adapter, u16 addr, u8 *buf, u16 len)
0012 {
0013 return flex_i2c_write(adapter, 0x20000000, 0x50, addr, buf, len);
0014 }
0015
0016 static int eeprom_lrc_write(struct adapter *adapter, u32 addr,
0017 u32 len, u8 *wbuf, u8 *rbuf, int retries)
0018 {
0019 int i;
0020
0021 for (i = 0; i < retries; i++) {
0022 if (eeprom_write(adapter, addr, wbuf, len) == len) {
0023 if (eeprom_lrc_read(adapter, addr, len, rbuf, retries) == 1)
0024 return 1;
0025 }
0026 }
0027 return 0;
0028 }
0029
0030
0031
0032 static int eeprom_writeKey(struct adapter *adapter, u8 *key, u32 len)
0033 {
0034 u8 rbuf[20];
0035 u8 wbuf[20];
0036
0037 if (len != 16)
0038 return 0;
0039
0040 memcpy(wbuf, key, len);
0041 wbuf[16] = 0;
0042 wbuf[17] = 0;
0043 wbuf[18] = 0;
0044 wbuf[19] = calc_lrc(wbuf, 19);
0045 return eeprom_lrc_write(adapter, 0x3e4, 20, wbuf, rbuf, 4);
0046 }
0047
0048 static int eeprom_readKey(struct adapter *adapter, u8 *key, u32 len)
0049 {
0050 u8 buf[20];
0051
0052 if (len != 16)
0053 return 0;
0054
0055 if (eeprom_lrc_read(adapter, 0x3e4, 20, buf, 4) == 0)
0056 return 0;
0057
0058 memcpy(key, buf, len);
0059 return 1;
0060 }
0061
0062 static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 *mac)
0063 {
0064 u8 tmp[8];
0065
0066 if (type != 0) {
0067 tmp[0] = mac[0];
0068 tmp[1] = mac[1];
0069 tmp[2] = mac[2];
0070 tmp[3] = mac[5];
0071 tmp[4] = mac[6];
0072 tmp[5] = mac[7];
0073 } else {
0074 tmp[0] = mac[0];
0075 tmp[1] = mac[1];
0076 tmp[2] = mac[2];
0077 tmp[3] = mac[3];
0078 tmp[4] = mac[4];
0079 tmp[5] = mac[5];
0080 }
0081
0082 tmp[6] = 0;
0083 tmp[7] = calc_lrc(tmp, 7);
0084
0085 if (eeprom_write(adapter, 0x3f8, tmp, 8) == 8)
0086 return 1;
0087 return 0;
0088 }
0089
0090 static int flexcop_eeprom_read(struct flexcop_device *fc,
0091 u16 addr, u8 *buf, u16 len)
0092 {
0093 return fc->i2c_request(fc,FC_READ,FC_I2C_PORT_EEPROM,0x50,addr,buf,len);
0094 }
0095
0096 #endif
0097
0098 static u8 calc_lrc(u8 *buf, int len)
0099 {
0100 int i;
0101 u8 sum = 0;
0102 for (i = 0; i < len; i++)
0103 sum = sum ^ buf[i];
0104 return sum;
0105 }
0106
0107 static int flexcop_eeprom_request(struct flexcop_device *fc,
0108 flexcop_access_op_t op, u16 addr, u8 *buf, u16 len, int retries)
0109 {
0110 int i,ret = 0;
0111 u8 chipaddr = 0x50 | ((addr >> 8) & 3);
0112 for (i = 0; i < retries; i++) {
0113 ret = fc->i2c_request(&fc->fc_i2c_adap[1], op, chipaddr,
0114 addr & 0xff, buf, len);
0115 if (ret == 0)
0116 break;
0117 }
0118 return ret;
0119 }
0120
0121 static int flexcop_eeprom_lrc_read(struct flexcop_device *fc, u16 addr,
0122 u8 *buf, u16 len, int retries)
0123 {
0124 int ret = flexcop_eeprom_request(fc, FC_READ, addr, buf, len, retries);
0125 if (ret == 0)
0126 if (calc_lrc(buf, len - 1) != buf[len - 1])
0127 ret = -EINVAL;
0128 return ret;
0129 }
0130
0131
0132
0133 int flexcop_eeprom_check_mac_addr(struct flexcop_device *fc, int extended)
0134 {
0135 u8 buf[8];
0136 int ret = 0;
0137
0138 if ((ret = flexcop_eeprom_lrc_read(fc,0x3f8,buf,8,4)) == 0) {
0139 if (extended != 0) {
0140 err("TODO: extended (EUI64) MAC addresses aren't completely supported yet");
0141 ret = -EINVAL;
0142 } else
0143 memcpy(fc->dvb_adapter.proposed_mac,buf,6);
0144 }
0145 return ret;
0146 }
0147 EXPORT_SYMBOL(flexcop_eeprom_check_mac_addr);