Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2020 NXP |
| 4 | */ |
| 5 | |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 6 | #include <miiphy.h> |
| 7 | #include <netdev.h> |
| 8 | #include <asm/arch/imx8ulp-pins.h> |
| 9 | #include <asm/arch/clock.h> |
| 10 | #include <asm/arch/pcc.h> |
| 11 | #include <asm/arch/sys_proto.h> |
| 12 | #include <miiphy.h> |
| 13 | #include <netdev.h> |
Ye Li | 27666ca | 2021-10-29 09:46:21 +0800 | [diff] [blame] | 14 | #include <asm/gpio.h> |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | #if IS_ENABLED(CONFIG_FEC_MXC) |
| 19 | #define ENET_CLK_PAD_CTRL (PAD_CTL_PUS_UP | PAD_CTL_DSE | PAD_CTL_IBE_ENABLE) |
| 20 | static iomux_cfg_t const enet_clk_pads[] = { |
| 21 | IMX8ULP_PAD_PTE19__ENET0_REFCLK | MUX_PAD_CTRL(ENET_CLK_PAD_CTRL), |
| 22 | IMX8ULP_PAD_PTF10__ENET0_1588_CLKIN | MUX_PAD_CTRL(ENET_CLK_PAD_CTRL), |
| 23 | }; |
| 24 | |
| 25 | static int setup_fec(void) |
| 26 | { |
| 27 | /* |
| 28 | * Since ref clock and timestamp clock are from external, |
| 29 | * set the iomux prior the clock enablement |
| 30 | */ |
| 31 | imx8ulp_iomux_setup_multiple_pads(enet_clk_pads, ARRAY_SIZE(enet_clk_pads)); |
| 32 | |
| 33 | /* Select enet time stamp clock: 001 - External Timestamp Clock */ |
| 34 | cgc1_enet_stamp_sel(1); |
| 35 | |
| 36 | /* enable FEC PCC */ |
| 37 | pcc_clock_enable(4, ENET_PCC4_SLOT, true); |
| 38 | pcc_reset_peripheral(4, ENET_PCC4_SLOT, false); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | int board_phy_config(struct phy_device *phydev) |
| 44 | { |
| 45 | if (phydev->drv->config) |
| 46 | phydev->drv->config(phydev); |
| 47 | return 0; |
| 48 | } |
| 49 | #endif |
| 50 | |
Ye Li | 27666ca | 2021-10-29 09:46:21 +0800 | [diff] [blame] | 51 | #define I2C_PAD_CTRL (PAD_CTL_ODE) |
| 52 | static const iomux_cfg_t lpi2c0_pads[] = { |
| 53 | IMX8ULP_PAD_PTA8__LPI2C0_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 54 | IMX8ULP_PAD_PTA9__LPI2C0_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL), |
| 55 | }; |
| 56 | |
| 57 | #define TPM_PAD_CTRL (PAD_CTL_DSE) |
| 58 | static const iomux_cfg_t tpm0_pads[] = { |
| 59 | IMX8ULP_PAD_PTA3__TPM0_CH2 | MUX_PAD_CTRL(TPM_PAD_CTRL), |
| 60 | }; |
| 61 | |
| 62 | void mipi_dsi_mux_panel(void) |
| 63 | { |
| 64 | int ret; |
| 65 | struct gpio_desc desc; |
| 66 | |
| 67 | /* It is temp solution to directly access i2c, need change to rpmsg later */ |
| 68 | |
| 69 | /* enable lpi2c0 clock and iomux */ |
| 70 | imx8ulp_iomux_setup_multiple_pads(lpi2c0_pads, ARRAY_SIZE(lpi2c0_pads)); |
| 71 | writel(0xD2000000, 0x28091060); |
| 72 | |
| 73 | ret = dm_gpio_lookup_name("gpio@20_9", &desc); |
| 74 | if (ret) { |
| 75 | printf("%s lookup gpio@20_9 failed ret = %d\n", __func__, ret); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | ret = dm_gpio_request(&desc, "dsi_mux"); |
| 80 | if (ret) { |
| 81 | printf("%s request dsi_mux failed ret = %d\n", __func__, ret); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 86 | } |
| 87 | |
| 88 | void mipi_dsi_panel_backlight(void) |
| 89 | { |
| 90 | /* It is temp solution to directly access pwm, need change to rpmsg later */ |
| 91 | imx8ulp_iomux_setup_multiple_pads(tpm0_pads, ARRAY_SIZE(tpm0_pads)); |
| 92 | writel(0xD4000001, 0x28091054); |
| 93 | |
| 94 | /* Use center-aligned PWM mode, CPWMS=1, MSnB:MSnA = 10, ELSnB:ELSnA = 00 */ |
| 95 | writel(1000, 0x28095018); |
| 96 | writel(1000, 0x28095034); /* MOD = CV, full duty */ |
| 97 | writel(0x28, 0x28095010); |
| 98 | writel(0x20, 0x28095030); |
| 99 | } |
| 100 | |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 101 | int board_init(void) |
| 102 | { |
Ye Li | a73e59e | 2022-04-06 14:30:23 +0800 | [diff] [blame] | 103 | |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 104 | if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 105 | setup_fec(); |
| 106 | |
Ye Li | a73e59e | 2022-04-06 14:30:23 +0800 | [diff] [blame] | 107 | /* When sync with M33 is failed, use local driver to set for video */ |
Ye Li | 80b3315 | 2023-01-31 16:42:17 +0800 | [diff] [blame] | 108 | if (!is_m33_handshake_necessary() && IS_ENABLED(CONFIG_VIDEO)) { |
Ye Li | 27666ca | 2021-10-29 09:46:21 +0800 | [diff] [blame] | 109 | mipi_dsi_mux_panel(); |
| 110 | mipi_dsi_panel_backlight(); |
| 111 | } |
| 112 | |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | int board_early_init_f(void) |
| 117 | { |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | int board_late_init(void) |
| 122 | { |
Ye Li | b85f483 | 2023-01-31 16:42:34 +0800 | [diff] [blame] | 123 | ulong addr; |
| 124 | |
Peng Fan | e858ca4 | 2022-04-06 14:30:26 +0800 | [diff] [blame] | 125 | #if CONFIG_IS_ENABLED(ENV_IS_IN_MMC) |
| 126 | board_late_mmc_env_init(); |
| 127 | #endif |
Ye Li | b85f483 | 2023-01-31 16:42:34 +0800 | [diff] [blame] | 128 | |
| 129 | /* clear fdtaddr to avoid obsolete data */ |
| 130 | addr = env_get_hex("fdt_addr_r", 0); |
| 131 | if (addr) |
| 132 | memset((void *)addr, 0, 0x400); |
| 133 | |
Peng Fan | cbe5d38 | 2021-08-07 16:01:13 +0800 | [diff] [blame] | 134 | return 0; |
| 135 | } |