1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2019 DENX Software Engineering
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
8 #include <clk-uclass.h>
10 #include <asm/arch/clock.h>
11 #include <asm/arch/imx-regs.h>
12 #include <dt-bindings/clock/imx6qdl-clock.h>
16 static int imx6q_check_id(ulong id)
18 if (id < IMX6QDL_CLK_DUMMY || id >= IMX6QDL_CLK_END) {
19 printf("%s: Invalid clk ID #%lu\n", __func__, id);
26 static ulong imx6q_clk_get_rate(struct clk *clk)
31 debug("%s(#%lu)\n", __func__, clk->id);
33 ret = imx6q_check_id(clk->id);
37 ret = clk_get_by_id(clk->id, &c);
41 return clk_get_rate(c);
44 static ulong imx6q_clk_set_rate(struct clk *clk, unsigned long rate)
46 debug("%s(#%lu), rate: %lu\n", __func__, clk->id, rate);
51 static int __imx6q_clk_enable(struct clk *clk, bool enable)
56 debug("%s(#%lu) en: %d\n", __func__, clk->id, enable);
58 ret = imx6q_check_id(clk->id);
62 ret = clk_get_by_id(clk->id, &c);
74 static int imx6q_clk_disable(struct clk *clk)
76 return __imx6q_clk_enable(clk, 0);
79 static int imx6q_clk_enable(struct clk *clk)
81 return __imx6q_clk_enable(clk, 1);
84 static struct clk_ops imx6q_clk_ops = {
85 .set_rate = imx6q_clk_set_rate,
86 .get_rate = imx6q_clk_get_rate,
87 .enable = imx6q_clk_enable,
88 .disable = imx6q_clk_disable,
91 static const char *const usdhc_sels[] = { "pll2_pfd2_396m", "pll2_pfd0_352m", };
93 static int imx6q_clk_probe(struct udevice *dev)
98 base = (void *)ANATOP_BASE_ADDR;
100 clk_dm(IMX6QDL_CLK_PLL2,
101 imx_clk_pllv3(IMX_PLLV3_GENERIC, "pll2_bus", "osc",
103 clk_dm(IMX6QDL_CLK_PLL3_USB_OTG,
104 imx_clk_pllv3(IMX_PLLV3_USB, "pll3_usb_otg", "osc",
106 clk_dm(IMX6QDL_CLK_PLL3_60M,
107 imx_clk_fixed_factor("pll3_60m", "pll3_usb_otg", 1, 8));
108 clk_dm(IMX6QDL_CLK_PLL2_PFD0_352M,
109 imx_clk_pfd("pll2_pfd0_352m", "pll2_bus", base + 0x100, 0));
110 clk_dm(IMX6QDL_CLK_PLL2_PFD2_396M,
111 imx_clk_pfd("pll2_pfd2_396m", "pll2_bus", base + 0x100, 2));
114 base = dev_read_addr_ptr(dev);
115 if (base == (void *)FDT_ADDR_T_NONE)
118 clk_dm(IMX6QDL_CLK_USDHC1_SEL,
119 imx_clk_mux("usdhc1_sel", base + 0x1c, 16, 1,
120 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
121 clk_dm(IMX6QDL_CLK_USDHC2_SEL,
122 imx_clk_mux("usdhc2_sel", base + 0x1c, 17, 1,
123 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
124 clk_dm(IMX6QDL_CLK_USDHC3_SEL,
125 imx_clk_mux("usdhc3_sel", base + 0x1c, 18, 1,
126 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
127 clk_dm(IMX6QDL_CLK_USDHC4_SEL,
128 imx_clk_mux("usdhc4_sel", base + 0x1c, 19, 1,
129 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
131 clk_dm(IMX6QDL_CLK_USDHC1_PODF,
132 imx_clk_divider("usdhc1_podf", "usdhc1_sel",
133 base + 0x24, 11, 3));
134 clk_dm(IMX6QDL_CLK_USDHC2_PODF,
135 imx_clk_divider("usdhc2_podf", "usdhc2_sel",
136 base + 0x24, 16, 3));
137 clk_dm(IMX6QDL_CLK_USDHC3_PODF,
138 imx_clk_divider("usdhc3_podf", "usdhc3_sel",
139 base + 0x24, 19, 3));
140 clk_dm(IMX6QDL_CLK_USDHC4_PODF,
141 imx_clk_divider("usdhc4_podf", "usdhc4_sel",
142 base + 0x24, 22, 3));
144 clk_dm(IMX6QDL_CLK_ECSPI_ROOT,
145 imx_clk_divider("ecspi_root", "pll3_60m", base + 0x38, 19, 6));
147 clk_dm(IMX6QDL_CLK_ECSPI1,
148 imx_clk_gate2("ecspi1", "ecspi_root", base + 0x6c, 0));
149 clk_dm(IMX6QDL_CLK_ECSPI2,
150 imx_clk_gate2("ecspi2", "ecspi_root", base + 0x6c, 2));
151 clk_dm(IMX6QDL_CLK_ECSPI3,
152 imx_clk_gate2("ecspi3", "ecspi_root", base + 0x6c, 4));
153 clk_dm(IMX6QDL_CLK_ECSPI4,
154 imx_clk_gate2("ecspi4", "ecspi_root", base + 0x6c, 6));
155 clk_dm(IMX6QDL_CLK_USDHC1,
156 imx_clk_gate2("usdhc1", "usdhc1_podf", base + 0x80, 2));
157 clk_dm(IMX6QDL_CLK_USDHC2,
158 imx_clk_gate2("usdhc2", "usdhc2_podf", base + 0x80, 4));
159 clk_dm(IMX6QDL_CLK_USDHC3,
160 imx_clk_gate2("usdhc3", "usdhc3_podf", base + 0x80, 6));
161 clk_dm(IMX6QDL_CLK_USDHC4,
162 imx_clk_gate2("usdhc4", "usdhc4_podf", base + 0x80, 8));
167 static const struct udevice_id imx6q_clk_ids[] = {
168 { .compatible = "fsl,imx6q-ccm" },
172 U_BOOT_DRIVER(imx6q_clk) = {
175 .of_match = imx6q_clk_ids,
176 .ops = &imx6q_clk_ops,
177 .probe = imx6q_clk_probe,
178 .flags = DM_FLAG_PRE_RELOC,