blob: 4e04a73a8ff38ad07a5111668fc47377253fd010 [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>
28#include <linux/clk.h>
29#include <linux/io.h>
30#include <linux/jiffies.h>
31#include <linux/seq_file.h>
32#include <linux/delay.h>
33#include <linux/workqueue.h>
Tomi Valkeinenab83b142010-06-09 15:31:01 +030034#include <linux/hardirq.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020035
36#include <plat/sram.h>
37#include <plat/clock.h>
38
39#include <plat/display.h>
40
41#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053042#include "dss_features.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020043
44/* DISPC */
45#define DISPC_BASE 0x48050400
46
47#define DISPC_SZ_REGS SZ_1K
48
49struct dispc_reg { u16 idx; };
50
51#define DISPC_REG(idx) ((const struct dispc_reg) { idx })
52
53/* DISPC common */
54#define DISPC_REVISION DISPC_REG(0x0000)
55#define DISPC_SYSCONFIG DISPC_REG(0x0010)
56#define DISPC_SYSSTATUS DISPC_REG(0x0014)
57#define DISPC_IRQSTATUS DISPC_REG(0x0018)
58#define DISPC_IRQENABLE DISPC_REG(0x001C)
59#define DISPC_CONTROL DISPC_REG(0x0040)
60#define DISPC_CONFIG DISPC_REG(0x0044)
61#define DISPC_CAPABLE DISPC_REG(0x0048)
62#define DISPC_DEFAULT_COLOR0 DISPC_REG(0x004C)
63#define DISPC_DEFAULT_COLOR1 DISPC_REG(0x0050)
64#define DISPC_TRANS_COLOR0 DISPC_REG(0x0054)
65#define DISPC_TRANS_COLOR1 DISPC_REG(0x0058)
66#define DISPC_LINE_STATUS DISPC_REG(0x005C)
67#define DISPC_LINE_NUMBER DISPC_REG(0x0060)
68#define DISPC_TIMING_H DISPC_REG(0x0064)
69#define DISPC_TIMING_V DISPC_REG(0x0068)
70#define DISPC_POL_FREQ DISPC_REG(0x006C)
71#define DISPC_DIVISOR DISPC_REG(0x0070)
72#define DISPC_GLOBAL_ALPHA DISPC_REG(0x0074)
73#define DISPC_SIZE_DIG DISPC_REG(0x0078)
74#define DISPC_SIZE_LCD DISPC_REG(0x007C)
75
76/* DISPC GFX plane */
77#define DISPC_GFX_BA0 DISPC_REG(0x0080)
78#define DISPC_GFX_BA1 DISPC_REG(0x0084)
79#define DISPC_GFX_POSITION DISPC_REG(0x0088)
80#define DISPC_GFX_SIZE DISPC_REG(0x008C)
81#define DISPC_GFX_ATTRIBUTES DISPC_REG(0x00A0)
82#define DISPC_GFX_FIFO_THRESHOLD DISPC_REG(0x00A4)
83#define DISPC_GFX_FIFO_SIZE_STATUS DISPC_REG(0x00A8)
84#define DISPC_GFX_ROW_INC DISPC_REG(0x00AC)
85#define DISPC_GFX_PIXEL_INC DISPC_REG(0x00B0)
86#define DISPC_GFX_WINDOW_SKIP DISPC_REG(0x00B4)
87#define DISPC_GFX_TABLE_BA DISPC_REG(0x00B8)
88
89#define DISPC_DATA_CYCLE1 DISPC_REG(0x01D4)
90#define DISPC_DATA_CYCLE2 DISPC_REG(0x01D8)
91#define DISPC_DATA_CYCLE3 DISPC_REG(0x01DC)
92
93#define DISPC_CPR_COEF_R DISPC_REG(0x0220)
94#define DISPC_CPR_COEF_G DISPC_REG(0x0224)
95#define DISPC_CPR_COEF_B DISPC_REG(0x0228)
96
97#define DISPC_GFX_PRELOAD DISPC_REG(0x022C)
98
99/* DISPC Video plane, n = 0 for VID1 and n = 1 for VID2 */
100#define DISPC_VID_REG(n, idx) DISPC_REG(0x00BC + (n)*0x90 + idx)
101
102#define DISPC_VID_BA0(n) DISPC_VID_REG(n, 0x0000)
103#define DISPC_VID_BA1(n) DISPC_VID_REG(n, 0x0004)
104#define DISPC_VID_POSITION(n) DISPC_VID_REG(n, 0x0008)
105#define DISPC_VID_SIZE(n) DISPC_VID_REG(n, 0x000C)
106#define DISPC_VID_ATTRIBUTES(n) DISPC_VID_REG(n, 0x0010)
107#define DISPC_VID_FIFO_THRESHOLD(n) DISPC_VID_REG(n, 0x0014)
108#define DISPC_VID_FIFO_SIZE_STATUS(n) DISPC_VID_REG(n, 0x0018)
109#define DISPC_VID_ROW_INC(n) DISPC_VID_REG(n, 0x001C)
110#define DISPC_VID_PIXEL_INC(n) DISPC_VID_REG(n, 0x0020)
111#define DISPC_VID_FIR(n) DISPC_VID_REG(n, 0x0024)
112#define DISPC_VID_PICTURE_SIZE(n) DISPC_VID_REG(n, 0x0028)
113#define DISPC_VID_ACCU0(n) DISPC_VID_REG(n, 0x002C)
114#define DISPC_VID_ACCU1(n) DISPC_VID_REG(n, 0x0030)
115
116/* coef index i = {0, 1, 2, 3, 4, 5, 6, 7} */
117#define DISPC_VID_FIR_COEF_H(n, i) DISPC_REG(0x00F0 + (n)*0x90 + (i)*0x8)
118/* coef index i = {0, 1, 2, 3, 4, 5, 6, 7} */
119#define DISPC_VID_FIR_COEF_HV(n, i) DISPC_REG(0x00F4 + (n)*0x90 + (i)*0x8)
120/* coef index i = {0, 1, 2, 3, 4} */
121#define DISPC_VID_CONV_COEF(n, i) DISPC_REG(0x0130 + (n)*0x90 + (i)*0x4)
122/* coef index i = {0, 1, 2, 3, 4, 5, 6, 7} */
123#define DISPC_VID_FIR_COEF_V(n, i) DISPC_REG(0x01E0 + (n)*0x20 + (i)*0x4)
124
125#define DISPC_VID_PRELOAD(n) DISPC_REG(0x230 + (n)*0x04)
126
127
128#define DISPC_IRQ_MASK_ERROR (DISPC_IRQ_GFX_FIFO_UNDERFLOW | \
129 DISPC_IRQ_OCP_ERR | \
130 DISPC_IRQ_VID1_FIFO_UNDERFLOW | \
131 DISPC_IRQ_VID2_FIFO_UNDERFLOW | \
132 DISPC_IRQ_SYNC_LOST | \
133 DISPC_IRQ_SYNC_LOST_DIGIT)
134
135#define DISPC_MAX_NR_ISRS 8
136
137struct omap_dispc_isr_data {
138 omap_dispc_isr_t isr;
139 void *arg;
140 u32 mask;
141};
142
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200143struct dispc_h_coef {
144 s8 hc4;
145 s8 hc3;
146 u8 hc2;
147 s8 hc1;
148 s8 hc0;
149};
150
151struct dispc_v_coef {
152 s8 vc22;
153 s8 vc2;
154 u8 vc1;
155 s8 vc0;
156 s8 vc00;
157};
158
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200159#define REG_GET(idx, start, end) \
160 FLD_GET(dispc_read_reg(idx), start, end)
161
162#define REG_FLD_MOD(idx, val, start, end) \
163 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
164
165static const struct dispc_reg dispc_reg_att[] = { DISPC_GFX_ATTRIBUTES,
166 DISPC_VID_ATTRIBUTES(0),
167 DISPC_VID_ATTRIBUTES(1) };
168
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200169struct dispc_irq_stats {
170 unsigned long last_reset;
171 unsigned irq_count;
172 unsigned irqs[32];
173};
174
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200175static struct {
176 void __iomem *base;
177
178 u32 fifo_size[3];
179
180 spinlock_t irq_lock;
181 u32 irq_error_mask;
182 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
183 u32 error_irqs;
184 struct work_struct error_work;
185
186 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200187
188#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
189 spinlock_t irq_stats_lock;
190 struct dispc_irq_stats irq_stats;
191#endif
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200192} dispc;
193
194static void _omap_dispc_set_irqs(void);
195
196static inline void dispc_write_reg(const struct dispc_reg idx, u32 val)
197{
198 __raw_writel(val, dispc.base + idx.idx);
199}
200
201static inline u32 dispc_read_reg(const struct dispc_reg idx)
202{
203 return __raw_readl(dispc.base + idx.idx);
204}
205
206#define SR(reg) \
207 dispc.ctx[(DISPC_##reg).idx / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
208#define RR(reg) \
209 dispc_write_reg(DISPC_##reg, dispc.ctx[(DISPC_##reg).idx / sizeof(u32)])
210
211void dispc_save_context(void)
212{
213 if (cpu_is_omap24xx())
214 return;
215
216 SR(SYSCONFIG);
217 SR(IRQENABLE);
218 SR(CONTROL);
219 SR(CONFIG);
220 SR(DEFAULT_COLOR0);
221 SR(DEFAULT_COLOR1);
222 SR(TRANS_COLOR0);
223 SR(TRANS_COLOR1);
224 SR(LINE_NUMBER);
225 SR(TIMING_H);
226 SR(TIMING_V);
227 SR(POL_FREQ);
228 SR(DIVISOR);
229 SR(GLOBAL_ALPHA);
230 SR(SIZE_DIG);
231 SR(SIZE_LCD);
232
233 SR(GFX_BA0);
234 SR(GFX_BA1);
235 SR(GFX_POSITION);
236 SR(GFX_SIZE);
237 SR(GFX_ATTRIBUTES);
238 SR(GFX_FIFO_THRESHOLD);
239 SR(GFX_ROW_INC);
240 SR(GFX_PIXEL_INC);
241 SR(GFX_WINDOW_SKIP);
242 SR(GFX_TABLE_BA);
243
244 SR(DATA_CYCLE1);
245 SR(DATA_CYCLE2);
246 SR(DATA_CYCLE3);
247
248 SR(CPR_COEF_R);
249 SR(CPR_COEF_G);
250 SR(CPR_COEF_B);
251
252 SR(GFX_PRELOAD);
253
254 /* VID1 */
255 SR(VID_BA0(0));
256 SR(VID_BA1(0));
257 SR(VID_POSITION(0));
258 SR(VID_SIZE(0));
259 SR(VID_ATTRIBUTES(0));
260 SR(VID_FIFO_THRESHOLD(0));
261 SR(VID_ROW_INC(0));
262 SR(VID_PIXEL_INC(0));
263 SR(VID_FIR(0));
264 SR(VID_PICTURE_SIZE(0));
265 SR(VID_ACCU0(0));
266 SR(VID_ACCU1(0));
267
268 SR(VID_FIR_COEF_H(0, 0));
269 SR(VID_FIR_COEF_H(0, 1));
270 SR(VID_FIR_COEF_H(0, 2));
271 SR(VID_FIR_COEF_H(0, 3));
272 SR(VID_FIR_COEF_H(0, 4));
273 SR(VID_FIR_COEF_H(0, 5));
274 SR(VID_FIR_COEF_H(0, 6));
275 SR(VID_FIR_COEF_H(0, 7));
276
277 SR(VID_FIR_COEF_HV(0, 0));
278 SR(VID_FIR_COEF_HV(0, 1));
279 SR(VID_FIR_COEF_HV(0, 2));
280 SR(VID_FIR_COEF_HV(0, 3));
281 SR(VID_FIR_COEF_HV(0, 4));
282 SR(VID_FIR_COEF_HV(0, 5));
283 SR(VID_FIR_COEF_HV(0, 6));
284 SR(VID_FIR_COEF_HV(0, 7));
285
286 SR(VID_CONV_COEF(0, 0));
287 SR(VID_CONV_COEF(0, 1));
288 SR(VID_CONV_COEF(0, 2));
289 SR(VID_CONV_COEF(0, 3));
290 SR(VID_CONV_COEF(0, 4));
291
292 SR(VID_FIR_COEF_V(0, 0));
293 SR(VID_FIR_COEF_V(0, 1));
294 SR(VID_FIR_COEF_V(0, 2));
295 SR(VID_FIR_COEF_V(0, 3));
296 SR(VID_FIR_COEF_V(0, 4));
297 SR(VID_FIR_COEF_V(0, 5));
298 SR(VID_FIR_COEF_V(0, 6));
299 SR(VID_FIR_COEF_V(0, 7));
300
301 SR(VID_PRELOAD(0));
302
303 /* VID2 */
304 SR(VID_BA0(1));
305 SR(VID_BA1(1));
306 SR(VID_POSITION(1));
307 SR(VID_SIZE(1));
308 SR(VID_ATTRIBUTES(1));
309 SR(VID_FIFO_THRESHOLD(1));
310 SR(VID_ROW_INC(1));
311 SR(VID_PIXEL_INC(1));
312 SR(VID_FIR(1));
313 SR(VID_PICTURE_SIZE(1));
314 SR(VID_ACCU0(1));
315 SR(VID_ACCU1(1));
316
317 SR(VID_FIR_COEF_H(1, 0));
318 SR(VID_FIR_COEF_H(1, 1));
319 SR(VID_FIR_COEF_H(1, 2));
320 SR(VID_FIR_COEF_H(1, 3));
321 SR(VID_FIR_COEF_H(1, 4));
322 SR(VID_FIR_COEF_H(1, 5));
323 SR(VID_FIR_COEF_H(1, 6));
324 SR(VID_FIR_COEF_H(1, 7));
325
326 SR(VID_FIR_COEF_HV(1, 0));
327 SR(VID_FIR_COEF_HV(1, 1));
328 SR(VID_FIR_COEF_HV(1, 2));
329 SR(VID_FIR_COEF_HV(1, 3));
330 SR(VID_FIR_COEF_HV(1, 4));
331 SR(VID_FIR_COEF_HV(1, 5));
332 SR(VID_FIR_COEF_HV(1, 6));
333 SR(VID_FIR_COEF_HV(1, 7));
334
335 SR(VID_CONV_COEF(1, 0));
336 SR(VID_CONV_COEF(1, 1));
337 SR(VID_CONV_COEF(1, 2));
338 SR(VID_CONV_COEF(1, 3));
339 SR(VID_CONV_COEF(1, 4));
340
341 SR(VID_FIR_COEF_V(1, 0));
342 SR(VID_FIR_COEF_V(1, 1));
343 SR(VID_FIR_COEF_V(1, 2));
344 SR(VID_FIR_COEF_V(1, 3));
345 SR(VID_FIR_COEF_V(1, 4));
346 SR(VID_FIR_COEF_V(1, 5));
347 SR(VID_FIR_COEF_V(1, 6));
348 SR(VID_FIR_COEF_V(1, 7));
349
350 SR(VID_PRELOAD(1));
351}
352
353void dispc_restore_context(void)
354{
355 RR(SYSCONFIG);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200356 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200357 /*RR(CONTROL);*/
358 RR(CONFIG);
359 RR(DEFAULT_COLOR0);
360 RR(DEFAULT_COLOR1);
361 RR(TRANS_COLOR0);
362 RR(TRANS_COLOR1);
363 RR(LINE_NUMBER);
364 RR(TIMING_H);
365 RR(TIMING_V);
366 RR(POL_FREQ);
367 RR(DIVISOR);
368 RR(GLOBAL_ALPHA);
369 RR(SIZE_DIG);
370 RR(SIZE_LCD);
371
372 RR(GFX_BA0);
373 RR(GFX_BA1);
374 RR(GFX_POSITION);
375 RR(GFX_SIZE);
376 RR(GFX_ATTRIBUTES);
377 RR(GFX_FIFO_THRESHOLD);
378 RR(GFX_ROW_INC);
379 RR(GFX_PIXEL_INC);
380 RR(GFX_WINDOW_SKIP);
381 RR(GFX_TABLE_BA);
382
383 RR(DATA_CYCLE1);
384 RR(DATA_CYCLE2);
385 RR(DATA_CYCLE3);
386
387 RR(CPR_COEF_R);
388 RR(CPR_COEF_G);
389 RR(CPR_COEF_B);
390
391 RR(GFX_PRELOAD);
392
393 /* VID1 */
394 RR(VID_BA0(0));
395 RR(VID_BA1(0));
396 RR(VID_POSITION(0));
397 RR(VID_SIZE(0));
398 RR(VID_ATTRIBUTES(0));
399 RR(VID_FIFO_THRESHOLD(0));
400 RR(VID_ROW_INC(0));
401 RR(VID_PIXEL_INC(0));
402 RR(VID_FIR(0));
403 RR(VID_PICTURE_SIZE(0));
404 RR(VID_ACCU0(0));
405 RR(VID_ACCU1(0));
406
407 RR(VID_FIR_COEF_H(0, 0));
408 RR(VID_FIR_COEF_H(0, 1));
409 RR(VID_FIR_COEF_H(0, 2));
410 RR(VID_FIR_COEF_H(0, 3));
411 RR(VID_FIR_COEF_H(0, 4));
412 RR(VID_FIR_COEF_H(0, 5));
413 RR(VID_FIR_COEF_H(0, 6));
414 RR(VID_FIR_COEF_H(0, 7));
415
416 RR(VID_FIR_COEF_HV(0, 0));
417 RR(VID_FIR_COEF_HV(0, 1));
418 RR(VID_FIR_COEF_HV(0, 2));
419 RR(VID_FIR_COEF_HV(0, 3));
420 RR(VID_FIR_COEF_HV(0, 4));
421 RR(VID_FIR_COEF_HV(0, 5));
422 RR(VID_FIR_COEF_HV(0, 6));
423 RR(VID_FIR_COEF_HV(0, 7));
424
425 RR(VID_CONV_COEF(0, 0));
426 RR(VID_CONV_COEF(0, 1));
427 RR(VID_CONV_COEF(0, 2));
428 RR(VID_CONV_COEF(0, 3));
429 RR(VID_CONV_COEF(0, 4));
430
431 RR(VID_FIR_COEF_V(0, 0));
432 RR(VID_FIR_COEF_V(0, 1));
433 RR(VID_FIR_COEF_V(0, 2));
434 RR(VID_FIR_COEF_V(0, 3));
435 RR(VID_FIR_COEF_V(0, 4));
436 RR(VID_FIR_COEF_V(0, 5));
437 RR(VID_FIR_COEF_V(0, 6));
438 RR(VID_FIR_COEF_V(0, 7));
439
440 RR(VID_PRELOAD(0));
441
442 /* VID2 */
443 RR(VID_BA0(1));
444 RR(VID_BA1(1));
445 RR(VID_POSITION(1));
446 RR(VID_SIZE(1));
447 RR(VID_ATTRIBUTES(1));
448 RR(VID_FIFO_THRESHOLD(1));
449 RR(VID_ROW_INC(1));
450 RR(VID_PIXEL_INC(1));
451 RR(VID_FIR(1));
452 RR(VID_PICTURE_SIZE(1));
453 RR(VID_ACCU0(1));
454 RR(VID_ACCU1(1));
455
456 RR(VID_FIR_COEF_H(1, 0));
457 RR(VID_FIR_COEF_H(1, 1));
458 RR(VID_FIR_COEF_H(1, 2));
459 RR(VID_FIR_COEF_H(1, 3));
460 RR(VID_FIR_COEF_H(1, 4));
461 RR(VID_FIR_COEF_H(1, 5));
462 RR(VID_FIR_COEF_H(1, 6));
463 RR(VID_FIR_COEF_H(1, 7));
464
465 RR(VID_FIR_COEF_HV(1, 0));
466 RR(VID_FIR_COEF_HV(1, 1));
467 RR(VID_FIR_COEF_HV(1, 2));
468 RR(VID_FIR_COEF_HV(1, 3));
469 RR(VID_FIR_COEF_HV(1, 4));
470 RR(VID_FIR_COEF_HV(1, 5));
471 RR(VID_FIR_COEF_HV(1, 6));
472 RR(VID_FIR_COEF_HV(1, 7));
473
474 RR(VID_CONV_COEF(1, 0));
475 RR(VID_CONV_COEF(1, 1));
476 RR(VID_CONV_COEF(1, 2));
477 RR(VID_CONV_COEF(1, 3));
478 RR(VID_CONV_COEF(1, 4));
479
480 RR(VID_FIR_COEF_V(1, 0));
481 RR(VID_FIR_COEF_V(1, 1));
482 RR(VID_FIR_COEF_V(1, 2));
483 RR(VID_FIR_COEF_V(1, 3));
484 RR(VID_FIR_COEF_V(1, 4));
485 RR(VID_FIR_COEF_V(1, 5));
486 RR(VID_FIR_COEF_V(1, 6));
487 RR(VID_FIR_COEF_V(1, 7));
488
489 RR(VID_PRELOAD(1));
490
491 /* enable last, because LCD & DIGIT enable are here */
492 RR(CONTROL);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200493
494 /* clear spurious SYNC_LOST_DIGIT interrupts */
495 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
496
497 /*
498 * enable last so IRQs won't trigger before
499 * the context is fully restored
500 */
501 RR(IRQENABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200502}
503
504#undef SR
505#undef RR
506
507static inline void enable_clocks(bool enable)
508{
509 if (enable)
510 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
511 else
512 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
513}
514
515bool dispc_go_busy(enum omap_channel channel)
516{
517 int bit;
518
519 if (channel == OMAP_DSS_CHANNEL_LCD)
520 bit = 5; /* GOLCD */
521 else
522 bit = 6; /* GODIGIT */
523
524 return REG_GET(DISPC_CONTROL, bit, bit) == 1;
525}
526
527void dispc_go(enum omap_channel channel)
528{
529 int bit;
530
531 enable_clocks(1);
532
533 if (channel == OMAP_DSS_CHANNEL_LCD)
534 bit = 0; /* LCDENABLE */
535 else
536 bit = 1; /* DIGITALENABLE */
537
538 /* if the channel is not enabled, we don't need GO */
539 if (REG_GET(DISPC_CONTROL, bit, bit) == 0)
540 goto end;
541
542 if (channel == OMAP_DSS_CHANNEL_LCD)
543 bit = 5; /* GOLCD */
544 else
545 bit = 6; /* GODIGIT */
546
547 if (REG_GET(DISPC_CONTROL, bit, bit) == 1) {
548 DSSERR("GO bit not down for channel %d\n", channel);
549 goto end;
550 }
551
552 DSSDBG("GO %s\n", channel == OMAP_DSS_CHANNEL_LCD ? "LCD" : "DIGIT");
553
554 REG_FLD_MOD(DISPC_CONTROL, 1, bit, bit);
555end:
556 enable_clocks(0);
557}
558
559static void _dispc_write_firh_reg(enum omap_plane plane, int reg, u32 value)
560{
561 BUG_ON(plane == OMAP_DSS_GFX);
562
563 dispc_write_reg(DISPC_VID_FIR_COEF_H(plane-1, reg), value);
564}
565
566static void _dispc_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
567{
568 BUG_ON(plane == OMAP_DSS_GFX);
569
570 dispc_write_reg(DISPC_VID_FIR_COEF_HV(plane-1, reg), value);
571}
572
573static void _dispc_write_firv_reg(enum omap_plane plane, int reg, u32 value)
574{
575 BUG_ON(plane == OMAP_DSS_GFX);
576
577 dispc_write_reg(DISPC_VID_FIR_COEF_V(plane-1, reg), value);
578}
579
580static void _dispc_set_scale_coef(enum omap_plane plane, int hscaleup,
581 int vscaleup, int five_taps)
582{
583 /* Coefficients for horizontal up-sampling */
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200584 static const struct dispc_h_coef coef_hup[8] = {
585 { 0, 0, 128, 0, 0 },
586 { -1, 13, 124, -8, 0 },
587 { -2, 30, 112, -11, -1 },
588 { -5, 51, 95, -11, -2 },
589 { 0, -9, 73, 73, -9 },
590 { -2, -11, 95, 51, -5 },
591 { -1, -11, 112, 30, -2 },
592 { 0, -8, 124, 13, -1 },
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200593 };
594
595 /* Coefficients for vertical up-sampling */
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200596 static const struct dispc_v_coef coef_vup_3tap[8] = {
597 { 0, 0, 128, 0, 0 },
598 { 0, 3, 123, 2, 0 },
599 { 0, 12, 111, 5, 0 },
600 { 0, 32, 89, 7, 0 },
601 { 0, 0, 64, 64, 0 },
602 { 0, 7, 89, 32, 0 },
603 { 0, 5, 111, 12, 0 },
604 { 0, 2, 123, 3, 0 },
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200605 };
606
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200607 static const struct dispc_v_coef coef_vup_5tap[8] = {
608 { 0, 0, 128, 0, 0 },
609 { -1, 13, 124, -8, 0 },
610 { -2, 30, 112, -11, -1 },
611 { -5, 51, 95, -11, -2 },
612 { 0, -9, 73, 73, -9 },
613 { -2, -11, 95, 51, -5 },
614 { -1, -11, 112, 30, -2 },
615 { 0, -8, 124, 13, -1 },
616 };
617
618 /* Coefficients for horizontal down-sampling */
619 static const struct dispc_h_coef coef_hdown[8] = {
620 { 0, 36, 56, 36, 0 },
621 { 4, 40, 55, 31, -2 },
622 { 8, 44, 54, 27, -5 },
623 { 12, 48, 53, 22, -7 },
624 { -9, 17, 52, 51, 17 },
625 { -7, 22, 53, 48, 12 },
626 { -5, 27, 54, 44, 8 },
627 { -2, 31, 55, 40, 4 },
628 };
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200629
630 /* Coefficients for vertical down-sampling */
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200631 static const struct dispc_v_coef coef_vdown_3tap[8] = {
632 { 0, 36, 56, 36, 0 },
633 { 0, 40, 57, 31, 0 },
634 { 0, 45, 56, 27, 0 },
635 { 0, 50, 55, 23, 0 },
636 { 0, 18, 55, 55, 0 },
637 { 0, 23, 55, 50, 0 },
638 { 0, 27, 56, 45, 0 },
639 { 0, 31, 57, 40, 0 },
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200640 };
641
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200642 static const struct dispc_v_coef coef_vdown_5tap[8] = {
643 { 0, 36, 56, 36, 0 },
644 { 4, 40, 55, 31, -2 },
645 { 8, 44, 54, 27, -5 },
646 { 12, 48, 53, 22, -7 },
647 { -9, 17, 52, 51, 17 },
648 { -7, 22, 53, 48, 12 },
649 { -5, 27, 54, 44, 8 },
650 { -2, 31, 55, 40, 4 },
651 };
652
653 const struct dispc_h_coef *h_coef;
654 const struct dispc_v_coef *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200655 int i;
656
657 if (hscaleup)
658 h_coef = coef_hup;
659 else
660 h_coef = coef_hdown;
661
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200662 if (vscaleup)
663 v_coef = five_taps ? coef_vup_5tap : coef_vup_3tap;
664 else
665 v_coef = five_taps ? coef_vdown_5tap : coef_vdown_3tap;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200666
667 for (i = 0; i < 8; i++) {
668 u32 h, hv;
669
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200670 h = FLD_VAL(h_coef[i].hc0, 7, 0)
671 | FLD_VAL(h_coef[i].hc1, 15, 8)
672 | FLD_VAL(h_coef[i].hc2, 23, 16)
673 | FLD_VAL(h_coef[i].hc3, 31, 24);
674 hv = FLD_VAL(h_coef[i].hc4, 7, 0)
675 | FLD_VAL(v_coef[i].vc0, 15, 8)
676 | FLD_VAL(v_coef[i].vc1, 23, 16)
677 | FLD_VAL(v_coef[i].vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200678
679 _dispc_write_firh_reg(plane, i, h);
680 _dispc_write_firhv_reg(plane, i, hv);
681 }
682
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200683 if (five_taps) {
684 for (i = 0; i < 8; i++) {
685 u32 v;
686 v = FLD_VAL(v_coef[i].vc00, 7, 0)
687 | FLD_VAL(v_coef[i].vc22, 15, 8);
688 _dispc_write_firv_reg(plane, i, v);
689 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200690 }
691}
692
693static void _dispc_setup_color_conv_coef(void)
694{
695 const struct color_conv_coef {
696 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
697 int full_range;
698 } ctbl_bt601_5 = {
699 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
700 };
701
702 const struct color_conv_coef *ct;
703
704#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
705
706 ct = &ctbl_bt601_5;
707
708 dispc_write_reg(DISPC_VID_CONV_COEF(0, 0), CVAL(ct->rcr, ct->ry));
709 dispc_write_reg(DISPC_VID_CONV_COEF(0, 1), CVAL(ct->gy, ct->rcb));
710 dispc_write_reg(DISPC_VID_CONV_COEF(0, 2), CVAL(ct->gcb, ct->gcr));
711 dispc_write_reg(DISPC_VID_CONV_COEF(0, 3), CVAL(ct->bcr, ct->by));
712 dispc_write_reg(DISPC_VID_CONV_COEF(0, 4), CVAL(0, ct->bcb));
713
714 dispc_write_reg(DISPC_VID_CONV_COEF(1, 0), CVAL(ct->rcr, ct->ry));
715 dispc_write_reg(DISPC_VID_CONV_COEF(1, 1), CVAL(ct->gy, ct->rcb));
716 dispc_write_reg(DISPC_VID_CONV_COEF(1, 2), CVAL(ct->gcb, ct->gcr));
717 dispc_write_reg(DISPC_VID_CONV_COEF(1, 3), CVAL(ct->bcr, ct->by));
718 dispc_write_reg(DISPC_VID_CONV_COEF(1, 4), CVAL(0, ct->bcb));
719
720#undef CVAL
721
722 REG_FLD_MOD(DISPC_VID_ATTRIBUTES(0), ct->full_range, 11, 11);
723 REG_FLD_MOD(DISPC_VID_ATTRIBUTES(1), ct->full_range, 11, 11);
724}
725
726
727static void _dispc_set_plane_ba0(enum omap_plane plane, u32 paddr)
728{
729 const struct dispc_reg ba0_reg[] = { DISPC_GFX_BA0,
730 DISPC_VID_BA0(0),
731 DISPC_VID_BA0(1) };
732
733 dispc_write_reg(ba0_reg[plane], paddr);
734}
735
736static void _dispc_set_plane_ba1(enum omap_plane plane, u32 paddr)
737{
738 const struct dispc_reg ba1_reg[] = { DISPC_GFX_BA1,
739 DISPC_VID_BA1(0),
740 DISPC_VID_BA1(1) };
741
742 dispc_write_reg(ba1_reg[plane], paddr);
743}
744
745static void _dispc_set_plane_pos(enum omap_plane plane, int x, int y)
746{
747 const struct dispc_reg pos_reg[] = { DISPC_GFX_POSITION,
748 DISPC_VID_POSITION(0),
749 DISPC_VID_POSITION(1) };
750
751 u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
752 dispc_write_reg(pos_reg[plane], val);
753}
754
755static void _dispc_set_pic_size(enum omap_plane plane, int width, int height)
756{
757 const struct dispc_reg siz_reg[] = { DISPC_GFX_SIZE,
758 DISPC_VID_PICTURE_SIZE(0),
759 DISPC_VID_PICTURE_SIZE(1) };
760 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
761 dispc_write_reg(siz_reg[plane], val);
762}
763
764static void _dispc_set_vid_size(enum omap_plane plane, int width, int height)
765{
766 u32 val;
767 const struct dispc_reg vsi_reg[] = { DISPC_VID_SIZE(0),
768 DISPC_VID_SIZE(1) };
769
770 BUG_ON(plane == OMAP_DSS_GFX);
771
772 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
773 dispc_write_reg(vsi_reg[plane-1], val);
774}
775
776static void _dispc_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
777{
Archit Tanejaa0acb552010-09-15 19:20:00 +0530778 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200779 return;
780
Archit Tanejaa0acb552010-09-15 19:20:00 +0530781 BUG_ON(!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
782 plane == OMAP_DSS_VIDEO1);
783
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200784 if (plane == OMAP_DSS_GFX)
785 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 7, 0);
786 else if (plane == OMAP_DSS_VIDEO2)
787 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 23, 16);
788}
789
790static void _dispc_set_pix_inc(enum omap_plane plane, s32 inc)
791{
792 const struct dispc_reg ri_reg[] = { DISPC_GFX_PIXEL_INC,
793 DISPC_VID_PIXEL_INC(0),
794 DISPC_VID_PIXEL_INC(1) };
795
796 dispc_write_reg(ri_reg[plane], inc);
797}
798
799static void _dispc_set_row_inc(enum omap_plane plane, s32 inc)
800{
801 const struct dispc_reg ri_reg[] = { DISPC_GFX_ROW_INC,
802 DISPC_VID_ROW_INC(0),
803 DISPC_VID_ROW_INC(1) };
804
805 dispc_write_reg(ri_reg[plane], inc);
806}
807
808static void _dispc_set_color_mode(enum omap_plane plane,
809 enum omap_color_mode color_mode)
810{
811 u32 m = 0;
812
813 switch (color_mode) {
814 case OMAP_DSS_COLOR_CLUT1:
815 m = 0x0; break;
816 case OMAP_DSS_COLOR_CLUT2:
817 m = 0x1; break;
818 case OMAP_DSS_COLOR_CLUT4:
819 m = 0x2; break;
820 case OMAP_DSS_COLOR_CLUT8:
821 m = 0x3; break;
822 case OMAP_DSS_COLOR_RGB12U:
823 m = 0x4; break;
824 case OMAP_DSS_COLOR_ARGB16:
825 m = 0x5; break;
826 case OMAP_DSS_COLOR_RGB16:
827 m = 0x6; break;
828 case OMAP_DSS_COLOR_RGB24U:
829 m = 0x8; break;
830 case OMAP_DSS_COLOR_RGB24P:
831 m = 0x9; break;
832 case OMAP_DSS_COLOR_YUV2:
833 m = 0xa; break;
834 case OMAP_DSS_COLOR_UYVY:
835 m = 0xb; break;
836 case OMAP_DSS_COLOR_ARGB32:
837 m = 0xc; break;
838 case OMAP_DSS_COLOR_RGBA32:
839 m = 0xd; break;
840 case OMAP_DSS_COLOR_RGBX32:
841 m = 0xe; break;
842 default:
843 BUG(); break;
844 }
845
846 REG_FLD_MOD(dispc_reg_att[plane], m, 4, 1);
847}
848
849static void _dispc_set_channel_out(enum omap_plane plane,
850 enum omap_channel channel)
851{
852 int shift;
853 u32 val;
854
855 switch (plane) {
856 case OMAP_DSS_GFX:
857 shift = 8;
858 break;
859 case OMAP_DSS_VIDEO1:
860 case OMAP_DSS_VIDEO2:
861 shift = 16;
862 break;
863 default:
864 BUG();
865 return;
866 }
867
868 val = dispc_read_reg(dispc_reg_att[plane]);
869 val = FLD_MOD(val, channel, shift, shift);
870 dispc_write_reg(dispc_reg_att[plane], val);
871}
872
873void dispc_set_burst_size(enum omap_plane plane,
874 enum omap_burst_size burst_size)
875{
876 int shift;
877 u32 val;
878
879 enable_clocks(1);
880
881 switch (plane) {
882 case OMAP_DSS_GFX:
883 shift = 6;
884 break;
885 case OMAP_DSS_VIDEO1:
886 case OMAP_DSS_VIDEO2:
887 shift = 14;
888 break;
889 default:
890 BUG();
891 return;
892 }
893
894 val = dispc_read_reg(dispc_reg_att[plane]);
895 val = FLD_MOD(val, burst_size, shift+1, shift);
896 dispc_write_reg(dispc_reg_att[plane], val);
897
898 enable_clocks(0);
899}
900
901static void _dispc_set_vid_color_conv(enum omap_plane plane, bool enable)
902{
903 u32 val;
904
905 BUG_ON(plane == OMAP_DSS_GFX);
906
907 val = dispc_read_reg(dispc_reg_att[plane]);
908 val = FLD_MOD(val, enable, 9, 9);
909 dispc_write_reg(dispc_reg_att[plane], val);
910}
911
912void dispc_enable_replication(enum omap_plane plane, bool enable)
913{
914 int bit;
915
916 if (plane == OMAP_DSS_GFX)
917 bit = 5;
918 else
919 bit = 10;
920
921 enable_clocks(1);
922 REG_FLD_MOD(dispc_reg_att[plane], enable, bit, bit);
923 enable_clocks(0);
924}
925
926void dispc_set_lcd_size(u16 width, u16 height)
927{
928 u32 val;
929 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
930 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
931 enable_clocks(1);
932 dispc_write_reg(DISPC_SIZE_LCD, val);
933 enable_clocks(0);
934}
935
936void dispc_set_digit_size(u16 width, u16 height)
937{
938 u32 val;
939 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
940 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
941 enable_clocks(1);
942 dispc_write_reg(DISPC_SIZE_DIG, val);
943 enable_clocks(0);
944}
945
946static void dispc_read_plane_fifo_sizes(void)
947{
948 const struct dispc_reg fsz_reg[] = { DISPC_GFX_FIFO_SIZE_STATUS,
949 DISPC_VID_FIFO_SIZE_STATUS(0),
950 DISPC_VID_FIFO_SIZE_STATUS(1) };
951 u32 size;
952 int plane;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530953 u8 start, end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200954
955 enable_clocks(1);
956
Archit Tanejaa0acb552010-09-15 19:20:00 +0530957 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200958
Archit Tanejaa0acb552010-09-15 19:20:00 +0530959 for (plane = 0; plane < ARRAY_SIZE(dispc.fifo_size); ++plane) {
960 size = FLD_GET(dispc_read_reg(fsz_reg[plane]), start, end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200961 dispc.fifo_size[plane] = size;
962 }
963
964 enable_clocks(0);
965}
966
967u32 dispc_get_plane_fifo_size(enum omap_plane plane)
968{
969 return dispc.fifo_size[plane];
970}
971
972void dispc_setup_plane_fifo(enum omap_plane plane, u32 low, u32 high)
973{
974 const struct dispc_reg ftrs_reg[] = { DISPC_GFX_FIFO_THRESHOLD,
975 DISPC_VID_FIFO_THRESHOLD(0),
976 DISPC_VID_FIFO_THRESHOLD(1) };
Archit Tanejaa0acb552010-09-15 19:20:00 +0530977 u8 hi_start, hi_end, lo_start, lo_end;
978
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200979 enable_clocks(1);
980
981 DSSDBG("fifo(%d) low/high old %u/%u, new %u/%u\n",
982 plane,
983 REG_GET(ftrs_reg[plane], 11, 0),
984 REG_GET(ftrs_reg[plane], 27, 16),
985 low, high);
986
Archit Tanejaa0acb552010-09-15 19:20:00 +0530987 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
988 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
989
990 dispc_write_reg(ftrs_reg[plane],
991 FLD_VAL(high, hi_start, hi_end) |
992 FLD_VAL(low, lo_start, lo_end));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200993
994 enable_clocks(0);
995}
996
997void dispc_enable_fifomerge(bool enable)
998{
999 enable_clocks(1);
1000
1001 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1002 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1003
1004 enable_clocks(0);
1005}
1006
1007static void _dispc_set_fir(enum omap_plane plane, int hinc, int vinc)
1008{
1009 u32 val;
1010 const struct dispc_reg fir_reg[] = { DISPC_VID_FIR(0),
1011 DISPC_VID_FIR(1) };
Archit Tanejaa0acb552010-09-15 19:20:00 +05301012 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001013
1014 BUG_ON(plane == OMAP_DSS_GFX);
1015
Archit Tanejaa0acb552010-09-15 19:20:00 +05301016 dss_feat_get_reg_field(FEAT_REG_FIRHINC, &hinc_start, &hinc_end);
1017 dss_feat_get_reg_field(FEAT_REG_FIRVINC, &vinc_start, &vinc_end);
1018
1019 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1020 FLD_VAL(hinc, hinc_start, hinc_end);
1021
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001022 dispc_write_reg(fir_reg[plane-1], val);
1023}
1024
1025static void _dispc_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1026{
1027 u32 val;
1028 const struct dispc_reg ac0_reg[] = { DISPC_VID_ACCU0(0),
1029 DISPC_VID_ACCU0(1) };
1030
1031 BUG_ON(plane == OMAP_DSS_GFX);
1032
1033 val = FLD_VAL(vaccu, 25, 16) | FLD_VAL(haccu, 9, 0);
1034 dispc_write_reg(ac0_reg[plane-1], val);
1035}
1036
1037static void _dispc_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1038{
1039 u32 val;
1040 const struct dispc_reg ac1_reg[] = { DISPC_VID_ACCU1(0),
1041 DISPC_VID_ACCU1(1) };
1042
1043 BUG_ON(plane == OMAP_DSS_GFX);
1044
1045 val = FLD_VAL(vaccu, 25, 16) | FLD_VAL(haccu, 9, 0);
1046 dispc_write_reg(ac1_reg[plane-1], val);
1047}
1048
1049
1050static void _dispc_set_scaling(enum omap_plane plane,
1051 u16 orig_width, u16 orig_height,
1052 u16 out_width, u16 out_height,
1053 bool ilace, bool five_taps,
1054 bool fieldmode)
1055{
1056 int fir_hinc;
1057 int fir_vinc;
1058 int hscaleup, vscaleup;
1059 int accu0 = 0;
1060 int accu1 = 0;
1061 u32 l;
1062
1063 BUG_ON(plane == OMAP_DSS_GFX);
1064
1065 hscaleup = orig_width <= out_width;
1066 vscaleup = orig_height <= out_height;
1067
1068 _dispc_set_scale_coef(plane, hscaleup, vscaleup, five_taps);
1069
1070 if (!orig_width || orig_width == out_width)
1071 fir_hinc = 0;
1072 else
1073 fir_hinc = 1024 * orig_width / out_width;
1074
1075 if (!orig_height || orig_height == out_height)
1076 fir_vinc = 0;
1077 else
1078 fir_vinc = 1024 * orig_height / out_height;
1079
1080 _dispc_set_fir(plane, fir_hinc, fir_vinc);
1081
1082 l = dispc_read_reg(dispc_reg_att[plane]);
1083 l &= ~((0x0f << 5) | (0x3 << 21));
1084
1085 l |= fir_hinc ? (1 << 5) : 0;
1086 l |= fir_vinc ? (1 << 6) : 0;
1087
1088 l |= hscaleup ? 0 : (1 << 7);
1089 l |= vscaleup ? 0 : (1 << 8);
1090
1091 l |= five_taps ? (1 << 21) : 0;
1092 l |= five_taps ? (1 << 22) : 0;
1093
1094 dispc_write_reg(dispc_reg_att[plane], l);
1095
1096 /*
1097 * field 0 = even field = bottom field
1098 * field 1 = odd field = top field
1099 */
1100 if (ilace && !fieldmode) {
1101 accu1 = 0;
1102 accu0 = (fir_vinc / 2) & 0x3ff;
1103 if (accu0 >= 1024/2) {
1104 accu1 = 1024/2;
1105 accu0 -= accu1;
1106 }
1107 }
1108
1109 _dispc_set_vid_accu0(plane, 0, accu0);
1110 _dispc_set_vid_accu1(plane, 0, accu1);
1111}
1112
1113static void _dispc_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1114 bool mirroring, enum omap_color_mode color_mode)
1115{
1116 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1117 color_mode == OMAP_DSS_COLOR_UYVY) {
1118 int vidrot = 0;
1119
1120 if (mirroring) {
1121 switch (rotation) {
1122 case OMAP_DSS_ROT_0:
1123 vidrot = 2;
1124 break;
1125 case OMAP_DSS_ROT_90:
1126 vidrot = 1;
1127 break;
1128 case OMAP_DSS_ROT_180:
1129 vidrot = 0;
1130 break;
1131 case OMAP_DSS_ROT_270:
1132 vidrot = 3;
1133 break;
1134 }
1135 } else {
1136 switch (rotation) {
1137 case OMAP_DSS_ROT_0:
1138 vidrot = 0;
1139 break;
1140 case OMAP_DSS_ROT_90:
1141 vidrot = 1;
1142 break;
1143 case OMAP_DSS_ROT_180:
1144 vidrot = 2;
1145 break;
1146 case OMAP_DSS_ROT_270:
1147 vidrot = 3;
1148 break;
1149 }
1150 }
1151
1152 REG_FLD_MOD(dispc_reg_att[plane], vidrot, 13, 12);
1153
1154 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1155 REG_FLD_MOD(dispc_reg_att[plane], 0x1, 18, 18);
1156 else
1157 REG_FLD_MOD(dispc_reg_att[plane], 0x0, 18, 18);
1158 } else {
1159 REG_FLD_MOD(dispc_reg_att[plane], 0, 13, 12);
1160 REG_FLD_MOD(dispc_reg_att[plane], 0, 18, 18);
1161 }
1162}
1163
1164static int color_mode_to_bpp(enum omap_color_mode color_mode)
1165{
1166 switch (color_mode) {
1167 case OMAP_DSS_COLOR_CLUT1:
1168 return 1;
1169 case OMAP_DSS_COLOR_CLUT2:
1170 return 2;
1171 case OMAP_DSS_COLOR_CLUT4:
1172 return 4;
1173 case OMAP_DSS_COLOR_CLUT8:
1174 return 8;
1175 case OMAP_DSS_COLOR_RGB12U:
1176 case OMAP_DSS_COLOR_RGB16:
1177 case OMAP_DSS_COLOR_ARGB16:
1178 case OMAP_DSS_COLOR_YUV2:
1179 case OMAP_DSS_COLOR_UYVY:
1180 return 16;
1181 case OMAP_DSS_COLOR_RGB24P:
1182 return 24;
1183 case OMAP_DSS_COLOR_RGB24U:
1184 case OMAP_DSS_COLOR_ARGB32:
1185 case OMAP_DSS_COLOR_RGBA32:
1186 case OMAP_DSS_COLOR_RGBX32:
1187 return 32;
1188 default:
1189 BUG();
1190 }
1191}
1192
1193static s32 pixinc(int pixels, u8 ps)
1194{
1195 if (pixels == 1)
1196 return 1;
1197 else if (pixels > 1)
1198 return 1 + (pixels - 1) * ps;
1199 else if (pixels < 0)
1200 return 1 - (-pixels + 1) * ps;
1201 else
1202 BUG();
1203}
1204
1205static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1206 u16 screen_width,
1207 u16 width, u16 height,
1208 enum omap_color_mode color_mode, bool fieldmode,
1209 unsigned int field_offset,
1210 unsigned *offset0, unsigned *offset1,
1211 s32 *row_inc, s32 *pix_inc)
1212{
1213 u8 ps;
1214
1215 /* FIXME CLUT formats */
1216 switch (color_mode) {
1217 case OMAP_DSS_COLOR_CLUT1:
1218 case OMAP_DSS_COLOR_CLUT2:
1219 case OMAP_DSS_COLOR_CLUT4:
1220 case OMAP_DSS_COLOR_CLUT8:
1221 BUG();
1222 return;
1223 case OMAP_DSS_COLOR_YUV2:
1224 case OMAP_DSS_COLOR_UYVY:
1225 ps = 4;
1226 break;
1227 default:
1228 ps = color_mode_to_bpp(color_mode) / 8;
1229 break;
1230 }
1231
1232 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1233 width, height);
1234
1235 /*
1236 * field 0 = even field = bottom field
1237 * field 1 = odd field = top field
1238 */
1239 switch (rotation + mirror * 4) {
1240 case OMAP_DSS_ROT_0:
1241 case OMAP_DSS_ROT_180:
1242 /*
1243 * If the pixel format is YUV or UYVY divide the width
1244 * of the image by 2 for 0 and 180 degree rotation.
1245 */
1246 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1247 color_mode == OMAP_DSS_COLOR_UYVY)
1248 width = width >> 1;
1249 case OMAP_DSS_ROT_90:
1250 case OMAP_DSS_ROT_270:
1251 *offset1 = 0;
1252 if (field_offset)
1253 *offset0 = field_offset * screen_width * ps;
1254 else
1255 *offset0 = 0;
1256
1257 *row_inc = pixinc(1 + (screen_width - width) +
1258 (fieldmode ? screen_width : 0),
1259 ps);
1260 *pix_inc = pixinc(1, ps);
1261 break;
1262
1263 case OMAP_DSS_ROT_0 + 4:
1264 case OMAP_DSS_ROT_180 + 4:
1265 /* If the pixel format is YUV or UYVY divide the width
1266 * of the image by 2 for 0 degree and 180 degree
1267 */
1268 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1269 color_mode == OMAP_DSS_COLOR_UYVY)
1270 width = width >> 1;
1271 case OMAP_DSS_ROT_90 + 4:
1272 case OMAP_DSS_ROT_270 + 4:
1273 *offset1 = 0;
1274 if (field_offset)
1275 *offset0 = field_offset * screen_width * ps;
1276 else
1277 *offset0 = 0;
1278 *row_inc = pixinc(1 - (screen_width + width) -
1279 (fieldmode ? screen_width : 0),
1280 ps);
1281 *pix_inc = pixinc(1, ps);
1282 break;
1283
1284 default:
1285 BUG();
1286 }
1287}
1288
1289static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1290 u16 screen_width,
1291 u16 width, u16 height,
1292 enum omap_color_mode color_mode, bool fieldmode,
1293 unsigned int field_offset,
1294 unsigned *offset0, unsigned *offset1,
1295 s32 *row_inc, s32 *pix_inc)
1296{
1297 u8 ps;
1298 u16 fbw, fbh;
1299
1300 /* FIXME CLUT formats */
1301 switch (color_mode) {
1302 case OMAP_DSS_COLOR_CLUT1:
1303 case OMAP_DSS_COLOR_CLUT2:
1304 case OMAP_DSS_COLOR_CLUT4:
1305 case OMAP_DSS_COLOR_CLUT8:
1306 BUG();
1307 return;
1308 default:
1309 ps = color_mode_to_bpp(color_mode) / 8;
1310 break;
1311 }
1312
1313 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1314 width, height);
1315
1316 /* width & height are overlay sizes, convert to fb sizes */
1317
1318 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1319 fbw = width;
1320 fbh = height;
1321 } else {
1322 fbw = height;
1323 fbh = width;
1324 }
1325
1326 /*
1327 * field 0 = even field = bottom field
1328 * field 1 = odd field = top field
1329 */
1330 switch (rotation + mirror * 4) {
1331 case OMAP_DSS_ROT_0:
1332 *offset1 = 0;
1333 if (field_offset)
1334 *offset0 = *offset1 + field_offset * screen_width * ps;
1335 else
1336 *offset0 = *offset1;
1337 *row_inc = pixinc(1 + (screen_width - fbw) +
1338 (fieldmode ? screen_width : 0),
1339 ps);
1340 *pix_inc = pixinc(1, ps);
1341 break;
1342 case OMAP_DSS_ROT_90:
1343 *offset1 = screen_width * (fbh - 1) * ps;
1344 if (field_offset)
1345 *offset0 = *offset1 + field_offset * ps;
1346 else
1347 *offset0 = *offset1;
1348 *row_inc = pixinc(screen_width * (fbh - 1) + 1 +
1349 (fieldmode ? 1 : 0), ps);
1350 *pix_inc = pixinc(-screen_width, ps);
1351 break;
1352 case OMAP_DSS_ROT_180:
1353 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1354 if (field_offset)
1355 *offset0 = *offset1 - field_offset * screen_width * ps;
1356 else
1357 *offset0 = *offset1;
1358 *row_inc = pixinc(-1 -
1359 (screen_width - fbw) -
1360 (fieldmode ? screen_width : 0),
1361 ps);
1362 *pix_inc = pixinc(-1, ps);
1363 break;
1364 case OMAP_DSS_ROT_270:
1365 *offset1 = (fbw - 1) * ps;
1366 if (field_offset)
1367 *offset0 = *offset1 - field_offset * ps;
1368 else
1369 *offset0 = *offset1;
1370 *row_inc = pixinc(-screen_width * (fbh - 1) - 1 -
1371 (fieldmode ? 1 : 0), ps);
1372 *pix_inc = pixinc(screen_width, ps);
1373 break;
1374
1375 /* mirroring */
1376 case OMAP_DSS_ROT_0 + 4:
1377 *offset1 = (fbw - 1) * ps;
1378 if (field_offset)
1379 *offset0 = *offset1 + field_offset * screen_width * ps;
1380 else
1381 *offset0 = *offset1;
1382 *row_inc = pixinc(screen_width * 2 - 1 +
1383 (fieldmode ? screen_width : 0),
1384 ps);
1385 *pix_inc = pixinc(-1, ps);
1386 break;
1387
1388 case OMAP_DSS_ROT_90 + 4:
1389 *offset1 = 0;
1390 if (field_offset)
1391 *offset0 = *offset1 + field_offset * ps;
1392 else
1393 *offset0 = *offset1;
1394 *row_inc = pixinc(-screen_width * (fbh - 1) + 1 +
1395 (fieldmode ? 1 : 0),
1396 ps);
1397 *pix_inc = pixinc(screen_width, ps);
1398 break;
1399
1400 case OMAP_DSS_ROT_180 + 4:
1401 *offset1 = screen_width * (fbh - 1) * ps;
1402 if (field_offset)
1403 *offset0 = *offset1 - field_offset * screen_width * ps;
1404 else
1405 *offset0 = *offset1;
1406 *row_inc = pixinc(1 - screen_width * 2 -
1407 (fieldmode ? screen_width : 0),
1408 ps);
1409 *pix_inc = pixinc(1, ps);
1410 break;
1411
1412 case OMAP_DSS_ROT_270 + 4:
1413 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1414 if (field_offset)
1415 *offset0 = *offset1 - field_offset * ps;
1416 else
1417 *offset0 = *offset1;
1418 *row_inc = pixinc(screen_width * (fbh - 1) - 1 -
1419 (fieldmode ? 1 : 0),
1420 ps);
1421 *pix_inc = pixinc(-screen_width, ps);
1422 break;
1423
1424 default:
1425 BUG();
1426 }
1427}
1428
1429static unsigned long calc_fclk_five_taps(u16 width, u16 height,
1430 u16 out_width, u16 out_height, enum omap_color_mode color_mode)
1431{
1432 u32 fclk = 0;
1433 /* FIXME venc pclk? */
1434 u64 tmp, pclk = dispc_pclk_rate();
1435
1436 if (height > out_height) {
1437 /* FIXME get real display PPL */
1438 unsigned int ppl = 800;
1439
1440 tmp = pclk * height * out_width;
1441 do_div(tmp, 2 * out_height * ppl);
1442 fclk = tmp;
1443
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02001444 if (height > 2 * out_height) {
1445 if (ppl == out_width)
1446 return 0;
1447
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001448 tmp = pclk * (height - 2 * out_height) * out_width;
1449 do_div(tmp, 2 * out_height * (ppl - out_width));
1450 fclk = max(fclk, (u32) tmp);
1451 }
1452 }
1453
1454 if (width > out_width) {
1455 tmp = pclk * width;
1456 do_div(tmp, out_width);
1457 fclk = max(fclk, (u32) tmp);
1458
1459 if (color_mode == OMAP_DSS_COLOR_RGB24U)
1460 fclk <<= 1;
1461 }
1462
1463 return fclk;
1464}
1465
1466static unsigned long calc_fclk(u16 width, u16 height,
1467 u16 out_width, u16 out_height)
1468{
1469 unsigned int hf, vf;
1470
1471 /*
1472 * FIXME how to determine the 'A' factor
1473 * for the no downscaling case ?
1474 */
1475
1476 if (width > 3 * out_width)
1477 hf = 4;
1478 else if (width > 2 * out_width)
1479 hf = 3;
1480 else if (width > out_width)
1481 hf = 2;
1482 else
1483 hf = 1;
1484
1485 if (height > out_height)
1486 vf = 2;
1487 else
1488 vf = 1;
1489
1490 /* FIXME venc pclk? */
1491 return dispc_pclk_rate() * vf * hf;
1492}
1493
1494void dispc_set_channel_out(enum omap_plane plane, enum omap_channel channel_out)
1495{
1496 enable_clocks(1);
1497 _dispc_set_channel_out(plane, channel_out);
1498 enable_clocks(0);
1499}
1500
1501static int _dispc_setup_plane(enum omap_plane plane,
1502 u32 paddr, u16 screen_width,
1503 u16 pos_x, u16 pos_y,
1504 u16 width, u16 height,
1505 u16 out_width, u16 out_height,
1506 enum omap_color_mode color_mode,
1507 bool ilace,
1508 enum omap_dss_rotation_type rotation_type,
1509 u8 rotation, int mirror,
1510 u8 global_alpha)
1511{
1512 const int maxdownscale = cpu_is_omap34xx() ? 4 : 2;
1513 bool five_taps = 0;
1514 bool fieldmode = 0;
1515 int cconv = 0;
1516 unsigned offset0, offset1;
1517 s32 row_inc;
1518 s32 pix_inc;
1519 u16 frame_height = height;
1520 unsigned int field_offset = 0;
1521
1522 if (paddr == 0)
1523 return -EINVAL;
1524
1525 if (ilace && height == out_height)
1526 fieldmode = 1;
1527
1528 if (ilace) {
1529 if (fieldmode)
1530 height /= 2;
1531 pos_y /= 2;
1532 out_height /= 2;
1533
1534 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
1535 "out_height %d\n",
1536 height, pos_y, out_height);
1537 }
1538
1539 if (plane == OMAP_DSS_GFX) {
1540 if (width != out_width || height != out_height)
1541 return -EINVAL;
1542
1543 switch (color_mode) {
1544 case OMAP_DSS_COLOR_ARGB16:
1545 case OMAP_DSS_COLOR_ARGB32:
1546 case OMAP_DSS_COLOR_RGBA32:
Archit Tanejaa0acb552010-09-15 19:20:00 +05301547 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
1548 return -EINVAL;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001549 case OMAP_DSS_COLOR_RGBX32:
1550 if (cpu_is_omap24xx())
1551 return -EINVAL;
1552 /* fall through */
1553 case OMAP_DSS_COLOR_RGB12U:
1554 case OMAP_DSS_COLOR_RGB16:
1555 case OMAP_DSS_COLOR_RGB24P:
1556 case OMAP_DSS_COLOR_RGB24U:
1557 break;
1558
1559 default:
1560 return -EINVAL;
1561 }
1562 } else {
1563 /* video plane */
1564
1565 unsigned long fclk = 0;
1566
1567 if (out_width < width / maxdownscale ||
1568 out_width > width * 8)
1569 return -EINVAL;
1570
1571 if (out_height < height / maxdownscale ||
1572 out_height > height * 8)
1573 return -EINVAL;
1574
1575 switch (color_mode) {
1576 case OMAP_DSS_COLOR_RGBX32:
1577 case OMAP_DSS_COLOR_RGB12U:
1578 if (cpu_is_omap24xx())
1579 return -EINVAL;
1580 /* fall through */
1581 case OMAP_DSS_COLOR_RGB16:
1582 case OMAP_DSS_COLOR_RGB24P:
1583 case OMAP_DSS_COLOR_RGB24U:
1584 break;
1585
1586 case OMAP_DSS_COLOR_ARGB16:
1587 case OMAP_DSS_COLOR_ARGB32:
1588 case OMAP_DSS_COLOR_RGBA32:
Archit Tanejaa0acb552010-09-15 19:20:00 +05301589 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001590 return -EINVAL;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301591 if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
1592 plane == OMAP_DSS_VIDEO1)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001593 return -EINVAL;
1594 break;
1595
1596 case OMAP_DSS_COLOR_YUV2:
1597 case OMAP_DSS_COLOR_UYVY:
1598 cconv = 1;
1599 break;
1600
1601 default:
1602 return -EINVAL;
1603 }
1604
1605 /* Must use 5-tap filter? */
1606 five_taps = height > out_height * 2;
1607
1608 if (!five_taps) {
1609 fclk = calc_fclk(width, height,
1610 out_width, out_height);
1611
1612 /* Try 5-tap filter if 3-tap fclk is too high */
1613 if (cpu_is_omap34xx() && height > out_height &&
1614 fclk > dispc_fclk_rate())
1615 five_taps = true;
1616 }
1617
1618 if (width > (2048 >> five_taps)) {
1619 DSSERR("failed to set up scaling, fclk too low\n");
1620 return -EINVAL;
1621 }
1622
1623 if (five_taps)
1624 fclk = calc_fclk_five_taps(width, height,
1625 out_width, out_height, color_mode);
1626
1627 DSSDBG("required fclk rate = %lu Hz\n", fclk);
1628 DSSDBG("current fclk rate = %lu Hz\n", dispc_fclk_rate());
1629
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02001630 if (!fclk || fclk > dispc_fclk_rate()) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001631 DSSERR("failed to set up scaling, "
1632 "required fclk rate = %lu Hz, "
1633 "current fclk rate = %lu Hz\n",
1634 fclk, dispc_fclk_rate());
1635 return -EINVAL;
1636 }
1637 }
1638
1639 if (ilace && !fieldmode) {
1640 /*
1641 * when downscaling the bottom field may have to start several
1642 * source lines below the top field. Unfortunately ACCUI
1643 * registers will only hold the fractional part of the offset
1644 * so the integer part must be added to the base address of the
1645 * bottom field.
1646 */
1647 if (!height || height == out_height)
1648 field_offset = 0;
1649 else
1650 field_offset = height / out_height / 2;
1651 }
1652
1653 /* Fields are independent but interleaved in memory. */
1654 if (fieldmode)
1655 field_offset = 1;
1656
1657 if (rotation_type == OMAP_DSS_ROT_DMA)
1658 calc_dma_rotation_offset(rotation, mirror,
1659 screen_width, width, frame_height, color_mode,
1660 fieldmode, field_offset,
1661 &offset0, &offset1, &row_inc, &pix_inc);
1662 else
1663 calc_vrfb_rotation_offset(rotation, mirror,
1664 screen_width, width, frame_height, color_mode,
1665 fieldmode, field_offset,
1666 &offset0, &offset1, &row_inc, &pix_inc);
1667
1668 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
1669 offset0, offset1, row_inc, pix_inc);
1670
1671 _dispc_set_color_mode(plane, color_mode);
1672
1673 _dispc_set_plane_ba0(plane, paddr + offset0);
1674 _dispc_set_plane_ba1(plane, paddr + offset1);
1675
1676 _dispc_set_row_inc(plane, row_inc);
1677 _dispc_set_pix_inc(plane, pix_inc);
1678
1679 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, width, height,
1680 out_width, out_height);
1681
1682 _dispc_set_plane_pos(plane, pos_x, pos_y);
1683
1684 _dispc_set_pic_size(plane, width, height);
1685
1686 if (plane != OMAP_DSS_GFX) {
1687 _dispc_set_scaling(plane, width, height,
1688 out_width, out_height,
1689 ilace, five_taps, fieldmode);
1690 _dispc_set_vid_size(plane, out_width, out_height);
1691 _dispc_set_vid_color_conv(plane, cconv);
1692 }
1693
1694 _dispc_set_rotation_attrs(plane, rotation, mirror, color_mode);
1695
1696 if (plane != OMAP_DSS_VIDEO1)
1697 _dispc_setup_global_alpha(plane, global_alpha);
1698
1699 return 0;
1700}
1701
1702static void _dispc_enable_plane(enum omap_plane plane, bool enable)
1703{
1704 REG_FLD_MOD(dispc_reg_att[plane], enable ? 1 : 0, 0, 0);
1705}
1706
1707static void dispc_disable_isr(void *data, u32 mask)
1708{
1709 struct completion *compl = data;
1710 complete(compl);
1711}
1712
1713static void _enable_lcd_out(bool enable)
1714{
1715 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0);
1716}
1717
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001718static void dispc_enable_lcd_out(bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001719{
1720 struct completion frame_done_completion;
1721 bool is_on;
1722 int r;
1723
1724 enable_clocks(1);
1725
1726 /* When we disable LCD output, we need to wait until frame is done.
1727 * Otherwise the DSS is still working, and turning off the clocks
1728 * prevents DSS from going to OFF mode */
1729 is_on = REG_GET(DISPC_CONTROL, 0, 0);
1730
1731 if (!enable && is_on) {
1732 init_completion(&frame_done_completion);
1733
1734 r = omap_dispc_register_isr(dispc_disable_isr,
1735 &frame_done_completion,
1736 DISPC_IRQ_FRAMEDONE);
1737
1738 if (r)
1739 DSSERR("failed to register FRAMEDONE isr\n");
1740 }
1741
1742 _enable_lcd_out(enable);
1743
1744 if (!enable && is_on) {
1745 if (!wait_for_completion_timeout(&frame_done_completion,
1746 msecs_to_jiffies(100)))
1747 DSSERR("timeout waiting for FRAME DONE\n");
1748
1749 r = omap_dispc_unregister_isr(dispc_disable_isr,
1750 &frame_done_completion,
1751 DISPC_IRQ_FRAMEDONE);
1752
1753 if (r)
1754 DSSERR("failed to unregister FRAMEDONE isr\n");
1755 }
1756
1757 enable_clocks(0);
1758}
1759
1760static void _enable_digit_out(bool enable)
1761{
1762 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
1763}
1764
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001765static void dispc_enable_digit_out(bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001766{
1767 struct completion frame_done_completion;
1768 int r;
1769
1770 enable_clocks(1);
1771
1772 if (REG_GET(DISPC_CONTROL, 1, 1) == enable) {
1773 enable_clocks(0);
1774 return;
1775 }
1776
1777 if (enable) {
1778 unsigned long flags;
1779 /* When we enable digit output, we'll get an extra digit
1780 * sync lost interrupt, that we need to ignore */
1781 spin_lock_irqsave(&dispc.irq_lock, flags);
1782 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
1783 _omap_dispc_set_irqs();
1784 spin_unlock_irqrestore(&dispc.irq_lock, flags);
1785 }
1786
1787 /* When we disable digit output, we need to wait until fields are done.
1788 * Otherwise the DSS is still working, and turning off the clocks
1789 * prevents DSS from going to OFF mode. And when enabling, we need to
1790 * wait for the extra sync losts */
1791 init_completion(&frame_done_completion);
1792
1793 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
1794 DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD);
1795 if (r)
1796 DSSERR("failed to register EVSYNC isr\n");
1797
1798 _enable_digit_out(enable);
1799
1800 /* XXX I understand from TRM that we should only wait for the
1801 * current field to complete. But it seems we have to wait
1802 * for both fields */
1803 if (!wait_for_completion_timeout(&frame_done_completion,
1804 msecs_to_jiffies(100)))
1805 DSSERR("timeout waiting for EVSYNC\n");
1806
1807 if (!wait_for_completion_timeout(&frame_done_completion,
1808 msecs_to_jiffies(100)))
1809 DSSERR("timeout waiting for EVSYNC\n");
1810
1811 r = omap_dispc_unregister_isr(dispc_disable_isr,
1812 &frame_done_completion,
1813 DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD);
1814 if (r)
1815 DSSERR("failed to unregister EVSYNC isr\n");
1816
1817 if (enable) {
1818 unsigned long flags;
1819 spin_lock_irqsave(&dispc.irq_lock, flags);
1820 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
1821 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
1822 _omap_dispc_set_irqs();
1823 spin_unlock_irqrestore(&dispc.irq_lock, flags);
1824 }
1825
1826 enable_clocks(0);
1827}
1828
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001829bool dispc_is_channel_enabled(enum omap_channel channel)
1830{
1831 if (channel == OMAP_DSS_CHANNEL_LCD)
1832 return !!REG_GET(DISPC_CONTROL, 0, 0);
1833 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
1834 return !!REG_GET(DISPC_CONTROL, 1, 1);
1835 else
1836 BUG();
1837}
1838
1839void dispc_enable_channel(enum omap_channel channel, bool enable)
1840{
1841 if (channel == OMAP_DSS_CHANNEL_LCD)
1842 dispc_enable_lcd_out(enable);
1843 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
1844 dispc_enable_digit_out(enable);
1845 else
1846 BUG();
1847}
1848
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001849void dispc_lcd_enable_signal_polarity(bool act_high)
1850{
1851 enable_clocks(1);
1852 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
1853 enable_clocks(0);
1854}
1855
1856void dispc_lcd_enable_signal(bool enable)
1857{
1858 enable_clocks(1);
1859 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
1860 enable_clocks(0);
1861}
1862
1863void dispc_pck_free_enable(bool enable)
1864{
1865 enable_clocks(1);
1866 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
1867 enable_clocks(0);
1868}
1869
1870void dispc_enable_fifohandcheck(bool enable)
1871{
1872 enable_clocks(1);
1873 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 16, 16);
1874 enable_clocks(0);
1875}
1876
1877
1878void dispc_set_lcd_display_type(enum omap_lcd_display_type type)
1879{
1880 int mode;
1881
1882 switch (type) {
1883 case OMAP_DSS_LCD_DISPLAY_STN:
1884 mode = 0;
1885 break;
1886
1887 case OMAP_DSS_LCD_DISPLAY_TFT:
1888 mode = 1;
1889 break;
1890
1891 default:
1892 BUG();
1893 return;
1894 }
1895
1896 enable_clocks(1);
1897 REG_FLD_MOD(DISPC_CONTROL, mode, 3, 3);
1898 enable_clocks(0);
1899}
1900
1901void dispc_set_loadmode(enum omap_dss_load_mode mode)
1902{
1903 enable_clocks(1);
1904 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
1905 enable_clocks(0);
1906}
1907
1908
1909void dispc_set_default_color(enum omap_channel channel, u32 color)
1910{
1911 const struct dispc_reg def_reg[] = { DISPC_DEFAULT_COLOR0,
1912 DISPC_DEFAULT_COLOR1 };
1913
1914 enable_clocks(1);
1915 dispc_write_reg(def_reg[channel], color);
1916 enable_clocks(0);
1917}
1918
1919u32 dispc_get_default_color(enum omap_channel channel)
1920{
1921 const struct dispc_reg def_reg[] = { DISPC_DEFAULT_COLOR0,
1922 DISPC_DEFAULT_COLOR1 };
1923 u32 l;
1924
1925 BUG_ON(channel != OMAP_DSS_CHANNEL_DIGIT &&
1926 channel != OMAP_DSS_CHANNEL_LCD);
1927
1928 enable_clocks(1);
1929 l = dispc_read_reg(def_reg[channel]);
1930 enable_clocks(0);
1931
1932 return l;
1933}
1934
1935void dispc_set_trans_key(enum omap_channel ch,
1936 enum omap_dss_trans_key_type type,
1937 u32 trans_key)
1938{
1939 const struct dispc_reg tr_reg[] = {
1940 DISPC_TRANS_COLOR0, DISPC_TRANS_COLOR1 };
1941
1942 enable_clocks(1);
1943 if (ch == OMAP_DSS_CHANNEL_LCD)
1944 REG_FLD_MOD(DISPC_CONFIG, type, 11, 11);
1945 else /* OMAP_DSS_CHANNEL_DIGIT */
1946 REG_FLD_MOD(DISPC_CONFIG, type, 13, 13);
1947
1948 dispc_write_reg(tr_reg[ch], trans_key);
1949 enable_clocks(0);
1950}
1951
1952void dispc_get_trans_key(enum omap_channel ch,
1953 enum omap_dss_trans_key_type *type,
1954 u32 *trans_key)
1955{
1956 const struct dispc_reg tr_reg[] = {
1957 DISPC_TRANS_COLOR0, DISPC_TRANS_COLOR1 };
1958
1959 enable_clocks(1);
1960 if (type) {
1961 if (ch == OMAP_DSS_CHANNEL_LCD)
1962 *type = REG_GET(DISPC_CONFIG, 11, 11);
1963 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
1964 *type = REG_GET(DISPC_CONFIG, 13, 13);
1965 else
1966 BUG();
1967 }
1968
1969 if (trans_key)
1970 *trans_key = dispc_read_reg(tr_reg[ch]);
1971 enable_clocks(0);
1972}
1973
1974void dispc_enable_trans_key(enum omap_channel ch, bool enable)
1975{
1976 enable_clocks(1);
1977 if (ch == OMAP_DSS_CHANNEL_LCD)
1978 REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10);
1979 else /* OMAP_DSS_CHANNEL_DIGIT */
1980 REG_FLD_MOD(DISPC_CONFIG, enable, 12, 12);
1981 enable_clocks(0);
1982}
1983void dispc_enable_alpha_blending(enum omap_channel ch, bool enable)
1984{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301985 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001986 return;
1987
1988 enable_clocks(1);
1989 if (ch == OMAP_DSS_CHANNEL_LCD)
1990 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
1991 else /* OMAP_DSS_CHANNEL_DIGIT */
1992 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
1993 enable_clocks(0);
1994}
1995bool dispc_alpha_blending_enabled(enum omap_channel ch)
1996{
1997 bool enabled;
1998
Archit Tanejaa0acb552010-09-15 19:20:00 +05301999 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002000 return false;
2001
2002 enable_clocks(1);
2003 if (ch == OMAP_DSS_CHANNEL_LCD)
2004 enabled = REG_GET(DISPC_CONFIG, 18, 18);
2005 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Archit Taneja712247a2010-11-08 12:56:21 +01002006 enabled = REG_GET(DISPC_CONFIG, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002007 else
2008 BUG();
2009 enable_clocks(0);
2010
2011 return enabled;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002012}
2013
2014
2015bool dispc_trans_key_enabled(enum omap_channel ch)
2016{
2017 bool enabled;
2018
2019 enable_clocks(1);
2020 if (ch == OMAP_DSS_CHANNEL_LCD)
2021 enabled = REG_GET(DISPC_CONFIG, 10, 10);
2022 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2023 enabled = REG_GET(DISPC_CONFIG, 12, 12);
2024 else
2025 BUG();
2026 enable_clocks(0);
2027
2028 return enabled;
2029}
2030
2031
2032void dispc_set_tft_data_lines(u8 data_lines)
2033{
2034 int code;
2035
2036 switch (data_lines) {
2037 case 12:
2038 code = 0;
2039 break;
2040 case 16:
2041 code = 1;
2042 break;
2043 case 18:
2044 code = 2;
2045 break;
2046 case 24:
2047 code = 3;
2048 break;
2049 default:
2050 BUG();
2051 return;
2052 }
2053
2054 enable_clocks(1);
2055 REG_FLD_MOD(DISPC_CONTROL, code, 9, 8);
2056 enable_clocks(0);
2057}
2058
2059void dispc_set_parallel_interface_mode(enum omap_parallel_interface_mode mode)
2060{
2061 u32 l;
2062 int stallmode;
2063 int gpout0 = 1;
2064 int gpout1;
2065
2066 switch (mode) {
2067 case OMAP_DSS_PARALLELMODE_BYPASS:
2068 stallmode = 0;
2069 gpout1 = 1;
2070 break;
2071
2072 case OMAP_DSS_PARALLELMODE_RFBI:
2073 stallmode = 1;
2074 gpout1 = 0;
2075 break;
2076
2077 case OMAP_DSS_PARALLELMODE_DSI:
2078 stallmode = 1;
2079 gpout1 = 1;
2080 break;
2081
2082 default:
2083 BUG();
2084 return;
2085 }
2086
2087 enable_clocks(1);
2088
2089 l = dispc_read_reg(DISPC_CONTROL);
2090
2091 l = FLD_MOD(l, stallmode, 11, 11);
2092 l = FLD_MOD(l, gpout0, 15, 15);
2093 l = FLD_MOD(l, gpout1, 16, 16);
2094
2095 dispc_write_reg(DISPC_CONTROL, l);
2096
2097 enable_clocks(0);
2098}
2099
2100static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2101 int vsw, int vfp, int vbp)
2102{
2103 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2104 if (hsw < 1 || hsw > 64 ||
2105 hfp < 1 || hfp > 256 ||
2106 hbp < 1 || hbp > 256 ||
2107 vsw < 1 || vsw > 64 ||
2108 vfp < 0 || vfp > 255 ||
2109 vbp < 0 || vbp > 255)
2110 return false;
2111 } else {
2112 if (hsw < 1 || hsw > 256 ||
2113 hfp < 1 || hfp > 4096 ||
2114 hbp < 1 || hbp > 4096 ||
2115 vsw < 1 || vsw > 256 ||
2116 vfp < 0 || vfp > 4095 ||
2117 vbp < 0 || vbp > 4095)
2118 return false;
2119 }
2120
2121 return true;
2122}
2123
2124bool dispc_lcd_timings_ok(struct omap_video_timings *timings)
2125{
2126 return _dispc_lcd_timings_ok(timings->hsw, timings->hfp,
2127 timings->hbp, timings->vsw,
2128 timings->vfp, timings->vbp);
2129}
2130
2131static void _dispc_set_lcd_timings(int hsw, int hfp, int hbp,
2132 int vsw, int vfp, int vbp)
2133{
2134 u32 timing_h, timing_v;
2135
2136 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2137 timing_h = FLD_VAL(hsw-1, 5, 0) | FLD_VAL(hfp-1, 15, 8) |
2138 FLD_VAL(hbp-1, 27, 20);
2139
2140 timing_v = FLD_VAL(vsw-1, 5, 0) | FLD_VAL(vfp, 15, 8) |
2141 FLD_VAL(vbp, 27, 20);
2142 } else {
2143 timing_h = FLD_VAL(hsw-1, 7, 0) | FLD_VAL(hfp-1, 19, 8) |
2144 FLD_VAL(hbp-1, 31, 20);
2145
2146 timing_v = FLD_VAL(vsw-1, 7, 0) | FLD_VAL(vfp, 19, 8) |
2147 FLD_VAL(vbp, 31, 20);
2148 }
2149
2150 enable_clocks(1);
2151 dispc_write_reg(DISPC_TIMING_H, timing_h);
2152 dispc_write_reg(DISPC_TIMING_V, timing_v);
2153 enable_clocks(0);
2154}
2155
2156/* change name to mode? */
2157void dispc_set_lcd_timings(struct omap_video_timings *timings)
2158{
2159 unsigned xtot, ytot;
2160 unsigned long ht, vt;
2161
2162 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
2163 timings->hbp, timings->vsw,
2164 timings->vfp, timings->vbp))
2165 BUG();
2166
2167 _dispc_set_lcd_timings(timings->hsw, timings->hfp, timings->hbp,
2168 timings->vsw, timings->vfp, timings->vbp);
2169
2170 dispc_set_lcd_size(timings->x_res, timings->y_res);
2171
2172 xtot = timings->x_res + timings->hfp + timings->hsw + timings->hbp;
2173 ytot = timings->y_res + timings->vfp + timings->vsw + timings->vbp;
2174
2175 ht = (timings->pixel_clock * 1000) / xtot;
2176 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2177
2178 DSSDBG("xres %u yres %u\n", timings->x_res, timings->y_res);
2179 DSSDBG("pck %u\n", timings->pixel_clock);
2180 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2181 timings->hsw, timings->hfp, timings->hbp,
2182 timings->vsw, timings->vfp, timings->vbp);
2183
2184 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2185}
2186
2187static void dispc_set_lcd_divisor(u16 lck_div, u16 pck_div)
2188{
2189 BUG_ON(lck_div < 1);
2190 BUG_ON(pck_div < 2);
2191
2192 enable_clocks(1);
2193 dispc_write_reg(DISPC_DIVISOR,
2194 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
2195 enable_clocks(0);
2196}
2197
2198static void dispc_get_lcd_divisor(int *lck_div, int *pck_div)
2199{
2200 u32 l;
2201 l = dispc_read_reg(DISPC_DIVISOR);
2202 *lck_div = FLD_GET(l, 23, 16);
2203 *pck_div = FLD_GET(l, 7, 0);
2204}
2205
2206unsigned long dispc_fclk_rate(void)
2207{
2208 unsigned long r = 0;
2209
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02002210 if (dss_get_dispc_clk_source() == DSS_SRC_DSS1_ALWON_FCLK)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002211 r = dss_clk_get_rate(DSS_CLK_FCK1);
2212 else
2213#ifdef CONFIG_OMAP2_DSS_DSI
2214 r = dsi_get_dsi1_pll_rate();
2215#else
2216 BUG();
2217#endif
2218 return r;
2219}
2220
2221unsigned long dispc_lclk_rate(void)
2222{
2223 int lcd;
2224 unsigned long r;
2225 u32 l;
2226
2227 l = dispc_read_reg(DISPC_DIVISOR);
2228
2229 lcd = FLD_GET(l, 23, 16);
2230
2231 r = dispc_fclk_rate();
2232
2233 return r / lcd;
2234}
2235
2236unsigned long dispc_pclk_rate(void)
2237{
2238 int lcd, pcd;
2239 unsigned long r;
2240 u32 l;
2241
2242 l = dispc_read_reg(DISPC_DIVISOR);
2243
2244 lcd = FLD_GET(l, 23, 16);
2245 pcd = FLD_GET(l, 7, 0);
2246
2247 r = dispc_fclk_rate();
2248
2249 return r / lcd / pcd;
2250}
2251
2252void dispc_dump_clocks(struct seq_file *s)
2253{
2254 int lcd, pcd;
2255
2256 enable_clocks(1);
2257
2258 dispc_get_lcd_divisor(&lcd, &pcd);
2259
2260 seq_printf(s, "- DISPC -\n");
2261
2262 seq_printf(s, "dispc fclk source = %s\n",
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02002263 dss_get_dispc_clk_source() == DSS_SRC_DSS1_ALWON_FCLK ?
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002264 "dss1_alwon_fclk" : "dsi1_pll_fclk");
2265
2266 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
2267 seq_printf(s, "lck\t\t%-16lulck div\t%u\n", dispc_lclk_rate(), lcd);
2268 seq_printf(s, "pck\t\t%-16lupck div\t%u\n", dispc_pclk_rate(), pcd);
2269
2270 enable_clocks(0);
2271}
2272
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02002273#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
2274void dispc_dump_irqs(struct seq_file *s)
2275{
2276 unsigned long flags;
2277 struct dispc_irq_stats stats;
2278
2279 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
2280
2281 stats = dispc.irq_stats;
2282 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
2283 dispc.irq_stats.last_reset = jiffies;
2284
2285 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
2286
2287 seq_printf(s, "period %u ms\n",
2288 jiffies_to_msecs(jiffies - stats.last_reset));
2289
2290 seq_printf(s, "irqs %d\n", stats.irq_count);
2291#define PIS(x) \
2292 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
2293
2294 PIS(FRAMEDONE);
2295 PIS(VSYNC);
2296 PIS(EVSYNC_EVEN);
2297 PIS(EVSYNC_ODD);
2298 PIS(ACBIAS_COUNT_STAT);
2299 PIS(PROG_LINE_NUM);
2300 PIS(GFX_FIFO_UNDERFLOW);
2301 PIS(GFX_END_WIN);
2302 PIS(PAL_GAMMA_MASK);
2303 PIS(OCP_ERR);
2304 PIS(VID1_FIFO_UNDERFLOW);
2305 PIS(VID1_END_WIN);
2306 PIS(VID2_FIFO_UNDERFLOW);
2307 PIS(VID2_END_WIN);
2308 PIS(SYNC_LOST);
2309 PIS(SYNC_LOST_DIGIT);
2310 PIS(WAKEUP);
2311#undef PIS
2312}
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02002313#endif
2314
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002315void dispc_dump_regs(struct seq_file *s)
2316{
2317#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dispc_read_reg(r))
2318
2319 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
2320
2321 DUMPREG(DISPC_REVISION);
2322 DUMPREG(DISPC_SYSCONFIG);
2323 DUMPREG(DISPC_SYSSTATUS);
2324 DUMPREG(DISPC_IRQSTATUS);
2325 DUMPREG(DISPC_IRQENABLE);
2326 DUMPREG(DISPC_CONTROL);
2327 DUMPREG(DISPC_CONFIG);
2328 DUMPREG(DISPC_CAPABLE);
2329 DUMPREG(DISPC_DEFAULT_COLOR0);
2330 DUMPREG(DISPC_DEFAULT_COLOR1);
2331 DUMPREG(DISPC_TRANS_COLOR0);
2332 DUMPREG(DISPC_TRANS_COLOR1);
2333 DUMPREG(DISPC_LINE_STATUS);
2334 DUMPREG(DISPC_LINE_NUMBER);
2335 DUMPREG(DISPC_TIMING_H);
2336 DUMPREG(DISPC_TIMING_V);
2337 DUMPREG(DISPC_POL_FREQ);
2338 DUMPREG(DISPC_DIVISOR);
2339 DUMPREG(DISPC_GLOBAL_ALPHA);
2340 DUMPREG(DISPC_SIZE_DIG);
2341 DUMPREG(DISPC_SIZE_LCD);
2342
2343 DUMPREG(DISPC_GFX_BA0);
2344 DUMPREG(DISPC_GFX_BA1);
2345 DUMPREG(DISPC_GFX_POSITION);
2346 DUMPREG(DISPC_GFX_SIZE);
2347 DUMPREG(DISPC_GFX_ATTRIBUTES);
2348 DUMPREG(DISPC_GFX_FIFO_THRESHOLD);
2349 DUMPREG(DISPC_GFX_FIFO_SIZE_STATUS);
2350 DUMPREG(DISPC_GFX_ROW_INC);
2351 DUMPREG(DISPC_GFX_PIXEL_INC);
2352 DUMPREG(DISPC_GFX_WINDOW_SKIP);
2353 DUMPREG(DISPC_GFX_TABLE_BA);
2354
2355 DUMPREG(DISPC_DATA_CYCLE1);
2356 DUMPREG(DISPC_DATA_CYCLE2);
2357 DUMPREG(DISPC_DATA_CYCLE3);
2358
2359 DUMPREG(DISPC_CPR_COEF_R);
2360 DUMPREG(DISPC_CPR_COEF_G);
2361 DUMPREG(DISPC_CPR_COEF_B);
2362
2363 DUMPREG(DISPC_GFX_PRELOAD);
2364
2365 DUMPREG(DISPC_VID_BA0(0));
2366 DUMPREG(DISPC_VID_BA1(0));
2367 DUMPREG(DISPC_VID_POSITION(0));
2368 DUMPREG(DISPC_VID_SIZE(0));
2369 DUMPREG(DISPC_VID_ATTRIBUTES(0));
2370 DUMPREG(DISPC_VID_FIFO_THRESHOLD(0));
2371 DUMPREG(DISPC_VID_FIFO_SIZE_STATUS(0));
2372 DUMPREG(DISPC_VID_ROW_INC(0));
2373 DUMPREG(DISPC_VID_PIXEL_INC(0));
2374 DUMPREG(DISPC_VID_FIR(0));
2375 DUMPREG(DISPC_VID_PICTURE_SIZE(0));
2376 DUMPREG(DISPC_VID_ACCU0(0));
2377 DUMPREG(DISPC_VID_ACCU1(0));
2378
2379 DUMPREG(DISPC_VID_BA0(1));
2380 DUMPREG(DISPC_VID_BA1(1));
2381 DUMPREG(DISPC_VID_POSITION(1));
2382 DUMPREG(DISPC_VID_SIZE(1));
2383 DUMPREG(DISPC_VID_ATTRIBUTES(1));
2384 DUMPREG(DISPC_VID_FIFO_THRESHOLD(1));
2385 DUMPREG(DISPC_VID_FIFO_SIZE_STATUS(1));
2386 DUMPREG(DISPC_VID_ROW_INC(1));
2387 DUMPREG(DISPC_VID_PIXEL_INC(1));
2388 DUMPREG(DISPC_VID_FIR(1));
2389 DUMPREG(DISPC_VID_PICTURE_SIZE(1));
2390 DUMPREG(DISPC_VID_ACCU0(1));
2391 DUMPREG(DISPC_VID_ACCU1(1));
2392
2393 DUMPREG(DISPC_VID_FIR_COEF_H(0, 0));
2394 DUMPREG(DISPC_VID_FIR_COEF_H(0, 1));
2395 DUMPREG(DISPC_VID_FIR_COEF_H(0, 2));
2396 DUMPREG(DISPC_VID_FIR_COEF_H(0, 3));
2397 DUMPREG(DISPC_VID_FIR_COEF_H(0, 4));
2398 DUMPREG(DISPC_VID_FIR_COEF_H(0, 5));
2399 DUMPREG(DISPC_VID_FIR_COEF_H(0, 6));
2400 DUMPREG(DISPC_VID_FIR_COEF_H(0, 7));
2401 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 0));
2402 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 1));
2403 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 2));
2404 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 3));
2405 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 4));
2406 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 5));
2407 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 6));
2408 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 7));
2409 DUMPREG(DISPC_VID_CONV_COEF(0, 0));
2410 DUMPREG(DISPC_VID_CONV_COEF(0, 1));
2411 DUMPREG(DISPC_VID_CONV_COEF(0, 2));
2412 DUMPREG(DISPC_VID_CONV_COEF(0, 3));
2413 DUMPREG(DISPC_VID_CONV_COEF(0, 4));
2414 DUMPREG(DISPC_VID_FIR_COEF_V(0, 0));
2415 DUMPREG(DISPC_VID_FIR_COEF_V(0, 1));
2416 DUMPREG(DISPC_VID_FIR_COEF_V(0, 2));
2417 DUMPREG(DISPC_VID_FIR_COEF_V(0, 3));
2418 DUMPREG(DISPC_VID_FIR_COEF_V(0, 4));
2419 DUMPREG(DISPC_VID_FIR_COEF_V(0, 5));
2420 DUMPREG(DISPC_VID_FIR_COEF_V(0, 6));
2421 DUMPREG(DISPC_VID_FIR_COEF_V(0, 7));
2422
2423 DUMPREG(DISPC_VID_FIR_COEF_H(1, 0));
2424 DUMPREG(DISPC_VID_FIR_COEF_H(1, 1));
2425 DUMPREG(DISPC_VID_FIR_COEF_H(1, 2));
2426 DUMPREG(DISPC_VID_FIR_COEF_H(1, 3));
2427 DUMPREG(DISPC_VID_FIR_COEF_H(1, 4));
2428 DUMPREG(DISPC_VID_FIR_COEF_H(1, 5));
2429 DUMPREG(DISPC_VID_FIR_COEF_H(1, 6));
2430 DUMPREG(DISPC_VID_FIR_COEF_H(1, 7));
2431 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 0));
2432 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 1));
2433 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 2));
2434 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 3));
2435 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 4));
2436 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 5));
2437 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 6));
2438 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 7));
2439 DUMPREG(DISPC_VID_CONV_COEF(1, 0));
2440 DUMPREG(DISPC_VID_CONV_COEF(1, 1));
2441 DUMPREG(DISPC_VID_CONV_COEF(1, 2));
2442 DUMPREG(DISPC_VID_CONV_COEF(1, 3));
2443 DUMPREG(DISPC_VID_CONV_COEF(1, 4));
2444 DUMPREG(DISPC_VID_FIR_COEF_V(1, 0));
2445 DUMPREG(DISPC_VID_FIR_COEF_V(1, 1));
2446 DUMPREG(DISPC_VID_FIR_COEF_V(1, 2));
2447 DUMPREG(DISPC_VID_FIR_COEF_V(1, 3));
2448 DUMPREG(DISPC_VID_FIR_COEF_V(1, 4));
2449 DUMPREG(DISPC_VID_FIR_COEF_V(1, 5));
2450 DUMPREG(DISPC_VID_FIR_COEF_V(1, 6));
2451 DUMPREG(DISPC_VID_FIR_COEF_V(1, 7));
2452
2453 DUMPREG(DISPC_VID_PRELOAD(0));
2454 DUMPREG(DISPC_VID_PRELOAD(1));
2455
2456 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
2457#undef DUMPREG
2458}
2459
2460static void _dispc_set_pol_freq(bool onoff, bool rf, bool ieo, bool ipc,
2461 bool ihs, bool ivs, u8 acbi, u8 acb)
2462{
2463 u32 l = 0;
2464
2465 DSSDBG("onoff %d rf %d ieo %d ipc %d ihs %d ivs %d acbi %d acb %d\n",
2466 onoff, rf, ieo, ipc, ihs, ivs, acbi, acb);
2467
2468 l |= FLD_VAL(onoff, 17, 17);
2469 l |= FLD_VAL(rf, 16, 16);
2470 l |= FLD_VAL(ieo, 15, 15);
2471 l |= FLD_VAL(ipc, 14, 14);
2472 l |= FLD_VAL(ihs, 13, 13);
2473 l |= FLD_VAL(ivs, 12, 12);
2474 l |= FLD_VAL(acbi, 11, 8);
2475 l |= FLD_VAL(acb, 7, 0);
2476
2477 enable_clocks(1);
2478 dispc_write_reg(DISPC_POL_FREQ, l);
2479 enable_clocks(0);
2480}
2481
2482void dispc_set_pol_freq(enum omap_panel_config config, u8 acbi, u8 acb)
2483{
2484 _dispc_set_pol_freq((config & OMAP_DSS_LCD_ONOFF) != 0,
2485 (config & OMAP_DSS_LCD_RF) != 0,
2486 (config & OMAP_DSS_LCD_IEO) != 0,
2487 (config & OMAP_DSS_LCD_IPC) != 0,
2488 (config & OMAP_DSS_LCD_IHS) != 0,
2489 (config & OMAP_DSS_LCD_IVS) != 0,
2490 acbi, acb);
2491}
2492
2493/* with fck as input clock rate, find dispc dividers that produce req_pck */
2494void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
2495 struct dispc_clock_info *cinfo)
2496{
2497 u16 pcd_min = is_tft ? 2 : 3;
2498 unsigned long best_pck;
2499 u16 best_ld, cur_ld;
2500 u16 best_pd, cur_pd;
2501
2502 best_pck = 0;
2503 best_ld = 0;
2504 best_pd = 0;
2505
2506 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
2507 unsigned long lck = fck / cur_ld;
2508
2509 for (cur_pd = pcd_min; cur_pd <= 255; ++cur_pd) {
2510 unsigned long pck = lck / cur_pd;
2511 long old_delta = abs(best_pck - req_pck);
2512 long new_delta = abs(pck - req_pck);
2513
2514 if (best_pck == 0 || new_delta < old_delta) {
2515 best_pck = pck;
2516 best_ld = cur_ld;
2517 best_pd = cur_pd;
2518
2519 if (pck == req_pck)
2520 goto found;
2521 }
2522
2523 if (pck < req_pck)
2524 break;
2525 }
2526
2527 if (lck / pcd_min < req_pck)
2528 break;
2529 }
2530
2531found:
2532 cinfo->lck_div = best_ld;
2533 cinfo->pck_div = best_pd;
2534 cinfo->lck = fck / cinfo->lck_div;
2535 cinfo->pck = cinfo->lck / cinfo->pck_div;
2536}
2537
2538/* calculate clock rates using dividers in cinfo */
2539int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
2540 struct dispc_clock_info *cinfo)
2541{
2542 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
2543 return -EINVAL;
2544 if (cinfo->pck_div < 2 || cinfo->pck_div > 255)
2545 return -EINVAL;
2546
2547 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
2548 cinfo->pck = cinfo->lck / cinfo->pck_div;
2549
2550 return 0;
2551}
2552
2553int dispc_set_clock_div(struct dispc_clock_info *cinfo)
2554{
2555 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
2556 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
2557
2558 dispc_set_lcd_divisor(cinfo->lck_div, cinfo->pck_div);
2559
2560 return 0;
2561}
2562
2563int dispc_get_clock_div(struct dispc_clock_info *cinfo)
2564{
2565 unsigned long fck;
2566
2567 fck = dispc_fclk_rate();
2568
2569 cinfo->lck_div = REG_GET(DISPC_DIVISOR, 23, 16);
2570 cinfo->pck_div = REG_GET(DISPC_DIVISOR, 7, 0);
2571
2572 cinfo->lck = fck / cinfo->lck_div;
2573 cinfo->pck = cinfo->lck / cinfo->pck_div;
2574
2575 return 0;
2576}
2577
2578/* dispc.irq_lock has to be locked by the caller */
2579static void _omap_dispc_set_irqs(void)
2580{
2581 u32 mask;
2582 u32 old_mask;
2583 int i;
2584 struct omap_dispc_isr_data *isr_data;
2585
2586 mask = dispc.irq_error_mask;
2587
2588 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2589 isr_data = &dispc.registered_isr[i];
2590
2591 if (isr_data->isr == NULL)
2592 continue;
2593
2594 mask |= isr_data->mask;
2595 }
2596
2597 enable_clocks(1);
2598
2599 old_mask = dispc_read_reg(DISPC_IRQENABLE);
2600 /* clear the irqstatus for newly enabled irqs */
2601 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
2602
2603 dispc_write_reg(DISPC_IRQENABLE, mask);
2604
2605 enable_clocks(0);
2606}
2607
2608int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
2609{
2610 int i;
2611 int ret;
2612 unsigned long flags;
2613 struct omap_dispc_isr_data *isr_data;
2614
2615 if (isr == NULL)
2616 return -EINVAL;
2617
2618 spin_lock_irqsave(&dispc.irq_lock, flags);
2619
2620 /* check for duplicate entry */
2621 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2622 isr_data = &dispc.registered_isr[i];
2623 if (isr_data->isr == isr && isr_data->arg == arg &&
2624 isr_data->mask == mask) {
2625 ret = -EINVAL;
2626 goto err;
2627 }
2628 }
2629
2630 isr_data = NULL;
2631 ret = -EBUSY;
2632
2633 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2634 isr_data = &dispc.registered_isr[i];
2635
2636 if (isr_data->isr != NULL)
2637 continue;
2638
2639 isr_data->isr = isr;
2640 isr_data->arg = arg;
2641 isr_data->mask = mask;
2642 ret = 0;
2643
2644 break;
2645 }
2646
2647 _omap_dispc_set_irqs();
2648
2649 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2650
2651 return 0;
2652err:
2653 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2654
2655 return ret;
2656}
2657EXPORT_SYMBOL(omap_dispc_register_isr);
2658
2659int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
2660{
2661 int i;
2662 unsigned long flags;
2663 int ret = -EINVAL;
2664 struct omap_dispc_isr_data *isr_data;
2665
2666 spin_lock_irqsave(&dispc.irq_lock, flags);
2667
2668 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2669 isr_data = &dispc.registered_isr[i];
2670 if (isr_data->isr != isr || isr_data->arg != arg ||
2671 isr_data->mask != mask)
2672 continue;
2673
2674 /* found the correct isr */
2675
2676 isr_data->isr = NULL;
2677 isr_data->arg = NULL;
2678 isr_data->mask = 0;
2679
2680 ret = 0;
2681 break;
2682 }
2683
2684 if (ret == 0)
2685 _omap_dispc_set_irqs();
2686
2687 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2688
2689 return ret;
2690}
2691EXPORT_SYMBOL(omap_dispc_unregister_isr);
2692
2693#ifdef DEBUG
2694static void print_irq_status(u32 status)
2695{
2696 if ((status & dispc.irq_error_mask) == 0)
2697 return;
2698
2699 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
2700
2701#define PIS(x) \
2702 if (status & DISPC_IRQ_##x) \
2703 printk(#x " ");
2704 PIS(GFX_FIFO_UNDERFLOW);
2705 PIS(OCP_ERR);
2706 PIS(VID1_FIFO_UNDERFLOW);
2707 PIS(VID2_FIFO_UNDERFLOW);
2708 PIS(SYNC_LOST);
2709 PIS(SYNC_LOST_DIGIT);
2710#undef PIS
2711
2712 printk("\n");
2713}
2714#endif
2715
2716/* Called from dss.c. Note that we don't touch clocks here,
2717 * but we presume they are on because we got an IRQ. However,
2718 * an irq handler may turn the clocks off, so we may not have
2719 * clock later in the function. */
2720void dispc_irq_handler(void)
2721{
2722 int i;
2723 u32 irqstatus;
2724 u32 handledirqs = 0;
2725 u32 unhandled_errors;
2726 struct omap_dispc_isr_data *isr_data;
2727 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
2728
2729 spin_lock(&dispc.irq_lock);
2730
2731 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
2732
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02002733#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
2734 spin_lock(&dispc.irq_stats_lock);
2735 dispc.irq_stats.irq_count++;
2736 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
2737 spin_unlock(&dispc.irq_stats_lock);
2738#endif
2739
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002740#ifdef DEBUG
2741 if (dss_debug)
2742 print_irq_status(irqstatus);
2743#endif
2744 /* Ack the interrupt. Do it here before clocks are possibly turned
2745 * off */
2746 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
2747 /* flush posted write */
2748 dispc_read_reg(DISPC_IRQSTATUS);
2749
2750 /* make a copy and unlock, so that isrs can unregister
2751 * themselves */
2752 memcpy(registered_isr, dispc.registered_isr,
2753 sizeof(registered_isr));
2754
2755 spin_unlock(&dispc.irq_lock);
2756
2757 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2758 isr_data = &registered_isr[i];
2759
2760 if (!isr_data->isr)
2761 continue;
2762
2763 if (isr_data->mask & irqstatus) {
2764 isr_data->isr(isr_data->arg, irqstatus);
2765 handledirqs |= isr_data->mask;
2766 }
2767 }
2768
2769 spin_lock(&dispc.irq_lock);
2770
2771 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
2772
2773 if (unhandled_errors) {
2774 dispc.error_irqs |= unhandled_errors;
2775
2776 dispc.irq_error_mask &= ~unhandled_errors;
2777 _omap_dispc_set_irqs();
2778
2779 schedule_work(&dispc.error_work);
2780 }
2781
2782 spin_unlock(&dispc.irq_lock);
2783}
2784
2785static void dispc_error_worker(struct work_struct *work)
2786{
2787 int i;
2788 u32 errors;
2789 unsigned long flags;
2790
2791 spin_lock_irqsave(&dispc.irq_lock, flags);
2792 errors = dispc.error_irqs;
2793 dispc.error_irqs = 0;
2794 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2795
2796 if (errors & DISPC_IRQ_GFX_FIFO_UNDERFLOW) {
2797 DSSERR("GFX_FIFO_UNDERFLOW, disabling GFX\n");
2798 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
2799 struct omap_overlay *ovl;
2800 ovl = omap_dss_get_overlay(i);
2801
2802 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
2803 continue;
2804
2805 if (ovl->id == 0) {
2806 dispc_enable_plane(ovl->id, 0);
2807 dispc_go(ovl->manager->id);
2808 mdelay(50);
2809 break;
2810 }
2811 }
2812 }
2813
2814 if (errors & DISPC_IRQ_VID1_FIFO_UNDERFLOW) {
2815 DSSERR("VID1_FIFO_UNDERFLOW, disabling VID1\n");
2816 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
2817 struct omap_overlay *ovl;
2818 ovl = omap_dss_get_overlay(i);
2819
2820 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
2821 continue;
2822
2823 if (ovl->id == 1) {
2824 dispc_enable_plane(ovl->id, 0);
2825 dispc_go(ovl->manager->id);
2826 mdelay(50);
2827 break;
2828 }
2829 }
2830 }
2831
2832 if (errors & DISPC_IRQ_VID2_FIFO_UNDERFLOW) {
2833 DSSERR("VID2_FIFO_UNDERFLOW, disabling VID2\n");
2834 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
2835 struct omap_overlay *ovl;
2836 ovl = omap_dss_get_overlay(i);
2837
2838 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
2839 continue;
2840
2841 if (ovl->id == 2) {
2842 dispc_enable_plane(ovl->id, 0);
2843 dispc_go(ovl->manager->id);
2844 mdelay(50);
2845 break;
2846 }
2847 }
2848 }
2849
2850 if (errors & DISPC_IRQ_SYNC_LOST) {
2851 struct omap_overlay_manager *manager = NULL;
2852 bool enable = false;
2853
2854 DSSERR("SYNC_LOST, disabling LCD\n");
2855
2856 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
2857 struct omap_overlay_manager *mgr;
2858 mgr = omap_dss_get_overlay_manager(i);
2859
2860 if (mgr->id == OMAP_DSS_CHANNEL_LCD) {
2861 manager = mgr;
2862 enable = mgr->device->state ==
2863 OMAP_DSS_DISPLAY_ACTIVE;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02002864 mgr->device->driver->disable(mgr->device);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002865 break;
2866 }
2867 }
2868
2869 if (manager) {
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02002870 struct omap_dss_device *dssdev = manager->device;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002871 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
2872 struct omap_overlay *ovl;
2873 ovl = omap_dss_get_overlay(i);
2874
2875 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
2876 continue;
2877
2878 if (ovl->id != 0 && ovl->manager == manager)
2879 dispc_enable_plane(ovl->id, 0);
2880 }
2881
2882 dispc_go(manager->id);
2883 mdelay(50);
2884 if (enable)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02002885 dssdev->driver->enable(dssdev);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002886 }
2887 }
2888
2889 if (errors & DISPC_IRQ_SYNC_LOST_DIGIT) {
2890 struct omap_overlay_manager *manager = NULL;
2891 bool enable = false;
2892
2893 DSSERR("SYNC_LOST_DIGIT, disabling TV\n");
2894
2895 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
2896 struct omap_overlay_manager *mgr;
2897 mgr = omap_dss_get_overlay_manager(i);
2898
2899 if (mgr->id == OMAP_DSS_CHANNEL_DIGIT) {
2900 manager = mgr;
2901 enable = mgr->device->state ==
2902 OMAP_DSS_DISPLAY_ACTIVE;
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02002903 mgr->device->driver->disable(mgr->device);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002904 break;
2905 }
2906 }
2907
2908 if (manager) {
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02002909 struct omap_dss_device *dssdev = manager->device;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002910 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
2911 struct omap_overlay *ovl;
2912 ovl = omap_dss_get_overlay(i);
2913
2914 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
2915 continue;
2916
2917 if (ovl->id != 0 && ovl->manager == manager)
2918 dispc_enable_plane(ovl->id, 0);
2919 }
2920
2921 dispc_go(manager->id);
2922 mdelay(50);
2923 if (enable)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02002924 dssdev->driver->enable(dssdev);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002925 }
2926 }
2927
2928 if (errors & DISPC_IRQ_OCP_ERR) {
2929 DSSERR("OCP_ERR\n");
2930 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
2931 struct omap_overlay_manager *mgr;
2932 mgr = omap_dss_get_overlay_manager(i);
2933
2934 if (mgr->caps & OMAP_DSS_OVL_CAP_DISPC)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02002935 mgr->device->driver->disable(mgr->device);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002936 }
2937 }
2938
2939 spin_lock_irqsave(&dispc.irq_lock, flags);
2940 dispc.irq_error_mask |= errors;
2941 _omap_dispc_set_irqs();
2942 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2943}
2944
2945int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
2946{
2947 void dispc_irq_wait_handler(void *data, u32 mask)
2948 {
2949 complete((struct completion *)data);
2950 }
2951
2952 int r;
2953 DECLARE_COMPLETION_ONSTACK(completion);
2954
2955 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
2956 irqmask);
2957
2958 if (r)
2959 return r;
2960
2961 timeout = wait_for_completion_timeout(&completion, timeout);
2962
2963 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
2964
2965 if (timeout == 0)
2966 return -ETIMEDOUT;
2967
2968 if (timeout == -ERESTARTSYS)
2969 return -ERESTARTSYS;
2970
2971 return 0;
2972}
2973
2974int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
2975 unsigned long timeout)
2976{
2977 void dispc_irq_wait_handler(void *data, u32 mask)
2978 {
2979 complete((struct completion *)data);
2980 }
2981
2982 int r;
2983 DECLARE_COMPLETION_ONSTACK(completion);
2984
2985 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
2986 irqmask);
2987
2988 if (r)
2989 return r;
2990
2991 timeout = wait_for_completion_interruptible_timeout(&completion,
2992 timeout);
2993
2994 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
2995
2996 if (timeout == 0)
2997 return -ETIMEDOUT;
2998
2999 if (timeout == -ERESTARTSYS)
3000 return -ERESTARTSYS;
3001
3002 return 0;
3003}
3004
3005#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
3006void dispc_fake_vsync_irq(void)
3007{
3008 u32 irqstatus = DISPC_IRQ_VSYNC;
3009 int i;
3010
Tomi Valkeinenab83b142010-06-09 15:31:01 +03003011 WARN_ON(!in_interrupt());
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003012
3013 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3014 struct omap_dispc_isr_data *isr_data;
3015 isr_data = &dispc.registered_isr[i];
3016
3017 if (!isr_data->isr)
3018 continue;
3019
3020 if (isr_data->mask & irqstatus)
3021 isr_data->isr(isr_data->arg, irqstatus);
3022 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003023}
3024#endif
3025
3026static void _omap_dispc_initialize_irq(void)
3027{
3028 unsigned long flags;
3029
3030 spin_lock_irqsave(&dispc.irq_lock, flags);
3031
3032 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3033
3034 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
3035
3036 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3037 * so clear it */
3038 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3039
3040 _omap_dispc_set_irqs();
3041
3042 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3043}
3044
3045void dispc_enable_sidle(void)
3046{
3047 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3048}
3049
3050void dispc_disable_sidle(void)
3051{
3052 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3053}
3054
3055static void _omap_dispc_initial_config(void)
3056{
3057 u32 l;
3058
3059 l = dispc_read_reg(DISPC_SYSCONFIG);
3060 l = FLD_MOD(l, 2, 13, 12); /* MIDLEMODE: smart standby */
3061 l = FLD_MOD(l, 2, 4, 3); /* SIDLEMODE: smart idle */
3062 l = FLD_MOD(l, 1, 2, 2); /* ENWAKEUP */
3063 l = FLD_MOD(l, 1, 0, 0); /* AUTOIDLE */
3064 dispc_write_reg(DISPC_SYSCONFIG, l);
3065
3066 /* FUNCGATED */
3067 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3068
3069 /* L3 firewall setting: enable access to OCM RAM */
3070 /* XXX this should be somewhere in plat-omap */
3071 if (cpu_is_omap24xx())
3072 __raw_writel(0x402000b0, OMAP2_L3_IO_ADDRESS(0x680050a0));
3073
3074 _dispc_setup_color_conv_coef();
3075
3076 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3077
3078 dispc_read_plane_fifo_sizes();
3079}
3080
3081int dispc_init(void)
3082{
3083 u32 rev;
3084
3085 spin_lock_init(&dispc.irq_lock);
3086
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003087#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3088 spin_lock_init(&dispc.irq_stats_lock);
3089 dispc.irq_stats.last_reset = jiffies;
3090#endif
3091
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003092 INIT_WORK(&dispc.error_work, dispc_error_worker);
3093
3094 dispc.base = ioremap(DISPC_BASE, DISPC_SZ_REGS);
3095 if (!dispc.base) {
3096 DSSERR("can't ioremap DISPC\n");
3097 return -ENOMEM;
3098 }
3099
3100 enable_clocks(1);
3101
3102 _omap_dispc_initial_config();
3103
3104 _omap_dispc_initialize_irq();
3105
3106 dispc_save_context();
3107
3108 rev = dispc_read_reg(DISPC_REVISION);
3109 printk(KERN_INFO "OMAP DISPC rev %d.%d\n",
3110 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3111
3112 enable_clocks(0);
3113
3114 return 0;
3115}
3116
3117void dispc_exit(void)
3118{
3119 iounmap(dispc.base);
3120}
3121
3122int dispc_enable_plane(enum omap_plane plane, bool enable)
3123{
3124 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
3125
3126 enable_clocks(1);
3127 _dispc_enable_plane(plane, enable);
3128 enable_clocks(0);
3129
3130 return 0;
3131}
3132
3133int dispc_setup_plane(enum omap_plane plane,
3134 u32 paddr, u16 screen_width,
3135 u16 pos_x, u16 pos_y,
3136 u16 width, u16 height,
3137 u16 out_width, u16 out_height,
3138 enum omap_color_mode color_mode,
3139 bool ilace,
3140 enum omap_dss_rotation_type rotation_type,
3141 u8 rotation, bool mirror, u8 global_alpha)
3142{
3143 int r = 0;
3144
3145 DSSDBG("dispc_setup_plane %d, pa %x, sw %d, %d,%d, %dx%d -> "
3146 "%dx%d, ilace %d, cmode %x, rot %d, mir %d\n",
3147 plane, paddr, screen_width, pos_x, pos_y,
3148 width, height,
3149 out_width, out_height,
3150 ilace, color_mode,
3151 rotation, mirror);
3152
3153 enable_clocks(1);
3154
3155 r = _dispc_setup_plane(plane,
3156 paddr, screen_width,
3157 pos_x, pos_y,
3158 width, height,
3159 out_width, out_height,
3160 color_mode, ilace,
3161 rotation_type,
3162 rotation, mirror,
3163 global_alpha);
3164
3165 enable_clocks(0);
3166
3167 return r;
3168}