blob: 4fe23b51cd1bc165dfa51dd491745fbc50f1bab7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Adrian Alonso98810772015-09-03 11:49:28 -05002/*
3 * Copyright (C) 2015 Freescale Semiconductor, Inc.
Adrian Alonso98810772015-09-03 11:49:28 -05004 */
5
Simon Glassa7b51302019-11-14 12:57:46 -07006#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06007#include <net.h>
Adrian Alonso98810772015-09-03 11:49:28 -05008#include <asm/arch/clock.h>
9#include <asm/arch/imx-regs.h>
10#include <asm/arch/mx7-pins.h>
11#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Adrian Alonso98810772015-09-03 11:49:28 -050013#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020014#include <asm/mach-imx/iomux-v3.h>
Adrian Alonso98810772015-09-03 11:49:28 -050015#include <asm/io.h>
Simon Glassdbd79542020-05-10 11:40:11 -060016#include <linux/delay.h>
Adrian Alonso98810772015-09-03 11:49:28 -050017#include <linux/sizes.h>
18#include <common.h>
Yangbo Lu73340382019-06-21 11:42:28 +080019#include <fsl_esdhc_imx.h>
Adrian Alonso98810772015-09-03 11:49:28 -050020#include <mmc.h>
21#include <miiphy.h>
Adrian Alonso98810772015-09-03 11:49:28 -050022#include <power/pmic.h>
23#include <power/pfuze3000_pmic.h>
24#include "../common/pfuze.h"
25#include <i2c.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020026#include <asm/mach-imx/mxc_i2c.h>
Adrian Alonso98810772015-09-03 11:49:28 -050027#include <asm/arch/crm_regs.h>
28
29DECLARE_GLOBAL_DATA_PTR;
30
31#define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | \
32 PAD_CTL_PUS_PU100KOHM | PAD_CTL_HYS)
33
Peng Fan55be1ed2015-10-29 15:54:53 +080034#define LCD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_PU100KOHM | \
35 PAD_CTL_DSE_3P3V_49OHM)
36
Peng Fan62f92602015-12-22 17:04:24 +080037#define NAND_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_SRE_SLOW | PAD_CTL_HYS)
38
Angus Ainslieaa7ea8c2016-11-11 11:31:39 -070039#define SPI_PAD_CTRL \
40 (PAD_CTL_HYS | PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_SRE_FAST)
41
Peng Fan62f92602015-12-22 17:04:24 +080042#define NAND_PAD_READY0_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_PUS_PU5KOHM)
Adrian Alonso98810772015-09-03 11:49:28 -050043
Peng Fan9aa9c412017-04-13 14:09:57 +080044#ifdef CONFIG_MXC_SPI
Angus Ainslieaa7ea8c2016-11-11 11:31:39 -070045static iomux_v3_cfg_t const ecspi3_pads[] = {
46 MX7D_PAD_SAI2_RX_DATA__ECSPI3_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL),
47 MX7D_PAD_SAI2_TX_SYNC__ECSPI3_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL),
48 MX7D_PAD_SAI2_TX_BCLK__ECSPI3_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL),
49 MX7D_PAD_SAI2_TX_DATA__GPIO6_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL),
50};
51
52int board_spi_cs_gpio(unsigned bus, unsigned cs)
53{
54 return (bus == 2 && cs == 0) ? (IMX_GPIO_NR(6, 22)) : -1;
55}
56
57static void setup_spi(void)
58{
59 imx_iomux_v3_setup_multiple_pads(ecspi3_pads, ARRAY_SIZE(ecspi3_pads));
60}
Peng Fan9aa9c412017-04-13 14:09:57 +080061#endif
Angus Ainslieaa7ea8c2016-11-11 11:31:39 -070062
Adrian Alonso98810772015-09-03 11:49:28 -050063int dram_init(void)
64{
65 gd->ram_size = PHYS_SDRAM_SIZE;
66
67 return 0;
68}
69
70static iomux_v3_cfg_t const wdog_pads[] = {
71 MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
72};
73
74static iomux_v3_cfg_t const uart1_pads[] = {
75 MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
76 MX7D_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
77};
78
Peng Fan62f92602015-12-22 17:04:24 +080079#ifdef CONFIG_NAND_MXS
80static iomux_v3_cfg_t const gpmi_pads[] = {
81 MX7D_PAD_SD3_DATA0__NAND_DATA00 | MUX_PAD_CTRL(NAND_PAD_CTRL),
82 MX7D_PAD_SD3_DATA1__NAND_DATA01 | MUX_PAD_CTRL(NAND_PAD_CTRL),
83 MX7D_PAD_SD3_DATA2__NAND_DATA02 | MUX_PAD_CTRL(NAND_PAD_CTRL),
84 MX7D_PAD_SD3_DATA3__NAND_DATA03 | MUX_PAD_CTRL(NAND_PAD_CTRL),
85 MX7D_PAD_SD3_DATA4__NAND_DATA04 | MUX_PAD_CTRL(NAND_PAD_CTRL),
86 MX7D_PAD_SD3_DATA5__NAND_DATA05 | MUX_PAD_CTRL(NAND_PAD_CTRL),
87 MX7D_PAD_SD3_DATA6__NAND_DATA06 | MUX_PAD_CTRL(NAND_PAD_CTRL),
88 MX7D_PAD_SD3_DATA7__NAND_DATA07 | MUX_PAD_CTRL(NAND_PAD_CTRL),
89 MX7D_PAD_SD3_CLK__NAND_CLE | MUX_PAD_CTRL(NAND_PAD_CTRL),
90 MX7D_PAD_SD3_CMD__NAND_ALE | MUX_PAD_CTRL(NAND_PAD_CTRL),
91 MX7D_PAD_SD3_STROBE__NAND_RE_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
92 MX7D_PAD_SD3_RESET_B__NAND_WE_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
93 MX7D_PAD_SAI1_MCLK__NAND_WP_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
94 MX7D_PAD_SAI1_RX_BCLK__NAND_CE3_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
95 MX7D_PAD_SAI1_RX_SYNC__NAND_CE2_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
96 MX7D_PAD_SAI1_RX_DATA__NAND_CE1_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
97 MX7D_PAD_SAI1_TX_BCLK__NAND_CE0_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
98 MX7D_PAD_SAI1_TX_SYNC__NAND_DQS | MUX_PAD_CTRL(NAND_PAD_CTRL),
99 MX7D_PAD_SAI1_TX_DATA__NAND_READY_B | MUX_PAD_CTRL(NAND_PAD_READY0_CTRL),
100};
101
102static void setup_gpmi_nand(void)
103{
104 imx_iomux_v3_setup_multiple_pads(gpmi_pads, ARRAY_SIZE(gpmi_pads));
105
106 /* NAND_USDHC_BUS_CLK is set in rom */
107 set_clk_nand();
108}
109#endif
110
Peng Fan55be1ed2015-10-29 15:54:53 +0800111#ifdef CONFIG_VIDEO_MXS
112static iomux_v3_cfg_t const lcd_pads[] = {
113 MX7D_PAD_LCD_CLK__LCD_CLK | MUX_PAD_CTRL(LCD_PAD_CTRL),
114 MX7D_PAD_LCD_ENABLE__LCD_ENABLE | MUX_PAD_CTRL(LCD_PAD_CTRL),
115 MX7D_PAD_LCD_HSYNC__LCD_HSYNC | MUX_PAD_CTRL(LCD_PAD_CTRL),
116 MX7D_PAD_LCD_VSYNC__LCD_VSYNC | MUX_PAD_CTRL(LCD_PAD_CTRL),
117 MX7D_PAD_LCD_DATA00__LCD_DATA0 | MUX_PAD_CTRL(LCD_PAD_CTRL),
118 MX7D_PAD_LCD_DATA01__LCD_DATA1 | MUX_PAD_CTRL(LCD_PAD_CTRL),
119 MX7D_PAD_LCD_DATA02__LCD_DATA2 | MUX_PAD_CTRL(LCD_PAD_CTRL),
120 MX7D_PAD_LCD_DATA03__LCD_DATA3 | MUX_PAD_CTRL(LCD_PAD_CTRL),
121 MX7D_PAD_LCD_DATA04__LCD_DATA4 | MUX_PAD_CTRL(LCD_PAD_CTRL),
122 MX7D_PAD_LCD_DATA05__LCD_DATA5 | MUX_PAD_CTRL(LCD_PAD_CTRL),
123 MX7D_PAD_LCD_DATA06__LCD_DATA6 | MUX_PAD_CTRL(LCD_PAD_CTRL),
124 MX7D_PAD_LCD_DATA07__LCD_DATA7 | MUX_PAD_CTRL(LCD_PAD_CTRL),
125 MX7D_PAD_LCD_DATA08__LCD_DATA8 | MUX_PAD_CTRL(LCD_PAD_CTRL),
126 MX7D_PAD_LCD_DATA09__LCD_DATA9 | MUX_PAD_CTRL(LCD_PAD_CTRL),
127 MX7D_PAD_LCD_DATA10__LCD_DATA10 | MUX_PAD_CTRL(LCD_PAD_CTRL),
128 MX7D_PAD_LCD_DATA11__LCD_DATA11 | MUX_PAD_CTRL(LCD_PAD_CTRL),
129 MX7D_PAD_LCD_DATA12__LCD_DATA12 | MUX_PAD_CTRL(LCD_PAD_CTRL),
130 MX7D_PAD_LCD_DATA13__LCD_DATA13 | MUX_PAD_CTRL(LCD_PAD_CTRL),
131 MX7D_PAD_LCD_DATA14__LCD_DATA14 | MUX_PAD_CTRL(LCD_PAD_CTRL),
132 MX7D_PAD_LCD_DATA15__LCD_DATA15 | MUX_PAD_CTRL(LCD_PAD_CTRL),
133 MX7D_PAD_LCD_DATA16__LCD_DATA16 | MUX_PAD_CTRL(LCD_PAD_CTRL),
134 MX7D_PAD_LCD_DATA17__LCD_DATA17 | MUX_PAD_CTRL(LCD_PAD_CTRL),
135 MX7D_PAD_LCD_DATA18__LCD_DATA18 | MUX_PAD_CTRL(LCD_PAD_CTRL),
136 MX7D_PAD_LCD_DATA19__LCD_DATA19 | MUX_PAD_CTRL(LCD_PAD_CTRL),
137 MX7D_PAD_LCD_DATA20__LCD_DATA20 | MUX_PAD_CTRL(LCD_PAD_CTRL),
138 MX7D_PAD_LCD_DATA21__LCD_DATA21 | MUX_PAD_CTRL(LCD_PAD_CTRL),
139 MX7D_PAD_LCD_DATA22__LCD_DATA22 | MUX_PAD_CTRL(LCD_PAD_CTRL),
140 MX7D_PAD_LCD_DATA23__LCD_DATA23 | MUX_PAD_CTRL(LCD_PAD_CTRL),
141
142 MX7D_PAD_LCD_RESET__GPIO3_IO4 | MUX_PAD_CTRL(LCD_PAD_CTRL),
143};
144
145static iomux_v3_cfg_t const pwm_pads[] = {
146 /* Use GPIO for Brightness adjustment, duty cycle = period */
147 MX7D_PAD_GPIO1_IO01__GPIO1_IO1 | MUX_PAD_CTRL(NO_PAD_CTRL),
148};
149
150static int setup_lcd(void)
151{
152 imx_iomux_v3_setup_multiple_pads(lcd_pads, ARRAY_SIZE(lcd_pads));
153
154 imx_iomux_v3_setup_multiple_pads(pwm_pads, ARRAY_SIZE(pwm_pads));
155
156 /* Reset LCD */
Peng Fan9aa9c412017-04-13 14:09:57 +0800157 gpio_request(IMX_GPIO_NR(3, 4), "lcd reset");
Peng Fan55be1ed2015-10-29 15:54:53 +0800158 gpio_direction_output(IMX_GPIO_NR(3, 4) , 0);
159 udelay(500);
160 gpio_direction_output(IMX_GPIO_NR(3, 4) , 1);
161
162 /* Set Brightness to high */
Peng Fan9aa9c412017-04-13 14:09:57 +0800163 gpio_request(IMX_GPIO_NR(1, 1), "lcd backlight");
Peng Fan55be1ed2015-10-29 15:54:53 +0800164 gpio_direction_output(IMX_GPIO_NR(1, 1) , 1);
165
166 return 0;
167}
168#endif
169
Adrian Alonso98810772015-09-03 11:49:28 -0500170static void setup_iomux_uart(void)
171{
172 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
173}
174
Peng Fan6c9d8fb2016-01-28 16:51:25 +0800175int board_mmc_get_env_dev(int devno)
Adrian Alonso98810772015-09-03 11:49:28 -0500176{
Peng Fan6c9d8fb2016-01-28 16:51:25 +0800177 if (devno == 2)
178 devno--;
Adrian Alonso98810772015-09-03 11:49:28 -0500179
Peng Fan6c9d8fb2016-01-28 16:51:25 +0800180 return devno;
Adrian Alonso98810772015-09-03 11:49:28 -0500181}
182
Peng Fan9aa9c412017-04-13 14:09:57 +0800183int mmc_map_to_kernel_blk(int dev_no)
Adrian Alonso98810772015-09-03 11:49:28 -0500184{
185 if (dev_no == 1)
186 dev_no++;
187
188 return dev_no;
189}
190
Adrian Alonso98810772015-09-03 11:49:28 -0500191#ifdef CONFIG_FEC_MXC
Adrian Alonso98810772015-09-03 11:49:28 -0500192static int setup_fec(void)
193{
194 struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs
195 = (struct iomuxc_gpr_base_regs *) IOMUXC_GPR_BASE_ADDR;
196
197 /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17]*/
198 clrsetbits_le32(&iomuxc_gpr_regs->gpr[1],
199 (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK |
200 IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0);
201
Eric Nelsoneadd7322017-08-31 08:34:23 -0700202 return set_clk_enet(ENET_125MHZ);
Adrian Alonso98810772015-09-03 11:49:28 -0500203}
204
Adrian Alonso98810772015-09-03 11:49:28 -0500205int board_phy_config(struct phy_device *phydev)
206{
207 /* enable rgmii rxc skew and phy mode select to RGMII copper */
208 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x21);
209 phy_write(phydev, MDIO_DEVAD_NONE, 0x1f, 0x7ea8);
210 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x2f);
211 phy_write(phydev, MDIO_DEVAD_NONE, 0x1f, 0x71b7);
212
213 if (phydev->drv->config)
214 phydev->drv->config(phydev);
215 return 0;
216}
217#endif
218
Peng Fan7431e702015-11-30 17:45:02 +0800219#ifdef CONFIG_FSL_QSPI
Peng Fan7431e702015-11-30 17:45:02 +0800220int board_qspi_init(void)
221{
Peng Fan7431e702015-11-30 17:45:02 +0800222 /* Set the clock */
223 set_clk_qspi();
224
225 return 0;
226}
227#endif
228
Adrian Alonso98810772015-09-03 11:49:28 -0500229int board_early_init_f(void)
230{
231 setup_iomux_uart();
232
Adrian Alonso98810772015-09-03 11:49:28 -0500233 return 0;
234}
235
236int board_init(void)
237{
238 /* address of boot parameters */
239 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
240
Adrian Alonso98810772015-09-03 11:49:28 -0500241#ifdef CONFIG_FEC_MXC
242 setup_fec();
243#endif
244
Peng Fan62f92602015-12-22 17:04:24 +0800245#ifdef CONFIG_NAND_MXS
246 setup_gpmi_nand();
247#endif
248
Peng Fan55be1ed2015-10-29 15:54:53 +0800249#ifdef CONFIG_VIDEO_MXS
250 setup_lcd();
251#endif
252
Peng Fan7431e702015-11-30 17:45:02 +0800253#ifdef CONFIG_FSL_QSPI
254 board_qspi_init();
255#endif
256
Angus Ainslieaa7ea8c2016-11-11 11:31:39 -0700257#ifdef CONFIG_MXC_SPI
258 setup_spi();
259#endif
260
Adrian Alonso98810772015-09-03 11:49:28 -0500261 return 0;
262}
263
Peng Fan9aa9c412017-04-13 14:09:57 +0800264#ifdef CONFIG_DM_PMIC
Adrian Alonso98810772015-09-03 11:49:28 -0500265int power_init_board(void)
266{
Peng Fan9aa9c412017-04-13 14:09:57 +0800267 struct udevice *dev;
268 int ret, dev_id, rev_id;
Adrian Alonso98810772015-09-03 11:49:28 -0500269
Fabio Estevam8457bcf2023-12-13 09:37:08 -0300270 ret = pmic_get("pmic@8", &dev);
Peng Fan9aa9c412017-04-13 14:09:57 +0800271 if (ret == -ENODEV)
272 return 0;
273 if (ret != 0)
Adrian Alonso98810772015-09-03 11:49:28 -0500274 return ret;
275
Peng Fan9aa9c412017-04-13 14:09:57 +0800276 dev_id = pmic_reg_read(dev, PFUZE3000_DEVICEID);
277 rev_id = pmic_reg_read(dev, PFUZE3000_REVID);
278 printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", dev_id, rev_id);
Adrian Alonso98810772015-09-03 11:49:28 -0500279
Peng Fan9aa9c412017-04-13 14:09:57 +0800280 pmic_clrsetbits(dev, PFUZE3000_LDOGCTL, 0, 1);
Adrian Alonso98810772015-09-03 11:49:28 -0500281
Gautam Bhat07822812017-07-03 00:50:32 +0530282 /*
283 * Set the voltage of VLDO4 output to 2.8V which feeds
284 * the MIPI DSI and MIPI CSI inputs.
285 */
286 pmic_clrsetbits(dev, PFUZE3000_VLD4CTL, 0xF, 0xA);
287
Adrian Alonso98810772015-09-03 11:49:28 -0500288 return 0;
289}
290#endif
291
292int board_late_init(void)
293{
Peng Fan6b7c3dc2015-09-14 13:34:45 +0800294 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
Fabio Estevamff4c1b22023-07-11 18:57:57 -0300295 unsigned char eth1addr[6];
Peng Fan6b7c3dc2015-09-14 13:34:45 +0800296
Adrian Alonso98810772015-09-03 11:49:28 -0500297 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
298
Peng Fan6b7c3dc2015-09-14 13:34:45 +0800299 set_wdog_reset(wdog);
300
301 /*
302 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
303 * since we use PMIC_PWRON to reset the board.
304 */
305 clrsetbits_le16(&wdog->wcr, 0, 0x10);
Adrian Alonso98810772015-09-03 11:49:28 -0500306
Fabio Estevamff4c1b22023-07-11 18:57:57 -0300307 /* Get the second MAC address */
308 imx_get_mac_from_fuse(1, eth1addr);
309 if (!env_get("eth1addr") && is_valid_ethaddr(eth1addr))
310 eth_env_set_enetaddr("eth1addr", eth1addr);
311
Adrian Alonso98810772015-09-03 11:49:28 -0500312 return 0;
313}
314
Adrian Alonso98810772015-09-03 11:49:28 -0500315int checkboard(void)
316{
Fabio Estevamea696c72016-07-28 20:49:46 -0300317 char *mode;
318
319 if (IS_ENABLED(CONFIG_ARMV7_BOOT_SEC_DEFAULT))
320 mode = "secure";
321 else
322 mode = "non-secure";
323
324 printf("Board: i.MX7D SABRESD in %s mode\n", mode);
Adrian Alonso98810772015-09-03 11:49:28 -0500325
326 return 0;
327}