All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH RFC] at91sam9/at91cap: move common initialisation to cpu
@ 2008-11-07 19:38 Jean-Christophe PLAGNIOL-VILLARD
  2008-11-13 21:28 ` Stelian Pop
  2009-02-05 21:38 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 2 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2008-11-07 19:38 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
The idea is to reduce common code initialisation which is actually in board.
as done on afeb9260 and Ronetix eval board for 9260 & 9263

Best Regards,
J.
 board/afeb9260/afeb9260.c                 |   32 ++----------
 board/atmel/at91cap9adk/at91cap9adk.c     |   33 ++-----------
 board/atmel/at91sam9260ek/at91sam9260ek.c |   34 ++-----------
 board/atmel/at91sam9261ek/at91sam9261ek.c |   33 ++-----------
 board/atmel/at91sam9263ek/at91sam9263ek.c |   33 ++-----------
 board/atmel/at91sam9rlek/at91sam9rlek.c   |   33 ++-----------
 cpu/arm926ejs/at91/Makefile               |   19 +++++++-
 cpu/arm926ejs/at91/at91cap9_serial.c      |   73 +++++++++++++++++++++++++++++
 cpu/arm926ejs/at91/at91cap9_spi.c         |   41 ++++++++++++++++
 cpu/arm926ejs/at91/at91sam9260_serial.c   |   73 +++++++++++++++++++++++++++++
 cpu/arm926ejs/at91/at91sam9260_spi.c      |   42 ++++++++++++++++
 cpu/arm926ejs/at91/at91sam9261_serial.c   |   73 +++++++++++++++++++++++++++++
 cpu/arm926ejs/at91/at91sam9261_spi.c      |   41 ++++++++++++++++
 cpu/arm926ejs/at91/at91sam9263_serial.c   |   73 +++++++++++++++++++++++++++++
 cpu/arm926ejs/at91/at91sam9263_spi.c      |   41 ++++++++++++++++
 cpu/arm926ejs/at91/at91sam9rl_serial.c    |   73 +++++++++++++++++++++++++++++
 cpu/arm926ejs/at91/at91sam9rl_spi.c       |   41 ++++++++++++++++
 include/asm-arm/arch-at91/at91_common.h   |   31 ++++++++++++
 18 files changed, 656 insertions(+), 163 deletions(-)
 create mode 100644 cpu/arm926ejs/at91/at91cap9_serial.c
 create mode 100644 cpu/arm926ejs/at91/at91cap9_spi.c
 create mode 100644 cpu/arm926ejs/at91/at91sam9260_serial.c
 create mode 100644 cpu/arm926ejs/at91/at91sam9260_spi.c
 create mode 100644 cpu/arm926ejs/at91/at91sam9261_serial.c
 create mode 100644 cpu/arm926ejs/at91/at91sam9261_spi.c
 create mode 100644 cpu/arm926ejs/at91/at91sam9263_serial.c
 create mode 100644 cpu/arm926ejs/at91/at91sam9263_spi.c
 create mode 100644 cpu/arm926ejs/at91/at91sam9rl_serial.c
 create mode 100644 cpu/arm926ejs/at91/at91sam9rl_spi.c
 create mode 100644 include/asm-arm/arch-at91/at91_common.h

diff --git a/board/afeb9260/afeb9260.c b/board/afeb9260/afeb9260.c
index 32445ab..e1d52ad 100644
--- a/board/afeb9260/afeb9260.c
+++ b/board/afeb9260/afeb9260.c
@@ -27,6 +27,7 @@
 #include <asm/arch/at91sam9260.h>
 #include <asm/arch/at91sam9260_matrix.h>
 #include <asm/arch/at91sam9_smc.h>
+#include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
 #include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
@@ -47,27 +48,19 @@ DECLARE_GLOBAL_DATA_PTR;
 static void afeb9260_serial_hw_init(void)
 {
 #ifdef CONFIG_USART0
-	at91_set_A_periph(AT91_PIN_PB4, 1);		/* TXD0 */
-	at91_set_A_periph(AT91_PIN_PB5, 0);		/* RXD0 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US0);
+	at91_serial_hw_init(0);
 #endif
 
 #ifdef CONFIG_USART1
-	at91_set_A_periph(AT91_PIN_PB6, 1);		/* TXD1 */
-	at91_set_A_periph(AT91_PIN_PB7, 0);		/* RXD1 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US1);
+	at91_serial_hw_init(1);
 #endif
 
 #ifdef CONFIG_USART2
-	at91_set_A_periph(AT91_PIN_PB8, 1);		/* TXD2 */
-	at91_set_A_periph(AT91_PIN_PB9, 0);		/* RXD2 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US2);
+	at91_serial_hw_init(2);
 #endif
 
 #ifdef CONFIG_USART3	/* DBGU */
-	at91_set_A_periph(AT91_PIN_PB14, 0);		/* DRXD */
-	at91_set_A_periph(AT91_PIN_PB15, 1);		/* DTXD */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+	at91_serial_hw_init(3);
 #endif
 }
 
@@ -104,19 +97,6 @@ static void afeb9260_nand_hw_init(void)
 	at91_set_gpio_output(AT91_PIN_PC14, 1);
 }
 
-static void afeb9260_spi_hw_init(void)
-{
-	at91_set_A_periph(AT91_PIN_PA3, 0);	/* SPI0_NPCS0 */
-	at91_set_B_periph(AT91_PIN_PC11, 0);	/* SPI0_NPCS1 */
-
-	at91_set_A_periph(AT91_PIN_PA0, 0);	/* SPI0_MISO */
-	at91_set_A_periph(AT91_PIN_PA1, 0);	/* SPI0_MOSI */
-	at91_set_A_periph(AT91_PIN_PA2, 0);	/* SPI0_SPCK */
-
-	/* Enable clock */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_SPI0);
-}
-
 #ifdef CONFIG_MACB
 static void afeb9260_macb_hw_init(void)
 {
@@ -205,7 +185,7 @@ int board_init(void)
 #ifdef CONFIG_CMD_NAND
 	afeb9260_nand_hw_init();
 #endif
-	afeb9260_spi_hw_init();
+	at91_spi_hw_init();
 #ifdef CONFIG_MACB
 	afeb9260_macb_hw_init();
 #endif
diff --git a/board/atmel/at91cap9adk/at91cap9adk.c b/board/atmel/at91cap9adk/at91cap9adk.c
index f7d68b7..2d2cfe5 100644
--- a/board/atmel/at91cap9adk/at91cap9adk.c
+++ b/board/atmel/at91cap9adk/at91cap9adk.c
@@ -26,6 +26,7 @@
 #include <asm/arch/at91cap9.h>
 #include <asm/arch/at91cap9_matrix.h>
 #include <asm/arch/at91sam9_smc.h>
+#include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
 #include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
@@ -50,27 +51,19 @@ DECLARE_GLOBAL_DATA_PTR;
 static void at91cap9_serial_hw_init(void)
 {
 #ifdef CONFIG_USART0
-	at91_set_A_periph(AT91_PIN_PA22, 1);		/* TXD0 */
-	at91_set_A_periph(AT91_PIN_PA23, 0);		/* RXD0 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US0);
+	at91_serial_hw_init(0);
 #endif
 
 #ifdef CONFIG_USART1
-	at91_set_A_periph(AT91_PIN_PD0, 1);		/* TXD1 */
-	at91_set_A_periph(AT91_PIN_PD1, 0);		/* RXD1 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US1);
+	at91_serial_hw_init(1);
 #endif
 
 #ifdef CONFIG_USART2
-	at91_set_A_periph(AT91_PIN_PD2, 1);		/* TXD2 */
-	at91_set_A_periph(AT91_PIN_PD3, 0);		/* RXD2 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US2);
+	at91_serial_hw_init(2);
 #endif
 
 #ifdef CONFIG_USART3	/* DBGU */
-	at91_set_A_periph(AT91_PIN_PC30, 0);		/* DRXD */
-	at91_set_A_periph(AT91_PIN_PC31, 1);		/* DTXD */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+	at91_serial_hw_init(3);
 #endif
 }
 
@@ -163,20 +156,6 @@ static void at91cap9_nand_hw_init(void)
 }
 #endif
 
-#ifdef CONFIG_HAS_DATAFLASH
-static void at91cap9_spi_hw_init(void)
-{
-	at91_set_B_periph(AT91_PIN_PA5, 0);	/* SPI0_NPCS0 */
-
-	at91_set_B_periph(AT91_PIN_PA0, 0);	/* SPI0_MISO */
-	at91_set_B_periph(AT91_PIN_PA1, 0);	/* SPI0_MOSI */
-	at91_set_B_periph(AT91_PIN_PA2, 0);	/* SPI0_SPCK */
-
-	/* Enable clock */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_SPI0);
-}
-#endif
-
 #ifdef CONFIG_MACB
 static void at91cap9_macb_hw_init(void)
 {
@@ -374,7 +353,7 @@ int board_init(void)
 	at91cap9_nand_hw_init();
 #endif
 #ifdef CONFIG_HAS_DATAFLASH
-	at91cap9_spi_hw_init();
+	at91_spi_hw_init();
 #endif
 #ifdef CONFIG_MACB
 	at91cap9_macb_hw_init();
diff --git a/board/atmel/at91sam9260ek/at91sam9260ek.c b/board/atmel/at91sam9260ek/at91sam9260ek.c
index ef99b8b..b51e8dc 100644
--- a/board/atmel/at91sam9260ek/at91sam9260ek.c
+++ b/board/atmel/at91sam9260ek/at91sam9260ek.c
@@ -26,6 +26,7 @@
 #include <asm/arch/at91sam9260.h>
 #include <asm/arch/at91sam9260_matrix.h>
 #include <asm/arch/at91sam9_smc.h>
+#include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
 #include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
@@ -46,27 +47,19 @@ DECLARE_GLOBAL_DATA_PTR;
 static void at91sam9260ek_serial_hw_init(void)
 {
 #ifdef CONFIG_USART0
-	at91_set_A_periph(AT91_PIN_PB4, 1);		/* TXD0 */
-	at91_set_A_periph(AT91_PIN_PB5, 0);		/* RXD0 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US0);
+	at91_serial_hw_init(0);
 #endif
 
 #ifdef CONFIG_USART1
-	at91_set_A_periph(AT91_PIN_PB6, 1);		/* TXD1 */
-	at91_set_A_periph(AT91_PIN_PB7, 0);		/* RXD1 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US1);
+	at91_serial_hw_init(1);
 #endif
 
 #ifdef CONFIG_USART2
-	at91_set_A_periph(AT91_PIN_PB8, 1);		/* TXD2 */
-	at91_set_A_periph(AT91_PIN_PB9, 0);		/* RXD2 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US2);
+	at91_serial_hw_init(2);
 #endif
 
 #ifdef CONFIG_USART3	/* DBGU */
-	at91_set_A_periph(AT91_PIN_PB14, 0);		/* DRXD */
-	at91_set_A_periph(AT91_PIN_PB15, 1);		/* DTXD */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+	at91_serial_hw_init(3);
 #endif
 }
 
@@ -109,21 +102,6 @@ static void at91sam9260ek_nand_hw_init(void)
 }
 #endif
 
-#ifdef CONFIG_HAS_DATAFLASH
-static void at91sam9260ek_spi_hw_init(void)
-{
-	at91_set_A_periph(AT91_PIN_PA3, 0);	/* SPI0_NPCS0 */
-	at91_set_B_periph(AT91_PIN_PC11, 0);	/* SPI0_NPCS1 */
-
-	at91_set_A_periph(AT91_PIN_PA0, 0);	/* SPI0_MISO */
-	at91_set_A_periph(AT91_PIN_PA1, 0);	/* SPI0_MOSI */
-	at91_set_A_periph(AT91_PIN_PA2, 0);	/* SPI0_SPCK */
-
-	/* Enable clock */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_SPI0);
-}
-#endif
-
 #ifdef CONFIG_MACB
 static void at91sam9260ek_macb_hw_init(void)
 {
@@ -222,7 +200,7 @@ int board_init(void)
 	at91sam9260ek_nand_hw_init();
 #endif
 #ifdef CONFIG_HAS_DATAFLASH
-	at91sam9260ek_spi_hw_init();
+	at91_spi_hw_init();
 #endif
 #ifdef CONFIG_MACB
 	at91sam9260ek_macb_hw_init();
diff --git a/board/atmel/at91sam9261ek/at91sam9261ek.c b/board/atmel/at91sam9261ek/at91sam9261ek.c
index 14f236d..82dffde 100644
--- a/board/atmel/at91sam9261ek/at91sam9261ek.c
+++ b/board/atmel/at91sam9261ek/at91sam9261ek.c
@@ -26,6 +26,7 @@
 #include <asm/arch/at91sam9261.h>
 #include <asm/arch/at91sam9261_matrix.h>
 #include <asm/arch/at91sam9_smc.h>
+#include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
 #include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
@@ -46,27 +47,19 @@ DECLARE_GLOBAL_DATA_PTR;
 static void at91sam9261ek_serial_hw_init(void)
 {
 #ifdef CONFIG_USART0
-	at91_set_A_periph(AT91_PIN_PC8, 1);		/* TXD0 */
-	at91_set_A_periph(AT91_PIN_PC9, 0);		/* RXD0 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_US0);
+	at91_serial_hw_init(0);
 #endif
 
 #ifdef CONFIG_USART1
-	at91_set_A_periph(AT91_PIN_PC12, 1);		/* TXD1 */
-	at91_set_A_periph(AT91_PIN_PC13, 0);		/* RXD1 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_US1);
+	at91_serial_hw_init(1);
 #endif
 
 #ifdef CONFIG_USART2
-	at91_set_A_periph(AT91_PIN_PC14, 1);		/* TXD2 */
-	at91_set_A_periph(AT91_PIN_PC15, 0);		/* RXD2 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_US2);
+	at91_serial_hw_init(2);
 #endif
 
 #ifdef CONFIG_USART3	/* DBGU */
-	at91_set_A_periph(AT91_PIN_PA9, 0);		/* DRXD */
-	at91_set_A_periph(AT91_PIN_PA10, 1);		/* DTXD */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+	at91_serial_hw_init(3);
 #endif
 }
 
@@ -112,20 +105,6 @@ static void at91sam9261ek_nand_hw_init(void)
 }
 #endif
 
-#ifdef CONFIG_HAS_DATAFLASH
-static void at91sam9261ek_spi_hw_init(void)
-{
-	at91_set_A_periph(AT91_PIN_PA3, 0);	/* SPI0_NPCS0 */
-
-	at91_set_A_periph(AT91_PIN_PA0, 0);	/* SPI0_MISO */
-	at91_set_A_periph(AT91_PIN_PA1, 0);	/* SPI0_MOSI */
-	at91_set_A_periph(AT91_PIN_PA2, 0);	/* SPI0_SPCK */
-
-	/* Enable clock */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_SPI0);
-}
-#endif
-
 #ifdef CONFIG_DRIVER_DM9000
 static void at91sam9261ek_dm9000_hw_init(void)
 {
@@ -255,7 +234,7 @@ int board_init(void)
 	at91sam9261ek_nand_hw_init();
 #endif
 #ifdef CONFIG_HAS_DATAFLASH
-	at91sam9261ek_spi_hw_init();
+	at91_spi_hw_init();
 #endif
 #ifdef CONFIG_DRIVER_DM9000
 	at91sam9261ek_dm9000_hw_init();
diff --git a/board/atmel/at91sam9263ek/at91sam9263ek.c b/board/atmel/at91sam9263ek/at91sam9263ek.c
index ebd4649..872a369 100644
--- a/board/atmel/at91sam9263ek/at91sam9263ek.c
+++ b/board/atmel/at91sam9263ek/at91sam9263ek.c
@@ -27,6 +27,7 @@
 #include <asm/arch/at91sam9263.h>
 #include <asm/arch/at91sam9263_matrix.h>
 #include <asm/arch/at91sam9_smc.h>
+#include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
 #include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
@@ -49,27 +50,19 @@ DECLARE_GLOBAL_DATA_PTR;
 static void at91sam9263ek_serial_hw_init(void)
 {
 #ifdef CONFIG_USART0
-	at91_set_A_periph(AT91_PIN_PA26, 1);		/* TXD0 */
-	at91_set_A_periph(AT91_PIN_PA27, 0);		/* RXD0 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_US0);
+	at91_serial_hw_init(0);
 #endif
 
 #ifdef CONFIG_USART1
-	at91_set_A_periph(AT91_PIN_PD0, 1);		/* TXD1 */
-	at91_set_A_periph(AT91_PIN_PD1, 0);		/* RXD1 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_US1);
+	at91_serial_hw_init(1);
 #endif
 
 #ifdef CONFIG_USART2
-	at91_set_A_periph(AT91_PIN_PD2, 1);		/* TXD2 */
-	at91_set_A_periph(AT91_PIN_PD3, 0);		/* RXD2 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_US2);
+	at91_serial_hw_init(2);
 #endif
 
 #ifdef CONFIG_USART3	/* DBGU */
-	at91_set_A_periph(AT91_PIN_PC30, 0);		/* DRXD */
-	at91_set_A_periph(AT91_PIN_PC31, 1);		/* DTXD */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+	at91_serial_hw_init(3);
 #endif
 }
 
@@ -113,20 +106,6 @@ static void at91sam9263ek_nand_hw_init(void)
 }
 #endif
 
-#ifdef CONFIG_HAS_DATAFLASH
-static void at91sam9263ek_spi_hw_init(void)
-{
-	at91_set_B_periph(AT91_PIN_PA5, 0);	/* SPI0_NPCS0 */
-
-	at91_set_B_periph(AT91_PIN_PA0, 0);	/* SPI0_MISO */
-	at91_set_B_periph(AT91_PIN_PA1, 0);	/* SPI0_MOSI */
-	at91_set_B_periph(AT91_PIN_PA2, 0);	/* SPI0_SPCK */
-
-	/* Enable clock */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_SPI0);
-}
-#endif
-
 #ifdef CONFIG_MACB
 static void at91sam9263ek_macb_hw_init(void)
 {
@@ -306,7 +285,7 @@ int board_init(void)
 	at91sam9263ek_nand_hw_init();
 #endif
 #ifdef CONFIG_HAS_DATAFLASH
-	at91sam9263ek_spi_hw_init();
+	at91_spi_hw_init();
 #endif
 #ifdef CONFIG_MACB
 	at91sam9263ek_macb_hw_init();
diff --git a/board/atmel/at91sam9rlek/at91sam9rlek.c b/board/atmel/at91sam9rlek/at91sam9rlek.c
index b6fef9d..b42565f 100644
--- a/board/atmel/at91sam9rlek/at91sam9rlek.c
+++ b/board/atmel/at91sam9rlek/at91sam9rlek.c
@@ -26,6 +26,7 @@
 #include <asm/arch/at91sam9rl.h>
 #include <asm/arch/at91sam9rl_matrix.h>
 #include <asm/arch/at91sam9_smc.h>
+#include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
 #include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
@@ -46,27 +47,19 @@ DECLARE_GLOBAL_DATA_PTR;
 static void at91sam9rlek_serial_hw_init(void)
 {
 #ifdef CONFIG_USART0
-	at91_set_A_periph(AT91_PIN_PA6, 1);		/* TXD0 */
-	at91_set_A_periph(AT91_PIN_PA7, 0);		/* RXD0 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9RL_ID_US0);
+	at91_serial_hw_init(0);
 #endif
 
 #ifdef CONFIG_USART1
-	at91_set_A_periph(AT91_PIN_PA11, 1);		/* TXD1 */
-	at91_set_A_periph(AT91_PIN_PA12, 0);		/* RXD1 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9RL_ID_US1);
+	at91_serial_hw_init(1);
 #endif
 
 #ifdef CONFIG_USART2
-	at91_set_A_periph(AT91_PIN_PA13, 1);		/* TXD2 */
-	at91_set_A_periph(AT91_PIN_PA14, 0);		/* RXD2 */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9RL_ID_US2);
+	at91_serial_hw_init(2);
 #endif
 
 #ifdef CONFIG_USART3	/* DBGU */
-	at91_set_A_periph(AT91_PIN_PA21, 0);		/* DRXD */
-	at91_set_A_periph(AT91_PIN_PA22, 1);		/* DTXD */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+	at91_serial_hw_init(3);
 #endif
 }
 
@@ -112,20 +105,6 @@ static void at91sam9rlek_nand_hw_init(void)
 }
 #endif
 
-#ifdef CONFIG_HAS_DATAFLASH
-static void at91sam9rlek_spi_hw_init(void)
-{
-	at91_set_A_periph(AT91_PIN_PA28, 0);	/* SPI0_NPCS0 */
-
-	at91_set_A_periph(AT91_PIN_PA25, 0);	/* SPI0_MISO */
-	at91_set_A_periph(AT91_PIN_PA26, 0);	/* SPI0_MOSI */
-	at91_set_A_periph(AT91_PIN_PA27, 0);	/* SPI0_SPCK */
-
-	/* Enable clock */
-	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9RL_ID_SPI);
-}
-#endif
-
 #ifdef CONFIG_LCD
 vidinfo_t panel_info = {
 	vl_col:		240,
@@ -228,7 +207,7 @@ int board_init(void)
 	at91sam9rlek_nand_hw_init();
 #endif
 #ifdef CONFIG_HAS_DATAFLASH
-	at91sam9rlek_spi_hw_init();
+	at91_spi_hw_init();
 #endif
 #ifdef CONFIG_LCD
 	at91sam9rlek_lcd_hw_init();
diff --git a/cpu/arm926ejs/at91/Makefile b/cpu/arm926ejs/at91/Makefile
index 2d2a888..502271e 100644
--- a/cpu/arm926ejs/at91/Makefile
+++ b/cpu/arm926ejs/at91/Makefile
@@ -25,8 +25,25 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(SOC).a
 
+COBJS-$(CONFIG_AT91CAP9)	+= at91cap9_serial.o
+ifdef CONFIG_AT91SAM9260
+COBJS-y				+= at91sam9260_serial.o
+COBJS-$(CONFIG_HAS_DATAFLASH)	+= at91sam9260_spi.o
+endif
+ifdef CONFIG_AT91SAM9261
+COBJS-y				+= at91sam9261_serial.o
+COBJS-$(CONFIG_HAS_DATAFLASH)	+= at91sam9261_spi.o
+endif
+ifdef CONFIG_AT91SAM9263
+COBJS-y				+= at91sam9263_serial.o
+COBJS-$(CONFIG_HAS_DATAFLASH)	+= at91sam9263_spi.o
+endif
+ifdef CONFIG_AT91SAM9RL
+COBJS-y				+= at91sam9rl_serial.o
+COBJS-$(CONFIG_HAS_DATAFLASH)	+= at91sam9rl_spi.o
+endif
+COBJS-$(CONFIG_HAS_DATAFLASH)	+= spi.o
 COBJS-y	+= timer.o
-COBJS-$(CONFIG_HAS_DATAFLASH) +=spi.o
 COBJS-y	+= usb.o
 SOBJS	= lowlevel_init.o
 
diff --git a/cpu/arm926ejs/at91/at91cap9_serial.c b/cpu/arm926ejs/at91/at91cap9_serial.c
new file mode 100644
index 0000000..c7dbad9
--- /dev/null
+++ b/cpu/arm926ejs/at91/at91cap9_serial.c
@@ -0,0 +1,73 @@
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian.pop@leadtechdesign.com>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#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>
+
+int at91_serial_hw_init(int uart)
+{
+	int err = -1;
+
+	switch(uart) {
+	case 0:
+#ifdef CONFIG_USART0
+		at91_set_A_periph(AT91_PIN_PA22, 1);		/* TXD0 */
+		at91_set_A_periph(AT91_PIN_PA23, 0);		/* RXD0 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US0);
+		err = 0;
+#endif
+		break;
+	case 1:
+#ifdef CONFIG_USART1
+		at91_set_A_periph(AT91_PIN_PD0, 1);		/* TXD1 */
+		at91_set_A_periph(AT91_PIN_PD1, 0);		/* RXD1 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US1);
+		err = 0;
+#endif
+		break;
+	case 2:
+#ifdef CONFIG_USART2
+		at91_set_A_periph(AT91_PIN_PD2, 1);		/* TXD2 */
+		at91_set_A_periph(AT91_PIN_PD3, 0);		/* RXD2 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US2);
+		err = 0;
+#endif
+		break;
+	case 3:
+#ifdef CONFIG_USART3	/* DBGU */
+		at91_set_A_periph(AT91_PIN_PC30, 0);		/* DRXD */
+		at91_set_A_periph(AT91_PIN_PC31, 1);		/* DTXD */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+		err = 0;
+#endif
+		break;
+	default:
+		printf(" uart%d configuration failled\n", err);
+	}
+
+	return err;
+}
diff --git a/cpu/arm926ejs/at91/at91cap9_spi.c b/cpu/arm926ejs/at91/at91cap9_spi.c
new file mode 100644
index 0000000..2ceb6a1
--- /dev/null
+++ b/cpu/arm926ejs/at91/at91cap9_spi.c
@@ -0,0 +1,41 @@
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian.pop@leadtechdesign.com>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#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_spi_hw_init(void)
+{
+	at91_set_B_periph(AT91_PIN_PA5, 0);	/* SPI0_NPCS0 */
+
+	at91_set_B_periph(AT91_PIN_PA0, 0);	/* SPI0_MISO */
+	at91_set_B_periph(AT91_PIN_PA1, 0);	/* SPI0_MOSI */
+	at91_set_B_periph(AT91_PIN_PA2, 0);	/* SPI0_SPCK */
+
+	/* Enable clock */
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_SPI0);
+}
diff --git a/cpu/arm926ejs/at91/at91sam9260_serial.c b/cpu/arm926ejs/at91/at91sam9260_serial.c
new file mode 100644
index 0000000..4dd7c95
--- /dev/null
+++ b/cpu/arm926ejs/at91/at91sam9260_serial.c
@@ -0,0 +1,73 @@
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian.pop@leadtechdesign.com>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#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>
+
+int at91_serial_hw_init(int uart)
+{
+	int err = -1;
+
+	switch(uart) {
+	case 0:
+#ifdef CONFIG_USART0
+		at91_set_A_periph(AT91_PIN_PB4, 1);		/* TXD0 */
+		at91_set_A_periph(AT91_PIN_PB5, 0);		/* RXD0 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US0);
+		err = 0;
+#endif
+		break;
+	case 1:
+#ifdef CONFIG_USART1
+		at91_set_A_periph(AT91_PIN_PB6, 1);		/* TXD1 */
+		at91_set_A_periph(AT91_PIN_PB7, 0);		/* RXD1 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US1);
+		err = 0;
+#endif
+		break;
+	case 2:
+#ifdef CONFIG_USART2
+		at91_set_A_periph(AT91_PIN_PB8, 1);		/* TXD2 */
+		at91_set_A_periph(AT91_PIN_PB9, 0);		/* RXD2 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US2);
+		err = 0;
+#endif
+		break;
+	case 3:
+#ifdef CONFIG_USART3	/* DBGU */
+		at91_set_A_periph(AT91_PIN_PB14, 0);		/* DRXD */
+		at91_set_A_periph(AT91_PIN_PB15, 1);		/* DTXD */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+		err = 0;
+#endif
+		break;
+	default:
+		printf(" uart%d configuration failled\n", err);
+	}
+
+	return err;
+}
diff --git a/cpu/arm926ejs/at91/at91sam9260_spi.c b/cpu/arm926ejs/at91/at91sam9260_spi.c
new file mode 100644
index 0000000..fba9699
--- /dev/null
+++ b/cpu/arm926ejs/at91/at91sam9260_spi.c
@@ -0,0 +1,42 @@
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian.pop@leadtechdesign.com>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#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_spi_hw_init(void)
+{
+	at91_set_A_periph(AT91_PIN_PA3, 0);	/* SPI0_NPCS0 */
+	at91_set_B_periph(AT91_PIN_PC11, 0);	/* SPI0_NPCS1 */
+
+	at91_set_A_periph(AT91_PIN_PA0, 0);	/* SPI0_MISO */
+	at91_set_A_periph(AT91_PIN_PA1, 0);	/* SPI0_MOSI */
+	at91_set_A_periph(AT91_PIN_PA2, 0);	/* SPI0_SPCK */
+
+	/* Enable clock */
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_SPI0);
+}
diff --git a/cpu/arm926ejs/at91/at91sam9261_serial.c b/cpu/arm926ejs/at91/at91sam9261_serial.c
new file mode 100644
index 0000000..bf3c450
--- /dev/null
+++ b/cpu/arm926ejs/at91/at91sam9261_serial.c
@@ -0,0 +1,73 @@
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian.pop@leadtechdesign.com>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#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>
+
+int at91_serial_hw_init(int uart)
+{
+	int err = -1;
+
+	switch(uart) {
+	case 0:
+#ifdef CONFIG_USART0
+		at91_set_A_periph(AT91_PIN_PC8, 1);		/* TXD0 */
+		at91_set_A_periph(AT91_PIN_PC9, 0);		/* RXD0 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_US0);
+		err = 0;
+#endif
+		break;
+	case 1:
+#ifdef CONFIG_USART1
+		at91_set_A_periph(AT91_PIN_PC12, 1);		/* TXD1 */
+		at91_set_A_periph(AT91_PIN_PC13, 0);		/* RXD1 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_US1);
+		err = 0;
+#endif
+		break;
+	case 2:
+#ifdef CONFIG_USART2
+		at91_set_A_periph(AT91_PIN_PC14, 1);		/* TXD2 */
+		at91_set_A_periph(AT91_PIN_PC15, 0);		/* RXD2 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_US2);
+		err = 0;
+#endif
+		break;
+	case 3:
+#ifdef CONFIG_USART3	/* DBGU */
+		at91_set_A_periph(AT91_PIN_PA9, 0);		/* DRXD */
+		at91_set_A_periph(AT91_PIN_PA10, 1);		/* DTXD */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+		err = 0;
+#endif
+		break;
+	default:
+		printf(" uart%d configuration failled\n", err);
+	}
+
+	return err;
+}
diff --git a/cpu/arm926ejs/at91/at91sam9261_spi.c b/cpu/arm926ejs/at91/at91sam9261_spi.c
new file mode 100644
index 0000000..8eda600
--- /dev/null
+++ b/cpu/arm926ejs/at91/at91sam9261_spi.c
@@ -0,0 +1,41 @@
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian.pop@leadtechdesign.com>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#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_spi_hw_init(void)
+{
+	at91_set_A_periph(AT91_PIN_PA3, 0);	/* SPI0_NPCS0 */
+
+	at91_set_A_periph(AT91_PIN_PA0, 0);	/* SPI0_MISO */
+	at91_set_A_periph(AT91_PIN_PA1, 0);	/* SPI0_MOSI */
+	at91_set_A_periph(AT91_PIN_PA2, 0);	/* SPI0_SPCK */
+
+	/* Enable clock */
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_SPI0);
+}
diff --git a/cpu/arm926ejs/at91/at91sam9263_serial.c b/cpu/arm926ejs/at91/at91sam9263_serial.c
new file mode 100644
index 0000000..c20699a
--- /dev/null
+++ b/cpu/arm926ejs/at91/at91sam9263_serial.c
@@ -0,0 +1,73 @@
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian.pop@leadtechdesign.com>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#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>
+
+int at91_serial_hw_init(int uart)
+{
+	int err = -1;
+
+	switch(uart) {
+	case 0:
+#ifdef CONFIG_USART0
+		at91_set_A_periph(AT91_PIN_PA26, 1);		/* TXD0 */
+		at91_set_A_periph(AT91_PIN_PA27, 0);		/* RXD0 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_US0);
+		err = 0;
+#endif
+		break;
+	case 1:
+#ifdef CONFIG_USART1
+		at91_set_A_periph(AT91_PIN_PD0, 1);		/* TXD1 */
+		at91_set_A_periph(AT91_PIN_PD1, 0);		/* RXD1 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_US1);
+		err = 0;
+#endif
+		break;
+	case 2:
+#ifdef CONFIG_USART2
+		at91_set_A_periph(AT91_PIN_PD2, 1);		/* TXD2 */
+		at91_set_A_periph(AT91_PIN_PD3, 0);		/* RXD2 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_US2);
+		err = 0;
+#endif
+		break;
+	case 3:
+#ifdef CONFIG_USART3	/* DBGU */
+		at91_set_A_periph(AT91_PIN_PC30, 0);		/* DRXD */
+		at91_set_A_periph(AT91_PIN_PC31, 1);		/* DTXD */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+		err = 0;
+#endif
+		break;
+	default:
+		printf(" uart%d configuration failled\n", err);
+	}
+
+	return err;
+}
diff --git a/cpu/arm926ejs/at91/at91sam9263_spi.c b/cpu/arm926ejs/at91/at91sam9263_spi.c
new file mode 100644
index 0000000..b01541c
--- /dev/null
+++ b/cpu/arm926ejs/at91/at91sam9263_spi.c
@@ -0,0 +1,41 @@
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian.pop@leadtechdesign.com>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#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_spi_hw_init(void)
+{
+	at91_set_B_periph(AT91_PIN_PA5, 0);	/* SPI0_NPCS0 */
+
+	at91_set_B_periph(AT91_PIN_PA0, 0);	/* SPI0_MISO */
+	at91_set_B_periph(AT91_PIN_PA1, 0);	/* SPI0_MOSI */
+	at91_set_B_periph(AT91_PIN_PA2, 0);	/* SPI0_SPCK */
+
+	/* Enable clock */
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_SPI0);
+}
diff --git a/cpu/arm926ejs/at91/at91sam9rl_serial.c b/cpu/arm926ejs/at91/at91sam9rl_serial.c
new file mode 100644
index 0000000..0effb8d
--- /dev/null
+++ b/cpu/arm926ejs/at91/at91sam9rl_serial.c
@@ -0,0 +1,73 @@
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian.pop@leadtechdesign.com>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#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>
+
+int at91_serial_hw_init(int uart)
+{
+	int err = -1;
+
+	switch(uart) {
+	case 0:
+#ifdef CONFIG_USART0
+		at91_set_A_periph(AT91_PIN_PA6, 1);		/* TXD0 */
+		at91_set_A_periph(AT91_PIN_PA7, 0);		/* RXD0 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9RL_ID_US0);
+		err = 0;
+#endif
+		break;
+	case 1:
+#ifdef CONFIG_USART1
+		at91_set_A_periph(AT91_PIN_PA11, 1);		/* TXD1 */
+		at91_set_A_periph(AT91_PIN_PA12, 0);		/* RXD1 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9RL_ID_US1);
+		err = 0;
+#endif
+		break;
+	case 2:
+#ifdef CONFIG_USART2
+		at91_set_A_periph(AT91_PIN_PA13, 1);		/* TXD2 */
+		at91_set_A_periph(AT91_PIN_PA14, 0);		/* RXD2 */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9RL_ID_US2);
+		err = 0;
+#endif
+		break;
+	case 3:
+#ifdef CONFIG_USART3	/* DBGU */
+		at91_set_A_periph(AT91_PIN_PA21, 0);		/* DRXD */
+		at91_set_A_periph(AT91_PIN_PA22, 1);		/* DTXD */
+		at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+		err = 0;
+#endif
+		break;
+	default:
+		printf(" uart%d configuration failled\n", err);
+	}
+
+	return err;
+}
diff --git a/cpu/arm926ejs/at91/at91sam9rl_spi.c b/cpu/arm926ejs/at91/at91sam9rl_spi.c
new file mode 100644
index 0000000..8196092
--- /dev/null
+++ b/cpu/arm926ejs/at91/at91sam9rl_spi.c
@@ -0,0 +1,41 @@
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian.pop@leadtechdesign.com>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#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_spi_hw_init(void)
+{
+	at91_set_A_periph(AT91_PIN_PA28, 0);	/* SPI0_NPCS0 */
+
+	at91_set_A_periph(AT91_PIN_PA25, 0);	/* SPI0_MISO */
+	at91_set_A_periph(AT91_PIN_PA26, 0);	/* SPI0_MOSI */
+	at91_set_A_periph(AT91_PIN_PA27, 0);	/* SPI0_SPCK */
+
+	/* Enable clock */
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9RL_ID_SPI);
+}
diff --git a/include/asm-arm/arch-at91/at91_common.h b/include/asm-arm/arch-at91/at91_common.h
new file mode 100644
index 0000000..507e4d3
--- /dev/null
+++ b/include/asm-arm/arch-at91/at91_common.h
@@ -0,0 +1,31 @@
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian.pop@leadtechdesign.com>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef AT91_COMMON_H
+#define AT91_COMMON_H
+
+int at91_serial_hw_init(int uart);
+void at91_spi_hw_init(void);
+
+#endif /* AT91_COMMON_H */
-- 
1.5.6.5

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

* [U-Boot] [PATCH RFC] at91sam9/at91cap: move common initialisation to cpu
  2008-11-07 19:38 [U-Boot] [PATCH RFC] at91sam9/at91cap: move common initialisation to cpu Jean-Christophe PLAGNIOL-VILLARD
@ 2008-11-13 21:28 ` Stelian Pop
  2008-11-13 22:32   ` Jean-Christophe PLAGNIOL-VILLARD
  2008-11-16 12:28   ` Remy Bohmer
  2009-02-05 21:38 ` Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 2 replies; 6+ messages in thread
From: Stelian Pop @ 2008-11-13 21:28 UTC (permalink / raw)
  To: u-boot

Le vendredi 07 novembre 2008 ? 20:38 +0100, Jean-Christophe
PLAGNIOL-VILLARD a ?crit :

> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> The idea is to reduce common code initialisation which is actually in board.
> as done on afeb9260 and Ronetix eval board for 9260 & 9263

[...]

I agree with the general idea of moving the serial and spi from board
specific files to the cpu specific files.

Note however that serial and spi are not the only initialisations that
can be moved: the very same thing can be done with all the other device
initialisations. Some devices will need to specify which GPIOs are used
when it's board specific, and this can be passed as arguments to the cpu
specfic function. One can look at the Linux kernel files which nicely
separates the cpu specific GPIOs (in arch/arm/mach-at91/XXX_devices.c)
and the board specific GPIOs (in arch/arm/mach-at91/board-YYY.c). Or one
can also RTFM of course.

I also don't like this:

> --- a/board/atmel/at91cap9adk/at91cap9adk.c
> +++ b/board/atmel/at91cap9adk/at91cap9adk.c

>  #ifdef CONFIG_USART0
> -	at91_set_A_periph(AT91_PIN_PA22, 1);		/* TXD0 */
> -	at91_set_A_periph(AT91_PIN_PA23, 0);		/* RXD0 */
> -	at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US0);
> +	at91_serial_hw_init(0);
>  #endif

Why don't just do at91_serial_hw_init() once, and test the CONFIG_USART*
inside the cpu specific at91_serial_hw_init function() ?

This also eliminates that unneeded switch case in that function.

Stelian.
-- 
Stelian Pop <stelian@popies.net>

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

* [U-Boot] [PATCH RFC] at91sam9/at91cap: move common initialisation to cpu
  2008-11-13 21:28 ` Stelian Pop
@ 2008-11-13 22:32   ` Jean-Christophe PLAGNIOL-VILLARD
  2008-11-14  9:17     ` Stelian Pop
  2008-11-16 12:28   ` Remy Bohmer
  1 sibling, 1 reply; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2008-11-13 22:32 UTC (permalink / raw)
  To: u-boot

On 22:28 Thu 13 Nov     , Stelian Pop wrote:
> Le vendredi 07 novembre 2008 ? 20:38 +0100, Jean-Christophe
> PLAGNIOL-VILLARD a ?crit :
> 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> > The idea is to reduce common code initialisation which is actually in board.
> > as done on afeb9260 and Ronetix eval board for 9260 & 9263
> 
> [...]
> 
> I agree with the general idea of moving the serial and spi from board
> specific files to the cpu specific files.
> 
> Note however that serial and spi are not the only initialisations that
> can be moved: the very same thing can be done with all the other device
> initialisations.
I've just put serial & spi for the RFC

> Some devices will need to specify which GPIOs are used
> when it's board specific, and this can be passed as arguments to the cpu
> specfic function. One can look at the Linux kernel files which nicely
> separates the cpu specific GPIOs (in arch/arm/mach-at91/XXX_devices.c)
> and the board specific GPIOs (in arch/arm/mach-at91/board-YYY.c).
This the idea

> 
> I also don't like this:
> 
> > --- a/board/atmel/at91cap9adk/at91cap9adk.c
> > +++ b/board/atmel/at91cap9adk/at91cap9adk.c
> 
> >  #ifdef CONFIG_USART0
> > -	at91_set_A_periph(AT91_PIN_PA22, 1);		/* TXD0 */
> > -	at91_set_A_periph(AT91_PIN_PA23, 0);		/* RXD0 */
> > -	at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US0);
> > +	at91_serial_hw_init(0);
> >  #endif
> 
> Why don't just do at91_serial_hw_init() once, and test the CONFIG_USART*
> inside the cpu specific at91_serial_hw_init function() ?
> 
> This also eliminates that unneeded switch case in that function.
The idea is too allow multiple serial at the same time.

I've plan to add the multi serial support to the at91 serial drivers

Best Regards,
J.

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

* [U-Boot] [PATCH RFC] at91sam9/at91cap: move common initialisation to cpu
  2008-11-13 22:32   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2008-11-14  9:17     ` Stelian Pop
  0 siblings, 0 replies; 6+ messages in thread
From: Stelian Pop @ 2008-11-14  9:17 UTC (permalink / raw)
  To: u-boot

Le jeudi 13 novembre 2008 ? 23:32 +0100, Jean-Christophe
PLAGNIOL-VILLARD a ?crit :

> > Note however that serial and spi are not the only initialisations that
> > can be moved: the very same thing can be done with all the other device
> > initialisations.
> I've just put serial & spi for the RFC

Ok then.

[...]

> > Why don't just do at91_serial_hw_init() once, and test the CONFIG_USART*
> > inside the cpu specific at91_serial_hw_init function() ?
> > 
> > This also eliminates that unneeded switch case in that function.
> The idea is too allow multiple serial at the same time.
> 
> I've plan to add the multi serial support to the at91 serial drivers

I'm not sure exactly what you mean by "multi serial support" but isn't
this orthogonal to what I'm saying (putting the #ifdef CONFIG_USART0
inside the cpu specific file instead of board specific file) ?

Stelian.
-- 
Stelian Pop <stelian@popies.net>

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

* [U-Boot] [PATCH RFC] at91sam9/at91cap: move common initialisation to cpu
  2008-11-13 21:28 ` Stelian Pop
  2008-11-13 22:32   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2008-11-16 12:28   ` Remy Bohmer
  1 sibling, 0 replies; 6+ messages in thread
From: Remy Bohmer @ 2008-11-16 12:28 UTC (permalink / raw)
  To: u-boot

Hello Stelian and Jean-Christophe,

> I agree with the general idea of moving the serial and spi from board
> specific files to the cpu specific files.

I agree partly on this, but I do not like with the way this patch is
doing it, and this is the reason why:
PIN multiplexing is board specific, not only SoC specific. pins can be
multiplexed in different ways per board per SoC.
In this patch all this 'knowledge' is moved to the generic SoC code,
where the assumption is made that all boards use the same pin layout.
This is _not_ true; in the generic code is, for example(!!), assumed
that all 9261 SoC derived boards only configure NPCS0, while a board
can utilise all NPCS pins and can have multiple dataflashes.
It may be true that all boards, currently existing in U-boot, use a
similar pin layout per SoC, but that does not mean that that is a
valid assumption for all future boards. The framework should be that
flexible that boards that are currently not in mainline can be added
in the future, without reverting patches like this, or creating
standalone copies from this framework. We should make it easier for
others to integrate their custom boards, instead of making it
harder...
The current code makes it very easy to create custom boards, this
patch makes that harder!

So, in short: pin layout must be specified by the board specific
files, not by the generic SoC code, although the generic SoC code can
provide (all) the possible options to choose from...

Kind Regards,

Remy



>
> Note however that serial and spi are not the only initialisations that
> can be moved: the very same thing can be done with all the other device
> initialisations. Some devices will need to specify which GPIOs are used
> when it's board specific, and this can be passed as arguments to the cpu
> specfic function. One can look at the Linux kernel files which nicely
> separates the cpu specific GPIOs (in arch/arm/mach-at91/XXX_devices.c)
> and the board specific GPIOs (in arch/arm/mach-at91/board-YYY.c). Or one
> can also RTFM of course.
>
> I also don't like this:
>
>> --- a/board/atmel/at91cap9adk/at91cap9adk.c
>> +++ b/board/atmel/at91cap9adk/at91cap9adk.c
>
>>  #ifdef CONFIG_USART0
>> -     at91_set_A_periph(AT91_PIN_PA22, 1);            /* TXD0 */
>> -     at91_set_A_periph(AT91_PIN_PA23, 0);            /* RXD0 */
>> -     at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US0);
>> +     at91_serial_hw_init(0);
>>  #endif
>
> Why don't just do at91_serial_hw_init() once, and test the CONFIG_USART*
> inside the cpu specific at91_serial_hw_init function() ?
>
> This also eliminates that unneeded switch case in that function.
>
> Stelian.
> --
> Stelian Pop <stelian@popies.net>
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
>

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

* [U-Boot] [PATCH RFC] at91sam9/at91cap: move common initialisation to cpu
  2008-11-07 19:38 [U-Boot] [PATCH RFC] at91sam9/at91cap: move common initialisation to cpu Jean-Christophe PLAGNIOL-VILLARD
  2008-11-13 21:28 ` Stelian Pop
@ 2009-02-05 21:38 ` Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2009-02-05 21:38 UTC (permalink / raw)
  To: u-boot

On 20:38 Fri 07 Nov     , Jean-Christophe PLAGNIOL-VILLARD wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
The idea is to reduce common code initialisation which is actually in board.
as done on afeb9260 and Ronetix eval board for 9260 & 9263

Any help to improve and continue this work is welcome

Best Regards,
J.

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

end of thread, other threads:[~2009-02-05 21:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-07 19:38 [U-Boot] [PATCH RFC] at91sam9/at91cap: move common initialisation to cpu Jean-Christophe PLAGNIOL-VILLARD
2008-11-13 21:28 ` Stelian Pop
2008-11-13 22:32   ` Jean-Christophe PLAGNIOL-VILLARD
2008-11-14  9:17     ` Stelian Pop
2008-11-16 12:28   ` Remy Bohmer
2009-02-05 21:38 ` Jean-Christophe PLAGNIOL-VILLARD

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.