blob: 6b056d0ce18743c03b91ea8ca0b4c02044fb5c00 [file] [log] [blame]
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001/*
2 * linux/drivers/video/omap2/dss/dispc.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#define DSS_SUBSYS_NAME "DISPC"
24
25#include <linux/kernel.h>
26#include <linux/dma-mapping.h>
27#include <linux/vmalloc.h>
Paul Gortmakera8a35932011-07-10 13:20:26 -040028#include <linux/export.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020029#include <linux/clk.h>
30#include <linux/io.h>
31#include <linux/jiffies.h>
32#include <linux/seq_file.h>
33#include <linux/delay.h>
34#include <linux/workqueue.h>
Tomi Valkeinenab83b142010-06-09 15:31:01 +030035#include <linux/hardirq.h>
Tomi Valkeinen24e62892011-05-23 11:51:18 +030036#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030037#include <linux/pm_runtime.h>
Tomi Valkeinen33366d02012-09-28 13:54:35 +030038#include <linux/sizes.h>
Tomi Valkeinen0006fd62014-09-05 19:15:03 +000039#include <linux/mfd/syscon.h>
40#include <linux/regmap.h>
41#include <linux/of.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020042
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030043#include <video/omapdss.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020044
45#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053046#include "dss_features.h"
Archit Taneja9b372c22011-05-06 11:45:49 +053047#include "dispc.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020048
49/* DISPC */
Sumit Semwal8613b002010-12-02 11:27:09 +000050#define DISPC_SZ_REGS SZ_4K
Tomi Valkeinen80c39712009-11-12 11:41:42 +020051
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030052enum omap_burst_size {
53 BURST_SIZE_X2 = 0,
54 BURST_SIZE_X4 = 1,
55 BURST_SIZE_X8 = 2,
56};
57
Tomi Valkeinen80c39712009-11-12 11:41:42 +020058#define REG_GET(idx, start, end) \
59 FLD_GET(dispc_read_reg(idx), start, end)
60
61#define REG_FLD_MOD(idx, val, start, end) \
62 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
63
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053064struct dispc_features {
65 u8 sw_start;
66 u8 fp_start;
67 u8 bp_start;
68 u16 sw_max;
69 u16 vp_max;
70 u16 hp_max;
Archit Taneja33b89922012-11-14 13:50:15 +053071 u8 mgr_width_start;
72 u8 mgr_height_start;
73 u16 mgr_width_max;
74 u16 mgr_height_max;
Archit Tanejaca5ca692013-03-26 19:15:22 +053075 unsigned long max_lcd_pclk;
76 unsigned long max_tv_pclk;
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +030077 int (*calc_scaling) (unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053078 const struct omap_video_timings *mgr_timings,
79 u16 width, u16 height, u16 out_width, u16 out_height,
80 enum omap_color_mode color_mode, bool *five_taps,
81 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +053082 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
Tomi Valkeinen8702ee52012-10-19 15:36:11 +030083 unsigned long (*calc_core_clk) (unsigned long pclk,
Archit Taneja8ba85302012-09-26 17:00:37 +053084 u16 width, u16 height, u16 out_width, u16 out_height,
85 bool mem_to_mem);
Tomi Valkeinen42a69612012-08-22 16:56:57 +030086 u8 num_fifos;
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +030087
88 /* swap GFX & WB fifos */
89 bool gfx_fifo_workaround:1;
Tomi Valkeinencffa9472012-11-08 10:01:33 +020090
91 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
92 bool no_framedone_tv:1;
Archit Tanejad0df9a22013-03-26 19:15:25 +053093
94 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
95 bool mstandby_workaround:1;
Archit Taneja8bc65552013-12-17 16:40:21 +053096
97 bool set_max_preload:1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053098};
99
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300100#define DISPC_MAX_NR_FIFOS 5
101
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200102static struct {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +0000103 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200104 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300105
archit tanejaaffe3602011-02-23 08:41:03 +0000106 int irq;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300107 irq_handler_t user_handler;
108 void *user_data;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200109
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200110 unsigned long core_clk_rate;
Tomi Valkeinen5391e872013-05-16 10:44:13 +0300111 unsigned long tv_pclk_rate;
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200112
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300113 u32 fifo_size[DISPC_MAX_NR_FIFOS];
114 /* maps which plane is using a fifo. fifo-id -> plane-id */
115 int fifo_assignment[DISPC_MAX_NR_FIFOS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200116
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300117 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200118 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200119
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530120 const struct dispc_features *feat;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300121
122 bool is_enabled;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +0000123
124 struct regmap *syscon_pol;
125 u32 syscon_pol_offset;
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200126
127 /* DISPC_CONTROL & DISPC_CONFIG lock*/
128 spinlock_t control_lock;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200129} dispc;
130
Amber Jain0d66cbb2011-05-19 19:47:54 +0530131enum omap_color_component {
132 /* used for all color formats for OMAP3 and earlier
133 * and for RGB and Y color component on OMAP4
134 */
135 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
136 /* used for UV component for
137 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
138 * color formats on OMAP4
139 */
140 DISPC_COLOR_COMPONENT_UV = 1 << 1,
141};
142
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530143enum mgr_reg_fields {
144 DISPC_MGR_FLD_ENABLE,
145 DISPC_MGR_FLD_STNTFT,
146 DISPC_MGR_FLD_GO,
147 DISPC_MGR_FLD_TFTDATALINES,
148 DISPC_MGR_FLD_STALLMODE,
149 DISPC_MGR_FLD_TCKENABLE,
150 DISPC_MGR_FLD_TCKSELECTION,
151 DISPC_MGR_FLD_CPR,
152 DISPC_MGR_FLD_FIFOHANDCHECK,
153 /* used to maintain a count of the above fields */
154 DISPC_MGR_FLD_NUM,
155};
156
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300157struct dispc_reg_field {
158 u16 reg;
159 u8 high;
160 u8 low;
161};
162
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530163static const struct {
164 const char *name;
165 u32 vsync_irq;
166 u32 framedone_irq;
167 u32 sync_lost_irq;
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300168 struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530169} mgr_desc[] = {
170 [OMAP_DSS_CHANNEL_LCD] = {
171 .name = "LCD",
172 .vsync_irq = DISPC_IRQ_VSYNC,
173 .framedone_irq = DISPC_IRQ_FRAMEDONE,
174 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
175 .reg_desc = {
176 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
177 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
178 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
179 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
180 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
181 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
182 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
183 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
184 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
185 },
186 },
187 [OMAP_DSS_CHANNEL_DIGIT] = {
188 .name = "DIGIT",
189 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200190 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530191 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
192 .reg_desc = {
193 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
194 [DISPC_MGR_FLD_STNTFT] = { },
195 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
196 [DISPC_MGR_FLD_TFTDATALINES] = { },
197 [DISPC_MGR_FLD_STALLMODE] = { },
198 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
199 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
200 [DISPC_MGR_FLD_CPR] = { },
201 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
202 },
203 },
204 [OMAP_DSS_CHANNEL_LCD2] = {
205 .name = "LCD2",
206 .vsync_irq = DISPC_IRQ_VSYNC2,
207 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
208 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
209 .reg_desc = {
210 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
211 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
212 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
213 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
214 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
215 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
216 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
217 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
218 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
219 },
220 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530221 [OMAP_DSS_CHANNEL_LCD3] = {
222 .name = "LCD3",
223 .vsync_irq = DISPC_IRQ_VSYNC3,
224 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
225 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
226 .reg_desc = {
227 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
228 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
229 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
230 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
231 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
232 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
233 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
234 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
235 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
236 },
237 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530238};
239
Archit Taneja6e5264b2012-09-11 12:04:47 +0530240struct color_conv_coef {
241 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
242 int full_range;
243};
244
Archit Taneja3e8a6ff2012-09-26 16:58:52 +0530245static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
246static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200247
Archit Taneja55978cc2011-05-06 11:45:51 +0530248static inline void dispc_write_reg(const u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200249{
Archit Taneja55978cc2011-05-06 11:45:51 +0530250 __raw_writel(val, dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200251}
252
Archit Taneja55978cc2011-05-06 11:45:51 +0530253static inline u32 dispc_read_reg(const u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200254{
Archit Taneja55978cc2011-05-06 11:45:51 +0530255 return __raw_readl(dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200256}
257
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530258static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
259{
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300260 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530261 return REG_GET(rfld.reg, rfld.high, rfld.low);
262}
263
264static void mgr_fld_write(enum omap_channel channel,
265 enum mgr_reg_fields regfld, int val) {
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300266 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200267 const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG;
268 unsigned long flags;
269
270 if (need_lock)
271 spin_lock_irqsave(&dispc.control_lock, flags);
272
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530273 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200274
275 if (need_lock)
276 spin_unlock_irqrestore(&dispc.control_lock, flags);
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530277}
278
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200279#define SR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530280 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200281#define RR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530282 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200283
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300284static void dispc_save_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200285{
Archit Tanejac6104b82011-08-05 19:06:02 +0530286 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200287
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300288 DSSDBG("dispc_save_context\n");
289
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200290 SR(IRQENABLE);
291 SR(CONTROL);
292 SR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200293 SR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530294 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
295 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300296 SR(GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000297 if (dss_has_feature(FEAT_MGR_LCD2)) {
298 SR(CONTROL2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000299 SR(CONFIG2);
300 }
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530301 if (dss_has_feature(FEAT_MGR_LCD3)) {
302 SR(CONTROL3);
303 SR(CONFIG3);
304 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200305
Archit Tanejac6104b82011-08-05 19:06:02 +0530306 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
307 SR(DEFAULT_COLOR(i));
308 SR(TRANS_COLOR(i));
309 SR(SIZE_MGR(i));
310 if (i == OMAP_DSS_CHANNEL_DIGIT)
311 continue;
312 SR(TIMING_H(i));
313 SR(TIMING_V(i));
314 SR(POL_FREQ(i));
315 SR(DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200316
Archit Tanejac6104b82011-08-05 19:06:02 +0530317 SR(DATA_CYCLE1(i));
318 SR(DATA_CYCLE2(i));
319 SR(DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200320
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300321 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530322 SR(CPR_COEF_R(i));
323 SR(CPR_COEF_G(i));
324 SR(CPR_COEF_B(i));
325 }
326 }
327
328 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
329 SR(OVL_BA0(i));
330 SR(OVL_BA1(i));
331 SR(OVL_POSITION(i));
332 SR(OVL_SIZE(i));
333 SR(OVL_ATTRIBUTES(i));
334 SR(OVL_FIFO_THRESHOLD(i));
335 SR(OVL_ROW_INC(i));
336 SR(OVL_PIXEL_INC(i));
337 if (dss_has_feature(FEAT_PRELOAD))
338 SR(OVL_PRELOAD(i));
339 if (i == OMAP_DSS_GFX) {
340 SR(OVL_WINDOW_SKIP(i));
341 SR(OVL_TABLE_BA(i));
342 continue;
343 }
344 SR(OVL_FIR(i));
345 SR(OVL_PICTURE_SIZE(i));
346 SR(OVL_ACCU0(i));
347 SR(OVL_ACCU1(i));
348
349 for (j = 0; j < 8; j++)
350 SR(OVL_FIR_COEF_H(i, j));
351
352 for (j = 0; j < 8; j++)
353 SR(OVL_FIR_COEF_HV(i, j));
354
355 for (j = 0; j < 5; j++)
356 SR(OVL_CONV_COEF(i, j));
357
358 if (dss_has_feature(FEAT_FIR_COEF_V)) {
359 for (j = 0; j < 8; j++)
360 SR(OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300361 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000362
Archit Tanejac6104b82011-08-05 19:06:02 +0530363 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
364 SR(OVL_BA0_UV(i));
365 SR(OVL_BA1_UV(i));
366 SR(OVL_FIR2(i));
367 SR(OVL_ACCU2_0(i));
368 SR(OVL_ACCU2_1(i));
369
370 for (j = 0; j < 8; j++)
371 SR(OVL_FIR_COEF_H2(i, j));
372
373 for (j = 0; j < 8; j++)
374 SR(OVL_FIR_COEF_HV2(i, j));
375
376 for (j = 0; j < 8; j++)
377 SR(OVL_FIR_COEF_V2(i, j));
378 }
379 if (dss_has_feature(FEAT_ATTR2))
380 SR(OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000381 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200382
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600383 if (dss_has_feature(FEAT_CORE_CLK_DIV))
384 SR(DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300385
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300386 dispc.ctx_valid = true;
387
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200388 DSSDBG("context saved\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200389}
390
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300391static void dispc_restore_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200392{
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200393 int i, j;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300394
395 DSSDBG("dispc_restore_context\n");
396
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300397 if (!dispc.ctx_valid)
398 return;
399
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200400 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200401 /*RR(CONTROL);*/
402 RR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200403 RR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530404 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
405 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300406 RR(GLOBAL_ALPHA);
Archit Tanejac6104b82011-08-05 19:06:02 +0530407 if (dss_has_feature(FEAT_MGR_LCD2))
Sumit Semwal2a205f32010-12-02 11:27:12 +0000408 RR(CONFIG2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530409 if (dss_has_feature(FEAT_MGR_LCD3))
410 RR(CONFIG3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200411
Archit Tanejac6104b82011-08-05 19:06:02 +0530412 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
413 RR(DEFAULT_COLOR(i));
414 RR(TRANS_COLOR(i));
415 RR(SIZE_MGR(i));
416 if (i == OMAP_DSS_CHANNEL_DIGIT)
417 continue;
418 RR(TIMING_H(i));
419 RR(TIMING_V(i));
420 RR(POL_FREQ(i));
421 RR(DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530422
Archit Tanejac6104b82011-08-05 19:06:02 +0530423 RR(DATA_CYCLE1(i));
424 RR(DATA_CYCLE2(i));
425 RR(DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000426
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300427 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530428 RR(CPR_COEF_R(i));
429 RR(CPR_COEF_G(i));
430 RR(CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300431 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000432 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200433
Archit Tanejac6104b82011-08-05 19:06:02 +0530434 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
435 RR(OVL_BA0(i));
436 RR(OVL_BA1(i));
437 RR(OVL_POSITION(i));
438 RR(OVL_SIZE(i));
439 RR(OVL_ATTRIBUTES(i));
440 RR(OVL_FIFO_THRESHOLD(i));
441 RR(OVL_ROW_INC(i));
442 RR(OVL_PIXEL_INC(i));
443 if (dss_has_feature(FEAT_PRELOAD))
444 RR(OVL_PRELOAD(i));
445 if (i == OMAP_DSS_GFX) {
446 RR(OVL_WINDOW_SKIP(i));
447 RR(OVL_TABLE_BA(i));
448 continue;
449 }
450 RR(OVL_FIR(i));
451 RR(OVL_PICTURE_SIZE(i));
452 RR(OVL_ACCU0(i));
453 RR(OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200454
Archit Tanejac6104b82011-08-05 19:06:02 +0530455 for (j = 0; j < 8; j++)
456 RR(OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200457
Archit Tanejac6104b82011-08-05 19:06:02 +0530458 for (j = 0; j < 8; j++)
459 RR(OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200460
Archit Tanejac6104b82011-08-05 19:06:02 +0530461 for (j = 0; j < 5; j++)
462 RR(OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200463
Archit Tanejac6104b82011-08-05 19:06:02 +0530464 if (dss_has_feature(FEAT_FIR_COEF_V)) {
465 for (j = 0; j < 8; j++)
466 RR(OVL_FIR_COEF_V(i, j));
467 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200468
Archit Tanejac6104b82011-08-05 19:06:02 +0530469 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
470 RR(OVL_BA0_UV(i));
471 RR(OVL_BA1_UV(i));
472 RR(OVL_FIR2(i));
473 RR(OVL_ACCU2_0(i));
474 RR(OVL_ACCU2_1(i));
475
476 for (j = 0; j < 8; j++)
477 RR(OVL_FIR_COEF_H2(i, j));
478
479 for (j = 0; j < 8; j++)
480 RR(OVL_FIR_COEF_HV2(i, j));
481
482 for (j = 0; j < 8; j++)
483 RR(OVL_FIR_COEF_V2(i, j));
484 }
485 if (dss_has_feature(FEAT_ATTR2))
486 RR(OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300487 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200488
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600489 if (dss_has_feature(FEAT_CORE_CLK_DIV))
490 RR(DIVISOR);
491
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200492 /* enable last, because LCD & DIGIT enable are here */
493 RR(CONTROL);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000494 if (dss_has_feature(FEAT_MGR_LCD2))
495 RR(CONTROL2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530496 if (dss_has_feature(FEAT_MGR_LCD3))
497 RR(CONTROL3);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200498 /* clear spurious SYNC_LOST_DIGIT interrupts */
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +0300499 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200500
501 /*
502 * enable last so IRQs won't trigger before
503 * the context is fully restored
504 */
505 RR(IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300506
507 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200508}
509
510#undef SR
511#undef RR
512
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300513int dispc_runtime_get(void)
514{
515 int r;
516
517 DSSDBG("dispc_runtime_get\n");
518
519 r = pm_runtime_get_sync(&dispc.pdev->dev);
520 WARN_ON(r < 0);
521 return r < 0 ? r : 0;
522}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200523EXPORT_SYMBOL(dispc_runtime_get);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300524
525void dispc_runtime_put(void)
526{
527 int r;
528
529 DSSDBG("dispc_runtime_put\n");
530
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200531 r = pm_runtime_put_sync(&dispc.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300532 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300533}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200534EXPORT_SYMBOL(dispc_runtime_put);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300535
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200536u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
537{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530538 return mgr_desc[channel].vsync_irq;
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200539}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200540EXPORT_SYMBOL(dispc_mgr_get_vsync_irq);
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200541
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200542u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
543{
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200544 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv)
545 return 0;
546
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530547 return mgr_desc[channel].framedone_irq;
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200548}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200549EXPORT_SYMBOL(dispc_mgr_get_framedone_irq);
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200550
Tomi Valkeinencb699202012-10-17 10:38:52 +0300551u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
552{
553 return mgr_desc[channel].sync_lost_irq;
554}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200555EXPORT_SYMBOL(dispc_mgr_get_sync_lost_irq);
Tomi Valkeinencb699202012-10-17 10:38:52 +0300556
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530557u32 dispc_wb_get_framedone_irq(void)
558{
559 return DISPC_IRQ_FRAMEDONEWB;
560}
561
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300562bool dispc_mgr_go_busy(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200563{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530564 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200565}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200566EXPORT_SYMBOL(dispc_mgr_go_busy);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200567
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300568void dispc_mgr_go(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200569{
Tomi Valkeinen3c91ee82012-10-19 15:06:07 +0300570 WARN_ON(dispc_mgr_is_enabled(channel) == false);
571 WARN_ON(dispc_mgr_go_busy(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200572
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530573 DSSDBG("GO %s\n", mgr_desc[channel].name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200574
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530575 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200576}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200577EXPORT_SYMBOL(dispc_mgr_go);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200578
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530579bool dispc_wb_go_busy(void)
580{
581 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
582}
583
584void dispc_wb_go(void)
585{
586 enum omap_plane plane = OMAP_DSS_WB;
587 bool enable, go;
588
589 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
590
591 if (!enable)
592 return;
593
594 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
595 if (go) {
596 DSSERR("GO bit not down for WB\n");
597 return;
598 }
599
600 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
601}
602
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300603static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200604{
Archit Taneja9b372c22011-05-06 11:45:49 +0530605 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200606}
607
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300608static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200609{
Archit Taneja9b372c22011-05-06 11:45:49 +0530610 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200611}
612
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300613static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200614{
Archit Taneja9b372c22011-05-06 11:45:49 +0530615 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200616}
617
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300618static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530619{
620 BUG_ON(plane == OMAP_DSS_GFX);
621
622 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
623}
624
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300625static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
626 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530627{
628 BUG_ON(plane == OMAP_DSS_GFX);
629
630 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
631}
632
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300633static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, 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_V2(plane, reg), value);
638}
639
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530640static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
641 int fir_vinc, int five_taps,
642 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200643{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530644 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200645 int i;
646
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530647 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
648 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200649
650 for (i = 0; i < 8; i++) {
651 u32 h, hv;
652
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530653 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
654 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
655 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
656 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
657 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
658 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
659 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
660 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200661
Amber Jain0d66cbb2011-05-19 19:47:54 +0530662 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300663 dispc_ovl_write_firh_reg(plane, i, h);
664 dispc_ovl_write_firhv_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530665 } else {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300666 dispc_ovl_write_firh2_reg(plane, i, h);
667 dispc_ovl_write_firhv2_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530668 }
669
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200670 }
671
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200672 if (five_taps) {
673 for (i = 0; i < 8; i++) {
674 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530675 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
676 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530677 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300678 dispc_ovl_write_firv_reg(plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530679 else
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300680 dispc_ovl_write_firv2_reg(plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200681 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200682 }
683}
684
Archit Taneja6e5264b2012-09-11 12:04:47 +0530685
686static void dispc_ovl_write_color_conv_coef(enum omap_plane plane,
687 const struct color_conv_coef *ct)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200688{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200689#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
690
Archit Taneja6e5264b2012-09-11 12:04:47 +0530691 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
692 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
693 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
694 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
695 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200696
Archit Taneja6e5264b2012-09-11 12:04:47 +0530697 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200698
699#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200700}
701
Archit Taneja6e5264b2012-09-11 12:04:47 +0530702static void dispc_setup_color_conv_coef(void)
703{
704 int i;
705 int num_ovl = dss_feat_get_num_ovls();
706 int num_wb = dss_feat_get_num_wbs();
707 const struct color_conv_coef ctbl_bt601_5_ovl = {
708 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
709 };
710 const struct color_conv_coef ctbl_bt601_5_wb = {
711 66, 112, -38, 129, -94, -74, 25, -18, 112, 0,
712 };
713
714 for (i = 1; i < num_ovl; i++)
715 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
716
717 for (; i < num_wb; i++)
718 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_wb);
719}
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200720
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300721static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200722{
Archit Taneja9b372c22011-05-06 11:45:49 +0530723 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200724}
725
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300726static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200727{
Archit Taneja9b372c22011-05-06 11:45:49 +0530728 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200729}
730
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300731static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530732{
733 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
734}
735
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300736static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530737{
738 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
739}
740
Archit Tanejad79db852012-09-22 12:30:17 +0530741static void dispc_ovl_set_pos(enum omap_plane plane,
742 enum omap_overlay_caps caps, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200743{
Archit Tanejad79db852012-09-22 12:30:17 +0530744 u32 val;
745
746 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
747 return;
748
749 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530750
751 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200752}
753
Archit Taneja78b687f2012-09-21 14:51:49 +0530754static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
755 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200756{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200757 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530758
Archit Taneja36d87d92012-07-28 22:59:03 +0530759 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
Archit Taneja9b372c22011-05-06 11:45:49 +0530760 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
761 else
762 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200763}
764
Archit Taneja78b687f2012-09-21 14:51:49 +0530765static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
766 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200767{
768 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200769
770 BUG_ON(plane == OMAP_DSS_GFX);
771
772 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530773
Archit Taneja36d87d92012-07-28 22:59:03 +0530774 if (plane == OMAP_DSS_WB)
775 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
776 else
777 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200778}
779
Archit Taneja5b54ed32012-09-26 16:55:27 +0530780static void dispc_ovl_set_zorder(enum omap_plane plane,
781 enum omap_overlay_caps caps, u8 zorder)
Archit Taneja54128702011-09-08 11:29:17 +0530782{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530783 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
Archit Taneja54128702011-09-08 11:29:17 +0530784 return;
785
786 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
787}
788
789static void dispc_ovl_enable_zorder_planes(void)
790{
791 int i;
792
793 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
794 return;
795
796 for (i = 0; i < dss_feat_get_num_ovls(); i++)
797 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
798}
799
Archit Taneja5b54ed32012-09-26 16:55:27 +0530800static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
801 enum omap_overlay_caps caps, bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100802{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530803 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100804 return;
805
Archit Taneja9b372c22011-05-06 11:45:49 +0530806 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100807}
808
Archit Taneja5b54ed32012-09-26 16:55:27 +0530809static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
810 enum omap_overlay_caps caps, u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200811{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530812 static const unsigned shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300813 int shift;
814
Archit Taneja5b54ed32012-09-26 16:55:27 +0530815 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100816 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530817
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300818 shift = shifts[plane];
819 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200820}
821
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300822static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200823{
Archit Taneja9b372c22011-05-06 11:45:49 +0530824 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200825}
826
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300827static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200828{
Archit Taneja9b372c22011-05-06 11:45:49 +0530829 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200830}
831
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300832static void dispc_ovl_set_color_mode(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200833 enum omap_color_mode color_mode)
834{
835 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +0530836 if (plane != OMAP_DSS_GFX) {
837 switch (color_mode) {
838 case OMAP_DSS_COLOR_NV12:
839 m = 0x0; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530840 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530841 m = 0x1; break;
842 case OMAP_DSS_COLOR_RGBA16:
843 m = 0x2; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530844 case OMAP_DSS_COLOR_RGB12U:
Amber Jainf20e4222011-05-19 19:47:50 +0530845 m = 0x4; break;
846 case OMAP_DSS_COLOR_ARGB16:
847 m = 0x5; break;
848 case OMAP_DSS_COLOR_RGB16:
849 m = 0x6; break;
850 case OMAP_DSS_COLOR_ARGB16_1555:
851 m = 0x7; break;
852 case OMAP_DSS_COLOR_RGB24U:
853 m = 0x8; break;
854 case OMAP_DSS_COLOR_RGB24P:
855 m = 0x9; break;
856 case OMAP_DSS_COLOR_YUV2:
857 m = 0xa; break;
858 case OMAP_DSS_COLOR_UYVY:
859 m = 0xb; break;
860 case OMAP_DSS_COLOR_ARGB32:
861 m = 0xc; break;
862 case OMAP_DSS_COLOR_RGBA32:
863 m = 0xd; break;
864 case OMAP_DSS_COLOR_RGBX32:
865 m = 0xe; break;
866 case OMAP_DSS_COLOR_XRGB16_1555:
867 m = 0xf; break;
868 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300869 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530870 }
871 } else {
872 switch (color_mode) {
873 case OMAP_DSS_COLOR_CLUT1:
874 m = 0x0; break;
875 case OMAP_DSS_COLOR_CLUT2:
876 m = 0x1; break;
877 case OMAP_DSS_COLOR_CLUT4:
878 m = 0x2; break;
879 case OMAP_DSS_COLOR_CLUT8:
880 m = 0x3; break;
881 case OMAP_DSS_COLOR_RGB12U:
882 m = 0x4; break;
883 case OMAP_DSS_COLOR_ARGB16:
884 m = 0x5; break;
885 case OMAP_DSS_COLOR_RGB16:
886 m = 0x6; break;
887 case OMAP_DSS_COLOR_ARGB16_1555:
888 m = 0x7; break;
889 case OMAP_DSS_COLOR_RGB24U:
890 m = 0x8; break;
891 case OMAP_DSS_COLOR_RGB24P:
892 m = 0x9; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530893 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530894 m = 0xa; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530895 case OMAP_DSS_COLOR_RGBA16:
Amber Jainf20e4222011-05-19 19:47:50 +0530896 m = 0xb; break;
897 case OMAP_DSS_COLOR_ARGB32:
898 m = 0xc; break;
899 case OMAP_DSS_COLOR_RGBA32:
900 m = 0xd; break;
901 case OMAP_DSS_COLOR_RGBX32:
902 m = 0xe; break;
903 case OMAP_DSS_COLOR_XRGB16_1555:
904 m = 0xf; break;
905 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300906 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530907 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200908 }
909
Archit Taneja9b372c22011-05-06 11:45:49 +0530910 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200911}
912
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530913static void dispc_ovl_configure_burst_type(enum omap_plane plane,
914 enum omap_dss_rotation_type rotation_type)
915{
916 if (dss_has_feature(FEAT_BURST_2D) == 0)
917 return;
918
919 if (rotation_type == OMAP_DSS_ROT_TILER)
920 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
921 else
922 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
923}
924
Tomi Valkeinenf4279842011-10-28 15:26:26 +0300925void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200926{
927 int shift;
928 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000929 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200930
931 switch (plane) {
932 case OMAP_DSS_GFX:
933 shift = 8;
934 break;
935 case OMAP_DSS_VIDEO1:
936 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +0530937 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200938 shift = 16;
939 break;
940 default:
941 BUG();
942 return;
943 }
944
Archit Taneja9b372c22011-05-06 11:45:49 +0530945 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000946 if (dss_has_feature(FEAT_MGR_LCD2)) {
947 switch (channel) {
948 case OMAP_DSS_CHANNEL_LCD:
949 chan = 0;
950 chan2 = 0;
951 break;
952 case OMAP_DSS_CHANNEL_DIGIT:
953 chan = 1;
954 chan2 = 0;
955 break;
956 case OMAP_DSS_CHANNEL_LCD2:
957 chan = 0;
958 chan2 = 1;
959 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530960 case OMAP_DSS_CHANNEL_LCD3:
961 if (dss_has_feature(FEAT_MGR_LCD3)) {
962 chan = 0;
963 chan2 = 2;
964 } else {
965 BUG();
966 return;
967 }
968 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000969 default:
970 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300971 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000972 }
973
974 val = FLD_MOD(val, chan, shift, shift);
975 val = FLD_MOD(val, chan2, 31, 30);
976 } else {
977 val = FLD_MOD(val, channel, shift, shift);
978 }
Archit Taneja9b372c22011-05-06 11:45:49 +0530979 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200980}
Tomi Valkeinen348be692012-11-07 18:17:35 +0200981EXPORT_SYMBOL(dispc_ovl_set_channel_out);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200982
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +0200983static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
984{
985 int shift;
986 u32 val;
987 enum omap_channel channel;
988
989 switch (plane) {
990 case OMAP_DSS_GFX:
991 shift = 8;
992 break;
993 case OMAP_DSS_VIDEO1:
994 case OMAP_DSS_VIDEO2:
995 case OMAP_DSS_VIDEO3:
996 shift = 16;
997 break;
998 default:
999 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001000 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001001 }
1002
1003 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1004
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05301005 if (dss_has_feature(FEAT_MGR_LCD3)) {
1006 if (FLD_GET(val, 31, 30) == 0)
1007 channel = FLD_GET(val, shift, shift);
1008 else if (FLD_GET(val, 31, 30) == 1)
1009 channel = OMAP_DSS_CHANNEL_LCD2;
1010 else
1011 channel = OMAP_DSS_CHANNEL_LCD3;
1012 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001013 if (FLD_GET(val, 31, 30) == 0)
1014 channel = FLD_GET(val, shift, shift);
1015 else
1016 channel = OMAP_DSS_CHANNEL_LCD2;
1017 } else {
1018 channel = FLD_GET(val, shift, shift);
1019 }
1020
1021 return channel;
1022}
1023
Archit Tanejad9ac7732012-09-22 12:38:19 +05301024void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1025{
1026 enum omap_plane plane = OMAP_DSS_WB;
1027
1028 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1029}
1030
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001031static void dispc_ovl_set_burst_size(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001032 enum omap_burst_size burst_size)
1033{
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301034 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001035 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001036
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001037 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001038 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001039}
1040
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001041static void dispc_configure_burst_sizes(void)
1042{
1043 int i;
1044 const int burst_size = BURST_SIZE_X8;
1045
1046 /* Configure burst size always to maximum size */
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001047 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001048 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001049}
1050
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001051static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001052{
1053 unsigned unit = dss_feat_get_burst_size_unit();
1054 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1055 return unit * 8;
1056}
1057
Mythri P Kd3862612011-03-11 18:02:49 +05301058void dispc_enable_gamma_table(bool enable)
1059{
1060 /*
1061 * This is partially implemented to support only disabling of
1062 * the gamma table.
1063 */
1064 if (enable) {
1065 DSSWARN("Gamma table enabling for TV not yet supported");
1066 return;
1067 }
1068
1069 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1070}
1071
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001072static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001073{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301074 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001075 return;
1076
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301077 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001078}
1079
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001080static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02001081 const struct omap_dss_cpr_coefs *coefs)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001082{
1083 u32 coef_r, coef_g, coef_b;
1084
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301085 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001086 return;
1087
1088 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1089 FLD_VAL(coefs->rb, 9, 0);
1090 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1091 FLD_VAL(coefs->gb, 9, 0);
1092 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1093 FLD_VAL(coefs->bb, 9, 0);
1094
1095 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1096 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1097 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1098}
1099
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001100static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001101{
1102 u32 val;
1103
1104 BUG_ON(plane == OMAP_DSS_GFX);
1105
Archit Taneja9b372c22011-05-06 11:45:49 +05301106 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001107 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +05301108 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001109}
1110
Archit Tanejad79db852012-09-22 12:30:17 +05301111static void dispc_ovl_enable_replication(enum omap_plane plane,
1112 enum omap_overlay_caps caps, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001113{
Archit Tanejab8c095b2011-09-13 18:20:33 +05301114 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001115 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001116
Archit Tanejad79db852012-09-22 12:30:17 +05301117 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1118 return;
1119
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001120 shift = shifts[plane];
1121 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001122}
1123
Archit Taneja8f366162012-04-16 12:53:44 +05301124static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
Archit Tanejae5c09e02012-04-16 12:53:42 +05301125 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001126{
1127 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301128
Archit Taneja33b89922012-11-14 13:50:15 +05301129 val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1130 FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1131
Archit Taneja702d1442011-05-06 11:45:50 +05301132 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001133}
1134
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001135static void dispc_init_fifos(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001136{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001137 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001138 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301139 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001140 u32 unit;
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001141 int i;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001142
1143 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001144
Archit Tanejaa0acb552010-09-15 19:20:00 +05301145 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001146
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001147 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1148 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001149 size *= unit;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001150 dispc.fifo_size[fifo] = size;
1151
1152 /*
1153 * By default fifos are mapped directly to overlays, fifo 0 to
1154 * ovl 0, fifo 1 to ovl 1, etc.
1155 */
1156 dispc.fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001157 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001158
1159 /*
1160 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1161 * causes problems with certain use cases, like using the tiler in 2D
1162 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1163 * giving GFX plane a larger fifo. WB but should work fine with a
1164 * smaller fifo.
1165 */
1166 if (dispc.feat->gfx_fifo_workaround) {
1167 u32 v;
1168
1169 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1170
1171 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1172 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1173 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1174 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1175
1176 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1177
1178 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1179 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1180 }
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001181
1182 /*
1183 * Setup default fifo thresholds.
1184 */
1185 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1186 u32 low, high;
1187 const bool use_fifomerge = false;
1188 const bool manual_update = false;
1189
1190 dispc_ovl_compute_fifo_thresholds(i, &low, &high,
1191 use_fifomerge, manual_update);
1192
1193 dispc_ovl_set_fifo_threshold(i, low, high);
1194 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001195}
1196
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001197static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001198{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001199 int fifo;
1200 u32 size = 0;
1201
1202 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1203 if (dispc.fifo_assignment[fifo] == plane)
1204 size += dispc.fifo_size[fifo];
1205 }
1206
1207 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001208}
1209
Tomi Valkeinen6f04e1b2011-10-31 08:58:52 +02001210void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001211{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301212 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001213 u32 unit;
1214
1215 unit = dss_feat_get_buffer_size_unit();
1216
1217 WARN_ON(low % unit != 0);
1218 WARN_ON(high % unit != 0);
1219
1220 low /= unit;
1221 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301222
Archit Taneja9b372c22011-05-06 11:45:49 +05301223 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1224 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1225
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001226 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001227 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301228 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001229 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301230 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001231 hi_start, hi_end) * unit,
1232 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001233
Archit Taneja9b372c22011-05-06 11:45:49 +05301234 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301235 FLD_VAL(high, hi_start, hi_end) |
1236 FLD_VAL(low, lo_start, lo_end));
Archit Taneja8bc65552013-12-17 16:40:21 +05301237
1238 /*
1239 * configure the preload to the pipeline's high threhold, if HT it's too
1240 * large for the preload field, set the threshold to the maximum value
1241 * that can be held by the preload register
1242 */
1243 if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload &&
1244 plane != OMAP_DSS_WB)
1245 dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001246}
Tomi Valkeinen8ee5c842013-11-08 10:07:20 +02001247EXPORT_SYMBOL(dispc_ovl_set_fifo_threshold);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001248
1249void dispc_enable_fifomerge(bool enable)
1250{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001251 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1252 WARN_ON(enable);
1253 return;
1254 }
1255
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001256 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1257 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001258}
1259
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001260void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001261 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1262 bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001263{
1264 /*
1265 * All sizes are in bytes. Both the buffer and burst are made of
1266 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1267 */
1268
1269 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001270 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1271 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001272
1273 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001274 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001275
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001276 if (use_fifomerge) {
1277 total_fifo_size = 0;
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001278 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001279 total_fifo_size += dispc_ovl_get_fifo_size(i);
1280 } else {
1281 total_fifo_size = ovl_fifo_size;
1282 }
1283
1284 /*
1285 * We use the same low threshold for both fifomerge and non-fifomerge
1286 * cases, but for fifomerge we calculate the high threshold using the
1287 * combined fifo size
1288 */
1289
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001290 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001291 *fifo_low = ovl_fifo_size - burst_size * 2;
1292 *fifo_high = total_fifo_size - burst_size;
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301293 } else if (plane == OMAP_DSS_WB) {
1294 /*
1295 * Most optimal configuration for writeback is to push out data
1296 * to the interconnect the moment writeback pushes enough pixels
1297 * in the FIFO to form a burst
1298 */
1299 *fifo_low = 0;
1300 *fifo_high = burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001301 } else {
1302 *fifo_low = ovl_fifo_size - burst_size;
1303 *fifo_high = total_fifo_size - buf_unit;
1304 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001305}
Tomi Valkeinen8ee5c842013-11-08 10:07:20 +02001306EXPORT_SYMBOL(dispc_ovl_compute_fifo_thresholds);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001307
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001308static void dispc_ovl_set_mflag(enum omap_plane plane, bool enable)
1309{
1310 int bit;
1311
1312 if (plane == OMAP_DSS_GFX)
1313 bit = 14;
1314 else
1315 bit = 23;
1316
1317 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1318}
1319
1320static void dispc_ovl_set_mflag_threshold(enum omap_plane plane,
1321 int low, int high)
1322{
1323 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane),
1324 FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1325}
1326
1327static void dispc_init_mflag(void)
1328{
1329 int i;
1330
1331 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE,
1332 (2 << 0) | /* MFLAG_CTRL = enable */
1333 (0 << 2)); /* MFLAG_START = disable */
1334
1335 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1336 u32 size = dispc_ovl_get_fifo_size(i);
1337 u32 unit = dss_feat_get_buffer_size_unit();
1338 u32 low, high;
1339
1340 dispc_ovl_set_mflag(i, true);
1341
1342 /*
1343 * Simulation team suggests below thesholds:
1344 * HT = fifosize * 5 / 8;
1345 * LT = fifosize * 4 / 8;
1346 */
1347
1348 low = size * 4 / 8 / unit;
1349 high = size * 5 / 8 / unit;
1350
1351 dispc_ovl_set_mflag_threshold(i, low, high);
1352 }
1353}
1354
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001355static void dispc_ovl_set_fir(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301356 int hinc, int vinc,
1357 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001358{
1359 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001360
Amber Jain0d66cbb2011-05-19 19:47:54 +05301361 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1362 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301363
Amber Jain0d66cbb2011-05-19 19:47:54 +05301364 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1365 &hinc_start, &hinc_end);
1366 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1367 &vinc_start, &vinc_end);
1368 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1369 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301370
Amber Jain0d66cbb2011-05-19 19:47:54 +05301371 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1372 } else {
1373 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1374 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1375 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001376}
1377
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001378static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001379{
1380 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301381 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001382
Archit Taneja87a74842011-03-02 11:19:50 +05301383 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1384 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1385
1386 val = FLD_VAL(vaccu, vert_start, vert_end) |
1387 FLD_VAL(haccu, hor_start, hor_end);
1388
Archit Taneja9b372c22011-05-06 11:45:49 +05301389 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001390}
1391
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001392static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001393{
1394 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301395 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001396
Archit Taneja87a74842011-03-02 11:19:50 +05301397 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1398 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1399
1400 val = FLD_VAL(vaccu, vert_start, vert_end) |
1401 FLD_VAL(haccu, hor_start, hor_end);
1402
Archit Taneja9b372c22011-05-06 11:45:49 +05301403 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001404}
1405
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001406static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1407 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301408{
1409 u32 val;
1410
1411 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1412 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1413}
1414
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001415static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1416 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301417{
1418 u32 val;
1419
1420 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1421 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1422}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001423
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001424static void dispc_ovl_set_scale_param(enum omap_plane plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001425 u16 orig_width, u16 orig_height,
1426 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301427 bool five_taps, u8 rotation,
1428 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001429{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301430 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001431
Amber Jained14a3c2011-05-19 19:47:51 +05301432 fir_hinc = 1024 * orig_width / out_width;
1433 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001434
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301435 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1436 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001437 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301438}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001439
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301440static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1441 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1442 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1443{
1444 int h_accu2_0, h_accu2_1;
1445 int v_accu2_0, v_accu2_1;
1446 int chroma_hinc, chroma_vinc;
1447 int idx;
1448
1449 struct accu {
1450 s8 h0_m, h0_n;
1451 s8 h1_m, h1_n;
1452 s8 v0_m, v0_n;
1453 s8 v1_m, v1_n;
1454 };
1455
1456 const struct accu *accu_table;
1457 const struct accu *accu_val;
1458
1459 static const struct accu accu_nv12[4] = {
1460 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1461 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1462 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1463 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1464 };
1465
1466 static const struct accu accu_nv12_ilace[4] = {
1467 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1468 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1469 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1470 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1471 };
1472
1473 static const struct accu accu_yuv[4] = {
1474 { 0, 1, 0, 1, 0, 1, 0, 1 },
1475 { 0, 1, 0, 1, 0, 1, 0, 1 },
1476 { -1, 1, 0, 1, 0, 1, 0, 1 },
1477 { 0, 1, 0, 1, -1, 1, 0, 1 },
1478 };
1479
1480 switch (rotation) {
1481 case OMAP_DSS_ROT_0:
1482 idx = 0;
1483 break;
1484 case OMAP_DSS_ROT_90:
1485 idx = 1;
1486 break;
1487 case OMAP_DSS_ROT_180:
1488 idx = 2;
1489 break;
1490 case OMAP_DSS_ROT_270:
1491 idx = 3;
1492 break;
1493 default:
1494 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001495 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301496 }
1497
1498 switch (color_mode) {
1499 case OMAP_DSS_COLOR_NV12:
1500 if (ilace)
1501 accu_table = accu_nv12_ilace;
1502 else
1503 accu_table = accu_nv12;
1504 break;
1505 case OMAP_DSS_COLOR_YUV2:
1506 case OMAP_DSS_COLOR_UYVY:
1507 accu_table = accu_yuv;
1508 break;
1509 default:
1510 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001511 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301512 }
1513
1514 accu_val = &accu_table[idx];
1515
1516 chroma_hinc = 1024 * orig_width / out_width;
1517 chroma_vinc = 1024 * orig_height / out_height;
1518
1519 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1520 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1521 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1522 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1523
1524 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1525 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1526}
1527
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001528static void dispc_ovl_set_scaling_common(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301529 u16 orig_width, u16 orig_height,
1530 u16 out_width, u16 out_height,
1531 bool ilace, bool five_taps,
1532 bool fieldmode, enum omap_color_mode color_mode,
1533 u8 rotation)
1534{
1535 int accu0 = 0;
1536 int accu1 = 0;
1537 u32 l;
1538
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001539 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301540 out_width, out_height, five_taps,
1541 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301542 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001543
Archit Taneja87a74842011-03-02 11:19:50 +05301544 /* RESIZEENABLE and VERTICALTAPS */
1545 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301546 l |= (orig_width != out_width) ? (1 << 5) : 0;
1547 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001548 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301549
1550 /* VRESIZECONF and HRESIZECONF */
1551 if (dss_has_feature(FEAT_RESIZECONF)) {
1552 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301553 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1554 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301555 }
1556
1557 /* LINEBUFFERSPLIT */
1558 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1559 l &= ~(0x1 << 22);
1560 l |= five_taps ? (1 << 22) : 0;
1561 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001562
Archit Taneja9b372c22011-05-06 11:45:49 +05301563 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001564
1565 /*
1566 * field 0 = even field = bottom field
1567 * field 1 = odd field = top field
1568 */
1569 if (ilace && !fieldmode) {
1570 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301571 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001572 if (accu0 >= 1024/2) {
1573 accu1 = 1024/2;
1574 accu0 -= accu1;
1575 }
1576 }
1577
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001578 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1579 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001580}
1581
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001582static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301583 u16 orig_width, u16 orig_height,
1584 u16 out_width, u16 out_height,
1585 bool ilace, bool five_taps,
1586 bool fieldmode, enum omap_color_mode color_mode,
1587 u8 rotation)
1588{
1589 int scale_x = out_width != orig_width;
1590 int scale_y = out_height != orig_height;
Archit Tanejaf92afae2012-08-24 11:11:14 +05301591 bool chroma_upscale = plane != OMAP_DSS_WB ? true : false;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301592
1593 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1594 return;
1595 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1596 color_mode != OMAP_DSS_COLOR_UYVY &&
1597 color_mode != OMAP_DSS_COLOR_NV12)) {
1598 /* reset chroma resampling for RGB formats */
Archit Taneja2a5561b2012-07-16 16:37:45 +05301599 if (plane != OMAP_DSS_WB)
1600 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301601 return;
1602 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001603
1604 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1605 out_height, ilace, color_mode, rotation);
1606
Amber Jain0d66cbb2011-05-19 19:47:54 +05301607 switch (color_mode) {
1608 case OMAP_DSS_COLOR_NV12:
Archit Taneja20fbb502012-08-22 17:04:48 +05301609 if (chroma_upscale) {
1610 /* UV is subsampled by 2 horizontally and vertically */
1611 orig_height >>= 1;
1612 orig_width >>= 1;
1613 } else {
1614 /* UV is downsampled by 2 horizontally and vertically */
1615 orig_height <<= 1;
1616 orig_width <<= 1;
1617 }
1618
Amber Jain0d66cbb2011-05-19 19:47:54 +05301619 break;
1620 case OMAP_DSS_COLOR_YUV2:
1621 case OMAP_DSS_COLOR_UYVY:
Archit Taneja20fbb502012-08-22 17:04:48 +05301622 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
Amber Jain0d66cbb2011-05-19 19:47:54 +05301623 if (rotation == OMAP_DSS_ROT_0 ||
Archit Taneja20fbb502012-08-22 17:04:48 +05301624 rotation == OMAP_DSS_ROT_180) {
1625 if (chroma_upscale)
1626 /* UV is subsampled by 2 horizontally */
1627 orig_width >>= 1;
1628 else
1629 /* UV is downsampled by 2 horizontally */
1630 orig_width <<= 1;
1631 }
1632
Amber Jain0d66cbb2011-05-19 19:47:54 +05301633 /* must use FIR for YUV422 if rotated */
1634 if (rotation != OMAP_DSS_ROT_0)
1635 scale_x = scale_y = true;
Archit Taneja20fbb502012-08-22 17:04:48 +05301636
Amber Jain0d66cbb2011-05-19 19:47:54 +05301637 break;
1638 default:
1639 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001640 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301641 }
1642
1643 if (out_width != orig_width)
1644 scale_x = true;
1645 if (out_height != orig_height)
1646 scale_y = true;
1647
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001648 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301649 out_width, out_height, five_taps,
1650 rotation, DISPC_COLOR_COMPONENT_UV);
1651
Archit Taneja2a5561b2012-07-16 16:37:45 +05301652 if (plane != OMAP_DSS_WB)
1653 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1654 (scale_x || scale_y) ? 1 : 0, 8, 8);
1655
Amber Jain0d66cbb2011-05-19 19:47:54 +05301656 /* set H scaling */
1657 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1658 /* set V scaling */
1659 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301660}
1661
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001662static void dispc_ovl_set_scaling(enum omap_plane plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301663 u16 orig_width, u16 orig_height,
1664 u16 out_width, u16 out_height,
1665 bool ilace, bool five_taps,
1666 bool fieldmode, enum omap_color_mode color_mode,
1667 u8 rotation)
1668{
1669 BUG_ON(plane == OMAP_DSS_GFX);
1670
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001671 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301672 orig_width, orig_height,
1673 out_width, out_height,
1674 ilace, five_taps,
1675 fieldmode, color_mode,
1676 rotation);
1677
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001678 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301679 orig_width, orig_height,
1680 out_width, out_height,
1681 ilace, five_taps,
1682 fieldmode, color_mode,
1683 rotation);
1684}
1685
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001686static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
Archit Tanejac35eeb22013-03-26 19:15:24 +05301687 enum omap_dss_rotation_type rotation_type,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001688 bool mirroring, enum omap_color_mode color_mode)
1689{
Archit Taneja87a74842011-03-02 11:19:50 +05301690 bool row_repeat = false;
1691 int vidrot = 0;
1692
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001693 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1694 color_mode == OMAP_DSS_COLOR_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001695
1696 if (mirroring) {
1697 switch (rotation) {
1698 case OMAP_DSS_ROT_0:
1699 vidrot = 2;
1700 break;
1701 case OMAP_DSS_ROT_90:
1702 vidrot = 1;
1703 break;
1704 case OMAP_DSS_ROT_180:
1705 vidrot = 0;
1706 break;
1707 case OMAP_DSS_ROT_270:
1708 vidrot = 3;
1709 break;
1710 }
1711 } else {
1712 switch (rotation) {
1713 case OMAP_DSS_ROT_0:
1714 vidrot = 0;
1715 break;
1716 case OMAP_DSS_ROT_90:
1717 vidrot = 1;
1718 break;
1719 case OMAP_DSS_ROT_180:
1720 vidrot = 2;
1721 break;
1722 case OMAP_DSS_ROT_270:
1723 vidrot = 3;
1724 break;
1725 }
1726 }
1727
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001728 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
Archit Taneja87a74842011-03-02 11:19:50 +05301729 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001730 else
Archit Taneja87a74842011-03-02 11:19:50 +05301731 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001732 }
Archit Taneja87a74842011-03-02 11:19:50 +05301733
Archit Taneja9b372c22011-05-06 11:45:49 +05301734 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301735 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301736 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1737 row_repeat ? 1 : 0, 18, 18);
Archit Tanejac35eeb22013-03-26 19:15:24 +05301738
1739 if (color_mode == OMAP_DSS_COLOR_NV12) {
1740 bool doublestride = (rotation_type == OMAP_DSS_ROT_TILER) &&
1741 (rotation == OMAP_DSS_ROT_0 ||
1742 rotation == OMAP_DSS_ROT_180);
1743 /* DOUBLESTRIDE */
1744 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22);
1745 }
1746
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001747}
1748
1749static int color_mode_to_bpp(enum omap_color_mode color_mode)
1750{
1751 switch (color_mode) {
1752 case OMAP_DSS_COLOR_CLUT1:
1753 return 1;
1754 case OMAP_DSS_COLOR_CLUT2:
1755 return 2;
1756 case OMAP_DSS_COLOR_CLUT4:
1757 return 4;
1758 case OMAP_DSS_COLOR_CLUT8:
Amber Jainf20e4222011-05-19 19:47:50 +05301759 case OMAP_DSS_COLOR_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001760 return 8;
1761 case OMAP_DSS_COLOR_RGB12U:
1762 case OMAP_DSS_COLOR_RGB16:
1763 case OMAP_DSS_COLOR_ARGB16:
1764 case OMAP_DSS_COLOR_YUV2:
1765 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301766 case OMAP_DSS_COLOR_RGBA16:
1767 case OMAP_DSS_COLOR_RGBX16:
1768 case OMAP_DSS_COLOR_ARGB16_1555:
1769 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001770 return 16;
1771 case OMAP_DSS_COLOR_RGB24P:
1772 return 24;
1773 case OMAP_DSS_COLOR_RGB24U:
1774 case OMAP_DSS_COLOR_ARGB32:
1775 case OMAP_DSS_COLOR_RGBA32:
1776 case OMAP_DSS_COLOR_RGBX32:
1777 return 32;
1778 default:
1779 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001780 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001781 }
1782}
1783
1784static s32 pixinc(int pixels, u8 ps)
1785{
1786 if (pixels == 1)
1787 return 1;
1788 else if (pixels > 1)
1789 return 1 + (pixels - 1) * ps;
1790 else if (pixels < 0)
1791 return 1 - (-pixels + 1) * ps;
1792 else
1793 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001794 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001795}
1796
1797static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1798 u16 screen_width,
1799 u16 width, u16 height,
1800 enum omap_color_mode color_mode, bool fieldmode,
1801 unsigned int field_offset,
1802 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301803 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001804{
1805 u8 ps;
1806
1807 /* FIXME CLUT formats */
1808 switch (color_mode) {
1809 case OMAP_DSS_COLOR_CLUT1:
1810 case OMAP_DSS_COLOR_CLUT2:
1811 case OMAP_DSS_COLOR_CLUT4:
1812 case OMAP_DSS_COLOR_CLUT8:
1813 BUG();
1814 return;
1815 case OMAP_DSS_COLOR_YUV2:
1816 case OMAP_DSS_COLOR_UYVY:
1817 ps = 4;
1818 break;
1819 default:
1820 ps = color_mode_to_bpp(color_mode) / 8;
1821 break;
1822 }
1823
1824 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1825 width, height);
1826
1827 /*
1828 * field 0 = even field = bottom field
1829 * field 1 = odd field = top field
1830 */
1831 switch (rotation + mirror * 4) {
1832 case OMAP_DSS_ROT_0:
1833 case OMAP_DSS_ROT_180:
1834 /*
1835 * If the pixel format is YUV or UYVY divide the width
1836 * of the image by 2 for 0 and 180 degree rotation.
1837 */
1838 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1839 color_mode == OMAP_DSS_COLOR_UYVY)
1840 width = width >> 1;
1841 case OMAP_DSS_ROT_90:
1842 case OMAP_DSS_ROT_270:
1843 *offset1 = 0;
1844 if (field_offset)
1845 *offset0 = field_offset * screen_width * ps;
1846 else
1847 *offset0 = 0;
1848
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301849 *row_inc = pixinc(1 +
1850 (y_predecim * screen_width - x_predecim * width) +
1851 (fieldmode ? screen_width : 0), ps);
1852 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001853 break;
1854
1855 case OMAP_DSS_ROT_0 + 4:
1856 case OMAP_DSS_ROT_180 + 4:
1857 /* If the pixel format is YUV or UYVY divide the width
1858 * of the image by 2 for 0 degree and 180 degree
1859 */
1860 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1861 color_mode == OMAP_DSS_COLOR_UYVY)
1862 width = width >> 1;
1863 case OMAP_DSS_ROT_90 + 4:
1864 case OMAP_DSS_ROT_270 + 4:
1865 *offset1 = 0;
1866 if (field_offset)
1867 *offset0 = field_offset * screen_width * ps;
1868 else
1869 *offset0 = 0;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301870 *row_inc = pixinc(1 -
1871 (y_predecim * screen_width + x_predecim * width) -
1872 (fieldmode ? screen_width : 0), ps);
1873 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001874 break;
1875
1876 default:
1877 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001878 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001879 }
1880}
1881
1882static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1883 u16 screen_width,
1884 u16 width, u16 height,
1885 enum omap_color_mode color_mode, bool fieldmode,
1886 unsigned int field_offset,
1887 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301888 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001889{
1890 u8 ps;
1891 u16 fbw, fbh;
1892
1893 /* FIXME CLUT formats */
1894 switch (color_mode) {
1895 case OMAP_DSS_COLOR_CLUT1:
1896 case OMAP_DSS_COLOR_CLUT2:
1897 case OMAP_DSS_COLOR_CLUT4:
1898 case OMAP_DSS_COLOR_CLUT8:
1899 BUG();
1900 return;
1901 default:
1902 ps = color_mode_to_bpp(color_mode) / 8;
1903 break;
1904 }
1905
1906 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1907 width, height);
1908
1909 /* width & height are overlay sizes, convert to fb sizes */
1910
1911 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1912 fbw = width;
1913 fbh = height;
1914 } else {
1915 fbw = height;
1916 fbh = width;
1917 }
1918
1919 /*
1920 * field 0 = even field = bottom field
1921 * field 1 = odd field = top field
1922 */
1923 switch (rotation + mirror * 4) {
1924 case OMAP_DSS_ROT_0:
1925 *offset1 = 0;
1926 if (field_offset)
1927 *offset0 = *offset1 + field_offset * screen_width * ps;
1928 else
1929 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301930 *row_inc = pixinc(1 +
1931 (y_predecim * screen_width - fbw * x_predecim) +
1932 (fieldmode ? screen_width : 0), ps);
1933 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1934 color_mode == OMAP_DSS_COLOR_UYVY)
1935 *pix_inc = pixinc(x_predecim, 2 * ps);
1936 else
1937 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001938 break;
1939 case OMAP_DSS_ROT_90:
1940 *offset1 = screen_width * (fbh - 1) * ps;
1941 if (field_offset)
1942 *offset0 = *offset1 + field_offset * ps;
1943 else
1944 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301945 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1946 y_predecim + (fieldmode ? 1 : 0), ps);
1947 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001948 break;
1949 case OMAP_DSS_ROT_180:
1950 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1951 if (field_offset)
1952 *offset0 = *offset1 - field_offset * screen_width * ps;
1953 else
1954 *offset0 = *offset1;
1955 *row_inc = pixinc(-1 -
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301956 (y_predecim * screen_width - fbw * x_predecim) -
1957 (fieldmode ? screen_width : 0), ps);
1958 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1959 color_mode == OMAP_DSS_COLOR_UYVY)
1960 *pix_inc = pixinc(-x_predecim, 2 * ps);
1961 else
1962 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001963 break;
1964 case OMAP_DSS_ROT_270:
1965 *offset1 = (fbw - 1) * ps;
1966 if (field_offset)
1967 *offset0 = *offset1 - field_offset * ps;
1968 else
1969 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301970 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1971 y_predecim - (fieldmode ? 1 : 0), ps);
1972 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001973 break;
1974
1975 /* mirroring */
1976 case OMAP_DSS_ROT_0 + 4:
1977 *offset1 = (fbw - 1) * ps;
1978 if (field_offset)
1979 *offset0 = *offset1 + field_offset * screen_width * ps;
1980 else
1981 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301982 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001983 (fieldmode ? screen_width : 0),
1984 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301985 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1986 color_mode == OMAP_DSS_COLOR_UYVY)
1987 *pix_inc = pixinc(-x_predecim, 2 * ps);
1988 else
1989 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001990 break;
1991
1992 case OMAP_DSS_ROT_90 + 4:
1993 *offset1 = 0;
1994 if (field_offset)
1995 *offset0 = *offset1 + field_offset * ps;
1996 else
1997 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301998 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1999 y_predecim + (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002000 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302001 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002002 break;
2003
2004 case OMAP_DSS_ROT_180 + 4:
2005 *offset1 = screen_width * (fbh - 1) * ps;
2006 if (field_offset)
2007 *offset0 = *offset1 - field_offset * screen_width * ps;
2008 else
2009 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302010 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002011 (fieldmode ? screen_width : 0),
2012 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302013 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2014 color_mode == OMAP_DSS_COLOR_UYVY)
2015 *pix_inc = pixinc(x_predecim, 2 * ps);
2016 else
2017 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002018 break;
2019
2020 case OMAP_DSS_ROT_270 + 4:
2021 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
2022 if (field_offset)
2023 *offset0 = *offset1 - field_offset * ps;
2024 else
2025 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302026 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
2027 y_predecim - (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002028 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302029 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002030 break;
2031
2032 default:
2033 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002034 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002035 }
2036}
2037
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302038static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
2039 enum omap_color_mode color_mode, bool fieldmode,
2040 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
2041 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
2042{
2043 u8 ps;
2044
2045 switch (color_mode) {
2046 case OMAP_DSS_COLOR_CLUT1:
2047 case OMAP_DSS_COLOR_CLUT2:
2048 case OMAP_DSS_COLOR_CLUT4:
2049 case OMAP_DSS_COLOR_CLUT8:
2050 BUG();
2051 return;
2052 default:
2053 ps = color_mode_to_bpp(color_mode) / 8;
2054 break;
2055 }
2056
2057 DSSDBG("scrw %d, width %d\n", screen_width, width);
2058
2059 /*
2060 * field 0 = even field = bottom field
2061 * field 1 = odd field = top field
2062 */
2063 *offset1 = 0;
2064 if (field_offset)
2065 *offset0 = *offset1 + field_offset * screen_width * ps;
2066 else
2067 *offset0 = *offset1;
2068 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
2069 (fieldmode ? screen_width : 0), ps);
2070 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2071 color_mode == OMAP_DSS_COLOR_UYVY)
2072 *pix_inc = pixinc(x_predecim, 2 * ps);
2073 else
2074 *pix_inc = pixinc(x_predecim, ps);
2075}
2076
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302077/*
2078 * This function is used to avoid synclosts in OMAP3, because of some
2079 * undocumented horizontal position and timing related limitations.
2080 */
Tomi Valkeinen465ec132012-10-19 15:40:24 +03002081static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302082 const struct omap_video_timings *t, u16 pos_x,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002083 u16 width, u16 height, u16 out_width, u16 out_height,
2084 bool five_taps)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302085{
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002086 const int ds = DIV_ROUND_UP(height, out_height);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302087 unsigned long nonactive;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302088 static const u8 limits[3] = { 8, 10, 20 };
2089 u64 val, blank;
2090 int i;
2091
Archit Taneja81ab95b2012-05-08 15:53:20 +05302092 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302093
2094 i = 0;
2095 if (out_height < height)
2096 i++;
2097 if (out_width < width)
2098 i++;
Archit Taneja81ab95b2012-05-08 15:53:20 +05302099 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302100 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2101 if (blank <= limits[i])
2102 return -EINVAL;
2103
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002104 /* FIXME add checks for 3-tap filter once the limitations are known */
2105 if (!five_taps)
2106 return 0;
2107
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302108 /*
2109 * Pixel data should be prepared before visible display point starts.
2110 * So, atleast DS-2 lines must have already been fetched by DISPC
2111 * during nonactive - pos_x period.
2112 */
2113 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2114 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002115 val, max(0, ds - 2) * width);
2116 if (val < max(0, ds - 2) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302117 return -EINVAL;
2118
2119 /*
2120 * All lines need to be refilled during the nonactive period of which
2121 * only one line can be loaded during the active period. So, atleast
2122 * DS - 1 lines should be loaded during nonactive period.
2123 */
2124 val = div_u64((u64)nonactive * lclk, pclk);
2125 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002126 val, max(0, ds - 1) * width);
2127 if (val < max(0, ds - 1) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302128 return -EINVAL;
2129
2130 return 0;
2131}
2132
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002133static unsigned long calc_core_clk_five_taps(unsigned long pclk,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302134 const struct omap_video_timings *mgr_timings, u16 width,
2135 u16 height, u16 out_width, u16 out_height,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002136 enum omap_color_mode color_mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002137{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302138 u32 core_clk = 0;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302139 u64 tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002140
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302141 if (height <= out_height && width <= out_width)
2142 return (unsigned long) pclk;
2143
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002144 if (height > out_height) {
Archit Taneja81ab95b2012-05-08 15:53:20 +05302145 unsigned int ppl = mgr_timings->x_res;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002146
2147 tmp = pclk * height * out_width;
2148 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302149 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002150
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02002151 if (height > 2 * out_height) {
2152 if (ppl == out_width)
2153 return 0;
2154
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002155 tmp = pclk * (height - 2 * out_height) * out_width;
2156 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302157 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002158 }
2159 }
2160
2161 if (width > out_width) {
2162 tmp = pclk * width;
2163 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302164 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002165
2166 if (color_mode == OMAP_DSS_COLOR_RGB24U)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302167 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002168 }
2169
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302170 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002171}
2172
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002173static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302174 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302175{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302176 if (height > out_height && width > out_width)
2177 return pclk * 4;
2178 else
2179 return pclk * 2;
2180}
2181
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002182static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302183 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002184{
2185 unsigned int hf, vf;
2186
2187 /*
2188 * FIXME how to determine the 'A' factor
2189 * for the no downscaling case ?
2190 */
2191
2192 if (width > 3 * out_width)
2193 hf = 4;
2194 else if (width > 2 * out_width)
2195 hf = 3;
2196 else if (width > out_width)
2197 hf = 2;
2198 else
2199 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002200 if (height > out_height)
2201 vf = 2;
2202 else
2203 vf = 1;
2204
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302205 return pclk * vf * hf;
2206}
2207
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002208static unsigned long calc_core_clk_44xx(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)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302210{
Archit Taneja8ba85302012-09-26 17:00:37 +05302211 /*
2212 * If the overlay/writeback is in mem to mem mode, there are no
2213 * downscaling limitations with respect to pixel clock, return 1 as
2214 * required core clock to represent that we have sufficient enough
2215 * core clock to do maximum downscaling
2216 */
2217 if (mem_to_mem)
2218 return 1;
2219
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302220 if (width > out_width)
2221 return DIV_ROUND_UP(pclk, out_width) * width;
2222 else
2223 return pclk;
2224}
2225
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002226static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302227 const struct omap_video_timings *mgr_timings,
2228 u16 width, u16 height, u16 out_width, u16 out_height,
2229 enum omap_color_mode color_mode, bool *five_taps,
2230 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302231 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302232{
2233 int error;
2234 u16 in_width, in_height;
2235 int min_factor = min(*decim_x, *decim_y);
2236 const int maxsinglelinewidth =
2237 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302238
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302239 *five_taps = false;
2240
2241 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002242 in_height = height / *decim_y;
2243 in_width = width / *decim_x;
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002244 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302245 in_height, out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302246 error = (in_width > maxsinglelinewidth || !*core_clk ||
2247 *core_clk > dispc_core_clk_rate());
2248 if (error) {
2249 if (*decim_x == *decim_y) {
2250 *decim_x = min_factor;
2251 ++*decim_y;
2252 } else {
2253 swap(*decim_x, *decim_y);
2254 if (*decim_x < *decim_y)
2255 ++*decim_x;
2256 }
2257 }
2258 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2259
2260 if (in_width > maxsinglelinewidth) {
2261 DSSERR("Cannot scale max input width exceeded");
2262 return -EINVAL;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302263 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302264 return 0;
2265}
2266
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002267static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302268 const struct omap_video_timings *mgr_timings,
2269 u16 width, u16 height, u16 out_width, u16 out_height,
2270 enum omap_color_mode color_mode, bool *five_taps,
2271 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302272 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302273{
2274 int error;
2275 u16 in_width, in_height;
2276 int min_factor = min(*decim_x, *decim_y);
2277 const int maxsinglelinewidth =
2278 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2279
2280 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002281 in_height = height / *decim_y;
2282 in_width = width / *decim_x;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002283 *five_taps = in_height > out_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302284
2285 if (in_width > maxsinglelinewidth)
2286 if (in_height > out_height &&
2287 in_height < out_height * 2)
2288 *five_taps = false;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002289again:
2290 if (*five_taps)
2291 *core_clk = calc_core_clk_five_taps(pclk, mgr_timings,
2292 in_width, in_height, out_width,
2293 out_height, color_mode);
2294 else
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002295 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302296 in_height, out_width, out_height,
2297 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302298
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002299 error = check_horiz_timing_omap3(pclk, lclk, mgr_timings,
2300 pos_x, in_width, in_height, out_width,
2301 out_height, *five_taps);
2302 if (error && *five_taps) {
2303 *five_taps = false;
2304 goto again;
2305 }
2306
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302307 error = (error || in_width > maxsinglelinewidth * 2 ||
2308 (in_width > maxsinglelinewidth && *five_taps) ||
2309 !*core_clk || *core_clk > dispc_core_clk_rate());
2310 if (error) {
2311 if (*decim_x == *decim_y) {
2312 *decim_x = min_factor;
2313 ++*decim_y;
2314 } else {
2315 swap(*decim_x, *decim_y);
2316 if (*decim_x < *decim_y)
2317 ++*decim_x;
2318 }
2319 }
2320 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2321
Tomi Valkeinen465ec132012-10-19 15:40:24 +03002322 if (check_horiz_timing_omap3(pclk, lclk, mgr_timings, pos_x, width,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002323 height, out_width, out_height, *five_taps)) {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302324 DSSERR("horizontal timing too tight\n");
2325 return -EINVAL;
2326 }
2327
2328 if (in_width > (maxsinglelinewidth * 2)) {
2329 DSSERR("Cannot setup scaling");
2330 DSSERR("width exceeds maximum width possible");
2331 return -EINVAL;
2332 }
2333
2334 if (in_width > maxsinglelinewidth && *five_taps) {
2335 DSSERR("cannot setup scaling with five taps");
2336 return -EINVAL;
2337 }
2338 return 0;
2339}
2340
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002341static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302342 const struct omap_video_timings *mgr_timings,
2343 u16 width, u16 height, u16 out_width, u16 out_height,
2344 enum omap_color_mode color_mode, bool *five_taps,
2345 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302346 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302347{
2348 u16 in_width, in_width_max;
2349 int decim_x_min = *decim_x;
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002350 u16 in_height = height / *decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302351 const int maxsinglelinewidth =
2352 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja8ba85302012-09-26 17:00:37 +05302353 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302354
Archit Taneja5d501082012-11-07 11:45:02 +05302355 if (mem_to_mem) {
2356 in_width_max = out_width * maxdownscale;
2357 } else {
Archit Taneja8ba85302012-09-26 17:00:37 +05302358 in_width_max = dispc_core_clk_rate() /
2359 DIV_ROUND_UP(pclk, out_width);
Archit Taneja5d501082012-11-07 11:45:02 +05302360 }
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302361
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302362 *decim_x = DIV_ROUND_UP(width, in_width_max);
2363
2364 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2365 if (*decim_x > *x_predecim)
2366 return -EINVAL;
2367
2368 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002369 in_width = width / *decim_x;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302370 } while (*decim_x <= *x_predecim &&
2371 in_width > maxsinglelinewidth && ++*decim_x);
2372
2373 if (in_width > maxsinglelinewidth) {
2374 DSSERR("Cannot scale width exceeds max line width");
2375 return -EINVAL;
2376 }
2377
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002378 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
Archit Taneja8ba85302012-09-26 17:00:37 +05302379 out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302380 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002381}
2382
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002383static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302384 enum omap_overlay_caps caps,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302385 const struct omap_video_timings *mgr_timings,
2386 u16 width, u16 height, u16 out_width, u16 out_height,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302387 enum omap_color_mode color_mode, bool *five_taps,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302388 int *x_predecim, int *y_predecim, u16 pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302389 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302390{
Archit Taneja0373cac2011-09-08 13:25:17 +05302391 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302392 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302393 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302394 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302395
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002396 if (width == out_width && height == out_height)
2397 return 0;
2398
Tomi Valkeinen4e1d3ca2014-10-03 15:14:09 +00002399 if (pclk == 0 || mgr_timings->pixelclock == 0) {
2400 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2401 return -EINVAL;
2402 }
2403
Archit Taneja5b54ed32012-09-26 16:55:27 +05302404 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002405 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302406
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002407 if (mem_to_mem) {
Archit Taneja1c031442012-11-07 11:45:03 +05302408 *x_predecim = *y_predecim = 1;
2409 } else {
2410 *x_predecim = max_decim_limit;
2411 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2412 dss_has_feature(FEAT_BURST_2D)) ?
2413 2 : max_decim_limit;
2414 }
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302415
2416 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2417 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2418 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2419 color_mode == OMAP_DSS_COLOR_CLUT8) {
2420 *x_predecim = 1;
2421 *y_predecim = 1;
2422 *five_taps = false;
2423 return 0;
2424 }
2425
2426 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2427 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2428
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302429 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302430 return -EINVAL;
2431
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302432 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302433 return -EINVAL;
2434
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002435 ret = dispc.feat->calc_scaling(pclk, lclk, mgr_timings, width, height,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302436 out_width, out_height, color_mode, five_taps,
Archit Taneja8ba85302012-09-26 17:00:37 +05302437 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2438 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302439 if (ret)
2440 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302441
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302442 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2443 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302444
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302445 if (!core_clk || core_clk > dispc_core_clk_rate()) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302446 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302447 "required core clk rate = %lu Hz, "
2448 "current core clk rate = %lu Hz\n",
2449 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302450 return -EINVAL;
2451 }
2452
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302453 *x_predecim = decim_x;
2454 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302455 return 0;
2456}
2457
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002458int dispc_ovl_check(enum omap_plane plane, enum omap_channel channel,
2459 const struct omap_overlay_info *oi,
2460 const struct omap_video_timings *timings,
2461 int *x_predecim, int *y_predecim)
2462{
2463 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2464 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002465 bool fieldmode = false;
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002466 u16 in_height = oi->height;
2467 u16 in_width = oi->width;
2468 bool ilace = timings->interlace;
2469 u16 out_width, out_height;
2470 int pos_x = oi->pos_x;
2471 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2472 unsigned long lclk = dispc_mgr_lclk_rate(channel);
2473
2474 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2475 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
2476
2477 if (ilace && oi->height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002478 fieldmode = true;
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002479
2480 if (ilace) {
2481 if (fieldmode)
2482 in_height /= 2;
2483 out_height /= 2;
2484
2485 DSSDBG("adjusting for ilace: height %d, out_height %d\n",
2486 in_height, out_height);
2487 }
2488
2489 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
2490 return -EINVAL;
2491
2492 return dispc_ovl_calc_scaling(pclk, lclk, caps, timings, in_width,
2493 in_height, out_width, out_height, oi->color_mode,
2494 &five_taps, x_predecim, y_predecim, pos_x,
2495 oi->rotation_type, false);
2496}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002497EXPORT_SYMBOL(dispc_ovl_check);
Tomi Valkeinenf9b719b2012-10-19 15:57:11 +03002498
Archit Taneja84a880f2012-09-26 16:57:37 +05302499static int dispc_ovl_setup_common(enum omap_plane plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302500 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2501 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2502 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2503 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2504 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
Archit Taneja8ba85302012-09-26 17:00:37 +05302505 bool replication, const struct omap_video_timings *mgr_timings,
2506 bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002507{
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302508 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002509 bool fieldmode = false;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302510 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002511 unsigned offset0, offset1;
2512 s32 row_inc;
2513 s32 pix_inc;
Archit Taneja6be0d732012-11-07 11:45:04 +05302514 u16 frame_width, frame_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002515 unsigned int field_offset = 0;
Archit Taneja84a880f2012-09-26 16:57:37 +05302516 u16 in_height = height;
2517 u16 in_width = width;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302518 int x_predecim = 1, y_predecim = 1;
Archit Taneja8050cbe2012-06-06 16:25:52 +05302519 bool ilace = mgr_timings->interlace;
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002520 unsigned long pclk = dispc_plane_pclk_rate(plane);
2521 unsigned long lclk = dispc_plane_lclk_rate(plane);
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002522
Tomi Valkeinene5666582014-11-28 14:34:15 +02002523 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002524 return -EINVAL;
2525
Archit Taneja84a880f2012-09-26 16:57:37 +05302526 out_width = out_width == 0 ? width : out_width;
2527 out_height = out_height == 0 ? height : out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002528
Archit Taneja84a880f2012-09-26 16:57:37 +05302529 if (ilace && height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002530 fieldmode = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002531
2532 if (ilace) {
2533 if (fieldmode)
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302534 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302535 pos_y /= 2;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302536 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002537
2538 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
Archit Taneja84a880f2012-09-26 16:57:37 +05302539 "out_height %d\n", in_height, pos_y,
2540 out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002541 }
2542
Archit Taneja84a880f2012-09-26 16:57:37 +05302543 if (!dss_feat_color_mode_supported(plane, color_mode))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302544 return -EINVAL;
2545
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002546 r = dispc_ovl_calc_scaling(pclk, lclk, caps, mgr_timings, in_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302547 in_height, out_width, out_height, color_mode,
2548 &five_taps, &x_predecim, &y_predecim, pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302549 rotation_type, mem_to_mem);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302550 if (r)
2551 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002552
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002553 in_width = in_width / x_predecim;
2554 in_height = in_height / y_predecim;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302555
Archit Taneja84a880f2012-09-26 16:57:37 +05302556 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2557 color_mode == OMAP_DSS_COLOR_UYVY ||
2558 color_mode == OMAP_DSS_COLOR_NV12)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302559 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002560
2561 if (ilace && !fieldmode) {
2562 /*
2563 * when downscaling the bottom field may have to start several
2564 * source lines below the top field. Unfortunately ACCUI
2565 * registers will only hold the fractional part of the offset
2566 * so the integer part must be added to the base address of the
2567 * bottom field.
2568 */
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302569 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002570 field_offset = 0;
2571 else
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302572 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002573 }
2574
2575 /* Fields are independent but interleaved in memory. */
2576 if (fieldmode)
2577 field_offset = 1;
2578
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002579 offset0 = 0;
2580 offset1 = 0;
2581 row_inc = 0;
2582 pix_inc = 0;
2583
Archit Taneja6be0d732012-11-07 11:45:04 +05302584 if (plane == OMAP_DSS_WB) {
2585 frame_width = out_width;
2586 frame_height = out_height;
2587 } else {
2588 frame_width = in_width;
2589 frame_height = height;
2590 }
2591
Archit Taneja84a880f2012-09-26 16:57:37 +05302592 if (rotation_type == OMAP_DSS_ROT_TILER)
Archit Taneja6be0d732012-11-07 11:45:04 +05302593 calc_tiler_rotation_offset(screen_width, frame_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302594 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302595 &offset0, &offset1, &row_inc, &pix_inc,
2596 x_predecim, y_predecim);
Archit Taneja84a880f2012-09-26 16:57:37 +05302597 else if (rotation_type == OMAP_DSS_ROT_DMA)
Archit Taneja6be0d732012-11-07 11:45:04 +05302598 calc_dma_rotation_offset(rotation, mirror, screen_width,
2599 frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302600 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302601 &offset0, &offset1, &row_inc, &pix_inc,
2602 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002603 else
Archit Taneja84a880f2012-09-26 16:57:37 +05302604 calc_vrfb_rotation_offset(rotation, mirror,
Archit Taneja6be0d732012-11-07 11:45:04 +05302605 screen_width, frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302606 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302607 &offset0, &offset1, &row_inc, &pix_inc,
2608 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002609
2610 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2611 offset0, offset1, row_inc, pix_inc);
2612
Archit Taneja84a880f2012-09-26 16:57:37 +05302613 dispc_ovl_set_color_mode(plane, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002614
Archit Taneja84a880f2012-09-26 16:57:37 +05302615 dispc_ovl_configure_burst_type(plane, rotation_type);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302616
Archit Taneja84a880f2012-09-26 16:57:37 +05302617 dispc_ovl_set_ba0(plane, paddr + offset0);
2618 dispc_ovl_set_ba1(plane, paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002619
Archit Taneja84a880f2012-09-26 16:57:37 +05302620 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2621 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2622 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302623 }
2624
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002625 dispc_ovl_set_row_inc(plane, row_inc);
2626 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002627
Archit Taneja84a880f2012-09-26 16:57:37 +05302628 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302629 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002630
Archit Taneja84a880f2012-09-26 16:57:37 +05302631 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002632
Archit Taneja78b687f2012-09-21 14:51:49 +05302633 dispc_ovl_set_input_size(plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002634
Archit Taneja5b54ed32012-09-26 16:55:27 +05302635 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302636 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2637 out_height, ilace, five_taps, fieldmode,
Archit Taneja84a880f2012-09-26 16:57:37 +05302638 color_mode, rotation);
Archit Taneja78b687f2012-09-21 14:51:49 +05302639 dispc_ovl_set_output_size(plane, out_width, out_height);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002640 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002641 }
2642
Archit Tanejac35eeb22013-03-26 19:15:24 +05302643 dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, mirror,
2644 color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002645
Archit Taneja84a880f2012-09-26 16:57:37 +05302646 dispc_ovl_set_zorder(plane, caps, zorder);
2647 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2648 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002649
Archit Tanejad79db852012-09-22 12:30:17 +05302650 dispc_ovl_enable_replication(plane, caps, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302651
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002652 return 0;
2653}
2654
Archit Taneja84a880f2012-09-26 16:57:37 +05302655int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
Archit Taneja8ba85302012-09-26 17:00:37 +05302656 bool replication, const struct omap_video_timings *mgr_timings,
2657 bool mem_to_mem)
Archit Taneja84a880f2012-09-26 16:57:37 +05302658{
2659 int r;
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002660 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
Archit Taneja84a880f2012-09-26 16:57:37 +05302661 enum omap_channel channel;
2662
2663 channel = dispc_ovl_get_channel_out(plane);
2664
Arnd Bergmann24f13a62014-04-24 13:28:18 +01002665 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2666 " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2667 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
Archit Taneja84a880f2012-09-26 16:57:37 +05302668 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2669 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2670
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002671 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302672 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2673 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2674 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
Archit Taneja8ba85302012-09-26 17:00:37 +05302675 oi->rotation_type, replication, mgr_timings, mem_to_mem);
Archit Taneja84a880f2012-09-26 16:57:37 +05302676
2677 return r;
2678}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002679EXPORT_SYMBOL(dispc_ovl_setup);
Archit Taneja84a880f2012-09-26 16:57:37 +05302680
Archit Taneja749feff2012-08-31 12:32:52 +05302681int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302682 bool mem_to_mem, const struct omap_video_timings *mgr_timings)
Archit Taneja749feff2012-08-31 12:32:52 +05302683{
2684 int r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302685 u32 l;
Archit Taneja749feff2012-08-31 12:32:52 +05302686 enum omap_plane plane = OMAP_DSS_WB;
2687 const int pos_x = 0, pos_y = 0;
2688 const u8 zorder = 0, global_alpha = 0;
2689 const bool replication = false;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302690 bool truncation;
Archit Taneja749feff2012-08-31 12:32:52 +05302691 int in_width = mgr_timings->x_res;
2692 int in_height = mgr_timings->y_res;
2693 enum omap_overlay_caps caps =
2694 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2695
2696 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2697 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2698 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2699 wi->mirror);
2700
2701 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2702 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2703 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2704 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302705 replication, mgr_timings, mem_to_mem);
2706
2707 switch (wi->color_mode) {
2708 case OMAP_DSS_COLOR_RGB16:
2709 case OMAP_DSS_COLOR_RGB24P:
2710 case OMAP_DSS_COLOR_ARGB16:
2711 case OMAP_DSS_COLOR_RGBA16:
2712 case OMAP_DSS_COLOR_RGB12U:
2713 case OMAP_DSS_COLOR_ARGB16_1555:
2714 case OMAP_DSS_COLOR_XRGB16_1555:
2715 case OMAP_DSS_COLOR_RGBX16:
2716 truncation = true;
2717 break;
2718 default:
2719 truncation = false;
2720 break;
2721 }
2722
2723 /* setup extra DISPC_WB_ATTRIBUTES */
2724 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2725 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2726 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2727 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Archit Taneja749feff2012-08-31 12:32:52 +05302728
2729 return r;
2730}
2731
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002732int dispc_ovl_enable(enum omap_plane plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002733{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002734 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2735
Archit Taneja9b372c22011-05-06 11:45:49 +05302736 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002737
2738 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002739}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002740EXPORT_SYMBOL(dispc_ovl_enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002741
Tomi Valkeinen04bd8ac2012-10-10 14:13:15 +03002742bool dispc_ovl_enabled(enum omap_plane plane)
2743{
2744 return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2745}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002746EXPORT_SYMBOL(dispc_ovl_enabled);
Tomi Valkeinen04bd8ac2012-10-10 14:13:15 +03002747
Tomi Valkeinenf1a813d2012-10-19 14:16:06 +03002748void dispc_mgr_enable(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002749{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302750 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2751 /* flush posted write */
2752 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002753}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002754EXPORT_SYMBOL(dispc_mgr_enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002755
Tomi Valkeinen65398512012-10-10 11:44:17 +03002756bool dispc_mgr_is_enabled(enum omap_channel channel)
2757{
2758 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2759}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002760EXPORT_SYMBOL(dispc_mgr_is_enabled);
Tomi Valkeinen65398512012-10-10 11:44:17 +03002761
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302762void dispc_wb_enable(bool enable)
2763{
Tomi Valkeinen916188a2012-10-10 14:13:26 +03002764 dispc_ovl_enable(OMAP_DSS_WB, enable);
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302765}
2766
2767bool dispc_wb_is_enabled(void)
2768{
Tomi Valkeinen916188a2012-10-10 14:13:26 +03002769 return dispc_ovl_enabled(OMAP_DSS_WB);
Archit Taneja0b23e5b2012-09-22 12:39:33 +05302770}
2771
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002772static void dispc_lcd_enable_signal_polarity(bool act_high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002773{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002774 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2775 return;
2776
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002777 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002778}
2779
2780void dispc_lcd_enable_signal(bool enable)
2781{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002782 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2783 return;
2784
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002785 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002786}
2787
2788void dispc_pck_free_enable(bool enable)
2789{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002790 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2791 return;
2792
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002793 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002794}
2795
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002796static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002797{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302798 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002799}
2800
2801
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002802static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002803{
Archit Tanejad21f43b2012-06-21 09:45:11 +05302804 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002805}
2806
2807void dispc_set_loadmode(enum omap_dss_load_mode mode)
2808{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002809 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002810}
2811
2812
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002813static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002814{
Sumit Semwal8613b002010-12-02 11:27:09 +00002815 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002816}
2817
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002818static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002819 enum omap_dss_trans_key_type type,
2820 u32 trans_key)
2821{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302822 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002823
Sumit Semwal8613b002010-12-02 11:27:09 +00002824 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002825}
2826
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002827static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002828{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302829 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002830}
Archit Taneja11354dd2011-09-26 11:47:29 +05302831
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002832static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2833 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002834{
Archit Taneja11354dd2011-09-26 11:47:29 +05302835 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002836 return;
2837
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002838 if (ch == OMAP_DSS_CHANNEL_LCD)
2839 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002840 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002841 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002842}
Archit Taneja11354dd2011-09-26 11:47:29 +05302843
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002844void dispc_mgr_setup(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02002845 const struct omap_overlay_manager_info *info)
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002846{
2847 dispc_mgr_set_default_color(channel, info->default_color);
2848 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2849 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2850 dispc_mgr_enable_alpha_fixed_zorder(channel,
2851 info->partial_alpha_enabled);
2852 if (dss_has_feature(FEAT_CPR)) {
2853 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2854 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2855 }
2856}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002857EXPORT_SYMBOL(dispc_mgr_setup);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002858
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002859static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002860{
2861 int code;
2862
2863 switch (data_lines) {
2864 case 12:
2865 code = 0;
2866 break;
2867 case 16:
2868 code = 1;
2869 break;
2870 case 18:
2871 code = 2;
2872 break;
2873 case 24:
2874 code = 3;
2875 break;
2876 default:
2877 BUG();
2878 return;
2879 }
2880
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302881 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002882}
2883
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002884static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002885{
2886 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302887 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002888
2889 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302890 case DSS_IO_PAD_MODE_RESET:
2891 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002892 gpout1 = 0;
2893 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302894 case DSS_IO_PAD_MODE_RFBI:
2895 gpout0 = 1;
2896 gpout1 = 0;
2897 break;
2898 case DSS_IO_PAD_MODE_BYPASS:
2899 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002900 gpout1 = 1;
2901 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002902 default:
2903 BUG();
2904 return;
2905 }
2906
Archit Taneja569969d2011-08-22 17:41:57 +05302907 l = dispc_read_reg(DISPC_CONTROL);
2908 l = FLD_MOD(l, gpout0, 15, 15);
2909 l = FLD_MOD(l, gpout1, 16, 16);
2910 dispc_write_reg(DISPC_CONTROL, l);
2911}
2912
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002913static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
Archit Taneja569969d2011-08-22 17:41:57 +05302914{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302915 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002916}
2917
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002918void dispc_mgr_set_lcd_config(enum omap_channel channel,
2919 const struct dss_lcd_mgr_config *config)
2920{
2921 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
2922
2923 dispc_mgr_enable_stallmode(channel, config->stallmode);
2924 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
2925
2926 dispc_mgr_set_clock_div(channel, &config->clock_info);
2927
2928 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
2929
2930 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
2931
2932 dispc_mgr_set_lcd_type_tft(channel);
2933}
Tomi Valkeinen348be692012-11-07 18:17:35 +02002934EXPORT_SYMBOL(dispc_mgr_set_lcd_config);
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002935
Archit Taneja8f366162012-04-16 12:53:44 +05302936static bool _dispc_mgr_size_ok(u16 width, u16 height)
2937{
Archit Taneja33b89922012-11-14 13:50:15 +05302938 return width <= dispc.feat->mgr_width_max &&
2939 height <= dispc.feat->mgr_height_max;
Archit Taneja8f366162012-04-16 12:53:44 +05302940}
2941
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002942static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2943 int vsw, int vfp, int vbp)
2944{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302945 if (hsw < 1 || hsw > dispc.feat->sw_max ||
2946 hfp < 1 || hfp > dispc.feat->hp_max ||
2947 hbp < 1 || hbp > dispc.feat->hp_max ||
2948 vsw < 1 || vsw > dispc.feat->sw_max ||
2949 vfp < 0 || vfp > dispc.feat->vp_max ||
2950 vbp < 0 || vbp > dispc.feat->vp_max)
2951 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002952 return true;
2953}
2954
Archit Tanejaca5ca692013-03-26 19:15:22 +05302955static bool _dispc_mgr_pclk_ok(enum omap_channel channel,
2956 unsigned long pclk)
2957{
2958 if (dss_mgr_is_lcd(channel))
2959 return pclk <= dispc.feat->max_lcd_pclk ? true : false;
2960 else
2961 return pclk <= dispc.feat->max_tv_pclk ? true : false;
2962}
2963
Archit Taneja8f366162012-04-16 12:53:44 +05302964bool dispc_mgr_timings_ok(enum omap_channel channel,
Archit Tanejab917fa32012-04-27 01:07:28 +05302965 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002966{
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002967 if (!_dispc_mgr_size_ok(timings->x_res, timings->y_res))
2968 return false;
Archit Taneja8f366162012-04-16 12:53:44 +05302969
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002970 if (!_dispc_mgr_pclk_ok(channel, timings->pixelclock))
2971 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302972
2973 if (dss_mgr_is_lcd(channel)) {
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03002974 /* TODO: OMAP4+ supports interlace for LCD outputs */
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002975 if (timings->interlace)
2976 return false;
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03002977
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002978 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
Archit Tanejaca5ca692013-03-26 19:15:22 +05302979 timings->hbp, timings->vsw, timings->vfp,
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002980 timings->vbp))
2981 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302982 }
Archit Taneja8f366162012-04-16 12:53:44 +05302983
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002984 return true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002985}
2986
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002987static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
Archit Taneja655e2942012-06-21 10:37:43 +05302988 int hfp, int hbp, int vsw, int vfp, int vbp,
2989 enum omap_dss_signal_level vsync_level,
2990 enum omap_dss_signal_level hsync_level,
2991 enum omap_dss_signal_edge data_pclk_edge,
2992 enum omap_dss_signal_level de_level,
2993 enum omap_dss_signal_edge sync_pclk_edge)
2994
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002995{
Archit Taneja655e2942012-06-21 10:37:43 +05302996 u32 timing_h, timing_v, l;
Tomi Valkeinened351882014-10-02 17:58:49 +00002997 bool onoff, rf, ipc, vs, hs, de;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002998
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302999 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
3000 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
3001 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
3002 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
3003 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
3004 FLD_VAL(vbp, dispc.feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003005
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003006 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
3007 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05303008
Tomi Valkeinened351882014-10-02 17:58:49 +00003009 switch (vsync_level) {
3010 case OMAPDSS_SIG_ACTIVE_LOW:
3011 vs = true;
3012 break;
3013 case OMAPDSS_SIG_ACTIVE_HIGH:
3014 vs = false;
3015 break;
3016 default:
3017 BUG();
3018 }
3019
3020 switch (hsync_level) {
3021 case OMAPDSS_SIG_ACTIVE_LOW:
3022 hs = true;
3023 break;
3024 case OMAPDSS_SIG_ACTIVE_HIGH:
3025 hs = false;
3026 break;
3027 default:
3028 BUG();
3029 }
3030
3031 switch (de_level) {
3032 case OMAPDSS_SIG_ACTIVE_LOW:
3033 de = true;
3034 break;
3035 case OMAPDSS_SIG_ACTIVE_HIGH:
3036 de = false;
3037 break;
3038 default:
3039 BUG();
3040 }
3041
Archit Taneja655e2942012-06-21 10:37:43 +05303042 switch (data_pclk_edge) {
3043 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3044 ipc = false;
3045 break;
3046 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3047 ipc = true;
3048 break;
Archit Taneja655e2942012-06-21 10:37:43 +05303049 default:
3050 BUG();
3051 }
3052
Tomi Valkeinen7a163602014-10-02 17:58:48 +00003053 /* always use the 'rf' setting */
3054 onoff = true;
3055
Archit Taneja655e2942012-06-21 10:37:43 +05303056 switch (sync_pclk_edge) {
Archit Taneja655e2942012-06-21 10:37:43 +05303057 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
Archit Taneja655e2942012-06-21 10:37:43 +05303058 rf = false;
3059 break;
3060 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
Archit Taneja655e2942012-06-21 10:37:43 +05303061 rf = true;
3062 break;
3063 default:
3064 BUG();
Joe Perchescf6ac4ce2013-10-08 16:23:24 -07003065 }
Archit Taneja655e2942012-06-21 10:37:43 +05303066
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003067 l = FLD_VAL(onoff, 17, 17) |
3068 FLD_VAL(rf, 16, 16) |
Tomi Valkeinened351882014-10-02 17:58:49 +00003069 FLD_VAL(de, 15, 15) |
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003070 FLD_VAL(ipc, 14, 14) |
Tomi Valkeinened351882014-10-02 17:58:49 +00003071 FLD_VAL(hs, 13, 13) |
3072 FLD_VAL(vs, 12, 12);
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003073
Archit Taneja655e2942012-06-21 10:37:43 +05303074 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003075
3076 if (dispc.syscon_pol) {
3077 const int shifts[] = {
3078 [OMAP_DSS_CHANNEL_LCD] = 0,
3079 [OMAP_DSS_CHANNEL_LCD2] = 1,
3080 [OMAP_DSS_CHANNEL_LCD3] = 2,
3081 };
3082
3083 u32 mask, val;
3084
3085 mask = (1 << 0) | (1 << 3) | (1 << 6);
3086 val = (rf << 0) | (ipc << 3) | (onoff << 6);
3087
3088 mask <<= 16 + shifts[channel];
3089 val <<= 16 + shifts[channel];
3090
3091 regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset,
3092 mask, val);
3093 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003094}
3095
3096/* change name to mode? */
Archit Tanejac51d9212012-04-16 12:53:43 +05303097void dispc_mgr_set_timings(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003098 const struct omap_video_timings *timings)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003099{
3100 unsigned xtot, ytot;
3101 unsigned long ht, vt;
Archit Taneja2aefad42012-05-18 14:36:54 +05303102 struct omap_video_timings t = *timings;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003103
Archit Taneja2aefad42012-05-18 14:36:54 +05303104 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
Archit Tanejac51d9212012-04-16 12:53:43 +05303105
Archit Taneja2aefad42012-05-18 14:36:54 +05303106 if (!dispc_mgr_timings_ok(channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05303107 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003108 return;
3109 }
Archit Tanejac51d9212012-04-16 12:53:43 +05303110
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303111 if (dss_mgr_is_lcd(channel)) {
Archit Taneja2aefad42012-05-18 14:36:54 +05303112 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
Archit Taneja655e2942012-06-21 10:37:43 +05303113 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
3114 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
Archit Tanejac51d9212012-04-16 12:53:43 +05303115
Archit Taneja2aefad42012-05-18 14:36:54 +05303116 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
3117 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
Archit Tanejac51d9212012-04-16 12:53:43 +05303118
Tomi Valkeinend8d789412013-04-10 14:12:14 +03003119 ht = timings->pixelclock / xtot;
3120 vt = timings->pixelclock / xtot / ytot;
Archit Tanejac51d9212012-04-16 12:53:43 +05303121
Tomi Valkeinend8d789412013-04-10 14:12:14 +03003122 DSSDBG("pck %u\n", timings->pixelclock);
Archit Tanejac51d9212012-04-16 12:53:43 +05303123 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Archit Taneja2aefad42012-05-18 14:36:54 +05303124 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
Archit Taneja655e2942012-06-21 10:37:43 +05303125 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3126 t.vsync_level, t.hsync_level, t.data_pclk_edge,
3127 t.de_level, t.sync_pclk_edge);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003128
Archit Tanejac51d9212012-04-16 12:53:43 +05303129 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05303130 } else {
Archit Taneja23c8f882012-06-28 11:15:51 +05303131 if (t.interlace == true)
Archit Taneja2aefad42012-05-18 14:36:54 +05303132 t.y_res /= 2;
Archit Tanejac51d9212012-04-16 12:53:43 +05303133 }
Archit Taneja8f366162012-04-16 12:53:44 +05303134
Archit Taneja2aefad42012-05-18 14:36:54 +05303135 dispc_mgr_set_size(channel, t.x_res, t.y_res);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003136}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003137EXPORT_SYMBOL(dispc_mgr_set_timings);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003138
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003139static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003140 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003141{
3142 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003143 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003144
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003145 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003146 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003147
3148 if (dss_has_feature(FEAT_CORE_CLK_DIV) == false &&
3149 channel == OMAP_DSS_CHANNEL_LCD)
3150 dispc.core_clk_rate = dispc_fclk_rate() / lck_div;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003151}
3152
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003153static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00003154 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003155{
3156 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003157 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003158 *lck_div = FLD_GET(l, 23, 16);
3159 *pck_div = FLD_GET(l, 7, 0);
3160}
3161
3162unsigned long dispc_fclk_rate(void)
3163{
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003164 struct dss_pll *pll;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003165 unsigned long r = 0;
3166
Taneja, Archit66534e82011-03-08 05:50:34 -06003167 switch (dss_get_dispc_clk_source()) {
Archit Taneja89a35e52011-04-12 13:52:23 +05303168 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen5aaee692012-12-12 10:37:03 +02003169 r = dss_get_dispc_clk_rate();
Taneja, Archit66534e82011-03-08 05:50:34 -06003170 break;
Archit Taneja89a35e52011-04-12 13:52:23 +05303171 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003172 pll = dss_pll_find("dsi0");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003173 if (!pll)
3174 pll = dss_pll_find("video0");
3175
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003176 r = pll->cinfo.clkout[0];
Taneja, Archit66534e82011-03-08 05:50:34 -06003177 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +05303178 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003179 pll = dss_pll_find("dsi1");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003180 if (!pll)
3181 pll = dss_pll_find("video1");
3182
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003183 r = pll->cinfo.clkout[0];
Archit Taneja5a8b5722011-05-12 17:26:29 +05303184 break;
Taneja, Archit66534e82011-03-08 05:50:34 -06003185 default:
3186 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003187 return 0;
Taneja, Archit66534e82011-03-08 05:50:34 -06003188 }
3189
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003190 return r;
3191}
3192
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003193unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003194{
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003195 struct dss_pll *pll;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003196 int lcd;
3197 unsigned long r;
3198 u32 l;
3199
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003200 if (dss_mgr_is_lcd(channel)) {
3201 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003202
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003203 lcd = FLD_GET(l, 23, 16);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003204
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003205 switch (dss_get_lcd_clk_source(channel)) {
3206 case OMAP_DSS_CLK_SRC_FCK:
Tomi Valkeinen5aaee692012-12-12 10:37:03 +02003207 r = dss_get_dispc_clk_rate();
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003208 break;
3209 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003210 pll = dss_pll_find("dsi0");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003211 if (!pll)
3212 pll = dss_pll_find("video0");
3213
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003214 r = pll->cinfo.clkout[0];
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003215 break;
3216 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003217 pll = dss_pll_find("dsi1");
Tomi Valkeinen93550922014-12-31 11:25:48 +02003218 if (!pll)
3219 pll = dss_pll_find("video1");
3220
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +03003221 r = pll->cinfo.clkout[0];
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003222 break;
3223 default:
3224 BUG();
3225 return 0;
3226 }
3227
3228 return r / lcd;
3229 } else {
3230 return dispc_fclk_rate();
Taneja, Architea751592011-03-08 05:50:35 -06003231 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003232}
3233
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003234unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003235{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003236 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003237
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303238 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303239 int pcd;
3240 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003241
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303242 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003243
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303244 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003245
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303246 r = dispc_mgr_lclk_rate(channel);
3247
3248 return r / pcd;
3249 } else {
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003250 return dispc.tv_pclk_rate;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303251 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003252}
3253
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003254void dispc_set_tv_pclk(unsigned long pclk)
3255{
3256 dispc.tv_pclk_rate = pclk;
3257}
3258
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303259unsigned long dispc_core_clk_rate(void)
3260{
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003261 return dispc.core_clk_rate;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303262}
3263
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303264static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3265{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003266 enum omap_channel channel;
3267
3268 if (plane == OMAP_DSS_WB)
3269 return 0;
3270
3271 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303272
3273 return dispc_mgr_pclk_rate(channel);
3274}
3275
3276static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3277{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003278 enum omap_channel channel;
3279
3280 if (plane == OMAP_DSS_WB)
3281 return 0;
3282
3283 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303284
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003285 return dispc_mgr_lclk_rate(channel);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303286}
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003287
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303288static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003289{
3290 int lcd, pcd;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303291 enum omap_dss_clk_source lcd_clk_src;
3292
3293 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3294
3295 lcd_clk_src = dss_get_lcd_clk_source(channel);
3296
3297 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3298 dss_get_generic_clk_source_name(lcd_clk_src),
3299 dss_feat_get_clk_source_name(lcd_clk_src));
3300
3301 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3302
3303 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3304 dispc_mgr_lclk_rate(channel), lcd);
3305 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3306 dispc_mgr_pclk_rate(channel), pcd);
3307}
3308
3309void dispc_dump_clocks(struct seq_file *s)
3310{
3311 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003312 u32 l;
Archit Taneja89a35e52011-04-12 13:52:23 +05303313 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003314
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003315 if (dispc_runtime_get())
3316 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003317
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003318 seq_printf(s, "- DISPC -\n");
3319
Archit Taneja067a57e2011-03-02 11:57:25 +05303320 seq_printf(s, "dispc fclk source = %s (%s)\n",
3321 dss_get_generic_clk_source_name(dispc_clk_src),
3322 dss_feat_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003323
3324 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00003325
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003326 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3327 seq_printf(s, "- DISPC-CORE-CLK -\n");
3328 l = dispc_read_reg(DISPC_DIVISOR);
3329 lcd = FLD_GET(l, 23, 16);
3330
3331 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3332 (dispc_fclk_rate()/lcd), lcd);
3333 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003334
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303335 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003336
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303337 if (dss_has_feature(FEAT_MGR_LCD2))
3338 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3339 if (dss_has_feature(FEAT_MGR_LCD3))
3340 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003341
3342 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003343}
3344
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003345static void dispc_dump_regs(struct seq_file *s)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003346{
Archit Taneja4dd2da12011-08-05 19:06:01 +05303347 int i, j;
3348 const char *mgr_names[] = {
3349 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3350 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3351 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303352 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303353 };
3354 const char *ovl_names[] = {
3355 [OMAP_DSS_GFX] = "GFX",
3356 [OMAP_DSS_VIDEO1] = "VID1",
3357 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303358 [OMAP_DSS_VIDEO3] = "VID3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303359 };
3360 const char **p_names;
3361
Archit Taneja9b372c22011-05-06 11:45:49 +05303362#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003363
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003364 if (dispc_runtime_get())
3365 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003366
Archit Taneja5010be82011-08-05 19:06:00 +05303367 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003368 DUMPREG(DISPC_REVISION);
3369 DUMPREG(DISPC_SYSCONFIG);
3370 DUMPREG(DISPC_SYSSTATUS);
3371 DUMPREG(DISPC_IRQSTATUS);
3372 DUMPREG(DISPC_IRQENABLE);
3373 DUMPREG(DISPC_CONTROL);
3374 DUMPREG(DISPC_CONFIG);
3375 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003376 DUMPREG(DISPC_LINE_STATUS);
3377 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05303378 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3379 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003380 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003381 if (dss_has_feature(FEAT_MGR_LCD2)) {
3382 DUMPREG(DISPC_CONTROL2);
3383 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003384 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303385 if (dss_has_feature(FEAT_MGR_LCD3)) {
3386 DUMPREG(DISPC_CONTROL3);
3387 DUMPREG(DISPC_CONFIG3);
3388 }
Tomi Valkeinen29fceee2013-11-14 11:38:25 +02003389 if (dss_has_feature(FEAT_MFLAG))
3390 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003391
Archit Taneja5010be82011-08-05 19:06:00 +05303392#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003393
Archit Taneja5010be82011-08-05 19:06:00 +05303394#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05303395#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003396 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303397 dispc_read_reg(DISPC_REG(i, r)))
3398
Archit Taneja4dd2da12011-08-05 19:06:01 +05303399 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303400
Archit Taneja4dd2da12011-08-05 19:06:01 +05303401 /* DISPC channel specific registers */
3402 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3403 DUMPREG(i, DISPC_DEFAULT_COLOR);
3404 DUMPREG(i, DISPC_TRANS_COLOR);
3405 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003406
Archit Taneja4dd2da12011-08-05 19:06:01 +05303407 if (i == OMAP_DSS_CHANNEL_DIGIT)
3408 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303409
Archit Taneja4dd2da12011-08-05 19:06:01 +05303410 DUMPREG(i, DISPC_TIMING_H);
3411 DUMPREG(i, DISPC_TIMING_V);
3412 DUMPREG(i, DISPC_POL_FREQ);
3413 DUMPREG(i, DISPC_DIVISORo);
Archit Taneja5010be82011-08-05 19:06:00 +05303414
Archit Taneja4dd2da12011-08-05 19:06:01 +05303415 DUMPREG(i, DISPC_DATA_CYCLE1);
3416 DUMPREG(i, DISPC_DATA_CYCLE2);
3417 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003418
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003419 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303420 DUMPREG(i, DISPC_CPR_COEF_R);
3421 DUMPREG(i, DISPC_CPR_COEF_G);
3422 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003423 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003424 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003425
Archit Taneja4dd2da12011-08-05 19:06:01 +05303426 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003427
Archit Taneja4dd2da12011-08-05 19:06:01 +05303428 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3429 DUMPREG(i, DISPC_OVL_BA0);
3430 DUMPREG(i, DISPC_OVL_BA1);
3431 DUMPREG(i, DISPC_OVL_POSITION);
3432 DUMPREG(i, DISPC_OVL_SIZE);
3433 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3434 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3435 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3436 DUMPREG(i, DISPC_OVL_ROW_INC);
3437 DUMPREG(i, DISPC_OVL_PIXEL_INC);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003438
Archit Taneja4dd2da12011-08-05 19:06:01 +05303439 if (dss_has_feature(FEAT_PRELOAD))
3440 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003441 if (dss_has_feature(FEAT_MFLAG))
3442 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003443
Archit Taneja4dd2da12011-08-05 19:06:01 +05303444 if (i == OMAP_DSS_GFX) {
3445 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3446 DUMPREG(i, DISPC_OVL_TABLE_BA);
3447 continue;
3448 }
3449
3450 DUMPREG(i, DISPC_OVL_FIR);
3451 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3452 DUMPREG(i, DISPC_OVL_ACCU0);
3453 DUMPREG(i, DISPC_OVL_ACCU1);
3454 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3455 DUMPREG(i, DISPC_OVL_BA0_UV);
3456 DUMPREG(i, DISPC_OVL_BA1_UV);
3457 DUMPREG(i, DISPC_OVL_FIR2);
3458 DUMPREG(i, DISPC_OVL_ACCU2_0);
3459 DUMPREG(i, DISPC_OVL_ACCU2_1);
3460 }
3461 if (dss_has_feature(FEAT_ATTR2))
3462 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
Archit Taneja5010be82011-08-05 19:06:00 +05303463 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003464
Archit Taneja5010be82011-08-05 19:06:00 +05303465#undef DISPC_REG
3466#undef DUMPREG
3467
3468#define DISPC_REG(plane, name, i) name(plane, i)
3469#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303470 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003471 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303472 dispc_read_reg(DISPC_REG(plane, name, i)))
3473
Archit Taneja4dd2da12011-08-05 19:06:01 +05303474 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303475
Archit Taneja4dd2da12011-08-05 19:06:01 +05303476 /* start from OMAP_DSS_VIDEO1 */
3477 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3478 for (j = 0; j < 8; j++)
3479 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303480
Archit Taneja4dd2da12011-08-05 19:06:01 +05303481 for (j = 0; j < 8; j++)
3482 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303483
Archit Taneja4dd2da12011-08-05 19:06:01 +05303484 for (j = 0; j < 5; j++)
3485 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003486
Archit Taneja4dd2da12011-08-05 19:06:01 +05303487 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3488 for (j = 0; j < 8; j++)
3489 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3490 }
Amber Jainab5ca072011-05-19 19:47:53 +05303491
Archit Taneja4dd2da12011-08-05 19:06:01 +05303492 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3493 for (j = 0; j < 8; j++)
3494 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303495
Archit Taneja4dd2da12011-08-05 19:06:01 +05303496 for (j = 0; j < 8; j++)
3497 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303498
Archit Taneja4dd2da12011-08-05 19:06:01 +05303499 for (j = 0; j < 8; j++)
3500 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3501 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003502 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003503
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003504 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05303505
3506#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003507#undef DUMPREG
3508}
3509
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003510/* calculate clock rates using dividers in cinfo */
3511int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3512 struct dispc_clock_info *cinfo)
3513{
3514 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3515 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003516 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003517 return -EINVAL;
3518
3519 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3520 cinfo->pck = cinfo->lck / cinfo->pck_div;
3521
3522 return 0;
3523}
3524
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003525bool dispc_div_calc(unsigned long dispc,
3526 unsigned long pck_min, unsigned long pck_max,
3527 dispc_div_calc_func func, void *data)
3528{
3529 int lckd, lckd_start, lckd_stop;
3530 int pckd, pckd_start, pckd_stop;
3531 unsigned long pck, lck;
3532 unsigned long lck_max;
3533 unsigned long pckd_hw_min, pckd_hw_max;
3534 unsigned min_fck_per_pck;
3535 unsigned long fck;
3536
3537#ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3538 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3539#else
3540 min_fck_per_pck = 0;
3541#endif
3542
3543 pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3544 pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3545
3546 lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
3547
3548 pck_min = pck_min ? pck_min : 1;
3549 pck_max = pck_max ? pck_max : ULONG_MAX;
3550
3551 lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul);
3552 lckd_stop = min(dispc / pck_min, 255ul);
3553
3554 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3555 lck = dispc / lckd;
3556
3557 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3558 pckd_stop = min(lck / pck_min, pckd_hw_max);
3559
3560 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3561 pck = lck / pckd;
3562
3563 /*
3564 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3565 * clock, which means we're configuring DISPC fclk here
3566 * also. Thus we need to use the calculated lck. For
3567 * OMAP4+ the DISPC fclk is a separate clock.
3568 */
3569 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3570 fck = dispc_core_clk_rate();
3571 else
3572 fck = lck;
3573
3574 if (fck < pck * min_fck_per_pck)
3575 continue;
3576
3577 if (func(lckd, pckd, lck, pck, data))
3578 return true;
3579 }
3580 }
3581
3582 return false;
3583}
3584
Archit Tanejaf0d08f82012-06-29 14:00:54 +05303585void dispc_mgr_set_clock_div(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003586 const struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003587{
3588 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3589 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3590
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003591 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003592}
3593
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003594int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003595 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003596{
3597 unsigned long fck;
3598
3599 fck = dispc_fclk_rate();
3600
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003601 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3602 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003603
3604 cinfo->lck = fck / cinfo->lck_div;
3605 cinfo->pck = cinfo->lck / cinfo->pck_div;
3606
3607 return 0;
3608}
3609
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003610u32 dispc_read_irqstatus(void)
3611{
3612 return dispc_read_reg(DISPC_IRQSTATUS);
3613}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003614EXPORT_SYMBOL(dispc_read_irqstatus);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003615
3616void dispc_clear_irqstatus(u32 mask)
3617{
3618 dispc_write_reg(DISPC_IRQSTATUS, mask);
3619}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003620EXPORT_SYMBOL(dispc_clear_irqstatus);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003621
3622u32 dispc_read_irqenable(void)
3623{
3624 return dispc_read_reg(DISPC_IRQENABLE);
3625}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003626EXPORT_SYMBOL(dispc_read_irqenable);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003627
3628void dispc_write_irqenable(u32 mask)
3629{
3630 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3631
3632 /* clear the irqstatus for newly enabled irqs */
3633 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3634
3635 dispc_write_reg(DISPC_IRQENABLE, mask);
3636}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003637EXPORT_SYMBOL(dispc_write_irqenable);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003638
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003639void dispc_enable_sidle(void)
3640{
3641 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3642}
3643
3644void dispc_disable_sidle(void)
3645{
3646 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3647}
3648
3649static void _omap_dispc_initial_config(void)
3650{
3651 u32 l;
3652
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003653 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3654 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3655 l = dispc_read_reg(DISPC_DIVISOR);
3656 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3657 l = FLD_MOD(l, 1, 0, 0);
3658 l = FLD_MOD(l, 1, 23, 16);
3659 dispc_write_reg(DISPC_DIVISOR, l);
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003660
3661 dispc.core_clk_rate = dispc_fclk_rate();
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003662 }
3663
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003664 /* FUNCGATED */
Archit Taneja6ced40b2010-12-02 11:27:13 +00003665 if (dss_has_feature(FEAT_FUNCGATED))
3666 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003667
Archit Taneja6e5264b2012-09-11 12:04:47 +05303668 dispc_setup_color_conv_coef();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003669
3670 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3671
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003672 dispc_init_fifos();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003673
3674 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05303675
3676 dispc_ovl_enable_zorder_planes();
Archit Tanejad0df9a22013-03-26 19:15:25 +05303677
3678 if (dispc.feat->mstandby_workaround)
3679 REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0);
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00003680
3681 if (dss_has_feature(FEAT_MFLAG))
3682 dispc_init_mflag();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003683}
3684
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303685static const struct dispc_features omap24xx_dispc_feats __initconst = {
3686 .sw_start = 5,
3687 .fp_start = 15,
3688 .bp_start = 27,
3689 .sw_max = 64,
3690 .vp_max = 255,
3691 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303692 .mgr_width_start = 10,
3693 .mgr_height_start = 26,
3694 .mgr_width_max = 2048,
3695 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303696 .max_lcd_pclk = 66500000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303697 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3698 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003699 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003700 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303701 .set_max_preload = false,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303702};
3703
3704static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
3705 .sw_start = 5,
3706 .fp_start = 15,
3707 .bp_start = 27,
3708 .sw_max = 64,
3709 .vp_max = 255,
3710 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303711 .mgr_width_start = 10,
3712 .mgr_height_start = 26,
3713 .mgr_width_max = 2048,
3714 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303715 .max_lcd_pclk = 173000000,
3716 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303717 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3718 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003719 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003720 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303721 .set_max_preload = false,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303722};
3723
3724static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
3725 .sw_start = 7,
3726 .fp_start = 19,
3727 .bp_start = 31,
3728 .sw_max = 256,
3729 .vp_max = 4095,
3730 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303731 .mgr_width_start = 10,
3732 .mgr_height_start = 26,
3733 .mgr_width_max = 2048,
3734 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303735 .max_lcd_pclk = 173000000,
3736 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303737 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3738 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003739 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003740 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303741 .set_max_preload = false,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303742};
3743
3744static const struct dispc_features omap44xx_dispc_feats __initconst = {
3745 .sw_start = 7,
3746 .fp_start = 19,
3747 .bp_start = 31,
3748 .sw_max = 256,
3749 .vp_max = 4095,
3750 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303751 .mgr_width_start = 10,
3752 .mgr_height_start = 26,
3753 .mgr_width_max = 2048,
3754 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303755 .max_lcd_pclk = 170000000,
3756 .max_tv_pclk = 185625000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303757 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3758 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003759 .num_fifos = 5,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03003760 .gfx_fifo_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303761 .set_max_preload = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303762};
3763
Archit Taneja264236f2012-11-14 13:50:16 +05303764static const struct dispc_features omap54xx_dispc_feats __initconst = {
3765 .sw_start = 7,
3766 .fp_start = 19,
3767 .bp_start = 31,
3768 .sw_max = 256,
3769 .vp_max = 4095,
3770 .hp_max = 4096,
3771 .mgr_width_start = 11,
3772 .mgr_height_start = 27,
3773 .mgr_width_max = 4096,
3774 .mgr_height_max = 4096,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303775 .max_lcd_pclk = 170000000,
3776 .max_tv_pclk = 186000000,
Archit Taneja264236f2012-11-14 13:50:16 +05303777 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3778 .calc_core_clk = calc_core_clk_44xx,
3779 .num_fifos = 5,
3780 .gfx_fifo_workaround = true,
Archit Tanejad0df9a22013-03-26 19:15:25 +05303781 .mstandby_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303782 .set_max_preload = true,
Archit Taneja264236f2012-11-14 13:50:16 +05303783};
3784
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003785static int __init dispc_init_features(struct platform_device *pdev)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303786{
3787 const struct dispc_features *src;
3788 struct dispc_features *dst;
3789
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003790 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303791 if (!dst) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003792 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303793 return -ENOMEM;
3794 }
3795
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +03003796 switch (omapdss_get_version()) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003797 case OMAPDSS_VER_OMAP24xx:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303798 src = &omap24xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003799 break;
3800
3801 case OMAPDSS_VER_OMAP34xx_ES1:
3802 src = &omap34xx_rev1_0_dispc_feats;
3803 break;
3804
3805 case OMAPDSS_VER_OMAP34xx_ES3:
3806 case OMAPDSS_VER_OMAP3630:
3807 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +05303808 case OMAPDSS_VER_AM43xx:
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003809 src = &omap34xx_rev3_0_dispc_feats;
3810 break;
3811
3812 case OMAPDSS_VER_OMAP4430_ES1:
3813 case OMAPDSS_VER_OMAP4430_ES2:
3814 case OMAPDSS_VER_OMAP4:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303815 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003816 break;
3817
3818 case OMAPDSS_VER_OMAP5:
Tomi Valkeinen93550922014-12-31 11:25:48 +02003819 case OMAPDSS_VER_DRA7xx:
Archit Taneja264236f2012-11-14 13:50:16 +05303820 src = &omap54xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003821 break;
3822
3823 default:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303824 return -ENODEV;
3825 }
3826
3827 memcpy(dst, src, sizeof(*dst));
3828 dispc.feat = dst;
3829
3830 return 0;
3831}
3832
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003833static irqreturn_t dispc_irq_handler(int irq, void *arg)
3834{
3835 if (!dispc.is_enabled)
3836 return IRQ_NONE;
3837
3838 return dispc.user_handler(irq, dispc.user_data);
3839}
3840
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003841int dispc_request_irq(irq_handler_t handler, void *dev_id)
3842{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003843 int r;
3844
3845 if (dispc.user_handler != NULL)
3846 return -EBUSY;
3847
3848 dispc.user_handler = handler;
3849 dispc.user_data = dev_id;
3850
3851 /* ensure the dispc_irq_handler sees the values above */
3852 smp_wmb();
3853
3854 r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler,
3855 IRQF_SHARED, "OMAP DISPC", &dispc);
3856 if (r) {
3857 dispc.user_handler = NULL;
3858 dispc.user_data = NULL;
3859 }
3860
3861 return r;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003862}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003863EXPORT_SYMBOL(dispc_request_irq);
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003864
3865void dispc_free_irq(void *dev_id)
3866{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003867 devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc);
3868
3869 dispc.user_handler = NULL;
3870 dispc.user_data = NULL;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003871}
Tomi Valkeinen348be692012-11-07 18:17:35 +02003872EXPORT_SYMBOL(dispc_free_irq);
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003873
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003874/* DISPC HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003875static int __init omap_dispchw_probe(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003876{
3877 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00003878 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003879 struct resource *dispc_mem;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003880 struct device_node *np = pdev->dev.of_node;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003881
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003882 dispc.pdev = pdev;
3883
Tomi Valkeinend49cd152014-11-10 12:23:00 +02003884 spin_lock_init(&dispc.control_lock);
3885
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003886 r = dispc_init_features(dispc.pdev);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303887 if (r)
3888 return r;
3889
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003890 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3891 if (!dispc_mem) {
3892 DSSERR("can't get IORESOURCE_MEM DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003893 return -EINVAL;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003894 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003895
Julia Lawall6e2a14d2012-01-24 14:00:45 +01003896 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3897 resource_size(dispc_mem));
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003898 if (!dispc.base) {
3899 DSSERR("can't ioremap DISPC\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003900 return -ENOMEM;
archit tanejaaffe3602011-02-23 08:41:03 +00003901 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003902
archit tanejaaffe3602011-02-23 08:41:03 +00003903 dispc.irq = platform_get_irq(dispc.pdev, 0);
3904 if (dispc.irq < 0) {
3905 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02003906 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00003907 }
3908
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003909 if (np && of_property_read_bool(np, "syscon-pol")) {
3910 dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
3911 if (IS_ERR(dispc.syscon_pol)) {
3912 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
3913 return PTR_ERR(dispc.syscon_pol);
3914 }
3915
3916 if (of_property_read_u32_index(np, "syscon-pol", 1,
3917 &dispc.syscon_pol_offset)) {
3918 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
3919 return -EINVAL;
3920 }
3921 }
3922
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003923 pm_runtime_enable(&pdev->dev);
3924
3925 r = dispc_runtime_get();
3926 if (r)
3927 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003928
3929 _omap_dispc_initial_config();
3930
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003931 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00003932 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003933 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3934
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003935 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003936
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03003937 dss_init_overlay_managers();
3938
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003939 dss_debugfs_create_file("dispc", dispc_dump_regs);
3940
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003941 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003942
3943err_runtime_get:
3944 pm_runtime_disable(&pdev->dev);
archit tanejaaffe3602011-02-23 08:41:03 +00003945 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003946}
3947
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02003948static int __exit omap_dispchw_remove(struct platform_device *pdev)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003949{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003950 pm_runtime_disable(&pdev->dev);
3951
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03003952 dss_uninit_overlay_managers();
3953
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00003954 return 0;
3955}
3956
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003957static int dispc_runtime_suspend(struct device *dev)
3958{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003959 dispc.is_enabled = false;
3960 /* ensure the dispc_irq_handler sees the is_enabled value */
3961 smp_wmb();
3962 /* wait for current handler to finish before turning the DISPC off */
3963 synchronize_irq(dispc.irq);
3964
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003965 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003966
3967 return 0;
3968}
3969
3970static int dispc_runtime_resume(struct device *dev)
3971{
Tomi Valkeinen9229b512014-02-14 09:37:09 +02003972 /*
3973 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
3974 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
3975 * _omap_dispc_initial_config(). We can thus use it to detect if
3976 * we have lost register context.
3977 */
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003978 if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
3979 _omap_dispc_initial_config();
Tomi Valkeinen9229b512014-02-14 09:37:09 +02003980
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003981 dispc_restore_context();
3982 }
Tomi Valkeinenbe07dcd72013-11-21 16:01:40 +02003983
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003984 dispc.is_enabled = true;
3985 /* ensure the dispc_irq_handler sees the is_enabled value */
3986 smp_wmb();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003987
3988 return 0;
3989}
3990
3991static const struct dev_pm_ops dispc_pm_ops = {
3992 .runtime_suspend = dispc_runtime_suspend,
3993 .runtime_resume = dispc_runtime_resume,
3994};
3995
Tomi Valkeinend7977f82013-12-17 11:54:02 +02003996static const struct of_device_id dispc_of_match[] = {
3997 { .compatible = "ti,omap2-dispc", },
3998 { .compatible = "ti,omap3-dispc", },
3999 { .compatible = "ti,omap4-dispc", },
Tomi Valkeinen2e7e6b62014-04-16 13:16:43 +03004000 { .compatible = "ti,omap5-dispc", },
Tomi Valkeinen93550922014-12-31 11:25:48 +02004001 { .compatible = "ti,dra7-dispc", },
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004002 {},
4003};
4004
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004005static struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004006 .remove = __exit_p(omap_dispchw_remove),
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004007 .driver = {
4008 .name = "omapdss_dispc",
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004009 .pm = &dispc_pm_ops,
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004010 .of_match_table = dispc_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +03004011 .suppress_bind_attrs = true,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004012 },
4013};
4014
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004015int __init dispc_init_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004016{
Tomi Valkeinen11436e12012-03-07 12:53:18 +02004017 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004018}
4019
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004020void __exit dispc_uninit_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004021{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02004022 platform_driver_unregister(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004023}