blob: b0f8d8a314a5cf8e53f50faaccc8400c49a9a0ae [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +00002/*
Pau Pajuelo09533e52017-04-01 17:18:40 +02003 * Board functions for IGEP COM AQUILA and SMARC AM335x based boards
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +00004 *
Pau Pajuelo09533e52017-04-01 17:18:40 +02005 * Copyright (C) 2013-2017, ISEE 2007 SL - http://www.isee.biz/
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +00006 */
7
8#include <common.h>
Simon Glass9fb625c2019-08-01 09:46:51 -06009#include <env.h>
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000010#include <errno.h>
Simon Glass52559322019-11-14 12:57:46 -070011#include <init.h>
Simon Glass336d4612020-02-03 07:36:16 -070012#include <malloc.h>
Simon Glassb03e0512019-11-14 12:57:24 -070013#include <serial.h>
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000014#include <spl.h>
15#include <asm/arch/cpu.h>
16#include <asm/arch/hardware.h>
17#include <asm/arch/omap.h>
18#include <asm/arch/ddr_defs.h>
19#include <asm/arch/clock.h>
20#include <asm/arch/gpio.h>
21#include <asm/arch/mmc_host_def.h>
22#include <asm/arch/sys_proto.h>
23#include <asm/io.h>
24#include <asm/emif.h>
25#include <asm/gpio.h>
26#include <i2c.h>
27#include <miiphy.h>
28#include <cpsw.h>
Ladislav Michl3607e0f2017-04-01 17:17:57 +020029#include <fdt_support.h>
30#include <mtd_node.h>
31#include <jffs2/load_kernel.h>
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000032#include "board.h"
33
34DECLARE_GLOBAL_DATA_PTR;
35
Pau Pajuelo09533e52017-04-01 17:18:40 +020036/* GPIO0_27 and GPIO0_26 are used to read board revision from IGEP003x boards
37 * and control IGEP0034 green and red LEDs.
38 * U-boot configures these pins as input pullup to detect board revision:
39 * IGEP0034-LITE = 0b00
40 * IGEP0034 (FULL) = 0b01
41 * IGEP0033 = 0b1X
42 */
43#define GPIO_GREEN_REVISION 27
44#define GPIO_RED_REVISION 26
45
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000046static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
47
Pau Pajuelo09533e52017-04-01 17:18:40 +020048/*
49 * Routine: get_board_revision
50 * Description: Returns the board revision
51 */
52static int get_board_revision(void)
53{
54 int revision;
55
56 gpio_request(GPIO_GREEN_REVISION, "green_revision");
57 gpio_direction_input(GPIO_GREEN_REVISION);
58 revision = 2 * gpio_get_value(GPIO_GREEN_REVISION);
59 gpio_free(GPIO_GREEN_REVISION);
60
61 gpio_request(GPIO_RED_REVISION, "red_revision");
62 gpio_direction_input(GPIO_RED_REVISION);
63 revision = revision + gpio_get_value(GPIO_RED_REVISION);
64 gpio_free(GPIO_RED_REVISION);
65
66 return revision;
67}
68
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000069#ifdef CONFIG_SPL_BUILD
Pau Pajuelo09533e52017-04-01 17:18:40 +020070/* PN H5TQ4G63AFR is equivalent to MT41K256M16HA125*/
71static const struct ddr_data ddr3_igep0034_data = {
72 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
73 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
74 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
75 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
76};
77
78static const struct ddr_data ddr3_igep0034_lite_data = {
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000079 .datardsratio0 = K4B2G1646EBIH9_RD_DQS,
80 .datawdsratio0 = K4B2G1646EBIH9_WR_DQS,
81 .datafwsratio0 = K4B2G1646EBIH9_PHY_FIFO_WE,
82 .datawrsratio0 = K4B2G1646EBIH9_PHY_WR_DATA,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000083};
84
Pau Pajuelo09533e52017-04-01 17:18:40 +020085static const struct cmd_control ddr3_igep0034_cmd_ctrl_data = {
86 .cmd0csratio = MT41K256M16HA125E_RATIO,
87 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
88
89 .cmd1csratio = MT41K256M16HA125E_RATIO,
90 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
91
92 .cmd2csratio = MT41K256M16HA125E_RATIO,
93 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
94};
95
96static const struct cmd_control ddr3_igep0034_lite_cmd_ctrl_data = {
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000097 .cmd0csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000098 .cmd0iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
99
100 .cmd1csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000101 .cmd1iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
102
103 .cmd2csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000104 .cmd2iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
105};
106
Pau Pajuelo09533e52017-04-01 17:18:40 +0200107static struct emif_regs ddr3_igep0034_emif_reg_data = {
108 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
109 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
110 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
111 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
112 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
113 .zq_config = MT41K256M16HA125E_ZQ_CFG,
114 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
115};
116
117static struct emif_regs ddr3_igep0034_lite_emif_reg_data = {
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000118 .sdram_config = K4B2G1646EBIH9_EMIF_SDCFG,
119 .ref_ctrl = K4B2G1646EBIH9_EMIF_SDREF,
120 .sdram_tim1 = K4B2G1646EBIH9_EMIF_TIM1,
121 .sdram_tim2 = K4B2G1646EBIH9_EMIF_TIM2,
122 .sdram_tim3 = K4B2G1646EBIH9_EMIF_TIM3,
123 .zq_config = K4B2G1646EBIH9_ZQ_CFG,
124 .emif_ddr_phy_ctlr_1 = K4B2G1646EBIH9_EMIF_READ_LATENCY,
125};
Lokesh Vutla94d77fb2013-07-30 10:48:52 +0530126
Pau Pajuelo09533e52017-04-01 17:18:40 +0200127const struct ctrl_ioregs ioregs_igep0034 = {
128 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
129 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
130 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
131 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
132 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
133};
134
135const struct ctrl_ioregs ioregs_igep0034_lite = {
136 .cm0ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
137 .cm1ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
138 .cm2ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
139 .dt0ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
140 .dt1ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
141};
142
Lokesh Vutla94d77fb2013-07-30 10:48:52 +0530143#define OSC (V_OSCK/1000000)
144const struct dpll_params dpll_ddr = {
Enric Balletbo i Serra94b32f62013-09-10 11:12:26 +0200145 400, OSC-1, 1, -1, -1, -1, -1};
Lokesh Vutla94d77fb2013-07-30 10:48:52 +0530146
147const struct dpll_params *get_dpll_ddr_params(void)
148{
149 return &dpll_ddr;
150}
151
Heiko Schocher06604812013-07-30 10:48:54 +0530152void set_uart_mux_conf(void)
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000153{
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000154 enable_uart0_pin_mux();
Heiko Schocher06604812013-07-30 10:48:54 +0530155}
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000156
Heiko Schocher06604812013-07-30 10:48:54 +0530157void set_mux_conf_regs(void)
158{
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000159 enable_board_pin_mux();
Heiko Schocher06604812013-07-30 10:48:54 +0530160}
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000161
Heiko Schocher06604812013-07-30 10:48:54 +0530162void sdram_init(void)
163{
Pau Pajuelo09533e52017-04-01 17:18:40 +0200164 if (get_board_revision() == 1)
165 config_ddr(400, &ioregs_igep0034, &ddr3_igep0034_data,
166 &ddr3_igep0034_cmd_ctrl_data, &ddr3_igep0034_emif_reg_data, 0);
167 else
168 config_ddr(400, &ioregs_igep0034_lite, &ddr3_igep0034_lite_data,
169 &ddr3_igep0034_lite_cmd_ctrl_data, &ddr3_igep0034_lite_emif_reg_data, 0);
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000170}
Ladislav Michlab3b7772017-06-25 10:30:47 +0200171
172#ifdef CONFIG_SPL_OS_BOOT
173int spl_start_uboot(void)
174{
175 /* break into full u-boot on 'c' */
176 return serial_tstc() && serial_getc() == 'c';
177}
178#endif
Heiko Schocher06604812013-07-30 10:48:54 +0530179#endif
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000180
181/*
182 * Basic board specific setup. Pinmux has been handled already.
183 */
184int board_init(void)
185{
Tom Rini73feefd2013-08-09 11:22:13 -0400186 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000187
188 gpmc_init();
189
190 return 0;
191}
192
Pau Pajuelo09533e52017-04-01 17:18:40 +0200193#ifdef CONFIG_BOARD_LATE_INIT
194int board_late_init(void)
195{
196#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
197 switch (get_board_revision()) {
198 case 0:
Simon Glass382bee52017-08-03 12:22:09 -0600199 env_set("board_name", "igep0034-lite");
Pau Pajuelo09533e52017-04-01 17:18:40 +0200200 break;
201 case 1:
Simon Glass382bee52017-08-03 12:22:09 -0600202 env_set("board_name", "igep0034");
Pau Pajuelo09533e52017-04-01 17:18:40 +0200203 break;
204 default:
Simon Glass382bee52017-08-03 12:22:09 -0600205 env_set("board_name", "igep0033");
Pau Pajuelo09533e52017-04-01 17:18:40 +0200206 break;
207 }
208#endif
209 return 0;
210}
211#endif
212
Ladislav Michl3607e0f2017-04-01 17:17:57 +0200213#ifdef CONFIG_OF_BOARD_SETUP
214int ft_board_setup(void *blob, bd_t *bd)
215{
216#ifdef CONFIG_FDT_FIXUP_PARTITIONS
Masahiro Yamadab35fb6a2018-07-19 16:28:23 +0900217 static const struct node_info nodes[] = {
Ladislav Michl3607e0f2017-04-01 17:17:57 +0200218 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
219 };
220
221 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
222#endif
223 return 0;
224}
225#endif
226
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000227#if defined(CONFIG_DRIVER_TI_CPSW)
228static void cpsw_control(int enabled)
229{
230 /* VTP can be added here */
231
232 return;
233}
234
235static struct cpsw_slave_data cpsw_slaves[] = {
236 {
237 .slave_reg_ofs = 0x208,
238 .sliver_reg_ofs = 0xd80,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500239 .phy_addr = 0,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000240 .phy_if = PHY_INTERFACE_MODE_RMII,
241 },
242};
243
244static struct cpsw_platform_data cpsw_data = {
245 .mdio_base = CPSW_MDIO_BASE,
246 .cpsw_base = CPSW_BASE,
247 .mdio_div = 0xff,
248 .channels = 8,
249 .cpdma_reg_ofs = 0x800,
250 .slaves = 1,
251 .slave_data = cpsw_slaves,
252 .ale_reg_ofs = 0xd00,
253 .ale_entries = 1024,
254 .host_port_reg_ofs = 0x108,
255 .hw_stats_reg_ofs = 0x900,
Lars Poeschel6478cde2013-09-30 09:51:34 +0200256 .bd_ram_ofs = 0x2000,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000257 .mac_control = (1 << 5),
258 .control = cpsw_control,
259 .host_port_num = 0,
260 .version = CPSW_CTRL_VERSION_2,
261};
262
263int board_eth_init(bd_t *bis)
264{
265 int rv, ret = 0;
266 uint8_t mac_addr[6];
267 uint32_t mac_hi, mac_lo;
268
Simon Glass35affd72017-08-03 12:22:14 -0600269 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000270 /* try reading mac address from efuse */
271 mac_lo = readl(&cdev->macid0l);
272 mac_hi = readl(&cdev->macid0h);
273 mac_addr[0] = mac_hi & 0xFF;
274 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
275 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
276 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
277 mac_addr[4] = mac_lo & 0xFF;
278 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500279 if (is_valid_ethaddr(mac_addr))
Simon Glassfd1e9592017-08-03 12:22:11 -0600280 eth_env_set_enetaddr("ethaddr", mac_addr);
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000281 }
282
Heiko Schocherdafd4db2013-08-19 16:38:56 +0200283 writel((GMII1_SEL_RMII | RMII1_IO_CLK_EN),
284 &cdev->miisel);
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000285
Pau Pajuelo09533e52017-04-01 17:18:40 +0200286 if (get_board_revision() == 1)
287 cpsw_slaves[0].phy_addr = 1;
288
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000289 rv = cpsw_register(&cpsw_data);
290 if (rv < 0)
291 printf("Error %d registering CPSW switch\n", rv);
292 else
293 ret += rv;
294
295 return ret;
296}
297#endif