blob: 9b4cb91b3418355853e8c90e092d49caa12554ab [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 Glass90526e92020-05-10 11:39:56 -060013#include <net.h>
Simon Glassb03e0512019-11-14 12:57:24 -070014#include <serial.h>
Enric Balletbo i Serra5f5c1d12013-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>
24#include <asm/io.h>
25#include <asm/emif.h>
26#include <asm/gpio.h>
27#include <i2c.h>
28#include <miiphy.h>
29#include <cpsw.h>
Ladislav Michl3607e0f2017-04-01 17:17:57 +020030#include <fdt_support.h>
31#include <mtd_node.h>
32#include <jffs2/load_kernel.h>
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000033#include "board.h"
34
35DECLARE_GLOBAL_DATA_PTR;
36
Pau Pajuelo09533e52017-04-01 17:18:40 +020037/* GPIO0_27 and GPIO0_26 are used to read board revision from IGEP003x boards
38 * and control IGEP0034 green and red LEDs.
39 * U-boot configures these pins as input pullup to detect board revision:
40 * IGEP0034-LITE = 0b00
41 * IGEP0034 (FULL) = 0b01
42 * IGEP0033 = 0b1X
43 */
44#define GPIO_GREEN_REVISION 27
45#define GPIO_RED_REVISION 26
46
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000047static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
48
Pau Pajuelo09533e52017-04-01 17:18:40 +020049/*
50 * Routine: get_board_revision
51 * Description: Returns the board revision
52 */
53static int get_board_revision(void)
54{
55 int revision;
56
57 gpio_request(GPIO_GREEN_REVISION, "green_revision");
58 gpio_direction_input(GPIO_GREEN_REVISION);
59 revision = 2 * gpio_get_value(GPIO_GREEN_REVISION);
60 gpio_free(GPIO_GREEN_REVISION);
61
62 gpio_request(GPIO_RED_REVISION, "red_revision");
63 gpio_direction_input(GPIO_RED_REVISION);
64 revision = revision + gpio_get_value(GPIO_RED_REVISION);
65 gpio_free(GPIO_RED_REVISION);
66
67 return revision;
68}
69
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000070#ifdef CONFIG_SPL_BUILD
Pau Pajuelo09533e52017-04-01 17:18:40 +020071/* PN H5TQ4G63AFR is equivalent to MT41K256M16HA125*/
72static const struct ddr_data ddr3_igep0034_data = {
73 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
74 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
75 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
76 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
77};
78
79static const struct ddr_data ddr3_igep0034_lite_data = {
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000080 .datardsratio0 = K4B2G1646EBIH9_RD_DQS,
81 .datawdsratio0 = K4B2G1646EBIH9_WR_DQS,
82 .datafwsratio0 = K4B2G1646EBIH9_PHY_FIFO_WE,
83 .datawrsratio0 = K4B2G1646EBIH9_PHY_WR_DATA,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000084};
85
Pau Pajuelo09533e52017-04-01 17:18:40 +020086static const struct cmd_control ddr3_igep0034_cmd_ctrl_data = {
87 .cmd0csratio = MT41K256M16HA125E_RATIO,
88 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
89
90 .cmd1csratio = MT41K256M16HA125E_RATIO,
91 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
92
93 .cmd2csratio = MT41K256M16HA125E_RATIO,
94 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
95};
96
97static const struct cmd_control ddr3_igep0034_lite_cmd_ctrl_data = {
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000098 .cmd0csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +000099 .cmd0iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
100
101 .cmd1csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000102 .cmd1iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
103
104 .cmd2csratio = K4B2G1646EBIH9_RATIO,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000105 .cmd2iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
106};
107
Pau Pajuelo09533e52017-04-01 17:18:40 +0200108static struct emif_regs ddr3_igep0034_emif_reg_data = {
109 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
110 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
111 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
112 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
113 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
114 .zq_config = MT41K256M16HA125E_ZQ_CFG,
115 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
116};
117
118static struct emif_regs ddr3_igep0034_lite_emif_reg_data = {
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000119 .sdram_config = K4B2G1646EBIH9_EMIF_SDCFG,
120 .ref_ctrl = K4B2G1646EBIH9_EMIF_SDREF,
121 .sdram_tim1 = K4B2G1646EBIH9_EMIF_TIM1,
122 .sdram_tim2 = K4B2G1646EBIH9_EMIF_TIM2,
123 .sdram_tim3 = K4B2G1646EBIH9_EMIF_TIM3,
124 .zq_config = K4B2G1646EBIH9_ZQ_CFG,
125 .emif_ddr_phy_ctlr_1 = K4B2G1646EBIH9_EMIF_READ_LATENCY,
126};
Lokesh Vutla94d77fb2013-07-30 10:48:52 +0530127
Pau Pajuelo09533e52017-04-01 17:18:40 +0200128const struct ctrl_ioregs ioregs_igep0034 = {
129 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
130 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
131 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
132 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
133 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
134};
135
136const struct ctrl_ioregs ioregs_igep0034_lite = {
137 .cm0ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
138 .cm1ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
139 .cm2ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
140 .dt0ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
141 .dt1ioctl = K4B2G1646EBIH9_IOCTRL_VALUE,
142};
143
Lokesh Vutla94d77fb2013-07-30 10:48:52 +0530144#define OSC (V_OSCK/1000000)
145const struct dpll_params dpll_ddr = {
Enric Balletbo i Serra94b32f62013-09-10 11:12:26 +0200146 400, OSC-1, 1, -1, -1, -1, -1};
Lokesh Vutla94d77fb2013-07-30 10:48:52 +0530147
148const struct dpll_params *get_dpll_ddr_params(void)
149{
150 return &dpll_ddr;
151}
152
Heiko Schocher06604812013-07-30 10:48:54 +0530153void set_uart_mux_conf(void)
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000154{
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000155 enable_uart0_pin_mux();
Heiko Schocher06604812013-07-30 10:48:54 +0530156}
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000157
Heiko Schocher06604812013-07-30 10:48:54 +0530158void set_mux_conf_regs(void)
159{
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000160 enable_board_pin_mux();
Heiko Schocher06604812013-07-30 10:48:54 +0530161}
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000162
Heiko Schocher06604812013-07-30 10:48:54 +0530163void sdram_init(void)
164{
Pau Pajuelo09533e52017-04-01 17:18:40 +0200165 if (get_board_revision() == 1)
166 config_ddr(400, &ioregs_igep0034, &ddr3_igep0034_data,
167 &ddr3_igep0034_cmd_ctrl_data, &ddr3_igep0034_emif_reg_data, 0);
168 else
169 config_ddr(400, &ioregs_igep0034_lite, &ddr3_igep0034_lite_data,
170 &ddr3_igep0034_lite_cmd_ctrl_data, &ddr3_igep0034_lite_emif_reg_data, 0);
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000171}
Ladislav Michlab3b7772017-06-25 10:30:47 +0200172
173#ifdef CONFIG_SPL_OS_BOOT
174int spl_start_uboot(void)
175{
176 /* break into full u-boot on 'c' */
177 return serial_tstc() && serial_getc() == 'c';
178}
179#endif
Heiko Schocher06604812013-07-30 10:48:54 +0530180#endif
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000181
182/*
183 * Basic board specific setup. Pinmux has been handled already.
184 */
185int board_init(void)
186{
Tom Rini73feefd2013-08-09 11:22:13 -0400187 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000188
189 gpmc_init();
190
191 return 0;
192}
193
Pau Pajuelo09533e52017-04-01 17:18:40 +0200194#ifdef CONFIG_BOARD_LATE_INIT
195int board_late_init(void)
196{
197#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
198 switch (get_board_revision()) {
199 case 0:
Simon Glass382bee52017-08-03 12:22:09 -0600200 env_set("board_name", "igep0034-lite");
Pau Pajuelo09533e52017-04-01 17:18:40 +0200201 break;
202 case 1:
Simon Glass382bee52017-08-03 12:22:09 -0600203 env_set("board_name", "igep0034");
Pau Pajuelo09533e52017-04-01 17:18:40 +0200204 break;
205 default:
Simon Glass382bee52017-08-03 12:22:09 -0600206 env_set("board_name", "igep0033");
Pau Pajuelo09533e52017-04-01 17:18:40 +0200207 break;
208 }
209#endif
210 return 0;
211}
212#endif
213
Ladislav Michl3607e0f2017-04-01 17:17:57 +0200214#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900215int ft_board_setup(void *blob, struct bd_info *bd)
Ladislav Michl3607e0f2017-04-01 17:17:57 +0200216{
217#ifdef CONFIG_FDT_FIXUP_PARTITIONS
Masahiro Yamadab35fb6a2018-07-19 16:28:23 +0900218 static const struct node_info nodes[] = {
Ladislav Michl3607e0f2017-04-01 17:17:57 +0200219 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
220 };
221
222 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
223#endif
224 return 0;
225}
226#endif
227
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000228#if defined(CONFIG_DRIVER_TI_CPSW)
229static void cpsw_control(int enabled)
230{
231 /* VTP can be added here */
232
233 return;
234}
235
236static struct cpsw_slave_data cpsw_slaves[] = {
237 {
238 .slave_reg_ofs = 0x208,
239 .sliver_reg_ofs = 0xd80,
Mugunthan V N9c653aa2014-02-18 07:31:52 -0500240 .phy_addr = 0,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000241 .phy_if = PHY_INTERFACE_MODE_RMII,
242 },
243};
244
245static struct cpsw_platform_data cpsw_data = {
246 .mdio_base = CPSW_MDIO_BASE,
247 .cpsw_base = CPSW_BASE,
248 .mdio_div = 0xff,
249 .channels = 8,
250 .cpdma_reg_ofs = 0x800,
251 .slaves = 1,
252 .slave_data = cpsw_slaves,
253 .ale_reg_ofs = 0xd00,
254 .ale_entries = 1024,
255 .host_port_reg_ofs = 0x108,
256 .hw_stats_reg_ofs = 0x900,
Lars Poeschel6478cde2013-09-30 09:51:34 +0200257 .bd_ram_ofs = 0x2000,
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000258 .mac_control = (1 << 5),
259 .control = cpsw_control,
260 .host_port_num = 0,
261 .version = CPSW_CTRL_VERSION_2,
262};
263
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900264int board_eth_init(struct bd_info *bis)
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000265{
266 int rv, ret = 0;
267 uint8_t mac_addr[6];
268 uint32_t mac_hi, mac_lo;
269
Simon Glass35affd72017-08-03 12:22:14 -0600270 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000271 /* try reading mac address from efuse */
272 mac_lo = readl(&cdev->macid0l);
273 mac_hi = readl(&cdev->macid0h);
274 mac_addr[0] = mac_hi & 0xFF;
275 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
276 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
277 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
278 mac_addr[4] = mac_lo & 0xFF;
279 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500280 if (is_valid_ethaddr(mac_addr))
Simon Glassfd1e9592017-08-03 12:22:11 -0600281 eth_env_set_enetaddr("ethaddr", mac_addr);
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000282 }
283
Heiko Schocherdafd4db2013-08-19 16:38:56 +0200284 writel((GMII1_SEL_RMII | RMII1_IO_CLK_EN),
285 &cdev->miisel);
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000286
Pau Pajuelo09533e52017-04-01 17:18:40 +0200287 if (get_board_revision() == 1)
288 cpsw_slaves[0].phy_addr = 1;
289
Enric Balletbo i Serra5f5c1d12013-04-04 22:27:58 +0000290 rv = cpsw_register(&cpsw_data);
291 if (rv < 0)
292 printf("Error %d registering CPSW switch\n", rv);
293 else
294 ret += rv;
295
296 return ret;
297}
298#endif