From ab0df36fc7db9dda0b786b909f653e279dfeb9cf Mon Sep 17 00:00:00 2001 From: Haavard Skinnemoen Date: Fri, 29 Aug 2008 21:09:49 +0200 Subject: avr32: refactor the portmux/gpio code - Separate the portmux configuration functionality from the GPIO pin control API. - Separate the controller-specific code from the chip-specific code. - Allow "ganged" port configuration (multiple pins at once). - Add more flexibility to the "canned" peripheral select functions: - Allow using more than 23 address bits, more chip selects, as well as NAND- and CF-specific pins. - Make the MACB SPEED pin optional, and choose between MII/RMII using a parameter instead of an #ifdef. - Make it possible to use other MMC slots than slot 0, and support different MMC/SDCard data bus widths. - Use more reasonable pull-up defaults; floating pins may consume a lot of power. - Get rid of some custom portmux code from the mimc200 board code. The old gpio/portmux API couldn't really handle its requirements, but the new one can. - Add documentation. The end result is slightly smaller code for all boards. Which isn't really the point, but at least it isn't any larger. This has been verified on ATSTK1002 and ATNGW100. I'd appreciate if the board maintainers could help me test this on their boards. In particular, the mimc200 port has lost a lot of code, so I'm hoping Mark can help me out. Signed-off-by: Haavard Skinnemoen Cc: Hans-Christian Egtvedt Cc: Mark Jackson Cc: Alex Raimondi Cc: Julien May Changes since v1: * Enable pullup on NWAIT * Add missing include to portmux-pio.h * Rename CONFIG_PIO2 -> CONFIG_PORTMUX_PIO to match docs --- board/miromico/hammerhead/hammerhead.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'board/miromico') diff --git a/board/miromico/hammerhead/hammerhead.c b/board/miromico/hammerhead/hammerhead.c index 738ece2fe3..3d6cf9b28b 100644 --- a/board/miromico/hammerhead/hammerhead.c +++ b/board/miromico/hammerhead/hammerhead.c @@ -29,9 +29,9 @@ #include #include #include -#include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -65,14 +65,14 @@ int board_early_init_f(void) /* Enable SDRAM in the EBI mux */ hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE)); - gpio_enable_ebi(); - gpio_enable_usart1(); + portmux_enable_ebi(32, 23, 0, PORTMUX_DRIVE_HIGH); + portmux_enable_usart1(PORTMUX_DRIVE_MIN); #if defined(CONFIG_MACB) - gpio_enable_macb0(); + portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH); #endif #if defined(CONFIG_MMC) - gpio_enable_mmci(); + portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW); #endif return 0; } @@ -107,7 +107,7 @@ void gclk_init(void) /* Hammerhead boards uses GCLK3 as 25MHz output to ethernet PHY */ /* Select GCLK3 peripheral function */ - gpio_select_periph_A(GPIO_PIN_PB29, 0); + portmux_select_peripheral(PORTMUX_PORT_B, 1 << 29, PORTMUX_FUNC_A, 0); /* Enable GCLK3 with no input divider, from OSC0 (crystal) */ sm_writel(PM_GCCTRL(3), SM_BIT(CEN)); -- cgit v1.2.1 From abdde2b1d570b1ee77606bf783444fcddf7f0965 Mon Sep 17 00:00:00 2001 From: Haavard Skinnemoen Date: Sun, 31 Aug 2008 18:07:35 +0200 Subject: hammerhead: Use gclk helper functions Use the new gclk helper functions to set up the PHY clock instead of accessing the PM registers directly. Signed-off-by: Haavard Skinnemoen --- board/miromico/hammerhead/hammerhead.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'board/miromico') diff --git a/board/miromico/hammerhead/hammerhead.c b/board/miromico/hammerhead/hammerhead.c index 3d6cf9b28b..bf432cba85 100644 --- a/board/miromico/hammerhead/hammerhead.c +++ b/board/miromico/hammerhead/hammerhead.c @@ -22,8 +22,6 @@ * MA 02111-1307 USA */ -#include "../cpu/at32ap/at32ap700x/sm.h" - #include #include @@ -105,10 +103,6 @@ void board_init_info(void) void gclk_init(void) { /* Hammerhead boards uses GCLK3 as 25MHz output to ethernet PHY */ - - /* Select GCLK3 peripheral function */ - portmux_select_peripheral(PORTMUX_PORT_B, 1 << 29, PORTMUX_FUNC_A, 0); - - /* Enable GCLK3 with no input divider, from OSC0 (crystal) */ - sm_writel(PM_GCCTRL(3), SM_BIT(CEN)); + gclk_enable_output(3, PORTMUX_DRIVE_LOW); + gclk_set_rate(3, GCLK_PARENT_OSC0, 25000000); } -- cgit v1.2.1 From 36d375faf5cff98e8dca32aabbbb1ec6036437dd Mon Sep 17 00:00:00 2001 From: Haavard Skinnemoen Date: Sun, 31 Aug 2008 18:24:24 +0200 Subject: avr32: Use board_postclk_init instead of gclk_init Replace the avr32-specific gclk_init() board hook with the standard board_postclk_init() hook which is supposed to run at the same point during initialization. Provide a dummy weak alias for boards not implementing this hook. The cost of this is: - 2 bytes for the dummy function (retal 0) - 2 bytes for each unnecessary function call (short rcall) which is a pretty small price to pay for avoiding lots of #ifdef clutter. In this particular case, all boards probably end up slightly smaller because we avoid the conditional checking if the gclk_init symbol is NULL. Signed-off-by: Haavard Skinnemoen --- board/miromico/hammerhead/hammerhead.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'board/miromico') diff --git a/board/miromico/hammerhead/hammerhead.c b/board/miromico/hammerhead/hammerhead.c index bf432cba85..8670527891 100644 --- a/board/miromico/hammerhead/hammerhead.c +++ b/board/miromico/hammerhead/hammerhead.c @@ -100,9 +100,10 @@ void board_init_info(void) gd->bd->bi_phy_id[0] = 0x01; } -void gclk_init(void) +int board_postclk_init(void) { /* Hammerhead boards uses GCLK3 as 25MHz output to ethernet PHY */ gclk_enable_output(3, PORTMUX_DRIVE_LOW); gclk_set_rate(3, GCLK_PARENT_OSC0, 25000000); + return 0; } -- cgit v1.2.1 From 25e6854d42c11046a468576179b5494f850311b2 Mon Sep 17 00:00:00 2001 From: Haavard Skinnemoen Date: Sun, 31 Aug 2008 18:46:35 +0200 Subject: avr32: use board_early_init_r instead of board_init_info Replace the avr32-specific board_init_info hook by the standard board_early_init_r hook and make it optional. board_early_init_r() runs somewhat earlier than board_init_info used to do, but this isn't a problem for any of the in-tree boards. Signed-off-by: Haavard Skinnemoen --- board/miromico/hammerhead/hammerhead.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'board/miromico') diff --git a/board/miromico/hammerhead/hammerhead.c b/board/miromico/hammerhead/hammerhead.c index 8670527891..7fd0781254 100644 --- a/board/miromico/hammerhead/hammerhead.c +++ b/board/miromico/hammerhead/hammerhead.c @@ -95,9 +95,10 @@ phys_size_t initdram(int board_type) return actual_size; } -void board_init_info(void) +int board_early_init_r(void) { gd->bd->bi_phy_id[0] = 0x01; + return 0; } int board_postclk_init(void) -- cgit v1.2.1