blob: bc9fdcd1e6c8267d3fd13eabcbe74addf6039fe2 [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 Glass36736182019-11-14 12:57:24 -070012#include <serial.h>
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000013#include <spl.h>
14#include <asm/arch/cpu.h>
15#include <asm/arch/hardware.h>
16#include <asm/arch/omap.h>
17#include <asm/arch/ddr_defs.h>
18#include <asm/arch/clock.h>
19#include <asm/arch/gpio.h>
20#include <asm/arch/mmc_host_def.h>
21#include <asm/arch/sys_proto.h>
22#include <asm/io.h>
23#include <asm/emif.h>
24#include <asm/gpio.h>
25#include <i2c.h>
26#include <miiphy.h>
27#include <cpsw.h>
Ladislav Michlb6bd7f92017-04-01 17:17:57 +020028#include <fdt_support.h>
29#include <mtd_node.h>
30#include <jffs2/load_kernel.h>
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000031#include "board.h"
32
33DECLARE_GLOBAL_DATA_PTR;
34
Pau Pajuelob2310f12017-04-01 17:18:40 +020035/* GPIO0_27 and GPIO0_26 are used to read board revision from IGEP003x boards
36 * and control IGEP0034 green and red LEDs.
37 * U-boot configures these pins as input pullup to detect board revision:
38 * IGEP0034-LITE = 0b00
39 * IGEP0034 (FULL) = 0b01
40 * IGEP0033 = 0b1X
41 */
42#define GPIO_GREEN_REVISION 27
43#define GPIO_RED_REVISION 26
44
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000045static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
46
Pau Pajuelob2310f12017-04-01 17:18:40 +020047/*
48 * Routine: get_board_revision
49 * Description: Returns the board revision
50 */
51static int get_board_revision(void)
52{
53 int revision;
54
55 gpio_request(GPIO_GREEN_REVISION, "green_revision");
56 gpio_direction_input(GPIO_GREEN_REVISION);
57 revision = 2 * gpio_get_value(GPIO_GREEN_REVISION);
58 gpio_free(GPIO_GREEN_REVISION);
59
60 gpio_request(GPIO_RED_REVISION, "red_revision");
61 gpio_direction_input(GPIO_RED_REVISION);
62 revision = revision + gpio_get_value(GPIO_RED_REVISION);
63 gpio_free(GPIO_RED_REVISION);
64
65 return revision;
66}
67
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000068#ifdef CONFIG_SPL_BUILD
Pau Pajuelob2310f12017-04-01 17:18:40 +020069/* PN H5TQ4G63AFR is equivalent to MT41K256M16HA125*/
70static const struct ddr_data ddr3_igep0034_data = {
71 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
72 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
73 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
74 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
75};
76
77static const struct ddr_data ddr3_igep0034_lite_data = {
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000078 .datardsratio0 = K4B2G1646EBIH9_RD_DQS,
79 .datawdsratio0 = K4B2G1646EBIH9_WR_DQS,
80 .datafwsratio0 = K4B2G1646EBIH9_PHY_FIFO_WE,
81 .datawrsratio0 = K4B2G1646EBIH9_PHY_WR_DATA,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000082};
83
Pau Pajuelob2310f12017-04-01 17:18:40 +020084static const struct cmd_control ddr3_igep0034_cmd_ctrl_data = {
85 .cmd0csratio = MT41K256M16HA125E_RATIO,
86 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
87
88 .cmd1csratio = MT41K256M16HA125E_RATIO,
89 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
90
91 .cmd2csratio = MT41K256M16HA125E_RATIO,
92 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
93};
94
95static const struct cmd_control ddr3_igep0034_lite_cmd_ctrl_data = {
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000096 .cmd0csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +000097 .cmd0iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
98
99 .cmd1csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000100 .cmd1iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
101
102 .cmd2csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000103 .cmd2iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
104};
105
Pau Pajuelob2310f12017-04-01 17:18:40 +0200106static struct emif_regs ddr3_igep0034_emif_reg_data = {
107 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
108 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
109 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
110 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
111 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
112 .zq_config = MT41K256M16HA125E_ZQ_CFG,
113 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
114};
115
116static struct emif_regs ddr3_igep0034_lite_emif_reg_data = {
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000117 .sdram_config = K4B2G1646EBIH9_EMIF_SDCFG,
118 .ref_ctrl = K4B2G1646EBIH9_EMIF_SDREF,
119 .sdram_tim1 = K4B2G1646EBIH9_EMIF_TIM1,
120 .sdram_tim2 = K4B2G1646EBIH9_EMIF_TIM2,
121 .sdram_tim3 = K4B2G1646EBIH9_EMIF_TIM3,
122 .zq_config = K4B2G1646EBIH9_ZQ_CFG,
123 .emif_ddr_phy_ctlr_1 = K4B2G1646EBIH9_EMIF_READ_LATENCY,
124};
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530125
Pau Pajuelob2310f12017-04-01 17:18:40 +0200126const struct ctrl_ioregs ioregs_igep0034 = {
127 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
128 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
129 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
130 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
131 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
132};
133
134const struct ctrl_ioregs ioregs_igep0034_lite = {
135 .cm0ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
136 .cm1ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
137 .cm2ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
138 .dt0ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
139 .dt1ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
140};
141
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530142#define OSC (V_OSCK/1000000)
143const struct dpll_params dpll_ddr = {
Enric Balletbo i Serra177db362013-09-10 11:12:26 +0200144 400, OSC-1, 1, -1, -1, -1, -1};
Lokesh Vutla89a83bf2013-07-30 10:48:52 +0530145
146const struct dpll_params *get_dpll_ddr_params(void)
147{
148 return &dpll_ddr;
149}
150
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530151void set_uart_mux_conf(void)
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000152{
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000153 enable_uart0_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530154}
Lokesh Vutlab1b6fba2013-07-30 10:48:53 +0530155
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530156void set_mux_conf_regs(void)
157{
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000158 enable_board_pin_mux();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530159}
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000160
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530161void sdram_init(void)
162{
Pau Pajuelob2310f12017-04-01 17:18:40 +0200163 if (get_board_revision() == 1)
164 config_ddr(400, &ioregs_igep0034, &ddr3_igep0034_data,
165 &ddr3_igep0034_cmd_ctrl_data, &ddr3_igep0034_emif_reg_data, 0);
166 else
167 config_ddr(400, &ioregs_igep0034_lite, &ddr3_igep0034_lite_data,
168 &ddr3_igep0034_lite_cmd_ctrl_data, &ddr3_igep0034_lite_emif_reg_data, 0);
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000169}
Ladislav Michl1e16bf72017-06-25 10:30:47 +0200170
171#ifdef CONFIG_SPL_OS_BOOT
172int spl_start_uboot(void)
173{
174 /* break into full u-boot on 'c' */
175 return serial_tstc() && serial_getc() == 'c';
176}
177#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530178#endif
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000179
180/*
181 * Basic board specific setup. Pinmux has been handled already.
182 */
183int board_init(void)
184{
Tom Rinif3b6a1d2013-08-09 11:22:13 -0400185 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000186
187 gpmc_init();
188
Pau Pajuelob2310f12017-04-01 17:18:40 +0200189 return 0;
190}
191
192#ifdef CONFIG_BOARD_LATE_INIT
193int board_late_init(void)
194{
195#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
196 switch (get_board_revision()) {
197 case 0:
Simon Glass6a38e412017-08-03 12:22:09 -0600198 env_set("board_name", "igep0034-lite");
Pau Pajuelob2310f12017-04-01 17:18:40 +0200199 break;
200 case 1:
Simon Glass6a38e412017-08-03 12:22:09 -0600201 env_set("board_name", "igep0034");
Pau Pajuelob2310f12017-04-01 17:18:40 +0200202 break;
203 default:
Simon Glass6a38e412017-08-03 12:22:09 -0600204 env_set("board_name", "igep0033");
Pau Pajuelob2310f12017-04-01 17:18:40 +0200205 break;
206 }
207#endif
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000208 return 0;
209}
Pau Pajuelob2310f12017-04-01 17:18:40 +0200210#endif
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000211
Ladislav Michlb6bd7f92017-04-01 17:17:57 +0200212#ifdef CONFIG_OF_BOARD_SETUP
213int ft_board_setup(void *blob, bd_t *bd)
214{
215#ifdef CONFIG_FDT_FIXUP_PARTITIONS
Masahiro Yamada20ead6f2018-07-19 16:28:23 +0900216 static const struct node_info nodes[] = {
Ladislav Michlb6bd7f92017-04-01 17:17:57 +0200217 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
218 };
219
220 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
221#endif
222 return 0;
223}
224#endif
225
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000226#if defined(CONFIG_DRIVER_TI_CPSW)
227static void cpsw_control(int enabled)
228{
229 /* VTP can be added here */
230
231 return;
232}
233
234static struct cpsw_slave_data cpsw_slaves[] = {
235 {
236 .slave_reg_ofs = 0x208,
237 .sliver_reg_ofs = 0xd80,
Mugunthan V N4944f372014-02-18 07:31:52 -0500238 .phy_addr = 0,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000239 .phy_if = PHY_INTERFACE_MODE_RMII,
240 },
241};
242
243static struct cpsw_platform_data cpsw_data = {
244 .mdio_base = CPSW_MDIO_BASE,
245 .cpsw_base = CPSW_BASE,
246 .mdio_div = 0xff,
247 .channels = 8,
248 .cpdma_reg_ofs = 0x800,
249 .slaves = 1,
250 .slave_data = cpsw_slaves,
251 .ale_reg_ofs = 0xd00,
252 .ale_entries = 1024,
253 .host_port_reg_ofs = 0x108,
254 .hw_stats_reg_ofs = 0x900,
Lars Poeschel949a6ad2013-09-30 09:51:34 +0200255 .bd_ram_ofs = 0x2000,
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000256 .mac_control = (1 << 5),
257 .control = cpsw_control,
258 .host_port_num = 0,
259 .version = CPSW_CTRL_VERSION_2,
260};
261
262int board_eth_init(bd_t *bis)
263{
264 int rv, ret = 0;
265 uint8_t mac_addr[6];
266 uint32_t mac_hi, mac_lo;
267
Simon Glass399a9ce2017-08-03 12:22:14 -0600268 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000269 /* try reading mac address from efuse */
270 mac_lo = readl(&cdev->macid0l);
271 mac_hi = readl(&cdev->macid0h);
272 mac_addr[0] = mac_hi & 0xFF;
273 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
274 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
275 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
276 mac_addr[4] = mac_lo & 0xFF;
277 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500278 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600279 eth_env_set_enetaddr("ethaddr", mac_addr);
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000280 }
281
Heiko Schocherc4fea292013-08-19 16:38:56 +0200282 writel((GMII1_SEL_RMII | RMII1_IO_CLK_EN),
283 &cdev->miisel);
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000284
Pau Pajuelob2310f12017-04-01 17:18:40 +0200285 if (get_board_revision() == 1)
286 cpsw_slaves[0].phy_addr = 1;
287
Enric Balletbo i Serra9b96f462013-04-04 22:27:58 +0000288 rv = cpsw_register(&cpsw_data);
289 if (rv < 0)
290 printf("Error %d registering CPSW switch\n", rv);
291 else
292 ret += rv;
293
294 return ret;
295}
296#endif