blob: ed7ace2a10847205ddbea66a51e6362bb31ad981 [file] [log] [blame]
Amol Jadi29f95032012-06-22 12:52:54 -07001/*
2 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 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 copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of Code Aurora nor
12 * the names of its contributors may be used to endorse or promote
13 * products derived from this software without specific prior written
14 * permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * 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
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,
215 .vote_reg = APCS_CLOCK_BRANCH_ENA_VOTE,
216 .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
224/* USB Clocks */
225static struct clk_freq_tbl ftbl_gcc_usb_hs_system_clk[] =
226{
227 F(75000000, gpll0, 8, 0, 0),
228 F_END
229};
230
231static struct rcg_clk usb_hs_system_clk_src =
232{
233 .cmd_reg = (uint32_t *) USB_HS_SYSTEM_CMD_RCGR,
234 .cfg_reg = (uint32_t *) USB_HS_SYSTEM_CFG_RCGR,
235
236 .set_rate = clock_lib2_rcg_set_rate_hid,
237 .freq_tbl = ftbl_gcc_usb_hs_system_clk,
238 .current_freq = &rcg_dummy_freq,
239
240 .c = {
241 .dbg_name = "usb_hs_system_clk",
242 .ops = &clk_ops_rcg,
243 },
244};
245
246static struct branch_clk gcc_usb_hs_system_clk =
247{
248 .cbcr_reg = (uint32_t *) USB_HS_SYSTEM_CBCR,
249 .parent = &usb_hs_system_clk_src.c,
250
251 .c = {
252 .dbg_name = "gcc_usb_hs_system_clk",
253 .ops = &clk_ops_branch,
254 },
255};
256
257static struct branch_clk gcc_usb_hs_ahb_clk =
258{
259 .cbcr_reg = (uint32_t *) USB_HS_AHB_CBCR,
260 .has_sibling = 1,
261
262 .c = {
263 .dbg_name = "gcc_usb_hs_ahb_clk",
264 .ops = &clk_ops_branch,
265 },
266};
267
268
269/* Clock lookup table */
270static struct clk_lookup msm_clocks_8974[] =
271{
272 CLK_LOOKUP("sdc1_iface_clk", gcc_sdcc1_ahb_clk.c),
273 CLK_LOOKUP("sdc1_core_clk", gcc_sdcc1_apps_clk.c),
274
Neeti Desaiac011272012-08-29 18:24:54 -0700275 CLK_LOOKUP("uart2_iface_clk", gcc_blsp1_ahb_clk.c),
276 CLK_LOOKUP("uart2_core_clk", gcc_blsp1_uart2_apps_clk.c),
Amol Jadi29f95032012-06-22 12:52:54 -0700277
278 CLK_LOOKUP("usb_iface_clk", gcc_usb_hs_ahb_clk.c),
279 CLK_LOOKUP("usb_core_clk", gcc_usb_hs_system_clk.c),
280};
281
282
283void platform_clock_init(void)
284{
285 clk_init(msm_clocks_8974, ARRAY_SIZE(msm_clocks_8974));
286}