blob: 0515842b933199c422335a8ea3f342f31d7c765e [file] [log] [blame]
vijay kumarca1672a2015-04-09 16:45:40 +05301/* Copyright (c) 2015, 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#include <platform.h>
38
39/* Mux source select values */
40#define cxo_source_val 0
41#define gpll0_source_val 1
42#define gpll4_source_val 2
43#define cxo_mm_source_val 0
44#define gpll0_mm_source_val 1
45
46struct clk_freq_tbl rcg_dummy_freq = F_END;
47
48
49/* Clock Operations */
50static struct clk_ops clk_ops_branch =
51{
52 .enable = clock_lib2_branch_clk_enable,
53 .disable = clock_lib2_branch_clk_disable,
54 .set_rate = clock_lib2_branch_set_rate,
55};
56
57static struct clk_ops clk_ops_rcg_mnd =
58{
59 .enable = clock_lib2_rcg_enable,
60 .set_rate = clock_lib2_rcg_set_rate,
61};
62
63static struct clk_ops clk_ops_rcg =
64{
65 .enable = clock_lib2_rcg_enable,
66 .set_rate = clock_lib2_rcg_set_rate,
67};
68
69static struct clk_ops clk_ops_cxo =
70{
71 .enable = cxo_clk_enable,
72 .disable = cxo_clk_disable,
73};
74
75static struct clk_ops clk_ops_pll_vote =
76{
77 .enable = pll_vote_clk_enable,
78 .disable = pll_vote_clk_disable,
79 .auto_off = pll_vote_clk_disable,
80 .is_enabled = pll_vote_clk_is_enabled,
81};
82
83static struct clk_ops clk_ops_vote =
84{
85 .enable = clock_lib2_vote_clk_enable,
86 .disable = clock_lib2_vote_clk_disable,
87};
88
89/* Clock Sources */
90static struct fixed_clk cxo_clk_src =
91{
92 .c = {
93 .rate = 19200000,
94 .dbg_name = "cxo_clk_src",
95 .ops = &clk_ops_cxo,
96 },
97};
98
99static struct pll_vote_clk gpll0_clk_src =
100{
101 .en_reg = (void *) APCS_GPLL_ENA_VOTE,
102 .en_mask = BIT(0),
vijay kumar20627da2015-10-01 13:28:58 +0530103 .status_reg = (void *) GPLL0_MODE,
104 .status_mask = BIT(30),
vijay kumarca1672a2015-04-09 16:45:40 +0530105 .parent = &cxo_clk_src.c,
106
107 .c = {
108 .rate = 800000000,
109 .dbg_name = "gpll0_clk_src",
110 .ops = &clk_ops_pll_vote,
111 },
112};
113
114/* UART Clocks */
vijay kumar20627da2015-10-01 13:28:58 +0530115static struct clk_freq_tbl ftbl_gcc_blsp1_2_uart5_apps_clk[] =
vijay kumarca1672a2015-04-09 16:45:40 +0530116{
117 F( 3686400, gpll0, 1, 72, 15625),
118 F( 7372800, gpll0, 1, 144, 15625),
119 F(14745600, gpll0, 1, 288, 15625),
120 F(16000000, gpll0, 10, 1, 5),
121 F(19200000, cxo, 1, 0, 0),
122 F(24000000, gpll0, 1, 3, 100),
123 F(25000000, gpll0, 16, 1, 2),
124 F(32000000, gpll0, 1, 1, 25),
125 F(40000000, gpll0, 1, 1, 20),
126 F(46400000, gpll0, 1, 29, 500),
127 F(48000000, gpll0, 1, 3, 50),
128 F(51200000, gpll0, 1, 8, 125),
129 F(56000000, gpll0, 1, 7, 100),
130 F(58982400, gpll0, 1,1152, 15625),
131 F(60000000, gpll0, 1, 3, 40),
132 F_END
133};
134
vijay kumar20627da2015-10-01 13:28:58 +0530135static struct rcg_clk blsp1_uart5_apps_clk_src =
vijay kumarca1672a2015-04-09 16:45:40 +0530136{
vijay kumar20627da2015-10-01 13:28:58 +0530137 .cmd_reg = (uint32_t *) BLSP1_UART5_APPS_CMD_RCGR,
138 .cfg_reg = (uint32_t *) BLSP1_UART5_APPS_CFG_RCGR,
139 .m_reg = (uint32_t *) BLSP1_UART5_APPS_M,
140 .n_reg = (uint32_t *) BLSP1_UART5_APPS_N,
141 .d_reg = (uint32_t *) BLSP1_UART5_APPS_D,
vijay kumarca1672a2015-04-09 16:45:40 +0530142
143 .set_rate = clock_lib2_rcg_set_rate_mnd,
vijay kumar20627da2015-10-01 13:28:58 +0530144 .freq_tbl = ftbl_gcc_blsp1_2_uart5_apps_clk,
vijay kumarca1672a2015-04-09 16:45:40 +0530145 .current_freq = &rcg_dummy_freq,
146
147 .c = {
148 .dbg_name = "blsp1_uart2_apps_clk",
149 .ops = &clk_ops_rcg_mnd,
150 },
151};
152
vijay kumar20627da2015-10-01 13:28:58 +0530153static struct branch_clk gcc_blsp1_uart5_apps_clk =
vijay kumarca1672a2015-04-09 16:45:40 +0530154{
vijay kumar20627da2015-10-01 13:28:58 +0530155 .cbcr_reg = (uint32_t *) BLSP1_UART5_APPS_CBCR,
156 .parent = &blsp1_uart5_apps_clk_src.c,
vijay kumarca1672a2015-04-09 16:45:40 +0530157
158 .c = {
vijay kumar20627da2015-10-01 13:28:58 +0530159 .dbg_name = "gcc_blsp1_uart5_apps_clk",
vijay kumarca1672a2015-04-09 16:45:40 +0530160 .ops = &clk_ops_branch,
161 },
162};
163
164static struct vote_clk gcc_blsp1_ahb_clk = {
165 .cbcr_reg = (uint32_t *) BLSP1_AHB_CBCR,
166 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
167 .en_mask = BIT(10),
168
169 .c = {
170 .dbg_name = "gcc_blsp1_ahb_clk",
171 .ops = &clk_ops_vote,
172 },
173};
174
175/* USB Clocks */
176static struct clk_freq_tbl ftbl_gcc_usb_hs_system_clk[] =
177{
178 F(133330000, gpll0, 6, 0, 0),
179 F_END
180};
181
182static struct rcg_clk usb_hs_system_clk_src =
183{
184 .cmd_reg = (uint32_t *) USB_HS_SYSTEM_CMD_RCGR,
185 .cfg_reg = (uint32_t *) USB_HS_SYSTEM_CFG_RCGR,
186
187 .set_rate = clock_lib2_rcg_set_rate_hid,
188 .freq_tbl = ftbl_gcc_usb_hs_system_clk,
189 .current_freq = &rcg_dummy_freq,
190
191 .c = {
192 .dbg_name = "usb_hs_system_clk",
193 .ops = &clk_ops_rcg,
194 },
195};
196
197static struct branch_clk gcc_usb_hs_system_clk =
198{
199 .cbcr_reg = (uint32_t *) USB_HS_SYSTEM_CBCR,
200 .parent = &usb_hs_system_clk_src.c,
201
202 .c = {
203 .dbg_name = "gcc_usb_hs_system_clk",
204 .ops = &clk_ops_branch,
205 },
206};
207
208static struct branch_clk gcc_usb_hs_ahb_clk =
209{
210 .cbcr_reg = (uint32_t *) USB_HS_AHB_CBCR,
211 .has_sibling = 1,
212
213 .c = {
214 .dbg_name = "gcc_usb_hs_ahb_clk",
215 .ops = &clk_ops_branch,
216 },
217};
vijay kumar70dbe3e2015-11-20 13:07:30 +0530218static struct clk_freq_tbl ftbl_gcc_ce1_clk[] = {
219 F(160000000, gpll0, 5, 0, 0),
220 F_END
221};
222
223static struct rcg_clk ce1_clk_src = {
224 .cmd_reg = (uint32_t *) GCC_CRYPTO_CMD_RCGR,
225 .cfg_reg = (uint32_t *) GCC_CRYPTO_CFG_RCGR,
226 .set_rate = clock_lib2_rcg_set_rate_hid,
227 .freq_tbl = ftbl_gcc_ce1_clk,
228 .current_freq = &rcg_dummy_freq,
229
230 .c = {
231 .dbg_name = "ce1_clk_src",
232 .ops = &clk_ops_rcg,
233 },
234};
235
236static struct vote_clk gcc_ce1_clk = {
237 .cbcr_reg = (uint32_t *) GCC_CRYPTO_CBCR,
238 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
239 .en_mask = BIT(2),
240
241 .c = {
242 .dbg_name = "gcc_ce1_clk",
243 .ops = &clk_ops_vote,
244 },
245};
246
247static struct vote_clk gcc_ce1_ahb_clk = {
248 .cbcr_reg = (uint32_t *) GCC_CRYPTO_AHB_CBCR,
249 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
250 .en_mask = BIT(0),
251
252 .c = {
253 .dbg_name = "gcc_ce1_ahb_clk",
254 .ops = &clk_ops_vote,
255 },
256};
257
258static struct vote_clk gcc_ce1_axi_clk = {
259 .cbcr_reg = (uint32_t *) GCC_CRYPTO_AXI_CBCR,
260 .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE,
261 .en_mask = BIT(1),
262
263 .c = {
264 .dbg_name = "gcc_ce1_axi_clk",
265 .ops = &clk_ops_vote,
266 },
267};
vijay kumarca1672a2015-04-09 16:45:40 +0530268
269/* Clock lookup table */
vijay kumardb062a32015-10-30 12:32:15 +0530270static struct clk_lookup mdm_clocks_9607[] =
vijay kumarca1672a2015-04-09 16:45:40 +0530271{
vijay kumar20627da2015-10-01 13:28:58 +0530272 CLK_LOOKUP("uart5_iface_clk", gcc_blsp1_ahb_clk.c),
273 CLK_LOOKUP("uart5_core_clk", gcc_blsp1_uart5_apps_clk.c),
vijay kumarca1672a2015-04-09 16:45:40 +0530274
275 CLK_LOOKUP("usb_iface_clk", gcc_usb_hs_ahb_clk.c),
276 CLK_LOOKUP("usb_core_clk", gcc_usb_hs_system_clk.c),
277
vijay kumar70dbe3e2015-11-20 13:07:30 +0530278 CLK_LOOKUP("ce1_ahb_clk", gcc_ce1_ahb_clk.c),
279 CLK_LOOKUP("ce1_axi_clk", gcc_ce1_axi_clk.c),
280 CLK_LOOKUP("ce1_core_clk", gcc_ce1_clk.c),
281 CLK_LOOKUP("ce1_src_clk", ce1_clk_src.c),
vijay kumarca1672a2015-04-09 16:45:40 +0530282};
283
284void platform_clock_init(void)
285{
vijay kumardb062a32015-10-30 12:32:15 +0530286 clk_init(mdm_clocks_9607, ARRAY_SIZE(mdm_clocks_9607));
vijay kumarca1672a2015-04-09 16:45:40 +0530287}