blob: 6d4835edf16ad89cc06b7ed924355d6c37eaa5ac [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 Agrawal76574f82013-05-23 19:33:01 -0700112void mdss_smp_setup(struct msm_panel_info *pinfo)
113{
114 uint32_t smp_cnt = 0, reg_rgb0 = 0, reg_rgb1 = 0, shift = 0;
115 uint32_t xres, bpp;
116
117 xres = pinfo->xres;
118 bpp = pinfo->bpp;
119
120 if (pinfo->lcdc.dual_pipe) {
121 /* Each pipe driving half the screen */
122 xres /= 2;
123 }
124
125 smp_cnt = ((xres) * (bpp / 8) * 2) +
126 MMSS_MDP_MAX_SMP_SIZE - 1;
127
128 smp_cnt /= MMSS_MDP_MAX_SMP_SIZE;
129
130 if (smp_cnt > 4) {
131 dprintf(CRITICAL, "ERROR: %s: Out of SMP's, cnt=%d! \n", __func__,
132 smp_cnt);
133 ASSERT(0); /* Max 4 SMPs can be allocated per client */
134 }
135
136 writel(smp_cnt * 0x40, RGB0_REQPRIORITY_FIFO_WATERMARK0);
137 writel(smp_cnt * 0x80, RGB0_REQPRIORITY_FIFO_WATERMARK1);
138 writel(smp_cnt * 0xc0, RGB0_REQPRIORITY_FIFO_WATERMARK2);
139
140 if (pinfo->lcdc.dual_pipe) {
141 writel(smp_cnt * 0x40, RGB1_REQPRIORITY_FIFO_WATERMARK0);
142 writel(smp_cnt * 0x80, RGB1_REQPRIORITY_FIFO_WATERMARK1);
143 writel(smp_cnt * 0xc0, RGB1_REQPRIORITY_FIFO_WATERMARK2);
144 }
145
146 while((smp_cnt > 0) && !(shift > 16)) {
147 reg_rgb0 |= ((MMSS_MDP_CLIENT_ID_RGB0) << (shift));
148 reg_rgb1 |= ((MMSS_MDP_CLIENT_ID_RGB1) << (shift));
149 smp_cnt--;
150 shift += 8;
151 }
152
153 /* Allocate SMP blocks */
154 writel(reg_rgb0, MMSS_MDP_SMP_ALLOC_W_0);
155 writel(reg_rgb0, MMSS_MDP_SMP_ALLOC_R_0);
156
157 if (pinfo->lcdc.dual_pipe) {
158 writel(reg_rgb1, MMSS_MDP_SMP_ALLOC_W_1);
159 writel(reg_rgb1, MMSS_MDP_SMP_ALLOC_R_1);
160 }
161}
162
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800163int mdp_dsi_video_config(struct msm_panel_info *pinfo,
164 struct fbcon_config *fb)
165{
166 int ret = NO_ERROR;
167 uint32_t hsync_period, vsync_period;
168 uint32_t hsync_start_x, hsync_end_x;
169 uint32_t display_hctl, active_hctl, hsync_ctl, display_vstart, display_vend;
170 struct lcdc_panel_info *lcdc = NULL;
171 unsigned mdp_rgb_size;
Siddhartha Agrawal8d690822013-01-28 12:18:58 -0800172 int access_secure = 0;
Siddhartha Agrawal1a87c5d2013-03-06 19:07:53 -0800173 uint32_t mdss_mdp_intf_off = 0;
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800174
175 if (pinfo == NULL)
176 return ERR_INVALID_ARGS;
177
178 lcdc = &(pinfo->lcdc);
179 if (lcdc == NULL)
180 return ERR_INVALID_ARGS;
181
182 hsync_period = lcdc->h_pulse_width +
183 lcdc->h_back_porch +
184 pinfo->xres + lcdc->xres_pad + lcdc->h_front_porch;
185 vsync_period = (lcdc->v_pulse_width +
186 lcdc->v_back_porch +
187 pinfo->yres + lcdc->yres_pad +
188 lcdc->v_front_porch);
189
190 hsync_start_x =
191 lcdc->h_pulse_width +
192 lcdc->h_back_porch;
193 hsync_end_x =
194 hsync_period - lcdc->h_front_porch - 1;
195
196 display_vstart = (lcdc->v_pulse_width +
197 lcdc->v_back_porch)
198 * hsync_period + lcdc->hsync_skew;
199 display_vend = ((vsync_period - lcdc->v_front_porch) * hsync_period)
200 +lcdc->hsync_skew - 1;
201
202 hsync_ctl = (hsync_period << 16) | lcdc->h_pulse_width;
203 display_hctl = (hsync_end_x << 16) | hsync_start_x;
204
Siddhartha Agrawal1a87c5d2013-03-06 19:07:53 -0800205 mdss_mdp_intf_off = mdss_mdp_intf_offset();
206
Siddhartha Agrawal8d690822013-01-28 12:18:58 -0800207 access_secure = restore_secure_cfg(SECURE_DEVICE_MDSS);
208
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800209 mdp_clk_gating_ctrl();
210
Siddhartha Agrawalf058d622013-01-28 16:21:03 -0800211 /* Ignore TZ return value till it's fixed */
212 if (!access_secure || 1) {
Siddhartha Agrawal61af9b02013-04-12 12:43:14 -0700213
Siddhartha Agrawal8d690822013-01-28 12:18:58 -0800214 /* Force VBIF Clocks on */
215 writel(0x1, VBIF_VBIF_DDR_FORCE_CLK_ON);
Siddhartha Agrawal61af9b02013-04-12 12:43:14 -0700216
217 if (readl(MDP_HW_REV) == MDSS_MDP_HW_REV_100) {
218 /* Configure DDR burst length */
219 writel(0x00000707, VBIF_VBIF_DDR_OUT_MAX_BURST);
220 writel(0x00000030, VBIF_VBIF_DDR_ARB_CTRL );
221 writel(0x00000001, VBIF_VBIF_DDR_RND_RBN_QOS_ARB);
222 writel(0x00000FFF, VBIF_VBIF_DDR_OUT_AOOO_AXI_EN);
223 writel(0x0FFF0FFF, VBIF_VBIF_DDR_OUT_AX_AOOO);
224 writel(0x22222222, VBIF_VBIF_DDR_AXI_AMEMTYPE_CONF0);
225 writel(0x00002222, VBIF_VBIF_DDR_AXI_AMEMTYPE_CONF1);
226 }
Siddhartha Agrawal8d690822013-01-28 12:18:58 -0800227 }
228
Siddhartha Agrawal76574f82013-05-23 19:33:01 -0700229 mdss_smp_setup(pinfo);
Siddhartha Agrawalb1b5a1f2013-04-17 19:53:41 -0700230
231 writel(0x0E9, MDP_QOS_REMAPPER_CLASS_0);
232
Siddhartha Agrawal1a87c5d2013-03-06 19:07:53 -0800233 writel(hsync_ctl, MDP_INTF_1_HSYNC_CTL + mdss_mdp_intf_off);
234 writel(vsync_period*hsync_period, MDP_INTF_1_VSYNC_PERIOD_F0 +
235 mdss_mdp_intf_off);
236 writel(0x00, MDP_INTF_1_VSYNC_PERIOD_F1 + mdss_mdp_intf_off);
237 writel(lcdc->v_pulse_width*hsync_period,
238 MDP_INTF_1_VSYNC_PULSE_WIDTH_F0 +
239 mdss_mdp_intf_off);
240 writel(0x00, MDP_INTF_1_VSYNC_PULSE_WIDTH_F1 + mdss_mdp_intf_off);
241 writel(display_hctl, MDP_INTF_1_DISPLAY_HCTL + mdss_mdp_intf_off);
242 writel(display_vstart, MDP_INTF_1_DISPLAY_V_START_F0 +
243 mdss_mdp_intf_off);
244 writel(0x00, MDP_INTF_1_DISPLAY_V_START_F1 + mdss_mdp_intf_off);
245 writel(display_vend, MDP_INTF_1_DISPLAY_V_END_F0 +
246 mdss_mdp_intf_off);
247 writel(0x00, MDP_INTF_1_DISPLAY_V_END_F1 + mdss_mdp_intf_off);
248 writel(0x00, MDP_INTF_1_ACTIVE_HCTL + mdss_mdp_intf_off);
249 writel(0x00, MDP_INTF_1_ACTIVE_V_START_F0 + mdss_mdp_intf_off);
250 writel(0x00, MDP_INTF_1_ACTIVE_V_START_F1 + mdss_mdp_intf_off);
251 writel(0x00, MDP_INTF_1_ACTIVE_V_END_F0 + mdss_mdp_intf_off);
252 writel(0x00, MDP_INTF_1_ACTIVE_V_END_F1 + mdss_mdp_intf_off);
253 writel(0xFF, MDP_INTF_1_UNDERFFLOW_COLOR + mdss_mdp_intf_off);
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800254
Siddhartha Agrawald3893392013-06-11 15:32:19 -0700255 mdss_rgb_pipe_config(fb, pinfo, MDP_VP_0_RGB_0_BASE);
256 if (pinfo->lcdc.dual_pipe)
257 mdss_rgb_pipe_config(fb, pinfo, MDP_VP_0_RGB_1_BASE);
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800258
259 writel(mdp_rgb_size,MDP_VP_0_LAYER_0_OUT_SIZE);
260 writel(0x00, MDP_VP_0_LAYER_0_OP_MODE);
261 writel(0x100, MDP_VP_0_LAYER_0_BLEND_OP);
262 writel(0xFF, MDP_VP_0_LAYER_0_BLEND0_FG_ALPHA);
263 writel(0x100, MDP_VP_0_LAYER_1_BLEND_OP);
264 writel(0xFF, MDP_VP_0_LAYER_1_BLEND0_FG_ALPHA);
265 writel(0x100, MDP_VP_0_LAYER_2_BLEND_OP);
266 writel(0xFF, MDP_VP_0_LAYER_2_BLEND0_FG_ALPHA);
267 writel(0x100, MDP_VP_0_LAYER_3_BLEND_OP);
268 writel(0xFF, MDP_VP_0_LAYER_3_BLEND0_FG_ALPHA);
269
270 /* Baselayer for layer mixer 0 */
271 writel(0x010000200, MDP_CTL_0_LAYER_0);
272
273 writel(0x1F20, MDP_CTL_0_TOP);
Siddhartha Agrawal1a87c5d2013-03-06 19:07:53 -0800274 writel(0x213F, MDP_INTF_1_PANEL_FORMAT + mdss_mdp_intf_off);
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800275
276 writel(0x0100, MDP_DISP_INTF_SEL);
277 writel(0x1111, MDP_VIDEO_INTF_UNDERFLOW_CTL);
278 writel(0x01, MDP_UPPER_NEW_ROI_PRIOR_RO_START);
279 writel(0x01, MDP_LOWER_NEW_ROI_PRIOR_TO_START);
280
281 return 0;
282}
283
284int mdp_dsi_cmd_config(struct msm_panel_info *pinfo,
285 struct fbcon_config *fb)
286{
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700287 int ret = NO_ERROR;
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800288
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700289 struct lcdc_panel_info *lcdc = NULL;
290 uint32_t mdp_rgb_size;
291 int access_secure = 0;
292 uint32_t mdss_mdp_intf_off = 0;
293
294 if (pinfo == NULL)
295 return ERR_INVALID_ARGS;
296
297 lcdc = &(pinfo->lcdc);
298 if (lcdc == NULL)
299 return ERR_INVALID_ARGS;
300
301 mdss_mdp_intf_off = mdss_mdp_intf_offset();
302 /* write active region size*/
303 mdp_rgb_size = (fb->height << 16) + fb->width;
304
305 access_secure = restore_secure_cfg(SECURE_DEVICE_MDSS);
306
307 mdp_clk_gating_ctrl();
308
309 writel(0x0100, MDP_DISP_INTF_SEL);
310
311 /* Ignore TZ return value till it's fixed */
312 if (!access_secure || 1) {
313 /* Force VBIF Clocks on */
314 writel(0x1, VBIF_VBIF_DDR_FORCE_CLK_ON);
315 /* Configure DDR burst length */
316 writel(0x00000707, VBIF_VBIF_DDR_OUT_MAX_BURST);
317 writel(0x00000030, VBIF_VBIF_DDR_ARB_CTRL );
318 writel(0x00000001, VBIF_VBIF_DDR_RND_RBN_QOS_ARB);
319 writel(0x00000FFF, VBIF_VBIF_DDR_OUT_AOOO_AXI_EN);
320 writel(0x0FFF0FFF, VBIF_VBIF_DDR_OUT_AX_AOOO);
321 writel(0x22222222, VBIF_VBIF_DDR_AXI_AMEMTYPE_CONF0);
322 writel(0x00002222, VBIF_VBIF_DDR_AXI_AMEMTYPE_CONF1);
323 }
324
Siddhartha Agrawal76574f82013-05-23 19:33:01 -0700325 mdss_smp_setup(pinfo);
Siddhartha Agrawald3893392013-06-11 15:32:19 -0700326 mdss_rgb_pipe_config(fb, pinfo, MDP_VP_0_RGB_0_BASE);
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700327
328 writel(mdp_rgb_size,MDP_VP_0_LAYER_0_OUT_SIZE);
329 writel(0x00, MDP_VP_0_LAYER_0_OP_MODE);
330 writel(0x100, MDP_VP_0_LAYER_0_BLEND_OP);
331 writel(0xFF, MDP_VP_0_LAYER_0_BLEND0_FG_ALPHA);
332 writel(0x100, MDP_VP_0_LAYER_1_BLEND_OP);
333 writel(0xFF, MDP_VP_0_LAYER_1_BLEND0_FG_ALPHA);
334 writel(0x100, MDP_VP_0_LAYER_2_BLEND_OP);
335 writel(0xFF, MDP_VP_0_LAYER_2_BLEND0_FG_ALPHA);
336 writel(0x100, MDP_VP_0_LAYER_3_BLEND_OP);
337 writel(0xFF, MDP_VP_0_LAYER_3_BLEND0_FG_ALPHA);
338
339 /* Baselayer for layer mixer 0 */
340 writel(0x00000200, MDP_CTL_0_LAYER_0);
341
342 writel(0x213F, MDP_INTF_1_PANEL_FORMAT + mdss_mdp_intf_off);
343
344 writel(0x20020, MDP_CTL_0_TOP);
345
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800346 return ret;
347}
348
349int mdp_dsi_video_on(void)
350{
351 int ret = NO_ERROR;
352 writel(0x32048, MDP_CTL_0_FLUSH);
Siddhartha Agrawal1a87c5d2013-03-06 19:07:53 -0800353 writel(0x01, MDP_INTF_1_TIMING_ENGINE_EN + mdss_mdp_intf_offset());
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800354 return ret;
355}
356
357int mdp_dsi_video_off()
358{
359 if(!target_cont_splash_screen())
360 {
Siddhartha Agrawal1a87c5d2013-03-06 19:07:53 -0800361 writel(0x00000000, MDP_INTF_1_TIMING_ENGINE_EN +
362 mdss_mdp_intf_offset());
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800363 mdelay(60);
364 /* Ping-Pong done Tear Check Read/Write */
365 /* Underrun(Interface 0/1/2/3) VSYNC Interrupt Enable */
366 writel(0xFF777713, MDP_INTR_CLEAR);
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800367 }
368
Siddhartha Agrawal6a598222013-02-17 18:33:27 -0800369 writel(0x00000000, MDP_INTR_EN);
370
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800371 return NO_ERROR;
372}
373
374int mdp_dsi_cmd_off()
375{
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700376 if(!target_cont_splash_screen())
377 {
378 /* Ping-Pong done Tear Check Read/Write */
379 /* Underrun(Interface 0/1/2/3) VSYNC Interrupt Enable */
380 writel(0xFF777713, MDP_INTR_CLEAR);
381 }
382 writel(0x00000000, MDP_INTR_EN);
383
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800384 return NO_ERROR;
385}
386
387int mdp_dma_on(void)
388{
Siddhartha Agrawal7dc3aa92013-04-21 16:04:26 -0700389 writel(0x32048, MDP_CTL_0_FLUSH);
390 writel(0x01, MDP_CTL_0_START);
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -0800391 return NO_ERROR;
392}
393
394void mdp_disable(void)
395{
396
397}