From f5a4a27c7b0fd6140d0048bd5ecaef31ec45e93b Mon Sep 17 00:00:00 2001 From: Grzegorz Daniluk <grzegorz.daniluk@cern.ch> Date: Thu, 8 Jan 2015 14:51:59 +0100 Subject: [PATCH] sdb-eeprom: adding erase function for i2c eeprom --- dev/sdb-eeprom.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/dev/sdb-eeprom.c b/dev/sdb-eeprom.c index 676bbe57d..ff2b5702f 100644 --- a/dev/sdb-eeprom.c +++ b/dev/sdb-eeprom.c @@ -110,6 +110,34 @@ static int sdb_i2c_write(struct sdbfs *fs, int offset, void *buf, int count) return count; } +static int sdb_i2c_erase(struct sdbfs *fs, int offset, int count) +{ + int i, busy; + struct i2c_params *p = fs->drvdata; + + for (i = 0; i < count; i++) { + mi2c_start(p->ifnum); + + if (mi2c_put_byte(p->ifnum, p->addr << 1) < 0) { + mi2c_stop(p->ifnum); + return -1; + } + mi2c_put_byte(p->ifnum, (offset >> 8) & 0xff); + mi2c_put_byte(p->ifnum, offset & 0xff); + mi2c_put_byte(p->ifnum, 0xff); + offset++; + mi2c_stop(p->ifnum); + + do { /* wait until the chip becomes ready */ + mi2c_start(p->ifnum); + busy = mi2c_put_byte(p->ifnum, p->addr << 1); + mi2c_stop(p->ifnum); + } while (busy); + + } + return count; +} + /* * A trivial dumper, just to show what's up in there */ @@ -186,6 +214,7 @@ void eeprom_init(int chosen_i2cif, int chosen_i2c_addr) wrc_sdb.drvdata = &i2c_params; wrc_sdb.read = sdb_i2c_read; wrc_sdb.write = sdb_i2c_write; + wrc_sdb.erase = sdb_i2c_erase; goto found_exit; } if (i == ARRAY_SIZE(entry_points)) { -- GitLab