blob: ced6050666ccff35ae0df06e4ee5f1f1afb3969d [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 Valkeinen736e60d2015-06-04 15:22:23 +030042#include <linux/component.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020043
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030044#include <video/omapdss.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020045
46#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053047#include "dss_features.h"
Archit Taneja9b372c22011-05-06 11:45:49 +053048#include "dispc.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020049
50/* DISPC */
Sumit Semwal8613b002010-12-02 11:27:09 +000051#define DISPC_SZ_REGS SZ_4K
Tomi Valkeinen80c39712009-11-12 11:41:42 +020052
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030053enum omap_burst_size {
54 BURST_SIZE_X2 = 0,
55 BURST_SIZE_X4 = 1,
56 BURST_SIZE_X8 = 2,
57};
58
Tomi Valkeinen80c39712009-11-12 11:41:42 +020059#define REG_GET(idx, start, end) \
60 FLD_GET(dispc_read_reg(idx), start, end)
61
62#define REG_FLD_MOD(idx, val, start, end) \
63 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
64
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053065struct dispc_features {
66 u8 sw_start;
67 u8 fp_start;
68 u8 bp_start;
69 u16 sw_max;
70 u16 vp_max;
71 u16 hp_max;
Archit Taneja33b89922012-11-14 13:50:15 +053072 u8 mgr_width_start;
73 u8 mgr_height_start;
74 u16 mgr_width_max;
75 u16 mgr_height_max;
Archit Tanejaca5ca692013-03-26 19:15:22 +053076 unsigned long max_lcd_pclk;
77 unsigned long max_tv_pclk;
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +030078 int (*calc_scaling) (unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053079 const struct omap_video_timings *mgr_timings,
80 u16 width, u16 height, u16 out_width, u16 out_height,
81 enum omap_color_mode color_mode, bool *five_taps,
82 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +053083 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
Tomi Valkeinen8702ee52012-10-19 15:36:11 +030084 unsigned long (*calc_core_clk) (unsigned long pclk,
Archit Taneja8ba85302012-09-26 17:00:37 +053085 u16 width, u16 height, u16 out_width, u16 out_height,
86 bool mem_to_mem);
Tomi Valkeinen42a69612012-08-22 16:56:57 +030087 u8 num_fifos;
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +030088
89 /* swap GFX & WB fifos */
90 bool gfx_fifo_workaround:1;
Tomi Valkeinencffa9472012-11-08 10:01:33 +020091
92 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
93 bool no_framedone_tv:1;
Archit Tanejad0df9a22013-03-26 19:15:25 +053094
95 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
96 bool mstandby_workaround:1;
Archit Taneja8bc65552013-12-17 16:40:21 +053097
98 bool set_max_preload:1;
Tomi Valkeinenf2aee312015-04-10 12:48:34 +030099
100 /* PIXEL_INC is not added to the last pixel of a line */
101 bool last_pixel_inc_missing:1;
Tomi Valkeinene5f80912015-10-21 13:08:59 +0300102
103 /* POL_FREQ has ALIGN bit */
104 bool supports_sync_align:1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530105};
106
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300107#define DISPC_MAX_NR_FIFOS 5
108
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200109static struct {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +0000110 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200111 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300112
archit tanejaaffe3602011-02-23 08:41:03 +0000113 int irq;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300114 irq_handler_t user_handler;
115 void *user_data;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200116
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200117 unsigned long core_clk_rate;
Tomi Valkeinen5391e872013-05-16 10:44:13 +0300118 unsigned long tv_pclk_rate;
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200119
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300120 u32 fifo_size[DISPC_MAX_NR_FIFOS];
121 /* maps which plane is using a fifo. fifo-id -> plane-id */
122 int fifo_assignment[DISPC_MAX_NR_FIFOS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200123
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300124 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200125 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200126
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530127 const struct dispc_features *feat;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300128
129 bool is_enabled;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +0000130
131 struct regmap *syscon_pol;
132 u32 syscon_pol_offset;
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200133
134 /* DISPC_CONTROL & DISPC_CONFIG lock*/
135 spinlock_t control_lock;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200136} dispc;
137
Amber Jain0d66cbb2011-05-19 19:47:54 +0530138enum omap_color_component {
139 /* used for all color formats for OMAP3 and earlier
140 * and for RGB and Y color component on OMAP4
141 */
142 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
143 /* used for UV component for
144 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
145 * color formats on OMAP4
146 */
147 DISPC_COLOR_COMPONENT_UV = 1 << 1,
148};
149
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530150enum mgr_reg_fields {
151 DISPC_MGR_FLD_ENABLE,
152 DISPC_MGR_FLD_STNTFT,
153 DISPC_MGR_FLD_GO,
154 DISPC_MGR_FLD_TFTDATALINES,
155 DISPC_MGR_FLD_STALLMODE,
156 DISPC_MGR_FLD_TCKENABLE,
157 DISPC_MGR_FLD_TCKSELECTION,
158 DISPC_MGR_FLD_CPR,
159 DISPC_MGR_FLD_FIFOHANDCHECK,
160 /* used to maintain a count of the above fields */
161 DISPC_MGR_FLD_NUM,
162};
163
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300164struct dispc_reg_field {
165 u16 reg;
166 u8 high;
167 u8 low;
168};
169
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530170static const struct {
171 const char *name;
172 u32 vsync_irq;
173 u32 framedone_irq;
174 u32 sync_lost_irq;
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300175 struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530176} mgr_desc[] = {
177 [OMAP_DSS_CHANNEL_LCD] = {
178 .name = "LCD",
179 .vsync_irq = DISPC_IRQ_VSYNC,
180 .framedone_irq = DISPC_IRQ_FRAMEDONE,
181 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
182 .reg_desc = {
183 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
184 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
185 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
186 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
187 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
188 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
189 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
190 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
191 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
192 },
193 },
194 [OMAP_DSS_CHANNEL_DIGIT] = {
195 .name = "DIGIT",
196 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200197 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530198 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
199 .reg_desc = {
200 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
201 [DISPC_MGR_FLD_STNTFT] = { },
202 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
203 [DISPC_MGR_FLD_TFTDATALINES] = { },
204 [DISPC_MGR_FLD_STALLMODE] = { },
205 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
206 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
207 [DISPC_MGR_FLD_CPR] = { },
208 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
209 },
210 },
211 [OMAP_DSS_CHANNEL_LCD2] = {
212 .name = "LCD2",
213 .vsync_irq = DISPC_IRQ_VSYNC2,
214 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
215 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
216 .reg_desc = {
217 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
218 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
219 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
220 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
221 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
222 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
223 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
224 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
225 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
226 },
227 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530228 [OMAP_DSS_CHANNEL_LCD3] = {
229 .name = "LCD3",
230 .vsync_irq = DISPC_IRQ_VSYNC3,
231 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
232 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
233 .reg_desc = {
234 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
235 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
236 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
237 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
238 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
239 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
240 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
241 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
242 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
243 },
244 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530245};
246
Archit Taneja6e5264b2012-09-11 12:04:47 +0530247struct color_conv_coef {
248 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
249 int full_range;
250};
251
Archit Taneja3e8a6ff2012-09-26 16:58:52 +0530252static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
253static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200254
Archit Taneja55978cc2011-05-06 11:45:51 +0530255static inline void dispc_write_reg(const u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200256{
Archit Taneja55978cc2011-05-06 11:45:51 +0530257 __raw_writel(val, dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200258}
259
Archit Taneja55978cc2011-05-06 11:45:51 +0530260static inline u32 dispc_read_reg(const u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200261{
Archit Taneja55978cc2011-05-06 11:45:51 +0530262 return __raw_readl(dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200263}
264
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530265static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
266{
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300267 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530268 return REG_GET(rfld.reg, rfld.high, rfld.low);
269}
270
271static void mgr_fld_write(enum omap_channel channel,
272 enum mgr_reg_fields regfld, int val) {
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300273 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200274 const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG;
275 unsigned long flags;
276
277 if (need_lock)
278 spin_lock_irqsave(&dispc.control_lock, flags);
279
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530280 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200281
282 if (need_lock)
283 spin_unlock_irqrestore(&dispc.control_lock, flags);
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530284}
285
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200286#define SR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530287 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200288#define RR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530289 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200290
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300291static void dispc_save_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200292{
Archit Tanejac6104b82011-08-05 19:06:02 +0530293 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200294
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300295 DSSDBG("dispc_save_context\n");
296
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200297 SR(IRQENABLE);
298 SR(CONTROL);
299 SR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200300 SR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530301 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
302 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300303 SR(GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000304 if (dss_has_feature(FEAT_MGR_LCD2)) {
305 SR(CONTROL2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000306 SR(CONFIG2);
307 }
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530308 if (dss_has_feature(FEAT_MGR_LCD3)) {
309 SR(CONTROL3);
310 SR(CONFIG3);
311 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200312
Archit Tanejac6104b82011-08-05 19:06:02 +0530313 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
314 SR(DEFAULT_COLOR(i));
315 SR(TRANS_COLOR(i));
316 SR(SIZE_MGR(i));
317 if (i == OMAP_DSS_CHANNEL_DIGIT)
318 continue;
319 SR(TIMING_H(i));
320 SR(TIMING_V(i));
321 SR(POL_FREQ(i));
322 SR(DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200323
Archit Tanejac6104b82011-08-05 19:06:02 +0530324 SR(DATA_CYCLE1(i));
325 SR(DATA_CYCLE2(i));
326 SR(DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200327
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300328 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530329 SR(CPR_COEF_R(i));
330 SR(CPR_COEF_G(i));
331 SR(CPR_COEF_B(i));
332 }
333 }
334
335 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
336 SR(OVL_BA0(i));
337 SR(OVL_BA1(i));
338 SR(OVL_POSITION(i));
339 SR(OVL_SIZE(i));
340 SR(OVL_ATTRIBUTES(i));
341 SR(OVL_FIFO_THRESHOLD(i));
342 SR(OVL_ROW_INC(i));
343 SR(OVL_PIXEL_INC(i));
344 if (dss_has_feature(FEAT_PRELOAD))
345 SR(OVL_PRELOAD(i));
346 if (i == OMAP_DSS_GFX) {
347 SR(OVL_WINDOW_SKIP(i));
348 SR(OVL_TABLE_BA(i));
349 continue;
350 }
351 SR(OVL_FIR(i));
352 SR(OVL_PICTURE_SIZE(i));
353 SR(OVL_ACCU0(i));
354 SR(OVL_ACCU1(i));
355
356 for (j = 0; j < 8; j++)
357 SR(OVL_FIR_COEF_H(i, j));
358
359 for (j = 0; j < 8; j++)
360 SR(OVL_FIR_COEF_HV(i, j));
361
362 for (j = 0; j < 5; j++)
363 SR(OVL_CONV_COEF(i, j));
364
365 if (dss_has_feature(FEAT_FIR_COEF_V)) {
366 for (j = 0; j < 8; j++)
367 SR(OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300368 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000369
Archit Tanejac6104b82011-08-05 19:06:02 +0530370 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
371 SR(OVL_BA0_UV(i));
372 SR(OVL_BA1_UV(i));
373 SR(OVL_FIR2(i));
374 SR(OVL_ACCU2_0(i));
375 SR(OVL_ACCU2_1(i));
376
377 for (j = 0; j < 8; j++)
378 SR(OVL_FIR_COEF_H2(i, j));
379
380 for (j = 0; j < 8; j++)
381 SR(OVL_FIR_COEF_HV2(i, j));
382
383 for (j = 0; j < 8; j++)
384 SR(OVL_FIR_COEF_V2(i, j));
385 }
386 if (dss_has_feature(FEAT_ATTR2))
387 SR(OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000388 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200389
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600390 if (dss_has_feature(FEAT_CORE_CLK_DIV))
391 SR(DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300392
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300393 dispc.ctx_valid = true;
394
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200395 DSSDBG("context saved\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200396}
397
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300398static void dispc_restore_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200399{
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200400 int i, j;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300401
402 DSSDBG("dispc_restore_context\n");
403
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300404 if (!dispc.ctx_valid)
405 return;
406
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200407 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200408 /*RR(CONTROL);*/
409 RR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200410 RR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530411 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
412 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300413 RR(GLOBAL_ALPHA);
Archit Tanejac6104b82011-08-05 19:06:02 +0530414 if (dss_has_feature(FEAT_MGR_LCD2))
Sumit Semwal2a205f32010-12-02 11:27:12 +0000415 RR(CONFIG2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530416 if (dss_has_feature(FEAT_MGR_LCD3))
417 RR(CONFIG3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200418
Archit Tanejac6104b82011-08-05 19:06:02 +0530419 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
420 RR(DEFAULT_COLOR(i));
421 RR(TRANS_COLOR(i));
422 RR(SIZE_MGR(i));
423 if (i == OMAP_DSS_CHANNEL_DIGIT)
424 continue;
425 RR(TIMING_H(i));
426 RR(TIMING_V(i));
427 RR(POL_FREQ(i));
428 RR(DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530429
Archit Tanejac6104b82011-08-05 19:06:02 +0530430 RR(DATA_CYCLE1(i));
431 RR(DATA_CYCLE2(i));
432 RR(DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000433
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300434 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530435 RR(CPR_COEF_R(i));
436 RR(CPR_COEF_G(i));
437 RR(CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300438 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000439 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200440
Archit Tanejac6104b82011-08-05 19:06:02 +0530441 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
442 RR(OVL_BA0(i));
443 RR(OVL_BA1(i));
444 RR(OVL_POSITION(i));
445 RR(OVL_SIZE(i));
446 RR(OVL_ATTRIBUTES(i));
447 RR(OVL_FIFO_THRESHOLD(i));
448 RR(OVL_ROW_INC(i));
449 RR(OVL_PIXEL_INC(i));
450 if (dss_has_feature(FEAT_PRELOAD))
451 RR(OVL_PRELOAD(i));
452 if (i == OMAP_DSS_GFX) {
453 RR(OVL_WINDOW_SKIP(i));
454 RR(OVL_TABLE_BA(i));
455 continue;
456 }
457 RR(OVL_FIR(i));
458 RR(OVL_PICTURE_SIZE(i));
459 RR(OVL_ACCU0(i));
460 RR(OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200461
Archit Tanejac6104b82011-08-05 19:06:02 +0530462 for (j = 0; j < 8; j++)
463 RR(OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200464
Archit Tanejac6104b82011-08-05 19:06:02 +0530465 for (j = 0; j < 8; j++)
466 RR(OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200467
Archit Tanejac6104b82011-08-05 19:06:02 +0530468 for (j = 0; j < 5; j++)
469 RR(OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200470
Archit Tanejac6104b82011-08-05 19:06:02 +0530471 if (dss_has_feature(FEAT_FIR_COEF_V)) {
472 for (j = 0; j < 8; j++)
473 RR(OVL_FIR_COEF_V(i, j));
474 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200475
Archit Tanejac6104b82011-08-05 19:06:02 +0530476 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
477 RR(OVL_BA0_UV(i));
478 RR(OVL_BA1_UV(i));
479 RR(OVL_FIR2(i));
480 RR(OVL_ACCU2_0(i));
481 RR(OVL_ACCU2_1(i));
482
483 for (j = 0; j < 8; j++)
484 RR(OVL_FIR_COEF_H2(i, j));
485
486 for (j = 0; j < 8; j++)
487 RR(OVL_FIR_COEF_HV2(i, j));
488
489 for (j = 0; j < 8; j++)
490 RR(OVL_FIR_COEF_V2(i, j));
491 }
492 if (dss_has_feature(FEAT_ATTR2))
493 RR(OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300494 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200495
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600496 if (dss_has_feature(FEAT_CORE_CLK_DIV))
497 RR(DIVISOR);
498
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200499 /* enable last, because LCD & DIGIT enable are here */
500 RR(CONTROL);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000501 if (dss_has_feature(FEAT_MGR_LCD2))
502 RR(CONTROL2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530503 if (dss_has_feature(FEAT_MGR_LCD3))
504 RR(CONTROL3);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200505 /* clear spurious SYNC_LOST_DIGIT interrupts */
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +0300506 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200507
508 /*
509 * enable last so IRQs won't trigger before
510 * the context is fully restored
511 */
512 RR(IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300513
514 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200515}
516
517#undef SR
518#undef RR
519
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300520int dispc_runtime_get(void)
521{
522 int r;
523
524 DSSDBG("dispc_runtime_get\n");
525
526 r = pm_runtime_get_sync(&dispc.pdev->dev);
527 WARN_ON(r < 0);
528 return r < 0 ? r : 0;
529}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200530EXPORT_SYMBOL(dispc_runtime_get);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300531
532void dispc_runtime_put(void)
533{
534 int r;
535
536 DSSDBG("dispc_runtime_put\n");
537
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200538 r = pm_runtime_put_sync(&dispc.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300539 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300540}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200541EXPORT_SYMBOL(dispc_runtime_put);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300542
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200543u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
544{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530545 return mgr_desc[channel].vsync_irq;
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200546}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200547EXPORT_SYMBOL(dispc_mgr_get_vsync_irq);
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200548
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200549u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
550{
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200551 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv)
552 return 0;
553
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530554 return mgr_desc[channel].framedone_irq;
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200555}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200556EXPORT_SYMBOL(dispc_mgr_get_framedone_irq);
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200557
Tomi Valkeinencb699202012-10-17 10:38:52 +0300558u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
559{
560 return mgr_desc[channel].sync_lost_irq;
561}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200562EXPORT_SYMBOL(dispc_mgr_get_sync_lost_irq);
Tomi Valkeinencb699202012-10-17 10:38:52 +0300563
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530564u32 dispc_wb_get_framedone_irq(void)
565{
566 return DISPC_IRQ_FRAMEDONEWB;
567}
568
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300569bool dispc_mgr_go_busy(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200570{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530571 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200572}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200573EXPORT_SYMBOL(dispc_mgr_go_busy);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200574
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300575void dispc_mgr_go(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200576{
Tomi Valkeinen3c91ee82012-10-19 15:06:07 +0300577 WARN_ON(dispc_mgr_is_enabled(channel) == false);
578 WARN_ON(dispc_mgr_go_busy(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200579
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530580 DSSDBG("GO %s\n", mgr_desc[channel].name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200581
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530582 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200583}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200584EXPORT_SYMBOL(dispc_mgr_go);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200585
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530586bool dispc_wb_go_busy(void)
587{
588 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
589}
590
591void dispc_wb_go(void)
592{
593 enum omap_plane plane = OMAP_DSS_WB;
594 bool enable, go;
595
596 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
597
598 if (!enable)
599 return;
600
601 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
602 if (go) {
603 DSSERR("GO bit not down for WB\n");
604 return;
605 }
606
607 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
608}
609
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300610static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200611{
Archit Taneja9b372c22011-05-06 11:45:49 +0530612 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200613}
614
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300615static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200616{
Archit Taneja9b372c22011-05-06 11:45:49 +0530617 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200618}
619
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300620static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200621{
Archit Taneja9b372c22011-05-06 11:45:49 +0530622 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200623}
624
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300625static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530626{
627 BUG_ON(plane == OMAP_DSS_GFX);
628
629 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
630}
631
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300632static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
633 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530634{
635 BUG_ON(plane == OMAP_DSS_GFX);
636
637 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
638}
639
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300640static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530641{
642 BUG_ON(plane == OMAP_DSS_GFX);
643
644 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
645}
646
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530647static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
648 int fir_vinc, int five_taps,
649 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200650{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530651 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200652 int i;
653
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530654 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
655 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200656
657 for (i = 0; i < 8; i++) {
658 u32 h, hv;
659
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530660 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
661 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
662 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
663 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
664 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
665 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
666 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
667 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200668
Amber Jain0d66cbb2011-05-19 19:47:54 +0530669 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300670 dispc_ovl_write_firh_reg(plane, i, h);
671 dispc_ovl_write_firhv_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530672 } else {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300673 dispc_ovl_write_firh2_reg(plane, i, h);
674 dispc_ovl_write_firhv2_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530675 }
676
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200677 }
678
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200679 if (five_taps) {
680 for (i = 0; i < 8; i++) {
681 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530682 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
683 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530684 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300685 dispc_ovl_write_firv_reg(plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530686 else
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300687 dispc_ovl_write_firv2_reg(plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200688 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200689 }
690}
691
Archit Taneja6e5264b2012-09-11 12:04:47 +0530692
693static void dispc_ovl_write_color_conv_coef(enum omap_plane plane,
694 const struct color_conv_coef *ct)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200695{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200696#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
697
Archit Taneja6e5264b2012-09-11 12:04:47 +0530698 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
699 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
700 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
701 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
702 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200703
Archit Taneja6e5264b2012-09-11 12:04:47 +0530704 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200705
706#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200707}
708
Archit Taneja6e5264b2012-09-11 12:04:47 +0530709static void dispc_setup_color_conv_coef(void)
710{
711 int i;
712 int num_ovl = dss_feat_get_num_ovls();
713 int num_wb = dss_feat_get_num_wbs();
714 const struct color_conv_coef ctbl_bt601_5_ovl = {
715 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
716 };
717 const struct color_conv_coef ctbl_bt601_5_wb = {
718 66, 112, -38, 129, -94, -74, 25, -18, 112, 0,
719 };
720
721 for (i = 1; i < num_ovl; i++)
722 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
723
724 for (; i < num_wb; i++)
725 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_wb);
726}
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200727
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300728static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200729{
Archit Taneja9b372c22011-05-06 11:45:49 +0530730 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200731}
732
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300733static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200734{
Archit Taneja9b372c22011-05-06 11:45:49 +0530735 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200736}
737
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300738static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530739{
740 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
741}
742
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300743static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530744{
745 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
746}
747
Archit Tanejad79db852012-09-22 12:30:17 +0530748static void dispc_ovl_set_pos(enum omap_plane plane,
749 enum omap_overlay_caps caps, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200750{
Archit Tanejad79db852012-09-22 12:30:17 +0530751 u32 val;
752
753 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
754 return;
755
756 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530757
758 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200759}
760
Archit Taneja78b687f2012-09-21 14:51:49 +0530761static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
762 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200763{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200764 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530765
Archit Taneja36d87d92012-07-28 22:59:03 +0530766 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
Archit Taneja9b372c22011-05-06 11:45:49 +0530767 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
768 else
769 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200770}
771
Archit Taneja78b687f2012-09-21 14:51:49 +0530772static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
773 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200774{
775 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200776
777 BUG_ON(plane == OMAP_DSS_GFX);
778
779 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530780
Archit Taneja36d87d92012-07-28 22:59:03 +0530781 if (plane == OMAP_DSS_WB)
782 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
783 else
784 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200785}
786
Archit Taneja5b54ed32012-09-26 16:55:27 +0530787static void dispc_ovl_set_zorder(enum omap_plane plane,
788 enum omap_overlay_caps caps, u8 zorder)
Archit Taneja54128702011-09-08 11:29:17 +0530789{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530790 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
Archit Taneja54128702011-09-08 11:29:17 +0530791 return;
792
793 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
794}
795
796static void dispc_ovl_enable_zorder_planes(void)
797{
798 int i;
799
800 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
801 return;
802
803 for (i = 0; i < dss_feat_get_num_ovls(); i++)
804 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
805}
806
Archit Taneja5b54ed32012-09-26 16:55:27 +0530807static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
808 enum omap_overlay_caps caps, bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100809{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530810 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100811 return;
812
Archit Taneja9b372c22011-05-06 11:45:49 +0530813 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100814}
815
Archit Taneja5b54ed32012-09-26 16:55:27 +0530816static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
817 enum omap_overlay_caps caps, u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200818{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530819 static const unsigned shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300820 int shift;
821
Archit Taneja5b54ed32012-09-26 16:55:27 +0530822 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100823 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530824
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300825 shift = shifts[plane];
826 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200827}
828
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300829static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200830{
Archit Taneja9b372c22011-05-06 11:45:49 +0530831 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200832}
833
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300834static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200835{
Archit Taneja9b372c22011-05-06 11:45:49 +0530836 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200837}
838
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300839static void dispc_ovl_set_color_mode(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200840 enum omap_color_mode color_mode)
841{
842 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +0530843 if (plane != OMAP_DSS_GFX) {
844 switch (color_mode) {
845 case OMAP_DSS_COLOR_NV12:
846 m = 0x0; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530847 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530848 m = 0x1; break;
849 case OMAP_DSS_COLOR_RGBA16:
850 m = 0x2; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530851 case OMAP_DSS_COLOR_RGB12U:
Amber Jainf20e4222011-05-19 19:47:50 +0530852 m = 0x4; break;
853 case OMAP_DSS_COLOR_ARGB16:
854 m = 0x5; break;
855 case OMAP_DSS_COLOR_RGB16:
856 m = 0x6; break;
857 case OMAP_DSS_COLOR_ARGB16_1555:
858 m = 0x7; break;
859 case OMAP_DSS_COLOR_RGB24U:
860 m = 0x8; break;
861 case OMAP_DSS_COLOR_RGB24P:
862 m = 0x9; break;
863 case OMAP_DSS_COLOR_YUV2:
864 m = 0xa; break;
865 case OMAP_DSS_COLOR_UYVY:
866 m = 0xb; break;
867 case OMAP_DSS_COLOR_ARGB32:
868 m = 0xc; break;
869 case OMAP_DSS_COLOR_RGBA32:
870 m = 0xd; break;
871 case OMAP_DSS_COLOR_RGBX32:
872 m = 0xe; break;
873 case OMAP_DSS_COLOR_XRGB16_1555:
874 m = 0xf; break;
875 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300876 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530877 }
878 } else {
879 switch (color_mode) {
880 case OMAP_DSS_COLOR_CLUT1:
881 m = 0x0; break;
882 case OMAP_DSS_COLOR_CLUT2:
883 m = 0x1; break;
884 case OMAP_DSS_COLOR_CLUT4:
885 m = 0x2; break;
886 case OMAP_DSS_COLOR_CLUT8:
887 m = 0x3; break;
888 case OMAP_DSS_COLOR_RGB12U:
889 m = 0x4; break;
890 case OMAP_DSS_COLOR_ARGB16:
891 m = 0x5; break;
892 case OMAP_DSS_COLOR_RGB16:
893 m = 0x6; break;
894 case OMAP_DSS_COLOR_ARGB16_1555:
895 m = 0x7; break;
896 case OMAP_DSS_COLOR_RGB24U:
897 m = 0x8; break;
898 case OMAP_DSS_COLOR_RGB24P:
899 m = 0x9; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530900 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530901 m = 0xa; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530902 case OMAP_DSS_COLOR_RGBA16:
Amber Jainf20e4222011-05-19 19:47:50 +0530903 m = 0xb; break;
904 case OMAP_DSS_COLOR_ARGB32:
905 m = 0xc; break;
906 case OMAP_DSS_COLOR_RGBA32:
907 m = 0xd; break;
908 case OMAP_DSS_COLOR_RGBX32:
909 m = 0xe; break;
910 case OMAP_DSS_COLOR_XRGB16_1555:
911 m = 0xf; break;
912 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300913 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530914 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200915 }
916
Archit Taneja9b372c22011-05-06 11:45:49 +0530917 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200918}
919
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530920static void dispc_ovl_configure_burst_type(enum omap_plane plane,
921 enum omap_dss_rotation_type rotation_type)
922{
923 if (dss_has_feature(FEAT_BURST_2D) == 0)
924 return;
925
926 if (rotation_type == OMAP_DSS_ROT_TILER)
927 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
928 else
929 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
930}
931
Tomi Valkeinenf4279842011-10-28 15:26:26 +0300932void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200933{
934 int shift;
935 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000936 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200937
938 switch (plane) {
939 case OMAP_DSS_GFX:
940 shift = 8;
941 break;
942 case OMAP_DSS_VIDEO1:
943 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +0530944 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200945 shift = 16;
946 break;
947 default:
948 BUG();
949 return;
950 }
951
Archit Taneja9b372c22011-05-06 11:45:49 +0530952 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000953 if (dss_has_feature(FEAT_MGR_LCD2)) {
954 switch (channel) {
955 case OMAP_DSS_CHANNEL_LCD:
956 chan = 0;
957 chan2 = 0;
958 break;
959 case OMAP_DSS_CHANNEL_DIGIT:
960 chan = 1;
961 chan2 = 0;
962 break;
963 case OMAP_DSS_CHANNEL_LCD2:
964 chan = 0;
965 chan2 = 1;
966 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530967 case OMAP_DSS_CHANNEL_LCD3:
968 if (dss_has_feature(FEAT_MGR_LCD3)) {
969 chan = 0;
970 chan2 = 2;
971 } else {
972 BUG();
973 return;
974 }
975 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000976 default:
977 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300978 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000979 }
980
981 val = FLD_MOD(val, chan, shift, shift);
982 val = FLD_MOD(val, chan2, 31, 30);
983 } else {
984 val = FLD_MOD(val, channel, shift, shift);
985 }
Archit Taneja9b372c22011-05-06 11:45:49 +0530986 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200987}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200988EXPORT_SYMBOL(dispc_ovl_set_channel_out);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200989
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200990static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
991{
992 int shift;
993 u32 val;
994 enum omap_channel channel;
995
996 switch (plane) {
997 case OMAP_DSS_GFX:
998 shift = 8;
999 break;
1000 case OMAP_DSS_VIDEO1:
1001 case OMAP_DSS_VIDEO2:
1002 case OMAP_DSS_VIDEO3:
1003 shift = 16;
1004 break;
1005 default:
1006 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001007 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001008 }
1009
1010 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1011
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05301012 if (dss_has_feature(FEAT_MGR_LCD3)) {
1013 if (FLD_GET(val, 31, 30) == 0)
1014 channel = FLD_GET(val, shift, shift);
1015 else if (FLD_GET(val, 31, 30) == 1)
1016 channel = OMAP_DSS_CHANNEL_LCD2;
1017 else
1018 channel = OMAP_DSS_CHANNEL_LCD3;
1019 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001020 if (FLD_GET(val, 31, 30) == 0)
1021 channel = FLD_GET(val, shift, shift);
1022 else
1023 channel = OMAP_DSS_CHANNEL_LCD2;
1024 } else {
1025 channel = FLD_GET(val, shift, shift);
1026 }
1027
1028 return channel;
1029}
1030
Archit Tanejad9ac7732012-09-22 12:38:19 +05301031void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1032{
1033 enum omap_plane plane = OMAP_DSS_WB;
1034
1035 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1036}
1037
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001038static void dispc_ovl_set_burst_size(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001039 enum omap_burst_size burst_size)
1040{
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301041 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001042 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001043
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001044 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001045 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001046}
1047
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001048static void dispc_configure_burst_sizes(void)
1049{
1050 int i;
1051 const int burst_size = BURST_SIZE_X8;
1052
1053 /* Configure burst size always to maximum size */
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001054 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001055 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001056}
1057
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001058static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001059{
1060 unsigned unit = dss_feat_get_burst_size_unit();
1061 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1062 return unit * 8;
1063}
1064
Mythri P Kd3862612011-03-11 18:02:49 +05301065void dispc_enable_gamma_table(bool enable)
1066{
1067 /*
1068 * This is partially implemented to support only disabling of
1069 * the gamma table.
1070 */
1071 if (enable) {
1072 DSSWARN("Gamma table enabling for TV not yet supported");
1073 return;
1074 }
1075
1076 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1077}
1078
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001079static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001080{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301081 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001082 return;
1083
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301084 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001085}
1086
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001087static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02001088 const struct omap_dss_cpr_coefs *coefs)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001089{
1090 u32 coef_r, coef_g, coef_b;
1091
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301092 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001093 return;
1094
1095 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1096 FLD_VAL(coefs->rb, 9, 0);
1097 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1098 FLD_VAL(coefs->gb, 9, 0);
1099 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1100 FLD_VAL(coefs->bb, 9, 0);
1101
1102 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1103 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1104 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1105}
1106
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001107static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001108{
1109 u32 val;
1110
1111 BUG_ON(plane == OMAP_DSS_GFX);
1112
Archit Taneja9b372c22011-05-06 11:45:49 +05301113 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001114 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +05301115 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001116}
1117
Archit Tanejad79db852012-09-22 12:30:17 +05301118static void dispc_ovl_enable_replication(enum omap_plane plane,
1119 enum omap_overlay_caps caps, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001120{
Archit Tanejab8c095b2011-09-13 18:20:33 +05301121 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001122 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001123
Archit Tanejad79db852012-09-22 12:30:17 +05301124 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1125 return;
1126
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001127 shift = shifts[plane];
1128 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001129}
1130
Archit Taneja8f366162012-04-16 12:53:44 +05301131static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
Archit Tanejae5c09e02012-04-16 12:53:42 +05301132 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001133{
1134 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301135
Archit Taneja33b89922012-11-14 13:50:15 +05301136 val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1137 FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1138
Archit Taneja702d1442011-05-06 11:45:50 +05301139 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001140}
1141
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001142static void dispc_init_fifos(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001143{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001144 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001145 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301146 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001147 u32 unit;
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001148 int i;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001149
1150 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001151
Archit Tanejaa0acb552010-09-15 19:20:00 +05301152 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001153
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001154 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1155 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001156 size *= unit;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001157 dispc.fifo_size[fifo] = size;
1158
1159 /*
1160 * By default fifos are mapped directly to overlays, fifo 0 to
1161 * ovl 0, fifo 1 to ovl 1, etc.
1162 */
1163 dispc.fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001164 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001165
1166 /*
1167 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1168 * causes problems with certain use cases, like using the tiler in 2D
1169 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1170 * giving GFX plane a larger fifo. WB but should work fine with a
1171 * smaller fifo.
1172 */
1173 if (dispc.feat->gfx_fifo_workaround) {
1174 u32 v;
1175
1176 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1177
1178 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1179 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1180 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1181 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1182
1183 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1184
1185 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1186 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1187 }
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001188
1189 /*
1190 * Setup default fifo thresholds.
1191 */
1192 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1193 u32 low, high;
1194 const bool use_fifomerge = false;
1195 const bool manual_update = false;
1196
1197 dispc_ovl_compute_fifo_thresholds(i, &low, &high,
1198 use_fifomerge, manual_update);
1199
1200 dispc_ovl_set_fifo_threshold(i, low, high);
1201 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001202}
1203
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001204static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001205{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001206 int fifo;
1207 u32 size = 0;
1208
1209 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1210 if (dispc.fifo_assignment[fifo] == plane)
1211 size += dispc.fifo_size[fifo];
1212 }
1213
1214 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001215}
1216
Tomi Valkeinen6f04e1b2011-10-31 08:58:52 +02001217void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001218{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301219 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001220 u32 unit;
1221
1222 unit = dss_feat_get_buffer_size_unit();
1223
1224 WARN_ON(low % unit != 0);
1225 WARN_ON(high % unit != 0);
1226
1227 low /= unit;
1228 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301229
Archit Taneja9b372c22011-05-06 11:45:49 +05301230 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1231 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1232
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001233 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001234 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301235 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001236 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301237 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001238 hi_start, hi_end) * unit,
1239 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001240
Archit Taneja9b372c22011-05-06 11:45:49 +05301241 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301242 FLD_VAL(high, hi_start, hi_end) |
1243 FLD_VAL(low, lo_start, lo_end));
Archit Taneja8bc65552013-12-17 16:40:21 +05301244
1245 /*
1246 * configure the preload to the pipeline's high threhold, if HT it's too
1247 * large for the preload field, set the threshold to the maximum value
1248 * that can be held by the preload register
1249 */
1250 if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload &&
1251 plane != OMAP_DSS_WB)
1252 dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001253}
Tomi Valkeinen8ee5c842013-11-08 10:07:20 +02001254EXPORT_SYMBOL(dispc_ovl_set_fifo_threshold);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001255
1256void dispc_enable_fifomerge(bool enable)
1257{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001258 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1259 WARN_ON(enable);
1260 return;
1261 }
1262
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001263 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1264 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001265}
1266
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001267void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001268 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1269 bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001270{
1271 /*
1272 * All sizes are in bytes. Both the buffer and burst are made of
1273 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1274 */
1275
1276 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001277 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1278 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001279
1280 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001281 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001282
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001283 if (use_fifomerge) {
1284 total_fifo_size = 0;
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001285 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001286 total_fifo_size += dispc_ovl_get_fifo_size(i);
1287 } else {
1288 total_fifo_size = ovl_fifo_size;
1289 }
1290
1291 /*
1292 * We use the same low threshold for both fifomerge and non-fifomerge
1293 * cases, but for fifomerge we calculate the high threshold using the
1294 * combined fifo size
1295 */
1296
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001297 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001298 *fifo_low = ovl_fifo_size - burst_size * 2;
1299 *fifo_high = total_fifo_size - burst_size;
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301300 } else if (plane == OMAP_DSS_WB) {
1301 /*
1302 * Most optimal configuration for writeback is to push out data
1303 * to the interconnect the moment writeback pushes enough pixels
1304 * in the FIFO to form a burst
1305 */
1306 *fifo_low = 0;
1307 *fifo_high = burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001308 } else {
1309 *fifo_low = ovl_fifo_size - burst_size;
1310 *fifo_high = total_fifo_size - buf_unit;
1311 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001312}
Tomi Valkeinen8ee5c842013-11-08 10:07:20 +02001313EXPORT_SYMBOL(dispc_ovl_compute_fifo_thresholds);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001314
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001315static void dispc_ovl_set_mflag(enum omap_plane plane, bool enable)
1316{
1317 int bit;
1318
1319 if (plane == OMAP_DSS_GFX)
1320 bit = 14;
1321 else
1322 bit = 23;
1323
1324 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1325}
1326
1327static void dispc_ovl_set_mflag_threshold(enum omap_plane plane,
1328 int low, int high)
1329{
1330 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane),
1331 FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1332}
1333
1334static void dispc_init_mflag(void)
1335{
1336 int i;
1337
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001338 /*
1339 * HACK: NV12 color format and MFLAG seem to have problems working
1340 * together: using two displays, and having an NV12 overlay on one of
1341 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1342 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1343 * remove the errors, but there doesn't seem to be a clear logic on
1344 * which values work and which not.
1345 *
1346 * As a work-around, set force MFLAG to always on.
1347 */
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001348 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE,
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001349 (1 << 0) | /* MFLAG_CTRL = force always on */
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001350 (0 << 2)); /* MFLAG_START = disable */
1351
1352 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1353 u32 size = dispc_ovl_get_fifo_size(i);
1354 u32 unit = dss_feat_get_buffer_size_unit();
1355 u32 low, high;
1356
1357 dispc_ovl_set_mflag(i, true);
1358
1359 /*
1360 * Simulation team suggests below thesholds:
1361 * HT = fifosize * 5 / 8;
1362 * LT = fifosize * 4 / 8;
1363 */
1364
1365 low = size * 4 / 8 / unit;
1366 high = size * 5 / 8 / unit;
1367
1368 dispc_ovl_set_mflag_threshold(i, low, high);
1369 }
1370}
1371
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001372static void dispc_ovl_set_fir(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301373 int hinc, int vinc,
1374 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001375{
1376 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001377
Amber Jain0d66cbb2011-05-19 19:47:54 +05301378 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1379 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301380
Amber Jain0d66cbb2011-05-19 19:47:54 +05301381 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1382 &hinc_start, &hinc_end);
1383 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1384 &vinc_start, &vinc_end);
1385 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1386 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301387
Amber Jain0d66cbb2011-05-19 19:47:54 +05301388 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1389 } else {
1390 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1391 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1392 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001393}
1394
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001395static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001396{
1397 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301398 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001399
Archit Taneja87a74842011-03-02 11:19:50 +05301400 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1401 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1402
1403 val = FLD_VAL(vaccu, vert_start, vert_end) |
1404 FLD_VAL(haccu, hor_start, hor_end);
1405
Archit Taneja9b372c22011-05-06 11:45:49 +05301406 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001407}
1408
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001409static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001410{
1411 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301412 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001413
Archit Taneja87a74842011-03-02 11:19:50 +05301414 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1415 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1416
1417 val = FLD_VAL(vaccu, vert_start, vert_end) |
1418 FLD_VAL(haccu, hor_start, hor_end);
1419
Archit Taneja9b372c22011-05-06 11:45:49 +05301420 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001421}
1422
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001423static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1424 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301425{
1426 u32 val;
1427
1428 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1429 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1430}
1431
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001432static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1433 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301434{
1435 u32 val;
1436
1437 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1438 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1439}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001440
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001441static void dispc_ovl_set_scale_param(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001442 u16 orig_width, u16 orig_height,
1443 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301444 bool five_taps, u8 rotation,
1445 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001446{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301447 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001448
Amber Jained14a3c2011-05-19 19:47:51 +05301449 fir_hinc = 1024 * orig_width / out_width;
1450 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001451
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301452 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1453 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001454 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301455}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001456
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301457static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1458 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1459 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1460{
1461 int h_accu2_0, h_accu2_1;
1462 int v_accu2_0, v_accu2_1;
1463 int chroma_hinc, chroma_vinc;
1464 int idx;
1465
1466 struct accu {
1467 s8 h0_m, h0_n;
1468 s8 h1_m, h1_n;
1469 s8 v0_m, v0_n;
1470 s8 v1_m, v1_n;
1471 };
1472
1473 const struct accu *accu_table;
1474 const struct accu *accu_val;
1475
1476 static const struct accu accu_nv12[4] = {
1477 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1478 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1479 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1480 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1481 };
1482
1483 static const struct accu accu_nv12_ilace[4] = {
1484 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1485 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1486 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1487 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1488 };
1489
1490 static const struct accu accu_yuv[4] = {
1491 { 0, 1, 0, 1, 0, 1, 0, 1 },
1492 { 0, 1, 0, 1, 0, 1, 0, 1 },
1493 { -1, 1, 0, 1, 0, 1, 0, 1 },
1494 { 0, 1, 0, 1, -1, 1, 0, 1 },
1495 };
1496
1497 switch (rotation) {
1498 case OMAP_DSS_ROT_0:
1499 idx = 0;
1500 break;
1501 case OMAP_DSS_ROT_90:
1502 idx = 1;
1503 break;
1504 case OMAP_DSS_ROT_180:
1505 idx = 2;
1506 break;
1507 case OMAP_DSS_ROT_270:
1508 idx = 3;
1509 break;
1510 default:
1511 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001512 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301513 }
1514
1515 switch (color_mode) {
1516 case OMAP_DSS_COLOR_NV12:
1517 if (ilace)
1518 accu_table = accu_nv12_ilace;
1519 else
1520 accu_table = accu_nv12;
1521 break;
1522 case OMAP_DSS_COLOR_YUV2:
1523 case OMAP_DSS_COLOR_UYVY:
1524 accu_table = accu_yuv;
1525 break;
1526 default:
1527 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001528 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301529 }
1530
1531 accu_val = &accu_table[idx];
1532
1533 chroma_hinc = 1024 * orig_width / out_width;
1534 chroma_vinc = 1024 * orig_height / out_height;
1535
1536 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1537 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1538 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1539 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1540
1541 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1542 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1543}
1544
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001545static void dispc_ovl_set_scaling_common(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301546 u16 orig_width, u16 orig_height,
1547 u16 out_width, u16 out_height,
1548 bool ilace, bool five_taps,
1549 bool fieldmode, enum omap_color_mode color_mode,
1550 u8 rotation)
1551{
1552 int accu0 = 0;
1553 int accu1 = 0;
1554 u32 l;
1555
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001556 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301557 out_width, out_height, five_taps,
1558 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301559 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001560
Archit Taneja87a74842011-03-02 11:19:50 +05301561 /* RESIZEENABLE and VERTICALTAPS */
1562 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301563 l |= (orig_width != out_width) ? (1 << 5) : 0;
1564 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001565 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301566
1567 /* VRESIZECONF and HRESIZECONF */
1568 if (dss_has_feature(FEAT_RESIZECONF)) {
1569 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301570 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1571 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301572 }
1573
1574 /* LINEBUFFERSPLIT */
1575 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1576 l &= ~(0x1 << 22);
1577 l |= five_taps ? (1 << 22) : 0;
1578 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001579
Archit Taneja9b372c22011-05-06 11:45:49 +05301580 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001581
1582 /*
1583 * field 0 = even field = bottom field
1584 * field 1 = odd field = top field
1585 */
1586 if (ilace && !fieldmode) {
1587 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301588 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001589 if (accu0 >= 1024/2) {
1590 accu1 = 1024/2;
1591 accu0 -= accu1;
1592 }
1593 }
1594
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001595 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1596 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001597}
1598
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001599static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301600 u16 orig_width, u16 orig_height,
1601 u16 out_width, u16 out_height,
1602 bool ilace, bool five_taps,
1603 bool fieldmode, enum omap_color_mode color_mode,
1604 u8 rotation)
1605{
1606 int scale_x = out_width != orig_width;
1607 int scale_y = out_height != orig_height;
Archit Tanejaf92afae2012-08-24 11:11:14 +05301608 bool chroma_upscale = plane != OMAP_DSS_WB ? true : false;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301609
1610 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1611 return;
1612 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1613 color_mode != OMAP_DSS_COLOR_UYVY &&
1614 color_mode != OMAP_DSS_COLOR_NV12)) {
1615 /* reset chroma resampling for RGB formats */
Archit Taneja2a5561b2012-07-16 16:37:45 +05301616 if (plane != OMAP_DSS_WB)
1617 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301618 return;
1619 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001620
1621 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1622 out_height, ilace, color_mode, rotation);
1623
Amber Jain0d66cbb2011-05-19 19:47:54 +05301624 switch (color_mode) {
1625 case OMAP_DSS_COLOR_NV12:
Archit Taneja20fbb502012-08-22 17:04:48 +05301626 if (chroma_upscale) {
1627 /* UV is subsampled by 2 horizontally and vertically */
1628 orig_height >>= 1;
1629 orig_width >>= 1;
1630 } else {
1631 /* UV is downsampled by 2 horizontally and vertically */
1632 orig_height <<= 1;
1633 orig_width <<= 1;
1634 }
1635
Amber Jain0d66cbb2011-05-19 19:47:54 +05301636 break;
1637 case OMAP_DSS_COLOR_YUV2:
1638 case OMAP_DSS_COLOR_UYVY:
Archit Taneja20fbb502012-08-22 17:04:48 +05301639 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
Amber Jain0d66cbb2011-05-19 19:47:54 +05301640 if (rotation == OMAP_DSS_ROT_0 ||
Archit Taneja20fbb502012-08-22 17:04:48 +05301641 rotation == OMAP_DSS_ROT_180) {
1642 if (chroma_upscale)
1643 /* UV is subsampled by 2 horizontally */
1644 orig_width >>= 1;
1645 else
1646 /* UV is downsampled by 2 horizontally */
1647 orig_width <<= 1;
1648 }
1649
Amber Jain0d66cbb2011-05-19 19:47:54 +05301650 /* must use FIR for YUV422 if rotated */
1651 if (rotation != OMAP_DSS_ROT_0)
1652 scale_x = scale_y = true;
Archit Taneja20fbb502012-08-22 17:04:48 +05301653
Amber Jain0d66cbb2011-05-19 19:47:54 +05301654 break;
1655 default:
1656 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001657 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301658 }
1659
1660 if (out_width != orig_width)
1661 scale_x = true;
1662 if (out_height != orig_height)
1663 scale_y = true;
1664
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001665 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301666 out_width, out_height, five_taps,
1667 rotation, DISPC_COLOR_COMPONENT_UV);
1668
Archit Taneja2a5561b2012-07-16 16:37:45 +05301669 if (plane != OMAP_DSS_WB)
1670 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1671 (scale_x || scale_y) ? 1 : 0, 8, 8);
1672
Amber Jain0d66cbb2011-05-19 19:47:54 +05301673 /* set H scaling */
1674 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1675 /* set V scaling */
1676 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301677}
1678
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001679static void dispc_ovl_set_scaling(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301680 u16 orig_width, u16 orig_height,
1681 u16 out_width, u16 out_height,
1682 bool ilace, bool five_taps,
1683 bool fieldmode, enum omap_color_mode color_mode,
1684 u8 rotation)
1685{
1686 BUG_ON(plane == OMAP_DSS_GFX);
1687
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001688 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301689 orig_width, orig_height,
1690 out_width, out_height,
1691 ilace, five_taps,
1692 fieldmode, color_mode,
1693 rotation);
1694
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001695 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301696 orig_width, orig_height,
1697 out_width, out_height,
1698 ilace, five_taps,
1699 fieldmode, color_mode,
1700 rotation);
1701}
1702
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001703static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
Archit Tanejac35eeb22013-03-26 19:15:24 +05301704 enum omap_dss_rotation_type rotation_type,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001705 bool mirroring, enum omap_color_mode color_mode)
1706{
Archit Taneja87a74842011-03-02 11:19:50 +05301707 bool row_repeat = false;
1708 int vidrot = 0;
1709
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001710 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1711 color_mode == OMAP_DSS_COLOR_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001712
1713 if (mirroring) {
1714 switch (rotation) {
1715 case OMAP_DSS_ROT_0:
1716 vidrot = 2;
1717 break;
1718 case OMAP_DSS_ROT_90:
1719 vidrot = 1;
1720 break;
1721 case OMAP_DSS_ROT_180:
1722 vidrot = 0;
1723 break;
1724 case OMAP_DSS_ROT_270:
1725 vidrot = 3;
1726 break;
1727 }
1728 } else {
1729 switch (rotation) {
1730 case OMAP_DSS_ROT_0:
1731 vidrot = 0;
1732 break;
1733 case OMAP_DSS_ROT_90:
1734 vidrot = 1;
1735 break;
1736 case OMAP_DSS_ROT_180:
1737 vidrot = 2;
1738 break;
1739 case OMAP_DSS_ROT_270:
1740 vidrot = 3;
1741 break;
1742 }
1743 }
1744
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001745 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
Archit Taneja87a74842011-03-02 11:19:50 +05301746 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001747 else
Archit Taneja87a74842011-03-02 11:19:50 +05301748 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001749 }
Archit Taneja87a74842011-03-02 11:19:50 +05301750
Tomi Valkeinen3397cc62015-04-09 13:51:30 +03001751 /*
1752 * OMAP4/5 Errata i631:
1753 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
1754 * rows beyond the framebuffer, which may cause OCP error.
1755 */
1756 if (color_mode == OMAP_DSS_COLOR_NV12 &&
1757 rotation_type != OMAP_DSS_ROT_TILER)
1758 vidrot = 1;
1759
Archit Taneja9b372c22011-05-06 11:45:49 +05301760 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301761 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301762 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1763 row_repeat ? 1 : 0, 18, 18);
Archit Tanejac35eeb22013-03-26 19:15:24 +05301764
1765 if (color_mode == OMAP_DSS_COLOR_NV12) {
1766 bool doublestride = (rotation_type == OMAP_DSS_ROT_TILER) &&
1767 (rotation == OMAP_DSS_ROT_0 ||
1768 rotation == OMAP_DSS_ROT_180);
1769 /* DOUBLESTRIDE */
1770 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22);
1771 }
1772
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001773}
1774
1775static int color_mode_to_bpp(enum omap_color_mode color_mode)
1776{
1777 switch (color_mode) {
1778 case OMAP_DSS_COLOR_CLUT1:
1779 return 1;
1780 case OMAP_DSS_COLOR_CLUT2:
1781 return 2;
1782 case OMAP_DSS_COLOR_CLUT4:
1783 return 4;
1784 case OMAP_DSS_COLOR_CLUT8:
Amber Jainf20e4222011-05-19 19:47:50 +05301785 case OMAP_DSS_COLOR_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001786 return 8;
1787 case OMAP_DSS_COLOR_RGB12U:
1788 case OMAP_DSS_COLOR_RGB16:
1789 case OMAP_DSS_COLOR_ARGB16:
1790 case OMAP_DSS_COLOR_YUV2:
1791 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301792 case OMAP_DSS_COLOR_RGBA16:
1793 case OMAP_DSS_COLOR_RGBX16:
1794 case OMAP_DSS_COLOR_ARGB16_1555:
1795 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001796 return 16;
1797 case OMAP_DSS_COLOR_RGB24P:
1798 return 24;
1799 case OMAP_DSS_COLOR_RGB24U:
1800 case OMAP_DSS_COLOR_ARGB32:
1801 case OMAP_DSS_COLOR_RGBA32:
1802 case OMAP_DSS_COLOR_RGBX32:
1803 return 32;
1804 default:
1805 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001806 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001807 }
1808}
1809
1810static s32 pixinc(int pixels, u8 ps)
1811{
1812 if (pixels == 1)
1813 return 1;
1814 else if (pixels > 1)
1815 return 1 + (pixels - 1) * ps;
1816 else if (pixels < 0)
1817 return 1 - (-pixels + 1) * ps;
1818 else
1819 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001820 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001821}
1822
1823static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1824 u16 screen_width,
1825 u16 width, u16 height,
1826 enum omap_color_mode color_mode, bool fieldmode,
1827 unsigned int field_offset,
1828 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301829 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001830{
1831 u8 ps;
1832
1833 /* FIXME CLUT formats */
1834 switch (color_mode) {
1835 case OMAP_DSS_COLOR_CLUT1:
1836 case OMAP_DSS_COLOR_CLUT2:
1837 case OMAP_DSS_COLOR_CLUT4:
1838 case OMAP_DSS_COLOR_CLUT8:
1839 BUG();
1840 return;
1841 case OMAP_DSS_COLOR_YUV2:
1842 case OMAP_DSS_COLOR_UYVY:
1843 ps = 4;
1844 break;
1845 default:
1846 ps = color_mode_to_bpp(color_mode) / 8;
1847 break;
1848 }
1849
1850 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1851 width, height);
1852
1853 /*
1854 * field 0 = even field = bottom field
1855 * field 1 = odd field = top field
1856 */
1857 switch (rotation + mirror * 4) {
1858 case OMAP_DSS_ROT_0:
1859 case OMAP_DSS_ROT_180:
1860 /*
1861 * If the pixel format is YUV or UYVY divide the width
1862 * of the image by 2 for 0 and 180 degree rotation.
1863 */
1864 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1865 color_mode == OMAP_DSS_COLOR_UYVY)
1866 width = width >> 1;
1867 case OMAP_DSS_ROT_90:
1868 case OMAP_DSS_ROT_270:
1869 *offset1 = 0;
1870 if (field_offset)
1871 *offset0 = field_offset * screen_width * ps;
1872 else
1873 *offset0 = 0;
1874
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301875 *row_inc = pixinc(1 +
1876 (y_predecim * screen_width - x_predecim * width) +
1877 (fieldmode ? screen_width : 0), ps);
1878 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001879 break;
1880
1881 case OMAP_DSS_ROT_0 + 4:
1882 case OMAP_DSS_ROT_180 + 4:
1883 /* If the pixel format is YUV or UYVY divide the width
1884 * of the image by 2 for 0 degree and 180 degree
1885 */
1886 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1887 color_mode == OMAP_DSS_COLOR_UYVY)
1888 width = width >> 1;
1889 case OMAP_DSS_ROT_90 + 4:
1890 case OMAP_DSS_ROT_270 + 4:
1891 *offset1 = 0;
1892 if (field_offset)
1893 *offset0 = field_offset * screen_width * ps;
1894 else
1895 *offset0 = 0;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301896 *row_inc = pixinc(1 -
1897 (y_predecim * screen_width + x_predecim * width) -
1898 (fieldmode ? screen_width : 0), ps);
1899 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001900 break;
1901
1902 default:
1903 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001904 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001905 }
1906}
1907
1908static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1909 u16 screen_width,
1910 u16 width, u16 height,
1911 enum omap_color_mode color_mode, bool fieldmode,
1912 unsigned int field_offset,
1913 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301914 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001915{
1916 u8 ps;
1917 u16 fbw, fbh;
1918
1919 /* FIXME CLUT formats */
1920 switch (color_mode) {
1921 case OMAP_DSS_COLOR_CLUT1:
1922 case OMAP_DSS_COLOR_CLUT2:
1923 case OMAP_DSS_COLOR_CLUT4:
1924 case OMAP_DSS_COLOR_CLUT8:
1925 BUG();
1926 return;
1927 default:
1928 ps = color_mode_to_bpp(color_mode) / 8;
1929 break;
1930 }
1931
1932 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1933 width, height);
1934
1935 /* width & height are overlay sizes, convert to fb sizes */
1936
1937 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1938 fbw = width;
1939 fbh = height;
1940 } else {
1941 fbw = height;
1942 fbh = width;
1943 }
1944
1945 /*
1946 * field 0 = even field = bottom field
1947 * field 1 = odd field = top field
1948 */
1949 switch (rotation + mirror * 4) {
1950 case OMAP_DSS_ROT_0:
1951 *offset1 = 0;
1952 if (field_offset)
1953 *offset0 = *offset1 + field_offset * screen_width * ps;
1954 else
1955 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301956 *row_inc = pixinc(1 +
1957 (y_predecim * screen_width - fbw * x_predecim) +
1958 (fieldmode ? screen_width : 0), ps);
1959 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1960 color_mode == OMAP_DSS_COLOR_UYVY)
1961 *pix_inc = pixinc(x_predecim, 2 * ps);
1962 else
1963 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001964 break;
1965 case OMAP_DSS_ROT_90:
1966 *offset1 = screen_width * (fbh - 1) * ps;
1967 if (field_offset)
1968 *offset0 = *offset1 + field_offset * ps;
1969 else
1970 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301971 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1972 y_predecim + (fieldmode ? 1 : 0), ps);
1973 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001974 break;
1975 case OMAP_DSS_ROT_180:
1976 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1977 if (field_offset)
1978 *offset0 = *offset1 - field_offset * screen_width * ps;
1979 else
1980 *offset0 = *offset1;
1981 *row_inc = pixinc(-1 -
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301982 (y_predecim * screen_width - fbw * x_predecim) -
1983 (fieldmode ? screen_width : 0), ps);
1984 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1985 color_mode == OMAP_DSS_COLOR_UYVY)
1986 *pix_inc = pixinc(-x_predecim, 2 * ps);
1987 else
1988 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001989 break;
1990 case OMAP_DSS_ROT_270:
1991 *offset1 = (fbw - 1) * ps;
1992 if (field_offset)
1993 *offset0 = *offset1 - field_offset * ps;
1994 else
1995 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301996 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1997 y_predecim - (fieldmode ? 1 : 0), ps);
1998 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001999 break;
2000
2001 /* mirroring */
2002 case OMAP_DSS_ROT_0 + 4:
2003 *offset1 = (fbw - 1) * ps;
2004 if (field_offset)
2005 *offset0 = *offset1 + field_offset * screen_width * ps;
2006 else
2007 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302008 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002009 (fieldmode ? screen_width : 0),
2010 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302011 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2012 color_mode == OMAP_DSS_COLOR_UYVY)
2013 *pix_inc = pixinc(-x_predecim, 2 * ps);
2014 else
2015 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002016 break;
2017
2018 case OMAP_DSS_ROT_90 + 4:
2019 *offset1 = 0;
2020 if (field_offset)
2021 *offset0 = *offset1 + field_offset * ps;
2022 else
2023 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302024 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
2025 y_predecim + (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002026 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302027 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002028 break;
2029
2030 case OMAP_DSS_ROT_180 + 4:
2031 *offset1 = screen_width * (fbh - 1) * ps;
2032 if (field_offset)
2033 *offset0 = *offset1 - field_offset * screen_width * ps;
2034 else
2035 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302036 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002037 (fieldmode ? screen_width : 0),
2038 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302039 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2040 color_mode == OMAP_DSS_COLOR_UYVY)
2041 *pix_inc = pixinc(x_predecim, 2 * ps);
2042 else
2043 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002044 break;
2045
2046 case OMAP_DSS_ROT_270 + 4:
2047 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
2048 if (field_offset)
2049 *offset0 = *offset1 - field_offset * ps;
2050 else
2051 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302052 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
2053 y_predecim - (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002054 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302055 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002056 break;
2057
2058 default:
2059 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002060 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002061 }
2062}
2063
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302064static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
2065 enum omap_color_mode color_mode, bool fieldmode,
2066 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
2067 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
2068{
2069 u8 ps;
2070
2071 switch (color_mode) {
2072 case OMAP_DSS_COLOR_CLUT1:
2073 case OMAP_DSS_COLOR_CLUT2:
2074 case OMAP_DSS_COLOR_CLUT4:
2075 case OMAP_DSS_COLOR_CLUT8:
2076 BUG();
2077 return;
2078 default:
2079 ps = color_mode_to_bpp(color_mode) / 8;
2080 break;
2081 }
2082
2083 DSSDBG("scrw %d, width %d\n", screen_width, width);
2084
2085 /*
2086 * field 0 = even field = bottom field
2087 * field 1 = odd field = top field
2088 */
2089 *offset1 = 0;
2090 if (field_offset)
2091 *offset0 = *offset1 + field_offset * screen_width * ps;
2092 else
2093 *offset0 = *offset1;
2094 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
2095 (fieldmode ? screen_width : 0), ps);
2096 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2097 color_mode == OMAP_DSS_COLOR_UYVY)
2098 *pix_inc = pixinc(x_predecim, 2 * ps);
2099 else
2100 *pix_inc = pixinc(x_predecim, ps);
2101}
2102
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302103/*
2104 * This function is used to avoid synclosts in OMAP3, because of some
2105 * undocumented horizontal position and timing related limitations.
2106 */
Tomi Valkeinen465ec132012-10-19 15:40:24 +03002107static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302108 const struct omap_video_timings *t, u16 pos_x,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002109 u16 width, u16 height, u16 out_width, u16 out_height,
2110 bool five_taps)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302111{
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002112 const int ds = DIV_ROUND_UP(height, out_height);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302113 unsigned long nonactive;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302114 static const u8 limits[3] = { 8, 10, 20 };
2115 u64 val, blank;
2116 int i;
2117
Archit Taneja81ab95b2012-05-08 15:53:20 +05302118 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302119
2120 i = 0;
2121 if (out_height < height)
2122 i++;
2123 if (out_width < width)
2124 i++;
Archit Taneja81ab95b2012-05-08 15:53:20 +05302125 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302126 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2127 if (blank <= limits[i])
2128 return -EINVAL;
2129
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002130 /* FIXME add checks for 3-tap filter once the limitations are known */
2131 if (!five_taps)
2132 return 0;
2133
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302134 /*
2135 * Pixel data should be prepared before visible display point starts.
2136 * So, atleast DS-2 lines must have already been fetched by DISPC
2137 * during nonactive - pos_x period.
2138 */
2139 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2140 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002141 val, max(0, ds - 2) * width);
2142 if (val < max(0, ds - 2) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302143 return -EINVAL;
2144
2145 /*
2146 * All lines need to be refilled during the nonactive period of which
2147 * only one line can be loaded during the active period. So, atleast
2148 * DS - 1 lines should be loaded during nonactive period.
2149 */
2150 val = div_u64((u64)nonactive * lclk, pclk);
2151 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002152 val, max(0, ds - 1) * width);
2153 if (val < max(0, ds - 1) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302154 return -EINVAL;
2155
2156 return 0;
2157}
2158
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002159static unsigned long calc_core_clk_five_taps(unsigned long pclk,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302160 const struct omap_video_timings *mgr_timings, u16 width,
2161 u16 height, u16 out_width, u16 out_height,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002162 enum omap_color_mode color_mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002163{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302164 u32 core_clk = 0;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302165 u64 tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002166
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302167 if (height <= out_height && width <= out_width)
2168 return (unsigned long) pclk;
2169
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002170 if (height > out_height) {
Archit Taneja81ab95b2012-05-08 15:53:20 +05302171 unsigned int ppl = mgr_timings->x_res;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002172
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002173 tmp = (u64)pclk * height * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002174 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302175 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002176
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02002177 if (height > 2 * out_height) {
2178 if (ppl == out_width)
2179 return 0;
2180
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002181 tmp = (u64)pclk * (height - 2 * out_height) * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002182 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302183 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002184 }
2185 }
2186
2187 if (width > out_width) {
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002188 tmp = (u64)pclk * width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002189 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302190 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002191
2192 if (color_mode == OMAP_DSS_COLOR_RGB24U)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302193 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002194 }
2195
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302196 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002197}
2198
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002199static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302200 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302201{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302202 if (height > out_height && width > out_width)
2203 return pclk * 4;
2204 else
2205 return pclk * 2;
2206}
2207
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002208static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302209 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002210{
2211 unsigned int hf, vf;
2212
2213 /*
2214 * FIXME how to determine the 'A' factor
2215 * for the no downscaling case ?
2216 */
2217
2218 if (width > 3 * out_width)
2219 hf = 4;
2220 else if (width > 2 * out_width)
2221 hf = 3;
2222 else if (width > out_width)
2223 hf = 2;
2224 else
2225 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002226 if (height > out_height)
2227 vf = 2;
2228 else
2229 vf = 1;
2230
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302231 return pclk * vf * hf;
2232}
2233
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002234static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302235 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302236{
Archit Taneja8ba85302012-09-26 17:00:37 +05302237 /*
2238 * If the overlay/writeback is in mem to mem mode, there are no
2239 * downscaling limitations with respect to pixel clock, return 1 as
2240 * required core clock to represent that we have sufficient enough
2241 * core clock to do maximum downscaling
2242 */
2243 if (mem_to_mem)
2244 return 1;
2245
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302246 if (width > out_width)
2247 return DIV_ROUND_UP(pclk, out_width) * width;
2248 else
2249 return pclk;
2250}
2251
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002252static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302253 const struct omap_video_timings *mgr_timings,
2254 u16 width, u16 height, u16 out_width, u16 out_height,
2255 enum omap_color_mode color_mode, bool *five_taps,
2256 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302257 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302258{
2259 int error;
2260 u16 in_width, in_height;
2261 int min_factor = min(*decim_x, *decim_y);
2262 const int maxsinglelinewidth =
2263 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302264
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302265 *five_taps = false;
2266
2267 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002268 in_height = height / *decim_y;
2269 in_width = width / *decim_x;
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002270 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302271 in_height, out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302272 error = (in_width > maxsinglelinewidth || !*core_clk ||
2273 *core_clk > dispc_core_clk_rate());
2274 if (error) {
2275 if (*decim_x == *decim_y) {
2276 *decim_x = min_factor;
2277 ++*decim_y;
2278 } else {
2279 swap(*decim_x, *decim_y);
2280 if (*decim_x < *decim_y)
2281 ++*decim_x;
2282 }
2283 }
2284 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2285
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002286 if (error) {
2287 DSSERR("failed to find scaling settings\n");
2288 return -EINVAL;
2289 }
2290
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302291 if (in_width > maxsinglelinewidth) {
2292 DSSERR("Cannot scale max input width exceeded");
2293 return -EINVAL;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302294 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302295 return 0;
2296}
2297
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002298static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302299 const struct omap_video_timings *mgr_timings,
2300 u16 width, u16 height, u16 out_width, u16 out_height,
2301 enum omap_color_mode color_mode, bool *five_taps,
2302 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302303 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302304{
2305 int error;
2306 u16 in_width, in_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302307 const int maxsinglelinewidth =
2308 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2309
2310 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002311 in_height = height / *decim_y;
2312 in_width = width / *decim_x;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002313 *five_taps = in_height > out_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302314
2315 if (in_width > maxsinglelinewidth)
2316 if (in_height > out_height &&
2317 in_height < out_height * 2)
2318 *five_taps = false;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002319again:
2320 if (*five_taps)
2321 *core_clk = calc_core_clk_five_taps(pclk, mgr_timings,
2322 in_width, in_height, out_width,
2323 out_height, color_mode);
2324 else
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002325 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302326 in_height, out_width, out_height,
2327 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302328
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002329 error = check_horiz_timing_omap3(pclk, lclk, mgr_timings,
2330 pos_x, in_width, in_height, out_width,
2331 out_height, *five_taps);
2332 if (error && *five_taps) {
2333 *five_taps = false;
2334 goto again;
2335 }
2336
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302337 error = (error || in_width > maxsinglelinewidth * 2 ||
2338 (in_width > maxsinglelinewidth && *five_taps) ||
2339 !*core_clk || *core_clk > dispc_core_clk_rate());
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002340
2341 if (!error) {
2342 /* verify that we're inside the limits of scaler */
2343 if (in_width / 4 > out_width)
2344 error = 1;
2345
2346 if (*five_taps) {
2347 if (in_height / 4 > out_height)
2348 error = 1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302349 } else {
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002350 if (in_height / 2 > out_height)
2351 error = 1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302352 }
2353 }
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002354
Tomi Valkeinen7059e3d2015-04-10 12:48:38 +03002355 if (error)
2356 ++*decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302357 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2358
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002359 if (error) {
2360 DSSERR("failed to find scaling settings\n");
2361 return -EINVAL;
2362 }
2363
Tomi Valkeinenf5a73482015-03-17 15:31:09 +02002364 if (check_horiz_timing_omap3(pclk, lclk, mgr_timings, pos_x, in_width,
2365 in_height, out_width, out_height, *five_taps)) {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302366 DSSERR("horizontal timing too tight\n");
2367 return -EINVAL;
2368 }
2369
2370 if (in_width > (maxsinglelinewidth * 2)) {
2371 DSSERR("Cannot setup scaling");
2372 DSSERR("width exceeds maximum width possible");
2373 return -EINVAL;
2374 }
2375
2376 if (in_width > maxsinglelinewidth && *five_taps) {
2377 DSSERR("cannot setup scaling with five taps");
2378 return -EINVAL;
2379 }
2380 return 0;
2381}
2382
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002383static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302384 const struct omap_video_timings *mgr_timings,
2385 u16 width, u16 height, u16 out_width, u16 out_height,
2386 enum omap_color_mode color_mode, bool *five_taps,
2387 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302388 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302389{
2390 u16 in_width, in_width_max;
2391 int decim_x_min = *decim_x;
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002392 u16 in_height = height / *decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302393 const int maxsinglelinewidth =
2394 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja8ba85302012-09-26 17:00:37 +05302395 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302396
Archit Taneja5d501082012-11-07 11:45:02 +05302397 if (mem_to_mem) {
2398 in_width_max = out_width * maxdownscale;
2399 } else {
Archit Taneja8ba85302012-09-26 17:00:37 +05302400 in_width_max = dispc_core_clk_rate() /
2401 DIV_ROUND_UP(pclk, out_width);
Archit Taneja5d501082012-11-07 11:45:02 +05302402 }
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302403
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302404 *decim_x = DIV_ROUND_UP(width, in_width_max);
2405
2406 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2407 if (*decim_x > *x_predecim)
2408 return -EINVAL;
2409
2410 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002411 in_width = width / *decim_x;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302412 } while (*decim_x <= *x_predecim &&
2413 in_width > maxsinglelinewidth && ++*decim_x);
2414
2415 if (in_width > maxsinglelinewidth) {
2416 DSSERR("Cannot scale width exceeds max line width");
2417 return -EINVAL;
2418 }
2419
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002420 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
Archit Taneja8ba85302012-09-26 17:00:37 +05302421 out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302422 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002423}
2424
Tomi Valkeinene4c5ae72015-04-10 12:48:39 +03002425#define DIV_FRAC(dividend, divisor) \
2426 ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2427
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002428static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302429 enum omap_overlay_caps caps,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302430 const struct omap_video_timings *mgr_timings,
2431 u16 width, u16 height, u16 out_width, u16 out_height,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302432 enum omap_color_mode color_mode, bool *five_taps,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302433 int *x_predecim, int *y_predecim, u16 pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302434 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302435{
Archit Taneja0373cac2011-09-08 13:25:17 +05302436 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302437 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302438 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302439 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302440
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002441 if (width == out_width && height == out_height)
2442 return 0;
2443
Tomi Valkeinen4e1d3ca2014-10-03 15:14:09 +00002444 if (pclk == 0 || mgr_timings->pixelclock == 0) {
2445 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2446 return -EINVAL;
2447 }
2448
Archit Taneja5b54ed32012-09-26 16:55:27 +05302449 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002450 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302451
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002452 if (mem_to_mem) {
Archit Taneja1c031442012-11-07 11:45:03 +05302453 *x_predecim = *y_predecim = 1;
2454 } else {
2455 *x_predecim = max_decim_limit;
2456 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2457 dss_has_feature(FEAT_BURST_2D)) ?
2458 2 : max_decim_limit;
2459 }
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302460
2461 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2462 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2463 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2464 color_mode == OMAP_DSS_COLOR_CLUT8) {
2465 *x_predecim = 1;
2466 *y_predecim = 1;
2467 *five_taps = false;
2468 return 0;
2469 }
2470
2471 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2472 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2473
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302474 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302475 return -EINVAL;
2476
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302477 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302478 return -EINVAL;
2479
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002480 ret = dispc.feat->calc_scaling(pclk, lclk, mgr_timings, width, height,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302481 out_width, out_height, color_mode, five_taps,
Archit Taneja8ba85302012-09-26 17:00:37 +05302482 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2483 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302484 if (ret)
2485 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302486
Tomi Valkeinene4c5ae72015-04-10 12:48:39 +03002487 DSSDBG("%dx%d -> %dx%d (%d.%02d x %d.%02d), decim %dx%d %dx%d (%d.%02d x %d.%02d), taps %d, req clk %lu, cur clk %lu\n",
2488 width, height,
2489 out_width, out_height,
2490 out_width / width, DIV_FRAC(out_width, width),
2491 out_height / height, DIV_FRAC(out_height, height),
2492
2493 decim_x, decim_y,
2494 width / decim_x, height / decim_y,
2495 out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
2496 out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
2497
2498 *five_taps ? 5 : 3,
2499 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302500
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302501 if (!core_clk || core_clk > dispc_core_clk_rate()) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302502 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302503 "required core clk rate = %lu Hz, "
2504 "current core clk rate = %lu Hz\n",
2505 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302506 return -EINVAL;
2507 }
2508
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302509 *x_predecim = decim_x;
2510 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302511 return 0;
2512}
2513
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002514int dispc_ovl_check(enum omap_plane plane, enum omap_channel channel,
2515 const struct omap_overlay_info *oi,
2516 const struct omap_video_timings *timings,
2517 int *x_predecim, int *y_predecim)
2518{
2519 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2520 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002521 bool fieldmode = false;
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002522 u16 in_height = oi->height;
2523 u16 in_width = oi->width;
2524 bool ilace = timings->interlace;
2525 u16 out_width, out_height;
2526 int pos_x = oi->pos_x;
2527 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2528 unsigned long lclk = dispc_mgr_lclk_rate(channel);
2529
2530 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2531 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
2532
2533 if (ilace && oi->height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002534 fieldmode = true;
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002535
2536 if (ilace) {
2537 if (fieldmode)
2538 in_height /= 2;
2539 out_height /= 2;
2540
2541 DSSDBG("adjusting for ilace: height %d, out_height %d\n",
2542 in_height, out_height);
2543 }
2544
2545 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
2546 return -EINVAL;
2547
2548 return dispc_ovl_calc_scaling(pclk, lclk, caps, timings, in_width,
2549 in_height, out_width, out_height, oi->color_mode,
2550 &five_taps, x_predecim, y_predecim, pos_x,
2551 oi->rotation_type, false);
2552}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002553EXPORT_SYMBOL(dispc_ovl_check);
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002554
Archit Taneja84a880f2012-09-26 16:57:37 +05302555static int dispc_ovl_setup_common(enum omap_plane plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302556 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2557 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2558 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2559 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2560 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
Archit Taneja8ba85302012-09-26 17:00:37 +05302561 bool replication, const struct omap_video_timings *mgr_timings,
2562 bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002563{
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302564 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002565 bool fieldmode = false;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302566 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002567 unsigned offset0, offset1;
2568 s32 row_inc;
2569 s32 pix_inc;
Archit Taneja6be0d732012-11-07 11:45:04 +05302570 u16 frame_width, frame_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002571 unsigned int field_offset = 0;
Archit Taneja84a880f2012-09-26 16:57:37 +05302572 u16 in_height = height;
2573 u16 in_width = width;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302574 int x_predecim = 1, y_predecim = 1;
Archit Taneja8050cbe2012-06-06 16:25:52 +05302575 bool ilace = mgr_timings->interlace;
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002576 unsigned long pclk = dispc_plane_pclk_rate(plane);
2577 unsigned long lclk = dispc_plane_lclk_rate(plane);
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002578
Tomi Valkeinene5666582014-11-28 14:34:15 +02002579 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002580 return -EINVAL;
2581
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002582 switch (color_mode) {
2583 case OMAP_DSS_COLOR_YUV2:
2584 case OMAP_DSS_COLOR_UYVY:
2585 case OMAP_DSS_COLOR_NV12:
2586 if (in_width & 1) {
2587 DSSERR("input width %d is not even for YUV format\n",
2588 in_width);
2589 return -EINVAL;
2590 }
2591 break;
2592
2593 default:
2594 break;
2595 }
2596
Archit Taneja84a880f2012-09-26 16:57:37 +05302597 out_width = out_width == 0 ? width : out_width;
2598 out_height = out_height == 0 ? height : out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002599
Archit Taneja84a880f2012-09-26 16:57:37 +05302600 if (ilace && height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002601 fieldmode = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002602
2603 if (ilace) {
2604 if (fieldmode)
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302605 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302606 pos_y /= 2;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302607 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002608
2609 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
Archit Taneja84a880f2012-09-26 16:57:37 +05302610 "out_height %d\n", in_height, pos_y,
2611 out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002612 }
2613
Archit Taneja84a880f2012-09-26 16:57:37 +05302614 if (!dss_feat_color_mode_supported(plane, color_mode))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302615 return -EINVAL;
2616
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002617 r = dispc_ovl_calc_scaling(pclk, lclk, caps, mgr_timings, in_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302618 in_height, out_width, out_height, color_mode,
2619 &five_taps, &x_predecim, &y_predecim, pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302620 rotation_type, mem_to_mem);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302621 if (r)
2622 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002623
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002624 in_width = in_width / x_predecim;
2625 in_height = in_height / y_predecim;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302626
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002627 if (x_predecim > 1 || y_predecim > 1)
2628 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2629 x_predecim, y_predecim, in_width, in_height);
2630
2631 switch (color_mode) {
2632 case OMAP_DSS_COLOR_YUV2:
2633 case OMAP_DSS_COLOR_UYVY:
2634 case OMAP_DSS_COLOR_NV12:
2635 if (in_width & 1) {
2636 DSSDBG("predecimated input width is not even for YUV format\n");
2637 DSSDBG("adjusting input width %d -> %d\n",
2638 in_width, in_width & ~1);
2639
2640 in_width &= ~1;
2641 }
2642 break;
2643
2644 default:
2645 break;
2646 }
2647
Archit Taneja84a880f2012-09-26 16:57:37 +05302648 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2649 color_mode == OMAP_DSS_COLOR_UYVY ||
2650 color_mode == OMAP_DSS_COLOR_NV12)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302651 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002652
2653 if (ilace && !fieldmode) {
2654 /*
2655 * when downscaling the bottom field may have to start several
2656 * source lines below the top field. Unfortunately ACCUI
2657 * registers will only hold the fractional part of the offset
2658 * so the integer part must be added to the base address of the
2659 * bottom field.
2660 */
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302661 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002662 field_offset = 0;
2663 else
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302664 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002665 }
2666
2667 /* Fields are independent but interleaved in memory. */
2668 if (fieldmode)
2669 field_offset = 1;
2670
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002671 offset0 = 0;
2672 offset1 = 0;
2673 row_inc = 0;
2674 pix_inc = 0;
2675
Archit Taneja6be0d732012-11-07 11:45:04 +05302676 if (plane == OMAP_DSS_WB) {
2677 frame_width = out_width;
2678 frame_height = out_height;
2679 } else {
2680 frame_width = in_width;
2681 frame_height = height;
2682 }
2683
Archit Taneja84a880f2012-09-26 16:57:37 +05302684 if (rotation_type == OMAP_DSS_ROT_TILER)
Archit Taneja6be0d732012-11-07 11:45:04 +05302685 calc_tiler_rotation_offset(screen_width, frame_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302686 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302687 &offset0, &offset1, &row_inc, &pix_inc,
2688 x_predecim, y_predecim);
Archit Taneja84a880f2012-09-26 16:57:37 +05302689 else if (rotation_type == OMAP_DSS_ROT_DMA)
Archit Taneja6be0d732012-11-07 11:45:04 +05302690 calc_dma_rotation_offset(rotation, mirror, screen_width,
2691 frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302692 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302693 &offset0, &offset1, &row_inc, &pix_inc,
2694 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002695 else
Archit Taneja84a880f2012-09-26 16:57:37 +05302696 calc_vrfb_rotation_offset(rotation, mirror,
Archit Taneja6be0d732012-11-07 11:45:04 +05302697 screen_width, frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302698 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302699 &offset0, &offset1, &row_inc, &pix_inc,
2700 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002701
2702 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2703 offset0, offset1, row_inc, pix_inc);
2704
Archit Taneja84a880f2012-09-26 16:57:37 +05302705 dispc_ovl_set_color_mode(plane, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002706
Archit Taneja84a880f2012-09-26 16:57:37 +05302707 dispc_ovl_configure_burst_type(plane, rotation_type);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302708
Archit Taneja84a880f2012-09-26 16:57:37 +05302709 dispc_ovl_set_ba0(plane, paddr + offset0);
2710 dispc_ovl_set_ba1(plane, paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002711
Archit Taneja84a880f2012-09-26 16:57:37 +05302712 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2713 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2714 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302715 }
2716
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03002717 if (dispc.feat->last_pixel_inc_missing)
2718 row_inc += pix_inc - 1;
2719
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002720 dispc_ovl_set_row_inc(plane, row_inc);
2721 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002722
Archit Taneja84a880f2012-09-26 16:57:37 +05302723 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302724 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002725
Archit Taneja84a880f2012-09-26 16:57:37 +05302726 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002727
Archit Taneja78b687f2012-09-21 14:51:49 +05302728 dispc_ovl_set_input_size(plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002729
Archit Taneja5b54ed32012-09-26 16:55:27 +05302730 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302731 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2732 out_height, ilace, five_taps, fieldmode,
Archit Taneja84a880f2012-09-26 16:57:37 +05302733 color_mode, rotation);
Archit Taneja78b687f2012-09-21 14:51:49 +05302734 dispc_ovl_set_output_size(plane, out_width, out_height);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002735 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002736 }
2737
Archit Tanejac35eeb22013-03-26 19:15:24 +05302738 dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, mirror,
2739 color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002740
Archit Taneja84a880f2012-09-26 16:57:37 +05302741 dispc_ovl_set_zorder(plane, caps, zorder);
2742 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2743 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002744
Archit Tanejad79db852012-09-22 12:30:17 +05302745 dispc_ovl_enable_replication(plane, caps, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302746
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002747 return 0;
2748}
2749
Archit Taneja84a880f2012-09-26 16:57:37 +05302750int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
Archit Taneja8ba85302012-09-26 17:00:37 +05302751 bool replication, const struct omap_video_timings *mgr_timings,
2752 bool mem_to_mem)
Archit Taneja84a880f2012-09-26 16:57:37 +05302753{
2754 int r;
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002755 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
Archit Taneja84a880f2012-09-26 16:57:37 +05302756 enum omap_channel channel;
2757
2758 channel = dispc_ovl_get_channel_out(plane);
2759
Arnd Bergmann24f13a62014-04-24 13:28:18 +01002760 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2761 " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2762 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
Archit Taneja84a880f2012-09-26 16:57:37 +05302763 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2764 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2765
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002766 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302767 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2768 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2769 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
Archit Taneja8ba85302012-09-26 17:00:37 +05302770 oi->rotation_type, replication, mgr_timings, mem_to_mem);
Archit Taneja84a880f2012-09-26 16:57:37 +05302771
2772 return r;
2773}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002774EXPORT_SYMBOL(dispc_ovl_setup);
Archit Taneja84a880f2012-09-26 16:57:37 +05302775
Archit Taneja749feff2012-08-31 12:32:52 +05302776int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302777 bool mem_to_mem, const struct omap_video_timings *mgr_timings)
Archit Taneja749feff2012-08-31 12:32:52 +05302778{
2779 int r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302780 u32 l;
Archit Taneja749feff2012-08-31 12:32:52 +05302781 enum omap_plane plane = OMAP_DSS_WB;
2782 const int pos_x = 0, pos_y = 0;
2783 const u8 zorder = 0, global_alpha = 0;
2784 const bool replication = false;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302785 bool truncation;
Archit Taneja749feff2012-08-31 12:32:52 +05302786 int in_width = mgr_timings->x_res;
2787 int in_height = mgr_timings->y_res;
2788 enum omap_overlay_caps caps =
2789 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2790
2791 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2792 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2793 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2794 wi->mirror);
2795
2796 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2797 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2798 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2799 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302800 replication, mgr_timings, mem_to_mem);
2801
2802 switch (wi->color_mode) {
2803 case OMAP_DSS_COLOR_RGB16:
2804 case OMAP_DSS_COLOR_RGB24P:
2805 case OMAP_DSS_COLOR_ARGB16:
2806 case OMAP_DSS_COLOR_RGBA16:
2807 case OMAP_DSS_COLOR_RGB12U:
2808 case OMAP_DSS_COLOR_ARGB16_1555:
2809 case OMAP_DSS_COLOR_XRGB16_1555:
2810 case OMAP_DSS_COLOR_RGBX16:
2811 truncation = true;
2812 break;
2813 default:
2814 truncation = false;
2815 break;
2816 }
2817
2818 /* setup extra DISPC_WB_ATTRIBUTES */
2819 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2820 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2821 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2822 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Archit Taneja749feff2012-08-31 12:32:52 +05302823
2824 return r;
2825}
2826
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002827int dispc_ovl_enable(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002828{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002829 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2830
Archit Taneja9b372c22011-05-06 11:45:49 +05302831 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002832
2833 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002834}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002835EXPORT_SYMBOL(dispc_ovl_enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002836
Tomi Valkeinen04bd8ac2012-10-10 14:13:15 +03002837bool dispc_ovl_enabled(enum omap_plane plane)
2838{
2839 return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2840}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002841EXPORT_SYMBOL(dispc_ovl_enabled);
Tomi Valkeinen04bd8ac2012-10-10 14:13:15 +03002842
Tomi Valkeinenf1a813d2012-10-19 14:16:06 +03002843void dispc_mgr_enable(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002844{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302845 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2846 /* flush posted write */
2847 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002848}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002849EXPORT_SYMBOL(dispc_mgr_enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002850
Tomi Valkeinen65398512012-10-10 11:44:17 +03002851bool dispc_mgr_is_enabled(enum omap_channel channel)
2852{
2853 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2854}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002855EXPORT_SYMBOL(dispc_mgr_is_enabled);
Tomi Valkeinen65398512012-10-10 11:44:17 +03002856
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302857void dispc_wb_enable(bool enable)
2858{
Tomi Valkeinen916188a2012-10-10 14:13:26 +03002859 dispc_ovl_enable(OMAP_DSS_WB, enable);
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302860}
2861
2862bool dispc_wb_is_enabled(void)
2863{
Tomi Valkeinen916188a2012-10-10 14:13:26 +03002864 return dispc_ovl_enabled(OMAP_DSS_WB);
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302865}
2866
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002867static void dispc_lcd_enable_signal_polarity(bool act_high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002868{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002869 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2870 return;
2871
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002872 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002873}
2874
2875void dispc_lcd_enable_signal(bool enable)
2876{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002877 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2878 return;
2879
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002880 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002881}
2882
2883void dispc_pck_free_enable(bool enable)
2884{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002885 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2886 return;
2887
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002888 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002889}
2890
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002891static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002892{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302893 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002894}
2895
2896
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002897static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002898{
Archit Tanejad21f43b2012-06-21 09:45:11 +05302899 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002900}
2901
2902void dispc_set_loadmode(enum omap_dss_load_mode mode)
2903{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002904 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002905}
2906
2907
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002908static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002909{
Sumit Semwal8613b002010-12-02 11:27:09 +00002910 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002911}
2912
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002913static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002914 enum omap_dss_trans_key_type type,
2915 u32 trans_key)
2916{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302917 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002918
Sumit Semwal8613b002010-12-02 11:27:09 +00002919 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002920}
2921
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002922static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002923{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302924 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002925}
Archit Taneja11354dd2011-09-26 11:47:29 +05302926
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002927static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2928 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002929{
Archit Taneja11354dd2011-09-26 11:47:29 +05302930 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002931 return;
2932
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002933 if (ch == OMAP_DSS_CHANNEL_LCD)
2934 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002935 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002936 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002937}
Archit Taneja11354dd2011-09-26 11:47:29 +05302938
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002939void dispc_mgr_setup(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02002940 const struct omap_overlay_manager_info *info)
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002941{
2942 dispc_mgr_set_default_color(channel, info->default_color);
2943 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2944 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2945 dispc_mgr_enable_alpha_fixed_zorder(channel,
2946 info->partial_alpha_enabled);
2947 if (dss_has_feature(FEAT_CPR)) {
2948 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2949 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2950 }
2951}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002952EXPORT_SYMBOL(dispc_mgr_setup);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002953
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002954static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002955{
2956 int code;
2957
2958 switch (data_lines) {
2959 case 12:
2960 code = 0;
2961 break;
2962 case 16:
2963 code = 1;
2964 break;
2965 case 18:
2966 code = 2;
2967 break;
2968 case 24:
2969 code = 3;
2970 break;
2971 default:
2972 BUG();
2973 return;
2974 }
2975
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302976 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002977}
2978
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002979static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002980{
2981 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302982 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002983
2984 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302985 case DSS_IO_PAD_MODE_RESET:
2986 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002987 gpout1 = 0;
2988 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302989 case DSS_IO_PAD_MODE_RFBI:
2990 gpout0 = 1;
2991 gpout1 = 0;
2992 break;
2993 case DSS_IO_PAD_MODE_BYPASS:
2994 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002995 gpout1 = 1;
2996 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002997 default:
2998 BUG();
2999 return;
3000 }
3001
Archit Taneja569969d2011-08-22 17:41:57 +05303002 l = dispc_read_reg(DISPC_CONTROL);
3003 l = FLD_MOD(l, gpout0, 15, 15);
3004 l = FLD_MOD(l, gpout1, 16, 16);
3005 dispc_write_reg(DISPC_CONTROL, l);
3006}
3007
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003008static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
Archit Taneja569969d2011-08-22 17:41:57 +05303009{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05303010 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003011}
3012
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003013void dispc_mgr_set_lcd_config(enum omap_channel channel,
3014 const struct dss_lcd_mgr_config *config)
3015{
3016 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
3017
3018 dispc_mgr_enable_stallmode(channel, config->stallmode);
3019 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
3020
3021 dispc_mgr_set_clock_div(channel, &config->clock_info);
3022
3023 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
3024
3025 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
3026
3027 dispc_mgr_set_lcd_type_tft(channel);
3028}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003029EXPORT_SYMBOL(dispc_mgr_set_lcd_config);
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003030
Archit Taneja8f366162012-04-16 12:53:44 +05303031static bool _dispc_mgr_size_ok(u16 width, u16 height)
3032{
Archit Taneja33b89922012-11-14 13:50:15 +05303033 return width <= dispc.feat->mgr_width_max &&
3034 height <= dispc.feat->mgr_height_max;
Archit Taneja8f366162012-04-16 12:53:44 +05303035}
3036
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003037static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
3038 int vsw, int vfp, int vbp)
3039{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303040 if (hsw < 1 || hsw > dispc.feat->sw_max ||
3041 hfp < 1 || hfp > dispc.feat->hp_max ||
3042 hbp < 1 || hbp > dispc.feat->hp_max ||
3043 vsw < 1 || vsw > dispc.feat->sw_max ||
3044 vfp < 0 || vfp > dispc.feat->vp_max ||
3045 vbp < 0 || vbp > dispc.feat->vp_max)
3046 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003047 return true;
3048}
3049
Archit Tanejaca5ca692013-03-26 19:15:22 +05303050static bool _dispc_mgr_pclk_ok(enum omap_channel channel,
3051 unsigned long pclk)
3052{
3053 if (dss_mgr_is_lcd(channel))
3054 return pclk <= dispc.feat->max_lcd_pclk ? true : false;
3055 else
3056 return pclk <= dispc.feat->max_tv_pclk ? true : false;
3057}
3058
Archit Taneja8f366162012-04-16 12:53:44 +05303059bool dispc_mgr_timings_ok(enum omap_channel channel,
Archit Tanejab917fa32012-04-27 01:07:28 +05303060 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003061{
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003062 if (!_dispc_mgr_size_ok(timings->x_res, timings->y_res))
3063 return false;
Archit Taneja8f366162012-04-16 12:53:44 +05303064
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003065 if (!_dispc_mgr_pclk_ok(channel, timings->pixelclock))
3066 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303067
3068 if (dss_mgr_is_lcd(channel)) {
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03003069 /* TODO: OMAP4+ supports interlace for LCD outputs */
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003070 if (timings->interlace)
3071 return false;
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03003072
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003073 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303074 timings->hbp, timings->vsw, timings->vfp,
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003075 timings->vbp))
3076 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303077 }
Archit Taneja8f366162012-04-16 12:53:44 +05303078
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003079 return true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003080}
3081
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003082static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
Archit Taneja655e2942012-06-21 10:37:43 +05303083 int hfp, int hbp, int vsw, int vfp, int vbp,
3084 enum omap_dss_signal_level vsync_level,
3085 enum omap_dss_signal_level hsync_level,
3086 enum omap_dss_signal_edge data_pclk_edge,
3087 enum omap_dss_signal_level de_level,
3088 enum omap_dss_signal_edge sync_pclk_edge)
3089
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003090{
Archit Taneja655e2942012-06-21 10:37:43 +05303091 u32 timing_h, timing_v, l;
Tomi Valkeinened351882014-10-02 17:58:49 +00003092 bool onoff, rf, ipc, vs, hs, de;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003093
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303094 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
3095 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
3096 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
3097 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
3098 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
3099 FLD_VAL(vbp, dispc.feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003100
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003101 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
3102 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05303103
Tomi Valkeinened351882014-10-02 17:58:49 +00003104 switch (vsync_level) {
3105 case OMAPDSS_SIG_ACTIVE_LOW:
3106 vs = true;
3107 break;
3108 case OMAPDSS_SIG_ACTIVE_HIGH:
3109 vs = false;
3110 break;
3111 default:
3112 BUG();
3113 }
3114
3115 switch (hsync_level) {
3116 case OMAPDSS_SIG_ACTIVE_LOW:
3117 hs = true;
3118 break;
3119 case OMAPDSS_SIG_ACTIVE_HIGH:
3120 hs = false;
3121 break;
3122 default:
3123 BUG();
3124 }
3125
3126 switch (de_level) {
3127 case OMAPDSS_SIG_ACTIVE_LOW:
3128 de = true;
3129 break;
3130 case OMAPDSS_SIG_ACTIVE_HIGH:
3131 de = false;
3132 break;
3133 default:
3134 BUG();
3135 }
3136
Archit Taneja655e2942012-06-21 10:37:43 +05303137 switch (data_pclk_edge) {
3138 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3139 ipc = false;
3140 break;
3141 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3142 ipc = true;
3143 break;
Archit Taneja655e2942012-06-21 10:37:43 +05303144 default:
3145 BUG();
3146 }
3147
Tomi Valkeinen7a163602014-10-02 17:58:48 +00003148 /* always use the 'rf' setting */
3149 onoff = true;
3150
Archit Taneja655e2942012-06-21 10:37:43 +05303151 switch (sync_pclk_edge) {
Archit Taneja655e2942012-06-21 10:37:43 +05303152 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
Archit Taneja655e2942012-06-21 10:37:43 +05303153 rf = false;
3154 break;
3155 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
Archit Taneja655e2942012-06-21 10:37:43 +05303156 rf = true;
3157 break;
3158 default:
3159 BUG();
Joe Perchescf6ac4ce2013-10-08 16:23:24 -07003160 }
Archit Taneja655e2942012-06-21 10:37:43 +05303161
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003162 l = FLD_VAL(onoff, 17, 17) |
3163 FLD_VAL(rf, 16, 16) |
Tomi Valkeinened351882014-10-02 17:58:49 +00003164 FLD_VAL(de, 15, 15) |
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003165 FLD_VAL(ipc, 14, 14) |
Tomi Valkeinened351882014-10-02 17:58:49 +00003166 FLD_VAL(hs, 13, 13) |
3167 FLD_VAL(vs, 12, 12);
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003168
Tomi Valkeinene5f80912015-10-21 13:08:59 +03003169 /* always set ALIGN bit when available */
3170 if (dispc.feat->supports_sync_align)
3171 l |= (1 << 18);
3172
Archit Taneja655e2942012-06-21 10:37:43 +05303173 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003174
3175 if (dispc.syscon_pol) {
3176 const int shifts[] = {
3177 [OMAP_DSS_CHANNEL_LCD] = 0,
3178 [OMAP_DSS_CHANNEL_LCD2] = 1,
3179 [OMAP_DSS_CHANNEL_LCD3] = 2,
3180 };
3181
3182 u32 mask, val;
3183
3184 mask = (1 << 0) | (1 << 3) | (1 << 6);
3185 val = (rf << 0) | (ipc << 3) | (onoff << 6);
3186
3187 mask <<= 16 + shifts[channel];
3188 val <<= 16 + shifts[channel];
3189
3190 regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset,
3191 mask, val);
3192 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003193}
3194
3195/* change name to mode? */
Archit Tanejac51d9212012-04-16 12:53:43 +05303196void dispc_mgr_set_timings(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003197 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003198{
3199 unsigned xtot, ytot;
3200 unsigned long ht, vt;
Archit Taneja2aefad42012-05-18 14:36:54 +05303201 struct omap_video_timings t = *timings;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003202
Archit Taneja2aefad42012-05-18 14:36:54 +05303203 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
Archit Tanejac51d9212012-04-16 12:53:43 +05303204
Archit Taneja2aefad42012-05-18 14:36:54 +05303205 if (!dispc_mgr_timings_ok(channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05303206 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003207 return;
3208 }
Archit Tanejac51d9212012-04-16 12:53:43 +05303209
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303210 if (dss_mgr_is_lcd(channel)) {
Archit Taneja2aefad42012-05-18 14:36:54 +05303211 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
Archit Taneja655e2942012-06-21 10:37:43 +05303212 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
3213 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
Archit Tanejac51d9212012-04-16 12:53:43 +05303214
Archit Taneja2aefad42012-05-18 14:36:54 +05303215 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
3216 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
Archit Tanejac51d9212012-04-16 12:53:43 +05303217
Tomi Valkeinend8d789412013-04-10 14:12:14 +03003218 ht = timings->pixelclock / xtot;
3219 vt = timings->pixelclock / xtot / ytot;
Archit Tanejac51d9212012-04-16 12:53:43 +05303220
Tomi Valkeinend8d789412013-04-10 14:12:14 +03003221 DSSDBG("pck %u\n", timings->pixelclock);
Archit Tanejac51d9212012-04-16 12:53:43 +05303222 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Archit Taneja2aefad42012-05-18 14:36:54 +05303223 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
Archit Taneja655e2942012-06-21 10:37:43 +05303224 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3225 t.vsync_level, t.hsync_level, t.data_pclk_edge,
3226 t.de_level, t.sync_pclk_edge);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003227
Archit Tanejac51d9212012-04-16 12:53:43 +05303228 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05303229 } else {
Archit Taneja23c8f882012-06-28 11:15:51 +05303230 if (t.interlace == true)
Archit Taneja2aefad42012-05-18 14:36:54 +05303231 t.y_res /= 2;
Archit Tanejac51d9212012-04-16 12:53:43 +05303232 }
Archit Taneja8f366162012-04-16 12:53:44 +05303233
Archit Taneja2aefad42012-05-18 14:36:54 +05303234 dispc_mgr_set_size(channel, t.x_res, t.y_res);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003235}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003236EXPORT_SYMBOL(dispc_mgr_set_timings);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003237
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003238static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003239 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003240{
3241 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003242 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003243
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003244 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003245 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003246
3247 if (dss_has_feature(FEAT_CORE_CLK_DIV) == false &&
3248 channel == OMAP_DSS_CHANNEL_LCD)
3249 dispc.core_clk_rate = dispc_fclk_rate() / lck_div;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003250}
3251
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003252static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00003253 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003254{
3255 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003256 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003257 *lck_div = FLD_GET(l, 23, 16);
3258 *pck_div = FLD_GET(l, 7, 0);
3259}
3260
3261unsigned long dispc_fclk_rate(void)
3262{
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003263 struct dss_pll *pll;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003264 unsigned long r = 0;
3265
Taneja, Archit66534e82011-03-08 05:50:34 -06003266 switch (dss_get_dispc_clk_source()) {
Archit Taneja89a35e52011-04-12 13:52:23 +05303267 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen5aaee692012-12-12 10:37:03 +02003268 r = dss_get_dispc_clk_rate();
Taneja, Archit66534e82011-03-08 05:50:34 -06003269 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05303270 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003271 pll = dss_pll_find("dsi0");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003272 if (!pll)
3273 pll = dss_pll_find("video0");
3274
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003275 r = pll->cinfo.clkout[0];
Taneja, Archit66534e82011-03-08 05:50:34 -06003276 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05303277 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003278 pll = dss_pll_find("dsi1");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003279 if (!pll)
3280 pll = dss_pll_find("video1");
3281
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003282 r = pll->cinfo.clkout[0];
Archit Taneja5a8b5722011-05-12 17:26:29 +05303283 break;
Taneja, Archit66534e82011-03-08 05:50:34 -06003284 default:
3285 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003286 return 0;
Taneja, Archit66534e82011-03-08 05:50:34 -06003287 }
3288
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003289 return r;
3290}
3291
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003292unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003293{
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003294 struct dss_pll *pll;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003295 int lcd;
3296 unsigned long r;
3297 u32 l;
3298
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003299 if (dss_mgr_is_lcd(channel)) {
3300 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003301
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003302 lcd = FLD_GET(l, 23, 16);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003303
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003304 switch (dss_get_lcd_clk_source(channel)) {
3305 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen5aaee692012-12-12 10:37:03 +02003306 r = dss_get_dispc_clk_rate();
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003307 break;
3308 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003309 pll = dss_pll_find("dsi0");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003310 if (!pll)
3311 pll = dss_pll_find("video0");
3312
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003313 r = pll->cinfo.clkout[0];
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003314 break;
3315 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003316 pll = dss_pll_find("dsi1");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003317 if (!pll)
3318 pll = dss_pll_find("video1");
3319
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003320 r = pll->cinfo.clkout[0];
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003321 break;
3322 default:
3323 BUG();
3324 return 0;
3325 }
3326
3327 return r / lcd;
3328 } else {
3329 return dispc_fclk_rate();
Taneja, Architea751592011-03-08 05:50:35 -06003330 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003331}
3332
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003333unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003334{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003335 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003336
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303337 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303338 int pcd;
3339 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003340
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303341 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003342
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303343 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003344
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303345 r = dispc_mgr_lclk_rate(channel);
3346
3347 return r / pcd;
3348 } else {
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003349 return dispc.tv_pclk_rate;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303350 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003351}
3352
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003353void dispc_set_tv_pclk(unsigned long pclk)
3354{
3355 dispc.tv_pclk_rate = pclk;
3356}
3357
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303358unsigned long dispc_core_clk_rate(void)
3359{
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003360 return dispc.core_clk_rate;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303361}
3362
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303363static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3364{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003365 enum omap_channel channel;
3366
3367 if (plane == OMAP_DSS_WB)
3368 return 0;
3369
3370 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303371
3372 return dispc_mgr_pclk_rate(channel);
3373}
3374
3375static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3376{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003377 enum omap_channel channel;
3378
3379 if (plane == OMAP_DSS_WB)
3380 return 0;
3381
3382 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303383
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003384 return dispc_mgr_lclk_rate(channel);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303385}
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003386
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303387static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003388{
3389 int lcd, pcd;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303390 enum omap_dss_clk_source lcd_clk_src;
3391
3392 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3393
3394 lcd_clk_src = dss_get_lcd_clk_source(channel);
3395
3396 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3397 dss_get_generic_clk_source_name(lcd_clk_src),
3398 dss_feat_get_clk_source_name(lcd_clk_src));
3399
3400 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3401
3402 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3403 dispc_mgr_lclk_rate(channel), lcd);
3404 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3405 dispc_mgr_pclk_rate(channel), pcd);
3406}
3407
3408void dispc_dump_clocks(struct seq_file *s)
3409{
3410 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003411 u32 l;
Archit Taneja89a35e52011-04-12 13:52:23 +05303412 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003413
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003414 if (dispc_runtime_get())
3415 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003416
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003417 seq_printf(s, "- DISPC -\n");
3418
Archit Taneja067a57e2011-03-02 11:57:25 +05303419 seq_printf(s, "dispc fclk source = %s (%s)\n",
3420 dss_get_generic_clk_source_name(dispc_clk_src),
3421 dss_feat_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003422
3423 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00003424
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003425 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3426 seq_printf(s, "- DISPC-CORE-CLK -\n");
3427 l = dispc_read_reg(DISPC_DIVISOR);
3428 lcd = FLD_GET(l, 23, 16);
3429
3430 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3431 (dispc_fclk_rate()/lcd), lcd);
3432 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003433
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303434 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003435
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303436 if (dss_has_feature(FEAT_MGR_LCD2))
3437 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3438 if (dss_has_feature(FEAT_MGR_LCD3))
3439 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003440
3441 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003442}
3443
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003444static void dispc_dump_regs(struct seq_file *s)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003445{
Archit Taneja4dd2da12011-08-05 19:06:01 +05303446 int i, j;
3447 const char *mgr_names[] = {
3448 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3449 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3450 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303451 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303452 };
3453 const char *ovl_names[] = {
3454 [OMAP_DSS_GFX] = "GFX",
3455 [OMAP_DSS_VIDEO1] = "VID1",
3456 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303457 [OMAP_DSS_VIDEO3] = "VID3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303458 };
3459 const char **p_names;
3460
Archit Taneja9b372c22011-05-06 11:45:49 +05303461#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003462
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003463 if (dispc_runtime_get())
3464 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003465
Archit Taneja5010be82011-08-05 19:06:00 +05303466 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003467 DUMPREG(DISPC_REVISION);
3468 DUMPREG(DISPC_SYSCONFIG);
3469 DUMPREG(DISPC_SYSSTATUS);
3470 DUMPREG(DISPC_IRQSTATUS);
3471 DUMPREG(DISPC_IRQENABLE);
3472 DUMPREG(DISPC_CONTROL);
3473 DUMPREG(DISPC_CONFIG);
3474 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003475 DUMPREG(DISPC_LINE_STATUS);
3476 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05303477 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3478 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003479 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003480 if (dss_has_feature(FEAT_MGR_LCD2)) {
3481 DUMPREG(DISPC_CONTROL2);
3482 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003483 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303484 if (dss_has_feature(FEAT_MGR_LCD3)) {
3485 DUMPREG(DISPC_CONTROL3);
3486 DUMPREG(DISPC_CONFIG3);
3487 }
Tomi Valkeinen29fceee2013-11-14 11:38:25 +02003488 if (dss_has_feature(FEAT_MFLAG))
3489 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003490
Archit Taneja5010be82011-08-05 19:06:00 +05303491#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003492
Archit Taneja5010be82011-08-05 19:06:00 +05303493#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05303494#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003495 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303496 dispc_read_reg(DISPC_REG(i, r)))
3497
Archit Taneja4dd2da12011-08-05 19:06:01 +05303498 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303499
Archit Taneja4dd2da12011-08-05 19:06:01 +05303500 /* DISPC channel specific registers */
3501 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3502 DUMPREG(i, DISPC_DEFAULT_COLOR);
3503 DUMPREG(i, DISPC_TRANS_COLOR);
3504 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003505
Archit Taneja4dd2da12011-08-05 19:06:01 +05303506 if (i == OMAP_DSS_CHANNEL_DIGIT)
3507 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303508
Archit Taneja4dd2da12011-08-05 19:06:01 +05303509 DUMPREG(i, DISPC_TIMING_H);
3510 DUMPREG(i, DISPC_TIMING_V);
3511 DUMPREG(i, DISPC_POL_FREQ);
3512 DUMPREG(i, DISPC_DIVISORo);
Archit Taneja5010be82011-08-05 19:06:00 +05303513
Archit Taneja4dd2da12011-08-05 19:06:01 +05303514 DUMPREG(i, DISPC_DATA_CYCLE1);
3515 DUMPREG(i, DISPC_DATA_CYCLE2);
3516 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003517
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003518 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303519 DUMPREG(i, DISPC_CPR_COEF_R);
3520 DUMPREG(i, DISPC_CPR_COEF_G);
3521 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003522 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003523 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003524
Archit Taneja4dd2da12011-08-05 19:06:01 +05303525 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003526
Archit Taneja4dd2da12011-08-05 19:06:01 +05303527 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3528 DUMPREG(i, DISPC_OVL_BA0);
3529 DUMPREG(i, DISPC_OVL_BA1);
3530 DUMPREG(i, DISPC_OVL_POSITION);
3531 DUMPREG(i, DISPC_OVL_SIZE);
3532 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3533 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3534 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3535 DUMPREG(i, DISPC_OVL_ROW_INC);
3536 DUMPREG(i, DISPC_OVL_PIXEL_INC);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003537
Archit Taneja4dd2da12011-08-05 19:06:01 +05303538 if (dss_has_feature(FEAT_PRELOAD))
3539 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003540 if (dss_has_feature(FEAT_MFLAG))
3541 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003542
Archit Taneja4dd2da12011-08-05 19:06:01 +05303543 if (i == OMAP_DSS_GFX) {
3544 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3545 DUMPREG(i, DISPC_OVL_TABLE_BA);
3546 continue;
3547 }
3548
3549 DUMPREG(i, DISPC_OVL_FIR);
3550 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3551 DUMPREG(i, DISPC_OVL_ACCU0);
3552 DUMPREG(i, DISPC_OVL_ACCU1);
3553 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3554 DUMPREG(i, DISPC_OVL_BA0_UV);
3555 DUMPREG(i, DISPC_OVL_BA1_UV);
3556 DUMPREG(i, DISPC_OVL_FIR2);
3557 DUMPREG(i, DISPC_OVL_ACCU2_0);
3558 DUMPREG(i, DISPC_OVL_ACCU2_1);
3559 }
3560 if (dss_has_feature(FEAT_ATTR2))
3561 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
Archit Taneja5010be82011-08-05 19:06:00 +05303562 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003563
Archit Taneja5010be82011-08-05 19:06:00 +05303564#undef DISPC_REG
3565#undef DUMPREG
3566
3567#define DISPC_REG(plane, name, i) name(plane, i)
3568#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303569 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003570 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303571 dispc_read_reg(DISPC_REG(plane, name, i)))
3572
Archit Taneja4dd2da12011-08-05 19:06:01 +05303573 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303574
Archit Taneja4dd2da12011-08-05 19:06:01 +05303575 /* start from OMAP_DSS_VIDEO1 */
3576 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3577 for (j = 0; j < 8; j++)
3578 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303579
Archit Taneja4dd2da12011-08-05 19:06:01 +05303580 for (j = 0; j < 8; j++)
3581 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303582
Archit Taneja4dd2da12011-08-05 19:06:01 +05303583 for (j = 0; j < 5; j++)
3584 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003585
Archit Taneja4dd2da12011-08-05 19:06:01 +05303586 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3587 for (j = 0; j < 8; j++)
3588 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3589 }
Amber Jainab5ca072011-05-19 19:47:53 +05303590
Archit Taneja4dd2da12011-08-05 19:06:01 +05303591 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3592 for (j = 0; j < 8; j++)
3593 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303594
Archit Taneja4dd2da12011-08-05 19:06:01 +05303595 for (j = 0; j < 8; j++)
3596 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303597
Archit Taneja4dd2da12011-08-05 19:06:01 +05303598 for (j = 0; j < 8; j++)
3599 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3600 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003601 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003602
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003603 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05303604
3605#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003606#undef DUMPREG
3607}
3608
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003609/* calculate clock rates using dividers in cinfo */
3610int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3611 struct dispc_clock_info *cinfo)
3612{
3613 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3614 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003615 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003616 return -EINVAL;
3617
3618 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3619 cinfo->pck = cinfo->lck / cinfo->pck_div;
3620
3621 return 0;
3622}
3623
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003624bool dispc_div_calc(unsigned long dispc,
3625 unsigned long pck_min, unsigned long pck_max,
3626 dispc_div_calc_func func, void *data)
3627{
3628 int lckd, lckd_start, lckd_stop;
3629 int pckd, pckd_start, pckd_stop;
3630 unsigned long pck, lck;
3631 unsigned long lck_max;
3632 unsigned long pckd_hw_min, pckd_hw_max;
3633 unsigned min_fck_per_pck;
3634 unsigned long fck;
3635
3636#ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3637 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3638#else
3639 min_fck_per_pck = 0;
3640#endif
3641
3642 pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3643 pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3644
3645 lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
3646
3647 pck_min = pck_min ? pck_min : 1;
3648 pck_max = pck_max ? pck_max : ULONG_MAX;
3649
3650 lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul);
3651 lckd_stop = min(dispc / pck_min, 255ul);
3652
3653 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3654 lck = dispc / lckd;
3655
3656 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3657 pckd_stop = min(lck / pck_min, pckd_hw_max);
3658
3659 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3660 pck = lck / pckd;
3661
3662 /*
3663 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3664 * clock, which means we're configuring DISPC fclk here
3665 * also. Thus we need to use the calculated lck. For
3666 * OMAP4+ the DISPC fclk is a separate clock.
3667 */
3668 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3669 fck = dispc_core_clk_rate();
3670 else
3671 fck = lck;
3672
3673 if (fck < pck * min_fck_per_pck)
3674 continue;
3675
3676 if (func(lckd, pckd, lck, pck, data))
3677 return true;
3678 }
3679 }
3680
3681 return false;
3682}
3683
Archit Tanejaf0d08f82012-06-29 14:00:54 +05303684void dispc_mgr_set_clock_div(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003685 const struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003686{
3687 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3688 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3689
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003690 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003691}
3692
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003693int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003694 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003695{
3696 unsigned long fck;
3697
3698 fck = dispc_fclk_rate();
3699
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003700 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3701 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003702
3703 cinfo->lck = fck / cinfo->lck_div;
3704 cinfo->pck = cinfo->lck / cinfo->pck_div;
3705
3706 return 0;
3707}
3708
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003709u32 dispc_read_irqstatus(void)
3710{
3711 return dispc_read_reg(DISPC_IRQSTATUS);
3712}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003713EXPORT_SYMBOL(dispc_read_irqstatus);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003714
3715void dispc_clear_irqstatus(u32 mask)
3716{
3717 dispc_write_reg(DISPC_IRQSTATUS, mask);
3718}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003719EXPORT_SYMBOL(dispc_clear_irqstatus);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003720
3721u32 dispc_read_irqenable(void)
3722{
3723 return dispc_read_reg(DISPC_IRQENABLE);
3724}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003725EXPORT_SYMBOL(dispc_read_irqenable);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003726
3727void dispc_write_irqenable(u32 mask)
3728{
3729 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3730
3731 /* clear the irqstatus for newly enabled irqs */
3732 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3733
3734 dispc_write_reg(DISPC_IRQENABLE, mask);
3735}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003736EXPORT_SYMBOL(dispc_write_irqenable);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003737
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003738void dispc_enable_sidle(void)
3739{
3740 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3741}
3742
3743void dispc_disable_sidle(void)
3744{
3745 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3746}
3747
3748static void _omap_dispc_initial_config(void)
3749{
3750 u32 l;
3751
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003752 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3753 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3754 l = dispc_read_reg(DISPC_DIVISOR);
3755 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3756 l = FLD_MOD(l, 1, 0, 0);
3757 l = FLD_MOD(l, 1, 23, 16);
3758 dispc_write_reg(DISPC_DIVISOR, l);
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003759
3760 dispc.core_clk_rate = dispc_fclk_rate();
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003761 }
3762
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003763 /* FUNCGATED */
Archit Taneja6ced40b2010-12-02 11:27:13 +00003764 if (dss_has_feature(FEAT_FUNCGATED))
3765 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003766
Archit Taneja6e5264b2012-09-11 12:04:47 +05303767 dispc_setup_color_conv_coef();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003768
3769 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3770
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003771 dispc_init_fifos();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003772
3773 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05303774
3775 dispc_ovl_enable_zorder_planes();
Archit Tanejad0df9a22013-03-26 19:15:25 +05303776
3777 if (dispc.feat->mstandby_workaround)
3778 REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0);
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00003779
3780 if (dss_has_feature(FEAT_MFLAG))
3781 dispc_init_mflag();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003782}
3783
Tomi Valkeinenede92692015-06-04 14:12:16 +03003784static const struct dispc_features omap24xx_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303785 .sw_start = 5,
3786 .fp_start = 15,
3787 .bp_start = 27,
3788 .sw_max = 64,
3789 .vp_max = 255,
3790 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303791 .mgr_width_start = 10,
3792 .mgr_height_start = 26,
3793 .mgr_width_max = 2048,
3794 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303795 .max_lcd_pclk = 66500000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303796 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3797 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003798 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003799 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303800 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003801 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303802};
3803
Tomi Valkeinenede92692015-06-04 14:12:16 +03003804static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303805 .sw_start = 5,
3806 .fp_start = 15,
3807 .bp_start = 27,
3808 .sw_max = 64,
3809 .vp_max = 255,
3810 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303811 .mgr_width_start = 10,
3812 .mgr_height_start = 26,
3813 .mgr_width_max = 2048,
3814 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303815 .max_lcd_pclk = 173000000,
3816 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303817 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3818 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003819 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003820 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303821 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003822 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303823};
3824
Tomi Valkeinenede92692015-06-04 14:12:16 +03003825static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303826 .sw_start = 7,
3827 .fp_start = 19,
3828 .bp_start = 31,
3829 .sw_max = 256,
3830 .vp_max = 4095,
3831 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303832 .mgr_width_start = 10,
3833 .mgr_height_start = 26,
3834 .mgr_width_max = 2048,
3835 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303836 .max_lcd_pclk = 173000000,
3837 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303838 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3839 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003840 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003841 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303842 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003843 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303844};
3845
Tomi Valkeinenede92692015-06-04 14:12:16 +03003846static const struct dispc_features omap44xx_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303847 .sw_start = 7,
3848 .fp_start = 19,
3849 .bp_start = 31,
3850 .sw_max = 256,
3851 .vp_max = 4095,
3852 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303853 .mgr_width_start = 10,
3854 .mgr_height_start = 26,
3855 .mgr_width_max = 2048,
3856 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303857 .max_lcd_pclk = 170000000,
3858 .max_tv_pclk = 185625000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303859 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3860 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003861 .num_fifos = 5,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03003862 .gfx_fifo_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303863 .set_max_preload = true,
Tomi Valkeinene5f80912015-10-21 13:08:59 +03003864 .supports_sync_align = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303865};
3866
Tomi Valkeinenede92692015-06-04 14:12:16 +03003867static const struct dispc_features omap54xx_dispc_feats = {
Archit Taneja264236f2012-11-14 13:50:16 +05303868 .sw_start = 7,
3869 .fp_start = 19,
3870 .bp_start = 31,
3871 .sw_max = 256,
3872 .vp_max = 4095,
3873 .hp_max = 4096,
3874 .mgr_width_start = 11,
3875 .mgr_height_start = 27,
3876 .mgr_width_max = 4096,
3877 .mgr_height_max = 4096,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303878 .max_lcd_pclk = 170000000,
3879 .max_tv_pclk = 186000000,
Archit Taneja264236f2012-11-14 13:50:16 +05303880 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3881 .calc_core_clk = calc_core_clk_44xx,
3882 .num_fifos = 5,
3883 .gfx_fifo_workaround = true,
Archit Tanejad0df9a22013-03-26 19:15:25 +05303884 .mstandby_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303885 .set_max_preload = true,
Tomi Valkeinene5f80912015-10-21 13:08:59 +03003886 .supports_sync_align = true,
Archit Taneja264236f2012-11-14 13:50:16 +05303887};
3888
Tomi Valkeinenede92692015-06-04 14:12:16 +03003889static int dispc_init_features(struct platform_device *pdev)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303890{
3891 const struct dispc_features *src;
3892 struct dispc_features *dst;
3893
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003894 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303895 if (!dst) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003896 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303897 return -ENOMEM;
3898 }
3899
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +03003900 switch (omapdss_get_version()) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003901 case OMAPDSS_VER_OMAP24xx:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303902 src = &omap24xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003903 break;
3904
3905 case OMAPDSS_VER_OMAP34xx_ES1:
3906 src = &omap34xx_rev1_0_dispc_feats;
3907 break;
3908
3909 case OMAPDSS_VER_OMAP34xx_ES3:
3910 case OMAPDSS_VER_OMAP3630:
3911 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +05303912 case OMAPDSS_VER_AM43xx:
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003913 src = &omap34xx_rev3_0_dispc_feats;
3914 break;
3915
3916 case OMAPDSS_VER_OMAP4430_ES1:
3917 case OMAPDSS_VER_OMAP4430_ES2:
3918 case OMAPDSS_VER_OMAP4:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303919 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003920 break;
3921
3922 case OMAPDSS_VER_OMAP5:
Tomi Valkeinen93550922014-12-31 11:25:48 +02003923 case OMAPDSS_VER_DRA7xx:
Archit Taneja264236f2012-11-14 13:50:16 +05303924 src = &omap54xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003925 break;
3926
3927 default:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303928 return -ENODEV;
3929 }
3930
3931 memcpy(dst, src, sizeof(*dst));
3932 dispc.feat = dst;
3933
3934 return 0;
3935}
3936
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003937static irqreturn_t dispc_irq_handler(int irq, void *arg)
3938{
3939 if (!dispc.is_enabled)
3940 return IRQ_NONE;
3941
3942 return dispc.user_handler(irq, dispc.user_data);
3943}
3944
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003945int dispc_request_irq(irq_handler_t handler, void *dev_id)
3946{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003947 int r;
3948
3949 if (dispc.user_handler != NULL)
3950 return -EBUSY;
3951
3952 dispc.user_handler = handler;
3953 dispc.user_data = dev_id;
3954
3955 /* ensure the dispc_irq_handler sees the values above */
3956 smp_wmb();
3957
3958 r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler,
3959 IRQF_SHARED, "OMAP DISPC", &dispc);
3960 if (r) {
3961 dispc.user_handler = NULL;
3962 dispc.user_data = NULL;
3963 }
3964
3965 return r;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003966}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003967EXPORT_SYMBOL(dispc_request_irq);
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003968
3969void dispc_free_irq(void *dev_id)
3970{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003971 devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc);
3972
3973 dispc.user_handler = NULL;
3974 dispc.user_data = NULL;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003975}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003976EXPORT_SYMBOL(dispc_free_irq);
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003977
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003978/* DISPC HW IP initialisation */
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03003979static int dispc_bind(struct device *dev, struct device *master, void *data)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003980{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03003981 struct platform_device *pdev = to_platform_device(dev);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003982 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00003983 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003984 struct resource *dispc_mem;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003985 struct device_node *np = pdev->dev.of_node;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003986
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003987 dispc.pdev = pdev;
3988
Tomi Valkeinend49cd152014-11-10 12:23:00 +02003989 spin_lock_init(&dispc.control_lock);
3990
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003991 r = dispc_init_features(dispc.pdev);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303992 if (r)
3993 return r;
3994
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003995 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3996 if (!dispc_mem) {
3997 DSSERR("can't get IORESOURCE_MEM DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003998 return -EINVAL;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003999 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004000
Julia Lawall6e2a14d2012-01-24 14:00:45 +01004001 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
4002 resource_size(dispc_mem));
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004003 if (!dispc.base) {
4004 DSSERR("can't ioremap DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004005 return -ENOMEM;
archit tanejaaffe3602011-02-23 08:41:03 +00004006 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004007
archit tanejaaffe3602011-02-23 08:41:03 +00004008 dispc.irq = platform_get_irq(dispc.pdev, 0);
4009 if (dispc.irq < 0) {
4010 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004011 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00004012 }
4013
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004014 if (np && of_property_read_bool(np, "syscon-pol")) {
4015 dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
4016 if (IS_ERR(dispc.syscon_pol)) {
4017 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
4018 return PTR_ERR(dispc.syscon_pol);
4019 }
4020
4021 if (of_property_read_u32_index(np, "syscon-pol", 1,
4022 &dispc.syscon_pol_offset)) {
4023 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
4024 return -EINVAL;
4025 }
4026 }
4027
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004028 pm_runtime_enable(&pdev->dev);
4029
4030 r = dispc_runtime_get();
4031 if (r)
4032 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004033
4034 _omap_dispc_initial_config();
4035
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004036 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00004037 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004038 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4039
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004040 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004041
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03004042 dss_init_overlay_managers();
4043
Tomi Valkeinene40402c2012-03-02 18:01:07 +02004044 dss_debugfs_create_file("dispc", dispc_dump_regs);
4045
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004046 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004047
4048err_runtime_get:
4049 pm_runtime_disable(&pdev->dev);
archit tanejaaffe3602011-02-23 08:41:03 +00004050 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004051}
4052
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004053static void dispc_unbind(struct device *dev, struct device *master,
4054 void *data)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004055{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004056 pm_runtime_disable(dev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004057
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03004058 dss_uninit_overlay_managers();
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004059}
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03004060
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004061static const struct component_ops dispc_component_ops = {
4062 .bind = dispc_bind,
4063 .unbind = dispc_unbind,
4064};
4065
4066static int dispc_probe(struct platform_device *pdev)
4067{
4068 return component_add(&pdev->dev, &dispc_component_ops);
4069}
4070
4071static int dispc_remove(struct platform_device *pdev)
4072{
4073 component_del(&pdev->dev, &dispc_component_ops);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004074 return 0;
4075}
4076
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004077static int dispc_runtime_suspend(struct device *dev)
4078{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004079 dispc.is_enabled = false;
4080 /* ensure the dispc_irq_handler sees the is_enabled value */
4081 smp_wmb();
4082 /* wait for current handler to finish before turning the DISPC off */
4083 synchronize_irq(dispc.irq);
4084
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004085 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004086
4087 return 0;
4088}
4089
4090static int dispc_runtime_resume(struct device *dev)
4091{
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004092 /*
4093 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4094 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4095 * _omap_dispc_initial_config(). We can thus use it to detect if
4096 * we have lost register context.
4097 */
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004098 if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
4099 _omap_dispc_initial_config();
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004100
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004101 dispc_restore_context();
4102 }
Tomi Valkeinenbe07dcd72013-11-21 16:01:40 +02004103
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004104 dispc.is_enabled = true;
4105 /* ensure the dispc_irq_handler sees the is_enabled value */
4106 smp_wmb();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004107
4108 return 0;
4109}
4110
4111static const struct dev_pm_ops dispc_pm_ops = {
4112 .runtime_suspend = dispc_runtime_suspend,
4113 .runtime_resume = dispc_runtime_resume,
4114};
4115
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004116static const struct of_device_id dispc_of_match[] = {
4117 { .compatible = "ti,omap2-dispc", },
4118 { .compatible = "ti,omap3-dispc", },
4119 { .compatible = "ti,omap4-dispc", },
Tomi Valkeinen2e7e6b62014-04-16 13:16:43 +03004120 { .compatible = "ti,omap5-dispc", },
Tomi Valkeinen93550922014-12-31 11:25:48 +02004121 { .compatible = "ti,dra7-dispc", },
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004122 {},
4123};
4124
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004125static struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004126 .probe = dispc_probe,
4127 .remove = dispc_remove,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004128 .driver = {
4129 .name = "omapdss_dispc",
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004130 .pm = &dispc_pm_ops,
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004131 .of_match_table = dispc_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +03004132 .suppress_bind_attrs = true,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004133 },
4134};
4135
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004136int __init dispc_init_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004137{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004138 return platform_driver_register(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004139}
4140
Tomi Valkeinenede92692015-06-04 14:12:16 +03004141void dispc_uninit_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004142{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02004143 platform_driver_unregister(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004144}