hamradio/scc: add missing block braces to multi-statement if
[linux/fpc-iii.git] / drivers / media / dvb / b2c2 / flexcop-eeprom.c
blob8a8ae8a3e6ba6954717739ef59487d8804698297
1 /*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
4 * flexcop-eeprom.c - eeprom access methods (currently only MAC address reading is used)
6 * see flexcop.c for copyright information.
7 */
8 #include "flexcop.h"
10 #if 0
11 /*EEPROM (Skystar2 has one "24LC08B" chip on board) */
12 static int eeprom_write(struct adapter *adapter, u16 addr, u8 *buf, u16 len)
14 return flex_i2c_write(adapter, 0x20000000, 0x50, addr, buf, len);
17 static int eeprom_lrc_write(struct adapter *adapter, u32 addr, u32 len, u8 *wbuf, u8 *rbuf, int retries)
19 int i;
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)
24 return 1;
28 return 0;
31 /* These functions could be used to unlock SkyStar2 cards. */
33 static int eeprom_writeKey(struct adapter *adapter, u8 *key, u32 len)
35 u8 rbuf[20];
36 u8 wbuf[20];
38 if (len != 16)
39 return 0;
41 memcpy(wbuf, key, len);
43 wbuf[16] = 0;
44 wbuf[17] = 0;
45 wbuf[18] = 0;
46 wbuf[19] = calc_lrc(wbuf, 19);
48 return eeprom_lrc_write(adapter, 0x3e4, 20, wbuf, rbuf, 4);
51 static int eeprom_readKey(struct adapter *adapter, u8 *key, u32 len)
53 u8 buf[20];
55 if (len != 16)
56 return 0;
58 if (eeprom_lrc_read(adapter, 0x3e4, 20, buf, 4) == 0)
59 return 0;
61 memcpy(key, buf, len);
63 return 1;
66 static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 *mac)
68 u8 tmp[8];
70 if (type != 0) {
71 tmp[0] = mac[0];
72 tmp[1] = mac[1];
73 tmp[2] = mac[2];
74 tmp[3] = mac[5];
75 tmp[4] = mac[6];
76 tmp[5] = mac[7];
78 } else {
80 tmp[0] = mac[0];
81 tmp[1] = mac[1];
82 tmp[2] = mac[2];
83 tmp[3] = mac[3];
84 tmp[4] = mac[4];
85 tmp[5] = mac[5];
88 tmp[6] = 0;
89 tmp[7] = calc_lrc(tmp, 7);
91 if (eeprom_write(adapter, 0x3f8, tmp, 8) == 8)
92 return 1;
94 return 0;
97 static int flexcop_eeprom_read(struct flexcop_device *fc, u16 addr, u8 *buf, u16 len)
99 return fc->i2c_request(fc,FC_READ,FC_I2C_PORT_EEPROM,0x50,addr,buf,len);
102 #endif
104 static u8 calc_lrc(u8 *buf, int len)
106 int i;
107 u8 sum = 0;
108 for (i = 0; i < len; i++)
109 sum = sum ^ buf[i];
110 return sum;
113 static int flexcop_eeprom_request(struct flexcop_device *fc, flexcop_access_op_t op, u16 addr, u8 *buf, u16 len, int retries)
115 int i,ret = 0;
116 u8 chipaddr = 0x50 | ((addr >> 8) & 3);
117 for (i = 0; i < retries; i++) {
118 ret = fc->i2c_request(&fc->fc_i2c_adap[1], op, chipaddr,
119 addr & 0xff, buf, len);
120 if (ret == 0)
121 break;
123 return ret;
126 static int flexcop_eeprom_lrc_read(struct flexcop_device *fc, u16 addr, u8 *buf, u16 len, int retries)
128 int ret = flexcop_eeprom_request(fc, FC_READ, addr, buf, len, retries);
129 if (ret == 0)
130 if (calc_lrc(buf, len - 1) != buf[len - 1])
131 ret = -EINVAL;
132 return ret;
135 /* JJ's comment about extended == 1: it is not presently used anywhere but was
136 * added to the low-level functions for possible support of EUI64
138 int flexcop_eeprom_check_mac_addr(struct flexcop_device *fc, int extended)
140 u8 buf[8];
141 int ret = 0;
143 if ((ret = flexcop_eeprom_lrc_read(fc,0x3f8,buf,8,4)) == 0) {
144 if (extended != 0) {
145 err("TODO: extended (EUI64) MAC addresses aren't completely supported yet");
146 ret = -EINVAL;
147 /* memcpy(fc->dvb_adapter.proposed_mac,buf,3);
148 mac[3] = 0xfe;
149 mac[4] = 0xff;
150 memcpy(&fc->dvb_adapter.proposed_mac[3],&buf[5],3); */
151 } else
152 memcpy(fc->dvb_adapter.proposed_mac,buf,6);
154 return ret;
156 EXPORT_SYMBOL(flexcop_eeprom_check_mac_addr);