blob: 73319eabf537f6941cb0f487e06b22df7919e793 [file] [log] [blame]
Jeevan Shriram2d3500b2014-12-29 16:25:06 -08001/* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -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>
Casey Piper98e94f12013-09-09 20:42:15 -070032#include <err.h>
vijay kumar32856d52014-08-06 16:18:03 +053033#include <qtimer.h>
34#include <string.h>
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -080035#include <msm_panel.h>
Casey Piper98e94f12013-09-09 20:42:15 -070036#include <mipi_dsi.h>
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -080037#include <pm8x41.h>
38#include <pm8x41_wled.h>
39#include <board.h>
40#include <mdp5.h>
vijay kumar32856d52014-08-06 16:18:03 +053041#include <edp.h>
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -080042#include <platform/gpio.h>
Asaf Pensoc9080dc2013-05-21 21:53:50 +030043#include <platform/clock.h>
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -070044#include <platform/iomap.h>
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -080045#include <target/display.h>
vijay kumar32856d52014-08-06 16:18:03 +053046#include <gcdb_display.h>
Casey Piper98e94f12013-09-09 20:42:15 -070047#include "include/panel.h"
48#include "include/display_resource.h"
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -080049
50static struct msm_fb_panel_data panel;
Casey Piper98e94f12013-09-09 20:42:15 -070051static uint8_t edp_enable;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -080052
Casey Piper98e94f12013-09-09 20:42:15 -070053#define HFPLL_LDO_ID 12
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -080054
vijay kumar32856d52014-08-06 16:18:03 +053055/*---------------------------------------------------------------------------*/
56/* GPIO configuration */
57/*---------------------------------------------------------------------------*/
58static struct gpio_pin reset_gpio = {
59 "pm8941_gpios", 19, 2, 1, 0, 1
60};
61
62static struct gpio_pin enable_gpio = {
63 "msmgpio", 58, 3, 1, 0, 1
64};
65
66static struct gpio_pin pwm_gpio = {
67 "pm8941_gpios", 36, 3, 1, 0, 1
68};
69
70/*---------------------------------------------------------------------------*/
71/* LDO configuration */
72/*---------------------------------------------------------------------------*/
73static struct ldo_entry ldo_entry_array[] = {
74 { "vdd", 22, 0, 3000000, 100000, 100, 0, 20, 0, 0},
75 { "vddio", 12, 0, 1800000, 100000, 100, 0, 20, 0, 0},
76 { "vdda", 2, 1, 1200000, 100000, 100, 0, 0, 0, 0},
77};
78
Asaf Penso0ecd86f2013-05-29 14:49:19 +030079static struct pm8x41_wled_data wled_ctrl = {
Amy Maloche543b5842013-07-31 18:07:38 -070080 .mod_scheme = 0x00,
Asaf Penso0ecd86f2013-05-29 14:49:19 +030081 .led1_brightness = (0x0F << 8) | 0xEF,
82 .led2_brightness = (0x0F << 8) | 0xEF,
83 .led3_brightness = (0x0F << 8) | 0xEF,
84 .max_duty_cycle = 0x01,
85 .ovp = 0x2,
86 .full_current_scale = 0x19
87};
88
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +053089static uint32_t dsi_pll_lock_status(uint32_t pll_base)
Casey Piper98e94f12013-09-09 20:42:15 -070090{
Dhaval Patelbb408712014-03-18 11:45:53 -070091 uint32_t counter, status;
Casey Piper98e94f12013-09-09 20:42:15 -070092
Dhaval Patelbb408712014-03-18 11:45:53 -070093 udelay(100);
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +053094 mdss_dsi_uniphy_pll_lock_detect_setting(pll_base);
Dhaval Patelbb408712014-03-18 11:45:53 -070095
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +053096 status = readl(pll_base + 0x00c0) & 0x01;
Dhaval Patelbb408712014-03-18 11:45:53 -070097 for (counter = 0; counter < 5 && !status; counter++) {
98 udelay(100);
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +053099 status = readl(pll_base + 0x00c0) & 0x01;
Dhaval Patelbb408712014-03-18 11:45:53 -0700100 }
101
102 return status;
103}
104
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530105static uint32_t dsi_pll_enable_seq_b(uint32_t pll_base)
Dhaval Patelbb408712014-03-18 11:45:53 -0700106{
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530107 mdss_dsi_uniphy_pll_sw_reset(pll_base);
Casey Piper98e94f12013-09-09 20:42:15 -0700108
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530109 writel(0x01, pll_base + 0x0020); /* GLB CFG */
Dhaval Patelbb408712014-03-18 11:45:53 -0700110 udelay(1);
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530111 writel(0x05, pll_base + 0x0020); /* GLB CFG */
Dhaval Patelbb408712014-03-18 11:45:53 -0700112 udelay(200);
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530113 writel(0x07, pll_base + 0x0020); /* GLB CFG */
Dhaval Patelbb408712014-03-18 11:45:53 -0700114 udelay(500);
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530115 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
Dhaval Patelbb408712014-03-18 11:45:53 -0700116 udelay(500);
Casey Piper98e94f12013-09-09 20:42:15 -0700117
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530118 return dsi_pll_lock_status(pll_base);
Dhaval Patelbb408712014-03-18 11:45:53 -0700119}
Casey Piper98e94f12013-09-09 20:42:15 -0700120
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530121static uint32_t dsi_pll_enable_seq_d(uint32_t pll_base)
Dhaval Patelbb408712014-03-18 11:45:53 -0700122{
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530123 mdss_dsi_uniphy_pll_sw_reset(pll_base);
Dhaval Patelbb408712014-03-18 11:45:53 -0700124
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530125 writel(0x01, pll_base + 0x0020); /* GLB CFG */
Dhaval Patelbb408712014-03-18 11:45:53 -0700126 udelay(1);
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530127 writel(0x05, pll_base + 0x0020); /* GLB CFG */
Dhaval Patelbb408712014-03-18 11:45:53 -0700128 udelay(200);
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530129 writel(0x07, pll_base + 0x0020); /* GLB CFG */
Dhaval Patelbb408712014-03-18 11:45:53 -0700130 udelay(250);
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530131 writel(0x05, pll_base + 0x0020); /* GLB CFG */
Dhaval Patelbb408712014-03-18 11:45:53 -0700132 udelay(200);
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530133 writel(0x07, pll_base + 0x0220); /* GLB CFG */
Dhaval Patelbb408712014-03-18 11:45:53 -0700134 udelay(500);
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530135 writel(0x0f, pll_base + 0x0220); /* GLB CFG */
Dhaval Patelbb408712014-03-18 11:45:53 -0700136 udelay(500);
137
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530138 return dsi_pll_lock_status(pll_base);
Dhaval Patelbb408712014-03-18 11:45:53 -0700139}
140
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530141static void dsi_pll_enable_seq(uint32_t pll_base)
Dhaval Patelbb408712014-03-18 11:45:53 -0700142{
143 uint32_t counter, status;
144
145 for (counter = 0; counter < 3; counter++) {
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530146 status = dsi_pll_enable_seq_b(pll_base);
Dhaval Patelbb408712014-03-18 11:45:53 -0700147 if (status)
148 break;
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530149 status = dsi_pll_enable_seq_d(pll_base);
Dhaval Patelbb408712014-03-18 11:45:53 -0700150 if (status)
151 break;
Padmanabhan Komanduru703bd6d2014-03-25 19:57:01 +0530152 status = dsi_pll_enable_seq_d(pll_base);
Dhaval Patelbb408712014-03-18 11:45:53 -0700153 if(status)
154 break;
Casey Piper98e94f12013-09-09 20:42:15 -0700155 }
Dhaval Patelbb408712014-03-18 11:45:53 -0700156
157 if (!status)
158 dprintf(CRITICAL, "Pll lock sequence failed\n");
Casey Piper98e94f12013-09-09 20:42:15 -0700159}
160
Kuogee Hsiehdf961742013-12-18 14:13:45 -0800161static int msm8974_wled_backlight_ctrl(uint8_t enable)
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800162{
Chandan Uddarajud1bcbeb2013-07-01 18:13:48 -0700163 uint32_t platform_id = board_platform_id();
164 uint32_t hardware_id = board_hardware_id();
Casey Piper98e94f12013-09-09 20:42:15 -0700165 uint8_t slave_id = 1;
Chandan Uddarajud1bcbeb2013-07-01 18:13:48 -0700166
Casey Piper98e94f12013-09-09 20:42:15 -0700167 if (enable) {
168 if (platform_id == MSM8974AC)
169 if ((hardware_id == HW_PLATFORM_MTP)
170 || (hardware_id == HW_PLATFORM_LIQUID))
171 slave_id = 3;
Chandan Uddarajud1bcbeb2013-07-01 18:13:48 -0700172
Casey Piper98e94f12013-09-09 20:42:15 -0700173 pm8x41_wled_config_slave_id(slave_id);
174 pm8x41_wled_config(&wled_ctrl);
175 pm8x41_wled_sink_control(enable);
176 pm8x41_wled_iled_sync_control(enable);
Jayant Shekhar855c5002013-12-06 17:36:07 +0530177 pm8x41_wled_led_mod_enable(enable);
Casey Piper98e94f12013-09-09 20:42:15 -0700178 }
179 pm8x41_wled_enable(enable);
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800180
Casey Piper98e94f12013-09-09 20:42:15 -0700181 return NO_ERROR;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800182}
183
Kuogee Hsiehdf961742013-12-18 14:13:45 -0800184static int msm8974_pwm_backlight_ctrl(int gpio_num, int lpg_chan, int enable)
185{
186 struct pm8x41_gpio gpio_param = {
187 .direction = PM_GPIO_DIR_OUT,
188 .function = PM_GPIO_FUNC_2,
189 .vin_sel = 2, /* VIN_2 */
190 .pull = PM_GPIO_PULL_UP_1_5 | PM_GPIO_PULLDOWN_10,
191 .output_buffer = PM_GPIO_OUT_CMOS,
192 .out_strength = PM_GPIO_OUT_DRIVE_HIGH,
193 };
194
195 dprintf(SPEW, "%s: gpio=%d lpg=%d enable=%d\n", __func__,
196 gpio_num, lpg_chan, enable);
197
198 if (enable) {
199 pm8x41_gpio_config(gpio_num, &gpio_param);
200 pm8x41_lpg_write(lpg_chan, 0x41, 0x33); /* LPG_PWM_SIZE_CLK, */
201 pm8x41_lpg_write(lpg_chan, 0x42, 0x01); /* LPG_PWM_FREQ_PREDIV */
202 pm8x41_lpg_write(lpg_chan, 0x43, 0x20); /* LPG_PWM_TYPE_CONFIG */
203 pm8x41_lpg_write(lpg_chan, 0x44, 0xb2); /* LPG_VALUE_LSB */
204 pm8x41_lpg_write(lpg_chan, 0x45, 0x01); /* LPG_VALUE_MSB */
205 pm8x41_lpg_write(lpg_chan, 0x46, 0xe4); /* LPG_ENABLE_CONTROL */
206 } else {
207 pm8x41_lpg_write(lpg_chan, 0x46, 0x00);
208 }
209
210 return NO_ERROR;
211}
212
213int target_backlight_ctrl(struct backlight *bl, uint8_t enable)
214{
215 uint32_t ret = NO_ERROR;
216
217 if (!bl) {
218 dprintf(CRITICAL, "backlight structure is not available\n");
219 return ERR_INVALID_ARGS;
220 }
221
222 switch (bl->bl_interface_type) {
223 case BL_WLED:
224 ret = msm8974_wled_backlight_ctrl(enable);
225 break;
226 case BL_PWM:
Dhaval Patel499b7d22014-01-07 21:57:30 -0800227 ret = msm8974_pwm_backlight_ctrl(pwm_gpio.pin_id,
228 PWM_BL_LPG_CHAN_ID,
Kuogee Hsiehdf961742013-12-18 14:13:45 -0800229 enable);
230 break;
231 default:
232 dprintf(CRITICAL, "backlight type:%d not supported\n",
233 bl->bl_interface_type);
234 return ERR_NOT_SUPPORTED;
235 }
236
237 return ret;
238}
239
Casey Piper98e94f12013-09-09 20:42:15 -0700240int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo)
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800241{
Casey Piper98e94f12013-09-09 20:42:15 -0700242 struct mdss_dsi_pll_config *pll_data;
243 uint32_t dual_dsi = pinfo->mipi.dual_dsi;
244 dprintf(SPEW, "target_panel_clock\n");
245
246 pll_data = pinfo->mipi.dsi_pll_config;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800247 if (enable) {
248 mdp_gdsc_ctrl(enable);
249 mdp_clock_init();
Padmanabhan Komanduruc0766c82015-04-27 16:39:15 -0700250 mdss_dsi_auto_pll_config(pinfo->mipi.pll_base,
Jeevan Shriram2d3500b2014-12-29 16:25:06 -0800251 pinfo->mipi.ctl_base, pll_data);
Padmanabhan Komanduruc0766c82015-04-27 16:39:15 -0700252 dsi_pll_enable_seq(pinfo->mipi.pll_base);
Casey Piper98e94f12013-09-09 20:42:15 -0700253 mmss_clock_auto_pll_init(DSI0_PHY_PLL_OUT, dual_dsi,
254 pll_data->pclk_m,
255 pll_data->pclk_n,
256 pll_data->pclk_d);
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800257 } else if(!target_cont_splash_screen()) {
258 // * Add here for continuous splash *
Siddhartha Agrawalc88737b2013-05-29 20:41:35 -0700259 mmss_clock_disable(dual_dsi);
260 mdp_clock_disable(dual_dsi);
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800261 }
262
Casey Piper98e94f12013-09-09 20:42:15 -0700263 return NO_ERROR;
Asaf Penso325f43a2013-05-21 21:55:48 +0300264}
265
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800266/* Pull DISP_RST_N high to get panel out of reset */
Casey Piper98e94f12013-09-09 20:42:15 -0700267int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
268 struct msm_panel_info *pinfo)
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800269{
Casey Piper98e94f12013-09-09 20:42:15 -0700270 uint32_t rst_gpio = reset_gpio.pin_id;
Chandan Uddarajud1bcbeb2013-07-01 18:13:48 -0700271 uint32_t platform_id = board_platform_id();
272 uint32_t hardware_id = board_hardware_id();
273
Casey Piper98e94f12013-09-09 20:42:15 -0700274 struct pm8x41_gpio resetgpio_param = {
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800275 .direction = PM_GPIO_DIR_OUT,
276 .output_buffer = PM_GPIO_OUT_CMOS,
277 .out_strength = PM_GPIO_OUT_DRIVE_MED,
278 };
279
Chandan Uddarajud1bcbeb2013-07-01 18:13:48 -0700280 if (platform_id == MSM8974AC)
Chandan Uddarajub2cee902013-09-05 18:31:23 -0700281 if ((hardware_id == HW_PLATFORM_MTP)
Chandan Uddarajud1bcbeb2013-07-01 18:13:48 -0700282 || (hardware_id == HW_PLATFORM_LIQUID))
283 rst_gpio = 20;
284
285 dprintf(SPEW, "platform_id: %u, rst_gpio: %u\n",
286 platform_id, rst_gpio);
287
Casey Piper98e94f12013-09-09 20:42:15 -0700288 pm8x41_gpio_config(rst_gpio, &resetgpio_param);
Siddhartha Agrawalc43c4872013-04-21 16:23:16 -0700289 if (enable) {
Casey Piper98e94f12013-09-09 20:42:15 -0700290 gpio_tlmm_config(enable_gpio.pin_id, 0,
291 enable_gpio.pin_direction, enable_gpio.pin_pull,
292 enable_gpio.pin_strength, enable_gpio.pin_state);
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800293
Casey Piper98e94f12013-09-09 20:42:15 -0700294 gpio_set(enable_gpio.pin_id, resetseq->pin_direction);
295 pm8x41_gpio_set(rst_gpio, resetseq->pin_state[0]);
296 mdelay(resetseq->sleep[0]);
297 pm8x41_gpio_set(rst_gpio, resetseq->pin_state[1]);
298 mdelay(resetseq->sleep[1]);
299 pm8x41_gpio_set(rst_gpio, resetseq->pin_state[2]);
300 mdelay(resetseq->sleep[2]);
Siddhartha Agrawalc43c4872013-04-21 16:23:16 -0700301 } else {
Casey Piper98e94f12013-09-09 20:42:15 -0700302 resetgpio_param.out_strength = PM_GPIO_OUT_DRIVE_LOW;
303 pm8x41_gpio_config(rst_gpio, &resetgpio_param);
Chandan Uddarajud1bcbeb2013-07-01 18:13:48 -0700304 pm8x41_gpio_set(rst_gpio, PM_GPIO_FUNC_LOW);
Casey Piper98e94f12013-09-09 20:42:15 -0700305 gpio_set(enable_gpio.pin_id, resetseq->pin_direction);
Siddhartha Agrawalc43c4872013-04-21 16:23:16 -0700306 }
Casey Piper98e94f12013-09-09 20:42:15 -0700307 return NO_ERROR;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800308}
309
Kuogee Hsieh93bcff62014-08-22 14:02:08 -0700310int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo)
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800311{
Casey Piper98e94f12013-09-09 20:42:15 -0700312 uint32_t ldocounter = 0;
313 uint32_t pm8x41_ldo_base = 0x13F00;
Deepa Dinamaniec4835b2013-06-03 16:14:24 -0700314
Casey Piper98e94f12013-09-09 20:42:15 -0700315 while (ldocounter < TOTAL_LDO_DEFINED) {
316 struct pm8x41_ldo ldo_entry = LDO((pm8x41_ldo_base +
317 0x100 * ldo_entry_array[ldocounter].ldo_id),
318 ldo_entry_array[ldocounter].ldo_type);
Deepa Dinamaniec4835b2013-06-03 16:14:24 -0700319
vijay kumar32856d52014-08-06 16:18:03 +0530320 dprintf(SPEW, "Setting %u\n",
Casey Piper98e94f12013-09-09 20:42:15 -0700321 ldo_entry_array[ldocounter].ldo_id);
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800322
Casey Piper98e94f12013-09-09 20:42:15 -0700323 /* Set voltage during power on */
324 if (enable) {
325 pm8x41_ldo_set_voltage(&ldo_entry,
326 ldo_entry_array[ldocounter].ldo_voltage);
327 pm8x41_ldo_control(&ldo_entry, enable);
328 } else if(ldo_entry_array[ldocounter].ldo_id != HFPLL_LDO_ID) {
329 pm8x41_ldo_control(&ldo_entry, enable);
330 }
331 ldocounter++;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800332 }
333
Casey Piper98e94f12013-09-09 20:42:15 -0700334 return NO_ERROR;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800335}
336
vijay kumar32856d52014-08-06 16:18:03 +0530337static uint32_t msm8974_mdss_edp_panel_clock(uint8_t enable , struct msm_panel_info *pinfo)
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300338{
Veera Sundaram Sankaranae0bd272014-12-17 12:12:49 -0800339 uint32_t dual_dsi = pinfo->mipi.dual_dsi;
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300340 if (enable) {
341 mdp_gdsc_ctrl(enable);
342 mdp_clock_init();
343 edp_clk_enable();
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300344 } else if (!target_cont_splash_screen()) {
345 /* Add here for continuous splash */
Kuogee Hsiehdf636eb2013-08-01 14:52:08 -0700346 edp_clk_disable();
Veera Sundaram Sankaranae0bd272014-12-17 12:12:49 -0800347 mdp_clock_disable(dual_dsi);
Kuogee Hsiehdf636eb2013-08-01 14:52:08 -0700348 mdp_gdsc_ctrl(enable);
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300349 }
350
351 return 0;
352}
353
vijay kumar32856d52014-08-06 16:18:03 +0530354static int msm8974_edp_panel_power(uint8_t enable)
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300355{
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300356 struct pm8x41_ldo ldo12 = LDO(PM8x41_LDO12, PLDO_TYPE);
357
358 if (enable) {
359 /* Enable backlight */
360 dprintf(SPEW, "Enable Backlight\n");
Kuogee Hsiehdf961742013-12-18 14:13:45 -0800361 msm8974_pwm_backlight_ctrl(36, 8, 1);
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300362 dprintf(SPEW, "Enable Backlight Done\n");
363
364 /* Turn on LDO12 for edp vdda */
365 dprintf(SPEW, "Setting LDO12 n");
366 pm8x41_ldo_set_voltage(&ldo12, 1800000);
367 pm8x41_ldo_control(&ldo12, enable);
368 dprintf(SPEW, "Setting LDO12 Done\n");
369
370 /* Panel Enable */
371 dprintf(SPEW, "Panel Enable\n");
372 gpio_tlmm_config(58, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA,
373 GPIO_DISABLE);
374 gpio_set(58, 2);
375 dprintf(SPEW, "Panel Enable Done\n");
376 } else {
377 /* Keep LDO12 on, otherwise kernel will not boot */
Kuogee Hsiehdf636eb2013-08-01 14:52:08 -0700378 gpio_set(58, 0);
Kuogee Hsiehdf961742013-12-18 14:13:45 -0800379 msm8974_pwm_backlight_ctrl(36, 8, 0);
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300380 }
381
382 return 0;
383}
384
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700385bool target_display_panel_node(char *panel_name, char *pbuf, uint16_t buf_size)
386{
387 int prefix_string_len = strlen(DISPLAY_CMDLINE_PREFIX);
388 bool ret = true;
389
390 panel_name += strspn(panel_name, " ");
391
392 if (!strcmp(panel_name, HDMI_PANEL_NAME)) {
393 if (buf_size < (prefix_string_len + LK_OVERRIDE_PANEL_LEN +
vijay kumar32856d52014-08-06 16:18:03 +0530394 strlen(HDMI_CONTROLLER_STRING))) {
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700395 dprintf(CRITICAL, "command line argument is greater than buffer size\n");
396 return false;
397 }
398
399 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
400 buf_size -= prefix_string_len;
401 strlcat(pbuf, LK_OVERRIDE_PANEL, buf_size);
402 buf_size -= LK_OVERRIDE_PANEL_LEN;
403 strlcat(pbuf, HDMI_CONTROLLER_STRING, buf_size);
404 } else {
Veera Sundaram Sankaranc95d6752014-07-31 11:49:52 -0700405 ret = gcdb_display_cmdline_arg(panel_name, pbuf, buf_size);
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700406 }
407
408 return ret;
409}
410
Aravind Venkateswaran6385f7e2014-02-25 16:45:11 -0800411void target_display_init(const char *panel_name)
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800412{
413 uint32_t hw_id = board_hardware_id();
Casey Piper74f8e5c2013-09-05 15:00:30 -0700414 uint32_t panel_loop = 0;
vijay kumar32856d52014-08-06 16:18:03 +0530415 int ret = 0;
Veera Sundaram Sankaran7868d542015-01-02 14:48:47 -0800416 char cont_splash = '\0';
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700417
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -0700418 if (target_hw_interposer())
419 return;
420
Veera Sundaram Sankaran7868d542015-01-02 14:48:47 -0800421 set_panel_cmd_string(panel_name, &cont_splash);
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700422 panel_name += strspn(panel_name, " ");
423
Veera Sundaram Sankaran3b758822014-10-17 12:15:39 -0700424 if (!strcmp(panel_name, NO_PANEL_CONFIG)
425 || !strcmp(panel_name, SIM_VIDEO_PANEL)
426 || !strcmp(panel_name, SIM_DUALDSI_VIDEO_PANEL)
427 || !strcmp(panel_name, SIM_CMD_PANEL)
428 || !strcmp(panel_name, SIM_DUALDSI_CMD_PANEL)) {
429 dprintf(INFO, "Selected panel: %s\nSkip panel configuration\n",
430 panel_name);
Jeevan Shriramb0d523a2014-05-30 12:55:17 -0700431 return;
Veera Sundaram Sankaranc95d6752014-07-31 11:49:52 -0700432 } else if (!strcmp(panel_name, HDMI_PANEL_NAME)) {
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700433 dprintf(INFO, "%s: HDMI is primary\n", __func__);
434 return;
435 }
Veera Sundaram Sankaran7868d542015-01-02 14:48:47 -0800436
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800437 switch (hw_id) {
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300438 case HW_PLATFORM_LIQUID:
Kuogee Hsiehdf636eb2013-08-01 14:52:08 -0700439 edp_panel_init(&(panel.panel_info));
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300440 panel.clk_func = msm8974_mdss_edp_panel_clock;
441 panel.power_func = msm8974_edp_panel_power;
442 panel.fb.base = (void *)EDP_FB_ADDR;
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300443 panel.fb.format = FB_FORMAT_RGB888;
444 panel.mdp_rev = MDP_REV_50;
Casey Piper98e94f12013-09-09 20:42:15 -0700445
446 if (msm_display_init(&panel)) {
447 dprintf(CRITICAL, "edp init failed!\n");
448 return;
449 }
450
451 edp_enable = 1;
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300452 break;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800453 default:
Casey Piper74f8e5c2013-09-05 15:00:30 -0700454 do {
Justin Philipbe9de5c2014-09-17 12:26:49 +0530455 target_force_cont_splash_disable(false);
Aravind Venkateswarand494f962014-02-25 17:16:49 -0800456 ret = gcdb_display_init(panel_name, MDP_REV_50,
vijay kumar32856d52014-08-06 16:18:03 +0530457 (void *)MIPI_FB_ADDR);
Casey Pipercc7e52e2013-10-01 15:51:04 -0700458 if (!ret || ret == ERR_NOT_SUPPORTED) {
459 break;
460 } else {
Casey Piper74f8e5c2013-09-05 15:00:30 -0700461 target_force_cont_splash_disable(true);
462 msm_display_off();
Casey Piper74f8e5c2013-09-05 15:00:30 -0700463 }
vijay kumar32856d52014-08-06 16:18:03 +0530464 } while (++panel_loop <= (uint32_t)oem_panel_max_auto_detect_panels());
Casey Piper98e94f12013-09-09 20:42:15 -0700465 break;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800466 }
Veera Sundaram Sankaran7868d542015-01-02 14:48:47 -0800467
468 if (cont_splash == '0') {
469 dprintf(INFO, "Forcing continuous splash disable\n");
470 target_force_cont_splash_disable(true);
471 }
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800472}
473
Aravind Venkateswarandd50c1a2014-02-25 14:42:43 -0800474void target_display_shutdown(void)
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800475{
Casey Piper98e94f12013-09-09 20:42:15 -0700476 uint32_t hw_id = board_hardware_id();
477 switch (hw_id) {
478 case HW_PLATFORM_LIQUID:
479 if (edp_enable)
480 msm_display_off();
481 break;
482 default:
483 gcdb_display_shutdown();
484 break;
485 }
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800486}