blob: 8805266a52f411b7a27f431ca7c97b26b897a8ef [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 Valkeinen0006fd62014-09-05 19:15:03 +000039#include <linux/mfd/syscon.h>
40#include <linux/regmap.h>
41#include <linux/of.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020042
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030043#include <video/omapdss.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020044
45#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053046#include "dss_features.h"
Archit Taneja9b372c22011-05-06 11:45:49 +053047#include "dispc.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020048
49/* DISPC */
Sumit Semwal8613b002010-12-02 11:27:09 +000050#define DISPC_SZ_REGS SZ_4K
Tomi Valkeinen80c39712009-11-12 11:41:42 +020051
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030052enum omap_burst_size {
53 BURST_SIZE_X2 = 0,
54 BURST_SIZE_X4 = 1,
55 BURST_SIZE_X8 = 2,
56};
57
Tomi Valkeinen80c39712009-11-12 11:41:42 +020058#define REG_GET(idx, start, end) \
59 FLD_GET(dispc_read_reg(idx), start, end)
60
61#define REG_FLD_MOD(idx, val, start, end) \
62 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
63
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053064struct dispc_features {
65 u8 sw_start;
66 u8 fp_start;
67 u8 bp_start;
68 u16 sw_max;
69 u16 vp_max;
70 u16 hp_max;
Archit Taneja33b89922012-11-14 13:50:15 +053071 u8 mgr_width_start;
72 u8 mgr_height_start;
73 u16 mgr_width_max;
74 u16 mgr_height_max;
Archit Tanejaca5ca692013-03-26 19:15:22 +053075 unsigned long max_lcd_pclk;
76 unsigned long max_tv_pclk;
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +030077 int (*calc_scaling) (unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053078 const struct omap_video_timings *mgr_timings,
79 u16 width, u16 height, u16 out_width, u16 out_height,
80 enum omap_color_mode color_mode, bool *five_taps,
81 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +053082 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
Tomi Valkeinen8702ee52012-10-19 15:36:11 +030083 unsigned long (*calc_core_clk) (unsigned long pclk,
Archit Taneja8ba85302012-09-26 17:00:37 +053084 u16 width, u16 height, u16 out_width, u16 out_height,
85 bool mem_to_mem);
Tomi Valkeinen42a69612012-08-22 16:56:57 +030086 u8 num_fifos;
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +030087
88 /* swap GFX & WB fifos */
89 bool gfx_fifo_workaround:1;
Tomi Valkeinencffa9472012-11-08 10:01:33 +020090
91 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
92 bool no_framedone_tv:1;
Archit Tanejad0df9a22013-03-26 19:15:25 +053093
94 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
95 bool mstandby_workaround:1;
Archit Taneja8bc65552013-12-17 16:40:21 +053096
97 bool set_max_preload:1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053098};
99
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300100#define DISPC_MAX_NR_FIFOS 5
101
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200102static struct {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +0000103 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200104 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300105
archit tanejaaffe3602011-02-23 08:41:03 +0000106 int irq;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300107 irq_handler_t user_handler;
108 void *user_data;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200109
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200110 unsigned long core_clk_rate;
Tomi Valkeinen5391e872013-05-16 10:44:13 +0300111 unsigned long tv_pclk_rate;
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200112
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300113 u32 fifo_size[DISPC_MAX_NR_FIFOS];
114 /* maps which plane is using a fifo. fifo-id -> plane-id */
115 int fifo_assignment[DISPC_MAX_NR_FIFOS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200116
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300117 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200118 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200119
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530120 const struct dispc_features *feat;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300121
122 bool is_enabled;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +0000123
124 struct regmap *syscon_pol;
125 u32 syscon_pol_offset;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200126} dispc;
127
Amber Jain0d66cbb2011-05-19 19:47:54 +0530128enum omap_color_component {
129 /* used for all color formats for OMAP3 and earlier
130 * and for RGB and Y color component on OMAP4
131 */
132 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
133 /* used for UV component for
134 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
135 * color formats on OMAP4
136 */
137 DISPC_COLOR_COMPONENT_UV = 1 << 1,
138};
139
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530140enum mgr_reg_fields {
141 DISPC_MGR_FLD_ENABLE,
142 DISPC_MGR_FLD_STNTFT,
143 DISPC_MGR_FLD_GO,
144 DISPC_MGR_FLD_TFTDATALINES,
145 DISPC_MGR_FLD_STALLMODE,
146 DISPC_MGR_FLD_TCKENABLE,
147 DISPC_MGR_FLD_TCKSELECTION,
148 DISPC_MGR_FLD_CPR,
149 DISPC_MGR_FLD_FIFOHANDCHECK,
150 /* used to maintain a count of the above fields */
151 DISPC_MGR_FLD_NUM,
152};
153
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300154struct dispc_reg_field {
155 u16 reg;
156 u8 high;
157 u8 low;
158};
159
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530160static const struct {
161 const char *name;
162 u32 vsync_irq;
163 u32 framedone_irq;
164 u32 sync_lost_irq;
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300165 struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530166} mgr_desc[] = {
167 [OMAP_DSS_CHANNEL_LCD] = {
168 .name = "LCD",
169 .vsync_irq = DISPC_IRQ_VSYNC,
170 .framedone_irq = DISPC_IRQ_FRAMEDONE,
171 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
172 .reg_desc = {
173 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
174 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
175 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
176 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
177 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
178 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
179 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
180 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
181 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
182 },
183 },
184 [OMAP_DSS_CHANNEL_DIGIT] = {
185 .name = "DIGIT",
186 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200187 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530188 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
189 .reg_desc = {
190 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
191 [DISPC_MGR_FLD_STNTFT] = { },
192 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
193 [DISPC_MGR_FLD_TFTDATALINES] = { },
194 [DISPC_MGR_FLD_STALLMODE] = { },
195 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
196 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
197 [DISPC_MGR_FLD_CPR] = { },
198 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
199 },
200 },
201 [OMAP_DSS_CHANNEL_LCD2] = {
202 .name = "LCD2",
203 .vsync_irq = DISPC_IRQ_VSYNC2,
204 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
205 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
206 .reg_desc = {
207 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
208 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
209 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
210 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
211 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
212 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
213 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
214 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
215 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
216 },
217 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530218 [OMAP_DSS_CHANNEL_LCD3] = {
219 .name = "LCD3",
220 .vsync_irq = DISPC_IRQ_VSYNC3,
221 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
222 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
223 .reg_desc = {
224 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
225 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
226 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
227 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
228 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
229 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
230 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
231 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
232 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
233 },
234 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530235};
236
Archit Taneja6e5264b2012-09-11 12:04:47 +0530237struct color_conv_coef {
238 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
239 int full_range;
240};
241
Archit Taneja3e8a6ff2012-09-26 16:58:52 +0530242static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
243static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200244
Archit Taneja55978cc2011-05-06 11:45:51 +0530245static inline void dispc_write_reg(const u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200246{
Archit Taneja55978cc2011-05-06 11:45:51 +0530247 __raw_writel(val, dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200248}
249
Archit Taneja55978cc2011-05-06 11:45:51 +0530250static inline u32 dispc_read_reg(const u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200251{
Archit Taneja55978cc2011-05-06 11:45:51 +0530252 return __raw_readl(dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200253}
254
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530255static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
256{
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300257 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530258 return REG_GET(rfld.reg, rfld.high, rfld.low);
259}
260
261static void mgr_fld_write(enum omap_channel channel,
262 enum mgr_reg_fields regfld, int val) {
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300263 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530264 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
265}
266
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200267#define SR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530268 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200269#define RR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530270 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200271
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300272static void dispc_save_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200273{
Archit Tanejac6104b82011-08-05 19:06:02 +0530274 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200275
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300276 DSSDBG("dispc_save_context\n");
277
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200278 SR(IRQENABLE);
279 SR(CONTROL);
280 SR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200281 SR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530282 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
283 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300284 SR(GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000285 if (dss_has_feature(FEAT_MGR_LCD2)) {
286 SR(CONTROL2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000287 SR(CONFIG2);
288 }
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530289 if (dss_has_feature(FEAT_MGR_LCD3)) {
290 SR(CONTROL3);
291 SR(CONFIG3);
292 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200293
Archit Tanejac6104b82011-08-05 19:06:02 +0530294 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
295 SR(DEFAULT_COLOR(i));
296 SR(TRANS_COLOR(i));
297 SR(SIZE_MGR(i));
298 if (i == OMAP_DSS_CHANNEL_DIGIT)
299 continue;
300 SR(TIMING_H(i));
301 SR(TIMING_V(i));
302 SR(POL_FREQ(i));
303 SR(DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200304
Archit Tanejac6104b82011-08-05 19:06:02 +0530305 SR(DATA_CYCLE1(i));
306 SR(DATA_CYCLE2(i));
307 SR(DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200308
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300309 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530310 SR(CPR_COEF_R(i));
311 SR(CPR_COEF_G(i));
312 SR(CPR_COEF_B(i));
313 }
314 }
315
316 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
317 SR(OVL_BA0(i));
318 SR(OVL_BA1(i));
319 SR(OVL_POSITION(i));
320 SR(OVL_SIZE(i));
321 SR(OVL_ATTRIBUTES(i));
322 SR(OVL_FIFO_THRESHOLD(i));
323 SR(OVL_ROW_INC(i));
324 SR(OVL_PIXEL_INC(i));
325 if (dss_has_feature(FEAT_PRELOAD))
326 SR(OVL_PRELOAD(i));
327 if (i == OMAP_DSS_GFX) {
328 SR(OVL_WINDOW_SKIP(i));
329 SR(OVL_TABLE_BA(i));
330 continue;
331 }
332 SR(OVL_FIR(i));
333 SR(OVL_PICTURE_SIZE(i));
334 SR(OVL_ACCU0(i));
335 SR(OVL_ACCU1(i));
336
337 for (j = 0; j < 8; j++)
338 SR(OVL_FIR_COEF_H(i, j));
339
340 for (j = 0; j < 8; j++)
341 SR(OVL_FIR_COEF_HV(i, j));
342
343 for (j = 0; j < 5; j++)
344 SR(OVL_CONV_COEF(i, j));
345
346 if (dss_has_feature(FEAT_FIR_COEF_V)) {
347 for (j = 0; j < 8; j++)
348 SR(OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300349 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000350
Archit Tanejac6104b82011-08-05 19:06:02 +0530351 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
352 SR(OVL_BA0_UV(i));
353 SR(OVL_BA1_UV(i));
354 SR(OVL_FIR2(i));
355 SR(OVL_ACCU2_0(i));
356 SR(OVL_ACCU2_1(i));
357
358 for (j = 0; j < 8; j++)
359 SR(OVL_FIR_COEF_H2(i, j));
360
361 for (j = 0; j < 8; j++)
362 SR(OVL_FIR_COEF_HV2(i, j));
363
364 for (j = 0; j < 8; j++)
365 SR(OVL_FIR_COEF_V2(i, j));
366 }
367 if (dss_has_feature(FEAT_ATTR2))
368 SR(OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000369 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200370
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600371 if (dss_has_feature(FEAT_CORE_CLK_DIV))
372 SR(DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300373
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300374 dispc.ctx_valid = true;
375
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200376 DSSDBG("context saved\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200377}
378
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300379static void dispc_restore_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200380{
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200381 int i, j;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300382
383 DSSDBG("dispc_restore_context\n");
384
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300385 if (!dispc.ctx_valid)
386 return;
387
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200388 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200389 /*RR(CONTROL);*/
390 RR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200391 RR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530392 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
393 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300394 RR(GLOBAL_ALPHA);
Archit Tanejac6104b82011-08-05 19:06:02 +0530395 if (dss_has_feature(FEAT_MGR_LCD2))
Sumit Semwal2a205f32010-12-02 11:27:12 +0000396 RR(CONFIG2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530397 if (dss_has_feature(FEAT_MGR_LCD3))
398 RR(CONFIG3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200399
Archit Tanejac6104b82011-08-05 19:06:02 +0530400 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
401 RR(DEFAULT_COLOR(i));
402 RR(TRANS_COLOR(i));
403 RR(SIZE_MGR(i));
404 if (i == OMAP_DSS_CHANNEL_DIGIT)
405 continue;
406 RR(TIMING_H(i));
407 RR(TIMING_V(i));
408 RR(POL_FREQ(i));
409 RR(DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530410
Archit Tanejac6104b82011-08-05 19:06:02 +0530411 RR(DATA_CYCLE1(i));
412 RR(DATA_CYCLE2(i));
413 RR(DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000414
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300415 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530416 RR(CPR_COEF_R(i));
417 RR(CPR_COEF_G(i));
418 RR(CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300419 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000420 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200421
Archit Tanejac6104b82011-08-05 19:06:02 +0530422 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
423 RR(OVL_BA0(i));
424 RR(OVL_BA1(i));
425 RR(OVL_POSITION(i));
426 RR(OVL_SIZE(i));
427 RR(OVL_ATTRIBUTES(i));
428 RR(OVL_FIFO_THRESHOLD(i));
429 RR(OVL_ROW_INC(i));
430 RR(OVL_PIXEL_INC(i));
431 if (dss_has_feature(FEAT_PRELOAD))
432 RR(OVL_PRELOAD(i));
433 if (i == OMAP_DSS_GFX) {
434 RR(OVL_WINDOW_SKIP(i));
435 RR(OVL_TABLE_BA(i));
436 continue;
437 }
438 RR(OVL_FIR(i));
439 RR(OVL_PICTURE_SIZE(i));
440 RR(OVL_ACCU0(i));
441 RR(OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200442
Archit Tanejac6104b82011-08-05 19:06:02 +0530443 for (j = 0; j < 8; j++)
444 RR(OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200445
Archit Tanejac6104b82011-08-05 19:06:02 +0530446 for (j = 0; j < 8; j++)
447 RR(OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200448
Archit Tanejac6104b82011-08-05 19:06:02 +0530449 for (j = 0; j < 5; j++)
450 RR(OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200451
Archit Tanejac6104b82011-08-05 19:06:02 +0530452 if (dss_has_feature(FEAT_FIR_COEF_V)) {
453 for (j = 0; j < 8; j++)
454 RR(OVL_FIR_COEF_V(i, j));
455 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200456
Archit Tanejac6104b82011-08-05 19:06:02 +0530457 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
458 RR(OVL_BA0_UV(i));
459 RR(OVL_BA1_UV(i));
460 RR(OVL_FIR2(i));
461 RR(OVL_ACCU2_0(i));
462 RR(OVL_ACCU2_1(i));
463
464 for (j = 0; j < 8; j++)
465 RR(OVL_FIR_COEF_H2(i, j));
466
467 for (j = 0; j < 8; j++)
468 RR(OVL_FIR_COEF_HV2(i, j));
469
470 for (j = 0; j < 8; j++)
471 RR(OVL_FIR_COEF_V2(i, j));
472 }
473 if (dss_has_feature(FEAT_ATTR2))
474 RR(OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300475 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200476
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600477 if (dss_has_feature(FEAT_CORE_CLK_DIV))
478 RR(DIVISOR);
479
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200480 /* enable last, because LCD & DIGIT enable are here */
481 RR(CONTROL);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000482 if (dss_has_feature(FEAT_MGR_LCD2))
483 RR(CONTROL2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530484 if (dss_has_feature(FEAT_MGR_LCD3))
485 RR(CONTROL3);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200486 /* clear spurious SYNC_LOST_DIGIT interrupts */
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +0300487 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200488
489 /*
490 * enable last so IRQs won't trigger before
491 * the context is fully restored
492 */
493 RR(IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300494
495 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200496}
497
498#undef SR
499#undef RR
500
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300501int dispc_runtime_get(void)
502{
503 int r;
504
505 DSSDBG("dispc_runtime_get\n");
506
507 r = pm_runtime_get_sync(&dispc.pdev->dev);
508 WARN_ON(r < 0);
509 return r < 0 ? r : 0;
510}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200511EXPORT_SYMBOL(dispc_runtime_get);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300512
513void dispc_runtime_put(void)
514{
515 int r;
516
517 DSSDBG("dispc_runtime_put\n");
518
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200519 r = pm_runtime_put_sync(&dispc.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300520 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300521}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200522EXPORT_SYMBOL(dispc_runtime_put);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300523
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200524u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
525{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530526 return mgr_desc[channel].vsync_irq;
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200527}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200528EXPORT_SYMBOL(dispc_mgr_get_vsync_irq);
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200529
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200530u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
531{
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200532 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv)
533 return 0;
534
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530535 return mgr_desc[channel].framedone_irq;
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200536}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200537EXPORT_SYMBOL(dispc_mgr_get_framedone_irq);
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200538
Tomi Valkeinencb699202012-10-17 10:38:52 +0300539u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
540{
541 return mgr_desc[channel].sync_lost_irq;
542}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200543EXPORT_SYMBOL(dispc_mgr_get_sync_lost_irq);
Tomi Valkeinencb699202012-10-17 10:38:52 +0300544
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530545u32 dispc_wb_get_framedone_irq(void)
546{
547 return DISPC_IRQ_FRAMEDONEWB;
548}
549
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300550bool dispc_mgr_go_busy(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200551{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530552 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200553}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200554EXPORT_SYMBOL(dispc_mgr_go_busy);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200555
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300556void dispc_mgr_go(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200557{
Tomi Valkeinen3c91ee82012-10-19 15:06:07 +0300558 WARN_ON(dispc_mgr_is_enabled(channel) == false);
559 WARN_ON(dispc_mgr_go_busy(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200560
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530561 DSSDBG("GO %s\n", mgr_desc[channel].name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200562
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530563 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200564}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200565EXPORT_SYMBOL(dispc_mgr_go);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200566
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530567bool dispc_wb_go_busy(void)
568{
569 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
570}
571
572void dispc_wb_go(void)
573{
574 enum omap_plane plane = OMAP_DSS_WB;
575 bool enable, go;
576
577 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
578
579 if (!enable)
580 return;
581
582 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
583 if (go) {
584 DSSERR("GO bit not down for WB\n");
585 return;
586 }
587
588 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
589}
590
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300591static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200592{
Archit Taneja9b372c22011-05-06 11:45:49 +0530593 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200594}
595
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300596static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200597{
Archit Taneja9b372c22011-05-06 11:45:49 +0530598 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200599}
600
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300601static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200602{
Archit Taneja9b372c22011-05-06 11:45:49 +0530603 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200604}
605
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300606static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530607{
608 BUG_ON(plane == OMAP_DSS_GFX);
609
610 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
611}
612
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300613static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
614 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530615{
616 BUG_ON(plane == OMAP_DSS_GFX);
617
618 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
619}
620
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300621static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530622{
623 BUG_ON(plane == OMAP_DSS_GFX);
624
625 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
626}
627
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530628static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
629 int fir_vinc, int five_taps,
630 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200631{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530632 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200633 int i;
634
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530635 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
636 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200637
638 for (i = 0; i < 8; i++) {
639 u32 h, hv;
640
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530641 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
642 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
643 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
644 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
645 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
646 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
647 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
648 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200649
Amber Jain0d66cbb2011-05-19 19:47:54 +0530650 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300651 dispc_ovl_write_firh_reg(plane, i, h);
652 dispc_ovl_write_firhv_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530653 } else {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300654 dispc_ovl_write_firh2_reg(plane, i, h);
655 dispc_ovl_write_firhv2_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530656 }
657
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200658 }
659
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200660 if (five_taps) {
661 for (i = 0; i < 8; i++) {
662 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530663 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
664 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530665 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300666 dispc_ovl_write_firv_reg(plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530667 else
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300668 dispc_ovl_write_firv2_reg(plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200669 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200670 }
671}
672
Archit Taneja6e5264b2012-09-11 12:04:47 +0530673
674static void dispc_ovl_write_color_conv_coef(enum omap_plane plane,
675 const struct color_conv_coef *ct)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200676{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200677#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
678
Archit Taneja6e5264b2012-09-11 12:04:47 +0530679 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
680 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
681 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
682 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
683 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200684
Archit Taneja6e5264b2012-09-11 12:04:47 +0530685 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200686
687#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200688}
689
Archit Taneja6e5264b2012-09-11 12:04:47 +0530690static void dispc_setup_color_conv_coef(void)
691{
692 int i;
693 int num_ovl = dss_feat_get_num_ovls();
694 int num_wb = dss_feat_get_num_wbs();
695 const struct color_conv_coef ctbl_bt601_5_ovl = {
696 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
697 };
698 const struct color_conv_coef ctbl_bt601_5_wb = {
699 66, 112, -38, 129, -94, -74, 25, -18, 112, 0,
700 };
701
702 for (i = 1; i < num_ovl; i++)
703 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
704
705 for (; i < num_wb; i++)
706 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_wb);
707}
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200708
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300709static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200710{
Archit Taneja9b372c22011-05-06 11:45:49 +0530711 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200712}
713
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300714static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200715{
Archit Taneja9b372c22011-05-06 11:45:49 +0530716 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200717}
718
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300719static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530720{
721 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
722}
723
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300724static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530725{
726 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
727}
728
Archit Tanejad79db852012-09-22 12:30:17 +0530729static void dispc_ovl_set_pos(enum omap_plane plane,
730 enum omap_overlay_caps caps, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200731{
Archit Tanejad79db852012-09-22 12:30:17 +0530732 u32 val;
733
734 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
735 return;
736
737 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530738
739 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200740}
741
Archit Taneja78b687f2012-09-21 14:51:49 +0530742static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
743 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200744{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200745 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530746
Archit Taneja36d87d92012-07-28 22:59:03 +0530747 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
Archit Taneja9b372c22011-05-06 11:45:49 +0530748 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
749 else
750 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200751}
752
Archit Taneja78b687f2012-09-21 14:51:49 +0530753static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
754 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200755{
756 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200757
758 BUG_ON(plane == OMAP_DSS_GFX);
759
760 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530761
Archit Taneja36d87d92012-07-28 22:59:03 +0530762 if (plane == OMAP_DSS_WB)
763 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
764 else
765 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200766}
767
Archit Taneja5b54ed32012-09-26 16:55:27 +0530768static void dispc_ovl_set_zorder(enum omap_plane plane,
769 enum omap_overlay_caps caps, u8 zorder)
Archit Taneja54128702011-09-08 11:29:17 +0530770{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530771 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
Archit Taneja54128702011-09-08 11:29:17 +0530772 return;
773
774 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
775}
776
777static void dispc_ovl_enable_zorder_planes(void)
778{
779 int i;
780
781 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
782 return;
783
784 for (i = 0; i < dss_feat_get_num_ovls(); i++)
785 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
786}
787
Archit Taneja5b54ed32012-09-26 16:55:27 +0530788static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
789 enum omap_overlay_caps caps, bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100790{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530791 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100792 return;
793
Archit Taneja9b372c22011-05-06 11:45:49 +0530794 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100795}
796
Archit Taneja5b54ed32012-09-26 16:55:27 +0530797static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
798 enum omap_overlay_caps caps, u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200799{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530800 static const unsigned shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300801 int shift;
802
Archit Taneja5b54ed32012-09-26 16:55:27 +0530803 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100804 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530805
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300806 shift = shifts[plane];
807 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200808}
809
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300810static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200811{
Archit Taneja9b372c22011-05-06 11:45:49 +0530812 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200813}
814
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300815static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200816{
Archit Taneja9b372c22011-05-06 11:45:49 +0530817 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200818}
819
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300820static void dispc_ovl_set_color_mode(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200821 enum omap_color_mode color_mode)
822{
823 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +0530824 if (plane != OMAP_DSS_GFX) {
825 switch (color_mode) {
826 case OMAP_DSS_COLOR_NV12:
827 m = 0x0; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530828 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530829 m = 0x1; break;
830 case OMAP_DSS_COLOR_RGBA16:
831 m = 0x2; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530832 case OMAP_DSS_COLOR_RGB12U:
Amber Jainf20e4222011-05-19 19:47:50 +0530833 m = 0x4; break;
834 case OMAP_DSS_COLOR_ARGB16:
835 m = 0x5; break;
836 case OMAP_DSS_COLOR_RGB16:
837 m = 0x6; break;
838 case OMAP_DSS_COLOR_ARGB16_1555:
839 m = 0x7; break;
840 case OMAP_DSS_COLOR_RGB24U:
841 m = 0x8; break;
842 case OMAP_DSS_COLOR_RGB24P:
843 m = 0x9; break;
844 case OMAP_DSS_COLOR_YUV2:
845 m = 0xa; break;
846 case OMAP_DSS_COLOR_UYVY:
847 m = 0xb; break;
848 case OMAP_DSS_COLOR_ARGB32:
849 m = 0xc; break;
850 case OMAP_DSS_COLOR_RGBA32:
851 m = 0xd; break;
852 case OMAP_DSS_COLOR_RGBX32:
853 m = 0xe; break;
854 case OMAP_DSS_COLOR_XRGB16_1555:
855 m = 0xf; break;
856 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300857 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530858 }
859 } else {
860 switch (color_mode) {
861 case OMAP_DSS_COLOR_CLUT1:
862 m = 0x0; break;
863 case OMAP_DSS_COLOR_CLUT2:
864 m = 0x1; break;
865 case OMAP_DSS_COLOR_CLUT4:
866 m = 0x2; break;
867 case OMAP_DSS_COLOR_CLUT8:
868 m = 0x3; break;
869 case OMAP_DSS_COLOR_RGB12U:
870 m = 0x4; break;
871 case OMAP_DSS_COLOR_ARGB16:
872 m = 0x5; break;
873 case OMAP_DSS_COLOR_RGB16:
874 m = 0x6; break;
875 case OMAP_DSS_COLOR_ARGB16_1555:
876 m = 0x7; break;
877 case OMAP_DSS_COLOR_RGB24U:
878 m = 0x8; break;
879 case OMAP_DSS_COLOR_RGB24P:
880 m = 0x9; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530881 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530882 m = 0xa; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530883 case OMAP_DSS_COLOR_RGBA16:
Amber Jainf20e4222011-05-19 19:47:50 +0530884 m = 0xb; break;
885 case OMAP_DSS_COLOR_ARGB32:
886 m = 0xc; break;
887 case OMAP_DSS_COLOR_RGBA32:
888 m = 0xd; break;
889 case OMAP_DSS_COLOR_RGBX32:
890 m = 0xe; break;
891 case OMAP_DSS_COLOR_XRGB16_1555:
892 m = 0xf; break;
893 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300894 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530895 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200896 }
897
Archit Taneja9b372c22011-05-06 11:45:49 +0530898 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200899}
900
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530901static void dispc_ovl_configure_burst_type(enum omap_plane plane,
902 enum omap_dss_rotation_type rotation_type)
903{
904 if (dss_has_feature(FEAT_BURST_2D) == 0)
905 return;
906
907 if (rotation_type == OMAP_DSS_ROT_TILER)
908 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
909 else
910 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
911}
912
Tomi Valkeinenf4279842011-10-28 15:26:26 +0300913void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200914{
915 int shift;
916 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000917 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200918
919 switch (plane) {
920 case OMAP_DSS_GFX:
921 shift = 8;
922 break;
923 case OMAP_DSS_VIDEO1:
924 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +0530925 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200926 shift = 16;
927 break;
928 default:
929 BUG();
930 return;
931 }
932
Archit Taneja9b372c22011-05-06 11:45:49 +0530933 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000934 if (dss_has_feature(FEAT_MGR_LCD2)) {
935 switch (channel) {
936 case OMAP_DSS_CHANNEL_LCD:
937 chan = 0;
938 chan2 = 0;
939 break;
940 case OMAP_DSS_CHANNEL_DIGIT:
941 chan = 1;
942 chan2 = 0;
943 break;
944 case OMAP_DSS_CHANNEL_LCD2:
945 chan = 0;
946 chan2 = 1;
947 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530948 case OMAP_DSS_CHANNEL_LCD3:
949 if (dss_has_feature(FEAT_MGR_LCD3)) {
950 chan = 0;
951 chan2 = 2;
952 } else {
953 BUG();
954 return;
955 }
956 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000957 default:
958 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300959 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000960 }
961
962 val = FLD_MOD(val, chan, shift, shift);
963 val = FLD_MOD(val, chan2, 31, 30);
964 } else {
965 val = FLD_MOD(val, channel, shift, shift);
966 }
Archit Taneja9b372c22011-05-06 11:45:49 +0530967 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200968}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200969EXPORT_SYMBOL(dispc_ovl_set_channel_out);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200970
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200971static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
972{
973 int shift;
974 u32 val;
975 enum omap_channel channel;
976
977 switch (plane) {
978 case OMAP_DSS_GFX:
979 shift = 8;
980 break;
981 case OMAP_DSS_VIDEO1:
982 case OMAP_DSS_VIDEO2:
983 case OMAP_DSS_VIDEO3:
984 shift = 16;
985 break;
986 default:
987 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300988 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200989 }
990
991 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
992
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530993 if (dss_has_feature(FEAT_MGR_LCD3)) {
994 if (FLD_GET(val, 31, 30) == 0)
995 channel = FLD_GET(val, shift, shift);
996 else if (FLD_GET(val, 31, 30) == 1)
997 channel = OMAP_DSS_CHANNEL_LCD2;
998 else
999 channel = OMAP_DSS_CHANNEL_LCD3;
1000 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001001 if (FLD_GET(val, 31, 30) == 0)
1002 channel = FLD_GET(val, shift, shift);
1003 else
1004 channel = OMAP_DSS_CHANNEL_LCD2;
1005 } else {
1006 channel = FLD_GET(val, shift, shift);
1007 }
1008
1009 return channel;
1010}
1011
Archit Tanejad9ac7732012-09-22 12:38:19 +05301012void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1013{
1014 enum omap_plane plane = OMAP_DSS_WB;
1015
1016 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1017}
1018
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001019static void dispc_ovl_set_burst_size(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001020 enum omap_burst_size burst_size)
1021{
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301022 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001023 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001024
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001025 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001026 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001027}
1028
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001029static void dispc_configure_burst_sizes(void)
1030{
1031 int i;
1032 const int burst_size = BURST_SIZE_X8;
1033
1034 /* Configure burst size always to maximum size */
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001035 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001036 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001037}
1038
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001039static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001040{
1041 unsigned unit = dss_feat_get_burst_size_unit();
1042 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1043 return unit * 8;
1044}
1045
Mythri P Kd3862612011-03-11 18:02:49 +05301046void dispc_enable_gamma_table(bool enable)
1047{
1048 /*
1049 * This is partially implemented to support only disabling of
1050 * the gamma table.
1051 */
1052 if (enable) {
1053 DSSWARN("Gamma table enabling for TV not yet supported");
1054 return;
1055 }
1056
1057 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1058}
1059
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001060static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001061{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301062 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001063 return;
1064
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301065 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001066}
1067
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001068static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02001069 const struct omap_dss_cpr_coefs *coefs)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001070{
1071 u32 coef_r, coef_g, coef_b;
1072
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301073 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001074 return;
1075
1076 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1077 FLD_VAL(coefs->rb, 9, 0);
1078 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1079 FLD_VAL(coefs->gb, 9, 0);
1080 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1081 FLD_VAL(coefs->bb, 9, 0);
1082
1083 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1084 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1085 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1086}
1087
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001088static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001089{
1090 u32 val;
1091
1092 BUG_ON(plane == OMAP_DSS_GFX);
1093
Archit Taneja9b372c22011-05-06 11:45:49 +05301094 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001095 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +05301096 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001097}
1098
Archit Tanejad79db852012-09-22 12:30:17 +05301099static void dispc_ovl_enable_replication(enum omap_plane plane,
1100 enum omap_overlay_caps caps, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001101{
Archit Tanejab8c095b2011-09-13 18:20:33 +05301102 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001103 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001104
Archit Tanejad79db852012-09-22 12:30:17 +05301105 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1106 return;
1107
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001108 shift = shifts[plane];
1109 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001110}
1111
Archit Taneja8f366162012-04-16 12:53:44 +05301112static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
Archit Tanejae5c09e02012-04-16 12:53:42 +05301113 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001114{
1115 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301116
Archit Taneja33b89922012-11-14 13:50:15 +05301117 val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1118 FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1119
Archit Taneja702d1442011-05-06 11:45:50 +05301120 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001121}
1122
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001123static void dispc_init_fifos(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001124{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001125 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001126 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301127 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001128 u32 unit;
1129
1130 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001131
Archit Tanejaa0acb552010-09-15 19:20:00 +05301132 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001133
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001134 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1135 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001136 size *= unit;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001137 dispc.fifo_size[fifo] = size;
1138
1139 /*
1140 * By default fifos are mapped directly to overlays, fifo 0 to
1141 * ovl 0, fifo 1 to ovl 1, etc.
1142 */
1143 dispc.fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001144 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001145
1146 /*
1147 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1148 * causes problems with certain use cases, like using the tiler in 2D
1149 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1150 * giving GFX plane a larger fifo. WB but should work fine with a
1151 * smaller fifo.
1152 */
1153 if (dispc.feat->gfx_fifo_workaround) {
1154 u32 v;
1155
1156 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1157
1158 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1159 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1160 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1161 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1162
1163 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1164
1165 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1166 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1167 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001168}
1169
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001170static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001171{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001172 int fifo;
1173 u32 size = 0;
1174
1175 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1176 if (dispc.fifo_assignment[fifo] == plane)
1177 size += dispc.fifo_size[fifo];
1178 }
1179
1180 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001181}
1182
Tomi Valkeinen6f04e1b2011-10-31 08:58:52 +02001183void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001184{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301185 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001186 u32 unit;
1187
1188 unit = dss_feat_get_buffer_size_unit();
1189
1190 WARN_ON(low % unit != 0);
1191 WARN_ON(high % unit != 0);
1192
1193 low /= unit;
1194 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301195
Archit Taneja9b372c22011-05-06 11:45:49 +05301196 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1197 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1198
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001199 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001200 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301201 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001202 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301203 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001204 hi_start, hi_end) * unit,
1205 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001206
Archit Taneja9b372c22011-05-06 11:45:49 +05301207 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301208 FLD_VAL(high, hi_start, hi_end) |
1209 FLD_VAL(low, lo_start, lo_end));
Archit Taneja8bc65552013-12-17 16:40:21 +05301210
1211 /*
1212 * configure the preload to the pipeline's high threhold, if HT it's too
1213 * large for the preload field, set the threshold to the maximum value
1214 * that can be held by the preload register
1215 */
1216 if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload &&
1217 plane != OMAP_DSS_WB)
1218 dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001219}
Tomi Valkeinen8ee5c842013-11-08 10:07:20 +02001220EXPORT_SYMBOL(dispc_ovl_set_fifo_threshold);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001221
1222void dispc_enable_fifomerge(bool enable)
1223{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001224 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1225 WARN_ON(enable);
1226 return;
1227 }
1228
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001229 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1230 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001231}
1232
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001233void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001234 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1235 bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001236{
1237 /*
1238 * All sizes are in bytes. Both the buffer and burst are made of
1239 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1240 */
1241
1242 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001243 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1244 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001245
1246 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001247 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001248
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001249 if (use_fifomerge) {
1250 total_fifo_size = 0;
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001251 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001252 total_fifo_size += dispc_ovl_get_fifo_size(i);
1253 } else {
1254 total_fifo_size = ovl_fifo_size;
1255 }
1256
1257 /*
1258 * We use the same low threshold for both fifomerge and non-fifomerge
1259 * cases, but for fifomerge we calculate the high threshold using the
1260 * combined fifo size
1261 */
1262
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001263 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001264 *fifo_low = ovl_fifo_size - burst_size * 2;
1265 *fifo_high = total_fifo_size - burst_size;
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301266 } else if (plane == OMAP_DSS_WB) {
1267 /*
1268 * Most optimal configuration for writeback is to push out data
1269 * to the interconnect the moment writeback pushes enough pixels
1270 * in the FIFO to form a burst
1271 */
1272 *fifo_low = 0;
1273 *fifo_high = burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001274 } else {
1275 *fifo_low = ovl_fifo_size - burst_size;
1276 *fifo_high = total_fifo_size - buf_unit;
1277 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001278}
Tomi Valkeinen8ee5c842013-11-08 10:07:20 +02001279EXPORT_SYMBOL(dispc_ovl_compute_fifo_thresholds);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001280
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001281static void dispc_ovl_set_fir(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301282 int hinc, int vinc,
1283 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001284{
1285 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001286
Amber Jain0d66cbb2011-05-19 19:47:54 +05301287 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1288 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301289
Amber Jain0d66cbb2011-05-19 19:47:54 +05301290 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1291 &hinc_start, &hinc_end);
1292 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1293 &vinc_start, &vinc_end);
1294 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1295 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301296
Amber Jain0d66cbb2011-05-19 19:47:54 +05301297 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1298 } else {
1299 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1300 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1301 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001302}
1303
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001304static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001305{
1306 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301307 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001308
Archit Taneja87a74842011-03-02 11:19:50 +05301309 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1310 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1311
1312 val = FLD_VAL(vaccu, vert_start, vert_end) |
1313 FLD_VAL(haccu, hor_start, hor_end);
1314
Archit Taneja9b372c22011-05-06 11:45:49 +05301315 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001316}
1317
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001318static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001319{
1320 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301321 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001322
Archit Taneja87a74842011-03-02 11:19:50 +05301323 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1324 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1325
1326 val = FLD_VAL(vaccu, vert_start, vert_end) |
1327 FLD_VAL(haccu, hor_start, hor_end);
1328
Archit Taneja9b372c22011-05-06 11:45:49 +05301329 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001330}
1331
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001332static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1333 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301334{
1335 u32 val;
1336
1337 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1338 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1339}
1340
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001341static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1342 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301343{
1344 u32 val;
1345
1346 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1347 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1348}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001349
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001350static void dispc_ovl_set_scale_param(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001351 u16 orig_width, u16 orig_height,
1352 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301353 bool five_taps, u8 rotation,
1354 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001355{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301356 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001357
Amber Jained14a3c2011-05-19 19:47:51 +05301358 fir_hinc = 1024 * orig_width / out_width;
1359 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001360
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301361 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1362 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001363 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301364}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001365
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301366static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1367 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1368 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1369{
1370 int h_accu2_0, h_accu2_1;
1371 int v_accu2_0, v_accu2_1;
1372 int chroma_hinc, chroma_vinc;
1373 int idx;
1374
1375 struct accu {
1376 s8 h0_m, h0_n;
1377 s8 h1_m, h1_n;
1378 s8 v0_m, v0_n;
1379 s8 v1_m, v1_n;
1380 };
1381
1382 const struct accu *accu_table;
1383 const struct accu *accu_val;
1384
1385 static const struct accu accu_nv12[4] = {
1386 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1387 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1388 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1389 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1390 };
1391
1392 static const struct accu accu_nv12_ilace[4] = {
1393 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1394 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1395 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1396 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1397 };
1398
1399 static const struct accu accu_yuv[4] = {
1400 { 0, 1, 0, 1, 0, 1, 0, 1 },
1401 { 0, 1, 0, 1, 0, 1, 0, 1 },
1402 { -1, 1, 0, 1, 0, 1, 0, 1 },
1403 { 0, 1, 0, 1, -1, 1, 0, 1 },
1404 };
1405
1406 switch (rotation) {
1407 case OMAP_DSS_ROT_0:
1408 idx = 0;
1409 break;
1410 case OMAP_DSS_ROT_90:
1411 idx = 1;
1412 break;
1413 case OMAP_DSS_ROT_180:
1414 idx = 2;
1415 break;
1416 case OMAP_DSS_ROT_270:
1417 idx = 3;
1418 break;
1419 default:
1420 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001421 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301422 }
1423
1424 switch (color_mode) {
1425 case OMAP_DSS_COLOR_NV12:
1426 if (ilace)
1427 accu_table = accu_nv12_ilace;
1428 else
1429 accu_table = accu_nv12;
1430 break;
1431 case OMAP_DSS_COLOR_YUV2:
1432 case OMAP_DSS_COLOR_UYVY:
1433 accu_table = accu_yuv;
1434 break;
1435 default:
1436 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001437 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301438 }
1439
1440 accu_val = &accu_table[idx];
1441
1442 chroma_hinc = 1024 * orig_width / out_width;
1443 chroma_vinc = 1024 * orig_height / out_height;
1444
1445 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1446 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1447 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1448 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1449
1450 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1451 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1452}
1453
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001454static void dispc_ovl_set_scaling_common(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301455 u16 orig_width, u16 orig_height,
1456 u16 out_width, u16 out_height,
1457 bool ilace, bool five_taps,
1458 bool fieldmode, enum omap_color_mode color_mode,
1459 u8 rotation)
1460{
1461 int accu0 = 0;
1462 int accu1 = 0;
1463 u32 l;
1464
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001465 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301466 out_width, out_height, five_taps,
1467 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301468 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001469
Archit Taneja87a74842011-03-02 11:19:50 +05301470 /* RESIZEENABLE and VERTICALTAPS */
1471 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301472 l |= (orig_width != out_width) ? (1 << 5) : 0;
1473 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001474 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301475
1476 /* VRESIZECONF and HRESIZECONF */
1477 if (dss_has_feature(FEAT_RESIZECONF)) {
1478 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301479 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1480 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301481 }
1482
1483 /* LINEBUFFERSPLIT */
1484 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1485 l &= ~(0x1 << 22);
1486 l |= five_taps ? (1 << 22) : 0;
1487 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001488
Archit Taneja9b372c22011-05-06 11:45:49 +05301489 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001490
1491 /*
1492 * field 0 = even field = bottom field
1493 * field 1 = odd field = top field
1494 */
1495 if (ilace && !fieldmode) {
1496 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301497 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001498 if (accu0 >= 1024/2) {
1499 accu1 = 1024/2;
1500 accu0 -= accu1;
1501 }
1502 }
1503
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001504 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1505 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001506}
1507
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001508static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301509 u16 orig_width, u16 orig_height,
1510 u16 out_width, u16 out_height,
1511 bool ilace, bool five_taps,
1512 bool fieldmode, enum omap_color_mode color_mode,
1513 u8 rotation)
1514{
1515 int scale_x = out_width != orig_width;
1516 int scale_y = out_height != orig_height;
Archit Tanejaf92afae2012-08-24 11:11:14 +05301517 bool chroma_upscale = plane != OMAP_DSS_WB ? true : false;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301518
1519 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1520 return;
1521 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1522 color_mode != OMAP_DSS_COLOR_UYVY &&
1523 color_mode != OMAP_DSS_COLOR_NV12)) {
1524 /* reset chroma resampling for RGB formats */
Archit Taneja2a5561b2012-07-16 16:37:45 +05301525 if (plane != OMAP_DSS_WB)
1526 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301527 return;
1528 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001529
1530 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1531 out_height, ilace, color_mode, rotation);
1532
Amber Jain0d66cbb2011-05-19 19:47:54 +05301533 switch (color_mode) {
1534 case OMAP_DSS_COLOR_NV12:
Archit Taneja20fbb502012-08-22 17:04:48 +05301535 if (chroma_upscale) {
1536 /* UV is subsampled by 2 horizontally and vertically */
1537 orig_height >>= 1;
1538 orig_width >>= 1;
1539 } else {
1540 /* UV is downsampled by 2 horizontally and vertically */
1541 orig_height <<= 1;
1542 orig_width <<= 1;
1543 }
1544
Amber Jain0d66cbb2011-05-19 19:47:54 +05301545 break;
1546 case OMAP_DSS_COLOR_YUV2:
1547 case OMAP_DSS_COLOR_UYVY:
Archit Taneja20fbb502012-08-22 17:04:48 +05301548 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
Amber Jain0d66cbb2011-05-19 19:47:54 +05301549 if (rotation == OMAP_DSS_ROT_0 ||
Archit Taneja20fbb502012-08-22 17:04:48 +05301550 rotation == OMAP_DSS_ROT_180) {
1551 if (chroma_upscale)
1552 /* UV is subsampled by 2 horizontally */
1553 orig_width >>= 1;
1554 else
1555 /* UV is downsampled by 2 horizontally */
1556 orig_width <<= 1;
1557 }
1558
Amber Jain0d66cbb2011-05-19 19:47:54 +05301559 /* must use FIR for YUV422 if rotated */
1560 if (rotation != OMAP_DSS_ROT_0)
1561 scale_x = scale_y = true;
Archit Taneja20fbb502012-08-22 17:04:48 +05301562
Amber Jain0d66cbb2011-05-19 19:47:54 +05301563 break;
1564 default:
1565 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001566 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301567 }
1568
1569 if (out_width != orig_width)
1570 scale_x = true;
1571 if (out_height != orig_height)
1572 scale_y = true;
1573
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001574 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301575 out_width, out_height, five_taps,
1576 rotation, DISPC_COLOR_COMPONENT_UV);
1577
Archit Taneja2a5561b2012-07-16 16:37:45 +05301578 if (plane != OMAP_DSS_WB)
1579 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1580 (scale_x || scale_y) ? 1 : 0, 8, 8);
1581
Amber Jain0d66cbb2011-05-19 19:47:54 +05301582 /* set H scaling */
1583 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1584 /* set V scaling */
1585 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301586}
1587
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001588static void dispc_ovl_set_scaling(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301589 u16 orig_width, u16 orig_height,
1590 u16 out_width, u16 out_height,
1591 bool ilace, bool five_taps,
1592 bool fieldmode, enum omap_color_mode color_mode,
1593 u8 rotation)
1594{
1595 BUG_ON(plane == OMAP_DSS_GFX);
1596
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001597 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301598 orig_width, orig_height,
1599 out_width, out_height,
1600 ilace, five_taps,
1601 fieldmode, color_mode,
1602 rotation);
1603
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001604 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301605 orig_width, orig_height,
1606 out_width, out_height,
1607 ilace, five_taps,
1608 fieldmode, color_mode,
1609 rotation);
1610}
1611
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001612static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
Archit Tanejac35eeb22013-03-26 19:15:24 +05301613 enum omap_dss_rotation_type rotation_type,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001614 bool mirroring, enum omap_color_mode color_mode)
1615{
Archit Taneja87a74842011-03-02 11:19:50 +05301616 bool row_repeat = false;
1617 int vidrot = 0;
1618
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001619 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1620 color_mode == OMAP_DSS_COLOR_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001621
1622 if (mirroring) {
1623 switch (rotation) {
1624 case OMAP_DSS_ROT_0:
1625 vidrot = 2;
1626 break;
1627 case OMAP_DSS_ROT_90:
1628 vidrot = 1;
1629 break;
1630 case OMAP_DSS_ROT_180:
1631 vidrot = 0;
1632 break;
1633 case OMAP_DSS_ROT_270:
1634 vidrot = 3;
1635 break;
1636 }
1637 } else {
1638 switch (rotation) {
1639 case OMAP_DSS_ROT_0:
1640 vidrot = 0;
1641 break;
1642 case OMAP_DSS_ROT_90:
1643 vidrot = 1;
1644 break;
1645 case OMAP_DSS_ROT_180:
1646 vidrot = 2;
1647 break;
1648 case OMAP_DSS_ROT_270:
1649 vidrot = 3;
1650 break;
1651 }
1652 }
1653
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001654 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
Archit Taneja87a74842011-03-02 11:19:50 +05301655 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001656 else
Archit Taneja87a74842011-03-02 11:19:50 +05301657 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001658 }
Archit Taneja87a74842011-03-02 11:19:50 +05301659
Archit Taneja9b372c22011-05-06 11:45:49 +05301660 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301661 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301662 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1663 row_repeat ? 1 : 0, 18, 18);
Archit Tanejac35eeb22013-03-26 19:15:24 +05301664
1665 if (color_mode == OMAP_DSS_COLOR_NV12) {
1666 bool doublestride = (rotation_type == OMAP_DSS_ROT_TILER) &&
1667 (rotation == OMAP_DSS_ROT_0 ||
1668 rotation == OMAP_DSS_ROT_180);
1669 /* DOUBLESTRIDE */
1670 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22);
1671 }
1672
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001673}
1674
1675static int color_mode_to_bpp(enum omap_color_mode color_mode)
1676{
1677 switch (color_mode) {
1678 case OMAP_DSS_COLOR_CLUT1:
1679 return 1;
1680 case OMAP_DSS_COLOR_CLUT2:
1681 return 2;
1682 case OMAP_DSS_COLOR_CLUT4:
1683 return 4;
1684 case OMAP_DSS_COLOR_CLUT8:
Amber Jainf20e4222011-05-19 19:47:50 +05301685 case OMAP_DSS_COLOR_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001686 return 8;
1687 case OMAP_DSS_COLOR_RGB12U:
1688 case OMAP_DSS_COLOR_RGB16:
1689 case OMAP_DSS_COLOR_ARGB16:
1690 case OMAP_DSS_COLOR_YUV2:
1691 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301692 case OMAP_DSS_COLOR_RGBA16:
1693 case OMAP_DSS_COLOR_RGBX16:
1694 case OMAP_DSS_COLOR_ARGB16_1555:
1695 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001696 return 16;
1697 case OMAP_DSS_COLOR_RGB24P:
1698 return 24;
1699 case OMAP_DSS_COLOR_RGB24U:
1700 case OMAP_DSS_COLOR_ARGB32:
1701 case OMAP_DSS_COLOR_RGBA32:
1702 case OMAP_DSS_COLOR_RGBX32:
1703 return 32;
1704 default:
1705 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001706 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001707 }
1708}
1709
1710static s32 pixinc(int pixels, u8 ps)
1711{
1712 if (pixels == 1)
1713 return 1;
1714 else if (pixels > 1)
1715 return 1 + (pixels - 1) * ps;
1716 else if (pixels < 0)
1717 return 1 - (-pixels + 1) * ps;
1718 else
1719 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001720 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001721}
1722
1723static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1724 u16 screen_width,
1725 u16 width, u16 height,
1726 enum omap_color_mode color_mode, bool fieldmode,
1727 unsigned int field_offset,
1728 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301729 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001730{
1731 u8 ps;
1732
1733 /* FIXME CLUT formats */
1734 switch (color_mode) {
1735 case OMAP_DSS_COLOR_CLUT1:
1736 case OMAP_DSS_COLOR_CLUT2:
1737 case OMAP_DSS_COLOR_CLUT4:
1738 case OMAP_DSS_COLOR_CLUT8:
1739 BUG();
1740 return;
1741 case OMAP_DSS_COLOR_YUV2:
1742 case OMAP_DSS_COLOR_UYVY:
1743 ps = 4;
1744 break;
1745 default:
1746 ps = color_mode_to_bpp(color_mode) / 8;
1747 break;
1748 }
1749
1750 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1751 width, height);
1752
1753 /*
1754 * field 0 = even field = bottom field
1755 * field 1 = odd field = top field
1756 */
1757 switch (rotation + mirror * 4) {
1758 case OMAP_DSS_ROT_0:
1759 case OMAP_DSS_ROT_180:
1760 /*
1761 * If the pixel format is YUV or UYVY divide the width
1762 * of the image by 2 for 0 and 180 degree rotation.
1763 */
1764 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1765 color_mode == OMAP_DSS_COLOR_UYVY)
1766 width = width >> 1;
1767 case OMAP_DSS_ROT_90:
1768 case OMAP_DSS_ROT_270:
1769 *offset1 = 0;
1770 if (field_offset)
1771 *offset0 = field_offset * screen_width * ps;
1772 else
1773 *offset0 = 0;
1774
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301775 *row_inc = pixinc(1 +
1776 (y_predecim * screen_width - x_predecim * width) +
1777 (fieldmode ? screen_width : 0), ps);
1778 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001779 break;
1780
1781 case OMAP_DSS_ROT_0 + 4:
1782 case OMAP_DSS_ROT_180 + 4:
1783 /* If the pixel format is YUV or UYVY divide the width
1784 * of the image by 2 for 0 degree and 180 degree
1785 */
1786 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1787 color_mode == OMAP_DSS_COLOR_UYVY)
1788 width = width >> 1;
1789 case OMAP_DSS_ROT_90 + 4:
1790 case OMAP_DSS_ROT_270 + 4:
1791 *offset1 = 0;
1792 if (field_offset)
1793 *offset0 = field_offset * screen_width * ps;
1794 else
1795 *offset0 = 0;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301796 *row_inc = pixinc(1 -
1797 (y_predecim * screen_width + x_predecim * width) -
1798 (fieldmode ? screen_width : 0), ps);
1799 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001800 break;
1801
1802 default:
1803 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001804 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001805 }
1806}
1807
1808static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1809 u16 screen_width,
1810 u16 width, u16 height,
1811 enum omap_color_mode color_mode, bool fieldmode,
1812 unsigned int field_offset,
1813 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301814 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001815{
1816 u8 ps;
1817 u16 fbw, fbh;
1818
1819 /* FIXME CLUT formats */
1820 switch (color_mode) {
1821 case OMAP_DSS_COLOR_CLUT1:
1822 case OMAP_DSS_COLOR_CLUT2:
1823 case OMAP_DSS_COLOR_CLUT4:
1824 case OMAP_DSS_COLOR_CLUT8:
1825 BUG();
1826 return;
1827 default:
1828 ps = color_mode_to_bpp(color_mode) / 8;
1829 break;
1830 }
1831
1832 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1833 width, height);
1834
1835 /* width & height are overlay sizes, convert to fb sizes */
1836
1837 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1838 fbw = width;
1839 fbh = height;
1840 } else {
1841 fbw = height;
1842 fbh = width;
1843 }
1844
1845 /*
1846 * field 0 = even field = bottom field
1847 * field 1 = odd field = top field
1848 */
1849 switch (rotation + mirror * 4) {
1850 case OMAP_DSS_ROT_0:
1851 *offset1 = 0;
1852 if (field_offset)
1853 *offset0 = *offset1 + field_offset * screen_width * ps;
1854 else
1855 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301856 *row_inc = pixinc(1 +
1857 (y_predecim * screen_width - fbw * x_predecim) +
1858 (fieldmode ? screen_width : 0), ps);
1859 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1860 color_mode == OMAP_DSS_COLOR_UYVY)
1861 *pix_inc = pixinc(x_predecim, 2 * ps);
1862 else
1863 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001864 break;
1865 case OMAP_DSS_ROT_90:
1866 *offset1 = screen_width * (fbh - 1) * ps;
1867 if (field_offset)
1868 *offset0 = *offset1 + field_offset * ps;
1869 else
1870 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301871 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1872 y_predecim + (fieldmode ? 1 : 0), ps);
1873 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001874 break;
1875 case OMAP_DSS_ROT_180:
1876 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1877 if (field_offset)
1878 *offset0 = *offset1 - field_offset * screen_width * ps;
1879 else
1880 *offset0 = *offset1;
1881 *row_inc = pixinc(-1 -
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301882 (y_predecim * screen_width - fbw * x_predecim) -
1883 (fieldmode ? screen_width : 0), ps);
1884 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1885 color_mode == OMAP_DSS_COLOR_UYVY)
1886 *pix_inc = pixinc(-x_predecim, 2 * ps);
1887 else
1888 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001889 break;
1890 case OMAP_DSS_ROT_270:
1891 *offset1 = (fbw - 1) * ps;
1892 if (field_offset)
1893 *offset0 = *offset1 - field_offset * ps;
1894 else
1895 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301896 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1897 y_predecim - (fieldmode ? 1 : 0), ps);
1898 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001899 break;
1900
1901 /* mirroring */
1902 case OMAP_DSS_ROT_0 + 4:
1903 *offset1 = (fbw - 1) * ps;
1904 if (field_offset)
1905 *offset0 = *offset1 + field_offset * screen_width * ps;
1906 else
1907 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301908 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001909 (fieldmode ? screen_width : 0),
1910 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301911 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1912 color_mode == OMAP_DSS_COLOR_UYVY)
1913 *pix_inc = pixinc(-x_predecim, 2 * ps);
1914 else
1915 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001916 break;
1917
1918 case OMAP_DSS_ROT_90 + 4:
1919 *offset1 = 0;
1920 if (field_offset)
1921 *offset0 = *offset1 + field_offset * ps;
1922 else
1923 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301924 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1925 y_predecim + (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001926 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301927 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001928 break;
1929
1930 case OMAP_DSS_ROT_180 + 4:
1931 *offset1 = screen_width * (fbh - 1) * ps;
1932 if (field_offset)
1933 *offset0 = *offset1 - field_offset * screen_width * ps;
1934 else
1935 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301936 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001937 (fieldmode ? screen_width : 0),
1938 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301939 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1940 color_mode == OMAP_DSS_COLOR_UYVY)
1941 *pix_inc = pixinc(x_predecim, 2 * ps);
1942 else
1943 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001944 break;
1945
1946 case OMAP_DSS_ROT_270 + 4:
1947 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1948 if (field_offset)
1949 *offset0 = *offset1 - field_offset * ps;
1950 else
1951 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301952 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
1953 y_predecim - (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001954 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301955 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001956 break;
1957
1958 default:
1959 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001960 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001961 }
1962}
1963
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301964static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
1965 enum omap_color_mode color_mode, bool fieldmode,
1966 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1967 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1968{
1969 u8 ps;
1970
1971 switch (color_mode) {
1972 case OMAP_DSS_COLOR_CLUT1:
1973 case OMAP_DSS_COLOR_CLUT2:
1974 case OMAP_DSS_COLOR_CLUT4:
1975 case OMAP_DSS_COLOR_CLUT8:
1976 BUG();
1977 return;
1978 default:
1979 ps = color_mode_to_bpp(color_mode) / 8;
1980 break;
1981 }
1982
1983 DSSDBG("scrw %d, width %d\n", screen_width, width);
1984
1985 /*
1986 * field 0 = even field = bottom field
1987 * field 1 = odd field = top field
1988 */
1989 *offset1 = 0;
1990 if (field_offset)
1991 *offset0 = *offset1 + field_offset * screen_width * ps;
1992 else
1993 *offset0 = *offset1;
1994 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1995 (fieldmode ? screen_width : 0), ps);
1996 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1997 color_mode == OMAP_DSS_COLOR_UYVY)
1998 *pix_inc = pixinc(x_predecim, 2 * ps);
1999 else
2000 *pix_inc = pixinc(x_predecim, ps);
2001}
2002
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302003/*
2004 * This function is used to avoid synclosts in OMAP3, because of some
2005 * undocumented horizontal position and timing related limitations.
2006 */
Tomi Valkeinen465ec132012-10-19 15:40:24 +03002007static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302008 const struct omap_video_timings *t, u16 pos_x,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002009 u16 width, u16 height, u16 out_width, u16 out_height,
2010 bool five_taps)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302011{
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002012 const int ds = DIV_ROUND_UP(height, out_height);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302013 unsigned long nonactive;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302014 static const u8 limits[3] = { 8, 10, 20 };
2015 u64 val, blank;
2016 int i;
2017
Archit Taneja81ab95b2012-05-08 15:53:20 +05302018 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302019
2020 i = 0;
2021 if (out_height < height)
2022 i++;
2023 if (out_width < width)
2024 i++;
Archit Taneja81ab95b2012-05-08 15:53:20 +05302025 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302026 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2027 if (blank <= limits[i])
2028 return -EINVAL;
2029
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002030 /* FIXME add checks for 3-tap filter once the limitations are known */
2031 if (!five_taps)
2032 return 0;
2033
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302034 /*
2035 * Pixel data should be prepared before visible display point starts.
2036 * So, atleast DS-2 lines must have already been fetched by DISPC
2037 * during nonactive - pos_x period.
2038 */
2039 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2040 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002041 val, max(0, ds - 2) * width);
2042 if (val < max(0, ds - 2) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302043 return -EINVAL;
2044
2045 /*
2046 * All lines need to be refilled during the nonactive period of which
2047 * only one line can be loaded during the active period. So, atleast
2048 * DS - 1 lines should be loaded during nonactive period.
2049 */
2050 val = div_u64((u64)nonactive * lclk, pclk);
2051 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002052 val, max(0, ds - 1) * width);
2053 if (val < max(0, ds - 1) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302054 return -EINVAL;
2055
2056 return 0;
2057}
2058
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002059static unsigned long calc_core_clk_five_taps(unsigned long pclk,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302060 const struct omap_video_timings *mgr_timings, u16 width,
2061 u16 height, u16 out_width, u16 out_height,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002062 enum omap_color_mode color_mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002063{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302064 u32 core_clk = 0;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302065 u64 tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002066
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302067 if (height <= out_height && width <= out_width)
2068 return (unsigned long) pclk;
2069
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002070 if (height > out_height) {
Archit Taneja81ab95b2012-05-08 15:53:20 +05302071 unsigned int ppl = mgr_timings->x_res;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002072
2073 tmp = pclk * height * out_width;
2074 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302075 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002076
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02002077 if (height > 2 * out_height) {
2078 if (ppl == out_width)
2079 return 0;
2080
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002081 tmp = pclk * (height - 2 * out_height) * out_width;
2082 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302083 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002084 }
2085 }
2086
2087 if (width > out_width) {
2088 tmp = pclk * width;
2089 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302090 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002091
2092 if (color_mode == OMAP_DSS_COLOR_RGB24U)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302093 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002094 }
2095
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302096 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002097}
2098
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002099static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302100 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302101{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302102 if (height > out_height && width > out_width)
2103 return pclk * 4;
2104 else
2105 return pclk * 2;
2106}
2107
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002108static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302109 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002110{
2111 unsigned int hf, vf;
2112
2113 /*
2114 * FIXME how to determine the 'A' factor
2115 * for the no downscaling case ?
2116 */
2117
2118 if (width > 3 * out_width)
2119 hf = 4;
2120 else if (width > 2 * out_width)
2121 hf = 3;
2122 else if (width > out_width)
2123 hf = 2;
2124 else
2125 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002126 if (height > out_height)
2127 vf = 2;
2128 else
2129 vf = 1;
2130
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302131 return pclk * vf * hf;
2132}
2133
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002134static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302135 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302136{
Archit Taneja8ba85302012-09-26 17:00:37 +05302137 /*
2138 * If the overlay/writeback is in mem to mem mode, there are no
2139 * downscaling limitations with respect to pixel clock, return 1 as
2140 * required core clock to represent that we have sufficient enough
2141 * core clock to do maximum downscaling
2142 */
2143 if (mem_to_mem)
2144 return 1;
2145
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302146 if (width > out_width)
2147 return DIV_ROUND_UP(pclk, out_width) * width;
2148 else
2149 return pclk;
2150}
2151
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002152static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302153 const struct omap_video_timings *mgr_timings,
2154 u16 width, u16 height, u16 out_width, u16 out_height,
2155 enum omap_color_mode color_mode, bool *five_taps,
2156 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302157 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302158{
2159 int error;
2160 u16 in_width, in_height;
2161 int min_factor = min(*decim_x, *decim_y);
2162 const int maxsinglelinewidth =
2163 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302164
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302165 *five_taps = false;
2166
2167 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002168 in_height = height / *decim_y;
2169 in_width = width / *decim_x;
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002170 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302171 in_height, out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302172 error = (in_width > maxsinglelinewidth || !*core_clk ||
2173 *core_clk > dispc_core_clk_rate());
2174 if (error) {
2175 if (*decim_x == *decim_y) {
2176 *decim_x = min_factor;
2177 ++*decim_y;
2178 } else {
2179 swap(*decim_x, *decim_y);
2180 if (*decim_x < *decim_y)
2181 ++*decim_x;
2182 }
2183 }
2184 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2185
2186 if (in_width > maxsinglelinewidth) {
2187 DSSERR("Cannot scale max input width exceeded");
2188 return -EINVAL;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302189 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302190 return 0;
2191}
2192
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002193static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302194 const struct omap_video_timings *mgr_timings,
2195 u16 width, u16 height, u16 out_width, u16 out_height,
2196 enum omap_color_mode color_mode, bool *five_taps,
2197 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302198 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302199{
2200 int error;
2201 u16 in_width, in_height;
2202 int min_factor = min(*decim_x, *decim_y);
2203 const int maxsinglelinewidth =
2204 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2205
2206 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002207 in_height = height / *decim_y;
2208 in_width = width / *decim_x;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002209 *five_taps = in_height > out_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302210
2211 if (in_width > maxsinglelinewidth)
2212 if (in_height > out_height &&
2213 in_height < out_height * 2)
2214 *five_taps = false;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002215again:
2216 if (*five_taps)
2217 *core_clk = calc_core_clk_five_taps(pclk, mgr_timings,
2218 in_width, in_height, out_width,
2219 out_height, color_mode);
2220 else
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002221 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302222 in_height, out_width, out_height,
2223 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302224
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002225 error = check_horiz_timing_omap3(pclk, lclk, mgr_timings,
2226 pos_x, in_width, in_height, out_width,
2227 out_height, *five_taps);
2228 if (error && *five_taps) {
2229 *five_taps = false;
2230 goto again;
2231 }
2232
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302233 error = (error || in_width > maxsinglelinewidth * 2 ||
2234 (in_width > maxsinglelinewidth && *five_taps) ||
2235 !*core_clk || *core_clk > dispc_core_clk_rate());
2236 if (error) {
2237 if (*decim_x == *decim_y) {
2238 *decim_x = min_factor;
2239 ++*decim_y;
2240 } else {
2241 swap(*decim_x, *decim_y);
2242 if (*decim_x < *decim_y)
2243 ++*decim_x;
2244 }
2245 }
2246 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2247
Tomi Valkeinen465ec132012-10-19 15:40:24 +03002248 if (check_horiz_timing_omap3(pclk, lclk, mgr_timings, pos_x, width,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002249 height, out_width, out_height, *five_taps)) {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302250 DSSERR("horizontal timing too tight\n");
2251 return -EINVAL;
2252 }
2253
2254 if (in_width > (maxsinglelinewidth * 2)) {
2255 DSSERR("Cannot setup scaling");
2256 DSSERR("width exceeds maximum width possible");
2257 return -EINVAL;
2258 }
2259
2260 if (in_width > maxsinglelinewidth && *five_taps) {
2261 DSSERR("cannot setup scaling with five taps");
2262 return -EINVAL;
2263 }
2264 return 0;
2265}
2266
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002267static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302268 const struct omap_video_timings *mgr_timings,
2269 u16 width, u16 height, u16 out_width, u16 out_height,
2270 enum omap_color_mode color_mode, bool *five_taps,
2271 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302272 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302273{
2274 u16 in_width, in_width_max;
2275 int decim_x_min = *decim_x;
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002276 u16 in_height = height / *decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302277 const int maxsinglelinewidth =
2278 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja8ba85302012-09-26 17:00:37 +05302279 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302280
Archit Taneja5d501082012-11-07 11:45:02 +05302281 if (mem_to_mem) {
2282 in_width_max = out_width * maxdownscale;
2283 } else {
Archit Taneja8ba85302012-09-26 17:00:37 +05302284 in_width_max = dispc_core_clk_rate() /
2285 DIV_ROUND_UP(pclk, out_width);
Archit Taneja5d501082012-11-07 11:45:02 +05302286 }
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302287
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302288 *decim_x = DIV_ROUND_UP(width, in_width_max);
2289
2290 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2291 if (*decim_x > *x_predecim)
2292 return -EINVAL;
2293
2294 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002295 in_width = width / *decim_x;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302296 } while (*decim_x <= *x_predecim &&
2297 in_width > maxsinglelinewidth && ++*decim_x);
2298
2299 if (in_width > maxsinglelinewidth) {
2300 DSSERR("Cannot scale width exceeds max line width");
2301 return -EINVAL;
2302 }
2303
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002304 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
Archit Taneja8ba85302012-09-26 17:00:37 +05302305 out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302306 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002307}
2308
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002309static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302310 enum omap_overlay_caps caps,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302311 const struct omap_video_timings *mgr_timings,
2312 u16 width, u16 height, u16 out_width, u16 out_height,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302313 enum omap_color_mode color_mode, bool *five_taps,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302314 int *x_predecim, int *y_predecim, u16 pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302315 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302316{
Archit Taneja0373cac2011-09-08 13:25:17 +05302317 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302318 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302319 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302320 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302321
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002322 if (width == out_width && height == out_height)
2323 return 0;
2324
Archit Taneja5b54ed32012-09-26 16:55:27 +05302325 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002326 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302327
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002328 if (mem_to_mem) {
Archit Taneja1c031442012-11-07 11:45:03 +05302329 *x_predecim = *y_predecim = 1;
2330 } else {
2331 *x_predecim = max_decim_limit;
2332 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2333 dss_has_feature(FEAT_BURST_2D)) ?
2334 2 : max_decim_limit;
2335 }
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302336
2337 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2338 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2339 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2340 color_mode == OMAP_DSS_COLOR_CLUT8) {
2341 *x_predecim = 1;
2342 *y_predecim = 1;
2343 *five_taps = false;
2344 return 0;
2345 }
2346
2347 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2348 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2349
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302350 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302351 return -EINVAL;
2352
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302353 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302354 return -EINVAL;
2355
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002356 ret = dispc.feat->calc_scaling(pclk, lclk, mgr_timings, width, height,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302357 out_width, out_height, color_mode, five_taps,
Archit Taneja8ba85302012-09-26 17:00:37 +05302358 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2359 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302360 if (ret)
2361 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302362
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302363 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2364 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302365
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302366 if (!core_clk || core_clk > dispc_core_clk_rate()) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302367 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302368 "required core clk rate = %lu Hz, "
2369 "current core clk rate = %lu Hz\n",
2370 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302371 return -EINVAL;
2372 }
2373
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302374 *x_predecim = decim_x;
2375 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302376 return 0;
2377}
2378
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002379int dispc_ovl_check(enum omap_plane plane, enum omap_channel channel,
2380 const struct omap_overlay_info *oi,
2381 const struct omap_video_timings *timings,
2382 int *x_predecim, int *y_predecim)
2383{
2384 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2385 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002386 bool fieldmode = false;
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002387 u16 in_height = oi->height;
2388 u16 in_width = oi->width;
2389 bool ilace = timings->interlace;
2390 u16 out_width, out_height;
2391 int pos_x = oi->pos_x;
2392 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2393 unsigned long lclk = dispc_mgr_lclk_rate(channel);
2394
2395 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2396 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
2397
2398 if (ilace && oi->height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002399 fieldmode = true;
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002400
2401 if (ilace) {
2402 if (fieldmode)
2403 in_height /= 2;
2404 out_height /= 2;
2405
2406 DSSDBG("adjusting for ilace: height %d, out_height %d\n",
2407 in_height, out_height);
2408 }
2409
2410 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
2411 return -EINVAL;
2412
2413 return dispc_ovl_calc_scaling(pclk, lclk, caps, timings, in_width,
2414 in_height, out_width, out_height, oi->color_mode,
2415 &five_taps, x_predecim, y_predecim, pos_x,
2416 oi->rotation_type, false);
2417}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002418EXPORT_SYMBOL(dispc_ovl_check);
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002419
Archit Taneja84a880f2012-09-26 16:57:37 +05302420static int dispc_ovl_setup_common(enum omap_plane plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302421 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2422 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2423 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2424 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2425 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
Archit Taneja8ba85302012-09-26 17:00:37 +05302426 bool replication, const struct omap_video_timings *mgr_timings,
2427 bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002428{
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302429 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002430 bool fieldmode = false;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302431 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002432 unsigned offset0, offset1;
2433 s32 row_inc;
2434 s32 pix_inc;
Archit Taneja6be0d732012-11-07 11:45:04 +05302435 u16 frame_width, frame_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002436 unsigned int field_offset = 0;
Archit Taneja84a880f2012-09-26 16:57:37 +05302437 u16 in_height = height;
2438 u16 in_width = width;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302439 int x_predecim = 1, y_predecim = 1;
Archit Taneja8050cbe2012-06-06 16:25:52 +05302440 bool ilace = mgr_timings->interlace;
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002441 unsigned long pclk = dispc_plane_pclk_rate(plane);
2442 unsigned long lclk = dispc_plane_lclk_rate(plane);
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002443
Tomi Valkeinene5666582014-11-28 14:34:15 +02002444 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002445 return -EINVAL;
2446
Archit Taneja84a880f2012-09-26 16:57:37 +05302447 out_width = out_width == 0 ? width : out_width;
2448 out_height = out_height == 0 ? height : out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002449
Archit Taneja84a880f2012-09-26 16:57:37 +05302450 if (ilace && height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002451 fieldmode = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002452
2453 if (ilace) {
2454 if (fieldmode)
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302455 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302456 pos_y /= 2;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302457 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002458
2459 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
Archit Taneja84a880f2012-09-26 16:57:37 +05302460 "out_height %d\n", in_height, pos_y,
2461 out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002462 }
2463
Archit Taneja84a880f2012-09-26 16:57:37 +05302464 if (!dss_feat_color_mode_supported(plane, color_mode))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302465 return -EINVAL;
2466
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002467 r = dispc_ovl_calc_scaling(pclk, lclk, caps, mgr_timings, in_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302468 in_height, out_width, out_height, color_mode,
2469 &five_taps, &x_predecim, &y_predecim, pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302470 rotation_type, mem_to_mem);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302471 if (r)
2472 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002473
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002474 in_width = in_width / x_predecim;
2475 in_height = in_height / y_predecim;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302476
Archit Taneja84a880f2012-09-26 16:57:37 +05302477 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2478 color_mode == OMAP_DSS_COLOR_UYVY ||
2479 color_mode == OMAP_DSS_COLOR_NV12)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302480 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002481
2482 if (ilace && !fieldmode) {
2483 /*
2484 * when downscaling the bottom field may have to start several
2485 * source lines below the top field. Unfortunately ACCUI
2486 * registers will only hold the fractional part of the offset
2487 * so the integer part must be added to the base address of the
2488 * bottom field.
2489 */
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302490 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002491 field_offset = 0;
2492 else
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302493 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002494 }
2495
2496 /* Fields are independent but interleaved in memory. */
2497 if (fieldmode)
2498 field_offset = 1;
2499
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002500 offset0 = 0;
2501 offset1 = 0;
2502 row_inc = 0;
2503 pix_inc = 0;
2504
Archit Taneja6be0d732012-11-07 11:45:04 +05302505 if (plane == OMAP_DSS_WB) {
2506 frame_width = out_width;
2507 frame_height = out_height;
2508 } else {
2509 frame_width = in_width;
2510 frame_height = height;
2511 }
2512
Archit Taneja84a880f2012-09-26 16:57:37 +05302513 if (rotation_type == OMAP_DSS_ROT_TILER)
Archit Taneja6be0d732012-11-07 11:45:04 +05302514 calc_tiler_rotation_offset(screen_width, frame_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302515 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302516 &offset0, &offset1, &row_inc, &pix_inc,
2517 x_predecim, y_predecim);
Archit Taneja84a880f2012-09-26 16:57:37 +05302518 else if (rotation_type == OMAP_DSS_ROT_DMA)
Archit Taneja6be0d732012-11-07 11:45:04 +05302519 calc_dma_rotation_offset(rotation, mirror, screen_width,
2520 frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302521 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302522 &offset0, &offset1, &row_inc, &pix_inc,
2523 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002524 else
Archit Taneja84a880f2012-09-26 16:57:37 +05302525 calc_vrfb_rotation_offset(rotation, mirror,
Archit Taneja6be0d732012-11-07 11:45:04 +05302526 screen_width, frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302527 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302528 &offset0, &offset1, &row_inc, &pix_inc,
2529 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002530
2531 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2532 offset0, offset1, row_inc, pix_inc);
2533
Archit Taneja84a880f2012-09-26 16:57:37 +05302534 dispc_ovl_set_color_mode(plane, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002535
Archit Taneja84a880f2012-09-26 16:57:37 +05302536 dispc_ovl_configure_burst_type(plane, rotation_type);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302537
Archit Taneja84a880f2012-09-26 16:57:37 +05302538 dispc_ovl_set_ba0(plane, paddr + offset0);
2539 dispc_ovl_set_ba1(plane, paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002540
Archit Taneja84a880f2012-09-26 16:57:37 +05302541 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2542 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2543 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302544 }
2545
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002546 dispc_ovl_set_row_inc(plane, row_inc);
2547 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002548
Archit Taneja84a880f2012-09-26 16:57:37 +05302549 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302550 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002551
Archit Taneja84a880f2012-09-26 16:57:37 +05302552 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002553
Archit Taneja78b687f2012-09-21 14:51:49 +05302554 dispc_ovl_set_input_size(plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002555
Archit Taneja5b54ed32012-09-26 16:55:27 +05302556 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302557 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2558 out_height, ilace, five_taps, fieldmode,
Archit Taneja84a880f2012-09-26 16:57:37 +05302559 color_mode, rotation);
Archit Taneja78b687f2012-09-21 14:51:49 +05302560 dispc_ovl_set_output_size(plane, out_width, out_height);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002561 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002562 }
2563
Archit Tanejac35eeb22013-03-26 19:15:24 +05302564 dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, mirror,
2565 color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002566
Archit Taneja84a880f2012-09-26 16:57:37 +05302567 dispc_ovl_set_zorder(plane, caps, zorder);
2568 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2569 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002570
Archit Tanejad79db852012-09-22 12:30:17 +05302571 dispc_ovl_enable_replication(plane, caps, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302572
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002573 return 0;
2574}
2575
Archit Taneja84a880f2012-09-26 16:57:37 +05302576int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
Archit Taneja8ba85302012-09-26 17:00:37 +05302577 bool replication, const struct omap_video_timings *mgr_timings,
2578 bool mem_to_mem)
Archit Taneja84a880f2012-09-26 16:57:37 +05302579{
2580 int r;
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002581 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
Archit Taneja84a880f2012-09-26 16:57:37 +05302582 enum omap_channel channel;
2583
2584 channel = dispc_ovl_get_channel_out(plane);
2585
Arnd Bergmann24f13a62014-04-24 13:28:18 +01002586 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2587 " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2588 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
Archit Taneja84a880f2012-09-26 16:57:37 +05302589 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2590 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2591
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002592 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302593 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2594 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2595 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
Archit Taneja8ba85302012-09-26 17:00:37 +05302596 oi->rotation_type, replication, mgr_timings, mem_to_mem);
Archit Taneja84a880f2012-09-26 16:57:37 +05302597
2598 return r;
2599}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002600EXPORT_SYMBOL(dispc_ovl_setup);
Archit Taneja84a880f2012-09-26 16:57:37 +05302601
Archit Taneja749feff2012-08-31 12:32:52 +05302602int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302603 bool mem_to_mem, const struct omap_video_timings *mgr_timings)
Archit Taneja749feff2012-08-31 12:32:52 +05302604{
2605 int r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302606 u32 l;
Archit Taneja749feff2012-08-31 12:32:52 +05302607 enum omap_plane plane = OMAP_DSS_WB;
2608 const int pos_x = 0, pos_y = 0;
2609 const u8 zorder = 0, global_alpha = 0;
2610 const bool replication = false;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302611 bool truncation;
Archit Taneja749feff2012-08-31 12:32:52 +05302612 int in_width = mgr_timings->x_res;
2613 int in_height = mgr_timings->y_res;
2614 enum omap_overlay_caps caps =
2615 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2616
2617 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2618 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2619 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2620 wi->mirror);
2621
2622 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2623 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2624 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2625 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302626 replication, mgr_timings, mem_to_mem);
2627
2628 switch (wi->color_mode) {
2629 case OMAP_DSS_COLOR_RGB16:
2630 case OMAP_DSS_COLOR_RGB24P:
2631 case OMAP_DSS_COLOR_ARGB16:
2632 case OMAP_DSS_COLOR_RGBA16:
2633 case OMAP_DSS_COLOR_RGB12U:
2634 case OMAP_DSS_COLOR_ARGB16_1555:
2635 case OMAP_DSS_COLOR_XRGB16_1555:
2636 case OMAP_DSS_COLOR_RGBX16:
2637 truncation = true;
2638 break;
2639 default:
2640 truncation = false;
2641 break;
2642 }
2643
2644 /* setup extra DISPC_WB_ATTRIBUTES */
2645 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2646 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2647 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2648 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Archit Taneja749feff2012-08-31 12:32:52 +05302649
2650 return r;
2651}
2652
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002653int dispc_ovl_enable(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002654{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002655 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2656
Archit Taneja9b372c22011-05-06 11:45:49 +05302657 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002658
2659 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002660}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002661EXPORT_SYMBOL(dispc_ovl_enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002662
Tomi Valkeinen04bd8ac2012-10-10 14:13:15 +03002663bool dispc_ovl_enabled(enum omap_plane plane)
2664{
2665 return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2666}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002667EXPORT_SYMBOL(dispc_ovl_enabled);
Tomi Valkeinen04bd8ac2012-10-10 14:13:15 +03002668
Tomi Valkeinenf1a813d2012-10-19 14:16:06 +03002669void dispc_mgr_enable(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002670{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302671 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2672 /* flush posted write */
2673 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002674}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002675EXPORT_SYMBOL(dispc_mgr_enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002676
Tomi Valkeinen65398512012-10-10 11:44:17 +03002677bool dispc_mgr_is_enabled(enum omap_channel channel)
2678{
2679 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2680}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002681EXPORT_SYMBOL(dispc_mgr_is_enabled);
Tomi Valkeinen65398512012-10-10 11:44:17 +03002682
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302683void dispc_wb_enable(bool enable)
2684{
Tomi Valkeinen916188a2012-10-10 14:13:26 +03002685 dispc_ovl_enable(OMAP_DSS_WB, enable);
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302686}
2687
2688bool dispc_wb_is_enabled(void)
2689{
Tomi Valkeinen916188a2012-10-10 14:13:26 +03002690 return dispc_ovl_enabled(OMAP_DSS_WB);
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302691}
2692
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002693static void dispc_lcd_enable_signal_polarity(bool act_high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002694{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002695 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2696 return;
2697
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002698 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002699}
2700
2701void dispc_lcd_enable_signal(bool enable)
2702{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002703 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2704 return;
2705
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002706 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002707}
2708
2709void dispc_pck_free_enable(bool enable)
2710{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002711 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2712 return;
2713
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002714 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002715}
2716
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002717static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002718{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302719 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002720}
2721
2722
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002723static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002724{
Archit Tanejad21f43b2012-06-21 09:45:11 +05302725 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002726}
2727
2728void dispc_set_loadmode(enum omap_dss_load_mode mode)
2729{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002730 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002731}
2732
2733
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002734static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002735{
Sumit Semwal8613b002010-12-02 11:27:09 +00002736 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002737}
2738
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002739static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002740 enum omap_dss_trans_key_type type,
2741 u32 trans_key)
2742{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302743 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002744
Sumit Semwal8613b002010-12-02 11:27:09 +00002745 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002746}
2747
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002748static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002749{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302750 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002751}
Archit Taneja11354dd2011-09-26 11:47:29 +05302752
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002753static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2754 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002755{
Archit Taneja11354dd2011-09-26 11:47:29 +05302756 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002757 return;
2758
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002759 if (ch == OMAP_DSS_CHANNEL_LCD)
2760 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002761 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002762 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002763}
Archit Taneja11354dd2011-09-26 11:47:29 +05302764
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002765void dispc_mgr_setup(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02002766 const struct omap_overlay_manager_info *info)
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002767{
2768 dispc_mgr_set_default_color(channel, info->default_color);
2769 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2770 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2771 dispc_mgr_enable_alpha_fixed_zorder(channel,
2772 info->partial_alpha_enabled);
2773 if (dss_has_feature(FEAT_CPR)) {
2774 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2775 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2776 }
2777}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002778EXPORT_SYMBOL(dispc_mgr_setup);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002779
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002780static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002781{
2782 int code;
2783
2784 switch (data_lines) {
2785 case 12:
2786 code = 0;
2787 break;
2788 case 16:
2789 code = 1;
2790 break;
2791 case 18:
2792 code = 2;
2793 break;
2794 case 24:
2795 code = 3;
2796 break;
2797 default:
2798 BUG();
2799 return;
2800 }
2801
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302802 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002803}
2804
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002805static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002806{
2807 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302808 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002809
2810 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302811 case DSS_IO_PAD_MODE_RESET:
2812 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002813 gpout1 = 0;
2814 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302815 case DSS_IO_PAD_MODE_RFBI:
2816 gpout0 = 1;
2817 gpout1 = 0;
2818 break;
2819 case DSS_IO_PAD_MODE_BYPASS:
2820 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002821 gpout1 = 1;
2822 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002823 default:
2824 BUG();
2825 return;
2826 }
2827
Archit Taneja569969d2011-08-22 17:41:57 +05302828 l = dispc_read_reg(DISPC_CONTROL);
2829 l = FLD_MOD(l, gpout0, 15, 15);
2830 l = FLD_MOD(l, gpout1, 16, 16);
2831 dispc_write_reg(DISPC_CONTROL, l);
2832}
2833
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002834static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
Archit Taneja569969d2011-08-22 17:41:57 +05302835{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302836 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002837}
2838
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002839void dispc_mgr_set_lcd_config(enum omap_channel channel,
2840 const struct dss_lcd_mgr_config *config)
2841{
2842 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
2843
2844 dispc_mgr_enable_stallmode(channel, config->stallmode);
2845 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
2846
2847 dispc_mgr_set_clock_div(channel, &config->clock_info);
2848
2849 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
2850
2851 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
2852
2853 dispc_mgr_set_lcd_type_tft(channel);
2854}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002855EXPORT_SYMBOL(dispc_mgr_set_lcd_config);
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002856
Archit Taneja8f366162012-04-16 12:53:44 +05302857static bool _dispc_mgr_size_ok(u16 width, u16 height)
2858{
Archit Taneja33b89922012-11-14 13:50:15 +05302859 return width <= dispc.feat->mgr_width_max &&
2860 height <= dispc.feat->mgr_height_max;
Archit Taneja8f366162012-04-16 12:53:44 +05302861}
2862
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002863static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2864 int vsw, int vfp, int vbp)
2865{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302866 if (hsw < 1 || hsw > dispc.feat->sw_max ||
2867 hfp < 1 || hfp > dispc.feat->hp_max ||
2868 hbp < 1 || hbp > dispc.feat->hp_max ||
2869 vsw < 1 || vsw > dispc.feat->sw_max ||
2870 vfp < 0 || vfp > dispc.feat->vp_max ||
2871 vbp < 0 || vbp > dispc.feat->vp_max)
2872 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002873 return true;
2874}
2875
Archit Tanejaca5ca692013-03-26 19:15:22 +05302876static bool _dispc_mgr_pclk_ok(enum omap_channel channel,
2877 unsigned long pclk)
2878{
2879 if (dss_mgr_is_lcd(channel))
2880 return pclk <= dispc.feat->max_lcd_pclk ? true : false;
2881 else
2882 return pclk <= dispc.feat->max_tv_pclk ? true : false;
2883}
2884
Archit Taneja8f366162012-04-16 12:53:44 +05302885bool dispc_mgr_timings_ok(enum omap_channel channel,
Archit Tanejab917fa32012-04-27 01:07:28 +05302886 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002887{
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002888 if (!_dispc_mgr_size_ok(timings->x_res, timings->y_res))
2889 return false;
Archit Taneja8f366162012-04-16 12:53:44 +05302890
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002891 if (!_dispc_mgr_pclk_ok(channel, timings->pixelclock))
2892 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302893
2894 if (dss_mgr_is_lcd(channel)) {
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03002895 /* TODO: OMAP4+ supports interlace for LCD outputs */
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002896 if (timings->interlace)
2897 return false;
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03002898
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002899 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
Archit Tanejaca5ca692013-03-26 19:15:22 +05302900 timings->hbp, timings->vsw, timings->vfp,
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002901 timings->vbp))
2902 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302903 }
Archit Taneja8f366162012-04-16 12:53:44 +05302904
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002905 return true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002906}
2907
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002908static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
Archit Taneja655e2942012-06-21 10:37:43 +05302909 int hfp, int hbp, int vsw, int vfp, int vbp,
2910 enum omap_dss_signal_level vsync_level,
2911 enum omap_dss_signal_level hsync_level,
2912 enum omap_dss_signal_edge data_pclk_edge,
2913 enum omap_dss_signal_level de_level,
2914 enum omap_dss_signal_edge sync_pclk_edge)
2915
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002916{
Archit Taneja655e2942012-06-21 10:37:43 +05302917 u32 timing_h, timing_v, l;
Tomi Valkeinened351882014-10-02 17:58:49 +00002918 bool onoff, rf, ipc, vs, hs, de;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002919
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302920 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
2921 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
2922 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
2923 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
2924 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
2925 FLD_VAL(vbp, dispc.feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002926
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002927 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2928 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05302929
Tomi Valkeinened351882014-10-02 17:58:49 +00002930 switch (vsync_level) {
2931 case OMAPDSS_SIG_ACTIVE_LOW:
2932 vs = true;
2933 break;
2934 case OMAPDSS_SIG_ACTIVE_HIGH:
2935 vs = false;
2936 break;
2937 default:
2938 BUG();
2939 }
2940
2941 switch (hsync_level) {
2942 case OMAPDSS_SIG_ACTIVE_LOW:
2943 hs = true;
2944 break;
2945 case OMAPDSS_SIG_ACTIVE_HIGH:
2946 hs = false;
2947 break;
2948 default:
2949 BUG();
2950 }
2951
2952 switch (de_level) {
2953 case OMAPDSS_SIG_ACTIVE_LOW:
2954 de = true;
2955 break;
2956 case OMAPDSS_SIG_ACTIVE_HIGH:
2957 de = false;
2958 break;
2959 default:
2960 BUG();
2961 }
2962
Archit Taneja655e2942012-06-21 10:37:43 +05302963 switch (data_pclk_edge) {
2964 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2965 ipc = false;
2966 break;
2967 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2968 ipc = true;
2969 break;
Archit Taneja655e2942012-06-21 10:37:43 +05302970 default:
2971 BUG();
2972 }
2973
Tomi Valkeinen7a163602014-10-02 17:58:48 +00002974 /* always use the 'rf' setting */
2975 onoff = true;
2976
Archit Taneja655e2942012-06-21 10:37:43 +05302977 switch (sync_pclk_edge) {
Archit Taneja655e2942012-06-21 10:37:43 +05302978 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
Archit Taneja655e2942012-06-21 10:37:43 +05302979 rf = false;
2980 break;
2981 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
Archit Taneja655e2942012-06-21 10:37:43 +05302982 rf = true;
2983 break;
2984 default:
2985 BUG();
Joe Perchescf6ac4ce2013-10-08 16:23:24 -07002986 }
Archit Taneja655e2942012-06-21 10:37:43 +05302987
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03002988 l = FLD_VAL(onoff, 17, 17) |
2989 FLD_VAL(rf, 16, 16) |
Tomi Valkeinened351882014-10-02 17:58:49 +00002990 FLD_VAL(de, 15, 15) |
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03002991 FLD_VAL(ipc, 14, 14) |
Tomi Valkeinened351882014-10-02 17:58:49 +00002992 FLD_VAL(hs, 13, 13) |
2993 FLD_VAL(vs, 12, 12);
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03002994
Archit Taneja655e2942012-06-21 10:37:43 +05302995 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00002996
2997 if (dispc.syscon_pol) {
2998 const int shifts[] = {
2999 [OMAP_DSS_CHANNEL_LCD] = 0,
3000 [OMAP_DSS_CHANNEL_LCD2] = 1,
3001 [OMAP_DSS_CHANNEL_LCD3] = 2,
3002 };
3003
3004 u32 mask, val;
3005
3006 mask = (1 << 0) | (1 << 3) | (1 << 6);
3007 val = (rf << 0) | (ipc << 3) | (onoff << 6);
3008
3009 mask <<= 16 + shifts[channel];
3010 val <<= 16 + shifts[channel];
3011
3012 regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset,
3013 mask, val);
3014 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003015}
3016
3017/* change name to mode? */
Archit Tanejac51d9212012-04-16 12:53:43 +05303018void dispc_mgr_set_timings(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003019 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003020{
3021 unsigned xtot, ytot;
3022 unsigned long ht, vt;
Archit Taneja2aefad42012-05-18 14:36:54 +05303023 struct omap_video_timings t = *timings;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003024
Archit Taneja2aefad42012-05-18 14:36:54 +05303025 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
Archit Tanejac51d9212012-04-16 12:53:43 +05303026
Archit Taneja2aefad42012-05-18 14:36:54 +05303027 if (!dispc_mgr_timings_ok(channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05303028 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003029 return;
3030 }
Archit Tanejac51d9212012-04-16 12:53:43 +05303031
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303032 if (dss_mgr_is_lcd(channel)) {
Archit Taneja2aefad42012-05-18 14:36:54 +05303033 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
Archit Taneja655e2942012-06-21 10:37:43 +05303034 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
3035 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
Archit Tanejac51d9212012-04-16 12:53:43 +05303036
Archit Taneja2aefad42012-05-18 14:36:54 +05303037 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
3038 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
Archit Tanejac51d9212012-04-16 12:53:43 +05303039
Tomi Valkeinend8d789412013-04-10 14:12:14 +03003040 ht = timings->pixelclock / xtot;
3041 vt = timings->pixelclock / xtot / ytot;
Archit Tanejac51d9212012-04-16 12:53:43 +05303042
Tomi Valkeinend8d789412013-04-10 14:12:14 +03003043 DSSDBG("pck %u\n", timings->pixelclock);
Archit Tanejac51d9212012-04-16 12:53:43 +05303044 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Archit Taneja2aefad42012-05-18 14:36:54 +05303045 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
Archit Taneja655e2942012-06-21 10:37:43 +05303046 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3047 t.vsync_level, t.hsync_level, t.data_pclk_edge,
3048 t.de_level, t.sync_pclk_edge);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003049
Archit Tanejac51d9212012-04-16 12:53:43 +05303050 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05303051 } else {
Archit Taneja23c8f882012-06-28 11:15:51 +05303052 if (t.interlace == true)
Archit Taneja2aefad42012-05-18 14:36:54 +05303053 t.y_res /= 2;
Archit Tanejac51d9212012-04-16 12:53:43 +05303054 }
Archit Taneja8f366162012-04-16 12:53:44 +05303055
Archit Taneja2aefad42012-05-18 14:36:54 +05303056 dispc_mgr_set_size(channel, t.x_res, t.y_res);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003057}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003058EXPORT_SYMBOL(dispc_mgr_set_timings);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003059
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003060static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003061 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003062{
3063 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003064 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003065
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003066 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003067 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003068
3069 if (dss_has_feature(FEAT_CORE_CLK_DIV) == false &&
3070 channel == OMAP_DSS_CHANNEL_LCD)
3071 dispc.core_clk_rate = dispc_fclk_rate() / lck_div;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003072}
3073
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003074static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00003075 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003076{
3077 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003078 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003079 *lck_div = FLD_GET(l, 23, 16);
3080 *pck_div = FLD_GET(l, 7, 0);
3081}
3082
3083unsigned long dispc_fclk_rate(void)
3084{
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003085 struct dss_pll *pll;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003086 unsigned long r = 0;
3087
Taneja, Archit66534e82011-03-08 05:50:34 -06003088 switch (dss_get_dispc_clk_source()) {
Archit Taneja89a35e52011-04-12 13:52:23 +05303089 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen5aaee692012-12-12 10:37:03 +02003090 r = dss_get_dispc_clk_rate();
Taneja, Archit66534e82011-03-08 05:50:34 -06003091 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05303092 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003093 pll = dss_pll_find("dsi0");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003094 if (!pll)
3095 pll = dss_pll_find("video0");
3096
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003097 r = pll->cinfo.clkout[0];
Taneja, Archit66534e82011-03-08 05:50:34 -06003098 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05303099 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003100 pll = dss_pll_find("dsi1");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003101 if (!pll)
3102 pll = dss_pll_find("video1");
3103
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003104 r = pll->cinfo.clkout[0];
Archit Taneja5a8b5722011-05-12 17:26:29 +05303105 break;
Taneja, Archit66534e82011-03-08 05:50:34 -06003106 default:
3107 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003108 return 0;
Taneja, Archit66534e82011-03-08 05:50:34 -06003109 }
3110
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003111 return r;
3112}
3113
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003114unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003115{
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003116 struct dss_pll *pll;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003117 int lcd;
3118 unsigned long r;
3119 u32 l;
3120
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003121 if (dss_mgr_is_lcd(channel)) {
3122 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003123
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003124 lcd = FLD_GET(l, 23, 16);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003125
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003126 switch (dss_get_lcd_clk_source(channel)) {
3127 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen5aaee692012-12-12 10:37:03 +02003128 r = dss_get_dispc_clk_rate();
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003129 break;
3130 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003131 pll = dss_pll_find("dsi0");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003132 if (!pll)
3133 pll = dss_pll_find("video0");
3134
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003135 r = pll->cinfo.clkout[0];
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003136 break;
3137 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003138 pll = dss_pll_find("dsi1");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003139 if (!pll)
3140 pll = dss_pll_find("video1");
3141
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003142 r = pll->cinfo.clkout[0];
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003143 break;
3144 default:
3145 BUG();
3146 return 0;
3147 }
3148
3149 return r / lcd;
3150 } else {
3151 return dispc_fclk_rate();
Taneja, Architea751592011-03-08 05:50:35 -06003152 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003153}
3154
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003155unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003156{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003157 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003158
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303159 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303160 int pcd;
3161 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003162
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303163 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003164
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303165 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003166
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303167 r = dispc_mgr_lclk_rate(channel);
3168
3169 return r / pcd;
3170 } else {
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003171 return dispc.tv_pclk_rate;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303172 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003173}
3174
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003175void dispc_set_tv_pclk(unsigned long pclk)
3176{
3177 dispc.tv_pclk_rate = pclk;
3178}
3179
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303180unsigned long dispc_core_clk_rate(void)
3181{
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003182 return dispc.core_clk_rate;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303183}
3184
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303185static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3186{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003187 enum omap_channel channel;
3188
3189 if (plane == OMAP_DSS_WB)
3190 return 0;
3191
3192 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303193
3194 return dispc_mgr_pclk_rate(channel);
3195}
3196
3197static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3198{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003199 enum omap_channel channel;
3200
3201 if (plane == OMAP_DSS_WB)
3202 return 0;
3203
3204 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303205
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003206 return dispc_mgr_lclk_rate(channel);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303207}
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003208
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303209static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003210{
3211 int lcd, pcd;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303212 enum omap_dss_clk_source lcd_clk_src;
3213
3214 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3215
3216 lcd_clk_src = dss_get_lcd_clk_source(channel);
3217
3218 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3219 dss_get_generic_clk_source_name(lcd_clk_src),
3220 dss_feat_get_clk_source_name(lcd_clk_src));
3221
3222 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3223
3224 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3225 dispc_mgr_lclk_rate(channel), lcd);
3226 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3227 dispc_mgr_pclk_rate(channel), pcd);
3228}
3229
3230void dispc_dump_clocks(struct seq_file *s)
3231{
3232 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003233 u32 l;
Archit Taneja89a35e52011-04-12 13:52:23 +05303234 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003235
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003236 if (dispc_runtime_get())
3237 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003238
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003239 seq_printf(s, "- DISPC -\n");
3240
Archit Taneja067a57e2011-03-02 11:57:25 +05303241 seq_printf(s, "dispc fclk source = %s (%s)\n",
3242 dss_get_generic_clk_source_name(dispc_clk_src),
3243 dss_feat_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003244
3245 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00003246
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003247 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3248 seq_printf(s, "- DISPC-CORE-CLK -\n");
3249 l = dispc_read_reg(DISPC_DIVISOR);
3250 lcd = FLD_GET(l, 23, 16);
3251
3252 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3253 (dispc_fclk_rate()/lcd), lcd);
3254 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003255
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303256 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003257
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303258 if (dss_has_feature(FEAT_MGR_LCD2))
3259 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3260 if (dss_has_feature(FEAT_MGR_LCD3))
3261 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003262
3263 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003264}
3265
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003266static void dispc_dump_regs(struct seq_file *s)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003267{
Archit Taneja4dd2da12011-08-05 19:06:01 +05303268 int i, j;
3269 const char *mgr_names[] = {
3270 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3271 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3272 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303273 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303274 };
3275 const char *ovl_names[] = {
3276 [OMAP_DSS_GFX] = "GFX",
3277 [OMAP_DSS_VIDEO1] = "VID1",
3278 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303279 [OMAP_DSS_VIDEO3] = "VID3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303280 };
3281 const char **p_names;
3282
Archit Taneja9b372c22011-05-06 11:45:49 +05303283#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003284
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003285 if (dispc_runtime_get())
3286 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003287
Archit Taneja5010be82011-08-05 19:06:00 +05303288 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003289 DUMPREG(DISPC_REVISION);
3290 DUMPREG(DISPC_SYSCONFIG);
3291 DUMPREG(DISPC_SYSSTATUS);
3292 DUMPREG(DISPC_IRQSTATUS);
3293 DUMPREG(DISPC_IRQENABLE);
3294 DUMPREG(DISPC_CONTROL);
3295 DUMPREG(DISPC_CONFIG);
3296 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003297 DUMPREG(DISPC_LINE_STATUS);
3298 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05303299 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3300 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003301 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003302 if (dss_has_feature(FEAT_MGR_LCD2)) {
3303 DUMPREG(DISPC_CONTROL2);
3304 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003305 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303306 if (dss_has_feature(FEAT_MGR_LCD3)) {
3307 DUMPREG(DISPC_CONTROL3);
3308 DUMPREG(DISPC_CONFIG3);
3309 }
Tomi Valkeinen29fceee2013-11-14 11:38:25 +02003310 if (dss_has_feature(FEAT_MFLAG))
3311 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003312
Archit Taneja5010be82011-08-05 19:06:00 +05303313#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003314
Archit Taneja5010be82011-08-05 19:06:00 +05303315#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05303316#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003317 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303318 dispc_read_reg(DISPC_REG(i, r)))
3319
Archit Taneja4dd2da12011-08-05 19:06:01 +05303320 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303321
Archit Taneja4dd2da12011-08-05 19:06:01 +05303322 /* DISPC channel specific registers */
3323 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3324 DUMPREG(i, DISPC_DEFAULT_COLOR);
3325 DUMPREG(i, DISPC_TRANS_COLOR);
3326 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003327
Archit Taneja4dd2da12011-08-05 19:06:01 +05303328 if (i == OMAP_DSS_CHANNEL_DIGIT)
3329 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303330
Archit Taneja4dd2da12011-08-05 19:06:01 +05303331 DUMPREG(i, DISPC_TIMING_H);
3332 DUMPREG(i, DISPC_TIMING_V);
3333 DUMPREG(i, DISPC_POL_FREQ);
3334 DUMPREG(i, DISPC_DIVISORo);
Archit Taneja5010be82011-08-05 19:06:00 +05303335
Archit Taneja4dd2da12011-08-05 19:06:01 +05303336 DUMPREG(i, DISPC_DATA_CYCLE1);
3337 DUMPREG(i, DISPC_DATA_CYCLE2);
3338 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003339
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003340 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303341 DUMPREG(i, DISPC_CPR_COEF_R);
3342 DUMPREG(i, DISPC_CPR_COEF_G);
3343 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003344 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003345 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003346
Archit Taneja4dd2da12011-08-05 19:06:01 +05303347 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003348
Archit Taneja4dd2da12011-08-05 19:06:01 +05303349 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3350 DUMPREG(i, DISPC_OVL_BA0);
3351 DUMPREG(i, DISPC_OVL_BA1);
3352 DUMPREG(i, DISPC_OVL_POSITION);
3353 DUMPREG(i, DISPC_OVL_SIZE);
3354 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3355 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3356 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3357 DUMPREG(i, DISPC_OVL_ROW_INC);
3358 DUMPREG(i, DISPC_OVL_PIXEL_INC);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003359
Archit Taneja4dd2da12011-08-05 19:06:01 +05303360 if (dss_has_feature(FEAT_PRELOAD))
3361 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003362 if (dss_has_feature(FEAT_MFLAG))
3363 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003364
Archit Taneja4dd2da12011-08-05 19:06:01 +05303365 if (i == OMAP_DSS_GFX) {
3366 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3367 DUMPREG(i, DISPC_OVL_TABLE_BA);
3368 continue;
3369 }
3370
3371 DUMPREG(i, DISPC_OVL_FIR);
3372 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3373 DUMPREG(i, DISPC_OVL_ACCU0);
3374 DUMPREG(i, DISPC_OVL_ACCU1);
3375 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3376 DUMPREG(i, DISPC_OVL_BA0_UV);
3377 DUMPREG(i, DISPC_OVL_BA1_UV);
3378 DUMPREG(i, DISPC_OVL_FIR2);
3379 DUMPREG(i, DISPC_OVL_ACCU2_0);
3380 DUMPREG(i, DISPC_OVL_ACCU2_1);
3381 }
3382 if (dss_has_feature(FEAT_ATTR2))
3383 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
Archit Taneja5010be82011-08-05 19:06:00 +05303384 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003385
Archit Taneja5010be82011-08-05 19:06:00 +05303386#undef DISPC_REG
3387#undef DUMPREG
3388
3389#define DISPC_REG(plane, name, i) name(plane, i)
3390#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303391 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003392 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303393 dispc_read_reg(DISPC_REG(plane, name, i)))
3394
Archit Taneja4dd2da12011-08-05 19:06:01 +05303395 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303396
Archit Taneja4dd2da12011-08-05 19:06:01 +05303397 /* start from OMAP_DSS_VIDEO1 */
3398 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3399 for (j = 0; j < 8; j++)
3400 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303401
Archit Taneja4dd2da12011-08-05 19:06:01 +05303402 for (j = 0; j < 8; j++)
3403 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303404
Archit Taneja4dd2da12011-08-05 19:06:01 +05303405 for (j = 0; j < 5; j++)
3406 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003407
Archit Taneja4dd2da12011-08-05 19:06:01 +05303408 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3409 for (j = 0; j < 8; j++)
3410 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3411 }
Amber Jainab5ca072011-05-19 19:47:53 +05303412
Archit Taneja4dd2da12011-08-05 19:06:01 +05303413 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3414 for (j = 0; j < 8; j++)
3415 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303416
Archit Taneja4dd2da12011-08-05 19:06:01 +05303417 for (j = 0; j < 8; j++)
3418 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303419
Archit Taneja4dd2da12011-08-05 19:06:01 +05303420 for (j = 0; j < 8; j++)
3421 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3422 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003423 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003424
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003425 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05303426
3427#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003428#undef DUMPREG
3429}
3430
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003431/* calculate clock rates using dividers in cinfo */
3432int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3433 struct dispc_clock_info *cinfo)
3434{
3435 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3436 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003437 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003438 return -EINVAL;
3439
3440 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3441 cinfo->pck = cinfo->lck / cinfo->pck_div;
3442
3443 return 0;
3444}
3445
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003446bool dispc_div_calc(unsigned long dispc,
3447 unsigned long pck_min, unsigned long pck_max,
3448 dispc_div_calc_func func, void *data)
3449{
3450 int lckd, lckd_start, lckd_stop;
3451 int pckd, pckd_start, pckd_stop;
3452 unsigned long pck, lck;
3453 unsigned long lck_max;
3454 unsigned long pckd_hw_min, pckd_hw_max;
3455 unsigned min_fck_per_pck;
3456 unsigned long fck;
3457
3458#ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3459 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3460#else
3461 min_fck_per_pck = 0;
3462#endif
3463
3464 pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3465 pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3466
3467 lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
3468
3469 pck_min = pck_min ? pck_min : 1;
3470 pck_max = pck_max ? pck_max : ULONG_MAX;
3471
3472 lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul);
3473 lckd_stop = min(dispc / pck_min, 255ul);
3474
3475 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3476 lck = dispc / lckd;
3477
3478 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3479 pckd_stop = min(lck / pck_min, pckd_hw_max);
3480
3481 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3482 pck = lck / pckd;
3483
3484 /*
3485 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3486 * clock, which means we're configuring DISPC fclk here
3487 * also. Thus we need to use the calculated lck. For
3488 * OMAP4+ the DISPC fclk is a separate clock.
3489 */
3490 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3491 fck = dispc_core_clk_rate();
3492 else
3493 fck = lck;
3494
3495 if (fck < pck * min_fck_per_pck)
3496 continue;
3497
3498 if (func(lckd, pckd, lck, pck, data))
3499 return true;
3500 }
3501 }
3502
3503 return false;
3504}
3505
Archit Tanejaf0d08f82012-06-29 14:00:54 +05303506void dispc_mgr_set_clock_div(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003507 const struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003508{
3509 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3510 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3511
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003512 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003513}
3514
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003515int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003516 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003517{
3518 unsigned long fck;
3519
3520 fck = dispc_fclk_rate();
3521
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003522 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3523 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003524
3525 cinfo->lck = fck / cinfo->lck_div;
3526 cinfo->pck = cinfo->lck / cinfo->pck_div;
3527
3528 return 0;
3529}
3530
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003531u32 dispc_read_irqstatus(void)
3532{
3533 return dispc_read_reg(DISPC_IRQSTATUS);
3534}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003535EXPORT_SYMBOL(dispc_read_irqstatus);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003536
3537void dispc_clear_irqstatus(u32 mask)
3538{
3539 dispc_write_reg(DISPC_IRQSTATUS, mask);
3540}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003541EXPORT_SYMBOL(dispc_clear_irqstatus);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003542
3543u32 dispc_read_irqenable(void)
3544{
3545 return dispc_read_reg(DISPC_IRQENABLE);
3546}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003547EXPORT_SYMBOL(dispc_read_irqenable);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003548
3549void dispc_write_irqenable(u32 mask)
3550{
3551 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3552
3553 /* clear the irqstatus for newly enabled irqs */
3554 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3555
3556 dispc_write_reg(DISPC_IRQENABLE, mask);
3557}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003558EXPORT_SYMBOL(dispc_write_irqenable);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003559
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003560void dispc_enable_sidle(void)
3561{
3562 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3563}
3564
3565void dispc_disable_sidle(void)
3566{
3567 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3568}
3569
3570static void _omap_dispc_initial_config(void)
3571{
3572 u32 l;
3573
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003574 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3575 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3576 l = dispc_read_reg(DISPC_DIVISOR);
3577 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3578 l = FLD_MOD(l, 1, 0, 0);
3579 l = FLD_MOD(l, 1, 23, 16);
3580 dispc_write_reg(DISPC_DIVISOR, l);
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003581
3582 dispc.core_clk_rate = dispc_fclk_rate();
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003583 }
3584
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003585 /* FUNCGATED */
Archit Taneja6ced40b2010-12-02 11:27:13 +00003586 if (dss_has_feature(FEAT_FUNCGATED))
3587 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003588
Archit Taneja6e5264b2012-09-11 12:04:47 +05303589 dispc_setup_color_conv_coef();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003590
3591 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3592
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003593 dispc_init_fifos();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003594
3595 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05303596
3597 dispc_ovl_enable_zorder_planes();
Archit Tanejad0df9a22013-03-26 19:15:25 +05303598
3599 if (dispc.feat->mstandby_workaround)
3600 REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003601}
3602
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303603static const struct dispc_features omap24xx_dispc_feats __initconst = {
3604 .sw_start = 5,
3605 .fp_start = 15,
3606 .bp_start = 27,
3607 .sw_max = 64,
3608 .vp_max = 255,
3609 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303610 .mgr_width_start = 10,
3611 .mgr_height_start = 26,
3612 .mgr_width_max = 2048,
3613 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303614 .max_lcd_pclk = 66500000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303615 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3616 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003617 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003618 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303619 .set_max_preload = false,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303620};
3621
3622static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
3623 .sw_start = 5,
3624 .fp_start = 15,
3625 .bp_start = 27,
3626 .sw_max = 64,
3627 .vp_max = 255,
3628 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303629 .mgr_width_start = 10,
3630 .mgr_height_start = 26,
3631 .mgr_width_max = 2048,
3632 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303633 .max_lcd_pclk = 173000000,
3634 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303635 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3636 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003637 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003638 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303639 .set_max_preload = false,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303640};
3641
3642static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
3643 .sw_start = 7,
3644 .fp_start = 19,
3645 .bp_start = 31,
3646 .sw_max = 256,
3647 .vp_max = 4095,
3648 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303649 .mgr_width_start = 10,
3650 .mgr_height_start = 26,
3651 .mgr_width_max = 2048,
3652 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303653 .max_lcd_pclk = 173000000,
3654 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303655 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3656 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003657 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003658 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303659 .set_max_preload = false,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303660};
3661
3662static const struct dispc_features omap44xx_dispc_feats __initconst = {
3663 .sw_start = 7,
3664 .fp_start = 19,
3665 .bp_start = 31,
3666 .sw_max = 256,
3667 .vp_max = 4095,
3668 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303669 .mgr_width_start = 10,
3670 .mgr_height_start = 26,
3671 .mgr_width_max = 2048,
3672 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303673 .max_lcd_pclk = 170000000,
3674 .max_tv_pclk = 185625000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303675 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3676 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003677 .num_fifos = 5,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03003678 .gfx_fifo_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303679 .set_max_preload = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303680};
3681
Archit Taneja264236f2012-11-14 13:50:16 +05303682static const struct dispc_features omap54xx_dispc_feats __initconst = {
3683 .sw_start = 7,
3684 .fp_start = 19,
3685 .bp_start = 31,
3686 .sw_max = 256,
3687 .vp_max = 4095,
3688 .hp_max = 4096,
3689 .mgr_width_start = 11,
3690 .mgr_height_start = 27,
3691 .mgr_width_max = 4096,
3692 .mgr_height_max = 4096,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303693 .max_lcd_pclk = 170000000,
3694 .max_tv_pclk = 186000000,
Archit Taneja264236f2012-11-14 13:50:16 +05303695 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3696 .calc_core_clk = calc_core_clk_44xx,
3697 .num_fifos = 5,
3698 .gfx_fifo_workaround = true,
Archit Tanejad0df9a22013-03-26 19:15:25 +05303699 .mstandby_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303700 .set_max_preload = true,
Archit Taneja264236f2012-11-14 13:50:16 +05303701};
3702
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003703static int __init dispc_init_features(struct platform_device *pdev)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303704{
3705 const struct dispc_features *src;
3706 struct dispc_features *dst;
3707
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003708 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303709 if (!dst) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003710 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303711 return -ENOMEM;
3712 }
3713
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +03003714 switch (omapdss_get_version()) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003715 case OMAPDSS_VER_OMAP24xx:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303716 src = &omap24xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003717 break;
3718
3719 case OMAPDSS_VER_OMAP34xx_ES1:
3720 src = &omap34xx_rev1_0_dispc_feats;
3721 break;
3722
3723 case OMAPDSS_VER_OMAP34xx_ES3:
3724 case OMAPDSS_VER_OMAP3630:
3725 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +05303726 case OMAPDSS_VER_AM43xx:
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003727 src = &omap34xx_rev3_0_dispc_feats;
3728 break;
3729
3730 case OMAPDSS_VER_OMAP4430_ES1:
3731 case OMAPDSS_VER_OMAP4430_ES2:
3732 case OMAPDSS_VER_OMAP4:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303733 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003734 break;
3735
3736 case OMAPDSS_VER_OMAP5:
Tomi Valkeinen93550922014-12-31 11:25:48 +02003737 case OMAPDSS_VER_DRA7xx:
Archit Taneja264236f2012-11-14 13:50:16 +05303738 src = &omap54xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003739 break;
3740
3741 default:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303742 return -ENODEV;
3743 }
3744
3745 memcpy(dst, src, sizeof(*dst));
3746 dispc.feat = dst;
3747
3748 return 0;
3749}
3750
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003751static irqreturn_t dispc_irq_handler(int irq, void *arg)
3752{
3753 if (!dispc.is_enabled)
3754 return IRQ_NONE;
3755
3756 return dispc.user_handler(irq, dispc.user_data);
3757}
3758
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003759int dispc_request_irq(irq_handler_t handler, void *dev_id)
3760{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003761 int r;
3762
3763 if (dispc.user_handler != NULL)
3764 return -EBUSY;
3765
3766 dispc.user_handler = handler;
3767 dispc.user_data = dev_id;
3768
3769 /* ensure the dispc_irq_handler sees the values above */
3770 smp_wmb();
3771
3772 r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler,
3773 IRQF_SHARED, "OMAP DISPC", &dispc);
3774 if (r) {
3775 dispc.user_handler = NULL;
3776 dispc.user_data = NULL;
3777 }
3778
3779 return r;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003780}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003781EXPORT_SYMBOL(dispc_request_irq);
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003782
3783void dispc_free_irq(void *dev_id)
3784{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003785 devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc);
3786
3787 dispc.user_handler = NULL;
3788 dispc.user_data = NULL;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003789}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003790EXPORT_SYMBOL(dispc_free_irq);
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003791
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003792/* DISPC HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003793static int __init omap_dispchw_probe(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003794{
3795 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00003796 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003797 struct resource *dispc_mem;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003798 struct device_node *np = pdev->dev.of_node;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003799
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003800 dispc.pdev = pdev;
3801
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003802 r = dispc_init_features(dispc.pdev);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303803 if (r)
3804 return r;
3805
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003806 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3807 if (!dispc_mem) {
3808 DSSERR("can't get IORESOURCE_MEM DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003809 return -EINVAL;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003810 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003811
Julia Lawall6e2a14d2012-01-24 14:00:45 +01003812 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3813 resource_size(dispc_mem));
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003814 if (!dispc.base) {
3815 DSSERR("can't ioremap DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003816 return -ENOMEM;
archit tanejaaffe3602011-02-23 08:41:03 +00003817 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003818
archit tanejaaffe3602011-02-23 08:41:03 +00003819 dispc.irq = platform_get_irq(dispc.pdev, 0);
3820 if (dispc.irq < 0) {
3821 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003822 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00003823 }
3824
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003825 if (np && of_property_read_bool(np, "syscon-pol")) {
3826 dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
3827 if (IS_ERR(dispc.syscon_pol)) {
3828 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
3829 return PTR_ERR(dispc.syscon_pol);
3830 }
3831
3832 if (of_property_read_u32_index(np, "syscon-pol", 1,
3833 &dispc.syscon_pol_offset)) {
3834 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
3835 return -EINVAL;
3836 }
3837 }
3838
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003839 pm_runtime_enable(&pdev->dev);
3840
3841 r = dispc_runtime_get();
3842 if (r)
3843 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003844
3845 _omap_dispc_initial_config();
3846
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003847 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00003848 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003849 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3850
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003851 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003852
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03003853 dss_init_overlay_managers();
3854
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003855 dss_debugfs_create_file("dispc", dispc_dump_regs);
3856
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003857 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003858
3859err_runtime_get:
3860 pm_runtime_disable(&pdev->dev);
archit tanejaaffe3602011-02-23 08:41:03 +00003861 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003862}
3863
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003864static int __exit omap_dispchw_remove(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003865{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003866 pm_runtime_disable(&pdev->dev);
3867
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03003868 dss_uninit_overlay_managers();
3869
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003870 return 0;
3871}
3872
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003873static int dispc_runtime_suspend(struct device *dev)
3874{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003875 dispc.is_enabled = false;
3876 /* ensure the dispc_irq_handler sees the is_enabled value */
3877 smp_wmb();
3878 /* wait for current handler to finish before turning the DISPC off */
3879 synchronize_irq(dispc.irq);
3880
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003881 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003882
3883 return 0;
3884}
3885
3886static int dispc_runtime_resume(struct device *dev)
3887{
Tomi Valkeinen9229b512014-02-14 09:37:09 +02003888 /*
3889 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
3890 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
3891 * _omap_dispc_initial_config(). We can thus use it to detect if
3892 * we have lost register context.
3893 */
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003894 if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
3895 _omap_dispc_initial_config();
Tomi Valkeinen9229b512014-02-14 09:37:09 +02003896
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003897 dispc_restore_context();
3898 }
Tomi Valkeinenbe07dcd72013-11-21 16:01:40 +02003899
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003900 dispc.is_enabled = true;
3901 /* ensure the dispc_irq_handler sees the is_enabled value */
3902 smp_wmb();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003903
3904 return 0;
3905}
3906
3907static const struct dev_pm_ops dispc_pm_ops = {
3908 .runtime_suspend = dispc_runtime_suspend,
3909 .runtime_resume = dispc_runtime_resume,
3910};
3911
Tomi Valkeinend7977f82013-12-17 11:54:02 +02003912static const struct of_device_id dispc_of_match[] = {
3913 { .compatible = "ti,omap2-dispc", },
3914 { .compatible = "ti,omap3-dispc", },
3915 { .compatible = "ti,omap4-dispc", },
Tomi Valkeinen2e7e6b62014-04-16 13:16:43 +03003916 { .compatible = "ti,omap5-dispc", },
Tomi Valkeinen93550922014-12-31 11:25:48 +02003917 { .compatible = "ti,dra7-dispc", },
Tomi Valkeinend7977f82013-12-17 11:54:02 +02003918 {},
3919};
3920
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003921static struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003922 .remove = __exit_p(omap_dispchw_remove),
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003923 .driver = {
3924 .name = "omapdss_dispc",
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003925 .pm = &dispc_pm_ops,
Tomi Valkeinend7977f82013-12-17 11:54:02 +02003926 .of_match_table = dispc_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +03003927 .suppress_bind_attrs = true,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003928 },
3929};
3930
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003931int __init dispc_init_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003932{
Tomi Valkeinen11436e12012-03-07 12:53:18 +02003933 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003934}
3935
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003936void __exit dispc_uninit_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003937{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02003938 platform_driver_unregister(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003939}