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-ipq806x.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" },
50 static const struct pll_config pll4_config
= {
55 .vco_mask
= BIT(17) | BIT(16),
57 .pre_div_mask
= BIT(19),
59 .post_div_mask
= BIT(21) | BIT(20),
60 .mn_ena_mask
= BIT(22),
61 .main_output_mask
= BIT(23),
69 static const struct parent_map lcc_pxo_pll4_map
[] = {
74 static const char * const lcc_pxo_pll4
[] = {
79 static struct freq_tbl clk_tbl_aif_mi2s
[] = {
80 { 1024000, P_PLL4
, 4, 1, 96 },
81 { 1411200, P_PLL4
, 4, 2, 139 },
82 { 1536000, P_PLL4
, 4, 1, 64 },
83 { 2048000, P_PLL4
, 4, 1, 48 },
84 { 2116800, P_PLL4
, 4, 2, 93 },
85 { 2304000, P_PLL4
, 4, 2, 85 },
86 { 2822400, P_PLL4
, 4, 6, 209 },
87 { 3072000, P_PLL4
, 4, 1, 32 },
88 { 3175200, P_PLL4
, 4, 1, 31 },
89 { 4096000, P_PLL4
, 4, 1, 24 },
90 { 4233600, P_PLL4
, 4, 9, 209 },
91 { 4608000, P_PLL4
, 4, 3, 64 },
92 { 5644800, P_PLL4
, 4, 12, 209 },
93 { 6144000, P_PLL4
, 4, 1, 16 },
94 { 6350400, P_PLL4
, 4, 2, 31 },
95 { 8192000, P_PLL4
, 4, 1, 12 },
96 { 8467200, P_PLL4
, 4, 18, 209 },
97 { 9216000, P_PLL4
, 4, 3, 32 },
98 { 11289600, P_PLL4
, 4, 24, 209 },
99 { 12288000, P_PLL4
, 4, 1, 8 },
100 { 12700800, P_PLL4
, 4, 27, 209 },
101 { 13824000, P_PLL4
, 4, 9, 64 },
102 { 16384000, P_PLL4
, 4, 1, 6 },
103 { 16934400, P_PLL4
, 4, 41, 238 },
104 { 18432000, P_PLL4
, 4, 3, 16 },
105 { 22579200, P_PLL4
, 2, 24, 209 },
106 { 24576000, P_PLL4
, 4, 1, 4 },
107 { 27648000, P_PLL4
, 4, 9, 32 },
108 { 33868800, P_PLL4
, 4, 41, 119 },
109 { 36864000, P_PLL4
, 4, 3, 8 },
110 { 45158400, P_PLL4
, 1, 24, 209 },
111 { 49152000, P_PLL4
, 4, 1, 2 },
112 { 50803200, P_PLL4
, 1, 27, 209 },
116 static struct clk_rcg mi2s_osr_src
= {
121 .mnctr_reset_bit
= 7,
122 .mnctr_mode_shift
= 5,
133 .parent_map
= lcc_pxo_pll4_map
,
135 .freq_tbl
= clk_tbl_aif_mi2s
,
138 .enable_mask
= BIT(9),
139 .hw
.init
= &(struct clk_init_data
){
140 .name
= "mi2s_osr_src",
141 .parent_names
= lcc_pxo_pll4
,
144 .flags
= CLK_SET_RATE_GATE
,
149 static const char * const lcc_mi2s_parents
[] = {
153 static struct clk_branch mi2s_osr_clk
= {
156 .halt_check
= BRANCH_HALT_ENABLE
,
159 .enable_mask
= BIT(17),
160 .hw
.init
= &(struct clk_init_data
){
161 .name
= "mi2s_osr_clk",
162 .parent_names
= lcc_mi2s_parents
,
164 .ops
= &clk_branch_ops
,
165 .flags
= CLK_SET_RATE_PARENT
,
170 static struct clk_regmap_div mi2s_div_clk
= {
175 .hw
.init
= &(struct clk_init_data
){
176 .name
= "mi2s_div_clk",
177 .parent_names
= lcc_mi2s_parents
,
179 .ops
= &clk_regmap_div_ops
,
184 static struct clk_branch mi2s_bit_div_clk
= {
187 .halt_check
= BRANCH_HALT_ENABLE
,
190 .enable_mask
= BIT(15),
191 .hw
.init
= &(struct clk_init_data
){
192 .name
= "mi2s_bit_div_clk",
193 .parent_names
= (const char *[]){ "mi2s_div_clk" },
195 .ops
= &clk_branch_ops
,
196 .flags
= CLK_SET_RATE_PARENT
,
202 static struct clk_regmap_mux mi2s_bit_clk
= {
207 .hw
.init
= &(struct clk_init_data
){
208 .name
= "mi2s_bit_clk",
209 .parent_names
= (const char *[]){
214 .ops
= &clk_regmap_mux_closest_ops
,
215 .flags
= CLK_SET_RATE_PARENT
,
220 static struct freq_tbl clk_tbl_pcm
[] = {
221 { 64000, P_PLL4
, 4, 1, 1536 },
222 { 128000, P_PLL4
, 4, 1, 768 },
223 { 256000, P_PLL4
, 4, 1, 384 },
224 { 512000, P_PLL4
, 4, 1, 192 },
225 { 1024000, P_PLL4
, 4, 1, 96 },
226 { 2048000, P_PLL4
, 4, 1, 48 },
230 static struct clk_rcg pcm_src
= {
235 .mnctr_reset_bit
= 7,
236 .mnctr_mode_shift
= 5,
247 .parent_map
= lcc_pxo_pll4_map
,
249 .freq_tbl
= clk_tbl_pcm
,
252 .enable_mask
= BIT(9),
253 .hw
.init
= &(struct clk_init_data
){
255 .parent_names
= lcc_pxo_pll4
,
258 .flags
= CLK_SET_RATE_GATE
,
263 static struct clk_branch pcm_clk_out
= {
266 .halt_check
= BRANCH_HALT_ENABLE
,
269 .enable_mask
= BIT(11),
270 .hw
.init
= &(struct clk_init_data
){
271 .name
= "pcm_clk_out",
272 .parent_names
= (const char *[]){ "pcm_src" },
274 .ops
= &clk_branch_ops
,
275 .flags
= CLK_SET_RATE_PARENT
,
280 static struct clk_regmap_mux pcm_clk
= {
285 .hw
.init
= &(struct clk_init_data
){
287 .parent_names
= (const char *[]){
292 .ops
= &clk_regmap_mux_closest_ops
,
293 .flags
= CLK_SET_RATE_PARENT
,
298 static struct freq_tbl clk_tbl_aif_osr
[] = {
299 { 2822400, P_PLL4
, 1, 147, 20480 },
300 { 4096000, P_PLL4
, 1, 1, 96 },
301 { 5644800, P_PLL4
, 1, 147, 10240 },
302 { 6144000, P_PLL4
, 1, 1, 64 },
303 { 11289600, P_PLL4
, 1, 147, 5120 },
304 { 12288000, P_PLL4
, 1, 1, 32 },
305 { 22579200, P_PLL4
, 1, 147, 2560 },
306 { 24576000, P_PLL4
, 1, 1, 16 },
310 static struct clk_rcg spdif_src
= {
315 .mnctr_reset_bit
= 7,
316 .mnctr_mode_shift
= 5,
327 .parent_map
= lcc_pxo_pll4_map
,
329 .freq_tbl
= clk_tbl_aif_osr
,
332 .enable_mask
= BIT(9),
333 .hw
.init
= &(struct clk_init_data
){
335 .parent_names
= lcc_pxo_pll4
,
338 .flags
= CLK_SET_RATE_GATE
,
343 static const char * const lcc_spdif_parents
[] = {
347 static struct clk_branch spdif_clk
= {
350 .halt_check
= BRANCH_HALT_ENABLE
,
353 .enable_mask
= BIT(12),
354 .hw
.init
= &(struct clk_init_data
){
356 .parent_names
= lcc_spdif_parents
,
358 .ops
= &clk_branch_ops
,
359 .flags
= CLK_SET_RATE_PARENT
,
364 static struct freq_tbl clk_tbl_ahbix
[] = {
365 { 131072000, P_PLL4
, 1, 1, 3 },
369 static struct clk_rcg ahbix_clk
= {
374 .mnctr_reset_bit
= 7,
375 .mnctr_mode_shift
= 5,
386 .parent_map
= lcc_pxo_pll4_map
,
388 .freq_tbl
= clk_tbl_ahbix
,
391 .enable_mask
= BIT(11),
392 .hw
.init
= &(struct clk_init_data
){
394 .parent_names
= lcc_pxo_pll4
,
396 .ops
= &clk_rcg_lcc_ops
,
401 static struct clk_regmap
*lcc_ipq806x_clks
[] = {
403 [MI2S_OSR_SRC
] = &mi2s_osr_src
.clkr
,
404 [MI2S_OSR_CLK
] = &mi2s_osr_clk
.clkr
,
405 [MI2S_DIV_CLK
] = &mi2s_div_clk
.clkr
,
406 [MI2S_BIT_DIV_CLK
] = &mi2s_bit_div_clk
.clkr
,
407 [MI2S_BIT_CLK
] = &mi2s_bit_clk
.clkr
,
408 [PCM_SRC
] = &pcm_src
.clkr
,
409 [PCM_CLK_OUT
] = &pcm_clk_out
.clkr
,
410 [PCM_CLK
] = &pcm_clk
.clkr
,
411 [SPDIF_SRC
] = &spdif_src
.clkr
,
412 [SPDIF_CLK
] = &spdif_clk
.clkr
,
413 [AHBIX_CLK
] = &ahbix_clk
.clkr
,
416 static const struct regmap_config lcc_ipq806x_regmap_config
= {
420 .max_register
= 0xfc,
424 static const struct qcom_cc_desc lcc_ipq806x_desc
= {
425 .config
= &lcc_ipq806x_regmap_config
,
426 .clks
= lcc_ipq806x_clks
,
427 .num_clks
= ARRAY_SIZE(lcc_ipq806x_clks
),
430 static const struct of_device_id lcc_ipq806x_match_table
[] = {
431 { .compatible
= "qcom,lcc-ipq8064" },
434 MODULE_DEVICE_TABLE(of
, lcc_ipq806x_match_table
);
436 static int lcc_ipq806x_probe(struct platform_device
*pdev
)
439 struct regmap
*regmap
;
441 regmap
= qcom_cc_map(pdev
, &lcc_ipq806x_desc
);
443 return PTR_ERR(regmap
);
445 /* Configure the rate of PLL4 if the bootloader hasn't already */
446 regmap_read(regmap
, 0x0, &val
);
448 clk_pll_configure_sr(&pll4
, regmap
, &pll4_config
, true);
449 /* Enable PLL4 source on the LPASS Primary PLL Mux */
450 regmap_write(regmap
, 0xc4, 0x1);
452 return qcom_cc_really_probe(pdev
, &lcc_ipq806x_desc
, regmap
);
455 static struct platform_driver lcc_ipq806x_driver
= {
456 .probe
= lcc_ipq806x_probe
,
458 .name
= "lcc-ipq806x",
459 .of_match_table
= lcc_ipq806x_match_table
,
462 module_platform_driver(lcc_ipq806x_driver
);
464 MODULE_DESCRIPTION("QCOM LCC IPQ806x Driver");
465 MODULE_LICENSE("GPL v2");
466 MODULE_ALIAS("platform:lcc-ipq806x");