Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2018 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 7 | #include <cpu_func.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 8 | #include <env.h> |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 9 | #include <errno.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 12 | #include <linux/delay.h> |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 13 | #include <linux/libfdt.h> |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 14 | #include <fsl_esdhc_imx.h> |
Alifer Moraes | c9c48d9 | 2020-01-16 12:43:06 -0300 | [diff] [blame] | 15 | #include <fdt_support.h> |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | #include <asm/gpio.h> |
| 18 | #include <asm/arch/clock.h> |
| 19 | #include <asm/arch/sci/sci.h> |
| 20 | #include <asm/arch/imx8-pins.h> |
Franck LENORMAND | d3b70ea | 2019-10-09 10:27:43 +0200 | [diff] [blame] | 21 | #include <asm/arch/snvs_security_sc.h> |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 22 | #include <asm/arch/iomux.h> |
| 23 | #include <asm/arch/sys_proto.h> |
| 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | #define GPIO_PAD_CTRL ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \ |
| 28 | (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \ |
| 29 | (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \ |
| 30 | (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT)) |
| 31 | |
| 32 | #define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \ |
| 33 | (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \ |
| 34 | (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \ |
| 35 | (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT)) |
| 36 | |
| 37 | static iomux_cfg_t uart0_pads[] = { |
| 38 | SC_P_UART0_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 39 | SC_P_UART0_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 40 | }; |
| 41 | |
| 42 | static void setup_iomux_uart(void) |
| 43 | { |
| 44 | imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads)); |
| 45 | } |
| 46 | |
| 47 | int board_early_init_f(void) |
| 48 | { |
Anatolij Gustschin | ef156d2 | 2019-06-12 13:35:25 +0200 | [diff] [blame] | 49 | sc_pm_clock_rate_t rate = SC_80MHZ; |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 50 | int ret; |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 51 | |
Anatolij Gustschin | ef156d2 | 2019-06-12 13:35:25 +0200 | [diff] [blame] | 52 | /* Set UART0 clock root to 80 MHz */ |
| 53 | ret = sc_pm_setup_uart(SC_R_UART_0, rate); |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 54 | if (ret) |
| 55 | return ret; |
| 56 | |
| 57 | setup_iomux_uart(); |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
Simon Glass | fa4689a | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 62 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 63 | static void board_gpio_init(void) |
| 64 | { |
| 65 | struct gpio_desc desc; |
| 66 | int ret; |
| 67 | |
| 68 | ret = dm_gpio_lookup_name("gpio@1a_3", &desc); |
| 69 | if (ret) |
| 70 | return; |
| 71 | |
| 72 | ret = dm_gpio_request(&desc, "bb_per_rst_b"); |
| 73 | if (ret) |
| 74 | return; |
| 75 | |
| 76 | dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT); |
| 77 | dm_gpio_set_value(&desc, 0); |
| 78 | udelay(50); |
| 79 | dm_gpio_set_value(&desc, 1); |
| 80 | } |
| 81 | #else |
| 82 | static inline void board_gpio_init(void) {} |
| 83 | #endif |
| 84 | |
| 85 | #if IS_ENABLED(CONFIG_FEC_MXC) |
| 86 | #include <miiphy.h> |
| 87 | |
| 88 | int board_phy_config(struct phy_device *phydev) |
| 89 | { |
| 90 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f); |
| 91 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8); |
| 92 | |
| 93 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05); |
| 94 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100); |
| 95 | |
| 96 | if (phydev->drv->config) |
| 97 | phydev->drv->config(phydev); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | #endif |
| 102 | |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 103 | int checkboard(void) |
| 104 | { |
| 105 | puts("Board: iMX8QXP MEK\n"); |
| 106 | |
| 107 | build_info(); |
| 108 | print_bootinfo(); |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | int board_init(void) |
| 114 | { |
| 115 | board_gpio_init(); |
| 116 | |
Franck LENORMAND | d3b70ea | 2019-10-09 10:27:43 +0200 | [diff] [blame] | 117 | #ifdef CONFIG_IMX_SNVS_SEC_SC_AUTO |
| 118 | { |
| 119 | int ret = snvs_security_sc_init(); |
| 120 | |
| 121 | if (ret) |
| 122 | return ret; |
| 123 | } |
| 124 | #endif |
| 125 | |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 129 | /* |
| 130 | * Board specific reset that is system reset. |
| 131 | */ |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 132 | void reset_cpu(void) |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 133 | { |
| 134 | /* TODO */ |
| 135 | } |
| 136 | |
| 137 | #ifdef CONFIG_OF_BOARD_SETUP |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 138 | int ft_board_setup(void *blob, struct bd_info *bd) |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 139 | { |
| 140 | return 0; |
| 141 | } |
| 142 | #endif |
| 143 | |
| 144 | int board_mmc_get_env_dev(int devno) |
| 145 | { |
| 146 | return devno; |
| 147 | } |
| 148 | |
| 149 | int board_late_init(void) |
| 150 | { |
Peng Fan | e95219d | 2020-05-05 20:28:45 +0800 | [diff] [blame] | 151 | char *fdt_file; |
| 152 | bool m4_booted; |
| 153 | |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 154 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 155 | env_set("board_name", "MEK"); |
| 156 | env_set("board_rev", "iMX8QXP"); |
| 157 | #endif |
| 158 | |
Peng Fan | e95219d | 2020-05-05 20:28:45 +0800 | [diff] [blame] | 159 | fdt_file = env_get("fdt_file"); |
| 160 | m4_booted = m4_parts_booted(); |
| 161 | |
| 162 | if (fdt_file && !strcmp(fdt_file, "undefined")) { |
| 163 | if (m4_booted) |
| 164 | env_set("fdt_file", "imx8qxp-mek-rpmsg.dtb"); |
| 165 | else |
| 166 | env_set("fdt_file", "imx8qxp-mek.dtb"); |
| 167 | } |
| 168 | |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 169 | return 0; |
| 170 | } |