Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 1 | /* 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 Patel | 9f61f13 | 2013-07-18 14:45:11 -0700 | [diff] [blame] | 34 | #include <string.h> |
| 35 | #include <stdlib.h> |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 36 | #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 Banerjee | da0c39a | 2013-05-24 16:12:45 -0700 | [diff] [blame] | 46 | #include "gcdb_autopll.h" |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 47 | |
| 48 | /*---------------------------------------------------------------------------*/ |
| 49 | /* static */ |
| 50 | /*---------------------------------------------------------------------------*/ |
| 51 | static struct msm_fb_panel_data panel; |
| 52 | struct panel_struct panelstruct; |
| 53 | static uint8_t display_enable; |
| 54 | static struct mdss_dsi_phy_ctrl dsi_video_mode_phy_db; |
| 55 | |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 56 | /*---------------------------------------------------------------------------*/ |
| 57 | /* Extern */ |
| 58 | /*---------------------------------------------------------------------------*/ |
| 59 | extern int msm_display_init(struct msm_fb_panel_data *pdata); |
| 60 | extern int msm_display_off(); |
| 61 | |
rayz | 3c988f0 | 2013-08-13 18:06:39 +0800 | [diff] [blame] | 62 | /* TODO: add other backlight type support */ |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 63 | static uint32_t panel_backlight_ctrl(uint8_t enable) |
| 64 | { |
| 65 | uint32_t ret = NO_ERROR; |
| 66 | |
rayz | 3c988f0 | 2013-08-13 18:06:39 +0800 | [diff] [blame] | 67 | if (panelstruct.backlightinfo->bl_pmic_controltype != BL_DCS) { |
| 68 | /* deal with non-dcs backlight */ |
| 69 | ret = target_backlight_ctrl(enable); |
| 70 | } |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 71 | |
| 72 | return ret; |
| 73 | } |
| 74 | |
| 75 | static uint32_t mdss_dsi_panel_reset(uint8_t enable) |
| 76 | { |
| 77 | uint32_t ret = NO_ERROR; |
| 78 | |
Dhaval Patel | 29f2449 | 2013-08-08 20:45:42 -0700 | [diff] [blame] | 79 | ret = target_panel_reset(enable, panelstruct.panelresetseq, |
| 80 | &panel.panel_info); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 81 | |
| 82 | return ret; |
| 83 | } |
| 84 | |
Arpita Banerjee | da0c39a | 2013-05-24 16:12:45 -0700 | [diff] [blame] | 85 | static uint32_t mdss_dsi_panel_clock(uint8_t enable, |
| 86 | struct msm_panel_info *pinfo) |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 87 | { |
| 88 | uint32_t ret = NO_ERROR; |
| 89 | |
Arpita Banerjee | da0c39a | 2013-05-24 16:12:45 -0700 | [diff] [blame] | 90 | 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 Banerjee | 0906ffd | 2013-05-24 16:25:38 -0700 | [diff] [blame] | 96 | ret = target_panel_clock(enable, pinfo); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 97 | |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | static int mdss_dsi_panel_power(uint8_t enable) |
| 102 | { |
| 103 | int ret = NO_ERROR; |
| 104 | |
| 105 | if (enable) { |
Dhaval Patel | 29f2449 | 2013-08-08 20:45:42 -0700 | [diff] [blame] | 106 | ret = target_ldo_ctrl(enable); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 107 | 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 Piper | 5fea4ba | 2013-09-11 16:23:18 -0700 | [diff] [blame] | 120 | /* Disable panel and ldo */ |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 121 | ret = mdss_dsi_panel_reset(enable); |
| 122 | if (ret) { |
| 123 | dprintf(CRITICAL, "panel reset disable failed \n"); |
| 124 | return ret; |
| 125 | } |
| 126 | |
Dhaval Patel | 29f2449 | 2013-08-08 20:45:42 -0700 | [diff] [blame] | 127 | ret = target_ldo_ctrl(enable); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 128 | 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 Piper | 5fea4ba | 2013-09-11 16:23:18 -0700 | [diff] [blame] | 138 | static 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 Patel | 9f61f13 | 2013-07-18 14:45:11 -0700 | [diff] [blame] | 149 | bool target_display_panel_node(char *pbuf, uint16_t buf_size) |
| 150 | { |
Casey Piper | e165d1a | 2013-11-21 11:19:25 -0800 | [diff] [blame^] | 151 | char *dsi_id = NULL; |
| 152 | char *panel_node = NULL; |
| 153 | uint16_t dsi_id_len = 0; |
| 154 | bool ret = true; |
Dhaval Patel | 9f61f13 | 2013-07-18 14:45:11 -0700 | [diff] [blame] | 155 | |
Casey Piper | e165d1a | 2013-11-21 11:19:25 -0800 | [diff] [blame^] | 156 | if(panelstruct.paneldata) |
| 157 | { |
| 158 | dsi_id = panelstruct.paneldata->panel_controller; |
| 159 | panel_node = panelstruct.paneldata->panel_node_id; |
Dhaval Patel | 9f61f13 | 2013-07-18 14:45:11 -0700 | [diff] [blame] | 160 | } |
Casey Piper | 9b7554e | 2013-10-08 18:37:18 -0700 | [diff] [blame] | 161 | |
Casey Piper | e165d1a | 2013-11-21 11:19:25 -0800 | [diff] [blame^] | 162 | if (dsi_id == NULL || panel_node == NULL) |
| 163 | return false; |
Casey Piper | 9b7554e | 2013-10-08 18:37:18 -0700 | [diff] [blame] | 164 | |
Casey Piper | e165d1a | 2013-11-21 11:19:25 -0800 | [diff] [blame^] | 165 | 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 Patel | 9f61f13 | 2013-07-18 14:45:11 -0700 | [diff] [blame] | 175 | { |
| 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 Piper | e165d1a | 2013-11-21 11:19:25 -0800 | [diff] [blame^] | 182 | pbuf += dsi_id_len; |
| 183 | buf_size -= dsi_id_len; |
Dhaval Patel | 9f61f13 | 2013-07-18 14:45:11 -0700 | [diff] [blame] | 184 | |
| 185 | strlcpy(pbuf, panel_node, buf_size); |
Casey Piper | 9b7554e | 2013-10-08 18:37:18 -0700 | [diff] [blame] | 186 | ret = true; |
Dhaval Patel | 9f61f13 | 2013-07-18 14:45:11 -0700 | [diff] [blame] | 187 | } |
| 188 | return ret; |
| 189 | } |
| 190 | |
| 191 | |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 192 | static 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 Piper | 85653e5 | 2013-09-05 14:54:42 -0700 | [diff] [blame] | 204 | int gcdb_display_init(uint32_t rev, void *base) |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 205 | { |
Casey Piper | 85653e5 | 2013-09-05 14:54:42 -0700 | [diff] [blame] | 206 | int ret = NO_ERROR; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 207 | |
| 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 Piper | 85653e5 | 2013-09-05 14:54:42 -0700 | [diff] [blame] | 211 | ret = ERR_NOT_SUPPORTED; |
| 212 | goto error_gcdb_display_init; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 213 | } |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 214 | init_platform_data(); |
| 215 | |
| 216 | if (dsi_panel_init(&(panel.panel_info), &panelstruct)) { |
| 217 | dprintf(CRITICAL, "DSI panel init failed!\n"); |
Casey Piper | 85653e5 | 2013-09-05 14:54:42 -0700 | [diff] [blame] | 218 | ret = ERROR; |
| 219 | goto error_gcdb_display_init; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | panel.panel_info.mipi.mdss_dsi_phy_db = &dsi_video_mode_phy_db; |
| 223 | |
Arpita Banerjee | da0c39a | 2013-05-24 16:12:45 -0700 | [diff] [blame] | 224 | panel.pll_clk_func = mdss_dsi_panel_clock; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 225 | panel.power_func = mdss_dsi_panel_power; |
Casey Piper | 5fea4ba | 2013-09-11 16:23:18 -0700 | [diff] [blame] | 226 | panel.bl_func = mdss_dsi_bl_enable; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 227 | 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 Piper | 85653e5 | 2013-09-05 14:54:42 -0700 | [diff] [blame] | 235 | ret = msm_display_init(&panel); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 236 | |
Casey Piper | 85653e5 | 2013-09-05 14:54:42 -0700 | [diff] [blame] | 237 | error_gcdb_display_init: |
| 238 | display_enable = ret ? 0 : 1; |
| 239 | return ret; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void gcdb_display_shutdown(void) |
| 243 | { |
| 244 | if (display_enable) |
| 245 | msm_display_off(); |
| 246 | } |