[U-Boot] [PATCH] I2C EEPROM simulator v2

This driver provides access to a simulated i2c eeprom. This simulated eeprom could be very useful in boards with ddr2 memories and no i2c interfaces.
Using this driver the user can simulate a spd eeprom of a ddr2 memory and use the ddr2 auto config.
User can use the macros CONFIG_EEPROM_SIMUL_LEN and CONFIG_EEPROM_SIMUL_DATA to define the content of the simulated eeprom
Signed-off-by: ricardo.ribalda@uam.es ricardo.ribalda@uam.es Signed-off-by: Ricardo Ribalda Delgado ricardo.ribalda@uam.es --- drivers/i2c/Makefile | 1 + drivers/i2c/eeprom_simul.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/eeprom_simul.c
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index 6079c05..1732b7a 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
LIB := $(obj)libi2c.a
+COBJS-$(CONFIG_EEPROM_SIMUL) += eeprom_simul.o COBJS-$(CONFIG_FSL_I2C) += fsl_i2c.o COBJS-$(CONFIG_I2C_MXC) += mxc_i2c.o COBJS-$(CONFIG_DRIVER_OMAP1510_I2C) += omap1510_i2c.o diff --git a/drivers/i2c/eeprom_simul.c b/drivers/i2c/eeprom_simul.c new file mode 100644 index 0000000..eefce48 --- /dev/null +++ b/drivers/i2c/eeprom_simul.c @@ -0,0 +1,67 @@ +/* + (C) Copyright 2008 + Ricado Ribalda-Universidad Autonoma de Madrid-ricardo.ribalda@uam.es + This work has been supported by: QTechnology http://qtec.com/ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses/. +*/ + +#include <common.h> +#include <i2c.h> + +#ifndef CONFIG_EEPROM_SIMUL_LEN +#define CONFIG_EEPROM_SIMUL_LEN 256 +#endif + +u8 eeprom_simul_buffer[CONFIG_EEPROM_SIMUL_LEN] +#ifdef CONFIG_EEPROM_SIMUL_DATA + = CONFIG_EEPROM_SIMUL_DATA +#endif + ; + +void i2c_init(int speed, int slaveaddr) +{ + return; +} + +int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) +{ + int i; + + if (addr + len > CONFIG_EEPROM_SIMUL_LEN) + return -1; + + for (i = 0; i < len; i++) + buffer[i] = eeprom_simul_buffer[i + addr]; + + return 0; +} + +int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) +{ + int i; + + if (addr + len > CONFIG_EEPROM_SIMUL_LEN) + return -1; + + for (i = 0; i < len; i++) + eeprom_simul_buffer[i + addr] = buffer[i]; + + return 0; +} + +int i2c_probe(uchar chip) +{ + return 0; +}
participants (1)
-
Ricardo Ribalda Delgado