Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Board functions for IGEP COM AQUILA/CYGNUS based boards |
| 3 | * |
| 4 | * Copyright (C) 2013, ISEE 2007 SL - http://www.isee.biz/ |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; either version 2 of |
| 9 | * the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <common.h> |
| 18 | #include <errno.h> |
| 19 | #include <spl.h> |
| 20 | #include <asm/arch/cpu.h> |
| 21 | #include <asm/arch/hardware.h> |
| 22 | #include <asm/arch/omap.h> |
| 23 | #include <asm/arch/ddr_defs.h> |
| 24 | #include <asm/arch/clock.h> |
| 25 | #include <asm/arch/gpio.h> |
| 26 | #include <asm/arch/mmc_host_def.h> |
| 27 | #include <asm/arch/sys_proto.h> |
| 28 | #include <asm/io.h> |
| 29 | #include <asm/emif.h> |
| 30 | #include <asm/gpio.h> |
| 31 | #include <i2c.h> |
| 32 | #include <miiphy.h> |
| 33 | #include <cpsw.h> |
| 34 | #include "board.h" |
| 35 | |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
| 38 | static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE; |
| 39 | #ifdef CONFIG_SPL_BUILD |
| 40 | static struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE; |
| 41 | #endif |
| 42 | |
| 43 | /* MII mode defines */ |
| 44 | #define RMII_MODE_ENABLE 0x4D |
| 45 | |
| 46 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 47 | |
| 48 | /* UART Defines */ |
| 49 | #ifdef CONFIG_SPL_BUILD |
| 50 | #define UART_RESET (0x1 << 1) |
| 51 | #define UART_CLK_RUNNING_MASK 0x1 |
| 52 | #define UART_SMART_IDLE_EN (0x1 << 0x3) |
| 53 | |
| 54 | static void rtc32k_enable(void) |
| 55 | { |
| 56 | struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE; |
| 57 | |
| 58 | /* |
| 59 | * Unlock the RTC's registers. For more details please see the |
| 60 | * RTC_SS section of the TRM. In order to unlock we need to |
| 61 | * write these specific values (keys) in this order. |
| 62 | */ |
| 63 | writel(0x83e70b13, &rtc->kick0r); |
| 64 | writel(0x95a4f1e0, &rtc->kick1r); |
| 65 | |
| 66 | /* Enable the RTC 32K OSC by setting bits 3 and 6. */ |
| 67 | writel((1 << 3) | (1 << 6), &rtc->osc); |
| 68 | } |
| 69 | |
| 70 | static const struct ddr_data ddr3_data = { |
| 71 | .datardsratio0 = K4B2G1646EBIH9_RD_DQS, |
| 72 | .datawdsratio0 = K4B2G1646EBIH9_WR_DQS, |
| 73 | .datafwsratio0 = K4B2G1646EBIH9_PHY_FIFO_WE, |
| 74 | .datawrsratio0 = K4B2G1646EBIH9_PHY_WR_DATA, |
| 75 | .datadldiff0 = PHY_DLL_LOCK_DIFF, |
| 76 | }; |
| 77 | |
| 78 | static const struct cmd_control ddr3_cmd_ctrl_data = { |
| 79 | .cmd0csratio = K4B2G1646EBIH9_RATIO, |
| 80 | .cmd0dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF, |
| 81 | .cmd0iclkout = K4B2G1646EBIH9_INVERT_CLKOUT, |
| 82 | |
| 83 | .cmd1csratio = K4B2G1646EBIH9_RATIO, |
| 84 | .cmd1dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF, |
| 85 | .cmd1iclkout = K4B2G1646EBIH9_INVERT_CLKOUT, |
| 86 | |
| 87 | .cmd2csratio = K4B2G1646EBIH9_RATIO, |
| 88 | .cmd2dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF, |
| 89 | .cmd2iclkout = K4B2G1646EBIH9_INVERT_CLKOUT, |
| 90 | }; |
| 91 | |
| 92 | static struct emif_regs ddr3_emif_reg_data = { |
| 93 | .sdram_config = K4B2G1646EBIH9_EMIF_SDCFG, |
| 94 | .ref_ctrl = K4B2G1646EBIH9_EMIF_SDREF, |
| 95 | .sdram_tim1 = K4B2G1646EBIH9_EMIF_TIM1, |
| 96 | .sdram_tim2 = K4B2G1646EBIH9_EMIF_TIM2, |
| 97 | .sdram_tim3 = K4B2G1646EBIH9_EMIF_TIM3, |
| 98 | .zq_config = K4B2G1646EBIH9_ZQ_CFG, |
| 99 | .emif_ddr_phy_ctlr_1 = K4B2G1646EBIH9_EMIF_READ_LATENCY, |
| 100 | }; |
| 101 | #endif |
| 102 | |
| 103 | /* |
| 104 | * Early system init of muxing and clocks. |
| 105 | */ |
| 106 | void s_init(void) |
| 107 | { |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame^] | 108 | /* |
| 109 | * Save the boot parameters passed from romcode. |
| 110 | * We cannot delay the saving further than this, |
| 111 | * to prevent overwrites. |
| 112 | */ |
| 113 | #ifdef CONFIG_SPL_BUILD |
| 114 | save_omap_boot_params(); |
| 115 | #endif |
| 116 | |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 117 | /* WDT1 is already running when the bootloader gets control |
| 118 | * Disable it to avoid "random" resets |
| 119 | */ |
| 120 | writel(0xAAAA, &wdtimer->wdtwspr); |
| 121 | while (readl(&wdtimer->wdtwwps) != 0x0) |
| 122 | ; |
| 123 | writel(0x5555, &wdtimer->wdtwspr); |
| 124 | while (readl(&wdtimer->wdtwwps) != 0x0) |
| 125 | ; |
| 126 | |
| 127 | #ifdef CONFIG_SPL_BUILD |
| 128 | /* Setup the PLLs and the clocks for the peripherals */ |
| 129 | pll_init(); |
| 130 | |
| 131 | /* Enable RTC32K clock */ |
| 132 | rtc32k_enable(); |
| 133 | |
| 134 | /* UART softreset */ |
| 135 | u32 regval; |
| 136 | |
| 137 | enable_uart0_pin_mux(); |
| 138 | |
| 139 | regval = readl(&uart_base->uartsyscfg); |
| 140 | regval |= UART_RESET; |
| 141 | writel(regval, &uart_base->uartsyscfg); |
| 142 | while ((readl(&uart_base->uartsyssts) & |
| 143 | UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK) |
| 144 | ; |
| 145 | |
| 146 | /* Disable smart idle */ |
| 147 | regval = readl(&uart_base->uartsyscfg); |
| 148 | regval |= UART_SMART_IDLE_EN; |
| 149 | writel(regval, &uart_base->uartsyscfg); |
| 150 | |
| 151 | gd = &gdata; |
| 152 | |
| 153 | preloader_console_init(); |
| 154 | |
| 155 | /* Configure board pin mux */ |
| 156 | enable_board_pin_mux(); |
| 157 | |
| 158 | config_ddr(303, K4B2G1646EBIH9_IOCTRL_VALUE, &ddr3_data, |
| 159 | &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0); |
| 160 | #endif |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * Basic board specific setup. Pinmux has been handled already. |
| 165 | */ |
| 166 | int board_init(void) |
| 167 | { |
| 168 | gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100; |
| 169 | |
| 170 | gpmc_init(); |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | #if defined(CONFIG_DRIVER_TI_CPSW) |
| 176 | static void cpsw_control(int enabled) |
| 177 | { |
| 178 | /* VTP can be added here */ |
| 179 | |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | static struct cpsw_slave_data cpsw_slaves[] = { |
| 184 | { |
| 185 | .slave_reg_ofs = 0x208, |
| 186 | .sliver_reg_ofs = 0xd80, |
| 187 | .phy_id = 0, |
| 188 | .phy_if = PHY_INTERFACE_MODE_RMII, |
| 189 | }, |
| 190 | }; |
| 191 | |
| 192 | static struct cpsw_platform_data cpsw_data = { |
| 193 | .mdio_base = CPSW_MDIO_BASE, |
| 194 | .cpsw_base = CPSW_BASE, |
| 195 | .mdio_div = 0xff, |
| 196 | .channels = 8, |
| 197 | .cpdma_reg_ofs = 0x800, |
| 198 | .slaves = 1, |
| 199 | .slave_data = cpsw_slaves, |
| 200 | .ale_reg_ofs = 0xd00, |
| 201 | .ale_entries = 1024, |
| 202 | .host_port_reg_ofs = 0x108, |
| 203 | .hw_stats_reg_ofs = 0x900, |
| 204 | .mac_control = (1 << 5), |
| 205 | .control = cpsw_control, |
| 206 | .host_port_num = 0, |
| 207 | .version = CPSW_CTRL_VERSION_2, |
| 208 | }; |
| 209 | |
| 210 | int board_eth_init(bd_t *bis) |
| 211 | { |
| 212 | int rv, ret = 0; |
| 213 | uint8_t mac_addr[6]; |
| 214 | uint32_t mac_hi, mac_lo; |
| 215 | |
| 216 | if (!eth_getenv_enetaddr("ethaddr", mac_addr)) { |
| 217 | /* try reading mac address from efuse */ |
| 218 | mac_lo = readl(&cdev->macid0l); |
| 219 | mac_hi = readl(&cdev->macid0h); |
| 220 | mac_addr[0] = mac_hi & 0xFF; |
| 221 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 222 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 223 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 224 | mac_addr[4] = mac_lo & 0xFF; |
| 225 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 226 | if (is_valid_ether_addr(mac_addr)) |
| 227 | eth_setenv_enetaddr("ethaddr", mac_addr); |
| 228 | } |
| 229 | |
| 230 | writel(RMII_MODE_ENABLE, &cdev->miisel); |
| 231 | |
| 232 | rv = cpsw_register(&cpsw_data); |
| 233 | if (rv < 0) |
| 234 | printf("Error %d registering CPSW switch\n", rv); |
| 235 | else |
| 236 | ret += rv; |
| 237 | |
| 238 | return ret; |
| 239 | } |
| 240 | #endif |
| 241 | |