Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [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 | 203a227 | 2019-03-05 02:32:49 +0000 | [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> |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 12 | #include <linux/libfdt.h> |
Alifer Moraes | ca43acf | 2020-01-16 12:43:07 -0300 | [diff] [blame] | 13 | #include <fdt_support.h> |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/gpio.h> |
| 16 | #include <asm/arch/clock.h> |
| 17 | #include <asm/arch/sci/sci.h> |
| 18 | #include <asm/arch/imx8-pins.h> |
| 19 | #include <asm/arch/iomux.h> |
| 20 | #include <asm/arch/sys_proto.h> |
| 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | #define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \ |
| 25 | (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \ |
| 26 | (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \ |
| 27 | (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT)) |
| 28 | |
| 29 | static iomux_cfg_t uart0_pads[] = { |
| 30 | SC_P_UART0_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 31 | SC_P_UART0_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 32 | }; |
| 33 | |
| 34 | static void setup_iomux_uart(void) |
| 35 | { |
| 36 | imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads)); |
| 37 | } |
| 38 | |
| 39 | int board_early_init_f(void) |
| 40 | { |
Anatolij Gustschin | ef156d2 | 2019-06-12 13:35:25 +0200 | [diff] [blame] | 41 | sc_pm_clock_rate_t rate = SC_80MHZ; |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 42 | int ret; |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 43 | |
Anatolij Gustschin | ef156d2 | 2019-06-12 13:35:25 +0200 | [diff] [blame] | 44 | /* Set UART0 clock root to 80 MHz */ |
| 45 | ret = sc_pm_setup_uart(SC_R_UART_0, rate); |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 46 | if (ret) |
| 47 | return ret; |
| 48 | |
| 49 | setup_iomux_uart(); |
| 50 | |
| 51 | sc_pm_set_resource_power_mode(-1, SC_R_GPIO_5, SC_PM_PW_MODE_ON); |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
Simon Glass | fa4689a | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 56 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 57 | static void board_gpio_init(void) |
| 58 | { |
| 59 | /* TODO */ |
| 60 | } |
| 61 | #else |
| 62 | static inline void board_gpio_init(void) {} |
| 63 | #endif |
| 64 | |
| 65 | #if IS_ENABLED(CONFIG_FEC_MXC) |
| 66 | #include <miiphy.h> |
| 67 | |
| 68 | int board_phy_config(struct phy_device *phydev) |
| 69 | { |
| 70 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f); |
| 71 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8); |
| 72 | |
| 73 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x00); |
| 74 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x82ee); |
| 75 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05); |
| 76 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100); |
| 77 | |
| 78 | if (phydev->drv->config) |
| 79 | phydev->drv->config(phydev); |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | #endif |
| 84 | |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 85 | int checkboard(void) |
| 86 | { |
| 87 | puts("Board: iMX8QM MEK\n"); |
| 88 | |
| 89 | build_info(); |
| 90 | print_bootinfo(); |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | int board_init(void) |
| 96 | { |
| 97 | /* Power up base board */ |
| 98 | sc_pm_set_resource_power_mode(-1, SC_R_BOARD_R1, SC_PM_PW_MODE_ON); |
| 99 | |
| 100 | board_gpio_init(); |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 105 | /* |
| 106 | * Board specific reset that is system reset. |
| 107 | */ |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame^] | 108 | void reset_cpu(void) |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 109 | { |
| 110 | /* TODO */ |
| 111 | } |
| 112 | |
| 113 | #ifdef CONFIG_OF_BOARD_SETUP |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 114 | int ft_board_setup(void *blob, struct bd_info *bd) |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 115 | { |
| 116 | return 0; |
| 117 | } |
| 118 | #endif |
| 119 | |
| 120 | int board_mmc_get_env_dev(int devno) |
| 121 | { |
| 122 | return devno; |
| 123 | } |
| 124 | |
| 125 | int board_late_init(void) |
| 126 | { |
Peng Fan | 88b119e | 2020-05-05 20:28:44 +0800 | [diff] [blame] | 127 | char *fdt_file; |
| 128 | bool m4_booted; |
| 129 | |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 130 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 131 | env_set("board_name", "MEK"); |
| 132 | env_set("board_rev", "iMX8QM"); |
| 133 | #endif |
| 134 | |
Peng Fan | 88b119e | 2020-05-05 20:28:44 +0800 | [diff] [blame] | 135 | fdt_file = env_get("fdt_file"); |
| 136 | m4_booted = m4_parts_booted(); |
| 137 | |
| 138 | if (fdt_file && !strcmp(fdt_file, "undefined")) { |
| 139 | if (m4_booted) |
| 140 | env_set("fdt_file", "imx8qm-mek-rpmsg.dtb"); |
| 141 | else |
| 142 | env_set("fdt_file", "imx8qm-mek.dtb"); |
| 143 | } |
| 144 | |
Peng Fan | 203a227 | 2019-03-05 02:32:49 +0000 | [diff] [blame] | 145 | return 0; |
| 146 | } |