2 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/kernel.h>
15 #include <linux/bitops.h>
16 #include <linux/err.h>
17 #include <linux/platform_device.h>
18 #include <linux/module.h>
20 #include <linux/of_device.h>
21 #include <linux/clk-provider.h>
22 #include <linux/regmap.h>
24 #include <dt-bindings/clock/qcom,lcc-msm8960.h>
27 #include "clk-regmap.h"
30 #include "clk-branch.h"
31 #include "clk-regmap-divider.h"
32 #include "clk-regmap-mux.h"
34 static struct clk_pll pll4
= {
42 .clkr
.hw
.init
= &(struct clk_init_data
){
44 .parent_names
= (const char *[]){ "pxo" },
55 static const struct parent_map lcc_pxo_pll4_map
[] = {
60 static const char * const lcc_pxo_pll4
[] = {
65 static struct freq_tbl clk_tbl_aif_osr_492
[] = {
66 { 512000, P_PLL4
, 4, 1, 240 },
67 { 768000, P_PLL4
, 4, 1, 160 },
68 { 1024000, P_PLL4
, 4, 1, 120 },
69 { 1536000, P_PLL4
, 4, 1, 80 },
70 { 2048000, P_PLL4
, 4, 1, 60 },
71 { 3072000, P_PLL4
, 4, 1, 40 },
72 { 4096000, P_PLL4
, 4, 1, 30 },
73 { 6144000, P_PLL4
, 4, 1, 20 },
74 { 8192000, P_PLL4
, 4, 1, 15 },
75 { 12288000, P_PLL4
, 4, 1, 10 },
76 { 24576000, P_PLL4
, 4, 1, 5 },
77 { 27000000, P_PXO
, 1, 0, 0 },
81 static struct freq_tbl clk_tbl_aif_osr_393
[] = {
82 { 512000, P_PLL4
, 4, 1, 192 },
83 { 768000, P_PLL4
, 4, 1, 128 },
84 { 1024000, P_PLL4
, 4, 1, 96 },
85 { 1536000, P_PLL4
, 4, 1, 64 },
86 { 2048000, P_PLL4
, 4, 1, 48 },
87 { 3072000, P_PLL4
, 4, 1, 32 },
88 { 4096000, P_PLL4
, 4, 1, 24 },
89 { 6144000, P_PLL4
, 4, 1, 16 },
90 { 8192000, P_PLL4
, 4, 1, 12 },
91 { 12288000, P_PLL4
, 4, 1, 8 },
92 { 24576000, P_PLL4
, 4, 1, 4 },
93 { 27000000, P_PXO
, 1, 0, 0 },
97 static struct clk_rcg mi2s_osr_src
= {
102 .mnctr_reset_bit
= 7,
103 .mnctr_mode_shift
= 5,
114 .parent_map
= lcc_pxo_pll4_map
,
116 .freq_tbl
= clk_tbl_aif_osr_393
,
119 .enable_mask
= BIT(9),
120 .hw
.init
= &(struct clk_init_data
){
121 .name
= "mi2s_osr_src",
122 .parent_names
= lcc_pxo_pll4
,
125 .flags
= CLK_SET_RATE_GATE
,
130 static const char * const lcc_mi2s_parents
[] = {
134 static struct clk_branch mi2s_osr_clk
= {
137 .halt_check
= BRANCH_HALT_ENABLE
,
140 .enable_mask
= BIT(17),
141 .hw
.init
= &(struct clk_init_data
){
142 .name
= "mi2s_osr_clk",
143 .parent_names
= lcc_mi2s_parents
,
145 .ops
= &clk_branch_ops
,
146 .flags
= CLK_SET_RATE_PARENT
,
151 static struct clk_regmap_div mi2s_div_clk
= {
157 .enable_mask
= BIT(15),
158 .hw
.init
= &(struct clk_init_data
){
159 .name
= "mi2s_div_clk",
160 .parent_names
= lcc_mi2s_parents
,
162 .ops
= &clk_regmap_div_ops
,
167 static struct clk_branch mi2s_bit_div_clk
= {
170 .halt_check
= BRANCH_HALT_ENABLE
,
173 .enable_mask
= BIT(15),
174 .hw
.init
= &(struct clk_init_data
){
175 .name
= "mi2s_bit_div_clk",
176 .parent_names
= (const char *[]){ "mi2s_div_clk" },
178 .ops
= &clk_branch_ops
,
179 .flags
= CLK_SET_RATE_PARENT
,
184 static struct clk_regmap_mux mi2s_bit_clk
= {
189 .hw
.init
= &(struct clk_init_data
){
190 .name
= "mi2s_bit_clk",
191 .parent_names
= (const char *[]){
196 .ops
= &clk_regmap_mux_closest_ops
,
197 .flags
= CLK_SET_RATE_PARENT
,
202 #define CLK_AIF_OSR_DIV(prefix, _ns, _md, hr) \
203 static struct clk_rcg prefix##_osr_src = { \
208 .mnctr_reset_bit = 7, \
209 .mnctr_mode_shift = 5, \
215 .pre_div_shift = 3, \
216 .pre_div_width = 2, \
219 .src_sel_shift = 0, \
220 .parent_map = lcc_pxo_pll4_map, \
222 .freq_tbl = clk_tbl_aif_osr_393, \
225 .enable_mask = BIT(9), \
226 .hw.init = &(struct clk_init_data){ \
227 .name = #prefix "_osr_src", \
228 .parent_names = lcc_pxo_pll4, \
230 .ops = &clk_rcg_ops, \
231 .flags = CLK_SET_RATE_GATE, \
236 static const char * const lcc_##prefix##_parents[] = { \
237 #prefix "_osr_src", \
240 static struct clk_branch prefix##_osr_clk = { \
243 .halt_check = BRANCH_HALT_ENABLE, \
246 .enable_mask = BIT(21), \
247 .hw.init = &(struct clk_init_data){ \
248 .name = #prefix "_osr_clk", \
249 .parent_names = lcc_##prefix##_parents, \
251 .ops = &clk_branch_ops, \
252 .flags = CLK_SET_RATE_PARENT, \
257 static struct clk_regmap_div prefix##_div_clk = { \
262 .hw.init = &(struct clk_init_data){ \
263 .name = #prefix "_div_clk", \
264 .parent_names = lcc_##prefix##_parents, \
266 .ops = &clk_regmap_div_ops, \
271 static struct clk_branch prefix##_bit_div_clk = { \
274 .halt_check = BRANCH_HALT_ENABLE, \
277 .enable_mask = BIT(19), \
278 .hw.init = &(struct clk_init_data){ \
279 .name = #prefix "_bit_div_clk", \
280 .parent_names = (const char *[]){ \
284 .ops = &clk_branch_ops, \
285 .flags = CLK_SET_RATE_PARENT, \
290 static struct clk_regmap_mux prefix##_bit_clk = { \
295 .hw.init = &(struct clk_init_data){ \
296 .name = #prefix "_bit_clk", \
297 .parent_names = (const char *[]){ \
298 #prefix "_bit_div_clk", \
299 #prefix "_codec_clk", \
302 .ops = &clk_regmap_mux_closest_ops, \
303 .flags = CLK_SET_RATE_PARENT, \
308 CLK_AIF_OSR_DIV(codec_i2s_mic
, 0x60, 0x64, 0x68);
309 CLK_AIF_OSR_DIV(spare_i2s_mic
, 0x78, 0x7c, 0x80);
310 CLK_AIF_OSR_DIV(codec_i2s_spkr
, 0x6c, 0x70, 0x74);
311 CLK_AIF_OSR_DIV(spare_i2s_spkr
, 0x84, 0x88, 0x8c);
313 static struct freq_tbl clk_tbl_pcm_492
[] = {
314 { 256000, P_PLL4
, 4, 1, 480 },
315 { 512000, P_PLL4
, 4, 1, 240 },
316 { 768000, P_PLL4
, 4, 1, 160 },
317 { 1024000, P_PLL4
, 4, 1, 120 },
318 { 1536000, P_PLL4
, 4, 1, 80 },
319 { 2048000, P_PLL4
, 4, 1, 60 },
320 { 3072000, P_PLL4
, 4, 1, 40 },
321 { 4096000, P_PLL4
, 4, 1, 30 },
322 { 6144000, P_PLL4
, 4, 1, 20 },
323 { 8192000, P_PLL4
, 4, 1, 15 },
324 { 12288000, P_PLL4
, 4, 1, 10 },
325 { 24576000, P_PLL4
, 4, 1, 5 },
326 { 27000000, P_PXO
, 1, 0, 0 },
330 static struct freq_tbl clk_tbl_pcm_393
[] = {
331 { 256000, P_PLL4
, 4, 1, 384 },
332 { 512000, P_PLL4
, 4, 1, 192 },
333 { 768000, P_PLL4
, 4, 1, 128 },
334 { 1024000, P_PLL4
, 4, 1, 96 },
335 { 1536000, P_PLL4
, 4, 1, 64 },
336 { 2048000, P_PLL4
, 4, 1, 48 },
337 { 3072000, P_PLL4
, 4, 1, 32 },
338 { 4096000, P_PLL4
, 4, 1, 24 },
339 { 6144000, P_PLL4
, 4, 1, 16 },
340 { 8192000, P_PLL4
, 4, 1, 12 },
341 { 12288000, P_PLL4
, 4, 1, 8 },
342 { 24576000, P_PLL4
, 4, 1, 4 },
343 { 27000000, P_PXO
, 1, 0, 0 },
347 static struct clk_rcg pcm_src
= {
352 .mnctr_reset_bit
= 7,
353 .mnctr_mode_shift
= 5,
364 .parent_map
= lcc_pxo_pll4_map
,
366 .freq_tbl
= clk_tbl_pcm_393
,
369 .enable_mask
= BIT(9),
370 .hw
.init
= &(struct clk_init_data
){
372 .parent_names
= lcc_pxo_pll4
,
375 .flags
= CLK_SET_RATE_GATE
,
380 static struct clk_branch pcm_clk_out
= {
383 .halt_check
= BRANCH_HALT_ENABLE
,
386 .enable_mask
= BIT(11),
387 .hw
.init
= &(struct clk_init_data
){
388 .name
= "pcm_clk_out",
389 .parent_names
= (const char *[]){ "pcm_src" },
391 .ops
= &clk_branch_ops
,
392 .flags
= CLK_SET_RATE_PARENT
,
397 static struct clk_regmap_mux pcm_clk
= {
402 .hw
.init
= &(struct clk_init_data
){
404 .parent_names
= (const char *[]){
409 .ops
= &clk_regmap_mux_closest_ops
,
410 .flags
= CLK_SET_RATE_PARENT
,
415 static struct clk_rcg slimbus_src
= {
420 .mnctr_reset_bit
= 7,
421 .mnctr_mode_shift
= 5,
432 .parent_map
= lcc_pxo_pll4_map
,
434 .freq_tbl
= clk_tbl_aif_osr_393
,
437 .enable_mask
= BIT(9),
438 .hw
.init
= &(struct clk_init_data
){
439 .name
= "slimbus_src",
440 .parent_names
= lcc_pxo_pll4
,
443 .flags
= CLK_SET_RATE_GATE
,
448 static const char * const lcc_slimbus_parents
[] = {
452 static struct clk_branch audio_slimbus_clk
= {
455 .halt_check
= BRANCH_HALT_ENABLE
,
458 .enable_mask
= BIT(10),
459 .hw
.init
= &(struct clk_init_data
){
460 .name
= "audio_slimbus_clk",
461 .parent_names
= lcc_slimbus_parents
,
463 .ops
= &clk_branch_ops
,
464 .flags
= CLK_SET_RATE_PARENT
,
469 static struct clk_branch sps_slimbus_clk
= {
472 .halt_check
= BRANCH_HALT_ENABLE
,
475 .enable_mask
= BIT(12),
476 .hw
.init
= &(struct clk_init_data
){
477 .name
= "sps_slimbus_clk",
478 .parent_names
= lcc_slimbus_parents
,
480 .ops
= &clk_branch_ops
,
481 .flags
= CLK_SET_RATE_PARENT
,
486 static struct clk_regmap
*lcc_msm8960_clks
[] = {
488 [MI2S_OSR_SRC
] = &mi2s_osr_src
.clkr
,
489 [MI2S_OSR_CLK
] = &mi2s_osr_clk
.clkr
,
490 [MI2S_DIV_CLK
] = &mi2s_div_clk
.clkr
,
491 [MI2S_BIT_DIV_CLK
] = &mi2s_bit_div_clk
.clkr
,
492 [MI2S_BIT_CLK
] = &mi2s_bit_clk
.clkr
,
493 [PCM_SRC
] = &pcm_src
.clkr
,
494 [PCM_CLK_OUT
] = &pcm_clk_out
.clkr
,
495 [PCM_CLK
] = &pcm_clk
.clkr
,
496 [SLIMBUS_SRC
] = &slimbus_src
.clkr
,
497 [AUDIO_SLIMBUS_CLK
] = &audio_slimbus_clk
.clkr
,
498 [SPS_SLIMBUS_CLK
] = &sps_slimbus_clk
.clkr
,
499 [CODEC_I2S_MIC_OSR_SRC
] = &codec_i2s_mic_osr_src
.clkr
,
500 [CODEC_I2S_MIC_OSR_CLK
] = &codec_i2s_mic_osr_clk
.clkr
,
501 [CODEC_I2S_MIC_DIV_CLK
] = &codec_i2s_mic_div_clk
.clkr
,
502 [CODEC_I2S_MIC_BIT_DIV_CLK
] = &codec_i2s_mic_bit_div_clk
.clkr
,
503 [CODEC_I2S_MIC_BIT_CLK
] = &codec_i2s_mic_bit_clk
.clkr
,
504 [SPARE_I2S_MIC_OSR_SRC
] = &spare_i2s_mic_osr_src
.clkr
,
505 [SPARE_I2S_MIC_OSR_CLK
] = &spare_i2s_mic_osr_clk
.clkr
,
506 [SPARE_I2S_MIC_DIV_CLK
] = &spare_i2s_mic_div_clk
.clkr
,
507 [SPARE_I2S_MIC_BIT_DIV_CLK
] = &spare_i2s_mic_bit_div_clk
.clkr
,
508 [SPARE_I2S_MIC_BIT_CLK
] = &spare_i2s_mic_bit_clk
.clkr
,
509 [CODEC_I2S_SPKR_OSR_SRC
] = &codec_i2s_spkr_osr_src
.clkr
,
510 [CODEC_I2S_SPKR_OSR_CLK
] = &codec_i2s_spkr_osr_clk
.clkr
,
511 [CODEC_I2S_SPKR_DIV_CLK
] = &codec_i2s_spkr_div_clk
.clkr
,
512 [CODEC_I2S_SPKR_BIT_DIV_CLK
] = &codec_i2s_spkr_bit_div_clk
.clkr
,
513 [CODEC_I2S_SPKR_BIT_CLK
] = &codec_i2s_spkr_bit_clk
.clkr
,
514 [SPARE_I2S_SPKR_OSR_SRC
] = &spare_i2s_spkr_osr_src
.clkr
,
515 [SPARE_I2S_SPKR_OSR_CLK
] = &spare_i2s_spkr_osr_clk
.clkr
,
516 [SPARE_I2S_SPKR_DIV_CLK
] = &spare_i2s_spkr_div_clk
.clkr
,
517 [SPARE_I2S_SPKR_BIT_DIV_CLK
] = &spare_i2s_spkr_bit_div_clk
.clkr
,
518 [SPARE_I2S_SPKR_BIT_CLK
] = &spare_i2s_spkr_bit_clk
.clkr
,
521 static const struct regmap_config lcc_msm8960_regmap_config
= {
525 .max_register
= 0xfc,
529 static const struct qcom_cc_desc lcc_msm8960_desc
= {
530 .config
= &lcc_msm8960_regmap_config
,
531 .clks
= lcc_msm8960_clks
,
532 .num_clks
= ARRAY_SIZE(lcc_msm8960_clks
),
535 static const struct of_device_id lcc_msm8960_match_table
[] = {
536 { .compatible
= "qcom,lcc-msm8960" },
537 { .compatible
= "qcom,lcc-apq8064" },
540 MODULE_DEVICE_TABLE(of
, lcc_msm8960_match_table
);
542 static int lcc_msm8960_probe(struct platform_device
*pdev
)
545 struct regmap
*regmap
;
547 regmap
= qcom_cc_map(pdev
, &lcc_msm8960_desc
);
549 return PTR_ERR(regmap
);
551 /* Use the correct frequency plan depending on speed of PLL4 */
552 regmap_read(regmap
, 0x4, &val
);
554 slimbus_src
.freq_tbl
= clk_tbl_aif_osr_492
;
555 mi2s_osr_src
.freq_tbl
= clk_tbl_aif_osr_492
;
556 codec_i2s_mic_osr_src
.freq_tbl
= clk_tbl_aif_osr_492
;
557 spare_i2s_mic_osr_src
.freq_tbl
= clk_tbl_aif_osr_492
;
558 codec_i2s_spkr_osr_src
.freq_tbl
= clk_tbl_aif_osr_492
;
559 spare_i2s_spkr_osr_src
.freq_tbl
= clk_tbl_aif_osr_492
;
560 pcm_src
.freq_tbl
= clk_tbl_pcm_492
;
562 /* Enable PLL4 source on the LPASS Primary PLL Mux */
563 regmap_write(regmap
, 0xc4, 0x1);
565 return qcom_cc_really_probe(pdev
, &lcc_msm8960_desc
, regmap
);
568 static struct platform_driver lcc_msm8960_driver
= {
569 .probe
= lcc_msm8960_probe
,
571 .name
= "lcc-msm8960",
572 .of_match_table
= lcc_msm8960_match_table
,
575 module_platform_driver(lcc_msm8960_driver
);
577 MODULE_DESCRIPTION("QCOM LCC MSM8960 Driver");
578 MODULE_LICENSE("GPL v2");
579 MODULE_ALIAS("platform:lcc-msm8960");