Enric Balletbo i Serra | 9b96f46 | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Enric Balletbo i Serra | 9b96f46 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <errno.h> |
| 11 | #include <spl.h> |
| 12 | #include <asm/arch/cpu.h> |
| 13 | #include <asm/arch/hardware.h> |
| 14 | #include <asm/arch/omap.h> |
| 15 | #include <asm/arch/ddr_defs.h> |
| 16 | #include <asm/arch/clock.h> |
| 17 | #include <asm/arch/gpio.h> |
| 18 | #include <asm/arch/mmc_host_def.h> |
| 19 | #include <asm/arch/sys_proto.h> |
| 20 | #include <asm/io.h> |
| 21 | #include <asm/emif.h> |
| 22 | #include <asm/gpio.h> |
| 23 | #include <i2c.h> |
| 24 | #include <miiphy.h> |
| 25 | #include <cpsw.h> |
| 26 | #include "board.h" |
| 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
| 30 | static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE; |
Enric Balletbo i Serra | 9b96f46 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 31 | |
| 32 | /* MII mode defines */ |
| 33 | #define RMII_MODE_ENABLE 0x4D |
| 34 | |
| 35 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 36 | |
Enric Balletbo i Serra | 9b96f46 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 37 | #ifdef CONFIG_SPL_BUILD |
Enric Balletbo i Serra | 9b96f46 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 38 | static const struct ddr_data ddr3_data = { |
| 39 | .datardsratio0 = K4B2G1646EBIH9_RD_DQS, |
| 40 | .datawdsratio0 = K4B2G1646EBIH9_WR_DQS, |
| 41 | .datafwsratio0 = K4B2G1646EBIH9_PHY_FIFO_WE, |
| 42 | .datawrsratio0 = K4B2G1646EBIH9_PHY_WR_DATA, |
| 43 | .datadldiff0 = PHY_DLL_LOCK_DIFF, |
| 44 | }; |
| 45 | |
| 46 | static const struct cmd_control ddr3_cmd_ctrl_data = { |
| 47 | .cmd0csratio = K4B2G1646EBIH9_RATIO, |
| 48 | .cmd0dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF, |
| 49 | .cmd0iclkout = K4B2G1646EBIH9_INVERT_CLKOUT, |
| 50 | |
| 51 | .cmd1csratio = K4B2G1646EBIH9_RATIO, |
| 52 | .cmd1dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF, |
| 53 | .cmd1iclkout = K4B2G1646EBIH9_INVERT_CLKOUT, |
| 54 | |
| 55 | .cmd2csratio = K4B2G1646EBIH9_RATIO, |
| 56 | .cmd2dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF, |
| 57 | .cmd2iclkout = K4B2G1646EBIH9_INVERT_CLKOUT, |
| 58 | }; |
| 59 | |
| 60 | static struct emif_regs ddr3_emif_reg_data = { |
| 61 | .sdram_config = K4B2G1646EBIH9_EMIF_SDCFG, |
| 62 | .ref_ctrl = K4B2G1646EBIH9_EMIF_SDREF, |
| 63 | .sdram_tim1 = K4B2G1646EBIH9_EMIF_TIM1, |
| 64 | .sdram_tim2 = K4B2G1646EBIH9_EMIF_TIM2, |
| 65 | .sdram_tim3 = K4B2G1646EBIH9_EMIF_TIM3, |
| 66 | .zq_config = K4B2G1646EBIH9_ZQ_CFG, |
| 67 | .emif_ddr_phy_ctlr_1 = K4B2G1646EBIH9_EMIF_READ_LATENCY, |
| 68 | }; |
Lokesh Vutla | 89a83bf | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 69 | |
| 70 | #define OSC (V_OSCK/1000000) |
| 71 | const struct dpll_params dpll_ddr = { |
| 72 | 303, OSC-1, 1, -1, -1, -1, -1}; |
| 73 | |
| 74 | const struct dpll_params *get_dpll_ddr_params(void) |
| 75 | { |
| 76 | return &dpll_ddr; |
| 77 | } |
| 78 | |
Enric Balletbo i Serra | 9b96f46 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 79 | #endif |
| 80 | |
| 81 | /* |
| 82 | * Early system init of muxing and clocks. |
| 83 | */ |
| 84 | void s_init(void) |
| 85 | { |
Tom Rini | 51df26c | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 86 | /* |
| 87 | * Save the boot parameters passed from romcode. |
| 88 | * We cannot delay the saving further than this, |
| 89 | * to prevent overwrites. |
| 90 | */ |
| 91 | #ifdef CONFIG_SPL_BUILD |
| 92 | save_omap_boot_params(); |
| 93 | #endif |
| 94 | |
Enric Balletbo i Serra | 9b96f46 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 95 | /* WDT1 is already running when the bootloader gets control |
| 96 | * Disable it to avoid "random" resets |
| 97 | */ |
| 98 | writel(0xAAAA, &wdtimer->wdtwspr); |
| 99 | while (readl(&wdtimer->wdtwwps) != 0x0) |
| 100 | ; |
| 101 | writel(0x5555, &wdtimer->wdtwspr); |
| 102 | while (readl(&wdtimer->wdtwwps) != 0x0) |
| 103 | ; |
| 104 | |
| 105 | #ifdef CONFIG_SPL_BUILD |
Lokesh Vutla | b1b6fba | 2013-07-30 10:48:53 +0530 | [diff] [blame^] | 106 | setup_clocks_for_console(); |
Enric Balletbo i Serra | 9b96f46 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 107 | |
Enric Balletbo i Serra | 9b96f46 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 108 | enable_uart0_pin_mux(); |
| 109 | |
Heiko Schocher | 57004c5 | 2013-06-04 11:00:57 +0200 | [diff] [blame] | 110 | uart_soft_reset(); |
Enric Balletbo i Serra | 9b96f46 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 111 | gd = &gdata; |
| 112 | |
| 113 | preloader_console_init(); |
| 114 | |
Lokesh Vutla | b1b6fba | 2013-07-30 10:48:53 +0530 | [diff] [blame^] | 115 | prcm_init(); |
| 116 | |
| 117 | /* Enable RTC32K clock */ |
| 118 | rtc32k_enable(); |
| 119 | |
Enric Balletbo i Serra | 9b96f46 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 120 | /* Configure board pin mux */ |
| 121 | enable_board_pin_mux(); |
| 122 | |
| 123 | config_ddr(303, K4B2G1646EBIH9_IOCTRL_VALUE, &ddr3_data, |
| 124 | &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0); |
| 125 | #endif |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * Basic board specific setup. Pinmux has been handled already. |
| 130 | */ |
| 131 | int board_init(void) |
| 132 | { |
| 133 | gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100; |
| 134 | |
| 135 | gpmc_init(); |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | #if defined(CONFIG_DRIVER_TI_CPSW) |
| 141 | static void cpsw_control(int enabled) |
| 142 | { |
| 143 | /* VTP can be added here */ |
| 144 | |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | static struct cpsw_slave_data cpsw_slaves[] = { |
| 149 | { |
| 150 | .slave_reg_ofs = 0x208, |
| 151 | .sliver_reg_ofs = 0xd80, |
| 152 | .phy_id = 0, |
| 153 | .phy_if = PHY_INTERFACE_MODE_RMII, |
| 154 | }, |
| 155 | }; |
| 156 | |
| 157 | static struct cpsw_platform_data cpsw_data = { |
| 158 | .mdio_base = CPSW_MDIO_BASE, |
| 159 | .cpsw_base = CPSW_BASE, |
| 160 | .mdio_div = 0xff, |
| 161 | .channels = 8, |
| 162 | .cpdma_reg_ofs = 0x800, |
| 163 | .slaves = 1, |
| 164 | .slave_data = cpsw_slaves, |
| 165 | .ale_reg_ofs = 0xd00, |
| 166 | .ale_entries = 1024, |
| 167 | .host_port_reg_ofs = 0x108, |
| 168 | .hw_stats_reg_ofs = 0x900, |
| 169 | .mac_control = (1 << 5), |
| 170 | .control = cpsw_control, |
| 171 | .host_port_num = 0, |
| 172 | .version = CPSW_CTRL_VERSION_2, |
| 173 | }; |
| 174 | |
| 175 | int board_eth_init(bd_t *bis) |
| 176 | { |
| 177 | int rv, ret = 0; |
| 178 | uint8_t mac_addr[6]; |
| 179 | uint32_t mac_hi, mac_lo; |
| 180 | |
| 181 | if (!eth_getenv_enetaddr("ethaddr", mac_addr)) { |
| 182 | /* try reading mac address from efuse */ |
| 183 | mac_lo = readl(&cdev->macid0l); |
| 184 | mac_hi = readl(&cdev->macid0h); |
| 185 | mac_addr[0] = mac_hi & 0xFF; |
| 186 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 187 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 188 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 189 | mac_addr[4] = mac_lo & 0xFF; |
| 190 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 191 | if (is_valid_ether_addr(mac_addr)) |
| 192 | eth_setenv_enetaddr("ethaddr", mac_addr); |
| 193 | } |
| 194 | |
| 195 | writel(RMII_MODE_ENABLE, &cdev->miisel); |
| 196 | |
| 197 | rv = cpsw_register(&cpsw_data); |
| 198 | if (rv < 0) |
| 199 | printf("Error %d registering CPSW switch\n", rv); |
| 200 | else |
| 201 | ret += rv; |
| 202 | |
| 203 | return ret; |
| 204 | } |
| 205 | #endif |
| 206 | |