blob: c80b02975aad0f8a83f794c4b17a149b6552c7be [file] [log] [blame]
Giulio Benetti0b463372020-02-18 20:02:51 +01001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright(C) 2020
4 * Author(s): Giulio Benetti <giulio.benetti@benettiengineering.com>
5 */
6
Giulio Benetti0b463372020-02-18 20:02:51 +01007#include <clk.h>
8#include <clk-uclass.h>
9#include <dm.h>
10#include <asm/arch/clock.h>
11#include <asm/arch/imx-regs.h>
12#include <dt-bindings/clock/imxrt1020-clock.h>
13
14#include "clk.h"
15
Giulio Benetti0b463372020-02-18 20:02:51 +010016static struct clk_ops imxrt1020_clk_ops = {
Sean Anderson35c84642022-03-20 16:34:46 -040017 .set_rate = ccf_clk_set_rate,
18 .get_rate = ccf_clk_get_rate,
19 .enable = ccf_clk_enable,
20 .disable = ccf_clk_disable,
Giulio Benetti0b463372020-02-18 20:02:51 +010021};
22
23static const char * const pll2_bypass_sels[] = {"pll2_sys", "osc", };
24static const char * const pll3_bypass_sels[] = {"pll3_usb_otg", "osc", };
25
26static const char *const pre_periph_sels[] = { "pll2_sys", "pll2_pfd3_297m", "pll3_pfd3_454_74m", "arm_podf", };
27static const char *const periph_sels[] = { "pre_periph_sel", "todo", };
28static const char *const usdhc_sels[] = { "pll2_pfd2_396m", "pll2_pfd0_352m", };
29static const char *const lpuart_sels[] = { "pll3_80m", "osc", };
30static const char *const semc_alt_sels[] = { "pll2_pfd2_396m", "pll3_pfd1_664_62m", };
31static const char *const semc_sels[] = { "periph_sel", "semc_alt_sel", };
32
33static int imxrt1020_clk_probe(struct udevice *dev)
34{
35 void *base;
36
37 /* Anatop clocks */
Jesse Taube214f4432022-03-17 14:33:18 -040038 base = (void *)ofnode_get_addr(ofnode_by_compatible(ofnode_null(), "fsl,imxrt-anatop"));
Giulio Benetti0b463372020-02-18 20:02:51 +010039
40 clk_dm(IMXRT1020_CLK_PLL2_SYS,
41 imx_clk_pllv3(IMX_PLLV3_GENERIC, "pll2_sys", "osc",
42 base + 0x30, 0x1));
43 clk_dm(IMXRT1020_CLK_PLL3_USB_OTG,
44 imx_clk_pllv3(IMX_PLLV3_USB, "pll3_usb_otg", "osc",
45 base + 0x10, 0x1));
46
47 /* PLL bypass out */
48 clk_dm(IMXRT1020_CLK_PLL2_BYPASS,
49 imx_clk_mux_flags("pll2_bypass", base + 0x30, 16, 1,
50 pll2_bypass_sels,
51 ARRAY_SIZE(pll2_bypass_sels),
52 CLK_SET_RATE_PARENT));
53 clk_dm(IMXRT1020_CLK_PLL3_BYPASS,
54 imx_clk_mux_flags("pll3_bypass", base + 0x10, 16, 1,
55 pll3_bypass_sels,
56 ARRAY_SIZE(pll3_bypass_sels),
57 CLK_SET_RATE_PARENT));
58
59 clk_dm(IMXRT1020_CLK_PLL3_80M,
60 imx_clk_fixed_factor("pll3_80m", "pll3_usb_otg", 1, 6));
61
62 clk_dm(IMXRT1020_CLK_PLL2_PFD0_352M,
63 imx_clk_pfd("pll2_pfd0_352m", "pll2_sys", base + 0x100, 0));
64 clk_dm(IMXRT1020_CLK_PLL2_PFD1_594M,
65 imx_clk_pfd("pll2_pfd1_594m", "pll2_sys", base + 0x100, 1));
66 clk_dm(IMXRT1020_CLK_PLL2_PFD2_396M,
67 imx_clk_pfd("pll2_pfd2_396m", "pll2_sys", base + 0x100, 2));
68 clk_dm(IMXRT1020_CLK_PLL2_PFD3_297M,
69 imx_clk_pfd("pll2_pfd3_297m", "pll2_sys", base + 0x100, 3));
70 clk_dm(IMXRT1020_CLK_PLL3_PFD1_664_62M,
71 imx_clk_pfd("pll3_pfd1_664_62m", "pll3_usb_otg", base + 0xf0, 1));
72 clk_dm(IMXRT1020_CLK_PLL3_PFD3_454_74M,
73 imx_clk_pfd("pll3_pfd3_454_74m", "pll3_usb_otg", base + 0xf0, 3));
74
75 /* CCM clocks */
76 base = dev_read_addr_ptr(dev);
77 if (base == (void *)FDT_ADDR_T_NONE)
78 return -EINVAL;
79
80 clk_dm(IMXRT1020_CLK_PRE_PERIPH_SEL,
81 imx_clk_mux("pre_periph_sel", base + 0x18, 18, 2,
82 pre_periph_sels, ARRAY_SIZE(pre_periph_sels)));
83 clk_dm(IMXRT1020_CLK_PERIPH_SEL,
84 imx_clk_mux("periph_sel", base + 0x14, 25, 1,
85 periph_sels, ARRAY_SIZE(periph_sels)));
86 clk_dm(IMXRT1020_CLK_USDHC1_SEL,
87 imx_clk_mux("usdhc1_sel", base + 0x1c, 16, 1,
88 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
89 clk_dm(IMXRT1020_CLK_USDHC2_SEL,
90 imx_clk_mux("usdhc2_sel", base + 0x1c, 17, 1,
91 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
92 clk_dm(IMXRT1020_CLK_LPUART_SEL,
93 imx_clk_mux("lpuart_sel", base + 0x24, 6, 1,
94 lpuart_sels, ARRAY_SIZE(lpuart_sels)));
95 clk_dm(IMXRT1020_CLK_SEMC_ALT_SEL,
96 imx_clk_mux("semc_alt_sel", base + 0x14, 7, 1,
97 semc_alt_sels, ARRAY_SIZE(semc_alt_sels)));
98 clk_dm(IMXRT1020_CLK_SEMC_SEL,
99 imx_clk_mux("semc_sel", base + 0x14, 6, 1,
100 semc_sels, ARRAY_SIZE(semc_sels)));
101
102 clk_dm(IMXRT1020_CLK_AHB_PODF,
103 imx_clk_divider("ahb_podf", "periph_sel",
104 base + 0x14, 10, 3));
105 clk_dm(IMXRT1020_CLK_USDHC1_PODF,
106 imx_clk_divider("usdhc1_podf", "usdhc1_sel",
107 base + 0x24, 11, 3));
108 clk_dm(IMXRT1020_CLK_USDHC2_PODF,
109 imx_clk_divider("usdhc2_podf", "usdhc2_sel",
110 base + 0x24, 16, 3));
111 clk_dm(IMXRT1020_CLK_LPUART_PODF,
112 imx_clk_divider("lpuart_podf", "lpuart_sel",
113 base + 0x24, 0, 6));
114 clk_dm(IMXRT1020_CLK_SEMC_PODF,
115 imx_clk_divider("semc_podf", "semc_sel",
116 base + 0x14, 16, 3));
117
118 clk_dm(IMXRT1020_CLK_USDHC1,
119 imx_clk_gate2("usdhc1", "usdhc1_podf", base + 0x80, 2));
120 clk_dm(IMXRT1020_CLK_USDHC2,
121 imx_clk_gate2("usdhc2", "usdhc2_podf", base + 0x80, 4));
122 clk_dm(IMXRT1020_CLK_LPUART1,
123 imx_clk_gate2("lpuart1", "lpuart_podf", base + 0x7c, 24));
124 clk_dm(IMXRT1020_CLK_SEMC,
125 imx_clk_gate2("semc", "semc_podf", base + 0x74, 4));
126
127#ifdef CONFIG_SPL_BUILD
128 struct clk *clk, *clk1;
129
130 clk_get_by_id(IMXRT1020_CLK_SEMC_SEL, &clk1);
131 clk_get_by_id(IMXRT1020_CLK_SEMC_ALT_SEL, &clk);
132 clk_set_parent(clk1, clk);
133
134 /* Configure PLL3_USB_OTG to 480MHz */
135 clk_get_by_id(IMXRT1020_CLK_PLL3_USB_OTG, &clk);
136 clk_enable(clk);
137 clk_set_rate(clk, 480000000UL);
138
139 clk_get_by_id(IMXRT1020_CLK_PLL3_BYPASS, &clk1);
140 clk_set_parent(clk1, clk);
141
142 clk_get_by_id(IMXRT1020_CLK_PLL2_PFD3_297M, &clk);
143 clk_set_rate(clk, 297000000UL);
144
145 clk_get_by_id(IMXRT1020_CLK_PLL2_SYS, &clk);
146 clk_enable(clk);
147 clk_set_rate(clk, 528000000UL);
148
149 clk_get_by_id(IMXRT1020_CLK_PLL2_BYPASS, &clk1);
150 clk_set_parent(clk1, clk);
151
152#endif
153
154 return 0;
155}
156
157static const struct udevice_id imxrt1020_clk_ids[] = {
158 { .compatible = "fsl,imxrt1020-ccm" },
159 { },
160};
161
162U_BOOT_DRIVER(imxrt1020_clk) = {
163 .name = "clk_imxrt1020",
164 .id = UCLASS_CLK,
165 .of_match = imxrt1020_clk_ids,
166 .ops = &imxrt1020_clk_ops,
167 .probe = imxrt1020_clk_probe,
168 .flags = DM_FLAG_PRE_RELOC,
169};