Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 |
| 3 | * Stefano Babic, DENX Software Engineering, sbabic@denx.de |
| 4 | * |
| 5 | * Based on da850evm.c, original Copyrights follow: |
| 6 | * |
| 7 | * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ |
| 8 | * |
| 9 | * Based on da830evm.c. Original Copyrights follow: |
| 10 | * |
| 11 | * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com> |
| 12 | * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net> |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 27 | */ |
| 28 | |
| 29 | #include <common.h> |
| 30 | #include <i2c.h> |
| 31 | #include <net.h> |
| 32 | #include <netdev.h> |
| 33 | #include <asm/arch/hardware.h> |
| 34 | #include <asm/arch/emif_defs.h> |
| 35 | #include <asm/arch/emac_defs.h> |
| 36 | #include <asm/io.h> |
| 37 | #include <asm/arch/davinci_misc.h> |
Bastian Ruppert | ca1646b | 2011-10-04 23:43:29 +0000 | [diff] [blame] | 38 | #include <asm/arch/gpio.h> |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 39 | |
| 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
| 42 | #define pinmux(x) (&davinci_syscfg_regs->pinmux[x]) |
| 43 | |
| 44 | /* SPI0 pin muxer settings */ |
| 45 | static const struct pinmux_config spi1_pins[] = { |
| 46 | { pinmux(5), 1, 1 }, |
| 47 | { pinmux(5), 1, 2 }, |
| 48 | { pinmux(5), 1, 4 }, |
| 49 | { pinmux(5), 1, 5 } |
| 50 | }; |
| 51 | |
Bastian Ruppert | f9fc237 | 2011-10-04 23:43:28 +0000 | [diff] [blame] | 52 | /* UART0 pin muxer settings */ |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 53 | static const struct pinmux_config uart_pins[] = { |
Bastian Ruppert | f9fc237 | 2011-10-04 23:43:28 +0000 | [diff] [blame] | 54 | { pinmux(3), 2, 7 }, |
| 55 | { pinmux(3), 2, 6 }, |
| 56 | { pinmux(3), 2, 4 }, |
| 57 | { pinmux(3), 2, 5 } |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | #ifdef CONFIG_DRIVER_TI_EMAC |
| 61 | #define HAS_RMII 1 |
| 62 | static const struct pinmux_config emac_pins[] = { |
| 63 | { pinmux(14), 8, 2 }, |
| 64 | { pinmux(14), 8, 3 }, |
| 65 | { pinmux(14), 8, 4 }, |
| 66 | { pinmux(14), 8, 5 }, |
| 67 | { pinmux(14), 8, 6 }, |
| 68 | { pinmux(14), 8, 7 }, |
| 69 | { pinmux(15), 8, 1 }, |
| 70 | { pinmux(4), 8, 0 }, |
| 71 | { pinmux(4), 8, 1 } |
| 72 | }; |
| 73 | #endif |
| 74 | |
| 75 | #ifdef CONFIG_NAND_DAVINCI |
| 76 | const struct pinmux_config nand_pins[] = { |
Stefano Babic | 17a8904 | 2011-10-04 23:43:30 +0000 | [diff] [blame] | 77 | { pinmux(7), 1, 0}, /* CS2 */ |
| 78 | { pinmux(7), 0, 1}, /* CS3 in three state*/ |
| 79 | { pinmux(7), 1, 4 }, /* EMA_WE */ |
| 80 | { pinmux(7), 1, 5 }, /* EMA_OE */ |
| 81 | { pinmux(9), 1, 0 }, /* EMA_D[7] */ |
| 82 | { pinmux(9), 1, 1 }, /* EMA_D[6] */ |
| 83 | { pinmux(9), 1, 2 }, /* EMA_D[5] */ |
| 84 | { pinmux(9), 1, 3 }, /* EMA_D[4] */ |
| 85 | { pinmux(9), 1, 4 }, /* EMA_D[3] */ |
| 86 | { pinmux(9), 1, 5 }, /* EMA_D[2] */ |
| 87 | { pinmux(9), 1, 6 }, /* EMA_D[1] */ |
| 88 | { pinmux(9), 1, 7 }, /* EMA_D[0] */ |
| 89 | { pinmux(12), 1, 5 }, /* EMA_A[2] */ |
| 90 | { pinmux(12), 1, 6 }, /* EMA_A[1] */ |
| 91 | { pinmux(6), 1, 0 } /* EMA_CLK */ |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 92 | }; |
| 93 | #endif |
| 94 | |
Bastian Ruppert | ca1646b | 2011-10-04 23:43:29 +0000 | [diff] [blame] | 95 | const struct pinmux_config gpio_pins[] = { |
| 96 | { pinmux(13), 8, 0 }, /* GPIO6[15] RESETOUTn on SOM*/ |
| 97 | { pinmux(13), 8, 5 }, /* GPIO6[10] U0_SW0 on EA20-00101_2*/ |
Bastian Ruppert | 8540b16 | 2011-10-04 23:43:34 +0000 | [diff] [blame^] | 98 | { pinmux(13), 8, 3 }, /* GPIO6[12] U0_SW1 on EA20-00101_2*/ |
| 99 | { pinmux(19), 8, 5 }, /* GPIO6[1] DISP_ON */ |
| 100 | { pinmux(14), 8, 1 } /* GPIO6[6] LCD_B_PWR*/ |
Bastian Ruppert | ca1646b | 2011-10-04 23:43:29 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
Bastian Ruppert | e5ee912 | 2011-10-04 23:43:33 +0000 | [diff] [blame] | 103 | const struct pinmux_config halten_pin[] = { |
| 104 | { pinmux(3), 4, 2 } /* GPIO8[6] HALTEN */ |
| 105 | }; |
| 106 | |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 107 | static const struct pinmux_resource pinmuxes[] = { |
| 108 | #ifdef CONFIG_SPI_FLASH |
| 109 | PINMUX_ITEM(spi1_pins), |
| 110 | #endif |
| 111 | PINMUX_ITEM(uart_pins), |
| 112 | #ifdef CONFIG_NAND_DAVINCI |
| 113 | PINMUX_ITEM(nand_pins), |
| 114 | #endif |
| 115 | }; |
| 116 | |
| 117 | static const struct lpsc_resource lpsc[] = { |
| 118 | { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */ |
| 119 | { DAVINCI_LPSC_SPI1 }, /* Serial Flash */ |
| 120 | { DAVINCI_LPSC_EMAC }, /* image download */ |
Bastian Ruppert | f9fc237 | 2011-10-04 23:43:28 +0000 | [diff] [blame] | 121 | { DAVINCI_LPSC_UART0 }, /* console */ |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 122 | { DAVINCI_LPSC_GPIO }, |
| 123 | }; |
| 124 | |
Stefano Babic | 1c6ec6d | 2011-10-04 23:43:31 +0000 | [diff] [blame] | 125 | int board_early_init_f(void) |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 126 | { |
Bastian Ruppert | ca1646b | 2011-10-04 23:43:29 +0000 | [diff] [blame] | 127 | struct davinci_gpio *gpio6_base = |
| 128 | (struct davinci_gpio *)DAVINCI_GPIO_BANK67; |
| 129 | |
| 130 | /* PinMux for GPIO */ |
| 131 | if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0) |
| 132 | return 1; |
| 133 | |
| 134 | /* Set the RESETOUTn low */ |
| 135 | writel((readl(&gpio6_base->set_data) & ~(1 << 15)), |
| 136 | &gpio6_base->set_data); |
| 137 | writel((readl(&gpio6_base->dir) & ~(1 << 15)), &gpio6_base->dir); |
| 138 | |
| 139 | /* Set U0_SW0 low for UART0 as console*/ |
| 140 | writel((readl(&gpio6_base->set_data) & ~(1 << 10)), |
| 141 | &gpio6_base->set_data); |
| 142 | writel((readl(&gpio6_base->dir) & ~(1 << 10)), &gpio6_base->dir); |
| 143 | |
| 144 | /* Set U0_SW1 low for UART0 as console*/ |
| 145 | writel((readl(&gpio6_base->set_data) & ~(1 << 12)), |
| 146 | &gpio6_base->set_data); |
| 147 | writel((readl(&gpio6_base->dir) & ~(1 << 12)), &gpio6_base->dir); |
| 148 | |
Bastian Ruppert | 8540b16 | 2011-10-04 23:43:34 +0000 | [diff] [blame^] | 149 | /* Set LCD_B_PWR low to power down LCD Backlight*/ |
| 150 | writel((readl(&gpio6_base->set_data) & ~(1 << 6)), |
| 151 | &gpio6_base->set_data); |
| 152 | writel((readl(&gpio6_base->dir) & ~(1 << 6)), &gpio6_base->dir); |
| 153 | |
| 154 | /* Set DISP_ON low to disable LCD output*/ |
| 155 | writel((readl(&gpio6_base->set_data) & ~(1 << 1)), |
| 156 | &gpio6_base->set_data); |
| 157 | writel((readl(&gpio6_base->dir) & ~(1 << 1)), &gpio6_base->dir); |
| 158 | |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 159 | #ifndef CONFIG_USE_IRQ |
| 160 | irq_init(); |
| 161 | #endif |
| 162 | |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 163 | /* |
| 164 | * NAND CS setup - cycle counts based on da850evm NAND timings in the |
| 165 | * Linux kernel @ 25MHz EMIFA |
| 166 | */ |
Stefano Babic | 17a8904 | 2011-10-04 23:43:30 +0000 | [diff] [blame] | 167 | #ifdef CONFIG_NAND_DAVINCI |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 168 | writel((DAVINCI_ABCR_WSETUP(0) | |
Stefano Babic | 17a8904 | 2011-10-04 23:43:30 +0000 | [diff] [blame] | 169 | DAVINCI_ABCR_WSTROBE(1) | |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 170 | DAVINCI_ABCR_WHOLD(0) | |
| 171 | DAVINCI_ABCR_RSETUP(0) | |
| 172 | DAVINCI_ABCR_RSTROBE(1) | |
| 173 | DAVINCI_ABCR_RHOLD(0) | |
| 174 | DAVINCI_ABCR_TA(0) | |
| 175 | DAVINCI_ABCR_ASIZE_8BIT), |
Stefano Babic | 17a8904 | 2011-10-04 23:43:30 +0000 | [diff] [blame] | 176 | &davinci_emif_regs->ab1cr); /* CS2 */ |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 177 | #endif |
| 178 | |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 179 | /* |
| 180 | * Power on required peripherals |
| 181 | * ARM does not have access by default to PSC0 and PSC1 |
| 182 | * assuming here that the DSP bootloader has set the IOPU |
| 183 | * such that PSC access is available to ARM |
| 184 | */ |
| 185 | if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) |
| 186 | return 1; |
| 187 | |
| 188 | /* setup the SUSPSRC for ARM to control emulation suspend */ |
| 189 | writel(readl(&davinci_syscfg_regs->suspsrc) & |
| 190 | ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C | |
| 191 | DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 | |
Bastian Ruppert | f9fc237 | 2011-10-04 23:43:28 +0000 | [diff] [blame] | 192 | DAVINCI_SYSCFG_SUSPSRC_UART0), |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 193 | &davinci_syscfg_regs->suspsrc); |
| 194 | |
| 195 | /* configure pinmux settings */ |
| 196 | if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) |
| 197 | return 1; |
| 198 | |
| 199 | #ifdef CONFIG_DRIVER_TI_EMAC |
| 200 | if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0) |
| 201 | return 1; |
| 202 | |
| 203 | davinci_emac_mii_mode_sel(HAS_RMII); |
| 204 | #endif /* CONFIG_DRIVER_TI_EMAC */ |
| 205 | |
| 206 | /* enable the console UART */ |
| 207 | writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST | |
| 208 | DAVINCI_UART_PWREMU_MGMT_UTRST), |
Bastian Ruppert | f9fc237 | 2011-10-04 23:43:28 +0000 | [diff] [blame] | 209 | &davinci_uart0_ctrl_regs->pwremu_mgmt); |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
Stefano Babic | 1c6ec6d | 2011-10-04 23:43:31 +0000 | [diff] [blame] | 214 | int board_init(void) |
| 215 | { |
| 216 | /* arch number of the board */ |
| 217 | gd->bd->bi_arch_number = MACH_TYPE_EA20; |
| 218 | |
| 219 | /* address of boot parameters */ |
| 220 | gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; |
| 221 | |
| 222 | return 0; |
| 223 | } |
Bastian Ruppert | e5ee912 | 2011-10-04 23:43:33 +0000 | [diff] [blame] | 224 | |
| 225 | #ifdef BOARD_LATE_INIT |
| 226 | |
| 227 | int board_late_init(void) |
| 228 | { |
| 229 | struct davinci_gpio *gpio8_base = |
| 230 | (struct davinci_gpio *)DAVINCI_GPIO_BANK8; |
| 231 | |
| 232 | /* PinMux for HALTEN */ |
| 233 | if (davinci_configure_pin_mux(halten_pin, ARRAY_SIZE(halten_pin)) != 0) |
| 234 | return 1; |
| 235 | |
| 236 | /* Set HALTEN to high */ |
| 237 | writel((readl(&gpio8_base->set_data) | (1 << 6)), |
| 238 | &gpio8_base->set_data); |
| 239 | writel((readl(&gpio8_base->dir) & ~(1 << 6)), &gpio8_base->dir); |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | #endif /* BOARD_LATE_INIT */ |
| 244 | |
Stefano Babic | 649a33e | 2010-11-30 11:46:56 -0500 | [diff] [blame] | 245 | #ifdef CONFIG_DRIVER_TI_EMAC |
| 246 | |
| 247 | /* |
| 248 | * Initializes on-board ethernet controllers. |
| 249 | */ |
| 250 | int board_eth_init(bd_t *bis) |
| 251 | { |
| 252 | if (!davinci_emac_initialize()) { |
| 253 | printf("Error: Ethernet init failed!\n"); |
| 254 | return -1; |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * This board has a RMII PHY. However, the MDC line on the SOM |
| 259 | * must not be disabled (there is no MII PHY on the |
| 260 | * baseboard) via the GPIO2[6], because this pin |
| 261 | * disables at the same time the SPI flash. |
| 262 | */ |
| 263 | |
| 264 | return 0; |
| 265 | } |
| 266 | #endif /* CONFIG_DRIVER_TI_EMAC */ |