3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #define EEPROM_CAP 0x50000358
30 #define EEPROM_DATA 0x5000035c
33 unsigned int eepromReadLong(int offs)
39 out_be16((void *)EEPROM_CAP, offs);
46 ret = in_be16((void *)EEPROM_CAP);
48 if ((ret & 0x8000) != 0)
52 value = in_be32((void *)EEPROM_DATA);
58 unsigned char eepromReadByte(int offs)
60 unsigned int valueLong;
63 valueLong = eepromReadLong(offs & ~3);
64 ptr = (unsigned char *)&valueLong;
70 void eepromWriteLong(int offs, unsigned int value)
77 out_be32((void *)EEPROM_DATA, value);
78 out_be16((void *)EEPROM_CAP, 0x8000 + offs);
83 ret = in_be16((void *)EEPROM_CAP);
85 if ((ret & 0x8000) == 0)
91 void eepromWriteByte(int offs, unsigned char valueByte)
93 unsigned int valueLong;
96 valueLong = eepromReadLong(offs & ~3);
97 ptr = (unsigned char *)&valueLong;
99 ptr[offs & 3] = valueByte;
101 eepromWriteLong(offs & ~3, valueLong);
105 void i2c_read (uchar *addr, int alen, uchar *buffer, int len)
110 /* printf("\naddr=%x alen=%x buffer=%x len=%x", addr[0], addr[1], *(short *)addr, alen, buffer, len); /###* test-only */
112 ptr = *(short *)addr;
115 * Read till lword boundary
117 len2 = 4 - (*(short *)addr & 0x0003);
118 for (i=0; i<len2; i++)
120 *buffer++ = eepromReadByte(ptr++);
126 len2 = (len - len2) >> 2;
127 for (i=0; i<len2; i++)
129 *(unsigned int *)buffer = eepromReadLong(ptr);
137 len2 = (*(short *)addr + len) & 0x0003;
138 for (i=0; i<len2; i++)
140 *buffer++ = eepromReadByte(ptr++);
144 void i2c_write (uchar *addr, int alen, uchar *buffer, int len)
149 /* printf("\naddr=%x alen=%x buffer=%x len=%x", addr[0], addr[1], *(short *)addr, alen, buffer, len); /###* test-only */
151 ptr = *(short *)addr;
154 * Write till lword boundary
156 len2 = 4 - (*(short *)addr & 0x0003);
157 for (i=0; i<len2; i++)
159 eepromWriteByte(ptr++, *buffer++);
165 len2 = (len - len2) >> 2;
166 for (i=0; i<len2; i++)
168 eepromWriteLong(ptr, *(unsigned int *)buffer);
176 len2 = (*(short *)addr + len) & 0x0003;
177 for (i=0; i<len2; i++)
179 eepromWriteByte(ptr++, *buffer++);