[U-Boot] [PATCH 12/13] at91: add hardware i2c drivers

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Fri Mar 27 23:30:25 CET 2009


Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 cpu/arm926ejs/at91/Makefile                        |    6 +
 .../arm926ejs/at91/at91cap9_i2c.c                  |   31 ++--
 .../arm926ejs/at91/at91sam9260_i2c.c               |   31 ++--
 .../arm926ejs/at91/at91sam9261_i2c.c               |   31 ++--
 .../arm926ejs/at91/at91sam9263_i2c.c               |   31 ++--
 .../clk.h => cpu/arm926ejs/at91/at91sam9rl_i2c.c   |   37 ++--
 drivers/i2c/Makefile                               |    1 +
 drivers/i2c/atmel_i2c.c                            |  234 ++++++++++++++++++++
 include/asm-arm/arch-at91/at91_common.h            |    2 +
 include/asm-arm/arch-at91/at91_twi.h               |   68 ++++++
 include/asm-arm/arch-at91/clk.h                    |    4 +
 include/asm-arm/arch-at91/hardware.h               |    5 +
 12 files changed, 405 insertions(+), 76 deletions(-)
 copy include/asm-arm/arch-at91/at91_common.h => cpu/arm926ejs/at91/at91cap9_i2c.c (61%)
 copy include/asm-arm/arch-at91/at91_common.h => cpu/arm926ejs/at91/at91sam9260_i2c.c (61%)
 copy include/asm-arm/arch-at91/at91_common.h => cpu/arm926ejs/at91/at91sam9261_i2c.c (61%)
 copy include/asm-arm/arch-at91/at91_common.h => cpu/arm926ejs/at91/at91sam9263_i2c.c (61%)
 copy include/asm-arm/arch-at91/clk.h => cpu/arm926ejs/at91/at91sam9rl_i2c.c (52%)
 create mode 100644 drivers/i2c/atmel_i2c.c
 create mode 100644 include/asm-arm/arch-at91/at91_twi.h

diff --git a/cpu/arm926ejs/at91/Makefile b/cpu/arm926ejs/at91/Makefile
index 34e7461..d37814f 100644
--- a/cpu/arm926ejs/at91/Makefile
+++ b/cpu/arm926ejs/at91/Makefile
@@ -26,31 +26,37 @@ include $(TOPDIR)/config.mk
 LIB	= $(obj)lib$(SOC).a
 
 ifdef CONFIG_AT91CAP9
+COBJS-$(CONFIG_HARD_I2C)	+= at91cap9_i2c.o
 COBJS-$(CONFIG_MACB)		+= at91cap9_macb.o
 COBJS-y				+= at91cap9_serial.o
 COBJS-$(CONFIG_HAS_DATAFLASH)	+= at91cap9_spi.o
 endif
 ifdef CONFIG_AT91SAM9260
+COBJS-$(CONFIG_HARD_I2C)	+= at91sam9260_i2c.o
 COBJS-$(CONFIG_MACB)		+= at91sam9260_macb.o
 COBJS-y				+= at91sam9260_serial.o
 COBJS-$(CONFIG_HAS_DATAFLASH)	+= at91sam9260_spi.o
 endif
 ifdef CONFIG_AT91SAM9G20
+COBJS-$(CONFIG_HARD_I2C)	+= at91sam9260_i2c.o
 COBJS-$(CONFIG_MACB)		+= at91sam9260_macb.o
 COBJS-y				+= at91sam9260_serial.o
 COBJS-$(CONFIG_HAS_DATAFLASH)	+= at91sam9260_spi.o
 endif
 ifdef CONFIG_AT91SAM9261
+COBJS-$(CONFIG_HARD_I2C)	+= at91sam9261_i2c.o
 COBJS-y				+= at91sam9261_serial.o
 COBJS-$(CONFIG_HAS_DATAFLASH)	+= at91sam9261_spi.o
 endif
 ifdef CONFIG_AT91SAM9263
+COBJS-$(CONFIG_HARD_I2C)	+= at91sam9263_i2c.o
 COBJS-$(CONFIG_MACB)		+= at91sam9263_macb.o
 COBJS-y				+= at91sam9263_serial.o
 COBJS-$(CONFIG_HAS_DATAFLASH)	+= at91sam9263_spi.o
 COBJS-$(CONFIG_USB_OHCI_NEW)	+= at91sam9263_usb.o
 endif
 ifdef CONFIG_AT91SAM9RL
+COBJS-$(CONFIG_HARD_I2C)	+= at91sam9rl_i2c.o
 COBJS-y				+= at91sam9rl_serial.o
 COBJS-$(CONFIG_HAS_DATAFLASH)	+= at91sam9rl_spi.o
 endif
diff --git a/include/asm-arm/arch-at91/at91_common.h b/cpu/arm926ejs/at91/at91cap9_i2c.c
similarity index 61%
copy from include/asm-arm/arch-at91/at91_common.h
copy to cpu/arm926ejs/at91/at91cap9_i2c.c
index 9c4e019..feb65bf 100644
--- a/include/asm-arm/arch-at91/at91_common.h
+++ b/cpu/arm926ejs/at91/at91cap9_i2c.c
@@ -1,7 +1,6 @@
 /*
- * (C) Copyright 2007-2008
- * Stelian Pop <stelian.pop at leadtechdesign.com>
- * Lead Tech Design <www.leadtechdesign.com>
+ * (C) Copyright 2009
+ * Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
  *
  * See file CREDITS for list of people who contributed to this
  * project.
@@ -22,17 +21,19 @@
  * MA 02111-1307 USA
  */
 
-#ifndef AT91_COMMON_H
-#define AT91_COMMON_H
+#include <common.h>
+#include <asm/arch/at91_common.h>
+#include <asm/arch/at91_pmc.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/io.h>
 
-void at91_macb_hw_init(void);
-void at91_serial_hw_init(void);
-void at91_serial0_hw_init(void);
-void at91_serial1_hw_init(void);
-void at91_serial2_hw_init(void);
-void at91_serial3_hw_init(void);
-void at91_spi0_hw_init(unsigned long cs_mask);
-void at91_spi1_hw_init(unsigned long cs_mask);
-void at91_uhp_hw_init(void);
+void at91_twi0_hw_init(void)
+{
+	at91_set_B_periph(AT91_PIN_PB4, 0);	/* TWD */
+	at91_set_multi_drive(AT91_PIN_PB4, 1);
 
-#endif /* AT91_COMMON_H */
+	at91_set_5_periph(AT91_PIN_PB5, 0);	/* TWCK */
+	at91_set_multi_drive(AT91_PIN_PB5, 1);
+
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_TWI);
+}
diff --git a/include/asm-arm/arch-at91/at91_common.h b/cpu/arm926ejs/at91/at91sam9260_i2c.c
similarity index 61%
copy from include/asm-arm/arch-at91/at91_common.h
copy to cpu/arm926ejs/at91/at91sam9260_i2c.c
index 9c4e019..ff8659f 100644
--- a/include/asm-arm/arch-at91/at91_common.h
+++ b/cpu/arm926ejs/at91/at91sam9260_i2c.c
@@ -1,7 +1,6 @@
 /*
- * (C) Copyright 2007-2008
- * Stelian Pop <stelian.pop at leadtechdesign.com>
- * Lead Tech Design <www.leadtechdesign.com>
+ * (C) Copyright 2009
+ * Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
  *
  * See file CREDITS for list of people who contributed to this
  * project.
@@ -22,17 +21,19 @@
  * MA 02111-1307 USA
  */
 
-#ifndef AT91_COMMON_H
-#define AT91_COMMON_H
+#include <common.h>
+#include <asm/arch/at91_common.h>
+#include <asm/arch/at91_pmc.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/io.h>
 
-void at91_macb_hw_init(void);
-void at91_serial_hw_init(void);
-void at91_serial0_hw_init(void);
-void at91_serial1_hw_init(void);
-void at91_serial2_hw_init(void);
-void at91_serial3_hw_init(void);
-void at91_spi0_hw_init(unsigned long cs_mask);
-void at91_spi1_hw_init(unsigned long cs_mask);
-void at91_uhp_hw_init(void);
+void at91_twi0_hw_init(void)
+{
+	at91_set_A_periph(AT91_PIN_PA23, 0);	/* TWD */
+	at91_set_multi_drive(AT91_PIN_PA23, 1);
 
-#endif /* AT91_COMMON_H */
+	at91_set_A_periph(AT91_PIN_PA24, 0);	/* TWCK */
+	at91_set_multi_drive(AT91_PIN_PA24, 1);
+
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_TWI);
+}
diff --git a/include/asm-arm/arch-at91/at91_common.h b/cpu/arm926ejs/at91/at91sam9261_i2c.c
similarity index 61%
copy from include/asm-arm/arch-at91/at91_common.h
copy to cpu/arm926ejs/at91/at91sam9261_i2c.c
index 9c4e019..5873e10 100644
--- a/include/asm-arm/arch-at91/at91_common.h
+++ b/cpu/arm926ejs/at91/at91sam9261_i2c.c
@@ -1,7 +1,6 @@
 /*
- * (C) Copyright 2007-2008
- * Stelian Pop <stelian.pop at leadtechdesign.com>
- * Lead Tech Design <www.leadtechdesign.com>
+ * (C) Copyright 2009
+ * Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
  *
  * See file CREDITS for list of people who contributed to this
  * project.
@@ -22,17 +21,19 @@
  * MA 02111-1307 USA
  */
 
-#ifndef AT91_COMMON_H
-#define AT91_COMMON_H
+#include <common.h>
+#include <asm/arch/at91_common.h>
+#include <asm/arch/at91_pmc.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/io.h>
 
-void at91_macb_hw_init(void);
-void at91_serial_hw_init(void);
-void at91_serial0_hw_init(void);
-void at91_serial1_hw_init(void);
-void at91_serial2_hw_init(void);
-void at91_serial3_hw_init(void);
-void at91_spi0_hw_init(unsigned long cs_mask);
-void at91_spi1_hw_init(unsigned long cs_mask);
-void at91_uhp_hw_init(void);
+void at91_twi0_hw_init(void)
+{
+	at91_set_A_periph(AT91_PIN_PA7, 0);	/* TWD */
+	at91_set_multi_drive(AT91_PIN_PA7, 1);
 
-#endif /* AT91_COMMON_H */
+	at91_set_A_periph(AT91_PIN_PA8, 0);	/* TWCK */
+	at91_set_multi_drive(AT91_PIN_PA8, 1);
+
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_TWI);
+}
diff --git a/include/asm-arm/arch-at91/at91_common.h b/cpu/arm926ejs/at91/at91sam9263_i2c.c
similarity index 61%
copy from include/asm-arm/arch-at91/at91_common.h
copy to cpu/arm926ejs/at91/at91sam9263_i2c.c
index 9c4e019..e8f63ad 100644
--- a/include/asm-arm/arch-at91/at91_common.h
+++ b/cpu/arm926ejs/at91/at91sam9263_i2c.c
@@ -1,7 +1,6 @@
 /*
- * (C) Copyright 2007-2008
- * Stelian Pop <stelian.pop at leadtechdesign.com>
- * Lead Tech Design <www.leadtechdesign.com>
+ * (C) Copyright 2009
+ * Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
  *
  * See file CREDITS for list of people who contributed to this
  * project.
@@ -22,17 +21,19 @@
  * MA 02111-1307 USA
  */
 
-#ifndef AT91_COMMON_H
-#define AT91_COMMON_H
+#include <common.h>
+#include <asm/arch/at91_common.h>
+#include <asm/arch/at91_pmc.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/io.h>
 
-void at91_macb_hw_init(void);
-void at91_serial_hw_init(void);
-void at91_serial0_hw_init(void);
-void at91_serial1_hw_init(void);
-void at91_serial2_hw_init(void);
-void at91_serial3_hw_init(void);
-void at91_spi0_hw_init(unsigned long cs_mask);
-void at91_spi1_hw_init(unsigned long cs_mask);
-void at91_uhp_hw_init(void);
+void at91_twi0_hw_init(void)
+{
+	at91_set_A_periph(AT91_PIN_PB4, 0);	/* TWD */
+	at91_set_multi_drive(AT91_PIN_PB4, 1);
 
-#endif /* AT91_COMMON_H */
+	at91_set_A_periph(AT91_PIN_PB5, 0);	/* TWCK */
+	at91_set_multi_drive(AT91_PIN_PB5, 1);
+
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_TWI);
+}
diff --git a/include/asm-arm/arch-at91/clk.h b/cpu/arm926ejs/at91/at91sam9rl_i2c.c
similarity index 52%
copy from include/asm-arm/arch-at91/clk.h
copy to cpu/arm926ejs/at91/at91sam9rl_i2c.c
index 1b502c8..f12f0fd 100644
--- a/include/asm-arm/arch-at91/clk.h
+++ b/cpu/arm926ejs/at91/at91sam9rl_i2c.c
@@ -1,7 +1,6 @@
 /*
- * (C) Copyright 2007
- * Stelian Pop <stelian.pop at leadtechdesign.com>
- * Lead Tech Design <www.leadtechdesign.com>
+ * (C) Copyright 2009
+ * Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
  *
  * See file CREDITS for list of people who contributed to this
  * project.
@@ -21,25 +20,31 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  * MA 02111-1307 USA
  */
-#ifndef __ASM_ARM_ARCH_CLK_H__
-#define __ASM_ARM_ARCH_CLK_H__
 
-#include <asm/arch/hardware.h>
+#include <common.h>
+#include <asm/arch/at91_common.h>
+#include <asm/arch/at91_pmc.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/io.h>
 
-static inline unsigned long get_macb_pclk_rate(unsigned int dev_id)
+void at91_twi0_hw_init(void)
 {
-	return AT91_MASTER_CLOCK;
-}
+	at91_set_A_periph(AT91_PIN_PA23, 0);	/* TWD */
+	at91_set_multi_drive(AT91_PIN_PA23, 1);
 
-static inline unsigned long get_usart_clk_rate(unsigned int dev_id)
-{
-	return AT91_MASTER_CLOCK;
+	at91_set_A_periph(AT91_PIN_PA24, 0);	/* TWCK */
+	at91_set_multi_drive(AT91_PIN_PA24, 1);
+
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9RL_ID_TWI0);
 }
 
-static inline unsigned long get_lcdc_clk_rate(unsigned int dev_id)
+void at91_twi1_hw_init(void)
 {
-	return AT91_MASTER_CLOCK;
-}
+	at91_set_A_periph(AT91_PIN_PD10, 0);	/* TWD */
+	at91_set_multi_drive(AT91_PIN_PD10, 1);
 
+	at91_set_A_periph(AT91_PIN_PD11, 0);	/* TWCK */
+	at91_set_multi_drive(AT91_PIN_PD11, 1);
 
-#endif /* __ASM_ARM_ARCH_CLK_H__ */
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9RL_ID_TWI1);
+}
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 9c74657..27a5251 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libi2c.a
 
+COBJS-$(CONFIG_I2C_ATMEL) += atmel_i2c.o
 COBJS-$(CONFIG_BFIN_TWI_I2C) += bfin-twi_i2c.o
 COBJS-$(CONFIG_FSL_I2C) += fsl_i2c.o
 COBJS-$(CONFIG_I2C_MXC) += mxc_i2c.o
diff --git a/drivers/i2c/atmel_i2c.c b/drivers/i2c/atmel_i2c.c
new file mode 100644
index 0000000..b4c5530
--- /dev/null
+++ b/drivers/i2c/atmel_i2c.c
@@ -0,0 +1,234 @@
+/*
+ *  i2c Support for Atmel's AT91RM9200 Two-Wire Interface
+ *
+ *  (c) Rick Bronson
+ *
+ *  Borrowed heavily from original work by:
+ *  Copyright (c) 2000 Philip Edelbrock <phil at stimpy.netroedge.com>
+ *
+ *  Modified to work with u-boot by (C) 2004 Gary Jennejohn garyj at denx.de
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+*/
+#include <common.h>
+
+#ifdef CONFIG_HARD_I2C
+
+#include <i2c.h>
+#include <asm/io.h>
+#include <asm/arch/hardware.h>
+#include <asm/arch/at91_twi.h>
+#include <asm/arch/clk.h>
+
+#define TWI_CLOCK		100000		/* Hz. max 400 Kbits/sec */
+
+#define at91_twi_read(reg)		__raw_readl(AT91_BASE_TWI + (reg))
+#define at91_twi_write(reg, val)	__raw_writel((val), AT91_BASE_TWI + (reg))
+/* define DEBUG */
+
+/*
+ * Poll the i2c status register until the specified bit is set.
+ * Returns 0 if timed out (100 msec)
+ */
+static short at91_poll_status(unsigned long bit)
+{
+	int loop_cntr = 10000;
+
+	do {
+		udelay(10);
+	} while (!(at91_twi_read(AT91_TWI_SR) & bit) && (--loop_cntr > 0));
+
+	return (loop_cntr > 0);
+}
+
+static int xfer_read(unsigned char *buf, int length)
+{
+	/* Send Start */
+	at91_twi_write(AT91_TWI_CR, AT91_TWI_START);
+
+	/* Read data */
+	while (length--) {
+		if (!length)	/* need to send Stop before reading last byte */
+			at91_twi_write(AT91_TWI_CR, AT91_TWI_STOP);
+		if (!at91_poll_status(AT91_TWI_RXRDY)) {
+			debug("at91_i2c: RXRDY timeout\n");
+			return 1;
+		}
+		*buf++ = (at91_twi_read(AT91_TWI_RHR) & 0xff);
+	}
+
+	return 0;
+}
+
+static int xfer_write(unsigned char *buf, int length)
+{
+	/* Load first byte into transmitter */
+	at91_twi_write(AT91_TWI_THR, *buf++);
+
+	/* Send Start */
+	at91_twi_write(AT91_TWI_CR, AT91_TWI_START);
+
+	do {
+		if (!at91_poll_status(AT91_TWI_TXRDY)) {
+			debug ("at91_i2c: TXRDY timeout\n");
+			return 1;
+		}
+
+		length--;	/* byte was transmitted */
+
+		if (length > 0)		/* more data to send? */
+			at91_twi_write(AT91_TWI_THR, *buf++);
+	} while (length);
+
+	/* Send Stop */
+	at91_twi_write(AT91_TWI_CR, AT91_TWI_STOP);
+
+	return 0;
+}
+
+/*
+ * Generic i2c master transfer entrypoint
+ *
+ * rw == 1 means that this is a read
+ */
+static int at91_xfer(unsigned char chip, unsigned int addr, int alen,
+		     unsigned char *buffer, int len, int rw)
+{
+	int length;
+	int ret = -1;
+	unsigned char *buf;
+
+	/* Set the TWI Master Mode Register */
+	at91_twi_write(AT91_TWI_MMR, (chip << 16) | (alen << 8)
+				    | ((rw == 1) ? AT91_TWI_MREAD : 0));
+
+	/* Set TWI Internal Address Register with first messages data field */
+	if (alen > 0)
+		at91_twi_write(AT91_TWI_IADR, addr);
+
+	length = len;
+	buf = buffer;
+	if (length && buf) {	/* sanity check */
+		if (rw)
+			ret = xfer_read(buf, len);
+		else
+			ret = xfer_write(buf, len);
+	}
+
+	return ret;
+}
+
+int
+i2c_probe(unsigned char chip)
+{
+	unsigned char buffer[1];
+
+	return at91_xfer(chip, 0, 0, buffer, 1, 1);
+}
+
+int
+i2c_read (unsigned char chip, unsigned int addr, int alen,
+	  unsigned char *buffer, int len)
+{
+#ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW
+	/* we only allow one address byte */
+	if (alen > 1)
+		return 1;
+	/* XXX assume an ATMEL AT24C16 */
+	if (alen == 1) {
+#if 0 /* EEPROM code already sets this correctly */
+		chip |= (addr >> 8) & 0xff;
+#endif
+		addr = addr & 0xff;
+	}
+#endif
+	return at91_xfer(chip, addr, alen, buffer, len, 1);
+}
+
+int
+i2c_write(unsigned char chip, unsigned int addr, int alen,
+	  unsigned char *buffer, int len)
+{
+#ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW
+	int i;
+	unsigned char *buf;
+
+	/* we only allow one address byte */
+	if (alen > 1)
+		return 1;
+	/* XXX assume an ATMEL AT24C16 */
+	if (alen == 1) {
+		buf = buffer;
+		/* do single byte writes */
+		for (i = 0; i < len; i++) {
+#if 0 /* EEPROM code already sets this correctly */
+			chip |= (addr >> 8) & 0xff;
+#endif
+			addr = addr & 0xff;
+			if (at91_xfer(chip, addr, alen, buf++, 1, 0))
+				return 1;
+			addr++;
+		}
+		return 0;
+	}
+#endif
+	return at91_xfer(chip, addr, alen, buffer, len, 0);
+}
+
+/*
+ * Main initialization routine
+ */
+void i2c_init(int speed, int slaveaddr)
+{
+	unsigned long cdiv, ckdiv;
+
+	at91_twi_write(AT91_TWI_IDR, 0xffffffff);	/* Disable all interrupts */
+	at91_twi_write(AT91_TWI_CR, AT91_TWI_SWRST);	/* Reset peripheral */
+	at91_twi_write(AT91_TWI_CR, AT91_TWI_MSEN);	/* Set Master mode */
+
+	/* Calcuate clock dividers */
+	cdiv = (get_twi_clk_rate(0) / (2 * TWI_CLOCK)) - 3;
+	cdiv = cdiv + 1;	/* round up */
+	ckdiv = 0;
+	while (cdiv > 255) {
+		ckdiv++;
+		cdiv = cdiv >> 1;
+	}
+
+#ifdef CONFIG_AT91RM9200
+	if (ckdiv > 5) {
+		printf("AT91 I2C: Invalid TWI_CLOCK value!\n");
+		ckdiv = 5;
+	}
+#endif
+
+	at91_twi_write(AT91_TWI_CWGR, (ckdiv << 16) | (cdiv << 8) | cdiv);
+
+	debug ("Found AT91 i2c\n");
+	return;
+}
+
+int i2c_set_bus_speed(unsigned int speed)
+{
+	return -1;
+}
+
+unsigned int i2c_get_bus_speed(void)
+{
+	return CONFIG_SYS_I2C_SPEED;
+}
+
+#endif /* CONFIG_HARD_I2C */
diff --git a/include/asm-arm/arch-at91/at91_common.h b/include/asm-arm/arch-at91/at91_common.h
index 9c4e019..43a5e07 100644
--- a/include/asm-arm/arch-at91/at91_common.h
+++ b/include/asm-arm/arch-at91/at91_common.h
@@ -33,6 +33,8 @@ void at91_serial2_hw_init(void);
 void at91_serial3_hw_init(void);
 void at91_spi0_hw_init(unsigned long cs_mask);
 void at91_spi1_hw_init(unsigned long cs_mask);
+void at91_twi0_hw_init(void);
+void at91_twi1_hw_init(void);
 void at91_uhp_hw_init(void);
 
 #endif /* AT91_COMMON_H */
diff --git a/include/asm-arm/arch-at91/at91_twi.h b/include/asm-arm/arch-at91/at91_twi.h
new file mode 100644
index 0000000..bb2880f
--- /dev/null
+++ b/include/asm-arm/arch-at91/at91_twi.h
@@ -0,0 +1,68 @@
+/*
+ * arch/arm/mach-at91/include/mach/at91_twi.h
+ *
+ * Copyright (C) 2005 Ivan Kokshaysky
+ * Copyright (C) SAN People
+ *
+ * Two-wire Interface (TWI) registers.
+ * Based on AT91RM9200 datasheet revision E.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef AT91_TWI_H
+#define AT91_TWI_H
+
+#define	AT91_TWI_CR		0x00		/* Control Register */
+#define		AT91_TWI_START		(1 <<  0)	/* Send a Start Condition */
+#define		AT91_TWI_STOP		(1 <<  1)	/* Send a Stop Condition */
+#define		AT91_TWI_MSEN		(1 <<  2)	/* Master Transfer Enable */
+#define		AT91_TWI_MSDIS		(1 <<  3)	/* Master Transfer Disable */
+#define		AT91_TWI_SVEN		(1 <<  4)	/* Slave Transfer Enable [SAM9260 only] */
+#define		AT91_TWI_SVDIS		(1 <<  5)	/* Slave Transfer Disable [SAM9260 only] */
+#define		AT91_TWI_SWRST		(1 <<  7)	/* Software Reset */
+
+#define	AT91_TWI_MMR		0x04		/* Master Mode Register */
+#define		AT91_TWI_IADRSZ		(3    <<  8)	/* Internal Device Address Size */
+#define			AT91_TWI_IADRSZ_NO		(0 << 8)
+#define			AT91_TWI_IADRSZ_1		(1 << 8)
+#define			AT91_TWI_IADRSZ_2		(2 << 8)
+#define			AT91_TWI_IADRSZ_3		(3 << 8)
+#define		AT91_TWI_MREAD		(1    << 12)	/* Master Read Direction */
+#define		AT91_TWI_DADR		(0x7f << 16)	/* Device Address */
+
+#define	AT91_TWI_SMR		0x08		/* Slave Mode Register [SAM9260 only] */
+#define		AT91_TWI_SADR		(0x7f << 16)	/* Slave Address */
+
+#define	AT91_TWI_IADR		0x0c		/* Internal Address Register */
+
+#define	AT91_TWI_CWGR		0x10		/* Clock Waveform Generator Register */
+#define		AT91_TWI_CLDIV		(0xff <<  0)	/* Clock Low Divisor */
+#define		AT91_TWI_CHDIV		(0xff <<  8)	/* Clock High Divisor */
+#define		AT91_TWI_CKDIV		(7    << 16)	/* Clock Divider */
+
+#define	AT91_TWI_SR		0x20		/* Status Register */
+#define		AT91_TWI_TXCOMP		(1 <<  0)	/* Transmission Complete */
+#define		AT91_TWI_RXRDY		(1 <<  1)	/* Receive Holding Register Ready */
+#define		AT91_TWI_TXRDY		(1 <<  2)	/* Transmit Holding Register Ready */
+#define		AT91_TWI_SVREAD		(1 <<  3)	/* Slave Read [SAM9260 only] */
+#define		AT91_TWI_SVACC		(1 <<  4)	/* Slave Access [SAM9260 only] */
+#define		AT91_TWI_GACC		(1 <<  5)	/* General Call Access [SAM9260 only] */
+#define		AT91_TWI_OVRE		(1 <<  6)	/* Overrun Error [AT91RM9200 only] */
+#define		AT91_TWI_UNRE		(1 <<  7)	/* Underrun Error [AT91RM9200 only] */
+#define		AT91_TWI_NACK		(1 <<  8)	/* Not Acknowledged */
+#define		AT91_TWI_ARBLST		(1 <<  9)	/* Arbitration Lost [SAM9260 only] */
+#define		AT91_TWI_SCLWS		(1 << 10)	/* Clock Wait State [SAM9260 only] */
+#define		AT91_TWI_EOSACC		(1 << 11)	/* End of Slave Address [SAM9260 only] */
+
+#define	AT91_TWI_IER		0x24		/* Interrupt Enable Register */
+#define	AT91_TWI_IDR		0x28		/* Interrupt Disable Register */
+#define	AT91_TWI_IMR		0x2c		/* Interrupt Mask Register */
+#define	AT91_TWI_RHR		0x30		/* Receive Holding Register */
+#define	AT91_TWI_THR		0x34		/* Transmit Holding Register */
+
+#endif
+
diff --git a/include/asm-arm/arch-at91/clk.h b/include/asm-arm/arch-at91/clk.h
index 1b502c8..85ab68e 100644
--- a/include/asm-arm/arch-at91/clk.h
+++ b/include/asm-arm/arch-at91/clk.h
@@ -41,5 +41,9 @@ static inline unsigned long get_lcdc_clk_rate(unsigned int dev_id)
 	return AT91_MASTER_CLOCK;
 }
 
+static inline unsigned long get_twi_clk_rate(unsigned int dev_id)
+{
+	return AT91_MASTER_CLOCK;
+}
 
 #endif /* __ASM_ARM_ARCH_CLK_H__ */
diff --git a/include/asm-arm/arch-at91/hardware.h b/include/asm-arm/arch-at91/hardware.h
index 4f0e1a7..f34071c 100644
--- a/include/asm-arm/arch-at91/hardware.h
+++ b/include/asm-arm/arch-at91/hardware.h
@@ -21,25 +21,30 @@
 #elif defined(CONFIG_AT91SAM9260) || defined(CONFIG_AT91SAM9G20)
 #include <asm/arch/at91sam9260.h>
 #define AT91_BASE_SPI	AT91SAM9260_BASE_SPI0
+#define AT91_BASE_TWI	AT91SAM9260_BASE_TWI
 #define AT91_ID_UHP	AT91SAM9260_ID_UHP
 #define AT91_PMC_UHP	AT91SAM926x_PMC_UHP
 #elif defined(CONFIG_AT91SAM9261)
 #include <asm/arch/at91sam9261.h>
 #define AT91_BASE_SPI	AT91SAM9261_BASE_SPI0
+#define AT91_BASE_TWI	AT91SAM9261_BASE_TWI
 #define AT91_ID_UHP	AT91SAM9261_ID_UHP
 #define AT91_PMC_UHP	AT91SAM926x_PMC_UHP
 #elif defined(CONFIG_AT91SAM9263)
 #include <asm/arch/at91sam9263.h>
 #define AT91_BASE_SPI	AT91SAM9263_BASE_SPI0
+#define AT91_BASE_TWI	AT91SAM9263_BASE_TWI
 #define AT91_ID_UHP	AT91SAM9263_ID_UHP
 #define AT91_PMC_UHP	AT91SAM926x_PMC_UHP
 #elif defined(CONFIG_AT91SAM9RL)
 #include <asm/arch/at91sam9rl.h>
 #define AT91_BASE_SPI	AT91SAM9RL_BASE_SPI
+#define AT91_BASE_TWI	AT91SAM9RL_BASE_TWI
 #define AT91_ID_UHP	AT91SAM9RL_ID_UHP
 #elif defined(CONFIG_AT91CAP9)
 #include <asm/arch/at91cap9.h>
 #define AT91_BASE_SPI	AT91CAP9_BASE_SPI0
+#define AT91_BASE_TWI	AT91CAP9_BASE_TWI
 #define AT91_ID_UHP	AT91CAP9_ID_UHP
 #define AT91_PMC_UHP	AT91CAP9_PMC_UHP
 #elif defined(CONFIG_AT91X40)
-- 
1.6.2.1



More information about the U-Boot mailing list