blob: 334842a3b52736e6c252e153a6f0af6ecd6991da [file] [log] [blame]
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001/*
2 * linux/drivers/video/omap2/dss/dispc.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#define DSS_SUBSYS_NAME "DISPC"
24
25#include <linux/kernel.h>
26#include <linux/dma-mapping.h>
27#include <linux/vmalloc.h>
Paul Gortmakera8a35932011-07-10 13:20:26 -040028#include <linux/export.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020029#include <linux/clk.h>
30#include <linux/io.h>
31#include <linux/jiffies.h>
32#include <linux/seq_file.h>
33#include <linux/delay.h>
34#include <linux/workqueue.h>
Tomi Valkeinenab83b142010-06-09 15:31:01 +030035#include <linux/hardirq.h>
archit tanejaaffe3602011-02-23 08:41:03 +000036#include <linux/interrupt.h>
Tomi Valkeinen24e62892011-05-23 11:51:18 +030037#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030038#include <linux/pm_runtime.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020039
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030040#include <video/omapdss.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020041
42#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053043#include "dss_features.h"
Archit Taneja9b372c22011-05-06 11:45:49 +053044#include "dispc.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020045
46/* DISPC */
Sumit Semwal8613b002010-12-02 11:27:09 +000047#define DISPC_SZ_REGS SZ_4K
Tomi Valkeinen80c39712009-11-12 11:41:42 +020048
Tomi Valkeinen80c39712009-11-12 11:41:42 +020049#define DISPC_IRQ_MASK_ERROR (DISPC_IRQ_GFX_FIFO_UNDERFLOW | \
50 DISPC_IRQ_OCP_ERR | \
51 DISPC_IRQ_VID1_FIFO_UNDERFLOW | \
52 DISPC_IRQ_VID2_FIFO_UNDERFLOW | \
53 DISPC_IRQ_SYNC_LOST | \
54 DISPC_IRQ_SYNC_LOST_DIGIT)
55
56#define DISPC_MAX_NR_ISRS 8
57
58struct omap_dispc_isr_data {
59 omap_dispc_isr_t isr;
60 void *arg;
61 u32 mask;
62};
63
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030064enum omap_burst_size {
65 BURST_SIZE_X2 = 0,
66 BURST_SIZE_X4 = 1,
67 BURST_SIZE_X8 = 2,
68};
69
Tomi Valkeinen80c39712009-11-12 11:41:42 +020070#define REG_GET(idx, start, end) \
71 FLD_GET(dispc_read_reg(idx), start, end)
72
73#define REG_FLD_MOD(idx, val, start, end) \
74 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
75
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +020076struct dispc_irq_stats {
77 unsigned long last_reset;
78 unsigned irq_count;
79 unsigned irqs[32];
80};
81
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053082struct dispc_features {
83 u8 sw_start;
84 u8 fp_start;
85 u8 bp_start;
86 u16 sw_max;
87 u16 vp_max;
88 u16 hp_max;
89 int (*calc_scaling) (enum omap_channel channel,
90 const struct omap_video_timings *mgr_timings,
91 u16 width, u16 height, u16 out_width, u16 out_height,
92 enum omap_color_mode color_mode, bool *five_taps,
93 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
94 u16 pos_x, unsigned long *core_clk);
95 unsigned long (*calc_core_clk) (enum omap_channel channel,
96 u16 width, u16 height, u16 out_width, u16 out_height);
Tomi Valkeinen42a69612012-08-22 16:56:57 +030097 u8 num_fifos;
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +030098
99 /* swap GFX & WB fifos */
100 bool gfx_fifo_workaround:1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530101};
102
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300103#define DISPC_MAX_NR_FIFOS 5
104
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200105static struct {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +0000106 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200107 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300108
109 int ctx_loss_cnt;
110
archit tanejaaffe3602011-02-23 08:41:03 +0000111 int irq;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300112 struct clk *dss_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200113
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300114 u32 fifo_size[DISPC_MAX_NR_FIFOS];
115 /* maps which plane is using a fifo. fifo-id -> plane-id */
116 int fifo_assignment[DISPC_MAX_NR_FIFOS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200117
118 spinlock_t irq_lock;
119 u32 irq_error_mask;
120 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
121 u32 error_irqs;
122 struct work_struct error_work;
123
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300124 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200125 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200126
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530127 const struct dispc_features *feat;
128
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200129#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
130 spinlock_t irq_stats_lock;
131 struct dispc_irq_stats irq_stats;
132#endif
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200133} dispc;
134
Amber Jain0d66cbb2011-05-19 19:47:54 +0530135enum omap_color_component {
136 /* used for all color formats for OMAP3 and earlier
137 * and for RGB and Y color component on OMAP4
138 */
139 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
140 /* used for UV component for
141 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
142 * color formats on OMAP4
143 */
144 DISPC_COLOR_COMPONENT_UV = 1 << 1,
145};
146
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530147enum mgr_reg_fields {
148 DISPC_MGR_FLD_ENABLE,
149 DISPC_MGR_FLD_STNTFT,
150 DISPC_MGR_FLD_GO,
151 DISPC_MGR_FLD_TFTDATALINES,
152 DISPC_MGR_FLD_STALLMODE,
153 DISPC_MGR_FLD_TCKENABLE,
154 DISPC_MGR_FLD_TCKSELECTION,
155 DISPC_MGR_FLD_CPR,
156 DISPC_MGR_FLD_FIFOHANDCHECK,
157 /* used to maintain a count of the above fields */
158 DISPC_MGR_FLD_NUM,
159};
160
161static const struct {
162 const char *name;
163 u32 vsync_irq;
164 u32 framedone_irq;
165 u32 sync_lost_irq;
166 struct reg_field reg_desc[DISPC_MGR_FLD_NUM];
167} mgr_desc[] = {
168 [OMAP_DSS_CHANNEL_LCD] = {
169 .name = "LCD",
170 .vsync_irq = DISPC_IRQ_VSYNC,
171 .framedone_irq = DISPC_IRQ_FRAMEDONE,
172 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
173 .reg_desc = {
174 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
175 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
176 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
177 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
178 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
179 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
180 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
181 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
182 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
183 },
184 },
185 [OMAP_DSS_CHANNEL_DIGIT] = {
186 .name = "DIGIT",
187 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
188 .framedone_irq = 0,
189 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
190 .reg_desc = {
191 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
192 [DISPC_MGR_FLD_STNTFT] = { },
193 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
194 [DISPC_MGR_FLD_TFTDATALINES] = { },
195 [DISPC_MGR_FLD_STALLMODE] = { },
196 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
197 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
198 [DISPC_MGR_FLD_CPR] = { },
199 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
200 },
201 },
202 [OMAP_DSS_CHANNEL_LCD2] = {
203 .name = "LCD2",
204 .vsync_irq = DISPC_IRQ_VSYNC2,
205 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
206 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
207 .reg_desc = {
208 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
209 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
210 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
211 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
212 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
213 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
214 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
215 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
216 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
217 },
218 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530219 [OMAP_DSS_CHANNEL_LCD3] = {
220 .name = "LCD3",
221 .vsync_irq = DISPC_IRQ_VSYNC3,
222 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
223 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
224 .reg_desc = {
225 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
226 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
227 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
228 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
229 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
230 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
231 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
232 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
233 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
234 },
235 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530236};
237
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200238static void _omap_dispc_set_irqs(void);
239
Archit Taneja55978cc2011-05-06 11:45:51 +0530240static inline void dispc_write_reg(const u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200241{
Archit Taneja55978cc2011-05-06 11:45:51 +0530242 __raw_writel(val, dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200243}
244
Archit Taneja55978cc2011-05-06 11:45:51 +0530245static inline u32 dispc_read_reg(const u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200246{
Archit Taneja55978cc2011-05-06 11:45:51 +0530247 return __raw_readl(dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200248}
249
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530250static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
251{
252 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
253 return REG_GET(rfld.reg, rfld.high, rfld.low);
254}
255
256static void mgr_fld_write(enum omap_channel channel,
257 enum mgr_reg_fields regfld, int val) {
258 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
259 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
260}
261
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200262#define SR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530263 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200264#define RR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530265 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200266
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300267static void dispc_save_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200268{
Archit Tanejac6104b82011-08-05 19:06:02 +0530269 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200270
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300271 DSSDBG("dispc_save_context\n");
272
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200273 SR(IRQENABLE);
274 SR(CONTROL);
275 SR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200276 SR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530277 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
278 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300279 SR(GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000280 if (dss_has_feature(FEAT_MGR_LCD2)) {
281 SR(CONTROL2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000282 SR(CONFIG2);
283 }
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530284 if (dss_has_feature(FEAT_MGR_LCD3)) {
285 SR(CONTROL3);
286 SR(CONFIG3);
287 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200288
Archit Tanejac6104b82011-08-05 19:06:02 +0530289 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
290 SR(DEFAULT_COLOR(i));
291 SR(TRANS_COLOR(i));
292 SR(SIZE_MGR(i));
293 if (i == OMAP_DSS_CHANNEL_DIGIT)
294 continue;
295 SR(TIMING_H(i));
296 SR(TIMING_V(i));
297 SR(POL_FREQ(i));
298 SR(DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200299
Archit Tanejac6104b82011-08-05 19:06:02 +0530300 SR(DATA_CYCLE1(i));
301 SR(DATA_CYCLE2(i));
302 SR(DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200303
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300304 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530305 SR(CPR_COEF_R(i));
306 SR(CPR_COEF_G(i));
307 SR(CPR_COEF_B(i));
308 }
309 }
310
311 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
312 SR(OVL_BA0(i));
313 SR(OVL_BA1(i));
314 SR(OVL_POSITION(i));
315 SR(OVL_SIZE(i));
316 SR(OVL_ATTRIBUTES(i));
317 SR(OVL_FIFO_THRESHOLD(i));
318 SR(OVL_ROW_INC(i));
319 SR(OVL_PIXEL_INC(i));
320 if (dss_has_feature(FEAT_PRELOAD))
321 SR(OVL_PRELOAD(i));
322 if (i == OMAP_DSS_GFX) {
323 SR(OVL_WINDOW_SKIP(i));
324 SR(OVL_TABLE_BA(i));
325 continue;
326 }
327 SR(OVL_FIR(i));
328 SR(OVL_PICTURE_SIZE(i));
329 SR(OVL_ACCU0(i));
330 SR(OVL_ACCU1(i));
331
332 for (j = 0; j < 8; j++)
333 SR(OVL_FIR_COEF_H(i, j));
334
335 for (j = 0; j < 8; j++)
336 SR(OVL_FIR_COEF_HV(i, j));
337
338 for (j = 0; j < 5; j++)
339 SR(OVL_CONV_COEF(i, j));
340
341 if (dss_has_feature(FEAT_FIR_COEF_V)) {
342 for (j = 0; j < 8; j++)
343 SR(OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300344 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000345
Archit Tanejac6104b82011-08-05 19:06:02 +0530346 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
347 SR(OVL_BA0_UV(i));
348 SR(OVL_BA1_UV(i));
349 SR(OVL_FIR2(i));
350 SR(OVL_ACCU2_0(i));
351 SR(OVL_ACCU2_1(i));
352
353 for (j = 0; j < 8; j++)
354 SR(OVL_FIR_COEF_H2(i, j));
355
356 for (j = 0; j < 8; j++)
357 SR(OVL_FIR_COEF_HV2(i, j));
358
359 for (j = 0; j < 8; j++)
360 SR(OVL_FIR_COEF_V2(i, j));
361 }
362 if (dss_has_feature(FEAT_ATTR2))
363 SR(OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000364 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200365
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600366 if (dss_has_feature(FEAT_CORE_CLK_DIV))
367 SR(DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300368
Tomi Valkeinen00928ea2012-02-20 11:50:06 +0200369 dispc.ctx_loss_cnt = dss_get_ctx_loss_count(&dispc.pdev->dev);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300370 dispc.ctx_valid = true;
371
372 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200373}
374
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300375static void dispc_restore_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200376{
Archit Tanejac6104b82011-08-05 19:06:02 +0530377 int i, j, ctx;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300378
379 DSSDBG("dispc_restore_context\n");
380
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300381 if (!dispc.ctx_valid)
382 return;
383
Tomi Valkeinen00928ea2012-02-20 11:50:06 +0200384 ctx = dss_get_ctx_loss_count(&dispc.pdev->dev);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300385
386 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
387 return;
388
389 DSSDBG("ctx_loss_count: saved %d, current %d\n",
390 dispc.ctx_loss_cnt, ctx);
391
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200392 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200393 /*RR(CONTROL);*/
394 RR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200395 RR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530396 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
397 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300398 RR(GLOBAL_ALPHA);
Archit Tanejac6104b82011-08-05 19:06:02 +0530399 if (dss_has_feature(FEAT_MGR_LCD2))
Sumit Semwal2a205f32010-12-02 11:27:12 +0000400 RR(CONFIG2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530401 if (dss_has_feature(FEAT_MGR_LCD3))
402 RR(CONFIG3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200403
Archit Tanejac6104b82011-08-05 19:06:02 +0530404 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
405 RR(DEFAULT_COLOR(i));
406 RR(TRANS_COLOR(i));
407 RR(SIZE_MGR(i));
408 if (i == OMAP_DSS_CHANNEL_DIGIT)
409 continue;
410 RR(TIMING_H(i));
411 RR(TIMING_V(i));
412 RR(POL_FREQ(i));
413 RR(DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530414
Archit Tanejac6104b82011-08-05 19:06:02 +0530415 RR(DATA_CYCLE1(i));
416 RR(DATA_CYCLE2(i));
417 RR(DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000418
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300419 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530420 RR(CPR_COEF_R(i));
421 RR(CPR_COEF_G(i));
422 RR(CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300423 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000424 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200425
Archit Tanejac6104b82011-08-05 19:06:02 +0530426 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
427 RR(OVL_BA0(i));
428 RR(OVL_BA1(i));
429 RR(OVL_POSITION(i));
430 RR(OVL_SIZE(i));
431 RR(OVL_ATTRIBUTES(i));
432 RR(OVL_FIFO_THRESHOLD(i));
433 RR(OVL_ROW_INC(i));
434 RR(OVL_PIXEL_INC(i));
435 if (dss_has_feature(FEAT_PRELOAD))
436 RR(OVL_PRELOAD(i));
437 if (i == OMAP_DSS_GFX) {
438 RR(OVL_WINDOW_SKIP(i));
439 RR(OVL_TABLE_BA(i));
440 continue;
441 }
442 RR(OVL_FIR(i));
443 RR(OVL_PICTURE_SIZE(i));
444 RR(OVL_ACCU0(i));
445 RR(OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200446
Archit Tanejac6104b82011-08-05 19:06:02 +0530447 for (j = 0; j < 8; j++)
448 RR(OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200449
Archit Tanejac6104b82011-08-05 19:06:02 +0530450 for (j = 0; j < 8; j++)
451 RR(OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200452
Archit Tanejac6104b82011-08-05 19:06:02 +0530453 for (j = 0; j < 5; j++)
454 RR(OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200455
Archit Tanejac6104b82011-08-05 19:06:02 +0530456 if (dss_has_feature(FEAT_FIR_COEF_V)) {
457 for (j = 0; j < 8; j++)
458 RR(OVL_FIR_COEF_V(i, j));
459 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200460
Archit Tanejac6104b82011-08-05 19:06:02 +0530461 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
462 RR(OVL_BA0_UV(i));
463 RR(OVL_BA1_UV(i));
464 RR(OVL_FIR2(i));
465 RR(OVL_ACCU2_0(i));
466 RR(OVL_ACCU2_1(i));
467
468 for (j = 0; j < 8; j++)
469 RR(OVL_FIR_COEF_H2(i, j));
470
471 for (j = 0; j < 8; j++)
472 RR(OVL_FIR_COEF_HV2(i, j));
473
474 for (j = 0; j < 8; j++)
475 RR(OVL_FIR_COEF_V2(i, j));
476 }
477 if (dss_has_feature(FEAT_ATTR2))
478 RR(OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300479 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200480
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600481 if (dss_has_feature(FEAT_CORE_CLK_DIV))
482 RR(DIVISOR);
483
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200484 /* enable last, because LCD & DIGIT enable are here */
485 RR(CONTROL);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000486 if (dss_has_feature(FEAT_MGR_LCD2))
487 RR(CONTROL2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530488 if (dss_has_feature(FEAT_MGR_LCD3))
489 RR(CONTROL3);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200490 /* clear spurious SYNC_LOST_DIGIT interrupts */
491 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
492
493 /*
494 * enable last so IRQs won't trigger before
495 * the context is fully restored
496 */
497 RR(IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300498
499 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200500}
501
502#undef SR
503#undef RR
504
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300505int dispc_runtime_get(void)
506{
507 int r;
508
509 DSSDBG("dispc_runtime_get\n");
510
511 r = pm_runtime_get_sync(&dispc.pdev->dev);
512 WARN_ON(r < 0);
513 return r < 0 ? r : 0;
514}
515
516void dispc_runtime_put(void)
517{
518 int r;
519
520 DSSDBG("dispc_runtime_put\n");
521
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200522 r = pm_runtime_put_sync(&dispc.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300523 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300524}
525
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200526u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
527{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530528 return mgr_desc[channel].vsync_irq;
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200529}
530
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200531u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
532{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530533 return mgr_desc[channel].framedone_irq;
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200534}
535
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300536bool dispc_mgr_go_busy(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200537{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530538 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200539}
540
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300541void dispc_mgr_go(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200542{
Sumit Semwal2a205f32010-12-02 11:27:12 +0000543 bool enable_bit, go_bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200544
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200545 /* if the channel is not enabled, we don't need GO */
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530546 enable_bit = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE) == 1;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000547
548 if (!enable_bit)
Tomi Valkeinene6d80f92011-05-19 14:12:26 +0300549 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200550
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530551 go_bit = mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000552
553 if (go_bit) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200554 DSSERR("GO bit not down for channel %d\n", channel);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +0300555 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200556 }
557
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530558 DSSDBG("GO %s\n", mgr_desc[channel].name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200559
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530560 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200561}
562
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300563static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200564{
Archit Taneja9b372c22011-05-06 11:45:49 +0530565 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200566}
567
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300568static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200569{
Archit Taneja9b372c22011-05-06 11:45:49 +0530570 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200571}
572
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300573static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200574{
Archit Taneja9b372c22011-05-06 11:45:49 +0530575 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200576}
577
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300578static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530579{
580 BUG_ON(plane == OMAP_DSS_GFX);
581
582 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
583}
584
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300585static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
586 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530587{
588 BUG_ON(plane == OMAP_DSS_GFX);
589
590 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
591}
592
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300593static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530594{
595 BUG_ON(plane == OMAP_DSS_GFX);
596
597 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
598}
599
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530600static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
601 int fir_vinc, int five_taps,
602 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200603{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530604 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200605 int i;
606
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530607 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
608 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200609
610 for (i = 0; i < 8; i++) {
611 u32 h, hv;
612
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530613 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
614 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
615 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
616 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
617 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
618 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
619 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
620 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200621
Amber Jain0d66cbb2011-05-19 19:47:54 +0530622 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300623 dispc_ovl_write_firh_reg(plane, i, h);
624 dispc_ovl_write_firhv_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530625 } else {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300626 dispc_ovl_write_firh2_reg(plane, i, h);
627 dispc_ovl_write_firhv2_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530628 }
629
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200630 }
631
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200632 if (five_taps) {
633 for (i = 0; i < 8; i++) {
634 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530635 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
636 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530637 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300638 dispc_ovl_write_firv_reg(plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530639 else
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300640 dispc_ovl_write_firv2_reg(plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200641 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200642 }
643}
644
645static void _dispc_setup_color_conv_coef(void)
646{
Archit Tanejaac01c292011-08-05 19:06:03 +0530647 int i;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200648 const struct color_conv_coef {
649 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
650 int full_range;
651 } ctbl_bt601_5 = {
652 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
653 };
654
655 const struct color_conv_coef *ct;
656
657#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
658
659 ct = &ctbl_bt601_5;
660
Archit Tanejaac01c292011-08-05 19:06:03 +0530661 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
662 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 0),
663 CVAL(ct->rcr, ct->ry));
664 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 1),
665 CVAL(ct->gy, ct->rcb));
666 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 2),
667 CVAL(ct->gcb, ct->gcr));
668 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 3),
669 CVAL(ct->bcr, ct->by));
670 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 4),
671 CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200672
Archit Tanejaac01c292011-08-05 19:06:03 +0530673 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), ct->full_range,
674 11, 11);
675 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200676
677#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200678}
679
680
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300681static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200682{
Archit Taneja9b372c22011-05-06 11:45:49 +0530683 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200684}
685
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300686static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200687{
Archit Taneja9b372c22011-05-06 11:45:49 +0530688 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200689}
690
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300691static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530692{
693 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
694}
695
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300696static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530697{
698 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
699}
700
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300701static void dispc_ovl_set_pos(enum omap_plane plane, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200702{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200703 u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530704
705 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200706}
707
Archit Taneja78b687f2012-09-21 14:51:49 +0530708static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
709 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200710{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200711 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530712
713 if (plane == OMAP_DSS_GFX)
714 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
715 else
716 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200717}
718
Archit Taneja78b687f2012-09-21 14:51:49 +0530719static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
720 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200721{
722 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200723
724 BUG_ON(plane == OMAP_DSS_GFX);
725
726 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530727
728 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200729}
730
Archit Taneja5b54ed32012-09-26 16:55:27 +0530731static void dispc_ovl_set_zorder(enum omap_plane plane,
732 enum omap_overlay_caps caps, u8 zorder)
Archit Taneja54128702011-09-08 11:29:17 +0530733{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530734 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
Archit Taneja54128702011-09-08 11:29:17 +0530735 return;
736
737 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
738}
739
740static void dispc_ovl_enable_zorder_planes(void)
741{
742 int i;
743
744 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
745 return;
746
747 for (i = 0; i < dss_feat_get_num_ovls(); i++)
748 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
749}
750
Archit Taneja5b54ed32012-09-26 16:55:27 +0530751static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
752 enum omap_overlay_caps caps, bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100753{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530754 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100755 return;
756
Archit Taneja9b372c22011-05-06 11:45:49 +0530757 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100758}
759
Archit Taneja5b54ed32012-09-26 16:55:27 +0530760static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
761 enum omap_overlay_caps caps, u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200762{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530763 static const unsigned shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300764 int shift;
765
Archit Taneja5b54ed32012-09-26 16:55:27 +0530766 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100767 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530768
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300769 shift = shifts[plane];
770 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200771}
772
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300773static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200774{
Archit Taneja9b372c22011-05-06 11:45:49 +0530775 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200776}
777
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300778static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200779{
Archit Taneja9b372c22011-05-06 11:45:49 +0530780 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200781}
782
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300783static void dispc_ovl_set_color_mode(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200784 enum omap_color_mode color_mode)
785{
786 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +0530787 if (plane != OMAP_DSS_GFX) {
788 switch (color_mode) {
789 case OMAP_DSS_COLOR_NV12:
790 m = 0x0; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530791 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530792 m = 0x1; break;
793 case OMAP_DSS_COLOR_RGBA16:
794 m = 0x2; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530795 case OMAP_DSS_COLOR_RGB12U:
Amber Jainf20e4222011-05-19 19:47:50 +0530796 m = 0x4; break;
797 case OMAP_DSS_COLOR_ARGB16:
798 m = 0x5; break;
799 case OMAP_DSS_COLOR_RGB16:
800 m = 0x6; break;
801 case OMAP_DSS_COLOR_ARGB16_1555:
802 m = 0x7; break;
803 case OMAP_DSS_COLOR_RGB24U:
804 m = 0x8; break;
805 case OMAP_DSS_COLOR_RGB24P:
806 m = 0x9; break;
807 case OMAP_DSS_COLOR_YUV2:
808 m = 0xa; break;
809 case OMAP_DSS_COLOR_UYVY:
810 m = 0xb; break;
811 case OMAP_DSS_COLOR_ARGB32:
812 m = 0xc; break;
813 case OMAP_DSS_COLOR_RGBA32:
814 m = 0xd; break;
815 case OMAP_DSS_COLOR_RGBX32:
816 m = 0xe; break;
817 case OMAP_DSS_COLOR_XRGB16_1555:
818 m = 0xf; break;
819 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300820 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530821 }
822 } else {
823 switch (color_mode) {
824 case OMAP_DSS_COLOR_CLUT1:
825 m = 0x0; break;
826 case OMAP_DSS_COLOR_CLUT2:
827 m = 0x1; break;
828 case OMAP_DSS_COLOR_CLUT4:
829 m = 0x2; break;
830 case OMAP_DSS_COLOR_CLUT8:
831 m = 0x3; break;
832 case OMAP_DSS_COLOR_RGB12U:
833 m = 0x4; break;
834 case OMAP_DSS_COLOR_ARGB16:
835 m = 0x5; break;
836 case OMAP_DSS_COLOR_RGB16:
837 m = 0x6; break;
838 case OMAP_DSS_COLOR_ARGB16_1555:
839 m = 0x7; break;
840 case OMAP_DSS_COLOR_RGB24U:
841 m = 0x8; break;
842 case OMAP_DSS_COLOR_RGB24P:
843 m = 0x9; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530844 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530845 m = 0xa; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530846 case OMAP_DSS_COLOR_RGBA16:
Amber Jainf20e4222011-05-19 19:47:50 +0530847 m = 0xb; break;
848 case OMAP_DSS_COLOR_ARGB32:
849 m = 0xc; break;
850 case OMAP_DSS_COLOR_RGBA32:
851 m = 0xd; break;
852 case OMAP_DSS_COLOR_RGBX32:
853 m = 0xe; break;
854 case OMAP_DSS_COLOR_XRGB16_1555:
855 m = 0xf; break;
856 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300857 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530858 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200859 }
860
Archit Taneja9b372c22011-05-06 11:45:49 +0530861 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200862}
863
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530864static void dispc_ovl_configure_burst_type(enum omap_plane plane,
865 enum omap_dss_rotation_type rotation_type)
866{
867 if (dss_has_feature(FEAT_BURST_2D) == 0)
868 return;
869
870 if (rotation_type == OMAP_DSS_ROT_TILER)
871 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
872 else
873 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
874}
875
Tomi Valkeinenf4279842011-10-28 15:26:26 +0300876void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200877{
878 int shift;
879 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000880 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200881
882 switch (plane) {
883 case OMAP_DSS_GFX:
884 shift = 8;
885 break;
886 case OMAP_DSS_VIDEO1:
887 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +0530888 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200889 shift = 16;
890 break;
891 default:
892 BUG();
893 return;
894 }
895
Archit Taneja9b372c22011-05-06 11:45:49 +0530896 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000897 if (dss_has_feature(FEAT_MGR_LCD2)) {
898 switch (channel) {
899 case OMAP_DSS_CHANNEL_LCD:
900 chan = 0;
901 chan2 = 0;
902 break;
903 case OMAP_DSS_CHANNEL_DIGIT:
904 chan = 1;
905 chan2 = 0;
906 break;
907 case OMAP_DSS_CHANNEL_LCD2:
908 chan = 0;
909 chan2 = 1;
910 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530911 case OMAP_DSS_CHANNEL_LCD3:
912 if (dss_has_feature(FEAT_MGR_LCD3)) {
913 chan = 0;
914 chan2 = 2;
915 } else {
916 BUG();
917 return;
918 }
919 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000920 default:
921 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300922 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000923 }
924
925 val = FLD_MOD(val, chan, shift, shift);
926 val = FLD_MOD(val, chan2, 31, 30);
927 } else {
928 val = FLD_MOD(val, channel, shift, shift);
929 }
Archit Taneja9b372c22011-05-06 11:45:49 +0530930 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200931}
932
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200933static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
934{
935 int shift;
936 u32 val;
937 enum omap_channel channel;
938
939 switch (plane) {
940 case OMAP_DSS_GFX:
941 shift = 8;
942 break;
943 case OMAP_DSS_VIDEO1:
944 case OMAP_DSS_VIDEO2:
945 case OMAP_DSS_VIDEO3:
946 shift = 16;
947 break;
948 default:
949 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300950 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200951 }
952
953 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
954
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530955 if (dss_has_feature(FEAT_MGR_LCD3)) {
956 if (FLD_GET(val, 31, 30) == 0)
957 channel = FLD_GET(val, shift, shift);
958 else if (FLD_GET(val, 31, 30) == 1)
959 channel = OMAP_DSS_CHANNEL_LCD2;
960 else
961 channel = OMAP_DSS_CHANNEL_LCD3;
962 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200963 if (FLD_GET(val, 31, 30) == 0)
964 channel = FLD_GET(val, shift, shift);
965 else
966 channel = OMAP_DSS_CHANNEL_LCD2;
967 } else {
968 channel = FLD_GET(val, shift, shift);
969 }
970
971 return channel;
972}
973
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300974static void dispc_ovl_set_burst_size(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200975 enum omap_burst_size burst_size)
976{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530977 static const unsigned shifts[] = { 6, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200978 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200979
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300980 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +0300981 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200982}
983
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +0300984static void dispc_configure_burst_sizes(void)
985{
986 int i;
987 const int burst_size = BURST_SIZE_X8;
988
989 /* Configure burst size always to maximum size */
990 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300991 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +0300992}
993
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +0200994static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +0300995{
996 unsigned unit = dss_feat_get_burst_size_unit();
997 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
998 return unit * 8;
999}
1000
Mythri P Kd3862612011-03-11 18:02:49 +05301001void dispc_enable_gamma_table(bool enable)
1002{
1003 /*
1004 * This is partially implemented to support only disabling of
1005 * the gamma table.
1006 */
1007 if (enable) {
1008 DSSWARN("Gamma table enabling for TV not yet supported");
1009 return;
1010 }
1011
1012 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1013}
1014
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001015static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001016{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301017 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001018 return;
1019
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301020 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001021}
1022
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001023static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001024 struct omap_dss_cpr_coefs *coefs)
1025{
1026 u32 coef_r, coef_g, coef_b;
1027
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301028 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001029 return;
1030
1031 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1032 FLD_VAL(coefs->rb, 9, 0);
1033 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1034 FLD_VAL(coefs->gb, 9, 0);
1035 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1036 FLD_VAL(coefs->bb, 9, 0);
1037
1038 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1039 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1040 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1041}
1042
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001043static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001044{
1045 u32 val;
1046
1047 BUG_ON(plane == OMAP_DSS_GFX);
1048
Archit Taneja9b372c22011-05-06 11:45:49 +05301049 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001050 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +05301051 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001052}
1053
Archit Tanejac3d925292011-09-14 11:52:54 +05301054static void dispc_ovl_enable_replication(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001055{
Archit Tanejab8c095b2011-09-13 18:20:33 +05301056 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001057 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001058
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001059 shift = shifts[plane];
1060 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001061}
1062
Archit Taneja8f366162012-04-16 12:53:44 +05301063static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
Archit Tanejae5c09e02012-04-16 12:53:42 +05301064 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001065{
1066 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301067
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001068 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja702d1442011-05-06 11:45:50 +05301069 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001070}
1071
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001072static void dispc_init_fifos(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001073{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001074 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001075 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301076 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001077 u32 unit;
1078
1079 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001080
Archit Tanejaa0acb552010-09-15 19:20:00 +05301081 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001082
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001083 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1084 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001085 size *= unit;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001086 dispc.fifo_size[fifo] = size;
1087
1088 /*
1089 * By default fifos are mapped directly to overlays, fifo 0 to
1090 * ovl 0, fifo 1 to ovl 1, etc.
1091 */
1092 dispc.fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001093 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001094
1095 /*
1096 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1097 * causes problems with certain use cases, like using the tiler in 2D
1098 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1099 * giving GFX plane a larger fifo. WB but should work fine with a
1100 * smaller fifo.
1101 */
1102 if (dispc.feat->gfx_fifo_workaround) {
1103 u32 v;
1104
1105 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1106
1107 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1108 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1109 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1110 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1111
1112 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1113
1114 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1115 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1116 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001117}
1118
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001119static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001120{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001121 int fifo;
1122 u32 size = 0;
1123
1124 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1125 if (dispc.fifo_assignment[fifo] == plane)
1126 size += dispc.fifo_size[fifo];
1127 }
1128
1129 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001130}
1131
Tomi Valkeinen6f04e1b2011-10-31 08:58:52 +02001132void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001133{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301134 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001135 u32 unit;
1136
1137 unit = dss_feat_get_buffer_size_unit();
1138
1139 WARN_ON(low % unit != 0);
1140 WARN_ON(high % unit != 0);
1141
1142 low /= unit;
1143 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301144
Archit Taneja9b372c22011-05-06 11:45:49 +05301145 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1146 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1147
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001148 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001149 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301150 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001151 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301152 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001153 hi_start, hi_end) * unit,
1154 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001155
Archit Taneja9b372c22011-05-06 11:45:49 +05301156 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301157 FLD_VAL(high, hi_start, hi_end) |
1158 FLD_VAL(low, lo_start, lo_end));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001159}
1160
1161void dispc_enable_fifomerge(bool enable)
1162{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001163 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1164 WARN_ON(enable);
1165 return;
1166 }
1167
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001168 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1169 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001170}
1171
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001172void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001173 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1174 bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001175{
1176 /*
1177 * All sizes are in bytes. Both the buffer and burst are made of
1178 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1179 */
1180
1181 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001182 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1183 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001184
1185 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001186 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001187
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001188 if (use_fifomerge) {
1189 total_fifo_size = 0;
1190 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
1191 total_fifo_size += dispc_ovl_get_fifo_size(i);
1192 } else {
1193 total_fifo_size = ovl_fifo_size;
1194 }
1195
1196 /*
1197 * We use the same low threshold for both fifomerge and non-fifomerge
1198 * cases, but for fifomerge we calculate the high threshold using the
1199 * combined fifo size
1200 */
1201
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001202 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001203 *fifo_low = ovl_fifo_size - burst_size * 2;
1204 *fifo_high = total_fifo_size - burst_size;
1205 } else {
1206 *fifo_low = ovl_fifo_size - burst_size;
1207 *fifo_high = total_fifo_size - buf_unit;
1208 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001209}
1210
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001211static void dispc_ovl_set_fir(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301212 int hinc, int vinc,
1213 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001214{
1215 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001216
Amber Jain0d66cbb2011-05-19 19:47:54 +05301217 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1218 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301219
Amber Jain0d66cbb2011-05-19 19:47:54 +05301220 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1221 &hinc_start, &hinc_end);
1222 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1223 &vinc_start, &vinc_end);
1224 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1225 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301226
Amber Jain0d66cbb2011-05-19 19:47:54 +05301227 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1228 } else {
1229 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1230 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1231 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001232}
1233
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001234static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001235{
1236 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301237 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001238
Archit Taneja87a74842011-03-02 11:19:50 +05301239 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1240 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1241
1242 val = FLD_VAL(vaccu, vert_start, vert_end) |
1243 FLD_VAL(haccu, hor_start, hor_end);
1244
Archit Taneja9b372c22011-05-06 11:45:49 +05301245 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001246}
1247
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001248static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001249{
1250 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301251 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001252
Archit Taneja87a74842011-03-02 11:19:50 +05301253 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1254 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1255
1256 val = FLD_VAL(vaccu, vert_start, vert_end) |
1257 FLD_VAL(haccu, hor_start, hor_end);
1258
Archit Taneja9b372c22011-05-06 11:45:49 +05301259 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001260}
1261
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001262static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1263 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301264{
1265 u32 val;
1266
1267 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1268 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1269}
1270
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001271static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1272 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301273{
1274 u32 val;
1275
1276 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1277 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1278}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001279
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001280static void dispc_ovl_set_scale_param(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001281 u16 orig_width, u16 orig_height,
1282 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301283 bool five_taps, u8 rotation,
1284 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001285{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301286 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001287
Amber Jained14a3c2011-05-19 19:47:51 +05301288 fir_hinc = 1024 * orig_width / out_width;
1289 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001290
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301291 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1292 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001293 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301294}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001295
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301296static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1297 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1298 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1299{
1300 int h_accu2_0, h_accu2_1;
1301 int v_accu2_0, v_accu2_1;
1302 int chroma_hinc, chroma_vinc;
1303 int idx;
1304
1305 struct accu {
1306 s8 h0_m, h0_n;
1307 s8 h1_m, h1_n;
1308 s8 v0_m, v0_n;
1309 s8 v1_m, v1_n;
1310 };
1311
1312 const struct accu *accu_table;
1313 const struct accu *accu_val;
1314
1315 static const struct accu accu_nv12[4] = {
1316 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1317 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1318 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1319 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1320 };
1321
1322 static const struct accu accu_nv12_ilace[4] = {
1323 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1324 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1325 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1326 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1327 };
1328
1329 static const struct accu accu_yuv[4] = {
1330 { 0, 1, 0, 1, 0, 1, 0, 1 },
1331 { 0, 1, 0, 1, 0, 1, 0, 1 },
1332 { -1, 1, 0, 1, 0, 1, 0, 1 },
1333 { 0, 1, 0, 1, -1, 1, 0, 1 },
1334 };
1335
1336 switch (rotation) {
1337 case OMAP_DSS_ROT_0:
1338 idx = 0;
1339 break;
1340 case OMAP_DSS_ROT_90:
1341 idx = 1;
1342 break;
1343 case OMAP_DSS_ROT_180:
1344 idx = 2;
1345 break;
1346 case OMAP_DSS_ROT_270:
1347 idx = 3;
1348 break;
1349 default:
1350 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001351 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301352 }
1353
1354 switch (color_mode) {
1355 case OMAP_DSS_COLOR_NV12:
1356 if (ilace)
1357 accu_table = accu_nv12_ilace;
1358 else
1359 accu_table = accu_nv12;
1360 break;
1361 case OMAP_DSS_COLOR_YUV2:
1362 case OMAP_DSS_COLOR_UYVY:
1363 accu_table = accu_yuv;
1364 break;
1365 default:
1366 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001367 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301368 }
1369
1370 accu_val = &accu_table[idx];
1371
1372 chroma_hinc = 1024 * orig_width / out_width;
1373 chroma_vinc = 1024 * orig_height / out_height;
1374
1375 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1376 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1377 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1378 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1379
1380 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1381 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1382}
1383
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001384static void dispc_ovl_set_scaling_common(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301385 u16 orig_width, u16 orig_height,
1386 u16 out_width, u16 out_height,
1387 bool ilace, bool five_taps,
1388 bool fieldmode, enum omap_color_mode color_mode,
1389 u8 rotation)
1390{
1391 int accu0 = 0;
1392 int accu1 = 0;
1393 u32 l;
1394
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001395 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301396 out_width, out_height, five_taps,
1397 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301398 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001399
Archit Taneja87a74842011-03-02 11:19:50 +05301400 /* RESIZEENABLE and VERTICALTAPS */
1401 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301402 l |= (orig_width != out_width) ? (1 << 5) : 0;
1403 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001404 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301405
1406 /* VRESIZECONF and HRESIZECONF */
1407 if (dss_has_feature(FEAT_RESIZECONF)) {
1408 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301409 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1410 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301411 }
1412
1413 /* LINEBUFFERSPLIT */
1414 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1415 l &= ~(0x1 << 22);
1416 l |= five_taps ? (1 << 22) : 0;
1417 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001418
Archit Taneja9b372c22011-05-06 11:45:49 +05301419 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001420
1421 /*
1422 * field 0 = even field = bottom field
1423 * field 1 = odd field = top field
1424 */
1425 if (ilace && !fieldmode) {
1426 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301427 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001428 if (accu0 >= 1024/2) {
1429 accu1 = 1024/2;
1430 accu0 -= accu1;
1431 }
1432 }
1433
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001434 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1435 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001436}
1437
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001438static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301439 u16 orig_width, u16 orig_height,
1440 u16 out_width, u16 out_height,
1441 bool ilace, bool five_taps,
1442 bool fieldmode, enum omap_color_mode color_mode,
1443 u8 rotation)
1444{
1445 int scale_x = out_width != orig_width;
1446 int scale_y = out_height != orig_height;
1447
1448 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1449 return;
1450 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1451 color_mode != OMAP_DSS_COLOR_UYVY &&
1452 color_mode != OMAP_DSS_COLOR_NV12)) {
1453 /* reset chroma resampling for RGB formats */
1454 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1455 return;
1456 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001457
1458 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1459 out_height, ilace, color_mode, rotation);
1460
Amber Jain0d66cbb2011-05-19 19:47:54 +05301461 switch (color_mode) {
1462 case OMAP_DSS_COLOR_NV12:
1463 /* UV is subsampled by 2 vertically*/
1464 orig_height >>= 1;
1465 /* UV is subsampled by 2 horz.*/
1466 orig_width >>= 1;
1467 break;
1468 case OMAP_DSS_COLOR_YUV2:
1469 case OMAP_DSS_COLOR_UYVY:
1470 /*For YUV422 with 90/270 rotation,
1471 *we don't upsample chroma
1472 */
1473 if (rotation == OMAP_DSS_ROT_0 ||
1474 rotation == OMAP_DSS_ROT_180)
1475 /* UV is subsampled by 2 hrz*/
1476 orig_width >>= 1;
1477 /* must use FIR for YUV422 if rotated */
1478 if (rotation != OMAP_DSS_ROT_0)
1479 scale_x = scale_y = true;
1480 break;
1481 default:
1482 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001483 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301484 }
1485
1486 if (out_width != orig_width)
1487 scale_x = true;
1488 if (out_height != orig_height)
1489 scale_y = true;
1490
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001491 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301492 out_width, out_height, five_taps,
1493 rotation, DISPC_COLOR_COMPONENT_UV);
1494
1495 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1496 (scale_x || scale_y) ? 1 : 0, 8, 8);
1497 /* set H scaling */
1498 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1499 /* set V scaling */
1500 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301501}
1502
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001503static void dispc_ovl_set_scaling(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301504 u16 orig_width, u16 orig_height,
1505 u16 out_width, u16 out_height,
1506 bool ilace, bool five_taps,
1507 bool fieldmode, enum omap_color_mode color_mode,
1508 u8 rotation)
1509{
1510 BUG_ON(plane == OMAP_DSS_GFX);
1511
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001512 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301513 orig_width, orig_height,
1514 out_width, out_height,
1515 ilace, five_taps,
1516 fieldmode, color_mode,
1517 rotation);
1518
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001519 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301520 orig_width, orig_height,
1521 out_width, out_height,
1522 ilace, five_taps,
1523 fieldmode, color_mode,
1524 rotation);
1525}
1526
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001527static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001528 bool mirroring, enum omap_color_mode color_mode)
1529{
Archit Taneja87a74842011-03-02 11:19:50 +05301530 bool row_repeat = false;
1531 int vidrot = 0;
1532
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001533 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1534 color_mode == OMAP_DSS_COLOR_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001535
1536 if (mirroring) {
1537 switch (rotation) {
1538 case OMAP_DSS_ROT_0:
1539 vidrot = 2;
1540 break;
1541 case OMAP_DSS_ROT_90:
1542 vidrot = 1;
1543 break;
1544 case OMAP_DSS_ROT_180:
1545 vidrot = 0;
1546 break;
1547 case OMAP_DSS_ROT_270:
1548 vidrot = 3;
1549 break;
1550 }
1551 } else {
1552 switch (rotation) {
1553 case OMAP_DSS_ROT_0:
1554 vidrot = 0;
1555 break;
1556 case OMAP_DSS_ROT_90:
1557 vidrot = 1;
1558 break;
1559 case OMAP_DSS_ROT_180:
1560 vidrot = 2;
1561 break;
1562 case OMAP_DSS_ROT_270:
1563 vidrot = 3;
1564 break;
1565 }
1566 }
1567
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001568 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
Archit Taneja87a74842011-03-02 11:19:50 +05301569 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001570 else
Archit Taneja87a74842011-03-02 11:19:50 +05301571 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001572 }
Archit Taneja87a74842011-03-02 11:19:50 +05301573
Archit Taneja9b372c22011-05-06 11:45:49 +05301574 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301575 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301576 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1577 row_repeat ? 1 : 0, 18, 18);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001578}
1579
1580static int color_mode_to_bpp(enum omap_color_mode color_mode)
1581{
1582 switch (color_mode) {
1583 case OMAP_DSS_COLOR_CLUT1:
1584 return 1;
1585 case OMAP_DSS_COLOR_CLUT2:
1586 return 2;
1587 case OMAP_DSS_COLOR_CLUT4:
1588 return 4;
1589 case OMAP_DSS_COLOR_CLUT8:
Amber Jainf20e4222011-05-19 19:47:50 +05301590 case OMAP_DSS_COLOR_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001591 return 8;
1592 case OMAP_DSS_COLOR_RGB12U:
1593 case OMAP_DSS_COLOR_RGB16:
1594 case OMAP_DSS_COLOR_ARGB16:
1595 case OMAP_DSS_COLOR_YUV2:
1596 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301597 case OMAP_DSS_COLOR_RGBA16:
1598 case OMAP_DSS_COLOR_RGBX16:
1599 case OMAP_DSS_COLOR_ARGB16_1555:
1600 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001601 return 16;
1602 case OMAP_DSS_COLOR_RGB24P:
1603 return 24;
1604 case OMAP_DSS_COLOR_RGB24U:
1605 case OMAP_DSS_COLOR_ARGB32:
1606 case OMAP_DSS_COLOR_RGBA32:
1607 case OMAP_DSS_COLOR_RGBX32:
1608 return 32;
1609 default:
1610 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001611 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001612 }
1613}
1614
1615static s32 pixinc(int pixels, u8 ps)
1616{
1617 if (pixels == 1)
1618 return 1;
1619 else if (pixels > 1)
1620 return 1 + (pixels - 1) * ps;
1621 else if (pixels < 0)
1622 return 1 - (-pixels + 1) * ps;
1623 else
1624 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001625 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001626}
1627
1628static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1629 u16 screen_width,
1630 u16 width, u16 height,
1631 enum omap_color_mode color_mode, bool fieldmode,
1632 unsigned int field_offset,
1633 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301634 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001635{
1636 u8 ps;
1637
1638 /* FIXME CLUT formats */
1639 switch (color_mode) {
1640 case OMAP_DSS_COLOR_CLUT1:
1641 case OMAP_DSS_COLOR_CLUT2:
1642 case OMAP_DSS_COLOR_CLUT4:
1643 case OMAP_DSS_COLOR_CLUT8:
1644 BUG();
1645 return;
1646 case OMAP_DSS_COLOR_YUV2:
1647 case OMAP_DSS_COLOR_UYVY:
1648 ps = 4;
1649 break;
1650 default:
1651 ps = color_mode_to_bpp(color_mode) / 8;
1652 break;
1653 }
1654
1655 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1656 width, height);
1657
1658 /*
1659 * field 0 = even field = bottom field
1660 * field 1 = odd field = top field
1661 */
1662 switch (rotation + mirror * 4) {
1663 case OMAP_DSS_ROT_0:
1664 case OMAP_DSS_ROT_180:
1665 /*
1666 * If the pixel format is YUV or UYVY divide the width
1667 * of the image by 2 for 0 and 180 degree rotation.
1668 */
1669 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1670 color_mode == OMAP_DSS_COLOR_UYVY)
1671 width = width >> 1;
1672 case OMAP_DSS_ROT_90:
1673 case OMAP_DSS_ROT_270:
1674 *offset1 = 0;
1675 if (field_offset)
1676 *offset0 = field_offset * screen_width * ps;
1677 else
1678 *offset0 = 0;
1679
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301680 *row_inc = pixinc(1 +
1681 (y_predecim * screen_width - x_predecim * width) +
1682 (fieldmode ? screen_width : 0), ps);
1683 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001684 break;
1685
1686 case OMAP_DSS_ROT_0 + 4:
1687 case OMAP_DSS_ROT_180 + 4:
1688 /* If the pixel format is YUV or UYVY divide the width
1689 * of the image by 2 for 0 degree and 180 degree
1690 */
1691 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1692 color_mode == OMAP_DSS_COLOR_UYVY)
1693 width = width >> 1;
1694 case OMAP_DSS_ROT_90 + 4:
1695 case OMAP_DSS_ROT_270 + 4:
1696 *offset1 = 0;
1697 if (field_offset)
1698 *offset0 = field_offset * screen_width * ps;
1699 else
1700 *offset0 = 0;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301701 *row_inc = pixinc(1 -
1702 (y_predecim * screen_width + x_predecim * width) -
1703 (fieldmode ? screen_width : 0), ps);
1704 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001705 break;
1706
1707 default:
1708 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001709 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001710 }
1711}
1712
1713static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1714 u16 screen_width,
1715 u16 width, u16 height,
1716 enum omap_color_mode color_mode, bool fieldmode,
1717 unsigned int field_offset,
1718 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301719 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001720{
1721 u8 ps;
1722 u16 fbw, fbh;
1723
1724 /* FIXME CLUT formats */
1725 switch (color_mode) {
1726 case OMAP_DSS_COLOR_CLUT1:
1727 case OMAP_DSS_COLOR_CLUT2:
1728 case OMAP_DSS_COLOR_CLUT4:
1729 case OMAP_DSS_COLOR_CLUT8:
1730 BUG();
1731 return;
1732 default:
1733 ps = color_mode_to_bpp(color_mode) / 8;
1734 break;
1735 }
1736
1737 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1738 width, height);
1739
1740 /* width & height are overlay sizes, convert to fb sizes */
1741
1742 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1743 fbw = width;
1744 fbh = height;
1745 } else {
1746 fbw = height;
1747 fbh = width;
1748 }
1749
1750 /*
1751 * field 0 = even field = bottom field
1752 * field 1 = odd field = top field
1753 */
1754 switch (rotation + mirror * 4) {
1755 case OMAP_DSS_ROT_0:
1756 *offset1 = 0;
1757 if (field_offset)
1758 *offset0 = *offset1 + field_offset * screen_width * ps;
1759 else
1760 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301761 *row_inc = pixinc(1 +
1762 (y_predecim * screen_width - fbw * x_predecim) +
1763 (fieldmode ? screen_width : 0), ps);
1764 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1765 color_mode == OMAP_DSS_COLOR_UYVY)
1766 *pix_inc = pixinc(x_predecim, 2 * ps);
1767 else
1768 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001769 break;
1770 case OMAP_DSS_ROT_90:
1771 *offset1 = screen_width * (fbh - 1) * ps;
1772 if (field_offset)
1773 *offset0 = *offset1 + field_offset * ps;
1774 else
1775 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301776 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1777 y_predecim + (fieldmode ? 1 : 0), ps);
1778 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001779 break;
1780 case OMAP_DSS_ROT_180:
1781 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1782 if (field_offset)
1783 *offset0 = *offset1 - field_offset * screen_width * ps;
1784 else
1785 *offset0 = *offset1;
1786 *row_inc = pixinc(-1 -
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301787 (y_predecim * screen_width - fbw * x_predecim) -
1788 (fieldmode ? screen_width : 0), ps);
1789 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1790 color_mode == OMAP_DSS_COLOR_UYVY)
1791 *pix_inc = pixinc(-x_predecim, 2 * ps);
1792 else
1793 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001794 break;
1795 case OMAP_DSS_ROT_270:
1796 *offset1 = (fbw - 1) * ps;
1797 if (field_offset)
1798 *offset0 = *offset1 - field_offset * ps;
1799 else
1800 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301801 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1802 y_predecim - (fieldmode ? 1 : 0), ps);
1803 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001804 break;
1805
1806 /* mirroring */
1807 case OMAP_DSS_ROT_0 + 4:
1808 *offset1 = (fbw - 1) * ps;
1809 if (field_offset)
1810 *offset0 = *offset1 + field_offset * screen_width * ps;
1811 else
1812 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301813 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001814 (fieldmode ? screen_width : 0),
1815 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301816 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1817 color_mode == OMAP_DSS_COLOR_UYVY)
1818 *pix_inc = pixinc(-x_predecim, 2 * ps);
1819 else
1820 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001821 break;
1822
1823 case OMAP_DSS_ROT_90 + 4:
1824 *offset1 = 0;
1825 if (field_offset)
1826 *offset0 = *offset1 + field_offset * ps;
1827 else
1828 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301829 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1830 y_predecim + (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001831 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301832 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001833 break;
1834
1835 case OMAP_DSS_ROT_180 + 4:
1836 *offset1 = screen_width * (fbh - 1) * ps;
1837 if (field_offset)
1838 *offset0 = *offset1 - field_offset * screen_width * ps;
1839 else
1840 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301841 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001842 (fieldmode ? screen_width : 0),
1843 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301844 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1845 color_mode == OMAP_DSS_COLOR_UYVY)
1846 *pix_inc = pixinc(x_predecim, 2 * ps);
1847 else
1848 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001849 break;
1850
1851 case OMAP_DSS_ROT_270 + 4:
1852 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1853 if (field_offset)
1854 *offset0 = *offset1 - field_offset * ps;
1855 else
1856 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301857 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
1858 y_predecim - (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001859 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301860 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001861 break;
1862
1863 default:
1864 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001865 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001866 }
1867}
1868
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301869static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
1870 enum omap_color_mode color_mode, bool fieldmode,
1871 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1872 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1873{
1874 u8 ps;
1875
1876 switch (color_mode) {
1877 case OMAP_DSS_COLOR_CLUT1:
1878 case OMAP_DSS_COLOR_CLUT2:
1879 case OMAP_DSS_COLOR_CLUT4:
1880 case OMAP_DSS_COLOR_CLUT8:
1881 BUG();
1882 return;
1883 default:
1884 ps = color_mode_to_bpp(color_mode) / 8;
1885 break;
1886 }
1887
1888 DSSDBG("scrw %d, width %d\n", screen_width, width);
1889
1890 /*
1891 * field 0 = even field = bottom field
1892 * field 1 = odd field = top field
1893 */
1894 *offset1 = 0;
1895 if (field_offset)
1896 *offset0 = *offset1 + field_offset * screen_width * ps;
1897 else
1898 *offset0 = *offset1;
1899 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1900 (fieldmode ? screen_width : 0), ps);
1901 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1902 color_mode == OMAP_DSS_COLOR_UYVY)
1903 *pix_inc = pixinc(x_predecim, 2 * ps);
1904 else
1905 *pix_inc = pixinc(x_predecim, ps);
1906}
1907
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301908/*
1909 * This function is used to avoid synclosts in OMAP3, because of some
1910 * undocumented horizontal position and timing related limitations.
1911 */
Archit Taneja81ab95b2012-05-08 15:53:20 +05301912static int check_horiz_timing_omap3(enum omap_channel channel,
1913 const struct omap_video_timings *t, u16 pos_x,
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301914 u16 width, u16 height, u16 out_width, u16 out_height)
1915{
1916 int DS = DIV_ROUND_UP(height, out_height);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301917 unsigned long nonactive, lclk, pclk;
1918 static const u8 limits[3] = { 8, 10, 20 };
1919 u64 val, blank;
1920 int i;
1921
Archit Taneja81ab95b2012-05-08 15:53:20 +05301922 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301923 pclk = dispc_mgr_pclk_rate(channel);
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301924 if (dss_mgr_is_lcd(channel))
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301925 lclk = dispc_mgr_lclk_rate(channel);
1926 else
1927 lclk = dispc_fclk_rate();
1928
1929 i = 0;
1930 if (out_height < height)
1931 i++;
1932 if (out_width < width)
1933 i++;
Archit Taneja81ab95b2012-05-08 15:53:20 +05301934 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301935 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
1936 if (blank <= limits[i])
1937 return -EINVAL;
1938
1939 /*
1940 * Pixel data should be prepared before visible display point starts.
1941 * So, atleast DS-2 lines must have already been fetched by DISPC
1942 * during nonactive - pos_x period.
1943 */
1944 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
1945 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
1946 val, max(0, DS - 2) * width);
1947 if (val < max(0, DS - 2) * width)
1948 return -EINVAL;
1949
1950 /*
1951 * All lines need to be refilled during the nonactive period of which
1952 * only one line can be loaded during the active period. So, atleast
1953 * DS - 1 lines should be loaded during nonactive period.
1954 */
1955 val = div_u64((u64)nonactive * lclk, pclk);
1956 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
1957 val, max(0, DS - 1) * width);
1958 if (val < max(0, DS - 1) * width)
1959 return -EINVAL;
1960
1961 return 0;
1962}
1963
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05301964static unsigned long calc_core_clk_five_taps(enum omap_channel channel,
Archit Taneja81ab95b2012-05-08 15:53:20 +05301965 const struct omap_video_timings *mgr_timings, u16 width,
1966 u16 height, u16 out_width, u16 out_height,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00001967 enum omap_color_mode color_mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001968{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05301969 u32 core_clk = 0;
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03001970 u64 tmp, pclk = dispc_mgr_pclk_rate(channel);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001971
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05301972 if (height <= out_height && width <= out_width)
1973 return (unsigned long) pclk;
1974
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001975 if (height > out_height) {
Archit Taneja81ab95b2012-05-08 15:53:20 +05301976 unsigned int ppl = mgr_timings->x_res;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001977
1978 tmp = pclk * height * out_width;
1979 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05301980 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001981
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02001982 if (height > 2 * out_height) {
1983 if (ppl == out_width)
1984 return 0;
1985
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001986 tmp = pclk * (height - 2 * out_height) * out_width;
1987 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05301988 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001989 }
1990 }
1991
1992 if (width > out_width) {
1993 tmp = pclk * width;
1994 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05301995 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001996
1997 if (color_mode == OMAP_DSS_COLOR_RGB24U)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05301998 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001999 }
2000
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302001 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002002}
2003
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302004static unsigned long calc_core_clk_24xx(enum omap_channel channel, u16 width,
2005 u16 height, u16 out_width, u16 out_height)
2006{
2007 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2008
2009 if (height > out_height && width > out_width)
2010 return pclk * 4;
2011 else
2012 return pclk * 2;
2013}
2014
2015static unsigned long calc_core_clk_34xx(enum omap_channel channel, u16 width,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002016 u16 height, u16 out_width, u16 out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002017{
2018 unsigned int hf, vf;
Archit Taneja79ee89c2012-01-30 10:54:17 +05302019 unsigned long pclk = dispc_mgr_pclk_rate(channel);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002020
2021 /*
2022 * FIXME how to determine the 'A' factor
2023 * for the no downscaling case ?
2024 */
2025
2026 if (width > 3 * out_width)
2027 hf = 4;
2028 else if (width > 2 * out_width)
2029 hf = 3;
2030 else if (width > out_width)
2031 hf = 2;
2032 else
2033 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002034 if (height > out_height)
2035 vf = 2;
2036 else
2037 vf = 1;
2038
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302039 return pclk * vf * hf;
2040}
2041
2042static unsigned long calc_core_clk_44xx(enum omap_channel channel, u16 width,
2043 u16 height, u16 out_width, u16 out_height)
2044{
2045 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2046
2047 if (width > out_width)
2048 return DIV_ROUND_UP(pclk, out_width) * width;
2049 else
2050 return pclk;
2051}
2052
2053static int dispc_ovl_calc_scaling_24xx(enum omap_channel channel,
2054 const struct omap_video_timings *mgr_timings,
2055 u16 width, u16 height, u16 out_width, u16 out_height,
2056 enum omap_color_mode color_mode, bool *five_taps,
2057 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2058 u16 pos_x, unsigned long *core_clk)
2059{
2060 int error;
2061 u16 in_width, in_height;
2062 int min_factor = min(*decim_x, *decim_y);
2063 const int maxsinglelinewidth =
2064 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2065 *five_taps = false;
2066
2067 do {
2068 in_height = DIV_ROUND_UP(height, *decim_y);
2069 in_width = DIV_ROUND_UP(width, *decim_x);
2070 *core_clk = dispc.feat->calc_core_clk(channel, in_width,
2071 in_height, out_width, out_height);
2072 error = (in_width > maxsinglelinewidth || !*core_clk ||
2073 *core_clk > dispc_core_clk_rate());
2074 if (error) {
2075 if (*decim_x == *decim_y) {
2076 *decim_x = min_factor;
2077 ++*decim_y;
2078 } else {
2079 swap(*decim_x, *decim_y);
2080 if (*decim_x < *decim_y)
2081 ++*decim_x;
2082 }
2083 }
2084 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2085
2086 if (in_width > maxsinglelinewidth) {
2087 DSSERR("Cannot scale max input width exceeded");
2088 return -EINVAL;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302089 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302090 return 0;
2091}
2092
2093static int dispc_ovl_calc_scaling_34xx(enum omap_channel channel,
2094 const struct omap_video_timings *mgr_timings,
2095 u16 width, u16 height, u16 out_width, u16 out_height,
2096 enum omap_color_mode color_mode, bool *five_taps,
2097 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2098 u16 pos_x, unsigned long *core_clk)
2099{
2100 int error;
2101 u16 in_width, in_height;
2102 int min_factor = min(*decim_x, *decim_y);
2103 const int maxsinglelinewidth =
2104 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2105
2106 do {
2107 in_height = DIV_ROUND_UP(height, *decim_y);
2108 in_width = DIV_ROUND_UP(width, *decim_x);
2109 *core_clk = calc_core_clk_five_taps(channel, mgr_timings,
2110 in_width, in_height, out_width, out_height, color_mode);
2111
2112 error = check_horiz_timing_omap3(channel, mgr_timings, pos_x,
2113 in_width, in_height, out_width, out_height);
2114
2115 if (in_width > maxsinglelinewidth)
2116 if (in_height > out_height &&
2117 in_height < out_height * 2)
2118 *five_taps = false;
2119 if (!*five_taps)
2120 *core_clk = dispc.feat->calc_core_clk(channel, in_width,
2121 in_height, out_width, out_height);
2122
2123 error = (error || in_width > maxsinglelinewidth * 2 ||
2124 (in_width > maxsinglelinewidth && *five_taps) ||
2125 !*core_clk || *core_clk > dispc_core_clk_rate());
2126 if (error) {
2127 if (*decim_x == *decim_y) {
2128 *decim_x = min_factor;
2129 ++*decim_y;
2130 } else {
2131 swap(*decim_x, *decim_y);
2132 if (*decim_x < *decim_y)
2133 ++*decim_x;
2134 }
2135 }
2136 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2137
2138 if (check_horiz_timing_omap3(channel, mgr_timings, pos_x, width, height,
2139 out_width, out_height)){
2140 DSSERR("horizontal timing too tight\n");
2141 return -EINVAL;
2142 }
2143
2144 if (in_width > (maxsinglelinewidth * 2)) {
2145 DSSERR("Cannot setup scaling");
2146 DSSERR("width exceeds maximum width possible");
2147 return -EINVAL;
2148 }
2149
2150 if (in_width > maxsinglelinewidth && *five_taps) {
2151 DSSERR("cannot setup scaling with five taps");
2152 return -EINVAL;
2153 }
2154 return 0;
2155}
2156
2157static int dispc_ovl_calc_scaling_44xx(enum omap_channel channel,
2158 const struct omap_video_timings *mgr_timings,
2159 u16 width, u16 height, u16 out_width, u16 out_height,
2160 enum omap_color_mode color_mode, bool *five_taps,
2161 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2162 u16 pos_x, unsigned long *core_clk)
2163{
2164 u16 in_width, in_width_max;
2165 int decim_x_min = *decim_x;
2166 u16 in_height = DIV_ROUND_UP(height, *decim_y);
2167 const int maxsinglelinewidth =
2168 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2169
2170 in_width_max = dispc_core_clk_rate() /
2171 DIV_ROUND_UP(dispc_mgr_pclk_rate(channel), out_width);
2172 *decim_x = DIV_ROUND_UP(width, in_width_max);
2173
2174 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2175 if (*decim_x > *x_predecim)
2176 return -EINVAL;
2177
2178 do {
2179 in_width = DIV_ROUND_UP(width, *decim_x);
2180 } while (*decim_x <= *x_predecim &&
2181 in_width > maxsinglelinewidth && ++*decim_x);
2182
2183 if (in_width > maxsinglelinewidth) {
2184 DSSERR("Cannot scale width exceeds max line width");
2185 return -EINVAL;
2186 }
2187
2188 *core_clk = dispc.feat->calc_core_clk(channel, in_width, in_height,
2189 out_width, out_height);
2190 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002191}
2192
Archit Taneja79ad75f2011-09-08 13:15:11 +05302193static int dispc_ovl_calc_scaling(enum omap_plane plane,
Archit Taneja5b54ed32012-09-26 16:55:27 +05302194 enum omap_overlay_caps caps, enum omap_channel channel,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302195 const struct omap_video_timings *mgr_timings,
2196 u16 width, u16 height, u16 out_width, u16 out_height,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302197 enum omap_color_mode color_mode, bool *five_taps,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302198 int *x_predecim, int *y_predecim, u16 pos_x,
2199 enum omap_dss_rotation_type rotation_type)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302200{
Archit Taneja0373cac2011-09-08 13:25:17 +05302201 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302202 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302203 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302204 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302205
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002206 if (width == out_width && height == out_height)
2207 return 0;
2208
Archit Taneja5b54ed32012-09-26 16:55:27 +05302209 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002210 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302211
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302212 *x_predecim = max_decim_limit;
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302213 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2214 dss_has_feature(FEAT_BURST_2D)) ? 2 : max_decim_limit;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302215
2216 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2217 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2218 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2219 color_mode == OMAP_DSS_COLOR_CLUT8) {
2220 *x_predecim = 1;
2221 *y_predecim = 1;
2222 *five_taps = false;
2223 return 0;
2224 }
2225
2226 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2227 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2228
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302229 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302230 return -EINVAL;
2231
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302232 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302233 return -EINVAL;
2234
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302235 ret = dispc.feat->calc_scaling(channel, mgr_timings, width, height,
2236 out_width, out_height, color_mode, five_taps, x_predecim,
2237 y_predecim, &decim_x, &decim_y, pos_x, &core_clk);
2238 if (ret)
2239 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302240
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302241 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2242 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302243
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302244 if (!core_clk || core_clk > dispc_core_clk_rate()) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302245 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302246 "required core clk rate = %lu Hz, "
2247 "current core clk rate = %lu Hz\n",
2248 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302249 return -EINVAL;
2250 }
2251
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302252 *x_predecim = decim_x;
2253 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302254 return 0;
2255}
2256
Archit Taneja8eeb7012012-08-22 12:33:49 +05302257int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
Archit Taneja8050cbe2012-06-06 16:25:52 +05302258 bool replication, const struct omap_video_timings *mgr_timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002259{
Archit Taneja79ad75f2011-09-08 13:15:11 +05302260 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
Archit Taneja5b54ed32012-09-26 16:55:27 +05302261 enum omap_overlay_caps caps = ovl->caps;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302262 bool five_taps = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002263 bool fieldmode = 0;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302264 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002265 unsigned offset0, offset1;
2266 s32 row_inc;
2267 s32 pix_inc;
Archit Tanejaa4273b72011-09-14 11:10:10 +05302268 u16 frame_height = oi->height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002269 unsigned int field_offset = 0;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302270 u16 in_height = oi->height;
2271 u16 in_width = oi->width;
2272 u16 out_width, out_height;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002273 enum omap_channel channel;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302274 int x_predecim = 1, y_predecim = 1;
Archit Taneja8050cbe2012-06-06 16:25:52 +05302275 bool ilace = mgr_timings->interlace;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302276 u16 pos_y = oi->pos_y;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002277
2278 channel = dispc_ovl_get_channel_out(plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002279
Archit Tanejaa4273b72011-09-14 11:10:10 +05302280 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
Tomi Valkeinenf38545d2011-11-03 17:00:07 +02002281 "%dx%d, cmode %x, rot %d, mir %d, ilace %d chan %d repl %d\n",
2282 plane, oi->paddr, oi->p_uv_addr,
Archit Tanejac3d925292011-09-14 11:52:54 +05302283 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2284 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
Tomi Valkeinenf38545d2011-11-03 17:00:07 +02002285 oi->mirror, ilace, channel, replication);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002286
Archit Tanejaa4273b72011-09-14 11:10:10 +05302287 if (oi->paddr == 0)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002288 return -EINVAL;
2289
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302290 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2291 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002292
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302293 if (ilace && oi->height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002294 fieldmode = 1;
2295
2296 if (ilace) {
2297 if (fieldmode)
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302298 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302299 pos_y /= 2;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302300 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002301
2302 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2303 "out_height %d\n",
Archit Taneja8eeb7012012-08-22 12:33:49 +05302304 in_height, pos_y, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002305 }
2306
Archit Tanejaa4273b72011-09-14 11:10:10 +05302307 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302308 return -EINVAL;
2309
Archit Taneja5b54ed32012-09-26 16:55:27 +05302310 r = dispc_ovl_calc_scaling(plane, caps, channel, mgr_timings, in_width,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302311 in_height, out_width, out_height, oi->color_mode,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302312 &five_taps, &x_predecim, &y_predecim, oi->pos_x,
2313 oi->rotation_type);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302314 if (r)
2315 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002316
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302317 in_width = DIV_ROUND_UP(in_width, x_predecim);
2318 in_height = DIV_ROUND_UP(in_height, y_predecim);
2319
Archit Taneja79ad75f2011-09-08 13:15:11 +05302320 if (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
2321 oi->color_mode == OMAP_DSS_COLOR_UYVY ||
2322 oi->color_mode == OMAP_DSS_COLOR_NV12)
2323 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002324
2325 if (ilace && !fieldmode) {
2326 /*
2327 * when downscaling the bottom field may have to start several
2328 * source lines below the top field. Unfortunately ACCUI
2329 * registers will only hold the fractional part of the offset
2330 * so the integer part must be added to the base address of the
2331 * bottom field.
2332 */
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302333 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002334 field_offset = 0;
2335 else
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302336 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002337 }
2338
2339 /* Fields are independent but interleaved in memory. */
2340 if (fieldmode)
2341 field_offset = 1;
2342
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002343 offset0 = 0;
2344 offset1 = 0;
2345 row_inc = 0;
2346 pix_inc = 0;
2347
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302348 if (oi->rotation_type == OMAP_DSS_ROT_TILER)
2349 calc_tiler_rotation_offset(oi->screen_width, in_width,
2350 oi->color_mode, fieldmode, field_offset,
2351 &offset0, &offset1, &row_inc, &pix_inc,
2352 x_predecim, y_predecim);
2353 else if (oi->rotation_type == OMAP_DSS_ROT_DMA)
Archit Tanejaa4273b72011-09-14 11:10:10 +05302354 calc_dma_rotation_offset(oi->rotation, oi->mirror,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302355 oi->screen_width, in_width, frame_height,
Archit Tanejaa4273b72011-09-14 11:10:10 +05302356 oi->color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302357 &offset0, &offset1, &row_inc, &pix_inc,
2358 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002359 else
Archit Tanejaa4273b72011-09-14 11:10:10 +05302360 calc_vrfb_rotation_offset(oi->rotation, oi->mirror,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302361 oi->screen_width, in_width, frame_height,
Archit Tanejaa4273b72011-09-14 11:10:10 +05302362 oi->color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302363 &offset0, &offset1, &row_inc, &pix_inc,
2364 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002365
2366 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2367 offset0, offset1, row_inc, pix_inc);
2368
Archit Tanejaa4273b72011-09-14 11:10:10 +05302369 dispc_ovl_set_color_mode(plane, oi->color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002370
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302371 dispc_ovl_configure_burst_type(plane, oi->rotation_type);
2372
Archit Tanejaa4273b72011-09-14 11:10:10 +05302373 dispc_ovl_set_ba0(plane, oi->paddr + offset0);
2374 dispc_ovl_set_ba1(plane, oi->paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002375
Archit Tanejaa4273b72011-09-14 11:10:10 +05302376 if (OMAP_DSS_COLOR_NV12 == oi->color_mode) {
2377 dispc_ovl_set_ba0_uv(plane, oi->p_uv_addr + offset0);
2378 dispc_ovl_set_ba1_uv(plane, oi->p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302379 }
2380
2381
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002382 dispc_ovl_set_row_inc(plane, row_inc);
2383 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002384
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302385 DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, in_width,
2386 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002387
Archit Taneja8eeb7012012-08-22 12:33:49 +05302388 dispc_ovl_set_pos(plane, oi->pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002389
Archit Taneja78b687f2012-09-21 14:51:49 +05302390 dispc_ovl_set_input_size(plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002391
Archit Taneja5b54ed32012-09-26 16:55:27 +05302392 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302393 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2394 out_height, ilace, five_taps, fieldmode,
Archit Tanejaa4273b72011-09-14 11:10:10 +05302395 oi->color_mode, oi->rotation);
Archit Taneja78b687f2012-09-21 14:51:49 +05302396
2397 dispc_ovl_set_output_size(plane, out_width, out_height);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002398 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002399 }
2400
Archit Tanejaa4273b72011-09-14 11:10:10 +05302401 dispc_ovl_set_rotation_attrs(plane, oi->rotation, oi->mirror,
2402 oi->color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002403
Archit Taneja5b54ed32012-09-26 16:55:27 +05302404 dispc_ovl_set_zorder(plane, caps, oi->zorder);
2405 dispc_ovl_set_pre_mult_alpha(plane, caps, oi->pre_mult_alpha);
2406 dispc_ovl_setup_global_alpha(plane, caps, oi->global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002407
Archit Tanejac3d925292011-09-14 11:52:54 +05302408 dispc_ovl_enable_replication(plane, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302409
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002410 return 0;
2411}
2412
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002413int dispc_ovl_enable(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002414{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002415 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2416
Archit Taneja9b372c22011-05-06 11:45:49 +05302417 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002418
2419 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002420}
2421
2422static void dispc_disable_isr(void *data, u32 mask)
2423{
2424 struct completion *compl = data;
2425 complete(compl);
2426}
2427
Sumit Semwal2a205f32010-12-02 11:27:12 +00002428static void _enable_lcd_out(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002429{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302430 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2431 /* flush posted write */
2432 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002433}
2434
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002435static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002436{
2437 struct completion frame_done_completion;
2438 bool is_on;
2439 int r;
Sumit Semwal2a205f32010-12-02 11:27:12 +00002440 u32 irq;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002441
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002442 /* When we disable LCD output, we need to wait until frame is done.
2443 * Otherwise the DSS is still working, and turning off the clocks
2444 * prevents DSS from going to OFF mode */
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302445 is_on = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002446
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302447 irq = mgr_desc[channel].framedone_irq;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002448
2449 if (!enable && is_on) {
2450 init_completion(&frame_done_completion);
2451
2452 r = omap_dispc_register_isr(dispc_disable_isr,
Sumit Semwal2a205f32010-12-02 11:27:12 +00002453 &frame_done_completion, irq);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002454
2455 if (r)
2456 DSSERR("failed to register FRAMEDONE isr\n");
2457 }
2458
Sumit Semwal2a205f32010-12-02 11:27:12 +00002459 _enable_lcd_out(channel, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002460
2461 if (!enable && is_on) {
2462 if (!wait_for_completion_timeout(&frame_done_completion,
2463 msecs_to_jiffies(100)))
2464 DSSERR("timeout waiting for FRAME DONE\n");
2465
2466 r = omap_dispc_unregister_isr(dispc_disable_isr,
Sumit Semwal2a205f32010-12-02 11:27:12 +00002467 &frame_done_completion, irq);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002468
2469 if (r)
2470 DSSERR("failed to unregister FRAMEDONE isr\n");
2471 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002472}
2473
2474static void _enable_digit_out(bool enable)
2475{
2476 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
Tomi Valkeinenb6a44e72011-10-12 10:17:02 +03002477 /* flush posted write */
2478 dispc_read_reg(DISPC_CONTROL);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002479}
2480
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002481static void dispc_mgr_enable_digit_out(bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002482{
2483 struct completion frame_done_completion;
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002484 enum dss_hdmi_venc_clk_source_select src;
2485 int r, i;
2486 u32 irq_mask;
2487 int num_irqs;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002488
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002489 if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002490 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002491
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002492 src = dss_get_hdmi_venc_clk_source();
2493
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002494 if (enable) {
2495 unsigned long flags;
2496 /* When we enable digit output, we'll get an extra digit
2497 * sync lost interrupt, that we need to ignore */
2498 spin_lock_irqsave(&dispc.irq_lock, flags);
2499 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
2500 _omap_dispc_set_irqs();
2501 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2502 }
2503
2504 /* When we disable digit output, we need to wait until fields are done.
2505 * Otherwise the DSS is still working, and turning off the clocks
2506 * prevents DSS from going to OFF mode. And when enabling, we need to
2507 * wait for the extra sync losts */
2508 init_completion(&frame_done_completion);
2509
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002510 if (src == DSS_HDMI_M_PCLK && enable == false) {
2511 irq_mask = DISPC_IRQ_FRAMEDONETV;
2512 num_irqs = 1;
2513 } else {
2514 irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
2515 /* XXX I understand from TRM that we should only wait for the
2516 * current field to complete. But it seems we have to wait for
2517 * both fields */
2518 num_irqs = 2;
2519 }
2520
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002521 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002522 irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002523 if (r)
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002524 DSSERR("failed to register %x isr\n", irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002525
2526 _enable_digit_out(enable);
2527
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002528 for (i = 0; i < num_irqs; ++i) {
2529 if (!wait_for_completion_timeout(&frame_done_completion,
2530 msecs_to_jiffies(100)))
2531 DSSERR("timeout waiting for digit out to %s\n",
2532 enable ? "start" : "stop");
2533 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002534
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002535 r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
2536 irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002537 if (r)
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002538 DSSERR("failed to unregister %x isr\n", irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002539
2540 if (enable) {
2541 unsigned long flags;
2542 spin_lock_irqsave(&dispc.irq_lock, flags);
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002543 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002544 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
2545 _omap_dispc_set_irqs();
2546 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2547 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002548}
2549
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002550bool dispc_mgr_is_enabled(enum omap_channel channel)
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002551{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302552 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002553}
2554
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002555void dispc_mgr_enable(enum omap_channel channel, bool enable)
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002556{
Archit Tanejadd88b7a2012-06-29 14:41:30 +05302557 if (dss_mgr_is_lcd(channel))
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002558 dispc_mgr_enable_lcd_out(channel, enable);
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002559 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002560 dispc_mgr_enable_digit_out(enable);
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002561 else
2562 BUG();
2563}
2564
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002565void dispc_lcd_enable_signal_polarity(bool act_high)
2566{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002567 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2568 return;
2569
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002570 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002571}
2572
2573void dispc_lcd_enable_signal(bool enable)
2574{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002575 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2576 return;
2577
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002578 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002579}
2580
2581void dispc_pck_free_enable(bool enable)
2582{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002583 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2584 return;
2585
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002586 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002587}
2588
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002589void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002590{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302591 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002592}
2593
2594
Archit Tanejad21f43b2012-06-21 09:45:11 +05302595void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002596{
Archit Tanejad21f43b2012-06-21 09:45:11 +05302597 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002598}
2599
2600void dispc_set_loadmode(enum omap_dss_load_mode mode)
2601{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002602 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002603}
2604
2605
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002606static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002607{
Sumit Semwal8613b002010-12-02 11:27:09 +00002608 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002609}
2610
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002611static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002612 enum omap_dss_trans_key_type type,
2613 u32 trans_key)
2614{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302615 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002616
Sumit Semwal8613b002010-12-02 11:27:09 +00002617 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002618}
2619
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002620static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002621{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302622 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002623}
Archit Taneja11354dd2011-09-26 11:47:29 +05302624
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002625static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2626 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002627{
Archit Taneja11354dd2011-09-26 11:47:29 +05302628 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002629 return;
2630
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002631 if (ch == OMAP_DSS_CHANNEL_LCD)
2632 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002633 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002634 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002635}
Archit Taneja11354dd2011-09-26 11:47:29 +05302636
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002637void dispc_mgr_setup(enum omap_channel channel,
2638 struct omap_overlay_manager_info *info)
2639{
2640 dispc_mgr_set_default_color(channel, info->default_color);
2641 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2642 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2643 dispc_mgr_enable_alpha_fixed_zorder(channel,
2644 info->partial_alpha_enabled);
2645 if (dss_has_feature(FEAT_CPR)) {
2646 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2647 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2648 }
2649}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002650
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002651void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002652{
2653 int code;
2654
2655 switch (data_lines) {
2656 case 12:
2657 code = 0;
2658 break;
2659 case 16:
2660 code = 1;
2661 break;
2662 case 18:
2663 code = 2;
2664 break;
2665 case 24:
2666 code = 3;
2667 break;
2668 default:
2669 BUG();
2670 return;
2671 }
2672
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302673 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002674}
2675
Archit Taneja569969d2011-08-22 17:41:57 +05302676void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002677{
2678 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302679 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002680
2681 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302682 case DSS_IO_PAD_MODE_RESET:
2683 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002684 gpout1 = 0;
2685 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302686 case DSS_IO_PAD_MODE_RFBI:
2687 gpout0 = 1;
2688 gpout1 = 0;
2689 break;
2690 case DSS_IO_PAD_MODE_BYPASS:
2691 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002692 gpout1 = 1;
2693 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002694 default:
2695 BUG();
2696 return;
2697 }
2698
Archit Taneja569969d2011-08-22 17:41:57 +05302699 l = dispc_read_reg(DISPC_CONTROL);
2700 l = FLD_MOD(l, gpout0, 15, 15);
2701 l = FLD_MOD(l, gpout1, 16, 16);
2702 dispc_write_reg(DISPC_CONTROL, l);
2703}
2704
2705void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2706{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302707 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002708}
2709
Archit Taneja8f366162012-04-16 12:53:44 +05302710static bool _dispc_mgr_size_ok(u16 width, u16 height)
2711{
2712 return width <= dss_feat_get_param_max(FEAT_PARAM_MGR_WIDTH) &&
2713 height <= dss_feat_get_param_max(FEAT_PARAM_MGR_HEIGHT);
2714}
2715
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002716static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2717 int vsw, int vfp, int vbp)
2718{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302719 if (hsw < 1 || hsw > dispc.feat->sw_max ||
2720 hfp < 1 || hfp > dispc.feat->hp_max ||
2721 hbp < 1 || hbp > dispc.feat->hp_max ||
2722 vsw < 1 || vsw > dispc.feat->sw_max ||
2723 vfp < 0 || vfp > dispc.feat->vp_max ||
2724 vbp < 0 || vbp > dispc.feat->vp_max)
2725 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002726 return true;
2727}
2728
Archit Taneja8f366162012-04-16 12:53:44 +05302729bool dispc_mgr_timings_ok(enum omap_channel channel,
Archit Tanejab917fa32012-04-27 01:07:28 +05302730 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002731{
Archit Taneja8f366162012-04-16 12:53:44 +05302732 bool timings_ok;
2733
2734 timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
2735
Archit Tanejadd88b7a2012-06-29 14:41:30 +05302736 if (dss_mgr_is_lcd(channel))
Archit Taneja8f366162012-04-16 12:53:44 +05302737 timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
2738 timings->hfp, timings->hbp,
2739 timings->vsw, timings->vfp,
2740 timings->vbp);
2741
2742 return timings_ok;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002743}
2744
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002745static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
Archit Taneja655e2942012-06-21 10:37:43 +05302746 int hfp, int hbp, int vsw, int vfp, int vbp,
2747 enum omap_dss_signal_level vsync_level,
2748 enum omap_dss_signal_level hsync_level,
2749 enum omap_dss_signal_edge data_pclk_edge,
2750 enum omap_dss_signal_level de_level,
2751 enum omap_dss_signal_edge sync_pclk_edge)
2752
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002753{
Archit Taneja655e2942012-06-21 10:37:43 +05302754 u32 timing_h, timing_v, l;
2755 bool onoff, rf, ipc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002756
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302757 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
2758 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
2759 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
2760 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
2761 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
2762 FLD_VAL(vbp, dispc.feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002763
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002764 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2765 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05302766
2767 switch (data_pclk_edge) {
2768 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2769 ipc = false;
2770 break;
2771 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2772 ipc = true;
2773 break;
2774 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2775 default:
2776 BUG();
2777 }
2778
2779 switch (sync_pclk_edge) {
2780 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2781 onoff = false;
2782 rf = false;
2783 break;
2784 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2785 onoff = true;
2786 rf = false;
2787 break;
2788 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2789 onoff = true;
2790 rf = true;
2791 break;
2792 default:
2793 BUG();
2794 };
2795
2796 l = dispc_read_reg(DISPC_POL_FREQ(channel));
2797 l |= FLD_VAL(onoff, 17, 17);
2798 l |= FLD_VAL(rf, 16, 16);
2799 l |= FLD_VAL(de_level, 15, 15);
2800 l |= FLD_VAL(ipc, 14, 14);
2801 l |= FLD_VAL(hsync_level, 13, 13);
2802 l |= FLD_VAL(vsync_level, 12, 12);
2803 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002804}
2805
2806/* change name to mode? */
Archit Tanejac51d9212012-04-16 12:53:43 +05302807void dispc_mgr_set_timings(enum omap_channel channel,
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002808 struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002809{
2810 unsigned xtot, ytot;
2811 unsigned long ht, vt;
Archit Taneja2aefad42012-05-18 14:36:54 +05302812 struct omap_video_timings t = *timings;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002813
Archit Taneja2aefad42012-05-18 14:36:54 +05302814 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
Archit Tanejac51d9212012-04-16 12:53:43 +05302815
Archit Taneja2aefad42012-05-18 14:36:54 +05302816 if (!dispc_mgr_timings_ok(channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05302817 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002818 return;
2819 }
Archit Tanejac51d9212012-04-16 12:53:43 +05302820
Archit Tanejadd88b7a2012-06-29 14:41:30 +05302821 if (dss_mgr_is_lcd(channel)) {
Archit Taneja2aefad42012-05-18 14:36:54 +05302822 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
Archit Taneja655e2942012-06-21 10:37:43 +05302823 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
2824 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
Archit Tanejac51d9212012-04-16 12:53:43 +05302825
Archit Taneja2aefad42012-05-18 14:36:54 +05302826 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
2827 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
Archit Tanejac51d9212012-04-16 12:53:43 +05302828
2829 ht = (timings->pixel_clock * 1000) / xtot;
2830 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2831
2832 DSSDBG("pck %u\n", timings->pixel_clock);
2833 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Archit Taneja2aefad42012-05-18 14:36:54 +05302834 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
Archit Taneja655e2942012-06-21 10:37:43 +05302835 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
2836 t.vsync_level, t.hsync_level, t.data_pclk_edge,
2837 t.de_level, t.sync_pclk_edge);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002838
Archit Tanejac51d9212012-04-16 12:53:43 +05302839 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05302840 } else {
Archit Taneja23c8f882012-06-28 11:15:51 +05302841 if (t.interlace == true)
Archit Taneja2aefad42012-05-18 14:36:54 +05302842 t.y_res /= 2;
Archit Tanejac51d9212012-04-16 12:53:43 +05302843 }
Archit Taneja8f366162012-04-16 12:53:44 +05302844
Archit Taneja2aefad42012-05-18 14:36:54 +05302845 dispc_mgr_set_size(channel, t.x_res, t.y_res);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002846}
2847
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002848static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002849 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002850{
2851 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03002852 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002853
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06002854 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002855 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002856}
2857
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002858static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00002859 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002860{
2861 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06002862 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002863 *lck_div = FLD_GET(l, 23, 16);
2864 *pck_div = FLD_GET(l, 7, 0);
2865}
2866
2867unsigned long dispc_fclk_rate(void)
2868{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302869 struct platform_device *dsidev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002870 unsigned long r = 0;
2871
Taneja, Archit66534e82011-03-08 05:50:34 -06002872 switch (dss_get_dispc_clk_source()) {
Archit Taneja89a35e52011-04-12 13:52:23 +05302873 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002874 r = clk_get_rate(dispc.dss_clk);
Taneja, Archit66534e82011-03-08 05:50:34 -06002875 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05302876 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302877 dsidev = dsi_get_dsidev_from_id(0);
2878 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
Taneja, Archit66534e82011-03-08 05:50:34 -06002879 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05302880 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2881 dsidev = dsi_get_dsidev_from_id(1);
2882 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2883 break;
Taneja, Archit66534e82011-03-08 05:50:34 -06002884 default:
2885 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002886 return 0;
Taneja, Archit66534e82011-03-08 05:50:34 -06002887 }
2888
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002889 return r;
2890}
2891
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002892unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002893{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302894 struct platform_device *dsidev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002895 int lcd;
2896 unsigned long r;
2897 u32 l;
2898
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06002899 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002900
2901 lcd = FLD_GET(l, 23, 16);
2902
Taneja, Architea751592011-03-08 05:50:35 -06002903 switch (dss_get_lcd_clk_source(channel)) {
Archit Taneja89a35e52011-04-12 13:52:23 +05302904 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002905 r = clk_get_rate(dispc.dss_clk);
Taneja, Architea751592011-03-08 05:50:35 -06002906 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05302907 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302908 dsidev = dsi_get_dsidev_from_id(0);
2909 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
Taneja, Architea751592011-03-08 05:50:35 -06002910 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05302911 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2912 dsidev = dsi_get_dsidev_from_id(1);
2913 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2914 break;
Taneja, Architea751592011-03-08 05:50:35 -06002915 default:
2916 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002917 return 0;
Taneja, Architea751592011-03-08 05:50:35 -06002918 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002919
2920 return r / lcd;
2921}
2922
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002923unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002924{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002925 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002926
Archit Tanejadd88b7a2012-06-29 14:41:30 +05302927 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302928 int pcd;
2929 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002930
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302931 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002932
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302933 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002934
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302935 r = dispc_mgr_lclk_rate(channel);
2936
2937 return r / pcd;
2938 } else {
Archit Taneja3fa03ba2012-04-09 15:06:41 +05302939 enum dss_hdmi_venc_clk_source_select source;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302940
Archit Taneja3fa03ba2012-04-09 15:06:41 +05302941 source = dss_get_hdmi_venc_clk_source();
2942
2943 switch (source) {
2944 case DSS_VENC_TV_CLK:
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302945 return venc_get_pixel_clock();
Archit Taneja3fa03ba2012-04-09 15:06:41 +05302946 case DSS_HDMI_M_PCLK:
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302947 return hdmi_get_pixel_clock();
2948 default:
2949 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002950 return 0;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302951 }
2952 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002953}
2954
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302955unsigned long dispc_core_clk_rate(void)
2956{
2957 int lcd;
2958 unsigned long fclk = dispc_fclk_rate();
2959
2960 if (dss_has_feature(FEAT_CORE_CLK_DIV))
2961 lcd = REG_GET(DISPC_DIVISOR, 23, 16);
2962 else
2963 lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
2964
2965 return fclk / lcd;
2966}
2967
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05302968static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002969{
2970 int lcd, pcd;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05302971 enum omap_dss_clk_source lcd_clk_src;
2972
2973 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
2974
2975 lcd_clk_src = dss_get_lcd_clk_source(channel);
2976
2977 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
2978 dss_get_generic_clk_source_name(lcd_clk_src),
2979 dss_feat_get_clk_source_name(lcd_clk_src));
2980
2981 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
2982
2983 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2984 dispc_mgr_lclk_rate(channel), lcd);
2985 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2986 dispc_mgr_pclk_rate(channel), pcd);
2987}
2988
2989void dispc_dump_clocks(struct seq_file *s)
2990{
2991 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06002992 u32 l;
Archit Taneja89a35e52011-04-12 13:52:23 +05302993 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002994
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002995 if (dispc_runtime_get())
2996 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002997
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002998 seq_printf(s, "- DISPC -\n");
2999
Archit Taneja067a57e2011-03-02 11:57:25 +05303000 seq_printf(s, "dispc fclk source = %s (%s)\n",
3001 dss_get_generic_clk_source_name(dispc_clk_src),
3002 dss_feat_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003003
3004 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00003005
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003006 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3007 seq_printf(s, "- DISPC-CORE-CLK -\n");
3008 l = dispc_read_reg(DISPC_DIVISOR);
3009 lcd = FLD_GET(l, 23, 16);
3010
3011 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3012 (dispc_fclk_rate()/lcd), lcd);
3013 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003014
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303015 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003016
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303017 if (dss_has_feature(FEAT_MGR_LCD2))
3018 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3019 if (dss_has_feature(FEAT_MGR_LCD3))
3020 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003021
3022 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003023}
3024
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003025#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3026void dispc_dump_irqs(struct seq_file *s)
3027{
3028 unsigned long flags;
3029 struct dispc_irq_stats stats;
3030
3031 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
3032
3033 stats = dispc.irq_stats;
3034 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
3035 dispc.irq_stats.last_reset = jiffies;
3036
3037 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
3038
3039 seq_printf(s, "period %u ms\n",
3040 jiffies_to_msecs(jiffies - stats.last_reset));
3041
3042 seq_printf(s, "irqs %d\n", stats.irq_count);
3043#define PIS(x) \
3044 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
3045
3046 PIS(FRAMEDONE);
3047 PIS(VSYNC);
3048 PIS(EVSYNC_EVEN);
3049 PIS(EVSYNC_ODD);
3050 PIS(ACBIAS_COUNT_STAT);
3051 PIS(PROG_LINE_NUM);
3052 PIS(GFX_FIFO_UNDERFLOW);
3053 PIS(GFX_END_WIN);
3054 PIS(PAL_GAMMA_MASK);
3055 PIS(OCP_ERR);
3056 PIS(VID1_FIFO_UNDERFLOW);
3057 PIS(VID1_END_WIN);
3058 PIS(VID2_FIFO_UNDERFLOW);
3059 PIS(VID2_END_WIN);
Archit Tanejab8c095b2011-09-13 18:20:33 +05303060 if (dss_feat_get_num_ovls() > 3) {
3061 PIS(VID3_FIFO_UNDERFLOW);
3062 PIS(VID3_END_WIN);
3063 }
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003064 PIS(SYNC_LOST);
3065 PIS(SYNC_LOST_DIGIT);
3066 PIS(WAKEUP);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003067 if (dss_has_feature(FEAT_MGR_LCD2)) {
3068 PIS(FRAMEDONE2);
3069 PIS(VSYNC2);
3070 PIS(ACBIAS_COUNT_STAT2);
3071 PIS(SYNC_LOST2);
3072 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303073 if (dss_has_feature(FEAT_MGR_LCD3)) {
3074 PIS(FRAMEDONE3);
3075 PIS(VSYNC3);
3076 PIS(ACBIAS_COUNT_STAT3);
3077 PIS(SYNC_LOST3);
3078 }
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003079#undef PIS
3080}
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003081#endif
3082
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003083static void dispc_dump_regs(struct seq_file *s)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003084{
Archit Taneja4dd2da12011-08-05 19:06:01 +05303085 int i, j;
3086 const char *mgr_names[] = {
3087 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3088 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3089 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303090 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303091 };
3092 const char *ovl_names[] = {
3093 [OMAP_DSS_GFX] = "GFX",
3094 [OMAP_DSS_VIDEO1] = "VID1",
3095 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303096 [OMAP_DSS_VIDEO3] = "VID3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303097 };
3098 const char **p_names;
3099
Archit Taneja9b372c22011-05-06 11:45:49 +05303100#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003101
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003102 if (dispc_runtime_get())
3103 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003104
Archit Taneja5010be82011-08-05 19:06:00 +05303105 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003106 DUMPREG(DISPC_REVISION);
3107 DUMPREG(DISPC_SYSCONFIG);
3108 DUMPREG(DISPC_SYSSTATUS);
3109 DUMPREG(DISPC_IRQSTATUS);
3110 DUMPREG(DISPC_IRQENABLE);
3111 DUMPREG(DISPC_CONTROL);
3112 DUMPREG(DISPC_CONFIG);
3113 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003114 DUMPREG(DISPC_LINE_STATUS);
3115 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05303116 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3117 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003118 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003119 if (dss_has_feature(FEAT_MGR_LCD2)) {
3120 DUMPREG(DISPC_CONTROL2);
3121 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003122 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303123 if (dss_has_feature(FEAT_MGR_LCD3)) {
3124 DUMPREG(DISPC_CONTROL3);
3125 DUMPREG(DISPC_CONFIG3);
3126 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003127
Archit Taneja5010be82011-08-05 19:06:00 +05303128#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003129
Archit Taneja5010be82011-08-05 19:06:00 +05303130#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05303131#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3132 48 - strlen(#r) - strlen(p_names[i]), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303133 dispc_read_reg(DISPC_REG(i, r)))
3134
Archit Taneja4dd2da12011-08-05 19:06:01 +05303135 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303136
Archit Taneja4dd2da12011-08-05 19:06:01 +05303137 /* DISPC channel specific registers */
3138 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3139 DUMPREG(i, DISPC_DEFAULT_COLOR);
3140 DUMPREG(i, DISPC_TRANS_COLOR);
3141 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003142
Archit Taneja4dd2da12011-08-05 19:06:01 +05303143 if (i == OMAP_DSS_CHANNEL_DIGIT)
3144 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303145
Archit Taneja4dd2da12011-08-05 19:06:01 +05303146 DUMPREG(i, DISPC_DEFAULT_COLOR);
3147 DUMPREG(i, DISPC_TRANS_COLOR);
3148 DUMPREG(i, DISPC_TIMING_H);
3149 DUMPREG(i, DISPC_TIMING_V);
3150 DUMPREG(i, DISPC_POL_FREQ);
3151 DUMPREG(i, DISPC_DIVISORo);
3152 DUMPREG(i, DISPC_SIZE_MGR);
Archit Taneja5010be82011-08-05 19:06:00 +05303153
Archit Taneja4dd2da12011-08-05 19:06:01 +05303154 DUMPREG(i, DISPC_DATA_CYCLE1);
3155 DUMPREG(i, DISPC_DATA_CYCLE2);
3156 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003157
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003158 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303159 DUMPREG(i, DISPC_CPR_COEF_R);
3160 DUMPREG(i, DISPC_CPR_COEF_G);
3161 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003162 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003163 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003164
Archit Taneja4dd2da12011-08-05 19:06:01 +05303165 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003166
Archit Taneja4dd2da12011-08-05 19:06:01 +05303167 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3168 DUMPREG(i, DISPC_OVL_BA0);
3169 DUMPREG(i, DISPC_OVL_BA1);
3170 DUMPREG(i, DISPC_OVL_POSITION);
3171 DUMPREG(i, DISPC_OVL_SIZE);
3172 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3173 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3174 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3175 DUMPREG(i, DISPC_OVL_ROW_INC);
3176 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3177 if (dss_has_feature(FEAT_PRELOAD))
3178 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003179
Archit Taneja4dd2da12011-08-05 19:06:01 +05303180 if (i == OMAP_DSS_GFX) {
3181 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3182 DUMPREG(i, DISPC_OVL_TABLE_BA);
3183 continue;
3184 }
3185
3186 DUMPREG(i, DISPC_OVL_FIR);
3187 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3188 DUMPREG(i, DISPC_OVL_ACCU0);
3189 DUMPREG(i, DISPC_OVL_ACCU1);
3190 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3191 DUMPREG(i, DISPC_OVL_BA0_UV);
3192 DUMPREG(i, DISPC_OVL_BA1_UV);
3193 DUMPREG(i, DISPC_OVL_FIR2);
3194 DUMPREG(i, DISPC_OVL_ACCU2_0);
3195 DUMPREG(i, DISPC_OVL_ACCU2_1);
3196 }
3197 if (dss_has_feature(FEAT_ATTR2))
3198 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3199 if (dss_has_feature(FEAT_PRELOAD))
3200 DUMPREG(i, DISPC_OVL_PRELOAD);
Archit Taneja5010be82011-08-05 19:06:00 +05303201 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003202
Archit Taneja5010be82011-08-05 19:06:00 +05303203#undef DISPC_REG
3204#undef DUMPREG
3205
3206#define DISPC_REG(plane, name, i) name(plane, i)
3207#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303208 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3209 46 - strlen(#name) - strlen(p_names[plane]), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303210 dispc_read_reg(DISPC_REG(plane, name, i)))
3211
Archit Taneja4dd2da12011-08-05 19:06:01 +05303212 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303213
Archit Taneja4dd2da12011-08-05 19:06:01 +05303214 /* start from OMAP_DSS_VIDEO1 */
3215 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3216 for (j = 0; j < 8; j++)
3217 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303218
Archit Taneja4dd2da12011-08-05 19:06:01 +05303219 for (j = 0; j < 8; j++)
3220 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303221
Archit Taneja4dd2da12011-08-05 19:06:01 +05303222 for (j = 0; j < 5; j++)
3223 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003224
Archit Taneja4dd2da12011-08-05 19:06:01 +05303225 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3226 for (j = 0; j < 8; j++)
3227 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3228 }
Amber Jainab5ca072011-05-19 19:47:53 +05303229
Archit Taneja4dd2da12011-08-05 19:06:01 +05303230 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3231 for (j = 0; j < 8; j++)
3232 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303233
Archit Taneja4dd2da12011-08-05 19:06:01 +05303234 for (j = 0; j < 8; j++)
3235 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303236
Archit Taneja4dd2da12011-08-05 19:06:01 +05303237 for (j = 0; j < 8; j++)
3238 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3239 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003240 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003241
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003242 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05303243
3244#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003245#undef DUMPREG
3246}
3247
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003248/* with fck as input clock rate, find dispc dividers that produce req_pck */
Archit Taneja6d523e72012-06-21 09:33:55 +05303249void dispc_find_clk_divs(unsigned long req_pck, unsigned long fck,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003250 struct dispc_clock_info *cinfo)
3251{
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003252 u16 pcd_min, pcd_max;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003253 unsigned long best_pck;
3254 u16 best_ld, cur_ld;
3255 u16 best_pd, cur_pd;
3256
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003257 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3258 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3259
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003260 best_pck = 0;
3261 best_ld = 0;
3262 best_pd = 0;
3263
3264 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
3265 unsigned long lck = fck / cur_ld;
3266
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003267 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003268 unsigned long pck = lck / cur_pd;
3269 long old_delta = abs(best_pck - req_pck);
3270 long new_delta = abs(pck - req_pck);
3271
3272 if (best_pck == 0 || new_delta < old_delta) {
3273 best_pck = pck;
3274 best_ld = cur_ld;
3275 best_pd = cur_pd;
3276
3277 if (pck == req_pck)
3278 goto found;
3279 }
3280
3281 if (pck < req_pck)
3282 break;
3283 }
3284
3285 if (lck / pcd_min < req_pck)
3286 break;
3287 }
3288
3289found:
3290 cinfo->lck_div = best_ld;
3291 cinfo->pck_div = best_pd;
3292 cinfo->lck = fck / cinfo->lck_div;
3293 cinfo->pck = cinfo->lck / cinfo->pck_div;
3294}
3295
3296/* calculate clock rates using dividers in cinfo */
3297int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3298 struct dispc_clock_info *cinfo)
3299{
3300 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3301 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003302 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003303 return -EINVAL;
3304
3305 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3306 cinfo->pck = cinfo->lck / cinfo->pck_div;
3307
3308 return 0;
3309}
3310
Archit Tanejaf0d08f82012-06-29 14:00:54 +05303311void dispc_mgr_set_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003312 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003313{
3314 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3315 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3316
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003317 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003318}
3319
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003320int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003321 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003322{
3323 unsigned long fck;
3324
3325 fck = dispc_fclk_rate();
3326
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003327 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3328 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003329
3330 cinfo->lck = fck / cinfo->lck_div;
3331 cinfo->pck = cinfo->lck / cinfo->pck_div;
3332
3333 return 0;
3334}
3335
3336/* dispc.irq_lock has to be locked by the caller */
3337static void _omap_dispc_set_irqs(void)
3338{
3339 u32 mask;
3340 u32 old_mask;
3341 int i;
3342 struct omap_dispc_isr_data *isr_data;
3343
3344 mask = dispc.irq_error_mask;
3345
3346 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3347 isr_data = &dispc.registered_isr[i];
3348
3349 if (isr_data->isr == NULL)
3350 continue;
3351
3352 mask |= isr_data->mask;
3353 }
3354
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003355 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3356 /* clear the irqstatus for newly enabled irqs */
3357 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
3358
3359 dispc_write_reg(DISPC_IRQENABLE, mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003360}
3361
3362int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3363{
3364 int i;
3365 int ret;
3366 unsigned long flags;
3367 struct omap_dispc_isr_data *isr_data;
3368
3369 if (isr == NULL)
3370 return -EINVAL;
3371
3372 spin_lock_irqsave(&dispc.irq_lock, flags);
3373
3374 /* check for duplicate entry */
3375 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3376 isr_data = &dispc.registered_isr[i];
3377 if (isr_data->isr == isr && isr_data->arg == arg &&
3378 isr_data->mask == mask) {
3379 ret = -EINVAL;
3380 goto err;
3381 }
3382 }
3383
3384 isr_data = NULL;
3385 ret = -EBUSY;
3386
3387 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3388 isr_data = &dispc.registered_isr[i];
3389
3390 if (isr_data->isr != NULL)
3391 continue;
3392
3393 isr_data->isr = isr;
3394 isr_data->arg = arg;
3395 isr_data->mask = mask;
3396 ret = 0;
3397
3398 break;
3399 }
3400
Tomi Valkeinenb9cb0982011-03-04 18:19:54 +02003401 if (ret)
3402 goto err;
3403
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003404 _omap_dispc_set_irqs();
3405
3406 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3407
3408 return 0;
3409err:
3410 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3411
3412 return ret;
3413}
3414EXPORT_SYMBOL(omap_dispc_register_isr);
3415
3416int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3417{
3418 int i;
3419 unsigned long flags;
3420 int ret = -EINVAL;
3421 struct omap_dispc_isr_data *isr_data;
3422
3423 spin_lock_irqsave(&dispc.irq_lock, flags);
3424
3425 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3426 isr_data = &dispc.registered_isr[i];
3427 if (isr_data->isr != isr || isr_data->arg != arg ||
3428 isr_data->mask != mask)
3429 continue;
3430
3431 /* found the correct isr */
3432
3433 isr_data->isr = NULL;
3434 isr_data->arg = NULL;
3435 isr_data->mask = 0;
3436
3437 ret = 0;
3438 break;
3439 }
3440
3441 if (ret == 0)
3442 _omap_dispc_set_irqs();
3443
3444 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3445
3446 return ret;
3447}
3448EXPORT_SYMBOL(omap_dispc_unregister_isr);
3449
3450#ifdef DEBUG
3451static void print_irq_status(u32 status)
3452{
3453 if ((status & dispc.irq_error_mask) == 0)
3454 return;
3455
3456 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
3457
3458#define PIS(x) \
3459 if (status & DISPC_IRQ_##x) \
3460 printk(#x " ");
3461 PIS(GFX_FIFO_UNDERFLOW);
3462 PIS(OCP_ERR);
3463 PIS(VID1_FIFO_UNDERFLOW);
3464 PIS(VID2_FIFO_UNDERFLOW);
Archit Tanejab8c095b2011-09-13 18:20:33 +05303465 if (dss_feat_get_num_ovls() > 3)
3466 PIS(VID3_FIFO_UNDERFLOW);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003467 PIS(SYNC_LOST);
3468 PIS(SYNC_LOST_DIGIT);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003469 if (dss_has_feature(FEAT_MGR_LCD2))
3470 PIS(SYNC_LOST2);
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303471 if (dss_has_feature(FEAT_MGR_LCD3))
3472 PIS(SYNC_LOST3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003473#undef PIS
3474
3475 printk("\n");
3476}
3477#endif
3478
3479/* Called from dss.c. Note that we don't touch clocks here,
3480 * but we presume they are on because we got an IRQ. However,
3481 * an irq handler may turn the clocks off, so we may not have
3482 * clock later in the function. */
archit tanejaaffe3602011-02-23 08:41:03 +00003483static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003484{
3485 int i;
archit tanejaaffe3602011-02-23 08:41:03 +00003486 u32 irqstatus, irqenable;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003487 u32 handledirqs = 0;
3488 u32 unhandled_errors;
3489 struct omap_dispc_isr_data *isr_data;
3490 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
3491
3492 spin_lock(&dispc.irq_lock);
3493
3494 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
archit tanejaaffe3602011-02-23 08:41:03 +00003495 irqenable = dispc_read_reg(DISPC_IRQENABLE);
3496
3497 /* IRQ is not for us */
3498 if (!(irqstatus & irqenable)) {
3499 spin_unlock(&dispc.irq_lock);
3500 return IRQ_NONE;
3501 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003502
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003503#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3504 spin_lock(&dispc.irq_stats_lock);
3505 dispc.irq_stats.irq_count++;
3506 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
3507 spin_unlock(&dispc.irq_stats_lock);
3508#endif
3509
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003510#ifdef DEBUG
3511 if (dss_debug)
3512 print_irq_status(irqstatus);
3513#endif
3514 /* Ack the interrupt. Do it here before clocks are possibly turned
3515 * off */
3516 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
3517 /* flush posted write */
3518 dispc_read_reg(DISPC_IRQSTATUS);
3519
3520 /* make a copy and unlock, so that isrs can unregister
3521 * themselves */
3522 memcpy(registered_isr, dispc.registered_isr,
3523 sizeof(registered_isr));
3524
3525 spin_unlock(&dispc.irq_lock);
3526
3527 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3528 isr_data = &registered_isr[i];
3529
3530 if (!isr_data->isr)
3531 continue;
3532
3533 if (isr_data->mask & irqstatus) {
3534 isr_data->isr(isr_data->arg, irqstatus);
3535 handledirqs |= isr_data->mask;
3536 }
3537 }
3538
3539 spin_lock(&dispc.irq_lock);
3540
3541 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3542
3543 if (unhandled_errors) {
3544 dispc.error_irqs |= unhandled_errors;
3545
3546 dispc.irq_error_mask &= ~unhandled_errors;
3547 _omap_dispc_set_irqs();
3548
3549 schedule_work(&dispc.error_work);
3550 }
3551
3552 spin_unlock(&dispc.irq_lock);
archit tanejaaffe3602011-02-23 08:41:03 +00003553
3554 return IRQ_HANDLED;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003555}
3556
3557static void dispc_error_worker(struct work_struct *work)
3558{
3559 int i;
3560 u32 errors;
3561 unsigned long flags;
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003562 static const unsigned fifo_underflow_bits[] = {
3563 DISPC_IRQ_GFX_FIFO_UNDERFLOW,
3564 DISPC_IRQ_VID1_FIFO_UNDERFLOW,
3565 DISPC_IRQ_VID2_FIFO_UNDERFLOW,
Archit Tanejab8c095b2011-09-13 18:20:33 +05303566 DISPC_IRQ_VID3_FIFO_UNDERFLOW,
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003567 };
3568
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003569 spin_lock_irqsave(&dispc.irq_lock, flags);
3570 errors = dispc.error_irqs;
3571 dispc.error_irqs = 0;
3572 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3573
Dima Zavin13eae1f2011-06-27 10:31:05 -07003574 dispc_runtime_get();
3575
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003576 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3577 struct omap_overlay *ovl;
3578 unsigned bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003579
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003580 ovl = omap_dss_get_overlay(i);
3581 bit = fifo_underflow_bits[i];
3582
3583 if (bit & errors) {
3584 DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
3585 ovl->name);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03003586 dispc_ovl_enable(ovl->id, false);
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003587 dispc_mgr_go(ovl->manager->id);
Jassi Brard7ad7182012-07-24 19:33:55 +05303588 msleep(50);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003589 }
3590 }
3591
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003592 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3593 struct omap_overlay_manager *mgr;
3594 unsigned bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003595
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003596 mgr = omap_dss_get_overlay_manager(i);
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05303597 bit = mgr_desc[i].sync_lost_irq;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003598
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003599 if (bit & errors) {
Archit Taneja794bc4e2012-09-07 17:44:51 +05303600 struct omap_dss_device *dssdev = mgr->get_device(mgr);
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003601 bool enable;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003602
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003603 DSSERR("SYNC_LOST on channel %s, restarting the output "
3604 "with video overlays disabled\n",
3605 mgr->name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003606
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003607 enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
3608 dssdev->driver->disable(dssdev);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003609
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003610 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3611 struct omap_overlay *ovl;
3612 ovl = omap_dss_get_overlay(i);
3613
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003614 if (ovl->id != OMAP_DSS_GFX &&
3615 ovl->manager == mgr)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03003616 dispc_ovl_enable(ovl->id, false);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003617 }
3618
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003619 dispc_mgr_go(mgr->id);
Jassi Brard7ad7182012-07-24 19:33:55 +05303620 msleep(50);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003621
Sumit Semwal2a205f32010-12-02 11:27:12 +00003622 if (enable)
3623 dssdev->driver->enable(dssdev);
3624 }
3625 }
3626
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003627 if (errors & DISPC_IRQ_OCP_ERR) {
3628 DSSERR("OCP_ERR\n");
3629 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3630 struct omap_overlay_manager *mgr;
Archit Taneja794bc4e2012-09-07 17:44:51 +05303631 struct omap_dss_device *dssdev;
3632
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003633 mgr = omap_dss_get_overlay_manager(i);
Archit Taneja794bc4e2012-09-07 17:44:51 +05303634 dssdev = mgr->get_device(mgr);
3635
3636 if (dssdev && dssdev->driver)
3637 dssdev->driver->disable(dssdev);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003638 }
3639 }
3640
3641 spin_lock_irqsave(&dispc.irq_lock, flags);
3642 dispc.irq_error_mask |= errors;
3643 _omap_dispc_set_irqs();
3644 spin_unlock_irqrestore(&dispc.irq_lock, flags);
Dima Zavin13eae1f2011-06-27 10:31:05 -07003645
3646 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003647}
3648
3649int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3650{
3651 void dispc_irq_wait_handler(void *data, u32 mask)
3652 {
3653 complete((struct completion *)data);
3654 }
3655
3656 int r;
3657 DECLARE_COMPLETION_ONSTACK(completion);
3658
3659 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3660 irqmask);
3661
3662 if (r)
3663 return r;
3664
3665 timeout = wait_for_completion_timeout(&completion, timeout);
3666
3667 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3668
3669 if (timeout == 0)
3670 return -ETIMEDOUT;
3671
3672 if (timeout == -ERESTARTSYS)
3673 return -ERESTARTSYS;
3674
3675 return 0;
3676}
3677
3678int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3679 unsigned long timeout)
3680{
3681 void dispc_irq_wait_handler(void *data, u32 mask)
3682 {
3683 complete((struct completion *)data);
3684 }
3685
3686 int r;
3687 DECLARE_COMPLETION_ONSTACK(completion);
3688
3689 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3690 irqmask);
3691
3692 if (r)
3693 return r;
3694
3695 timeout = wait_for_completion_interruptible_timeout(&completion,
3696 timeout);
3697
3698 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3699
3700 if (timeout == 0)
3701 return -ETIMEDOUT;
3702
3703 if (timeout == -ERESTARTSYS)
3704 return -ERESTARTSYS;
3705
3706 return 0;
3707}
3708
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003709static void _omap_dispc_initialize_irq(void)
3710{
3711 unsigned long flags;
3712
3713 spin_lock_irqsave(&dispc.irq_lock, flags);
3714
3715 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3716
3717 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
Sumit Semwal2a205f32010-12-02 11:27:12 +00003718 if (dss_has_feature(FEAT_MGR_LCD2))
3719 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05303720 if (dss_has_feature(FEAT_MGR_LCD3))
3721 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST3;
Archit Tanejab8c095b2011-09-13 18:20:33 +05303722 if (dss_feat_get_num_ovls() > 3)
3723 dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003724
3725 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3726 * so clear it */
3727 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3728
3729 _omap_dispc_set_irqs();
3730
3731 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3732}
3733
3734void dispc_enable_sidle(void)
3735{
3736 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3737}
3738
3739void dispc_disable_sidle(void)
3740{
3741 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3742}
3743
3744static void _omap_dispc_initial_config(void)
3745{
3746 u32 l;
3747
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003748 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3749 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3750 l = dispc_read_reg(DISPC_DIVISOR);
3751 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3752 l = FLD_MOD(l, 1, 0, 0);
3753 l = FLD_MOD(l, 1, 23, 16);
3754 dispc_write_reg(DISPC_DIVISOR, l);
3755 }
3756
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003757 /* FUNCGATED */
Archit Taneja6ced40b2010-12-02 11:27:13 +00003758 if (dss_has_feature(FEAT_FUNCGATED))
3759 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003760
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003761 _dispc_setup_color_conv_coef();
3762
3763 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3764
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003765 dispc_init_fifos();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003766
3767 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05303768
3769 dispc_ovl_enable_zorder_planes();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003770}
3771
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303772static const struct dispc_features omap24xx_dispc_feats __initconst = {
3773 .sw_start = 5,
3774 .fp_start = 15,
3775 .bp_start = 27,
3776 .sw_max = 64,
3777 .vp_max = 255,
3778 .hp_max = 256,
3779 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3780 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003781 .num_fifos = 3,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303782};
3783
3784static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
3785 .sw_start = 5,
3786 .fp_start = 15,
3787 .bp_start = 27,
3788 .sw_max = 64,
3789 .vp_max = 255,
3790 .hp_max = 256,
3791 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3792 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003793 .num_fifos = 3,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303794};
3795
3796static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
3797 .sw_start = 7,
3798 .fp_start = 19,
3799 .bp_start = 31,
3800 .sw_max = 256,
3801 .vp_max = 4095,
3802 .hp_max = 4096,
3803 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3804 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003805 .num_fifos = 3,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303806};
3807
3808static const struct dispc_features omap44xx_dispc_feats __initconst = {
3809 .sw_start = 7,
3810 .fp_start = 19,
3811 .bp_start = 31,
3812 .sw_max = 256,
3813 .vp_max = 4095,
3814 .hp_max = 4096,
3815 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3816 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003817 .num_fifos = 5,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03003818 .gfx_fifo_workaround = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303819};
3820
3821static int __init dispc_init_features(struct device *dev)
3822{
3823 const struct dispc_features *src;
3824 struct dispc_features *dst;
3825
3826 dst = devm_kzalloc(dev, sizeof(*dst), GFP_KERNEL);
3827 if (!dst) {
3828 dev_err(dev, "Failed to allocate DISPC Features\n");
3829 return -ENOMEM;
3830 }
3831
3832 if (cpu_is_omap24xx()) {
3833 src = &omap24xx_dispc_feats;
3834 } else if (cpu_is_omap34xx()) {
3835 if (omap_rev() < OMAP3430_REV_ES3_0)
3836 src = &omap34xx_rev1_0_dispc_feats;
3837 else
3838 src = &omap34xx_rev3_0_dispc_feats;
3839 } else if (cpu_is_omap44xx()) {
3840 src = &omap44xx_dispc_feats;
Archit Taneja23362832012-04-08 16:47:01 +05303841 } else if (soc_is_omap54xx()) {
3842 src = &omap44xx_dispc_feats;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303843 } else {
3844 return -ENODEV;
3845 }
3846
3847 memcpy(dst, src, sizeof(*dst));
3848 dispc.feat = dst;
3849
3850 return 0;
3851}
3852
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003853/* DISPC HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003854static int __init omap_dispchw_probe(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003855{
3856 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00003857 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003858 struct resource *dispc_mem;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003859 struct clk *clk;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003860
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003861 dispc.pdev = pdev;
3862
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303863 r = dispc_init_features(&dispc.pdev->dev);
3864 if (r)
3865 return r;
3866
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003867 spin_lock_init(&dispc.irq_lock);
3868
3869#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3870 spin_lock_init(&dispc.irq_stats_lock);
3871 dispc.irq_stats.last_reset = jiffies;
3872#endif
3873
3874 INIT_WORK(&dispc.error_work, dispc_error_worker);
3875
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003876 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3877 if (!dispc_mem) {
3878 DSSERR("can't get IORESOURCE_MEM DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003879 return -EINVAL;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003880 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003881
Julia Lawall6e2a14d2012-01-24 14:00:45 +01003882 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3883 resource_size(dispc_mem));
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003884 if (!dispc.base) {
3885 DSSERR("can't ioremap DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003886 return -ENOMEM;
archit tanejaaffe3602011-02-23 08:41:03 +00003887 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003888
archit tanejaaffe3602011-02-23 08:41:03 +00003889 dispc.irq = platform_get_irq(dispc.pdev, 0);
3890 if (dispc.irq < 0) {
3891 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003892 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00003893 }
3894
Julia Lawall6e2a14d2012-01-24 14:00:45 +01003895 r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
3896 IRQF_SHARED, "OMAP DISPC", dispc.pdev);
archit tanejaaffe3602011-02-23 08:41:03 +00003897 if (r < 0) {
3898 DSSERR("request_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003899 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003900 }
3901
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003902 clk = clk_get(&pdev->dev, "fck");
3903 if (IS_ERR(clk)) {
3904 DSSERR("can't get fck\n");
3905 r = PTR_ERR(clk);
3906 return r;
3907 }
3908
3909 dispc.dss_clk = clk;
3910
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003911 pm_runtime_enable(&pdev->dev);
3912
3913 r = dispc_runtime_get();
3914 if (r)
3915 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003916
3917 _omap_dispc_initial_config();
3918
3919 _omap_dispc_initialize_irq();
3920
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003921 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00003922 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003923 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3924
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003925 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003926
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003927 dss_debugfs_create_file("dispc", dispc_dump_regs);
3928
3929#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3930 dss_debugfs_create_file("dispc_irq", dispc_dump_irqs);
3931#endif
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003932 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003933
3934err_runtime_get:
3935 pm_runtime_disable(&pdev->dev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003936 clk_put(dispc.dss_clk);
archit tanejaaffe3602011-02-23 08:41:03 +00003937 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003938}
3939
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003940static int __exit omap_dispchw_remove(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003941{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003942 pm_runtime_disable(&pdev->dev);
3943
3944 clk_put(dispc.dss_clk);
3945
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003946 return 0;
3947}
3948
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003949static int dispc_runtime_suspend(struct device *dev)
3950{
3951 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003952
3953 return 0;
3954}
3955
3956static int dispc_runtime_resume(struct device *dev)
3957{
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +03003958 dispc_restore_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003959
3960 return 0;
3961}
3962
3963static const struct dev_pm_ops dispc_pm_ops = {
3964 .runtime_suspend = dispc_runtime_suspend,
3965 .runtime_resume = dispc_runtime_resume,
3966};
3967
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003968static struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003969 .remove = __exit_p(omap_dispchw_remove),
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003970 .driver = {
3971 .name = "omapdss_dispc",
3972 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003973 .pm = &dispc_pm_ops,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003974 },
3975};
3976
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003977int __init dispc_init_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003978{
Tomi Valkeinen11436e12012-03-07 12:53:18 +02003979 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003980}
3981
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003982void __exit dispc_uninit_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003983{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02003984 platform_driver_unregister(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003985}