]> git.sur5r.net Git - u-boot/blobdiff - cpu/mpc5xxx/i2c.c
mpc83xx: clean up cache operations and unlock_ram_in_cache() functions
[u-boot] / cpu / mpc5xxx / i2c.c
index ea37fb0e68d6cf41f5f1f4476ee5fe07d4d834fc..0f02e78a3bd3e25d04459b50c0b36c5d0e79cdc1 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <common.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 #ifdef CONFIG_HARD_I2C
 
 #include <mpc5xxx.h>
@@ -55,8 +57,9 @@ static int  mpc_get_fdr   (int);
 
 static int mpc_reg_in(volatile u32 *reg)
 {
-       return *reg >> 24;
+       int ret = *reg >> 24;
        __asm__ __volatile__ ("eieio");
+       return ret;
 }
 
 static void mpc_reg_out(volatile u32 *reg, int val, int mask)
@@ -227,11 +230,11 @@ void i2c_init(int speed, int saddr)
 
 static int mpc_get_fdr(int speed)
 {
-       DECLARE_GLOBAL_DATA_PTR;
        static int fdr = -1;
-       static int best_speed = 0;
 
        if (fdr == -1) {
+               ulong best_speed = 0;
+               ulong divider;
                ulong ipb, scl;
                ulong bestmatch = 0xffffffffUL;
                int best_i = 0, best_j = 0, i, j;
@@ -262,8 +265,13 @@ static int mpc_get_fdr(int speed)
                                }
                        }
                }
-               fdr = (best_i & 3) | ((best_i & 4) << 3) | (best_j << 2);
-               printf("%d kHz, ", best_speed / 1000);
+               divider = (best_i & 3) | ((best_i & 4) << 3) | (best_j << 2);
+               if (gd->flags & GD_FLG_RELOC) {
+                       fdr = divider;
+               } else {
+                       printf("%ld kHz, ", best_speed / 1000);
+                       return divider;
+               }
        }
 
        return fdr;
@@ -279,6 +287,7 @@ int i2c_probe(uchar chip)
 
                if (! do_address(chip, 0)) {
                        mpc_reg_out(&regs->mcr, 0, I2C_STA);
+                       udelay(500);
                        break;
                }
 
@@ -291,7 +300,7 @@ int i2c_probe(uchar chip)
 
 int i2c_read(uchar chip, uint addr, int alen, uchar *buf, int len)
 {
-       uchar                xaddr[4];
+       char                xaddr[4];
        struct mpc5xxx_i2c * regs        = (struct mpc5xxx_i2c *)I2C_BASE;
        int                  ret         = -1;
 
@@ -322,7 +331,7 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buf, int len)
                goto Done;
        }
 
-       if (receive_bytes(chip, buf, len)) {
+       if (receive_bytes(chip, (char *)buf, len)) {
                printf("i2c_read: receive_bytes failed\n");
                goto Done;
        }
@@ -335,7 +344,7 @@ Done:
 
 int i2c_write(uchar chip, uint addr, int alen, uchar *buf, int len)
 {
-       uchar               xaddr[4];
+       char               xaddr[4];
        struct mpc5xxx_i2c *regs        = (struct mpc5xxx_i2c *)I2C_BASE;
        int                 ret         = -1;
 
@@ -360,7 +369,7 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buf, int len)
                goto Done;
        }
 
-       if (send_bytes(chip, buf, len)) {
+       if (send_bytes(chip, (char *)buf, len)) {
                printf("i2c_write: send_bytes failed\n");
                goto Done;
        }
@@ -373,7 +382,7 @@ Done:
 
 uchar i2c_reg_read(uchar chip, uchar reg)
 {
-       char buf;
+       uchar buf;
 
        i2c_read(chip, reg, 1, &buf, 1);