pxa: move i2c driver to the common place

For better sharing with other platform other than pxa's,
it is more convenient to put the driver to the common place.

Acked-by: Heiko Schocher <hs@denx.de>
Acked-by: Prafulla Wadaskar <prafulla@marvell.com>
Signed-off-by: Lei Wen <leiwen@marvell.com>
diff --git a/arch/arm/cpu/pxa/Makefile b/arch/arm/cpu/pxa/Makefile
index 49a6ed3..e8b59a3 100644
--- a/arch/arm/cpu/pxa/Makefile
+++ b/arch/arm/cpu/pxa/Makefile
@@ -28,7 +28,6 @@
 START	= start.o
 
 COBJS	+= cpu.o
-COBJS	+= i2c.o
 COBJS	+= pxafb.o
 COBJS	+= timer.o
 COBJS	+= usb.o
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 052fe36..00a12cc 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -29,6 +29,7 @@
 COBJS-$(CONFIG_DRIVER_DAVINCI_I2C) += davinci_i2c.o
 COBJS-$(CONFIG_FSL_I2C) += fsl_i2c.o
 COBJS-$(CONFIG_I2C_MVTWSI) += mvtwsi.o
+COBJS-$(CONFIG_I2C_MV) += mv_i2c.o
 COBJS-$(CONFIG_I2C_MXC) += mxc_i2c.o
 COBJS-$(CONFIG_DRIVER_OMAP1510_I2C) += omap1510_i2c.o
 COBJS-$(CONFIG_DRIVER_OMAP24XX_I2C) += omap24xx_i2c.o
diff --git a/arch/arm/cpu/pxa/i2c.c b/drivers/i2c/mv_i2c.c
similarity index 85%
rename from arch/arm/cpu/pxa/i2c.c
rename to drivers/i2c/mv_i2c.c
index 7aa49ae..09756a4 100644
--- a/arch/arm/cpu/pxa/i2c.c
+++ b/drivers/i2c/mv_i2c.c
@@ -30,8 +30,6 @@
  * Murray.Jensen@cmst.csiro.au, 27-Jan-01.
  */
 
-/* FIXME: this file is PXA255 specific! What about other XScales? */
-
 #include <common.h>
 #include <asm/io.h>
 
@@ -46,11 +44,9 @@
 #include <asm/arch/pxa-regs.h>
 #include <i2c.h>
 
-/*#define	DEBUG_I2C	1	/###* activate local debugging output  */
-#define I2C_PXA_SLAVE_ADDR	0x1	/* slave pxa unit address           */
-
 #if (CONFIG_SYS_I2C_SPEED == 400000)
-#define I2C_ICR_INIT	(ICR_FM | ICR_BEIE | ICR_IRFIE | ICR_ITEIE | ICR_GCD | ICR_SCLE)
+#define I2C_ICR_INIT	(ICR_FM | ICR_BEIE | ICR_IRFIE | ICR_ITEIE | ICR_GCD \
+			| ICR_SCLE)
 #else
 #define I2C_ICR_INIT	(ICR_BEIE | ICR_IRFIE | ICR_ITEIE | ICR_GCD | ICR_SCLE)
 #endif
@@ -63,7 +59,6 @@
 #define PRINTD(x)
 #endif
 
-
 /* Shall the current transfer have a start/stop condition? */
 #define I2C_COND_NORMAL		0
 #define I2C_COND_START		1
@@ -86,13 +81,11 @@
 	u8 data;
 };
 
-
-/**
+/*
  * i2c_pxa_reset: - reset the host controller
  *
  */
-
-static void i2c_reset( void )
+static void i2c_reset(void)
 {
 	writel(readl(ICR) & ~ICR_IUE, ICR);	/* disable unit */
 	writel(readl(ICR) | ICR_UR, ICR);	/* reset the unit */
@@ -112,27 +105,27 @@
 	udelay(100);
 }
 
-
-/**
+/*
  * i2c_isr_set_cleared: - wait until certain bits of the I2C status register
  *	                  are set and cleared
  *
  * @return: 1 in case of success, 0 means timeout (no match within 10 ms).
  */
-static int i2c_isr_set_cleared( unsigned long set_mask, unsigned long cleared_mask )
+static int i2c_isr_set_cleared(unsigned long set_mask,
+			       unsigned long cleared_mask)
 {
 	int timeout = 10000;
 
-	while( ((ISR & set_mask)!=set_mask) || ((ISR & cleared_mask)!=0) ){
-		udelay( 10 );
-		if( timeout-- < 0 ) return 0;
+	while (((ISR & set_mask) != set_mask) || ((ISR & cleared_mask) != 0)) {
+		udelay(10);
+		if (timeout-- < 0)
+			return 0;
 	}
 
 	return 1;
 }
 
-
-/**
+/*
  * i2c_transfer: - Transfer one byte over the i2c bus
  *
  * This function can tranfer a byte over the i2c bus in both directions.
@@ -153,12 +146,10 @@
 	if (!msg)
 		goto transfer_error_msg_empty;
 
-	switch(msg->direction) {
-
+	switch (msg->direction) {
 	case I2C_WRITE:
-
 		/* check if bus is not busy */
-		if (!i2c_isr_set_cleared(0,ISR_IBB))
+		if (!i2c_isr_set_cleared(0, ISR_IBB))
 			goto transfer_error_bus_busy;
 
 		/* start transmission */
@@ -177,7 +168,7 @@
 		writel(readl(ICR) | ICR_TB, ICR);
 
 		/* transmit register empty? */
-		if (!i2c_isr_set_cleared(ISR_ITE,0))
+		if (!i2c_isr_set_cleared(ISR_ITE, 0))
 			goto transfer_error_transmit_timeout;
 
 		/* clear 'transmit empty' state */
@@ -185,14 +176,14 @@
 
 		/* wait for ACK from slave */
 		if (msg->acknack == I2C_ACKNAK_WAITACK)
-			if (!i2c_isr_set_cleared(0,ISR_ACKNAK))
+			if (!i2c_isr_set_cleared(0, ISR_ACKNAK))
 				goto transfer_error_ack_missing;
 		break;
 
 	case I2C_READ:
 
 		/* check if bus is not busy */
-		if (!i2c_isr_set_cleared(0,ISR_IBB))
+		if (!i2c_isr_set_cleared(0, ISR_IBB))
 			goto transfer_error_bus_busy;
 
 		/* start receive */
@@ -210,7 +201,7 @@
 		writel(readl(ICR) | ICR_TB, ICR);
 
 		/* receive register full? */
-		if (!i2c_isr_set_cleared(ISR_IRF,0))
+		if (!i2c_isr_set_cleared(ISR_IRF, 0))
 			goto transfer_error_receive_timeout;
 
 		msg->data = readl(IDBR);
@@ -219,11 +210,8 @@
 		writel(readl(ISR) | ISR_IRF, ISR);
 
 		break;
-
 	default:
-
 		goto transfer_error_illegal_param;
-
 	}
 
 	return 0;
@@ -253,16 +241,14 @@
 		ret = -6; goto i2c_transfer_finish;
 
 i2c_transfer_finish:
-		PRINTD(("i2c_transfer: ISR: 0x%04x\n",ISR));
+		PRINTD(("i2c_transfer: ISR: 0x%04x\n", ISR));
 		i2c_reset();
 		return ret;
-
 }
 
 /* ------------------------------------------------------------------------ */
 /* API Functions                                                            */
 /* ------------------------------------------------------------------------ */
-
 void i2c_init(int speed, int slaveaddr)
 {
 #ifdef CONFIG_SYS_I2C_INIT_BOARD
@@ -273,14 +259,12 @@
 #endif
 }
 
-
-/**
+/*
  * i2c_probe: - Test if a chip answers for a given i2c address
  *
  * @chip:	address of the chip which is searched for
  * @return:	0 if a chip was found, -1 otherwhise
  */
-
 int i2c_probe(uchar chip)
 {
 	struct i2c_msg msg;
@@ -291,19 +275,20 @@
 	msg.acknack   = I2C_ACKNAK_WAITACK;
 	msg.direction = I2C_WRITE;
 	msg.data      = (chip << 1) + 1;
-	if (i2c_transfer(&msg)) return -1;
+	if (i2c_transfer(&msg))
+		return -1;
 
 	msg.condition = I2C_COND_STOP;
 	msg.acknack   = I2C_ACKNAK_SENDNAK;
 	msg.direction = I2C_READ;
 	msg.data      = 0x00;
-	if (i2c_transfer(&msg)) return -1;
+	if (i2c_transfer(&msg))
+		return -1;
 
 	return 0;
 }
 
-
-/**
+/*
  * i2c_read: - Read multiple bytes from an i2c device
  *
  * The higher level routines take into account that this function is only
@@ -316,14 +301,13 @@
  * @len:	how much byte do we want to read
  * @return:	0 in case of success
  */
-
 int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
 {
 	struct i2c_msg msg;
 	u8 addr_bytes[3]; /* lowest...highest byte of data address */
-	int ret;
 
-	PRINTD(("i2c_read(chip=0x%02x, addr=0x%02x, alen=0x%02x, len=0x%02x)\n",chip,addr,alen,len));
+	PRINTD(("i2c_read(chip=0x%02x, addr=0x%02x, alen=0x%02x, "
+		"len=0x%02x)\n", chip, addr, alen, len));
 
 	i2c_reset();
 
@@ -332,9 +316,10 @@
 	msg.condition = I2C_COND_START;
 	msg.acknack   = I2C_ACKNAK_WAITACK;
 	msg.direction = I2C_WRITE;
-	msg.data      = (chip << 1);
-	msg.data     &= 0xFE;
-	if ((ret=i2c_transfer(&msg))) return -1;
+	msg.data = (chip << 1);
+	msg.data &= 0xFE;
+	if (i2c_transfer(&msg))
+		return -1;
 
 	/*
 	 * send memory address bytes;
@@ -346,16 +331,15 @@
 	addr_bytes[2] = (u8)((addr >> 16) & 0x000000FF);
 
 	while (--alen >= 0) {
-
-		PRINTD(("i2c_read: send memory word address byte %1d\n",alen));
+		PRINTD(("i2c_read: send memory word address byte %1d\n", alen));
 		msg.condition = I2C_COND_NORMAL;
 		msg.acknack   = I2C_ACKNAK_WAITACK;
 		msg.direction = I2C_WRITE;
 		msg.data      = addr_bytes[alen];
-		if ((ret=i2c_transfer(&msg))) return -1;
+		if (i2c_transfer(&msg))
+			return -1;
 	}
 
-
 	/* start read sequence */
 	PRINTD(("i2c_read: start read sequence\n"));
 	msg.condition = I2C_COND_START;
@@ -363,12 +347,12 @@
 	msg.direction = I2C_WRITE;
 	msg.data      = (chip << 1);
 	msg.data     |= 0x01;
-	if ((ret=i2c_transfer(&msg))) return -1;
+	if (i2c_transfer(&msg))
+		return -1;
 
 	/* read bytes; send NACK at last byte */
 	while (len--) {
-
-		if (len==0) {
+		if (len == 0) {
 			msg.condition = I2C_COND_STOP;
 			msg.acknack   = I2C_ACKNAK_SENDNAK;
 		} else {
@@ -378,12 +362,13 @@
 
 		msg.direction = I2C_READ;
 		msg.data      = 0x00;
-		if ((ret=i2c_transfer(&msg))) return -1;
+		if (i2c_transfer(&msg))
+			return -1;
 
 		*buffer = msg.data;
-		PRINTD(("i2c_read: reading byte (0x%08x)=0x%02x\n",(unsigned int)buffer,*buffer));
+		PRINTD(("i2c_read: reading byte (0x%08x)=0x%02x\n",
+			(unsigned int)buffer, *buffer));
 		buffer++;
-
 	}
 
 	i2c_reset();
@@ -391,8 +376,7 @@
 	return 0;
 }
 
-
-/**
+/*
  * i2c_write: -  Write multiple bytes to an i2c device
  *
  * The higher level routines take into account that this function is only
@@ -405,13 +389,13 @@
  * @len:	how much byte do we want to read
  * @return:	0 in case of success
  */
-
 int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
 {
 	struct i2c_msg msg;
 	u8 addr_bytes[3]; /* lowest...highest byte of data address */
 
-	PRINTD(("i2c_write(chip=0x%02x, addr=0x%02x, alen=0x%02x, len=0x%02x)\n",chip,addr,alen,len));
+	PRINTD(("i2c_write(chip=0x%02x, addr=0x%02x, alen=0x%02x, "
+		"len=0x%02x)\n", chip, addr, alen, len));
 
 	i2c_reset();
 
@@ -420,9 +404,10 @@
 	msg.condition = I2C_COND_START;
 	msg.acknack   = I2C_ACKNAK_WAITACK;
 	msg.direction = I2C_WRITE;
-	msg.data      = (chip << 1);
-	msg.data     &= 0xFE;
-	if (i2c_transfer(&msg)) return -1;
+	msg.data = (chip << 1);
+	msg.data &= 0xFE;
+	if (i2c_transfer(&msg))
+		return -1;
 
 	/*
 	 * send memory address bytes;
@@ -433,21 +418,21 @@
 	addr_bytes[2] = (u8)((addr >> 16) & 0x000000FF);
 
 	while (--alen >= 0) {
-
 		PRINTD(("i2c_write: send memory word address\n"));
 		msg.condition = I2C_COND_NORMAL;
 		msg.acknack   = I2C_ACKNAK_WAITACK;
 		msg.direction = I2C_WRITE;
 		msg.data      = addr_bytes[alen];
-		if (i2c_transfer(&msg)) return -1;
+		if (i2c_transfer(&msg))
+			return -1;
 	}
 
 	/* write bytes; send NACK at last byte */
 	while (len--) {
+		PRINTD(("i2c_write: writing byte (0x%08x)=0x%02x\n",
+			(unsigned int)buffer, *buffer));
 
-		PRINTD(("i2c_write: writing byte (0x%08x)=0x%02x\n",(unsigned int)buffer,*buffer));
-
-		if (len==0)
+		if (len == 0)
 			msg.condition = I2C_COND_STOP;
 		else
 			msg.condition = I2C_COND_NORMAL;
@@ -456,14 +441,12 @@
 		msg.direction = I2C_WRITE;
 		msg.data      = *(buffer++);
 
-		if (i2c_transfer(&msg)) return -1;
-
+		if (i2c_transfer(&msg))
+			return -1;
 	}
 
 	i2c_reset();
 
 	return 0;
-
 }
-
 #endif	/* CONFIG_HARD_I2C */
diff --git a/include/configs/innokom.h b/include/configs/innokom.h
index d8fcbdb..0ea73c9 100644
--- a/include/configs/innokom.h
+++ b/include/configs/innokom.h
@@ -140,6 +140,7 @@
 /*
  * I2C bus
  */
+#define CONFIG_I2C_MV			1
 #define CONFIG_HARD_I2C			1
 #define CONFIG_SYS_I2C_SPEED			50000
 #define CONFIG_SYS_I2C_SLAVE			0xfe
diff --git a/include/configs/xm250.h b/include/configs/xm250.h
index 497cb91..b4b940a 100644
--- a/include/configs/xm250.h
+++ b/include/configs/xm250.h
@@ -61,6 +61,7 @@
 /*
  * I2C bus
  */
+#define CONFIG_I2C_MV			1
 #define CONFIG_HARD_I2C			1
 #define CONFIG_SYS_I2C_SPEED			50000
 #define CONFIG_SYS_I2C_SLAVE			0xfe