blob: 0bf5ce025c2fd6fc012c2a38ed611d8e9a3ec355 [file] [log] [blame]
Channagoud Kadabi123c9722014-02-06 13:22:50 -08001/* Copyright (c) 2013-2014, 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 gpll4_source_val 5
43#define cxo_mm_source_val 0
44#define mmpll0_mm_source_val 1
45#define mmpll1_mm_source_val 2
46#define mmpll3_mm_source_val 3
47#define gpll0_mm_source_val 5
48
49struct clk_freq_tbl rcg_dummy_freq = F_END;
50
51
52/* Clock Operations */
53static struct clk_ops clk_ops_branch =
54{
55 .enable = clock_lib2_branch_clk_enable,
56 .disable = clock_lib2_branch_clk_disable,
57 .set_rate = clock_lib2_branch_set_rate,
58};
59
60static struct clk_ops clk_ops_rcg_mnd =
61{
62 .enable = clock_lib2_rcg_enable,
63 .set_rate = clock_lib2_rcg_set_rate,
64};
65
66static struct clk_ops clk_ops_rcg =
67{
68 .enable = clock_lib2_rcg_enable,
69 .set_rate = clock_lib2_rcg_set_rate,
70};
71
72static struct clk_ops clk_ops_cxo =
73{
74 .enable = cxo_clk_enable,
75 .disable = cxo_clk_disable,
76};
77
78static struct clk_ops clk_ops_pll_vote =
79{
80 .enable = pll_vote_clk_enable,
81 .disable = pll_vote_clk_disable,
82 .auto_off = pll_vote_clk_disable,
83 .is_enabled = pll_vote_clk_is_enabled,
84};
85
86static struct clk_ops clk_ops_vote =
87{
88 .enable = clock_lib2_vote_clk_enable,
89 .disable = clock_lib2_vote_clk_disable,
90};
91
92/* Clock Sources */
93static struct fixed_clk cxo_clk_src =
94{
95 .c = {
96 .rate = 19200000,
97 .dbg_name = "cxo_clk_src",
98 .ops = &clk_ops_cxo,
99 },
100};
101
102static struct pll_vote_clk gpll0_clk_src =
103{
104 .en_reg = (void *) APCS_GPLL_ENA_VOTE,
105 .en_mask = BIT(0),
106 .status_reg = (void *) GPLL0_MODE,
107 .status_mask = BIT(30),
108 .parent = &cxo_clk_src.c,
109
110 .c = {
111 .rate = 600000000,
112 .dbg_name = "gpll0_clk_src",
113 .ops = &clk_ops_pll_vote,
114 },
115};
116
117static struct pll_vote_clk gpll4_clk_src =
118{
119 .en_reg = (void *) APCS_GPLL_ENA_VOTE,
120 .en_mask = BIT(4),
121 .status_reg = (void *) GPLL4_MODE,
122 .status_mask = BIT(30),
123 .parent = &cxo_clk_src.c,
124
125 .c = {
126 .rate = 1600000000,
127 .dbg_name = "gpll4_clk_src",
128 .ops = &clk_ops_pll_vote,
129 },
130};
131
132/* UART Clocks */
133static struct clk_freq_tbl ftbl_gcc_blsp1_2_uart1_6_apps_clk[] =
134{
135 F( 3686400, gpll0, 1, 96, 15625),
136 F( 7372800, gpll0, 1, 192, 15625),
137 F(14745600, gpll0, 1, 384, 15625),
138 F(16000000, gpll0, 5, 2, 15),
139 F(19200000, cxo, 1, 0, 0),
140 F(24000000, gpll0, 5, 1, 5),
141 F(32000000, gpll0, 1, 4, 75),
142 F(40000000, gpll0, 15, 0, 0),
143 F(46400000, gpll0, 1, 29, 375),
144 F(48000000, gpll0, 12.5, 0, 0),
145 F(51200000, gpll0, 1, 32, 375),
146 F(56000000, gpll0, 1, 7, 75),
147 F(58982400, gpll0, 1, 1536, 15625),
148 F(60000000, gpll0, 10, 0, 0),
149 F_END
150};
151
152static struct rcg_clk blsp2_uart2_apps_clk_src =
153{
154 .cmd_reg = (uint32_t *) BLSP2_UART2_APPS_CMD_RCGR,
155 .cfg_reg = (uint32_t *) BLSP2_UART2_APPS_CFG_RCGR,
156 .m_reg = (uint32_t *) BLSP2_UART2_APPS_M,
157 .n_reg = (uint32_t *) BLSP2_UART2_APPS_N,
158 .d_reg = (uint32_t *) BLSP2_UART2_APPS_D,
159
160 .set_rate = clock_lib2_rcg_set_rate_mnd,
161 .freq_tbl = ftbl_gcc_blsp1_2_uart1_6_apps_clk,
162 .current_freq = &rcg_dummy_freq,
163
164 .c = {
165 .dbg_name = "blsp1_uart2_apps_clk",
166 .ops = &clk_ops_rcg_mnd,
167 },
168};
169
170static struct rcg_clk blsp1_uart2_apps_clk_src =
171{
172 .cmd_reg = (uint32_t *) BLSP1_UART2_APPS_CMD_RCGR,
173 .cfg_reg = (uint32_t *) BLSP1_UART2_APPS_CFG_RCGR,
174 .m_reg = (uint32_t *) BLSP1_UART2_APPS_M,
175 .n_reg = (uint32_t *) BLSP1_UART2_APPS_N,
176 .d_reg = (uint32_t *) BLSP1_UART2_APPS_D,
177
178 .set_rate = clock_lib2_rcg_set_rate_mnd,
179 .freq_tbl = ftbl_gcc_blsp1_2_uart1_6_apps_clk,
180 .current_freq = &rcg_dummy_freq,
181
182 .c = {
183 .dbg_name = "blsp1_uart2_apps_clk",
184 .ops = &clk_ops_rcg_mnd,
185 },
186};
187
188static struct branch_clk gcc_blsp2_uart2_apps_clk =
189{
190 .cbcr_reg = (uint32_t *) BLSP2_UART2_APPS_CBCR,
191 .parent = &blsp2_uart2_apps_clk_src.c,
192
193 .c = {
194 .dbg_name = "gcc_blsp2_uart2_apps_clk",
195 .ops = &clk_ops_branch,
196 },
197};
198
199static struct branch_clk gcc_blsp1_uart2_apps_clk =
200{
201 .cbcr_reg = (uint32_t *) BLSP1_UART2_APPS_CBCR,
202 .parent = &blsp1_uart2_apps_clk_src.c,
203
204 .c = {
205 .dbg_name = "gcc_blsp1_uart2_apps_clk",
206 .ops = &clk_ops_branch,
207 },
208};
209
210static struct vote_clk gcc_blsp1_ahb_clk = {
211 .cbcr_reg = (uint32_t *) BLSP1_AHB_CBCR,
212 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
213 .en_mask = BIT(17),
214
215 .c = {
216 .dbg_name = "gcc_blsp1_ahb_clk",
217 .ops = &clk_ops_vote,
218 },
219};
220
221static struct vote_clk gcc_blsp2_ahb_clk = {
222 .cbcr_reg = (uint32_t *) BLSP2_AHB_CBCR,
223 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
224 .en_mask = BIT(15),
225
226 .c = {
227 .dbg_name = "gcc_blsp2_ahb_clk",
228 .ops = &clk_ops_vote,
229 },
230};
231
232/* USB Clocks */
233static struct clk_freq_tbl ftbl_gcc_usb_hs_system_clk[] =
234{
235 F(75000000, gpll0, 8, 0, 0),
236 F_END
237};
238
239static struct rcg_clk usb_hs_system_clk_src =
240{
241 .cmd_reg = (uint32_t *) USB_HS_SYSTEM_CMD_RCGR,
242 .cfg_reg = (uint32_t *) USB_HS_SYSTEM_CFG_RCGR,
243
244 .set_rate = clock_lib2_rcg_set_rate_hid,
245 .freq_tbl = ftbl_gcc_usb_hs_system_clk,
246 .current_freq = &rcg_dummy_freq,
247
248 .c = {
249 .dbg_name = "usb_hs_system_clk",
250 .ops = &clk_ops_rcg,
251 },
252};
253
254static struct branch_clk gcc_usb_hs_system_clk =
255{
256 .cbcr_reg = (uint32_t *) USB_HS_SYSTEM_CBCR,
257 .parent = &usb_hs_system_clk_src.c,
258
259 .c = {
260 .dbg_name = "gcc_usb_hs_system_clk",
261 .ops = &clk_ops_branch,
262 },
263};
264
265static struct branch_clk gcc_usb_hs_ahb_clk =
266{
267 .cbcr_reg = (uint32_t *) USB_HS_AHB_CBCR,
268 .has_sibling = 1,
269
270 .c = {
271 .dbg_name = "gcc_usb_hs_ahb_clk",
272 .ops = &clk_ops_branch,
273 },
274};
275
276/* SDCC Clocks */
277static struct clk_freq_tbl ftbl_gcc_sdcc1_4_apps_clk[] =
278{
279 F( 144000, cxo, 16, 3, 25),
280 F( 400000, cxo, 12, 1, 4),
281 F( 20000000, gpll0, 15, 1, 2),
282 F( 25000000, gpll0, 12, 1, 2),
283 F( 50000000, gpll0, 12, 0, 0),
284 F( 96000000, gpll4, 16, 0, 0),
285 F(192000000, gpll4, 8, 0, 0),
286 F(384000000, gpll4, 4, 0, 0),
287 F_END
288};
289
290static struct rcg_clk sdcc1_apps_clk_src =
291{
292 .cmd_reg = (uint32_t *) SDCC1_CMD_RCGR,
293 .cfg_reg = (uint32_t *) SDCC1_CFG_RCGR,
294 .m_reg = (uint32_t *) SDCC1_M,
295 .n_reg = (uint32_t *) SDCC1_N,
296 .d_reg = (uint32_t *) SDCC1_D,
297
298 .set_rate = clock_lib2_rcg_set_rate_mnd,
299 .freq_tbl = ftbl_gcc_sdcc1_4_apps_clk,
300 .current_freq = &rcg_dummy_freq,
301
302 .c = {
303 .dbg_name = "sdc1_clk",
304 .ops = &clk_ops_rcg_mnd,
305 },
306};
307
308static struct branch_clk gcc_sdcc1_apps_clk =
309{
310 .cbcr_reg = (uint32_t *) SDCC1_APPS_CBCR,
311 .parent = &sdcc1_apps_clk_src.c,
312
313 .c = {
314 .dbg_name = "gcc_sdcc1_apps_clk",
315 .ops = &clk_ops_branch,
316 },
317};
318
319static struct branch_clk gcc_sdcc1_ahb_clk =
320{
321 .cbcr_reg = (uint32_t *) SDCC1_AHB_CBCR,
322 .has_sibling = 1,
323
324 .c = {
325 .dbg_name = "gcc_sdcc1_ahb_clk",
326 .ops = &clk_ops_branch,
327 },
328};
329
330/* Clock lookup table */
Channagoud Kadabi608b6a72014-04-14 13:58:03 -0700331static struct clk_lookup msm_8994_clocks[] =
Channagoud Kadabi123c9722014-02-06 13:22:50 -0800332{
333 CLK_LOOKUP("sdc1_iface_clk", gcc_sdcc1_ahb_clk.c),
334 CLK_LOOKUP("sdc1_core_clk", gcc_sdcc1_apps_clk.c),
335
336 CLK_LOOKUP("uart2_iface_clk", gcc_blsp1_ahb_clk.c),
337 CLK_LOOKUP("uart2_core_clk", gcc_blsp1_uart2_apps_clk.c),
338
339 CLK_LOOKUP("usb_iface_clk", gcc_usb_hs_ahb_clk.c),
340 CLK_LOOKUP("usb_core_clk", gcc_usb_hs_system_clk.c),
341};
342
343void platform_clock_init(void)
344{
Channagoud Kadabi608b6a72014-04-14 13:58:03 -0700345 clk_init(msm_8994_clocks, ARRAY_SIZE(msm_8994_clocks));
Channagoud Kadabi123c9722014-02-06 13:22:50 -0800346}