blob: c6164f36326c8c1642dfed0586d9ea4c4d9a3181 [file] [log] [blame]
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -08001/* Copyright (c) 2012-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 are met:
5 * * Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * * Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 * * Neither the name of The Linux Foundation nor
11 * the names of its contributors may be used to endorse or promote
12 * products derived from this software without specific prior written
13 * permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <mdp5.h>
29#include <debug.h>
30#include <reg.h>
31#include <target/display.h>
32#include <platform/timer.h>
33#include <platform/iomap.h>
34#include <dev/lcdc.h>
35#include <dev/fbcon.h>
36#include <bits.h>
37#include <msm_panel.h>
38#include <mipi_dsi.h>
39#include <err.h>
40#include <clock.h>
41#include <mdp5.h>
Siddhartha Agrawal8d690822013-01-28 12:18:58 -080042#include <scm.h>
43
44int restore_secure_cfg(uint32_t id);
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -080045
46static int mdp_rev;
47
48void mdp_set_revision(int rev)
49{
50 mdp_rev = rev;
51}
52
53int mdp_get_revision()
54{
55 return mdp_rev;
56}
57
Siddhartha Agrawal1a87c5d2013-03-06 19:07:53 -080058uint32_t mdss_mdp_intf_offset()
59{
60 uint32_t mdss_mdp_intf_off;
61 uint32_t mdss_mdp_rev = readl(MDP_HW_REV);
62
63 if (mdss_mdp_rev > MDSS_MDP_HW_REV_100)
64 mdss_mdp_intf_off = 0;
65 else
66 mdss_mdp_intf_off = 0xEC00;
67
68 return mdss_mdp_intf_off;
69}
70
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -080071void mdp_clk_gating_ctrl(void)
72{
73 writel(0x40000000, MDP_CLK_CTRL0);
74 udelay(20);
75 writel(0x40000040, MDP_CLK_CTRL0);
76 writel(0x40000000, MDP_CLK_CTRL1);
77 writel(0x00400000, MDP_CLK_CTRL3);
78 udelay(20);
79 writel(0x00404000, MDP_CLK_CTRL3);
80 writel(0x40000000, MDP_CLK_CTRL4);
81}
82
Siddhartha Agrawald3893392013-06-11 15:32:19 -070083static void mdss_rgb_pipe_config(struct fbcon_config *fb, struct msm_panel_info
84 *pinfo, uint32_t pipe_base)
85{
86 uint32_t src_size, out_size, stride;
87
88 /* write active region size*/
89 src_size = (fb->height << 16) + fb->width;
90 out_size = src_size;
91
92 if (pinfo->lcdc.dual_pipe) {
93 out_size = (fb->height << 16) + (fb->width / 2);
94 }
95
96 stride = (fb->stride * fb->bpp/8);
97
98 writel(fb->base, pipe_base + PIPE_SSPP_SRC0_ADDR);
99 writel(stride, pipe_base + PIPE_SSPP_SRC_YSTRIDE);
100 writel(src_size, pipe_base + PIPE_SSPP_SRC_IMG_SIZE);
101 writel(out_size, pipe_base + PIPE_SSPP_SRC_SIZE);
102 writel(out_size, pipe_base + PIPE_SSPP_SRC_OUT_SIZE);
103 writel(0x00, pipe_base + PIPE_SSPP_SRC_XY);
104 writel(0x00, pipe_base + PIPE_SSPP_OUT_XY);
105
106 /* Tight Packing 3bpp 0-Alpha 8-bit R B G */
107 writel(0x0002243F, pipe_base + PIPE_SSPP_SRC_FORMAT);
108 writel(0x00020001, pipe_base + PIPE_SSPP_SRC_UNPACK_PATTERN);
109 writel(0x00, pipe_base + PIPE_SSPP_SRC_OP_MODE);
110}
111
Siddhartha Agrawal703153e2013-05-23 19:35:36 -0700112static void mdss_vbif_setup()
113{
114 int access_secure = restore_secure_cfg(SECURE_DEVICE_MDSS);
115
116 /* TZ returns an errornous ret val even if the VBIF registers were
117 * successfully unlocked. Ignore TZ return value till it's fixed */
118 if (!access_secure || 1) {
119 dprintf(SPEW, "MDSS VBIF registers unlocked by TZ.\n");
120
121 /* Force VBIF Clocks on */
122 writel(0x1, VBIF_VBIF_DDR_FORCE_CLK_ON);
123
124 if (readl(MDP_HW_REV) == MDSS_MDP_HW_REV_100) {
125 /* Configure DDR burst length */
126 writel(0x00000707, VBIF_VBIF_DDR_OUT_MAX_BURST);
127 writel(0x00000030, VBIF_VBIF_DDR_ARB_CTRL );
128 writel(0x00000001, VBIF_VBIF_DDR_RND_RBN_QOS_ARB);
129 writel(0x00000FFF, VBIF_VBIF_DDR_OUT_AOOO_AXI_EN);
130 writel(0x0FFF0FFF, VBIF_VBIF_DDR_OUT_AX_AOOO);
131 writel(0x22222222, VBIF_VBIF_DDR_AXI_AMEMTYPE_CONF0);
132 writel(0x00002222, VBIF_VBIF_DDR_AXI_AMEMTYPE_CONF1);
133 }
134 }
135}
136
Siddhartha Agrawal76574f82013-05-23 19:33:01 -0700137void mdss_smp_setup(struct msm_panel_info *pinfo)
138{
139 uint32_t smp_cnt = 0, reg_rgb0 = 0, reg_rgb1 = 0, shift = 0;
140 uint32_t xres, bpp;
141
142 xres = pinfo->xres;
143 bpp = pinfo->bpp;
144
145 if (pinfo->lcdc.dual_pipe) {
146 /* Each pipe driving half the screen */
147 xres /= 2;
148 }
149
150 smp_cnt = ((xres) * (bpp / 8) * 2) +
151 MMSS_MDP_MAX_SMP_SIZE - 1;
152
153 smp_cnt /= MMSS_MDP_MAX_SMP_SIZE;
154
155 if (smp_cnt > 4) {
156 dprintf(CRITICAL, "ERROR: %s: Out of SMP's, cnt=%d! \n", __func__,
157 smp_cnt);
158 ASSERT(0); /* Max 4 SMPs can be allocated per client */
159 }
160
161 writel(smp_cnt * 0x40, RGB0_REQPRIORITY_FIFO_WATERMARK0);
162 writel(smp_cnt * 0x80, RGB0_REQPRIORITY_FIFO_WATERMARK1);
163 writel(smp_cnt * 0xc0, RGB0_REQPRIORITY_FIFO_WATERMARK2);
164
165 if (pinfo->lcdc.dual_pipe) {
166 writel(smp_cnt * 0x40, RGB1_REQPRIORITY_FIFO_WATERMARK0);
167 writel(smp_cnt * 0x80, RGB1_REQPRIORITY_FIFO_WATERMARK1);
168 writel(smp_cnt * 0xc0, RGB1_REQPRIORITY_FIFO_WATERMARK2);
169 }
170
171 while((smp_cnt > 0) && !(shift > 16)) {
172 reg_rgb0 |= ((MMSS_MDP_CLIENT_ID_RGB0) << (shift));
173 reg_rgb1 |= ((MMSS_MDP_CLIENT_ID_RGB1) << (shift));
174 smp_cnt--;
175 shift += 8;
176 }
177
178 /* Allocate SMP blocks */
179 writel(reg_rgb0, MMSS_MDP_SMP_ALLOC_W_0);
180 writel(reg_rgb0, MMSS_MDP_SMP_ALLOC_R_0);
181
182 if (pinfo->lcdc.dual_pipe) {
183 writel(reg_rgb1, MMSS_MDP_SMP_ALLOC_W_1);
184 writel(reg_rgb1, MMSS_MDP_SMP_ALLOC_R_1);
185 }
186}
187
Siddhartha Agrawalf0b41a22013-05-23 20:32:20 -0700188void mdss_intf_tg_setup(struct msm_panel_info *pinfo, uint32_t intf_base)
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800189{
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800190 uint32_t hsync_period, vsync_period;
191 uint32_t hsync_start_x, hsync_end_x;
192 uint32_t display_hctl, active_hctl, hsync_ctl, display_vstart, display_vend;
Siddhartha Agrawalf0b41a22013-05-23 20:32:20 -0700193 uint32_t mdss_mdp_intf_off;
194
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800195 struct lcdc_panel_info *lcdc = NULL;
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800196
197 if (pinfo == NULL)
198 return ERR_INVALID_ARGS;
199
200 lcdc = &(pinfo->lcdc);
201 if (lcdc == NULL)
202 return ERR_INVALID_ARGS;
203
Siddhartha Agrawalf0b41a22013-05-23 20:32:20 -0700204 if (pinfo->lcdc.dual_pipe) {
205 if (intf_base == MDP_INTF_1_BASE) {
206 writel(BIT(8), MDP_TG_SINK);
207 writel(0x0, MDP_REG_SPLIT_DISPLAY_UPPER_PIPE_CTL);
208 writel(0x1, MDP_REG_SPLIT_DISPLAY_EN);
209 }
210 }
211
212 mdss_mdp_intf_off = intf_base + mdss_mdp_intf_offset();
213
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800214 hsync_period = lcdc->h_pulse_width +
215 lcdc->h_back_porch +
216 pinfo->xres + lcdc->xres_pad + lcdc->h_front_porch;
217 vsync_period = (lcdc->v_pulse_width +
218 lcdc->v_back_porch +
219 pinfo->yres + lcdc->yres_pad +
220 lcdc->v_front_porch);
221
222 hsync_start_x =
223 lcdc->h_pulse_width +
224 lcdc->h_back_porch;
225 hsync_end_x =
226 hsync_period - lcdc->h_front_porch - 1;
227
228 display_vstart = (lcdc->v_pulse_width +
229 lcdc->v_back_porch)
230 * hsync_period + lcdc->hsync_skew;
231 display_vend = ((vsync_period - lcdc->v_front_porch) * hsync_period)
232 +lcdc->hsync_skew - 1;
233
234 hsync_ctl = (hsync_period << 16) | lcdc->h_pulse_width;
235 display_hctl = (hsync_end_x << 16) | hsync_start_x;
236
Siddhartha Agrawalf0b41a22013-05-23 20:32:20 -0700237 writel(hsync_ctl, MDP_HSYNC_CTL + mdss_mdp_intf_off);
238 writel(vsync_period*hsync_period, MDP_VSYNC_PERIOD_F0 +
239 mdss_mdp_intf_off);
240 writel(0x00, MDP_VSYNC_PERIOD_F1 + mdss_mdp_intf_off);
241 writel(lcdc->v_pulse_width*hsync_period,
242 MDP_VSYNC_PULSE_WIDTH_F0 +
243 mdss_mdp_intf_off);
244 writel(0x00, MDP_VSYNC_PULSE_WIDTH_F1 + mdss_mdp_intf_off);
245 writel(display_hctl, MDP_DISPLAY_HCTL + mdss_mdp_intf_off);
246 writel(display_vstart, MDP_DISPLAY_V_START_F0 +
247 mdss_mdp_intf_off);
248 writel(0x00, MDP_DISPLAY_V_START_F1 + mdss_mdp_intf_off);
249 writel(display_vend, MDP_DISPLAY_V_END_F0 +
250 mdss_mdp_intf_off);
251 writel(0x00, MDP_DISPLAY_V_END_F1 + mdss_mdp_intf_off);
252 writel(0x00, MDP_ACTIVE_HCTL + mdss_mdp_intf_off);
253 writel(0x00, MDP_ACTIVE_V_START_F0 + mdss_mdp_intf_off);
254 writel(0x00, MDP_ACTIVE_V_START_F1 + mdss_mdp_intf_off);
255 writel(0x00, MDP_ACTIVE_V_END_F0 + mdss_mdp_intf_off);
256 writel(0x00, MDP_ACTIVE_V_END_F1 + mdss_mdp_intf_off);
257 writel(0xFF, MDP_UNDERFFLOW_COLOR + mdss_mdp_intf_off);
258
259 writel(0x213F, MDP_PANEL_FORMAT + mdss_mdp_intf_off);
260
261}
262
263int mdp_dsi_video_config(struct msm_panel_info *pinfo,
264 struct fbcon_config *fb)
265{
266 int ret = NO_ERROR;
267 struct lcdc_panel_info *lcdc = NULL;
268 unsigned mdp_rgb_size;
269 uint32_t intf_sel = 0x100;
270
271 mdss_intf_tg_setup(pinfo, MDP_INTF_1_BASE);
272
273 if (pinfo->mipi.dual_dsi)
274 mdss_intf_tg_setup(pinfo, MDP_INTF_2_BASE);
Siddhartha Agrawal1a87c5d2013-03-06 19:07:53 -0800275
Siddhartha Agrawal703153e2013-05-23 19:35:36 -0700276 /* write active region size*/
277 mdp_rgb_size = (fb->height << 16) | fb->width;
Siddhartha Agrawal8d690822013-01-28 12:18:58 -0800278
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800279 mdp_clk_gating_ctrl();
280
Siddhartha Agrawal703153e2013-05-23 19:35:36 -0700281 mdss_vbif_setup();
Siddhartha Agrawal76574f82013-05-23 19:33:01 -0700282 mdss_smp_setup(pinfo);
Siddhartha Agrawalb1b5a1f2013-04-17 19:53:41 -0700283
284 writel(0x0E9, MDP_QOS_REMAPPER_CLASS_0);
285
Siddhartha Agrawald3893392013-06-11 15:32:19 -0700286 mdss_rgb_pipe_config(fb, pinfo, MDP_VP_0_RGB_0_BASE);
287 if (pinfo->lcdc.dual_pipe)
288 mdss_rgb_pipe_config(fb, pinfo, MDP_VP_0_RGB_1_BASE);
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800289
290 writel(mdp_rgb_size,MDP_VP_0_LAYER_0_OUT_SIZE);
291 writel(0x00, MDP_VP_0_LAYER_0_OP_MODE);
292 writel(0x100, MDP_VP_0_LAYER_0_BLEND_OP);
293 writel(0xFF, MDP_VP_0_LAYER_0_BLEND0_FG_ALPHA);
294 writel(0x100, MDP_VP_0_LAYER_1_BLEND_OP);
295 writel(0xFF, MDP_VP_0_LAYER_1_BLEND0_FG_ALPHA);
296 writel(0x100, MDP_VP_0_LAYER_2_BLEND_OP);
297 writel(0xFF, MDP_VP_0_LAYER_2_BLEND0_FG_ALPHA);
298 writel(0x100, MDP_VP_0_LAYER_3_BLEND_OP);
299 writel(0xFF, MDP_VP_0_LAYER_3_BLEND0_FG_ALPHA);
300
301 /* Baselayer for layer mixer 0 */
302 writel(0x010000200, MDP_CTL_0_LAYER_0);
303
304 writel(0x1F20, MDP_CTL_0_TOP);
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800305
Siddhartha Agrawalf0b41a22013-05-23 20:32:20 -0700306 if (pinfo->mipi.dual_dsi)
307 intf_sel |= BIT(16); /* INTF 2 enable */
308
309 writel(intf_sel, MDP_DISP_INTF_SEL);
310
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800311 writel(0x1111, MDP_VIDEO_INTF_UNDERFLOW_CTL);
312 writel(0x01, MDP_UPPER_NEW_ROI_PRIOR_RO_START);
313 writel(0x01, MDP_LOWER_NEW_ROI_PRIOR_TO_START);
314
315 return 0;
316}
317
318int mdp_dsi_cmd_config(struct msm_panel_info *pinfo,
319 struct fbcon_config *fb)
320{
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700321 int ret = NO_ERROR;
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800322
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700323 struct lcdc_panel_info *lcdc = NULL;
324 uint32_t mdp_rgb_size;
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700325 uint32_t mdss_mdp_intf_off = 0;
326
327 if (pinfo == NULL)
328 return ERR_INVALID_ARGS;
329
330 lcdc = &(pinfo->lcdc);
331 if (lcdc == NULL)
332 return ERR_INVALID_ARGS;
333
334 mdss_mdp_intf_off = mdss_mdp_intf_offset();
335 /* write active region size*/
336 mdp_rgb_size = (fb->height << 16) + fb->width;
337
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700338 mdp_clk_gating_ctrl();
339
340 writel(0x0100, MDP_DISP_INTF_SEL);
341
Siddhartha Agrawal703153e2013-05-23 19:35:36 -0700342 mdss_vbif_setup();
Siddhartha Agrawal76574f82013-05-23 19:33:01 -0700343 mdss_smp_setup(pinfo);
Siddhartha Agrawald3893392013-06-11 15:32:19 -0700344 mdss_rgb_pipe_config(fb, pinfo, MDP_VP_0_RGB_0_BASE);
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700345
346 writel(mdp_rgb_size,MDP_VP_0_LAYER_0_OUT_SIZE);
347 writel(0x00, MDP_VP_0_LAYER_0_OP_MODE);
348 writel(0x100, MDP_VP_0_LAYER_0_BLEND_OP);
349 writel(0xFF, MDP_VP_0_LAYER_0_BLEND0_FG_ALPHA);
350 writel(0x100, MDP_VP_0_LAYER_1_BLEND_OP);
351 writel(0xFF, MDP_VP_0_LAYER_1_BLEND0_FG_ALPHA);
352 writel(0x100, MDP_VP_0_LAYER_2_BLEND_OP);
353 writel(0xFF, MDP_VP_0_LAYER_2_BLEND0_FG_ALPHA);
354 writel(0x100, MDP_VP_0_LAYER_3_BLEND_OP);
355 writel(0xFF, MDP_VP_0_LAYER_3_BLEND0_FG_ALPHA);
356
357 /* Baselayer for layer mixer 0 */
358 writel(0x00000200, MDP_CTL_0_LAYER_0);
359
Siddhartha Agrawalf0b41a22013-05-23 20:32:20 -0700360 writel(0x213F, MDP_INTF_1_BASE + MDP_PANEL_FORMAT + mdss_mdp_intf_off);
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700361
362 writel(0x20020, MDP_CTL_0_TOP);
363
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800364 return ret;
365}
366
367int mdp_dsi_video_on(void)
368{
369 int ret = NO_ERROR;
370 writel(0x32048, MDP_CTL_0_FLUSH);
Siddhartha Agrawal1a87c5d2013-03-06 19:07:53 -0800371 writel(0x01, MDP_INTF_1_TIMING_ENGINE_EN + mdss_mdp_intf_offset());
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800372 return ret;
373}
374
375int mdp_dsi_video_off()
376{
377 if(!target_cont_splash_screen())
378 {
Siddhartha Agrawal1a87c5d2013-03-06 19:07:53 -0800379 writel(0x00000000, MDP_INTF_1_TIMING_ENGINE_EN +
380 mdss_mdp_intf_offset());
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800381 mdelay(60);
382 /* Ping-Pong done Tear Check Read/Write */
383 /* Underrun(Interface 0/1/2/3) VSYNC Interrupt Enable */
384 writel(0xFF777713, MDP_INTR_CLEAR);
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800385 }
386
Siddhartha Agrawal6a598222013-02-17 18:33:27 -0800387 writel(0x00000000, MDP_INTR_EN);
388
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800389 return NO_ERROR;
390}
391
392int mdp_dsi_cmd_off()
393{
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700394 if(!target_cont_splash_screen())
395 {
396 /* Ping-Pong done Tear Check Read/Write */
397 /* Underrun(Interface 0/1/2/3) VSYNC Interrupt Enable */
398 writel(0xFF777713, MDP_INTR_CLEAR);
399 }
400 writel(0x00000000, MDP_INTR_EN);
401
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800402 return NO_ERROR;
403}
404
405int mdp_dma_on(void)
406{
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700407 writel(0x32048, MDP_CTL_0_FLUSH);
408 writel(0x01, MDP_CTL_0_START);
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800409 return NO_ERROR;
410}
411
412void mdp_disable(void)
413{
414
415}