blob: 5333656a1519dee9f5e6851a171036dd7ad1334a [file] [log] [blame]
Krishna Manikandanb415cc12018-08-14 14:10:04 +05301/* Copyright (c) 2011-2015, 2017-2018, The Linux Foundation. All rights reserved.
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +05302 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * 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
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
Padmanabhan Komandurufa4be752012-10-08 16:51:56 +053012 * * Neither the name of The Linux Foundation, Inc. nor the names of its
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +053013 * 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 "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29#include <mdp3.h>
30#include <debug.h>
31#include <reg.h>
Channagoud Kadabi539ef722012-03-29 16:02:50 +053032#include <msm_panel.h>
33#include <err.h>
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +053034#include <target/display.h>
35#include <platform/timer.h>
36#include <platform/iomap.h>
37
Sachin Bhayare5e5f32a2015-10-07 11:47:19 +053038#define BIT(bit) (1 << (bit))
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070039static int mdp_rev;
40
Sachin Bhayare5e5f32a2015-10-07 11:47:19 +053041/**
42 * mdp3_get_panic_lut_cfg() - calculate panic and robust lut mask
43 * @panel_width: Panel width
44 *
45 * DMA buffer has 16 fill levels. Which needs to configured as safe
46 * and panic levels based on panel resolutions.
47 * No. of fill levels used = ((panel active width * 8) / 512).
48 * Roundoff the use fill levels if needed.
49 * half of the total fill levels used will be treated as panic levels.
50 * Roundoff panic levels if total used fill levels are odd.
51 *
52 * Sample calculation for 720p display:
53 * Fill levels used = (720 * 8) / 512 = 12.5 after round off 13.
54 * panic levels = 13 / 2 = 6.5 after roundoff 7.
55 * Panic mask = 0x3FFF (2 bits per level)
56 * Robust mask = 0xFF80 (1 bit per level)
57 */
58unsigned long long mdp3_get_panic_lut_cfg(int panel_width)
59{
60 unsigned int fill_levels = (((panel_width * 8) / 512) + 1);
61 unsigned int panic_mask = 0;
62 unsigned int robust_mask = 0;
63 int i = 0;
64 unsigned long long panic_config = 0;
65 int panic_levels = 0;
66
67 panic_levels = fill_levels/2;
68 if (fill_levels % 2)
69 panic_levels++;
70 for (i = 0; i < panic_levels; i++) {
71 panic_mask |= (BIT((i * 2) + 1) | BIT(i * 2));
72 robust_mask |= BIT(i);
73 }
74 panic_config = (~robust_mask);
75 panic_config = panic_config << 32;
76 panic_config |= panic_mask;
77 return panic_config;
78}
79
Channagoud Kadabi539ef722012-03-29 16:02:50 +053080int mdp_dsi_video_config(struct msm_panel_info *pinfo,
81 struct fbcon_config *fb)
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +053082{
Ajay Dudanib01e5062011-12-03 23:23:42 -080083 unsigned long hsync_period;
84 unsigned long vsync_period;
85 unsigned long vsync_period_intmd;
Channagoud Kadabi539ef722012-03-29 16:02:50 +053086 struct lcdc_panel_info *lcdc = NULL;
87 int ystride = 3;
Terence Hampson7385f6a2013-08-16 15:31:25 -040088 int mdp_rev = mdp_get_revision();
Sachin Bhayare5e5f32a2015-10-07 11:47:19 +053089 unsigned long long panic_config = mdp3_get_panic_lut_cfg(pinfo->xres);
Channagoud Kadabi539ef722012-03-29 16:02:50 +053090
91 if (pinfo == NULL)
92 return ERR_INVALID_ARGS;
93
94 lcdc = &(pinfo->lcdc);
95 if (lcdc == NULL)
96 return ERR_INVALID_ARGS;
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +053097
Ajay Dudanib01e5062011-12-03 23:23:42 -080098 dprintf(SPEW, "MDP3.0.3 for DSI Video Mode\n");
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +053099
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530100 hsync_period = pinfo->xres + lcdc->h_front_porch + \
101 lcdc->h_back_porch + 1;
102 vsync_period_intmd = pinfo->yres + lcdc->v_front_porch + \
103 lcdc->v_back_porch + 1;
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530104 if (mdp_rev == MDP_REV_304 || mdp_rev == MDP_REV_305) {
Terence Hampson7385f6a2013-08-16 15:31:25 -0400105 hsync_period += lcdc->h_pulse_width - 1;
106 vsync_period_intmd += lcdc->v_pulse_width - 1;
107 }
Ajay Dudanib01e5062011-12-03 23:23:42 -0800108 vsync_period = vsync_period_intmd * hsync_period;
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530109
Sandeep Panda09fd9782014-12-26 10:32:01 +0530110 /* Program QOS remapper settings */
111 writel(0x1A9, MDP_DMA_P_QOS_REMAPPER);
112 writel(0x0, MDP_DMA_P_WATERMARK_0);
113 writel(0x0, MDP_DMA_P_WATERMARK_1);
114 writel(0x0, MDP_DMA_P_WATERMARK_2);
Sandeep Panda09fd9782014-12-26 10:32:01 +0530115
Sachin Bhayare5e5f32a2015-10-07 11:47:19 +0530116 writel((panic_config & 0xFFFF), MDP_PANIC_LUT0);
117 writel(((panic_config >> 16) & 0xFFFF) , MDP_PANIC_LUT1);
118 writel(((panic_config >> 32) & 0xFFFF), MDP_ROBUST_LUT);
119 writel(0x1, MDP_PANIC_ROBUST_CTRL);
120 dprintf(INFO, "Panic Lut0 %x Lut1 %x Robest %x\n",
121 (panic_config & 0xFFFF), ((panic_config >> 16) & 0xFFFF),
122 ((panic_config >> 32) & 0xFFFF));
Ajay Dudanib01e5062011-12-03 23:23:42 -0800123 // ------------- programming MDP_DMA_P_CONFIG ---------------------
124 writel(0x1800bf, MDP_DMA_P_CONFIG); // rgb888
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530125
Ajay Dudanib01e5062011-12-03 23:23:42 -0800126 writel(0x00000000, MDP_DMA_P_OUT_XY);
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530127 writel(pinfo->yres << 16 | pinfo->xres, MDP_DMA_P_SIZE);
Nirmal Abrahambc36a0b2017-06-06 17:41:31 +0530128 writel((uint32_t)fb->base, MDP_DMA_P_BUF_ADDR);
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530129 writel(pinfo->xres * ystride, MDP_DMA_P_BUF_Y_STRIDE);
130 writel(hsync_period << 16 | lcdc->h_pulse_width, \
131 MDP_DSI_VIDEO_HSYNC_CTL);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800132 writel(vsync_period, MDP_DSI_VIDEO_VSYNC_PERIOD);
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530133 writel(lcdc->v_pulse_width * hsync_period, \
134 MDP_DSI_VIDEO_VSYNC_PULSE_WIDTH);
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530135 if (mdp_rev == MDP_REV_304 || mdp_rev == MDP_REV_305) {
Terence Hampson7385f6a2013-08-16 15:31:25 -0400136 writel((pinfo->xres + lcdc->h_back_porch + \
137 lcdc->h_pulse_width - 1) << 16 | \
138 lcdc->h_back_porch + lcdc->h_pulse_width, \
139 MDP_DSI_VIDEO_DISPLAY_HCTL);
140 writel((lcdc->v_back_porch + lcdc->v_pulse_width) \
141 * hsync_period, MDP_DSI_VIDEO_DISPLAY_V_START);
142 writel(vsync_period - lcdc->v_front_porch * hsync_period - 1,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800143 MDP_DSI_VIDEO_DISPLAY_V_END);
Terence Hampson7385f6a2013-08-16 15:31:25 -0400144 } else {
145 writel((pinfo->xres + lcdc->h_back_porch - 1) << 16 | \
146 lcdc->h_back_porch, MDP_DSI_VIDEO_DISPLAY_HCTL);
147 writel(lcdc->v_back_porch * hsync_period, \
148 MDP_DSI_VIDEO_DISPLAY_V_START);
149 writel((pinfo->yres + lcdc->v_back_porch) * hsync_period,
150 MDP_DSI_VIDEO_DISPLAY_V_END);
151 }
Ajay Dudanib01e5062011-12-03 23:23:42 -0800152 writel(0x00ABCDEF, MDP_DSI_VIDEO_BORDER_CLR);
153 writel(0x00000000, MDP_DSI_VIDEO_HSYNC_SKEW);
154 writel(0x00000000, MDP_DSI_VIDEO_CTL_POLARITY);
Krishna Manikandanb415cc12018-08-14 14:10:04 +0530155 writel(0x70000000, MDP_DSI_VIDEO_TEST_CTL);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800156 // end of cmd mdp
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530157
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530158 return 0;
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530159}
Ajay Dudanib01e5062011-12-03 23:23:42 -0800160
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530161int mdp_dsi_cmd_config(struct msm_panel_info *pinfo,
162 struct fbcon_config *fb)
163{
164 int ret = 0;
165 unsigned short pack_pattern = 0x21;
166 unsigned char ystride = 3;
Sachin Bhayare0f15bea2017-02-16 12:58:58 +0530167 unsigned int sync_cfg;
Sachin Bhayare5e5f32a2015-10-07 11:47:19 +0530168 unsigned long long panic_config = 0;
Sachin Bhayare0f15bea2017-02-16 12:58:58 +0530169 const uint32_t vsync_hz = 19200000; /* Vsync Clock 19.2 HMz */
170 /* Auto refresh fps = Panel fps / frame num */
171 /* Auto refresh frame num = 60/10 = 6fps */
172 const uint32_t autorefresh_framenum = 10;
Sachin Bhayare5e5f32a2015-10-07 11:47:19 +0530173
174 if (pinfo == NULL)
175 return ERR_INVALID_ARGS;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530176
Sandeep Panda09fd9782014-12-26 10:32:01 +0530177 /* Program QOS remapper settings */
178 writel(0x1A9, MDP_DMA_P_QOS_REMAPPER);
179 writel(0x0, MDP_DMA_P_WATERMARK_0);
180 writel(0x0, MDP_DMA_P_WATERMARK_1);
181 writel(0x0, MDP_DMA_P_WATERMARK_2);
Sachin Bhayare5e5f32a2015-10-07 11:47:19 +0530182
183 panic_config = mdp3_get_panic_lut_cfg(pinfo->xres);
184 writel((panic_config & 0xFFFF), MDP_PANIC_LUT0);
185 writel(((panic_config >> 16) & 0xFFFF) , MDP_PANIC_LUT1);
186 writel(((panic_config >> 32) & 0xFFFF), MDP_ROBUST_LUT);
Sandeep Panda09fd9782014-12-26 10:32:01 +0530187 writel(0x1, MDP_PANIC_ROBUST_CTRL);
Sachin Bhayare5e5f32a2015-10-07 11:47:19 +0530188 dprintf(INFO, "Panic Lut0 %x Lut1 %x Robest %x\n",
189 (panic_config & 0xFFFF), ((panic_config >> 16) & 0xFFFF),
190 ((panic_config >> 32) & 0xFFFF));
Sandeep Panda09fd9782014-12-26 10:32:01 +0530191
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530192 writel(0x03ffffff, MDP_INTR_ENABLE);
193
194 // ------------- programming MDP_DMA_P_CONFIG ---------------------
Sachin Bhayare0f15bea2017-02-16 12:58:58 +0530195 writel(pack_pattern << 8 | 0x3f | (0 << 25)| (1 << 19) | (1 << 7) ,
196 MDP_DMA_P_CONFIG); /* rgb888 */
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530197 writel(0x00000000, MDP_DMA_P_OUT_XY);
198 writel(pinfo->yres << 16 | pinfo->xres, MDP_DMA_P_SIZE);
Nirmal Abrahambc36a0b2017-06-06 17:41:31 +0530199 writel((uint32_t)fb->base, MDP_DMA_P_BUF_ADDR);
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530200
201 writel(pinfo->xres * ystride, MDP_DMA_P_BUF_Y_STRIDE);
202
203 writel(0x10, MDP_DSI_CMD_MODE_ID_MAP);
204 writel(0x11, MDP_DSI_CMD_MODE_TRIGGER_EN);
Sachin Bhayare0f15bea2017-02-16 12:58:58 +0530205 /* Enable Auto refresh */
206 sync_cfg = (pinfo->yres - 1) << 21;
207 sync_cfg |= BIT(19);
208
209 sync_cfg |= vsync_hz / (pinfo->yres * 60);
210 writel(sync_cfg, MDP_SYNC_CONFIG_0);
211 writel((BIT(28) | autorefresh_framenum),
212 MDP_AUTOREFRESH_CONFIG_P);
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530213 mdelay(10);
214
215 return ret;
216}
217
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530218void mdp_disable(void)
219{
Channagoud Kadabif2488462012-06-12 15:22:48 +0530220 if (!target_cont_splash_screen())
221 writel(0x00000000, MDP_DSI_VIDEO_EN);
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530222}
223
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530224int mdp_dsi_video_off(void)
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530225{
Channagoud Kadabif2488462012-06-12 15:22:48 +0530226 if (!target_cont_splash_screen()) {
227 mdp_disable();
228 mdelay(60);
Channagoud Kadabif2488462012-06-12 15:22:48 +0530229 }
Padmanabhan Komandurufa4be752012-10-08 16:51:56 +0530230 writel(0x00000000, MDP_INTR_ENABLE);
231 writel(0x01ffffff, MDP_INTR_CLEAR);
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530232 return NO_ERROR;
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530233}
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700234
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530235int mdp_dsi_cmd_off(void)
236{
Channagoud Kadabif2488462012-06-12 15:22:48 +0530237 if (!target_cont_splash_screen()) {
238 mdp_dma_off();
239 /*
240 * Allow sometime for the DMA channel to
241 * stop the data transfer
242 */
243 mdelay(10);
Channagoud Kadabif2488462012-06-12 15:22:48 +0530244 }
Sachin Bhayare0f15bea2017-02-16 12:58:58 +0530245 /* Disable Auto refresh */
246 if (readl(MDP_AUTOREFRESH_CONFIG_P))
247 writel(0, MDP_AUTOREFRESH_CONFIG_P);
Padmanabhan Komandurufa4be752012-10-08 16:51:56 +0530248 writel(0x00000000, MDP_INTR_ENABLE);
249 writel(0x01ffffff, MDP_INTR_CLEAR);
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530250 return NO_ERROR;
251}
252
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700253void mdp_set_revision(int rev)
254{
255 mdp_rev = rev;
256}
257
258int mdp_get_revision(void)
259{
260 return mdp_rev;
261}
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530262
Jayant Shekhar32397f92014-03-27 13:30:41 +0530263int mdp_dsi_video_on(struct msm_panel_info *pinfo)
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530264{
265 int ret = 0;
266
267 writel(0x00000001, MDP_DSI_VIDEO_EN);
268
269 return ret;
270}
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530271
Jayant Shekhar32397f92014-03-27 13:30:41 +0530272int mdp_dma_on(struct msm_panel_info *pinfo)
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530273{
274 int ret = 0;
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400275 mdelay(100);
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530276 writel(0x00000001, MDP_DMA_P_START);
277
278 return ret;
279}
280
281int mdp_dma_off()
282{
283 int ret = 0;
284
Channagoud Kadabif2488462012-06-12 15:22:48 +0530285 if (!target_cont_splash_screen())
286 writel(0x00000000, MDP_DMA_P_START);
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530287
288 return ret;
289}
Asaf Penso6c58a6b2013-07-14 19:57:29 +0300290
291int mdp_edp_config(struct msm_panel_info *pinfo, struct fbcon_config *fb)
292{
293 return NO_ERROR;
294}
295
Jayant Shekhar32397f92014-03-27 13:30:41 +0530296int mdp_edp_on(struct msm_panel_info *pinfo)
Asaf Penso6c58a6b2013-07-14 19:57:29 +0300297{
298 return NO_ERROR;
299}
300
301int mdp_edp_off(void)
302{
303 return NO_ERROR;
304}
Ajay Singh Parmar63c18502014-07-23 23:37:19 -0700305
Ajay Singh Parmar243d82b2014-07-23 23:01:44 -0700306int mdss_hdmi_config(struct msm_panel_info *pinfo, struct fbcon_config *fb)
Ajay Singh Parmar63c18502014-07-23 23:37:19 -0700307{
308 return NO_ERROR;
309}
310
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -0800311int mdss_hdmi_on(struct msm_panel_info *pinfo)
Ajay Singh Parmar63c18502014-07-23 23:37:19 -0700312{
313 return NO_ERROR;
314}
315
Ajay Singh Parmar243d82b2014-07-23 23:01:44 -0700316int mdss_hdmi_off(void)
Ajay Singh Parmar63c18502014-07-23 23:37:19 -0700317{
318 return NO_ERROR;
319}