blob: 169fb1c660218170af47151b0d3e19f68d6969ca [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>
34#include <board.h>
35#include <mdp5.h>
36#include <platform/gpio.h>
37#include <mipi_dsi.h>
38
39#include "include/display_resource.h"
40#include "include/panel.h"
41#include "panel_display.h"
42#include "gcdb_display.h"
43#include "target/display.h"
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -070044#include "gcdb_autopll.h"
Arpita Banerjee841fa062013-05-24 14:59:51 -070045
46/*---------------------------------------------------------------------------*/
47/* static */
48/*---------------------------------------------------------------------------*/
49static struct msm_fb_panel_data panel;
50struct panel_struct panelstruct;
51static uint8_t display_enable;
52static struct mdss_dsi_phy_ctrl dsi_video_mode_phy_db;
53
54
55/*---------------------------------------------------------------------------*/
56/* Extern */
57/*---------------------------------------------------------------------------*/
58extern int msm_display_init(struct msm_fb_panel_data *pdata);
59extern int msm_display_off();
60
rayz3c988f02013-08-13 18:06:39 +080061/* TODO: add other backlight type support */
Arpita Banerjee841fa062013-05-24 14:59:51 -070062static uint32_t panel_backlight_ctrl(uint8_t enable)
63{
64 uint32_t ret = NO_ERROR;
65
rayz3c988f02013-08-13 18:06:39 +080066 if (panelstruct.backlightinfo->bl_pmic_controltype != BL_DCS) {
67 /* deal with non-dcs backlight */
68 ret = target_backlight_ctrl(enable);
69 }
Arpita Banerjee841fa062013-05-24 14:59:51 -070070
71 return ret;
72}
73
74static uint32_t mdss_dsi_panel_reset(uint8_t enable)
75{
76 uint32_t ret = NO_ERROR;
77
78 ret = target_panel_reset(enable, &reset_gpio,
79 &enable_gpio, &reset_sequence);
80
81 return ret;
82}
83
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -070084static uint32_t mdss_dsi_panel_clock(uint8_t enable,
85 struct msm_panel_info *pinfo)
Arpita Banerjee841fa062013-05-24 14:59:51 -070086{
87 uint32_t ret = NO_ERROR;
88
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -070089 ret = calculate_clock_config(pinfo);
90 if (ret) {
91 dprintf(CRITICAL, "Clock calculation failed \n");
92 /* should it stop here ? check with display team */
93 }
94
Arpita Banerjee0906ffd2013-05-24 16:25:38 -070095 ret = target_panel_clock(enable, pinfo);
Arpita Banerjee841fa062013-05-24 14:59:51 -070096
97 return ret;
98}
99
100static int mdss_dsi_panel_power(uint8_t enable)
101{
102 int ret = NO_ERROR;
103
104 if (enable) {
105
106 /* Enable backlight */
107 ret = panel_backlight_ctrl(enable);
108 if (ret) {
109 dprintf(CRITICAL, "Backlight enable failed \n");
110 return ret;
111 }
112 ret = target_ldo_ctrl(enable, ldo_entry_array,
113 TOTAL_LDO_DEFINED);
114 if (ret) {
115 dprintf(CRITICAL, "LDO control enable failed \n");
116 return ret;
117 }
118
119 /* Panel Reset */
120 ret = mdss_dsi_panel_reset(enable);
121 if (ret) {
122 dprintf(CRITICAL, "panel reset failed \n");
123 return ret;
124 }
125 dprintf(SPEW, "Panel power on done\n");
126 } else {
127 /* Disable panel, backlight and ldo */
128 ret = mdss_dsi_panel_reset(enable);
129 if (ret) {
130 dprintf(CRITICAL, "panel reset disable failed \n");
131 return ret;
132 }
133
134 ret = panel_backlight_ctrl(enable);
135 if (ret) {
136 dprintf(CRITICAL, "Backlight disable failed \n");
137 return ret;
138 }
139
140 ret = target_ldo_ctrl(enable, ldo_entry_array,
141 TOTAL_LDO_DEFINED);
142 if (ret) {
143 dprintf(CRITICAL, "ldo control disable failed \n");
144 return ret;
145 }
146 dprintf(SPEW, "Panel power off done\n");
147 }
148
149 return ret;
150}
151
152static void init_platform_data()
153{
154 memcpy(dsi_video_mode_phy_db.regulator, panel_regulator_settings,
155 REGULATOR_SIZE);
156 memcpy(dsi_video_mode_phy_db.ctrl, panel_physical_ctrl,
157 PHYSICAL_SIZE);
158 memcpy(dsi_video_mode_phy_db.strength, panel_strength_ctrl,
159 STRENGTH_SIZE);
160 memcpy(dsi_video_mode_phy_db.bistCtrl, panel_bist_ctrl, BIST_SIZE);
161 memcpy(dsi_video_mode_phy_db.laneCfg, panel_lane_config, LANE_SIZE);
162}
163
164void gcdb_display_init(uint32_t rev, void *base)
165{
166
167 if (!oem_panel_select(&panelstruct, &(panel.panel_info),
168 &dsi_video_mode_phy_db)) {
169 dprintf(CRITICAL, "Target panel init not found!\n");
170 return;
171 }
172
173 init_platform_data();
174
175 if (dsi_panel_init(&(panel.panel_info), &panelstruct)) {
176 dprintf(CRITICAL, "DSI panel init failed!\n");
177 return;
178 }
179
180 panel.panel_info.mipi.mdss_dsi_phy_db = &dsi_video_mode_phy_db;
181
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -0700182 panel.pll_clk_func = mdss_dsi_panel_clock;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700183 panel.power_func = mdss_dsi_panel_power;
184 panel.fb.base = base;
185 panel.fb.width = panel.panel_info.xres;
186 panel.fb.height = panel.panel_info.yres;
187 panel.fb.stride = panel.panel_info.xres;
188 panel.fb.bpp = panel.panel_info.bpp;
189 panel.fb.format = panel.panel_info.mipi.dst_format;
190 panel.mdp_rev = rev;
191
192 if (msm_display_init(&panel)) {
193 dprintf(CRITICAL, "Display init failed!\n");
194 return;
195 }
196
197 display_enable = 1;
198}
199
200void gcdb_display_shutdown(void)
201{
202 if (display_enable)
203 msm_display_off();
204}