2 * Copyright 2007 Free Software Foundation, Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 static const int EEPROM_PAGESIZE = 16;
24 eeprom_write (int i2c_addr, int eeprom_offset, const void *buf, int len)
27 const unsigned char *p = (unsigned char *) buf;
29 // The simplest thing that could possibly work:
30 // all writes are single byte writes.
32 // We could speed this up using the page write feature,
33 // but we write so infrequently, why bother...
36 cmd[0] = eeprom_offset++;
38 bool r = i2c_write (i2c_addr, cmd, sizeof (cmd));
39 mdelay (10); // delay 10ms worst case write time
47 eeprom_read (int i2c_addr, int eeprom_offset, void *buf, int len)
49 unsigned char *p = (unsigned char *) buf;
51 // We setup a random read by first doing a "zero byte write".
52 // Writes carry an address. Reads use an implicit address.
55 cmd[0] = eeprom_offset;
56 if (!i2c_write (i2c_addr, cmd, sizeof (cmd)))
60 // int n = std::min (len, MAX_EP0_PKTSIZE);
62 if (!i2c_read (i2c_addr, p, n))