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 | 1f911d4 | 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> |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 11 | #include <linux/libfdt.h> |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 12 | #include <fsl_esdhc_imx.h> |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | #include <asm/gpio.h> |
| 15 | #include <asm/arch/clock.h> |
| 16 | #include <asm/arch/sci/sci.h> |
| 17 | #include <asm/arch/imx8-pins.h> |
| 18 | #include <asm/arch/iomux.h> |
| 19 | #include <asm/arch/sys_proto.h> |
| 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | #define GPIO_PAD_CTRL ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \ |
| 24 | (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \ |
| 25 | (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \ |
| 26 | (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT)) |
| 27 | |
| 28 | #define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \ |
| 29 | (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \ |
| 30 | (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \ |
| 31 | (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT)) |
| 32 | |
| 33 | static iomux_cfg_t uart0_pads[] = { |
| 34 | SC_P_UART0_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 35 | SC_P_UART0_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 36 | }; |
| 37 | |
| 38 | static void setup_iomux_uart(void) |
| 39 | { |
| 40 | imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads)); |
| 41 | } |
| 42 | |
| 43 | int board_early_init_f(void) |
| 44 | { |
Anatolij Gustschin | ef156d2 | 2019-06-12 13:35:25 +0200 | [diff] [blame] | 45 | sc_pm_clock_rate_t rate = SC_80MHZ; |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 46 | int ret; |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 47 | |
Anatolij Gustschin | ef156d2 | 2019-06-12 13:35:25 +0200 | [diff] [blame] | 48 | /* Set UART0 clock root to 80 MHz */ |
| 49 | ret = sc_pm_setup_uart(SC_R_UART_0, rate); |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 50 | if (ret) |
| 51 | return ret; |
| 52 | |
| 53 | setup_iomux_uart(); |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Simon Glass | fa4689a | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 58 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 59 | static void board_gpio_init(void) |
| 60 | { |
| 61 | struct gpio_desc desc; |
| 62 | int ret; |
| 63 | |
| 64 | ret = dm_gpio_lookup_name("gpio@1a_3", &desc); |
| 65 | if (ret) |
| 66 | return; |
| 67 | |
| 68 | ret = dm_gpio_request(&desc, "bb_per_rst_b"); |
| 69 | if (ret) |
| 70 | return; |
| 71 | |
| 72 | dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT); |
| 73 | dm_gpio_set_value(&desc, 0); |
| 74 | udelay(50); |
| 75 | dm_gpio_set_value(&desc, 1); |
| 76 | } |
| 77 | #else |
| 78 | static inline void board_gpio_init(void) {} |
| 79 | #endif |
| 80 | |
| 81 | #if IS_ENABLED(CONFIG_FEC_MXC) |
| 82 | #include <miiphy.h> |
| 83 | |
| 84 | int board_phy_config(struct phy_device *phydev) |
| 85 | { |
| 86 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f); |
| 87 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8); |
| 88 | |
| 89 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05); |
| 90 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100); |
| 91 | |
| 92 | if (phydev->drv->config) |
| 93 | phydev->drv->config(phydev); |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | #endif |
| 98 | |
Peng Fan | 702c6dc | 2018-10-18 14:28:37 +0200 | [diff] [blame] | 99 | int checkboard(void) |
| 100 | { |
| 101 | puts("Board: iMX8QXP MEK\n"); |
| 102 | |
| 103 | build_info(); |
| 104 | print_bootinfo(); |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | int board_init(void) |
| 110 | { |
| 111 | board_gpio_init(); |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | void detail_board_ddr_info(void) |
| 117 | { |
| 118 | puts("\nDDR "); |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * Board specific reset that is system reset. |
| 123 | */ |
| 124 | void reset_cpu(ulong addr) |
| 125 | { |
| 126 | /* TODO */ |
| 127 | } |
| 128 | |
| 129 | #ifdef CONFIG_OF_BOARD_SETUP |
| 130 | int ft_board_setup(void *blob, bd_t *bd) |
| 131 | { |
| 132 | return 0; |
| 133 | } |
| 134 | #endif |
| 135 | |
| 136 | int board_mmc_get_env_dev(int devno) |
| 137 | { |
| 138 | return devno; |
| 139 | } |
| 140 | |
| 141 | int board_late_init(void) |
| 142 | { |
| 143 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 144 | env_set("board_name", "MEK"); |
| 145 | env_set("board_rev", "iMX8QXP"); |
| 146 | #endif |
| 147 | |
| 148 | return 0; |
| 149 | } |