blob: 1e0e131addfe7a613d94ae363e78da3e2f40b674 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocher499c4982013-08-19 16:39:01 +02002/*
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 Menoneaa39c62023-11-01 15:56:03 -050010 * Copyright (C) 2011, Texas Instruments, Incorporated - https://www.ti.com/
Heiko Schocher499c4982013-08-19 16:39:01 +020011 */
12
13#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060014#include <env.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020015#include <errno.h>
Simon Glassa7b51302019-11-14 12:57:46 -070016#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -070017#include <malloc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060018#include <net.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020019#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 Glassdbd79542020-05-10 11:40:11 -060037#include <linux/delay.h>
Enrico Leto2e740502024-01-24 15:43:53 +010038#include "../common/board_am335x.h"
Enrico Leto096bfdc2024-01-24 15:43:49 +010039#include "../common/eeprom.h"
Heiko Schocher499c4982013-08-19 16:39:01 +020040#include "../common/factoryset.h"
Heiko Schocher499c4982013-08-19 16:39:01 +020041
Enrico Leto32f433f2024-01-24 15:43:50 +010042#ifdef CONFIG_SPL_BUILD
Heiko Schocher499c4982013-08-19 16:39:01 +020043/*
44 * Read header information from EEPROM into global structure.
45 */
Enrico Leto2e740502024-01-24 15:43:53 +010046int draco_read_eeprom(void)
Heiko Schocher499c4982013-08-19 16:39:01 +020047{
48 return 0;
49}
50
Enrico Leto2e740502024-01-24 15:43:53 +010051void draco_init_ddr(void)
Heiko Schocher499c4982013-08-19 16:39:01 +020052{
53struct 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
63struct ddr_data rut_ddr3_data = {
64 .datardsratio0 = 0x3b,
65 .datawdsratio0 = 0x85,
66 .datafwsratio0 = 0x100,
67 .datawrsratio0 = 0xc1,
Heiko Schocher499c4982013-08-19 16:39:01 +020068};
69
70struct cmd_control rut_ddr3_cmd_ctrl_data = {
71 .cmd0csratio = 0x40,
Heiko Schocher499c4982013-08-19 16:39:01 +020072 .cmd0iclkout = 1,
73 .cmd1csratio = 0x40,
Heiko Schocher499c4982013-08-19 16:39:01 +020074 .cmd1iclkout = 1,
75 .cmd2csratio = 0x40,
Heiko Schocher499c4982013-08-19 16:39:01 +020076 .cmd2iclkout = 1,
77};
78
Lokesh Vutla303b2672013-12-10 15:02:21 +053079const 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 Schocher499c4982013-08-19 16:39:01 +020088 &rut_ddr3_cmd_ctrl_data, &rut_ddr3_emif_reg_data, 0);
89}
90
Samuel Egli8069bfe2013-11-04 14:05:03 +010091static 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
114err_free_gpio:
115 gpio_free(gpio);
116err:
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
Enrico Leto2e740502024-01-24 15:43:53 +0100128void spl_draco_board_init(void)
Heiko Schocher499c4982013-08-19 16:39:01 +0200129{
Samuel Egli8069bfe2013-11-04 14:05:03 +0100130 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 Schocher499c4982013-08-19 16:39:01 +0200133}
134#endif /* if def CONFIG_SPL_BUILD */
135
136#if defined(CONFIG_DRIVER_TI_CPSW)
137static void cpsw_control(int enabled)
138{
139 /* VTP can be added here */
140
141 return;
142}
143
144static struct cpsw_slave_data cpsw_slaves[] = {
145 {
146 .slave_reg_ofs = 0x208,
147 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500148 .phy_addr = 1,
Heiko Schocher499c4982013-08-19 16:39:01 +0200149 .phy_if = PHY_INTERFACE_MODE_RMII,
150 },
151 {
152 .slave_reg_ofs = 0x308,
153 .sliver_reg_ofs = 0xdc0,
Mugunthan V N4944f372014-02-18 07:31:52 -0500154 .phy_addr = 0,
Heiko Schocher499c4982013-08-19 16:39:01 +0200155 .phy_if = PHY_INTERFACE_MODE_RMII,
156 },
157};
158
159static 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 Kocialkowskif34dfcb2015-08-04 17:04:06 +0200179 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900180int board_eth_init(struct bd_info *bis)
Heiko Schocher499c4982013-08-19 16:39:01 +0200181{
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 Glass6a38e412017-08-03 12:22:09 -0600187 factoryset_env_set();
Heiko Schocher499c4982013-08-19 16:39:01 +0200188#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)
204static bool hw_watchdog_init_done;
205static int hw_watchdog_trigger_level;
206
207void 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
216void 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 Schocherfaf2dc62014-11-18 11:51:06 +0100227#ifdef CONFIG_BOARD_LATE_INIT
228int 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 Whitten34fd6c92015-12-30 13:05:58 +0000239 strcpy(tmp, "QMX7.E38_4.0");
Heiko Schocherfaf2dc62014-11-18 11:51:06 +0100240
Simon Glass6a38e412017-08-03 12:22:09 -0600241 ret = env_set("boardid", tmp);
Heiko Schocherfaf2dc62014-11-18 11:51:06 +0100242 if (ret)
243 printf("error setting board id\n");
244
245 return 0;
246}
247#endif