1 /* Three-wire (MicroWire) serial eeprom driver (for 93C46 and compatibles) */
4 #include <asm/ic/ssi.h>
7 * Serial EEPROM opcodes, including start bit
9 #define EEP_OPC_ERASE 0x7 /* 3-bit opcode */
10 #define EEP_OPC_WRITE 0x5 /* 3-bit opcode */
11 #define EEP_OPC_READ 0x6 /* 3-bit opcode */
13 #define EEP_OPC_ERASE_ALL 0x12 /* 5-bit opcode */
14 #define EEP_OPC_ERASE_EN 0x13 /* 5-bit opcode */
15 #define EEP_OPC_WRITE_ALL 0x11 /* 5-bit opcode */
16 #define EEP_OPC_ERASE_DIS 0x10 /* 5-bit opcode */
20 static void mw_eeprom_select(int dev)
22 ssi_set_interface(2048, 0, 0, 0);
29 static int mw_eeprom_size(int dev)
34 mw_eeprom_select(dev);
35 ssi_tx_byte(EEP_OPC_READ);
37 res = ssi_txrx_byte(0) << 8;
39 for (x = 0; x < 16; x++) {
40 if (! (res & 0x8000)) {
50 int mw_eeprom_erase_enable(int dev)
52 mw_eeprom_select(dev);
53 ssi_tx_byte(EEP_OPC_ERASE_EN);
61 int mw_eeprom_erase_disable(int dev)
63 mw_eeprom_select(dev);
64 ssi_tx_byte(EEP_OPC_ERASE_DIS);
73 u32 mw_eeprom_read_word(int dev, int addr)
79 mw_eeprom_select(dev);
80 ssi_tx_byte((EEP_OPC_READ << 5) | ((addr >> (addrlen - 5)) & 0x1f));
81 rcv = ssi_txrx_byte(addr << (13 - addrlen));
82 res = rcv << (16 - addrlen);
88 res |= rcv << (bits - 8);
90 res |= rcv >> (8 - bits);
100 int mw_eeprom_write_word(int dev, int addr, u16 data)
105 mw_eeprom_erase_enable(dev);
106 mw_eeprom_select(dev);
110 byte1 = EEP_OPC_WRITE >> 2;
111 byte2 = (EEP_OPC_WRITE << 6)&0xc0;
115 byte1 = EEP_OPC_WRITE >> 1;
116 byte2 = (EEP_OPC_WRITE << 7)&0x80;
120 byte1 = EEP_OPC_WRITE;
124 byte1 = EEP_OPC_WRITE << 1;
129 byte1 = EEP_OPC_WRITE << 2;
134 printf("Unsupported number of address bits: %d\n", addrlen);
141 ssi_tx_byte(data >> 8);
142 ssi_tx_byte(data & 0xff);
144 udelay(10000); /* Worst case */
145 mw_eeprom_erase_disable(dev);
151 int mw_eeprom_write(int dev, int addr, u8 *buffer, int len)
157 u16 temp = mw_eeprom_read_word(dev, addr >> 1);
161 mw_eeprom_write_word(dev, addr >> 1, temp);
169 mw_eeprom_write_word(dev, addr >> 1, *(u16*)buffer);
177 u16 temp = mw_eeprom_read_word(dev, addr >> 1);
179 temp |= buffer[0] << 8;
181 mw_eeprom_write_word(dev, addr >> 1, temp);
192 int mw_eeprom_read(int dev, int addr, u8 *buffer, int len)
198 u16 temp = mw_eeprom_read_word(dev, addr >> 1);
199 buffer[0]= temp & 0xff;
208 *(u16*)buffer = mw_eeprom_read_word(dev, addr >> 1);
216 u16 temp = mw_eeprom_read_word(dev, addr >> 1);
217 buffer[0] = temp >> 8;
228 int mw_eeprom_probe(int dev)
230 addrlen = mw_eeprom_size(dev);
232 if (addrlen < 6 || addrlen > 10) {