blob: adacf1d2a62c331d7afee6a004447af9e5b0f71a [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
Dhaval Patel7709c412015-05-12 10:09:41 -0700266int target_dsi_phy_config(struct mdss_dsi_phy_ctrl *phy_db)
267{
268 memcpy(phy_db->regulator, panel_regulator_settings, REGULATOR_SIZE);
269 memcpy(phy_db->ctrl, panel_physical_ctrl, PHYSICAL_SIZE);
270 memcpy(phy_db->strength, panel_strength_ctrl, STRENGTH_SIZE);
271 memcpy(phy_db->bistCtrl, panel_bist_ctrl, BIST_SIZE);
272 memcpy(phy_db->laneCfg, panel_lane_config, LANE_SIZE);
273 return NO_ERROR;
274}
275
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800276/* Pull DISP_RST_N high to get panel out of reset */
Casey Piper98e94f12013-09-09 20:42:15 -0700277int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
278 struct msm_panel_info *pinfo)
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800279{
Casey Piper98e94f12013-09-09 20:42:15 -0700280 uint32_t rst_gpio = reset_gpio.pin_id;
Chandan Uddarajud1bcbeb2013-07-01 18:13:48 -0700281 uint32_t platform_id = board_platform_id();
282 uint32_t hardware_id = board_hardware_id();
283
Casey Piper98e94f12013-09-09 20:42:15 -0700284 struct pm8x41_gpio resetgpio_param = {
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800285 .direction = PM_GPIO_DIR_OUT,
286 .output_buffer = PM_GPIO_OUT_CMOS,
287 .out_strength = PM_GPIO_OUT_DRIVE_MED,
288 };
289
Chandan Uddarajud1bcbeb2013-07-01 18:13:48 -0700290 if (platform_id == MSM8974AC)
Chandan Uddarajub2cee902013-09-05 18:31:23 -0700291 if ((hardware_id == HW_PLATFORM_MTP)
Chandan Uddarajud1bcbeb2013-07-01 18:13:48 -0700292 || (hardware_id == HW_PLATFORM_LIQUID))
293 rst_gpio = 20;
294
295 dprintf(SPEW, "platform_id: %u, rst_gpio: %u\n",
296 platform_id, rst_gpio);
297
Casey Piper98e94f12013-09-09 20:42:15 -0700298 pm8x41_gpio_config(rst_gpio, &resetgpio_param);
Siddhartha Agrawalc43c4872013-04-21 16:23:16 -0700299 if (enable) {
Casey Piper98e94f12013-09-09 20:42:15 -0700300 gpio_tlmm_config(enable_gpio.pin_id, 0,
301 enable_gpio.pin_direction, enable_gpio.pin_pull,
302 enable_gpio.pin_strength, enable_gpio.pin_state);
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800303
Casey Piper98e94f12013-09-09 20:42:15 -0700304 gpio_set(enable_gpio.pin_id, resetseq->pin_direction);
305 pm8x41_gpio_set(rst_gpio, resetseq->pin_state[0]);
306 mdelay(resetseq->sleep[0]);
307 pm8x41_gpio_set(rst_gpio, resetseq->pin_state[1]);
308 mdelay(resetseq->sleep[1]);
309 pm8x41_gpio_set(rst_gpio, resetseq->pin_state[2]);
310 mdelay(resetseq->sleep[2]);
Siddhartha Agrawalc43c4872013-04-21 16:23:16 -0700311 } else {
Casey Piper98e94f12013-09-09 20:42:15 -0700312 resetgpio_param.out_strength = PM_GPIO_OUT_DRIVE_LOW;
313 pm8x41_gpio_config(rst_gpio, &resetgpio_param);
Chandan Uddarajud1bcbeb2013-07-01 18:13:48 -0700314 pm8x41_gpio_set(rst_gpio, PM_GPIO_FUNC_LOW);
Casey Piper98e94f12013-09-09 20:42:15 -0700315 gpio_set(enable_gpio.pin_id, resetseq->pin_direction);
Siddhartha Agrawalc43c4872013-04-21 16:23:16 -0700316 }
Casey Piper98e94f12013-09-09 20:42:15 -0700317 return NO_ERROR;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800318}
319
Kuogee Hsieh93bcff62014-08-22 14:02:08 -0700320int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo)
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800321{
Casey Piper98e94f12013-09-09 20:42:15 -0700322 uint32_t ldocounter = 0;
323 uint32_t pm8x41_ldo_base = 0x13F00;
Deepa Dinamaniec4835b2013-06-03 16:14:24 -0700324
Casey Piper98e94f12013-09-09 20:42:15 -0700325 while (ldocounter < TOTAL_LDO_DEFINED) {
326 struct pm8x41_ldo ldo_entry = LDO((pm8x41_ldo_base +
327 0x100 * ldo_entry_array[ldocounter].ldo_id),
328 ldo_entry_array[ldocounter].ldo_type);
Deepa Dinamaniec4835b2013-06-03 16:14:24 -0700329
vijay kumar32856d52014-08-06 16:18:03 +0530330 dprintf(SPEW, "Setting %u\n",
Casey Piper98e94f12013-09-09 20:42:15 -0700331 ldo_entry_array[ldocounter].ldo_id);
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800332
Casey Piper98e94f12013-09-09 20:42:15 -0700333 /* Set voltage during power on */
334 if (enable) {
335 pm8x41_ldo_set_voltage(&ldo_entry,
336 ldo_entry_array[ldocounter].ldo_voltage);
337 pm8x41_ldo_control(&ldo_entry, enable);
338 } else if(ldo_entry_array[ldocounter].ldo_id != HFPLL_LDO_ID) {
339 pm8x41_ldo_control(&ldo_entry, enable);
340 }
341 ldocounter++;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800342 }
343
Casey Piper98e94f12013-09-09 20:42:15 -0700344 return NO_ERROR;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800345}
346
vijay kumar32856d52014-08-06 16:18:03 +0530347static uint32_t msm8974_mdss_edp_panel_clock(uint8_t enable , struct msm_panel_info *pinfo)
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300348{
Veera Sundaram Sankaranae0bd272014-12-17 12:12:49 -0800349 uint32_t dual_dsi = pinfo->mipi.dual_dsi;
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300350 if (enable) {
351 mdp_gdsc_ctrl(enable);
352 mdp_clock_init();
353 edp_clk_enable();
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300354 } else if (!target_cont_splash_screen()) {
355 /* Add here for continuous splash */
Kuogee Hsiehdf636eb2013-08-01 14:52:08 -0700356 edp_clk_disable();
Veera Sundaram Sankaranae0bd272014-12-17 12:12:49 -0800357 mdp_clock_disable(dual_dsi);
Kuogee Hsiehdf636eb2013-08-01 14:52:08 -0700358 mdp_gdsc_ctrl(enable);
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300359 }
360
361 return 0;
362}
363
vijay kumar32856d52014-08-06 16:18:03 +0530364static int msm8974_edp_panel_power(uint8_t enable)
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300365{
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300366 struct pm8x41_ldo ldo12 = LDO(PM8x41_LDO12, PLDO_TYPE);
367
368 if (enable) {
369 /* Enable backlight */
370 dprintf(SPEW, "Enable Backlight\n");
Kuogee Hsiehdf961742013-12-18 14:13:45 -0800371 msm8974_pwm_backlight_ctrl(36, 8, 1);
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300372 dprintf(SPEW, "Enable Backlight Done\n");
373
374 /* Turn on LDO12 for edp vdda */
375 dprintf(SPEW, "Setting LDO12 n");
376 pm8x41_ldo_set_voltage(&ldo12, 1800000);
377 pm8x41_ldo_control(&ldo12, enable);
378 dprintf(SPEW, "Setting LDO12 Done\n");
379
380 /* Panel Enable */
381 dprintf(SPEW, "Panel Enable\n");
382 gpio_tlmm_config(58, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA,
383 GPIO_DISABLE);
384 gpio_set(58, 2);
385 dprintf(SPEW, "Panel Enable Done\n");
386 } else {
387 /* Keep LDO12 on, otherwise kernel will not boot */
Kuogee Hsiehdf636eb2013-08-01 14:52:08 -0700388 gpio_set(58, 0);
Kuogee Hsiehdf961742013-12-18 14:13:45 -0800389 msm8974_pwm_backlight_ctrl(36, 8, 0);
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300390 }
391
392 return 0;
393}
394
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530395bool target_display_panel_node(char *pbuf, uint16_t buf_size)
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700396{
397 int prefix_string_len = strlen(DISPLAY_CMDLINE_PREFIX);
398 bool ret = true;
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530399 struct oem_panel_data oem = mdss_dsi_get_oem_data();
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700400
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530401 if (!strcmp(oem.panel, HDMI_PANEL_NAME)) {
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700402 if (buf_size < (prefix_string_len + LK_OVERRIDE_PANEL_LEN +
vijay kumar32856d52014-08-06 16:18:03 +0530403 strlen(HDMI_CONTROLLER_STRING))) {
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700404 dprintf(CRITICAL, "command line argument is greater than buffer size\n");
405 return false;
406 }
407
408 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
409 buf_size -= prefix_string_len;
410 strlcat(pbuf, LK_OVERRIDE_PANEL, buf_size);
411 buf_size -= LK_OVERRIDE_PANEL_LEN;
412 strlcat(pbuf, HDMI_CONTROLLER_STRING, buf_size);
413 } else {
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530414 ret = gcdb_display_cmdline_arg(pbuf, buf_size);
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700415 }
416
417 return ret;
418}
419
Aravind Venkateswaran6385f7e2014-02-25 16:45:11 -0800420void target_display_init(const char *panel_name)
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800421{
422 uint32_t hw_id = board_hardware_id();
Casey Piper74f8e5c2013-09-05 15:00:30 -0700423 uint32_t panel_loop = 0;
vijay kumar32856d52014-08-06 16:18:03 +0530424 int ret = 0;
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530425 struct oem_panel_data oem;
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700426
Channagoud Kadabi62ac4cb2014-05-13 11:55:38 -0700427 if (target_hw_interposer())
428 return;
429
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530430 set_panel_cmd_string(panel_name);
431 oem = mdss_dsi_get_oem_data();
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700432
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530433 if (!strcmp(oem.panel, NO_PANEL_CONFIG)
434 || !strcmp(oem.panel, SIM_VIDEO_PANEL)
435 || !strcmp(oem.panel, SIM_DUALDSI_VIDEO_PANEL)
436 || !strcmp(oem.panel, SIM_CMD_PANEL)
437 || !strcmp(oem.panel, SIM_DUALDSI_CMD_PANEL)
438 || oem.skip) {
Veera Sundaram Sankaran3b758822014-10-17 12:15:39 -0700439 dprintf(INFO, "Selected panel: %s\nSkip panel configuration\n",
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530440 oem.panel);
Jeevan Shriramb0d523a2014-05-30 12:55:17 -0700441 return;
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530442 } else if (!strcmp(oem.panel, HDMI_PANEL_NAME)) {
Ajay Singh Parmareef1d602014-03-15 17:41:52 -0700443 dprintf(INFO, "%s: HDMI is primary\n", __func__);
444 return;
445 }
Veera Sundaram Sankaran7868d542015-01-02 14:48:47 -0800446
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800447 switch (hw_id) {
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300448 case HW_PLATFORM_LIQUID:
Kuogee Hsiehdf636eb2013-08-01 14:52:08 -0700449 edp_panel_init(&(panel.panel_info));
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300450 panel.clk_func = msm8974_mdss_edp_panel_clock;
451 panel.power_func = msm8974_edp_panel_power;
452 panel.fb.base = (void *)EDP_FB_ADDR;
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300453 panel.fb.format = FB_FORMAT_RGB888;
454 panel.mdp_rev = MDP_REV_50;
Casey Piper98e94f12013-09-09 20:42:15 -0700455
456 if (msm_display_init(&panel)) {
457 dprintf(CRITICAL, "edp init failed!\n");
458 return;
459 }
460
461 edp_enable = 1;
Asaf Pensoe6870ff2013-07-07 17:23:56 +0300462 break;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800463 default:
Casey Piper74f8e5c2013-09-05 15:00:30 -0700464 do {
Justin Philipbe9de5c2014-09-17 12:26:49 +0530465 target_force_cont_splash_disable(false);
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530466 ret = gcdb_display_init(oem.panel, MDP_REV_50,
vijay kumar32856d52014-08-06 16:18:03 +0530467 (void *)MIPI_FB_ADDR);
Casey Pipercc7e52e2013-10-01 15:51:04 -0700468 if (!ret || ret == ERR_NOT_SUPPORTED) {
469 break;
470 } else {
Casey Piper74f8e5c2013-09-05 15:00:30 -0700471 target_force_cont_splash_disable(true);
472 msm_display_off();
Casey Piper74f8e5c2013-09-05 15:00:30 -0700473 }
vijay kumar32856d52014-08-06 16:18:03 +0530474 } while (++panel_loop <= (uint32_t)oem_panel_max_auto_detect_panels());
Casey Piper98e94f12013-09-09 20:42:15 -0700475 break;
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800476 }
Veera Sundaram Sankaran7868d542015-01-02 14:48:47 -0800477
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530478 if (!oem.cont_splash) {
Veera Sundaram Sankaran7868d542015-01-02 14:48:47 -0800479 dprintf(INFO, "Forcing continuous splash disable\n");
480 target_force_cont_splash_disable(true);
481 }
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800482}
483
Aravind Venkateswarandd50c1a2014-02-25 14:42:43 -0800484void target_display_shutdown(void)
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800485{
Casey Piper98e94f12013-09-09 20:42:15 -0700486 uint32_t hw_id = board_hardware_id();
487 switch (hw_id) {
488 case HW_PLATFORM_LIQUID:
489 if (edp_enable)
490 msm_display_off();
491 break;
492 default:
493 gcdb_display_shutdown();
494 break;
495 }
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800496}