blob: 67548839ff51176b6fa3cfdf82debd5851e08902 [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>
Tomi Valkeinen24e62892011-05-23 11:51:18 +030036#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030037#include <linux/pm_runtime.h>
Tomi Valkeinen33366d02012-09-28 13:54:35 +030038#include <linux/sizes.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020039
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030040#include <video/omapdss.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020041
42#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053043#include "dss_features.h"
Archit Taneja9b372c22011-05-06 11:45:49 +053044#include "dispc.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020045
46/* DISPC */
Sumit Semwal8613b002010-12-02 11:27:09 +000047#define DISPC_SZ_REGS SZ_4K
Tomi Valkeinen80c39712009-11-12 11:41:42 +020048
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030049enum omap_burst_size {
50 BURST_SIZE_X2 = 0,
51 BURST_SIZE_X4 = 1,
52 BURST_SIZE_X8 = 2,
53};
54
Tomi Valkeinen80c39712009-11-12 11:41:42 +020055#define REG_GET(idx, start, end) \
56 FLD_GET(dispc_read_reg(idx), start, end)
57
58#define REG_FLD_MOD(idx, val, start, end) \
59 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
60
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053061struct dispc_features {
62 u8 sw_start;
63 u8 fp_start;
64 u8 bp_start;
65 u16 sw_max;
66 u16 vp_max;
67 u16 hp_max;
Archit Taneja33b89922012-11-14 13:50:15 +053068 u8 mgr_width_start;
69 u8 mgr_height_start;
70 u16 mgr_width_max;
71 u16 mgr_height_max;
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +030072 int (*calc_scaling) (unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053073 const struct omap_video_timings *mgr_timings,
74 u16 width, u16 height, u16 out_width, u16 out_height,
75 enum omap_color_mode color_mode, bool *five_taps,
76 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +053077 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
Tomi Valkeinen8702ee52012-10-19 15:36:11 +030078 unsigned long (*calc_core_clk) (unsigned long pclk,
Archit Taneja8ba85302012-09-26 17:00:37 +053079 u16 width, u16 height, u16 out_width, u16 out_height,
80 bool mem_to_mem);
Tomi Valkeinen42a69612012-08-22 16:56:57 +030081 u8 num_fifos;
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +030082
83 /* swap GFX & WB fifos */
84 bool gfx_fifo_workaround:1;
Tomi Valkeinencffa9472012-11-08 10:01:33 +020085
86 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
87 bool no_framedone_tv:1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053088};
89
Tomi Valkeinen42a69612012-08-22 16:56:57 +030090#define DISPC_MAX_NR_FIFOS 5
91
Tomi Valkeinen80c39712009-11-12 11:41:42 +020092static struct {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +000093 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +020094 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030095
96 int ctx_loss_cnt;
97
archit tanejaaffe3602011-02-23 08:41:03 +000098 int irq;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030099 struct clk *dss_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200100
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300101 u32 fifo_size[DISPC_MAX_NR_FIFOS];
102 /* maps which plane is using a fifo. fifo-id -> plane-id */
103 int fifo_assignment[DISPC_MAX_NR_FIFOS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200104
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300105 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200106 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200107
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530108 const struct dispc_features *feat;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200109} dispc;
110
Amber Jain0d66cbb2011-05-19 19:47:54 +0530111enum omap_color_component {
112 /* used for all color formats for OMAP3 and earlier
113 * and for RGB and Y color component on OMAP4
114 */
115 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
116 /* used for UV component for
117 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
118 * color formats on OMAP4
119 */
120 DISPC_COLOR_COMPONENT_UV = 1 << 1,
121};
122
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530123enum mgr_reg_fields {
124 DISPC_MGR_FLD_ENABLE,
125 DISPC_MGR_FLD_STNTFT,
126 DISPC_MGR_FLD_GO,
127 DISPC_MGR_FLD_TFTDATALINES,
128 DISPC_MGR_FLD_STALLMODE,
129 DISPC_MGR_FLD_TCKENABLE,
130 DISPC_MGR_FLD_TCKSELECTION,
131 DISPC_MGR_FLD_CPR,
132 DISPC_MGR_FLD_FIFOHANDCHECK,
133 /* used to maintain a count of the above fields */
134 DISPC_MGR_FLD_NUM,
135};
136
137static const struct {
138 const char *name;
139 u32 vsync_irq;
140 u32 framedone_irq;
141 u32 sync_lost_irq;
142 struct reg_field reg_desc[DISPC_MGR_FLD_NUM];
143} mgr_desc[] = {
144 [OMAP_DSS_CHANNEL_LCD] = {
145 .name = "LCD",
146 .vsync_irq = DISPC_IRQ_VSYNC,
147 .framedone_irq = DISPC_IRQ_FRAMEDONE,
148 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
149 .reg_desc = {
150 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
151 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
152 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
153 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
154 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
155 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
156 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
157 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
158 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
159 },
160 },
161 [OMAP_DSS_CHANNEL_DIGIT] = {
162 .name = "DIGIT",
163 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200164 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530165 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
166 .reg_desc = {
167 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
168 [DISPC_MGR_FLD_STNTFT] = { },
169 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
170 [DISPC_MGR_FLD_TFTDATALINES] = { },
171 [DISPC_MGR_FLD_STALLMODE] = { },
172 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
173 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
174 [DISPC_MGR_FLD_CPR] = { },
175 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
176 },
177 },
178 [OMAP_DSS_CHANNEL_LCD2] = {
179 .name = "LCD2",
180 .vsync_irq = DISPC_IRQ_VSYNC2,
181 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
182 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
183 .reg_desc = {
184 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
185 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
186 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
187 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
188 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
189 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
190 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
191 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
192 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
193 },
194 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530195 [OMAP_DSS_CHANNEL_LCD3] = {
196 .name = "LCD3",
197 .vsync_irq = DISPC_IRQ_VSYNC3,
198 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
199 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
200 .reg_desc = {
201 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
202 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
203 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
204 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
205 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
206 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
207 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
208 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
209 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
210 },
211 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530212};
213
Archit Taneja6e5264b2012-09-11 12:04:47 +0530214struct color_conv_coef {
215 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
216 int full_range;
217};
218
Archit Taneja3e8a6ff2012-09-26 16:58:52 +0530219static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
220static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200221
Archit Taneja55978cc2011-05-06 11:45:51 +0530222static inline void dispc_write_reg(const u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200223{
Archit Taneja55978cc2011-05-06 11:45:51 +0530224 __raw_writel(val, dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200225}
226
Archit Taneja55978cc2011-05-06 11:45:51 +0530227static inline u32 dispc_read_reg(const u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200228{
Archit Taneja55978cc2011-05-06 11:45:51 +0530229 return __raw_readl(dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200230}
231
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530232static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
233{
234 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
235 return REG_GET(rfld.reg, rfld.high, rfld.low);
236}
237
238static void mgr_fld_write(enum omap_channel channel,
239 enum mgr_reg_fields regfld, int val) {
240 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
241 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
242}
243
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200244#define SR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530245 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200246#define RR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530247 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200248
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300249static void dispc_save_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200250{
Archit Tanejac6104b82011-08-05 19:06:02 +0530251 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200252
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300253 DSSDBG("dispc_save_context\n");
254
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200255 SR(IRQENABLE);
256 SR(CONTROL);
257 SR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200258 SR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530259 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
260 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300261 SR(GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000262 if (dss_has_feature(FEAT_MGR_LCD2)) {
263 SR(CONTROL2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000264 SR(CONFIG2);
265 }
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530266 if (dss_has_feature(FEAT_MGR_LCD3)) {
267 SR(CONTROL3);
268 SR(CONFIG3);
269 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200270
Archit Tanejac6104b82011-08-05 19:06:02 +0530271 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
272 SR(DEFAULT_COLOR(i));
273 SR(TRANS_COLOR(i));
274 SR(SIZE_MGR(i));
275 if (i == OMAP_DSS_CHANNEL_DIGIT)
276 continue;
277 SR(TIMING_H(i));
278 SR(TIMING_V(i));
279 SR(POL_FREQ(i));
280 SR(DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200281
Archit Tanejac6104b82011-08-05 19:06:02 +0530282 SR(DATA_CYCLE1(i));
283 SR(DATA_CYCLE2(i));
284 SR(DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200285
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300286 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530287 SR(CPR_COEF_R(i));
288 SR(CPR_COEF_G(i));
289 SR(CPR_COEF_B(i));
290 }
291 }
292
293 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
294 SR(OVL_BA0(i));
295 SR(OVL_BA1(i));
296 SR(OVL_POSITION(i));
297 SR(OVL_SIZE(i));
298 SR(OVL_ATTRIBUTES(i));
299 SR(OVL_FIFO_THRESHOLD(i));
300 SR(OVL_ROW_INC(i));
301 SR(OVL_PIXEL_INC(i));
302 if (dss_has_feature(FEAT_PRELOAD))
303 SR(OVL_PRELOAD(i));
304 if (i == OMAP_DSS_GFX) {
305 SR(OVL_WINDOW_SKIP(i));
306 SR(OVL_TABLE_BA(i));
307 continue;
308 }
309 SR(OVL_FIR(i));
310 SR(OVL_PICTURE_SIZE(i));
311 SR(OVL_ACCU0(i));
312 SR(OVL_ACCU1(i));
313
314 for (j = 0; j < 8; j++)
315 SR(OVL_FIR_COEF_H(i, j));
316
317 for (j = 0; j < 8; j++)
318 SR(OVL_FIR_COEF_HV(i, j));
319
320 for (j = 0; j < 5; j++)
321 SR(OVL_CONV_COEF(i, j));
322
323 if (dss_has_feature(FEAT_FIR_COEF_V)) {
324 for (j = 0; j < 8; j++)
325 SR(OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300326 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000327
Archit Tanejac6104b82011-08-05 19:06:02 +0530328 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
329 SR(OVL_BA0_UV(i));
330 SR(OVL_BA1_UV(i));
331 SR(OVL_FIR2(i));
332 SR(OVL_ACCU2_0(i));
333 SR(OVL_ACCU2_1(i));
334
335 for (j = 0; j < 8; j++)
336 SR(OVL_FIR_COEF_H2(i, j));
337
338 for (j = 0; j < 8; j++)
339 SR(OVL_FIR_COEF_HV2(i, j));
340
341 for (j = 0; j < 8; j++)
342 SR(OVL_FIR_COEF_V2(i, j));
343 }
344 if (dss_has_feature(FEAT_ATTR2))
345 SR(OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000346 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200347
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600348 if (dss_has_feature(FEAT_CORE_CLK_DIV))
349 SR(DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300350
Archit Tanejabdb736a2012-11-28 17:01:39 +0530351 dispc.ctx_loss_cnt = dss_get_ctx_loss_count();
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300352 dispc.ctx_valid = true;
353
354 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200355}
356
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300357static void dispc_restore_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200358{
Archit Tanejac6104b82011-08-05 19:06:02 +0530359 int i, j, ctx;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300360
361 DSSDBG("dispc_restore_context\n");
362
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300363 if (!dispc.ctx_valid)
364 return;
365
Archit Tanejabdb736a2012-11-28 17:01:39 +0530366 ctx = dss_get_ctx_loss_count();
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300367
368 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
369 return;
370
371 DSSDBG("ctx_loss_count: saved %d, current %d\n",
372 dispc.ctx_loss_cnt, ctx);
373
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200374 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200375 /*RR(CONTROL);*/
376 RR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200377 RR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530378 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
379 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300380 RR(GLOBAL_ALPHA);
Archit Tanejac6104b82011-08-05 19:06:02 +0530381 if (dss_has_feature(FEAT_MGR_LCD2))
Sumit Semwal2a205f32010-12-02 11:27:12 +0000382 RR(CONFIG2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530383 if (dss_has_feature(FEAT_MGR_LCD3))
384 RR(CONFIG3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200385
Archit Tanejac6104b82011-08-05 19:06:02 +0530386 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
387 RR(DEFAULT_COLOR(i));
388 RR(TRANS_COLOR(i));
389 RR(SIZE_MGR(i));
390 if (i == OMAP_DSS_CHANNEL_DIGIT)
391 continue;
392 RR(TIMING_H(i));
393 RR(TIMING_V(i));
394 RR(POL_FREQ(i));
395 RR(DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530396
Archit Tanejac6104b82011-08-05 19:06:02 +0530397 RR(DATA_CYCLE1(i));
398 RR(DATA_CYCLE2(i));
399 RR(DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000400
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300401 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530402 RR(CPR_COEF_R(i));
403 RR(CPR_COEF_G(i));
404 RR(CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300405 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000406 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200407
Archit Tanejac6104b82011-08-05 19:06:02 +0530408 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
409 RR(OVL_BA0(i));
410 RR(OVL_BA1(i));
411 RR(OVL_POSITION(i));
412 RR(OVL_SIZE(i));
413 RR(OVL_ATTRIBUTES(i));
414 RR(OVL_FIFO_THRESHOLD(i));
415 RR(OVL_ROW_INC(i));
416 RR(OVL_PIXEL_INC(i));
417 if (dss_has_feature(FEAT_PRELOAD))
418 RR(OVL_PRELOAD(i));
419 if (i == OMAP_DSS_GFX) {
420 RR(OVL_WINDOW_SKIP(i));
421 RR(OVL_TABLE_BA(i));
422 continue;
423 }
424 RR(OVL_FIR(i));
425 RR(OVL_PICTURE_SIZE(i));
426 RR(OVL_ACCU0(i));
427 RR(OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200428
Archit Tanejac6104b82011-08-05 19:06:02 +0530429 for (j = 0; j < 8; j++)
430 RR(OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200431
Archit Tanejac6104b82011-08-05 19:06:02 +0530432 for (j = 0; j < 8; j++)
433 RR(OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200434
Archit Tanejac6104b82011-08-05 19:06:02 +0530435 for (j = 0; j < 5; j++)
436 RR(OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200437
Archit Tanejac6104b82011-08-05 19:06:02 +0530438 if (dss_has_feature(FEAT_FIR_COEF_V)) {
439 for (j = 0; j < 8; j++)
440 RR(OVL_FIR_COEF_V(i, j));
441 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200442
Archit Tanejac6104b82011-08-05 19:06:02 +0530443 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
444 RR(OVL_BA0_UV(i));
445 RR(OVL_BA1_UV(i));
446 RR(OVL_FIR2(i));
447 RR(OVL_ACCU2_0(i));
448 RR(OVL_ACCU2_1(i));
449
450 for (j = 0; j < 8; j++)
451 RR(OVL_FIR_COEF_H2(i, j));
452
453 for (j = 0; j < 8; j++)
454 RR(OVL_FIR_COEF_HV2(i, j));
455
456 for (j = 0; j < 8; j++)
457 RR(OVL_FIR_COEF_V2(i, j));
458 }
459 if (dss_has_feature(FEAT_ATTR2))
460 RR(OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300461 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200462
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600463 if (dss_has_feature(FEAT_CORE_CLK_DIV))
464 RR(DIVISOR);
465
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200466 /* enable last, because LCD & DIGIT enable are here */
467 RR(CONTROL);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000468 if (dss_has_feature(FEAT_MGR_LCD2))
469 RR(CONTROL2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530470 if (dss_has_feature(FEAT_MGR_LCD3))
471 RR(CONTROL3);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200472 /* clear spurious SYNC_LOST_DIGIT interrupts */
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +0300473 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200474
475 /*
476 * enable last so IRQs won't trigger before
477 * the context is fully restored
478 */
479 RR(IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300480
481 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200482}
483
484#undef SR
485#undef RR
486
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300487int dispc_runtime_get(void)
488{
489 int r;
490
491 DSSDBG("dispc_runtime_get\n");
492
493 r = pm_runtime_get_sync(&dispc.pdev->dev);
494 WARN_ON(r < 0);
495 return r < 0 ? r : 0;
496}
497
498void dispc_runtime_put(void)
499{
500 int r;
501
502 DSSDBG("dispc_runtime_put\n");
503
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200504 r = pm_runtime_put_sync(&dispc.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300505 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300506}
507
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200508u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
509{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530510 return mgr_desc[channel].vsync_irq;
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200511}
512
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200513u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
514{
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200515 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv)
516 return 0;
517
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530518 return mgr_desc[channel].framedone_irq;
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200519}
520
Tomi Valkeinencb699202012-10-17 10:38:52 +0300521u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
522{
523 return mgr_desc[channel].sync_lost_irq;
524}
525
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530526u32 dispc_wb_get_framedone_irq(void)
527{
528 return DISPC_IRQ_FRAMEDONEWB;
529}
530
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300531bool dispc_mgr_go_busy(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200532{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530533 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200534}
535
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300536void dispc_mgr_go(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200537{
Tomi Valkeinen3c91ee82012-10-19 15:06:07 +0300538 WARN_ON(dispc_mgr_is_enabled(channel) == false);
539 WARN_ON(dispc_mgr_go_busy(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200540
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530541 DSSDBG("GO %s\n", mgr_desc[channel].name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200542
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530543 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200544}
545
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530546bool dispc_wb_go_busy(void)
547{
548 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
549}
550
551void dispc_wb_go(void)
552{
553 enum omap_plane plane = OMAP_DSS_WB;
554 bool enable, go;
555
556 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
557
558 if (!enable)
559 return;
560
561 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
562 if (go) {
563 DSSERR("GO bit not down for WB\n");
564 return;
565 }
566
567 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
568}
569
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300570static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200571{
Archit Taneja9b372c22011-05-06 11:45:49 +0530572 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200573}
574
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300575static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200576{
Archit Taneja9b372c22011-05-06 11:45:49 +0530577 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200578}
579
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300580static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200581{
Archit Taneja9b372c22011-05-06 11:45:49 +0530582 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200583}
584
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300585static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530586{
587 BUG_ON(plane == OMAP_DSS_GFX);
588
589 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
590}
591
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300592static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
593 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530594{
595 BUG_ON(plane == OMAP_DSS_GFX);
596
597 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
598}
599
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300600static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530601{
602 BUG_ON(plane == OMAP_DSS_GFX);
603
604 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
605}
606
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530607static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
608 int fir_vinc, int five_taps,
609 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200610{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530611 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200612 int i;
613
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530614 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
615 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200616
617 for (i = 0; i < 8; i++) {
618 u32 h, hv;
619
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530620 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
621 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
622 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
623 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
624 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
625 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
626 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
627 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200628
Amber Jain0d66cbb2011-05-19 19:47:54 +0530629 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300630 dispc_ovl_write_firh_reg(plane, i, h);
631 dispc_ovl_write_firhv_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530632 } else {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300633 dispc_ovl_write_firh2_reg(plane, i, h);
634 dispc_ovl_write_firhv2_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530635 }
636
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200637 }
638
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200639 if (five_taps) {
640 for (i = 0; i < 8; i++) {
641 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530642 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
643 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530644 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300645 dispc_ovl_write_firv_reg(plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530646 else
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300647 dispc_ovl_write_firv2_reg(plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200648 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200649 }
650}
651
Archit Taneja6e5264b2012-09-11 12:04:47 +0530652
653static void dispc_ovl_write_color_conv_coef(enum omap_plane plane,
654 const struct color_conv_coef *ct)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200655{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200656#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
657
Archit Taneja6e5264b2012-09-11 12:04:47 +0530658 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
659 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
660 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
661 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
662 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200663
Archit Taneja6e5264b2012-09-11 12:04:47 +0530664 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200665
666#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200667}
668
Archit Taneja6e5264b2012-09-11 12:04:47 +0530669static void dispc_setup_color_conv_coef(void)
670{
671 int i;
672 int num_ovl = dss_feat_get_num_ovls();
673 int num_wb = dss_feat_get_num_wbs();
674 const struct color_conv_coef ctbl_bt601_5_ovl = {
675 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
676 };
677 const struct color_conv_coef ctbl_bt601_5_wb = {
678 66, 112, -38, 129, -94, -74, 25, -18, 112, 0,
679 };
680
681 for (i = 1; i < num_ovl; i++)
682 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
683
684 for (; i < num_wb; i++)
685 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_wb);
686}
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200687
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300688static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200689{
Archit Taneja9b372c22011-05-06 11:45:49 +0530690 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200691}
692
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300693static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200694{
Archit Taneja9b372c22011-05-06 11:45:49 +0530695 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200696}
697
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300698static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530699{
700 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
701}
702
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300703static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530704{
705 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
706}
707
Archit Tanejad79db852012-09-22 12:30:17 +0530708static void dispc_ovl_set_pos(enum omap_plane plane,
709 enum omap_overlay_caps caps, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200710{
Archit Tanejad79db852012-09-22 12:30:17 +0530711 u32 val;
712
713 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
714 return;
715
716 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530717
718 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200719}
720
Archit Taneja78b687f2012-09-21 14:51:49 +0530721static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
722 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200723{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200724 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530725
Archit Taneja36d87d92012-07-28 22:59:03 +0530726 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
Archit Taneja9b372c22011-05-06 11:45:49 +0530727 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
728 else
729 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200730}
731
Archit Taneja78b687f2012-09-21 14:51:49 +0530732static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
733 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200734{
735 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200736
737 BUG_ON(plane == OMAP_DSS_GFX);
738
739 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530740
Archit Taneja36d87d92012-07-28 22:59:03 +0530741 if (plane == OMAP_DSS_WB)
742 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
743 else
744 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200745}
746
Archit Taneja5b54ed32012-09-26 16:55:27 +0530747static void dispc_ovl_set_zorder(enum omap_plane plane,
748 enum omap_overlay_caps caps, u8 zorder)
Archit Taneja54128702011-09-08 11:29:17 +0530749{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530750 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
Archit Taneja54128702011-09-08 11:29:17 +0530751 return;
752
753 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
754}
755
756static void dispc_ovl_enable_zorder_planes(void)
757{
758 int i;
759
760 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
761 return;
762
763 for (i = 0; i < dss_feat_get_num_ovls(); i++)
764 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
765}
766
Archit Taneja5b54ed32012-09-26 16:55:27 +0530767static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
768 enum omap_overlay_caps caps, bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100769{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530770 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100771 return;
772
Archit Taneja9b372c22011-05-06 11:45:49 +0530773 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100774}
775
Archit Taneja5b54ed32012-09-26 16:55:27 +0530776static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
777 enum omap_overlay_caps caps, u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200778{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530779 static const unsigned shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300780 int shift;
781
Archit Taneja5b54ed32012-09-26 16:55:27 +0530782 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100783 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530784
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300785 shift = shifts[plane];
786 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200787}
788
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300789static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200790{
Archit Taneja9b372c22011-05-06 11:45:49 +0530791 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200792}
793
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300794static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200795{
Archit Taneja9b372c22011-05-06 11:45:49 +0530796 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200797}
798
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300799static void dispc_ovl_set_color_mode(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200800 enum omap_color_mode color_mode)
801{
802 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +0530803 if (plane != OMAP_DSS_GFX) {
804 switch (color_mode) {
805 case OMAP_DSS_COLOR_NV12:
806 m = 0x0; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530807 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530808 m = 0x1; break;
809 case OMAP_DSS_COLOR_RGBA16:
810 m = 0x2; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530811 case OMAP_DSS_COLOR_RGB12U:
Amber Jainf20e4222011-05-19 19:47:50 +0530812 m = 0x4; break;
813 case OMAP_DSS_COLOR_ARGB16:
814 m = 0x5; break;
815 case OMAP_DSS_COLOR_RGB16:
816 m = 0x6; break;
817 case OMAP_DSS_COLOR_ARGB16_1555:
818 m = 0x7; break;
819 case OMAP_DSS_COLOR_RGB24U:
820 m = 0x8; break;
821 case OMAP_DSS_COLOR_RGB24P:
822 m = 0x9; break;
823 case OMAP_DSS_COLOR_YUV2:
824 m = 0xa; break;
825 case OMAP_DSS_COLOR_UYVY:
826 m = 0xb; break;
827 case OMAP_DSS_COLOR_ARGB32:
828 m = 0xc; break;
829 case OMAP_DSS_COLOR_RGBA32:
830 m = 0xd; break;
831 case OMAP_DSS_COLOR_RGBX32:
832 m = 0xe; break;
833 case OMAP_DSS_COLOR_XRGB16_1555:
834 m = 0xf; break;
835 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300836 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530837 }
838 } else {
839 switch (color_mode) {
840 case OMAP_DSS_COLOR_CLUT1:
841 m = 0x0; break;
842 case OMAP_DSS_COLOR_CLUT2:
843 m = 0x1; break;
844 case OMAP_DSS_COLOR_CLUT4:
845 m = 0x2; break;
846 case OMAP_DSS_COLOR_CLUT8:
847 m = 0x3; break;
848 case OMAP_DSS_COLOR_RGB12U:
849 m = 0x4; break;
850 case OMAP_DSS_COLOR_ARGB16:
851 m = 0x5; break;
852 case OMAP_DSS_COLOR_RGB16:
853 m = 0x6; break;
854 case OMAP_DSS_COLOR_ARGB16_1555:
855 m = 0x7; break;
856 case OMAP_DSS_COLOR_RGB24U:
857 m = 0x8; break;
858 case OMAP_DSS_COLOR_RGB24P:
859 m = 0x9; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530860 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530861 m = 0xa; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530862 case OMAP_DSS_COLOR_RGBA16:
Amber Jainf20e4222011-05-19 19:47:50 +0530863 m = 0xb; break;
864 case OMAP_DSS_COLOR_ARGB32:
865 m = 0xc; break;
866 case OMAP_DSS_COLOR_RGBA32:
867 m = 0xd; break;
868 case OMAP_DSS_COLOR_RGBX32:
869 m = 0xe; break;
870 case OMAP_DSS_COLOR_XRGB16_1555:
871 m = 0xf; break;
872 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300873 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530874 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200875 }
876
Archit Taneja9b372c22011-05-06 11:45:49 +0530877 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200878}
879
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530880static void dispc_ovl_configure_burst_type(enum omap_plane plane,
881 enum omap_dss_rotation_type rotation_type)
882{
883 if (dss_has_feature(FEAT_BURST_2D) == 0)
884 return;
885
886 if (rotation_type == OMAP_DSS_ROT_TILER)
887 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
888 else
889 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
890}
891
Tomi Valkeinenf4279842011-10-28 15:26:26 +0300892void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200893{
894 int shift;
895 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000896 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200897
898 switch (plane) {
899 case OMAP_DSS_GFX:
900 shift = 8;
901 break;
902 case OMAP_DSS_VIDEO1:
903 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +0530904 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200905 shift = 16;
906 break;
907 default:
908 BUG();
909 return;
910 }
911
Archit Taneja9b372c22011-05-06 11:45:49 +0530912 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000913 if (dss_has_feature(FEAT_MGR_LCD2)) {
914 switch (channel) {
915 case OMAP_DSS_CHANNEL_LCD:
916 chan = 0;
917 chan2 = 0;
918 break;
919 case OMAP_DSS_CHANNEL_DIGIT:
920 chan = 1;
921 chan2 = 0;
922 break;
923 case OMAP_DSS_CHANNEL_LCD2:
924 chan = 0;
925 chan2 = 1;
926 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530927 case OMAP_DSS_CHANNEL_LCD3:
928 if (dss_has_feature(FEAT_MGR_LCD3)) {
929 chan = 0;
930 chan2 = 2;
931 } else {
932 BUG();
933 return;
934 }
935 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000936 default:
937 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300938 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000939 }
940
941 val = FLD_MOD(val, chan, shift, shift);
942 val = FLD_MOD(val, chan2, 31, 30);
943 } else {
944 val = FLD_MOD(val, channel, shift, shift);
945 }
Archit Taneja9b372c22011-05-06 11:45:49 +0530946 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200947}
948
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200949static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
950{
951 int shift;
952 u32 val;
953 enum omap_channel channel;
954
955 switch (plane) {
956 case OMAP_DSS_GFX:
957 shift = 8;
958 break;
959 case OMAP_DSS_VIDEO1:
960 case OMAP_DSS_VIDEO2:
961 case OMAP_DSS_VIDEO3:
962 shift = 16;
963 break;
964 default:
965 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300966 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200967 }
968
969 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
970
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530971 if (dss_has_feature(FEAT_MGR_LCD3)) {
972 if (FLD_GET(val, 31, 30) == 0)
973 channel = FLD_GET(val, shift, shift);
974 else if (FLD_GET(val, 31, 30) == 1)
975 channel = OMAP_DSS_CHANNEL_LCD2;
976 else
977 channel = OMAP_DSS_CHANNEL_LCD3;
978 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200979 if (FLD_GET(val, 31, 30) == 0)
980 channel = FLD_GET(val, shift, shift);
981 else
982 channel = OMAP_DSS_CHANNEL_LCD2;
983 } else {
984 channel = FLD_GET(val, shift, shift);
985 }
986
987 return channel;
988}
989
Archit Tanejad9ac7732012-09-22 12:38:19 +0530990void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
991{
992 enum omap_plane plane = OMAP_DSS_WB;
993
994 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
995}
996
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300997static void dispc_ovl_set_burst_size(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200998 enum omap_burst_size burst_size)
999{
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301000 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001001 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001002
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001003 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001004 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001005}
1006
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001007static void dispc_configure_burst_sizes(void)
1008{
1009 int i;
1010 const int burst_size = BURST_SIZE_X8;
1011
1012 /* Configure burst size always to maximum size */
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001013 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001014 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001015}
1016
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001017static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001018{
1019 unsigned unit = dss_feat_get_burst_size_unit();
1020 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1021 return unit * 8;
1022}
1023
Mythri P Kd3862612011-03-11 18:02:49 +05301024void dispc_enable_gamma_table(bool enable)
1025{
1026 /*
1027 * This is partially implemented to support only disabling of
1028 * the gamma table.
1029 */
1030 if (enable) {
1031 DSSWARN("Gamma table enabling for TV not yet supported");
1032 return;
1033 }
1034
1035 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1036}
1037
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001038static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001039{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301040 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001041 return;
1042
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301043 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001044}
1045
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001046static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02001047 const struct omap_dss_cpr_coefs *coefs)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001048{
1049 u32 coef_r, coef_g, coef_b;
1050
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301051 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001052 return;
1053
1054 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1055 FLD_VAL(coefs->rb, 9, 0);
1056 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1057 FLD_VAL(coefs->gb, 9, 0);
1058 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1059 FLD_VAL(coefs->bb, 9, 0);
1060
1061 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1062 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1063 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1064}
1065
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001066static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001067{
1068 u32 val;
1069
1070 BUG_ON(plane == OMAP_DSS_GFX);
1071
Archit Taneja9b372c22011-05-06 11:45:49 +05301072 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001073 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +05301074 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001075}
1076
Archit Tanejad79db852012-09-22 12:30:17 +05301077static void dispc_ovl_enable_replication(enum omap_plane plane,
1078 enum omap_overlay_caps caps, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001079{
Archit Tanejab8c095b2011-09-13 18:20:33 +05301080 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001081 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001082
Archit Tanejad79db852012-09-22 12:30:17 +05301083 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1084 return;
1085
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001086 shift = shifts[plane];
1087 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001088}
1089
Archit Taneja8f366162012-04-16 12:53:44 +05301090static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
Archit Tanejae5c09e02012-04-16 12:53:42 +05301091 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001092{
1093 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301094
Archit Taneja33b89922012-11-14 13:50:15 +05301095 val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1096 FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1097
Archit Taneja702d1442011-05-06 11:45:50 +05301098 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001099}
1100
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001101static void dispc_init_fifos(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001102{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001103 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001104 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301105 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001106 u32 unit;
1107
1108 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001109
Archit Tanejaa0acb552010-09-15 19:20:00 +05301110 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001111
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001112 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1113 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001114 size *= unit;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001115 dispc.fifo_size[fifo] = size;
1116
1117 /*
1118 * By default fifos are mapped directly to overlays, fifo 0 to
1119 * ovl 0, fifo 1 to ovl 1, etc.
1120 */
1121 dispc.fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001122 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001123
1124 /*
1125 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1126 * causes problems with certain use cases, like using the tiler in 2D
1127 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1128 * giving GFX plane a larger fifo. WB but should work fine with a
1129 * smaller fifo.
1130 */
1131 if (dispc.feat->gfx_fifo_workaround) {
1132 u32 v;
1133
1134 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1135
1136 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1137 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1138 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1139 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1140
1141 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1142
1143 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1144 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1145 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001146}
1147
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001148static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001149{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001150 int fifo;
1151 u32 size = 0;
1152
1153 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1154 if (dispc.fifo_assignment[fifo] == plane)
1155 size += dispc.fifo_size[fifo];
1156 }
1157
1158 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001159}
1160
Tomi Valkeinen6f04e1b2011-10-31 08:58:52 +02001161void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001162{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301163 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001164 u32 unit;
1165
1166 unit = dss_feat_get_buffer_size_unit();
1167
1168 WARN_ON(low % unit != 0);
1169 WARN_ON(high % unit != 0);
1170
1171 low /= unit;
1172 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301173
Archit Taneja9b372c22011-05-06 11:45:49 +05301174 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1175 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1176
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001177 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001178 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301179 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001180 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301181 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001182 hi_start, hi_end) * unit,
1183 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001184
Archit Taneja9b372c22011-05-06 11:45:49 +05301185 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301186 FLD_VAL(high, hi_start, hi_end) |
1187 FLD_VAL(low, lo_start, lo_end));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001188}
1189
1190void dispc_enable_fifomerge(bool enable)
1191{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001192 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1193 WARN_ON(enable);
1194 return;
1195 }
1196
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001197 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1198 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001199}
1200
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001201void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001202 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1203 bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001204{
1205 /*
1206 * All sizes are in bytes. Both the buffer and burst are made of
1207 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1208 */
1209
1210 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001211 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1212 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001213
1214 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001215 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001216
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001217 if (use_fifomerge) {
1218 total_fifo_size = 0;
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001219 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001220 total_fifo_size += dispc_ovl_get_fifo_size(i);
1221 } else {
1222 total_fifo_size = ovl_fifo_size;
1223 }
1224
1225 /*
1226 * We use the same low threshold for both fifomerge and non-fifomerge
1227 * cases, but for fifomerge we calculate the high threshold using the
1228 * combined fifo size
1229 */
1230
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001231 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001232 *fifo_low = ovl_fifo_size - burst_size * 2;
1233 *fifo_high = total_fifo_size - burst_size;
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301234 } else if (plane == OMAP_DSS_WB) {
1235 /*
1236 * Most optimal configuration for writeback is to push out data
1237 * to the interconnect the moment writeback pushes enough pixels
1238 * in the FIFO to form a burst
1239 */
1240 *fifo_low = 0;
1241 *fifo_high = burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001242 } else {
1243 *fifo_low = ovl_fifo_size - burst_size;
1244 *fifo_high = total_fifo_size - buf_unit;
1245 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001246}
1247
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001248static void dispc_ovl_set_fir(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301249 int hinc, int vinc,
1250 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001251{
1252 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001253
Amber Jain0d66cbb2011-05-19 19:47:54 +05301254 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1255 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301256
Amber Jain0d66cbb2011-05-19 19:47:54 +05301257 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1258 &hinc_start, &hinc_end);
1259 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1260 &vinc_start, &vinc_end);
1261 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1262 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301263
Amber Jain0d66cbb2011-05-19 19:47:54 +05301264 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1265 } else {
1266 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1267 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1268 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001269}
1270
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001271static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001272{
1273 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301274 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001275
Archit Taneja87a74842011-03-02 11:19:50 +05301276 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1277 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1278
1279 val = FLD_VAL(vaccu, vert_start, vert_end) |
1280 FLD_VAL(haccu, hor_start, hor_end);
1281
Archit Taneja9b372c22011-05-06 11:45:49 +05301282 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001283}
1284
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001285static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001286{
1287 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301288 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001289
Archit Taneja87a74842011-03-02 11:19:50 +05301290 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1291 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1292
1293 val = FLD_VAL(vaccu, vert_start, vert_end) |
1294 FLD_VAL(haccu, hor_start, hor_end);
1295
Archit Taneja9b372c22011-05-06 11:45:49 +05301296 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001297}
1298
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001299static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1300 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301301{
1302 u32 val;
1303
1304 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1305 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1306}
1307
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001308static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1309 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301310{
1311 u32 val;
1312
1313 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1314 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1315}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001316
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001317static void dispc_ovl_set_scale_param(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001318 u16 orig_width, u16 orig_height,
1319 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301320 bool five_taps, u8 rotation,
1321 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001322{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301323 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001324
Amber Jained14a3c2011-05-19 19:47:51 +05301325 fir_hinc = 1024 * orig_width / out_width;
1326 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001327
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301328 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1329 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001330 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301331}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001332
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301333static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1334 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1335 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1336{
1337 int h_accu2_0, h_accu2_1;
1338 int v_accu2_0, v_accu2_1;
1339 int chroma_hinc, chroma_vinc;
1340 int idx;
1341
1342 struct accu {
1343 s8 h0_m, h0_n;
1344 s8 h1_m, h1_n;
1345 s8 v0_m, v0_n;
1346 s8 v1_m, v1_n;
1347 };
1348
1349 const struct accu *accu_table;
1350 const struct accu *accu_val;
1351
1352 static const struct accu accu_nv12[4] = {
1353 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1354 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1355 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1356 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1357 };
1358
1359 static const struct accu accu_nv12_ilace[4] = {
1360 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1361 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1362 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1363 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1364 };
1365
1366 static const struct accu accu_yuv[4] = {
1367 { 0, 1, 0, 1, 0, 1, 0, 1 },
1368 { 0, 1, 0, 1, 0, 1, 0, 1 },
1369 { -1, 1, 0, 1, 0, 1, 0, 1 },
1370 { 0, 1, 0, 1, -1, 1, 0, 1 },
1371 };
1372
1373 switch (rotation) {
1374 case OMAP_DSS_ROT_0:
1375 idx = 0;
1376 break;
1377 case OMAP_DSS_ROT_90:
1378 idx = 1;
1379 break;
1380 case OMAP_DSS_ROT_180:
1381 idx = 2;
1382 break;
1383 case OMAP_DSS_ROT_270:
1384 idx = 3;
1385 break;
1386 default:
1387 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001388 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301389 }
1390
1391 switch (color_mode) {
1392 case OMAP_DSS_COLOR_NV12:
1393 if (ilace)
1394 accu_table = accu_nv12_ilace;
1395 else
1396 accu_table = accu_nv12;
1397 break;
1398 case OMAP_DSS_COLOR_YUV2:
1399 case OMAP_DSS_COLOR_UYVY:
1400 accu_table = accu_yuv;
1401 break;
1402 default:
1403 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001404 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301405 }
1406
1407 accu_val = &accu_table[idx];
1408
1409 chroma_hinc = 1024 * orig_width / out_width;
1410 chroma_vinc = 1024 * orig_height / out_height;
1411
1412 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1413 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1414 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1415 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1416
1417 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1418 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1419}
1420
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001421static void dispc_ovl_set_scaling_common(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301422 u16 orig_width, u16 orig_height,
1423 u16 out_width, u16 out_height,
1424 bool ilace, bool five_taps,
1425 bool fieldmode, enum omap_color_mode color_mode,
1426 u8 rotation)
1427{
1428 int accu0 = 0;
1429 int accu1 = 0;
1430 u32 l;
1431
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001432 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301433 out_width, out_height, five_taps,
1434 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301435 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001436
Archit Taneja87a74842011-03-02 11:19:50 +05301437 /* RESIZEENABLE and VERTICALTAPS */
1438 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301439 l |= (orig_width != out_width) ? (1 << 5) : 0;
1440 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001441 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301442
1443 /* VRESIZECONF and HRESIZECONF */
1444 if (dss_has_feature(FEAT_RESIZECONF)) {
1445 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301446 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1447 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301448 }
1449
1450 /* LINEBUFFERSPLIT */
1451 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1452 l &= ~(0x1 << 22);
1453 l |= five_taps ? (1 << 22) : 0;
1454 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001455
Archit Taneja9b372c22011-05-06 11:45:49 +05301456 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001457
1458 /*
1459 * field 0 = even field = bottom field
1460 * field 1 = odd field = top field
1461 */
1462 if (ilace && !fieldmode) {
1463 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301464 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001465 if (accu0 >= 1024/2) {
1466 accu1 = 1024/2;
1467 accu0 -= accu1;
1468 }
1469 }
1470
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001471 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1472 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001473}
1474
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001475static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301476 u16 orig_width, u16 orig_height,
1477 u16 out_width, u16 out_height,
1478 bool ilace, bool five_taps,
1479 bool fieldmode, enum omap_color_mode color_mode,
1480 u8 rotation)
1481{
1482 int scale_x = out_width != orig_width;
1483 int scale_y = out_height != orig_height;
Archit Tanejaf92afae2012-08-24 11:11:14 +05301484 bool chroma_upscale = plane != OMAP_DSS_WB ? true : false;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301485
1486 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1487 return;
1488 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1489 color_mode != OMAP_DSS_COLOR_UYVY &&
1490 color_mode != OMAP_DSS_COLOR_NV12)) {
1491 /* reset chroma resampling for RGB formats */
Archit Taneja2a5561b2012-07-16 16:37:45 +05301492 if (plane != OMAP_DSS_WB)
1493 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301494 return;
1495 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001496
1497 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1498 out_height, ilace, color_mode, rotation);
1499
Amber Jain0d66cbb2011-05-19 19:47:54 +05301500 switch (color_mode) {
1501 case OMAP_DSS_COLOR_NV12:
Archit Taneja20fbb502012-08-22 17:04:48 +05301502 if (chroma_upscale) {
1503 /* UV is subsampled by 2 horizontally and vertically */
1504 orig_height >>= 1;
1505 orig_width >>= 1;
1506 } else {
1507 /* UV is downsampled by 2 horizontally and vertically */
1508 orig_height <<= 1;
1509 orig_width <<= 1;
1510 }
1511
Amber Jain0d66cbb2011-05-19 19:47:54 +05301512 break;
1513 case OMAP_DSS_COLOR_YUV2:
1514 case OMAP_DSS_COLOR_UYVY:
Archit Taneja20fbb502012-08-22 17:04:48 +05301515 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
Amber Jain0d66cbb2011-05-19 19:47:54 +05301516 if (rotation == OMAP_DSS_ROT_0 ||
Archit Taneja20fbb502012-08-22 17:04:48 +05301517 rotation == OMAP_DSS_ROT_180) {
1518 if (chroma_upscale)
1519 /* UV is subsampled by 2 horizontally */
1520 orig_width >>= 1;
1521 else
1522 /* UV is downsampled by 2 horizontally */
1523 orig_width <<= 1;
1524 }
1525
Amber Jain0d66cbb2011-05-19 19:47:54 +05301526 /* must use FIR for YUV422 if rotated */
1527 if (rotation != OMAP_DSS_ROT_0)
1528 scale_x = scale_y = true;
Archit Taneja20fbb502012-08-22 17:04:48 +05301529
Amber Jain0d66cbb2011-05-19 19:47:54 +05301530 break;
1531 default:
1532 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001533 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301534 }
1535
1536 if (out_width != orig_width)
1537 scale_x = true;
1538 if (out_height != orig_height)
1539 scale_y = true;
1540
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001541 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301542 out_width, out_height, five_taps,
1543 rotation, DISPC_COLOR_COMPONENT_UV);
1544
Archit Taneja2a5561b2012-07-16 16:37:45 +05301545 if (plane != OMAP_DSS_WB)
1546 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1547 (scale_x || scale_y) ? 1 : 0, 8, 8);
1548
Amber Jain0d66cbb2011-05-19 19:47:54 +05301549 /* set H scaling */
1550 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1551 /* set V scaling */
1552 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301553}
1554
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001555static void dispc_ovl_set_scaling(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301556 u16 orig_width, u16 orig_height,
1557 u16 out_width, u16 out_height,
1558 bool ilace, bool five_taps,
1559 bool fieldmode, enum omap_color_mode color_mode,
1560 u8 rotation)
1561{
1562 BUG_ON(plane == OMAP_DSS_GFX);
1563
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001564 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301565 orig_width, orig_height,
1566 out_width, out_height,
1567 ilace, five_taps,
1568 fieldmode, color_mode,
1569 rotation);
1570
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001571 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301572 orig_width, orig_height,
1573 out_width, out_height,
1574 ilace, five_taps,
1575 fieldmode, color_mode,
1576 rotation);
1577}
1578
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001579static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001580 bool mirroring, enum omap_color_mode color_mode)
1581{
Archit Taneja87a74842011-03-02 11:19:50 +05301582 bool row_repeat = false;
1583 int vidrot = 0;
1584
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001585 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1586 color_mode == OMAP_DSS_COLOR_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001587
1588 if (mirroring) {
1589 switch (rotation) {
1590 case OMAP_DSS_ROT_0:
1591 vidrot = 2;
1592 break;
1593 case OMAP_DSS_ROT_90:
1594 vidrot = 1;
1595 break;
1596 case OMAP_DSS_ROT_180:
1597 vidrot = 0;
1598 break;
1599 case OMAP_DSS_ROT_270:
1600 vidrot = 3;
1601 break;
1602 }
1603 } else {
1604 switch (rotation) {
1605 case OMAP_DSS_ROT_0:
1606 vidrot = 0;
1607 break;
1608 case OMAP_DSS_ROT_90:
1609 vidrot = 1;
1610 break;
1611 case OMAP_DSS_ROT_180:
1612 vidrot = 2;
1613 break;
1614 case OMAP_DSS_ROT_270:
1615 vidrot = 3;
1616 break;
1617 }
1618 }
1619
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001620 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
Archit Taneja87a74842011-03-02 11:19:50 +05301621 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001622 else
Archit Taneja87a74842011-03-02 11:19:50 +05301623 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001624 }
Archit Taneja87a74842011-03-02 11:19:50 +05301625
Archit Taneja9b372c22011-05-06 11:45:49 +05301626 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301627 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301628 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1629 row_repeat ? 1 : 0, 18, 18);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001630}
1631
1632static int color_mode_to_bpp(enum omap_color_mode color_mode)
1633{
1634 switch (color_mode) {
1635 case OMAP_DSS_COLOR_CLUT1:
1636 return 1;
1637 case OMAP_DSS_COLOR_CLUT2:
1638 return 2;
1639 case OMAP_DSS_COLOR_CLUT4:
1640 return 4;
1641 case OMAP_DSS_COLOR_CLUT8:
Amber Jainf20e4222011-05-19 19:47:50 +05301642 case OMAP_DSS_COLOR_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001643 return 8;
1644 case OMAP_DSS_COLOR_RGB12U:
1645 case OMAP_DSS_COLOR_RGB16:
1646 case OMAP_DSS_COLOR_ARGB16:
1647 case OMAP_DSS_COLOR_YUV2:
1648 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301649 case OMAP_DSS_COLOR_RGBA16:
1650 case OMAP_DSS_COLOR_RGBX16:
1651 case OMAP_DSS_COLOR_ARGB16_1555:
1652 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001653 return 16;
1654 case OMAP_DSS_COLOR_RGB24P:
1655 return 24;
1656 case OMAP_DSS_COLOR_RGB24U:
1657 case OMAP_DSS_COLOR_ARGB32:
1658 case OMAP_DSS_COLOR_RGBA32:
1659 case OMAP_DSS_COLOR_RGBX32:
1660 return 32;
1661 default:
1662 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001663 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001664 }
1665}
1666
1667static s32 pixinc(int pixels, u8 ps)
1668{
1669 if (pixels == 1)
1670 return 1;
1671 else if (pixels > 1)
1672 return 1 + (pixels - 1) * ps;
1673 else if (pixels < 0)
1674 return 1 - (-pixels + 1) * ps;
1675 else
1676 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001677 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001678}
1679
1680static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1681 u16 screen_width,
1682 u16 width, u16 height,
1683 enum omap_color_mode color_mode, bool fieldmode,
1684 unsigned int field_offset,
1685 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301686 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001687{
1688 u8 ps;
1689
1690 /* FIXME CLUT formats */
1691 switch (color_mode) {
1692 case OMAP_DSS_COLOR_CLUT1:
1693 case OMAP_DSS_COLOR_CLUT2:
1694 case OMAP_DSS_COLOR_CLUT4:
1695 case OMAP_DSS_COLOR_CLUT8:
1696 BUG();
1697 return;
1698 case OMAP_DSS_COLOR_YUV2:
1699 case OMAP_DSS_COLOR_UYVY:
1700 ps = 4;
1701 break;
1702 default:
1703 ps = color_mode_to_bpp(color_mode) / 8;
1704 break;
1705 }
1706
1707 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1708 width, height);
1709
1710 /*
1711 * field 0 = even field = bottom field
1712 * field 1 = odd field = top field
1713 */
1714 switch (rotation + mirror * 4) {
1715 case OMAP_DSS_ROT_0:
1716 case OMAP_DSS_ROT_180:
1717 /*
1718 * If the pixel format is YUV or UYVY divide the width
1719 * of the image by 2 for 0 and 180 degree rotation.
1720 */
1721 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1722 color_mode == OMAP_DSS_COLOR_UYVY)
1723 width = width >> 1;
1724 case OMAP_DSS_ROT_90:
1725 case OMAP_DSS_ROT_270:
1726 *offset1 = 0;
1727 if (field_offset)
1728 *offset0 = field_offset * screen_width * ps;
1729 else
1730 *offset0 = 0;
1731
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301732 *row_inc = pixinc(1 +
1733 (y_predecim * screen_width - x_predecim * width) +
1734 (fieldmode ? screen_width : 0), ps);
1735 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001736 break;
1737
1738 case OMAP_DSS_ROT_0 + 4:
1739 case OMAP_DSS_ROT_180 + 4:
1740 /* If the pixel format is YUV or UYVY divide the width
1741 * of the image by 2 for 0 degree and 180 degree
1742 */
1743 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1744 color_mode == OMAP_DSS_COLOR_UYVY)
1745 width = width >> 1;
1746 case OMAP_DSS_ROT_90 + 4:
1747 case OMAP_DSS_ROT_270 + 4:
1748 *offset1 = 0;
1749 if (field_offset)
1750 *offset0 = field_offset * screen_width * ps;
1751 else
1752 *offset0 = 0;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301753 *row_inc = pixinc(1 -
1754 (y_predecim * screen_width + x_predecim * width) -
1755 (fieldmode ? screen_width : 0), ps);
1756 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001757 break;
1758
1759 default:
1760 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001761 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001762 }
1763}
1764
1765static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1766 u16 screen_width,
1767 u16 width, u16 height,
1768 enum omap_color_mode color_mode, bool fieldmode,
1769 unsigned int field_offset,
1770 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301771 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001772{
1773 u8 ps;
1774 u16 fbw, fbh;
1775
1776 /* FIXME CLUT formats */
1777 switch (color_mode) {
1778 case OMAP_DSS_COLOR_CLUT1:
1779 case OMAP_DSS_COLOR_CLUT2:
1780 case OMAP_DSS_COLOR_CLUT4:
1781 case OMAP_DSS_COLOR_CLUT8:
1782 BUG();
1783 return;
1784 default:
1785 ps = color_mode_to_bpp(color_mode) / 8;
1786 break;
1787 }
1788
1789 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1790 width, height);
1791
1792 /* width & height are overlay sizes, convert to fb sizes */
1793
1794 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1795 fbw = width;
1796 fbh = height;
1797 } else {
1798 fbw = height;
1799 fbh = width;
1800 }
1801
1802 /*
1803 * field 0 = even field = bottom field
1804 * field 1 = odd field = top field
1805 */
1806 switch (rotation + mirror * 4) {
1807 case OMAP_DSS_ROT_0:
1808 *offset1 = 0;
1809 if (field_offset)
1810 *offset0 = *offset1 + field_offset * screen_width * ps;
1811 else
1812 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301813 *row_inc = pixinc(1 +
1814 (y_predecim * screen_width - fbw * x_predecim) +
1815 (fieldmode ? screen_width : 0), ps);
1816 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1817 color_mode == OMAP_DSS_COLOR_UYVY)
1818 *pix_inc = pixinc(x_predecim, 2 * ps);
1819 else
1820 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001821 break;
1822 case OMAP_DSS_ROT_90:
1823 *offset1 = screen_width * (fbh - 1) * ps;
1824 if (field_offset)
1825 *offset0 = *offset1 + field_offset * ps;
1826 else
1827 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301828 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1829 y_predecim + (fieldmode ? 1 : 0), ps);
1830 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001831 break;
1832 case OMAP_DSS_ROT_180:
1833 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1834 if (field_offset)
1835 *offset0 = *offset1 - field_offset * screen_width * ps;
1836 else
1837 *offset0 = *offset1;
1838 *row_inc = pixinc(-1 -
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301839 (y_predecim * screen_width - fbw * x_predecim) -
1840 (fieldmode ? screen_width : 0), ps);
1841 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1842 color_mode == OMAP_DSS_COLOR_UYVY)
1843 *pix_inc = pixinc(-x_predecim, 2 * ps);
1844 else
1845 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001846 break;
1847 case OMAP_DSS_ROT_270:
1848 *offset1 = (fbw - 1) * ps;
1849 if (field_offset)
1850 *offset0 = *offset1 - field_offset * ps;
1851 else
1852 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301853 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1854 y_predecim - (fieldmode ? 1 : 0), ps);
1855 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001856 break;
1857
1858 /* mirroring */
1859 case OMAP_DSS_ROT_0 + 4:
1860 *offset1 = (fbw - 1) * ps;
1861 if (field_offset)
1862 *offset0 = *offset1 + field_offset * screen_width * ps;
1863 else
1864 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301865 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001866 (fieldmode ? screen_width : 0),
1867 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301868 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1869 color_mode == OMAP_DSS_COLOR_UYVY)
1870 *pix_inc = pixinc(-x_predecim, 2 * ps);
1871 else
1872 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001873 break;
1874
1875 case OMAP_DSS_ROT_90 + 4:
1876 *offset1 = 0;
1877 if (field_offset)
1878 *offset0 = *offset1 + field_offset * ps;
1879 else
1880 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301881 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1882 y_predecim + (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001883 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301884 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001885 break;
1886
1887 case OMAP_DSS_ROT_180 + 4:
1888 *offset1 = screen_width * (fbh - 1) * ps;
1889 if (field_offset)
1890 *offset0 = *offset1 - field_offset * screen_width * ps;
1891 else
1892 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301893 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001894 (fieldmode ? screen_width : 0),
1895 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301896 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1897 color_mode == OMAP_DSS_COLOR_UYVY)
1898 *pix_inc = pixinc(x_predecim, 2 * ps);
1899 else
1900 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001901 break;
1902
1903 case OMAP_DSS_ROT_270 + 4:
1904 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1905 if (field_offset)
1906 *offset0 = *offset1 - field_offset * ps;
1907 else
1908 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301909 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
1910 y_predecim - (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001911 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301912 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001913 break;
1914
1915 default:
1916 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001917 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001918 }
1919}
1920
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301921static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
1922 enum omap_color_mode color_mode, bool fieldmode,
1923 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1924 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1925{
1926 u8 ps;
1927
1928 switch (color_mode) {
1929 case OMAP_DSS_COLOR_CLUT1:
1930 case OMAP_DSS_COLOR_CLUT2:
1931 case OMAP_DSS_COLOR_CLUT4:
1932 case OMAP_DSS_COLOR_CLUT8:
1933 BUG();
1934 return;
1935 default:
1936 ps = color_mode_to_bpp(color_mode) / 8;
1937 break;
1938 }
1939
1940 DSSDBG("scrw %d, width %d\n", screen_width, width);
1941
1942 /*
1943 * field 0 = even field = bottom field
1944 * field 1 = odd field = top field
1945 */
1946 *offset1 = 0;
1947 if (field_offset)
1948 *offset0 = *offset1 + field_offset * screen_width * ps;
1949 else
1950 *offset0 = *offset1;
1951 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1952 (fieldmode ? screen_width : 0), ps);
1953 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1954 color_mode == OMAP_DSS_COLOR_UYVY)
1955 *pix_inc = pixinc(x_predecim, 2 * ps);
1956 else
1957 *pix_inc = pixinc(x_predecim, ps);
1958}
1959
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301960/*
1961 * This function is used to avoid synclosts in OMAP3, because of some
1962 * undocumented horizontal position and timing related limitations.
1963 */
Tomi Valkeinen465ec132012-10-19 15:40:24 +03001964static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
Archit Taneja81ab95b2012-05-08 15:53:20 +05301965 const struct omap_video_timings *t, u16 pos_x,
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301966 u16 width, u16 height, u16 out_width, u16 out_height)
1967{
Tomi Valkeinen230edc02012-11-05 14:40:19 +02001968 const int ds = DIV_ROUND_UP(height, out_height);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05301969 unsigned long nonactive;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301970 static const u8 limits[3] = { 8, 10, 20 };
1971 u64 val, blank;
1972 int i;
1973
Archit Taneja81ab95b2012-05-08 15:53:20 +05301974 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301975
1976 i = 0;
1977 if (out_height < height)
1978 i++;
1979 if (out_width < width)
1980 i++;
Archit Taneja81ab95b2012-05-08 15:53:20 +05301981 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301982 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
1983 if (blank <= limits[i])
1984 return -EINVAL;
1985
1986 /*
1987 * Pixel data should be prepared before visible display point starts.
1988 * So, atleast DS-2 lines must have already been fetched by DISPC
1989 * during nonactive - pos_x period.
1990 */
1991 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
1992 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02001993 val, max(0, ds - 2) * width);
1994 if (val < max(0, ds - 2) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301995 return -EINVAL;
1996
1997 /*
1998 * All lines need to be refilled during the nonactive period of which
1999 * only one line can be loaded during the active period. So, atleast
2000 * DS - 1 lines should be loaded during nonactive period.
2001 */
2002 val = div_u64((u64)nonactive * lclk, pclk);
2003 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002004 val, max(0, ds - 1) * width);
2005 if (val < max(0, ds - 1) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302006 return -EINVAL;
2007
2008 return 0;
2009}
2010
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002011static unsigned long calc_core_clk_five_taps(unsigned long pclk,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302012 const struct omap_video_timings *mgr_timings, u16 width,
2013 u16 height, u16 out_width, u16 out_height,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002014 enum omap_color_mode color_mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002015{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302016 u32 core_clk = 0;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302017 u64 tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002018
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302019 if (height <= out_height && width <= out_width)
2020 return (unsigned long) pclk;
2021
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002022 if (height > out_height) {
Archit Taneja81ab95b2012-05-08 15:53:20 +05302023 unsigned int ppl = mgr_timings->x_res;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002024
2025 tmp = pclk * height * out_width;
2026 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302027 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002028
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02002029 if (height > 2 * out_height) {
2030 if (ppl == out_width)
2031 return 0;
2032
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002033 tmp = pclk * (height - 2 * out_height) * out_width;
2034 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302035 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002036 }
2037 }
2038
2039 if (width > out_width) {
2040 tmp = pclk * width;
2041 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302042 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002043
2044 if (color_mode == OMAP_DSS_COLOR_RGB24U)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302045 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002046 }
2047
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302048 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002049}
2050
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002051static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302052 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302053{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302054 if (height > out_height && width > out_width)
2055 return pclk * 4;
2056 else
2057 return pclk * 2;
2058}
2059
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002060static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302061 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002062{
2063 unsigned int hf, vf;
2064
2065 /*
2066 * FIXME how to determine the 'A' factor
2067 * for the no downscaling case ?
2068 */
2069
2070 if (width > 3 * out_width)
2071 hf = 4;
2072 else if (width > 2 * out_width)
2073 hf = 3;
2074 else if (width > out_width)
2075 hf = 2;
2076 else
2077 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002078 if (height > out_height)
2079 vf = 2;
2080 else
2081 vf = 1;
2082
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302083 return pclk * vf * hf;
2084}
2085
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002086static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302087 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302088{
Archit Taneja8ba85302012-09-26 17:00:37 +05302089 /*
2090 * If the overlay/writeback is in mem to mem mode, there are no
2091 * downscaling limitations with respect to pixel clock, return 1 as
2092 * required core clock to represent that we have sufficient enough
2093 * core clock to do maximum downscaling
2094 */
2095 if (mem_to_mem)
2096 return 1;
2097
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302098 if (width > out_width)
2099 return DIV_ROUND_UP(pclk, out_width) * width;
2100 else
2101 return pclk;
2102}
2103
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002104static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302105 const struct omap_video_timings *mgr_timings,
2106 u16 width, u16 height, u16 out_width, u16 out_height,
2107 enum omap_color_mode color_mode, bool *five_taps,
2108 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302109 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302110{
2111 int error;
2112 u16 in_width, in_height;
2113 int min_factor = min(*decim_x, *decim_y);
2114 const int maxsinglelinewidth =
2115 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302116
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302117 *five_taps = false;
2118
2119 do {
2120 in_height = DIV_ROUND_UP(height, *decim_y);
2121 in_width = DIV_ROUND_UP(width, *decim_x);
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002122 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302123 in_height, out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302124 error = (in_width > maxsinglelinewidth || !*core_clk ||
2125 *core_clk > dispc_core_clk_rate());
2126 if (error) {
2127 if (*decim_x == *decim_y) {
2128 *decim_x = min_factor;
2129 ++*decim_y;
2130 } else {
2131 swap(*decim_x, *decim_y);
2132 if (*decim_x < *decim_y)
2133 ++*decim_x;
2134 }
2135 }
2136 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2137
2138 if (in_width > maxsinglelinewidth) {
2139 DSSERR("Cannot scale max input width exceeded");
2140 return -EINVAL;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302141 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302142 return 0;
2143}
2144
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002145static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302146 const struct omap_video_timings *mgr_timings,
2147 u16 width, u16 height, u16 out_width, u16 out_height,
2148 enum omap_color_mode color_mode, bool *five_taps,
2149 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302150 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302151{
2152 int error;
2153 u16 in_width, in_height;
2154 int min_factor = min(*decim_x, *decim_y);
2155 const int maxsinglelinewidth =
2156 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2157
2158 do {
2159 in_height = DIV_ROUND_UP(height, *decim_y);
2160 in_width = DIV_ROUND_UP(width, *decim_x);
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002161 *core_clk = calc_core_clk_five_taps(pclk, mgr_timings,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302162 in_width, in_height, out_width, out_height, color_mode);
2163
Tomi Valkeinen465ec132012-10-19 15:40:24 +03002164 error = check_horiz_timing_omap3(pclk, lclk, mgr_timings,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302165 pos_x, in_width, in_height, out_width,
2166 out_height);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302167
2168 if (in_width > maxsinglelinewidth)
2169 if (in_height > out_height &&
2170 in_height < out_height * 2)
2171 *five_taps = false;
2172 if (!*five_taps)
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002173 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302174 in_height, out_width, out_height,
2175 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302176
2177 error = (error || in_width > maxsinglelinewidth * 2 ||
2178 (in_width > maxsinglelinewidth && *five_taps) ||
2179 !*core_clk || *core_clk > dispc_core_clk_rate());
2180 if (error) {
2181 if (*decim_x == *decim_y) {
2182 *decim_x = min_factor;
2183 ++*decim_y;
2184 } else {
2185 swap(*decim_x, *decim_y);
2186 if (*decim_x < *decim_y)
2187 ++*decim_x;
2188 }
2189 }
2190 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2191
Tomi Valkeinen465ec132012-10-19 15:40:24 +03002192 if (check_horiz_timing_omap3(pclk, lclk, mgr_timings, pos_x, width,
2193 height, out_width, out_height)){
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302194 DSSERR("horizontal timing too tight\n");
2195 return -EINVAL;
2196 }
2197
2198 if (in_width > (maxsinglelinewidth * 2)) {
2199 DSSERR("Cannot setup scaling");
2200 DSSERR("width exceeds maximum width possible");
2201 return -EINVAL;
2202 }
2203
2204 if (in_width > maxsinglelinewidth && *five_taps) {
2205 DSSERR("cannot setup scaling with five taps");
2206 return -EINVAL;
2207 }
2208 return 0;
2209}
2210
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002211static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302212 const struct omap_video_timings *mgr_timings,
2213 u16 width, u16 height, u16 out_width, u16 out_height,
2214 enum omap_color_mode color_mode, bool *five_taps,
2215 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302216 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302217{
2218 u16 in_width, in_width_max;
2219 int decim_x_min = *decim_x;
2220 u16 in_height = DIV_ROUND_UP(height, *decim_y);
2221 const int maxsinglelinewidth =
2222 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja8ba85302012-09-26 17:00:37 +05302223 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302224
Archit Taneja5d501082012-11-07 11:45:02 +05302225 if (mem_to_mem) {
2226 in_width_max = out_width * maxdownscale;
2227 } else {
Archit Taneja8ba85302012-09-26 17:00:37 +05302228 in_width_max = dispc_core_clk_rate() /
2229 DIV_ROUND_UP(pclk, out_width);
Archit Taneja5d501082012-11-07 11:45:02 +05302230 }
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302231
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302232 *decim_x = DIV_ROUND_UP(width, in_width_max);
2233
2234 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2235 if (*decim_x > *x_predecim)
2236 return -EINVAL;
2237
2238 do {
2239 in_width = DIV_ROUND_UP(width, *decim_x);
2240 } while (*decim_x <= *x_predecim &&
2241 in_width > maxsinglelinewidth && ++*decim_x);
2242
2243 if (in_width > maxsinglelinewidth) {
2244 DSSERR("Cannot scale width exceeds max line width");
2245 return -EINVAL;
2246 }
2247
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002248 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
Archit Taneja8ba85302012-09-26 17:00:37 +05302249 out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302250 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002251}
2252
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002253static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302254 enum omap_overlay_caps caps,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302255 const struct omap_video_timings *mgr_timings,
2256 u16 width, u16 height, u16 out_width, u16 out_height,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302257 enum omap_color_mode color_mode, bool *five_taps,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302258 int *x_predecim, int *y_predecim, u16 pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302259 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302260{
Archit Taneja0373cac2011-09-08 13:25:17 +05302261 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302262 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302263 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302264 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302265
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002266 if (width == out_width && height == out_height)
2267 return 0;
2268
Archit Taneja5b54ed32012-09-26 16:55:27 +05302269 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002270 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302271
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002272 if (mem_to_mem) {
Archit Taneja1c031442012-11-07 11:45:03 +05302273 *x_predecim = *y_predecim = 1;
2274 } else {
2275 *x_predecim = max_decim_limit;
2276 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2277 dss_has_feature(FEAT_BURST_2D)) ?
2278 2 : max_decim_limit;
2279 }
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302280
2281 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2282 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2283 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2284 color_mode == OMAP_DSS_COLOR_CLUT8) {
2285 *x_predecim = 1;
2286 *y_predecim = 1;
2287 *five_taps = false;
2288 return 0;
2289 }
2290
2291 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2292 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2293
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302294 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302295 return -EINVAL;
2296
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302297 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302298 return -EINVAL;
2299
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002300 ret = dispc.feat->calc_scaling(pclk, lclk, mgr_timings, width, height,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302301 out_width, out_height, color_mode, five_taps,
Archit Taneja8ba85302012-09-26 17:00:37 +05302302 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2303 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302304 if (ret)
2305 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302306
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302307 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2308 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302309
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302310 if (!core_clk || core_clk > dispc_core_clk_rate()) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302311 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302312 "required core clk rate = %lu Hz, "
2313 "current core clk rate = %lu Hz\n",
2314 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302315 return -EINVAL;
2316 }
2317
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302318 *x_predecim = decim_x;
2319 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302320 return 0;
2321}
2322
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002323int dispc_ovl_check(enum omap_plane plane, enum omap_channel channel,
2324 const struct omap_overlay_info *oi,
2325 const struct omap_video_timings *timings,
2326 int *x_predecim, int *y_predecim)
2327{
2328 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2329 bool five_taps = true;
2330 bool fieldmode = 0;
2331 u16 in_height = oi->height;
2332 u16 in_width = oi->width;
2333 bool ilace = timings->interlace;
2334 u16 out_width, out_height;
2335 int pos_x = oi->pos_x;
2336 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2337 unsigned long lclk = dispc_mgr_lclk_rate(channel);
2338
2339 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2340 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
2341
2342 if (ilace && oi->height == out_height)
2343 fieldmode = 1;
2344
2345 if (ilace) {
2346 if (fieldmode)
2347 in_height /= 2;
2348 out_height /= 2;
2349
2350 DSSDBG("adjusting for ilace: height %d, out_height %d\n",
2351 in_height, out_height);
2352 }
2353
2354 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
2355 return -EINVAL;
2356
2357 return dispc_ovl_calc_scaling(pclk, lclk, caps, timings, in_width,
2358 in_height, out_width, out_height, oi->color_mode,
2359 &five_taps, x_predecim, y_predecim, pos_x,
2360 oi->rotation_type, false);
2361}
2362
Archit Taneja84a880f2012-09-26 16:57:37 +05302363static int dispc_ovl_setup_common(enum omap_plane plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302364 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2365 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2366 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2367 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2368 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
Archit Taneja8ba85302012-09-26 17:00:37 +05302369 bool replication, const struct omap_video_timings *mgr_timings,
2370 bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002371{
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302372 bool five_taps = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002373 bool fieldmode = 0;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302374 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002375 unsigned offset0, offset1;
2376 s32 row_inc;
2377 s32 pix_inc;
Archit Taneja6be0d732012-11-07 11:45:04 +05302378 u16 frame_width, frame_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002379 unsigned int field_offset = 0;
Archit Taneja84a880f2012-09-26 16:57:37 +05302380 u16 in_height = height;
2381 u16 in_width = width;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302382 int x_predecim = 1, y_predecim = 1;
Archit Taneja8050cbe2012-06-06 16:25:52 +05302383 bool ilace = mgr_timings->interlace;
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002384 unsigned long pclk = dispc_plane_pclk_rate(plane);
2385 unsigned long lclk = dispc_plane_lclk_rate(plane);
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002386
Archit Taneja84a880f2012-09-26 16:57:37 +05302387 if (paddr == 0)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002388 return -EINVAL;
2389
Archit Taneja84a880f2012-09-26 16:57:37 +05302390 out_width = out_width == 0 ? width : out_width;
2391 out_height = out_height == 0 ? height : out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002392
Archit Taneja84a880f2012-09-26 16:57:37 +05302393 if (ilace && height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002394 fieldmode = 1;
2395
2396 if (ilace) {
2397 if (fieldmode)
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302398 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302399 pos_y /= 2;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302400 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002401
2402 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
Archit Taneja84a880f2012-09-26 16:57:37 +05302403 "out_height %d\n", in_height, pos_y,
2404 out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002405 }
2406
Archit Taneja84a880f2012-09-26 16:57:37 +05302407 if (!dss_feat_color_mode_supported(plane, color_mode))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302408 return -EINVAL;
2409
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002410 r = dispc_ovl_calc_scaling(pclk, lclk, caps, mgr_timings, in_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302411 in_height, out_width, out_height, color_mode,
2412 &five_taps, &x_predecim, &y_predecim, pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302413 rotation_type, mem_to_mem);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302414 if (r)
2415 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002416
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302417 in_width = DIV_ROUND_UP(in_width, x_predecim);
2418 in_height = DIV_ROUND_UP(in_height, y_predecim);
2419
Archit Taneja84a880f2012-09-26 16:57:37 +05302420 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2421 color_mode == OMAP_DSS_COLOR_UYVY ||
2422 color_mode == OMAP_DSS_COLOR_NV12)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302423 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002424
2425 if (ilace && !fieldmode) {
2426 /*
2427 * when downscaling the bottom field may have to start several
2428 * source lines below the top field. Unfortunately ACCUI
2429 * registers will only hold the fractional part of the offset
2430 * so the integer part must be added to the base address of the
2431 * bottom field.
2432 */
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302433 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002434 field_offset = 0;
2435 else
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302436 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002437 }
2438
2439 /* Fields are independent but interleaved in memory. */
2440 if (fieldmode)
2441 field_offset = 1;
2442
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002443 offset0 = 0;
2444 offset1 = 0;
2445 row_inc = 0;
2446 pix_inc = 0;
2447
Archit Taneja6be0d732012-11-07 11:45:04 +05302448 if (plane == OMAP_DSS_WB) {
2449 frame_width = out_width;
2450 frame_height = out_height;
2451 } else {
2452 frame_width = in_width;
2453 frame_height = height;
2454 }
2455
Archit Taneja84a880f2012-09-26 16:57:37 +05302456 if (rotation_type == OMAP_DSS_ROT_TILER)
Archit Taneja6be0d732012-11-07 11:45:04 +05302457 calc_tiler_rotation_offset(screen_width, frame_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302458 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302459 &offset0, &offset1, &row_inc, &pix_inc,
2460 x_predecim, y_predecim);
Archit Taneja84a880f2012-09-26 16:57:37 +05302461 else if (rotation_type == OMAP_DSS_ROT_DMA)
Archit Taneja6be0d732012-11-07 11:45:04 +05302462 calc_dma_rotation_offset(rotation, mirror, screen_width,
2463 frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302464 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302465 &offset0, &offset1, &row_inc, &pix_inc,
2466 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002467 else
Archit Taneja84a880f2012-09-26 16:57:37 +05302468 calc_vrfb_rotation_offset(rotation, mirror,
Archit Taneja6be0d732012-11-07 11:45:04 +05302469 screen_width, frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302470 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302471 &offset0, &offset1, &row_inc, &pix_inc,
2472 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002473
2474 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2475 offset0, offset1, row_inc, pix_inc);
2476
Archit Taneja84a880f2012-09-26 16:57:37 +05302477 dispc_ovl_set_color_mode(plane, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002478
Archit Taneja84a880f2012-09-26 16:57:37 +05302479 dispc_ovl_configure_burst_type(plane, rotation_type);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302480
Archit Taneja84a880f2012-09-26 16:57:37 +05302481 dispc_ovl_set_ba0(plane, paddr + offset0);
2482 dispc_ovl_set_ba1(plane, paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002483
Archit Taneja84a880f2012-09-26 16:57:37 +05302484 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2485 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2486 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302487 }
2488
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002489 dispc_ovl_set_row_inc(plane, row_inc);
2490 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002491
Archit Taneja84a880f2012-09-26 16:57:37 +05302492 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302493 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002494
Archit Taneja84a880f2012-09-26 16:57:37 +05302495 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002496
Archit Taneja78b687f2012-09-21 14:51:49 +05302497 dispc_ovl_set_input_size(plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002498
Archit Taneja5b54ed32012-09-26 16:55:27 +05302499 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302500 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2501 out_height, ilace, five_taps, fieldmode,
Archit Taneja84a880f2012-09-26 16:57:37 +05302502 color_mode, rotation);
Archit Taneja78b687f2012-09-21 14:51:49 +05302503 dispc_ovl_set_output_size(plane, out_width, out_height);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002504 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002505 }
2506
Archit Taneja84a880f2012-09-26 16:57:37 +05302507 dispc_ovl_set_rotation_attrs(plane, rotation, mirror, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002508
Archit Taneja84a880f2012-09-26 16:57:37 +05302509 dispc_ovl_set_zorder(plane, caps, zorder);
2510 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2511 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002512
Archit Tanejad79db852012-09-22 12:30:17 +05302513 dispc_ovl_enable_replication(plane, caps, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302514
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002515 return 0;
2516}
2517
Archit Taneja84a880f2012-09-26 16:57:37 +05302518int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
Archit Taneja8ba85302012-09-26 17:00:37 +05302519 bool replication, const struct omap_video_timings *mgr_timings,
2520 bool mem_to_mem)
Archit Taneja84a880f2012-09-26 16:57:37 +05302521{
2522 int r;
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002523 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
Archit Taneja84a880f2012-09-26 16:57:37 +05302524 enum omap_channel channel;
2525
2526 channel = dispc_ovl_get_channel_out(plane);
2527
2528 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
2529 "%dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2530 plane, oi->paddr, oi->p_uv_addr, oi->screen_width, oi->pos_x,
2531 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2532 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2533
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002534 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302535 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2536 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2537 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
Archit Taneja8ba85302012-09-26 17:00:37 +05302538 oi->rotation_type, replication, mgr_timings, mem_to_mem);
Archit Taneja84a880f2012-09-26 16:57:37 +05302539
2540 return r;
2541}
2542
Archit Taneja749feff2012-08-31 12:32:52 +05302543int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302544 bool mem_to_mem, const struct omap_video_timings *mgr_timings)
Archit Taneja749feff2012-08-31 12:32:52 +05302545{
2546 int r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302547 u32 l;
Archit Taneja749feff2012-08-31 12:32:52 +05302548 enum omap_plane plane = OMAP_DSS_WB;
2549 const int pos_x = 0, pos_y = 0;
2550 const u8 zorder = 0, global_alpha = 0;
2551 const bool replication = false;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302552 bool truncation;
Archit Taneja749feff2012-08-31 12:32:52 +05302553 int in_width = mgr_timings->x_res;
2554 int in_height = mgr_timings->y_res;
2555 enum omap_overlay_caps caps =
2556 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2557
2558 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2559 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2560 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2561 wi->mirror);
2562
2563 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2564 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2565 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2566 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302567 replication, mgr_timings, mem_to_mem);
2568
2569 switch (wi->color_mode) {
2570 case OMAP_DSS_COLOR_RGB16:
2571 case OMAP_DSS_COLOR_RGB24P:
2572 case OMAP_DSS_COLOR_ARGB16:
2573 case OMAP_DSS_COLOR_RGBA16:
2574 case OMAP_DSS_COLOR_RGB12U:
2575 case OMAP_DSS_COLOR_ARGB16_1555:
2576 case OMAP_DSS_COLOR_XRGB16_1555:
2577 case OMAP_DSS_COLOR_RGBX16:
2578 truncation = true;
2579 break;
2580 default:
2581 truncation = false;
2582 break;
2583 }
2584
2585 /* setup extra DISPC_WB_ATTRIBUTES */
2586 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2587 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2588 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2589 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Archit Taneja749feff2012-08-31 12:32:52 +05302590
2591 return r;
2592}
2593
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002594int dispc_ovl_enable(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002595{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002596 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2597
Archit Taneja9b372c22011-05-06 11:45:49 +05302598 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002599
2600 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002601}
2602
Tomi Valkeinen04bd8ac2012-10-10 14:13:15 +03002603bool dispc_ovl_enabled(enum omap_plane plane)
2604{
2605 return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2606}
2607
Tomi Valkeinenf1a813d2012-10-19 14:16:06 +03002608void dispc_mgr_enable(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002609{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302610 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2611 /* flush posted write */
2612 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002613}
2614
Tomi Valkeinen65398512012-10-10 11:44:17 +03002615bool dispc_mgr_is_enabled(enum omap_channel channel)
2616{
2617 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2618}
2619
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302620void dispc_wb_enable(bool enable)
2621{
Tomi Valkeinen916188a2012-10-10 14:13:26 +03002622 dispc_ovl_enable(OMAP_DSS_WB, enable);
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302623}
2624
2625bool dispc_wb_is_enabled(void)
2626{
Tomi Valkeinen916188a2012-10-10 14:13:26 +03002627 return dispc_ovl_enabled(OMAP_DSS_WB);
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302628}
2629
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002630static void dispc_lcd_enable_signal_polarity(bool act_high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002631{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002632 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2633 return;
2634
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002635 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002636}
2637
2638void dispc_lcd_enable_signal(bool enable)
2639{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002640 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2641 return;
2642
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002643 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002644}
2645
2646void dispc_pck_free_enable(bool enable)
2647{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002648 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2649 return;
2650
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002651 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002652}
2653
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002654static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002655{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302656 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002657}
2658
2659
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002660static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002661{
Archit Tanejad21f43b2012-06-21 09:45:11 +05302662 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002663}
2664
2665void dispc_set_loadmode(enum omap_dss_load_mode mode)
2666{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002667 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002668}
2669
2670
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002671static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002672{
Sumit Semwal8613b002010-12-02 11:27:09 +00002673 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002674}
2675
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002676static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002677 enum omap_dss_trans_key_type type,
2678 u32 trans_key)
2679{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302680 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002681
Sumit Semwal8613b002010-12-02 11:27:09 +00002682 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002683}
2684
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002685static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002686{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302687 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002688}
Archit Taneja11354dd2011-09-26 11:47:29 +05302689
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002690static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2691 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002692{
Archit Taneja11354dd2011-09-26 11:47:29 +05302693 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002694 return;
2695
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002696 if (ch == OMAP_DSS_CHANNEL_LCD)
2697 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002698 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002699 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002700}
Archit Taneja11354dd2011-09-26 11:47:29 +05302701
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002702void dispc_mgr_setup(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02002703 const struct omap_overlay_manager_info *info)
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002704{
2705 dispc_mgr_set_default_color(channel, info->default_color);
2706 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2707 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2708 dispc_mgr_enable_alpha_fixed_zorder(channel,
2709 info->partial_alpha_enabled);
2710 if (dss_has_feature(FEAT_CPR)) {
2711 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2712 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2713 }
2714}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002715
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002716static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002717{
2718 int code;
2719
2720 switch (data_lines) {
2721 case 12:
2722 code = 0;
2723 break;
2724 case 16:
2725 code = 1;
2726 break;
2727 case 18:
2728 code = 2;
2729 break;
2730 case 24:
2731 code = 3;
2732 break;
2733 default:
2734 BUG();
2735 return;
2736 }
2737
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302738 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002739}
2740
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002741static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002742{
2743 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302744 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002745
2746 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302747 case DSS_IO_PAD_MODE_RESET:
2748 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002749 gpout1 = 0;
2750 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302751 case DSS_IO_PAD_MODE_RFBI:
2752 gpout0 = 1;
2753 gpout1 = 0;
2754 break;
2755 case DSS_IO_PAD_MODE_BYPASS:
2756 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002757 gpout1 = 1;
2758 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002759 default:
2760 BUG();
2761 return;
2762 }
2763
Archit Taneja569969d2011-08-22 17:41:57 +05302764 l = dispc_read_reg(DISPC_CONTROL);
2765 l = FLD_MOD(l, gpout0, 15, 15);
2766 l = FLD_MOD(l, gpout1, 16, 16);
2767 dispc_write_reg(DISPC_CONTROL, l);
2768}
2769
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002770static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
Archit Taneja569969d2011-08-22 17:41:57 +05302771{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302772 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002773}
2774
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002775void dispc_mgr_set_lcd_config(enum omap_channel channel,
2776 const struct dss_lcd_mgr_config *config)
2777{
2778 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
2779
2780 dispc_mgr_enable_stallmode(channel, config->stallmode);
2781 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
2782
2783 dispc_mgr_set_clock_div(channel, &config->clock_info);
2784
2785 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
2786
2787 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
2788
2789 dispc_mgr_set_lcd_type_tft(channel);
2790}
2791
Archit Taneja8f366162012-04-16 12:53:44 +05302792static bool _dispc_mgr_size_ok(u16 width, u16 height)
2793{
Archit Taneja33b89922012-11-14 13:50:15 +05302794 return width <= dispc.feat->mgr_width_max &&
2795 height <= dispc.feat->mgr_height_max;
Archit Taneja8f366162012-04-16 12:53:44 +05302796}
2797
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002798static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2799 int vsw, int vfp, int vbp)
2800{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302801 if (hsw < 1 || hsw > dispc.feat->sw_max ||
2802 hfp < 1 || hfp > dispc.feat->hp_max ||
2803 hbp < 1 || hbp > dispc.feat->hp_max ||
2804 vsw < 1 || vsw > dispc.feat->sw_max ||
2805 vfp < 0 || vfp > dispc.feat->vp_max ||
2806 vbp < 0 || vbp > dispc.feat->vp_max)
2807 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002808 return true;
2809}
2810
Archit Taneja8f366162012-04-16 12:53:44 +05302811bool dispc_mgr_timings_ok(enum omap_channel channel,
Archit Tanejab917fa32012-04-27 01:07:28 +05302812 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002813{
Archit Taneja8f366162012-04-16 12:53:44 +05302814 bool timings_ok;
2815
2816 timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
2817
Archit Tanejadd88b7a2012-06-29 14:41:30 +05302818 if (dss_mgr_is_lcd(channel))
Archit Taneja8f366162012-04-16 12:53:44 +05302819 timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
2820 timings->hfp, timings->hbp,
2821 timings->vsw, timings->vfp,
2822 timings->vbp);
2823
2824 return timings_ok;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002825}
2826
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002827static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
Archit Taneja655e2942012-06-21 10:37:43 +05302828 int hfp, int hbp, int vsw, int vfp, int vbp,
2829 enum omap_dss_signal_level vsync_level,
2830 enum omap_dss_signal_level hsync_level,
2831 enum omap_dss_signal_edge data_pclk_edge,
2832 enum omap_dss_signal_level de_level,
2833 enum omap_dss_signal_edge sync_pclk_edge)
2834
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002835{
Archit Taneja655e2942012-06-21 10:37:43 +05302836 u32 timing_h, timing_v, l;
2837 bool onoff, rf, ipc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002838
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302839 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
2840 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
2841 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
2842 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
2843 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
2844 FLD_VAL(vbp, dispc.feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002845
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002846 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2847 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05302848
2849 switch (data_pclk_edge) {
2850 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2851 ipc = false;
2852 break;
2853 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2854 ipc = true;
2855 break;
2856 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2857 default:
2858 BUG();
2859 }
2860
2861 switch (sync_pclk_edge) {
2862 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2863 onoff = false;
2864 rf = false;
2865 break;
2866 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2867 onoff = true;
2868 rf = false;
2869 break;
2870 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2871 onoff = true;
2872 rf = true;
2873 break;
2874 default:
2875 BUG();
2876 };
2877
2878 l = dispc_read_reg(DISPC_POL_FREQ(channel));
2879 l |= FLD_VAL(onoff, 17, 17);
2880 l |= FLD_VAL(rf, 16, 16);
2881 l |= FLD_VAL(de_level, 15, 15);
2882 l |= FLD_VAL(ipc, 14, 14);
2883 l |= FLD_VAL(hsync_level, 13, 13);
2884 l |= FLD_VAL(vsync_level, 12, 12);
2885 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002886}
2887
2888/* change name to mode? */
Archit Tanejac51d9212012-04-16 12:53:43 +05302889void dispc_mgr_set_timings(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02002890 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002891{
2892 unsigned xtot, ytot;
2893 unsigned long ht, vt;
Archit Taneja2aefad42012-05-18 14:36:54 +05302894 struct omap_video_timings t = *timings;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002895
Archit Taneja2aefad42012-05-18 14:36:54 +05302896 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
Archit Tanejac51d9212012-04-16 12:53:43 +05302897
Archit Taneja2aefad42012-05-18 14:36:54 +05302898 if (!dispc_mgr_timings_ok(channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05302899 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002900 return;
2901 }
Archit Tanejac51d9212012-04-16 12:53:43 +05302902
Archit Tanejadd88b7a2012-06-29 14:41:30 +05302903 if (dss_mgr_is_lcd(channel)) {
Archit Taneja2aefad42012-05-18 14:36:54 +05302904 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
Archit Taneja655e2942012-06-21 10:37:43 +05302905 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
2906 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
Archit Tanejac51d9212012-04-16 12:53:43 +05302907
Archit Taneja2aefad42012-05-18 14:36:54 +05302908 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
2909 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
Archit Tanejac51d9212012-04-16 12:53:43 +05302910
2911 ht = (timings->pixel_clock * 1000) / xtot;
2912 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2913
2914 DSSDBG("pck %u\n", timings->pixel_clock);
2915 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Archit Taneja2aefad42012-05-18 14:36:54 +05302916 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
Archit Taneja655e2942012-06-21 10:37:43 +05302917 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
2918 t.vsync_level, t.hsync_level, t.data_pclk_edge,
2919 t.de_level, t.sync_pclk_edge);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002920
Archit Tanejac51d9212012-04-16 12:53:43 +05302921 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05302922 } else {
Archit Taneja23c8f882012-06-28 11:15:51 +05302923 if (t.interlace == true)
Archit Taneja2aefad42012-05-18 14:36:54 +05302924 t.y_res /= 2;
Archit Tanejac51d9212012-04-16 12:53:43 +05302925 }
Archit Taneja8f366162012-04-16 12:53:44 +05302926
Archit Taneja2aefad42012-05-18 14:36:54 +05302927 dispc_mgr_set_size(channel, t.x_res, t.y_res);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002928}
2929
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002930static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002931 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002932{
2933 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03002934 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002935
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06002936 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002937 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002938}
2939
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002940static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00002941 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002942{
2943 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06002944 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002945 *lck_div = FLD_GET(l, 23, 16);
2946 *pck_div = FLD_GET(l, 7, 0);
2947}
2948
2949unsigned long dispc_fclk_rate(void)
2950{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302951 struct platform_device *dsidev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002952 unsigned long r = 0;
2953
Taneja, Archit66534e82011-03-08 05:50:34 -06002954 switch (dss_get_dispc_clk_source()) {
Archit Taneja89a35e52011-04-12 13:52:23 +05302955 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002956 r = clk_get_rate(dispc.dss_clk);
Taneja, Archit66534e82011-03-08 05:50:34 -06002957 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05302958 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302959 dsidev = dsi_get_dsidev_from_id(0);
2960 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
Taneja, Archit66534e82011-03-08 05:50:34 -06002961 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05302962 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2963 dsidev = dsi_get_dsidev_from_id(1);
2964 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2965 break;
Taneja, Archit66534e82011-03-08 05:50:34 -06002966 default:
2967 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002968 return 0;
Taneja, Archit66534e82011-03-08 05:50:34 -06002969 }
2970
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002971 return r;
2972}
2973
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002974unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002975{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302976 struct platform_device *dsidev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002977 int lcd;
2978 unsigned long r;
2979 u32 l;
2980
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03002981 if (dss_mgr_is_lcd(channel)) {
2982 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002983
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03002984 lcd = FLD_GET(l, 23, 16);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002985
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03002986 switch (dss_get_lcd_clk_source(channel)) {
2987 case OMAP_DSS_CLK_SRC_FCK:
2988 r = clk_get_rate(dispc.dss_clk);
2989 break;
2990 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2991 dsidev = dsi_get_dsidev_from_id(0);
2992 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2993 break;
2994 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2995 dsidev = dsi_get_dsidev_from_id(1);
2996 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2997 break;
2998 default:
2999 BUG();
3000 return 0;
3001 }
3002
3003 return r / lcd;
3004 } else {
3005 return dispc_fclk_rate();
Taneja, Architea751592011-03-08 05:50:35 -06003006 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003007}
3008
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003009unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003010{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003011 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003012
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303013 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303014 int pcd;
3015 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003016
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303017 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003018
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303019 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003020
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303021 r = dispc_mgr_lclk_rate(channel);
3022
3023 return r / pcd;
3024 } else {
Archit Taneja3fa03ba2012-04-09 15:06:41 +05303025 enum dss_hdmi_venc_clk_source_select source;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303026
Archit Taneja3fa03ba2012-04-09 15:06:41 +05303027 source = dss_get_hdmi_venc_clk_source();
3028
3029 switch (source) {
3030 case DSS_VENC_TV_CLK:
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303031 return venc_get_pixel_clock();
Archit Taneja3fa03ba2012-04-09 15:06:41 +05303032 case DSS_HDMI_M_PCLK:
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303033 return hdmi_get_pixel_clock();
3034 default:
3035 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003036 return 0;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303037 }
3038 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003039}
3040
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303041unsigned long dispc_core_clk_rate(void)
3042{
3043 int lcd;
3044 unsigned long fclk = dispc_fclk_rate();
3045
3046 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3047 lcd = REG_GET(DISPC_DIVISOR, 23, 16);
3048 else
3049 lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
3050
3051 return fclk / lcd;
3052}
3053
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303054static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3055{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003056 enum omap_channel channel;
3057
3058 if (plane == OMAP_DSS_WB)
3059 return 0;
3060
3061 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303062
3063 return dispc_mgr_pclk_rate(channel);
3064}
3065
3066static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3067{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003068 enum omap_channel channel;
3069
3070 if (plane == OMAP_DSS_WB)
3071 return 0;
3072
3073 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303074
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003075 return dispc_mgr_lclk_rate(channel);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303076}
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003077
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303078static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003079{
3080 int lcd, pcd;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303081 enum omap_dss_clk_source lcd_clk_src;
3082
3083 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3084
3085 lcd_clk_src = dss_get_lcd_clk_source(channel);
3086
3087 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3088 dss_get_generic_clk_source_name(lcd_clk_src),
3089 dss_feat_get_clk_source_name(lcd_clk_src));
3090
3091 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3092
3093 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3094 dispc_mgr_lclk_rate(channel), lcd);
3095 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3096 dispc_mgr_pclk_rate(channel), pcd);
3097}
3098
3099void dispc_dump_clocks(struct seq_file *s)
3100{
3101 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003102 u32 l;
Archit Taneja89a35e52011-04-12 13:52:23 +05303103 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003104
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003105 if (dispc_runtime_get())
3106 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003107
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003108 seq_printf(s, "- DISPC -\n");
3109
Archit Taneja067a57e2011-03-02 11:57:25 +05303110 seq_printf(s, "dispc fclk source = %s (%s)\n",
3111 dss_get_generic_clk_source_name(dispc_clk_src),
3112 dss_feat_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003113
3114 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00003115
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003116 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3117 seq_printf(s, "- DISPC-CORE-CLK -\n");
3118 l = dispc_read_reg(DISPC_DIVISOR);
3119 lcd = FLD_GET(l, 23, 16);
3120
3121 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3122 (dispc_fclk_rate()/lcd), lcd);
3123 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003124
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303125 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003126
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303127 if (dss_has_feature(FEAT_MGR_LCD2))
3128 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3129 if (dss_has_feature(FEAT_MGR_LCD3))
3130 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003131
3132 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003133}
3134
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003135static void dispc_dump_regs(struct seq_file *s)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003136{
Archit Taneja4dd2da12011-08-05 19:06:01 +05303137 int i, j;
3138 const char *mgr_names[] = {
3139 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3140 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3141 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303142 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303143 };
3144 const char *ovl_names[] = {
3145 [OMAP_DSS_GFX] = "GFX",
3146 [OMAP_DSS_VIDEO1] = "VID1",
3147 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303148 [OMAP_DSS_VIDEO3] = "VID3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303149 };
3150 const char **p_names;
3151
Archit Taneja9b372c22011-05-06 11:45:49 +05303152#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003153
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003154 if (dispc_runtime_get())
3155 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003156
Archit Taneja5010be82011-08-05 19:06:00 +05303157 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003158 DUMPREG(DISPC_REVISION);
3159 DUMPREG(DISPC_SYSCONFIG);
3160 DUMPREG(DISPC_SYSSTATUS);
3161 DUMPREG(DISPC_IRQSTATUS);
3162 DUMPREG(DISPC_IRQENABLE);
3163 DUMPREG(DISPC_CONTROL);
3164 DUMPREG(DISPC_CONFIG);
3165 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003166 DUMPREG(DISPC_LINE_STATUS);
3167 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05303168 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3169 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003170 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003171 if (dss_has_feature(FEAT_MGR_LCD2)) {
3172 DUMPREG(DISPC_CONTROL2);
3173 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003174 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303175 if (dss_has_feature(FEAT_MGR_LCD3)) {
3176 DUMPREG(DISPC_CONTROL3);
3177 DUMPREG(DISPC_CONFIG3);
3178 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003179
Archit Taneja5010be82011-08-05 19:06:00 +05303180#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003181
Archit Taneja5010be82011-08-05 19:06:00 +05303182#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05303183#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003184 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303185 dispc_read_reg(DISPC_REG(i, r)))
3186
Archit Taneja4dd2da12011-08-05 19:06:01 +05303187 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303188
Archit Taneja4dd2da12011-08-05 19:06:01 +05303189 /* DISPC channel specific registers */
3190 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3191 DUMPREG(i, DISPC_DEFAULT_COLOR);
3192 DUMPREG(i, DISPC_TRANS_COLOR);
3193 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003194
Archit Taneja4dd2da12011-08-05 19:06:01 +05303195 if (i == OMAP_DSS_CHANNEL_DIGIT)
3196 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303197
Archit Taneja4dd2da12011-08-05 19:06:01 +05303198 DUMPREG(i, DISPC_DEFAULT_COLOR);
3199 DUMPREG(i, DISPC_TRANS_COLOR);
3200 DUMPREG(i, DISPC_TIMING_H);
3201 DUMPREG(i, DISPC_TIMING_V);
3202 DUMPREG(i, DISPC_POL_FREQ);
3203 DUMPREG(i, DISPC_DIVISORo);
3204 DUMPREG(i, DISPC_SIZE_MGR);
Archit Taneja5010be82011-08-05 19:06:00 +05303205
Archit Taneja4dd2da12011-08-05 19:06:01 +05303206 DUMPREG(i, DISPC_DATA_CYCLE1);
3207 DUMPREG(i, DISPC_DATA_CYCLE2);
3208 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003209
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003210 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303211 DUMPREG(i, DISPC_CPR_COEF_R);
3212 DUMPREG(i, DISPC_CPR_COEF_G);
3213 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003214 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003215 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003216
Archit Taneja4dd2da12011-08-05 19:06:01 +05303217 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003218
Archit Taneja4dd2da12011-08-05 19:06:01 +05303219 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3220 DUMPREG(i, DISPC_OVL_BA0);
3221 DUMPREG(i, DISPC_OVL_BA1);
3222 DUMPREG(i, DISPC_OVL_POSITION);
3223 DUMPREG(i, DISPC_OVL_SIZE);
3224 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3225 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3226 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3227 DUMPREG(i, DISPC_OVL_ROW_INC);
3228 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3229 if (dss_has_feature(FEAT_PRELOAD))
3230 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003231
Archit Taneja4dd2da12011-08-05 19:06:01 +05303232 if (i == OMAP_DSS_GFX) {
3233 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3234 DUMPREG(i, DISPC_OVL_TABLE_BA);
3235 continue;
3236 }
3237
3238 DUMPREG(i, DISPC_OVL_FIR);
3239 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3240 DUMPREG(i, DISPC_OVL_ACCU0);
3241 DUMPREG(i, DISPC_OVL_ACCU1);
3242 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3243 DUMPREG(i, DISPC_OVL_BA0_UV);
3244 DUMPREG(i, DISPC_OVL_BA1_UV);
3245 DUMPREG(i, DISPC_OVL_FIR2);
3246 DUMPREG(i, DISPC_OVL_ACCU2_0);
3247 DUMPREG(i, DISPC_OVL_ACCU2_1);
3248 }
3249 if (dss_has_feature(FEAT_ATTR2))
3250 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3251 if (dss_has_feature(FEAT_PRELOAD))
3252 DUMPREG(i, DISPC_OVL_PRELOAD);
Archit Taneja5010be82011-08-05 19:06:00 +05303253 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003254
Archit Taneja5010be82011-08-05 19:06:00 +05303255#undef DISPC_REG
3256#undef DUMPREG
3257
3258#define DISPC_REG(plane, name, i) name(plane, i)
3259#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303260 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003261 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303262 dispc_read_reg(DISPC_REG(plane, name, i)))
3263
Archit Taneja4dd2da12011-08-05 19:06:01 +05303264 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303265
Archit Taneja4dd2da12011-08-05 19:06:01 +05303266 /* start from OMAP_DSS_VIDEO1 */
3267 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3268 for (j = 0; j < 8; j++)
3269 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303270
Archit Taneja4dd2da12011-08-05 19:06:01 +05303271 for (j = 0; j < 8; j++)
3272 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303273
Archit Taneja4dd2da12011-08-05 19:06:01 +05303274 for (j = 0; j < 5; j++)
3275 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003276
Archit Taneja4dd2da12011-08-05 19:06:01 +05303277 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3278 for (j = 0; j < 8; j++)
3279 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3280 }
Amber Jainab5ca072011-05-19 19:47:53 +05303281
Archit Taneja4dd2da12011-08-05 19:06:01 +05303282 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3283 for (j = 0; j < 8; j++)
3284 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303285
Archit Taneja4dd2da12011-08-05 19:06:01 +05303286 for (j = 0; j < 8; j++)
3287 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303288
Archit Taneja4dd2da12011-08-05 19:06:01 +05303289 for (j = 0; j < 8; j++)
3290 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3291 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003292 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003293
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003294 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05303295
3296#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003297#undef DUMPREG
3298}
3299
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003300/* with fck as input clock rate, find dispc dividers that produce req_pck */
Archit Taneja6d523e72012-06-21 09:33:55 +05303301void dispc_find_clk_divs(unsigned long req_pck, unsigned long fck,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003302 struct dispc_clock_info *cinfo)
3303{
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003304 u16 pcd_min, pcd_max;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003305 unsigned long best_pck;
3306 u16 best_ld, cur_ld;
3307 u16 best_pd, cur_pd;
3308
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003309 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3310 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3311
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003312 best_pck = 0;
3313 best_ld = 0;
3314 best_pd = 0;
3315
3316 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
3317 unsigned long lck = fck / cur_ld;
3318
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003319 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003320 unsigned long pck = lck / cur_pd;
3321 long old_delta = abs(best_pck - req_pck);
3322 long new_delta = abs(pck - req_pck);
3323
3324 if (best_pck == 0 || new_delta < old_delta) {
3325 best_pck = pck;
3326 best_ld = cur_ld;
3327 best_pd = cur_pd;
3328
3329 if (pck == req_pck)
3330 goto found;
3331 }
3332
3333 if (pck < req_pck)
3334 break;
3335 }
3336
3337 if (lck / pcd_min < req_pck)
3338 break;
3339 }
3340
3341found:
3342 cinfo->lck_div = best_ld;
3343 cinfo->pck_div = best_pd;
3344 cinfo->lck = fck / cinfo->lck_div;
3345 cinfo->pck = cinfo->lck / cinfo->pck_div;
3346}
3347
3348/* calculate clock rates using dividers in cinfo */
3349int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3350 struct dispc_clock_info *cinfo)
3351{
3352 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3353 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003354 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003355 return -EINVAL;
3356
3357 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3358 cinfo->pck = cinfo->lck / cinfo->pck_div;
3359
3360 return 0;
3361}
3362
Archit Tanejaf0d08f82012-06-29 14:00:54 +05303363void dispc_mgr_set_clock_div(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003364 const struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003365{
3366 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3367 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3368
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003369 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003370}
3371
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003372int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003373 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003374{
3375 unsigned long fck;
3376
3377 fck = dispc_fclk_rate();
3378
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003379 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3380 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003381
3382 cinfo->lck = fck / cinfo->lck_div;
3383 cinfo->pck = cinfo->lck / cinfo->pck_div;
3384
3385 return 0;
3386}
3387
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003388u32 dispc_read_irqstatus(void)
3389{
3390 return dispc_read_reg(DISPC_IRQSTATUS);
3391}
3392
3393void dispc_clear_irqstatus(u32 mask)
3394{
3395 dispc_write_reg(DISPC_IRQSTATUS, mask);
3396}
3397
3398u32 dispc_read_irqenable(void)
3399{
3400 return dispc_read_reg(DISPC_IRQENABLE);
3401}
3402
3403void dispc_write_irqenable(u32 mask)
3404{
3405 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3406
3407 /* clear the irqstatus for newly enabled irqs */
3408 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3409
3410 dispc_write_reg(DISPC_IRQENABLE, mask);
3411}
3412
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003413void dispc_enable_sidle(void)
3414{
3415 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3416}
3417
3418void dispc_disable_sidle(void)
3419{
3420 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3421}
3422
3423static void _omap_dispc_initial_config(void)
3424{
3425 u32 l;
3426
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003427 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3428 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3429 l = dispc_read_reg(DISPC_DIVISOR);
3430 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3431 l = FLD_MOD(l, 1, 0, 0);
3432 l = FLD_MOD(l, 1, 23, 16);
3433 dispc_write_reg(DISPC_DIVISOR, l);
3434 }
3435
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003436 /* FUNCGATED */
Archit Taneja6ced40b2010-12-02 11:27:13 +00003437 if (dss_has_feature(FEAT_FUNCGATED))
3438 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003439
Archit Taneja6e5264b2012-09-11 12:04:47 +05303440 dispc_setup_color_conv_coef();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003441
3442 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3443
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003444 dispc_init_fifos();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003445
3446 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05303447
3448 dispc_ovl_enable_zorder_planes();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003449}
3450
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303451static const struct dispc_features omap24xx_dispc_feats __initconst = {
3452 .sw_start = 5,
3453 .fp_start = 15,
3454 .bp_start = 27,
3455 .sw_max = 64,
3456 .vp_max = 255,
3457 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303458 .mgr_width_start = 10,
3459 .mgr_height_start = 26,
3460 .mgr_width_max = 2048,
3461 .mgr_height_max = 2048,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303462 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3463 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003464 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003465 .no_framedone_tv = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303466};
3467
3468static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
3469 .sw_start = 5,
3470 .fp_start = 15,
3471 .bp_start = 27,
3472 .sw_max = 64,
3473 .vp_max = 255,
3474 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303475 .mgr_width_start = 10,
3476 .mgr_height_start = 26,
3477 .mgr_width_max = 2048,
3478 .mgr_height_max = 2048,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303479 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3480 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003481 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003482 .no_framedone_tv = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303483};
3484
3485static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
3486 .sw_start = 7,
3487 .fp_start = 19,
3488 .bp_start = 31,
3489 .sw_max = 256,
3490 .vp_max = 4095,
3491 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303492 .mgr_width_start = 10,
3493 .mgr_height_start = 26,
3494 .mgr_width_max = 2048,
3495 .mgr_height_max = 2048,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303496 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3497 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003498 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003499 .no_framedone_tv = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303500};
3501
3502static const struct dispc_features omap44xx_dispc_feats __initconst = {
3503 .sw_start = 7,
3504 .fp_start = 19,
3505 .bp_start = 31,
3506 .sw_max = 256,
3507 .vp_max = 4095,
3508 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303509 .mgr_width_start = 10,
3510 .mgr_height_start = 26,
3511 .mgr_width_max = 2048,
3512 .mgr_height_max = 2048,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303513 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3514 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003515 .num_fifos = 5,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03003516 .gfx_fifo_workaround = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303517};
3518
Archit Taneja264236f2012-11-14 13:50:16 +05303519static const struct dispc_features omap54xx_dispc_feats __initconst = {
3520 .sw_start = 7,
3521 .fp_start = 19,
3522 .bp_start = 31,
3523 .sw_max = 256,
3524 .vp_max = 4095,
3525 .hp_max = 4096,
3526 .mgr_width_start = 11,
3527 .mgr_height_start = 27,
3528 .mgr_width_max = 4096,
3529 .mgr_height_max = 4096,
3530 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3531 .calc_core_clk = calc_core_clk_44xx,
3532 .num_fifos = 5,
3533 .gfx_fifo_workaround = true,
3534};
3535
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003536static int __init dispc_init_features(struct platform_device *pdev)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303537{
3538 const struct dispc_features *src;
3539 struct dispc_features *dst;
3540
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003541 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303542 if (!dst) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003543 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303544 return -ENOMEM;
3545 }
3546
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +03003547 switch (omapdss_get_version()) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003548 case OMAPDSS_VER_OMAP24xx:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303549 src = &omap24xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003550 break;
3551
3552 case OMAPDSS_VER_OMAP34xx_ES1:
3553 src = &omap34xx_rev1_0_dispc_feats;
3554 break;
3555
3556 case OMAPDSS_VER_OMAP34xx_ES3:
3557 case OMAPDSS_VER_OMAP3630:
3558 case OMAPDSS_VER_AM35xx:
3559 src = &omap34xx_rev3_0_dispc_feats;
3560 break;
3561
3562 case OMAPDSS_VER_OMAP4430_ES1:
3563 case OMAPDSS_VER_OMAP4430_ES2:
3564 case OMAPDSS_VER_OMAP4:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303565 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003566 break;
3567
3568 case OMAPDSS_VER_OMAP5:
Archit Taneja264236f2012-11-14 13:50:16 +05303569 src = &omap54xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003570 break;
3571
3572 default:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303573 return -ENODEV;
3574 }
3575
3576 memcpy(dst, src, sizeof(*dst));
3577 dispc.feat = dst;
3578
3579 return 0;
3580}
3581
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003582int dispc_request_irq(irq_handler_t handler, void *dev_id)
3583{
3584 return devm_request_irq(&dispc.pdev->dev, dispc.irq, handler,
3585 IRQF_SHARED, "OMAP DISPC", dev_id);
3586}
3587
3588void dispc_free_irq(void *dev_id)
3589{
3590 devm_free_irq(&dispc.pdev->dev, dispc.irq, dev_id);
3591}
3592
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003593/* DISPC HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003594static int __init omap_dispchw_probe(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003595{
3596 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00003597 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003598 struct resource *dispc_mem;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003599 struct clk *clk;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003600
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003601 dispc.pdev = pdev;
3602
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003603 r = dispc_init_features(dispc.pdev);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303604 if (r)
3605 return r;
3606
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003607 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3608 if (!dispc_mem) {
3609 DSSERR("can't get IORESOURCE_MEM DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003610 return -EINVAL;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003611 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003612
Julia Lawall6e2a14d2012-01-24 14:00:45 +01003613 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3614 resource_size(dispc_mem));
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003615 if (!dispc.base) {
3616 DSSERR("can't ioremap DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003617 return -ENOMEM;
archit tanejaaffe3602011-02-23 08:41:03 +00003618 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003619
archit tanejaaffe3602011-02-23 08:41:03 +00003620 dispc.irq = platform_get_irq(dispc.pdev, 0);
3621 if (dispc.irq < 0) {
3622 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003623 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00003624 }
3625
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003626 clk = clk_get(&pdev->dev, "fck");
3627 if (IS_ERR(clk)) {
3628 DSSERR("can't get fck\n");
3629 r = PTR_ERR(clk);
3630 return r;
3631 }
3632
3633 dispc.dss_clk = clk;
3634
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003635 pm_runtime_enable(&pdev->dev);
3636
3637 r = dispc_runtime_get();
3638 if (r)
3639 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003640
3641 _omap_dispc_initial_config();
3642
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003643 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00003644 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003645 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3646
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003647 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003648
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003649 dss_debugfs_create_file("dispc", dispc_dump_regs);
3650
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003651 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003652
3653err_runtime_get:
3654 pm_runtime_disable(&pdev->dev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003655 clk_put(dispc.dss_clk);
archit tanejaaffe3602011-02-23 08:41:03 +00003656 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003657}
3658
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003659static int __exit omap_dispchw_remove(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003660{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003661 pm_runtime_disable(&pdev->dev);
3662
3663 clk_put(dispc.dss_clk);
3664
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003665 return 0;
3666}
3667
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003668static int dispc_runtime_suspend(struct device *dev)
3669{
3670 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003671
3672 return 0;
3673}
3674
3675static int dispc_runtime_resume(struct device *dev)
3676{
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +03003677 dispc_restore_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003678
3679 return 0;
3680}
3681
3682static const struct dev_pm_ops dispc_pm_ops = {
3683 .runtime_suspend = dispc_runtime_suspend,
3684 .runtime_resume = dispc_runtime_resume,
3685};
3686
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003687static struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003688 .remove = __exit_p(omap_dispchw_remove),
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003689 .driver = {
3690 .name = "omapdss_dispc",
3691 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003692 .pm = &dispc_pm_ops,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003693 },
3694};
3695
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003696int __init dispc_init_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003697{
Tomi Valkeinen11436e12012-03-07 12:53:18 +02003698 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003699}
3700
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003701void __exit dispc_uninit_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003702{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02003703 platform_driver_unregister(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003704}