blob: 09a854a0d8d8f93c11aaca366e2b4fbd3be4c070 [file] [log] [blame]
Deepa Dinamanieb182372013-02-04 15:53:58 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <assert.h>
30#include <reg.h>
31#include <err.h>
32#include <clock.h>
33#include <clock_pll.h>
34#include <clock_lib2.h>
35#include <platform/clock.h>
36#include <platform/iomap.h>
37
38
39/* Mux source select values */
40#define cxo_source_val 0
41#define gpll0_source_val 1
42#define cxo_mm_source_val 0
43#define mmpll0_mm_source_val 1
44#define mmpll1_mm_source_val 2
45#define mmpll3_mm_source_val 3
46#define gpll0_mm_source_val 5
47
48struct clk_freq_tbl rcg_dummy_freq = F_END;
49
50
51/* Clock Operations */
52static struct clk_ops clk_ops_branch =
53{
54 .enable = clock_lib2_branch_clk_enable,
55 .disable = clock_lib2_branch_clk_disable,
56 .set_rate = clock_lib2_branch_set_rate,
57};
58
59static struct clk_ops clk_ops_rcg_mnd =
60{
61 .enable = clock_lib2_rcg_enable,
62 .set_rate = clock_lib2_rcg_set_rate,
63};
64
65static struct clk_ops clk_ops_rcg =
66{
67 .enable = clock_lib2_rcg_enable,
68 .set_rate = clock_lib2_rcg_set_rate,
69};
70
71static struct clk_ops clk_ops_cxo =
72{
73 .enable = cxo_clk_enable,
74 .disable = cxo_clk_disable,
75};
76
77static struct clk_ops clk_ops_pll_vote =
78{
79 .enable = pll_vote_clk_enable,
80 .disable = pll_vote_clk_disable,
81 .auto_off = pll_vote_clk_disable,
82 .is_enabled = pll_vote_clk_is_enabled,
83};
84
85static struct clk_ops clk_ops_vote =
86{
87 .enable = clock_lib2_vote_clk_enable,
88 .disable = clock_lib2_vote_clk_disable,
89};
90
91/* Clock Sources */
92static struct fixed_clk cxo_clk_src =
93{
94 .c = {
95 .rate = 19200000,
96 .dbg_name = "cxo_clk_src",
97 .ops = &clk_ops_cxo,
98 },
99};
100
101static struct pll_vote_clk gpll0_clk_src =
102{
103 .en_reg = (void *) APCS_GPLL_ENA_VOTE,
104 .en_mask = BIT(0),
105 .status_reg = (void *) GPLL0_STATUS,
106 .status_mask = BIT(17),
107 .parent = &cxo_clk_src.c,
108
109 .c = {
110 .rate = 600000000,
111 .dbg_name = "gpll0_clk_src",
112 .ops = &clk_ops_pll_vote,
113 },
114};
115
116/* SDCC Clocks */
117static struct clk_freq_tbl ftbl_gcc_sdcc1_2_apps_clk[] =
118{
119 F( 144000, cxo, 16, 3, 25),
120 F( 400000, cxo, 12, 1, 4),
121 F( 20000000, gpll0, 15, 1, 2),
122 F( 25000000, gpll0, 12, 1, 2),
123 F( 50000000, gpll0, 12, 0, 0),
124 F(100000000, gpll0, 6, 0, 0),
125 F(200000000, gpll0, 3, 0, 0),
126 F_END
127};
128
129static struct rcg_clk sdcc1_apps_clk_src =
130{
131 .cmd_reg = (uint32_t *) SDCC1_CMD_RCGR,
132 .cfg_reg = (uint32_t *) SDCC1_CFG_RCGR,
133 .m_reg = (uint32_t *) SDCC1_M,
134 .n_reg = (uint32_t *) SDCC1_N,
135 .d_reg = (uint32_t *) SDCC1_D,
136
137 .set_rate = clock_lib2_rcg_set_rate_mnd,
138 .freq_tbl = ftbl_gcc_sdcc1_2_apps_clk,
139 .current_freq = &rcg_dummy_freq,
140
141 .c = {
142 .dbg_name = "sdc1_clk",
143 .ops = &clk_ops_rcg_mnd,
144 },
145};
146
147static struct branch_clk gcc_sdcc1_apps_clk =
148{
149 .cbcr_reg = (uint32_t *) SDCC1_APPS_CBCR,
150 .parent = &sdcc1_apps_clk_src.c,
151
152 .c = {
153 .dbg_name = "gcc_sdcc1_apps_clk",
154 .ops = &clk_ops_branch,
155 },
156};
157
158static struct branch_clk gcc_sdcc1_ahb_clk =
159{
160 .cbcr_reg = (uint32_t *) SDCC1_AHB_CBCR,
161 .has_sibling = 1,
162
163 .c = {
164 .dbg_name = "gcc_sdcc1_ahb_clk",
165 .ops = &clk_ops_branch,
166 },
167};
168
Channagoud Kadabi6b9205d2013-05-14 13:22:35 -0700169static struct rcg_clk sdcc2_apps_clk_src =
170{
171 .cmd_reg = (uint32_t *) SDCC2_CMD_RCGR,
172 .cfg_reg = (uint32_t *) SDCC2_CFG_RCGR,
173 .m_reg = (uint32_t *) SDCC2_M,
174 .n_reg = (uint32_t *) SDCC2_N,
175 .d_reg = (uint32_t *) SDCC2_D,
176
177 .set_rate = clock_lib2_rcg_set_rate_mnd,
178 .freq_tbl = ftbl_gcc_sdcc1_2_apps_clk,
179 .current_freq = &rcg_dummy_freq,
180
181 .c = {
182 .dbg_name = "sdc2_clk",
183 .ops = &clk_ops_rcg_mnd,
184 },
185};
186
187static struct branch_clk gcc_sdcc2_apps_clk =
188{
189 .cbcr_reg = (uint32_t *) SDCC2_APPS_CBCR,
190 .parent = &sdcc2_apps_clk_src.c,
191
192 .c = {
193 .dbg_name = "gcc_sdcc2_apps_clk",
194 .ops = &clk_ops_branch,
195 },
196};
197
198static struct branch_clk gcc_sdcc2_ahb_clk =
199{
200 .cbcr_reg = (uint32_t *) SDCC2_AHB_CBCR,
201 .has_sibling = 1,
202
203 .c = {
204 .dbg_name = "gcc_sdcc2_ahb_clk",
205 .ops = &clk_ops_branch,
206 },
207};
208
Deepa Dinamanieb182372013-02-04 15:53:58 -0800209/* UART Clocks */
210static struct clk_freq_tbl ftbl_gcc_blsp1_2_uart1_6_apps_clk[] =
211{
212 F( 3686400, gpll0, 1, 96, 15625),
213 F( 7372800, gpll0, 1, 192, 15625),
214 F(14745600, gpll0, 1, 384, 15625),
215 F(16000000, gpll0, 5, 2, 15),
216 F(19200000, cxo, 1, 0, 0),
217 F(24000000, gpll0, 5, 1, 5),
218 F(32000000, gpll0, 1, 4, 75),
219 F(40000000, gpll0, 15, 0, 0),
220 F(46400000, gpll0, 1, 29, 375),
221 F(48000000, gpll0, 12.5, 0, 0),
222 F(51200000, gpll0, 1, 32, 375),
223 F(56000000, gpll0, 1, 7, 75),
224 F(58982400, gpll0, 1, 1536, 15625),
225 F(60000000, gpll0, 10, 0, 0),
226 F_END
227};
228
229static struct rcg_clk blsp1_uart3_apps_clk_src =
230{
231 .cmd_reg = (uint32_t *) BLSP1_UART3_APPS_CMD_RCGR,
232 .cfg_reg = (uint32_t *) BLSP1_UART3_APPS_CFG_RCGR,
233 .m_reg = (uint32_t *) BLSP1_UART3_APPS_M,
234 .n_reg = (uint32_t *) BLSP1_UART3_APPS_N,
235 .d_reg = (uint32_t *) BLSP1_UART3_APPS_D,
236
237 .set_rate = clock_lib2_rcg_set_rate_mnd,
238 .freq_tbl = ftbl_gcc_blsp1_2_uart1_6_apps_clk,
239 .current_freq = &rcg_dummy_freq,
240
241 .c = {
242 .dbg_name = "blsp1_uart3_apps_clk",
243 .ops = &clk_ops_rcg_mnd,
244 },
245};
246
247static struct branch_clk gcc_blsp1_uart3_apps_clk =
248{
249 .cbcr_reg = (uint32_t *) BLSP1_UART3_APPS_CBCR,
250 .parent = &blsp1_uart3_apps_clk_src.c,
251
252 .c = {
253 .dbg_name = "gcc_blsp1_uart3_apps_clk",
254 .ops = &clk_ops_branch,
255 },
256};
257
258static struct vote_clk gcc_blsp1_ahb_clk = {
259 .cbcr_reg = (uint32_t *) BLSP1_AHB_CBCR,
260 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
261 .en_mask = BIT(17),
262
263 .c = {
264 .dbg_name = "gcc_blsp1_ahb_clk",
265 .ops = &clk_ops_vote,
266 },
267};
268
269/* USB Clocks */
270static struct clk_freq_tbl ftbl_gcc_usb_hs_system_clk[] =
271{
272 F(75000000, gpll0, 8, 0, 0),
273 F_END
274};
275
276static struct rcg_clk usb_hs_system_clk_src =
277{
278 .cmd_reg = (uint32_t *) USB_HS_SYSTEM_CMD_RCGR,
279 .cfg_reg = (uint32_t *) USB_HS_SYSTEM_CFG_RCGR,
280
281 .set_rate = clock_lib2_rcg_set_rate_hid,
282 .freq_tbl = ftbl_gcc_usb_hs_system_clk,
283 .current_freq = &rcg_dummy_freq,
284
285 .c = {
286 .dbg_name = "usb_hs_system_clk",
287 .ops = &clk_ops_rcg,
288 },
289};
290
291static struct branch_clk gcc_usb_hs_system_clk =
292{
293 .cbcr_reg = (uint32_t *) USB_HS_SYSTEM_CBCR,
294 .parent = &usb_hs_system_clk_src.c,
295
296 .c = {
297 .dbg_name = "gcc_usb_hs_system_clk",
298 .ops = &clk_ops_branch,
299 },
300};
301
302static struct branch_clk gcc_usb_hs_ahb_clk =
303{
304 .cbcr_reg = (uint32_t *) USB_HS_AHB_CBCR,
305 .has_sibling = 1,
306
307 .c = {
308 .dbg_name = "gcc_usb_hs_ahb_clk",
309 .ops = &clk_ops_branch,
310 },
311};
312
Deepa Dinamanic51ad202013-04-02 14:58:56 -0700313static struct clk_freq_tbl ftbl_gcc_ce1_clk[] = {
314 F( 50000000, gpll0, 12, 0, 0),
315 F(100000000, gpll0, 6, 0, 0),
316 F_END
317};
318
319static struct rcg_clk ce1_clk_src = {
320 .cmd_reg = (uint32_t *) GCC_CE1_CMD_RCGR,
321 .cfg_reg = (uint32_t *) GCC_CE1_CFG_RCGR,
322 .set_rate = clock_lib2_rcg_set_rate_hid,
323 .freq_tbl = ftbl_gcc_ce1_clk,
324 .current_freq = &rcg_dummy_freq,
325
326 .c = {
327 .dbg_name = "ce1_clk_src",
328 .ops = &clk_ops_rcg,
329 },
330};
331
332static struct vote_clk gcc_ce1_clk = {
333 .cbcr_reg = (uint32_t *) GCC_CE1_CBCR,
334 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
335 .en_mask = BIT(5),
336
337 .c = {
338 .dbg_name = "gcc_ce1_clk",
339 .ops = &clk_ops_vote,
340 },
341};
342
343static struct vote_clk gcc_ce1_ahb_clk = {
344 .cbcr_reg = (uint32_t *) GCC_CE1_AHB_CBCR,
345 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
346 .en_mask = BIT(3),
347
348 .c = {
349 .dbg_name = "gcc_ce1_ahb_clk",
350 .ops = &clk_ops_vote,
351 },
352};
353
354static struct vote_clk gcc_ce1_axi_clk = {
355 .cbcr_reg = (uint32_t *) GCC_CE1_AXI_CBCR,
356 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
357 .en_mask = BIT(4),
358
359 .c = {
360 .dbg_name = "gcc_ce1_axi_clk",
361 .ops = &clk_ops_vote,
362 },
363};
364
Ray Zhang955c55f2013-05-25 23:07:50 +0800365/* Display clocks */
366static struct clk_freq_tbl ftbl_mdss_esc0_1_clk[] = {
367 F_MM(19200000, cxo, 1, 0, 0),
368 F_END
369};
370
371static struct clk_freq_tbl ftbl_mmss_axi_clk[] = {
372 F_MM(19200000, cxo, 1, 0, 0),
373 F_MM(100000000, gpll0, 6, 0, 0),
374 F_END
375};
376
377static struct clk_freq_tbl ftbl_mdp_clk[] = {
378 F_MM( 75000000, gpll0, 8, 0, 0),
379 F_MM( 100000000, gpll0, 6, 0, 0),
Jayant Shekhar4ccdbfc2013-10-21 16:42:02 +0530380 F_MM( 200000000, gpll0, 3, 0, 0),
Ray Zhang955c55f2013-05-25 23:07:50 +0800381 F_END
382};
383
384static struct rcg_clk dsi_esc0_clk_src = {
385 .cmd_reg = (uint32_t *) DSI_ESC0_CMD_RCGR,
386 .cfg_reg = (uint32_t *) DSI_ESC0_CFG_RCGR,
387 .set_rate = clock_lib2_rcg_set_rate_hid,
388 .freq_tbl = ftbl_mdss_esc0_1_clk,
389
390 .c = {
391 .dbg_name = "dsi_esc0_clk_src",
392 .ops = &clk_ops_rcg,
393 },
394};
395
396static struct clk_freq_tbl ftbl_mdss_vsync_clk[] = {
397 F_MM(19200000, cxo, 1, 0, 0),
398 F_END
399};
400
401static struct rcg_clk vsync_clk_src = {
402 .cmd_reg = (uint32_t *) VSYNC_CMD_RCGR,
403 .cfg_reg = (uint32_t *) VSYNC_CFG_RCGR,
404 .set_rate = clock_lib2_rcg_set_rate_hid,
405 .freq_tbl = ftbl_mdss_vsync_clk,
406
407 .c = {
408 .dbg_name = "vsync_clk_src",
409 .ops = &clk_ops_rcg,
410 },
411};
412
413static struct rcg_clk mdp_axi_clk_src = {
414 .cmd_reg = (uint32_t *) MDP_AXI_CMD_RCGR,
415 .cfg_reg = (uint32_t *) MDP_AXI_CFG_RCGR,
416 .set_rate = clock_lib2_rcg_set_rate_hid,
417 .freq_tbl = ftbl_mmss_axi_clk,
418
419 .c = {
420 .dbg_name = "mdp_axi_clk_src",
421 .ops = &clk_ops_rcg,
422 },
423};
424
425static struct branch_clk mdss_esc0_clk = {
426 .cbcr_reg = (uint32_t *) DSI_ESC0_CBCR,
427 .parent = &dsi_esc0_clk_src.c,
428 .has_sibling = 0,
429
430 .c = {
431 .dbg_name = "mdss_esc0_clk",
432 .ops = &clk_ops_branch,
433 },
434};
435
436static struct branch_clk mdss_axi_clk = {
437 .cbcr_reg = (uint32_t *) MDP_AXI_CBCR,
438 .parent = &mdp_axi_clk_src.c,
439 .has_sibling = 0,
440
441 .c = {
442 .dbg_name = "mdss_axi_clk",
443 .ops = &clk_ops_branch,
444 },
445};
446
447static struct branch_clk mmss_mmssnoc_axi_clk = {
448 .cbcr_reg = (uint32_t *) MMSS_MMSSNOC_AXI_CBCR,
449 .parent = &mdp_axi_clk_src.c,
450 .has_sibling = 0,
451
452 .c = {
453 .dbg_name = "mmss_mmssnoc_axi_clk",
454 .ops = &clk_ops_branch,
455 },
456};
457
458static struct branch_clk mmss_s0_axi_clk = {
459 .cbcr_reg = (uint32_t *) MMSS_S0_AXI_CBCR,
460 .parent = &mdp_axi_clk_src.c,
461 .has_sibling = 0,
462
463 .c = {
464 .dbg_name = "mmss_s0_axi_clk",
465 .ops = &clk_ops_branch,
466 },
467};
468
469static struct branch_clk mdp_ahb_clk = {
470 .cbcr_reg = (uint32_t *) MDP_AHB_CBCR,
471 .has_sibling = 1,
472
473 .c = {
474 .dbg_name = "mdp_ahb_clk",
475 .ops = &clk_ops_branch,
476 },
477};
478
479static struct rcg_clk mdss_mdp_clk_src = {
480 .cmd_reg = (uint32_t *) MDP_CMD_RCGR,
481 .cfg_reg = (uint32_t *) MDP_CFG_RCGR,
482 .set_rate = clock_lib2_rcg_set_rate_hid,
483 .freq_tbl = ftbl_mdp_clk,
484 .current_freq = &rcg_dummy_freq,
485
486 .c = {
487 .dbg_name = "mdss_mdp_clk_src",
488 .ops = &clk_ops_rcg,
489 },
490};
491
492static struct branch_clk mdss_mdp_clk = {
493 .cbcr_reg = (uint32_t *) MDP_CBCR,
494 .parent = &mdss_mdp_clk_src.c,
495 .has_sibling = 1,
496
497 .c = {
498 .dbg_name = "mdss_mdp_clk",
499 .ops = &clk_ops_branch,
500 },
501};
502
503static struct branch_clk mdss_mdp_lut_clk = {
vijay kumar3335f0e2014-10-27 22:36:49 +0530504 .cbcr_reg = (uint32_t *)MDP_LUT_CBCR,
Ray Zhang955c55f2013-05-25 23:07:50 +0800505 .parent = &mdss_mdp_clk_src.c,
506 .has_sibling = 1,
507
508 .c = {
509 .dbg_name = "mdss_mdp_lut_clk",
510 .ops = &clk_ops_branch,
511 },
512};
513
514static struct branch_clk mdss_vsync_clk = {
vijay kumar3335f0e2014-10-27 22:36:49 +0530515 .cbcr_reg = (uint32_t *)MDSS_VSYNC_CBCR,
Ray Zhang955c55f2013-05-25 23:07:50 +0800516 .parent = &vsync_clk_src.c,
517 .has_sibling = 0,
518
519 .c = {
520 .dbg_name = "mdss_vsync_clk",
521 .ops = &clk_ops_branch,
522 },
523};
Deepa Dinamanic51ad202013-04-02 14:58:56 -0700524
Deepa Dinamanieb182372013-02-04 15:53:58 -0800525/* Clock lookup table */
526static struct clk_lookup msm_clocks_8226[] =
527{
528 CLK_LOOKUP("sdc1_iface_clk", gcc_sdcc1_ahb_clk.c),
529 CLK_LOOKUP("sdc1_core_clk", gcc_sdcc1_apps_clk.c),
530
Channagoud Kadabi6b9205d2013-05-14 13:22:35 -0700531 CLK_LOOKUP("sdc2_iface_clk", gcc_sdcc2_ahb_clk.c),
532 CLK_LOOKUP("sdc2_core_clk", gcc_sdcc2_apps_clk.c),
533
Deepa Dinamanieb182372013-02-04 15:53:58 -0800534 CLK_LOOKUP("uart3_iface_clk", gcc_blsp1_ahb_clk.c),
535 CLK_LOOKUP("uart3_core_clk", gcc_blsp1_uart3_apps_clk.c),
536
537 CLK_LOOKUP("usb_iface_clk", gcc_usb_hs_ahb_clk.c),
538 CLK_LOOKUP("usb_core_clk", gcc_usb_hs_system_clk.c),
Deepa Dinamanic51ad202013-04-02 14:58:56 -0700539
540 CLK_LOOKUP("ce1_ahb_clk", gcc_ce1_ahb_clk.c),
541 CLK_LOOKUP("ce1_axi_clk", gcc_ce1_axi_clk.c),
542 CLK_LOOKUP("ce1_core_clk", gcc_ce1_clk.c),
543 CLK_LOOKUP("ce1_src_clk", ce1_clk_src.c),
Ray Zhang955c55f2013-05-25 23:07:50 +0800544
545 CLK_LOOKUP("mdp_ahb_clk", mdp_ahb_clk.c),
546 CLK_LOOKUP("mdss_esc0_clk", mdss_esc0_clk.c),
547 CLK_LOOKUP("mdss_axi_clk", mdss_axi_clk.c),
548 CLK_LOOKUP("mmss_mmssnoc_axi_clk", mmss_mmssnoc_axi_clk.c),
549 CLK_LOOKUP("mmss_s0_axi_clk", mmss_s0_axi_clk.c),
550 CLK_LOOKUP("mdss_vsync_clk", mdss_vsync_clk.c),
551 CLK_LOOKUP("mdss_mdp_clk_src", mdss_mdp_clk_src.c),
552 CLK_LOOKUP("mdss_mdp_clk", mdss_mdp_clk.c),
553 CLK_LOOKUP("mdss_mdp_lut_clk", mdss_mdp_lut_clk.c),
Deepa Dinamanieb182372013-02-04 15:53:58 -0800554};
555
556void platform_clock_init(void)
557{
558 clk_init(msm_clocks_8226, ARRAY_SIZE(msm_clocks_8226));
559}