blob: 0370db67e49309ff74a6319a5375ba914444b9aa [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevam5c824dd2013-09-26 22:59:25 -03002/*
3 * Copyright (C) 2013 Freescale Semiconductor, Inc.
4 *
5 * Author: Fabio Estevam <fabio.estevam@freescale.com>
Fabio Estevam5c824dd2013-09-26 22:59:25 -03006 */
7
Simon Glassa7b51302019-11-14 12:57:46 -07008#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06009#include <net.h>
Fabio Estevam5c824dd2013-09-26 22:59:25 -030010#include <asm/arch/clock.h>
11#include <asm/arch/imx-regs.h>
12#include <asm/arch/iomux.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060013#include <env.h>
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +010014#include <malloc.h>
Fabio Estevam5c824dd2013-09-26 22:59:25 -030015#include <asm/arch/mx6-pins.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090016#include <linux/errno.h>
Fabio Estevam5c824dd2013-09-26 22:59:25 -030017#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/iomux-v3.h>
19#include <asm/mach-imx/sata.h>
Fabio Estevam5c824dd2013-09-26 22:59:25 -030020#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080021#include <fsl_esdhc_imx.h>
Fabio Estevam5c824dd2013-09-26 22:59:25 -030022#include <asm/arch/crm_regs.h>
23#include <asm/io.h>
24#include <asm/arch/sys_proto.h>
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +010025#include <micrel.h>
26#include <miiphy.h>
27#include <netdev.h>
Fabio Estevam5c824dd2013-09-26 22:59:25 -030028
29DECLARE_GLOBAL_DATA_PTR;
30
31#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
32 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
33 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
34
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +010035#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
36 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
37
Fabio Estevam5c824dd2013-09-26 22:59:25 -030038#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
39 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
40 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
41
42#define WDT_EN IMX_GPIO_NR(5, 4)
43#define WDT_TRG IMX_GPIO_NR(3, 19)
44
45int dram_init(void)
46{
vpeter476b08ce2015-08-03 12:49:05 +020047 gd->ram_size = imx_ddr_size();
Fabio Estevam5c824dd2013-09-26 22:59:25 -030048
49 return 0;
50}
51
52static iomux_v3_cfg_t const uart2_pads[] = {
vpeter476b08ce2015-08-03 12:49:05 +020053 IOMUX_PADS(PAD_EIM_D26__UART2_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
54 IOMUX_PADS(PAD_EIM_D27__UART2_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevam5c824dd2013-09-26 22:59:25 -030055};
56
57static iomux_v3_cfg_t const usdhc3_pads[] = {
vpeter476b08ce2015-08-03 12:49:05 +020058 IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
59 IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
60 IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
61 IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
62 IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
63 IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Fabio Estevam5c824dd2013-09-26 22:59:25 -030064};
65
66static iomux_v3_cfg_t const wdog_pads[] = {
vpeter476b08ce2015-08-03 12:49:05 +020067 IOMUX_PADS(PAD_EIM_A24__GPIO5_IO04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
68 IOMUX_PADS(PAD_EIM_D19__GPIO3_IO19),
Fabio Estevam5c824dd2013-09-26 22:59:25 -030069};
70
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +010071int mx6_rgmii_rework(struct phy_device *phydev)
72{
73 /*
74 * Bug: Apparently uDoo does not works with Gigabit switches...
75 * Limiting speed to 10/100Mbps, and setting master mode, seems to
76 * be the only way to have a successfull PHY auto negotiation.
77 * How to fix: Understand why Linux kernel do not have this issue.
78 */
79 phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, 0x1c00);
80
81 /* control data pad skew - devaddr = 0x02, register = 0x04 */
82 ksz9031_phy_extended_write(phydev, 0x02,
83 MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW,
84 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
85 /* rx data pad skew - devaddr = 0x02, register = 0x05 */
86 ksz9031_phy_extended_write(phydev, 0x02,
87 MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW,
88 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
89 /* tx data pad skew - devaddr = 0x02, register = 0x05 */
90 ksz9031_phy_extended_write(phydev, 0x02,
91 MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW,
92 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x0000);
93 /* gtx and rx clock pad skew - devaddr = 0x02, register = 0x08 */
94 ksz9031_phy_extended_write(phydev, 0x02,
95 MII_KSZ9031_EXT_RGMII_CLOCK_SKEW,
96 MII_KSZ9031_MOD_DATA_NO_POST_INC, 0x03FF);
97 return 0;
98}
99
100static iomux_v3_cfg_t const enet_pads1[] = {
vpeter476b08ce2015-08-03 12:49:05 +0200101 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
102 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
103 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
104 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
105 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
106 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
107 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
108 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
109 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL)),
110 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100111 /* RGMII reset */
vpeter476b08ce2015-08-03 12:49:05 +0200112 IOMUX_PADS(PAD_EIM_D23__GPIO3_IO23 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100113 /* Ethernet power supply */
vpeter476b08ce2015-08-03 12:49:05 +0200114 IOMUX_PADS(PAD_EIM_EB3__GPIO2_IO31 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100115 /* pin 32 - 1 - (MODE0) all */
vpeter476b08ce2015-08-03 12:49:05 +0200116 IOMUX_PADS(PAD_RGMII_RD0__GPIO6_IO25 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100117 /* pin 31 - 1 - (MODE1) all */
vpeter476b08ce2015-08-03 12:49:05 +0200118 IOMUX_PADS(PAD_RGMII_RD1__GPIO6_IO27 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100119 /* pin 28 - 1 - (MODE2) all */
vpeter476b08ce2015-08-03 12:49:05 +0200120 IOMUX_PADS(PAD_RGMII_RD2__GPIO6_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100121 /* pin 27 - 1 - (MODE3) all */
vpeter476b08ce2015-08-03 12:49:05 +0200122 IOMUX_PADS(PAD_RGMII_RD3__GPIO6_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100123 /* pin 33 - 1 - (CLK125_EN) 125Mhz clockout enabled */
vpeter476b08ce2015-08-03 12:49:05 +0200124 IOMUX_PADS(PAD_RGMII_RX_CTL__GPIO6_IO24 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100125};
126
127static iomux_v3_cfg_t const enet_pads2[] = {
vpeter476b08ce2015-08-03 12:49:05 +0200128 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
129 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
130 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
131 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
132 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL)),
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100133};
134
135static void setup_iomux_enet(void)
136{
vpeter476b08ce2015-08-03 12:49:05 +0200137 SETUP_IOMUX_PADS(enet_pads1);
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100138 udelay(20);
139 gpio_direction_output(IMX_GPIO_NR(2, 31), 1); /* Power supply on */
140
141 gpio_direction_output(IMX_GPIO_NR(3, 23), 0); /* assert PHY rst */
142
143 gpio_direction_output(IMX_GPIO_NR(6, 24), 1);
144 gpio_direction_output(IMX_GPIO_NR(6, 25), 1);
145 gpio_direction_output(IMX_GPIO_NR(6, 27), 1);
146 gpio_direction_output(IMX_GPIO_NR(6, 28), 1);
147 gpio_direction_output(IMX_GPIO_NR(6, 29), 1);
148 udelay(1000);
149
150 gpio_set_value(IMX_GPIO_NR(3, 23), 1); /* deassert PHY rst */
151
152 /* Need 100ms delay to exit from reset. */
153 udelay(1000 * 100);
154
155 gpio_free(IMX_GPIO_NR(6, 24));
156 gpio_free(IMX_GPIO_NR(6, 25));
157 gpio_free(IMX_GPIO_NR(6, 27));
158 gpio_free(IMX_GPIO_NR(6, 28));
159 gpio_free(IMX_GPIO_NR(6, 29));
160
vpeter476b08ce2015-08-03 12:49:05 +0200161 SETUP_IOMUX_PADS(enet_pads2);
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100162}
163
Fabio Estevam5c824dd2013-09-26 22:59:25 -0300164static void setup_iomux_uart(void)
165{
vpeter476b08ce2015-08-03 12:49:05 +0200166 SETUP_IOMUX_PADS(uart2_pads);
Fabio Estevam5c824dd2013-09-26 22:59:25 -0300167}
168
169static void setup_iomux_wdog(void)
170{
vpeter476b08ce2015-08-03 12:49:05 +0200171 SETUP_IOMUX_PADS(wdog_pads);
Fabio Estevam5c824dd2013-09-26 22:59:25 -0300172 gpio_direction_output(WDT_TRG, 0);
173 gpio_direction_output(WDT_EN, 1);
Giuseppe Paganoc1546692013-11-15 17:42:54 +0100174 gpio_direction_input(WDT_TRG);
Fabio Estevam5c824dd2013-09-26 22:59:25 -0300175}
176
177static struct fsl_esdhc_cfg usdhc_cfg = { USDHC3_BASE_ADDR };
178
179int board_mmc_getcd(struct mmc *mmc)
180{
181 return 1; /* Always present */
182}
183
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100184int board_eth_init(bd_t *bis)
185{
186 uint32_t base = IMX_FEC_BASE;
187 struct mii_dev *bus = NULL;
188 struct phy_device *phydev = NULL;
189 int ret;
190
191 setup_iomux_enet();
192
193#ifdef CONFIG_FEC_MXC
194 bus = fec_get_miibus(base, -1);
195 if (!bus)
Fabio Estevam49ea64a2015-09-11 13:32:50 -0300196 return -EINVAL;
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100197 /* scan phy 4,5,6,7 */
198 phydev = phy_find_by_mask(bus, (0xf << 4), PHY_INTERFACE_MODE_RGMII);
199
200 if (!phydev) {
Fabio Estevam49ea64a2015-09-11 13:32:50 -0300201 ret = -EINVAL;
202 goto free_bus;
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100203 }
204 printf("using phy at %d\n", phydev->addr);
205 ret = fec_probe(bis, -1, base, bus, phydev);
Fabio Estevam49ea64a2015-09-11 13:32:50 -0300206 if (ret)
207 goto free_phydev;
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100208#endif
209 return 0;
Fabio Estevam49ea64a2015-09-11 13:32:50 -0300210
211free_phydev:
212 free(phydev);
213free_bus:
214 free(bus);
215 return ret;
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100216}
217
Fabio Estevam5c824dd2013-09-26 22:59:25 -0300218int board_mmc_init(bd_t *bis)
219{
vpeter476b08ce2015-08-03 12:49:05 +0200220 SETUP_IOMUX_PADS(usdhc3_pads);
Fabio Estevam5c824dd2013-09-26 22:59:25 -0300221 usdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
222 usdhc_cfg.max_bus_width = 4;
223
224 return fsl_esdhc_initialize(bis, &usdhc_cfg);
225}
226
227int board_early_init_f(void)
228{
229 setup_iomux_wdog();
230 setup_iomux_uart();
231
232 return 0;
233}
234
Giuseppe Paganocbadb0b2013-11-15 17:42:51 +0100235int board_phy_config(struct phy_device *phydev)
236{
237 mx6_rgmii_rework(phydev);
238 if (phydev->drv->config)
239 phydev->drv->config(phydev);
240
241 return 0;
242}
243
Fabio Estevam5c824dd2013-09-26 22:59:25 -0300244int board_init(void)
245{
246 /* address of boot parameters */
247 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
248
Simon Glassab3055a2017-06-14 21:28:25 -0600249#ifdef CONFIG_SATA
Fabio Estevam997b1452017-10-15 11:21:07 -0200250 setup_sata();
Giuseppe Pagano3fe87cd2013-11-28 12:32:49 +0100251#endif
Fabio Estevam5c824dd2013-09-26 22:59:25 -0300252 return 0;
253}
254
vpeter476b08ce2015-08-03 12:49:05 +0200255int board_late_init(void)
256{
257#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
258 if (is_cpu_type(MXC_CPU_MX6Q))
Simon Glass6a38e412017-08-03 12:22:09 -0600259 env_set("board_rev", "MX6Q");
vpeter476b08ce2015-08-03 12:49:05 +0200260 else
Simon Glass6a38e412017-08-03 12:22:09 -0600261 env_set("board_rev", "MX6DL");
vpeter476b08ce2015-08-03 12:49:05 +0200262#endif
263 return 0;
264}
265
Fabio Estevam5c824dd2013-09-26 22:59:25 -0300266int checkboard(void)
267{
vpeter476b08ce2015-08-03 12:49:05 +0200268 if (is_cpu_type(MXC_CPU_MX6Q))
269 puts("Board: Udoo Quad\n");
270 else
271 puts("Board: Udoo DualLite\n");
Fabio Estevam5c824dd2013-09-26 22:59:25 -0300272
273 return 0;
274}