blob: 754f3948427582fd095f32ed5f1c08259980cdc8 [file] [log] [blame]
Giulio Benettieee03dc92020-01-10 15:47:01 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright(C) 2019
4 * Author(s): Giulio Benetti <giulio.benetti@benettiengineering.com>
5 */
6
Giulio Benettieee03dc92020-01-10 15:47:01 +01007#include <clk.h>
8#include <clk-uclass.h>
9#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Giulio Benettieee03dc92020-01-10 15:47:01 +010011#include <asm/arch/clock.h>
12#include <asm/arch/imx-regs.h>
13#include <dt-bindings/clock/imxrt1050-clock.h>
14
15#include "clk.h"
16
Giulio Benettieee03dc92020-01-10 15:47:01 +010017static const char * const pll_ref_sels[] = {"osc", "dummy", };
18static const char * const pll1_bypass_sels[] = {"pll1_arm", "pll1_arm_ref_sel", };
19static const char * const pll2_bypass_sels[] = {"pll2_sys", "pll2_sys_ref_sel", };
20static const char * const pll3_bypass_sels[] = {"pll3_usb_otg", "pll3_usb_otg_ref_sel", };
21static const char * const pll5_bypass_sels[] = {"pll5_video", "pll5_video_ref_sel", };
22
23static const char *const pre_periph_sels[] = { "pll2_sys", "pll2_pfd2_396m", "pll2_pfd0_352m", "arm_podf", };
24static const char *const periph_sels[] = { "pre_periph_sel", "todo", };
25static const char *const usdhc_sels[] = { "pll2_pfd2_396m", "pll2_pfd0_352m", };
26static const char *const lpuart_sels[] = { "pll3_80m", "osc", };
27static const char *const semc_alt_sels[] = { "pll2_pfd2_396m", "pll3_pfd1_664_62m", };
28static const char *const semc_sels[] = { "periph_sel", "semc_alt_sel", };
Giulio Benetti1c8faa62020-04-08 17:10:08 +020029static const char *const lcdif_sels[] = { "pll2_sys", "pll3_pfd3_454_74m", "pll5_video", "pll2_pfd0_352m", "pll2_pfd1_594m", "pll3_pfd1_664_62m"};
Giulio Benettieee03dc92020-01-10 15:47:01 +010030
31static int imxrt1050_clk_probe(struct udevice *dev)
32{
33 void *base;
34
35 /* Anatop clocks */
Jesse Taube214f4432022-03-17 14:33:18 -040036 base = (void *)ofnode_get_addr(ofnode_by_compatible(ofnode_null(), "fsl,imxrt-anatop"));
Giulio Benettieee03dc92020-01-10 15:47:01 +010037
38 clk_dm(IMXRT1050_CLK_PLL1_REF_SEL,
39 imx_clk_mux("pll1_arm_ref_sel", base + 0x0, 14, 2,
40 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
41 clk_dm(IMXRT1050_CLK_PLL2_REF_SEL,
42 imx_clk_mux("pll2_sys_ref_sel", base + 0x30, 14, 2,
43 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
44 clk_dm(IMXRT1050_CLK_PLL3_REF_SEL,
45 imx_clk_mux("pll3_usb_otg_ref_sel", base + 0x10, 14, 2,
46 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
47 clk_dm(IMXRT1050_CLK_PLL5_REF_SEL,
48 imx_clk_mux("pll5_video_ref_sel", base + 0xa0, 14, 2,
49 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
50
51 clk_dm(IMXRT1050_CLK_PLL1_ARM,
52 imx_clk_pllv3(IMX_PLLV3_SYS, "pll1_arm", "pll1_arm_ref_sel",
53 base + 0x0, 0x7f));
54 clk_dm(IMXRT1050_CLK_PLL2_SYS,
55 imx_clk_pllv3(IMX_PLLV3_GENERIC, "pll2_sys", "pll2_sys_ref_sel",
56 base + 0x30, 0x1));
57 clk_dm(IMXRT1050_CLK_PLL3_USB_OTG,
58 imx_clk_pllv3(IMX_PLLV3_USB, "pll3_usb_otg",
59 "pll3_usb_otg_ref_sel",
60 base + 0x10, 0x1));
61 clk_dm(IMXRT1050_CLK_PLL5_VIDEO,
62 imx_clk_pllv3(IMX_PLLV3_AV, "pll5_video", "pll5_video_ref_sel",
63 base + 0xa0, 0x7f));
64
65 /* PLL bypass out */
66 clk_dm(IMXRT1050_CLK_PLL1_BYPASS,
67 imx_clk_mux_flags("pll1_bypass", base + 0x0, 16, 1,
68 pll1_bypass_sels,
69 ARRAY_SIZE(pll1_bypass_sels),
70 CLK_SET_RATE_PARENT));
71 clk_dm(IMXRT1050_CLK_PLL2_BYPASS,
72 imx_clk_mux_flags("pll2_bypass", base + 0x30, 16, 1,
73 pll2_bypass_sels,
74 ARRAY_SIZE(pll2_bypass_sels),
75 CLK_SET_RATE_PARENT));
76 clk_dm(IMXRT1050_CLK_PLL3_BYPASS,
77 imx_clk_mux_flags("pll3_bypass", base + 0x10, 16, 1,
78 pll3_bypass_sels,
79 ARRAY_SIZE(pll3_bypass_sels),
80 CLK_SET_RATE_PARENT));
81 clk_dm(IMXRT1050_CLK_PLL5_BYPASS,
82 imx_clk_mux_flags("pll5_bypass", base + 0xa0, 16, 1,
83 pll5_bypass_sels,
84 ARRAY_SIZE(pll5_bypass_sels),
85 CLK_SET_RATE_PARENT));
86
87 clk_dm(IMXRT1050_CLK_VIDEO_POST_DIV_SEL,
88 imx_clk_divider("video_post_div_sel", "pll5_video",
89 base + 0xa0, 19, 2));
90 clk_dm(IMXRT1050_CLK_VIDEO_DIV,
91 imx_clk_divider("video_div", "video_post_div_sel",
92 base + 0x170, 30, 2));
93
94 clk_dm(IMXRT1050_CLK_PLL3_80M,
95 imx_clk_fixed_factor("pll3_80m", "pll3_usb_otg", 1, 6));
96
97 clk_dm(IMXRT1050_CLK_PLL2_PFD0_352M,
98 imx_clk_pfd("pll2_pfd0_352m", "pll2_sys", base + 0x100, 0));
99 clk_dm(IMXRT1050_CLK_PLL2_PFD1_594M,
100 imx_clk_pfd("pll2_pfd1_594m", "pll2_sys", base + 0x100, 1));
101 clk_dm(IMXRT1050_CLK_PLL2_PFD2_396M,
102 imx_clk_pfd("pll2_pfd2_396m", "pll2_sys", base + 0x100, 2));
103 clk_dm(IMXRT1050_CLK_PLL3_PFD1_664_62M,
104 imx_clk_pfd("pll3_pfd1_664_62m", "pll3_usb_otg", base + 0xf0,
105 1));
106 clk_dm(IMXRT1050_CLK_PLL3_PFD3_454_74M,
107 imx_clk_pfd("pll3_pfd3_454_74m", "pll3_usb_otg", base + 0xf0,
108 3));
109
110 /* CCM clocks */
111 base = dev_read_addr_ptr(dev);
112 if (base == (void *)FDT_ADDR_T_NONE)
113 return -EINVAL;
114
115 clk_dm(IMXRT1050_CLK_ARM_PODF,
116 imx_clk_divider("arm_podf", "pll1_arm",
117 base + 0x10, 0, 3));
118
119 clk_dm(IMXRT1050_CLK_PRE_PERIPH_SEL,
120 imx_clk_mux("pre_periph_sel", base + 0x18, 18, 2,
121 pre_periph_sels, ARRAY_SIZE(pre_periph_sels)));
122 clk_dm(IMXRT1050_CLK_PERIPH_SEL,
123 imx_clk_mux("periph_sel", base + 0x14, 25, 1,
124 periph_sels, ARRAY_SIZE(periph_sels)));
125 clk_dm(IMXRT1050_CLK_USDHC1_SEL,
126 imx_clk_mux("usdhc1_sel", base + 0x1c, 16, 1,
127 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
128 clk_dm(IMXRT1050_CLK_USDHC2_SEL,
129 imx_clk_mux("usdhc2_sel", base + 0x1c, 17, 1,
130 usdhc_sels, ARRAY_SIZE(usdhc_sels)));
131 clk_dm(IMXRT1050_CLK_LPUART_SEL,
132 imx_clk_mux("lpuart_sel", base + 0x24, 6, 1,
133 lpuart_sels, ARRAY_SIZE(lpuart_sels)));
134 clk_dm(IMXRT1050_CLK_SEMC_ALT_SEL,
135 imx_clk_mux("semc_alt_sel", base + 0x14, 7, 1,
136 semc_alt_sels, ARRAY_SIZE(semc_alt_sels)));
137 clk_dm(IMXRT1050_CLK_SEMC_SEL,
138 imx_clk_mux("semc_sel", base + 0x14, 6, 1,
139 semc_sels, ARRAY_SIZE(semc_sels)));
140 clk_dm(IMXRT1050_CLK_LCDIF_SEL,
141 imx_clk_mux("lcdif_sel", base + 0x38, 15, 3,
142 lcdif_sels, ARRAY_SIZE(lcdif_sels)));
143
144 clk_dm(IMXRT1050_CLK_AHB_PODF,
145 imx_clk_divider("ahb_podf", "periph_sel",
146 base + 0x14, 10, 3));
147 clk_dm(IMXRT1050_CLK_USDHC1_PODF,
148 imx_clk_divider("usdhc1_podf", "usdhc1_sel",
149 base + 0x24, 11, 3));
150 clk_dm(IMXRT1050_CLK_USDHC2_PODF,
151 imx_clk_divider("usdhc2_podf", "usdhc2_sel",
152 base + 0x24, 16, 3));
153 clk_dm(IMXRT1050_CLK_LPUART_PODF,
154 imx_clk_divider("lpuart_podf", "lpuart_sel",
155 base + 0x24, 0, 6));
156 clk_dm(IMXRT1050_CLK_SEMC_PODF,
157 imx_clk_divider("semc_podf", "semc_sel",
158 base + 0x14, 16, 3));
159 clk_dm(IMXRT1050_CLK_LCDIF_PRED,
160 imx_clk_divider("lcdif_pred", "lcdif_sel",
161 base + 0x38, 12, 3));
162 clk_dm(IMXRT1050_CLK_LCDIF_PODF,
163 imx_clk_divider("lcdif_podf", "lcdif_pred",
164 base + 0x18, 23, 3));
165
166 clk_dm(IMXRT1050_CLK_USDHC1,
167 imx_clk_gate2("usdhc1", "usdhc1_podf", base + 0x80, 2));
168 clk_dm(IMXRT1050_CLK_USDHC2,
169 imx_clk_gate2("usdhc2", "usdhc2_podf", base + 0x80, 4));
170 clk_dm(IMXRT1050_CLK_LPUART1,
171 imx_clk_gate2("lpuart1", "lpuart_podf", base + 0x7c, 24));
172 clk_dm(IMXRT1050_CLK_SEMC,
173 imx_clk_gate2("semc", "semc_podf", base + 0x74, 4));
Giulio Benetti71d1ee42021-05-13 12:19:33 +0200174 clk_dm(IMXRT1050_CLK_LCDIF_APB,
175 imx_clk_gate2("lcdif", "lcdif_podf", base + 0x70, 28));
176 clk_dm(IMXRT1050_CLK_LCDIF_PIX,
177 imx_clk_gate2("lcdif_pix", "lcdif", base + 0x74, 10));
Giulio Benettid08f8672021-05-20 16:10:14 +0200178 clk_dm(IMXRT1050_CLK_USBOH3,
179 imx_clk_gate2("usboh3", "pll3_usb_otg", base + 0x80, 0));
Giulio Benettieee03dc92020-01-10 15:47:01 +0100180
Giulio Benettieee03dc92020-01-10 15:47:01 +0100181 struct clk *clk, *clk1;
182
Giulio Benetti735b6d12020-04-08 17:10:09 +0200183#ifdef CONFIG_SPL_BUILD
Giulio Benettieee03dc92020-01-10 15:47:01 +0100184 /* bypass pll1 before setting its rate */
185 clk_get_by_id(IMXRT1050_CLK_PLL1_REF_SEL, &clk);
186 clk_get_by_id(IMXRT1050_CLK_PLL1_BYPASS, &clk1);
187 clk_set_parent(clk1, clk);
188
189 clk_get_by_id(IMXRT1050_CLK_PLL1_ARM, &clk);
190 clk_enable(clk);
191 clk_set_rate(clk, 1056000000UL);
192
193 clk_get_by_id(IMXRT1050_CLK_PLL1_BYPASS, &clk1);
194 clk_set_parent(clk1, clk);
195
196 clk_get_by_id(IMXRT1050_CLK_SEMC_SEL, &clk1);
197 clk_get_by_id(IMXRT1050_CLK_SEMC_ALT_SEL, &clk);
198 clk_set_parent(clk1, clk);
199
200 clk_get_by_id(IMXRT1050_CLK_PLL2_SYS, &clk);
201 clk_enable(clk);
202 clk_set_rate(clk, 528000000UL);
203
204 clk_get_by_id(IMXRT1050_CLK_PLL2_BYPASS, &clk1);
205 clk_set_parent(clk1, clk);
206
207 /* Configure PLL3_USB_OTG to 480MHz */
208 clk_get_by_id(IMXRT1050_CLK_PLL3_USB_OTG, &clk);
209 clk_enable(clk);
210 clk_set_rate(clk, 480000000UL);
211
212 clk_get_by_id(IMXRT1050_CLK_PLL3_BYPASS, &clk1);
213 clk_set_parent(clk1, clk);
Giulio Benetti735b6d12020-04-08 17:10:09 +0200214#else
215 /* Set PLL5 for LCDIF to its default 650Mhz */
216 clk_get_by_id(IMXRT1050_CLK_PLL5_VIDEO, &clk);
217 clk_enable(clk);
218 clk_set_rate(clk, 650000000UL);
Giulio Benettieee03dc92020-01-10 15:47:01 +0100219
Giulio Benetti735b6d12020-04-08 17:10:09 +0200220 clk_get_by_id(IMXRT1050_CLK_PLL5_BYPASS, &clk1);
221 clk_set_parent(clk1, clk);
Giulio Benettieee03dc92020-01-10 15:47:01 +0100222#endif
223
224 return 0;
225}
226
227static const struct udevice_id imxrt1050_clk_ids[] = {
228 { .compatible = "fsl,imxrt1050-ccm" },
229 { },
230};
231
232U_BOOT_DRIVER(imxrt1050_clk) = {
233 .name = "clk_imxrt1050",
234 .id = UCLASS_CLK,
235 .of_match = imxrt1050_clk_ids,
Sean Anderson35c84642022-03-20 16:34:46 -0400236 .ops = &ccf_clk_ops,
Giulio Benettieee03dc92020-01-10 15:47:01 +0100237 .probe = imxrt1050_clk_probe,
238 .flags = DM_FLAG_PRE_RELOC,
239};