Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 4 | * Copyright (c) 2009-2011, The Linux Foundation. All rights reserved. |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * * Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in |
| 13 | * the documentation and/or other materials provided with the |
| 14 | * distribution. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 19 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 20 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 22 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 23 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 24 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 26 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | */ |
| 29 | #include <reg.h> |
| 30 | #include <stdint.h> |
| 31 | #include <debug.h> |
| 32 | #include <gsbi.h> |
| 33 | #include <platform/iomap.h> |
| 34 | #include <platform/clock.h> |
| 35 | |
| 36 | /* Set rate and enable the clock */ |
| 37 | void clock_config(uint32_t ns, uint32_t md, uint32_t ns_addr, uint32_t md_addr) |
| 38 | { |
| 39 | unsigned int val = 0; |
| 40 | |
| 41 | /* Activate the reset for the M/N Counter */ |
| 42 | val = 1 << 7; |
| 43 | writel(val, ns_addr); |
| 44 | |
| 45 | /* Write the MD value into the MD register */ |
| 46 | if (md_addr != 0x0) |
| 47 | writel(md, md_addr); |
| 48 | |
| 49 | /* Write the ns value, and active reset for M/N Counter, again */ |
| 50 | val = 1 << 7; |
| 51 | val |= ns; |
| 52 | writel(val, ns_addr); |
| 53 | |
| 54 | /* De-activate the reset for M/N Counter */ |
| 55 | val = 1 << 7; |
| 56 | val = ~val; |
| 57 | val = val & readl(ns_addr); |
| 58 | writel(val, ns_addr); |
| 59 | |
| 60 | /* Enable the Clock Root */ |
| 61 | val = 1 << 11; |
| 62 | val = val | readl(ns_addr); |
| 63 | writel(val, ns_addr); |
| 64 | |
| 65 | /* Enable the Clock Branch */ |
| 66 | val = 1 << 9; |
| 67 | val = val | readl(ns_addr); |
| 68 | writel(val, ns_addr); |
| 69 | |
| 70 | /* Enable the M/N Counter */ |
| 71 | val = 1 << 8; |
| 72 | val = val | readl(ns_addr); |
| 73 | writel(val, ns_addr); |
| 74 | } |
| 75 | |
| 76 | void pll8_enable(void) |
| 77 | { |
| 78 | unsigned int curr_value = 0; |
| 79 | |
| 80 | /* Vote for PLL8 to be enabled */ |
| 81 | curr_value = readl(MSM_BOOT_PLL_ENABLE_SC0); |
| 82 | curr_value |= (1 << 8); |
| 83 | writel(curr_value, MSM_BOOT_PLL_ENABLE_SC0); |
| 84 | |
| 85 | /* Proceed only after PLL is enabled */ |
| 86 | while (!(readl(MSM_BOOT_PLL8_STATUS) & (1<<16))); |
| 87 | } |
| 88 | |
| 89 | void acpu_clock_init(void) |
| 90 | { |
| 91 | /* ADM3: enable cc_adm0_clk */ |
| 92 | writel( (1 << SC0_U_BRANCH_ENA_VOTE_ADM0) | |
| 93 | (1 << SC0_U_BRANCH_ENA_VOTE_ADM0_PBUS), SC0_U_BRANCH_ENA_VOTE); |
| 94 | } |
| 95 | |
| 96 | void hsusb_clock_init(void) |
| 97 | { |
Deepa Dinamani | 1129150 | 2011-11-18 14:28:05 -0800 | [diff] [blame] | 98 | uint32_t reg; |
| 99 | |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 100 | pll8_enable(); |
| 101 | |
| 102 | /* Setup USB HS1 System clock - 60 Mhz */ |
| 103 | //TODO: Remove this when verify that this is already configured |
| 104 | if (!(readl(USB_HS1_SYSTEM_CLK_NS))){ |
| 105 | clock_config(USB_XCVR_CLK_NS, |
| 106 | USB_XCVR_CLK_MD, |
| 107 | USB_HS1_SYSTEM_CLK_NS, |
| 108 | USB_HS1_SYSTEM_CLK_MD); |
| 109 | } |
| 110 | |
| 111 | /* Setup USB HS1 XCVR clock - 60 Mhz */ |
| 112 | clock_config(USB_XCVR_CLK_NS, |
| 113 | USB_XCVR_CLK_MD, |
| 114 | USB_HS1_XCVR_FS_CLK_NS, |
| 115 | USB_HS1_XCVR_FS_CLK_MD); |
| 116 | |
| 117 | /* HS-USB: enable cc_usb_hs1_hs_clk */ |
Deepa Dinamani | 1129150 | 2011-11-18 14:28:05 -0800 | [diff] [blame] | 118 | reg = readl(USB_HS1_HCLK_CTL); |
| 119 | reg |= 0x1 << 4; |
| 120 | writel( reg, USB_HS1_HCLK_CTL); |
Kinson Chik | 18e3633 | 2011-08-15 10:07:28 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /* Configure UART clock - based on the gsbi id */ |
| 124 | void clock_config_uart_dm(uint8_t id) |
| 125 | { |
| 126 | /* Enable gsbi_uart_clk */ |
| 127 | clock_config(UART_DM_CLK_NS_115200, |
| 128 | UART_DM_CLK_MD_115200, |
| 129 | GSBIn_UART_APPS_NS(id), |
| 130 | GSBIn_UART_APPS_MD(id)); |
| 131 | |
| 132 | /* Enable gsbi_pclk */ |
| 133 | writel(GSBI_HCLK_CTL_CLK_ENA << GSBI_HCLK_CTL_S, GSBIn_HCLK_CTL(id)); |
| 134 | } |