blob: 05def42e528b4790d9cb3a4a4f06487ff8ffbec6 [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 Valkeinen33366d02012-09-28 13:54:35 +030039#include <linux/sizes.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020040
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030041#include <video/omapdss.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020042
43#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053044#include "dss_features.h"
Archit Taneja9b372c22011-05-06 11:45:49 +053045#include "dispc.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020046
47/* DISPC */
Sumit Semwal8613b002010-12-02 11:27:09 +000048#define DISPC_SZ_REGS SZ_4K
Tomi Valkeinen80c39712009-11-12 11:41:42 +020049
Tomi Valkeinen80c39712009-11-12 11:41:42 +020050#define DISPC_IRQ_MASK_ERROR (DISPC_IRQ_GFX_FIFO_UNDERFLOW | \
51 DISPC_IRQ_OCP_ERR | \
52 DISPC_IRQ_VID1_FIFO_UNDERFLOW | \
53 DISPC_IRQ_VID2_FIFO_UNDERFLOW | \
54 DISPC_IRQ_SYNC_LOST | \
55 DISPC_IRQ_SYNC_LOST_DIGIT)
56
57#define DISPC_MAX_NR_ISRS 8
58
59struct omap_dispc_isr_data {
60 omap_dispc_isr_t isr;
61 void *arg;
62 u32 mask;
63};
64
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030065enum omap_burst_size {
66 BURST_SIZE_X2 = 0,
67 BURST_SIZE_X4 = 1,
68 BURST_SIZE_X8 = 2,
69};
70
Tomi Valkeinen80c39712009-11-12 11:41:42 +020071#define REG_GET(idx, start, end) \
72 FLD_GET(dispc_read_reg(idx), start, end)
73
74#define REG_FLD_MOD(idx, val, start, end) \
75 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
76
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +020077struct dispc_irq_stats {
78 unsigned long last_reset;
79 unsigned irq_count;
80 unsigned irqs[32];
81};
82
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053083struct dispc_features {
84 u8 sw_start;
85 u8 fp_start;
86 u8 bp_start;
87 u16 sw_max;
88 u16 vp_max;
89 u16 hp_max;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +053090 int (*calc_scaling) (enum omap_plane plane,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053091 const struct omap_video_timings *mgr_timings,
92 u16 width, u16 height, u16 out_width, u16 out_height,
93 enum omap_color_mode color_mode, bool *five_taps,
94 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +053095 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +053096 unsigned long (*calc_core_clk) (enum omap_plane plane,
Archit Taneja8ba85302012-09-26 17:00:37 +053097 u16 width, u16 height, u16 out_width, u16 out_height,
98 bool mem_to_mem);
Tomi Valkeinen42a69612012-08-22 16:56:57 +030099 u8 num_fifos;
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +0300100
101 /* swap GFX & WB fifos */
102 bool gfx_fifo_workaround:1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530103};
104
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300105#define DISPC_MAX_NR_FIFOS 5
106
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200107static struct {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +0000108 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200109 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300110
111 int ctx_loss_cnt;
112
archit tanejaaffe3602011-02-23 08:41:03 +0000113 int irq;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300114 struct clk *dss_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200115
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300116 u32 fifo_size[DISPC_MAX_NR_FIFOS];
117 /* maps which plane is using a fifo. fifo-id -> plane-id */
118 int fifo_assignment[DISPC_MAX_NR_FIFOS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200119
120 spinlock_t irq_lock;
121 u32 irq_error_mask;
122 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
123 u32 error_irqs;
124 struct work_struct error_work;
125
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300126 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200127 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200128
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530129 const struct dispc_features *feat;
130
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200131#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
132 spinlock_t irq_stats_lock;
133 struct dispc_irq_stats irq_stats;
134#endif
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200135} dispc;
136
Amber Jain0d66cbb2011-05-19 19:47:54 +0530137enum omap_color_component {
138 /* used for all color formats for OMAP3 and earlier
139 * and for RGB and Y color component on OMAP4
140 */
141 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
142 /* used for UV component for
143 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
144 * color formats on OMAP4
145 */
146 DISPC_COLOR_COMPONENT_UV = 1 << 1,
147};
148
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530149enum mgr_reg_fields {
150 DISPC_MGR_FLD_ENABLE,
151 DISPC_MGR_FLD_STNTFT,
152 DISPC_MGR_FLD_GO,
153 DISPC_MGR_FLD_TFTDATALINES,
154 DISPC_MGR_FLD_STALLMODE,
155 DISPC_MGR_FLD_TCKENABLE,
156 DISPC_MGR_FLD_TCKSELECTION,
157 DISPC_MGR_FLD_CPR,
158 DISPC_MGR_FLD_FIFOHANDCHECK,
159 /* used to maintain a count of the above fields */
160 DISPC_MGR_FLD_NUM,
161};
162
163static const struct {
164 const char *name;
165 u32 vsync_irq;
166 u32 framedone_irq;
167 u32 sync_lost_irq;
168 struct reg_field reg_desc[DISPC_MGR_FLD_NUM];
169} mgr_desc[] = {
170 [OMAP_DSS_CHANNEL_LCD] = {
171 .name = "LCD",
172 .vsync_irq = DISPC_IRQ_VSYNC,
173 .framedone_irq = DISPC_IRQ_FRAMEDONE,
174 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
175 .reg_desc = {
176 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
177 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
178 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
179 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
180 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
181 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
182 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
183 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
184 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
185 },
186 },
187 [OMAP_DSS_CHANNEL_DIGIT] = {
188 .name = "DIGIT",
189 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
190 .framedone_irq = 0,
191 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
192 .reg_desc = {
193 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
194 [DISPC_MGR_FLD_STNTFT] = { },
195 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
196 [DISPC_MGR_FLD_TFTDATALINES] = { },
197 [DISPC_MGR_FLD_STALLMODE] = { },
198 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
199 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
200 [DISPC_MGR_FLD_CPR] = { },
201 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
202 },
203 },
204 [OMAP_DSS_CHANNEL_LCD2] = {
205 .name = "LCD2",
206 .vsync_irq = DISPC_IRQ_VSYNC2,
207 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
208 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
209 .reg_desc = {
210 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
211 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
212 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
213 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
214 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
215 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
216 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
217 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
218 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
219 },
220 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530221 [OMAP_DSS_CHANNEL_LCD3] = {
222 .name = "LCD3",
223 .vsync_irq = DISPC_IRQ_VSYNC3,
224 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
225 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
226 .reg_desc = {
227 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
228 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
229 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
230 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
231 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
232 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
233 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
234 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
235 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
236 },
237 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530238};
239
Archit Taneja6e5264b2012-09-11 12:04:47 +0530240struct color_conv_coef {
241 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
242 int full_range;
243};
244
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200245static void _omap_dispc_set_irqs(void);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +0530246static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
247static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200248
Archit Taneja55978cc2011-05-06 11:45:51 +0530249static inline void dispc_write_reg(const u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200250{
Archit Taneja55978cc2011-05-06 11:45:51 +0530251 __raw_writel(val, dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200252}
253
Archit Taneja55978cc2011-05-06 11:45:51 +0530254static inline u32 dispc_read_reg(const u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200255{
Archit Taneja55978cc2011-05-06 11:45:51 +0530256 return __raw_readl(dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200257}
258
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530259static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
260{
261 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
262 return REG_GET(rfld.reg, rfld.high, rfld.low);
263}
264
265static void mgr_fld_write(enum omap_channel channel,
266 enum mgr_reg_fields regfld, int val) {
267 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
268 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
269}
270
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200271#define SR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530272 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200273#define RR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530274 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200275
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300276static void dispc_save_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200277{
Archit Tanejac6104b82011-08-05 19:06:02 +0530278 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200279
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300280 DSSDBG("dispc_save_context\n");
281
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200282 SR(IRQENABLE);
283 SR(CONTROL);
284 SR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200285 SR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530286 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
287 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300288 SR(GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000289 if (dss_has_feature(FEAT_MGR_LCD2)) {
290 SR(CONTROL2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000291 SR(CONFIG2);
292 }
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530293 if (dss_has_feature(FEAT_MGR_LCD3)) {
294 SR(CONTROL3);
295 SR(CONFIG3);
296 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200297
Archit Tanejac6104b82011-08-05 19:06:02 +0530298 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
299 SR(DEFAULT_COLOR(i));
300 SR(TRANS_COLOR(i));
301 SR(SIZE_MGR(i));
302 if (i == OMAP_DSS_CHANNEL_DIGIT)
303 continue;
304 SR(TIMING_H(i));
305 SR(TIMING_V(i));
306 SR(POL_FREQ(i));
307 SR(DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200308
Archit Tanejac6104b82011-08-05 19:06:02 +0530309 SR(DATA_CYCLE1(i));
310 SR(DATA_CYCLE2(i));
311 SR(DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200312
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300313 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530314 SR(CPR_COEF_R(i));
315 SR(CPR_COEF_G(i));
316 SR(CPR_COEF_B(i));
317 }
318 }
319
320 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
321 SR(OVL_BA0(i));
322 SR(OVL_BA1(i));
323 SR(OVL_POSITION(i));
324 SR(OVL_SIZE(i));
325 SR(OVL_ATTRIBUTES(i));
326 SR(OVL_FIFO_THRESHOLD(i));
327 SR(OVL_ROW_INC(i));
328 SR(OVL_PIXEL_INC(i));
329 if (dss_has_feature(FEAT_PRELOAD))
330 SR(OVL_PRELOAD(i));
331 if (i == OMAP_DSS_GFX) {
332 SR(OVL_WINDOW_SKIP(i));
333 SR(OVL_TABLE_BA(i));
334 continue;
335 }
336 SR(OVL_FIR(i));
337 SR(OVL_PICTURE_SIZE(i));
338 SR(OVL_ACCU0(i));
339 SR(OVL_ACCU1(i));
340
341 for (j = 0; j < 8; j++)
342 SR(OVL_FIR_COEF_H(i, j));
343
344 for (j = 0; j < 8; j++)
345 SR(OVL_FIR_COEF_HV(i, j));
346
347 for (j = 0; j < 5; j++)
348 SR(OVL_CONV_COEF(i, j));
349
350 if (dss_has_feature(FEAT_FIR_COEF_V)) {
351 for (j = 0; j < 8; j++)
352 SR(OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300353 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000354
Archit Tanejac6104b82011-08-05 19:06:02 +0530355 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
356 SR(OVL_BA0_UV(i));
357 SR(OVL_BA1_UV(i));
358 SR(OVL_FIR2(i));
359 SR(OVL_ACCU2_0(i));
360 SR(OVL_ACCU2_1(i));
361
362 for (j = 0; j < 8; j++)
363 SR(OVL_FIR_COEF_H2(i, j));
364
365 for (j = 0; j < 8; j++)
366 SR(OVL_FIR_COEF_HV2(i, j));
367
368 for (j = 0; j < 8; j++)
369 SR(OVL_FIR_COEF_V2(i, j));
370 }
371 if (dss_has_feature(FEAT_ATTR2))
372 SR(OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000373 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200374
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600375 if (dss_has_feature(FEAT_CORE_CLK_DIV))
376 SR(DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300377
Tomi Valkeinen00928ea2012-02-20 11:50:06 +0200378 dispc.ctx_loss_cnt = dss_get_ctx_loss_count(&dispc.pdev->dev);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300379 dispc.ctx_valid = true;
380
381 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200382}
383
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300384static void dispc_restore_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200385{
Archit Tanejac6104b82011-08-05 19:06:02 +0530386 int i, j, ctx;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300387
388 DSSDBG("dispc_restore_context\n");
389
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300390 if (!dispc.ctx_valid)
391 return;
392
Tomi Valkeinen00928ea2012-02-20 11:50:06 +0200393 ctx = dss_get_ctx_loss_count(&dispc.pdev->dev);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300394
395 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
396 return;
397
398 DSSDBG("ctx_loss_count: saved %d, current %d\n",
399 dispc.ctx_loss_cnt, ctx);
400
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200401 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200402 /*RR(CONTROL);*/
403 RR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200404 RR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530405 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
406 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300407 RR(GLOBAL_ALPHA);
Archit Tanejac6104b82011-08-05 19:06:02 +0530408 if (dss_has_feature(FEAT_MGR_LCD2))
Sumit Semwal2a205f32010-12-02 11:27:12 +0000409 RR(CONFIG2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530410 if (dss_has_feature(FEAT_MGR_LCD3))
411 RR(CONFIG3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200412
Archit Tanejac6104b82011-08-05 19:06:02 +0530413 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
414 RR(DEFAULT_COLOR(i));
415 RR(TRANS_COLOR(i));
416 RR(SIZE_MGR(i));
417 if (i == OMAP_DSS_CHANNEL_DIGIT)
418 continue;
419 RR(TIMING_H(i));
420 RR(TIMING_V(i));
421 RR(POL_FREQ(i));
422 RR(DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530423
Archit Tanejac6104b82011-08-05 19:06:02 +0530424 RR(DATA_CYCLE1(i));
425 RR(DATA_CYCLE2(i));
426 RR(DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000427
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300428 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530429 RR(CPR_COEF_R(i));
430 RR(CPR_COEF_G(i));
431 RR(CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300432 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000433 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200434
Archit Tanejac6104b82011-08-05 19:06:02 +0530435 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
436 RR(OVL_BA0(i));
437 RR(OVL_BA1(i));
438 RR(OVL_POSITION(i));
439 RR(OVL_SIZE(i));
440 RR(OVL_ATTRIBUTES(i));
441 RR(OVL_FIFO_THRESHOLD(i));
442 RR(OVL_ROW_INC(i));
443 RR(OVL_PIXEL_INC(i));
444 if (dss_has_feature(FEAT_PRELOAD))
445 RR(OVL_PRELOAD(i));
446 if (i == OMAP_DSS_GFX) {
447 RR(OVL_WINDOW_SKIP(i));
448 RR(OVL_TABLE_BA(i));
449 continue;
450 }
451 RR(OVL_FIR(i));
452 RR(OVL_PICTURE_SIZE(i));
453 RR(OVL_ACCU0(i));
454 RR(OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200455
Archit Tanejac6104b82011-08-05 19:06:02 +0530456 for (j = 0; j < 8; j++)
457 RR(OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200458
Archit Tanejac6104b82011-08-05 19:06:02 +0530459 for (j = 0; j < 8; j++)
460 RR(OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200461
Archit Tanejac6104b82011-08-05 19:06:02 +0530462 for (j = 0; j < 5; j++)
463 RR(OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200464
Archit Tanejac6104b82011-08-05 19:06:02 +0530465 if (dss_has_feature(FEAT_FIR_COEF_V)) {
466 for (j = 0; j < 8; j++)
467 RR(OVL_FIR_COEF_V(i, j));
468 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200469
Archit Tanejac6104b82011-08-05 19:06:02 +0530470 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
471 RR(OVL_BA0_UV(i));
472 RR(OVL_BA1_UV(i));
473 RR(OVL_FIR2(i));
474 RR(OVL_ACCU2_0(i));
475 RR(OVL_ACCU2_1(i));
476
477 for (j = 0; j < 8; j++)
478 RR(OVL_FIR_COEF_H2(i, j));
479
480 for (j = 0; j < 8; j++)
481 RR(OVL_FIR_COEF_HV2(i, j));
482
483 for (j = 0; j < 8; j++)
484 RR(OVL_FIR_COEF_V2(i, j));
485 }
486 if (dss_has_feature(FEAT_ATTR2))
487 RR(OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300488 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200489
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600490 if (dss_has_feature(FEAT_CORE_CLK_DIV))
491 RR(DIVISOR);
492
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200493 /* enable last, because LCD & DIGIT enable are here */
494 RR(CONTROL);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000495 if (dss_has_feature(FEAT_MGR_LCD2))
496 RR(CONTROL2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530497 if (dss_has_feature(FEAT_MGR_LCD3))
498 RR(CONTROL3);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200499 /* clear spurious SYNC_LOST_DIGIT interrupts */
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +0300500 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200501
502 /*
503 * enable last so IRQs won't trigger before
504 * the context is fully restored
505 */
506 RR(IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300507
508 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200509}
510
511#undef SR
512#undef RR
513
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300514int dispc_runtime_get(void)
515{
516 int r;
517
518 DSSDBG("dispc_runtime_get\n");
519
520 r = pm_runtime_get_sync(&dispc.pdev->dev);
521 WARN_ON(r < 0);
522 return r < 0 ? r : 0;
523}
524
525void dispc_runtime_put(void)
526{
527 int r;
528
529 DSSDBG("dispc_runtime_put\n");
530
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200531 r = pm_runtime_put_sync(&dispc.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300532 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300533}
534
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200535u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
536{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530537 return mgr_desc[channel].vsync_irq;
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200538}
539
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200540u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
541{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530542 return mgr_desc[channel].framedone_irq;
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200543}
544
Tomi Valkeinencb699202012-10-17 10:38:52 +0300545u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
546{
547 return mgr_desc[channel].sync_lost_irq;
548}
549
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530550u32 dispc_wb_get_framedone_irq(void)
551{
552 return DISPC_IRQ_FRAMEDONEWB;
553}
554
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300555bool dispc_mgr_go_busy(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200556{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530557 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200558}
559
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300560void dispc_mgr_go(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200561{
Sumit Semwal2a205f32010-12-02 11:27:12 +0000562 bool enable_bit, go_bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200563
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200564 /* if the channel is not enabled, we don't need GO */
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530565 enable_bit = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE) == 1;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000566
567 if (!enable_bit)
Tomi Valkeinene6d80f92011-05-19 14:12:26 +0300568 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200569
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530570 go_bit = mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000571
572 if (go_bit) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200573 DSSERR("GO bit not down for channel %d\n", channel);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +0300574 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200575 }
576
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530577 DSSDBG("GO %s\n", mgr_desc[channel].name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200578
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530579 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200580}
581
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530582bool dispc_wb_go_busy(void)
583{
584 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
585}
586
587void dispc_wb_go(void)
588{
589 enum omap_plane plane = OMAP_DSS_WB;
590 bool enable, go;
591
592 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
593
594 if (!enable)
595 return;
596
597 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
598 if (go) {
599 DSSERR("GO bit not down for WB\n");
600 return;
601 }
602
603 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
604}
605
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300606static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200607{
Archit Taneja9b372c22011-05-06 11:45:49 +0530608 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200609}
610
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300611static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200612{
Archit Taneja9b372c22011-05-06 11:45:49 +0530613 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200614}
615
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300616static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200617{
Archit Taneja9b372c22011-05-06 11:45:49 +0530618 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200619}
620
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300621static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530622{
623 BUG_ON(plane == OMAP_DSS_GFX);
624
625 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
626}
627
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300628static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
629 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530630{
631 BUG_ON(plane == OMAP_DSS_GFX);
632
633 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
634}
635
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300636static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530637{
638 BUG_ON(plane == OMAP_DSS_GFX);
639
640 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
641}
642
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530643static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
644 int fir_vinc, int five_taps,
645 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200646{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530647 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200648 int i;
649
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530650 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
651 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200652
653 for (i = 0; i < 8; i++) {
654 u32 h, hv;
655
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530656 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
657 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
658 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
659 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
660 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
661 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
662 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
663 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200664
Amber Jain0d66cbb2011-05-19 19:47:54 +0530665 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300666 dispc_ovl_write_firh_reg(plane, i, h);
667 dispc_ovl_write_firhv_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530668 } else {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300669 dispc_ovl_write_firh2_reg(plane, i, h);
670 dispc_ovl_write_firhv2_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530671 }
672
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200673 }
674
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200675 if (five_taps) {
676 for (i = 0; i < 8; i++) {
677 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530678 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
679 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530680 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300681 dispc_ovl_write_firv_reg(plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530682 else
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300683 dispc_ovl_write_firv2_reg(plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200684 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200685 }
686}
687
Archit Taneja6e5264b2012-09-11 12:04:47 +0530688
689static void dispc_ovl_write_color_conv_coef(enum omap_plane plane,
690 const struct color_conv_coef *ct)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200691{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200692#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
693
Archit Taneja6e5264b2012-09-11 12:04:47 +0530694 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
695 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
696 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
697 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
698 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200699
Archit Taneja6e5264b2012-09-11 12:04:47 +0530700 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200701
702#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200703}
704
Archit Taneja6e5264b2012-09-11 12:04:47 +0530705static void dispc_setup_color_conv_coef(void)
706{
707 int i;
708 int num_ovl = dss_feat_get_num_ovls();
709 int num_wb = dss_feat_get_num_wbs();
710 const struct color_conv_coef ctbl_bt601_5_ovl = {
711 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
712 };
713 const struct color_conv_coef ctbl_bt601_5_wb = {
714 66, 112, -38, 129, -94, -74, 25, -18, 112, 0,
715 };
716
717 for (i = 1; i < num_ovl; i++)
718 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
719
720 for (; i < num_wb; i++)
721 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_wb);
722}
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200723
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300724static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200725{
Archit Taneja9b372c22011-05-06 11:45:49 +0530726 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200727}
728
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300729static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200730{
Archit Taneja9b372c22011-05-06 11:45:49 +0530731 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200732}
733
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300734static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530735{
736 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
737}
738
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300739static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530740{
741 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
742}
743
Archit Tanejad79db852012-09-22 12:30:17 +0530744static void dispc_ovl_set_pos(enum omap_plane plane,
745 enum omap_overlay_caps caps, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200746{
Archit Tanejad79db852012-09-22 12:30:17 +0530747 u32 val;
748
749 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
750 return;
751
752 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530753
754 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200755}
756
Archit Taneja78b687f2012-09-21 14:51:49 +0530757static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
758 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200759{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200760 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530761
Archit Taneja36d87d92012-07-28 22:59:03 +0530762 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
Archit Taneja9b372c22011-05-06 11:45:49 +0530763 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
764 else
765 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200766}
767
Archit Taneja78b687f2012-09-21 14:51:49 +0530768static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
769 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200770{
771 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200772
773 BUG_ON(plane == OMAP_DSS_GFX);
774
775 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530776
Archit Taneja36d87d92012-07-28 22:59:03 +0530777 if (plane == OMAP_DSS_WB)
778 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
779 else
780 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200781}
782
Archit Taneja5b54ed32012-09-26 16:55:27 +0530783static void dispc_ovl_set_zorder(enum omap_plane plane,
784 enum omap_overlay_caps caps, u8 zorder)
Archit Taneja54128702011-09-08 11:29:17 +0530785{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530786 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
Archit Taneja54128702011-09-08 11:29:17 +0530787 return;
788
789 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
790}
791
792static void dispc_ovl_enable_zorder_planes(void)
793{
794 int i;
795
796 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
797 return;
798
799 for (i = 0; i < dss_feat_get_num_ovls(); i++)
800 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
801}
802
Archit Taneja5b54ed32012-09-26 16:55:27 +0530803static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
804 enum omap_overlay_caps caps, bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100805{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530806 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100807 return;
808
Archit Taneja9b372c22011-05-06 11:45:49 +0530809 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100810}
811
Archit Taneja5b54ed32012-09-26 16:55:27 +0530812static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
813 enum omap_overlay_caps caps, u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200814{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530815 static const unsigned shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300816 int shift;
817
Archit Taneja5b54ed32012-09-26 16:55:27 +0530818 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100819 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530820
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300821 shift = shifts[plane];
822 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200823}
824
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300825static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200826{
Archit Taneja9b372c22011-05-06 11:45:49 +0530827 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200828}
829
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300830static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200831{
Archit Taneja9b372c22011-05-06 11:45:49 +0530832 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200833}
834
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300835static void dispc_ovl_set_color_mode(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200836 enum omap_color_mode color_mode)
837{
838 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +0530839 if (plane != OMAP_DSS_GFX) {
840 switch (color_mode) {
841 case OMAP_DSS_COLOR_NV12:
842 m = 0x0; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530843 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530844 m = 0x1; break;
845 case OMAP_DSS_COLOR_RGBA16:
846 m = 0x2; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530847 case OMAP_DSS_COLOR_RGB12U:
Amber Jainf20e4222011-05-19 19:47:50 +0530848 m = 0x4; break;
849 case OMAP_DSS_COLOR_ARGB16:
850 m = 0x5; break;
851 case OMAP_DSS_COLOR_RGB16:
852 m = 0x6; break;
853 case OMAP_DSS_COLOR_ARGB16_1555:
854 m = 0x7; break;
855 case OMAP_DSS_COLOR_RGB24U:
856 m = 0x8; break;
857 case OMAP_DSS_COLOR_RGB24P:
858 m = 0x9; break;
859 case OMAP_DSS_COLOR_YUV2:
860 m = 0xa; break;
861 case OMAP_DSS_COLOR_UYVY:
862 m = 0xb; break;
863 case OMAP_DSS_COLOR_ARGB32:
864 m = 0xc; break;
865 case OMAP_DSS_COLOR_RGBA32:
866 m = 0xd; break;
867 case OMAP_DSS_COLOR_RGBX32:
868 m = 0xe; break;
869 case OMAP_DSS_COLOR_XRGB16_1555:
870 m = 0xf; break;
871 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300872 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530873 }
874 } else {
875 switch (color_mode) {
876 case OMAP_DSS_COLOR_CLUT1:
877 m = 0x0; break;
878 case OMAP_DSS_COLOR_CLUT2:
879 m = 0x1; break;
880 case OMAP_DSS_COLOR_CLUT4:
881 m = 0x2; break;
882 case OMAP_DSS_COLOR_CLUT8:
883 m = 0x3; break;
884 case OMAP_DSS_COLOR_RGB12U:
885 m = 0x4; break;
886 case OMAP_DSS_COLOR_ARGB16:
887 m = 0x5; break;
888 case OMAP_DSS_COLOR_RGB16:
889 m = 0x6; break;
890 case OMAP_DSS_COLOR_ARGB16_1555:
891 m = 0x7; break;
892 case OMAP_DSS_COLOR_RGB24U:
893 m = 0x8; break;
894 case OMAP_DSS_COLOR_RGB24P:
895 m = 0x9; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530896 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530897 m = 0xa; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530898 case OMAP_DSS_COLOR_RGBA16:
Amber Jainf20e4222011-05-19 19:47:50 +0530899 m = 0xb; break;
900 case OMAP_DSS_COLOR_ARGB32:
901 m = 0xc; break;
902 case OMAP_DSS_COLOR_RGBA32:
903 m = 0xd; break;
904 case OMAP_DSS_COLOR_RGBX32:
905 m = 0xe; break;
906 case OMAP_DSS_COLOR_XRGB16_1555:
907 m = 0xf; break;
908 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300909 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530910 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200911 }
912
Archit Taneja9b372c22011-05-06 11:45:49 +0530913 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200914}
915
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530916static void dispc_ovl_configure_burst_type(enum omap_plane plane,
917 enum omap_dss_rotation_type rotation_type)
918{
919 if (dss_has_feature(FEAT_BURST_2D) == 0)
920 return;
921
922 if (rotation_type == OMAP_DSS_ROT_TILER)
923 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
924 else
925 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
926}
927
Tomi Valkeinenf4279842011-10-28 15:26:26 +0300928void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200929{
930 int shift;
931 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000932 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200933
934 switch (plane) {
935 case OMAP_DSS_GFX:
936 shift = 8;
937 break;
938 case OMAP_DSS_VIDEO1:
939 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +0530940 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200941 shift = 16;
942 break;
943 default:
944 BUG();
945 return;
946 }
947
Archit Taneja9b372c22011-05-06 11:45:49 +0530948 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000949 if (dss_has_feature(FEAT_MGR_LCD2)) {
950 switch (channel) {
951 case OMAP_DSS_CHANNEL_LCD:
952 chan = 0;
953 chan2 = 0;
954 break;
955 case OMAP_DSS_CHANNEL_DIGIT:
956 chan = 1;
957 chan2 = 0;
958 break;
959 case OMAP_DSS_CHANNEL_LCD2:
960 chan = 0;
961 chan2 = 1;
962 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530963 case OMAP_DSS_CHANNEL_LCD3:
964 if (dss_has_feature(FEAT_MGR_LCD3)) {
965 chan = 0;
966 chan2 = 2;
967 } else {
968 BUG();
969 return;
970 }
971 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000972 default:
973 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300974 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000975 }
976
977 val = FLD_MOD(val, chan, shift, shift);
978 val = FLD_MOD(val, chan2, 31, 30);
979 } else {
980 val = FLD_MOD(val, channel, shift, shift);
981 }
Archit Taneja9b372c22011-05-06 11:45:49 +0530982 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200983}
984
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200985static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
986{
987 int shift;
988 u32 val;
989 enum omap_channel channel;
990
991 switch (plane) {
992 case OMAP_DSS_GFX:
993 shift = 8;
994 break;
995 case OMAP_DSS_VIDEO1:
996 case OMAP_DSS_VIDEO2:
997 case OMAP_DSS_VIDEO3:
998 shift = 16;
999 break;
1000 default:
1001 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001002 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001003 }
1004
1005 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1006
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05301007 if (dss_has_feature(FEAT_MGR_LCD3)) {
1008 if (FLD_GET(val, 31, 30) == 0)
1009 channel = FLD_GET(val, shift, shift);
1010 else if (FLD_GET(val, 31, 30) == 1)
1011 channel = OMAP_DSS_CHANNEL_LCD2;
1012 else
1013 channel = OMAP_DSS_CHANNEL_LCD3;
1014 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001015 if (FLD_GET(val, 31, 30) == 0)
1016 channel = FLD_GET(val, shift, shift);
1017 else
1018 channel = OMAP_DSS_CHANNEL_LCD2;
1019 } else {
1020 channel = FLD_GET(val, shift, shift);
1021 }
1022
1023 return channel;
1024}
1025
Archit Tanejad9ac7732012-09-22 12:38:19 +05301026void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1027{
1028 enum omap_plane plane = OMAP_DSS_WB;
1029
1030 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1031}
1032
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001033static void dispc_ovl_set_burst_size(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001034 enum omap_burst_size burst_size)
1035{
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301036 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001037 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001038
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001039 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001040 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001041}
1042
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001043static void dispc_configure_burst_sizes(void)
1044{
1045 int i;
1046 const int burst_size = BURST_SIZE_X8;
1047
1048 /* Configure burst size always to maximum size */
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001049 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001050 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001051}
1052
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001053static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001054{
1055 unsigned unit = dss_feat_get_burst_size_unit();
1056 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1057 return unit * 8;
1058}
1059
Mythri P Kd3862612011-03-11 18:02:49 +05301060void dispc_enable_gamma_table(bool enable)
1061{
1062 /*
1063 * This is partially implemented to support only disabling of
1064 * the gamma table.
1065 */
1066 if (enable) {
1067 DSSWARN("Gamma table enabling for TV not yet supported");
1068 return;
1069 }
1070
1071 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1072}
1073
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001074static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001075{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301076 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001077 return;
1078
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301079 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001080}
1081
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001082static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02001083 const struct omap_dss_cpr_coefs *coefs)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001084{
1085 u32 coef_r, coef_g, coef_b;
1086
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301087 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001088 return;
1089
1090 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1091 FLD_VAL(coefs->rb, 9, 0);
1092 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1093 FLD_VAL(coefs->gb, 9, 0);
1094 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1095 FLD_VAL(coefs->bb, 9, 0);
1096
1097 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1098 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1099 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1100}
1101
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001102static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001103{
1104 u32 val;
1105
1106 BUG_ON(plane == OMAP_DSS_GFX);
1107
Archit Taneja9b372c22011-05-06 11:45:49 +05301108 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001109 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +05301110 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001111}
1112
Archit Tanejad79db852012-09-22 12:30:17 +05301113static void dispc_ovl_enable_replication(enum omap_plane plane,
1114 enum omap_overlay_caps caps, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001115{
Archit Tanejab8c095b2011-09-13 18:20:33 +05301116 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001117 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001118
Archit Tanejad79db852012-09-22 12:30:17 +05301119 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1120 return;
1121
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001122 shift = shifts[plane];
1123 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001124}
1125
Archit Taneja8f366162012-04-16 12:53:44 +05301126static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
Archit Tanejae5c09e02012-04-16 12:53:42 +05301127 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001128{
1129 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301130
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001131 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja702d1442011-05-06 11:45:50 +05301132 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001133}
1134
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001135static void dispc_init_fifos(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001136{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001137 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001138 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301139 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001140 u32 unit;
1141
1142 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001143
Archit Tanejaa0acb552010-09-15 19:20:00 +05301144 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001145
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001146 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1147 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001148 size *= unit;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001149 dispc.fifo_size[fifo] = size;
1150
1151 /*
1152 * By default fifos are mapped directly to overlays, fifo 0 to
1153 * ovl 0, fifo 1 to ovl 1, etc.
1154 */
1155 dispc.fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001156 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001157
1158 /*
1159 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1160 * causes problems with certain use cases, like using the tiler in 2D
1161 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1162 * giving GFX plane a larger fifo. WB but should work fine with a
1163 * smaller fifo.
1164 */
1165 if (dispc.feat->gfx_fifo_workaround) {
1166 u32 v;
1167
1168 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1169
1170 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1171 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1172 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1173 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1174
1175 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1176
1177 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1178 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1179 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001180}
1181
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001182static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001183{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001184 int fifo;
1185 u32 size = 0;
1186
1187 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1188 if (dispc.fifo_assignment[fifo] == plane)
1189 size += dispc.fifo_size[fifo];
1190 }
1191
1192 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001193}
1194
Tomi Valkeinen6f04e1b2011-10-31 08:58:52 +02001195void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001196{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301197 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001198 u32 unit;
1199
1200 unit = dss_feat_get_buffer_size_unit();
1201
1202 WARN_ON(low % unit != 0);
1203 WARN_ON(high % unit != 0);
1204
1205 low /= unit;
1206 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301207
Archit Taneja9b372c22011-05-06 11:45:49 +05301208 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1209 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1210
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001211 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001212 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301213 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001214 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301215 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001216 hi_start, hi_end) * unit,
1217 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001218
Archit Taneja9b372c22011-05-06 11:45:49 +05301219 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301220 FLD_VAL(high, hi_start, hi_end) |
1221 FLD_VAL(low, lo_start, lo_end));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001222}
1223
1224void dispc_enable_fifomerge(bool enable)
1225{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001226 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1227 WARN_ON(enable);
1228 return;
1229 }
1230
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001231 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1232 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001233}
1234
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001235void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001236 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1237 bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001238{
1239 /*
1240 * All sizes are in bytes. Both the buffer and burst are made of
1241 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1242 */
1243
1244 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001245 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1246 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001247
1248 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001249 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001250
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001251 if (use_fifomerge) {
1252 total_fifo_size = 0;
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001253 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001254 total_fifo_size += dispc_ovl_get_fifo_size(i);
1255 } else {
1256 total_fifo_size = ovl_fifo_size;
1257 }
1258
1259 /*
1260 * We use the same low threshold for both fifomerge and non-fifomerge
1261 * cases, but for fifomerge we calculate the high threshold using the
1262 * combined fifo size
1263 */
1264
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001265 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001266 *fifo_low = ovl_fifo_size - burst_size * 2;
1267 *fifo_high = total_fifo_size - burst_size;
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301268 } else if (plane == OMAP_DSS_WB) {
1269 /*
1270 * Most optimal configuration for writeback is to push out data
1271 * to the interconnect the moment writeback pushes enough pixels
1272 * in the FIFO to form a burst
1273 */
1274 *fifo_low = 0;
1275 *fifo_high = burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001276 } else {
1277 *fifo_low = ovl_fifo_size - burst_size;
1278 *fifo_high = total_fifo_size - buf_unit;
1279 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001280}
1281
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001282static void dispc_ovl_set_fir(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301283 int hinc, int vinc,
1284 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001285{
1286 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001287
Amber Jain0d66cbb2011-05-19 19:47:54 +05301288 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1289 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301290
Amber Jain0d66cbb2011-05-19 19:47:54 +05301291 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1292 &hinc_start, &hinc_end);
1293 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1294 &vinc_start, &vinc_end);
1295 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1296 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301297
Amber Jain0d66cbb2011-05-19 19:47:54 +05301298 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1299 } else {
1300 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1301 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1302 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001303}
1304
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001305static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001306{
1307 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301308 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001309
Archit Taneja87a74842011-03-02 11:19:50 +05301310 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1311 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1312
1313 val = FLD_VAL(vaccu, vert_start, vert_end) |
1314 FLD_VAL(haccu, hor_start, hor_end);
1315
Archit Taneja9b372c22011-05-06 11:45:49 +05301316 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001317}
1318
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001319static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001320{
1321 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301322 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001323
Archit Taneja87a74842011-03-02 11:19:50 +05301324 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1325 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1326
1327 val = FLD_VAL(vaccu, vert_start, vert_end) |
1328 FLD_VAL(haccu, hor_start, hor_end);
1329
Archit Taneja9b372c22011-05-06 11:45:49 +05301330 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001331}
1332
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001333static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1334 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301335{
1336 u32 val;
1337
1338 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1339 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1340}
1341
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001342static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1343 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301344{
1345 u32 val;
1346
1347 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1348 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1349}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001350
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001351static void dispc_ovl_set_scale_param(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001352 u16 orig_width, u16 orig_height,
1353 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301354 bool five_taps, u8 rotation,
1355 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001356{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301357 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001358
Amber Jained14a3c2011-05-19 19:47:51 +05301359 fir_hinc = 1024 * orig_width / out_width;
1360 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001361
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301362 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1363 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001364 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301365}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001366
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301367static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1368 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1369 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1370{
1371 int h_accu2_0, h_accu2_1;
1372 int v_accu2_0, v_accu2_1;
1373 int chroma_hinc, chroma_vinc;
1374 int idx;
1375
1376 struct accu {
1377 s8 h0_m, h0_n;
1378 s8 h1_m, h1_n;
1379 s8 v0_m, v0_n;
1380 s8 v1_m, v1_n;
1381 };
1382
1383 const struct accu *accu_table;
1384 const struct accu *accu_val;
1385
1386 static const struct accu accu_nv12[4] = {
1387 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1388 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1389 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1390 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1391 };
1392
1393 static const struct accu accu_nv12_ilace[4] = {
1394 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1395 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1396 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1397 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1398 };
1399
1400 static const struct accu accu_yuv[4] = {
1401 { 0, 1, 0, 1, 0, 1, 0, 1 },
1402 { 0, 1, 0, 1, 0, 1, 0, 1 },
1403 { -1, 1, 0, 1, 0, 1, 0, 1 },
1404 { 0, 1, 0, 1, -1, 1, 0, 1 },
1405 };
1406
1407 switch (rotation) {
1408 case OMAP_DSS_ROT_0:
1409 idx = 0;
1410 break;
1411 case OMAP_DSS_ROT_90:
1412 idx = 1;
1413 break;
1414 case OMAP_DSS_ROT_180:
1415 idx = 2;
1416 break;
1417 case OMAP_DSS_ROT_270:
1418 idx = 3;
1419 break;
1420 default:
1421 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001422 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301423 }
1424
1425 switch (color_mode) {
1426 case OMAP_DSS_COLOR_NV12:
1427 if (ilace)
1428 accu_table = accu_nv12_ilace;
1429 else
1430 accu_table = accu_nv12;
1431 break;
1432 case OMAP_DSS_COLOR_YUV2:
1433 case OMAP_DSS_COLOR_UYVY:
1434 accu_table = accu_yuv;
1435 break;
1436 default:
1437 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001438 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301439 }
1440
1441 accu_val = &accu_table[idx];
1442
1443 chroma_hinc = 1024 * orig_width / out_width;
1444 chroma_vinc = 1024 * orig_height / out_height;
1445
1446 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1447 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1448 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1449 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1450
1451 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1452 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1453}
1454
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001455static void dispc_ovl_set_scaling_common(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301456 u16 orig_width, u16 orig_height,
1457 u16 out_width, u16 out_height,
1458 bool ilace, bool five_taps,
1459 bool fieldmode, enum omap_color_mode color_mode,
1460 u8 rotation)
1461{
1462 int accu0 = 0;
1463 int accu1 = 0;
1464 u32 l;
1465
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001466 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301467 out_width, out_height, five_taps,
1468 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301469 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001470
Archit Taneja87a74842011-03-02 11:19:50 +05301471 /* RESIZEENABLE and VERTICALTAPS */
1472 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301473 l |= (orig_width != out_width) ? (1 << 5) : 0;
1474 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001475 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301476
1477 /* VRESIZECONF and HRESIZECONF */
1478 if (dss_has_feature(FEAT_RESIZECONF)) {
1479 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301480 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1481 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301482 }
1483
1484 /* LINEBUFFERSPLIT */
1485 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1486 l &= ~(0x1 << 22);
1487 l |= five_taps ? (1 << 22) : 0;
1488 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001489
Archit Taneja9b372c22011-05-06 11:45:49 +05301490 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001491
1492 /*
1493 * field 0 = even field = bottom field
1494 * field 1 = odd field = top field
1495 */
1496 if (ilace && !fieldmode) {
1497 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301498 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001499 if (accu0 >= 1024/2) {
1500 accu1 = 1024/2;
1501 accu0 -= accu1;
1502 }
1503 }
1504
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001505 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1506 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001507}
1508
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001509static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301510 u16 orig_width, u16 orig_height,
1511 u16 out_width, u16 out_height,
1512 bool ilace, bool five_taps,
1513 bool fieldmode, enum omap_color_mode color_mode,
1514 u8 rotation)
1515{
1516 int scale_x = out_width != orig_width;
1517 int scale_y = out_height != orig_height;
Archit Tanejaf92afae2012-08-24 11:11:14 +05301518 bool chroma_upscale = plane != OMAP_DSS_WB ? true : false;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301519
1520 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1521 return;
1522 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1523 color_mode != OMAP_DSS_COLOR_UYVY &&
1524 color_mode != OMAP_DSS_COLOR_NV12)) {
1525 /* reset chroma resampling for RGB formats */
Archit Taneja2a5561b2012-07-16 16:37:45 +05301526 if (plane != OMAP_DSS_WB)
1527 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301528 return;
1529 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001530
1531 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1532 out_height, ilace, color_mode, rotation);
1533
Amber Jain0d66cbb2011-05-19 19:47:54 +05301534 switch (color_mode) {
1535 case OMAP_DSS_COLOR_NV12:
Archit Taneja20fbb502012-08-22 17:04:48 +05301536 if (chroma_upscale) {
1537 /* UV is subsampled by 2 horizontally and vertically */
1538 orig_height >>= 1;
1539 orig_width >>= 1;
1540 } else {
1541 /* UV is downsampled by 2 horizontally and vertically */
1542 orig_height <<= 1;
1543 orig_width <<= 1;
1544 }
1545
Amber Jain0d66cbb2011-05-19 19:47:54 +05301546 break;
1547 case OMAP_DSS_COLOR_YUV2:
1548 case OMAP_DSS_COLOR_UYVY:
Archit Taneja20fbb502012-08-22 17:04:48 +05301549 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
Amber Jain0d66cbb2011-05-19 19:47:54 +05301550 if (rotation == OMAP_DSS_ROT_0 ||
Archit Taneja20fbb502012-08-22 17:04:48 +05301551 rotation == OMAP_DSS_ROT_180) {
1552 if (chroma_upscale)
1553 /* UV is subsampled by 2 horizontally */
1554 orig_width >>= 1;
1555 else
1556 /* UV is downsampled by 2 horizontally */
1557 orig_width <<= 1;
1558 }
1559
Amber Jain0d66cbb2011-05-19 19:47:54 +05301560 /* must use FIR for YUV422 if rotated */
1561 if (rotation != OMAP_DSS_ROT_0)
1562 scale_x = scale_y = true;
Archit Taneja20fbb502012-08-22 17:04:48 +05301563
Amber Jain0d66cbb2011-05-19 19:47:54 +05301564 break;
1565 default:
1566 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001567 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301568 }
1569
1570 if (out_width != orig_width)
1571 scale_x = true;
1572 if (out_height != orig_height)
1573 scale_y = true;
1574
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001575 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301576 out_width, out_height, five_taps,
1577 rotation, DISPC_COLOR_COMPONENT_UV);
1578
Archit Taneja2a5561b2012-07-16 16:37:45 +05301579 if (plane != OMAP_DSS_WB)
1580 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1581 (scale_x || scale_y) ? 1 : 0, 8, 8);
1582
Amber Jain0d66cbb2011-05-19 19:47:54 +05301583 /* set H scaling */
1584 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1585 /* set V scaling */
1586 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301587}
1588
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001589static void dispc_ovl_set_scaling(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301590 u16 orig_width, u16 orig_height,
1591 u16 out_width, u16 out_height,
1592 bool ilace, bool five_taps,
1593 bool fieldmode, enum omap_color_mode color_mode,
1594 u8 rotation)
1595{
1596 BUG_ON(plane == OMAP_DSS_GFX);
1597
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001598 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301599 orig_width, orig_height,
1600 out_width, out_height,
1601 ilace, five_taps,
1602 fieldmode, color_mode,
1603 rotation);
1604
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001605 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301606 orig_width, orig_height,
1607 out_width, out_height,
1608 ilace, five_taps,
1609 fieldmode, color_mode,
1610 rotation);
1611}
1612
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001613static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001614 bool mirroring, enum omap_color_mode color_mode)
1615{
Archit Taneja87a74842011-03-02 11:19:50 +05301616 bool row_repeat = false;
1617 int vidrot = 0;
1618
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001619 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1620 color_mode == OMAP_DSS_COLOR_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001621
1622 if (mirroring) {
1623 switch (rotation) {
1624 case OMAP_DSS_ROT_0:
1625 vidrot = 2;
1626 break;
1627 case OMAP_DSS_ROT_90:
1628 vidrot = 1;
1629 break;
1630 case OMAP_DSS_ROT_180:
1631 vidrot = 0;
1632 break;
1633 case OMAP_DSS_ROT_270:
1634 vidrot = 3;
1635 break;
1636 }
1637 } else {
1638 switch (rotation) {
1639 case OMAP_DSS_ROT_0:
1640 vidrot = 0;
1641 break;
1642 case OMAP_DSS_ROT_90:
1643 vidrot = 1;
1644 break;
1645 case OMAP_DSS_ROT_180:
1646 vidrot = 2;
1647 break;
1648 case OMAP_DSS_ROT_270:
1649 vidrot = 3;
1650 break;
1651 }
1652 }
1653
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001654 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
Archit Taneja87a74842011-03-02 11:19:50 +05301655 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001656 else
Archit Taneja87a74842011-03-02 11:19:50 +05301657 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001658 }
Archit Taneja87a74842011-03-02 11:19:50 +05301659
Archit Taneja9b372c22011-05-06 11:45:49 +05301660 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301661 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301662 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1663 row_repeat ? 1 : 0, 18, 18);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001664}
1665
1666static int color_mode_to_bpp(enum omap_color_mode color_mode)
1667{
1668 switch (color_mode) {
1669 case OMAP_DSS_COLOR_CLUT1:
1670 return 1;
1671 case OMAP_DSS_COLOR_CLUT2:
1672 return 2;
1673 case OMAP_DSS_COLOR_CLUT4:
1674 return 4;
1675 case OMAP_DSS_COLOR_CLUT8:
Amber Jainf20e4222011-05-19 19:47:50 +05301676 case OMAP_DSS_COLOR_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001677 return 8;
1678 case OMAP_DSS_COLOR_RGB12U:
1679 case OMAP_DSS_COLOR_RGB16:
1680 case OMAP_DSS_COLOR_ARGB16:
1681 case OMAP_DSS_COLOR_YUV2:
1682 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301683 case OMAP_DSS_COLOR_RGBA16:
1684 case OMAP_DSS_COLOR_RGBX16:
1685 case OMAP_DSS_COLOR_ARGB16_1555:
1686 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001687 return 16;
1688 case OMAP_DSS_COLOR_RGB24P:
1689 return 24;
1690 case OMAP_DSS_COLOR_RGB24U:
1691 case OMAP_DSS_COLOR_ARGB32:
1692 case OMAP_DSS_COLOR_RGBA32:
1693 case OMAP_DSS_COLOR_RGBX32:
1694 return 32;
1695 default:
1696 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001697 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001698 }
1699}
1700
1701static s32 pixinc(int pixels, u8 ps)
1702{
1703 if (pixels == 1)
1704 return 1;
1705 else if (pixels > 1)
1706 return 1 + (pixels - 1) * ps;
1707 else if (pixels < 0)
1708 return 1 - (-pixels + 1) * ps;
1709 else
1710 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001711 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001712}
1713
1714static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1715 u16 screen_width,
1716 u16 width, u16 height,
1717 enum omap_color_mode color_mode, bool fieldmode,
1718 unsigned int field_offset,
1719 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301720 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001721{
1722 u8 ps;
1723
1724 /* FIXME CLUT formats */
1725 switch (color_mode) {
1726 case OMAP_DSS_COLOR_CLUT1:
1727 case OMAP_DSS_COLOR_CLUT2:
1728 case OMAP_DSS_COLOR_CLUT4:
1729 case OMAP_DSS_COLOR_CLUT8:
1730 BUG();
1731 return;
1732 case OMAP_DSS_COLOR_YUV2:
1733 case OMAP_DSS_COLOR_UYVY:
1734 ps = 4;
1735 break;
1736 default:
1737 ps = color_mode_to_bpp(color_mode) / 8;
1738 break;
1739 }
1740
1741 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1742 width, height);
1743
1744 /*
1745 * field 0 = even field = bottom field
1746 * field 1 = odd field = top field
1747 */
1748 switch (rotation + mirror * 4) {
1749 case OMAP_DSS_ROT_0:
1750 case OMAP_DSS_ROT_180:
1751 /*
1752 * If the pixel format is YUV or UYVY divide the width
1753 * of the image by 2 for 0 and 180 degree rotation.
1754 */
1755 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1756 color_mode == OMAP_DSS_COLOR_UYVY)
1757 width = width >> 1;
1758 case OMAP_DSS_ROT_90:
1759 case OMAP_DSS_ROT_270:
1760 *offset1 = 0;
1761 if (field_offset)
1762 *offset0 = field_offset * screen_width * ps;
1763 else
1764 *offset0 = 0;
1765
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301766 *row_inc = pixinc(1 +
1767 (y_predecim * screen_width - x_predecim * width) +
1768 (fieldmode ? screen_width : 0), ps);
1769 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001770 break;
1771
1772 case OMAP_DSS_ROT_0 + 4:
1773 case OMAP_DSS_ROT_180 + 4:
1774 /* If the pixel format is YUV or UYVY divide the width
1775 * of the image by 2 for 0 degree and 180 degree
1776 */
1777 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1778 color_mode == OMAP_DSS_COLOR_UYVY)
1779 width = width >> 1;
1780 case OMAP_DSS_ROT_90 + 4:
1781 case OMAP_DSS_ROT_270 + 4:
1782 *offset1 = 0;
1783 if (field_offset)
1784 *offset0 = field_offset * screen_width * ps;
1785 else
1786 *offset0 = 0;
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301787 *row_inc = pixinc(1 -
1788 (y_predecim * screen_width + x_predecim * width) -
1789 (fieldmode ? screen_width : 0), ps);
1790 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001791 break;
1792
1793 default:
1794 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001795 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001796 }
1797}
1798
1799static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1800 u16 screen_width,
1801 u16 width, u16 height,
1802 enum omap_color_mode color_mode, bool fieldmode,
1803 unsigned int field_offset,
1804 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301805 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001806{
1807 u8 ps;
1808 u16 fbw, fbh;
1809
1810 /* FIXME CLUT formats */
1811 switch (color_mode) {
1812 case OMAP_DSS_COLOR_CLUT1:
1813 case OMAP_DSS_COLOR_CLUT2:
1814 case OMAP_DSS_COLOR_CLUT4:
1815 case OMAP_DSS_COLOR_CLUT8:
1816 BUG();
1817 return;
1818 default:
1819 ps = color_mode_to_bpp(color_mode) / 8;
1820 break;
1821 }
1822
1823 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1824 width, height);
1825
1826 /* width & height are overlay sizes, convert to fb sizes */
1827
1828 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1829 fbw = width;
1830 fbh = height;
1831 } else {
1832 fbw = height;
1833 fbh = width;
1834 }
1835
1836 /*
1837 * field 0 = even field = bottom field
1838 * field 1 = odd field = top field
1839 */
1840 switch (rotation + mirror * 4) {
1841 case OMAP_DSS_ROT_0:
1842 *offset1 = 0;
1843 if (field_offset)
1844 *offset0 = *offset1 + field_offset * screen_width * ps;
1845 else
1846 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301847 *row_inc = pixinc(1 +
1848 (y_predecim * screen_width - fbw * x_predecim) +
1849 (fieldmode ? screen_width : 0), ps);
1850 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1851 color_mode == OMAP_DSS_COLOR_UYVY)
1852 *pix_inc = pixinc(x_predecim, 2 * ps);
1853 else
1854 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001855 break;
1856 case OMAP_DSS_ROT_90:
1857 *offset1 = screen_width * (fbh - 1) * ps;
1858 if (field_offset)
1859 *offset0 = *offset1 + field_offset * ps;
1860 else
1861 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301862 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1863 y_predecim + (fieldmode ? 1 : 0), ps);
1864 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001865 break;
1866 case OMAP_DSS_ROT_180:
1867 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1868 if (field_offset)
1869 *offset0 = *offset1 - field_offset * screen_width * ps;
1870 else
1871 *offset0 = *offset1;
1872 *row_inc = pixinc(-1 -
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301873 (y_predecim * screen_width - fbw * x_predecim) -
1874 (fieldmode ? screen_width : 0), ps);
1875 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1876 color_mode == OMAP_DSS_COLOR_UYVY)
1877 *pix_inc = pixinc(-x_predecim, 2 * ps);
1878 else
1879 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001880 break;
1881 case OMAP_DSS_ROT_270:
1882 *offset1 = (fbw - 1) * ps;
1883 if (field_offset)
1884 *offset0 = *offset1 - field_offset * ps;
1885 else
1886 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301887 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1888 y_predecim - (fieldmode ? 1 : 0), ps);
1889 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001890 break;
1891
1892 /* mirroring */
1893 case OMAP_DSS_ROT_0 + 4:
1894 *offset1 = (fbw - 1) * ps;
1895 if (field_offset)
1896 *offset0 = *offset1 + field_offset * screen_width * ps;
1897 else
1898 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301899 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001900 (fieldmode ? screen_width : 0),
1901 ps);
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301902 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1903 color_mode == OMAP_DSS_COLOR_UYVY)
1904 *pix_inc = pixinc(-x_predecim, 2 * ps);
1905 else
1906 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001907 break;
1908
1909 case OMAP_DSS_ROT_90 + 4:
1910 *offset1 = 0;
1911 if (field_offset)
1912 *offset0 = *offset1 + field_offset * ps;
1913 else
1914 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301915 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1916 y_predecim + (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001917 ps);
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301918 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001919 break;
1920
1921 case OMAP_DSS_ROT_180 + 4:
1922 *offset1 = screen_width * (fbh - 1) * ps;
1923 if (field_offset)
1924 *offset0 = *offset1 - field_offset * screen_width * ps;
1925 else
1926 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301927 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001928 (fieldmode ? screen_width : 0),
1929 ps);
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301930 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1931 color_mode == OMAP_DSS_COLOR_UYVY)
1932 *pix_inc = pixinc(x_predecim, 2 * ps);
1933 else
1934 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001935 break;
1936
1937 case OMAP_DSS_ROT_270 + 4:
1938 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1939 if (field_offset)
1940 *offset0 = *offset1 - field_offset * ps;
1941 else
1942 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301943 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
1944 y_predecim - (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001945 ps);
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05301946 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001947 break;
1948
1949 default:
1950 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001951 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001952 }
1953}
1954
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301955static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
1956 enum omap_color_mode color_mode, bool fieldmode,
1957 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1958 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1959{
1960 u8 ps;
1961
1962 switch (color_mode) {
1963 case OMAP_DSS_COLOR_CLUT1:
1964 case OMAP_DSS_COLOR_CLUT2:
1965 case OMAP_DSS_COLOR_CLUT4:
1966 case OMAP_DSS_COLOR_CLUT8:
1967 BUG();
1968 return;
1969 default:
1970 ps = color_mode_to_bpp(color_mode) / 8;
1971 break;
1972 }
1973
1974 DSSDBG("scrw %d, width %d\n", screen_width, width);
1975
1976 /*
1977 * field 0 = even field = bottom field
1978 * field 1 = odd field = top field
1979 */
1980 *offset1 = 0;
1981 if (field_offset)
1982 *offset0 = *offset1 + field_offset * screen_width * ps;
1983 else
1984 *offset0 = *offset1;
1985 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1986 (fieldmode ? screen_width : 0), ps);
1987 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1988 color_mode == OMAP_DSS_COLOR_UYVY)
1989 *pix_inc = pixinc(x_predecim, 2 * ps);
1990 else
1991 *pix_inc = pixinc(x_predecim, ps);
1992}
1993
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301994/*
1995 * This function is used to avoid synclosts in OMAP3, because of some
1996 * undocumented horizontal position and timing related limitations.
1997 */
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05301998static int check_horiz_timing_omap3(enum omap_plane plane,
Archit Taneja81ab95b2012-05-08 15:53:20 +05301999 const struct omap_video_timings *t, u16 pos_x,
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302000 u16 width, u16 height, u16 out_width, u16 out_height)
2001{
2002 int DS = DIV_ROUND_UP(height, out_height);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302003 unsigned long nonactive;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302004 static const u8 limits[3] = { 8, 10, 20 };
2005 u64 val, blank;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302006 unsigned long pclk = dispc_plane_pclk_rate(plane);
2007 unsigned long lclk = dispc_plane_lclk_rate(plane);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302008 int i;
2009
Archit Taneja81ab95b2012-05-08 15:53:20 +05302010 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302011
2012 i = 0;
2013 if (out_height < height)
2014 i++;
2015 if (out_width < width)
2016 i++;
Archit Taneja81ab95b2012-05-08 15:53:20 +05302017 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302018 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2019 if (blank <= limits[i])
2020 return -EINVAL;
2021
2022 /*
2023 * Pixel data should be prepared before visible display point starts.
2024 * So, atleast DS-2 lines must have already been fetched by DISPC
2025 * during nonactive - pos_x period.
2026 */
2027 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2028 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2029 val, max(0, DS - 2) * width);
2030 if (val < max(0, DS - 2) * width)
2031 return -EINVAL;
2032
2033 /*
2034 * All lines need to be refilled during the nonactive period of which
2035 * only one line can be loaded during the active period. So, atleast
2036 * DS - 1 lines should be loaded during nonactive period.
2037 */
2038 val = div_u64((u64)nonactive * lclk, pclk);
2039 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
2040 val, max(0, DS - 1) * width);
2041 if (val < max(0, DS - 1) * width)
2042 return -EINVAL;
2043
2044 return 0;
2045}
2046
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302047static unsigned long calc_core_clk_five_taps(enum omap_plane plane,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302048 const struct omap_video_timings *mgr_timings, u16 width,
2049 u16 height, u16 out_width, u16 out_height,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002050 enum omap_color_mode color_mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002051{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302052 u32 core_clk = 0;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302053 u64 tmp;
2054 unsigned long pclk = dispc_plane_pclk_rate(plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002055
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302056 if (height <= out_height && width <= out_width)
2057 return (unsigned long) pclk;
2058
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002059 if (height > out_height) {
Archit Taneja81ab95b2012-05-08 15:53:20 +05302060 unsigned int ppl = mgr_timings->x_res;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002061
2062 tmp = pclk * height * out_width;
2063 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302064 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002065
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02002066 if (height > 2 * out_height) {
2067 if (ppl == out_width)
2068 return 0;
2069
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002070 tmp = pclk * (height - 2 * out_height) * out_width;
2071 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302072 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002073 }
2074 }
2075
2076 if (width > out_width) {
2077 tmp = pclk * width;
2078 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302079 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002080
2081 if (color_mode == OMAP_DSS_COLOR_RGB24U)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302082 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002083 }
2084
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302085 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002086}
2087
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302088static unsigned long calc_core_clk_24xx(enum omap_plane plane, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302089 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302090{
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302091 unsigned long pclk = dispc_plane_pclk_rate(plane);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302092
2093 if (height > out_height && width > out_width)
2094 return pclk * 4;
2095 else
2096 return pclk * 2;
2097}
2098
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302099static unsigned long calc_core_clk_34xx(enum omap_plane plane, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302100 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002101{
2102 unsigned int hf, vf;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302103 unsigned long pclk = dispc_plane_pclk_rate(plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002104
2105 /*
2106 * FIXME how to determine the 'A' factor
2107 * for the no downscaling case ?
2108 */
2109
2110 if (width > 3 * out_width)
2111 hf = 4;
2112 else if (width > 2 * out_width)
2113 hf = 3;
2114 else if (width > out_width)
2115 hf = 2;
2116 else
2117 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002118 if (height > out_height)
2119 vf = 2;
2120 else
2121 vf = 1;
2122
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302123 return pclk * vf * hf;
2124}
2125
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302126static unsigned long calc_core_clk_44xx(enum omap_plane plane, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302127 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302128{
Archit Taneja8ba85302012-09-26 17:00:37 +05302129 unsigned long pclk;
2130
2131 /*
2132 * If the overlay/writeback is in mem to mem mode, there are no
2133 * downscaling limitations with respect to pixel clock, return 1 as
2134 * required core clock to represent that we have sufficient enough
2135 * core clock to do maximum downscaling
2136 */
2137 if (mem_to_mem)
2138 return 1;
2139
2140 pclk = dispc_plane_pclk_rate(plane);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302141
2142 if (width > out_width)
2143 return DIV_ROUND_UP(pclk, out_width) * width;
2144 else
2145 return pclk;
2146}
2147
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302148static int dispc_ovl_calc_scaling_24xx(enum omap_plane plane,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302149 const struct omap_video_timings *mgr_timings,
2150 u16 width, u16 height, u16 out_width, u16 out_height,
2151 enum omap_color_mode color_mode, bool *five_taps,
2152 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302153 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302154{
2155 int error;
2156 u16 in_width, in_height;
2157 int min_factor = min(*decim_x, *decim_y);
2158 const int maxsinglelinewidth =
2159 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302160
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302161 *five_taps = false;
2162
2163 do {
2164 in_height = DIV_ROUND_UP(height, *decim_y);
2165 in_width = DIV_ROUND_UP(width, *decim_x);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302166 *core_clk = dispc.feat->calc_core_clk(plane, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302167 in_height, out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302168 error = (in_width > maxsinglelinewidth || !*core_clk ||
2169 *core_clk > dispc_core_clk_rate());
2170 if (error) {
2171 if (*decim_x == *decim_y) {
2172 *decim_x = min_factor;
2173 ++*decim_y;
2174 } else {
2175 swap(*decim_x, *decim_y);
2176 if (*decim_x < *decim_y)
2177 ++*decim_x;
2178 }
2179 }
2180 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2181
2182 if (in_width > maxsinglelinewidth) {
2183 DSSERR("Cannot scale max input width exceeded");
2184 return -EINVAL;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302185 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302186 return 0;
2187}
2188
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302189static int dispc_ovl_calc_scaling_34xx(enum omap_plane plane,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302190 const struct omap_video_timings *mgr_timings,
2191 u16 width, u16 height, u16 out_width, u16 out_height,
2192 enum omap_color_mode color_mode, bool *five_taps,
2193 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302194 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302195{
2196 int error;
2197 u16 in_width, in_height;
2198 int min_factor = min(*decim_x, *decim_y);
2199 const int maxsinglelinewidth =
2200 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2201
2202 do {
2203 in_height = DIV_ROUND_UP(height, *decim_y);
2204 in_width = DIV_ROUND_UP(width, *decim_x);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302205 *core_clk = calc_core_clk_five_taps(plane, mgr_timings,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302206 in_width, in_height, out_width, out_height, color_mode);
2207
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302208 error = check_horiz_timing_omap3(plane, mgr_timings,
2209 pos_x, in_width, in_height, out_width,
2210 out_height);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302211
2212 if (in_width > maxsinglelinewidth)
2213 if (in_height > out_height &&
2214 in_height < out_height * 2)
2215 *five_taps = false;
2216 if (!*five_taps)
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302217 *core_clk = dispc.feat->calc_core_clk(plane, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302218 in_height, out_width, out_height,
2219 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302220
2221 error = (error || in_width > maxsinglelinewidth * 2 ||
2222 (in_width > maxsinglelinewidth && *five_taps) ||
2223 !*core_clk || *core_clk > dispc_core_clk_rate());
2224 if (error) {
2225 if (*decim_x == *decim_y) {
2226 *decim_x = min_factor;
2227 ++*decim_y;
2228 } else {
2229 swap(*decim_x, *decim_y);
2230 if (*decim_x < *decim_y)
2231 ++*decim_x;
2232 }
2233 }
2234 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2235
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302236 if (check_horiz_timing_omap3(plane, mgr_timings, pos_x, width, height,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302237 out_width, out_height)){
2238 DSSERR("horizontal timing too tight\n");
2239 return -EINVAL;
2240 }
2241
2242 if (in_width > (maxsinglelinewidth * 2)) {
2243 DSSERR("Cannot setup scaling");
2244 DSSERR("width exceeds maximum width possible");
2245 return -EINVAL;
2246 }
2247
2248 if (in_width > maxsinglelinewidth && *five_taps) {
2249 DSSERR("cannot setup scaling with five taps");
2250 return -EINVAL;
2251 }
2252 return 0;
2253}
2254
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302255static int dispc_ovl_calc_scaling_44xx(enum omap_plane plane,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302256 const struct omap_video_timings *mgr_timings,
2257 u16 width, u16 height, u16 out_width, u16 out_height,
2258 enum omap_color_mode color_mode, bool *five_taps,
2259 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302260 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302261{
2262 u16 in_width, in_width_max;
2263 int decim_x_min = *decim_x;
2264 u16 in_height = DIV_ROUND_UP(height, *decim_y);
2265 const int maxsinglelinewidth =
2266 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302267 unsigned long pclk = dispc_plane_pclk_rate(plane);
Archit Taneja8ba85302012-09-26 17:00:37 +05302268 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302269
Archit Taneja8ba85302012-09-26 17:00:37 +05302270 if (mem_to_mem)
2271 in_width_max = DIV_ROUND_UP(out_width, maxdownscale);
2272 else
2273 in_width_max = dispc_core_clk_rate() /
2274 DIV_ROUND_UP(pclk, out_width);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302275
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302276 *decim_x = DIV_ROUND_UP(width, in_width_max);
2277
2278 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2279 if (*decim_x > *x_predecim)
2280 return -EINVAL;
2281
2282 do {
2283 in_width = DIV_ROUND_UP(width, *decim_x);
2284 } while (*decim_x <= *x_predecim &&
2285 in_width > maxsinglelinewidth && ++*decim_x);
2286
2287 if (in_width > maxsinglelinewidth) {
2288 DSSERR("Cannot scale width exceeds max line width");
2289 return -EINVAL;
2290 }
2291
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302292 *core_clk = dispc.feat->calc_core_clk(plane, in_width, in_height,
Archit Taneja8ba85302012-09-26 17:00:37 +05302293 out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302294 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002295}
2296
Archit Taneja79ad75f2011-09-08 13:15:11 +05302297static int dispc_ovl_calc_scaling(enum omap_plane plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302298 enum omap_overlay_caps caps,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302299 const struct omap_video_timings *mgr_timings,
2300 u16 width, u16 height, u16 out_width, u16 out_height,
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302301 enum omap_color_mode color_mode, bool *five_taps,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302302 int *x_predecim, int *y_predecim, u16 pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302303 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302304{
Archit Taneja0373cac2011-09-08 13:25:17 +05302305 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302306 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302307 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302308 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302309
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002310 if (width == out_width && height == out_height)
2311 return 0;
2312
Archit Taneja5b54ed32012-09-26 16:55:27 +05302313 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002314 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302315
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302316 *x_predecim = max_decim_limit;
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302317 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2318 dss_has_feature(FEAT_BURST_2D)) ? 2 : max_decim_limit;
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302319
2320 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2321 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2322 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2323 color_mode == OMAP_DSS_COLOR_CLUT8) {
2324 *x_predecim = 1;
2325 *y_predecim = 1;
2326 *five_taps = false;
2327 return 0;
2328 }
2329
2330 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2331 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2332
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302333 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302334 return -EINVAL;
2335
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302336 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302337 return -EINVAL;
2338
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302339 ret = dispc.feat->calc_scaling(plane, mgr_timings, width, height,
2340 out_width, out_height, color_mode, five_taps,
Archit Taneja8ba85302012-09-26 17:00:37 +05302341 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2342 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302343 if (ret)
2344 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302345
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302346 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2347 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302348
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302349 if (!core_clk || core_clk > dispc_core_clk_rate()) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302350 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302351 "required core clk rate = %lu Hz, "
2352 "current core clk rate = %lu Hz\n",
2353 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302354 return -EINVAL;
2355 }
2356
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302357 *x_predecim = decim_x;
2358 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302359 return 0;
2360}
2361
Archit Taneja84a880f2012-09-26 16:57:37 +05302362static int dispc_ovl_setup_common(enum omap_plane plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302363 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2364 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2365 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2366 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2367 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
Archit Taneja8ba85302012-09-26 17:00:37 +05302368 bool replication, const struct omap_video_timings *mgr_timings,
2369 bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002370{
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302371 bool five_taps = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002372 bool fieldmode = 0;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302373 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002374 unsigned offset0, offset1;
2375 s32 row_inc;
2376 s32 pix_inc;
Archit Taneja84a880f2012-09-26 16:57:37 +05302377 u16 frame_height = height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002378 unsigned int field_offset = 0;
Archit Taneja84a880f2012-09-26 16:57:37 +05302379 u16 in_height = height;
2380 u16 in_width = width;
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302381 int x_predecim = 1, y_predecim = 1;
Archit Taneja8050cbe2012-06-06 16:25:52 +05302382 bool ilace = mgr_timings->interlace;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002383
Archit Taneja84a880f2012-09-26 16:57:37 +05302384 if (paddr == 0)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002385 return -EINVAL;
2386
Archit Taneja84a880f2012-09-26 16:57:37 +05302387 out_width = out_width == 0 ? width : out_width;
2388 out_height = out_height == 0 ? height : out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002389
Archit Taneja84a880f2012-09-26 16:57:37 +05302390 if (ilace && height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002391 fieldmode = 1;
2392
2393 if (ilace) {
2394 if (fieldmode)
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302395 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302396 pos_y /= 2;
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302397 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002398
2399 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
Archit Taneja84a880f2012-09-26 16:57:37 +05302400 "out_height %d\n", in_height, pos_y,
2401 out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002402 }
2403
Archit Taneja84a880f2012-09-26 16:57:37 +05302404 if (!dss_feat_color_mode_supported(plane, color_mode))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302405 return -EINVAL;
2406
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302407 r = dispc_ovl_calc_scaling(plane, caps, mgr_timings, in_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302408 in_height, out_width, out_height, color_mode,
2409 &five_taps, &x_predecim, &y_predecim, pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302410 rotation_type, mem_to_mem);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302411 if (r)
2412 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002413
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302414 in_width = DIV_ROUND_UP(in_width, x_predecim);
2415 in_height = DIV_ROUND_UP(in_height, y_predecim);
2416
Archit Taneja84a880f2012-09-26 16:57:37 +05302417 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2418 color_mode == OMAP_DSS_COLOR_UYVY ||
2419 color_mode == OMAP_DSS_COLOR_NV12)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302420 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002421
2422 if (ilace && !fieldmode) {
2423 /*
2424 * when downscaling the bottom field may have to start several
2425 * source lines below the top field. Unfortunately ACCUI
2426 * registers will only hold the fractional part of the offset
2427 * so the integer part must be added to the base address of the
2428 * bottom field.
2429 */
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302430 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002431 field_offset = 0;
2432 else
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302433 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002434 }
2435
2436 /* Fields are independent but interleaved in memory. */
2437 if (fieldmode)
2438 field_offset = 1;
2439
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002440 offset0 = 0;
2441 offset1 = 0;
2442 row_inc = 0;
2443 pix_inc = 0;
2444
Archit Taneja84a880f2012-09-26 16:57:37 +05302445 if (rotation_type == OMAP_DSS_ROT_TILER)
2446 calc_tiler_rotation_offset(screen_width, in_width,
2447 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302448 &offset0, &offset1, &row_inc, &pix_inc,
2449 x_predecim, y_predecim);
Archit Taneja84a880f2012-09-26 16:57:37 +05302450 else if (rotation_type == OMAP_DSS_ROT_DMA)
2451 calc_dma_rotation_offset(rotation, mirror,
2452 screen_width, in_width, frame_height,
2453 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302454 &offset0, &offset1, &row_inc, &pix_inc,
2455 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002456 else
Archit Taneja84a880f2012-09-26 16:57:37 +05302457 calc_vrfb_rotation_offset(rotation, mirror,
2458 screen_width, in_width, frame_height,
2459 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302460 &offset0, &offset1, &row_inc, &pix_inc,
2461 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002462
2463 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2464 offset0, offset1, row_inc, pix_inc);
2465
Archit Taneja84a880f2012-09-26 16:57:37 +05302466 dispc_ovl_set_color_mode(plane, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002467
Archit Taneja84a880f2012-09-26 16:57:37 +05302468 dispc_ovl_configure_burst_type(plane, rotation_type);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302469
Archit Taneja84a880f2012-09-26 16:57:37 +05302470 dispc_ovl_set_ba0(plane, paddr + offset0);
2471 dispc_ovl_set_ba1(plane, paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002472
Archit Taneja84a880f2012-09-26 16:57:37 +05302473 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2474 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2475 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302476 }
2477
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002478 dispc_ovl_set_row_inc(plane, row_inc);
2479 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002480
Archit Taneja84a880f2012-09-26 16:57:37 +05302481 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302482 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002483
Archit Taneja84a880f2012-09-26 16:57:37 +05302484 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002485
Archit Taneja78b687f2012-09-21 14:51:49 +05302486 dispc_ovl_set_input_size(plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002487
Archit Taneja5b54ed32012-09-26 16:55:27 +05302488 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Chandrabhanu Mahapatraaed74b52012-04-02 20:43:16 +05302489 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2490 out_height, ilace, five_taps, fieldmode,
Archit Taneja84a880f2012-09-26 16:57:37 +05302491 color_mode, rotation);
Archit Taneja78b687f2012-09-21 14:51:49 +05302492 dispc_ovl_set_output_size(plane, out_width, out_height);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002493 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002494 }
2495
Archit Taneja84a880f2012-09-26 16:57:37 +05302496 dispc_ovl_set_rotation_attrs(plane, rotation, mirror, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002497
Archit Taneja84a880f2012-09-26 16:57:37 +05302498 dispc_ovl_set_zorder(plane, caps, zorder);
2499 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2500 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002501
Archit Tanejad79db852012-09-22 12:30:17 +05302502 dispc_ovl_enable_replication(plane, caps, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302503
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002504 return 0;
2505}
2506
Archit Taneja84a880f2012-09-26 16:57:37 +05302507int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
Archit Taneja8ba85302012-09-26 17:00:37 +05302508 bool replication, const struct omap_video_timings *mgr_timings,
2509 bool mem_to_mem)
Archit Taneja84a880f2012-09-26 16:57:37 +05302510{
2511 int r;
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002512 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
Archit Taneja84a880f2012-09-26 16:57:37 +05302513 enum omap_channel channel;
2514
2515 channel = dispc_ovl_get_channel_out(plane);
2516
2517 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
2518 "%dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2519 plane, oi->paddr, oi->p_uv_addr, oi->screen_width, oi->pos_x,
2520 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2521 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2522
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002523 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302524 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2525 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2526 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
Archit Taneja8ba85302012-09-26 17:00:37 +05302527 oi->rotation_type, replication, mgr_timings, mem_to_mem);
Archit Taneja84a880f2012-09-26 16:57:37 +05302528
2529 return r;
2530}
2531
Archit Taneja749feff2012-08-31 12:32:52 +05302532int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302533 bool mem_to_mem, const struct omap_video_timings *mgr_timings)
Archit Taneja749feff2012-08-31 12:32:52 +05302534{
2535 int r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302536 u32 l;
Archit Taneja749feff2012-08-31 12:32:52 +05302537 enum omap_plane plane = OMAP_DSS_WB;
2538 const int pos_x = 0, pos_y = 0;
2539 const u8 zorder = 0, global_alpha = 0;
2540 const bool replication = false;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302541 bool truncation;
Archit Taneja749feff2012-08-31 12:32:52 +05302542 int in_width = mgr_timings->x_res;
2543 int in_height = mgr_timings->y_res;
2544 enum omap_overlay_caps caps =
2545 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2546
2547 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2548 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2549 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2550 wi->mirror);
2551
2552 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2553 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2554 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2555 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302556 replication, mgr_timings, mem_to_mem);
2557
2558 switch (wi->color_mode) {
2559 case OMAP_DSS_COLOR_RGB16:
2560 case OMAP_DSS_COLOR_RGB24P:
2561 case OMAP_DSS_COLOR_ARGB16:
2562 case OMAP_DSS_COLOR_RGBA16:
2563 case OMAP_DSS_COLOR_RGB12U:
2564 case OMAP_DSS_COLOR_ARGB16_1555:
2565 case OMAP_DSS_COLOR_XRGB16_1555:
2566 case OMAP_DSS_COLOR_RGBX16:
2567 truncation = true;
2568 break;
2569 default:
2570 truncation = false;
2571 break;
2572 }
2573
2574 /* setup extra DISPC_WB_ATTRIBUTES */
2575 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2576 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2577 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2578 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Archit Taneja749feff2012-08-31 12:32:52 +05302579
2580 return r;
2581}
2582
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002583int dispc_ovl_enable(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002584{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002585 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2586
Archit Taneja9b372c22011-05-06 11:45:49 +05302587 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002588
2589 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002590}
2591
Tomi Valkeinen04bd8ac2012-10-10 14:13:15 +03002592bool dispc_ovl_enabled(enum omap_plane plane)
2593{
2594 return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2595}
2596
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002597static void dispc_mgr_disable_isr(void *data, u32 mask)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002598{
2599 struct completion *compl = data;
2600 complete(compl);
2601}
2602
Tomi Valkeinenf1a813d2012-10-19 14:16:06 +03002603void dispc_mgr_enable(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002604{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302605 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2606 /* flush posted write */
2607 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002608}
2609
Tomi Valkeinen65398512012-10-10 11:44:17 +03002610bool dispc_mgr_is_enabled(enum omap_channel channel)
2611{
2612 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2613}
2614
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002615static void dispc_mgr_enable_lcd_out(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002616{
Tomi Valkeinenf1a813d2012-10-19 14:16:06 +03002617 dispc_mgr_enable(channel, true);
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002618}
2619
2620static void dispc_mgr_disable_lcd_out(enum omap_channel channel)
2621{
2622 DECLARE_COMPLETION_ONSTACK(framedone_compl);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002623 int r;
Sumit Semwal2a205f32010-12-02 11:27:12 +00002624 u32 irq;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002625
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002626 if (dispc_mgr_is_enabled(channel) == false)
2627 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +00002628
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002629 /*
2630 * When we disable LCD output, we need to wait for FRAMEDONE to know
2631 * that DISPC has finished with the LCD output.
2632 */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002633
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002634 irq = dispc_mgr_get_framedone_irq(channel);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002635
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002636 r = omap_dispc_register_isr(dispc_mgr_disable_isr, &framedone_compl,
2637 irq);
2638 if (r)
2639 DSSERR("failed to register FRAMEDONE isr\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002640
Tomi Valkeinenf1a813d2012-10-19 14:16:06 +03002641 dispc_mgr_enable(channel, false);
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002642
2643 /* if we couldn't register for framedone, just sleep and exit */
2644 if (r) {
2645 msleep(100);
2646 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002647 }
2648
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002649 if (!wait_for_completion_timeout(&framedone_compl,
2650 msecs_to_jiffies(100)))
2651 DSSERR("timeout waiting for FRAME DONE\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002652
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002653 r = omap_dispc_unregister_isr(dispc_mgr_disable_isr, &framedone_compl,
2654 irq);
2655 if (r)
2656 DSSERR("failed to unregister FRAMEDONE isr\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002657}
2658
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002659static void dispc_digit_out_enable_isr(void *data, u32 mask)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002660{
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002661 struct completion *compl = data;
2662
2663 /* ignore any sync lost interrupts */
2664 if (mask & (DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD))
2665 complete(compl);
2666}
2667
2668static void dispc_mgr_enable_digit_out(void)
2669{
2670 DECLARE_COMPLETION_ONSTACK(vsync_compl);
2671 int r;
2672 u32 irq_mask;
2673
2674 if (dispc_mgr_is_enabled(OMAP_DSS_CHANNEL_DIGIT) == true)
2675 return;
2676
2677 /*
2678 * Digit output produces some sync lost interrupts during the first
2679 * frame when enabling. Those need to be ignored, so we register for the
2680 * sync lost irq to prevent the error handler from triggering.
2681 */
2682
2683 irq_mask = dispc_mgr_get_vsync_irq(OMAP_DSS_CHANNEL_DIGIT) |
2684 dispc_mgr_get_sync_lost_irq(OMAP_DSS_CHANNEL_DIGIT);
2685
2686 r = omap_dispc_register_isr(dispc_digit_out_enable_isr, &vsync_compl,
2687 irq_mask);
2688 if (r) {
2689 DSSERR("failed to register %x isr\n", irq_mask);
2690 return;
2691 }
2692
Tomi Valkeinenf1a813d2012-10-19 14:16:06 +03002693 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, true);
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002694
2695 /* wait for the first evsync */
2696 if (!wait_for_completion_timeout(&vsync_compl, msecs_to_jiffies(100)))
2697 DSSERR("timeout waiting for digit out to start\n");
2698
2699 r = omap_dispc_unregister_isr(dispc_digit_out_enable_isr, &vsync_compl,
2700 irq_mask);
2701 if (r)
2702 DSSERR("failed to unregister %x isr\n", irq_mask);
2703}
2704
2705static void dispc_mgr_disable_digit_out(void)
2706{
2707 DECLARE_COMPLETION_ONSTACK(framedone_compl);
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002708 enum dss_hdmi_venc_clk_source_select src;
2709 int r, i;
2710 u32 irq_mask;
2711 int num_irqs;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002712
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002713 if (dispc_mgr_is_enabled(OMAP_DSS_CHANNEL_DIGIT) == false)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002714 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002715
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002716 src = dss_get_hdmi_venc_clk_source();
2717
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002718 /*
2719 * When we disable the digit output, we need to wait for FRAMEDONE to
2720 * know that DISPC has finished with the output. For analog tv out we'll
2721 * use vsync, as omap2/3 don't have framedone for TV.
2722 */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002723
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002724 if (src == DSS_HDMI_M_PCLK) {
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002725 irq_mask = DISPC_IRQ_FRAMEDONETV;
2726 num_irqs = 1;
2727 } else {
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002728 irq_mask = dispc_mgr_get_vsync_irq(OMAP_DSS_CHANNEL_DIGIT);
2729 /*
2730 * We need to wait for both even and odd vsyncs. Note that this
2731 * is not totally reliable, as we could get a vsync interrupt
2732 * before we disable the output, which leads to timeout in the
2733 * wait_for_completion.
2734 */
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002735 num_irqs = 2;
2736 }
2737
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002738 r = omap_dispc_register_isr(dispc_mgr_disable_isr, &framedone_compl,
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002739 irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002740 if (r)
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002741 DSSERR("failed to register %x isr\n", irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002742
Tomi Valkeinenf1a813d2012-10-19 14:16:06 +03002743 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, false);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002744
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002745 /* if we couldn't register the irq, just sleep and exit */
2746 if (r) {
2747 msleep(100);
2748 return;
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002749 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002750
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002751 for (i = 0; i < num_irqs; ++i) {
2752 if (!wait_for_completion_timeout(&framedone_compl,
2753 msecs_to_jiffies(100)))
2754 DSSERR("timeout waiting for digit out to stop\n");
2755 }
2756
2757 r = omap_dispc_unregister_isr(dispc_mgr_disable_isr, &framedone_compl,
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002758 irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002759 if (r)
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002760 DSSERR("failed to unregister %x isr\n", irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002761}
2762
Tomi Valkeinen3a979f82012-10-19 14:14:38 +03002763void dispc_mgr_enable_sync(enum omap_channel channel)
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002764{
Archit Tanejadd88b7a2012-06-29 14:41:30 +05302765 if (dss_mgr_is_lcd(channel))
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002766 dispc_mgr_enable_lcd_out(channel);
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002767 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002768 dispc_mgr_enable_digit_out();
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002769 else
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002770 WARN_ON(1);
2771}
2772
Tomi Valkeinen3a979f82012-10-19 14:14:38 +03002773void dispc_mgr_disable_sync(enum omap_channel channel)
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002774{
2775 if (dss_mgr_is_lcd(channel))
2776 dispc_mgr_disable_lcd_out(channel);
2777 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2778 dispc_mgr_disable_digit_out();
2779 else
2780 WARN_ON(1);
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002781}
2782
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302783void dispc_wb_enable(bool enable)
2784{
2785 enum omap_plane plane = OMAP_DSS_WB;
2786 struct completion frame_done_completion;
2787 bool is_on;
2788 int r;
2789 u32 irq;
2790
2791 is_on = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2792 irq = DISPC_IRQ_FRAMEDONEWB;
2793
2794 if (!enable && is_on) {
2795 init_completion(&frame_done_completion);
2796
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002797 r = omap_dispc_register_isr(dispc_mgr_disable_isr,
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302798 &frame_done_completion, irq);
2799 if (r)
2800 DSSERR("failed to register FRAMEDONEWB isr\n");
2801 }
2802
2803 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2804
2805 if (!enable && is_on) {
2806 if (!wait_for_completion_timeout(&frame_done_completion,
2807 msecs_to_jiffies(100)))
2808 DSSERR("timeout waiting for FRAMEDONEWB\n");
2809
Tomi Valkeinenb1112242012-10-10 12:48:31 +03002810 r = omap_dispc_unregister_isr(dispc_mgr_disable_isr,
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302811 &frame_done_completion, irq);
2812 if (r)
2813 DSSERR("failed to unregister FRAMEDONEWB isr\n");
2814 }
2815}
2816
2817bool dispc_wb_is_enabled(void)
2818{
2819 enum omap_plane plane = OMAP_DSS_WB;
2820
2821 return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2822}
2823
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002824static void dispc_lcd_enable_signal_polarity(bool act_high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002825{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002826 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2827 return;
2828
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002829 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002830}
2831
2832void dispc_lcd_enable_signal(bool enable)
2833{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002834 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2835 return;
2836
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002837 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002838}
2839
2840void dispc_pck_free_enable(bool enable)
2841{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002842 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2843 return;
2844
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002845 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002846}
2847
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002848static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002849{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302850 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002851}
2852
2853
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002854static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002855{
Archit Tanejad21f43b2012-06-21 09:45:11 +05302856 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002857}
2858
2859void dispc_set_loadmode(enum omap_dss_load_mode mode)
2860{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002861 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002862}
2863
2864
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002865static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002866{
Sumit Semwal8613b002010-12-02 11:27:09 +00002867 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002868}
2869
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002870static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002871 enum omap_dss_trans_key_type type,
2872 u32 trans_key)
2873{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302874 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002875
Sumit Semwal8613b002010-12-02 11:27:09 +00002876 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002877}
2878
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002879static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002880{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302881 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002882}
Archit Taneja11354dd2011-09-26 11:47:29 +05302883
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002884static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2885 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002886{
Archit Taneja11354dd2011-09-26 11:47:29 +05302887 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002888 return;
2889
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002890 if (ch == OMAP_DSS_CHANNEL_LCD)
2891 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002892 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002893 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002894}
Archit Taneja11354dd2011-09-26 11:47:29 +05302895
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002896void dispc_mgr_setup(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02002897 const struct omap_overlay_manager_info *info)
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002898{
2899 dispc_mgr_set_default_color(channel, info->default_color);
2900 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2901 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2902 dispc_mgr_enable_alpha_fixed_zorder(channel,
2903 info->partial_alpha_enabled);
2904 if (dss_has_feature(FEAT_CPR)) {
2905 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2906 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2907 }
2908}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002909
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002910static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002911{
2912 int code;
2913
2914 switch (data_lines) {
2915 case 12:
2916 code = 0;
2917 break;
2918 case 16:
2919 code = 1;
2920 break;
2921 case 18:
2922 code = 2;
2923 break;
2924 case 24:
2925 code = 3;
2926 break;
2927 default:
2928 BUG();
2929 return;
2930 }
2931
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302932 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002933}
2934
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002935static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002936{
2937 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302938 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002939
2940 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302941 case DSS_IO_PAD_MODE_RESET:
2942 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002943 gpout1 = 0;
2944 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302945 case DSS_IO_PAD_MODE_RFBI:
2946 gpout0 = 1;
2947 gpout1 = 0;
2948 break;
2949 case DSS_IO_PAD_MODE_BYPASS:
2950 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002951 gpout1 = 1;
2952 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002953 default:
2954 BUG();
2955 return;
2956 }
2957
Archit Taneja569969d2011-08-22 17:41:57 +05302958 l = dispc_read_reg(DISPC_CONTROL);
2959 l = FLD_MOD(l, gpout0, 15, 15);
2960 l = FLD_MOD(l, gpout1, 16, 16);
2961 dispc_write_reg(DISPC_CONTROL, l);
2962}
2963
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002964static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
Archit Taneja569969d2011-08-22 17:41:57 +05302965{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302966 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002967}
2968
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002969void dispc_mgr_set_lcd_config(enum omap_channel channel,
2970 const struct dss_lcd_mgr_config *config)
2971{
2972 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
2973
2974 dispc_mgr_enable_stallmode(channel, config->stallmode);
2975 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
2976
2977 dispc_mgr_set_clock_div(channel, &config->clock_info);
2978
2979 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
2980
2981 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
2982
2983 dispc_mgr_set_lcd_type_tft(channel);
2984}
2985
Archit Taneja8f366162012-04-16 12:53:44 +05302986static bool _dispc_mgr_size_ok(u16 width, u16 height)
2987{
2988 return width <= dss_feat_get_param_max(FEAT_PARAM_MGR_WIDTH) &&
2989 height <= dss_feat_get_param_max(FEAT_PARAM_MGR_HEIGHT);
2990}
2991
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002992static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2993 int vsw, int vfp, int vbp)
2994{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302995 if (hsw < 1 || hsw > dispc.feat->sw_max ||
2996 hfp < 1 || hfp > dispc.feat->hp_max ||
2997 hbp < 1 || hbp > dispc.feat->hp_max ||
2998 vsw < 1 || vsw > dispc.feat->sw_max ||
2999 vfp < 0 || vfp > dispc.feat->vp_max ||
3000 vbp < 0 || vbp > dispc.feat->vp_max)
3001 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003002 return true;
3003}
3004
Archit Taneja8f366162012-04-16 12:53:44 +05303005bool dispc_mgr_timings_ok(enum omap_channel channel,
Archit Tanejab917fa32012-04-27 01:07:28 +05303006 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003007{
Archit Taneja8f366162012-04-16 12:53:44 +05303008 bool timings_ok;
3009
3010 timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
3011
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303012 if (dss_mgr_is_lcd(channel))
Archit Taneja8f366162012-04-16 12:53:44 +05303013 timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
3014 timings->hfp, timings->hbp,
3015 timings->vsw, timings->vfp,
3016 timings->vbp);
3017
3018 return timings_ok;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003019}
3020
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003021static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
Archit Taneja655e2942012-06-21 10:37:43 +05303022 int hfp, int hbp, int vsw, int vfp, int vbp,
3023 enum omap_dss_signal_level vsync_level,
3024 enum omap_dss_signal_level hsync_level,
3025 enum omap_dss_signal_edge data_pclk_edge,
3026 enum omap_dss_signal_level de_level,
3027 enum omap_dss_signal_edge sync_pclk_edge)
3028
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003029{
Archit Taneja655e2942012-06-21 10:37:43 +05303030 u32 timing_h, timing_v, l;
3031 bool onoff, rf, ipc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003032
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303033 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
3034 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
3035 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
3036 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
3037 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
3038 FLD_VAL(vbp, dispc.feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003039
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003040 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
3041 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05303042
3043 switch (data_pclk_edge) {
3044 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3045 ipc = false;
3046 break;
3047 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3048 ipc = true;
3049 break;
3050 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
3051 default:
3052 BUG();
3053 }
3054
3055 switch (sync_pclk_edge) {
3056 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
3057 onoff = false;
3058 rf = false;
3059 break;
3060 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3061 onoff = true;
3062 rf = false;
3063 break;
3064 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3065 onoff = true;
3066 rf = true;
3067 break;
3068 default:
3069 BUG();
3070 };
3071
3072 l = dispc_read_reg(DISPC_POL_FREQ(channel));
3073 l |= FLD_VAL(onoff, 17, 17);
3074 l |= FLD_VAL(rf, 16, 16);
3075 l |= FLD_VAL(de_level, 15, 15);
3076 l |= FLD_VAL(ipc, 14, 14);
3077 l |= FLD_VAL(hsync_level, 13, 13);
3078 l |= FLD_VAL(vsync_level, 12, 12);
3079 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003080}
3081
3082/* change name to mode? */
Archit Tanejac51d9212012-04-16 12:53:43 +05303083void dispc_mgr_set_timings(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003084 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003085{
3086 unsigned xtot, ytot;
3087 unsigned long ht, vt;
Archit Taneja2aefad42012-05-18 14:36:54 +05303088 struct omap_video_timings t = *timings;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003089
Archit Taneja2aefad42012-05-18 14:36:54 +05303090 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
Archit Tanejac51d9212012-04-16 12:53:43 +05303091
Archit Taneja2aefad42012-05-18 14:36:54 +05303092 if (!dispc_mgr_timings_ok(channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05303093 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003094 return;
3095 }
Archit Tanejac51d9212012-04-16 12:53:43 +05303096
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303097 if (dss_mgr_is_lcd(channel)) {
Archit Taneja2aefad42012-05-18 14:36:54 +05303098 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
Archit Taneja655e2942012-06-21 10:37:43 +05303099 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
3100 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
Archit Tanejac51d9212012-04-16 12:53:43 +05303101
Archit Taneja2aefad42012-05-18 14:36:54 +05303102 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
3103 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
Archit Tanejac51d9212012-04-16 12:53:43 +05303104
3105 ht = (timings->pixel_clock * 1000) / xtot;
3106 vt = (timings->pixel_clock * 1000) / xtot / ytot;
3107
3108 DSSDBG("pck %u\n", timings->pixel_clock);
3109 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Archit Taneja2aefad42012-05-18 14:36:54 +05303110 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
Archit Taneja655e2942012-06-21 10:37:43 +05303111 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3112 t.vsync_level, t.hsync_level, t.data_pclk_edge,
3113 t.de_level, t.sync_pclk_edge);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003114
Archit Tanejac51d9212012-04-16 12:53:43 +05303115 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05303116 } else {
Archit Taneja23c8f882012-06-28 11:15:51 +05303117 if (t.interlace == true)
Archit Taneja2aefad42012-05-18 14:36:54 +05303118 t.y_res /= 2;
Archit Tanejac51d9212012-04-16 12:53:43 +05303119 }
Archit Taneja8f366162012-04-16 12:53:44 +05303120
Archit Taneja2aefad42012-05-18 14:36:54 +05303121 dispc_mgr_set_size(channel, t.x_res, t.y_res);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003122}
3123
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003124static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003125 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003126{
3127 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003128 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003129
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003130 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003131 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003132}
3133
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003134static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00003135 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003136{
3137 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003138 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003139 *lck_div = FLD_GET(l, 23, 16);
3140 *pck_div = FLD_GET(l, 7, 0);
3141}
3142
3143unsigned long dispc_fclk_rate(void)
3144{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303145 struct platform_device *dsidev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003146 unsigned long r = 0;
3147
Taneja, Archit66534e82011-03-08 05:50:34 -06003148 switch (dss_get_dispc_clk_source()) {
Archit Taneja89a35e52011-04-12 13:52:23 +05303149 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003150 r = clk_get_rate(dispc.dss_clk);
Taneja, Archit66534e82011-03-08 05:50:34 -06003151 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05303152 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303153 dsidev = dsi_get_dsidev_from_id(0);
3154 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
Taneja, Archit66534e82011-03-08 05:50:34 -06003155 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05303156 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3157 dsidev = dsi_get_dsidev_from_id(1);
3158 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
3159 break;
Taneja, Archit66534e82011-03-08 05:50:34 -06003160 default:
3161 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003162 return 0;
Taneja, Archit66534e82011-03-08 05:50:34 -06003163 }
3164
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003165 return r;
3166}
3167
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003168unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003169{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303170 struct platform_device *dsidev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003171 int lcd;
3172 unsigned long r;
3173 u32 l;
3174
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003175 if (dss_mgr_is_lcd(channel)) {
3176 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003177
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003178 lcd = FLD_GET(l, 23, 16);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003179
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003180 switch (dss_get_lcd_clk_source(channel)) {
3181 case OMAP_DSS_CLK_SRC_FCK:
3182 r = clk_get_rate(dispc.dss_clk);
3183 break;
3184 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
3185 dsidev = dsi_get_dsidev_from_id(0);
3186 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
3187 break;
3188 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3189 dsidev = dsi_get_dsidev_from_id(1);
3190 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
3191 break;
3192 default:
3193 BUG();
3194 return 0;
3195 }
3196
3197 return r / lcd;
3198 } else {
3199 return dispc_fclk_rate();
Taneja, Architea751592011-03-08 05:50:35 -06003200 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003201}
3202
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003203unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003204{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003205 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003206
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303207 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303208 int pcd;
3209 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003210
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303211 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003212
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303213 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003214
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303215 r = dispc_mgr_lclk_rate(channel);
3216
3217 return r / pcd;
3218 } else {
Archit Taneja3fa03ba2012-04-09 15:06:41 +05303219 enum dss_hdmi_venc_clk_source_select source;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303220
Archit Taneja3fa03ba2012-04-09 15:06:41 +05303221 source = dss_get_hdmi_venc_clk_source();
3222
3223 switch (source) {
3224 case DSS_VENC_TV_CLK:
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303225 return venc_get_pixel_clock();
Archit Taneja3fa03ba2012-04-09 15:06:41 +05303226 case DSS_HDMI_M_PCLK:
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303227 return hdmi_get_pixel_clock();
3228 default:
3229 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003230 return 0;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303231 }
3232 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003233}
3234
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303235unsigned long dispc_core_clk_rate(void)
3236{
3237 int lcd;
3238 unsigned long fclk = dispc_fclk_rate();
3239
3240 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3241 lcd = REG_GET(DISPC_DIVISOR, 23, 16);
3242 else
3243 lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
3244
3245 return fclk / lcd;
3246}
3247
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303248static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3249{
3250 enum omap_channel channel = dispc_ovl_get_channel_out(plane);
3251
3252 return dispc_mgr_pclk_rate(channel);
3253}
3254
3255static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3256{
3257 enum omap_channel channel = dispc_ovl_get_channel_out(plane);
3258
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003259 return dispc_mgr_lclk_rate(channel);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303260}
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003261
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303262static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003263{
3264 int lcd, pcd;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303265 enum omap_dss_clk_source lcd_clk_src;
3266
3267 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3268
3269 lcd_clk_src = dss_get_lcd_clk_source(channel);
3270
3271 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3272 dss_get_generic_clk_source_name(lcd_clk_src),
3273 dss_feat_get_clk_source_name(lcd_clk_src));
3274
3275 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3276
3277 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3278 dispc_mgr_lclk_rate(channel), lcd);
3279 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3280 dispc_mgr_pclk_rate(channel), pcd);
3281}
3282
3283void dispc_dump_clocks(struct seq_file *s)
3284{
3285 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003286 u32 l;
Archit Taneja89a35e52011-04-12 13:52:23 +05303287 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003288
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003289 if (dispc_runtime_get())
3290 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003291
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003292 seq_printf(s, "- DISPC -\n");
3293
Archit Taneja067a57e2011-03-02 11:57:25 +05303294 seq_printf(s, "dispc fclk source = %s (%s)\n",
3295 dss_get_generic_clk_source_name(dispc_clk_src),
3296 dss_feat_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003297
3298 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00003299
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003300 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3301 seq_printf(s, "- DISPC-CORE-CLK -\n");
3302 l = dispc_read_reg(DISPC_DIVISOR);
3303 lcd = FLD_GET(l, 23, 16);
3304
3305 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3306 (dispc_fclk_rate()/lcd), lcd);
3307 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003308
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303309 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003310
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303311 if (dss_has_feature(FEAT_MGR_LCD2))
3312 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3313 if (dss_has_feature(FEAT_MGR_LCD3))
3314 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003315
3316 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003317}
3318
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003319#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3320void dispc_dump_irqs(struct seq_file *s)
3321{
3322 unsigned long flags;
3323 struct dispc_irq_stats stats;
3324
3325 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
3326
3327 stats = dispc.irq_stats;
3328 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
3329 dispc.irq_stats.last_reset = jiffies;
3330
3331 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
3332
3333 seq_printf(s, "period %u ms\n",
3334 jiffies_to_msecs(jiffies - stats.last_reset));
3335
3336 seq_printf(s, "irqs %d\n", stats.irq_count);
3337#define PIS(x) \
3338 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
3339
3340 PIS(FRAMEDONE);
3341 PIS(VSYNC);
3342 PIS(EVSYNC_EVEN);
3343 PIS(EVSYNC_ODD);
3344 PIS(ACBIAS_COUNT_STAT);
3345 PIS(PROG_LINE_NUM);
3346 PIS(GFX_FIFO_UNDERFLOW);
3347 PIS(GFX_END_WIN);
3348 PIS(PAL_GAMMA_MASK);
3349 PIS(OCP_ERR);
3350 PIS(VID1_FIFO_UNDERFLOW);
3351 PIS(VID1_END_WIN);
3352 PIS(VID2_FIFO_UNDERFLOW);
3353 PIS(VID2_END_WIN);
Archit Tanejab8c095b2011-09-13 18:20:33 +05303354 if (dss_feat_get_num_ovls() > 3) {
3355 PIS(VID3_FIFO_UNDERFLOW);
3356 PIS(VID3_END_WIN);
3357 }
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003358 PIS(SYNC_LOST);
3359 PIS(SYNC_LOST_DIGIT);
3360 PIS(WAKEUP);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003361 if (dss_has_feature(FEAT_MGR_LCD2)) {
3362 PIS(FRAMEDONE2);
3363 PIS(VSYNC2);
3364 PIS(ACBIAS_COUNT_STAT2);
3365 PIS(SYNC_LOST2);
3366 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303367 if (dss_has_feature(FEAT_MGR_LCD3)) {
3368 PIS(FRAMEDONE3);
3369 PIS(VSYNC3);
3370 PIS(ACBIAS_COUNT_STAT3);
3371 PIS(SYNC_LOST3);
3372 }
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003373#undef PIS
3374}
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003375#endif
3376
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003377static void dispc_dump_regs(struct seq_file *s)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003378{
Archit Taneja4dd2da12011-08-05 19:06:01 +05303379 int i, j;
3380 const char *mgr_names[] = {
3381 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3382 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3383 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303384 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303385 };
3386 const char *ovl_names[] = {
3387 [OMAP_DSS_GFX] = "GFX",
3388 [OMAP_DSS_VIDEO1] = "VID1",
3389 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303390 [OMAP_DSS_VIDEO3] = "VID3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303391 };
3392 const char **p_names;
3393
Archit Taneja9b372c22011-05-06 11:45:49 +05303394#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003395
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003396 if (dispc_runtime_get())
3397 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003398
Archit Taneja5010be82011-08-05 19:06:00 +05303399 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003400 DUMPREG(DISPC_REVISION);
3401 DUMPREG(DISPC_SYSCONFIG);
3402 DUMPREG(DISPC_SYSSTATUS);
3403 DUMPREG(DISPC_IRQSTATUS);
3404 DUMPREG(DISPC_IRQENABLE);
3405 DUMPREG(DISPC_CONTROL);
3406 DUMPREG(DISPC_CONFIG);
3407 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003408 DUMPREG(DISPC_LINE_STATUS);
3409 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05303410 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3411 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003412 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003413 if (dss_has_feature(FEAT_MGR_LCD2)) {
3414 DUMPREG(DISPC_CONTROL2);
3415 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003416 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303417 if (dss_has_feature(FEAT_MGR_LCD3)) {
3418 DUMPREG(DISPC_CONTROL3);
3419 DUMPREG(DISPC_CONFIG3);
3420 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003421
Archit Taneja5010be82011-08-05 19:06:00 +05303422#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003423
Archit Taneja5010be82011-08-05 19:06:00 +05303424#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05303425#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003426 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303427 dispc_read_reg(DISPC_REG(i, r)))
3428
Archit Taneja4dd2da12011-08-05 19:06:01 +05303429 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303430
Archit Taneja4dd2da12011-08-05 19:06:01 +05303431 /* DISPC channel specific registers */
3432 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3433 DUMPREG(i, DISPC_DEFAULT_COLOR);
3434 DUMPREG(i, DISPC_TRANS_COLOR);
3435 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003436
Archit Taneja4dd2da12011-08-05 19:06:01 +05303437 if (i == OMAP_DSS_CHANNEL_DIGIT)
3438 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303439
Archit Taneja4dd2da12011-08-05 19:06:01 +05303440 DUMPREG(i, DISPC_DEFAULT_COLOR);
3441 DUMPREG(i, DISPC_TRANS_COLOR);
3442 DUMPREG(i, DISPC_TIMING_H);
3443 DUMPREG(i, DISPC_TIMING_V);
3444 DUMPREG(i, DISPC_POL_FREQ);
3445 DUMPREG(i, DISPC_DIVISORo);
3446 DUMPREG(i, DISPC_SIZE_MGR);
Archit Taneja5010be82011-08-05 19:06:00 +05303447
Archit Taneja4dd2da12011-08-05 19:06:01 +05303448 DUMPREG(i, DISPC_DATA_CYCLE1);
3449 DUMPREG(i, DISPC_DATA_CYCLE2);
3450 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003451
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003452 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303453 DUMPREG(i, DISPC_CPR_COEF_R);
3454 DUMPREG(i, DISPC_CPR_COEF_G);
3455 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003456 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003457 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003458
Archit Taneja4dd2da12011-08-05 19:06:01 +05303459 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003460
Archit Taneja4dd2da12011-08-05 19:06:01 +05303461 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3462 DUMPREG(i, DISPC_OVL_BA0);
3463 DUMPREG(i, DISPC_OVL_BA1);
3464 DUMPREG(i, DISPC_OVL_POSITION);
3465 DUMPREG(i, DISPC_OVL_SIZE);
3466 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3467 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3468 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3469 DUMPREG(i, DISPC_OVL_ROW_INC);
3470 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3471 if (dss_has_feature(FEAT_PRELOAD))
3472 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003473
Archit Taneja4dd2da12011-08-05 19:06:01 +05303474 if (i == OMAP_DSS_GFX) {
3475 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3476 DUMPREG(i, DISPC_OVL_TABLE_BA);
3477 continue;
3478 }
3479
3480 DUMPREG(i, DISPC_OVL_FIR);
3481 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3482 DUMPREG(i, DISPC_OVL_ACCU0);
3483 DUMPREG(i, DISPC_OVL_ACCU1);
3484 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3485 DUMPREG(i, DISPC_OVL_BA0_UV);
3486 DUMPREG(i, DISPC_OVL_BA1_UV);
3487 DUMPREG(i, DISPC_OVL_FIR2);
3488 DUMPREG(i, DISPC_OVL_ACCU2_0);
3489 DUMPREG(i, DISPC_OVL_ACCU2_1);
3490 }
3491 if (dss_has_feature(FEAT_ATTR2))
3492 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3493 if (dss_has_feature(FEAT_PRELOAD))
3494 DUMPREG(i, DISPC_OVL_PRELOAD);
Archit Taneja5010be82011-08-05 19:06:00 +05303495 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003496
Archit Taneja5010be82011-08-05 19:06:00 +05303497#undef DISPC_REG
3498#undef DUMPREG
3499
3500#define DISPC_REG(plane, name, i) name(plane, i)
3501#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303502 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003503 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303504 dispc_read_reg(DISPC_REG(plane, name, i)))
3505
Archit Taneja4dd2da12011-08-05 19:06:01 +05303506 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303507
Archit Taneja4dd2da12011-08-05 19:06:01 +05303508 /* start from OMAP_DSS_VIDEO1 */
3509 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3510 for (j = 0; j < 8; j++)
3511 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303512
Archit Taneja4dd2da12011-08-05 19:06:01 +05303513 for (j = 0; j < 8; j++)
3514 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303515
Archit Taneja4dd2da12011-08-05 19:06:01 +05303516 for (j = 0; j < 5; j++)
3517 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003518
Archit Taneja4dd2da12011-08-05 19:06:01 +05303519 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3520 for (j = 0; j < 8; j++)
3521 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3522 }
Amber Jainab5ca072011-05-19 19:47:53 +05303523
Archit Taneja4dd2da12011-08-05 19:06:01 +05303524 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3525 for (j = 0; j < 8; j++)
3526 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303527
Archit Taneja4dd2da12011-08-05 19:06:01 +05303528 for (j = 0; j < 8; j++)
3529 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303530
Archit Taneja4dd2da12011-08-05 19:06:01 +05303531 for (j = 0; j < 8; j++)
3532 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3533 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003534 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003535
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003536 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05303537
3538#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003539#undef DUMPREG
3540}
3541
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003542/* with fck as input clock rate, find dispc dividers that produce req_pck */
Archit Taneja6d523e72012-06-21 09:33:55 +05303543void dispc_find_clk_divs(unsigned long req_pck, unsigned long fck,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003544 struct dispc_clock_info *cinfo)
3545{
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003546 u16 pcd_min, pcd_max;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003547 unsigned long best_pck;
3548 u16 best_ld, cur_ld;
3549 u16 best_pd, cur_pd;
3550
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003551 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3552 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3553
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003554 best_pck = 0;
3555 best_ld = 0;
3556 best_pd = 0;
3557
3558 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
3559 unsigned long lck = fck / cur_ld;
3560
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003561 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003562 unsigned long pck = lck / cur_pd;
3563 long old_delta = abs(best_pck - req_pck);
3564 long new_delta = abs(pck - req_pck);
3565
3566 if (best_pck == 0 || new_delta < old_delta) {
3567 best_pck = pck;
3568 best_ld = cur_ld;
3569 best_pd = cur_pd;
3570
3571 if (pck == req_pck)
3572 goto found;
3573 }
3574
3575 if (pck < req_pck)
3576 break;
3577 }
3578
3579 if (lck / pcd_min < req_pck)
3580 break;
3581 }
3582
3583found:
3584 cinfo->lck_div = best_ld;
3585 cinfo->pck_div = best_pd;
3586 cinfo->lck = fck / cinfo->lck_div;
3587 cinfo->pck = cinfo->lck / cinfo->pck_div;
3588}
3589
3590/* calculate clock rates using dividers in cinfo */
3591int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3592 struct dispc_clock_info *cinfo)
3593{
3594 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3595 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003596 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003597 return -EINVAL;
3598
3599 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3600 cinfo->pck = cinfo->lck / cinfo->pck_div;
3601
3602 return 0;
3603}
3604
Archit Tanejaf0d08f82012-06-29 14:00:54 +05303605void dispc_mgr_set_clock_div(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003606 const struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003607{
3608 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3609 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3610
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003611 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003612}
3613
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003614int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003615 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003616{
3617 unsigned long fck;
3618
3619 fck = dispc_fclk_rate();
3620
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003621 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3622 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003623
3624 cinfo->lck = fck / cinfo->lck_div;
3625 cinfo->pck = cinfo->lck / cinfo->pck_div;
3626
3627 return 0;
3628}
3629
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003630u32 dispc_read_irqstatus(void)
3631{
3632 return dispc_read_reg(DISPC_IRQSTATUS);
3633}
3634
3635void dispc_clear_irqstatus(u32 mask)
3636{
3637 dispc_write_reg(DISPC_IRQSTATUS, mask);
3638}
3639
3640u32 dispc_read_irqenable(void)
3641{
3642 return dispc_read_reg(DISPC_IRQENABLE);
3643}
3644
3645void dispc_write_irqenable(u32 mask)
3646{
3647 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3648
3649 /* clear the irqstatus for newly enabled irqs */
3650 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3651
3652 dispc_write_reg(DISPC_IRQENABLE, mask);
3653}
3654
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003655/* dispc.irq_lock has to be locked by the caller */
3656static void _omap_dispc_set_irqs(void)
3657{
3658 u32 mask;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003659 int i;
3660 struct omap_dispc_isr_data *isr_data;
3661
3662 mask = dispc.irq_error_mask;
3663
3664 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3665 isr_data = &dispc.registered_isr[i];
3666
3667 if (isr_data->isr == NULL)
3668 continue;
3669
3670 mask |= isr_data->mask;
3671 }
3672
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003673 dispc_write_irqenable(mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003674}
3675
3676int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3677{
3678 int i;
3679 int ret;
3680 unsigned long flags;
3681 struct omap_dispc_isr_data *isr_data;
3682
3683 if (isr == NULL)
3684 return -EINVAL;
3685
3686 spin_lock_irqsave(&dispc.irq_lock, flags);
3687
3688 /* check for duplicate entry */
3689 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3690 isr_data = &dispc.registered_isr[i];
3691 if (isr_data->isr == isr && isr_data->arg == arg &&
3692 isr_data->mask == mask) {
3693 ret = -EINVAL;
3694 goto err;
3695 }
3696 }
3697
3698 isr_data = NULL;
3699 ret = -EBUSY;
3700
3701 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3702 isr_data = &dispc.registered_isr[i];
3703
3704 if (isr_data->isr != NULL)
3705 continue;
3706
3707 isr_data->isr = isr;
3708 isr_data->arg = arg;
3709 isr_data->mask = mask;
3710 ret = 0;
3711
3712 break;
3713 }
3714
Tomi Valkeinenb9cb0982011-03-04 18:19:54 +02003715 if (ret)
3716 goto err;
3717
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003718 _omap_dispc_set_irqs();
3719
3720 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3721
3722 return 0;
3723err:
3724 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3725
3726 return ret;
3727}
3728EXPORT_SYMBOL(omap_dispc_register_isr);
3729
3730int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3731{
3732 int i;
3733 unsigned long flags;
3734 int ret = -EINVAL;
3735 struct omap_dispc_isr_data *isr_data;
3736
3737 spin_lock_irqsave(&dispc.irq_lock, flags);
3738
3739 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3740 isr_data = &dispc.registered_isr[i];
3741 if (isr_data->isr != isr || isr_data->arg != arg ||
3742 isr_data->mask != mask)
3743 continue;
3744
3745 /* found the correct isr */
3746
3747 isr_data->isr = NULL;
3748 isr_data->arg = NULL;
3749 isr_data->mask = 0;
3750
3751 ret = 0;
3752 break;
3753 }
3754
3755 if (ret == 0)
3756 _omap_dispc_set_irqs();
3757
3758 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3759
3760 return ret;
3761}
3762EXPORT_SYMBOL(omap_dispc_unregister_isr);
3763
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003764static void print_irq_status(u32 status)
3765{
3766 if ((status & dispc.irq_error_mask) == 0)
3767 return;
3768
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +05303769#define PIS(x) (status & DISPC_IRQ_##x) ? (#x " ") : ""
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003770
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +05303771 pr_debug("DISPC IRQ: 0x%x: %s%s%s%s%s%s%s%s%s\n",
3772 status,
3773 PIS(OCP_ERR),
3774 PIS(GFX_FIFO_UNDERFLOW),
3775 PIS(VID1_FIFO_UNDERFLOW),
3776 PIS(VID2_FIFO_UNDERFLOW),
3777 dss_feat_get_num_ovls() > 3 ? PIS(VID3_FIFO_UNDERFLOW) : "",
3778 PIS(SYNC_LOST),
3779 PIS(SYNC_LOST_DIGIT),
3780 dss_has_feature(FEAT_MGR_LCD2) ? PIS(SYNC_LOST2) : "",
3781 dss_has_feature(FEAT_MGR_LCD3) ? PIS(SYNC_LOST3) : "");
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003782#undef PIS
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003783}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003784
3785/* Called from dss.c. Note that we don't touch clocks here,
3786 * but we presume they are on because we got an IRQ. However,
3787 * an irq handler may turn the clocks off, so we may not have
3788 * clock later in the function. */
archit tanejaaffe3602011-02-23 08:41:03 +00003789static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003790{
3791 int i;
archit tanejaaffe3602011-02-23 08:41:03 +00003792 u32 irqstatus, irqenable;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003793 u32 handledirqs = 0;
3794 u32 unhandled_errors;
3795 struct omap_dispc_isr_data *isr_data;
3796 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
3797
3798 spin_lock(&dispc.irq_lock);
3799
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003800 irqstatus = dispc_read_irqstatus();
3801 irqenable = dispc_read_irqenable();
archit tanejaaffe3602011-02-23 08:41:03 +00003802
3803 /* IRQ is not for us */
3804 if (!(irqstatus & irqenable)) {
3805 spin_unlock(&dispc.irq_lock);
3806 return IRQ_NONE;
3807 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003808
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003809#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3810 spin_lock(&dispc.irq_stats_lock);
3811 dispc.irq_stats.irq_count++;
3812 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
3813 spin_unlock(&dispc.irq_stats_lock);
3814#endif
3815
Chandrabhanu Mahapatra28bcd192012-09-29 13:57:31 +05303816 print_irq_status(irqstatus);
3817
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003818 /* Ack the interrupt. Do it here before clocks are possibly turned
3819 * off */
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003820 dispc_clear_irqstatus(irqstatus);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003821 /* flush posted write */
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003822 dispc_read_irqstatus();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003823
3824 /* make a copy and unlock, so that isrs can unregister
3825 * themselves */
3826 memcpy(registered_isr, dispc.registered_isr,
3827 sizeof(registered_isr));
3828
3829 spin_unlock(&dispc.irq_lock);
3830
3831 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3832 isr_data = &registered_isr[i];
3833
3834 if (!isr_data->isr)
3835 continue;
3836
3837 if (isr_data->mask & irqstatus) {
3838 isr_data->isr(isr_data->arg, irqstatus);
3839 handledirqs |= isr_data->mask;
3840 }
3841 }
3842
3843 spin_lock(&dispc.irq_lock);
3844
3845 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3846
3847 if (unhandled_errors) {
3848 dispc.error_irqs |= unhandled_errors;
3849
3850 dispc.irq_error_mask &= ~unhandled_errors;
3851 _omap_dispc_set_irqs();
3852
3853 schedule_work(&dispc.error_work);
3854 }
3855
3856 spin_unlock(&dispc.irq_lock);
archit tanejaaffe3602011-02-23 08:41:03 +00003857
3858 return IRQ_HANDLED;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003859}
3860
3861static void dispc_error_worker(struct work_struct *work)
3862{
3863 int i;
3864 u32 errors;
3865 unsigned long flags;
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003866 static const unsigned fifo_underflow_bits[] = {
3867 DISPC_IRQ_GFX_FIFO_UNDERFLOW,
3868 DISPC_IRQ_VID1_FIFO_UNDERFLOW,
3869 DISPC_IRQ_VID2_FIFO_UNDERFLOW,
Archit Tanejab8c095b2011-09-13 18:20:33 +05303870 DISPC_IRQ_VID3_FIFO_UNDERFLOW,
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003871 };
3872
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003873 spin_lock_irqsave(&dispc.irq_lock, flags);
3874 errors = dispc.error_irqs;
3875 dispc.error_irqs = 0;
3876 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3877
Dima Zavin13eae1f2011-06-27 10:31:05 -07003878 dispc_runtime_get();
3879
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003880 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3881 struct omap_overlay *ovl;
3882 unsigned bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003883
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003884 ovl = omap_dss_get_overlay(i);
3885 bit = fifo_underflow_bits[i];
3886
3887 if (bit & errors) {
3888 DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
3889 ovl->name);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03003890 dispc_ovl_enable(ovl->id, false);
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003891 dispc_mgr_go(ovl->manager->id);
Jassi Brard7ad7182012-07-24 19:33:55 +05303892 msleep(50);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003893 }
3894 }
3895
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003896 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3897 struct omap_overlay_manager *mgr;
3898 unsigned bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003899
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003900 mgr = omap_dss_get_overlay_manager(i);
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05303901 bit = mgr_desc[i].sync_lost_irq;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003902
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003903 if (bit & errors) {
Tomi Valkeinen4c6c65b2012-10-24 09:20:40 +03003904 int j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003905
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003906 DSSERR("SYNC_LOST on channel %s, restarting the output "
3907 "with video overlays disabled\n",
3908 mgr->name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003909
Tomi Valkeinenb276dd02012-06-15 15:34:24 +03003910 dss_mgr_disable(mgr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003911
Tomi Valkeinen4c6c65b2012-10-24 09:20:40 +03003912 for (j = 0; j < omap_dss_get_num_overlays(); ++j) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003913 struct omap_overlay *ovl;
Tomi Valkeinen4c6c65b2012-10-24 09:20:40 +03003914 ovl = omap_dss_get_overlay(j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003915
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003916 if (ovl->id != OMAP_DSS_GFX &&
3917 ovl->manager == mgr)
Tomi Valkeinenb276dd02012-06-15 15:34:24 +03003918 ovl->disable(ovl);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003919 }
3920
Tomi Valkeinenb276dd02012-06-15 15:34:24 +03003921 dss_mgr_enable(mgr);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003922 }
3923 }
3924
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003925 if (errors & DISPC_IRQ_OCP_ERR) {
3926 DSSERR("OCP_ERR\n");
3927 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3928 struct omap_overlay_manager *mgr;
Archit Taneja794bc4e2012-09-07 17:44:51 +05303929
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003930 mgr = omap_dss_get_overlay_manager(i);
Tomi Valkeinenb276dd02012-06-15 15:34:24 +03003931 dss_mgr_disable(mgr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003932 }
3933 }
3934
3935 spin_lock_irqsave(&dispc.irq_lock, flags);
3936 dispc.irq_error_mask |= errors;
3937 _omap_dispc_set_irqs();
3938 spin_unlock_irqrestore(&dispc.irq_lock, flags);
Dima Zavin13eae1f2011-06-27 10:31:05 -07003939
3940 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003941}
3942
3943int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3944{
3945 void dispc_irq_wait_handler(void *data, u32 mask)
3946 {
3947 complete((struct completion *)data);
3948 }
3949
3950 int r;
3951 DECLARE_COMPLETION_ONSTACK(completion);
3952
3953 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3954 irqmask);
3955
3956 if (r)
3957 return r;
3958
3959 timeout = wait_for_completion_timeout(&completion, timeout);
3960
3961 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3962
3963 if (timeout == 0)
3964 return -ETIMEDOUT;
3965
3966 if (timeout == -ERESTARTSYS)
3967 return -ERESTARTSYS;
3968
3969 return 0;
3970}
3971
3972int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3973 unsigned long timeout)
3974{
3975 void dispc_irq_wait_handler(void *data, u32 mask)
3976 {
3977 complete((struct completion *)data);
3978 }
3979
3980 int r;
3981 DECLARE_COMPLETION_ONSTACK(completion);
3982
3983 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3984 irqmask);
3985
3986 if (r)
3987 return r;
3988
3989 timeout = wait_for_completion_interruptible_timeout(&completion,
3990 timeout);
3991
3992 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3993
3994 if (timeout == 0)
3995 return -ETIMEDOUT;
3996
3997 if (timeout == -ERESTARTSYS)
3998 return -ERESTARTSYS;
3999
4000 return 0;
4001}
4002
Tomi Valkeinen80c39712009-11-12 11:41:42 +02004003static void _omap_dispc_initialize_irq(void)
4004{
4005 unsigned long flags;
4006
4007 spin_lock_irqsave(&dispc.irq_lock, flags);
4008
4009 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
4010
4011 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
Sumit Semwal2a205f32010-12-02 11:27:12 +00004012 if (dss_has_feature(FEAT_MGR_LCD2))
4013 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05304014 if (dss_has_feature(FEAT_MGR_LCD3))
4015 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST3;
Archit Tanejab8c095b2011-09-13 18:20:33 +05304016 if (dss_feat_get_num_ovls() > 3)
4017 dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02004018
4019 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
4020 * so clear it */
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03004021 dispc_clear_irqstatus(dispc_read_irqstatus());
Tomi Valkeinen80c39712009-11-12 11:41:42 +02004022
4023 _omap_dispc_set_irqs();
4024
4025 spin_unlock_irqrestore(&dispc.irq_lock, flags);
4026}
4027
4028void dispc_enable_sidle(void)
4029{
4030 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
4031}
4032
4033void dispc_disable_sidle(void)
4034{
4035 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
4036}
4037
4038static void _omap_dispc_initial_config(void)
4039{
4040 u32 l;
4041
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06004042 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
4043 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
4044 l = dispc_read_reg(DISPC_DIVISOR);
4045 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
4046 l = FLD_MOD(l, 1, 0, 0);
4047 l = FLD_MOD(l, 1, 23, 16);
4048 dispc_write_reg(DISPC_DIVISOR, l);
4049 }
4050
Tomi Valkeinen80c39712009-11-12 11:41:42 +02004051 /* FUNCGATED */
Archit Taneja6ced40b2010-12-02 11:27:13 +00004052 if (dss_has_feature(FEAT_FUNCGATED))
4053 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02004054
Archit Taneja6e5264b2012-09-11 12:04:47 +05304055 dispc_setup_color_conv_coef();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02004056
4057 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
4058
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004059 dispc_init_fifos();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03004060
4061 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05304062
4063 dispc_ovl_enable_zorder_planes();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02004064}
4065
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304066static const struct dispc_features omap24xx_dispc_feats __initconst = {
4067 .sw_start = 5,
4068 .fp_start = 15,
4069 .bp_start = 27,
4070 .sw_max = 64,
4071 .vp_max = 255,
4072 .hp_max = 256,
4073 .calc_scaling = dispc_ovl_calc_scaling_24xx,
4074 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004075 .num_fifos = 3,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304076};
4077
4078static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
4079 .sw_start = 5,
4080 .fp_start = 15,
4081 .bp_start = 27,
4082 .sw_max = 64,
4083 .vp_max = 255,
4084 .hp_max = 256,
4085 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4086 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004087 .num_fifos = 3,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304088};
4089
4090static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
4091 .sw_start = 7,
4092 .fp_start = 19,
4093 .bp_start = 31,
4094 .sw_max = 256,
4095 .vp_max = 4095,
4096 .hp_max = 4096,
4097 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4098 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004099 .num_fifos = 3,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304100};
4101
4102static const struct dispc_features omap44xx_dispc_feats __initconst = {
4103 .sw_start = 7,
4104 .fp_start = 19,
4105 .bp_start = 31,
4106 .sw_max = 256,
4107 .vp_max = 4095,
4108 .hp_max = 4096,
4109 .calc_scaling = dispc_ovl_calc_scaling_44xx,
4110 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004111 .num_fifos = 5,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03004112 .gfx_fifo_workaround = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304113};
4114
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004115static int __init dispc_init_features(struct platform_device *pdev)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304116{
4117 const struct dispc_features *src;
4118 struct dispc_features *dst;
4119
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004120 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304121 if (!dst) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004122 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304123 return -ENOMEM;
4124 }
4125
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +03004126 switch (omapdss_get_version()) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004127 case OMAPDSS_VER_OMAP24xx:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304128 src = &omap24xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004129 break;
4130
4131 case OMAPDSS_VER_OMAP34xx_ES1:
4132 src = &omap34xx_rev1_0_dispc_feats;
4133 break;
4134
4135 case OMAPDSS_VER_OMAP34xx_ES3:
4136 case OMAPDSS_VER_OMAP3630:
4137 case OMAPDSS_VER_AM35xx:
4138 src = &omap34xx_rev3_0_dispc_feats;
4139 break;
4140
4141 case OMAPDSS_VER_OMAP4430_ES1:
4142 case OMAPDSS_VER_OMAP4430_ES2:
4143 case OMAPDSS_VER_OMAP4:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304144 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004145 break;
4146
4147 case OMAPDSS_VER_OMAP5:
Archit Taneja23362832012-04-08 16:47:01 +05304148 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004149 break;
4150
4151 default:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304152 return -ENODEV;
4153 }
4154
4155 memcpy(dst, src, sizeof(*dst));
4156 dispc.feat = dst;
4157
4158 return 0;
4159}
4160
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004161/* DISPC HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004162static int __init omap_dispchw_probe(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004163{
4164 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00004165 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004166 struct resource *dispc_mem;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004167 struct clk *clk;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004168
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004169 dispc.pdev = pdev;
4170
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004171 r = dispc_init_features(dispc.pdev);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304172 if (r)
4173 return r;
4174
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004175 spin_lock_init(&dispc.irq_lock);
4176
4177#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
4178 spin_lock_init(&dispc.irq_stats_lock);
4179 dispc.irq_stats.last_reset = jiffies;
4180#endif
4181
4182 INIT_WORK(&dispc.error_work, dispc_error_worker);
4183
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004184 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
4185 if (!dispc_mem) {
4186 DSSERR("can't get IORESOURCE_MEM DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004187 return -EINVAL;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004188 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004189
Julia Lawall6e2a14d2012-01-24 14:00:45 +01004190 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
4191 resource_size(dispc_mem));
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004192 if (!dispc.base) {
4193 DSSERR("can't ioremap DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004194 return -ENOMEM;
archit tanejaaffe3602011-02-23 08:41:03 +00004195 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004196
archit tanejaaffe3602011-02-23 08:41:03 +00004197 dispc.irq = platform_get_irq(dispc.pdev, 0);
4198 if (dispc.irq < 0) {
4199 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004200 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00004201 }
4202
Julia Lawall6e2a14d2012-01-24 14:00:45 +01004203 r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
4204 IRQF_SHARED, "OMAP DISPC", dispc.pdev);
archit tanejaaffe3602011-02-23 08:41:03 +00004205 if (r < 0) {
4206 DSSERR("request_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004207 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004208 }
4209
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004210 clk = clk_get(&pdev->dev, "fck");
4211 if (IS_ERR(clk)) {
4212 DSSERR("can't get fck\n");
4213 r = PTR_ERR(clk);
4214 return r;
4215 }
4216
4217 dispc.dss_clk = clk;
4218
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004219 pm_runtime_enable(&pdev->dev);
4220
4221 r = dispc_runtime_get();
4222 if (r)
4223 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004224
4225 _omap_dispc_initial_config();
4226
4227 _omap_dispc_initialize_irq();
4228
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004229 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00004230 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004231 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4232
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004233 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004234
Tomi Valkeinene40402c2012-03-02 18:01:07 +02004235 dss_debugfs_create_file("dispc", dispc_dump_regs);
4236
4237#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
4238 dss_debugfs_create_file("dispc_irq", dispc_dump_irqs);
4239#endif
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004240 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004241
4242err_runtime_get:
4243 pm_runtime_disable(&pdev->dev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004244 clk_put(dispc.dss_clk);
archit tanejaaffe3602011-02-23 08:41:03 +00004245 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004246}
4247
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004248static int __exit omap_dispchw_remove(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004249{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004250 pm_runtime_disable(&pdev->dev);
4251
4252 clk_put(dispc.dss_clk);
4253
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004254 return 0;
4255}
4256
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004257static int dispc_runtime_suspend(struct device *dev)
4258{
4259 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004260
4261 return 0;
4262}
4263
4264static int dispc_runtime_resume(struct device *dev)
4265{
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +03004266 dispc_restore_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004267
4268 return 0;
4269}
4270
4271static const struct dev_pm_ops dispc_pm_ops = {
4272 .runtime_suspend = dispc_runtime_suspend,
4273 .runtime_resume = dispc_runtime_resume,
4274};
4275
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004276static struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004277 .remove = __exit_p(omap_dispchw_remove),
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004278 .driver = {
4279 .name = "omapdss_dispc",
4280 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004281 .pm = &dispc_pm_ops,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004282 },
4283};
4284
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004285int __init dispc_init_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004286{
Tomi Valkeinen11436e12012-03-07 12:53:18 +02004287 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004288}
4289
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004290void __exit dispc_uninit_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004291{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02004292 platform_driver_unregister(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004293}