blob: 0bdb587cb48c464b8393c95a5f061abc2fe49fb8 [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;
Tomi Valkeinenf2aee312015-04-10 12:48:34 +030098
99 /* PIXEL_INC is not added to the last pixel of a line */
100 bool last_pixel_inc_missing:1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530101};
102
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300103#define DISPC_MAX_NR_FIFOS 5
104
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200105static struct {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +0000106 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200107 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300108
archit tanejaaffe3602011-02-23 08:41:03 +0000109 int irq;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300110 irq_handler_t user_handler;
111 void *user_data;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200112
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200113 unsigned long core_clk_rate;
Tomi Valkeinen5391e872013-05-16 10:44:13 +0300114 unsigned long tv_pclk_rate;
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200115
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300116 u32 fifo_size[DISPC_MAX_NR_FIFOS];
117 /* maps which plane is using a fifo. fifo-id -> plane-id */
118 int fifo_assignment[DISPC_MAX_NR_FIFOS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200119
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300120 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200121 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200122
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530123 const struct dispc_features *feat;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300124
125 bool is_enabled;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +0000126
127 struct regmap *syscon_pol;
128 u32 syscon_pol_offset;
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200129
130 /* DISPC_CONTROL & DISPC_CONFIG lock*/
131 spinlock_t control_lock;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200132} dispc;
133
Amber Jain0d66cbb2011-05-19 19:47:54 +0530134enum omap_color_component {
135 /* used for all color formats for OMAP3 and earlier
136 * and for RGB and Y color component on OMAP4
137 */
138 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
139 /* used for UV component for
140 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
141 * color formats on OMAP4
142 */
143 DISPC_COLOR_COMPONENT_UV = 1 << 1,
144};
145
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530146enum mgr_reg_fields {
147 DISPC_MGR_FLD_ENABLE,
148 DISPC_MGR_FLD_STNTFT,
149 DISPC_MGR_FLD_GO,
150 DISPC_MGR_FLD_TFTDATALINES,
151 DISPC_MGR_FLD_STALLMODE,
152 DISPC_MGR_FLD_TCKENABLE,
153 DISPC_MGR_FLD_TCKSELECTION,
154 DISPC_MGR_FLD_CPR,
155 DISPC_MGR_FLD_FIFOHANDCHECK,
156 /* used to maintain a count of the above fields */
157 DISPC_MGR_FLD_NUM,
158};
159
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300160struct dispc_reg_field {
161 u16 reg;
162 u8 high;
163 u8 low;
164};
165
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530166static const struct {
167 const char *name;
168 u32 vsync_irq;
169 u32 framedone_irq;
170 u32 sync_lost_irq;
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300171 struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530172} mgr_desc[] = {
173 [OMAP_DSS_CHANNEL_LCD] = {
174 .name = "LCD",
175 .vsync_irq = DISPC_IRQ_VSYNC,
176 .framedone_irq = DISPC_IRQ_FRAMEDONE,
177 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
178 .reg_desc = {
179 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
180 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
181 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
182 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
183 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
184 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
185 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
186 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
187 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
188 },
189 },
190 [OMAP_DSS_CHANNEL_DIGIT] = {
191 .name = "DIGIT",
192 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200193 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530194 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
195 .reg_desc = {
196 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
197 [DISPC_MGR_FLD_STNTFT] = { },
198 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
199 [DISPC_MGR_FLD_TFTDATALINES] = { },
200 [DISPC_MGR_FLD_STALLMODE] = { },
201 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
202 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
203 [DISPC_MGR_FLD_CPR] = { },
204 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
205 },
206 },
207 [OMAP_DSS_CHANNEL_LCD2] = {
208 .name = "LCD2",
209 .vsync_irq = DISPC_IRQ_VSYNC2,
210 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
211 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
212 .reg_desc = {
213 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
214 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
215 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
216 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
217 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
218 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
219 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
220 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
221 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
222 },
223 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530224 [OMAP_DSS_CHANNEL_LCD3] = {
225 .name = "LCD3",
226 .vsync_irq = DISPC_IRQ_VSYNC3,
227 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
228 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
229 .reg_desc = {
230 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
231 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
232 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
233 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
234 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
235 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
236 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
237 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
238 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
239 },
240 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530241};
242
Archit Taneja6e5264b2012-09-11 12:04:47 +0530243struct color_conv_coef {
244 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
245 int full_range;
246};
247
Archit Taneja3e8a6ff2012-09-26 16:58:52 +0530248static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
249static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200250
Archit Taneja55978cc2011-05-06 11:45:51 +0530251static inline void dispc_write_reg(const u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200252{
Archit Taneja55978cc2011-05-06 11:45:51 +0530253 __raw_writel(val, dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200254}
255
Archit Taneja55978cc2011-05-06 11:45:51 +0530256static inline u32 dispc_read_reg(const u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200257{
Archit Taneja55978cc2011-05-06 11:45:51 +0530258 return __raw_readl(dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200259}
260
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530261static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
262{
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 return REG_GET(rfld.reg, rfld.high, rfld.low);
265}
266
267static void mgr_fld_write(enum omap_channel channel,
268 enum mgr_reg_fields regfld, int val) {
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300269 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200270 const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG;
271 unsigned long flags;
272
273 if (need_lock)
274 spin_lock_irqsave(&dispc.control_lock, flags);
275
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530276 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200277
278 if (need_lock)
279 spin_unlock_irqrestore(&dispc.control_lock, flags);
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530280}
281
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200282#define SR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530283 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200284#define RR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530285 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200286
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300287static void dispc_save_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200288{
Archit Tanejac6104b82011-08-05 19:06:02 +0530289 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200290
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300291 DSSDBG("dispc_save_context\n");
292
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200293 SR(IRQENABLE);
294 SR(CONTROL);
295 SR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200296 SR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530297 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
298 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300299 SR(GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000300 if (dss_has_feature(FEAT_MGR_LCD2)) {
301 SR(CONTROL2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000302 SR(CONFIG2);
303 }
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530304 if (dss_has_feature(FEAT_MGR_LCD3)) {
305 SR(CONTROL3);
306 SR(CONFIG3);
307 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200308
Archit Tanejac6104b82011-08-05 19:06:02 +0530309 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
310 SR(DEFAULT_COLOR(i));
311 SR(TRANS_COLOR(i));
312 SR(SIZE_MGR(i));
313 if (i == OMAP_DSS_CHANNEL_DIGIT)
314 continue;
315 SR(TIMING_H(i));
316 SR(TIMING_V(i));
317 SR(POL_FREQ(i));
318 SR(DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200319
Archit Tanejac6104b82011-08-05 19:06:02 +0530320 SR(DATA_CYCLE1(i));
321 SR(DATA_CYCLE2(i));
322 SR(DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200323
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300324 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530325 SR(CPR_COEF_R(i));
326 SR(CPR_COEF_G(i));
327 SR(CPR_COEF_B(i));
328 }
329 }
330
331 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
332 SR(OVL_BA0(i));
333 SR(OVL_BA1(i));
334 SR(OVL_POSITION(i));
335 SR(OVL_SIZE(i));
336 SR(OVL_ATTRIBUTES(i));
337 SR(OVL_FIFO_THRESHOLD(i));
338 SR(OVL_ROW_INC(i));
339 SR(OVL_PIXEL_INC(i));
340 if (dss_has_feature(FEAT_PRELOAD))
341 SR(OVL_PRELOAD(i));
342 if (i == OMAP_DSS_GFX) {
343 SR(OVL_WINDOW_SKIP(i));
344 SR(OVL_TABLE_BA(i));
345 continue;
346 }
347 SR(OVL_FIR(i));
348 SR(OVL_PICTURE_SIZE(i));
349 SR(OVL_ACCU0(i));
350 SR(OVL_ACCU1(i));
351
352 for (j = 0; j < 8; j++)
353 SR(OVL_FIR_COEF_H(i, j));
354
355 for (j = 0; j < 8; j++)
356 SR(OVL_FIR_COEF_HV(i, j));
357
358 for (j = 0; j < 5; j++)
359 SR(OVL_CONV_COEF(i, j));
360
361 if (dss_has_feature(FEAT_FIR_COEF_V)) {
362 for (j = 0; j < 8; j++)
363 SR(OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300364 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000365
Archit Tanejac6104b82011-08-05 19:06:02 +0530366 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
367 SR(OVL_BA0_UV(i));
368 SR(OVL_BA1_UV(i));
369 SR(OVL_FIR2(i));
370 SR(OVL_ACCU2_0(i));
371 SR(OVL_ACCU2_1(i));
372
373 for (j = 0; j < 8; j++)
374 SR(OVL_FIR_COEF_H2(i, j));
375
376 for (j = 0; j < 8; j++)
377 SR(OVL_FIR_COEF_HV2(i, j));
378
379 for (j = 0; j < 8; j++)
380 SR(OVL_FIR_COEF_V2(i, j));
381 }
382 if (dss_has_feature(FEAT_ATTR2))
383 SR(OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000384 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200385
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600386 if (dss_has_feature(FEAT_CORE_CLK_DIV))
387 SR(DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300388
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300389 dispc.ctx_valid = true;
390
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200391 DSSDBG("context saved\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200392}
393
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300394static void dispc_restore_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200395{
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200396 int i, j;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300397
398 DSSDBG("dispc_restore_context\n");
399
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300400 if (!dispc.ctx_valid)
401 return;
402
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200403 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200404 /*RR(CONTROL);*/
405 RR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200406 RR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530407 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
408 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300409 RR(GLOBAL_ALPHA);
Archit Tanejac6104b82011-08-05 19:06:02 +0530410 if (dss_has_feature(FEAT_MGR_LCD2))
Sumit Semwal2a205f32010-12-02 11:27:12 +0000411 RR(CONFIG2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530412 if (dss_has_feature(FEAT_MGR_LCD3))
413 RR(CONFIG3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200414
Archit Tanejac6104b82011-08-05 19:06:02 +0530415 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
416 RR(DEFAULT_COLOR(i));
417 RR(TRANS_COLOR(i));
418 RR(SIZE_MGR(i));
419 if (i == OMAP_DSS_CHANNEL_DIGIT)
420 continue;
421 RR(TIMING_H(i));
422 RR(TIMING_V(i));
423 RR(POL_FREQ(i));
424 RR(DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530425
Archit Tanejac6104b82011-08-05 19:06:02 +0530426 RR(DATA_CYCLE1(i));
427 RR(DATA_CYCLE2(i));
428 RR(DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000429
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300430 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530431 RR(CPR_COEF_R(i));
432 RR(CPR_COEF_G(i));
433 RR(CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300434 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000435 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200436
Archit Tanejac6104b82011-08-05 19:06:02 +0530437 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
438 RR(OVL_BA0(i));
439 RR(OVL_BA1(i));
440 RR(OVL_POSITION(i));
441 RR(OVL_SIZE(i));
442 RR(OVL_ATTRIBUTES(i));
443 RR(OVL_FIFO_THRESHOLD(i));
444 RR(OVL_ROW_INC(i));
445 RR(OVL_PIXEL_INC(i));
446 if (dss_has_feature(FEAT_PRELOAD))
447 RR(OVL_PRELOAD(i));
448 if (i == OMAP_DSS_GFX) {
449 RR(OVL_WINDOW_SKIP(i));
450 RR(OVL_TABLE_BA(i));
451 continue;
452 }
453 RR(OVL_FIR(i));
454 RR(OVL_PICTURE_SIZE(i));
455 RR(OVL_ACCU0(i));
456 RR(OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200457
Archit Tanejac6104b82011-08-05 19:06:02 +0530458 for (j = 0; j < 8; j++)
459 RR(OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200460
Archit Tanejac6104b82011-08-05 19:06:02 +0530461 for (j = 0; j < 8; j++)
462 RR(OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200463
Archit Tanejac6104b82011-08-05 19:06:02 +0530464 for (j = 0; j < 5; j++)
465 RR(OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200466
Archit Tanejac6104b82011-08-05 19:06:02 +0530467 if (dss_has_feature(FEAT_FIR_COEF_V)) {
468 for (j = 0; j < 8; j++)
469 RR(OVL_FIR_COEF_V(i, j));
470 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200471
Archit Tanejac6104b82011-08-05 19:06:02 +0530472 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
473 RR(OVL_BA0_UV(i));
474 RR(OVL_BA1_UV(i));
475 RR(OVL_FIR2(i));
476 RR(OVL_ACCU2_0(i));
477 RR(OVL_ACCU2_1(i));
478
479 for (j = 0; j < 8; j++)
480 RR(OVL_FIR_COEF_H2(i, j));
481
482 for (j = 0; j < 8; j++)
483 RR(OVL_FIR_COEF_HV2(i, j));
484
485 for (j = 0; j < 8; j++)
486 RR(OVL_FIR_COEF_V2(i, j));
487 }
488 if (dss_has_feature(FEAT_ATTR2))
489 RR(OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300490 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200491
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600492 if (dss_has_feature(FEAT_CORE_CLK_DIV))
493 RR(DIVISOR);
494
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200495 /* enable last, because LCD & DIGIT enable are here */
496 RR(CONTROL);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000497 if (dss_has_feature(FEAT_MGR_LCD2))
498 RR(CONTROL2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530499 if (dss_has_feature(FEAT_MGR_LCD3))
500 RR(CONTROL3);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200501 /* clear spurious SYNC_LOST_DIGIT interrupts */
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +0300502 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200503
504 /*
505 * enable last so IRQs won't trigger before
506 * the context is fully restored
507 */
508 RR(IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300509
510 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200511}
512
513#undef SR
514#undef RR
515
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300516int dispc_runtime_get(void)
517{
518 int r;
519
520 DSSDBG("dispc_runtime_get\n");
521
522 r = pm_runtime_get_sync(&dispc.pdev->dev);
523 WARN_ON(r < 0);
524 return r < 0 ? r : 0;
525}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200526EXPORT_SYMBOL(dispc_runtime_get);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300527
528void dispc_runtime_put(void)
529{
530 int r;
531
532 DSSDBG("dispc_runtime_put\n");
533
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200534 r = pm_runtime_put_sync(&dispc.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300535 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300536}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200537EXPORT_SYMBOL(dispc_runtime_put);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300538
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200539u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
540{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530541 return mgr_desc[channel].vsync_irq;
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200542}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200543EXPORT_SYMBOL(dispc_mgr_get_vsync_irq);
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200544
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200545u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
546{
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200547 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv)
548 return 0;
549
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530550 return mgr_desc[channel].framedone_irq;
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200551}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200552EXPORT_SYMBOL(dispc_mgr_get_framedone_irq);
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200553
Tomi Valkeinencb699202012-10-17 10:38:52 +0300554u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
555{
556 return mgr_desc[channel].sync_lost_irq;
557}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200558EXPORT_SYMBOL(dispc_mgr_get_sync_lost_irq);
Tomi Valkeinencb699202012-10-17 10:38:52 +0300559
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530560u32 dispc_wb_get_framedone_irq(void)
561{
562 return DISPC_IRQ_FRAMEDONEWB;
563}
564
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300565bool dispc_mgr_go_busy(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200566{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530567 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200568}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200569EXPORT_SYMBOL(dispc_mgr_go_busy);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200570
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300571void dispc_mgr_go(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200572{
Tomi Valkeinen3c91ee82012-10-19 15:06:07 +0300573 WARN_ON(dispc_mgr_is_enabled(channel) == false);
574 WARN_ON(dispc_mgr_go_busy(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200575
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530576 DSSDBG("GO %s\n", mgr_desc[channel].name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200577
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530578 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200579}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200580EXPORT_SYMBOL(dispc_mgr_go);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200581
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530582bool dispc_wb_go_busy(void)
583{
584 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
585}
586
587void dispc_wb_go(void)
588{
589 enum omap_plane plane = OMAP_DSS_WB;
590 bool enable, go;
591
592 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
593
594 if (!enable)
595 return;
596
597 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
598 if (go) {
599 DSSERR("GO bit not down for WB\n");
600 return;
601 }
602
603 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
604}
605
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300606static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200607{
Archit Taneja9b372c22011-05-06 11:45:49 +0530608 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200609}
610
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300611static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200612{
Archit Taneja9b372c22011-05-06 11:45:49 +0530613 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200614}
615
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300616static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200617{
Archit Taneja9b372c22011-05-06 11:45:49 +0530618 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200619}
620
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300621static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530622{
623 BUG_ON(plane == OMAP_DSS_GFX);
624
625 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
626}
627
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300628static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
629 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530630{
631 BUG_ON(plane == OMAP_DSS_GFX);
632
633 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
634}
635
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300636static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530637{
638 BUG_ON(plane == OMAP_DSS_GFX);
639
640 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
641}
642
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530643static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
644 int fir_vinc, int five_taps,
645 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200646{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530647 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200648 int i;
649
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530650 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
651 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200652
653 for (i = 0; i < 8; i++) {
654 u32 h, hv;
655
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530656 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
657 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
658 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
659 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
660 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
661 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
662 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
663 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200664
Amber Jain0d66cbb2011-05-19 19:47:54 +0530665 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300666 dispc_ovl_write_firh_reg(plane, i, h);
667 dispc_ovl_write_firhv_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530668 } else {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300669 dispc_ovl_write_firh2_reg(plane, i, h);
670 dispc_ovl_write_firhv2_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530671 }
672
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200673 }
674
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200675 if (five_taps) {
676 for (i = 0; i < 8; i++) {
677 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530678 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
679 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530680 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300681 dispc_ovl_write_firv_reg(plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530682 else
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300683 dispc_ovl_write_firv2_reg(plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200684 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200685 }
686}
687
Archit Taneja6e5264b2012-09-11 12:04:47 +0530688
689static void dispc_ovl_write_color_conv_coef(enum omap_plane plane,
690 const struct color_conv_coef *ct)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200691{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200692#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
693
Archit Taneja6e5264b2012-09-11 12:04:47 +0530694 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
695 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
696 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
697 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
698 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200699
Archit Taneja6e5264b2012-09-11 12:04:47 +0530700 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200701
702#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200703}
704
Archit Taneja6e5264b2012-09-11 12:04:47 +0530705static void dispc_setup_color_conv_coef(void)
706{
707 int i;
708 int num_ovl = dss_feat_get_num_ovls();
709 int num_wb = dss_feat_get_num_wbs();
710 const struct color_conv_coef ctbl_bt601_5_ovl = {
711 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
712 };
713 const struct color_conv_coef ctbl_bt601_5_wb = {
714 66, 112, -38, 129, -94, -74, 25, -18, 112, 0,
715 };
716
717 for (i = 1; i < num_ovl; i++)
718 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
719
720 for (; i < num_wb; i++)
721 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_wb);
722}
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200723
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300724static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200725{
Archit Taneja9b372c22011-05-06 11:45:49 +0530726 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200727}
728
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300729static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200730{
Archit Taneja9b372c22011-05-06 11:45:49 +0530731 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200732}
733
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300734static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530735{
736 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
737}
738
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300739static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530740{
741 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
742}
743
Archit Tanejad79db852012-09-22 12:30:17 +0530744static void dispc_ovl_set_pos(enum omap_plane plane,
745 enum omap_overlay_caps caps, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200746{
Archit Tanejad79db852012-09-22 12:30:17 +0530747 u32 val;
748
749 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
750 return;
751
752 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530753
754 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200755}
756
Archit Taneja78b687f2012-09-21 14:51:49 +0530757static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
758 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200759{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200760 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530761
Archit Taneja36d87d92012-07-28 22:59:03 +0530762 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
Archit Taneja9b372c22011-05-06 11:45:49 +0530763 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
764 else
765 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200766}
767
Archit Taneja78b687f2012-09-21 14:51:49 +0530768static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
769 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200770{
771 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200772
773 BUG_ON(plane == OMAP_DSS_GFX);
774
775 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530776
Archit Taneja36d87d92012-07-28 22:59:03 +0530777 if (plane == OMAP_DSS_WB)
778 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
779 else
780 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200781}
782
Archit Taneja5b54ed32012-09-26 16:55:27 +0530783static void dispc_ovl_set_zorder(enum omap_plane plane,
784 enum omap_overlay_caps caps, u8 zorder)
Archit Taneja54128702011-09-08 11:29:17 +0530785{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530786 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
Archit Taneja54128702011-09-08 11:29:17 +0530787 return;
788
789 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
790}
791
792static void dispc_ovl_enable_zorder_planes(void)
793{
794 int i;
795
796 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
797 return;
798
799 for (i = 0; i < dss_feat_get_num_ovls(); i++)
800 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
801}
802
Archit Taneja5b54ed32012-09-26 16:55:27 +0530803static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
804 enum omap_overlay_caps caps, bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100805{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530806 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100807 return;
808
Archit Taneja9b372c22011-05-06 11:45:49 +0530809 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100810}
811
Archit Taneja5b54ed32012-09-26 16:55:27 +0530812static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
813 enum omap_overlay_caps caps, u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200814{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530815 static const unsigned shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300816 int shift;
817
Archit Taneja5b54ed32012-09-26 16:55:27 +0530818 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100819 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530820
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300821 shift = shifts[plane];
822 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200823}
824
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300825static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200826{
Archit Taneja9b372c22011-05-06 11:45:49 +0530827 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200828}
829
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300830static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200831{
Archit Taneja9b372c22011-05-06 11:45:49 +0530832 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200833}
834
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300835static void dispc_ovl_set_color_mode(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200836 enum omap_color_mode color_mode)
837{
838 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +0530839 if (plane != OMAP_DSS_GFX) {
840 switch (color_mode) {
841 case OMAP_DSS_COLOR_NV12:
842 m = 0x0; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530843 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530844 m = 0x1; break;
845 case OMAP_DSS_COLOR_RGBA16:
846 m = 0x2; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530847 case OMAP_DSS_COLOR_RGB12U:
Amber Jainf20e4222011-05-19 19:47:50 +0530848 m = 0x4; break;
849 case OMAP_DSS_COLOR_ARGB16:
850 m = 0x5; break;
851 case OMAP_DSS_COLOR_RGB16:
852 m = 0x6; break;
853 case OMAP_DSS_COLOR_ARGB16_1555:
854 m = 0x7; break;
855 case OMAP_DSS_COLOR_RGB24U:
856 m = 0x8; break;
857 case OMAP_DSS_COLOR_RGB24P:
858 m = 0x9; break;
859 case OMAP_DSS_COLOR_YUV2:
860 m = 0xa; break;
861 case OMAP_DSS_COLOR_UYVY:
862 m = 0xb; break;
863 case OMAP_DSS_COLOR_ARGB32:
864 m = 0xc; break;
865 case OMAP_DSS_COLOR_RGBA32:
866 m = 0xd; break;
867 case OMAP_DSS_COLOR_RGBX32:
868 m = 0xe; break;
869 case OMAP_DSS_COLOR_XRGB16_1555:
870 m = 0xf; break;
871 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300872 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530873 }
874 } else {
875 switch (color_mode) {
876 case OMAP_DSS_COLOR_CLUT1:
877 m = 0x0; break;
878 case OMAP_DSS_COLOR_CLUT2:
879 m = 0x1; break;
880 case OMAP_DSS_COLOR_CLUT4:
881 m = 0x2; break;
882 case OMAP_DSS_COLOR_CLUT8:
883 m = 0x3; break;
884 case OMAP_DSS_COLOR_RGB12U:
885 m = 0x4; break;
886 case OMAP_DSS_COLOR_ARGB16:
887 m = 0x5; break;
888 case OMAP_DSS_COLOR_RGB16:
889 m = 0x6; break;
890 case OMAP_DSS_COLOR_ARGB16_1555:
891 m = 0x7; break;
892 case OMAP_DSS_COLOR_RGB24U:
893 m = 0x8; break;
894 case OMAP_DSS_COLOR_RGB24P:
895 m = 0x9; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530896 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530897 m = 0xa; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530898 case OMAP_DSS_COLOR_RGBA16:
Amber Jainf20e4222011-05-19 19:47:50 +0530899 m = 0xb; break;
900 case OMAP_DSS_COLOR_ARGB32:
901 m = 0xc; break;
902 case OMAP_DSS_COLOR_RGBA32:
903 m = 0xd; break;
904 case OMAP_DSS_COLOR_RGBX32:
905 m = 0xe; break;
906 case OMAP_DSS_COLOR_XRGB16_1555:
907 m = 0xf; break;
908 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300909 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530910 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200911 }
912
Archit Taneja9b372c22011-05-06 11:45:49 +0530913 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200914}
915
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530916static void dispc_ovl_configure_burst_type(enum omap_plane plane,
917 enum omap_dss_rotation_type rotation_type)
918{
919 if (dss_has_feature(FEAT_BURST_2D) == 0)
920 return;
921
922 if (rotation_type == OMAP_DSS_ROT_TILER)
923 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
924 else
925 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
926}
927
Tomi Valkeinenf4279842011-10-28 15:26:26 +0300928void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200929{
930 int shift;
931 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000932 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200933
934 switch (plane) {
935 case OMAP_DSS_GFX:
936 shift = 8;
937 break;
938 case OMAP_DSS_VIDEO1:
939 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +0530940 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200941 shift = 16;
942 break;
943 default:
944 BUG();
945 return;
946 }
947
Archit Taneja9b372c22011-05-06 11:45:49 +0530948 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000949 if (dss_has_feature(FEAT_MGR_LCD2)) {
950 switch (channel) {
951 case OMAP_DSS_CHANNEL_LCD:
952 chan = 0;
953 chan2 = 0;
954 break;
955 case OMAP_DSS_CHANNEL_DIGIT:
956 chan = 1;
957 chan2 = 0;
958 break;
959 case OMAP_DSS_CHANNEL_LCD2:
960 chan = 0;
961 chan2 = 1;
962 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530963 case OMAP_DSS_CHANNEL_LCD3:
964 if (dss_has_feature(FEAT_MGR_LCD3)) {
965 chan = 0;
966 chan2 = 2;
967 } else {
968 BUG();
969 return;
970 }
971 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000972 default:
973 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300974 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000975 }
976
977 val = FLD_MOD(val, chan, shift, shift);
978 val = FLD_MOD(val, chan2, 31, 30);
979 } else {
980 val = FLD_MOD(val, channel, shift, shift);
981 }
Archit Taneja9b372c22011-05-06 11:45:49 +0530982 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200983}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200984EXPORT_SYMBOL(dispc_ovl_set_channel_out);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200985
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200986static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
987{
988 int shift;
989 u32 val;
990 enum omap_channel channel;
991
992 switch (plane) {
993 case OMAP_DSS_GFX:
994 shift = 8;
995 break;
996 case OMAP_DSS_VIDEO1:
997 case OMAP_DSS_VIDEO2:
998 case OMAP_DSS_VIDEO3:
999 shift = 16;
1000 break;
1001 default:
1002 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001003 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001004 }
1005
1006 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1007
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05301008 if (dss_has_feature(FEAT_MGR_LCD3)) {
1009 if (FLD_GET(val, 31, 30) == 0)
1010 channel = FLD_GET(val, shift, shift);
1011 else if (FLD_GET(val, 31, 30) == 1)
1012 channel = OMAP_DSS_CHANNEL_LCD2;
1013 else
1014 channel = OMAP_DSS_CHANNEL_LCD3;
1015 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001016 if (FLD_GET(val, 31, 30) == 0)
1017 channel = FLD_GET(val, shift, shift);
1018 else
1019 channel = OMAP_DSS_CHANNEL_LCD2;
1020 } else {
1021 channel = FLD_GET(val, shift, shift);
1022 }
1023
1024 return channel;
1025}
1026
Archit Tanejad9ac7732012-09-22 12:38:19 +05301027void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1028{
1029 enum omap_plane plane = OMAP_DSS_WB;
1030
1031 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1032}
1033
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001034static void dispc_ovl_set_burst_size(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001035 enum omap_burst_size burst_size)
1036{
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301037 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001038 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001039
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001040 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001041 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001042}
1043
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001044static void dispc_configure_burst_sizes(void)
1045{
1046 int i;
1047 const int burst_size = BURST_SIZE_X8;
1048
1049 /* Configure burst size always to maximum size */
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001050 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001051 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001052}
1053
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001054static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001055{
1056 unsigned unit = dss_feat_get_burst_size_unit();
1057 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1058 return unit * 8;
1059}
1060
Mythri P Kd3862612011-03-11 18:02:49 +05301061void dispc_enable_gamma_table(bool enable)
1062{
1063 /*
1064 * This is partially implemented to support only disabling of
1065 * the gamma table.
1066 */
1067 if (enable) {
1068 DSSWARN("Gamma table enabling for TV not yet supported");
1069 return;
1070 }
1071
1072 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1073}
1074
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001075static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001076{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301077 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001078 return;
1079
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301080 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001081}
1082
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001083static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02001084 const struct omap_dss_cpr_coefs *coefs)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001085{
1086 u32 coef_r, coef_g, coef_b;
1087
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301088 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001089 return;
1090
1091 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1092 FLD_VAL(coefs->rb, 9, 0);
1093 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1094 FLD_VAL(coefs->gb, 9, 0);
1095 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1096 FLD_VAL(coefs->bb, 9, 0);
1097
1098 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1099 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1100 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1101}
1102
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001103static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001104{
1105 u32 val;
1106
1107 BUG_ON(plane == OMAP_DSS_GFX);
1108
Archit Taneja9b372c22011-05-06 11:45:49 +05301109 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001110 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +05301111 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001112}
1113
Archit Tanejad79db852012-09-22 12:30:17 +05301114static void dispc_ovl_enable_replication(enum omap_plane plane,
1115 enum omap_overlay_caps caps, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001116{
Archit Tanejab8c095b2011-09-13 18:20:33 +05301117 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001118 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001119
Archit Tanejad79db852012-09-22 12:30:17 +05301120 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1121 return;
1122
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001123 shift = shifts[plane];
1124 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001125}
1126
Archit Taneja8f366162012-04-16 12:53:44 +05301127static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
Archit Tanejae5c09e02012-04-16 12:53:42 +05301128 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001129{
1130 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301131
Archit Taneja33b89922012-11-14 13:50:15 +05301132 val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1133 FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1134
Archit Taneja702d1442011-05-06 11:45:50 +05301135 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001136}
1137
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001138static void dispc_init_fifos(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001139{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001140 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001141 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301142 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001143 u32 unit;
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001144 int i;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001145
1146 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001147
Archit Tanejaa0acb552010-09-15 19:20:00 +05301148 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001149
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001150 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1151 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001152 size *= unit;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001153 dispc.fifo_size[fifo] = size;
1154
1155 /*
1156 * By default fifos are mapped directly to overlays, fifo 0 to
1157 * ovl 0, fifo 1 to ovl 1, etc.
1158 */
1159 dispc.fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001160 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001161
1162 /*
1163 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1164 * causes problems with certain use cases, like using the tiler in 2D
1165 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1166 * giving GFX plane a larger fifo. WB but should work fine with a
1167 * smaller fifo.
1168 */
1169 if (dispc.feat->gfx_fifo_workaround) {
1170 u32 v;
1171
1172 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1173
1174 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1175 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1176 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1177 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1178
1179 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1180
1181 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1182 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1183 }
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001184
1185 /*
1186 * Setup default fifo thresholds.
1187 */
1188 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1189 u32 low, high;
1190 const bool use_fifomerge = false;
1191 const bool manual_update = false;
1192
1193 dispc_ovl_compute_fifo_thresholds(i, &low, &high,
1194 use_fifomerge, manual_update);
1195
1196 dispc_ovl_set_fifo_threshold(i, low, high);
1197 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001198}
1199
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001200static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001201{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001202 int fifo;
1203 u32 size = 0;
1204
1205 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1206 if (dispc.fifo_assignment[fifo] == plane)
1207 size += dispc.fifo_size[fifo];
1208 }
1209
1210 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001211}
1212
Tomi Valkeinen6f04e1b2011-10-31 08:58:52 +02001213void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001214{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301215 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001216 u32 unit;
1217
1218 unit = dss_feat_get_buffer_size_unit();
1219
1220 WARN_ON(low % unit != 0);
1221 WARN_ON(high % unit != 0);
1222
1223 low /= unit;
1224 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301225
Archit Taneja9b372c22011-05-06 11:45:49 +05301226 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1227 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1228
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001229 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001230 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301231 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001232 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301233 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001234 hi_start, hi_end) * unit,
1235 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001236
Archit Taneja9b372c22011-05-06 11:45:49 +05301237 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301238 FLD_VAL(high, hi_start, hi_end) |
1239 FLD_VAL(low, lo_start, lo_end));
Archit Taneja8bc65552013-12-17 16:40:21 +05301240
1241 /*
1242 * configure the preload to the pipeline's high threhold, if HT it's too
1243 * large for the preload field, set the threshold to the maximum value
1244 * that can be held by the preload register
1245 */
1246 if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload &&
1247 plane != OMAP_DSS_WB)
1248 dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001249}
Tomi Valkeinen8ee5c842013-11-08 10:07:20 +02001250EXPORT_SYMBOL(dispc_ovl_set_fifo_threshold);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001251
1252void dispc_enable_fifomerge(bool enable)
1253{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001254 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1255 WARN_ON(enable);
1256 return;
1257 }
1258
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001259 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1260 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001261}
1262
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001263void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001264 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1265 bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001266{
1267 /*
1268 * All sizes are in bytes. Both the buffer and burst are made of
1269 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1270 */
1271
1272 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001273 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1274 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001275
1276 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001277 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001278
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001279 if (use_fifomerge) {
1280 total_fifo_size = 0;
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001281 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001282 total_fifo_size += dispc_ovl_get_fifo_size(i);
1283 } else {
1284 total_fifo_size = ovl_fifo_size;
1285 }
1286
1287 /*
1288 * We use the same low threshold for both fifomerge and non-fifomerge
1289 * cases, but for fifomerge we calculate the high threshold using the
1290 * combined fifo size
1291 */
1292
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001293 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001294 *fifo_low = ovl_fifo_size - burst_size * 2;
1295 *fifo_high = total_fifo_size - burst_size;
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301296 } else if (plane == OMAP_DSS_WB) {
1297 /*
1298 * Most optimal configuration for writeback is to push out data
1299 * to the interconnect the moment writeback pushes enough pixels
1300 * in the FIFO to form a burst
1301 */
1302 *fifo_low = 0;
1303 *fifo_high = burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001304 } else {
1305 *fifo_low = ovl_fifo_size - burst_size;
1306 *fifo_high = total_fifo_size - buf_unit;
1307 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001308}
Tomi Valkeinen8ee5c842013-11-08 10:07:20 +02001309EXPORT_SYMBOL(dispc_ovl_compute_fifo_thresholds);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001310
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001311static void dispc_ovl_set_mflag(enum omap_plane plane, bool enable)
1312{
1313 int bit;
1314
1315 if (plane == OMAP_DSS_GFX)
1316 bit = 14;
1317 else
1318 bit = 23;
1319
1320 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1321}
1322
1323static void dispc_ovl_set_mflag_threshold(enum omap_plane plane,
1324 int low, int high)
1325{
1326 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane),
1327 FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1328}
1329
1330static void dispc_init_mflag(void)
1331{
1332 int i;
1333
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001334 /*
1335 * HACK: NV12 color format and MFLAG seem to have problems working
1336 * together: using two displays, and having an NV12 overlay on one of
1337 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1338 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1339 * remove the errors, but there doesn't seem to be a clear logic on
1340 * which values work and which not.
1341 *
1342 * As a work-around, set force MFLAG to always on.
1343 */
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001344 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE,
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001345 (1 << 0) | /* MFLAG_CTRL = force always on */
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001346 (0 << 2)); /* MFLAG_START = disable */
1347
1348 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1349 u32 size = dispc_ovl_get_fifo_size(i);
1350 u32 unit = dss_feat_get_buffer_size_unit();
1351 u32 low, high;
1352
1353 dispc_ovl_set_mflag(i, true);
1354
1355 /*
1356 * Simulation team suggests below thesholds:
1357 * HT = fifosize * 5 / 8;
1358 * LT = fifosize * 4 / 8;
1359 */
1360
1361 low = size * 4 / 8 / unit;
1362 high = size * 5 / 8 / unit;
1363
1364 dispc_ovl_set_mflag_threshold(i, low, high);
1365 }
1366}
1367
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001368static void dispc_ovl_set_fir(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301369 int hinc, int vinc,
1370 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001371{
1372 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001373
Amber Jain0d66cbb2011-05-19 19:47:54 +05301374 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1375 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301376
Amber Jain0d66cbb2011-05-19 19:47:54 +05301377 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1378 &hinc_start, &hinc_end);
1379 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1380 &vinc_start, &vinc_end);
1381 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1382 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301383
Amber Jain0d66cbb2011-05-19 19:47:54 +05301384 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1385 } else {
1386 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1387 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1388 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001389}
1390
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001391static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001392{
1393 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301394 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001395
Archit Taneja87a74842011-03-02 11:19:50 +05301396 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1397 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1398
1399 val = FLD_VAL(vaccu, vert_start, vert_end) |
1400 FLD_VAL(haccu, hor_start, hor_end);
1401
Archit Taneja9b372c22011-05-06 11:45:49 +05301402 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001403}
1404
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001405static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001406{
1407 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301408 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001409
Archit Taneja87a74842011-03-02 11:19:50 +05301410 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1411 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1412
1413 val = FLD_VAL(vaccu, vert_start, vert_end) |
1414 FLD_VAL(haccu, hor_start, hor_end);
1415
Archit Taneja9b372c22011-05-06 11:45:49 +05301416 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001417}
1418
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001419static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1420 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301421{
1422 u32 val;
1423
1424 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1425 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1426}
1427
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001428static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1429 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301430{
1431 u32 val;
1432
1433 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1434 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1435}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001436
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001437static void dispc_ovl_set_scale_param(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001438 u16 orig_width, u16 orig_height,
1439 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301440 bool five_taps, u8 rotation,
1441 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001442{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301443 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001444
Amber Jained14a3c2011-05-19 19:47:51 +05301445 fir_hinc = 1024 * orig_width / out_width;
1446 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001447
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301448 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1449 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001450 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301451}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001452
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301453static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1454 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1455 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1456{
1457 int h_accu2_0, h_accu2_1;
1458 int v_accu2_0, v_accu2_1;
1459 int chroma_hinc, chroma_vinc;
1460 int idx;
1461
1462 struct accu {
1463 s8 h0_m, h0_n;
1464 s8 h1_m, h1_n;
1465 s8 v0_m, v0_n;
1466 s8 v1_m, v1_n;
1467 };
1468
1469 const struct accu *accu_table;
1470 const struct accu *accu_val;
1471
1472 static const struct accu accu_nv12[4] = {
1473 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1474 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1475 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1476 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1477 };
1478
1479 static const struct accu accu_nv12_ilace[4] = {
1480 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1481 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1482 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1483 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1484 };
1485
1486 static const struct accu accu_yuv[4] = {
1487 { 0, 1, 0, 1, 0, 1, 0, 1 },
1488 { 0, 1, 0, 1, 0, 1, 0, 1 },
1489 { -1, 1, 0, 1, 0, 1, 0, 1 },
1490 { 0, 1, 0, 1, -1, 1, 0, 1 },
1491 };
1492
1493 switch (rotation) {
1494 case OMAP_DSS_ROT_0:
1495 idx = 0;
1496 break;
1497 case OMAP_DSS_ROT_90:
1498 idx = 1;
1499 break;
1500 case OMAP_DSS_ROT_180:
1501 idx = 2;
1502 break;
1503 case OMAP_DSS_ROT_270:
1504 idx = 3;
1505 break;
1506 default:
1507 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001508 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301509 }
1510
1511 switch (color_mode) {
1512 case OMAP_DSS_COLOR_NV12:
1513 if (ilace)
1514 accu_table = accu_nv12_ilace;
1515 else
1516 accu_table = accu_nv12;
1517 break;
1518 case OMAP_DSS_COLOR_YUV2:
1519 case OMAP_DSS_COLOR_UYVY:
1520 accu_table = accu_yuv;
1521 break;
1522 default:
1523 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001524 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301525 }
1526
1527 accu_val = &accu_table[idx];
1528
1529 chroma_hinc = 1024 * orig_width / out_width;
1530 chroma_vinc = 1024 * orig_height / out_height;
1531
1532 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1533 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1534 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1535 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1536
1537 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1538 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1539}
1540
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001541static void dispc_ovl_set_scaling_common(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301542 u16 orig_width, u16 orig_height,
1543 u16 out_width, u16 out_height,
1544 bool ilace, bool five_taps,
1545 bool fieldmode, enum omap_color_mode color_mode,
1546 u8 rotation)
1547{
1548 int accu0 = 0;
1549 int accu1 = 0;
1550 u32 l;
1551
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001552 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301553 out_width, out_height, five_taps,
1554 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301555 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001556
Archit Taneja87a74842011-03-02 11:19:50 +05301557 /* RESIZEENABLE and VERTICALTAPS */
1558 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301559 l |= (orig_width != out_width) ? (1 << 5) : 0;
1560 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001561 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301562
1563 /* VRESIZECONF and HRESIZECONF */
1564 if (dss_has_feature(FEAT_RESIZECONF)) {
1565 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301566 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1567 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301568 }
1569
1570 /* LINEBUFFERSPLIT */
1571 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1572 l &= ~(0x1 << 22);
1573 l |= five_taps ? (1 << 22) : 0;
1574 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001575
Archit Taneja9b372c22011-05-06 11:45:49 +05301576 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001577
1578 /*
1579 * field 0 = even field = bottom field
1580 * field 1 = odd field = top field
1581 */
1582 if (ilace && !fieldmode) {
1583 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301584 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001585 if (accu0 >= 1024/2) {
1586 accu1 = 1024/2;
1587 accu0 -= accu1;
1588 }
1589 }
1590
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001591 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1592 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001593}
1594
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001595static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301596 u16 orig_width, u16 orig_height,
1597 u16 out_width, u16 out_height,
1598 bool ilace, bool five_taps,
1599 bool fieldmode, enum omap_color_mode color_mode,
1600 u8 rotation)
1601{
1602 int scale_x = out_width != orig_width;
1603 int scale_y = out_height != orig_height;
Archit Tanejaf92afae2012-08-24 11:11:14 +05301604 bool chroma_upscale = plane != OMAP_DSS_WB ? true : false;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301605
1606 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1607 return;
1608 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1609 color_mode != OMAP_DSS_COLOR_UYVY &&
1610 color_mode != OMAP_DSS_COLOR_NV12)) {
1611 /* reset chroma resampling for RGB formats */
Archit Taneja2a5561b2012-07-16 16:37:45 +05301612 if (plane != OMAP_DSS_WB)
1613 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301614 return;
1615 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001616
1617 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1618 out_height, ilace, color_mode, rotation);
1619
Amber Jain0d66cbb2011-05-19 19:47:54 +05301620 switch (color_mode) {
1621 case OMAP_DSS_COLOR_NV12:
Archit Taneja20fbb502012-08-22 17:04:48 +05301622 if (chroma_upscale) {
1623 /* UV is subsampled by 2 horizontally and vertically */
1624 orig_height >>= 1;
1625 orig_width >>= 1;
1626 } else {
1627 /* UV is downsampled by 2 horizontally and vertically */
1628 orig_height <<= 1;
1629 orig_width <<= 1;
1630 }
1631
Amber Jain0d66cbb2011-05-19 19:47:54 +05301632 break;
1633 case OMAP_DSS_COLOR_YUV2:
1634 case OMAP_DSS_COLOR_UYVY:
Archit Taneja20fbb502012-08-22 17:04:48 +05301635 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
Amber Jain0d66cbb2011-05-19 19:47:54 +05301636 if (rotation == OMAP_DSS_ROT_0 ||
Archit Taneja20fbb502012-08-22 17:04:48 +05301637 rotation == OMAP_DSS_ROT_180) {
1638 if (chroma_upscale)
1639 /* UV is subsampled by 2 horizontally */
1640 orig_width >>= 1;
1641 else
1642 /* UV is downsampled by 2 horizontally */
1643 orig_width <<= 1;
1644 }
1645
Amber Jain0d66cbb2011-05-19 19:47:54 +05301646 /* must use FIR for YUV422 if rotated */
1647 if (rotation != OMAP_DSS_ROT_0)
1648 scale_x = scale_y = true;
Archit Taneja20fbb502012-08-22 17:04:48 +05301649
Amber Jain0d66cbb2011-05-19 19:47:54 +05301650 break;
1651 default:
1652 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001653 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301654 }
1655
1656 if (out_width != orig_width)
1657 scale_x = true;
1658 if (out_height != orig_height)
1659 scale_y = true;
1660
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001661 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301662 out_width, out_height, five_taps,
1663 rotation, DISPC_COLOR_COMPONENT_UV);
1664
Archit Taneja2a5561b2012-07-16 16:37:45 +05301665 if (plane != OMAP_DSS_WB)
1666 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1667 (scale_x || scale_y) ? 1 : 0, 8, 8);
1668
Amber Jain0d66cbb2011-05-19 19:47:54 +05301669 /* set H scaling */
1670 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1671 /* set V scaling */
1672 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301673}
1674
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001675static void dispc_ovl_set_scaling(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301676 u16 orig_width, u16 orig_height,
1677 u16 out_width, u16 out_height,
1678 bool ilace, bool five_taps,
1679 bool fieldmode, enum omap_color_mode color_mode,
1680 u8 rotation)
1681{
1682 BUG_ON(plane == OMAP_DSS_GFX);
1683
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001684 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301685 orig_width, orig_height,
1686 out_width, out_height,
1687 ilace, five_taps,
1688 fieldmode, color_mode,
1689 rotation);
1690
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001691 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301692 orig_width, orig_height,
1693 out_width, out_height,
1694 ilace, five_taps,
1695 fieldmode, color_mode,
1696 rotation);
1697}
1698
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001699static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
Archit Tanejac35eeb22013-03-26 19:15:24 +05301700 enum omap_dss_rotation_type rotation_type,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001701 bool mirroring, enum omap_color_mode color_mode)
1702{
Archit Taneja87a74842011-03-02 11:19:50 +05301703 bool row_repeat = false;
1704 int vidrot = 0;
1705
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001706 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1707 color_mode == OMAP_DSS_COLOR_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001708
1709 if (mirroring) {
1710 switch (rotation) {
1711 case OMAP_DSS_ROT_0:
1712 vidrot = 2;
1713 break;
1714 case OMAP_DSS_ROT_90:
1715 vidrot = 1;
1716 break;
1717 case OMAP_DSS_ROT_180:
1718 vidrot = 0;
1719 break;
1720 case OMAP_DSS_ROT_270:
1721 vidrot = 3;
1722 break;
1723 }
1724 } else {
1725 switch (rotation) {
1726 case OMAP_DSS_ROT_0:
1727 vidrot = 0;
1728 break;
1729 case OMAP_DSS_ROT_90:
1730 vidrot = 1;
1731 break;
1732 case OMAP_DSS_ROT_180:
1733 vidrot = 2;
1734 break;
1735 case OMAP_DSS_ROT_270:
1736 vidrot = 3;
1737 break;
1738 }
1739 }
1740
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001741 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
Archit Taneja87a74842011-03-02 11:19:50 +05301742 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001743 else
Archit Taneja87a74842011-03-02 11:19:50 +05301744 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001745 }
Archit Taneja87a74842011-03-02 11:19:50 +05301746
Tomi Valkeinen3397cc62015-04-09 13:51:30 +03001747 /*
1748 * OMAP4/5 Errata i631:
1749 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
1750 * rows beyond the framebuffer, which may cause OCP error.
1751 */
1752 if (color_mode == OMAP_DSS_COLOR_NV12 &&
1753 rotation_type != OMAP_DSS_ROT_TILER)
1754 vidrot = 1;
1755
Archit Taneja9b372c22011-05-06 11:45:49 +05301756 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301757 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301758 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1759 row_repeat ? 1 : 0, 18, 18);
Archit Tanejac35eeb22013-03-26 19:15:24 +05301760
1761 if (color_mode == OMAP_DSS_COLOR_NV12) {
1762 bool doublestride = (rotation_type == OMAP_DSS_ROT_TILER) &&
1763 (rotation == OMAP_DSS_ROT_0 ||
1764 rotation == OMAP_DSS_ROT_180);
1765 /* DOUBLESTRIDE */
1766 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22);
1767 }
1768
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001769}
1770
1771static int color_mode_to_bpp(enum omap_color_mode color_mode)
1772{
1773 switch (color_mode) {
1774 case OMAP_DSS_COLOR_CLUT1:
1775 return 1;
1776 case OMAP_DSS_COLOR_CLUT2:
1777 return 2;
1778 case OMAP_DSS_COLOR_CLUT4:
1779 return 4;
1780 case OMAP_DSS_COLOR_CLUT8:
Amber Jainf20e4222011-05-19 19:47:50 +05301781 case OMAP_DSS_COLOR_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001782 return 8;
1783 case OMAP_DSS_COLOR_RGB12U:
1784 case OMAP_DSS_COLOR_RGB16:
1785 case OMAP_DSS_COLOR_ARGB16:
1786 case OMAP_DSS_COLOR_YUV2:
1787 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301788 case OMAP_DSS_COLOR_RGBA16:
1789 case OMAP_DSS_COLOR_RGBX16:
1790 case OMAP_DSS_COLOR_ARGB16_1555:
1791 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001792 return 16;
1793 case OMAP_DSS_COLOR_RGB24P:
1794 return 24;
1795 case OMAP_DSS_COLOR_RGB24U:
1796 case OMAP_DSS_COLOR_ARGB32:
1797 case OMAP_DSS_COLOR_RGBA32:
1798 case OMAP_DSS_COLOR_RGBX32:
1799 return 32;
1800 default:
1801 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001802 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001803 }
1804}
1805
1806static s32 pixinc(int pixels, u8 ps)
1807{
1808 if (pixels == 1)
1809 return 1;
1810 else if (pixels > 1)
1811 return 1 + (pixels - 1) * ps;
1812 else if (pixels < 0)
1813 return 1 - (-pixels + 1) * ps;
1814 else
1815 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001816 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001817}
1818
1819static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1820 u16 screen_width,
1821 u16 width, u16 height,
1822 enum omap_color_mode color_mode, bool fieldmode,
1823 unsigned int field_offset,
1824 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301825 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001826{
1827 u8 ps;
1828
1829 /* FIXME CLUT formats */
1830 switch (color_mode) {
1831 case OMAP_DSS_COLOR_CLUT1:
1832 case OMAP_DSS_COLOR_CLUT2:
1833 case OMAP_DSS_COLOR_CLUT4:
1834 case OMAP_DSS_COLOR_CLUT8:
1835 BUG();
1836 return;
1837 case OMAP_DSS_COLOR_YUV2:
1838 case OMAP_DSS_COLOR_UYVY:
1839 ps = 4;
1840 break;
1841 default:
1842 ps = color_mode_to_bpp(color_mode) / 8;
1843 break;
1844 }
1845
1846 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1847 width, height);
1848
1849 /*
1850 * field 0 = even field = bottom field
1851 * field 1 = odd field = top field
1852 */
1853 switch (rotation + mirror * 4) {
1854 case OMAP_DSS_ROT_0:
1855 case OMAP_DSS_ROT_180:
1856 /*
1857 * If the pixel format is YUV or UYVY divide the width
1858 * of the image by 2 for 0 and 180 degree rotation.
1859 */
1860 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1861 color_mode == OMAP_DSS_COLOR_UYVY)
1862 width = width >> 1;
1863 case OMAP_DSS_ROT_90:
1864 case OMAP_DSS_ROT_270:
1865 *offset1 = 0;
1866 if (field_offset)
1867 *offset0 = field_offset * screen_width * ps;
1868 else
1869 *offset0 = 0;
1870
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301871 *row_inc = pixinc(1 +
1872 (y_predecim * screen_width - x_predecim * width) +
1873 (fieldmode ? screen_width : 0), ps);
1874 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001875 break;
1876
1877 case OMAP_DSS_ROT_0 + 4:
1878 case OMAP_DSS_ROT_180 + 4:
1879 /* If the pixel format is YUV or UYVY divide the width
1880 * of the image by 2 for 0 degree and 180 degree
1881 */
1882 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1883 color_mode == OMAP_DSS_COLOR_UYVY)
1884 width = width >> 1;
1885 case OMAP_DSS_ROT_90 + 4:
1886 case OMAP_DSS_ROT_270 + 4:
1887 *offset1 = 0;
1888 if (field_offset)
1889 *offset0 = field_offset * screen_width * ps;
1890 else
1891 *offset0 = 0;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301892 *row_inc = pixinc(1 -
1893 (y_predecim * screen_width + x_predecim * width) -
1894 (fieldmode ? screen_width : 0), ps);
1895 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001896 break;
1897
1898 default:
1899 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001900 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001901 }
1902}
1903
1904static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1905 u16 screen_width,
1906 u16 width, u16 height,
1907 enum omap_color_mode color_mode, bool fieldmode,
1908 unsigned int field_offset,
1909 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301910 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001911{
1912 u8 ps;
1913 u16 fbw, fbh;
1914
1915 /* FIXME CLUT formats */
1916 switch (color_mode) {
1917 case OMAP_DSS_COLOR_CLUT1:
1918 case OMAP_DSS_COLOR_CLUT2:
1919 case OMAP_DSS_COLOR_CLUT4:
1920 case OMAP_DSS_COLOR_CLUT8:
1921 BUG();
1922 return;
1923 default:
1924 ps = color_mode_to_bpp(color_mode) / 8;
1925 break;
1926 }
1927
1928 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1929 width, height);
1930
1931 /* width & height are overlay sizes, convert to fb sizes */
1932
1933 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1934 fbw = width;
1935 fbh = height;
1936 } else {
1937 fbw = height;
1938 fbh = width;
1939 }
1940
1941 /*
1942 * field 0 = even field = bottom field
1943 * field 1 = odd field = top field
1944 */
1945 switch (rotation + mirror * 4) {
1946 case OMAP_DSS_ROT_0:
1947 *offset1 = 0;
1948 if (field_offset)
1949 *offset0 = *offset1 + field_offset * screen_width * ps;
1950 else
1951 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301952 *row_inc = pixinc(1 +
1953 (y_predecim * screen_width - fbw * x_predecim) +
1954 (fieldmode ? screen_width : 0), ps);
1955 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1956 color_mode == OMAP_DSS_COLOR_UYVY)
1957 *pix_inc = pixinc(x_predecim, 2 * ps);
1958 else
1959 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001960 break;
1961 case OMAP_DSS_ROT_90:
1962 *offset1 = screen_width * (fbh - 1) * ps;
1963 if (field_offset)
1964 *offset0 = *offset1 + field_offset * ps;
1965 else
1966 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301967 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1968 y_predecim + (fieldmode ? 1 : 0), ps);
1969 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001970 break;
1971 case OMAP_DSS_ROT_180:
1972 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1973 if (field_offset)
1974 *offset0 = *offset1 - field_offset * screen_width * ps;
1975 else
1976 *offset0 = *offset1;
1977 *row_inc = pixinc(-1 -
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301978 (y_predecim * screen_width - fbw * x_predecim) -
1979 (fieldmode ? screen_width : 0), ps);
1980 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1981 color_mode == OMAP_DSS_COLOR_UYVY)
1982 *pix_inc = pixinc(-x_predecim, 2 * ps);
1983 else
1984 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001985 break;
1986 case OMAP_DSS_ROT_270:
1987 *offset1 = (fbw - 1) * ps;
1988 if (field_offset)
1989 *offset0 = *offset1 - field_offset * ps;
1990 else
1991 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301992 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1993 y_predecim - (fieldmode ? 1 : 0), ps);
1994 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001995 break;
1996
1997 /* mirroring */
1998 case OMAP_DSS_ROT_0 + 4:
1999 *offset1 = (fbw - 1) * ps;
2000 if (field_offset)
2001 *offset0 = *offset1 + field_offset * screen_width * ps;
2002 else
2003 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302004 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002005 (fieldmode ? screen_width : 0),
2006 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302007 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2008 color_mode == OMAP_DSS_COLOR_UYVY)
2009 *pix_inc = pixinc(-x_predecim, 2 * ps);
2010 else
2011 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002012 break;
2013
2014 case OMAP_DSS_ROT_90 + 4:
2015 *offset1 = 0;
2016 if (field_offset)
2017 *offset0 = *offset1 + field_offset * ps;
2018 else
2019 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302020 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
2021 y_predecim + (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002022 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302023 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002024 break;
2025
2026 case OMAP_DSS_ROT_180 + 4:
2027 *offset1 = screen_width * (fbh - 1) * ps;
2028 if (field_offset)
2029 *offset0 = *offset1 - field_offset * screen_width * ps;
2030 else
2031 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302032 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002033 (fieldmode ? screen_width : 0),
2034 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302035 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2036 color_mode == OMAP_DSS_COLOR_UYVY)
2037 *pix_inc = pixinc(x_predecim, 2 * ps);
2038 else
2039 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002040 break;
2041
2042 case OMAP_DSS_ROT_270 + 4:
2043 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
2044 if (field_offset)
2045 *offset0 = *offset1 - field_offset * ps;
2046 else
2047 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302048 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
2049 y_predecim - (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002050 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302051 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002052 break;
2053
2054 default:
2055 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002056 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002057 }
2058}
2059
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302060static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
2061 enum omap_color_mode color_mode, bool fieldmode,
2062 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
2063 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
2064{
2065 u8 ps;
2066
2067 switch (color_mode) {
2068 case OMAP_DSS_COLOR_CLUT1:
2069 case OMAP_DSS_COLOR_CLUT2:
2070 case OMAP_DSS_COLOR_CLUT4:
2071 case OMAP_DSS_COLOR_CLUT8:
2072 BUG();
2073 return;
2074 default:
2075 ps = color_mode_to_bpp(color_mode) / 8;
2076 break;
2077 }
2078
2079 DSSDBG("scrw %d, width %d\n", screen_width, width);
2080
2081 /*
2082 * field 0 = even field = bottom field
2083 * field 1 = odd field = top field
2084 */
2085 *offset1 = 0;
2086 if (field_offset)
2087 *offset0 = *offset1 + field_offset * screen_width * ps;
2088 else
2089 *offset0 = *offset1;
2090 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
2091 (fieldmode ? screen_width : 0), ps);
2092 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2093 color_mode == OMAP_DSS_COLOR_UYVY)
2094 *pix_inc = pixinc(x_predecim, 2 * ps);
2095 else
2096 *pix_inc = pixinc(x_predecim, ps);
2097}
2098
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302099/*
2100 * This function is used to avoid synclosts in OMAP3, because of some
2101 * undocumented horizontal position and timing related limitations.
2102 */
Tomi Valkeinen465ec132012-10-19 15:40:24 +03002103static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302104 const struct omap_video_timings *t, u16 pos_x,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002105 u16 width, u16 height, u16 out_width, u16 out_height,
2106 bool five_taps)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302107{
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002108 const int ds = DIV_ROUND_UP(height, out_height);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302109 unsigned long nonactive;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302110 static const u8 limits[3] = { 8, 10, 20 };
2111 u64 val, blank;
2112 int i;
2113
Archit Taneja81ab95b2012-05-08 15:53:20 +05302114 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302115
2116 i = 0;
2117 if (out_height < height)
2118 i++;
2119 if (out_width < width)
2120 i++;
Archit Taneja81ab95b2012-05-08 15:53:20 +05302121 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302122 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2123 if (blank <= limits[i])
2124 return -EINVAL;
2125
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002126 /* FIXME add checks for 3-tap filter once the limitations are known */
2127 if (!five_taps)
2128 return 0;
2129
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302130 /*
2131 * Pixel data should be prepared before visible display point starts.
2132 * So, atleast DS-2 lines must have already been fetched by DISPC
2133 * during nonactive - pos_x period.
2134 */
2135 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2136 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002137 val, max(0, ds - 2) * width);
2138 if (val < max(0, ds - 2) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302139 return -EINVAL;
2140
2141 /*
2142 * All lines need to be refilled during the nonactive period of which
2143 * only one line can be loaded during the active period. So, atleast
2144 * DS - 1 lines should be loaded during nonactive period.
2145 */
2146 val = div_u64((u64)nonactive * lclk, pclk);
2147 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002148 val, max(0, ds - 1) * width);
2149 if (val < max(0, ds - 1) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302150 return -EINVAL;
2151
2152 return 0;
2153}
2154
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002155static unsigned long calc_core_clk_five_taps(unsigned long pclk,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302156 const struct omap_video_timings *mgr_timings, u16 width,
2157 u16 height, u16 out_width, u16 out_height,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002158 enum omap_color_mode color_mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002159{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302160 u32 core_clk = 0;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302161 u64 tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002162
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302163 if (height <= out_height && width <= out_width)
2164 return (unsigned long) pclk;
2165
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002166 if (height > out_height) {
Archit Taneja81ab95b2012-05-08 15:53:20 +05302167 unsigned int ppl = mgr_timings->x_res;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002168
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002169 tmp = (u64)pclk * height * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002170 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302171 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002172
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02002173 if (height > 2 * out_height) {
2174 if (ppl == out_width)
2175 return 0;
2176
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002177 tmp = (u64)pclk * (height - 2 * out_height) * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002178 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302179 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002180 }
2181 }
2182
2183 if (width > out_width) {
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002184 tmp = (u64)pclk * width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002185 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302186 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002187
2188 if (color_mode == OMAP_DSS_COLOR_RGB24U)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302189 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002190 }
2191
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302192 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002193}
2194
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002195static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302196 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302197{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302198 if (height > out_height && width > out_width)
2199 return pclk * 4;
2200 else
2201 return pclk * 2;
2202}
2203
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002204static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302205 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002206{
2207 unsigned int hf, vf;
2208
2209 /*
2210 * FIXME how to determine the 'A' factor
2211 * for the no downscaling case ?
2212 */
2213
2214 if (width > 3 * out_width)
2215 hf = 4;
2216 else if (width > 2 * out_width)
2217 hf = 3;
2218 else if (width > out_width)
2219 hf = 2;
2220 else
2221 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002222 if (height > out_height)
2223 vf = 2;
2224 else
2225 vf = 1;
2226
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302227 return pclk * vf * hf;
2228}
2229
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002230static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302231 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302232{
Archit Taneja8ba85302012-09-26 17:00:37 +05302233 /*
2234 * If the overlay/writeback is in mem to mem mode, there are no
2235 * downscaling limitations with respect to pixel clock, return 1 as
2236 * required core clock to represent that we have sufficient enough
2237 * core clock to do maximum downscaling
2238 */
2239 if (mem_to_mem)
2240 return 1;
2241
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302242 if (width > out_width)
2243 return DIV_ROUND_UP(pclk, out_width) * width;
2244 else
2245 return pclk;
2246}
2247
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002248static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302249 const struct omap_video_timings *mgr_timings,
2250 u16 width, u16 height, u16 out_width, u16 out_height,
2251 enum omap_color_mode color_mode, bool *five_taps,
2252 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302253 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302254{
2255 int error;
2256 u16 in_width, in_height;
2257 int min_factor = min(*decim_x, *decim_y);
2258 const int maxsinglelinewidth =
2259 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302260
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302261 *five_taps = false;
2262
2263 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002264 in_height = height / *decim_y;
2265 in_width = width / *decim_x;
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002266 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302267 in_height, out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302268 error = (in_width > maxsinglelinewidth || !*core_clk ||
2269 *core_clk > dispc_core_clk_rate());
2270 if (error) {
2271 if (*decim_x == *decim_y) {
2272 *decim_x = min_factor;
2273 ++*decim_y;
2274 } else {
2275 swap(*decim_x, *decim_y);
2276 if (*decim_x < *decim_y)
2277 ++*decim_x;
2278 }
2279 }
2280 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2281
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002282 if (error) {
2283 DSSERR("failed to find scaling settings\n");
2284 return -EINVAL;
2285 }
2286
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302287 if (in_width > maxsinglelinewidth) {
2288 DSSERR("Cannot scale max input width exceeded");
2289 return -EINVAL;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302290 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302291 return 0;
2292}
2293
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002294static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302295 const struct omap_video_timings *mgr_timings,
2296 u16 width, u16 height, u16 out_width, u16 out_height,
2297 enum omap_color_mode color_mode, bool *five_taps,
2298 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302299 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302300{
2301 int error;
2302 u16 in_width, in_height;
2303 int min_factor = min(*decim_x, *decim_y);
2304 const int maxsinglelinewidth =
2305 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2306
2307 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002308 in_height = height / *decim_y;
2309 in_width = width / *decim_x;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002310 *five_taps = in_height > out_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302311
2312 if (in_width > maxsinglelinewidth)
2313 if (in_height > out_height &&
2314 in_height < out_height * 2)
2315 *five_taps = false;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002316again:
2317 if (*five_taps)
2318 *core_clk = calc_core_clk_five_taps(pclk, mgr_timings,
2319 in_width, in_height, out_width,
2320 out_height, color_mode);
2321 else
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002322 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302323 in_height, out_width, out_height,
2324 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302325
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002326 error = check_horiz_timing_omap3(pclk, lclk, mgr_timings,
2327 pos_x, in_width, in_height, out_width,
2328 out_height, *five_taps);
2329 if (error && *five_taps) {
2330 *five_taps = false;
2331 goto again;
2332 }
2333
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302334 error = (error || in_width > maxsinglelinewidth * 2 ||
2335 (in_width > maxsinglelinewidth && *five_taps) ||
2336 !*core_clk || *core_clk > dispc_core_clk_rate());
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002337
2338 if (!error) {
2339 /* verify that we're inside the limits of scaler */
2340 if (in_width / 4 > out_width)
2341 error = 1;
2342
2343 if (*five_taps) {
2344 if (in_height / 4 > out_height)
2345 error = 1;
2346 } else {
2347 if (in_height / 2 > out_height)
2348 error = 1;
2349 }
2350 }
2351
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302352 if (error) {
2353 if (*decim_x == *decim_y) {
2354 *decim_x = min_factor;
2355 ++*decim_y;
2356 } else {
2357 swap(*decim_x, *decim_y);
2358 if (*decim_x < *decim_y)
2359 ++*decim_x;
2360 }
2361 }
2362 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2363
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002364 if (error) {
2365 DSSERR("failed to find scaling settings\n");
2366 return -EINVAL;
2367 }
2368
Tomi Valkeinenf5a73482015-03-17 15:31:09 +02002369 if (check_horiz_timing_omap3(pclk, lclk, mgr_timings, pos_x, in_width,
2370 in_height, out_width, out_height, *five_taps)) {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302371 DSSERR("horizontal timing too tight\n");
2372 return -EINVAL;
2373 }
2374
2375 if (in_width > (maxsinglelinewidth * 2)) {
2376 DSSERR("Cannot setup scaling");
2377 DSSERR("width exceeds maximum width possible");
2378 return -EINVAL;
2379 }
2380
2381 if (in_width > maxsinglelinewidth && *five_taps) {
2382 DSSERR("cannot setup scaling with five taps");
2383 return -EINVAL;
2384 }
2385 return 0;
2386}
2387
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002388static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302389 const struct omap_video_timings *mgr_timings,
2390 u16 width, u16 height, u16 out_width, u16 out_height,
2391 enum omap_color_mode color_mode, bool *five_taps,
2392 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302393 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302394{
2395 u16 in_width, in_width_max;
2396 int decim_x_min = *decim_x;
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002397 u16 in_height = height / *decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302398 const int maxsinglelinewidth =
2399 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja8ba85302012-09-26 17:00:37 +05302400 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302401
Archit Taneja5d501082012-11-07 11:45:02 +05302402 if (mem_to_mem) {
2403 in_width_max = out_width * maxdownscale;
2404 } else {
Archit Taneja8ba85302012-09-26 17:00:37 +05302405 in_width_max = dispc_core_clk_rate() /
2406 DIV_ROUND_UP(pclk, out_width);
Archit Taneja5d501082012-11-07 11:45:02 +05302407 }
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302408
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302409 *decim_x = DIV_ROUND_UP(width, in_width_max);
2410
2411 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2412 if (*decim_x > *x_predecim)
2413 return -EINVAL;
2414
2415 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002416 in_width = width / *decim_x;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302417 } while (*decim_x <= *x_predecim &&
2418 in_width > maxsinglelinewidth && ++*decim_x);
2419
2420 if (in_width > maxsinglelinewidth) {
2421 DSSERR("Cannot scale width exceeds max line width");
2422 return -EINVAL;
2423 }
2424
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002425 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
Archit Taneja8ba85302012-09-26 17:00:37 +05302426 out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302427 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002428}
2429
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002430static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302431 enum omap_overlay_caps caps,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302432 const struct omap_video_timings *mgr_timings,
2433 u16 width, u16 height, u16 out_width, u16 out_height,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302434 enum omap_color_mode color_mode, bool *five_taps,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302435 int *x_predecim, int *y_predecim, u16 pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302436 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302437{
Archit Taneja0373cac2011-09-08 13:25:17 +05302438 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302439 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302440 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302441 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302442
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002443 if (width == out_width && height == out_height)
2444 return 0;
2445
Tomi Valkeinen4e1d3ca2014-10-03 15:14:09 +00002446 if (pclk == 0 || mgr_timings->pixelclock == 0) {
2447 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2448 return -EINVAL;
2449 }
2450
Archit Taneja5b54ed32012-09-26 16:55:27 +05302451 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002452 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302453
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002454 if (mem_to_mem) {
Archit Taneja1c031442012-11-07 11:45:03 +05302455 *x_predecim = *y_predecim = 1;
2456 } else {
2457 *x_predecim = max_decim_limit;
2458 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2459 dss_has_feature(FEAT_BURST_2D)) ?
2460 2 : max_decim_limit;
2461 }
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302462
2463 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2464 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2465 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2466 color_mode == OMAP_DSS_COLOR_CLUT8) {
2467 *x_predecim = 1;
2468 *y_predecim = 1;
2469 *five_taps = false;
2470 return 0;
2471 }
2472
2473 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2474 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2475
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302476 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302477 return -EINVAL;
2478
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302479 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302480 return -EINVAL;
2481
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002482 ret = dispc.feat->calc_scaling(pclk, lclk, mgr_timings, width, height,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302483 out_width, out_height, color_mode, five_taps,
Archit Taneja8ba85302012-09-26 17:00:37 +05302484 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2485 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302486 if (ret)
2487 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302488
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302489 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2490 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302491
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302492 if (!core_clk || core_clk > dispc_core_clk_rate()) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302493 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302494 "required core clk rate = %lu Hz, "
2495 "current core clk rate = %lu Hz\n",
2496 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302497 return -EINVAL;
2498 }
2499
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302500 *x_predecim = decim_x;
2501 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302502 return 0;
2503}
2504
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002505int dispc_ovl_check(enum omap_plane plane, enum omap_channel channel,
2506 const struct omap_overlay_info *oi,
2507 const struct omap_video_timings *timings,
2508 int *x_predecim, int *y_predecim)
2509{
2510 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2511 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002512 bool fieldmode = false;
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002513 u16 in_height = oi->height;
2514 u16 in_width = oi->width;
2515 bool ilace = timings->interlace;
2516 u16 out_width, out_height;
2517 int pos_x = oi->pos_x;
2518 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2519 unsigned long lclk = dispc_mgr_lclk_rate(channel);
2520
2521 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2522 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
2523
2524 if (ilace && oi->height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002525 fieldmode = true;
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002526
2527 if (ilace) {
2528 if (fieldmode)
2529 in_height /= 2;
2530 out_height /= 2;
2531
2532 DSSDBG("adjusting for ilace: height %d, out_height %d\n",
2533 in_height, out_height);
2534 }
2535
2536 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
2537 return -EINVAL;
2538
2539 return dispc_ovl_calc_scaling(pclk, lclk, caps, timings, in_width,
2540 in_height, out_width, out_height, oi->color_mode,
2541 &five_taps, x_predecim, y_predecim, pos_x,
2542 oi->rotation_type, false);
2543}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002544EXPORT_SYMBOL(dispc_ovl_check);
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002545
Archit Taneja84a880f2012-09-26 16:57:37 +05302546static int dispc_ovl_setup_common(enum omap_plane plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302547 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2548 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2549 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2550 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2551 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
Archit Taneja8ba85302012-09-26 17:00:37 +05302552 bool replication, const struct omap_video_timings *mgr_timings,
2553 bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002554{
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302555 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002556 bool fieldmode = false;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302557 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002558 unsigned offset0, offset1;
2559 s32 row_inc;
2560 s32 pix_inc;
Archit Taneja6be0d732012-11-07 11:45:04 +05302561 u16 frame_width, frame_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002562 unsigned int field_offset = 0;
Archit Taneja84a880f2012-09-26 16:57:37 +05302563 u16 in_height = height;
2564 u16 in_width = width;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302565 int x_predecim = 1, y_predecim = 1;
Archit Taneja8050cbe2012-06-06 16:25:52 +05302566 bool ilace = mgr_timings->interlace;
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002567 unsigned long pclk = dispc_plane_pclk_rate(plane);
2568 unsigned long lclk = dispc_plane_lclk_rate(plane);
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002569
Tomi Valkeinene5666582014-11-28 14:34:15 +02002570 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002571 return -EINVAL;
2572
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002573 switch (color_mode) {
2574 case OMAP_DSS_COLOR_YUV2:
2575 case OMAP_DSS_COLOR_UYVY:
2576 case OMAP_DSS_COLOR_NV12:
2577 if (in_width & 1) {
2578 DSSERR("input width %d is not even for YUV format\n",
2579 in_width);
2580 return -EINVAL;
2581 }
2582 break;
2583
2584 default:
2585 break;
2586 }
2587
Archit Taneja84a880f2012-09-26 16:57:37 +05302588 out_width = out_width == 0 ? width : out_width;
2589 out_height = out_height == 0 ? height : out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002590
Archit Taneja84a880f2012-09-26 16:57:37 +05302591 if (ilace && height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002592 fieldmode = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002593
2594 if (ilace) {
2595 if (fieldmode)
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302596 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302597 pos_y /= 2;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302598 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002599
2600 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
Archit Taneja84a880f2012-09-26 16:57:37 +05302601 "out_height %d\n", in_height, pos_y,
2602 out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002603 }
2604
Archit Taneja84a880f2012-09-26 16:57:37 +05302605 if (!dss_feat_color_mode_supported(plane, color_mode))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302606 return -EINVAL;
2607
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002608 r = dispc_ovl_calc_scaling(pclk, lclk, caps, mgr_timings, in_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302609 in_height, out_width, out_height, color_mode,
2610 &five_taps, &x_predecim, &y_predecim, pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302611 rotation_type, mem_to_mem);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302612 if (r)
2613 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002614
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002615 in_width = in_width / x_predecim;
2616 in_height = in_height / y_predecim;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302617
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002618 if (x_predecim > 1 || y_predecim > 1)
2619 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2620 x_predecim, y_predecim, in_width, in_height);
2621
2622 switch (color_mode) {
2623 case OMAP_DSS_COLOR_YUV2:
2624 case OMAP_DSS_COLOR_UYVY:
2625 case OMAP_DSS_COLOR_NV12:
2626 if (in_width & 1) {
2627 DSSDBG("predecimated input width is not even for YUV format\n");
2628 DSSDBG("adjusting input width %d -> %d\n",
2629 in_width, in_width & ~1);
2630
2631 in_width &= ~1;
2632 }
2633 break;
2634
2635 default:
2636 break;
2637 }
2638
Archit Taneja84a880f2012-09-26 16:57:37 +05302639 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2640 color_mode == OMAP_DSS_COLOR_UYVY ||
2641 color_mode == OMAP_DSS_COLOR_NV12)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302642 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002643
2644 if (ilace && !fieldmode) {
2645 /*
2646 * when downscaling the bottom field may have to start several
2647 * source lines below the top field. Unfortunately ACCUI
2648 * registers will only hold the fractional part of the offset
2649 * so the integer part must be added to the base address of the
2650 * bottom field.
2651 */
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302652 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002653 field_offset = 0;
2654 else
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302655 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002656 }
2657
2658 /* Fields are independent but interleaved in memory. */
2659 if (fieldmode)
2660 field_offset = 1;
2661
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002662 offset0 = 0;
2663 offset1 = 0;
2664 row_inc = 0;
2665 pix_inc = 0;
2666
Archit Taneja6be0d732012-11-07 11:45:04 +05302667 if (plane == OMAP_DSS_WB) {
2668 frame_width = out_width;
2669 frame_height = out_height;
2670 } else {
2671 frame_width = in_width;
2672 frame_height = height;
2673 }
2674
Archit Taneja84a880f2012-09-26 16:57:37 +05302675 if (rotation_type == OMAP_DSS_ROT_TILER)
Archit Taneja6be0d732012-11-07 11:45:04 +05302676 calc_tiler_rotation_offset(screen_width, frame_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302677 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302678 &offset0, &offset1, &row_inc, &pix_inc,
2679 x_predecim, y_predecim);
Archit Taneja84a880f2012-09-26 16:57:37 +05302680 else if (rotation_type == OMAP_DSS_ROT_DMA)
Archit Taneja6be0d732012-11-07 11:45:04 +05302681 calc_dma_rotation_offset(rotation, mirror, screen_width,
2682 frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302683 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302684 &offset0, &offset1, &row_inc, &pix_inc,
2685 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002686 else
Archit Taneja84a880f2012-09-26 16:57:37 +05302687 calc_vrfb_rotation_offset(rotation, mirror,
Archit Taneja6be0d732012-11-07 11:45:04 +05302688 screen_width, frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302689 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302690 &offset0, &offset1, &row_inc, &pix_inc,
2691 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002692
2693 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2694 offset0, offset1, row_inc, pix_inc);
2695
Archit Taneja84a880f2012-09-26 16:57:37 +05302696 dispc_ovl_set_color_mode(plane, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002697
Archit Taneja84a880f2012-09-26 16:57:37 +05302698 dispc_ovl_configure_burst_type(plane, rotation_type);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302699
Archit Taneja84a880f2012-09-26 16:57:37 +05302700 dispc_ovl_set_ba0(plane, paddr + offset0);
2701 dispc_ovl_set_ba1(plane, paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002702
Archit Taneja84a880f2012-09-26 16:57:37 +05302703 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2704 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2705 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302706 }
2707
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03002708 if (dispc.feat->last_pixel_inc_missing)
2709 row_inc += pix_inc - 1;
2710
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002711 dispc_ovl_set_row_inc(plane, row_inc);
2712 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002713
Archit Taneja84a880f2012-09-26 16:57:37 +05302714 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302715 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002716
Archit Taneja84a880f2012-09-26 16:57:37 +05302717 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002718
Archit Taneja78b687f2012-09-21 14:51:49 +05302719 dispc_ovl_set_input_size(plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002720
Archit Taneja5b54ed32012-09-26 16:55:27 +05302721 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302722 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2723 out_height, ilace, five_taps, fieldmode,
Archit Taneja84a880f2012-09-26 16:57:37 +05302724 color_mode, rotation);
Archit Taneja78b687f2012-09-21 14:51:49 +05302725 dispc_ovl_set_output_size(plane, out_width, out_height);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002726 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002727 }
2728
Archit Tanejac35eeb22013-03-26 19:15:24 +05302729 dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, mirror,
2730 color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002731
Archit Taneja84a880f2012-09-26 16:57:37 +05302732 dispc_ovl_set_zorder(plane, caps, zorder);
2733 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2734 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002735
Archit Tanejad79db852012-09-22 12:30:17 +05302736 dispc_ovl_enable_replication(plane, caps, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302737
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002738 return 0;
2739}
2740
Archit Taneja84a880f2012-09-26 16:57:37 +05302741int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
Archit Taneja8ba85302012-09-26 17:00:37 +05302742 bool replication, const struct omap_video_timings *mgr_timings,
2743 bool mem_to_mem)
Archit Taneja84a880f2012-09-26 16:57:37 +05302744{
2745 int r;
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002746 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
Archit Taneja84a880f2012-09-26 16:57:37 +05302747 enum omap_channel channel;
2748
2749 channel = dispc_ovl_get_channel_out(plane);
2750
Arnd Bergmann24f13a62014-04-24 13:28:18 +01002751 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2752 " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2753 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
Archit Taneja84a880f2012-09-26 16:57:37 +05302754 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2755 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2756
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002757 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302758 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2759 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2760 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
Archit Taneja8ba85302012-09-26 17:00:37 +05302761 oi->rotation_type, replication, mgr_timings, mem_to_mem);
Archit Taneja84a880f2012-09-26 16:57:37 +05302762
2763 return r;
2764}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002765EXPORT_SYMBOL(dispc_ovl_setup);
Archit Taneja84a880f2012-09-26 16:57:37 +05302766
Archit Taneja749feff2012-08-31 12:32:52 +05302767int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302768 bool mem_to_mem, const struct omap_video_timings *mgr_timings)
Archit Taneja749feff2012-08-31 12:32:52 +05302769{
2770 int r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302771 u32 l;
Archit Taneja749feff2012-08-31 12:32:52 +05302772 enum omap_plane plane = OMAP_DSS_WB;
2773 const int pos_x = 0, pos_y = 0;
2774 const u8 zorder = 0, global_alpha = 0;
2775 const bool replication = false;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302776 bool truncation;
Archit Taneja749feff2012-08-31 12:32:52 +05302777 int in_width = mgr_timings->x_res;
2778 int in_height = mgr_timings->y_res;
2779 enum omap_overlay_caps caps =
2780 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2781
2782 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2783 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2784 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2785 wi->mirror);
2786
2787 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2788 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2789 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2790 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302791 replication, mgr_timings, mem_to_mem);
2792
2793 switch (wi->color_mode) {
2794 case OMAP_DSS_COLOR_RGB16:
2795 case OMAP_DSS_COLOR_RGB24P:
2796 case OMAP_DSS_COLOR_ARGB16:
2797 case OMAP_DSS_COLOR_RGBA16:
2798 case OMAP_DSS_COLOR_RGB12U:
2799 case OMAP_DSS_COLOR_ARGB16_1555:
2800 case OMAP_DSS_COLOR_XRGB16_1555:
2801 case OMAP_DSS_COLOR_RGBX16:
2802 truncation = true;
2803 break;
2804 default:
2805 truncation = false;
2806 break;
2807 }
2808
2809 /* setup extra DISPC_WB_ATTRIBUTES */
2810 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2811 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2812 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2813 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Archit Taneja749feff2012-08-31 12:32:52 +05302814
2815 return r;
2816}
2817
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002818int dispc_ovl_enable(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002819{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002820 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2821
Archit Taneja9b372c22011-05-06 11:45:49 +05302822 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002823
2824 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002825}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002826EXPORT_SYMBOL(dispc_ovl_enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002827
Tomi Valkeinen04bd8ac2012-10-10 14:13:15 +03002828bool dispc_ovl_enabled(enum omap_plane plane)
2829{
2830 return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2831}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002832EXPORT_SYMBOL(dispc_ovl_enabled);
Tomi Valkeinen04bd8ac2012-10-10 14:13:15 +03002833
Tomi Valkeinenf1a813d2012-10-19 14:16:06 +03002834void dispc_mgr_enable(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002835{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302836 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2837 /* flush posted write */
2838 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002839}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002840EXPORT_SYMBOL(dispc_mgr_enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002841
Tomi Valkeinen65398512012-10-10 11:44:17 +03002842bool dispc_mgr_is_enabled(enum omap_channel channel)
2843{
2844 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2845}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002846EXPORT_SYMBOL(dispc_mgr_is_enabled);
Tomi Valkeinen65398512012-10-10 11:44:17 +03002847
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302848void dispc_wb_enable(bool enable)
2849{
Tomi Valkeinen916188a2012-10-10 14:13:26 +03002850 dispc_ovl_enable(OMAP_DSS_WB, enable);
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302851}
2852
2853bool dispc_wb_is_enabled(void)
2854{
Tomi Valkeinen916188a2012-10-10 14:13:26 +03002855 return dispc_ovl_enabled(OMAP_DSS_WB);
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302856}
2857
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002858static void dispc_lcd_enable_signal_polarity(bool act_high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002859{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002860 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2861 return;
2862
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002863 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002864}
2865
2866void dispc_lcd_enable_signal(bool enable)
2867{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002868 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2869 return;
2870
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002871 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002872}
2873
2874void dispc_pck_free_enable(bool enable)
2875{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002876 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2877 return;
2878
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002879 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002880}
2881
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002882static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002883{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302884 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002885}
2886
2887
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002888static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002889{
Archit Tanejad21f43b2012-06-21 09:45:11 +05302890 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002891}
2892
2893void dispc_set_loadmode(enum omap_dss_load_mode mode)
2894{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002895 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002896}
2897
2898
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002899static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002900{
Sumit Semwal8613b002010-12-02 11:27:09 +00002901 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002902}
2903
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002904static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002905 enum omap_dss_trans_key_type type,
2906 u32 trans_key)
2907{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302908 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002909
Sumit Semwal8613b002010-12-02 11:27:09 +00002910 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002911}
2912
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002913static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002914{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302915 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002916}
Archit Taneja11354dd2011-09-26 11:47:29 +05302917
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002918static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2919 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002920{
Archit Taneja11354dd2011-09-26 11:47:29 +05302921 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002922 return;
2923
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002924 if (ch == OMAP_DSS_CHANNEL_LCD)
2925 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002926 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002927 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002928}
Archit Taneja11354dd2011-09-26 11:47:29 +05302929
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002930void dispc_mgr_setup(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02002931 const struct omap_overlay_manager_info *info)
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002932{
2933 dispc_mgr_set_default_color(channel, info->default_color);
2934 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2935 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2936 dispc_mgr_enable_alpha_fixed_zorder(channel,
2937 info->partial_alpha_enabled);
2938 if (dss_has_feature(FEAT_CPR)) {
2939 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2940 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2941 }
2942}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002943EXPORT_SYMBOL(dispc_mgr_setup);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002944
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002945static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002946{
2947 int code;
2948
2949 switch (data_lines) {
2950 case 12:
2951 code = 0;
2952 break;
2953 case 16:
2954 code = 1;
2955 break;
2956 case 18:
2957 code = 2;
2958 break;
2959 case 24:
2960 code = 3;
2961 break;
2962 default:
2963 BUG();
2964 return;
2965 }
2966
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302967 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002968}
2969
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002970static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002971{
2972 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302973 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002974
2975 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302976 case DSS_IO_PAD_MODE_RESET:
2977 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002978 gpout1 = 0;
2979 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302980 case DSS_IO_PAD_MODE_RFBI:
2981 gpout0 = 1;
2982 gpout1 = 0;
2983 break;
2984 case DSS_IO_PAD_MODE_BYPASS:
2985 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002986 gpout1 = 1;
2987 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002988 default:
2989 BUG();
2990 return;
2991 }
2992
Archit Taneja569969d2011-08-22 17:41:57 +05302993 l = dispc_read_reg(DISPC_CONTROL);
2994 l = FLD_MOD(l, gpout0, 15, 15);
2995 l = FLD_MOD(l, gpout1, 16, 16);
2996 dispc_write_reg(DISPC_CONTROL, l);
2997}
2998
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002999static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
Archit Taneja569969d2011-08-22 17:41:57 +05303000{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05303001 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003002}
3003
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003004void dispc_mgr_set_lcd_config(enum omap_channel channel,
3005 const struct dss_lcd_mgr_config *config)
3006{
3007 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
3008
3009 dispc_mgr_enable_stallmode(channel, config->stallmode);
3010 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
3011
3012 dispc_mgr_set_clock_div(channel, &config->clock_info);
3013
3014 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
3015
3016 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
3017
3018 dispc_mgr_set_lcd_type_tft(channel);
3019}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003020EXPORT_SYMBOL(dispc_mgr_set_lcd_config);
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003021
Archit Taneja8f366162012-04-16 12:53:44 +05303022static bool _dispc_mgr_size_ok(u16 width, u16 height)
3023{
Archit Taneja33b89922012-11-14 13:50:15 +05303024 return width <= dispc.feat->mgr_width_max &&
3025 height <= dispc.feat->mgr_height_max;
Archit Taneja8f366162012-04-16 12:53:44 +05303026}
3027
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003028static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
3029 int vsw, int vfp, int vbp)
3030{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303031 if (hsw < 1 || hsw > dispc.feat->sw_max ||
3032 hfp < 1 || hfp > dispc.feat->hp_max ||
3033 hbp < 1 || hbp > dispc.feat->hp_max ||
3034 vsw < 1 || vsw > dispc.feat->sw_max ||
3035 vfp < 0 || vfp > dispc.feat->vp_max ||
3036 vbp < 0 || vbp > dispc.feat->vp_max)
3037 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003038 return true;
3039}
3040
Archit Tanejaca5ca692013-03-26 19:15:22 +05303041static bool _dispc_mgr_pclk_ok(enum omap_channel channel,
3042 unsigned long pclk)
3043{
3044 if (dss_mgr_is_lcd(channel))
3045 return pclk <= dispc.feat->max_lcd_pclk ? true : false;
3046 else
3047 return pclk <= dispc.feat->max_tv_pclk ? true : false;
3048}
3049
Archit Taneja8f366162012-04-16 12:53:44 +05303050bool dispc_mgr_timings_ok(enum omap_channel channel,
Archit Tanejab917fa32012-04-27 01:07:28 +05303051 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003052{
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003053 if (!_dispc_mgr_size_ok(timings->x_res, timings->y_res))
3054 return false;
Archit Taneja8f366162012-04-16 12:53:44 +05303055
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003056 if (!_dispc_mgr_pclk_ok(channel, timings->pixelclock))
3057 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303058
3059 if (dss_mgr_is_lcd(channel)) {
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03003060 /* TODO: OMAP4+ supports interlace for LCD outputs */
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003061 if (timings->interlace)
3062 return false;
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03003063
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003064 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303065 timings->hbp, timings->vsw, timings->vfp,
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003066 timings->vbp))
3067 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303068 }
Archit Taneja8f366162012-04-16 12:53:44 +05303069
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003070 return true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003071}
3072
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003073static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
Archit Taneja655e2942012-06-21 10:37:43 +05303074 int hfp, int hbp, int vsw, int vfp, int vbp,
3075 enum omap_dss_signal_level vsync_level,
3076 enum omap_dss_signal_level hsync_level,
3077 enum omap_dss_signal_edge data_pclk_edge,
3078 enum omap_dss_signal_level de_level,
3079 enum omap_dss_signal_edge sync_pclk_edge)
3080
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003081{
Archit Taneja655e2942012-06-21 10:37:43 +05303082 u32 timing_h, timing_v, l;
Tomi Valkeinened351882014-10-02 17:58:49 +00003083 bool onoff, rf, ipc, vs, hs, de;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003084
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303085 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
3086 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
3087 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
3088 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
3089 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
3090 FLD_VAL(vbp, dispc.feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003091
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003092 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
3093 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05303094
Tomi Valkeinened351882014-10-02 17:58:49 +00003095 switch (vsync_level) {
3096 case OMAPDSS_SIG_ACTIVE_LOW:
3097 vs = true;
3098 break;
3099 case OMAPDSS_SIG_ACTIVE_HIGH:
3100 vs = false;
3101 break;
3102 default:
3103 BUG();
3104 }
3105
3106 switch (hsync_level) {
3107 case OMAPDSS_SIG_ACTIVE_LOW:
3108 hs = true;
3109 break;
3110 case OMAPDSS_SIG_ACTIVE_HIGH:
3111 hs = false;
3112 break;
3113 default:
3114 BUG();
3115 }
3116
3117 switch (de_level) {
3118 case OMAPDSS_SIG_ACTIVE_LOW:
3119 de = true;
3120 break;
3121 case OMAPDSS_SIG_ACTIVE_HIGH:
3122 de = false;
3123 break;
3124 default:
3125 BUG();
3126 }
3127
Archit Taneja655e2942012-06-21 10:37:43 +05303128 switch (data_pclk_edge) {
3129 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3130 ipc = false;
3131 break;
3132 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3133 ipc = true;
3134 break;
Archit Taneja655e2942012-06-21 10:37:43 +05303135 default:
3136 BUG();
3137 }
3138
Tomi Valkeinen7a163602014-10-02 17:58:48 +00003139 /* always use the 'rf' setting */
3140 onoff = true;
3141
Archit Taneja655e2942012-06-21 10:37:43 +05303142 switch (sync_pclk_edge) {
Archit Taneja655e2942012-06-21 10:37:43 +05303143 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
Archit Taneja655e2942012-06-21 10:37:43 +05303144 rf = false;
3145 break;
3146 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
Archit Taneja655e2942012-06-21 10:37:43 +05303147 rf = true;
3148 break;
3149 default:
3150 BUG();
Joe Perchescf6ac4ce2013-10-08 16:23:24 -07003151 }
Archit Taneja655e2942012-06-21 10:37:43 +05303152
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003153 l = FLD_VAL(onoff, 17, 17) |
3154 FLD_VAL(rf, 16, 16) |
Tomi Valkeinened351882014-10-02 17:58:49 +00003155 FLD_VAL(de, 15, 15) |
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003156 FLD_VAL(ipc, 14, 14) |
Tomi Valkeinened351882014-10-02 17:58:49 +00003157 FLD_VAL(hs, 13, 13) |
3158 FLD_VAL(vs, 12, 12);
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003159
Archit Taneja655e2942012-06-21 10:37:43 +05303160 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003161
3162 if (dispc.syscon_pol) {
3163 const int shifts[] = {
3164 [OMAP_DSS_CHANNEL_LCD] = 0,
3165 [OMAP_DSS_CHANNEL_LCD2] = 1,
3166 [OMAP_DSS_CHANNEL_LCD3] = 2,
3167 };
3168
3169 u32 mask, val;
3170
3171 mask = (1 << 0) | (1 << 3) | (1 << 6);
3172 val = (rf << 0) | (ipc << 3) | (onoff << 6);
3173
3174 mask <<= 16 + shifts[channel];
3175 val <<= 16 + shifts[channel];
3176
3177 regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset,
3178 mask, val);
3179 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003180}
3181
3182/* change name to mode? */
Archit Tanejac51d9212012-04-16 12:53:43 +05303183void dispc_mgr_set_timings(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003184 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003185{
3186 unsigned xtot, ytot;
3187 unsigned long ht, vt;
Archit Taneja2aefad42012-05-18 14:36:54 +05303188 struct omap_video_timings t = *timings;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003189
Archit Taneja2aefad42012-05-18 14:36:54 +05303190 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
Archit Tanejac51d9212012-04-16 12:53:43 +05303191
Archit Taneja2aefad42012-05-18 14:36:54 +05303192 if (!dispc_mgr_timings_ok(channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05303193 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003194 return;
3195 }
Archit Tanejac51d9212012-04-16 12:53:43 +05303196
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303197 if (dss_mgr_is_lcd(channel)) {
Archit Taneja2aefad42012-05-18 14:36:54 +05303198 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
Archit Taneja655e2942012-06-21 10:37:43 +05303199 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
3200 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
Archit Tanejac51d9212012-04-16 12:53:43 +05303201
Archit Taneja2aefad42012-05-18 14:36:54 +05303202 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
3203 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
Archit Tanejac51d9212012-04-16 12:53:43 +05303204
Tomi Valkeinend8d789412013-04-10 14:12:14 +03003205 ht = timings->pixelclock / xtot;
3206 vt = timings->pixelclock / xtot / ytot;
Archit Tanejac51d9212012-04-16 12:53:43 +05303207
Tomi Valkeinend8d789412013-04-10 14:12:14 +03003208 DSSDBG("pck %u\n", timings->pixelclock);
Archit Tanejac51d9212012-04-16 12:53:43 +05303209 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Archit Taneja2aefad42012-05-18 14:36:54 +05303210 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
Archit Taneja655e2942012-06-21 10:37:43 +05303211 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3212 t.vsync_level, t.hsync_level, t.data_pclk_edge,
3213 t.de_level, t.sync_pclk_edge);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003214
Archit Tanejac51d9212012-04-16 12:53:43 +05303215 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05303216 } else {
Archit Taneja23c8f882012-06-28 11:15:51 +05303217 if (t.interlace == true)
Archit Taneja2aefad42012-05-18 14:36:54 +05303218 t.y_res /= 2;
Archit Tanejac51d9212012-04-16 12:53:43 +05303219 }
Archit Taneja8f366162012-04-16 12:53:44 +05303220
Archit Taneja2aefad42012-05-18 14:36:54 +05303221 dispc_mgr_set_size(channel, t.x_res, t.y_res);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003222}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003223EXPORT_SYMBOL(dispc_mgr_set_timings);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003224
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003225static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003226 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003227{
3228 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003229 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003230
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003231 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003232 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003233
3234 if (dss_has_feature(FEAT_CORE_CLK_DIV) == false &&
3235 channel == OMAP_DSS_CHANNEL_LCD)
3236 dispc.core_clk_rate = dispc_fclk_rate() / lck_div;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003237}
3238
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003239static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00003240 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003241{
3242 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003243 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003244 *lck_div = FLD_GET(l, 23, 16);
3245 *pck_div = FLD_GET(l, 7, 0);
3246}
3247
3248unsigned long dispc_fclk_rate(void)
3249{
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003250 struct dss_pll *pll;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003251 unsigned long r = 0;
3252
Taneja, Archit66534e82011-03-08 05:50:34 -06003253 switch (dss_get_dispc_clk_source()) {
Archit Taneja89a35e52011-04-12 13:52:23 +05303254 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen5aaee692012-12-12 10:37:03 +02003255 r = dss_get_dispc_clk_rate();
Taneja, Archit66534e82011-03-08 05:50:34 -06003256 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05303257 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003258 pll = dss_pll_find("dsi0");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003259 if (!pll)
3260 pll = dss_pll_find("video0");
3261
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003262 r = pll->cinfo.clkout[0];
Taneja, Archit66534e82011-03-08 05:50:34 -06003263 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05303264 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003265 pll = dss_pll_find("dsi1");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003266 if (!pll)
3267 pll = dss_pll_find("video1");
3268
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003269 r = pll->cinfo.clkout[0];
Archit Taneja5a8b5722011-05-12 17:26:29 +05303270 break;
Taneja, Archit66534e82011-03-08 05:50:34 -06003271 default:
3272 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003273 return 0;
Taneja, Archit66534e82011-03-08 05:50:34 -06003274 }
3275
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003276 return r;
3277}
3278
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003279unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003280{
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003281 struct dss_pll *pll;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003282 int lcd;
3283 unsigned long r;
3284 u32 l;
3285
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003286 if (dss_mgr_is_lcd(channel)) {
3287 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003288
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003289 lcd = FLD_GET(l, 23, 16);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003290
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003291 switch (dss_get_lcd_clk_source(channel)) {
3292 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen5aaee692012-12-12 10:37:03 +02003293 r = dss_get_dispc_clk_rate();
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003294 break;
3295 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003296 pll = dss_pll_find("dsi0");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003297 if (!pll)
3298 pll = dss_pll_find("video0");
3299
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003300 r = pll->cinfo.clkout[0];
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003301 break;
3302 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003303 pll = dss_pll_find("dsi1");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003304 if (!pll)
3305 pll = dss_pll_find("video1");
3306
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003307 r = pll->cinfo.clkout[0];
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003308 break;
3309 default:
3310 BUG();
3311 return 0;
3312 }
3313
3314 return r / lcd;
3315 } else {
3316 return dispc_fclk_rate();
Taneja, Architea751592011-03-08 05:50:35 -06003317 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003318}
3319
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003320unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003321{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003322 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003323
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303324 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303325 int pcd;
3326 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003327
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303328 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003329
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303330 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003331
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303332 r = dispc_mgr_lclk_rate(channel);
3333
3334 return r / pcd;
3335 } else {
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003336 return dispc.tv_pclk_rate;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303337 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003338}
3339
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003340void dispc_set_tv_pclk(unsigned long pclk)
3341{
3342 dispc.tv_pclk_rate = pclk;
3343}
3344
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303345unsigned long dispc_core_clk_rate(void)
3346{
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003347 return dispc.core_clk_rate;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303348}
3349
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303350static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3351{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003352 enum omap_channel channel;
3353
3354 if (plane == OMAP_DSS_WB)
3355 return 0;
3356
3357 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303358
3359 return dispc_mgr_pclk_rate(channel);
3360}
3361
3362static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3363{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003364 enum omap_channel channel;
3365
3366 if (plane == OMAP_DSS_WB)
3367 return 0;
3368
3369 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303370
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003371 return dispc_mgr_lclk_rate(channel);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303372}
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003373
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303374static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003375{
3376 int lcd, pcd;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303377 enum omap_dss_clk_source lcd_clk_src;
3378
3379 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3380
3381 lcd_clk_src = dss_get_lcd_clk_source(channel);
3382
3383 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3384 dss_get_generic_clk_source_name(lcd_clk_src),
3385 dss_feat_get_clk_source_name(lcd_clk_src));
3386
3387 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3388
3389 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3390 dispc_mgr_lclk_rate(channel), lcd);
3391 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3392 dispc_mgr_pclk_rate(channel), pcd);
3393}
3394
3395void dispc_dump_clocks(struct seq_file *s)
3396{
3397 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003398 u32 l;
Archit Taneja89a35e52011-04-12 13:52:23 +05303399 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003400
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003401 if (dispc_runtime_get())
3402 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003403
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003404 seq_printf(s, "- DISPC -\n");
3405
Archit Taneja067a57e2011-03-02 11:57:25 +05303406 seq_printf(s, "dispc fclk source = %s (%s)\n",
3407 dss_get_generic_clk_source_name(dispc_clk_src),
3408 dss_feat_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003409
3410 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00003411
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003412 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3413 seq_printf(s, "- DISPC-CORE-CLK -\n");
3414 l = dispc_read_reg(DISPC_DIVISOR);
3415 lcd = FLD_GET(l, 23, 16);
3416
3417 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3418 (dispc_fclk_rate()/lcd), lcd);
3419 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003420
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303421 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003422
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303423 if (dss_has_feature(FEAT_MGR_LCD2))
3424 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3425 if (dss_has_feature(FEAT_MGR_LCD3))
3426 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003427
3428 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003429}
3430
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003431static void dispc_dump_regs(struct seq_file *s)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003432{
Archit Taneja4dd2da12011-08-05 19:06:01 +05303433 int i, j;
3434 const char *mgr_names[] = {
3435 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3436 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3437 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303438 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303439 };
3440 const char *ovl_names[] = {
3441 [OMAP_DSS_GFX] = "GFX",
3442 [OMAP_DSS_VIDEO1] = "VID1",
3443 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303444 [OMAP_DSS_VIDEO3] = "VID3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303445 };
3446 const char **p_names;
3447
Archit Taneja9b372c22011-05-06 11:45:49 +05303448#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003449
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003450 if (dispc_runtime_get())
3451 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003452
Archit Taneja5010be82011-08-05 19:06:00 +05303453 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003454 DUMPREG(DISPC_REVISION);
3455 DUMPREG(DISPC_SYSCONFIG);
3456 DUMPREG(DISPC_SYSSTATUS);
3457 DUMPREG(DISPC_IRQSTATUS);
3458 DUMPREG(DISPC_IRQENABLE);
3459 DUMPREG(DISPC_CONTROL);
3460 DUMPREG(DISPC_CONFIG);
3461 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003462 DUMPREG(DISPC_LINE_STATUS);
3463 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05303464 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3465 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003466 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003467 if (dss_has_feature(FEAT_MGR_LCD2)) {
3468 DUMPREG(DISPC_CONTROL2);
3469 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003470 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303471 if (dss_has_feature(FEAT_MGR_LCD3)) {
3472 DUMPREG(DISPC_CONTROL3);
3473 DUMPREG(DISPC_CONFIG3);
3474 }
Tomi Valkeinen29fceee2013-11-14 11:38:25 +02003475 if (dss_has_feature(FEAT_MFLAG))
3476 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003477
Archit Taneja5010be82011-08-05 19:06:00 +05303478#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003479
Archit Taneja5010be82011-08-05 19:06:00 +05303480#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05303481#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003482 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303483 dispc_read_reg(DISPC_REG(i, r)))
3484
Archit Taneja4dd2da12011-08-05 19:06:01 +05303485 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303486
Archit Taneja4dd2da12011-08-05 19:06:01 +05303487 /* DISPC channel specific registers */
3488 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3489 DUMPREG(i, DISPC_DEFAULT_COLOR);
3490 DUMPREG(i, DISPC_TRANS_COLOR);
3491 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003492
Archit Taneja4dd2da12011-08-05 19:06:01 +05303493 if (i == OMAP_DSS_CHANNEL_DIGIT)
3494 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303495
Archit Taneja4dd2da12011-08-05 19:06:01 +05303496 DUMPREG(i, DISPC_TIMING_H);
3497 DUMPREG(i, DISPC_TIMING_V);
3498 DUMPREG(i, DISPC_POL_FREQ);
3499 DUMPREG(i, DISPC_DIVISORo);
Archit Taneja5010be82011-08-05 19:06:00 +05303500
Archit Taneja4dd2da12011-08-05 19:06:01 +05303501 DUMPREG(i, DISPC_DATA_CYCLE1);
3502 DUMPREG(i, DISPC_DATA_CYCLE2);
3503 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003504
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003505 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303506 DUMPREG(i, DISPC_CPR_COEF_R);
3507 DUMPREG(i, DISPC_CPR_COEF_G);
3508 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003509 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003510 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003511
Archit Taneja4dd2da12011-08-05 19:06:01 +05303512 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003513
Archit Taneja4dd2da12011-08-05 19:06:01 +05303514 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3515 DUMPREG(i, DISPC_OVL_BA0);
3516 DUMPREG(i, DISPC_OVL_BA1);
3517 DUMPREG(i, DISPC_OVL_POSITION);
3518 DUMPREG(i, DISPC_OVL_SIZE);
3519 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3520 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3521 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3522 DUMPREG(i, DISPC_OVL_ROW_INC);
3523 DUMPREG(i, DISPC_OVL_PIXEL_INC);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003524
Archit Taneja4dd2da12011-08-05 19:06:01 +05303525 if (dss_has_feature(FEAT_PRELOAD))
3526 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003527 if (dss_has_feature(FEAT_MFLAG))
3528 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003529
Archit Taneja4dd2da12011-08-05 19:06:01 +05303530 if (i == OMAP_DSS_GFX) {
3531 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3532 DUMPREG(i, DISPC_OVL_TABLE_BA);
3533 continue;
3534 }
3535
3536 DUMPREG(i, DISPC_OVL_FIR);
3537 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3538 DUMPREG(i, DISPC_OVL_ACCU0);
3539 DUMPREG(i, DISPC_OVL_ACCU1);
3540 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3541 DUMPREG(i, DISPC_OVL_BA0_UV);
3542 DUMPREG(i, DISPC_OVL_BA1_UV);
3543 DUMPREG(i, DISPC_OVL_FIR2);
3544 DUMPREG(i, DISPC_OVL_ACCU2_0);
3545 DUMPREG(i, DISPC_OVL_ACCU2_1);
3546 }
3547 if (dss_has_feature(FEAT_ATTR2))
3548 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
Archit Taneja5010be82011-08-05 19:06:00 +05303549 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003550
Archit Taneja5010be82011-08-05 19:06:00 +05303551#undef DISPC_REG
3552#undef DUMPREG
3553
3554#define DISPC_REG(plane, name, i) name(plane, i)
3555#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303556 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003557 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303558 dispc_read_reg(DISPC_REG(plane, name, i)))
3559
Archit Taneja4dd2da12011-08-05 19:06:01 +05303560 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303561
Archit Taneja4dd2da12011-08-05 19:06:01 +05303562 /* start from OMAP_DSS_VIDEO1 */
3563 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3564 for (j = 0; j < 8; j++)
3565 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303566
Archit Taneja4dd2da12011-08-05 19:06:01 +05303567 for (j = 0; j < 8; j++)
3568 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303569
Archit Taneja4dd2da12011-08-05 19:06:01 +05303570 for (j = 0; j < 5; j++)
3571 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003572
Archit Taneja4dd2da12011-08-05 19:06:01 +05303573 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3574 for (j = 0; j < 8; j++)
3575 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3576 }
Amber Jainab5ca072011-05-19 19:47:53 +05303577
Archit Taneja4dd2da12011-08-05 19:06:01 +05303578 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3579 for (j = 0; j < 8; j++)
3580 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303581
Archit Taneja4dd2da12011-08-05 19:06:01 +05303582 for (j = 0; j < 8; j++)
3583 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303584
Archit Taneja4dd2da12011-08-05 19:06:01 +05303585 for (j = 0; j < 8; j++)
3586 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3587 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003588 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003589
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003590 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05303591
3592#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003593#undef DUMPREG
3594}
3595
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003596/* calculate clock rates using dividers in cinfo */
3597int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3598 struct dispc_clock_info *cinfo)
3599{
3600 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3601 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003602 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003603 return -EINVAL;
3604
3605 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3606 cinfo->pck = cinfo->lck / cinfo->pck_div;
3607
3608 return 0;
3609}
3610
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003611bool dispc_div_calc(unsigned long dispc,
3612 unsigned long pck_min, unsigned long pck_max,
3613 dispc_div_calc_func func, void *data)
3614{
3615 int lckd, lckd_start, lckd_stop;
3616 int pckd, pckd_start, pckd_stop;
3617 unsigned long pck, lck;
3618 unsigned long lck_max;
3619 unsigned long pckd_hw_min, pckd_hw_max;
3620 unsigned min_fck_per_pck;
3621 unsigned long fck;
3622
3623#ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3624 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3625#else
3626 min_fck_per_pck = 0;
3627#endif
3628
3629 pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3630 pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3631
3632 lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
3633
3634 pck_min = pck_min ? pck_min : 1;
3635 pck_max = pck_max ? pck_max : ULONG_MAX;
3636
3637 lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul);
3638 lckd_stop = min(dispc / pck_min, 255ul);
3639
3640 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3641 lck = dispc / lckd;
3642
3643 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3644 pckd_stop = min(lck / pck_min, pckd_hw_max);
3645
3646 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3647 pck = lck / pckd;
3648
3649 /*
3650 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3651 * clock, which means we're configuring DISPC fclk here
3652 * also. Thus we need to use the calculated lck. For
3653 * OMAP4+ the DISPC fclk is a separate clock.
3654 */
3655 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3656 fck = dispc_core_clk_rate();
3657 else
3658 fck = lck;
3659
3660 if (fck < pck * min_fck_per_pck)
3661 continue;
3662
3663 if (func(lckd, pckd, lck, pck, data))
3664 return true;
3665 }
3666 }
3667
3668 return false;
3669}
3670
Archit Tanejaf0d08f82012-06-29 14:00:54 +05303671void dispc_mgr_set_clock_div(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003672 const struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003673{
3674 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3675 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3676
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003677 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003678}
3679
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003680int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003681 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003682{
3683 unsigned long fck;
3684
3685 fck = dispc_fclk_rate();
3686
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003687 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3688 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003689
3690 cinfo->lck = fck / cinfo->lck_div;
3691 cinfo->pck = cinfo->lck / cinfo->pck_div;
3692
3693 return 0;
3694}
3695
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003696u32 dispc_read_irqstatus(void)
3697{
3698 return dispc_read_reg(DISPC_IRQSTATUS);
3699}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003700EXPORT_SYMBOL(dispc_read_irqstatus);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003701
3702void dispc_clear_irqstatus(u32 mask)
3703{
3704 dispc_write_reg(DISPC_IRQSTATUS, mask);
3705}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003706EXPORT_SYMBOL(dispc_clear_irqstatus);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003707
3708u32 dispc_read_irqenable(void)
3709{
3710 return dispc_read_reg(DISPC_IRQENABLE);
3711}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003712EXPORT_SYMBOL(dispc_read_irqenable);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003713
3714void dispc_write_irqenable(u32 mask)
3715{
3716 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3717
3718 /* clear the irqstatus for newly enabled irqs */
3719 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3720
3721 dispc_write_reg(DISPC_IRQENABLE, mask);
3722}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003723EXPORT_SYMBOL(dispc_write_irqenable);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003724
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003725void dispc_enable_sidle(void)
3726{
3727 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3728}
3729
3730void dispc_disable_sidle(void)
3731{
3732 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3733}
3734
3735static void _omap_dispc_initial_config(void)
3736{
3737 u32 l;
3738
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003739 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3740 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3741 l = dispc_read_reg(DISPC_DIVISOR);
3742 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3743 l = FLD_MOD(l, 1, 0, 0);
3744 l = FLD_MOD(l, 1, 23, 16);
3745 dispc_write_reg(DISPC_DIVISOR, l);
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003746
3747 dispc.core_clk_rate = dispc_fclk_rate();
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003748 }
3749
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003750 /* FUNCGATED */
Archit Taneja6ced40b2010-12-02 11:27:13 +00003751 if (dss_has_feature(FEAT_FUNCGATED))
3752 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003753
Archit Taneja6e5264b2012-09-11 12:04:47 +05303754 dispc_setup_color_conv_coef();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003755
3756 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3757
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003758 dispc_init_fifos();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003759
3760 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05303761
3762 dispc_ovl_enable_zorder_planes();
Archit Tanejad0df9a22013-03-26 19:15:25 +05303763
3764 if (dispc.feat->mstandby_workaround)
3765 REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0);
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00003766
3767 if (dss_has_feature(FEAT_MFLAG))
3768 dispc_init_mflag();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003769}
3770
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303771static const struct dispc_features omap24xx_dispc_feats __initconst = {
3772 .sw_start = 5,
3773 .fp_start = 15,
3774 .bp_start = 27,
3775 .sw_max = 64,
3776 .vp_max = 255,
3777 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303778 .mgr_width_start = 10,
3779 .mgr_height_start = 26,
3780 .mgr_width_max = 2048,
3781 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303782 .max_lcd_pclk = 66500000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303783 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3784 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003785 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003786 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303787 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003788 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303789};
3790
3791static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
3792 .sw_start = 5,
3793 .fp_start = 15,
3794 .bp_start = 27,
3795 .sw_max = 64,
3796 .vp_max = 255,
3797 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303798 .mgr_width_start = 10,
3799 .mgr_height_start = 26,
3800 .mgr_width_max = 2048,
3801 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303802 .max_lcd_pclk = 173000000,
3803 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303804 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3805 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003806 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003807 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303808 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003809 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303810};
3811
3812static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
3813 .sw_start = 7,
3814 .fp_start = 19,
3815 .bp_start = 31,
3816 .sw_max = 256,
3817 .vp_max = 4095,
3818 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303819 .mgr_width_start = 10,
3820 .mgr_height_start = 26,
3821 .mgr_width_max = 2048,
3822 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303823 .max_lcd_pclk = 173000000,
3824 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303825 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3826 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003827 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003828 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303829 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003830 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303831};
3832
3833static const struct dispc_features omap44xx_dispc_feats __initconst = {
3834 .sw_start = 7,
3835 .fp_start = 19,
3836 .bp_start = 31,
3837 .sw_max = 256,
3838 .vp_max = 4095,
3839 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303840 .mgr_width_start = 10,
3841 .mgr_height_start = 26,
3842 .mgr_width_max = 2048,
3843 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303844 .max_lcd_pclk = 170000000,
3845 .max_tv_pclk = 185625000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303846 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3847 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003848 .num_fifos = 5,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03003849 .gfx_fifo_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303850 .set_max_preload = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303851};
3852
Archit Taneja264236f2012-11-14 13:50:16 +05303853static const struct dispc_features omap54xx_dispc_feats __initconst = {
3854 .sw_start = 7,
3855 .fp_start = 19,
3856 .bp_start = 31,
3857 .sw_max = 256,
3858 .vp_max = 4095,
3859 .hp_max = 4096,
3860 .mgr_width_start = 11,
3861 .mgr_height_start = 27,
3862 .mgr_width_max = 4096,
3863 .mgr_height_max = 4096,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303864 .max_lcd_pclk = 170000000,
3865 .max_tv_pclk = 186000000,
Archit Taneja264236f2012-11-14 13:50:16 +05303866 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3867 .calc_core_clk = calc_core_clk_44xx,
3868 .num_fifos = 5,
3869 .gfx_fifo_workaround = true,
Archit Tanejad0df9a22013-03-26 19:15:25 +05303870 .mstandby_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303871 .set_max_preload = true,
Archit Taneja264236f2012-11-14 13:50:16 +05303872};
3873
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003874static int __init dispc_init_features(struct platform_device *pdev)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303875{
3876 const struct dispc_features *src;
3877 struct dispc_features *dst;
3878
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003879 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303880 if (!dst) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003881 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303882 return -ENOMEM;
3883 }
3884
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +03003885 switch (omapdss_get_version()) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003886 case OMAPDSS_VER_OMAP24xx:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303887 src = &omap24xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003888 break;
3889
3890 case OMAPDSS_VER_OMAP34xx_ES1:
3891 src = &omap34xx_rev1_0_dispc_feats;
3892 break;
3893
3894 case OMAPDSS_VER_OMAP34xx_ES3:
3895 case OMAPDSS_VER_OMAP3630:
3896 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +05303897 case OMAPDSS_VER_AM43xx:
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003898 src = &omap34xx_rev3_0_dispc_feats;
3899 break;
3900
3901 case OMAPDSS_VER_OMAP4430_ES1:
3902 case OMAPDSS_VER_OMAP4430_ES2:
3903 case OMAPDSS_VER_OMAP4:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303904 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003905 break;
3906
3907 case OMAPDSS_VER_OMAP5:
Tomi Valkeinen93550922014-12-31 11:25:48 +02003908 case OMAPDSS_VER_DRA7xx:
Archit Taneja264236f2012-11-14 13:50:16 +05303909 src = &omap54xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003910 break;
3911
3912 default:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303913 return -ENODEV;
3914 }
3915
3916 memcpy(dst, src, sizeof(*dst));
3917 dispc.feat = dst;
3918
3919 return 0;
3920}
3921
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003922static irqreturn_t dispc_irq_handler(int irq, void *arg)
3923{
3924 if (!dispc.is_enabled)
3925 return IRQ_NONE;
3926
3927 return dispc.user_handler(irq, dispc.user_data);
3928}
3929
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003930int dispc_request_irq(irq_handler_t handler, void *dev_id)
3931{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003932 int r;
3933
3934 if (dispc.user_handler != NULL)
3935 return -EBUSY;
3936
3937 dispc.user_handler = handler;
3938 dispc.user_data = dev_id;
3939
3940 /* ensure the dispc_irq_handler sees the values above */
3941 smp_wmb();
3942
3943 r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler,
3944 IRQF_SHARED, "OMAP DISPC", &dispc);
3945 if (r) {
3946 dispc.user_handler = NULL;
3947 dispc.user_data = NULL;
3948 }
3949
3950 return r;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003951}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003952EXPORT_SYMBOL(dispc_request_irq);
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003953
3954void dispc_free_irq(void *dev_id)
3955{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003956 devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc);
3957
3958 dispc.user_handler = NULL;
3959 dispc.user_data = NULL;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003960}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003961EXPORT_SYMBOL(dispc_free_irq);
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003962
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003963/* DISPC HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003964static int __init omap_dispchw_probe(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003965{
3966 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00003967 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003968 struct resource *dispc_mem;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003969 struct device_node *np = pdev->dev.of_node;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003970
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003971 dispc.pdev = pdev;
3972
Tomi Valkeinend49cd152014-11-10 12:23:00 +02003973 spin_lock_init(&dispc.control_lock);
3974
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003975 r = dispc_init_features(dispc.pdev);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303976 if (r)
3977 return r;
3978
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003979 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3980 if (!dispc_mem) {
3981 DSSERR("can't get IORESOURCE_MEM DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003982 return -EINVAL;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003983 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003984
Julia Lawall6e2a14d2012-01-24 14:00:45 +01003985 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3986 resource_size(dispc_mem));
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003987 if (!dispc.base) {
3988 DSSERR("can't ioremap DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003989 return -ENOMEM;
archit tanejaaffe3602011-02-23 08:41:03 +00003990 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003991
archit tanejaaffe3602011-02-23 08:41:03 +00003992 dispc.irq = platform_get_irq(dispc.pdev, 0);
3993 if (dispc.irq < 0) {
3994 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003995 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00003996 }
3997
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003998 if (np && of_property_read_bool(np, "syscon-pol")) {
3999 dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
4000 if (IS_ERR(dispc.syscon_pol)) {
4001 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
4002 return PTR_ERR(dispc.syscon_pol);
4003 }
4004
4005 if (of_property_read_u32_index(np, "syscon-pol", 1,
4006 &dispc.syscon_pol_offset)) {
4007 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
4008 return -EINVAL;
4009 }
4010 }
4011
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004012 pm_runtime_enable(&pdev->dev);
4013
4014 r = dispc_runtime_get();
4015 if (r)
4016 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004017
4018 _omap_dispc_initial_config();
4019
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004020 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00004021 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004022 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4023
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004024 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004025
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03004026 dss_init_overlay_managers();
4027
Tomi Valkeinene40402c2012-03-02 18:01:07 +02004028 dss_debugfs_create_file("dispc", dispc_dump_regs);
4029
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004030 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004031
4032err_runtime_get:
4033 pm_runtime_disable(&pdev->dev);
archit tanejaaffe3602011-02-23 08:41:03 +00004034 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004035}
4036
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004037static int __exit omap_dispchw_remove(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004038{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004039 pm_runtime_disable(&pdev->dev);
4040
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03004041 dss_uninit_overlay_managers();
4042
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004043 return 0;
4044}
4045
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004046static int dispc_runtime_suspend(struct device *dev)
4047{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004048 dispc.is_enabled = false;
4049 /* ensure the dispc_irq_handler sees the is_enabled value */
4050 smp_wmb();
4051 /* wait for current handler to finish before turning the DISPC off */
4052 synchronize_irq(dispc.irq);
4053
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004054 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004055
4056 return 0;
4057}
4058
4059static int dispc_runtime_resume(struct device *dev)
4060{
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004061 /*
4062 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4063 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4064 * _omap_dispc_initial_config(). We can thus use it to detect if
4065 * we have lost register context.
4066 */
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004067 if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
4068 _omap_dispc_initial_config();
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004069
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004070 dispc_restore_context();
4071 }
Tomi Valkeinenbe07dcd72013-11-21 16:01:40 +02004072
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004073 dispc.is_enabled = true;
4074 /* ensure the dispc_irq_handler sees the is_enabled value */
4075 smp_wmb();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004076
4077 return 0;
4078}
4079
4080static const struct dev_pm_ops dispc_pm_ops = {
4081 .runtime_suspend = dispc_runtime_suspend,
4082 .runtime_resume = dispc_runtime_resume,
4083};
4084
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004085static const struct of_device_id dispc_of_match[] = {
4086 { .compatible = "ti,omap2-dispc", },
4087 { .compatible = "ti,omap3-dispc", },
4088 { .compatible = "ti,omap4-dispc", },
Tomi Valkeinen2e7e6b62014-04-16 13:16:43 +03004089 { .compatible = "ti,omap5-dispc", },
Tomi Valkeinen93550922014-12-31 11:25:48 +02004090 { .compatible = "ti,dra7-dispc", },
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004091 {},
4092};
4093
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004094static struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004095 .remove = __exit_p(omap_dispchw_remove),
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004096 .driver = {
4097 .name = "omapdss_dispc",
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004098 .pm = &dispc_pm_ops,
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004099 .of_match_table = dispc_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +03004100 .suppress_bind_attrs = true,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004101 },
4102};
4103
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004104int __init dispc_init_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004105{
Tomi Valkeinen11436e12012-03-07 12:53:18 +02004106 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004107}
4108
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004109void __exit dispc_uninit_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004110{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02004111 platform_driver_unregister(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004112}