tricorder: rewrite tricordereeprom command
PATCH 1/17 tricorder: rewrite tricordereeprom command
From: Andreas Bie?mann <[email protected]>
This rewrite uses lately promoted eeprom_init(int) function to choose the right I2C bus when writing data to the EEPROM.
--- board/corscience/tricorder/tricorder-eeprom.c | 36 +++++++-------------------- 1 file changed, 9 insertions(+), 27 deletions(-)
board/corscience/tricorder/tricorder-eeprom.c +9 -27
@@ -77,17 +77,13 @@ static int handle_eeprom_v1(struct tricorder_eeprom *eeprom)int tricorder_get_eeprom (int addr,struct tricorder_eeprom *eeprom) { -#ifdef CONFIG_SYS_EEPROM_BUS_NUM unsigned int bus =i2c_get_bus_num ();i2c_set_bus_num (CONFIG_SYS_EEPROM_BUS_NUM ); -#endif memset (eeprom,0 ,TRICORDER_EEPROM_SIZE );i2c_read (addr,0 ,2 , (unsigned char *)eeprom,TRICORDER_EEPROM_SIZE ); -#ifdef CONFIG_SYS_EEPROM_BUS_NUM i2c_set_bus_num (bus); -#endif if (be32_to_cpu (eeprom->magic) !=TRICORDER_EEPROM_MAGIC ) { warn_wrong_value("magic", TRICORDER_EEPROM_MAGIC,
@@ -138,9 +134,6 @@ int tricorder_eeprom_write(unsigned devaddr, const char *name,int ret;unsigned char *p;int i; -#ifdef CONFIG_SYS_EEPROM_BUS_NUM -unsigned int bus; -#endif memset (eeprom,0 ,TRICORDER_EEPROM_SIZE );memset (eeprom_verify,0 ,TRICORDER_EEPROM_SIZE );
@@ -172,33 +165,23 @@ int tricorder_eeprom_write(unsigned devaddr, const char *name,print_buffer (0 , &eeprom,1 ,sizeof (eeprom),16 );#endif -#ifdef CONFIG_SYS_EEPROM_BUS_NUM - bus =i2c_get_bus_num (); -i2c_set_bus_num (CONFIG_SYS_EEPROM_BUS_NUM ); -#endif +eeprom_init (CONFIG_SYS_EEPROM_BUS_NUM ); -/* do page write to the eeprom */ -for (i =0 , p = (unsigned char *)&eeprom; - i <sizeof (eeprom); - i +=32 , p +=32 ) { - ret =i2c_write (devaddr, i,CONFIG_SYS_I2C_EEPROM_ADDR_LEN , - p,min (sizeof (eeprom) - i,32 )); -if (ret) -break ; -udelay (5000 );/* 5ms write cycle timing */ - } + ret =eeprom_write (devaddr,0 , (unsigned char *)&eeprom, +TRICORDER_EEPROM_SIZE ); +if (ret) +printf ("Tricorder: Could not write EEPROM content!\n" ); - ret =i2c_read (devaddr,0 ,2 , (unsigned char *)&eeprom_verify, + ret =eeprom_read (devaddr,0 , (unsigned char *)&eeprom_verify,TRICORDER_EEPROM_SIZE ); +if (ret) +printf ("Tricorder: Could not read EEPROM content!\n" );if (memcmp (&eeprom, &eeprom_verify,sizeof (eeprom)) !=0 ) {printf ("Tricorder: Could not verify EEPROM content!\n" ); ret =1 ; } -#ifdef CONFIG_SYS_EEPROM_BUS_NUM -i2c_set_bus_num (bus); -#endif return ret; }
@@ -206,7 +189,7 @@ int do_tricorder_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {if (argc ==3 ) {ulong dev_addr =simple_strtoul (argv[2 ],NULL ,16 ); -eeprom_init (); +if (strcmp (argv[1 ],"read" ) ==0 ) {int rcode;
@@ -220,7 +203,6 @@ int do_tricorder_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])char *version = argv[4 ];char *serial = argv[5 ];char *interface =NULL ; -eeprom_init ();if (argc ==7 ) interface = argv[6 ];
Signature · 1 line
2.1.4
PATCH 2/17 eeprom: Shuffle code around
Just move the code around so that the forward declarations are not necessary. Also zap a few checkpatch issues where applicable and zap the use of #ifdef CONFIG_CMD_EEPROM in the code, since this is always true.
--- common/cmd_eeprom.c | 168 ++++++++++++++++++++++------------------------------ 1 file changed, 70 insertions(+), 98 deletions(-)
common/cmd_eeprom.c +70 -98
@@ -25,94 +25,55 @@#include <command.h> #include <i2c.h> -extern void eeprom_init (void ); -extern int eeprom_read (unsigned dev_addr,unsigned offset, -uchar *buffer,unsigned cnt); -extern int eeprom_write (unsigned dev_addr,unsigned offset, -uchar *buffer,unsigned cnt); -#if defined(CONFIG_SYS_EEPROM_WREN ) -extern int eeprom_write_enable (unsigned dev_addr,int state); +#ifndef CONFIG_SYS_I2C_SPEED +#define CONFIG_SYS_I2C_SPEED 50000#endif - +/* Maximum number of times to poll for acknowledge after write */ #if defined(CONFIG_SYS_EEPROM_X40430 ) -/* Maximum number of times to poll for acknowledge after write */ #define MAX_ACKNOWLEDGE_POLLS 10#endif -/* ------------------------------------------------------------------------- */ - -#if defined(CONFIG_CMD_EEPROM ) -static int do_eeprom (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) -{ -const char *const fmt = -"\nEEPROM @0x%lX %s: addr %08lx off %04lx count %ld ... " ; - -#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS ) -if (argc ==6 ) { -ulong dev_addr =simple_strtoul (argv[2 ],NULL ,16 ); -ulong addr =simple_strtoul (argv[3 ],NULL ,16 ); -ulong off =simple_strtoul (argv[4 ],NULL ,16 ); -ulong cnt =simple_strtoul (argv[5 ],NULL ,16 ); -#else -if (argc ==5 ) { -ulong dev_addr =CONFIG_SYS_DEF_EEPROM_ADDR ; -ulong addr =simple_strtoul (argv[2 ],NULL ,16 ); -ulong off =simple_strtoul (argv[3 ],NULL ,16 ); -ulong cnt =simple_strtoul (argv[4 ],NULL ,16 ); -#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */ - -# if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -eeprom_init (); -# endif /* !CONFIG_SPI */ - -if (strcmp (argv[1 ],"read" ) ==0 ) { -int rcode; - -printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - - rcode =eeprom_read (dev_addr, off, (uchar *) addr, cnt); - -puts ("done\n" ); -return rcode; - }else if (strcmp (argv[1 ],"write" ) ==0 ) { -int rcode; - -printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - - rcode =eeprom_write (dev_addr, off, (uchar *) addr, cnt); - -puts ("done\n" ); -return rcode; - } - } - -return CMD_RET_USAGE ; -} -#endif - -/*----------------------------------------------------------------------- -* +/* * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is * 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM. * * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is * 0x00000nxx for EEPROM address selectors and page number at n. */ -#if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN ) ||CONFIG_SYS_I2C_EEPROM_ADDR_LEN <1 ||CONFIG_SYS_I2C_EEPROM_ADDR_LEN >2 +#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN ) || \ + (CONFIG_SYS_I2C_EEPROM_ADDR_LEN <1 ) || \ + (CONFIG_SYS_I2C_EEPROM_ADDR_LEN >2 )#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2#endif #endif +#if defined(CONFIG_SYS_EEPROM_WREN ) +extern int eeprom_write_enable (unsigned dev_addr,int state); +#endif + +void eeprom_init (void ) +{ +/* SPI EEPROM */ +#if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) +spi_init_f (); +#endif + +/* I2C EEPROM */ +#if defined(CONFIG_HARD_I2C ) || defined(CONFIG_SYS_I2C_SOFT ) +i2c_init (CONFIG_SYS_I2C_SPEED ,CONFIG_SYS_I2C_SLAVE ); +#endif +} +int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) {unsigned end = offset + cnt;unsigned blk_off;int rcode =0 ; -/* Read data until done or would cross a page boundary. +/* +* Read data until done or would cross a page boundary. * We must write the address again when changing pages * because the next page may be in a different device. */
@@ -174,15 +135,6 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cntreturn rcode; } -/*----------------------------------------------------------------------- -* -* for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is -* 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM. -* -* for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is -* 0x00000nxx for EEPROM address selectors and page number at n. -*/ -int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) {unsigned end = offset + cnt;
@@ -200,7 +152,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn#if defined(CONFIG_SYS_EEPROM_WREN )eeprom_write_enable (dev_addr,1 );#endif -/* Write data until done or would cross a write page boundary. +/* +* Write data until done or would cross a write page boundary. * We must write the address again when changing pages * because the address counter only increments within a page. */
@@ -363,8 +316,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn }#if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -int -eeprom_probe (unsigned dev_addr,unsigned offset) +int eeprom_probe (unsigned dev_addr,unsigned offset) {unsigned char chip;
@@ -382,30 +334,52 @@ eeprom_probe (unsigned dev_addr, unsigned offset) }#endif -/*----------------------------------------------------------------------- -* Set default values -*/ -#ifndef CONFIG_SYS_I2C_SPEED -#define CONFIG_SYS_I2C_SPEED 50000 -#endif - -void eeprom_init (void ) +static int do_eeprom (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { +const char *const fmt = +"\nEEPROM @0x%lX %s: addr %08lx off %04lx count %ld ... " ; -#if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -spi_init_f (); -#endif -#if defined(CONFIG_HARD_I2C ) || defined(CONFIG_SYS_I2C_SOFT ) -i2c_init (CONFIG_SYS_I2C_SPEED ,CONFIG_SYS_I2C_SLAVE ); -#endif -} +#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS ) +if (argc ==6 ) { +ulong dev_addr =simple_strtoul (argv[2 ],NULL ,16 ); +ulong addr =simple_strtoul (argv[3 ],NULL ,16 ); +ulong off =simple_strtoul (argv[4 ],NULL ,16 ); +ulong cnt =simple_strtoul (argv[5 ],NULL ,16 ); +#else +if (argc ==5 ) { +ulong dev_addr =CONFIG_SYS_DEF_EEPROM_ADDR ; +ulong addr =simple_strtoul (argv[2 ],NULL ,16 ); +ulong off =simple_strtoul (argv[3 ],NULL ,16 ); +ulong cnt =simple_strtoul (argv[4 ],NULL ,16 ); +#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */ -/*----------------------------------------------------------------------- -*/ +# if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) +eeprom_init (); +# endif /* !CONFIG_SPI */ -/***************************************************/ +if (strcmp (argv[1 ],"read" ) ==0 ) { +int rcode; + +printf (fmt, dev_addr, argv[1 ], addr, off, cnt); -#if defined(CONFIG_CMD_EEPROM ) + rcode =eeprom_read (dev_addr, off, (uchar *) addr, cnt); + +puts ("done\n" ); +return rcode; + }else if (strcmp (argv[1 ],"write" ) ==0 ) { +int rcode; + +printf (fmt, dev_addr, argv[1 ], addr, off, cnt); + + rcode =eeprom_write (dev_addr, off, (uchar *) addr, cnt); + +puts ("done\n" ); +return rcode; + } + } + +return CMD_RET_USAGE ; +}#ifdef CONFIG_SYS_I2C_MULTI_EEPROMS U_BOOT_CMD(
@@ -424,5 +398,3 @@ U_BOOT_CMD( " - read/write `cnt' bytes at EEPROM offset `off'" )#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */ - -#endif
Signature · 1 line
2.1.4
PATCH 2/17 eeprom: Shuffle code around
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 5 lines
Just move the code around so that the forward declarations are not necessary. Also zap a few checkpatch issues where applicable and zap the use of #ifdef
CONFIG_CMD_EEPROMin the code, since this is always true.
Quoted 7 lines
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 168 ++++++++++++++++++++++------------------------------ 1 file changed, 70 insertions(+), 98 deletions(-)
bye,
Heiko
Quoted 241 lines
common/cmd_eeprom.c +70
-98@@ -25,94 +25,55 @@#include <command.h> #include <i2c.h> -extern void eeprom_init (void ); -extern int eeprom_read (unsigned dev_addr,unsigned offset, -uchar *buffer,unsigned cnt); -extern int eeprom_write (unsigned dev_addr,unsigned offset, -uchar *buffer,unsigned cnt); -#if defined(CONFIG_SYS_EEPROM_WREN ) -extern int eeprom_write_enable (unsigned dev_addr,int state); +#ifndef CONFIG_SYS_I2C_SPEED +#define CONFIG_SYS_I2C_SPEED 50000#endif - +/* Maximum number of times to poll for acknowledge after write */ #if defined(CONFIG_SYS_EEPROM_X40430 ) -/* Maximum number of times to poll for acknowledge after write */ #define MAX_ACKNOWLEDGE_POLLS 10#endif -/* ------------------------------------------------------------------------- */ - -#if defined(CONFIG_CMD_EEPROM ) -static int do_eeprom (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) -{ -const char *const fmt = -"\nEEPROM @0x%lX %s: addr %08lx off %04lx count %ld ... " ; - -#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS ) -if (argc ==6 ) { -ulong dev_addr =simple_strtoul (argv[2 ],NULL ,16 ); -ulong addr =simple_strtoul (argv[3 ],NULL ,16 ); -ulong off =simple_strtoul (argv[4 ],NULL ,16 ); -ulong cnt =simple_strtoul (argv[5 ],NULL ,16 ); -#else -if (argc ==5 ) { -ulong dev_addr =CONFIG_SYS_DEF_EEPROM_ADDR ; -ulong addr =simple_strtoul (argv[2 ],NULL ,16 ); -ulong off =simple_strtoul (argv[3 ],NULL ,16 ); -ulong cnt =simple_strtoul (argv[4 ],NULL ,16 ); -#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */ - -# if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -eeprom_init (); -# endif /* !CONFIG_SPI */ - -if (strcmp (argv[1 ],"read" ) ==0 ) { -int rcode; - -printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - - rcode =eeprom_read (dev_addr, off, (uchar *) addr, cnt); - -puts ("done\n" ); -return rcode; - }else if (strcmp (argv[1 ],"write" ) ==0 ) { -int rcode; - -printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - - rcode =eeprom_write (dev_addr, off, (uchar *) addr, cnt); - -puts ("done\n" ); -return rcode; - } - } - -return CMD_RET_USAGE ; -} -#endif - -/*----------------------------------------------------------------------- -* +/* * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is * 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM. * * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is * 0x00000nxx for EEPROM address selectors and page number at n. */ -#if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN ) ||CONFIG_SYS_I2C_EEPROM_ADDR_LEN <1 ||CONFIG_SYS_I2C_EEPROM_ADDR_LEN >2 +#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN ) || \ + (CONFIG_SYS_I2C_EEPROM_ADDR_LEN <1 ) || \ + (CONFIG_SYS_I2C_EEPROM_ADDR_LEN >2 )#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2#endif #endif +#if defined(CONFIG_SYS_EEPROM_WREN ) +extern int eeprom_write_enable (unsigned dev_addr,int state); +#endif + +void eeprom_init (void ) +{ +/* SPI EEPROM */ +#if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) +spi_init_f (); +#endif + +/* I2C EEPROM */ +#if defined(CONFIG_HARD_I2C ) || defined(CONFIG_SYS_I2C_SOFT ) +i2c_init (CONFIG_SYS_I2C_SPEED ,CONFIG_SYS_I2C_SLAVE ); +#endif +} +int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) {unsigned end = offset + cnt;unsigned blk_off;int rcode =0 ; -/* Read data until done or would cross a page boundary. +/* +* Read data until done or would cross a page boundary. * We must write the address again when changing pages * because the next page may be in a different device. */ @@ -174,15 +135,6 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cntreturn rcode; } -/*----------------------------------------------------------------------- -* -* for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is -* 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM. -* -* for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is -* 0x00000nxx for EEPROM address selectors and page number at n. -*/ -int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) {unsigned end = offset + cnt;@@ -200,7 +152,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn#if defined(CONFIG_SYS_EEPROM_WREN )eeprom_write_enable (dev_addr,1 );#endif -/* Write data until done or would cross a write page boundary. +/* +* Write data until done or would cross a write page boundary. * We must write the address again when changing pages * because the address counter only increments within a page. */ @@ -363,8 +316,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn }#if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -int -eeprom_probe (unsigned dev_addr,unsigned offset) +int eeprom_probe (unsigned dev_addr,unsigned offset) {unsigned char chip;@@ -382,30 +334,52 @@ eeprom_probe (unsigned dev_addr, unsigned offset) }#endif -/*----------------------------------------------------------------------- -* Set default values -*/ -#ifndef CONFIG_SYS_I2C_SPEED -#define CONFIG_SYS_I2C_SPEED 50000 -#endif - -void eeprom_init (void ) +static int do_eeprom (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { +const char *const fmt = +"\nEEPROM @0x%lX %s: addr %08lx off %04lx count %ld ... " ; -#if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -spi_init_f (); -#endif -#if defined(CONFIG_HARD_I2C ) || defined(CONFIG_SYS_I2C_SOFT ) -i2c_init (CONFIG_SYS_I2C_SPEED ,CONFIG_SYS_I2C_SLAVE ); -#endif -} +#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS ) +if (argc ==6 ) { +ulong dev_addr =simple_strtoul (argv[2 ],NULL ,16 ); +ulong addr =simple_strtoul (argv[3 ],NULL ,16 ); +ulong off =simple_strtoul (argv[4 ],NULL ,16 ); +ulong cnt =simple_strtoul (argv[5 ],NULL ,16 ); +#else +if (argc ==5 ) { +ulong dev_addr =CONFIG_SYS_DEF_EEPROM_ADDR ; +ulong addr =simple_strtoul (argv[2 ],NULL ,16 ); +ulong off =simple_strtoul (argv[3 ],NULL ,16 ); +ulong cnt =simple_strtoul (argv[4 ],NULL ,16 ); +#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */ -/*----------------------------------------------------------------------- -*/ +# if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) +eeprom_init (); +# endif /* !CONFIG_SPI */ -/***************************************************/ +if (strcmp (argv[1 ],"read" ) ==0 ) { +int rcode; + +printf (fmt, dev_addr, argv[1 ], addr, off, cnt); -#if defined(CONFIG_CMD_EEPROM ) + rcode =eeprom_read (dev_addr, off, (uchar *) addr, cnt); + +puts ("done\n" ); +return rcode; + }else if (strcmp (argv[1 ],"write" ) ==0 ) { +int rcode; + +printf (fmt, dev_addr, argv[1 ], addr, off, cnt); + + rcode =eeprom_write (dev_addr, off, (uchar *) addr, cnt); + +puts ("done\n" ); +return rcode; + } + } + +return CMD_RET_USAGE ; +}#ifdef CONFIG_SYS_I2C_MULTI_EEPROMS U_BOOT_CMD(@@ -424,5 +398,3 @@ U_BOOT_CMD( " - read/write `cnt' bytes at EEPROM offset `off'" )#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */ - -#endif
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 2/17 eeprom: Shuffle code around
In reply to Marek VasutQuoted 10 lines · Marek Vasut
Just move the code around so that the forward declarations are not necessary. Also zap a few checkpatch issues where applicable and zap the use of #ifdef
CONFIG_CMD_EEPROMin the code, since this is always true.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/94feae2e/attachment.sig>
PATCH 3/17 eeprom: Zap CONFIG_SYS_I2C_MULTI_EEPROMS
In reply to Marek VasutThis option only complicates the code unnecessarily, just use CONFIG_SYS_DEF_EEPROM_ADDR as the default address if there are only five arguments to eeprom {read/write} if this is defined. If CONFIG_SYS_DEF_EEPROM_ADDR is not defined, we mandate all six arguments.
--- common/cmd_eeprom.c | 69 ++++++++++++++++++----------------------- include/configs/BSC9131RDB.h | 1 - include/configs/BSC9132QDS.h | 1 - include/configs/C29XPCIE.h | 1 - include/configs/P1010RDB.h | 1 - include/configs/PMC440.h | 1 - include/configs/TQM834x.h | 1 - include/configs/acadia.h | 1 - include/configs/am335x_evm.h | 1 - include/configs/am43xx_evm.h | 1 - include/configs/axs101.h | 1 - include/configs/bamboo.h | 1 - include/configs/canyonlands.h | 1 - include/configs/icon.h | 1 - include/configs/intip.h | 1 - include/configs/katmai.h | 1 - include/configs/km/km-powerpc.h | 1 - include/configs/km/km_arm.h | 1 - include/configs/luan.h | 1 - include/configs/m28evk.h | 1 - include/configs/motionpro.h | 1 - include/configs/p1_p2_rdb_pc.h | 1 - include/configs/p1_twr.h | 1 - include/configs/pcm051.h | 1 - include/configs/pengwyn.h | 1 - include/configs/sequoia.h | 1 - include/configs/t3corp.h | 1 - include/configs/tricorder.h | 1 - include/configs/walnut.h | 1 - include/configs/yosemite.h | 1 - 30 files changed, 30 insertions(+), 68 deletions(-)
common/cmd_eeprom.c +30 -39
@@ -338,50 +338,50 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {const char *const fmt ="\nEEPROM @0x%lX %s: addr %08lx off %04lx count %ld ... " ; +char *const *args = &argv[2 ]; +int rcode; +ulong dev_addr, addr, off, cnt; + +switch (argc) { +#ifdef CONFIG_SYS_DEF_EEPROM_ADDR +case 5 : + dev_addr =CONFIG_SYS_DEF_EEPROM_ADDR ; +break ; +#endif +case 6 : + dev_addr =simple_strtoul (*args++,NULL ,16 ); +break ; +default : +return CMD_RET_USAGE ; + } -#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS) - if (argc == 6) { - ulong dev_addr = simple_strtoul (argv[2], NULL, 16); - ulong addr = simple_strtoul (argv[3], NULL, 16); - ulong off = simple_strtoul (argv[4], NULL, 16); - ulong cnt = simple_strtoul (argv[5], NULL, 16); -#else - if (argc == 5) { - ulong dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR; - ulong addr = simple_strtoul (argv[2], NULL, 16); - ulong off = simple_strtoul (argv[3], NULL, 16); - ulong cnt = simple_strtoul (argv[4], NULL, 16); -#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */ + addr =simple_strtoul (*args++,NULL ,16 ); + off =simple_strtoul (*args++,NULL ,16 ); + cnt =simple_strtoul (*args++,NULL ,16 );# if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) - eeprom_init (); +eeprom_init ();# endif /* !CONFIG_SPI */ - if (strcmp (argv[1], "read") == 0) { - int rcode; - - printf (fmt, dev_addr, argv[1], addr, off, cnt); - - rcode = eeprom_read (dev_addr, off, (uchar *) addr, cnt); +if (strcmp (argv[1 ],"read" ) ==0 ) { +printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - puts ("done\n"); - return rcode; - } else if (strcmp (argv[1], "write") == 0) { - int rcode; + rcode =eeprom_read (dev_addr, off, (uchar *) addr, cnt); - printf (fmt, dev_addr, argv[1], addr, off, cnt); +puts ("done\n" ); +return rcode; + }else if (strcmp (argv[1 ],"write" ) ==0 ) { +printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - rcode = eeprom_write (dev_addr, off, (uchar *) addr, cnt); + rcode =eeprom_write (dev_addr, off, (uchar *) addr, cnt); - puts ("done\n"); - return rcode; - } +puts ("done\n" ); +return rcode; }return CMD_RET_USAGE ; } -#ifdef CONFIG_SYS_I2C_MULTI_EEPROMS U_BOOT_CMD( eeprom, 6, 1, do_eeprom, "EEPROM sub-system",
@@ -389,12 +389,3 @@ U_BOOT_CMD("eeprom write devaddr addr off cnt\n" " - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'" ) -#else /* One EEPROM */ -U_BOOT_CMD ( - eeprom,5 ,1 , do_eeprom, -"EEPROM sub-system" , -"read addr off cnt\n" -"eeprom write addr off cnt\n" -" - read/write `cnt' bytes at EEPROM offset `off'" -) -#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
include/configs/BSC9131RDB.h +0 -1
@@ -267,7 +267,6 @@ extern unsigned long get_sdram_size(void);/* I2C EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/BSC9132QDS.h +0 -1
@@ -463,7 +463,6 @@ combinations. this should be removed later/* enable read and write access to EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/C29XPCIE.h +0 -1
@@ -420,7 +420,6 @@/* I2C EEPROM */ /* enable read and write access to EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/P1010RDB.h +0 -1
@@ -660,7 +660,6 @@ extern unsigned long get_sdram_size(void);#endif /* enable read and write access to EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/PMC440.h +0 -1
@@ -159,7 +159,6 @@#define CONFIG_SYS_I2C_PPC4XX_SPEED_1 400000#define CONFIG_SYS_I2C_PPC4XX_SLAVE_1 0x7F -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR 0x54#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2
include/configs/TQM834x.h +0 -1
@@ -183,7 +183,6 @@#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2/* 16 bit */ #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 5/* 32 bytes/write */ #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 12/* 10ms +/- 20% */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS /* more than one eeprom */ /* I2C RTC */ #define CONFIG_RTC_DS1337 /* use ds1337 rtc via i2c */
include/configs/acadia.h +0 -1
@@ -120,7 +120,6 @@*----------------------------------------------------------------------*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/am335x_evm.h +0 -1
@@ -213,7 +213,6 @@#define CONFIG_ENV_EEPROM_IS_ON_I2C #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50/* Main EEPROM */ #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2 -#define CONFIG_SYS_I2C_MULTI_EEPROMS /* PMIC support */ #define CONFIG_POWER_TPS65217
include/configs/am43xx_evm.h +0 -1
@@ -36,7 +36,6 @@#define CONFIG_ENV_EEPROM_IS_ON_I2C #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50/* Main EEPROM */ #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2 -#define CONFIG_SYS_I2C_MULTI_EEPROMS /* Power */ #define CONFIG_POWER
include/configs/axs101.h +0 -1
@@ -91,7 +91,6 @@/* * EEPROM configuration */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xA8 >> 1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW 1
include/configs/bamboo.h +0 -1
@@ -139,7 +139,6 @@*----------------------------------------------------------------------*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/canyonlands.h +0 -1
@@ -248,7 +248,6 @@*----------------------------------------------------------------------*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/icon.h +0 -1
@@ -107,7 +107,6 @@#define CONFIG_SYS_SPD_BUS_NUM 0/* The I2C bus for SPD */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/intip.h +0 -1
@@ -214,7 +214,6 @@*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/katmai.h +0 -1
@@ -109,7 +109,6 @@#define IIC0_BOOTPROM_ADDR 0x50#define IIC0_ALT_BOOTPROM_ADDR 0x54 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0x50)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/km/km-powerpc.h +0 -1
@@ -21,7 +21,6 @@#define CONFIG_KM_COMMON_ETH_INIT /* EEprom support 24C08, 24C16, 24C64 */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_EEPROM_PAGE_WRITE_ENABLE #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3/* 8 Byte write page */ #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 10
include/configs/km/km_arm.h +0 -1
@@ -215,7 +215,6 @@ int get_scl(void);#define CONFIG_SYS_I2C_SOFT_SPEED 100000/* EEprom support 24C128, 24C256 valid for environment eeprom */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_EEPROM_PAGE_WRITE_ENABLE #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 6/* 64 Byte write page */ #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 10
include/configs/luan.h +0 -1
@@ -119,7 +119,6 @@*----------------------------------------------------------------------*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/m28evk.h +0 -1
@@ -92,7 +92,6 @@/* EEPROM */ #ifdef CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2#endif
include/configs/motionpro.h +0 -1
@@ -285,7 +285,6 @@#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 1/* 2 bytes per write cycle */ #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5/* 2ms/cycle + 3ms extra */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS 1/* 2 EEPROMs (addr:50,52) */ /* * RTC configuration
include/configs/p1_p2_rdb_pc.h +0 -1
@@ -701,7 +701,6 @@/* enable read and write access to EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/p1_twr.h +0 -1
@@ -262,7 +262,6 @@ extern unsigned long get_board_sys_clk(unsigned long dummy);/* enable read and write access to EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/pcm051.h +0 -1
@@ -115,7 +115,6 @@#define CONFIG_ENV_EEPROM_IS_ON_I2C #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50/* Main EEPROM */ #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_BAUDRATE_TABLE { 110, 300, 600, 1200, 2400, \ 4800, 9600, 14400, 19200, 28800, 38400, 56000, 57600, 115200 }
include/configs/pengwyn.h +0 -1
@@ -112,7 +112,6 @@#define CONFIG_ENV_EEPROM_IS_ON_I2C #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2 -#define CONFIG_SYS_I2C_MULTI_EEPROMS /* SPL */ #define CONFIG_SPL_POWER_SUPPORT
include/configs/sequoia.h +0 -1
@@ -151,7 +151,6 @@*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/t3corp.h +0 -1
@@ -307,7 +307,6 @@*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/tricorder.h +0 -1
@@ -112,7 +112,6 @@/* EEPROM */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_CMD_EEPROM #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2#define CONFIG_SYS_EEPROM_BUS_NUM 1
include/configs/walnut.h +0 -1
@@ -80,7 +80,6 @@*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/yosemite.h +0 -1
@@ -122,7 +122,6 @@*----------------------------------------------------------------------*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
Signature · 1 line
2.1.4
PATCH 3/17 eeprom: Zap CONFIG_SYS_I2C_MULTI_EEPROMS
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 34 lines
This option only complicates the code unnecessarily, just use
CONFIG_SYS_DEF_EEPROM_ADDRas the default address if there are only five arguments to eeprom {read/write} if this is defined. IfCONFIG_SYS_DEF_EEPROM_ADDRis not defined, we mandate all six arguments.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 69 ++++++++++++++++++----------------------- include/configs/BSC9131RDB.h | 1 - include/configs/BSC9132QDS.h | 1 - include/configs/C29XPCIE.h | 1 - include/configs/P1010RDB.h | 1 - include/configs/PMC440.h | 1 - include/configs/TQM834x.h | 1 - include/configs/acadia.h | 1 - include/configs/am335x_evm.h | 1 - include/configs/am43xx_evm.h | 1 - include/configs/axs101.h | 1 - include/configs/bamboo.h | 1 - include/configs/canyonlands.h | 1 - include/configs/icon.h | 1 - include/configs/intip.h | 1 - include/configs/katmai.h | 1 - include/configs/km/km-powerpc.h | 1 - include/configs/km/km_arm.h | 1 - include/configs/luan.h | 1 - include/configs/m28evk.h | 1 - include/configs/motionpro.h | 1 - include/configs/p1_p2_rdb_pc.h | 1 - include/configs/p1_twr.h | 1 -
Quoted 8 lines
include/configs/pcm051.h | 1 - include/configs/pengwyn.h | 1 - include/configs/sequoia.h | 1 - include/configs/t3corp.h | 1 - include/configs/tricorder.h | 1 - include/configs/walnut.h | 1 - include/configs/yosemite.h | 1 - 30 files changed, 30 insertions(+), 68 deletions(-)
bye,
Heiko
Quoted 448 lines
common/cmd_eeprom.c +30
-39@@ -338,50 +338,50 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {const char *const fmt ="\nEEPROM @0x%lX %s: addr %08lx off %04lx count %ld ... " ; +char *const *args = &argv[2 ]; +int rcode; +ulong dev_addr, addr, off, cnt; + +switch (argc) { +#ifdef CONFIG_SYS_DEF_EEPROM_ADDR +case 5 : + dev_addr =CONFIG_SYS_DEF_EEPROM_ADDR ; +break ; +#endif +case 6 : + dev_addr =simple_strtoul (*args++,NULL ,16 ); +break ; +default : +return CMD_RET_USAGE ; + } -#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS) - if (argc == 6) { - ulong dev_addr = simple_strtoul (argv[2], NULL, 16); - ulong addr = simple_strtoul (argv[3], NULL, 16); - ulong off = simple_strtoul (argv[4], NULL, 16); - ulong cnt = simple_strtoul (argv[5], NULL, 16); -#else - if (argc == 5) { - ulong dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR; - ulong addr = simple_strtoul (argv[2], NULL, 16); - ulong off = simple_strtoul (argv[3], NULL, 16); - ulong cnt = simple_strtoul (argv[4], NULL, 16); -#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */ + addr =simple_strtoul (*args++,NULL ,16 ); + off =simple_strtoul (*args++,NULL ,16 ); + cnt =simple_strtoul (*args++,NULL ,16 );# if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) - eeprom_init (); +eeprom_init ();# endif /* !CONFIG_SPI */ - if (strcmp (argv[1], "read") == 0) { - int rcode; - - printf (fmt, dev_addr, argv[1], addr, off, cnt); - - rcode = eeprom_read (dev_addr, off, (uchar *) addr, cnt); +if (strcmp (argv[1 ],"read" ) ==0 ) { +printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - puts ("done\n"); - return rcode; - } else if (strcmp (argv[1], "write") == 0) { - int rcode; + rcode =eeprom_read (dev_addr, off, (uchar *) addr, cnt); - printf (fmt, dev_addr, argv[1], addr, off, cnt); +puts ("done\n" ); +return rcode; + }else if (strcmp (argv[1 ],"write" ) ==0 ) { +printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - rcode = eeprom_write (dev_addr, off, (uchar *) addr, cnt); + rcode =eeprom_write (dev_addr, off, (uchar *) addr, cnt); - puts ("done\n"); - return rcode; - } +puts ("done\n" ); +return rcode; }return CMD_RET_USAGE ; } -#ifdef CONFIG_SYS_I2C_MULTI_EEPROMS U_BOOT_CMD( eeprom, 6, 1, do_eeprom, "EEPROM sub-system",@@ -389,12 +389,3 @@ U_BOOT_CMD("eeprom write devaddr addr off cnt\n" " - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'" ) -#else /* One EEPROM */ -U_BOOT_CMD ( - eeprom,5 ,1 , do_eeprom, -"EEPROM sub-system" , -"read addr off cnt\n" -"eeprom write addr off cnt\n" -" - read/write `cnt' bytes at EEPROM offset `off'" -) -#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */ include/configs/BSC9131RDB.h +0
-1@@ -267,7 +267,6 @@ extern unsigned long get_sdram_size(void);/* I2C EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5include/configs/BSC9132QDS.h +0
-1@@ -463,7 +463,6 @@ combinations. this should be removed later/* enable read and write access to EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5include/configs/C29XPCIE.h +0
-1@@ -420,7 +420,6 @@/* I2C EEPROM */ /* enable read and write access to EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5include/configs/P1010RDB.h +0
-1@@ -660,7 +660,6 @@ extern unsigned long get_sdram_size(void);#endif /* enable read and write access to EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5include/configs/PMC440.h +0
-1@@ -159,7 +159,6 @@#define CONFIG_SYS_I2C_PPC4XX_SPEED_1 400000#define CONFIG_SYS_I2C_PPC4XX_SLAVE_1 0x7F -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR 0x54#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2include/configs/TQM834x.h +0
-1@@ -183,7 +183,6 @@#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2/* 16 bit */ #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 5/* 32 bytes/write */ #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 12/* 10ms +/- 20% */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS /* more than one eeprom */ /* I2C RTC */ #define CONFIG_RTC_DS1337 /* use ds1337 rtc via i2c */ include/configs/acadia.h +0
-1@@ -120,7 +120,6 @@*----------------------------------------------------------------------*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3include/configs/am335x_evm.h +0
-1@@ -213,7 +213,6 @@#define CONFIG_ENV_EEPROM_IS_ON_I2C #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50/* Main EEPROM */ #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2 -#define CONFIG_SYS_I2C_MULTI_EEPROMS /* PMIC support */ #define CONFIG_POWER_TPS65217 include/configs/am43xx_evm.h +0
-1@@ -36,7 +36,6 @@#define CONFIG_ENV_EEPROM_IS_ON_I2C #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50/* Main EEPROM */ #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2 -#define CONFIG_SYS_I2C_MULTI_EEPROMS /* Power */ #define CONFIG_POWER include/configs/axs101.h +0
-1@@ -91,7 +91,6 @@/* * EEPROM configuration */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xA8 >> 1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW 1include/configs/bamboo.h +0
-1@@ -139,7 +139,6 @@*----------------------------------------------------------------------*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3include/configs/canyonlands.h +0
-1@@ -248,7 +248,6 @@*----------------------------------------------------------------------*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3include/configs/icon.h +0
-1@@ -107,7 +107,6 @@#define CONFIG_SYS_SPD_BUS_NUM 0/* The I2C bus for SPD */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3include/configs/intip.h +0
-1@@ -214,7 +214,6 @@*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3include/configs/katmai.h +0
-1@@ -109,7 +109,6 @@#define IIC0_BOOTPROM_ADDR 0x50#define IIC0_ALT_BOOTPROM_ADDR 0x54 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0x50)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3include/configs/km/km-powerpc.h +0
-1@@ -21,7 +21,6 @@#define CONFIG_KM_COMMON_ETH_INIT /* EEprom support 24C08, 24C16, 24C64 */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_EEPROM_PAGE_WRITE_ENABLE #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3/* 8 Byte write page */ #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 10include/configs/km/km_arm.h +0
-1@@ -215,7 +215,6 @@ int get_scl(void);#define CONFIG_SYS_I2C_SOFT_SPEED 100000/* EEprom support 24C128, 24C256 valid for environment eeprom */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_EEPROM_PAGE_WRITE_ENABLE #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 6/* 64 Byte write page */ #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 10include/configs/luan.h +0
-1@@ -119,7 +119,6 @@*----------------------------------------------------------------------*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3include/configs/m28evk.h +0
-1@@ -92,7 +92,6 @@/* EEPROM */ #ifdef CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2#endif include/configs/motionpro.h +0
-1@@ -285,7 +285,6 @@#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 1/* 2 bytes per write cycle */ #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5/* 2ms/cycle + 3ms extra */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS 1/* 2 EEPROMs (addr:50,52) */ /* * RTC configuration include/configs/p1_p2_rdb_pc.h +0
-1@@ -701,7 +701,6 @@/* enable read and write access to EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5include/configs/p1_twr.h +0
-1@@ -262,7 +262,6 @@ extern unsigned long get_board_sys_clk(unsigned long dummy);/* enable read and write access to EEPROM */ #define CONFIG_CMD_EEPROM -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5include/configs/pcm051.h +0
-1@@ -115,7 +115,6 @@#define CONFIG_ENV_EEPROM_IS_ON_I2C #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50/* Main EEPROM */ #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_BAUDRATE_TABLE { 110, 300, 600, 1200, 2400, \ 4800, 9600, 14400, 19200, 28800, 38400, 56000, 57600, 115200 }include/configs/pengwyn.h +0
-1@@ -112,7 +112,6 @@#define CONFIG_ENV_EEPROM_IS_ON_I2C #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2 -#define CONFIG_SYS_I2C_MULTI_EEPROMS /* SPL */ #define CONFIG_SPL_POWER_SUPPORT include/configs/sequoia.h +0
-1@@ -151,7 +151,6 @@*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3include/configs/t3corp.h +0
-1@@ -307,7 +307,6 @@*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3include/configs/tricorder.h +0
-1@@ -112,7 +112,6 @@/* EEPROM */ -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_CMD_EEPROM #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2#define CONFIG_SYS_EEPROM_BUS_NUM 1include/configs/walnut.h +0
-1@@ -80,7 +80,6 @@*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3include/configs/yosemite.h +0
-1@@ -122,7 +122,6 @@*----------------------------------------------------------------------*/ #define CONFIG_SYS_I2C_PPC4XX_SPEED_0 400000 -#define CONFIG_SYS_I2C_MULTI_EEPROMS #define CONFIG_SYS_I2C_EEPROM_ADDR (0xa8>>1)#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 3/17 eeprom: Zap CONFIG_SYS_I2C_MULTI_EEPROMS
In reply to Marek VasutQuoted 11 lines · Marek Vasut
This option only complicates the code unnecessarily, just use
CONFIG_SYS_DEF_EEPROM_ADDRas the default address if there are only five arguments to eeprom {read/write} if this is defined. IfCONFIG_SYS_DEF_EEPROM_ADDRis not defined, we mandate all six arguments.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/61493f78/attachment.sig>
PATCH 4/17 eeprom: Zap CONFIG_SYS_EEPROM_X40430
In reply to Marek VasutNow that the only user of CONFIG_SYS_EEPROM_X40430 was removed, remove this unused code from cmd_eeprom.c
--- common/cmd_eeprom.c | 94 ----------------------------------------------------- 1 file changed, 94 deletions(-)
common/cmd_eeprom.c +0 -94
@@ -29,11 +29,6 @@#define CONFIG_SYS_I2C_SPEED 50000#endif -/* Maximum number of times to poll for acknowledge after write */ -#if defined(CONFIG_SYS_EEPROM_X40430 ) -#define MAX_ACKNOWLEDGE_POLLS 10 -#endif -/* * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is * 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
@@ -141,14 +136,6 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnunsigned blk_off;int rcode =0 ; -#if defined(CONFIG_SYS_EEPROM_X40430 ) -uchar contr_r_addr[2 ]; -uchar addr_void[2 ]; -uchar contr_reg[2 ]; -uchar ctrl_reg_v; -int i; -#endif -#if defined(CONFIG_SYS_EEPROM_WREN )eeprom_write_enable (dev_addr,1 );#endif
@@ -213,88 +200,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn#if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C )spi_write (addr, alen, buffer, len);#else -#if defined(CONFIG_SYS_EEPROM_X40430 ) -/* Get the value of the control register. -* Set current address (internal pointer in the x40430) -* to 0x1ff. -*/ - contr_r_addr[0 ] =9 ; - contr_r_addr[1 ] =0xff ; - addr_void[0 ] =0 ; - addr_void[1 ] = addr[1 ]; -#ifdef CONFIG_SYS_I2C_EEPROM_ADDR - contr_r_addr[0 ] |=CONFIG_SYS_I2C_EEPROM_ADDR ; - addr_void[0 ] |=CONFIG_SYS_I2C_EEPROM_ADDR ; -#endif - contr_reg[0 ] =0xff ; -if (i2c_read (contr_r_addr[0 ], contr_r_addr[1 ],1 , contr_reg,1 ) !=0 ) { - rcode =1 ; - } - ctrl_reg_v = contr_reg[0 ]; -/* Are any of the eeprom blocks write protected? -*/ -if (ctrl_reg_v &0x18 ) { - ctrl_reg_v &= ~0x18 ;/* reset block protect bits */ - ctrl_reg_v |=0x02 ;/* set write enable latch */ - ctrl_reg_v &= ~0x04 ;/* clear RWEL */ - -/* Set write enable latch. -*/ - contr_reg[0 ] =0x02 ; -if (i2c_write (contr_r_addr[0 ],0xff ,1 , contr_reg,1 ) !=0 ) { - rcode =1 ; - } - -/* Set register write enable latch. -*/ - contr_reg[0 ] =0x06 ; -if (i2c_write (contr_r_addr[0 ],0xFF ,1 , contr_reg,1 ) !=0 ) { - rcode =1 ; - } - -/* Modify ctrl register. -*/ - contr_reg[0 ] = ctrl_reg_v; -if (i2c_write (contr_r_addr[0 ],0xFF ,1 , contr_reg,1 ) !=0 ) { - rcode =1 ; - } - -/* The write (above) is an operation on NV memory. -* These can take some time (~5ms), and the device -* will not respond to further I2C messages till -* it's completed the write. -* So poll device for an I2C acknowledge. -* When we get one we know we can continue with other -* operations. -*/ - contr_reg[0 ] =0 ; -for (i =0 ; i <MAX_ACKNOWLEDGE_POLLS ; i++) { -if (i2c_read (addr_void[0 ], addr_void[1 ],1 , contr_reg,1 ) ==0 ) -break ;/* got ack */ -#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS ) -udelay (CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS *1000 ); -#endif - } -if (i ==MAX_ACKNOWLEDGE_POLLS ) { -puts ("EEPROM poll acknowledge failed\n" ); - rcode =1 ; - } - } - -/* Is the write enable latch on?. -*/ -else if (!(ctrl_reg_v &0x02 )) { -/* Set write enable latch. -*/ - contr_reg[0 ] =0x02 ; -if (i2c_write (contr_r_addr[0 ],0xFF ,1 , contr_reg,1 ) !=0 ) { - rcode =1 ; - } - } -/* Write is enabled ... now write eeprom value. -*/ -#endif #if defined(CONFIG_SYS_I2C_EEPROM_BUS )i2c_set_bus_num (CONFIG_SYS_I2C_EEPROM_BUS );#endif
Signature · 1 line
2.1.4
PATCH 4/17 eeprom: Zap CONFIG_SYS_EEPROM_X40430
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 10 lines
Now that the only user of
CONFIG_SYS_EEPROM_X40430was removed, remove this unused code fromcmd_eeprom.cSigned-off-by Marek Vasut <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 94 ----------------------------------------------------- 1 file changed, 94 deletions(-)
bye,
Heiko
Quoted 122 lines
common/cmd_eeprom.c +0
-94@@ -29,11 +29,6 @@#define CONFIG_SYS_I2C_SPEED 50000#endif -/* Maximum number of times to poll for acknowledge after write */ -#if defined(CONFIG_SYS_EEPROM_X40430 ) -#define MAX_ACKNOWLEDGE_POLLS 10 -#endif -/* * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is * 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM. @@ -141,14 +136,6 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnunsigned blk_off;int rcode =0 ; -#if defined(CONFIG_SYS_EEPROM_X40430 ) -uchar contr_r_addr[2 ]; -uchar addr_void[2 ]; -uchar contr_reg[2 ]; -uchar ctrl_reg_v; -int i; -#endif -#if defined(CONFIG_SYS_EEPROM_WREN )eeprom_write_enable (dev_addr,1 );#endif @@ -213,88 +200,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn#if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C )spi_write (addr, alen, buffer, len);#else -#if defined(CONFIG_SYS_EEPROM_X40430 ) -/* Get the value of the control register. -* Set current address (internal pointer in the x40430) -* to 0x1ff. -*/ - contr_r_addr[0 ] =9 ; - contr_r_addr[1 ] =0xff ; - addr_void[0 ] =0 ; - addr_void[1 ] = addr[1 ]; -#ifdef CONFIG_SYS_I2C_EEPROM_ADDR - contr_r_addr[0 ] |=CONFIG_SYS_I2C_EEPROM_ADDR ; - addr_void[0 ] |=CONFIG_SYS_I2C_EEPROM_ADDR ; -#endif - contr_reg[0 ] =0xff ; -if (i2c_read (contr_r_addr[0 ], contr_r_addr[1 ],1 , contr_reg,1 ) !=0 ) { - rcode =1 ; - } - ctrl_reg_v = contr_reg[0 ]; -/* Are any of the eeprom blocks write protected? -*/ -if (ctrl_reg_v &0x18 ) { - ctrl_reg_v &= ~0x18 ;/* reset block protect bits */ - ctrl_reg_v |=0x02 ;/* set write enable latch */ - ctrl_reg_v &= ~0x04 ;/* clear RWEL */ - -/* Set write enable latch. -*/ - contr_reg[0 ] =0x02 ; -if (i2c_write (contr_r_addr[0 ],0xff ,1 , contr_reg,1 ) !=0 ) { - rcode =1 ; - } - -/* Set register write enable latch. -*/ - contr_reg[0 ] =0x06 ; -if (i2c_write (contr_r_addr[0 ],0xFF ,1 , contr_reg,1 ) !=0 ) { - rcode =1 ; - } - -/* Modify ctrl register. -*/ - contr_reg[0 ] = ctrl_reg_v; -if (i2c_write (contr_r_addr[0 ],0xFF ,1 , contr_reg,1 ) !=0 ) { - rcode =1 ; - } - -/* The write (above) is an operation on NV memory. -* These can take some time (~5ms), and the device -* will not respond to further I2C messages till -* it's completed the write. -* So poll device for an I2C acknowledge. -* When we get one we know we can continue with other -* operations. -*/ - contr_reg[0 ] =0 ; -for (i =0 ; i <MAX_ACKNOWLEDGE_POLLS ; i++) { -if (i2c_read (addr_void[0 ], addr_void[1 ],1 , contr_reg,1 ) ==0 ) -break ;/* got ack */ -#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS ) -udelay (CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS *1000 ); -#endif - } -if (i ==MAX_ACKNOWLEDGE_POLLS ) { -puts ("EEPROM poll acknowledge failed\n" ); - rcode =1 ; - } - } - -/* Is the write enable latch on?. -*/ -else if (!(ctrl_reg_v &0x02 )) { -/* Set write enable latch. -*/ - contr_reg[0 ] =0x02 ; -if (i2c_write (contr_r_addr[0 ],0xFF ,1 , contr_reg,1 ) !=0 ) { - rcode =1 ; - } - } -/* Write is enabled ... now write eeprom value. -*/ -#endif #if defined(CONFIG_SYS_I2C_EEPROM_BUS )i2c_set_bus_num (CONFIG_SYS_I2C_EEPROM_BUS );#endif
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 4/17 eeprom: Zap CONFIG_SYS_EEPROM_X40430
In reply to Marek VasutQuoted 8 lines · Marek Vasut
Now that the only user of
CONFIG_SYS_EEPROM_X40430was removed, remove this unused code fromcmd_eeprom.cSigned-off-by Marek Vasut <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/284a924a/attachment.sig>
PATCH 5/17 eeprom: Zap eeprom_probe()
In reply to Marek VasutRemove this function as it's no longer used.
--- common/cmd_eeprom.c | 19 ------------------- include/common.h | 3 --- 2 files changed, 22 deletions(-)
common/cmd_eeprom.c +0 -19
@@ -221,25 +221,6 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnreturn rcode; } -#if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -int eeprom_probe (unsigned dev_addr,unsigned offset) -{ -unsigned char chip; - -/* Probe the chip address -*/ -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 && !defined(CONFIG_SPI_X ) - chip = offset >>8 ;/* block number */ -#else - chip = offset >>16 ;/* block number */ -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */ - - chip |= dev_addr;/* insert device address */ - -return (i2c_probe (chip)); -} -#endif -static int do_eeprom (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { const char *const fmt =
include/common.h +0 -3
@@ -476,9 +476,6 @@ void fdc_hw_init (void);/* $(BOARD)/eeprom.c */ void eeprom_init (void ); -#ifndef CONFIG_SPI -int eeprom_probe (unsigned dev_addr,unsigned offset); -#endif int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt);int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt);
Signature · 1 line
2.1.4
PATCH 5/17 eeprom: Zap eeprom_probe()
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 10 lines
Remove this function as it's no longer used.
Signed-off-by Marek Vasut <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 19 ------------------- include/common.h | 3 --- 2 files changed, 22 deletions(-)
bye,
Heiko
Quoted 46 lines
common/cmd_eeprom.c +0
-19@@ -221,25 +221,6 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnreturn rcode; } -#if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -int eeprom_probe (unsigned dev_addr,unsigned offset) -{ -unsigned char chip; - -/* Probe the chip address -*/ -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 && !defined(CONFIG_SPI_X ) - chip = offset >>8 ;/* block number */ -#else - chip = offset >>16 ;/* block number */ -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */ - - chip |= dev_addr;/* insert device address */ - -return (i2c_probe (chip)); -} -#endif -static int do_eeprom (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { const char *const fmt =include/common.h +0
-3@@ -476,9 +476,6 @@ void fdc_hw_init (void);/* $(BOARD)/eeprom.c */ void eeprom_init (void ); -#ifndef CONFIG_SPI -int eeprom_probe (unsigned dev_addr,unsigned offset); -#endif int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt);int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt);
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 5/17 eeprom: Zap eeprom_probe()
In reply to Marek VasutQuoted 7 lines · Marek Vasut
Remove this function as it's no longer used.
Signed-off-by Marek Vasut <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/5cf52cf2/attachment.sig>
PATCH 6/17 eeprom: Zap CONFIG_SPI_X
In reply to Marek VasutThis macro is no longer used, so just reap it.
--- README | 5 ----- common/cmd_eeprom.c | 8 ++++---- 2 files changed, 4 insertions(+), 9 deletions(-)
README +0 -5
@@ -2705,11 +2705,6 @@ CBFS (Coreboot Filesystem) support Enables the driver for SPI controller on SuperH. Currently only SH7757 is supported. - CONFIG_SPI_X - - Enables extended (16-bit) SPI EEPROM addressing. - (symmetrical to CONFIG_I2C_X) - CONFIG_SOFT_SPI Enables a software (bit-bang) SPI driver rather than
common/cmd_eeprom.c +4 -4
@@ -78,7 +78,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cntunsigned maxlen;#endif -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 && !defined(CONFIG_SPI_X ) +#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 uchar addr[2 ]; blk_off = offset &0xFF ;/* block offset */
@@ -95,7 +95,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt addr[1 ] = offset >>8 ;/* upper address octet */ addr[2 ] = blk_off;/* lower address octet */ alen =3 ; -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */ +#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ addr[0 ] |= dev_addr;/* insert device address */
@@ -151,7 +151,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnunsigned maxlen;#endif -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 && !defined(CONFIG_SPI_X ) +#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 uchar addr[2 ]; blk_off = offset &0xFF ;/* block offset */
@@ -168,7 +168,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn addr[1 ] = offset >>8 ;/* upper address octet */ addr[2 ] = blk_off;/* lower address octet */ alen =3 ; -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */ +#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ addr[0 ] |= dev_addr;/* insert device address */
Signature · 1 line
2.1.4
PATCH 6/17 eeprom: Zap CONFIG_SPI_X
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 10 lines
This macro is no longer used, so just reap it.
Signed-off-by Marek Vasut <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>Cc Heiko Schocher <[email protected]>--- README | 5 ----- common/cmd_eeprom.c | 8 ++++---- 2 files changed, 4 insertions(+), 9 deletions(-)
bye,
Heiko
Quoted 58 lines
README +0
-5@@ -2705,11 +2705,6 @@ CBFS (Coreboot Filesystem) support Enables the driver for SPI controller on SuperH. Currently only SH7757 is supported. - CONFIG_SPI_X - - Enables extended (16-bit) SPI EEPROM addressing. - (symmetrical to CONFIG_I2C_X) - CONFIG_SOFT_SPI Enables a software (bit-bang) SPI driver rather thancommon/cmd_eeprom.c +4
-4@@ -78,7 +78,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cntunsigned maxlen;#endif -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 && !defined(CONFIG_SPI_X ) +#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 uchar addr[2 ]; blk_off = offset &0xFF ;/* block offset */ @@ -95,7 +95,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt addr[1 ] = offset >>8 ;/* upper address octet */ addr[2 ] = blk_off;/* lower address octet */ alen =3 ; -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */ +#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ addr[0 ] |= dev_addr;/* insert device address */ @@ -151,7 +151,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnunsigned maxlen;#endif -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 && !defined(CONFIG_SPI_X ) +#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 uchar addr[2 ]; blk_off = offset &0xFF ;/* block offset */ @@ -168,7 +168,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn addr[1 ] = offset >>8 ;/* upper address octet */ addr[2 ] = blk_off;/* lower address octet */ alen =3 ; -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */ +#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ addr[0 ] |= dev_addr;/* insert device address */
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 6/17 eeprom: Zap CONFIG_SPI_X
In reply to Marek VasutQuoted 7 lines · Marek Vasut
This macro is no longer used, so just reap it.
Signed-off-by Marek Vasut <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/48cc885b/attachment.sig>
PATCH 7/17 eeprom: Pull out the I/O code
In reply to Marek VasutPull out the code which does the I2C or SPI read/write, so that the beefy ifdef around it is contained in a single function.
--- common/cmd_eeprom.c | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-)
common/cmd_eeprom.c +31 -19
@@ -61,6 +61,34 @@ void eeprom_init(void)#endif } +static int eeprom_rw_block (unsigned offset,uchar *addr,unsigned alen, +uchar *buffer,unsigned len,bool read) +{ +int ret =0 ; + +/* SPI */ +#if defined(CONFIG_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_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); + +if (ret) + ret =1 ; +#endif +return ret; +} +int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) {unsigned end = offset + cnt;
@@ -114,15 +142,8 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt len = maxlen;#endif -#if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -spi_read (addr, alen, buffer, len); -#else -#if defined(CONFIG_SYS_I2C_EEPROM_BUS ) -i2c_set_bus_num (CONFIG_SYS_I2C_EEPROM_BUS ); -#endif -if (i2c_read (addr[0 ], offset, alen -1 , buffer, len)) - rcode =1 ; -#endif + rcode =eeprom_rw_block (offset, addr, alen, buffer, len,1 ); + buffer += len; offset += len; }
@@ -197,17 +218,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn len = maxlen;#endif -#if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -spi_write (addr, alen, buffer, len); -#else + rcode =eeprom_rw_block (offset, addr, alen, buffer, len,0 ); -#if defined(CONFIG_SYS_I2C_EEPROM_BUS ) -i2c_set_bus_num (CONFIG_SYS_I2C_EEPROM_BUS ); -#endif -if (i2c_write (addr[0 ], offset, alen -1 , buffer, len)) - rcode =1 ; - -#endif buffer += len; offset += len;
Signature · 1 line
2.1.4
PATCH 7/17 eeprom: Pull out the I/O code
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 10 lines
Pull out the code which does the I2C or SPI read/write, so that the beefy ifdef around it is contained in a single function.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-)
bye,
Heiko
Quoted 78 lines
common/cmd_eeprom.c +31
-19@@ -61,6 +61,34 @@ void eeprom_init(void)#endif } +static int eeprom_rw_block (unsigned offset,uchar *addr,unsigned alen, +uchar *buffer,unsigned len,bool read) +{ +int ret =0 ; + +/* SPI */ +#if defined(CONFIG_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_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); + +if (ret) + ret =1 ; +#endif +return ret; +} +int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) {unsigned end = offset + cnt;@@ -114,15 +142,8 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt len = maxlen;#endif -#if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -spi_read (addr, alen, buffer, len); -#else -#if defined(CONFIG_SYS_I2C_EEPROM_BUS ) -i2c_set_bus_num (CONFIG_SYS_I2C_EEPROM_BUS ); -#endif -if (i2c_read (addr[0 ], offset, alen -1 , buffer, len)) - rcode =1 ; -#endif + rcode =eeprom_rw_block (offset, addr, alen, buffer, len,1 ); + buffer += len; offset += len; }@@ -197,17 +218,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn len = maxlen;#endif -#if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -spi_write (addr, alen, buffer, len); -#else + rcode =eeprom_rw_block (offset, addr, alen, buffer, len,0 ); -#if defined(CONFIG_SYS_I2C_EEPROM_BUS ) -i2c_set_bus_num (CONFIG_SYS_I2C_EEPROM_BUS ); -#endif -if (i2c_write (addr[0 ], offset, alen -1 , buffer, len)) - rcode =1 ; - -#endif buffer += len; offset += len;
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 7/17 eeprom: Pull out the I/O code
In reply to Marek VasutQuoted 8 lines · Marek Vasut
Pull out the code which does the I2C or SPI read/write, so that the beefy ifdef around it is contained in a single function.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/d719b9af/attachment.sig>
PATCH 8/17 eeprom: Pull out address computation
In reply to Marek VasutPull out the code computing the EEPROM address into separate function so that it's not duplicated.
--- common/cmd_eeprom.c | 64 ++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 38 deletions(-)
common/cmd_eeprom.c +26 -38
@@ -61,6 +61,28 @@ void eeprom_init(void)#endif } +static int eeprom_addr (unsigned dev_addr,unsigned offset,uchar *addr) +{ +unsigned blk_off; +int alen; + + blk_off = offset &0xff ;/* block offset */ +#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 + addr[0 ] = offset >>8 ;/* block number */ + addr[1 ] = blk_off;/* block offset */ + alen =2 ; +#else + addr[0 ] = offset >>16 ;/* block number */ + addr[1 ] = offset >>8 ;/* upper address octet */ + addr[2 ] = blk_off;/* lower address octet */ + alen =3 ; +#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ + + addr[0 ] |= dev_addr;/* insert device address */ + +return alen; +} +static int eeprom_rw_block (unsigned offset,uchar *addr,unsigned alen,uchar *buffer,unsigned len,bool read) {
@@ -94,6 +116,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cntunsigned end = offset + cnt;unsigned blk_off;int rcode =0 ; +uchar addr[3 ];/* * Read data until done or would cross a page boundary.
@@ -106,26 +129,8 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cntunsigned maxlen;#endif -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 -uchar addr[2 ]; - - blk_off = offset &0xFF ;/* block offset */ - - addr[0 ] = offset >>8 ;/* block number */ - addr[1 ] = blk_off;/* block offset */ - alen =2 ; -#else -uchar addr[3 ]; - blk_off = offset &0xFF ;/* block offset */ - - addr[0 ] = offset >>16 ;/* block number */ - addr[1 ] = offset >>8 ;/* upper address octet */ - addr[2 ] = blk_off;/* lower address octet */ - alen =3 ; -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ - - addr[0 ] |= dev_addr;/* insert device address */ + alen =eeprom_addr (dev_addr, offset, addr); len = end - offset;
@@ -156,6 +161,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnunsigned end = offset + cnt;unsigned blk_off;int rcode =0 ; +uchar addr[3 ];#if defined(CONFIG_SYS_EEPROM_WREN )eeprom_write_enable (dev_addr,1 );
@@ -172,26 +178,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnunsigned maxlen;#endif -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 -uchar addr[2 ]; - blk_off = offset &0xFF ;/* block offset */ - - addr[0 ] = offset >>8 ;/* block number */ - addr[1 ] = blk_off;/* block offset */ - alen =2 ; -#else -uchar addr[3 ]; - - blk_off = offset &0xFF ;/* block offset */ - - addr[0 ] = offset >>16 ;/* block number */ - addr[1 ] = offset >>8 ;/* upper address octet */ - addr[2 ] = blk_off;/* lower address octet */ - alen =3 ; -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ - - addr[0 ] |= dev_addr;/* insert device address */ + alen =eeprom_addr (dev_addr, offset, addr); len = end - offset;
Signature · 1 line
2.1.4
PATCH 8/17 eeprom: Pull out address computation
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 10 lines
Pull out the code computing the EEPROM address into separate function so that it's not duplicated.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 64 ++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 38 deletions(-)
bye,
Heiko
Quoted 107 lines
common/cmd_eeprom.c +26
-38@@ -61,6 +61,28 @@ void eeprom_init(void)#endif } +static int eeprom_addr (unsigned dev_addr,unsigned offset,uchar *addr) +{ +unsigned blk_off; +int alen; + + blk_off = offset &0xff ;/* block offset */ +#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 + addr[0 ] = offset >>8 ;/* block number */ + addr[1 ] = blk_off;/* block offset */ + alen =2 ; +#else + addr[0 ] = offset >>16 ;/* block number */ + addr[1 ] = offset >>8 ;/* upper address octet */ + addr[2 ] = blk_off;/* lower address octet */ + alen =3 ; +#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ + + addr[0 ] |= dev_addr;/* insert device address */ + +return alen; +} +static int eeprom_rw_block (unsigned offset,uchar *addr,unsigned alen,uchar *buffer,unsigned len,bool read) {@@ -94,6 +116,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cntunsigned end = offset + cnt;unsigned blk_off;int rcode =0 ; +uchar addr[3 ];/* * Read data until done or would cross a page boundary. @@ -106,26 +129,8 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cntunsigned maxlen;#endif -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 -uchar addr[2 ]; - - blk_off = offset &0xFF ;/* block offset */ - - addr[0 ] = offset >>8 ;/* block number */ - addr[1 ] = blk_off;/* block offset */ - alen =2 ; -#else -uchar addr[3 ]; - blk_off = offset &0xFF ;/* block offset */ - - addr[0 ] = offset >>16 ;/* block number */ - addr[1 ] = offset >>8 ;/* upper address octet */ - addr[2 ] = blk_off;/* lower address octet */ - alen =3 ; -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ - - addr[0 ] |= dev_addr;/* insert device address */ + alen =eeprom_addr (dev_addr, offset, addr); len = end - offset;@@ -156,6 +161,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnunsigned end = offset + cnt;unsigned blk_off;int rcode =0 ; +uchar addr[3 ];#if defined(CONFIG_SYS_EEPROM_WREN )eeprom_write_enable (dev_addr,1 );@@ -172,26 +178,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnunsigned maxlen;#endif -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN ==1 -uchar addr[2 ]; - blk_off = offset &0xFF ;/* block offset */ - - addr[0 ] = offset >>8 ;/* block number */ - addr[1 ] = blk_off;/* block offset */ - alen =2 ; -#else -uchar addr[3 ]; - - blk_off = offset &0xFF ;/* block offset */ - - addr[0 ] = offset >>16 ;/* block number */ - addr[1 ] = offset >>8 ;/* upper address octet */ - addr[2 ] = blk_off;/* lower address octet */ - alen =3 ; -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ - - addr[0 ] |= dev_addr;/* insert device address */ + alen =eeprom_addr (dev_addr, offset, addr); len = end - offset;
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 8/17 eeprom: Pull out address computation
In reply to Marek VasutQuoted 8 lines · Marek Vasut
Pull out the code computing the EEPROM address into separate function so that it's not duplicated.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/79184d2e/attachment.sig>
PATCH 9/17 eeprom: Make eeprom_write_enable() weak
In reply to Marek VasutMake this function weak and implement it's weak implementation so that the boards can just reimplement it. This zaps the horrid CONFIG_SYS_EEPROM_WREN macro.
--- common/cmd_eeprom.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
common/cmd_eeprom.c +9 -9
@@ -44,9 +44,10 @@#endif #endif -#if defined(CONFIG_SYS_EEPROM_WREN ) -extern int eeprom_write_enable (unsigned dev_addr,int state); -#endif +__weak int eeprom_write_enable (unsigned dev_addr,int state) +{ +return 0 ; +}void eeprom_init (void ) {
@@ -163,9 +164,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnint rcode =0 ;uchar addr[3 ]; -#if defined(CONFIG_SYS_EEPROM_WREN ) -eeprom_write_enable (dev_addr,1 ); -#endif +eeprom_write_enable (dev_addr,1 ); +/* * Write data until done or would cross a write page boundary. * We must write the address again when changing pages
@@ -215,9 +215,9 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnudelay (CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS *1000 );#endif } -#if defined(CONFIG_SYS_EEPROM_WREN ) -eeprom_write_enable (dev_addr,0 ); -#endif + +eeprom_write_enable (dev_addr,0 ); +return rcode; }
Signature · 1 line
2.1.4
PATCH 9/17 eeprom: Make eeprom_write_enable() weak
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 11 lines
Make this function weak and implement it's weak implementation so that the boards can just reimplement it. This zaps the horrid
CONFIG_SYS_EEPROM_WRENmacro.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
bye,
Heiko
Quoted 45 lines
common/cmd_eeprom.c +9
-9@@ -44,9 +44,10 @@#endif #endif -#if defined(CONFIG_SYS_EEPROM_WREN ) -extern int eeprom_write_enable (unsigned dev_addr,int state); -#endif +__weak int eeprom_write_enable (unsigned dev_addr,int state) +{ +return 0 ; +}void eeprom_init (void ) {@@ -163,9 +164,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnint rcode =0 ;uchar addr[3 ]; -#if defined(CONFIG_SYS_EEPROM_WREN ) -eeprom_write_enable (dev_addr,1 ); -#endif +eeprom_write_enable (dev_addr,1 ); +/* * Write data until done or would cross a write page boundary. * We must write the address again when changing pages @@ -215,9 +215,9 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnudelay (CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS *1000 );#endif } -#if defined(CONFIG_SYS_EEPROM_WREN ) -eeprom_write_enable (dev_addr,0 ); -#endif + +eeprom_write_enable (dev_addr,0 ); +return rcode; }
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 9/17 eeprom: Make eeprom_write_enable() weak
In reply to Marek VasutQuoted 9 lines · Marek Vasut
Make this function weak and implement it's weak implementation so that the boards can just reimplement it. This zaps the horrid
CONFIG_SYS_EEPROM_WRENmacro.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/2c247ad0/attachment.sig>
PATCH 10/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
In reply to Marek VasutPull this macro to the beginning of the cmd_eeprom.c and remove another nasty ifdef from the code. Note that this is legal, since udelay(0) changes the behavior only such that it pings the WDT if WDT is enabled and otherwise does not wait.
--- common/cmd_eeprom.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
common/cmd_eeprom.c +4 -2
@@ -29,6 +29,10 @@#define CONFIG_SYS_I2C_SPEED 50000#endif +#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS +#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 0 +#endif +/* * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is * 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
@@ -211,9 +215,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn buffer += len; offset += len; -#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS )udelay (CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS *1000 ); -#endif }eeprom_write_enable (dev_addr,0 );
Signature · 1 line
2.1.4
PATCH 10/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 5 lines
Pull this macro to the beginning of the
cmd_eeprom.cand remove another nasty ifdef from the code. Note that this is legal, since udelay(0) changes the behavior only such that it pings the WDT if WDT is enabled and otherwise does not wait.
Quoted 7 lines
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
bye,
Heiko
Quoted 27 lines
common/cmd_eeprom.c +4
-2@@ -29,6 +29,10 @@#define CONFIG_SYS_I2C_SPEED 50000#endif +#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS +#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 0 +#endif +/* * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is * 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM. @@ -211,9 +215,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn buffer += len; offset += len; -#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS )udelay (CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS *1000 ); -#endif }eeprom_write_enable (dev_addr,0 );
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 10/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
In reply to Marek VasutQuoted 10 lines · Marek Vasut
Pull this macro to the beginning of the
cmd_eeprom.cand remove another nasty ifdef from the code. Note that this is legal, since udelay(0) changes the behavior only such that it pings the WDT if WDT is enabled and otherwise does not wait.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/c107b23e/attachment.sig>
PATCH 11/17 eeprom: Suck the ifdef into eeprom_init()
In reply to Marek VasutJust suck the ugly ifdef around eeprom_init() call into eeprom_init() function itself. This puts all of the ifdef mess into one place.
--- common/cmd_eeprom.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
common/cmd_eeprom.c +2 -4
@@ -57,7 +57,7 @@ void eeprom_init(void) {/* SPI EEPROM */ #if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -spi_init_f (); +spi_init_f ();#endif /* I2C EEPROM */
@@ -248,9 +248,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) off =simple_strtoul (*args++,NULL ,16 ); cnt =simple_strtoul (*args++,NULL ,16 ); -# if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -eeprom_init (); -# endif /* !CONFIG_SPI */ +eeprom_init ();if (strcmp (argv[1 ],"read" ) ==0 ) {printf (fmt, dev_addr, argv[1 ], addr, off, cnt);
Signature · 1 line
2.1.4
PATCH 11/17 eeprom: Suck the ifdef into eeprom_init()
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 10 lines
Just suck the ugly ifdef around
eeprom_init()call intoeeprom_init()function itself. This puts all of the ifdef mess into one place.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
bye,
Heiko
Quoted 26 lines
common/cmd_eeprom.c +2
-4@@ -57,7 +57,7 @@ void eeprom_init(void) {/* SPI EEPROM */ #if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -spi_init_f (); +spi_init_f ();#endif /* I2C EEPROM */ @@ -248,9 +248,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) off =simple_strtoul (*args++,NULL ,16 ); cnt =simple_strtoul (*args++,NULL ,16 ); -# if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C ) -eeprom_init (); -# endif /* !CONFIG_SPI */ +eeprom_init ();if (strcmp (argv[1 ],"read" ) ==0 ) {printf (fmt, dev_addr, argv[1 ], addr, off, cnt);
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 11/17 eeprom: Suck the ifdef into eeprom_init()
In reply to Marek VasutQuoted 8 lines · Marek Vasut
Just suck the ugly ifdef around
eeprom_init()call intoeeprom_init()function itself. This puts all of the ifdef mess into one place.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/8b57ffc1/attachment.sig>
PATCH 12/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_BITS
In reply to Marek VasutImplement default value of 8 for this macro and pull out all of this macro out of the code. The default value of 8 actually does implement exactly the same behavior as the previous code which was in the #else clause of the ifdef.
--- common/cmd_eeprom.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
common/cmd_eeprom.c +8 -8
@@ -33,6 +33,13 @@#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 0#endif +#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_BITS +#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 8 +#endif + +#define EEPROM_PAGE_SIZE (1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS) +#define EEPROM_PAGE_OFFSET (x) ((x) & (EEPROM_PAGE_SIZE - 1)) +/* * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is * 0x000nxxxx for EEPROM address selectors@n, offset xxxx in EEPROM.
@@ -194,15 +201,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn*/ #if !defined(CONFIG_SYS_I2C_FRAM ) -#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_BITS ) - -#define EEPROM_PAGE_SIZE (1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS) -#define EEPROM_PAGE_OFFSET (x) ((x) & (EEPROM_PAGE_SIZE - 1)) - maxlen =EEPROM_PAGE_SIZE -EEPROM_PAGE_OFFSET (blk_off); -#else - maxlen =0x100 - blk_off; -#endif +if (maxlen >I2C_RXTX_LEN ) maxlen =I2C_RXTX_LEN ;
Signature · 1 line
2.1.4
PATCH 12/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_BITS
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 5 lines
Implement default value of 8 for this macro and pull out all of this macro out of the code. The default value of 8 actually does implement exactly the same behavior as the previous code which was in the #else clause of the ifdef.
Quoted 7 lines
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
bye,
Heiko
Quoted 37 lines
common/cmd_eeprom.c +8
-8@@ -33,6 +33,13 @@#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 0#endif +#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_BITS +#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 8 +#endif + +#define EEPROM_PAGE_SIZE (1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS) +#define EEPROM_PAGE_OFFSET (x) ((x) & (EEPROM_PAGE_SIZE - 1)) +/* * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is * 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM. @@ -194,15 +201,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn*/ #if !defined(CONFIG_SYS_I2C_FRAM ) -#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_BITS ) - -#define EEPROM_PAGE_SIZE (1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS) -#define EEPROM_PAGE_OFFSET (x) ((x) & (EEPROM_PAGE_SIZE - 1)) - maxlen =EEPROM_PAGE_SIZE -EEPROM_PAGE_OFFSET (blk_off); -#else - maxlen =0x100 - blk_off; -#endif +if (maxlen >I2C_RXTX_LEN ) maxlen =I2C_RXTX_LEN ;
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 12/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_BITS
In reply to Marek VasutQuoted 10 lines · Marek Vasut
Implement default value of 8 for this macro and pull out all of this macro out of the code. The default value of 8 actually does implement exactly the same behavior as the previous code which was in the #else clause of the ifdef.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/0f4139a3/attachment.sig>
PATCH 13/17 eeprom: Pull out transfer length computation
In reply to Marek VasutPull out the code which computes the length of the transfer into separate code and clean it up a little. This again trims down the code duplication.
--- common/cmd_eeprom.c | 66 ++++++++++++++++++++--------------------------------- 1 file changed, 25 insertions(+), 41 deletions(-)
common/cmd_eeprom.c +25 -41
@@ -95,6 +95,29 @@ static int eeprom_addr(unsigned dev_addr, unsigned offset, uchar *addr)return alen; } +static int eeprom_len (unsigned offset,unsigned end) +{ +unsigned len = end - offset; + +/* +* For a FRAM device there is no limit on the number of the +* bytes that can be ccessed with the single read or write +* operation. +*/ +#if !defined(CONFIG_SYS_I2C_FRAM ) +unsigned blk_off = offset &0xff ; +unsigned maxlen =EEPROM_PAGE_SIZE -EEPROM_PAGE_OFFSET (blk_off); + +if (maxlen >I2C_RXTX_LEN ) + maxlen =I2C_RXTX_LEN ; + +if (len > maxlen) + len = maxlen; +#endif + +return len; +} +static int eeprom_rw_block (unsigned offset,uchar *addr,unsigned alen,uchar *buffer,unsigned len,bool read) {
@@ -126,7 +149,6 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) {unsigned end = offset + cnt; -unsigned blk_off;int rcode =0 ;uchar addr[3 ];
@@ -137,27 +159,10 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt*/ while (offset < end) {unsigned alen, len; -#if !defined(CONFIG_SYS_I2C_FRAM ) -unsigned maxlen; -#endif - blk_off = offset &0xFF ;/* block offset */ alen =eeprom_addr (dev_addr, offset, addr); - len = end - offset; - -/* -* For a FRAM device there is no limit on the number of the -* bytes that can be ccessed with the single read or write -* operation. -*/ -#if !defined(CONFIG_SYS_I2C_FRAM ) - maxlen =0x100 - blk_off; -if (maxlen >I2C_RXTX_LEN ) - maxlen =I2C_RXTX_LEN ; -if (len > maxlen) - len = maxlen; -#endif + len =eeprom_len (offset, end); rcode =eeprom_rw_block (offset, addr, alen, buffer, len,1 );
@@ -171,7 +176,6 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cntint eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) {unsigned end = offset + cnt; -unsigned blk_off;int rcode =0 ;uchar addr[3 ];
@@ -185,30 +189,10 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnwhile (offset < end) {unsigned alen, len; -#if !defined(CONFIG_SYS_I2C_FRAM ) -unsigned maxlen; -#endif - blk_off = offset &0xFF ;/* block offset */ alen =eeprom_addr (dev_addr, offset, addr); - len = end - offset; - -/* -* For a FRAM device there is no limit on the number of the -* bytes that can be accessed with the single read or write -* operation. -*/ -#if !defined(CONFIG_SYS_I2C_FRAM ) - - maxlen =EEPROM_PAGE_SIZE -EEPROM_PAGE_OFFSET (blk_off); - -if (maxlen >I2C_RXTX_LEN ) - maxlen =I2C_RXTX_LEN ; - -if (len > maxlen) - len = maxlen; -#endif + len =eeprom_len (offset, end); rcode =eeprom_rw_block (offset, addr, alen, buffer, len,0 );
Signature · 1 line
2.1.4
PATCH 13/17 eeprom: Pull out transfer length computation
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 11 lines
Pull out the code which computes the length of the transfer into separate code and clean it up a little. This again trims down the code duplication.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 66 ++++++++++++++++++++--------------------------------- 1 file changed, 25 insertions(+), 41 deletions(-)
bye,
Heiko
Quoted 113 lines
common/cmd_eeprom.c +25
-41@@ -95,6 +95,29 @@ static int eeprom_addr(unsigned dev_addr, unsigned offset, uchar *addr)return alen; } +static int eeprom_len (unsigned offset,unsigned end) +{ +unsigned len = end - offset; + +/* +* For a FRAM device there is no limit on the number of the +* bytes that can be ccessed with the single read or write +* operation. +*/ +#if !defined(CONFIG_SYS_I2C_FRAM ) +unsigned blk_off = offset &0xff ; +unsigned maxlen =EEPROM_PAGE_SIZE -EEPROM_PAGE_OFFSET (blk_off); + +if (maxlen >I2C_RXTX_LEN ) + maxlen =I2C_RXTX_LEN ; + +if (len > maxlen) + len = maxlen; +#endif + +return len; +} +static int eeprom_rw_block (unsigned offset,uchar *addr,unsigned alen,uchar *buffer,unsigned len,bool read) {@@ -126,7 +149,6 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) {unsigned end = offset + cnt; -unsigned blk_off;int rcode =0 ;uchar addr[3 ];@@ -137,27 +159,10 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt*/ while (offset < end) {unsigned alen, len; -#if !defined(CONFIG_SYS_I2C_FRAM ) -unsigned maxlen; -#endif - blk_off = offset &0xFF ;/* block offset */ alen =eeprom_addr (dev_addr, offset, addr); - len = end - offset; - -/* -* For a FRAM device there is no limit on the number of the -* bytes that can be ccessed with the single read or write -* operation. -*/ -#if !defined(CONFIG_SYS_I2C_FRAM ) - maxlen =0x100 - blk_off; -if (maxlen >I2C_RXTX_LEN ) - maxlen =I2C_RXTX_LEN ; -if (len > maxlen) - len = maxlen; -#endif + len =eeprom_len (offset, end); rcode =eeprom_rw_block (offset, addr, alen, buffer, len,1 );@@ -171,7 +176,6 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cntint eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) {unsigned end = offset + cnt; -unsigned blk_off;int rcode =0 ;uchar addr[3 ];@@ -185,30 +189,10 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnwhile (offset < end) {unsigned alen, len; -#if !defined(CONFIG_SYS_I2C_FRAM ) -unsigned maxlen; -#endif - blk_off = offset &0xFF ;/* block offset */ alen =eeprom_addr (dev_addr, offset, addr); - len = end - offset; - -/* -* For a FRAM device there is no limit on the number of the -* bytes that can be accessed with the single read or write -* operation. -*/ -#if !defined(CONFIG_SYS_I2C_FRAM ) - - maxlen =EEPROM_PAGE_SIZE -EEPROM_PAGE_OFFSET (blk_off); - -if (maxlen >I2C_RXTX_LEN ) - maxlen =I2C_RXTX_LEN ; - -if (len > maxlen) - len = maxlen; -#endif + len =eeprom_len (offset, end); rcode =eeprom_rw_block (offset, addr, alen, buffer, len,0 );
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 13/17 eeprom: Pull out transfer length computation
In reply to Marek VasutQuoted 9 lines · Marek Vasut
Pull out the code which computes the length of the transfer into separate code and clean it up a little. This again trims down the code duplication.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/cde76822/attachment.sig>
PATCH 14/17 eeprom: Pull out the RW loop
In reply to Marek VasutUnify the code for doing read/write into single function, since the code for both the read and write is almost identical. This again trims down the code duplication.
--- common/cmd_eeprom.c | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-)
common/cmd_eeprom.c +21 -30
@@ -146,38 +146,44 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,return ret; } -int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) +static int eeprom_rw (unsigned dev_addr,unsigned offset,uchar *buffer, +unsigned cnt,bool read) {unsigned end = offset + cnt; +unsigned alen, len;int rcode =0 ;uchar addr[3 ]; -/* -* Read data until done or would cross a page boundary. -* We must write the address again when changing pages -* because the next page may be in a different device. -*/ while (offset < end) { -unsigned alen, len; - alen =eeprom_addr (dev_addr, offset, addr); len =eeprom_len (offset, end); - rcode =eeprom_rw_block (offset, addr, alen, buffer, len,1 ); + rcode =eeprom_rw_block (offset, addr, alen, buffer, len, read); buffer += len; offset += len; + +if (!read) +udelay (CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS *1000 ); }return rcode; } -int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) +int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) { -unsigned end = offset + cnt; -int rcode =0 ; -uchar addr[3 ]; +/* +* Read data until done or would cross a page boundary. +* We must write the address again when changing pages +* because the next page may be in a different device. +*/ +return eeprom_rw (dev_addr, offset, buffer, cnt,1 ); +} + +int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) +{ +int ret;eeprom_write_enable (dev_addr,1 );
@@ -186,25 +192,10 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn* We must write the address again when changing pages * because the address counter only increments within a page. */ - -while (offset < end) { -unsigned alen, len; - - alen =eeprom_addr (dev_addr, offset, addr); - - len =eeprom_len (offset, end); - - rcode =eeprom_rw_block (offset, addr, alen, buffer, len,0 ); - - buffer += len; - offset += len; - -udelay (CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS *1000 ); - } + ret =eeprom_rw (dev_addr, offset, buffer, cnt,1 );eeprom_write_enable (dev_addr,0 ); - -return rcode; +return ret; }static int do_eeprom (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[])
Signature · 1 line
2.1.4
PATCH 14/17 eeprom: Pull out the RW loop
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 11 lines
Unify the code for doing read/write into single function, since the code for both the read and write is almost identical. This again trims down the code duplication.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-)
bye,
Heiko
Quoted 92 lines
common/cmd_eeprom.c +21
-30@@ -146,38 +146,44 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,return ret; } -int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) +static int eeprom_rw (unsigned dev_addr,unsigned offset,uchar *buffer, +unsigned cnt,bool read) {unsigned end = offset + cnt; +unsigned alen, len;int rcode =0 ;uchar addr[3 ]; -/* -* Read data until done or would cross a page boundary. -* We must write the address again when changing pages -* because the next page may be in a different device. -*/ while (offset < end) { -unsigned alen, len; - alen =eeprom_addr (dev_addr, offset, addr); len =eeprom_len (offset, end); - rcode =eeprom_rw_block (offset, addr, alen, buffer, len,1 ); + rcode =eeprom_rw_block (offset, addr, alen, buffer, len, read); buffer += len; offset += len; + +if (!read) +udelay (CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS *1000 ); }return rcode; } -int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) +int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) { -unsigned end = offset + cnt; -int rcode =0 ; -uchar addr[3 ]; +/* +* Read data until done or would cross a page boundary. +* We must write the address again when changing pages +* because the next page may be in a different device. +*/ +return eeprom_rw (dev_addr, offset, buffer, cnt,1 ); +} + +int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) +{ +int ret;eeprom_write_enable (dev_addr,1 );@@ -186,25 +192,10 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn* We must write the address again when changing pages * because the address counter only increments within a page. */ - -while (offset < end) { -unsigned alen, len; - - alen =eeprom_addr (dev_addr, offset, addr); - - len =eeprom_len (offset, end); - - rcode =eeprom_rw_block (offset, addr, alen, buffer, len,0 ); - - buffer += len; - offset += len; - -udelay (CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS *1000 ); - } + ret =eeprom_rw (dev_addr, offset, buffer, cnt,1 );eeprom_write_enable (dev_addr,0 ); - -return rcode; +return ret; }static int do_eeprom (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[])
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 14/17 eeprom: Pull out the RW loop
In reply to Marek VasutQuoted 9 lines · Marek Vasut
Unify the code for doing read/write into single function, since the code for both the read and write is almost identical. This again trims down the code duplication.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/0797280d/attachment.sig>
PATCH 15/17 eeprom: Add bus argument to eeprom_init()
In reply to Marek VasutAdd bus argument to eeprom_init(), so that it can select the I2C bus number on which the eeprom resides. Any negative value of the $bus argument will preserve the old behavior. This is in place so that old code does not randomly break.
--- common/cmd_eeprom.c | 6 ++++-- common/env_eeprom.c | 4 ++-- include/common.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-)
common/cmd_eeprom.c +4 -2
@@ -60,7 +60,7 @@ __weak int eeprom_write_enable(unsigned dev_addr, int state)return 0 ; } -void eeprom_init (void ) +void eeprom_init (int bus) {/* SPI EEPROM */ #if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C )
@@ -69,6 +69,8 @@ void eeprom_init(void)/* I2C EEPROM */ #if defined(CONFIG_HARD_I2C ) || defined(CONFIG_SYS_I2C_SOFT ) +if (bus >=0 ) +i2c_set_bus_num (bus);i2c_init (CONFIG_SYS_I2C_SPEED ,CONFIG_SYS_I2C_SLAVE );#endif }
@@ -223,7 +225,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) off =simple_strtoul (*args++,NULL ,16 ); cnt =simple_strtoul (*args++,NULL ,16 ); -eeprom_init (); +eeprom_init (-1 );if (strcmp (argv[1 ],"read" ) ==0 ) {printf (fmt, dev_addr, argv[1 ], addr, off, cnt);
common/env_eeprom.c +2 -2
@@ -91,7 +91,7 @@ void env_relocate_spec(void)uchar rdbuf[64 ], flags[2 ];int i, crc_ok[2 ] = {0 ,0 }; -eeprom_init ();/* prepare for EEPROM read/write */ +eeprom_init (-1 );/* prepare for EEPROM read/write */ off_env[0 ] =CONFIG_ENV_OFFSET ; off_env[1 ] =CONFIG_ENV_OFFSET_REDUND ;
@@ -154,7 +154,7 @@ void env_relocate_spec(void)ulong crc, len, new;uchar rdbuf[64 ]; -eeprom_init ();/* prepare for EEPROM read/write */ +eeprom_init (-1 );/* prepare for EEPROM read/write */ /* read old CRC */ eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,
include/common.h +1 -1
@@ -475,7 +475,7 @@ void reset_phy (void);void fdc_hw_init (void );/* $(BOARD)/eeprom.c */ -void eeprom_init (void ); +void eeprom_init (int bus);int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt);int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt);
Signature · 1 line
2.1.4
PATCH 15/17 eeprom: Add bus argument to eeprom_init()
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 9 lines
Add bus argument to
eeprom_init(), so that it can select the I2C bus number on which the eeprom resides. Any negative value of the $bus argument will preserve the old behavior. This is in place so that old code does not randomly break.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>
Quoted 5 lines
--- common/cmd_eeprom.c | 6 ++++-- common/env_eeprom.c | 4 ++-- include/common.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-)
bye,
Heiko
Quoted 68 lines
common/cmd_eeprom.c +4
-2@@ -60,7 +60,7 @@ __weak int eeprom_write_enable(unsigned dev_addr, int state)return 0 ; } -void eeprom_init (void ) +void eeprom_init (int bus) {/* SPI EEPROM */ #if defined(CONFIG_SPI ) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C )@@ -69,6 +69,8 @@ void eeprom_init(void)/* I2C EEPROM */ #if defined(CONFIG_HARD_I2C ) || defined(CONFIG_SYS_I2C_SOFT ) +if (bus >=0 ) +i2c_set_bus_num (bus);i2c_init (CONFIG_SYS_I2C_SPEED ,CONFIG_SYS_I2C_SLAVE );#endif }@@ -223,7 +225,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) off =simple_strtoul (*args++,NULL ,16 ); cnt =simple_strtoul (*args++,NULL ,16 ); -eeprom_init (); +eeprom_init (-1 );if (strcmp (argv[1 ],"read" ) ==0 ) {printf (fmt, dev_addr, argv[1 ], addr, off, cnt);common/env_eeprom.c +2
-2@@ -91,7 +91,7 @@ void env_relocate_spec(void)uchar rdbuf[64 ], flags[2 ];int i, crc_ok[2 ] = {0 ,0 }; -eeprom_init ();/* prepare for EEPROM read/write */ +eeprom_init (-1 );/* prepare for EEPROM read/write */ off_env[0 ] =CONFIG_ENV_OFFSET ; off_env[1 ] =CONFIG_ENV_OFFSET_REDUND ;@@ -154,7 +154,7 @@ void env_relocate_spec(void)ulong crc, len, new;uchar rdbuf[64 ]; -eeprom_init ();/* prepare for EEPROM read/write */ +eeprom_init (-1 );/* prepare for EEPROM read/write */ /* read old CRC */ eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,include/common.h +1
-1@@ -475,7 +475,7 @@ void reset_phy (void);void fdc_hw_init (void );/* $(BOARD)/eeprom.c */ -void eeprom_init (void ); +void eeprom_init (int bus);int eeprom_read (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt);int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt);
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 15/17 eeprom: Add bus argument to eeprom_init()
Quoted 7 lines · Heiko Schocher
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 4 lines
Add bus argument to
eeprom_init(), so that it can select the I2C bus number on which the eeprom resides. Any negative value of the $bus argument will preserve the old behavior. This is in place so that old code does not randomly break.
[snip]
Quoted 9 lines
common/cmd_eeprom.c void eeprom_init(void) · line 76
Quoted 9 lines
common/cmd_eeprom.c +2
-0@@ -69,6 +69,8 @@ void eeprom_init(void)/* I2C EEPROM */ #if defined(CONFIG_HARD_I2C ) || defined(CONFIG_SYS_I2C_SOFT ) +if (bus >=0 ) +i2c_set_bus_num (bus);i2c_init (CONFIG_SYS_I2C_SPEED ,CONFIG_SYS_I2C_SLAVE );#endif }
Note that we need to wrap this call in CONFIG_SYS_I2C as CONFIG_HARD_I2C doesn't provide this function. Fixing up and testing again locally.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151121/bbb130ac/attachment.sig>
PATCH 15/17 eeprom: Add bus argument to eeprom_init()
In reply to Marek VasutQuoted 10 lines · Marek Vasut
Add bus argument to
eeprom_init(), so that it can select the I2C bus number on which the eeprom resides. Any negative value of the $bus argument will preserve the old behavior. This is in place so that old code does not randomly break.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/d66c9b4a/attachment.sig>
PATCH 16/17 eeprom: Add support for selecting i2c bus
In reply to Marek VasutAdd additional parameter into the eeprom command to select the I2C bus on which the eeprom resides.
--- common/cmd_eeprom.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
common/cmd_eeprom.c +11 -4
@@ -207,14 +207,21 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])char *const *args = &argv[2 ];int rcode;ulong dev_addr, addr, off, cnt; +int bus_addr;switch (argc) {#ifdef CONFIG_SYS_DEF_EEPROM_ADDR case 5 : + bus_addr =-1 ; dev_addr =CONFIG_SYS_DEF_EEPROM_ADDR ;break ;#endif case 6 : + bus_addr =-1 ; + dev_addr =simple_strtoul (*args++,NULL ,16 ); +break ; +case 7 : + bus_addr =simple_strtoul (*args++,NULL ,16 ); dev_addr =simple_strtoul (*args++,NULL ,16 );break ;default :
@@ -225,7 +232,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) off =simple_strtoul (*args++,NULL ,16 ); cnt =simple_strtoul (*args++,NULL ,16 ); -eeprom_init (-1 ); +eeprom_init (bus_addr);if (strcmp (argv[1 ],"read" ) ==0 ) {printf (fmt, dev_addr, argv[1 ], addr, off, cnt);
@@ -247,9 +254,9 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }U_BOOT_CMD ( - eeprom,6 ,1 , do_eeprom, + eeprom,7 ,1 , do_eeprom,"EEPROM sub-system" , -"read devaddr addr off cnt\n" -"eeprom write devaddr addr off cnt\n" +"read <bus> <devaddr> addr off cnt\n" +"eeprom write <bus> <devaddr> addr off cnt\n" " - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'" )
Signature · 1 line
2.1.4
PATCH 16/17 eeprom: Add support for selecting i2c bus
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 10 lines
Add additional parameter into the eeprom command to select the I2C bus on which the eeprom resides.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
bye,
Heiko
Quoted 50 lines
common/cmd_eeprom.c +11
-4@@ -207,14 +207,21 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])char *const *args = &argv[2 ];int rcode;ulong dev_addr, addr, off, cnt; +int bus_addr;switch (argc) {#ifdef CONFIG_SYS_DEF_EEPROM_ADDR case 5 : + bus_addr =-1 ; dev_addr =CONFIG_SYS_DEF_EEPROM_ADDR ;break ;#endif case 6 : + bus_addr =-1 ; + dev_addr =simple_strtoul (*args++,NULL ,16 ); +break ; +case 7 : + bus_addr =simple_strtoul (*args++,NULL ,16 ); dev_addr =simple_strtoul (*args++,NULL ,16 );break ;default :@@ -225,7 +232,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) off =simple_strtoul (*args++,NULL ,16 ); cnt =simple_strtoul (*args++,NULL ,16 ); -eeprom_init (-1 ); +eeprom_init (bus_addr);if (strcmp (argv[1 ],"read" ) ==0 ) {printf (fmt, dev_addr, argv[1 ], addr, off, cnt);@@ -247,9 +254,9 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }U_BOOT_CMD ( - eeprom,6 ,1 , do_eeprom, + eeprom,7 ,1 , do_eeprom,"EEPROM sub-system" , -"read devaddr addr off cnt\n" -"eeprom write devaddr addr off cnt\n" +"read <bus> <devaddr> addr off cnt\n" +"eeprom write <bus> <devaddr> addr off cnt\n" " - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'" )
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 16/17 eeprom: Add support for selecting i2c bus
In reply to Marek VasutQuoted 8 lines · Marek Vasut
Add additional parameter into the eeprom command to select the I2C bus on which the eeprom resides.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/bff55239/attachment.sig>
PATCH 17/17 eeprom: Clean up checkpatch issues
In reply to Marek VasutCosmetic fixes to the file, make it checkpatch clean.
--- common/cmd_eeprom.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
common/cmd_eeprom.c +10 -9
@@ -49,8 +49,8 @@*/ #if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C )#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN ) || \ - (CONFIG_SYS_I2C_EEPROM_ADDR_LEN <1 ) || \ - (CONFIG_SYS_I2C_EEPROM_ADDR_LEN >2 ) + (CONFIG_SYS_I2C_EEPROM_ADDR_LEN <1 ) || \ + (CONFIG_SYS_I2C_EEPROM_ADDR_LEN >2 )#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2#endif #endif
@@ -183,7 +183,8 @@ int eeprom_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)return eeprom_rw (dev_addr, offset, buffer, cnt,1 ); } -int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) +int eeprom_write (unsigned dev_addr,unsigned offset, +uchar *buffer,unsigned cnt) {int ret;
@@ -234,19 +235,19 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])eeprom_init (bus_addr); -if (strcmp (argv[1 ],"read" ) ==0 ) { +if (strcmp (argv[1 ],"read" ) ==0 ) {printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - rcode =eeprom_read (dev_addr, off, (uchar *) addr, cnt); + rcode =eeprom_read (dev_addr, off, (uchar *)addr, cnt); -puts ("done\n" ); +puts ("done\n" );return rcode; - }else if (strcmp (argv[1 ],"write" ) ==0 ) { + }else if (strcmp (argv[1 ],"write" ) ==0 ) {printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - rcode =eeprom_write (dev_addr, off, (uchar *) addr, cnt); + rcode =eeprom_write (dev_addr, off, (uchar *)addr, cnt); -puts ("done\n" ); +puts ("done\n" );return rcode; }
Signature · 1 line
2.1.4
PATCH 17/17 eeprom: Clean up checkpatch issues
Hello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 9 lines
Cosmetic fixes to the file, make it checkpatch clean.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- common/cmd_eeprom.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
bye,
Heiko
Quoted 53 lines
common/cmd_eeprom.c +10
-9@@ -49,8 +49,8 @@*/ #if !defined(CONFIG_SPI ) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C )#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN ) || \ - (CONFIG_SYS_I2C_EEPROM_ADDR_LEN <1 ) || \ - (CONFIG_SYS_I2C_EEPROM_ADDR_LEN >2 ) + (CONFIG_SYS_I2C_EEPROM_ADDR_LEN <1 ) || \ + (CONFIG_SYS_I2C_EEPROM_ADDR_LEN >2 )#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2#endif #endif @@ -183,7 +183,8 @@ int eeprom_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)return eeprom_rw (dev_addr, offset, buffer, cnt,1 ); } -int eeprom_write (unsigned dev_addr,unsigned offset,uchar *buffer,unsigned cnt) +int eeprom_write (unsigned dev_addr,unsigned offset, +uchar *buffer,unsigned cnt) {int ret;@@ -234,19 +235,19 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])eeprom_init (bus_addr); -if (strcmp (argv[1 ],"read" ) ==0 ) { +if (strcmp (argv[1 ],"read" ) ==0 ) {printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - rcode =eeprom_read (dev_addr, off, (uchar *) addr, cnt); + rcode =eeprom_read (dev_addr, off, (uchar *)addr, cnt); -puts ("done\n" ); +puts ("done\n" );return rcode; - }else if (strcmp (argv[1 ],"write" ) ==0 ) { + }else if (strcmp (argv[1 ],"write" ) ==0 ) {printf (fmt, dev_addr, argv[1 ], addr, off, cnt); - rcode =eeprom_write (dev_addr, off, (uchar *) addr, cnt); + rcode =eeprom_write (dev_addr, off, (uchar *)addr, cnt); -puts ("done\n" ); +puts ("done\n" );return rcode; }
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 17/17 eeprom: Clean up checkpatch issues
In reply to Marek VasutQuoted 7 lines · Marek Vasut
Cosmetic fixes to the file, make it checkpatch clean.
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/2d99adb8/attachment.sig>
PATCH 1/17 tricorder: rewrite tricordereeprom command
In reply to Marek VasutHello Marek,
Am 10.11.2015 um 20:53 schrieb Marek Vasut:
Quoted 5 lines
From: Andreas Bie?mann <[email protected]>
This rewrite uses lately promoted
eeprom_init(int)function to choose the right I2C bus when writing data to the EEPROM.
Quoted 8 lines
Signed-off-by Andreas Bie?mann <[email protected]>Cc Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>--- board/corscience/tricorder/tricorder-eeprom.c | 36 +++++++-------------------- 1 file changed, 9 insertions(+), 27 deletions(-)
Thanks for this cleanup! ... eeprom code is really ugly ...
bye,
Heiko
Quoted 93 lines
board/corscience/tricorder/tricorder-eeprom.c +9
-27@@ -77,17 +77,13 @@ static int handle_eeprom_v1(struct tricorder_eeprom *eeprom)int tricorder_get_eeprom (int addr,struct tricorder_eeprom *eeprom) { -#ifdef CONFIG_SYS_EEPROM_BUS_NUM unsigned int bus =i2c_get_bus_num ();i2c_set_bus_num (CONFIG_SYS_EEPROM_BUS_NUM ); -#endif memset (eeprom,0 ,TRICORDER_EEPROM_SIZE );i2c_read (addr,0 ,2 , (unsigned char *)eeprom,TRICORDER_EEPROM_SIZE ); -#ifdef CONFIG_SYS_EEPROM_BUS_NUM i2c_set_bus_num (bus); -#endif if (be32_to_cpu (eeprom->magic) !=TRICORDER_EEPROM_MAGIC ) { warn_wrong_value("magic", TRICORDER_EEPROM_MAGIC,@@ -138,9 +134,6 @@ int tricorder_eeprom_write(unsigned devaddr, const char *name,int ret;unsigned char *p;int i; -#ifdef CONFIG_SYS_EEPROM_BUS_NUM -unsigned int bus; -#endif memset (eeprom,0 ,TRICORDER_EEPROM_SIZE );memset (eeprom_verify,0 ,TRICORDER_EEPROM_SIZE );@@ -172,33 +165,23 @@ int tricorder_eeprom_write(unsigned devaddr, const char *name,print_buffer (0 , &eeprom,1 ,sizeof (eeprom),16 );#endif -#ifdef CONFIG_SYS_EEPROM_BUS_NUM - bus =i2c_get_bus_num (); -i2c_set_bus_num (CONFIG_SYS_EEPROM_BUS_NUM ); -#endif +eeprom_init (CONFIG_SYS_EEPROM_BUS_NUM ); -/* do page write to the eeprom */ -for (i =0 , p = (unsigned char *)&eeprom; - i <sizeof (eeprom); - i +=32 , p +=32 ) { - ret =i2c_write (devaddr, i,CONFIG_SYS_I2C_EEPROM_ADDR_LEN , - p,min (sizeof (eeprom) - i,32 )); -if (ret) -break ; -udelay (5000 );/* 5ms write cycle timing */ - } + ret =eeprom_write (devaddr,0 , (unsigned char *)&eeprom, +TRICORDER_EEPROM_SIZE ); +if (ret) +printf ("Tricorder: Could not write EEPROM content!\n" ); - ret =i2c_read (devaddr,0 ,2 , (unsigned char *)&eeprom_verify, + ret =eeprom_read (devaddr,0 , (unsigned char *)&eeprom_verify,TRICORDER_EEPROM_SIZE ); +if (ret) +printf ("Tricorder: Could not read EEPROM content!\n" );if (memcmp (&eeprom, &eeprom_verify,sizeof (eeprom)) !=0 ) {printf ("Tricorder: Could not verify EEPROM content!\n" ); ret =1 ; } -#ifdef CONFIG_SYS_EEPROM_BUS_NUM -i2c_set_bus_num (bus); -#endif return ret; }@@ -206,7 +189,7 @@ int do_tricorder_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {if (argc ==3 ) {ulong dev_addr =simple_strtoul (argv[2 ],NULL ,16 ); -eeprom_init (); +if (strcmp (argv[1 ],"read" ) ==0 ) {int rcode;@@ -220,7 +203,6 @@ int do_tricorder_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])char *version = argv[4 ];char *serial = argv[5 ];char *interface =NULL ; -eeprom_init ();if (argc ==7 ) interface = argv[6 ];
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 1/17 tricorder: rewrite tricordereeprom command
In reply to Marek VasutQuoted 11 lines · Marek Vasut
From: Andreas Bie?mann <[email protected]>
This rewrite uses lately promoted
eeprom_init(int)function to choose the right I2C bus when writing data to the EEPROM.Signed-off-by Andreas Bie?mann <[email protected]>Cc Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Heiko Schocher <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/b48fe37a/attachment.sig>