blob: 809b368853044c2b684c94c5b3b6fd35d35cf913 [file] [log] [blame]
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +05301/* Copyright (c) 2013-2014, 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 <smem.h>
32#include <err.h>
33#include <msm_panel.h>
34#include <mipi_dsi.h>
35#include <pm8x41.h>
36#include <pm8x41_wled.h>
37#include <board.h>
38#include <mdp5.h>
39#include <scm.h>
40#include <platform/gpio.h>
41#include <platform/iomap.h>
42#include <target/display.h>
43
44#include "include/panel.h"
45#include "include/display_resource.h"
46
Padmanabhan Komanduru18aa5072014-04-17 16:52:53 +053047#define VCO_DELAY_USEC 1000
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +053048#define GPIO_STATE_LOW 0
49#define GPIO_STATE_HIGH 2
50#define RESET_GPIO_SEQ_LEN 3
51#define PWM_DUTY_US 13
52#define PWM_PERIOD_US 27
53
Padmanabhan Komanduru0a5db942014-04-17 16:56:04 +053054static void mdss_dsi_uniphy_pll_sw_reset_8916(uint32_t pll_base)
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +053055{
Padmanabhan Komanduru0a5db942014-04-17 16:56:04 +053056 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
57 mdelay(1);
58 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
59 mdelay(1);
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +053060}
61
Padmanabhan Komanduru0a5db942014-04-17 16:56:04 +053062static uint32_t dsi_pll_enable_seq_8916(uint32_t pll_base)
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +053063{
64 uint32_t pll_locked = 0;
65
Padmanabhan Komanduru0a5db942014-04-17 16:56:04 +053066 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
67 udelay(1);
68 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +053069
70 /*
71 * Add hardware recommended delays between register writes for
72 * the updates to take effect. These delays are necessary for the
73 * PLL to successfully lock
74 */
Padmanabhan Komanduru0a5db942014-04-17 16:56:04 +053075 writel(0x34, pll_base + 0x0070); /* CAL CFG1*/
76 udelay(1);
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +053077 writel(0x01, pll_base + 0x0020); /* GLB CFG */
Padmanabhan Komanduru0a5db942014-04-17 16:56:04 +053078 udelay(1);
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +053079 writel(0x05, pll_base + 0x0020); /* GLB CFG */
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +053080 udelay(1);
81 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
Padmanabhan Komanduru0a5db942014-04-17 16:56:04 +053082 udelay(1);
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +053083
Padmanabhan Komanduru0a5db942014-04-17 16:56:04 +053084 writel(0x04, pll_base + 0x0064); /* LKDetect CFG2 */
85 udelay(1);
86 writel(0x05, pll_base + 0x0064); /* LKDetect CFG2 */
87 udelay(512);
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +053088 pll_locked = readl(pll_base + 0x00c0) & 0x01;
89
90 return pll_locked;
91}
92
93int target_backlight_ctrl(struct backlight *bl, uint8_t enable)
94{
95 struct pm8x41_mpp mpp;
96 int rc;
97
Shuo Yan123546b2014-05-19 19:35:41 +080098 if (bl->bl_interface_type == BL_DCS)
99 return 0;
100
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530101 mpp.base = PM8x41_MMP4_BASE;
102 mpp.vin = MPP_VIN0;
103 if (enable) {
104 pm_pwm_enable(false);
105 rc = pm_pwm_config(PWM_DUTY_US, PWM_PERIOD_US);
106 if (rc < 0)
107 mpp.mode = MPP_HIGH;
108 else {
109 mpp.mode = MPP_DTEST1;
110 pm_pwm_enable(true);
111 }
112 pm8x41_config_output_mpp(&mpp);
113 pm8x41_enable_mpp(&mpp, MPP_ENABLE);
114 } else {
115 pm_pwm_enable(false);
116 pm8x41_enable_mpp(&mpp, MPP_DISABLE);
117 }
118 mdelay(20);
119 return 0;
120}
121
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530122int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo)
123{
124 int32_t ret = 0;
125 struct mdss_dsi_pll_config *pll_data;
126 dprintf(SPEW, "target_panel_clock\n");
127
128 pll_data = pinfo->mipi.dsi_pll_config;
Padmanabhan Komanduru18aa5072014-04-17 16:52:53 +0530129 pll_data->vco_delay = VCO_DELAY_USEC;
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530130
131 if (enable) {
132 mdp_gdsc_ctrl(enable);
133 mdss_bus_clocks_enable();
134 mdp_clock_enable();
135 ret = restore_secure_cfg(SECURE_DEVICE_MDSS);
136 if (ret) {
137 dprintf(CRITICAL,
138 "%s: Failed to restore MDP security configs",
139 __func__);
140 mdp_clock_disable();
141 mdss_bus_clocks_disable();
142 mdp_gdsc_ctrl(0);
143 return ret;
144 }
Padmanabhan Komanduru0a5db942014-04-17 16:56:04 +0530145 mdss_dsi_uniphy_pll_sw_reset_8916(DSI0_PLL_BASE);
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530146 mdss_dsi_auto_pll_config(DSI0_PLL_BASE,
147 MIPI_DSI0_BASE, pll_data);
Padmanabhan Komanduru0a5db942014-04-17 16:56:04 +0530148 if (!dsi_pll_enable_seq_8916(DSI0_PLL_BASE))
149 dprintf(CRITICAL, "Not able to enable the pll\n");
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530150 gcc_dsi_clocks_enable(pll_data->pclk_m,
151 pll_data->pclk_n,
152 pll_data->pclk_d);
153 } else if(!target_cont_splash_screen()) {
154 gcc_dsi_clocks_disable();
155 mdp_clock_disable();
156 mdss_bus_clocks_disable();
157 mdp_gdsc_ctrl(enable);
158 }
159
160 return 0;
161}
162
163int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
164 struct msm_panel_info *pinfo)
165{
166 int ret = NO_ERROR;
Mao Flynn81409472014-04-10 15:01:30 +0800167 uint32_t hw_id = board_hardware_id();
168 uint32_t hw_subtype = board_hardware_subtype();
169
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530170 if (enable) {
171 if (pinfo->mipi.use_enable_gpio) {
172 gpio_tlmm_config(enable_gpio.pin_id, 0,
173 enable_gpio.pin_direction, enable_gpio.pin_pull,
174 enable_gpio.pin_strength,
175 enable_gpio.pin_state);
176
177 gpio_set_dir(enable_gpio.pin_id, 2);
178 }
179
Shuo Yanc8a417f2014-05-20 14:44:56 +0800180 if (hw_id == HW_PLATFORM_QRD &&
Mao Flynn81409472014-04-10 15:01:30 +0800181 hw_subtype == HW_PLATFORM_SUBTYPE_SKUH) {
182 /* for tps65132 ENP */
183 gpio_tlmm_config(enp_gpio.pin_id, 0,
184 enp_gpio.pin_direction, enp_gpio.pin_pull,
185 enp_gpio.pin_strength,
186 enp_gpio.pin_state);
187 gpio_set_dir(enp_gpio.pin_id, 2);
188
189 /* for tps65132 ENN */
190 gpio_tlmm_config(enn_gpio.pin_id, 0,
191 enn_gpio.pin_direction, enn_gpio.pin_pull,
192 enn_gpio.pin_strength,
193 enn_gpio.pin_state);
194 gpio_set_dir(enn_gpio.pin_id, 2);
195 }
196
Shuo Yanc8a417f2014-05-20 14:44:56 +0800197 if (hw_id == HW_PLATFORM_MTP || hw_id == HW_PLATFORM_SURF) {
198 /* configure backlight gpio for MTP & CDP */
199 gpio_tlmm_config(bkl_gpio.pin_id, 0,
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530200 bkl_gpio.pin_direction, bkl_gpio.pin_pull,
201 bkl_gpio.pin_strength, bkl_gpio.pin_state);
Shuo Yanc8a417f2014-05-20 14:44:56 +0800202 gpio_set_dir(bkl_gpio.pin_id, 2);
203 }
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530204
205 gpio_tlmm_config(reset_gpio.pin_id, 0,
206 reset_gpio.pin_direction, reset_gpio.pin_pull,
207 reset_gpio.pin_strength, reset_gpio.pin_state);
208
209 gpio_set_dir(reset_gpio.pin_id, 2);
210
211 /* reset */
212 for (int i = 0; i < RESET_GPIO_SEQ_LEN; i++) {
213 if (resetseq->pin_state[i] == GPIO_STATE_LOW)
214 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_LOW);
215 else
216 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_HIGH);
217 mdelay(resetseq->sleep[i]);
218 }
219 } else if(!target_cont_splash_screen()) {
220 gpio_set_dir(reset_gpio.pin_id, 0);
221 if (pinfo->mipi.use_enable_gpio)
222 gpio_set_dir(enable_gpio.pin_id, 0);
Mao Flynn81409472014-04-10 15:01:30 +0800223
224 if(hw_id == HW_PLATFORM_QRD &&
225 hw_subtype == HW_PLATFORM_SUBTYPE_SKUH) {
226 gpio_set_dir(enp_gpio.pin_id, 0); /* ENP */
227 gpio_set_dir(enn_gpio.pin_id, 0); /* ENN */
228 }
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530229 }
230
231 return ret;
232}
233
234int target_ldo_ctrl(uint8_t enable)
235{
Padmanabhan Komanduru0ed51fb2014-06-04 12:22:08 +0530236 /*
237 * The PMIC regulators needed for display are enabled in SBL.
238 * There is no access to the regulators is LK.
239 */
240 return NO_ERROR;
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530241}
242
243bool target_display_panel_node(char *panel_name, char *pbuf, uint16_t buf_size)
244{
245 return gcdb_display_cmdline_arg(pbuf, buf_size);
246}
247
248void target_display_init(const char *panel_name)
249{
Padmanabhan Komanduru1869a762014-04-01 20:12:05 +0530250 uint32_t panel_loop = 0;
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530251 uint32_t ret = 0;
Padmanabhan Komanduru1869a762014-04-01 20:12:05 +0530252 do {
253 ret = gcdb_display_init(panel_name, MDP_REV_50, MIPI_FB_ADDR);
254 if (!ret || ret == ERR_NOT_SUPPORTED) {
255 break;
256 } else {
257 target_force_cont_splash_disable(true);
258 msm_display_off();
259 target_force_cont_splash_disable(false);
260 }
261 } while (++panel_loop <= oem_panel_max_auto_detect_panels());
Padmanabhan Komandurucd5645e2014-03-25 20:34:18 +0530262}
263
264void target_display_shutdown(void)
265{
266 gcdb_display_shutdown();
267}