GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / media / dvb / ttpci / ttpci-eeprom.c
blob5166bf0a1fbdc198d22ecaefca21f5b21235c123
1 /*
2 Retrieve encoded MAC address from 24C16 serial 2-wire EEPROM,
3 decode it and store it in the associated adapter struct for
4 use by dvb_net.c
6 This card appear to have the 24C16 write protect held to ground,
7 thus permitting normal read/write operation. Theoretically it
8 would be possible to write routines to burn a different (encoded)
9 MAC address into the EEPROM.
11 Robert Schlabbach GMX
12 Michael Glaum KVH Industries
13 Holger Waechtler Convergence
15 Copyright (C) 2002-2003 Ralph Metzler <rjkm@metzlerbros.de>
16 Metzler Brothers Systementwicklung GbR
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 2 of the License, or
21 (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 #include <asm/errno.h>
35 #include <linux/init.h>
36 #include <linux/module.h>
37 #include <linux/string.h>
38 #include <linux/i2c.h>
40 #include "ttpci-eeprom.h"
42 #define dprintk(x...) do { printk(x); } while (0)
45 static int check_mac_tt(u8 *buf)
47 int i;
48 u16 tmp = 0xffff;
50 for (i = 0; i < 8; i++) {
51 tmp = (tmp << 8) | ((tmp >> 8) ^ buf[i]);
52 tmp ^= (tmp >> 4) & 0x0f;
53 tmp ^= (tmp << 12) ^ ((tmp & 0xff) << 5);
55 tmp ^= 0xffff;
56 return (((tmp >> 8) ^ buf[8]) | ((tmp & 0xff) ^ buf[9]));
59 static int getmac_tt(u8 * decodedMAC, u8 * encodedMAC)
61 u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
62 0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
63 0x1d, 0x36, 0x64, 0x78};
64 u8 data[20];
65 int i;
67 /* In case there is a sig check failure have the orig contents available */
68 memcpy(data, encodedMAC, 20);
70 for (i = 0; i < 20; i++)
71 data[i] ^= xor[i];
72 for (i = 0; i < 10; i++)
73 data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
74 >> ((data[2 * i + 1] >> 6) & 3);
76 if (check_mac_tt(data))
77 return -ENODEV;
79 decodedMAC[0] = data[2]; decodedMAC[1] = data[1]; decodedMAC[2] = data[0];
80 decodedMAC[3] = data[6]; decodedMAC[4] = data[5]; decodedMAC[5] = data[4];
81 return 0;
84 static int ttpci_eeprom_read_encodedMAC(struct i2c_adapter *adapter, u8 * encodedMAC)
86 int ret;
87 u8 b0[] = { 0xcc };
89 struct i2c_msg msg[] = {
90 { .addr = 0x50, .flags = 0, .buf = b0, .len = 1 },
91 { .addr = 0x50, .flags = I2C_M_RD, .buf = encodedMAC, .len = 20 }
94 /* dprintk("%s\n", __func__); */
96 ret = i2c_transfer(adapter, msg, 2);
98 if (ret != 2) /* Assume EEPROM isn't there */
99 return (-ENODEV);
101 return 0;
105 int ttpci_eeprom_parse_mac(struct i2c_adapter *adapter, u8 *proposed_mac)
107 int ret, i;
108 u8 encodedMAC[20];
109 u8 decodedMAC[6];
111 ret = ttpci_eeprom_read_encodedMAC(adapter, encodedMAC);
113 if (ret != 0) { /* Will only be -ENODEV */
114 dprintk("Couldn't read from EEPROM: not there?\n");
115 memset(proposed_mac, 0, 6);
116 return ret;
119 ret = getmac_tt(decodedMAC, encodedMAC);
120 if( ret != 0 ) {
121 dprintk("adapter failed MAC signature check\n");
122 dprintk("encoded MAC from EEPROM was " );
123 for(i=0; i<19; i++) {
124 dprintk( "%.2x:", encodedMAC[i]);
126 dprintk("%.2x\n", encodedMAC[19]);
127 memset(proposed_mac, 0, 6);
128 return ret;
131 memcpy(proposed_mac, decodedMAC, 6);
132 dprintk("adapter has MAC addr = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
133 decodedMAC[0], decodedMAC[1], decodedMAC[2],
134 decodedMAC[3], decodedMAC[4], decodedMAC[5]);
135 return 0;
138 EXPORT_SYMBOL(ttpci_eeprom_parse_mac);
140 MODULE_LICENSE("GPL");
141 MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, others");
142 MODULE_DESCRIPTION("Decode dvb_net MAC address from EEPROM of PCI DVB cards "
143 "made by Siemens, Technotrend, Hauppauge");