Heiko Schocher | 03efcb0 | 2013-08-05 16:00:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 3 | * Based on: |
| 4 | * U-Boot:board/davinci/da8xxevm/da850evm.c |
| 5 | * |
| 6 | * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ |
| 7 | * |
| 8 | * Based on da830evm.c. Original Copyrights follow: |
| 9 | * |
| 10 | * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com> |
| 11 | * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net> |
| 12 | * |
| 13 | * SPDX-License-Identifier: GPL-2.0+ |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
| 17 | #include <i2c.h> |
| 18 | #include <net.h> |
| 19 | #include <netdev.h> |
| 20 | #include <spi.h> |
| 21 | #include <spi_flash.h> |
| 22 | #include <asm/arch/hardware.h> |
Khoronzhuk, Ivan | 3e01ed0 | 2014-06-07 04:22:52 +0300 | [diff] [blame^] | 23 | #include <asm/ti-common/davinci_nand.h> |
Heiko Schocher | 03efcb0 | 2013-08-05 16:00:38 +0200 | [diff] [blame] | 24 | #include <asm/arch/emac_defs.h> |
| 25 | #include <asm/arch/pinmux_defs.h> |
| 26 | #include <asm/io.h> |
| 27 | #include <asm/arch/davinci_misc.h> |
| 28 | #include <asm/errno.h> |
| 29 | #include <asm/gpio.h> |
| 30 | #include <hwconfig.h> |
| 31 | #include <bootstage.h> |
| 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
| 35 | #ifdef CONFIG_DRIVER_TI_EMAC |
| 36 | #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII |
| 37 | #define HAS_RMII 1 |
| 38 | #else |
| 39 | #define HAS_RMII 0 |
| 40 | #endif |
| 41 | #endif /* CONFIG_DRIVER_TI_EMAC */ |
| 42 | |
| 43 | void dsp_lpsc_on(unsigned domain, unsigned int id) |
| 44 | { |
| 45 | dv_reg_p mdstat, mdctl, ptstat, ptcmd; |
| 46 | struct davinci_psc_regs *psc_regs; |
| 47 | |
| 48 | psc_regs = davinci_psc0_regs; |
| 49 | mdstat = &psc_regs->psc0.mdstat[id]; |
| 50 | mdctl = &psc_regs->psc0.mdctl[id]; |
| 51 | ptstat = &psc_regs->ptstat; |
| 52 | ptcmd = &psc_regs->ptcmd; |
| 53 | |
| 54 | while (*ptstat & (0x1 << domain)) |
| 55 | ; |
| 56 | |
| 57 | if ((*mdstat & 0x1f) == 0x03) |
| 58 | return; /* Already on and enabled */ |
| 59 | |
| 60 | *mdctl |= 0x03; |
| 61 | |
| 62 | *ptcmd = 0x1 << domain; |
| 63 | |
| 64 | while (*ptstat & (0x1 << domain)) |
| 65 | ; |
| 66 | while ((*mdstat & 0x1f) != 0x03) |
| 67 | ; /* Probably an overkill... */ |
| 68 | } |
| 69 | |
| 70 | static void dspwake(void) |
| 71 | { |
| 72 | unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE; |
| 73 | u32 val; |
| 74 | |
| 75 | /* if the device is ARM only, return */ |
| 76 | if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10) |
| 77 | return; |
| 78 | |
| 79 | if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL)) |
| 80 | return; |
| 81 | |
| 82 | *resetvect++ = 0x1E000; /* DSP Idle */ |
| 83 | /* clear out the next 10 words as NOP */ |
| 84 | memset(resetvect, 0, sizeof(unsigned) * 10); |
| 85 | |
| 86 | /* setup the DSP reset vector */ |
| 87 | writel(DAVINCI_L3CBARAM_BASE, HOST1CFG); |
| 88 | |
| 89 | dsp_lpsc_on(1, DAVINCI_LPSC_GEM); |
| 90 | val = readl(PSC0_MDCTL + (15 * 4)); |
| 91 | val |= 0x100; |
| 92 | writel(val, (PSC0_MDCTL + (15 * 4))); |
| 93 | } |
| 94 | |
| 95 | int misc_init_r(void) |
| 96 | { |
| 97 | dspwake(); |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | static const struct pinmux_config gpio_pins[] = { |
| 102 | /* GP7[14] selects bootmode*/ |
| 103 | { pinmux(16), 8, 3 }, /* GP7[14] */ |
| 104 | }; |
| 105 | |
| 106 | const struct pinmux_resource pinmuxes[] = { |
| 107 | #ifdef CONFIG_DRIVER_TI_EMAC |
| 108 | PINMUX_ITEM(emac_pins_mdio), |
| 109 | #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII |
| 110 | PINMUX_ITEM(emac_pins_rmii), |
| 111 | #else |
| 112 | PINMUX_ITEM(emac_pins_mii), |
| 113 | #endif |
| 114 | #endif |
| 115 | PINMUX_ITEM(uart2_pins_txrx), |
| 116 | PINMUX_ITEM(uart2_pins_rtscts), |
| 117 | PINMUX_ITEM(uart0_pins_txrx), |
| 118 | PINMUX_ITEM(uart0_pins_rtscts), |
| 119 | #ifdef CONFIG_NAND_DAVINCI |
| 120 | PINMUX_ITEM(emifa_pins_cs3), |
| 121 | PINMUX_ITEM(emifa_pins_nand), |
| 122 | #endif |
| 123 | PINMUX_ITEM(gpio_pins), |
| 124 | }; |
| 125 | |
| 126 | const int pinmuxes_size = ARRAY_SIZE(pinmuxes); |
| 127 | |
| 128 | const struct lpsc_resource lpsc[] = { |
| 129 | { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */ |
| 130 | { DAVINCI_LPSC_EMAC }, /* image download */ |
| 131 | { DAVINCI_LPSC_UART2 }, /* console */ |
| 132 | { DAVINCI_LPSC_UART0 }, /* console */ |
| 133 | { DAVINCI_LPSC_GPIO }, |
| 134 | }; |
| 135 | |
| 136 | const int lpsc_size = ARRAY_SIZE(lpsc); |
| 137 | |
| 138 | #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK |
| 139 | #define CONFIG_DA850_EVM_MAX_CPU_CLK 300000000 |
| 140 | #endif |
| 141 | |
| 142 | #define REV_AM18X_EVM 0x100 |
| 143 | |
| 144 | /* |
| 145 | * get_board_rev() - setup to pass kernel board revision information |
| 146 | * Returns: |
| 147 | * bit[0-3] Maximum cpu clock rate supported by onboard SoC |
| 148 | * 0000b - 300 MHz |
| 149 | * 0001b - 372 MHz |
| 150 | * 0010b - 408 MHz |
| 151 | * 0011b - 456 MHz |
| 152 | */ |
| 153 | u32 get_board_rev(void) |
| 154 | { |
| 155 | char *s; |
| 156 | u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK; |
| 157 | u32 rev = 0; |
| 158 | |
| 159 | s = getenv("maxcpuclk"); |
| 160 | if (s) |
| 161 | maxcpuclk = simple_strtoul(s, NULL, 10); |
| 162 | |
| 163 | if (maxcpuclk >= 456000000) |
| 164 | rev = 3; |
| 165 | else if (maxcpuclk >= 408000000) |
| 166 | rev = 2; |
| 167 | else if (maxcpuclk >= 372000000) |
| 168 | rev = 1; |
| 169 | #ifdef CONFIG_DA850_AM18X_EVM |
| 170 | rev |= REV_AM18X_EVM; |
| 171 | #endif |
| 172 | return rev; |
| 173 | } |
| 174 | |
| 175 | int board_early_init_f(void) |
| 176 | { |
| 177 | /* |
| 178 | * Power on required peripherals |
| 179 | * ARM does not have access by default to PSC0 and PSC1 |
| 180 | * assuming here that the DSP bootloader has set the IOPU |
| 181 | * such that PSC access is available to ARM |
| 182 | */ |
| 183 | if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) |
| 184 | return 1; |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | int board_init(void) |
| 190 | { |
| 191 | #ifndef CONFIG_USE_IRQ |
| 192 | irq_init(); |
| 193 | #endif |
| 194 | |
| 195 | /* arch number of the board */ |
| 196 | gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM; |
| 197 | |
| 198 | /* address of boot parameters */ |
| 199 | gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; |
| 200 | |
| 201 | /* setup the SUSPSRC for ARM to control emulation suspend */ |
| 202 | writel(readl(&davinci_syscfg_regs->suspsrc) & |
| 203 | ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C | |
| 204 | DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 | |
| 205 | DAVINCI_SYSCFG_SUSPSRC_UART0), |
| 206 | &davinci_syscfg_regs->suspsrc); |
| 207 | |
| 208 | /* configure pinmux settings */ |
| 209 | if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) |
| 210 | return 1; |
| 211 | |
| 212 | #ifdef CONFIG_DRIVER_TI_EMAC |
| 213 | davinci_emac_mii_mode_sel(HAS_RMII); |
| 214 | #endif /* CONFIG_DRIVER_TI_EMAC */ |
| 215 | |
| 216 | /* enable the console UART */ |
| 217 | writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST | |
| 218 | DAVINCI_UART_PWREMU_MGMT_UTRST), |
| 219 | #if (CONFIG_SYS_NS16550_COM1 == DAVINCI_UART0_BASE) |
| 220 | &davinci_uart0_ctrl_regs->pwremu_mgmt); |
| 221 | #else |
| 222 | &davinci_uart2_ctrl_regs->pwremu_mgmt); |
| 223 | #endif |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | #ifdef CONFIG_DRIVER_TI_EMAC |
| 228 | /* |
| 229 | * Initializes on-board ethernet controllers. |
| 230 | */ |
| 231 | int board_eth_init(bd_t *bis) |
| 232 | { |
| 233 | if (!davinci_emac_initialize()) { |
| 234 | printf("Error: Ethernet init failed!\n"); |
| 235 | return -1; |
| 236 | } |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | #endif /* CONFIG_DRIVER_TI_EMAC */ |
| 241 | |
| 242 | static int init_led(int gpio, char *name, int val) |
| 243 | { |
| 244 | int ret; |
| 245 | |
| 246 | ret = gpio_request(gpio, name); |
| 247 | if (ret) |
| 248 | return -1; |
| 249 | ret = gpio_direction_output(gpio, val); |
| 250 | if (ret) |
| 251 | return -1; |
| 252 | |
| 253 | return gpio; |
| 254 | } |
| 255 | |
| 256 | #define LED_ON 0 |
| 257 | #define LED_OFF 1 |
| 258 | |
| 259 | #if !defined(CONFIG_SPL_BUILD) |
| 260 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 261 | void show_boot_progress(int status) |
| 262 | { |
| 263 | static int red; |
| 264 | static int green; |
| 265 | |
| 266 | if (red == 0) |
Heiko Schocher | 660a2e6 | 2013-09-06 05:21:24 +0200 | [diff] [blame] | 267 | red = init_led(CONFIG_IPAM390_GPIO_LED_RED, "red", LED_ON); |
Heiko Schocher | 03efcb0 | 2013-08-05 16:00:38 +0200 | [diff] [blame] | 268 | if (red != CONFIG_IPAM390_GPIO_LED_RED) |
| 269 | return; |
| 270 | if (green == 0) |
| 271 | green = init_led(CONFIG_IPAM390_GPIO_LED_GREEN, "green", |
| 272 | LED_OFF); |
| 273 | if (green != CONFIG_IPAM390_GPIO_LED_GREEN) |
| 274 | return; |
| 275 | |
| 276 | switch (status) { |
| 277 | case BOOTSTAGE_ID_RUN_OS: |
| 278 | /* |
| 279 | * set normal state |
Heiko Schocher | 660a2e6 | 2013-09-06 05:21:24 +0200 | [diff] [blame] | 280 | * LED Red : on |
Heiko Schocher | 03efcb0 | 2013-08-05 16:00:38 +0200 | [diff] [blame] | 281 | * LED green: off |
| 282 | */ |
Heiko Schocher | 660a2e6 | 2013-09-06 05:21:24 +0200 | [diff] [blame] | 283 | gpio_set_value(red, LED_ON); |
Heiko Schocher | 03efcb0 | 2013-08-05 16:00:38 +0200 | [diff] [blame] | 284 | gpio_set_value(green, LED_OFF); |
| 285 | break; |
| 286 | case BOOTSTAGE_ID_MAIN_LOOP: |
| 287 | /* |
| 288 | * U-Boot operation |
| 289 | * LED Red : on |
| 290 | * LED green: on |
| 291 | */ |
| 292 | gpio_set_value(red, LED_ON); |
| 293 | gpio_set_value(green, LED_ON); |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | #endif |
| 298 | #endif |
| 299 | |
| 300 | #ifdef CONFIG_SPL_OS_BOOT |
| 301 | int spl_start_uboot(void) |
| 302 | { |
| 303 | int ret; |
| 304 | int bootmode = 0; |
| 305 | |
| 306 | /* |
| 307 | * GP7[14] selects bootmode: |
| 308 | * 1: boot linux |
| 309 | * 0: boot u-boot |
| 310 | * if error accessing gpio boot U-Boot |
| 311 | * |
| 312 | * SPL bootmode |
| 313 | * 0: boot linux |
| 314 | * 1: boot u-boot |
| 315 | */ |
| 316 | ret = gpio_request(CONFIG_IPAM390_GPIO_BOOTMODE , "bootmode"); |
| 317 | if (ret) |
| 318 | bootmode = 1; |
| 319 | if (!bootmode) { |
| 320 | ret = gpio_direction_input(CONFIG_IPAM390_GPIO_BOOTMODE); |
| 321 | if (ret) |
| 322 | bootmode = 1; |
| 323 | } |
| 324 | if (!bootmode) |
| 325 | ret = gpio_get_value(CONFIG_IPAM390_GPIO_BOOTMODE); |
| 326 | if (!bootmode) |
| 327 | if (ret == 0) |
| 328 | bootmode = 1; |
Heiko Schocher | 660a2e6 | 2013-09-06 05:21:24 +0200 | [diff] [blame] | 329 | /* |
| 330 | * LED red : on |
| 331 | * LED green: off |
| 332 | */ |
| 333 | init_led(CONFIG_IPAM390_GPIO_LED_RED, "red", LED_ON); |
| 334 | init_led(CONFIG_IPAM390_GPIO_LED_GREEN, "green", LED_OFF); |
Heiko Schocher | 03efcb0 | 2013-08-05 16:00:38 +0200 | [diff] [blame] | 335 | return bootmode; |
| 336 | } |
| 337 | #endif |