blob: ba75fd1aad68a64b8325de0eb1af96b88af24991 [file] [log] [blame]
Lukasz Majewski4de44bb2019-06-24 15:50:45 +02001// 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 Majewski4de44bb2019-06-24 15:50:45 +02007#include <clk-uclass.h>
8#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020010#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 Anderson35c84642022-03-20 16:34:46 -040016static int imx6q_clk_request(struct clk *clk)
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020017{
Sean Anderson35c84642022-03-20 16:34:46 -040018 if (clk->id < IMX6QDL_CLK_DUMMY || clk->id >= IMX6QDL_CLK_END) {
19 printf("%s: Invalid clk ID #%lu\n", __func__, clk->id);
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020020 return -EINVAL;
21 }
22
23 return 0;
24}
25
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020026static struct clk_ops imx6q_clk_ops = {
Sean Anderson35c84642022-03-20 16:34:46 -040027 .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 Majewski4de44bb2019-06-24 15:50:45 +020032};
33
34static const char *const usdhc_sels[] = { "pll2_pfd2_396m", "pll2_pfd0_352m", };
Lukasz Majewski2f665412019-10-15 12:44:57 +020035static const char *const periph_sels[] = { "periph_pre", "periph_clk2", };
36static const char *const periph_pre_sels[] = { "pll2_bus", "pll2_pfd2_396m",
37 "pll2_pfd0_352m", "pll2_198m", };
Adam Ford5a7c1c12025-03-18 18:38:29 -050038static const char *const ecspi_sels[] = { "pll3_60m", "osc", };
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020039
40static int imx6q_clk_probe(struct udevice *dev)
41{
42 void *base;
43
44 /* Anatop clocks */
45 base = (void *)ANATOP_BASE_ADDR;
46
47 clk_dm(IMX6QDL_CLK_PLL2,
48 imx_clk_pllv3(IMX_PLLV3_GENERIC, "pll2_bus", "osc",
49 base + 0x30, 0x1));
50 clk_dm(IMX6QDL_CLK_PLL3_USB_OTG,
51 imx_clk_pllv3(IMX_PLLV3_USB, "pll3_usb_otg", "osc",
52 base + 0x10, 0x3));
53 clk_dm(IMX6QDL_CLK_PLL3_60M,
54 imx_clk_fixed_factor("pll3_60m", "pll3_usb_otg", 1, 8));
55 clk_dm(IMX6QDL_CLK_PLL2_PFD0_352M,
56 imx_clk_pfd("pll2_pfd0_352m", "pll2_bus", base + 0x100, 0));
57 clk_dm(IMX6QDL_CLK_PLL2_PFD2_396M,
58 imx_clk_pfd("pll2_pfd2_396m", "pll2_bus", base + 0x100, 2));
Lukasz Majewski8252da02020-02-24 14:55:26 +010059 clk_dm(IMX6QDL_CLK_PLL6,
60 imx_clk_pllv3(IMX_PLLV3_ENET, "pll6", "osc", base + 0xe0, 0x3));
61 clk_dm(IMX6QDL_CLK_PLL6_ENET,
62 imx_clk_gate("pll6_enet", "pll6", base + 0xe0, 13));
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020063
64 /* CCM clocks */
65 base = dev_read_addr_ptr(dev);
Sean Andersonb58106d2019-12-24 23:57:47 -050066 if (!base)
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020067 return -EINVAL;
68
69 clk_dm(IMX6QDL_CLK_USDHC1_SEL,
70 imx_clk_mux("usdhc1_sel", base + 0x1c, 16, 1,
71 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
72 clk_dm(IMX6QDL_CLK_USDHC2_SEL,
73 imx_clk_mux("usdhc2_sel", base + 0x1c, 17, 1,
74 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
75 clk_dm(IMX6QDL_CLK_USDHC3_SEL,
76 imx_clk_mux("usdhc3_sel", base + 0x1c, 18, 1,
77 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
78 clk_dm(IMX6QDL_CLK_USDHC4_SEL,
79 imx_clk_mux("usdhc4_sel", base + 0x1c, 19, 1,
80 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
81
Adam Ford5a7c1c12025-03-18 18:38:29 -050082 if (of_machine_is_compatible("fsl,imx6qp"))
83 clk_dm(IMX6QDL_CLK_ECSPI_SEL,
84 imx_clk_mux("ecspi_sel", base + 0x38, 18, 1, ecspi_sels,
85 ARRAY_SIZE(ecspi_sels)));
86
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020087 clk_dm(IMX6QDL_CLK_USDHC1_PODF,
88 imx_clk_divider("usdhc1_podf", "usdhc1_sel",
89 base + 0x24, 11, 3));
90 clk_dm(IMX6QDL_CLK_USDHC2_PODF,
91 imx_clk_divider("usdhc2_podf", "usdhc2_sel",
92 base + 0x24, 16, 3));
93 clk_dm(IMX6QDL_CLK_USDHC3_PODF,
94 imx_clk_divider("usdhc3_podf", "usdhc3_sel",
95 base + 0x24, 19, 3));
96 clk_dm(IMX6QDL_CLK_USDHC4_PODF,
97 imx_clk_divider("usdhc4_podf", "usdhc4_sel",
98 base + 0x24, 22, 3));
99
Adam Ford5a7c1c12025-03-18 18:38:29 -0500100 if (of_machine_is_compatible("fsl,imx6qp"))
101 clk_dm(IMX6QDL_CLK_ECSPI_ROOT,
102 imx_clk_divider("ecspi_root", "ecspi_sel", base + 0x38, 19, 6));
103 else
104 clk_dm(IMX6QDL_CLK_ECSPI_ROOT,
105 imx_clk_divider("ecspi_root", "pll3_60m", base + 0x38, 19, 6));
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200106
107 clk_dm(IMX6QDL_CLK_ECSPI1,
108 imx_clk_gate2("ecspi1", "ecspi_root", base + 0x6c, 0));
109 clk_dm(IMX6QDL_CLK_ECSPI2,
110 imx_clk_gate2("ecspi2", "ecspi_root", base + 0x6c, 2));
111 clk_dm(IMX6QDL_CLK_ECSPI3,
112 imx_clk_gate2("ecspi3", "ecspi_root", base + 0x6c, 4));
113 clk_dm(IMX6QDL_CLK_ECSPI4,
114 imx_clk_gate2("ecspi4", "ecspi_root", base + 0x6c, 6));
115 clk_dm(IMX6QDL_CLK_USDHC1,
116 imx_clk_gate2("usdhc1", "usdhc1_podf", base + 0x80, 2));
117 clk_dm(IMX6QDL_CLK_USDHC2,
118 imx_clk_gate2("usdhc2", "usdhc2_podf", base + 0x80, 4));
119 clk_dm(IMX6QDL_CLK_USDHC3,
120 imx_clk_gate2("usdhc3", "usdhc3_podf", base + 0x80, 6));
121 clk_dm(IMX6QDL_CLK_USDHC4,
122 imx_clk_gate2("usdhc4", "usdhc4_podf", base + 0x80, 8));
123
Lukasz Majewski2f665412019-10-15 12:44:57 +0200124 clk_dm(IMX6QDL_CLK_PERIPH_PRE,
125 imx_clk_mux("periph_pre", base + 0x18, 18, 2, periph_pre_sels,
126 ARRAY_SIZE(periph_pre_sels)));
127 clk_dm(IMX6QDL_CLK_PERIPH,
128 imx_clk_busy_mux("periph", base + 0x14, 25, 1, base + 0x48,
129 5, periph_sels, ARRAY_SIZE(periph_sels)));
130 clk_dm(IMX6QDL_CLK_AHB,
131 imx_clk_busy_divider("ahb", "periph", base + 0x14, 10, 3,
132 base + 0x48, 1));
133 clk_dm(IMX6QDL_CLK_IPG,
134 imx_clk_divider("ipg", "ahb", base + 0x14, 8, 2));
135 clk_dm(IMX6QDL_CLK_IPG_PER,
136 imx_clk_divider("ipg_per", "ipg", base + 0x1c, 0, 6));
137 clk_dm(IMX6QDL_CLK_I2C1,
138 imx_clk_gate2("i2c1", "ipg_per", base + 0x70, 6));
139 clk_dm(IMX6QDL_CLK_I2C2,
140 imx_clk_gate2("i2c2", "ipg_per", base + 0x70, 8));
Emil Kronborg55f528f2024-07-12 14:19:10 +0000141 clk_dm(IMX6QDL_CLK_I2C3,
142 imx_clk_gate2("i2c3", "ipg_per", base + 0x70, 10));
Emil Kronborg907d1c42024-07-22 13:14:58 -0300143 clk_dm(IMX6QDL_CLK_PWM1,
144 imx_clk_gate2("pwm1", "ipg_per", base + 0x78, 16));
Lukasz Majewski2f665412019-10-15 12:44:57 +0200145
Lukasz Majewskicffad9c2020-02-24 14:55:24 +0100146 clk_dm(IMX6QDL_CLK_ENET, imx_clk_gate2("enet", "ipg", base + 0x6c, 10));
Lukasz Majewski8252da02020-02-24 14:55:26 +0100147 clk_dm(IMX6QDL_CLK_ENET_REF,
148 imx_clk_fixed_factor("enet_ref", "pll6_enet", 1, 1));
149
Lukasz Majewski4de44bb2019-06-24 15:50:45 +0200150 return 0;
151}
152
153static const struct udevice_id imx6q_clk_ids[] = {
154 { .compatible = "fsl,imx6q-ccm" },
155 { },
156};
157
158U_BOOT_DRIVER(imx6q_clk) = {
159 .name = "clk_imx6q",
160 .id = UCLASS_CLK,
161 .of_match = imx6q_clk_ids,
162 .ops = &imx6q_clk_ops,
163 .probe = imx6q_clk_probe,
164 .flags = DM_FLAG_PRE_RELOC,
165};