1d058fd9eSRahul Tanwar // SPDX-License-Identifier: GPL-2.0
2d058fd9eSRahul Tanwar /*
303617731SRahul Tanwar * Copyright (C) 2020-2022 MaxLinear, Inc.
4d058fd9eSRahul Tanwar * Copyright (C) 2020 Intel Corporation.
503617731SRahul Tanwar * Zhu Yixin <yzhu@maxlinear.com>
603617731SRahul Tanwar * Rahul Tanwar <rtanwar@maxlinear.com>
7d058fd9eSRahul Tanwar */
8d058fd9eSRahul Tanwar #include <linux/clk-provider.h>
903617731SRahul Tanwar #include <linux/mfd/syscon.h>
10d058fd9eSRahul Tanwar #include <linux/of.h>
11d058fd9eSRahul Tanwar #include <linux/platform_device.h>
12d058fd9eSRahul Tanwar #include <dt-bindings/clock/intel,lgm-clk.h>
13d058fd9eSRahul Tanwar #include "clk-cgu.h"
14d058fd9eSRahul Tanwar
15d058fd9eSRahul Tanwar #define PLL_DIV_WIDTH 4
16d058fd9eSRahul Tanwar #define PLL_DDIV_WIDTH 3
17d058fd9eSRahul Tanwar
18d058fd9eSRahul Tanwar /* Gate0 clock shift */
19d058fd9eSRahul Tanwar #define G_C55_SHIFT 7
20d058fd9eSRahul Tanwar #define G_QSPI_SHIFT 9
21d058fd9eSRahul Tanwar #define G_EIP197_SHIFT 11
22d058fd9eSRahul Tanwar #define G_VAULT130_SHIFT 12
23d058fd9eSRahul Tanwar #define G_TOE_SHIFT 13
24d058fd9eSRahul Tanwar #define G_SDXC_SHIFT 14
25d058fd9eSRahul Tanwar #define G_EMMC_SHIFT 15
26d058fd9eSRahul Tanwar #define G_SPIDBG_SHIFT 17
27d058fd9eSRahul Tanwar #define G_DMA3_SHIFT 28
28d058fd9eSRahul Tanwar
29d058fd9eSRahul Tanwar /* Gate1 clock shift */
30d058fd9eSRahul Tanwar #define G_DMA0_SHIFT 0
31d058fd9eSRahul Tanwar #define G_LEDC0_SHIFT 1
32d058fd9eSRahul Tanwar #define G_LEDC1_SHIFT 2
33d058fd9eSRahul Tanwar #define G_I2S0_SHIFT 3
34d058fd9eSRahul Tanwar #define G_I2S1_SHIFT 4
35d058fd9eSRahul Tanwar #define G_EBU_SHIFT 5
36d058fd9eSRahul Tanwar #define G_PWM_SHIFT 6
37d058fd9eSRahul Tanwar #define G_I2C0_SHIFT 7
38d058fd9eSRahul Tanwar #define G_I2C1_SHIFT 8
39d058fd9eSRahul Tanwar #define G_I2C2_SHIFT 9
40d058fd9eSRahul Tanwar #define G_I2C3_SHIFT 10
41d058fd9eSRahul Tanwar
42d058fd9eSRahul Tanwar #define G_SSC0_SHIFT 12
43d058fd9eSRahul Tanwar #define G_SSC1_SHIFT 13
44d058fd9eSRahul Tanwar #define G_SSC2_SHIFT 14
45d058fd9eSRahul Tanwar #define G_SSC3_SHIFT 15
46d058fd9eSRahul Tanwar
47d058fd9eSRahul Tanwar #define G_GPTC0_SHIFT 17
48d058fd9eSRahul Tanwar #define G_GPTC1_SHIFT 18
49d058fd9eSRahul Tanwar #define G_GPTC2_SHIFT 19
50d058fd9eSRahul Tanwar #define G_GPTC3_SHIFT 20
51d058fd9eSRahul Tanwar
52d058fd9eSRahul Tanwar #define G_ASC0_SHIFT 22
53d058fd9eSRahul Tanwar #define G_ASC1_SHIFT 23
54d058fd9eSRahul Tanwar #define G_ASC2_SHIFT 24
55d058fd9eSRahul Tanwar #define G_ASC3_SHIFT 25
56d058fd9eSRahul Tanwar
57d058fd9eSRahul Tanwar #define G_PCM0_SHIFT 27
58d058fd9eSRahul Tanwar #define G_PCM1_SHIFT 28
59d058fd9eSRahul Tanwar #define G_PCM2_SHIFT 29
60d058fd9eSRahul Tanwar
61d058fd9eSRahul Tanwar /* Gate2 clock shift */
62d058fd9eSRahul Tanwar #define G_PCIE10_SHIFT 1
63d058fd9eSRahul Tanwar #define G_PCIE11_SHIFT 2
64d058fd9eSRahul Tanwar #define G_PCIE30_SHIFT 3
65d058fd9eSRahul Tanwar #define G_PCIE31_SHIFT 4
66d058fd9eSRahul Tanwar #define G_PCIE20_SHIFT 5
67d058fd9eSRahul Tanwar #define G_PCIE21_SHIFT 6
68d058fd9eSRahul Tanwar #define G_PCIE40_SHIFT 7
69d058fd9eSRahul Tanwar #define G_PCIE41_SHIFT 8
70d058fd9eSRahul Tanwar
71d058fd9eSRahul Tanwar #define G_XPCS0_SHIFT 10
72d058fd9eSRahul Tanwar #define G_XPCS1_SHIFT 11
73d058fd9eSRahul Tanwar #define G_XPCS2_SHIFT 12
74d058fd9eSRahul Tanwar #define G_XPCS3_SHIFT 13
75d058fd9eSRahul Tanwar #define G_SATA0_SHIFT 14
76d058fd9eSRahul Tanwar #define G_SATA1_SHIFT 15
77d058fd9eSRahul Tanwar #define G_SATA2_SHIFT 16
78d058fd9eSRahul Tanwar #define G_SATA3_SHIFT 17
79d058fd9eSRahul Tanwar
80d058fd9eSRahul Tanwar /* Gate3 clock shift */
81d058fd9eSRahul Tanwar #define G_ARCEM4_SHIFT 0
82d058fd9eSRahul Tanwar #define G_IDMAR1_SHIFT 2
83d058fd9eSRahul Tanwar #define G_IDMAT0_SHIFT 3
84d058fd9eSRahul Tanwar #define G_IDMAT1_SHIFT 4
85d058fd9eSRahul Tanwar #define G_IDMAT2_SHIFT 5
86d058fd9eSRahul Tanwar
87d058fd9eSRahul Tanwar #define G_PPV4_SHIFT 8
88d058fd9eSRahul Tanwar #define G_GSWIPO_SHIFT 9
89d058fd9eSRahul Tanwar #define G_CQEM_SHIFT 10
90d058fd9eSRahul Tanwar #define G_XPCS5_SHIFT 14
91d058fd9eSRahul Tanwar #define G_USB1_SHIFT 25
92d058fd9eSRahul Tanwar #define G_USB2_SHIFT 26
93d058fd9eSRahul Tanwar
94d058fd9eSRahul Tanwar
95d058fd9eSRahul Tanwar /* Register definition */
96d058fd9eSRahul Tanwar #define CGU_PLL0CZ_CFG0 0x000
97d058fd9eSRahul Tanwar #define CGU_PLL0CM0_CFG0 0x020
98d058fd9eSRahul Tanwar #define CGU_PLL0CM1_CFG0 0x040
99d058fd9eSRahul Tanwar #define CGU_PLL0B_CFG0 0x060
100d058fd9eSRahul Tanwar #define CGU_PLL1_CFG0 0x080
101d058fd9eSRahul Tanwar #define CGU_PLL2_CFG0 0x0A0
102d058fd9eSRahul Tanwar #define CGU_PLLPP_CFG0 0x0C0
103d058fd9eSRahul Tanwar #define CGU_LJPLL3_CFG0 0x0E0
104d058fd9eSRahul Tanwar #define CGU_LJPLL4_CFG0 0x100
105d058fd9eSRahul Tanwar #define CGU_C55_PCMCR 0x18C
106d058fd9eSRahul Tanwar #define CGU_PCMCR 0x190
107d058fd9eSRahul Tanwar #define CGU_IF_CLK1 0x1A0
108d058fd9eSRahul Tanwar #define CGU_IF_CLK2 0x1A4
109d058fd9eSRahul Tanwar #define CGU_GATE0 0x300
110d058fd9eSRahul Tanwar #define CGU_GATE1 0x310
111d058fd9eSRahul Tanwar #define CGU_GATE2 0x320
112d058fd9eSRahul Tanwar #define CGU_GATE3 0x310
113d058fd9eSRahul Tanwar
114d058fd9eSRahul Tanwar #define PLL_DIV(x) ((x) + 0x04)
115d058fd9eSRahul Tanwar #define PLL_SSC(x) ((x) + 0x10)
116d058fd9eSRahul Tanwar
117d058fd9eSRahul Tanwar #define CLK_NR_CLKS (LGM_GCLK_USB2 + 1)
118d058fd9eSRahul Tanwar
119d058fd9eSRahul Tanwar /*
120d058fd9eSRahul Tanwar * Below table defines the pair's of regval & effective dividers.
121d058fd9eSRahul Tanwar * It's more efficient to provide an explicit table due to non-linear
122d058fd9eSRahul Tanwar * relation between values.
123d058fd9eSRahul Tanwar */
124d058fd9eSRahul Tanwar static const struct clk_div_table pll_div[] = {
125d058fd9eSRahul Tanwar { .val = 0, .div = 1 },
126d058fd9eSRahul Tanwar { .val = 1, .div = 2 },
127d058fd9eSRahul Tanwar { .val = 2, .div = 3 },
128d058fd9eSRahul Tanwar { .val = 3, .div = 4 },
129d058fd9eSRahul Tanwar { .val = 4, .div = 5 },
130d058fd9eSRahul Tanwar { .val = 5, .div = 6 },
131d058fd9eSRahul Tanwar { .val = 6, .div = 8 },
132d058fd9eSRahul Tanwar { .val = 7, .div = 10 },
133d058fd9eSRahul Tanwar { .val = 8, .div = 12 },
134d058fd9eSRahul Tanwar { .val = 9, .div = 16 },
135d058fd9eSRahul Tanwar { .val = 10, .div = 20 },
136d058fd9eSRahul Tanwar { .val = 11, .div = 24 },
137d058fd9eSRahul Tanwar { .val = 12, .div = 32 },
138d058fd9eSRahul Tanwar { .val = 13, .div = 40 },
139d058fd9eSRahul Tanwar { .val = 14, .div = 48 },
140d058fd9eSRahul Tanwar { .val = 15, .div = 64 },
141d058fd9eSRahul Tanwar {}
142d058fd9eSRahul Tanwar };
143d058fd9eSRahul Tanwar
144d058fd9eSRahul Tanwar static const struct clk_div_table dcl_div[] = {
145d058fd9eSRahul Tanwar { .val = 0, .div = 6 },
146d058fd9eSRahul Tanwar { .val = 1, .div = 12 },
147d058fd9eSRahul Tanwar { .val = 2, .div = 24 },
148d058fd9eSRahul Tanwar { .val = 3, .div = 32 },
149d058fd9eSRahul Tanwar { .val = 4, .div = 48 },
150d058fd9eSRahul Tanwar { .val = 5, .div = 96 },
151d058fd9eSRahul Tanwar {}
152d058fd9eSRahul Tanwar };
153d058fd9eSRahul Tanwar
154d058fd9eSRahul Tanwar static const struct clk_parent_data pll_p[] = {
155d058fd9eSRahul Tanwar { .fw_name = "osc", .name = "osc" },
156d058fd9eSRahul Tanwar };
157d058fd9eSRahul Tanwar static const struct clk_parent_data pllcm_p[] = {
158d058fd9eSRahul Tanwar { .fw_name = "cpu_cm", .name = "cpu_cm" },
159d058fd9eSRahul Tanwar };
160d058fd9eSRahul Tanwar static const struct clk_parent_data emmc_p[] = {
161d058fd9eSRahul Tanwar { .fw_name = "emmc4", .name = "emmc4" },
162d058fd9eSRahul Tanwar { .fw_name = "noc4", .name = "noc4" },
163d058fd9eSRahul Tanwar };
164d058fd9eSRahul Tanwar static const struct clk_parent_data sdxc_p[] = {
165d058fd9eSRahul Tanwar { .fw_name = "sdxc3", .name = "sdxc3" },
166d058fd9eSRahul Tanwar { .fw_name = "sdxc2", .name = "sdxc2" },
167d058fd9eSRahul Tanwar };
168d058fd9eSRahul Tanwar static const struct clk_parent_data pcm_p[] = {
169d058fd9eSRahul Tanwar { .fw_name = "v_docsis", .name = "v_docsis" },
170d058fd9eSRahul Tanwar { .fw_name = "dcl", .name = "dcl" },
171d058fd9eSRahul Tanwar };
172d058fd9eSRahul Tanwar static const struct clk_parent_data cbphy_p[] = {
173d058fd9eSRahul Tanwar { .fw_name = "dd_serdes", .name = "dd_serdes" },
174d058fd9eSRahul Tanwar { .fw_name = "dd_pcie", .name = "dd_pcie" },
175d058fd9eSRahul Tanwar };
176d058fd9eSRahul Tanwar
177d058fd9eSRahul Tanwar static const struct lgm_pll_clk_data lgm_pll_clks[] = {
178d058fd9eSRahul Tanwar LGM_PLL(LGM_CLK_PLL0CZ, "pll0cz", pll_p, CLK_IGNORE_UNUSED,
179d058fd9eSRahul Tanwar CGU_PLL0CZ_CFG0, TYPE_ROPLL),
180d058fd9eSRahul Tanwar LGM_PLL(LGM_CLK_PLL0CM0, "pll0cm0", pllcm_p, CLK_IGNORE_UNUSED,
181d058fd9eSRahul Tanwar CGU_PLL0CM0_CFG0, TYPE_ROPLL),
182d058fd9eSRahul Tanwar LGM_PLL(LGM_CLK_PLL0CM1, "pll0cm1", pllcm_p, CLK_IGNORE_UNUSED,
183d058fd9eSRahul Tanwar CGU_PLL0CM1_CFG0, TYPE_ROPLL),
184d058fd9eSRahul Tanwar LGM_PLL(LGM_CLK_PLL0B, "pll0b", pll_p, CLK_IGNORE_UNUSED,
185d058fd9eSRahul Tanwar CGU_PLL0B_CFG0, TYPE_ROPLL),
186d058fd9eSRahul Tanwar LGM_PLL(LGM_CLK_PLL1, "pll1", pll_p, 0, CGU_PLL1_CFG0, TYPE_ROPLL),
187d058fd9eSRahul Tanwar LGM_PLL(LGM_CLK_PLL2, "pll2", pll_p, CLK_IGNORE_UNUSED,
188d058fd9eSRahul Tanwar CGU_PLL2_CFG0, TYPE_ROPLL),
189d058fd9eSRahul Tanwar LGM_PLL(LGM_CLK_PLLPP, "pllpp", pll_p, 0, CGU_PLLPP_CFG0, TYPE_ROPLL),
190d058fd9eSRahul Tanwar LGM_PLL(LGM_CLK_LJPLL3, "ljpll3", pll_p, 0, CGU_LJPLL3_CFG0, TYPE_LJPLL),
191d058fd9eSRahul Tanwar LGM_PLL(LGM_CLK_LJPLL4, "ljpll4", pll_p, 0, CGU_LJPLL4_CFG0, TYPE_LJPLL),
192d058fd9eSRahul Tanwar };
193d058fd9eSRahul Tanwar
194d058fd9eSRahul Tanwar static const struct lgm_clk_branch lgm_branch_clks[] = {
195d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_PP_HW, "pp_hw", "pllpp", 0, PLL_DIV(CGU_PLLPP_CFG0),
196d058fd9eSRahul Tanwar 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div),
197d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_PP_UC, "pp_uc", "pllpp", 0, PLL_DIV(CGU_PLLPP_CFG0),
198d058fd9eSRahul Tanwar 4, PLL_DIV_WIDTH, 25, 1, 0, 0, pll_div),
199d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_PP_FXD, "pp_fxd", "pllpp", 0, PLL_DIV(CGU_PLLPP_CFG0),
200d058fd9eSRahul Tanwar 8, PLL_DIV_WIDTH, 26, 1, 0, 0, pll_div),
201d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_PP_TBM, "pp_tbm", "pllpp", 0, PLL_DIV(CGU_PLLPP_CFG0),
202d058fd9eSRahul Tanwar 12, PLL_DIV_WIDTH, 27, 1, 0, 0, pll_div),
203d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_DDR, "ddr", "pll2", CLK_IGNORE_UNUSED,
204d058fd9eSRahul Tanwar PLL_DIV(CGU_PLL2_CFG0), 0, PLL_DIV_WIDTH, 24, 1, 0, 0,
205d058fd9eSRahul Tanwar pll_div),
206d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_CM, "cpu_cm", "pll0cz", 0, PLL_DIV(CGU_PLL0CZ_CFG0),
207d058fd9eSRahul Tanwar 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div),
208d058fd9eSRahul Tanwar
209d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_IC, "cpu_ic", "pll0cz", CLK_IGNORE_UNUSED,
210d058fd9eSRahul Tanwar PLL_DIV(CGU_PLL0CZ_CFG0), 4, PLL_DIV_WIDTH, 25,
211d058fd9eSRahul Tanwar 1, 0, 0, pll_div),
212d058fd9eSRahul Tanwar
213d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_SDXC3, "sdxc3", "pll0cz", 0, PLL_DIV(CGU_PLL0CZ_CFG0),
214d058fd9eSRahul Tanwar 8, PLL_DIV_WIDTH, 26, 1, 0, 0, pll_div),
215d058fd9eSRahul Tanwar
216d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_CPU0, "cm0", "pll0cm0",
217d058fd9eSRahul Tanwar CLK_IGNORE_UNUSED, PLL_DIV(CGU_PLL0CM0_CFG0),
218d058fd9eSRahul Tanwar 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div),
219d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_CPU1, "cm1", "pll0cm1",
220d058fd9eSRahul Tanwar CLK_IGNORE_UNUSED, PLL_DIV(CGU_PLL0CM1_CFG0),
221d058fd9eSRahul Tanwar 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div),
222d058fd9eSRahul Tanwar
223d058fd9eSRahul Tanwar /*
224d058fd9eSRahul Tanwar * Marking ngi_clk (next generation interconnect) and noc_clk
225d058fd9eSRahul Tanwar * (network on chip peripheral clk) as critical clocks because
226d058fd9eSRahul Tanwar * these are shared parent clock sources for many different
227d058fd9eSRahul Tanwar * peripherals.
228d058fd9eSRahul Tanwar */
229d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_NGI, "ngi", "pll0b",
230d058fd9eSRahul Tanwar (CLK_IGNORE_UNUSED|CLK_IS_CRITICAL), PLL_DIV(CGU_PLL0B_CFG0),
231d058fd9eSRahul Tanwar 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div),
232d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_NOC4, "noc4", "pll0b",
233d058fd9eSRahul Tanwar (CLK_IGNORE_UNUSED|CLK_IS_CRITICAL), PLL_DIV(CGU_PLL0B_CFG0),
234d058fd9eSRahul Tanwar 4, PLL_DIV_WIDTH, 25, 1, 0, 0, pll_div),
235d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_SW, "switch", "pll0b", 0, PLL_DIV(CGU_PLL0B_CFG0),
236d058fd9eSRahul Tanwar 8, PLL_DIV_WIDTH, 26, 1, 0, 0, pll_div),
237d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_QSPI, "qspi", "pll0b", 0, PLL_DIV(CGU_PLL0B_CFG0),
238d058fd9eSRahul Tanwar 12, PLL_DIV_WIDTH, 27, 1, 0, 0, pll_div),
239d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_CT, "v_ct", "pll1", 0, PLL_DIV(CGU_PLL1_CFG0),
240d058fd9eSRahul Tanwar 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div),
241d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_DSP, "v_dsp", "pll1", 0, PLL_DIV(CGU_PLL1_CFG0),
242d058fd9eSRahul Tanwar 8, PLL_DIV_WIDTH, 26, 1, 0, 0, pll_div),
243d058fd9eSRahul Tanwar LGM_DIV(LGM_CLK_VIF, "v_ifclk", "pll1", 0, PLL_DIV(CGU_PLL1_CFG0),
244d058fd9eSRahul Tanwar 12, PLL_DIV_WIDTH, 27, 1, 0, 0, pll_div),
245d058fd9eSRahul Tanwar
246d058fd9eSRahul Tanwar LGM_FIXED_FACTOR(LGM_CLK_EMMC4, "emmc4", "sdxc3", 0, 0,
247d058fd9eSRahul Tanwar 0, 0, 0, 0, 1, 4),
248d058fd9eSRahul Tanwar LGM_FIXED_FACTOR(LGM_CLK_SDXC2, "sdxc2", "noc4", 0, 0,
249d058fd9eSRahul Tanwar 0, 0, 0, 0, 1, 4),
250d058fd9eSRahul Tanwar LGM_MUX(LGM_CLK_EMMC, "emmc", emmc_p, 0, CGU_IF_CLK1,
251d058fd9eSRahul Tanwar 0, 1, CLK_MUX_ROUND_CLOSEST, 0),
252d058fd9eSRahul Tanwar LGM_MUX(LGM_CLK_SDXC, "sdxc", sdxc_p, 0, CGU_IF_CLK1,
253d058fd9eSRahul Tanwar 1, 1, CLK_MUX_ROUND_CLOSEST, 0),
254d058fd9eSRahul Tanwar LGM_FIXED(LGM_CLK_OSC, "osc", NULL, 0, 0, 0, 0, 0, 40000000, 0),
255d058fd9eSRahul Tanwar LGM_FIXED(LGM_CLK_SLIC, "slic", NULL, 0, CGU_IF_CLK1,
256d058fd9eSRahul Tanwar 8, 2, CLOCK_FLAG_VAL_INIT, 8192000, 2),
257d058fd9eSRahul Tanwar LGM_FIXED(LGM_CLK_DOCSIS, "v_docsis", NULL, 0, 0, 0, 0, 0, 16000000, 0),
258106ef3bdSRahul Tanwar LGM_DIV(LGM_CLK_DCL, "dcl", "v_ifclk", CLK_SET_RATE_PARENT, CGU_PCMCR,
259106ef3bdSRahul Tanwar 25, 3, 0, 0, DIV_CLK_NO_MASK, 0, dcl_div),
260d058fd9eSRahul Tanwar LGM_MUX(LGM_CLK_PCM, "pcm", pcm_p, 0, CGU_C55_PCMCR,
261d058fd9eSRahul Tanwar 0, 1, CLK_MUX_ROUND_CLOSEST, 0),
262d058fd9eSRahul Tanwar LGM_FIXED_FACTOR(LGM_CLK_DDR_PHY, "ddr_phy", "ddr",
263d058fd9eSRahul Tanwar CLK_IGNORE_UNUSED, 0,
264d058fd9eSRahul Tanwar 0, 0, 0, 0, 2, 1),
265d058fd9eSRahul Tanwar LGM_FIXED_FACTOR(LGM_CLK_PONDEF, "pondef", "dd_pool",
266d058fd9eSRahul Tanwar CLK_SET_RATE_PARENT, 0, 0, 0, 0, 0, 1, 2),
267d058fd9eSRahul Tanwar LGM_MUX(LGM_CLK_CBPHY0, "cbphy0", cbphy_p, 0, 0,
268d058fd9eSRahul Tanwar 0, 0, MUX_CLK_SW | CLK_MUX_ROUND_CLOSEST, 0),
269d058fd9eSRahul Tanwar LGM_MUX(LGM_CLK_CBPHY1, "cbphy1", cbphy_p, 0, 0,
270d058fd9eSRahul Tanwar 0, 0, MUX_CLK_SW | CLK_MUX_ROUND_CLOSEST, 0),
271d058fd9eSRahul Tanwar LGM_MUX(LGM_CLK_CBPHY2, "cbphy2", cbphy_p, 0, 0,
272d058fd9eSRahul Tanwar 0, 0, MUX_CLK_SW | CLK_MUX_ROUND_CLOSEST, 0),
273d058fd9eSRahul Tanwar LGM_MUX(LGM_CLK_CBPHY3, "cbphy3", cbphy_p, 0, 0,
274d058fd9eSRahul Tanwar 0, 0, MUX_CLK_SW | CLK_MUX_ROUND_CLOSEST, 0),
275d058fd9eSRahul Tanwar
276d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_C55, "g_c55", NULL, 0, CGU_GATE0,
277d058fd9eSRahul Tanwar G_C55_SHIFT, 0, 0),
278d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_QSPI, "g_qspi", "qspi", 0, CGU_GATE0,
279d058fd9eSRahul Tanwar G_QSPI_SHIFT, 0, 0),
280d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_EIP197, "g_eip197", NULL, 0, CGU_GATE0,
281d058fd9eSRahul Tanwar G_EIP197_SHIFT, 0, 0),
282d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_VAULT, "g_vault130", NULL, 0, CGU_GATE0,
283d058fd9eSRahul Tanwar G_VAULT130_SHIFT, 0, 0),
284d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_TOE, "g_toe", NULL, 0, CGU_GATE0,
285d058fd9eSRahul Tanwar G_TOE_SHIFT, 0, 0),
286d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_SDXC, "g_sdxc", "sdxc", 0, CGU_GATE0,
287d058fd9eSRahul Tanwar G_SDXC_SHIFT, 0, 0),
288d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_EMMC, "g_emmc", "emmc", 0, CGU_GATE0,
289d058fd9eSRahul Tanwar G_EMMC_SHIFT, 0, 0),
290d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_SPI_DBG, "g_spidbg", NULL, 0, CGU_GATE0,
291d058fd9eSRahul Tanwar G_SPIDBG_SHIFT, 0, 0),
292d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_DMA3, "g_dma3", NULL, 0, CGU_GATE0,
293d058fd9eSRahul Tanwar G_DMA3_SHIFT, 0, 0),
294d058fd9eSRahul Tanwar
295d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_DMA0, "g_dma0", NULL, 0, CGU_GATE1,
296d058fd9eSRahul Tanwar G_DMA0_SHIFT, 0, 0),
297d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_LEDC0, "g_ledc0", NULL, 0, CGU_GATE1,
298d058fd9eSRahul Tanwar G_LEDC0_SHIFT, 0, 0),
299d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_LEDC1, "g_ledc1", NULL, 0, CGU_GATE1,
300d058fd9eSRahul Tanwar G_LEDC1_SHIFT, 0, 0),
301d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_I2S0, "g_i2s0", NULL, 0, CGU_GATE1,
302d058fd9eSRahul Tanwar G_I2S0_SHIFT, 0, 0),
303d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_I2S1, "g_i2s1", NULL, 0, CGU_GATE1,
304d058fd9eSRahul Tanwar G_I2S1_SHIFT, 0, 0),
305d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_EBU, "g_ebu", NULL, 0, CGU_GATE1,
306d058fd9eSRahul Tanwar G_EBU_SHIFT, 0, 0),
307d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PWM, "g_pwm", NULL, 0, CGU_GATE1,
308d058fd9eSRahul Tanwar G_PWM_SHIFT, 0, 0),
309d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_I2C0, "g_i2c0", NULL, 0, CGU_GATE1,
310d058fd9eSRahul Tanwar G_I2C0_SHIFT, 0, 0),
311d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_I2C1, "g_i2c1", NULL, 0, CGU_GATE1,
312d058fd9eSRahul Tanwar G_I2C1_SHIFT, 0, 0),
313d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_I2C2, "g_i2c2", NULL, 0, CGU_GATE1,
314d058fd9eSRahul Tanwar G_I2C2_SHIFT, 0, 0),
315d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_I2C3, "g_i2c3", NULL, 0, CGU_GATE1,
316d058fd9eSRahul Tanwar G_I2C3_SHIFT, 0, 0),
317d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_SSC0, "g_ssc0", "noc4", 0, CGU_GATE1,
318d058fd9eSRahul Tanwar G_SSC0_SHIFT, 0, 0),
319d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_SSC1, "g_ssc1", "noc4", 0, CGU_GATE1,
320d058fd9eSRahul Tanwar G_SSC1_SHIFT, 0, 0),
321d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_SSC2, "g_ssc2", "noc4", 0, CGU_GATE1,
322d058fd9eSRahul Tanwar G_SSC2_SHIFT, 0, 0),
323d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_SSC3, "g_ssc3", "noc4", 0, CGU_GATE1,
324d058fd9eSRahul Tanwar G_SSC3_SHIFT, 0, 0),
325d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_GPTC0, "g_gptc0", "noc4", 0, CGU_GATE1,
326d058fd9eSRahul Tanwar G_GPTC0_SHIFT, 0, 0),
327d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_GPTC1, "g_gptc1", "noc4", 0, CGU_GATE1,
328d058fd9eSRahul Tanwar G_GPTC1_SHIFT, 0, 0),
329d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_GPTC2, "g_gptc2", "noc4", 0, CGU_GATE1,
330d058fd9eSRahul Tanwar G_GPTC2_SHIFT, 0, 0),
331d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_GPTC3, "g_gptc3", "osc", 0, CGU_GATE1,
332d058fd9eSRahul Tanwar G_GPTC3_SHIFT, 0, 0),
333d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_ASC0, "g_asc0", "noc4", 0, CGU_GATE1,
334d058fd9eSRahul Tanwar G_ASC0_SHIFT, 0, 0),
335d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_ASC1, "g_asc1", "noc4", 0, CGU_GATE1,
336d058fd9eSRahul Tanwar G_ASC1_SHIFT, 0, 0),
337d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_ASC2, "g_asc2", "noc4", 0, CGU_GATE1,
338d058fd9eSRahul Tanwar G_ASC2_SHIFT, 0, 0),
339d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_ASC3, "g_asc3", "osc", 0, CGU_GATE1,
340d058fd9eSRahul Tanwar G_ASC3_SHIFT, 0, 0),
341d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PCM0, "g_pcm0", NULL, 0, CGU_GATE1,
342d058fd9eSRahul Tanwar G_PCM0_SHIFT, 0, 0),
343d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PCM1, "g_pcm1", NULL, 0, CGU_GATE1,
344d058fd9eSRahul Tanwar G_PCM1_SHIFT, 0, 0),
345d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PCM2, "g_pcm2", NULL, 0, CGU_GATE1,
346d058fd9eSRahul Tanwar G_PCM2_SHIFT, 0, 0),
347d058fd9eSRahul Tanwar
348d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PCIE10, "g_pcie10", NULL, 0, CGU_GATE2,
349d058fd9eSRahul Tanwar G_PCIE10_SHIFT, 0, 0),
350d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PCIE11, "g_pcie11", NULL, 0, CGU_GATE2,
351d058fd9eSRahul Tanwar G_PCIE11_SHIFT, 0, 0),
352d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PCIE30, "g_pcie30", NULL, 0, CGU_GATE2,
353d058fd9eSRahul Tanwar G_PCIE30_SHIFT, 0, 0),
354d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PCIE31, "g_pcie31", NULL, 0, CGU_GATE2,
355d058fd9eSRahul Tanwar G_PCIE31_SHIFT, 0, 0),
356d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PCIE20, "g_pcie20", NULL, 0, CGU_GATE2,
357d058fd9eSRahul Tanwar G_PCIE20_SHIFT, 0, 0),
358d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PCIE21, "g_pcie21", NULL, 0, CGU_GATE2,
359d058fd9eSRahul Tanwar G_PCIE21_SHIFT, 0, 0),
360d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PCIE40, "g_pcie40", NULL, 0, CGU_GATE2,
361d058fd9eSRahul Tanwar G_PCIE40_SHIFT, 0, 0),
362d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PCIE41, "g_pcie41", NULL, 0, CGU_GATE2,
363d058fd9eSRahul Tanwar G_PCIE41_SHIFT, 0, 0),
364d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_XPCS0, "g_xpcs0", NULL, 0, CGU_GATE2,
365d058fd9eSRahul Tanwar G_XPCS0_SHIFT, 0, 0),
366d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_XPCS1, "g_xpcs1", NULL, 0, CGU_GATE2,
367d058fd9eSRahul Tanwar G_XPCS1_SHIFT, 0, 0),
368d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_XPCS2, "g_xpcs2", NULL, 0, CGU_GATE2,
369d058fd9eSRahul Tanwar G_XPCS2_SHIFT, 0, 0),
370d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_XPCS3, "g_xpcs3", NULL, 0, CGU_GATE2,
371d058fd9eSRahul Tanwar G_XPCS3_SHIFT, 0, 0),
372d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_SATA0, "g_sata0", NULL, 0, CGU_GATE2,
373d058fd9eSRahul Tanwar G_SATA0_SHIFT, 0, 0),
374d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_SATA1, "g_sata1", NULL, 0, CGU_GATE2,
375d058fd9eSRahul Tanwar G_SATA1_SHIFT, 0, 0),
376d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_SATA2, "g_sata2", NULL, 0, CGU_GATE2,
377d058fd9eSRahul Tanwar G_SATA2_SHIFT, 0, 0),
378d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_SATA3, "g_sata3", NULL, 0, CGU_GATE2,
379d058fd9eSRahul Tanwar G_SATA3_SHIFT, 0, 0),
380d058fd9eSRahul Tanwar
381d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_ARCEM4, "g_arcem4", NULL, 0, CGU_GATE3,
382d058fd9eSRahul Tanwar G_ARCEM4_SHIFT, 0, 0),
383d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_IDMAR1, "g_idmar1", NULL, 0, CGU_GATE3,
384d058fd9eSRahul Tanwar G_IDMAR1_SHIFT, 0, 0),
385d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_IDMAT0, "g_idmat0", NULL, 0, CGU_GATE3,
386d058fd9eSRahul Tanwar G_IDMAT0_SHIFT, 0, 0),
387d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_IDMAT1, "g_idmat1", NULL, 0, CGU_GATE3,
388d058fd9eSRahul Tanwar G_IDMAT1_SHIFT, 0, 0),
389d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_IDMAT2, "g_idmat2", NULL, 0, CGU_GATE3,
390d058fd9eSRahul Tanwar G_IDMAT2_SHIFT, 0, 0),
391d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_PPV4, "g_ppv4", NULL, 0, CGU_GATE3,
392d058fd9eSRahul Tanwar G_PPV4_SHIFT, 0, 0),
393d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_GSWIPO, "g_gswipo", "switch", 0, CGU_GATE3,
394d058fd9eSRahul Tanwar G_GSWIPO_SHIFT, 0, 0),
395d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_CQEM, "g_cqem", "switch", 0, CGU_GATE3,
396d058fd9eSRahul Tanwar G_CQEM_SHIFT, 0, 0),
397d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_XPCS5, "g_xpcs5", NULL, 0, CGU_GATE3,
398d058fd9eSRahul Tanwar G_XPCS5_SHIFT, 0, 0),
399d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_USB1, "g_usb1", NULL, 0, CGU_GATE3,
400d058fd9eSRahul Tanwar G_USB1_SHIFT, 0, 0),
401d058fd9eSRahul Tanwar LGM_GATE(LGM_GCLK_USB2, "g_usb2", NULL, 0, CGU_GATE3,
402d058fd9eSRahul Tanwar G_USB2_SHIFT, 0, 0),
403d058fd9eSRahul Tanwar };
404d058fd9eSRahul Tanwar
405d058fd9eSRahul Tanwar
406d058fd9eSRahul Tanwar static const struct lgm_clk_ddiv_data lgm_ddiv_clks[] = {
407d058fd9eSRahul Tanwar LGM_DDIV(LGM_CLK_CML, "dd_cml", "ljpll3", 0,
408d058fd9eSRahul Tanwar PLL_DIV(CGU_LJPLL3_CFG0), 0, PLL_DDIV_WIDTH,
409d058fd9eSRahul Tanwar 3, PLL_DDIV_WIDTH, 24, 1, 29, 0),
410d058fd9eSRahul Tanwar LGM_DDIV(LGM_CLK_SERDES, "dd_serdes", "ljpll3", 0,
411d058fd9eSRahul Tanwar PLL_DIV(CGU_LJPLL3_CFG0), 6, PLL_DDIV_WIDTH,
412d058fd9eSRahul Tanwar 9, PLL_DDIV_WIDTH, 25, 1, 28, 0),
413d058fd9eSRahul Tanwar LGM_DDIV(LGM_CLK_POOL, "dd_pool", "ljpll3", 0,
414d058fd9eSRahul Tanwar PLL_DIV(CGU_LJPLL3_CFG0), 12, PLL_DDIV_WIDTH,
415d058fd9eSRahul Tanwar 15, PLL_DDIV_WIDTH, 26, 1, 28, 0),
416d058fd9eSRahul Tanwar LGM_DDIV(LGM_CLK_PTP, "dd_ptp", "ljpll3", 0,
417d058fd9eSRahul Tanwar PLL_DIV(CGU_LJPLL3_CFG0), 18, PLL_DDIV_WIDTH,
418d058fd9eSRahul Tanwar 21, PLL_DDIV_WIDTH, 27, 1, 28, 0),
419d058fd9eSRahul Tanwar LGM_DDIV(LGM_CLK_PCIE, "dd_pcie", "ljpll4", 0,
420d058fd9eSRahul Tanwar PLL_DIV(CGU_LJPLL4_CFG0), 0, PLL_DDIV_WIDTH,
421d058fd9eSRahul Tanwar 3, PLL_DDIV_WIDTH, 24, 1, 29, 0),
422d058fd9eSRahul Tanwar };
423d058fd9eSRahul Tanwar
lgm_cgu_probe(struct platform_device * pdev)424d058fd9eSRahul Tanwar static int lgm_cgu_probe(struct platform_device *pdev)
425d058fd9eSRahul Tanwar {
426d058fd9eSRahul Tanwar struct lgm_clk_provider *ctx;
427d058fd9eSRahul Tanwar struct device *dev = &pdev->dev;
428d058fd9eSRahul Tanwar struct device_node *np = dev->of_node;
429d058fd9eSRahul Tanwar int ret;
430d058fd9eSRahul Tanwar
431d058fd9eSRahul Tanwar ctx = devm_kzalloc(dev, struct_size(ctx, clk_data.hws, CLK_NR_CLKS),
432d058fd9eSRahul Tanwar GFP_KERNEL);
433d058fd9eSRahul Tanwar if (!ctx)
434d058fd9eSRahul Tanwar return -ENOMEM;
435d058fd9eSRahul Tanwar
436d058fd9eSRahul Tanwar ctx->clk_data.num = CLK_NR_CLKS;
437d058fd9eSRahul Tanwar
43803617731SRahul Tanwar ctx->membase = syscon_node_to_regmap(np);
439*7256d1f4SRahul Tanwar if (IS_ERR(ctx->membase)) {
44003617731SRahul Tanwar dev_err(dev, "Failed to get clk CGU iomem\n");
441d058fd9eSRahul Tanwar return PTR_ERR(ctx->membase);
44203617731SRahul Tanwar }
44303617731SRahul Tanwar
444d058fd9eSRahul Tanwar
445d058fd9eSRahul Tanwar ctx->np = np;
446d058fd9eSRahul Tanwar ctx->dev = dev;
447d058fd9eSRahul Tanwar
448d058fd9eSRahul Tanwar ret = lgm_clk_register_plls(ctx, lgm_pll_clks,
449d058fd9eSRahul Tanwar ARRAY_SIZE(lgm_pll_clks));
450d058fd9eSRahul Tanwar if (ret)
451d058fd9eSRahul Tanwar return ret;
452d058fd9eSRahul Tanwar
453d058fd9eSRahul Tanwar ret = lgm_clk_register_branches(ctx, lgm_branch_clks,
454d058fd9eSRahul Tanwar ARRAY_SIZE(lgm_branch_clks));
455d058fd9eSRahul Tanwar if (ret)
456d058fd9eSRahul Tanwar return ret;
457d058fd9eSRahul Tanwar
458d058fd9eSRahul Tanwar ret = lgm_clk_register_ddiv(ctx, lgm_ddiv_clks,
459d058fd9eSRahul Tanwar ARRAY_SIZE(lgm_ddiv_clks));
460d058fd9eSRahul Tanwar if (ret)
461d058fd9eSRahul Tanwar return ret;
462d058fd9eSRahul Tanwar
463d058fd9eSRahul Tanwar return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
464d058fd9eSRahul Tanwar &ctx->clk_data);
465d058fd9eSRahul Tanwar }
466d058fd9eSRahul Tanwar
467d058fd9eSRahul Tanwar static const struct of_device_id of_lgm_cgu_match[] = {
468d058fd9eSRahul Tanwar { .compatible = "intel,cgu-lgm" },
469d058fd9eSRahul Tanwar {}
470d058fd9eSRahul Tanwar };
471d058fd9eSRahul Tanwar
472d058fd9eSRahul Tanwar static struct platform_driver lgm_cgu_driver = {
473d058fd9eSRahul Tanwar .probe = lgm_cgu_probe,
474d058fd9eSRahul Tanwar .driver = {
475d058fd9eSRahul Tanwar .name = "cgu-lgm",
476d058fd9eSRahul Tanwar .of_match_table = of_lgm_cgu_match,
477d058fd9eSRahul Tanwar },
478d058fd9eSRahul Tanwar };
479d058fd9eSRahul Tanwar builtin_platform_driver(lgm_cgu_driver);
480