1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved.
7 #include <linux/clk-provider.h>
9 #include <linux/of_address.h>
10 #include <linux/delay.h>
11 #include <linux/export.h>
12 #include <linux/clk/tegra.h>
17 #define AUDIO_SYNC_CLK_I2S0 0x4a0
18 #define AUDIO_SYNC_CLK_I2S1 0x4a4
19 #define AUDIO_SYNC_CLK_I2S2 0x4a8
20 #define AUDIO_SYNC_CLK_I2S3 0x4ac
21 #define AUDIO_SYNC_CLK_I2S4 0x4b0
22 #define AUDIO_SYNC_CLK_SPDIF 0x4b4
23 #define AUDIO_SYNC_CLK_DMIC1 0x560
24 #define AUDIO_SYNC_CLK_DMIC2 0x564
25 #define AUDIO_SYNC_CLK_DMIC3 0x6b8
27 #define AUDIO_SYNC_DOUBLER 0x49c
31 struct tegra_sync_source_initdata
{
34 unsigned long max_rate
;
41 .clk_id = tegra_clk_ ## _name,\
44 struct tegra_audio_clk_initdata
{
52 #define AUDIO(_name, _offset) \
55 .mux_name = #_name"_mux",\
57 .gate_clk_id = tegra_clk_ ## _name,\
58 .mux_clk_id = tegra_clk_ ## _name ## _mux,\
61 struct tegra_audio2x_clk_initdata
{
71 #define AUDIO2X(_name, _num, _offset) \
74 .gate_name = #_name"_2x",\
75 .name_2x = #_name"_doubler",\
76 .div_name = #_name"_div",\
77 .clk_id = tegra_clk_ ## _name ## _2x,\
79 .div_offset = _offset,\
82 static DEFINE_SPINLOCK(clk_doubler_lock
);
84 static const char * const mux_audio_sync_clk
[] = { "spdif_in_sync",
85 "i2s0_sync", "i2s1_sync", "i2s2_sync", "i2s3_sync", "i2s4_sync",
86 "pll_a_out0", "vimclk_sync",
89 static const char * const mux_dmic_sync_clk
[] = { "unused", "i2s0_sync",
90 "i2s1_sync", "i2s2_sync", "i2s3_sync", "i2s4_sync", "pll_a_out0",
94 static struct tegra_sync_source_initdata sync_source_clks
[] __initdata
= {
104 static struct tegra_audio_clk_initdata audio_clks
[] = {
105 AUDIO(audio0
, AUDIO_SYNC_CLK_I2S0
),
106 AUDIO(audio1
, AUDIO_SYNC_CLK_I2S1
),
107 AUDIO(audio2
, AUDIO_SYNC_CLK_I2S2
),
108 AUDIO(audio3
, AUDIO_SYNC_CLK_I2S3
),
109 AUDIO(audio4
, AUDIO_SYNC_CLK_I2S4
),
110 AUDIO(spdif
, AUDIO_SYNC_CLK_SPDIF
),
113 static struct tegra_audio_clk_initdata dmic_clks
[] = {
114 AUDIO(dmic1_sync_clk
, AUDIO_SYNC_CLK_DMIC1
),
115 AUDIO(dmic2_sync_clk
, AUDIO_SYNC_CLK_DMIC2
),
116 AUDIO(dmic3_sync_clk
, AUDIO_SYNC_CLK_DMIC3
),
119 static struct tegra_audio2x_clk_initdata audio2x_clks
[] = {
120 AUDIO2X(audio0
, 113, 24),
121 AUDIO2X(audio1
, 114, 25),
122 AUDIO2X(audio2
, 115, 26),
123 AUDIO2X(audio3
, 116, 27),
124 AUDIO2X(audio4
, 117, 28),
125 AUDIO2X(spdif
, 118, 29),
128 static void __init
tegra_audio_sync_clk_init(void __iomem
*clk_base
,
129 struct tegra_clk
*tegra_clks
,
130 struct tegra_audio_clk_initdata
*sync
,
132 const char * const *mux_names
,
137 struct tegra_audio_clk_initdata
*data
;
140 for (i
= 0, data
= sync
; i
< num_sync_clks
; i
++, data
++) {
141 dt_clk
= tegra_lookup_dt_id(data
->mux_clk_id
, tegra_clks
);
145 clk
= clk_register_mux(NULL
, data
->mux_name
, mux_names
,
147 CLK_SET_RATE_NO_REPARENT
,
148 clk_base
+ data
->offset
, 0, 3, 0,
152 dt_clk
= tegra_lookup_dt_id(data
->gate_clk_id
, tegra_clks
);
156 clk
= clk_register_gate(NULL
, data
->gate_name
, data
->mux_name
,
157 0, clk_base
+ data
->offset
, 4,
158 CLK_GATE_SET_TO_DISABLE
, NULL
);
163 void __init
tegra_audio_clk_init(void __iomem
*clk_base
,
164 void __iomem
*pmc_base
, struct tegra_clk
*tegra_clks
,
165 struct tegra_audio_clk_info
*audio_info
,
166 unsigned int num_plls
, unsigned long sync_max_rate
)
172 if (!audio_info
|| num_plls
< 1) {
173 pr_err("No audio data passed to tegra_audio_clk_init\n");
178 for (i
= 0; i
< num_plls
; i
++) {
179 struct tegra_audio_clk_info
*info
= &audio_info
[i
];
181 dt_clk
= tegra_lookup_dt_id(info
->clk_id
, tegra_clks
);
183 clk
= tegra_clk_register_pll(info
->name
, info
->parent
,
184 clk_base
, pmc_base
, 0, info
->pll_params
,
191 dt_clk
= tegra_lookup_dt_id(tegra_clk_pll_a_out0
, tegra_clks
);
193 clk
= tegra_clk_register_divider("pll_a_out0_div", "pll_a",
194 clk_base
+ PLLA_OUT
, 0, TEGRA_DIVIDER_ROUND_UP
,
196 clk
= tegra_clk_register_pll_out("pll_a_out0", "pll_a_out0_div",
197 clk_base
+ PLLA_OUT
, 1, 0, CLK_IGNORE_UNUSED
|
198 CLK_SET_RATE_PARENT
, 0, NULL
);
202 for (i
= 0; i
< ARRAY_SIZE(sync_source_clks
); i
++) {
203 struct tegra_sync_source_initdata
*data
;
205 data
= &sync_source_clks
[i
];
207 dt_clk
= tegra_lookup_dt_id(data
->clk_id
, tegra_clks
);
211 clk
= tegra_clk_register_sync_source(data
->name
, sync_max_rate
);
215 tegra_audio_sync_clk_init(clk_base
, tegra_clks
, audio_clks
,
216 ARRAY_SIZE(audio_clks
), mux_audio_sync_clk
,
217 ARRAY_SIZE(mux_audio_sync_clk
));
219 /* make sure the DMIC sync clocks have a valid parent */
220 for (i
= 0; i
< ARRAY_SIZE(dmic_clks
); i
++)
221 writel_relaxed(1, clk_base
+ dmic_clks
[i
].offset
);
223 tegra_audio_sync_clk_init(clk_base
, tegra_clks
, dmic_clks
,
224 ARRAY_SIZE(dmic_clks
), mux_dmic_sync_clk
,
225 ARRAY_SIZE(mux_dmic_sync_clk
));
227 for (i
= 0; i
< ARRAY_SIZE(audio2x_clks
); i
++) {
228 struct tegra_audio2x_clk_initdata
*data
;
230 data
= &audio2x_clks
[i
];
231 dt_clk
= tegra_lookup_dt_id(data
->clk_id
, tegra_clks
);
235 clk
= clk_register_fixed_factor(NULL
, data
->name_2x
,
236 data
->parent
, CLK_SET_RATE_PARENT
, 2, 1);
237 clk
= tegra_clk_register_divider(data
->div_name
,
238 data
->name_2x
, clk_base
+ AUDIO_SYNC_DOUBLER
,
239 0, 0, data
->div_offset
, 1, 0,
241 clk
= tegra_clk_register_periph_gate(data
->gate_name
,
242 data
->div_name
, TEGRA_PERIPH_NO_RESET
,
243 clk_base
, CLK_SET_RATE_PARENT
, data
->clk_num
,
244 periph_clk_enb_refcnt
);