xref: /openbmc/linux/drivers/clk/qcom/lpasscorecc-sc7180.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1edab812dSTaniya Das // SPDX-License-Identifier: GPL-2.0-only
2edab812dSTaniya Das /*
3edab812dSTaniya Das  * Copyright (c) 2020, The Linux Foundation. All rights reserved.
4edab812dSTaniya Das  */
5edab812dSTaniya Das 
6edab812dSTaniya Das #include <linux/clk-provider.h>
7edab812dSTaniya Das #include <linux/err.h>
8edab812dSTaniya Das #include <linux/module.h>
9*a96cbb14SRob Herring #include <linux/platform_device.h>
10edab812dSTaniya Das #include <linux/pm_clock.h>
11edab812dSTaniya Das #include <linux/pm_runtime.h>
12edab812dSTaniya Das #include <linux/of.h>
13edab812dSTaniya Das #include <linux/regmap.h>
14edab812dSTaniya Das 
15edab812dSTaniya Das #include <dt-bindings/clock/qcom,lpasscorecc-sc7180.h>
16edab812dSTaniya Das 
17edab812dSTaniya Das #include "clk-alpha-pll.h"
18edab812dSTaniya Das #include "clk-branch.h"
19edab812dSTaniya Das #include "clk-rcg.h"
20edab812dSTaniya Das #include "clk-regmap.h"
21edab812dSTaniya Das #include "common.h"
22edab812dSTaniya Das #include "gdsc.h"
23edab812dSTaniya Das 
24edab812dSTaniya Das enum {
25edab812dSTaniya Das 	P_BI_TCXO,
26edab812dSTaniya Das 	P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD,
27edab812dSTaniya Das 	P_SLEEP_CLK,
28edab812dSTaniya Das };
29edab812dSTaniya Das 
30edab812dSTaniya Das static struct pll_vco fabia_vco[] = {
31edab812dSTaniya Das 	{ 249600000, 2000000000, 0 },
32edab812dSTaniya Das };
33edab812dSTaniya Das 
34edab812dSTaniya Das static const struct alpha_pll_config lpass_lpaaudio_dig_pll_config = {
35edab812dSTaniya Das 	.l = 0x20,
36edab812dSTaniya Das 	.alpha = 0x0,
37edab812dSTaniya Das 	.config_ctl_val = 0x20485699,
38edab812dSTaniya Das 	.config_ctl_hi_val = 0x00002067,
39edab812dSTaniya Das 	.test_ctl_val = 0x40000000,
40edab812dSTaniya Das 	.test_ctl_hi_val = 0x00000000,
41edab812dSTaniya Das 	.user_ctl_val = 0x00005105,
42edab812dSTaniya Das 	.user_ctl_hi_val = 0x00004805,
43edab812dSTaniya Das };
44edab812dSTaniya Das 
45edab812dSTaniya Das static const u8 clk_alpha_pll_regs_offset[][PLL_OFF_MAX_REGS] = {
46edab812dSTaniya Das 	[CLK_ALPHA_PLL_TYPE_FABIA] =  {
47edab812dSTaniya Das 		[PLL_OFF_L_VAL] = 0x04,
48edab812dSTaniya Das 		[PLL_OFF_CAL_L_VAL] = 0x8,
49edab812dSTaniya Das 		[PLL_OFF_USER_CTL] = 0x0c,
50edab812dSTaniya Das 		[PLL_OFF_USER_CTL_U] = 0x10,
51edab812dSTaniya Das 		[PLL_OFF_USER_CTL_U1] = 0x14,
52edab812dSTaniya Das 		[PLL_OFF_CONFIG_CTL] = 0x18,
53edab812dSTaniya Das 		[PLL_OFF_CONFIG_CTL_U] = 0x1C,
54edab812dSTaniya Das 		[PLL_OFF_CONFIG_CTL_U1] = 0x20,
55edab812dSTaniya Das 		[PLL_OFF_TEST_CTL] = 0x24,
56edab812dSTaniya Das 		[PLL_OFF_TEST_CTL_U] = 0x28,
57edab812dSTaniya Das 		[PLL_OFF_STATUS] = 0x30,
58edab812dSTaniya Das 		[PLL_OFF_OPMODE] = 0x38,
59edab812dSTaniya Das 		[PLL_OFF_FRAC] = 0x40,
60edab812dSTaniya Das 	},
61edab812dSTaniya Das };
62edab812dSTaniya Das 
63edab812dSTaniya Das static struct clk_alpha_pll lpass_lpaaudio_dig_pll = {
64edab812dSTaniya Das 	.offset = 0x1000,
65edab812dSTaniya Das 	.vco_table = fabia_vco,
66edab812dSTaniya Das 	.num_vco = ARRAY_SIZE(fabia_vco),
67edab812dSTaniya Das 	.regs = clk_alpha_pll_regs_offset[CLK_ALPHA_PLL_TYPE_FABIA],
68edab812dSTaniya Das 	.clkr = {
69edab812dSTaniya Das 		.hw.init = &(struct clk_init_data){
70edab812dSTaniya Das 			.name = "lpass_lpaaudio_dig_pll",
71edab812dSTaniya Das 			.parent_data = &(const struct clk_parent_data){
72edab812dSTaniya Das 				.fw_name = "bi_tcxo",
73edab812dSTaniya Das 			},
74edab812dSTaniya Das 			.num_parents = 1,
75edab812dSTaniya Das 			.ops = &clk_alpha_pll_fabia_ops,
76edab812dSTaniya Das 		},
77edab812dSTaniya Das 	},
78edab812dSTaniya Das };
79edab812dSTaniya Das 
80edab812dSTaniya Das static const struct clk_div_table
81edab812dSTaniya Das 			post_div_table_lpass_lpaaudio_dig_pll_out_odd[] = {
82edab812dSTaniya Das 	{ 0x5, 5 },
83edab812dSTaniya Das 	{ }
84edab812dSTaniya Das };
85edab812dSTaniya Das 
86edab812dSTaniya Das static struct clk_alpha_pll_postdiv lpass_lpaaudio_dig_pll_out_odd = {
87edab812dSTaniya Das 	.offset = 0x1000,
88edab812dSTaniya Das 	.post_div_shift = 12,
89edab812dSTaniya Das 	.post_div_table = post_div_table_lpass_lpaaudio_dig_pll_out_odd,
90edab812dSTaniya Das 	.num_post_div =
91edab812dSTaniya Das 		ARRAY_SIZE(post_div_table_lpass_lpaaudio_dig_pll_out_odd),
92edab812dSTaniya Das 	.width = 4,
93edab812dSTaniya Das 	.regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
94edab812dSTaniya Das 	.clkr.hw.init = &(struct clk_init_data){
95edab812dSTaniya Das 		.name = "lpass_lpaaudio_dig_pll_out_odd",
967e5c218fSDmitry Baryshkov 		.parent_hws = (const struct clk_hw*[]) {
977e5c218fSDmitry Baryshkov 			&lpass_lpaaudio_dig_pll.clkr.hw,
98edab812dSTaniya Das 		},
99edab812dSTaniya Das 		.num_parents = 1,
100edab812dSTaniya Das 		.flags = CLK_SET_RATE_PARENT,
101edab812dSTaniya Das 		.ops = &clk_alpha_pll_postdiv_fabia_ops,
102edab812dSTaniya Das 	},
103edab812dSTaniya Das };
104edab812dSTaniya Das 
105edab812dSTaniya Das static const struct parent_map lpass_core_cc_parent_map_0[] = {
106edab812dSTaniya Das 	{ P_BI_TCXO, 0 },
107edab812dSTaniya Das 	{ P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 5 },
108edab812dSTaniya Das };
109edab812dSTaniya Das 
110edab812dSTaniya Das static const struct clk_parent_data lpass_core_cc_parent_data_0[] = {
111edab812dSTaniya Das 	{ .fw_name = "bi_tcxo" },
112edab812dSTaniya Das 	{ .hw = &lpass_lpaaudio_dig_pll_out_odd.clkr.hw },
113edab812dSTaniya Das };
114edab812dSTaniya Das 
115edab812dSTaniya Das static const struct parent_map lpass_core_cc_parent_map_2[] = {
116edab812dSTaniya Das 	{ P_BI_TCXO, 0 },
117edab812dSTaniya Das };
118edab812dSTaniya Das 
119edab812dSTaniya Das static struct clk_rcg2 core_clk_src = {
120edab812dSTaniya Das 	.cmd_rcgr = 0x1d000,
121edab812dSTaniya Das 	.mnd_width = 8,
122edab812dSTaniya Das 	.hid_width = 5,
123edab812dSTaniya Das 	.parent_map = lpass_core_cc_parent_map_2,
124edab812dSTaniya Das 	.clkr.hw.init = &(struct clk_init_data){
125edab812dSTaniya Das 		.name = "core_clk_src",
126edab812dSTaniya Das 		.parent_data = &(const struct clk_parent_data){
127edab812dSTaniya Das 			.fw_name = "bi_tcxo",
128edab812dSTaniya Das 		},
129edab812dSTaniya Das 		.num_parents = 1,
130edab812dSTaniya Das 		.ops = &clk_rcg2_ops,
131edab812dSTaniya Das 	},
132edab812dSTaniya Das };
133edab812dSTaniya Das 
134edab812dSTaniya Das static const struct freq_tbl ftbl_ext_mclk0_clk_src[] = {
135edab812dSTaniya Das 	F(9600000, P_BI_TCXO, 2, 0, 0),
136edab812dSTaniya Das 	F(19200000, P_BI_TCXO, 1, 0, 0),
137edab812dSTaniya Das 	{ }
138edab812dSTaniya Das };
139edab812dSTaniya Das 
140edab812dSTaniya Das static const struct freq_tbl ftbl_ext_lpaif_clk_src[] = {
141edab812dSTaniya Das 	F(256000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 15, 1, 32),
142edab812dSTaniya Das 	F(512000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 15, 1, 16),
143edab812dSTaniya Das 	F(768000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 10, 1, 16),
144edab812dSTaniya Das 	F(1024000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 15, 1, 8),
145edab812dSTaniya Das 	F(1536000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 10, 1, 8),
146edab812dSTaniya Das 	F(2048000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 15, 1, 4),
147edab812dSTaniya Das 	F(3072000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 10, 1, 4),
148edab812dSTaniya Das 	F(4096000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 15, 1, 2),
149edab812dSTaniya Das 	F(6144000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 10, 1, 2),
150edab812dSTaniya Das 	F(8192000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 15, 0, 0),
151edab812dSTaniya Das 	F(9600000, P_BI_TCXO, 2, 0, 0),
152edab812dSTaniya Das 	F(12288000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 10, 0, 0),
153edab812dSTaniya Das 	F(19200000, P_BI_TCXO, 1, 0, 0),
154edab812dSTaniya Das 	F(24576000, P_LPASS_LPAAUDIO_DIG_PLL_OUT_ODD, 5, 0, 0),
155edab812dSTaniya Das 	{ }
156edab812dSTaniya Das };
157edab812dSTaniya Das 
158edab812dSTaniya Das static struct clk_rcg2 ext_mclk0_clk_src = {
159edab812dSTaniya Das 	.cmd_rcgr = 0x20000,
160edab812dSTaniya Das 	.mnd_width = 8,
161edab812dSTaniya Das 	.hid_width = 5,
162edab812dSTaniya Das 	.parent_map = lpass_core_cc_parent_map_0,
163edab812dSTaniya Das 	.freq_tbl = ftbl_ext_mclk0_clk_src,
164edab812dSTaniya Das 	.clkr.hw.init = &(struct clk_init_data){
165edab812dSTaniya Das 		.name = "ext_mclk0_clk_src",
166edab812dSTaniya Das 		.parent_data = lpass_core_cc_parent_data_0,
167edab812dSTaniya Das 		.num_parents = 2,
168edab812dSTaniya Das 		.flags = CLK_SET_RATE_PARENT,
169edab812dSTaniya Das 		.ops = &clk_rcg2_ops,
170edab812dSTaniya Das 	},
171edab812dSTaniya Das };
172edab812dSTaniya Das 
173edab812dSTaniya Das static struct clk_rcg2 lpaif_pri_clk_src = {
174edab812dSTaniya Das 	.cmd_rcgr = 0x10000,
175edab812dSTaniya Das 	.mnd_width = 16,
176edab812dSTaniya Das 	.hid_width = 5,
177edab812dSTaniya Das 	.parent_map = lpass_core_cc_parent_map_0,
178edab812dSTaniya Das 	.freq_tbl = ftbl_ext_lpaif_clk_src,
179edab812dSTaniya Das 	.clkr.hw.init = &(struct clk_init_data){
180edab812dSTaniya Das 		.name = "lpaif_pri_clk_src",
181edab812dSTaniya Das 		.parent_data = lpass_core_cc_parent_data_0,
182edab812dSTaniya Das 		.num_parents = 2,
183edab812dSTaniya Das 		.flags = CLK_SET_RATE_PARENT,
184edab812dSTaniya Das 		.ops = &clk_rcg2_ops,
185edab812dSTaniya Das 	},
186edab812dSTaniya Das };
187edab812dSTaniya Das 
188edab812dSTaniya Das static struct clk_rcg2 lpaif_sec_clk_src = {
189edab812dSTaniya Das 	.cmd_rcgr = 0x11000,
190edab812dSTaniya Das 	.mnd_width = 16,
191edab812dSTaniya Das 	.hid_width = 5,
192edab812dSTaniya Das 	.parent_map = lpass_core_cc_parent_map_0,
193edab812dSTaniya Das 	.freq_tbl = ftbl_ext_lpaif_clk_src,
194edab812dSTaniya Das 	.clkr.hw.init = &(struct clk_init_data){
195edab812dSTaniya Das 		.name = "lpaif_sec_clk_src",
196edab812dSTaniya Das 		.parent_data = lpass_core_cc_parent_data_0,
197edab812dSTaniya Das 		.num_parents = 2,
198edab812dSTaniya Das 		.flags = CLK_SET_RATE_PARENT,
199edab812dSTaniya Das 		.ops = &clk_rcg2_ops,
200edab812dSTaniya Das 	},
201edab812dSTaniya Das };
202edab812dSTaniya Das 
203edab812dSTaniya Das static struct clk_branch lpass_audio_core_ext_mclk0_clk = {
204edab812dSTaniya Das 	.halt_reg = 0x20014,
205edab812dSTaniya Das 	.halt_check = BRANCH_HALT,
206edab812dSTaniya Das 	.hwcg_reg = 0x20014,
207edab812dSTaniya Das 	.hwcg_bit = 1,
208edab812dSTaniya Das 	.clkr = {
209edab812dSTaniya Das 		.enable_reg = 0x20014,
210edab812dSTaniya Das 		.enable_mask = BIT(0),
211edab812dSTaniya Das 		.hw.init = &(struct clk_init_data){
212edab812dSTaniya Das 			.name = "lpass_audio_core_ext_mclk0_clk",
2137e5c218fSDmitry Baryshkov 			.parent_hws = (const struct clk_hw*[]) {
2147e5c218fSDmitry Baryshkov 				&ext_mclk0_clk_src.clkr.hw,
215edab812dSTaniya Das 			},
216edab812dSTaniya Das 			.num_parents = 1,
217edab812dSTaniya Das 			.flags = CLK_SET_RATE_PARENT,
218edab812dSTaniya Das 			.ops = &clk_branch2_ops,
219edab812dSTaniya Das 		},
220edab812dSTaniya Das 	},
221edab812dSTaniya Das };
222edab812dSTaniya Das 
223edab812dSTaniya Das static struct clk_branch lpass_audio_core_lpaif_pri_ibit_clk = {
224edab812dSTaniya Das 	.halt_reg = 0x10018,
225edab812dSTaniya Das 	.halt_check = BRANCH_HALT,
226edab812dSTaniya Das 	.hwcg_reg = 0x10018,
227edab812dSTaniya Das 	.hwcg_bit = 1,
228edab812dSTaniya Das 	.clkr = {
229edab812dSTaniya Das 		.enable_reg = 0x10018,
230edab812dSTaniya Das 		.enable_mask = BIT(0),
231edab812dSTaniya Das 		.hw.init = &(struct clk_init_data){
232edab812dSTaniya Das 			.name = "lpass_audio_core_lpaif_pri_ibit_clk",
2337e5c218fSDmitry Baryshkov 			.parent_hws = (const struct clk_hw*[]) {
2347e5c218fSDmitry Baryshkov 				&lpaif_pri_clk_src.clkr.hw,
235edab812dSTaniya Das 			},
236edab812dSTaniya Das 			.num_parents = 1,
237edab812dSTaniya Das 			.flags = CLK_SET_RATE_PARENT,
238edab812dSTaniya Das 			.ops = &clk_branch2_ops,
239edab812dSTaniya Das 		},
240edab812dSTaniya Das 	},
241edab812dSTaniya Das };
242edab812dSTaniya Das 
243edab812dSTaniya Das static struct clk_branch lpass_audio_core_lpaif_sec_ibit_clk = {
244edab812dSTaniya Das 	.halt_reg = 0x11018,
245edab812dSTaniya Das 	.halt_check = BRANCH_HALT,
246edab812dSTaniya Das 	.hwcg_reg = 0x11018,
247edab812dSTaniya Das 	.hwcg_bit = 1,
248edab812dSTaniya Das 	.clkr = {
249edab812dSTaniya Das 		.enable_reg = 0x11018,
250edab812dSTaniya Das 		.enable_mask = BIT(0),
251edab812dSTaniya Das 		.hw.init = &(struct clk_init_data){
252edab812dSTaniya Das 			.name = "lpass_audio_core_lpaif_sec_ibit_clk",
2537e5c218fSDmitry Baryshkov 			.parent_hws = (const struct clk_hw*[]) {
2547e5c218fSDmitry Baryshkov 				&lpaif_sec_clk_src.clkr.hw,
255edab812dSTaniya Das 			},
256edab812dSTaniya Das 			.num_parents = 1,
257edab812dSTaniya Das 			.flags = CLK_SET_RATE_PARENT,
258edab812dSTaniya Das 			.ops = &clk_branch2_ops,
259edab812dSTaniya Das 		},
260edab812dSTaniya Das 	},
261edab812dSTaniya Das };
262edab812dSTaniya Das 
263edab812dSTaniya Das static struct clk_branch lpass_audio_core_sysnoc_mport_core_clk = {
264edab812dSTaniya Das 	.halt_reg = 0x23000,
265edab812dSTaniya Das 	.halt_check = BRANCH_HALT,
266edab812dSTaniya Das 	.hwcg_reg = 0x23000,
267edab812dSTaniya Das 	.hwcg_bit = 1,
268edab812dSTaniya Das 	.clkr = {
269edab812dSTaniya Das 		.enable_reg = 0x23000,
270edab812dSTaniya Das 		.enable_mask = BIT(0),
271edab812dSTaniya Das 		.hw.init = &(struct clk_init_data){
272edab812dSTaniya Das 			.name = "lpass_audio_core_sysnoc_mport_core_clk",
2737e5c218fSDmitry Baryshkov 			.parent_hws = (const struct clk_hw*[]) {
2747e5c218fSDmitry Baryshkov 				&core_clk_src.clkr.hw,
275edab812dSTaniya Das 			},
276edab812dSTaniya Das 			.num_parents = 1,
277edab812dSTaniya Das 			.flags = CLK_SET_RATE_PARENT,
278edab812dSTaniya Das 			.ops = &clk_branch2_ops,
279edab812dSTaniya Das 		},
280edab812dSTaniya Das 	},
281edab812dSTaniya Das };
282edab812dSTaniya Das 
283edab812dSTaniya Das static struct clk_regmap *lpass_core_cc_sc7180_clocks[] = {
284edab812dSTaniya Das 	[EXT_MCLK0_CLK_SRC] = &ext_mclk0_clk_src.clkr,
285edab812dSTaniya Das 	[LPAIF_PRI_CLK_SRC] = &lpaif_pri_clk_src.clkr,
286edab812dSTaniya Das 	[LPAIF_SEC_CLK_SRC] = &lpaif_sec_clk_src.clkr,
287edab812dSTaniya Das 	[CORE_CLK_SRC] = &core_clk_src.clkr,
288edab812dSTaniya Das 	[LPASS_AUDIO_CORE_EXT_MCLK0_CLK] = &lpass_audio_core_ext_mclk0_clk.clkr,
289edab812dSTaniya Das 	[LPASS_AUDIO_CORE_LPAIF_PRI_IBIT_CLK] =
290edab812dSTaniya Das 		&lpass_audio_core_lpaif_pri_ibit_clk.clkr,
291edab812dSTaniya Das 	[LPASS_AUDIO_CORE_LPAIF_SEC_IBIT_CLK] =
292edab812dSTaniya Das 		&lpass_audio_core_lpaif_sec_ibit_clk.clkr,
293edab812dSTaniya Das 	[LPASS_AUDIO_CORE_SYSNOC_MPORT_CORE_CLK] =
294edab812dSTaniya Das 		&lpass_audio_core_sysnoc_mport_core_clk.clkr,
295edab812dSTaniya Das 	[LPASS_LPAAUDIO_DIG_PLL] = &lpass_lpaaudio_dig_pll.clkr,
296edab812dSTaniya Das 	[LPASS_LPAAUDIO_DIG_PLL_OUT_ODD] = &lpass_lpaaudio_dig_pll_out_odd.clkr,
297edab812dSTaniya Das };
298edab812dSTaniya Das 
299edab812dSTaniya Das static struct gdsc lpass_pdc_hm_gdsc = {
300edab812dSTaniya Das 	.gdscr = 0x3090,
301edab812dSTaniya Das 	.pd = {
302edab812dSTaniya Das 		.name = "lpass_pdc_hm_gdsc",
303edab812dSTaniya Das 	},
304edab812dSTaniya Das 	.pwrsts = PWRSTS_OFF_ON,
305edab812dSTaniya Das 	.flags = VOTABLE,
306edab812dSTaniya Das };
307edab812dSTaniya Das 
308edab812dSTaniya Das static struct gdsc lpass_audio_hm_gdsc = {
309edab812dSTaniya Das 	.gdscr = 0x9090,
310edab812dSTaniya Das 	.pd = {
311edab812dSTaniya Das 		.name = "lpass_audio_hm_gdsc",
312edab812dSTaniya Das 	},
313edab812dSTaniya Das 	.pwrsts = PWRSTS_OFF_ON,
314edab812dSTaniya Das };
315edab812dSTaniya Das 
316edab812dSTaniya Das static struct gdsc lpass_core_hm_gdsc = {
317edab812dSTaniya Das 	.gdscr = 0x0,
318edab812dSTaniya Das 	.pd = {
319edab812dSTaniya Das 		.name = "lpass_core_hm_gdsc",
320edab812dSTaniya Das 	},
321edab812dSTaniya Das 	.pwrsts = PWRSTS_OFF_ON,
322edab812dSTaniya Das 	.flags = RETAIN_FF_ENABLE,
323edab812dSTaniya Das };
324edab812dSTaniya Das 
325edab812dSTaniya Das static struct gdsc *lpass_core_hm_sc7180_gdscs[] = {
326edab812dSTaniya Das 	[LPASS_CORE_HM_GDSCR] = &lpass_core_hm_gdsc,
327edab812dSTaniya Das };
328edab812dSTaniya Das 
329edab812dSTaniya Das static struct gdsc *lpass_audio_hm_sc7180_gdscs[] = {
330edab812dSTaniya Das 	[LPASS_PDC_HM_GDSCR] = &lpass_pdc_hm_gdsc,
331edab812dSTaniya Das 	[LPASS_AUDIO_HM_GDSCR] = &lpass_audio_hm_gdsc,
332edab812dSTaniya Das };
333edab812dSTaniya Das 
334edab812dSTaniya Das static struct regmap_config lpass_core_cc_sc7180_regmap_config = {
335edab812dSTaniya Das 	.reg_bits = 32,
336edab812dSTaniya Das 	.reg_stride = 4,
337edab812dSTaniya Das 	.val_bits = 32,
338edab812dSTaniya Das 	.fast_io = true,
339edab812dSTaniya Das };
340edab812dSTaniya Das 
341edab812dSTaniya Das static const struct qcom_cc_desc lpass_core_hm_sc7180_desc = {
342edab812dSTaniya Das 	.config = &lpass_core_cc_sc7180_regmap_config,
343edab812dSTaniya Das 	.gdscs = lpass_core_hm_sc7180_gdscs,
344edab812dSTaniya Das 	.num_gdscs = ARRAY_SIZE(lpass_core_hm_sc7180_gdscs),
345edab812dSTaniya Das };
346edab812dSTaniya Das 
347edab812dSTaniya Das static const struct qcom_cc_desc lpass_core_cc_sc7180_desc = {
348edab812dSTaniya Das 	.config = &lpass_core_cc_sc7180_regmap_config,
349edab812dSTaniya Das 	.clks = lpass_core_cc_sc7180_clocks,
350edab812dSTaniya Das 	.num_clks = ARRAY_SIZE(lpass_core_cc_sc7180_clocks),
351edab812dSTaniya Das };
352edab812dSTaniya Das 
353edab812dSTaniya Das static const struct qcom_cc_desc lpass_audio_hm_sc7180_desc = {
354edab812dSTaniya Das 	.config = &lpass_core_cc_sc7180_regmap_config,
355edab812dSTaniya Das 	.gdscs = lpass_audio_hm_sc7180_gdscs,
356edab812dSTaniya Das 	.num_gdscs = ARRAY_SIZE(lpass_audio_hm_sc7180_gdscs),
357edab812dSTaniya Das };
358edab812dSTaniya Das 
lpass_setup_runtime_pm(struct platform_device * pdev)359ff1ccf59SDouglas Anderson static int lpass_setup_runtime_pm(struct platform_device *pdev)
3604ee9fe3eSDouglas Anderson {
3614ee9fe3eSDouglas Anderson 	int ret;
3624ee9fe3eSDouglas Anderson 
363ce8c195eSTaniya Das 	pm_runtime_use_autosuspend(&pdev->dev);
364ce8c195eSTaniya Das 	pm_runtime_set_autosuspend_delay(&pdev->dev, 500);
365ce8c195eSTaniya Das 
36672cfc73fSDmitry Baryshkov 	ret = devm_pm_runtime_enable(&pdev->dev);
3674ee9fe3eSDouglas Anderson 	if (ret)
3684ee9fe3eSDouglas Anderson 		return ret;
3694ee9fe3eSDouglas Anderson 
37072cfc73fSDmitry Baryshkov 	ret = devm_pm_clk_create(&pdev->dev);
3714ee9fe3eSDouglas Anderson 	if (ret)
3724ee9fe3eSDouglas Anderson 		return ret;
3734ee9fe3eSDouglas Anderson 
3744ee9fe3eSDouglas Anderson 	ret = pm_clk_add(&pdev->dev, "iface");
3754ee9fe3eSDouglas Anderson 	if (ret < 0)
3764ee9fe3eSDouglas Anderson 		dev_err(&pdev->dev, "failed to acquire iface clock\n");
3774ee9fe3eSDouglas Anderson 
378ff1ccf59SDouglas Anderson 	return pm_runtime_resume_and_get(&pdev->dev);
3794ee9fe3eSDouglas Anderson }
3804ee9fe3eSDouglas Anderson 
lpass_core_cc_sc7180_probe(struct platform_device * pdev)381edab812dSTaniya Das static int lpass_core_cc_sc7180_probe(struct platform_device *pdev)
382edab812dSTaniya Das {
383edab812dSTaniya Das 	const struct qcom_cc_desc *desc;
384edab812dSTaniya Das 	struct regmap *regmap;
385edab812dSTaniya Das 	int ret;
386edab812dSTaniya Das 
387ff1ccf59SDouglas Anderson 	ret = lpass_setup_runtime_pm(pdev);
3884ee9fe3eSDouglas Anderson 	if (ret)
3894ee9fe3eSDouglas Anderson 		return ret;
3904ee9fe3eSDouglas Anderson 
391edab812dSTaniya Das 	lpass_core_cc_sc7180_regmap_config.name = "lpass_audio_cc";
392edab812dSTaniya Das 	desc = &lpass_audio_hm_sc7180_desc;
393edab812dSTaniya Das 	ret = qcom_cc_probe_by_index(pdev, 1, desc);
394edab812dSTaniya Das 	if (ret)
395ff1ccf59SDouglas Anderson 		goto exit;
396edab812dSTaniya Das 
397edab812dSTaniya Das 	lpass_core_cc_sc7180_regmap_config.name = "lpass_core_cc";
398edab812dSTaniya Das 	regmap = qcom_cc_map(pdev, &lpass_core_cc_sc7180_desc);
399ff1ccf59SDouglas Anderson 	if (IS_ERR(regmap)) {
400ff1ccf59SDouglas Anderson 		ret = PTR_ERR(regmap);
401ff1ccf59SDouglas Anderson 		goto exit;
402ff1ccf59SDouglas Anderson 	}
403edab812dSTaniya Das 
404edab812dSTaniya Das 	/*
405edab812dSTaniya Das 	 * Keep the CLK always-ON
406edab812dSTaniya Das 	 * LPASS_AUDIO_CORE_SYSNOC_SWAY_CORE_CLK
407edab812dSTaniya Das 	 */
408edab812dSTaniya Das 	regmap_update_bits(regmap, 0x24000, BIT(0), BIT(0));
409edab812dSTaniya Das 
410edab812dSTaniya Das 	/* PLL settings */
411edab812dSTaniya Das 	regmap_write(regmap, 0x1008, 0x20);
412edab812dSTaniya Das 	regmap_update_bits(regmap, 0x1014, BIT(0), BIT(0));
413edab812dSTaniya Das 
414edab812dSTaniya Das 	clk_fabia_pll_configure(&lpass_lpaaudio_dig_pll, regmap,
415edab812dSTaniya Das 				&lpass_lpaaudio_dig_pll_config);
416edab812dSTaniya Das 
417ce8c195eSTaniya Das 	ret = qcom_cc_really_probe(pdev, &lpass_core_cc_sc7180_desc, regmap);
418ce8c195eSTaniya Das 
419ce8c195eSTaniya Das 	pm_runtime_mark_last_busy(&pdev->dev);
420ff1ccf59SDouglas Anderson exit:
421ce8c195eSTaniya Das 	pm_runtime_put_autosuspend(&pdev->dev);
422ce8c195eSTaniya Das 
423ce8c195eSTaniya Das 	return ret;
424edab812dSTaniya Das }
425edab812dSTaniya Das 
lpass_hm_core_probe(struct platform_device * pdev)426edab812dSTaniya Das static int lpass_hm_core_probe(struct platform_device *pdev)
427edab812dSTaniya Das {
428edab812dSTaniya Das 	const struct qcom_cc_desc *desc;
4294ee9fe3eSDouglas Anderson 	int ret;
4304ee9fe3eSDouglas Anderson 
431ff1ccf59SDouglas Anderson 	ret = lpass_setup_runtime_pm(pdev);
4324ee9fe3eSDouglas Anderson 	if (ret)
4334ee9fe3eSDouglas Anderson 		return ret;
434edab812dSTaniya Das 
435edab812dSTaniya Das 	lpass_core_cc_sc7180_regmap_config.name = "lpass_hm_core";
436edab812dSTaniya Das 	desc = &lpass_core_hm_sc7180_desc;
437edab812dSTaniya Das 
438ff1ccf59SDouglas Anderson 	ret = qcom_cc_probe_by_index(pdev, 0, desc);
439ff1ccf59SDouglas Anderson 
440ff1ccf59SDouglas Anderson 	pm_runtime_mark_last_busy(&pdev->dev);
441ff1ccf59SDouglas Anderson 	pm_runtime_put_autosuspend(&pdev->dev);
442ff1ccf59SDouglas Anderson 
443ff1ccf59SDouglas Anderson 	return ret;
444edab812dSTaniya Das }
445edab812dSTaniya Das 
4464ee9fe3eSDouglas Anderson static const struct of_device_id lpass_hm_sc7180_match_table[] = {
447edab812dSTaniya Das 	{
448edab812dSTaniya Das 		.compatible = "qcom,sc7180-lpasshm",
449edab812dSTaniya Das 	},
4504ee9fe3eSDouglas Anderson 	{ }
4514ee9fe3eSDouglas Anderson };
4524ee9fe3eSDouglas Anderson MODULE_DEVICE_TABLE(of, lpass_hm_sc7180_match_table);
4534ee9fe3eSDouglas Anderson 
4544ee9fe3eSDouglas Anderson static const struct of_device_id lpass_core_cc_sc7180_match_table[] = {
455edab812dSTaniya Das 	{
456edab812dSTaniya Das 		.compatible = "qcom,sc7180-lpasscorecc",
457edab812dSTaniya Das 	},
458edab812dSTaniya Das 	{ }
459edab812dSTaniya Das };
460edab812dSTaniya Das MODULE_DEVICE_TABLE(of, lpass_core_cc_sc7180_match_table);
461edab812dSTaniya Das 
462e3ad6c3fSDouglas Anderson static const struct dev_pm_ops lpass_pm_ops = {
463edab812dSTaniya Das 	SET_RUNTIME_PM_OPS(pm_clk_suspend, pm_clk_resume, NULL)
464edab812dSTaniya Das };
465edab812dSTaniya Das 
466edab812dSTaniya Das static struct platform_driver lpass_core_cc_sc7180_driver = {
4674ee9fe3eSDouglas Anderson 	.probe = lpass_core_cc_sc7180_probe,
468edab812dSTaniya Das 	.driver = {
469edab812dSTaniya Das 		.name = "lpass_core_cc-sc7180",
470edab812dSTaniya Das 		.of_match_table = lpass_core_cc_sc7180_match_table,
471e3ad6c3fSDouglas Anderson 		.pm = &lpass_pm_ops,
472edab812dSTaniya Das 	},
473edab812dSTaniya Das };
474edab812dSTaniya Das 
4754ee9fe3eSDouglas Anderson static struct platform_driver lpass_hm_sc7180_driver = {
4764ee9fe3eSDouglas Anderson 	.probe = lpass_hm_core_probe,
4774ee9fe3eSDouglas Anderson 	.driver = {
4784ee9fe3eSDouglas Anderson 		.name = "lpass_hm-sc7180",
4794ee9fe3eSDouglas Anderson 		.of_match_table = lpass_hm_sc7180_match_table,
480e3ad6c3fSDouglas Anderson 		.pm = &lpass_pm_ops,
4814ee9fe3eSDouglas Anderson 	},
4824ee9fe3eSDouglas Anderson };
4834ee9fe3eSDouglas Anderson 
lpass_sc7180_init(void)4844ee9fe3eSDouglas Anderson static int __init lpass_sc7180_init(void)
485edab812dSTaniya Das {
4864ee9fe3eSDouglas Anderson 	int ret;
4874ee9fe3eSDouglas Anderson 
4884ee9fe3eSDouglas Anderson 	ret = platform_driver_register(&lpass_core_cc_sc7180_driver);
4894ee9fe3eSDouglas Anderson 	if (ret)
4904ee9fe3eSDouglas Anderson 		return ret;
4914ee9fe3eSDouglas Anderson 
492e4accab4SDan Carpenter 	ret = platform_driver_register(&lpass_hm_sc7180_driver);
493e4accab4SDan Carpenter 	if (ret) {
494e4accab4SDan Carpenter 		platform_driver_unregister(&lpass_core_cc_sc7180_driver);
495e4accab4SDan Carpenter 		return ret;
496e4accab4SDan Carpenter 	}
497e4accab4SDan Carpenter 
498e4accab4SDan Carpenter 	return 0;
4994ee9fe3eSDouglas Anderson }
5004ee9fe3eSDouglas Anderson subsys_initcall(lpass_sc7180_init);
5014ee9fe3eSDouglas Anderson 
lpass_sc7180_exit(void)5024ee9fe3eSDouglas Anderson static void __exit lpass_sc7180_exit(void)
5034ee9fe3eSDouglas Anderson {
5044ee9fe3eSDouglas Anderson 	platform_driver_unregister(&lpass_hm_sc7180_driver);
505edab812dSTaniya Das 	platform_driver_unregister(&lpass_core_cc_sc7180_driver);
506edab812dSTaniya Das }
5074ee9fe3eSDouglas Anderson module_exit(lpass_sc7180_exit);
508edab812dSTaniya Das 
509edab812dSTaniya Das MODULE_DESCRIPTION("QTI LPASS_CORE_CC SC7180 Driver");
510edab812dSTaniya Das MODULE_LICENSE("GPL v2");
511