Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are 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 copyright |
| 9 | * notice, this list of conditions and the following disclaimer in the |
| 10 | * documentation and/or other materials provided with the distribution. |
| 11 | * * Neither the name of Code Aurora nor |
| 12 | * the names of its contributors may be used to endorse or promote |
| 13 | * products derived from this software without specific prior written |
| 14 | * permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <reg.h> |
| 31 | #include <platform/iomap.h> |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 32 | #include <platform/clock.h> |
| 33 | #include <uart_dm.h> |
| 34 | #include <gsbi.h> |
Amol Jadi | 8225456 | 2011-06-27 11:25:48 -0700 | [diff] [blame] | 35 | #include <mmc.h> |
Shashank Mittal | ed17773 | 2011-05-06 19:12:59 -0700 | [diff] [blame] | 36 | |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 37 | /* Set rate and enable the clock */ |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 38 | void clock_config(uint32_t ns, uint32_t md, uint32_t ns_addr, uint32_t md_addr) |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 39 | { |
Shashank Mittal | ed17773 | 2011-05-06 19:12:59 -0700 | [diff] [blame] | 40 | unsigned int val = 0; |
| 41 | |
| 42 | /* Activate the reset for the M/N Counter */ |
| 43 | val = 1 << 7; |
| 44 | writel(val, ns_addr); |
| 45 | |
| 46 | /* Write the MD value into the MD register */ |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 47 | if (md_addr != 0x0) |
| 48 | writel(md, md_addr); |
Shashank Mittal | ed17773 | 2011-05-06 19:12:59 -0700 | [diff] [blame] | 49 | |
| 50 | /* Write the ns value, and active reset for M/N Counter, again */ |
| 51 | val = 1 << 7; |
| 52 | val |= ns; |
| 53 | writel(val, ns_addr); |
| 54 | |
| 55 | /* De-activate the reset for M/N Counter */ |
| 56 | val = 1 << 7; |
| 57 | val = ~val; |
| 58 | val = val & readl(ns_addr); |
| 59 | writel(val, ns_addr); |
| 60 | |
| 61 | /* Enable the Clock Root */ |
| 62 | val = 1 << 11; |
| 63 | val = val | readl(ns_addr); |
| 64 | writel(val, ns_addr); |
| 65 | |
| 66 | /* Enable the Clock Branch */ |
| 67 | val = 1 << 9; |
| 68 | val = val | readl(ns_addr); |
| 69 | writel(val, ns_addr); |
| 70 | |
| 71 | /* Enable the M/N Counter */ |
| 72 | val = 1 << 8; |
| 73 | val = val | readl(ns_addr); |
| 74 | writel(val, ns_addr); |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 77 | /* Write the M,N,D values and enable the MMSS Clocks */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 78 | void config_mmss_clk(uint32_t ns, |
| 79 | uint32_t md, |
| 80 | uint32_t cc, |
| 81 | uint32_t ns_addr, uint32_t md_addr, uint32_t cc_addr) |
| 82 | { |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 83 | unsigned int val = 0; |
| 84 | |
| 85 | clock_config(ns, md, ns_addr, md_addr); |
| 86 | |
| 87 | /* Enable MND counter */ |
| 88 | val = cc | (1 << 5); |
| 89 | val = val | readl(cc_addr); |
| 90 | writel(val, cc_addr); |
| 91 | |
| 92 | /* Enable the root of the clock tree */ |
| 93 | val = 1 << 2; |
| 94 | val = val | readl(cc_addr); |
| 95 | writel(val, cc_addr); |
| 96 | |
| 97 | /* Enable the Pixel Clock */ |
| 98 | val = 1 << 0; |
| 99 | val = val | readl(cc_addr); |
| 100 | writel(val, cc_addr); |
| 101 | |
| 102 | /* Force On */ |
| 103 | val = 1 << 31; |
| 104 | val = val | readl(cc_addr); |
| 105 | writel(val, cc_addr); |
| 106 | } |
| 107 | |
Shashank Mittal | ed17773 | 2011-05-06 19:12:59 -0700 | [diff] [blame] | 108 | void pll8_enable(void) |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 109 | { |
Shashank Mittal | ed17773 | 2011-05-06 19:12:59 -0700 | [diff] [blame] | 110 | unsigned int curr_value = 0; |
| 111 | |
| 112 | /* Vote for PLL8 to be enabled */ |
| 113 | curr_value = readl(MSM_BOOT_PLL_ENABLE_SC0); |
| 114 | curr_value |= (1 << 8); |
| 115 | writel(curr_value, MSM_BOOT_PLL_ENABLE_SC0); |
| 116 | |
| 117 | /* Proceed only after PLL is enabled */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 118 | while (!(readl(MSM_BOOT_PLL8_STATUS) & (1 << 16))) ; |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void hsusb_clock_init(void) |
| 122 | { |
Shashank Mittal | ed17773 | 2011-05-06 19:12:59 -0700 | [diff] [blame] | 123 | /* TODO: Enable pll8 here */ |
| 124 | /* Setup USB AHB clock */ |
| 125 | |
Shashank Mittal | ed17773 | 2011-05-06 19:12:59 -0700 | [diff] [blame] | 126 | /* Setup XCVR clock */ |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 127 | clock_config(USB_XCVR_CLK_NS, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 128 | USB_XCVR_CLK_MD, |
| 129 | USB_HS1_XCVR_FS_CLK_NS, USB_HS1_XCVR_FS_CLK_MD); |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 130 | } |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 131 | |
| 132 | /* Configure UART clock - based on the gsbi id */ |
| 133 | void clock_config_uart_dm(uint8_t id) |
| 134 | { |
| 135 | /* Enable gsbi_uart_clk */ |
| 136 | clock_config(UART_DM_CLK_NS_115200, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 137 | UART_DM_CLK_MD_115200, |
| 138 | GSBIn_UART_APPS_NS(id), GSBIn_UART_APPS_MD(id)); |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 139 | |
| 140 | /* Enable gsbi_pclk */ |
| 141 | writel(GSBI_HCLK_CTL_CLK_ENA << GSBI_HCLK_CTL_S, GSBIn_HCLK_CTL(id)); |
| 142 | } |
| 143 | |
| 144 | /* Configure i2c clock */ |
| 145 | void clock_config_i2c(uint8_t id, uint32_t freq) |
| 146 | { |
| 147 | uint32_t ns; |
| 148 | uint32_t md; |
| 149 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 150 | switch (freq) { |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 151 | case 24000000: |
| 152 | ns = I2C_CLK_NS_24MHz; |
| 153 | md = I2C_CLK_MD_24MHz; |
| 154 | break; |
| 155 | default: |
| 156 | ASSERT(0); |
| 157 | } |
| 158 | |
| 159 | clock_config(ns, md, GSBIn_QUP_APPS_NS(id), GSBIn_QUP_APPS_MD(id)); |
| 160 | |
| 161 | /* Enable the GSBI HCLK */ |
| 162 | writel(GSBI_HCLK_CTL_CLK_ENA << GSBI_HCLK_CTL_S, GSBIn_HCLK_CTL(id)); |
| 163 | } |
| 164 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 165 | void pll1_enable(void) |
| 166 | { |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 167 | uint32_t val = 0; |
| 168 | |
| 169 | /* Reset MND divider */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 170 | val |= (1 << 2); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 171 | writel(val, MM_PLL1_MODE_REG); |
| 172 | |
| 173 | /* Use PLL -- Disable Bypass */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 174 | val |= (1 << 1); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 175 | writel(val, MM_PLL1_MODE_REG); |
| 176 | |
| 177 | /* Activate PLL out control */ |
| 178 | val |= 1; |
| 179 | writel(val, MM_PLL1_MODE_REG); |
| 180 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 181 | while (!readl(MM_PLL1_STATUS_REG)) ; |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Amol Jadi | 8225456 | 2011-06-27 11:25:48 -0700 | [diff] [blame] | 184 | void config_mdp_lut_clk(void) |
| 185 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 186 | /* Force on */ |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 187 | writel(MDP_LUT_VAL, MDP_LUT_CC_REG); |
| 188 | } |
| 189 | |
| 190 | /* Turn on MDP related clocks and pll's for MDP */ |
| 191 | void mdp_clock_init(void) |
| 192 | { |
| 193 | /* Turn on the PLL1, as source for MDP clock */ |
| 194 | pll1_enable(); |
| 195 | |
| 196 | /* Turn on MDP clk */ |
| 197 | config_mmss_clk(MDP_NS_VAL, MDP_MD_VAL, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 198 | MDP_CC_VAL, MDP_NS_REG, MDP_MD_REG, MDP_CC_REG); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 199 | |
| 200 | /* Seems to lose pixels without this from status 0x051E0048 */ |
| 201 | config_mdp_lut_clk(); |
| 202 | } |
| 203 | |
| 204 | /* Initialize all clocks needed by Display */ |
Amol Jadi | 8225456 | 2011-06-27 11:25:48 -0700 | [diff] [blame] | 205 | void mmss_clock_init(void) |
| 206 | { |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 207 | /* Configure Pixel clock */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 208 | config_mmss_clk(PIXEL_NS_VAL, PIXEL_MD_VAL, PIXEL_CC_VAL, PIXEL_NS_REG, |
| 209 | PIXEL_MD_REG, PIXEL_CC_REG); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 210 | |
| 211 | /* Configure DSI clock */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 212 | config_mmss_clk(DSI_NS_VAL, DSI_MD_VAL, DSI_CC_VAL, DSI_NS_REG, |
| 213 | DSI_MD_REG, DSI_CC_REG); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 214 | |
| 215 | /* Configure Byte clock */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 216 | config_mmss_clk(BYTE_NS_VAL, 0x0, BYTE_CC_VAL, BYTE_NS_REG, 0x0, |
| 217 | BYTE_CC_REG); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 218 | |
| 219 | /* Configure ESC clock */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 220 | config_mmss_clk(ESC_NS_VAL, 0x0, ESC_CC_VAL, ESC_NS_REG, 0x0, |
| 221 | ESC_CC_REG); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 222 | } |
Amol Jadi | 8225456 | 2011-06-27 11:25:48 -0700 | [diff] [blame] | 223 | |
| 224 | /* Intialize MMC clock */ |
| 225 | void clock_init_mmc(uint32_t interface) |
| 226 | { |
| 227 | /* Nothing to be done. */ |
| 228 | } |
| 229 | |
| 230 | /* Configure MMC clock */ |
| 231 | void clock_config_mmc(uint32_t interface, uint32_t freq) |
| 232 | { |
| 233 | uint32_t reg = 0; |
| 234 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 235 | switch (freq) { |
Amol Jadi | 8225456 | 2011-06-27 11:25:48 -0700 | [diff] [blame] | 236 | case MMC_CLK_400KHZ: |
| 237 | clock_config(SDC_CLK_NS_400KHZ, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 238 | SDC_CLK_MD_400KHZ, |
| 239 | SDC_NS(interface), SDC_MD(interface)); |
Amol Jadi | 8225456 | 2011-06-27 11:25:48 -0700 | [diff] [blame] | 240 | break; |
| 241 | case MMC_CLK_48MHZ: |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 242 | case MMC_CLK_50MHZ: /* Max supported is 48MHZ */ |
Amol Jadi | 8225456 | 2011-06-27 11:25:48 -0700 | [diff] [blame] | 243 | clock_config(SDC_CLK_NS_48MHZ, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 244 | SDC_CLK_MD_48MHZ, |
| 245 | SDC_NS(interface), SDC_MD(interface)); |
Amol Jadi | 8225456 | 2011-06-27 11:25:48 -0700 | [diff] [blame] | 246 | break; |
| 247 | default: |
| 248 | ASSERT(0); |
| 249 | |
| 250 | } |
| 251 | |
| 252 | reg |= MMC_BOOT_MCI_CLK_ENABLE; |
| 253 | reg |= MMC_BOOT_MCI_CLK_ENA_FLOW; |
| 254 | reg |= MMC_BOOT_MCI_CLK_IN_FEEDBACK; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 255 | writel(reg, MMC_BOOT_MCI_CLK); |
Amol Jadi | 8225456 | 2011-06-27 11:25:48 -0700 | [diff] [blame] | 256 | } |
Shashank Mittal | 1fcde7a | 2011-07-25 13:41:50 -0700 | [diff] [blame] | 257 | |
| 258 | /* Configure crypto engine clock */ |
| 259 | void ce_clock_init(void) |
| 260 | { |
| 261 | /* Enable HCLK for CE1 */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 262 | writel((1 << 4), CE1_HCLK_CTL); |
Shashank Mittal | 1fcde7a | 2011-07-25 13:41:50 -0700 | [diff] [blame] | 263 | /* Enable core clk for CE1 */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame^] | 264 | writel((1 << 4), CE1_CORE_CLK_CTL); |
Shashank Mittal | 1fcde7a | 2011-07-25 13:41:50 -0700 | [diff] [blame] | 265 | return; |
| 266 | } |