]> git.sur5r.net Git - u-boot/blobdiff - cpu/mpc8260/i2c.c
Merge branch 'master' of git://www.denx.de/git/u-boot-cfi-flash
[u-boot] / cpu / mpc8260 / i2c.c
index 69ae535ba29733f1a70a42507ca737753ea4ee40..c3af7b6d839ee6f9f21f137beff5c9775d222e95 100644 (file)
@@ -34,6 +34,8 @@
 /* define to enable debug messages */
 #undef  DEBUG_I2C
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /* uSec to wait between polls of the i2c */
 #define DELAY_US       100
 /* uSec to wait for the CPM to start processing the buffer */
@@ -149,7 +151,7 @@ i2c_roundrate(int hz, int speed, int filter, int modval,
 
     PRINTD(("\t\tmoddiv=%d, brgdiv=%d\n", moddiv, brgdiv));
 
-    *brgval = (brgdiv / 2) - 3 - (2*filter);
+    *brgval = ((brgdiv + 1) / 2) - 3 - (2*filter);
 
     if ((*brgval < 0) || (*brgval > 255)) {
          PRINTD(("\t\trejected brgval=%d\n", *brgval));
@@ -158,7 +160,7 @@ i2c_roundrate(int hz, int speed, int filter, int modval,
 
     brgdiv = 2 * (*brgval + 3 + (2 * filter));
     div = moddiv * brgdiv ;
-    *totspeed = (hz + div - 1) / div;
+    *totspeed = hz / div;
 
     PRINTD(("\t\taccepted brgval=%d, totspeed=%d\n", *brgval, *totspeed));
 
@@ -189,10 +191,10 @@ static int i2c_setrate(int hz, int speed)
 
                        if ((diff >= 0) && (diff < bestspeed_diff))
                        {
-                               bestspeed_diff  = diff ;
-                               bestspeed_modval        = modval;
-                               bestspeed_brgval        = brgval;
-                               bestspeed_filter        = filter;
+                               bestspeed_diff  = diff ;
+                               bestspeed_modval        = modval;
+                               bestspeed_brgval        = brgval;
+                               bestspeed_filter        = filter;
                        }
                }
        }
@@ -213,8 +215,6 @@ static int i2c_setrate(int hz, int speed)
 
 void i2c_init(int speed, int slaveadd)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        volatile immap_t *immap = (immap_t *)CFG_IMMR ;
        volatile cpm8260_t *cp = (cpm8260_t *)&immap->im_cpm;
        volatile i2c8260_t *i2c = (i2c8260_t *)&immap->im_i2c;
@@ -223,7 +223,7 @@ void i2c_init(int speed, int slaveadd)
        volatile I2C_BD *rxbd, *txbd;
        uint dpaddr;
 
-#ifdef CFG_I2C_INIT_BOARD        
+#ifdef CFG_I2C_INIT_BOARD
        /* call board specific i2c bus reset routine before accessing the   */
        /* environment, which might be in a chip on that bus. For details   */
        /* about this problem see doc/I2C_Edge_Conditions.                  */
@@ -242,7 +242,7 @@ void i2c_init(int speed, int slaveadd)
        /*
         * initialise data in dual port ram:
         *
-        *        dpaddr -> parameter ram (64 bytes)
+        *        dpaddr -> parameter ram (64 bytes)
         *         rbase -> rx BD         (NUM_RX_BDS * sizeof(I2C_BD) bytes)
         *         tbase -> tx BD         (NUM_TX_BDS * sizeof(I2C_BD) bytes)
         *                  tx buffer     (MAX_TX_SPACE bytes)
@@ -494,7 +494,7 @@ int i2c_doio(i2c_state_t *state)
        volatile iic_t *iip;
        volatile i2c8260_t *i2c = (i2c8260_t *)&immap->im_i2c;
        volatile I2C_BD *txbd, *rxbd;
-        int  n, i, b, rxcnt = 0, rxtimeo = 0, txcnt = 0, txtimeo = 0, rc = 0;
+       int  n, i, b, rxcnt = 0, rxtimeo = 0, txcnt = 0, txtimeo = 0, rc = 0;
        uint dpaddr;
 
        PRINTD(("[I2C] i2c_doio\n"));
@@ -543,7 +543,7 @@ int i2c_doio(i2c_state_t *state)
 
                rxbd = ((I2C_BD*)state->rxbd) - n;
                for (i = 0; i < n; i++) {
-                       rxtimeo += TOUT_LOOP * rxbd->length;
+                       rxtimeo += TOUT_LOOP * rxbd->length;
                        rxbd++;
                }
 
@@ -670,7 +670,7 @@ i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
          * and the extra bits end up in the "chip address" bit slots.
          * This makes a 24WC08 (1Kbyte) chip look like four 256 byte
          * chips.
-         *
+         *
          * Note that we consider the length of the address field to still
          * be one byte because the extra address bits are hidden in the
          * chip address.
@@ -719,7 +719,7 @@ i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
          * and the extra bits end up in the "chip address" bit slots.
          * This makes a 24WC08 (1Kbyte) chip look like four 256 byte
          * chips.
-         *
+         *
          * Note that we consider the length of the address field to still
          * be one byte because the extra address bits are hidden in the
          * chip address.
@@ -752,7 +752,7 @@ i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
 uchar
 i2c_reg_read(uchar chip, uchar reg)
 {
-       char buf;
+       uchar buf;
 
        i2c_read(chip, reg, 1, &buf, 1);