blob: 0757c72c1b88918f1029bb5ff432e5aedbb7fe90 [file] [log] [blame]
Kuogee Hsiehb06e0d72013-12-18 14:12:09 -08001/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Arpita Banerjee841fa062013-05-24 14:59:51 -07002 *
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 <err.h>
32#include <smem.h>
33#include <msm_panel.h>
Dhaval Patel9f61f132013-07-18 14:45:11 -070034#include <string.h>
35#include <stdlib.h>
Arpita Banerjee841fa062013-05-24 14:59:51 -070036#include <board.h>
37#include <mdp5.h>
38#include <platform/gpio.h>
39#include <mipi_dsi.h>
40
41#include "include/display_resource.h"
42#include "include/panel.h"
43#include "panel_display.h"
44#include "gcdb_display.h"
45#include "target/display.h"
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -070046#include "gcdb_autopll.h"
Arpita Banerjee841fa062013-05-24 14:59:51 -070047
48/*---------------------------------------------------------------------------*/
49/* static */
50/*---------------------------------------------------------------------------*/
51static struct msm_fb_panel_data panel;
52struct panel_struct panelstruct;
53static uint8_t display_enable;
54static struct mdss_dsi_phy_ctrl dsi_video_mode_phy_db;
55
Arpita Banerjee841fa062013-05-24 14:59:51 -070056/*---------------------------------------------------------------------------*/
57/* Extern */
58/*---------------------------------------------------------------------------*/
59extern int msm_display_init(struct msm_fb_panel_data *pdata);
60extern int msm_display_off();
61
62static uint32_t panel_backlight_ctrl(uint8_t enable)
63{
Kuogee Hsiehb06e0d72013-12-18 14:12:09 -080064 return target_backlight_ctrl(panelstruct.backlightinfo, enable);
Arpita Banerjee841fa062013-05-24 14:59:51 -070065}
66
67static uint32_t mdss_dsi_panel_reset(uint8_t enable)
68{
69 uint32_t ret = NO_ERROR;
70
Dhaval Patel29f24492013-08-08 20:45:42 -070071 ret = target_panel_reset(enable, panelstruct.panelresetseq,
72 &panel.panel_info);
Arpita Banerjee841fa062013-05-24 14:59:51 -070073
74 return ret;
75}
76
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -070077static uint32_t mdss_dsi_panel_clock(uint8_t enable,
78 struct msm_panel_info *pinfo)
Arpita Banerjee841fa062013-05-24 14:59:51 -070079{
80 uint32_t ret = NO_ERROR;
81
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -070082 ret = calculate_clock_config(pinfo);
83 if (ret) {
84 dprintf(CRITICAL, "Clock calculation failed \n");
85 /* should it stop here ? check with display team */
86 }
87
Arpita Banerjee0906ffd2013-05-24 16:25:38 -070088 ret = target_panel_clock(enable, pinfo);
Arpita Banerjee841fa062013-05-24 14:59:51 -070089
90 return ret;
91}
92
93static int mdss_dsi_panel_power(uint8_t enable)
94{
95 int ret = NO_ERROR;
96
97 if (enable) {
Dhaval Patel29f24492013-08-08 20:45:42 -070098 ret = target_ldo_ctrl(enable);
Arpita Banerjee841fa062013-05-24 14:59:51 -070099 if (ret) {
100 dprintf(CRITICAL, "LDO control enable failed \n");
101 return ret;
102 }
dongzq0414a568ba42015-08-12 17:32:10 +0800103 mdelay(10);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700104 /* Panel Reset */
105 ret = mdss_dsi_panel_reset(enable);
106 if (ret) {
107 dprintf(CRITICAL, "panel reset failed \n");
108 return ret;
109 }
110 dprintf(SPEW, "Panel power on done\n");
111 } else {
Casey Piper5fea4ba2013-09-11 16:23:18 -0700112 /* Disable panel and ldo */
Arpita Banerjee841fa062013-05-24 14:59:51 -0700113 ret = mdss_dsi_panel_reset(enable);
114 if (ret) {
115 dprintf(CRITICAL, "panel reset disable failed \n");
116 return ret;
117 }
118
Dhaval Patel29f24492013-08-08 20:45:42 -0700119 ret = target_ldo_ctrl(enable);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700120 if (ret) {
121 dprintf(CRITICAL, "ldo control disable failed \n");
122 return ret;
123 }
124 dprintf(SPEW, "Panel power off done\n");
125 }
126
127 return ret;
128}
129
Ray Zhang59ace5c2013-12-03 17:16:08 +0800130static int mdss_dsi_panel_pre_init(void)
131{
132 int ret = NO_ERROR;
133
134 if (panelstruct.paneldata->panel_lp11_init) {
135 ret = mdss_dsi_panel_reset(1);
136 if (ret) {
137 dprintf(CRITICAL, "panel reset failed\n");
138 return ret;
139 }
140 }
141
142 if(panelstruct.paneldata->panel_init_delay)
143 udelay(panelstruct.paneldata->panel_init_delay);
144
145 dprintf(SPEW, "Panel pre init done\n");
146 return ret;
147}
148
Casey Piper5fea4ba2013-09-11 16:23:18 -0700149static int mdss_dsi_bl_enable(uint8_t enable)
150{
151 int ret = NO_ERROR;
152
153 ret = panel_backlight_ctrl(enable);
154 if (ret)
155 dprintf(CRITICAL, "Backlight %s failed\n", enable ? "enable" :
156 "disable");
157 return ret;
158}
159
Dhaval Patel9f61f132013-07-18 14:45:11 -0700160bool target_display_panel_node(char *pbuf, uint16_t buf_size)
161{
Casey Pipere165d1a2013-11-21 11:19:25 -0800162 char *dsi_id = NULL;
163 char *panel_node = NULL;
Dhaval Patelbb645c32014-01-03 13:31:09 -0800164 char *slave_panel_node = NULL;
165 uint16_t dsi_id_len = 0, panel_node_len = 0, slave_panel_node_len = 0;
166 uint32_t arg_size = 0;
Casey Pipere165d1a2013-11-21 11:19:25 -0800167 bool ret = true;
Casey Piper13bd82a2013-11-15 12:26:17 -0800168 char *default_str;
Dhaval Patelbb645c32014-01-03 13:31:09 -0800169 int panel_mode = SPLIT_DISPLAY_FLAG | DUAL_PIPE_FLAG;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700170
Justin Philipd4b293a2014-09-17 12:26:49 +0530171 if(panelstruct.paneldata && target_cont_splash_screen())
Casey Pipere165d1a2013-11-21 11:19:25 -0800172 {
173 dsi_id = panelstruct.paneldata->panel_controller;
174 panel_node = panelstruct.paneldata->panel_node_id;
Dhaval Patelbb645c32014-01-03 13:31:09 -0800175 panel_mode = panelstruct.paneldata->panel_operating_mode &
176 panel_mode;
177 slave_panel_node = panelstruct.paneldata->slave_panel_node_id;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700178 }
Casey Piper13bd82a2013-11-15 12:26:17 -0800179 else
180 {
181 if (target_is_edp())
182 {
Siddhartha Agrawalf67b3ff2013-10-23 18:08:04 -0700183 default_str = "1:edp:";
Casey Piper13bd82a2013-11-15 12:26:17 -0800184 }
185 else
186 {
187 default_str = "0:dsi:0:";
188 }
189 strlcpy(pbuf, default_str, buf_size);
190 return true;
191 }
Casey Piper9b7554e2013-10-08 18:37:18 -0700192
Dhaval Patelbb645c32014-01-03 13:31:09 -0800193 if (dsi_id == NULL || panel_node == NULL) {
194 dprintf(CRITICAL, "panel node or dsi ctrl not present\n");
Casey Pipere165d1a2013-11-21 11:19:25 -0800195 return false;
Dhaval Patelbb645c32014-01-03 13:31:09 -0800196 }
197
198 if (panel_mode && slave_panel_node == NULL) {
199 dprintf(CRITICAL, "slave node not present in dual dsi case\n");
200 return false;
201 }
Casey Piper9b7554e2013-10-08 18:37:18 -0700202
Casey Pipere165d1a2013-11-21 11:19:25 -0800203 dsi_id_len = strlen(dsi_id);
Dhaval Patelbb645c32014-01-03 13:31:09 -0800204 panel_node_len = strlen(panel_node);
205 slave_panel_node_len = strlen(slave_panel_node);
Casey Pipere165d1a2013-11-21 11:19:25 -0800206
Dhaval Patelbb645c32014-01-03 13:31:09 -0800207 arg_size = dsi_id_len + panel_node_len + LK_OVERRIDE_PANEL_LEN + 1;
208
209 /* For dual pipe or split display */
210 if (panel_mode)
211 arg_size += DSI_1_STRING_LEN + slave_panel_node_len;
212
213 if (buf_size < arg_size)
Casey Pipere165d1a2013-11-21 11:19:25 -0800214 {
Dhaval Patelbb645c32014-01-03 13:31:09 -0800215 dprintf(CRITICAL, "display command line buffer is small\n");
Casey Pipere165d1a2013-11-21 11:19:25 -0800216 ret = false;
217 }
218 else
Dhaval Patel9f61f132013-07-18 14:45:11 -0700219 {
Dhaval Patelbb645c32014-01-03 13:31:09 -0800220 strlcpy(pbuf, LK_OVERRIDE_PANEL, buf_size);
221 pbuf += LK_OVERRIDE_PANEL_LEN;
222 buf_size -= LK_OVERRIDE_PANEL_LEN;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700223
224 strlcpy(pbuf, dsi_id, buf_size);
Casey Pipere165d1a2013-11-21 11:19:25 -0800225 pbuf += dsi_id_len;
226 buf_size -= dsi_id_len;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700227
228 strlcpy(pbuf, panel_node, buf_size);
Dhaval Patelbb645c32014-01-03 13:31:09 -0800229
230 /* Return string for single dsi */
231 if (!panel_mode)
232 goto end;
233
234 pbuf += panel_node_len;
235 buf_size -= panel_node_len;
236
237 strlcpy(pbuf, DSI_1_STRING, buf_size);
238 pbuf += DSI_1_STRING_LEN;
239 buf_size -= DSI_1_STRING_LEN;
240
241 strlcpy(pbuf, slave_panel_node, buf_size);
Dhaval Patel9f61f132013-07-18 14:45:11 -0700242 }
Dhaval Patelbb645c32014-01-03 13:31:09 -0800243end:
Dhaval Patel9f61f132013-07-18 14:45:11 -0700244 return ret;
245}
246
247
Arpita Banerjee841fa062013-05-24 14:59:51 -0700248static void init_platform_data()
249{
250 memcpy(dsi_video_mode_phy_db.regulator, panel_regulator_settings,
251 REGULATOR_SIZE);
252 memcpy(dsi_video_mode_phy_db.ctrl, panel_physical_ctrl,
253 PHYSICAL_SIZE);
254 memcpy(dsi_video_mode_phy_db.strength, panel_strength_ctrl,
255 STRENGTH_SIZE);
256 memcpy(dsi_video_mode_phy_db.bistCtrl, panel_bist_ctrl, BIST_SIZE);
257 memcpy(dsi_video_mode_phy_db.laneCfg, panel_lane_config, LANE_SIZE);
258}
259
Aravind Venkateswaran927e9102014-02-25 17:16:49 -0800260int gcdb_display_init(const char *panel_name, uint32_t rev, void *base)
Arpita Banerjee841fa062013-05-24 14:59:51 -0700261{
Casey Piper85653e52013-09-05 14:54:42 -0700262 int ret = NO_ERROR;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700263
Aravind Venkateswaran927e9102014-02-25 17:16:49 -0800264 if (!oem_panel_select(panel_name, &panelstruct, &(panel.panel_info),
Arpita Banerjee841fa062013-05-24 14:59:51 -0700265 &dsi_video_mode_phy_db)) {
266 dprintf(CRITICAL, "Target panel init not found!\n");
Casey Piper85653e52013-09-05 14:54:42 -0700267 ret = ERR_NOT_SUPPORTED;
268 goto error_gcdb_display_init;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700269 }
Arpita Banerjee841fa062013-05-24 14:59:51 -0700270 init_platform_data();
271
272 if (dsi_panel_init(&(panel.panel_info), &panelstruct)) {
273 dprintf(CRITICAL, "DSI panel init failed!\n");
Casey Piper85653e52013-09-05 14:54:42 -0700274 ret = ERROR;
275 goto error_gcdb_display_init;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700276 }
277
278 panel.panel_info.mipi.mdss_dsi_phy_db = &dsi_video_mode_phy_db;
279
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -0700280 panel.pll_clk_func = mdss_dsi_panel_clock;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700281 panel.power_func = mdss_dsi_panel_power;
Ray Zhang59ace5c2013-12-03 17:16:08 +0800282 panel.pre_init_func = mdss_dsi_panel_pre_init;
Casey Piper5fea4ba2013-09-11 16:23:18 -0700283 panel.bl_func = mdss_dsi_bl_enable;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700284 panel.fb.base = base;
285 panel.fb.width = panel.panel_info.xres;
286 panel.fb.height = panel.panel_info.yres;
287 panel.fb.stride = panel.panel_info.xres;
288 panel.fb.bpp = panel.panel_info.bpp;
289 panel.fb.format = panel.panel_info.mipi.dst_format;
290 panel.mdp_rev = rev;
291
Casey Piper85653e52013-09-05 14:54:42 -0700292 ret = msm_display_init(&panel);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700293
Casey Piper85653e52013-09-05 14:54:42 -0700294error_gcdb_display_init:
295 display_enable = ret ? 0 : 1;
296 return ret;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700297}
298
299void gcdb_display_shutdown(void)
300{
301 if (display_enable)
302 msm_display_off();
303}