blob: d6a4b31fa0be9d97dd7fdf387cd5dc891096786b [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 Valkeinen80c39712009-11-12 11:41:42 +020040#include <plat/clock.h>
41
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030042#include <video/omapdss.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020043
44#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053045#include "dss_features.h"
Archit Taneja9b372c22011-05-06 11:45:49 +053046#include "dispc.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020047
48/* DISPC */
Sumit Semwal8613b002010-12-02 11:27:09 +000049#define DISPC_SZ_REGS SZ_4K
Tomi Valkeinen80c39712009-11-12 11:41:42 +020050
Tomi Valkeinen80c39712009-11-12 11:41:42 +020051#define DISPC_IRQ_MASK_ERROR (DISPC_IRQ_GFX_FIFO_UNDERFLOW | \
52 DISPC_IRQ_OCP_ERR | \
53 DISPC_IRQ_VID1_FIFO_UNDERFLOW | \
54 DISPC_IRQ_VID2_FIFO_UNDERFLOW | \
55 DISPC_IRQ_SYNC_LOST | \
56 DISPC_IRQ_SYNC_LOST_DIGIT)
57
58#define DISPC_MAX_NR_ISRS 8
59
60struct omap_dispc_isr_data {
61 omap_dispc_isr_t isr;
62 void *arg;
63 u32 mask;
64};
65
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030066enum omap_burst_size {
67 BURST_SIZE_X2 = 0,
68 BURST_SIZE_X4 = 1,
69 BURST_SIZE_X8 = 2,
70};
71
Tomi Valkeinen80c39712009-11-12 11:41:42 +020072#define REG_GET(idx, start, end) \
73 FLD_GET(dispc_read_reg(idx), start, end)
74
75#define REG_FLD_MOD(idx, val, start, end) \
76 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
77
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +020078struct dispc_irq_stats {
79 unsigned long last_reset;
80 unsigned irq_count;
81 unsigned irqs[32];
82};
83
Tomi Valkeinen80c39712009-11-12 11:41:42 +020084static struct {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +000085 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +020086 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030087
88 int ctx_loss_cnt;
89
archit tanejaaffe3602011-02-23 08:41:03 +000090 int irq;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030091 struct clk *dss_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +020092
Archit Tanejae13a1382011-08-05 19:06:04 +053093 u32 fifo_size[MAX_DSS_OVERLAYS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +020094
95 spinlock_t irq_lock;
96 u32 irq_error_mask;
97 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
98 u32 error_irqs;
99 struct work_struct error_work;
100
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300101 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200102 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200103
104#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
105 spinlock_t irq_stats_lock;
106 struct dispc_irq_stats irq_stats;
107#endif
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200108} dispc;
109
Amber Jain0d66cbb2011-05-19 19:47:54 +0530110enum omap_color_component {
111 /* used for all color formats for OMAP3 and earlier
112 * and for RGB and Y color component on OMAP4
113 */
114 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
115 /* used for UV component for
116 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
117 * color formats on OMAP4
118 */
119 DISPC_COLOR_COMPONENT_UV = 1 << 1,
120};
121
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200122static void _omap_dispc_set_irqs(void);
123
Archit Taneja55978cc2011-05-06 11:45:51 +0530124static inline void dispc_write_reg(const u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200125{
Archit Taneja55978cc2011-05-06 11:45:51 +0530126 __raw_writel(val, dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200127}
128
Archit Taneja55978cc2011-05-06 11:45:51 +0530129static inline u32 dispc_read_reg(const u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200130{
Archit Taneja55978cc2011-05-06 11:45:51 +0530131 return __raw_readl(dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200132}
133
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300134static int dispc_get_ctx_loss_count(void)
135{
136 struct device *dev = &dispc.pdev->dev;
137 struct omap_display_platform_data *pdata = dev->platform_data;
138 struct omap_dss_board_info *board_data = pdata->board_data;
139 int cnt;
140
141 if (!board_data->get_context_loss_count)
142 return -ENOENT;
143
144 cnt = board_data->get_context_loss_count(dev);
145
146 WARN_ONCE(cnt < 0, "get_context_loss_count failed: %d\n", cnt);
147
148 return cnt;
149}
150
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200151#define SR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530152 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200153#define RR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530154 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200155
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300156static void dispc_save_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200157{
Archit Tanejac6104b82011-08-05 19:06:02 +0530158 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200159
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300160 DSSDBG("dispc_save_context\n");
161
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200162 SR(IRQENABLE);
163 SR(CONTROL);
164 SR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200165 SR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530166 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
167 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300168 SR(GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000169 if (dss_has_feature(FEAT_MGR_LCD2)) {
170 SR(CONTROL2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000171 SR(CONFIG2);
172 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200173
Archit Tanejac6104b82011-08-05 19:06:02 +0530174 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
175 SR(DEFAULT_COLOR(i));
176 SR(TRANS_COLOR(i));
177 SR(SIZE_MGR(i));
178 if (i == OMAP_DSS_CHANNEL_DIGIT)
179 continue;
180 SR(TIMING_H(i));
181 SR(TIMING_V(i));
182 SR(POL_FREQ(i));
183 SR(DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200184
Archit Tanejac6104b82011-08-05 19:06:02 +0530185 SR(DATA_CYCLE1(i));
186 SR(DATA_CYCLE2(i));
187 SR(DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200188
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300189 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530190 SR(CPR_COEF_R(i));
191 SR(CPR_COEF_G(i));
192 SR(CPR_COEF_B(i));
193 }
194 }
195
196 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
197 SR(OVL_BA0(i));
198 SR(OVL_BA1(i));
199 SR(OVL_POSITION(i));
200 SR(OVL_SIZE(i));
201 SR(OVL_ATTRIBUTES(i));
202 SR(OVL_FIFO_THRESHOLD(i));
203 SR(OVL_ROW_INC(i));
204 SR(OVL_PIXEL_INC(i));
205 if (dss_has_feature(FEAT_PRELOAD))
206 SR(OVL_PRELOAD(i));
207 if (i == OMAP_DSS_GFX) {
208 SR(OVL_WINDOW_SKIP(i));
209 SR(OVL_TABLE_BA(i));
210 continue;
211 }
212 SR(OVL_FIR(i));
213 SR(OVL_PICTURE_SIZE(i));
214 SR(OVL_ACCU0(i));
215 SR(OVL_ACCU1(i));
216
217 for (j = 0; j < 8; j++)
218 SR(OVL_FIR_COEF_H(i, j));
219
220 for (j = 0; j < 8; j++)
221 SR(OVL_FIR_COEF_HV(i, j));
222
223 for (j = 0; j < 5; j++)
224 SR(OVL_CONV_COEF(i, j));
225
226 if (dss_has_feature(FEAT_FIR_COEF_V)) {
227 for (j = 0; j < 8; j++)
228 SR(OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300229 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000230
Archit Tanejac6104b82011-08-05 19:06:02 +0530231 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
232 SR(OVL_BA0_UV(i));
233 SR(OVL_BA1_UV(i));
234 SR(OVL_FIR2(i));
235 SR(OVL_ACCU2_0(i));
236 SR(OVL_ACCU2_1(i));
237
238 for (j = 0; j < 8; j++)
239 SR(OVL_FIR_COEF_H2(i, j));
240
241 for (j = 0; j < 8; j++)
242 SR(OVL_FIR_COEF_HV2(i, j));
243
244 for (j = 0; j < 8; j++)
245 SR(OVL_FIR_COEF_V2(i, j));
246 }
247 if (dss_has_feature(FEAT_ATTR2))
248 SR(OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000249 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200250
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600251 if (dss_has_feature(FEAT_CORE_CLK_DIV))
252 SR(DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300253
254 dispc.ctx_loss_cnt = dispc_get_ctx_loss_count();
255 dispc.ctx_valid = true;
256
257 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200258}
259
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300260static void dispc_restore_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200261{
Archit Tanejac6104b82011-08-05 19:06:02 +0530262 int i, j, ctx;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300263
264 DSSDBG("dispc_restore_context\n");
265
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300266 if (!dispc.ctx_valid)
267 return;
268
269 ctx = dispc_get_ctx_loss_count();
270
271 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
272 return;
273
274 DSSDBG("ctx_loss_count: saved %d, current %d\n",
275 dispc.ctx_loss_cnt, ctx);
276
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200277 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200278 /*RR(CONTROL);*/
279 RR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200280 RR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530281 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
282 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300283 RR(GLOBAL_ALPHA);
Archit Tanejac6104b82011-08-05 19:06:02 +0530284 if (dss_has_feature(FEAT_MGR_LCD2))
Sumit Semwal2a205f32010-12-02 11:27:12 +0000285 RR(CONFIG2);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200286
Archit Tanejac6104b82011-08-05 19:06:02 +0530287 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
288 RR(DEFAULT_COLOR(i));
289 RR(TRANS_COLOR(i));
290 RR(SIZE_MGR(i));
291 if (i == OMAP_DSS_CHANNEL_DIGIT)
292 continue;
293 RR(TIMING_H(i));
294 RR(TIMING_V(i));
295 RR(POL_FREQ(i));
296 RR(DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530297
Archit Tanejac6104b82011-08-05 19:06:02 +0530298 RR(DATA_CYCLE1(i));
299 RR(DATA_CYCLE2(i));
300 RR(DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000301
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300302 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530303 RR(CPR_COEF_R(i));
304 RR(CPR_COEF_G(i));
305 RR(CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300306 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000307 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200308
Archit Tanejac6104b82011-08-05 19:06:02 +0530309 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
310 RR(OVL_BA0(i));
311 RR(OVL_BA1(i));
312 RR(OVL_POSITION(i));
313 RR(OVL_SIZE(i));
314 RR(OVL_ATTRIBUTES(i));
315 RR(OVL_FIFO_THRESHOLD(i));
316 RR(OVL_ROW_INC(i));
317 RR(OVL_PIXEL_INC(i));
318 if (dss_has_feature(FEAT_PRELOAD))
319 RR(OVL_PRELOAD(i));
320 if (i == OMAP_DSS_GFX) {
321 RR(OVL_WINDOW_SKIP(i));
322 RR(OVL_TABLE_BA(i));
323 continue;
324 }
325 RR(OVL_FIR(i));
326 RR(OVL_PICTURE_SIZE(i));
327 RR(OVL_ACCU0(i));
328 RR(OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200329
Archit Tanejac6104b82011-08-05 19:06:02 +0530330 for (j = 0; j < 8; j++)
331 RR(OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200332
Archit Tanejac6104b82011-08-05 19:06:02 +0530333 for (j = 0; j < 8; j++)
334 RR(OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200335
Archit Tanejac6104b82011-08-05 19:06:02 +0530336 for (j = 0; j < 5; j++)
337 RR(OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200338
Archit Tanejac6104b82011-08-05 19:06:02 +0530339 if (dss_has_feature(FEAT_FIR_COEF_V)) {
340 for (j = 0; j < 8; j++)
341 RR(OVL_FIR_COEF_V(i, j));
342 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200343
Archit Tanejac6104b82011-08-05 19:06:02 +0530344 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
345 RR(OVL_BA0_UV(i));
346 RR(OVL_BA1_UV(i));
347 RR(OVL_FIR2(i));
348 RR(OVL_ACCU2_0(i));
349 RR(OVL_ACCU2_1(i));
350
351 for (j = 0; j < 8; j++)
352 RR(OVL_FIR_COEF_H2(i, j));
353
354 for (j = 0; j < 8; j++)
355 RR(OVL_FIR_COEF_HV2(i, j));
356
357 for (j = 0; j < 8; j++)
358 RR(OVL_FIR_COEF_V2(i, j));
359 }
360 if (dss_has_feature(FEAT_ATTR2))
361 RR(OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300362 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200363
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600364 if (dss_has_feature(FEAT_CORE_CLK_DIV))
365 RR(DIVISOR);
366
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200367 /* enable last, because LCD & DIGIT enable are here */
368 RR(CONTROL);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000369 if (dss_has_feature(FEAT_MGR_LCD2))
370 RR(CONTROL2);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200371 /* clear spurious SYNC_LOST_DIGIT interrupts */
372 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
373
374 /*
375 * enable last so IRQs won't trigger before
376 * the context is fully restored
377 */
378 RR(IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300379
380 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200381}
382
383#undef SR
384#undef RR
385
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300386int dispc_runtime_get(void)
387{
388 int r;
389
390 DSSDBG("dispc_runtime_get\n");
391
392 r = pm_runtime_get_sync(&dispc.pdev->dev);
393 WARN_ON(r < 0);
394 return r < 0 ? r : 0;
395}
396
397void dispc_runtime_put(void)
398{
399 int r;
400
401 DSSDBG("dispc_runtime_put\n");
402
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200403 r = pm_runtime_put_sync(&dispc.pdev->dev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300404 WARN_ON(r < 0);
405}
406
Archit Tanejadac57a02011-09-08 12:30:19 +0530407static inline bool dispc_mgr_is_lcd(enum omap_channel channel)
408{
409 if (channel == OMAP_DSS_CHANNEL_LCD ||
410 channel == OMAP_DSS_CHANNEL_LCD2)
411 return true;
412 else
413 return false;
414}
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300415
Archit Tanejac3dc6a72011-09-13 18:28:41 +0530416static struct omap_dss_device *dispc_mgr_get_device(enum omap_channel channel)
417{
418 struct omap_overlay_manager *mgr =
419 omap_dss_get_overlay_manager(channel);
420
421 return mgr ? mgr->device : NULL;
422}
423
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200424u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
425{
426 switch (channel) {
427 case OMAP_DSS_CHANNEL_LCD:
428 return DISPC_IRQ_VSYNC;
429 case OMAP_DSS_CHANNEL_LCD2:
430 return DISPC_IRQ_VSYNC2;
431 case OMAP_DSS_CHANNEL_DIGIT:
432 return DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
433 default:
434 BUG();
435 }
436}
437
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200438u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
439{
440 switch (channel) {
441 case OMAP_DSS_CHANNEL_LCD:
442 return DISPC_IRQ_FRAMEDONE;
443 case OMAP_DSS_CHANNEL_LCD2:
444 return DISPC_IRQ_FRAMEDONE2;
445 case OMAP_DSS_CHANNEL_DIGIT:
446 return 0;
447 default:
448 BUG();
449 }
450}
451
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300452bool dispc_mgr_go_busy(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200453{
454 int bit;
455
Archit Tanejadac57a02011-09-08 12:30:19 +0530456 if (dispc_mgr_is_lcd(channel))
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200457 bit = 5; /* GOLCD */
458 else
459 bit = 6; /* GODIGIT */
460
Sumit Semwal2a205f32010-12-02 11:27:12 +0000461 if (channel == OMAP_DSS_CHANNEL_LCD2)
462 return REG_GET(DISPC_CONTROL2, bit, bit) == 1;
463 else
464 return REG_GET(DISPC_CONTROL, bit, bit) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200465}
466
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300467void dispc_mgr_go(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200468{
469 int bit;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000470 bool enable_bit, go_bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200471
Archit Tanejadac57a02011-09-08 12:30:19 +0530472 if (dispc_mgr_is_lcd(channel))
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200473 bit = 0; /* LCDENABLE */
474 else
475 bit = 1; /* DIGITALENABLE */
476
477 /* if the channel is not enabled, we don't need GO */
Sumit Semwal2a205f32010-12-02 11:27:12 +0000478 if (channel == OMAP_DSS_CHANNEL_LCD2)
479 enable_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
480 else
481 enable_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
482
483 if (!enable_bit)
Tomi Valkeinene6d80f92011-05-19 14:12:26 +0300484 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200485
Archit Tanejadac57a02011-09-08 12:30:19 +0530486 if (dispc_mgr_is_lcd(channel))
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200487 bit = 5; /* GOLCD */
488 else
489 bit = 6; /* GODIGIT */
490
Sumit Semwal2a205f32010-12-02 11:27:12 +0000491 if (channel == OMAP_DSS_CHANNEL_LCD2)
492 go_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
493 else
494 go_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
495
496 if (go_bit) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200497 DSSERR("GO bit not down for channel %d\n", channel);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +0300498 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200499 }
500
Sumit Semwal2a205f32010-12-02 11:27:12 +0000501 DSSDBG("GO %s\n", channel == OMAP_DSS_CHANNEL_LCD ? "LCD" :
502 (channel == OMAP_DSS_CHANNEL_LCD2 ? "LCD2" : "DIGIT"));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200503
Sumit Semwal2a205f32010-12-02 11:27:12 +0000504 if (channel == OMAP_DSS_CHANNEL_LCD2)
505 REG_FLD_MOD(DISPC_CONTROL2, 1, bit, bit);
506 else
507 REG_FLD_MOD(DISPC_CONTROL, 1, bit, bit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200508}
509
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300510static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200511{
Archit Taneja9b372c22011-05-06 11:45:49 +0530512 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200513}
514
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300515static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200516{
Archit Taneja9b372c22011-05-06 11:45:49 +0530517 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200518}
519
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300520static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200521{
Archit Taneja9b372c22011-05-06 11:45:49 +0530522 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200523}
524
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300525static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530526{
527 BUG_ON(plane == OMAP_DSS_GFX);
528
529 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
530}
531
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300532static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
533 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530534{
535 BUG_ON(plane == OMAP_DSS_GFX);
536
537 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
538}
539
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300540static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530541{
542 BUG_ON(plane == OMAP_DSS_GFX);
543
544 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
545}
546
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530547static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
548 int fir_vinc, int five_taps,
549 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200550{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530551 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200552 int i;
553
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530554 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
555 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200556
557 for (i = 0; i < 8; i++) {
558 u32 h, hv;
559
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530560 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
561 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
562 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
563 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
564 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
565 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
566 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
567 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200568
Amber Jain0d66cbb2011-05-19 19:47:54 +0530569 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300570 dispc_ovl_write_firh_reg(plane, i, h);
571 dispc_ovl_write_firhv_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530572 } else {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300573 dispc_ovl_write_firh2_reg(plane, i, h);
574 dispc_ovl_write_firhv2_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530575 }
576
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200577 }
578
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200579 if (five_taps) {
580 for (i = 0; i < 8; i++) {
581 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530582 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
583 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530584 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300585 dispc_ovl_write_firv_reg(plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530586 else
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300587 dispc_ovl_write_firv2_reg(plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200588 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200589 }
590}
591
592static void _dispc_setup_color_conv_coef(void)
593{
Archit Tanejaac01c292011-08-05 19:06:03 +0530594 int i;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200595 const struct color_conv_coef {
596 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
597 int full_range;
598 } ctbl_bt601_5 = {
599 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
600 };
601
602 const struct color_conv_coef *ct;
603
604#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
605
606 ct = &ctbl_bt601_5;
607
Archit Tanejaac01c292011-08-05 19:06:03 +0530608 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
609 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 0),
610 CVAL(ct->rcr, ct->ry));
611 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 1),
612 CVAL(ct->gy, ct->rcb));
613 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 2),
614 CVAL(ct->gcb, ct->gcr));
615 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 3),
616 CVAL(ct->bcr, ct->by));
617 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 4),
618 CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200619
Archit Tanejaac01c292011-08-05 19:06:03 +0530620 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), ct->full_range,
621 11, 11);
622 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200623
624#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200625}
626
627
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300628static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200629{
Archit Taneja9b372c22011-05-06 11:45:49 +0530630 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200631}
632
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300633static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200634{
Archit Taneja9b372c22011-05-06 11:45:49 +0530635 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200636}
637
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300638static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530639{
640 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
641}
642
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300643static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530644{
645 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
646}
647
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300648static void dispc_ovl_set_pos(enum omap_plane plane, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200649{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200650 u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530651
652 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200653}
654
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300655static void dispc_ovl_set_pic_size(enum omap_plane plane, int width, int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200656{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200657 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530658
659 if (plane == OMAP_DSS_GFX)
660 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
661 else
662 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200663}
664
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300665static void dispc_ovl_set_vid_size(enum omap_plane plane, int width, int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200666{
667 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200668
669 BUG_ON(plane == OMAP_DSS_GFX);
670
671 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530672
673 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200674}
675
Archit Taneja54128702011-09-08 11:29:17 +0530676static void dispc_ovl_set_zorder(enum omap_plane plane, u8 zorder)
677{
678 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
679
680 if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
681 return;
682
683 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
684}
685
686static void dispc_ovl_enable_zorder_planes(void)
687{
688 int i;
689
690 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
691 return;
692
693 for (i = 0; i < dss_feat_get_num_ovls(); i++)
694 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
695}
696
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300697static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane, bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100698{
Tomi Valkeinenf6dc8152011-08-15 15:18:20 +0300699 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100700
Tomi Valkeinenf6dc8152011-08-15 15:18:20 +0300701 if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100702 return;
703
Archit Taneja9b372c22011-05-06 11:45:49 +0530704 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100705}
706
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300707static void dispc_ovl_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200708{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530709 static const unsigned shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300710 int shift;
Tomi Valkeinenf6dc8152011-08-15 15:18:20 +0300711 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300712
Tomi Valkeinenf6dc8152011-08-15 15:18:20 +0300713 if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100714 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530715
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300716 shift = shifts[plane];
717 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200718}
719
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300720static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200721{
Archit Taneja9b372c22011-05-06 11:45:49 +0530722 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200723}
724
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300725static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200726{
Archit Taneja9b372c22011-05-06 11:45:49 +0530727 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200728}
729
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300730static void dispc_ovl_set_color_mode(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200731 enum omap_color_mode color_mode)
732{
733 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +0530734 if (plane != OMAP_DSS_GFX) {
735 switch (color_mode) {
736 case OMAP_DSS_COLOR_NV12:
737 m = 0x0; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530738 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530739 m = 0x1; break;
740 case OMAP_DSS_COLOR_RGBA16:
741 m = 0x2; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530742 case OMAP_DSS_COLOR_RGB12U:
Amber Jainf20e4222011-05-19 19:47:50 +0530743 m = 0x4; break;
744 case OMAP_DSS_COLOR_ARGB16:
745 m = 0x5; break;
746 case OMAP_DSS_COLOR_RGB16:
747 m = 0x6; break;
748 case OMAP_DSS_COLOR_ARGB16_1555:
749 m = 0x7; break;
750 case OMAP_DSS_COLOR_RGB24U:
751 m = 0x8; break;
752 case OMAP_DSS_COLOR_RGB24P:
753 m = 0x9; break;
754 case OMAP_DSS_COLOR_YUV2:
755 m = 0xa; break;
756 case OMAP_DSS_COLOR_UYVY:
757 m = 0xb; break;
758 case OMAP_DSS_COLOR_ARGB32:
759 m = 0xc; break;
760 case OMAP_DSS_COLOR_RGBA32:
761 m = 0xd; break;
762 case OMAP_DSS_COLOR_RGBX32:
763 m = 0xe; break;
764 case OMAP_DSS_COLOR_XRGB16_1555:
765 m = 0xf; break;
766 default:
767 BUG(); break;
768 }
769 } else {
770 switch (color_mode) {
771 case OMAP_DSS_COLOR_CLUT1:
772 m = 0x0; break;
773 case OMAP_DSS_COLOR_CLUT2:
774 m = 0x1; break;
775 case OMAP_DSS_COLOR_CLUT4:
776 m = 0x2; break;
777 case OMAP_DSS_COLOR_CLUT8:
778 m = 0x3; break;
779 case OMAP_DSS_COLOR_RGB12U:
780 m = 0x4; break;
781 case OMAP_DSS_COLOR_ARGB16:
782 m = 0x5; break;
783 case OMAP_DSS_COLOR_RGB16:
784 m = 0x6; break;
785 case OMAP_DSS_COLOR_ARGB16_1555:
786 m = 0x7; break;
787 case OMAP_DSS_COLOR_RGB24U:
788 m = 0x8; break;
789 case OMAP_DSS_COLOR_RGB24P:
790 m = 0x9; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530791 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530792 m = 0xa; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530793 case OMAP_DSS_COLOR_RGBA16:
Amber Jainf20e4222011-05-19 19:47:50 +0530794 m = 0xb; break;
795 case OMAP_DSS_COLOR_ARGB32:
796 m = 0xc; break;
797 case OMAP_DSS_COLOR_RGBA32:
798 m = 0xd; break;
799 case OMAP_DSS_COLOR_RGBX32:
800 m = 0xe; break;
801 case OMAP_DSS_COLOR_XRGB16_1555:
802 m = 0xf; break;
803 default:
804 BUG(); break;
805 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200806 }
807
Archit Taneja9b372c22011-05-06 11:45:49 +0530808 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200809}
810
Tomi Valkeinenf4279842011-10-28 15:26:26 +0300811void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200812{
813 int shift;
814 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000815 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200816
817 switch (plane) {
818 case OMAP_DSS_GFX:
819 shift = 8;
820 break;
821 case OMAP_DSS_VIDEO1:
822 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +0530823 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200824 shift = 16;
825 break;
826 default:
827 BUG();
828 return;
829 }
830
Archit Taneja9b372c22011-05-06 11:45:49 +0530831 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000832 if (dss_has_feature(FEAT_MGR_LCD2)) {
833 switch (channel) {
834 case OMAP_DSS_CHANNEL_LCD:
835 chan = 0;
836 chan2 = 0;
837 break;
838 case OMAP_DSS_CHANNEL_DIGIT:
839 chan = 1;
840 chan2 = 0;
841 break;
842 case OMAP_DSS_CHANNEL_LCD2:
843 chan = 0;
844 chan2 = 1;
845 break;
846 default:
847 BUG();
848 }
849
850 val = FLD_MOD(val, chan, shift, shift);
851 val = FLD_MOD(val, chan2, 31, 30);
852 } else {
853 val = FLD_MOD(val, channel, shift, shift);
854 }
Archit Taneja9b372c22011-05-06 11:45:49 +0530855 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200856}
857
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200858static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
859{
860 int shift;
861 u32 val;
862 enum omap_channel channel;
863
864 switch (plane) {
865 case OMAP_DSS_GFX:
866 shift = 8;
867 break;
868 case OMAP_DSS_VIDEO1:
869 case OMAP_DSS_VIDEO2:
870 case OMAP_DSS_VIDEO3:
871 shift = 16;
872 break;
873 default:
874 BUG();
875 }
876
877 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
878
879 if (dss_has_feature(FEAT_MGR_LCD2)) {
880 if (FLD_GET(val, 31, 30) == 0)
881 channel = FLD_GET(val, shift, shift);
882 else
883 channel = OMAP_DSS_CHANNEL_LCD2;
884 } else {
885 channel = FLD_GET(val, shift, shift);
886 }
887
888 return channel;
889}
890
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300891static void dispc_ovl_set_burst_size(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200892 enum omap_burst_size burst_size)
893{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530894 static const unsigned shifts[] = { 6, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200895 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200896
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300897 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +0300898 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200899}
900
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +0300901static void dispc_configure_burst_sizes(void)
902{
903 int i;
904 const int burst_size = BURST_SIZE_X8;
905
906 /* Configure burst size always to maximum size */
907 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300908 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +0300909}
910
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +0200911static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +0300912{
913 unsigned unit = dss_feat_get_burst_size_unit();
914 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
915 return unit * 8;
916}
917
Mythri P Kd3862612011-03-11 18:02:49 +0530918void dispc_enable_gamma_table(bool enable)
919{
920 /*
921 * This is partially implemented to support only disabling of
922 * the gamma table.
923 */
924 if (enable) {
925 DSSWARN("Gamma table enabling for TV not yet supported");
926 return;
927 }
928
929 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
930}
931
Tomi Valkeinenc64dca42011-11-04 18:14:20 +0200932static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +0300933{
934 u16 reg;
935
936 if (channel == OMAP_DSS_CHANNEL_LCD)
937 reg = DISPC_CONFIG;
938 else if (channel == OMAP_DSS_CHANNEL_LCD2)
939 reg = DISPC_CONFIG2;
940 else
941 return;
942
943 REG_FLD_MOD(reg, enable, 15, 15);
944}
945
Tomi Valkeinenc64dca42011-11-04 18:14:20 +0200946static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +0300947 struct omap_dss_cpr_coefs *coefs)
948{
949 u32 coef_r, coef_g, coef_b;
950
Archit Tanejadac57a02011-09-08 12:30:19 +0530951 if (!dispc_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +0300952 return;
953
954 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
955 FLD_VAL(coefs->rb, 9, 0);
956 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
957 FLD_VAL(coefs->gb, 9, 0);
958 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
959 FLD_VAL(coefs->bb, 9, 0);
960
961 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
962 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
963 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
964}
965
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300966static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200967{
968 u32 val;
969
970 BUG_ON(plane == OMAP_DSS_GFX);
971
Archit Taneja9b372c22011-05-06 11:45:49 +0530972 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200973 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +0530974 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200975}
976
Archit Tanejac3d925292011-09-14 11:52:54 +0530977static void dispc_ovl_enable_replication(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200978{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530979 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300980 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200981
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300982 shift = shifts[plane];
983 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200984}
985
Archit Tanejae5c09e02012-04-16 12:53:42 +0530986static void dispc_mgr_set_lcd_size(enum omap_channel channel, u16 width,
987 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200988{
989 u32 val;
990 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
991 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja702d1442011-05-06 11:45:50 +0530992 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200993}
994
Archit Tanejac51d9212012-04-16 12:53:43 +0530995static void dispc_mgr_set_digit_size(u16 width, u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200996{
997 u32 val;
998 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
999 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja702d1442011-05-06 11:45:50 +05301000 dispc_write_reg(DISPC_SIZE_MGR(OMAP_DSS_CHANNEL_DIGIT), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001001}
1002
1003static void dispc_read_plane_fifo_sizes(void)
1004{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001005 u32 size;
1006 int plane;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301007 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001008 u32 unit;
1009
1010 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001011
Archit Tanejaa0acb552010-09-15 19:20:00 +05301012 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001013
Archit Tanejae13a1382011-08-05 19:06:04 +05301014 for (plane = 0; plane < dss_feat_get_num_ovls(); ++plane) {
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001015 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(plane), start, end);
1016 size *= unit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001017 dispc.fifo_size[plane] = size;
1018 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001019}
1020
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001021static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001022{
1023 return dispc.fifo_size[plane];
1024}
1025
Tomi Valkeinen6f04e1b2011-10-31 08:58:52 +02001026void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001027{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301028 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001029 u32 unit;
1030
1031 unit = dss_feat_get_buffer_size_unit();
1032
1033 WARN_ON(low % unit != 0);
1034 WARN_ON(high % unit != 0);
1035
1036 low /= unit;
1037 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301038
Archit Taneja9b372c22011-05-06 11:45:49 +05301039 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1040 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1041
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001042 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001043 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301044 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001045 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301046 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001047 hi_start, hi_end) * unit,
1048 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001049
Archit Taneja9b372c22011-05-06 11:45:49 +05301050 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301051 FLD_VAL(high, hi_start, hi_end) |
1052 FLD_VAL(low, lo_start, lo_end));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001053}
1054
1055void dispc_enable_fifomerge(bool enable)
1056{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001057 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1058 WARN_ON(enable);
1059 return;
1060 }
1061
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001062 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1063 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001064}
1065
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001066void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1067 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge)
1068{
1069 /*
1070 * All sizes are in bytes. Both the buffer and burst are made of
1071 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1072 */
1073
1074 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001075 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1076 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001077
1078 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001079 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001080
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001081 if (use_fifomerge) {
1082 total_fifo_size = 0;
1083 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
1084 total_fifo_size += dispc_ovl_get_fifo_size(i);
1085 } else {
1086 total_fifo_size = ovl_fifo_size;
1087 }
1088
1089 /*
1090 * We use the same low threshold for both fifomerge and non-fifomerge
1091 * cases, but for fifomerge we calculate the high threshold using the
1092 * combined fifo size
1093 */
1094
1095 if (dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1096 *fifo_low = ovl_fifo_size - burst_size * 2;
1097 *fifo_high = total_fifo_size - burst_size;
1098 } else {
1099 *fifo_low = ovl_fifo_size - burst_size;
1100 *fifo_high = total_fifo_size - buf_unit;
1101 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001102}
1103
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001104static void dispc_ovl_set_fir(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301105 int hinc, int vinc,
1106 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001107{
1108 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001109
Amber Jain0d66cbb2011-05-19 19:47:54 +05301110 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1111 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301112
Amber Jain0d66cbb2011-05-19 19:47:54 +05301113 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1114 &hinc_start, &hinc_end);
1115 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1116 &vinc_start, &vinc_end);
1117 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1118 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301119
Amber Jain0d66cbb2011-05-19 19:47:54 +05301120 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1121 } else {
1122 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1123 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1124 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001125}
1126
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001127static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001128{
1129 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301130 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001131
Archit Taneja87a74842011-03-02 11:19:50 +05301132 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1133 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1134
1135 val = FLD_VAL(vaccu, vert_start, vert_end) |
1136 FLD_VAL(haccu, hor_start, hor_end);
1137
Archit Taneja9b372c22011-05-06 11:45:49 +05301138 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001139}
1140
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001141static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001142{
1143 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301144 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001145
Archit Taneja87a74842011-03-02 11:19:50 +05301146 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1147 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1148
1149 val = FLD_VAL(vaccu, vert_start, vert_end) |
1150 FLD_VAL(haccu, hor_start, hor_end);
1151
Archit Taneja9b372c22011-05-06 11:45:49 +05301152 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001153}
1154
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001155static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1156 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301157{
1158 u32 val;
1159
1160 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1161 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1162}
1163
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001164static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1165 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301166{
1167 u32 val;
1168
1169 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1170 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1171}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001172
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001173static void dispc_ovl_set_scale_param(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001174 u16 orig_width, u16 orig_height,
1175 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301176 bool five_taps, u8 rotation,
1177 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001178{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301179 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001180
Amber Jained14a3c2011-05-19 19:47:51 +05301181 fir_hinc = 1024 * orig_width / out_width;
1182 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001183
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301184 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1185 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001186 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301187}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001188
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001189static void dispc_ovl_set_scaling_common(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301190 u16 orig_width, u16 orig_height,
1191 u16 out_width, u16 out_height,
1192 bool ilace, bool five_taps,
1193 bool fieldmode, enum omap_color_mode color_mode,
1194 u8 rotation)
1195{
1196 int accu0 = 0;
1197 int accu1 = 0;
1198 u32 l;
1199
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001200 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301201 out_width, out_height, five_taps,
1202 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301203 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001204
Archit Taneja87a74842011-03-02 11:19:50 +05301205 /* RESIZEENABLE and VERTICALTAPS */
1206 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301207 l |= (orig_width != out_width) ? (1 << 5) : 0;
1208 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001209 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301210
1211 /* VRESIZECONF and HRESIZECONF */
1212 if (dss_has_feature(FEAT_RESIZECONF)) {
1213 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301214 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1215 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301216 }
1217
1218 /* LINEBUFFERSPLIT */
1219 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1220 l &= ~(0x1 << 22);
1221 l |= five_taps ? (1 << 22) : 0;
1222 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001223
Archit Taneja9b372c22011-05-06 11:45:49 +05301224 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001225
1226 /*
1227 * field 0 = even field = bottom field
1228 * field 1 = odd field = top field
1229 */
1230 if (ilace && !fieldmode) {
1231 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301232 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001233 if (accu0 >= 1024/2) {
1234 accu1 = 1024/2;
1235 accu0 -= accu1;
1236 }
1237 }
1238
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001239 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1240 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001241}
1242
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001243static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301244 u16 orig_width, u16 orig_height,
1245 u16 out_width, u16 out_height,
1246 bool ilace, bool five_taps,
1247 bool fieldmode, enum omap_color_mode color_mode,
1248 u8 rotation)
1249{
1250 int scale_x = out_width != orig_width;
1251 int scale_y = out_height != orig_height;
1252
1253 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1254 return;
1255 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1256 color_mode != OMAP_DSS_COLOR_UYVY &&
1257 color_mode != OMAP_DSS_COLOR_NV12)) {
1258 /* reset chroma resampling for RGB formats */
1259 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1260 return;
1261 }
1262 switch (color_mode) {
1263 case OMAP_DSS_COLOR_NV12:
1264 /* UV is subsampled by 2 vertically*/
1265 orig_height >>= 1;
1266 /* UV is subsampled by 2 horz.*/
1267 orig_width >>= 1;
1268 break;
1269 case OMAP_DSS_COLOR_YUV2:
1270 case OMAP_DSS_COLOR_UYVY:
1271 /*For YUV422 with 90/270 rotation,
1272 *we don't upsample chroma
1273 */
1274 if (rotation == OMAP_DSS_ROT_0 ||
1275 rotation == OMAP_DSS_ROT_180)
1276 /* UV is subsampled by 2 hrz*/
1277 orig_width >>= 1;
1278 /* must use FIR for YUV422 if rotated */
1279 if (rotation != OMAP_DSS_ROT_0)
1280 scale_x = scale_y = true;
1281 break;
1282 default:
1283 BUG();
1284 }
1285
1286 if (out_width != orig_width)
1287 scale_x = true;
1288 if (out_height != orig_height)
1289 scale_y = true;
1290
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001291 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301292 out_width, out_height, five_taps,
1293 rotation, DISPC_COLOR_COMPONENT_UV);
1294
1295 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1296 (scale_x || scale_y) ? 1 : 0, 8, 8);
1297 /* set H scaling */
1298 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1299 /* set V scaling */
1300 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1301
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001302 dispc_ovl_set_vid_accu2_0(plane, 0x80, 0);
1303 dispc_ovl_set_vid_accu2_1(plane, 0x80, 0);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301304}
1305
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001306static void dispc_ovl_set_scaling(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301307 u16 orig_width, u16 orig_height,
1308 u16 out_width, u16 out_height,
1309 bool ilace, bool five_taps,
1310 bool fieldmode, enum omap_color_mode color_mode,
1311 u8 rotation)
1312{
1313 BUG_ON(plane == OMAP_DSS_GFX);
1314
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001315 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301316 orig_width, orig_height,
1317 out_width, out_height,
1318 ilace, five_taps,
1319 fieldmode, color_mode,
1320 rotation);
1321
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001322 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301323 orig_width, orig_height,
1324 out_width, out_height,
1325 ilace, five_taps,
1326 fieldmode, color_mode,
1327 rotation);
1328}
1329
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001330static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001331 bool mirroring, enum omap_color_mode color_mode)
1332{
Archit Taneja87a74842011-03-02 11:19:50 +05301333 bool row_repeat = false;
1334 int vidrot = 0;
1335
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001336 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1337 color_mode == OMAP_DSS_COLOR_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001338
1339 if (mirroring) {
1340 switch (rotation) {
1341 case OMAP_DSS_ROT_0:
1342 vidrot = 2;
1343 break;
1344 case OMAP_DSS_ROT_90:
1345 vidrot = 1;
1346 break;
1347 case OMAP_DSS_ROT_180:
1348 vidrot = 0;
1349 break;
1350 case OMAP_DSS_ROT_270:
1351 vidrot = 3;
1352 break;
1353 }
1354 } else {
1355 switch (rotation) {
1356 case OMAP_DSS_ROT_0:
1357 vidrot = 0;
1358 break;
1359 case OMAP_DSS_ROT_90:
1360 vidrot = 1;
1361 break;
1362 case OMAP_DSS_ROT_180:
1363 vidrot = 2;
1364 break;
1365 case OMAP_DSS_ROT_270:
1366 vidrot = 3;
1367 break;
1368 }
1369 }
1370
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001371 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
Archit Taneja87a74842011-03-02 11:19:50 +05301372 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001373 else
Archit Taneja87a74842011-03-02 11:19:50 +05301374 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001375 }
Archit Taneja87a74842011-03-02 11:19:50 +05301376
Archit Taneja9b372c22011-05-06 11:45:49 +05301377 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301378 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301379 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1380 row_repeat ? 1 : 0, 18, 18);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001381}
1382
1383static int color_mode_to_bpp(enum omap_color_mode color_mode)
1384{
1385 switch (color_mode) {
1386 case OMAP_DSS_COLOR_CLUT1:
1387 return 1;
1388 case OMAP_DSS_COLOR_CLUT2:
1389 return 2;
1390 case OMAP_DSS_COLOR_CLUT4:
1391 return 4;
1392 case OMAP_DSS_COLOR_CLUT8:
Amber Jainf20e4222011-05-19 19:47:50 +05301393 case OMAP_DSS_COLOR_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001394 return 8;
1395 case OMAP_DSS_COLOR_RGB12U:
1396 case OMAP_DSS_COLOR_RGB16:
1397 case OMAP_DSS_COLOR_ARGB16:
1398 case OMAP_DSS_COLOR_YUV2:
1399 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301400 case OMAP_DSS_COLOR_RGBA16:
1401 case OMAP_DSS_COLOR_RGBX16:
1402 case OMAP_DSS_COLOR_ARGB16_1555:
1403 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001404 return 16;
1405 case OMAP_DSS_COLOR_RGB24P:
1406 return 24;
1407 case OMAP_DSS_COLOR_RGB24U:
1408 case OMAP_DSS_COLOR_ARGB32:
1409 case OMAP_DSS_COLOR_RGBA32:
1410 case OMAP_DSS_COLOR_RGBX32:
1411 return 32;
1412 default:
1413 BUG();
1414 }
1415}
1416
1417static s32 pixinc(int pixels, u8 ps)
1418{
1419 if (pixels == 1)
1420 return 1;
1421 else if (pixels > 1)
1422 return 1 + (pixels - 1) * ps;
1423 else if (pixels < 0)
1424 return 1 - (-pixels + 1) * ps;
1425 else
1426 BUG();
1427}
1428
1429static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1430 u16 screen_width,
1431 u16 width, u16 height,
1432 enum omap_color_mode color_mode, bool fieldmode,
1433 unsigned int field_offset,
1434 unsigned *offset0, unsigned *offset1,
1435 s32 *row_inc, s32 *pix_inc)
1436{
1437 u8 ps;
1438
1439 /* FIXME CLUT formats */
1440 switch (color_mode) {
1441 case OMAP_DSS_COLOR_CLUT1:
1442 case OMAP_DSS_COLOR_CLUT2:
1443 case OMAP_DSS_COLOR_CLUT4:
1444 case OMAP_DSS_COLOR_CLUT8:
1445 BUG();
1446 return;
1447 case OMAP_DSS_COLOR_YUV2:
1448 case OMAP_DSS_COLOR_UYVY:
1449 ps = 4;
1450 break;
1451 default:
1452 ps = color_mode_to_bpp(color_mode) / 8;
1453 break;
1454 }
1455
1456 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1457 width, height);
1458
1459 /*
1460 * field 0 = even field = bottom field
1461 * field 1 = odd field = top field
1462 */
1463 switch (rotation + mirror * 4) {
1464 case OMAP_DSS_ROT_0:
1465 case OMAP_DSS_ROT_180:
1466 /*
1467 * If the pixel format is YUV or UYVY divide the width
1468 * of the image by 2 for 0 and 180 degree rotation.
1469 */
1470 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1471 color_mode == OMAP_DSS_COLOR_UYVY)
1472 width = width >> 1;
1473 case OMAP_DSS_ROT_90:
1474 case OMAP_DSS_ROT_270:
1475 *offset1 = 0;
1476 if (field_offset)
1477 *offset0 = field_offset * screen_width * ps;
1478 else
1479 *offset0 = 0;
1480
1481 *row_inc = pixinc(1 + (screen_width - width) +
1482 (fieldmode ? screen_width : 0),
1483 ps);
1484 *pix_inc = pixinc(1, ps);
1485 break;
1486
1487 case OMAP_DSS_ROT_0 + 4:
1488 case OMAP_DSS_ROT_180 + 4:
1489 /* If the pixel format is YUV or UYVY divide the width
1490 * of the image by 2 for 0 degree and 180 degree
1491 */
1492 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1493 color_mode == OMAP_DSS_COLOR_UYVY)
1494 width = width >> 1;
1495 case OMAP_DSS_ROT_90 + 4:
1496 case OMAP_DSS_ROT_270 + 4:
1497 *offset1 = 0;
1498 if (field_offset)
1499 *offset0 = field_offset * screen_width * ps;
1500 else
1501 *offset0 = 0;
1502 *row_inc = pixinc(1 - (screen_width + width) -
1503 (fieldmode ? screen_width : 0),
1504 ps);
1505 *pix_inc = pixinc(1, ps);
1506 break;
1507
1508 default:
1509 BUG();
1510 }
1511}
1512
1513static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1514 u16 screen_width,
1515 u16 width, u16 height,
1516 enum omap_color_mode color_mode, bool fieldmode,
1517 unsigned int field_offset,
1518 unsigned *offset0, unsigned *offset1,
1519 s32 *row_inc, s32 *pix_inc)
1520{
1521 u8 ps;
1522 u16 fbw, fbh;
1523
1524 /* FIXME CLUT formats */
1525 switch (color_mode) {
1526 case OMAP_DSS_COLOR_CLUT1:
1527 case OMAP_DSS_COLOR_CLUT2:
1528 case OMAP_DSS_COLOR_CLUT4:
1529 case OMAP_DSS_COLOR_CLUT8:
1530 BUG();
1531 return;
1532 default:
1533 ps = color_mode_to_bpp(color_mode) / 8;
1534 break;
1535 }
1536
1537 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1538 width, height);
1539
1540 /* width & height are overlay sizes, convert to fb sizes */
1541
1542 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1543 fbw = width;
1544 fbh = height;
1545 } else {
1546 fbw = height;
1547 fbh = width;
1548 }
1549
1550 /*
1551 * field 0 = even field = bottom field
1552 * field 1 = odd field = top field
1553 */
1554 switch (rotation + mirror * 4) {
1555 case OMAP_DSS_ROT_0:
1556 *offset1 = 0;
1557 if (field_offset)
1558 *offset0 = *offset1 + field_offset * screen_width * ps;
1559 else
1560 *offset0 = *offset1;
1561 *row_inc = pixinc(1 + (screen_width - fbw) +
1562 (fieldmode ? screen_width : 0),
1563 ps);
1564 *pix_inc = pixinc(1, ps);
1565 break;
1566 case OMAP_DSS_ROT_90:
1567 *offset1 = screen_width * (fbh - 1) * ps;
1568 if (field_offset)
1569 *offset0 = *offset1 + field_offset * ps;
1570 else
1571 *offset0 = *offset1;
1572 *row_inc = pixinc(screen_width * (fbh - 1) + 1 +
1573 (fieldmode ? 1 : 0), ps);
1574 *pix_inc = pixinc(-screen_width, ps);
1575 break;
1576 case OMAP_DSS_ROT_180:
1577 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1578 if (field_offset)
1579 *offset0 = *offset1 - field_offset * screen_width * ps;
1580 else
1581 *offset0 = *offset1;
1582 *row_inc = pixinc(-1 -
1583 (screen_width - fbw) -
1584 (fieldmode ? screen_width : 0),
1585 ps);
1586 *pix_inc = pixinc(-1, ps);
1587 break;
1588 case OMAP_DSS_ROT_270:
1589 *offset1 = (fbw - 1) * ps;
1590 if (field_offset)
1591 *offset0 = *offset1 - field_offset * ps;
1592 else
1593 *offset0 = *offset1;
1594 *row_inc = pixinc(-screen_width * (fbh - 1) - 1 -
1595 (fieldmode ? 1 : 0), ps);
1596 *pix_inc = pixinc(screen_width, ps);
1597 break;
1598
1599 /* mirroring */
1600 case OMAP_DSS_ROT_0 + 4:
1601 *offset1 = (fbw - 1) * ps;
1602 if (field_offset)
1603 *offset0 = *offset1 + field_offset * screen_width * ps;
1604 else
1605 *offset0 = *offset1;
1606 *row_inc = pixinc(screen_width * 2 - 1 +
1607 (fieldmode ? screen_width : 0),
1608 ps);
1609 *pix_inc = pixinc(-1, ps);
1610 break;
1611
1612 case OMAP_DSS_ROT_90 + 4:
1613 *offset1 = 0;
1614 if (field_offset)
1615 *offset0 = *offset1 + field_offset * ps;
1616 else
1617 *offset0 = *offset1;
1618 *row_inc = pixinc(-screen_width * (fbh - 1) + 1 +
1619 (fieldmode ? 1 : 0),
1620 ps);
1621 *pix_inc = pixinc(screen_width, ps);
1622 break;
1623
1624 case OMAP_DSS_ROT_180 + 4:
1625 *offset1 = screen_width * (fbh - 1) * ps;
1626 if (field_offset)
1627 *offset0 = *offset1 - field_offset * screen_width * ps;
1628 else
1629 *offset0 = *offset1;
1630 *row_inc = pixinc(1 - screen_width * 2 -
1631 (fieldmode ? screen_width : 0),
1632 ps);
1633 *pix_inc = pixinc(1, ps);
1634 break;
1635
1636 case OMAP_DSS_ROT_270 + 4:
1637 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1638 if (field_offset)
1639 *offset0 = *offset1 - field_offset * ps;
1640 else
1641 *offset0 = *offset1;
1642 *row_inc = pixinc(screen_width * (fbh - 1) - 1 -
1643 (fieldmode ? 1 : 0),
1644 ps);
1645 *pix_inc = pixinc(-screen_width, ps);
1646 break;
1647
1648 default:
1649 BUG();
1650 }
1651}
1652
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00001653static unsigned long calc_fclk_five_taps(enum omap_channel channel, u16 width,
1654 u16 height, u16 out_width, u16 out_height,
1655 enum omap_color_mode color_mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001656{
1657 u32 fclk = 0;
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03001658 u64 tmp, pclk = dispc_mgr_pclk_rate(channel);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001659
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05301660 if (height <= out_height && width <= out_width)
1661 return (unsigned long) pclk;
1662
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001663 if (height > out_height) {
Archit Tanejaebdc5242011-09-08 12:51:10 +05301664 struct omap_dss_device *dssdev = dispc_mgr_get_device(channel);
1665 unsigned int ppl = dssdev->panel.timings.x_res;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001666
1667 tmp = pclk * height * out_width;
1668 do_div(tmp, 2 * out_height * ppl);
1669 fclk = tmp;
1670
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02001671 if (height > 2 * out_height) {
1672 if (ppl == out_width)
1673 return 0;
1674
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001675 tmp = pclk * (height - 2 * out_height) * out_width;
1676 do_div(tmp, 2 * out_height * (ppl - out_width));
1677 fclk = max(fclk, (u32) tmp);
1678 }
1679 }
1680
1681 if (width > out_width) {
1682 tmp = pclk * width;
1683 do_div(tmp, out_width);
1684 fclk = max(fclk, (u32) tmp);
1685
1686 if (color_mode == OMAP_DSS_COLOR_RGB24U)
1687 fclk <<= 1;
1688 }
1689
1690 return fclk;
1691}
1692
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00001693static unsigned long calc_fclk(enum omap_channel channel, u16 width,
1694 u16 height, u16 out_width, u16 out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001695{
1696 unsigned int hf, vf;
Archit Taneja79ee89c2012-01-30 10:54:17 +05301697 unsigned long pclk = dispc_mgr_pclk_rate(channel);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001698
1699 /*
1700 * FIXME how to determine the 'A' factor
1701 * for the no downscaling case ?
1702 */
1703
1704 if (width > 3 * out_width)
1705 hf = 4;
1706 else if (width > 2 * out_width)
1707 hf = 3;
1708 else if (width > out_width)
1709 hf = 2;
1710 else
1711 hf = 1;
1712
1713 if (height > out_height)
1714 vf = 2;
1715 else
1716 vf = 1;
1717
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05301718 if (cpu_is_omap24xx()) {
1719 if (vf > 1 && hf > 1)
Archit Taneja79ee89c2012-01-30 10:54:17 +05301720 return pclk * 4;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05301721 else
Archit Taneja79ee89c2012-01-30 10:54:17 +05301722 return pclk * 2;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05301723 } else if (cpu_is_omap34xx()) {
Archit Taneja79ee89c2012-01-30 10:54:17 +05301724 return pclk * vf * hf;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05301725 } else {
Archit Taneja79ee89c2012-01-30 10:54:17 +05301726 if (hf > 1)
1727 return DIV_ROUND_UP(pclk, out_width) * width;
1728 else
1729 return pclk;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05301730 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001731}
1732
Archit Taneja79ad75f2011-09-08 13:15:11 +05301733static int dispc_ovl_calc_scaling(enum omap_plane plane,
1734 enum omap_channel channel, u16 width, u16 height,
1735 u16 out_width, u16 out_height,
1736 enum omap_color_mode color_mode, bool *five_taps)
1737{
1738 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
Archit Taneja0373cac2011-09-08 13:25:17 +05301739 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05301740 const int maxsinglelinewidth =
1741 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja79ad75f2011-09-08 13:15:11 +05301742 unsigned long fclk = 0;
1743
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02001744 if (width == out_width && height == out_height)
1745 return 0;
1746
1747 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
1748 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05301749
1750 if (out_width < width / maxdownscale ||
1751 out_width > width * 8)
1752 return -EINVAL;
1753
1754 if (out_height < height / maxdownscale ||
1755 out_height > height * 8)
1756 return -EINVAL;
1757
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05301758 if (cpu_is_omap24xx()) {
1759 if (width > maxsinglelinewidth)
1760 DSSERR("Cannot scale max input width exceeded");
1761 *five_taps = false;
1762 fclk = calc_fclk(channel, width, height, out_width,
1763 out_height);
1764 } else if (cpu_is_omap34xx()) {
1765 if (width > (maxsinglelinewidth * 2)) {
1766 DSSERR("Cannot setup scaling");
1767 DSSERR("width exceeds maximum width possible");
1768 return -EINVAL;
1769 }
1770 fclk = calc_fclk_five_taps(channel, width, height, out_width,
1771 out_height, color_mode);
1772 if (width > maxsinglelinewidth) {
1773 if (height > out_height && height < out_height * 2)
1774 *five_taps = false;
1775 else {
1776 DSSERR("cannot setup scaling with five taps");
1777 return -EINVAL;
1778 }
1779 }
1780 if (!*five_taps)
1781 fclk = calc_fclk(channel, width, height, out_width,
1782 out_height);
1783 } else {
1784 if (width > maxsinglelinewidth) {
1785 DSSERR("Cannot scale width exceeds max line width");
1786 return -EINVAL;
1787 }
Archit Taneja79ad75f2011-09-08 13:15:11 +05301788 fclk = calc_fclk(channel, width, height, out_width,
1789 out_height);
Archit Taneja79ad75f2011-09-08 13:15:11 +05301790 }
1791
Archit Taneja79ad75f2011-09-08 13:15:11 +05301792 DSSDBG("required fclk rate = %lu Hz\n", fclk);
1793 DSSDBG("current fclk rate = %lu Hz\n", dispc_fclk_rate());
1794
1795 if (!fclk || fclk > dispc_fclk_rate()) {
1796 DSSERR("failed to set up scaling, "
1797 "required fclk rate = %lu Hz, "
1798 "current fclk rate = %lu Hz\n",
1799 fclk, dispc_fclk_rate());
1800 return -EINVAL;
1801 }
1802
1803 return 0;
1804}
1805
Archit Tanejaa4273b72011-09-14 11:10:10 +05301806int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001807 bool ilace, bool replication)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001808{
Archit Taneja79ad75f2011-09-08 13:15:11 +05301809 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05301810 bool five_taps = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001811 bool fieldmode = 0;
Archit Taneja79ad75f2011-09-08 13:15:11 +05301812 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001813 unsigned offset0, offset1;
1814 s32 row_inc;
1815 s32 pix_inc;
Archit Tanejaa4273b72011-09-14 11:10:10 +05301816 u16 frame_height = oi->height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001817 unsigned int field_offset = 0;
Tomi Valkeinencf073662011-11-03 16:08:27 +02001818 u16 outw, outh;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001819 enum omap_channel channel;
1820
1821 channel = dispc_ovl_get_channel_out(plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001822
Archit Tanejaa4273b72011-09-14 11:10:10 +05301823 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
Tomi Valkeinenf38545d2011-11-03 17:00:07 +02001824 "%dx%d, cmode %x, rot %d, mir %d, ilace %d chan %d repl %d\n",
1825 plane, oi->paddr, oi->p_uv_addr,
Archit Tanejac3d925292011-09-14 11:52:54 +05301826 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
1827 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
Tomi Valkeinenf38545d2011-11-03 17:00:07 +02001828 oi->mirror, ilace, channel, replication);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03001829
Archit Tanejaa4273b72011-09-14 11:10:10 +05301830 if (oi->paddr == 0)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001831 return -EINVAL;
1832
Tomi Valkeinencf073662011-11-03 16:08:27 +02001833 outw = oi->out_width == 0 ? oi->width : oi->out_width;
1834 outh = oi->out_height == 0 ? oi->height : oi->out_height;
1835
1836 if (ilace && oi->height == outh)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001837 fieldmode = 1;
1838
1839 if (ilace) {
1840 if (fieldmode)
Archit Tanejaa4273b72011-09-14 11:10:10 +05301841 oi->height /= 2;
1842 oi->pos_y /= 2;
Tomi Valkeinencf073662011-11-03 16:08:27 +02001843 outh /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001844
1845 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
1846 "out_height %d\n",
Tomi Valkeinencf073662011-11-03 16:08:27 +02001847 oi->height, oi->pos_y, outh);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001848 }
1849
Archit Tanejaa4273b72011-09-14 11:10:10 +05301850 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05301851 return -EINVAL;
1852
Archit Taneja79ad75f2011-09-08 13:15:11 +05301853 r = dispc_ovl_calc_scaling(plane, channel, oi->width, oi->height,
Tomi Valkeinencf073662011-11-03 16:08:27 +02001854 outw, outh, oi->color_mode,
Archit Taneja79ad75f2011-09-08 13:15:11 +05301855 &five_taps);
1856 if (r)
1857 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001858
Archit Taneja79ad75f2011-09-08 13:15:11 +05301859 if (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
1860 oi->color_mode == OMAP_DSS_COLOR_UYVY ||
1861 oi->color_mode == OMAP_DSS_COLOR_NV12)
1862 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001863
1864 if (ilace && !fieldmode) {
1865 /*
1866 * when downscaling the bottom field may have to start several
1867 * source lines below the top field. Unfortunately ACCUI
1868 * registers will only hold the fractional part of the offset
1869 * so the integer part must be added to the base address of the
1870 * bottom field.
1871 */
Tomi Valkeinencf073662011-11-03 16:08:27 +02001872 if (!oi->height || oi->height == outh)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001873 field_offset = 0;
1874 else
Tomi Valkeinencf073662011-11-03 16:08:27 +02001875 field_offset = oi->height / outh / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001876 }
1877
1878 /* Fields are independent but interleaved in memory. */
1879 if (fieldmode)
1880 field_offset = 1;
1881
Archit Tanejaa4273b72011-09-14 11:10:10 +05301882 if (oi->rotation_type == OMAP_DSS_ROT_DMA)
1883 calc_dma_rotation_offset(oi->rotation, oi->mirror,
1884 oi->screen_width, oi->width, frame_height,
1885 oi->color_mode, fieldmode, field_offset,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001886 &offset0, &offset1, &row_inc, &pix_inc);
1887 else
Archit Tanejaa4273b72011-09-14 11:10:10 +05301888 calc_vrfb_rotation_offset(oi->rotation, oi->mirror,
1889 oi->screen_width, oi->width, frame_height,
1890 oi->color_mode, fieldmode, field_offset,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001891 &offset0, &offset1, &row_inc, &pix_inc);
1892
1893 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
1894 offset0, offset1, row_inc, pix_inc);
1895
Archit Tanejaa4273b72011-09-14 11:10:10 +05301896 dispc_ovl_set_color_mode(plane, oi->color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001897
Archit Tanejaa4273b72011-09-14 11:10:10 +05301898 dispc_ovl_set_ba0(plane, oi->paddr + offset0);
1899 dispc_ovl_set_ba1(plane, oi->paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001900
Archit Tanejaa4273b72011-09-14 11:10:10 +05301901 if (OMAP_DSS_COLOR_NV12 == oi->color_mode) {
1902 dispc_ovl_set_ba0_uv(plane, oi->p_uv_addr + offset0);
1903 dispc_ovl_set_ba1_uv(plane, oi->p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301904 }
1905
1906
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001907 dispc_ovl_set_row_inc(plane, row_inc);
1908 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001909
Archit Tanejaa4273b72011-09-14 11:10:10 +05301910 DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, oi->width,
Tomi Valkeinencf073662011-11-03 16:08:27 +02001911 oi->height, outw, outh);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001912
Archit Tanejaa4273b72011-09-14 11:10:10 +05301913 dispc_ovl_set_pos(plane, oi->pos_x, oi->pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001914
Archit Tanejaa4273b72011-09-14 11:10:10 +05301915 dispc_ovl_set_pic_size(plane, oi->width, oi->height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001916
Archit Taneja79ad75f2011-09-08 13:15:11 +05301917 if (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) {
Archit Tanejaa4273b72011-09-14 11:10:10 +05301918 dispc_ovl_set_scaling(plane, oi->width, oi->height,
Tomi Valkeinencf073662011-11-03 16:08:27 +02001919 outw, outh,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301920 ilace, five_taps, fieldmode,
Archit Tanejaa4273b72011-09-14 11:10:10 +05301921 oi->color_mode, oi->rotation);
Tomi Valkeinencf073662011-11-03 16:08:27 +02001922 dispc_ovl_set_vid_size(plane, outw, outh);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001923 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001924 }
1925
Archit Tanejaa4273b72011-09-14 11:10:10 +05301926 dispc_ovl_set_rotation_attrs(plane, oi->rotation, oi->mirror,
1927 oi->color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001928
Archit Taneja54128702011-09-08 11:29:17 +05301929 dispc_ovl_set_zorder(plane, oi->zorder);
Archit Tanejaa4273b72011-09-14 11:10:10 +05301930 dispc_ovl_set_pre_mult_alpha(plane, oi->pre_mult_alpha);
1931 dispc_ovl_setup_global_alpha(plane, oi->global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001932
Archit Tanejac3d925292011-09-14 11:52:54 +05301933 dispc_ovl_enable_replication(plane, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05301934
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001935 return 0;
1936}
1937
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001938int dispc_ovl_enable(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001939{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03001940 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
1941
Archit Taneja9b372c22011-05-06 11:45:49 +05301942 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03001943
1944 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001945}
1946
1947static void dispc_disable_isr(void *data, u32 mask)
1948{
1949 struct completion *compl = data;
1950 complete(compl);
1951}
1952
Sumit Semwal2a205f32010-12-02 11:27:12 +00001953static void _enable_lcd_out(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001954{
Tomi Valkeinenb6a44e72011-10-12 10:17:02 +03001955 if (channel == OMAP_DSS_CHANNEL_LCD2) {
Sumit Semwal2a205f32010-12-02 11:27:12 +00001956 REG_FLD_MOD(DISPC_CONTROL2, enable ? 1 : 0, 0, 0);
Tomi Valkeinenb6a44e72011-10-12 10:17:02 +03001957 /* flush posted write */
1958 dispc_read_reg(DISPC_CONTROL2);
1959 } else {
Sumit Semwal2a205f32010-12-02 11:27:12 +00001960 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0);
Tomi Valkeinenb6a44e72011-10-12 10:17:02 +03001961 dispc_read_reg(DISPC_CONTROL);
1962 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001963}
1964
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03001965static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001966{
1967 struct completion frame_done_completion;
1968 bool is_on;
1969 int r;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001970 u32 irq;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001971
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001972 /* When we disable LCD output, we need to wait until frame is done.
1973 * Otherwise the DSS is still working, and turning off the clocks
1974 * prevents DSS from going to OFF mode */
Sumit Semwal2a205f32010-12-02 11:27:12 +00001975 is_on = channel == OMAP_DSS_CHANNEL_LCD2 ?
1976 REG_GET(DISPC_CONTROL2, 0, 0) :
1977 REG_GET(DISPC_CONTROL, 0, 0);
1978
1979 irq = channel == OMAP_DSS_CHANNEL_LCD2 ? DISPC_IRQ_FRAMEDONE2 :
1980 DISPC_IRQ_FRAMEDONE;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001981
1982 if (!enable && is_on) {
1983 init_completion(&frame_done_completion);
1984
1985 r = omap_dispc_register_isr(dispc_disable_isr,
Sumit Semwal2a205f32010-12-02 11:27:12 +00001986 &frame_done_completion, irq);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001987
1988 if (r)
1989 DSSERR("failed to register FRAMEDONE isr\n");
1990 }
1991
Sumit Semwal2a205f32010-12-02 11:27:12 +00001992 _enable_lcd_out(channel, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001993
1994 if (!enable && is_on) {
1995 if (!wait_for_completion_timeout(&frame_done_completion,
1996 msecs_to_jiffies(100)))
1997 DSSERR("timeout waiting for FRAME DONE\n");
1998
1999 r = omap_dispc_unregister_isr(dispc_disable_isr,
Sumit Semwal2a205f32010-12-02 11:27:12 +00002000 &frame_done_completion, irq);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002001
2002 if (r)
2003 DSSERR("failed to unregister FRAMEDONE isr\n");
2004 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002005}
2006
2007static void _enable_digit_out(bool enable)
2008{
2009 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
Tomi Valkeinenb6a44e72011-10-12 10:17:02 +03002010 /* flush posted write */
2011 dispc_read_reg(DISPC_CONTROL);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002012}
2013
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002014static void dispc_mgr_enable_digit_out(bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002015{
2016 struct completion frame_done_completion;
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002017 enum dss_hdmi_venc_clk_source_select src;
2018 int r, i;
2019 u32 irq_mask;
2020 int num_irqs;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002021
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002022 if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002023 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002024
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002025 src = dss_get_hdmi_venc_clk_source();
2026
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002027 if (enable) {
2028 unsigned long flags;
2029 /* When we enable digit output, we'll get an extra digit
2030 * sync lost interrupt, that we need to ignore */
2031 spin_lock_irqsave(&dispc.irq_lock, flags);
2032 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
2033 _omap_dispc_set_irqs();
2034 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2035 }
2036
2037 /* When we disable digit output, we need to wait until fields are done.
2038 * Otherwise the DSS is still working, and turning off the clocks
2039 * prevents DSS from going to OFF mode. And when enabling, we need to
2040 * wait for the extra sync losts */
2041 init_completion(&frame_done_completion);
2042
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002043 if (src == DSS_HDMI_M_PCLK && enable == false) {
2044 irq_mask = DISPC_IRQ_FRAMEDONETV;
2045 num_irqs = 1;
2046 } else {
2047 irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
2048 /* XXX I understand from TRM that we should only wait for the
2049 * current field to complete. But it seems we have to wait for
2050 * both fields */
2051 num_irqs = 2;
2052 }
2053
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002054 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002055 irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002056 if (r)
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002057 DSSERR("failed to register %x isr\n", irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002058
2059 _enable_digit_out(enable);
2060
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002061 for (i = 0; i < num_irqs; ++i) {
2062 if (!wait_for_completion_timeout(&frame_done_completion,
2063 msecs_to_jiffies(100)))
2064 DSSERR("timeout waiting for digit out to %s\n",
2065 enable ? "start" : "stop");
2066 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002067
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002068 r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
2069 irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002070 if (r)
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002071 DSSERR("failed to unregister %x isr\n", irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002072
2073 if (enable) {
2074 unsigned long flags;
2075 spin_lock_irqsave(&dispc.irq_lock, flags);
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002076 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002077 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
2078 _omap_dispc_set_irqs();
2079 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2080 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002081}
2082
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002083bool dispc_mgr_is_enabled(enum omap_channel channel)
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002084{
2085 if (channel == OMAP_DSS_CHANNEL_LCD)
2086 return !!REG_GET(DISPC_CONTROL, 0, 0);
2087 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2088 return !!REG_GET(DISPC_CONTROL, 1, 1);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002089 else if (channel == OMAP_DSS_CHANNEL_LCD2)
2090 return !!REG_GET(DISPC_CONTROL2, 0, 0);
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002091 else
2092 BUG();
2093}
2094
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002095void dispc_mgr_enable(enum omap_channel channel, bool enable)
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002096{
Archit Tanejadac57a02011-09-08 12:30:19 +05302097 if (dispc_mgr_is_lcd(channel))
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002098 dispc_mgr_enable_lcd_out(channel, enable);
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002099 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002100 dispc_mgr_enable_digit_out(enable);
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002101 else
2102 BUG();
2103}
2104
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002105void dispc_lcd_enable_signal_polarity(bool act_high)
2106{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002107 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2108 return;
2109
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002110 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002111}
2112
2113void dispc_lcd_enable_signal(bool enable)
2114{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002115 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2116 return;
2117
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002118 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002119}
2120
2121void dispc_pck_free_enable(bool enable)
2122{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002123 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2124 return;
2125
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002126 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002127}
2128
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002129void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002130{
Sumit Semwal2a205f32010-12-02 11:27:12 +00002131 if (channel == OMAP_DSS_CHANNEL_LCD2)
2132 REG_FLD_MOD(DISPC_CONFIG2, enable ? 1 : 0, 16, 16);
2133 else
2134 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 16, 16);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002135}
2136
2137
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002138void dispc_mgr_set_lcd_display_type(enum omap_channel channel,
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002139 enum omap_lcd_display_type type)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002140{
2141 int mode;
2142
2143 switch (type) {
2144 case OMAP_DSS_LCD_DISPLAY_STN:
2145 mode = 0;
2146 break;
2147
2148 case OMAP_DSS_LCD_DISPLAY_TFT:
2149 mode = 1;
2150 break;
2151
2152 default:
2153 BUG();
2154 return;
2155 }
2156
Sumit Semwal2a205f32010-12-02 11:27:12 +00002157 if (channel == OMAP_DSS_CHANNEL_LCD2)
2158 REG_FLD_MOD(DISPC_CONTROL2, mode, 3, 3);
2159 else
2160 REG_FLD_MOD(DISPC_CONTROL, mode, 3, 3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002161}
2162
2163void dispc_set_loadmode(enum omap_dss_load_mode mode)
2164{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002165 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002166}
2167
2168
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002169static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002170{
Sumit Semwal8613b002010-12-02 11:27:09 +00002171 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002172}
2173
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002174static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002175 enum omap_dss_trans_key_type type,
2176 u32 trans_key)
2177{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002178 if (ch == OMAP_DSS_CHANNEL_LCD)
2179 REG_FLD_MOD(DISPC_CONFIG, type, 11, 11);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002180 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002181 REG_FLD_MOD(DISPC_CONFIG, type, 13, 13);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002182 else /* OMAP_DSS_CHANNEL_LCD2 */
2183 REG_FLD_MOD(DISPC_CONFIG2, type, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002184
Sumit Semwal8613b002010-12-02 11:27:09 +00002185 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002186}
2187
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002188static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002189{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002190 if (ch == OMAP_DSS_CHANNEL_LCD)
2191 REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002192 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002193 REG_FLD_MOD(DISPC_CONFIG, enable, 12, 12);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002194 else /* OMAP_DSS_CHANNEL_LCD2 */
2195 REG_FLD_MOD(DISPC_CONFIG2, enable, 10, 10);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002196}
Archit Taneja11354dd2011-09-26 11:47:29 +05302197
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002198static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2199 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002200{
Archit Taneja11354dd2011-09-26 11:47:29 +05302201 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002202 return;
2203
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002204 if (ch == OMAP_DSS_CHANNEL_LCD)
2205 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002206 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002207 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002208}
Archit Taneja11354dd2011-09-26 11:47:29 +05302209
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002210void dispc_mgr_setup(enum omap_channel channel,
2211 struct omap_overlay_manager_info *info)
2212{
2213 dispc_mgr_set_default_color(channel, info->default_color);
2214 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2215 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2216 dispc_mgr_enable_alpha_fixed_zorder(channel,
2217 info->partial_alpha_enabled);
2218 if (dss_has_feature(FEAT_CPR)) {
2219 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2220 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2221 }
2222}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002223
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002224void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002225{
2226 int code;
2227
2228 switch (data_lines) {
2229 case 12:
2230 code = 0;
2231 break;
2232 case 16:
2233 code = 1;
2234 break;
2235 case 18:
2236 code = 2;
2237 break;
2238 case 24:
2239 code = 3;
2240 break;
2241 default:
2242 BUG();
2243 return;
2244 }
2245
Sumit Semwal2a205f32010-12-02 11:27:12 +00002246 if (channel == OMAP_DSS_CHANNEL_LCD2)
2247 REG_FLD_MOD(DISPC_CONTROL2, code, 9, 8);
2248 else
2249 REG_FLD_MOD(DISPC_CONTROL, code, 9, 8);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002250}
2251
Archit Taneja569969d2011-08-22 17:41:57 +05302252void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002253{
2254 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302255 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002256
2257 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302258 case DSS_IO_PAD_MODE_RESET:
2259 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002260 gpout1 = 0;
2261 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302262 case DSS_IO_PAD_MODE_RFBI:
2263 gpout0 = 1;
2264 gpout1 = 0;
2265 break;
2266 case DSS_IO_PAD_MODE_BYPASS:
2267 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002268 gpout1 = 1;
2269 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002270 default:
2271 BUG();
2272 return;
2273 }
2274
Archit Taneja569969d2011-08-22 17:41:57 +05302275 l = dispc_read_reg(DISPC_CONTROL);
2276 l = FLD_MOD(l, gpout0, 15, 15);
2277 l = FLD_MOD(l, gpout1, 16, 16);
2278 dispc_write_reg(DISPC_CONTROL, l);
2279}
2280
2281void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2282{
2283 if (channel == OMAP_DSS_CHANNEL_LCD2)
2284 REG_FLD_MOD(DISPC_CONTROL2, enable, 11, 11);
2285 else
2286 REG_FLD_MOD(DISPC_CONTROL, enable, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002287}
2288
2289static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2290 int vsw, int vfp, int vbp)
2291{
2292 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2293 if (hsw < 1 || hsw > 64 ||
2294 hfp < 1 || hfp > 256 ||
2295 hbp < 1 || hbp > 256 ||
2296 vsw < 1 || vsw > 64 ||
2297 vfp < 0 || vfp > 255 ||
2298 vbp < 0 || vbp > 255)
2299 return false;
2300 } else {
2301 if (hsw < 1 || hsw > 256 ||
2302 hfp < 1 || hfp > 4096 ||
2303 hbp < 1 || hbp > 4096 ||
2304 vsw < 1 || vsw > 256 ||
2305 vfp < 0 || vfp > 4095 ||
2306 vbp < 0 || vbp > 4095)
2307 return false;
2308 }
2309
2310 return true;
2311}
2312
2313bool dispc_lcd_timings_ok(struct omap_video_timings *timings)
2314{
2315 return _dispc_lcd_timings_ok(timings->hsw, timings->hfp,
2316 timings->hbp, timings->vsw,
2317 timings->vfp, timings->vbp);
2318}
2319
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002320static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002321 int hfp, int hbp, int vsw, int vfp, int vbp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002322{
2323 u32 timing_h, timing_v;
2324
2325 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2326 timing_h = FLD_VAL(hsw-1, 5, 0) | FLD_VAL(hfp-1, 15, 8) |
2327 FLD_VAL(hbp-1, 27, 20);
2328
2329 timing_v = FLD_VAL(vsw-1, 5, 0) | FLD_VAL(vfp, 15, 8) |
2330 FLD_VAL(vbp, 27, 20);
2331 } else {
2332 timing_h = FLD_VAL(hsw-1, 7, 0) | FLD_VAL(hfp-1, 19, 8) |
2333 FLD_VAL(hbp-1, 31, 20);
2334
2335 timing_v = FLD_VAL(vsw-1, 7, 0) | FLD_VAL(vfp, 19, 8) |
2336 FLD_VAL(vbp, 31, 20);
2337 }
2338
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002339 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2340 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002341}
2342
2343/* change name to mode? */
Archit Tanejac51d9212012-04-16 12:53:43 +05302344void dispc_mgr_set_timings(enum omap_channel channel,
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002345 struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002346{
2347 unsigned xtot, ytot;
2348 unsigned long ht, vt;
2349
Sumit Semwal2a205f32010-12-02 11:27:12 +00002350 DSSDBG("channel %d xres %u yres %u\n", channel, timings->x_res,
2351 timings->y_res);
Archit Tanejac51d9212012-04-16 12:53:43 +05302352
2353 if (dispc_mgr_is_lcd(channel)) {
2354 if (!dispc_lcd_timings_ok(timings))
2355 BUG();
2356
2357 _dispc_mgr_set_lcd_timings(channel, timings->hsw, timings->hfp,
2358 timings->hbp, timings->vsw, timings->vfp,
2359 timings->vbp);
2360
2361 dispc_mgr_set_lcd_size(channel, timings->x_res, timings->y_res);
2362
2363 xtot = timings->x_res + timings->hfp + timings->hsw +
2364 timings->hbp;
2365 ytot = timings->y_res + timings->vfp + timings->vsw +
2366 timings->vbp;
2367
2368 ht = (timings->pixel_clock * 1000) / xtot;
2369 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2370
2371 DSSDBG("pck %u\n", timings->pixel_clock);
2372 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002373 timings->hsw, timings->hfp, timings->hbp,
2374 timings->vsw, timings->vfp, timings->vbp);
2375
Archit Tanejac51d9212012-04-16 12:53:43 +05302376 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2377 } else {
2378 dispc_mgr_set_digit_size(timings->x_res, timings->y_res);
2379 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002380}
2381
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002382static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002383 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002384{
2385 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03002386 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002387
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06002388 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002389 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002390}
2391
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002392static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00002393 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002394{
2395 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06002396 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002397 *lck_div = FLD_GET(l, 23, 16);
2398 *pck_div = FLD_GET(l, 7, 0);
2399}
2400
2401unsigned long dispc_fclk_rate(void)
2402{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302403 struct platform_device *dsidev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002404 unsigned long r = 0;
2405
Taneja, Archit66534e82011-03-08 05:50:34 -06002406 switch (dss_get_dispc_clk_source()) {
Archit Taneja89a35e52011-04-12 13:52:23 +05302407 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002408 r = clk_get_rate(dispc.dss_clk);
Taneja, Archit66534e82011-03-08 05:50:34 -06002409 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05302410 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302411 dsidev = dsi_get_dsidev_from_id(0);
2412 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
Taneja, Archit66534e82011-03-08 05:50:34 -06002413 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05302414 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2415 dsidev = dsi_get_dsidev_from_id(1);
2416 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2417 break;
Taneja, Archit66534e82011-03-08 05:50:34 -06002418 default:
2419 BUG();
2420 }
2421
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002422 return r;
2423}
2424
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002425unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002426{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302427 struct platform_device *dsidev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002428 int lcd;
2429 unsigned long r;
2430 u32 l;
2431
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06002432 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002433
2434 lcd = FLD_GET(l, 23, 16);
2435
Taneja, Architea751592011-03-08 05:50:35 -06002436 switch (dss_get_lcd_clk_source(channel)) {
Archit Taneja89a35e52011-04-12 13:52:23 +05302437 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002438 r = clk_get_rate(dispc.dss_clk);
Taneja, Architea751592011-03-08 05:50:35 -06002439 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05302440 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302441 dsidev = dsi_get_dsidev_from_id(0);
2442 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
Taneja, Architea751592011-03-08 05:50:35 -06002443 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05302444 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2445 dsidev = dsi_get_dsidev_from_id(1);
2446 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2447 break;
Taneja, Architea751592011-03-08 05:50:35 -06002448 default:
2449 BUG();
2450 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002451
2452 return r / lcd;
2453}
2454
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002455unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002456{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002457 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002458
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302459 if (dispc_mgr_is_lcd(channel)) {
2460 int pcd;
2461 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002462
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302463 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002464
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302465 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002466
Archit Tanejac3dc6a72011-09-13 18:28:41 +05302467 r = dispc_mgr_lclk_rate(channel);
2468
2469 return r / pcd;
2470 } else {
2471 struct omap_dss_device *dssdev =
2472 dispc_mgr_get_device(channel);
2473
2474 switch (dssdev->type) {
2475 case OMAP_DISPLAY_TYPE_VENC:
2476 return venc_get_pixel_clock();
2477 case OMAP_DISPLAY_TYPE_HDMI:
2478 return hdmi_get_pixel_clock();
2479 default:
2480 BUG();
2481 }
2482 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002483}
2484
2485void dispc_dump_clocks(struct seq_file *s)
2486{
2487 int lcd, pcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06002488 u32 l;
Archit Taneja89a35e52011-04-12 13:52:23 +05302489 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
2490 enum omap_dss_clk_source lcd_clk_src;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002491
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002492 if (dispc_runtime_get())
2493 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002494
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002495 seq_printf(s, "- DISPC -\n");
2496
Archit Taneja067a57e2011-03-02 11:57:25 +05302497 seq_printf(s, "dispc fclk source = %s (%s)\n",
2498 dss_get_generic_clk_source_name(dispc_clk_src),
2499 dss_feat_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002500
2501 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00002502
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06002503 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
2504 seq_printf(s, "- DISPC-CORE-CLK -\n");
2505 l = dispc_read_reg(DISPC_DIVISOR);
2506 lcd = FLD_GET(l, 23, 16);
2507
2508 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2509 (dispc_fclk_rate()/lcd), lcd);
2510 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00002511 seq_printf(s, "- LCD1 -\n");
2512
Taneja, Architea751592011-03-08 05:50:35 -06002513 lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD);
2514
2515 seq_printf(s, "lcd1_clk source = %s (%s)\n",
2516 dss_get_generic_clk_source_name(lcd_clk_src),
2517 dss_feat_get_clk_source_name(lcd_clk_src));
2518
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002519 dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD, &lcd, &pcd);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002520
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002521 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002522 dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD), lcd);
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002523 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002524 dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD), pcd);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002525 if (dss_has_feature(FEAT_MGR_LCD2)) {
2526 seq_printf(s, "- LCD2 -\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002527
Taneja, Architea751592011-03-08 05:50:35 -06002528 lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD2);
2529
2530 seq_printf(s, "lcd2_clk source = %s (%s)\n",
2531 dss_get_generic_clk_source_name(lcd_clk_src),
2532 dss_feat_get_clk_source_name(lcd_clk_src));
2533
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002534 dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD2, &lcd, &pcd);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002535
2536 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002537 dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD2), lcd);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002538 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002539 dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD2), pcd);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002540 }
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002541
2542 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002543}
2544
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02002545#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
2546void dispc_dump_irqs(struct seq_file *s)
2547{
2548 unsigned long flags;
2549 struct dispc_irq_stats stats;
2550
2551 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
2552
2553 stats = dispc.irq_stats;
2554 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
2555 dispc.irq_stats.last_reset = jiffies;
2556
2557 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
2558
2559 seq_printf(s, "period %u ms\n",
2560 jiffies_to_msecs(jiffies - stats.last_reset));
2561
2562 seq_printf(s, "irqs %d\n", stats.irq_count);
2563#define PIS(x) \
2564 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
2565
2566 PIS(FRAMEDONE);
2567 PIS(VSYNC);
2568 PIS(EVSYNC_EVEN);
2569 PIS(EVSYNC_ODD);
2570 PIS(ACBIAS_COUNT_STAT);
2571 PIS(PROG_LINE_NUM);
2572 PIS(GFX_FIFO_UNDERFLOW);
2573 PIS(GFX_END_WIN);
2574 PIS(PAL_GAMMA_MASK);
2575 PIS(OCP_ERR);
2576 PIS(VID1_FIFO_UNDERFLOW);
2577 PIS(VID1_END_WIN);
2578 PIS(VID2_FIFO_UNDERFLOW);
2579 PIS(VID2_END_WIN);
Archit Tanejab8c095b2011-09-13 18:20:33 +05302580 if (dss_feat_get_num_ovls() > 3) {
2581 PIS(VID3_FIFO_UNDERFLOW);
2582 PIS(VID3_END_WIN);
2583 }
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02002584 PIS(SYNC_LOST);
2585 PIS(SYNC_LOST_DIGIT);
2586 PIS(WAKEUP);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002587 if (dss_has_feature(FEAT_MGR_LCD2)) {
2588 PIS(FRAMEDONE2);
2589 PIS(VSYNC2);
2590 PIS(ACBIAS_COUNT_STAT2);
2591 PIS(SYNC_LOST2);
2592 }
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02002593#undef PIS
2594}
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02002595#endif
2596
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002597void dispc_dump_regs(struct seq_file *s)
2598{
Archit Taneja4dd2da12011-08-05 19:06:01 +05302599 int i, j;
2600 const char *mgr_names[] = {
2601 [OMAP_DSS_CHANNEL_LCD] = "LCD",
2602 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
2603 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
2604 };
2605 const char *ovl_names[] = {
2606 [OMAP_DSS_GFX] = "GFX",
2607 [OMAP_DSS_VIDEO1] = "VID1",
2608 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05302609 [OMAP_DSS_VIDEO3] = "VID3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05302610 };
2611 const char **p_names;
2612
Archit Taneja9b372c22011-05-06 11:45:49 +05302613#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002614
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002615 if (dispc_runtime_get())
2616 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002617
Archit Taneja5010be82011-08-05 19:06:00 +05302618 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002619 DUMPREG(DISPC_REVISION);
2620 DUMPREG(DISPC_SYSCONFIG);
2621 DUMPREG(DISPC_SYSSTATUS);
2622 DUMPREG(DISPC_IRQSTATUS);
2623 DUMPREG(DISPC_IRQENABLE);
2624 DUMPREG(DISPC_CONTROL);
2625 DUMPREG(DISPC_CONFIG);
2626 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002627 DUMPREG(DISPC_LINE_STATUS);
2628 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05302629 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
2630 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03002631 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002632 if (dss_has_feature(FEAT_MGR_LCD2)) {
2633 DUMPREG(DISPC_CONTROL2);
2634 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002635 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002636
Archit Taneja5010be82011-08-05 19:06:00 +05302637#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002638
Archit Taneja5010be82011-08-05 19:06:00 +05302639#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05302640#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
2641 48 - strlen(#r) - strlen(p_names[i]), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05302642 dispc_read_reg(DISPC_REG(i, r)))
2643
Archit Taneja4dd2da12011-08-05 19:06:01 +05302644 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05302645
Archit Taneja4dd2da12011-08-05 19:06:01 +05302646 /* DISPC channel specific registers */
2647 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
2648 DUMPREG(i, DISPC_DEFAULT_COLOR);
2649 DUMPREG(i, DISPC_TRANS_COLOR);
2650 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002651
Archit Taneja4dd2da12011-08-05 19:06:01 +05302652 if (i == OMAP_DSS_CHANNEL_DIGIT)
2653 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05302654
Archit Taneja4dd2da12011-08-05 19:06:01 +05302655 DUMPREG(i, DISPC_DEFAULT_COLOR);
2656 DUMPREG(i, DISPC_TRANS_COLOR);
2657 DUMPREG(i, DISPC_TIMING_H);
2658 DUMPREG(i, DISPC_TIMING_V);
2659 DUMPREG(i, DISPC_POL_FREQ);
2660 DUMPREG(i, DISPC_DIVISORo);
2661 DUMPREG(i, DISPC_SIZE_MGR);
Archit Taneja5010be82011-08-05 19:06:00 +05302662
Archit Taneja4dd2da12011-08-05 19:06:01 +05302663 DUMPREG(i, DISPC_DATA_CYCLE1);
2664 DUMPREG(i, DISPC_DATA_CYCLE2);
2665 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002666
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03002667 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05302668 DUMPREG(i, DISPC_CPR_COEF_R);
2669 DUMPREG(i, DISPC_CPR_COEF_G);
2670 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03002671 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00002672 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002673
Archit Taneja4dd2da12011-08-05 19:06:01 +05302674 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002675
Archit Taneja4dd2da12011-08-05 19:06:01 +05302676 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
2677 DUMPREG(i, DISPC_OVL_BA0);
2678 DUMPREG(i, DISPC_OVL_BA1);
2679 DUMPREG(i, DISPC_OVL_POSITION);
2680 DUMPREG(i, DISPC_OVL_SIZE);
2681 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
2682 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
2683 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
2684 DUMPREG(i, DISPC_OVL_ROW_INC);
2685 DUMPREG(i, DISPC_OVL_PIXEL_INC);
2686 if (dss_has_feature(FEAT_PRELOAD))
2687 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002688
Archit Taneja4dd2da12011-08-05 19:06:01 +05302689 if (i == OMAP_DSS_GFX) {
2690 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
2691 DUMPREG(i, DISPC_OVL_TABLE_BA);
2692 continue;
2693 }
2694
2695 DUMPREG(i, DISPC_OVL_FIR);
2696 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
2697 DUMPREG(i, DISPC_OVL_ACCU0);
2698 DUMPREG(i, DISPC_OVL_ACCU1);
2699 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
2700 DUMPREG(i, DISPC_OVL_BA0_UV);
2701 DUMPREG(i, DISPC_OVL_BA1_UV);
2702 DUMPREG(i, DISPC_OVL_FIR2);
2703 DUMPREG(i, DISPC_OVL_ACCU2_0);
2704 DUMPREG(i, DISPC_OVL_ACCU2_1);
2705 }
2706 if (dss_has_feature(FEAT_ATTR2))
2707 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
2708 if (dss_has_feature(FEAT_PRELOAD))
2709 DUMPREG(i, DISPC_OVL_PRELOAD);
Archit Taneja5010be82011-08-05 19:06:00 +05302710 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002711
Archit Taneja5010be82011-08-05 19:06:00 +05302712#undef DISPC_REG
2713#undef DUMPREG
2714
2715#define DISPC_REG(plane, name, i) name(plane, i)
2716#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05302717 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
2718 46 - strlen(#name) - strlen(p_names[plane]), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05302719 dispc_read_reg(DISPC_REG(plane, name, i)))
2720
Archit Taneja4dd2da12011-08-05 19:06:01 +05302721 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05302722
Archit Taneja4dd2da12011-08-05 19:06:01 +05302723 /* start from OMAP_DSS_VIDEO1 */
2724 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
2725 for (j = 0; j < 8; j++)
2726 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05302727
Archit Taneja4dd2da12011-08-05 19:06:01 +05302728 for (j = 0; j < 8; j++)
2729 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05302730
Archit Taneja4dd2da12011-08-05 19:06:01 +05302731 for (j = 0; j < 5; j++)
2732 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002733
Archit Taneja4dd2da12011-08-05 19:06:01 +05302734 if (dss_has_feature(FEAT_FIR_COEF_V)) {
2735 for (j = 0; j < 8; j++)
2736 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
2737 }
Amber Jainab5ca072011-05-19 19:47:53 +05302738
Archit Taneja4dd2da12011-08-05 19:06:01 +05302739 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
2740 for (j = 0; j < 8; j++)
2741 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05302742
Archit Taneja4dd2da12011-08-05 19:06:01 +05302743 for (j = 0; j < 8; j++)
2744 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05302745
Archit Taneja4dd2da12011-08-05 19:06:01 +05302746 for (j = 0; j < 8; j++)
2747 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
2748 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03002749 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002750
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002751 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05302752
2753#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002754#undef DUMPREG
2755}
2756
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002757static void _dispc_mgr_set_pol_freq(enum omap_channel channel, bool onoff,
2758 bool rf, bool ieo, bool ipc, bool ihs, bool ivs, u8 acbi,
2759 u8 acb)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002760{
2761 u32 l = 0;
2762
2763 DSSDBG("onoff %d rf %d ieo %d ipc %d ihs %d ivs %d acbi %d acb %d\n",
2764 onoff, rf, ieo, ipc, ihs, ivs, acbi, acb);
2765
2766 l |= FLD_VAL(onoff, 17, 17);
2767 l |= FLD_VAL(rf, 16, 16);
2768 l |= FLD_VAL(ieo, 15, 15);
2769 l |= FLD_VAL(ipc, 14, 14);
2770 l |= FLD_VAL(ihs, 13, 13);
2771 l |= FLD_VAL(ivs, 12, 12);
2772 l |= FLD_VAL(acbi, 11, 8);
2773 l |= FLD_VAL(acb, 7, 0);
2774
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002775 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002776}
2777
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002778void dispc_mgr_set_pol_freq(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002779 enum omap_panel_config config, u8 acbi, u8 acb)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002780{
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002781 _dispc_mgr_set_pol_freq(channel, (config & OMAP_DSS_LCD_ONOFF) != 0,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002782 (config & OMAP_DSS_LCD_RF) != 0,
2783 (config & OMAP_DSS_LCD_IEO) != 0,
2784 (config & OMAP_DSS_LCD_IPC) != 0,
2785 (config & OMAP_DSS_LCD_IHS) != 0,
2786 (config & OMAP_DSS_LCD_IVS) != 0,
2787 acbi, acb);
2788}
2789
2790/* with fck as input clock rate, find dispc dividers that produce req_pck */
2791void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
2792 struct dispc_clock_info *cinfo)
2793{
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03002794 u16 pcd_min, pcd_max;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002795 unsigned long best_pck;
2796 u16 best_ld, cur_ld;
2797 u16 best_pd, cur_pd;
2798
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03002799 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
2800 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
2801
2802 if (!is_tft)
2803 pcd_min = 3;
2804
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002805 best_pck = 0;
2806 best_ld = 0;
2807 best_pd = 0;
2808
2809 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
2810 unsigned long lck = fck / cur_ld;
2811
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03002812 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002813 unsigned long pck = lck / cur_pd;
2814 long old_delta = abs(best_pck - req_pck);
2815 long new_delta = abs(pck - req_pck);
2816
2817 if (best_pck == 0 || new_delta < old_delta) {
2818 best_pck = pck;
2819 best_ld = cur_ld;
2820 best_pd = cur_pd;
2821
2822 if (pck == req_pck)
2823 goto found;
2824 }
2825
2826 if (pck < req_pck)
2827 break;
2828 }
2829
2830 if (lck / pcd_min < req_pck)
2831 break;
2832 }
2833
2834found:
2835 cinfo->lck_div = best_ld;
2836 cinfo->pck_div = best_pd;
2837 cinfo->lck = fck / cinfo->lck_div;
2838 cinfo->pck = cinfo->lck / cinfo->pck_div;
2839}
2840
2841/* calculate clock rates using dividers in cinfo */
2842int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
2843 struct dispc_clock_info *cinfo)
2844{
2845 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
2846 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03002847 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002848 return -EINVAL;
2849
2850 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
2851 cinfo->pck = cinfo->lck / cinfo->pck_div;
2852
2853 return 0;
2854}
2855
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002856int dispc_mgr_set_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002857 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002858{
2859 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
2860 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
2861
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002862 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002863
2864 return 0;
2865}
2866
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002867int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002868 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002869{
2870 unsigned long fck;
2871
2872 fck = dispc_fclk_rate();
2873
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06002874 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
2875 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002876
2877 cinfo->lck = fck / cinfo->lck_div;
2878 cinfo->pck = cinfo->lck / cinfo->pck_div;
2879
2880 return 0;
2881}
2882
2883/* dispc.irq_lock has to be locked by the caller */
2884static void _omap_dispc_set_irqs(void)
2885{
2886 u32 mask;
2887 u32 old_mask;
2888 int i;
2889 struct omap_dispc_isr_data *isr_data;
2890
2891 mask = dispc.irq_error_mask;
2892
2893 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2894 isr_data = &dispc.registered_isr[i];
2895
2896 if (isr_data->isr == NULL)
2897 continue;
2898
2899 mask |= isr_data->mask;
2900 }
2901
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002902 old_mask = dispc_read_reg(DISPC_IRQENABLE);
2903 /* clear the irqstatus for newly enabled irqs */
2904 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
2905
2906 dispc_write_reg(DISPC_IRQENABLE, mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002907}
2908
2909int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
2910{
2911 int i;
2912 int ret;
2913 unsigned long flags;
2914 struct omap_dispc_isr_data *isr_data;
2915
2916 if (isr == NULL)
2917 return -EINVAL;
2918
2919 spin_lock_irqsave(&dispc.irq_lock, flags);
2920
2921 /* check for duplicate entry */
2922 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2923 isr_data = &dispc.registered_isr[i];
2924 if (isr_data->isr == isr && isr_data->arg == arg &&
2925 isr_data->mask == mask) {
2926 ret = -EINVAL;
2927 goto err;
2928 }
2929 }
2930
2931 isr_data = NULL;
2932 ret = -EBUSY;
2933
2934 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2935 isr_data = &dispc.registered_isr[i];
2936
2937 if (isr_data->isr != NULL)
2938 continue;
2939
2940 isr_data->isr = isr;
2941 isr_data->arg = arg;
2942 isr_data->mask = mask;
2943 ret = 0;
2944
2945 break;
2946 }
2947
Tomi Valkeinenb9cb0982011-03-04 18:19:54 +02002948 if (ret)
2949 goto err;
2950
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002951 _omap_dispc_set_irqs();
2952
2953 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2954
2955 return 0;
2956err:
2957 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2958
2959 return ret;
2960}
2961EXPORT_SYMBOL(omap_dispc_register_isr);
2962
2963int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
2964{
2965 int i;
2966 unsigned long flags;
2967 int ret = -EINVAL;
2968 struct omap_dispc_isr_data *isr_data;
2969
2970 spin_lock_irqsave(&dispc.irq_lock, flags);
2971
2972 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2973 isr_data = &dispc.registered_isr[i];
2974 if (isr_data->isr != isr || isr_data->arg != arg ||
2975 isr_data->mask != mask)
2976 continue;
2977
2978 /* found the correct isr */
2979
2980 isr_data->isr = NULL;
2981 isr_data->arg = NULL;
2982 isr_data->mask = 0;
2983
2984 ret = 0;
2985 break;
2986 }
2987
2988 if (ret == 0)
2989 _omap_dispc_set_irqs();
2990
2991 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2992
2993 return ret;
2994}
2995EXPORT_SYMBOL(omap_dispc_unregister_isr);
2996
2997#ifdef DEBUG
2998static void print_irq_status(u32 status)
2999{
3000 if ((status & dispc.irq_error_mask) == 0)
3001 return;
3002
3003 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
3004
3005#define PIS(x) \
3006 if (status & DISPC_IRQ_##x) \
3007 printk(#x " ");
3008 PIS(GFX_FIFO_UNDERFLOW);
3009 PIS(OCP_ERR);
3010 PIS(VID1_FIFO_UNDERFLOW);
3011 PIS(VID2_FIFO_UNDERFLOW);
Archit Tanejab8c095b2011-09-13 18:20:33 +05303012 if (dss_feat_get_num_ovls() > 3)
3013 PIS(VID3_FIFO_UNDERFLOW);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003014 PIS(SYNC_LOST);
3015 PIS(SYNC_LOST_DIGIT);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003016 if (dss_has_feature(FEAT_MGR_LCD2))
3017 PIS(SYNC_LOST2);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003018#undef PIS
3019
3020 printk("\n");
3021}
3022#endif
3023
3024/* Called from dss.c. Note that we don't touch clocks here,
3025 * but we presume they are on because we got an IRQ. However,
3026 * an irq handler may turn the clocks off, so we may not have
3027 * clock later in the function. */
archit tanejaaffe3602011-02-23 08:41:03 +00003028static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003029{
3030 int i;
archit tanejaaffe3602011-02-23 08:41:03 +00003031 u32 irqstatus, irqenable;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003032 u32 handledirqs = 0;
3033 u32 unhandled_errors;
3034 struct omap_dispc_isr_data *isr_data;
3035 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
3036
3037 spin_lock(&dispc.irq_lock);
3038
3039 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
archit tanejaaffe3602011-02-23 08:41:03 +00003040 irqenable = dispc_read_reg(DISPC_IRQENABLE);
3041
3042 /* IRQ is not for us */
3043 if (!(irqstatus & irqenable)) {
3044 spin_unlock(&dispc.irq_lock);
3045 return IRQ_NONE;
3046 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003047
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003048#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3049 spin_lock(&dispc.irq_stats_lock);
3050 dispc.irq_stats.irq_count++;
3051 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
3052 spin_unlock(&dispc.irq_stats_lock);
3053#endif
3054
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003055#ifdef DEBUG
3056 if (dss_debug)
3057 print_irq_status(irqstatus);
3058#endif
3059 /* Ack the interrupt. Do it here before clocks are possibly turned
3060 * off */
3061 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
3062 /* flush posted write */
3063 dispc_read_reg(DISPC_IRQSTATUS);
3064
3065 /* make a copy and unlock, so that isrs can unregister
3066 * themselves */
3067 memcpy(registered_isr, dispc.registered_isr,
3068 sizeof(registered_isr));
3069
3070 spin_unlock(&dispc.irq_lock);
3071
3072 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3073 isr_data = &registered_isr[i];
3074
3075 if (!isr_data->isr)
3076 continue;
3077
3078 if (isr_data->mask & irqstatus) {
3079 isr_data->isr(isr_data->arg, irqstatus);
3080 handledirqs |= isr_data->mask;
3081 }
3082 }
3083
3084 spin_lock(&dispc.irq_lock);
3085
3086 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3087
3088 if (unhandled_errors) {
3089 dispc.error_irqs |= unhandled_errors;
3090
3091 dispc.irq_error_mask &= ~unhandled_errors;
3092 _omap_dispc_set_irqs();
3093
3094 schedule_work(&dispc.error_work);
3095 }
3096
3097 spin_unlock(&dispc.irq_lock);
archit tanejaaffe3602011-02-23 08:41:03 +00003098
3099 return IRQ_HANDLED;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003100}
3101
3102static void dispc_error_worker(struct work_struct *work)
3103{
3104 int i;
3105 u32 errors;
3106 unsigned long flags;
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003107 static const unsigned fifo_underflow_bits[] = {
3108 DISPC_IRQ_GFX_FIFO_UNDERFLOW,
3109 DISPC_IRQ_VID1_FIFO_UNDERFLOW,
3110 DISPC_IRQ_VID2_FIFO_UNDERFLOW,
Archit Tanejab8c095b2011-09-13 18:20:33 +05303111 DISPC_IRQ_VID3_FIFO_UNDERFLOW,
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003112 };
3113
3114 static const unsigned sync_lost_bits[] = {
3115 DISPC_IRQ_SYNC_LOST,
3116 DISPC_IRQ_SYNC_LOST_DIGIT,
3117 DISPC_IRQ_SYNC_LOST2,
3118 };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003119
3120 spin_lock_irqsave(&dispc.irq_lock, flags);
3121 errors = dispc.error_irqs;
3122 dispc.error_irqs = 0;
3123 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3124
Dima Zavin13eae1f2011-06-27 10:31:05 -07003125 dispc_runtime_get();
3126
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003127 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3128 struct omap_overlay *ovl;
3129 unsigned bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003130
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003131 ovl = omap_dss_get_overlay(i);
3132 bit = fifo_underflow_bits[i];
3133
3134 if (bit & errors) {
3135 DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
3136 ovl->name);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03003137 dispc_ovl_enable(ovl->id, false);
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003138 dispc_mgr_go(ovl->manager->id);
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003139 mdelay(50);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003140 }
3141 }
3142
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003143 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3144 struct omap_overlay_manager *mgr;
3145 unsigned bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003146
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003147 mgr = omap_dss_get_overlay_manager(i);
3148 bit = sync_lost_bits[i];
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003149
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003150 if (bit & errors) {
3151 struct omap_dss_device *dssdev = mgr->device;
3152 bool enable;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003153
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003154 DSSERR("SYNC_LOST on channel %s, restarting the output "
3155 "with video overlays disabled\n",
3156 mgr->name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003157
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003158 enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
3159 dssdev->driver->disable(dssdev);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003160
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003161 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3162 struct omap_overlay *ovl;
3163 ovl = omap_dss_get_overlay(i);
3164
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003165 if (ovl->id != OMAP_DSS_GFX &&
3166 ovl->manager == mgr)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03003167 dispc_ovl_enable(ovl->id, false);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003168 }
3169
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003170 dispc_mgr_go(mgr->id);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003171 mdelay(50);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003172
Sumit Semwal2a205f32010-12-02 11:27:12 +00003173 if (enable)
3174 dssdev->driver->enable(dssdev);
3175 }
3176 }
3177
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003178 if (errors & DISPC_IRQ_OCP_ERR) {
3179 DSSERR("OCP_ERR\n");
3180 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3181 struct omap_overlay_manager *mgr;
3182 mgr = omap_dss_get_overlay_manager(i);
Rob Clark00f17e42011-12-11 14:02:27 -06003183 if (mgr->device && mgr->device->driver)
3184 mgr->device->driver->disable(mgr->device);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003185 }
3186 }
3187
3188 spin_lock_irqsave(&dispc.irq_lock, flags);
3189 dispc.irq_error_mask |= errors;
3190 _omap_dispc_set_irqs();
3191 spin_unlock_irqrestore(&dispc.irq_lock, flags);
Dima Zavin13eae1f2011-06-27 10:31:05 -07003192
3193 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003194}
3195
3196int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3197{
3198 void dispc_irq_wait_handler(void *data, u32 mask)
3199 {
3200 complete((struct completion *)data);
3201 }
3202
3203 int r;
3204 DECLARE_COMPLETION_ONSTACK(completion);
3205
3206 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3207 irqmask);
3208
3209 if (r)
3210 return r;
3211
3212 timeout = wait_for_completion_timeout(&completion, timeout);
3213
3214 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3215
3216 if (timeout == 0)
3217 return -ETIMEDOUT;
3218
3219 if (timeout == -ERESTARTSYS)
3220 return -ERESTARTSYS;
3221
3222 return 0;
3223}
3224
3225int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3226 unsigned long timeout)
3227{
3228 void dispc_irq_wait_handler(void *data, u32 mask)
3229 {
3230 complete((struct completion *)data);
3231 }
3232
3233 int r;
3234 DECLARE_COMPLETION_ONSTACK(completion);
3235
3236 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3237 irqmask);
3238
3239 if (r)
3240 return r;
3241
3242 timeout = wait_for_completion_interruptible_timeout(&completion,
3243 timeout);
3244
3245 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3246
3247 if (timeout == 0)
3248 return -ETIMEDOUT;
3249
3250 if (timeout == -ERESTARTSYS)
3251 return -ERESTARTSYS;
3252
3253 return 0;
3254}
3255
3256#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
3257void dispc_fake_vsync_irq(void)
3258{
3259 u32 irqstatus = DISPC_IRQ_VSYNC;
3260 int i;
3261
Tomi Valkeinenab83b142010-06-09 15:31:01 +03003262 WARN_ON(!in_interrupt());
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003263
3264 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3265 struct omap_dispc_isr_data *isr_data;
3266 isr_data = &dispc.registered_isr[i];
3267
3268 if (!isr_data->isr)
3269 continue;
3270
3271 if (isr_data->mask & irqstatus)
3272 isr_data->isr(isr_data->arg, irqstatus);
3273 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003274}
3275#endif
3276
3277static void _omap_dispc_initialize_irq(void)
3278{
3279 unsigned long flags;
3280
3281 spin_lock_irqsave(&dispc.irq_lock, flags);
3282
3283 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3284
3285 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
Sumit Semwal2a205f32010-12-02 11:27:12 +00003286 if (dss_has_feature(FEAT_MGR_LCD2))
3287 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
Archit Tanejab8c095b2011-09-13 18:20:33 +05303288 if (dss_feat_get_num_ovls() > 3)
3289 dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003290
3291 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3292 * so clear it */
3293 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3294
3295 _omap_dispc_set_irqs();
3296
3297 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3298}
3299
3300void dispc_enable_sidle(void)
3301{
3302 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3303}
3304
3305void dispc_disable_sidle(void)
3306{
3307 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3308}
3309
3310static void _omap_dispc_initial_config(void)
3311{
3312 u32 l;
3313
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003314 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3315 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3316 l = dispc_read_reg(DISPC_DIVISOR);
3317 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3318 l = FLD_MOD(l, 1, 0, 0);
3319 l = FLD_MOD(l, 1, 23, 16);
3320 dispc_write_reg(DISPC_DIVISOR, l);
3321 }
3322
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003323 /* FUNCGATED */
Archit Taneja6ced40b2010-12-02 11:27:13 +00003324 if (dss_has_feature(FEAT_FUNCGATED))
3325 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003326
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003327 _dispc_setup_color_conv_coef();
3328
3329 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3330
3331 dispc_read_plane_fifo_sizes();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003332
3333 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05303334
3335 dispc_ovl_enable_zorder_planes();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003336}
3337
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003338/* DISPC HW IP initialisation */
3339static int omap_dispchw_probe(struct platform_device *pdev)
3340{
3341 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00003342 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003343 struct resource *dispc_mem;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003344 struct clk *clk;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003345
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003346 dispc.pdev = pdev;
3347
3348 spin_lock_init(&dispc.irq_lock);
3349
3350#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3351 spin_lock_init(&dispc.irq_stats_lock);
3352 dispc.irq_stats.last_reset = jiffies;
3353#endif
3354
3355 INIT_WORK(&dispc.error_work, dispc_error_worker);
3356
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003357 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3358 if (!dispc_mem) {
3359 DSSERR("can't get IORESOURCE_MEM DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003360 return -EINVAL;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003361 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003362
Julia Lawall6e2a14d2012-01-24 14:00:45 +01003363 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3364 resource_size(dispc_mem));
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003365 if (!dispc.base) {
3366 DSSERR("can't ioremap DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003367 return -ENOMEM;
archit tanejaaffe3602011-02-23 08:41:03 +00003368 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003369
archit tanejaaffe3602011-02-23 08:41:03 +00003370 dispc.irq = platform_get_irq(dispc.pdev, 0);
3371 if (dispc.irq < 0) {
3372 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003373 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00003374 }
3375
Julia Lawall6e2a14d2012-01-24 14:00:45 +01003376 r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
3377 IRQF_SHARED, "OMAP DISPC", dispc.pdev);
archit tanejaaffe3602011-02-23 08:41:03 +00003378 if (r < 0) {
3379 DSSERR("request_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003380 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003381 }
3382
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003383 clk = clk_get(&pdev->dev, "fck");
3384 if (IS_ERR(clk)) {
3385 DSSERR("can't get fck\n");
3386 r = PTR_ERR(clk);
3387 return r;
3388 }
3389
3390 dispc.dss_clk = clk;
3391
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003392 pm_runtime_enable(&pdev->dev);
3393
3394 r = dispc_runtime_get();
3395 if (r)
3396 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003397
3398 _omap_dispc_initial_config();
3399
3400 _omap_dispc_initialize_irq();
3401
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003402 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00003403 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003404 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3405
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003406 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003407
3408 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003409
3410err_runtime_get:
3411 pm_runtime_disable(&pdev->dev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003412 clk_put(dispc.dss_clk);
archit tanejaaffe3602011-02-23 08:41:03 +00003413 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003414}
3415
3416static int omap_dispchw_remove(struct platform_device *pdev)
3417{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003418 pm_runtime_disable(&pdev->dev);
3419
3420 clk_put(dispc.dss_clk);
3421
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003422 return 0;
3423}
3424
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003425static int dispc_runtime_suspend(struct device *dev)
3426{
3427 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003428 dss_runtime_put();
3429
3430 return 0;
3431}
3432
3433static int dispc_runtime_resume(struct device *dev)
3434{
3435 int r;
3436
3437 r = dss_runtime_get();
3438 if (r < 0)
3439 return r;
3440
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +03003441 dispc_restore_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003442
3443 return 0;
3444}
3445
3446static const struct dev_pm_ops dispc_pm_ops = {
3447 .runtime_suspend = dispc_runtime_suspend,
3448 .runtime_resume = dispc_runtime_resume,
3449};
3450
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003451static struct platform_driver omap_dispchw_driver = {
3452 .probe = omap_dispchw_probe,
3453 .remove = omap_dispchw_remove,
3454 .driver = {
3455 .name = "omapdss_dispc",
3456 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003457 .pm = &dispc_pm_ops,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003458 },
3459};
3460
3461int dispc_init_platform_driver(void)
3462{
3463 return platform_driver_register(&omap_dispchw_driver);
3464}
3465
3466void dispc_uninit_platform_driver(void)
3467{
3468 return platform_driver_unregister(&omap_dispchw_driver);
3469}