blob: e7f11f3f9df9d53935c7c49e18be11df5c6bbaab [file] [log] [blame]
Arpita Banerjee841fa062013-05-24 14:59:51 -07001/* Copyright (c) 2013, 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 <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
rayz3c988f02013-08-13 18:06:39 +080062/* TODO: add other backlight type support */
Arpita Banerjee841fa062013-05-24 14:59:51 -070063static uint32_t panel_backlight_ctrl(uint8_t enable)
64{
65 uint32_t ret = NO_ERROR;
66
rayz3c988f02013-08-13 18:06:39 +080067 if (panelstruct.backlightinfo->bl_pmic_controltype != BL_DCS) {
68 /* deal with non-dcs backlight */
69 ret = target_backlight_ctrl(enable);
70 }
Arpita Banerjee841fa062013-05-24 14:59:51 -070071
72 return ret;
73}
74
75static uint32_t mdss_dsi_panel_reset(uint8_t enable)
76{
77 uint32_t ret = NO_ERROR;
78
Dhaval Patel29f24492013-08-08 20:45:42 -070079 ret = target_panel_reset(enable, panelstruct.panelresetseq,
80 &panel.panel_info);
Arpita Banerjee841fa062013-05-24 14:59:51 -070081
82 return ret;
83}
84
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -070085static uint32_t mdss_dsi_panel_clock(uint8_t enable,
86 struct msm_panel_info *pinfo)
Arpita Banerjee841fa062013-05-24 14:59:51 -070087{
88 uint32_t ret = NO_ERROR;
89
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -070090 ret = calculate_clock_config(pinfo);
91 if (ret) {
92 dprintf(CRITICAL, "Clock calculation failed \n");
93 /* should it stop here ? check with display team */
94 }
95
Arpita Banerjee0906ffd2013-05-24 16:25:38 -070096 ret = target_panel_clock(enable, pinfo);
Arpita Banerjee841fa062013-05-24 14:59:51 -070097
98 return ret;
99}
100
101static int mdss_dsi_panel_power(uint8_t enable)
102{
103 int ret = NO_ERROR;
104
105 if (enable) {
Dhaval Patel29f24492013-08-08 20:45:42 -0700106 ret = target_ldo_ctrl(enable);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700107 if (ret) {
108 dprintf(CRITICAL, "LDO control enable failed \n");
109 return ret;
110 }
111
112 /* Panel Reset */
113 ret = mdss_dsi_panel_reset(enable);
114 if (ret) {
115 dprintf(CRITICAL, "panel reset failed \n");
116 return ret;
117 }
118 dprintf(SPEW, "Panel power on done\n");
119 } else {
Casey Piper5fea4ba2013-09-11 16:23:18 -0700120 /* Disable panel and ldo */
Arpita Banerjee841fa062013-05-24 14:59:51 -0700121 ret = mdss_dsi_panel_reset(enable);
122 if (ret) {
123 dprintf(CRITICAL, "panel reset disable failed \n");
124 return ret;
125 }
126
Dhaval Patel29f24492013-08-08 20:45:42 -0700127 ret = target_ldo_ctrl(enable);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700128 if (ret) {
129 dprintf(CRITICAL, "ldo control disable failed \n");
130 return ret;
131 }
132 dprintf(SPEW, "Panel power off done\n");
133 }
134
135 return ret;
136}
137
Casey Piper5fea4ba2013-09-11 16:23:18 -0700138static int mdss_dsi_bl_enable(uint8_t enable)
139{
140 int ret = NO_ERROR;
141
142 ret = panel_backlight_ctrl(enable);
143 if (ret)
144 dprintf(CRITICAL, "Backlight %s failed\n", enable ? "enable" :
145 "disable");
146 return ret;
147}
148
Dhaval Patel9f61f132013-07-18 14:45:11 -0700149bool target_display_panel_node(char *pbuf, uint16_t buf_size)
150{
Casey Pipere165d1a2013-11-21 11:19:25 -0800151 char *dsi_id = NULL;
152 char *panel_node = NULL;
153 uint16_t dsi_id_len = 0;
154 bool ret = true;
Casey Piper13bd82a2013-11-15 12:26:17 -0800155 char *default_str;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700156
Casey Pipere165d1a2013-11-21 11:19:25 -0800157 if(panelstruct.paneldata)
158 {
159 dsi_id = panelstruct.paneldata->panel_controller;
160 panel_node = panelstruct.paneldata->panel_node_id;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700161 }
Casey Piper13bd82a2013-11-15 12:26:17 -0800162 else
163 {
164 if (target_is_edp())
165 {
166 default_str = "0:edp:";
167 }
168 else
169 {
170 default_str = "0:dsi:0:";
171 }
172 strlcpy(pbuf, default_str, buf_size);
173 return true;
174 }
Casey Piper9b7554e2013-10-08 18:37:18 -0700175
Casey Pipere165d1a2013-11-21 11:19:25 -0800176 if (dsi_id == NULL || panel_node == NULL)
177 return false;
Casey Piper9b7554e2013-10-08 18:37:18 -0700178
Casey Pipere165d1a2013-11-21 11:19:25 -0800179 dsi_id_len = strlen(dsi_id);
180
181 if (buf_size < (strlen(panel_node) + dsi_id_len +
182 MAX_PANEL_FORMAT_STRING + 1) ||
Casey Piperd1e5d8d2013-12-10 13:52:39 -0800183 !strlen(panel_node) ||
184 !strlen(dsi_id))
Casey Pipere165d1a2013-11-21 11:19:25 -0800185 {
186 ret = false;
187 }
188 else
Dhaval Patel9f61f132013-07-18 14:45:11 -0700189 {
190 pbuf[0] = '1'; // 1 indicates that LK is overriding the panel
191 pbuf[1] = ':'; // seperator
192 pbuf += MAX_PANEL_FORMAT_STRING;
193 buf_size -= MAX_PANEL_FORMAT_STRING;
194
195 strlcpy(pbuf, dsi_id, buf_size);
Casey Pipere165d1a2013-11-21 11:19:25 -0800196 pbuf += dsi_id_len;
197 buf_size -= dsi_id_len;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700198
199 strlcpy(pbuf, panel_node, buf_size);
Casey Piper9b7554e2013-10-08 18:37:18 -0700200 ret = true;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700201 }
202 return ret;
203}
204
205
Arpita Banerjee841fa062013-05-24 14:59:51 -0700206static void init_platform_data()
207{
208 memcpy(dsi_video_mode_phy_db.regulator, panel_regulator_settings,
209 REGULATOR_SIZE);
210 memcpy(dsi_video_mode_phy_db.ctrl, panel_physical_ctrl,
211 PHYSICAL_SIZE);
212 memcpy(dsi_video_mode_phy_db.strength, panel_strength_ctrl,
213 STRENGTH_SIZE);
214 memcpy(dsi_video_mode_phy_db.bistCtrl, panel_bist_ctrl, BIST_SIZE);
215 memcpy(dsi_video_mode_phy_db.laneCfg, panel_lane_config, LANE_SIZE);
216}
217
Casey Piper85653e52013-09-05 14:54:42 -0700218int gcdb_display_init(uint32_t rev, void *base)
Arpita Banerjee841fa062013-05-24 14:59:51 -0700219{
Casey Piper85653e52013-09-05 14:54:42 -0700220 int ret = NO_ERROR;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700221
222 if (!oem_panel_select(&panelstruct, &(panel.panel_info),
223 &dsi_video_mode_phy_db)) {
224 dprintf(CRITICAL, "Target panel init not found!\n");
Casey Piper85653e52013-09-05 14:54:42 -0700225 ret = ERR_NOT_SUPPORTED;
226 goto error_gcdb_display_init;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700227 }
Arpita Banerjee841fa062013-05-24 14:59:51 -0700228 init_platform_data();
229
230 if (dsi_panel_init(&(panel.panel_info), &panelstruct)) {
231 dprintf(CRITICAL, "DSI panel init failed!\n");
Casey Piper85653e52013-09-05 14:54:42 -0700232 ret = ERROR;
233 goto error_gcdb_display_init;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700234 }
235
236 panel.panel_info.mipi.mdss_dsi_phy_db = &dsi_video_mode_phy_db;
237
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -0700238 panel.pll_clk_func = mdss_dsi_panel_clock;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700239 panel.power_func = mdss_dsi_panel_power;
Casey Piper5fea4ba2013-09-11 16:23:18 -0700240 panel.bl_func = mdss_dsi_bl_enable;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700241 panel.fb.base = base;
242 panel.fb.width = panel.panel_info.xres;
243 panel.fb.height = panel.panel_info.yres;
244 panel.fb.stride = panel.panel_info.xres;
245 panel.fb.bpp = panel.panel_info.bpp;
246 panel.fb.format = panel.panel_info.mipi.dst_format;
247 panel.mdp_rev = rev;
248
Casey Piper85653e52013-09-05 14:54:42 -0700249 ret = msm_display_init(&panel);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700250
Casey Piper85653e52013-09-05 14:54:42 -0700251error_gcdb_display_init:
252 display_enable = ret ? 0 : 1;
253 return ret;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700254}
255
256void gcdb_display_shutdown(void)
257{
258 if (display_enable)
259 msm_display_off();
260}