blob: d30e5fa1864a99b94482da6bfdad2d5d84f5605e [file] [log] [blame]
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001/*
2 * linux/drivers/video/omap2/dss/dispc.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#define DSS_SUBSYS_NAME "DISPC"
24
25#include <linux/kernel.h>
26#include <linux/dma-mapping.h>
27#include <linux/vmalloc.h>
Paul Gortmakera8a35932011-07-10 13:20:26 -040028#include <linux/export.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020029#include <linux/clk.h>
30#include <linux/io.h>
31#include <linux/jiffies.h>
32#include <linux/seq_file.h>
33#include <linux/delay.h>
34#include <linux/workqueue.h>
Tomi Valkeinenab83b142010-06-09 15:31:01 +030035#include <linux/hardirq.h>
archit tanejaaffe3602011-02-23 08:41:03 +000036#include <linux/interrupt.h>
Tomi Valkeinen24e62892011-05-23 11:51:18 +030037#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030038#include <linux/pm_runtime.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020039
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070040#include <plat/cpu.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020041
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030042#include <video/omapdss.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020043
44#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053045#include "dss_features.h"
Archit Taneja9b372c22011-05-06 11:45:49 +053046#include "dispc.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020047
48/* DISPC */
Sumit Semwal8613b002010-12-02 11:27:09 +000049#define DISPC_SZ_REGS SZ_4K
Tomi Valkeinen80c39712009-11-12 11:41:42 +020050
Tomi Valkeinen80c39712009-11-12 11:41:42 +020051#define DISPC_IRQ_MASK_ERROR (DISPC_IRQ_GFX_FIFO_UNDERFLOW | \
52 DISPC_IRQ_OCP_ERR | \
53 DISPC_IRQ_VID1_FIFO_UNDERFLOW | \
54 DISPC_IRQ_VID2_FIFO_UNDERFLOW | \
55 DISPC_IRQ_SYNC_LOST | \
56 DISPC_IRQ_SYNC_LOST_DIGIT)
57
58#define DISPC_MAX_NR_ISRS 8
59
60struct omap_dispc_isr_data {
61 omap_dispc_isr_t isr;
62 void *arg;
63 u32 mask;
64};
65
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030066enum omap_burst_size {
67 BURST_SIZE_X2 = 0,
68 BURST_SIZE_X4 = 1,
69 BURST_SIZE_X8 = 2,
70};
71
Tomi Valkeinen80c39712009-11-12 11:41:42 +020072#define REG_GET(idx, start, end) \
73 FLD_GET(dispc_read_reg(idx), start, end)
74
75#define REG_FLD_MOD(idx, val, start, end) \
76 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
77
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +020078struct dispc_irq_stats {
79 unsigned long last_reset;
80 unsigned irq_count;
81 unsigned irqs[32];
82};
83
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053084struct dispc_features {
85 u8 sw_start;
86 u8 fp_start;
87 u8 bp_start;
88 u16 sw_max;
89 u16 vp_max;
90 u16 hp_max;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +053091 int (*calc_scaling) (enum omap_plane plane,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053092 const struct omap_video_timings *mgr_timings,
93 u16 width, u16 height, u16 out_width, u16 out_height,
94 enum omap_color_mode color_mode, bool *five_taps,
95 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +053096 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +053097 unsigned long (*calc_core_clk) (enum omap_plane plane,
Archit Taneja8ba85302012-09-26 17:00:37 +053098 u16 width, u16 height, u16 out_width, u16 out_height,
99 bool mem_to_mem);
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300100 u8 num_fifos;
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +0300101
102 /* swap GFX & WB fifos */
103 bool gfx_fifo_workaround:1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530104};
105
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300106#define DISPC_MAX_NR_FIFOS 5
107
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200108static struct {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +0000109 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200110 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300111
112 int ctx_loss_cnt;
113
archit tanejaaffe3602011-02-23 08:41:03 +0000114 int irq;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300115 struct clk *dss_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200116
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300117 u32 fifo_size[DISPC_MAX_NR_FIFOS];
118 /* maps which plane is using a fifo. fifo-id -> plane-id */
119 int fifo_assignment[DISPC_MAX_NR_FIFOS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200120
121 spinlock_t irq_lock;
122 u32 irq_error_mask;
123 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
124 u32 error_irqs;
125 struct work_struct error_work;
126
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300127 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200128 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200129
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530130 const struct dispc_features *feat;
131
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200132#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
133 spinlock_t irq_stats_lock;
134 struct dispc_irq_stats irq_stats;
135#endif
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200136} dispc;
137
Amber Jain0d66cbb2011-05-19 19:47:54 +0530138enum omap_color_component {
139 /* used for all color formats for OMAP3 and earlier
140 * and for RGB and Y color component on OMAP4
141 */
142 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
143 /* used for UV component for
144 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
145 * color formats on OMAP4
146 */
147 DISPC_COLOR_COMPONENT_UV = 1 << 1,
148};
149
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530150enum mgr_reg_fields {
151 DISPC_MGR_FLD_ENABLE,
152 DISPC_MGR_FLD_STNTFT,
153 DISPC_MGR_FLD_GO,
154 DISPC_MGR_FLD_TFTDATALINES,
155 DISPC_MGR_FLD_STALLMODE,
156 DISPC_MGR_FLD_TCKENABLE,
157 DISPC_MGR_FLD_TCKSELECTION,
158 DISPC_MGR_FLD_CPR,
159 DISPC_MGR_FLD_FIFOHANDCHECK,
160 /* used to maintain a count of the above fields */
161 DISPC_MGR_FLD_NUM,
162};
163
164static const struct {
165 const char *name;
166 u32 vsync_irq;
167 u32 framedone_irq;
168 u32 sync_lost_irq;
169 struct reg_field reg_desc[DISPC_MGR_FLD_NUM];
170} mgr_desc[] = {
171 [OMAP_DSS_CHANNEL_LCD] = {
172 .name = "LCD",
173 .vsync_irq = DISPC_IRQ_VSYNC,
174 .framedone_irq = DISPC_IRQ_FRAMEDONE,
175 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
176 .reg_desc = {
177 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
178 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
179 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
180 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
181 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
182 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
183 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
184 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
185 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
186 },
187 },
188 [OMAP_DSS_CHANNEL_DIGIT] = {
189 .name = "DIGIT",
190 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
191 .framedone_irq = 0,
192 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
193 .reg_desc = {
194 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
195 [DISPC_MGR_FLD_STNTFT] = { },
196 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
197 [DISPC_MGR_FLD_TFTDATALINES] = { },
198 [DISPC_MGR_FLD_STALLMODE] = { },
199 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
200 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
201 [DISPC_MGR_FLD_CPR] = { },
202 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
203 },
204 },
205 [OMAP_DSS_CHANNEL_LCD2] = {
206 .name = "LCD2",
207 .vsync_irq = DISPC_IRQ_VSYNC2,
208 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
209 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
210 .reg_desc = {
211 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
212 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
213 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
214 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
215 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
216 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
217 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
218 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
219 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
220 },
221 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530222 [OMAP_DSS_CHANNEL_LCD3] = {
223 .name = "LCD3",
224 .vsync_irq = DISPC_IRQ_VSYNC3,
225 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
226 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
227 .reg_desc = {
228 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
229 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
230 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
231 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
232 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
233 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
234 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
235 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
236 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
237 },
238 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530239};
240
Archit Taneja6e5264b2012-09-11 12:04:47 +0530241struct color_conv_coef {
242 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
243 int full_range;
244};
245
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200246static void _omap_dispc_set_irqs(void);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +0530247static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
248static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200249
Archit Taneja55978cc2011-05-06 11:45:51 +0530250static inline void dispc_write_reg(const u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200251{
Archit Taneja55978cc2011-05-06 11:45:51 +0530252 __raw_writel(val, dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200253}
254
Archit Taneja55978cc2011-05-06 11:45:51 +0530255static inline u32 dispc_read_reg(const u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200256{
Archit Taneja55978cc2011-05-06 11:45:51 +0530257 return __raw_readl(dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200258}
259
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530260static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
261{
262 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
263 return REG_GET(rfld.reg, rfld.high, rfld.low);
264}
265
266static void mgr_fld_write(enum omap_channel channel,
267 enum mgr_reg_fields regfld, int val) {
268 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
269 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
270}
271
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200272#define SR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530273 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200274#define RR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530275 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200276
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300277static void dispc_save_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200278{
Archit Tanejac6104b82011-08-05 19:06:02 +0530279 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200280
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300281 DSSDBG("dispc_save_context\n");
282
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200283 SR(IRQENABLE);
284 SR(CONTROL);
285 SR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200286 SR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530287 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
288 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300289 SR(GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000290 if (dss_has_feature(FEAT_MGR_LCD2)) {
291 SR(CONTROL2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000292 SR(CONFIG2);
293 }
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530294 if (dss_has_feature(FEAT_MGR_LCD3)) {
295 SR(CONTROL3);
296 SR(CONFIG3);
297 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200298
Archit Tanejac6104b82011-08-05 19:06:02 +0530299 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
300 SR(DEFAULT_COLOR(i));
301 SR(TRANS_COLOR(i));
302 SR(SIZE_MGR(i));
303 if (i == OMAP_DSS_CHANNEL_DIGIT)
304 continue;
305 SR(TIMING_H(i));
306 SR(TIMING_V(i));
307 SR(POL_FREQ(i));
308 SR(DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200309
Archit Tanejac6104b82011-08-05 19:06:02 +0530310 SR(DATA_CYCLE1(i));
311 SR(DATA_CYCLE2(i));
312 SR(DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200313
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300314 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530315 SR(CPR_COEF_R(i));
316 SR(CPR_COEF_G(i));
317 SR(CPR_COEF_B(i));
318 }
319 }
320
321 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
322 SR(OVL_BA0(i));
323 SR(OVL_BA1(i));
324 SR(OVL_POSITION(i));
325 SR(OVL_SIZE(i));
326 SR(OVL_ATTRIBUTES(i));
327 SR(OVL_FIFO_THRESHOLD(i));
328 SR(OVL_ROW_INC(i));
329 SR(OVL_PIXEL_INC(i));
330 if (dss_has_feature(FEAT_PRELOAD))
331 SR(OVL_PRELOAD(i));
332 if (i == OMAP_DSS_GFX) {
333 SR(OVL_WINDOW_SKIP(i));
334 SR(OVL_TABLE_BA(i));
335 continue;
336 }
337 SR(OVL_FIR(i));
338 SR(OVL_PICTURE_SIZE(i));
339 SR(OVL_ACCU0(i));
340 SR(OVL_ACCU1(i));
341
342 for (j = 0; j < 8; j++)
343 SR(OVL_FIR_COEF_H(i, j));
344
345 for (j = 0; j < 8; j++)
346 SR(OVL_FIR_COEF_HV(i, j));
347
348 for (j = 0; j < 5; j++)
349 SR(OVL_CONV_COEF(i, j));
350
351 if (dss_has_feature(FEAT_FIR_COEF_V)) {
352 for (j = 0; j < 8; j++)
353 SR(OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300354 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000355
Archit Tanejac6104b82011-08-05 19:06:02 +0530356 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
357 SR(OVL_BA0_UV(i));
358 SR(OVL_BA1_UV(i));
359 SR(OVL_FIR2(i));
360 SR(OVL_ACCU2_0(i));
361 SR(OVL_ACCU2_1(i));
362
363 for (j = 0; j < 8; j++)
364 SR(OVL_FIR_COEF_H2(i, j));
365
366 for (j = 0; j < 8; j++)
367 SR(OVL_FIR_COEF_HV2(i, j));
368
369 for (j = 0; j < 8; j++)
370 SR(OVL_FIR_COEF_V2(i, j));
371 }
372 if (dss_has_feature(FEAT_ATTR2))
373 SR(OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000374 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200375
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600376 if (dss_has_feature(FEAT_CORE_CLK_DIV))
377 SR(DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300378
Tomi Valkeinen00928ea2012-02-20 11:50:06 +0200379 dispc.ctx_loss_cnt = dss_get_ctx_loss_count(&dispc.pdev->dev);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300380 dispc.ctx_valid = true;
381
382 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200383}
384
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300385static void dispc_restore_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200386{
Archit Tanejac6104b82011-08-05 19:06:02 +0530387 int i, j, ctx;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300388
389 DSSDBG("dispc_restore_context\n");
390
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300391 if (!dispc.ctx_valid)
392 return;
393
Tomi Valkeinen00928ea2012-02-20 11:50:06 +0200394 ctx = dss_get_ctx_loss_count(&dispc.pdev->dev);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300395
396 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
397 return;
398
399 DSSDBG("ctx_loss_count: saved %d, current %d\n",
400 dispc.ctx_loss_cnt, ctx);
401
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200402 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200403 /*RR(CONTROL);*/
404 RR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200405 RR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530406 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
407 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300408 RR(GLOBAL_ALPHA);
Archit Tanejac6104b82011-08-05 19:06:02 +0530409 if (dss_has_feature(FEAT_MGR_LCD2))
Sumit Semwal2a205f32010-12-02 11:27:12 +0000410 RR(CONFIG2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530411 if (dss_has_feature(FEAT_MGR_LCD3))
412 RR(CONFIG3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200413
Archit Tanejac6104b82011-08-05 19:06:02 +0530414 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
415 RR(DEFAULT_COLOR(i));
416 RR(TRANS_COLOR(i));
417 RR(SIZE_MGR(i));
418 if (i == OMAP_DSS_CHANNEL_DIGIT)
419 continue;
420 RR(TIMING_H(i));
421 RR(TIMING_V(i));
422 RR(POL_FREQ(i));
423 RR(DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530424
Archit Tanejac6104b82011-08-05 19:06:02 +0530425 RR(DATA_CYCLE1(i));
426 RR(DATA_CYCLE2(i));
427 RR(DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000428
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300429 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530430 RR(CPR_COEF_R(i));
431 RR(CPR_COEF_G(i));
432 RR(CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300433 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000434 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200435
Archit Tanejac6104b82011-08-05 19:06:02 +0530436 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
437 RR(OVL_BA0(i));
438 RR(OVL_BA1(i));
439 RR(OVL_POSITION(i));
440 RR(OVL_SIZE(i));
441 RR(OVL_ATTRIBUTES(i));
442 RR(OVL_FIFO_THRESHOLD(i));
443 RR(OVL_ROW_INC(i));
444 RR(OVL_PIXEL_INC(i));
445 if (dss_has_feature(FEAT_PRELOAD))
446 RR(OVL_PRELOAD(i));
447 if (i == OMAP_DSS_GFX) {
448 RR(OVL_WINDOW_SKIP(i));
449 RR(OVL_TABLE_BA(i));
450 continue;
451 }
452 RR(OVL_FIR(i));
453 RR(OVL_PICTURE_SIZE(i));
454 RR(OVL_ACCU0(i));
455 RR(OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200456
Archit Tanejac6104b82011-08-05 19:06:02 +0530457 for (j = 0; j < 8; j++)
458 RR(OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200459
Archit Tanejac6104b82011-08-05 19:06:02 +0530460 for (j = 0; j < 8; j++)
461 RR(OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200462
Archit Tanejac6104b82011-08-05 19:06:02 +0530463 for (j = 0; j < 5; j++)
464 RR(OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200465
Archit Tanejac6104b82011-08-05 19:06:02 +0530466 if (dss_has_feature(FEAT_FIR_COEF_V)) {
467 for (j = 0; j < 8; j++)
468 RR(OVL_FIR_COEF_V(i, j));
469 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200470
Archit Tanejac6104b82011-08-05 19:06:02 +0530471 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
472 RR(OVL_BA0_UV(i));
473 RR(OVL_BA1_UV(i));
474 RR(OVL_FIR2(i));
475 RR(OVL_ACCU2_0(i));
476 RR(OVL_ACCU2_1(i));
477
478 for (j = 0; j < 8; j++)
479 RR(OVL_FIR_COEF_H2(i, j));
480
481 for (j = 0; j < 8; j++)
482 RR(OVL_FIR_COEF_HV2(i, j));
483
484 for (j = 0; j < 8; j++)
485 RR(OVL_FIR_COEF_V2(i, j));
486 }
487 if (dss_has_feature(FEAT_ATTR2))
488 RR(OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300489 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200490
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600491 if (dss_has_feature(FEAT_CORE_CLK_DIV))
492 RR(DIVISOR);
493
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200494 /* enable last, because LCD & DIGIT enable are here */
495 RR(CONTROL);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000496 if (dss_has_feature(FEAT_MGR_LCD2))
497 RR(CONTROL2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530498 if (dss_has_feature(FEAT_MGR_LCD3))
499 RR(CONTROL3);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200500 /* clear spurious SYNC_LOST_DIGIT interrupts */
501 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
502
503 /*
504 * enable last so IRQs won't trigger before
505 * the context is fully restored
506 */
507 RR(IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300508
509 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200510}
511
512#undef SR
513#undef RR
514
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300515int dispc_runtime_get(void)
516{
517 int r;
518
519 DSSDBG("dispc_runtime_get\n");
520
521 r = pm_runtime_get_sync(&dispc.pdev->dev);
522 WARN_ON(r < 0);
523 return r < 0 ? r : 0;
524}
525
526void dispc_runtime_put(void)
527{
528 int r;
529
530 DSSDBG("dispc_runtime_put\n");
531
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200532 r = pm_runtime_put_sync(&dispc.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300533 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300534}
535
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200536u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
537{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530538 return mgr_desc[channel].vsync_irq;
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200539}
540
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200541u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
542{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530543 return mgr_desc[channel].framedone_irq;
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200544}
545
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530546u32 dispc_wb_get_framedone_irq(void)
547{
548 return DISPC_IRQ_FRAMEDONEWB;
549}
550
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300551bool dispc_mgr_go_busy(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200552{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530553 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200554}
555
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300556void dispc_mgr_go(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200557{
Sumit Semwal2a205f32010-12-02 11:27:12 +0000558 bool enable_bit, go_bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200559
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200560 /* if the channel is not enabled, we don't need GO */
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530561 enable_bit = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE) == 1;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000562
563 if (!enable_bit)
Tomi Valkeinene6d80f92011-05-19 14:12:26 +0300564 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200565
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530566 go_bit = mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000567
568 if (go_bit) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200569 DSSERR("GO bit not down for channel %d\n", channel);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +0300570 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200571 }
572
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530573 DSSDBG("GO %s\n", mgr_desc[channel].name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200574
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530575 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200576}
577
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530578bool dispc_wb_go_busy(void)
579{
580 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
581}
582
583void dispc_wb_go(void)
584{
585 enum omap_plane plane = OMAP_DSS_WB;
586 bool enable, go;
587
588 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
589
590 if (!enable)
591 return;
592
593 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
594 if (go) {
595 DSSERR("GO bit not down for WB\n");
596 return;
597 }
598
599 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
600}
601
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300602static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200603{
Archit Taneja9b372c22011-05-06 11:45:49 +0530604 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200605}
606
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300607static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200608{
Archit Taneja9b372c22011-05-06 11:45:49 +0530609 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200610}
611
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300612static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200613{
Archit Taneja9b372c22011-05-06 11:45:49 +0530614 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200615}
616
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300617static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530618{
619 BUG_ON(plane == OMAP_DSS_GFX);
620
621 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
622}
623
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300624static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
625 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530626{
627 BUG_ON(plane == OMAP_DSS_GFX);
628
629 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
630}
631
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300632static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530633{
634 BUG_ON(plane == OMAP_DSS_GFX);
635
636 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
637}
638
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530639static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
640 int fir_vinc, int five_taps,
641 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200642{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530643 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200644 int i;
645
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530646 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
647 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200648
649 for (i = 0; i < 8; i++) {
650 u32 h, hv;
651
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530652 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
653 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
654 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
655 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
656 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
657 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
658 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
659 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200660
Amber Jain0d66cbb2011-05-19 19:47:54 +0530661 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300662 dispc_ovl_write_firh_reg(plane, i, h);
663 dispc_ovl_write_firhv_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530664 } else {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300665 dispc_ovl_write_firh2_reg(plane, i, h);
666 dispc_ovl_write_firhv2_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530667 }
668
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200669 }
670
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200671 if (five_taps) {
672 for (i = 0; i < 8; i++) {
673 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530674 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
675 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530676 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300677 dispc_ovl_write_firv_reg(plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530678 else
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300679 dispc_ovl_write_firv2_reg(plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200680 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200681 }
682}
683
Archit Taneja6e5264b2012-09-11 12:04:47 +0530684
685static void dispc_ovl_write_color_conv_coef(enum omap_plane plane,
686 const struct color_conv_coef *ct)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200687{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200688#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
689
Archit Taneja6e5264b2012-09-11 12:04:47 +0530690 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
691 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
692 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
693 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
694 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200695
Archit Taneja6e5264b2012-09-11 12:04:47 +0530696 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200697
698#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200699}
700
Archit Taneja6e5264b2012-09-11 12:04:47 +0530701static void dispc_setup_color_conv_coef(void)
702{
703 int i;
704 int num_ovl = dss_feat_get_num_ovls();
705 int num_wb = dss_feat_get_num_wbs();
706 const struct color_conv_coef ctbl_bt601_5_ovl = {
707 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
708 };
709 const struct color_conv_coef ctbl_bt601_5_wb = {
710 66, 112, -38, 129, -94, -74, 25, -18, 112, 0,
711 };
712
713 for (i = 1; i < num_ovl; i++)
714 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
715
716 for (; i < num_wb; i++)
717 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_wb);
718}
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200719
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300720static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200721{
Archit Taneja9b372c22011-05-06 11:45:49 +0530722 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200723}
724
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300725static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200726{
Archit Taneja9b372c22011-05-06 11:45:49 +0530727 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200728}
729
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300730static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530731{
732 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
733}
734
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300735static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530736{
737 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
738}
739
Archit Tanejad79db852012-09-22 12:30:17 +0530740static void dispc_ovl_set_pos(enum omap_plane plane,
741 enum omap_overlay_caps caps, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200742{
Archit Tanejad79db852012-09-22 12:30:17 +0530743 u32 val;
744
745 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
746 return;
747
748 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530749
750 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200751}
752
Archit Taneja78b687f2012-09-21 14:51:49 +0530753static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
754 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200755{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200756 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530757
Archit Taneja36d87d92012-07-28 22:59:03 +0530758 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
Archit Taneja9b372c22011-05-06 11:45:49 +0530759 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
760 else
761 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200762}
763
Archit Taneja78b687f2012-09-21 14:51:49 +0530764static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
765 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200766{
767 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200768
769 BUG_ON(plane == OMAP_DSS_GFX);
770
771 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530772
Archit Taneja36d87d92012-07-28 22:59:03 +0530773 if (plane == OMAP_DSS_WB)
774 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
775 else
776 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200777}
778
Archit Taneja5b54ed32012-09-26 16:55:27 +0530779static void dispc_ovl_set_zorder(enum omap_plane plane,
780 enum omap_overlay_caps caps, u8 zorder)
Archit Taneja54128702011-09-08 11:29:17 +0530781{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530782 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
Archit Taneja54128702011-09-08 11:29:17 +0530783 return;
784
785 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
786}
787
788static void dispc_ovl_enable_zorder_planes(void)
789{
790 int i;
791
792 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
793 return;
794
795 for (i = 0; i < dss_feat_get_num_ovls(); i++)
796 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
797}
798
Archit Taneja5b54ed32012-09-26 16:55:27 +0530799static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
800 enum omap_overlay_caps caps, bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100801{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530802 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100803 return;
804
Archit Taneja9b372c22011-05-06 11:45:49 +0530805 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100806}
807
Archit Taneja5b54ed32012-09-26 16:55:27 +0530808static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
809 enum omap_overlay_caps caps, u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200810{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530811 static const unsigned shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300812 int shift;
813
Archit Taneja5b54ed32012-09-26 16:55:27 +0530814 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100815 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530816
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300817 shift = shifts[plane];
818 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200819}
820
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300821static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200822{
Archit Taneja9b372c22011-05-06 11:45:49 +0530823 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200824}
825
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300826static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200827{
Archit Taneja9b372c22011-05-06 11:45:49 +0530828 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200829}
830
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300831static void dispc_ovl_set_color_mode(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200832 enum omap_color_mode color_mode)
833{
834 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +0530835 if (plane != OMAP_DSS_GFX) {
836 switch (color_mode) {
837 case OMAP_DSS_COLOR_NV12:
838 m = 0x0; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530839 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530840 m = 0x1; break;
841 case OMAP_DSS_COLOR_RGBA16:
842 m = 0x2; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530843 case OMAP_DSS_COLOR_RGB12U:
Amber Jainf20e4222011-05-19 19:47:50 +0530844 m = 0x4; break;
845 case OMAP_DSS_COLOR_ARGB16:
846 m = 0x5; break;
847 case OMAP_DSS_COLOR_RGB16:
848 m = 0x6; break;
849 case OMAP_DSS_COLOR_ARGB16_1555:
850 m = 0x7; break;
851 case OMAP_DSS_COLOR_RGB24U:
852 m = 0x8; break;
853 case OMAP_DSS_COLOR_RGB24P:
854 m = 0x9; break;
855 case OMAP_DSS_COLOR_YUV2:
856 m = 0xa; break;
857 case OMAP_DSS_COLOR_UYVY:
858 m = 0xb; break;
859 case OMAP_DSS_COLOR_ARGB32:
860 m = 0xc; break;
861 case OMAP_DSS_COLOR_RGBA32:
862 m = 0xd; break;
863 case OMAP_DSS_COLOR_RGBX32:
864 m = 0xe; break;
865 case OMAP_DSS_COLOR_XRGB16_1555:
866 m = 0xf; break;
867 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300868 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530869 }
870 } else {
871 switch (color_mode) {
872 case OMAP_DSS_COLOR_CLUT1:
873 m = 0x0; break;
874 case OMAP_DSS_COLOR_CLUT2:
875 m = 0x1; break;
876 case OMAP_DSS_COLOR_CLUT4:
877 m = 0x2; break;
878 case OMAP_DSS_COLOR_CLUT8:
879 m = 0x3; break;
880 case OMAP_DSS_COLOR_RGB12U:
881 m = 0x4; break;
882 case OMAP_DSS_COLOR_ARGB16:
883 m = 0x5; break;
884 case OMAP_DSS_COLOR_RGB16:
885 m = 0x6; break;
886 case OMAP_DSS_COLOR_ARGB16_1555:
887 m = 0x7; break;
888 case OMAP_DSS_COLOR_RGB24U:
889 m = 0x8; break;
890 case OMAP_DSS_COLOR_RGB24P:
891 m = 0x9; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530892 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530893 m = 0xa; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530894 case OMAP_DSS_COLOR_RGBA16:
Amber Jainf20e4222011-05-19 19:47:50 +0530895 m = 0xb; break;
896 case OMAP_DSS_COLOR_ARGB32:
897 m = 0xc; break;
898 case OMAP_DSS_COLOR_RGBA32:
899 m = 0xd; break;
900 case OMAP_DSS_COLOR_RGBX32:
901 m = 0xe; break;
902 case OMAP_DSS_COLOR_XRGB16_1555:
903 m = 0xf; break;
904 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300905 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530906 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200907 }
908
Archit Taneja9b372c22011-05-06 11:45:49 +0530909 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200910}
911
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530912static void dispc_ovl_configure_burst_type(enum omap_plane plane,
913 enum omap_dss_rotation_type rotation_type)
914{
915 if (dss_has_feature(FEAT_BURST_2D) == 0)
916 return;
917
918 if (rotation_type == OMAP_DSS_ROT_TILER)
919 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
920 else
921 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
922}
923
Tomi Valkeinenf4279842011-10-28 15:26:26 +0300924void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200925{
926 int shift;
927 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000928 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200929
930 switch (plane) {
931 case OMAP_DSS_GFX:
932 shift = 8;
933 break;
934 case OMAP_DSS_VIDEO1:
935 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +0530936 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200937 shift = 16;
938 break;
939 default:
940 BUG();
941 return;
942 }
943
Archit Taneja9b372c22011-05-06 11:45:49 +0530944 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000945 if (dss_has_feature(FEAT_MGR_LCD2)) {
946 switch (channel) {
947 case OMAP_DSS_CHANNEL_LCD:
948 chan = 0;
949 chan2 = 0;
950 break;
951 case OMAP_DSS_CHANNEL_DIGIT:
952 chan = 1;
953 chan2 = 0;
954 break;
955 case OMAP_DSS_CHANNEL_LCD2:
956 chan = 0;
957 chan2 = 1;
958 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530959 case OMAP_DSS_CHANNEL_LCD3:
960 if (dss_has_feature(FEAT_MGR_LCD3)) {
961 chan = 0;
962 chan2 = 2;
963 } else {
964 BUG();
965 return;
966 }
967 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000968 default:
969 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300970 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000971 }
972
973 val = FLD_MOD(val, chan, shift, shift);
974 val = FLD_MOD(val, chan2, 31, 30);
975 } else {
976 val = FLD_MOD(val, channel, shift, shift);
977 }
Archit Taneja9b372c22011-05-06 11:45:49 +0530978 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200979}
980
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200981static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
982{
983 int shift;
984 u32 val;
985 enum omap_channel channel;
986
987 switch (plane) {
988 case OMAP_DSS_GFX:
989 shift = 8;
990 break;
991 case OMAP_DSS_VIDEO1:
992 case OMAP_DSS_VIDEO2:
993 case OMAP_DSS_VIDEO3:
994 shift = 16;
995 break;
996 default:
997 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300998 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200999 }
1000
1001 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1002
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05301003 if (dss_has_feature(FEAT_MGR_LCD3)) {
1004 if (FLD_GET(val, 31, 30) == 0)
1005 channel = FLD_GET(val, shift, shift);
1006 else if (FLD_GET(val, 31, 30) == 1)
1007 channel = OMAP_DSS_CHANNEL_LCD2;
1008 else
1009 channel = OMAP_DSS_CHANNEL_LCD3;
1010 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001011 if (FLD_GET(val, 31, 30) == 0)
1012 channel = FLD_GET(val, shift, shift);
1013 else
1014 channel = OMAP_DSS_CHANNEL_LCD2;
1015 } else {
1016 channel = FLD_GET(val, shift, shift);
1017 }
1018
1019 return channel;
1020}
1021
Archit Tanejad9ac7732012-09-22 12:38:19 +05301022void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1023{
1024 enum omap_plane plane = OMAP_DSS_WB;
1025
1026 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1027}
1028
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001029static void dispc_ovl_set_burst_size(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001030 enum omap_burst_size burst_size)
1031{
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301032 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001033 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001034
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001035 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001036 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001037}
1038
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001039static void dispc_configure_burst_sizes(void)
1040{
1041 int i;
1042 const int burst_size = BURST_SIZE_X8;
1043
1044 /* Configure burst size always to maximum size */
1045 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001046 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001047}
1048
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001049static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001050{
1051 unsigned unit = dss_feat_get_burst_size_unit();
1052 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1053 return unit * 8;
1054}
1055
Mythri P Kd3862612011-03-11 18:02:49 +05301056void dispc_enable_gamma_table(bool enable)
1057{
1058 /*
1059 * This is partially implemented to support only disabling of
1060 * the gamma table.
1061 */
1062 if (enable) {
1063 DSSWARN("Gamma table enabling for TV not yet supported");
1064 return;
1065 }
1066
1067 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1068}
1069
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001070static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001071{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301072 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001073 return;
1074
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301075 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001076}
1077
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001078static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001079 struct omap_dss_cpr_coefs *coefs)
1080{
1081 u32 coef_r, coef_g, coef_b;
1082
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301083 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001084 return;
1085
1086 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1087 FLD_VAL(coefs->rb, 9, 0);
1088 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1089 FLD_VAL(coefs->gb, 9, 0);
1090 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1091 FLD_VAL(coefs->bb, 9, 0);
1092
1093 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1094 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1095 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1096}
1097
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001098static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001099{
1100 u32 val;
1101
1102 BUG_ON(plane == OMAP_DSS_GFX);
1103
Archit Taneja9b372c22011-05-06 11:45:49 +05301104 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001105 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +05301106 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001107}
1108
Archit Tanejad79db852012-09-22 12:30:17 +05301109static void dispc_ovl_enable_replication(enum omap_plane plane,
1110 enum omap_overlay_caps caps, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001111{
Archit Tanejab8c095b2011-09-13 18:20:33 +05301112 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001113 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001114
Archit Tanejad79db852012-09-22 12:30:17 +05301115 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1116 return;
1117
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001118 shift = shifts[plane];
1119 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001120}
1121
Archit Taneja8f366162012-04-16 12:53:44 +05301122static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
Archit Tanejae5c09e02012-04-16 12:53:42 +05301123 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001124{
1125 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301126
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001127 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja702d1442011-05-06 11:45:50 +05301128 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001129}
1130
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001131static void dispc_init_fifos(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001132{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001133 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001134 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301135 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001136 u32 unit;
1137
1138 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001139
Archit Tanejaa0acb552010-09-15 19:20:00 +05301140 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001141
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001142 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1143 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001144 size *= unit;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001145 dispc.fifo_size[fifo] = size;
1146
1147 /*
1148 * By default fifos are mapped directly to overlays, fifo 0 to
1149 * ovl 0, fifo 1 to ovl 1, etc.
1150 */
1151 dispc.fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001152 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001153
1154 /*
1155 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1156 * causes problems with certain use cases, like using the tiler in 2D
1157 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1158 * giving GFX plane a larger fifo. WB but should work fine with a
1159 * smaller fifo.
1160 */
1161 if (dispc.feat->gfx_fifo_workaround) {
1162 u32 v;
1163
1164 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1165
1166 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1167 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1168 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1169 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1170
1171 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1172
1173 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1174 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001175 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001176}
1177
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001178static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001179{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001180 int fifo;
1181 u32 size = 0;
1182
1183 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1184 if (dispc.fifo_assignment[fifo] == plane)
1185 size += dispc.fifo_size[fifo];
1186 }
1187
1188 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001189}
1190
Tomi Valkeinen6f04e1b2011-10-31 08:58:52 +02001191void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001192{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301193 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001194 u32 unit;
1195
1196 unit = dss_feat_get_buffer_size_unit();
1197
1198 WARN_ON(low % unit != 0);
1199 WARN_ON(high % unit != 0);
1200
1201 low /= unit;
1202 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301203
Archit Taneja9b372c22011-05-06 11:45:49 +05301204 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1205 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1206
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001207 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001208 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301209 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001210 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301211 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001212 hi_start, hi_end) * unit,
1213 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001214
Archit Taneja9b372c22011-05-06 11:45:49 +05301215 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301216 FLD_VAL(high, hi_start, hi_end) |
1217 FLD_VAL(low, lo_start, lo_end));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001218}
1219
1220void dispc_enable_fifomerge(bool enable)
1221{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001222 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1223 WARN_ON(enable);
1224 return;
1225 }
1226
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001227 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1228 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001229}
1230
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001231void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001232 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1233 bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001234{
1235 /*
1236 * All sizes are in bytes. Both the buffer and burst are made of
1237 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1238 */
1239
1240 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001241 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1242 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001243
1244 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001245 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001246
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001247 if (use_fifomerge) {
1248 total_fifo_size = 0;
1249 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
1250 total_fifo_size += dispc_ovl_get_fifo_size(i);
1251 } else {
1252 total_fifo_size = ovl_fifo_size;
1253 }
1254
1255 /*
1256 * We use the same low threshold for both fifomerge and non-fifomerge
1257 * cases, but for fifomerge we calculate the high threshold using the
1258 * combined fifo size
1259 */
1260
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001261 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001262 *fifo_low = ovl_fifo_size - burst_size * 2;
1263 *fifo_high = total_fifo_size - burst_size;
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301264 } else if (plane == OMAP_DSS_WB) {
1265 /*
1266 * Most optimal configuration for writeback is to push out data
1267 * to the interconnect the moment writeback pushes enough pixels
1268 * in the FIFO to form a burst
1269 */
1270 *fifo_low = 0;
1271 *fifo_high = burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001272 } else {
1273 *fifo_low = ovl_fifo_size - burst_size;
1274 *fifo_high = total_fifo_size - buf_unit;
1275 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001276}
1277
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001278static void dispc_ovl_set_fir(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301279 int hinc, int vinc,
1280 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001281{
1282 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001283
Amber Jain0d66cbb2011-05-19 19:47:54 +05301284 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1285 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301286
Amber Jain0d66cbb2011-05-19 19:47:54 +05301287 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1288 &hinc_start, &hinc_end);
1289 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1290 &vinc_start, &vinc_end);
1291 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1292 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301293
Amber Jain0d66cbb2011-05-19 19:47:54 +05301294 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1295 } else {
1296 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1297 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1298 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001299}
1300
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001301static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001302{
1303 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301304 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001305
Archit Taneja87a74842011-03-02 11:19:50 +05301306 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1307 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1308
1309 val = FLD_VAL(vaccu, vert_start, vert_end) |
1310 FLD_VAL(haccu, hor_start, hor_end);
1311
Archit Taneja9b372c22011-05-06 11:45:49 +05301312 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001313}
1314
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001315static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001316{
1317 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301318 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001319
Archit Taneja87a74842011-03-02 11:19:50 +05301320 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1321 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1322
1323 val = FLD_VAL(vaccu, vert_start, vert_end) |
1324 FLD_VAL(haccu, hor_start, hor_end);
1325
Archit Taneja9b372c22011-05-06 11:45:49 +05301326 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001327}
1328
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001329static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1330 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301331{
1332 u32 val;
1333
1334 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1335 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1336}
1337
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001338static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1339 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301340{
1341 u32 val;
1342
1343 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1344 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1345}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001346
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001347static void dispc_ovl_set_scale_param(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001348 u16 orig_width, u16 orig_height,
1349 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301350 bool five_taps, u8 rotation,
1351 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001352{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301353 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001354
Amber Jained14a3c2011-05-19 19:47:51 +05301355 fir_hinc = 1024 * orig_width / out_width;
1356 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001357
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301358 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1359 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001360 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301361}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001362
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301363static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1364 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1365 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1366{
1367 int h_accu2_0, h_accu2_1;
1368 int v_accu2_0, v_accu2_1;
1369 int chroma_hinc, chroma_vinc;
1370 int idx;
1371
1372 struct accu {
1373 s8 h0_m, h0_n;
1374 s8 h1_m, h1_n;
1375 s8 v0_m, v0_n;
1376 s8 v1_m, v1_n;
1377 };
1378
1379 const struct accu *accu_table;
1380 const struct accu *accu_val;
1381
1382 static const struct accu accu_nv12[4] = {
1383 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1384 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1385 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1386 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1387 };
1388
1389 static const struct accu accu_nv12_ilace[4] = {
1390 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1391 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1392 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1393 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1394 };
1395
1396 static const struct accu accu_yuv[4] = {
1397 { 0, 1, 0, 1, 0, 1, 0, 1 },
1398 { 0, 1, 0, 1, 0, 1, 0, 1 },
1399 { -1, 1, 0, 1, 0, 1, 0, 1 },
1400 { 0, 1, 0, 1, -1, 1, 0, 1 },
1401 };
1402
1403 switch (rotation) {
1404 case OMAP_DSS_ROT_0:
1405 idx = 0;
1406 break;
1407 case OMAP_DSS_ROT_90:
1408 idx = 1;
1409 break;
1410 case OMAP_DSS_ROT_180:
1411 idx = 2;
1412 break;
1413 case OMAP_DSS_ROT_270:
1414 idx = 3;
1415 break;
1416 default:
1417 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001418 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301419 }
1420
1421 switch (color_mode) {
1422 case OMAP_DSS_COLOR_NV12:
1423 if (ilace)
1424 accu_table = accu_nv12_ilace;
1425 else
1426 accu_table = accu_nv12;
1427 break;
1428 case OMAP_DSS_COLOR_YUV2:
1429 case OMAP_DSS_COLOR_UYVY:
1430 accu_table = accu_yuv;
1431 break;
1432 default:
1433 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001434 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301435 }
1436
1437 accu_val = &accu_table[idx];
1438
1439 chroma_hinc = 1024 * orig_width / out_width;
1440 chroma_vinc = 1024 * orig_height / out_height;
1441
1442 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1443 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1444 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1445 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1446
1447 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1448 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1449}
1450
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001451static void dispc_ovl_set_scaling_common(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301452 u16 orig_width, u16 orig_height,
1453 u16 out_width, u16 out_height,
1454 bool ilace, bool five_taps,
1455 bool fieldmode, enum omap_color_mode color_mode,
1456 u8 rotation)
1457{
1458 int accu0 = 0;
1459 int accu1 = 0;
1460 u32 l;
1461
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001462 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301463 out_width, out_height, five_taps,
1464 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301465 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001466
Archit Taneja87a74842011-03-02 11:19:50 +05301467 /* RESIZEENABLE and VERTICALTAPS */
1468 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301469 l |= (orig_width != out_width) ? (1 << 5) : 0;
1470 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001471 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301472
1473 /* VRESIZECONF and HRESIZECONF */
1474 if (dss_has_feature(FEAT_RESIZECONF)) {
1475 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301476 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1477 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301478 }
1479
1480 /* LINEBUFFERSPLIT */
1481 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1482 l &= ~(0x1 << 22);
1483 l |= five_taps ? (1 << 22) : 0;
1484 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001485
Archit Taneja9b372c22011-05-06 11:45:49 +05301486 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001487
1488 /*
1489 * field 0 = even field = bottom field
1490 * field 1 = odd field = top field
1491 */
1492 if (ilace && !fieldmode) {
1493 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301494 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001495 if (accu0 >= 1024/2) {
1496 accu1 = 1024/2;
1497 accu0 -= accu1;
1498 }
1499 }
1500
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001501 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1502 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001503}
1504
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001505static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301506 u16 orig_width, u16 orig_height,
1507 u16 out_width, u16 out_height,
1508 bool ilace, bool five_taps,
1509 bool fieldmode, enum omap_color_mode color_mode,
1510 u8 rotation)
1511{
1512 int scale_x = out_width != orig_width;
1513 int scale_y = out_height != orig_height;
Archit Tanejaf92afae2012-08-24 11:11:14 +05301514 bool chroma_upscale = plane != OMAP_DSS_WB ? true : false;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301515
1516 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1517 return;
1518 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1519 color_mode != OMAP_DSS_COLOR_UYVY &&
1520 color_mode != OMAP_DSS_COLOR_NV12)) {
1521 /* reset chroma resampling for RGB formats */
Archit Taneja2a5561b2012-07-16 16:37:45 +05301522 if (plane != OMAP_DSS_WB)
1523 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301524 return;
1525 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001526
1527 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1528 out_height, ilace, color_mode, rotation);
1529
Amber Jain0d66cbb2011-05-19 19:47:54 +05301530 switch (color_mode) {
1531 case OMAP_DSS_COLOR_NV12:
Archit Taneja20fbb502012-08-22 17:04:48 +05301532 if (chroma_upscale) {
1533 /* UV is subsampled by 2 horizontally and vertically */
1534 orig_height >>= 1;
1535 orig_width >>= 1;
1536 } else {
1537 /* UV is downsampled by 2 horizontally and vertically */
1538 orig_height <<= 1;
1539 orig_width <<= 1;
1540 }
1541
Amber Jain0d66cbb2011-05-19 19:47:54 +05301542 break;
1543 case OMAP_DSS_COLOR_YUV2:
1544 case OMAP_DSS_COLOR_UYVY:
Archit Taneja20fbb502012-08-22 17:04:48 +05301545 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
Amber Jain0d66cbb2011-05-19 19:47:54 +05301546 if (rotation == OMAP_DSS_ROT_0 ||
Archit Taneja20fbb502012-08-22 17:04:48 +05301547 rotation == OMAP_DSS_ROT_180) {
1548 if (chroma_upscale)
1549 /* UV is subsampled by 2 horizontally */
1550 orig_width >>= 1;
1551 else
1552 /* UV is downsampled by 2 horizontally */
1553 orig_width <<= 1;
1554 }
1555
Amber Jain0d66cbb2011-05-19 19:47:54 +05301556 /* must use FIR for YUV422 if rotated */
1557 if (rotation != OMAP_DSS_ROT_0)
1558 scale_x = scale_y = true;
Archit Taneja20fbb502012-08-22 17:04:48 +05301559
Amber Jain0d66cbb2011-05-19 19:47:54 +05301560 break;
1561 default:
1562 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001563 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301564 }
1565
1566 if (out_width != orig_width)
1567 scale_x = true;
1568 if (out_height != orig_height)
1569 scale_y = true;
1570
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001571 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301572 out_width, out_height, five_taps,
1573 rotation, DISPC_COLOR_COMPONENT_UV);
1574
Archit Taneja2a5561b2012-07-16 16:37:45 +05301575 if (plane != OMAP_DSS_WB)
1576 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1577 (scale_x || scale_y) ? 1 : 0, 8, 8);
1578
Amber Jain0d66cbb2011-05-19 19:47:54 +05301579 /* set H scaling */
1580 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1581 /* set V scaling */
1582 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301583}
1584
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001585static void dispc_ovl_set_scaling(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301586 u16 orig_width, u16 orig_height,
1587 u16 out_width, u16 out_height,
1588 bool ilace, bool five_taps,
1589 bool fieldmode, enum omap_color_mode color_mode,
1590 u8 rotation)
1591{
1592 BUG_ON(plane == OMAP_DSS_GFX);
1593
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001594 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301595 orig_width, orig_height,
1596 out_width, out_height,
1597 ilace, five_taps,
1598 fieldmode, color_mode,
1599 rotation);
1600
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001601 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301602 orig_width, orig_height,
1603 out_width, out_height,
1604 ilace, five_taps,
1605 fieldmode, color_mode,
1606 rotation);
1607}
1608
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001609static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001610 bool mirroring, enum omap_color_mode color_mode)
1611{
Archit Taneja87a74842011-03-02 11:19:50 +05301612 bool row_repeat = false;
1613 int vidrot = 0;
1614
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001615 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1616 color_mode == OMAP_DSS_COLOR_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001617
1618 if (mirroring) {
1619 switch (rotation) {
1620 case OMAP_DSS_ROT_0:
1621 vidrot = 2;
1622 break;
1623 case OMAP_DSS_ROT_90:
1624 vidrot = 1;
1625 break;
1626 case OMAP_DSS_ROT_180:
1627 vidrot = 0;
1628 break;
1629 case OMAP_DSS_ROT_270:
1630 vidrot = 3;
1631 break;
1632 }
1633 } else {
1634 switch (rotation) {
1635 case OMAP_DSS_ROT_0:
1636 vidrot = 0;
1637 break;
1638 case OMAP_DSS_ROT_90:
1639 vidrot = 1;
1640 break;
1641 case OMAP_DSS_ROT_180:
1642 vidrot = 2;
1643 break;
1644 case OMAP_DSS_ROT_270:
1645 vidrot = 3;
1646 break;
1647 }
1648 }
1649
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001650 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
Archit Taneja87a74842011-03-02 11:19:50 +05301651 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001652 else
Archit Taneja87a74842011-03-02 11:19:50 +05301653 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001654 }
Archit Taneja87a74842011-03-02 11:19:50 +05301655
Archit Taneja9b372c22011-05-06 11:45:49 +05301656 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301657 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301658 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1659 row_repeat ? 1 : 0, 18, 18);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001660}
1661
1662static int color_mode_to_bpp(enum omap_color_mode color_mode)
1663{
1664 switch (color_mode) {
1665 case OMAP_DSS_COLOR_CLUT1:
1666 return 1;
1667 case OMAP_DSS_COLOR_CLUT2:
1668 return 2;
1669 case OMAP_DSS_COLOR_CLUT4:
1670 return 4;
1671 case OMAP_DSS_COLOR_CLUT8:
Amber Jainf20e4222011-05-19 19:47:50 +05301672 case OMAP_DSS_COLOR_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001673 return 8;
1674 case OMAP_DSS_COLOR_RGB12U:
1675 case OMAP_DSS_COLOR_RGB16:
1676 case OMAP_DSS_COLOR_ARGB16:
1677 case OMAP_DSS_COLOR_YUV2:
1678 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301679 case OMAP_DSS_COLOR_RGBA16:
1680 case OMAP_DSS_COLOR_RGBX16:
1681 case OMAP_DSS_COLOR_ARGB16_1555:
1682 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001683 return 16;
1684 case OMAP_DSS_COLOR_RGB24P:
1685 return 24;
1686 case OMAP_DSS_COLOR_RGB24U:
1687 case OMAP_DSS_COLOR_ARGB32:
1688 case OMAP_DSS_COLOR_RGBA32:
1689 case OMAP_DSS_COLOR_RGBX32:
1690 return 32;
1691 default:
1692 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001693 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001694 }
1695}
1696
1697static s32 pixinc(int pixels, u8 ps)
1698{
1699 if (pixels == 1)
1700 return 1;
1701 else if (pixels > 1)
1702 return 1 + (pixels - 1) * ps;
1703 else if (pixels < 0)
1704 return 1 - (-pixels + 1) * ps;
1705 else
1706 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001707 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001708}
1709
1710static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1711 u16 screen_width,
1712 u16 width, u16 height,
1713 enum omap_color_mode color_mode, bool fieldmode,
1714 unsigned int field_offset,
1715 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301716 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001717{
1718 u8 ps;
1719
1720 /* FIXME CLUT formats */
1721 switch (color_mode) {
1722 case OMAP_DSS_COLOR_CLUT1:
1723 case OMAP_DSS_COLOR_CLUT2:
1724 case OMAP_DSS_COLOR_CLUT4:
1725 case OMAP_DSS_COLOR_CLUT8:
1726 BUG();
1727 return;
1728 case OMAP_DSS_COLOR_YUV2:
1729 case OMAP_DSS_COLOR_UYVY:
1730 ps = 4;
1731 break;
1732 default:
1733 ps = color_mode_to_bpp(color_mode) / 8;
1734 break;
1735 }
1736
1737 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1738 width, height);
1739
1740 /*
1741 * field 0 = even field = bottom field
1742 * field 1 = odd field = top field
1743 */
1744 switch (rotation + mirror * 4) {
1745 case OMAP_DSS_ROT_0:
1746 case OMAP_DSS_ROT_180:
1747 /*
1748 * If the pixel format is YUV or UYVY divide the width
1749 * of the image by 2 for 0 and 180 degree rotation.
1750 */
1751 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1752 color_mode == OMAP_DSS_COLOR_UYVY)
1753 width = width >> 1;
1754 case OMAP_DSS_ROT_90:
1755 case OMAP_DSS_ROT_270:
1756 *offset1 = 0;
1757 if (field_offset)
1758 *offset0 = field_offset * screen_width * ps;
1759 else
1760 *offset0 = 0;
1761
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301762 *row_inc = pixinc(1 +
1763 (y_predecim * screen_width - x_predecim * width) +
1764 (fieldmode ? screen_width : 0), ps);
1765 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001766 break;
1767
1768 case OMAP_DSS_ROT_0 + 4:
1769 case OMAP_DSS_ROT_180 + 4:
1770 /* If the pixel format is YUV or UYVY divide the width
1771 * of the image by 2 for 0 degree and 180 degree
1772 */
1773 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1774 color_mode == OMAP_DSS_COLOR_UYVY)
1775 width = width >> 1;
1776 case OMAP_DSS_ROT_90 + 4:
1777 case OMAP_DSS_ROT_270 + 4:
1778 *offset1 = 0;
1779 if (field_offset)
1780 *offset0 = field_offset * screen_width * ps;
1781 else
1782 *offset0 = 0;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301783 *row_inc = pixinc(1 -
1784 (y_predecim * screen_width + x_predecim * width) -
1785 (fieldmode ? screen_width : 0), ps);
1786 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001787 break;
1788
1789 default:
1790 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001791 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001792 }
1793}
1794
1795static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1796 u16 screen_width,
1797 u16 width, u16 height,
1798 enum omap_color_mode color_mode, bool fieldmode,
1799 unsigned int field_offset,
1800 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301801 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001802{
1803 u8 ps;
1804 u16 fbw, fbh;
1805
1806 /* FIXME CLUT formats */
1807 switch (color_mode) {
1808 case OMAP_DSS_COLOR_CLUT1:
1809 case OMAP_DSS_COLOR_CLUT2:
1810 case OMAP_DSS_COLOR_CLUT4:
1811 case OMAP_DSS_COLOR_CLUT8:
1812 BUG();
1813 return;
1814 default:
1815 ps = color_mode_to_bpp(color_mode) / 8;
1816 break;
1817 }
1818
1819 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1820 width, height);
1821
1822 /* width & height are overlay sizes, convert to fb sizes */
1823
1824 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1825 fbw = width;
1826 fbh = height;
1827 } else {
1828 fbw = height;
1829 fbh = width;
1830 }
1831
1832 /*
1833 * field 0 = even field = bottom field
1834 * field 1 = odd field = top field
1835 */
1836 switch (rotation + mirror * 4) {
1837 case OMAP_DSS_ROT_0:
1838 *offset1 = 0;
1839 if (field_offset)
1840 *offset0 = *offset1 + field_offset * screen_width * ps;
1841 else
1842 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301843 *row_inc = pixinc(1 +
1844 (y_predecim * screen_width - fbw * x_predecim) +
1845 (fieldmode ? screen_width : 0), ps);
1846 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1847 color_mode == OMAP_DSS_COLOR_UYVY)
1848 *pix_inc = pixinc(x_predecim, 2 * ps);
1849 else
1850 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001851 break;
1852 case OMAP_DSS_ROT_90:
1853 *offset1 = screen_width * (fbh - 1) * ps;
1854 if (field_offset)
1855 *offset0 = *offset1 + field_offset * ps;
1856 else
1857 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301858 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1859 y_predecim + (fieldmode ? 1 : 0), ps);
1860 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001861 break;
1862 case OMAP_DSS_ROT_180:
1863 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1864 if (field_offset)
1865 *offset0 = *offset1 - field_offset * screen_width * ps;
1866 else
1867 *offset0 = *offset1;
1868 *row_inc = pixinc(-1 -
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301869 (y_predecim * screen_width - fbw * x_predecim) -
1870 (fieldmode ? screen_width : 0), ps);
1871 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1872 color_mode == OMAP_DSS_COLOR_UYVY)
1873 *pix_inc = pixinc(-x_predecim, 2 * ps);
1874 else
1875 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001876 break;
1877 case OMAP_DSS_ROT_270:
1878 *offset1 = (fbw - 1) * ps;
1879 if (field_offset)
1880 *offset0 = *offset1 - field_offset * ps;
1881 else
1882 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301883 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1884 y_predecim - (fieldmode ? 1 : 0), ps);
1885 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001886 break;
1887
1888 /* mirroring */
1889 case OMAP_DSS_ROT_0 + 4:
1890 *offset1 = (fbw - 1) * ps;
1891 if (field_offset)
1892 *offset0 = *offset1 + field_offset * screen_width * ps;
1893 else
1894 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301895 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001896 (fieldmode ? screen_width : 0),
1897 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301898 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1899 color_mode == OMAP_DSS_COLOR_UYVY)
1900 *pix_inc = pixinc(-x_predecim, 2 * ps);
1901 else
1902 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001903 break;
1904
1905 case OMAP_DSS_ROT_90 + 4:
1906 *offset1 = 0;
1907 if (field_offset)
1908 *offset0 = *offset1 + field_offset * ps;
1909 else
1910 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301911 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1912 y_predecim + (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001913 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301914 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001915 break;
1916
1917 case OMAP_DSS_ROT_180 + 4:
1918 *offset1 = screen_width * (fbh - 1) * ps;
1919 if (field_offset)
1920 *offset0 = *offset1 - field_offset * screen_width * ps;
1921 else
1922 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301923 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001924 (fieldmode ? screen_width : 0),
1925 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301926 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1927 color_mode == OMAP_DSS_COLOR_UYVY)
1928 *pix_inc = pixinc(x_predecim, 2 * ps);
1929 else
1930 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001931 break;
1932
1933 case OMAP_DSS_ROT_270 + 4:
1934 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1935 if (field_offset)
1936 *offset0 = *offset1 - field_offset * ps;
1937 else
1938 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301939 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
1940 y_predecim - (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001941 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301942 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001943 break;
1944
1945 default:
1946 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001947 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001948 }
1949}
1950
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301951static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
1952 enum omap_color_mode color_mode, bool fieldmode,
1953 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1954 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1955{
1956 u8 ps;
1957
1958 switch (color_mode) {
1959 case OMAP_DSS_COLOR_CLUT1:
1960 case OMAP_DSS_COLOR_CLUT2:
1961 case OMAP_DSS_COLOR_CLUT4:
1962 case OMAP_DSS_COLOR_CLUT8:
1963 BUG();
1964 return;
1965 default:
1966 ps = color_mode_to_bpp(color_mode) / 8;
1967 break;
1968 }
1969
1970 DSSDBG("scrw %d, width %d\n", screen_width, width);
1971
1972 /*
1973 * field 0 = even field = bottom field
1974 * field 1 = odd field = top field
1975 */
1976 *offset1 = 0;
1977 if (field_offset)
1978 *offset0 = *offset1 + field_offset * screen_width * ps;
1979 else
1980 *offset0 = *offset1;
1981 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1982 (fieldmode ? screen_width : 0), ps);
1983 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1984 color_mode == OMAP_DSS_COLOR_UYVY)
1985 *pix_inc = pixinc(x_predecim, 2 * ps);
1986 else
1987 *pix_inc = pixinc(x_predecim, ps);
1988}
1989
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301990/*
1991 * This function is used to avoid synclosts in OMAP3, because of some
1992 * undocumented horizontal position and timing related limitations.
1993 */
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05301994static int check_horiz_timing_omap3(enum omap_plane plane,
Archit Taneja81ab95b2012-05-08 15:53:20 +05301995 const struct omap_video_timings *t, u16 pos_x,
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301996 u16 width, u16 height, u16 out_width, u16 out_height)
1997{
1998 int DS = DIV_ROUND_UP(height, out_height);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05301999 unsigned long nonactive;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302000 static const u8 limits[3] = { 8, 10, 20 };
2001 u64 val, blank;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302002 unsigned long pclk = dispc_plane_pclk_rate(plane);
2003 unsigned long lclk = dispc_plane_lclk_rate(plane);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302004 int i;
2005
Archit Taneja81ab95b2012-05-08 15:53:20 +05302006 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302007
2008 i = 0;
2009 if (out_height < height)
2010 i++;
2011 if (out_width < width)
2012 i++;
Archit Taneja81ab95b2012-05-08 15:53:20 +05302013 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302014 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2015 if (blank <= limits[i])
2016 return -EINVAL;
2017
2018 /*
2019 * Pixel data should be prepared before visible display point starts.
2020 * So, atleast DS-2 lines must have already been fetched by DISPC
2021 * during nonactive - pos_x period.
2022 */
2023 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2024 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2025 val, max(0, DS - 2) * width);
2026 if (val < max(0, DS - 2) * width)
2027 return -EINVAL;
2028
2029 /*
2030 * All lines need to be refilled during the nonactive period of which
2031 * only one line can be loaded during the active period. So, atleast
2032 * DS - 1 lines should be loaded during nonactive period.
2033 */
2034 val = div_u64((u64)nonactive * lclk, pclk);
2035 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
2036 val, max(0, DS - 1) * width);
2037 if (val < max(0, DS - 1) * width)
2038 return -EINVAL;
2039
2040 return 0;
2041}
2042
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302043static unsigned long calc_core_clk_five_taps(enum omap_plane plane,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302044 const struct omap_video_timings *mgr_timings, u16 width,
2045 u16 height, u16 out_width, u16 out_height,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002046 enum omap_color_mode color_mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002047{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302048 u32 core_clk = 0;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302049 u64 tmp;
2050 unsigned long pclk = dispc_plane_pclk_rate(plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002051
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302052 if (height <= out_height && width <= out_width)
2053 return (unsigned long) pclk;
2054
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002055 if (height > out_height) {
Archit Taneja81ab95b2012-05-08 15:53:20 +05302056 unsigned int ppl = mgr_timings->x_res;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002057
2058 tmp = pclk * height * out_width;
2059 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302060 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002061
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02002062 if (height > 2 * out_height) {
2063 if (ppl == out_width)
2064 return 0;
2065
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002066 tmp = pclk * (height - 2 * out_height) * out_width;
2067 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302068 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002069 }
2070 }
2071
2072 if (width > out_width) {
2073 tmp = pclk * width;
2074 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302075 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002076
2077 if (color_mode == OMAP_DSS_COLOR_RGB24U)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302078 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002079 }
2080
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302081 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002082}
2083
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302084static unsigned long calc_core_clk_24xx(enum omap_plane plane, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302085 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302086{
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302087 unsigned long pclk = dispc_plane_pclk_rate(plane);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302088
2089 if (height > out_height && width > out_width)
2090 return pclk * 4;
2091 else
2092 return pclk * 2;
2093}
2094
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302095static unsigned long calc_core_clk_34xx(enum omap_plane plane, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302096 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002097{
2098 unsigned int hf, vf;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302099 unsigned long pclk = dispc_plane_pclk_rate(plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002100
2101 /*
2102 * FIXME how to determine the 'A' factor
2103 * for the no downscaling case ?
2104 */
2105
2106 if (width > 3 * out_width)
2107 hf = 4;
2108 else if (width > 2 * out_width)
2109 hf = 3;
2110 else if (width > out_width)
2111 hf = 2;
2112 else
2113 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002114 if (height > out_height)
2115 vf = 2;
2116 else
2117 vf = 1;
2118
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302119 return pclk * vf * hf;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002120}
2121
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302122static unsigned long calc_core_clk_44xx(enum omap_plane plane, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302123 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302124{
Archit Taneja8ba85302012-09-26 17:00:37 +05302125 unsigned long pclk;
2126
2127 /*
2128 * If the overlay/writeback is in mem to mem mode, there are no
2129 * downscaling limitations with respect to pixel clock, return 1 as
2130 * required core clock to represent that we have sufficient enough
2131 * core clock to do maximum downscaling
2132 */
2133 if (mem_to_mem)
2134 return 1;
2135
2136 pclk = dispc_plane_pclk_rate(plane);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302137
2138 if (width > out_width)
2139 return DIV_ROUND_UP(pclk, out_width) * width;
2140 else
2141 return pclk;
2142}
2143
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302144static int dispc_ovl_calc_scaling_24xx(enum omap_plane plane,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302145 const struct omap_video_timings *mgr_timings,
2146 u16 width, u16 height, u16 out_width, u16 out_height,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302147 enum omap_color_mode color_mode, bool *five_taps,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302148 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302149 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302150{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302151 int error;
2152 u16 in_width, in_height;
2153 int min_factor = min(*decim_x, *decim_y);
2154 const int maxsinglelinewidth =
2155 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302156
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302157 *five_taps = false;
2158
2159 do {
2160 in_height = DIV_ROUND_UP(height, *decim_y);
2161 in_width = DIV_ROUND_UP(width, *decim_x);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302162 *core_clk = dispc.feat->calc_core_clk(plane, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302163 in_height, out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302164 error = (in_width > maxsinglelinewidth || !*core_clk ||
2165 *core_clk > dispc_core_clk_rate());
2166 if (error) {
2167 if (*decim_x == *decim_y) {
2168 *decim_x = min_factor;
2169 ++*decim_y;
2170 } else {
2171 swap(*decim_x, *decim_y);
2172 if (*decim_x < *decim_y)
2173 ++*decim_x;
2174 }
2175 }
2176 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2177
2178 if (in_width > maxsinglelinewidth) {
2179 DSSERR("Cannot scale max input width exceeded");
2180 return -EINVAL;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002181 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302182 return 0;
2183}
2184
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302185static int dispc_ovl_calc_scaling_34xx(enum omap_plane plane,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302186 const struct omap_video_timings *mgr_timings,
2187 u16 width, u16 height, u16 out_width, u16 out_height,
2188 enum omap_color_mode color_mode, bool *five_taps,
2189 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302190 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302191{
2192 int error;
2193 u16 in_width, in_height;
2194 int min_factor = min(*decim_x, *decim_y);
2195 const int maxsinglelinewidth =
2196 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2197
2198 do {
2199 in_height = DIV_ROUND_UP(height, *decim_y);
2200 in_width = DIV_ROUND_UP(width, *decim_x);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302201 *core_clk = calc_core_clk_five_taps(plane, mgr_timings,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302202 in_width, in_height, out_width, out_height, color_mode);
2203
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302204 error = check_horiz_timing_omap3(plane, mgr_timings,
2205 pos_x, in_width, in_height, out_width,
2206 out_height);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302207
2208 if (in_width > maxsinglelinewidth)
2209 if (in_height > out_height &&
2210 in_height < out_height * 2)
2211 *five_taps = false;
2212 if (!*five_taps)
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302213 *core_clk = dispc.feat->calc_core_clk(plane, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302214 in_height, out_width, out_height,
2215 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302216
2217 error = (error || in_width > maxsinglelinewidth * 2 ||
2218 (in_width > maxsinglelinewidth && *five_taps) ||
2219 !*core_clk || *core_clk > dispc_core_clk_rate());
2220 if (error) {
2221 if (*decim_x == *decim_y) {
2222 *decim_x = min_factor;
2223 ++*decim_y;
2224 } else {
2225 swap(*decim_x, *decim_y);
2226 if (*decim_x < *decim_y)
2227 ++*decim_x;
2228 }
2229 }
2230 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2231
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302232 if (check_horiz_timing_omap3(plane, mgr_timings, pos_x, width, height,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302233 out_width, out_height)){
2234 DSSERR("horizontal timing too tight\n");
2235 return -EINVAL;
2236 }
2237
2238 if (in_width > (maxsinglelinewidth * 2)) {
2239 DSSERR("Cannot setup scaling");
2240 DSSERR("width exceeds maximum width possible");
2241 return -EINVAL;
2242 }
2243
2244 if (in_width > maxsinglelinewidth && *five_taps) {
2245 DSSERR("cannot setup scaling with five taps");
2246 return -EINVAL;
2247 }
2248 return 0;
2249}
2250
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302251static int dispc_ovl_calc_scaling_44xx(enum omap_plane plane,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302252 const struct omap_video_timings *mgr_timings,
2253 u16 width, u16 height, u16 out_width, u16 out_height,
2254 enum omap_color_mode color_mode, bool *five_taps,
2255 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302256 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302257{
2258 u16 in_width, in_width_max;
2259 int decim_x_min = *decim_x;
2260 u16 in_height = DIV_ROUND_UP(height, *decim_y);
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302261 const int maxsinglelinewidth =
2262 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302263 unsigned long pclk = dispc_plane_pclk_rate(plane);
Archit Taneja8ba85302012-09-26 17:00:37 +05302264 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302265
Archit Taneja8ba85302012-09-26 17:00:37 +05302266 if (mem_to_mem)
2267 in_width_max = DIV_ROUND_UP(out_width, maxdownscale);
2268 else
2269 in_width_max = dispc_core_clk_rate() /
2270 DIV_ROUND_UP(pclk, out_width);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302271
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302272 *decim_x = DIV_ROUND_UP(width, in_width_max);
2273
2274 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2275 if (*decim_x > *x_predecim)
2276 return -EINVAL;
2277
2278 do {
2279 in_width = DIV_ROUND_UP(width, *decim_x);
2280 } while (*decim_x <= *x_predecim &&
2281 in_width > maxsinglelinewidth && ++*decim_x);
2282
2283 if (in_width > maxsinglelinewidth) {
2284 DSSERR("Cannot scale width exceeds max line width");
2285 return -EINVAL;
2286 }
2287
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302288 *core_clk = dispc.feat->calc_core_clk(plane, in_width, in_height,
Archit Taneja8ba85302012-09-26 17:00:37 +05302289 out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302290 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002291}
2292
Archit Taneja79ad75f2011-09-08 13:15:11 +05302293static int dispc_ovl_calc_scaling(enum omap_plane plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302294 enum omap_overlay_caps caps,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002295 const struct omap_video_timings *mgr_timings,
2296 u16 width, u16 height, u16 out_width, u16 out_height,
Archit Taneja79ad75f2011-09-08 13:15:11 +05302297 enum omap_color_mode color_mode, bool *five_taps,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302298 int *x_predecim, int *y_predecim, u16 pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302299 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302300{
Archit Taneja79ad75f2011-09-08 13:15:11 +05302301 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302302 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302303 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302304 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302305
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002306 if (width == out_width && height == out_height)
2307 return 0;
2308
Archit Taneja5b54ed32012-09-26 16:55:27 +05302309 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002310 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302311
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302312 *x_predecim = max_decim_limit;
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302313 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2314 dss_has_feature(FEAT_BURST_2D)) ? 2 : max_decim_limit;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302315
2316 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2317 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2318 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2319 color_mode == OMAP_DSS_COLOR_CLUT8) {
2320 *x_predecim = 1;
2321 *y_predecim = 1;
2322 *five_taps = false;
2323 return 0;
2324 }
2325
2326 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2327 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2328
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302329 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302330 return -EINVAL;
2331
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302332 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302333 return -EINVAL;
2334
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302335 ret = dispc.feat->calc_scaling(plane, mgr_timings, width, height,
2336 out_width, out_height, color_mode, five_taps,
Archit Taneja8ba85302012-09-26 17:00:37 +05302337 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2338 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302339 if (ret)
2340 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302341
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302342 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2343 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302344
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302345 if (!core_clk || core_clk > dispc_core_clk_rate()) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302346 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302347 "required core clk rate = %lu Hz, "
2348 "current core clk rate = %lu Hz\n",
2349 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302350 return -EINVAL;
2351 }
2352
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302353 *x_predecim = decim_x;
2354 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302355 return 0;
2356}
2357
Archit Taneja84a880f2012-09-26 16:57:37 +05302358static int dispc_ovl_setup_common(enum omap_plane plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302359 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2360 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2361 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2362 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2363 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
Archit Taneja8ba85302012-09-26 17:00:37 +05302364 bool replication, const struct omap_video_timings *mgr_timings,
2365 bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002366{
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302367 bool five_taps = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002368 bool fieldmode = 0;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302369 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002370 unsigned offset0, offset1;
2371 s32 row_inc;
2372 s32 pix_inc;
Archit Taneja84a880f2012-09-26 16:57:37 +05302373 u16 frame_height = height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002374 unsigned int field_offset = 0;
Archit Taneja84a880f2012-09-26 16:57:37 +05302375 u16 in_height = height;
2376 u16 in_width = width;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302377 int x_predecim = 1, y_predecim = 1;
Archit Taneja8050cbe2012-06-06 16:25:52 +05302378 bool ilace = mgr_timings->interlace;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002379
Archit Taneja84a880f2012-09-26 16:57:37 +05302380 if (paddr == 0)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002381 return -EINVAL;
2382
Archit Taneja84a880f2012-09-26 16:57:37 +05302383 out_width = out_width == 0 ? width : out_width;
2384 out_height = out_height == 0 ? height : out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002385
Archit Taneja84a880f2012-09-26 16:57:37 +05302386 if (ilace && height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002387 fieldmode = 1;
2388
2389 if (ilace) {
2390 if (fieldmode)
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302391 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302392 pos_y /= 2;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302393 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002394
2395 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
Archit Taneja84a880f2012-09-26 16:57:37 +05302396 "out_height %d\n", in_height, pos_y,
2397 out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002398 }
2399
Archit Taneja84a880f2012-09-26 16:57:37 +05302400 if (!dss_feat_color_mode_supported(plane, color_mode))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302401 return -EINVAL;
2402
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302403 r = dispc_ovl_calc_scaling(plane, caps, mgr_timings, in_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302404 in_height, out_width, out_height, color_mode,
2405 &five_taps, &x_predecim, &y_predecim, pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302406 rotation_type, mem_to_mem);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302407 if (r)
2408 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002409
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302410 in_width = DIV_ROUND_UP(in_width, x_predecim);
2411 in_height = DIV_ROUND_UP(in_height, y_predecim);
2412
Archit Taneja84a880f2012-09-26 16:57:37 +05302413 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2414 color_mode == OMAP_DSS_COLOR_UYVY ||
2415 color_mode == OMAP_DSS_COLOR_NV12)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302416 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002417
2418 if (ilace && !fieldmode) {
2419 /*
2420 * when downscaling the bottom field may have to start several
2421 * source lines below the top field. Unfortunately ACCUI
2422 * registers will only hold the fractional part of the offset
2423 * so the integer part must be added to the base address of the
2424 * bottom field.
2425 */
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302426 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002427 field_offset = 0;
2428 else
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302429 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002430 }
2431
2432 /* Fields are independent but interleaved in memory. */
2433 if (fieldmode)
2434 field_offset = 1;
2435
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002436 offset0 = 0;
2437 offset1 = 0;
2438 row_inc = 0;
2439 pix_inc = 0;
2440
Archit Taneja84a880f2012-09-26 16:57:37 +05302441 if (rotation_type == OMAP_DSS_ROT_TILER)
2442 calc_tiler_rotation_offset(screen_width, in_width,
2443 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302444 &offset0, &offset1, &row_inc, &pix_inc,
2445 x_predecim, y_predecim);
Archit Taneja84a880f2012-09-26 16:57:37 +05302446 else if (rotation_type == OMAP_DSS_ROT_DMA)
2447 calc_dma_rotation_offset(rotation, mirror,
2448 screen_width, in_width, frame_height,
2449 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302450 &offset0, &offset1, &row_inc, &pix_inc,
2451 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002452 else
Archit Taneja84a880f2012-09-26 16:57:37 +05302453 calc_vrfb_rotation_offset(rotation, mirror,
2454 screen_width, in_width, frame_height,
2455 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302456 &offset0, &offset1, &row_inc, &pix_inc,
2457 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002458
2459 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2460 offset0, offset1, row_inc, pix_inc);
2461
Archit Taneja84a880f2012-09-26 16:57:37 +05302462 dispc_ovl_set_color_mode(plane, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002463
Archit Taneja84a880f2012-09-26 16:57:37 +05302464 dispc_ovl_configure_burst_type(plane, rotation_type);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302465
Archit Taneja84a880f2012-09-26 16:57:37 +05302466 dispc_ovl_set_ba0(plane, paddr + offset0);
2467 dispc_ovl_set_ba1(plane, paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002468
Archit Taneja84a880f2012-09-26 16:57:37 +05302469 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2470 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2471 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302472 }
2473
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002474 dispc_ovl_set_row_inc(plane, row_inc);
2475 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002476
Archit Taneja84a880f2012-09-26 16:57:37 +05302477 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302478 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002479
Archit Taneja84a880f2012-09-26 16:57:37 +05302480 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002481
Archit Taneja78b687f2012-09-21 14:51:49 +05302482 dispc_ovl_set_input_size(plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002483
Archit Taneja5b54ed32012-09-26 16:55:27 +05302484 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302485 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2486 out_height, ilace, five_taps, fieldmode,
Archit Taneja84a880f2012-09-26 16:57:37 +05302487 color_mode, rotation);
Archit Taneja78b687f2012-09-21 14:51:49 +05302488 dispc_ovl_set_output_size(plane, out_width, out_height);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002489 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002490 }
2491
Archit Taneja84a880f2012-09-26 16:57:37 +05302492 dispc_ovl_set_rotation_attrs(plane, rotation, mirror, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002493
Archit Taneja84a880f2012-09-26 16:57:37 +05302494 dispc_ovl_set_zorder(plane, caps, zorder);
2495 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2496 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002497
Archit Tanejad79db852012-09-22 12:30:17 +05302498 dispc_ovl_enable_replication(plane, caps, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302499
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002500 return 0;
2501}
2502
Archit Taneja84a880f2012-09-26 16:57:37 +05302503int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
Archit Taneja8ba85302012-09-26 17:00:37 +05302504 bool replication, const struct omap_video_timings *mgr_timings,
2505 bool mem_to_mem)
Archit Taneja84a880f2012-09-26 16:57:37 +05302506{
2507 int r;
2508 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
2509 enum omap_channel channel;
2510
2511 channel = dispc_ovl_get_channel_out(plane);
2512
2513 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
2514 "%dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2515 plane, oi->paddr, oi->p_uv_addr, oi->screen_width, oi->pos_x,
2516 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2517 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2518
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302519 r = dispc_ovl_setup_common(plane, ovl->caps, oi->paddr, oi->p_uv_addr,
2520 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2521 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2522 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
Archit Taneja8ba85302012-09-26 17:00:37 +05302523 oi->rotation_type, replication, mgr_timings, mem_to_mem);
Archit Taneja84a880f2012-09-26 16:57:37 +05302524
2525 return r;
2526}
2527
Archit Taneja749feff2012-08-31 12:32:52 +05302528int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302529 bool mem_to_mem, const struct omap_video_timings *mgr_timings)
Archit Taneja749feff2012-08-31 12:32:52 +05302530{
2531 int r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302532 u32 l;
Archit Taneja749feff2012-08-31 12:32:52 +05302533 enum omap_plane plane = OMAP_DSS_WB;
2534 const int pos_x = 0, pos_y = 0;
2535 const u8 zorder = 0, global_alpha = 0;
2536 const bool replication = false;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302537 bool truncation;
Archit Taneja749feff2012-08-31 12:32:52 +05302538 int in_width = mgr_timings->x_res;
2539 int in_height = mgr_timings->y_res;
2540 enum omap_overlay_caps caps =
2541 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2542
2543 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2544 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2545 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2546 wi->mirror);
2547
2548 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2549 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2550 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2551 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302552 replication, mgr_timings, mem_to_mem);
2553
2554 switch (wi->color_mode) {
2555 case OMAP_DSS_COLOR_RGB16:
2556 case OMAP_DSS_COLOR_RGB24P:
2557 case OMAP_DSS_COLOR_ARGB16:
2558 case OMAP_DSS_COLOR_RGBA16:
2559 case OMAP_DSS_COLOR_RGB12U:
2560 case OMAP_DSS_COLOR_ARGB16_1555:
2561 case OMAP_DSS_COLOR_XRGB16_1555:
2562 case OMAP_DSS_COLOR_RGBX16:
2563 truncation = true;
2564 break;
2565 default:
2566 truncation = false;
2567 break;
2568 }
2569
2570 /* setup extra DISPC_WB_ATTRIBUTES */
2571 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2572 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2573 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2574 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Archit Taneja749feff2012-08-31 12:32:52 +05302575
2576 return r;
2577}
2578
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002579int dispc_ovl_enable(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002580{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002581 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2582
Archit Taneja9b372c22011-05-06 11:45:49 +05302583 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002584
2585 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002586}
2587
2588static void dispc_disable_isr(void *data, u32 mask)
2589{
2590 struct completion *compl = data;
2591 complete(compl);
2592}
2593
Sumit Semwal2a205f32010-12-02 11:27:12 +00002594static void _enable_lcd_out(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002595{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302596 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2597 /* flush posted write */
2598 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002599}
2600
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002601static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002602{
2603 struct completion frame_done_completion;
2604 bool is_on;
2605 int r;
Sumit Semwal2a205f32010-12-02 11:27:12 +00002606 u32 irq;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002607
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002608 /* When we disable LCD output, we need to wait until frame is done.
2609 * Otherwise the DSS is still working, and turning off the clocks
2610 * prevents DSS from going to OFF mode */
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302611 is_on = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002612
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302613 irq = mgr_desc[channel].framedone_irq;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002614
2615 if (!enable && is_on) {
2616 init_completion(&frame_done_completion);
2617
2618 r = omap_dispc_register_isr(dispc_disable_isr,
Sumit Semwal2a205f32010-12-02 11:27:12 +00002619 &frame_done_completion, irq);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002620
2621 if (r)
2622 DSSERR("failed to register FRAMEDONE isr\n");
2623 }
2624
Sumit Semwal2a205f32010-12-02 11:27:12 +00002625 _enable_lcd_out(channel, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002626
2627 if (!enable && is_on) {
2628 if (!wait_for_completion_timeout(&frame_done_completion,
2629 msecs_to_jiffies(100)))
2630 DSSERR("timeout waiting for FRAME DONE\n");
2631
2632 r = omap_dispc_unregister_isr(dispc_disable_isr,
Sumit Semwal2a205f32010-12-02 11:27:12 +00002633 &frame_done_completion, irq);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002634
2635 if (r)
2636 DSSERR("failed to unregister FRAMEDONE isr\n");
2637 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002638}
2639
2640static void _enable_digit_out(bool enable)
2641{
2642 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
Tomi Valkeinenb6a44e72011-10-12 10:17:02 +03002643 /* flush posted write */
2644 dispc_read_reg(DISPC_CONTROL);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002645}
2646
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002647static void dispc_mgr_enable_digit_out(bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002648{
2649 struct completion frame_done_completion;
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002650 enum dss_hdmi_venc_clk_source_select src;
2651 int r, i;
2652 u32 irq_mask;
2653 int num_irqs;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002654
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002655 if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002656 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002657
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002658 src = dss_get_hdmi_venc_clk_source();
2659
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002660 if (enable) {
2661 unsigned long flags;
2662 /* When we enable digit output, we'll get an extra digit
2663 * sync lost interrupt, that we need to ignore */
2664 spin_lock_irqsave(&dispc.irq_lock, flags);
2665 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
2666 _omap_dispc_set_irqs();
2667 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2668 }
2669
2670 /* When we disable digit output, we need to wait until fields are done.
2671 * Otherwise the DSS is still working, and turning off the clocks
2672 * prevents DSS from going to OFF mode. And when enabling, we need to
2673 * wait for the extra sync losts */
2674 init_completion(&frame_done_completion);
2675
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002676 if (src == DSS_HDMI_M_PCLK && enable == false) {
2677 irq_mask = DISPC_IRQ_FRAMEDONETV;
2678 num_irqs = 1;
2679 } else {
2680 irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
2681 /* XXX I understand from TRM that we should only wait for the
2682 * current field to complete. But it seems we have to wait for
2683 * both fields */
2684 num_irqs = 2;
2685 }
2686
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002687 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002688 irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002689 if (r)
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002690 DSSERR("failed to register %x isr\n", irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002691
2692 _enable_digit_out(enable);
2693
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002694 for (i = 0; i < num_irqs; ++i) {
2695 if (!wait_for_completion_timeout(&frame_done_completion,
2696 msecs_to_jiffies(100)))
2697 DSSERR("timeout waiting for digit out to %s\n",
2698 enable ? "start" : "stop");
2699 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002700
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002701 r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
2702 irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002703 if (r)
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002704 DSSERR("failed to unregister %x isr\n", irq_mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002705
2706 if (enable) {
2707 unsigned long flags;
2708 spin_lock_irqsave(&dispc.irq_lock, flags);
Tomi Valkeinene82b0902011-08-31 14:42:49 +03002709 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002710 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
2711 _omap_dispc_set_irqs();
2712 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2713 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002714}
2715
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002716bool dispc_mgr_is_enabled(enum omap_channel channel)
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002717{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302718 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002719}
2720
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002721void dispc_mgr_enable(enum omap_channel channel, bool enable)
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002722{
Archit Tanejadd88b7a2012-06-29 14:41:30 +05302723 if (dss_mgr_is_lcd(channel))
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002724 dispc_mgr_enable_lcd_out(channel, enable);
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002725 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002726 dispc_mgr_enable_digit_out(enable);
Tomi Valkeinena2faee82010-01-08 17:14:53 +02002727 else
2728 BUG();
2729}
2730
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302731void dispc_wb_enable(bool enable)
2732{
2733 enum omap_plane plane = OMAP_DSS_WB;
2734 struct completion frame_done_completion;
2735 bool is_on;
2736 int r;
2737 u32 irq;
2738
2739 is_on = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2740 irq = DISPC_IRQ_FRAMEDONEWB;
2741
2742 if (!enable && is_on) {
2743 init_completion(&frame_done_completion);
2744
2745 r = omap_dispc_register_isr(dispc_disable_isr,
2746 &frame_done_completion, irq);
2747 if (r)
2748 DSSERR("failed to register FRAMEDONEWB isr\n");
2749 }
2750
2751 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2752
2753 if (!enable && is_on) {
2754 if (!wait_for_completion_timeout(&frame_done_completion,
2755 msecs_to_jiffies(100)))
2756 DSSERR("timeout waiting for FRAMEDONEWB\n");
2757
2758 r = omap_dispc_unregister_isr(dispc_disable_isr,
2759 &frame_done_completion, irq);
2760 if (r)
2761 DSSERR("failed to unregister FRAMEDONEWB isr\n");
2762 }
2763}
2764
2765bool dispc_wb_is_enabled(void)
2766{
2767 enum omap_plane plane = OMAP_DSS_WB;
2768
2769 return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2770}
2771
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002772void dispc_lcd_enable_signal_polarity(bool act_high)
2773{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002774 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2775 return;
2776
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002777 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002778}
2779
2780void dispc_lcd_enable_signal(bool enable)
2781{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002782 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2783 return;
2784
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002785 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002786}
2787
2788void dispc_pck_free_enable(bool enable)
2789{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002790 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2791 return;
2792
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002793 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002794}
2795
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002796void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002797{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302798 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002799}
2800
2801
Archit Tanejad21f43b2012-06-21 09:45:11 +05302802void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002803{
Archit Tanejad21f43b2012-06-21 09:45:11 +05302804 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002805}
2806
2807void dispc_set_loadmode(enum omap_dss_load_mode mode)
2808{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002809 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002810}
2811
2812
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002813static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002814{
Sumit Semwal8613b002010-12-02 11:27:09 +00002815 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002816}
2817
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002818static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002819 enum omap_dss_trans_key_type type,
2820 u32 trans_key)
2821{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302822 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002823
Sumit Semwal8613b002010-12-02 11:27:09 +00002824 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002825}
2826
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002827static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002828{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302829 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002830}
Archit Taneja11354dd2011-09-26 11:47:29 +05302831
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002832static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2833 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002834{
Archit Taneja11354dd2011-09-26 11:47:29 +05302835 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002836 return;
2837
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002838 if (ch == OMAP_DSS_CHANNEL_LCD)
2839 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002840 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002841 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002842}
Archit Taneja11354dd2011-09-26 11:47:29 +05302843
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002844void dispc_mgr_setup(enum omap_channel channel,
2845 struct omap_overlay_manager_info *info)
2846{
2847 dispc_mgr_set_default_color(channel, info->default_color);
2848 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2849 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2850 dispc_mgr_enable_alpha_fixed_zorder(channel,
2851 info->partial_alpha_enabled);
2852 if (dss_has_feature(FEAT_CPR)) {
2853 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2854 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2855 }
2856}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002857
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002858void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002859{
2860 int code;
2861
2862 switch (data_lines) {
2863 case 12:
2864 code = 0;
2865 break;
2866 case 16:
2867 code = 1;
2868 break;
2869 case 18:
2870 code = 2;
2871 break;
2872 case 24:
2873 code = 3;
2874 break;
2875 default:
2876 BUG();
2877 return;
2878 }
2879
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302880 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002881}
2882
Archit Taneja569969d2011-08-22 17:41:57 +05302883void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002884{
2885 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302886 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002887
2888 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302889 case DSS_IO_PAD_MODE_RESET:
2890 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002891 gpout1 = 0;
2892 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302893 case DSS_IO_PAD_MODE_RFBI:
2894 gpout0 = 1;
2895 gpout1 = 0;
2896 break;
2897 case DSS_IO_PAD_MODE_BYPASS:
2898 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002899 gpout1 = 1;
2900 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002901 default:
2902 BUG();
2903 return;
2904 }
2905
Archit Taneja569969d2011-08-22 17:41:57 +05302906 l = dispc_read_reg(DISPC_CONTROL);
2907 l = FLD_MOD(l, gpout0, 15, 15);
2908 l = FLD_MOD(l, gpout1, 16, 16);
2909 dispc_write_reg(DISPC_CONTROL, l);
2910}
2911
2912void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2913{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302914 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002915}
2916
Archit Taneja8f366162012-04-16 12:53:44 +05302917static bool _dispc_mgr_size_ok(u16 width, u16 height)
2918{
2919 return width <= dss_feat_get_param_max(FEAT_PARAM_MGR_WIDTH) &&
2920 height <= dss_feat_get_param_max(FEAT_PARAM_MGR_HEIGHT);
2921}
2922
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002923static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2924 int vsw, int vfp, int vbp)
2925{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302926 if (hsw < 1 || hsw > dispc.feat->sw_max ||
2927 hfp < 1 || hfp > dispc.feat->hp_max ||
2928 hbp < 1 || hbp > dispc.feat->hp_max ||
2929 vsw < 1 || vsw > dispc.feat->sw_max ||
2930 vfp < 0 || vfp > dispc.feat->vp_max ||
2931 vbp < 0 || vbp > dispc.feat->vp_max)
2932 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002933 return true;
2934}
2935
Archit Taneja8f366162012-04-16 12:53:44 +05302936bool dispc_mgr_timings_ok(enum omap_channel channel,
Archit Tanejab917fa32012-04-27 01:07:28 +05302937 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002938{
Archit Taneja8f366162012-04-16 12:53:44 +05302939 bool timings_ok;
2940
2941 timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
2942
Archit Tanejadd88b7a2012-06-29 14:41:30 +05302943 if (dss_mgr_is_lcd(channel))
Archit Taneja8f366162012-04-16 12:53:44 +05302944 timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
2945 timings->hfp, timings->hbp,
2946 timings->vsw, timings->vfp,
2947 timings->vbp);
2948
2949 return timings_ok;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002950}
2951
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002952static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
Archit Taneja655e2942012-06-21 10:37:43 +05302953 int hfp, int hbp, int vsw, int vfp, int vbp,
2954 enum omap_dss_signal_level vsync_level,
2955 enum omap_dss_signal_level hsync_level,
2956 enum omap_dss_signal_edge data_pclk_edge,
2957 enum omap_dss_signal_level de_level,
2958 enum omap_dss_signal_edge sync_pclk_edge)
2959
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002960{
Archit Taneja655e2942012-06-21 10:37:43 +05302961 u32 timing_h, timing_v, l;
2962 bool onoff, rf, ipc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002963
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302964 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
2965 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
2966 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
2967 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
2968 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
2969 FLD_VAL(vbp, dispc.feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002970
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002971 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2972 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05302973
2974 switch (data_pclk_edge) {
2975 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2976 ipc = false;
2977 break;
2978 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2979 ipc = true;
2980 break;
2981 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2982 default:
2983 BUG();
2984 }
2985
2986 switch (sync_pclk_edge) {
2987 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2988 onoff = false;
2989 rf = false;
2990 break;
2991 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2992 onoff = true;
2993 rf = false;
2994 break;
2995 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2996 onoff = true;
2997 rf = true;
2998 break;
2999 default:
3000 BUG();
3001 };
3002
3003 l = dispc_read_reg(DISPC_POL_FREQ(channel));
3004 l |= FLD_VAL(onoff, 17, 17);
3005 l |= FLD_VAL(rf, 16, 16);
3006 l |= FLD_VAL(de_level, 15, 15);
3007 l |= FLD_VAL(ipc, 14, 14);
3008 l |= FLD_VAL(hsync_level, 13, 13);
3009 l |= FLD_VAL(vsync_level, 12, 12);
3010 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003011}
3012
3013/* change name to mode? */
Archit Tanejac51d9212012-04-16 12:53:43 +05303014void dispc_mgr_set_timings(enum omap_channel channel,
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003015 struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003016{
3017 unsigned xtot, ytot;
3018 unsigned long ht, vt;
Archit Taneja2aefad42012-05-18 14:36:54 +05303019 struct omap_video_timings t = *timings;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003020
Archit Taneja2aefad42012-05-18 14:36:54 +05303021 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
Archit Tanejac51d9212012-04-16 12:53:43 +05303022
Archit Taneja2aefad42012-05-18 14:36:54 +05303023 if (!dispc_mgr_timings_ok(channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05303024 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003025 return;
3026 }
Archit Tanejac51d9212012-04-16 12:53:43 +05303027
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303028 if (dss_mgr_is_lcd(channel)) {
Archit Taneja2aefad42012-05-18 14:36:54 +05303029 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
Archit Taneja655e2942012-06-21 10:37:43 +05303030 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
3031 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
Archit Tanejac51d9212012-04-16 12:53:43 +05303032
Archit Taneja2aefad42012-05-18 14:36:54 +05303033 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
3034 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
Archit Tanejac51d9212012-04-16 12:53:43 +05303035
3036 ht = (timings->pixel_clock * 1000) / xtot;
3037 vt = (timings->pixel_clock * 1000) / xtot / ytot;
3038
3039 DSSDBG("pck %u\n", timings->pixel_clock);
3040 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Archit Taneja2aefad42012-05-18 14:36:54 +05303041 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
Archit Taneja655e2942012-06-21 10:37:43 +05303042 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3043 t.vsync_level, t.hsync_level, t.data_pclk_edge,
3044 t.de_level, t.sync_pclk_edge);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003045
Archit Tanejac51d9212012-04-16 12:53:43 +05303046 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05303047 } else {
Archit Taneja23c8f882012-06-28 11:15:51 +05303048 if (t.interlace == true)
Archit Taneja2aefad42012-05-18 14:36:54 +05303049 t.y_res /= 2;
Archit Tanejac51d9212012-04-16 12:53:43 +05303050 }
Archit Taneja8f366162012-04-16 12:53:44 +05303051
Archit Taneja2aefad42012-05-18 14:36:54 +05303052 dispc_mgr_set_size(channel, t.x_res, t.y_res);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003053}
3054
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003055static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003056 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003057{
3058 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003059 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003060
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003061 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003062 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003063}
3064
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003065static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00003066 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003067{
3068 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003069 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003070 *lck_div = FLD_GET(l, 23, 16);
3071 *pck_div = FLD_GET(l, 7, 0);
3072}
3073
3074unsigned long dispc_fclk_rate(void)
3075{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303076 struct platform_device *dsidev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003077 unsigned long r = 0;
3078
Taneja, Archit66534e82011-03-08 05:50:34 -06003079 switch (dss_get_dispc_clk_source()) {
Archit Taneja89a35e52011-04-12 13:52:23 +05303080 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003081 r = clk_get_rate(dispc.dss_clk);
Taneja, Archit66534e82011-03-08 05:50:34 -06003082 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05303083 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303084 dsidev = dsi_get_dsidev_from_id(0);
3085 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
Taneja, Archit66534e82011-03-08 05:50:34 -06003086 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05303087 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3088 dsidev = dsi_get_dsidev_from_id(1);
3089 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
3090 break;
Taneja, Archit66534e82011-03-08 05:50:34 -06003091 default:
3092 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003093 return 0;
Taneja, Archit66534e82011-03-08 05:50:34 -06003094 }
3095
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003096 return r;
3097}
3098
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003099unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003100{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303101 struct platform_device *dsidev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003102 int lcd;
3103 unsigned long r;
3104 u32 l;
3105
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003106 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003107
3108 lcd = FLD_GET(l, 23, 16);
3109
Taneja, Architea751592011-03-08 05:50:35 -06003110 switch (dss_get_lcd_clk_source(channel)) {
Archit Taneja89a35e52011-04-12 13:52:23 +05303111 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003112 r = clk_get_rate(dispc.dss_clk);
Taneja, Architea751592011-03-08 05:50:35 -06003113 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05303114 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303115 dsidev = dsi_get_dsidev_from_id(0);
3116 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
Taneja, Architea751592011-03-08 05:50:35 -06003117 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05303118 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3119 dsidev = dsi_get_dsidev_from_id(1);
3120 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
3121 break;
Taneja, Architea751592011-03-08 05:50:35 -06003122 default:
3123 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003124 return 0;
Taneja, Architea751592011-03-08 05:50:35 -06003125 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003126
3127 return r / lcd;
3128}
3129
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003130unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003131{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003132 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003133
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303134 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303135 int pcd;
3136 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003137
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303138 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003139
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303140 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003141
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303142 r = dispc_mgr_lclk_rate(channel);
3143
3144 return r / pcd;
3145 } else {
Archit Taneja3fa03ba2012-04-09 15:06:41 +05303146 enum dss_hdmi_venc_clk_source_select source;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303147
Archit Taneja3fa03ba2012-04-09 15:06:41 +05303148 source = dss_get_hdmi_venc_clk_source();
3149
3150 switch (source) {
3151 case DSS_VENC_TV_CLK:
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303152 return venc_get_pixel_clock();
Archit Taneja3fa03ba2012-04-09 15:06:41 +05303153 case DSS_HDMI_M_PCLK:
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303154 return hdmi_get_pixel_clock();
3155 default:
3156 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003157 return 0;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303158 }
3159 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003160}
3161
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303162unsigned long dispc_core_clk_rate(void)
3163{
3164 int lcd;
3165 unsigned long fclk = dispc_fclk_rate();
3166
3167 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3168 lcd = REG_GET(DISPC_DIVISOR, 23, 16);
3169 else
3170 lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
3171
3172 return fclk / lcd;
3173}
3174
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303175static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3176{
3177 enum omap_channel channel = dispc_ovl_get_channel_out(plane);
3178
3179 return dispc_mgr_pclk_rate(channel);
3180}
3181
3182static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3183{
3184 enum omap_channel channel = dispc_ovl_get_channel_out(plane);
3185
3186 if (dss_mgr_is_lcd(channel))
3187 return dispc_mgr_lclk_rate(channel);
3188 else
3189 return dispc_fclk_rate();
3190
3191}
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303192static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003193{
3194 int lcd, pcd;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303195 enum omap_dss_clk_source lcd_clk_src;
3196
3197 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3198
3199 lcd_clk_src = dss_get_lcd_clk_source(channel);
3200
3201 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3202 dss_get_generic_clk_source_name(lcd_clk_src),
3203 dss_feat_get_clk_source_name(lcd_clk_src));
3204
3205 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3206
3207 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3208 dispc_mgr_lclk_rate(channel), lcd);
3209 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3210 dispc_mgr_pclk_rate(channel), pcd);
3211}
3212
3213void dispc_dump_clocks(struct seq_file *s)
3214{
3215 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003216 u32 l;
Archit Taneja89a35e52011-04-12 13:52:23 +05303217 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003218
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003219 if (dispc_runtime_get())
3220 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003221
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003222 seq_printf(s, "- DISPC -\n");
3223
Archit Taneja067a57e2011-03-02 11:57:25 +05303224 seq_printf(s, "dispc fclk source = %s (%s)\n",
3225 dss_get_generic_clk_source_name(dispc_clk_src),
3226 dss_feat_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003227
3228 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00003229
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003230 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3231 seq_printf(s, "- DISPC-CORE-CLK -\n");
3232 l = dispc_read_reg(DISPC_DIVISOR);
3233 lcd = FLD_GET(l, 23, 16);
3234
3235 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3236 (dispc_fclk_rate()/lcd), lcd);
3237 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003238
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303239 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003240
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303241 if (dss_has_feature(FEAT_MGR_LCD2))
3242 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3243 if (dss_has_feature(FEAT_MGR_LCD3))
3244 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003245
3246 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003247}
3248
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003249#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3250void dispc_dump_irqs(struct seq_file *s)
3251{
3252 unsigned long flags;
3253 struct dispc_irq_stats stats;
3254
3255 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
3256
3257 stats = dispc.irq_stats;
3258 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
3259 dispc.irq_stats.last_reset = jiffies;
3260
3261 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
3262
3263 seq_printf(s, "period %u ms\n",
3264 jiffies_to_msecs(jiffies - stats.last_reset));
3265
3266 seq_printf(s, "irqs %d\n", stats.irq_count);
3267#define PIS(x) \
3268 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
3269
3270 PIS(FRAMEDONE);
3271 PIS(VSYNC);
3272 PIS(EVSYNC_EVEN);
3273 PIS(EVSYNC_ODD);
3274 PIS(ACBIAS_COUNT_STAT);
3275 PIS(PROG_LINE_NUM);
3276 PIS(GFX_FIFO_UNDERFLOW);
3277 PIS(GFX_END_WIN);
3278 PIS(PAL_GAMMA_MASK);
3279 PIS(OCP_ERR);
3280 PIS(VID1_FIFO_UNDERFLOW);
3281 PIS(VID1_END_WIN);
3282 PIS(VID2_FIFO_UNDERFLOW);
3283 PIS(VID2_END_WIN);
Archit Tanejab8c095b2011-09-13 18:20:33 +05303284 if (dss_feat_get_num_ovls() > 3) {
3285 PIS(VID3_FIFO_UNDERFLOW);
3286 PIS(VID3_END_WIN);
3287 }
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003288 PIS(SYNC_LOST);
3289 PIS(SYNC_LOST_DIGIT);
3290 PIS(WAKEUP);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003291 if (dss_has_feature(FEAT_MGR_LCD2)) {
3292 PIS(FRAMEDONE2);
3293 PIS(VSYNC2);
3294 PIS(ACBIAS_COUNT_STAT2);
3295 PIS(SYNC_LOST2);
3296 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303297 if (dss_has_feature(FEAT_MGR_LCD3)) {
3298 PIS(FRAMEDONE3);
3299 PIS(VSYNC3);
3300 PIS(ACBIAS_COUNT_STAT3);
3301 PIS(SYNC_LOST3);
3302 }
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003303#undef PIS
3304}
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003305#endif
3306
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003307static void dispc_dump_regs(struct seq_file *s)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003308{
Archit Taneja4dd2da12011-08-05 19:06:01 +05303309 int i, j;
3310 const char *mgr_names[] = {
3311 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3312 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3313 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303314 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303315 };
3316 const char *ovl_names[] = {
3317 [OMAP_DSS_GFX] = "GFX",
3318 [OMAP_DSS_VIDEO1] = "VID1",
3319 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303320 [OMAP_DSS_VIDEO3] = "VID3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303321 };
3322 const char **p_names;
3323
Archit Taneja9b372c22011-05-06 11:45:49 +05303324#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003325
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003326 if (dispc_runtime_get())
3327 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003328
Archit Taneja5010be82011-08-05 19:06:00 +05303329 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003330 DUMPREG(DISPC_REVISION);
3331 DUMPREG(DISPC_SYSCONFIG);
3332 DUMPREG(DISPC_SYSSTATUS);
3333 DUMPREG(DISPC_IRQSTATUS);
3334 DUMPREG(DISPC_IRQENABLE);
3335 DUMPREG(DISPC_CONTROL);
3336 DUMPREG(DISPC_CONFIG);
3337 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003338 DUMPREG(DISPC_LINE_STATUS);
3339 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05303340 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3341 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003342 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003343 if (dss_has_feature(FEAT_MGR_LCD2)) {
3344 DUMPREG(DISPC_CONTROL2);
3345 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003346 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303347 if (dss_has_feature(FEAT_MGR_LCD3)) {
3348 DUMPREG(DISPC_CONTROL3);
3349 DUMPREG(DISPC_CONFIG3);
3350 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003351
Archit Taneja5010be82011-08-05 19:06:00 +05303352#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003353
Archit Taneja5010be82011-08-05 19:06:00 +05303354#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05303355#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3356 48 - strlen(#r) - strlen(p_names[i]), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303357 dispc_read_reg(DISPC_REG(i, r)))
3358
Archit Taneja4dd2da12011-08-05 19:06:01 +05303359 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303360
Archit Taneja4dd2da12011-08-05 19:06:01 +05303361 /* DISPC channel specific registers */
3362 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3363 DUMPREG(i, DISPC_DEFAULT_COLOR);
3364 DUMPREG(i, DISPC_TRANS_COLOR);
3365 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003366
Archit Taneja4dd2da12011-08-05 19:06:01 +05303367 if (i == OMAP_DSS_CHANNEL_DIGIT)
3368 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303369
Archit Taneja4dd2da12011-08-05 19:06:01 +05303370 DUMPREG(i, DISPC_DEFAULT_COLOR);
3371 DUMPREG(i, DISPC_TRANS_COLOR);
3372 DUMPREG(i, DISPC_TIMING_H);
3373 DUMPREG(i, DISPC_TIMING_V);
3374 DUMPREG(i, DISPC_POL_FREQ);
3375 DUMPREG(i, DISPC_DIVISORo);
3376 DUMPREG(i, DISPC_SIZE_MGR);
Archit Taneja5010be82011-08-05 19:06:00 +05303377
Archit Taneja4dd2da12011-08-05 19:06:01 +05303378 DUMPREG(i, DISPC_DATA_CYCLE1);
3379 DUMPREG(i, DISPC_DATA_CYCLE2);
3380 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003381
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003382 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303383 DUMPREG(i, DISPC_CPR_COEF_R);
3384 DUMPREG(i, DISPC_CPR_COEF_G);
3385 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003386 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003387 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003388
Archit Taneja4dd2da12011-08-05 19:06:01 +05303389 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003390
Archit Taneja4dd2da12011-08-05 19:06:01 +05303391 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3392 DUMPREG(i, DISPC_OVL_BA0);
3393 DUMPREG(i, DISPC_OVL_BA1);
3394 DUMPREG(i, DISPC_OVL_POSITION);
3395 DUMPREG(i, DISPC_OVL_SIZE);
3396 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3397 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3398 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3399 DUMPREG(i, DISPC_OVL_ROW_INC);
3400 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3401 if (dss_has_feature(FEAT_PRELOAD))
3402 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003403
Archit Taneja4dd2da12011-08-05 19:06:01 +05303404 if (i == OMAP_DSS_GFX) {
3405 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3406 DUMPREG(i, DISPC_OVL_TABLE_BA);
3407 continue;
3408 }
3409
3410 DUMPREG(i, DISPC_OVL_FIR);
3411 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3412 DUMPREG(i, DISPC_OVL_ACCU0);
3413 DUMPREG(i, DISPC_OVL_ACCU1);
3414 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3415 DUMPREG(i, DISPC_OVL_BA0_UV);
3416 DUMPREG(i, DISPC_OVL_BA1_UV);
3417 DUMPREG(i, DISPC_OVL_FIR2);
3418 DUMPREG(i, DISPC_OVL_ACCU2_0);
3419 DUMPREG(i, DISPC_OVL_ACCU2_1);
3420 }
3421 if (dss_has_feature(FEAT_ATTR2))
3422 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3423 if (dss_has_feature(FEAT_PRELOAD))
3424 DUMPREG(i, DISPC_OVL_PRELOAD);
Archit Taneja5010be82011-08-05 19:06:00 +05303425 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003426
Archit Taneja5010be82011-08-05 19:06:00 +05303427#undef DISPC_REG
3428#undef DUMPREG
3429
3430#define DISPC_REG(plane, name, i) name(plane, i)
3431#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303432 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3433 46 - strlen(#name) - strlen(p_names[plane]), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303434 dispc_read_reg(DISPC_REG(plane, name, i)))
3435
Archit Taneja4dd2da12011-08-05 19:06:01 +05303436 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303437
Archit Taneja4dd2da12011-08-05 19:06:01 +05303438 /* start from OMAP_DSS_VIDEO1 */
3439 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3440 for (j = 0; j < 8; j++)
3441 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303442
Archit Taneja4dd2da12011-08-05 19:06:01 +05303443 for (j = 0; j < 8; j++)
3444 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303445
Archit Taneja4dd2da12011-08-05 19:06:01 +05303446 for (j = 0; j < 5; j++)
3447 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003448
Archit Taneja4dd2da12011-08-05 19:06:01 +05303449 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3450 for (j = 0; j < 8; j++)
3451 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3452 }
Amber Jainab5ca072011-05-19 19:47:53 +05303453
Archit Taneja4dd2da12011-08-05 19:06:01 +05303454 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3455 for (j = 0; j < 8; j++)
3456 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303457
Archit Taneja4dd2da12011-08-05 19:06:01 +05303458 for (j = 0; j < 8; j++)
3459 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303460
Archit Taneja4dd2da12011-08-05 19:06:01 +05303461 for (j = 0; j < 8; j++)
3462 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3463 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003464 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003465
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003466 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05303467
3468#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003469#undef DUMPREG
3470}
3471
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003472/* with fck as input clock rate, find dispc dividers that produce req_pck */
Archit Taneja6d523e72012-06-21 09:33:55 +05303473void dispc_find_clk_divs(unsigned long req_pck, unsigned long fck,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003474 struct dispc_clock_info *cinfo)
3475{
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003476 u16 pcd_min, pcd_max;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003477 unsigned long best_pck;
3478 u16 best_ld, cur_ld;
3479 u16 best_pd, cur_pd;
3480
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003481 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3482 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3483
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003484 best_pck = 0;
3485 best_ld = 0;
3486 best_pd = 0;
3487
3488 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
3489 unsigned long lck = fck / cur_ld;
3490
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003491 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003492 unsigned long pck = lck / cur_pd;
3493 long old_delta = abs(best_pck - req_pck);
3494 long new_delta = abs(pck - req_pck);
3495
3496 if (best_pck == 0 || new_delta < old_delta) {
3497 best_pck = pck;
3498 best_ld = cur_ld;
3499 best_pd = cur_pd;
3500
3501 if (pck == req_pck)
3502 goto found;
3503 }
3504
3505 if (pck < req_pck)
3506 break;
3507 }
3508
3509 if (lck / pcd_min < req_pck)
3510 break;
3511 }
3512
3513found:
3514 cinfo->lck_div = best_ld;
3515 cinfo->pck_div = best_pd;
3516 cinfo->lck = fck / cinfo->lck_div;
3517 cinfo->pck = cinfo->lck / cinfo->pck_div;
3518}
3519
3520/* calculate clock rates using dividers in cinfo */
3521int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3522 struct dispc_clock_info *cinfo)
3523{
3524 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3525 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003526 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003527 return -EINVAL;
3528
3529 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3530 cinfo->pck = cinfo->lck / cinfo->pck_div;
3531
3532 return 0;
3533}
3534
Archit Tanejaf0d08f82012-06-29 14:00:54 +05303535void dispc_mgr_set_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003536 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003537{
3538 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3539 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3540
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003541 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003542}
3543
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003544int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003545 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003546{
3547 unsigned long fck;
3548
3549 fck = dispc_fclk_rate();
3550
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003551 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3552 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003553
3554 cinfo->lck = fck / cinfo->lck_div;
3555 cinfo->pck = cinfo->lck / cinfo->pck_div;
3556
3557 return 0;
3558}
3559
3560/* dispc.irq_lock has to be locked by the caller */
3561static void _omap_dispc_set_irqs(void)
3562{
3563 u32 mask;
3564 u32 old_mask;
3565 int i;
3566 struct omap_dispc_isr_data *isr_data;
3567
3568 mask = dispc.irq_error_mask;
3569
3570 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3571 isr_data = &dispc.registered_isr[i];
3572
3573 if (isr_data->isr == NULL)
3574 continue;
3575
3576 mask |= isr_data->mask;
3577 }
3578
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003579 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3580 /* clear the irqstatus for newly enabled irqs */
3581 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
3582
3583 dispc_write_reg(DISPC_IRQENABLE, mask);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003584}
3585
3586int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3587{
3588 int i;
3589 int ret;
3590 unsigned long flags;
3591 struct omap_dispc_isr_data *isr_data;
3592
3593 if (isr == NULL)
3594 return -EINVAL;
3595
3596 spin_lock_irqsave(&dispc.irq_lock, flags);
3597
3598 /* check for duplicate entry */
3599 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3600 isr_data = &dispc.registered_isr[i];
3601 if (isr_data->isr == isr && isr_data->arg == arg &&
3602 isr_data->mask == mask) {
3603 ret = -EINVAL;
3604 goto err;
3605 }
3606 }
3607
3608 isr_data = NULL;
3609 ret = -EBUSY;
3610
3611 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3612 isr_data = &dispc.registered_isr[i];
3613
3614 if (isr_data->isr != NULL)
3615 continue;
3616
3617 isr_data->isr = isr;
3618 isr_data->arg = arg;
3619 isr_data->mask = mask;
3620 ret = 0;
3621
3622 break;
3623 }
3624
Tomi Valkeinenb9cb0982011-03-04 18:19:54 +02003625 if (ret)
3626 goto err;
3627
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003628 _omap_dispc_set_irqs();
3629
3630 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3631
3632 return 0;
3633err:
3634 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3635
3636 return ret;
3637}
3638EXPORT_SYMBOL(omap_dispc_register_isr);
3639
3640int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3641{
3642 int i;
3643 unsigned long flags;
3644 int ret = -EINVAL;
3645 struct omap_dispc_isr_data *isr_data;
3646
3647 spin_lock_irqsave(&dispc.irq_lock, flags);
3648
3649 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3650 isr_data = &dispc.registered_isr[i];
3651 if (isr_data->isr != isr || isr_data->arg != arg ||
3652 isr_data->mask != mask)
3653 continue;
3654
3655 /* found the correct isr */
3656
3657 isr_data->isr = NULL;
3658 isr_data->arg = NULL;
3659 isr_data->mask = 0;
3660
3661 ret = 0;
3662 break;
3663 }
3664
3665 if (ret == 0)
3666 _omap_dispc_set_irqs();
3667
3668 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3669
3670 return ret;
3671}
3672EXPORT_SYMBOL(omap_dispc_unregister_isr);
3673
3674#ifdef DEBUG
3675static void print_irq_status(u32 status)
3676{
3677 if ((status & dispc.irq_error_mask) == 0)
3678 return;
3679
3680 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
3681
3682#define PIS(x) \
3683 if (status & DISPC_IRQ_##x) \
3684 printk(#x " ");
3685 PIS(GFX_FIFO_UNDERFLOW);
3686 PIS(OCP_ERR);
3687 PIS(VID1_FIFO_UNDERFLOW);
3688 PIS(VID2_FIFO_UNDERFLOW);
Archit Tanejab8c095b2011-09-13 18:20:33 +05303689 if (dss_feat_get_num_ovls() > 3)
3690 PIS(VID3_FIFO_UNDERFLOW);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003691 PIS(SYNC_LOST);
3692 PIS(SYNC_LOST_DIGIT);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003693 if (dss_has_feature(FEAT_MGR_LCD2))
3694 PIS(SYNC_LOST2);
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303695 if (dss_has_feature(FEAT_MGR_LCD3))
3696 PIS(SYNC_LOST3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003697#undef PIS
3698
3699 printk("\n");
3700}
3701#endif
3702
3703/* Called from dss.c. Note that we don't touch clocks here,
3704 * but we presume they are on because we got an IRQ. However,
3705 * an irq handler may turn the clocks off, so we may not have
3706 * clock later in the function. */
archit tanejaaffe3602011-02-23 08:41:03 +00003707static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003708{
3709 int i;
archit tanejaaffe3602011-02-23 08:41:03 +00003710 u32 irqstatus, irqenable;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003711 u32 handledirqs = 0;
3712 u32 unhandled_errors;
3713 struct omap_dispc_isr_data *isr_data;
3714 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
3715
3716 spin_lock(&dispc.irq_lock);
3717
3718 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
archit tanejaaffe3602011-02-23 08:41:03 +00003719 irqenable = dispc_read_reg(DISPC_IRQENABLE);
3720
3721 /* IRQ is not for us */
3722 if (!(irqstatus & irqenable)) {
3723 spin_unlock(&dispc.irq_lock);
3724 return IRQ_NONE;
3725 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003726
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003727#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3728 spin_lock(&dispc.irq_stats_lock);
3729 dispc.irq_stats.irq_count++;
3730 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
3731 spin_unlock(&dispc.irq_stats_lock);
3732#endif
3733
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003734#ifdef DEBUG
3735 if (dss_debug)
3736 print_irq_status(irqstatus);
3737#endif
3738 /* Ack the interrupt. Do it here before clocks are possibly turned
3739 * off */
3740 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
3741 /* flush posted write */
3742 dispc_read_reg(DISPC_IRQSTATUS);
3743
3744 /* make a copy and unlock, so that isrs can unregister
3745 * themselves */
3746 memcpy(registered_isr, dispc.registered_isr,
3747 sizeof(registered_isr));
3748
3749 spin_unlock(&dispc.irq_lock);
3750
3751 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3752 isr_data = &registered_isr[i];
3753
3754 if (!isr_data->isr)
3755 continue;
3756
3757 if (isr_data->mask & irqstatus) {
3758 isr_data->isr(isr_data->arg, irqstatus);
3759 handledirqs |= isr_data->mask;
3760 }
3761 }
3762
3763 spin_lock(&dispc.irq_lock);
3764
3765 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3766
3767 if (unhandled_errors) {
3768 dispc.error_irqs |= unhandled_errors;
3769
3770 dispc.irq_error_mask &= ~unhandled_errors;
3771 _omap_dispc_set_irqs();
3772
3773 schedule_work(&dispc.error_work);
3774 }
3775
3776 spin_unlock(&dispc.irq_lock);
archit tanejaaffe3602011-02-23 08:41:03 +00003777
3778 return IRQ_HANDLED;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003779}
3780
3781static void dispc_error_worker(struct work_struct *work)
3782{
3783 int i;
3784 u32 errors;
3785 unsigned long flags;
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003786 static const unsigned fifo_underflow_bits[] = {
3787 DISPC_IRQ_GFX_FIFO_UNDERFLOW,
3788 DISPC_IRQ_VID1_FIFO_UNDERFLOW,
3789 DISPC_IRQ_VID2_FIFO_UNDERFLOW,
Archit Tanejab8c095b2011-09-13 18:20:33 +05303790 DISPC_IRQ_VID3_FIFO_UNDERFLOW,
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003791 };
3792
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003793 spin_lock_irqsave(&dispc.irq_lock, flags);
3794 errors = dispc.error_irqs;
3795 dispc.error_irqs = 0;
3796 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3797
Dima Zavin13eae1f2011-06-27 10:31:05 -07003798 dispc_runtime_get();
3799
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003800 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3801 struct omap_overlay *ovl;
3802 unsigned bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003803
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003804 ovl = omap_dss_get_overlay(i);
3805 bit = fifo_underflow_bits[i];
3806
3807 if (bit & errors) {
3808 DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
3809 ovl->name);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03003810 dispc_ovl_enable(ovl->id, false);
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003811 dispc_mgr_go(ovl->manager->id);
Jassi Brard7ad7182012-07-24 19:33:55 +05303812 msleep(50);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003813 }
3814 }
3815
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003816 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3817 struct omap_overlay_manager *mgr;
3818 unsigned bit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003819
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003820 mgr = omap_dss_get_overlay_manager(i);
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05303821 bit = mgr_desc[i].sync_lost_irq;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003822
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003823 if (bit & errors) {
Archit Taneja794bc4e2012-09-07 17:44:51 +05303824 struct omap_dss_device *dssdev = mgr->get_device(mgr);
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003825 bool enable;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003826
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003827 DSSERR("SYNC_LOST on channel %s, restarting the output "
3828 "with video overlays disabled\n",
3829 mgr->name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003830
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003831 enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
3832 dssdev->driver->disable(dssdev);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003833
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003834 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3835 struct omap_overlay *ovl;
3836 ovl = omap_dss_get_overlay(i);
3837
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03003838 if (ovl->id != OMAP_DSS_GFX &&
3839 ovl->manager == mgr)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03003840 dispc_ovl_enable(ovl->id, false);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003841 }
3842
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003843 dispc_mgr_go(mgr->id);
Jassi Brard7ad7182012-07-24 19:33:55 +05303844 msleep(50);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003845
Sumit Semwal2a205f32010-12-02 11:27:12 +00003846 if (enable)
3847 dssdev->driver->enable(dssdev);
3848 }
3849 }
3850
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003851 if (errors & DISPC_IRQ_OCP_ERR) {
3852 DSSERR("OCP_ERR\n");
3853 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3854 struct omap_overlay_manager *mgr;
Archit Taneja794bc4e2012-09-07 17:44:51 +05303855 struct omap_dss_device *dssdev;
3856
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003857 mgr = omap_dss_get_overlay_manager(i);
Archit Taneja794bc4e2012-09-07 17:44:51 +05303858 dssdev = mgr->get_device(mgr);
3859
3860 if (dssdev && dssdev->driver)
3861 dssdev->driver->disable(dssdev);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003862 }
3863 }
3864
3865 spin_lock_irqsave(&dispc.irq_lock, flags);
3866 dispc.irq_error_mask |= errors;
3867 _omap_dispc_set_irqs();
3868 spin_unlock_irqrestore(&dispc.irq_lock, flags);
Dima Zavin13eae1f2011-06-27 10:31:05 -07003869
3870 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003871}
3872
3873int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3874{
3875 void dispc_irq_wait_handler(void *data, u32 mask)
3876 {
3877 complete((struct completion *)data);
3878 }
3879
3880 int r;
3881 DECLARE_COMPLETION_ONSTACK(completion);
3882
3883 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3884 irqmask);
3885
3886 if (r)
3887 return r;
3888
3889 timeout = wait_for_completion_timeout(&completion, timeout);
3890
3891 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3892
3893 if (timeout == 0)
3894 return -ETIMEDOUT;
3895
3896 if (timeout == -ERESTARTSYS)
3897 return -ERESTARTSYS;
3898
3899 return 0;
3900}
3901
3902int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3903 unsigned long timeout)
3904{
3905 void dispc_irq_wait_handler(void *data, u32 mask)
3906 {
3907 complete((struct completion *)data);
3908 }
3909
3910 int r;
3911 DECLARE_COMPLETION_ONSTACK(completion);
3912
3913 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3914 irqmask);
3915
3916 if (r)
3917 return r;
3918
3919 timeout = wait_for_completion_interruptible_timeout(&completion,
3920 timeout);
3921
3922 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3923
3924 if (timeout == 0)
3925 return -ETIMEDOUT;
3926
3927 if (timeout == -ERESTARTSYS)
3928 return -ERESTARTSYS;
3929
3930 return 0;
3931}
3932
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003933static void _omap_dispc_initialize_irq(void)
3934{
3935 unsigned long flags;
3936
3937 spin_lock_irqsave(&dispc.irq_lock, flags);
3938
3939 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3940
3941 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
Sumit Semwal2a205f32010-12-02 11:27:12 +00003942 if (dss_has_feature(FEAT_MGR_LCD2))
3943 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05303944 if (dss_has_feature(FEAT_MGR_LCD3))
3945 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST3;
Archit Tanejab8c095b2011-09-13 18:20:33 +05303946 if (dss_feat_get_num_ovls() > 3)
3947 dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003948
3949 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3950 * so clear it */
3951 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3952
3953 _omap_dispc_set_irqs();
3954
3955 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3956}
3957
3958void dispc_enable_sidle(void)
3959{
3960 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3961}
3962
3963void dispc_disable_sidle(void)
3964{
3965 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3966}
3967
3968static void _omap_dispc_initial_config(void)
3969{
3970 u32 l;
3971
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003972 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3973 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3974 l = dispc_read_reg(DISPC_DIVISOR);
3975 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3976 l = FLD_MOD(l, 1, 0, 0);
3977 l = FLD_MOD(l, 1, 23, 16);
3978 dispc_write_reg(DISPC_DIVISOR, l);
3979 }
3980
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003981 /* FUNCGATED */
Archit Taneja6ced40b2010-12-02 11:27:13 +00003982 if (dss_has_feature(FEAT_FUNCGATED))
3983 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003984
Archit Taneja6e5264b2012-09-11 12:04:47 +05303985 dispc_setup_color_conv_coef();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003986
3987 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3988
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003989 dispc_init_fifos();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003990
3991 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05303992
3993 dispc_ovl_enable_zorder_planes();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003994}
3995
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303996static const struct dispc_features omap24xx_dispc_feats __initconst = {
3997 .sw_start = 5,
3998 .fp_start = 15,
3999 .bp_start = 27,
4000 .sw_max = 64,
4001 .vp_max = 255,
4002 .hp_max = 256,
4003 .calc_scaling = dispc_ovl_calc_scaling_24xx,
4004 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004005 .num_fifos = 3,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304006};
4007
4008static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
4009 .sw_start = 5,
4010 .fp_start = 15,
4011 .bp_start = 27,
4012 .sw_max = 64,
4013 .vp_max = 255,
4014 .hp_max = 256,
4015 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4016 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004017 .num_fifos = 3,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304018};
4019
4020static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
4021 .sw_start = 7,
4022 .fp_start = 19,
4023 .bp_start = 31,
4024 .sw_max = 256,
4025 .vp_max = 4095,
4026 .hp_max = 4096,
4027 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4028 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004029 .num_fifos = 3,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304030};
4031
4032static const struct dispc_features omap44xx_dispc_feats __initconst = {
4033 .sw_start = 7,
4034 .fp_start = 19,
4035 .bp_start = 31,
4036 .sw_max = 256,
4037 .vp_max = 4095,
4038 .hp_max = 4096,
4039 .calc_scaling = dispc_ovl_calc_scaling_44xx,
4040 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004041 .num_fifos = 5,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03004042 .gfx_fifo_workaround = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304043};
4044
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004045static int __init dispc_init_features(struct platform_device *pdev)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304046{
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004047 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304048 const struct dispc_features *src;
4049 struct dispc_features *dst;
4050
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004051 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304052 if (!dst) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004053 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304054 return -ENOMEM;
4055 }
4056
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004057 switch (pdata->version) {
4058 case OMAPDSS_VER_OMAP24xx:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304059 src = &omap24xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004060 break;
4061
4062 case OMAPDSS_VER_OMAP34xx_ES1:
4063 src = &omap34xx_rev1_0_dispc_feats;
4064 break;
4065
4066 case OMAPDSS_VER_OMAP34xx_ES3:
4067 case OMAPDSS_VER_OMAP3630:
4068 case OMAPDSS_VER_AM35xx:
4069 src = &omap34xx_rev3_0_dispc_feats;
4070 break;
4071
4072 case OMAPDSS_VER_OMAP4430_ES1:
4073 case OMAPDSS_VER_OMAP4430_ES2:
4074 case OMAPDSS_VER_OMAP4:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304075 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004076 break;
4077
4078 case OMAPDSS_VER_OMAP5:
Archit Taneja23362832012-04-08 16:47:01 +05304079 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004080 break;
4081
4082 default:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304083 return -ENODEV;
4084 }
4085
4086 memcpy(dst, src, sizeof(*dst));
4087 dispc.feat = dst;
4088
4089 return 0;
4090}
4091
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004092/* DISPC HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004093static int __init omap_dispchw_probe(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004094{
4095 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00004096 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004097 struct resource *dispc_mem;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004098 struct clk *clk;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004099
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004100 dispc.pdev = pdev;
4101
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004102 r = dispc_init_features(dispc.pdev);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304103 if (r)
4104 return r;
4105
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004106 spin_lock_init(&dispc.irq_lock);
4107
4108#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
4109 spin_lock_init(&dispc.irq_stats_lock);
4110 dispc.irq_stats.last_reset = jiffies;
4111#endif
4112
4113 INIT_WORK(&dispc.error_work, dispc_error_worker);
4114
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004115 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
4116 if (!dispc_mem) {
4117 DSSERR("can't get IORESOURCE_MEM DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004118 return -EINVAL;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004119 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004120
Julia Lawall6e2a14d2012-01-24 14:00:45 +01004121 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
4122 resource_size(dispc_mem));
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004123 if (!dispc.base) {
4124 DSSERR("can't ioremap DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004125 return -ENOMEM;
archit tanejaaffe3602011-02-23 08:41:03 +00004126 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004127
archit tanejaaffe3602011-02-23 08:41:03 +00004128 dispc.irq = platform_get_irq(dispc.pdev, 0);
4129 if (dispc.irq < 0) {
4130 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004131 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00004132 }
4133
Julia Lawall6e2a14d2012-01-24 14:00:45 +01004134 r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
4135 IRQF_SHARED, "OMAP DISPC", dispc.pdev);
archit tanejaaffe3602011-02-23 08:41:03 +00004136 if (r < 0) {
4137 DSSERR("request_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004138 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004139 }
4140
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004141 clk = clk_get(&pdev->dev, "fck");
4142 if (IS_ERR(clk)) {
4143 DSSERR("can't get fck\n");
4144 r = PTR_ERR(clk);
4145 return r;
4146 }
4147
4148 dispc.dss_clk = clk;
4149
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004150 pm_runtime_enable(&pdev->dev);
4151
4152 r = dispc_runtime_get();
4153 if (r)
4154 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004155
4156 _omap_dispc_initial_config();
4157
4158 _omap_dispc_initialize_irq();
4159
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004160 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00004161 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004162 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4163
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004164 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004165
Tomi Valkeinene40402c2012-03-02 18:01:07 +02004166 dss_debugfs_create_file("dispc", dispc_dump_regs);
4167
4168#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
4169 dss_debugfs_create_file("dispc_irq", dispc_dump_irqs);
4170#endif
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004171 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004172
4173err_runtime_get:
4174 pm_runtime_disable(&pdev->dev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004175 clk_put(dispc.dss_clk);
archit tanejaaffe3602011-02-23 08:41:03 +00004176 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004177}
4178
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004179static int __exit omap_dispchw_remove(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004180{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004181 pm_runtime_disable(&pdev->dev);
4182
4183 clk_put(dispc.dss_clk);
4184
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004185 return 0;
4186}
4187
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004188static int dispc_runtime_suspend(struct device *dev)
4189{
4190 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004191
4192 return 0;
4193}
4194
4195static int dispc_runtime_resume(struct device *dev)
4196{
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +03004197 dispc_restore_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004198
4199 return 0;
4200}
4201
4202static const struct dev_pm_ops dispc_pm_ops = {
4203 .runtime_suspend = dispc_runtime_suspend,
4204 .runtime_resume = dispc_runtime_resume,
4205};
4206
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004207static struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004208 .remove = __exit_p(omap_dispchw_remove),
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004209 .driver = {
4210 .name = "omapdss_dispc",
4211 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004212 .pm = &dispc_pm_ops,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004213 },
4214};
4215
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004216int __init dispc_init_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004217{
Tomi Valkeinen11436e12012-03-07 12:53:18 +02004218 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004219}
4220
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004221void __exit dispc_uninit_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004222{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02004223 platform_driver_unregister(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004224}