diff --git a/drivers/i2c/sh_riic.c b/drivers/i2c/sh_riic.c index 498a4f0..cee9d87 100644 --- a/drivers/i2c/sh_riic.c +++ b/drivers/i2c/sh_riic.c @@ -145,7 +145,8 @@ #define ICBRL_RESERVED 0xe0 /* The write value shoud always be 1 */ #define ICBRL_BRL_MASK 0x1f -#define RIIC_TIMEOUT 10000 /* 100msec (unit = 10usec) */ +#define RIIC_ICCR2_TIMEOUT 1 /* 1 ms (bus-free-time: 4.7 us(Sm) */ +#define RIIC_ICSR2_TIMEOUT 100 /* 100 ms */ struct riic_data { unsigned int reg; @@ -257,11 +258,16 @@ static int riic_set_clock(struct riic_data *pd, int clock) static int riic_check_busy(void) { - if (riic_read(pd, RIIC_ICCR2) & ICCR2_BBSY) { - printf("i2c bus is busy.\n"); - return -EBUSY; - } - return 0; + ulong start, timeout = (ulong)RIIC_ICCR2_TIMEOUT; + + start = get_timer(0); + do { + if (!(riic_read(pd, RIIC_ICCR2) & ICCR2_BBSY)) + return 0; + } while (get_timer(start) < timeout); + + debug("%s: i2c bus is busy.\n", __func__); + return -EBUSY; } static int riic_init_setting(struct riic_data *pd, int clock) @@ -288,20 +294,19 @@ static int riic_init_setting(struct riic_data *pd, int clock) static int riic_wait_for_icsr2(struct riic_data *pd, unsigned short bit) { unsigned char icsr2; - int timeout = RIIC_TIMEOUT; + ulong start, timeout = (ulong)RIIC_ICSR2_TIMEOUT; - while (timeout-- > 0) { + start = get_timer(0); + do { icsr2 = riic_read(pd, RIIC_ICSR2); if (icsr2 & ICSR2_NACKF) return -EIO; if (icsr2 & bit) return 0; - udelay(10); - } - - printf("%s: Timeout!(bit = %x icsr2 = %x, iccr2 = %x)\n", __func__, - bit, riic_read(pd, RIIC_ICSR2), riic_read(pd, RIIC_ICCR2)); + } while (get_timer(start) < timeout); + debug("%s: ICSR2 timeout! (bit = %x ICSR2 = %x)\n", __func__, + bit, riic_read(pd, RIIC_ICSR2)); return -ETIMEDOUT; } @@ -351,7 +356,7 @@ static int riic_i2c_raw_read(u8 *buf, int len) int ret = 0; int index = 0; - while (len > index) { + do { ret = riic_wait_for_icsr2(pd, ICSR2_RDRF); if (ret < 0) return ret; @@ -362,7 +367,7 @@ static int riic_i2c_raw_read(u8 *buf, int len) else index++; riic_set_receive_ack(pd, 1); - } + } while (index < (len - 1)); ret = riic_wait_for_icsr2(pd, ICSR2_RDRF); if (ret < 0) diff --git a/include/configs/rskrza1.h b/include/configs/rskrza1.h index 2a11425..d69504f 100755 --- a/include/configs/rskrza1.h +++ b/include/configs/rskrza1.h @@ -128,10 +128,10 @@ #define CONFIG_SYS_MAX_I2C_BUS 4 #define CONFIG_SYS_I2C_SPEED 100000 /* 100 kHz */ #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50 -#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1 -#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 4 /* 16-Byte Write Mode */ +#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2 +#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 6 /* 64-Byte Write Mode */ #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 10 /* 10ms of delay */ -#define CONFIG_SYS_I2C_MODULE 3 +#define CONFIG_SYS_I2C_MODULE 2 #define CONFIG_SH_I2C_BASE0 0xFCFEE000 #define CONFIG_SH_I2C_BASE1 0xFCFEE400 #define CONFIG_SH_I2C_BASE2 0xFCFEE800