[U-Boot] [PATCH 22/29] cpu/mpc512x/i2c.c: use immr offsets from C struct instead of #define

Wolfgang Denk wd at denx.de
Sat May 9 21:51:01 CEST 2009


Signed-off-by: Wolfgang Denk <wd at denx.de>
Cc: John Rigby <jcrigby at gmail.com>
---
 cpu/mpc512x/i2c.c |   33 ++++++++++++++++++++-------------
 1 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/cpu/mpc512x/i2c.c b/cpu/mpc512x/i2c.c
index 812f24a..e9bb3e7 100644
--- a/cpu/mpc512x/i2c.c
+++ b/cpu/mpc512x/i2c.c
@@ -31,8 +31,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #include <i2c.h>
 
-#define immr ((immap_t *)CONFIG_SYS_IMMR)
-
 /* by default set I2C bus 0 active */
 static unsigned int bus_num = 0;
 
@@ -77,7 +75,8 @@ static void mpc_reg_out (volatile u32 *reg, int val, int mask)
 
 static int wait_for_bb (void)
 {
-	i2c512x_dev_t *regs = &immr->i2c.dev[bus_num];
+	volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
+	volatile i2c512x_dev_t *regs = &im->i2c.dev[bus_num];
 	int timeout = I2C_TIMEOUT;
 	int status;
 
@@ -100,7 +99,8 @@ static int wait_for_bb (void)
 
 static int wait_for_pin (int *status)
 {
-	i2c512x_dev_t *regs = &immr->i2c.dev[bus_num];
+	volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
+	volatile i2c512x_dev_t *regs = &im->i2c.dev[bus_num];
 	int timeout = I2C_TIMEOUT;
 
 	*status = mpc_reg_in (&regs->msr);
@@ -121,7 +121,8 @@ static int wait_for_pin (int *status)
 
 static int do_address (uchar chip, char rdwr_flag)
 {
-	i2c512x_dev_t *regs = &immr->i2c.dev[bus_num];
+	volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
+	volatile i2c512x_dev_t *regs = &im->i2c.dev[bus_num];
 	int status;
 
 	chip <<= 1;
@@ -146,7 +147,8 @@ static int do_address (uchar chip, char rdwr_flag)
 
 static int send_bytes (uchar chip, char *buf, int len)
 {
-	i2c512x_dev_t *regs = &immr->i2c.dev[bus_num];
+	volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
+	volatile i2c512x_dev_t *regs = &im->i2c.dev[bus_num];
 	int wrcount;
 	int status;
 
@@ -169,7 +171,8 @@ static int send_bytes (uchar chip, char *buf, int len)
 
 static int receive_bytes (uchar chip, char *buf, int len)
 {
-	i2c512x_dev_t *regs = &immr->i2c.dev[bus_num];
+	volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
+	volatile i2c512x_dev_t *regs = &im->i2c.dev[bus_num];
 	int dummy   = 1;
 	int rdcount = 0;
 	int status;
@@ -207,9 +210,10 @@ static int receive_bytes (uchar chip, char *buf, int len)
 
 void i2c_init (int speed, int saddr)
 {
+	volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
 	int i;
 	for(i = 0; i < I2C_BUS_CNT; i++){
-		i2c512x_dev_t *regs = &immr->i2c.dev[i];
+		volatile i2c512x_dev_t *regs = &im->i2c.dev[i];
 		mpc_reg_out (&regs->mcr, 0, 0);
 
 		/* Set clock */
@@ -222,9 +226,9 @@ void i2c_init (int speed, int saddr)
 	}
 
 	/* Disable interrupts */
-	immr->i2c.icr = 0;
+	im->i2c.icr = 0;
 	/* Turn off filters */
-	immr->i2c.mifr = 0;
+	im->i2c.mifr = 0;
 	return;
 }
 
@@ -280,7 +284,8 @@ static int mpc_get_fdr (int speed)
 
 int i2c_probe (uchar chip)
 {
-	i2c512x_dev_t *regs = &immr->i2c.dev[bus_num];
+	volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
+	volatile i2c512x_dev_t *regs = &im->i2c.dev[bus_num];
 	int i;
 
 	for (i = 0; i < I2C_RETRIES; i++) {
@@ -301,8 +306,9 @@ int i2c_probe (uchar chip)
 
 int i2c_read (uchar chip, uint addr, int alen, uchar *buf, int len)
 {
+	volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
+	volatile i2c512x_dev_t *regs = &im->i2c.dev[bus_num];
 	char xaddr[4];
-	i2c512x_dev_t *regs = &immr->i2c.dev[bus_num];
 	int ret = -1;
 
 	xaddr[0] = (addr >> 24) & 0xFF;
@@ -345,8 +351,9 @@ Done:
 
 int i2c_write (uchar chip, uint addr, int alen, uchar *buf, int len)
 {
+	volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
+	volatile i2c512x_dev_t *regs = &im->i2c.dev[bus_num];
 	char xaddr[4];
-	i2c512x_dev_t *regs = &immr->i2c.dev[bus_num];
 	int ret = -1;
 
 	xaddr[0] = (addr >> 24) & 0xFF;
-- 
1.6.0.6



More information about the U-Boot mailing list