blob: 9a86cd94698440ed02398b7fa428ce1f214e646d [file] [log] [blame]
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -07001/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2 *
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 <string.h>
32#include <smem.h>
33#include <err.h>
34#include <msm_panel.h>
35#include <mipi_dsi.h>
36#include <pm8x41.h>
37#include <pm8x41_wled.h>
38#include <qpnp_wled.h>
39#include <board.h>
40#include <mdp5.h>
41#include <scm.h>
42#include <regulator.h>
43#include <platform/clock.h>
44#include <platform/gpio.h>
45#include <platform/iomap.h>
46#include <target/display.h>
47#include <qtimer.h>
48
49#include "include/panel.h"
50#include "include/display_resource.h"
51#include "gcdb_display.h"
52
53/*---------------------------------------------------------------------------*/
54/* GPIO configuration */
55/*---------------------------------------------------------------------------*/
56static struct gpio_pin reset_gpio = {
57 "msmgpio", 0, 3, 1, 0, 1
58};
59
60static struct gpio_pin enable_gpio = {
61 "msmgpio", 90, 3, 1, 0, 1
62};
63
64static struct gpio_pin bkl_gpio = {
65 "msmgpio", 91, 3, 1, 0, 1
66};
67
68#define VCO_DELAY_USEC 1000
69#define GPIO_STATE_LOW 0
70#define GPIO_STATE_HIGH 2
71#define RESET_GPIO_SEQ_LEN 3
72#define PMIC_WLED_SLAVE_ID 3
73
74static void mdss_dsi_uniphy_pll_sw_reset_8952(uint32_t pll_base)
75{
76 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
77 mdelay(1);
78 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
79 mdelay(1);
80}
81
82static void dsi_pll_toggle_lock_detect_8952(uint32_t pll_base)
83{
84 writel(0x04, pll_base + 0x0064); /* LKDetect CFG2 */
85 udelay(1);
86 writel(0x05, pll_base + 0x0064); /* LKDetect CFG2 */
87 udelay(512);
88}
89
90static void dsi_pll_sw_reset_8952(uint32_t pll_base)
91{
92 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
93 udelay(1);
94 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
95}
96
97static uint32_t gf_1_dsi_pll_enable_sequence_8952(uint32_t pll_base)
98{
99 uint32_t rc;
100
101 dsi_pll_sw_reset_8952(pll_base);
102
103 /*
104 * Add hardware recommended delays between register writes for
105 * the updates to take effect. These delays are necessary for the
106 * PLL to successfully lock
107 */
108 writel(0x14, pll_base + 0x0070); /* CAL CFG1*/
109 writel(0x01, pll_base + 0x0020); /* GLB CFG */
110 writel(0x05, pll_base + 0x0020); /* GLB CFG */
111 udelay(3);
112 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
113 udelay(500);
114
115 dsi_pll_toggle_lock_detect_8952(pll_base);
116 rc = readl(pll_base + 0x00c0) & 0x01;
117
118 return rc;
119}
120
121static uint32_t gf_2_dsi_pll_enable_sequence_8952(uint32_t pll_base)
122{
123 uint32_t rc;
124
125 dsi_pll_sw_reset_8952(pll_base);
126
127 /*
128 * Add hardware recommended delays between register writes for
129 * the updates to take effect. These delays are necessary for the
130 * PLL to successfully lock
131 */
132 writel(0x04, pll_base + 0x0070); /* CAL CFG1*/
133 writel(0x01, pll_base + 0x0020); /* GLB CFG */
134 writel(0x05, pll_base + 0x0020); /* GLB CFG */
135 udelay(3);
136 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
137 udelay(500);
138
139 dsi_pll_toggle_lock_detect_8952(pll_base);
140 rc = readl(pll_base + 0x00c0) & 0x01;
141
142 return rc;
143}
144
145static uint32_t tsmc_dsi_pll_enable_sequence_8952(uint32_t pll_base)
146{
147 uint32_t rc;
148
149 dsi_pll_sw_reset_8952(pll_base);
150 /*
151 * Add hardware recommended delays between register writes for
152 * the updates to take effect. These delays are necessary for the
153 * PLL to successfully lock
154 */
155
156 writel(0x34, pll_base + 0x0070); /* CAL CFG1*/
157 writel(0x01, pll_base + 0x0020); /* GLB CFG */
158 writel(0x05, pll_base + 0x0020); /* GLB CFG */
159 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
160 udelay(500);
161
162 dsi_pll_toggle_lock_detect_8952(pll_base);
163 rc = readl(pll_base + 0x00c0) & 0x01;
164
165 return rc;
166}
167
168
169static uint32_t dsi_pll_enable_seq_8952(uint32_t pll_base)
170{
171 uint32_t pll_locked = 0;
172 uint32_t counter = 0;
173
174 do {
175 pll_locked = tsmc_dsi_pll_enable_sequence_8952(pll_base);
176
177 dprintf(SPEW, "TSMC pll locked status is %d\n", pll_locked);
178 ++counter;
179 } while (!pll_locked && (counter < 3));
180
181 if(!pll_locked) {
182 counter = 0;
183 do {
184 pll_locked = gf_1_dsi_pll_enable_sequence_8952(pll_base);
185
186 dprintf(SPEW, "GF P1 pll locked status is %d\n", pll_locked);
187 ++counter;
188 } while (!pll_locked && (counter < 3));
189 }
190
191 if(!pll_locked) {
192 counter = 0;
193 do {
194 pll_locked = gf_2_dsi_pll_enable_sequence_8952(pll_base);
195
196 dprintf(SPEW, "GF P2 pll locked status is %d\n", pll_locked);
197 ++counter;
198 } while (!pll_locked && (counter < 3));
199 }
200
201 return pll_locked;
202}
203
204static int msm8952_wled_backlight_ctrl(uint8_t enable)
205{
206 uint8_t slave_id = PMIC_WLED_SLAVE_ID; /* pmi */
207
208 pm8x41_wled_config_slave_id(slave_id);
209 qpnp_wled_enable_backlight(enable);
210 qpnp_ibb_enable(enable);
211 return NO_ERROR;
212}
213
214int target_backlight_ctrl(struct backlight *bl, uint8_t enable)
215{
216 uint32_t ret = NO_ERROR;
217
218 if (bl->bl_interface_type == BL_DCS)
219 return ret;
220
221 ret = msm8952_wled_backlight_ctrl(enable);
222
223 return ret;
224}
225
226int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo)
227{
228 int32_t ret = 0;
229 struct mdss_dsi_pll_config *pll_data;
230 dprintf(SPEW, "target_panel_clock\n");
231
232 pll_data = pinfo->mipi.dsi_pll_config;
233 pll_data->vco_delay = VCO_DELAY_USEC;
234
235 if (enable) {
236 mdp_gdsc_ctrl(enable);
237 mdss_bus_clocks_enable();
238 mdp_clock_enable();
239 ret = restore_secure_cfg(SECURE_DEVICE_MDSS);
240 if (ret) {
241 dprintf(CRITICAL,
242 "%s: Failed to restore MDP security configs",
243 __func__);
244 mdp_clock_disable();
245 mdss_bus_clocks_disable();
246 mdp_gdsc_ctrl(0);
247 return ret;
248 }
Padmanabhan Komanduruc0766c82015-04-27 16:39:15 -0700249 mdss_dsi_uniphy_pll_sw_reset_8952(pinfo->mipi.pll_base);
250 mdss_dsi_auto_pll_config(pinfo->mipi.pll_base,
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700251 pinfo->mipi.ctl_base, pll_data);
Padmanabhan Komanduruc0766c82015-04-27 16:39:15 -0700252 if (!dsi_pll_enable_seq_8952(pinfo->mipi.pll_base))
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700253 dprintf(CRITICAL, "Not able to enable the pll\n");
254 gcc_dsi_clocks_enable(pll_data->pclk_m, pll_data->pclk_n,
255 pll_data->pclk_d);
256 } else if(!target_cont_splash_screen()) {
257 gcc_dsi_clocks_disable();
258 mdp_clock_disable();
259 mdss_bus_clocks_disable();
260 mdp_gdsc_ctrl(enable);
261 }
262
263 return 0;
264}
265
266int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
267 struct msm_panel_info *pinfo)
268{
269 int ret = NO_ERROR;
270
271 if (enable) {
272 if (pinfo->mipi.use_enable_gpio) {
273 gpio_tlmm_config(enable_gpio.pin_id, 0,
274 enable_gpio.pin_direction, enable_gpio.pin_pull,
275 enable_gpio.pin_strength,
276 enable_gpio.pin_state);
277
278 gpio_set_dir(enable_gpio.pin_id, 2);
279 }
280
281 gpio_tlmm_config(bkl_gpio.pin_id, 0,
282 bkl_gpio.pin_direction, bkl_gpio.pin_pull,
283 bkl_gpio.pin_strength, bkl_gpio.pin_state);
284
285 gpio_set_dir(bkl_gpio.pin_id, 2);
286
287 gpio_tlmm_config(reset_gpio.pin_id, 0,
288 reset_gpio.pin_direction, reset_gpio.pin_pull,
289 reset_gpio.pin_strength, reset_gpio.pin_state);
290
291 gpio_set_dir(reset_gpio.pin_id, 2);
292
293 /* reset */
294 for (int i = 0; i < RESET_GPIO_SEQ_LEN; i++) {
295 if (resetseq->pin_state[i] == GPIO_STATE_LOW)
296 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_LOW);
297 else
298 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_HIGH);
299 mdelay(resetseq->sleep[i]);
300 }
301 } else if(!target_cont_splash_screen()) {
302 gpio_set_dir(reset_gpio.pin_id, 0);
303 if (pinfo->mipi.use_enable_gpio)
304 gpio_set_dir(enable_gpio.pin_id, 0);
305 }
306
307 return ret;
308}
309
310static void wled_init(struct msm_panel_info *pinfo)
311{
312 struct qpnp_wled_config_data config = {0};
313 struct labibb_desc *labibb;
314 int display_type = 0;
315
316 labibb = pinfo->labibb;
317
318 if (labibb)
319 display_type = labibb->amoled_panel;
320
321 config.display_type = display_type;
322 config.lab_init_volt = 4600000; /* fixed, see pmi register */
323 config.ibb_init_volt = 1400000; /* fixed, see pmi register */
324
325 if (labibb && labibb->force_config) {
326 config.lab_min_volt = labibb->lab_min_volt;
327 config.lab_max_volt = labibb->lab_max_volt;
328 config.ibb_min_volt = labibb->ibb_min_volt;
329 config.ibb_max_volt = labibb->ibb_max_volt;
330 config.pwr_up_delay = labibb->pwr_up_delay;
331 config.pwr_down_delay = labibb->pwr_down_delay;
332 config.ibb_discharge_en = labibb->ibb_discharge_en;
333 } else {
334 /* default */
335 config.pwr_up_delay = 3;
336 config.pwr_down_delay = 3;
337 config.ibb_discharge_en = 1;
338 if (display_type) { /* amoled */
339 config.lab_min_volt = 4600000;
340 config.lab_max_volt = 4600000;
341 config.ibb_min_volt = 4000000;
342 config.ibb_max_volt = 4000000;
343 } else { /* lcd */
344 config.lab_min_volt = 5500000;
345 config.lab_max_volt = 5500000;
346 config.ibb_min_volt = 5500000;
347 config.ibb_max_volt = 5500000;
348 }
349 }
350
351 dprintf(SPEW, "%s: %d %d %d %d %d %d %d %d %d %d\n", __func__,
352 config.display_type,
353 config.lab_min_volt, config.lab_max_volt,
354 config.ibb_min_volt, config.ibb_max_volt,
355 config.lab_init_volt, config.ibb_init_volt,
356 config.pwr_up_delay, config.pwr_down_delay,
357 config.ibb_discharge_en);
358
359 /* QPNP WLED init for display backlight */
360 pm8x41_wled_config_slave_id(PMIC_WLED_SLAVE_ID);
361
362 qpnp_wled_init(&config);
363}
364
365int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo)
366{
367
368 if (enable) {
369 regulator_enable(REG_LDO2 | REG_LDO6 | REG_LDO17);
370 mdelay(10);
371 wled_init(pinfo);
372 qpnp_ibb_enable(true); /*5V boost*/
373 mdelay(50);
374 } else {
375 regulator_disable(REG_LDO2 | REG_LDO6 | REG_LDO17);
376 }
377
378 return NO_ERROR;
379}
380
381bool target_display_panel_node(char *panel_name, char *pbuf, uint16_t buf_size)
382{
383 return gcdb_display_cmdline_arg(panel_name, pbuf, buf_size);
384}
385
386void target_display_init(const char *panel_name)
387{
388 char cont_splash = '\0';
389
390 set_panel_cmd_string(panel_name, &cont_splash);
391 panel_name += strspn(panel_name, " ");
392
393 if (!strcmp(panel_name, NO_PANEL_CONFIG)
394 || !strcmp(panel_name, SIM_VIDEO_PANEL)
395 || !strcmp(panel_name, SIM_CMD_PANEL)) {
396 dprintf(INFO, "Selected panel: %s\nSkip panel configuration\n",
397 panel_name);
398 return;
399 }
400
401 if (gcdb_display_init(panel_name, MDP_REV_50, (void *)MIPI_FB_ADDR)) {
402 target_force_cont_splash_disable(true);
403 msm_display_off();
404 }
405
406 if (cont_splash == '0') {
407 dprintf(INFO, "Forcing continuous splash disable\n");
408 target_force_cont_splash_disable(true);
409 }
410}
411
412void target_display_shutdown(void)
413{
414 gcdb_display_shutdown();
415}