Saravana Kannan | c85ecf9 | 2013-01-21 17:58:35 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Chandan Uddaraju | 09adf32 | 2012-08-16 02:55:23 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/io.h> |
| 15 | #include <linux/err.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/iopoll.h> |
| 19 | #include <linux/clk.h> |
| 20 | |
| 21 | #include <asm/processor.h> |
| 22 | #include <mach/msm_iomap.h> |
Matt Wagantall | 33d01f5 | 2012-02-23 23:27:44 -0800 | [diff] [blame] | 23 | #include <mach/clk-provider.h> |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 24 | #include <mach/clk.h> |
| 25 | #include <mach/clock-generic.h> |
Chandan Uddaraju | 09adf32 | 2012-08-16 02:55:23 -0700 | [diff] [blame] | 26 | |
Chandan Uddaraju | 09adf32 | 2012-08-16 02:55:23 -0700 | [diff] [blame] | 27 | #include "clock-mdss-8974.h" |
| 28 | |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 29 | #define REG_R(addr) readl_relaxed(addr) |
| 30 | #define REG_W(data, addr) writel_relaxed(data, addr) |
| 31 | #define DSS_REG_W(base, offset, data) REG_W((data), (base) + (offset)) |
| 32 | #define DSS_REG_R(base, offset) REG_R((base) + (offset)) |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 33 | |
Matt Wagantall | 7cf535b | 2013-02-28 16:16:51 -0800 | [diff] [blame] | 34 | #define GDSC_PHYS 0xFD8C2304 |
| 35 | #define GDSC_SIZE 0x4 |
| 36 | |
Vikram Mulukutla | 81e17e5 | 2013-05-02 20:31:51 -0700 | [diff] [blame] | 37 | #define DSI_PHY_PHYS 0xFD922A00 |
| 38 | #define DSI_PHY_SIZE 0x000000D4 |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 39 | |
| 40 | #define HDMI_PHY_PHYS 0xFD922500 |
| 41 | #define HDMI_PHY_SIZE 0x0000007C |
| 42 | |
| 43 | #define HDMI_PHY_PLL_PHYS 0xFD922700 |
| 44 | #define HDMI_PHY_PLL_SIZE 0x000000D4 |
| 45 | |
| 46 | /* hdmi phy registers */ |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 47 | #define HDMI_PHY_ANA_CFG0 (0x0000) |
| 48 | #define HDMI_PHY_ANA_CFG1 (0x0004) |
| 49 | #define HDMI_PHY_ANA_CFG2 (0x0008) |
| 50 | #define HDMI_PHY_ANA_CFG3 (0x000C) |
| 51 | #define HDMI_PHY_PD_CTRL0 (0x0010) |
| 52 | #define HDMI_PHY_PD_CTRL1 (0x0014) |
| 53 | #define HDMI_PHY_GLB_CFG (0x0018) |
| 54 | #define HDMI_PHY_DCC_CFG0 (0x001C) |
| 55 | #define HDMI_PHY_DCC_CFG1 (0x0020) |
| 56 | #define HDMI_PHY_TXCAL_CFG0 (0x0024) |
| 57 | #define HDMI_PHY_TXCAL_CFG1 (0x0028) |
| 58 | #define HDMI_PHY_TXCAL_CFG2 (0x002C) |
| 59 | #define HDMI_PHY_TXCAL_CFG3 (0x0030) |
| 60 | #define HDMI_PHY_BIST_CFG0 (0x0034) |
| 61 | #define HDMI_PHY_BIST_CFG1 (0x0038) |
| 62 | #define HDMI_PHY_BIST_PATN0 (0x003C) |
| 63 | #define HDMI_PHY_BIST_PATN1 (0x0040) |
| 64 | #define HDMI_PHY_BIST_PATN2 (0x0044) |
| 65 | #define HDMI_PHY_BIST_PATN3 (0x0048) |
| 66 | #define HDMI_PHY_STATUS (0x005C) |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 67 | |
| 68 | /* hdmi phy unified pll registers */ |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 69 | #define HDMI_UNI_PLL_REFCLK_CFG (0x0000) |
| 70 | #define HDMI_UNI_PLL_POSTDIV1_CFG (0x0004) |
| 71 | #define HDMI_UNI_PLL_CHFPUMP_CFG (0x0008) |
| 72 | #define HDMI_UNI_PLL_VCOLPF_CFG (0x000C) |
| 73 | #define HDMI_UNI_PLL_VREG_CFG (0x0010) |
| 74 | #define HDMI_UNI_PLL_PWRGEN_CFG (0x0014) |
| 75 | #define HDMI_UNI_PLL_GLB_CFG (0x0020) |
| 76 | #define HDMI_UNI_PLL_POSTDIV2_CFG (0x0024) |
| 77 | #define HDMI_UNI_PLL_POSTDIV3_CFG (0x0028) |
| 78 | #define HDMI_UNI_PLL_LPFR_CFG (0x002C) |
| 79 | #define HDMI_UNI_PLL_LPFC1_CFG (0x0030) |
| 80 | #define HDMI_UNI_PLL_LPFC2_CFG (0x0034) |
| 81 | #define HDMI_UNI_PLL_SDM_CFG0 (0x0038) |
| 82 | #define HDMI_UNI_PLL_SDM_CFG1 (0x003C) |
| 83 | #define HDMI_UNI_PLL_SDM_CFG2 (0x0040) |
| 84 | #define HDMI_UNI_PLL_SDM_CFG3 (0x0044) |
| 85 | #define HDMI_UNI_PLL_SDM_CFG4 (0x0048) |
| 86 | #define HDMI_UNI_PLL_SSC_CFG0 (0x004C) |
| 87 | #define HDMI_UNI_PLL_SSC_CFG1 (0x0050) |
| 88 | #define HDMI_UNI_PLL_SSC_CFG2 (0x0054) |
| 89 | #define HDMI_UNI_PLL_SSC_CFG3 (0x0058) |
| 90 | #define HDMI_UNI_PLL_LKDET_CFG0 (0x005C) |
| 91 | #define HDMI_UNI_PLL_LKDET_CFG1 (0x0060) |
| 92 | #define HDMI_UNI_PLL_LKDET_CFG2 (0x0064) |
| 93 | #define HDMI_UNI_PLL_CAL_CFG0 (0x006C) |
| 94 | #define HDMI_UNI_PLL_CAL_CFG1 (0x0070) |
| 95 | #define HDMI_UNI_PLL_CAL_CFG2 (0x0074) |
| 96 | #define HDMI_UNI_PLL_CAL_CFG3 (0x0078) |
| 97 | #define HDMI_UNI_PLL_CAL_CFG4 (0x007C) |
| 98 | #define HDMI_UNI_PLL_CAL_CFG5 (0x0080) |
| 99 | #define HDMI_UNI_PLL_CAL_CFG6 (0x0084) |
| 100 | #define HDMI_UNI_PLL_CAL_CFG7 (0x0088) |
| 101 | #define HDMI_UNI_PLL_CAL_CFG8 (0x008C) |
| 102 | #define HDMI_UNI_PLL_CAL_CFG9 (0x0090) |
| 103 | #define HDMI_UNI_PLL_CAL_CFG10 (0x0094) |
| 104 | #define HDMI_UNI_PLL_CAL_CFG11 (0x0098) |
| 105 | #define HDMI_UNI_PLL_STATUS (0x00C0) |
Chandan Uddaraju | 09adf32 | 2012-08-16 02:55:23 -0700 | [diff] [blame] | 106 | |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 107 | #define DSI_0_PHY_PLL_UNIPHY_PLL_REFCLK_CFG (0x00000000) |
| 108 | #define DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV1_CFG (0x00000004) |
| 109 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CHGPUMP_CFG (0x00000008) |
| 110 | #define DSI_0_PHY_PLL_UNIPHY_PLL_VCOLPF_CFG (0x0000000C) |
| 111 | #define DSI_0_PHY_PLL_UNIPHY_PLL_VREG_CFG (0x00000010) |
| 112 | #define DSI_0_PHY_PLL_UNIPHY_PLL_PWRGEN_CFG (0x00000014) |
| 113 | #define DSI_0_PHY_PLL_UNIPHY_PLL_DMUX_CFG (0x00000018) |
| 114 | #define DSI_0_PHY_PLL_UNIPHY_PLL_AMUX_CFG (0x0000001C) |
| 115 | #define DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG (0x00000020) |
| 116 | #define DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV2_CFG (0x00000024) |
| 117 | #define DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV3_CFG (0x00000028) |
| 118 | #define DSI_0_PHY_PLL_UNIPHY_PLL_LPFR_CFG (0x0000002C) |
| 119 | #define DSI_0_PHY_PLL_UNIPHY_PLL_LPFC1_CFG (0x00000030) |
| 120 | #define DSI_0_PHY_PLL_UNIPHY_PLL_LPFC2_CFG (0x00000034) |
| 121 | #define DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG0 (0x00000038) |
| 122 | #define DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG1 (0x0000003C) |
| 123 | #define DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG2 (0x00000040) |
| 124 | #define DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG3 (0x00000044) |
| 125 | #define DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG4 (0x00000048) |
| 126 | #define DSI_0_PHY_PLL_UNIPHY_PLL_SSC_CFG0 (0x0000004C) |
| 127 | #define DSI_0_PHY_PLL_UNIPHY_PLL_SSC_CFG1 (0x00000050) |
| 128 | #define DSI_0_PHY_PLL_UNIPHY_PLL_SSC_CFG2 (0x00000054) |
| 129 | #define DSI_0_PHY_PLL_UNIPHY_PLL_SSC_CFG3 (0x00000058) |
| 130 | #define DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG0 (0x0000005C) |
| 131 | #define DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG1 (0x00000060) |
| 132 | #define DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2 (0x00000064) |
| 133 | #define DSI_0_PHY_PLL_UNIPHY_PLL_TEST_CFG (0x00000068) |
| 134 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG0 (0x0000006C) |
| 135 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG1 (0x00000070) |
| 136 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG2 (0x00000074) |
| 137 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG3 (0x00000078) |
| 138 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG4 (0x0000007C) |
| 139 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG5 (0x00000080) |
| 140 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG6 (0x00000084) |
| 141 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG7 (0x00000088) |
| 142 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG8 (0x0000008C) |
| 143 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG9 (0x00000090) |
| 144 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG10 (0x00000094) |
| 145 | #define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG11 (0x00000098) |
| 146 | #define DSI_0_PHY_PLL_UNIPHY_PLL_EFUSE_CFG (0x0000009C) |
| 147 | #define DSI_0_PHY_PLL_UNIPHY_PLL_STATUS (0x000000C0) |
| 148 | |
| 149 | #define PLL_POLL_MAX_READS 10 |
| 150 | #define PLL_POLL_TIMEOUT_US 50 |
| 151 | |
| 152 | static long vco_cached_rate; |
Chandan Uddaraju | 09adf32 | 2012-08-16 02:55:23 -0700 | [diff] [blame] | 153 | static unsigned char *mdss_dsi_base; |
Matt Wagantall | 7cf535b | 2013-02-28 16:16:51 -0800 | [diff] [blame] | 154 | static unsigned char *gdsc_base; |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 155 | static struct clk *mdss_ahb_clk; |
Chandan Uddaraju | 09adf32 | 2012-08-16 02:55:23 -0700 | [diff] [blame] | 156 | |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 157 | static void __iomem *hdmi_phy_base; |
| 158 | static void __iomem *hdmi_phy_pll_base; |
| 159 | static unsigned hdmi_pll_on; |
| 160 | |
Matt Wagantall | 7cf535b | 2013-02-28 16:16:51 -0800 | [diff] [blame] | 161 | static int mdss_gdsc_enabled(void) |
| 162 | { |
| 163 | if (!gdsc_base) |
| 164 | return 0; |
| 165 | |
| 166 | return !!(readl_relaxed(gdsc_base) & BIT(31)); |
| 167 | } |
| 168 | |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 169 | void hdmi_pll_disable(void) |
| 170 | { |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 171 | clk_enable(mdss_ahb_clk); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 172 | REG_W(0x0, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 173 | udelay(5); |
| 174 | REG_W(0x0, hdmi_phy_base + HDMI_PHY_GLB_CFG); |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 175 | clk_disable(mdss_ahb_clk); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 176 | |
| 177 | hdmi_pll_on = 0; |
| 178 | } /* hdmi_pll_disable */ |
| 179 | |
| 180 | int hdmi_pll_enable(void) |
| 181 | { |
| 182 | u32 status; |
| 183 | u32 max_reads, timeout_us; |
| 184 | |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 185 | clk_enable(mdss_ahb_clk); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 186 | /* Global Enable */ |
| 187 | REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG); |
| 188 | /* Power up power gen */ |
| 189 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL0); |
| 190 | udelay(350); |
| 191 | |
| 192 | /* PLL Power-Up */ |
| 193 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 194 | udelay(5); |
| 195 | /* Power up PLL LDO */ |
| 196 | REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 197 | udelay(350); |
| 198 | |
| 199 | /* PLL Power-Up */ |
| 200 | REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 201 | udelay(350); |
| 202 | |
| 203 | /* poll for PLL ready status */ |
| 204 | max_reads = 20; |
| 205 | timeout_us = 100; |
| 206 | if (readl_poll_timeout_noirq((hdmi_phy_pll_base + HDMI_UNI_PLL_STATUS), |
| 207 | status, ((status & BIT(0)) == 1), max_reads, timeout_us)) { |
| 208 | pr_err("%s: hdmi phy pll status=%x failed to Lock\n", |
| 209 | __func__, status); |
| 210 | hdmi_pll_disable(); |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 211 | clk_disable(mdss_ahb_clk); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 212 | return -EINVAL; |
| 213 | } |
| 214 | pr_debug("%s: hdmi phy pll is locked\n", __func__); |
| 215 | |
| 216 | udelay(350); |
| 217 | /* poll for PHY ready status */ |
| 218 | max_reads = 20; |
| 219 | timeout_us = 100; |
| 220 | if (readl_poll_timeout_noirq((hdmi_phy_base + HDMI_PHY_STATUS), |
| 221 | status, ((status & BIT(0)) == 1), max_reads, timeout_us)) { |
| 222 | pr_err("%s: hdmi phy status=%x failed to Lock\n", |
| 223 | __func__, status); |
| 224 | hdmi_pll_disable(); |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 225 | clk_disable(mdss_ahb_clk); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 226 | return -EINVAL; |
| 227 | } |
| 228 | pr_debug("%s: hdmi phy is locked\n", __func__); |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 229 | clk_disable(mdss_ahb_clk); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 230 | |
| 231 | hdmi_pll_on = 1; |
| 232 | |
| 233 | return 0; |
| 234 | } /* hdmi_pll_enable */ |
| 235 | |
| 236 | int hdmi_pll_set_rate(unsigned long rate) |
| 237 | { |
| 238 | unsigned int set_power_dwn = 0; |
| 239 | |
| 240 | if (hdmi_pll_on) { |
| 241 | hdmi_pll_disable(); |
| 242 | set_power_dwn = 1; |
| 243 | } |
| 244 | |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 245 | clk_enable(mdss_ahb_clk); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 246 | pr_debug("%s: rate=%ld\n", __func__, rate); |
| 247 | switch (rate) { |
| 248 | case 0: |
| 249 | /* This case is needed for suspend/resume. */ |
| 250 | break; |
| 251 | |
| 252 | case 25200000: |
| 253 | /* 640x480p60 */ |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 254 | REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG); |
| 255 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 256 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG); |
| 257 | REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG); |
| 258 | REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG); |
| 259 | REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG); |
| 260 | REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG); |
| 261 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0); |
| 262 | REG_W(0x52, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 263 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 264 | REG_W(0xB0, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 265 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4); |
| 266 | REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0); |
| 267 | REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1); |
| 268 | REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 269 | REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 270 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG); |
| 271 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 272 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 273 | REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8); |
| 274 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 275 | REG_W(0xF4, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10); |
| 276 | REG_W(0x02, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11); |
| 277 | REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0); |
| 278 | udelay(50); |
| 279 | |
| 280 | REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 281 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1); |
| 282 | REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 283 | REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0); |
| 284 | REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1); |
| 285 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 286 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3); |
| 287 | REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG); |
| 288 | REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0); |
| 289 | REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1); |
| 290 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0); |
| 291 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1); |
| 292 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2); |
| 293 | REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3); |
| 294 | udelay(200); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 295 | break; |
| 296 | |
Ujwal Patel | e698fae | 2012-11-29 14:04:33 -0800 | [diff] [blame] | 297 | case 27000000: |
| 298 | /* 576p50/576i50 case */ |
| 299 | REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG); |
| 300 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 301 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG); |
| 302 | REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG); |
| 303 | REG_W(0X0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG); |
| 304 | REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG); |
| 305 | REG_W(0X0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG); |
| 306 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0); |
| 307 | REG_W(0x54, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1); |
| 308 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2); |
| 309 | REG_W(0x18, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3); |
| 310 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4); |
| 311 | REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0); |
| 312 | REG_W(0X1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1); |
| 313 | REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2); |
| 314 | REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG); |
| 315 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG); |
| 316 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG); |
| 317 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2); |
| 318 | REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8); |
| 319 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9); |
| 320 | REG_W(0x2a, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10); |
| 321 | REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11); |
| 322 | REG_W(0X1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0); |
| 323 | udelay(50); |
| 324 | |
| 325 | REG_W(0X0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 326 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1); |
| 327 | REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 328 | REG_W(0XDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0); |
| 329 | REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1); |
| 330 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 331 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3); |
| 332 | REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG); |
| 333 | REG_W(0XD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0); |
| 334 | REG_W(0X1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1); |
| 335 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0); |
| 336 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1); |
| 337 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2); |
| 338 | REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3); |
| 339 | udelay(200); |
| 340 | break; |
| 341 | |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 342 | case 27030000: |
| 343 | /* 480p60/480i60 case */ |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 344 | REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG); |
| 345 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 346 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG); |
| 347 | REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG); |
| 348 | REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG); |
| 349 | REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG); |
| 350 | REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG); |
| 351 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0); |
| 352 | REG_W(0x54, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1); |
| 353 | REG_W(0x66, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 354 | REG_W(0x1D, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3); |
| 355 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4); |
| 356 | REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0); |
| 357 | REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1); |
| 358 | REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2); |
| 359 | REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG); |
| 360 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG); |
| 361 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 362 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 363 | REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8); |
| 364 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9); |
| 365 | REG_W(0x2A, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10); |
| 366 | REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 367 | REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0); |
| 368 | udelay(50); |
| 369 | |
| 370 | REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 371 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1); |
| 372 | REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 373 | REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0); |
| 374 | REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1); |
| 375 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 376 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3); |
| 377 | REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG); |
| 378 | REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0); |
| 379 | REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1); |
| 380 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0); |
| 381 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1); |
| 382 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2); |
| 383 | REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3); |
| 384 | udelay(200); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 385 | break; |
Manoj Rao | 6c1d279 | 2013-05-08 11:59:38 -0700 | [diff] [blame] | 386 | case 65000000: |
| 387 | REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG); |
| 388 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 389 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG); |
| 390 | REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG); |
| 391 | REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG); |
| 392 | REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG); |
| 393 | REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG); |
| 394 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0); |
| 395 | REG_W(0x4F, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1); |
| 396 | REG_W(0x55, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2); |
| 397 | REG_W(0xED, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3); |
| 398 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4); |
| 399 | REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0); |
| 400 | REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1); |
| 401 | REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2); |
| 402 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG); |
| 403 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG); |
| 404 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG); |
| 405 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2); |
| 406 | REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8); |
| 407 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9); |
| 408 | REG_W(0x8A, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10); |
| 409 | REG_W(0x02, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11); |
| 410 | REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0); |
| 411 | udelay(50); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 412 | |
Manoj Rao | 6c1d279 | 2013-05-08 11:59:38 -0700 | [diff] [blame] | 413 | REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 414 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1); |
| 415 | REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 416 | REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0); |
| 417 | REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1); |
| 418 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 419 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3); |
| 420 | REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG); |
| 421 | REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0); |
| 422 | REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1); |
| 423 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0); |
| 424 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1); |
| 425 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2); |
| 426 | REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3); |
| 427 | udelay(200); |
| 428 | break; |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 429 | case 74250000: |
| 430 | /* |
| 431 | * 720p60/720p50/1080i60/1080i50 |
| 432 | * 1080p24/1080p30/1080p25 case |
| 433 | */ |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 434 | REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG); |
| 435 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 436 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG); |
| 437 | REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG); |
| 438 | REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG); |
| 439 | REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG); |
| 440 | REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG); |
| 441 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 442 | REG_W(0x52, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 443 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2); |
| 444 | REG_W(0x56, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 445 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4); |
| 446 | REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0); |
| 447 | REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1); |
| 448 | REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 449 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 450 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG); |
| 451 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 452 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 453 | REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8); |
| 454 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9); |
| 455 | REG_W(0xE6, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10); |
| 456 | REG_W(0x02, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 457 | REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0); |
| 458 | udelay(50); |
| 459 | |
| 460 | REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 461 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1); |
| 462 | REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 463 | REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0); |
| 464 | REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1); |
| 465 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 466 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3); |
| 467 | REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG); |
| 468 | REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0); |
| 469 | REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1); |
| 470 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0); |
| 471 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1); |
| 472 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2); |
| 473 | REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3); |
| 474 | udelay(200); |
| 475 | break; |
| 476 | |
Manoj Rao | 6c1d279 | 2013-05-08 11:59:38 -0700 | [diff] [blame] | 477 | case 108000000: |
| 478 | REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG); |
| 479 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 480 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG); |
| 481 | REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG); |
| 482 | REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG); |
| 483 | REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG); |
| 484 | REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG); |
| 485 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0); |
| 486 | REG_W(0x5B, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1); |
| 487 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2); |
| 488 | REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3); |
| 489 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4); |
| 490 | REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0); |
| 491 | REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1); |
| 492 | REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2); |
| 493 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG); |
| 494 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG); |
| 495 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG); |
| 496 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2); |
| 497 | REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8); |
| 498 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9); |
| 499 | REG_W(0x38, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10); |
| 500 | REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11); |
| 501 | REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0); |
| 502 | udelay(50); |
| 503 | |
| 504 | REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 505 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1); |
| 506 | REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 507 | REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0); |
| 508 | REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1); |
| 509 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 510 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3); |
| 511 | REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG); |
| 512 | REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0); |
| 513 | REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1); |
| 514 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0); |
| 515 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1); |
| 516 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2); |
| 517 | REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3); |
| 518 | udelay(200); |
| 519 | break; |
| 520 | |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 521 | case 148500000: |
| 522 | REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG); |
| 523 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 524 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG); |
| 525 | REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG); |
| 526 | REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG); |
| 527 | REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG); |
| 528 | REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG); |
| 529 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0); |
| 530 | REG_W(0x52, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1); |
| 531 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2); |
| 532 | REG_W(0x56, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3); |
| 533 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4); |
| 534 | REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0); |
| 535 | REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1); |
| 536 | REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2); |
| 537 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG); |
| 538 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG); |
| 539 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG); |
| 540 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2); |
| 541 | REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8); |
| 542 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9); |
| 543 | REG_W(0xE6, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10); |
| 544 | REG_W(0x02, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11); |
| 545 | REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0); |
| 546 | udelay(50); |
| 547 | |
| 548 | REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 549 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1); |
| 550 | REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 551 | REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0); |
| 552 | REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1); |
| 553 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 554 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3); |
| 555 | REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG); |
| 556 | REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0); |
| 557 | REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1); |
| 558 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0); |
| 559 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1); |
| 560 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2); |
| 561 | REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3); |
| 562 | udelay(200); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 563 | break; |
| 564 | |
Ujwal Patel | e698fae | 2012-11-29 14:04:33 -0800 | [diff] [blame] | 565 | case 268500000: |
| 566 | REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG); |
| 567 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 568 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG); |
| 569 | REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG); |
| 570 | REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG); |
| 571 | REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG); |
| 572 | REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG); |
| 573 | REG_W(0x36, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0); |
| 574 | REG_W(0x61, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1); |
| 575 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2); |
| 576 | REG_W(0xF6, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3); |
| 577 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4); |
| 578 | REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0); |
| 579 | REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1); |
| 580 | REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2); |
| 581 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG); |
| 582 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG); |
| 583 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG); |
| 584 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2); |
| 585 | REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8); |
| 586 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9); |
| 587 | REG_W(0x3E, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10); |
| 588 | REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11); |
| 589 | REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0); |
| 590 | udelay(50); |
| 591 | |
| 592 | REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 593 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1); |
| 594 | REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 595 | REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0); |
| 596 | REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1); |
| 597 | REG_W(0x05, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 598 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3); |
| 599 | REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG); |
| 600 | REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0); |
| 601 | REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1); |
| 602 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0); |
| 603 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1); |
| 604 | REG_W(0x11, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2); |
| 605 | REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3); |
| 606 | udelay(200); |
| 607 | break; |
| 608 | |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 609 | case 297000000: |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 610 | REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG); |
| 611 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 612 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG); |
| 613 | REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG); |
| 614 | REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG); |
| 615 | REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG); |
| 616 | REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG); |
| 617 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 618 | REG_W(0x65, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 619 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 620 | REG_W(0xAC, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3); |
| 621 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4); |
| 622 | REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0); |
| 623 | REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1); |
| 624 | REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2); |
| 625 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG); |
| 626 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG); |
| 627 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 628 | REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 629 | REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8); |
| 630 | REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9); |
| 631 | REG_W(0xCD, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10); |
| 632 | REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11); |
Ujwal Patel | c801765 | 2012-11-15 18:03:01 -0800 | [diff] [blame] | 633 | REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0); |
| 634 | udelay(50); |
| 635 | |
| 636 | REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG); |
| 637 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1); |
| 638 | REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 639 | REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0); |
| 640 | REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1); |
| 641 | REG_W(0x06, hdmi_phy_base + HDMI_PHY_ANA_CFG2); |
| 642 | REG_W(0x03, hdmi_phy_base + HDMI_PHY_ANA_CFG3); |
| 643 | REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG); |
| 644 | REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0); |
| 645 | REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1); |
| 646 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0); |
| 647 | REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1); |
| 648 | REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2); |
| 649 | REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3); |
| 650 | udelay(200); |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 651 | break; |
| 652 | |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 653 | default: |
| 654 | pr_err("%s: not supported rate=%ld\n", __func__, rate); |
| 655 | } |
| 656 | |
| 657 | /* Make sure writes complete before disabling iface clock */ |
| 658 | mb(); |
| 659 | |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 660 | clk_disable(mdss_ahb_clk); |
Vikram Mulukutla | 5d581bd | 2012-11-30 11:51:41 -0800 | [diff] [blame] | 661 | |
Abhishek Kharbanda | c155984 | 2012-08-13 18:45:02 -0700 | [diff] [blame] | 662 | if (set_power_dwn) |
| 663 | hdmi_pll_enable(); |
| 664 | |
| 665 | return 0; |
| 666 | } /* hdmi_pll_set_rate */ |
| 667 | |
Vikram Mulukutla | 853e2fa | 2013-05-02 20:02:13 -0700 | [diff] [blame] | 668 | /* Auto PLL calibaration */ |
| 669 | int mdss_ahb_clk_enable(int enable) |
| 670 | { |
| 671 | int rc = 0; |
| 672 | |
| 673 | /* todo: Ideally, we should enable/disable GDSC whenever we are |
| 674 | * attempting to enable/disable MDSS AHB clock. |
| 675 | * For now, just return error if GDSC is not enabled. |
| 676 | */ |
| 677 | if (!mdss_gdsc_enabled()) |
| 678 | return -EPERM; |
| 679 | |
| 680 | if (enable) |
| 681 | rc = clk_prepare_enable(mdss_ahb_clk); |
| 682 | else |
| 683 | clk_disable_unprepare(mdss_ahb_clk); |
| 684 | |
| 685 | return rc; |
| 686 | } |
| 687 | |
| 688 | int set_byte_mux_sel(struct mux_clk *clk, int sel) |
| 689 | { |
| 690 | pr_debug("%s: byte mux set to %s mode\n", __func__, |
| 691 | sel ? "indirect" : "direct"); |
| 692 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_VREG_CFG, |
| 693 | (sel << 1)); |
| 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | int get_byte_mux_sel(struct mux_clk *clk) |
| 698 | { |
| 699 | int mux_mode; |
| 700 | |
| 701 | if (mdss_ahb_clk_enable(1)) { |
| 702 | pr_debug("%s: Failed to enable mdss ahb clock\n", __func__); |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | mux_mode = DSS_REG_R(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_VREG_CFG) |
| 707 | & BIT(1); |
| 708 | pr_debug("%s: byte mux mode = %s", __func__, |
| 709 | mux_mode ? "indirect" : "direct"); |
| 710 | |
| 711 | mdss_ahb_clk_enable(0); |
| 712 | return !!mux_mode; |
| 713 | } |
| 714 | |
| 715 | static inline struct dsi_pll_vco_clk *to_vco_clk(struct clk *clk) |
| 716 | { |
| 717 | return container_of(clk, struct dsi_pll_vco_clk, c); |
| 718 | } |
| 719 | |
| 720 | /* |
| 721 | * When the display is turned off, the display registers are wiped out. |
| 722 | * Temporarily use the prepare ops to restore the register values. |
| 723 | * |
| 724 | */ |
| 725 | int div_prepare(struct clk *c) |
| 726 | { |
| 727 | struct div_clk *div = to_div_clk(c); |
| 728 | /* Restore the divider's value */ |
| 729 | return div->ops->set_div(div, div->div); |
| 730 | } |
| 731 | |
| 732 | int mux_prepare(struct clk *c) |
| 733 | { |
| 734 | struct mux_clk *mux = to_mux_clk(c); |
| 735 | int i, rc, sel = 0; |
| 736 | |
| 737 | rc = mdss_ahb_clk_enable(1); |
| 738 | if (rc) { |
| 739 | pr_err("%s: failed to enable mdss ahb clock. rc=%d\n", |
| 740 | __func__, rc); |
| 741 | return rc; |
| 742 | } |
| 743 | |
| 744 | for (i = 0; i < mux->num_parents; i++) |
| 745 | if (mux->parents[i].src == c->parent) { |
| 746 | sel = mux->parents[i].sel; |
| 747 | break; |
| 748 | } |
| 749 | |
| 750 | if (i == mux->num_parents) { |
| 751 | rc = -EINVAL; |
| 752 | goto error; |
| 753 | } |
| 754 | |
| 755 | /* Restore the mux source select value */ |
| 756 | rc = mux->ops->set_mux_sel(mux, sel); |
| 757 | |
| 758 | error: |
| 759 | mdss_ahb_clk_enable(0); |
| 760 | return rc; |
| 761 | } |
| 762 | |
| 763 | static int fixed_4div_set_div(struct div_clk *clk, int div) |
| 764 | { |
| 765 | int rc = 0; |
| 766 | |
| 767 | rc = mdss_ahb_clk_enable(1); |
| 768 | if (rc) { |
| 769 | pr_err("%s: failed to enable mdss ahb clock. rc=%d\n", |
| 770 | __func__, rc); |
| 771 | return rc; |
| 772 | } |
| 773 | |
| 774 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV2_CFG, |
| 775 | (div - 1)); |
| 776 | |
| 777 | mdss_ahb_clk_enable(0); |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | static int fixed_4div_get_div(struct div_clk *clk) |
| 782 | { |
| 783 | int div = 0; |
| 784 | |
| 785 | if (mdss_ahb_clk_enable(1)) { |
| 786 | pr_debug("%s: Failed to enable mdss ahb clock\n", __func__); |
| 787 | return 1; |
| 788 | } |
| 789 | div = DSS_REG_R(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV2_CFG); |
| 790 | mdss_ahb_clk_enable(0); |
| 791 | return div + 1; |
| 792 | } |
| 793 | |
| 794 | static int digital_set_div(struct div_clk *clk, int div) |
| 795 | { |
| 796 | int rc = 0; |
| 797 | |
| 798 | rc = mdss_ahb_clk_enable(1); |
| 799 | if (rc) { |
| 800 | pr_err("%s: failed to enable mdss ahb clock. rc=%d\n", |
| 801 | __func__, rc); |
| 802 | return rc; |
| 803 | } |
| 804 | |
| 805 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV3_CFG, |
| 806 | (div - 1)); |
| 807 | |
| 808 | mdss_ahb_clk_enable(0); |
| 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | static int digital_get_div(struct div_clk *clk) |
| 813 | { |
| 814 | int div = 0; |
| 815 | |
| 816 | if (mdss_ahb_clk_enable(1)) { |
| 817 | pr_debug("%s: Failed to enable mdss ahb clock\n", __func__); |
| 818 | return 1; |
| 819 | } |
| 820 | div = DSS_REG_R(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV3_CFG); |
| 821 | mdss_ahb_clk_enable(0); |
| 822 | return div + 1; |
| 823 | } |
| 824 | |
| 825 | static int analog_set_div(struct div_clk *clk, int div) |
| 826 | { |
| 827 | int rc = 0; |
| 828 | |
| 829 | rc = mdss_ahb_clk_enable(1); |
| 830 | if (rc) { |
| 831 | pr_err("%s: failed to enable mdss ahb clock. rc=%d\n", |
| 832 | __func__, rc); |
| 833 | return rc; |
| 834 | } |
| 835 | |
| 836 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV1_CFG, |
| 837 | div - 1); |
| 838 | |
| 839 | mdss_ahb_clk_enable(0); |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | static int analog_get_div(struct div_clk *clk) |
| 844 | { |
| 845 | int div = 0; |
| 846 | |
| 847 | if (mdss_ahb_clk_enable(1)) { |
| 848 | pr_debug("%s: Failed to enable mdss ahb clock\n", __func__); |
| 849 | return 1; |
| 850 | } |
| 851 | div = DSS_REG_R(mdss_dsi_base, |
| 852 | DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV1_CFG) + 1; |
| 853 | mdss_ahb_clk_enable(0); |
| 854 | return div; |
| 855 | } |
| 856 | |
| 857 | static int dsi_pll_lock_status(void) |
| 858 | { |
| 859 | u32 status; |
| 860 | int pll_locked = 0; |
| 861 | |
| 862 | /* poll for PLL ready status */ |
| 863 | if (readl_poll_timeout_noirq((mdss_dsi_base + |
| 864 | DSI_0_PHY_PLL_UNIPHY_PLL_STATUS), |
| 865 | status, |
| 866 | ((status & BIT(0)) == 1), |
| 867 | PLL_POLL_MAX_READS, PLL_POLL_TIMEOUT_US)) { |
| 868 | pr_debug("%s: DSI PLL status=%x failed to Lock\n", |
| 869 | __func__, status); |
| 870 | pll_locked = 0; |
| 871 | } else { |
| 872 | pll_locked = 1; |
| 873 | } |
| 874 | |
| 875 | return pll_locked; |
| 876 | } |
| 877 | |
| 878 | static void dsi_pll_software_reset(void) |
| 879 | { |
| 880 | /* |
| 881 | * Add HW recommended delays after toggling the software |
| 882 | * reset bit off and back on. |
| 883 | */ |
| 884 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_TEST_CFG, 0x01); |
| 885 | udelay(1000); |
| 886 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_TEST_CFG, 0x00); |
| 887 | udelay(1000); |
| 888 | } |
| 889 | |
| 890 | static int dsi_pll_enable_seq_m(void) |
| 891 | { |
| 892 | int i = 0; |
| 893 | int pll_locked = 0; |
| 894 | |
| 895 | dsi_pll_software_reset(); |
| 896 | |
| 897 | /* |
| 898 | * Add hardware recommended delays between register writes for |
| 899 | * the updates to take effect. These delays are necessary for the |
| 900 | * PLL to successfully lock |
| 901 | */ |
| 902 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01); |
| 903 | udelay(200); |
| 904 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05); |
| 905 | udelay(200); |
| 906 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f); |
| 907 | udelay(1000); |
| 908 | |
| 909 | do { |
| 910 | pll_locked = dsi_pll_lock_status(); |
| 911 | if (!pll_locked) { |
| 912 | DSS_REG_W(mdss_dsi_base, |
| 913 | DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x07); |
| 914 | udelay(1); |
| 915 | DSS_REG_W(mdss_dsi_base, |
| 916 | DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f); |
| 917 | udelay(1000); |
| 918 | i++; |
| 919 | } |
| 920 | } while ((i < 3) && !pll_locked); |
| 921 | |
| 922 | if (pll_locked) |
| 923 | pr_debug("%s: PLL Locked at attempt #%d\n", __func__, i); |
| 924 | else |
| 925 | pr_debug("%s: PLL failed to lock after %d attempt(s)\n", |
| 926 | __func__, i); |
| 927 | |
| 928 | return pll_locked ? 0 : -EINVAL; |
| 929 | } |
| 930 | |
| 931 | static int dsi_pll_enable_seq_d(void) |
| 932 | { |
| 933 | int pll_locked = 0; |
| 934 | |
| 935 | dsi_pll_software_reset(); |
| 936 | |
| 937 | /* |
| 938 | * Add hardware recommended delays between register writes for |
| 939 | * the updates to take effect. These delays are necessary for the |
| 940 | * PLL to successfully lock |
| 941 | */ |
| 942 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01); |
| 943 | udelay(1); |
| 944 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05); |
| 945 | udelay(1); |
| 946 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x07); |
| 947 | udelay(1); |
| 948 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05); |
| 949 | udelay(1); |
| 950 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x07); |
| 951 | udelay(1); |
| 952 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f); |
| 953 | udelay(1); |
| 954 | |
| 955 | pll_locked = dsi_pll_lock_status(); |
| 956 | pr_debug("%s: PLL status = %s\n", __func__, |
| 957 | pll_locked ? "Locked" : "Unlocked"); |
| 958 | |
| 959 | return pll_locked ? 0 : -EINVAL; |
| 960 | } |
| 961 | |
| 962 | static int dsi_pll_enable_seq_f1(void) |
| 963 | { |
| 964 | int pll_locked = 0; |
| 965 | |
| 966 | dsi_pll_software_reset(); |
| 967 | |
| 968 | /* |
| 969 | * Add hardware recommended delays between register writes for |
| 970 | * the updates to take effect. These delays are necessary for the |
| 971 | * PLL to successfully lock |
| 972 | */ |
| 973 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01); |
| 974 | udelay(200); |
| 975 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05); |
| 976 | udelay(200); |
| 977 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f); |
| 978 | udelay(200); |
| 979 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0d); |
| 980 | udelay(200); |
| 981 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f); |
| 982 | udelay(1000); |
| 983 | |
| 984 | pll_locked = dsi_pll_lock_status(); |
| 985 | pr_debug("%s: PLL status = %s\n", __func__, |
| 986 | pll_locked ? "Locked" : "Unlocked"); |
| 987 | |
| 988 | return pll_locked ? 0 : -EINVAL; |
| 989 | } |
| 990 | |
| 991 | static int dsi_pll_enable_seq_c(void) |
| 992 | { |
| 993 | int pll_locked = 0; |
| 994 | |
| 995 | dsi_pll_software_reset(); |
| 996 | |
| 997 | /* |
| 998 | * Add hardware recommended delays between register writes for |
| 999 | * the updates to take effect. These delays are necessary for the |
| 1000 | * PLL to successfully lock |
| 1001 | */ |
| 1002 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01); |
| 1003 | udelay(200); |
| 1004 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05); |
| 1005 | udelay(200); |
| 1006 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f); |
| 1007 | udelay(1000); |
| 1008 | |
| 1009 | pll_locked = dsi_pll_lock_status(); |
| 1010 | pr_debug("%s: PLL status = %s\n", __func__, |
| 1011 | pll_locked ? "Locked" : "Unlocked"); |
| 1012 | |
| 1013 | return pll_locked ? 0 : -EINVAL; |
| 1014 | } |
| 1015 | |
| 1016 | static int dsi_pll_enable_seq_e(void) |
| 1017 | { |
| 1018 | int pll_locked = 0; |
| 1019 | |
| 1020 | dsi_pll_software_reset(); |
| 1021 | |
| 1022 | /* |
| 1023 | * Add hardware recommended delays between register writes for |
| 1024 | * the updates to take effect. These delays are necessary for the |
| 1025 | * PLL to successfully lock |
| 1026 | */ |
| 1027 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01); |
| 1028 | udelay(200); |
| 1029 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05); |
| 1030 | udelay(200); |
| 1031 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0d); |
| 1032 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f); |
| 1033 | udelay(1000); |
| 1034 | |
| 1035 | pll_locked = dsi_pll_lock_status(); |
| 1036 | pr_debug("%s: PLL status = %s\n", __func__, |
| 1037 | pll_locked ? "Locked" : "Unlocked"); |
| 1038 | |
| 1039 | return pll_locked ? 0 : -EINVAL; |
| 1040 | } |
| 1041 | |
| 1042 | static int dsi_pll_enable_seq_8974(void) |
| 1043 | { |
| 1044 | int i, rc = 0; |
| 1045 | u32 status, max_reads, timeout_us; |
| 1046 | |
| 1047 | dsi_pll_software_reset(); |
| 1048 | |
| 1049 | /* |
| 1050 | * PLL power up sequence. |
| 1051 | * Add necessary delays recommeded by hardware. |
| 1052 | */ |
| 1053 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01); |
| 1054 | udelay(1000); |
| 1055 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05); |
| 1056 | udelay(1000); |
| 1057 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x07); |
| 1058 | udelay(1000); |
| 1059 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f); |
| 1060 | udelay(1000); |
| 1061 | |
| 1062 | for (i = 0; i < 3; i++) { |
| 1063 | /* DSI Uniphy lock detect setting */ |
| 1064 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2, |
| 1065 | 0x04); |
| 1066 | udelay(100); |
| 1067 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2, |
| 1068 | 0x05); |
| 1069 | udelay(500); |
| 1070 | /* poll for PLL ready status */ |
| 1071 | max_reads = 5; |
| 1072 | timeout_us = 100; |
| 1073 | if (readl_poll_timeout_noirq((mdss_dsi_base + |
| 1074 | DSI_0_PHY_PLL_UNIPHY_PLL_STATUS), |
| 1075 | status, |
| 1076 | ((status & 0x01) == 1), |
| 1077 | max_reads, timeout_us)) { |
| 1078 | pr_debug("%s: DSI PLL status=%x failed to Lock\n", |
| 1079 | __func__, status); |
| 1080 | pr_debug("%s:Trying to power UP PLL again\n", |
| 1081 | __func__); |
| 1082 | } else { |
| 1083 | break; |
| 1084 | } |
| 1085 | |
| 1086 | dsi_pll_software_reset(); |
| 1087 | /* |
| 1088 | * PLL power up sequence. |
| 1089 | * Add necessary delays recommeded by hardware. |
| 1090 | */ |
| 1091 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x1); |
| 1092 | udelay(1000); |
| 1093 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x5); |
| 1094 | udelay(1000); |
| 1095 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x7); |
| 1096 | udelay(1000); |
| 1097 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x5); |
| 1098 | udelay(1000); |
| 1099 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x7); |
| 1100 | udelay(1000); |
| 1101 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0xf); |
| 1102 | udelay(2000); |
| 1103 | |
| 1104 | } |
| 1105 | |
| 1106 | if ((status & 0x01) != 1) { |
| 1107 | pr_debug("%s: DSI PLL status=%x failed to Lock\n", |
| 1108 | __func__, status); |
| 1109 | rc = -EINVAL; |
| 1110 | goto error; |
| 1111 | } |
| 1112 | |
| 1113 | pr_debug("%s: DSI PLL Lock success\n", __func__); |
| 1114 | |
| 1115 | error: |
| 1116 | return rc; |
| 1117 | } |
| 1118 | |
| 1119 | static int vco_enable(struct clk *c) |
| 1120 | { |
| 1121 | int i, rc = 0; |
| 1122 | struct dsi_pll_vco_clk *vco = to_vco_clk(c); |
| 1123 | |
| 1124 | rc = clk_enable(mdss_ahb_clk); |
| 1125 | if (rc) { |
| 1126 | pr_err("%s: failed to enable mdss ahb clock. rc=%d\n", |
| 1127 | __func__, rc); |
| 1128 | return rc; |
| 1129 | } |
| 1130 | |
| 1131 | /* Try all enable sequences until one succeeds */ |
| 1132 | for (i = 0; i < vco->pll_en_seq_cnt; i++) { |
| 1133 | rc = vco->pll_enable_seqs[i](); |
| 1134 | pr_debug("%s: DSI PLL %s after sequence #%d\n", __func__, |
| 1135 | rc ? "unlocked" : "locked", i + 1); |
| 1136 | if (!rc) |
| 1137 | break; |
| 1138 | } |
| 1139 | clk_disable(mdss_ahb_clk); |
| 1140 | |
| 1141 | if (rc) |
| 1142 | pr_err("%s: DSI PLL failed to lock\n", __func__); |
| 1143 | |
| 1144 | return rc; |
| 1145 | } |
| 1146 | |
| 1147 | static void vco_disable(struct clk *c) |
| 1148 | { |
| 1149 | int rc = 0; |
| 1150 | |
| 1151 | rc = clk_enable(mdss_ahb_clk); |
| 1152 | if (rc) { |
| 1153 | pr_err("%s: failed to enable mdss ahb clock. rc=%d\n", |
| 1154 | __func__, rc); |
| 1155 | return; |
| 1156 | } |
| 1157 | |
| 1158 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x00); |
| 1159 | |
| 1160 | clk_disable(mdss_ahb_clk); |
| 1161 | pr_debug("%s: DSI PLL Disabled\n", __func__); |
| 1162 | return; |
| 1163 | } |
| 1164 | |
| 1165 | static int vco_set_rate(struct clk *c, unsigned long rate) |
| 1166 | { |
| 1167 | s64 vco_clk_rate = rate; |
| 1168 | s32 rem; |
| 1169 | s64 refclk_cfg, frac_n_mode, ref_doubler_en_b; |
| 1170 | s64 ref_clk_to_pll, div_fbx1000, frac_n_value; |
| 1171 | s64 sdm_cfg0, sdm_cfg1, sdm_cfg2, sdm_cfg3; |
| 1172 | s64 gen_vco_clk, cal_cfg10, cal_cfg11; |
| 1173 | u32 res; |
| 1174 | int i, rc = 0; |
| 1175 | struct dsi_pll_vco_clk *vco = to_vco_clk(c); |
| 1176 | |
| 1177 | rc = mdss_ahb_clk_enable(1); |
| 1178 | if (rc) { |
| 1179 | pr_err("%s: failed to enable mdss ahb clock. rc=%d\n", |
| 1180 | __func__, rc); |
| 1181 | return rc; |
| 1182 | } |
| 1183 | |
| 1184 | /* Configure the Loop filter resistance */ |
| 1185 | for (i = 0; i < vco->lpfr_lut_size; i++) |
| 1186 | if (vco_clk_rate <= vco->lpfr_lut[i].vco_rate) |
| 1187 | break; |
| 1188 | if (i == vco->lpfr_lut_size) { |
| 1189 | pr_err("%s: unable to get loop filter resistance. vco=%ld\n", |
| 1190 | __func__, rate); |
| 1191 | rc = -EINVAL; |
| 1192 | goto error; |
| 1193 | } |
| 1194 | res = vco->lpfr_lut[i].r; |
| 1195 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LPFR_CFG, res); |
| 1196 | |
| 1197 | /* Loop filter capacitance values : c1 and c2 */ |
| 1198 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LPFC1_CFG, 0x70); |
| 1199 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LPFC2_CFG, 0x15); |
| 1200 | |
| 1201 | div_s64_rem(vco_clk_rate, vco->ref_clk_rate, &rem); |
| 1202 | if (rem) { |
| 1203 | refclk_cfg = 0x1; |
| 1204 | frac_n_mode = 1; |
| 1205 | ref_doubler_en_b = 0; |
| 1206 | } else { |
| 1207 | refclk_cfg = 0x0; |
| 1208 | frac_n_mode = 0; |
| 1209 | ref_doubler_en_b = 1; |
| 1210 | } |
| 1211 | |
| 1212 | pr_debug("%s:refclk_cfg = %lld\n", __func__, refclk_cfg); |
| 1213 | |
| 1214 | ref_clk_to_pll = ((vco->ref_clk_rate * 2 * (refclk_cfg)) |
| 1215 | + (ref_doubler_en_b * vco->ref_clk_rate)); |
| 1216 | div_fbx1000 = div_s64((vco_clk_rate * 1000), ref_clk_to_pll); |
| 1217 | |
| 1218 | div_s64_rem(div_fbx1000, 1000, &rem); |
| 1219 | frac_n_value = div_s64((rem * (1 << 16)), 1000); |
| 1220 | gen_vco_clk = div_s64(div_fbx1000 * ref_clk_to_pll, 1000); |
| 1221 | |
| 1222 | pr_debug("%s:ref_clk_to_pll = %lld\n", __func__, ref_clk_to_pll); |
| 1223 | pr_debug("%s:div_fb = %lld\n", __func__, div_fbx1000); |
| 1224 | pr_debug("%s:frac_n_value = %lld\n", __func__, frac_n_value); |
| 1225 | |
| 1226 | pr_debug("%s:Generated VCO Clock: %lld\n", __func__, gen_vco_clk); |
| 1227 | rem = 0; |
| 1228 | if (frac_n_mode) { |
| 1229 | sdm_cfg0 = (0x0 << 5); |
| 1230 | sdm_cfg0 |= (0x0 & 0x3f); |
| 1231 | sdm_cfg1 = (div_s64(div_fbx1000, 1000) & 0x3f) - 1; |
| 1232 | sdm_cfg3 = div_s64_rem(frac_n_value, 256, &rem); |
| 1233 | sdm_cfg2 = rem; |
| 1234 | } else { |
| 1235 | sdm_cfg0 = (0x1 << 5); |
| 1236 | sdm_cfg0 |= (div_s64(div_fbx1000, 1000) & 0x3f) - 1; |
| 1237 | sdm_cfg1 = (0x0 & 0x3f); |
| 1238 | sdm_cfg2 = 0; |
| 1239 | sdm_cfg3 = 0; |
| 1240 | } |
| 1241 | |
| 1242 | pr_debug("%s: sdm_cfg0=%lld\n", __func__, sdm_cfg0); |
| 1243 | pr_debug("%s: sdm_cfg1=%lld\n", __func__, sdm_cfg1); |
| 1244 | pr_debug("%s: sdm_cfg2=%lld\n", __func__, sdm_cfg2); |
| 1245 | pr_debug("%s: sdm_cfg3=%lld\n", __func__, sdm_cfg3); |
| 1246 | |
| 1247 | cal_cfg11 = div_s64_rem(gen_vco_clk, 256 * 1000000, &rem); |
| 1248 | cal_cfg10 = rem / 1000000; |
| 1249 | pr_debug("%s: cal_cfg10=%lld, cal_cfg11=%lld\n", __func__, |
| 1250 | cal_cfg10, cal_cfg11); |
| 1251 | |
| 1252 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CHGPUMP_CFG, 0x02); |
| 1253 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG3, 0x2b); |
| 1254 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG4, 0x66); |
| 1255 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2, 0x05); |
| 1256 | |
| 1257 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG1, |
| 1258 | (u32)(sdm_cfg1 & 0xff)); |
| 1259 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG2, |
| 1260 | (u32)(sdm_cfg2 & 0xff)); |
| 1261 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG3, |
| 1262 | (u32)(sdm_cfg3 & 0xff)); |
| 1263 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG4, 0x00); |
| 1264 | |
| 1265 | /* Add hardware recommended delay for correct PLL configuration */ |
| 1266 | udelay(1000); |
| 1267 | |
| 1268 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_REFCLK_CFG, |
| 1269 | (u32)refclk_cfg); |
| 1270 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_PWRGEN_CFG, 0x00); |
| 1271 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_VCOLPF_CFG, 0x71); |
| 1272 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG0, |
| 1273 | (u32)sdm_cfg0); |
| 1274 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG0, 0x0a); |
| 1275 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG6, 0x30); |
| 1276 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG7, 0x00); |
| 1277 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG8, 0x60); |
| 1278 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG9, 0x00); |
| 1279 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG10, |
| 1280 | (u32)(cal_cfg10 & 0xff)); |
| 1281 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG11, |
| 1282 | (u32)(cal_cfg11 & 0xff)); |
| 1283 | DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_EFUSE_CFG, 0x20); |
| 1284 | |
| 1285 | error: |
| 1286 | mdss_ahb_clk_enable(0); |
| 1287 | return rc; |
| 1288 | } |
| 1289 | |
| 1290 | /* rate is the bit clk rate */ |
| 1291 | static long vco_round_rate(struct clk *c, unsigned long rate) |
| 1292 | { |
| 1293 | unsigned long rrate = rate; |
| 1294 | struct dsi_pll_vco_clk *vco = to_vco_clk(c); |
| 1295 | |
| 1296 | if (rate < vco->min_rate) |
| 1297 | rrate = vco->min_rate; |
| 1298 | if (rate > vco->max_rate) |
| 1299 | rrate = vco->max_rate; |
| 1300 | |
| 1301 | return rrate; |
| 1302 | } |
| 1303 | |
| 1304 | static unsigned long vco_get_rate(struct clk *c) |
| 1305 | { |
| 1306 | u32 sdm0, doubler, sdm_byp_div; |
| 1307 | u64 vco_rate; |
| 1308 | u32 sdm_dc_off, sdm_freq_seed, sdm2, sdm3; |
| 1309 | struct dsi_pll_vco_clk *vco = to_vco_clk(c); |
| 1310 | u64 ref_clk = vco->ref_clk_rate; |
| 1311 | |
| 1312 | /* Check to see if the ref clk doubler is enabled */ |
| 1313 | doubler = DSS_REG_R(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_REFCLK_CFG) |
| 1314 | & BIT(0); |
| 1315 | ref_clk += (doubler * vco->ref_clk_rate); |
| 1316 | |
| 1317 | /* see if it is integer mode or sdm mode */ |
| 1318 | sdm0 = DSS_REG_R(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG0); |
| 1319 | if (sdm0 & BIT(6)) { |
| 1320 | /* integer mode */ |
| 1321 | sdm_byp_div = (DSS_REG_R(mdss_dsi_base, |
| 1322 | DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG0) & 0x3f) + 1; |
| 1323 | vco_rate = ref_clk * sdm_byp_div; |
| 1324 | } else { |
| 1325 | /* sdm mode */ |
| 1326 | sdm_dc_off = DSS_REG_R(mdss_dsi_base, |
| 1327 | DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG1) & 0xFF; |
| 1328 | pr_debug("%s: sdm_dc_off = %d\n", __func__, sdm_dc_off); |
| 1329 | sdm2 = DSS_REG_R(mdss_dsi_base, |
| 1330 | DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG2) & 0xFF; |
| 1331 | sdm3 = DSS_REG_R(mdss_dsi_base, |
| 1332 | DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG3) & 0xFF; |
| 1333 | sdm_freq_seed = (sdm3 << 8) | sdm2; |
| 1334 | pr_debug("%s: sdm_freq_seed = %d\n", __func__, sdm_freq_seed); |
| 1335 | |
| 1336 | vco_rate = (ref_clk * (sdm_dc_off + 1)) + |
| 1337 | mult_frac(ref_clk, sdm_freq_seed, BIT(16)); |
| 1338 | pr_debug("%s: vco rate = %lld", __func__, vco_rate); |
| 1339 | } |
| 1340 | |
| 1341 | pr_debug("%s: returning vco rate = %lu\n", __func__, |
| 1342 | (unsigned long)vco_rate); |
| 1343 | return (unsigned long)vco_rate; |
| 1344 | } |
| 1345 | |
| 1346 | static enum handoff vco_handoff(struct clk *c) |
| 1347 | { |
| 1348 | int rc = 0; |
| 1349 | enum handoff ret = HANDOFF_DISABLED_CLK; |
| 1350 | |
| 1351 | rc = mdss_ahb_clk_enable(1); |
| 1352 | if (rc) { |
| 1353 | pr_err("%s: failed to enable mdss ahb clock. rc=%d\n", |
| 1354 | __func__, rc); |
| 1355 | return ret; |
| 1356 | } |
| 1357 | if (dsi_pll_lock_status()) { |
| 1358 | c->rate = vco_get_rate(c); |
| 1359 | ret = HANDOFF_ENABLED_CLK; |
| 1360 | } |
| 1361 | |
| 1362 | mdss_ahb_clk_enable(0); |
| 1363 | return ret; |
| 1364 | } |
| 1365 | |
| 1366 | static int vco_prepare(struct clk *c) |
| 1367 | { |
| 1368 | return vco_set_rate(c, vco_cached_rate); |
| 1369 | } |
| 1370 | |
| 1371 | static void vco_unprepare(struct clk *c) |
| 1372 | { |
| 1373 | vco_cached_rate = c->rate; |
| 1374 | } |
| 1375 | |
| 1376 | /* Op structures */ |
| 1377 | |
| 1378 | static struct clk_ops clk_ops_dsi_vco = { |
| 1379 | .enable = vco_enable, |
| 1380 | .disable = vco_disable, |
| 1381 | .set_rate = vco_set_rate, |
| 1382 | .round_rate = vco_round_rate, |
| 1383 | .handoff = vco_handoff, |
| 1384 | .prepare = vco_prepare, |
| 1385 | .unprepare = vco_unprepare, |
| 1386 | }; |
| 1387 | |
| 1388 | static struct clk_div_ops fixed_2div_ops; |
| 1389 | |
| 1390 | static struct clk_div_ops fixed_4div_ops = { |
| 1391 | .set_div = fixed_4div_set_div, |
| 1392 | .get_div = fixed_4div_get_div, |
| 1393 | }; |
| 1394 | |
| 1395 | static struct clk_div_ops analog_postdiv_ops = { |
| 1396 | .set_div = analog_set_div, |
| 1397 | .get_div = analog_get_div, |
| 1398 | }; |
| 1399 | |
| 1400 | static struct clk_div_ops digital_postdiv_ops = { |
| 1401 | .set_div = digital_set_div, |
| 1402 | .get_div = digital_get_div, |
| 1403 | }; |
| 1404 | |
| 1405 | struct clk_mux_ops byte_mux_ops = { |
| 1406 | .set_mux_sel = set_byte_mux_sel, |
| 1407 | .get_mux_sel = get_byte_mux_sel, |
| 1408 | }; |
| 1409 | |
| 1410 | struct clk_ops byte_mux_clk_ops; |
| 1411 | |
| 1412 | static struct clk_ops pixel_clk_src_ops; |
| 1413 | static struct clk_ops byte_clk_src_ops; |
| 1414 | static struct clk_ops analog_potsdiv_clk_ops; |
| 1415 | |
| 1416 | /* Display clocks */ |
| 1417 | |
| 1418 | struct dsi_pll_vco_clk dsi_vco_clk_8226 = { |
| 1419 | .ref_clk_rate = 19200000, |
| 1420 | .min_rate = 350000000, |
| 1421 | .max_rate = 750000000, |
| 1422 | .pll_en_seq_cnt = 6, |
| 1423 | .pll_enable_seqs[0] = dsi_pll_enable_seq_m, |
| 1424 | .pll_enable_seqs[1] = dsi_pll_enable_seq_d, |
| 1425 | .pll_enable_seqs[2] = dsi_pll_enable_seq_d, |
| 1426 | .pll_enable_seqs[3] = dsi_pll_enable_seq_f1, |
| 1427 | .pll_enable_seqs[4] = dsi_pll_enable_seq_c, |
| 1428 | .pll_enable_seqs[5] = dsi_pll_enable_seq_e, |
| 1429 | .lpfr_lut_size = 10, |
| 1430 | .lpfr_lut = (struct lpfr_cfg[]){ |
| 1431 | {479500000, 8}, |
| 1432 | {480000000, 11}, |
| 1433 | {575500000, 8}, |
| 1434 | {576000000, 12}, |
| 1435 | {610500000, 8}, |
| 1436 | {659500000, 9}, |
| 1437 | {671500000, 10}, |
| 1438 | {672000000, 14}, |
| 1439 | {708500000, 10}, |
| 1440 | {750000000, 11}, |
| 1441 | }, |
| 1442 | .c = { |
| 1443 | .dbg_name = "dsi_vco_clk", |
| 1444 | .ops = &clk_ops_dsi_vco, |
| 1445 | CLK_INIT(dsi_vco_clk_8226.c), |
| 1446 | }, |
| 1447 | }; |
| 1448 | |
| 1449 | struct div_clk analog_postdiv_clk_8226 = { |
| 1450 | .max_div = 255, |
| 1451 | .min_div = 1, |
| 1452 | .ops = &analog_postdiv_ops, |
| 1453 | .c = { |
| 1454 | .parent = &dsi_vco_clk_8226.c, |
| 1455 | .dbg_name = "analog_postdiv_clk", |
| 1456 | .ops = &analog_potsdiv_clk_ops, |
| 1457 | .flags = CLKFLAG_NO_RATE_CACHE, |
| 1458 | CLK_INIT(analog_postdiv_clk_8226.c), |
| 1459 | }, |
| 1460 | }; |
| 1461 | |
| 1462 | struct div_clk indirect_path_div2_clk_8226 = { |
| 1463 | .ops = &fixed_2div_ops, |
| 1464 | .div = 2, |
| 1465 | .c = { |
| 1466 | .parent = &analog_postdiv_clk_8226.c, |
| 1467 | .dbg_name = "indirect_path_div2_clk", |
| 1468 | .ops = &clk_ops_div, |
| 1469 | .flags = CLKFLAG_NO_RATE_CACHE, |
| 1470 | CLK_INIT(indirect_path_div2_clk_8226.c), |
| 1471 | }, |
| 1472 | }; |
| 1473 | |
| 1474 | struct div_clk pixel_clk_src_8226 = { |
| 1475 | .max_div = 255, |
| 1476 | .min_div = 1, |
| 1477 | .ops = &digital_postdiv_ops, |
| 1478 | .c = { |
| 1479 | .parent = &dsi_vco_clk_8226.c, |
| 1480 | .dbg_name = "pixel_clk_src", |
| 1481 | .ops = &pixel_clk_src_ops, |
| 1482 | .flags = CLKFLAG_NO_RATE_CACHE, |
| 1483 | CLK_INIT(pixel_clk_src_8226.c), |
| 1484 | }, |
| 1485 | }; |
| 1486 | |
| 1487 | struct mux_clk byte_mux_8226 = { |
| 1488 | .num_parents = 2, |
| 1489 | .parents = (struct clk_src[]){ |
| 1490 | {&dsi_vco_clk_8226.c, 0}, |
| 1491 | {&indirect_path_div2_clk_8226.c, 1}, |
| 1492 | }, |
| 1493 | .ops = &byte_mux_ops, |
| 1494 | .c = { |
| 1495 | .parent = &dsi_vco_clk_8226.c, |
| 1496 | .dbg_name = "byte_mux", |
| 1497 | .ops = &byte_mux_clk_ops, |
| 1498 | CLK_INIT(byte_mux_8226.c), |
| 1499 | }, |
| 1500 | }; |
| 1501 | |
| 1502 | struct div_clk byte_clk_src_8226 = { |
| 1503 | .ops = &fixed_4div_ops, |
| 1504 | .min_div = 4, |
| 1505 | .max_div = 4, |
| 1506 | .c = { |
| 1507 | .parent = &byte_mux_8226.c, |
| 1508 | .dbg_name = "byte_clk_src", |
| 1509 | .ops = &byte_clk_src_ops, |
| 1510 | CLK_INIT(byte_clk_src_8226.c), |
| 1511 | }, |
| 1512 | }; |
| 1513 | |
| 1514 | struct dsi_pll_vco_clk dsi_vco_clk_8974 = { |
| 1515 | .ref_clk_rate = 19200000, |
| 1516 | .min_rate = 350000000, |
| 1517 | .max_rate = 750000000, |
| 1518 | .pll_en_seq_cnt = 3, |
| 1519 | .pll_enable_seqs[0] = dsi_pll_enable_seq_8974, |
| 1520 | .pll_enable_seqs[1] = dsi_pll_enable_seq_8974, |
| 1521 | .pll_enable_seqs[2] = dsi_pll_enable_seq_8974, |
| 1522 | .lpfr_lut_size = 10, |
| 1523 | .lpfr_lut = (struct lpfr_cfg[]){ |
| 1524 | {479500000, 8}, |
| 1525 | {480000000, 11}, |
| 1526 | {575500000, 8}, |
| 1527 | {576000000, 12}, |
| 1528 | {610500000, 8}, |
| 1529 | {659500000, 9}, |
| 1530 | {671500000, 10}, |
| 1531 | {672000000, 14}, |
| 1532 | {708500000, 10}, |
| 1533 | {750000000, 11}, |
| 1534 | }, |
| 1535 | .c = { |
| 1536 | .dbg_name = "dsi_vco_clk", |
| 1537 | .ops = &clk_ops_dsi_vco, |
| 1538 | CLK_INIT(dsi_vco_clk_8974.c), |
| 1539 | }, |
| 1540 | }; |
| 1541 | |
| 1542 | struct div_clk analog_postdiv_clk_8974 = { |
| 1543 | .max_div = 255, |
| 1544 | .min_div = 1, |
| 1545 | .ops = &analog_postdiv_ops, |
| 1546 | .c = { |
| 1547 | .parent = &dsi_vco_clk_8974.c, |
| 1548 | .dbg_name = "analog_postdiv_clk", |
| 1549 | .ops = &analog_potsdiv_clk_ops, |
| 1550 | .flags = CLKFLAG_NO_RATE_CACHE, |
| 1551 | CLK_INIT(analog_postdiv_clk_8974.c), |
| 1552 | }, |
| 1553 | }; |
| 1554 | |
| 1555 | struct div_clk indirect_path_div2_clk_8974 = { |
| 1556 | .ops = &fixed_2div_ops, |
| 1557 | .div = 2, |
| 1558 | .c = { |
| 1559 | .parent = &analog_postdiv_clk_8974.c, |
| 1560 | .dbg_name = "indirect_path_div2_clk", |
| 1561 | .ops = &clk_ops_div, |
| 1562 | .flags = CLKFLAG_NO_RATE_CACHE, |
| 1563 | CLK_INIT(indirect_path_div2_clk_8974.c), |
| 1564 | }, |
| 1565 | }; |
| 1566 | |
| 1567 | struct div_clk pixel_clk_src_8974 = { |
| 1568 | .max_div = 255, |
| 1569 | .min_div = 1, |
| 1570 | .ops = &digital_postdiv_ops, |
| 1571 | .c = { |
| 1572 | .parent = &dsi_vco_clk_8974.c, |
| 1573 | .dbg_name = "pixel_clk_src", |
| 1574 | .ops = &pixel_clk_src_ops, |
| 1575 | .flags = CLKFLAG_NO_RATE_CACHE, |
| 1576 | CLK_INIT(pixel_clk_src_8974.c), |
| 1577 | }, |
| 1578 | }; |
| 1579 | |
| 1580 | struct mux_clk byte_mux_8974 = { |
| 1581 | .num_parents = 2, |
| 1582 | .parents = (struct clk_src[]){ |
| 1583 | {&dsi_vco_clk_8974.c, 0}, |
| 1584 | {&indirect_path_div2_clk_8974.c, 1}, |
| 1585 | }, |
| 1586 | .ops = &byte_mux_ops, |
| 1587 | .c = { |
| 1588 | .parent = &dsi_vco_clk_8974.c, |
| 1589 | .dbg_name = "byte_mux", |
| 1590 | .ops = &byte_mux_clk_ops, |
| 1591 | CLK_INIT(byte_mux_8974.c), |
| 1592 | }, |
| 1593 | }; |
| 1594 | |
| 1595 | struct div_clk byte_clk_src_8974 = { |
| 1596 | .ops = &fixed_4div_ops, |
| 1597 | .min_div = 4, |
| 1598 | .max_div = 4, |
| 1599 | .c = { |
| 1600 | .parent = &byte_mux_8974.c, |
| 1601 | .dbg_name = "byte_clk_src", |
| 1602 | .ops = &byte_clk_src_ops, |
| 1603 | CLK_INIT(byte_clk_src_8974.c), |
| 1604 | }, |
| 1605 | }; |
| 1606 | |
| 1607 | void __init mdss_clk_ctrl_pre_init(struct clk *ahb_clk) |
| 1608 | { |
| 1609 | BUG_ON(ahb_clk == NULL); |
| 1610 | |
| 1611 | gdsc_base = ioremap(GDSC_PHYS, GDSC_SIZE); |
| 1612 | if (!gdsc_base) |
| 1613 | pr_err("%s: unable to remap gdsc base", __func__); |
| 1614 | |
| 1615 | mdss_dsi_base = ioremap(DSI_PHY_PHYS, DSI_PHY_SIZE); |
| 1616 | if (!mdss_dsi_base) |
| 1617 | pr_err("%s: unable to remap dsi base", __func__); |
| 1618 | |
| 1619 | mdss_ahb_clk = ahb_clk; |
| 1620 | |
| 1621 | hdmi_phy_base = ioremap(HDMI_PHY_PHYS, HDMI_PHY_SIZE); |
| 1622 | if (!hdmi_phy_base) |
| 1623 | pr_err("%s: unable to ioremap hdmi phy base", __func__); |
| 1624 | |
| 1625 | hdmi_phy_pll_base = ioremap(HDMI_PHY_PLL_PHYS, HDMI_PHY_PLL_SIZE); |
| 1626 | if (!hdmi_phy_pll_base) |
| 1627 | pr_err("%s: unable to ioremap hdmi phy pll base", __func__); |
| 1628 | |
| 1629 | pixel_clk_src_ops = clk_ops_slave_div; |
| 1630 | pixel_clk_src_ops.prepare = div_prepare; |
| 1631 | |
| 1632 | byte_clk_src_ops = clk_ops_div; |
| 1633 | byte_clk_src_ops.prepare = div_prepare; |
| 1634 | |
| 1635 | analog_potsdiv_clk_ops = clk_ops_div; |
| 1636 | analog_potsdiv_clk_ops.prepare = div_prepare; |
| 1637 | |
| 1638 | byte_mux_clk_ops = clk_ops_gen_mux; |
| 1639 | byte_mux_clk_ops.prepare = mux_prepare; |
| 1640 | } |
| 1641 | |