blob: ccee3427183474c49cb02eb6612f9446e0d8a958 [file] [log] [blame]
Channagoud Kadabi634ac6d2012-12-12 18:13:56 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Amol Jadi29f95032012-06-22 12:52:54 -07002 *
3 * Redistribution and use in source and binary forms, with or without
Deepa Dinamani32bfad02012-11-02 12:15:05 -07004 * 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.
Amol Jadi29f95032012-06-22 12:52:54 -070015 *
Deepa Dinamani32bfad02012-11-02 12:15:05 -070016 * 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.
Amol Jadi29f95032012-06-22 12:52:54 -070027 */
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
43struct clk_freq_tbl rcg_dummy_freq = F_END;
44
45
46/* Clock Operations */
47static struct clk_ops clk_ops_branch =
48{
49 .enable = clock_lib2_branch_clk_enable,
50 .disable = clock_lib2_branch_clk_disable,
51 .set_rate = clock_lib2_branch_set_rate,
52};
53
54static struct clk_ops clk_ops_rcg_mnd =
55{
56 .enable = clock_lib2_rcg_enable,
57 .set_rate = clock_lib2_rcg_set_rate,
58};
59
60static struct clk_ops clk_ops_rcg =
61{
62 .enable = clock_lib2_rcg_enable,
63 .set_rate = clock_lib2_rcg_set_rate,
64};
65
66static struct clk_ops clk_ops_cxo =
67{
68 .enable = cxo_clk_enable,
69 .disable = cxo_clk_disable,
70};
71
72static struct clk_ops clk_ops_pll_vote =
73{
74 .enable = pll_vote_clk_enable,
75 .disable = pll_vote_clk_disable,
76 .auto_off = pll_vote_clk_disable,
77 .is_enabled = pll_vote_clk_is_enabled,
78};
79
Neeti Desaiac011272012-08-29 18:24:54 -070080static struct clk_ops clk_ops_vote =
81{
82 .enable = clock_lib2_vote_clk_enable,
83 .disable = clock_lib2_vote_clk_disable,
84};
Amol Jadi29f95032012-06-22 12:52:54 -070085
86/* Clock Sources */
87static struct fixed_clk cxo_clk_src =
88{
89 .c = {
90 .rate = 19200000,
91 .dbg_name = "cxo_clk_src",
92 .ops = &clk_ops_cxo,
93 },
94};
95
96static struct pll_vote_clk gpll0_clk_src =
97{
98 .en_reg = (void *) APCS_GPLL_ENA_VOTE,
99 .en_mask = BIT(0),
100 .status_reg = (void *) GPLL0_STATUS,
101 .status_mask = BIT(17),
102 .parent = &cxo_clk_src.c,
103
104 .c = {
105 .rate = 600000000,
106 .dbg_name = "gpll0_clk_src",
107 .ops = &clk_ops_pll_vote,
108 },
109};
110
111/* SDCC Clocks */
112static struct clk_freq_tbl ftbl_gcc_sdcc1_2_apps_clk[] =
113{
114 F( 144000, cxo, 16, 3, 25),
115 F( 400000, cxo, 12, 1, 4),
116 F( 20000000, gpll0, 15, 1, 2),
117 F( 25000000, gpll0, 12, 1, 2),
118 F( 50000000, gpll0, 12, 0, 0),
119 F(100000000, gpll0, 6, 0, 0),
120 F(200000000, gpll0, 3, 0, 0),
121 F_END
122};
123
124static struct rcg_clk sdcc1_apps_clk_src =
125{
126 .cmd_reg = (uint32_t *) SDCC1_CMD_RCGR,
127 .cfg_reg = (uint32_t *) SDCC1_CFG_RCGR,
128 .m_reg = (uint32_t *) SDCC1_M,
129 .n_reg = (uint32_t *) SDCC1_N,
130 .d_reg = (uint32_t *) SDCC1_D,
131
132 .set_rate = clock_lib2_rcg_set_rate_mnd,
133 .freq_tbl = ftbl_gcc_sdcc1_2_apps_clk,
134 .current_freq = &rcg_dummy_freq,
135
136 .c = {
137 .dbg_name = "sdc1_clk",
138 .ops = &clk_ops_rcg_mnd,
139 },
140};
141
142static struct branch_clk gcc_sdcc1_apps_clk =
143{
144 .cbcr_reg = (uint32_t *) SDCC1_APPS_CBCR,
145 .parent = &sdcc1_apps_clk_src.c,
146
147 .c = {
148 .dbg_name = "gcc_sdcc1_apps_clk",
149 .ops = &clk_ops_branch,
150 },
151};
152
153static struct branch_clk gcc_sdcc1_ahb_clk =
154{
155 .cbcr_reg = (uint32_t *) SDCC1_AHB_CBCR,
156 .has_sibling = 1,
157
158 .c = {
159 .dbg_name = "gcc_sdcc1_ahb_clk",
160 .ops = &clk_ops_branch,
161 },
162};
163
164/* UART Clocks */
165static struct clk_freq_tbl ftbl_gcc_blsp1_2_uart1_6_apps_clk[] =
166{
167 F( 3686400, gpll0, 1, 96, 15625),
168 F( 7372800, gpll0, 1, 192, 15625),
169 F(14745600, gpll0, 1, 384, 15625),
170 F(16000000, gpll0, 5, 2, 15),
171 F(19200000, cxo, 1, 0, 0),
172 F(24000000, gpll0, 5, 1, 5),
173 F(32000000, gpll0, 1, 4, 75),
174 F(40000000, gpll0, 15, 0, 0),
175 F(46400000, gpll0, 1, 29, 375),
176 F(48000000, gpll0, 12.5, 0, 0),
177 F(51200000, gpll0, 1, 32, 375),
178 F(56000000, gpll0, 1, 7, 75),
179 F(58982400, gpll0, 1, 1536, 15625),
180 F(60000000, gpll0, 10, 0, 0),
181 F_END
182};
183
Neeti Desaiac011272012-08-29 18:24:54 -0700184static struct rcg_clk blsp1_uart2_apps_clk_src =
Amol Jadi29f95032012-06-22 12:52:54 -0700185{
Neeti Desaiac011272012-08-29 18:24:54 -0700186 .cmd_reg = (uint32_t *) BLSP1_UART2_APPS_CMD_RCGR,
187 .cfg_reg = (uint32_t *) BLSP1_UART2_APPS_CFG_RCGR,
188 .m_reg = (uint32_t *) BLSP1_UART2_APPS_M,
189 .n_reg = (uint32_t *) BLSP1_UART2_APPS_N,
190 .d_reg = (uint32_t *) BLSP1_UART2_APPS_D,
Amol Jadi29f95032012-06-22 12:52:54 -0700191
192 .set_rate = clock_lib2_rcg_set_rate_mnd,
193 .freq_tbl = ftbl_gcc_blsp1_2_uart1_6_apps_clk,
194 .current_freq = &rcg_dummy_freq,
195
196 .c = {
Neeti Desaiac011272012-08-29 18:24:54 -0700197 .dbg_name = "blsp1_uart2_apps_clk",
Amol Jadi29f95032012-06-22 12:52:54 -0700198 .ops = &clk_ops_rcg_mnd,
199 },
200};
201
Neeti Desaiac011272012-08-29 18:24:54 -0700202static struct branch_clk gcc_blsp1_uart2_apps_clk =
Amol Jadi29f95032012-06-22 12:52:54 -0700203{
Neeti Desaiac011272012-08-29 18:24:54 -0700204 .cbcr_reg = (uint32_t *) BLSP1_UART2_APPS_CBCR,
205 .parent = &blsp1_uart2_apps_clk_src.c,
Amol Jadi29f95032012-06-22 12:52:54 -0700206
207 .c = {
Neeti Desaiac011272012-08-29 18:24:54 -0700208 .dbg_name = "gcc_blsp1_uart2_apps_clk",
Amol Jadi29f95032012-06-22 12:52:54 -0700209 .ops = &clk_ops_branch,
210 },
211};
212
Neeti Desaiac011272012-08-29 18:24:54 -0700213static struct vote_clk gcc_blsp1_ahb_clk = {
214 .cbcr_reg = (uint32_t *) BLSP1_AHB_CBCR,
Deepa Dinamani32bfad02012-11-02 12:15:05 -0700215 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
Neeti Desaiac011272012-08-29 18:24:54 -0700216 .en_mask = BIT(17),
Amol Jadi29f95032012-06-22 12:52:54 -0700217
218 .c = {
Neeti Desaiac011272012-08-29 18:24:54 -0700219 .dbg_name = "gcc_blsp1_ahb_clk",
220 .ops = &clk_ops_vote,
Amol Jadi29f95032012-06-22 12:52:54 -0700221 },
222};
223
Channagoud Kadabi634ac6d2012-12-12 18:13:56 -0800224static struct vote_clk gcc_blsp2_ahb_clk = {
225 .cbcr_reg = (uint32_t *) BLSP2_AHB_CBCR,
226 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
227 .en_mask = BIT(15),
228
229 .c = {
230 .dbg_name = "gcc_blsp2_ahb_clk",
231 .ops = &clk_ops_vote,
232 },
233};
234
Amol Jadi29f95032012-06-22 12:52:54 -0700235/* USB Clocks */
236static struct clk_freq_tbl ftbl_gcc_usb_hs_system_clk[] =
237{
238 F(75000000, gpll0, 8, 0, 0),
239 F_END
240};
241
242static struct rcg_clk usb_hs_system_clk_src =
243{
244 .cmd_reg = (uint32_t *) USB_HS_SYSTEM_CMD_RCGR,
245 .cfg_reg = (uint32_t *) USB_HS_SYSTEM_CFG_RCGR,
246
247 .set_rate = clock_lib2_rcg_set_rate_hid,
248 .freq_tbl = ftbl_gcc_usb_hs_system_clk,
249 .current_freq = &rcg_dummy_freq,
250
251 .c = {
252 .dbg_name = "usb_hs_system_clk",
253 .ops = &clk_ops_rcg,
254 },
255};
256
257static struct branch_clk gcc_usb_hs_system_clk =
258{
259 .cbcr_reg = (uint32_t *) USB_HS_SYSTEM_CBCR,
260 .parent = &usb_hs_system_clk_src.c,
261
262 .c = {
263 .dbg_name = "gcc_usb_hs_system_clk",
264 .ops = &clk_ops_branch,
265 },
266};
267
268static struct branch_clk gcc_usb_hs_ahb_clk =
269{
270 .cbcr_reg = (uint32_t *) USB_HS_AHB_CBCR,
271 .has_sibling = 1,
272
273 .c = {
274 .dbg_name = "gcc_usb_hs_ahb_clk",
275 .ops = &clk_ops_branch,
276 },
277};
278
Deepa Dinamani32bfad02012-11-02 12:15:05 -0700279/* CE Clocks */
280static struct clk_freq_tbl ftbl_gcc_ce2_clk[] = {
281 F( 50000000, gpll0, 12, 0, 0),
282 F(100000000, gpll0, 6, 0, 0),
283 F_END
284};
285
286static struct rcg_clk ce2_clk_src = {
287 .cmd_reg = (uint32_t *) GCC_CE2_CMD_RCGR,
288 .cfg_reg = (uint32_t *) GCC_CE2_CFG_RCGR,
289 .set_rate = clock_lib2_rcg_set_rate_hid,
290 .freq_tbl = ftbl_gcc_ce2_clk,
291 .current_freq = &rcg_dummy_freq,
292
293 .c = {
294 .dbg_name = "ce2_clk_src",
295 .ops = &clk_ops_rcg,
296 },
297};
298
299static struct vote_clk gcc_ce2_clk = {
300 .cbcr_reg = (uint32_t *) GCC_CE2_CBCR,
301 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
302 .en_mask = BIT(2),
303
304 .c = {
305 .dbg_name = "gcc_ce2_clk",
306 .ops = &clk_ops_vote,
307 },
308};
309
310static struct vote_clk gcc_ce2_ahb_clk = {
311 .cbcr_reg = (uint32_t *) GCC_CE2_AHB_CBCR,
312 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
313 .en_mask = BIT(0),
314
315 .c = {
316 .dbg_name = "gcc_ce2_ahb_clk",
317 .ops = &clk_ops_vote,
318 },
319};
320
321static struct vote_clk gcc_ce2_axi_clk = {
322 .cbcr_reg = (uint32_t *) GCC_CE2_AXI_CBCR,
323 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
324 .en_mask = BIT(1),
325
326 .c = {
327 .dbg_name = "gcc_ce2_axi_clk",
328 .ops = &clk_ops_vote,
329 },
330};
Amol Jadi29f95032012-06-22 12:52:54 -0700331
Channagoud Kadabi634ac6d2012-12-12 18:13:56 -0800332struct branch_clk gcc_blsp2_qup5_i2c_apps_clk = {
333 .cbcr_reg = BLSP2_QUP5_I2C_APPS_CBCR,
334 .parent = &cxo_clk_src.c,
335
336 .c = {
337 .dbg_name = "gcc_blsp2_qup5_i2c_apps_clk",
338 .ops = &clk_ops_branch,
339 },
340};
341
Amol Jadi29f95032012-06-22 12:52:54 -0700342/* Clock lookup table */
343static struct clk_lookup msm_clocks_8974[] =
344{
345 CLK_LOOKUP("sdc1_iface_clk", gcc_sdcc1_ahb_clk.c),
346 CLK_LOOKUP("sdc1_core_clk", gcc_sdcc1_apps_clk.c),
347
Neeti Desaiac011272012-08-29 18:24:54 -0700348 CLK_LOOKUP("uart2_iface_clk", gcc_blsp1_ahb_clk.c),
349 CLK_LOOKUP("uart2_core_clk", gcc_blsp1_uart2_apps_clk.c),
Amol Jadi29f95032012-06-22 12:52:54 -0700350
351 CLK_LOOKUP("usb_iface_clk", gcc_usb_hs_ahb_clk.c),
352 CLK_LOOKUP("usb_core_clk", gcc_usb_hs_system_clk.c),
Deepa Dinamani32bfad02012-11-02 12:15:05 -0700353
354 CLK_LOOKUP("ce2_ahb_clk", gcc_ce2_ahb_clk.c),
355 CLK_LOOKUP("ce2_axi_clk", gcc_ce2_axi_clk.c),
356 CLK_LOOKUP("ce2_core_clk", gcc_ce2_clk.c),
357 CLK_LOOKUP("ce2_src_clk", ce2_clk_src.c),
Channagoud Kadabi634ac6d2012-12-12 18:13:56 -0800358
359 CLK_LOOKUP("blsp2_ahb_clk", gcc_blsp2_ahb_clk.c),
360 CLK_LOOKUP("blsp2_qup5_i2c_apps_clk", gcc_blsp2_qup5_i2c_apps_clk.c),
Amol Jadi29f95032012-06-22 12:52:54 -0700361};
362
363
364void platform_clock_init(void)
365{
366 clk_init(msm_clocks_8974, ARRAY_SIZE(msm_clocks_8974));
367}