Channagoud Kadabi | de6bab0 | 2015-01-21 10:39:46 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [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 <stdint.h> |
| 30 | #include <debug.h> |
| 31 | #include <reg.h> |
| 32 | #include <mmc.h> |
| 33 | #include <clock.h> |
| 34 | #include <platform/timer.h> |
| 35 | #include <platform/clock.h> |
| 36 | #include <platform/iomap.h> |
| 37 | #include <pm8x41.h> |
| 38 | |
| 39 | void clock_init_mmc(uint32_t interface) |
| 40 | { |
| 41 | char clk_name[64]; |
| 42 | int ret; |
| 43 | |
| 44 | snprintf(clk_name, sizeof(clk_name), "sdc%u_iface_clk", interface); |
| 45 | |
| 46 | /* enable interface clock */ |
| 47 | ret = clk_get_set_enable(clk_name, 0, true); |
| 48 | if(ret) |
| 49 | { |
| 50 | dprintf(CRITICAL, "failed to set sdc%u_iface_clk ret = %d\n", interface, ret); |
| 51 | ASSERT(0); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /* Configure MMC clock */ |
| 56 | void clock_config_mmc(uint32_t interface, uint32_t freq) |
| 57 | { |
| 58 | int ret = 0; |
| 59 | char clk_name[64]; |
| 60 | |
| 61 | snprintf(clk_name, sizeof(clk_name), "sdc%u_core_clk", interface); |
| 62 | |
| 63 | if(freq == MMC_CLK_400KHZ) |
| 64 | { |
| 65 | ret = clk_get_set_enable(clk_name, 400000, true); |
| 66 | } |
| 67 | else if(freq == MMC_CLK_50MHZ) |
| 68 | { |
| 69 | ret = clk_get_set_enable(clk_name, 50000000, true); |
| 70 | } |
| 71 | else if(freq == MMC_CLK_96MHZ) |
| 72 | { |
Channagoud Kadabi | 99d2370 | 2015-02-02 20:52:17 -0800 | [diff] [blame] | 73 | ret = clk_get_set_enable(clk_name, 96000000, true); |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 74 | } |
| 75 | else if(freq == MMC_CLK_192MHZ) |
| 76 | { |
| 77 | ret = clk_get_set_enable(clk_name, 192000000, true); |
| 78 | } |
Channagoud Kadabi | 99d2370 | 2015-02-02 20:52:17 -0800 | [diff] [blame] | 79 | else if(freq == MMC_CLK_400MHZ) |
| 80 | { |
| 81 | ret = clk_get_set_enable(clk_name, 384000000, 1); |
| 82 | } |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 83 | else |
| 84 | { |
| 85 | dprintf(CRITICAL, "sdc frequency (%u) is not supported\n", freq); |
| 86 | ASSERT(0); |
| 87 | } |
| 88 | |
| 89 | if(ret) |
| 90 | { |
| 91 | dprintf(CRITICAL, "failed to set sdc%u_core_clk ret = %d\n", interface, ret); |
| 92 | ASSERT(0); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /* Configure UART clock based on the UART block id*/ |
| 97 | void clock_config_uart_dm(uint8_t id) |
| 98 | { |
| 99 | int ret; |
| 100 | char iclk[64]; |
| 101 | char cclk[64]; |
| 102 | |
| 103 | snprintf(iclk, sizeof(iclk), "uart%u_iface_clk", id); |
| 104 | snprintf(cclk, sizeof(cclk), "uart%u_core_clk", id); |
| 105 | |
| 106 | ret = clk_get_set_enable(iclk, 0, true); |
| 107 | if(ret) |
| 108 | { |
| 109 | dprintf(CRITICAL, "failed to set uart%u_iface_clk ret = %d\n", id, ret); |
| 110 | ASSERT(0); |
| 111 | } |
| 112 | |
| 113 | ret = clk_get_set_enable(cclk, 7372800, true); |
| 114 | if(ret) |
| 115 | { |
| 116 | dprintf(CRITICAL, "failed to set uart%u_core_clk ret = %d\n", id, ret); |
| 117 | ASSERT(0); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /* Function to asynchronously reset CE (Crypto Engine). |
| 122 | * Function assumes that all the CE clocks are off. |
| 123 | */ |
| 124 | static void ce_async_reset(uint8_t instance) |
| 125 | { |
Channagoud Kadabi | 037c8b8 | 2015-02-05 12:09:32 -0800 | [diff] [blame^] | 126 | if (instance == 1) |
| 127 | { |
| 128 | /* Start the block reset for CE */ |
| 129 | writel(1, GCC_CE1_BCR); |
| 130 | udelay(2); |
| 131 | /* Take CE block out of reset */ |
| 132 | writel(0, GCC_CE1_BCR); |
| 133 | udelay(2); |
| 134 | } |
| 135 | else |
| 136 | { |
| 137 | dprintf(CRITICAL, "Unsupported CE instance: %u\n", instance); |
| 138 | ASSERT(0); |
| 139 | } |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | void clock_ce_enable(uint8_t instance) |
| 143 | { |
| 144 | } |
| 145 | |
| 146 | void clock_ce_disable(uint8_t instance) |
| 147 | { |
| 148 | } |
| 149 | |
| 150 | void clock_config_ce(uint8_t instance) |
| 151 | { |
| 152 | /* Need to enable the clock before disabling since the clk_disable() |
| 153 | * has a check to default to nop when the clk_enable() is not called |
| 154 | * on that particular clock. |
| 155 | */ |
| 156 | clock_ce_enable(instance); |
| 157 | |
| 158 | clock_ce_disable(instance); |
| 159 | |
| 160 | ce_async_reset(instance); |
| 161 | |
| 162 | clock_ce_enable(instance); |
| 163 | |
| 164 | } |
| 165 | |
| 166 | void clock_usb30_gdsc_enable(void) |
| 167 | { |
| 168 | uint32_t reg = readl(GCC_USB30_GDSCR); |
| 169 | |
| 170 | reg &= ~(0x1); |
| 171 | |
| 172 | writel(reg, GCC_USB30_GDSCR); |
| 173 | } |
| 174 | |
| 175 | /* enables usb30 clocks */ |
| 176 | void clock_usb30_init(void) |
| 177 | { |
| 178 | int ret; |
| 179 | |
| 180 | ret = clk_get_set_enable("usb30_iface_clk", 0, true); |
| 181 | if(ret) |
| 182 | { |
| 183 | dprintf(CRITICAL, "failed to set usb30_iface_clk. ret = %d\n", ret); |
| 184 | ASSERT(0); |
| 185 | } |
| 186 | |
| 187 | clock_usb30_gdsc_enable(); |
| 188 | |
| 189 | ret = clk_get_set_enable("usb30_master_clk", 125000000, true); |
| 190 | if(ret) |
| 191 | { |
| 192 | dprintf(CRITICAL, "failed to set usb30_master_clk. ret = %d\n", ret); |
| 193 | ASSERT(0); |
| 194 | } |
| 195 | |
| 196 | ret = clk_get_set_enable("usb30_phy_aux_clk", 1200000, true); |
| 197 | if(ret) |
| 198 | { |
| 199 | dprintf(CRITICAL, "failed to set usb30_phy_aux_clk. ret = %d\n", ret); |
| 200 | ASSERT(0); |
| 201 | } |
| 202 | |
| 203 | ret = clk_get_set_enable("usb30_mock_utmi_clk", 60000000, true); |
| 204 | if(ret) |
| 205 | { |
| 206 | dprintf(CRITICAL, "failed to set usb30_mock_utmi_clk ret = %d\n", ret); |
| 207 | ASSERT(0); |
| 208 | } |
| 209 | |
| 210 | ret = clk_get_set_enable("usb30_sleep_clk", 0, true); |
| 211 | if(ret) |
| 212 | { |
| 213 | dprintf(CRITICAL, "failed to set usb30_sleep_clk ret = %d\n", ret); |
| 214 | ASSERT(0); |
| 215 | } |
| 216 | |
| 217 | ret = clk_get_set_enable("usb_phy_cfg_ahb2phy_clk", 0, true); |
| 218 | if(ret) |
| 219 | { |
| 220 | dprintf(CRITICAL, "failed to enable usb_phy_cfg_ahb2phy_clk = %d\n", ret); |
| 221 | ASSERT(0); |
| 222 | } |
Channagoud Kadabi | ed60a8b | 2014-06-27 15:35:09 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | void clock_bumpup_pipe3_clk() |
| 226 | { |
| 227 | int ret = 0; |
| 228 | |
| 229 | ret = clk_get_set_enable("usb30_pipe_clk", 0, true); |
| 230 | if(ret) |
| 231 | { |
| 232 | dprintf(CRITICAL, "failed to set usb30_pipe_clk. ret = %d\n", ret); |
| 233 | ASSERT(0); |
| 234 | } |
| 235 | |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | void clock_reset_usb_phy() |
| 240 | { |
| 241 | int ret; |
| 242 | |
| 243 | struct clk *phy_reset_clk = NULL; |
| 244 | struct clk *pipe_reset_clk = NULL; |
| 245 | |
| 246 | /* Look if phy com clock is present */ |
| 247 | phy_reset_clk = clk_get("usb30_phy_reset"); |
| 248 | ASSERT(phy_reset_clk); |
| 249 | |
| 250 | pipe_reset_clk = clk_get("usb30_pipe_clk"); |
| 251 | ASSERT(pipe_reset_clk); |
| 252 | |
| 253 | /* ASSERT */ |
| 254 | ret = clk_reset(phy_reset_clk, CLK_RESET_ASSERT); |
| 255 | |
| 256 | if (ret) |
| 257 | { |
| 258 | dprintf(CRITICAL, "Failed to assert usb30_phy_reset clk\n"); |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | ret = clk_reset(pipe_reset_clk, CLK_RESET_ASSERT); |
| 263 | if (ret) |
| 264 | { |
| 265 | dprintf(CRITICAL, "Failed to assert usb30_pipe_clk\n"); |
| 266 | goto deassert_phy_clk; |
| 267 | } |
| 268 | |
| 269 | udelay(100); |
| 270 | |
| 271 | /* DEASSERT */ |
| 272 | ret = clk_reset(pipe_reset_clk, CLK_RESET_DEASSERT); |
| 273 | if (ret) |
| 274 | { |
| 275 | dprintf(CRITICAL, "Failed to deassert usb_pipe_clk\n"); |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | deassert_phy_clk: |
| 280 | |
| 281 | ret = clk_reset(phy_reset_clk, CLK_RESET_DEASSERT); |
| 282 | if (ret) |
| 283 | { |
| 284 | dprintf(CRITICAL, "Failed to deassert usb30_phy_com_reset clk\n"); |
| 285 | return; |
| 286 | } |
| 287 | } |