blob: 53e2c93a5455671f96c9782c4976b5d9b5d966fc [file] [log] [blame]
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001/*
2 * linux/drivers/video/omap2/dss/dispc.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#define DSS_SUBSYS_NAME "DISPC"
24
25#include <linux/kernel.h>
26#include <linux/dma-mapping.h>
27#include <linux/vmalloc.h>
Paul Gortmakera8a35932011-07-10 13:20:26 -040028#include <linux/export.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020029#include <linux/clk.h>
30#include <linux/io.h>
31#include <linux/jiffies.h>
32#include <linux/seq_file.h>
33#include <linux/delay.h>
34#include <linux/workqueue.h>
Tomi Valkeinenab83b142010-06-09 15:31:01 +030035#include <linux/hardirq.h>
Tomi Valkeinen24e62892011-05-23 11:51:18 +030036#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030037#include <linux/pm_runtime.h>
Tomi Valkeinen33366d02012-09-28 13:54:35 +030038#include <linux/sizes.h>
Tomi Valkeinen0006fd62014-09-05 19:15:03 +000039#include <linux/mfd/syscon.h>
40#include <linux/regmap.h>
41#include <linux/of.h>
Tomi Valkeinen736e60d2015-06-04 15:22:23 +030042#include <linux/component.h>
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +030043#include <drm/drm_fourcc.h>
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +030044#include <drm/drm_blend.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020045
Peter Ujfalusi32043da2016-05-27 14:40:49 +030046#include "omapdss.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020047#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053048#include "dss_features.h"
Archit Taneja9b372c22011-05-06 11:45:49 +053049#include "dispc.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020050
51/* DISPC */
Sumit Semwal8613b002010-12-02 11:27:09 +000052#define DISPC_SZ_REGS SZ_4K
Tomi Valkeinen80c39712009-11-12 11:41:42 +020053
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030054enum omap_burst_size {
55 BURST_SIZE_X2 = 0,
56 BURST_SIZE_X4 = 1,
57 BURST_SIZE_X8 = 2,
58};
59
Tomi Valkeinen80c39712009-11-12 11:41:42 +020060#define REG_GET(idx, start, end) \
61 FLD_GET(dispc_read_reg(idx), start, end)
62
63#define REG_FLD_MOD(idx, val, start, end) \
64 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
65
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053066struct dispc_features {
67 u8 sw_start;
68 u8 fp_start;
69 u8 bp_start;
70 u16 sw_max;
71 u16 vp_max;
72 u16 hp_max;
Archit Taneja33b89922012-11-14 13:50:15 +053073 u8 mgr_width_start;
74 u8 mgr_height_start;
75 u16 mgr_width_max;
76 u16 mgr_height_max;
Archit Tanejaca5ca692013-03-26 19:15:22 +053077 unsigned long max_lcd_pclk;
78 unsigned long max_tv_pclk;
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +030079 int (*calc_scaling) (unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030080 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053081 u16 width, u16 height, u16 out_width, u16 out_height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +030082 u32 fourcc, bool *five_taps,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053083 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +053084 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
Tomi Valkeinen8702ee52012-10-19 15:36:11 +030085 unsigned long (*calc_core_clk) (unsigned long pclk,
Archit Taneja8ba85302012-09-26 17:00:37 +053086 u16 width, u16 height, u16 out_width, u16 out_height,
87 bool mem_to_mem);
Tomi Valkeinen42a69612012-08-22 16:56:57 +030088 u8 num_fifos;
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +030089
90 /* swap GFX & WB fifos */
91 bool gfx_fifo_workaround:1;
Tomi Valkeinencffa9472012-11-08 10:01:33 +020092
93 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
94 bool no_framedone_tv:1;
Archit Tanejad0df9a22013-03-26 19:15:25 +053095
96 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
97 bool mstandby_workaround:1;
Archit Taneja8bc65552013-12-17 16:40:21 +053098
99 bool set_max_preload:1;
Tomi Valkeinenf2aee312015-04-10 12:48:34 +0300100
101 /* PIXEL_INC is not added to the last pixel of a line */
102 bool last_pixel_inc_missing:1;
Tomi Valkeinene5f80912015-10-21 13:08:59 +0300103
104 /* POL_FREQ has ALIGN bit */
105 bool supports_sync_align:1;
Tomi Valkeinen20efbc32015-11-04 17:10:44 +0200106
107 bool has_writeback:1;
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +0200108
109 bool supports_double_pixel:1;
Tomi Valkeinenb7536d62016-01-13 18:41:36 +0200110
111 /*
112 * Field order for VENC is different than HDMI. We should handle this in
113 * some intelligent manner, but as the SoCs have either HDMI or VENC,
114 * never both, we can just use this flag for now.
115 */
116 bool reverse_ilace_field_order:1;
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300117
118 bool has_gamma_table:1;
Jyri Sarhafbff0102016-06-07 15:09:16 +0300119
120 bool has_gamma_i734_bug:1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530121};
122
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300123#define DISPC_MAX_NR_FIFOS 5
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300124#define DISPC_MAX_CHANNEL_GAMMA 4
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300125
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200126static struct {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +0000127 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200128 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300129
archit tanejaaffe3602011-02-23 08:41:03 +0000130 int irq;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300131 irq_handler_t user_handler;
132 void *user_data;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200133
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200134 unsigned long core_clk_rate;
Tomi Valkeinen5391e872013-05-16 10:44:13 +0300135 unsigned long tv_pclk_rate;
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200136
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300137 u32 fifo_size[DISPC_MAX_NR_FIFOS];
138 /* maps which plane is using a fifo. fifo-id -> plane-id */
139 int fifo_assignment[DISPC_MAX_NR_FIFOS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200140
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300141 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200142 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200143
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300144 u32 *gamma_table[DISPC_MAX_CHANNEL_GAMMA];
145
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530146 const struct dispc_features *feat;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300147
148 bool is_enabled;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +0000149
150 struct regmap *syscon_pol;
151 u32 syscon_pol_offset;
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200152
153 /* DISPC_CONTROL & DISPC_CONFIG lock*/
154 spinlock_t control_lock;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200155} dispc;
156
Amber Jain0d66cbb2011-05-19 19:47:54 +0530157enum omap_color_component {
158 /* used for all color formats for OMAP3 and earlier
159 * and for RGB and Y color component on OMAP4
160 */
161 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
162 /* used for UV component for
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300163 * DRM_FORMAT_YUYV, DRM_FORMAT_UYVY, DRM_FORMAT_NV12
Amber Jain0d66cbb2011-05-19 19:47:54 +0530164 * color formats on OMAP4
165 */
166 DISPC_COLOR_COMPONENT_UV = 1 << 1,
167};
168
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530169enum mgr_reg_fields {
170 DISPC_MGR_FLD_ENABLE,
171 DISPC_MGR_FLD_STNTFT,
172 DISPC_MGR_FLD_GO,
173 DISPC_MGR_FLD_TFTDATALINES,
174 DISPC_MGR_FLD_STALLMODE,
175 DISPC_MGR_FLD_TCKENABLE,
176 DISPC_MGR_FLD_TCKSELECTION,
177 DISPC_MGR_FLD_CPR,
178 DISPC_MGR_FLD_FIFOHANDCHECK,
179 /* used to maintain a count of the above fields */
180 DISPC_MGR_FLD_NUM,
181};
182
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300183struct dispc_reg_field {
184 u16 reg;
185 u8 high;
186 u8 low;
187};
188
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300189struct dispc_gamma_desc {
190 u32 len;
191 u32 bits;
192 u16 reg;
193 bool has_index;
194};
195
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530196static const struct {
197 const char *name;
198 u32 vsync_irq;
199 u32 framedone_irq;
200 u32 sync_lost_irq;
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300201 struct dispc_gamma_desc gamma;
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300202 struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530203} mgr_desc[] = {
204 [OMAP_DSS_CHANNEL_LCD] = {
205 .name = "LCD",
206 .vsync_irq = DISPC_IRQ_VSYNC,
207 .framedone_irq = DISPC_IRQ_FRAMEDONE,
208 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300209 .gamma = {
210 .len = 256,
211 .bits = 8,
212 .reg = DISPC_GAMMA_TABLE0,
213 .has_index = true,
214 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530215 .reg_desc = {
216 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
217 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
218 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
219 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
220 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
221 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
222 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
223 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
224 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
225 },
226 },
227 [OMAP_DSS_CHANNEL_DIGIT] = {
228 .name = "DIGIT",
229 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200230 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530231 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300232 .gamma = {
233 .len = 1024,
234 .bits = 10,
235 .reg = DISPC_GAMMA_TABLE2,
236 .has_index = false,
237 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530238 .reg_desc = {
239 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
240 [DISPC_MGR_FLD_STNTFT] = { },
241 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
242 [DISPC_MGR_FLD_TFTDATALINES] = { },
243 [DISPC_MGR_FLD_STALLMODE] = { },
244 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
245 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
246 [DISPC_MGR_FLD_CPR] = { },
247 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
248 },
249 },
250 [OMAP_DSS_CHANNEL_LCD2] = {
251 .name = "LCD2",
252 .vsync_irq = DISPC_IRQ_VSYNC2,
253 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
254 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300255 .gamma = {
256 .len = 256,
257 .bits = 8,
258 .reg = DISPC_GAMMA_TABLE1,
259 .has_index = true,
260 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530261 .reg_desc = {
262 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
263 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
264 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
265 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
266 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
267 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
268 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
269 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
270 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
271 },
272 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530273 [OMAP_DSS_CHANNEL_LCD3] = {
274 .name = "LCD3",
275 .vsync_irq = DISPC_IRQ_VSYNC3,
276 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
277 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300278 .gamma = {
279 .len = 256,
280 .bits = 8,
281 .reg = DISPC_GAMMA_TABLE3,
282 .has_index = true,
283 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530284 .reg_desc = {
285 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
286 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
287 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
288 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
289 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
290 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
291 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
292 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
293 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
294 },
295 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530296};
297
Archit Taneja6e5264b2012-09-11 12:04:47 +0530298struct color_conv_coef {
299 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
300 int full_range;
301};
302
Tomi Valkeinen65904152015-11-04 17:10:57 +0200303static unsigned long dispc_fclk_rate(void);
304static unsigned long dispc_core_clk_rate(void);
305static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel);
306static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel);
307
Jyri Sarha864050c2017-03-24 16:47:52 +0200308static unsigned long dispc_plane_pclk_rate(enum omap_plane_id plane);
309static unsigned long dispc_plane_lclk_rate(enum omap_plane_id plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200310
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200311static void dispc_clear_irqstatus(u32 mask);
312static bool dispc_mgr_is_enabled(enum omap_channel channel);
313static void dispc_clear_irqstatus(u32 mask);
314
Archit Taneja55978cc2011-05-06 11:45:51 +0530315static inline void dispc_write_reg(const u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200316{
Archit Taneja55978cc2011-05-06 11:45:51 +0530317 __raw_writel(val, dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200318}
319
Archit Taneja55978cc2011-05-06 11:45:51 +0530320static inline u32 dispc_read_reg(const u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200321{
Archit Taneja55978cc2011-05-06 11:45:51 +0530322 return __raw_readl(dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200323}
324
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530325static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
326{
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300327 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530328 return REG_GET(rfld.reg, rfld.high, rfld.low);
329}
330
331static void mgr_fld_write(enum omap_channel channel,
332 enum mgr_reg_fields regfld, int val) {
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300333 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200334 const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG;
335 unsigned long flags;
336
337 if (need_lock)
338 spin_lock_irqsave(&dispc.control_lock, flags);
339
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530340 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200341
342 if (need_lock)
343 spin_unlock_irqrestore(&dispc.control_lock, flags);
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530344}
345
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200346#define SR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530347 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200348#define RR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530349 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200350
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300351static void dispc_save_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200352{
Archit Tanejac6104b82011-08-05 19:06:02 +0530353 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200354
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300355 DSSDBG("dispc_save_context\n");
356
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200357 SR(IRQENABLE);
358 SR(CONTROL);
359 SR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200360 SR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530361 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
362 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300363 SR(GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000364 if (dss_has_feature(FEAT_MGR_LCD2)) {
365 SR(CONTROL2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000366 SR(CONFIG2);
367 }
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530368 if (dss_has_feature(FEAT_MGR_LCD3)) {
369 SR(CONTROL3);
370 SR(CONFIG3);
371 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200372
Archit Tanejac6104b82011-08-05 19:06:02 +0530373 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
374 SR(DEFAULT_COLOR(i));
375 SR(TRANS_COLOR(i));
376 SR(SIZE_MGR(i));
377 if (i == OMAP_DSS_CHANNEL_DIGIT)
378 continue;
379 SR(TIMING_H(i));
380 SR(TIMING_V(i));
381 SR(POL_FREQ(i));
382 SR(DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200383
Archit Tanejac6104b82011-08-05 19:06:02 +0530384 SR(DATA_CYCLE1(i));
385 SR(DATA_CYCLE2(i));
386 SR(DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200387
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300388 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530389 SR(CPR_COEF_R(i));
390 SR(CPR_COEF_G(i));
391 SR(CPR_COEF_B(i));
392 }
393 }
394
395 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
396 SR(OVL_BA0(i));
397 SR(OVL_BA1(i));
398 SR(OVL_POSITION(i));
399 SR(OVL_SIZE(i));
400 SR(OVL_ATTRIBUTES(i));
401 SR(OVL_FIFO_THRESHOLD(i));
402 SR(OVL_ROW_INC(i));
403 SR(OVL_PIXEL_INC(i));
404 if (dss_has_feature(FEAT_PRELOAD))
405 SR(OVL_PRELOAD(i));
406 if (i == OMAP_DSS_GFX) {
407 SR(OVL_WINDOW_SKIP(i));
408 SR(OVL_TABLE_BA(i));
409 continue;
410 }
411 SR(OVL_FIR(i));
412 SR(OVL_PICTURE_SIZE(i));
413 SR(OVL_ACCU0(i));
414 SR(OVL_ACCU1(i));
415
416 for (j = 0; j < 8; j++)
417 SR(OVL_FIR_COEF_H(i, j));
418
419 for (j = 0; j < 8; j++)
420 SR(OVL_FIR_COEF_HV(i, j));
421
422 for (j = 0; j < 5; j++)
423 SR(OVL_CONV_COEF(i, j));
424
425 if (dss_has_feature(FEAT_FIR_COEF_V)) {
426 for (j = 0; j < 8; j++)
427 SR(OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300428 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000429
Archit Tanejac6104b82011-08-05 19:06:02 +0530430 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
431 SR(OVL_BA0_UV(i));
432 SR(OVL_BA1_UV(i));
433 SR(OVL_FIR2(i));
434 SR(OVL_ACCU2_0(i));
435 SR(OVL_ACCU2_1(i));
436
437 for (j = 0; j < 8; j++)
438 SR(OVL_FIR_COEF_H2(i, j));
439
440 for (j = 0; j < 8; j++)
441 SR(OVL_FIR_COEF_HV2(i, j));
442
443 for (j = 0; j < 8; j++)
444 SR(OVL_FIR_COEF_V2(i, j));
445 }
446 if (dss_has_feature(FEAT_ATTR2))
447 SR(OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000448 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200449
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600450 if (dss_has_feature(FEAT_CORE_CLK_DIV))
451 SR(DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300452
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300453 dispc.ctx_valid = true;
454
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200455 DSSDBG("context saved\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200456}
457
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300458static void dispc_restore_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200459{
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200460 int i, j;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300461
462 DSSDBG("dispc_restore_context\n");
463
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300464 if (!dispc.ctx_valid)
465 return;
466
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200467 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200468 /*RR(CONTROL);*/
469 RR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200470 RR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530471 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
472 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300473 RR(GLOBAL_ALPHA);
Archit Tanejac6104b82011-08-05 19:06:02 +0530474 if (dss_has_feature(FEAT_MGR_LCD2))
Sumit Semwal2a205f32010-12-02 11:27:12 +0000475 RR(CONFIG2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530476 if (dss_has_feature(FEAT_MGR_LCD3))
477 RR(CONFIG3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200478
Archit Tanejac6104b82011-08-05 19:06:02 +0530479 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
480 RR(DEFAULT_COLOR(i));
481 RR(TRANS_COLOR(i));
482 RR(SIZE_MGR(i));
483 if (i == OMAP_DSS_CHANNEL_DIGIT)
484 continue;
485 RR(TIMING_H(i));
486 RR(TIMING_V(i));
487 RR(POL_FREQ(i));
488 RR(DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530489
Archit Tanejac6104b82011-08-05 19:06:02 +0530490 RR(DATA_CYCLE1(i));
491 RR(DATA_CYCLE2(i));
492 RR(DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000493
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300494 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530495 RR(CPR_COEF_R(i));
496 RR(CPR_COEF_G(i));
497 RR(CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300498 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000499 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200500
Archit Tanejac6104b82011-08-05 19:06:02 +0530501 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
502 RR(OVL_BA0(i));
503 RR(OVL_BA1(i));
504 RR(OVL_POSITION(i));
505 RR(OVL_SIZE(i));
506 RR(OVL_ATTRIBUTES(i));
507 RR(OVL_FIFO_THRESHOLD(i));
508 RR(OVL_ROW_INC(i));
509 RR(OVL_PIXEL_INC(i));
510 if (dss_has_feature(FEAT_PRELOAD))
511 RR(OVL_PRELOAD(i));
512 if (i == OMAP_DSS_GFX) {
513 RR(OVL_WINDOW_SKIP(i));
514 RR(OVL_TABLE_BA(i));
515 continue;
516 }
517 RR(OVL_FIR(i));
518 RR(OVL_PICTURE_SIZE(i));
519 RR(OVL_ACCU0(i));
520 RR(OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200521
Archit Tanejac6104b82011-08-05 19:06:02 +0530522 for (j = 0; j < 8; j++)
523 RR(OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200524
Archit Tanejac6104b82011-08-05 19:06:02 +0530525 for (j = 0; j < 8; j++)
526 RR(OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200527
Archit Tanejac6104b82011-08-05 19:06:02 +0530528 for (j = 0; j < 5; j++)
529 RR(OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200530
Archit Tanejac6104b82011-08-05 19:06:02 +0530531 if (dss_has_feature(FEAT_FIR_COEF_V)) {
532 for (j = 0; j < 8; j++)
533 RR(OVL_FIR_COEF_V(i, j));
534 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200535
Archit Tanejac6104b82011-08-05 19:06:02 +0530536 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
537 RR(OVL_BA0_UV(i));
538 RR(OVL_BA1_UV(i));
539 RR(OVL_FIR2(i));
540 RR(OVL_ACCU2_0(i));
541 RR(OVL_ACCU2_1(i));
542
543 for (j = 0; j < 8; j++)
544 RR(OVL_FIR_COEF_H2(i, j));
545
546 for (j = 0; j < 8; j++)
547 RR(OVL_FIR_COEF_HV2(i, j));
548
549 for (j = 0; j < 8; j++)
550 RR(OVL_FIR_COEF_V2(i, j));
551 }
552 if (dss_has_feature(FEAT_ATTR2))
553 RR(OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300554 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200555
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600556 if (dss_has_feature(FEAT_CORE_CLK_DIV))
557 RR(DIVISOR);
558
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200559 /* enable last, because LCD & DIGIT enable are here */
560 RR(CONTROL);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000561 if (dss_has_feature(FEAT_MGR_LCD2))
562 RR(CONTROL2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530563 if (dss_has_feature(FEAT_MGR_LCD3))
564 RR(CONTROL3);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200565 /* clear spurious SYNC_LOST_DIGIT interrupts */
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +0300566 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200567
568 /*
569 * enable last so IRQs won't trigger before
570 * the context is fully restored
571 */
572 RR(IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300573
574 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200575}
576
577#undef SR
578#undef RR
579
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300580int dispc_runtime_get(void)
581{
582 int r;
583
584 DSSDBG("dispc_runtime_get\n");
585
586 r = pm_runtime_get_sync(&dispc.pdev->dev);
587 WARN_ON(r < 0);
588 return r < 0 ? r : 0;
589}
590
591void dispc_runtime_put(void)
592{
593 int r;
594
595 DSSDBG("dispc_runtime_put\n");
596
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200597 r = pm_runtime_put_sync(&dispc.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300598 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300599}
600
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200601static u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200602{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530603 return mgr_desc[channel].vsync_irq;
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200604}
605
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200606static u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200607{
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200608 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv)
609 return 0;
610
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530611 return mgr_desc[channel].framedone_irq;
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200612}
613
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200614static u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
Tomi Valkeinencb699202012-10-17 10:38:52 +0300615{
616 return mgr_desc[channel].sync_lost_irq;
617}
618
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530619u32 dispc_wb_get_framedone_irq(void)
620{
621 return DISPC_IRQ_FRAMEDONEWB;
622}
623
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200624static void dispc_mgr_enable(enum omap_channel channel, bool enable)
Laurent Pinchart03af8152016-04-18 03:09:48 +0300625{
626 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
627 /* flush posted write */
628 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
629}
Laurent Pinchart03af8152016-04-18 03:09:48 +0300630
631static bool dispc_mgr_is_enabled(enum omap_channel channel)
632{
633 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
634}
635
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200636static bool dispc_mgr_go_busy(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200637{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530638 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200639}
640
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200641static void dispc_mgr_go(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200642{
Luis de Bethencourt0bcfdba2015-10-15 13:29:38 +0100643 WARN_ON(!dispc_mgr_is_enabled(channel));
Tomi Valkeinen3c91ee82012-10-19 15:06:07 +0300644 WARN_ON(dispc_mgr_go_busy(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200645
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530646 DSSDBG("GO %s\n", mgr_desc[channel].name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200647
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530648 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200649}
650
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530651bool dispc_wb_go_busy(void)
652{
653 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
654}
655
656void dispc_wb_go(void)
657{
Jyri Sarha864050c2017-03-24 16:47:52 +0200658 enum omap_plane_id plane = OMAP_DSS_WB;
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530659 bool enable, go;
660
661 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
662
663 if (!enable)
664 return;
665
666 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
667 if (go) {
668 DSSERR("GO bit not down for WB\n");
669 return;
670 }
671
672 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
673}
674
Jyri Sarha864050c2017-03-24 16:47:52 +0200675static void dispc_ovl_write_firh_reg(enum omap_plane_id plane, int reg,
676 u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200677{
Archit Taneja9b372c22011-05-06 11:45:49 +0530678 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200679}
680
Jyri Sarha864050c2017-03-24 16:47:52 +0200681static void dispc_ovl_write_firhv_reg(enum omap_plane_id plane, int reg,
682 u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200683{
Archit Taneja9b372c22011-05-06 11:45:49 +0530684 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200685}
686
Jyri Sarha864050c2017-03-24 16:47:52 +0200687static void dispc_ovl_write_firv_reg(enum omap_plane_id plane, int reg,
688 u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200689{
Archit Taneja9b372c22011-05-06 11:45:49 +0530690 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200691}
692
Jyri Sarha864050c2017-03-24 16:47:52 +0200693static void dispc_ovl_write_firh2_reg(enum omap_plane_id plane, int reg,
694 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530695{
696 BUG_ON(plane == OMAP_DSS_GFX);
697
698 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
699}
700
Jyri Sarha864050c2017-03-24 16:47:52 +0200701static void dispc_ovl_write_firhv2_reg(enum omap_plane_id plane, int reg,
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300702 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530703{
704 BUG_ON(plane == OMAP_DSS_GFX);
705
706 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
707}
708
Jyri Sarha864050c2017-03-24 16:47:52 +0200709static void dispc_ovl_write_firv2_reg(enum omap_plane_id plane, int reg,
710 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530711{
712 BUG_ON(plane == OMAP_DSS_GFX);
713
714 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
715}
716
Jyri Sarha864050c2017-03-24 16:47:52 +0200717static void dispc_ovl_set_scale_coef(enum omap_plane_id plane, int fir_hinc,
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530718 int fir_vinc, int five_taps,
719 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200720{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530721 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200722 int i;
723
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530724 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
725 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200726
727 for (i = 0; i < 8; i++) {
728 u32 h, hv;
729
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530730 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
731 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
732 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
733 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
734 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
735 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
736 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
737 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200738
Amber Jain0d66cbb2011-05-19 19:47:54 +0530739 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300740 dispc_ovl_write_firh_reg(plane, i, h);
741 dispc_ovl_write_firhv_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530742 } else {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300743 dispc_ovl_write_firh2_reg(plane, i, h);
744 dispc_ovl_write_firhv2_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530745 }
746
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200747 }
748
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200749 if (five_taps) {
750 for (i = 0; i < 8; i++) {
751 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530752 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
753 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530754 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300755 dispc_ovl_write_firv_reg(plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530756 else
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300757 dispc_ovl_write_firv2_reg(plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200758 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200759 }
760}
761
Archit Taneja6e5264b2012-09-11 12:04:47 +0530762
Jyri Sarha864050c2017-03-24 16:47:52 +0200763static void dispc_ovl_write_color_conv_coef(enum omap_plane_id plane,
Archit Taneja6e5264b2012-09-11 12:04:47 +0530764 const struct color_conv_coef *ct)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200765{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200766#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
767
Archit Taneja6e5264b2012-09-11 12:04:47 +0530768 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
769 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
770 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
771 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
772 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200773
Archit Taneja6e5264b2012-09-11 12:04:47 +0530774 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200775
776#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200777}
778
Archit Taneja6e5264b2012-09-11 12:04:47 +0530779static void dispc_setup_color_conv_coef(void)
780{
781 int i;
782 int num_ovl = dss_feat_get_num_ovls();
Archit Taneja6e5264b2012-09-11 12:04:47 +0530783 const struct color_conv_coef ctbl_bt601_5_ovl = {
Tomi Valkeinen7d18bbe2015-11-04 17:10:52 +0200784 /* YUV -> RGB */
Archit Taneja6e5264b2012-09-11 12:04:47 +0530785 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
786 };
787 const struct color_conv_coef ctbl_bt601_5_wb = {
Tomi Valkeinen7d18bbe2015-11-04 17:10:52 +0200788 /* RGB -> YUV */
789 66, 129, 25, 112, -94, -18, -38, -74, 112, 0,
Archit Taneja6e5264b2012-09-11 12:04:47 +0530790 };
791
792 for (i = 1; i < num_ovl; i++)
793 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
794
Tomi Valkeinen20efbc32015-11-04 17:10:44 +0200795 if (dispc.feat->has_writeback)
796 dispc_ovl_write_color_conv_coef(OMAP_DSS_WB, &ctbl_bt601_5_wb);
Archit Taneja6e5264b2012-09-11 12:04:47 +0530797}
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200798
Jyri Sarha864050c2017-03-24 16:47:52 +0200799static void dispc_ovl_set_ba0(enum omap_plane_id plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200800{
Archit Taneja9b372c22011-05-06 11:45:49 +0530801 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200802}
803
Jyri Sarha864050c2017-03-24 16:47:52 +0200804static void dispc_ovl_set_ba1(enum omap_plane_id plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200805{
Archit Taneja9b372c22011-05-06 11:45:49 +0530806 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200807}
808
Jyri Sarha864050c2017-03-24 16:47:52 +0200809static void dispc_ovl_set_ba0_uv(enum omap_plane_id plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530810{
811 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
812}
813
Jyri Sarha864050c2017-03-24 16:47:52 +0200814static void dispc_ovl_set_ba1_uv(enum omap_plane_id plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530815{
816 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
817}
818
Jyri Sarha864050c2017-03-24 16:47:52 +0200819static void dispc_ovl_set_pos(enum omap_plane_id plane,
Archit Tanejad79db852012-09-22 12:30:17 +0530820 enum omap_overlay_caps caps, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200821{
Archit Tanejad79db852012-09-22 12:30:17 +0530822 u32 val;
823
824 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
825 return;
826
827 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530828
829 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200830}
831
Jyri Sarha864050c2017-03-24 16:47:52 +0200832static void dispc_ovl_set_input_size(enum omap_plane_id plane, int width,
Archit Taneja78b687f2012-09-21 14:51:49 +0530833 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200834{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200835 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530836
Archit Taneja36d87d92012-07-28 22:59:03 +0530837 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
Archit Taneja9b372c22011-05-06 11:45:49 +0530838 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
839 else
840 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200841}
842
Jyri Sarha864050c2017-03-24 16:47:52 +0200843static void dispc_ovl_set_output_size(enum omap_plane_id plane, int width,
Archit Taneja78b687f2012-09-21 14:51:49 +0530844 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200845{
846 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200847
848 BUG_ON(plane == OMAP_DSS_GFX);
849
850 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530851
Archit Taneja36d87d92012-07-28 22:59:03 +0530852 if (plane == OMAP_DSS_WB)
853 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
854 else
855 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200856}
857
Jyri Sarha864050c2017-03-24 16:47:52 +0200858static void dispc_ovl_set_zorder(enum omap_plane_id plane,
Archit Taneja5b54ed32012-09-26 16:55:27 +0530859 enum omap_overlay_caps caps, u8 zorder)
Archit Taneja54128702011-09-08 11:29:17 +0530860{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530861 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
Archit Taneja54128702011-09-08 11:29:17 +0530862 return;
863
864 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
865}
866
867static void dispc_ovl_enable_zorder_planes(void)
868{
869 int i;
870
871 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
872 return;
873
874 for (i = 0; i < dss_feat_get_num_ovls(); i++)
875 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
876}
877
Jyri Sarha864050c2017-03-24 16:47:52 +0200878static void dispc_ovl_set_pre_mult_alpha(enum omap_plane_id plane,
Archit Taneja5b54ed32012-09-26 16:55:27 +0530879 enum omap_overlay_caps caps, bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100880{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530881 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100882 return;
883
Archit Taneja9b372c22011-05-06 11:45:49 +0530884 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100885}
886
Jyri Sarha864050c2017-03-24 16:47:52 +0200887static void dispc_ovl_setup_global_alpha(enum omap_plane_id plane,
Archit Taneja5b54ed32012-09-26 16:55:27 +0530888 enum omap_overlay_caps caps, u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200889{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530890 static const unsigned shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300891 int shift;
892
Archit Taneja5b54ed32012-09-26 16:55:27 +0530893 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100894 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530895
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300896 shift = shifts[plane];
897 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200898}
899
Jyri Sarha864050c2017-03-24 16:47:52 +0200900static void dispc_ovl_set_pix_inc(enum omap_plane_id plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200901{
Archit Taneja9b372c22011-05-06 11:45:49 +0530902 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200903}
904
Jyri Sarha864050c2017-03-24 16:47:52 +0200905static void dispc_ovl_set_row_inc(enum omap_plane_id plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200906{
Archit Taneja9b372c22011-05-06 11:45:49 +0530907 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200908}
909
Tomi Valkeinen41aff422017-05-04 11:31:56 +0300910static void dispc_ovl_set_color_mode(enum omap_plane_id plane, u32 fourcc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200911{
912 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +0530913 if (plane != OMAP_DSS_GFX) {
Tomi Valkeinen41aff422017-05-04 11:31:56 +0300914 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300915 case DRM_FORMAT_NV12:
Amber Jainf20e4222011-05-19 19:47:50 +0530916 m = 0x0; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300917 case DRM_FORMAT_XRGB4444:
Amber Jainf20e4222011-05-19 19:47:50 +0530918 m = 0x1; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300919 case DRM_FORMAT_RGBA4444:
Amber Jainf20e4222011-05-19 19:47:50 +0530920 m = 0x2; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300921 case DRM_FORMAT_RGBX4444:
Amber Jainf20e4222011-05-19 19:47:50 +0530922 m = 0x4; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300923 case DRM_FORMAT_ARGB4444:
Amber Jainf20e4222011-05-19 19:47:50 +0530924 m = 0x5; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300925 case DRM_FORMAT_RGB565:
Amber Jainf20e4222011-05-19 19:47:50 +0530926 m = 0x6; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300927 case DRM_FORMAT_ARGB1555:
Amber Jainf20e4222011-05-19 19:47:50 +0530928 m = 0x7; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300929 case DRM_FORMAT_XRGB8888:
Amber Jainf20e4222011-05-19 19:47:50 +0530930 m = 0x8; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300931 case DRM_FORMAT_RGB888:
Amber Jainf20e4222011-05-19 19:47:50 +0530932 m = 0x9; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300933 case DRM_FORMAT_YUYV:
Amber Jainf20e4222011-05-19 19:47:50 +0530934 m = 0xa; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300935 case DRM_FORMAT_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +0530936 m = 0xb; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300937 case DRM_FORMAT_ARGB8888:
Amber Jainf20e4222011-05-19 19:47:50 +0530938 m = 0xc; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300939 case DRM_FORMAT_RGBA8888:
Amber Jainf20e4222011-05-19 19:47:50 +0530940 m = 0xd; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300941 case DRM_FORMAT_RGBX8888:
Amber Jainf20e4222011-05-19 19:47:50 +0530942 m = 0xe; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300943 case DRM_FORMAT_XRGB1555:
Amber Jainf20e4222011-05-19 19:47:50 +0530944 m = 0xf; break;
945 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300946 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530947 }
948 } else {
Tomi Valkeinen41aff422017-05-04 11:31:56 +0300949 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300950 case DRM_FORMAT_RGBX4444:
Amber Jainf20e4222011-05-19 19:47:50 +0530951 m = 0x4; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300952 case DRM_FORMAT_ARGB4444:
Amber Jainf20e4222011-05-19 19:47:50 +0530953 m = 0x5; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300954 case DRM_FORMAT_RGB565:
Amber Jainf20e4222011-05-19 19:47:50 +0530955 m = 0x6; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300956 case DRM_FORMAT_ARGB1555:
Amber Jainf20e4222011-05-19 19:47:50 +0530957 m = 0x7; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300958 case DRM_FORMAT_XRGB8888:
Amber Jainf20e4222011-05-19 19:47:50 +0530959 m = 0x8; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300960 case DRM_FORMAT_RGB888:
Amber Jainf20e4222011-05-19 19:47:50 +0530961 m = 0x9; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300962 case DRM_FORMAT_XRGB4444:
Amber Jainf20e4222011-05-19 19:47:50 +0530963 m = 0xa; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300964 case DRM_FORMAT_RGBA4444:
Amber Jainf20e4222011-05-19 19:47:50 +0530965 m = 0xb; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300966 case DRM_FORMAT_ARGB8888:
Amber Jainf20e4222011-05-19 19:47:50 +0530967 m = 0xc; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300968 case DRM_FORMAT_RGBA8888:
Amber Jainf20e4222011-05-19 19:47:50 +0530969 m = 0xd; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300970 case DRM_FORMAT_RGBX8888:
Amber Jainf20e4222011-05-19 19:47:50 +0530971 m = 0xe; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300972 case DRM_FORMAT_XRGB1555:
Amber Jainf20e4222011-05-19 19:47:50 +0530973 m = 0xf; break;
974 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300975 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530976 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200977 }
978
Archit Taneja9b372c22011-05-06 11:45:49 +0530979 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200980}
981
Tomi Valkeinen41aff422017-05-04 11:31:56 +0300982static bool format_is_yuv(u32 fourcc)
Tomi Valkeinen5edec142017-05-04 09:13:32 +0300983{
Tomi Valkeinen41aff422017-05-04 11:31:56 +0300984 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300985 case DRM_FORMAT_YUYV:
986 case DRM_FORMAT_UYVY:
987 case DRM_FORMAT_NV12:
Tomi Valkeinen5edec142017-05-04 09:13:32 +0300988 return true;
989 default:
990 return false;
991 }
992}
993
Jyri Sarha864050c2017-03-24 16:47:52 +0200994static void dispc_ovl_configure_burst_type(enum omap_plane_id plane,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530995 enum omap_dss_rotation_type rotation_type)
996{
997 if (dss_has_feature(FEAT_BURST_2D) == 0)
998 return;
999
1000 if (rotation_type == OMAP_DSS_ROT_TILER)
1001 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
1002 else
1003 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
1004}
1005
Jyri Sarha864050c2017-03-24 16:47:52 +02001006static void dispc_ovl_set_channel_out(enum omap_plane_id plane,
1007 enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001008{
1009 int shift;
1010 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001011 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001012
1013 switch (plane) {
1014 case OMAP_DSS_GFX:
1015 shift = 8;
1016 break;
1017 case OMAP_DSS_VIDEO1:
1018 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +05301019 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001020 shift = 16;
1021 break;
1022 default:
1023 BUG();
1024 return;
1025 }
1026
Archit Taneja9b372c22011-05-06 11:45:49 +05301027 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +00001028 if (dss_has_feature(FEAT_MGR_LCD2)) {
1029 switch (channel) {
1030 case OMAP_DSS_CHANNEL_LCD:
1031 chan = 0;
1032 chan2 = 0;
1033 break;
1034 case OMAP_DSS_CHANNEL_DIGIT:
1035 chan = 1;
1036 chan2 = 0;
1037 break;
1038 case OMAP_DSS_CHANNEL_LCD2:
1039 chan = 0;
1040 chan2 = 1;
1041 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05301042 case OMAP_DSS_CHANNEL_LCD3:
1043 if (dss_has_feature(FEAT_MGR_LCD3)) {
1044 chan = 0;
1045 chan2 = 2;
1046 } else {
1047 BUG();
1048 return;
1049 }
1050 break;
Tomi Valkeinenc2665c42015-11-04 17:10:47 +02001051 case OMAP_DSS_CHANNEL_WB:
1052 chan = 0;
1053 chan2 = 3;
1054 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001055 default:
1056 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001057 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001058 }
1059
1060 val = FLD_MOD(val, chan, shift, shift);
1061 val = FLD_MOD(val, chan2, 31, 30);
1062 } else {
1063 val = FLD_MOD(val, channel, shift, shift);
1064 }
Archit Taneja9b372c22011-05-06 11:45:49 +05301065 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001066}
1067
Jyri Sarha864050c2017-03-24 16:47:52 +02001068static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane_id plane)
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001069{
1070 int shift;
1071 u32 val;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001072
1073 switch (plane) {
1074 case OMAP_DSS_GFX:
1075 shift = 8;
1076 break;
1077 case OMAP_DSS_VIDEO1:
1078 case OMAP_DSS_VIDEO2:
1079 case OMAP_DSS_VIDEO3:
1080 shift = 16;
1081 break;
1082 default:
1083 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001084 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001085 }
1086
1087 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1088
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001089 if (FLD_GET(val, shift, shift) == 1)
1090 return OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001091
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001092 if (!dss_has_feature(FEAT_MGR_LCD2))
1093 return OMAP_DSS_CHANNEL_LCD;
1094
1095 switch (FLD_GET(val, 31, 30)) {
1096 case 0:
1097 default:
1098 return OMAP_DSS_CHANNEL_LCD;
1099 case 1:
1100 return OMAP_DSS_CHANNEL_LCD2;
1101 case 2:
1102 return OMAP_DSS_CHANNEL_LCD3;
Tomi Valkeinenc2665c42015-11-04 17:10:47 +02001103 case 3:
1104 return OMAP_DSS_CHANNEL_WB;
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001105 }
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001106}
1107
Archit Tanejad9ac7732012-09-22 12:38:19 +05301108void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1109{
Jyri Sarha864050c2017-03-24 16:47:52 +02001110 enum omap_plane_id plane = OMAP_DSS_WB;
Archit Tanejad9ac7732012-09-22 12:38:19 +05301111
1112 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1113}
1114
Jyri Sarha864050c2017-03-24 16:47:52 +02001115static void dispc_ovl_set_burst_size(enum omap_plane_id plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001116 enum omap_burst_size burst_size)
1117{
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301118 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001119 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001120
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001121 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001122 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001123}
1124
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001125static void dispc_configure_burst_sizes(void)
1126{
1127 int i;
1128 const int burst_size = BURST_SIZE_X8;
1129
1130 /* Configure burst size always to maximum size */
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001131 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001132 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5b354af2015-11-04 17:10:48 +02001133 if (dispc.feat->has_writeback)
1134 dispc_ovl_set_burst_size(OMAP_DSS_WB, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001135}
1136
Jyri Sarha864050c2017-03-24 16:47:52 +02001137static u32 dispc_ovl_get_burst_size(enum omap_plane_id plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001138{
1139 unsigned unit = dss_feat_get_burst_size_unit();
1140 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1141 return unit * 8;
1142}
1143
Tomi Valkeinen9c39d172017-05-04 11:19:12 +03001144static const u32 *dispc_ovl_get_color_modes(enum omap_plane_id plane)
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001145{
1146 return dss_feat_get_supported_color_modes(plane);
1147}
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001148
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02001149static int dispc_get_num_ovls(void)
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001150{
1151 return dss_feat_get_num_ovls();
1152}
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001153
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001154static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001155{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301156 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001157 return;
1158
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301159 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001160}
1161
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001162static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02001163 const struct omap_dss_cpr_coefs *coefs)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001164{
1165 u32 coef_r, coef_g, coef_b;
1166
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301167 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001168 return;
1169
1170 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1171 FLD_VAL(coefs->rb, 9, 0);
1172 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1173 FLD_VAL(coefs->gb, 9, 0);
1174 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1175 FLD_VAL(coefs->bb, 9, 0);
1176
1177 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1178 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1179 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1180}
1181
Jyri Sarha864050c2017-03-24 16:47:52 +02001182static void dispc_ovl_set_vid_color_conv(enum omap_plane_id plane,
1183 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001184{
1185 u32 val;
1186
1187 BUG_ON(plane == OMAP_DSS_GFX);
1188
Archit Taneja9b372c22011-05-06 11:45:49 +05301189 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001190 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +05301191 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001192}
1193
Jyri Sarha864050c2017-03-24 16:47:52 +02001194static void dispc_ovl_enable_replication(enum omap_plane_id plane,
Archit Tanejad79db852012-09-22 12:30:17 +05301195 enum omap_overlay_caps caps, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001196{
Archit Tanejab8c095b2011-09-13 18:20:33 +05301197 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001198 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001199
Archit Tanejad79db852012-09-22 12:30:17 +05301200 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1201 return;
1202
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001203 shift = shifts[plane];
1204 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001205}
1206
Archit Taneja8f366162012-04-16 12:53:44 +05301207static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
Archit Tanejae5c09e02012-04-16 12:53:42 +05301208 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001209{
1210 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301211
Archit Taneja33b89922012-11-14 13:50:15 +05301212 val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1213 FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1214
Archit Taneja702d1442011-05-06 11:45:50 +05301215 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001216}
1217
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001218static void dispc_init_fifos(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001219{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001220 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001221 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301222 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001223 u32 unit;
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001224 int i;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001225
1226 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001227
Archit Tanejaa0acb552010-09-15 19:20:00 +05301228 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001229
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001230 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1231 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001232 size *= unit;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001233 dispc.fifo_size[fifo] = size;
1234
1235 /*
1236 * By default fifos are mapped directly to overlays, fifo 0 to
1237 * ovl 0, fifo 1 to ovl 1, etc.
1238 */
1239 dispc.fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001240 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001241
1242 /*
1243 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1244 * causes problems with certain use cases, like using the tiler in 2D
1245 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1246 * giving GFX plane a larger fifo. WB but should work fine with a
1247 * smaller fifo.
1248 */
1249 if (dispc.feat->gfx_fifo_workaround) {
1250 u32 v;
1251
1252 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1253
1254 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1255 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1256 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1257 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1258
1259 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1260
1261 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1262 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1263 }
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001264
1265 /*
1266 * Setup default fifo thresholds.
1267 */
1268 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1269 u32 low, high;
1270 const bool use_fifomerge = false;
1271 const bool manual_update = false;
1272
1273 dispc_ovl_compute_fifo_thresholds(i, &low, &high,
1274 use_fifomerge, manual_update);
1275
1276 dispc_ovl_set_fifo_threshold(i, low, high);
1277 }
Tomi Valkeinen65e116e2015-11-04 17:10:49 +02001278
1279 if (dispc.feat->has_writeback) {
1280 u32 low, high;
1281 const bool use_fifomerge = false;
1282 const bool manual_update = false;
1283
1284 dispc_ovl_compute_fifo_thresholds(OMAP_DSS_WB, &low, &high,
1285 use_fifomerge, manual_update);
1286
1287 dispc_ovl_set_fifo_threshold(OMAP_DSS_WB, low, high);
1288 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001289}
1290
Jyri Sarha864050c2017-03-24 16:47:52 +02001291static u32 dispc_ovl_get_fifo_size(enum omap_plane_id plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001292{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001293 int fifo;
1294 u32 size = 0;
1295
1296 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1297 if (dispc.fifo_assignment[fifo] == plane)
1298 size += dispc.fifo_size[fifo];
1299 }
1300
1301 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001302}
1303
Jyri Sarha864050c2017-03-24 16:47:52 +02001304void dispc_ovl_set_fifo_threshold(enum omap_plane_id plane, u32 low,
1305 u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001306{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301307 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001308 u32 unit;
1309
1310 unit = dss_feat_get_buffer_size_unit();
1311
1312 WARN_ON(low % unit != 0);
1313 WARN_ON(high % unit != 0);
1314
1315 low /= unit;
1316 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301317
Archit Taneja9b372c22011-05-06 11:45:49 +05301318 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1319 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1320
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001321 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001322 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301323 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001324 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301325 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001326 hi_start, hi_end) * unit,
1327 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001328
Archit Taneja9b372c22011-05-06 11:45:49 +05301329 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301330 FLD_VAL(high, hi_start, hi_end) |
1331 FLD_VAL(low, lo_start, lo_end));
Archit Taneja8bc65552013-12-17 16:40:21 +05301332
1333 /*
1334 * configure the preload to the pipeline's high threhold, if HT it's too
1335 * large for the preload field, set the threshold to the maximum value
1336 * that can be held by the preload register
1337 */
1338 if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload &&
1339 plane != OMAP_DSS_WB)
1340 dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001341}
1342
1343void dispc_enable_fifomerge(bool enable)
1344{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001345 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1346 WARN_ON(enable);
1347 return;
1348 }
1349
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001350 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1351 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001352}
1353
Jyri Sarha864050c2017-03-24 16:47:52 +02001354void dispc_ovl_compute_fifo_thresholds(enum omap_plane_id plane,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001355 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1356 bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001357{
1358 /*
1359 * All sizes are in bytes. Both the buffer and burst are made of
1360 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1361 */
1362
1363 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001364 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1365 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001366
1367 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001368 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001369
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001370 if (use_fifomerge) {
1371 total_fifo_size = 0;
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001372 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001373 total_fifo_size += dispc_ovl_get_fifo_size(i);
1374 } else {
1375 total_fifo_size = ovl_fifo_size;
1376 }
1377
1378 /*
1379 * We use the same low threshold for both fifomerge and non-fifomerge
1380 * cases, but for fifomerge we calculate the high threshold using the
1381 * combined fifo size
1382 */
1383
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001384 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001385 *fifo_low = ovl_fifo_size - burst_size * 2;
1386 *fifo_high = total_fifo_size - burst_size;
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301387 } else if (plane == OMAP_DSS_WB) {
1388 /*
1389 * Most optimal configuration for writeback is to push out data
1390 * to the interconnect the moment writeback pushes enough pixels
1391 * in the FIFO to form a burst
1392 */
1393 *fifo_low = 0;
1394 *fifo_high = burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001395 } else {
1396 *fifo_low = ovl_fifo_size - burst_size;
1397 *fifo_high = total_fifo_size - buf_unit;
1398 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001399}
1400
Jyri Sarha864050c2017-03-24 16:47:52 +02001401static void dispc_ovl_set_mflag(enum omap_plane_id plane, bool enable)
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001402{
1403 int bit;
1404
1405 if (plane == OMAP_DSS_GFX)
1406 bit = 14;
1407 else
1408 bit = 23;
1409
1410 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1411}
1412
Jyri Sarha864050c2017-03-24 16:47:52 +02001413static void dispc_ovl_set_mflag_threshold(enum omap_plane_id plane,
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001414 int low, int high)
1415{
1416 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane),
1417 FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1418}
1419
1420static void dispc_init_mflag(void)
1421{
1422 int i;
1423
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001424 /*
1425 * HACK: NV12 color format and MFLAG seem to have problems working
1426 * together: using two displays, and having an NV12 overlay on one of
1427 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1428 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1429 * remove the errors, but there doesn't seem to be a clear logic on
1430 * which values work and which not.
1431 *
1432 * As a work-around, set force MFLAG to always on.
1433 */
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001434 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE,
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001435 (1 << 0) | /* MFLAG_CTRL = force always on */
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001436 (0 << 2)); /* MFLAG_START = disable */
1437
1438 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1439 u32 size = dispc_ovl_get_fifo_size(i);
1440 u32 unit = dss_feat_get_buffer_size_unit();
1441 u32 low, high;
1442
1443 dispc_ovl_set_mflag(i, true);
1444
1445 /*
1446 * Simulation team suggests below thesholds:
1447 * HT = fifosize * 5 / 8;
1448 * LT = fifosize * 4 / 8;
1449 */
1450
1451 low = size * 4 / 8 / unit;
1452 high = size * 5 / 8 / unit;
1453
1454 dispc_ovl_set_mflag_threshold(i, low, high);
1455 }
Tomi Valkeinenecb0b362015-11-04 17:10:50 +02001456
1457 if (dispc.feat->has_writeback) {
1458 u32 size = dispc_ovl_get_fifo_size(OMAP_DSS_WB);
1459 u32 unit = dss_feat_get_buffer_size_unit();
1460 u32 low, high;
1461
1462 dispc_ovl_set_mflag(OMAP_DSS_WB, true);
1463
1464 /*
1465 * Simulation team suggests below thesholds:
1466 * HT = fifosize * 5 / 8;
1467 * LT = fifosize * 4 / 8;
1468 */
1469
1470 low = size * 4 / 8 / unit;
1471 high = size * 5 / 8 / unit;
1472
1473 dispc_ovl_set_mflag_threshold(OMAP_DSS_WB, low, high);
1474 }
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001475}
1476
Jyri Sarha864050c2017-03-24 16:47:52 +02001477static void dispc_ovl_set_fir(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301478 int hinc, int vinc,
1479 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001480{
1481 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001482
Amber Jain0d66cbb2011-05-19 19:47:54 +05301483 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1484 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301485
Amber Jain0d66cbb2011-05-19 19:47:54 +05301486 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1487 &hinc_start, &hinc_end);
1488 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1489 &vinc_start, &vinc_end);
1490 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1491 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301492
Amber Jain0d66cbb2011-05-19 19:47:54 +05301493 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1494 } else {
1495 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1496 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1497 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001498}
1499
Jyri Sarha864050c2017-03-24 16:47:52 +02001500static void dispc_ovl_set_vid_accu0(enum omap_plane_id plane, int haccu,
1501 int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001502{
1503 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301504 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001505
Archit Taneja87a74842011-03-02 11:19:50 +05301506 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1507 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1508
1509 val = FLD_VAL(vaccu, vert_start, vert_end) |
1510 FLD_VAL(haccu, hor_start, hor_end);
1511
Archit Taneja9b372c22011-05-06 11:45:49 +05301512 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001513}
1514
Jyri Sarha864050c2017-03-24 16:47:52 +02001515static void dispc_ovl_set_vid_accu1(enum omap_plane_id plane, int haccu,
1516 int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001517{
1518 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301519 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001520
Archit Taneja87a74842011-03-02 11:19:50 +05301521 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1522 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1523
1524 val = FLD_VAL(vaccu, vert_start, vert_end) |
1525 FLD_VAL(haccu, hor_start, hor_end);
1526
Archit Taneja9b372c22011-05-06 11:45:49 +05301527 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001528}
1529
Jyri Sarha864050c2017-03-24 16:47:52 +02001530static void dispc_ovl_set_vid_accu2_0(enum omap_plane_id plane, int haccu,
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001531 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301532{
1533 u32 val;
1534
1535 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1536 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1537}
1538
Jyri Sarha864050c2017-03-24 16:47:52 +02001539static void dispc_ovl_set_vid_accu2_1(enum omap_plane_id plane, int haccu,
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001540 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301541{
1542 u32 val;
1543
1544 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1545 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1546}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001547
Jyri Sarha864050c2017-03-24 16:47:52 +02001548static void dispc_ovl_set_scale_param(enum omap_plane_id plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001549 u16 orig_width, u16 orig_height,
1550 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301551 bool five_taps, u8 rotation,
1552 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001553{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301554 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001555
Amber Jained14a3c2011-05-19 19:47:51 +05301556 fir_hinc = 1024 * orig_width / out_width;
1557 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001558
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301559 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1560 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001561 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301562}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001563
Jyri Sarha864050c2017-03-24 16:47:52 +02001564static void dispc_ovl_set_accu_uv(enum omap_plane_id plane,
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301565 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001566 bool ilace, u32 fourcc, u8 rotation)
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301567{
1568 int h_accu2_0, h_accu2_1;
1569 int v_accu2_0, v_accu2_1;
1570 int chroma_hinc, chroma_vinc;
1571 int idx;
1572
1573 struct accu {
1574 s8 h0_m, h0_n;
1575 s8 h1_m, h1_n;
1576 s8 v0_m, v0_n;
1577 s8 v1_m, v1_n;
1578 };
1579
1580 const struct accu *accu_table;
1581 const struct accu *accu_val;
1582
1583 static const struct accu accu_nv12[4] = {
1584 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1585 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1586 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1587 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1588 };
1589
1590 static const struct accu accu_nv12_ilace[4] = {
1591 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1592 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1593 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1594 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1595 };
1596
1597 static const struct accu accu_yuv[4] = {
1598 { 0, 1, 0, 1, 0, 1, 0, 1 },
1599 { 0, 1, 0, 1, 0, 1, 0, 1 },
1600 { -1, 1, 0, 1, 0, 1, 0, 1 },
1601 { 0, 1, 0, 1, -1, 1, 0, 1 },
1602 };
1603
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001604 /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
1605 switch (rotation & DRM_MODE_ROTATE_MASK) {
1606 default:
1607 case DRM_MODE_ROTATE_0:
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301608 idx = 0;
1609 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001610 case DRM_MODE_ROTATE_90:
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301611 idx = 3;
1612 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001613 case DRM_MODE_ROTATE_180:
1614 idx = 2;
1615 break;
1616 case DRM_MODE_ROTATE_270:
1617 idx = 1;
1618 break;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301619 }
1620
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001621 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001622 case DRM_FORMAT_NV12:
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301623 if (ilace)
1624 accu_table = accu_nv12_ilace;
1625 else
1626 accu_table = accu_nv12;
1627 break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001628 case DRM_FORMAT_YUYV:
1629 case DRM_FORMAT_UYVY:
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301630 accu_table = accu_yuv;
1631 break;
1632 default:
1633 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001634 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301635 }
1636
1637 accu_val = &accu_table[idx];
1638
1639 chroma_hinc = 1024 * orig_width / out_width;
1640 chroma_vinc = 1024 * orig_height / out_height;
1641
1642 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1643 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1644 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1645 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1646
1647 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1648 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1649}
1650
Jyri Sarha864050c2017-03-24 16:47:52 +02001651static void dispc_ovl_set_scaling_common(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301652 u16 orig_width, u16 orig_height,
1653 u16 out_width, u16 out_height,
1654 bool ilace, bool five_taps,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001655 bool fieldmode, u32 fourcc,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301656 u8 rotation)
1657{
1658 int accu0 = 0;
1659 int accu1 = 0;
1660 u32 l;
1661
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001662 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301663 out_width, out_height, five_taps,
1664 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301665 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001666
Archit Taneja87a74842011-03-02 11:19:50 +05301667 /* RESIZEENABLE and VERTICALTAPS */
1668 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301669 l |= (orig_width != out_width) ? (1 << 5) : 0;
1670 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001671 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301672
1673 /* VRESIZECONF and HRESIZECONF */
1674 if (dss_has_feature(FEAT_RESIZECONF)) {
1675 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301676 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1677 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301678 }
1679
1680 /* LINEBUFFERSPLIT */
1681 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1682 l &= ~(0x1 << 22);
1683 l |= five_taps ? (1 << 22) : 0;
1684 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001685
Archit Taneja9b372c22011-05-06 11:45:49 +05301686 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001687
1688 /*
1689 * field 0 = even field = bottom field
1690 * field 1 = odd field = top field
1691 */
1692 if (ilace && !fieldmode) {
1693 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301694 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001695 if (accu0 >= 1024/2) {
1696 accu1 = 1024/2;
1697 accu0 -= accu1;
1698 }
1699 }
1700
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001701 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1702 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001703}
1704
Jyri Sarha864050c2017-03-24 16:47:52 +02001705static void dispc_ovl_set_scaling_uv(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301706 u16 orig_width, u16 orig_height,
1707 u16 out_width, u16 out_height,
1708 bool ilace, bool five_taps,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001709 bool fieldmode, u32 fourcc,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301710 u8 rotation)
1711{
1712 int scale_x = out_width != orig_width;
1713 int scale_y = out_height != orig_height;
Andrew F. Davis0cac5b62016-07-01 09:27:21 -05001714 bool chroma_upscale = plane != OMAP_DSS_WB;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301715
1716 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1717 return;
Tomi Valkeinen5edec142017-05-04 09:13:32 +03001718
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001719 if (!format_is_yuv(fourcc)) {
Amber Jain0d66cbb2011-05-19 19:47:54 +05301720 /* reset chroma resampling for RGB formats */
Archit Taneja2a5561b2012-07-16 16:37:45 +05301721 if (plane != OMAP_DSS_WB)
1722 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301723 return;
1724 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001725
1726 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001727 out_height, ilace, fourcc, rotation);
Tomi Valkeinen36377352012-05-15 15:54:15 +03001728
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001729 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001730 case DRM_FORMAT_NV12:
Archit Taneja20fbb502012-08-22 17:04:48 +05301731 if (chroma_upscale) {
1732 /* UV is subsampled by 2 horizontally and vertically */
1733 orig_height >>= 1;
1734 orig_width >>= 1;
1735 } else {
1736 /* UV is downsampled by 2 horizontally and vertically */
1737 orig_height <<= 1;
1738 orig_width <<= 1;
1739 }
1740
Amber Jain0d66cbb2011-05-19 19:47:54 +05301741 break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001742 case DRM_FORMAT_YUYV:
1743 case DRM_FORMAT_UYVY:
Archit Taneja20fbb502012-08-22 17:04:48 +05301744 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001745 if (!drm_rotation_90_or_270(rotation)) {
Archit Taneja20fbb502012-08-22 17:04:48 +05301746 if (chroma_upscale)
1747 /* UV is subsampled by 2 horizontally */
1748 orig_width >>= 1;
1749 else
1750 /* UV is downsampled by 2 horizontally */
1751 orig_width <<= 1;
1752 }
1753
Amber Jain0d66cbb2011-05-19 19:47:54 +05301754 /* must use FIR for YUV422 if rotated */
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001755 if ((rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0)
Amber Jain0d66cbb2011-05-19 19:47:54 +05301756 scale_x = scale_y = true;
Archit Taneja20fbb502012-08-22 17:04:48 +05301757
Amber Jain0d66cbb2011-05-19 19:47:54 +05301758 break;
1759 default:
1760 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001761 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301762 }
1763
1764 if (out_width != orig_width)
1765 scale_x = true;
1766 if (out_height != orig_height)
1767 scale_y = true;
1768
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001769 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301770 out_width, out_height, five_taps,
1771 rotation, DISPC_COLOR_COMPONENT_UV);
1772
Archit Taneja2a5561b2012-07-16 16:37:45 +05301773 if (plane != OMAP_DSS_WB)
1774 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1775 (scale_x || scale_y) ? 1 : 0, 8, 8);
1776
Amber Jain0d66cbb2011-05-19 19:47:54 +05301777 /* set H scaling */
1778 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1779 /* set V scaling */
1780 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301781}
1782
Jyri Sarha864050c2017-03-24 16:47:52 +02001783static void dispc_ovl_set_scaling(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301784 u16 orig_width, u16 orig_height,
1785 u16 out_width, u16 out_height,
1786 bool ilace, bool five_taps,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001787 bool fieldmode, u32 fourcc,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301788 u8 rotation)
1789{
1790 BUG_ON(plane == OMAP_DSS_GFX);
1791
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001792 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301793 orig_width, orig_height,
1794 out_width, out_height,
1795 ilace, five_taps,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001796 fieldmode, fourcc,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301797 rotation);
1798
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001799 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301800 orig_width, orig_height,
1801 out_width, out_height,
1802 ilace, five_taps,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001803 fieldmode, fourcc,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301804 rotation);
1805}
1806
Jyri Sarha273ffea2017-03-24 16:47:53 +02001807static void dispc_ovl_set_rotation_attrs(enum omap_plane_id plane, u8 rotation,
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03001808 enum omap_dss_rotation_type rotation_type, u32 fourcc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001809{
Archit Taneja87a74842011-03-02 11:19:50 +05301810 bool row_repeat = false;
1811 int vidrot = 0;
1812
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001813 /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001814 if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001815
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03001816 if (rotation & DRM_MODE_REFLECT_X) {
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001817 switch (rotation & DRM_MODE_ROTATE_MASK) {
1818 case DRM_MODE_ROTATE_0:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001819 vidrot = 2;
1820 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001821 case DRM_MODE_ROTATE_90:
1822 vidrot = 3;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001823 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001824 case DRM_MODE_ROTATE_180:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001825 vidrot = 0;
1826 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001827 case DRM_MODE_ROTATE_270:
1828 vidrot = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001829 break;
1830 }
1831 } else {
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001832 switch (rotation & DRM_MODE_ROTATE_MASK) {
1833 case DRM_MODE_ROTATE_0:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001834 vidrot = 0;
1835 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001836 case DRM_MODE_ROTATE_90:
1837 vidrot = 3;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001838 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001839 case DRM_MODE_ROTATE_180:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001840 vidrot = 2;
1841 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001842 case DRM_MODE_ROTATE_270:
1843 vidrot = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001844 break;
1845 }
1846 }
1847
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001848 if (drm_rotation_90_or_270(rotation))
Archit Taneja87a74842011-03-02 11:19:50 +05301849 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001850 else
Archit Taneja87a74842011-03-02 11:19:50 +05301851 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001852 }
Archit Taneja87a74842011-03-02 11:19:50 +05301853
Tomi Valkeinen3397cc62015-04-09 13:51:30 +03001854 /*
1855 * OMAP4/5 Errata i631:
1856 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
1857 * rows beyond the framebuffer, which may cause OCP error.
1858 */
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001859 if (fourcc == DRM_FORMAT_NV12 && rotation_type != OMAP_DSS_ROT_TILER)
Tomi Valkeinen3397cc62015-04-09 13:51:30 +03001860 vidrot = 1;
1861
Archit Taneja9b372c22011-05-06 11:45:49 +05301862 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301863 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301864 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1865 row_repeat ? 1 : 0, 18, 18);
Archit Tanejac35eeb22013-03-26 19:15:24 +05301866
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001867 if (dss_feat_color_mode_supported(plane, DRM_FORMAT_NV12)) {
Tomi Valkeinen6d862782016-08-29 11:15:49 +03001868 bool doublestride =
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001869 fourcc == DRM_FORMAT_NV12 &&
Tomi Valkeinen6d862782016-08-29 11:15:49 +03001870 rotation_type == OMAP_DSS_ROT_TILER &&
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001871 !drm_rotation_90_or_270(rotation);
Tomi Valkeinen6d862782016-08-29 11:15:49 +03001872
Archit Tanejac35eeb22013-03-26 19:15:24 +05301873 /* DOUBLESTRIDE */
1874 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22);
1875 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001876}
1877
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001878static int color_mode_to_bpp(u32 fourcc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001879{
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001880 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001881 case DRM_FORMAT_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001882 return 8;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001883 case DRM_FORMAT_RGBX4444:
1884 case DRM_FORMAT_RGB565:
1885 case DRM_FORMAT_ARGB4444:
1886 case DRM_FORMAT_YUYV:
1887 case DRM_FORMAT_UYVY:
1888 case DRM_FORMAT_RGBA4444:
1889 case DRM_FORMAT_XRGB4444:
1890 case DRM_FORMAT_ARGB1555:
1891 case DRM_FORMAT_XRGB1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001892 return 16;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001893 case DRM_FORMAT_RGB888:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001894 return 24;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001895 case DRM_FORMAT_XRGB8888:
1896 case DRM_FORMAT_ARGB8888:
1897 case DRM_FORMAT_RGBA8888:
1898 case DRM_FORMAT_RGBX8888:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001899 return 32;
1900 default:
1901 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001902 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001903 }
1904}
1905
1906static s32 pixinc(int pixels, u8 ps)
1907{
1908 if (pixels == 1)
1909 return 1;
1910 else if (pixels > 1)
1911 return 1 + (pixels - 1) * ps;
1912 else if (pixels < 0)
1913 return 1 - (-pixels + 1) * ps;
1914 else
1915 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001916 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001917}
1918
Tomi Valkeinen517a8a952017-05-03 14:14:27 +03001919static void calc_offset(u16 screen_width, u16 width,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001920 u32 fourcc, bool fieldmode,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301921 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1922 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1923{
1924 u8 ps;
1925
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001926 ps = color_mode_to_bpp(fourcc) / 8;
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301927
1928 DSSDBG("scrw %d, width %d\n", screen_width, width);
1929
1930 /*
1931 * field 0 = even field = bottom field
1932 * field 1 = odd field = top field
1933 */
Tomi Valkeinen185e23e2017-05-03 15:01:10 +03001934 *offset0 = field_offset * screen_width * ps;
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301935 *offset1 = 0;
Tomi Valkeinen185e23e2017-05-03 15:01:10 +03001936
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301937 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1938 (fieldmode ? screen_width : 0), ps);
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001939 if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY)
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301940 *pix_inc = pixinc(x_predecim, 2 * ps);
1941 else
1942 *pix_inc = pixinc(x_predecim, ps);
1943}
1944
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301945/*
1946 * This function is used to avoid synclosts in OMAP3, because of some
1947 * undocumented horizontal position and timing related limitations.
1948 */
Tomi Valkeinen465ec132012-10-19 15:40:24 +03001949static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03001950 const struct videomode *vm, u16 pos_x,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02001951 u16 width, u16 height, u16 out_width, u16 out_height,
1952 bool five_taps)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301953{
Tomi Valkeinen230edc02012-11-05 14:40:19 +02001954 const int ds = DIV_ROUND_UP(height, out_height);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05301955 unsigned long nonactive;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301956 static const u8 limits[3] = { 8, 10, 20 };
1957 u64 val, blank;
1958 int i;
1959
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03001960 nonactive = vm->hactive + vm->hfront_porch + vm->hsync_len +
1961 vm->hback_porch - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301962
1963 i = 0;
1964 if (out_height < height)
1965 i++;
1966 if (out_width < width)
1967 i++;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03001968 blank = div_u64((u64)(vm->hback_porch + vm->hsync_len + vm->hfront_porch) *
Peter Ujfalusi0a30e152016-09-22 14:06:49 +03001969 lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301970 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
1971 if (blank <= limits[i])
1972 return -EINVAL;
1973
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02001974 /* FIXME add checks for 3-tap filter once the limitations are known */
1975 if (!five_taps)
1976 return 0;
1977
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301978 /*
1979 * Pixel data should be prepared before visible display point starts.
1980 * So, atleast DS-2 lines must have already been fetched by DISPC
1981 * during nonactive - pos_x period.
1982 */
1983 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
1984 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02001985 val, max(0, ds - 2) * width);
1986 if (val < max(0, ds - 2) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301987 return -EINVAL;
1988
1989 /*
1990 * All lines need to be refilled during the nonactive period of which
1991 * only one line can be loaded during the active period. So, atleast
1992 * DS - 1 lines should be loaded during nonactive period.
1993 */
1994 val = div_u64((u64)nonactive * lclk, pclk);
1995 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02001996 val, max(0, ds - 1) * width);
1997 if (val < max(0, ds - 1) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301998 return -EINVAL;
1999
2000 return 0;
2001}
2002
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002003static unsigned long calc_core_clk_five_taps(unsigned long pclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002004 const struct videomode *vm, u16 width,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302005 u16 height, u16 out_width, u16 out_height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002006 u32 fourcc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002007{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302008 u32 core_clk = 0;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302009 u64 tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002010
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302011 if (height <= out_height && width <= out_width)
2012 return (unsigned long) pclk;
2013
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002014 if (height > out_height) {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002015 unsigned int ppl = vm->hactive;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002016
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002017 tmp = (u64)pclk * height * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002018 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302019 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002020
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02002021 if (height > 2 * out_height) {
2022 if (ppl == out_width)
2023 return 0;
2024
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002025 tmp = (u64)pclk * (height - 2 * out_height) * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002026 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302027 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002028 }
2029 }
2030
2031 if (width > out_width) {
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002032 tmp = (u64)pclk * width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002033 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302034 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002035
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002036 if (fourcc == DRM_FORMAT_XRGB8888)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302037 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002038 }
2039
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302040 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002041}
2042
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002043static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302044 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302045{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302046 if (height > out_height && width > out_width)
2047 return pclk * 4;
2048 else
2049 return pclk * 2;
2050}
2051
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002052static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302053 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002054{
2055 unsigned int hf, vf;
2056
2057 /*
2058 * FIXME how to determine the 'A' factor
2059 * for the no downscaling case ?
2060 */
2061
2062 if (width > 3 * out_width)
2063 hf = 4;
2064 else if (width > 2 * out_width)
2065 hf = 3;
2066 else if (width > out_width)
2067 hf = 2;
2068 else
2069 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002070 if (height > out_height)
2071 vf = 2;
2072 else
2073 vf = 1;
2074
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302075 return pclk * vf * hf;
2076}
2077
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002078static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302079 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302080{
Archit Taneja8ba85302012-09-26 17:00:37 +05302081 /*
2082 * If the overlay/writeback is in mem to mem mode, there are no
2083 * downscaling limitations with respect to pixel clock, return 1 as
2084 * required core clock to represent that we have sufficient enough
2085 * core clock to do maximum downscaling
2086 */
2087 if (mem_to_mem)
2088 return 1;
2089
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302090 if (width > out_width)
2091 return DIV_ROUND_UP(pclk, out_width) * width;
2092 else
2093 return pclk;
2094}
2095
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002096static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002097 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302098 u16 width, u16 height, u16 out_width, u16 out_height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002099 u32 fourcc, bool *five_taps,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302100 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302101 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302102{
2103 int error;
2104 u16 in_width, in_height;
2105 int min_factor = min(*decim_x, *decim_y);
2106 const int maxsinglelinewidth =
2107 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302108
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302109 *five_taps = false;
2110
2111 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002112 in_height = height / *decim_y;
2113 in_width = width / *decim_x;
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002114 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302115 in_height, out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302116 error = (in_width > maxsinglelinewidth || !*core_clk ||
2117 *core_clk > dispc_core_clk_rate());
2118 if (error) {
2119 if (*decim_x == *decim_y) {
2120 *decim_x = min_factor;
2121 ++*decim_y;
2122 } else {
2123 swap(*decim_x, *decim_y);
2124 if (*decim_x < *decim_y)
2125 ++*decim_x;
2126 }
2127 }
2128 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2129
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002130 if (error) {
2131 DSSERR("failed to find scaling settings\n");
2132 return -EINVAL;
2133 }
2134
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302135 if (in_width > maxsinglelinewidth) {
2136 DSSERR("Cannot scale max input width exceeded");
2137 return -EINVAL;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302138 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302139 return 0;
2140}
2141
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002142static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002143 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302144 u16 width, u16 height, u16 out_width, u16 out_height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002145 u32 fourcc, bool *five_taps,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302146 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302147 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302148{
2149 int error;
2150 u16 in_width, in_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302151 const int maxsinglelinewidth =
2152 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2153
2154 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002155 in_height = height / *decim_y;
2156 in_width = width / *decim_x;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002157 *five_taps = in_height > out_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302158
2159 if (in_width > maxsinglelinewidth)
2160 if (in_height > out_height &&
2161 in_height < out_height * 2)
2162 *five_taps = false;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002163again:
2164 if (*five_taps)
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002165 *core_clk = calc_core_clk_five_taps(pclk, vm,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002166 in_width, in_height, out_width,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002167 out_height, fourcc);
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002168 else
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002169 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302170 in_height, out_width, out_height,
2171 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302172
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002173 error = check_horiz_timing_omap3(pclk, lclk, vm,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002174 pos_x, in_width, in_height, out_width,
2175 out_height, *five_taps);
2176 if (error && *five_taps) {
2177 *five_taps = false;
2178 goto again;
2179 }
2180
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302181 error = (error || in_width > maxsinglelinewidth * 2 ||
2182 (in_width > maxsinglelinewidth && *five_taps) ||
2183 !*core_clk || *core_clk > dispc_core_clk_rate());
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002184
2185 if (!error) {
2186 /* verify that we're inside the limits of scaler */
2187 if (in_width / 4 > out_width)
2188 error = 1;
2189
2190 if (*five_taps) {
2191 if (in_height / 4 > out_height)
2192 error = 1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302193 } else {
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002194 if (in_height / 2 > out_height)
2195 error = 1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302196 }
2197 }
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002198
Tomi Valkeinen7059e3d2015-04-10 12:48:38 +03002199 if (error)
2200 ++*decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302201 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2202
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002203 if (error) {
2204 DSSERR("failed to find scaling settings\n");
2205 return -EINVAL;
2206 }
2207
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002208 if (check_horiz_timing_omap3(pclk, lclk, vm, pos_x, in_width,
Tomi Valkeinenf5a73482015-03-17 15:31:09 +02002209 in_height, out_width, out_height, *five_taps)) {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302210 DSSERR("horizontal timing too tight\n");
2211 return -EINVAL;
2212 }
2213
2214 if (in_width > (maxsinglelinewidth * 2)) {
2215 DSSERR("Cannot setup scaling");
2216 DSSERR("width exceeds maximum width possible");
2217 return -EINVAL;
2218 }
2219
2220 if (in_width > maxsinglelinewidth && *five_taps) {
2221 DSSERR("cannot setup scaling with five taps");
2222 return -EINVAL;
2223 }
2224 return 0;
2225}
2226
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002227static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002228 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302229 u16 width, u16 height, u16 out_width, u16 out_height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002230 u32 fourcc, bool *five_taps,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302231 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302232 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302233{
2234 u16 in_width, in_width_max;
2235 int decim_x_min = *decim_x;
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002236 u16 in_height = height / *decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302237 const int maxsinglelinewidth =
2238 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja8ba85302012-09-26 17:00:37 +05302239 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302240
Archit Taneja5d501082012-11-07 11:45:02 +05302241 if (mem_to_mem) {
2242 in_width_max = out_width * maxdownscale;
2243 } else {
Archit Taneja8ba85302012-09-26 17:00:37 +05302244 in_width_max = dispc_core_clk_rate() /
2245 DIV_ROUND_UP(pclk, out_width);
Archit Taneja5d501082012-11-07 11:45:02 +05302246 }
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302247
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302248 *decim_x = DIV_ROUND_UP(width, in_width_max);
2249
2250 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2251 if (*decim_x > *x_predecim)
2252 return -EINVAL;
2253
2254 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002255 in_width = width / *decim_x;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302256 } while (*decim_x <= *x_predecim &&
2257 in_width > maxsinglelinewidth && ++*decim_x);
2258
2259 if (in_width > maxsinglelinewidth) {
2260 DSSERR("Cannot scale width exceeds max line width");
2261 return -EINVAL;
2262 }
2263
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002264 if (*decim_x > 4 && fourcc != DRM_FORMAT_NV12) {
Jyri Sarha1b30ab02017-02-08 16:08:06 +02002265 /*
2266 * Let's disable all scaling that requires horizontal
2267 * decimation with higher factor than 4, until we have
2268 * better estimates of what we can and can not
2269 * do. However, NV12 color format appears to work Ok
2270 * with all decimation factors.
2271 *
2272 * When decimating horizontally by more that 4 the dss
2273 * is not able to fetch the data in burst mode. When
2274 * this happens it is hard to tell if there enough
2275 * bandwidth. Despite what theory says this appears to
2276 * be true also for 16-bit color formats.
2277 */
2278 DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)", *decim_x);
2279
2280 return -EINVAL;
2281 }
2282
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002283 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
Archit Taneja8ba85302012-09-26 17:00:37 +05302284 out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302285 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002286}
2287
Tomi Valkeinene4c5ae72015-04-10 12:48:39 +03002288#define DIV_FRAC(dividend, divisor) \
2289 ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2290
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002291static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302292 enum omap_overlay_caps caps,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002293 const struct videomode *vm,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302294 u16 width, u16 height, u16 out_width, u16 out_height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002295 u32 fourcc, bool *five_taps,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302296 int *x_predecim, int *y_predecim, u16 pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302297 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302298{
Archit Taneja0373cac2011-09-08 13:25:17 +05302299 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302300 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302301 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302302 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302303
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002304 if (width == out_width && height == out_height)
2305 return 0;
2306
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002307 if (!mem_to_mem && (pclk == 0 || vm->pixelclock == 0)) {
Tomi Valkeinen4e1d3ca2014-10-03 15:14:09 +00002308 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2309 return -EINVAL;
2310 }
2311
Archit Taneja5b54ed32012-09-26 16:55:27 +05302312 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002313 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302314
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002315 if (mem_to_mem) {
Archit Taneja1c031442012-11-07 11:45:03 +05302316 *x_predecim = *y_predecim = 1;
2317 } else {
2318 *x_predecim = max_decim_limit;
2319 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2320 dss_has_feature(FEAT_BURST_2D)) ?
2321 2 : max_decim_limit;
2322 }
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302323
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302324 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2325 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2326
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302327 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302328 return -EINVAL;
2329
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302330 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302331 return -EINVAL;
2332
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002333 ret = dispc.feat->calc_scaling(pclk, lclk, vm, width, height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002334 out_width, out_height, fourcc, five_taps,
Archit Taneja8ba85302012-09-26 17:00:37 +05302335 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2336 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302337 if (ret)
2338 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302339
Tomi Valkeinene4c5ae72015-04-10 12:48:39 +03002340 DSSDBG("%dx%d -> %dx%d (%d.%02d x %d.%02d), decim %dx%d %dx%d (%d.%02d x %d.%02d), taps %d, req clk %lu, cur clk %lu\n",
2341 width, height,
2342 out_width, out_height,
2343 out_width / width, DIV_FRAC(out_width, width),
2344 out_height / height, DIV_FRAC(out_height, height),
2345
2346 decim_x, decim_y,
2347 width / decim_x, height / decim_y,
2348 out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
2349 out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
2350
2351 *five_taps ? 5 : 3,
2352 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302353
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302354 if (!core_clk || core_clk > dispc_core_clk_rate()) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302355 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302356 "required core clk rate = %lu Hz, "
2357 "current core clk rate = %lu Hz\n",
2358 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302359 return -EINVAL;
2360 }
2361
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302362 *x_predecim = decim_x;
2363 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302364 return 0;
2365}
2366
Jyri Sarha864050c2017-03-24 16:47:52 +02002367static int dispc_ovl_setup_common(enum omap_plane_id plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302368 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2369 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002370 u16 out_width, u16 out_height, u32 fourcc,
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002371 u8 rotation, u8 zorder, u8 pre_mult_alpha,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302372 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002373 bool replication, const struct videomode *vm,
Archit Taneja8ba85302012-09-26 17:00:37 +05302374 bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002375{
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302376 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002377 bool fieldmode = false;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302378 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002379 unsigned offset0, offset1;
2380 s32 row_inc;
2381 s32 pix_inc;
Archit Taneja6be0d732012-11-07 11:45:04 +05302382 u16 frame_width, frame_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002383 unsigned int field_offset = 0;
Archit Taneja84a880f2012-09-26 16:57:37 +05302384 u16 in_height = height;
2385 u16 in_width = width;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302386 int x_predecim = 1, y_predecim = 1;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002387 bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED);
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002388 unsigned long pclk = dispc_plane_pclk_rate(plane);
2389 unsigned long lclk = dispc_plane_lclk_rate(plane);
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002390
Tomi Valkeinene5666582014-11-28 14:34:15 +02002391 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002392 return -EINVAL;
2393
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002394 if (format_is_yuv(fourcc) && (in_width & 1)) {
Tomi Valkeinen5edec142017-05-04 09:13:32 +03002395 DSSERR("input width %d is not even for YUV format\n", in_width);
2396 return -EINVAL;
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002397 }
2398
Archit Taneja84a880f2012-09-26 16:57:37 +05302399 out_width = out_width == 0 ? width : out_width;
2400 out_height = out_height == 0 ? height : out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002401
Archit Taneja84a880f2012-09-26 16:57:37 +05302402 if (ilace && height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002403 fieldmode = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002404
2405 if (ilace) {
2406 if (fieldmode)
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302407 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302408 pos_y /= 2;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302409 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002410
2411 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
Archit Taneja84a880f2012-09-26 16:57:37 +05302412 "out_height %d\n", in_height, pos_y,
2413 out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002414 }
2415
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002416 if (!dss_feat_color_mode_supported(plane, fourcc))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302417 return -EINVAL;
2418
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002419 r = dispc_ovl_calc_scaling(pclk, lclk, caps, vm, in_width,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002420 in_height, out_width, out_height, fourcc,
Archit Taneja84a880f2012-09-26 16:57:37 +05302421 &five_taps, &x_predecim, &y_predecim, pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302422 rotation_type, mem_to_mem);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302423 if (r)
2424 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002425
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002426 in_width = in_width / x_predecim;
2427 in_height = in_height / y_predecim;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302428
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002429 if (x_predecim > 1 || y_predecim > 1)
2430 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2431 x_predecim, y_predecim, in_width, in_height);
2432
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002433 if (format_is_yuv(fourcc) && (in_width & 1)) {
Tomi Valkeinen5edec142017-05-04 09:13:32 +03002434 DSSDBG("predecimated input width is not even for YUV format\n");
2435 DSSDBG("adjusting input width %d -> %d\n",
2436 in_width, in_width & ~1);
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002437
Tomi Valkeinen5edec142017-05-04 09:13:32 +03002438 in_width &= ~1;
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002439 }
2440
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002441 if (format_is_yuv(fourcc))
Archit Taneja79ad75f2011-09-08 13:15:11 +05302442 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002443
2444 if (ilace && !fieldmode) {
2445 /*
2446 * when downscaling the bottom field may have to start several
2447 * source lines below the top field. Unfortunately ACCUI
2448 * registers will only hold the fractional part of the offset
2449 * so the integer part must be added to the base address of the
2450 * bottom field.
2451 */
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302452 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002453 field_offset = 0;
2454 else
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302455 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002456 }
2457
2458 /* Fields are independent but interleaved in memory. */
2459 if (fieldmode)
2460 field_offset = 1;
2461
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002462 offset0 = 0;
2463 offset1 = 0;
2464 row_inc = 0;
2465 pix_inc = 0;
2466
Archit Taneja6be0d732012-11-07 11:45:04 +05302467 if (plane == OMAP_DSS_WB) {
2468 frame_width = out_width;
2469 frame_height = out_height;
2470 } else {
2471 frame_width = in_width;
2472 frame_height = height;
2473 }
2474
Tomi Valkeinen517a8a952017-05-03 14:14:27 +03002475 calc_offset(screen_width, frame_width,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002476 fourcc, fieldmode, field_offset,
Tomi Valkeinen517a8a952017-05-03 14:14:27 +03002477 &offset0, &offset1, &row_inc, &pix_inc,
2478 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002479
2480 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2481 offset0, offset1, row_inc, pix_inc);
2482
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002483 dispc_ovl_set_color_mode(plane, fourcc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002484
Archit Taneja84a880f2012-09-26 16:57:37 +05302485 dispc_ovl_configure_burst_type(plane, rotation_type);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302486
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02002487 if (dispc.feat->reverse_ilace_field_order)
2488 swap(offset0, offset1);
2489
Archit Taneja84a880f2012-09-26 16:57:37 +05302490 dispc_ovl_set_ba0(plane, paddr + offset0);
2491 dispc_ovl_set_ba1(plane, paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002492
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002493 if (fourcc == DRM_FORMAT_NV12) {
Archit Taneja84a880f2012-09-26 16:57:37 +05302494 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2495 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302496 }
2497
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03002498 if (dispc.feat->last_pixel_inc_missing)
2499 row_inc += pix_inc - 1;
2500
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002501 dispc_ovl_set_row_inc(plane, row_inc);
2502 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002503
Archit Taneja84a880f2012-09-26 16:57:37 +05302504 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302505 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002506
Archit Taneja84a880f2012-09-26 16:57:37 +05302507 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002508
Archit Taneja78b687f2012-09-21 14:51:49 +05302509 dispc_ovl_set_input_size(plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002510
Archit Taneja5b54ed32012-09-26 16:55:27 +05302511 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302512 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2513 out_height, ilace, five_taps, fieldmode,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002514 fourcc, rotation);
Archit Taneja78b687f2012-09-21 14:51:49 +05302515 dispc_ovl_set_output_size(plane, out_width, out_height);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002516 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002517 }
2518
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002519 dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, fourcc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002520
Archit Taneja84a880f2012-09-26 16:57:37 +05302521 dispc_ovl_set_zorder(plane, caps, zorder);
2522 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2523 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002524
Archit Tanejad79db852012-09-22 12:30:17 +05302525 dispc_ovl_enable_replication(plane, caps, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302526
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002527 return 0;
2528}
2529
Jyri Sarha864050c2017-03-24 16:47:52 +02002530static int dispc_ovl_setup(enum omap_plane_id plane,
Jyri Sarha273ffea2017-03-24 16:47:53 +02002531 const struct omap_overlay_info *oi,
Tomi Valkeinen49a30572017-02-17 12:30:07 +02002532 const struct videomode *vm, bool mem_to_mem,
2533 enum omap_channel channel)
Archit Taneja84a880f2012-09-26 16:57:37 +05302534{
2535 int r;
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002536 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
Tomi Valkeinenbe2d68c2016-08-29 13:15:02 +03002537 const bool replication = true;
Archit Taneja84a880f2012-09-26 16:57:37 +05302538
Arnd Bergmann24f13a62014-04-24 13:28:18 +01002539 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002540 " %dx%d, cmode %x, rot %d, chan %d repl %d\n",
Arnd Bergmann24f13a62014-04-24 13:28:18 +01002541 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
Archit Taneja84a880f2012-09-26 16:57:37 +05302542 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002543 oi->fourcc, oi->rotation, channel, replication);
Archit Taneja84a880f2012-09-26 16:57:37 +05302544
Tomi Valkeinen49a30572017-02-17 12:30:07 +02002545 dispc_ovl_set_channel_out(plane, channel);
2546
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002547 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302548 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002549 oi->out_width, oi->out_height, oi->fourcc, oi->rotation,
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002550 oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002551 oi->rotation_type, replication, vm, mem_to_mem);
Archit Taneja84a880f2012-09-26 16:57:37 +05302552
2553 return r;
2554}
2555
Archit Taneja749feff2012-08-31 12:32:52 +05302556int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002557 bool mem_to_mem, const struct videomode *vm)
Archit Taneja749feff2012-08-31 12:32:52 +05302558{
2559 int r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302560 u32 l;
Jyri Sarha864050c2017-03-24 16:47:52 +02002561 enum omap_plane_id plane = OMAP_DSS_WB;
Archit Taneja749feff2012-08-31 12:32:52 +05302562 const int pos_x = 0, pos_y = 0;
2563 const u8 zorder = 0, global_alpha = 0;
Tomi Valkeinenbe2d68c2016-08-29 13:15:02 +03002564 const bool replication = true;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302565 bool truncation;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002566 int in_width = vm->hactive;
2567 int in_height = vm->vactive;
Archit Taneja749feff2012-08-31 12:32:52 +05302568 enum omap_overlay_caps caps =
2569 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2570
2571 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002572 "rot %d\n", wi->paddr, wi->p_uv_addr, in_width,
2573 in_height, wi->width, wi->height, wi->fourcc, wi->rotation);
Archit Taneja749feff2012-08-31 12:32:52 +05302574
2575 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2576 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002577 wi->height, wi->fourcc, wi->rotation, zorder,
Archit Taneja749feff2012-08-31 12:32:52 +05302578 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002579 replication, vm, mem_to_mem);
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302580
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002581 switch (wi->fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03002582 case DRM_FORMAT_RGB565:
2583 case DRM_FORMAT_RGB888:
2584 case DRM_FORMAT_ARGB4444:
2585 case DRM_FORMAT_RGBA4444:
2586 case DRM_FORMAT_RGBX4444:
2587 case DRM_FORMAT_ARGB1555:
2588 case DRM_FORMAT_XRGB1555:
2589 case DRM_FORMAT_XRGB4444:
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302590 truncation = true;
2591 break;
2592 default:
2593 truncation = false;
2594 break;
2595 }
2596
2597 /* setup extra DISPC_WB_ATTRIBUTES */
2598 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2599 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2600 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
Tomi Valkeinen4c055ce2015-11-04 17:10:53 +02002601 if (mem_to_mem)
2602 l = FLD_MOD(l, 1, 26, 24); /* CAPTUREMODE */
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002603 else
2604 l = FLD_MOD(l, 0, 26, 24); /* CAPTUREMODE */
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302605 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Archit Taneja749feff2012-08-31 12:32:52 +05302606
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002607 if (mem_to_mem) {
2608 /* WBDELAYCOUNT */
2609 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0);
2610 } else {
2611 int wbdelay;
2612
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002613 wbdelay = min(vm->vfront_porch +
2614 vm->vsync_len + vm->vback_porch, (u32)255);
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002615
2616 /* WBDELAYCOUNT */
2617 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0);
2618 }
2619
Archit Taneja749feff2012-08-31 12:32:52 +05302620 return r;
2621}
2622
Jyri Sarha864050c2017-03-24 16:47:52 +02002623static int dispc_ovl_enable(enum omap_plane_id plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002624{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002625 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2626
Archit Taneja9b372c22011-05-06 11:45:49 +05302627 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002628
2629 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002630}
2631
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002632static enum omap_dss_output_id dispc_mgr_get_supported_outputs(enum omap_channel channel)
Tomi Valkeinen7b9cb5e2015-11-04 15:11:25 +02002633{
2634 return dss_feat_get_supported_outputs(channel);
2635}
Tomi Valkeinen7b9cb5e2015-11-04 15:11:25 +02002636
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002637static void dispc_lcd_enable_signal_polarity(bool act_high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002638{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002639 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2640 return;
2641
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002642 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002643}
2644
2645void dispc_lcd_enable_signal(bool enable)
2646{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002647 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2648 return;
2649
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002650 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002651}
2652
2653void dispc_pck_free_enable(bool enable)
2654{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002655 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2656 return;
2657
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002658 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002659}
2660
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002661static int dispc_get_num_mgrs(void)
Tomi Valkeinenc2834002015-11-05 19:54:33 +02002662{
2663 return dss_feat_get_num_mgrs();
2664}
Tomi Valkeinenc2834002015-11-05 19:54:33 +02002665
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002666static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002667{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302668 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002669}
2670
2671
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002672static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002673{
Archit Tanejad21f43b2012-06-21 09:45:11 +05302674 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002675}
2676
Tomi Valkeinen65904152015-11-04 17:10:57 +02002677static void dispc_set_loadmode(enum omap_dss_load_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002678{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002679 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002680}
2681
2682
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002683static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002684{
Sumit Semwal8613b002010-12-02 11:27:09 +00002685 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002686}
2687
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002688static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002689 enum omap_dss_trans_key_type type,
2690 u32 trans_key)
2691{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302692 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002693
Sumit Semwal8613b002010-12-02 11:27:09 +00002694 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002695}
2696
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002697static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002698{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302699 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002700}
Archit Taneja11354dd2011-09-26 11:47:29 +05302701
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002702static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2703 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002704{
Archit Taneja11354dd2011-09-26 11:47:29 +05302705 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002706 return;
2707
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002708 if (ch == OMAP_DSS_CHANNEL_LCD)
2709 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002710 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002711 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002712}
Archit Taneja11354dd2011-09-26 11:47:29 +05302713
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002714static void dispc_mgr_setup(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02002715 const struct omap_overlay_manager_info *info)
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002716{
2717 dispc_mgr_set_default_color(channel, info->default_color);
2718 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2719 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2720 dispc_mgr_enable_alpha_fixed_zorder(channel,
2721 info->partial_alpha_enabled);
2722 if (dss_has_feature(FEAT_CPR)) {
2723 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2724 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2725 }
2726}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002727
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002728static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002729{
2730 int code;
2731
2732 switch (data_lines) {
2733 case 12:
2734 code = 0;
2735 break;
2736 case 16:
2737 code = 1;
2738 break;
2739 case 18:
2740 code = 2;
2741 break;
2742 case 24:
2743 code = 3;
2744 break;
2745 default:
2746 BUG();
2747 return;
2748 }
2749
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302750 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002751}
2752
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002753static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002754{
2755 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302756 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002757
2758 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302759 case DSS_IO_PAD_MODE_RESET:
2760 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002761 gpout1 = 0;
2762 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302763 case DSS_IO_PAD_MODE_RFBI:
2764 gpout0 = 1;
2765 gpout1 = 0;
2766 break;
2767 case DSS_IO_PAD_MODE_BYPASS:
2768 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002769 gpout1 = 1;
2770 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002771 default:
2772 BUG();
2773 return;
2774 }
2775
Archit Taneja569969d2011-08-22 17:41:57 +05302776 l = dispc_read_reg(DISPC_CONTROL);
2777 l = FLD_MOD(l, gpout0, 15, 15);
2778 l = FLD_MOD(l, gpout1, 16, 16);
2779 dispc_write_reg(DISPC_CONTROL, l);
2780}
2781
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002782static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
Archit Taneja569969d2011-08-22 17:41:57 +05302783{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302784 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002785}
2786
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002787static void dispc_mgr_set_lcd_config(enum omap_channel channel,
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002788 const struct dss_lcd_mgr_config *config)
2789{
2790 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
2791
2792 dispc_mgr_enable_stallmode(channel, config->stallmode);
2793 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
2794
2795 dispc_mgr_set_clock_div(channel, &config->clock_info);
2796
2797 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
2798
2799 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
2800
2801 dispc_mgr_set_lcd_type_tft(channel);
2802}
2803
Archit Taneja8f366162012-04-16 12:53:44 +05302804static bool _dispc_mgr_size_ok(u16 width, u16 height)
2805{
Archit Taneja33b89922012-11-14 13:50:15 +05302806 return width <= dispc.feat->mgr_width_max &&
2807 height <= dispc.feat->mgr_height_max;
Archit Taneja8f366162012-04-16 12:53:44 +05302808}
2809
Peter Ujfalusi4dc22502016-09-22 14:06:48 +03002810static bool _dispc_lcd_timings_ok(int hsync_len, int hfp, int hbp,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002811 int vsw, int vfp, int vbp)
2812{
Peter Ujfalusi4dc22502016-09-22 14:06:48 +03002813 if (hsync_len < 1 || hsync_len > dispc.feat->sw_max ||
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302814 hfp < 1 || hfp > dispc.feat->hp_max ||
2815 hbp < 1 || hbp > dispc.feat->hp_max ||
2816 vsw < 1 || vsw > dispc.feat->sw_max ||
2817 vfp < 0 || vfp > dispc.feat->vp_max ||
2818 vbp < 0 || vbp > dispc.feat->vp_max)
2819 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002820 return true;
2821}
2822
Archit Tanejaca5ca692013-03-26 19:15:22 +05302823static bool _dispc_mgr_pclk_ok(enum omap_channel channel,
2824 unsigned long pclk)
2825{
2826 if (dss_mgr_is_lcd(channel))
Andrew F. Davis0cac5b62016-07-01 09:27:21 -05002827 return pclk <= dispc.feat->max_lcd_pclk;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302828 else
Andrew F. Davis0cac5b62016-07-01 09:27:21 -05002829 return pclk <= dispc.feat->max_tv_pclk;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302830}
2831
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002832bool dispc_mgr_timings_ok(enum omap_channel channel, const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002833{
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002834 if (!_dispc_mgr_size_ok(vm->hactive, vm->vactive))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002835 return false;
Archit Taneja8f366162012-04-16 12:53:44 +05302836
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002837 if (!_dispc_mgr_pclk_ok(channel, vm->pixelclock))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002838 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302839
2840 if (dss_mgr_is_lcd(channel)) {
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03002841 /* TODO: OMAP4+ supports interlace for LCD outputs */
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002842 if (vm->flags & DISPLAY_FLAGS_INTERLACED)
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002843 return false;
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03002844
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002845 if (!_dispc_lcd_timings_ok(vm->hsync_len,
2846 vm->hfront_porch, vm->hback_porch,
2847 vm->vsync_len, vm->vfront_porch,
2848 vm->vback_porch))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002849 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302850 }
Archit Taneja8f366162012-04-16 12:53:44 +05302851
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002852 return true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002853}
2854
Peter Ujfalusi3b592932016-09-22 14:06:56 +03002855static void _dispc_mgr_set_lcd_timings(enum omap_channel channel,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002856 const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002857{
Archit Taneja655e2942012-06-21 10:37:43 +05302858 u32 timing_h, timing_v, l;
Tomi Valkeinened351882014-10-02 17:58:49 +00002859 bool onoff, rf, ipc, vs, hs, de;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002860
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002861 timing_h = FLD_VAL(vm->hsync_len - 1, dispc.feat->sw_start, 0) |
2862 FLD_VAL(vm->hfront_porch - 1, dispc.feat->fp_start, 8) |
2863 FLD_VAL(vm->hback_porch - 1, dispc.feat->bp_start, 20);
2864 timing_v = FLD_VAL(vm->vsync_len - 1, dispc.feat->sw_start, 0) |
2865 FLD_VAL(vm->vfront_porch, dispc.feat->fp_start, 8) |
2866 FLD_VAL(vm->vback_porch, dispc.feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002867
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002868 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2869 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05302870
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002871 if (vm->flags & DISPLAY_FLAGS_VSYNC_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00002872 vs = false;
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03002873 else
2874 vs = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00002875
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002876 if (vm->flags & DISPLAY_FLAGS_HSYNC_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00002877 hs = false;
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03002878 else
2879 hs = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00002880
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002881 if (vm->flags & DISPLAY_FLAGS_DE_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00002882 de = false;
Peter Ujfalusi3fa3ab42016-09-22 14:06:58 +03002883 else
2884 de = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00002885
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002886 if (vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
Archit Taneja655e2942012-06-21 10:37:43 +05302887 ipc = false;
Peter Ujfalusif149e172016-09-22 14:07:00 +03002888 else
Archit Taneja655e2942012-06-21 10:37:43 +05302889 ipc = true;
Archit Taneja655e2942012-06-21 10:37:43 +05302890
Tomi Valkeinen7a163602014-10-02 17:58:48 +00002891 /* always use the 'rf' setting */
2892 onoff = true;
2893
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002894 if (vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE)
Archit Taneja655e2942012-06-21 10:37:43 +05302895 rf = true;
Peter Ujfalusid34afb72016-09-22 14:07:01 +03002896 else
2897 rf = false;
Archit Taneja655e2942012-06-21 10:37:43 +05302898
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03002899 l = FLD_VAL(onoff, 17, 17) |
2900 FLD_VAL(rf, 16, 16) |
Tomi Valkeinened351882014-10-02 17:58:49 +00002901 FLD_VAL(de, 15, 15) |
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03002902 FLD_VAL(ipc, 14, 14) |
Tomi Valkeinened351882014-10-02 17:58:49 +00002903 FLD_VAL(hs, 13, 13) |
2904 FLD_VAL(vs, 12, 12);
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03002905
Tomi Valkeinene5f80912015-10-21 13:08:59 +03002906 /* always set ALIGN bit when available */
2907 if (dispc.feat->supports_sync_align)
2908 l |= (1 << 18);
2909
Archit Taneja655e2942012-06-21 10:37:43 +05302910 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00002911
2912 if (dispc.syscon_pol) {
2913 const int shifts[] = {
2914 [OMAP_DSS_CHANNEL_LCD] = 0,
2915 [OMAP_DSS_CHANNEL_LCD2] = 1,
2916 [OMAP_DSS_CHANNEL_LCD3] = 2,
2917 };
2918
2919 u32 mask, val;
2920
2921 mask = (1 << 0) | (1 << 3) | (1 << 6);
2922 val = (rf << 0) | (ipc << 3) | (onoff << 6);
2923
2924 mask <<= 16 + shifts[channel];
2925 val <<= 16 + shifts[channel];
2926
2927 regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset,
2928 mask, val);
2929 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002930}
2931
Tomi Valkeinen956d4f92016-11-23 13:23:42 +02002932static int vm_flag_to_int(enum display_flags flags, enum display_flags high,
2933 enum display_flags low)
2934{
2935 if (flags & high)
2936 return 1;
2937 if (flags & low)
2938 return -1;
2939 return 0;
2940}
2941
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002942/* change name to mode? */
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002943static void dispc_mgr_set_timings(enum omap_channel channel,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002944 const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002945{
2946 unsigned xtot, ytot;
2947 unsigned long ht, vt;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002948 struct videomode t = *vm;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002949
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03002950 DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive);
Archit Tanejac51d9212012-04-16 12:53:43 +05302951
Archit Taneja2aefad42012-05-18 14:36:54 +05302952 if (!dispc_mgr_timings_ok(channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05302953 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002954 return;
2955 }
Archit Tanejac51d9212012-04-16 12:53:43 +05302956
Archit Tanejadd88b7a2012-06-29 14:41:30 +05302957 if (dss_mgr_is_lcd(channel)) {
Peter Ujfalusi3b592932016-09-22 14:06:56 +03002958 _dispc_mgr_set_lcd_timings(channel, &t);
Archit Tanejac51d9212012-04-16 12:53:43 +05302959
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03002960 xtot = t.hactive + t.hfront_porch + t.hsync_len + t.hback_porch;
Peter Ujfalusi458540c2016-09-22 14:06:53 +03002961 ytot = t.vactive + t.vfront_porch + t.vsync_len + t.vback_porch;
Archit Tanejac51d9212012-04-16 12:53:43 +05302962
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002963 ht = vm->pixelclock / xtot;
2964 vt = vm->pixelclock / xtot / ytot;
Archit Tanejac51d9212012-04-16 12:53:43 +05302965
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002966 DSSDBG("pck %lu\n", vm->pixelclock);
Peter Ujfalusi4dc22502016-09-22 14:06:48 +03002967 DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03002968 t.hsync_len, t.hfront_porch, t.hback_porch,
Peter Ujfalusi458540c2016-09-22 14:06:53 +03002969 t.vsync_len, t.vfront_porch, t.vback_porch);
Archit Taneja655e2942012-06-21 10:37:43 +05302970 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
Tomi Valkeinen956d4f92016-11-23 13:23:42 +02002971 vm_flag_to_int(t.flags, DISPLAY_FLAGS_VSYNC_HIGH, DISPLAY_FLAGS_VSYNC_LOW),
2972 vm_flag_to_int(t.flags, DISPLAY_FLAGS_HSYNC_HIGH, DISPLAY_FLAGS_HSYNC_LOW),
2973 vm_flag_to_int(t.flags, DISPLAY_FLAGS_PIXDATA_POSEDGE, DISPLAY_FLAGS_PIXDATA_NEGEDGE),
2974 vm_flag_to_int(t.flags, DISPLAY_FLAGS_DE_HIGH, DISPLAY_FLAGS_DE_LOW),
2975 vm_flag_to_int(t.flags, DISPLAY_FLAGS_SYNC_POSEDGE, DISPLAY_FLAGS_SYNC_NEGEDGE));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002976
Archit Tanejac51d9212012-04-16 12:53:43 +05302977 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05302978 } else {
Peter Ujfalusi53058292016-09-22 14:06:55 +03002979 if (t.flags & DISPLAY_FLAGS_INTERLACED)
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03002980 t.vactive /= 2;
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02002981
2982 if (dispc.feat->supports_double_pixel)
Peter Ujfalusi531efb32016-09-22 14:06:59 +03002983 REG_FLD_MOD(DISPC_CONTROL,
2984 !!(t.flags & DISPLAY_FLAGS_DOUBLECLK),
2985 19, 17);
Archit Tanejac51d9212012-04-16 12:53:43 +05302986 }
Archit Taneja8f366162012-04-16 12:53:44 +05302987
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03002988 dispc_mgr_set_size(channel, t.hactive, t.vactive);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002989}
2990
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03002991static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002992 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002993{
2994 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03002995 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002996
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06002997 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002998 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02002999
Luis de Bethencourt0bcfdba2015-10-15 13:29:38 +01003000 if (!dss_has_feature(FEAT_CORE_CLK_DIV) &&
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003001 channel == OMAP_DSS_CHANNEL_LCD)
3002 dispc.core_clk_rate = dispc_fclk_rate() / lck_div;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003003}
3004
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003005static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00003006 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003007{
3008 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003009 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003010 *lck_div = FLD_GET(l, 23, 16);
3011 *pck_div = FLD_GET(l, 7, 0);
3012}
3013
Tomi Valkeinen65904152015-11-04 17:10:57 +02003014static unsigned long dispc_fclk_rate(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003015{
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003016 unsigned long r;
3017 enum dss_clk_source src;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003018
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003019 src = dss_get_dispc_clk_source();
3020
3021 if (src == DSS_CLK_SRC_FCK) {
Tomi Valkeinen5aaee692012-12-12 10:37:03 +02003022 r = dss_get_dispc_clk_rate();
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003023 } else {
3024 struct dss_pll *pll;
3025 unsigned clkout_idx;
Tomi Valkeinen93550922014-12-31 11:25:48 +02003026
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003027 pll = dss_pll_find_by_src(src);
3028 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
Tomi Valkeinen93550922014-12-31 11:25:48 +02003029
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003030 r = pll->cinfo.clkout[clkout_idx];
Taneja, Archit66534e82011-03-08 05:50:34 -06003031 }
3032
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003033 return r;
3034}
3035
Tomi Valkeinen65904152015-11-04 17:10:57 +02003036static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003037{
3038 int lcd;
3039 unsigned long r;
Tomi Valkeinen01575772016-05-17 16:08:34 +03003040 enum dss_clk_source src;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003041
Tomi Valkeinen01575772016-05-17 16:08:34 +03003042 /* for TV, LCLK rate is the FCLK rate */
3043 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003044 return dispc_fclk_rate();
Tomi Valkeinen01575772016-05-17 16:08:34 +03003045
3046 src = dss_get_lcd_clk_source(channel);
3047
3048 if (src == DSS_CLK_SRC_FCK) {
3049 r = dss_get_dispc_clk_rate();
3050 } else {
3051 struct dss_pll *pll;
3052 unsigned clkout_idx;
3053
3054 pll = dss_pll_find_by_src(src);
3055 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
3056
3057 r = pll->cinfo.clkout[clkout_idx];
Taneja, Architea751592011-03-08 05:50:35 -06003058 }
Tomi Valkeinen01575772016-05-17 16:08:34 +03003059
3060 lcd = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3061
3062 return r / lcd;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003063}
3064
Tomi Valkeinen65904152015-11-04 17:10:57 +02003065static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003066{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003067 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003068
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303069 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303070 int pcd;
3071 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003072
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303073 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003074
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303075 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003076
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303077 r = dispc_mgr_lclk_rate(channel);
3078
3079 return r / pcd;
3080 } else {
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003081 return dispc.tv_pclk_rate;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303082 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003083}
3084
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003085void dispc_set_tv_pclk(unsigned long pclk)
3086{
3087 dispc.tv_pclk_rate = pclk;
3088}
3089
Tomi Valkeinen65904152015-11-04 17:10:57 +02003090static unsigned long dispc_core_clk_rate(void)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303091{
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003092 return dispc.core_clk_rate;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303093}
3094
Jyri Sarha864050c2017-03-24 16:47:52 +02003095static unsigned long dispc_plane_pclk_rate(enum omap_plane_id plane)
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303096{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003097 enum omap_channel channel;
3098
3099 if (plane == OMAP_DSS_WB)
3100 return 0;
3101
3102 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303103
3104 return dispc_mgr_pclk_rate(channel);
3105}
3106
Jyri Sarha864050c2017-03-24 16:47:52 +02003107static unsigned long dispc_plane_lclk_rate(enum omap_plane_id plane)
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303108{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003109 enum omap_channel channel;
3110
3111 if (plane == OMAP_DSS_WB)
3112 return 0;
3113
3114 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303115
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003116 return dispc_mgr_lclk_rate(channel);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303117}
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003118
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303119static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003120{
3121 int lcd, pcd;
Tomi Valkeinendc0352d2016-05-17 13:45:09 +03003122 enum dss_clk_source lcd_clk_src;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303123
3124 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3125
3126 lcd_clk_src = dss_get_lcd_clk_source(channel);
3127
Tomi Valkeinen557a1542016-05-17 13:49:18 +03003128 seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name,
Tomi Valkeinen407bd562016-05-17 13:50:55 +03003129 dss_get_clk_source_name(lcd_clk_src));
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303130
3131 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3132
3133 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3134 dispc_mgr_lclk_rate(channel), lcd);
3135 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3136 dispc_mgr_pclk_rate(channel), pcd);
3137}
3138
3139void dispc_dump_clocks(struct seq_file *s)
3140{
3141 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003142 u32 l;
Tomi Valkeinendc0352d2016-05-17 13:45:09 +03003143 enum dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003144
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003145 if (dispc_runtime_get())
3146 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003147
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003148 seq_printf(s, "- DISPC -\n");
3149
Tomi Valkeinen557a1542016-05-17 13:49:18 +03003150 seq_printf(s, "dispc fclk source = %s\n",
Tomi Valkeinen407bd562016-05-17 13:50:55 +03003151 dss_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003152
3153 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00003154
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003155 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3156 seq_printf(s, "- DISPC-CORE-CLK -\n");
3157 l = dispc_read_reg(DISPC_DIVISOR);
3158 lcd = FLD_GET(l, 23, 16);
3159
3160 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3161 (dispc_fclk_rate()/lcd), lcd);
3162 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003163
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303164 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003165
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303166 if (dss_has_feature(FEAT_MGR_LCD2))
3167 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3168 if (dss_has_feature(FEAT_MGR_LCD3))
3169 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003170
3171 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003172}
3173
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003174static void dispc_dump_regs(struct seq_file *s)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003175{
Archit Taneja4dd2da12011-08-05 19:06:01 +05303176 int i, j;
3177 const char *mgr_names[] = {
3178 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3179 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3180 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303181 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303182 };
3183 const char *ovl_names[] = {
3184 [OMAP_DSS_GFX] = "GFX",
3185 [OMAP_DSS_VIDEO1] = "VID1",
3186 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303187 [OMAP_DSS_VIDEO3] = "VID3",
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003188 [OMAP_DSS_WB] = "WB",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303189 };
3190 const char **p_names;
3191
Archit Taneja9b372c22011-05-06 11:45:49 +05303192#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003193
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003194 if (dispc_runtime_get())
3195 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003196
Archit Taneja5010be82011-08-05 19:06:00 +05303197 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003198 DUMPREG(DISPC_REVISION);
3199 DUMPREG(DISPC_SYSCONFIG);
3200 DUMPREG(DISPC_SYSSTATUS);
3201 DUMPREG(DISPC_IRQSTATUS);
3202 DUMPREG(DISPC_IRQENABLE);
3203 DUMPREG(DISPC_CONTROL);
3204 DUMPREG(DISPC_CONFIG);
3205 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003206 DUMPREG(DISPC_LINE_STATUS);
3207 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05303208 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3209 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003210 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003211 if (dss_has_feature(FEAT_MGR_LCD2)) {
3212 DUMPREG(DISPC_CONTROL2);
3213 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003214 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303215 if (dss_has_feature(FEAT_MGR_LCD3)) {
3216 DUMPREG(DISPC_CONTROL3);
3217 DUMPREG(DISPC_CONFIG3);
3218 }
Tomi Valkeinen29fceee2013-11-14 11:38:25 +02003219 if (dss_has_feature(FEAT_MFLAG))
3220 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003221
Archit Taneja5010be82011-08-05 19:06:00 +05303222#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003223
Archit Taneja5010be82011-08-05 19:06:00 +05303224#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05303225#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003226 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303227 dispc_read_reg(DISPC_REG(i, r)))
3228
Archit Taneja4dd2da12011-08-05 19:06:01 +05303229 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303230
Archit Taneja4dd2da12011-08-05 19:06:01 +05303231 /* DISPC channel specific registers */
3232 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3233 DUMPREG(i, DISPC_DEFAULT_COLOR);
3234 DUMPREG(i, DISPC_TRANS_COLOR);
3235 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003236
Archit Taneja4dd2da12011-08-05 19:06:01 +05303237 if (i == OMAP_DSS_CHANNEL_DIGIT)
3238 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303239
Archit Taneja4dd2da12011-08-05 19:06:01 +05303240 DUMPREG(i, DISPC_TIMING_H);
3241 DUMPREG(i, DISPC_TIMING_V);
3242 DUMPREG(i, DISPC_POL_FREQ);
3243 DUMPREG(i, DISPC_DIVISORo);
Archit Taneja5010be82011-08-05 19:06:00 +05303244
Archit Taneja4dd2da12011-08-05 19:06:01 +05303245 DUMPREG(i, DISPC_DATA_CYCLE1);
3246 DUMPREG(i, DISPC_DATA_CYCLE2);
3247 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003248
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003249 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303250 DUMPREG(i, DISPC_CPR_COEF_R);
3251 DUMPREG(i, DISPC_CPR_COEF_G);
3252 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003253 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003254 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003255
Archit Taneja4dd2da12011-08-05 19:06:01 +05303256 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003257
Archit Taneja4dd2da12011-08-05 19:06:01 +05303258 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3259 DUMPREG(i, DISPC_OVL_BA0);
3260 DUMPREG(i, DISPC_OVL_BA1);
3261 DUMPREG(i, DISPC_OVL_POSITION);
3262 DUMPREG(i, DISPC_OVL_SIZE);
3263 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3264 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3265 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3266 DUMPREG(i, DISPC_OVL_ROW_INC);
3267 DUMPREG(i, DISPC_OVL_PIXEL_INC);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003268
Archit Taneja4dd2da12011-08-05 19:06:01 +05303269 if (dss_has_feature(FEAT_PRELOAD))
3270 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003271 if (dss_has_feature(FEAT_MFLAG))
3272 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003273
Archit Taneja4dd2da12011-08-05 19:06:01 +05303274 if (i == OMAP_DSS_GFX) {
3275 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3276 DUMPREG(i, DISPC_OVL_TABLE_BA);
3277 continue;
3278 }
3279
3280 DUMPREG(i, DISPC_OVL_FIR);
3281 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3282 DUMPREG(i, DISPC_OVL_ACCU0);
3283 DUMPREG(i, DISPC_OVL_ACCU1);
3284 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3285 DUMPREG(i, DISPC_OVL_BA0_UV);
3286 DUMPREG(i, DISPC_OVL_BA1_UV);
3287 DUMPREG(i, DISPC_OVL_FIR2);
3288 DUMPREG(i, DISPC_OVL_ACCU2_0);
3289 DUMPREG(i, DISPC_OVL_ACCU2_1);
3290 }
3291 if (dss_has_feature(FEAT_ATTR2))
3292 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
Archit Taneja5010be82011-08-05 19:06:00 +05303293 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003294
Tomi Valkeinen20efbc32015-11-04 17:10:44 +02003295 if (dispc.feat->has_writeback) {
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003296 i = OMAP_DSS_WB;
3297 DUMPREG(i, DISPC_OVL_BA0);
3298 DUMPREG(i, DISPC_OVL_BA1);
3299 DUMPREG(i, DISPC_OVL_SIZE);
3300 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3301 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3302 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3303 DUMPREG(i, DISPC_OVL_ROW_INC);
3304 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3305
3306 if (dss_has_feature(FEAT_MFLAG))
3307 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
3308
3309 DUMPREG(i, DISPC_OVL_FIR);
3310 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3311 DUMPREG(i, DISPC_OVL_ACCU0);
3312 DUMPREG(i, DISPC_OVL_ACCU1);
3313 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3314 DUMPREG(i, DISPC_OVL_BA0_UV);
3315 DUMPREG(i, DISPC_OVL_BA1_UV);
3316 DUMPREG(i, DISPC_OVL_FIR2);
3317 DUMPREG(i, DISPC_OVL_ACCU2_0);
3318 DUMPREG(i, DISPC_OVL_ACCU2_1);
3319 }
3320 if (dss_has_feature(FEAT_ATTR2))
3321 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3322 }
3323
Archit Taneja5010be82011-08-05 19:06:00 +05303324#undef DISPC_REG
3325#undef DUMPREG
3326
3327#define DISPC_REG(plane, name, i) name(plane, i)
3328#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303329 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003330 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303331 dispc_read_reg(DISPC_REG(plane, name, i)))
3332
Archit Taneja4dd2da12011-08-05 19:06:01 +05303333 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303334
Archit Taneja4dd2da12011-08-05 19:06:01 +05303335 /* start from OMAP_DSS_VIDEO1 */
3336 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3337 for (j = 0; j < 8; j++)
3338 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303339
Archit Taneja4dd2da12011-08-05 19:06:01 +05303340 for (j = 0; j < 8; j++)
3341 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303342
Archit Taneja4dd2da12011-08-05 19:06:01 +05303343 for (j = 0; j < 5; j++)
3344 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003345
Archit Taneja4dd2da12011-08-05 19:06:01 +05303346 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3347 for (j = 0; j < 8; j++)
3348 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3349 }
Amber Jainab5ca072011-05-19 19:47:53 +05303350
Archit Taneja4dd2da12011-08-05 19:06:01 +05303351 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3352 for (j = 0; j < 8; j++)
3353 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303354
Archit Taneja4dd2da12011-08-05 19:06:01 +05303355 for (j = 0; j < 8; j++)
3356 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303357
Archit Taneja4dd2da12011-08-05 19:06:01 +05303358 for (j = 0; j < 8; j++)
3359 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3360 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003361 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003362
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003363 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05303364
3365#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003366#undef DUMPREG
3367}
3368
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003369/* calculate clock rates using dividers in cinfo */
3370int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3371 struct dispc_clock_info *cinfo)
3372{
3373 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3374 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003375 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003376 return -EINVAL;
3377
3378 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3379 cinfo->pck = cinfo->lck / cinfo->pck_div;
3380
3381 return 0;
3382}
3383
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003384bool dispc_div_calc(unsigned long dispc,
3385 unsigned long pck_min, unsigned long pck_max,
3386 dispc_div_calc_func func, void *data)
3387{
3388 int lckd, lckd_start, lckd_stop;
3389 int pckd, pckd_start, pckd_stop;
3390 unsigned long pck, lck;
3391 unsigned long lck_max;
3392 unsigned long pckd_hw_min, pckd_hw_max;
3393 unsigned min_fck_per_pck;
3394 unsigned long fck;
3395
3396#ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3397 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3398#else
3399 min_fck_per_pck = 0;
3400#endif
3401
3402 pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3403 pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3404
3405 lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
3406
3407 pck_min = pck_min ? pck_min : 1;
3408 pck_max = pck_max ? pck_max : ULONG_MAX;
3409
3410 lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul);
3411 lckd_stop = min(dispc / pck_min, 255ul);
3412
3413 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3414 lck = dispc / lckd;
3415
3416 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3417 pckd_stop = min(lck / pck_min, pckd_hw_max);
3418
3419 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3420 pck = lck / pckd;
3421
3422 /*
3423 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3424 * clock, which means we're configuring DISPC fclk here
3425 * also. Thus we need to use the calculated lck. For
3426 * OMAP4+ the DISPC fclk is a separate clock.
3427 */
3428 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3429 fck = dispc_core_clk_rate();
3430 else
3431 fck = lck;
3432
3433 if (fck < pck * min_fck_per_pck)
3434 continue;
3435
3436 if (func(lckd, pckd, lck, pck, data))
3437 return true;
3438 }
3439 }
3440
3441 return false;
3442}
3443
Archit Tanejaf0d08f82012-06-29 14:00:54 +05303444void dispc_mgr_set_clock_div(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003445 const struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003446{
3447 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3448 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3449
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003450 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003451}
3452
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003453int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003454 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003455{
3456 unsigned long fck;
3457
3458 fck = dispc_fclk_rate();
3459
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003460 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3461 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003462
3463 cinfo->lck = fck / cinfo->lck_div;
3464 cinfo->pck = cinfo->lck / cinfo->pck_div;
3465
3466 return 0;
3467}
3468
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003469static u32 dispc_read_irqstatus(void)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003470{
3471 return dispc_read_reg(DISPC_IRQSTATUS);
3472}
3473
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003474static void dispc_clear_irqstatus(u32 mask)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003475{
3476 dispc_write_reg(DISPC_IRQSTATUS, mask);
3477}
3478
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003479static void dispc_write_irqenable(u32 mask)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003480{
3481 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3482
3483 /* clear the irqstatus for newly enabled irqs */
3484 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3485
3486 dispc_write_reg(DISPC_IRQENABLE, mask);
Tomi Valkeinen2e953d82017-02-20 13:18:38 +02003487
3488 /* flush posted write */
3489 dispc_read_reg(DISPC_IRQENABLE);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003490}
3491
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003492void dispc_enable_sidle(void)
3493{
3494 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3495}
3496
3497void dispc_disable_sidle(void)
3498{
3499 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3500}
3501
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003502static u32 dispc_mgr_gamma_size(enum omap_channel channel)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003503{
3504 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3505
3506 if (!dispc.feat->has_gamma_table)
3507 return 0;
3508
3509 return gdesc->len;
3510}
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003511
3512static void dispc_mgr_write_gamma_table(enum omap_channel channel)
3513{
3514 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3515 u32 *table = dispc.gamma_table[channel];
3516 unsigned int i;
3517
3518 DSSDBG("%s: channel %d\n", __func__, channel);
3519
3520 for (i = 0; i < gdesc->len; ++i) {
3521 u32 v = table[i];
3522
3523 if (gdesc->has_index)
3524 v |= i << 24;
3525 else if (i == 0)
3526 v |= 1 << 31;
3527
3528 dispc_write_reg(gdesc->reg, v);
3529 }
3530}
3531
3532static void dispc_restore_gamma_tables(void)
3533{
3534 DSSDBG("%s()\n", __func__);
3535
3536 if (!dispc.feat->has_gamma_table)
3537 return;
3538
3539 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD);
3540
3541 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_DIGIT);
3542
3543 if (dss_has_feature(FEAT_MGR_LCD2))
3544 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD2);
3545
3546 if (dss_has_feature(FEAT_MGR_LCD3))
3547 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD3);
3548}
3549
3550static const struct drm_color_lut dispc_mgr_gamma_default_lut[] = {
3551 { .red = 0, .green = 0, .blue = 0, },
3552 { .red = U16_MAX, .green = U16_MAX, .blue = U16_MAX, },
3553};
3554
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003555static void dispc_mgr_set_gamma(enum omap_channel channel,
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003556 const struct drm_color_lut *lut,
3557 unsigned int length)
3558{
3559 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3560 u32 *table = dispc.gamma_table[channel];
3561 uint i;
3562
3563 DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__,
3564 channel, length, gdesc->len);
3565
3566 if (!dispc.feat->has_gamma_table)
3567 return;
3568
3569 if (lut == NULL || length < 2) {
3570 lut = dispc_mgr_gamma_default_lut;
3571 length = ARRAY_SIZE(dispc_mgr_gamma_default_lut);
3572 }
3573
3574 for (i = 0; i < length - 1; ++i) {
3575 uint first = i * (gdesc->len - 1) / (length - 1);
3576 uint last = (i + 1) * (gdesc->len - 1) / (length - 1);
3577 uint w = last - first;
3578 u16 r, g, b;
3579 uint j;
3580
3581 if (w == 0)
3582 continue;
3583
3584 for (j = 0; j <= w; j++) {
3585 r = (lut[i].red * (w - j) + lut[i+1].red * j) / w;
3586 g = (lut[i].green * (w - j) + lut[i+1].green * j) / w;
3587 b = (lut[i].blue * (w - j) + lut[i+1].blue * j) / w;
3588
3589 r >>= 16 - gdesc->bits;
3590 g >>= 16 - gdesc->bits;
3591 b >>= 16 - gdesc->bits;
3592
3593 table[first + j] = (r << (gdesc->bits * 2)) |
3594 (g << gdesc->bits) | b;
3595 }
3596 }
3597
3598 if (dispc.is_enabled)
3599 dispc_mgr_write_gamma_table(channel);
3600}
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003601
3602static int dispc_init_gamma_tables(void)
3603{
3604 int channel;
3605
3606 if (!dispc.feat->has_gamma_table)
3607 return 0;
3608
3609 for (channel = 0; channel < ARRAY_SIZE(dispc.gamma_table); channel++) {
3610 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3611 u32 *gt;
3612
3613 if (channel == OMAP_DSS_CHANNEL_LCD2 &&
3614 !dss_has_feature(FEAT_MGR_LCD2))
3615 continue;
3616
3617 if (channel == OMAP_DSS_CHANNEL_LCD3 &&
3618 !dss_has_feature(FEAT_MGR_LCD3))
3619 continue;
3620
3621 gt = devm_kmalloc_array(&dispc.pdev->dev, gdesc->len,
3622 sizeof(u32), GFP_KERNEL);
3623 if (!gt)
3624 return -ENOMEM;
3625
3626 dispc.gamma_table[channel] = gt;
3627
3628 dispc_mgr_set_gamma(channel, NULL, 0);
3629 }
3630 return 0;
3631}
3632
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003633static void _omap_dispc_initial_config(void)
3634{
3635 u32 l;
3636
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003637 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3638 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3639 l = dispc_read_reg(DISPC_DIVISOR);
3640 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3641 l = FLD_MOD(l, 1, 0, 0);
3642 l = FLD_MOD(l, 1, 23, 16);
3643 dispc_write_reg(DISPC_DIVISOR, l);
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003644
3645 dispc.core_clk_rate = dispc_fclk_rate();
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003646 }
3647
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003648 /* Use gamma table mode, instead of palette mode */
3649 if (dispc.feat->has_gamma_table)
3650 REG_FLD_MOD(DISPC_CONFIG, 1, 3, 3);
3651
3652 /* For older DSS versions (FEAT_FUNCGATED) this enables
3653 * func-clock auto-gating. For newer versions
3654 * (dispc.feat->has_gamma_table) this enables tv-out gamma tables.
3655 */
3656 if (dss_has_feature(FEAT_FUNCGATED) || dispc.feat->has_gamma_table)
Archit Taneja6ced40b2010-12-02 11:27:13 +00003657 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003658
Archit Taneja6e5264b2012-09-11 12:04:47 +05303659 dispc_setup_color_conv_coef();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003660
3661 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3662
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003663 dispc_init_fifos();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003664
3665 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05303666
3667 dispc_ovl_enable_zorder_planes();
Archit Tanejad0df9a22013-03-26 19:15:25 +05303668
3669 if (dispc.feat->mstandby_workaround)
3670 REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0);
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00003671
3672 if (dss_has_feature(FEAT_MFLAG))
3673 dispc_init_mflag();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003674}
3675
Tomi Valkeinenede92692015-06-04 14:12:16 +03003676static const struct dispc_features omap24xx_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303677 .sw_start = 5,
3678 .fp_start = 15,
3679 .bp_start = 27,
3680 .sw_max = 64,
3681 .vp_max = 255,
3682 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303683 .mgr_width_start = 10,
3684 .mgr_height_start = 26,
3685 .mgr_width_max = 2048,
3686 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303687 .max_lcd_pclk = 66500000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303688 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3689 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003690 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003691 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303692 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003693 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303694};
3695
Tomi Valkeinenede92692015-06-04 14:12:16 +03003696static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303697 .sw_start = 5,
3698 .fp_start = 15,
3699 .bp_start = 27,
3700 .sw_max = 64,
3701 .vp_max = 255,
3702 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303703 .mgr_width_start = 10,
3704 .mgr_height_start = 26,
3705 .mgr_width_max = 2048,
3706 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303707 .max_lcd_pclk = 173000000,
3708 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303709 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3710 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003711 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003712 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303713 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003714 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303715};
3716
Tomi Valkeinenede92692015-06-04 14:12:16 +03003717static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303718 .sw_start = 7,
3719 .fp_start = 19,
3720 .bp_start = 31,
3721 .sw_max = 256,
3722 .vp_max = 4095,
3723 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303724 .mgr_width_start = 10,
3725 .mgr_height_start = 26,
3726 .mgr_width_max = 2048,
3727 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303728 .max_lcd_pclk = 173000000,
3729 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303730 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3731 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003732 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003733 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303734 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003735 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303736};
3737
Tomi Valkeinenede92692015-06-04 14:12:16 +03003738static const struct dispc_features omap44xx_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303739 .sw_start = 7,
3740 .fp_start = 19,
3741 .bp_start = 31,
3742 .sw_max = 256,
3743 .vp_max = 4095,
3744 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303745 .mgr_width_start = 10,
3746 .mgr_height_start = 26,
3747 .mgr_width_max = 2048,
3748 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303749 .max_lcd_pclk = 170000000,
3750 .max_tv_pclk = 185625000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303751 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3752 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003753 .num_fifos = 5,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03003754 .gfx_fifo_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303755 .set_max_preload = true,
Tomi Valkeinene5f80912015-10-21 13:08:59 +03003756 .supports_sync_align = true,
Tomi Valkeinen20efbc32015-11-04 17:10:44 +02003757 .has_writeback = true,
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02003758 .supports_double_pixel = true,
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02003759 .reverse_ilace_field_order = true,
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003760 .has_gamma_table = true,
Jyri Sarhafbff0102016-06-07 15:09:16 +03003761 .has_gamma_i734_bug = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303762};
3763
Tomi Valkeinenede92692015-06-04 14:12:16 +03003764static const struct dispc_features omap54xx_dispc_feats = {
Archit Taneja264236f2012-11-14 13:50:16 +05303765 .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,
Tomi Valkeinene5f80912015-10-21 13:08:59 +03003783 .supports_sync_align = true,
Tomi Valkeinen20efbc32015-11-04 17:10:44 +02003784 .has_writeback = true,
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02003785 .supports_double_pixel = true,
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02003786 .reverse_ilace_field_order = true,
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003787 .has_gamma_table = true,
Jyri Sarhafbff0102016-06-07 15:09:16 +03003788 .has_gamma_i734_bug = true,
Archit Taneja264236f2012-11-14 13:50:16 +05303789};
3790
Tomi Valkeinenede92692015-06-04 14:12:16 +03003791static int dispc_init_features(struct platform_device *pdev)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303792{
3793 const struct dispc_features *src;
3794 struct dispc_features *dst;
3795
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003796 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303797 if (!dst) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003798 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303799 return -ENOMEM;
3800 }
3801
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +03003802 switch (omapdss_get_version()) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003803 case OMAPDSS_VER_OMAP24xx:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303804 src = &omap24xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003805 break;
3806
3807 case OMAPDSS_VER_OMAP34xx_ES1:
3808 src = &omap34xx_rev1_0_dispc_feats;
3809 break;
3810
3811 case OMAPDSS_VER_OMAP34xx_ES3:
3812 case OMAPDSS_VER_OMAP3630:
3813 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +05303814 case OMAPDSS_VER_AM43xx:
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003815 src = &omap34xx_rev3_0_dispc_feats;
3816 break;
3817
3818 case OMAPDSS_VER_OMAP4430_ES1:
3819 case OMAPDSS_VER_OMAP4430_ES2:
3820 case OMAPDSS_VER_OMAP4:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303821 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003822 break;
3823
3824 case OMAPDSS_VER_OMAP5:
Tomi Valkeinen93550922014-12-31 11:25:48 +02003825 case OMAPDSS_VER_DRA7xx:
Archit Taneja264236f2012-11-14 13:50:16 +05303826 src = &omap54xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003827 break;
3828
3829 default:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303830 return -ENODEV;
3831 }
3832
3833 memcpy(dst, src, sizeof(*dst));
3834 dispc.feat = dst;
3835
3836 return 0;
3837}
3838
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003839static irqreturn_t dispc_irq_handler(int irq, void *arg)
3840{
3841 if (!dispc.is_enabled)
3842 return IRQ_NONE;
3843
3844 return dispc.user_handler(irq, dispc.user_data);
3845}
3846
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003847static int dispc_request_irq(irq_handler_t handler, void *dev_id)
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003848{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003849 int r;
3850
3851 if (dispc.user_handler != NULL)
3852 return -EBUSY;
3853
3854 dispc.user_handler = handler;
3855 dispc.user_data = dev_id;
3856
3857 /* ensure the dispc_irq_handler sees the values above */
3858 smp_wmb();
3859
3860 r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler,
3861 IRQF_SHARED, "OMAP DISPC", &dispc);
3862 if (r) {
3863 dispc.user_handler = NULL;
3864 dispc.user_data = NULL;
3865 }
3866
3867 return r;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003868}
3869
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003870static void dispc_free_irq(void *dev_id)
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003871{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003872 devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc);
3873
3874 dispc.user_handler = NULL;
3875 dispc.user_data = NULL;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003876}
3877
Jyri Sarhafbff0102016-06-07 15:09:16 +03003878/*
3879 * Workaround for errata i734 in DSS dispc
3880 * - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled
3881 *
3882 * For gamma tables to work on LCD1 the GFX plane has to be used at
3883 * least once after DSS HW has come out of reset. The workaround
3884 * sets up a minimal LCD setup with GFX plane and waits for one
3885 * vertical sync irq before disabling the setup and continuing with
3886 * the context restore. The physical outputs are gated during the
3887 * operation. This workaround requires that gamma table's LOADMODE
3888 * is set to 0x2 in DISPC_CONTROL1 register.
3889 *
3890 * For details see:
3891 * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata
3892 * Literature Number: SWPZ037E
3893 * Or some other relevant errata document for the DSS IP version.
3894 */
3895
3896static const struct dispc_errata_i734_data {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003897 struct videomode vm;
Jyri Sarhafbff0102016-06-07 15:09:16 +03003898 struct omap_overlay_info ovli;
3899 struct omap_overlay_manager_info mgri;
3900 struct dss_lcd_mgr_config lcd_conf;
3901} i734 = {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003902 .vm = {
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03003903 .hactive = 8, .vactive = 1,
Jyri Sarhafbff0102016-06-07 15:09:16 +03003904 .pixelclock = 16000000,
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03003905 .hsync_len = 8, .hfront_porch = 4, .hback_porch = 4,
Peter Ujfalusi458540c2016-09-22 14:06:53 +03003906 .vsync_len = 1, .vfront_porch = 1, .vback_porch = 1,
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03003907
Peter Ujfalusi3fa3ab42016-09-22 14:06:58 +03003908 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
Peter Ujfalusid34afb72016-09-22 14:07:01 +03003909 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
3910 DISPLAY_FLAGS_PIXDATA_POSEDGE,
Jyri Sarhafbff0102016-06-07 15:09:16 +03003911 },
3912 .ovli = {
3913 .screen_width = 1,
3914 .width = 1, .height = 1,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03003915 .fourcc = DRM_FORMAT_XRGB8888,
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03003916 .rotation = DRM_MODE_ROTATE_0,
Tomi Valkeinen517a8a952017-05-03 14:14:27 +03003917 .rotation_type = OMAP_DSS_ROT_NONE,
Jyri Sarhafbff0102016-06-07 15:09:16 +03003918 .pos_x = 0, .pos_y = 0,
3919 .out_width = 0, .out_height = 0,
3920 .global_alpha = 0xff,
3921 .pre_mult_alpha = 0,
3922 .zorder = 0,
3923 },
3924 .mgri = {
3925 .default_color = 0,
3926 .trans_enabled = false,
3927 .partial_alpha_enabled = false,
3928 .cpr_enable = false,
3929 },
3930 .lcd_conf = {
3931 .io_pad_mode = DSS_IO_PAD_MODE_BYPASS,
3932 .stallmode = false,
3933 .fifohandcheck = false,
3934 .clock_info = {
3935 .lck_div = 1,
3936 .pck_div = 2,
3937 },
3938 .video_port_width = 24,
3939 .lcden_sig_polarity = 0,
3940 },
3941};
3942
3943static struct i734_buf {
3944 size_t size;
3945 dma_addr_t paddr;
3946 void *vaddr;
3947} i734_buf;
3948
3949static int dispc_errata_i734_wa_init(void)
3950{
3951 if (!dispc.feat->has_gamma_i734_bug)
3952 return 0;
3953
3954 i734_buf.size = i734.ovli.width * i734.ovli.height *
Tomi Valkeinen41aff422017-05-04 11:31:56 +03003955 color_mode_to_bpp(i734.ovli.fourcc) / 8;
Jyri Sarhafbff0102016-06-07 15:09:16 +03003956
3957 i734_buf.vaddr = dma_alloc_writecombine(&dispc.pdev->dev, i734_buf.size,
3958 &i734_buf.paddr, GFP_KERNEL);
3959 if (!i734_buf.vaddr) {
3960 dev_err(&dispc.pdev->dev, "%s: dma_alloc_writecombine failed",
3961 __func__);
3962 return -ENOMEM;
3963 }
3964
3965 return 0;
3966}
3967
3968static void dispc_errata_i734_wa_fini(void)
3969{
3970 if (!dispc.feat->has_gamma_i734_bug)
3971 return;
3972
3973 dma_free_writecombine(&dispc.pdev->dev, i734_buf.size, i734_buf.vaddr,
3974 i734_buf.paddr);
3975}
3976
3977static void dispc_errata_i734_wa(void)
3978{
3979 u32 framedone_irq = dispc_mgr_get_framedone_irq(OMAP_DSS_CHANNEL_LCD);
3980 struct omap_overlay_info ovli;
3981 struct dss_lcd_mgr_config lcd_conf;
3982 u32 gatestate;
3983 unsigned int count;
3984
3985 if (!dispc.feat->has_gamma_i734_bug)
3986 return;
3987
3988 gatestate = REG_GET(DISPC_CONFIG, 8, 4);
3989
3990 ovli = i734.ovli;
3991 ovli.paddr = i734_buf.paddr;
3992 lcd_conf = i734.lcd_conf;
3993
3994 /* Gate all LCD1 outputs */
3995 REG_FLD_MOD(DISPC_CONFIG, 0x1f, 8, 4);
3996
3997 /* Setup and enable GFX plane */
Tomi Valkeinen49a30572017-02-17 12:30:07 +02003998 dispc_ovl_setup(OMAP_DSS_GFX, &ovli, &i734.vm, false,
3999 OMAP_DSS_CHANNEL_LCD);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004000 dispc_ovl_enable(OMAP_DSS_GFX, true);
4001
4002 /* Set up and enable display manager for LCD1 */
4003 dispc_mgr_setup(OMAP_DSS_CHANNEL_LCD, &i734.mgri);
4004 dispc_calc_clock_rates(dss_get_dispc_clk_rate(),
4005 &lcd_conf.clock_info);
4006 dispc_mgr_set_lcd_config(OMAP_DSS_CHANNEL_LCD, &lcd_conf);
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03004007 dispc_mgr_set_timings(OMAP_DSS_CHANNEL_LCD, &i734.vm);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004008
4009 dispc_clear_irqstatus(framedone_irq);
4010
4011 /* Enable and shut the channel to produce just one frame */
4012 dispc_mgr_enable(OMAP_DSS_CHANNEL_LCD, true);
4013 dispc_mgr_enable(OMAP_DSS_CHANNEL_LCD, false);
4014
4015 /* Busy wait for framedone. We can't fiddle with irq handlers
4016 * in PM resume. Typically the loop runs less than 5 times and
4017 * waits less than a micro second.
4018 */
4019 count = 0;
4020 while (!(dispc_read_irqstatus() & framedone_irq)) {
4021 if (count++ > 10000) {
4022 dev_err(&dispc.pdev->dev, "%s: framedone timeout\n",
4023 __func__);
4024 break;
4025 }
4026 }
4027 dispc_ovl_enable(OMAP_DSS_GFX, false);
4028
4029 /* Clear all irq bits before continuing */
4030 dispc_clear_irqstatus(0xffffffff);
4031
4032 /* Restore the original state to LCD1 output gates */
4033 REG_FLD_MOD(DISPC_CONFIG, gatestate, 8, 4);
4034}
4035
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004036static const struct dispc_ops dispc_ops = {
4037 .read_irqstatus = dispc_read_irqstatus,
4038 .clear_irqstatus = dispc_clear_irqstatus,
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004039 .write_irqenable = dispc_write_irqenable,
4040
4041 .request_irq = dispc_request_irq,
4042 .free_irq = dispc_free_irq,
4043
4044 .runtime_get = dispc_runtime_get,
4045 .runtime_put = dispc_runtime_put,
4046
4047 .get_num_ovls = dispc_get_num_ovls,
4048 .get_num_mgrs = dispc_get_num_mgrs,
4049
4050 .mgr_enable = dispc_mgr_enable,
4051 .mgr_is_enabled = dispc_mgr_is_enabled,
4052 .mgr_get_vsync_irq = dispc_mgr_get_vsync_irq,
4053 .mgr_get_framedone_irq = dispc_mgr_get_framedone_irq,
4054 .mgr_get_sync_lost_irq = dispc_mgr_get_sync_lost_irq,
4055 .mgr_go_busy = dispc_mgr_go_busy,
4056 .mgr_go = dispc_mgr_go,
4057 .mgr_set_lcd_config = dispc_mgr_set_lcd_config,
4058 .mgr_set_timings = dispc_mgr_set_timings,
4059 .mgr_setup = dispc_mgr_setup,
4060 .mgr_get_supported_outputs = dispc_mgr_get_supported_outputs,
4061 .mgr_gamma_size = dispc_mgr_gamma_size,
4062 .mgr_set_gamma = dispc_mgr_set_gamma,
4063
4064 .ovl_enable = dispc_ovl_enable,
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004065 .ovl_setup = dispc_ovl_setup,
4066 .ovl_get_color_modes = dispc_ovl_get_color_modes,
4067};
4068
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004069/* DISPC HW IP initialisation */
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004070static int dispc_bind(struct device *dev, struct device *master, void *data)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004071{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004072 struct platform_device *pdev = to_platform_device(dev);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004073 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00004074 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004075 struct resource *dispc_mem;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004076 struct device_node *np = pdev->dev.of_node;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004077
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004078 dispc.pdev = pdev;
4079
Tomi Valkeinend49cd152014-11-10 12:23:00 +02004080 spin_lock_init(&dispc.control_lock);
4081
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004082 r = dispc_init_features(dispc.pdev);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304083 if (r)
4084 return r;
4085
Jyri Sarhafbff0102016-06-07 15:09:16 +03004086 r = dispc_errata_i734_wa_init();
4087 if (r)
4088 return r;
4089
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004090 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
Laurent Pinchartb22622f2017-05-07 00:29:09 +03004091 dispc.base = devm_ioremap_resource(&pdev->dev, dispc_mem);
4092 if (IS_ERR(dispc.base))
4093 return PTR_ERR(dispc.base);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004094
archit tanejaaffe3602011-02-23 08:41:03 +00004095 dispc.irq = platform_get_irq(dispc.pdev, 0);
4096 if (dispc.irq < 0) {
4097 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004098 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00004099 }
4100
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004101 if (np && of_property_read_bool(np, "syscon-pol")) {
4102 dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
4103 if (IS_ERR(dispc.syscon_pol)) {
4104 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
4105 return PTR_ERR(dispc.syscon_pol);
4106 }
4107
4108 if (of_property_read_u32_index(np, "syscon-pol", 1,
4109 &dispc.syscon_pol_offset)) {
4110 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
4111 return -EINVAL;
4112 }
4113 }
4114
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004115 r = dispc_init_gamma_tables();
4116 if (r)
4117 return r;
4118
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004119 pm_runtime_enable(&pdev->dev);
4120
4121 r = dispc_runtime_get();
4122 if (r)
4123 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004124
4125 _omap_dispc_initial_config();
4126
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004127 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00004128 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004129 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4130
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004131 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004132
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004133 dispc_set_ops(&dispc_ops);
4134
Tomi Valkeinene40402c2012-03-02 18:01:07 +02004135 dss_debugfs_create_file("dispc", dispc_dump_regs);
4136
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004137 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004138
4139err_runtime_get:
4140 pm_runtime_disable(&pdev->dev);
archit tanejaaffe3602011-02-23 08:41:03 +00004141 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004142}
4143
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004144static void dispc_unbind(struct device *dev, struct device *master,
4145 void *data)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004146{
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004147 dispc_set_ops(NULL);
4148
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004149 pm_runtime_disable(dev);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004150
4151 dispc_errata_i734_wa_fini();
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004152}
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03004153
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004154static const struct component_ops dispc_component_ops = {
4155 .bind = dispc_bind,
4156 .unbind = dispc_unbind,
4157};
4158
4159static int dispc_probe(struct platform_device *pdev)
4160{
4161 return component_add(&pdev->dev, &dispc_component_ops);
4162}
4163
4164static int dispc_remove(struct platform_device *pdev)
4165{
4166 component_del(&pdev->dev, &dispc_component_ops);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004167 return 0;
4168}
4169
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004170static int dispc_runtime_suspend(struct device *dev)
4171{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004172 dispc.is_enabled = false;
4173 /* ensure the dispc_irq_handler sees the is_enabled value */
4174 smp_wmb();
4175 /* wait for current handler to finish before turning the DISPC off */
4176 synchronize_irq(dispc.irq);
4177
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004178 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004179
4180 return 0;
4181}
4182
4183static int dispc_runtime_resume(struct device *dev)
4184{
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004185 /*
4186 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4187 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4188 * _omap_dispc_initial_config(). We can thus use it to detect if
4189 * we have lost register context.
4190 */
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004191 if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
4192 _omap_dispc_initial_config();
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004193
Jyri Sarhafbff0102016-06-07 15:09:16 +03004194 dispc_errata_i734_wa();
4195
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004196 dispc_restore_context();
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004197
4198 dispc_restore_gamma_tables();
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004199 }
Tomi Valkeinenbe07dcd72013-11-21 16:01:40 +02004200
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004201 dispc.is_enabled = true;
4202 /* ensure the dispc_irq_handler sees the is_enabled value */
4203 smp_wmb();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004204
4205 return 0;
4206}
4207
4208static const struct dev_pm_ops dispc_pm_ops = {
4209 .runtime_suspend = dispc_runtime_suspend,
4210 .runtime_resume = dispc_runtime_resume,
4211};
4212
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004213static const struct of_device_id dispc_of_match[] = {
4214 { .compatible = "ti,omap2-dispc", },
4215 { .compatible = "ti,omap3-dispc", },
4216 { .compatible = "ti,omap4-dispc", },
Tomi Valkeinen2e7e6b62014-04-16 13:16:43 +03004217 { .compatible = "ti,omap5-dispc", },
Tomi Valkeinen93550922014-12-31 11:25:48 +02004218 { .compatible = "ti,dra7-dispc", },
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004219 {},
4220};
4221
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004222static struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004223 .probe = dispc_probe,
4224 .remove = dispc_remove,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004225 .driver = {
4226 .name = "omapdss_dispc",
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004227 .pm = &dispc_pm_ops,
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004228 .of_match_table = dispc_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +03004229 .suppress_bind_attrs = true,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004230 },
4231};
4232
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004233int __init dispc_init_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004234{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004235 return platform_driver_register(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004236}
4237
Tomi Valkeinenede92692015-06-04 14:12:16 +03004238void dispc_uninit_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004239{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02004240 platform_driver_unregister(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004241}