1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
6 #include <linux/kernel.h>
7 #include <linux/bitops.h>
9 #include <linux/platform_device.h>
10 #include <linux/module.h>
12 #include <linux/of_device.h>
13 #include <linux/clk-provider.h>
14 #include <linux/regmap.h>
16 #include <dt-bindings/clock/qcom,lcc-ipq806x.h>
19 #include "clk-regmap.h"
22 #include "clk-branch.h"
23 #include "clk-regmap-divider.h"
24 #include "clk-regmap-mux.h"
26 static struct clk_pll pll4
= {
34 .clkr
.hw
.init
= &(struct clk_init_data
){
36 .parent_names
= (const char *[]){ "pxo" },
42 static const struct pll_config pll4_config
= {
47 .vco_mask
= BIT(17) | BIT(16),
49 .pre_div_mask
= BIT(19),
51 .post_div_mask
= BIT(21) | BIT(20),
52 .mn_ena_mask
= BIT(22),
53 .main_output_mask
= BIT(23),
61 static const struct parent_map lcc_pxo_pll4_map
[] = {
66 static const char * const lcc_pxo_pll4
[] = {
71 static struct freq_tbl clk_tbl_aif_mi2s
[] = {
72 { 1024000, P_PLL4
, 4, 1, 96 },
73 { 1411200, P_PLL4
, 4, 2, 139 },
74 { 1536000, P_PLL4
, 4, 1, 64 },
75 { 2048000, P_PLL4
, 4, 1, 48 },
76 { 2116800, P_PLL4
, 4, 2, 93 },
77 { 2304000, P_PLL4
, 4, 2, 85 },
78 { 2822400, P_PLL4
, 4, 6, 209 },
79 { 3072000, P_PLL4
, 4, 1, 32 },
80 { 3175200, P_PLL4
, 4, 1, 31 },
81 { 4096000, P_PLL4
, 4, 1, 24 },
82 { 4233600, P_PLL4
, 4, 9, 209 },
83 { 4608000, P_PLL4
, 4, 3, 64 },
84 { 5644800, P_PLL4
, 4, 12, 209 },
85 { 6144000, P_PLL4
, 4, 1, 16 },
86 { 6350400, P_PLL4
, 4, 2, 31 },
87 { 8192000, P_PLL4
, 4, 1, 12 },
88 { 8467200, P_PLL4
, 4, 18, 209 },
89 { 9216000, P_PLL4
, 4, 3, 32 },
90 { 11289600, P_PLL4
, 4, 24, 209 },
91 { 12288000, P_PLL4
, 4, 1, 8 },
92 { 12700800, P_PLL4
, 4, 27, 209 },
93 { 13824000, P_PLL4
, 4, 9, 64 },
94 { 16384000, P_PLL4
, 4, 1, 6 },
95 { 16934400, P_PLL4
, 4, 41, 238 },
96 { 18432000, P_PLL4
, 4, 3, 16 },
97 { 22579200, P_PLL4
, 2, 24, 209 },
98 { 24576000, P_PLL4
, 4, 1, 4 },
99 { 27648000, P_PLL4
, 4, 9, 32 },
100 { 33868800, P_PLL4
, 4, 41, 119 },
101 { 36864000, P_PLL4
, 4, 3, 8 },
102 { 45158400, P_PLL4
, 1, 24, 209 },
103 { 49152000, P_PLL4
, 4, 1, 2 },
104 { 50803200, P_PLL4
, 1, 27, 209 },
108 static struct clk_rcg mi2s_osr_src
= {
113 .mnctr_reset_bit
= 7,
114 .mnctr_mode_shift
= 5,
125 .parent_map
= lcc_pxo_pll4_map
,
127 .freq_tbl
= clk_tbl_aif_mi2s
,
130 .enable_mask
= BIT(9),
131 .hw
.init
= &(struct clk_init_data
){
132 .name
= "mi2s_osr_src",
133 .parent_names
= lcc_pxo_pll4
,
136 .flags
= CLK_SET_RATE_GATE
,
141 static const char * const lcc_mi2s_parents
[] = {
145 static struct clk_branch mi2s_osr_clk
= {
148 .halt_check
= BRANCH_HALT_ENABLE
,
151 .enable_mask
= BIT(17),
152 .hw
.init
= &(struct clk_init_data
){
153 .name
= "mi2s_osr_clk",
154 .parent_names
= lcc_mi2s_parents
,
156 .ops
= &clk_branch_ops
,
157 .flags
= CLK_SET_RATE_PARENT
,
162 static struct clk_regmap_div mi2s_div_clk
= {
167 .hw
.init
= &(struct clk_init_data
){
168 .name
= "mi2s_div_clk",
169 .parent_names
= lcc_mi2s_parents
,
171 .ops
= &clk_regmap_div_ops
,
176 static struct clk_branch mi2s_bit_div_clk
= {
179 .halt_check
= BRANCH_HALT_ENABLE
,
182 .enable_mask
= BIT(15),
183 .hw
.init
= &(struct clk_init_data
){
184 .name
= "mi2s_bit_div_clk",
185 .parent_names
= (const char *[]){ "mi2s_div_clk" },
187 .ops
= &clk_branch_ops
,
188 .flags
= CLK_SET_RATE_PARENT
,
194 static struct clk_regmap_mux mi2s_bit_clk
= {
199 .hw
.init
= &(struct clk_init_data
){
200 .name
= "mi2s_bit_clk",
201 .parent_names
= (const char *[]){
206 .ops
= &clk_regmap_mux_closest_ops
,
207 .flags
= CLK_SET_RATE_PARENT
,
212 static struct freq_tbl clk_tbl_pcm
[] = {
213 { 64000, P_PLL4
, 4, 1, 1536 },
214 { 128000, P_PLL4
, 4, 1, 768 },
215 { 256000, P_PLL4
, 4, 1, 384 },
216 { 512000, P_PLL4
, 4, 1, 192 },
217 { 1024000, P_PLL4
, 4, 1, 96 },
218 { 2048000, P_PLL4
, 4, 1, 48 },
222 static struct clk_rcg pcm_src
= {
227 .mnctr_reset_bit
= 7,
228 .mnctr_mode_shift
= 5,
239 .parent_map
= lcc_pxo_pll4_map
,
241 .freq_tbl
= clk_tbl_pcm
,
244 .enable_mask
= BIT(9),
245 .hw
.init
= &(struct clk_init_data
){
247 .parent_names
= lcc_pxo_pll4
,
250 .flags
= CLK_SET_RATE_GATE
,
255 static struct clk_branch pcm_clk_out
= {
258 .halt_check
= BRANCH_HALT_ENABLE
,
261 .enable_mask
= BIT(11),
262 .hw
.init
= &(struct clk_init_data
){
263 .name
= "pcm_clk_out",
264 .parent_names
= (const char *[]){ "pcm_src" },
266 .ops
= &clk_branch_ops
,
267 .flags
= CLK_SET_RATE_PARENT
,
272 static struct clk_regmap_mux pcm_clk
= {
277 .hw
.init
= &(struct clk_init_data
){
279 .parent_names
= (const char *[]){
284 .ops
= &clk_regmap_mux_closest_ops
,
285 .flags
= CLK_SET_RATE_PARENT
,
290 static struct freq_tbl clk_tbl_aif_osr
[] = {
291 { 2822400, P_PLL4
, 1, 147, 20480 },
292 { 4096000, P_PLL4
, 1, 1, 96 },
293 { 5644800, P_PLL4
, 1, 147, 10240 },
294 { 6144000, P_PLL4
, 1, 1, 64 },
295 { 11289600, P_PLL4
, 1, 147, 5120 },
296 { 12288000, P_PLL4
, 1, 1, 32 },
297 { 22579200, P_PLL4
, 1, 147, 2560 },
298 { 24576000, P_PLL4
, 1, 1, 16 },
302 static struct clk_rcg spdif_src
= {
307 .mnctr_reset_bit
= 7,
308 .mnctr_mode_shift
= 5,
319 .parent_map
= lcc_pxo_pll4_map
,
321 .freq_tbl
= clk_tbl_aif_osr
,
324 .enable_mask
= BIT(9),
325 .hw
.init
= &(struct clk_init_data
){
327 .parent_names
= lcc_pxo_pll4
,
330 .flags
= CLK_SET_RATE_GATE
,
335 static const char * const lcc_spdif_parents
[] = {
339 static struct clk_branch spdif_clk
= {
342 .halt_check
= BRANCH_HALT_ENABLE
,
345 .enable_mask
= BIT(12),
346 .hw
.init
= &(struct clk_init_data
){
348 .parent_names
= lcc_spdif_parents
,
350 .ops
= &clk_branch_ops
,
351 .flags
= CLK_SET_RATE_PARENT
,
356 static struct freq_tbl clk_tbl_ahbix
[] = {
357 { 131072000, P_PLL4
, 1, 1, 3 },
361 static struct clk_rcg ahbix_clk
= {
366 .mnctr_reset_bit
= 7,
367 .mnctr_mode_shift
= 5,
378 .parent_map
= lcc_pxo_pll4_map
,
380 .freq_tbl
= clk_tbl_ahbix
,
383 .enable_mask
= BIT(11),
384 .hw
.init
= &(struct clk_init_data
){
386 .parent_names
= lcc_pxo_pll4
,
388 .ops
= &clk_rcg_lcc_ops
,
393 static struct clk_regmap
*lcc_ipq806x_clks
[] = {
395 [MI2S_OSR_SRC
] = &mi2s_osr_src
.clkr
,
396 [MI2S_OSR_CLK
] = &mi2s_osr_clk
.clkr
,
397 [MI2S_DIV_CLK
] = &mi2s_div_clk
.clkr
,
398 [MI2S_BIT_DIV_CLK
] = &mi2s_bit_div_clk
.clkr
,
399 [MI2S_BIT_CLK
] = &mi2s_bit_clk
.clkr
,
400 [PCM_SRC
] = &pcm_src
.clkr
,
401 [PCM_CLK_OUT
] = &pcm_clk_out
.clkr
,
402 [PCM_CLK
] = &pcm_clk
.clkr
,
403 [SPDIF_SRC
] = &spdif_src
.clkr
,
404 [SPDIF_CLK
] = &spdif_clk
.clkr
,
405 [AHBIX_CLK
] = &ahbix_clk
.clkr
,
408 static const struct regmap_config lcc_ipq806x_regmap_config
= {
412 .max_register
= 0xfc,
416 static const struct qcom_cc_desc lcc_ipq806x_desc
= {
417 .config
= &lcc_ipq806x_regmap_config
,
418 .clks
= lcc_ipq806x_clks
,
419 .num_clks
= ARRAY_SIZE(lcc_ipq806x_clks
),
422 static const struct of_device_id lcc_ipq806x_match_table
[] = {
423 { .compatible
= "qcom,lcc-ipq8064" },
426 MODULE_DEVICE_TABLE(of
, lcc_ipq806x_match_table
);
428 static int lcc_ipq806x_probe(struct platform_device
*pdev
)
431 struct regmap
*regmap
;
433 regmap
= qcom_cc_map(pdev
, &lcc_ipq806x_desc
);
435 return PTR_ERR(regmap
);
437 /* Configure the rate of PLL4 if the bootloader hasn't already */
438 regmap_read(regmap
, 0x0, &val
);
440 clk_pll_configure_sr(&pll4
, regmap
, &pll4_config
, true);
441 /* Enable PLL4 source on the LPASS Primary PLL Mux */
442 regmap_write(regmap
, 0xc4, 0x1);
444 return qcom_cc_really_probe(pdev
, &lcc_ipq806x_desc
, regmap
);
447 static struct platform_driver lcc_ipq806x_driver
= {
448 .probe
= lcc_ipq806x_probe
,
450 .name
= "lcc-ipq806x",
451 .of_match_table
= lcc_ipq806x_match_table
,
454 module_platform_driver(lcc_ipq806x_driver
);
456 MODULE_DESCRIPTION("QCOM LCC IPQ806x Driver");
457 MODULE_LICENSE("GPL v2");
458 MODULE_ALIAS("platform:lcc-ipq806x");