blob: 9c5e15ce0b8486261866bd579286d9fd422b0184 [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;
145 uint16_t dsi_id_len = 0;
146 bool ret = true;
Casey Piper13bd82a2013-11-15 12:26:17 -0800147 char *default_str;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700148
Casey Pipere165d1a2013-11-21 11:19:25 -0800149 if(panelstruct.paneldata)
150 {
151 dsi_id = panelstruct.paneldata->panel_controller;
152 panel_node = panelstruct.paneldata->panel_node_id;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700153 }
Casey Piper13bd82a2013-11-15 12:26:17 -0800154 else
155 {
156 if (target_is_edp())
157 {
Siddhartha Agrawalf67b3ff2013-10-23 18:08:04 -0700158 default_str = "1:edp:";
Casey Piper13bd82a2013-11-15 12:26:17 -0800159 }
160 else
161 {
162 default_str = "0:dsi:0:";
163 }
164 strlcpy(pbuf, default_str, buf_size);
165 return true;
166 }
Casey Piper9b7554e2013-10-08 18:37:18 -0700167
Casey Pipere165d1a2013-11-21 11:19:25 -0800168 if (dsi_id == NULL || panel_node == NULL)
169 return false;
Casey Piper9b7554e2013-10-08 18:37:18 -0700170
Casey Pipere165d1a2013-11-21 11:19:25 -0800171 dsi_id_len = strlen(dsi_id);
172
173 if (buf_size < (strlen(panel_node) + dsi_id_len +
174 MAX_PANEL_FORMAT_STRING + 1) ||
Casey Piperd1e5d8d2013-12-10 13:52:39 -0800175 !strlen(panel_node) ||
176 !strlen(dsi_id))
Casey Pipere165d1a2013-11-21 11:19:25 -0800177 {
178 ret = false;
179 }
180 else
Dhaval Patel9f61f132013-07-18 14:45:11 -0700181 {
182 pbuf[0] = '1'; // 1 indicates that LK is overriding the panel
183 pbuf[1] = ':'; // seperator
184 pbuf += MAX_PANEL_FORMAT_STRING;
185 buf_size -= MAX_PANEL_FORMAT_STRING;
186
187 strlcpy(pbuf, dsi_id, buf_size);
Casey Pipere165d1a2013-11-21 11:19:25 -0800188 pbuf += dsi_id_len;
189 buf_size -= dsi_id_len;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700190
191 strlcpy(pbuf, panel_node, buf_size);
Casey Piper9b7554e2013-10-08 18:37:18 -0700192 ret = true;
Dhaval Patel9f61f132013-07-18 14:45:11 -0700193 }
194 return ret;
195}
196
197
Arpita Banerjee841fa062013-05-24 14:59:51 -0700198static void init_platform_data()
199{
200 memcpy(dsi_video_mode_phy_db.regulator, panel_regulator_settings,
201 REGULATOR_SIZE);
202 memcpy(dsi_video_mode_phy_db.ctrl, panel_physical_ctrl,
203 PHYSICAL_SIZE);
204 memcpy(dsi_video_mode_phy_db.strength, panel_strength_ctrl,
205 STRENGTH_SIZE);
206 memcpy(dsi_video_mode_phy_db.bistCtrl, panel_bist_ctrl, BIST_SIZE);
207 memcpy(dsi_video_mode_phy_db.laneCfg, panel_lane_config, LANE_SIZE);
208}
209
Casey Piper85653e52013-09-05 14:54:42 -0700210int gcdb_display_init(uint32_t rev, void *base)
Arpita Banerjee841fa062013-05-24 14:59:51 -0700211{
Casey Piper85653e52013-09-05 14:54:42 -0700212 int ret = NO_ERROR;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700213
214 if (!oem_panel_select(&panelstruct, &(panel.panel_info),
215 &dsi_video_mode_phy_db)) {
216 dprintf(CRITICAL, "Target panel init not found!\n");
Casey Piper85653e52013-09-05 14:54:42 -0700217 ret = ERR_NOT_SUPPORTED;
218 goto error_gcdb_display_init;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700219 }
Arpita Banerjee841fa062013-05-24 14:59:51 -0700220 init_platform_data();
221
222 if (dsi_panel_init(&(panel.panel_info), &panelstruct)) {
223 dprintf(CRITICAL, "DSI panel init failed!\n");
Casey Piper85653e52013-09-05 14:54:42 -0700224 ret = ERROR;
225 goto error_gcdb_display_init;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700226 }
227
228 panel.panel_info.mipi.mdss_dsi_phy_db = &dsi_video_mode_phy_db;
229
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -0700230 panel.pll_clk_func = mdss_dsi_panel_clock;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700231 panel.power_func = mdss_dsi_panel_power;
Casey Piper5fea4ba2013-09-11 16:23:18 -0700232 panel.bl_func = mdss_dsi_bl_enable;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700233 panel.fb.base = base;
234 panel.fb.width = panel.panel_info.xres;
235 panel.fb.height = panel.panel_info.yres;
236 panel.fb.stride = panel.panel_info.xres;
237 panel.fb.bpp = panel.panel_info.bpp;
238 panel.fb.format = panel.panel_info.mipi.dst_format;
239 panel.mdp_rev = rev;
240
Casey Piper85653e52013-09-05 14:54:42 -0700241 ret = msm_display_init(&panel);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700242
Casey Piper85653e52013-09-05 14:54:42 -0700243error_gcdb_display_init:
244 display_enable = ret ? 0 : 1;
245 return ret;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700246}
247
248void gcdb_display_shutdown(void)
249{
250 if (display_enable)
251 msm_display_off();
252}