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