vijay kumar | dd51c59 | 2015-01-05 12:46:28 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 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 <err.h> |
| 30 | #include <assert.h> |
| 31 | #include <debug.h> |
| 32 | #include <reg.h> |
| 33 | #include <platform/timer.h> |
| 34 | #include <platform/iomap.h> |
| 35 | #include <mmc.h> |
| 36 | #include <clock.h> |
| 37 | #include <platform/clock.h> |
Aparna Mallavarapu | 3f24f3b | 2014-05-15 11:50:37 +0530 | [diff] [blame] | 38 | #include <blsp_qup.h> |
Unnati Gandhi | bd9dbea | 2014-07-17 14:30:29 +0530 | [diff] [blame] | 39 | #include <platform.h> |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 40 | |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 41 | #define MAX_LOOPS 500 |
| 42 | |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 43 | void hsusb_clock_init(void) |
| 44 | { |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 45 | int ret; |
| 46 | struct clk *iclk, *cclk; |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 47 | |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 48 | ret = clk_get_set_enable("usb_iface_clk", 0, 1); |
| 49 | if(ret) |
| 50 | { |
| 51 | dprintf(CRITICAL, "failed to set usb_iface_clk ret = %d\n", ret); |
| 52 | ASSERT(0); |
| 53 | } |
| 54 | |
| 55 | ret = clk_get_set_enable("usb_core_clk", 80000000, 1); |
| 56 | if(ret) |
| 57 | { |
| 58 | dprintf(CRITICAL, "failed to set usb_core_clk ret = %d\n", ret); |
| 59 | ASSERT(0); |
| 60 | } |
| 61 | |
| 62 | mdelay(20); |
| 63 | |
| 64 | iclk = clk_get("usb_iface_clk"); |
| 65 | cclk = clk_get("usb_core_clk"); |
| 66 | |
| 67 | clk_disable(iclk); |
| 68 | clk_disable(cclk); |
| 69 | |
| 70 | mdelay(20); |
| 71 | |
| 72 | /* Start the block reset for usb */ |
| 73 | writel(1, USB_HS_BCR); |
| 74 | |
| 75 | mdelay(20); |
| 76 | |
| 77 | /* Take usb block out of reset */ |
| 78 | writel(0, USB_HS_BCR); |
| 79 | |
| 80 | mdelay(20); |
| 81 | |
| 82 | ret = clk_enable(iclk); |
| 83 | |
| 84 | if(ret) |
| 85 | { |
| 86 | dprintf(CRITICAL, "failed to set usb_iface_clk after async ret = %d\n", ret); |
| 87 | ASSERT(0); |
| 88 | } |
| 89 | |
| 90 | ret = clk_enable(cclk); |
| 91 | |
| 92 | if(ret) |
| 93 | { |
| 94 | dprintf(CRITICAL, "failed to set usb_iface_clk after async ret = %d\n", ret); |
| 95 | ASSERT(0); |
| 96 | } |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | void clock_init_mmc(uint32_t interface) |
| 100 | { |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 101 | char clk_name[64]; |
| 102 | int ret; |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 103 | |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 104 | snprintf(clk_name, sizeof(clk_name), "sdc%u_iface_clk", interface); |
| 105 | |
| 106 | /* enable interface clock */ |
| 107 | ret = clk_get_set_enable(clk_name, 0, 1); |
| 108 | if(ret) |
| 109 | { |
| 110 | dprintf(CRITICAL, "failed to set sdc1_iface_clk ret = %d\n", ret); |
| 111 | ASSERT(0); |
| 112 | } |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /* Configure MMC clock */ |
| 116 | void clock_config_mmc(uint32_t interface, uint32_t freq) |
| 117 | { |
Unnati Gandhi | bd9dbea | 2014-07-17 14:30:29 +0530 | [diff] [blame] | 118 | int ret = 1; |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 119 | char clk_name[64]; |
| 120 | |
| 121 | snprintf(clk_name, sizeof(clk_name), "sdc%u_core_clk", interface); |
| 122 | |
| 123 | if(freq == MMC_CLK_400KHZ) |
| 124 | { |
| 125 | ret = clk_get_set_enable(clk_name, 400000, 1); |
| 126 | } |
| 127 | else if(freq == MMC_CLK_50MHZ) |
| 128 | { |
| 129 | ret = clk_get_set_enable(clk_name, 50000000, 1); |
| 130 | } |
| 131 | else if(freq == MMC_CLK_200MHZ) |
| 132 | { |
| 133 | ret = clk_get_set_enable(clk_name, 200000000, 1); |
| 134 | } |
| 135 | else if(freq == MMC_CLK_177MHZ) |
| 136 | { |
| 137 | ret = clk_get_set_enable(clk_name, 177770000, 1); |
| 138 | } |
| 139 | else |
| 140 | { |
| 141 | dprintf(CRITICAL, "sdc frequency (%u) is not supported\n", freq); |
| 142 | ASSERT(0); |
| 143 | } |
| 144 | |
| 145 | if(ret) |
| 146 | { |
| 147 | dprintf(CRITICAL, "failed to set %s ret = %d\n", clk_name, ret); |
| 148 | ASSERT(0); |
| 149 | } |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* Configure UART clock based on the UART block id*/ |
| 153 | void clock_config_uart_dm(uint8_t id) |
| 154 | { |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 155 | int ret; |
| 156 | char iclk[64]; |
| 157 | char cclk[64]; |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 158 | |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 159 | snprintf(iclk, sizeof(iclk), "uart%u_iface_clk", id); |
| 160 | snprintf(cclk, sizeof(cclk), "uart%u_core_clk", id); |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 161 | |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 162 | ret = clk_get_set_enable(iclk, 0, 1); |
| 163 | if(ret) |
| 164 | { |
| 165 | dprintf(CRITICAL, "failed to set %s ret = %d\n", iclk, ret); |
| 166 | ASSERT(0); |
| 167 | } |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 168 | |
Aparna Mallavarapu | 70e5df5 | 2014-02-27 22:51:29 -0800 | [diff] [blame] | 169 | ret = clk_get_set_enable(cclk, 7372800, 1); |
| 170 | if(ret) |
| 171 | { |
| 172 | dprintf(CRITICAL, "failed to set %s ret = %d\n", cclk, ret); |
| 173 | ASSERT(0); |
| 174 | } |
Aparna Mallavarapu | 9e01437 | 2013-10-19 15:04:58 +0530 | [diff] [blame] | 175 | } |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 176 | |
| 177 | /* Control the MDSS GDSC */ |
| 178 | void mdp_gdsc_ctrl(uint8_t enable) |
| 179 | { |
| 180 | uint32_t reg = 0; |
| 181 | reg = readl(MDP_GDSCR); |
| 182 | if (enable) { |
| 183 | if (!(reg & GDSC_POWER_ON_BIT)) { |
| 184 | reg &= ~(BIT(0) | GDSC_EN_FEW_WAIT_MASK); |
| 185 | reg |= GDSC_EN_FEW_WAIT_256_MASK; |
| 186 | writel(reg, MDP_GDSCR); |
| 187 | while(!(readl(MDP_GDSCR) & (GDSC_POWER_ON_BIT))); |
| 188 | } else { |
| 189 | dprintf(SPEW, "MDP GDSC already enabled\n"); |
| 190 | } |
| 191 | } else { |
| 192 | reg |= BIT(0); |
| 193 | writel(reg, MDP_GDSCR); |
| 194 | while(readl(MDP_GDSCR) & (GDSC_POWER_ON_BIT)); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /* Enable all the MDP branch clocks */ |
| 199 | void mdp_clock_enable(void) |
| 200 | { |
| 201 | int ret; |
| 202 | |
| 203 | ret = clk_get_set_enable("mdp_ahb_clk", 0, 1); |
| 204 | if(ret) |
| 205 | { |
| 206 | dprintf(CRITICAL, "failed to set mdp_ahb_clk ret = %d\n", ret); |
| 207 | ASSERT(0); |
| 208 | } |
| 209 | |
vijay kumar | dd51c59 | 2015-01-05 12:46:28 +0530 | [diff] [blame] | 210 | if (platform_is_msm8939() || platform_is_msm8929()) |
Radhika Ranjan Soni | bc86e2c | 2014-06-11 17:46:56 +0530 | [diff] [blame] | 211 | ret = clk_get_set_enable("mdss_mdp_clk_src", 307200000, 1); |
| 212 | else |
| 213 | /* Set MDP clock to 320MHz */ |
| 214 | ret = clk_get_set_enable("mdss_mdp_clk_src", 320000000, 1); |
| 215 | |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 216 | if(ret) |
| 217 | { |
| 218 | dprintf(CRITICAL, "failed to set mdp_clk_src ret = %d\n", ret); |
| 219 | ASSERT(0); |
| 220 | } |
| 221 | |
| 222 | ret = clk_get_set_enable("mdss_vsync_clk", 0, 1); |
| 223 | if(ret) |
| 224 | { |
| 225 | dprintf(CRITICAL, "failed to set mdss vsync clk ret = %d\n", ret); |
| 226 | ASSERT(0); |
| 227 | } |
| 228 | |
| 229 | ret = clk_get_set_enable("mdss_mdp_clk", 0, 1); |
| 230 | if(ret) |
| 231 | { |
| 232 | dprintf(CRITICAL, "failed to set mdp_clk ret = %d\n", ret); |
| 233 | ASSERT(0); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | /* Disable all the MDP branch clocks */ |
| 238 | void mdp_clock_disable(void) |
| 239 | { |
| 240 | clk_disable(clk_get("mdss_vsync_clk")); |
| 241 | clk_disable(clk_get("mdss_mdp_clk")); |
| 242 | clk_disable(clk_get("mdss_mdp_clk_src")); |
| 243 | clk_disable(clk_get("mdp_ahb_clk")); |
| 244 | } |
| 245 | |
| 246 | /* Disable all the bus clocks needed by MDSS */ |
| 247 | void mdss_bus_clocks_disable(void) |
| 248 | { |
| 249 | /* Disable MDSS AXI clock */ |
| 250 | clk_disable(clk_get("mdss_axi_clk")); |
| 251 | } |
| 252 | |
| 253 | /* Enable all the bus clocks needed by MDSS */ |
| 254 | void mdss_bus_clocks_enable(void) |
| 255 | { |
| 256 | int ret; |
| 257 | |
| 258 | /* Configure AXI clock */ |
| 259 | ret = clk_get_set_enable("mdss_axi_clk", 0, 1); |
| 260 | if(ret) |
| 261 | { |
| 262 | dprintf(CRITICAL, "failed to set mdss_axi_clk ret = %d\n", ret); |
| 263 | ASSERT(0); |
| 264 | } |
| 265 | } |
| 266 | |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 267 | static void rcg_update_config(uint32_t reg) |
| 268 | { |
| 269 | int i; |
| 270 | |
| 271 | for (i = 0; i < MAX_LOOPS; i++) { |
| 272 | if (!(readl(reg) & BIT(0))) |
| 273 | return; |
| 274 | udelay(1); |
| 275 | } |
| 276 | |
| 277 | dprintf(CRITICAL, "failed to update rcg config for reg = 0x%x\n", reg); |
| 278 | ASSERT(0); |
| 279 | } |
| 280 | |
| 281 | static void branch_clk_halt_check(uint32_t reg) |
| 282 | { |
| 283 | int i; |
| 284 | |
| 285 | for (i = 0; i < MAX_LOOPS; i++) { |
| 286 | if (!(readl(reg) & BIT(31))) |
| 287 | return; |
| 288 | udelay(1); |
| 289 | } |
| 290 | |
| 291 | dprintf(CRITICAL, "failed to enable branch for reg = 0x%x\n", reg); |
| 292 | ASSERT(0); |
| 293 | } |
| 294 | |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 295 | /* Disable all the branch clocks needed by the DSI controller */ |
Vineet Bajaj | e022da6 | 2014-07-24 19:13:34 +0530 | [diff] [blame] | 296 | void gcc_dsi_clocks_disable(uint8_t dual_dsi) |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 297 | { |
| 298 | clk_disable(clk_get("mdss_esc0_clk")); |
| 299 | writel(0x0, DSI_PIXEL0_CBCR); |
| 300 | writel(0x0, DSI_BYTE0_CBCR); |
Vineet Bajaj | e022da6 | 2014-07-24 19:13:34 +0530 | [diff] [blame] | 301 | if (dual_dsi) { |
| 302 | clk_disable(clk_get("mdss_esc1_clk")); |
| 303 | writel(0x0, DSI_PIXEL1_CBCR); |
| 304 | writel(0x0, DSI_BYTE1_CBCR); |
| 305 | } |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /* Configure all the branch clocks needed by the DSI controller */ |
Vineet Bajaj | e022da6 | 2014-07-24 19:13:34 +0530 | [diff] [blame] | 309 | void gcc_dsi_clocks_enable(uint8_t dual_dsi, uint8_t pclk0_m, uint8_t pclk0_n, uint8_t pclk0_d) |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 310 | { |
| 311 | int ret; |
| 312 | |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 313 | /* |
| 314 | * Configure Byte clock -autopll- This will not change becasue |
| 315 | * byte clock does not need any divider |
| 316 | */ |
| 317 | /* Set the source for DSI0 byte RCG */ |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 318 | writel(0x100, DSI_BYTE0_CFG_RCGR); |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 319 | /* Set the update RCG bit */ |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 320 | writel(0x1, DSI_BYTE0_CMD_RCGR); |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 321 | rcg_update_config(DSI_BYTE0_CMD_RCGR); |
| 322 | /* Enable the branch clock */ |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 323 | writel(0x1, DSI_BYTE0_CBCR); |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 324 | branch_clk_halt_check(DSI_BYTE0_CBCR); |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 325 | |
| 326 | /* Configure Pixel clock */ |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 327 | /* Set the source for DSI0 pixel RCG */ |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 328 | writel(0x100, DSI_PIXEL0_CFG_RCGR); |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 329 | /* Set the MND for DSI0 pixel clock */ |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 330 | writel(pclk0_m, DSI_PIXEL0_M); |
| 331 | writel(pclk0_n, DSI_PIXEL0_N); |
| 332 | writel(pclk0_d, DSI_PIXEL0_D); |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 333 | /* Set the update RCG bit */ |
| 334 | writel(0x1, DSI_PIXEL0_CMD_RCGR); |
| 335 | rcg_update_config(DSI_PIXEL0_CMD_RCGR); |
| 336 | /* Enable the branch clock */ |
| 337 | writel(0x1, DSI_PIXEL0_CBCR); |
| 338 | branch_clk_halt_check(DSI_PIXEL0_CBCR); |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 339 | |
| 340 | /* Configure ESC clock */ |
| 341 | ret = clk_get_set_enable("mdss_esc0_clk", 0, 1); |
| 342 | if (ret) { |
| 343 | dprintf(CRITICAL, "failed to set esc0_clk ret = %d\n", ret); |
| 344 | ASSERT(0); |
| 345 | } |
Vineet Bajaj | e022da6 | 2014-07-24 19:13:34 +0530 | [diff] [blame] | 346 | |
| 347 | if (dual_dsi) { |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 348 | /* Set the source for DSI1 byte RCG */ |
Vineet Bajaj | e022da6 | 2014-07-24 19:13:34 +0530 | [diff] [blame] | 349 | writel(0x100, DSI_BYTE1_CFG_RCGR); |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 350 | /* Set the update RCG bit */ |
Vineet Bajaj | e022da6 | 2014-07-24 19:13:34 +0530 | [diff] [blame] | 351 | writel(0x1, DSI_BYTE1_CMD_RCGR); |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 352 | rcg_update_config(DSI_BYTE1_CMD_RCGR); |
| 353 | /* Enable the branch clock */ |
Vineet Bajaj | e022da6 | 2014-07-24 19:13:34 +0530 | [diff] [blame] | 354 | writel(0x1, DSI_BYTE1_CBCR); |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 355 | branch_clk_halt_check(DSI_BYTE1_CBCR); |
Vineet Bajaj | e022da6 | 2014-07-24 19:13:34 +0530 | [diff] [blame] | 356 | |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 357 | /* Set the source for DSI1 pixel RCG */ |
Vineet Bajaj | e022da6 | 2014-07-24 19:13:34 +0530 | [diff] [blame] | 358 | writel(0x100, DSI_PIXEL1_CFG_RCGR); |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 359 | /* Set the MND for DSI1 pixel clock */ |
Vineet Bajaj | e022da6 | 2014-07-24 19:13:34 +0530 | [diff] [blame] | 360 | writel(pclk0_m, DSI_PIXEL1_M); |
| 361 | writel(pclk0_n, DSI_PIXEL1_N); |
| 362 | writel(pclk0_d, DSI_PIXEL1_D); |
Padmanabhan Komanduru | 36e609f | 2015-05-04 12:52:26 -0700 | [diff] [blame] | 363 | /* Set the update RCG bit */ |
| 364 | writel(0x1, DSI_PIXEL1_CMD_RCGR); |
| 365 | rcg_update_config(DSI_PIXEL1_CMD_RCGR); |
| 366 | /* Enable the branch clock */ |
| 367 | writel(0x1, DSI_PIXEL1_CBCR); |
| 368 | branch_clk_halt_check(DSI_PIXEL1_CBCR); |
Vineet Bajaj | e022da6 | 2014-07-24 19:13:34 +0530 | [diff] [blame] | 369 | |
| 370 | /* Configure ESC clock */ |
| 371 | ret = clk_get_set_enable("mdss_esc1_clk", 0, 1); |
| 372 | if (ret) { |
| 373 | dprintf(CRITICAL, "failed to set esc1_clk ret = %d\n", ret); |
| 374 | ASSERT(0); |
| 375 | } |
| 376 | } |
Padmanabhan Komanduru | dd778b9 | 2014-03-21 19:25:17 +0530 | [diff] [blame] | 377 | } |
Aparna Mallavarapu | 2e89967 | 2014-04-22 15:12:05 +0530 | [diff] [blame] | 378 | |
| 379 | /* Function to asynchronously reset CE. |
| 380 | * Function assumes that all the CE clocks are off. |
| 381 | */ |
| 382 | static void ce_async_reset(uint8_t instance) |
| 383 | { |
| 384 | /* Start the block reset for CE */ |
| 385 | writel(1, GCC_CRYPTO_BCR); |
| 386 | |
| 387 | udelay(2); |
| 388 | |
| 389 | /* Take CE block out of reset */ |
| 390 | writel(0, GCC_CRYPTO_BCR); |
| 391 | |
| 392 | udelay(2); |
| 393 | } |
| 394 | |
| 395 | void clock_ce_enable(uint8_t instance) |
| 396 | { |
| 397 | int ret; |
| 398 | char clk_name[64]; |
| 399 | |
| 400 | snprintf(clk_name, sizeof(clk_name), "ce%u_src_clk", instance); |
| 401 | ret = clk_get_set_enable(clk_name, 160000000, 1); |
| 402 | if(ret) |
| 403 | { |
| 404 | dprintf(CRITICAL, "failed to set ce%u_src_clk ret = %d\n", instance, ret); |
| 405 | ASSERT(0); |
| 406 | } |
| 407 | |
| 408 | snprintf(clk_name, sizeof(clk_name), "ce%u_core_clk", instance); |
| 409 | ret = clk_get_set_enable(clk_name, 0, 1); |
| 410 | if(ret) |
| 411 | { |
| 412 | dprintf(CRITICAL, "failed to set ce%u_core_clk ret = %d\n", instance, ret); |
| 413 | ASSERT(0); |
| 414 | } |
| 415 | |
| 416 | snprintf(clk_name, sizeof(clk_name), "ce%u_ahb_clk", instance); |
| 417 | ret = clk_get_set_enable(clk_name, 0, 1); |
| 418 | if(ret) |
| 419 | { |
| 420 | dprintf(CRITICAL, "failed to set ce%u_ahb_clk ret = %d\n", instance, ret); |
| 421 | ASSERT(0); |
| 422 | } |
| 423 | |
| 424 | snprintf(clk_name, sizeof(clk_name), "ce%u_axi_clk", instance); |
| 425 | ret = clk_get_set_enable(clk_name, 0, 1); |
| 426 | if(ret) |
| 427 | { |
| 428 | dprintf(CRITICAL, "failed to set ce%u_axi_clk ret = %d\n", instance, ret); |
| 429 | ASSERT(0); |
| 430 | } |
| 431 | |
| 432 | /* Wait for 48 * #pipes cycles. |
| 433 | * This is necessary as immediately after an access control reset (boot up) |
| 434 | * or a debug re-enable, the Crypto core sequentially clears its internal |
| 435 | * pipe key storage memory. If pipe key initialization writes are attempted |
| 436 | * during this time, they may be overwritten by the internal clearing logic. |
| 437 | */ |
| 438 | udelay(1); |
| 439 | } |
| 440 | |
| 441 | void clock_ce_disable(uint8_t instance) |
| 442 | { |
| 443 | struct clk *ahb_clk; |
| 444 | struct clk *cclk; |
| 445 | struct clk *axi_clk; |
| 446 | struct clk *src_clk; |
| 447 | char clk_name[64]; |
| 448 | |
| 449 | snprintf(clk_name, sizeof(clk_name), "ce%u_src_clk", instance); |
| 450 | src_clk = clk_get(clk_name); |
| 451 | |
| 452 | snprintf(clk_name, sizeof(clk_name), "ce%u_ahb_clk", instance); |
| 453 | ahb_clk = clk_get(clk_name); |
| 454 | |
| 455 | snprintf(clk_name, sizeof(clk_name), "ce%u_axi_clk", instance); |
| 456 | axi_clk = clk_get(clk_name); |
| 457 | |
| 458 | snprintf(clk_name, sizeof(clk_name), "ce%u_core_clk", instance); |
| 459 | cclk = clk_get(clk_name); |
| 460 | |
| 461 | clk_disable(ahb_clk); |
| 462 | clk_disable(axi_clk); |
| 463 | clk_disable(cclk); |
| 464 | clk_disable(src_clk); |
| 465 | |
| 466 | /* Some delay for the clocks to stabalize. */ |
| 467 | udelay(1); |
| 468 | } |
| 469 | |
| 470 | void clock_config_ce(uint8_t instance) |
| 471 | { |
| 472 | /* Need to enable the clock before disabling since the clk_disable() |
| 473 | * has a check to default to nop when the clk_enable() is not called |
| 474 | * on that particular clock. |
| 475 | */ |
| 476 | clock_ce_enable(instance); |
| 477 | |
| 478 | clock_ce_disable(instance); |
| 479 | |
| 480 | ce_async_reset(instance); |
| 481 | |
| 482 | clock_ce_enable(instance); |
| 483 | } |
Aparna Mallavarapu | 3f24f3b | 2014-05-15 11:50:37 +0530 | [diff] [blame] | 484 | |
| 485 | void clock_config_blsp_i2c(uint8_t blsp_id, uint8_t qup_id) |
| 486 | { |
| 487 | uint8_t ret = 0; |
| 488 | char clk_name[64]; |
| 489 | |
| 490 | struct clk *qup_clk; |
| 491 | |
vijay kumar | 0251c7d | 2015-04-06 19:16:06 +0530 | [diff] [blame] | 492 | if((blsp_id != BLSP_ID_1) || ((qup_id != QUP_ID_1) && (qup_id != QUP_ID_3))) { |
Aparna Mallavarapu | 3f24f3b | 2014-05-15 11:50:37 +0530 | [diff] [blame] | 493 | dprintf(CRITICAL, "Incorrect BLSP-%d or QUP-%d configuration\n", blsp_id, qup_id); |
| 494 | ASSERT(0); |
| 495 | } |
| 496 | |
vijay kumar | 0251c7d | 2015-04-06 19:16:06 +0530 | [diff] [blame] | 497 | if (qup_id == QUP_ID_1) { |
| 498 | snprintf(clk_name, sizeof(clk_name), "blsp1_qup2_ahb_iface_clk"); |
| 499 | } |
| 500 | else if (qup_id == QUP_ID_3) { |
| 501 | snprintf(clk_name, sizeof(clk_name), "blsp1_qup4_ahb_iface_clk"); |
| 502 | } |
Aparna Mallavarapu | 3f24f3b | 2014-05-15 11:50:37 +0530 | [diff] [blame] | 503 | |
| 504 | ret = clk_get_set_enable(clk_name, 0 , 1); |
| 505 | |
| 506 | if (ret) { |
| 507 | dprintf(CRITICAL, "Failed to enable %s clock\n", clk_name); |
| 508 | return; |
| 509 | } |
| 510 | |
vijay kumar | 0251c7d | 2015-04-06 19:16:06 +0530 | [diff] [blame] | 511 | if (qup_id == QUP_ID_1) { |
| 512 | snprintf(clk_name, sizeof(clk_name), "gcc_blsp1_qup2_i2c_apps_clk"); |
| 513 | } |
| 514 | else if (qup_id == QUP_ID_3) { |
| 515 | snprintf(clk_name, sizeof(clk_name), "gcc_blsp1_qup4_i2c_apps_clk"); |
| 516 | } |
Aparna Mallavarapu | 3f24f3b | 2014-05-15 11:50:37 +0530 | [diff] [blame] | 517 | |
| 518 | qup_clk = clk_get(clk_name); |
| 519 | |
| 520 | if (!qup_clk) { |
| 521 | dprintf(CRITICAL, "Failed to get %s\n", clk_name); |
| 522 | return; |
| 523 | } |
| 524 | |
| 525 | ret = clk_enable(qup_clk); |
| 526 | |
| 527 | if (ret) { |
| 528 | dprintf(CRITICAL, "Failed to enable %s\n", clk_name); |
| 529 | return; |
| 530 | } |
| 531 | } |