blob: 772f8d18d009ea5afd18414880357bc1be0cb0a5 [file] [log] [blame]
Kuogee Hsiehdf961742013-12-18 14:13:45 -08001/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Ray Zhang743e5032013-05-25 23:25:39 +08002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions
5 * 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
10 * the documentation and/or other materials provided with the
11 * distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED 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
30#include <debug.h>
31#include <smem.h>
Arpita Banerjeec5f78df2013-05-24 15:43:40 -070032#include <err.h>
Ray Zhang743e5032013-05-25 23:25:39 +080033#include <msm_panel.h>
Arpita Banerjee0906ffd2013-05-24 16:25:38 -070034#include <mipi_dsi.h>
Ray Zhang743e5032013-05-25 23:25:39 +080035#include <pm8x41.h>
36#include <pm8x41_wled.h>
37#include <board.h>
38#include <mdp5.h>
Aravind Venkateswaranfada7f32013-09-19 15:23:34 -070039#include <scm.h>
Ray Zhang743e5032013-05-25 23:25:39 +080040#include <platform/gpio.h>
41#include <platform/iomap.h>
42#include <target/display.h>
43
Casey Pipercbdfbd22013-08-14 17:22:16 -070044#include "include/panel.h"
Arpita Banerjeec5f78df2013-05-24 15:43:40 -070045#include "include/display_resource.h"
Ray Zhang743e5032013-05-25 23:25:39 +080046
Dhaval Patel815567c2013-07-31 11:13:25 -070047#define HFPLL_LDO_ID 8
48
Ray Zhang743e5032013-05-25 23:25:39 +080049static struct pm8x41_wled_data wled_ctrl = {
rayzhanga3667cd2013-07-01 12:22:54 +080050 .mod_scheme = 0x00,
Ray Zhang743e5032013-05-25 23:25:39 +080051 .led1_brightness = (0x0F << 8) | 0xEF,
Ray Zhang743e5032013-05-25 23:25:39 +080052 .max_duty_cycle = 0x01,
rayzhanga3667cd2013-07-01 12:22:54 +080053 .ovp = 0x0,
Zhenhua Huangd5355cb2013-09-04 16:03:01 +080054 .full_current_scale = 0x19,
55 .fdbck = 0x1
Ray Zhang743e5032013-05-25 23:25:39 +080056};
57
Casey Piperaee81202013-08-26 11:14:02 -070058static uint32_t dsi_pll_enable_seq_m(uint32_t ctl_base)
59{
60 uint32_t i = 0;
61 uint32_t pll_locked = 0;
62
63 mdss_dsi_uniphy_pll_sw_reset(ctl_base);
64
65 /*
66 * Add hardware recommended delays between register writes for
67 * the updates to take effect. These delays are necessary for the
68 * PLL to successfully lock
69 */
70 writel(0x01, ctl_base + 0x0220); /* GLB CFG */
71 udelay(200);
72 writel(0x05, ctl_base + 0x0220); /* GLB CFG */
73 udelay(200);
74 writel(0x0f, ctl_base + 0x0220); /* GLB CFG */
75 udelay(1000);
76
77 mdss_dsi_uniphy_pll_lock_detect_setting(ctl_base);
78 pll_locked = readl(ctl_base + 0x02c0) & 0x01;
79 for (i = 0; (i < 4) && !pll_locked; i++) {
80 writel(0x07, ctl_base + 0x0220); /* GLB CFG */
81 if (i != 0)
82 writel(0x34, ctl_base + 0x00270); /* CAL CFG1*/
83 udelay(1);
84 writel(0x0f, ctl_base + 0x0220); /* GLB CFG */
85 udelay(1000);
86 mdss_dsi_uniphy_pll_lock_detect_setting(ctl_base);
87 pll_locked = readl(ctl_base + 0x02c0) & 0x01;
88 }
89
90 return pll_locked;
91}
92
93static uint32_t dsi_pll_enable_seq_d(uint32_t ctl_base)
94{
95 uint32_t pll_locked = 0;
96
97 mdss_dsi_uniphy_pll_sw_reset(ctl_base);
98
99 /*
100 * Add hardware recommended delays between register writes for
101 * the updates to take effect. These delays are necessary for the
102 * PLL to successfully lock
103 */
104 writel(0x01, ctl_base + 0x0220); /* GLB CFG */
105 udelay(200);
106 writel(0x05, ctl_base + 0x0220); /* GLB CFG */
107 udelay(200);
108 writel(0x07, ctl_base + 0x0220); /* GLB CFG */
109 udelay(200);
110 writel(0x05, ctl_base + 0x0220); /* GLB CFG */
111 udelay(200);
112 writel(0x07, ctl_base + 0x0220); /* GLB CFG */
113 udelay(200);
114 writel(0x0f, ctl_base + 0x0220); /* GLB CFG */
115 udelay(1000);
116
117 mdss_dsi_uniphy_pll_lock_detect_setting(ctl_base);
118 pll_locked = readl(ctl_base + 0x02c0) & 0x01;
119
120 return pll_locked;
121}
122
123static uint32_t dsi_pll_enable_seq_f1(uint32_t ctl_base)
124{
125 uint32_t pll_locked = 0;
126
127 mdss_dsi_uniphy_pll_sw_reset(ctl_base);
128
129 /*
130 * Add hardware recommended delays between register writes for
131 * the updates to take effect. These delays are necessary for the
132 * PLL to successfully lock
133 */
134 writel(0x01, ctl_base + 0x0220); /* GLB CFG */
135 udelay(200);
136 writel(0x05, ctl_base + 0x0220); /* GLB CFG */
137 udelay(200);
138 writel(0x0f, ctl_base + 0x0220); /* GLB CFG */
139 udelay(200);
140 writel(0x0d, ctl_base + 0x0220); /* GLB CFG */
141 udelay(200);
142 writel(0x0f, ctl_base + 0x0220); /* GLB CFG */
143 udelay(1000);
144
145 mdss_dsi_uniphy_pll_lock_detect_setting(ctl_base);
146 pll_locked = readl(ctl_base + 0x02c0) & 0x01;
147
148 return pll_locked;
149}
150
151static uint32_t dsi_pll_enable_seq_c(uint32_t ctl_base)
152{
153 uint32_t pll_locked = 0;
154
155 mdss_dsi_uniphy_pll_sw_reset(ctl_base);
156
157 /*
158 * Add hardware recommended delays between register writes for
159 * the updates to take effect. These delays are necessary for the
160 * PLL to successfully lock
161 */
162 writel(0x01, ctl_base + 0x0220); /* GLB CFG */
163 udelay(200);
164 writel(0x05, ctl_base + 0x0220); /* GLB CFG */
165 udelay(200);
166 writel(0x0f, ctl_base + 0x0220); /* GLB CFG */
167 udelay(1000);
168
169 mdss_dsi_uniphy_pll_lock_detect_setting(ctl_base);
170 pll_locked = readl(ctl_base + 0x02c0) & 0x01;
171
172 return pll_locked;
173}
174
175static uint32_t dsi_pll_enable_seq_e(uint32_t ctl_base)
176{
177 uint32_t pll_locked = 0;
178
179 mdss_dsi_uniphy_pll_sw_reset(ctl_base);
180
181 /*
182 * Add hardware recommended delays between register writes for
183 * the updates to take effect. These delays are necessary for the
184 * PLL to successfully lock
185 */
186 writel(0x01, ctl_base + 0x0220); /* GLB CFG */
187 udelay(200);
188 writel(0x05, ctl_base + 0x0220); /* GLB CFG */
189 udelay(200);
190 writel(0x0d, ctl_base + 0x0220); /* GLB CFG */
191 udelay(1);
192 writel(0x0f, ctl_base + 0x0220); /* GLB CFG */
193 udelay(1000);
194
195 mdss_dsi_uniphy_pll_lock_detect_setting(ctl_base);
196 pll_locked = readl(ctl_base + 0x02c0) & 0x01;
197
198 return pll_locked;
199}
200
Kuogee Hsiehdf961742013-12-18 14:13:45 -0800201int target_backlight_ctrl(struct backlight *bl, uint8_t enable)
Ray Zhang743e5032013-05-25 23:25:39 +0800202{
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700203 dprintf(SPEW, "target_backlight_ctrl\n");
204
Kuogee Hsiehdf961742013-12-18 14:13:45 -0800205 if (!bl) {
206 dprintf(CRITICAL, "backlight structure is not available\n");
207 return ERR_INVALID_ARGS;
208 }
209
210 if (bl->bl_interface_type != BL_WLED) {
211 dprintf(CRITICAL, "backlight type:%d not supported\n",
212 bl->bl_interface_type);
213 return ERR_NOT_SUPPORTED;
214 }
215
Jayant Shekhar09c46c22013-11-26 23:07:47 +0530216 if (enable) {
217 pm8x41_wled_config(&wled_ctrl);
218 pm8x41_wled_sink_control(enable);
219 pm8x41_wled_iled_sync_control(enable);
220 pm8x41_wled_led_mod_enable(enable);
221 }
222
223 pm8x41_wled_enable(enable);
Ray Zhang743e5032013-05-25 23:25:39 +0800224
225 return 0;
226}
227
Casey Piperaee81202013-08-26 11:14:02 -0700228static void dsi_pll_enable_seq(uint32_t ctl_base)
229{
230 if (dsi_pll_enable_seq_m(ctl_base)) {
231 } else if (dsi_pll_enable_seq_d(ctl_base)) {
232 } else if (dsi_pll_enable_seq_d(ctl_base)) {
233 } else if (dsi_pll_enable_seq_f1(ctl_base)) {
234 } else if (dsi_pll_enable_seq_c(ctl_base)) {
235 } else if (dsi_pll_enable_seq_e(ctl_base)) {
236 } else {
237 dprintf(CRITICAL, "Not able to enable the pll\n");
238 }
239}
240
Arpita Banerjee0906ffd2013-05-24 16:25:38 -0700241int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo)
Ray Zhang743e5032013-05-25 23:25:39 +0800242{
Aravind Venkateswaranfada7f32013-09-19 15:23:34 -0700243 int32_t ret;
Arpita Banerjee0906ffd2013-05-24 16:25:38 -0700244 struct mdss_dsi_pll_config *pll_data;
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700245 dprintf(SPEW, "target_panel_clock\n");
Ray Zhang743e5032013-05-25 23:25:39 +0800246
Arpita Banerjee0906ffd2013-05-24 16:25:38 -0700247 pll_data = pinfo->mipi.dsi_pll_config;
248
Ray Zhang743e5032013-05-25 23:25:39 +0800249 if (enable) {
250 mdp_gdsc_ctrl(enable);
Aravind Venkateswaran5f546922013-09-19 15:13:43 -0700251 mmss_bus_clocks_enable();
252 mdp_clock_enable();
Aravind Venkateswaranfada7f32013-09-19 15:23:34 -0700253 ret = restore_secure_cfg(SECURE_DEVICE_MDSS);
254 if (ret) {
255 dprintf(CRITICAL,
256 "%s: Failed to restore MDP security configs",
257 __func__);
258 mdp_clock_disable();
259 mmss_bus_clocks_disable();
260 mdp_gdsc_ctrl(0);
261 return ret;
262 }
Casey Piperaee81202013-08-26 11:14:02 -0700263 mdss_dsi_auto_pll_config(MIPI_DSI0_BASE, pll_data);
264 dsi_pll_enable_seq(MIPI_DSI0_BASE);
Aravind Venkateswaran5f546922013-09-19 15:13:43 -0700265 mmss_dsi_clocks_enable(pll_data->pclk_m,
Arpita Banerjee0906ffd2013-05-24 16:25:38 -0700266 pll_data->pclk_n,
267 pll_data->pclk_d);
Ray Zhang743e5032013-05-25 23:25:39 +0800268 } else if(!target_cont_splash_screen()) {
Aravind Venkateswaran5f546922013-09-19 15:13:43 -0700269 mmss_dsi_clocks_disable();
270 mdp_clock_disable();
271 mmss_bus_clocks_disable();
272 mdp_gdsc_ctrl(enable);
Ray Zhang743e5032013-05-25 23:25:39 +0800273 }
274
275 return 0;
276}
277
Dhaval Patel7a349562013-08-08 20:43:52 -0700278int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
279 struct msm_panel_info *pinfo)
Ray Zhang743e5032013-05-25 23:25:39 +0800280{
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700281 int ret = NO_ERROR;
Ray Zhang743e5032013-05-25 23:25:39 +0800282 if (enable) {
Aravind Venkateswaranaf241212013-11-04 16:46:46 -0800283 if (pinfo->mipi.use_enable_gpio) {
284 gpio_tlmm_config(enable_gpio.pin_id, 0,
285 enable_gpio.pin_direction, enable_gpio.pin_pull,
286 enable_gpio.pin_strength,
287 enable_gpio.pin_state);
288
289 gpio_set_dir(enable_gpio.pin_id, 2);
290 }
291
Dhaval Patel7a349562013-08-08 20:43:52 -0700292 gpio_tlmm_config(reset_gpio.pin_id, 0,
293 reset_gpio.pin_direction, reset_gpio.pin_pull,
294 reset_gpio.pin_strength, reset_gpio.pin_state);
Ray Zhang743e5032013-05-25 23:25:39 +0800295
Dhaval Patel7a349562013-08-08 20:43:52 -0700296 gpio_set_dir(reset_gpio.pin_id, 2);
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700297
Dhaval Patel7a349562013-08-08 20:43:52 -0700298 gpio_set_value(reset_gpio.pin_id, resetseq->pin_state[0]);
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700299 mdelay(resetseq->sleep[0]);
Dhaval Patel7a349562013-08-08 20:43:52 -0700300 gpio_set_value(reset_gpio.pin_id, resetseq->pin_state[1]);
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700301 mdelay(resetseq->sleep[1]);
Dhaval Patel7a349562013-08-08 20:43:52 -0700302 gpio_set_value(reset_gpio.pin_id, resetseq->pin_state[2]);
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700303 mdelay(resetseq->sleep[2]);
Ray Zhang743e5032013-05-25 23:25:39 +0800304 } else if(!target_cont_splash_screen()) {
Dhaval Patel7a349562013-08-08 20:43:52 -0700305 gpio_set_value(reset_gpio.pin_id, 0);
Aravind Venkateswaranaf241212013-11-04 16:46:46 -0800306 if (pinfo->mipi.use_enable_gpio)
307 gpio_set_value(enable_gpio.pin_id, 0);
Ray Zhang743e5032013-05-25 23:25:39 +0800308 }
309
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700310 return ret;
Ray Zhang743e5032013-05-25 23:25:39 +0800311}
312
Dhaval Patel7a349562013-08-08 20:43:52 -0700313int target_ldo_ctrl(uint8_t enable)
Ray Zhang743e5032013-05-25 23:25:39 +0800314{
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700315 uint32_t ret = NO_ERROR;
316 uint32_t ldocounter = 0;
317 uint32_t pm8x41_ldo_base = 0x13F00;
Ray Zhang743e5032013-05-25 23:25:39 +0800318
Dhaval Patel7a349562013-08-08 20:43:52 -0700319 while (ldocounter < TOTAL_LDO_DEFINED) {
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700320 struct pm8x41_ldo ldo_entry = LDO((pm8x41_ldo_base +
321 0x100 * ldo_entry_array[ldocounter].ldo_id),
322 ldo_entry_array[ldocounter].ldo_type);
Ray Zhang743e5032013-05-25 23:25:39 +0800323
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700324 dprintf(SPEW, "Setting %s\n",
325 ldo_entry_array[ldocounter].ldo_id);
Ray Zhang743e5032013-05-25 23:25:39 +0800326
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700327 /* Set voltage during power on */
Dhaval Patel815567c2013-07-31 11:13:25 -0700328 if (enable) {
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700329 pm8x41_ldo_set_voltage(&ldo_entry,
330 ldo_entry_array[ldocounter].ldo_voltage);
Dhaval Patel815567c2013-07-31 11:13:25 -0700331
332 pm8x41_ldo_control(&ldo_entry, enable);
333
334 } else if(!target_cont_splash_screen() &&
335 ldo_entry_array[ldocounter].ldo_id != HFPLL_LDO_ID) {
336 pm8x41_ldo_control(&ldo_entry, enable);
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700337 }
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700338 ldocounter++;
Ray Zhang743e5032013-05-25 23:25:39 +0800339 }
340
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700341 return ret;
Ray Zhang743e5032013-05-25 23:25:39 +0800342}
343
Aravind Venkateswarandd50c1a2014-02-25 14:42:43 -0800344void target_display_init(void)
Ray Zhang743e5032013-05-25 23:25:39 +0800345{
Pradeep Jilagamfeb15982013-10-29 13:08:51 +0530346 uint32_t panel_loop = 0;
347 uint32_t ret = 0;
348
349 do {
350 ret = gcdb_display_init(MDP_REV_50, MIPI_FB_ADDR);
351 if (!ret || ret == ERR_NOT_SUPPORTED) {
352 break;
353 } else {
354 target_force_cont_splash_disable(true);
355 msm_display_off();
356 target_force_cont_splash_disable(false);
357 }
358 } while (++panel_loop <= oem_panel_max_auto_detect_panels());
359
Ray Zhang743e5032013-05-25 23:25:39 +0800360}
361
Aravind Venkateswarandd50c1a2014-02-25 14:42:43 -0800362void target_display_shutdown(void)
Ray Zhang743e5032013-05-25 23:25:39 +0800363{
Arpita Banerjeec5f78df2013-05-24 15:43:40 -0700364 gcdb_display_shutdown();
Ray Zhang743e5032013-05-25 23:25:39 +0800365}