Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Board functions for TI AM335X based rut board |
| 4 | * (C) Copyright 2013 Siemens Schweiz AG |
| 5 | * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 6 | * |
| 7 | * Based on: |
| 8 | * u-boot:/board/ti/am335x/board.c |
| 9 | * |
| 10 | * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/ |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 14 | #include <env.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 15 | #include <errno.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 16 | #include <init.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 17 | #include <malloc.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 18 | #include <net.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 19 | #include <spi.h> |
| 20 | #include <spl.h> |
| 21 | #include <asm/arch/cpu.h> |
| 22 | #include <asm/arch/hardware.h> |
| 23 | #include <asm/arch/omap.h> |
| 24 | #include <asm/arch/ddr_defs.h> |
| 25 | #include <asm/arch/clock.h> |
| 26 | #include <asm/arch/gpio.h> |
| 27 | #include <asm/arch/mmc_host_def.h> |
| 28 | #include <asm/arch/sys_proto.h> |
| 29 | #include <asm/io.h> |
| 30 | #include <asm/emif.h> |
| 31 | #include <asm/gpio.h> |
| 32 | #include <i2c.h> |
| 33 | #include <miiphy.h> |
| 34 | #include <cpsw.h> |
| 35 | #include <video.h> |
| 36 | #include <watchdog.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 37 | #include <linux/delay.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 38 | #include "board.h" |
| 39 | #include "../common/factoryset.h" |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 40 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 41 | /* |
| 42 | * Read header information from EEPROM into global structure. |
| 43 | */ |
| 44 | static int read_eeprom(void) |
| 45 | { |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | #ifdef CONFIG_SPL_BUILD |
| 50 | static void board_init_ddr(void) |
| 51 | { |
| 52 | struct emif_regs rut_ddr3_emif_reg_data = { |
| 53 | .sdram_config = 0x61C04AB2, |
| 54 | .sdram_tim1 = 0x0888A39B, |
| 55 | .sdram_tim2 = 0x26337FDA, |
| 56 | .sdram_tim3 = 0x501F830F, |
| 57 | .emif_ddr_phy_ctlr_1 = 0x6, |
| 58 | .zq_config = 0x50074BE4, |
| 59 | .ref_ctrl = 0x93B, |
| 60 | }; |
| 61 | |
| 62 | struct ddr_data rut_ddr3_data = { |
| 63 | .datardsratio0 = 0x3b, |
| 64 | .datawdsratio0 = 0x85, |
| 65 | .datafwsratio0 = 0x100, |
| 66 | .datawrsratio0 = 0xc1, |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | struct cmd_control rut_ddr3_cmd_ctrl_data = { |
| 70 | .cmd0csratio = 0x40, |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 71 | .cmd0iclkout = 1, |
| 72 | .cmd1csratio = 0x40, |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 73 | .cmd1iclkout = 1, |
| 74 | .cmd2csratio = 0x40, |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 75 | .cmd2iclkout = 1, |
| 76 | }; |
| 77 | |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 78 | const struct ctrl_ioregs ioregs = { |
| 79 | .cm0ioctl = RUT_IOCTRL_VAL, |
| 80 | .cm1ioctl = RUT_IOCTRL_VAL, |
| 81 | .cm2ioctl = RUT_IOCTRL_VAL, |
| 82 | .dt0ioctl = RUT_IOCTRL_VAL, |
| 83 | .dt1ioctl = RUT_IOCTRL_VAL, |
| 84 | }; |
| 85 | |
| 86 | config_ddr(DDR_PLL_FREQ, &ioregs, &rut_ddr3_data, |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 87 | &rut_ddr3_cmd_ctrl_data, &rut_ddr3_emif_reg_data, 0); |
| 88 | } |
| 89 | |
Samuel Egli | 8069bfe | 2013-11-04 14:05:03 +0100 | [diff] [blame] | 90 | static int request_and_pulse_reset(int gpio, const char *name) |
| 91 | { |
| 92 | int ret; |
| 93 | const int delay_us = 2000; /* 2ms */ |
| 94 | |
| 95 | ret = gpio_request(gpio, name); |
| 96 | if (ret < 0) { |
| 97 | printf("%s: Unable to request %s\n", __func__, name); |
| 98 | goto err; |
| 99 | } |
| 100 | |
| 101 | ret = gpio_direction_output(gpio, 0); |
| 102 | if (ret < 0) { |
| 103 | printf("%s: Unable to set %s as output\n", __func__, name); |
| 104 | goto err_free_gpio; |
| 105 | } |
| 106 | |
| 107 | udelay(delay_us); |
| 108 | |
| 109 | gpio_set_value(gpio, 1); |
| 110 | |
| 111 | return 0; |
| 112 | |
| 113 | err_free_gpio: |
| 114 | gpio_free(gpio); |
| 115 | err: |
| 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio)) |
| 120 | #define ETH_PHY_RESET_GPIO GPIO_TO_PIN(2, 18) |
| 121 | #define MAXTOUCH_RESET_GPIO GPIO_TO_PIN(3, 18) |
| 122 | #define DISPLAY_RESET_GPIO GPIO_TO_PIN(3, 19) |
| 123 | |
| 124 | #define REQUEST_AND_PULSE_RESET(N) \ |
| 125 | request_and_pulse_reset(N, #N); |
| 126 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 127 | static void spl_siemens_board_init(void) |
| 128 | { |
Samuel Egli | 8069bfe | 2013-11-04 14:05:03 +0100 | [diff] [blame] | 129 | REQUEST_AND_PULSE_RESET(ETH_PHY_RESET_GPIO); |
| 130 | REQUEST_AND_PULSE_RESET(MAXTOUCH_RESET_GPIO); |
| 131 | REQUEST_AND_PULSE_RESET(DISPLAY_RESET_GPIO); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 132 | } |
| 133 | #endif /* if def CONFIG_SPL_BUILD */ |
| 134 | |
| 135 | #if defined(CONFIG_DRIVER_TI_CPSW) |
| 136 | static void cpsw_control(int enabled) |
| 137 | { |
| 138 | /* VTP can be added here */ |
| 139 | |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | static struct cpsw_slave_data cpsw_slaves[] = { |
| 144 | { |
| 145 | .slave_reg_ofs = 0x208, |
| 146 | .sliver_reg_ofs = 0xd80, |
Mugunthan V N | 4944f37 | 2014-02-18 07:31:52 -0500 | [diff] [blame] | 147 | .phy_addr = 1, |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 148 | .phy_if = PHY_INTERFACE_MODE_RMII, |
| 149 | }, |
| 150 | { |
| 151 | .slave_reg_ofs = 0x308, |
| 152 | .sliver_reg_ofs = 0xdc0, |
Mugunthan V N | 4944f37 | 2014-02-18 07:31:52 -0500 | [diff] [blame] | 153 | .phy_addr = 0, |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 154 | .phy_if = PHY_INTERFACE_MODE_RMII, |
| 155 | }, |
| 156 | }; |
| 157 | |
| 158 | static struct cpsw_platform_data cpsw_data = { |
| 159 | .mdio_base = CPSW_MDIO_BASE, |
| 160 | .cpsw_base = CPSW_BASE, |
| 161 | .mdio_div = 0xff, |
| 162 | .channels = 8, |
| 163 | .cpdma_reg_ofs = 0x800, |
| 164 | .slaves = 1, |
| 165 | .slave_data = cpsw_slaves, |
| 166 | .ale_reg_ofs = 0xd00, |
| 167 | .ale_entries = 1024, |
| 168 | .host_port_reg_ofs = 0x108, |
| 169 | .hw_stats_reg_ofs = 0x900, |
| 170 | .bd_ram_ofs = 0x2000, |
| 171 | .mac_control = (1 << 5), |
| 172 | .control = cpsw_control, |
| 173 | .host_port_num = 0, |
| 174 | .version = CPSW_CTRL_VERSION_2, |
| 175 | }; |
| 176 | |
| 177 | #if defined(CONFIG_DRIVER_TI_CPSW) || \ |
Paul Kocialkowski | f34dfcb | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 178 | (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 179 | int board_eth_init(struct bd_info *bis) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 180 | { |
| 181 | struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 182 | int n = 0; |
| 183 | int rv; |
| 184 | |
| 185 | #ifndef CONFIG_SPL_BUILD |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 186 | factoryset_env_set(); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 187 | #endif |
| 188 | |
| 189 | /* Set rgmii mode and enable rmii clock to be sourced from chip */ |
| 190 | writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel); |
| 191 | |
| 192 | rv = cpsw_register(&cpsw_data); |
| 193 | if (rv < 0) |
| 194 | printf("Error %d registering CPSW switch\n", rv); |
| 195 | else |
| 196 | n += rv; |
| 197 | return n; |
| 198 | } |
| 199 | #endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */ |
| 200 | #endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */ |
| 201 | |
| 202 | #if defined(CONFIG_HW_WATCHDOG) |
| 203 | static bool hw_watchdog_init_done; |
| 204 | static int hw_watchdog_trigger_level; |
| 205 | |
| 206 | void hw_watchdog_reset(void) |
| 207 | { |
| 208 | if (!hw_watchdog_init_done) |
| 209 | return; |
| 210 | |
| 211 | hw_watchdog_trigger_level = hw_watchdog_trigger_level ? 0 : 1; |
| 212 | gpio_set_value(WATCHDOG_TRIGGER_GPIO, hw_watchdog_trigger_level); |
| 213 | } |
| 214 | |
| 215 | void hw_watchdog_init(void) |
| 216 | { |
| 217 | gpio_request(WATCHDOG_TRIGGER_GPIO, "watchdog_trigger"); |
| 218 | gpio_direction_output(WATCHDOG_TRIGGER_GPIO, hw_watchdog_trigger_level); |
| 219 | |
| 220 | hw_watchdog_reset(); |
| 221 | |
| 222 | hw_watchdog_init_done = 1; |
| 223 | } |
| 224 | #endif /* defined(CONFIG_HW_WATCHDOG) */ |
| 225 | |
Heiko Schocher | faf2dc6 | 2014-11-18 11:51:06 +0100 | [diff] [blame] | 226 | #ifdef CONFIG_BOARD_LATE_INIT |
| 227 | int board_late_init(void) |
| 228 | { |
| 229 | int ret; |
| 230 | char tmp[2 * MAX_STRING_LENGTH + 2]; |
| 231 | |
| 232 | omap_nand_switch_ecc(1, 8); |
| 233 | |
| 234 | if (factory_dat.asn[0] != 0) |
| 235 | sprintf(tmp, "%s_%s", factory_dat.asn, |
| 236 | factory_dat.comp_version); |
| 237 | else |
Ben Whitten | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 238 | strcpy(tmp, "QMX7.E38_4.0"); |
Heiko Schocher | faf2dc6 | 2014-11-18 11:51:06 +0100 | [diff] [blame] | 239 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 240 | ret = env_set("boardid", tmp); |
Heiko Schocher | faf2dc6 | 2014-11-18 11:51:06 +0100 | [diff] [blame] | 241 | if (ret) |
| 242 | printf("error setting board id\n"); |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | #endif |
| 247 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 248 | #include "../common/board.c" |