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