blob: 41c620795cb83af2a584d9fe866e3538bfd52227 [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>
Adrian Alonso98810772015-09-03 11:49:28 -05007#include <asm/arch/clock.h>
8#include <asm/arch/imx-regs.h>
9#include <asm/arch/mx7-pins.h>
10#include <asm/arch/sys_proto.h>
11#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020012#include <asm/mach-imx/iomux-v3.h>
Adrian Alonso98810772015-09-03 11:49:28 -050013#include <asm/io.h>
14#include <linux/sizes.h>
15#include <common.h>
Yangbo Lu73340382019-06-21 11:42:28 +080016#include <fsl_esdhc_imx.h>
Adrian Alonso98810772015-09-03 11:49:28 -050017#include <mmc.h>
18#include <miiphy.h>
Adrian Alonso98810772015-09-03 11:49:28 -050019#include <power/pmic.h>
20#include <power/pfuze3000_pmic.h>
21#include "../common/pfuze.h"
22#include <i2c.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020023#include <asm/mach-imx/mxc_i2c.h>
Adrian Alonso98810772015-09-03 11:49:28 -050024#include <asm/arch/crm_regs.h>
25
26DECLARE_GLOBAL_DATA_PTR;
27
28#define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | \
29 PAD_CTL_PUS_PU100KOHM | PAD_CTL_HYS)
30
Peng Fan55be1ed2015-10-29 15:54:53 +080031#define LCD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_PU100KOHM | \
32 PAD_CTL_DSE_3P3V_49OHM)
33
Peng Fan62f92602015-12-22 17:04:24 +080034#define NAND_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_SRE_SLOW | PAD_CTL_HYS)
35
Angus Ainslieaa7ea8c2016-11-11 11:31:39 -070036#define SPI_PAD_CTRL \
37 (PAD_CTL_HYS | PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_SRE_FAST)
38
Peng Fan62f92602015-12-22 17:04:24 +080039#define NAND_PAD_READY0_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_PUS_PU5KOHM)
Adrian Alonso98810772015-09-03 11:49:28 -050040
Peng Fan9aa9c412017-04-13 14:09:57 +080041#ifdef CONFIG_MXC_SPI
Angus Ainslieaa7ea8c2016-11-11 11:31:39 -070042static iomux_v3_cfg_t const ecspi3_pads[] = {
43 MX7D_PAD_SAI2_RX_DATA__ECSPI3_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL),
44 MX7D_PAD_SAI2_TX_SYNC__ECSPI3_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL),
45 MX7D_PAD_SAI2_TX_BCLK__ECSPI3_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL),
46 MX7D_PAD_SAI2_TX_DATA__GPIO6_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL),
47};
48
49int board_spi_cs_gpio(unsigned bus, unsigned cs)
50{
51 return (bus == 2 && cs == 0) ? (IMX_GPIO_NR(6, 22)) : -1;
52}
53
54static void setup_spi(void)
55{
56 imx_iomux_v3_setup_multiple_pads(ecspi3_pads, ARRAY_SIZE(ecspi3_pads));
57}
Peng Fan9aa9c412017-04-13 14:09:57 +080058#endif
Angus Ainslieaa7ea8c2016-11-11 11:31:39 -070059
Adrian Alonso98810772015-09-03 11:49:28 -050060int dram_init(void)
61{
62 gd->ram_size = PHYS_SDRAM_SIZE;
63
64 return 0;
65}
66
67static iomux_v3_cfg_t const wdog_pads[] = {
68 MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
69};
70
71static iomux_v3_cfg_t const uart1_pads[] = {
72 MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
73 MX7D_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
74};
75
Peng Fan62f92602015-12-22 17:04:24 +080076#ifdef CONFIG_NAND_MXS
77static iomux_v3_cfg_t const gpmi_pads[] = {
78 MX7D_PAD_SD3_DATA0__NAND_DATA00 | MUX_PAD_CTRL(NAND_PAD_CTRL),
79 MX7D_PAD_SD3_DATA1__NAND_DATA01 | MUX_PAD_CTRL(NAND_PAD_CTRL),
80 MX7D_PAD_SD3_DATA2__NAND_DATA02 | MUX_PAD_CTRL(NAND_PAD_CTRL),
81 MX7D_PAD_SD3_DATA3__NAND_DATA03 | MUX_PAD_CTRL(NAND_PAD_CTRL),
82 MX7D_PAD_SD3_DATA4__NAND_DATA04 | MUX_PAD_CTRL(NAND_PAD_CTRL),
83 MX7D_PAD_SD3_DATA5__NAND_DATA05 | MUX_PAD_CTRL(NAND_PAD_CTRL),
84 MX7D_PAD_SD3_DATA6__NAND_DATA06 | MUX_PAD_CTRL(NAND_PAD_CTRL),
85 MX7D_PAD_SD3_DATA7__NAND_DATA07 | MUX_PAD_CTRL(NAND_PAD_CTRL),
86 MX7D_PAD_SD3_CLK__NAND_CLE | MUX_PAD_CTRL(NAND_PAD_CTRL),
87 MX7D_PAD_SD3_CMD__NAND_ALE | MUX_PAD_CTRL(NAND_PAD_CTRL),
88 MX7D_PAD_SD3_STROBE__NAND_RE_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
89 MX7D_PAD_SD3_RESET_B__NAND_WE_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
90 MX7D_PAD_SAI1_MCLK__NAND_WP_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
91 MX7D_PAD_SAI1_RX_BCLK__NAND_CE3_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
92 MX7D_PAD_SAI1_RX_SYNC__NAND_CE2_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
93 MX7D_PAD_SAI1_RX_DATA__NAND_CE1_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
94 MX7D_PAD_SAI1_TX_BCLK__NAND_CE0_B | MUX_PAD_CTRL(NAND_PAD_CTRL),
95 MX7D_PAD_SAI1_TX_SYNC__NAND_DQS | MUX_PAD_CTRL(NAND_PAD_CTRL),
96 MX7D_PAD_SAI1_TX_DATA__NAND_READY_B | MUX_PAD_CTRL(NAND_PAD_READY0_CTRL),
97};
98
99static void setup_gpmi_nand(void)
100{
101 imx_iomux_v3_setup_multiple_pads(gpmi_pads, ARRAY_SIZE(gpmi_pads));
102
103 /* NAND_USDHC_BUS_CLK is set in rom */
104 set_clk_nand();
105}
106#endif
107
Peng Fan55be1ed2015-10-29 15:54:53 +0800108#ifdef CONFIG_VIDEO_MXS
109static iomux_v3_cfg_t const lcd_pads[] = {
110 MX7D_PAD_LCD_CLK__LCD_CLK | MUX_PAD_CTRL(LCD_PAD_CTRL),
111 MX7D_PAD_LCD_ENABLE__LCD_ENABLE | MUX_PAD_CTRL(LCD_PAD_CTRL),
112 MX7D_PAD_LCD_HSYNC__LCD_HSYNC | MUX_PAD_CTRL(LCD_PAD_CTRL),
113 MX7D_PAD_LCD_VSYNC__LCD_VSYNC | MUX_PAD_CTRL(LCD_PAD_CTRL),
114 MX7D_PAD_LCD_DATA00__LCD_DATA0 | MUX_PAD_CTRL(LCD_PAD_CTRL),
115 MX7D_PAD_LCD_DATA01__LCD_DATA1 | MUX_PAD_CTRL(LCD_PAD_CTRL),
116 MX7D_PAD_LCD_DATA02__LCD_DATA2 | MUX_PAD_CTRL(LCD_PAD_CTRL),
117 MX7D_PAD_LCD_DATA03__LCD_DATA3 | MUX_PAD_CTRL(LCD_PAD_CTRL),
118 MX7D_PAD_LCD_DATA04__LCD_DATA4 | MUX_PAD_CTRL(LCD_PAD_CTRL),
119 MX7D_PAD_LCD_DATA05__LCD_DATA5 | MUX_PAD_CTRL(LCD_PAD_CTRL),
120 MX7D_PAD_LCD_DATA06__LCD_DATA6 | MUX_PAD_CTRL(LCD_PAD_CTRL),
121 MX7D_PAD_LCD_DATA07__LCD_DATA7 | MUX_PAD_CTRL(LCD_PAD_CTRL),
122 MX7D_PAD_LCD_DATA08__LCD_DATA8 | MUX_PAD_CTRL(LCD_PAD_CTRL),
123 MX7D_PAD_LCD_DATA09__LCD_DATA9 | MUX_PAD_CTRL(LCD_PAD_CTRL),
124 MX7D_PAD_LCD_DATA10__LCD_DATA10 | MUX_PAD_CTRL(LCD_PAD_CTRL),
125 MX7D_PAD_LCD_DATA11__LCD_DATA11 | MUX_PAD_CTRL(LCD_PAD_CTRL),
126 MX7D_PAD_LCD_DATA12__LCD_DATA12 | MUX_PAD_CTRL(LCD_PAD_CTRL),
127 MX7D_PAD_LCD_DATA13__LCD_DATA13 | MUX_PAD_CTRL(LCD_PAD_CTRL),
128 MX7D_PAD_LCD_DATA14__LCD_DATA14 | MUX_PAD_CTRL(LCD_PAD_CTRL),
129 MX7D_PAD_LCD_DATA15__LCD_DATA15 | MUX_PAD_CTRL(LCD_PAD_CTRL),
130 MX7D_PAD_LCD_DATA16__LCD_DATA16 | MUX_PAD_CTRL(LCD_PAD_CTRL),
131 MX7D_PAD_LCD_DATA17__LCD_DATA17 | MUX_PAD_CTRL(LCD_PAD_CTRL),
132 MX7D_PAD_LCD_DATA18__LCD_DATA18 | MUX_PAD_CTRL(LCD_PAD_CTRL),
133 MX7D_PAD_LCD_DATA19__LCD_DATA19 | MUX_PAD_CTRL(LCD_PAD_CTRL),
134 MX7D_PAD_LCD_DATA20__LCD_DATA20 | MUX_PAD_CTRL(LCD_PAD_CTRL),
135 MX7D_PAD_LCD_DATA21__LCD_DATA21 | MUX_PAD_CTRL(LCD_PAD_CTRL),
136 MX7D_PAD_LCD_DATA22__LCD_DATA22 | MUX_PAD_CTRL(LCD_PAD_CTRL),
137 MX7D_PAD_LCD_DATA23__LCD_DATA23 | MUX_PAD_CTRL(LCD_PAD_CTRL),
138
139 MX7D_PAD_LCD_RESET__GPIO3_IO4 | MUX_PAD_CTRL(LCD_PAD_CTRL),
140};
141
142static iomux_v3_cfg_t const pwm_pads[] = {
143 /* Use GPIO for Brightness adjustment, duty cycle = period */
144 MX7D_PAD_GPIO1_IO01__GPIO1_IO1 | MUX_PAD_CTRL(NO_PAD_CTRL),
145};
146
147static int setup_lcd(void)
148{
149 imx_iomux_v3_setup_multiple_pads(lcd_pads, ARRAY_SIZE(lcd_pads));
150
151 imx_iomux_v3_setup_multiple_pads(pwm_pads, ARRAY_SIZE(pwm_pads));
152
153 /* Reset LCD */
Peng Fan9aa9c412017-04-13 14:09:57 +0800154 gpio_request(IMX_GPIO_NR(3, 4), "lcd reset");
Peng Fan55be1ed2015-10-29 15:54:53 +0800155 gpio_direction_output(IMX_GPIO_NR(3, 4) , 0);
156 udelay(500);
157 gpio_direction_output(IMX_GPIO_NR(3, 4) , 1);
158
159 /* Set Brightness to high */
Peng Fan9aa9c412017-04-13 14:09:57 +0800160 gpio_request(IMX_GPIO_NR(1, 1), "lcd backlight");
Peng Fan55be1ed2015-10-29 15:54:53 +0800161 gpio_direction_output(IMX_GPIO_NR(1, 1) , 1);
162
163 return 0;
164}
165#endif
166
Adrian Alonso98810772015-09-03 11:49:28 -0500167static void setup_iomux_uart(void)
168{
169 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
170}
171
Peng Fan6c9d8fb2016-01-28 16:51:25 +0800172int board_mmc_get_env_dev(int devno)
Adrian Alonso98810772015-09-03 11:49:28 -0500173{
Peng Fan6c9d8fb2016-01-28 16:51:25 +0800174 if (devno == 2)
175 devno--;
Adrian Alonso98810772015-09-03 11:49:28 -0500176
Peng Fan6c9d8fb2016-01-28 16:51:25 +0800177 return devno;
Adrian Alonso98810772015-09-03 11:49:28 -0500178}
179
Peng Fan9aa9c412017-04-13 14:09:57 +0800180int mmc_map_to_kernel_blk(int dev_no)
Adrian Alonso98810772015-09-03 11:49:28 -0500181{
182 if (dev_no == 1)
183 dev_no++;
184
185 return dev_no;
186}
187
Adrian Alonso98810772015-09-03 11:49:28 -0500188#ifdef CONFIG_FEC_MXC
Adrian Alonso98810772015-09-03 11:49:28 -0500189static int setup_fec(void)
190{
191 struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs
192 = (struct iomuxc_gpr_base_regs *) IOMUXC_GPR_BASE_ADDR;
193
194 /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17]*/
195 clrsetbits_le32(&iomuxc_gpr_regs->gpr[1],
196 (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK |
197 IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0);
198
Eric Nelsoneadd7322017-08-31 08:34:23 -0700199 return set_clk_enet(ENET_125MHZ);
Adrian Alonso98810772015-09-03 11:49:28 -0500200}
201
Adrian Alonso98810772015-09-03 11:49:28 -0500202int board_phy_config(struct phy_device *phydev)
203{
204 /* enable rgmii rxc skew and phy mode select to RGMII copper */
205 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x21);
206 phy_write(phydev, MDIO_DEVAD_NONE, 0x1f, 0x7ea8);
207 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x2f);
208 phy_write(phydev, MDIO_DEVAD_NONE, 0x1f, 0x71b7);
209
210 if (phydev->drv->config)
211 phydev->drv->config(phydev);
212 return 0;
213}
214#endif
215
Peng Fan7431e702015-11-30 17:45:02 +0800216#ifdef CONFIG_FSL_QSPI
Peng Fan7431e702015-11-30 17:45:02 +0800217int board_qspi_init(void)
218{
Peng Fan7431e702015-11-30 17:45:02 +0800219 /* Set the clock */
220 set_clk_qspi();
221
222 return 0;
223}
224#endif
225
Adrian Alonso98810772015-09-03 11:49:28 -0500226int board_early_init_f(void)
227{
228 setup_iomux_uart();
229
Adrian Alonso98810772015-09-03 11:49:28 -0500230 return 0;
231}
232
233int board_init(void)
234{
235 /* address of boot parameters */
236 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
237
Adrian Alonso98810772015-09-03 11:49:28 -0500238#ifdef CONFIG_FEC_MXC
239 setup_fec();
240#endif
241
Peng Fan62f92602015-12-22 17:04:24 +0800242#ifdef CONFIG_NAND_MXS
243 setup_gpmi_nand();
244#endif
245
Peng Fan55be1ed2015-10-29 15:54:53 +0800246#ifdef CONFIG_VIDEO_MXS
247 setup_lcd();
248#endif
249
Peng Fan7431e702015-11-30 17:45:02 +0800250#ifdef CONFIG_FSL_QSPI
251 board_qspi_init();
252#endif
253
Angus Ainslieaa7ea8c2016-11-11 11:31:39 -0700254#ifdef CONFIG_MXC_SPI
255 setup_spi();
256#endif
257
Adrian Alonso98810772015-09-03 11:49:28 -0500258 return 0;
259}
260
Peng Fan9aa9c412017-04-13 14:09:57 +0800261#ifdef CONFIG_DM_PMIC
Adrian Alonso98810772015-09-03 11:49:28 -0500262int power_init_board(void)
263{
Peng Fan9aa9c412017-04-13 14:09:57 +0800264 struct udevice *dev;
265 int ret, dev_id, rev_id;
Adrian Alonso98810772015-09-03 11:49:28 -0500266
Joris Offouga59e53df2020-01-16 17:41:43 +0100267 ret = pmic_get("pfuze3000@8", &dev);
Peng Fan9aa9c412017-04-13 14:09:57 +0800268 if (ret == -ENODEV)
269 return 0;
270 if (ret != 0)
Adrian Alonso98810772015-09-03 11:49:28 -0500271 return ret;
272
Peng Fan9aa9c412017-04-13 14:09:57 +0800273 dev_id = pmic_reg_read(dev, PFUZE3000_DEVICEID);
274 rev_id = pmic_reg_read(dev, PFUZE3000_REVID);
275 printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", dev_id, rev_id);
Adrian Alonso98810772015-09-03 11:49:28 -0500276
Peng Fan9aa9c412017-04-13 14:09:57 +0800277 pmic_clrsetbits(dev, PFUZE3000_LDOGCTL, 0, 1);
Adrian Alonso98810772015-09-03 11:49:28 -0500278
Gautam Bhat07822812017-07-03 00:50:32 +0530279 /*
280 * Set the voltage of VLDO4 output to 2.8V which feeds
281 * the MIPI DSI and MIPI CSI inputs.
282 */
283 pmic_clrsetbits(dev, PFUZE3000_VLD4CTL, 0xF, 0xA);
284
Adrian Alonso98810772015-09-03 11:49:28 -0500285 return 0;
286}
287#endif
288
289int board_late_init(void)
290{
Peng Fan6b7c3dc2015-09-14 13:34:45 +0800291 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
292
Adrian Alonso98810772015-09-03 11:49:28 -0500293 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
294
Peng Fan6b7c3dc2015-09-14 13:34:45 +0800295 set_wdog_reset(wdog);
296
297 /*
298 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
299 * since we use PMIC_PWRON to reset the board.
300 */
301 clrsetbits_le16(&wdog->wcr, 0, 0x10);
Adrian Alonso98810772015-09-03 11:49:28 -0500302
303 return 0;
304}
305
Adrian Alonso98810772015-09-03 11:49:28 -0500306int checkboard(void)
307{
Fabio Estevamea696c72016-07-28 20:49:46 -0300308 char *mode;
309
310 if (IS_ENABLED(CONFIG_ARMV7_BOOT_SEC_DEFAULT))
311 mode = "secure";
312 else
313 mode = "non-secure";
314
315 printf("Board: i.MX7D SABRESD in %s mode\n", mode);
Adrian Alonso98810772015-09-03 11:49:28 -0500316
317 return 0;
318}