1 /* Three-wire (MicroWire) serial eeprom driver (for 93C46 and compatibles) */
7 #ifdef CONFIG_MW_EEPROM
10 * Serial EEPROM opcodes, including start bit
12 #define EEP_OPC_ERASE 0x7 /* 3-bit opcode */
13 #define EEP_OPC_WRITE 0x5 /* 3-bit opcode */
14 #define EEP_OPC_READ 0x6 /* 3-bit opcode */
16 #define EEP_OPC_ERASE_ALL 0x12 /* 5-bit opcode */
17 #define EEP_OPC_ERASE_EN 0x13 /* 5-bit opcode */
18 #define EEP_OPC_WRITE_ALL 0x11 /* 5-bit opcode */
19 #define EEP_OPC_ERASE_DIS 0x10 /* 5-bit opcode */
23 static void mw_eeprom_select(int dev)
25 ssi_set_interface(2048, 0, 0, 0);
32 static int mw_eeprom_size(int dev)
37 mw_eeprom_select(dev);
38 ssi_tx_byte(EEP_OPC_READ);
40 res = ssi_txrx_byte(0) << 8;
42 for (x = 0; x < 16; x++) {
43 if (! (res & 0x8000)) {
53 int mw_eeprom_erase_enable(int dev)
55 mw_eeprom_select(dev);
56 ssi_tx_byte(EEP_OPC_ERASE_EN);
64 int mw_eeprom_erase_disable(int dev)
66 mw_eeprom_select(dev);
67 ssi_tx_byte(EEP_OPC_ERASE_DIS);
76 u32 mw_eeprom_read_word(int dev, int addr)
82 mw_eeprom_select(dev);
83 ssi_tx_byte((EEP_OPC_READ << 5) | ((addr >> (addrlen - 5)) & 0x1f));
84 rcv = ssi_txrx_byte(addr << (13 - addrlen));
85 res = rcv << (16 - addrlen);
91 res |= rcv << (bits - 8);
93 res |= rcv >> (8 - bits);
103 int mw_eeprom_write_word(int dev, int addr, u16 data)
108 mw_eeprom_erase_enable(dev);
109 mw_eeprom_select(dev);
113 byte1 = EEP_OPC_WRITE >> 2;
114 byte2 = (EEP_OPC_WRITE << 6)&0xc0;
118 byte1 = EEP_OPC_WRITE >> 1;
119 byte2 = (EEP_OPC_WRITE << 7)&0x80;
123 byte1 = EEP_OPC_WRITE;
127 byte1 = EEP_OPC_WRITE << 1;
132 byte1 = EEP_OPC_WRITE << 2;
137 printf("Unsupported number of address bits: %d\n", addrlen);
144 ssi_tx_byte(data >> 8);
145 ssi_tx_byte(data & 0xff);
147 udelay(10000); /* Worst case */
148 mw_eeprom_erase_disable(dev);
154 int mw_eeprom_write(int dev, int addr, u8 *buffer, int len)
160 u16 temp = mw_eeprom_read_word(dev, addr >> 1);
164 mw_eeprom_write_word(dev, addr >> 1, temp);
172 mw_eeprom_write_word(dev, addr >> 1, *(u16*)buffer);
180 u16 temp = mw_eeprom_read_word(dev, addr >> 1);
182 temp |= buffer[0] << 8;
184 mw_eeprom_write_word(dev, addr >> 1, temp);
195 int mw_eeprom_read(int dev, int addr, u8 *buffer, int len)
201 u16 temp = mw_eeprom_read_word(dev, addr >> 1);
202 buffer[0]= temp & 0xff;
211 *(u16*)buffer = mw_eeprom_read_word(dev, addr >> 1);
219 u16 temp = mw_eeprom_read_word(dev, addr >> 1);
220 buffer[0] = temp >> 8;
231 int mw_eeprom_probe(int dev)
233 addrlen = mw_eeprom_size(dev);
235 if (addrlen < 6 || addrlen > 10) {