Lukasz Majewski | 4de44bb | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2019 DENX Software Engineering |
| 4 | * Lukasz Majewski, DENX Software Engineering, lukma@denx.de |
| 5 | */ |
| 6 | |
Lukasz Majewski | 4de44bb | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 7 | #include <clk-uclass.h> |
| 8 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Lukasz Majewski | 4de44bb | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 10 | #include <asm/arch/clock.h> |
| 11 | #include <asm/arch/imx-regs.h> |
| 12 | #include <dt-bindings/clock/imx6qdl-clock.h> |
| 13 | |
| 14 | #include "clk.h" |
| 15 | |
Sean Anderson | 35c8464 | 2022-03-20 16:34:46 -0400 | [diff] [blame] | 16 | static int imx6q_clk_request(struct clk *clk) |
Lukasz Majewski | 4de44bb | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 17 | { |
Sean Anderson | 35c8464 | 2022-03-20 16:34:46 -0400 | [diff] [blame] | 18 | if (clk->id < IMX6QDL_CLK_DUMMY || clk->id >= IMX6QDL_CLK_END) { |
| 19 | printf("%s: Invalid clk ID #%lu\n", __func__, clk->id); |
Lukasz Majewski | 4de44bb | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 20 | return -EINVAL; |
| 21 | } |
| 22 | |
| 23 | return 0; |
| 24 | } |
| 25 | |
Lukasz Majewski | 4de44bb | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 26 | static struct clk_ops imx6q_clk_ops = { |
Sean Anderson | 35c8464 | 2022-03-20 16:34:46 -0400 | [diff] [blame] | 27 | .request = imx6q_clk_request, |
| 28 | .set_rate = ccf_clk_set_rate, |
| 29 | .get_rate = ccf_clk_get_rate, |
| 30 | .enable = ccf_clk_enable, |
| 31 | .disable = ccf_clk_disable, |
Lukasz Majewski | 4de44bb | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | static const char *const usdhc_sels[] = { "pll2_pfd2_396m", "pll2_pfd0_352m", }; |
Lukasz Majewski | 2f66541 | 2019-10-15 12:44:57 +0200 | [diff] [blame] | 35 | static const char *const periph_sels[] = { "periph_pre", "periph_clk2", }; |
| 36 | static const char *const periph_pre_sels[] = { "pll2_bus", "pll2_pfd2_396m", |
| 37 | "pll2_pfd0_352m", "pll2_198m", }; |
Lukasz Majewski | 4de44bb | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 38 | |
| 39 | static int imx6q_clk_probe(struct udevice *dev) |
| 40 | { |
| 41 | void *base; |
| 42 | |
| 43 | /* Anatop clocks */ |
| 44 | base = (void *)ANATOP_BASE_ADDR; |
| 45 | |
| 46 | clk_dm(IMX6QDL_CLK_PLL2, |
| 47 | imx_clk_pllv3(IMX_PLLV3_GENERIC, "pll2_bus", "osc", |
| 48 | base + 0x30, 0x1)); |
| 49 | clk_dm(IMX6QDL_CLK_PLL3_USB_OTG, |
| 50 | imx_clk_pllv3(IMX_PLLV3_USB, "pll3_usb_otg", "osc", |
| 51 | base + 0x10, 0x3)); |
| 52 | clk_dm(IMX6QDL_CLK_PLL3_60M, |
| 53 | imx_clk_fixed_factor("pll3_60m", "pll3_usb_otg", 1, 8)); |
| 54 | clk_dm(IMX6QDL_CLK_PLL2_PFD0_352M, |
| 55 | imx_clk_pfd("pll2_pfd0_352m", "pll2_bus", base + 0x100, 0)); |
| 56 | clk_dm(IMX6QDL_CLK_PLL2_PFD2_396M, |
| 57 | imx_clk_pfd("pll2_pfd2_396m", "pll2_bus", base + 0x100, 2)); |
Lukasz Majewski | 8252da0 | 2020-02-24 14:55:26 +0100 | [diff] [blame] | 58 | clk_dm(IMX6QDL_CLK_PLL6, |
| 59 | imx_clk_pllv3(IMX_PLLV3_ENET, "pll6", "osc", base + 0xe0, 0x3)); |
| 60 | clk_dm(IMX6QDL_CLK_PLL6_ENET, |
| 61 | imx_clk_gate("pll6_enet", "pll6", base + 0xe0, 13)); |
Lukasz Majewski | 4de44bb | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 62 | |
| 63 | /* CCM clocks */ |
| 64 | base = dev_read_addr_ptr(dev); |
Sean Anderson | b58106d | 2019-12-24 23:57:47 -0500 | [diff] [blame] | 65 | if (!base) |
Lukasz Majewski | 4de44bb | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 66 | return -EINVAL; |
| 67 | |
| 68 | clk_dm(IMX6QDL_CLK_USDHC1_SEL, |
| 69 | imx_clk_mux("usdhc1_sel", base + 0x1c, 16, 1, |
| 70 | usdhc_sels, ARRAY_SIZE(usdhc_sels))); |
| 71 | clk_dm(IMX6QDL_CLK_USDHC2_SEL, |
| 72 | imx_clk_mux("usdhc2_sel", base + 0x1c, 17, 1, |
| 73 | usdhc_sels, ARRAY_SIZE(usdhc_sels))); |
| 74 | clk_dm(IMX6QDL_CLK_USDHC3_SEL, |
| 75 | imx_clk_mux("usdhc3_sel", base + 0x1c, 18, 1, |
| 76 | usdhc_sels, ARRAY_SIZE(usdhc_sels))); |
| 77 | clk_dm(IMX6QDL_CLK_USDHC4_SEL, |
| 78 | imx_clk_mux("usdhc4_sel", base + 0x1c, 19, 1, |
| 79 | usdhc_sels, ARRAY_SIZE(usdhc_sels))); |
| 80 | |
| 81 | clk_dm(IMX6QDL_CLK_USDHC1_PODF, |
| 82 | imx_clk_divider("usdhc1_podf", "usdhc1_sel", |
| 83 | base + 0x24, 11, 3)); |
| 84 | clk_dm(IMX6QDL_CLK_USDHC2_PODF, |
| 85 | imx_clk_divider("usdhc2_podf", "usdhc2_sel", |
| 86 | base + 0x24, 16, 3)); |
| 87 | clk_dm(IMX6QDL_CLK_USDHC3_PODF, |
| 88 | imx_clk_divider("usdhc3_podf", "usdhc3_sel", |
| 89 | base + 0x24, 19, 3)); |
| 90 | clk_dm(IMX6QDL_CLK_USDHC4_PODF, |
| 91 | imx_clk_divider("usdhc4_podf", "usdhc4_sel", |
| 92 | base + 0x24, 22, 3)); |
| 93 | |
| 94 | clk_dm(IMX6QDL_CLK_ECSPI_ROOT, |
| 95 | imx_clk_divider("ecspi_root", "pll3_60m", base + 0x38, 19, 6)); |
| 96 | |
| 97 | clk_dm(IMX6QDL_CLK_ECSPI1, |
| 98 | imx_clk_gate2("ecspi1", "ecspi_root", base + 0x6c, 0)); |
| 99 | clk_dm(IMX6QDL_CLK_ECSPI2, |
| 100 | imx_clk_gate2("ecspi2", "ecspi_root", base + 0x6c, 2)); |
| 101 | clk_dm(IMX6QDL_CLK_ECSPI3, |
| 102 | imx_clk_gate2("ecspi3", "ecspi_root", base + 0x6c, 4)); |
| 103 | clk_dm(IMX6QDL_CLK_ECSPI4, |
| 104 | imx_clk_gate2("ecspi4", "ecspi_root", base + 0x6c, 6)); |
| 105 | clk_dm(IMX6QDL_CLK_USDHC1, |
| 106 | imx_clk_gate2("usdhc1", "usdhc1_podf", base + 0x80, 2)); |
| 107 | clk_dm(IMX6QDL_CLK_USDHC2, |
| 108 | imx_clk_gate2("usdhc2", "usdhc2_podf", base + 0x80, 4)); |
| 109 | clk_dm(IMX6QDL_CLK_USDHC3, |
| 110 | imx_clk_gate2("usdhc3", "usdhc3_podf", base + 0x80, 6)); |
| 111 | clk_dm(IMX6QDL_CLK_USDHC4, |
| 112 | imx_clk_gate2("usdhc4", "usdhc4_podf", base + 0x80, 8)); |
| 113 | |
Lukasz Majewski | 2f66541 | 2019-10-15 12:44:57 +0200 | [diff] [blame] | 114 | clk_dm(IMX6QDL_CLK_PERIPH_PRE, |
| 115 | imx_clk_mux("periph_pre", base + 0x18, 18, 2, periph_pre_sels, |
| 116 | ARRAY_SIZE(periph_pre_sels))); |
| 117 | clk_dm(IMX6QDL_CLK_PERIPH, |
| 118 | imx_clk_busy_mux("periph", base + 0x14, 25, 1, base + 0x48, |
| 119 | 5, periph_sels, ARRAY_SIZE(periph_sels))); |
| 120 | clk_dm(IMX6QDL_CLK_AHB, |
| 121 | imx_clk_busy_divider("ahb", "periph", base + 0x14, 10, 3, |
| 122 | base + 0x48, 1)); |
| 123 | clk_dm(IMX6QDL_CLK_IPG, |
| 124 | imx_clk_divider("ipg", "ahb", base + 0x14, 8, 2)); |
| 125 | clk_dm(IMX6QDL_CLK_IPG_PER, |
| 126 | imx_clk_divider("ipg_per", "ipg", base + 0x1c, 0, 6)); |
| 127 | clk_dm(IMX6QDL_CLK_I2C1, |
| 128 | imx_clk_gate2("i2c1", "ipg_per", base + 0x70, 6)); |
| 129 | clk_dm(IMX6QDL_CLK_I2C2, |
| 130 | imx_clk_gate2("i2c2", "ipg_per", base + 0x70, 8)); |
Emil Kronborg | 55f528f | 2024-07-12 14:19:10 +0000 | [diff] [blame] | 131 | clk_dm(IMX6QDL_CLK_I2C3, |
| 132 | imx_clk_gate2("i2c3", "ipg_per", base + 0x70, 10)); |
Emil Kronborg | 907d1c4 | 2024-07-22 13:14:58 -0300 | [diff] [blame] | 133 | clk_dm(IMX6QDL_CLK_PWM1, |
| 134 | imx_clk_gate2("pwm1", "ipg_per", base + 0x78, 16)); |
Lukasz Majewski | 2f66541 | 2019-10-15 12:44:57 +0200 | [diff] [blame] | 135 | |
Lukasz Majewski | cffad9c | 2020-02-24 14:55:24 +0100 | [diff] [blame] | 136 | clk_dm(IMX6QDL_CLK_ENET, imx_clk_gate2("enet", "ipg", base + 0x6c, 10)); |
Lukasz Majewski | 8252da0 | 2020-02-24 14:55:26 +0100 | [diff] [blame] | 137 | clk_dm(IMX6QDL_CLK_ENET_REF, |
| 138 | imx_clk_fixed_factor("enet_ref", "pll6_enet", 1, 1)); |
| 139 | |
Lukasz Majewski | 4de44bb | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | static const struct udevice_id imx6q_clk_ids[] = { |
| 144 | { .compatible = "fsl,imx6q-ccm" }, |
| 145 | { }, |
| 146 | }; |
| 147 | |
| 148 | U_BOOT_DRIVER(imx6q_clk) = { |
| 149 | .name = "clk_imx6q", |
| 150 | .id = UCLASS_CLK, |
| 151 | .of_match = imx6q_clk_ids, |
| 152 | .ops = &imx6q_clk_ops, |
| 153 | .probe = imx6q_clk_probe, |
| 154 | .flags = DM_FLAG_PRE_RELOC, |
| 155 | }; |