Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * board.c |
| 3 | * |
| 4 | * Board functions for Phytec phyCORE-AM335x (pcm051) based boards |
| 5 | * |
| 6 | * Copyright (C) 2013 Lemonage Software GmbH |
| 7 | * Author Lars Poeschel <poeschel@lemonage.de> |
| 8 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Alex Kiernan | 9c21549 | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 13 | #include <environment.h> |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 14 | #include <errno.h> |
| 15 | #include <spl.h> |
| 16 | #include <asm/arch/cpu.h> |
| 17 | #include <asm/arch/hardware.h> |
| 18 | #include <asm/arch/omap.h> |
| 19 | #include <asm/arch/ddr_defs.h> |
| 20 | #include <asm/arch/clock.h> |
| 21 | #include <asm/arch/gpio.h> |
| 22 | #include <asm/arch/mmc_host_def.h> |
| 23 | #include <asm/arch/sys_proto.h> |
| 24 | #include <asm/io.h> |
| 25 | #include <asm/emif.h> |
| 26 | #include <asm/gpio.h> |
| 27 | #include <i2c.h> |
| 28 | #include <miiphy.h> |
| 29 | #include <cpsw.h> |
| 30 | #include "board.h" |
| 31 | |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 34 | /* MII mode defines */ |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 35 | #define RMII_RGMII2_MODE_ENABLE 0x49 |
| 36 | |
| 37 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 38 | |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 39 | #ifdef CONFIG_SPL_BUILD |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 40 | |
| 41 | /* DDR RAM defines */ |
| 42 | #define DDR_CLK_MHZ 303 /* DDR_DPLL_MULT value */ |
| 43 | |
Lokesh Vutla | 89a83bf | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 44 | #define OSC (V_OSCK/1000000) |
| 45 | const struct dpll_params dpll_ddr = { |
| 46 | DDR_CLK_MHZ, OSC-1, 1, -1, -1, -1, -1}; |
| 47 | |
| 48 | const struct dpll_params *get_dpll_ddr_params(void) |
| 49 | { |
| 50 | return &dpll_ddr; |
| 51 | } |
| 52 | |
Lars Poeschel | 2fbf12a | 2013-11-19 11:22:18 +0100 | [diff] [blame] | 53 | #ifdef CONFIG_REV1 |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 54 | const struct ctrl_ioregs ioregs = { |
| 55 | .cm0ioctl = MT41J256M8HX15E_IOCTRL_VALUE, |
| 56 | .cm1ioctl = MT41J256M8HX15E_IOCTRL_VALUE, |
| 57 | .cm2ioctl = MT41J256M8HX15E_IOCTRL_VALUE, |
| 58 | .dt0ioctl = MT41J256M8HX15E_IOCTRL_VALUE, |
| 59 | .dt1ioctl = MT41J256M8HX15E_IOCTRL_VALUE, |
| 60 | }; |
| 61 | |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 62 | static const struct ddr_data ddr3_data = { |
| 63 | .datardsratio0 = MT41J256M8HX15E_RD_DQS, |
| 64 | .datawdsratio0 = MT41J256M8HX15E_WR_DQS, |
| 65 | .datafwsratio0 = MT41J256M8HX15E_PHY_FIFO_WE, |
| 66 | .datawrsratio0 = MT41J256M8HX15E_PHY_WR_DATA, |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static const struct cmd_control ddr3_cmd_ctrl_data = { |
| 70 | .cmd0csratio = MT41J256M8HX15E_RATIO, |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 71 | .cmd0iclkout = MT41J256M8HX15E_INVERT_CLKOUT, |
| 72 | |
| 73 | .cmd1csratio = MT41J256M8HX15E_RATIO, |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 74 | .cmd1iclkout = MT41J256M8HX15E_INVERT_CLKOUT, |
| 75 | |
| 76 | .cmd2csratio = MT41J256M8HX15E_RATIO, |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 77 | .cmd2iclkout = MT41J256M8HX15E_INVERT_CLKOUT, |
| 78 | }; |
| 79 | |
| 80 | static struct emif_regs ddr3_emif_reg_data = { |
| 81 | .sdram_config = MT41J256M8HX15E_EMIF_SDCFG, |
| 82 | .ref_ctrl = MT41J256M8HX15E_EMIF_SDREF, |
| 83 | .sdram_tim1 = MT41J256M8HX15E_EMIF_TIM1, |
| 84 | .sdram_tim2 = MT41J256M8HX15E_EMIF_TIM2, |
| 85 | .sdram_tim3 = MT41J256M8HX15E_EMIF_TIM3, |
| 86 | .zq_config = MT41J256M8HX15E_ZQ_CFG, |
Lars Poeschel | 3ccf01a | 2013-04-03 04:37:52 +0000 | [diff] [blame] | 87 | .emif_ddr_phy_ctlr_1 = MT41J256M8HX15E_EMIF_READ_LATENCY | |
| 88 | PHY_EN_DYN_PWRDN, |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 89 | }; |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 90 | |
Lars Poeschel | 2fbf12a | 2013-11-19 11:22:18 +0100 | [diff] [blame] | 91 | void sdram_init(void) |
| 92 | { |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 93 | config_ddr(DDR_CLK_MHZ, &ioregs, &ddr3_data, |
Lars Poeschel | 2fbf12a | 2013-11-19 11:22:18 +0100 | [diff] [blame] | 94 | &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0); |
| 95 | } |
| 96 | #else |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 97 | const struct ctrl_ioregs ioregs = { |
| 98 | .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 99 | .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 100 | .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 101 | .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 102 | .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 103 | }; |
| 104 | |
Lars Poeschel | 2fbf12a | 2013-11-19 11:22:18 +0100 | [diff] [blame] | 105 | static const struct ddr_data ddr3_data = { |
| 106 | .datardsratio0 = MT41K256M16HA125E_RD_DQS, |
| 107 | .datawdsratio0 = MT41K256M16HA125E_WR_DQS, |
| 108 | .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE, |
| 109 | .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA, |
Lars Poeschel | 2fbf12a | 2013-11-19 11:22:18 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | static const struct cmd_control ddr3_cmd_ctrl_data = { |
| 113 | .cmd0csratio = MT41K256M16HA125E_RATIO, |
Lars Poeschel | 2fbf12a | 2013-11-19 11:22:18 +0100 | [diff] [blame] | 114 | .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 115 | |
| 116 | .cmd1csratio = MT41K256M16HA125E_RATIO, |
Lars Poeschel | 2fbf12a | 2013-11-19 11:22:18 +0100 | [diff] [blame] | 117 | .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 118 | |
| 119 | .cmd2csratio = MT41K256M16HA125E_RATIO, |
Lars Poeschel | 2fbf12a | 2013-11-19 11:22:18 +0100 | [diff] [blame] | 120 | .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 121 | }; |
| 122 | |
| 123 | static struct emif_regs ddr3_emif_reg_data = { |
| 124 | .sdram_config = MT41K256M16HA125E_EMIF_SDCFG, |
| 125 | .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF, |
| 126 | .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1, |
| 127 | .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2, |
| 128 | .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3, |
| 129 | .zq_config = MT41K256M16HA125E_ZQ_CFG, |
| 130 | .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY | |
| 131 | PHY_EN_DYN_PWRDN, |
| 132 | }; |
| 133 | |
| 134 | void sdram_init(void) |
| 135 | { |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 136 | config_ddr(DDR_CLK_MHZ, &ioregs, &ddr3_data, |
Lars Poeschel | 2fbf12a | 2013-11-19 11:22:18 +0100 | [diff] [blame] | 137 | &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0); |
| 138 | } |
| 139 | #endif |
| 140 | |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 141 | void set_uart_mux_conf(void) |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 142 | { |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 143 | enable_uart0_pin_mux(); |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 144 | } |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 145 | |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 146 | void set_mux_conf_regs(void) |
| 147 | { |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 148 | /* Initalize the board header */ |
| 149 | enable_i2c0_pin_mux(); |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 150 | i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE); |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 151 | |
| 152 | enable_board_pin_mux(); |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 153 | } |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 154 | #endif |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 155 | |
| 156 | /* |
| 157 | * Basic board specific setup. Pinmux has been handled already. |
| 158 | */ |
| 159 | int board_init(void) |
| 160 | { |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 161 | i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE); |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 162 | |
Tom Rini | f3b6a1d | 2013-08-09 11:22:13 -0400 | [diff] [blame] | 163 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | #ifdef CONFIG_DRIVER_TI_CPSW |
| 169 | static void cpsw_control(int enabled) |
| 170 | { |
| 171 | /* VTP can be added here */ |
| 172 | |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | static struct cpsw_slave_data cpsw_slaves[] = { |
| 177 | { |
| 178 | .slave_reg_ofs = 0x208, |
| 179 | .sliver_reg_ofs = 0xd80, |
Mugunthan V N | 4944f37 | 2014-02-18 07:31:52 -0500 | [diff] [blame] | 180 | .phy_addr = 0, |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 181 | .phy_if = PHY_INTERFACE_MODE_RGMII, |
| 182 | }, |
| 183 | { |
| 184 | .slave_reg_ofs = 0x308, |
| 185 | .sliver_reg_ofs = 0xdc0, |
Mugunthan V N | 4944f37 | 2014-02-18 07:31:52 -0500 | [diff] [blame] | 186 | .phy_addr = 1, |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 187 | .phy_if = PHY_INTERFACE_MODE_RGMII, |
| 188 | }, |
| 189 | }; |
| 190 | |
| 191 | static struct cpsw_platform_data cpsw_data = { |
Matt Porter | e24646f | 2013-03-15 10:07:02 +0000 | [diff] [blame] | 192 | .mdio_base = CPSW_MDIO_BASE, |
| 193 | .cpsw_base = CPSW_BASE, |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 194 | .mdio_div = 0xff, |
| 195 | .channels = 8, |
| 196 | .cpdma_reg_ofs = 0x800, |
| 197 | .slaves = 1, |
| 198 | .slave_data = cpsw_slaves, |
| 199 | .ale_reg_ofs = 0xd00, |
| 200 | .ale_entries = 1024, |
| 201 | .host_port_reg_ofs = 0x108, |
| 202 | .hw_stats_reg_ofs = 0x900, |
Lars Poeschel | 949a6ad | 2013-09-30 09:51:34 +0200 | [diff] [blame] | 203 | .bd_ram_ofs = 0x2000, |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 204 | .mac_control = (1 << 5), |
| 205 | .control = cpsw_control, |
| 206 | .host_port_num = 0, |
| 207 | .version = CPSW_CTRL_VERSION_2, |
| 208 | }; |
| 209 | #endif |
| 210 | |
| 211 | #if defined(CONFIG_DRIVER_TI_CPSW) || \ |
Paul Kocialkowski | f34dfcb | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 212 | (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)) |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 213 | int board_eth_init(bd_t *bis) |
| 214 | { |
| 215 | int rv, n = 0; |
| 216 | #ifdef CONFIG_DRIVER_TI_CPSW |
| 217 | uint8_t mac_addr[6]; |
| 218 | uint32_t mac_hi, mac_lo; |
| 219 | |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 220 | if (!eth_env_get_enetaddr("ethaddr", mac_addr)) { |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 221 | printf("<ethaddr> not set. Reading from E-fuse\n"); |
| 222 | /* try reading mac address from efuse */ |
| 223 | mac_lo = readl(&cdev->macid0l); |
| 224 | mac_hi = readl(&cdev->macid0h); |
| 225 | mac_addr[0] = mac_hi & 0xFF; |
| 226 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 227 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 228 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 229 | mac_addr[4] = mac_lo & 0xFF; |
| 230 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 231 | |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 232 | if (is_valid_ethaddr(mac_addr)) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 233 | eth_env_set_enetaddr("ethaddr", mac_addr); |
Lars Poeschel | 67b4a79 | 2013-01-11 00:53:31 +0000 | [diff] [blame] | 234 | else |
| 235 | goto try_usbether; |
| 236 | } |
| 237 | |
| 238 | writel(RMII_RGMII2_MODE_ENABLE, &cdev->miisel); |
| 239 | |
| 240 | rv = cpsw_register(&cpsw_data); |
| 241 | if (rv < 0) |
| 242 | printf("Error %d registering CPSW switch\n", rv); |
| 243 | else |
| 244 | n += rv; |
| 245 | try_usbether: |
| 246 | #endif |
| 247 | |
| 248 | #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_SPL_BUILD) |
| 249 | rv = usb_eth_initialize(bis); |
| 250 | if (rv < 0) |
| 251 | printf("Error %d registering USB_ETHER\n", rv); |
| 252 | else |
| 253 | n += rv; |
| 254 | #endif |
| 255 | return n; |
| 256 | } |
| 257 | #endif |