X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fsoft_i2c.c;h=edad51bc4180517a2093622296ce18bf0b27f2b4;hb=701f649aa304e547639fb8bbfdfec0753e9b3b9a;hp=77774801e87018f1e4ae962efc9b004583f3e56f;hpb=c609719b8d1b2dca590e0ed499016d041203e403;p=u-boot diff --git a/common/soft_i2c.c b/common/soft_i2c.c index 77774801e8..edad51bc41 100644 --- a/common/soft_i2c.c +++ b/common/soft_i2c.c @@ -29,12 +29,23 @@ #ifdef CONFIG_MPC8260 /* only valid for MPC8260 */ #include #endif +#ifdef CONFIG_AT91RM9200DK /* need this for the at91rm9200dk */ +#include +#include +#endif +#ifdef CONFIG_IXP425 /* only valid for IXP425 */ +#include +#endif #include #if defined(CONFIG_SOFT_I2C) /* #define DEBUG_I2C */ +#ifdef DEBUG_I2C +DECLARE_GLOBAL_DATA_PTR; +#endif + /*----------------------------------------------------------------------- * Definitions @@ -49,7 +60,6 @@ #ifdef DEBUG_I2C #define PRINTD(fmt,args...) do { \ - DECLARE_GLOBAL_DATA_PTR; \ if (gd->have_console) \ printf (fmt ,##args); \ } while (0) @@ -83,8 +93,12 @@ static void send_reset(void) #endif int j; - I2C_ACTIVE; + I2C_SCL(1); I2C_SDA(1); +#ifdef I2C_INIT + I2C_INIT; +#endif + I2C_TRISTATE; for(j = 0; j < 9; j++) { I2C_SCL(0); I2C_DELAY; @@ -156,13 +170,10 @@ static void send_ack(int ack) volatile immap_t *immr = (immap_t *)CFG_IMMR; #endif - I2C_ACTIVE; I2C_SCL(0); I2C_DELAY; - - I2C_SDA(ack); - I2C_ACTIVE; + I2C_SDA(ack); I2C_DELAY; I2C_SCL(1); I2C_DELAY; @@ -262,18 +273,11 @@ static uchar read_byte(int ack) */ void i2c_init (int speed, int slaveaddr) { -#ifdef CONFIG_8xx - volatile immap_t *immr = (immap_t *)CFG_IMMR; -#endif - -#ifdef I2C_INIT - I2C_INIT; -#endif /* - * WARNING: Do NOT save speed in a static variable: if the - * I2C routines are called before RAM is initialized (to read - * the DIMM SPD, for instance), RAM won't be usable and your - * system will crash. + * WARNING: Do NOT save speed in a static variable: if the + * I2C routines are called before RAM is initialized (to read + * the DIMM SPD, for instance), RAM won't be usable and your + * system will crash. */ send_reset (); } @@ -287,8 +291,12 @@ int i2c_probe(uchar addr) { int rc; + /* + * perform 1 byte write transaction with just address byte + * (fake write) + */ send_start(); - rc = write_byte ((addr << 1) | 1); + rc = write_byte ((addr << 1) | 0); send_stop(); return (rc ? 1 : 0); @@ -397,7 +405,7 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) */ uchar i2c_reg_read(uchar i2c_addr, uchar reg) { - char buf; + uchar buf; i2c_read(i2c_addr, reg, 1, &buf, 1);