blob: d0f739c624a1e17ed561d4281decac88a1a94adc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vanessa Maegima27142c32017-05-08 13:17:28 -03002/*
3 * Copyright (C) 2017 NXP Semiconductors
Vanessa Maegima27142c32017-05-08 13:17:28 -03004 */
5
Simon Glassa7b51302019-11-14 12:57:46 -07006#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06007#include <net.h>
Vanessa Maegima27142c32017-05-08 13:17:28 -03008#include <asm/arch/clock.h>
9#include <asm/arch/crm_regs.h>
10#include <asm/arch/imx-regs.h>
11#include <asm/arch/mx7-pins.h>
12#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Vanessa Maegima27142c32017-05-08 13:17:28 -030014#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020015#include <asm/mach-imx/iomux-v3.h>
Benjamin Szőke4f6092e2023-12-13 15:51:49 -030016#include <asm/mach-imx/boot_mode.h>
Vanessa Maegima27142c32017-05-08 13:17:28 -030017#include <asm/io.h>
Vanessa Maegima27142c32017-05-08 13:17:28 -030018#include <miiphy.h>
Vanessa Maegima27142c32017-05-08 13:17:28 -030019#include <power/pmic.h>
20#include <power/pfuze3000_pmic.h>
21#include "../../freescale/common/pfuze.h"
22
23DECLARE_GLOBAL_DATA_PTR;
24
25#define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | \
26 PAD_CTL_PUS_PU100KOHM | PAD_CTL_HYS)
27
Benjamin Szőke4f6092e2023-12-13 15:51:49 -030028#define PICO_MMC0 0
29#define PICO_MMC0_BLK 2
30#define PICO_MMC1 1
31#define PICO_MMC1_BLK 0
32
Vanessa Maegima27142c32017-05-08 13:17:28 -030033int dram_init(void)
34{
Fabio Estevam6ed39812018-06-29 15:19:11 -030035 gd->ram_size = imx_ddr_size();
Vanessa Maegima27142c32017-05-08 13:17:28 -030036
Jun Niefeb13442019-05-08 14:38:32 +080037 /* Subtract the defined OPTEE runtime firmware length */
38#ifdef CONFIG_OPTEE_TZDRAM_SIZE
39 gd->ram_size -= CONFIG_OPTEE_TZDRAM_SIZE;
40#endif
41
Vanessa Maegima27142c32017-05-08 13:17:28 -030042 return 0;
43}
44
Fabio Estevamb31953e2023-01-03 10:19:40 -030045#if CONFIG_IS_ENABLED(DM_PMIC)
Vanessa Maegima27142c32017-05-08 13:17:28 -030046int power_init_board(void)
47{
Fabio Estevamb31953e2023-01-03 10:19:40 -030048 struct udevice *dev;
49 int reg, rev_id;
Vanessa Maegima27142c32017-05-08 13:17:28 -030050 int ret;
Vanessa Maegima27142c32017-05-08 13:17:28 -030051
Fabio Estevamb31953e2023-01-03 10:19:40 -030052 ret = pmic_get("pfuze3000@8", &dev);
53 if (ret == -ENODEV)
Jun Nie8600eef2019-05-08 14:38:36 +080054 return 0;
Fabio Estevamb31953e2023-01-03 10:19:40 -030055 if (ret != 0)
56 return ret;
Vanessa Maegima27142c32017-05-08 13:17:28 -030057
Fabio Estevamb31953e2023-01-03 10:19:40 -030058 reg = pmic_reg_read(dev, PFUZE3000_DEVICEID);
59 rev_id = pmic_reg_read(dev, PFUZE3000_REVID);
60 printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", reg, rev_id);
Vanessa Maegima27142c32017-05-08 13:17:28 -030061
62 /* disable Low Power Mode during standby mode */
Fabio Estevamb31953e2023-01-03 10:19:40 -030063 reg = pmic_reg_read(dev, PFUZE3000_LDOGCTL);
Vanessa Maegima27142c32017-05-08 13:17:28 -030064 reg |= 0x1;
Fabio Estevamb31953e2023-01-03 10:19:40 -030065 pmic_reg_write(dev, PFUZE3000_LDOGCTL, reg);
Vanessa Maegima27142c32017-05-08 13:17:28 -030066
67 /* SW1A/1B mode set to APS/APS */
68 reg = 0x8;
Fabio Estevamb31953e2023-01-03 10:19:40 -030069 pmic_reg_write(dev, PFUZE3000_SW1AMODE, reg);
70 pmic_reg_write(dev, PFUZE3000_SW1BMODE, reg);
Vanessa Maegima27142c32017-05-08 13:17:28 -030071
72 /* SW1A/1B standby voltage set to 1.025V */
73 reg = 0xd;
Fabio Estevamb31953e2023-01-03 10:19:40 -030074 pmic_reg_write(dev, PFUZE3000_SW1ASTBY, reg);
75 pmic_reg_write(dev, PFUZE3000_SW1BSTBY, reg);
Vanessa Maegima27142c32017-05-08 13:17:28 -030076
77 /* decrease SW1B normal voltage to 0.975V */
Fabio Estevamb31953e2023-01-03 10:19:40 -030078 reg = pmic_reg_read(dev, PFUZE3000_SW1BVOLT);
Vanessa Maegima27142c32017-05-08 13:17:28 -030079 reg &= ~0x1f;
80 reg |= PFUZE3000_SW1AB_SETP(975);
Fabio Estevamb31953e2023-01-03 10:19:40 -030081 pmic_reg_write(dev, PFUZE3000_SW1BVOLT, reg);
Vanessa Maegima27142c32017-05-08 13:17:28 -030082
83 return 0;
84}
85#endif
86
87static iomux_v3_cfg_t const wdog_pads[] = {
88 MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
89};
90
91static iomux_v3_cfg_t const uart5_pads[] = {
92 MX7D_PAD_I2C4_SCL__UART5_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
93 MX7D_PAD_I2C4_SDA__UART5_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
94};
95
Vanessa Maegima27142c32017-05-08 13:17:28 -030096#ifdef CONFIG_FEC_MXC
Vanessa Maegima27142c32017-05-08 13:17:28 -030097static int setup_fec(void)
98{
99 struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs
100 = (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
101
102 /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17] */
103 clrsetbits_le32(&iomuxc_gpr_regs->gpr[1],
104 (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK |
105 IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0);
106
Eric Nelsoneadd7322017-08-31 08:34:23 -0700107 return set_clk_enet(ENET_125MHZ);
Vanessa Maegima27142c32017-05-08 13:17:28 -0300108}
Vanessa Maegima27142c32017-05-08 13:17:28 -0300109#endif
110
111static void setup_iomux_uart(void)
112{
113 imx_iomux_v3_setup_multiple_pads(uart5_pads, ARRAY_SIZE(uart5_pads));
114}
115
Vanessa Maegima27142c32017-05-08 13:17:28 -0300116int board_early_init_f(void)
117{
118 setup_iomux_uart();
119
Vanessa Maegima27142c32017-05-08 13:17:28 -0300120 return 0;
121}
122
Simon Glass52cb5042022-10-18 07:46:31 -0600123#ifdef CONFIG_VIDEO
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200124void setup_lcd(void)
125{
Joris Offouga0dc6a40e2019-04-04 14:00:54 +0200126 gpio_request(IMX_GPIO_NR(1, 11), "lcd_brightness");
127 gpio_request(IMX_GPIO_NR(1, 6), "lcd_enable");
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200128 /* Set Brightness to high */
129 gpio_direction_output(IMX_GPIO_NR(1, 11) , 1);
130 /* Set LCD enable to high */
131 gpio_direction_output(IMX_GPIO_NR(1, 6) , 1);
132}
133#endif
134
Vanessa Maegima27142c32017-05-08 13:17:28 -0300135int board_init(void)
136{
137 /* address of boot parameters */
138 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
139
Simon Glass52cb5042022-10-18 07:46:31 -0600140#ifdef CONFIG_VIDEO
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200141 setup_lcd();
142#endif
Vanessa Maegima27142c32017-05-08 13:17:28 -0300143#ifdef CONFIG_FEC_MXC
144 setup_fec();
145#endif
146
147 return 0;
148}
149
150int board_late_init(void)
151{
152 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
153
154 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
155
156 set_wdog_reset(wdog);
157
Benjamin Szőke4f6092e2023-12-13 15:51:49 -0300158#if CONFIG_IS_ENABLED(FSL_ESDHC_IMX)
159#if CONFIG_IS_ENABLED(ENV_IS_IN_MMC) || CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
160 board_late_mmc_env_init();
161#endif /* CONFIG_ENV_IS_IN_MMC or CONFIG_ENV_IS_NOWHERE */
162#endif
163
Vanessa Maegima27142c32017-05-08 13:17:28 -0300164 /*
165 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
166 * since we use PMIC_PWRON to reset the board.
167 */
168 clrsetbits_le16(&wdog->wcr, 0, 0x10);
169
170 return 0;
171}
172
173int checkboard(void)
174{
175 puts("Board: i.MX7D PICOSOM\n");
176
177 return 0;
178}
179
Fabio Estevam7d8a02a2018-09-28 11:22:39 -0300180static iomux_v3_cfg_t const usb_otg2_pads[] = {
181 MX7D_PAD_UART3_CTS_B__USB_OTG2_PWR | MUX_PAD_CTRL(NO_PAD_CTRL),
182};
183
184int board_ehci_hcd_init(int port)
185{
186 switch (port) {
187 case 0:
188 break;
189 case 1:
190 imx_iomux_v3_setup_multiple_pads(usb_otg2_pads,
191 ARRAY_SIZE(usb_otg2_pads));
192 break;
193 default:
194 return -EINVAL;
195 }
196 return 0;
197}
Benjamin Szőke4f6092e2023-12-13 15:51:49 -0300198
199#if CONFIG_IS_ENABLED(FSL_ESDHC_IMX)
200#if CONFIG_IS_ENABLED(ENV_IS_IN_MMC) || CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
201int board_mmc_get_env_dev(int devno)
202{
203 int dev_env = 0;
204
205 switch (get_boot_device()) {
206 case SD3_BOOT:
207 case MMC3_BOOT:
208 env_set("bootdev", "MMC3");
209 dev_env = PICO_MMC0;
210 break;
211 case SD1_BOOT:
212 env_set("bootdev", "SD1");
213 dev_env = PICO_MMC1;
214 break;
215 default:
216 printf("Wrong boot device!");
217 }
218
219 return dev_env;
220}
221
222int mmc_map_to_kernel_blk(int dev_no)
223{
224 int blk_no = 0;
225
226 switch (dev_no) {
227 case PICO_MMC0:
228 blk_no = PICO_MMC0_BLK;
229 break;
230 case PICO_MMC1:
231 blk_no = PICO_MMC1_BLK;
232 break;
233 default:
234 printf("Invalid MMC device!");
235 }
236
237 return blk_no;
238}
239#endif
240
241#if CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
242int mmc_get_env_dev(void)
243{
244 return board_mmc_get_env_dev(0);
245}
246#endif
247#endif /* CONFIG_FSL_ESDHC_IMX */