Deepa Dinamani | 554b062 | 2013-05-16 15:00:30 -0700 | [diff] [blame] | 1 | /* Copyright (c) 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 | |
| 48 | struct clk_freq_tbl rcg_dummy_freq = F_END; |
| 49 | |
| 50 | |
| 51 | /* Clock Operations */ |
| 52 | static 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 | |
| 59 | static struct clk_ops clk_ops_rcg_mnd = |
| 60 | { |
| 61 | .enable = clock_lib2_rcg_enable, |
| 62 | .set_rate = clock_lib2_rcg_set_rate, |
| 63 | }; |
| 64 | |
| 65 | static struct clk_ops clk_ops_rcg = |
| 66 | { |
| 67 | .enable = clock_lib2_rcg_enable, |
| 68 | .set_rate = clock_lib2_rcg_set_rate, |
| 69 | }; |
| 70 | |
| 71 | static struct clk_ops clk_ops_cxo = |
| 72 | { |
| 73 | .enable = cxo_clk_enable, |
| 74 | .disable = cxo_clk_disable, |
| 75 | }; |
| 76 | |
| 77 | static 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 | |
| 85 | static 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 */ |
| 92 | static 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 | |
Sundarajan Srinivasan | 09374ed | 2013-06-18 13:29:32 -0700 | [diff] [blame] | 101 | static 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 | /* UART Clocks */ |
| 117 | static struct clk_freq_tbl ftbl_gcc_blsp1_2_uart1_6_apps_clk[] = |
| 118 | { |
| 119 | F( 3686400, gpll0, 1, 96, 15625), |
| 120 | F( 7372800, gpll0, 1, 192, 15625), |
| 121 | F(14745600, gpll0, 1, 384, 15625), |
| 122 | F(16000000, gpll0, 5, 2, 15), |
| 123 | F(19200000, cxo, 1, 0, 0), |
| 124 | F(24000000, gpll0, 5, 1, 5), |
| 125 | F(32000000, gpll0, 1, 4, 75), |
| 126 | F(40000000, gpll0, 15, 0, 0), |
| 127 | F(46400000, gpll0, 1, 29, 375), |
| 128 | F(48000000, gpll0, 12.5, 0, 0), |
| 129 | F(51200000, gpll0, 1, 32, 375), |
| 130 | F(56000000, gpll0, 1, 7, 75), |
| 131 | F(58982400, gpll0, 1, 1536, 15625), |
| 132 | F(60000000, gpll0, 10, 0, 0), |
| 133 | F_END |
| 134 | }; |
| 135 | |
Sundarajan Srinivasan | d8b7c6f | 2013-09-13 16:50:22 -0700 | [diff] [blame] | 136 | static struct rcg_clk blsp2_uart2_apps_clk_src = |
Sundarajan Srinivasan | 09374ed | 2013-06-18 13:29:32 -0700 | [diff] [blame] | 137 | { |
Sundarajan Srinivasan | d8b7c6f | 2013-09-13 16:50:22 -0700 | [diff] [blame] | 138 | .cmd_reg = (uint32_t *) BLSP2_UART2_APPS_CMD_RCGR, |
| 139 | .cfg_reg = (uint32_t *) BLSP2_UART2_APPS_CFG_RCGR, |
| 140 | .m_reg = (uint32_t *) BLSP2_UART2_APPS_M, |
| 141 | .n_reg = (uint32_t *) BLSP2_UART2_APPS_N, |
| 142 | .d_reg = (uint32_t *) BLSP2_UART2_APPS_D, |
Sundarajan Srinivasan | 09374ed | 2013-06-18 13:29:32 -0700 | [diff] [blame] | 143 | |
| 144 | .set_rate = clock_lib2_rcg_set_rate_mnd, |
| 145 | .freq_tbl = ftbl_gcc_blsp1_2_uart1_6_apps_clk, |
| 146 | .current_freq = &rcg_dummy_freq, |
| 147 | |
| 148 | .c = { |
| 149 | .dbg_name = "blsp1_uart2_apps_clk", |
| 150 | .ops = &clk_ops_rcg_mnd, |
| 151 | }, |
| 152 | }; |
| 153 | |
Sundarajan Srinivasan | d8b7c6f | 2013-09-13 16:50:22 -0700 | [diff] [blame] | 154 | static struct branch_clk gcc_blsp2_uart2_apps_clk = |
Sundarajan Srinivasan | 09374ed | 2013-06-18 13:29:32 -0700 | [diff] [blame] | 155 | { |
Sundarajan Srinivasan | d8b7c6f | 2013-09-13 16:50:22 -0700 | [diff] [blame] | 156 | .cbcr_reg = (uint32_t *) BLSP2_UART2_APPS_CBCR, |
| 157 | .parent = &blsp2_uart2_apps_clk_src.c, |
Sundarajan Srinivasan | 09374ed | 2013-06-18 13:29:32 -0700 | [diff] [blame] | 158 | |
| 159 | .c = { |
Sundarajan Srinivasan | d8b7c6f | 2013-09-13 16:50:22 -0700 | [diff] [blame] | 160 | .dbg_name = "gcc_blsp2_uart2_apps_clk", |
Sundarajan Srinivasan | 09374ed | 2013-06-18 13:29:32 -0700 | [diff] [blame] | 161 | .ops = &clk_ops_branch, |
| 162 | }, |
| 163 | }; |
| 164 | |
| 165 | static struct vote_clk gcc_blsp1_ahb_clk = { |
| 166 | .cbcr_reg = (uint32_t *) BLSP1_AHB_CBCR, |
| 167 | .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE, |
| 168 | .en_mask = BIT(17), |
| 169 | |
| 170 | .c = { |
| 171 | .dbg_name = "gcc_blsp1_ahb_clk", |
| 172 | .ops = &clk_ops_vote, |
| 173 | }, |
| 174 | }; |
| 175 | |
| 176 | static struct vote_clk gcc_blsp2_ahb_clk = { |
| 177 | .cbcr_reg = (uint32_t *) BLSP2_AHB_CBCR, |
| 178 | .vote_reg = (uint32_t *) APCS_CLOCK_BRANCH_ENA_VOTE, |
| 179 | .en_mask = BIT(15), |
| 180 | |
| 181 | .c = { |
| 182 | .dbg_name = "gcc_blsp2_ahb_clk", |
| 183 | .ops = &clk_ops_vote, |
| 184 | }, |
| 185 | }; |
| 186 | |
| 187 | /* USB Clocks */ |
| 188 | static struct clk_freq_tbl ftbl_gcc_usb_hs_system_clk[] = |
| 189 | { |
| 190 | F(75000000, gpll0, 8, 0, 0), |
| 191 | F_END |
| 192 | }; |
| 193 | |
| 194 | static struct rcg_clk usb_hs_system_clk_src = |
| 195 | { |
| 196 | .cmd_reg = (uint32_t *) USB_HS_SYSTEM_CMD_RCGR, |
| 197 | .cfg_reg = (uint32_t *) USB_HS_SYSTEM_CFG_RCGR, |
| 198 | |
| 199 | .set_rate = clock_lib2_rcg_set_rate_hid, |
| 200 | .freq_tbl = ftbl_gcc_usb_hs_system_clk, |
| 201 | .current_freq = &rcg_dummy_freq, |
| 202 | |
| 203 | .c = { |
| 204 | .dbg_name = "usb_hs_system_clk", |
| 205 | .ops = &clk_ops_rcg, |
| 206 | }, |
| 207 | }; |
| 208 | |
| 209 | static struct branch_clk gcc_usb_hs_system_clk = |
| 210 | { |
| 211 | .cbcr_reg = (uint32_t *) USB_HS_SYSTEM_CBCR, |
| 212 | .parent = &usb_hs_system_clk_src.c, |
| 213 | |
| 214 | .c = { |
| 215 | .dbg_name = "gcc_usb_hs_system_clk", |
| 216 | .ops = &clk_ops_branch, |
| 217 | }, |
| 218 | }; |
| 219 | |
| 220 | static struct branch_clk gcc_usb_hs_ahb_clk = |
| 221 | { |
| 222 | .cbcr_reg = (uint32_t *) USB_HS_AHB_CBCR, |
| 223 | .has_sibling = 1, |
| 224 | |
| 225 | .c = { |
| 226 | .dbg_name = "gcc_usb_hs_ahb_clk", |
| 227 | .ops = &clk_ops_branch, |
| 228 | }, |
| 229 | }; |
| 230 | |
| 231 | /* SDCC Clocks */ |
| 232 | static struct clk_freq_tbl ftbl_gcc_sdcc1_2_apps_clk[] = |
| 233 | { |
| 234 | F( 144000, cxo, 16, 3, 25), |
| 235 | F( 400000, cxo, 12, 1, 4), |
| 236 | F( 20000000, gpll0, 15, 1, 2), |
| 237 | F( 25000000, gpll0, 12, 1, 2), |
| 238 | F( 50000000, gpll0, 12, 0, 0), |
| 239 | F(100000000, gpll0, 6, 0, 0), |
| 240 | F(200000000, gpll0, 3, 0, 0), |
| 241 | F_END |
| 242 | }; |
| 243 | |
| 244 | static struct rcg_clk sdcc1_apps_clk_src = |
| 245 | { |
| 246 | .cmd_reg = (uint32_t *) SDCC1_CMD_RCGR, |
| 247 | .cfg_reg = (uint32_t *) SDCC1_CFG_RCGR, |
| 248 | .m_reg = (uint32_t *) SDCC1_M, |
| 249 | .n_reg = (uint32_t *) SDCC1_N, |
| 250 | .d_reg = (uint32_t *) SDCC1_D, |
| 251 | |
| 252 | .set_rate = clock_lib2_rcg_set_rate_mnd, |
| 253 | .freq_tbl = ftbl_gcc_sdcc1_2_apps_clk, |
| 254 | .current_freq = &rcg_dummy_freq, |
| 255 | |
| 256 | .c = { |
| 257 | .dbg_name = "sdc1_clk", |
| 258 | .ops = &clk_ops_rcg_mnd, |
| 259 | }, |
| 260 | }; |
| 261 | |
| 262 | static struct branch_clk gcc_sdcc1_apps_clk = |
| 263 | { |
| 264 | .cbcr_reg = (uint32_t *) SDCC1_APPS_CBCR, |
| 265 | .parent = &sdcc1_apps_clk_src.c, |
| 266 | |
| 267 | .c = { |
| 268 | .dbg_name = "gcc_sdcc1_apps_clk", |
| 269 | .ops = &clk_ops_branch, |
| 270 | }, |
| 271 | }; |
| 272 | |
| 273 | static struct branch_clk gcc_sdcc1_ahb_clk = |
| 274 | { |
| 275 | .cbcr_reg = (uint32_t *) SDCC1_AHB_CBCR, |
| 276 | .has_sibling = 1, |
| 277 | |
| 278 | .c = { |
| 279 | .dbg_name = "gcc_sdcc1_ahb_clk", |
| 280 | .ops = &clk_ops_branch, |
| 281 | }, |
| 282 | }; |
| 283 | |
Amol Jadi | 0a4c9b4 | 2013-10-11 14:22:11 -0700 | [diff] [blame] | 284 | /* USB 3.0 Clocks */ |
| 285 | static struct clk_freq_tbl ftbl_gcc_usb30_master_clk[] = |
| 286 | { |
| 287 | F(125000000, gpll0, 1, 5, 24), |
| 288 | F_END |
| 289 | }; |
| 290 | |
| 291 | static struct rcg_clk usb30_master_clk_src = |
| 292 | { |
| 293 | .cmd_reg = (uint32_t *) GCC_USB30_MASTER_CMD_RCGR, |
| 294 | .cfg_reg = (uint32_t *) GCC_USB30_MASTER_CFG_RCGR, |
| 295 | .m_reg = (uint32_t *) GCC_USB30_MASTER_M, |
| 296 | .n_reg = (uint32_t *) GCC_USB30_MASTER_N, |
| 297 | .d_reg = (uint32_t *) GCC_USB30_MASTER_D, |
| 298 | |
| 299 | .set_rate = clock_lib2_rcg_set_rate_mnd, |
| 300 | .freq_tbl = ftbl_gcc_usb30_master_clk, |
| 301 | .current_freq = &rcg_dummy_freq, |
| 302 | |
| 303 | .c = { |
| 304 | .dbg_name = "usb30_master_clk_src", |
| 305 | .ops = &clk_ops_rcg, |
| 306 | }, |
| 307 | }; |
| 308 | |
| 309 | |
| 310 | static struct branch_clk gcc_usb30_master_clk = |
| 311 | { |
| 312 | .cbcr_reg = (uint32_t *) GCC_USB30_MASTER_CBCR, |
| 313 | .parent = &usb30_master_clk_src.c, |
| 314 | |
| 315 | .c = { |
| 316 | .dbg_name = "gcc_usb30_master_clk", |
| 317 | .ops = &clk_ops_branch, |
| 318 | }, |
| 319 | }; |
| 320 | |
| 321 | static struct branch_clk gcc_sys_noc_usb30_axi_clk = |
| 322 | { |
| 323 | .cbcr_reg = (uint32_t *) SYS_NOC_USB3_AXI_CBCR, |
| 324 | .has_sibling = 1, |
| 325 | |
| 326 | .c = { |
| 327 | .dbg_name = "gcc_sys_noc_usb3_axi_clk", |
| 328 | .ops = &clk_ops_branch, |
| 329 | }, |
| 330 | }; |
| 331 | |
Deepa Dinamani | 554b062 | 2013-05-16 15:00:30 -0700 | [diff] [blame] | 332 | /* Clock lookup table */ |
| 333 | static struct clk_lookup msm_clocks_8084[] = |
| 334 | { |
Sundarajan Srinivasan | 09374ed | 2013-06-18 13:29:32 -0700 | [diff] [blame] | 335 | CLK_LOOKUP("sdc1_iface_clk", gcc_sdcc1_ahb_clk.c), |
| 336 | CLK_LOOKUP("sdc1_core_clk", gcc_sdcc1_apps_clk.c), |
Deepa Dinamani | 554b062 | 2013-05-16 15:00:30 -0700 | [diff] [blame] | 337 | |
Sundarajan Srinivasan | d8b7c6f | 2013-09-13 16:50:22 -0700 | [diff] [blame] | 338 | CLK_LOOKUP("uart7_iface_clk", gcc_blsp2_ahb_clk.c), |
| 339 | CLK_LOOKUP("uart7_core_clk", gcc_blsp2_uart2_apps_clk.c), |
Sundarajan Srinivasan | 09374ed | 2013-06-18 13:29:32 -0700 | [diff] [blame] | 340 | |
| 341 | CLK_LOOKUP("usb_iface_clk", gcc_usb_hs_ahb_clk.c), |
| 342 | CLK_LOOKUP("usb_core_clk", gcc_usb_hs_system_clk.c), |
Amol Jadi | 0a4c9b4 | 2013-10-11 14:22:11 -0700 | [diff] [blame] | 343 | |
| 344 | /* USB 3.0 */ |
| 345 | CLK_LOOKUP("usb30_iface_clk", gcc_sys_noc_usb30_axi_clk.c), |
| 346 | CLK_LOOKUP("usb30_master_clk", gcc_usb30_master_clk.c), |
Sundarajan Srinivasan | 09374ed | 2013-06-18 13:29:32 -0700 | [diff] [blame] | 347 | }; |
Deepa Dinamani | 554b062 | 2013-05-16 15:00:30 -0700 | [diff] [blame] | 348 | |
| 349 | void platform_clock_init(void) |
| 350 | { |
| 351 | clk_init(msm_clocks_8084, ARRAY_SIZE(msm_clocks_8084)); |
| 352 | } |