]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/omap24xx_i2c.c
Merge git://www.denx.de/git/u-boot
[karo-tx-uboot.git] / drivers / omap24xx_i2c.c
index b64e713ef1f6b3335860379d9470f879b1f624b6..7dab78685dfb44102295a2cf138d49f48118b9ac 100644 (file)
  */
 
 #include <common.h>
+
+#ifdef CONFIG_DRIVER_OMAP24XX_I2C
+
 #include <asm/arch/i2c.h>
 #include <asm/io.h>
 
 #define inw(a) __raw_readw(a)
 #define outw(a,v) __raw_writew(a,v)
 
-#ifdef CONFIG_DRIVER_OMAP24XX_I2C
-
 static void wait_for_bb (void);
 static u16 wait_for_pin (void);
-void flush_fifo(void);
+static void flush_fifo(void);
 
 void i2c_init (int speed, int slaveadd)
 {
        u16 scl;
 
+       outw(0x2, I2C_SYSC); /* for ES2 after soft reset */
+       udelay(1000);
+       outw(0x0, I2C_SYSC); /* will probably self clear but */
+
        if (inw (I2C_CON) & I2C_CON_EN) {
                outw (0, I2C_CON);
                udelay (50000);
@@ -51,11 +56,14 @@ void i2c_init (int speed, int slaveadd)
        /* own address */
        outw (slaveadd, I2C_OA);
        outw (I2C_CON_EN, I2C_CON);
-       outw (0, I2C_CNT);
+
        /* have to enable intrrupts or OMAP i2c module doesn't work */
        outw (I2C_IE_XRDY_IE | I2C_IE_RRDY_IE | I2C_IE_ARDY_IE |
              I2C_IE_NACK_IE | I2C_IE_AL_IE, I2C_IE);
        udelay (1000);
+       flush_fifo();
+       outw (0xFFFF, I2C_STAT);
+       outw (0, I2C_CNT);
 }
 
 static int i2c_read_byte (u8 devaddr, u8 regoffset, u8 * value)
@@ -159,11 +167,15 @@ static int i2c_write_byte (u8 devaddr, u8 regoffset, u8 value)
        }
 
        if (!i2c_error) {
+               int eout = 200;
+
                outw (I2C_CON_EN, I2C_CON);
                while ((stat = inw (I2C_STAT)) || (inw (I2C_CON) & I2C_CON_MST)) {
                        udelay (1000);
                        /* have to read to clear intrrupt */
                        outw (0xFFFF, I2C_STAT);
+                       if(--eout == 0) /* better leave with error than hang */
+                               break;
                }
        }
        flush_fifo();
@@ -172,7 +184,7 @@ static int i2c_write_byte (u8 devaddr, u8 regoffset, u8 value)
        return i2c_error;
 }
 
-void flush_fifo(void)
+static void flush_fifo(void)
 {      u16 stat;
 
        /* note: if you try and read data when its not there or ready