X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=cmd%2Feeprom.c;h=f61a5510e8028007dba5d9848c274c8a87332756;hb=09140113108541b95d340f3c7b6ee597d31ccc73;hp=e88cb131a16d0bf08017ea1d3a36df724f696541;hpb=0a3d59e01038a3a50484b8bfcf834376a7215af0;p=oweals%2Fu-boot.git diff --git a/cmd/eeprom.c b/cmd/eeprom.c index e88cb131a1..f61a5510e8 100644 --- a/cmd/eeprom.c +++ b/cmd/eeprom.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,10 @@ #endif #endif +#if defined(CONFIG_DM_I2C) +static int eeprom_i2c_bus; +#endif + __weak int eeprom_write_enable(unsigned dev_addr, int state) { return 0; @@ -66,13 +71,10 @@ __weak int eeprom_write_enable(unsigned dev_addr, int state) void eeprom_init(int bus) { - /* SPI EEPROM */ -#if defined(CONFIG_MPC8XX_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C) - spi_init_f(); -#endif - /* I2C EEPROM */ -#if defined(CONFIG_SYS_I2C) +#if defined(CONFIG_DM_I2C) + eeprom_i2c_bus = bus; +#elif defined(CONFIG_SYS_I2C) if (bus >= 0) i2c_set_bus_num(bus); i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); @@ -107,7 +109,7 @@ static int eeprom_len(unsigned offset, unsigned end) /* * For a FRAM device there is no limit on the number of the - * bytes that can be ccessed with the single read or write + * bytes that can be accessed with the single read or write * operation. */ #if !defined(CONFIG_SYS_I2C_FRAM) @@ -129,22 +131,14 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen, { int ret = 0; - /* SPI */ -#if defined(CONFIG_MPC8XX_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C) - if (read) - spi_read(addr, alen, buffer, len); - else - spi_write(addr, alen, buffer, len); -#else /* I2C */ - -#if defined(CONFIG_DM_I2C) && defined(CONFIG_SYS_I2C_EEPROM_BUS) +#if defined(CONFIG_DM_I2C) struct udevice *dev; - ret = i2c_get_chip_for_busnum(CONFIG_SYS_I2C_EEPROM_BUS, addr[0], + ret = i2c_get_chip_for_busnum(eeprom_i2c_bus, addr[0], alen - 1, &dev); if (ret) { printf("%s: Cannot find udev for a bus %d\n", __func__, - CONFIG_SYS_I2C_EEPROM_BUS); + eeprom_i2c_bus); return CMD_RET_FAILURE; } @@ -154,16 +148,12 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen, ret = dm_i2c_write(dev, offset, buffer, len); #else /* Non DM I2C support - will be removed */ -#if defined(CONFIG_SYS_I2C_EEPROM_BUS) - i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS); -#endif if (read) ret = i2c_read(addr[0], offset, alen - 1, buffer, len); else ret = i2c_write(addr[0], offset, alen - 1, buffer, len); -#endif -#endif /* CONFIG_DM_I2C && CONFIG_SYS_I2C_EEPROM_BUS */ +#endif /* CONFIG_DM_I2C */ if (ret) ret = CMD_RET_FAILURE; @@ -178,6 +168,10 @@ static int eeprom_rw(unsigned dev_addr, unsigned offset, uchar *buffer, int rcode = 0; uchar addr[3]; +#if defined(CONFIG_SYS_I2C_EEPROM_BUS) + eeprom_init(CONFIG_SYS_I2C_EEPROM_BUS); +#endif + while (offset < end) { alen = eeprom_addr(dev_addr, offset, addr); @@ -243,7 +237,7 @@ static int parse_numeric_param(char *str) * @returns: number of arguments parsed or CMD_RET_USAGE if error */ static int parse_i2c_bus_addr(int *i2c_bus, ulong *i2c_addr, int argc, - char * const argv[], int argc_no_bus_addr) + char *const argv[], int argc_no_bus_addr) { int argc_no_bus = argc_no_bus_addr + 1; int argc_bus_addr = argc_no_bus_addr + 2; @@ -314,7 +308,7 @@ static int eeprom_execute_command(enum eeprom_action action, int i2c_bus, { int rcode = 0; const char *const fmt = - "\nEEPROM @0x%lX %s: addr %08lx off %04lx count %ld ... "; + "\nEEPROM @0x%lX %s: addr 0x%08lx off 0x%04lx count %ld ... "; #ifdef CONFIG_CMD_EEPROM_LAYOUT struct eeprom_layout layout; #endif @@ -361,7 +355,7 @@ static int eeprom_execute_command(enum eeprom_action action, int i2c_bus, } #define NEXT_PARAM(argc, index) { (argc)--; (index)++; } -int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { int layout_ver = LAYOUT_VERSION_AUTODETECT; enum eeprom_action action = EEPROM_ACTION_INVALID;