Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright 2019 NXP |
| 4 | * Peng Fan <peng.fan@nxp.com> |
| 5 | */ |
| 6 | |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 7 | #include <clk.h> |
| 8 | #include <clk-uclass.h> |
| 9 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/imx-regs.h> |
| 13 | #include <dt-bindings/clock/imx8mn-clock.h> |
| 14 | |
| 15 | #include "clk.h" |
| 16 | |
Michael Trimarchi | 252e54e | 2022-08-30 16:45:20 +0200 | [diff] [blame] | 17 | static u32 share_count_nand; |
| 18 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 19 | static const char * const pll_ref_sels[] = { "clock-osc-24m", "dummy", "dummy", "dummy", }; |
| 20 | static const char * const dram_pll_bypass_sels[] = {"dram_pll", "dram_pll_ref_sel", }; |
| 21 | static const char * const arm_pll_bypass_sels[] = {"arm_pll", "arm_pll_ref_sel", }; |
| 22 | static const char * const sys_pll1_bypass_sels[] = {"sys_pll1", "sys_pll1_ref_sel", }; |
| 23 | static const char * const sys_pll2_bypass_sels[] = {"sys_pll2", "sys_pll2_ref_sel", }; |
| 24 | static const char * const sys_pll3_bypass_sels[] = {"sys_pll3", "sys_pll3_ref_sel", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 25 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 26 | static const char * const imx8mn_a53_sels[] = {"clock-osc-24m", "arm_pll_out", "sys_pll2_500m", |
| 27 | "sys_pll2_1000m", "sys_pll1_800m", "sys_pll1_400m", |
| 28 | "audio_pll1_out", "sys_pll3_out", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 29 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 30 | static const char * const imx8mn_ahb_sels[] = {"clock-osc-24m", "sys_pll1_133m", "sys_pll1_800m", |
| 31 | "sys_pll1_400m", "sys_pll2_125m", "sys_pll3_out", |
| 32 | "audio_pll1_out", "video_pll_out", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 33 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 34 | static const char * const imx8mn_enet_axi_sels[] = {"clock-osc-24m", "sys_pll1_266m", "sys_pll1_800m", |
| 35 | "sys_pll2_250m", "sys_pll2_200m", "audio_pll1_out", |
| 36 | "video_pll_out", "sys_pll3_out", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 37 | |
Ye Li | 418c1fc | 2020-04-18 08:19:12 -0700 | [diff] [blame] | 38 | #ifndef CONFIG_SPL_BUILD |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 39 | static const char * const imx8mn_enet_ref_sels[] = {"clock-osc-24m", "sys_pll2_125m", "sys_pll2_50m", |
| 40 | "sys_pll2_100m", "sys_pll1_160m", "audio_pll1_out", |
| 41 | "video_pll_out", "clk_ext4", }; |
Ye Li | 418c1fc | 2020-04-18 08:19:12 -0700 | [diff] [blame] | 42 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 43 | static const char * const imx8mn_enet_timer_sels[] = {"clock-osc-24m", "sys_pll2_100m", "audio_pll1_out", |
| 44 | "clk_ext1", "clk_ext2", "clk_ext3", |
| 45 | "clk_ext4", "video_pll_out", }; |
Ye Li | 418c1fc | 2020-04-18 08:19:12 -0700 | [diff] [blame] | 46 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 47 | static const char * const imx8mn_enet_phy_sels[] = {"clock-osc-24m", "sys_pll2_50m", "sys_pll2_125m", |
| 48 | "sys_pll2_200m", "sys_pll2_500m", "audio_pll1_out", |
| 49 | "video_pll_out", "audio_pll2_out", }; |
Ye Li | 418c1fc | 2020-04-18 08:19:12 -0700 | [diff] [blame] | 50 | #endif |
| 51 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 52 | static const char * const imx8mn_nand_usdhc_sels[] = {"clock-osc-24m", "sys_pll1_266m", "sys_pll1_800m", |
| 53 | "sys_pll2_200m", "sys_pll1_133m", "sys_pll3_out", |
| 54 | "sys_pll2_250m", "audio_pll1_out", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 55 | |
Ye Li | 0321edb | 2020-04-19 02:22:09 -0700 | [diff] [blame] | 56 | static const char * const imx8mn_usb_bus_sels[] = {"clock-osc-24m", "sys_pll2_500m", "sys_pll1_800m", |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 57 | "sys_pll2_100m", "sys_pll2_200m", "clk_ext2", |
| 58 | "clk_ext4", "audio_pll2_out", }; |
Ye Li | 0321edb | 2020-04-19 02:22:09 -0700 | [diff] [blame] | 59 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 60 | static const char * const imx8mn_usdhc1_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m", |
| 61 | "sys_pll2_500m", "sys_pll3_out", "sys_pll1_266m", |
| 62 | "audio_pll2_out", "sys_pll1_100m", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 63 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 64 | static const char * const imx8mn_usdhc2_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m", |
| 65 | "sys_pll2_500m", "sys_pll3_out", "sys_pll1_266m", |
| 66 | "audio_pll2_out", "sys_pll1_100m", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 67 | |
Marek Vasut | b1a8bb0 | 2021-01-19 00:58:31 +0100 | [diff] [blame] | 68 | #if CONFIG_IS_ENABLED(DM_SPI) |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 69 | static const char * const imx8mn_ecspi1_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m", |
| 70 | "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out", |
| 71 | "sys_pll2_250m", "audio_pll2_out", }; |
Marek Vasut | b1a8bb0 | 2021-01-19 00:58:31 +0100 | [diff] [blame] | 72 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 73 | static const char * const imx8mn_ecspi2_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m", |
| 74 | "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out", |
| 75 | "sys_pll2_250m", "audio_pll2_out", }; |
Marek Vasut | b1a8bb0 | 2021-01-19 00:58:31 +0100 | [diff] [blame] | 76 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 77 | static const char * const imx8mn_ecspi3_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m", |
| 78 | "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out", |
| 79 | "sys_pll2_250m", "audio_pll2_out", }; |
Marek Vasut | b1a8bb0 | 2021-01-19 00:58:31 +0100 | [diff] [blame] | 80 | #endif |
| 81 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 82 | static const char * const imx8mn_i2c1_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", |
| 83 | "sys_pll3_out", "audio_pll1_out", "video_pll_out", |
| 84 | "audio_pll2_out", "sys_pll1_133m", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 85 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 86 | static const char * const imx8mn_i2c2_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", |
| 87 | "sys_pll3_out", "audio_pll1_out", "video_pll_out", |
| 88 | "audio_pll2_out", "sys_pll1_133m", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 89 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 90 | static const char * const imx8mn_i2c3_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", |
| 91 | "sys_pll3_out", "audio_pll1_out", "video_pll_out", |
| 92 | "audio_pll2_out", "sys_pll1_133m", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 93 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 94 | static const char * const imx8mn_i2c4_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", |
| 95 | "sys_pll3_out", "audio_pll1_out", "video_pll_out", |
| 96 | "audio_pll2_out", "sys_pll1_133m", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 97 | |
Nicolas Heemeryck | e5e8523 | 2023-12-11 11:06:13 +0100 | [diff] [blame] | 98 | #ifndef CONFIG_SPL_BUILD |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 99 | static const char * const imx8mn_pwm1_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m", |
| 100 | "sys_pll1_40m", "sys_pll3_out", "clk_ext1", |
| 101 | "sys_pll1_80m", "video_pll_out", }; |
Nicolas Heemeryck | e5e8523 | 2023-12-11 11:06:13 +0100 | [diff] [blame] | 102 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 103 | static const char * const imx8mn_pwm2_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m", |
| 104 | "sys_pll1_40m", "sys_pll3_out", "clk_ext1", |
| 105 | "sys_pll1_80m", "video_pll_out", }; |
Nicolas Heemeryck | e5e8523 | 2023-12-11 11:06:13 +0100 | [diff] [blame] | 106 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 107 | static const char * const imx8mn_pwm3_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m", |
| 108 | "sys_pll1_40m", "sys_pll3_out", "clk_ext2", |
| 109 | "sys_pll1_80m", "video_pll_out", }; |
Nicolas Heemeryck | e5e8523 | 2023-12-11 11:06:13 +0100 | [diff] [blame] | 110 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 111 | static const char * const imx8mn_pwm4_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m", |
| 112 | "sys_pll1_40m", "sys_pll3_out", "clk_ext2", |
| 113 | "sys_pll1_80m", "video_pll_out", }; |
Nicolas Heemeryck | e5e8523 | 2023-12-11 11:06:13 +0100 | [diff] [blame] | 114 | #endif |
| 115 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 116 | static const char * const imx8mn_wdog_sels[] = {"clock-osc-24m", "sys_pll1_133m", "sys_pll1_160m", |
| 117 | "m7_alt_pll", "sys_pll2_125m", "sys_pll3_out", |
| 118 | "sys_pll1_80m", "sys_pll2_166m", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 119 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 120 | static const char * const imx8mn_usdhc3_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m", |
| 121 | "sys_pll2_500m", "sys_pll3_out", "sys_pll1_266m", |
| 122 | "audio_pll2_clk", "sys_pll1_100m", }; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 123 | |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 124 | static const char * const imx8mn_qspi_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll2_333m", |
| 125 | "sys_pll2_500m", "audio_pll2_out", "sys_pll1_266m", |
| 126 | "sys_pll3_out", "sys_pll1_100m", }; |
Ye Li | 418c1fc | 2020-04-18 08:19:12 -0700 | [diff] [blame] | 127 | |
Michael Trimarchi | 2468583 | 2024-07-07 10:19:58 +0200 | [diff] [blame] | 128 | static const char * const imx8mn_nand_sels[] = {"clock-osc-24m", "sys_pll2_500m", "audio_pll1_out", |
Michael Trimarchi | 252e54e | 2022-08-30 16:45:20 +0200 | [diff] [blame] | 129 | "sys_pll1_400m", "audio_pll2_out", "sys_pll3_out", |
Dario Binacchi | 2f51cf9 | 2022-12-19 12:31:25 +0100 | [diff] [blame] | 130 | "sys_pll2_250m", "video_pll_out", }; |
Michael Trimarchi | 252e54e | 2022-08-30 16:45:20 +0200 | [diff] [blame] | 131 | |
Ye Li | 0321edb | 2020-04-19 02:22:09 -0700 | [diff] [blame] | 132 | static const char * const imx8mn_usb_core_sels[] = {"clock-osc-24m", "sys_pll1_100m", "sys_pll1_40m", |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 133 | "sys_pll2_100m", "sys_pll2_200m", "clk_ext2", |
| 134 | "clk_ext3", "audio_pll2_out", }; |
Ye Li | 0321edb | 2020-04-19 02:22:09 -0700 | [diff] [blame] | 135 | |
| 136 | static const char * const imx8mn_usb_phy_sels[] = {"clock-osc-24m", "sys_pll1_100m", "sys_pll1_40m", |
Michael Trimarchi | a5e8304 | 2024-07-07 10:19:59 +0200 | [diff] [blame^] | 137 | "sys_pll2_100m", "sys_pll2_200m", "clk_ext2", |
| 138 | "clk_ext3", "audio_pll2_out", }; |
Ye Li | 0321edb | 2020-04-19 02:22:09 -0700 | [diff] [blame] | 139 | |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 140 | static int imx8mn_clk_probe(struct udevice *dev) |
| 141 | { |
Michael Trimarchi | 2468583 | 2024-07-07 10:19:58 +0200 | [diff] [blame] | 142 | struct clk osc_24m_clk; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 143 | void __iomem *base; |
Michael Trimarchi | 2468583 | 2024-07-07 10:19:58 +0200 | [diff] [blame] | 144 | int ret; |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 145 | |
| 146 | base = (void *)ANATOP_BASE_ADDR; |
| 147 | |
| 148 | clk_dm(IMX8MN_DRAM_PLL_REF_SEL, |
| 149 | imx_clk_mux("dram_pll_ref_sel", base + 0x50, 0, 2, |
| 150 | pll_ref_sels, ARRAY_SIZE(pll_ref_sels))); |
| 151 | clk_dm(IMX8MN_ARM_PLL_REF_SEL, |
| 152 | imx_clk_mux("arm_pll_ref_sel", base + 0x84, 0, 2, |
| 153 | pll_ref_sels, ARRAY_SIZE(pll_ref_sels))); |
| 154 | clk_dm(IMX8MN_SYS_PLL1_REF_SEL, |
| 155 | imx_clk_mux("sys_pll1_ref_sel", base + 0x94, 0, 2, |
| 156 | pll_ref_sels, ARRAY_SIZE(pll_ref_sels))); |
| 157 | clk_dm(IMX8MN_SYS_PLL2_REF_SEL, |
| 158 | imx_clk_mux("sys_pll2_ref_sel", base + 0x104, 0, 2, |
| 159 | pll_ref_sels, ARRAY_SIZE(pll_ref_sels))); |
| 160 | clk_dm(IMX8MN_SYS_PLL3_REF_SEL, |
| 161 | imx_clk_mux("sys_pll3_ref_sel", base + 0x114, 0, 2, |
| 162 | pll_ref_sels, ARRAY_SIZE(pll_ref_sels))); |
| 163 | |
| 164 | clk_dm(IMX8MN_DRAM_PLL, |
| 165 | imx_clk_pll14xx("dram_pll", "dram_pll_ref_sel", |
Angus Ainslie | 73d75ec | 2022-03-29 07:02:40 -0700 | [diff] [blame] | 166 | base + 0x50, &imx_1443x_dram_pll)); |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 167 | clk_dm(IMX8MN_ARM_PLL, |
| 168 | imx_clk_pll14xx("arm_pll", "arm_pll_ref_sel", |
Angus Ainslie | 73d75ec | 2022-03-29 07:02:40 -0700 | [diff] [blame] | 169 | base + 0x84, &imx_1416x_pll)); |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 170 | clk_dm(IMX8MN_SYS_PLL1, |
| 171 | imx_clk_pll14xx("sys_pll1", "sys_pll1_ref_sel", |
Angus Ainslie | 73d75ec | 2022-03-29 07:02:40 -0700 | [diff] [blame] | 172 | base + 0x94, &imx_1416x_pll)); |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 173 | clk_dm(IMX8MN_SYS_PLL2, |
| 174 | imx_clk_pll14xx("sys_pll2", "sys_pll2_ref_sel", |
Angus Ainslie | 73d75ec | 2022-03-29 07:02:40 -0700 | [diff] [blame] | 175 | base + 0x104, &imx_1416x_pll)); |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 176 | clk_dm(IMX8MN_SYS_PLL3, |
| 177 | imx_clk_pll14xx("sys_pll3", "sys_pll3_ref_sel", |
Angus Ainslie | 73d75ec | 2022-03-29 07:02:40 -0700 | [diff] [blame] | 178 | base + 0x114, &imx_1416x_pll)); |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 179 | |
| 180 | /* PLL bypass out */ |
| 181 | clk_dm(IMX8MN_DRAM_PLL_BYPASS, |
| 182 | imx_clk_mux_flags("dram_pll_bypass", base + 0x50, 4, 1, |
| 183 | dram_pll_bypass_sels, |
| 184 | ARRAY_SIZE(dram_pll_bypass_sels), |
| 185 | CLK_SET_RATE_PARENT)); |
| 186 | clk_dm(IMX8MN_ARM_PLL_BYPASS, |
| 187 | imx_clk_mux_flags("arm_pll_bypass", base + 0x84, 4, 1, |
| 188 | arm_pll_bypass_sels, |
| 189 | ARRAY_SIZE(arm_pll_bypass_sels), |
| 190 | CLK_SET_RATE_PARENT)); |
| 191 | clk_dm(IMX8MN_SYS_PLL1_BYPASS, |
| 192 | imx_clk_mux_flags("sys_pll1_bypass", base + 0x94, 4, 1, |
| 193 | sys_pll1_bypass_sels, |
| 194 | ARRAY_SIZE(sys_pll1_bypass_sels), |
| 195 | CLK_SET_RATE_PARENT)); |
| 196 | clk_dm(IMX8MN_SYS_PLL2_BYPASS, |
| 197 | imx_clk_mux_flags("sys_pll2_bypass", base + 0x104, 4, 1, |
| 198 | sys_pll2_bypass_sels, |
| 199 | ARRAY_SIZE(sys_pll2_bypass_sels), |
| 200 | CLK_SET_RATE_PARENT)); |
| 201 | clk_dm(IMX8MN_SYS_PLL3_BYPASS, |
| 202 | imx_clk_mux_flags("sys_pll3_bypass", base + 0x114, 4, 1, |
| 203 | sys_pll3_bypass_sels, |
| 204 | ARRAY_SIZE(sys_pll3_bypass_sels), |
| 205 | CLK_SET_RATE_PARENT)); |
| 206 | |
| 207 | /* PLL out gate */ |
| 208 | clk_dm(IMX8MN_DRAM_PLL_OUT, |
| 209 | imx_clk_gate("dram_pll_out", "dram_pll_bypass", |
| 210 | base + 0x50, 13)); |
| 211 | clk_dm(IMX8MN_ARM_PLL_OUT, |
| 212 | imx_clk_gate("arm_pll_out", "arm_pll_bypass", |
| 213 | base + 0x84, 11)); |
| 214 | clk_dm(IMX8MN_SYS_PLL1_OUT, |
| 215 | imx_clk_gate("sys_pll1_out", "sys_pll1_bypass", |
| 216 | base + 0x94, 11)); |
| 217 | clk_dm(IMX8MN_SYS_PLL2_OUT, |
| 218 | imx_clk_gate("sys_pll2_out", "sys_pll2_bypass", |
| 219 | base + 0x104, 11)); |
| 220 | clk_dm(IMX8MN_SYS_PLL3_OUT, |
| 221 | imx_clk_gate("sys_pll3_out", "sys_pll3_bypass", |
| 222 | base + 0x114, 11)); |
| 223 | |
| 224 | /* SYS PLL fixed output */ |
| 225 | clk_dm(IMX8MN_SYS_PLL1_40M, |
| 226 | imx_clk_fixed_factor("sys_pll1_40m", "sys_pll1_out", 1, 20)); |
| 227 | clk_dm(IMX8MN_SYS_PLL1_80M, |
| 228 | imx_clk_fixed_factor("sys_pll1_80m", "sys_pll1_out", 1, 10)); |
| 229 | clk_dm(IMX8MN_SYS_PLL1_100M, |
| 230 | imx_clk_fixed_factor("sys_pll1_100m", "sys_pll1_out", 1, 8)); |
| 231 | clk_dm(IMX8MN_SYS_PLL1_133M, |
| 232 | imx_clk_fixed_factor("sys_pll1_133m", "sys_pll1_out", 1, 6)); |
| 233 | clk_dm(IMX8MN_SYS_PLL1_160M, |
| 234 | imx_clk_fixed_factor("sys_pll1_160m", "sys_pll1_out", 1, 5)); |
| 235 | clk_dm(IMX8MN_SYS_PLL1_200M, |
| 236 | imx_clk_fixed_factor("sys_pll1_200m", "sys_pll1_out", 1, 4)); |
| 237 | clk_dm(IMX8MN_SYS_PLL1_266M, |
| 238 | imx_clk_fixed_factor("sys_pll1_266m", "sys_pll1_out", 1, 3)); |
| 239 | clk_dm(IMX8MN_SYS_PLL1_400M, |
| 240 | imx_clk_fixed_factor("sys_pll1_400m", "sys_pll1_out", 1, 2)); |
| 241 | clk_dm(IMX8MN_SYS_PLL1_800M, |
| 242 | imx_clk_fixed_factor("sys_pll1_800m", "sys_pll1_out", 1, 1)); |
| 243 | |
| 244 | clk_dm(IMX8MN_SYS_PLL2_50M, |
| 245 | imx_clk_fixed_factor("sys_pll2_50m", "sys_pll2_out", 1, 20)); |
| 246 | clk_dm(IMX8MN_SYS_PLL2_100M, |
| 247 | imx_clk_fixed_factor("sys_pll2_100m", "sys_pll2_out", 1, 10)); |
| 248 | clk_dm(IMX8MN_SYS_PLL2_125M, |
| 249 | imx_clk_fixed_factor("sys_pll2_125m", "sys_pll2_out", 1, 8)); |
| 250 | clk_dm(IMX8MN_SYS_PLL2_166M, |
| 251 | imx_clk_fixed_factor("sys_pll2_166m", "sys_pll2_out", 1, 6)); |
| 252 | clk_dm(IMX8MN_SYS_PLL2_200M, |
| 253 | imx_clk_fixed_factor("sys_pll2_200m", "sys_pll2_out", 1, 5)); |
| 254 | clk_dm(IMX8MN_SYS_PLL2_250M, |
| 255 | imx_clk_fixed_factor("sys_pll2_250m", "sys_pll2_out", 1, 4)); |
| 256 | clk_dm(IMX8MN_SYS_PLL2_333M, |
| 257 | imx_clk_fixed_factor("sys_pll2_333m", "sys_pll2_out", 1, 3)); |
| 258 | clk_dm(IMX8MN_SYS_PLL2_500M, |
| 259 | imx_clk_fixed_factor("sys_pll2_500m", "sys_pll2_out", 1, 2)); |
| 260 | clk_dm(IMX8MN_SYS_PLL2_1000M, |
| 261 | imx_clk_fixed_factor("sys_pll2_1000m", "sys_pll2_out", 1, 1)); |
| 262 | |
Michael Trimarchi | 2468583 | 2024-07-07 10:19:58 +0200 | [diff] [blame] | 263 | ret = clk_get_by_name(dev, "osc_24m", &osc_24m_clk); |
| 264 | if (ret) |
| 265 | return ret; |
| 266 | clk_dm(IMX8MN_CLK_24M, dev_get_clk_ptr(osc_24m_clk.dev)); |
| 267 | |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 268 | base = dev_read_addr_ptr(dev); |
Sean Anderson | b58106d | 2019-12-24 23:57:47 -0500 | [diff] [blame] | 269 | if (!base) |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 270 | return -EINVAL; |
| 271 | |
| 272 | clk_dm(IMX8MN_CLK_A53_SRC, |
| 273 | imx_clk_mux2("arm_a53_src", base + 0x8000, 24, 3, |
| 274 | imx8mn_a53_sels, ARRAY_SIZE(imx8mn_a53_sels))); |
| 275 | clk_dm(IMX8MN_CLK_A53_CG, |
| 276 | imx_clk_gate3("arm_a53_cg", "arm_a53_src", base + 0x8000, 28)); |
| 277 | clk_dm(IMX8MN_CLK_A53_DIV, |
| 278 | imx_clk_divider2("arm_a53_div", "arm_a53_cg", |
| 279 | base + 0x8000, 0, 3)); |
| 280 | |
| 281 | clk_dm(IMX8MN_CLK_AHB, |
| 282 | imx8m_clk_composite_critical("ahb", imx8mn_ahb_sels, |
| 283 | base + 0x9000)); |
| 284 | clk_dm(IMX8MN_CLK_IPG_ROOT, |
| 285 | imx_clk_divider2("ipg_root", "ahb", base + 0x9080, 0, 1)); |
| 286 | |
| 287 | clk_dm(IMX8MN_CLK_ENET_AXI, |
| 288 | imx8m_clk_composite("enet_axi", imx8mn_enet_axi_sels, |
| 289 | base + 0x8880)); |
| 290 | clk_dm(IMX8MN_CLK_NAND_USDHC_BUS, |
| 291 | imx8m_clk_composite_critical("nand_usdhc_bus", |
| 292 | imx8mn_nand_usdhc_sels, |
| 293 | base + 0x8900)); |
Ye Li | 0321edb | 2020-04-19 02:22:09 -0700 | [diff] [blame] | 294 | clk_dm(IMX8MN_CLK_USB_BUS, |
| 295 | imx8m_clk_composite("usb_bus", imx8mn_usb_bus_sels, base + 0x8b80)); |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 296 | |
| 297 | /* IP */ |
| 298 | clk_dm(IMX8MN_CLK_USDHC1, |
| 299 | imx8m_clk_composite("usdhc1", imx8mn_usdhc1_sels, |
| 300 | base + 0xac00)); |
| 301 | clk_dm(IMX8MN_CLK_USDHC2, |
| 302 | imx8m_clk_composite("usdhc2", imx8mn_usdhc2_sels, |
| 303 | base + 0xac80)); |
| 304 | clk_dm(IMX8MN_CLK_I2C1, |
| 305 | imx8m_clk_composite("i2c1", imx8mn_i2c1_sels, base + 0xad00)); |
| 306 | clk_dm(IMX8MN_CLK_I2C2, |
| 307 | imx8m_clk_composite("i2c2", imx8mn_i2c2_sels, base + 0xad80)); |
| 308 | clk_dm(IMX8MN_CLK_I2C3, |
| 309 | imx8m_clk_composite("i2c3", imx8mn_i2c3_sels, base + 0xae00)); |
| 310 | clk_dm(IMX8MN_CLK_I2C4, |
| 311 | imx8m_clk_composite("i2c4", imx8mn_i2c4_sels, base + 0xae80)); |
| 312 | clk_dm(IMX8MN_CLK_WDOG, |
| 313 | imx8m_clk_composite("wdog", imx8mn_wdog_sels, base + 0xb900)); |
| 314 | clk_dm(IMX8MN_CLK_USDHC3, |
| 315 | imx8m_clk_composite("usdhc3", imx8mn_usdhc3_sels, |
| 316 | base + 0xbc80)); |
Michael Trimarchi | 252e54e | 2022-08-30 16:45:20 +0200 | [diff] [blame] | 317 | clk_dm(IMX8MN_CLK_NAND, |
| 318 | imx8m_clk_composite("nand", imx8mn_nand_sels, base + 0xab00)); |
Ye Li | 418c1fc | 2020-04-18 08:19:12 -0700 | [diff] [blame] | 319 | clk_dm(IMX8MN_CLK_QSPI, |
| 320 | imx8m_clk_composite("qspi", imx8mn_qspi_sels, base + 0xab80)); |
Ye Li | 0321edb | 2020-04-19 02:22:09 -0700 | [diff] [blame] | 321 | clk_dm(IMX8MN_CLK_USB_CORE_REF, |
| 322 | imx8m_clk_composite("usb_core_ref", imx8mn_usb_core_sels, base + 0xb100)); |
| 323 | clk_dm(IMX8MN_CLK_USB_PHY_REF, |
| 324 | imx8m_clk_composite("usb_phy_ref", imx8mn_usb_phy_sels, base + 0xb180)); |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 325 | |
| 326 | clk_dm(IMX8MN_CLK_I2C1_ROOT, |
| 327 | imx_clk_gate4("i2c1_root_clk", "i2c1", base + 0x4170, 0)); |
| 328 | clk_dm(IMX8MN_CLK_I2C2_ROOT, |
| 329 | imx_clk_gate4("i2c2_root_clk", "i2c2", base + 0x4180, 0)); |
| 330 | clk_dm(IMX8MN_CLK_I2C3_ROOT, |
| 331 | imx_clk_gate4("i2c3_root_clk", "i2c3", base + 0x4190, 0)); |
| 332 | clk_dm(IMX8MN_CLK_I2C4_ROOT, |
| 333 | imx_clk_gate4("i2c4_root_clk", "i2c4", base + 0x41a0, 0)); |
| 334 | clk_dm(IMX8MN_CLK_OCOTP_ROOT, |
| 335 | imx_clk_gate4("ocotp_root_clk", "ipg_root", base + 0x4220, 0)); |
| 336 | clk_dm(IMX8MN_CLK_USDHC1_ROOT, |
| 337 | imx_clk_gate4("usdhc1_root_clk", "usdhc1", base + 0x4510, 0)); |
| 338 | clk_dm(IMX8MN_CLK_USDHC2_ROOT, |
| 339 | imx_clk_gate4("usdhc2_root_clk", "usdhc2", base + 0x4520, 0)); |
| 340 | clk_dm(IMX8MN_CLK_WDOG1_ROOT, |
| 341 | imx_clk_gate4("wdog1_root_clk", "wdog", base + 0x4530, 0)); |
| 342 | clk_dm(IMX8MN_CLK_WDOG2_ROOT, |
| 343 | imx_clk_gate4("wdog2_root_clk", "wdog", base + 0x4540, 0)); |
| 344 | clk_dm(IMX8MN_CLK_WDOG3_ROOT, |
| 345 | imx_clk_gate4("wdog3_root_clk", "wdog", base + 0x4550, 0)); |
| 346 | clk_dm(IMX8MN_CLK_USDHC3_ROOT, |
| 347 | imx_clk_gate4("usdhc3_root_clk", "usdhc3", base + 0x45e0, 0)); |
Ye Li | 418c1fc | 2020-04-18 08:19:12 -0700 | [diff] [blame] | 348 | clk_dm(IMX8MN_CLK_QSPI_ROOT, |
| 349 | imx_clk_gate4("qspi_root_clk", "qspi", base + 0x42f0, 0)); |
Michael Trimarchi | 252e54e | 2022-08-30 16:45:20 +0200 | [diff] [blame] | 350 | clk_dm(IMX8MN_CLK_NAND_ROOT, |
| 351 | imx_clk_gate2_shared2("nand_root_clk", "nand", base + 0x4300, 0, &share_count_nand)); |
| 352 | clk_dm(IMX8MN_CLK_NAND_USDHC_BUS_RAWNAND_CLK, |
| 353 | imx_clk_gate2_shared2("nand_usdhc_rawnand_clk", |
| 354 | "nand_usdhc_bus", base + 0x4300, 0, |
| 355 | &share_count_nand)); |
Ye Li | 0321edb | 2020-04-19 02:22:09 -0700 | [diff] [blame] | 356 | clk_dm(IMX8MN_CLK_USB1_CTRL_ROOT, |
| 357 | imx_clk_gate4("usb1_ctrl_root_clk", "usb_bus", base + 0x44d0, 0)); |
Ye Li | 418c1fc | 2020-04-18 08:19:12 -0700 | [diff] [blame] | 358 | |
| 359 | /* clks not needed in SPL stage */ |
| 360 | #ifndef CONFIG_SPL_BUILD |
| 361 | clk_dm(IMX8MN_CLK_ENET_REF, |
| 362 | imx8m_clk_composite("enet_ref", imx8mn_enet_ref_sels, |
| 363 | base + 0xa980)); |
| 364 | clk_dm(IMX8MN_CLK_ENET_TIMER, |
| 365 | imx8m_clk_composite("enet_timer", imx8mn_enet_timer_sels, |
| 366 | base + 0xaa00)); |
| 367 | clk_dm(IMX8MN_CLK_ENET_PHY_REF, |
| 368 | imx8m_clk_composite("enet_phy", imx8mn_enet_phy_sels, |
| 369 | base + 0xaa80)); |
| 370 | clk_dm(IMX8MN_CLK_ENET1_ROOT, |
| 371 | imx_clk_gate4("enet1_root_clk", "enet_axi", |
| 372 | base + 0x40a0, 0)); |
Nicolas Heemeryck | e5e8523 | 2023-12-11 11:06:13 +0100 | [diff] [blame] | 373 | clk_dm(IMX8MN_CLK_PWM1, |
| 374 | imx8m_clk_composite("pwm1", imx8mn_pwm1_sels, base + 0xb380)); |
| 375 | clk_dm(IMX8MN_CLK_PWM2, |
| 376 | imx8m_clk_composite("pwm2", imx8mn_pwm2_sels, base + 0xb400)); |
| 377 | clk_dm(IMX8MN_CLK_PWM3, |
| 378 | imx8m_clk_composite("pwm3", imx8mn_pwm3_sels, base + 0xb480)); |
| 379 | clk_dm(IMX8MN_CLK_PWM4, |
| 380 | imx8m_clk_composite("pwm4", imx8mn_pwm4_sels, base + 0xb500)); |
| 381 | clk_dm(IMX8MN_CLK_PWM1_ROOT, |
| 382 | imx_clk_gate4("pwm1_root_clk", "pwm1", base + 0x4280, 0)); |
| 383 | clk_dm(IMX8MN_CLK_PWM2_ROOT, |
| 384 | imx_clk_gate4("pwm2_root_clk", "pwm2", base + 0x4290, 0)); |
| 385 | clk_dm(IMX8MN_CLK_PWM3_ROOT, |
| 386 | imx_clk_gate4("pwm3_root_clk", "pwm3", base + 0x42a0, 0)); |
| 387 | clk_dm(IMX8MN_CLK_PWM4_ROOT, |
| 388 | imx_clk_gate4("pwm4_root_clk", "pwm4", base + 0x42b0, 0)); |
Ye Li | 418c1fc | 2020-04-18 08:19:12 -0700 | [diff] [blame] | 389 | #endif |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 390 | |
Marek Vasut | b1a8bb0 | 2021-01-19 00:58:31 +0100 | [diff] [blame] | 391 | #if CONFIG_IS_ENABLED(DM_SPI) |
| 392 | clk_dm(IMX8MN_CLK_ECSPI1, |
| 393 | imx8m_clk_composite("ecspi1", imx8mn_ecspi1_sels, base + 0xb280)); |
| 394 | clk_dm(IMX8MN_CLK_ECSPI2, |
| 395 | imx8m_clk_composite("ecspi2", imx8mn_ecspi2_sels, base + 0xb300)); |
| 396 | clk_dm(IMX8MN_CLK_ECSPI3, |
| 397 | imx8m_clk_composite("ecspi3", imx8mn_ecspi3_sels, base + 0xc180)); |
| 398 | clk_dm(IMX8MN_CLK_ECSPI1_ROOT, |
| 399 | imx_clk_gate4("ecspi1_root_clk", "ecspi1", base + 0x4070, 0)); |
| 400 | clk_dm(IMX8MN_CLK_ECSPI2_ROOT, |
| 401 | imx_clk_gate4("ecspi2_root_clk", "ecspi2", base + 0x4080, 0)); |
| 402 | clk_dm(IMX8MN_CLK_ECSPI3_ROOT, |
| 403 | imx_clk_gate4("ecspi3_root_clk", "ecspi3", base + 0x4090, 0)); |
| 404 | #endif |
| 405 | |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static const struct udevice_id imx8mn_clk_ids[] = { |
| 410 | { .compatible = "fsl,imx8mn-ccm" }, |
| 411 | { }, |
| 412 | }; |
| 413 | |
| 414 | U_BOOT_DRIVER(imx8mn_clk) = { |
| 415 | .name = "clk_imx8mn", |
| 416 | .id = UCLASS_CLK, |
| 417 | .of_match = imx8mn_clk_ids, |
Sean Anderson | 35c8464 | 2022-03-20 16:34:46 -0400 | [diff] [blame] | 418 | .ops = &ccf_clk_ops, |
Peng Fan | e2f674d | 2019-09-16 03:09:47 +0000 | [diff] [blame] | 419 | .probe = imx8mn_clk_probe, |
| 420 | .flags = DM_FLAG_PRE_RELOC, |
| 421 | }; |