blob: b2b4bc58b180559ff411bd1b3d233ed485db9d42 [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;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700155
Casey Pipere165d1a2013-11-21 11:19:25 -0800156 if(panelstruct.paneldata)
157 {
158 dsi_id = panelstruct.paneldata->panel_controller;
159 panel_node = panelstruct.paneldata->panel_node_id;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700160 }
Casey Piper9b7554e2013-10-08 18:37:18 -0700161
Casey Pipere165d1a2013-11-21 11:19:25 -0800162 if (dsi_id == NULL || panel_node == NULL)
163 return false;
Casey Piper9b7554e2013-10-08 18:37:18 -0700164
Casey Pipere165d1a2013-11-21 11:19:25 -0800165 dsi_id_len = strlen(dsi_id);
166
167 if (buf_size < (strlen(panel_node) + dsi_id_len +
168 MAX_PANEL_FORMAT_STRING + 1) ||
169 strlen(panel_node) ||
170 strlen(dsi_id))
171 {
172 ret = false;
173 }
174 else
Dhaval Patel9f61f132013-07-18 14:45:11 -0700175 {
176 pbuf[0] = '1'; // 1 indicates that LK is overriding the panel
177 pbuf[1] = ':'; // seperator
178 pbuf += MAX_PANEL_FORMAT_STRING;
179 buf_size -= MAX_PANEL_FORMAT_STRING;
180
181 strlcpy(pbuf, dsi_id, buf_size);
Casey Pipere165d1a2013-11-21 11:19:25 -0800182 pbuf += dsi_id_len;
183 buf_size -= dsi_id_len;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700184
185 strlcpy(pbuf, panel_node, buf_size);
Casey Piper9b7554e2013-10-08 18:37:18 -0700186 ret = true;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700187 }
188 return ret;
189}
190
191
Arpita Banerjee841fa062013-05-24 14:59:51 -0700192static void init_platform_data()
193{
194 memcpy(dsi_video_mode_phy_db.regulator, panel_regulator_settings,
195 REGULATOR_SIZE);
196 memcpy(dsi_video_mode_phy_db.ctrl, panel_physical_ctrl,
197 PHYSICAL_SIZE);
198 memcpy(dsi_video_mode_phy_db.strength, panel_strength_ctrl,
199 STRENGTH_SIZE);
200 memcpy(dsi_video_mode_phy_db.bistCtrl, panel_bist_ctrl, BIST_SIZE);
201 memcpy(dsi_video_mode_phy_db.laneCfg, panel_lane_config, LANE_SIZE);
202}
203
Casey Piper85653e52013-09-05 14:54:42 -0700204int gcdb_display_init(uint32_t rev, void *base)
Arpita Banerjee841fa062013-05-24 14:59:51 -0700205{
Casey Piper85653e52013-09-05 14:54:42 -0700206 int ret = NO_ERROR;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700207
208 if (!oem_panel_select(&panelstruct, &(panel.panel_info),
209 &dsi_video_mode_phy_db)) {
210 dprintf(CRITICAL, "Target panel init not found!\n");
Casey Piper85653e52013-09-05 14:54:42 -0700211 ret = ERR_NOT_SUPPORTED;
212 goto error_gcdb_display_init;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700213 }
Arpita Banerjee841fa062013-05-24 14:59:51 -0700214 init_platform_data();
215
216 if (dsi_panel_init(&(panel.panel_info), &panelstruct)) {
217 dprintf(CRITICAL, "DSI panel init failed!\n");
Casey Piper85653e52013-09-05 14:54:42 -0700218 ret = ERROR;
219 goto error_gcdb_display_init;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700220 }
221
222 panel.panel_info.mipi.mdss_dsi_phy_db = &dsi_video_mode_phy_db;
223
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -0700224 panel.pll_clk_func = mdss_dsi_panel_clock;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700225 panel.power_func = mdss_dsi_panel_power;
Casey Piper5fea4ba2013-09-11 16:23:18 -0700226 panel.bl_func = mdss_dsi_bl_enable;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700227 panel.fb.base = base;
228 panel.fb.width = panel.panel_info.xres;
229 panel.fb.height = panel.panel_info.yres;
230 panel.fb.stride = panel.panel_info.xres;
231 panel.fb.bpp = panel.panel_info.bpp;
232 panel.fb.format = panel.panel_info.mipi.dst_format;
233 panel.mdp_rev = rev;
234
Casey Piper85653e52013-09-05 14:54:42 -0700235 ret = msm_display_init(&panel);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700236
Casey Piper85653e52013-09-05 14:54:42 -0700237error_gcdb_display_init:
238 display_enable = ret ? 0 : 1;
239 return ret;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700240}
241
242void gcdb_display_shutdown(void)
243{
244 if (display_enable)
245 msm_display_off();
246}