1 // SPDX-License-Identifier: GPL-2.0+
3 * Board functions for IGEP COM AQUILA and SMARC AM335x based boards
5 * Copyright (C) 2013-2017, ISEE 2007 SL - http://www.isee.biz/
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>
28 #include <fdt_support.h>
30 #include <jffs2/load_kernel.h>
33 DECLARE_GLOBAL_DATA_PTR;
35 /* 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
42 #define GPIO_GREEN_REVISION 27
43 #define GPIO_RED_REVISION 26
45 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
48 * Routine: get_board_revision
49 * Description: Returns the board revision
51 static int get_board_revision(void)
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);
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);
68 #ifdef CONFIG_SPL_BUILD
69 /* PN H5TQ4G63AFR is equivalent to MT41K256M16HA125*/
70 static 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,
77 static const struct ddr_data ddr3_igep0034_lite_data = {
78 .datardsratio0 = K4B2G1646EBIH9_RD_DQS,
79 .datawdsratio0 = K4B2G1646EBIH9_WR_DQS,
80 .datafwsratio0 = K4B2G1646EBIH9_PHY_FIFO_WE,
81 .datawrsratio0 = K4B2G1646EBIH9_PHY_WR_DATA,
84 static const struct cmd_control ddr3_igep0034_cmd_ctrl_data = {
85 .cmd0csratio = MT41K256M16HA125E_RATIO,
86 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
88 .cmd1csratio = MT41K256M16HA125E_RATIO,
89 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
91 .cmd2csratio = MT41K256M16HA125E_RATIO,
92 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
95 static const struct cmd_control ddr3_igep0034_lite_cmd_ctrl_data = {
96 .cmd0csratio = K4B2G1646EBIH9_RATIO,
97 .cmd0iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
99 .cmd1csratio = K4B2G1646EBIH9_RATIO,
100 .cmd1iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
102 .cmd2csratio = K4B2G1646EBIH9_RATIO,
103 .cmd2iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
106 static 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,
116 static struct emif_regs ddr3_igep0034_lite_emif_reg_data = {
117 .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,
126 const 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,
134 const 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,
142 #define OSC (V_OSCK/1000000)
143 const struct dpll_params dpll_ddr = {
144 400, OSC-1, 1, -1, -1, -1, -1};
146 const struct dpll_params *get_dpll_ddr_params(void)
151 void set_uart_mux_conf(void)
153 enable_uart0_pin_mux();
156 void set_mux_conf_regs(void)
158 enable_board_pin_mux();
161 void sdram_init(void)
163 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);
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);
171 #ifdef CONFIG_SPL_OS_BOOT
172 int spl_start_uboot(void)
174 /* break into full u-boot on 'c' */
175 return serial_tstc() && serial_getc() == 'c';
181 * Basic board specific setup. Pinmux has been handled already.
185 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
192 #ifdef CONFIG_BOARD_LATE_INIT
193 int board_late_init(void)
195 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
196 switch (get_board_revision()) {
198 env_set("board_name", "igep0034-lite");
201 env_set("board_name", "igep0034");
204 env_set("board_name", "igep0033");
212 #ifdef CONFIG_OF_BOARD_SETUP
213 int ft_board_setup(void *blob, bd_t *bd)
215 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
216 static const struct node_info nodes[] = {
217 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
220 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
226 #if defined(CONFIG_DRIVER_TI_CPSW)
227 static void cpsw_control(int enabled)
229 /* VTP can be added here */
234 static struct cpsw_slave_data cpsw_slaves[] = {
236 .slave_reg_ofs = 0x208,
237 .sliver_reg_ofs = 0xd80,
239 .phy_if = PHY_INTERFACE_MODE_RMII,
243 static struct cpsw_platform_data cpsw_data = {
244 .mdio_base = CPSW_MDIO_BASE,
245 .cpsw_base = CPSW_BASE,
248 .cpdma_reg_ofs = 0x800,
250 .slave_data = cpsw_slaves,
251 .ale_reg_ofs = 0xd00,
253 .host_port_reg_ofs = 0x108,
254 .hw_stats_reg_ofs = 0x900,
255 .bd_ram_ofs = 0x2000,
256 .mac_control = (1 << 5),
257 .control = cpsw_control,
259 .version = CPSW_CTRL_VERSION_2,
262 int board_eth_init(bd_t *bis)
266 uint32_t mac_hi, mac_lo;
268 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
269 /* 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;
278 if (is_valid_ethaddr(mac_addr))
279 eth_env_set_enetaddr("ethaddr", mac_addr);
282 writel((GMII1_SEL_RMII | RMII1_IO_CLK_EN),
285 if (get_board_revision() == 1)
286 cpsw_slaves[0].phy_addr = 1;
288 rv = cpsw_register(&cpsw_data);
290 printf("Error %d registering CPSW switch\n", rv);