vijay kumar | ca1672a | 2015-04-09 16:45:40 +0530 | [diff] [blame] | 1 | /* 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 | |
| 46 | struct clk_freq_tbl rcg_dummy_freq = F_END; |
| 47 | |
| 48 | |
| 49 | /* Clock Operations */ |
| 50 | static 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 | |
| 57 | static struct clk_ops clk_ops_rcg_mnd = |
| 58 | { |
| 59 | .enable = clock_lib2_rcg_enable, |
| 60 | .set_rate = clock_lib2_rcg_set_rate, |
| 61 | }; |
| 62 | |
| 63 | static struct clk_ops clk_ops_rcg = |
| 64 | { |
| 65 | .enable = clock_lib2_rcg_enable, |
| 66 | .set_rate = clock_lib2_rcg_set_rate, |
| 67 | }; |
| 68 | |
| 69 | static struct clk_ops clk_ops_cxo = |
| 70 | { |
| 71 | .enable = cxo_clk_enable, |
| 72 | .disable = cxo_clk_disable, |
| 73 | }; |
| 74 | |
| 75 | static 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 | |
| 83 | static 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 */ |
| 90 | static 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 | |
| 99 | static struct pll_vote_clk gpll0_clk_src = |
| 100 | { |
| 101 | .en_reg = (void *) APCS_GPLL_ENA_VOTE, |
| 102 | .en_mask = BIT(0), |
vijay kumar | 20627da | 2015-10-01 13:28:58 +0530 | [diff] [blame^] | 103 | .status_reg = (void *) GPLL0_MODE, |
| 104 | .status_mask = BIT(30), |
vijay kumar | ca1672a | 2015-04-09 16:45:40 +0530 | [diff] [blame] | 105 | .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 kumar | 20627da | 2015-10-01 13:28:58 +0530 | [diff] [blame^] | 115 | static struct clk_freq_tbl ftbl_gcc_blsp1_2_uart5_apps_clk[] = |
vijay kumar | ca1672a | 2015-04-09 16:45:40 +0530 | [diff] [blame] | 116 | { |
| 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 kumar | 20627da | 2015-10-01 13:28:58 +0530 | [diff] [blame^] | 135 | static struct rcg_clk blsp1_uart5_apps_clk_src = |
vijay kumar | ca1672a | 2015-04-09 16:45:40 +0530 | [diff] [blame] | 136 | { |
vijay kumar | 20627da | 2015-10-01 13:28:58 +0530 | [diff] [blame^] | 137 | .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 kumar | ca1672a | 2015-04-09 16:45:40 +0530 | [diff] [blame] | 142 | |
| 143 | .set_rate = clock_lib2_rcg_set_rate_mnd, |
vijay kumar | 20627da | 2015-10-01 13:28:58 +0530 | [diff] [blame^] | 144 | .freq_tbl = ftbl_gcc_blsp1_2_uart5_apps_clk, |
vijay kumar | ca1672a | 2015-04-09 16:45:40 +0530 | [diff] [blame] | 145 | .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 kumar | 20627da | 2015-10-01 13:28:58 +0530 | [diff] [blame^] | 153 | static struct branch_clk gcc_blsp1_uart5_apps_clk = |
vijay kumar | ca1672a | 2015-04-09 16:45:40 +0530 | [diff] [blame] | 154 | { |
vijay kumar | 20627da | 2015-10-01 13:28:58 +0530 | [diff] [blame^] | 155 | .cbcr_reg = (uint32_t *) BLSP1_UART5_APPS_CBCR, |
| 156 | .parent = &blsp1_uart5_apps_clk_src.c, |
vijay kumar | ca1672a | 2015-04-09 16:45:40 +0530 | [diff] [blame] | 157 | |
| 158 | .c = { |
vijay kumar | 20627da | 2015-10-01 13:28:58 +0530 | [diff] [blame^] | 159 | .dbg_name = "gcc_blsp1_uart5_apps_clk", |
vijay kumar | ca1672a | 2015-04-09 16:45:40 +0530 | [diff] [blame] | 160 | .ops = &clk_ops_branch, |
| 161 | }, |
| 162 | }; |
| 163 | |
| 164 | static 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 */ |
| 176 | static struct clk_freq_tbl ftbl_gcc_usb_hs_system_clk[] = |
| 177 | { |
| 178 | F(133330000, gpll0, 6, 0, 0), |
| 179 | F_END |
| 180 | }; |
| 181 | |
| 182 | static 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 | |
| 197 | static 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 | |
| 208 | static 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 | }; |
| 218 | |
| 219 | /* Clock lookup table */ |
| 220 | static struct clk_lookup mdm_clocks_fermium[] = |
| 221 | { |
vijay kumar | 20627da | 2015-10-01 13:28:58 +0530 | [diff] [blame^] | 222 | CLK_LOOKUP("uart5_iface_clk", gcc_blsp1_ahb_clk.c), |
| 223 | CLK_LOOKUP("uart5_core_clk", gcc_blsp1_uart5_apps_clk.c), |
vijay kumar | ca1672a | 2015-04-09 16:45:40 +0530 | [diff] [blame] | 224 | |
| 225 | CLK_LOOKUP("usb_iface_clk", gcc_usb_hs_ahb_clk.c), |
| 226 | CLK_LOOKUP("usb_core_clk", gcc_usb_hs_system_clk.c), |
| 227 | |
| 228 | }; |
| 229 | |
| 230 | void platform_clock_init(void) |
| 231 | { |
| 232 | clk_init(mdm_clocks_fermium, ARRAY_SIZE(mdm_clocks_fermium)); |
| 233 | } |