blob: 02ae7df04db988e072c6589cc7294f3a9e45c8de [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +00002/*
Pau Pajuelob2310f12017-04-01 17:18:40 +02003 * Board functions for IGEP COM AQUILA and SMARC AM335x based boards
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +00004 *
Pau Pajuelob2310f12017-04-01 17:18:40 +02005 * Copyright (C) 2013-2017, ISEE 2007 SL - http://www.isee.biz/
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +00006 */
7
8#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06009#include <env.h>
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000010#include <errno.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -070012#include <malloc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <net.h>
Simon Glass36736182019-11-14 12:57:24 -070014#include <serial.h>
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000015#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>
Simon Glass3ba929a2020-10-30 21:38:53 -060024#include <asm/global_data.h>
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000025#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>
Ladislav Michlb6bd7f92017-04-01 17:17:57 +020031#include <fdt_support.h>
32#include <mtd_node.h>
33#include <jffs2/load_kernel.h>
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000034#include "board.h"
35
36DECLARE_GLOBAL_DATA_PTR;
37
Pau Pajuelob2310f12017-04-01 17:18:40 +020038/* GPIO0_27 and GPIO0_26 are used to read board revision from IGEP003x boards
39 * and control IGEP0034 green and red LEDs.
40 * U-boot configures these pins as input pullup to detect board revision:
41 * IGEP0034-LITE = 0b00
42 * IGEP0034 (FULL) = 0b01
43 * IGEP0033 = 0b1X
44 */
45#define GPIO_GREEN_REVISION 27
46#define GPIO_RED_REVISION 26
47
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000048static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
49
Pau Pajuelob2310f12017-04-01 17:18:40 +020050/*
51 * Routine: get_board_revision
52 * Description: Returns the board revision
53 */
54static int get_board_revision(void)
55{
56 int revision;
57
58 gpio_request(GPIO_GREEN_REVISION, "green_revision");
59 gpio_direction_input(GPIO_GREEN_REVISION);
60 revision = 2 * gpio_get_value(GPIO_GREEN_REVISION);
61 gpio_free(GPIO_GREEN_REVISION);
62
63 gpio_request(GPIO_RED_REVISION, "red_revision");
64 gpio_direction_input(GPIO_RED_REVISION);
65 revision = revision + gpio_get_value(GPIO_RED_REVISION);
66 gpio_free(GPIO_RED_REVISION);
67
68 return revision;
69}
70
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000071#ifdef CONFIG_SPL_BUILD
Pau Pajuelob2310f12017-04-01 17:18:40 +020072/* PN H5TQ4G63AFR is equivalent to MT41K256M16HA125*/
73static const struct ddr_data ddr3_igep0034_data = {
74 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
75 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
76 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
77 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
78};
79
80static const struct ddr_data ddr3_igep0034_lite_data = {
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000081 .datardsratio0 = K4B2G1646EBIH9_RD_DQS,
82 .datawdsratio0 = K4B2G1646EBIH9_WR_DQS,
83 .datafwsratio0 = K4B2G1646EBIH9_PHY_FIFO_WE,
84 .datawrsratio0 = K4B2G1646EBIH9_PHY_WR_DATA,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000085};
86
Pau Pajuelob2310f12017-04-01 17:18:40 +020087static const struct cmd_control ddr3_igep0034_cmd_ctrl_data = {
88 .cmd0csratio = MT41K256M16HA125E_RATIO,
89 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
90
91 .cmd1csratio = MT41K256M16HA125E_RATIO,
92 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
93
94 .cmd2csratio = MT41K256M16HA125E_RATIO,
95 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
96};
97
98static const struct cmd_control ddr3_igep0034_lite_cmd_ctrl_data = {
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000099 .cmd0csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000100 .cmd0iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
101
102 .cmd1csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000103 .cmd1iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
104
105 .cmd2csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000106 .cmd2iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
107};
108
Pau Pajuelob2310f12017-04-01 17:18:40 +0200109static struct emif_regs ddr3_igep0034_emif_reg_data = {
110 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
111 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
112 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
113 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
114 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
115 .zq_config = MT41K256M16HA125E_ZQ_CFG,
116 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
117};
118
119static struct emif_regs ddr3_igep0034_lite_emif_reg_data = {
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000120 .sdram_config = K4B2G1646EBIH9_EMIF_SDCFG,
121 .ref_ctrl = K4B2G1646EBIH9_EMIF_SDREF,
122 .sdram_tim1 = K4B2G1646EBIH9_EMIF_TIM1,
123 .sdram_tim2 = K4B2G1646EBIH9_EMIF_TIM2,
124 .sdram_tim3 = K4B2G1646EBIH9_EMIF_TIM3,
125 .zq_config = K4B2G1646EBIH9_ZQ_CFG,
126 .emif_ddr_phy_ctlr_1 = K4B2G1646EBIH9_EMIF_READ_LATENCY,
127};
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530128
Pau Pajuelob2310f12017-04-01 17:18:40 +0200129const struct ctrl_ioregs ioregs_igep0034 = {
130 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
131 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
132 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
133 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
134 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
135};
136
137const struct ctrl_ioregs ioregs_igep0034_lite = {
138 .cm0ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
139 .cm1ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
140 .cm2ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
141 .dt0ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
142 .dt1ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
143};
144
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530145#define OSC (V_OSCK/1000000)
146const struct dpll_params dpll_ddr = {
Enric Balletbo i Serra177db362013-09-10 11:12:26 +0200147 400, OSC-1, 1, -1, -1, -1, -1};
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530148
149const struct dpll_params *get_dpll_ddr_params(void)
150{
151 return &dpll_ddr;
152}
153
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530154void set_uart_mux_conf(void)
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000155{
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000156 enable_uart0_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530157}
Lokesh Vutlab1b6fba2013-07-30 10:48:53 +0530158
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530159void set_mux_conf_regs(void)
160{
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000161 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530162}
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000163
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530164void sdram_init(void)
165{
Pau Pajuelob2310f12017-04-01 17:18:40 +0200166 if (get_board_revision() == 1)
167 config_ddr(400, &ioregs_igep0034, &ddr3_igep0034_data,
168 &ddr3_igep0034_cmd_ctrl_data, &ddr3_igep0034_emif_reg_data, 0);
169 else
170 config_ddr(400, &ioregs_igep0034_lite, &ddr3_igep0034_lite_data,
171 &ddr3_igep0034_lite_cmd_ctrl_data, &ddr3_igep0034_lite_emif_reg_data, 0);
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000172}
Ladislav Michl1e16bf72017-06-25 10:30:47 +0200173
174#ifdef CONFIG_SPL_OS_BOOT
175int spl_start_uboot(void)
176{
177 /* break into full u-boot on 'c' */
178 return serial_tstc() && serial_getc() == 'c';
179}
180#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530181#endif
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000182
183/*
184 * Basic board specific setup. Pinmux has been handled already.
185 */
186int board_init(void)
187{
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400188 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000189
190 gpmc_init();
191
Pau Pajuelob2310f12017-04-01 17:18:40 +0200192 return 0;
193}
194
195#ifdef CONFIG_BOARD_LATE_INIT
196int board_late_init(void)
197{
198#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
199 switch (get_board_revision()) {
200 case 0:
Simon Glass6a38e412017-08-03 12:22:09 -0600201 env_set("board_name", "igep0034-lite");
Pau Pajuelob2310f12017-04-01 17:18:40 +0200202 break;
203 case 1:
Simon Glass6a38e412017-08-03 12:22:09 -0600204 env_set("board_name", "igep0034");
Pau Pajuelob2310f12017-04-01 17:18:40 +0200205 break;
206 default:
Simon Glass6a38e412017-08-03 12:22:09 -0600207 env_set("board_name", "igep0033");
Pau Pajuelob2310f12017-04-01 17:18:40 +0200208 break;
209 }
210#endif
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000211 return 0;
212}
Pau Pajuelob2310f12017-04-01 17:18:40 +0200213#endif
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000214
Ladislav Michlb6bd7f92017-04-01 17:17:57 +0200215#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900216int ft_board_setup(void *blob, struct bd_info *bd)
Ladislav Michlb6bd7f92017-04-01 17:17:57 +0200217{
218#ifdef CONFIG_FDT_FIXUP_PARTITIONS
Masahiro Yamada20ead6f2018-07-19 16:28:23 +0900219 static const struct node_info nodes[] = {
Ladislav Michlb6bd7f92017-04-01 17:17:57 +0200220 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
221 };
222
223 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
224#endif
225 return 0;
226}
227#endif
228
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000229#if defined(CONFIG_DRIVER_TI_CPSW)
230static void cpsw_control(int enabled)
231{
232 /* VTP can be added here */
233
234 return;
235}
236
237static struct cpsw_slave_data cpsw_slaves[] = {
238 {
239 .slave_reg_ofs = 0x208,
240 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500241 .phy_addr = 0,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000242 .phy_if = PHY_INTERFACE_MODE_RMII,
243 },
244};
245
246static struct cpsw_platform_data cpsw_data = {
247 .mdio_base = CPSW_MDIO_BASE,
248 .cpsw_base = CPSW_BASE,
249 .mdio_div = 0xff,
250 .channels = 8,
251 .cpdma_reg_ofs = 0x800,
252 .slaves = 1,
253 .slave_data = cpsw_slaves,
254 .ale_reg_ofs = 0xd00,
255 .ale_entries = 1024,
256 .host_port_reg_ofs = 0x108,
257 .hw_stats_reg_ofs = 0x900,
Lars Poeschel949a6ad2013-09-30 09:51:34 +0200258 .bd_ram_ofs = 0x2000,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000259 .mac_control = (1 << 5),
260 .control = cpsw_control,
261 .host_port_num = 0,
262 .version = CPSW_CTRL_VERSION_2,
263};
264
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900265int board_eth_init(struct bd_info *bis)
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000266{
267 int rv, ret = 0;
268 uint8_t mac_addr[6];
269 uint32_t mac_hi, mac_lo;
270
Simon Glass399a9ce2017-08-03 12:22:14 -0600271 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000272 /* try reading mac address from efuse */
273 mac_lo = readl(&cdev->macid0l);
274 mac_hi = readl(&cdev->macid0h);
275 mac_addr[0] = mac_hi & 0xFF;
276 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
277 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
278 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
279 mac_addr[4] = mac_lo & 0xFF;
280 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500281 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600282 eth_env_set_enetaddr("ethaddr", mac_addr);
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000283 }
284
Heiko Schocherc4fea292013-08-19 16:38:56 +0200285 writel((GMII1_SEL_RMII | RMII1_IO_CLK_EN),
286 &cdev->miisel);
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000287
Pau Pajuelob2310f12017-04-01 17:18:40 +0200288 if (get_board_revision() == 1)
289 cpsw_slaves[0].phy_addr = 1;
290
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000291 rv = cpsw_register(&cpsw_data);
292 if (rv < 0)
293 printf("Error %d registering CPSW switch\n", rv);
294 else
295 ret += rv;
296
297 return ret;
298}
299#endif