blob: 000a3d4a27bf8356aa302ac4b5c59281dc39026a [file] [log] [blame]
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001/*
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002 * Copyright (C) 2009 Nokia Corporation
3 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
4 *
5 * Some code and ideas taken from drivers/video/omap/ driver
6 * by Imre Deak.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#define DSS_SUBSYS_NAME "DISPC"
22
23#include <linux/kernel.h>
24#include <linux/dma-mapping.h>
25#include <linux/vmalloc.h>
Paul Gortmakera8a35932011-07-10 13:20:26 -040026#include <linux/export.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020027#include <linux/clk.h>
28#include <linux/io.h>
29#include <linux/jiffies.h>
30#include <linux/seq_file.h>
31#include <linux/delay.h>
32#include <linux/workqueue.h>
Tomi Valkeinenab83b142010-06-09 15:31:01 +030033#include <linux/hardirq.h>
Tomi Valkeinen24e62892011-05-23 11:51:18 +030034#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030035#include <linux/pm_runtime.h>
Tomi Valkeinen33366d02012-09-28 13:54:35 +030036#include <linux/sizes.h>
Tomi Valkeinen0006fd62014-09-05 19:15:03 +000037#include <linux/mfd/syscon.h>
38#include <linux/regmap.h>
39#include <linux/of.h>
Laurent Pinchart7a143a42017-08-05 01:43:55 +030040#include <linux/of_device.h>
Tomi Valkeinen736e60d2015-06-04 15:22:23 +030041#include <linux/component.h>
Laurent Pinchart7a143a42017-08-05 01:43:55 +030042#include <linux/sys_soc.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 Taneja9b372c22011-05-06 11:45:49 +053048#include "dispc.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020049
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +020050struct dispc_device;
51
Tomi Valkeinen80c39712009-11-12 11:41:42 +020052/* DISPC */
Sumit Semwal8613b002010-12-02 11:27:09 +000053#define DISPC_SZ_REGS SZ_4K
Tomi Valkeinen80c39712009-11-12 11:41:42 +020054
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030055enum omap_burst_size {
56 BURST_SIZE_X2 = 0,
57 BURST_SIZE_X4 = 1,
58 BURST_SIZE_X8 = 2,
59};
60
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +020061#define REG_GET(dispc, idx, start, end) \
62 FLD_GET(dispc_read_reg(dispc, idx), start, end)
Tomi Valkeinen80c39712009-11-12 11:41:42 +020063
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +020064#define REG_FLD_MOD(dispc, idx, val, start, end) \
65 dispc_write_reg(dispc, idx, \
66 FLD_MOD(dispc_read_reg(dispc, idx), val, start, end))
Tomi Valkeinen80c39712009-11-12 11:41:42 +020067
Laurent Pinchart1ac0c892017-08-05 01:44:14 +030068/* DISPC has feature id */
69enum dispc_feature_id {
70 FEAT_LCDENABLEPOL,
71 FEAT_LCDENABLESIGNAL,
72 FEAT_PCKFREEENABLE,
73 FEAT_FUNCGATED,
74 FEAT_MGR_LCD2,
75 FEAT_MGR_LCD3,
76 FEAT_LINEBUFFERSPLIT,
77 FEAT_ROWREPEATENABLE,
78 FEAT_RESIZECONF,
79 /* Independent core clk divider */
80 FEAT_CORE_CLK_DIV,
81 FEAT_HANDLE_UV_SEPARATE,
82 FEAT_ATTR2,
83 FEAT_CPR,
84 FEAT_PRELOAD,
85 FEAT_FIR_COEF_V,
86 FEAT_ALPHA_FIXED_ZORDER,
87 FEAT_ALPHA_FREE_ZORDER,
88 FEAT_FIFO_MERGE,
89 /* An unknown HW bug causing the normal FIFO thresholds not to work */
90 FEAT_OMAP3_DSI_FIFO_BUG,
91 FEAT_BURST_2D,
92 FEAT_MFLAG,
93};
94
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053095struct dispc_features {
96 u8 sw_start;
97 u8 fp_start;
98 u8 bp_start;
99 u16 sw_max;
100 u16 vp_max;
101 u16 hp_max;
Archit Taneja33b89922012-11-14 13:50:15 +0530102 u8 mgr_width_start;
103 u8 mgr_height_start;
104 u16 mgr_width_max;
105 u16 mgr_height_max;
Archit Tanejaca5ca692013-03-26 19:15:22 +0530106 unsigned long max_lcd_pclk;
107 unsigned long max_tv_pclk;
Laurent Pinchartc4ff6ea2017-08-05 01:44:16 +0300108 unsigned int max_downscale;
109 unsigned int max_line_width;
110 unsigned int min_pcd;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200111 int (*calc_scaling)(struct dispc_device *dispc,
112 unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300113 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530114 u16 width, u16 height, u16 out_width, u16 out_height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +0300115 u32 fourcc, bool *five_taps,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530116 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +0530117 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
Tomi Valkeinen8702ee52012-10-19 15:36:11 +0300118 unsigned long (*calc_core_clk) (unsigned long pclk,
Archit Taneja8ba85302012-09-26 17:00:37 +0530119 u16 width, u16 height, u16 out_width, u16 out_height,
120 bool mem_to_mem);
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300121 u8 num_fifos;
Laurent Pinchart1ac0c892017-08-05 01:44:14 +0300122 const enum dispc_feature_id *features;
123 unsigned int num_features;
Laurent Pinchart38dc0702017-08-05 01:44:08 +0300124 const struct dss_reg_field *reg_fields;
125 const unsigned int num_reg_fields;
Laurent Pinchartfcd41882017-08-05 01:44:05 +0300126 const enum omap_overlay_caps *overlay_caps;
Laurent Pinchart94f96ad2017-08-05 01:44:04 +0300127 const u32 **supported_color_modes;
Laurent Pinchartacf591c2017-08-05 01:44:06 +0300128 unsigned int num_mgrs;
129 unsigned int num_ovls;
Laurent Pinchart28550472017-08-05 01:44:03 +0300130 unsigned int buffer_size_unit;
131 unsigned int burst_size_unit;
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +0300132
133 /* swap GFX & WB fifos */
134 bool gfx_fifo_workaround:1;
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200135
136 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
137 bool no_framedone_tv:1;
Archit Tanejad0df9a22013-03-26 19:15:25 +0530138
139 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
140 bool mstandby_workaround:1;
Archit Taneja8bc65552013-12-17 16:40:21 +0530141
142 bool set_max_preload:1;
Tomi Valkeinenf2aee312015-04-10 12:48:34 +0300143
144 /* PIXEL_INC is not added to the last pixel of a line */
145 bool last_pixel_inc_missing:1;
Tomi Valkeinene5f80912015-10-21 13:08:59 +0300146
147 /* POL_FREQ has ALIGN bit */
148 bool supports_sync_align:1;
Tomi Valkeinen20efbc32015-11-04 17:10:44 +0200149
150 bool has_writeback:1;
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +0200151
152 bool supports_double_pixel:1;
Tomi Valkeinenb7536d62016-01-13 18:41:36 +0200153
154 /*
155 * Field order for VENC is different than HDMI. We should handle this in
156 * some intelligent manner, but as the SoCs have either HDMI or VENC,
157 * never both, we can just use this flag for now.
158 */
159 bool reverse_ilace_field_order:1;
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300160
161 bool has_gamma_table:1;
Jyri Sarhafbff0102016-06-07 15:09:16 +0300162
163 bool has_gamma_i734_bug:1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530164};
165
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300166#define DISPC_MAX_NR_FIFOS 5
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300167#define DISPC_MAX_CHANNEL_GAMMA 4
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300168
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200169struct dispc_device {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +0000170 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200171 void __iomem *base;
Laurent Pinchart3cc62aa2018-02-13 14:00:25 +0200172 struct dss_device *dss;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300173
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200174 struct dss_debugfs_entry *debugfs;
175
archit tanejaaffe3602011-02-23 08:41:03 +0000176 int irq;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300177 irq_handler_t user_handler;
178 void *user_data;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200179
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200180 unsigned long core_clk_rate;
Tomi Valkeinen5391e872013-05-16 10:44:13 +0300181 unsigned long tv_pclk_rate;
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200182
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300183 u32 fifo_size[DISPC_MAX_NR_FIFOS];
184 /* maps which plane is using a fifo. fifo-id -> plane-id */
185 int fifo_assignment[DISPC_MAX_NR_FIFOS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200186
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300187 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200188 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200189
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300190 u32 *gamma_table[DISPC_MAX_CHANNEL_GAMMA];
191
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530192 const struct dispc_features *feat;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300193
194 bool is_enabled;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +0000195
196 struct regmap *syscon_pol;
197 u32 syscon_pol_offset;
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200198
199 /* DISPC_CONTROL & DISPC_CONFIG lock*/
200 spinlock_t control_lock;
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200201};
202
Amber Jain0d66cbb2011-05-19 19:47:54 +0530203enum omap_color_component {
204 /* used for all color formats for OMAP3 and earlier
205 * and for RGB and Y color component on OMAP4
206 */
207 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
208 /* used for UV component for
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +0300209 * DRM_FORMAT_YUYV, DRM_FORMAT_UYVY, DRM_FORMAT_NV12
Amber Jain0d66cbb2011-05-19 19:47:54 +0530210 * color formats on OMAP4
211 */
212 DISPC_COLOR_COMPONENT_UV = 1 << 1,
213};
214
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530215enum mgr_reg_fields {
216 DISPC_MGR_FLD_ENABLE,
217 DISPC_MGR_FLD_STNTFT,
218 DISPC_MGR_FLD_GO,
219 DISPC_MGR_FLD_TFTDATALINES,
220 DISPC_MGR_FLD_STALLMODE,
221 DISPC_MGR_FLD_TCKENABLE,
222 DISPC_MGR_FLD_TCKSELECTION,
223 DISPC_MGR_FLD_CPR,
224 DISPC_MGR_FLD_FIFOHANDCHECK,
225 /* used to maintain a count of the above fields */
226 DISPC_MGR_FLD_NUM,
227};
228
Laurent Pinchart38dc0702017-08-05 01:44:08 +0300229/* DISPC register field id */
230enum dispc_feat_reg_field {
231 FEAT_REG_FIRHINC,
232 FEAT_REG_FIRVINC,
233 FEAT_REG_FIFOHIGHTHRESHOLD,
234 FEAT_REG_FIFOLOWTHRESHOLD,
235 FEAT_REG_FIFOSIZE,
236 FEAT_REG_HORIZONTALACCU,
237 FEAT_REG_VERTICALACCU,
238};
239
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300240struct dispc_reg_field {
241 u16 reg;
242 u8 high;
243 u8 low;
244};
245
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300246struct dispc_gamma_desc {
247 u32 len;
248 u32 bits;
249 u16 reg;
250 bool has_index;
251};
252
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530253static const struct {
254 const char *name;
255 u32 vsync_irq;
256 u32 framedone_irq;
257 u32 sync_lost_irq;
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300258 struct dispc_gamma_desc gamma;
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300259 struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530260} mgr_desc[] = {
261 [OMAP_DSS_CHANNEL_LCD] = {
262 .name = "LCD",
263 .vsync_irq = DISPC_IRQ_VSYNC,
264 .framedone_irq = DISPC_IRQ_FRAMEDONE,
265 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300266 .gamma = {
267 .len = 256,
268 .bits = 8,
269 .reg = DISPC_GAMMA_TABLE0,
270 .has_index = true,
271 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530272 .reg_desc = {
273 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
274 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
275 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
276 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
277 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
278 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
279 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
280 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
281 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
282 },
283 },
284 [OMAP_DSS_CHANNEL_DIGIT] = {
285 .name = "DIGIT",
286 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200287 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530288 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300289 .gamma = {
290 .len = 1024,
291 .bits = 10,
292 .reg = DISPC_GAMMA_TABLE2,
293 .has_index = false,
294 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530295 .reg_desc = {
296 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
297 [DISPC_MGR_FLD_STNTFT] = { },
298 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
299 [DISPC_MGR_FLD_TFTDATALINES] = { },
300 [DISPC_MGR_FLD_STALLMODE] = { },
301 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
302 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
303 [DISPC_MGR_FLD_CPR] = { },
304 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
305 },
306 },
307 [OMAP_DSS_CHANNEL_LCD2] = {
308 .name = "LCD2",
309 .vsync_irq = DISPC_IRQ_VSYNC2,
310 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
311 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300312 .gamma = {
313 .len = 256,
314 .bits = 8,
315 .reg = DISPC_GAMMA_TABLE1,
316 .has_index = true,
317 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530318 .reg_desc = {
319 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
320 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
321 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
322 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
323 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
324 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
325 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
326 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
327 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
328 },
329 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530330 [OMAP_DSS_CHANNEL_LCD3] = {
331 .name = "LCD3",
332 .vsync_irq = DISPC_IRQ_VSYNC3,
333 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
334 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300335 .gamma = {
336 .len = 256,
337 .bits = 8,
338 .reg = DISPC_GAMMA_TABLE3,
339 .has_index = true,
340 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530341 .reg_desc = {
342 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
343 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
344 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
345 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
346 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
347 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
348 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
349 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
350 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
351 },
352 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530353};
354
Archit Taneja6e5264b2012-09-11 12:04:47 +0530355struct color_conv_coef {
356 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
357 int full_range;
358};
359
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200360static unsigned long dispc_fclk_rate(struct dispc_device *dispc);
361static unsigned long dispc_core_clk_rate(struct dispc_device *dispc);
362static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
363 enum omap_channel channel);
364static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
365 enum omap_channel channel);
Tomi Valkeinen65904152015-11-04 17:10:57 +0200366
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200367static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
368 enum omap_plane_id plane);
369static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
370 enum omap_plane_id plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200371
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200372static void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask);
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200373
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200374static inline void dispc_write_reg(struct dispc_device *dispc, u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200375{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200376 __raw_writel(val, dispc->base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200377}
378
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200379static inline u32 dispc_read_reg(struct dispc_device *dispc, u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200380{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200381 return __raw_readl(dispc->base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200382}
383
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200384static u32 mgr_fld_read(struct dispc_device *dispc, enum omap_channel channel,
385 enum mgr_reg_fields regfld)
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530386{
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300387 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200388
389 return REG_GET(dispc, rfld.reg, rfld.high, rfld.low);
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530390}
391
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200392static void mgr_fld_write(struct dispc_device *dispc, enum omap_channel channel,
393 enum mgr_reg_fields regfld, int val)
394{
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300395 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200396 const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG;
397 unsigned long flags;
398
Tomi Valkeinenfe6b5032018-02-12 09:16:08 +0200399 if (need_lock) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200400 spin_lock_irqsave(&dispc->control_lock, flags);
Tomi Valkeinenfe6b5032018-02-12 09:16:08 +0200401 REG_FLD_MOD(dispc, rfld.reg, val, rfld.high, rfld.low);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200402 spin_unlock_irqrestore(&dispc->control_lock, flags);
Tomi Valkeinenfe6b5032018-02-12 09:16:08 +0200403 } else {
404 REG_FLD_MOD(dispc, rfld.reg, val, rfld.high, rfld.low);
405 }
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530406}
407
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200408static int dispc_get_num_ovls(struct dispc_device *dispc)
Laurent Pinchartacf591c2017-08-05 01:44:06 +0300409{
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200410 return dispc->feat->num_ovls;
Laurent Pinchartacf591c2017-08-05 01:44:06 +0300411}
412
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200413static int dispc_get_num_mgrs(struct dispc_device *dispc)
Laurent Pinchartacf591c2017-08-05 01:44:06 +0300414{
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200415 return dispc->feat->num_mgrs;
Laurent Pinchartacf591c2017-08-05 01:44:06 +0300416}
417
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200418static void dispc_get_reg_field(struct dispc_device *dispc,
419 enum dispc_feat_reg_field id,
Laurent Pinchart38dc0702017-08-05 01:44:08 +0300420 u8 *start, u8 *end)
421{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200422 if (id >= dispc->feat->num_reg_fields)
Laurent Pinchart38dc0702017-08-05 01:44:08 +0300423 BUG();
424
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200425 *start = dispc->feat->reg_fields[id].start;
426 *end = dispc->feat->reg_fields[id].end;
Laurent Pinchart38dc0702017-08-05 01:44:08 +0300427}
428
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200429static bool dispc_has_feature(struct dispc_device *dispc,
430 enum dispc_feature_id id)
Laurent Pinchart1ac0c892017-08-05 01:44:14 +0300431{
432 unsigned int i;
433
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200434 for (i = 0; i < dispc->feat->num_features; i++) {
435 if (dispc->feat->features[i] == id)
Laurent Pinchart1ac0c892017-08-05 01:44:14 +0300436 return true;
437 }
438
439 return false;
440}
441
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200442#define SR(dispc, reg) \
443 dispc->ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(dispc, DISPC_##reg)
444#define RR(dispc, reg) \
445 dispc_write_reg(dispc, DISPC_##reg, dispc->ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200446
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200447static void dispc_save_context(struct dispc_device *dispc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200448{
Archit Tanejac6104b82011-08-05 19:06:02 +0530449 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200450
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300451 DSSDBG("dispc_save_context\n");
452
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200453 SR(dispc, IRQENABLE);
454 SR(dispc, CONTROL);
455 SR(dispc, CONFIG);
456 SR(dispc, LINE_NUMBER);
457 if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
458 dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
459 SR(dispc, GLOBAL_ALPHA);
460 if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
461 SR(dispc, CONTROL2);
462 SR(dispc, CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000463 }
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200464 if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
465 SR(dispc, CONTROL3);
466 SR(dispc, CONFIG3);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530467 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200468
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200469 for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
470 SR(dispc, DEFAULT_COLOR(i));
471 SR(dispc, TRANS_COLOR(i));
472 SR(dispc, SIZE_MGR(i));
Archit Tanejac6104b82011-08-05 19:06:02 +0530473 if (i == OMAP_DSS_CHANNEL_DIGIT)
474 continue;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200475 SR(dispc, TIMING_H(i));
476 SR(dispc, TIMING_V(i));
477 SR(dispc, POL_FREQ(i));
478 SR(dispc, DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200479
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200480 SR(dispc, DATA_CYCLE1(i));
481 SR(dispc, DATA_CYCLE2(i));
482 SR(dispc, DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200483
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200484 if (dispc_has_feature(dispc, FEAT_CPR)) {
485 SR(dispc, CPR_COEF_R(i));
486 SR(dispc, CPR_COEF_G(i));
487 SR(dispc, CPR_COEF_B(i));
Archit Tanejac6104b82011-08-05 19:06:02 +0530488 }
489 }
490
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200491 for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
492 SR(dispc, OVL_BA0(i));
493 SR(dispc, OVL_BA1(i));
494 SR(dispc, OVL_POSITION(i));
495 SR(dispc, OVL_SIZE(i));
496 SR(dispc, OVL_ATTRIBUTES(i));
497 SR(dispc, OVL_FIFO_THRESHOLD(i));
498 SR(dispc, OVL_ROW_INC(i));
499 SR(dispc, OVL_PIXEL_INC(i));
500 if (dispc_has_feature(dispc, FEAT_PRELOAD))
501 SR(dispc, OVL_PRELOAD(i));
Archit Tanejac6104b82011-08-05 19:06:02 +0530502 if (i == OMAP_DSS_GFX) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200503 SR(dispc, OVL_WINDOW_SKIP(i));
504 SR(dispc, OVL_TABLE_BA(i));
Archit Tanejac6104b82011-08-05 19:06:02 +0530505 continue;
506 }
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200507 SR(dispc, OVL_FIR(i));
508 SR(dispc, OVL_PICTURE_SIZE(i));
509 SR(dispc, OVL_ACCU0(i));
510 SR(dispc, OVL_ACCU1(i));
Archit Tanejac6104b82011-08-05 19:06:02 +0530511
512 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200513 SR(dispc, OVL_FIR_COEF_H(i, j));
Archit Tanejac6104b82011-08-05 19:06:02 +0530514
515 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200516 SR(dispc, OVL_FIR_COEF_HV(i, j));
Archit Tanejac6104b82011-08-05 19:06:02 +0530517
518 for (j = 0; j < 5; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200519 SR(dispc, OVL_CONV_COEF(i, j));
Archit Tanejac6104b82011-08-05 19:06:02 +0530520
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200521 if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530522 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200523 SR(dispc, OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300524 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000525
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200526 if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
527 SR(dispc, OVL_BA0_UV(i));
528 SR(dispc, OVL_BA1_UV(i));
529 SR(dispc, OVL_FIR2(i));
530 SR(dispc, OVL_ACCU2_0(i));
531 SR(dispc, OVL_ACCU2_1(i));
Archit Tanejac6104b82011-08-05 19:06:02 +0530532
533 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200534 SR(dispc, OVL_FIR_COEF_H2(i, j));
Archit Tanejac6104b82011-08-05 19:06:02 +0530535
536 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200537 SR(dispc, OVL_FIR_COEF_HV2(i, j));
Archit Tanejac6104b82011-08-05 19:06:02 +0530538
539 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200540 SR(dispc, OVL_FIR_COEF_V2(i, j));
Archit Tanejac6104b82011-08-05 19:06:02 +0530541 }
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200542 if (dispc_has_feature(dispc, FEAT_ATTR2))
543 SR(dispc, OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000544 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200545
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200546 if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
547 SR(dispc, DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300548
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200549 dispc->ctx_valid = true;
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300550
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200551 DSSDBG("context saved\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200552}
553
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200554static void dispc_restore_context(struct dispc_device *dispc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200555{
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200556 int i, j;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300557
558 DSSDBG("dispc_restore_context\n");
559
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200560 if (!dispc->ctx_valid)
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300561 return;
562
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200563 /*RR(dispc, IRQENABLE);*/
564 /*RR(dispc, CONTROL);*/
565 RR(dispc, CONFIG);
566 RR(dispc, LINE_NUMBER);
567 if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
568 dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
569 RR(dispc, GLOBAL_ALPHA);
570 if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
571 RR(dispc, CONFIG2);
572 if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
573 RR(dispc, CONFIG3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200574
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200575 for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
576 RR(dispc, DEFAULT_COLOR(i));
577 RR(dispc, TRANS_COLOR(i));
578 RR(dispc, SIZE_MGR(i));
Archit Tanejac6104b82011-08-05 19:06:02 +0530579 if (i == OMAP_DSS_CHANNEL_DIGIT)
580 continue;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200581 RR(dispc, TIMING_H(i));
582 RR(dispc, TIMING_V(i));
583 RR(dispc, POL_FREQ(i));
584 RR(dispc, DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530585
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200586 RR(dispc, DATA_CYCLE1(i));
587 RR(dispc, DATA_CYCLE2(i));
588 RR(dispc, DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000589
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200590 if (dispc_has_feature(dispc, FEAT_CPR)) {
591 RR(dispc, CPR_COEF_R(i));
592 RR(dispc, CPR_COEF_G(i));
593 RR(dispc, CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300594 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000595 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200596
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200597 for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
598 RR(dispc, OVL_BA0(i));
599 RR(dispc, OVL_BA1(i));
600 RR(dispc, OVL_POSITION(i));
601 RR(dispc, OVL_SIZE(i));
602 RR(dispc, OVL_ATTRIBUTES(i));
603 RR(dispc, OVL_FIFO_THRESHOLD(i));
604 RR(dispc, OVL_ROW_INC(i));
605 RR(dispc, OVL_PIXEL_INC(i));
606 if (dispc_has_feature(dispc, FEAT_PRELOAD))
607 RR(dispc, OVL_PRELOAD(i));
Archit Tanejac6104b82011-08-05 19:06:02 +0530608 if (i == OMAP_DSS_GFX) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200609 RR(dispc, OVL_WINDOW_SKIP(i));
610 RR(dispc, OVL_TABLE_BA(i));
Archit Tanejac6104b82011-08-05 19:06:02 +0530611 continue;
612 }
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200613 RR(dispc, OVL_FIR(i));
614 RR(dispc, OVL_PICTURE_SIZE(i));
615 RR(dispc, OVL_ACCU0(i));
616 RR(dispc, OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200617
Archit Tanejac6104b82011-08-05 19:06:02 +0530618 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200619 RR(dispc, OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200620
Archit Tanejac6104b82011-08-05 19:06:02 +0530621 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200622 RR(dispc, OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200623
Archit Tanejac6104b82011-08-05 19:06:02 +0530624 for (j = 0; j < 5; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200625 RR(dispc, OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200626
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200627 if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530628 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200629 RR(dispc, OVL_FIR_COEF_V(i, j));
Archit Tanejac6104b82011-08-05 19:06:02 +0530630 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200631
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200632 if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
633 RR(dispc, OVL_BA0_UV(i));
634 RR(dispc, OVL_BA1_UV(i));
635 RR(dispc, OVL_FIR2(i));
636 RR(dispc, OVL_ACCU2_0(i));
637 RR(dispc, OVL_ACCU2_1(i));
Archit Tanejac6104b82011-08-05 19:06:02 +0530638
639 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200640 RR(dispc, OVL_FIR_COEF_H2(i, j));
Archit Tanejac6104b82011-08-05 19:06:02 +0530641
642 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200643 RR(dispc, OVL_FIR_COEF_HV2(i, j));
Archit Tanejac6104b82011-08-05 19:06:02 +0530644
645 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200646 RR(dispc, OVL_FIR_COEF_V2(i, j));
Archit Tanejac6104b82011-08-05 19:06:02 +0530647 }
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200648 if (dispc_has_feature(dispc, FEAT_ATTR2))
649 RR(dispc, OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300650 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200651
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200652 if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
653 RR(dispc, DIVISOR);
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600654
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200655 /* enable last, because LCD & DIGIT enable are here */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200656 RR(dispc, CONTROL);
657 if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
658 RR(dispc, CONTROL2);
659 if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
660 RR(dispc, CONTROL3);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200661 /* clear spurious SYNC_LOST_DIGIT interrupts */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200662 dispc_clear_irqstatus(dispc, DISPC_IRQ_SYNC_LOST_DIGIT);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200663
664 /*
665 * enable last so IRQs won't trigger before
666 * the context is fully restored
667 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200668 RR(dispc, IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300669
670 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200671}
672
673#undef SR
674#undef RR
675
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200676int dispc_runtime_get(struct dispc_device *dispc)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300677{
678 int r;
679
680 DSSDBG("dispc_runtime_get\n");
681
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200682 r = pm_runtime_get_sync(&dispc->pdev->dev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300683 WARN_ON(r < 0);
684 return r < 0 ? r : 0;
685}
686
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200687void dispc_runtime_put(struct dispc_device *dispc)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300688{
689 int r;
690
691 DSSDBG("dispc_runtime_put\n");
692
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200693 r = pm_runtime_put_sync(&dispc->pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300694 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300695}
696
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200697static u32 dispc_mgr_get_vsync_irq(struct dispc_device *dispc,
698 enum omap_channel channel)
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200699{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530700 return mgr_desc[channel].vsync_irq;
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200701}
702
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200703static u32 dispc_mgr_get_framedone_irq(struct dispc_device *dispc,
704 enum omap_channel channel)
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200705{
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200706 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc->feat->no_framedone_tv)
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200707 return 0;
708
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530709 return mgr_desc[channel].framedone_irq;
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200710}
711
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200712static u32 dispc_mgr_get_sync_lost_irq(struct dispc_device *dispc,
713 enum omap_channel channel)
Tomi Valkeinencb699202012-10-17 10:38:52 +0300714{
715 return mgr_desc[channel].sync_lost_irq;
716}
717
Laurent Pinchart8a7eda72018-02-13 14:00:43 +0200718u32 dispc_wb_get_framedone_irq(struct dispc_device *dispc)
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530719{
720 return DISPC_IRQ_FRAMEDONEWB;
721}
722
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200723static void dispc_mgr_enable(struct dispc_device *dispc,
724 enum omap_channel channel, bool enable)
Laurent Pinchart03af8152016-04-18 03:09:48 +0300725{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200726 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_ENABLE, enable);
Laurent Pinchart03af8152016-04-18 03:09:48 +0300727 /* flush posted write */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200728 mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
Laurent Pinchart03af8152016-04-18 03:09:48 +0300729}
Laurent Pinchart03af8152016-04-18 03:09:48 +0300730
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200731static bool dispc_mgr_is_enabled(struct dispc_device *dispc,
732 enum omap_channel channel)
Laurent Pinchart03af8152016-04-18 03:09:48 +0300733{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200734 return !!mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
Laurent Pinchart03af8152016-04-18 03:09:48 +0300735}
736
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200737static bool dispc_mgr_go_busy(struct dispc_device *dispc,
738 enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200739{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200740 return mgr_fld_read(dispc, channel, DISPC_MGR_FLD_GO) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200741}
742
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200743static void dispc_mgr_go(struct dispc_device *dispc, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200744{
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200745 WARN_ON(!dispc_mgr_is_enabled(dispc, channel));
746 WARN_ON(dispc_mgr_go_busy(dispc, channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200747
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530748 DSSDBG("GO %s\n", mgr_desc[channel].name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200749
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200750 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_GO, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200751}
752
Laurent Pinchart8a7eda72018-02-13 14:00:43 +0200753bool dispc_wb_go_busy(struct dispc_device *dispc)
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530754{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200755 return REG_GET(dispc, DISPC_CONTROL2, 6, 6) == 1;
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530756}
757
Laurent Pinchart8a7eda72018-02-13 14:00:43 +0200758void dispc_wb_go(struct dispc_device *dispc)
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530759{
Jyri Sarha864050c2017-03-24 16:47:52 +0200760 enum omap_plane_id plane = OMAP_DSS_WB;
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530761 bool enable, go;
762
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200763 enable = REG_GET(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530764
765 if (!enable)
766 return;
767
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200768 go = REG_GET(dispc, DISPC_CONTROL2, 6, 6) == 1;
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530769 if (go) {
770 DSSERR("GO bit not down for WB\n");
771 return;
772 }
773
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200774 REG_FLD_MOD(dispc, DISPC_CONTROL2, 1, 6, 6);
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530775}
776
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200777static void dispc_ovl_write_firh_reg(struct dispc_device *dispc,
778 enum omap_plane_id plane, int reg,
Jyri Sarha864050c2017-03-24 16:47:52 +0200779 u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200780{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200781 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200782}
783
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200784static void dispc_ovl_write_firhv_reg(struct dispc_device *dispc,
785 enum omap_plane_id plane, int reg,
Jyri Sarha864050c2017-03-24 16:47:52 +0200786 u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200787{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200788 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200789}
790
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200791static void dispc_ovl_write_firv_reg(struct dispc_device *dispc,
792 enum omap_plane_id plane, int reg,
Jyri Sarha864050c2017-03-24 16:47:52 +0200793 u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200794{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200795 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200796}
797
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200798static void dispc_ovl_write_firh2_reg(struct dispc_device *dispc,
799 enum omap_plane_id plane, int reg,
Jyri Sarha864050c2017-03-24 16:47:52 +0200800 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530801{
802 BUG_ON(plane == OMAP_DSS_GFX);
803
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200804 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H2(plane, reg), value);
Amber Jainab5ca072011-05-19 19:47:53 +0530805}
806
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200807static void dispc_ovl_write_firhv2_reg(struct dispc_device *dispc,
808 enum omap_plane_id plane, int reg,
809 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530810{
811 BUG_ON(plane == OMAP_DSS_GFX);
812
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200813 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
Amber Jainab5ca072011-05-19 19:47:53 +0530814}
815
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200816static void dispc_ovl_write_firv2_reg(struct dispc_device *dispc,
817 enum omap_plane_id plane, int reg,
Jyri Sarha864050c2017-03-24 16:47:52 +0200818 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530819{
820 BUG_ON(plane == OMAP_DSS_GFX);
821
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200822 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V2(plane, reg), value);
Amber Jainab5ca072011-05-19 19:47:53 +0530823}
824
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200825static void dispc_ovl_set_scale_coef(struct dispc_device *dispc,
826 enum omap_plane_id plane, int fir_hinc,
827 int fir_vinc, int five_taps,
828 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200829{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530830 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200831 int i;
832
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530833 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
834 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200835
836 for (i = 0; i < 8; i++) {
837 u32 h, hv;
838
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530839 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
840 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
841 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
842 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
843 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
844 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
845 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
846 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200847
Amber Jain0d66cbb2011-05-19 19:47:54 +0530848 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200849 dispc_ovl_write_firh_reg(dispc, plane, i, h);
850 dispc_ovl_write_firhv_reg(dispc, plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530851 } else {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200852 dispc_ovl_write_firh2_reg(dispc, plane, i, h);
853 dispc_ovl_write_firhv2_reg(dispc, plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530854 }
855
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200856 }
857
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200858 if (five_taps) {
859 for (i = 0; i < 8; i++) {
860 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530861 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
862 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530863 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200864 dispc_ovl_write_firv_reg(dispc, plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530865 else
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200866 dispc_ovl_write_firv2_reg(dispc, plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200867 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200868 }
869}
870
Archit Taneja6e5264b2012-09-11 12:04:47 +0530871
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200872static void dispc_ovl_write_color_conv_coef(struct dispc_device *dispc,
873 enum omap_plane_id plane,
874 const struct color_conv_coef *ct)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200875{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200876#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
877
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200878 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
879 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
880 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
881 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
882 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200883
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200884 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200885
886#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200887}
888
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200889static void dispc_setup_color_conv_coef(struct dispc_device *dispc)
Archit Taneja6e5264b2012-09-11 12:04:47 +0530890{
891 int i;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200892 int num_ovl = dispc_get_num_ovls(dispc);
Archit Taneja6e5264b2012-09-11 12:04:47 +0530893 const struct color_conv_coef ctbl_bt601_5_ovl = {
Tomi Valkeinen7d18bbe2015-11-04 17:10:52 +0200894 /* YUV -> RGB */
Archit Taneja6e5264b2012-09-11 12:04:47 +0530895 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
896 };
897 const struct color_conv_coef ctbl_bt601_5_wb = {
Tomi Valkeinen7d18bbe2015-11-04 17:10:52 +0200898 /* RGB -> YUV */
899 66, 129, 25, 112, -94, -18, -38, -74, 112, 0,
Archit Taneja6e5264b2012-09-11 12:04:47 +0530900 };
901
902 for (i = 1; i < num_ovl; i++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200903 dispc_ovl_write_color_conv_coef(dispc, i, &ctbl_bt601_5_ovl);
Archit Taneja6e5264b2012-09-11 12:04:47 +0530904
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200905 if (dispc->feat->has_writeback)
906 dispc_ovl_write_color_conv_coef(dispc, OMAP_DSS_WB,
907 &ctbl_bt601_5_wb);
Archit Taneja6e5264b2012-09-11 12:04:47 +0530908}
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200909
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200910static void dispc_ovl_set_ba0(struct dispc_device *dispc,
911 enum omap_plane_id plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200912{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200913 dispc_write_reg(dispc, DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200914}
915
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200916static void dispc_ovl_set_ba1(struct dispc_device *dispc,
917 enum omap_plane_id plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200918{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200919 dispc_write_reg(dispc, DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200920}
921
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200922static void dispc_ovl_set_ba0_uv(struct dispc_device *dispc,
923 enum omap_plane_id plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530924{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200925 dispc_write_reg(dispc, DISPC_OVL_BA0_UV(plane), paddr);
Amber Jainab5ca072011-05-19 19:47:53 +0530926}
927
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200928static void dispc_ovl_set_ba1_uv(struct dispc_device *dispc,
929 enum omap_plane_id plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530930{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200931 dispc_write_reg(dispc, DISPC_OVL_BA1_UV(plane), paddr);
Amber Jainab5ca072011-05-19 19:47:53 +0530932}
933
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200934static void dispc_ovl_set_pos(struct dispc_device *dispc,
935 enum omap_plane_id plane,
936 enum omap_overlay_caps caps, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200937{
Archit Tanejad79db852012-09-22 12:30:17 +0530938 u32 val;
939
940 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
941 return;
942
943 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530944
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200945 dispc_write_reg(dispc, DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200946}
947
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200948static void dispc_ovl_set_input_size(struct dispc_device *dispc,
949 enum omap_plane_id plane, int width,
950 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200951{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200952 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530953
Archit Taneja36d87d92012-07-28 22:59:03 +0530954 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200955 dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
Archit Taneja9b372c22011-05-06 11:45:49 +0530956 else
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200957 dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200958}
959
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200960static void dispc_ovl_set_output_size(struct dispc_device *dispc,
961 enum omap_plane_id plane, int width,
962 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200963{
964 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200965
966 BUG_ON(plane == OMAP_DSS_GFX);
967
968 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530969
Archit Taneja36d87d92012-07-28 22:59:03 +0530970 if (plane == OMAP_DSS_WB)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200971 dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
Archit Taneja36d87d92012-07-28 22:59:03 +0530972 else
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200973 dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200974}
975
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200976static void dispc_ovl_set_zorder(struct dispc_device *dispc,
977 enum omap_plane_id plane,
978 enum omap_overlay_caps caps, u8 zorder)
Archit Taneja54128702011-09-08 11:29:17 +0530979{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530980 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
Archit Taneja54128702011-09-08 11:29:17 +0530981 return;
982
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200983 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
Archit Taneja54128702011-09-08 11:29:17 +0530984}
985
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200986static void dispc_ovl_enable_zorder_planes(struct dispc_device *dispc)
Archit Taneja54128702011-09-08 11:29:17 +0530987{
988 int i;
989
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200990 if (!dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
Archit Taneja54128702011-09-08 11:29:17 +0530991 return;
992
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200993 for (i = 0; i < dispc_get_num_ovls(dispc); i++)
994 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
Archit Taneja54128702011-09-08 11:29:17 +0530995}
996
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +0200997static void dispc_ovl_set_pre_mult_alpha(struct dispc_device *dispc,
998 enum omap_plane_id plane,
999 enum omap_overlay_caps caps,
1000 bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +01001001{
Archit Taneja5b54ed32012-09-26 16:55:27 +05301002 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +01001003 return;
1004
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001005 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +01001006}
1007
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001008static void dispc_ovl_setup_global_alpha(struct dispc_device *dispc,
1009 enum omap_plane_id plane,
1010 enum omap_overlay_caps caps,
1011 u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001012{
Laurent Pinchartd11e5c82018-02-11 15:07:34 +02001013 static const unsigned int shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001014 int shift;
1015
Archit Taneja5b54ed32012-09-26 16:55:27 +05301016 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +01001017 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301018
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001019 shift = shifts[plane];
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001020 REG_FLD_MOD(dispc, DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001021}
1022
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001023static void dispc_ovl_set_pix_inc(struct dispc_device *dispc,
1024 enum omap_plane_id plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001025{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001026 dispc_write_reg(dispc, DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001027}
1028
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001029static void dispc_ovl_set_row_inc(struct dispc_device *dispc,
1030 enum omap_plane_id plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001031{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001032 dispc_write_reg(dispc, DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001033}
1034
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001035static void dispc_ovl_set_color_mode(struct dispc_device *dispc,
1036 enum omap_plane_id plane, u32 fourcc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001037{
1038 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +05301039 if (plane != OMAP_DSS_GFX) {
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001040 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001041 case DRM_FORMAT_NV12:
Amber Jainf20e4222011-05-19 19:47:50 +05301042 m = 0x0; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001043 case DRM_FORMAT_XRGB4444:
Amber Jainf20e4222011-05-19 19:47:50 +05301044 m = 0x1; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001045 case DRM_FORMAT_RGBA4444:
Amber Jainf20e4222011-05-19 19:47:50 +05301046 m = 0x2; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001047 case DRM_FORMAT_RGBX4444:
Amber Jainf20e4222011-05-19 19:47:50 +05301048 m = 0x4; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001049 case DRM_FORMAT_ARGB4444:
Amber Jainf20e4222011-05-19 19:47:50 +05301050 m = 0x5; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001051 case DRM_FORMAT_RGB565:
Amber Jainf20e4222011-05-19 19:47:50 +05301052 m = 0x6; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001053 case DRM_FORMAT_ARGB1555:
Amber Jainf20e4222011-05-19 19:47:50 +05301054 m = 0x7; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001055 case DRM_FORMAT_XRGB8888:
Amber Jainf20e4222011-05-19 19:47:50 +05301056 m = 0x8; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001057 case DRM_FORMAT_RGB888:
Amber Jainf20e4222011-05-19 19:47:50 +05301058 m = 0x9; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001059 case DRM_FORMAT_YUYV:
Amber Jainf20e4222011-05-19 19:47:50 +05301060 m = 0xa; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001061 case DRM_FORMAT_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301062 m = 0xb; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001063 case DRM_FORMAT_ARGB8888:
Amber Jainf20e4222011-05-19 19:47:50 +05301064 m = 0xc; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001065 case DRM_FORMAT_RGBA8888:
Amber Jainf20e4222011-05-19 19:47:50 +05301066 m = 0xd; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001067 case DRM_FORMAT_RGBX8888:
Amber Jainf20e4222011-05-19 19:47:50 +05301068 m = 0xe; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001069 case DRM_FORMAT_XRGB1555:
Amber Jainf20e4222011-05-19 19:47:50 +05301070 m = 0xf; break;
1071 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001072 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +05301073 }
1074 } else {
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001075 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001076 case DRM_FORMAT_RGBX4444:
Amber Jainf20e4222011-05-19 19:47:50 +05301077 m = 0x4; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001078 case DRM_FORMAT_ARGB4444:
Amber Jainf20e4222011-05-19 19:47:50 +05301079 m = 0x5; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001080 case DRM_FORMAT_RGB565:
Amber Jainf20e4222011-05-19 19:47:50 +05301081 m = 0x6; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001082 case DRM_FORMAT_ARGB1555:
Amber Jainf20e4222011-05-19 19:47:50 +05301083 m = 0x7; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001084 case DRM_FORMAT_XRGB8888:
Amber Jainf20e4222011-05-19 19:47:50 +05301085 m = 0x8; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001086 case DRM_FORMAT_RGB888:
Amber Jainf20e4222011-05-19 19:47:50 +05301087 m = 0x9; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001088 case DRM_FORMAT_XRGB4444:
Amber Jainf20e4222011-05-19 19:47:50 +05301089 m = 0xa; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001090 case DRM_FORMAT_RGBA4444:
Amber Jainf20e4222011-05-19 19:47:50 +05301091 m = 0xb; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001092 case DRM_FORMAT_ARGB8888:
Amber Jainf20e4222011-05-19 19:47:50 +05301093 m = 0xc; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001094 case DRM_FORMAT_RGBA8888:
Amber Jainf20e4222011-05-19 19:47:50 +05301095 m = 0xd; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001096 case DRM_FORMAT_RGBX8888:
Amber Jainf20e4222011-05-19 19:47:50 +05301097 m = 0xe; break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001098 case DRM_FORMAT_XRGB1555:
Amber Jainf20e4222011-05-19 19:47:50 +05301099 m = 0xf; break;
1100 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001101 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +05301102 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001103 }
1104
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001105 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001106}
1107
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001108static bool format_is_yuv(u32 fourcc)
Tomi Valkeinen5edec142017-05-04 09:13:32 +03001109{
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001110 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001111 case DRM_FORMAT_YUYV:
1112 case DRM_FORMAT_UYVY:
1113 case DRM_FORMAT_NV12:
Tomi Valkeinen5edec142017-05-04 09:13:32 +03001114 return true;
1115 default:
1116 return false;
1117 }
1118}
1119
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001120static void dispc_ovl_configure_burst_type(struct dispc_device *dispc,
1121 enum omap_plane_id plane,
1122 enum omap_dss_rotation_type rotation)
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301123{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001124 if (dispc_has_feature(dispc, FEAT_BURST_2D) == 0)
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301125 return;
1126
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001127 if (rotation == OMAP_DSS_ROT_TILER)
1128 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301129 else
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001130 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301131}
1132
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001133static void dispc_ovl_set_channel_out(struct dispc_device *dispc,
1134 enum omap_plane_id plane,
Jyri Sarha864050c2017-03-24 16:47:52 +02001135 enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001136{
1137 int shift;
1138 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001139 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001140
1141 switch (plane) {
1142 case OMAP_DSS_GFX:
1143 shift = 8;
1144 break;
1145 case OMAP_DSS_VIDEO1:
1146 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +05301147 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001148 shift = 16;
1149 break;
1150 default:
1151 BUG();
1152 return;
1153 }
1154
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001155 val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
1156 if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
Sumit Semwal2a205f32010-12-02 11:27:12 +00001157 switch (channel) {
1158 case OMAP_DSS_CHANNEL_LCD:
1159 chan = 0;
1160 chan2 = 0;
1161 break;
1162 case OMAP_DSS_CHANNEL_DIGIT:
1163 chan = 1;
1164 chan2 = 0;
1165 break;
1166 case OMAP_DSS_CHANNEL_LCD2:
1167 chan = 0;
1168 chan2 = 1;
1169 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05301170 case OMAP_DSS_CHANNEL_LCD3:
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001171 if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05301172 chan = 0;
1173 chan2 = 2;
1174 } else {
1175 BUG();
1176 return;
1177 }
1178 break;
Tomi Valkeinenc2665c42015-11-04 17:10:47 +02001179 case OMAP_DSS_CHANNEL_WB:
1180 chan = 0;
1181 chan2 = 3;
1182 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001183 default:
1184 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001185 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001186 }
1187
1188 val = FLD_MOD(val, chan, shift, shift);
1189 val = FLD_MOD(val, chan2, 31, 30);
1190 } else {
1191 val = FLD_MOD(val, channel, shift, shift);
1192 }
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001193 dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001194}
1195
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001196static enum omap_channel dispc_ovl_get_channel_out(struct dispc_device *dispc,
1197 enum omap_plane_id plane)
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001198{
1199 int shift;
1200 u32 val;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001201
1202 switch (plane) {
1203 case OMAP_DSS_GFX:
1204 shift = 8;
1205 break;
1206 case OMAP_DSS_VIDEO1:
1207 case OMAP_DSS_VIDEO2:
1208 case OMAP_DSS_VIDEO3:
1209 shift = 16;
1210 break;
1211 default:
1212 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001213 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001214 }
1215
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001216 val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001217
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001218 if (FLD_GET(val, shift, shift) == 1)
1219 return OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001220
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001221 if (!dispc_has_feature(dispc, FEAT_MGR_LCD2))
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001222 return OMAP_DSS_CHANNEL_LCD;
1223
1224 switch (FLD_GET(val, 31, 30)) {
1225 case 0:
1226 default:
1227 return OMAP_DSS_CHANNEL_LCD;
1228 case 1:
1229 return OMAP_DSS_CHANNEL_LCD2;
1230 case 2:
1231 return OMAP_DSS_CHANNEL_LCD3;
Tomi Valkeinenc2665c42015-11-04 17:10:47 +02001232 case 3:
1233 return OMAP_DSS_CHANNEL_WB;
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001234 }
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001235}
1236
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001237static void dispc_ovl_set_burst_size(struct dispc_device *dispc,
1238 enum omap_plane_id plane,
1239 enum omap_burst_size burst_size)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001240{
Laurent Pinchartd11e5c82018-02-11 15:07:34 +02001241 static const unsigned int shifts[] = { 6, 14, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001242 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001243
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001244 shift = shifts[plane];
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001245 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), burst_size,
1246 shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001247}
1248
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001249static void dispc_configure_burst_sizes(struct dispc_device *dispc)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001250{
1251 int i;
1252 const int burst_size = BURST_SIZE_X8;
1253
1254 /* Configure burst size always to maximum size */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001255 for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
1256 dispc_ovl_set_burst_size(dispc, i, burst_size);
1257 if (dispc->feat->has_writeback)
1258 dispc_ovl_set_burst_size(dispc, OMAP_DSS_WB, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001259}
1260
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001261static u32 dispc_ovl_get_burst_size(struct dispc_device *dispc,
1262 enum omap_plane_id plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001263{
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001264 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001265 return dispc->feat->burst_size_unit * 8;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001266}
1267
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001268static bool dispc_ovl_color_mode_supported(struct dispc_device *dispc,
1269 enum omap_plane_id plane, u32 fourcc)
Laurent Pinchart94f96ad2017-08-05 01:44:04 +03001270{
1271 const u32 *modes;
1272 unsigned int i;
1273
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001274 modes = dispc->feat->supported_color_modes[plane];
Laurent Pinchart94f96ad2017-08-05 01:44:04 +03001275
1276 for (i = 0; modes[i]; ++i) {
1277 if (modes[i] == fourcc)
1278 return true;
1279 }
1280
1281 return false;
1282}
1283
Laurent Pinchart50638ae2018-02-13 14:00:42 +02001284static const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc,
1285 enum omap_plane_id plane)
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001286{
Laurent Pinchart50638ae2018-02-13 14:00:42 +02001287 return dispc->feat->supported_color_modes[plane];
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001288}
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001289
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001290static void dispc_mgr_enable_cpr(struct dispc_device *dispc,
1291 enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001292{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301293 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001294 return;
1295
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001296 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001297}
1298
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001299static void dispc_mgr_set_cpr_coef(struct dispc_device *dispc,
1300 enum omap_channel channel,
1301 const struct omap_dss_cpr_coefs *coefs)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001302{
1303 u32 coef_r, coef_g, coef_b;
1304
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301305 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001306 return;
1307
1308 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1309 FLD_VAL(coefs->rb, 9, 0);
1310 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1311 FLD_VAL(coefs->gb, 9, 0);
1312 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1313 FLD_VAL(coefs->bb, 9, 0);
1314
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001315 dispc_write_reg(dispc, DISPC_CPR_COEF_R(channel), coef_r);
1316 dispc_write_reg(dispc, DISPC_CPR_COEF_G(channel), coef_g);
1317 dispc_write_reg(dispc, DISPC_CPR_COEF_B(channel), coef_b);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001318}
1319
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001320static void dispc_ovl_set_vid_color_conv(struct dispc_device *dispc,
1321 enum omap_plane_id plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001322{
1323 u32 val;
1324
1325 BUG_ON(plane == OMAP_DSS_GFX);
1326
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001327 val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001328 val = FLD_MOD(val, enable, 9, 9);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001329 dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001330}
1331
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001332static void dispc_ovl_enable_replication(struct dispc_device *dispc,
1333 enum omap_plane_id plane,
1334 enum omap_overlay_caps caps,
1335 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001336{
Laurent Pinchartd11e5c82018-02-11 15:07:34 +02001337 static const unsigned int shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001338 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001339
Archit Tanejad79db852012-09-22 12:30:17 +05301340 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1341 return;
1342
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001343 shift = shifts[plane];
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001344 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001345}
1346
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001347static void dispc_mgr_set_size(struct dispc_device *dispc,
1348 enum omap_channel channel, u16 width, u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001349{
1350 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301351
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001352 val = FLD_VAL(height - 1, dispc->feat->mgr_height_start, 16) |
1353 FLD_VAL(width - 1, dispc->feat->mgr_width_start, 0);
Archit Taneja33b89922012-11-14 13:50:15 +05301354
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001355 dispc_write_reg(dispc, DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001356}
1357
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001358static void dispc_init_fifos(struct dispc_device *dispc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001359{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001360 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001361 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301362 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001363 u32 unit;
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001364 int i;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001365
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001366 unit = dispc->feat->buffer_size_unit;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001367
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001368 dispc_get_reg_field(dispc, FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001369
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001370 for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
1371 size = REG_GET(dispc, DISPC_OVL_FIFO_SIZE_STATUS(fifo),
1372 start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001373 size *= unit;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001374 dispc->fifo_size[fifo] = size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001375
1376 /*
1377 * By default fifos are mapped directly to overlays, fifo 0 to
1378 * ovl 0, fifo 1 to ovl 1, etc.
1379 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001380 dispc->fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001381 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001382
1383 /*
1384 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1385 * causes problems with certain use cases, like using the tiler in 2D
1386 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1387 * giving GFX plane a larger fifo. WB but should work fine with a
1388 * smaller fifo.
1389 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001390 if (dispc->feat->gfx_fifo_workaround) {
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001391 u32 v;
1392
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001393 v = dispc_read_reg(dispc, DISPC_GLOBAL_BUFFER);
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001394
1395 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1396 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1397 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1398 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1399
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001400 dispc_write_reg(dispc, DISPC_GLOBAL_BUFFER, v);
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001401
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001402 dispc->fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1403 dispc->fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001404 }
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001405
1406 /*
1407 * Setup default fifo thresholds.
1408 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001409 for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001410 u32 low, high;
1411 const bool use_fifomerge = false;
1412 const bool manual_update = false;
1413
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001414 dispc_ovl_compute_fifo_thresholds(dispc, i, &low, &high,
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02001415 use_fifomerge, manual_update);
Tomi Valkeinen65e116e2015-11-04 17:10:49 +02001416
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001417 dispc_ovl_set_fifo_threshold(dispc, i, low, high);
1418 }
1419
1420 if (dispc->feat->has_writeback) {
1421 u32 low, high;
1422 const bool use_fifomerge = false;
1423 const bool manual_update = false;
1424
1425 dispc_ovl_compute_fifo_thresholds(dispc, OMAP_DSS_WB,
1426 &low, &high, use_fifomerge,
1427 manual_update);
1428
1429 dispc_ovl_set_fifo_threshold(dispc, OMAP_DSS_WB, low, high);
Tomi Valkeinen65e116e2015-11-04 17:10:49 +02001430 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001431}
1432
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001433static u32 dispc_ovl_get_fifo_size(struct dispc_device *dispc,
1434 enum omap_plane_id plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001435{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001436 int fifo;
1437 u32 size = 0;
1438
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001439 for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
1440 if (dispc->fifo_assignment[fifo] == plane)
1441 size += dispc->fifo_size[fifo];
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001442 }
1443
1444 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001445}
1446
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02001447void dispc_ovl_set_fifo_threshold(struct dispc_device *dispc,
1448 enum omap_plane_id plane,
1449 u32 low, u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001450{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301451 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001452 u32 unit;
1453
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02001454 unit = dispc->feat->buffer_size_unit;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001455
1456 WARN_ON(low % unit != 0);
1457 WARN_ON(high % unit != 0);
1458
1459 low /= unit;
1460 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301461
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001462 dispc_get_reg_field(dispc, FEAT_REG_FIFOHIGHTHRESHOLD,
1463 &hi_start, &hi_end);
1464 dispc_get_reg_field(dispc, FEAT_REG_FIFOLOWTHRESHOLD,
1465 &lo_start, &lo_end);
Archit Taneja9b372c22011-05-06 11:45:49 +05301466
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001467 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001468 plane,
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001469 REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001470 lo_start, lo_end) * unit,
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001471 REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001472 hi_start, hi_end) * unit,
1473 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001474
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001475 dispc_write_reg(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301476 FLD_VAL(high, hi_start, hi_end) |
1477 FLD_VAL(low, lo_start, lo_end));
Archit Taneja8bc65552013-12-17 16:40:21 +05301478
1479 /*
1480 * configure the preload to the pipeline's high threhold, if HT it's too
1481 * large for the preload field, set the threshold to the maximum value
1482 * that can be held by the preload register
1483 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001484 if (dispc_has_feature(dispc, FEAT_PRELOAD) &&
1485 dispc->feat->set_max_preload && plane != OMAP_DSS_WB)
1486 dispc_write_reg(dispc, DISPC_OVL_PRELOAD(plane),
1487 min(high, 0xfffu));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001488}
1489
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02001490void dispc_enable_fifomerge(struct dispc_device *dispc, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001491{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001492 if (!dispc_has_feature(dispc, FEAT_FIFO_MERGE)) {
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001493 WARN_ON(enable);
1494 return;
1495 }
1496
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001497 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001498 REG_FLD_MOD(dispc, DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001499}
1500
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02001501void dispc_ovl_compute_fifo_thresholds(struct dispc_device *dispc,
1502 enum omap_plane_id plane,
1503 u32 *fifo_low, u32 *fifo_high,
1504 bool use_fifomerge, bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001505{
1506 /*
1507 * All sizes are in bytes. Both the buffer and burst are made of
1508 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1509 */
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02001510 unsigned int buf_unit = dispc->feat->buffer_size_unit;
Laurent Pinchartd11e5c82018-02-11 15:07:34 +02001511 unsigned int ovl_fifo_size, total_fifo_size, burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001512 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001513
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001514 burst_size = dispc_ovl_get_burst_size(dispc, plane);
1515 ovl_fifo_size = dispc_ovl_get_fifo_size(dispc, plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001516
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001517 if (use_fifomerge) {
1518 total_fifo_size = 0;
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02001519 for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001520 total_fifo_size += dispc_ovl_get_fifo_size(dispc, i);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001521 } else {
1522 total_fifo_size = ovl_fifo_size;
1523 }
1524
1525 /*
1526 * We use the same low threshold for both fifomerge and non-fifomerge
1527 * cases, but for fifomerge we calculate the high threshold using the
1528 * combined fifo size
1529 */
1530
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001531 if (manual_update && dispc_has_feature(dispc, FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001532 *fifo_low = ovl_fifo_size - burst_size * 2;
1533 *fifo_high = total_fifo_size - burst_size;
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301534 } else if (plane == OMAP_DSS_WB) {
1535 /*
1536 * Most optimal configuration for writeback is to push out data
1537 * to the interconnect the moment writeback pushes enough pixels
1538 * in the FIFO to form a burst
1539 */
1540 *fifo_low = 0;
1541 *fifo_high = burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001542 } else {
1543 *fifo_low = ovl_fifo_size - burst_size;
1544 *fifo_high = total_fifo_size - buf_unit;
1545 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001546}
1547
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001548static void dispc_ovl_set_mflag(struct dispc_device *dispc,
1549 enum omap_plane_id plane, bool enable)
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001550{
1551 int bit;
1552
1553 if (plane == OMAP_DSS_GFX)
1554 bit = 14;
1555 else
1556 bit = 23;
1557
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001558 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001559}
1560
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001561static void dispc_ovl_set_mflag_threshold(struct dispc_device *dispc,
1562 enum omap_plane_id plane,
1563 int low, int high)
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001564{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001565 dispc_write_reg(dispc, DISPC_OVL_MFLAG_THRESHOLD(plane),
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001566 FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1567}
1568
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001569static void dispc_init_mflag(struct dispc_device *dispc)
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001570{
1571 int i;
1572
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001573 /*
1574 * HACK: NV12 color format and MFLAG seem to have problems working
1575 * together: using two displays, and having an NV12 overlay on one of
1576 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1577 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1578 * remove the errors, but there doesn't seem to be a clear logic on
1579 * which values work and which not.
1580 *
1581 * As a work-around, set force MFLAG to always on.
1582 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001583 dispc_write_reg(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE,
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001584 (1 << 0) | /* MFLAG_CTRL = force always on */
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001585 (0 << 2)); /* MFLAG_START = disable */
1586
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001587 for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
1588 u32 size = dispc_ovl_get_fifo_size(dispc, i);
1589 u32 unit = dispc->feat->buffer_size_unit;
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001590 u32 low, high;
1591
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001592 dispc_ovl_set_mflag(dispc, i, true);
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001593
1594 /*
1595 * Simulation team suggests below thesholds:
1596 * HT = fifosize * 5 / 8;
1597 * LT = fifosize * 4 / 8;
1598 */
1599
1600 low = size * 4 / 8 / unit;
1601 high = size * 5 / 8 / unit;
1602
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001603 dispc_ovl_set_mflag_threshold(dispc, i, low, high);
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001604 }
Tomi Valkeinenecb0b362015-11-04 17:10:50 +02001605
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001606 if (dispc->feat->has_writeback) {
1607 u32 size = dispc_ovl_get_fifo_size(dispc, OMAP_DSS_WB);
1608 u32 unit = dispc->feat->buffer_size_unit;
Tomi Valkeinenecb0b362015-11-04 17:10:50 +02001609 u32 low, high;
1610
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001611 dispc_ovl_set_mflag(dispc, OMAP_DSS_WB, true);
Tomi Valkeinenecb0b362015-11-04 17:10:50 +02001612
1613 /*
1614 * Simulation team suggests below thesholds:
1615 * HT = fifosize * 5 / 8;
1616 * LT = fifosize * 4 / 8;
1617 */
1618
1619 low = size * 4 / 8 / unit;
1620 high = size * 5 / 8 / unit;
1621
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001622 dispc_ovl_set_mflag_threshold(dispc, OMAP_DSS_WB, low, high);
Tomi Valkeinenecb0b362015-11-04 17:10:50 +02001623 }
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001624}
1625
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001626static void dispc_ovl_set_fir(struct dispc_device *dispc,
1627 enum omap_plane_id plane,
1628 int hinc, int vinc,
1629 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001630{
1631 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001632
Amber Jain0d66cbb2011-05-19 19:47:54 +05301633 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1634 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301635
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001636 dispc_get_reg_field(dispc, FEAT_REG_FIRHINC,
1637 &hinc_start, &hinc_end);
1638 dispc_get_reg_field(dispc, FEAT_REG_FIRVINC,
1639 &vinc_start, &vinc_end);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301640 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1641 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301642
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001643 dispc_write_reg(dispc, DISPC_OVL_FIR(plane), val);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301644 } else {
1645 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001646 dispc_write_reg(dispc, DISPC_OVL_FIR2(plane), val);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301647 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001648}
1649
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001650static void dispc_ovl_set_vid_accu0(struct dispc_device *dispc,
1651 enum omap_plane_id plane, int haccu,
Jyri Sarha864050c2017-03-24 16:47:52 +02001652 int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001653{
1654 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301655 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001656
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001657 dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
1658 &hor_start, &hor_end);
1659 dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
1660 &vert_start, &vert_end);
Archit Taneja87a74842011-03-02 11:19:50 +05301661
1662 val = FLD_VAL(vaccu, vert_start, vert_end) |
1663 FLD_VAL(haccu, hor_start, hor_end);
1664
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001665 dispc_write_reg(dispc, DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001666}
1667
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001668static void dispc_ovl_set_vid_accu1(struct dispc_device *dispc,
1669 enum omap_plane_id plane, int haccu,
Jyri Sarha864050c2017-03-24 16:47:52 +02001670 int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001671{
1672 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301673 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001674
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001675 dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
1676 &hor_start, &hor_end);
1677 dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
1678 &vert_start, &vert_end);
Archit Taneja87a74842011-03-02 11:19:50 +05301679
1680 val = FLD_VAL(vaccu, vert_start, vert_end) |
1681 FLD_VAL(haccu, hor_start, hor_end);
1682
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001683 dispc_write_reg(dispc, DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001684}
1685
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001686static void dispc_ovl_set_vid_accu2_0(struct dispc_device *dispc,
1687 enum omap_plane_id plane, int haccu,
1688 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301689{
1690 u32 val;
1691
1692 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001693 dispc_write_reg(dispc, DISPC_OVL_ACCU2_0(plane), val);
Amber Jainab5ca072011-05-19 19:47:53 +05301694}
1695
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001696static void dispc_ovl_set_vid_accu2_1(struct dispc_device *dispc,
1697 enum omap_plane_id plane, int haccu,
1698 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301699{
1700 u32 val;
1701
1702 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001703 dispc_write_reg(dispc, DISPC_OVL_ACCU2_1(plane), val);
Amber Jainab5ca072011-05-19 19:47:53 +05301704}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001705
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001706static void dispc_ovl_set_scale_param(struct dispc_device *dispc,
1707 enum omap_plane_id plane,
1708 u16 orig_width, u16 orig_height,
1709 u16 out_width, u16 out_height,
1710 bool five_taps, u8 rotation,
1711 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001712{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301713 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001714
Amber Jained14a3c2011-05-19 19:47:51 +05301715 fir_hinc = 1024 * orig_width / out_width;
1716 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001717
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001718 dispc_ovl_set_scale_coef(dispc, plane, fir_hinc, fir_vinc, five_taps,
1719 color_comp);
1720 dispc_ovl_set_fir(dispc, plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301721}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001722
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001723static void dispc_ovl_set_accu_uv(struct dispc_device *dispc,
1724 enum omap_plane_id plane,
1725 u16 orig_width, u16 orig_height,
1726 u16 out_width, u16 out_height,
1727 bool ilace, u32 fourcc, u8 rotation)
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301728{
1729 int h_accu2_0, h_accu2_1;
1730 int v_accu2_0, v_accu2_1;
1731 int chroma_hinc, chroma_vinc;
1732 int idx;
1733
1734 struct accu {
1735 s8 h0_m, h0_n;
1736 s8 h1_m, h1_n;
1737 s8 v0_m, v0_n;
1738 s8 v1_m, v1_n;
1739 };
1740
1741 const struct accu *accu_table;
1742 const struct accu *accu_val;
1743
1744 static const struct accu accu_nv12[4] = {
1745 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1746 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1747 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1748 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1749 };
1750
1751 static const struct accu accu_nv12_ilace[4] = {
1752 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1753 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1754 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1755 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1756 };
1757
1758 static const struct accu accu_yuv[4] = {
1759 { 0, 1, 0, 1, 0, 1, 0, 1 },
1760 { 0, 1, 0, 1, 0, 1, 0, 1 },
1761 { -1, 1, 0, 1, 0, 1, 0, 1 },
1762 { 0, 1, 0, 1, -1, 1, 0, 1 },
1763 };
1764
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001765 /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
1766 switch (rotation & DRM_MODE_ROTATE_MASK) {
1767 default:
1768 case DRM_MODE_ROTATE_0:
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301769 idx = 0;
1770 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001771 case DRM_MODE_ROTATE_90:
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301772 idx = 3;
1773 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001774 case DRM_MODE_ROTATE_180:
1775 idx = 2;
1776 break;
1777 case DRM_MODE_ROTATE_270:
1778 idx = 1;
1779 break;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301780 }
1781
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001782 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001783 case DRM_FORMAT_NV12:
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301784 if (ilace)
1785 accu_table = accu_nv12_ilace;
1786 else
1787 accu_table = accu_nv12;
1788 break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001789 case DRM_FORMAT_YUYV:
1790 case DRM_FORMAT_UYVY:
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301791 accu_table = accu_yuv;
1792 break;
1793 default:
1794 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001795 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301796 }
1797
1798 accu_val = &accu_table[idx];
1799
1800 chroma_hinc = 1024 * orig_width / out_width;
1801 chroma_vinc = 1024 * orig_height / out_height;
1802
1803 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1804 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1805 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1806 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1807
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001808 dispc_ovl_set_vid_accu2_0(dispc, plane, h_accu2_0, v_accu2_0);
1809 dispc_ovl_set_vid_accu2_1(dispc, plane, h_accu2_1, v_accu2_1);
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301810}
1811
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001812static void dispc_ovl_set_scaling_common(struct dispc_device *dispc,
1813 enum omap_plane_id plane,
1814 u16 orig_width, u16 orig_height,
1815 u16 out_width, u16 out_height,
1816 bool ilace, bool five_taps,
1817 bool fieldmode, u32 fourcc,
1818 u8 rotation)
Amber Jain0d66cbb2011-05-19 19:47:54 +05301819{
1820 int accu0 = 0;
1821 int accu1 = 0;
1822 u32 l;
1823
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001824 dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
1825 out_width, out_height, five_taps,
1826 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1827 l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001828
Archit Taneja87a74842011-03-02 11:19:50 +05301829 /* RESIZEENABLE and VERTICALTAPS */
1830 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301831 l |= (orig_width != out_width) ? (1 << 5) : 0;
1832 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001833 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301834
1835 /* VRESIZECONF and HRESIZECONF */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001836 if (dispc_has_feature(dispc, FEAT_RESIZECONF)) {
Archit Taneja87a74842011-03-02 11:19:50 +05301837 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301838 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1839 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301840 }
1841
1842 /* LINEBUFFERSPLIT */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001843 if (dispc_has_feature(dispc, FEAT_LINEBUFFERSPLIT)) {
Archit Taneja87a74842011-03-02 11:19:50 +05301844 l &= ~(0x1 << 22);
1845 l |= five_taps ? (1 << 22) : 0;
1846 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001847
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001848 dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001849
1850 /*
1851 * field 0 = even field = bottom field
1852 * field 1 = odd field = top field
1853 */
1854 if (ilace && !fieldmode) {
1855 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301856 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001857 if (accu0 >= 1024/2) {
1858 accu1 = 1024/2;
1859 accu0 -= accu1;
1860 }
1861 }
1862
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001863 dispc_ovl_set_vid_accu0(dispc, plane, 0, accu0);
1864 dispc_ovl_set_vid_accu1(dispc, plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001865}
1866
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001867static void dispc_ovl_set_scaling_uv(struct dispc_device *dispc,
1868 enum omap_plane_id plane,
1869 u16 orig_width, u16 orig_height,
1870 u16 out_width, u16 out_height,
1871 bool ilace, bool five_taps,
1872 bool fieldmode, u32 fourcc,
1873 u8 rotation)
Amber Jain0d66cbb2011-05-19 19:47:54 +05301874{
1875 int scale_x = out_width != orig_width;
1876 int scale_y = out_height != orig_height;
Andrew F. Davis0cac5b62016-07-01 09:27:21 -05001877 bool chroma_upscale = plane != OMAP_DSS_WB;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301878
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001879 if (!dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE))
Amber Jain0d66cbb2011-05-19 19:47:54 +05301880 return;
Tomi Valkeinen5edec142017-05-04 09:13:32 +03001881
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001882 if (!format_is_yuv(fourcc)) {
Amber Jain0d66cbb2011-05-19 19:47:54 +05301883 /* reset chroma resampling for RGB formats */
Archit Taneja2a5561b2012-07-16 16:37:45 +05301884 if (plane != OMAP_DSS_WB)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001885 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
1886 0, 8, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301887 return;
1888 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001889
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001890 dispc_ovl_set_accu_uv(dispc, plane, orig_width, orig_height, out_width,
1891 out_height, ilace, fourcc, rotation);
Tomi Valkeinen36377352012-05-15 15:54:15 +03001892
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001893 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001894 case DRM_FORMAT_NV12:
Archit Taneja20fbb502012-08-22 17:04:48 +05301895 if (chroma_upscale) {
1896 /* UV is subsampled by 2 horizontally and vertically */
1897 orig_height >>= 1;
1898 orig_width >>= 1;
1899 } else {
1900 /* UV is downsampled by 2 horizontally and vertically */
1901 orig_height <<= 1;
1902 orig_width <<= 1;
1903 }
1904
Amber Jain0d66cbb2011-05-19 19:47:54 +05301905 break;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03001906 case DRM_FORMAT_YUYV:
1907 case DRM_FORMAT_UYVY:
Archit Taneja20fbb502012-08-22 17:04:48 +05301908 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001909 if (!drm_rotation_90_or_270(rotation)) {
Archit Taneja20fbb502012-08-22 17:04:48 +05301910 if (chroma_upscale)
1911 /* UV is subsampled by 2 horizontally */
1912 orig_width >>= 1;
1913 else
1914 /* UV is downsampled by 2 horizontally */
1915 orig_width <<= 1;
1916 }
1917
Amber Jain0d66cbb2011-05-19 19:47:54 +05301918 /* must use FIR for YUV422 if rotated */
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001919 if ((rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0)
Amber Jain0d66cbb2011-05-19 19:47:54 +05301920 scale_x = scale_y = true;
Archit Taneja20fbb502012-08-22 17:04:48 +05301921
Amber Jain0d66cbb2011-05-19 19:47:54 +05301922 break;
1923 default:
1924 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001925 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301926 }
1927
1928 if (out_width != orig_width)
1929 scale_x = true;
1930 if (out_height != orig_height)
1931 scale_y = true;
1932
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001933 dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
1934 out_width, out_height, five_taps,
1935 rotation, DISPC_COLOR_COMPONENT_UV);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301936
Archit Taneja2a5561b2012-07-16 16:37:45 +05301937 if (plane != OMAP_DSS_WB)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001938 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
Archit Taneja2a5561b2012-07-16 16:37:45 +05301939 (scale_x || scale_y) ? 1 : 0, 8, 8);
1940
Amber Jain0d66cbb2011-05-19 19:47:54 +05301941 /* set H scaling */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001942 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301943 /* set V scaling */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001944 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301945}
1946
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001947static void dispc_ovl_set_scaling(struct dispc_device *dispc,
1948 enum omap_plane_id plane,
1949 u16 orig_width, u16 orig_height,
1950 u16 out_width, u16 out_height,
1951 bool ilace, bool five_taps,
1952 bool fieldmode, u32 fourcc,
1953 u8 rotation)
Amber Jain0d66cbb2011-05-19 19:47:54 +05301954{
1955 BUG_ON(plane == OMAP_DSS_GFX);
1956
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001957 dispc_ovl_set_scaling_common(dispc, plane, orig_width, orig_height,
1958 out_width, out_height, ilace, five_taps,
1959 fieldmode, fourcc, rotation);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301960
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001961 dispc_ovl_set_scaling_uv(dispc, plane, orig_width, orig_height,
1962 out_width, out_height, ilace, five_taps,
1963 fieldmode, fourcc, rotation);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301964}
1965
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02001966static void dispc_ovl_set_rotation_attrs(struct dispc_device *dispc,
1967 enum omap_plane_id plane, u8 rotation,
1968 enum omap_dss_rotation_type rotation_type,
1969 u32 fourcc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001970{
Archit Taneja87a74842011-03-02 11:19:50 +05301971 bool row_repeat = false;
1972 int vidrot = 0;
1973
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001974 /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
Tomi Valkeinen41aff422017-05-04 11:31:56 +03001975 if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001976
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03001977 if (rotation & DRM_MODE_REFLECT_X) {
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001978 switch (rotation & DRM_MODE_ROTATE_MASK) {
1979 case DRM_MODE_ROTATE_0:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001980 vidrot = 2;
1981 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001982 case DRM_MODE_ROTATE_90:
Tomi Valkeinen2add8d132017-05-16 15:25:45 +03001983 vidrot = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001984 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001985 case DRM_MODE_ROTATE_180:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001986 vidrot = 0;
1987 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001988 case DRM_MODE_ROTATE_270:
Tomi Valkeinen2add8d132017-05-16 15:25:45 +03001989 vidrot = 3;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001990 break;
1991 }
1992 } else {
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001993 switch (rotation & DRM_MODE_ROTATE_MASK) {
1994 case DRM_MODE_ROTATE_0:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001995 vidrot = 0;
1996 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03001997 case DRM_MODE_ROTATE_90:
1998 vidrot = 3;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001999 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03002000 case DRM_MODE_ROTATE_180:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002001 vidrot = 2;
2002 break;
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03002003 case DRM_MODE_ROTATE_270:
2004 vidrot = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002005 break;
2006 }
2007 }
2008
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03002009 if (drm_rotation_90_or_270(rotation))
Archit Taneja87a74842011-03-02 11:19:50 +05302010 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002011 else
Archit Taneja87a74842011-03-02 11:19:50 +05302012 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002013 }
Archit Taneja87a74842011-03-02 11:19:50 +05302014
Tomi Valkeinen3397cc62015-04-09 13:51:30 +03002015 /*
2016 * OMAP4/5 Errata i631:
2017 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
2018 * rows beyond the framebuffer, which may cause OCP error.
2019 */
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002020 if (fourcc == DRM_FORMAT_NV12 && rotation_type != OMAP_DSS_ROT_TILER)
Tomi Valkeinen3397cc62015-04-09 13:51:30 +03002021 vidrot = 1;
2022
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002023 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
2024 if (dispc_has_feature(dispc, FEAT_ROWREPEATENABLE))
2025 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
Archit Taneja9b372c22011-05-06 11:45:49 +05302026 row_repeat ? 1 : 0, 18, 18);
Archit Tanejac35eeb22013-03-26 19:15:24 +05302027
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002028 if (dispc_ovl_color_mode_supported(dispc, plane, DRM_FORMAT_NV12)) {
Tomi Valkeinen6d862782016-08-29 11:15:49 +03002029 bool doublestride =
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002030 fourcc == DRM_FORMAT_NV12 &&
Tomi Valkeinen6d862782016-08-29 11:15:49 +03002031 rotation_type == OMAP_DSS_ROT_TILER &&
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03002032 !drm_rotation_90_or_270(rotation);
Tomi Valkeinen6d862782016-08-29 11:15:49 +03002033
Archit Tanejac35eeb22013-03-26 19:15:24 +05302034 /* DOUBLESTRIDE */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002035 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
2036 doublestride, 22, 22);
Archit Tanejac35eeb22013-03-26 19:15:24 +05302037 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002038}
2039
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002040static int color_mode_to_bpp(u32 fourcc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002041{
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002042 switch (fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03002043 case DRM_FORMAT_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002044 return 8;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03002045 case DRM_FORMAT_RGBX4444:
2046 case DRM_FORMAT_RGB565:
2047 case DRM_FORMAT_ARGB4444:
2048 case DRM_FORMAT_YUYV:
2049 case DRM_FORMAT_UYVY:
2050 case DRM_FORMAT_RGBA4444:
2051 case DRM_FORMAT_XRGB4444:
2052 case DRM_FORMAT_ARGB1555:
2053 case DRM_FORMAT_XRGB1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002054 return 16;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03002055 case DRM_FORMAT_RGB888:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002056 return 24;
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03002057 case DRM_FORMAT_XRGB8888:
2058 case DRM_FORMAT_ARGB8888:
2059 case DRM_FORMAT_RGBA8888:
2060 case DRM_FORMAT_RGBX8888:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002061 return 32;
2062 default:
2063 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002064 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002065 }
2066}
2067
2068static s32 pixinc(int pixels, u8 ps)
2069{
2070 if (pixels == 1)
2071 return 1;
2072 else if (pixels > 1)
2073 return 1 + (pixels - 1) * ps;
2074 else if (pixels < 0)
2075 return 1 - (-pixels + 1) * ps;
2076 else
2077 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002078 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002079}
2080
Tomi Valkeinen517a8a952017-05-03 14:14:27 +03002081static void calc_offset(u16 screen_width, u16 width,
Laurent Pinchartd11e5c82018-02-11 15:07:34 +02002082 u32 fourcc, bool fieldmode, unsigned int field_offset,
2083 unsigned int *offset0, unsigned int *offset1,
Tomi Valkeinenc4df6e42017-05-15 11:09:25 +03002084 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim,
2085 enum omap_dss_rotation_type rotation_type, u8 rotation)
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302086{
2087 u8 ps;
2088
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002089 ps = color_mode_to_bpp(fourcc) / 8;
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302090
2091 DSSDBG("scrw %d, width %d\n", screen_width, width);
2092
Tomi Valkeinenc4df6e42017-05-15 11:09:25 +03002093 if (rotation_type == OMAP_DSS_ROT_TILER &&
2094 (fourcc == DRM_FORMAT_UYVY || fourcc == DRM_FORMAT_YUYV) &&
2095 drm_rotation_90_or_270(rotation)) {
2096 /*
2097 * HACK: ROW_INC needs to be calculated with TILER units.
2098 * We get such 'screen_width' that multiplying it with the
2099 * YUV422 pixel size gives the correct TILER container width.
2100 * However, 'width' is in pixels and multiplying it with YUV422
2101 * pixel size gives incorrect result. We thus multiply it here
2102 * with 2 to match the 32 bit TILER unit size.
2103 */
2104 width *= 2;
2105 }
2106
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302107 /*
2108 * field 0 = even field = bottom field
2109 * field 1 = odd field = top field
2110 */
Tomi Valkeinen185e23e2017-05-03 15:01:10 +03002111 *offset0 = field_offset * screen_width * ps;
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302112 *offset1 = 0;
Tomi Valkeinen185e23e2017-05-03 15:01:10 +03002113
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302114 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
2115 (fieldmode ? screen_width : 0), ps);
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002116 if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY)
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302117 *pix_inc = pixinc(x_predecim, 2 * ps);
2118 else
2119 *pix_inc = pixinc(x_predecim, ps);
2120}
2121
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302122/*
2123 * This function is used to avoid synclosts in OMAP3, because of some
2124 * undocumented horizontal position and timing related limitations.
2125 */
Tomi Valkeinen465ec132012-10-19 15:40:24 +03002126static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002127 const struct videomode *vm, u16 pos_x,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002128 u16 width, u16 height, u16 out_width, u16 out_height,
2129 bool five_taps)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302130{
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002131 const int ds = DIV_ROUND_UP(height, out_height);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302132 unsigned long nonactive;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302133 static const u8 limits[3] = { 8, 10, 20 };
2134 u64 val, blank;
2135 int i;
2136
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002137 nonactive = vm->hactive + vm->hfront_porch + vm->hsync_len +
2138 vm->hback_porch - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302139
2140 i = 0;
2141 if (out_height < height)
2142 i++;
2143 if (out_width < width)
2144 i++;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002145 blank = div_u64((u64)(vm->hback_porch + vm->hsync_len + vm->hfront_porch) *
Peter Ujfalusi0a30e152016-09-22 14:06:49 +03002146 lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302147 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2148 if (blank <= limits[i])
2149 return -EINVAL;
2150
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002151 /* FIXME add checks for 3-tap filter once the limitations are known */
2152 if (!five_taps)
2153 return 0;
2154
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302155 /*
2156 * Pixel data should be prepared before visible display point starts.
2157 * So, atleast DS-2 lines must have already been fetched by DISPC
2158 * during nonactive - pos_x period.
2159 */
2160 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2161 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002162 val, max(0, ds - 2) * width);
2163 if (val < max(0, ds - 2) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302164 return -EINVAL;
2165
2166 /*
2167 * All lines need to be refilled during the nonactive period of which
2168 * only one line can be loaded during the active period. So, atleast
2169 * DS - 1 lines should be loaded during nonactive period.
2170 */
2171 val = div_u64((u64)nonactive * lclk, pclk);
2172 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002173 val, max(0, ds - 1) * width);
2174 if (val < max(0, ds - 1) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302175 return -EINVAL;
2176
2177 return 0;
2178}
2179
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002180static unsigned long calc_core_clk_five_taps(unsigned long pclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002181 const struct videomode *vm, u16 width,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302182 u16 height, u16 out_width, u16 out_height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002183 u32 fourcc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002184{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302185 u32 core_clk = 0;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302186 u64 tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002187
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302188 if (height <= out_height && width <= out_width)
2189 return (unsigned long) pclk;
2190
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002191 if (height > out_height) {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002192 unsigned int ppl = vm->hactive;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002193
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002194 tmp = (u64)pclk * height * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002195 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302196 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002197
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02002198 if (height > 2 * out_height) {
2199 if (ppl == out_width)
2200 return 0;
2201
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002202 tmp = (u64)pclk * (height - 2 * out_height) * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002203 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302204 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002205 }
2206 }
2207
2208 if (width > out_width) {
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002209 tmp = (u64)pclk * width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002210 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302211 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002212
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002213 if (fourcc == DRM_FORMAT_XRGB8888)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302214 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002215 }
2216
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302217 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002218}
2219
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002220static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302221 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302222{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302223 if (height > out_height && width > out_width)
2224 return pclk * 4;
2225 else
2226 return pclk * 2;
2227}
2228
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002229static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302230 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002231{
2232 unsigned int hf, vf;
2233
2234 /*
2235 * FIXME how to determine the 'A' factor
2236 * for the no downscaling case ?
2237 */
2238
2239 if (width > 3 * out_width)
2240 hf = 4;
2241 else if (width > 2 * out_width)
2242 hf = 3;
2243 else if (width > out_width)
2244 hf = 2;
2245 else
2246 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002247 if (height > out_height)
2248 vf = 2;
2249 else
2250 vf = 1;
2251
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302252 return pclk * vf * hf;
2253}
2254
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002255static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302256 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302257{
Archit Taneja8ba85302012-09-26 17:00:37 +05302258 /*
2259 * If the overlay/writeback is in mem to mem mode, there are no
2260 * downscaling limitations with respect to pixel clock, return 1 as
2261 * required core clock to represent that we have sufficient enough
2262 * core clock to do maximum downscaling
2263 */
2264 if (mem_to_mem)
2265 return 1;
2266
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302267 if (width > out_width)
2268 return DIV_ROUND_UP(pclk, out_width) * width;
2269 else
2270 return pclk;
2271}
2272
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002273static int dispc_ovl_calc_scaling_24xx(struct dispc_device *dispc,
2274 unsigned long pclk, unsigned long lclk,
2275 const struct videomode *vm,
2276 u16 width, u16 height,
2277 u16 out_width, u16 out_height,
2278 u32 fourcc, bool *five_taps,
2279 int *x_predecim, int *y_predecim,
2280 int *decim_x, int *decim_y,
2281 u16 pos_x, unsigned long *core_clk,
2282 bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302283{
2284 int error;
2285 u16 in_width, in_height;
2286 int min_factor = min(*decim_x, *decim_y);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002287 const int maxsinglelinewidth = dispc->feat->max_line_width;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302288
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302289 *five_taps = false;
2290
2291 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002292 in_height = height / *decim_y;
2293 in_width = width / *decim_x;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002294 *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302295 in_height, out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302296 error = (in_width > maxsinglelinewidth || !*core_clk ||
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002297 *core_clk > dispc_core_clk_rate(dispc));
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302298 if (error) {
2299 if (*decim_x == *decim_y) {
2300 *decim_x = min_factor;
2301 ++*decim_y;
2302 } else {
2303 swap(*decim_x, *decim_y);
2304 if (*decim_x < *decim_y)
2305 ++*decim_x;
2306 }
2307 }
2308 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2309
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002310 if (error) {
2311 DSSERR("failed to find scaling settings\n");
2312 return -EINVAL;
2313 }
2314
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302315 if (in_width > maxsinglelinewidth) {
2316 DSSERR("Cannot scale max input width exceeded");
2317 return -EINVAL;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302318 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302319 return 0;
2320}
2321
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002322static int dispc_ovl_calc_scaling_34xx(struct dispc_device *dispc,
2323 unsigned long pclk, unsigned long lclk,
2324 const struct videomode *vm,
2325 u16 width, u16 height,
2326 u16 out_width, u16 out_height,
2327 u32 fourcc, bool *five_taps,
2328 int *x_predecim, int *y_predecim,
2329 int *decim_x, int *decim_y,
2330 u16 pos_x, unsigned long *core_clk,
2331 bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302332{
2333 int error;
2334 u16 in_width, in_height;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002335 const int maxsinglelinewidth = dispc->feat->max_line_width;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302336
2337 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002338 in_height = height / *decim_y;
2339 in_width = width / *decim_x;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002340 *five_taps = in_height > out_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302341
2342 if (in_width > maxsinglelinewidth)
2343 if (in_height > out_height &&
2344 in_height < out_height * 2)
2345 *five_taps = false;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002346again:
2347 if (*five_taps)
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002348 *core_clk = calc_core_clk_five_taps(pclk, vm,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002349 in_width, in_height, out_width,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002350 out_height, fourcc);
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002351 else
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002352 *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302353 in_height, out_width, out_height,
2354 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302355
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002356 error = check_horiz_timing_omap3(pclk, lclk, vm,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002357 pos_x, in_width, in_height, out_width,
2358 out_height, *five_taps);
2359 if (error && *five_taps) {
2360 *five_taps = false;
2361 goto again;
2362 }
2363
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302364 error = (error || in_width > maxsinglelinewidth * 2 ||
2365 (in_width > maxsinglelinewidth && *five_taps) ||
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002366 !*core_clk || *core_clk > dispc_core_clk_rate(dispc));
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002367
2368 if (!error) {
2369 /* verify that we're inside the limits of scaler */
2370 if (in_width / 4 > out_width)
2371 error = 1;
2372
2373 if (*five_taps) {
2374 if (in_height / 4 > out_height)
2375 error = 1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302376 } else {
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002377 if (in_height / 2 > out_height)
2378 error = 1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302379 }
2380 }
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002381
Tomi Valkeinen7059e3d2015-04-10 12:48:38 +03002382 if (error)
2383 ++*decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302384 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2385
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002386 if (error) {
2387 DSSERR("failed to find scaling settings\n");
2388 return -EINVAL;
2389 }
2390
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002391 if (check_horiz_timing_omap3(pclk, lclk, vm, pos_x, in_width,
Tomi Valkeinenf5a73482015-03-17 15:31:09 +02002392 in_height, out_width, out_height, *five_taps)) {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302393 DSSERR("horizontal timing too tight\n");
2394 return -EINVAL;
2395 }
2396
2397 if (in_width > (maxsinglelinewidth * 2)) {
2398 DSSERR("Cannot setup scaling");
2399 DSSERR("width exceeds maximum width possible");
2400 return -EINVAL;
2401 }
2402
2403 if (in_width > maxsinglelinewidth && *five_taps) {
2404 DSSERR("cannot setup scaling with five taps");
2405 return -EINVAL;
2406 }
2407 return 0;
2408}
2409
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002410static int dispc_ovl_calc_scaling_44xx(struct dispc_device *dispc,
2411 unsigned long pclk, unsigned long lclk,
2412 const struct videomode *vm,
2413 u16 width, u16 height,
2414 u16 out_width, u16 out_height,
2415 u32 fourcc, bool *five_taps,
2416 int *x_predecim, int *y_predecim,
2417 int *decim_x, int *decim_y,
2418 u16 pos_x, unsigned long *core_clk,
2419 bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302420{
2421 u16 in_width, in_width_max;
2422 int decim_x_min = *decim_x;
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002423 u16 in_height = height / *decim_y;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002424 const int maxsinglelinewidth = dispc->feat->max_line_width;
2425 const int maxdownscale = dispc->feat->max_downscale;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302426
Archit Taneja5d501082012-11-07 11:45:02 +05302427 if (mem_to_mem) {
2428 in_width_max = out_width * maxdownscale;
2429 } else {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002430 in_width_max = dispc_core_clk_rate(dispc)
2431 / DIV_ROUND_UP(pclk, out_width);
Archit Taneja5d501082012-11-07 11:45:02 +05302432 }
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302433
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302434 *decim_x = DIV_ROUND_UP(width, in_width_max);
2435
2436 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2437 if (*decim_x > *x_predecim)
2438 return -EINVAL;
2439
2440 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002441 in_width = width / *decim_x;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302442 } while (*decim_x <= *x_predecim &&
2443 in_width > maxsinglelinewidth && ++*decim_x);
2444
2445 if (in_width > maxsinglelinewidth) {
2446 DSSERR("Cannot scale width exceeds max line width");
2447 return -EINVAL;
2448 }
2449
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002450 if (*decim_x > 4 && fourcc != DRM_FORMAT_NV12) {
Jyri Sarha1b30ab02017-02-08 16:08:06 +02002451 /*
2452 * Let's disable all scaling that requires horizontal
2453 * decimation with higher factor than 4, until we have
2454 * better estimates of what we can and can not
2455 * do. However, NV12 color format appears to work Ok
2456 * with all decimation factors.
2457 *
2458 * When decimating horizontally by more that 4 the dss
2459 * is not able to fetch the data in burst mode. When
2460 * this happens it is hard to tell if there enough
2461 * bandwidth. Despite what theory says this appears to
2462 * be true also for 16-bit color formats.
2463 */
2464 DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)", *decim_x);
2465
2466 return -EINVAL;
2467 }
2468
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002469 *core_clk = dispc->feat->calc_core_clk(pclk, in_width, in_height,
Archit Taneja8ba85302012-09-26 17:00:37 +05302470 out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302471 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002472}
2473
Tomi Valkeinene4c5ae72015-04-10 12:48:39 +03002474#define DIV_FRAC(dividend, divisor) \
2475 ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2476
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002477static int dispc_ovl_calc_scaling(struct dispc_device *dispc,
2478 unsigned long pclk, unsigned long lclk,
2479 enum omap_overlay_caps caps,
2480 const struct videomode *vm,
2481 u16 width, u16 height,
2482 u16 out_width, u16 out_height,
2483 u32 fourcc, bool *five_taps,
2484 int *x_predecim, int *y_predecim, u16 pos_x,
2485 enum omap_dss_rotation_type rotation_type,
2486 bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302487{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002488 const int maxdownscale = dispc->feat->max_downscale;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302489 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302490 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302491 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302492
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002493 if (width == out_width && height == out_height)
2494 return 0;
2495
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002496 if (!mem_to_mem && (pclk == 0 || vm->pixelclock == 0)) {
Tomi Valkeinen4e1d3ca2014-10-03 15:14:09 +00002497 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2498 return -EINVAL;
2499 }
2500
Archit Taneja5b54ed32012-09-26 16:55:27 +05302501 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002502 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302503
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002504 if (mem_to_mem) {
Archit Taneja1c031442012-11-07 11:45:03 +05302505 *x_predecim = *y_predecim = 1;
2506 } else {
2507 *x_predecim = max_decim_limit;
2508 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002509 dispc_has_feature(dispc, FEAT_BURST_2D)) ?
Archit Taneja1c031442012-11-07 11:45:03 +05302510 2 : max_decim_limit;
2511 }
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302512
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302513 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2514 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2515
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302516 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302517 return -EINVAL;
2518
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302519 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302520 return -EINVAL;
2521
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002522 ret = dispc->feat->calc_scaling(dispc, pclk, lclk, vm, width, height,
2523 out_width, out_height, fourcc,
2524 five_taps, x_predecim, y_predecim,
2525 &decim_x, &decim_y, pos_x, &core_clk,
2526 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302527 if (ret)
2528 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302529
Tomi Valkeinene4c5ae72015-04-10 12:48:39 +03002530 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",
2531 width, height,
2532 out_width, out_height,
2533 out_width / width, DIV_FRAC(out_width, width),
2534 out_height / height, DIV_FRAC(out_height, height),
2535
2536 decim_x, decim_y,
2537 width / decim_x, height / decim_y,
2538 out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
2539 out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
2540
2541 *five_taps ? 5 : 3,
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002542 core_clk, dispc_core_clk_rate(dispc));
Archit Taneja79ad75f2011-09-08 13:15:11 +05302543
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002544 if (!core_clk || core_clk > dispc_core_clk_rate(dispc)) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302545 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302546 "required core clk rate = %lu Hz, "
2547 "current core clk rate = %lu Hz\n",
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002548 core_clk, dispc_core_clk_rate(dispc));
Archit Taneja79ad75f2011-09-08 13:15:11 +05302549 return -EINVAL;
2550 }
2551
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302552 *x_predecim = decim_x;
2553 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302554 return 0;
2555}
2556
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002557static int dispc_ovl_setup_common(struct dispc_device *dispc,
2558 enum omap_plane_id plane,
2559 enum omap_overlay_caps caps,
2560 u32 paddr, u32 p_uv_addr,
2561 u16 screen_width, int pos_x, int pos_y,
2562 u16 width, u16 height,
2563 u16 out_width, u16 out_height,
2564 u32 fourcc, u8 rotation, u8 zorder,
2565 u8 pre_mult_alpha, u8 global_alpha,
2566 enum omap_dss_rotation_type rotation_type,
2567 bool replication, const struct videomode *vm,
2568 bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002569{
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302570 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002571 bool fieldmode = false;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302572 int r, cconv = 0;
Laurent Pinchartd11e5c82018-02-11 15:07:34 +02002573 unsigned int offset0, offset1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002574 s32 row_inc;
2575 s32 pix_inc;
Archit Taneja6be0d732012-11-07 11:45:04 +05302576 u16 frame_width, frame_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002577 unsigned int field_offset = 0;
Archit Taneja84a880f2012-09-26 16:57:37 +05302578 u16 in_height = height;
2579 u16 in_width = width;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302580 int x_predecim = 1, y_predecim = 1;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002581 bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002582 unsigned long pclk = dispc_plane_pclk_rate(dispc, plane);
2583 unsigned long lclk = dispc_plane_lclk_rate(dispc, plane);
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002584
Benoit Parrot9deb5ad2016-05-16 16:42:50 -05002585 /* when setting up WB, dispc_plane_pclk_rate() returns 0 */
2586 if (plane == OMAP_DSS_WB)
2587 pclk = vm->pixelclock;
2588
Tomi Valkeinene5666582014-11-28 14:34:15 +02002589 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002590 return -EINVAL;
2591
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002592 if (format_is_yuv(fourcc) && (in_width & 1)) {
Tomi Valkeinen5edec142017-05-04 09:13:32 +03002593 DSSERR("input width %d is not even for YUV format\n", in_width);
2594 return -EINVAL;
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002595 }
2596
Archit Taneja84a880f2012-09-26 16:57:37 +05302597 out_width = out_width == 0 ? width : out_width;
2598 out_height = out_height == 0 ? height : out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002599
Archit Taneja84a880f2012-09-26 16:57:37 +05302600 if (ilace && height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002601 fieldmode = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002602
2603 if (ilace) {
2604 if (fieldmode)
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302605 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302606 pos_y /= 2;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302607 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002608
2609 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
Archit Taneja84a880f2012-09-26 16:57:37 +05302610 "out_height %d\n", in_height, pos_y,
2611 out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002612 }
2613
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002614 if (!dispc_ovl_color_mode_supported(dispc, plane, fourcc))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302615 return -EINVAL;
2616
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002617 r = dispc_ovl_calc_scaling(dispc, pclk, lclk, caps, vm, in_width,
2618 in_height, out_width, out_height, fourcc,
2619 &five_taps, &x_predecim, &y_predecim, pos_x,
2620 rotation_type, mem_to_mem);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302621 if (r)
2622 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002623
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002624 in_width = in_width / x_predecim;
2625 in_height = in_height / y_predecim;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302626
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002627 if (x_predecim > 1 || y_predecim > 1)
2628 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2629 x_predecim, y_predecim, in_width, in_height);
2630
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002631 if (format_is_yuv(fourcc) && (in_width & 1)) {
Tomi Valkeinen5edec142017-05-04 09:13:32 +03002632 DSSDBG("predecimated input width is not even for YUV format\n");
2633 DSSDBG("adjusting input width %d -> %d\n",
2634 in_width, in_width & ~1);
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002635
Tomi Valkeinen5edec142017-05-04 09:13:32 +03002636 in_width &= ~1;
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002637 }
2638
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002639 if (format_is_yuv(fourcc))
Archit Taneja79ad75f2011-09-08 13:15:11 +05302640 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002641
2642 if (ilace && !fieldmode) {
2643 /*
2644 * when downscaling the bottom field may have to start several
2645 * source lines below the top field. Unfortunately ACCUI
2646 * registers will only hold the fractional part of the offset
2647 * so the integer part must be added to the base address of the
2648 * bottom field.
2649 */
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302650 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002651 field_offset = 0;
2652 else
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302653 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002654 }
2655
2656 /* Fields are independent but interleaved in memory. */
2657 if (fieldmode)
2658 field_offset = 1;
2659
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002660 offset0 = 0;
2661 offset1 = 0;
2662 row_inc = 0;
2663 pix_inc = 0;
2664
Archit Taneja6be0d732012-11-07 11:45:04 +05302665 if (plane == OMAP_DSS_WB) {
2666 frame_width = out_width;
2667 frame_height = out_height;
2668 } else {
2669 frame_width = in_width;
2670 frame_height = height;
2671 }
2672
Tomi Valkeinen517a8a952017-05-03 14:14:27 +03002673 calc_offset(screen_width, frame_width,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002674 fourcc, fieldmode, field_offset,
Tomi Valkeinen517a8a952017-05-03 14:14:27 +03002675 &offset0, &offset1, &row_inc, &pix_inc,
Tomi Valkeinenc4df6e42017-05-15 11:09:25 +03002676 x_predecim, y_predecim,
2677 rotation_type, rotation);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002678
2679 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2680 offset0, offset1, row_inc, pix_inc);
2681
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002682 dispc_ovl_set_color_mode(dispc, plane, fourcc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002683
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002684 dispc_ovl_configure_burst_type(dispc, plane, rotation_type);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302685
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002686 if (dispc->feat->reverse_ilace_field_order)
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02002687 swap(offset0, offset1);
2688
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002689 dispc_ovl_set_ba0(dispc, plane, paddr + offset0);
2690 dispc_ovl_set_ba1(dispc, plane, paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002691
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002692 if (fourcc == DRM_FORMAT_NV12) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002693 dispc_ovl_set_ba0_uv(dispc, plane, p_uv_addr + offset0);
2694 dispc_ovl_set_ba1_uv(dispc, plane, p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302695 }
2696
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002697 if (dispc->feat->last_pixel_inc_missing)
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03002698 row_inc += pix_inc - 1;
2699
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002700 dispc_ovl_set_row_inc(dispc, plane, row_inc);
2701 dispc_ovl_set_pix_inc(dispc, plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002702
Archit Taneja84a880f2012-09-26 16:57:37 +05302703 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302704 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002705
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002706 dispc_ovl_set_pos(dispc, plane, caps, pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002707
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002708 dispc_ovl_set_input_size(dispc, plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002709
Archit Taneja5b54ed32012-09-26 16:55:27 +05302710 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002711 dispc_ovl_set_scaling(dispc, plane, in_width, in_height,
2712 out_width, out_height, ilace, five_taps,
2713 fieldmode, fourcc, rotation);
2714 dispc_ovl_set_output_size(dispc, plane, out_width, out_height);
2715 dispc_ovl_set_vid_color_conv(dispc, plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002716 }
2717
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002718 dispc_ovl_set_rotation_attrs(dispc, plane, rotation, rotation_type,
2719 fourcc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002720
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002721 dispc_ovl_set_zorder(dispc, plane, caps, zorder);
2722 dispc_ovl_set_pre_mult_alpha(dispc, plane, caps, pre_mult_alpha);
2723 dispc_ovl_setup_global_alpha(dispc, plane, caps, global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002724
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002725 dispc_ovl_enable_replication(dispc, plane, caps, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302726
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002727 return 0;
2728}
2729
Laurent Pinchart50638ae2018-02-13 14:00:42 +02002730static int dispc_ovl_setup(struct dispc_device *dispc,
2731 enum omap_plane_id plane,
2732 const struct omap_overlay_info *oi,
2733 const struct videomode *vm, bool mem_to_mem,
2734 enum omap_channel channel)
Archit Taneja84a880f2012-09-26 16:57:37 +05302735{
2736 int r;
Laurent Pinchart50638ae2018-02-13 14:00:42 +02002737 enum omap_overlay_caps caps = dispc->feat->overlay_caps[plane];
Tomi Valkeinenbe2d68c2016-08-29 13:15:02 +03002738 const bool replication = true;
Archit Taneja84a880f2012-09-26 16:57:37 +05302739
Arnd Bergmann24f13a62014-04-24 13:28:18 +01002740 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002741 " %dx%d, cmode %x, rot %d, chan %d repl %d\n",
Arnd Bergmann24f13a62014-04-24 13:28:18 +01002742 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
Archit Taneja84a880f2012-09-26 16:57:37 +05302743 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002744 oi->fourcc, oi->rotation, channel, replication);
Archit Taneja84a880f2012-09-26 16:57:37 +05302745
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002746 dispc_ovl_set_channel_out(dispc, plane, channel);
Tomi Valkeinen49a30572017-02-17 12:30:07 +02002747
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002748 r = dispc_ovl_setup_common(dispc, plane, caps, oi->paddr, oi->p_uv_addr,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302749 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002750 oi->out_width, oi->out_height, oi->fourcc, oi->rotation,
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002751 oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002752 oi->rotation_type, replication, vm, mem_to_mem);
Archit Taneja84a880f2012-09-26 16:57:37 +05302753
2754 return r;
2755}
2756
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02002757int dispc_wb_setup(struct dispc_device *dispc,
2758 const struct omap_dss_writeback_info *wi,
Tomi Valkeinen9f7853a2018-01-09 15:36:47 +02002759 bool mem_to_mem, const struct videomode *vm,
2760 enum dss_writeback_channel channel_in)
Archit Taneja749feff2012-08-31 12:32:52 +05302761{
2762 int r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302763 u32 l;
Jyri Sarha864050c2017-03-24 16:47:52 +02002764 enum omap_plane_id plane = OMAP_DSS_WB;
Archit Taneja749feff2012-08-31 12:32:52 +05302765 const int pos_x = 0, pos_y = 0;
2766 const u8 zorder = 0, global_alpha = 0;
Tomi Valkeinenbe2d68c2016-08-29 13:15:02 +03002767 const bool replication = true;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302768 bool truncation;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002769 int in_width = vm->hactive;
2770 int in_height = vm->vactive;
Archit Taneja749feff2012-08-31 12:32:52 +05302771 enum omap_overlay_caps caps =
2772 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2773
2774 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002775 "rot %d\n", wi->paddr, wi->p_uv_addr, in_width,
2776 in_height, wi->width, wi->height, wi->fourcc, wi->rotation);
Archit Taneja749feff2012-08-31 12:32:52 +05302777
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002778 r = dispc_ovl_setup_common(dispc, plane, caps, wi->paddr, wi->p_uv_addr,
Archit Taneja749feff2012-08-31 12:32:52 +05302779 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
Tomi Valkeinen4eebb802017-05-16 12:05:24 +03002780 wi->height, wi->fourcc, wi->rotation, zorder,
Archit Taneja749feff2012-08-31 12:32:52 +05302781 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002782 replication, vm, mem_to_mem);
Benoit Parrotb5d025e2016-06-22 12:59:50 -05002783 if (r)
2784 return r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302785
Tomi Valkeinen41aff422017-05-04 11:31:56 +03002786 switch (wi->fourcc) {
Tomi Valkeinen3e1d65c2017-05-04 10:40:46 +03002787 case DRM_FORMAT_RGB565:
2788 case DRM_FORMAT_RGB888:
2789 case DRM_FORMAT_ARGB4444:
2790 case DRM_FORMAT_RGBA4444:
2791 case DRM_FORMAT_RGBX4444:
2792 case DRM_FORMAT_ARGB1555:
2793 case DRM_FORMAT_XRGB1555:
2794 case DRM_FORMAT_XRGB4444:
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302795 truncation = true;
2796 break;
2797 default:
2798 truncation = false;
2799 break;
2800 }
2801
2802 /* setup extra DISPC_WB_ATTRIBUTES */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002803 l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302804 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
Tomi Valkeinen9f7853a2018-01-09 15:36:47 +02002805 l = FLD_MOD(l, channel_in, 18, 16); /* CHANNELIN */
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302806 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
Tomi Valkeinen4c055ce2015-11-04 17:10:53 +02002807 if (mem_to_mem)
2808 l = FLD_MOD(l, 1, 26, 24); /* CAPTUREMODE */
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002809 else
2810 l = FLD_MOD(l, 0, 26, 24); /* CAPTUREMODE */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002811 dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
Archit Taneja749feff2012-08-31 12:32:52 +05302812
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002813 if (mem_to_mem) {
2814 /* WBDELAYCOUNT */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002815 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0);
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002816 } else {
Tomi Valkeinenb994e532017-10-26 14:40:12 +03002817 u32 wbdelay;
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002818
Tomi Valkeinen46a93042016-06-03 13:29:59 +03002819 if (channel_in == DSS_WB_TV_MGR)
Tomi Valkeinenb994e532017-10-26 14:40:12 +03002820 wbdelay = vm->vsync_len + vm->vback_porch;
Tomi Valkeinen46a93042016-06-03 13:29:59 +03002821 else
Tomi Valkeinenb994e532017-10-26 14:40:12 +03002822 wbdelay = vm->vfront_porch + vm->vsync_len +
2823 vm->vback_porch;
2824
2825 if (vm->flags & DISPLAY_FLAGS_INTERLACED)
2826 wbdelay /= 2;
2827
2828 wbdelay = min(wbdelay, 255u);
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002829
2830 /* WBDELAYCOUNT */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002831 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0);
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002832 }
2833
Benoit Parrotb5d025e2016-06-22 12:59:50 -05002834 return 0;
Archit Taneja749feff2012-08-31 12:32:52 +05302835}
2836
Laurent Pinchart50638ae2018-02-13 14:00:42 +02002837static int dispc_ovl_enable(struct dispc_device *dispc,
2838 enum omap_plane_id plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002839{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002840 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2841
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002842 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002843
2844 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002845}
2846
Laurent Pinchart50638ae2018-02-13 14:00:42 +02002847static enum omap_dss_output_id
2848dispc_mgr_get_supported_outputs(struct dispc_device *dispc,
2849 enum omap_channel channel)
Tomi Valkeinen7b9cb5e2015-11-04 15:11:25 +02002850{
Laurent Pinchart50638ae2018-02-13 14:00:42 +02002851 return dss_get_supported_outputs(dispc->dss, channel);
Tomi Valkeinen7b9cb5e2015-11-04 15:11:25 +02002852}
Tomi Valkeinen7b9cb5e2015-11-04 15:11:25 +02002853
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002854static void dispc_lcd_enable_signal_polarity(struct dispc_device *dispc,
2855 bool act_high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002856{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002857 if (!dispc_has_feature(dispc, FEAT_LCDENABLEPOL))
Archit Taneja6ced40b2010-12-02 11:27:13 +00002858 return;
2859
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002860 REG_FLD_MOD(dispc, DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002861}
2862
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02002863void dispc_lcd_enable_signal(struct dispc_device *dispc, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002864{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002865 if (!dispc_has_feature(dispc, FEAT_LCDENABLESIGNAL))
Archit Taneja6ced40b2010-12-02 11:27:13 +00002866 return;
2867
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002868 REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002869}
2870
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02002871void dispc_pck_free_enable(struct dispc_device *dispc, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002872{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002873 if (!dispc_has_feature(dispc, FEAT_PCKFREEENABLE))
Archit Taneja6ced40b2010-12-02 11:27:13 +00002874 return;
2875
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002876 REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002877}
2878
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002879static void dispc_mgr_enable_fifohandcheck(struct dispc_device *dispc,
2880 enum omap_channel channel,
2881 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002882{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002883 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002884}
2885
2886
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002887static void dispc_mgr_set_lcd_type_tft(struct dispc_device *dispc,
2888 enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002889{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002890 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002891}
2892
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002893static void dispc_set_loadmode(struct dispc_device *dispc,
2894 enum omap_dss_load_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002895{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002896 REG_FLD_MOD(dispc, DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002897}
2898
2899
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002900static void dispc_mgr_set_default_color(struct dispc_device *dispc,
2901 enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002902{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002903 dispc_write_reg(dispc, DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002904}
2905
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002906static void dispc_mgr_set_trans_key(struct dispc_device *dispc,
2907 enum omap_channel ch,
2908 enum omap_dss_trans_key_type type,
2909 u32 trans_key)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002910{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002911 mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002912
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002913 dispc_write_reg(dispc, DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002914}
2915
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002916static void dispc_mgr_enable_trans_key(struct dispc_device *dispc,
2917 enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002918{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002919 mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002920}
Archit Taneja11354dd2011-09-26 11:47:29 +05302921
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002922static void dispc_mgr_enable_alpha_fixed_zorder(struct dispc_device *dispc,
2923 enum omap_channel ch,
2924 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002925{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002926 if (!dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002927 return;
2928
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002929 if (ch == OMAP_DSS_CHANNEL_LCD)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002930 REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002931 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002932 REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002933}
Archit Taneja11354dd2011-09-26 11:47:29 +05302934
Laurent Pinchart50638ae2018-02-13 14:00:42 +02002935static void dispc_mgr_setup(struct dispc_device *dispc,
2936 enum omap_channel channel,
2937 const struct omap_overlay_manager_info *info)
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002938{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002939 dispc_mgr_set_default_color(dispc, channel, info->default_color);
2940 dispc_mgr_set_trans_key(dispc, channel, info->trans_key_type,
2941 info->trans_key);
2942 dispc_mgr_enable_trans_key(dispc, channel, info->trans_enabled);
2943 dispc_mgr_enable_alpha_fixed_zorder(dispc, channel,
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002944 info->partial_alpha_enabled);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002945 if (dispc_has_feature(dispc, FEAT_CPR)) {
2946 dispc_mgr_enable_cpr(dispc, channel, info->cpr_enable);
2947 dispc_mgr_set_cpr_coef(dispc, channel, &info->cpr_coefs);
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002948 }
2949}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002950
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002951static void dispc_mgr_set_tft_data_lines(struct dispc_device *dispc,
2952 enum omap_channel channel,
2953 u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002954{
2955 int code;
2956
2957 switch (data_lines) {
2958 case 12:
2959 code = 0;
2960 break;
2961 case 16:
2962 code = 1;
2963 break;
2964 case 18:
2965 code = 2;
2966 break;
2967 case 24:
2968 code = 3;
2969 break;
2970 default:
2971 BUG();
2972 return;
2973 }
2974
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002975 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002976}
2977
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02002978static void dispc_mgr_set_io_pad_mode(struct dispc_device *dispc,
2979 enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002980{
2981 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302982 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002983
2984 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302985 case DSS_IO_PAD_MODE_RESET:
2986 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002987 gpout1 = 0;
2988 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302989 case DSS_IO_PAD_MODE_RFBI:
2990 gpout0 = 1;
2991 gpout1 = 0;
2992 break;
2993 case DSS_IO_PAD_MODE_BYPASS:
2994 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002995 gpout1 = 1;
2996 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002997 default:
2998 BUG();
2999 return;
3000 }
3001
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003002 l = dispc_read_reg(dispc, DISPC_CONTROL);
Archit Taneja569969d2011-08-22 17:41:57 +05303003 l = FLD_MOD(l, gpout0, 15, 15);
3004 l = FLD_MOD(l, gpout1, 16, 16);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003005 dispc_write_reg(dispc, DISPC_CONTROL, l);
Archit Taneja569969d2011-08-22 17:41:57 +05303006}
3007
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003008static void dispc_mgr_enable_stallmode(struct dispc_device *dispc,
3009 enum omap_channel channel, bool enable)
Archit Taneja569969d2011-08-22 17:41:57 +05303010{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003011 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003012}
3013
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003014static void dispc_mgr_set_lcd_config(struct dispc_device *dispc,
3015 enum omap_channel channel,
3016 const struct dss_lcd_mgr_config *config)
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003017{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003018 dispc_mgr_set_io_pad_mode(dispc, config->io_pad_mode);
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003019
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003020 dispc_mgr_enable_stallmode(dispc, channel, config->stallmode);
3021 dispc_mgr_enable_fifohandcheck(dispc, channel, config->fifohandcheck);
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003022
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003023 dispc_mgr_set_clock_div(dispc, channel, &config->clock_info);
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003024
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003025 dispc_mgr_set_tft_data_lines(dispc, channel, config->video_port_width);
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003026
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003027 dispc_lcd_enable_signal_polarity(dispc, config->lcden_sig_polarity);
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003028
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003029 dispc_mgr_set_lcd_type_tft(dispc, channel);
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003030}
3031
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003032static bool _dispc_mgr_size_ok(struct dispc_device *dispc,
3033 u16 width, u16 height)
Archit Taneja8f366162012-04-16 12:53:44 +05303034{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003035 return width <= dispc->feat->mgr_width_max &&
3036 height <= dispc->feat->mgr_height_max;
Archit Taneja8f366162012-04-16 12:53:44 +05303037}
3038
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003039static bool _dispc_lcd_timings_ok(struct dispc_device *dispc,
3040 int hsync_len, int hfp, int hbp,
3041 int vsw, int vfp, int vbp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003042{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003043 if (hsync_len < 1 || hsync_len > dispc->feat->sw_max ||
3044 hfp < 1 || hfp > dispc->feat->hp_max ||
3045 hbp < 1 || hbp > dispc->feat->hp_max ||
3046 vsw < 1 || vsw > dispc->feat->sw_max ||
3047 vfp < 0 || vfp > dispc->feat->vp_max ||
3048 vbp < 0 || vbp > dispc->feat->vp_max)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303049 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003050 return true;
3051}
3052
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003053static bool _dispc_mgr_pclk_ok(struct dispc_device *dispc,
3054 enum omap_channel channel,
3055 unsigned long pclk)
Archit Tanejaca5ca692013-03-26 19:15:22 +05303056{
3057 if (dss_mgr_is_lcd(channel))
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003058 return pclk <= dispc->feat->max_lcd_pclk;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303059 else
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003060 return pclk <= dispc->feat->max_tv_pclk;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303061}
3062
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003063bool dispc_mgr_timings_ok(struct dispc_device *dispc, enum omap_channel channel,
3064 const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003065{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003066 if (!_dispc_mgr_size_ok(dispc, vm->hactive, vm->vactive))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003067 return false;
Archit Taneja8f366162012-04-16 12:53:44 +05303068
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003069 if (!_dispc_mgr_pclk_ok(dispc, channel, vm->pixelclock))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003070 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303071
3072 if (dss_mgr_is_lcd(channel)) {
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03003073 /* TODO: OMAP4+ supports interlace for LCD outputs */
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003074 if (vm->flags & DISPLAY_FLAGS_INTERLACED)
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003075 return false;
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03003076
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003077 if (!_dispc_lcd_timings_ok(dispc, vm->hsync_len,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003078 vm->hfront_porch, vm->hback_porch,
3079 vm->vsync_len, vm->vfront_porch,
3080 vm->vback_porch))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003081 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303082 }
Archit Taneja8f366162012-04-16 12:53:44 +05303083
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003084 return true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003085}
3086
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003087static void _dispc_mgr_set_lcd_timings(struct dispc_device *dispc,
3088 enum omap_channel channel,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003089 const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003090{
Archit Taneja655e2942012-06-21 10:37:43 +05303091 u32 timing_h, timing_v, l;
Tomi Valkeinened351882014-10-02 17:58:49 +00003092 bool onoff, rf, ipc, vs, hs, de;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003093
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003094 timing_h = FLD_VAL(vm->hsync_len - 1, dispc->feat->sw_start, 0) |
3095 FLD_VAL(vm->hfront_porch - 1, dispc->feat->fp_start, 8) |
3096 FLD_VAL(vm->hback_porch - 1, dispc->feat->bp_start, 20);
3097 timing_v = FLD_VAL(vm->vsync_len - 1, dispc->feat->sw_start, 0) |
3098 FLD_VAL(vm->vfront_porch, dispc->feat->fp_start, 8) |
3099 FLD_VAL(vm->vback_porch, dispc->feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003100
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003101 dispc_write_reg(dispc, DISPC_TIMING_H(channel), timing_h);
3102 dispc_write_reg(dispc, DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05303103
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003104 if (vm->flags & DISPLAY_FLAGS_VSYNC_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00003105 vs = false;
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03003106 else
3107 vs = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00003108
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003109 if (vm->flags & DISPLAY_FLAGS_HSYNC_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00003110 hs = false;
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03003111 else
3112 hs = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00003113
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003114 if (vm->flags & DISPLAY_FLAGS_DE_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00003115 de = false;
Peter Ujfalusi3fa3ab42016-09-22 14:06:58 +03003116 else
3117 de = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00003118
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003119 if (vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
Archit Taneja655e2942012-06-21 10:37:43 +05303120 ipc = false;
Peter Ujfalusif149e172016-09-22 14:07:00 +03003121 else
Archit Taneja655e2942012-06-21 10:37:43 +05303122 ipc = true;
Archit Taneja655e2942012-06-21 10:37:43 +05303123
Tomi Valkeinen7a163602014-10-02 17:58:48 +00003124 /* always use the 'rf' setting */
3125 onoff = true;
3126
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003127 if (vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE)
Archit Taneja655e2942012-06-21 10:37:43 +05303128 rf = true;
Peter Ujfalusid34afb72016-09-22 14:07:01 +03003129 else
3130 rf = false;
Archit Taneja655e2942012-06-21 10:37:43 +05303131
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003132 l = FLD_VAL(onoff, 17, 17) |
3133 FLD_VAL(rf, 16, 16) |
Tomi Valkeinened351882014-10-02 17:58:49 +00003134 FLD_VAL(de, 15, 15) |
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003135 FLD_VAL(ipc, 14, 14) |
Tomi Valkeinened351882014-10-02 17:58:49 +00003136 FLD_VAL(hs, 13, 13) |
3137 FLD_VAL(vs, 12, 12);
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003138
Tomi Valkeinene5f80912015-10-21 13:08:59 +03003139 /* always set ALIGN bit when available */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003140 if (dispc->feat->supports_sync_align)
Tomi Valkeinene5f80912015-10-21 13:08:59 +03003141 l |= (1 << 18);
3142
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003143 dispc_write_reg(dispc, DISPC_POL_FREQ(channel), l);
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003144
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003145 if (dispc->syscon_pol) {
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003146 const int shifts[] = {
3147 [OMAP_DSS_CHANNEL_LCD] = 0,
3148 [OMAP_DSS_CHANNEL_LCD2] = 1,
3149 [OMAP_DSS_CHANNEL_LCD3] = 2,
3150 };
3151
3152 u32 mask, val;
3153
3154 mask = (1 << 0) | (1 << 3) | (1 << 6);
3155 val = (rf << 0) | (ipc << 3) | (onoff << 6);
3156
3157 mask <<= 16 + shifts[channel];
3158 val <<= 16 + shifts[channel];
3159
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003160 regmap_update_bits(dispc->syscon_pol, dispc->syscon_pol_offset,
3161 mask, val);
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003162 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003163}
3164
Tomi Valkeinen956d4f92016-11-23 13:23:42 +02003165static int vm_flag_to_int(enum display_flags flags, enum display_flags high,
3166 enum display_flags low)
3167{
3168 if (flags & high)
3169 return 1;
3170 if (flags & low)
3171 return -1;
3172 return 0;
3173}
3174
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003175/* change name to mode? */
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003176static void dispc_mgr_set_timings(struct dispc_device *dispc,
3177 enum omap_channel channel,
3178 const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003179{
Laurent Pinchartd11e5c82018-02-11 15:07:34 +02003180 unsigned int xtot, ytot;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003181 unsigned long ht, vt;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003182 struct videomode t = *vm;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003183
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03003184 DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive);
Archit Tanejac51d9212012-04-16 12:53:43 +05303185
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003186 if (!dispc_mgr_timings_ok(dispc, channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05303187 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003188 return;
3189 }
Archit Tanejac51d9212012-04-16 12:53:43 +05303190
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303191 if (dss_mgr_is_lcd(channel)) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003192 _dispc_mgr_set_lcd_timings(dispc, channel, &t);
Archit Tanejac51d9212012-04-16 12:53:43 +05303193
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03003194 xtot = t.hactive + t.hfront_porch + t.hsync_len + t.hback_porch;
Peter Ujfalusi458540c2016-09-22 14:06:53 +03003195 ytot = t.vactive + t.vfront_porch + t.vsync_len + t.vback_porch;
Archit Tanejac51d9212012-04-16 12:53:43 +05303196
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003197 ht = vm->pixelclock / xtot;
3198 vt = vm->pixelclock / xtot / ytot;
Archit Tanejac51d9212012-04-16 12:53:43 +05303199
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003200 DSSDBG("pck %lu\n", vm->pixelclock);
Peter Ujfalusi4dc22502016-09-22 14:06:48 +03003201 DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03003202 t.hsync_len, t.hfront_porch, t.hback_porch,
Peter Ujfalusi458540c2016-09-22 14:06:53 +03003203 t.vsync_len, t.vfront_porch, t.vback_porch);
Archit Taneja655e2942012-06-21 10:37:43 +05303204 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 +02003205 vm_flag_to_int(t.flags, DISPLAY_FLAGS_VSYNC_HIGH, DISPLAY_FLAGS_VSYNC_LOW),
3206 vm_flag_to_int(t.flags, DISPLAY_FLAGS_HSYNC_HIGH, DISPLAY_FLAGS_HSYNC_LOW),
3207 vm_flag_to_int(t.flags, DISPLAY_FLAGS_PIXDATA_POSEDGE, DISPLAY_FLAGS_PIXDATA_NEGEDGE),
3208 vm_flag_to_int(t.flags, DISPLAY_FLAGS_DE_HIGH, DISPLAY_FLAGS_DE_LOW),
3209 vm_flag_to_int(t.flags, DISPLAY_FLAGS_SYNC_POSEDGE, DISPLAY_FLAGS_SYNC_NEGEDGE));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003210
Archit Tanejac51d9212012-04-16 12:53:43 +05303211 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05303212 } else {
Peter Ujfalusi53058292016-09-22 14:06:55 +03003213 if (t.flags & DISPLAY_FLAGS_INTERLACED)
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03003214 t.vactive /= 2;
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02003215
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003216 if (dispc->feat->supports_double_pixel)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003217 REG_FLD_MOD(dispc, DISPC_CONTROL,
Peter Ujfalusi531efb32016-09-22 14:06:59 +03003218 !!(t.flags & DISPLAY_FLAGS_DOUBLECLK),
3219 19, 17);
Archit Tanejac51d9212012-04-16 12:53:43 +05303220 }
Archit Taneja8f366162012-04-16 12:53:44 +05303221
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003222 dispc_mgr_set_size(dispc, channel, t.hactive, t.vactive);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003223}
3224
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003225static void dispc_mgr_set_lcd_divisor(struct dispc_device *dispc,
3226 enum omap_channel channel, u16 lck_div,
3227 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003228{
3229 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003230 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003231
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003232 dispc_write_reg(dispc, DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003233 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003234
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003235 if (!dispc_has_feature(dispc, FEAT_CORE_CLK_DIV) &&
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003236 channel == OMAP_DSS_CHANNEL_LCD)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003237 dispc->core_clk_rate = dispc_fclk_rate(dispc) / lck_div;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003238}
3239
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003240static void dispc_mgr_get_lcd_divisor(struct dispc_device *dispc,
3241 enum omap_channel channel, int *lck_div,
3242 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003243{
3244 u32 l;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003245 l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003246 *lck_div = FLD_GET(l, 23, 16);
3247 *pck_div = FLD_GET(l, 7, 0);
3248}
3249
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003250static unsigned long dispc_fclk_rate(struct dispc_device *dispc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003251{
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003252 unsigned long r;
3253 enum dss_clk_source src;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003254
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003255 src = dss_get_dispc_clk_source(dispc->dss);
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003256
3257 if (src == DSS_CLK_SRC_FCK) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003258 r = dss_get_dispc_clk_rate(dispc->dss);
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003259 } else {
3260 struct dss_pll *pll;
Laurent Pinchartd11e5c82018-02-11 15:07:34 +02003261 unsigned int clkout_idx;
Tomi Valkeinen93550922014-12-31 11:25:48 +02003262
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003263 pll = dss_pll_find_by_src(dispc->dss, src);
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003264 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
Tomi Valkeinen93550922014-12-31 11:25:48 +02003265
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003266 r = pll->cinfo.clkout[clkout_idx];
Taneja, Archit66534e82011-03-08 05:50:34 -06003267 }
3268
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003269 return r;
3270}
3271
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003272static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
3273 enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003274{
3275 int lcd;
3276 unsigned long r;
Tomi Valkeinen01575772016-05-17 16:08:34 +03003277 enum dss_clk_source src;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003278
Tomi Valkeinen01575772016-05-17 16:08:34 +03003279 /* for TV, LCLK rate is the FCLK rate */
3280 if (!dss_mgr_is_lcd(channel))
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003281 return dispc_fclk_rate(dispc);
Tomi Valkeinen01575772016-05-17 16:08:34 +03003282
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003283 src = dss_get_lcd_clk_source(dispc->dss, channel);
Tomi Valkeinen01575772016-05-17 16:08:34 +03003284
3285 if (src == DSS_CLK_SRC_FCK) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003286 r = dss_get_dispc_clk_rate(dispc->dss);
Tomi Valkeinen01575772016-05-17 16:08:34 +03003287 } else {
3288 struct dss_pll *pll;
Laurent Pinchartd11e5c82018-02-11 15:07:34 +02003289 unsigned int clkout_idx;
Tomi Valkeinen01575772016-05-17 16:08:34 +03003290
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003291 pll = dss_pll_find_by_src(dispc->dss, src);
Tomi Valkeinen01575772016-05-17 16:08:34 +03003292 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
3293
3294 r = pll->cinfo.clkout[clkout_idx];
Taneja, Architea751592011-03-08 05:50:35 -06003295 }
Tomi Valkeinen01575772016-05-17 16:08:34 +03003296
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003297 lcd = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
Tomi Valkeinen01575772016-05-17 16:08:34 +03003298
3299 return r / lcd;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003300}
3301
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003302static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
3303 enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003304{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003305 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003306
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303307 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303308 int pcd;
3309 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003310
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003311 l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003312
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303313 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003314
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003315 r = dispc_mgr_lclk_rate(dispc, channel);
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303316
3317 return r / pcd;
3318 } else {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003319 return dispc->tv_pclk_rate;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303320 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003321}
3322
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003323void dispc_set_tv_pclk(struct dispc_device *dispc, unsigned long pclk)
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003324{
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003325 dispc->tv_pclk_rate = pclk;
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003326}
3327
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003328static unsigned long dispc_core_clk_rate(struct dispc_device *dispc)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303329{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003330 return dispc->core_clk_rate;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303331}
3332
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003333static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
3334 enum omap_plane_id plane)
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303335{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003336 enum omap_channel channel;
3337
3338 if (plane == OMAP_DSS_WB)
3339 return 0;
3340
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003341 channel = dispc_ovl_get_channel_out(dispc, plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303342
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003343 return dispc_mgr_pclk_rate(dispc, channel);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303344}
3345
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003346static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
3347 enum omap_plane_id plane)
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303348{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003349 enum omap_channel channel;
3350
3351 if (plane == OMAP_DSS_WB)
3352 return 0;
3353
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003354 channel = dispc_ovl_get_channel_out(dispc, plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303355
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003356 return dispc_mgr_lclk_rate(dispc, channel);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303357}
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003358
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003359static void dispc_dump_clocks_channel(struct dispc_device *dispc,
3360 struct seq_file *s,
3361 enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003362{
3363 int lcd, pcd;
Tomi Valkeinendc0352d2016-05-17 13:45:09 +03003364 enum dss_clk_source lcd_clk_src;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303365
3366 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3367
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003368 lcd_clk_src = dss_get_lcd_clk_source(dispc->dss, channel);
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303369
Tomi Valkeinen557a1542016-05-17 13:49:18 +03003370 seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name,
Tomi Valkeinen407bd562016-05-17 13:50:55 +03003371 dss_get_clk_source_name(lcd_clk_src));
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303372
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003373 dispc_mgr_get_lcd_divisor(dispc, channel, &lcd, &pcd);
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303374
3375 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003376 dispc_mgr_lclk_rate(dispc, channel), lcd);
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303377 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003378 dispc_mgr_pclk_rate(dispc, channel), pcd);
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303379}
3380
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003381void dispc_dump_clocks(struct dispc_device *dispc, struct seq_file *s)
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303382{
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003383 enum dss_clk_source dispc_clk_src;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303384 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003385 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003386
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003387 if (dispc_runtime_get(dispc))
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003388 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003389
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003390 seq_printf(s, "- DISPC -\n");
3391
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003392 dispc_clk_src = dss_get_dispc_clk_source(dispc->dss);
Tomi Valkeinen557a1542016-05-17 13:49:18 +03003393 seq_printf(s, "dispc fclk source = %s\n",
Tomi Valkeinen407bd562016-05-17 13:50:55 +03003394 dss_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003395
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003396 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate(dispc));
Sumit Semwal2a205f32010-12-02 11:27:12 +00003397
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003398 if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003399 seq_printf(s, "- DISPC-CORE-CLK -\n");
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003400 l = dispc_read_reg(dispc, DISPC_DIVISOR);
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003401 lcd = FLD_GET(l, 23, 16);
3402
3403 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003404 (dispc_fclk_rate(dispc)/lcd), lcd);
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003405 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003406
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003407 dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003408
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003409 if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
3410 dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD2);
3411 if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
3412 dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003413
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003414 dispc_runtime_put(dispc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003415}
3416
Laurent Pinchartf33656e2018-02-13 14:00:29 +02003417static int dispc_dump_regs(struct seq_file *s, void *p)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003418{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003419 struct dispc_device *dispc = s->private;
Archit Taneja4dd2da12011-08-05 19:06:01 +05303420 int i, j;
3421 const char *mgr_names[] = {
3422 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3423 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3424 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303425 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303426 };
3427 const char *ovl_names[] = {
3428 [OMAP_DSS_GFX] = "GFX",
3429 [OMAP_DSS_VIDEO1] = "VID1",
3430 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303431 [OMAP_DSS_VIDEO3] = "VID3",
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003432 [OMAP_DSS_WB] = "WB",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303433 };
3434 const char **p_names;
3435
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003436#define DUMPREG(dispc, r) \
3437 seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(dispc, r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003438
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003439 if (dispc_runtime_get(dispc))
Laurent Pinchartf33656e2018-02-13 14:00:29 +02003440 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003441
Archit Taneja5010be82011-08-05 19:06:00 +05303442 /* DISPC common registers */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003443 DUMPREG(dispc, DISPC_REVISION);
3444 DUMPREG(dispc, DISPC_SYSCONFIG);
3445 DUMPREG(dispc, DISPC_SYSSTATUS);
3446 DUMPREG(dispc, DISPC_IRQSTATUS);
3447 DUMPREG(dispc, DISPC_IRQENABLE);
3448 DUMPREG(dispc, DISPC_CONTROL);
3449 DUMPREG(dispc, DISPC_CONFIG);
3450 DUMPREG(dispc, DISPC_CAPABLE);
3451 DUMPREG(dispc, DISPC_LINE_STATUS);
3452 DUMPREG(dispc, DISPC_LINE_NUMBER);
3453 if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
3454 dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
3455 DUMPREG(dispc, DISPC_GLOBAL_ALPHA);
3456 if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
3457 DUMPREG(dispc, DISPC_CONTROL2);
3458 DUMPREG(dispc, DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003459 }
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003460 if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
3461 DUMPREG(dispc, DISPC_CONTROL3);
3462 DUMPREG(dispc, DISPC_CONFIG3);
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303463 }
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003464 if (dispc_has_feature(dispc, FEAT_MFLAG))
3465 DUMPREG(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003466
Archit Taneja5010be82011-08-05 19:06:00 +05303467#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003468
Archit Taneja5010be82011-08-05 19:06:00 +05303469#define DISPC_REG(i, name) name(i)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003470#define DUMPREG(dispc, i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003471 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003472 dispc_read_reg(dispc, DISPC_REG(i, r)))
Archit Taneja5010be82011-08-05 19:06:00 +05303473
Archit Taneja4dd2da12011-08-05 19:06:01 +05303474 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303475
Archit Taneja4dd2da12011-08-05 19:06:01 +05303476 /* DISPC channel specific registers */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003477 for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
3478 DUMPREG(dispc, i, DISPC_DEFAULT_COLOR);
3479 DUMPREG(dispc, i, DISPC_TRANS_COLOR);
3480 DUMPREG(dispc, i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003481
Archit Taneja4dd2da12011-08-05 19:06:01 +05303482 if (i == OMAP_DSS_CHANNEL_DIGIT)
3483 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303484
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003485 DUMPREG(dispc, i, DISPC_TIMING_H);
3486 DUMPREG(dispc, i, DISPC_TIMING_V);
3487 DUMPREG(dispc, i, DISPC_POL_FREQ);
3488 DUMPREG(dispc, i, DISPC_DIVISORo);
Archit Taneja5010be82011-08-05 19:06:00 +05303489
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003490 DUMPREG(dispc, i, DISPC_DATA_CYCLE1);
3491 DUMPREG(dispc, i, DISPC_DATA_CYCLE2);
3492 DUMPREG(dispc, i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003493
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003494 if (dispc_has_feature(dispc, FEAT_CPR)) {
3495 DUMPREG(dispc, i, DISPC_CPR_COEF_R);
3496 DUMPREG(dispc, i, DISPC_CPR_COEF_G);
3497 DUMPREG(dispc, i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003498 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003499 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003500
Archit Taneja4dd2da12011-08-05 19:06:01 +05303501 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003502
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003503 for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
3504 DUMPREG(dispc, i, DISPC_OVL_BA0);
3505 DUMPREG(dispc, i, DISPC_OVL_BA1);
3506 DUMPREG(dispc, i, DISPC_OVL_POSITION);
3507 DUMPREG(dispc, i, DISPC_OVL_SIZE);
3508 DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
3509 DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
3510 DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
3511 DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
3512 DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003513
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003514 if (dispc_has_feature(dispc, FEAT_PRELOAD))
3515 DUMPREG(dispc, i, DISPC_OVL_PRELOAD);
3516 if (dispc_has_feature(dispc, FEAT_MFLAG))
3517 DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003518
Archit Taneja4dd2da12011-08-05 19:06:01 +05303519 if (i == OMAP_DSS_GFX) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003520 DUMPREG(dispc, i, DISPC_OVL_WINDOW_SKIP);
3521 DUMPREG(dispc, i, DISPC_OVL_TABLE_BA);
Archit Taneja4dd2da12011-08-05 19:06:01 +05303522 continue;
3523 }
3524
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003525 DUMPREG(dispc, i, DISPC_OVL_FIR);
3526 DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
3527 DUMPREG(dispc, i, DISPC_OVL_ACCU0);
3528 DUMPREG(dispc, i, DISPC_OVL_ACCU1);
3529 if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
3530 DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
3531 DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
3532 DUMPREG(dispc, i, DISPC_OVL_FIR2);
3533 DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
3534 DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
Archit Taneja4dd2da12011-08-05 19:06:01 +05303535 }
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003536 if (dispc_has_feature(dispc, FEAT_ATTR2))
3537 DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
Archit Taneja5010be82011-08-05 19:06:00 +05303538 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003539
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003540 if (dispc->feat->has_writeback) {
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003541 i = OMAP_DSS_WB;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003542 DUMPREG(dispc, i, DISPC_OVL_BA0);
3543 DUMPREG(dispc, i, DISPC_OVL_BA1);
3544 DUMPREG(dispc, i, DISPC_OVL_SIZE);
3545 DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
3546 DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
3547 DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
3548 DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
3549 DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003550
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003551 if (dispc_has_feature(dispc, FEAT_MFLAG))
3552 DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003553
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003554 DUMPREG(dispc, i, DISPC_OVL_FIR);
3555 DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
3556 DUMPREG(dispc, i, DISPC_OVL_ACCU0);
3557 DUMPREG(dispc, i, DISPC_OVL_ACCU1);
3558 if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
3559 DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
3560 DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
3561 DUMPREG(dispc, i, DISPC_OVL_FIR2);
3562 DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
3563 DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003564 }
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003565 if (dispc_has_feature(dispc, FEAT_ATTR2))
3566 DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003567 }
3568
Archit Taneja5010be82011-08-05 19:06:00 +05303569#undef DISPC_REG
3570#undef DUMPREG
3571
3572#define DISPC_REG(plane, name, i) name(plane, i)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003573#define DUMPREG(dispc, plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303574 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003575 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003576 dispc_read_reg(dispc, DISPC_REG(plane, name, i)))
Archit Taneja5010be82011-08-05 19:06:00 +05303577
Archit Taneja4dd2da12011-08-05 19:06:01 +05303578 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303579
Archit Taneja4dd2da12011-08-05 19:06:01 +05303580 /* start from OMAP_DSS_VIDEO1 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003581 for (i = 1; i < dispc_get_num_ovls(dispc); i++) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303582 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003583 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303584
Archit Taneja4dd2da12011-08-05 19:06:01 +05303585 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003586 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303587
Archit Taneja4dd2da12011-08-05 19:06:01 +05303588 for (j = 0; j < 5; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003589 DUMPREG(dispc, i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003590
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003591 if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303592 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003593 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V, j);
Archit Taneja4dd2da12011-08-05 19:06:01 +05303594 }
Amber Jainab5ca072011-05-19 19:47:53 +05303595
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003596 if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303597 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003598 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303599
Archit Taneja4dd2da12011-08-05 19:06:01 +05303600 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003601 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303602
Archit Taneja4dd2da12011-08-05 19:06:01 +05303603 for (j = 0; j < 8; j++)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003604 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V2, j);
Archit Taneja4dd2da12011-08-05 19:06:01 +05303605 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003606 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003607
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003608 dispc_runtime_put(dispc);
Archit Taneja5010be82011-08-05 19:06:00 +05303609
3610#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003611#undef DUMPREG
Laurent Pinchartf33656e2018-02-13 14:00:29 +02003612
3613 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003614}
3615
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003616/* calculate clock rates using dividers in cinfo */
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003617int dispc_calc_clock_rates(struct dispc_device *dispc,
3618 unsigned long dispc_fclk_rate,
3619 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003620{
3621 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3622 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003623 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003624 return -EINVAL;
3625
3626 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3627 cinfo->pck = cinfo->lck / cinfo->pck_div;
3628
3629 return 0;
3630}
3631
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003632bool dispc_div_calc(struct dispc_device *dispc, unsigned long dispc_freq,
3633 unsigned long pck_min, unsigned long pck_max,
3634 dispc_div_calc_func func, void *data)
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003635{
3636 int lckd, lckd_start, lckd_stop;
3637 int pckd, pckd_start, pckd_stop;
3638 unsigned long pck, lck;
3639 unsigned long lck_max;
3640 unsigned long pckd_hw_min, pckd_hw_max;
Laurent Pinchartd11e5c82018-02-11 15:07:34 +02003641 unsigned int min_fck_per_pck;
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003642 unsigned long fck;
3643
3644#ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3645 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3646#else
3647 min_fck_per_pck = 0;
3648#endif
3649
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003650 pckd_hw_min = dispc->feat->min_pcd;
Laurent Pinchartc4ff6ea2017-08-05 01:44:16 +03003651 pckd_hw_max = 255;
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003652
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003653 lck_max = dss_get_max_fck_rate(dispc->dss);
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003654
3655 pck_min = pck_min ? pck_min : 1;
3656 pck_max = pck_max ? pck_max : ULONG_MAX;
3657
Laurent Pinchartc4ff6ea2017-08-05 01:44:16 +03003658 lckd_start = max(DIV_ROUND_UP(dispc_freq, lck_max), 1ul);
3659 lckd_stop = min(dispc_freq / pck_min, 255ul);
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003660
3661 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
Laurent Pinchartc4ff6ea2017-08-05 01:44:16 +03003662 lck = dispc_freq / lckd;
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003663
3664 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3665 pckd_stop = min(lck / pck_min, pckd_hw_max);
3666
3667 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3668 pck = lck / pckd;
3669
3670 /*
3671 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3672 * clock, which means we're configuring DISPC fclk here
3673 * also. Thus we need to use the calculated lck. For
3674 * OMAP4+ the DISPC fclk is a separate clock.
3675 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003676 if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
3677 fck = dispc_core_clk_rate(dispc);
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003678 else
3679 fck = lck;
3680
3681 if (fck < pck * min_fck_per_pck)
3682 continue;
3683
3684 if (func(lckd, pckd, lck, pck, data))
3685 return true;
3686 }
3687 }
3688
3689 return false;
3690}
3691
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003692void dispc_mgr_set_clock_div(struct dispc_device *dispc,
3693 enum omap_channel channel,
3694 const struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003695{
3696 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3697 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3698
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003699 dispc_mgr_set_lcd_divisor(dispc, channel, cinfo->lck_div,
3700 cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003701}
3702
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003703int dispc_mgr_get_clock_div(struct dispc_device *dispc,
3704 enum omap_channel channel,
3705 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003706{
3707 unsigned long fck;
3708
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003709 fck = dispc_fclk_rate(dispc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003710
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003711 cinfo->lck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
3712 cinfo->pck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003713
3714 cinfo->lck = fck / cinfo->lck_div;
3715 cinfo->pck = cinfo->lck / cinfo->pck_div;
3716
3717 return 0;
3718}
3719
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003720static u32 dispc_read_irqstatus(struct dispc_device *dispc)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003721{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003722 return dispc_read_reg(dispc, DISPC_IRQSTATUS);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003723}
3724
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003725static void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003726{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003727 dispc_write_reg(dispc, DISPC_IRQSTATUS, mask);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003728}
3729
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003730static void dispc_write_irqenable(struct dispc_device *dispc, u32 mask)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003731{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003732 u32 old_mask = dispc_read_reg(dispc, DISPC_IRQENABLE);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003733
3734 /* clear the irqstatus for newly enabled irqs */
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003735 dispc_clear_irqstatus(dispc, (mask ^ old_mask) & mask);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003736
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003737 dispc_write_reg(dispc, DISPC_IRQENABLE, mask);
Tomi Valkeinen2e953d82017-02-20 13:18:38 +02003738
3739 /* flush posted write */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003740 dispc_read_reg(dispc, DISPC_IRQENABLE);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003741}
3742
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003743void dispc_enable_sidle(struct dispc_device *dispc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003744{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003745 /* SIDLEMODE: smart idle */
3746 REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 2, 4, 3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003747}
3748
Laurent Pinchart8a7eda72018-02-13 14:00:43 +02003749void dispc_disable_sidle(struct dispc_device *dispc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003750{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003751 REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003752}
3753
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003754static u32 dispc_mgr_gamma_size(struct dispc_device *dispc,
3755 enum omap_channel channel)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003756{
3757 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3758
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003759 if (!dispc->feat->has_gamma_table)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003760 return 0;
3761
3762 return gdesc->len;
3763}
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003764
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003765static void dispc_mgr_write_gamma_table(struct dispc_device *dispc,
3766 enum omap_channel channel)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003767{
3768 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003769 u32 *table = dispc->gamma_table[channel];
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003770 unsigned int i;
3771
3772 DSSDBG("%s: channel %d\n", __func__, channel);
3773
3774 for (i = 0; i < gdesc->len; ++i) {
3775 u32 v = table[i];
3776
3777 if (gdesc->has_index)
3778 v |= i << 24;
3779 else if (i == 0)
3780 v |= 1 << 31;
3781
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003782 dispc_write_reg(dispc, gdesc->reg, v);
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003783 }
3784}
3785
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003786static void dispc_restore_gamma_tables(struct dispc_device *dispc)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003787{
3788 DSSDBG("%s()\n", __func__);
3789
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003790 if (!dispc->feat->has_gamma_table)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003791 return;
3792
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003793 dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD);
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003794
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003795 dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_DIGIT);
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003796
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003797 if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
3798 dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD2);
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003799
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003800 if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
3801 dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD3);
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003802}
3803
3804static const struct drm_color_lut dispc_mgr_gamma_default_lut[] = {
3805 { .red = 0, .green = 0, .blue = 0, },
3806 { .red = U16_MAX, .green = U16_MAX, .blue = U16_MAX, },
3807};
3808
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003809static void dispc_mgr_set_gamma(struct dispc_device *dispc,
3810 enum omap_channel channel,
3811 const struct drm_color_lut *lut,
3812 unsigned int length)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003813{
3814 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003815 u32 *table = dispc->gamma_table[channel];
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003816 uint i;
3817
3818 DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__,
3819 channel, length, gdesc->len);
3820
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003821 if (!dispc->feat->has_gamma_table)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003822 return;
3823
3824 if (lut == NULL || length < 2) {
3825 lut = dispc_mgr_gamma_default_lut;
3826 length = ARRAY_SIZE(dispc_mgr_gamma_default_lut);
3827 }
3828
3829 for (i = 0; i < length - 1; ++i) {
3830 uint first = i * (gdesc->len - 1) / (length - 1);
3831 uint last = (i + 1) * (gdesc->len - 1) / (length - 1);
3832 uint w = last - first;
3833 u16 r, g, b;
3834 uint j;
3835
3836 if (w == 0)
3837 continue;
3838
3839 for (j = 0; j <= w; j++) {
3840 r = (lut[i].red * (w - j) + lut[i+1].red * j) / w;
3841 g = (lut[i].green * (w - j) + lut[i+1].green * j) / w;
3842 b = (lut[i].blue * (w - j) + lut[i+1].blue * j) / w;
3843
3844 r >>= 16 - gdesc->bits;
3845 g >>= 16 - gdesc->bits;
3846 b >>= 16 - gdesc->bits;
3847
3848 table[first + j] = (r << (gdesc->bits * 2)) |
3849 (g << gdesc->bits) | b;
3850 }
3851 }
3852
Laurent Pinchart50638ae2018-02-13 14:00:42 +02003853 if (dispc->is_enabled)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003854 dispc_mgr_write_gamma_table(dispc, channel);
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003855}
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003856
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003857static int dispc_init_gamma_tables(struct dispc_device *dispc)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003858{
3859 int channel;
3860
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003861 if (!dispc->feat->has_gamma_table)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003862 return 0;
3863
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003864 for (channel = 0; channel < ARRAY_SIZE(dispc->gamma_table); channel++) {
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003865 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3866 u32 *gt;
3867
3868 if (channel == OMAP_DSS_CHANNEL_LCD2 &&
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003869 !dispc_has_feature(dispc, FEAT_MGR_LCD2))
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003870 continue;
3871
3872 if (channel == OMAP_DSS_CHANNEL_LCD3 &&
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003873 !dispc_has_feature(dispc, FEAT_MGR_LCD3))
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003874 continue;
3875
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003876 gt = devm_kmalloc_array(&dispc->pdev->dev, gdesc->len,
3877 sizeof(u32), GFP_KERNEL);
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003878 if (!gt)
3879 return -ENOMEM;
3880
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003881 dispc->gamma_table[channel] = gt;
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003882
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003883 dispc_mgr_set_gamma(dispc, channel, NULL, 0);
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003884 }
3885 return 0;
3886}
3887
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003888static void _omap_dispc_initial_config(struct dispc_device *dispc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003889{
3890 u32 l;
3891
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003892 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003893 if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
3894 l = dispc_read_reg(dispc, DISPC_DIVISOR);
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003895 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3896 l = FLD_MOD(l, 1, 0, 0);
3897 l = FLD_MOD(l, 1, 23, 16);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003898 dispc_write_reg(dispc, DISPC_DIVISOR, l);
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003899
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003900 dispc->core_clk_rate = dispc_fclk_rate(dispc);
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003901 }
3902
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003903 /* Use gamma table mode, instead of palette mode */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003904 if (dispc->feat->has_gamma_table)
3905 REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 3, 3);
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003906
3907 /* For older DSS versions (FEAT_FUNCGATED) this enables
3908 * func-clock auto-gating. For newer versions
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003909 * (dispc->feat->has_gamma_table) this enables tv-out gamma tables.
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003910 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003911 if (dispc_has_feature(dispc, FEAT_FUNCGATED) ||
3912 dispc->feat->has_gamma_table)
3913 REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003914
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003915 dispc_setup_color_conv_coef(dispc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003916
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003917 dispc_set_loadmode(dispc, OMAP_DSS_LOAD_FRAME_ONLY);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003918
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003919 dispc_init_fifos(dispc);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003920
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003921 dispc_configure_burst_sizes(dispc);
Archit Taneja54128702011-09-08 11:29:17 +05303922
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003923 dispc_ovl_enable_zorder_planes(dispc);
Archit Tanejad0df9a22013-03-26 19:15:25 +05303924
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003925 if (dispc->feat->mstandby_workaround)
3926 REG_FLD_MOD(dispc, DISPC_MSTANDBY_CTRL, 1, 0, 0);
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00003927
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02003928 if (dispc_has_feature(dispc, FEAT_MFLAG))
3929 dispc_init_mflag(dispc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003930}
3931
Laurent Pinchart1ac0c892017-08-05 01:44:14 +03003932static const enum dispc_feature_id omap2_dispc_features_list[] = {
3933 FEAT_LCDENABLEPOL,
3934 FEAT_LCDENABLESIGNAL,
3935 FEAT_PCKFREEENABLE,
3936 FEAT_FUNCGATED,
3937 FEAT_ROWREPEATENABLE,
3938 FEAT_RESIZECONF,
3939};
3940
3941static const enum dispc_feature_id omap3_dispc_features_list[] = {
3942 FEAT_LCDENABLEPOL,
3943 FEAT_LCDENABLESIGNAL,
3944 FEAT_PCKFREEENABLE,
3945 FEAT_FUNCGATED,
3946 FEAT_LINEBUFFERSPLIT,
3947 FEAT_ROWREPEATENABLE,
3948 FEAT_RESIZECONF,
3949 FEAT_CPR,
3950 FEAT_PRELOAD,
3951 FEAT_FIR_COEF_V,
3952 FEAT_ALPHA_FIXED_ZORDER,
3953 FEAT_FIFO_MERGE,
3954 FEAT_OMAP3_DSI_FIFO_BUG,
3955};
3956
3957static const enum dispc_feature_id am43xx_dispc_features_list[] = {
3958 FEAT_LCDENABLEPOL,
3959 FEAT_LCDENABLESIGNAL,
3960 FEAT_PCKFREEENABLE,
3961 FEAT_FUNCGATED,
3962 FEAT_LINEBUFFERSPLIT,
3963 FEAT_ROWREPEATENABLE,
3964 FEAT_RESIZECONF,
3965 FEAT_CPR,
3966 FEAT_PRELOAD,
3967 FEAT_FIR_COEF_V,
3968 FEAT_ALPHA_FIXED_ZORDER,
3969 FEAT_FIFO_MERGE,
3970};
3971
3972static const enum dispc_feature_id omap4_dispc_features_list[] = {
3973 FEAT_MGR_LCD2,
3974 FEAT_CORE_CLK_DIV,
3975 FEAT_HANDLE_UV_SEPARATE,
3976 FEAT_ATTR2,
3977 FEAT_CPR,
3978 FEAT_PRELOAD,
3979 FEAT_FIR_COEF_V,
3980 FEAT_ALPHA_FREE_ZORDER,
3981 FEAT_FIFO_MERGE,
3982 FEAT_BURST_2D,
3983};
3984
3985static const enum dispc_feature_id omap5_dispc_features_list[] = {
3986 FEAT_MGR_LCD2,
3987 FEAT_MGR_LCD3,
3988 FEAT_CORE_CLK_DIV,
3989 FEAT_HANDLE_UV_SEPARATE,
3990 FEAT_ATTR2,
3991 FEAT_CPR,
3992 FEAT_PRELOAD,
3993 FEAT_FIR_COEF_V,
3994 FEAT_ALPHA_FREE_ZORDER,
3995 FEAT_FIFO_MERGE,
3996 FEAT_BURST_2D,
3997 FEAT_MFLAG,
3998};
3999
Laurent Pinchart38dc0702017-08-05 01:44:08 +03004000static const struct dss_reg_field omap2_dispc_reg_fields[] = {
4001 [FEAT_REG_FIRHINC] = { 11, 0 },
4002 [FEAT_REG_FIRVINC] = { 27, 16 },
4003 [FEAT_REG_FIFOLOWTHRESHOLD] = { 8, 0 },
4004 [FEAT_REG_FIFOHIGHTHRESHOLD] = { 24, 16 },
4005 [FEAT_REG_FIFOSIZE] = { 8, 0 },
4006 [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
4007 [FEAT_REG_VERTICALACCU] = { 25, 16 },
4008};
4009
4010static const struct dss_reg_field omap3_dispc_reg_fields[] = {
4011 [FEAT_REG_FIRHINC] = { 12, 0 },
4012 [FEAT_REG_FIRVINC] = { 28, 16 },
4013 [FEAT_REG_FIFOLOWTHRESHOLD] = { 11, 0 },
4014 [FEAT_REG_FIFOHIGHTHRESHOLD] = { 27, 16 },
4015 [FEAT_REG_FIFOSIZE] = { 10, 0 },
4016 [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
4017 [FEAT_REG_VERTICALACCU] = { 25, 16 },
4018};
4019
4020static const struct dss_reg_field omap4_dispc_reg_fields[] = {
4021 [FEAT_REG_FIRHINC] = { 12, 0 },
4022 [FEAT_REG_FIRVINC] = { 28, 16 },
4023 [FEAT_REG_FIFOLOWTHRESHOLD] = { 15, 0 },
4024 [FEAT_REG_FIFOHIGHTHRESHOLD] = { 31, 16 },
4025 [FEAT_REG_FIFOSIZE] = { 15, 0 },
4026 [FEAT_REG_HORIZONTALACCU] = { 10, 0 },
4027 [FEAT_REG_VERTICALACCU] = { 26, 16 },
4028};
4029
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004030static const enum omap_overlay_caps omap2_dispc_overlay_caps[] = {
4031 /* OMAP_DSS_GFX */
4032 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4033
4034 /* OMAP_DSS_VIDEO1 */
4035 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4036 OMAP_DSS_OVL_CAP_REPLICATION,
4037
4038 /* OMAP_DSS_VIDEO2 */
4039 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4040 OMAP_DSS_OVL_CAP_REPLICATION,
4041};
4042
4043static const enum omap_overlay_caps omap3430_dispc_overlay_caps[] = {
4044 /* OMAP_DSS_GFX */
4045 OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_POS |
4046 OMAP_DSS_OVL_CAP_REPLICATION,
4047
4048 /* OMAP_DSS_VIDEO1 */
4049 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4050 OMAP_DSS_OVL_CAP_REPLICATION,
4051
4052 /* OMAP_DSS_VIDEO2 */
4053 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4054 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4055};
4056
4057static const enum omap_overlay_caps omap3630_dispc_overlay_caps[] = {
4058 /* OMAP_DSS_GFX */
4059 OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
4060 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4061
4062 /* OMAP_DSS_VIDEO1 */
4063 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4064 OMAP_DSS_OVL_CAP_REPLICATION,
4065
4066 /* OMAP_DSS_VIDEO2 */
4067 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4068 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_POS |
4069 OMAP_DSS_OVL_CAP_REPLICATION,
4070};
4071
4072static const enum omap_overlay_caps omap4_dispc_overlay_caps[] = {
4073 /* OMAP_DSS_GFX */
4074 OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
4075 OMAP_DSS_OVL_CAP_ZORDER | OMAP_DSS_OVL_CAP_POS |
4076 OMAP_DSS_OVL_CAP_REPLICATION,
4077
4078 /* OMAP_DSS_VIDEO1 */
4079 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4080 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
4081 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4082
4083 /* OMAP_DSS_VIDEO2 */
4084 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4085 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
4086 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4087
4088 /* OMAP_DSS_VIDEO3 */
4089 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4090 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
4091 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4092};
4093
Laurent Pinchart94f96ad2017-08-05 01:44:04 +03004094#define COLOR_ARRAY(arr...) (const u32[]) { arr, 0 }
4095
4096static const u32 *omap2_dispc_supported_color_modes[] = {
4097
4098 /* OMAP_DSS_GFX */
4099 COLOR_ARRAY(
4100 DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
4101 DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888),
4102
4103 /* OMAP_DSS_VIDEO1 */
4104 COLOR_ARRAY(
4105 DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4106 DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
4107 DRM_FORMAT_UYVY),
4108
4109 /* OMAP_DSS_VIDEO2 */
4110 COLOR_ARRAY(
4111 DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4112 DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
4113 DRM_FORMAT_UYVY),
4114};
4115
4116static const u32 *omap3_dispc_supported_color_modes[] = {
4117 /* OMAP_DSS_GFX */
4118 COLOR_ARRAY(
4119 DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
4120 DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4121 DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
4122 DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
4123
4124 /* OMAP_DSS_VIDEO1 */
4125 COLOR_ARRAY(
4126 DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888,
4127 DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
4128 DRM_FORMAT_YUYV, DRM_FORMAT_UYVY),
4129
4130 /* OMAP_DSS_VIDEO2 */
4131 COLOR_ARRAY(
4132 DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
4133 DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4134 DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
4135 DRM_FORMAT_UYVY, DRM_FORMAT_ARGB8888,
4136 DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
4137};
4138
4139static const u32 *omap4_dispc_supported_color_modes[] = {
4140 /* OMAP_DSS_GFX */
4141 COLOR_ARRAY(
4142 DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
4143 DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4144 DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
4145 DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888,
4146 DRM_FORMAT_ARGB1555, DRM_FORMAT_XRGB4444,
4147 DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB1555),
4148
4149 /* OMAP_DSS_VIDEO1 */
4150 COLOR_ARRAY(
4151 DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4152 DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4153 DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4154 DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4155 DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4156 DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4157 DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4158 DRM_FORMAT_RGBX8888),
4159
4160 /* OMAP_DSS_VIDEO2 */
4161 COLOR_ARRAY(
4162 DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4163 DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4164 DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4165 DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4166 DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4167 DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4168 DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4169 DRM_FORMAT_RGBX8888),
4170
4171 /* OMAP_DSS_VIDEO3 */
4172 COLOR_ARRAY(
4173 DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4174 DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4175 DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4176 DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4177 DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4178 DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4179 DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4180 DRM_FORMAT_RGBX8888),
4181
4182 /* OMAP_DSS_WB */
4183 COLOR_ARRAY(
4184 DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4185 DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4186 DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4187 DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4188 DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4189 DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4190 DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4191 DRM_FORMAT_RGBX8888),
4192};
4193
Tomi Valkeinenede92692015-06-04 14:12:16 +03004194static const struct dispc_features omap24xx_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304195 .sw_start = 5,
4196 .fp_start = 15,
4197 .bp_start = 27,
4198 .sw_max = 64,
4199 .vp_max = 255,
4200 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05304201 .mgr_width_start = 10,
4202 .mgr_height_start = 26,
4203 .mgr_width_max = 2048,
4204 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05304205 .max_lcd_pclk = 66500000,
Laurent Pinchartc4ff6ea2017-08-05 01:44:16 +03004206 .max_downscale = 2,
4207 /*
4208 * Assume the line width buffer to be 768 pixels as OMAP2 DISPC scaler
4209 * cannot scale an image width larger than 768.
4210 */
4211 .max_line_width = 768,
4212 .min_pcd = 2,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304213 .calc_scaling = dispc_ovl_calc_scaling_24xx,
4214 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004215 .num_fifos = 3,
Laurent Pinchart1ac0c892017-08-05 01:44:14 +03004216 .features = omap2_dispc_features_list,
4217 .num_features = ARRAY_SIZE(omap2_dispc_features_list),
Laurent Pinchart38dc0702017-08-05 01:44:08 +03004218 .reg_fields = omap2_dispc_reg_fields,
4219 .num_reg_fields = ARRAY_SIZE(omap2_dispc_reg_fields),
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004220 .overlay_caps = omap2_dispc_overlay_caps,
Laurent Pinchart94f96ad2017-08-05 01:44:04 +03004221 .supported_color_modes = omap2_dispc_supported_color_modes,
Laurent Pinchartacf591c2017-08-05 01:44:06 +03004222 .num_mgrs = 2,
4223 .num_ovls = 3,
Laurent Pinchart28550472017-08-05 01:44:03 +03004224 .buffer_size_unit = 1,
4225 .burst_size_unit = 8,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02004226 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05304227 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03004228 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304229};
4230
Tomi Valkeinenede92692015-06-04 14:12:16 +03004231static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304232 .sw_start = 5,
4233 .fp_start = 15,
4234 .bp_start = 27,
4235 .sw_max = 64,
4236 .vp_max = 255,
4237 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05304238 .mgr_width_start = 10,
4239 .mgr_height_start = 26,
4240 .mgr_width_max = 2048,
4241 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05304242 .max_lcd_pclk = 173000000,
4243 .max_tv_pclk = 59000000,
Laurent Pinchartc4ff6ea2017-08-05 01:44:16 +03004244 .max_downscale = 4,
4245 .max_line_width = 1024,
4246 .min_pcd = 1,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304247 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4248 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004249 .num_fifos = 3,
Laurent Pinchart1ac0c892017-08-05 01:44:14 +03004250 .features = omap3_dispc_features_list,
4251 .num_features = ARRAY_SIZE(omap3_dispc_features_list),
Laurent Pinchart38dc0702017-08-05 01:44:08 +03004252 .reg_fields = omap3_dispc_reg_fields,
4253 .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004254 .overlay_caps = omap3430_dispc_overlay_caps,
Laurent Pinchart94f96ad2017-08-05 01:44:04 +03004255 .supported_color_modes = omap3_dispc_supported_color_modes,
Laurent Pinchartacf591c2017-08-05 01:44:06 +03004256 .num_mgrs = 2,
4257 .num_ovls = 3,
Laurent Pinchart28550472017-08-05 01:44:03 +03004258 .buffer_size_unit = 1,
4259 .burst_size_unit = 8,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02004260 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05304261 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03004262 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304263};
4264
Tomi Valkeinenede92692015-06-04 14:12:16 +03004265static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304266 .sw_start = 7,
4267 .fp_start = 19,
4268 .bp_start = 31,
4269 .sw_max = 256,
4270 .vp_max = 4095,
4271 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05304272 .mgr_width_start = 10,
4273 .mgr_height_start = 26,
4274 .mgr_width_max = 2048,
4275 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05304276 .max_lcd_pclk = 173000000,
4277 .max_tv_pclk = 59000000,
Laurent Pinchartc4ff6ea2017-08-05 01:44:16 +03004278 .max_downscale = 4,
4279 .max_line_width = 1024,
4280 .min_pcd = 1,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304281 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4282 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004283 .num_fifos = 3,
Laurent Pinchart1ac0c892017-08-05 01:44:14 +03004284 .features = omap3_dispc_features_list,
4285 .num_features = ARRAY_SIZE(omap3_dispc_features_list),
Laurent Pinchart38dc0702017-08-05 01:44:08 +03004286 .reg_fields = omap3_dispc_reg_fields,
4287 .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004288 .overlay_caps = omap3430_dispc_overlay_caps,
4289 .supported_color_modes = omap3_dispc_supported_color_modes,
Laurent Pinchartacf591c2017-08-05 01:44:06 +03004290 .num_mgrs = 2,
4291 .num_ovls = 3,
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004292 .buffer_size_unit = 1,
4293 .burst_size_unit = 8,
4294 .no_framedone_tv = true,
4295 .set_max_preload = false,
4296 .last_pixel_inc_missing = true,
4297};
4298
4299static const struct dispc_features omap36xx_dispc_feats = {
4300 .sw_start = 7,
4301 .fp_start = 19,
4302 .bp_start = 31,
4303 .sw_max = 256,
4304 .vp_max = 4095,
4305 .hp_max = 4096,
4306 .mgr_width_start = 10,
4307 .mgr_height_start = 26,
4308 .mgr_width_max = 2048,
4309 .mgr_height_max = 2048,
4310 .max_lcd_pclk = 173000000,
4311 .max_tv_pclk = 59000000,
Laurent Pinchartc4ff6ea2017-08-05 01:44:16 +03004312 .max_downscale = 4,
4313 .max_line_width = 1024,
4314 .min_pcd = 1,
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004315 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4316 .calc_core_clk = calc_core_clk_34xx,
4317 .num_fifos = 3,
Laurent Pinchart1ac0c892017-08-05 01:44:14 +03004318 .features = omap3_dispc_features_list,
4319 .num_features = ARRAY_SIZE(omap3_dispc_features_list),
Laurent Pinchart38dc0702017-08-05 01:44:08 +03004320 .reg_fields = omap3_dispc_reg_fields,
4321 .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004322 .overlay_caps = omap3630_dispc_overlay_caps,
Laurent Pinchart94f96ad2017-08-05 01:44:04 +03004323 .supported_color_modes = omap3_dispc_supported_color_modes,
Laurent Pinchartacf591c2017-08-05 01:44:06 +03004324 .num_mgrs = 2,
4325 .num_ovls = 3,
4326 .buffer_size_unit = 1,
4327 .burst_size_unit = 8,
4328 .no_framedone_tv = true,
4329 .set_max_preload = false,
4330 .last_pixel_inc_missing = true,
4331};
4332
4333static const struct dispc_features am43xx_dispc_feats = {
4334 .sw_start = 7,
4335 .fp_start = 19,
4336 .bp_start = 31,
4337 .sw_max = 256,
4338 .vp_max = 4095,
4339 .hp_max = 4096,
4340 .mgr_width_start = 10,
4341 .mgr_height_start = 26,
4342 .mgr_width_max = 2048,
4343 .mgr_height_max = 2048,
4344 .max_lcd_pclk = 173000000,
4345 .max_tv_pclk = 59000000,
Laurent Pinchartc4ff6ea2017-08-05 01:44:16 +03004346 .max_downscale = 4,
4347 .max_line_width = 1024,
4348 .min_pcd = 1,
Laurent Pinchartacf591c2017-08-05 01:44:06 +03004349 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4350 .calc_core_clk = calc_core_clk_34xx,
4351 .num_fifos = 3,
Laurent Pinchart1ac0c892017-08-05 01:44:14 +03004352 .features = am43xx_dispc_features_list,
4353 .num_features = ARRAY_SIZE(am43xx_dispc_features_list),
Laurent Pinchart38dc0702017-08-05 01:44:08 +03004354 .reg_fields = omap3_dispc_reg_fields,
4355 .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
Laurent Pinchartacf591c2017-08-05 01:44:06 +03004356 .overlay_caps = omap3430_dispc_overlay_caps,
4357 .supported_color_modes = omap3_dispc_supported_color_modes,
4358 .num_mgrs = 1,
4359 .num_ovls = 3,
Laurent Pinchart28550472017-08-05 01:44:03 +03004360 .buffer_size_unit = 1,
4361 .burst_size_unit = 8,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02004362 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05304363 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03004364 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304365};
4366
Tomi Valkeinenede92692015-06-04 14:12:16 +03004367static const struct dispc_features omap44xx_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304368 .sw_start = 7,
4369 .fp_start = 19,
4370 .bp_start = 31,
4371 .sw_max = 256,
4372 .vp_max = 4095,
4373 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05304374 .mgr_width_start = 10,
4375 .mgr_height_start = 26,
4376 .mgr_width_max = 2048,
4377 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05304378 .max_lcd_pclk = 170000000,
4379 .max_tv_pclk = 185625000,
Laurent Pinchartc4ff6ea2017-08-05 01:44:16 +03004380 .max_downscale = 4,
4381 .max_line_width = 2048,
4382 .min_pcd = 1,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304383 .calc_scaling = dispc_ovl_calc_scaling_44xx,
4384 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004385 .num_fifos = 5,
Laurent Pinchart1ac0c892017-08-05 01:44:14 +03004386 .features = omap4_dispc_features_list,
4387 .num_features = ARRAY_SIZE(omap4_dispc_features_list),
Laurent Pinchart38dc0702017-08-05 01:44:08 +03004388 .reg_fields = omap4_dispc_reg_fields,
4389 .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004390 .overlay_caps = omap4_dispc_overlay_caps,
Laurent Pinchart94f96ad2017-08-05 01:44:04 +03004391 .supported_color_modes = omap4_dispc_supported_color_modes,
Laurent Pinchartacf591c2017-08-05 01:44:06 +03004392 .num_mgrs = 3,
4393 .num_ovls = 4,
Laurent Pinchart28550472017-08-05 01:44:03 +03004394 .buffer_size_unit = 16,
4395 .burst_size_unit = 16,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03004396 .gfx_fifo_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05304397 .set_max_preload = true,
Tomi Valkeinene5f80912015-10-21 13:08:59 +03004398 .supports_sync_align = true,
Tomi Valkeinen20efbc32015-11-04 17:10:44 +02004399 .has_writeback = true,
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02004400 .supports_double_pixel = true,
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02004401 .reverse_ilace_field_order = true,
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004402 .has_gamma_table = true,
Jyri Sarhafbff0102016-06-07 15:09:16 +03004403 .has_gamma_i734_bug = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304404};
4405
Tomi Valkeinenede92692015-06-04 14:12:16 +03004406static const struct dispc_features omap54xx_dispc_feats = {
Archit Taneja264236f2012-11-14 13:50:16 +05304407 .sw_start = 7,
4408 .fp_start = 19,
4409 .bp_start = 31,
4410 .sw_max = 256,
4411 .vp_max = 4095,
4412 .hp_max = 4096,
4413 .mgr_width_start = 11,
4414 .mgr_height_start = 27,
4415 .mgr_width_max = 4096,
4416 .mgr_height_max = 4096,
Archit Tanejaca5ca692013-03-26 19:15:22 +05304417 .max_lcd_pclk = 170000000,
4418 .max_tv_pclk = 186000000,
Laurent Pinchartc4ff6ea2017-08-05 01:44:16 +03004419 .max_downscale = 4,
4420 .max_line_width = 2048,
4421 .min_pcd = 1,
Archit Taneja264236f2012-11-14 13:50:16 +05304422 .calc_scaling = dispc_ovl_calc_scaling_44xx,
4423 .calc_core_clk = calc_core_clk_44xx,
4424 .num_fifos = 5,
Laurent Pinchart1ac0c892017-08-05 01:44:14 +03004425 .features = omap5_dispc_features_list,
4426 .num_features = ARRAY_SIZE(omap5_dispc_features_list),
Laurent Pinchart38dc0702017-08-05 01:44:08 +03004427 .reg_fields = omap4_dispc_reg_fields,
4428 .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004429 .overlay_caps = omap4_dispc_overlay_caps,
Laurent Pinchart94f96ad2017-08-05 01:44:04 +03004430 .supported_color_modes = omap4_dispc_supported_color_modes,
Laurent Pinchartacf591c2017-08-05 01:44:06 +03004431 .num_mgrs = 4,
4432 .num_ovls = 4,
Laurent Pinchart28550472017-08-05 01:44:03 +03004433 .buffer_size_unit = 16,
4434 .burst_size_unit = 16,
Archit Taneja264236f2012-11-14 13:50:16 +05304435 .gfx_fifo_workaround = true,
Archit Tanejad0df9a22013-03-26 19:15:25 +05304436 .mstandby_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05304437 .set_max_preload = true,
Tomi Valkeinene5f80912015-10-21 13:08:59 +03004438 .supports_sync_align = true,
Tomi Valkeinen20efbc32015-11-04 17:10:44 +02004439 .has_writeback = true,
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02004440 .supports_double_pixel = true,
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02004441 .reverse_ilace_field_order = true,
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004442 .has_gamma_table = true,
Jyri Sarhafbff0102016-06-07 15:09:16 +03004443 .has_gamma_i734_bug = true,
Archit Taneja264236f2012-11-14 13:50:16 +05304444};
4445
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004446static irqreturn_t dispc_irq_handler(int irq, void *arg)
4447{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004448 struct dispc_device *dispc = arg;
4449
4450 if (!dispc->is_enabled)
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004451 return IRQ_NONE;
4452
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004453 return dispc->user_handler(irq, dispc->user_data);
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004454}
4455
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004456static int dispc_request_irq(struct dispc_device *dispc, irq_handler_t handler,
4457 void *dev_id)
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03004458{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004459 int r;
4460
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004461 if (dispc->user_handler != NULL)
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004462 return -EBUSY;
4463
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004464 dispc->user_handler = handler;
4465 dispc->user_data = dev_id;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004466
4467 /* ensure the dispc_irq_handler sees the values above */
4468 smp_wmb();
4469
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004470 r = devm_request_irq(&dispc->pdev->dev, dispc->irq, dispc_irq_handler,
4471 IRQF_SHARED, "OMAP DISPC", dispc);
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004472 if (r) {
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004473 dispc->user_handler = NULL;
4474 dispc->user_data = NULL;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004475 }
4476
4477 return r;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03004478}
4479
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004480static void dispc_free_irq(struct dispc_device *dispc, void *dev_id)
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03004481{
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004482 devm_free_irq(&dispc->pdev->dev, dispc->irq, dispc);
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004483
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004484 dispc->user_handler = NULL;
4485 dispc->user_data = NULL;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03004486}
4487
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004488static u32 dispc_get_memory_bandwidth_limit(struct dispc_device *dispc)
Peter Ujfalusi867d7e02017-11-30 14:12:36 +02004489{
4490 u32 limit = 0;
4491
4492 /* Optional maximum memory bandwidth */
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004493 of_property_read_u32(dispc->pdev->dev.of_node, "max-memory-bandwidth",
Peter Ujfalusi867d7e02017-11-30 14:12:36 +02004494 &limit);
4495
4496 return limit;
4497}
4498
Jyri Sarhafbff0102016-06-07 15:09:16 +03004499/*
4500 * Workaround for errata i734 in DSS dispc
4501 * - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled
4502 *
4503 * For gamma tables to work on LCD1 the GFX plane has to be used at
4504 * least once after DSS HW has come out of reset. The workaround
4505 * sets up a minimal LCD setup with GFX plane and waits for one
4506 * vertical sync irq before disabling the setup and continuing with
4507 * the context restore. The physical outputs are gated during the
4508 * operation. This workaround requires that gamma table's LOADMODE
4509 * is set to 0x2 in DISPC_CONTROL1 register.
4510 *
4511 * For details see:
4512 * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata
4513 * Literature Number: SWPZ037E
4514 * Or some other relevant errata document for the DSS IP version.
4515 */
4516
4517static const struct dispc_errata_i734_data {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03004518 struct videomode vm;
Jyri Sarhafbff0102016-06-07 15:09:16 +03004519 struct omap_overlay_info ovli;
4520 struct omap_overlay_manager_info mgri;
4521 struct dss_lcd_mgr_config lcd_conf;
4522} i734 = {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03004523 .vm = {
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03004524 .hactive = 8, .vactive = 1,
Jyri Sarhafbff0102016-06-07 15:09:16 +03004525 .pixelclock = 16000000,
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03004526 .hsync_len = 8, .hfront_porch = 4, .hback_porch = 4,
Peter Ujfalusi458540c2016-09-22 14:06:53 +03004527 .vsync_len = 1, .vfront_porch = 1, .vback_porch = 1,
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03004528
Peter Ujfalusi3fa3ab42016-09-22 14:06:58 +03004529 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
Peter Ujfalusid34afb72016-09-22 14:07:01 +03004530 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
4531 DISPLAY_FLAGS_PIXDATA_POSEDGE,
Jyri Sarhafbff0102016-06-07 15:09:16 +03004532 },
4533 .ovli = {
4534 .screen_width = 1,
4535 .width = 1, .height = 1,
Tomi Valkeinen41aff422017-05-04 11:31:56 +03004536 .fourcc = DRM_FORMAT_XRGB8888,
Tomi Valkeinen0bd97c42017-05-16 11:05:09 +03004537 .rotation = DRM_MODE_ROTATE_0,
Tomi Valkeinen517a8a952017-05-03 14:14:27 +03004538 .rotation_type = OMAP_DSS_ROT_NONE,
Jyri Sarhafbff0102016-06-07 15:09:16 +03004539 .pos_x = 0, .pos_y = 0,
4540 .out_width = 0, .out_height = 0,
4541 .global_alpha = 0xff,
4542 .pre_mult_alpha = 0,
4543 .zorder = 0,
4544 },
4545 .mgri = {
4546 .default_color = 0,
4547 .trans_enabled = false,
4548 .partial_alpha_enabled = false,
4549 .cpr_enable = false,
4550 },
4551 .lcd_conf = {
4552 .io_pad_mode = DSS_IO_PAD_MODE_BYPASS,
4553 .stallmode = false,
4554 .fifohandcheck = false,
4555 .clock_info = {
4556 .lck_div = 1,
4557 .pck_div = 2,
4558 },
4559 .video_port_width = 24,
4560 .lcden_sig_polarity = 0,
4561 },
4562};
4563
4564static struct i734_buf {
4565 size_t size;
4566 dma_addr_t paddr;
4567 void *vaddr;
4568} i734_buf;
4569
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004570static int dispc_errata_i734_wa_init(struct dispc_device *dispc)
Jyri Sarhafbff0102016-06-07 15:09:16 +03004571{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004572 if (!dispc->feat->has_gamma_i734_bug)
Jyri Sarhafbff0102016-06-07 15:09:16 +03004573 return 0;
4574
4575 i734_buf.size = i734.ovli.width * i734.ovli.height *
Tomi Valkeinen41aff422017-05-04 11:31:56 +03004576 color_mode_to_bpp(i734.ovli.fourcc) / 8;
Jyri Sarhafbff0102016-06-07 15:09:16 +03004577
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004578 i734_buf.vaddr = dma_alloc_writecombine(&dispc->pdev->dev,
4579 i734_buf.size, &i734_buf.paddr,
4580 GFP_KERNEL);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004581 if (!i734_buf.vaddr) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004582 dev_err(&dispc->pdev->dev, "%s: dma_alloc_writecombine failed",
Jyri Sarhafbff0102016-06-07 15:09:16 +03004583 __func__);
4584 return -ENOMEM;
4585 }
4586
4587 return 0;
4588}
4589
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004590static void dispc_errata_i734_wa_fini(struct dispc_device *dispc)
Jyri Sarhafbff0102016-06-07 15:09:16 +03004591{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004592 if (!dispc->feat->has_gamma_i734_bug)
Jyri Sarhafbff0102016-06-07 15:09:16 +03004593 return;
4594
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004595 dma_free_writecombine(&dispc->pdev->dev, i734_buf.size, i734_buf.vaddr,
Jyri Sarhafbff0102016-06-07 15:09:16 +03004596 i734_buf.paddr);
4597}
4598
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004599static void dispc_errata_i734_wa(struct dispc_device *dispc)
Jyri Sarhafbff0102016-06-07 15:09:16 +03004600{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004601 u32 framedone_irq = dispc_mgr_get_framedone_irq(dispc,
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004602 OMAP_DSS_CHANNEL_LCD);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004603 struct omap_overlay_info ovli;
4604 struct dss_lcd_mgr_config lcd_conf;
4605 u32 gatestate;
4606 unsigned int count;
4607
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004608 if (!dispc->feat->has_gamma_i734_bug)
Jyri Sarhafbff0102016-06-07 15:09:16 +03004609 return;
4610
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004611 gatestate = REG_GET(dispc, DISPC_CONFIG, 8, 4);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004612
4613 ovli = i734.ovli;
4614 ovli.paddr = i734_buf.paddr;
4615 lcd_conf = i734.lcd_conf;
4616
4617 /* Gate all LCD1 outputs */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004618 REG_FLD_MOD(dispc, DISPC_CONFIG, 0x1f, 8, 4);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004619
4620 /* Setup and enable GFX plane */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004621 dispc_ovl_setup(dispc, OMAP_DSS_GFX, &ovli, &i734.vm, false,
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004622 OMAP_DSS_CHANNEL_LCD);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004623 dispc_ovl_enable(dispc, OMAP_DSS_GFX, true);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004624
4625 /* Set up and enable display manager for LCD1 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004626 dispc_mgr_setup(dispc, OMAP_DSS_CHANNEL_LCD, &i734.mgri);
4627 dispc_calc_clock_rates(dispc, dss_get_dispc_clk_rate(dispc->dss),
Jyri Sarhafbff0102016-06-07 15:09:16 +03004628 &lcd_conf.clock_info);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004629 dispc_mgr_set_lcd_config(dispc, OMAP_DSS_CHANNEL_LCD, &lcd_conf);
4630 dispc_mgr_set_timings(dispc, OMAP_DSS_CHANNEL_LCD, &i734.vm);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004631
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004632 dispc_clear_irqstatus(dispc, framedone_irq);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004633
4634 /* Enable and shut the channel to produce just one frame */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004635 dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, true);
4636 dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, false);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004637
4638 /* Busy wait for framedone. We can't fiddle with irq handlers
4639 * in PM resume. Typically the loop runs less than 5 times and
4640 * waits less than a micro second.
4641 */
4642 count = 0;
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004643 while (!(dispc_read_irqstatus(dispc) & framedone_irq)) {
Jyri Sarhafbff0102016-06-07 15:09:16 +03004644 if (count++ > 10000) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004645 dev_err(&dispc->pdev->dev, "%s: framedone timeout\n",
Jyri Sarhafbff0102016-06-07 15:09:16 +03004646 __func__);
4647 break;
4648 }
4649 }
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004650 dispc_ovl_enable(dispc, OMAP_DSS_GFX, false);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004651
4652 /* Clear all irq bits before continuing */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004653 dispc_clear_irqstatus(dispc, 0xffffffff);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004654
4655 /* Restore the original state to LCD1 output gates */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004656 REG_FLD_MOD(dispc, DISPC_CONFIG, gatestate, 8, 4);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004657}
4658
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004659static const struct dispc_ops dispc_ops = {
4660 .read_irqstatus = dispc_read_irqstatus,
4661 .clear_irqstatus = dispc_clear_irqstatus,
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004662 .write_irqenable = dispc_write_irqenable,
4663
4664 .request_irq = dispc_request_irq,
4665 .free_irq = dispc_free_irq,
4666
4667 .runtime_get = dispc_runtime_get,
4668 .runtime_put = dispc_runtime_put,
4669
4670 .get_num_ovls = dispc_get_num_ovls,
4671 .get_num_mgrs = dispc_get_num_mgrs,
4672
Peter Ujfalusi867d7e02017-11-30 14:12:36 +02004673 .get_memory_bandwidth_limit = dispc_get_memory_bandwidth_limit,
4674
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004675 .mgr_enable = dispc_mgr_enable,
4676 .mgr_is_enabled = dispc_mgr_is_enabled,
4677 .mgr_get_vsync_irq = dispc_mgr_get_vsync_irq,
4678 .mgr_get_framedone_irq = dispc_mgr_get_framedone_irq,
4679 .mgr_get_sync_lost_irq = dispc_mgr_get_sync_lost_irq,
4680 .mgr_go_busy = dispc_mgr_go_busy,
4681 .mgr_go = dispc_mgr_go,
4682 .mgr_set_lcd_config = dispc_mgr_set_lcd_config,
4683 .mgr_set_timings = dispc_mgr_set_timings,
4684 .mgr_setup = dispc_mgr_setup,
4685 .mgr_get_supported_outputs = dispc_mgr_get_supported_outputs,
4686 .mgr_gamma_size = dispc_mgr_gamma_size,
4687 .mgr_set_gamma = dispc_mgr_set_gamma,
4688
4689 .ovl_enable = dispc_ovl_enable,
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004690 .ovl_setup = dispc_ovl_setup,
4691 .ovl_get_color_modes = dispc_ovl_get_color_modes,
4692};
4693
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004694/* DISPC HW IP initialisation */
Laurent Pinchart7a143a42017-08-05 01:43:55 +03004695static const struct of_device_id dispc_of_match[] = {
4696 { .compatible = "ti,omap2-dispc", .data = &omap24xx_dispc_feats },
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004697 { .compatible = "ti,omap3-dispc", .data = &omap36xx_dispc_feats },
Laurent Pinchart7a143a42017-08-05 01:43:55 +03004698 { .compatible = "ti,omap4-dispc", .data = &omap44xx_dispc_feats },
4699 { .compatible = "ti,omap5-dispc", .data = &omap54xx_dispc_feats },
4700 { .compatible = "ti,dra7-dispc", .data = &omap54xx_dispc_feats },
4701 {},
4702};
4703
4704static const struct soc_device_attribute dispc_soc_devices[] = {
4705 { .machine = "OMAP3[45]*",
4706 .revision = "ES[12].?", .data = &omap34xx_rev1_0_dispc_feats },
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004707 { .machine = "OMAP3[45]*", .data = &omap34xx_rev3_0_dispc_feats },
4708 { .machine = "AM35*", .data = &omap34xx_rev3_0_dispc_feats },
Laurent Pinchartacf591c2017-08-05 01:44:06 +03004709 { .machine = "AM43*", .data = &am43xx_dispc_feats },
Laurent Pinchart7a143a42017-08-05 01:43:55 +03004710 { /* sentinel */ }
4711};
4712
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004713static int dispc_bind(struct device *dev, struct device *master, void *data)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004714{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004715 struct platform_device *pdev = to_platform_device(dev);
Laurent Pinchart7a143a42017-08-05 01:43:55 +03004716 const struct soc_device_attribute *soc;
Laurent Pinchart3cc62aa2018-02-13 14:00:25 +02004717 struct dss_device *dss = dss_get_device(master);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004718 struct dispc_device *dispc;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004719 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00004720 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004721 struct resource *dispc_mem;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004722 struct device_node *np = pdev->dev.of_node;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004723
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004724 dispc = kzalloc(sizeof(*dispc), GFP_KERNEL);
4725 if (!dispc)
4726 return -ENOMEM;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004727
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004728 dispc->pdev = pdev;
4729 platform_set_drvdata(pdev, dispc);
4730 dispc->dss = dss;
4731
4732 spin_lock_init(&dispc->control_lock);
Tomi Valkeinend49cd152014-11-10 12:23:00 +02004733
Laurent Pinchart7a143a42017-08-05 01:43:55 +03004734 /*
Laurent Pinchartacf591c2017-08-05 01:44:06 +03004735 * The OMAP3-based models can't be told apart using the compatible
Laurent Pinchartfcd41882017-08-05 01:44:05 +03004736 * string, use SoC device matching.
Laurent Pinchart7a143a42017-08-05 01:43:55 +03004737 */
4738 soc = soc_device_match(dispc_soc_devices);
4739 if (soc)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004740 dispc->feat = soc->data;
Laurent Pinchart7a143a42017-08-05 01:43:55 +03004741 else
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004742 dispc->feat = of_match_device(dispc_of_match, &pdev->dev)->data;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304743
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004744 r = dispc_errata_i734_wa_init(dispc);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004745 if (r)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004746 goto err_free;
Jyri Sarhafbff0102016-06-07 15:09:16 +03004747
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004748 dispc_mem = platform_get_resource(dispc->pdev, IORESOURCE_MEM, 0);
4749 dispc->base = devm_ioremap_resource(&pdev->dev, dispc_mem);
4750 if (IS_ERR(dispc->base)) {
4751 r = PTR_ERR(dispc->base);
4752 goto err_free;
4753 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004754
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004755 dispc->irq = platform_get_irq(dispc->pdev, 0);
4756 if (dispc->irq < 0) {
archit tanejaaffe3602011-02-23 08:41:03 +00004757 DSSERR("platform_get_irq failed\n");
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004758 r = -ENODEV;
4759 goto err_free;
archit tanejaaffe3602011-02-23 08:41:03 +00004760 }
4761
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004762 if (np && of_property_read_bool(np, "syscon-pol")) {
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004763 dispc->syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
4764 if (IS_ERR(dispc->syscon_pol)) {
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004765 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004766 r = PTR_ERR(dispc->syscon_pol);
4767 goto err_free;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004768 }
4769
4770 if (of_property_read_u32_index(np, "syscon-pol", 1,
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004771 &dispc->syscon_pol_offset)) {
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004772 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004773 r = -EINVAL;
4774 goto err_free;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004775 }
4776 }
4777
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004778 r = dispc_init_gamma_tables(dispc);
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004779 if (r)
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004780 goto err_free;
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004781
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004782 pm_runtime_enable(&pdev->dev);
4783
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004784 r = dispc_runtime_get(dispc);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004785 if (r)
4786 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004787
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004788 _omap_dispc_initial_config(dispc);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004789
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004790 rev = dispc_read_reg(dispc, DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00004791 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004792 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4793
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004794 dispc_runtime_put(dispc);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004795
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004796 dss->dispc = dispc;
Laurent Pinchartd3541ca2018-02-13 14:00:41 +02004797 dss->dispc_ops = &dispc_ops;
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004798
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004799 dispc->debugfs = dss_debugfs_create_file(dss, "dispc", dispc_dump_regs,
4800 dispc);
Tomi Valkeinene40402c2012-03-02 18:01:07 +02004801
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004802 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004803
4804err_runtime_get:
4805 pm_runtime_disable(&pdev->dev);
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004806err_free:
4807 kfree(dispc);
archit tanejaaffe3602011-02-23 08:41:03 +00004808 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004809}
4810
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004811static void dispc_unbind(struct device *dev, struct device *master, void *data)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004812{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004813 struct dispc_device *dispc = dev_get_drvdata(dev);
4814 struct dss_device *dss = dispc->dss;
Laurent Pinchartd3541ca2018-02-13 14:00:41 +02004815
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004816 dss_debugfs_remove_file(dispc->debugfs);
Laurent Pinchartf33656e2018-02-13 14:00:29 +02004817
Laurent Pinchart50638ae2018-02-13 14:00:42 +02004818 dss->dispc = NULL;
Laurent Pinchartd3541ca2018-02-13 14:00:41 +02004819 dss->dispc_ops = NULL;
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004820
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004821 pm_runtime_disable(dev);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004822
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004823 dispc_errata_i734_wa_fini(dispc);
4824
4825 kfree(dispc);
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004826}
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03004827
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004828static const struct component_ops dispc_component_ops = {
4829 .bind = dispc_bind,
4830 .unbind = dispc_unbind,
4831};
4832
4833static int dispc_probe(struct platform_device *pdev)
4834{
4835 return component_add(&pdev->dev, &dispc_component_ops);
4836}
4837
4838static int dispc_remove(struct platform_device *pdev)
4839{
4840 component_del(&pdev->dev, &dispc_component_ops);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004841 return 0;
4842}
4843
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004844static int dispc_runtime_suspend(struct device *dev)
4845{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004846 struct dispc_device *dispc = dev_get_drvdata(dev);
4847
4848 dispc->is_enabled = false;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004849 /* ensure the dispc_irq_handler sees the is_enabled value */
4850 smp_wmb();
4851 /* wait for current handler to finish before turning the DISPC off */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004852 synchronize_irq(dispc->irq);
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004853
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004854 dispc_save_context(dispc);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004855
4856 return 0;
4857}
4858
4859static int dispc_runtime_resume(struct device *dev)
4860{
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004861 struct dispc_device *dispc = dev_get_drvdata(dev);
4862
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004863 /*
4864 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4865 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4866 * _omap_dispc_initial_config(). We can thus use it to detect if
4867 * we have lost register context.
4868 */
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004869 if (REG_GET(dispc, DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
4870 _omap_dispc_initial_config(dispc);
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004871
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004872 dispc_errata_i734_wa(dispc);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004873
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004874 dispc_restore_context(dispc);
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004875
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004876 dispc_restore_gamma_tables(dispc);
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004877 }
Tomi Valkeinenbe07dcd72013-11-21 16:01:40 +02004878
Laurent Pinchart1f6b6b62018-02-13 14:00:44 +02004879 dispc->is_enabled = true;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004880 /* ensure the dispc_irq_handler sees the is_enabled value */
4881 smp_wmb();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004882
4883 return 0;
4884}
4885
4886static const struct dev_pm_ops dispc_pm_ops = {
4887 .runtime_suspend = dispc_runtime_suspend,
4888 .runtime_resume = dispc_runtime_resume,
4889};
4890
Andrew F. Davisd66c36a2017-12-05 14:29:32 -06004891struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004892 .probe = dispc_probe,
4893 .remove = dispc_remove,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004894 .driver = {
4895 .name = "omapdss_dispc",
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004896 .pm = &dispc_pm_ops,
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004897 .of_match_table = dispc_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +03004898 .suppress_bind_attrs = true,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004899 },
4900};