blob: b092ea80538977fd37a36186c76abca43cc3ba65 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevam14a16132014-06-24 17:41:01 -03002/*
3 * Copyright (C) 2014 Freescale Semiconductor, Inc.
4 *
5 * Author: Fabio Estevam <fabio.estevam@freescale.com>
Fabio Estevam14a16132014-06-24 17:41:01 -03006 */
7
Simon Glass52559322019-11-14 12:57:46 -07008#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -06009#include <net.h>
Fabio Estevam14a16132014-06-24 17:41:01 -030010#include <asm/arch/clock.h>
Fabio Estevamd1458782014-08-15 00:24:29 -030011#include <asm/arch/crm_regs.h>
Fabio Estevam14a16132014-06-24 17:41:01 -030012#include <asm/arch/iomux.h>
13#include <asm/arch/imx-regs.h>
14#include <asm/arch/mx6-pins.h>
15#include <asm/arch/sys_proto.h>
16#include <asm/gpio.h>
Stefano Babic552a8482017-06-29 10:16:06 +020017#include <asm/mach-imx/iomux-v3.h>
Fabio Estevam14a16132014-06-24 17:41:01 -030018#include <asm/io.h>
Stefano Babic552a8482017-06-29 10:16:06 +020019#include <asm/mach-imx/mxc_i2c.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060020#include <env.h>
Simon Glassc05ed002020-05-10 11:40:11 -060021#include <linux/delay.h>
Fabio Estevam14a16132014-06-24 17:41:01 -030022#include <linux/sizes.h>
23#include <common.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080024#include <fsl_esdhc_imx.h>
Fabio Estevam14a16132014-06-24 17:41:01 -030025#include <mmc.h>
Fabio Estevamfa8cf312014-07-09 16:13:30 -030026#include <i2c.h>
Fabio Estevamd1458782014-08-15 00:24:29 -030027#include <miiphy.h>
28#include <netdev.h>
Fabio Estevamfa8cf312014-07-09 16:13:30 -030029#include <power/pmic.h>
30#include <power/pfuze100_pmic.h>
Ye.Li1f98e312014-11-06 16:29:01 +080031#include "../common/pfuze.h"
Fabio Estevam14a16132014-06-24 17:41:01 -030032
33DECLARE_GLOBAL_DATA_PTR;
34
35#define UART_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
36 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
37 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
38
39#define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
40 PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \
41 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
42
Fabio Estevamd1458782014-08-15 00:24:29 -030043#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_PUE | \
44 PAD_CTL_SPEED_HIGH | \
45 PAD_CTL_DSE_48ohm | PAD_CTL_SRE_FAST)
46
47#define ENET_CLK_PAD_CTRL (PAD_CTL_SPEED_MED | \
48 PAD_CTL_DSE_120ohm | PAD_CTL_SRE_FAST)
49
50#define ENET_RX_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
51 PAD_CTL_SPEED_HIGH | PAD_CTL_SRE_FAST)
52
Ye Li85eb0952016-01-26 22:09:40 +080053#define LCD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP | PAD_CTL_PUE | \
54 PAD_CTL_PKE | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm)
55
Peng Fane80f9e12018-01-02 09:32:09 +080056#define WDOG_PAD_CTRL (PAD_CTL_PUE | PAD_CTL_PKE | PAD_CTL_SPEED_MED | \
57 PAD_CTL_DSE_40ohm)
58
Fabio Estevam14a16132014-06-24 17:41:01 -030059int dram_init(void)
60{
Vanessa Maegimad6b0c462016-06-09 15:28:33 -030061 gd->ram_size = imx_ddr_size();
Fabio Estevam14a16132014-06-24 17:41:01 -030062
63 return 0;
64}
65
66static iomux_v3_cfg_t const uart1_pads[] = {
67 MX6_PAD_GPIO1_IO04__UART1_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
68 MX6_PAD_GPIO1_IO05__UART1_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
69};
70
Peng Fane80f9e12018-01-02 09:32:09 +080071static iomux_v3_cfg_t const wdog_b_pad = {
72 MX6_PAD_GPIO1_IO13__GPIO1_IO_13 | MUX_PAD_CTRL(WDOG_PAD_CTRL),
73};
Fabio Estevamd1458782014-08-15 00:24:29 -030074static iomux_v3_cfg_t const fec1_pads[] = {
75 MX6_PAD_ENET1_MDC__ENET1_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
76 MX6_PAD_ENET1_MDIO__ENET1_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
77 MX6_PAD_RGMII1_RX_CTL__ENET1_RX_EN | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
78 MX6_PAD_RGMII1_RD0__ENET1_RX_DATA_0 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
79 MX6_PAD_RGMII1_RD1__ENET1_RX_DATA_1 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
80 MX6_PAD_RGMII1_RD2__ENET1_RX_DATA_2 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
81 MX6_PAD_RGMII1_RD3__ENET1_RX_DATA_3 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
82 MX6_PAD_RGMII1_RXC__ENET1_RX_CLK | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
83 MX6_PAD_RGMII1_TX_CTL__ENET1_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),
84 MX6_PAD_RGMII1_TD0__ENET1_TX_DATA_0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
85 MX6_PAD_RGMII1_TD1__ENET1_TX_DATA_1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
86 MX6_PAD_RGMII1_TD2__ENET1_TX_DATA_2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
87 MX6_PAD_RGMII1_TD3__ENET1_TX_DATA_3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
88 MX6_PAD_RGMII1_TXC__ENET1_RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
89};
90
91static iomux_v3_cfg_t const peri_3v3_pads[] = {
92 MX6_PAD_QSPI1A_DATA0__GPIO4_IO_16 | MUX_PAD_CTRL(NO_PAD_CTRL),
93};
94
95static iomux_v3_cfg_t const phy_control_pads[] = {
96 /* 25MHz Ethernet PHY Clock */
97 MX6_PAD_ENET2_RX_CLK__ENET2_REF_CLK_25M | MUX_PAD_CTRL(ENET_CLK_PAD_CTRL),
98
99 /* ENET PHY Power */
100 MX6_PAD_ENET2_COL__GPIO2_IO_6 | MUX_PAD_CTRL(NO_PAD_CTRL),
101
102 /* AR8031 PHY Reset */
103 MX6_PAD_ENET2_CRS__GPIO2_IO_7 | MUX_PAD_CTRL(NO_PAD_CTRL),
104};
105
Fabio Estevam14a16132014-06-24 17:41:01 -0300106static void setup_iomux_uart(void)
107{
108 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
109}
110
Fabio Estevamd1458782014-08-15 00:24:29 -0300111static int setup_fec(void)
112{
113 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
114 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Fabio Estevam29bc24e2015-11-23 16:18:02 -0200115 int reg, ret;
Fabio Estevamd1458782014-08-15 00:24:29 -0300116
117 /* Use 125MHz anatop loopback REF_CLK1 for ENET1 */
118 clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC1_MASK, 0);
119
Fabio Estevam29bc24e2015-11-23 16:18:02 -0200120 ret = enable_fec_anatop_clock(0, ENET_125MHZ);
121 if (ret)
122 return ret;
123
Fabio Estevamd1458782014-08-15 00:24:29 -0300124 imx_iomux_v3_setup_multiple_pads(phy_control_pads,
125 ARRAY_SIZE(phy_control_pads));
126
127 /* Enable the ENET power, active low */
Peng Fan5dfc9d32018-01-02 09:32:08 +0800128 gpio_request(IMX_GPIO_NR(2, 6), "enet_rst");
Fabio Estevamd1458782014-08-15 00:24:29 -0300129 gpio_direction_output(IMX_GPIO_NR(2, 6) , 0);
130
131 /* Reset AR8031 PHY */
Peng Fan5dfc9d32018-01-02 09:32:08 +0800132 gpio_request(IMX_GPIO_NR(2, 7), "phy_rst");
Fabio Estevamd1458782014-08-15 00:24:29 -0300133 gpio_direction_output(IMX_GPIO_NR(2, 7) , 0);
Fabio Estevam29bc24e2015-11-23 16:18:02 -0200134 mdelay(10);
Fabio Estevamd1458782014-08-15 00:24:29 -0300135 gpio_set_value(IMX_GPIO_NR(2, 7), 1);
136
137 reg = readl(&anatop->pll_enet);
138 reg |= BM_ANADIG_PLL_ENET_REF_25M_ENABLE;
139 writel(reg, &anatop->pll_enet);
140
Fabio Estevam29bc24e2015-11-23 16:18:02 -0200141 return 0;
Fabio Estevamd1458782014-08-15 00:24:29 -0300142}
143
144int board_eth_init(bd_t *bis)
145{
146 imx_iomux_v3_setup_multiple_pads(fec1_pads, ARRAY_SIZE(fec1_pads));
147 setup_fec();
148
149 return cpu_eth_init(bis);
150}
151
Ye.Li1f98e312014-11-06 16:29:01 +0800152int power_init_board(void)
Fabio Estevamfa8cf312014-07-09 16:13:30 -0300153{
Peng Fan5dfc9d32018-01-02 09:32:08 +0800154 struct udevice *dev;
Fabio Estevam42acd182015-07-21 20:37:22 -0300155 unsigned int reg;
156 int ret;
Fabio Estevamfa8cf312014-07-09 16:13:30 -0300157
Peng Fan5dfc9d32018-01-02 09:32:08 +0800158 dev = pfuze_common_init();
159 if (!dev)
Ye.Li1f98e312014-11-06 16:29:01 +0800160 return -ENODEV;
Fabio Estevamfa8cf312014-07-09 16:13:30 -0300161
Peng Fan5dfc9d32018-01-02 09:32:08 +0800162 ret = pfuze_mode_init(dev, APS_PFM);
Peng Fan258c98f2015-01-27 10:14:04 +0800163 if (ret < 0)
164 return ret;
165
Fabio Estevamfa8cf312014-07-09 16:13:30 -0300166 /* Enable power of VGEN5 3V3, needed for SD3 */
Peng Fan5dfc9d32018-01-02 09:32:08 +0800167 reg = pmic_reg_read(dev, PFUZE100_VGEN5VOL);
Ye.Li1f98e312014-11-06 16:29:01 +0800168 reg &= ~LDO_VOL_MASK;
169 reg |= (LDOB_3_30V | (1 << LDO_EN));
Peng Fan5dfc9d32018-01-02 09:32:08 +0800170 pmic_reg_write(dev, PFUZE100_VGEN5VOL, reg);
Fabio Estevamfa8cf312014-07-09 16:13:30 -0300171
172 return 0;
173}
174
Fabio Estevamd1458782014-08-15 00:24:29 -0300175int board_phy_config(struct phy_device *phydev)
176{
177 /*
178 * Enable 1.8V(SEL_1P5_1P8_POS_REG) on
179 * Phy control debug reg 0
180 */
181 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
182 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
183
184 /* rgmii tx clock delay enable */
185 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
186 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
187
188 if (phydev->drv->config)
189 phydev->drv->config(phydev);
190
191 return 0;
192}
193
Fabio Estevam14a16132014-06-24 17:41:01 -0300194int board_early_init_f(void)
195{
196 setup_iomux_uart();
Fabio Estevamfa8cf312014-07-09 16:13:30 -0300197
Fabio Estevamd1458782014-08-15 00:24:29 -0300198 /* Enable PERI_3V3, which is used by SD2, ENET, LVDS, BT */
199 imx_iomux_v3_setup_multiple_pads(peri_3v3_pads,
200 ARRAY_SIZE(peri_3v3_pads));
201
Fabio Estevam14a16132014-06-24 17:41:01 -0300202 return 0;
203}
204
Peng Fanfb0d0422016-01-28 16:51:27 +0800205int board_mmc_get_env_dev(int devno)
206{
Peng Fan5dfc9d32018-01-02 09:32:08 +0800207 return devno;
Fabio Estevam14a16132014-06-24 17:41:01 -0300208}
209
Peng Fanfad7d732014-12-31 11:01:40 +0800210#ifdef CONFIG_FSL_QSPI
211
Peng Fanfad7d732014-12-31 11:01:40 +0800212int board_qspi_init(void)
213{
Peng Fanfad7d732014-12-31 11:01:40 +0800214 /* Set the clock */
215 enable_qspi_clk(1);
216
217 return 0;
218}
219#endif
220
Ye Li85eb0952016-01-26 22:09:40 +0800221#ifdef CONFIG_VIDEO_MXS
222static iomux_v3_cfg_t const lcd_pads[] = {
223 MX6_PAD_LCD1_CLK__LCDIF1_CLK | MUX_PAD_CTRL(LCD_PAD_CTRL),
224 MX6_PAD_LCD1_ENABLE__LCDIF1_ENABLE | MUX_PAD_CTRL(LCD_PAD_CTRL),
225 MX6_PAD_LCD1_HSYNC__LCDIF1_HSYNC | MUX_PAD_CTRL(LCD_PAD_CTRL),
226 MX6_PAD_LCD1_VSYNC__LCDIF1_VSYNC | MUX_PAD_CTRL(LCD_PAD_CTRL),
227 MX6_PAD_LCD1_DATA00__LCDIF1_DATA_0 | MUX_PAD_CTRL(LCD_PAD_CTRL),
228 MX6_PAD_LCD1_DATA01__LCDIF1_DATA_1 | MUX_PAD_CTRL(LCD_PAD_CTRL),
229 MX6_PAD_LCD1_DATA02__LCDIF1_DATA_2 | MUX_PAD_CTRL(LCD_PAD_CTRL),
230 MX6_PAD_LCD1_DATA03__LCDIF1_DATA_3 | MUX_PAD_CTRL(LCD_PAD_CTRL),
231 MX6_PAD_LCD1_DATA04__LCDIF1_DATA_4 | MUX_PAD_CTRL(LCD_PAD_CTRL),
232 MX6_PAD_LCD1_DATA05__LCDIF1_DATA_5 | MUX_PAD_CTRL(LCD_PAD_CTRL),
233 MX6_PAD_LCD1_DATA06__LCDIF1_DATA_6 | MUX_PAD_CTRL(LCD_PAD_CTRL),
234 MX6_PAD_LCD1_DATA07__LCDIF1_DATA_7 | MUX_PAD_CTRL(LCD_PAD_CTRL),
235 MX6_PAD_LCD1_DATA08__LCDIF1_DATA_8 | MUX_PAD_CTRL(LCD_PAD_CTRL),
236 MX6_PAD_LCD1_DATA09__LCDIF1_DATA_9 | MUX_PAD_CTRL(LCD_PAD_CTRL),
237 MX6_PAD_LCD1_DATA10__LCDIF1_DATA_10 | MUX_PAD_CTRL(LCD_PAD_CTRL),
238 MX6_PAD_LCD1_DATA11__LCDIF1_DATA_11 | MUX_PAD_CTRL(LCD_PAD_CTRL),
239 MX6_PAD_LCD1_DATA12__LCDIF1_DATA_12 | MUX_PAD_CTRL(LCD_PAD_CTRL),
240 MX6_PAD_LCD1_DATA13__LCDIF1_DATA_13 | MUX_PAD_CTRL(LCD_PAD_CTRL),
241 MX6_PAD_LCD1_DATA14__LCDIF1_DATA_14 | MUX_PAD_CTRL(LCD_PAD_CTRL),
242 MX6_PAD_LCD1_DATA15__LCDIF1_DATA_15 | MUX_PAD_CTRL(LCD_PAD_CTRL),
243 MX6_PAD_LCD1_DATA16__LCDIF1_DATA_16 | MUX_PAD_CTRL(LCD_PAD_CTRL),
244 MX6_PAD_LCD1_DATA17__LCDIF1_DATA_17 | MUX_PAD_CTRL(LCD_PAD_CTRL),
245 MX6_PAD_LCD1_DATA18__LCDIF1_DATA_18 | MUX_PAD_CTRL(LCD_PAD_CTRL),
246 MX6_PAD_LCD1_DATA19__LCDIF1_DATA_19 | MUX_PAD_CTRL(LCD_PAD_CTRL),
247 MX6_PAD_LCD1_DATA20__LCDIF1_DATA_20 | MUX_PAD_CTRL(LCD_PAD_CTRL),
248 MX6_PAD_LCD1_DATA21__LCDIF1_DATA_21 | MUX_PAD_CTRL(LCD_PAD_CTRL),
249 MX6_PAD_LCD1_DATA22__LCDIF1_DATA_22 | MUX_PAD_CTRL(LCD_PAD_CTRL),
250 MX6_PAD_LCD1_DATA23__LCDIF1_DATA_23 | MUX_PAD_CTRL(LCD_PAD_CTRL),
251 MX6_PAD_LCD1_RESET__GPIO3_IO_27 | MUX_PAD_CTRL(NO_PAD_CTRL),
252
253 /* Use GPIO for Brightness adjustment, duty cycle = period */
254 MX6_PAD_SD1_DATA2__GPIO6_IO_4 | MUX_PAD_CTRL(NO_PAD_CTRL),
255};
256
257static int setup_lcd(void)
258{
Peng Fan708f6922016-12-11 19:24:28 +0800259 enable_lcdif_clock(LCDIF1_BASE_ADDR, 1);
Ye Li85eb0952016-01-26 22:09:40 +0800260
261 imx_iomux_v3_setup_multiple_pads(lcd_pads, ARRAY_SIZE(lcd_pads));
262
263 /* Reset the LCD */
Peng Fan5dfc9d32018-01-02 09:32:08 +0800264 gpio_request(IMX_GPIO_NR(3, 27), "lcd_rst");
Ye Li85eb0952016-01-26 22:09:40 +0800265 gpio_direction_output(IMX_GPIO_NR(3, 27) , 0);
266 udelay(500);
267 gpio_direction_output(IMX_GPIO_NR(3, 27) , 1);
268
269 /* Set Brightness to high */
Peng Fan5dfc9d32018-01-02 09:32:08 +0800270 gpio_request(IMX_GPIO_NR(6, 4), "lcd_bright");
Ye Li85eb0952016-01-26 22:09:40 +0800271 gpio_direction_output(IMX_GPIO_NR(6, 4) , 1);
272
273 return 0;
274}
275#endif
276
Fabio Estevam14a16132014-06-24 17:41:01 -0300277int board_init(void)
278{
279 /* Address of boot parameters */
280 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
281
Peng Fane80f9e12018-01-02 09:32:09 +0800282 /*
283 * Because kernel set WDOG_B mux before pad with the common pinctrl
284 * framwork now and wdog reset will be triggered once set WDOG_B mux
285 * with default pad setting, we set pad setting here to workaround this.
286 * Since imx_iomux_v3_setup_pad also set mux before pad setting, we set
287 * as GPIO mux firstly here to workaround it.
288 */
289 imx_iomux_v3_setup_pad(wdog_b_pad);
290
Peng Fan5dfc9d32018-01-02 09:32:08 +0800291 /* Active high for ncp692 */
292 gpio_request(IMX_GPIO_NR(4, 16), "ncp692_en");
293 gpio_direction_output(IMX_GPIO_NR(4, 16), 1);
Peng Fan05095532014-10-31 11:08:06 +0800294
Peng Fanfad7d732014-12-31 11:01:40 +0800295#ifdef CONFIG_FSL_QSPI
296 board_qspi_init();
297#endif
298
Ye Li85eb0952016-01-26 22:09:40 +0800299#ifdef CONFIG_VIDEO_MXS
300 setup_lcd();
301#endif
302
Fabio Estevam14a16132014-06-24 17:41:01 -0300303 return 0;
304}
305
Fabio Estevam6ca03f02017-11-27 10:25:10 -0200306static bool is_reva(void)
307{
308 return (nxp_board_rev() == 1);
309}
310
311int board_late_init(void)
312{
313#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
314 if (is_reva())
315 env_set("board_rev", "REVA");
316#endif
317 return 0;
318}
319
Fabio Estevam14a16132014-06-24 17:41:01 -0300320int checkboard(void)
321{
Fabio Estevam6ca03f02017-11-27 10:25:10 -0200322 printf("Board: MX6SX SABRE SDB rev%c\n", nxp_board_rev_string());
Fabio Estevam14a16132014-06-24 17:41:01 -0300323
324 return 0;
325}