blob: c011c6673b0fb7fe8501d3770ad8f031bbb753c3 [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 }
103
104 /* 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
Casey Piper5fea4ba2013-09-11 16:23:18 -0700130static int mdss_dsi_bl_enable(uint8_t enable)
131{
132 int ret = NO_ERROR;
133
134 ret = panel_backlight_ctrl(enable);
135 if (ret)
136 dprintf(CRITICAL, "Backlight %s failed\n", enable ? "enable" :
137 "disable");
138 return ret;
139}
140
Dhaval Patel9f61f132013-07-18 14:45:11 -0700141bool target_display_panel_node(char *pbuf, uint16_t buf_size)
142{
Casey Pipere165d1a2013-11-21 11:19:25 -0800143 char *dsi_id = NULL;
144 char *panel_node = NULL;
Dhaval Patelbb645c32014-01-03 13:31:09 -0800145 char *slave_panel_node = NULL;
146 uint16_t dsi_id_len = 0, panel_node_len = 0, slave_panel_node_len = 0;
147 uint32_t arg_size = 0;
Casey Pipere165d1a2013-11-21 11:19:25 -0800148 bool ret = true;
Casey Piper13bd82a2013-11-15 12:26:17 -0800149 char *default_str;
Dhaval Patelbb645c32014-01-03 13:31:09 -0800150 int panel_mode = SPLIT_DISPLAY_FLAG | DUAL_PIPE_FLAG;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700151
Casey Pipere165d1a2013-11-21 11:19:25 -0800152 if(panelstruct.paneldata)
153 {
154 dsi_id = panelstruct.paneldata->panel_controller;
155 panel_node = panelstruct.paneldata->panel_node_id;
Dhaval Patelbb645c32014-01-03 13:31:09 -0800156 panel_mode = panelstruct.paneldata->panel_operating_mode &
157 panel_mode;
158 slave_panel_node = panelstruct.paneldata->slave_panel_node_id;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700159 }
Casey Piper13bd82a2013-11-15 12:26:17 -0800160 else
161 {
162 if (target_is_edp())
163 {
Siddhartha Agrawalf67b3ff2013-10-23 18:08:04 -0700164 default_str = "1:edp:";
Casey Piper13bd82a2013-11-15 12:26:17 -0800165 }
166 else
167 {
168 default_str = "0:dsi:0:";
169 }
170 strlcpy(pbuf, default_str, buf_size);
171 return true;
172 }
Casey Piper9b7554e2013-10-08 18:37:18 -0700173
Dhaval Patelbb645c32014-01-03 13:31:09 -0800174 if (dsi_id == NULL || panel_node == NULL) {
175 dprintf(CRITICAL, "panel node or dsi ctrl not present\n");
Casey Pipere165d1a2013-11-21 11:19:25 -0800176 return false;
Dhaval Patelbb645c32014-01-03 13:31:09 -0800177 }
178
179 if (panel_mode && slave_panel_node == NULL) {
180 dprintf(CRITICAL, "slave node not present in dual dsi case\n");
181 return false;
182 }
Casey Piper9b7554e2013-10-08 18:37:18 -0700183
Casey Pipere165d1a2013-11-21 11:19:25 -0800184 dsi_id_len = strlen(dsi_id);
Dhaval Patelbb645c32014-01-03 13:31:09 -0800185 panel_node_len = strlen(panel_node);
186 slave_panel_node_len = strlen(slave_panel_node);
Casey Pipere165d1a2013-11-21 11:19:25 -0800187
Dhaval Patelbb645c32014-01-03 13:31:09 -0800188 arg_size = dsi_id_len + panel_node_len + LK_OVERRIDE_PANEL_LEN + 1;
189
190 /* For dual pipe or split display */
191 if (panel_mode)
192 arg_size += DSI_1_STRING_LEN + slave_panel_node_len;
193
194 if (buf_size < arg_size)
Casey Pipere165d1a2013-11-21 11:19:25 -0800195 {
Dhaval Patelbb645c32014-01-03 13:31:09 -0800196 dprintf(CRITICAL, "display command line buffer is small\n");
Casey Pipere165d1a2013-11-21 11:19:25 -0800197 ret = false;
198 }
199 else
Dhaval Patel9f61f132013-07-18 14:45:11 -0700200 {
Dhaval Patelbb645c32014-01-03 13:31:09 -0800201 strlcpy(pbuf, LK_OVERRIDE_PANEL, buf_size);
202 pbuf += LK_OVERRIDE_PANEL_LEN;
203 buf_size -= LK_OVERRIDE_PANEL_LEN;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700204
205 strlcpy(pbuf, dsi_id, buf_size);
Casey Pipere165d1a2013-11-21 11:19:25 -0800206 pbuf += dsi_id_len;
207 buf_size -= dsi_id_len;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700208
209 strlcpy(pbuf, panel_node, buf_size);
Dhaval Patelbb645c32014-01-03 13:31:09 -0800210
211 /* Return string for single dsi */
212 if (!panel_mode)
213 goto end;
214
215 pbuf += panel_node_len;
216 buf_size -= panel_node_len;
217
218 strlcpy(pbuf, DSI_1_STRING, buf_size);
219 pbuf += DSI_1_STRING_LEN;
220 buf_size -= DSI_1_STRING_LEN;
221
222 strlcpy(pbuf, slave_panel_node, buf_size);
Dhaval Patel9f61f132013-07-18 14:45:11 -0700223 }
Dhaval Patelbb645c32014-01-03 13:31:09 -0800224end:
Dhaval Patel9f61f132013-07-18 14:45:11 -0700225 return ret;
226}
227
228
Arpita Banerjee841fa062013-05-24 14:59:51 -0700229static void init_platform_data()
230{
231 memcpy(dsi_video_mode_phy_db.regulator, panel_regulator_settings,
232 REGULATOR_SIZE);
233 memcpy(dsi_video_mode_phy_db.ctrl, panel_physical_ctrl,
234 PHYSICAL_SIZE);
235 memcpy(dsi_video_mode_phy_db.strength, panel_strength_ctrl,
236 STRENGTH_SIZE);
237 memcpy(dsi_video_mode_phy_db.bistCtrl, panel_bist_ctrl, BIST_SIZE);
238 memcpy(dsi_video_mode_phy_db.laneCfg, panel_lane_config, LANE_SIZE);
239}
240
Casey Piper85653e52013-09-05 14:54:42 -0700241int gcdb_display_init(uint32_t rev, void *base)
Arpita Banerjee841fa062013-05-24 14:59:51 -0700242{
Casey Piper85653e52013-09-05 14:54:42 -0700243 int ret = NO_ERROR;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700244
245 if (!oem_panel_select(&panelstruct, &(panel.panel_info),
246 &dsi_video_mode_phy_db)) {
247 dprintf(CRITICAL, "Target panel init not found!\n");
Casey Piper85653e52013-09-05 14:54:42 -0700248 ret = ERR_NOT_SUPPORTED;
249 goto error_gcdb_display_init;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700250 }
Arpita Banerjee841fa062013-05-24 14:59:51 -0700251 init_platform_data();
252
253 if (dsi_panel_init(&(panel.panel_info), &panelstruct)) {
254 dprintf(CRITICAL, "DSI panel init failed!\n");
Casey Piper85653e52013-09-05 14:54:42 -0700255 ret = ERROR;
256 goto error_gcdb_display_init;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700257 }
258
259 panel.panel_info.mipi.mdss_dsi_phy_db = &dsi_video_mode_phy_db;
260
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -0700261 panel.pll_clk_func = mdss_dsi_panel_clock;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700262 panel.power_func = mdss_dsi_panel_power;
Casey Piper5fea4ba2013-09-11 16:23:18 -0700263 panel.bl_func = mdss_dsi_bl_enable;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700264 panel.fb.base = base;
265 panel.fb.width = panel.panel_info.xres;
266 panel.fb.height = panel.panel_info.yres;
267 panel.fb.stride = panel.panel_info.xres;
268 panel.fb.bpp = panel.panel_info.bpp;
269 panel.fb.format = panel.panel_info.mipi.dst_format;
270 panel.mdp_rev = rev;
271
Casey Piper85653e52013-09-05 14:54:42 -0700272 ret = msm_display_init(&panel);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700273
Casey Piper85653e52013-09-05 14:54:42 -0700274error_gcdb_display_init:
275 display_enable = ret ? 0 : 1;
276 return ret;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700277}
278
279void gcdb_display_shutdown(void)
280{
281 if (display_enable)
282 msm_display_off();
283}