Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 NXP Semiconductors |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 6 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 7 | #include <net.h> |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 8 | #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 Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 14 | #include <asm/gpio.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 15 | #include <asm/mach-imx/iomux-v3.h> |
Benjamin Szőke | 4f6092e | 2023-12-13 15:51:49 -0300 | [diff] [blame] | 16 | #include <asm/mach-imx/boot_mode.h> |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 17 | #include <asm/io.h> |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 18 | #include <miiphy.h> |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 19 | #include <power/pmic.h> |
| 20 | #include <power/pfuze3000_pmic.h> |
| 21 | #include "../../freescale/common/pfuze.h" |
| 22 | |
| 23 | DECLARE_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őke | 4f6092e | 2023-12-13 15:51:49 -0300 | [diff] [blame] | 28 | #define PICO_MMC0 0 |
| 29 | #define PICO_MMC0_BLK 2 |
| 30 | #define PICO_MMC1 1 |
| 31 | #define PICO_MMC1_BLK 0 |
| 32 | |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 33 | int dram_init(void) |
| 34 | { |
Fabio Estevam | 6ed3981 | 2018-06-29 15:19:11 -0300 | [diff] [blame] | 35 | gd->ram_size = imx_ddr_size(); |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 36 | |
Jun Nie | feb1344 | 2019-05-08 14:38:32 +0800 | [diff] [blame] | 37 | /* 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 Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 42 | return 0; |
| 43 | } |
| 44 | |
Fabio Estevam | b31953e | 2023-01-03 10:19:40 -0300 | [diff] [blame] | 45 | #if CONFIG_IS_ENABLED(DM_PMIC) |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 46 | int power_init_board(void) |
| 47 | { |
Fabio Estevam | b31953e | 2023-01-03 10:19:40 -0300 | [diff] [blame] | 48 | struct udevice *dev; |
| 49 | int reg, rev_id; |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 50 | int ret; |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 51 | |
Fabio Estevam | b31953e | 2023-01-03 10:19:40 -0300 | [diff] [blame] | 52 | ret = pmic_get("pfuze3000@8", &dev); |
| 53 | if (ret == -ENODEV) |
Jun Nie | 8600eef | 2019-05-08 14:38:36 +0800 | [diff] [blame] | 54 | return 0; |
Fabio Estevam | b31953e | 2023-01-03 10:19:40 -0300 | [diff] [blame] | 55 | if (ret != 0) |
| 56 | return ret; |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 57 | |
Fabio Estevam | b31953e | 2023-01-03 10:19:40 -0300 | [diff] [blame] | 58 | 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 Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 61 | |
| 62 | /* disable Low Power Mode during standby mode */ |
Fabio Estevam | b31953e | 2023-01-03 10:19:40 -0300 | [diff] [blame] | 63 | reg = pmic_reg_read(dev, PFUZE3000_LDOGCTL); |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 64 | reg |= 0x1; |
Fabio Estevam | b31953e | 2023-01-03 10:19:40 -0300 | [diff] [blame] | 65 | pmic_reg_write(dev, PFUZE3000_LDOGCTL, reg); |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 66 | |
| 67 | /* SW1A/1B mode set to APS/APS */ |
| 68 | reg = 0x8; |
Fabio Estevam | b31953e | 2023-01-03 10:19:40 -0300 | [diff] [blame] | 69 | pmic_reg_write(dev, PFUZE3000_SW1AMODE, reg); |
| 70 | pmic_reg_write(dev, PFUZE3000_SW1BMODE, reg); |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 71 | |
| 72 | /* SW1A/1B standby voltage set to 1.025V */ |
| 73 | reg = 0xd; |
Fabio Estevam | b31953e | 2023-01-03 10:19:40 -0300 | [diff] [blame] | 74 | pmic_reg_write(dev, PFUZE3000_SW1ASTBY, reg); |
| 75 | pmic_reg_write(dev, PFUZE3000_SW1BSTBY, reg); |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 76 | |
| 77 | /* decrease SW1B normal voltage to 0.975V */ |
Fabio Estevam | b31953e | 2023-01-03 10:19:40 -0300 | [diff] [blame] | 78 | reg = pmic_reg_read(dev, PFUZE3000_SW1BVOLT); |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 79 | reg &= ~0x1f; |
| 80 | reg |= PFUZE3000_SW1AB_SETP(975); |
Fabio Estevam | b31953e | 2023-01-03 10:19:40 -0300 | [diff] [blame] | 81 | pmic_reg_write(dev, PFUZE3000_SW1BVOLT, reg); |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | #endif |
| 86 | |
| 87 | static iomux_v3_cfg_t const wdog_pads[] = { |
| 88 | MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 89 | }; |
| 90 | |
| 91 | static 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 Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 96 | #ifdef CONFIG_FEC_MXC |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 97 | static 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 Nelson | eadd732 | 2017-08-31 08:34:23 -0700 | [diff] [blame] | 107 | return set_clk_enet(ENET_125MHZ); |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 108 | } |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 109 | #endif |
| 110 | |
| 111 | static void setup_iomux_uart(void) |
| 112 | { |
| 113 | imx_iomux_v3_setup_multiple_pads(uart5_pads, ARRAY_SIZE(uart5_pads)); |
| 114 | } |
| 115 | |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 116 | int board_early_init_f(void) |
| 117 | { |
| 118 | setup_iomux_uart(); |
| 119 | |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | |
Simon Glass | 52cb504 | 2022-10-18 07:46:31 -0600 | [diff] [blame] | 123 | #ifdef CONFIG_VIDEO |
Fabio Estevam | fb3532d | 2018-12-11 16:40:38 -0200 | [diff] [blame] | 124 | void setup_lcd(void) |
| 125 | { |
Joris Offouga | 0dc6a40e | 2019-04-04 14:00:54 +0200 | [diff] [blame] | 126 | gpio_request(IMX_GPIO_NR(1, 11), "lcd_brightness"); |
| 127 | gpio_request(IMX_GPIO_NR(1, 6), "lcd_enable"); |
Fabio Estevam | fb3532d | 2018-12-11 16:40:38 -0200 | [diff] [blame] | 128 | /* 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 Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 135 | int board_init(void) |
| 136 | { |
| 137 | /* address of boot parameters */ |
| 138 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 139 | |
Simon Glass | 52cb504 | 2022-10-18 07:46:31 -0600 | [diff] [blame] | 140 | #ifdef CONFIG_VIDEO |
Fabio Estevam | fb3532d | 2018-12-11 16:40:38 -0200 | [diff] [blame] | 141 | setup_lcd(); |
| 142 | #endif |
Vanessa Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 143 | #ifdef CONFIG_FEC_MXC |
| 144 | setup_fec(); |
| 145 | #endif |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | int 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őke | 4f6092e | 2023-12-13 15:51:49 -0300 | [diff] [blame] | 158 | #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 Maegima | 27142c3 | 2017-05-08 13:17:28 -0300 | [diff] [blame] | 164 | /* |
| 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 | |
| 173 | int checkboard(void) |
| 174 | { |
| 175 | puts("Board: i.MX7D PICOSOM\n"); |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
Fabio Estevam | 7d8a02a | 2018-09-28 11:22:39 -0300 | [diff] [blame] | 180 | static 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 | |
| 184 | int 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őke | 4f6092e | 2023-12-13 15:51:49 -0300 | [diff] [blame] | 198 | |
| 199 | #if CONFIG_IS_ENABLED(FSL_ESDHC_IMX) |
| 200 | #if CONFIG_IS_ENABLED(ENV_IS_IN_MMC) || CONFIG_IS_ENABLED(ENV_IS_NOWHERE) |
| 201 | int 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 | |
| 222 | int 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) |
| 242 | int mmc_get_env_dev(void) |
| 243 | { |
| 244 | return board_mmc_get_env_dev(0); |
| 245 | } |
| 246 | #endif |
| 247 | #endif /* CONFIG_FSL_ESDHC_IMX */ |