blob: 3f2a493ca94200bf300d499d49beabb89d6d88e6 [file] [log] [blame]
Sandeep Pandaae8d68e2014-12-29 20:07:22 +05301/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +05302 *
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>
Shivaraj Shettyaf4c6072014-11-04 16:25:31 +053036#include <pm8x41_wled.h>
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +053037#include <board.h>
38#include <mdp3.h>
39#include <scm.h>
40#include <platform/gpio.h>
41#include <platform/iomap.h>
42#include <target/display.h>
Casey Piperd2af07b2015-04-01 18:01:58 -070043#include <regulator.h>
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +053044
45#include "include/panel.h"
46#include "include/display_resource.h"
Veera Sundaram Sankaran87f88132015-01-28 11:32:44 -080047#include "gcdb_display.h"
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +053048
49#define VCO_DELAY_USEC 1000
50#define GPIO_STATE_LOW 0
51#define GPIO_STATE_HIGH 2
52#define RESET_GPIO_SEQ_LEN 3
53#define PWM_DUTY_US 13
54#define PWM_PERIOD_US 27
Shivaraj Shetty89fc8ed2015-01-23 15:03:35 +053055#define PM8916_VER 0x20000
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +053056
57static void mdss_dsi_uniphy_pll_sw_reset_8909(uint32_t pll_base)
58{
59 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
60 mdelay(1);
61 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
62 mdelay(1);
63}
64
65static uint32_t dsi_pll_enable_seq_8909(uint32_t pll_base)
66{
67 uint32_t pll_locked = 0;
68
69 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
70 udelay(1);
71 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
72
73 /*
74 * Add hardware recommended delays between register writes for
75 * the updates to take effect. These delays are necessary for the
76 * PLL to successfully lock
77 */
78 writel(0x34, pll_base + 0x0070); /* CAL CFG1*/
79 udelay(1);
80 writel(0x01, pll_base + 0x0020); /* GLB CFG */
81 udelay(1);
82 writel(0x05, pll_base + 0x0020); /* GLB CFG */
83 udelay(1);
84 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
85 udelay(1);
86
87 writel(0x04, pll_base + 0x0064); /* LKDetect CFG2 */
88 udelay(1);
89 writel(0x05, pll_base + 0x0064); /* LKDetect CFG2 */
90 udelay(512);
91 pll_locked = readl(pll_base + 0x00c0) & 0x01;
92
93 return pll_locked;
94}
95
96int target_backlight_ctrl(struct backlight *bl, uint8_t enable)
97{
98 struct pm8x41_mpp mpp;
Shivaraj Shettybe6b6fd2014-12-12 13:48:29 +053099 uint32_t hw_id = board_hardware_id();
Shivaraj Shetty89fc8ed2015-01-23 15:03:35 +0530100 struct board_pmic_data pmic_info;
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530101 int rc;
102
103 if (bl->bl_interface_type == BL_DCS)
104 return 0;
105
Shivaraj Shetty89fc8ed2015-01-23 15:03:35 +0530106 board_pmic_info(&pmic_info, 1);
107 if (pmic_info.pmic_version == PM8916_VER)
Shivaraj Shettybe6b6fd2014-12-12 13:48:29 +0530108 mpp.base = PM8x41_MMP4_BASE;
109 else
110 mpp.base = PM8x41_MMP2_BASE;
111
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530112 mpp.vin = MPP_VIN0;
113 if (enable) {
114 pm_pwm_enable(false);
115 rc = pm_pwm_config(PWM_DUTY_US, PWM_PERIOD_US);
116 if (rc < 0)
117 mpp.mode = MPP_HIGH;
118 else {
119 mpp.mode = MPP_DTEST1;
120 pm_pwm_enable(true);
121 }
122 pm8x41_config_output_mpp(&mpp);
123 pm8x41_enable_mpp(&mpp, MPP_ENABLE);
124 } else {
125 pm_pwm_enable(false);
126 pm8x41_enable_mpp(&mpp, MPP_DISABLE);
127 }
128 mdelay(20);
Sandeep Pandaae8d68e2014-12-29 20:07:22 +0530129
130 if (enable) {
131 gpio_tlmm_config(bkl_gpio.pin_id, 0,
132 bkl_gpio.pin_direction, bkl_gpio.pin_pull,
133 bkl_gpio.pin_strength, bkl_gpio.pin_state);
134 gpio_set(bkl_gpio.pin_id, 2);
135 }
136
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530137 return 0;
138}
139
140int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo)
141{
142 int32_t ret = 0;
143 struct mdss_dsi_pll_config *pll_data;
144 dprintf(SPEW, "target_panel_clock\n");
145
146 pll_data = pinfo->mipi.dsi_pll_config;
147 pll_data->vco_delay = VCO_DELAY_USEC;
148
149 if (enable) {
150 mdp_gdsc_ctrl(enable);
151 mdss_bus_clocks_enable();
152 mdp_clock_enable();
Shivaraj Shettyaf4c6072014-11-04 16:25:31 +0530153
154 /*
155 * Enable auto functional gating
156 * on DSI CMD AXI fetch from DDR
157 */
158 writel(0x3ffff, MDP_CGC_EN);
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530159 ret = restore_secure_cfg(SECURE_DEVICE_MDSS);
160 if (ret) {
161 dprintf(CRITICAL,
162 "%s: Failed to restore MDP security configs",
163 __func__);
164 mdp_clock_disable();
165 mdss_bus_clocks_disable();
166 mdp_gdsc_ctrl(0);
167 return ret;
168 }
169 mdss_dsi_uniphy_pll_sw_reset_8909(DSI0_PLL_BASE);
Jeevan Shriram2d3500b2014-12-29 16:25:06 -0800170 mdss_dsi_auto_pll_config(pinfo->mipi.pll_0_base,
171 pinfo->mipi.ctl_base, pll_data);
172 if (!dsi_pll_enable_seq_8909(pinfo->mipi.pll_0_base))
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530173 dprintf(CRITICAL, "Not able to enable the pll\n");
174 gcc_dsi_clocks_enable(pll_data->pclk_m,
175 pll_data->pclk_n,
176 pll_data->pclk_d);
177 } else if(!target_cont_splash_screen()) {
178 gcc_dsi_clocks_disable();
179 mdp_clock_disable();
180 mdss_bus_clocks_disable();
181 mdp_gdsc_ctrl(enable);
182 }
183
184 return 0;
185}
186
187int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
188 struct msm_panel_info *pinfo)
189{
190 int ret = NO_ERROR;
191 uint32_t hw_id = board_hardware_id();
192 uint32_t hw_subtype = board_hardware_subtype();
193
194 if (enable) {
195 if (pinfo->mipi.use_enable_gpio) {
196 gpio_tlmm_config(enable_gpio.pin_id, 0,
197 enable_gpio.pin_direction, enable_gpio.pin_pull,
198 enable_gpio.pin_strength,
199 enable_gpio.pin_state);
200
Shivaraj Shettyaf4c6072014-11-04 16:25:31 +0530201 gpio_set(enable_gpio.pin_id, 2);
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530202 }
203
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530204 gpio_tlmm_config(reset_gpio.pin_id, 0,
205 reset_gpio.pin_direction, reset_gpio.pin_pull,
206 reset_gpio.pin_strength, reset_gpio.pin_state);
207
Shivaraj Shettyaf4c6072014-11-04 16:25:31 +0530208 gpio_set(reset_gpio.pin_id, 2);
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530209
210 /* reset */
211 for (int i = 0; i < RESET_GPIO_SEQ_LEN; i++) {
212 if (resetseq->pin_state[i] == GPIO_STATE_LOW)
Shivaraj Shettyaf4c6072014-11-04 16:25:31 +0530213 gpio_set(reset_gpio.pin_id, GPIO_STATE_LOW);
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530214 else
Shivaraj Shettyaf4c6072014-11-04 16:25:31 +0530215 gpio_set(reset_gpio.pin_id, GPIO_STATE_HIGH);
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530216 mdelay(resetseq->sleep[i]);
217 }
218 } else if(!target_cont_splash_screen()) {
Shivaraj Shettyaf4c6072014-11-04 16:25:31 +0530219 gpio_set(reset_gpio.pin_id, 0);
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530220 if (pinfo->mipi.use_enable_gpio)
Shivaraj Shettyaf4c6072014-11-04 16:25:31 +0530221 gpio_set(enable_gpio.pin_id, 0);
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530222 }
223
224 return ret;
225}
226
Veera Sundaram Sankaran87f88132015-01-28 11:32:44 -0800227int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo)
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530228{
Shivaraj Shetty01734d32014-11-20 12:24:01 +0530229 if (enable)
Casey Piperd2af07b2015-04-01 18:01:58 -0700230 regulator_enable(REG_LDO2 | REG_LDO6 | REG_LDO17);
Shivaraj Shetty01734d32014-11-20 12:24:01 +0530231
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530232 return NO_ERROR;
233}
234
235bool target_display_panel_node(char *panel_name, char *pbuf, uint16_t buf_size)
236{
Shivaraj Shettyaf4c6072014-11-04 16:25:31 +0530237 return gcdb_display_cmdline_arg(panel_name, pbuf, buf_size);
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530238}
239
240void target_display_init(const char *panel_name)
241{
242 uint32_t panel_loop = 0;
243 uint32_t ret = 0;
Veera Sundaram Sankaran7868d542015-01-02 14:48:47 -0800244 char cont_splash = '\0';
245
246 set_panel_cmd_string(panel_name, &cont_splash);
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530247
Sandeep Panda63933f92014-11-26 19:13:44 +0530248 panel_name += strspn(panel_name, " ");
249 if (!strcmp(panel_name, NO_PANEL_CONFIG)
250 || !strcmp(panel_name, SIM_VIDEO_PANEL)
251 || !strcmp(panel_name, SIM_CMD_PANEL)) {
252 dprintf(INFO, "Selected %s: Skip panel configuration\n",
253 panel_name);
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530254 return;
255 }
256
257 do {
258 target_force_cont_splash_disable(false);
259 ret = gcdb_display_init(panel_name, MDP_REV_305, MIPI_FB_ADDR);
260 if (!ret || ret == ERR_NOT_SUPPORTED) {
261 break;
262 } else {
263 target_force_cont_splash_disable(true);
264 msm_display_off();
265 }
266 } while (++panel_loop <= oem_panel_max_auto_detect_panels());
Veera Sundaram Sankaran7868d542015-01-02 14:48:47 -0800267
268 if (cont_splash == '0') {
269 dprintf(INFO, "Forcing continuous splash disable\n");
270 target_force_cont_splash_disable(true);
271 }
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530272}
273
274void target_display_shutdown(void)
275{
276 gcdb_display_shutdown();
277}