Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007-2008 |
Stelian Pop | 567fb85 | 2008-05-08 22:52:09 +0200 | [diff] [blame] | 3 | * Stelian Pop <stelian.pop@leadtechdesign.com> |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 4 | * Lead Tech Design <www.leadtechdesign.com> |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <common.h> |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 26 | #include <asm/arch/at91cap9.h> |
| 27 | #include <asm/arch/at91cap9_matrix.h> |
Stelian Pop | 4f6c810 | 2008-05-08 20:52:10 +0200 | [diff] [blame^] | 28 | #include <asm/arch/at91sam9_smc.h> |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 29 | #include <asm/arch/at91_pmc.h> |
| 30 | #include <asm/arch/at91_rstc.h> |
| 31 | #include <asm/arch/gpio.h> |
| 32 | #include <asm/arch/io.h> |
Jean-Christophe PLAGNIOL-VILLARD | 64d7920 | 2008-02-17 14:15:30 +0100 | [diff] [blame] | 33 | #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB) |
| 34 | #include <net.h> |
| 35 | #endif |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 36 | |
| 37 | #define MP_BLOCK_3_BASE 0xFDF00000 |
| 38 | |
| 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
| 41 | /* ------------------------------------------------------------------------- */ |
| 42 | /* |
| 43 | * Miscelaneous platform dependent initialisations |
| 44 | */ |
| 45 | |
| 46 | static void at91cap9_serial_hw_init(void) |
| 47 | { |
| 48 | #ifdef CONFIG_USART0 |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 49 | at91_set_A_periph(AT91_PIN_PA22, 1); /* TXD0 */ |
| 50 | at91_set_A_periph(AT91_PIN_PA23, 0); /* RXD0 */ |
| 51 | at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US0); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 52 | #endif |
| 53 | |
| 54 | #ifdef CONFIG_USART1 |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 55 | at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */ |
| 56 | at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */ |
| 57 | at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US1); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
| 60 | #ifdef CONFIG_USART2 |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 61 | at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */ |
| 62 | at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */ |
| 63 | at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US2); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 64 | #endif |
| 65 | |
| 66 | #ifdef CONFIG_USART3 /* DBGU */ |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 67 | at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */ |
| 68 | at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */ |
| 69 | at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 70 | #endif |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static void at91cap9_nor_hw_init(void) |
| 74 | { |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 75 | unsigned long csa; |
| 76 | |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 77 | /* Ensure EBI supply is 3.3V */ |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 78 | csa = at91_sys_read(AT91_MATRIX_EBICSA); |
| 79 | at91_sys_write(AT91_MATRIX_EBICSA, |
| 80 | csa | AT91_MATRIX_EBI_VDDIOMSEL_3_3V); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 81 | /* Configure SMC CS0 for parallel flash */ |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 82 | at91_sys_write(AT91_SMC_SETUP(0), |
| 83 | AT91_SMC_NWESETUP_(4) | AT91_SMC_NCS_WRSETUP_(2) | |
| 84 | AT91_SMC_NRDSETUP_(4) | AT91_SMC_NCS_RDSETUP_(2)); |
| 85 | at91_sys_write(AT91_SMC_PULSE(0), |
| 86 | AT91_SMC_NWEPULSE_(8) | AT91_SMC_NCS_WRPULSE_(10) | |
| 87 | AT91_SMC_NRDPULSE_(8) | AT91_SMC_NCS_RDPULSE_(10)); |
| 88 | at91_sys_write(AT91_SMC_CYCLE(0), |
| 89 | AT91_SMC_NWECYCLE_(16) | AT91_SMC_NRDCYCLE_(16)); |
| 90 | at91_sys_write(AT91_SMC_MODE(0), |
| 91 | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | |
| 92 | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE | |
| 93 | AT91_SMC_DBW_16 | AT91_SMC_TDF_(1)); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | #ifdef CONFIG_CMD_NAND |
| 97 | static void at91cap9_nand_hw_init(void) |
| 98 | { |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 99 | unsigned long csa; |
| 100 | |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 101 | /* Enable CS3 */ |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 102 | csa = at91_sys_read(AT91_MATRIX_EBICSA); |
| 103 | at91_sys_write(AT91_MATRIX_EBICSA, |
| 104 | csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA | |
| 105 | AT91_MATRIX_EBI_VDDIOMSEL_3_3V); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 106 | |
| 107 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 108 | at91_sys_write(AT91_SMC_SETUP(3), |
| 109 | AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(1) | |
| 110 | AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(1)); |
| 111 | at91_sys_write(AT91_SMC_PULSE(3), |
| 112 | AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(6) | |
| 113 | AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(6)); |
| 114 | at91_sys_write(AT91_SMC_CYCLE(3), |
| 115 | AT91_SMC_NWECYCLE_(8) | AT91_SMC_NRDCYCLE_(8)); |
| 116 | at91_sys_write(AT91_SMC_MODE(3), |
| 117 | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | |
| 118 | AT91_SMC_EXNWMODE_DISABLE | |
| 119 | AT91_SMC_DBW_8 | AT91_SMC_TDF_(1)); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 120 | |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 121 | at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_PIOABCD); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 122 | |
| 123 | /* RDY/BSY is not connected */ |
| 124 | |
| 125 | /* Enable NandFlash */ |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 126 | at91_set_gpio_output(AT91_PIN_PD15, 1); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 127 | } |
| 128 | #endif |
| 129 | |
| 130 | #ifdef CONFIG_HAS_DATAFLASH |
| 131 | static void at91cap9_spi_hw_init(void) |
| 132 | { |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 133 | at91_set_B_periph(AT91_PIN_PA5, 0); /* SPI0_NPCS0 */ |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 134 | |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 135 | at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */ |
| 136 | at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */ |
| 137 | at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */ |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 138 | |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 139 | /* Enable clock */ |
| 140 | at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_SPI0); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 141 | } |
| 142 | #endif |
| 143 | |
| 144 | #ifdef CONFIG_MACB |
| 145 | static void at91cap9_macb_hw_init(void) |
| 146 | { |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 147 | /* Enable clock */ |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 148 | at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_EMAC); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 149 | |
| 150 | /* |
| 151 | * Disable pull-up on: |
| 152 | * RXDV (PB22) => PHY normal mode (not Test mode) |
| 153 | * ERX0 (PB25) => PHY ADDR0 |
| 154 | * ERX1 (PB26) => PHY ADDR1 => PHYADDR = 0x0 |
| 155 | * |
| 156 | * PHY has internal pull-down |
| 157 | */ |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 158 | writel(pin_to_mask(AT91_PIN_PB22) | |
| 159 | pin_to_mask(AT91_PIN_PB25) | |
| 160 | pin_to_mask(AT91_PIN_PB26), |
| 161 | pin_to_controller(AT91_PIN_PA0) + PIO_PUDR); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 162 | |
| 163 | /* Need to reset PHY -> 500ms reset */ |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 164 | at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY | |
| 165 | AT91_RSTC_ERSTL | (0x0D << 8) | |
| 166 | AT91_RSTC_URSTEN); |
| 167 | |
| 168 | at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 169 | |
| 170 | /* Wait for end hardware reset */ |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 171 | while (!(at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_NRSTL)); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 172 | |
| 173 | /* Re-enable pull-up */ |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 174 | writel(pin_to_mask(AT91_PIN_PB22) | |
| 175 | pin_to_mask(AT91_PIN_PB25) | |
| 176 | pin_to_mask(AT91_PIN_PB26), |
| 177 | pin_to_controller(AT91_PIN_PA0) + PIO_PUER); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 178 | |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 179 | at91_set_A_periph(AT91_PIN_PB21, 0); /* ETXCK_EREFCK */ |
| 180 | at91_set_A_periph(AT91_PIN_PB22, 0); /* ERXDV */ |
| 181 | at91_set_A_periph(AT91_PIN_PB25, 0); /* ERX0 */ |
| 182 | at91_set_A_periph(AT91_PIN_PB26, 0); /* ERX1 */ |
| 183 | at91_set_A_periph(AT91_PIN_PB27, 0); /* ERXER */ |
| 184 | at91_set_A_periph(AT91_PIN_PB28, 0); /* ETXEN */ |
| 185 | at91_set_A_periph(AT91_PIN_PB23, 0); /* ETX0 */ |
| 186 | at91_set_A_periph(AT91_PIN_PB24, 0); /* ETX1 */ |
| 187 | at91_set_A_periph(AT91_PIN_PB30, 0); /* EMDIO */ |
| 188 | at91_set_A_periph(AT91_PIN_PB29, 0); /* EMDC */ |
| 189 | |
| 190 | #ifndef CONFIG_RMII |
| 191 | at91_set_B_periph(AT91_PIN_PC25, 0); /* ECRS */ |
| 192 | at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */ |
| 193 | at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */ |
| 194 | at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */ |
| 195 | at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */ |
| 196 | at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */ |
| 197 | at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */ |
| 198 | at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */ |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 199 | #endif |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 200 | /* Unlock EMAC, 3 0 2 1 sequence */ |
| 201 | #define MP_MAC_KEY0 0x5969cb2a |
| 202 | #define MP_MAC_KEY1 0xb4a1872e |
| 203 | #define MP_MAC_KEY2 0x05683fbc |
| 204 | #define MP_MAC_KEY3 0x3634fba4 |
| 205 | #define UNLOCK_MAC 0x00000008 |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 206 | writel(MP_MAC_KEY3, MP_BLOCK_3_BASE + 0x3c); |
| 207 | writel(MP_MAC_KEY0, MP_BLOCK_3_BASE + 0x30); |
| 208 | writel(MP_MAC_KEY2, MP_BLOCK_3_BASE + 0x38); |
| 209 | writel(MP_MAC_KEY1, MP_BLOCK_3_BASE + 0x34); |
| 210 | writel(UNLOCK_MAC, MP_BLOCK_3_BASE + 0x40); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 211 | } |
| 212 | #endif |
| 213 | |
| 214 | #ifdef CONFIG_USB_OHCI_NEW |
| 215 | static void at91cap9_uhp_hw_init(void) |
| 216 | { |
| 217 | /* Unlock USB OHCI, 3 2 0 1 sequence */ |
| 218 | #define MP_OHCI_KEY0 0x896c11ca |
| 219 | #define MP_OHCI_KEY1 0x68ebca21 |
| 220 | #define MP_OHCI_KEY2 0x4823efbc |
| 221 | #define MP_OHCI_KEY3 0x8651aae4 |
| 222 | #define UNLOCK_OHCI 0x00000010 |
Stelian Pop | 983c1db | 2008-03-26 20:52:32 +0100 | [diff] [blame] | 223 | writel(MP_OHCI_KEY3, MP_BLOCK_3_BASE + 0x3c); |
| 224 | writel(MP_OHCI_KEY2, MP_BLOCK_3_BASE + 0x38); |
| 225 | writel(MP_OHCI_KEY0, MP_BLOCK_3_BASE + 0x30); |
| 226 | writel(MP_OHCI_KEY1, MP_BLOCK_3_BASE + 0x34); |
| 227 | writel(UNLOCK_OHCI, MP_BLOCK_3_BASE + 0x40); |
Stelian Pop | 6afcabf | 2008-02-07 16:37:54 +0000 | [diff] [blame] | 228 | } |
| 229 | #endif |
| 230 | |
| 231 | int board_init(void) |
| 232 | { |
| 233 | /* Enable Ctrlc */ |
| 234 | console_init_f(); |
| 235 | |
| 236 | /* arch number of AT91CAP9ADK-Board */ |
| 237 | gd->bd->bi_arch_number = MACH_TYPE_AT91CAP9ADK; |
| 238 | /* adress of boot parameters */ |
| 239 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 240 | |
| 241 | at91cap9_serial_hw_init(); |
| 242 | at91cap9_nor_hw_init(); |
| 243 | #ifdef CONFIG_CMD_NAND |
| 244 | at91cap9_nand_hw_init(); |
| 245 | #endif |
| 246 | #ifdef CONFIG_HAS_DATAFLASH |
| 247 | at91cap9_spi_hw_init(); |
| 248 | #endif |
| 249 | #ifdef CONFIG_MACB |
| 250 | at91cap9_macb_hw_init(); |
| 251 | #endif |
| 252 | #ifdef CONFIG_USB_OHCI_NEW |
| 253 | at91cap9_uhp_hw_init(); |
| 254 | #endif |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | int dram_init(void) |
| 260 | { |
| 261 | gd->bd->bi_dram[0].start = PHYS_SDRAM; |
| 262 | gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE; |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | #ifdef CONFIG_RESET_PHY_R |
| 267 | void reset_phy(void) |
| 268 | { |
| 269 | #ifdef CONFIG_MACB |
| 270 | /* |
| 271 | * Initialize ethernet HW addr prior to starting Linux, |
| 272 | * needed for nfsroot |
| 273 | */ |
| 274 | eth_init(gd->bd); |
| 275 | #endif |
| 276 | } |
| 277 | #endif |