public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot-Users] [AT91] Problems configuring bit-banged I2C
@ 2008-05-23 23:36 Sergey Lapin
  2008-05-24 13:33 ` Jean-Christophe PLAGNIOL-VILLARD
  2008-05-24 15:24 ` Haavard Skinnemoen
  0 siblings, 2 replies; 5+ messages in thread
From: Sergey Lapin @ 2008-05-23 23:36 UTC (permalink / raw)
  To: u-boot

Hi, all!

I use the following patch on my AT91SAM9260-based custom board to
configure bit-banged I2C:

diff --git a/board/atmel/at91sam9260ek/at91sam9260ek.c b/board/atmel/at91sam9260ek/at91sam9260ek.c
index b30aad8..99fc2bd 100644
--- a/board/atmel/at91sam9260ek/at91sam9260ek.c
+++ b/board/atmel/at91sam9260ek/at91sam9260ek.c
@ -234,3 +234,46 @@ void reset_phy(void)
 #endif
 }
 #endif
+
+#define GPIO_I2C_SCL	AT91_PIN_PA24
+#define GPIO_I2C_SDA	AT91_PIN_PA23
+
+void at91sam9260_i2c_init(void)
+{
+	__raw_writel(pin_to_mask(GPIO_I2C_SCL), pin_to_controller(GPIO_I2C_SCL) + PIO_IDR);
+	__raw_writel(pin_to_mask(GPIO_I2C_SCL), pin_to_controller(GPIO_I2C_SCL) + PIO_PUER);
+	__raw_writel(pin_to_mask(GPIO_I2C_SCL), pin_to_controller(GPIO_I2C_SCL) + PIO_PER);
+	__raw_writel(pin_to_mask(GPIO_I2C_SCL), pin_to_controller(GPIO_I2C_SCL) + PIO_MDER);
+	__raw_writel(pin_to_mask(GPIO_I2C_SCL), pin_to_controller(GPIO_I2C_SCL) + PIO_SODR);
+	__raw_writel(pin_to_mask(GPIO_I2C_SCL), pin_to_controller(GPIO_I2C_SCL) + PIO_OER);
+
+	__raw_writel(pin_to_mask(GPIO_I2C_SDA), pin_to_controller(GPIO_I2C_SDA) + PIO_IDR);
+	__raw_writel(pin_to_mask(GPIO_I2C_SDA), pin_to_controller(GPIO_I2C_SDA) + PIO_PUER);
+	__raw_writel(pin_to_mask(GPIO_I2C_SDA), pin_to_controller(GPIO_I2C_SDA) + PIO_PER);
+	__raw_writel(pin_to_mask(GPIO_I2C_SDA), pin_to_controller(GPIO_I2C_SDA) + PIO_MDER);
+	__raw_writel(pin_to_mask(GPIO_I2C_SDA), pin_to_controller(GPIO_I2C_SDA) + PIO_SODR);
+	__raw_writel(pin_to_mask(GPIO_I2C_SDA), pin_to_controller(GPIO_I2C_SDA) + PIO_OER);
+}
+void at91sam9260_i2c_scl(unsigned long bit)
+{
+	if(bit)
+		__raw_writel(pin_to_mask(GPIO_I2C_SCL), pin_to_controller(GPIO_I2C_SCL) + PIO_SODR);
+	 else
+		__raw_writel(pin_to_mask(GPIO_I2C_SCL), pin_to_controller(GPIO_I2C_SCL) + PIO_CODR);
+}
+
+void at91sam9260_i2c_sda(unsigned long bit)
+{
+	printf("Setting %u\n", bit);
+	if(bit)
+		__raw_writel(pin_to_mask(GPIO_I2C_SDA), pin_to_controller(GPIO_I2C_SDA) + PIO_SODR);
+	 else
+		__raw_writel(pin_to_mask(GPIO_I2C_SDA), pin_to_controller(GPIO_I2C_SDA) + PIO_CODR);
+}
+
+int  at91sam9260_i2c_read(void)
+{
+	int c = (__raw_readl(pin_to_controller(GPIO_I2C_SDA) + PIO_PDSR) & pin_to_mask(GPIO_I2C_SDA)) ? 1 : 0;
+	printf("Reading %d\n", c);
+	return c;
+}
diff --git a/include/configs/at91sam9260ek.h b/include/configs/at91sam9260ek.h
index fd9932f..5e66c9e 100644
--- a/include/configs/at91sam9260ek.h
+++ b/include/configs/at91sam9260ek.h
@@ -85,6 +85,8 @@
 
 #define CONFIG_CMD_NAND		1
 #define CONFIG_CMD_USB		1
+#define CONFIG_CMD_I2C		1
+#define CONFIG_I2C_CMD_TREE	1
 
 /* SDRAM */
 #define CONFIG_NR_DRAM_BANKS		1
@ -192,4 +194,20 @@
 #error CONFIG_USE_IRQ not supported
 #endif
 
+/*
+ * Software (bit-bang) I2C driver configuration
+ */
+#define CONFIG_SOFT_I2C		1
+#define CFG_I2C_SPEED		1000000
+#define I2C_INIT		at91sam9260_i2c_init()
+				
+#define I2C_ACTIVE
+#define I2C_TRISTATE
+#define I2C_SCL(bit)	at91sam9260_i2c_scl(bit)
+#define I2C_SDA(bit)	at91sam9260_i2c_sda(bit)
+#define I2C_DELAY	udelay(2)
+#define I2C_READ	at91sam9260_i2c_read()
+#define CFG_I2C_SLAVE		0
+#define DEBUG_I2C
 #endif
+

But I'm unable to read proper values from lines - they always
return 0s. Any ideas on fixing?
Linux i2c-gpio driver works perfectly.

Thanks a lot,
S.

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-05-30 21:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-23 23:36 [U-Boot-Users] [AT91] Problems configuring bit-banged I2C Sergey Lapin
2008-05-24 13:33 ` Jean-Christophe PLAGNIOL-VILLARD
2008-05-30 21:58   ` Sergey Lapin
2008-05-24 15:24 ` Haavard Skinnemoen
2008-05-29 21:56   ` Sergey Lapin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox