blob: fb4da7408057559f2eb98de0f6797c3b5fdfee90 [file] [log] [blame]
Ajay Singh Parmar2dad3572013-02-13 20:37:41 +05301/* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
Channagoud Kadabie4884122011-09-21 23:54:44 +05302 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
Duy Truongf3ac7b32013-02-13 01:07:28 -080012 * * Neither the name of The Linux Foundation nor the names of its
Channagoud Kadabie4884122011-09-21 23:54:44 +053013 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#include <hdmi.h>
31#include <platform/timer.h>
32#include <platform/gpio.h>
33#include <platform/clock.h>
34#include <platform/iomap.h>
35#include <platform/scm-io.h>
36
37extern void hdmi_app_clk_init(int);
Ajay Singh Parmar2dad3572013-02-13 20:37:41 +053038extern int hdmi_msm_turn_on();
39
40#define FB_ADDR 0x43E00000
41
42static struct fbcon_config fb_cfg = {
43 .height = DTV_FB_HEIGHT,
44 .width = DTV_FB_WIDTH,
45 .stride = DTV_FB_WIDTH,
46 .format = DTV_FORMAT_RGB565,
47 .bpp = DTV_BPP,
48 .update_start = NULL,
49 .update_done = NULL,
50 .base = FB_ADDR;
51};
52
53struct fbcon_config *get_fbcon(void)
54{
55 return &fb_cfg;
56}
Channagoud Kadabie4884122011-09-21 23:54:44 +053057
58void hdmi_msm_init_phy()
59{
Ajay Dudanib01e5062011-12-03 23:23:42 -080060 dprintf(SPEW, "PHY INIT\n");
Channagoud Kadabie4884122011-09-21 23:54:44 +053061 uint32_t offset = 0;
62 uint32_t len = 0;
63
Ajay Dudanib01e5062011-12-03 23:23:42 -080064 writel(0x0C, HDMI_PHY_REG_0);
65 writel(0x54, HDMI_PHY_REG_1);
66 writel(0x7F, HDMI_PHY_REG_2);
67 writel(0x3F, HDMI_PHY_REG_2);
68 writel(0x1F, HDMI_PHY_REG_2);
Channagoud Kadabie4884122011-09-21 23:54:44 +053069
Ajay Dudanib01e5062011-12-03 23:23:42 -080070 writel(0x01, HDMI_PHY_REG_3);
71 writel(0x00, HDMI_PHY_REG_9);
72 writel(0x03, HDMI_PHY_REG_12);
73 writel(0x01, HDMI_PHY_REG_2);
74 writel(0x81, HDMI_PHY_REG_2);
Channagoud Kadabie4884122011-09-21 23:54:44 +053075
76 offset = (HDMI_PHY_REG_4 - MSM_HDMI_BASE);
77 len = (HDMI_PHY_REG_11 - MSM_HDMI_BASE);
78 while (offset <= len) {
79 writel(0x0, MSM_HDMI_BASE + offset);
80 offset += 4;
81 }
Ajay Dudanib01e5062011-12-03 23:23:42 -080082 writel(0x13, HDMI_PHY_REG_12);
Channagoud Kadabie4884122011-09-21 23:54:44 +053083}
84
Channagoud Kadabie4884122011-09-21 23:54:44 +053085static void hdmi_gpio_config()
86{
87 uint32_t func;
88 uint32_t pull;
89 uint32_t drv;
90 uint32_t enable = 0;
91 uint32_t dir;
92
93 func = 1;
94 pull = GPIO_NO_PULL;
95 drv = GPIO_16MA;
96 dir = 1;
97 gpio_tlmm_config(170, func, dir, pull, drv, enable);
98
99 gpio_tlmm_config(171, func, dir, pull, drv, enable);
100
101 func = 1;
102 pull = GPIO_PULL_DOWN;
103 drv = GPIO_16MA;
104 gpio_tlmm_config(172, func, dir, pull, drv, enable);
105}
106
107/*
108 * This is the start function which initializes clocks , gpios for hdmi
109 * & powers on the HDMI core
110 */
Ajay Singh Parmar2dad3572013-02-13 20:37:41 +0530111void hdmi_power_init()
Channagoud Kadabie4884122011-09-21 23:54:44 +0530112{
113 // Enable HDMI clocks
114 hdmi_app_clk_init(1);
115 // Enable pm8058
116 pm8058_ldo_set_voltage();
117 pm8058_vreg_enable();
118 // configure HDMI Gpio
119 hdmi_gpio_config();
120 // Enable pm8091
121 pm8901_mpp_enable();
122 pm8901_vs_enable();
123 // Power on HDMI
124 hdmi_msm_turn_on();
125}
126
Ajay Singh Parmar2dad3572013-02-13 20:37:41 +0530127static void hdmi_msm_reset_core()
128{
129 uint32_t reg_val = 0;
130 hdmi_msm_set_mode(0);
131 // Disable clocks
132 hdmi_app_clk_init(0);
133 udelay(5);
134 // Enable clocks
135 hdmi_app_clk_init(1);
136
137 reg_val = secure_readl(SW_RESET_CORE_REG);
138 reg_val |= BIT(11);
139 secure_writel(reg_val, SW_RESET_CORE_REG);
140 udelay(5);
141 reg_val = secure_readl(SW_RESET_AHB_REG);
142 reg_val |= BIT(9);
143 secure_writel(reg_val, SW_RESET_AHB_REG);
144 udelay(5);
145 reg_val = secure_readl(SW_RESET_AHB_REG);
146 reg_val |= BIT(9);
147 secure_writel(reg_val, SW_RESET_AHB_REG);
148 udelay(20);
149 reg_val = secure_readl(SW_RESET_CORE_REG);
150 reg_val &= ~(BIT(11));
151 secure_writel(reg_val, SW_RESET_CORE_REG);
152 udelay(5);
153 reg_val = secure_readl(SW_RESET_AHB_REG);
154 reg_val &= ~(BIT(9));
155 secure_writel(reg_val, SW_RESET_AHB_REG);
156 udelay(5);
157 reg_val = secure_readl(SW_RESET_AHB_REG);
158 reg_val &= ~(BIT(9));
159 secure_writel(reg_val, SW_RESET_AHB_REG);
160 udelay(5);
161}
162
163int hdmi_dtv_on()
Channagoud Kadabie4884122011-09-21 23:54:44 +0530164{
165 uint32_t val, pll_mode, ns_val, pll_config;
166
167 // Configure PLL2 for tv src clk
168 pll_mode |= BIT(1);
169 secure_writel(pll_mode, MM_PLL2_MODE_REG);
170 udelay(10);
171
172 pll_mode = secure_readl(MM_PLL2_MODE_REG);
173 pll_mode &= ~BIT(0);
174 secure_writel(pll_mode, MM_PLL2_MODE_REG);
175 pll_mode &= ~BIT(2);
176 secure_writel(pll_mode, MM_PLL2_MODE_REG);
177
178 secure_writel(0x2C, MM_PLL2_L_VAL_REG);
179 secure_writel(0x0, MM_PLL2_M_VAL_REG);
180 secure_writel(0x0, MM_PLL2_N_VAL_REG);
181 udelay(10);
182
183 val = 0xA6248F;
184 secure_writel(val, MM_PLL2_CONFIG_REG);
185
186 // set M N D
187 ns_val = secure_readl(TV_NS_REG);
188 ns_val |= BIT(7);
189 secure_writel(ns_val, TV_NS_REG);
190
191 secure_writel(0xff, TV_MD_REG);
192
193 val = secure_readl(TV_CC_REG);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800194 val &= ~(BM(7, 6));
Channagoud Kadabie4884122011-09-21 23:54:44 +0530195 val |= CC(6, 0);
196 secure_writel(val, TV_CC_REG);
197
198 ns_val &= ~BIT(7);
199 secure_writel(ns_val, TV_NS_REG);
200
201 // confiure hdmi_ref clk to run @ 148.5 MHz
202 val = secure_readl(MISC_CC2_REG);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800203 val &= ~(BIT(28) | BM(21, 18));
Channagoud Kadabie4884122011-09-21 23:54:44 +0530204 ns_val = NS_MM(23, 16, 0, 0, 15, 14, 2, 2, 0, 3);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800205 val |= (BIT(28) | BVAL(21, 18, (ns_val >> 14) & 0x3));
Channagoud Kadabie4884122011-09-21 23:54:44 +0530206 secure_writel(val, MISC_CC2_REG);
207
208 pll_mode |= BIT(2);
209 secure_writel(pll_mode, MM_PLL2_MODE_REG);
210
211 pll_mode |= BIT(0);
212 secure_writel(pll_mode, MM_PLL2_MODE_REG);
213 udelay(50);
214
215 // Enable TV src clk
216 val = secure_readl(TV_NS_REG);
217 val &= ~(BM(23, 16) | BM(15, 14) | BM(2, 0));
218 ns_val = NS_MM(23, 16, 0, 0, 15, 14, 2, 2, 0, 3);
219 val |= (ns_val & (BM(23, 16) | BM(15, 14) | BM(2, 0)));
220 secure_writel(val, TV_NS_REG);
221
222 // Enable hdmi clk
223 val = secure_readl(TV_CC_REG);
224 val |= BIT(12);
225 secure_writel(val, TV_CC_REG);
226
227 // Root en of tv src clk
228 val = secure_readl(TV_CC_REG);
229 val |= BIT(2);
230 secure_writel(val, TV_CC_REG);
231
232 // De-Assert hdmi clk
233 val = secure_readl(SW_RESET_CORE_REG);
234 val |= BIT(1);
235 secure_writel(val, SW_RESET_CORE_REG);
236 udelay(10);
237 val = secure_readl(SW_RESET_CORE_REG);
238 val &= ~(BIT(1));
239 secure_writel(val, SW_RESET_CORE_REG);
240 udelay(10);
241
242 // enable mdp dtv clk
243 val = secure_readl(TV_CC_REG);
244 val |= BIT(0);
245 secure_writel(val, TV_CC_REG);
246 udelay(10);
Ajay Singh Parmar2dad3572013-02-13 20:37:41 +0530247
248 return 0;
Channagoud Kadabie4884122011-09-21 23:54:44 +0530249}