blob: 77d10bf9285f29c5893abcfbea08d55812aea6da [file] [log] [blame]
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001/*
2 * linux/drivers/video/omap2/dss/dispc.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#define DSS_SUBSYS_NAME "DISPC"
24
25#include <linux/kernel.h>
26#include <linux/dma-mapping.h>
27#include <linux/vmalloc.h>
Paul Gortmakera8a35932011-07-10 13:20:26 -040028#include <linux/export.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020029#include <linux/clk.h>
30#include <linux/io.h>
31#include <linux/jiffies.h>
32#include <linux/seq_file.h>
33#include <linux/delay.h>
34#include <linux/workqueue.h>
Tomi Valkeinenab83b142010-06-09 15:31:01 +030035#include <linux/hardirq.h>
Tomi Valkeinen24e62892011-05-23 11:51:18 +030036#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030037#include <linux/pm_runtime.h>
Tomi Valkeinen33366d02012-09-28 13:54:35 +030038#include <linux/sizes.h>
Tomi Valkeinen0006fd62014-09-05 19:15:03 +000039#include <linux/mfd/syscon.h>
40#include <linux/regmap.h>
41#include <linux/of.h>
Tomi Valkeinen736e60d2015-06-04 15:22:23 +030042#include <linux/component.h>
Tomi Valkeinen80c39712009-11-12 11:41:42 +020043
Peter Ujfalusi32043da2016-05-27 14:40:49 +030044#include "omapdss.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020045#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053046#include "dss_features.h"
Archit Taneja9b372c22011-05-06 11:45:49 +053047#include "dispc.h"
Tomi Valkeinen80c39712009-11-12 11:41:42 +020048
49/* DISPC */
Sumit Semwal8613b002010-12-02 11:27:09 +000050#define DISPC_SZ_REGS SZ_4K
Tomi Valkeinen80c39712009-11-12 11:41:42 +020051
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030052enum omap_burst_size {
53 BURST_SIZE_X2 = 0,
54 BURST_SIZE_X4 = 1,
55 BURST_SIZE_X8 = 2,
56};
57
Tomi Valkeinen80c39712009-11-12 11:41:42 +020058#define REG_GET(idx, start, end) \
59 FLD_GET(dispc_read_reg(idx), start, end)
60
61#define REG_FLD_MOD(idx, val, start, end) \
62 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
63
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053064struct dispc_features {
65 u8 sw_start;
66 u8 fp_start;
67 u8 bp_start;
68 u16 sw_max;
69 u16 vp_max;
70 u16 hp_max;
Archit Taneja33b89922012-11-14 13:50:15 +053071 u8 mgr_width_start;
72 u8 mgr_height_start;
73 u16 mgr_width_max;
74 u16 mgr_height_max;
Archit Tanejaca5ca692013-03-26 19:15:22 +053075 unsigned long max_lcd_pclk;
76 unsigned long max_tv_pclk;
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +030077 int (*calc_scaling) (unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030078 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +053079 u16 width, u16 height, u16 out_width, u16 out_height,
80 enum omap_color_mode color_mode, bool *five_taps,
81 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +053082 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
Tomi Valkeinen8702ee52012-10-19 15:36:11 +030083 unsigned long (*calc_core_clk) (unsigned long pclk,
Archit Taneja8ba85302012-09-26 17:00:37 +053084 u16 width, u16 height, u16 out_width, u16 out_height,
85 bool mem_to_mem);
Tomi Valkeinen42a69612012-08-22 16:56:57 +030086 u8 num_fifos;
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +030087
88 /* swap GFX & WB fifos */
89 bool gfx_fifo_workaround:1;
Tomi Valkeinencffa9472012-11-08 10:01:33 +020090
91 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
92 bool no_framedone_tv:1;
Archit Tanejad0df9a22013-03-26 19:15:25 +053093
94 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
95 bool mstandby_workaround:1;
Archit Taneja8bc65552013-12-17 16:40:21 +053096
97 bool set_max_preload:1;
Tomi Valkeinenf2aee312015-04-10 12:48:34 +030098
99 /* PIXEL_INC is not added to the last pixel of a line */
100 bool last_pixel_inc_missing:1;
Tomi Valkeinene5f80912015-10-21 13:08:59 +0300101
102 /* POL_FREQ has ALIGN bit */
103 bool supports_sync_align:1;
Tomi Valkeinen20efbc32015-11-04 17:10:44 +0200104
105 bool has_writeback:1;
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +0200106
107 bool supports_double_pixel:1;
Tomi Valkeinenb7536d62016-01-13 18:41:36 +0200108
109 /*
110 * Field order for VENC is different than HDMI. We should handle this in
111 * some intelligent manner, but as the SoCs have either HDMI or VENC,
112 * never both, we can just use this flag for now.
113 */
114 bool reverse_ilace_field_order:1;
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300115
116 bool has_gamma_table:1;
Jyri Sarhafbff0102016-06-07 15:09:16 +0300117
118 bool has_gamma_i734_bug:1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530119};
120
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300121#define DISPC_MAX_NR_FIFOS 5
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300122#define DISPC_MAX_CHANNEL_GAMMA 4
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300123
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200124static struct {
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +0000125 struct platform_device *pdev;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200126 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300127
archit tanejaaffe3602011-02-23 08:41:03 +0000128 int irq;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300129 irq_handler_t user_handler;
130 void *user_data;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200131
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200132 unsigned long core_clk_rate;
Tomi Valkeinen5391e872013-05-16 10:44:13 +0300133 unsigned long tv_pclk_rate;
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +0200134
Tomi Valkeinen42a69612012-08-22 16:56:57 +0300135 u32 fifo_size[DISPC_MAX_NR_FIFOS];
136 /* maps which plane is using a fifo. fifo-id -> plane-id */
137 int fifo_assignment[DISPC_MAX_NR_FIFOS];
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200138
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300139 bool ctx_valid;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200140 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200141
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300142 u32 *gamma_table[DISPC_MAX_CHANNEL_GAMMA];
143
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +0530144 const struct dispc_features *feat;
Tomi Valkeinen0925afc2014-04-11 13:49:55 +0300145
146 bool is_enabled;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +0000147
148 struct regmap *syscon_pol;
149 u32 syscon_pol_offset;
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200150
151 /* DISPC_CONTROL & DISPC_CONFIG lock*/
152 spinlock_t control_lock;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200153} dispc;
154
Amber Jain0d66cbb2011-05-19 19:47:54 +0530155enum omap_color_component {
156 /* used for all color formats for OMAP3 and earlier
157 * and for RGB and Y color component on OMAP4
158 */
159 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
160 /* used for UV component for
161 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
162 * color formats on OMAP4
163 */
164 DISPC_COLOR_COMPONENT_UV = 1 << 1,
165};
166
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530167enum mgr_reg_fields {
168 DISPC_MGR_FLD_ENABLE,
169 DISPC_MGR_FLD_STNTFT,
170 DISPC_MGR_FLD_GO,
171 DISPC_MGR_FLD_TFTDATALINES,
172 DISPC_MGR_FLD_STALLMODE,
173 DISPC_MGR_FLD_TCKENABLE,
174 DISPC_MGR_FLD_TCKSELECTION,
175 DISPC_MGR_FLD_CPR,
176 DISPC_MGR_FLD_FIFOHANDCHECK,
177 /* used to maintain a count of the above fields */
178 DISPC_MGR_FLD_NUM,
179};
180
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300181struct dispc_reg_field {
182 u16 reg;
183 u8 high;
184 u8 low;
185};
186
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300187struct dispc_gamma_desc {
188 u32 len;
189 u32 bits;
190 u16 reg;
191 bool has_index;
192};
193
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530194static const struct {
195 const char *name;
196 u32 vsync_irq;
197 u32 framedone_irq;
198 u32 sync_lost_irq;
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300199 struct dispc_gamma_desc gamma;
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300200 struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530201} mgr_desc[] = {
202 [OMAP_DSS_CHANNEL_LCD] = {
203 .name = "LCD",
204 .vsync_irq = DISPC_IRQ_VSYNC,
205 .framedone_irq = DISPC_IRQ_FRAMEDONE,
206 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300207 .gamma = {
208 .len = 256,
209 .bits = 8,
210 .reg = DISPC_GAMMA_TABLE0,
211 .has_index = true,
212 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530213 .reg_desc = {
214 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
215 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
216 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
217 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
218 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
219 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
220 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
221 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
222 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
223 },
224 },
225 [OMAP_DSS_CHANNEL_DIGIT] = {
226 .name = "DIGIT",
227 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200228 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530229 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300230 .gamma = {
231 .len = 1024,
232 .bits = 10,
233 .reg = DISPC_GAMMA_TABLE2,
234 .has_index = false,
235 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530236 .reg_desc = {
237 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
238 [DISPC_MGR_FLD_STNTFT] = { },
239 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
240 [DISPC_MGR_FLD_TFTDATALINES] = { },
241 [DISPC_MGR_FLD_STALLMODE] = { },
242 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
243 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
244 [DISPC_MGR_FLD_CPR] = { },
245 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
246 },
247 },
248 [OMAP_DSS_CHANNEL_LCD2] = {
249 .name = "LCD2",
250 .vsync_irq = DISPC_IRQ_VSYNC2,
251 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
252 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300253 .gamma = {
254 .len = 256,
255 .bits = 8,
256 .reg = DISPC_GAMMA_TABLE1,
257 .has_index = true,
258 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530259 .reg_desc = {
260 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
261 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
262 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
263 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
264 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
265 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
266 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
267 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
268 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
269 },
270 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530271 [OMAP_DSS_CHANNEL_LCD3] = {
272 .name = "LCD3",
273 .vsync_irq = DISPC_IRQ_VSYNC3,
274 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
275 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
Jyri Sarhaacc3a232016-06-07 15:09:15 +0300276 .gamma = {
277 .len = 256,
278 .bits = 8,
279 .reg = DISPC_GAMMA_TABLE3,
280 .has_index = true,
281 },
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530282 .reg_desc = {
283 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
284 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
285 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
286 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
287 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
288 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
289 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
290 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
291 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
292 },
293 },
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530294};
295
Archit Taneja6e5264b2012-09-11 12:04:47 +0530296struct color_conv_coef {
297 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
298 int full_range;
299};
300
Tomi Valkeinen65904152015-11-04 17:10:57 +0200301static unsigned long dispc_fclk_rate(void);
302static unsigned long dispc_core_clk_rate(void);
303static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel);
304static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel);
305
Jyri Sarha864050c2017-03-24 16:47:52 +0200306static unsigned long dispc_plane_pclk_rate(enum omap_plane_id plane);
307static unsigned long dispc_plane_lclk_rate(enum omap_plane_id plane);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200308
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200309static void dispc_clear_irqstatus(u32 mask);
310static bool dispc_mgr_is_enabled(enum omap_channel channel);
311static void dispc_clear_irqstatus(u32 mask);
312
Archit Taneja55978cc2011-05-06 11:45:51 +0530313static inline void dispc_write_reg(const u16 idx, u32 val)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200314{
Archit Taneja55978cc2011-05-06 11:45:51 +0530315 __raw_writel(val, dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200316}
317
Archit Taneja55978cc2011-05-06 11:45:51 +0530318static inline u32 dispc_read_reg(const u16 idx)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200319{
Archit Taneja55978cc2011-05-06 11:45:51 +0530320 return __raw_readl(dispc.base + idx);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200321}
322
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530323static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
324{
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300325 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530326 return REG_GET(rfld.reg, rfld.high, rfld.low);
327}
328
329static void mgr_fld_write(enum omap_channel channel,
330 enum mgr_reg_fields regfld, int val) {
Jyri Sarha5c348ba2014-04-11 16:25:06 +0300331 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200332 const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG;
333 unsigned long flags;
334
335 if (need_lock)
336 spin_lock_irqsave(&dispc.control_lock, flags);
337
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530338 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
Tomi Valkeinend49cd152014-11-10 12:23:00 +0200339
340 if (need_lock)
341 spin_unlock_irqrestore(&dispc.control_lock, flags);
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530342}
343
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200344#define SR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530345 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200346#define RR(reg) \
Archit Taneja55978cc2011-05-06 11:45:51 +0530347 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200348
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300349static void dispc_save_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200350{
Archit Tanejac6104b82011-08-05 19:06:02 +0530351 int i, j;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200352
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300353 DSSDBG("dispc_save_context\n");
354
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200355 SR(IRQENABLE);
356 SR(CONTROL);
357 SR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200358 SR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530359 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
360 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300361 SR(GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000362 if (dss_has_feature(FEAT_MGR_LCD2)) {
363 SR(CONTROL2);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000364 SR(CONFIG2);
365 }
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530366 if (dss_has_feature(FEAT_MGR_LCD3)) {
367 SR(CONTROL3);
368 SR(CONFIG3);
369 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200370
Archit Tanejac6104b82011-08-05 19:06:02 +0530371 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
372 SR(DEFAULT_COLOR(i));
373 SR(TRANS_COLOR(i));
374 SR(SIZE_MGR(i));
375 if (i == OMAP_DSS_CHANNEL_DIGIT)
376 continue;
377 SR(TIMING_H(i));
378 SR(TIMING_V(i));
379 SR(POL_FREQ(i));
380 SR(DIVISORo(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200381
Archit Tanejac6104b82011-08-05 19:06:02 +0530382 SR(DATA_CYCLE1(i));
383 SR(DATA_CYCLE2(i));
384 SR(DATA_CYCLE3(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200385
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300386 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530387 SR(CPR_COEF_R(i));
388 SR(CPR_COEF_G(i));
389 SR(CPR_COEF_B(i));
390 }
391 }
392
393 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
394 SR(OVL_BA0(i));
395 SR(OVL_BA1(i));
396 SR(OVL_POSITION(i));
397 SR(OVL_SIZE(i));
398 SR(OVL_ATTRIBUTES(i));
399 SR(OVL_FIFO_THRESHOLD(i));
400 SR(OVL_ROW_INC(i));
401 SR(OVL_PIXEL_INC(i));
402 if (dss_has_feature(FEAT_PRELOAD))
403 SR(OVL_PRELOAD(i));
404 if (i == OMAP_DSS_GFX) {
405 SR(OVL_WINDOW_SKIP(i));
406 SR(OVL_TABLE_BA(i));
407 continue;
408 }
409 SR(OVL_FIR(i));
410 SR(OVL_PICTURE_SIZE(i));
411 SR(OVL_ACCU0(i));
412 SR(OVL_ACCU1(i));
413
414 for (j = 0; j < 8; j++)
415 SR(OVL_FIR_COEF_H(i, j));
416
417 for (j = 0; j < 8; j++)
418 SR(OVL_FIR_COEF_HV(i, j));
419
420 for (j = 0; j < 5; j++)
421 SR(OVL_CONV_COEF(i, j));
422
423 if (dss_has_feature(FEAT_FIR_COEF_V)) {
424 for (j = 0; j < 8; j++)
425 SR(OVL_FIR_COEF_V(i, j));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300426 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000427
Archit Tanejac6104b82011-08-05 19:06:02 +0530428 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
429 SR(OVL_BA0_UV(i));
430 SR(OVL_BA1_UV(i));
431 SR(OVL_FIR2(i));
432 SR(OVL_ACCU2_0(i));
433 SR(OVL_ACCU2_1(i));
434
435 for (j = 0; j < 8; j++)
436 SR(OVL_FIR_COEF_H2(i, j));
437
438 for (j = 0; j < 8; j++)
439 SR(OVL_FIR_COEF_HV2(i, j));
440
441 for (j = 0; j < 8; j++)
442 SR(OVL_FIR_COEF_V2(i, j));
443 }
444 if (dss_has_feature(FEAT_ATTR2))
445 SR(OVL_ATTRIBUTES2(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000446 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200447
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600448 if (dss_has_feature(FEAT_CORE_CLK_DIV))
449 SR(DIVISOR);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300450
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300451 dispc.ctx_valid = true;
452
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200453 DSSDBG("context saved\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200454}
455
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300456static void dispc_restore_context(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200457{
Tomi Valkeinen9229b512014-02-14 09:37:09 +0200458 int i, j;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300459
460 DSSDBG("dispc_restore_context\n");
461
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300462 if (!dispc.ctx_valid)
463 return;
464
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200465 /*RR(IRQENABLE);*/
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200466 /*RR(CONTROL);*/
467 RR(CONFIG);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200468 RR(LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +0530469 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
470 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300471 RR(GLOBAL_ALPHA);
Archit Tanejac6104b82011-08-05 19:06:02 +0530472 if (dss_has_feature(FEAT_MGR_LCD2))
Sumit Semwal2a205f32010-12-02 11:27:12 +0000473 RR(CONFIG2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530474 if (dss_has_feature(FEAT_MGR_LCD3))
475 RR(CONFIG3);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200476
Archit Tanejac6104b82011-08-05 19:06:02 +0530477 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
478 RR(DEFAULT_COLOR(i));
479 RR(TRANS_COLOR(i));
480 RR(SIZE_MGR(i));
481 if (i == OMAP_DSS_CHANNEL_DIGIT)
482 continue;
483 RR(TIMING_H(i));
484 RR(TIMING_V(i));
485 RR(POL_FREQ(i));
486 RR(DIVISORo(i));
Archit Taneja9b372c22011-05-06 11:45:49 +0530487
Archit Tanejac6104b82011-08-05 19:06:02 +0530488 RR(DATA_CYCLE1(i));
489 RR(DATA_CYCLE2(i));
490 RR(DATA_CYCLE3(i));
Sumit Semwal2a205f32010-12-02 11:27:12 +0000491
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300492 if (dss_has_feature(FEAT_CPR)) {
Archit Tanejac6104b82011-08-05 19:06:02 +0530493 RR(CPR_COEF_R(i));
494 RR(CPR_COEF_G(i));
495 RR(CPR_COEF_B(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300496 }
Sumit Semwal2a205f32010-12-02 11:27:12 +0000497 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200498
Archit Tanejac6104b82011-08-05 19:06:02 +0530499 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
500 RR(OVL_BA0(i));
501 RR(OVL_BA1(i));
502 RR(OVL_POSITION(i));
503 RR(OVL_SIZE(i));
504 RR(OVL_ATTRIBUTES(i));
505 RR(OVL_FIFO_THRESHOLD(i));
506 RR(OVL_ROW_INC(i));
507 RR(OVL_PIXEL_INC(i));
508 if (dss_has_feature(FEAT_PRELOAD))
509 RR(OVL_PRELOAD(i));
510 if (i == OMAP_DSS_GFX) {
511 RR(OVL_WINDOW_SKIP(i));
512 RR(OVL_TABLE_BA(i));
513 continue;
514 }
515 RR(OVL_FIR(i));
516 RR(OVL_PICTURE_SIZE(i));
517 RR(OVL_ACCU0(i));
518 RR(OVL_ACCU1(i));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200519
Archit Tanejac6104b82011-08-05 19:06:02 +0530520 for (j = 0; j < 8; j++)
521 RR(OVL_FIR_COEF_H(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200522
Archit Tanejac6104b82011-08-05 19:06:02 +0530523 for (j = 0; j < 8; j++)
524 RR(OVL_FIR_COEF_HV(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200525
Archit Tanejac6104b82011-08-05 19:06:02 +0530526 for (j = 0; j < 5; j++)
527 RR(OVL_CONV_COEF(i, j));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200528
Archit Tanejac6104b82011-08-05 19:06:02 +0530529 if (dss_has_feature(FEAT_FIR_COEF_V)) {
530 for (j = 0; j < 8; j++)
531 RR(OVL_FIR_COEF_V(i, j));
532 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200533
Archit Tanejac6104b82011-08-05 19:06:02 +0530534 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
535 RR(OVL_BA0_UV(i));
536 RR(OVL_BA1_UV(i));
537 RR(OVL_FIR2(i));
538 RR(OVL_ACCU2_0(i));
539 RR(OVL_ACCU2_1(i));
540
541 for (j = 0; j < 8; j++)
542 RR(OVL_FIR_COEF_H2(i, j));
543
544 for (j = 0; j < 8; j++)
545 RR(OVL_FIR_COEF_HV2(i, j));
546
547 for (j = 0; j < 8; j++)
548 RR(OVL_FIR_COEF_V2(i, j));
549 }
550 if (dss_has_feature(FEAT_ATTR2))
551 RR(OVL_ATTRIBUTES2(i));
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300552 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200553
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -0600554 if (dss_has_feature(FEAT_CORE_CLK_DIV))
555 RR(DIVISOR);
556
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200557 /* enable last, because LCD & DIGIT enable are here */
558 RR(CONTROL);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000559 if (dss_has_feature(FEAT_MGR_LCD2))
560 RR(CONTROL2);
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530561 if (dss_has_feature(FEAT_MGR_LCD3))
562 RR(CONTROL3);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200563 /* clear spurious SYNC_LOST_DIGIT interrupts */
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +0300564 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
Ville Syrjälä75c7d592010-03-05 01:13:11 +0200565
566 /*
567 * enable last so IRQs won't trigger before
568 * the context is fully restored
569 */
570 RR(IRQENABLE);
Tomi Valkeinen49ea86f2011-06-01 15:54:06 +0300571
572 DSSDBG("context restored\n");
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200573}
574
575#undef SR
576#undef RR
577
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300578int dispc_runtime_get(void)
579{
580 int r;
581
582 DSSDBG("dispc_runtime_get\n");
583
584 r = pm_runtime_get_sync(&dispc.pdev->dev);
585 WARN_ON(r < 0);
586 return r < 0 ? r : 0;
587}
588
589void dispc_runtime_put(void)
590{
591 int r;
592
593 DSSDBG("dispc_runtime_put\n");
594
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200595 r = pm_runtime_put_sync(&dispc.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300596 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300597}
598
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200599static u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200600{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530601 return mgr_desc[channel].vsync_irq;
Tomi Valkeinen3dcec4d2011-11-07 15:50:09 +0200602}
603
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200604static u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200605{
Tomi Valkeinencffa9472012-11-08 10:01:33 +0200606 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv)
607 return 0;
608
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530609 return mgr_desc[channel].framedone_irq;
Tomi Valkeinen7d1365c2011-11-18 15:39:52 +0200610}
611
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200612static u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
Tomi Valkeinencb699202012-10-17 10:38:52 +0300613{
614 return mgr_desc[channel].sync_lost_irq;
615}
616
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530617u32 dispc_wb_get_framedone_irq(void)
618{
619 return DISPC_IRQ_FRAMEDONEWB;
620}
621
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200622static void dispc_mgr_enable(enum omap_channel channel, bool enable)
Laurent Pinchart03af8152016-04-18 03:09:48 +0300623{
624 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
625 /* flush posted write */
626 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
627}
Laurent Pinchart03af8152016-04-18 03:09:48 +0300628
629static bool dispc_mgr_is_enabled(enum omap_channel channel)
630{
631 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
632}
633
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200634static bool dispc_mgr_go_busy(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200635{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530636 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200637}
638
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +0200639static void dispc_mgr_go(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200640{
Luis de Bethencourt0bcfdba2015-10-15 13:29:38 +0100641 WARN_ON(!dispc_mgr_is_enabled(channel));
Tomi Valkeinen3c91ee82012-10-19 15:06:07 +0300642 WARN_ON(dispc_mgr_go_busy(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200643
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530644 DSSDBG("GO %s\n", mgr_desc[channel].name);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200645
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +0530646 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200647}
648
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530649bool dispc_wb_go_busy(void)
650{
651 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
652}
653
654void dispc_wb_go(void)
655{
Jyri Sarha864050c2017-03-24 16:47:52 +0200656 enum omap_plane_id plane = OMAP_DSS_WB;
Archit Taneja0b23e5b2012-09-22 12:39:33 +0530657 bool enable, go;
658
659 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
660
661 if (!enable)
662 return;
663
664 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
665 if (go) {
666 DSSERR("GO bit not down for WB\n");
667 return;
668 }
669
670 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
671}
672
Jyri Sarha864050c2017-03-24 16:47:52 +0200673static void dispc_ovl_write_firh_reg(enum omap_plane_id plane, int reg,
674 u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200675{
Archit Taneja9b372c22011-05-06 11:45:49 +0530676 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200677}
678
Jyri Sarha864050c2017-03-24 16:47:52 +0200679static void dispc_ovl_write_firhv_reg(enum omap_plane_id plane, int reg,
680 u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200681{
Archit Taneja9b372c22011-05-06 11:45:49 +0530682 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200683}
684
Jyri Sarha864050c2017-03-24 16:47:52 +0200685static void dispc_ovl_write_firv_reg(enum omap_plane_id plane, int reg,
686 u32 value)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200687{
Archit Taneja9b372c22011-05-06 11:45:49 +0530688 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200689}
690
Jyri Sarha864050c2017-03-24 16:47:52 +0200691static void dispc_ovl_write_firh2_reg(enum omap_plane_id plane, int reg,
692 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530693{
694 BUG_ON(plane == OMAP_DSS_GFX);
695
696 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
697}
698
Jyri Sarha864050c2017-03-24 16:47:52 +0200699static void dispc_ovl_write_firhv2_reg(enum omap_plane_id plane, int reg,
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300700 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530701{
702 BUG_ON(plane == OMAP_DSS_GFX);
703
704 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
705}
706
Jyri Sarha864050c2017-03-24 16:47:52 +0200707static void dispc_ovl_write_firv2_reg(enum omap_plane_id plane, int reg,
708 u32 value)
Amber Jainab5ca072011-05-19 19:47:53 +0530709{
710 BUG_ON(plane == OMAP_DSS_GFX);
711
712 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
713}
714
Jyri Sarha864050c2017-03-24 16:47:52 +0200715static void dispc_ovl_set_scale_coef(enum omap_plane_id plane, int fir_hinc,
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530716 int fir_vinc, int five_taps,
717 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200718{
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530719 const struct dispc_coef *h_coef, *v_coef;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200720 int i;
721
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530722 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
723 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200724
725 for (i = 0; i < 8; i++) {
726 u32 h, hv;
727
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530728 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
729 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
730 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
731 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
732 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
733 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
734 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
735 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200736
Amber Jain0d66cbb2011-05-19 19:47:54 +0530737 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300738 dispc_ovl_write_firh_reg(plane, i, h);
739 dispc_ovl_write_firhv_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530740 } else {
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300741 dispc_ovl_write_firh2_reg(plane, i, h);
742 dispc_ovl_write_firhv2_reg(plane, i, hv);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530743 }
744
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200745 }
746
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200747 if (five_taps) {
748 for (i = 0; i < 8; i++) {
749 u32 v;
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +0530750 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
751 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530752 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300753 dispc_ovl_write_firv_reg(plane, i, v);
Amber Jain0d66cbb2011-05-19 19:47:54 +0530754 else
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +0300755 dispc_ovl_write_firv2_reg(plane, i, v);
Grazvydas Ignotas66be8f62010-08-24 15:18:43 +0200756 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200757 }
758}
759
Archit Taneja6e5264b2012-09-11 12:04:47 +0530760
Jyri Sarha864050c2017-03-24 16:47:52 +0200761static void dispc_ovl_write_color_conv_coef(enum omap_plane_id plane,
Archit Taneja6e5264b2012-09-11 12:04:47 +0530762 const struct color_conv_coef *ct)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200763{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200764#define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
765
Archit Taneja6e5264b2012-09-11 12:04:47 +0530766 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
767 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
768 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
769 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
770 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200771
Archit Taneja6e5264b2012-09-11 12:04:47 +0530772 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200773
774#undef CVAL
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200775}
776
Archit Taneja6e5264b2012-09-11 12:04:47 +0530777static void dispc_setup_color_conv_coef(void)
778{
779 int i;
780 int num_ovl = dss_feat_get_num_ovls();
Archit Taneja6e5264b2012-09-11 12:04:47 +0530781 const struct color_conv_coef ctbl_bt601_5_ovl = {
Tomi Valkeinen7d18bbe2015-11-04 17:10:52 +0200782 /* YUV -> RGB */
Archit Taneja6e5264b2012-09-11 12:04:47 +0530783 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
784 };
785 const struct color_conv_coef ctbl_bt601_5_wb = {
Tomi Valkeinen7d18bbe2015-11-04 17:10:52 +0200786 /* RGB -> YUV */
787 66, 129, 25, 112, -94, -18, -38, -74, 112, 0,
Archit Taneja6e5264b2012-09-11 12:04:47 +0530788 };
789
790 for (i = 1; i < num_ovl; i++)
791 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
792
Tomi Valkeinen20efbc32015-11-04 17:10:44 +0200793 if (dispc.feat->has_writeback)
794 dispc_ovl_write_color_conv_coef(OMAP_DSS_WB, &ctbl_bt601_5_wb);
Archit Taneja6e5264b2012-09-11 12:04:47 +0530795}
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200796
Jyri Sarha864050c2017-03-24 16:47:52 +0200797static void dispc_ovl_set_ba0(enum omap_plane_id plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200798{
Archit Taneja9b372c22011-05-06 11:45:49 +0530799 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200800}
801
Jyri Sarha864050c2017-03-24 16:47:52 +0200802static void dispc_ovl_set_ba1(enum omap_plane_id plane, u32 paddr)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200803{
Archit Taneja9b372c22011-05-06 11:45:49 +0530804 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200805}
806
Jyri Sarha864050c2017-03-24 16:47:52 +0200807static void dispc_ovl_set_ba0_uv(enum omap_plane_id plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530808{
809 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
810}
811
Jyri Sarha864050c2017-03-24 16:47:52 +0200812static void dispc_ovl_set_ba1_uv(enum omap_plane_id plane, u32 paddr)
Amber Jainab5ca072011-05-19 19:47:53 +0530813{
814 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
815}
816
Jyri Sarha864050c2017-03-24 16:47:52 +0200817static void dispc_ovl_set_pos(enum omap_plane_id plane,
Archit Tanejad79db852012-09-22 12:30:17 +0530818 enum omap_overlay_caps caps, int x, int y)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200819{
Archit Tanejad79db852012-09-22 12:30:17 +0530820 u32 val;
821
822 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
823 return;
824
825 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530826
827 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200828}
829
Jyri Sarha864050c2017-03-24 16:47:52 +0200830static void dispc_ovl_set_input_size(enum omap_plane_id plane, int width,
Archit Taneja78b687f2012-09-21 14:51:49 +0530831 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200832{
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200833 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530834
Archit Taneja36d87d92012-07-28 22:59:03 +0530835 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
Archit Taneja9b372c22011-05-06 11:45:49 +0530836 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
837 else
838 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200839}
840
Jyri Sarha864050c2017-03-24 16:47:52 +0200841static void dispc_ovl_set_output_size(enum omap_plane_id plane, int width,
Archit Taneja78b687f2012-09-21 14:51:49 +0530842 int height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200843{
844 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200845
846 BUG_ON(plane == OMAP_DSS_GFX);
847
848 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
Archit Taneja9b372c22011-05-06 11:45:49 +0530849
Archit Taneja36d87d92012-07-28 22:59:03 +0530850 if (plane == OMAP_DSS_WB)
851 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
852 else
853 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200854}
855
Jyri Sarha864050c2017-03-24 16:47:52 +0200856static void dispc_ovl_set_zorder(enum omap_plane_id plane,
Archit Taneja5b54ed32012-09-26 16:55:27 +0530857 enum omap_overlay_caps caps, u8 zorder)
Archit Taneja54128702011-09-08 11:29:17 +0530858{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530859 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
Archit Taneja54128702011-09-08 11:29:17 +0530860 return;
861
862 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
863}
864
865static void dispc_ovl_enable_zorder_planes(void)
866{
867 int i;
868
869 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
870 return;
871
872 for (i = 0; i < dss_feat_get_num_ovls(); i++)
873 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
874}
875
Jyri Sarha864050c2017-03-24 16:47:52 +0200876static void dispc_ovl_set_pre_mult_alpha(enum omap_plane_id plane,
Archit Taneja5b54ed32012-09-26 16:55:27 +0530877 enum omap_overlay_caps caps, bool enable)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100878{
Archit Taneja5b54ed32012-09-26 16:55:27 +0530879 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100880 return;
881
Archit Taneja9b372c22011-05-06 11:45:49 +0530882 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100883}
884
Jyri Sarha864050c2017-03-24 16:47:52 +0200885static void dispc_ovl_setup_global_alpha(enum omap_plane_id plane,
Archit Taneja5b54ed32012-09-26 16:55:27 +0530886 enum omap_overlay_caps caps, u8 global_alpha)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200887{
Archit Tanejab8c095b2011-09-13 18:20:33 +0530888 static const unsigned shifts[] = { 0, 8, 16, 24, };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300889 int shift;
890
Archit Taneja5b54ed32012-09-26 16:55:27 +0530891 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Rajkumar Nfd28a392010-11-04 12:28:42 +0100892 return;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530893
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +0300894 shift = shifts[plane];
895 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200896}
897
Jyri Sarha864050c2017-03-24 16:47:52 +0200898static void dispc_ovl_set_pix_inc(enum omap_plane_id plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200899{
Archit Taneja9b372c22011-05-06 11:45:49 +0530900 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200901}
902
Jyri Sarha864050c2017-03-24 16:47:52 +0200903static void dispc_ovl_set_row_inc(enum omap_plane_id plane, s32 inc)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200904{
Archit Taneja9b372c22011-05-06 11:45:49 +0530905 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200906}
907
Jyri Sarha864050c2017-03-24 16:47:52 +0200908static void dispc_ovl_set_color_mode(enum omap_plane_id plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200909 enum omap_color_mode color_mode)
910{
911 u32 m = 0;
Amber Jainf20e4222011-05-19 19:47:50 +0530912 if (plane != OMAP_DSS_GFX) {
913 switch (color_mode) {
914 case OMAP_DSS_COLOR_NV12:
915 m = 0x0; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530916 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530917 m = 0x1; break;
918 case OMAP_DSS_COLOR_RGBA16:
919 m = 0x2; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530920 case OMAP_DSS_COLOR_RGB12U:
Amber Jainf20e4222011-05-19 19:47:50 +0530921 m = 0x4; break;
922 case OMAP_DSS_COLOR_ARGB16:
923 m = 0x5; break;
924 case OMAP_DSS_COLOR_RGB16:
925 m = 0x6; break;
926 case OMAP_DSS_COLOR_ARGB16_1555:
927 m = 0x7; break;
928 case OMAP_DSS_COLOR_RGB24U:
929 m = 0x8; break;
930 case OMAP_DSS_COLOR_RGB24P:
931 m = 0x9; break;
932 case OMAP_DSS_COLOR_YUV2:
933 m = 0xa; break;
934 case OMAP_DSS_COLOR_UYVY:
935 m = 0xb; break;
936 case OMAP_DSS_COLOR_ARGB32:
937 m = 0xc; break;
938 case OMAP_DSS_COLOR_RGBA32:
939 m = 0xd; break;
940 case OMAP_DSS_COLOR_RGBX32:
941 m = 0xe; break;
942 case OMAP_DSS_COLOR_XRGB16_1555:
943 m = 0xf; break;
944 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300945 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530946 }
947 } else {
948 switch (color_mode) {
Amber Jainf20e4222011-05-19 19:47:50 +0530949 case OMAP_DSS_COLOR_RGB12U:
950 m = 0x4; break;
951 case OMAP_DSS_COLOR_ARGB16:
952 m = 0x5; break;
953 case OMAP_DSS_COLOR_RGB16:
954 m = 0x6; break;
955 case OMAP_DSS_COLOR_ARGB16_1555:
956 m = 0x7; break;
957 case OMAP_DSS_COLOR_RGB24U:
958 m = 0x8; break;
959 case OMAP_DSS_COLOR_RGB24P:
960 m = 0x9; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530961 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530962 m = 0xa; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530963 case OMAP_DSS_COLOR_RGBA16:
Amber Jainf20e4222011-05-19 19:47:50 +0530964 m = 0xb; break;
965 case OMAP_DSS_COLOR_ARGB32:
966 m = 0xc; break;
967 case OMAP_DSS_COLOR_RGBA32:
968 m = 0xd; break;
969 case OMAP_DSS_COLOR_RGBX32:
970 m = 0xe; break;
971 case OMAP_DSS_COLOR_XRGB16_1555:
972 m = 0xf; break;
973 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300974 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530975 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200976 }
977
Archit Taneja9b372c22011-05-06 11:45:49 +0530978 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200979}
980
Jyri Sarha864050c2017-03-24 16:47:52 +0200981static void dispc_ovl_configure_burst_type(enum omap_plane_id plane,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530982 enum omap_dss_rotation_type rotation_type)
983{
984 if (dss_has_feature(FEAT_BURST_2D) == 0)
985 return;
986
987 if (rotation_type == OMAP_DSS_ROT_TILER)
988 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
989 else
990 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
991}
992
Jyri Sarha864050c2017-03-24 16:47:52 +0200993static void dispc_ovl_set_channel_out(enum omap_plane_id plane,
994 enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200995{
996 int shift;
997 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +0000998 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200999
1000 switch (plane) {
1001 case OMAP_DSS_GFX:
1002 shift = 8;
1003 break;
1004 case OMAP_DSS_VIDEO1:
1005 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +05301006 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001007 shift = 16;
1008 break;
1009 default:
1010 BUG();
1011 return;
1012 }
1013
Archit Taneja9b372c22011-05-06 11:45:49 +05301014 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +00001015 if (dss_has_feature(FEAT_MGR_LCD2)) {
1016 switch (channel) {
1017 case OMAP_DSS_CHANNEL_LCD:
1018 chan = 0;
1019 chan2 = 0;
1020 break;
1021 case OMAP_DSS_CHANNEL_DIGIT:
1022 chan = 1;
1023 chan2 = 0;
1024 break;
1025 case OMAP_DSS_CHANNEL_LCD2:
1026 chan = 0;
1027 chan2 = 1;
1028 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05301029 case OMAP_DSS_CHANNEL_LCD3:
1030 if (dss_has_feature(FEAT_MGR_LCD3)) {
1031 chan = 0;
1032 chan2 = 2;
1033 } else {
1034 BUG();
1035 return;
1036 }
1037 break;
Tomi Valkeinenc2665c42015-11-04 17:10:47 +02001038 case OMAP_DSS_CHANNEL_WB:
1039 chan = 0;
1040 chan2 = 3;
1041 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001042 default:
1043 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001044 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001045 }
1046
1047 val = FLD_MOD(val, chan, shift, shift);
1048 val = FLD_MOD(val, chan2, 31, 30);
1049 } else {
1050 val = FLD_MOD(val, channel, shift, shift);
1051 }
Archit Taneja9b372c22011-05-06 11:45:49 +05301052 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001053}
1054
Jyri Sarha864050c2017-03-24 16:47:52 +02001055static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane_id plane)
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001056{
1057 int shift;
1058 u32 val;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001059
1060 switch (plane) {
1061 case OMAP_DSS_GFX:
1062 shift = 8;
1063 break;
1064 case OMAP_DSS_VIDEO1:
1065 case OMAP_DSS_VIDEO2:
1066 case OMAP_DSS_VIDEO3:
1067 shift = 16;
1068 break;
1069 default:
1070 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001071 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001072 }
1073
1074 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1075
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001076 if (FLD_GET(val, shift, shift) == 1)
1077 return OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001078
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001079 if (!dss_has_feature(FEAT_MGR_LCD2))
1080 return OMAP_DSS_CHANNEL_LCD;
1081
1082 switch (FLD_GET(val, 31, 30)) {
1083 case 0:
1084 default:
1085 return OMAP_DSS_CHANNEL_LCD;
1086 case 1:
1087 return OMAP_DSS_CHANNEL_LCD2;
1088 case 2:
1089 return OMAP_DSS_CHANNEL_LCD3;
Tomi Valkeinenc2665c42015-11-04 17:10:47 +02001090 case 3:
1091 return OMAP_DSS_CHANNEL_WB;
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001092 }
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001093}
1094
Archit Tanejad9ac7732012-09-22 12:38:19 +05301095void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1096{
Jyri Sarha864050c2017-03-24 16:47:52 +02001097 enum omap_plane_id plane = OMAP_DSS_WB;
Archit Tanejad9ac7732012-09-22 12:38:19 +05301098
1099 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1100}
1101
Jyri Sarha864050c2017-03-24 16:47:52 +02001102static void dispc_ovl_set_burst_size(enum omap_plane_id plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001103 enum omap_burst_size burst_size)
1104{
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301105 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001106 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001107
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001108 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001109 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001110}
1111
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001112static void dispc_configure_burst_sizes(void)
1113{
1114 int i;
1115 const int burst_size = BURST_SIZE_X8;
1116
1117 /* Configure burst size always to maximum size */
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001118 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001119 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5b354af2015-11-04 17:10:48 +02001120 if (dispc.feat->has_writeback)
1121 dispc_ovl_set_burst_size(OMAP_DSS_WB, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001122}
1123
Jyri Sarha864050c2017-03-24 16:47:52 +02001124static u32 dispc_ovl_get_burst_size(enum omap_plane_id plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001125{
1126 unsigned unit = dss_feat_get_burst_size_unit();
1127 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1128 return unit * 8;
1129}
1130
Jyri Sarha864050c2017-03-24 16:47:52 +02001131static enum omap_color_mode dispc_ovl_get_color_modes(enum omap_plane_id plane)
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001132{
1133 return dss_feat_get_supported_color_modes(plane);
1134}
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001135
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02001136static int dispc_get_num_ovls(void)
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001137{
1138 return dss_feat_get_num_ovls();
1139}
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001140
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001141static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001142{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301143 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001144 return;
1145
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301146 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001147}
1148
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001149static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02001150 const struct omap_dss_cpr_coefs *coefs)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001151{
1152 u32 coef_r, coef_g, coef_b;
1153
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301154 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001155 return;
1156
1157 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1158 FLD_VAL(coefs->rb, 9, 0);
1159 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1160 FLD_VAL(coefs->gb, 9, 0);
1161 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1162 FLD_VAL(coefs->bb, 9, 0);
1163
1164 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1165 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1166 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1167}
1168
Jyri Sarha864050c2017-03-24 16:47:52 +02001169static void dispc_ovl_set_vid_color_conv(enum omap_plane_id plane,
1170 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001171{
1172 u32 val;
1173
1174 BUG_ON(plane == OMAP_DSS_GFX);
1175
Archit Taneja9b372c22011-05-06 11:45:49 +05301176 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001177 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +05301178 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001179}
1180
Jyri Sarha864050c2017-03-24 16:47:52 +02001181static void dispc_ovl_enable_replication(enum omap_plane_id plane,
Archit Tanejad79db852012-09-22 12:30:17 +05301182 enum omap_overlay_caps caps, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001183{
Archit Tanejab8c095b2011-09-13 18:20:33 +05301184 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001185 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001186
Archit Tanejad79db852012-09-22 12:30:17 +05301187 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1188 return;
1189
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001190 shift = shifts[plane];
1191 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001192}
1193
Archit Taneja8f366162012-04-16 12:53:44 +05301194static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
Archit Tanejae5c09e02012-04-16 12:53:42 +05301195 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001196{
1197 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301198
Archit Taneja33b89922012-11-14 13:50:15 +05301199 val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1200 FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1201
Archit Taneja702d1442011-05-06 11:45:50 +05301202 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001203}
1204
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001205static void dispc_init_fifos(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001206{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001207 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001208 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301209 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001210 u32 unit;
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001211 int i;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001212
1213 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001214
Archit Tanejaa0acb552010-09-15 19:20:00 +05301215 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001216
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001217 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1218 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001219 size *= unit;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001220 dispc.fifo_size[fifo] = size;
1221
1222 /*
1223 * By default fifos are mapped directly to overlays, fifo 0 to
1224 * ovl 0, fifo 1 to ovl 1, etc.
1225 */
1226 dispc.fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001227 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001228
1229 /*
1230 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1231 * causes problems with certain use cases, like using the tiler in 2D
1232 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1233 * giving GFX plane a larger fifo. WB but should work fine with a
1234 * smaller fifo.
1235 */
1236 if (dispc.feat->gfx_fifo_workaround) {
1237 u32 v;
1238
1239 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1240
1241 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1242 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1243 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1244 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1245
1246 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1247
1248 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1249 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1250 }
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001251
1252 /*
1253 * Setup default fifo thresholds.
1254 */
1255 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1256 u32 low, high;
1257 const bool use_fifomerge = false;
1258 const bool manual_update = false;
1259
1260 dispc_ovl_compute_fifo_thresholds(i, &low, &high,
1261 use_fifomerge, manual_update);
1262
1263 dispc_ovl_set_fifo_threshold(i, low, high);
1264 }
Tomi Valkeinen65e116e2015-11-04 17:10:49 +02001265
1266 if (dispc.feat->has_writeback) {
1267 u32 low, high;
1268 const bool use_fifomerge = false;
1269 const bool manual_update = false;
1270
1271 dispc_ovl_compute_fifo_thresholds(OMAP_DSS_WB, &low, &high,
1272 use_fifomerge, manual_update);
1273
1274 dispc_ovl_set_fifo_threshold(OMAP_DSS_WB, low, high);
1275 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001276}
1277
Jyri Sarha864050c2017-03-24 16:47:52 +02001278static u32 dispc_ovl_get_fifo_size(enum omap_plane_id plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001279{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001280 int fifo;
1281 u32 size = 0;
1282
1283 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1284 if (dispc.fifo_assignment[fifo] == plane)
1285 size += dispc.fifo_size[fifo];
1286 }
1287
1288 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001289}
1290
Jyri Sarha864050c2017-03-24 16:47:52 +02001291void dispc_ovl_set_fifo_threshold(enum omap_plane_id plane, u32 low,
1292 u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001293{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301294 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001295 u32 unit;
1296
1297 unit = dss_feat_get_buffer_size_unit();
1298
1299 WARN_ON(low % unit != 0);
1300 WARN_ON(high % unit != 0);
1301
1302 low /= unit;
1303 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301304
Archit Taneja9b372c22011-05-06 11:45:49 +05301305 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1306 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1307
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001308 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001309 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301310 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001311 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301312 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001313 hi_start, hi_end) * unit,
1314 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001315
Archit Taneja9b372c22011-05-06 11:45:49 +05301316 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301317 FLD_VAL(high, hi_start, hi_end) |
1318 FLD_VAL(low, lo_start, lo_end));
Archit Taneja8bc65552013-12-17 16:40:21 +05301319
1320 /*
1321 * configure the preload to the pipeline's high threhold, if HT it's too
1322 * large for the preload field, set the threshold to the maximum value
1323 * that can be held by the preload register
1324 */
1325 if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload &&
1326 plane != OMAP_DSS_WB)
1327 dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001328}
1329
1330void dispc_enable_fifomerge(bool enable)
1331{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001332 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1333 WARN_ON(enable);
1334 return;
1335 }
1336
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001337 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1338 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001339}
1340
Jyri Sarha864050c2017-03-24 16:47:52 +02001341void dispc_ovl_compute_fifo_thresholds(enum omap_plane_id plane,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001342 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1343 bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001344{
1345 /*
1346 * All sizes are in bytes. Both the buffer and burst are made of
1347 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1348 */
1349
1350 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001351 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1352 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001353
1354 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001355 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001356
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001357 if (use_fifomerge) {
1358 total_fifo_size = 0;
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001359 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001360 total_fifo_size += dispc_ovl_get_fifo_size(i);
1361 } else {
1362 total_fifo_size = ovl_fifo_size;
1363 }
1364
1365 /*
1366 * We use the same low threshold for both fifomerge and non-fifomerge
1367 * cases, but for fifomerge we calculate the high threshold using the
1368 * combined fifo size
1369 */
1370
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001371 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001372 *fifo_low = ovl_fifo_size - burst_size * 2;
1373 *fifo_high = total_fifo_size - burst_size;
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301374 } else if (plane == OMAP_DSS_WB) {
1375 /*
1376 * Most optimal configuration for writeback is to push out data
1377 * to the interconnect the moment writeback pushes enough pixels
1378 * in the FIFO to form a burst
1379 */
1380 *fifo_low = 0;
1381 *fifo_high = burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001382 } else {
1383 *fifo_low = ovl_fifo_size - burst_size;
1384 *fifo_high = total_fifo_size - buf_unit;
1385 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001386}
1387
Jyri Sarha864050c2017-03-24 16:47:52 +02001388static void dispc_ovl_set_mflag(enum omap_plane_id plane, bool enable)
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001389{
1390 int bit;
1391
1392 if (plane == OMAP_DSS_GFX)
1393 bit = 14;
1394 else
1395 bit = 23;
1396
1397 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1398}
1399
Jyri Sarha864050c2017-03-24 16:47:52 +02001400static void dispc_ovl_set_mflag_threshold(enum omap_plane_id plane,
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001401 int low, int high)
1402{
1403 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane),
1404 FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1405}
1406
1407static void dispc_init_mflag(void)
1408{
1409 int i;
1410
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001411 /*
1412 * HACK: NV12 color format and MFLAG seem to have problems working
1413 * together: using two displays, and having an NV12 overlay on one of
1414 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1415 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1416 * remove the errors, but there doesn't seem to be a clear logic on
1417 * which values work and which not.
1418 *
1419 * As a work-around, set force MFLAG to always on.
1420 */
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001421 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE,
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001422 (1 << 0) | /* MFLAG_CTRL = force always on */
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001423 (0 << 2)); /* MFLAG_START = disable */
1424
1425 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1426 u32 size = dispc_ovl_get_fifo_size(i);
1427 u32 unit = dss_feat_get_buffer_size_unit();
1428 u32 low, high;
1429
1430 dispc_ovl_set_mflag(i, true);
1431
1432 /*
1433 * Simulation team suggests below thesholds:
1434 * HT = fifosize * 5 / 8;
1435 * LT = fifosize * 4 / 8;
1436 */
1437
1438 low = size * 4 / 8 / unit;
1439 high = size * 5 / 8 / unit;
1440
1441 dispc_ovl_set_mflag_threshold(i, low, high);
1442 }
Tomi Valkeinenecb0b362015-11-04 17:10:50 +02001443
1444 if (dispc.feat->has_writeback) {
1445 u32 size = dispc_ovl_get_fifo_size(OMAP_DSS_WB);
1446 u32 unit = dss_feat_get_buffer_size_unit();
1447 u32 low, high;
1448
1449 dispc_ovl_set_mflag(OMAP_DSS_WB, true);
1450
1451 /*
1452 * Simulation team suggests below thesholds:
1453 * HT = fifosize * 5 / 8;
1454 * LT = fifosize * 4 / 8;
1455 */
1456
1457 low = size * 4 / 8 / unit;
1458 high = size * 5 / 8 / unit;
1459
1460 dispc_ovl_set_mflag_threshold(OMAP_DSS_WB, low, high);
1461 }
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001462}
1463
Jyri Sarha864050c2017-03-24 16:47:52 +02001464static void dispc_ovl_set_fir(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301465 int hinc, int vinc,
1466 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001467{
1468 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001469
Amber Jain0d66cbb2011-05-19 19:47:54 +05301470 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1471 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301472
Amber Jain0d66cbb2011-05-19 19:47:54 +05301473 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1474 &hinc_start, &hinc_end);
1475 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1476 &vinc_start, &vinc_end);
1477 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1478 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301479
Amber Jain0d66cbb2011-05-19 19:47:54 +05301480 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1481 } else {
1482 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1483 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1484 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001485}
1486
Jyri Sarha864050c2017-03-24 16:47:52 +02001487static void dispc_ovl_set_vid_accu0(enum omap_plane_id plane, int haccu,
1488 int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001489{
1490 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301491 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001492
Archit Taneja87a74842011-03-02 11:19:50 +05301493 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1494 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1495
1496 val = FLD_VAL(vaccu, vert_start, vert_end) |
1497 FLD_VAL(haccu, hor_start, hor_end);
1498
Archit Taneja9b372c22011-05-06 11:45:49 +05301499 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001500}
1501
Jyri Sarha864050c2017-03-24 16:47:52 +02001502static void dispc_ovl_set_vid_accu1(enum omap_plane_id plane, int haccu,
1503 int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001504{
1505 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301506 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001507
Archit Taneja87a74842011-03-02 11:19:50 +05301508 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1509 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1510
1511 val = FLD_VAL(vaccu, vert_start, vert_end) |
1512 FLD_VAL(haccu, hor_start, hor_end);
1513
Archit Taneja9b372c22011-05-06 11:45:49 +05301514 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001515}
1516
Jyri Sarha864050c2017-03-24 16:47:52 +02001517static void dispc_ovl_set_vid_accu2_0(enum omap_plane_id plane, int haccu,
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001518 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301519{
1520 u32 val;
1521
1522 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1523 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1524}
1525
Jyri Sarha864050c2017-03-24 16:47:52 +02001526static void dispc_ovl_set_vid_accu2_1(enum omap_plane_id plane, int haccu,
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001527 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301528{
1529 u32 val;
1530
1531 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1532 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1533}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001534
Jyri Sarha864050c2017-03-24 16:47:52 +02001535static void dispc_ovl_set_scale_param(enum omap_plane_id plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001536 u16 orig_width, u16 orig_height,
1537 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301538 bool five_taps, u8 rotation,
1539 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001540{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301541 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001542
Amber Jained14a3c2011-05-19 19:47:51 +05301543 fir_hinc = 1024 * orig_width / out_width;
1544 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001545
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301546 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1547 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001548 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301549}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001550
Jyri Sarha864050c2017-03-24 16:47:52 +02001551static void dispc_ovl_set_accu_uv(enum omap_plane_id plane,
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301552 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1553 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1554{
1555 int h_accu2_0, h_accu2_1;
1556 int v_accu2_0, v_accu2_1;
1557 int chroma_hinc, chroma_vinc;
1558 int idx;
1559
1560 struct accu {
1561 s8 h0_m, h0_n;
1562 s8 h1_m, h1_n;
1563 s8 v0_m, v0_n;
1564 s8 v1_m, v1_n;
1565 };
1566
1567 const struct accu *accu_table;
1568 const struct accu *accu_val;
1569
1570 static const struct accu accu_nv12[4] = {
1571 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1572 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1573 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1574 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1575 };
1576
1577 static const struct accu accu_nv12_ilace[4] = {
1578 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1579 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1580 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1581 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1582 };
1583
1584 static const struct accu accu_yuv[4] = {
1585 { 0, 1, 0, 1, 0, 1, 0, 1 },
1586 { 0, 1, 0, 1, 0, 1, 0, 1 },
1587 { -1, 1, 0, 1, 0, 1, 0, 1 },
1588 { 0, 1, 0, 1, -1, 1, 0, 1 },
1589 };
1590
1591 switch (rotation) {
1592 case OMAP_DSS_ROT_0:
1593 idx = 0;
1594 break;
1595 case OMAP_DSS_ROT_90:
1596 idx = 1;
1597 break;
1598 case OMAP_DSS_ROT_180:
1599 idx = 2;
1600 break;
1601 case OMAP_DSS_ROT_270:
1602 idx = 3;
1603 break;
1604 default:
1605 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001606 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301607 }
1608
1609 switch (color_mode) {
1610 case OMAP_DSS_COLOR_NV12:
1611 if (ilace)
1612 accu_table = accu_nv12_ilace;
1613 else
1614 accu_table = accu_nv12;
1615 break;
1616 case OMAP_DSS_COLOR_YUV2:
1617 case OMAP_DSS_COLOR_UYVY:
1618 accu_table = accu_yuv;
1619 break;
1620 default:
1621 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001622 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301623 }
1624
1625 accu_val = &accu_table[idx];
1626
1627 chroma_hinc = 1024 * orig_width / out_width;
1628 chroma_vinc = 1024 * orig_height / out_height;
1629
1630 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1631 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1632 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1633 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1634
1635 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1636 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1637}
1638
Jyri Sarha864050c2017-03-24 16:47:52 +02001639static void dispc_ovl_set_scaling_common(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301640 u16 orig_width, u16 orig_height,
1641 u16 out_width, u16 out_height,
1642 bool ilace, bool five_taps,
1643 bool fieldmode, enum omap_color_mode color_mode,
1644 u8 rotation)
1645{
1646 int accu0 = 0;
1647 int accu1 = 0;
1648 u32 l;
1649
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001650 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301651 out_width, out_height, five_taps,
1652 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301653 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001654
Archit Taneja87a74842011-03-02 11:19:50 +05301655 /* RESIZEENABLE and VERTICALTAPS */
1656 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301657 l |= (orig_width != out_width) ? (1 << 5) : 0;
1658 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001659 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301660
1661 /* VRESIZECONF and HRESIZECONF */
1662 if (dss_has_feature(FEAT_RESIZECONF)) {
1663 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301664 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1665 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301666 }
1667
1668 /* LINEBUFFERSPLIT */
1669 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1670 l &= ~(0x1 << 22);
1671 l |= five_taps ? (1 << 22) : 0;
1672 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001673
Archit Taneja9b372c22011-05-06 11:45:49 +05301674 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001675
1676 /*
1677 * field 0 = even field = bottom field
1678 * field 1 = odd field = top field
1679 */
1680 if (ilace && !fieldmode) {
1681 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301682 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001683 if (accu0 >= 1024/2) {
1684 accu1 = 1024/2;
1685 accu0 -= accu1;
1686 }
1687 }
1688
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001689 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1690 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001691}
1692
Jyri Sarha864050c2017-03-24 16:47:52 +02001693static void dispc_ovl_set_scaling_uv(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301694 u16 orig_width, u16 orig_height,
1695 u16 out_width, u16 out_height,
1696 bool ilace, bool five_taps,
1697 bool fieldmode, enum omap_color_mode color_mode,
1698 u8 rotation)
1699{
1700 int scale_x = out_width != orig_width;
1701 int scale_y = out_height != orig_height;
Andrew F. Davis0cac5b62016-07-01 09:27:21 -05001702 bool chroma_upscale = plane != OMAP_DSS_WB;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301703
1704 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1705 return;
1706 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1707 color_mode != OMAP_DSS_COLOR_UYVY &&
1708 color_mode != OMAP_DSS_COLOR_NV12)) {
1709 /* reset chroma resampling for RGB formats */
Archit Taneja2a5561b2012-07-16 16:37:45 +05301710 if (plane != OMAP_DSS_WB)
1711 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301712 return;
1713 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001714
1715 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1716 out_height, ilace, color_mode, rotation);
1717
Amber Jain0d66cbb2011-05-19 19:47:54 +05301718 switch (color_mode) {
1719 case OMAP_DSS_COLOR_NV12:
Archit Taneja20fbb502012-08-22 17:04:48 +05301720 if (chroma_upscale) {
1721 /* UV is subsampled by 2 horizontally and vertically */
1722 orig_height >>= 1;
1723 orig_width >>= 1;
1724 } else {
1725 /* UV is downsampled by 2 horizontally and vertically */
1726 orig_height <<= 1;
1727 orig_width <<= 1;
1728 }
1729
Amber Jain0d66cbb2011-05-19 19:47:54 +05301730 break;
1731 case OMAP_DSS_COLOR_YUV2:
1732 case OMAP_DSS_COLOR_UYVY:
Archit Taneja20fbb502012-08-22 17:04:48 +05301733 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
Amber Jain0d66cbb2011-05-19 19:47:54 +05301734 if (rotation == OMAP_DSS_ROT_0 ||
Archit Taneja20fbb502012-08-22 17:04:48 +05301735 rotation == OMAP_DSS_ROT_180) {
1736 if (chroma_upscale)
1737 /* UV is subsampled by 2 horizontally */
1738 orig_width >>= 1;
1739 else
1740 /* UV is downsampled by 2 horizontally */
1741 orig_width <<= 1;
1742 }
1743
Amber Jain0d66cbb2011-05-19 19:47:54 +05301744 /* must use FIR for YUV422 if rotated */
1745 if (rotation != OMAP_DSS_ROT_0)
1746 scale_x = scale_y = true;
Archit Taneja20fbb502012-08-22 17:04:48 +05301747
Amber Jain0d66cbb2011-05-19 19:47:54 +05301748 break;
1749 default:
1750 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001751 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301752 }
1753
1754 if (out_width != orig_width)
1755 scale_x = true;
1756 if (out_height != orig_height)
1757 scale_y = true;
1758
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001759 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301760 out_width, out_height, five_taps,
1761 rotation, DISPC_COLOR_COMPONENT_UV);
1762
Archit Taneja2a5561b2012-07-16 16:37:45 +05301763 if (plane != OMAP_DSS_WB)
1764 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1765 (scale_x || scale_y) ? 1 : 0, 8, 8);
1766
Amber Jain0d66cbb2011-05-19 19:47:54 +05301767 /* set H scaling */
1768 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1769 /* set V scaling */
1770 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301771}
1772
Jyri Sarha864050c2017-03-24 16:47:52 +02001773static void dispc_ovl_set_scaling(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301774 u16 orig_width, u16 orig_height,
1775 u16 out_width, u16 out_height,
1776 bool ilace, bool five_taps,
1777 bool fieldmode, enum omap_color_mode color_mode,
1778 u8 rotation)
1779{
1780 BUG_ON(plane == OMAP_DSS_GFX);
1781
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001782 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301783 orig_width, orig_height,
1784 out_width, out_height,
1785 ilace, five_taps,
1786 fieldmode, color_mode,
1787 rotation);
1788
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001789 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301790 orig_width, orig_height,
1791 out_width, out_height,
1792 ilace, five_taps,
1793 fieldmode, color_mode,
1794 rotation);
1795}
1796
Jyri Sarha273ffea2017-03-24 16:47:53 +02001797static void dispc_ovl_set_rotation_attrs(enum omap_plane_id plane, u8 rotation,
Archit Tanejac35eeb22013-03-26 19:15:24 +05301798 enum omap_dss_rotation_type rotation_type,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001799 bool mirroring, enum omap_color_mode color_mode)
1800{
Archit Taneja87a74842011-03-02 11:19:50 +05301801 bool row_repeat = false;
1802 int vidrot = 0;
1803
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001804 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1805 color_mode == OMAP_DSS_COLOR_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001806
1807 if (mirroring) {
1808 switch (rotation) {
1809 case OMAP_DSS_ROT_0:
1810 vidrot = 2;
1811 break;
1812 case OMAP_DSS_ROT_90:
1813 vidrot = 1;
1814 break;
1815 case OMAP_DSS_ROT_180:
1816 vidrot = 0;
1817 break;
1818 case OMAP_DSS_ROT_270:
1819 vidrot = 3;
1820 break;
1821 }
1822 } else {
1823 switch (rotation) {
1824 case OMAP_DSS_ROT_0:
1825 vidrot = 0;
1826 break;
1827 case OMAP_DSS_ROT_90:
1828 vidrot = 1;
1829 break;
1830 case OMAP_DSS_ROT_180:
1831 vidrot = 2;
1832 break;
1833 case OMAP_DSS_ROT_270:
1834 vidrot = 3;
1835 break;
1836 }
1837 }
1838
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001839 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
Archit Taneja87a74842011-03-02 11:19:50 +05301840 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001841 else
Archit Taneja87a74842011-03-02 11:19:50 +05301842 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001843 }
Archit Taneja87a74842011-03-02 11:19:50 +05301844
Tomi Valkeinen3397cc62015-04-09 13:51:30 +03001845 /*
1846 * OMAP4/5 Errata i631:
1847 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
1848 * rows beyond the framebuffer, which may cause OCP error.
1849 */
1850 if (color_mode == OMAP_DSS_COLOR_NV12 &&
1851 rotation_type != OMAP_DSS_ROT_TILER)
1852 vidrot = 1;
1853
Archit Taneja9b372c22011-05-06 11:45:49 +05301854 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301855 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301856 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1857 row_repeat ? 1 : 0, 18, 18);
Archit Tanejac35eeb22013-03-26 19:15:24 +05301858
Tomi Valkeinen6d862782016-08-29 11:15:49 +03001859 if (dss_feat_color_mode_supported(plane, OMAP_DSS_COLOR_NV12)) {
1860 bool doublestride =
1861 color_mode == OMAP_DSS_COLOR_NV12 &&
1862 rotation_type == OMAP_DSS_ROT_TILER &&
1863 (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180);
1864
Archit Tanejac35eeb22013-03-26 19:15:24 +05301865 /* DOUBLESTRIDE */
1866 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22);
1867 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001868}
1869
1870static int color_mode_to_bpp(enum omap_color_mode color_mode)
1871{
1872 switch (color_mode) {
Amber Jainf20e4222011-05-19 19:47:50 +05301873 case OMAP_DSS_COLOR_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001874 return 8;
1875 case OMAP_DSS_COLOR_RGB12U:
1876 case OMAP_DSS_COLOR_RGB16:
1877 case OMAP_DSS_COLOR_ARGB16:
1878 case OMAP_DSS_COLOR_YUV2:
1879 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301880 case OMAP_DSS_COLOR_RGBA16:
1881 case OMAP_DSS_COLOR_RGBX16:
1882 case OMAP_DSS_COLOR_ARGB16_1555:
1883 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001884 return 16;
1885 case OMAP_DSS_COLOR_RGB24P:
1886 return 24;
1887 case OMAP_DSS_COLOR_RGB24U:
1888 case OMAP_DSS_COLOR_ARGB32:
1889 case OMAP_DSS_COLOR_RGBA32:
1890 case OMAP_DSS_COLOR_RGBX32:
1891 return 32;
1892 default:
1893 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001894 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001895 }
1896}
1897
1898static s32 pixinc(int pixels, u8 ps)
1899{
1900 if (pixels == 1)
1901 return 1;
1902 else if (pixels > 1)
1903 return 1 + (pixels - 1) * ps;
1904 else if (pixels < 0)
1905 return 1 - (-pixels + 1) * ps;
1906 else
1907 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001908 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001909}
1910
Tomi Valkeinen517a8a952017-05-03 14:14:27 +03001911static void calc_offset(u16 screen_width, u16 width,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301912 enum omap_color_mode color_mode, bool fieldmode,
1913 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1914 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1915{
1916 u8 ps;
1917
Tomi Valkeinen4b9cdd92017-03-10 10:32:30 +02001918 ps = color_mode_to_bpp(color_mode) / 8;
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05301919
1920 DSSDBG("scrw %d, width %d\n", screen_width, width);
1921
1922 /*
1923 * field 0 = even field = bottom field
1924 * field 1 = odd field = top field
1925 */
1926 *offset1 = 0;
1927 if (field_offset)
1928 *offset0 = *offset1 + field_offset * screen_width * ps;
1929 else
1930 *offset0 = *offset1;
1931 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1932 (fieldmode ? screen_width : 0), ps);
1933 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1934 color_mode == OMAP_DSS_COLOR_UYVY)
1935 *pix_inc = pixinc(x_predecim, 2 * ps);
1936 else
1937 *pix_inc = pixinc(x_predecim, ps);
1938}
1939
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301940/*
1941 * This function is used to avoid synclosts in OMAP3, because of some
1942 * undocumented horizontal position and timing related limitations.
1943 */
Tomi Valkeinen465ec132012-10-19 15:40:24 +03001944static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03001945 const struct videomode *vm, u16 pos_x,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02001946 u16 width, u16 height, u16 out_width, u16 out_height,
1947 bool five_taps)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301948{
Tomi Valkeinen230edc02012-11-05 14:40:19 +02001949 const int ds = DIV_ROUND_UP(height, out_height);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05301950 unsigned long nonactive;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301951 static const u8 limits[3] = { 8, 10, 20 };
1952 u64 val, blank;
1953 int i;
1954
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03001955 nonactive = vm->hactive + vm->hfront_porch + vm->hsync_len +
1956 vm->hback_porch - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301957
1958 i = 0;
1959 if (out_height < height)
1960 i++;
1961 if (out_width < width)
1962 i++;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03001963 blank = div_u64((u64)(vm->hback_porch + vm->hsync_len + vm->hfront_porch) *
Peter Ujfalusi0a30e152016-09-22 14:06:49 +03001964 lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301965 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
1966 if (blank <= limits[i])
1967 return -EINVAL;
1968
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02001969 /* FIXME add checks for 3-tap filter once the limitations are known */
1970 if (!five_taps)
1971 return 0;
1972
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301973 /*
1974 * Pixel data should be prepared before visible display point starts.
1975 * So, atleast DS-2 lines must have already been fetched by DISPC
1976 * during nonactive - pos_x period.
1977 */
1978 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
1979 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02001980 val, max(0, ds - 2) * width);
1981 if (val < max(0, ds - 2) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301982 return -EINVAL;
1983
1984 /*
1985 * All lines need to be refilled during the nonactive period of which
1986 * only one line can be loaded during the active period. So, atleast
1987 * DS - 1 lines should be loaded during nonactive period.
1988 */
1989 val = div_u64((u64)nonactive * lclk, pclk);
1990 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02001991 val, max(0, ds - 1) * width);
1992 if (val < max(0, ds - 1) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05301993 return -EINVAL;
1994
1995 return 0;
1996}
1997
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03001998static unsigned long calc_core_clk_five_taps(unsigned long pclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03001999 const struct videomode *vm, u16 width,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302000 u16 height, u16 out_width, u16 out_height,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002001 enum omap_color_mode color_mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002002{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302003 u32 core_clk = 0;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302004 u64 tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002005
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302006 if (height <= out_height && width <= out_width)
2007 return (unsigned long) pclk;
2008
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002009 if (height > out_height) {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002010 unsigned int ppl = vm->hactive;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002011
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002012 tmp = (u64)pclk * height * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002013 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302014 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002015
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02002016 if (height > 2 * out_height) {
2017 if (ppl == out_width)
2018 return 0;
2019
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002020 tmp = (u64)pclk * (height - 2 * out_height) * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002021 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302022 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002023 }
2024 }
2025
2026 if (width > out_width) {
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002027 tmp = (u64)pclk * width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002028 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302029 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002030
2031 if (color_mode == OMAP_DSS_COLOR_RGB24U)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302032 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002033 }
2034
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302035 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002036}
2037
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002038static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302039 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302040{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302041 if (height > out_height && width > out_width)
2042 return pclk * 4;
2043 else
2044 return pclk * 2;
2045}
2046
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002047static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302048 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002049{
2050 unsigned int hf, vf;
2051
2052 /*
2053 * FIXME how to determine the 'A' factor
2054 * for the no downscaling case ?
2055 */
2056
2057 if (width > 3 * out_width)
2058 hf = 4;
2059 else if (width > 2 * out_width)
2060 hf = 3;
2061 else if (width > out_width)
2062 hf = 2;
2063 else
2064 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002065 if (height > out_height)
2066 vf = 2;
2067 else
2068 vf = 1;
2069
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302070 return pclk * vf * hf;
2071}
2072
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002073static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302074 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302075{
Archit Taneja8ba85302012-09-26 17:00:37 +05302076 /*
2077 * If the overlay/writeback is in mem to mem mode, there are no
2078 * downscaling limitations with respect to pixel clock, return 1 as
2079 * required core clock to represent that we have sufficient enough
2080 * core clock to do maximum downscaling
2081 */
2082 if (mem_to_mem)
2083 return 1;
2084
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302085 if (width > out_width)
2086 return DIV_ROUND_UP(pclk, out_width) * width;
2087 else
2088 return pclk;
2089}
2090
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002091static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002092 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302093 u16 width, u16 height, u16 out_width, u16 out_height,
2094 enum omap_color_mode color_mode, bool *five_taps,
2095 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302096 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302097{
2098 int error;
2099 u16 in_width, in_height;
2100 int min_factor = min(*decim_x, *decim_y);
2101 const int maxsinglelinewidth =
2102 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302103
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302104 *five_taps = false;
2105
2106 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002107 in_height = height / *decim_y;
2108 in_width = width / *decim_x;
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002109 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302110 in_height, out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302111 error = (in_width > maxsinglelinewidth || !*core_clk ||
2112 *core_clk > dispc_core_clk_rate());
2113 if (error) {
2114 if (*decim_x == *decim_y) {
2115 *decim_x = min_factor;
2116 ++*decim_y;
2117 } else {
2118 swap(*decim_x, *decim_y);
2119 if (*decim_x < *decim_y)
2120 ++*decim_x;
2121 }
2122 }
2123 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2124
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002125 if (error) {
2126 DSSERR("failed to find scaling settings\n");
2127 return -EINVAL;
2128 }
2129
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302130 if (in_width > maxsinglelinewidth) {
2131 DSSERR("Cannot scale max input width exceeded");
2132 return -EINVAL;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302133 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302134 return 0;
2135}
2136
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002137static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002138 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302139 u16 width, u16 height, u16 out_width, u16 out_height,
2140 enum omap_color_mode color_mode, bool *five_taps,
2141 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302142 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302143{
2144 int error;
2145 u16 in_width, in_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302146 const int maxsinglelinewidth =
2147 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2148
2149 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002150 in_height = height / *decim_y;
2151 in_width = width / *decim_x;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002152 *five_taps = in_height > out_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302153
2154 if (in_width > maxsinglelinewidth)
2155 if (in_height > out_height &&
2156 in_height < out_height * 2)
2157 *five_taps = false;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002158again:
2159 if (*five_taps)
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002160 *core_clk = calc_core_clk_five_taps(pclk, vm,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002161 in_width, in_height, out_width,
2162 out_height, color_mode);
2163 else
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002164 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302165 in_height, out_width, out_height,
2166 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302167
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002168 error = check_horiz_timing_omap3(pclk, lclk, vm,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002169 pos_x, in_width, in_height, out_width,
2170 out_height, *five_taps);
2171 if (error && *five_taps) {
2172 *five_taps = false;
2173 goto again;
2174 }
2175
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302176 error = (error || in_width > maxsinglelinewidth * 2 ||
2177 (in_width > maxsinglelinewidth && *five_taps) ||
2178 !*core_clk || *core_clk > dispc_core_clk_rate());
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002179
2180 if (!error) {
2181 /* verify that we're inside the limits of scaler */
2182 if (in_width / 4 > out_width)
2183 error = 1;
2184
2185 if (*five_taps) {
2186 if (in_height / 4 > out_height)
2187 error = 1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302188 } else {
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002189 if (in_height / 2 > out_height)
2190 error = 1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302191 }
2192 }
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002193
Tomi Valkeinen7059e3d2015-04-10 12:48:38 +03002194 if (error)
2195 ++*decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302196 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2197
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002198 if (error) {
2199 DSSERR("failed to find scaling settings\n");
2200 return -EINVAL;
2201 }
2202
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002203 if (check_horiz_timing_omap3(pclk, lclk, vm, pos_x, in_width,
Tomi Valkeinenf5a73482015-03-17 15:31:09 +02002204 in_height, out_width, out_height, *five_taps)) {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302205 DSSERR("horizontal timing too tight\n");
2206 return -EINVAL;
2207 }
2208
2209 if (in_width > (maxsinglelinewidth * 2)) {
2210 DSSERR("Cannot setup scaling");
2211 DSSERR("width exceeds maximum width possible");
2212 return -EINVAL;
2213 }
2214
2215 if (in_width > maxsinglelinewidth && *five_taps) {
2216 DSSERR("cannot setup scaling with five taps");
2217 return -EINVAL;
2218 }
2219 return 0;
2220}
2221
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002222static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002223 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302224 u16 width, u16 height, u16 out_width, u16 out_height,
2225 enum omap_color_mode color_mode, bool *five_taps,
2226 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302227 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302228{
2229 u16 in_width, in_width_max;
2230 int decim_x_min = *decim_x;
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002231 u16 in_height = height / *decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302232 const int maxsinglelinewidth =
2233 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja8ba85302012-09-26 17:00:37 +05302234 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302235
Archit Taneja5d501082012-11-07 11:45:02 +05302236 if (mem_to_mem) {
2237 in_width_max = out_width * maxdownscale;
2238 } else {
Archit Taneja8ba85302012-09-26 17:00:37 +05302239 in_width_max = dispc_core_clk_rate() /
2240 DIV_ROUND_UP(pclk, out_width);
Archit Taneja5d501082012-11-07 11:45:02 +05302241 }
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302242
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302243 *decim_x = DIV_ROUND_UP(width, in_width_max);
2244
2245 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2246 if (*decim_x > *x_predecim)
2247 return -EINVAL;
2248
2249 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002250 in_width = width / *decim_x;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302251 } while (*decim_x <= *x_predecim &&
2252 in_width > maxsinglelinewidth && ++*decim_x);
2253
2254 if (in_width > maxsinglelinewidth) {
2255 DSSERR("Cannot scale width exceeds max line width");
2256 return -EINVAL;
2257 }
2258
Jyri Sarha1b30ab02017-02-08 16:08:06 +02002259 if (*decim_x > 4 && color_mode != OMAP_DSS_COLOR_NV12) {
2260 /*
2261 * Let's disable all scaling that requires horizontal
2262 * decimation with higher factor than 4, until we have
2263 * better estimates of what we can and can not
2264 * do. However, NV12 color format appears to work Ok
2265 * with all decimation factors.
2266 *
2267 * When decimating horizontally by more that 4 the dss
2268 * is not able to fetch the data in burst mode. When
2269 * this happens it is hard to tell if there enough
2270 * bandwidth. Despite what theory says this appears to
2271 * be true also for 16-bit color formats.
2272 */
2273 DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)", *decim_x);
2274
2275 return -EINVAL;
2276 }
2277
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002278 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
Archit Taneja8ba85302012-09-26 17:00:37 +05302279 out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302280 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002281}
2282
Tomi Valkeinene4c5ae72015-04-10 12:48:39 +03002283#define DIV_FRAC(dividend, divisor) \
2284 ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2285
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002286static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302287 enum omap_overlay_caps caps,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002288 const struct videomode *vm,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302289 u16 width, u16 height, u16 out_width, u16 out_height,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302290 enum omap_color_mode color_mode, bool *five_taps,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302291 int *x_predecim, int *y_predecim, u16 pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302292 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302293{
Archit Taneja0373cac2011-09-08 13:25:17 +05302294 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302295 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302296 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302297 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302298
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002299 if (width == out_width && height == out_height)
2300 return 0;
2301
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002302 if (!mem_to_mem && (pclk == 0 || vm->pixelclock == 0)) {
Tomi Valkeinen4e1d3ca2014-10-03 15:14:09 +00002303 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2304 return -EINVAL;
2305 }
2306
Archit Taneja5b54ed32012-09-26 16:55:27 +05302307 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002308 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302309
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002310 if (mem_to_mem) {
Archit Taneja1c031442012-11-07 11:45:03 +05302311 *x_predecim = *y_predecim = 1;
2312 } else {
2313 *x_predecim = max_decim_limit;
2314 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2315 dss_has_feature(FEAT_BURST_2D)) ?
2316 2 : max_decim_limit;
2317 }
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302318
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302319 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2320 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2321
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302322 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302323 return -EINVAL;
2324
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302325 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302326 return -EINVAL;
2327
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002328 ret = dispc.feat->calc_scaling(pclk, lclk, vm, width, height,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302329 out_width, out_height, color_mode, five_taps,
Archit Taneja8ba85302012-09-26 17:00:37 +05302330 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2331 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302332 if (ret)
2333 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302334
Tomi Valkeinene4c5ae72015-04-10 12:48:39 +03002335 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",
2336 width, height,
2337 out_width, out_height,
2338 out_width / width, DIV_FRAC(out_width, width),
2339 out_height / height, DIV_FRAC(out_height, height),
2340
2341 decim_x, decim_y,
2342 width / decim_x, height / decim_y,
2343 out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
2344 out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
2345
2346 *five_taps ? 5 : 3,
2347 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302348
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302349 if (!core_clk || core_clk > dispc_core_clk_rate()) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302350 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302351 "required core clk rate = %lu Hz, "
2352 "current core clk rate = %lu Hz\n",
2353 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302354 return -EINVAL;
2355 }
2356
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302357 *x_predecim = decim_x;
2358 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302359 return 0;
2360}
2361
Jyri Sarha864050c2017-03-24 16:47:52 +02002362static int dispc_ovl_setup_common(enum omap_plane_id plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302363 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2364 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2365 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2366 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2367 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002368 bool replication, const struct videomode *vm,
Archit Taneja8ba85302012-09-26 17:00:37 +05302369 bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002370{
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302371 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002372 bool fieldmode = false;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302373 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002374 unsigned offset0, offset1;
2375 s32 row_inc;
2376 s32 pix_inc;
Archit Taneja6be0d732012-11-07 11:45:04 +05302377 u16 frame_width, frame_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002378 unsigned int field_offset = 0;
Archit Taneja84a880f2012-09-26 16:57:37 +05302379 u16 in_height = height;
2380 u16 in_width = width;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302381 int x_predecim = 1, y_predecim = 1;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002382 bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED);
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002383 unsigned long pclk = dispc_plane_pclk_rate(plane);
2384 unsigned long lclk = dispc_plane_lclk_rate(plane);
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002385
Tomi Valkeinene5666582014-11-28 14:34:15 +02002386 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002387 return -EINVAL;
2388
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002389 switch (color_mode) {
2390 case OMAP_DSS_COLOR_YUV2:
2391 case OMAP_DSS_COLOR_UYVY:
2392 case OMAP_DSS_COLOR_NV12:
2393 if (in_width & 1) {
2394 DSSERR("input width %d is not even for YUV format\n",
2395 in_width);
2396 return -EINVAL;
2397 }
2398 break;
2399
2400 default:
2401 break;
2402 }
2403
Archit Taneja84a880f2012-09-26 16:57:37 +05302404 out_width = out_width == 0 ? width : out_width;
2405 out_height = out_height == 0 ? height : out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002406
Archit Taneja84a880f2012-09-26 16:57:37 +05302407 if (ilace && height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002408 fieldmode = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002409
2410 if (ilace) {
2411 if (fieldmode)
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302412 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302413 pos_y /= 2;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302414 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002415
2416 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
Archit Taneja84a880f2012-09-26 16:57:37 +05302417 "out_height %d\n", in_height, pos_y,
2418 out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002419 }
2420
Archit Taneja84a880f2012-09-26 16:57:37 +05302421 if (!dss_feat_color_mode_supported(plane, color_mode))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302422 return -EINVAL;
2423
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002424 r = dispc_ovl_calc_scaling(pclk, lclk, caps, vm, in_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302425 in_height, out_width, out_height, color_mode,
2426 &five_taps, &x_predecim, &y_predecim, pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302427 rotation_type, mem_to_mem);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302428 if (r)
2429 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002430
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002431 in_width = in_width / x_predecim;
2432 in_height = in_height / y_predecim;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302433
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002434 if (x_predecim > 1 || y_predecim > 1)
2435 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2436 x_predecim, y_predecim, in_width, in_height);
2437
2438 switch (color_mode) {
2439 case OMAP_DSS_COLOR_YUV2:
2440 case OMAP_DSS_COLOR_UYVY:
2441 case OMAP_DSS_COLOR_NV12:
2442 if (in_width & 1) {
2443 DSSDBG("predecimated input width is not even for YUV format\n");
2444 DSSDBG("adjusting input width %d -> %d\n",
2445 in_width, in_width & ~1);
2446
2447 in_width &= ~1;
2448 }
2449 break;
2450
2451 default:
2452 break;
2453 }
2454
Archit Taneja84a880f2012-09-26 16:57:37 +05302455 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2456 color_mode == OMAP_DSS_COLOR_UYVY ||
2457 color_mode == OMAP_DSS_COLOR_NV12)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302458 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002459
2460 if (ilace && !fieldmode) {
2461 /*
2462 * when downscaling the bottom field may have to start several
2463 * source lines below the top field. Unfortunately ACCUI
2464 * registers will only hold the fractional part of the offset
2465 * so the integer part must be added to the base address of the
2466 * bottom field.
2467 */
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302468 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002469 field_offset = 0;
2470 else
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302471 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002472 }
2473
2474 /* Fields are independent but interleaved in memory. */
2475 if (fieldmode)
2476 field_offset = 1;
2477
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002478 offset0 = 0;
2479 offset1 = 0;
2480 row_inc = 0;
2481 pix_inc = 0;
2482
Archit Taneja6be0d732012-11-07 11:45:04 +05302483 if (plane == OMAP_DSS_WB) {
2484 frame_width = out_width;
2485 frame_height = out_height;
2486 } else {
2487 frame_width = in_width;
2488 frame_height = height;
2489 }
2490
Tomi Valkeinen517a8a952017-05-03 14:14:27 +03002491 calc_offset(screen_width, frame_width,
2492 color_mode, fieldmode, field_offset,
2493 &offset0, &offset1, &row_inc, &pix_inc,
2494 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002495
2496 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2497 offset0, offset1, row_inc, pix_inc);
2498
Archit Taneja84a880f2012-09-26 16:57:37 +05302499 dispc_ovl_set_color_mode(plane, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002500
Archit Taneja84a880f2012-09-26 16:57:37 +05302501 dispc_ovl_configure_burst_type(plane, rotation_type);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302502
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02002503 if (dispc.feat->reverse_ilace_field_order)
2504 swap(offset0, offset1);
2505
Archit Taneja84a880f2012-09-26 16:57:37 +05302506 dispc_ovl_set_ba0(plane, paddr + offset0);
2507 dispc_ovl_set_ba1(plane, paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002508
Archit Taneja84a880f2012-09-26 16:57:37 +05302509 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2510 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2511 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302512 }
2513
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03002514 if (dispc.feat->last_pixel_inc_missing)
2515 row_inc += pix_inc - 1;
2516
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002517 dispc_ovl_set_row_inc(plane, row_inc);
2518 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002519
Archit Taneja84a880f2012-09-26 16:57:37 +05302520 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302521 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002522
Archit Taneja84a880f2012-09-26 16:57:37 +05302523 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002524
Archit Taneja78b687f2012-09-21 14:51:49 +05302525 dispc_ovl_set_input_size(plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002526
Archit Taneja5b54ed32012-09-26 16:55:27 +05302527 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302528 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2529 out_height, ilace, five_taps, fieldmode,
Archit Taneja84a880f2012-09-26 16:57:37 +05302530 color_mode, rotation);
Archit Taneja78b687f2012-09-21 14:51:49 +05302531 dispc_ovl_set_output_size(plane, out_width, out_height);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002532 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002533 }
2534
Archit Tanejac35eeb22013-03-26 19:15:24 +05302535 dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, mirror,
2536 color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002537
Archit Taneja84a880f2012-09-26 16:57:37 +05302538 dispc_ovl_set_zorder(plane, caps, zorder);
2539 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2540 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002541
Archit Tanejad79db852012-09-22 12:30:17 +05302542 dispc_ovl_enable_replication(plane, caps, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302543
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002544 return 0;
2545}
2546
Jyri Sarha864050c2017-03-24 16:47:52 +02002547static int dispc_ovl_setup(enum omap_plane_id plane,
Jyri Sarha273ffea2017-03-24 16:47:53 +02002548 const struct omap_overlay_info *oi,
Tomi Valkeinen49a30572017-02-17 12:30:07 +02002549 const struct videomode *vm, bool mem_to_mem,
2550 enum omap_channel channel)
Archit Taneja84a880f2012-09-26 16:57:37 +05302551{
2552 int r;
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002553 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
Tomi Valkeinenbe2d68c2016-08-29 13:15:02 +03002554 const bool replication = true;
Archit Taneja84a880f2012-09-26 16:57:37 +05302555
Arnd Bergmann24f13a62014-04-24 13:28:18 +01002556 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2557 " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2558 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
Archit Taneja84a880f2012-09-26 16:57:37 +05302559 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2560 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2561
Tomi Valkeinen49a30572017-02-17 12:30:07 +02002562 dispc_ovl_set_channel_out(plane, channel);
2563
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002564 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302565 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2566 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2567 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002568 oi->rotation_type, replication, vm, mem_to_mem);
Archit Taneja84a880f2012-09-26 16:57:37 +05302569
2570 return r;
2571}
2572
Archit Taneja749feff2012-08-31 12:32:52 +05302573int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002574 bool mem_to_mem, const struct videomode *vm)
Archit Taneja749feff2012-08-31 12:32:52 +05302575{
2576 int r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302577 u32 l;
Jyri Sarha864050c2017-03-24 16:47:52 +02002578 enum omap_plane_id plane = OMAP_DSS_WB;
Archit Taneja749feff2012-08-31 12:32:52 +05302579 const int pos_x = 0, pos_y = 0;
2580 const u8 zorder = 0, global_alpha = 0;
Tomi Valkeinenbe2d68c2016-08-29 13:15:02 +03002581 const bool replication = true;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302582 bool truncation;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002583 int in_width = vm->hactive;
2584 int in_height = vm->vactive;
Archit Taneja749feff2012-08-31 12:32:52 +05302585 enum omap_overlay_caps caps =
2586 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2587
2588 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2589 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2590 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2591 wi->mirror);
2592
2593 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2594 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2595 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2596 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002597 replication, vm, mem_to_mem);
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302598
2599 switch (wi->color_mode) {
2600 case OMAP_DSS_COLOR_RGB16:
2601 case OMAP_DSS_COLOR_RGB24P:
2602 case OMAP_DSS_COLOR_ARGB16:
2603 case OMAP_DSS_COLOR_RGBA16:
2604 case OMAP_DSS_COLOR_RGB12U:
2605 case OMAP_DSS_COLOR_ARGB16_1555:
2606 case OMAP_DSS_COLOR_XRGB16_1555:
2607 case OMAP_DSS_COLOR_RGBX16:
2608 truncation = true;
2609 break;
2610 default:
2611 truncation = false;
2612 break;
2613 }
2614
2615 /* setup extra DISPC_WB_ATTRIBUTES */
2616 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2617 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2618 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
Tomi Valkeinen4c055ce2015-11-04 17:10:53 +02002619 if (mem_to_mem)
2620 l = FLD_MOD(l, 1, 26, 24); /* CAPTUREMODE */
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002621 else
2622 l = FLD_MOD(l, 0, 26, 24); /* CAPTUREMODE */
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302623 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Archit Taneja749feff2012-08-31 12:32:52 +05302624
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002625 if (mem_to_mem) {
2626 /* WBDELAYCOUNT */
2627 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0);
2628 } else {
2629 int wbdelay;
2630
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002631 wbdelay = min(vm->vfront_porch +
2632 vm->vsync_len + vm->vback_porch, (u32)255);
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002633
2634 /* WBDELAYCOUNT */
2635 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0);
2636 }
2637
Archit Taneja749feff2012-08-31 12:32:52 +05302638 return r;
2639}
2640
Jyri Sarha864050c2017-03-24 16:47:52 +02002641static int dispc_ovl_enable(enum omap_plane_id plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002642{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002643 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2644
Archit Taneja9b372c22011-05-06 11:45:49 +05302645 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002646
2647 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002648}
2649
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002650static enum omap_dss_output_id dispc_mgr_get_supported_outputs(enum omap_channel channel)
Tomi Valkeinen7b9cb5e2015-11-04 15:11:25 +02002651{
2652 return dss_feat_get_supported_outputs(channel);
2653}
Tomi Valkeinen7b9cb5e2015-11-04 15:11:25 +02002654
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002655static void dispc_lcd_enable_signal_polarity(bool act_high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002656{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002657 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2658 return;
2659
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002660 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002661}
2662
2663void dispc_lcd_enable_signal(bool enable)
2664{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002665 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2666 return;
2667
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002668 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002669}
2670
2671void dispc_pck_free_enable(bool enable)
2672{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002673 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2674 return;
2675
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002676 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002677}
2678
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002679static int dispc_get_num_mgrs(void)
Tomi Valkeinenc2834002015-11-05 19:54:33 +02002680{
2681 return dss_feat_get_num_mgrs();
2682}
Tomi Valkeinenc2834002015-11-05 19:54:33 +02002683
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002684static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002685{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302686 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002687}
2688
2689
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002690static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002691{
Archit Tanejad21f43b2012-06-21 09:45:11 +05302692 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002693}
2694
Tomi Valkeinen65904152015-11-04 17:10:57 +02002695static void dispc_set_loadmode(enum omap_dss_load_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002696{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002697 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002698}
2699
2700
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002701static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002702{
Sumit Semwal8613b002010-12-02 11:27:09 +00002703 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002704}
2705
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002706static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002707 enum omap_dss_trans_key_type type,
2708 u32 trans_key)
2709{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302710 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002711
Sumit Semwal8613b002010-12-02 11:27:09 +00002712 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002713}
2714
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002715static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002716{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302717 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002718}
Archit Taneja11354dd2011-09-26 11:47:29 +05302719
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002720static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2721 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002722{
Archit Taneja11354dd2011-09-26 11:47:29 +05302723 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002724 return;
2725
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002726 if (ch == OMAP_DSS_CHANNEL_LCD)
2727 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00002728 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002729 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002730}
Archit Taneja11354dd2011-09-26 11:47:29 +05302731
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002732static void dispc_mgr_setup(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02002733 const struct omap_overlay_manager_info *info)
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002734{
2735 dispc_mgr_set_default_color(channel, info->default_color);
2736 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2737 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2738 dispc_mgr_enable_alpha_fixed_zorder(channel,
2739 info->partial_alpha_enabled);
2740 if (dss_has_feature(FEAT_CPR)) {
2741 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2742 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2743 }
2744}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002745
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002746static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002747{
2748 int code;
2749
2750 switch (data_lines) {
2751 case 12:
2752 code = 0;
2753 break;
2754 case 16:
2755 code = 1;
2756 break;
2757 case 18:
2758 code = 2;
2759 break;
2760 case 24:
2761 code = 3;
2762 break;
2763 default:
2764 BUG();
2765 return;
2766 }
2767
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302768 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002769}
2770
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002771static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002772{
2773 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05302774 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002775
2776 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05302777 case DSS_IO_PAD_MODE_RESET:
2778 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002779 gpout1 = 0;
2780 break;
Archit Taneja569969d2011-08-22 17:41:57 +05302781 case DSS_IO_PAD_MODE_RFBI:
2782 gpout0 = 1;
2783 gpout1 = 0;
2784 break;
2785 case DSS_IO_PAD_MODE_BYPASS:
2786 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002787 gpout1 = 1;
2788 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002789 default:
2790 BUG();
2791 return;
2792 }
2793
Archit Taneja569969d2011-08-22 17:41:57 +05302794 l = dispc_read_reg(DISPC_CONTROL);
2795 l = FLD_MOD(l, gpout0, 15, 15);
2796 l = FLD_MOD(l, gpout1, 16, 16);
2797 dispc_write_reg(DISPC_CONTROL, l);
2798}
2799
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002800static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
Archit Taneja569969d2011-08-22 17:41:57 +05302801{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302802 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002803}
2804
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002805static void dispc_mgr_set_lcd_config(enum omap_channel channel,
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002806 const struct dss_lcd_mgr_config *config)
2807{
2808 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
2809
2810 dispc_mgr_enable_stallmode(channel, config->stallmode);
2811 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
2812
2813 dispc_mgr_set_clock_div(channel, &config->clock_info);
2814
2815 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
2816
2817 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
2818
2819 dispc_mgr_set_lcd_type_tft(channel);
2820}
2821
Archit Taneja8f366162012-04-16 12:53:44 +05302822static bool _dispc_mgr_size_ok(u16 width, u16 height)
2823{
Archit Taneja33b89922012-11-14 13:50:15 +05302824 return width <= dispc.feat->mgr_width_max &&
2825 height <= dispc.feat->mgr_height_max;
Archit Taneja8f366162012-04-16 12:53:44 +05302826}
2827
Peter Ujfalusi4dc22502016-09-22 14:06:48 +03002828static bool _dispc_lcd_timings_ok(int hsync_len, int hfp, int hbp,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002829 int vsw, int vfp, int vbp)
2830{
Peter Ujfalusi4dc22502016-09-22 14:06:48 +03002831 if (hsync_len < 1 || hsync_len > dispc.feat->sw_max ||
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302832 hfp < 1 || hfp > dispc.feat->hp_max ||
2833 hbp < 1 || hbp > dispc.feat->hp_max ||
2834 vsw < 1 || vsw > dispc.feat->sw_max ||
2835 vfp < 0 || vfp > dispc.feat->vp_max ||
2836 vbp < 0 || vbp > dispc.feat->vp_max)
2837 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002838 return true;
2839}
2840
Archit Tanejaca5ca692013-03-26 19:15:22 +05302841static bool _dispc_mgr_pclk_ok(enum omap_channel channel,
2842 unsigned long pclk)
2843{
2844 if (dss_mgr_is_lcd(channel))
Andrew F. Davis0cac5b62016-07-01 09:27:21 -05002845 return pclk <= dispc.feat->max_lcd_pclk;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302846 else
Andrew F. Davis0cac5b62016-07-01 09:27:21 -05002847 return pclk <= dispc.feat->max_tv_pclk;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302848}
2849
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002850bool dispc_mgr_timings_ok(enum omap_channel channel, const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002851{
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002852 if (!_dispc_mgr_size_ok(vm->hactive, vm->vactive))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002853 return false;
Archit Taneja8f366162012-04-16 12:53:44 +05302854
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002855 if (!_dispc_mgr_pclk_ok(channel, vm->pixelclock))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002856 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302857
2858 if (dss_mgr_is_lcd(channel)) {
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03002859 /* TODO: OMAP4+ supports interlace for LCD outputs */
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002860 if (vm->flags & DISPLAY_FLAGS_INTERLACED)
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002861 return false;
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03002862
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002863 if (!_dispc_lcd_timings_ok(vm->hsync_len,
2864 vm->hfront_porch, vm->hback_porch,
2865 vm->vsync_len, vm->vfront_porch,
2866 vm->vback_porch))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002867 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05302868 }
Archit Taneja8f366162012-04-16 12:53:44 +05302869
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03002870 return true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002871}
2872
Peter Ujfalusi3b592932016-09-22 14:06:56 +03002873static void _dispc_mgr_set_lcd_timings(enum omap_channel channel,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002874 const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002875{
Archit Taneja655e2942012-06-21 10:37:43 +05302876 u32 timing_h, timing_v, l;
Tomi Valkeinened351882014-10-02 17:58:49 +00002877 bool onoff, rf, ipc, vs, hs, de;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002878
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002879 timing_h = FLD_VAL(vm->hsync_len - 1, dispc.feat->sw_start, 0) |
2880 FLD_VAL(vm->hfront_porch - 1, dispc.feat->fp_start, 8) |
2881 FLD_VAL(vm->hback_porch - 1, dispc.feat->bp_start, 20);
2882 timing_v = FLD_VAL(vm->vsync_len - 1, dispc.feat->sw_start, 0) |
2883 FLD_VAL(vm->vfront_porch, dispc.feat->fp_start, 8) |
2884 FLD_VAL(vm->vback_porch, dispc.feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002885
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002886 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2887 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05302888
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002889 if (vm->flags & DISPLAY_FLAGS_VSYNC_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00002890 vs = false;
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03002891 else
2892 vs = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00002893
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002894 if (vm->flags & DISPLAY_FLAGS_HSYNC_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00002895 hs = false;
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03002896 else
2897 hs = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00002898
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002899 if (vm->flags & DISPLAY_FLAGS_DE_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00002900 de = false;
Peter Ujfalusi3fa3ab42016-09-22 14:06:58 +03002901 else
2902 de = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00002903
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002904 if (vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
Archit Taneja655e2942012-06-21 10:37:43 +05302905 ipc = false;
Peter Ujfalusif149e172016-09-22 14:07:00 +03002906 else
Archit Taneja655e2942012-06-21 10:37:43 +05302907 ipc = true;
Archit Taneja655e2942012-06-21 10:37:43 +05302908
Tomi Valkeinen7a163602014-10-02 17:58:48 +00002909 /* always use the 'rf' setting */
2910 onoff = true;
2911
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002912 if (vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE)
Archit Taneja655e2942012-06-21 10:37:43 +05302913 rf = true;
Peter Ujfalusid34afb72016-09-22 14:07:01 +03002914 else
2915 rf = false;
Archit Taneja655e2942012-06-21 10:37:43 +05302916
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03002917 l = FLD_VAL(onoff, 17, 17) |
2918 FLD_VAL(rf, 16, 16) |
Tomi Valkeinened351882014-10-02 17:58:49 +00002919 FLD_VAL(de, 15, 15) |
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03002920 FLD_VAL(ipc, 14, 14) |
Tomi Valkeinened351882014-10-02 17:58:49 +00002921 FLD_VAL(hs, 13, 13) |
2922 FLD_VAL(vs, 12, 12);
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03002923
Tomi Valkeinene5f80912015-10-21 13:08:59 +03002924 /* always set ALIGN bit when available */
2925 if (dispc.feat->supports_sync_align)
2926 l |= (1 << 18);
2927
Archit Taneja655e2942012-06-21 10:37:43 +05302928 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00002929
2930 if (dispc.syscon_pol) {
2931 const int shifts[] = {
2932 [OMAP_DSS_CHANNEL_LCD] = 0,
2933 [OMAP_DSS_CHANNEL_LCD2] = 1,
2934 [OMAP_DSS_CHANNEL_LCD3] = 2,
2935 };
2936
2937 u32 mask, val;
2938
2939 mask = (1 << 0) | (1 << 3) | (1 << 6);
2940 val = (rf << 0) | (ipc << 3) | (onoff << 6);
2941
2942 mask <<= 16 + shifts[channel];
2943 val <<= 16 + shifts[channel];
2944
2945 regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset,
2946 mask, val);
2947 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002948}
2949
Tomi Valkeinen956d4f92016-11-23 13:23:42 +02002950static int vm_flag_to_int(enum display_flags flags, enum display_flags high,
2951 enum display_flags low)
2952{
2953 if (flags & high)
2954 return 1;
2955 if (flags & low)
2956 return -1;
2957 return 0;
2958}
2959
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002960/* change name to mode? */
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002961static void dispc_mgr_set_timings(enum omap_channel channel,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002962 const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002963{
2964 unsigned xtot, ytot;
2965 unsigned long ht, vt;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002966 struct videomode t = *vm;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002967
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03002968 DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive);
Archit Tanejac51d9212012-04-16 12:53:43 +05302969
Archit Taneja2aefad42012-05-18 14:36:54 +05302970 if (!dispc_mgr_timings_ok(channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05302971 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002972 return;
2973 }
Archit Tanejac51d9212012-04-16 12:53:43 +05302974
Archit Tanejadd88b7a2012-06-29 14:41:30 +05302975 if (dss_mgr_is_lcd(channel)) {
Peter Ujfalusi3b592932016-09-22 14:06:56 +03002976 _dispc_mgr_set_lcd_timings(channel, &t);
Archit Tanejac51d9212012-04-16 12:53:43 +05302977
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03002978 xtot = t.hactive + t.hfront_porch + t.hsync_len + t.hback_porch;
Peter Ujfalusi458540c2016-09-22 14:06:53 +03002979 ytot = t.vactive + t.vfront_porch + t.vsync_len + t.vback_porch;
Archit Tanejac51d9212012-04-16 12:53:43 +05302980
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002981 ht = vm->pixelclock / xtot;
2982 vt = vm->pixelclock / xtot / ytot;
Archit Tanejac51d9212012-04-16 12:53:43 +05302983
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002984 DSSDBG("pck %lu\n", vm->pixelclock);
Peter Ujfalusi4dc22502016-09-22 14:06:48 +03002985 DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03002986 t.hsync_len, t.hfront_porch, t.hback_porch,
Peter Ujfalusi458540c2016-09-22 14:06:53 +03002987 t.vsync_len, t.vfront_porch, t.vback_porch);
Archit Taneja655e2942012-06-21 10:37:43 +05302988 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 +02002989 vm_flag_to_int(t.flags, DISPLAY_FLAGS_VSYNC_HIGH, DISPLAY_FLAGS_VSYNC_LOW),
2990 vm_flag_to_int(t.flags, DISPLAY_FLAGS_HSYNC_HIGH, DISPLAY_FLAGS_HSYNC_LOW),
2991 vm_flag_to_int(t.flags, DISPLAY_FLAGS_PIXDATA_POSEDGE, DISPLAY_FLAGS_PIXDATA_NEGEDGE),
2992 vm_flag_to_int(t.flags, DISPLAY_FLAGS_DE_HIGH, DISPLAY_FLAGS_DE_LOW),
2993 vm_flag_to_int(t.flags, DISPLAY_FLAGS_SYNC_POSEDGE, DISPLAY_FLAGS_SYNC_NEGEDGE));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002994
Archit Tanejac51d9212012-04-16 12:53:43 +05302995 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05302996 } else {
Peter Ujfalusi53058292016-09-22 14:06:55 +03002997 if (t.flags & DISPLAY_FLAGS_INTERLACED)
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03002998 t.vactive /= 2;
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02002999
3000 if (dispc.feat->supports_double_pixel)
Peter Ujfalusi531efb32016-09-22 14:06:59 +03003001 REG_FLD_MOD(DISPC_CONTROL,
3002 !!(t.flags & DISPLAY_FLAGS_DOUBLECLK),
3003 19, 17);
Archit Tanejac51d9212012-04-16 12:53:43 +05303004 }
Archit Taneja8f366162012-04-16 12:53:44 +05303005
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03003006 dispc_mgr_set_size(channel, t.hactive, t.vactive);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003007}
3008
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003009static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003010 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003011{
3012 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003013 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003014
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003015 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003016 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003017
Luis de Bethencourt0bcfdba2015-10-15 13:29:38 +01003018 if (!dss_has_feature(FEAT_CORE_CLK_DIV) &&
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003019 channel == OMAP_DSS_CHANNEL_LCD)
3020 dispc.core_clk_rate = dispc_fclk_rate() / lck_div;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003021}
3022
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003023static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00003024 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003025{
3026 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003027 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003028 *lck_div = FLD_GET(l, 23, 16);
3029 *pck_div = FLD_GET(l, 7, 0);
3030}
3031
Tomi Valkeinen65904152015-11-04 17:10:57 +02003032static unsigned long dispc_fclk_rate(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003033{
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003034 unsigned long r;
3035 enum dss_clk_source src;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003036
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003037 src = dss_get_dispc_clk_source();
3038
3039 if (src == DSS_CLK_SRC_FCK) {
Tomi Valkeinen5aaee692012-12-12 10:37:03 +02003040 r = dss_get_dispc_clk_rate();
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003041 } else {
3042 struct dss_pll *pll;
3043 unsigned clkout_idx;
Tomi Valkeinen93550922014-12-31 11:25:48 +02003044
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003045 pll = dss_pll_find_by_src(src);
3046 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
Tomi Valkeinen93550922014-12-31 11:25:48 +02003047
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003048 r = pll->cinfo.clkout[clkout_idx];
Taneja, Archit66534e82011-03-08 05:50:34 -06003049 }
3050
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003051 return r;
3052}
3053
Tomi Valkeinen65904152015-11-04 17:10:57 +02003054static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003055{
3056 int lcd;
3057 unsigned long r;
Tomi Valkeinen01575772016-05-17 16:08:34 +03003058 enum dss_clk_source src;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003059
Tomi Valkeinen01575772016-05-17 16:08:34 +03003060 /* for TV, LCLK rate is the FCLK rate */
3061 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003062 return dispc_fclk_rate();
Tomi Valkeinen01575772016-05-17 16:08:34 +03003063
3064 src = dss_get_lcd_clk_source(channel);
3065
3066 if (src == DSS_CLK_SRC_FCK) {
3067 r = dss_get_dispc_clk_rate();
3068 } else {
3069 struct dss_pll *pll;
3070 unsigned clkout_idx;
3071
3072 pll = dss_pll_find_by_src(src);
3073 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
3074
3075 r = pll->cinfo.clkout[clkout_idx];
Taneja, Architea751592011-03-08 05:50:35 -06003076 }
Tomi Valkeinen01575772016-05-17 16:08:34 +03003077
3078 lcd = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3079
3080 return r / lcd;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003081}
3082
Tomi Valkeinen65904152015-11-04 17:10:57 +02003083static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003084{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003085 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003086
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303087 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303088 int pcd;
3089 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003090
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303091 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003092
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303093 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003094
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303095 r = dispc_mgr_lclk_rate(channel);
3096
3097 return r / pcd;
3098 } else {
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003099 return dispc.tv_pclk_rate;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303100 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003101}
3102
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003103void dispc_set_tv_pclk(unsigned long pclk)
3104{
3105 dispc.tv_pclk_rate = pclk;
3106}
3107
Tomi Valkeinen65904152015-11-04 17:10:57 +02003108static unsigned long dispc_core_clk_rate(void)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303109{
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003110 return dispc.core_clk_rate;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303111}
3112
Jyri Sarha864050c2017-03-24 16:47:52 +02003113static unsigned long dispc_plane_pclk_rate(enum omap_plane_id plane)
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303114{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003115 enum omap_channel channel;
3116
3117 if (plane == OMAP_DSS_WB)
3118 return 0;
3119
3120 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303121
3122 return dispc_mgr_pclk_rate(channel);
3123}
3124
Jyri Sarha864050c2017-03-24 16:47:52 +02003125static unsigned long dispc_plane_lclk_rate(enum omap_plane_id plane)
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303126{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003127 enum omap_channel channel;
3128
3129 if (plane == OMAP_DSS_WB)
3130 return 0;
3131
3132 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303133
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003134 return dispc_mgr_lclk_rate(channel);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303135}
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003136
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303137static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003138{
3139 int lcd, pcd;
Tomi Valkeinendc0352d2016-05-17 13:45:09 +03003140 enum dss_clk_source lcd_clk_src;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303141
3142 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3143
3144 lcd_clk_src = dss_get_lcd_clk_source(channel);
3145
Tomi Valkeinen557a1542016-05-17 13:49:18 +03003146 seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name,
Tomi Valkeinen407bd562016-05-17 13:50:55 +03003147 dss_get_clk_source_name(lcd_clk_src));
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303148
3149 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3150
3151 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3152 dispc_mgr_lclk_rate(channel), lcd);
3153 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3154 dispc_mgr_pclk_rate(channel), pcd);
3155}
3156
3157void dispc_dump_clocks(struct seq_file *s)
3158{
3159 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003160 u32 l;
Tomi Valkeinendc0352d2016-05-17 13:45:09 +03003161 enum dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003162
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003163 if (dispc_runtime_get())
3164 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003165
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003166 seq_printf(s, "- DISPC -\n");
3167
Tomi Valkeinen557a1542016-05-17 13:49:18 +03003168 seq_printf(s, "dispc fclk source = %s\n",
Tomi Valkeinen407bd562016-05-17 13:50:55 +03003169 dss_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003170
3171 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00003172
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003173 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3174 seq_printf(s, "- DISPC-CORE-CLK -\n");
3175 l = dispc_read_reg(DISPC_DIVISOR);
3176 lcd = FLD_GET(l, 23, 16);
3177
3178 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3179 (dispc_fclk_rate()/lcd), lcd);
3180 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003181
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303182 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003183
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303184 if (dss_has_feature(FEAT_MGR_LCD2))
3185 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3186 if (dss_has_feature(FEAT_MGR_LCD3))
3187 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003188
3189 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003190}
3191
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003192static void dispc_dump_regs(struct seq_file *s)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003193{
Archit Taneja4dd2da12011-08-05 19:06:01 +05303194 int i, j;
3195 const char *mgr_names[] = {
3196 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3197 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3198 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303199 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303200 };
3201 const char *ovl_names[] = {
3202 [OMAP_DSS_GFX] = "GFX",
3203 [OMAP_DSS_VIDEO1] = "VID1",
3204 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303205 [OMAP_DSS_VIDEO3] = "VID3",
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003206 [OMAP_DSS_WB] = "WB",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303207 };
3208 const char **p_names;
3209
Archit Taneja9b372c22011-05-06 11:45:49 +05303210#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003211
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003212 if (dispc_runtime_get())
3213 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003214
Archit Taneja5010be82011-08-05 19:06:00 +05303215 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003216 DUMPREG(DISPC_REVISION);
3217 DUMPREG(DISPC_SYSCONFIG);
3218 DUMPREG(DISPC_SYSSTATUS);
3219 DUMPREG(DISPC_IRQSTATUS);
3220 DUMPREG(DISPC_IRQENABLE);
3221 DUMPREG(DISPC_CONTROL);
3222 DUMPREG(DISPC_CONFIG);
3223 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003224 DUMPREG(DISPC_LINE_STATUS);
3225 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05303226 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3227 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003228 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003229 if (dss_has_feature(FEAT_MGR_LCD2)) {
3230 DUMPREG(DISPC_CONTROL2);
3231 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003232 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303233 if (dss_has_feature(FEAT_MGR_LCD3)) {
3234 DUMPREG(DISPC_CONTROL3);
3235 DUMPREG(DISPC_CONFIG3);
3236 }
Tomi Valkeinen29fceee2013-11-14 11:38:25 +02003237 if (dss_has_feature(FEAT_MFLAG))
3238 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003239
Archit Taneja5010be82011-08-05 19:06:00 +05303240#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003241
Archit Taneja5010be82011-08-05 19:06:00 +05303242#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05303243#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003244 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303245 dispc_read_reg(DISPC_REG(i, r)))
3246
Archit Taneja4dd2da12011-08-05 19:06:01 +05303247 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303248
Archit Taneja4dd2da12011-08-05 19:06:01 +05303249 /* DISPC channel specific registers */
3250 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3251 DUMPREG(i, DISPC_DEFAULT_COLOR);
3252 DUMPREG(i, DISPC_TRANS_COLOR);
3253 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003254
Archit Taneja4dd2da12011-08-05 19:06:01 +05303255 if (i == OMAP_DSS_CHANNEL_DIGIT)
3256 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303257
Archit Taneja4dd2da12011-08-05 19:06:01 +05303258 DUMPREG(i, DISPC_TIMING_H);
3259 DUMPREG(i, DISPC_TIMING_V);
3260 DUMPREG(i, DISPC_POL_FREQ);
3261 DUMPREG(i, DISPC_DIVISORo);
Archit Taneja5010be82011-08-05 19:06:00 +05303262
Archit Taneja4dd2da12011-08-05 19:06:01 +05303263 DUMPREG(i, DISPC_DATA_CYCLE1);
3264 DUMPREG(i, DISPC_DATA_CYCLE2);
3265 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003266
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003267 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303268 DUMPREG(i, DISPC_CPR_COEF_R);
3269 DUMPREG(i, DISPC_CPR_COEF_G);
3270 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003271 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003272 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003273
Archit Taneja4dd2da12011-08-05 19:06:01 +05303274 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003275
Archit Taneja4dd2da12011-08-05 19:06:01 +05303276 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3277 DUMPREG(i, DISPC_OVL_BA0);
3278 DUMPREG(i, DISPC_OVL_BA1);
3279 DUMPREG(i, DISPC_OVL_POSITION);
3280 DUMPREG(i, DISPC_OVL_SIZE);
3281 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3282 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3283 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3284 DUMPREG(i, DISPC_OVL_ROW_INC);
3285 DUMPREG(i, DISPC_OVL_PIXEL_INC);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003286
Archit Taneja4dd2da12011-08-05 19:06:01 +05303287 if (dss_has_feature(FEAT_PRELOAD))
3288 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003289 if (dss_has_feature(FEAT_MFLAG))
3290 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003291
Archit Taneja4dd2da12011-08-05 19:06:01 +05303292 if (i == OMAP_DSS_GFX) {
3293 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3294 DUMPREG(i, DISPC_OVL_TABLE_BA);
3295 continue;
3296 }
3297
3298 DUMPREG(i, DISPC_OVL_FIR);
3299 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3300 DUMPREG(i, DISPC_OVL_ACCU0);
3301 DUMPREG(i, DISPC_OVL_ACCU1);
3302 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3303 DUMPREG(i, DISPC_OVL_BA0_UV);
3304 DUMPREG(i, DISPC_OVL_BA1_UV);
3305 DUMPREG(i, DISPC_OVL_FIR2);
3306 DUMPREG(i, DISPC_OVL_ACCU2_0);
3307 DUMPREG(i, DISPC_OVL_ACCU2_1);
3308 }
3309 if (dss_has_feature(FEAT_ATTR2))
3310 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
Archit Taneja5010be82011-08-05 19:06:00 +05303311 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003312
Tomi Valkeinen20efbc32015-11-04 17:10:44 +02003313 if (dispc.feat->has_writeback) {
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003314 i = OMAP_DSS_WB;
3315 DUMPREG(i, DISPC_OVL_BA0);
3316 DUMPREG(i, DISPC_OVL_BA1);
3317 DUMPREG(i, DISPC_OVL_SIZE);
3318 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3319 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3320 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3321 DUMPREG(i, DISPC_OVL_ROW_INC);
3322 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3323
3324 if (dss_has_feature(FEAT_MFLAG))
3325 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
3326
3327 DUMPREG(i, DISPC_OVL_FIR);
3328 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3329 DUMPREG(i, DISPC_OVL_ACCU0);
3330 DUMPREG(i, DISPC_OVL_ACCU1);
3331 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3332 DUMPREG(i, DISPC_OVL_BA0_UV);
3333 DUMPREG(i, DISPC_OVL_BA1_UV);
3334 DUMPREG(i, DISPC_OVL_FIR2);
3335 DUMPREG(i, DISPC_OVL_ACCU2_0);
3336 DUMPREG(i, DISPC_OVL_ACCU2_1);
3337 }
3338 if (dss_has_feature(FEAT_ATTR2))
3339 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3340 }
3341
Archit Taneja5010be82011-08-05 19:06:00 +05303342#undef DISPC_REG
3343#undef DUMPREG
3344
3345#define DISPC_REG(plane, name, i) name(plane, i)
3346#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303347 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003348 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303349 dispc_read_reg(DISPC_REG(plane, name, i)))
3350
Archit Taneja4dd2da12011-08-05 19:06:01 +05303351 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303352
Archit Taneja4dd2da12011-08-05 19:06:01 +05303353 /* start from OMAP_DSS_VIDEO1 */
3354 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3355 for (j = 0; j < 8; j++)
3356 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303357
Archit Taneja4dd2da12011-08-05 19:06:01 +05303358 for (j = 0; j < 8; j++)
3359 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303360
Archit Taneja4dd2da12011-08-05 19:06:01 +05303361 for (j = 0; j < 5; j++)
3362 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003363
Archit Taneja4dd2da12011-08-05 19:06:01 +05303364 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3365 for (j = 0; j < 8; j++)
3366 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3367 }
Amber Jainab5ca072011-05-19 19:47:53 +05303368
Archit Taneja4dd2da12011-08-05 19:06:01 +05303369 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3370 for (j = 0; j < 8; j++)
3371 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303372
Archit Taneja4dd2da12011-08-05 19:06:01 +05303373 for (j = 0; j < 8; j++)
3374 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303375
Archit Taneja4dd2da12011-08-05 19:06:01 +05303376 for (j = 0; j < 8; j++)
3377 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3378 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003379 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003380
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003381 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05303382
3383#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003384#undef DUMPREG
3385}
3386
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003387/* calculate clock rates using dividers in cinfo */
3388int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3389 struct dispc_clock_info *cinfo)
3390{
3391 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3392 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003393 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003394 return -EINVAL;
3395
3396 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3397 cinfo->pck = cinfo->lck / cinfo->pck_div;
3398
3399 return 0;
3400}
3401
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003402bool dispc_div_calc(unsigned long dispc,
3403 unsigned long pck_min, unsigned long pck_max,
3404 dispc_div_calc_func func, void *data)
3405{
3406 int lckd, lckd_start, lckd_stop;
3407 int pckd, pckd_start, pckd_stop;
3408 unsigned long pck, lck;
3409 unsigned long lck_max;
3410 unsigned long pckd_hw_min, pckd_hw_max;
3411 unsigned min_fck_per_pck;
3412 unsigned long fck;
3413
3414#ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3415 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3416#else
3417 min_fck_per_pck = 0;
3418#endif
3419
3420 pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3421 pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3422
3423 lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
3424
3425 pck_min = pck_min ? pck_min : 1;
3426 pck_max = pck_max ? pck_max : ULONG_MAX;
3427
3428 lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul);
3429 lckd_stop = min(dispc / pck_min, 255ul);
3430
3431 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3432 lck = dispc / lckd;
3433
3434 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3435 pckd_stop = min(lck / pck_min, pckd_hw_max);
3436
3437 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3438 pck = lck / pckd;
3439
3440 /*
3441 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3442 * clock, which means we're configuring DISPC fclk here
3443 * also. Thus we need to use the calculated lck. For
3444 * OMAP4+ the DISPC fclk is a separate clock.
3445 */
3446 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3447 fck = dispc_core_clk_rate();
3448 else
3449 fck = lck;
3450
3451 if (fck < pck * min_fck_per_pck)
3452 continue;
3453
3454 if (func(lckd, pckd, lck, pck, data))
3455 return true;
3456 }
3457 }
3458
3459 return false;
3460}
3461
Archit Tanejaf0d08f82012-06-29 14:00:54 +05303462void dispc_mgr_set_clock_div(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003463 const struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003464{
3465 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3466 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3467
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003468 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003469}
3470
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003471int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003472 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003473{
3474 unsigned long fck;
3475
3476 fck = dispc_fclk_rate();
3477
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003478 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3479 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003480
3481 cinfo->lck = fck / cinfo->lck_div;
3482 cinfo->pck = cinfo->lck / cinfo->pck_div;
3483
3484 return 0;
3485}
3486
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003487static u32 dispc_read_irqstatus(void)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003488{
3489 return dispc_read_reg(DISPC_IRQSTATUS);
3490}
3491
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003492static void dispc_clear_irqstatus(u32 mask)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003493{
3494 dispc_write_reg(DISPC_IRQSTATUS, mask);
3495}
3496
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003497static void dispc_write_irqenable(u32 mask)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003498{
3499 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3500
3501 /* clear the irqstatus for newly enabled irqs */
3502 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3503
3504 dispc_write_reg(DISPC_IRQENABLE, mask);
Tomi Valkeinen2e953d82017-02-20 13:18:38 +02003505
3506 /* flush posted write */
3507 dispc_read_reg(DISPC_IRQENABLE);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003508}
3509
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003510void dispc_enable_sidle(void)
3511{
3512 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3513}
3514
3515void dispc_disable_sidle(void)
3516{
3517 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3518}
3519
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003520static u32 dispc_mgr_gamma_size(enum omap_channel channel)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003521{
3522 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3523
3524 if (!dispc.feat->has_gamma_table)
3525 return 0;
3526
3527 return gdesc->len;
3528}
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003529
3530static void dispc_mgr_write_gamma_table(enum omap_channel channel)
3531{
3532 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3533 u32 *table = dispc.gamma_table[channel];
3534 unsigned int i;
3535
3536 DSSDBG("%s: channel %d\n", __func__, channel);
3537
3538 for (i = 0; i < gdesc->len; ++i) {
3539 u32 v = table[i];
3540
3541 if (gdesc->has_index)
3542 v |= i << 24;
3543 else if (i == 0)
3544 v |= 1 << 31;
3545
3546 dispc_write_reg(gdesc->reg, v);
3547 }
3548}
3549
3550static void dispc_restore_gamma_tables(void)
3551{
3552 DSSDBG("%s()\n", __func__);
3553
3554 if (!dispc.feat->has_gamma_table)
3555 return;
3556
3557 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD);
3558
3559 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_DIGIT);
3560
3561 if (dss_has_feature(FEAT_MGR_LCD2))
3562 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD2);
3563
3564 if (dss_has_feature(FEAT_MGR_LCD3))
3565 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD3);
3566}
3567
3568static const struct drm_color_lut dispc_mgr_gamma_default_lut[] = {
3569 { .red = 0, .green = 0, .blue = 0, },
3570 { .red = U16_MAX, .green = U16_MAX, .blue = U16_MAX, },
3571};
3572
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003573static void dispc_mgr_set_gamma(enum omap_channel channel,
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003574 const struct drm_color_lut *lut,
3575 unsigned int length)
3576{
3577 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3578 u32 *table = dispc.gamma_table[channel];
3579 uint i;
3580
3581 DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__,
3582 channel, length, gdesc->len);
3583
3584 if (!dispc.feat->has_gamma_table)
3585 return;
3586
3587 if (lut == NULL || length < 2) {
3588 lut = dispc_mgr_gamma_default_lut;
3589 length = ARRAY_SIZE(dispc_mgr_gamma_default_lut);
3590 }
3591
3592 for (i = 0; i < length - 1; ++i) {
3593 uint first = i * (gdesc->len - 1) / (length - 1);
3594 uint last = (i + 1) * (gdesc->len - 1) / (length - 1);
3595 uint w = last - first;
3596 u16 r, g, b;
3597 uint j;
3598
3599 if (w == 0)
3600 continue;
3601
3602 for (j = 0; j <= w; j++) {
3603 r = (lut[i].red * (w - j) + lut[i+1].red * j) / w;
3604 g = (lut[i].green * (w - j) + lut[i+1].green * j) / w;
3605 b = (lut[i].blue * (w - j) + lut[i+1].blue * j) / w;
3606
3607 r >>= 16 - gdesc->bits;
3608 g >>= 16 - gdesc->bits;
3609 b >>= 16 - gdesc->bits;
3610
3611 table[first + j] = (r << (gdesc->bits * 2)) |
3612 (g << gdesc->bits) | b;
3613 }
3614 }
3615
3616 if (dispc.is_enabled)
3617 dispc_mgr_write_gamma_table(channel);
3618}
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003619
3620static int dispc_init_gamma_tables(void)
3621{
3622 int channel;
3623
3624 if (!dispc.feat->has_gamma_table)
3625 return 0;
3626
3627 for (channel = 0; channel < ARRAY_SIZE(dispc.gamma_table); channel++) {
3628 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3629 u32 *gt;
3630
3631 if (channel == OMAP_DSS_CHANNEL_LCD2 &&
3632 !dss_has_feature(FEAT_MGR_LCD2))
3633 continue;
3634
3635 if (channel == OMAP_DSS_CHANNEL_LCD3 &&
3636 !dss_has_feature(FEAT_MGR_LCD3))
3637 continue;
3638
3639 gt = devm_kmalloc_array(&dispc.pdev->dev, gdesc->len,
3640 sizeof(u32), GFP_KERNEL);
3641 if (!gt)
3642 return -ENOMEM;
3643
3644 dispc.gamma_table[channel] = gt;
3645
3646 dispc_mgr_set_gamma(channel, NULL, 0);
3647 }
3648 return 0;
3649}
3650
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003651static void _omap_dispc_initial_config(void)
3652{
3653 u32 l;
3654
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003655 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3656 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3657 l = dispc_read_reg(DISPC_DIVISOR);
3658 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3659 l = FLD_MOD(l, 1, 0, 0);
3660 l = FLD_MOD(l, 1, 23, 16);
3661 dispc_write_reg(DISPC_DIVISOR, l);
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003662
3663 dispc.core_clk_rate = dispc_fclk_rate();
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003664 }
3665
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003666 /* Use gamma table mode, instead of palette mode */
3667 if (dispc.feat->has_gamma_table)
3668 REG_FLD_MOD(DISPC_CONFIG, 1, 3, 3);
3669
3670 /* For older DSS versions (FEAT_FUNCGATED) this enables
3671 * func-clock auto-gating. For newer versions
3672 * (dispc.feat->has_gamma_table) this enables tv-out gamma tables.
3673 */
3674 if (dss_has_feature(FEAT_FUNCGATED) || dispc.feat->has_gamma_table)
Archit Taneja6ced40b2010-12-02 11:27:13 +00003675 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003676
Archit Taneja6e5264b2012-09-11 12:04:47 +05303677 dispc_setup_color_conv_coef();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003678
3679 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3680
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003681 dispc_init_fifos();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003682
3683 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05303684
3685 dispc_ovl_enable_zorder_planes();
Archit Tanejad0df9a22013-03-26 19:15:25 +05303686
3687 if (dispc.feat->mstandby_workaround)
3688 REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0);
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00003689
3690 if (dss_has_feature(FEAT_MFLAG))
3691 dispc_init_mflag();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003692}
3693
Tomi Valkeinenede92692015-06-04 14:12:16 +03003694static const struct dispc_features omap24xx_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303695 .sw_start = 5,
3696 .fp_start = 15,
3697 .bp_start = 27,
3698 .sw_max = 64,
3699 .vp_max = 255,
3700 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303701 .mgr_width_start = 10,
3702 .mgr_height_start = 26,
3703 .mgr_width_max = 2048,
3704 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303705 .max_lcd_pclk = 66500000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303706 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3707 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003708 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003709 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303710 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003711 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303712};
3713
Tomi Valkeinenede92692015-06-04 14:12:16 +03003714static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303715 .sw_start = 5,
3716 .fp_start = 15,
3717 .bp_start = 27,
3718 .sw_max = 64,
3719 .vp_max = 255,
3720 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303721 .mgr_width_start = 10,
3722 .mgr_height_start = 26,
3723 .mgr_width_max = 2048,
3724 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303725 .max_lcd_pclk = 173000000,
3726 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303727 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3728 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003729 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003730 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303731 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003732 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303733};
3734
Tomi Valkeinenede92692015-06-04 14:12:16 +03003735static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303736 .sw_start = 7,
3737 .fp_start = 19,
3738 .bp_start = 31,
3739 .sw_max = 256,
3740 .vp_max = 4095,
3741 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303742 .mgr_width_start = 10,
3743 .mgr_height_start = 26,
3744 .mgr_width_max = 2048,
3745 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303746 .max_lcd_pclk = 173000000,
3747 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303748 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3749 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003750 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003751 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303752 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003753 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303754};
3755
Tomi Valkeinenede92692015-06-04 14:12:16 +03003756static const struct dispc_features omap44xx_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303757 .sw_start = 7,
3758 .fp_start = 19,
3759 .bp_start = 31,
3760 .sw_max = 256,
3761 .vp_max = 4095,
3762 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05303763 .mgr_width_start = 10,
3764 .mgr_height_start = 26,
3765 .mgr_width_max = 2048,
3766 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303767 .max_lcd_pclk = 170000000,
3768 .max_tv_pclk = 185625000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303769 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3770 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003771 .num_fifos = 5,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03003772 .gfx_fifo_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303773 .set_max_preload = true,
Tomi Valkeinene5f80912015-10-21 13:08:59 +03003774 .supports_sync_align = true,
Tomi Valkeinen20efbc32015-11-04 17:10:44 +02003775 .has_writeback = true,
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02003776 .supports_double_pixel = true,
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02003777 .reverse_ilace_field_order = true,
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003778 .has_gamma_table = true,
Jyri Sarhafbff0102016-06-07 15:09:16 +03003779 .has_gamma_i734_bug = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303780};
3781
Tomi Valkeinenede92692015-06-04 14:12:16 +03003782static const struct dispc_features omap54xx_dispc_feats = {
Archit Taneja264236f2012-11-14 13:50:16 +05303783 .sw_start = 7,
3784 .fp_start = 19,
3785 .bp_start = 31,
3786 .sw_max = 256,
3787 .vp_max = 4095,
3788 .hp_max = 4096,
3789 .mgr_width_start = 11,
3790 .mgr_height_start = 27,
3791 .mgr_width_max = 4096,
3792 .mgr_height_max = 4096,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303793 .max_lcd_pclk = 170000000,
3794 .max_tv_pclk = 186000000,
Archit Taneja264236f2012-11-14 13:50:16 +05303795 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3796 .calc_core_clk = calc_core_clk_44xx,
3797 .num_fifos = 5,
3798 .gfx_fifo_workaround = true,
Archit Tanejad0df9a22013-03-26 19:15:25 +05303799 .mstandby_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303800 .set_max_preload = true,
Tomi Valkeinene5f80912015-10-21 13:08:59 +03003801 .supports_sync_align = true,
Tomi Valkeinen20efbc32015-11-04 17:10:44 +02003802 .has_writeback = true,
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02003803 .supports_double_pixel = true,
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02003804 .reverse_ilace_field_order = true,
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003805 .has_gamma_table = true,
Jyri Sarhafbff0102016-06-07 15:09:16 +03003806 .has_gamma_i734_bug = true,
Archit Taneja264236f2012-11-14 13:50:16 +05303807};
3808
Tomi Valkeinenede92692015-06-04 14:12:16 +03003809static int dispc_init_features(struct platform_device *pdev)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303810{
3811 const struct dispc_features *src;
3812 struct dispc_features *dst;
3813
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003814 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303815 if (!dst) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003816 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303817 return -ENOMEM;
3818 }
3819
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +03003820 switch (omapdss_get_version()) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003821 case OMAPDSS_VER_OMAP24xx:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303822 src = &omap24xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003823 break;
3824
3825 case OMAPDSS_VER_OMAP34xx_ES1:
3826 src = &omap34xx_rev1_0_dispc_feats;
3827 break;
3828
3829 case OMAPDSS_VER_OMAP34xx_ES3:
3830 case OMAPDSS_VER_OMAP3630:
3831 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +05303832 case OMAPDSS_VER_AM43xx:
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003833 src = &omap34xx_rev3_0_dispc_feats;
3834 break;
3835
3836 case OMAPDSS_VER_OMAP4430_ES1:
3837 case OMAPDSS_VER_OMAP4430_ES2:
3838 case OMAPDSS_VER_OMAP4:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303839 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003840 break;
3841
3842 case OMAPDSS_VER_OMAP5:
Tomi Valkeinen93550922014-12-31 11:25:48 +02003843 case OMAPDSS_VER_DRA7xx:
Archit Taneja264236f2012-11-14 13:50:16 +05303844 src = &omap54xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03003845 break;
3846
3847 default:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303848 return -ENODEV;
3849 }
3850
3851 memcpy(dst, src, sizeof(*dst));
3852 dispc.feat = dst;
3853
3854 return 0;
3855}
3856
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003857static irqreturn_t dispc_irq_handler(int irq, void *arg)
3858{
3859 if (!dispc.is_enabled)
3860 return IRQ_NONE;
3861
3862 return dispc.user_handler(irq, dispc.user_data);
3863}
3864
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003865static int dispc_request_irq(irq_handler_t handler, void *dev_id)
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003866{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003867 int r;
3868
3869 if (dispc.user_handler != NULL)
3870 return -EBUSY;
3871
3872 dispc.user_handler = handler;
3873 dispc.user_data = dev_id;
3874
3875 /* ensure the dispc_irq_handler sees the values above */
3876 smp_wmb();
3877
3878 r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler,
3879 IRQF_SHARED, "OMAP DISPC", &dispc);
3880 if (r) {
3881 dispc.user_handler = NULL;
3882 dispc.user_data = NULL;
3883 }
3884
3885 return r;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003886}
3887
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003888static void dispc_free_irq(void *dev_id)
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003889{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03003890 devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc);
3891
3892 dispc.user_handler = NULL;
3893 dispc.user_data = NULL;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03003894}
3895
Jyri Sarhafbff0102016-06-07 15:09:16 +03003896/*
3897 * Workaround for errata i734 in DSS dispc
3898 * - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled
3899 *
3900 * For gamma tables to work on LCD1 the GFX plane has to be used at
3901 * least once after DSS HW has come out of reset. The workaround
3902 * sets up a minimal LCD setup with GFX plane and waits for one
3903 * vertical sync irq before disabling the setup and continuing with
3904 * the context restore. The physical outputs are gated during the
3905 * operation. This workaround requires that gamma table's LOADMODE
3906 * is set to 0x2 in DISPC_CONTROL1 register.
3907 *
3908 * For details see:
3909 * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata
3910 * Literature Number: SWPZ037E
3911 * Or some other relevant errata document for the DSS IP version.
3912 */
3913
3914static const struct dispc_errata_i734_data {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003915 struct videomode vm;
Jyri Sarhafbff0102016-06-07 15:09:16 +03003916 struct omap_overlay_info ovli;
3917 struct omap_overlay_manager_info mgri;
3918 struct dss_lcd_mgr_config lcd_conf;
3919} i734 = {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003920 .vm = {
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03003921 .hactive = 8, .vactive = 1,
Jyri Sarhafbff0102016-06-07 15:09:16 +03003922 .pixelclock = 16000000,
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03003923 .hsync_len = 8, .hfront_porch = 4, .hback_porch = 4,
Peter Ujfalusi458540c2016-09-22 14:06:53 +03003924 .vsync_len = 1, .vfront_porch = 1, .vback_porch = 1,
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03003925
Peter Ujfalusi3fa3ab42016-09-22 14:06:58 +03003926 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
Peter Ujfalusid34afb72016-09-22 14:07:01 +03003927 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
3928 DISPLAY_FLAGS_PIXDATA_POSEDGE,
Jyri Sarhafbff0102016-06-07 15:09:16 +03003929 },
3930 .ovli = {
3931 .screen_width = 1,
3932 .width = 1, .height = 1,
3933 .color_mode = OMAP_DSS_COLOR_RGB24U,
3934 .rotation = OMAP_DSS_ROT_0,
Tomi Valkeinen517a8a952017-05-03 14:14:27 +03003935 .rotation_type = OMAP_DSS_ROT_NONE,
Jyri Sarhafbff0102016-06-07 15:09:16 +03003936 .mirror = 0,
3937 .pos_x = 0, .pos_y = 0,
3938 .out_width = 0, .out_height = 0,
3939 .global_alpha = 0xff,
3940 .pre_mult_alpha = 0,
3941 .zorder = 0,
3942 },
3943 .mgri = {
3944 .default_color = 0,
3945 .trans_enabled = false,
3946 .partial_alpha_enabled = false,
3947 .cpr_enable = false,
3948 },
3949 .lcd_conf = {
3950 .io_pad_mode = DSS_IO_PAD_MODE_BYPASS,
3951 .stallmode = false,
3952 .fifohandcheck = false,
3953 .clock_info = {
3954 .lck_div = 1,
3955 .pck_div = 2,
3956 },
3957 .video_port_width = 24,
3958 .lcden_sig_polarity = 0,
3959 },
3960};
3961
3962static struct i734_buf {
3963 size_t size;
3964 dma_addr_t paddr;
3965 void *vaddr;
3966} i734_buf;
3967
3968static int dispc_errata_i734_wa_init(void)
3969{
3970 if (!dispc.feat->has_gamma_i734_bug)
3971 return 0;
3972
3973 i734_buf.size = i734.ovli.width * i734.ovli.height *
3974 color_mode_to_bpp(i734.ovli.color_mode) / 8;
3975
3976 i734_buf.vaddr = dma_alloc_writecombine(&dispc.pdev->dev, i734_buf.size,
3977 &i734_buf.paddr, GFP_KERNEL);
3978 if (!i734_buf.vaddr) {
3979 dev_err(&dispc.pdev->dev, "%s: dma_alloc_writecombine failed",
3980 __func__);
3981 return -ENOMEM;
3982 }
3983
3984 return 0;
3985}
3986
3987static void dispc_errata_i734_wa_fini(void)
3988{
3989 if (!dispc.feat->has_gamma_i734_bug)
3990 return;
3991
3992 dma_free_writecombine(&dispc.pdev->dev, i734_buf.size, i734_buf.vaddr,
3993 i734_buf.paddr);
3994}
3995
3996static void dispc_errata_i734_wa(void)
3997{
3998 u32 framedone_irq = dispc_mgr_get_framedone_irq(OMAP_DSS_CHANNEL_LCD);
3999 struct omap_overlay_info ovli;
4000 struct dss_lcd_mgr_config lcd_conf;
4001 u32 gatestate;
4002 unsigned int count;
4003
4004 if (!dispc.feat->has_gamma_i734_bug)
4005 return;
4006
4007 gatestate = REG_GET(DISPC_CONFIG, 8, 4);
4008
4009 ovli = i734.ovli;
4010 ovli.paddr = i734_buf.paddr;
4011 lcd_conf = i734.lcd_conf;
4012
4013 /* Gate all LCD1 outputs */
4014 REG_FLD_MOD(DISPC_CONFIG, 0x1f, 8, 4);
4015
4016 /* Setup and enable GFX plane */
Tomi Valkeinen49a30572017-02-17 12:30:07 +02004017 dispc_ovl_setup(OMAP_DSS_GFX, &ovli, &i734.vm, false,
4018 OMAP_DSS_CHANNEL_LCD);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004019 dispc_ovl_enable(OMAP_DSS_GFX, true);
4020
4021 /* Set up and enable display manager for LCD1 */
4022 dispc_mgr_setup(OMAP_DSS_CHANNEL_LCD, &i734.mgri);
4023 dispc_calc_clock_rates(dss_get_dispc_clk_rate(),
4024 &lcd_conf.clock_info);
4025 dispc_mgr_set_lcd_config(OMAP_DSS_CHANNEL_LCD, &lcd_conf);
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03004026 dispc_mgr_set_timings(OMAP_DSS_CHANNEL_LCD, &i734.vm);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004027
4028 dispc_clear_irqstatus(framedone_irq);
4029
4030 /* Enable and shut the channel to produce just one frame */
4031 dispc_mgr_enable(OMAP_DSS_CHANNEL_LCD, true);
4032 dispc_mgr_enable(OMAP_DSS_CHANNEL_LCD, false);
4033
4034 /* Busy wait for framedone. We can't fiddle with irq handlers
4035 * in PM resume. Typically the loop runs less than 5 times and
4036 * waits less than a micro second.
4037 */
4038 count = 0;
4039 while (!(dispc_read_irqstatus() & framedone_irq)) {
4040 if (count++ > 10000) {
4041 dev_err(&dispc.pdev->dev, "%s: framedone timeout\n",
4042 __func__);
4043 break;
4044 }
4045 }
4046 dispc_ovl_enable(OMAP_DSS_GFX, false);
4047
4048 /* Clear all irq bits before continuing */
4049 dispc_clear_irqstatus(0xffffffff);
4050
4051 /* Restore the original state to LCD1 output gates */
4052 REG_FLD_MOD(DISPC_CONFIG, gatestate, 8, 4);
4053}
4054
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004055static const struct dispc_ops dispc_ops = {
4056 .read_irqstatus = dispc_read_irqstatus,
4057 .clear_irqstatus = dispc_clear_irqstatus,
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004058 .write_irqenable = dispc_write_irqenable,
4059
4060 .request_irq = dispc_request_irq,
4061 .free_irq = dispc_free_irq,
4062
4063 .runtime_get = dispc_runtime_get,
4064 .runtime_put = dispc_runtime_put,
4065
4066 .get_num_ovls = dispc_get_num_ovls,
4067 .get_num_mgrs = dispc_get_num_mgrs,
4068
4069 .mgr_enable = dispc_mgr_enable,
4070 .mgr_is_enabled = dispc_mgr_is_enabled,
4071 .mgr_get_vsync_irq = dispc_mgr_get_vsync_irq,
4072 .mgr_get_framedone_irq = dispc_mgr_get_framedone_irq,
4073 .mgr_get_sync_lost_irq = dispc_mgr_get_sync_lost_irq,
4074 .mgr_go_busy = dispc_mgr_go_busy,
4075 .mgr_go = dispc_mgr_go,
4076 .mgr_set_lcd_config = dispc_mgr_set_lcd_config,
4077 .mgr_set_timings = dispc_mgr_set_timings,
4078 .mgr_setup = dispc_mgr_setup,
4079 .mgr_get_supported_outputs = dispc_mgr_get_supported_outputs,
4080 .mgr_gamma_size = dispc_mgr_gamma_size,
4081 .mgr_set_gamma = dispc_mgr_set_gamma,
4082
4083 .ovl_enable = dispc_ovl_enable,
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004084 .ovl_setup = dispc_ovl_setup,
4085 .ovl_get_color_modes = dispc_ovl_get_color_modes,
4086};
4087
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004088/* DISPC HW IP initialisation */
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004089static int dispc_bind(struct device *dev, struct device *master, void *data)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004090{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004091 struct platform_device *pdev = to_platform_device(dev);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004092 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00004093 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004094 struct resource *dispc_mem;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004095 struct device_node *np = pdev->dev.of_node;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004096
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004097 dispc.pdev = pdev;
4098
Tomi Valkeinend49cd152014-11-10 12:23:00 +02004099 spin_lock_init(&dispc.control_lock);
4100
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004101 r = dispc_init_features(dispc.pdev);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304102 if (r)
4103 return r;
4104
Jyri Sarhafbff0102016-06-07 15:09:16 +03004105 r = dispc_errata_i734_wa_init();
4106 if (r)
4107 return r;
4108
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004109 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
Laurent Pinchartb22622f2017-05-07 00:29:09 +03004110 dispc.base = devm_ioremap_resource(&pdev->dev, dispc_mem);
4111 if (IS_ERR(dispc.base))
4112 return PTR_ERR(dispc.base);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004113
archit tanejaaffe3602011-02-23 08:41:03 +00004114 dispc.irq = platform_get_irq(dispc.pdev, 0);
4115 if (dispc.irq < 0) {
4116 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004117 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00004118 }
4119
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004120 if (np && of_property_read_bool(np, "syscon-pol")) {
4121 dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
4122 if (IS_ERR(dispc.syscon_pol)) {
4123 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
4124 return PTR_ERR(dispc.syscon_pol);
4125 }
4126
4127 if (of_property_read_u32_index(np, "syscon-pol", 1,
4128 &dispc.syscon_pol_offset)) {
4129 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
4130 return -EINVAL;
4131 }
4132 }
4133
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004134 r = dispc_init_gamma_tables();
4135 if (r)
4136 return r;
4137
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004138 pm_runtime_enable(&pdev->dev);
4139
4140 r = dispc_runtime_get();
4141 if (r)
4142 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004143
4144 _omap_dispc_initial_config();
4145
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004146 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00004147 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004148 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4149
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004150 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004151
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004152 dispc_set_ops(&dispc_ops);
4153
Tomi Valkeinene40402c2012-03-02 18:01:07 +02004154 dss_debugfs_create_file("dispc", dispc_dump_regs);
4155
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004156 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004157
4158err_runtime_get:
4159 pm_runtime_disable(&pdev->dev);
archit tanejaaffe3602011-02-23 08:41:03 +00004160 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004161}
4162
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004163static void dispc_unbind(struct device *dev, struct device *master,
4164 void *data)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004165{
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004166 dispc_set_ops(NULL);
4167
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004168 pm_runtime_disable(dev);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004169
4170 dispc_errata_i734_wa_fini();
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004171}
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03004172
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004173static const struct component_ops dispc_component_ops = {
4174 .bind = dispc_bind,
4175 .unbind = dispc_unbind,
4176};
4177
4178static int dispc_probe(struct platform_device *pdev)
4179{
4180 return component_add(&pdev->dev, &dispc_component_ops);
4181}
4182
4183static int dispc_remove(struct platform_device *pdev)
4184{
4185 component_del(&pdev->dev, &dispc_component_ops);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004186 return 0;
4187}
4188
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004189static int dispc_runtime_suspend(struct device *dev)
4190{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004191 dispc.is_enabled = false;
4192 /* ensure the dispc_irq_handler sees the is_enabled value */
4193 smp_wmb();
4194 /* wait for current handler to finish before turning the DISPC off */
4195 synchronize_irq(dispc.irq);
4196
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004197 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004198
4199 return 0;
4200}
4201
4202static int dispc_runtime_resume(struct device *dev)
4203{
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004204 /*
4205 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4206 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4207 * _omap_dispc_initial_config(). We can thus use it to detect if
4208 * we have lost register context.
4209 */
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004210 if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
4211 _omap_dispc_initial_config();
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004212
Jyri Sarhafbff0102016-06-07 15:09:16 +03004213 dispc_errata_i734_wa();
4214
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004215 dispc_restore_context();
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004216
4217 dispc_restore_gamma_tables();
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004218 }
Tomi Valkeinenbe07dcd72013-11-21 16:01:40 +02004219
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004220 dispc.is_enabled = true;
4221 /* ensure the dispc_irq_handler sees the is_enabled value */
4222 smp_wmb();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004223
4224 return 0;
4225}
4226
4227static const struct dev_pm_ops dispc_pm_ops = {
4228 .runtime_suspend = dispc_runtime_suspend,
4229 .runtime_resume = dispc_runtime_resume,
4230};
4231
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004232static const struct of_device_id dispc_of_match[] = {
4233 { .compatible = "ti,omap2-dispc", },
4234 { .compatible = "ti,omap3-dispc", },
4235 { .compatible = "ti,omap4-dispc", },
Tomi Valkeinen2e7e6b62014-04-16 13:16:43 +03004236 { .compatible = "ti,omap5-dispc", },
Tomi Valkeinen93550922014-12-31 11:25:48 +02004237 { .compatible = "ti,dra7-dispc", },
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004238 {},
4239};
4240
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004241static struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004242 .probe = dispc_probe,
4243 .remove = dispc_remove,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004244 .driver = {
4245 .name = "omapdss_dispc",
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004246 .pm = &dispc_pm_ops,
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004247 .of_match_table = dispc_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +03004248 .suppress_bind_attrs = true,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004249 },
4250};
4251
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004252int __init dispc_init_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004253{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004254 return platform_driver_register(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004255}
4256
Tomi Valkeinenede92692015-06-04 14:12:16 +03004257void dispc_uninit_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004258{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02004259 platform_driver_unregister(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004260}