Skip to contentSkip to conversation

5/12 Multiadapter/multibus I2C, drivers part 2

PATCH New ksi at koi8.net 4 participants 5 messages Feb 12, 2009 – Feb 17, 2009 I2C

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 5/12 Multiadapter/multibus I2C, drivers part 2

---

drivers/i2c/omap1510_i2c.c +79 -46
diff -purN u-boot-i2c.orig/drivers/i2c/omap1510_i2c.c u-boot-i2c/drivers/i2c/omap1510_i2c.c
@@ -1,4 +1,8 @@
 /*
+ * Copyright (c) 2009 Sergey Kubushyn <[email protected]>
+ *
+ * Changes for multibus/multiadapter I2C support.
+ *
  * Basic I2C functions
  *
  * Copyright (c) 2003 Texas Instruments
@@ -19,11 +23,51 @@
  */
 
 #include <common.h>
+#include <i2c.h>
+
+i2c_adap_t	omap1510_i2c_adap;
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static void wait_for_bb (void)
+{
+	int timeout = 10;
+
+	while ((inw (I2C_STAT) & I2C_STAT_BB) && timeout--) {
+		inw (I2C_IV);
+		udelay (1000);
+	}
+
+	if (timeout <= 0) {
+		printf ("timed out in wait_for_bb: I2C_STAT=%x\n",
+			inw (I2C_STAT));
+	}
+}
+
+static u16 wait_for_pin (void)
+{
+	u16 status, iv;
+	int timeout = 10;
+
+	do {
+		udelay (1000);
+		status = inw (I2C_STAT);
+		iv = inw (I2C_IV);
+	} while (!iv &&
+		 !(status &
+		   (I2C_STAT_ROVR | I2C_STAT_XUDF | I2C_STAT_XRDY |
+		    I2C_STAT_RRDY | I2C_STAT_ARDY | I2C_STAT_NACK |
+		    I2C_STAT_AL)) && timeout--);
+
+	if (timeout <= 0) {
+		printf ("timed out in wait_for_pin: I2C_STAT=%x\n",
+			inw (I2C_STAT));
+	}
 
-static void wait_for_bb (void);
-static u16 wait_for_pin (void);
+	return status;
+}
 
-void i2c_init (int speed, int slaveadd)
+static void omap1510_i2c_init (int speed, int slaveadd)
 {
 	u16 scl;
 
@@ -46,6 +90,10 @@ void i2c_init (int speed, int slaveadd)
 	outw (slaveadd, I2C_OA);
 	outw (0, I2C_CNT);
 	udelay (1000);
+
+	if (gd->flags & GD_FLG_RELOC) {
+		omap1510_i2c_adap.init_done = 1;
+	}
 }
 
 static int i2c_read_byte (u8 devaddr, u8 regoffset, u8 * value)
@@ -158,7 +206,7 @@ static int i2c_write_byte (u8 devaddr, u
 	return i2c_error;
 }
 
-int i2c_probe (uchar chip)
+static int omap1510_i2c_probe (uchar chip)
 {
 	int res = 1;
 
@@ -188,24 +236,24 @@ int i2c_probe (uchar chip)
 	return res;
 }
 
-int i2c_read (uchar chip, uint addr, int alen, uchar * buffer, int len)
+static int omap1510_i2c_read (uchar chip, uint addr, int alen, uchar * buffer, int len)
 {
 	int i;
 
 	if (alen > 1) {
-		printf ("I2C read: addr len %d not supported\n", alen);
+		printf ("%s: addr len %d not supported\n", __FUNCTION__, alen);
 		return 1;
 	}
 
 	if (addr + len > 256) {
-		printf ("I2C read: address out of range\n");
+		printf ("%s: address out of range\n", __FUNCTION__);
 		return 1;
 	}
 
 	for (i = 0; i < len; i++) {
 		if (i2c_read_byte (chip, addr + i, &buffer[i])) {
-			printf ("I2C read: I/O error\n");
-			i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+			printf ("%s: I/O error\n", __FUNCTION__);
+			i2c_init (CONFIG_SYS_OMAP1510_I2C_SPEED, CONFIG_SYS_OMAP1510_I2C_SLAVE);
 			return 1;
 		}
 	}
@@ -213,24 +261,24 @@ int i2c_read (uchar chip, uint addr, int
 	return 0;
 }
 
-int i2c_write (uchar chip, uint addr, int alen, uchar * buffer, int len)
+static int omap1510_i2c_write (uchar chip, uint addr, int alen, uchar * buffer, int len)
 {
 	int i;
 
 	if (alen > 1) {
-		printf ("I2C read: addr len %d not supported\n", alen);
+		printf ("%s: addr len %d not supported\n", __FUNCTION__, alen);
 		return 1;
 	}
 
 	if (addr + len > 256) {
-		printf ("I2C read: address out of range\n");
+		printf ("%s: address out of range\n", __FUNCTION__);
 		return 1;
 	}
 
 	for (i = 0; i < len; i++) {
 		if (i2c_write_byte (chip, addr + i, buffer[i])) {
-			printf ("I2C read: I/O error\n");
-			i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+			printf ("%s: I/O error\n", __FUNCTION__);
+			i2c_init (CONFIG_SYS_OMAP1510_I2C_SPEED, CONFIG_SYS_OMAP1510_I2C_SLAVE);
 			return 1;
 		}
 	}
@@ -238,40 +286,25 @@ int i2c_write (uchar chip, uint addr, in
 	return 0;
 }
 
-static void wait_for_bb (void)
+static unsigned int omap1510_i2c_set_bus_speed(unsigned int speed)
 {
-	int timeout = 10;
-
-	while ((inw (I2C_STAT) & I2C_STAT_BB) && timeout--) {
-		inw (I2C_IV);
-		udelay (1000);
-	}
-
-	if (timeout <= 0) {
-		printf ("timed out in wait_for_bb: I2C_STAT=%x\n",
-			inw (I2C_STAT));
-	}
+	return(omap1510_i2c_adap.speed);
 }
 
-static u16 wait_for_pin (void)
+static unsigned int omap1510_i2c_get_bus_speed(void)
 {
-	u16 status, iv;
-	int timeout = 10;
-
-	do {
-		udelay (1000);
-		status = inw (I2C_STAT);
-		iv = inw (I2C_IV);
-	} while (!iv &&
-		 !(status &
-		   (I2C_STAT_ROVR | I2C_STAT_XUDF | I2C_STAT_XRDY |
-		    I2C_STAT_RRDY | I2C_STAT_ARDY | I2C_STAT_NACK |
-		    I2C_STAT_AL)) && timeout--);
-
-	if (timeout <= 0) {
-		printf ("timed out in wait_for_pin: I2C_STAT=%x\n",
-			inw (I2C_STAT));
-	}
-
-	return status;
+	return(omap1510_i2c_adap.speed);
 }
+
+i2c_adap_t	omap1510_i2c_adap = {
+	.init		=	omap1510_i2c_init,
+	.probe		=	omap1510_i2c_probe,
+	.read		=	omap1510_i2c_read,
+	.write		=	omap1510_i2c_write,
+	.set_bus_speed	=	omap1510_i2c_set_bus_speed,
+	.get_bus_speed	=	omap1510_i2c_get_bus_speed,
+	.speed		=	CONFIG_SYS_OMAP1510_I2C_SPEED,
+	.slaveaddr	=	CONFIG_SYS_OMAP1510_I2C_SLAVE,
+	.init_done	=	0,
+	.name		=	"omap1510_i2c"
+};
drivers/i2c/omap24xx_i2c.c +388 -134

706 lines not on this page · raw message

drivers/i2c/tsi108_i2c.c +38 -6

81 lines not on this page · raw message

include/asm-arm/arch-omap24xx/i2c.h +16 -16
diff -purN u-boot-i2c.orig/include/asm-arm/arch-omap24xx/i2c.h u-boot-i2c/include/asm-arm/arch-omap24xx/i2c.h
@@ -23,24 +23,24 @@
 #ifndef _OMAP24XX_I2C_H_
 #define _OMAP24XX_I2C_H_
 
-#define I2C_BASE                0x48070000
+#define I2C_BASE1               0x48070000
 #define I2C_BASE2               0x48072000 /* nothing hooked up on h4 */
 
-#define I2C_REV                 (I2C_BASE + 0x00)
-#define I2C_IE                  (I2C_BASE + 0x04)
-#define I2C_STAT                (I2C_BASE + 0x08)
-#define I2C_IV                  (I2C_BASE + 0x0c)
-#define I2C_BUF                 (I2C_BASE + 0x14)
-#define I2C_CNT                 (I2C_BASE + 0x18)
-#define I2C_DATA                (I2C_BASE + 0x1c)
-#define I2C_SYSC                (I2C_BASE + 0x20)
-#define I2C_CON                 (I2C_BASE + 0x24)
-#define I2C_OA                  (I2C_BASE + 0x28)
-#define I2C_SA                  (I2C_BASE + 0x2c)
-#define I2C_PSC                 (I2C_BASE + 0x30)
-#define I2C_SCLL                (I2C_BASE + 0x34)
-#define I2C_SCLH                (I2C_BASE + 0x38)
-#define I2C_SYSTEST             (I2C_BASE + 0x3c)
+#define I2C_REV                 (0x00)
+#define I2C_IE                  (0x04)
+#define I2C_STAT                (0x08)
+#define I2C_IV                  (0x0c)
+#define I2C_BUF                 (0x14)
+#define I2C_CNT                 (0x18)
+#define I2C_DATA                (0x1c)
+#define I2C_SYSC                (0x20)
+#define I2C_CON                 (0x24)
+#define I2C_OA                  (0x28)
+#define I2C_SA                  (0x2c)
+#define I2C_PSC                 (0x30)
+#define I2C_SCLL                (0x34)
+#define I2C_SCLH                (0x38)
+#define I2C_SYSTEST             (0x3c)
 
 /* I2C masks */
 
include/asm-arm/arch-omap3/i2c.h +18 -20
diff -purN u-boot-i2c.orig/include/asm-arm/arch-omap3/i2c.h u-boot-i2c/include/asm-arm/arch-omap3/i2c.h
@@ -20,26 +20,24 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  * MA 02111-1307 USA
  */
-#ifndef _I2C_H_
-#define _I2C_H_
+#ifndef _OMAP3_I2C_H_
+#define _OMAP3_I2C_H_
 
-#define I2C_DEFAULT_BASE	I2C_BASE1
-
-#define I2C_REV		(I2C_DEFAULT_BASE + 0x00)
-#define I2C_IE 		(I2C_DEFAULT_BASE + 0x04)
-#define I2C_STAT	(I2C_DEFAULT_BASE + 0x08)
-#define I2C_IV 		(I2C_DEFAULT_BASE + 0x0c)
-#define I2C_BUF		(I2C_DEFAULT_BASE + 0x14)
-#define I2C_CNT		(I2C_DEFAULT_BASE + 0x18)
-#define I2C_DATA	(I2C_DEFAULT_BASE + 0x1c)
-#define I2C_SYSC	(I2C_DEFAULT_BASE + 0x20)
-#define I2C_CON		(I2C_DEFAULT_BASE + 0x24)
-#define I2C_OA 		(I2C_DEFAULT_BASE + 0x28)
-#define I2C_SA 		(I2C_DEFAULT_BASE + 0x2c)
-#define I2C_PSC		(I2C_DEFAULT_BASE + 0x30)
-#define I2C_SCLL	(I2C_DEFAULT_BASE + 0x34)
-#define I2C_SCLH	(I2C_DEFAULT_BASE + 0x38)
-#define I2C_SYSTEST	(I2C_DEFAULT_BASE + 0x3c)
+#define I2C_REV		(0x00)
+#define I2C_IE 		(0x04)
+#define I2C_STAT	(0x08)
+#define I2C_IV 		(0x0c)
+#define I2C_BUF		(0x14)
+#define I2C_CNT		(0x18)
+#define I2C_DATA	(0x1c)
+#define I2C_SYSC	(0x20)
+#define I2C_CON		(0x24)
+#define I2C_OA 		(0x28)
+#define I2C_SA 		(0x2c)
+#define I2C_PSC		(0x30)
+#define I2C_SCLL	(0x34)
+#define I2C_SCLH	(0x38)
+#define I2C_SYSTEST	(0x3c)
 
 /* I2C masks */
 
@@ -125,4 +123,4 @@
 #define I2C_PSC_MAX		0x0f
 #define I2C_PSC_MIN		0x00
 
-#endif /* _I2C_H_ */
+#endif /* _OMAP3_I2C_H_ */
#1 lore raw

PATCH 1/1 5/12 Multiadapter/multibus I2C, drivers part 2

Hello ksi

Quoted 2 lines · ksi at koi8.net wrote:

Patch apply with warnings:

Applying: 5/12 Multiadapter/multibus I2C, drivers part 2 /home/hs/i2c/u-boot-i2c/.git/rebase-apply/patch:698: trailing whitespace. #ifdef CONFIG_SYS_OMAP24XX_I2C2_BASE /home/hs/i2c/u-boot-i2c/.git/rebase-apply/patch:799: trailing whitespace. #ifdef CONFIG_SYS_OMAP24XX_I2C3_BASE /home/hs/i2c/u-boot-i2c/.git/rebase-apply/patch:894: trailing whitespace. #ifdef CONFIG_SYS_OMAP24XX_I2C2_BASE /home/hs/i2c/u-boot-i2c/.git/rebase-apply/patch:908: trailing whitespace. #ifdef CONFIG_SYS_OMAP24XX_I2C3_BASE /home/hs/i2c/u-boot-i2c/.git/rebase-apply/patch:1013: trailing whitespace.

warning: 5 lines add whitespace errors.

please fix
bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany 
#3 lore raw

PATCH 1/1 5/12 Multiadapter/multibus I2C, drivers part 2

In reply to ksi at koi8.net

Dear ksi at koi8.net,

Quoted 1 line · In message <[email protected]> you wrote:

...

Quoted 4 lines
drivers/i2c/omap1510_i2c.c +1 -1
-int i2c_read (uchar chip, uint addr, int alen, uchar * buffer, int len)
+static int omap1510_i2c_read (uchar chip, uint addr, int alen, uchar * buffer, int len)
 {
 	int i;

drivers/i2c/omap1510_i2c.c int i2c_probe (uchar chip) · line 249

Quoted 10 lines
drivers/i2c/omap1510_i2c.c +2 -2
 
 	if (alen > 1) {
-		printf ("I2C read: addr len %d not supported\n", alen);
+		printf ("%s: addr len %d not supported\n", __FUNCTION__, alen);
 		return 1;
 	}
 
 	if (addr + len > 256) {
-		printf ("I2C read: address out of range\n");
+		printf ("%s: address out of range\n", __FUNCTION__);

These are changes really to the worse: instead of

I2C read: address out of range

we now get

omap1510_i2c_read: address out of range

More difficult to read, higher memory footprint.

Please revert this.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Today's robots are very primitive, capable of understanding  only  a
few  simple  instructions  such  as 'go left', 'go right', and 'build
car'."                                                  - John Sladek
#4 lore raw

PATCH 1/1 5/12 Multiadapter/multibus I2C, drivers part 2

Quoted 24 lines · Wolfgang Denk

Dear ksi at koi8.net,

Quoted 1 line · In message <[email protected]> you wrote:

...

Quoted 4 lines
drivers/i2c/omap1510_i2c.c +1 -1
-int i2c_read (uchar chip, uint addr, int alen, uchar * buffer, int len)
+static int omap1510_i2c_read (uchar chip, uint addr, int alen, uchar * buffer, int len)
 {
 	int i;

drivers/i2c/omap1510_i2c.c int i2c_probe (uchar chip) · line 249

Quoted 10 lines
drivers/i2c/omap1510_i2c.c +2 -2
 
 	if (alen > 1) {
-		printf ("I2C read: addr len %d not supported\n", alen);
+		printf ("%s: addr len %d not supported\n", __FUNCTION__, alen);
 		return 1;
 	}
 
 	if (addr + len > 256) {
-		printf ("I2C read: address out of range\n");
+		printf ("%s: address out of range\n", __FUNCTION__);

These are changes really to the worse: instead of

I2C read: address out of range

Quoted 7 lines

we now get

omap1510_i2c_read: address out of range

More difficult to read, higher memory footprint.

Please revert this.

No problems, will do.

---
******************************************************************
* KSI at home KOI8 Net < > The impossible we do immediately. *
* Las Vegas NV, USA < > Miracles require 24-hour notice. *
******************************************************************