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-msm8960.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" },
47 static const struct parent_map lcc_pxo_pll4_map
[] = {
52 static const char * const lcc_pxo_pll4
[] = {
57 static struct freq_tbl clk_tbl_aif_osr_492
[] = {
58 { 512000, P_PLL4
, 4, 1, 240 },
59 { 768000, P_PLL4
, 4, 1, 160 },
60 { 1024000, P_PLL4
, 4, 1, 120 },
61 { 1536000, P_PLL4
, 4, 1, 80 },
62 { 2048000, P_PLL4
, 4, 1, 60 },
63 { 3072000, P_PLL4
, 4, 1, 40 },
64 { 4096000, P_PLL4
, 4, 1, 30 },
65 { 6144000, P_PLL4
, 4, 1, 20 },
66 { 8192000, P_PLL4
, 4, 1, 15 },
67 { 12288000, P_PLL4
, 4, 1, 10 },
68 { 24576000, P_PLL4
, 4, 1, 5 },
69 { 27000000, P_PXO
, 1, 0, 0 },
73 static struct freq_tbl clk_tbl_aif_osr_393
[] = {
74 { 512000, P_PLL4
, 4, 1, 192 },
75 { 768000, P_PLL4
, 4, 1, 128 },
76 { 1024000, P_PLL4
, 4, 1, 96 },
77 { 1536000, P_PLL4
, 4, 1, 64 },
78 { 2048000, P_PLL4
, 4, 1, 48 },
79 { 3072000, P_PLL4
, 4, 1, 32 },
80 { 4096000, P_PLL4
, 4, 1, 24 },
81 { 6144000, P_PLL4
, 4, 1, 16 },
82 { 8192000, P_PLL4
, 4, 1, 12 },
83 { 12288000, P_PLL4
, 4, 1, 8 },
84 { 24576000, P_PLL4
, 4, 1, 4 },
85 { 27000000, P_PXO
, 1, 0, 0 },
89 static struct clk_rcg mi2s_osr_src
= {
95 .mnctr_mode_shift
= 5,
106 .parent_map
= lcc_pxo_pll4_map
,
108 .freq_tbl
= clk_tbl_aif_osr_393
,
111 .enable_mask
= BIT(9),
112 .hw
.init
= &(struct clk_init_data
){
113 .name
= "mi2s_osr_src",
114 .parent_names
= lcc_pxo_pll4
,
117 .flags
= CLK_SET_RATE_GATE
,
122 static const char * const lcc_mi2s_parents
[] = {
126 static struct clk_branch mi2s_osr_clk
= {
129 .halt_check
= BRANCH_HALT_ENABLE
,
132 .enable_mask
= BIT(17),
133 .hw
.init
= &(struct clk_init_data
){
134 .name
= "mi2s_osr_clk",
135 .parent_names
= lcc_mi2s_parents
,
137 .ops
= &clk_branch_ops
,
138 .flags
= CLK_SET_RATE_PARENT
,
143 static struct clk_regmap_div mi2s_div_clk
= {
149 .enable_mask
= BIT(15),
150 .hw
.init
= &(struct clk_init_data
){
151 .name
= "mi2s_div_clk",
152 .parent_names
= lcc_mi2s_parents
,
154 .ops
= &clk_regmap_div_ops
,
159 static struct clk_branch mi2s_bit_div_clk
= {
162 .halt_check
= BRANCH_HALT_ENABLE
,
165 .enable_mask
= BIT(15),
166 .hw
.init
= &(struct clk_init_data
){
167 .name
= "mi2s_bit_div_clk",
168 .parent_names
= (const char *[]){ "mi2s_div_clk" },
170 .ops
= &clk_branch_ops
,
171 .flags
= CLK_SET_RATE_PARENT
,
176 static struct clk_regmap_mux mi2s_bit_clk
= {
181 .hw
.init
= &(struct clk_init_data
){
182 .name
= "mi2s_bit_clk",
183 .parent_names
= (const char *[]){
188 .ops
= &clk_regmap_mux_closest_ops
,
189 .flags
= CLK_SET_RATE_PARENT
,
194 #define CLK_AIF_OSR_DIV(prefix, _ns, _md, hr) \
195 static struct clk_rcg prefix##_osr_src = { \
200 .mnctr_reset_bit = 7, \
201 .mnctr_mode_shift = 5, \
207 .pre_div_shift = 3, \
208 .pre_div_width = 2, \
211 .src_sel_shift = 0, \
212 .parent_map = lcc_pxo_pll4_map, \
214 .freq_tbl = clk_tbl_aif_osr_393, \
217 .enable_mask = BIT(9), \
218 .hw.init = &(struct clk_init_data){ \
219 .name = #prefix "_osr_src", \
220 .parent_names = lcc_pxo_pll4, \
222 .ops = &clk_rcg_ops, \
223 .flags = CLK_SET_RATE_GATE, \
228 static const char * const lcc_##prefix##_parents[] = { \
229 #prefix "_osr_src", \
232 static struct clk_branch prefix##_osr_clk = { \
235 .halt_check = BRANCH_HALT_ENABLE, \
238 .enable_mask = BIT(21), \
239 .hw.init = &(struct clk_init_data){ \
240 .name = #prefix "_osr_clk", \
241 .parent_names = lcc_##prefix##_parents, \
243 .ops = &clk_branch_ops, \
244 .flags = CLK_SET_RATE_PARENT, \
249 static struct clk_regmap_div prefix##_div_clk = { \
254 .hw.init = &(struct clk_init_data){ \
255 .name = #prefix "_div_clk", \
256 .parent_names = lcc_##prefix##_parents, \
258 .ops = &clk_regmap_div_ops, \
263 static struct clk_branch prefix##_bit_div_clk = { \
266 .halt_check = BRANCH_HALT_ENABLE, \
269 .enable_mask = BIT(19), \
270 .hw.init = &(struct clk_init_data){ \
271 .name = #prefix "_bit_div_clk", \
272 .parent_names = (const char *[]){ \
276 .ops = &clk_branch_ops, \
277 .flags = CLK_SET_RATE_PARENT, \
282 static struct clk_regmap_mux prefix##_bit_clk = { \
287 .hw.init = &(struct clk_init_data){ \
288 .name = #prefix "_bit_clk", \
289 .parent_names = (const char *[]){ \
290 #prefix "_bit_div_clk", \
291 #prefix "_codec_clk", \
294 .ops = &clk_regmap_mux_closest_ops, \
295 .flags = CLK_SET_RATE_PARENT, \
300 CLK_AIF_OSR_DIV(codec_i2s_mic
, 0x60, 0x64, 0x68);
301 CLK_AIF_OSR_DIV(spare_i2s_mic
, 0x78, 0x7c, 0x80);
302 CLK_AIF_OSR_DIV(codec_i2s_spkr
, 0x6c, 0x70, 0x74);
303 CLK_AIF_OSR_DIV(spare_i2s_spkr
, 0x84, 0x88, 0x8c);
305 static struct freq_tbl clk_tbl_pcm_492
[] = {
306 { 256000, P_PLL4
, 4, 1, 480 },
307 { 512000, P_PLL4
, 4, 1, 240 },
308 { 768000, P_PLL4
, 4, 1, 160 },
309 { 1024000, P_PLL4
, 4, 1, 120 },
310 { 1536000, P_PLL4
, 4, 1, 80 },
311 { 2048000, P_PLL4
, 4, 1, 60 },
312 { 3072000, P_PLL4
, 4, 1, 40 },
313 { 4096000, P_PLL4
, 4, 1, 30 },
314 { 6144000, P_PLL4
, 4, 1, 20 },
315 { 8192000, P_PLL4
, 4, 1, 15 },
316 { 12288000, P_PLL4
, 4, 1, 10 },
317 { 24576000, P_PLL4
, 4, 1, 5 },
318 { 27000000, P_PXO
, 1, 0, 0 },
322 static struct freq_tbl clk_tbl_pcm_393
[] = {
323 { 256000, P_PLL4
, 4, 1, 384 },
324 { 512000, P_PLL4
, 4, 1, 192 },
325 { 768000, P_PLL4
, 4, 1, 128 },
326 { 1024000, P_PLL4
, 4, 1, 96 },
327 { 1536000, P_PLL4
, 4, 1, 64 },
328 { 2048000, P_PLL4
, 4, 1, 48 },
329 { 3072000, P_PLL4
, 4, 1, 32 },
330 { 4096000, P_PLL4
, 4, 1, 24 },
331 { 6144000, P_PLL4
, 4, 1, 16 },
332 { 8192000, P_PLL4
, 4, 1, 12 },
333 { 12288000, P_PLL4
, 4, 1, 8 },
334 { 24576000, P_PLL4
, 4, 1, 4 },
335 { 27000000, P_PXO
, 1, 0, 0 },
339 static struct clk_rcg pcm_src
= {
344 .mnctr_reset_bit
= 7,
345 .mnctr_mode_shift
= 5,
356 .parent_map
= lcc_pxo_pll4_map
,
358 .freq_tbl
= clk_tbl_pcm_393
,
361 .enable_mask
= BIT(9),
362 .hw
.init
= &(struct clk_init_data
){
364 .parent_names
= lcc_pxo_pll4
,
367 .flags
= CLK_SET_RATE_GATE
,
372 static struct clk_branch pcm_clk_out
= {
375 .halt_check
= BRANCH_HALT_ENABLE
,
378 .enable_mask
= BIT(11),
379 .hw
.init
= &(struct clk_init_data
){
380 .name
= "pcm_clk_out",
381 .parent_names
= (const char *[]){ "pcm_src" },
383 .ops
= &clk_branch_ops
,
384 .flags
= CLK_SET_RATE_PARENT
,
389 static struct clk_regmap_mux pcm_clk
= {
394 .hw
.init
= &(struct clk_init_data
){
396 .parent_names
= (const char *[]){
401 .ops
= &clk_regmap_mux_closest_ops
,
402 .flags
= CLK_SET_RATE_PARENT
,
407 static struct clk_rcg slimbus_src
= {
412 .mnctr_reset_bit
= 7,
413 .mnctr_mode_shift
= 5,
424 .parent_map
= lcc_pxo_pll4_map
,
426 .freq_tbl
= clk_tbl_aif_osr_393
,
429 .enable_mask
= BIT(9),
430 .hw
.init
= &(struct clk_init_data
){
431 .name
= "slimbus_src",
432 .parent_names
= lcc_pxo_pll4
,
435 .flags
= CLK_SET_RATE_GATE
,
440 static const char * const lcc_slimbus_parents
[] = {
444 static struct clk_branch audio_slimbus_clk
= {
447 .halt_check
= BRANCH_HALT_ENABLE
,
450 .enable_mask
= BIT(10),
451 .hw
.init
= &(struct clk_init_data
){
452 .name
= "audio_slimbus_clk",
453 .parent_names
= lcc_slimbus_parents
,
455 .ops
= &clk_branch_ops
,
456 .flags
= CLK_SET_RATE_PARENT
,
461 static struct clk_branch sps_slimbus_clk
= {
464 .halt_check
= BRANCH_HALT_ENABLE
,
467 .enable_mask
= BIT(12),
468 .hw
.init
= &(struct clk_init_data
){
469 .name
= "sps_slimbus_clk",
470 .parent_names
= lcc_slimbus_parents
,
472 .ops
= &clk_branch_ops
,
473 .flags
= CLK_SET_RATE_PARENT
,
478 static struct clk_regmap
*lcc_msm8960_clks
[] = {
480 [MI2S_OSR_SRC
] = &mi2s_osr_src
.clkr
,
481 [MI2S_OSR_CLK
] = &mi2s_osr_clk
.clkr
,
482 [MI2S_DIV_CLK
] = &mi2s_div_clk
.clkr
,
483 [MI2S_BIT_DIV_CLK
] = &mi2s_bit_div_clk
.clkr
,
484 [MI2S_BIT_CLK
] = &mi2s_bit_clk
.clkr
,
485 [PCM_SRC
] = &pcm_src
.clkr
,
486 [PCM_CLK_OUT
] = &pcm_clk_out
.clkr
,
487 [PCM_CLK
] = &pcm_clk
.clkr
,
488 [SLIMBUS_SRC
] = &slimbus_src
.clkr
,
489 [AUDIO_SLIMBUS_CLK
] = &audio_slimbus_clk
.clkr
,
490 [SPS_SLIMBUS_CLK
] = &sps_slimbus_clk
.clkr
,
491 [CODEC_I2S_MIC_OSR_SRC
] = &codec_i2s_mic_osr_src
.clkr
,
492 [CODEC_I2S_MIC_OSR_CLK
] = &codec_i2s_mic_osr_clk
.clkr
,
493 [CODEC_I2S_MIC_DIV_CLK
] = &codec_i2s_mic_div_clk
.clkr
,
494 [CODEC_I2S_MIC_BIT_DIV_CLK
] = &codec_i2s_mic_bit_div_clk
.clkr
,
495 [CODEC_I2S_MIC_BIT_CLK
] = &codec_i2s_mic_bit_clk
.clkr
,
496 [SPARE_I2S_MIC_OSR_SRC
] = &spare_i2s_mic_osr_src
.clkr
,
497 [SPARE_I2S_MIC_OSR_CLK
] = &spare_i2s_mic_osr_clk
.clkr
,
498 [SPARE_I2S_MIC_DIV_CLK
] = &spare_i2s_mic_div_clk
.clkr
,
499 [SPARE_I2S_MIC_BIT_DIV_CLK
] = &spare_i2s_mic_bit_div_clk
.clkr
,
500 [SPARE_I2S_MIC_BIT_CLK
] = &spare_i2s_mic_bit_clk
.clkr
,
501 [CODEC_I2S_SPKR_OSR_SRC
] = &codec_i2s_spkr_osr_src
.clkr
,
502 [CODEC_I2S_SPKR_OSR_CLK
] = &codec_i2s_spkr_osr_clk
.clkr
,
503 [CODEC_I2S_SPKR_DIV_CLK
] = &codec_i2s_spkr_div_clk
.clkr
,
504 [CODEC_I2S_SPKR_BIT_DIV_CLK
] = &codec_i2s_spkr_bit_div_clk
.clkr
,
505 [CODEC_I2S_SPKR_BIT_CLK
] = &codec_i2s_spkr_bit_clk
.clkr
,
506 [SPARE_I2S_SPKR_OSR_SRC
] = &spare_i2s_spkr_osr_src
.clkr
,
507 [SPARE_I2S_SPKR_OSR_CLK
] = &spare_i2s_spkr_osr_clk
.clkr
,
508 [SPARE_I2S_SPKR_DIV_CLK
] = &spare_i2s_spkr_div_clk
.clkr
,
509 [SPARE_I2S_SPKR_BIT_DIV_CLK
] = &spare_i2s_spkr_bit_div_clk
.clkr
,
510 [SPARE_I2S_SPKR_BIT_CLK
] = &spare_i2s_spkr_bit_clk
.clkr
,
513 static const struct regmap_config lcc_msm8960_regmap_config
= {
517 .max_register
= 0xfc,
521 static const struct qcom_cc_desc lcc_msm8960_desc
= {
522 .config
= &lcc_msm8960_regmap_config
,
523 .clks
= lcc_msm8960_clks
,
524 .num_clks
= ARRAY_SIZE(lcc_msm8960_clks
),
527 static const struct of_device_id lcc_msm8960_match_table
[] = {
528 { .compatible
= "qcom,lcc-msm8960" },
529 { .compatible
= "qcom,lcc-apq8064" },
532 MODULE_DEVICE_TABLE(of
, lcc_msm8960_match_table
);
534 static int lcc_msm8960_probe(struct platform_device
*pdev
)
537 struct regmap
*regmap
;
539 regmap
= qcom_cc_map(pdev
, &lcc_msm8960_desc
);
541 return PTR_ERR(regmap
);
543 /* Use the correct frequency plan depending on speed of PLL4 */
544 regmap_read(regmap
, 0x4, &val
);
546 slimbus_src
.freq_tbl
= clk_tbl_aif_osr_492
;
547 mi2s_osr_src
.freq_tbl
= clk_tbl_aif_osr_492
;
548 codec_i2s_mic_osr_src
.freq_tbl
= clk_tbl_aif_osr_492
;
549 spare_i2s_mic_osr_src
.freq_tbl
= clk_tbl_aif_osr_492
;
550 codec_i2s_spkr_osr_src
.freq_tbl
= clk_tbl_aif_osr_492
;
551 spare_i2s_spkr_osr_src
.freq_tbl
= clk_tbl_aif_osr_492
;
552 pcm_src
.freq_tbl
= clk_tbl_pcm_492
;
554 /* Enable PLL4 source on the LPASS Primary PLL Mux */
555 regmap_write(regmap
, 0xc4, 0x1);
557 return qcom_cc_really_probe(pdev
, &lcc_msm8960_desc
, regmap
);
560 static struct platform_driver lcc_msm8960_driver
= {
561 .probe
= lcc_msm8960_probe
,
563 .name
= "lcc-msm8960",
564 .of_match_table
= lcc_msm8960_match_table
,
567 module_platform_driver(lcc_msm8960_driver
);
569 MODULE_DESCRIPTION("QCOM LCC MSM8960 Driver");
570 MODULE_LICENSE("GPL v2");
571 MODULE_ALIAS("platform:lcc-msm8960");