blob: ac8ca605e3147d56d392d93ca6d76b36543ce2a6 [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) {
949 case OMAP_DSS_COLOR_CLUT1:
950 m = 0x0; break;
951 case OMAP_DSS_COLOR_CLUT2:
952 m = 0x1; break;
953 case OMAP_DSS_COLOR_CLUT4:
954 m = 0x2; break;
955 case OMAP_DSS_COLOR_CLUT8:
956 m = 0x3; break;
957 case OMAP_DSS_COLOR_RGB12U:
958 m = 0x4; break;
959 case OMAP_DSS_COLOR_ARGB16:
960 m = 0x5; break;
961 case OMAP_DSS_COLOR_RGB16:
962 m = 0x6; break;
963 case OMAP_DSS_COLOR_ARGB16_1555:
964 m = 0x7; break;
965 case OMAP_DSS_COLOR_RGB24U:
966 m = 0x8; break;
967 case OMAP_DSS_COLOR_RGB24P:
968 m = 0x9; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530969 case OMAP_DSS_COLOR_RGBX16:
Amber Jainf20e4222011-05-19 19:47:50 +0530970 m = 0xa; break;
Lajos Molnar08f32672012-02-21 19:36:30 +0530971 case OMAP_DSS_COLOR_RGBA16:
Amber Jainf20e4222011-05-19 19:47:50 +0530972 m = 0xb; break;
973 case OMAP_DSS_COLOR_ARGB32:
974 m = 0xc; break;
975 case OMAP_DSS_COLOR_RGBA32:
976 m = 0xd; break;
977 case OMAP_DSS_COLOR_RGBX32:
978 m = 0xe; break;
979 case OMAP_DSS_COLOR_XRGB16_1555:
980 m = 0xf; break;
981 default:
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300982 BUG(); return;
Amber Jainf20e4222011-05-19 19:47:50 +0530983 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200984 }
985
Archit Taneja9b372c22011-05-06 11:45:49 +0530986 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +0200987}
988
Jyri Sarha864050c2017-03-24 16:47:52 +0200989static void dispc_ovl_configure_burst_type(enum omap_plane_id plane,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530990 enum omap_dss_rotation_type rotation_type)
991{
992 if (dss_has_feature(FEAT_BURST_2D) == 0)
993 return;
994
995 if (rotation_type == OMAP_DSS_ROT_TILER)
996 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
997 else
998 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
999}
1000
Jyri Sarha864050c2017-03-24 16:47:52 +02001001static void dispc_ovl_set_channel_out(enum omap_plane_id plane,
1002 enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001003{
1004 int shift;
1005 u32 val;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001006 int chan = 0, chan2 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001007
1008 switch (plane) {
1009 case OMAP_DSS_GFX:
1010 shift = 8;
1011 break;
1012 case OMAP_DSS_VIDEO1:
1013 case OMAP_DSS_VIDEO2:
Archit Tanejab8c095b2011-09-13 18:20:33 +05301014 case OMAP_DSS_VIDEO3:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001015 shift = 16;
1016 break;
1017 default:
1018 BUG();
1019 return;
1020 }
1021
Archit Taneja9b372c22011-05-06 11:45:49 +05301022 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Sumit Semwal2a205f32010-12-02 11:27:12 +00001023 if (dss_has_feature(FEAT_MGR_LCD2)) {
1024 switch (channel) {
1025 case OMAP_DSS_CHANNEL_LCD:
1026 chan = 0;
1027 chan2 = 0;
1028 break;
1029 case OMAP_DSS_CHANNEL_DIGIT:
1030 chan = 1;
1031 chan2 = 0;
1032 break;
1033 case OMAP_DSS_CHANNEL_LCD2:
1034 chan = 0;
1035 chan2 = 1;
1036 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +05301037 case OMAP_DSS_CHANNEL_LCD3:
1038 if (dss_has_feature(FEAT_MGR_LCD3)) {
1039 chan = 0;
1040 chan2 = 2;
1041 } else {
1042 BUG();
1043 return;
1044 }
1045 break;
Tomi Valkeinenc2665c42015-11-04 17:10:47 +02001046 case OMAP_DSS_CHANNEL_WB:
1047 chan = 0;
1048 chan2 = 3;
1049 break;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001050 default:
1051 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001052 return;
Sumit Semwal2a205f32010-12-02 11:27:12 +00001053 }
1054
1055 val = FLD_MOD(val, chan, shift, shift);
1056 val = FLD_MOD(val, chan2, 31, 30);
1057 } else {
1058 val = FLD_MOD(val, channel, shift, shift);
1059 }
Archit Taneja9b372c22011-05-06 11:45:49 +05301060 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001061}
1062
Jyri Sarha864050c2017-03-24 16:47:52 +02001063static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane_id plane)
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001064{
1065 int shift;
1066 u32 val;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001067
1068 switch (plane) {
1069 case OMAP_DSS_GFX:
1070 shift = 8;
1071 break;
1072 case OMAP_DSS_VIDEO1:
1073 case OMAP_DSS_VIDEO2:
1074 case OMAP_DSS_VIDEO3:
1075 shift = 16;
1076 break;
1077 default:
1078 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001079 return 0;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001080 }
1081
1082 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1083
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001084 if (FLD_GET(val, shift, shift) == 1)
1085 return OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001086
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001087 if (!dss_has_feature(FEAT_MGR_LCD2))
1088 return OMAP_DSS_CHANNEL_LCD;
1089
1090 switch (FLD_GET(val, 31, 30)) {
1091 case 0:
1092 default:
1093 return OMAP_DSS_CHANNEL_LCD;
1094 case 1:
1095 return OMAP_DSS_CHANNEL_LCD2;
1096 case 2:
1097 return OMAP_DSS_CHANNEL_LCD3;
Tomi Valkeinenc2665c42015-11-04 17:10:47 +02001098 case 3:
1099 return OMAP_DSS_CHANNEL_WB;
Tomi Valkeinend7df5ad2015-11-04 17:10:46 +02001100 }
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02001101}
1102
Archit Tanejad9ac7732012-09-22 12:38:19 +05301103void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1104{
Jyri Sarha864050c2017-03-24 16:47:52 +02001105 enum omap_plane_id plane = OMAP_DSS_WB;
Archit Tanejad9ac7732012-09-22 12:38:19 +05301106
1107 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1108}
1109
Jyri Sarha864050c2017-03-24 16:47:52 +02001110static void dispc_ovl_set_burst_size(enum omap_plane_id plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001111 enum omap_burst_size burst_size)
1112{
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301113 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001114 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001115
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001116 shift = shifts[plane];
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001117 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001118}
1119
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001120static void dispc_configure_burst_sizes(void)
1121{
1122 int i;
1123 const int burst_size = BURST_SIZE_X8;
1124
1125 /* Configure burst size always to maximum size */
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001126 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001127 dispc_ovl_set_burst_size(i, burst_size);
Tomi Valkeinen5b354af2015-11-04 17:10:48 +02001128 if (dispc.feat->has_writeback)
1129 dispc_ovl_set_burst_size(OMAP_DSS_WB, burst_size);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001130}
1131
Jyri Sarha864050c2017-03-24 16:47:52 +02001132static u32 dispc_ovl_get_burst_size(enum omap_plane_id plane)
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001133{
1134 unsigned unit = dss_feat_get_burst_size_unit();
1135 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1136 return unit * 8;
1137}
1138
Jyri Sarha864050c2017-03-24 16:47:52 +02001139static enum omap_color_mode dispc_ovl_get_color_modes(enum omap_plane_id plane)
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001140{
1141 return dss_feat_get_supported_color_modes(plane);
1142}
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001143
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02001144static int dispc_get_num_ovls(void)
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001145{
1146 return dss_feat_get_num_ovls();
1147}
Tomi Valkeinenc2834002015-11-05 19:54:33 +02001148
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001149static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001150{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301151 if (channel == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001152 return;
1153
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05301154 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001155}
1156
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02001157static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02001158 const struct omap_dss_cpr_coefs *coefs)
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001159{
1160 u32 coef_r, coef_g, coef_b;
1161
Archit Tanejadd88b7a2012-06-29 14:41:30 +05301162 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinen3c07cae2011-06-21 09:34:30 +03001163 return;
1164
1165 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1166 FLD_VAL(coefs->rb, 9, 0);
1167 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1168 FLD_VAL(coefs->gb, 9, 0);
1169 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1170 FLD_VAL(coefs->bb, 9, 0);
1171
1172 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1173 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1174 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1175}
1176
Jyri Sarha864050c2017-03-24 16:47:52 +02001177static void dispc_ovl_set_vid_color_conv(enum omap_plane_id plane,
1178 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001179{
1180 u32 val;
1181
1182 BUG_ON(plane == OMAP_DSS_GFX);
1183
Archit Taneja9b372c22011-05-06 11:45:49 +05301184 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001185 val = FLD_MOD(val, enable, 9, 9);
Archit Taneja9b372c22011-05-06 11:45:49 +05301186 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001187}
1188
Jyri Sarha864050c2017-03-24 16:47:52 +02001189static void dispc_ovl_enable_replication(enum omap_plane_id plane,
Archit Tanejad79db852012-09-22 12:30:17 +05301190 enum omap_overlay_caps caps, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001191{
Archit Tanejab8c095b2011-09-13 18:20:33 +05301192 static const unsigned shifts[] = { 5, 10, 10, 10 };
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001193 int shift;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001194
Archit Tanejad79db852012-09-22 12:30:17 +05301195 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1196 return;
1197
Tomi Valkeinenfe3cc9d2011-08-15 11:51:50 +03001198 shift = shifts[plane];
1199 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001200}
1201
Archit Taneja8f366162012-04-16 12:53:44 +05301202static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
Archit Tanejae5c09e02012-04-16 12:53:42 +05301203 u16 height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001204{
1205 u32 val;
Archit Taneja8f366162012-04-16 12:53:44 +05301206
Archit Taneja33b89922012-11-14 13:50:15 +05301207 val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1208 FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1209
Archit Taneja702d1442011-05-06 11:45:50 +05301210 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001211}
1212
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001213static void dispc_init_fifos(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001214{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001215 u32 size;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001216 int fifo;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301217 u8 start, end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001218 u32 unit;
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001219 int i;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001220
1221 unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001222
Archit Tanejaa0acb552010-09-15 19:20:00 +05301223 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001224
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001225 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1226 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001227 size *= unit;
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001228 dispc.fifo_size[fifo] = size;
1229
1230 /*
1231 * By default fifos are mapped directly to overlays, fifo 0 to
1232 * ovl 0, fifo 1 to ovl 1, etc.
1233 */
1234 dispc.fifo_assignment[fifo] = fifo;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001235 }
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03001236
1237 /*
1238 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1239 * causes problems with certain use cases, like using the tiler in 2D
1240 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1241 * giving GFX plane a larger fifo. WB but should work fine with a
1242 * smaller fifo.
1243 */
1244 if (dispc.feat->gfx_fifo_workaround) {
1245 u32 v;
1246
1247 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1248
1249 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1250 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1251 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1252 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1253
1254 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1255
1256 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1257 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1258 }
Tomi Valkeinen47fc4692014-09-29 20:46:17 +00001259
1260 /*
1261 * Setup default fifo thresholds.
1262 */
1263 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1264 u32 low, high;
1265 const bool use_fifomerge = false;
1266 const bool manual_update = false;
1267
1268 dispc_ovl_compute_fifo_thresholds(i, &low, &high,
1269 use_fifomerge, manual_update);
1270
1271 dispc_ovl_set_fifo_threshold(i, low, high);
1272 }
Tomi Valkeinen65e116e2015-11-04 17:10:49 +02001273
1274 if (dispc.feat->has_writeback) {
1275 u32 low, high;
1276 const bool use_fifomerge = false;
1277 const bool manual_update = false;
1278
1279 dispc_ovl_compute_fifo_thresholds(OMAP_DSS_WB, &low, &high,
1280 use_fifomerge, manual_update);
1281
1282 dispc_ovl_set_fifo_threshold(OMAP_DSS_WB, low, high);
1283 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001284}
1285
Jyri Sarha864050c2017-03-24 16:47:52 +02001286static u32 dispc_ovl_get_fifo_size(enum omap_plane_id plane)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001287{
Tomi Valkeinen42a69612012-08-22 16:56:57 +03001288 int fifo;
1289 u32 size = 0;
1290
1291 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1292 if (dispc.fifo_assignment[fifo] == plane)
1293 size += dispc.fifo_size[fifo];
1294 }
1295
1296 return size;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001297}
1298
Jyri Sarha864050c2017-03-24 16:47:52 +02001299void dispc_ovl_set_fifo_threshold(enum omap_plane_id plane, u32 low,
1300 u32 high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001301{
Archit Tanejaa0acb552010-09-15 19:20:00 +05301302 u8 hi_start, hi_end, lo_start, lo_end;
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03001303 u32 unit;
1304
1305 unit = dss_feat_get_buffer_size_unit();
1306
1307 WARN_ON(low % unit != 0);
1308 WARN_ON(high % unit != 0);
1309
1310 low /= unit;
1311 high /= unit;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301312
Archit Taneja9b372c22011-05-06 11:45:49 +05301313 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1314 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1315
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001316 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001317 plane,
Archit Taneja9b372c22011-05-06 11:45:49 +05301318 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001319 lo_start, lo_end) * unit,
Archit Taneja9b372c22011-05-06 11:45:49 +05301320 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
Tomi Valkeinen3cb5d962012-01-13 13:14:57 +02001321 hi_start, hi_end) * unit,
1322 low * unit, high * unit);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001323
Archit Taneja9b372c22011-05-06 11:45:49 +05301324 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
Archit Tanejaa0acb552010-09-15 19:20:00 +05301325 FLD_VAL(high, hi_start, hi_end) |
1326 FLD_VAL(low, lo_start, lo_end));
Archit Taneja8bc65552013-12-17 16:40:21 +05301327
1328 /*
1329 * configure the preload to the pipeline's high threhold, if HT it's too
1330 * large for the preload field, set the threshold to the maximum value
1331 * that can be held by the preload register
1332 */
1333 if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload &&
1334 plane != OMAP_DSS_WB)
1335 dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001336}
1337
1338void dispc_enable_fifomerge(bool enable)
1339{
Tomi Valkeinene6b0f882012-01-13 13:24:04 +02001340 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1341 WARN_ON(enable);
1342 return;
1343 }
1344
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001345 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1346 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001347}
1348
Jyri Sarha864050c2017-03-24 16:47:52 +02001349void dispc_ovl_compute_fifo_thresholds(enum omap_plane_id plane,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001350 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1351 bool manual_update)
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001352{
1353 /*
1354 * All sizes are in bytes. Both the buffer and burst are made of
1355 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1356 */
1357
1358 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001359 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1360 int i;
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001361
1362 burst_size = dispc_ovl_get_burst_size(plane);
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001363 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001364
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001365 if (use_fifomerge) {
1366 total_fifo_size = 0;
Tomi Valkeinen392faa02012-10-15 15:37:22 +03001367 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001368 total_fifo_size += dispc_ovl_get_fifo_size(i);
1369 } else {
1370 total_fifo_size = ovl_fifo_size;
1371 }
1372
1373 /*
1374 * We use the same low threshold for both fifomerge and non-fifomerge
1375 * cases, but for fifomerge we calculate the high threshold using the
1376 * combined fifo size
1377 */
1378
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001379 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001380 *fifo_low = ovl_fifo_size - burst_size * 2;
1381 *fifo_high = total_fifo_size - burst_size;
Archit Taneja8bbe09e2012-09-10 17:31:39 +05301382 } else if (plane == OMAP_DSS_WB) {
1383 /*
1384 * Most optimal configuration for writeback is to push out data
1385 * to the interconnect the moment writeback pushes enough pixels
1386 * in the FIFO to form a burst
1387 */
1388 *fifo_low = 0;
1389 *fifo_high = burst_size;
Tomi Valkeinene0e405b2012-01-13 13:18:11 +02001390 } else {
1391 *fifo_low = ovl_fifo_size - burst_size;
1392 *fifo_high = total_fifo_size - buf_unit;
1393 }
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001394}
1395
Jyri Sarha864050c2017-03-24 16:47:52 +02001396static void dispc_ovl_set_mflag(enum omap_plane_id plane, bool enable)
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001397{
1398 int bit;
1399
1400 if (plane == OMAP_DSS_GFX)
1401 bit = 14;
1402 else
1403 bit = 23;
1404
1405 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1406}
1407
Jyri Sarha864050c2017-03-24 16:47:52 +02001408static void dispc_ovl_set_mflag_threshold(enum omap_plane_id plane,
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001409 int low, int high)
1410{
1411 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane),
1412 FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1413}
1414
1415static void dispc_init_mflag(void)
1416{
1417 int i;
1418
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001419 /*
1420 * HACK: NV12 color format and MFLAG seem to have problems working
1421 * together: using two displays, and having an NV12 overlay on one of
1422 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1423 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1424 * remove the errors, but there doesn't seem to be a clear logic on
1425 * which values work and which not.
1426 *
1427 * As a work-around, set force MFLAG to always on.
1428 */
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001429 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE,
Tomi Valkeinenfe59e5c2014-11-19 12:50:16 +02001430 (1 << 0) | /* MFLAG_CTRL = force always on */
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001431 (0 << 2)); /* MFLAG_START = disable */
1432
1433 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1434 u32 size = dispc_ovl_get_fifo_size(i);
1435 u32 unit = dss_feat_get_buffer_size_unit();
1436 u32 low, high;
1437
1438 dispc_ovl_set_mflag(i, true);
1439
1440 /*
1441 * Simulation team suggests below thesholds:
1442 * HT = fifosize * 5 / 8;
1443 * LT = fifosize * 4 / 8;
1444 */
1445
1446 low = size * 4 / 8 / unit;
1447 high = size * 5 / 8 / unit;
1448
1449 dispc_ovl_set_mflag_threshold(i, low, high);
1450 }
Tomi Valkeinenecb0b362015-11-04 17:10:50 +02001451
1452 if (dispc.feat->has_writeback) {
1453 u32 size = dispc_ovl_get_fifo_size(OMAP_DSS_WB);
1454 u32 unit = dss_feat_get_buffer_size_unit();
1455 u32 low, high;
1456
1457 dispc_ovl_set_mflag(OMAP_DSS_WB, true);
1458
1459 /*
1460 * Simulation team suggests below thesholds:
1461 * HT = fifosize * 5 / 8;
1462 * LT = fifosize * 4 / 8;
1463 */
1464
1465 low = size * 4 / 8 / unit;
1466 high = size * 5 / 8 / unit;
1467
1468 dispc_ovl_set_mflag_threshold(OMAP_DSS_WB, low, high);
1469 }
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00001470}
1471
Jyri Sarha864050c2017-03-24 16:47:52 +02001472static void dispc_ovl_set_fir(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301473 int hinc, int vinc,
1474 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001475{
1476 u32 val;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001477
Amber Jain0d66cbb2011-05-19 19:47:54 +05301478 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1479 u8 hinc_start, hinc_end, vinc_start, vinc_end;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301480
Amber Jain0d66cbb2011-05-19 19:47:54 +05301481 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1482 &hinc_start, &hinc_end);
1483 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1484 &vinc_start, &vinc_end);
1485 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1486 FLD_VAL(hinc, hinc_start, hinc_end);
Archit Tanejaa0acb552010-09-15 19:20:00 +05301487
Amber Jain0d66cbb2011-05-19 19:47:54 +05301488 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1489 } else {
1490 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1491 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1492 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001493}
1494
Jyri Sarha864050c2017-03-24 16:47:52 +02001495static void dispc_ovl_set_vid_accu0(enum omap_plane_id plane, int haccu,
1496 int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001497{
1498 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301499 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001500
Archit Taneja87a74842011-03-02 11:19:50 +05301501 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1502 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1503
1504 val = FLD_VAL(vaccu, vert_start, vert_end) |
1505 FLD_VAL(haccu, hor_start, hor_end);
1506
Archit Taneja9b372c22011-05-06 11:45:49 +05301507 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001508}
1509
Jyri Sarha864050c2017-03-24 16:47:52 +02001510static void dispc_ovl_set_vid_accu1(enum omap_plane_id plane, int haccu,
1511 int vaccu)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001512{
1513 u32 val;
Archit Taneja87a74842011-03-02 11:19:50 +05301514 u8 hor_start, hor_end, vert_start, vert_end;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001515
Archit Taneja87a74842011-03-02 11:19:50 +05301516 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1517 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1518
1519 val = FLD_VAL(vaccu, vert_start, vert_end) |
1520 FLD_VAL(haccu, hor_start, hor_end);
1521
Archit Taneja9b372c22011-05-06 11:45:49 +05301522 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001523}
1524
Jyri Sarha864050c2017-03-24 16:47:52 +02001525static void dispc_ovl_set_vid_accu2_0(enum omap_plane_id plane, int haccu,
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001526 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301527{
1528 u32 val;
1529
1530 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1531 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1532}
1533
Jyri Sarha864050c2017-03-24 16:47:52 +02001534static void dispc_ovl_set_vid_accu2_1(enum omap_plane_id plane, int haccu,
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001535 int vaccu)
Amber Jainab5ca072011-05-19 19:47:53 +05301536{
1537 u32 val;
1538
1539 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1540 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1541}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001542
Jyri Sarha864050c2017-03-24 16:47:52 +02001543static void dispc_ovl_set_scale_param(enum omap_plane_id plane,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001544 u16 orig_width, u16 orig_height,
1545 u16 out_width, u16 out_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301546 bool five_taps, u8 rotation,
1547 enum omap_color_component color_comp)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001548{
Amber Jain0d66cbb2011-05-19 19:47:54 +05301549 int fir_hinc, fir_vinc;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001550
Amber Jained14a3c2011-05-19 19:47:51 +05301551 fir_hinc = 1024 * orig_width / out_width;
1552 fir_vinc = 1024 * orig_height / out_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001553
Chandrabhanu Mahapatradebd9072011-12-19 14:03:44 +05301554 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1555 color_comp);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001556 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301557}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001558
Jyri Sarha864050c2017-03-24 16:47:52 +02001559static void dispc_ovl_set_accu_uv(enum omap_plane_id plane,
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301560 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1561 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1562{
1563 int h_accu2_0, h_accu2_1;
1564 int v_accu2_0, v_accu2_1;
1565 int chroma_hinc, chroma_vinc;
1566 int idx;
1567
1568 struct accu {
1569 s8 h0_m, h0_n;
1570 s8 h1_m, h1_n;
1571 s8 v0_m, v0_n;
1572 s8 v1_m, v1_n;
1573 };
1574
1575 const struct accu *accu_table;
1576 const struct accu *accu_val;
1577
1578 static const struct accu accu_nv12[4] = {
1579 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1580 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1581 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1582 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1583 };
1584
1585 static const struct accu accu_nv12_ilace[4] = {
1586 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1587 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1588 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1589 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1590 };
1591
1592 static const struct accu accu_yuv[4] = {
1593 { 0, 1, 0, 1, 0, 1, 0, 1 },
1594 { 0, 1, 0, 1, 0, 1, 0, 1 },
1595 { -1, 1, 0, 1, 0, 1, 0, 1 },
1596 { 0, 1, 0, 1, -1, 1, 0, 1 },
1597 };
1598
1599 switch (rotation) {
1600 case OMAP_DSS_ROT_0:
1601 idx = 0;
1602 break;
1603 case OMAP_DSS_ROT_90:
1604 idx = 1;
1605 break;
1606 case OMAP_DSS_ROT_180:
1607 idx = 2;
1608 break;
1609 case OMAP_DSS_ROT_270:
1610 idx = 3;
1611 break;
1612 default:
1613 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001614 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301615 }
1616
1617 switch (color_mode) {
1618 case OMAP_DSS_COLOR_NV12:
1619 if (ilace)
1620 accu_table = accu_nv12_ilace;
1621 else
1622 accu_table = accu_nv12;
1623 break;
1624 case OMAP_DSS_COLOR_YUV2:
1625 case OMAP_DSS_COLOR_UYVY:
1626 accu_table = accu_yuv;
1627 break;
1628 default:
1629 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001630 return;
Chandrabhanu Mahapatra05dd0f52012-05-15 12:22:34 +05301631 }
1632
1633 accu_val = &accu_table[idx];
1634
1635 chroma_hinc = 1024 * orig_width / out_width;
1636 chroma_vinc = 1024 * orig_height / out_height;
1637
1638 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1639 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1640 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1641 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1642
1643 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1644 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1645}
1646
Jyri Sarha864050c2017-03-24 16:47:52 +02001647static void dispc_ovl_set_scaling_common(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301648 u16 orig_width, u16 orig_height,
1649 u16 out_width, u16 out_height,
1650 bool ilace, bool five_taps,
1651 bool fieldmode, enum omap_color_mode color_mode,
1652 u8 rotation)
1653{
1654 int accu0 = 0;
1655 int accu1 = 0;
1656 u32 l;
1657
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001658 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301659 out_width, out_height, five_taps,
1660 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
Archit Taneja9b372c22011-05-06 11:45:49 +05301661 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001662
Archit Taneja87a74842011-03-02 11:19:50 +05301663 /* RESIZEENABLE and VERTICALTAPS */
1664 l &= ~((0x3 << 5) | (0x1 << 21));
Amber Jained14a3c2011-05-19 19:47:51 +05301665 l |= (orig_width != out_width) ? (1 << 5) : 0;
1666 l |= (orig_height != out_height) ? (1 << 6) : 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001667 l |= five_taps ? (1 << 21) : 0;
Archit Taneja87a74842011-03-02 11:19:50 +05301668
1669 /* VRESIZECONF and HRESIZECONF */
1670 if (dss_has_feature(FEAT_RESIZECONF)) {
1671 l &= ~(0x3 << 7);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301672 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1673 l |= (orig_height <= out_height) ? 0 : (1 << 8);
Archit Taneja87a74842011-03-02 11:19:50 +05301674 }
1675
1676 /* LINEBUFFERSPLIT */
1677 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1678 l &= ~(0x1 << 22);
1679 l |= five_taps ? (1 << 22) : 0;
1680 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001681
Archit Taneja9b372c22011-05-06 11:45:49 +05301682 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001683
1684 /*
1685 * field 0 = even field = bottom field
1686 * field 1 = odd field = top field
1687 */
1688 if (ilace && !fieldmode) {
1689 accu1 = 0;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301690 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001691 if (accu0 >= 1024/2) {
1692 accu1 = 1024/2;
1693 accu0 -= accu1;
1694 }
1695 }
1696
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001697 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1698 dispc_ovl_set_vid_accu1(plane, 0, accu1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001699}
1700
Jyri Sarha864050c2017-03-24 16:47:52 +02001701static void dispc_ovl_set_scaling_uv(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301702 u16 orig_width, u16 orig_height,
1703 u16 out_width, u16 out_height,
1704 bool ilace, bool five_taps,
1705 bool fieldmode, enum omap_color_mode color_mode,
1706 u8 rotation)
1707{
1708 int scale_x = out_width != orig_width;
1709 int scale_y = out_height != orig_height;
Andrew F. Davis0cac5b62016-07-01 09:27:21 -05001710 bool chroma_upscale = plane != OMAP_DSS_WB;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301711
1712 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1713 return;
1714 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1715 color_mode != OMAP_DSS_COLOR_UYVY &&
1716 color_mode != OMAP_DSS_COLOR_NV12)) {
1717 /* reset chroma resampling for RGB formats */
Archit Taneja2a5561b2012-07-16 16:37:45 +05301718 if (plane != OMAP_DSS_WB)
1719 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301720 return;
1721 }
Tomi Valkeinen36377352012-05-15 15:54:15 +03001722
1723 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1724 out_height, ilace, color_mode, rotation);
1725
Amber Jain0d66cbb2011-05-19 19:47:54 +05301726 switch (color_mode) {
1727 case OMAP_DSS_COLOR_NV12:
Archit Taneja20fbb502012-08-22 17:04:48 +05301728 if (chroma_upscale) {
1729 /* UV is subsampled by 2 horizontally and vertically */
1730 orig_height >>= 1;
1731 orig_width >>= 1;
1732 } else {
1733 /* UV is downsampled by 2 horizontally and vertically */
1734 orig_height <<= 1;
1735 orig_width <<= 1;
1736 }
1737
Amber Jain0d66cbb2011-05-19 19:47:54 +05301738 break;
1739 case OMAP_DSS_COLOR_YUV2:
1740 case OMAP_DSS_COLOR_UYVY:
Archit Taneja20fbb502012-08-22 17:04:48 +05301741 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
Amber Jain0d66cbb2011-05-19 19:47:54 +05301742 if (rotation == OMAP_DSS_ROT_0 ||
Archit Taneja20fbb502012-08-22 17:04:48 +05301743 rotation == OMAP_DSS_ROT_180) {
1744 if (chroma_upscale)
1745 /* UV is subsampled by 2 horizontally */
1746 orig_width >>= 1;
1747 else
1748 /* UV is downsampled by 2 horizontally */
1749 orig_width <<= 1;
1750 }
1751
Amber Jain0d66cbb2011-05-19 19:47:54 +05301752 /* must use FIR for YUV422 if rotated */
1753 if (rotation != OMAP_DSS_ROT_0)
1754 scale_x = scale_y = true;
Archit Taneja20fbb502012-08-22 17:04:48 +05301755
Amber Jain0d66cbb2011-05-19 19:47:54 +05301756 break;
1757 default:
1758 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001759 return;
Amber Jain0d66cbb2011-05-19 19:47:54 +05301760 }
1761
1762 if (out_width != orig_width)
1763 scale_x = true;
1764 if (out_height != orig_height)
1765 scale_y = true;
1766
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001767 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301768 out_width, out_height, five_taps,
1769 rotation, DISPC_COLOR_COMPONENT_UV);
1770
Archit Taneja2a5561b2012-07-16 16:37:45 +05301771 if (plane != OMAP_DSS_WB)
1772 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1773 (scale_x || scale_y) ? 1 : 0, 8, 8);
1774
Amber Jain0d66cbb2011-05-19 19:47:54 +05301775 /* set H scaling */
1776 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1777 /* set V scaling */
1778 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
Amber Jain0d66cbb2011-05-19 19:47:54 +05301779}
1780
Jyri Sarha864050c2017-03-24 16:47:52 +02001781static void dispc_ovl_set_scaling(enum omap_plane_id plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301782 u16 orig_width, u16 orig_height,
1783 u16 out_width, u16 out_height,
1784 bool ilace, bool five_taps,
1785 bool fieldmode, enum omap_color_mode color_mode,
1786 u8 rotation)
1787{
1788 BUG_ON(plane == OMAP_DSS_GFX);
1789
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001790 dispc_ovl_set_scaling_common(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301791 orig_width, orig_height,
1792 out_width, out_height,
1793 ilace, five_taps,
1794 fieldmode, color_mode,
1795 rotation);
1796
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03001797 dispc_ovl_set_scaling_uv(plane,
Amber Jain0d66cbb2011-05-19 19:47:54 +05301798 orig_width, orig_height,
1799 out_width, out_height,
1800 ilace, five_taps,
1801 fieldmode, color_mode,
1802 rotation);
1803}
1804
Jyri Sarha273ffea2017-03-24 16:47:53 +02001805static void dispc_ovl_set_rotation_attrs(enum omap_plane_id plane, u8 rotation,
Archit Tanejac35eeb22013-03-26 19:15:24 +05301806 enum omap_dss_rotation_type rotation_type,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001807 bool mirroring, enum omap_color_mode color_mode)
1808{
Archit Taneja87a74842011-03-02 11:19:50 +05301809 bool row_repeat = false;
1810 int vidrot = 0;
1811
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001812 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1813 color_mode == OMAP_DSS_COLOR_UYVY) {
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001814
1815 if (mirroring) {
1816 switch (rotation) {
1817 case OMAP_DSS_ROT_0:
1818 vidrot = 2;
1819 break;
1820 case OMAP_DSS_ROT_90:
1821 vidrot = 1;
1822 break;
1823 case OMAP_DSS_ROT_180:
1824 vidrot = 0;
1825 break;
1826 case OMAP_DSS_ROT_270:
1827 vidrot = 3;
1828 break;
1829 }
1830 } else {
1831 switch (rotation) {
1832 case OMAP_DSS_ROT_0:
1833 vidrot = 0;
1834 break;
1835 case OMAP_DSS_ROT_90:
1836 vidrot = 1;
1837 break;
1838 case OMAP_DSS_ROT_180:
1839 vidrot = 2;
1840 break;
1841 case OMAP_DSS_ROT_270:
1842 vidrot = 3;
1843 break;
1844 }
1845 }
1846
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001847 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
Archit Taneja87a74842011-03-02 11:19:50 +05301848 row_repeat = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001849 else
Archit Taneja87a74842011-03-02 11:19:50 +05301850 row_repeat = false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001851 }
Archit Taneja87a74842011-03-02 11:19:50 +05301852
Tomi Valkeinen3397cc62015-04-09 13:51:30 +03001853 /*
1854 * OMAP4/5 Errata i631:
1855 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
1856 * rows beyond the framebuffer, which may cause OCP error.
1857 */
1858 if (color_mode == OMAP_DSS_COLOR_NV12 &&
1859 rotation_type != OMAP_DSS_ROT_TILER)
1860 vidrot = 1;
1861
Archit Taneja9b372c22011-05-06 11:45:49 +05301862 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
Archit Taneja87a74842011-03-02 11:19:50 +05301863 if (dss_has_feature(FEAT_ROWREPEATENABLE))
Archit Taneja9b372c22011-05-06 11:45:49 +05301864 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1865 row_repeat ? 1 : 0, 18, 18);
Archit Tanejac35eeb22013-03-26 19:15:24 +05301866
1867 if (color_mode == OMAP_DSS_COLOR_NV12) {
1868 bool doublestride = (rotation_type == OMAP_DSS_ROT_TILER) &&
1869 (rotation == OMAP_DSS_ROT_0 ||
1870 rotation == OMAP_DSS_ROT_180);
1871 /* DOUBLESTRIDE */
1872 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22);
1873 }
1874
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001875}
1876
1877static int color_mode_to_bpp(enum omap_color_mode color_mode)
1878{
1879 switch (color_mode) {
1880 case OMAP_DSS_COLOR_CLUT1:
1881 return 1;
1882 case OMAP_DSS_COLOR_CLUT2:
1883 return 2;
1884 case OMAP_DSS_COLOR_CLUT4:
1885 return 4;
1886 case OMAP_DSS_COLOR_CLUT8:
Amber Jainf20e4222011-05-19 19:47:50 +05301887 case OMAP_DSS_COLOR_NV12:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001888 return 8;
1889 case OMAP_DSS_COLOR_RGB12U:
1890 case OMAP_DSS_COLOR_RGB16:
1891 case OMAP_DSS_COLOR_ARGB16:
1892 case OMAP_DSS_COLOR_YUV2:
1893 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +05301894 case OMAP_DSS_COLOR_RGBA16:
1895 case OMAP_DSS_COLOR_RGBX16:
1896 case OMAP_DSS_COLOR_ARGB16_1555:
1897 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001898 return 16;
1899 case OMAP_DSS_COLOR_RGB24P:
1900 return 24;
1901 case OMAP_DSS_COLOR_RGB24U:
1902 case OMAP_DSS_COLOR_ARGB32:
1903 case OMAP_DSS_COLOR_RGBA32:
1904 case OMAP_DSS_COLOR_RGBX32:
1905 return 32;
1906 default:
1907 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001908 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001909 }
1910}
1911
1912static s32 pixinc(int pixels, u8 ps)
1913{
1914 if (pixels == 1)
1915 return 1;
1916 else if (pixels > 1)
1917 return 1 + (pixels - 1) * ps;
1918 else if (pixels < 0)
1919 return 1 - (-pixels + 1) * ps;
1920 else
1921 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03001922 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001923}
1924
1925static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1926 u16 screen_width,
1927 u16 width, u16 height,
1928 enum omap_color_mode color_mode, bool fieldmode,
1929 unsigned int field_offset,
1930 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301931 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001932{
1933 u8 ps;
1934
1935 /* FIXME CLUT formats */
1936 switch (color_mode) {
1937 case OMAP_DSS_COLOR_CLUT1:
1938 case OMAP_DSS_COLOR_CLUT2:
1939 case OMAP_DSS_COLOR_CLUT4:
1940 case OMAP_DSS_COLOR_CLUT8:
1941 BUG();
1942 return;
1943 case OMAP_DSS_COLOR_YUV2:
1944 case OMAP_DSS_COLOR_UYVY:
1945 ps = 4;
1946 break;
1947 default:
1948 ps = color_mode_to_bpp(color_mode) / 8;
1949 break;
1950 }
1951
1952 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1953 width, height);
1954
1955 /*
1956 * field 0 = even field = bottom field
1957 * field 1 = odd field = top field
1958 */
1959 switch (rotation + mirror * 4) {
1960 case OMAP_DSS_ROT_0:
1961 case OMAP_DSS_ROT_180:
1962 /*
1963 * If the pixel format is YUV or UYVY divide the width
1964 * of the image by 2 for 0 and 180 degree rotation.
1965 */
1966 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1967 color_mode == OMAP_DSS_COLOR_UYVY)
1968 width = width >> 1;
1969 case OMAP_DSS_ROT_90:
1970 case OMAP_DSS_ROT_270:
1971 *offset1 = 0;
1972 if (field_offset)
1973 *offset0 = field_offset * screen_width * ps;
1974 else
1975 *offset0 = 0;
1976
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301977 *row_inc = pixinc(1 +
1978 (y_predecim * screen_width - x_predecim * width) +
1979 (fieldmode ? screen_width : 0), ps);
1980 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02001981 break;
1982
1983 case OMAP_DSS_ROT_0 + 4:
1984 case OMAP_DSS_ROT_180 + 4:
1985 /* If the pixel format is YUV or UYVY divide the width
1986 * of the image by 2 for 0 degree and 180 degree
1987 */
1988 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1989 color_mode == OMAP_DSS_COLOR_UYVY)
1990 width = width >> 1;
1991 case OMAP_DSS_ROT_90 + 4:
1992 case OMAP_DSS_ROT_270 + 4:
1993 *offset1 = 0;
1994 if (field_offset)
1995 *offset0 = field_offset * screen_width * ps;
1996 else
1997 *offset0 = 0;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05301998 *row_inc = pixinc(1 -
1999 (y_predecim * screen_width + x_predecim * width) -
2000 (fieldmode ? screen_width : 0), ps);
2001 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002002 break;
2003
2004 default:
2005 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002006 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002007 }
2008}
2009
2010static void calc_dma_rotation_offset(u8 rotation, bool mirror,
2011 u16 screen_width,
2012 u16 width, u16 height,
2013 enum omap_color_mode color_mode, bool fieldmode,
2014 unsigned int field_offset,
2015 unsigned *offset0, unsigned *offset1,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302016 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002017{
2018 u8 ps;
2019 u16 fbw, fbh;
2020
2021 /* FIXME CLUT formats */
2022 switch (color_mode) {
2023 case OMAP_DSS_COLOR_CLUT1:
2024 case OMAP_DSS_COLOR_CLUT2:
2025 case OMAP_DSS_COLOR_CLUT4:
2026 case OMAP_DSS_COLOR_CLUT8:
2027 BUG();
2028 return;
2029 default:
2030 ps = color_mode_to_bpp(color_mode) / 8;
2031 break;
2032 }
2033
2034 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
2035 width, height);
2036
2037 /* width & height are overlay sizes, convert to fb sizes */
2038
2039 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
2040 fbw = width;
2041 fbh = height;
2042 } else {
2043 fbw = height;
2044 fbh = width;
2045 }
2046
2047 /*
2048 * field 0 = even field = bottom field
2049 * field 1 = odd field = top field
2050 */
2051 switch (rotation + mirror * 4) {
2052 case OMAP_DSS_ROT_0:
2053 *offset1 = 0;
2054 if (field_offset)
2055 *offset0 = *offset1 + field_offset * screen_width * ps;
2056 else
2057 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302058 *row_inc = pixinc(1 +
2059 (y_predecim * screen_width - fbw * x_predecim) +
2060 (fieldmode ? screen_width : 0), ps);
2061 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2062 color_mode == OMAP_DSS_COLOR_UYVY)
2063 *pix_inc = pixinc(x_predecim, 2 * ps);
2064 else
2065 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002066 break;
2067 case OMAP_DSS_ROT_90:
2068 *offset1 = screen_width * (fbh - 1) * ps;
2069 if (field_offset)
2070 *offset0 = *offset1 + field_offset * ps;
2071 else
2072 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302073 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
2074 y_predecim + (fieldmode ? 1 : 0), ps);
2075 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002076 break;
2077 case OMAP_DSS_ROT_180:
2078 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
2079 if (field_offset)
2080 *offset0 = *offset1 - field_offset * screen_width * ps;
2081 else
2082 *offset0 = *offset1;
2083 *row_inc = pixinc(-1 -
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302084 (y_predecim * screen_width - fbw * x_predecim) -
2085 (fieldmode ? screen_width : 0), ps);
2086 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2087 color_mode == OMAP_DSS_COLOR_UYVY)
2088 *pix_inc = pixinc(-x_predecim, 2 * ps);
2089 else
2090 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002091 break;
2092 case OMAP_DSS_ROT_270:
2093 *offset1 = (fbw - 1) * ps;
2094 if (field_offset)
2095 *offset0 = *offset1 - field_offset * ps;
2096 else
2097 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302098 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
2099 y_predecim - (fieldmode ? 1 : 0), ps);
2100 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002101 break;
2102
2103 /* mirroring */
2104 case OMAP_DSS_ROT_0 + 4:
2105 *offset1 = (fbw - 1) * ps;
2106 if (field_offset)
2107 *offset0 = *offset1 + field_offset * screen_width * ps;
2108 else
2109 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302110 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002111 (fieldmode ? screen_width : 0),
2112 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302113 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2114 color_mode == OMAP_DSS_COLOR_UYVY)
2115 *pix_inc = pixinc(-x_predecim, 2 * ps);
2116 else
2117 *pix_inc = pixinc(-x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002118 break;
2119
2120 case OMAP_DSS_ROT_90 + 4:
2121 *offset1 = 0;
2122 if (field_offset)
2123 *offset0 = *offset1 + field_offset * ps;
2124 else
2125 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302126 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
2127 y_predecim + (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002128 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302129 *pix_inc = pixinc(x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002130 break;
2131
2132 case OMAP_DSS_ROT_180 + 4:
2133 *offset1 = screen_width * (fbh - 1) * ps;
2134 if (field_offset)
2135 *offset0 = *offset1 - field_offset * screen_width * ps;
2136 else
2137 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302138 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002139 (fieldmode ? screen_width : 0),
2140 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302141 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2142 color_mode == OMAP_DSS_COLOR_UYVY)
2143 *pix_inc = pixinc(x_predecim, 2 * ps);
2144 else
2145 *pix_inc = pixinc(x_predecim, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002146 break;
2147
2148 case OMAP_DSS_ROT_270 + 4:
2149 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
2150 if (field_offset)
2151 *offset0 = *offset1 - field_offset * ps;
2152 else
2153 *offset0 = *offset1;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302154 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
2155 y_predecim - (fieldmode ? 1 : 0),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002156 ps);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302157 *pix_inc = pixinc(-x_predecim * screen_width, ps);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002158 break;
2159
2160 default:
2161 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002162 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002163 }
2164}
2165
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302166static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
2167 enum omap_color_mode color_mode, bool fieldmode,
2168 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
2169 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
2170{
2171 u8 ps;
2172
2173 switch (color_mode) {
2174 case OMAP_DSS_COLOR_CLUT1:
2175 case OMAP_DSS_COLOR_CLUT2:
2176 case OMAP_DSS_COLOR_CLUT4:
2177 case OMAP_DSS_COLOR_CLUT8:
2178 BUG();
2179 return;
2180 default:
2181 ps = color_mode_to_bpp(color_mode) / 8;
2182 break;
2183 }
2184
2185 DSSDBG("scrw %d, width %d\n", screen_width, width);
2186
2187 /*
2188 * field 0 = even field = bottom field
2189 * field 1 = odd field = top field
2190 */
2191 *offset1 = 0;
2192 if (field_offset)
2193 *offset0 = *offset1 + field_offset * screen_width * ps;
2194 else
2195 *offset0 = *offset1;
2196 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
2197 (fieldmode ? screen_width : 0), ps);
2198 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2199 color_mode == OMAP_DSS_COLOR_UYVY)
2200 *pix_inc = pixinc(x_predecim, 2 * ps);
2201 else
2202 *pix_inc = pixinc(x_predecim, ps);
2203}
2204
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302205/*
2206 * This function is used to avoid synclosts in OMAP3, because of some
2207 * undocumented horizontal position and timing related limitations.
2208 */
Tomi Valkeinen465ec132012-10-19 15:40:24 +03002209static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002210 const struct videomode *vm, u16 pos_x,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002211 u16 width, u16 height, u16 out_width, u16 out_height,
2212 bool five_taps)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302213{
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002214 const int ds = DIV_ROUND_UP(height, out_height);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302215 unsigned long nonactive;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302216 static const u8 limits[3] = { 8, 10, 20 };
2217 u64 val, blank;
2218 int i;
2219
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002220 nonactive = vm->hactive + vm->hfront_porch + vm->hsync_len +
2221 vm->hback_porch - out_width;
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302222
2223 i = 0;
2224 if (out_height < height)
2225 i++;
2226 if (out_width < width)
2227 i++;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002228 blank = div_u64((u64)(vm->hback_porch + vm->hsync_len + vm->hfront_porch) *
Peter Ujfalusi0a30e152016-09-22 14:06:49 +03002229 lclk, pclk);
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302230 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2231 if (blank <= limits[i])
2232 return -EINVAL;
2233
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002234 /* FIXME add checks for 3-tap filter once the limitations are known */
2235 if (!five_taps)
2236 return 0;
2237
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302238 /*
2239 * Pixel data should be prepared before visible display point starts.
2240 * So, atleast DS-2 lines must have already been fetched by DISPC
2241 * during nonactive - pos_x period.
2242 */
2243 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2244 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002245 val, max(0, ds - 2) * width);
2246 if (val < max(0, ds - 2) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302247 return -EINVAL;
2248
2249 /*
2250 * All lines need to be refilled during the nonactive period of which
2251 * only one line can be loaded during the active period. So, atleast
2252 * DS - 1 lines should be loaded during nonactive period.
2253 */
2254 val = div_u64((u64)nonactive * lclk, pclk);
2255 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
Tomi Valkeinen230edc02012-11-05 14:40:19 +02002256 val, max(0, ds - 1) * width);
2257 if (val < max(0, ds - 1) * width)
Chandrabhanu Mahapatra7faa9232012-04-02 20:43:17 +05302258 return -EINVAL;
2259
2260 return 0;
2261}
2262
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002263static unsigned long calc_core_clk_five_taps(unsigned long pclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002264 const struct videomode *vm, u16 width,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302265 u16 height, u16 out_width, u16 out_height,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002266 enum omap_color_mode color_mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002267{
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302268 u32 core_clk = 0;
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302269 u64 tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002270
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302271 if (height <= out_height && width <= out_width)
2272 return (unsigned long) pclk;
2273
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002274 if (height > out_height) {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002275 unsigned int ppl = vm->hactive;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002276
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002277 tmp = (u64)pclk * height * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002278 do_div(tmp, 2 * out_height * ppl);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302279 core_clk = tmp;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002280
Ville Syrjälä2d9c5592010-01-08 11:56:41 +02002281 if (height > 2 * out_height) {
2282 if (ppl == out_width)
2283 return 0;
2284
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002285 tmp = (u64)pclk * (height - 2 * out_height) * out_width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002286 do_div(tmp, 2 * out_height * (ppl - out_width));
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302287 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002288 }
2289 }
2290
2291 if (width > out_width) {
Tomi Valkeinenc5829352015-04-10 12:48:36 +03002292 tmp = (u64)pclk * width;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002293 do_div(tmp, out_width);
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302294 core_clk = max_t(u32, core_clk, tmp);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002295
2296 if (color_mode == OMAP_DSS_COLOR_RGB24U)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302297 core_clk <<= 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002298 }
2299
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302300 return core_clk;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002301}
2302
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002303static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302304 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302305{
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302306 if (height > out_height && width > out_width)
2307 return pclk * 4;
2308 else
2309 return pclk * 2;
2310}
2311
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002312static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302313 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002314{
2315 unsigned int hf, vf;
2316
2317 /*
2318 * FIXME how to determine the 'A' factor
2319 * for the no downscaling case ?
2320 */
2321
2322 if (width > 3 * out_width)
2323 hf = 4;
2324 else if (width > 2 * out_width)
2325 hf = 3;
2326 else if (width > out_width)
2327 hf = 2;
2328 else
2329 hf = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002330 if (height > out_height)
2331 vf = 2;
2332 else
2333 vf = 1;
2334
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302335 return pclk * vf * hf;
2336}
2337
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002338static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302339 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302340{
Archit Taneja8ba85302012-09-26 17:00:37 +05302341 /*
2342 * If the overlay/writeback is in mem to mem mode, there are no
2343 * downscaling limitations with respect to pixel clock, return 1 as
2344 * required core clock to represent that we have sufficient enough
2345 * core clock to do maximum downscaling
2346 */
2347 if (mem_to_mem)
2348 return 1;
2349
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302350 if (width > out_width)
2351 return DIV_ROUND_UP(pclk, out_width) * width;
2352 else
2353 return pclk;
2354}
2355
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002356static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002357 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302358 u16 width, u16 height, u16 out_width, u16 out_height,
2359 enum omap_color_mode color_mode, bool *five_taps,
2360 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302361 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302362{
2363 int error;
2364 u16 in_width, in_height;
2365 int min_factor = min(*decim_x, *decim_y);
2366 const int maxsinglelinewidth =
2367 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302368
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302369 *five_taps = false;
2370
2371 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002372 in_height = height / *decim_y;
2373 in_width = width / *decim_x;
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002374 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302375 in_height, out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302376 error = (in_width > maxsinglelinewidth || !*core_clk ||
2377 *core_clk > dispc_core_clk_rate());
2378 if (error) {
2379 if (*decim_x == *decim_y) {
2380 *decim_x = min_factor;
2381 ++*decim_y;
2382 } else {
2383 swap(*decim_x, *decim_y);
2384 if (*decim_x < *decim_y)
2385 ++*decim_x;
2386 }
2387 }
2388 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2389
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002390 if (error) {
2391 DSSERR("failed to find scaling settings\n");
2392 return -EINVAL;
2393 }
2394
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302395 if (in_width > maxsinglelinewidth) {
2396 DSSERR("Cannot scale max input width exceeded");
2397 return -EINVAL;
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302398 }
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302399 return 0;
2400}
2401
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002402static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002403 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302404 u16 width, u16 height, u16 out_width, u16 out_height,
2405 enum omap_color_mode color_mode, bool *five_taps,
2406 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302407 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302408{
2409 int error;
2410 u16 in_width, in_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302411 const int maxsinglelinewidth =
2412 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2413
2414 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002415 in_height = height / *decim_y;
2416 in_width = width / *decim_x;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002417 *five_taps = in_height > out_height;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302418
2419 if (in_width > maxsinglelinewidth)
2420 if (in_height > out_height &&
2421 in_height < out_height * 2)
2422 *five_taps = false;
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002423again:
2424 if (*five_taps)
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002425 *core_clk = calc_core_clk_five_taps(pclk, vm,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002426 in_width, in_height, out_width,
2427 out_height, color_mode);
2428 else
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002429 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
Archit Taneja8ba85302012-09-26 17:00:37 +05302430 in_height, out_width, out_height,
2431 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302432
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002433 error = check_horiz_timing_omap3(pclk, lclk, vm,
Ivaylo Dimitrove49986342014-01-13 18:33:02 +02002434 pos_x, in_width, in_height, out_width,
2435 out_height, *five_taps);
2436 if (error && *five_taps) {
2437 *five_taps = false;
2438 goto again;
2439 }
2440
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302441 error = (error || in_width > maxsinglelinewidth * 2 ||
2442 (in_width > maxsinglelinewidth && *five_taps) ||
2443 !*core_clk || *core_clk > dispc_core_clk_rate());
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002444
2445 if (!error) {
2446 /* verify that we're inside the limits of scaler */
2447 if (in_width / 4 > out_width)
2448 error = 1;
2449
2450 if (*five_taps) {
2451 if (in_height / 4 > out_height)
2452 error = 1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302453 } else {
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002454 if (in_height / 2 > out_height)
2455 error = 1;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302456 }
2457 }
Tomi Valkeinenab6b2582015-03-17 15:31:10 +02002458
Tomi Valkeinen7059e3d2015-04-10 12:48:38 +03002459 if (error)
2460 ++*decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302461 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2462
Tomi Valkeinen3ce17b42015-04-10 12:48:37 +03002463 if (error) {
2464 DSSERR("failed to find scaling settings\n");
2465 return -EINVAL;
2466 }
2467
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002468 if (check_horiz_timing_omap3(pclk, lclk, vm, pos_x, in_width,
Tomi Valkeinenf5a73482015-03-17 15:31:09 +02002469 in_height, out_width, out_height, *five_taps)) {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302470 DSSERR("horizontal timing too tight\n");
2471 return -EINVAL;
2472 }
2473
2474 if (in_width > (maxsinglelinewidth * 2)) {
2475 DSSERR("Cannot setup scaling");
2476 DSSERR("width exceeds maximum width possible");
2477 return -EINVAL;
2478 }
2479
2480 if (in_width > maxsinglelinewidth && *five_taps) {
2481 DSSERR("cannot setup scaling with five taps");
2482 return -EINVAL;
2483 }
2484 return 0;
2485}
2486
Tomi Valkeinen0c6921d2012-10-19 15:43:29 +03002487static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002488 const struct videomode *vm,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302489 u16 width, u16 height, u16 out_width, u16 out_height,
2490 enum omap_color_mode color_mode, bool *five_taps,
2491 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
Archit Taneja8ba85302012-09-26 17:00:37 +05302492 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302493{
2494 u16 in_width, in_width_max;
2495 int decim_x_min = *decim_x;
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002496 u16 in_height = height / *decim_y;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302497 const int maxsinglelinewidth =
2498 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
Archit Taneja8ba85302012-09-26 17:00:37 +05302499 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302500
Archit Taneja5d501082012-11-07 11:45:02 +05302501 if (mem_to_mem) {
2502 in_width_max = out_width * maxdownscale;
2503 } else {
Archit Taneja8ba85302012-09-26 17:00:37 +05302504 in_width_max = dispc_core_clk_rate() /
2505 DIV_ROUND_UP(pclk, out_width);
Archit Taneja5d501082012-11-07 11:45:02 +05302506 }
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302507
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302508 *decim_x = DIV_ROUND_UP(width, in_width_max);
2509
2510 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2511 if (*decim_x > *x_predecim)
2512 return -EINVAL;
2513
2514 do {
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002515 in_width = width / *decim_x;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302516 } while (*decim_x <= *x_predecim &&
2517 in_width > maxsinglelinewidth && ++*decim_x);
2518
2519 if (in_width > maxsinglelinewidth) {
2520 DSSERR("Cannot scale width exceeds max line width");
2521 return -EINVAL;
2522 }
2523
Jyri Sarha1b30ab02017-02-08 16:08:06 +02002524 if (*decim_x > 4 && color_mode != OMAP_DSS_COLOR_NV12) {
2525 /*
2526 * Let's disable all scaling that requires horizontal
2527 * decimation with higher factor than 4, until we have
2528 * better estimates of what we can and can not
2529 * do. However, NV12 color format appears to work Ok
2530 * with all decimation factors.
2531 *
2532 * When decimating horizontally by more that 4 the dss
2533 * is not able to fetch the data in burst mode. When
2534 * this happens it is hard to tell if there enough
2535 * bandwidth. Despite what theory says this appears to
2536 * be true also for 16-bit color formats.
2537 */
2538 DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)", *decim_x);
2539
2540 return -EINVAL;
2541 }
2542
Tomi Valkeinen8702ee52012-10-19 15:36:11 +03002543 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
Archit Taneja8ba85302012-09-26 17:00:37 +05302544 out_width, out_height, mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302545 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002546}
2547
Tomi Valkeinene4c5ae72015-04-10 12:48:39 +03002548#define DIV_FRAC(dividend, divisor) \
2549 ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2550
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002551static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302552 enum omap_overlay_caps caps,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002553 const struct videomode *vm,
Archit Taneja81ab95b2012-05-08 15:53:20 +05302554 u16 width, u16 height, u16 out_width, u16 out_height,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302555 enum omap_color_mode color_mode, bool *five_taps,
Chandrabhanu Mahapatrad557a9c2012-09-24 12:08:27 +05302556 int *x_predecim, int *y_predecim, u16 pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302557 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302558{
Archit Taneja0373cac2011-09-08 13:25:17 +05302559 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302560 const int max_decim_limit = 16;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302561 unsigned long core_clk = 0;
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302562 int decim_x, decim_y, ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302563
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002564 if (width == out_width && height == out_height)
2565 return 0;
2566
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002567 if (!mem_to_mem && (pclk == 0 || vm->pixelclock == 0)) {
Tomi Valkeinen4e1d3ca2014-10-03 15:14:09 +00002568 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2569 return -EINVAL;
2570 }
2571
Archit Taneja5b54ed32012-09-26 16:55:27 +05302572 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
Tomi Valkeinenf95cb5e2011-11-01 10:50:45 +02002573 return -EINVAL;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302574
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002575 if (mem_to_mem) {
Archit Taneja1c031442012-11-07 11:45:03 +05302576 *x_predecim = *y_predecim = 1;
2577 } else {
2578 *x_predecim = max_decim_limit;
2579 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2580 dss_has_feature(FEAT_BURST_2D)) ?
2581 2 : max_decim_limit;
2582 }
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302583
2584 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2585 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2586 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2587 color_mode == OMAP_DSS_COLOR_CLUT8) {
2588 *x_predecim = 1;
2589 *y_predecim = 1;
2590 *five_taps = false;
2591 return 0;
2592 }
2593
2594 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2595 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2596
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302597 if (decim_x > *x_predecim || out_width > width * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302598 return -EINVAL;
2599
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302600 if (decim_y > *y_predecim || out_height > height * 8)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302601 return -EINVAL;
2602
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002603 ret = dispc.feat->calc_scaling(pclk, lclk, vm, width, height,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302604 out_width, out_height, color_mode, five_taps,
Archit Taneja8ba85302012-09-26 17:00:37 +05302605 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2606 mem_to_mem);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05302607 if (ret)
2608 return ret;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302609
Tomi Valkeinene4c5ae72015-04-10 12:48:39 +03002610 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",
2611 width, height,
2612 out_width, out_height,
2613 out_width / width, DIV_FRAC(out_width, width),
2614 out_height / height, DIV_FRAC(out_height, height),
2615
2616 decim_x, decim_y,
2617 width / decim_x, height / decim_y,
2618 out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
2619 out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
2620
2621 *five_taps ? 5 : 3,
2622 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302623
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302624 if (!core_clk || core_clk > dispc_core_clk_rate()) {
Archit Taneja79ad75f2011-09-08 13:15:11 +05302625 DSSERR("failed to set up scaling, "
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05302626 "required core clk rate = %lu Hz, "
2627 "current core clk rate = %lu Hz\n",
2628 core_clk, dispc_core_clk_rate());
Archit Taneja79ad75f2011-09-08 13:15:11 +05302629 return -EINVAL;
2630 }
2631
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302632 *x_predecim = decim_x;
2633 *y_predecim = decim_y;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302634 return 0;
2635}
2636
Jyri Sarha864050c2017-03-24 16:47:52 +02002637static int dispc_ovl_setup_common(enum omap_plane_id plane,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302638 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2639 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2640 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2641 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2642 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002643 bool replication, const struct videomode *vm,
Archit Taneja8ba85302012-09-26 17:00:37 +05302644 bool mem_to_mem)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002645{
Chandrabhanu Mahapatra7282f1b2011-12-19 14:03:56 +05302646 bool five_taps = true;
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002647 bool fieldmode = false;
Archit Taneja79ad75f2011-09-08 13:15:11 +05302648 int r, cconv = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002649 unsigned offset0, offset1;
2650 s32 row_inc;
2651 s32 pix_inc;
Archit Taneja6be0d732012-11-07 11:45:04 +05302652 u16 frame_width, frame_height;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002653 unsigned int field_offset = 0;
Archit Taneja84a880f2012-09-26 16:57:37 +05302654 u16 in_height = height;
2655 u16 in_width = width;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302656 int x_predecim = 1, y_predecim = 1;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002657 bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED);
Tomi Valkeinen74e16452012-10-19 15:46:30 +03002658 unsigned long pclk = dispc_plane_pclk_rate(plane);
2659 unsigned long lclk = dispc_plane_lclk_rate(plane);
Tomi Valkeinen2cc5d1a2011-11-03 17:03:44 +02002660
Tomi Valkeinene5666582014-11-28 14:34:15 +02002661 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002662 return -EINVAL;
2663
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002664 switch (color_mode) {
2665 case OMAP_DSS_COLOR_YUV2:
2666 case OMAP_DSS_COLOR_UYVY:
2667 case OMAP_DSS_COLOR_NV12:
2668 if (in_width & 1) {
2669 DSSERR("input width %d is not even for YUV format\n",
2670 in_width);
2671 return -EINVAL;
2672 }
2673 break;
2674
2675 default:
2676 break;
2677 }
2678
Archit Taneja84a880f2012-09-26 16:57:37 +05302679 out_width = out_width == 0 ? width : out_width;
2680 out_height = out_height == 0 ? height : out_height;
Tomi Valkeinencf073662011-11-03 16:08:27 +02002681
Archit Taneja84a880f2012-09-26 16:57:37 +05302682 if (ilace && height == out_height)
Peter Senna Tschudin62a83182013-09-22 20:44:11 +02002683 fieldmode = true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002684
2685 if (ilace) {
2686 if (fieldmode)
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302687 in_height /= 2;
Archit Taneja8eeb7012012-08-22 12:33:49 +05302688 pos_y /= 2;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302689 out_height /= 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002690
2691 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
Archit Taneja84a880f2012-09-26 16:57:37 +05302692 "out_height %d\n", in_height, pos_y,
2693 out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002694 }
2695
Archit Taneja84a880f2012-09-26 16:57:37 +05302696 if (!dss_feat_color_mode_supported(plane, color_mode))
Archit Taneja8dad2ab2010-11-25 17:58:10 +05302697 return -EINVAL;
2698
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002699 r = dispc_ovl_calc_scaling(pclk, lclk, caps, vm, in_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302700 in_height, out_width, out_height, color_mode,
2701 &five_taps, &x_predecim, &y_predecim, pos_x,
Archit Taneja8ba85302012-09-26 17:00:37 +05302702 rotation_type, mem_to_mem);
Archit Taneja79ad75f2011-09-08 13:15:11 +05302703 if (r)
2704 return r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002705
Tomi Valkeineneec77da2014-01-27 11:29:53 +02002706 in_width = in_width / x_predecim;
2707 in_height = in_height / y_predecim;
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302708
Tomi Valkeinenc4661b32015-02-27 13:07:58 +02002709 if (x_predecim > 1 || y_predecim > 1)
2710 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2711 x_predecim, y_predecim, in_width, in_height);
2712
2713 switch (color_mode) {
2714 case OMAP_DSS_COLOR_YUV2:
2715 case OMAP_DSS_COLOR_UYVY:
2716 case OMAP_DSS_COLOR_NV12:
2717 if (in_width & 1) {
2718 DSSDBG("predecimated input width is not even for YUV format\n");
2719 DSSDBG("adjusting input width %d -> %d\n",
2720 in_width, in_width & ~1);
2721
2722 in_width &= ~1;
2723 }
2724 break;
2725
2726 default:
2727 break;
2728 }
2729
Archit Taneja84a880f2012-09-26 16:57:37 +05302730 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2731 color_mode == OMAP_DSS_COLOR_UYVY ||
2732 color_mode == OMAP_DSS_COLOR_NV12)
Archit Taneja79ad75f2011-09-08 13:15:11 +05302733 cconv = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002734
2735 if (ilace && !fieldmode) {
2736 /*
2737 * when downscaling the bottom field may have to start several
2738 * source lines below the top field. Unfortunately ACCUI
2739 * registers will only hold the fractional part of the offset
2740 * so the integer part must be added to the base address of the
2741 * bottom field.
2742 */
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302743 if (!in_height || in_height == out_height)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002744 field_offset = 0;
2745 else
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302746 field_offset = in_height / out_height / 2;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002747 }
2748
2749 /* Fields are independent but interleaved in memory. */
2750 if (fieldmode)
2751 field_offset = 1;
2752
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002753 offset0 = 0;
2754 offset1 = 0;
2755 row_inc = 0;
2756 pix_inc = 0;
2757
Archit Taneja6be0d732012-11-07 11:45:04 +05302758 if (plane == OMAP_DSS_WB) {
2759 frame_width = out_width;
2760 frame_height = out_height;
2761 } else {
2762 frame_width = in_width;
2763 frame_height = height;
2764 }
2765
Archit Taneja84a880f2012-09-26 16:57:37 +05302766 if (rotation_type == OMAP_DSS_ROT_TILER)
Archit Taneja6be0d732012-11-07 11:45:04 +05302767 calc_tiler_rotation_offset(screen_width, frame_width,
Archit Taneja84a880f2012-09-26 16:57:37 +05302768 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302769 &offset0, &offset1, &row_inc, &pix_inc,
2770 x_predecim, y_predecim);
Archit Taneja84a880f2012-09-26 16:57:37 +05302771 else if (rotation_type == OMAP_DSS_ROT_DMA)
Archit Taneja6be0d732012-11-07 11:45:04 +05302772 calc_dma_rotation_offset(rotation, mirror, screen_width,
2773 frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302774 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302775 &offset0, &offset1, &row_inc, &pix_inc,
2776 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002777 else
Archit Taneja84a880f2012-09-26 16:57:37 +05302778 calc_vrfb_rotation_offset(rotation, mirror,
Archit Taneja6be0d732012-11-07 11:45:04 +05302779 screen_width, frame_width, frame_height,
Archit Taneja84a880f2012-09-26 16:57:37 +05302780 color_mode, fieldmode, field_offset,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302781 &offset0, &offset1, &row_inc, &pix_inc,
2782 x_predecim, y_predecim);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002783
2784 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2785 offset0, offset1, row_inc, pix_inc);
2786
Archit Taneja84a880f2012-09-26 16:57:37 +05302787 dispc_ovl_set_color_mode(plane, color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002788
Archit Taneja84a880f2012-09-26 16:57:37 +05302789 dispc_ovl_configure_burst_type(plane, rotation_type);
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +05302790
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02002791 if (dispc.feat->reverse_ilace_field_order)
2792 swap(offset0, offset1);
2793
Archit Taneja84a880f2012-09-26 16:57:37 +05302794 dispc_ovl_set_ba0(plane, paddr + offset0);
2795 dispc_ovl_set_ba1(plane, paddr + offset1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002796
Archit Taneja84a880f2012-09-26 16:57:37 +05302797 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2798 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2799 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
Amber Jain0d66cbb2011-05-19 19:47:54 +05302800 }
2801
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03002802 if (dispc.feat->last_pixel_inc_missing)
2803 row_inc += pix_inc - 1;
2804
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002805 dispc_ovl_set_row_inc(plane, row_inc);
2806 dispc_ovl_set_pix_inc(plane, pix_inc);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002807
Archit Taneja84a880f2012-09-26 16:57:37 +05302808 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302809 in_height, out_width, out_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002810
Archit Taneja84a880f2012-09-26 16:57:37 +05302811 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002812
Archit Taneja78b687f2012-09-21 14:51:49 +05302813 dispc_ovl_set_input_size(plane, in_width, in_height);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002814
Archit Taneja5b54ed32012-09-26 16:55:27 +05302815 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
Chandrabhanu Mahapatraaed74b552012-04-02 20:43:16 +05302816 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2817 out_height, ilace, five_taps, fieldmode,
Archit Taneja84a880f2012-09-26 16:57:37 +05302818 color_mode, rotation);
Archit Taneja78b687f2012-09-21 14:51:49 +05302819 dispc_ovl_set_output_size(plane, out_width, out_height);
Tomi Valkeinenf0e5caa2011-08-16 13:25:00 +03002820 dispc_ovl_set_vid_color_conv(plane, cconv);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002821 }
2822
Archit Tanejac35eeb22013-03-26 19:15:24 +05302823 dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, mirror,
2824 color_mode);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002825
Archit Taneja84a880f2012-09-26 16:57:37 +05302826 dispc_ovl_set_zorder(plane, caps, zorder);
2827 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2828 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002829
Archit Tanejad79db852012-09-22 12:30:17 +05302830 dispc_ovl_enable_replication(plane, caps, replication);
Archit Tanejac3d925292011-09-14 11:52:54 +05302831
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002832 return 0;
2833}
2834
Jyri Sarha864050c2017-03-24 16:47:52 +02002835static int dispc_ovl_setup(enum omap_plane_id plane,
Jyri Sarha273ffea2017-03-24 16:47:53 +02002836 const struct omap_overlay_info *oi,
Tomi Valkeinen49a30572017-02-17 12:30:07 +02002837 const struct videomode *vm, bool mem_to_mem,
2838 enum omap_channel channel)
Archit Taneja84a880f2012-09-26 16:57:37 +05302839{
2840 int r;
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002841 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
Tomi Valkeinenbe2d68c2016-08-29 13:15:02 +03002842 const bool replication = true;
Archit Taneja84a880f2012-09-26 16:57:37 +05302843
Arnd Bergmann24f13a62014-04-24 13:28:18 +01002844 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2845 " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2846 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
Archit Taneja84a880f2012-09-26 16:57:37 +05302847 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2848 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2849
Tomi Valkeinen49a30572017-02-17 12:30:07 +02002850 dispc_ovl_set_channel_out(plane, channel);
2851
Tomi Valkeinen16bf20c2012-10-15 15:33:22 +03002852 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05302853 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2854 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2855 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002856 oi->rotation_type, replication, vm, mem_to_mem);
Archit Taneja84a880f2012-09-26 16:57:37 +05302857
2858 return r;
2859}
2860
Archit Taneja749feff2012-08-31 12:32:52 +05302861int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002862 bool mem_to_mem, const struct videomode *vm)
Archit Taneja749feff2012-08-31 12:32:52 +05302863{
2864 int r;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302865 u32 l;
Jyri Sarha864050c2017-03-24 16:47:52 +02002866 enum omap_plane_id plane = OMAP_DSS_WB;
Archit Taneja749feff2012-08-31 12:32:52 +05302867 const int pos_x = 0, pos_y = 0;
2868 const u8 zorder = 0, global_alpha = 0;
Tomi Valkeinenbe2d68c2016-08-29 13:15:02 +03002869 const bool replication = true;
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302870 bool truncation;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002871 int in_width = vm->hactive;
2872 int in_height = vm->vactive;
Archit Taneja749feff2012-08-31 12:32:52 +05302873 enum omap_overlay_caps caps =
2874 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2875
2876 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2877 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2878 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2879 wi->mirror);
2880
2881 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2882 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2883 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2884 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002885 replication, vm, mem_to_mem);
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302886
2887 switch (wi->color_mode) {
2888 case OMAP_DSS_COLOR_RGB16:
2889 case OMAP_DSS_COLOR_RGB24P:
2890 case OMAP_DSS_COLOR_ARGB16:
2891 case OMAP_DSS_COLOR_RGBA16:
2892 case OMAP_DSS_COLOR_RGB12U:
2893 case OMAP_DSS_COLOR_ARGB16_1555:
2894 case OMAP_DSS_COLOR_XRGB16_1555:
2895 case OMAP_DSS_COLOR_RGBX16:
2896 truncation = true;
2897 break;
2898 default:
2899 truncation = false;
2900 break;
2901 }
2902
2903 /* setup extra DISPC_WB_ATTRIBUTES */
2904 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2905 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2906 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
Tomi Valkeinen4c055ce2015-11-04 17:10:53 +02002907 if (mem_to_mem)
2908 l = FLD_MOD(l, 1, 26, 24); /* CAPTUREMODE */
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002909 else
2910 l = FLD_MOD(l, 0, 26, 24); /* CAPTUREMODE */
Archit Taneja9e4a0fc2012-08-24 16:59:26 +05302911 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
Archit Taneja749feff2012-08-31 12:32:52 +05302912
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002913 if (mem_to_mem) {
2914 /* WBDELAYCOUNT */
2915 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0);
2916 } else {
2917 int wbdelay;
2918
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03002919 wbdelay = min(vm->vfront_porch +
2920 vm->vsync_len + vm->vback_porch, (u32)255);
Tomi Valkeinen98cd5792015-11-04 17:10:54 +02002921
2922 /* WBDELAYCOUNT */
2923 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0);
2924 }
2925
Archit Taneja749feff2012-08-31 12:32:52 +05302926 return r;
2927}
2928
Jyri Sarha864050c2017-03-24 16:47:52 +02002929static int dispc_ovl_enable(enum omap_plane_id plane, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002930{
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002931 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2932
Archit Taneja9b372c22011-05-06 11:45:49 +05302933 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
Tomi Valkeinene6d80f92011-05-19 14:12:26 +03002934
2935 return 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002936}
2937
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002938static enum omap_dss_output_id dispc_mgr_get_supported_outputs(enum omap_channel channel)
Tomi Valkeinen7b9cb5e2015-11-04 15:11:25 +02002939{
2940 return dss_feat_get_supported_outputs(channel);
2941}
Tomi Valkeinen7b9cb5e2015-11-04 15:11:25 +02002942
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002943static void dispc_lcd_enable_signal_polarity(bool act_high)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002944{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002945 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2946 return;
2947
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002948 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002949}
2950
2951void dispc_lcd_enable_signal(bool enable)
2952{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002953 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2954 return;
2955
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002956 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002957}
2958
2959void dispc_pck_free_enable(bool enable)
2960{
Archit Taneja6ced40b2010-12-02 11:27:13 +00002961 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2962 return;
2963
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002964 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002965}
2966
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02002967static int dispc_get_num_mgrs(void)
Tomi Valkeinenc2834002015-11-05 19:54:33 +02002968{
2969 return dss_feat_get_num_mgrs();
2970}
Tomi Valkeinenc2834002015-11-05 19:54:33 +02002971
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002972static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002973{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302974 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002975}
2976
2977
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03002978static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002979{
Archit Tanejad21f43b2012-06-21 09:45:11 +05302980 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002981}
2982
Tomi Valkeinen65904152015-11-04 17:10:57 +02002983static void dispc_set_loadmode(enum omap_dss_load_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002984{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002985 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002986}
2987
2988
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002989static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002990{
Sumit Semwal8613b002010-12-02 11:27:09 +00002991 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002992}
2993
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02002994static void dispc_mgr_set_trans_key(enum omap_channel ch,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002995 enum omap_dss_trans_key_type type,
2996 u32 trans_key)
2997{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05302998 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02002999
Sumit Semwal8613b002010-12-02 11:27:09 +00003000 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003001}
3002
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02003003static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003004{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05303005 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003006}
Archit Taneja11354dd2011-09-26 11:47:29 +05303007
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02003008static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
3009 bool enable)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003010{
Archit Taneja11354dd2011-09-26 11:47:29 +05303011 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003012 return;
3013
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003014 if (ch == OMAP_DSS_CHANNEL_LCD)
3015 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003016 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003017 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003018}
Archit Taneja11354dd2011-09-26 11:47:29 +05303019
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003020static void dispc_mgr_setup(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003021 const struct omap_overlay_manager_info *info)
Tomi Valkeinenc64dca42011-11-04 18:14:20 +02003022{
3023 dispc_mgr_set_default_color(channel, info->default_color);
3024 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
3025 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
3026 dispc_mgr_enable_alpha_fixed_zorder(channel,
3027 info->partial_alpha_enabled);
3028 if (dss_has_feature(FEAT_CPR)) {
3029 dispc_mgr_enable_cpr(channel, info->cpr_enable);
3030 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
3031 }
3032}
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003033
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003034static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003035{
3036 int code;
3037
3038 switch (data_lines) {
3039 case 12:
3040 code = 0;
3041 break;
3042 case 16:
3043 code = 1;
3044 break;
3045 case 18:
3046 code = 2;
3047 break;
3048 case 24:
3049 code = 3;
3050 break;
3051 default:
3052 BUG();
3053 return;
3054 }
3055
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05303056 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003057}
3058
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003059static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003060{
3061 u32 l;
Archit Taneja569969d2011-08-22 17:41:57 +05303062 int gpout0, gpout1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003063
3064 switch (mode) {
Archit Taneja569969d2011-08-22 17:41:57 +05303065 case DSS_IO_PAD_MODE_RESET:
3066 gpout0 = 0;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003067 gpout1 = 0;
3068 break;
Archit Taneja569969d2011-08-22 17:41:57 +05303069 case DSS_IO_PAD_MODE_RFBI:
3070 gpout0 = 1;
3071 gpout1 = 0;
3072 break;
3073 case DSS_IO_PAD_MODE_BYPASS:
3074 gpout0 = 1;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003075 gpout1 = 1;
3076 break;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003077 default:
3078 BUG();
3079 return;
3080 }
3081
Archit Taneja569969d2011-08-22 17:41:57 +05303082 l = dispc_read_reg(DISPC_CONTROL);
3083 l = FLD_MOD(l, gpout0, 15, 15);
3084 l = FLD_MOD(l, gpout1, 16, 16);
3085 dispc_write_reg(DISPC_CONTROL, l);
3086}
3087
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003088static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
Archit Taneja569969d2011-08-22 17:41:57 +05303089{
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05303090 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003091}
3092
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003093static void dispc_mgr_set_lcd_config(enum omap_channel channel,
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +03003094 const struct dss_lcd_mgr_config *config)
3095{
3096 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
3097
3098 dispc_mgr_enable_stallmode(channel, config->stallmode);
3099 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
3100
3101 dispc_mgr_set_clock_div(channel, &config->clock_info);
3102
3103 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
3104
3105 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
3106
3107 dispc_mgr_set_lcd_type_tft(channel);
3108}
3109
Archit Taneja8f366162012-04-16 12:53:44 +05303110static bool _dispc_mgr_size_ok(u16 width, u16 height)
3111{
Archit Taneja33b89922012-11-14 13:50:15 +05303112 return width <= dispc.feat->mgr_width_max &&
3113 height <= dispc.feat->mgr_height_max;
Archit Taneja8f366162012-04-16 12:53:44 +05303114}
3115
Peter Ujfalusi4dc22502016-09-22 14:06:48 +03003116static bool _dispc_lcd_timings_ok(int hsync_len, int hfp, int hbp,
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003117 int vsw, int vfp, int vbp)
3118{
Peter Ujfalusi4dc22502016-09-22 14:06:48 +03003119 if (hsync_len < 1 || hsync_len > dispc.feat->sw_max ||
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303120 hfp < 1 || hfp > dispc.feat->hp_max ||
3121 hbp < 1 || hbp > dispc.feat->hp_max ||
3122 vsw < 1 || vsw > dispc.feat->sw_max ||
3123 vfp < 0 || vfp > dispc.feat->vp_max ||
3124 vbp < 0 || vbp > dispc.feat->vp_max)
3125 return false;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003126 return true;
3127}
3128
Archit Tanejaca5ca692013-03-26 19:15:22 +05303129static bool _dispc_mgr_pclk_ok(enum omap_channel channel,
3130 unsigned long pclk)
3131{
3132 if (dss_mgr_is_lcd(channel))
Andrew F. Davis0cac5b62016-07-01 09:27:21 -05003133 return pclk <= dispc.feat->max_lcd_pclk;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303134 else
Andrew F. Davis0cac5b62016-07-01 09:27:21 -05003135 return pclk <= dispc.feat->max_tv_pclk;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303136}
3137
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003138bool dispc_mgr_timings_ok(enum omap_channel channel, const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003139{
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003140 if (!_dispc_mgr_size_ok(vm->hactive, vm->vactive))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003141 return false;
Archit Taneja8f366162012-04-16 12:53:44 +05303142
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003143 if (!_dispc_mgr_pclk_ok(channel, vm->pixelclock))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003144 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303145
3146 if (dss_mgr_is_lcd(channel)) {
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03003147 /* TODO: OMAP4+ supports interlace for LCD outputs */
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003148 if (vm->flags & DISPLAY_FLAGS_INTERLACED)
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003149 return false;
Tomi Valkeinenbeb83842014-06-05 11:35:10 +03003150
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003151 if (!_dispc_lcd_timings_ok(vm->hsync_len,
3152 vm->hfront_porch, vm->hback_porch,
3153 vm->vsync_len, vm->vfront_porch,
3154 vm->vback_porch))
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003155 return false;
Archit Tanejaca5ca692013-03-26 19:15:22 +05303156 }
Archit Taneja8f366162012-04-16 12:53:44 +05303157
Tomi Valkeineneadd33b2014-06-05 11:36:08 +03003158 return true;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003159}
3160
Peter Ujfalusi3b592932016-09-22 14:06:56 +03003161static void _dispc_mgr_set_lcd_timings(enum omap_channel channel,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003162 const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003163{
Archit Taneja655e2942012-06-21 10:37:43 +05303164 u32 timing_h, timing_v, l;
Tomi Valkeinened351882014-10-02 17:58:49 +00003165 bool onoff, rf, ipc, vs, hs, de;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003166
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003167 timing_h = FLD_VAL(vm->hsync_len - 1, dispc.feat->sw_start, 0) |
3168 FLD_VAL(vm->hfront_porch - 1, dispc.feat->fp_start, 8) |
3169 FLD_VAL(vm->hback_porch - 1, dispc.feat->bp_start, 20);
3170 timing_v = FLD_VAL(vm->vsync_len - 1, dispc.feat->sw_start, 0) |
3171 FLD_VAL(vm->vfront_porch, dispc.feat->fp_start, 8) |
3172 FLD_VAL(vm->vback_porch, dispc.feat->bp_start, 20);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003173
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003174 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
3175 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
Archit Taneja655e2942012-06-21 10:37:43 +05303176
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003177 if (vm->flags & DISPLAY_FLAGS_VSYNC_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00003178 vs = false;
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03003179 else
3180 vs = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00003181
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003182 if (vm->flags & DISPLAY_FLAGS_HSYNC_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00003183 hs = false;
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03003184 else
3185 hs = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00003186
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003187 if (vm->flags & DISPLAY_FLAGS_DE_HIGH)
Tomi Valkeinened351882014-10-02 17:58:49 +00003188 de = false;
Peter Ujfalusi3fa3ab42016-09-22 14:06:58 +03003189 else
3190 de = true;
Tomi Valkeinened351882014-10-02 17:58:49 +00003191
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003192 if (vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
Archit Taneja655e2942012-06-21 10:37:43 +05303193 ipc = false;
Peter Ujfalusif149e172016-09-22 14:07:00 +03003194 else
Archit Taneja655e2942012-06-21 10:37:43 +05303195 ipc = true;
Archit Taneja655e2942012-06-21 10:37:43 +05303196
Tomi Valkeinen7a163602014-10-02 17:58:48 +00003197 /* always use the 'rf' setting */
3198 onoff = true;
3199
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003200 if (vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE)
Archit Taneja655e2942012-06-21 10:37:43 +05303201 rf = true;
Peter Ujfalusid34afb72016-09-22 14:07:01 +03003202 else
3203 rf = false;
Archit Taneja655e2942012-06-21 10:37:43 +05303204
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003205 l = FLD_VAL(onoff, 17, 17) |
3206 FLD_VAL(rf, 16, 16) |
Tomi Valkeinened351882014-10-02 17:58:49 +00003207 FLD_VAL(de, 15, 15) |
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003208 FLD_VAL(ipc, 14, 14) |
Tomi Valkeinened351882014-10-02 17:58:49 +00003209 FLD_VAL(hs, 13, 13) |
3210 FLD_VAL(vs, 12, 12);
Tomi Valkeinend80e02e2014-04-25 11:46:16 +03003211
Tomi Valkeinene5f80912015-10-21 13:08:59 +03003212 /* always set ALIGN bit when available */
3213 if (dispc.feat->supports_sync_align)
3214 l |= (1 << 18);
3215
Archit Taneja655e2942012-06-21 10:37:43 +05303216 dispc_write_reg(DISPC_POL_FREQ(channel), l);
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00003217
3218 if (dispc.syscon_pol) {
3219 const int shifts[] = {
3220 [OMAP_DSS_CHANNEL_LCD] = 0,
3221 [OMAP_DSS_CHANNEL_LCD2] = 1,
3222 [OMAP_DSS_CHANNEL_LCD3] = 2,
3223 };
3224
3225 u32 mask, val;
3226
3227 mask = (1 << 0) | (1 << 3) | (1 << 6);
3228 val = (rf << 0) | (ipc << 3) | (onoff << 6);
3229
3230 mask <<= 16 + shifts[channel];
3231 val <<= 16 + shifts[channel];
3232
3233 regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset,
3234 mask, val);
3235 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003236}
3237
Tomi Valkeinen956d4f92016-11-23 13:23:42 +02003238static int vm_flag_to_int(enum display_flags flags, enum display_flags high,
3239 enum display_flags low)
3240{
3241 if (flags & high)
3242 return 1;
3243 if (flags & low)
3244 return -1;
3245 return 0;
3246}
3247
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003248/* change name to mode? */
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003249static void dispc_mgr_set_timings(enum omap_channel channel,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003250 const struct videomode *vm)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003251{
3252 unsigned xtot, ytot;
3253 unsigned long ht, vt;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003254 struct videomode t = *vm;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003255
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03003256 DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive);
Archit Tanejac51d9212012-04-16 12:53:43 +05303257
Archit Taneja2aefad42012-05-18 14:36:54 +05303258 if (!dispc_mgr_timings_ok(channel, &t)) {
Archit Taneja8f366162012-04-16 12:53:44 +05303259 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003260 return;
3261 }
Archit Tanejac51d9212012-04-16 12:53:43 +05303262
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303263 if (dss_mgr_is_lcd(channel)) {
Peter Ujfalusi3b592932016-09-22 14:06:56 +03003264 _dispc_mgr_set_lcd_timings(channel, &t);
Archit Tanejac51d9212012-04-16 12:53:43 +05303265
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03003266 xtot = t.hactive + t.hfront_porch + t.hsync_len + t.hback_porch;
Peter Ujfalusi458540c2016-09-22 14:06:53 +03003267 ytot = t.vactive + t.vfront_porch + t.vsync_len + t.vback_porch;
Archit Tanejac51d9212012-04-16 12:53:43 +05303268
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003269 ht = vm->pixelclock / xtot;
3270 vt = vm->pixelclock / xtot / ytot;
Archit Tanejac51d9212012-04-16 12:53:43 +05303271
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03003272 DSSDBG("pck %lu\n", vm->pixelclock);
Peter Ujfalusi4dc22502016-09-22 14:06:48 +03003273 DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03003274 t.hsync_len, t.hfront_porch, t.hback_porch,
Peter Ujfalusi458540c2016-09-22 14:06:53 +03003275 t.vsync_len, t.vfront_porch, t.vback_porch);
Archit Taneja655e2942012-06-21 10:37:43 +05303276 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 +02003277 vm_flag_to_int(t.flags, DISPLAY_FLAGS_VSYNC_HIGH, DISPLAY_FLAGS_VSYNC_LOW),
3278 vm_flag_to_int(t.flags, DISPLAY_FLAGS_HSYNC_HIGH, DISPLAY_FLAGS_HSYNC_LOW),
3279 vm_flag_to_int(t.flags, DISPLAY_FLAGS_PIXDATA_POSEDGE, DISPLAY_FLAGS_PIXDATA_NEGEDGE),
3280 vm_flag_to_int(t.flags, DISPLAY_FLAGS_DE_HIGH, DISPLAY_FLAGS_DE_LOW),
3281 vm_flag_to_int(t.flags, DISPLAY_FLAGS_SYNC_POSEDGE, DISPLAY_FLAGS_SYNC_NEGEDGE));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003282
Archit Tanejac51d9212012-04-16 12:53:43 +05303283 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
Archit Taneja2aefad42012-05-18 14:36:54 +05303284 } else {
Peter Ujfalusi53058292016-09-22 14:06:55 +03003285 if (t.flags & DISPLAY_FLAGS_INTERLACED)
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03003286 t.vactive /= 2;
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02003287
3288 if (dispc.feat->supports_double_pixel)
Peter Ujfalusi531efb32016-09-22 14:06:59 +03003289 REG_FLD_MOD(DISPC_CONTROL,
3290 !!(t.flags & DISPLAY_FLAGS_DOUBLECLK),
3291 19, 17);
Archit Tanejac51d9212012-04-16 12:53:43 +05303292 }
Archit Taneja8f366162012-04-16 12:53:44 +05303293
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03003294 dispc_mgr_set_size(channel, t.hactive, t.vactive);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003295}
3296
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003297static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003298 u16 pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003299{
3300 BUG_ON(lck_div < 1);
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003301 BUG_ON(pck_div < 1);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003302
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003303 dispc_write_reg(DISPC_DIVISORo(channel),
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003304 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003305
Luis de Bethencourt0bcfdba2015-10-15 13:29:38 +01003306 if (!dss_has_feature(FEAT_CORE_CLK_DIV) &&
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003307 channel == OMAP_DSS_CHANNEL_LCD)
3308 dispc.core_clk_rate = dispc_fclk_rate() / lck_div;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003309}
3310
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003311static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
Sumit Semwal2a205f32010-12-02 11:27:12 +00003312 int *pck_div)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003313{
3314 u32 l;
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003315 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003316 *lck_div = FLD_GET(l, 23, 16);
3317 *pck_div = FLD_GET(l, 7, 0);
3318}
3319
Tomi Valkeinen65904152015-11-04 17:10:57 +02003320static unsigned long dispc_fclk_rate(void)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003321{
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003322 unsigned long r;
3323 enum dss_clk_source src;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003324
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003325 src = dss_get_dispc_clk_source();
3326
3327 if (src == DSS_CLK_SRC_FCK) {
Tomi Valkeinen5aaee692012-12-12 10:37:03 +02003328 r = dss_get_dispc_clk_rate();
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003329 } else {
3330 struct dss_pll *pll;
3331 unsigned clkout_idx;
Tomi Valkeinen93550922014-12-31 11:25:48 +02003332
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003333 pll = dss_pll_find_by_src(src);
3334 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
Tomi Valkeinen93550922014-12-31 11:25:48 +02003335
Tomi Valkeinenef03b402016-05-18 13:52:14 +03003336 r = pll->cinfo.clkout[clkout_idx];
Taneja, Archit66534e82011-03-08 05:50:34 -06003337 }
3338
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003339 return r;
3340}
3341
Tomi Valkeinen65904152015-11-04 17:10:57 +02003342static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003343{
3344 int lcd;
3345 unsigned long r;
Tomi Valkeinen01575772016-05-17 16:08:34 +03003346 enum dss_clk_source src;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003347
Tomi Valkeinen01575772016-05-17 16:08:34 +03003348 /* for TV, LCLK rate is the FCLK rate */
3349 if (!dss_mgr_is_lcd(channel))
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003350 return dispc_fclk_rate();
Tomi Valkeinen01575772016-05-17 16:08:34 +03003351
3352 src = dss_get_lcd_clk_source(channel);
3353
3354 if (src == DSS_CLK_SRC_FCK) {
3355 r = dss_get_dispc_clk_rate();
3356 } else {
3357 struct dss_pll *pll;
3358 unsigned clkout_idx;
3359
3360 pll = dss_pll_find_by_src(src);
3361 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
3362
3363 r = pll->cinfo.clkout[clkout_idx];
Taneja, Architea751592011-03-08 05:50:35 -06003364 }
Tomi Valkeinen01575772016-05-17 16:08:34 +03003365
3366 lcd = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3367
3368 return r / lcd;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003369}
3370
Tomi Valkeinen65904152015-11-04 17:10:57 +02003371static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003372{
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003373 unsigned long r;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003374
Archit Tanejadd88b7a2012-06-29 14:41:30 +05303375 if (dss_mgr_is_lcd(channel)) {
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303376 int pcd;
3377 u32 l;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003378
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303379 l = dispc_read_reg(DISPC_DIVISORo(channel));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003380
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303381 pcd = FLD_GET(l, 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003382
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303383 r = dispc_mgr_lclk_rate(channel);
3384
3385 return r / pcd;
3386 } else {
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003387 return dispc.tv_pclk_rate;
Archit Tanejac3dc6a72011-09-13 18:28:41 +05303388 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003389}
3390
Tomi Valkeinen5391e872013-05-16 10:44:13 +03003391void dispc_set_tv_pclk(unsigned long pclk)
3392{
3393 dispc.tv_pclk_rate = pclk;
3394}
3395
Tomi Valkeinen65904152015-11-04 17:10:57 +02003396static unsigned long dispc_core_clk_rate(void)
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303397{
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003398 return dispc.core_clk_rate;
Chandrabhanu Mahapatra8b53d992012-04-23 12:16:50 +05303399}
3400
Jyri Sarha864050c2017-03-24 16:47:52 +02003401static unsigned long dispc_plane_pclk_rate(enum omap_plane_id plane)
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303402{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003403 enum omap_channel channel;
3404
3405 if (plane == OMAP_DSS_WB)
3406 return 0;
3407
3408 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303409
3410 return dispc_mgr_pclk_rate(channel);
3411}
3412
Jyri Sarha864050c2017-03-24 16:47:52 +02003413static unsigned long dispc_plane_lclk_rate(enum omap_plane_id plane)
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303414{
Tomi Valkeinen251886d2012-11-15 13:20:02 +02003415 enum omap_channel channel;
3416
3417 if (plane == OMAP_DSS_WB)
3418 return 0;
3419
3420 channel = dispc_ovl_get_channel_out(plane);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303421
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003422 return dispc_mgr_lclk_rate(channel);
Archit Taneja3e8a6ff2012-09-26 16:58:52 +05303423}
Tomi Valkeinenc31cba82012-10-23 11:50:10 +03003424
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303425static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003426{
3427 int lcd, pcd;
Tomi Valkeinendc0352d2016-05-17 13:45:09 +03003428 enum dss_clk_source lcd_clk_src;
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303429
3430 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3431
3432 lcd_clk_src = dss_get_lcd_clk_source(channel);
3433
Tomi Valkeinen557a1542016-05-17 13:49:18 +03003434 seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name,
Tomi Valkeinen407bd562016-05-17 13:50:55 +03003435 dss_get_clk_source_name(lcd_clk_src));
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303436
3437 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3438
3439 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3440 dispc_mgr_lclk_rate(channel), lcd);
3441 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3442 dispc_mgr_pclk_rate(channel), pcd);
3443}
3444
3445void dispc_dump_clocks(struct seq_file *s)
3446{
3447 int lcd;
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003448 u32 l;
Tomi Valkeinendc0352d2016-05-17 13:45:09 +03003449 enum dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003450
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003451 if (dispc_runtime_get())
3452 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003453
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003454 seq_printf(s, "- DISPC -\n");
3455
Tomi Valkeinen557a1542016-05-17 13:49:18 +03003456 seq_printf(s, "dispc fclk source = %s\n",
Tomi Valkeinen407bd562016-05-17 13:50:55 +03003457 dss_get_clk_source_name(dispc_clk_src));
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003458
3459 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
Sumit Semwal2a205f32010-12-02 11:27:12 +00003460
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003461 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3462 seq_printf(s, "- DISPC-CORE-CLK -\n");
3463 l = dispc_read_reg(DISPC_DIVISOR);
3464 lcd = FLD_GET(l, 23, 16);
3465
3466 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3467 (dispc_fclk_rate()/lcd), lcd);
3468 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003469
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303470 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
Taneja, Architea751592011-03-08 05:50:35 -06003471
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303472 if (dss_has_feature(FEAT_MGR_LCD2))
3473 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3474 if (dss_has_feature(FEAT_MGR_LCD3))
3475 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003476
3477 dispc_runtime_put();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003478}
3479
Tomi Valkeinene40402c2012-03-02 18:01:07 +02003480static void dispc_dump_regs(struct seq_file *s)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003481{
Archit Taneja4dd2da12011-08-05 19:06:01 +05303482 int i, j;
3483 const char *mgr_names[] = {
3484 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3485 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3486 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303487 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303488 };
3489 const char *ovl_names[] = {
3490 [OMAP_DSS_GFX] = "GFX",
3491 [OMAP_DSS_VIDEO1] = "VID1",
3492 [OMAP_DSS_VIDEO2] = "VID2",
Archit Tanejab8c095b2011-09-13 18:20:33 +05303493 [OMAP_DSS_VIDEO3] = "VID3",
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003494 [OMAP_DSS_WB] = "WB",
Archit Taneja4dd2da12011-08-05 19:06:01 +05303495 };
3496 const char **p_names;
3497
Archit Taneja9b372c22011-05-06 11:45:49 +05303498#define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003499
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003500 if (dispc_runtime_get())
3501 return;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003502
Archit Taneja5010be82011-08-05 19:06:00 +05303503 /* DISPC common registers */
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003504 DUMPREG(DISPC_REVISION);
3505 DUMPREG(DISPC_SYSCONFIG);
3506 DUMPREG(DISPC_SYSSTATUS);
3507 DUMPREG(DISPC_IRQSTATUS);
3508 DUMPREG(DISPC_IRQENABLE);
3509 DUMPREG(DISPC_CONTROL);
3510 DUMPREG(DISPC_CONFIG);
3511 DUMPREG(DISPC_CAPABLE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003512 DUMPREG(DISPC_LINE_STATUS);
3513 DUMPREG(DISPC_LINE_NUMBER);
Archit Taneja11354dd2011-09-26 11:47:29 +05303514 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3515 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003516 DUMPREG(DISPC_GLOBAL_ALPHA);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003517 if (dss_has_feature(FEAT_MGR_LCD2)) {
3518 DUMPREG(DISPC_CONTROL2);
3519 DUMPREG(DISPC_CONFIG2);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003520 }
Chandrabhanu Mahapatra6f1891f2012-06-21 11:23:56 +05303521 if (dss_has_feature(FEAT_MGR_LCD3)) {
3522 DUMPREG(DISPC_CONTROL3);
3523 DUMPREG(DISPC_CONFIG3);
3524 }
Tomi Valkeinen29fceee2013-11-14 11:38:25 +02003525 if (dss_has_feature(FEAT_MFLAG))
3526 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003527
Archit Taneja5010be82011-08-05 19:06:00 +05303528#undef DUMPREG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003529
Archit Taneja5010be82011-08-05 19:06:00 +05303530#define DISPC_REG(i, name) name(i)
Archit Taneja4dd2da12011-08-05 19:06:01 +05303531#define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003532 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303533 dispc_read_reg(DISPC_REG(i, r)))
3534
Archit Taneja4dd2da12011-08-05 19:06:01 +05303535 p_names = mgr_names;
Archit Taneja5010be82011-08-05 19:06:00 +05303536
Archit Taneja4dd2da12011-08-05 19:06:01 +05303537 /* DISPC channel specific registers */
3538 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3539 DUMPREG(i, DISPC_DEFAULT_COLOR);
3540 DUMPREG(i, DISPC_TRANS_COLOR);
3541 DUMPREG(i, DISPC_SIZE_MGR);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003542
Archit Taneja4dd2da12011-08-05 19:06:01 +05303543 if (i == OMAP_DSS_CHANNEL_DIGIT)
3544 continue;
Archit Taneja5010be82011-08-05 19:06:00 +05303545
Archit Taneja4dd2da12011-08-05 19:06:01 +05303546 DUMPREG(i, DISPC_TIMING_H);
3547 DUMPREG(i, DISPC_TIMING_V);
3548 DUMPREG(i, DISPC_POL_FREQ);
3549 DUMPREG(i, DISPC_DIVISORo);
Archit Taneja5010be82011-08-05 19:06:00 +05303550
Archit Taneja4dd2da12011-08-05 19:06:01 +05303551 DUMPREG(i, DISPC_DATA_CYCLE1);
3552 DUMPREG(i, DISPC_DATA_CYCLE2);
3553 DUMPREG(i, DISPC_DATA_CYCLE3);
Sumit Semwal2a205f32010-12-02 11:27:12 +00003554
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003555 if (dss_has_feature(FEAT_CPR)) {
Archit Taneja4dd2da12011-08-05 19:06:01 +05303556 DUMPREG(i, DISPC_CPR_COEF_R);
3557 DUMPREG(i, DISPC_CPR_COEF_G);
3558 DUMPREG(i, DISPC_CPR_COEF_B);
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003559 }
Sumit Semwal2a205f32010-12-02 11:27:12 +00003560 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003561
Archit Taneja4dd2da12011-08-05 19:06:01 +05303562 p_names = ovl_names;
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003563
Archit Taneja4dd2da12011-08-05 19:06:01 +05303564 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3565 DUMPREG(i, DISPC_OVL_BA0);
3566 DUMPREG(i, DISPC_OVL_BA1);
3567 DUMPREG(i, DISPC_OVL_POSITION);
3568 DUMPREG(i, DISPC_OVL_SIZE);
3569 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3570 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3571 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3572 DUMPREG(i, DISPC_OVL_ROW_INC);
3573 DUMPREG(i, DISPC_OVL_PIXEL_INC);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003574
Archit Taneja4dd2da12011-08-05 19:06:01 +05303575 if (dss_has_feature(FEAT_PRELOAD))
3576 DUMPREG(i, DISPC_OVL_PRELOAD);
Tomi Valkeinenaba837a2014-09-29 20:46:16 +00003577 if (dss_has_feature(FEAT_MFLAG))
3578 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003579
Archit Taneja4dd2da12011-08-05 19:06:01 +05303580 if (i == OMAP_DSS_GFX) {
3581 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3582 DUMPREG(i, DISPC_OVL_TABLE_BA);
3583 continue;
3584 }
3585
3586 DUMPREG(i, DISPC_OVL_FIR);
3587 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3588 DUMPREG(i, DISPC_OVL_ACCU0);
3589 DUMPREG(i, DISPC_OVL_ACCU1);
3590 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3591 DUMPREG(i, DISPC_OVL_BA0_UV);
3592 DUMPREG(i, DISPC_OVL_BA1_UV);
3593 DUMPREG(i, DISPC_OVL_FIR2);
3594 DUMPREG(i, DISPC_OVL_ACCU2_0);
3595 DUMPREG(i, DISPC_OVL_ACCU2_1);
3596 }
3597 if (dss_has_feature(FEAT_ATTR2))
3598 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
Archit Taneja5010be82011-08-05 19:06:00 +05303599 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003600
Tomi Valkeinen20efbc32015-11-04 17:10:44 +02003601 if (dispc.feat->has_writeback) {
Tomi Valkeinen06c525f2015-11-04 17:10:42 +02003602 i = OMAP_DSS_WB;
3603 DUMPREG(i, DISPC_OVL_BA0);
3604 DUMPREG(i, DISPC_OVL_BA1);
3605 DUMPREG(i, DISPC_OVL_SIZE);
3606 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3607 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3608 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3609 DUMPREG(i, DISPC_OVL_ROW_INC);
3610 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3611
3612 if (dss_has_feature(FEAT_MFLAG))
3613 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
3614
3615 DUMPREG(i, DISPC_OVL_FIR);
3616 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3617 DUMPREG(i, DISPC_OVL_ACCU0);
3618 DUMPREG(i, DISPC_OVL_ACCU1);
3619 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3620 DUMPREG(i, DISPC_OVL_BA0_UV);
3621 DUMPREG(i, DISPC_OVL_BA1_UV);
3622 DUMPREG(i, DISPC_OVL_FIR2);
3623 DUMPREG(i, DISPC_OVL_ACCU2_0);
3624 DUMPREG(i, DISPC_OVL_ACCU2_1);
3625 }
3626 if (dss_has_feature(FEAT_ATTR2))
3627 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3628 }
3629
Archit Taneja5010be82011-08-05 19:06:00 +05303630#undef DISPC_REG
3631#undef DUMPREG
3632
3633#define DISPC_REG(plane, name, i) name(plane, i)
3634#define DUMPREG(plane, name, i) \
Archit Taneja4dd2da12011-08-05 19:06:01 +05303635 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
Tomi Valkeinen311d5ce2012-09-28 13:58:14 +03003636 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
Archit Taneja5010be82011-08-05 19:06:00 +05303637 dispc_read_reg(DISPC_REG(plane, name, i)))
3638
Archit Taneja4dd2da12011-08-05 19:06:01 +05303639 /* Video pipeline coefficient registers */
Archit Taneja5010be82011-08-05 19:06:00 +05303640
Archit Taneja4dd2da12011-08-05 19:06:01 +05303641 /* start from OMAP_DSS_VIDEO1 */
3642 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3643 for (j = 0; j < 8; j++)
3644 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303645
Archit Taneja4dd2da12011-08-05 19:06:01 +05303646 for (j = 0; j < 8; j++)
3647 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
Archit Taneja5010be82011-08-05 19:06:00 +05303648
Archit Taneja4dd2da12011-08-05 19:06:01 +05303649 for (j = 0; j < 5; j++)
3650 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003651
Archit Taneja4dd2da12011-08-05 19:06:01 +05303652 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3653 for (j = 0; j < 8; j++)
3654 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3655 }
Amber Jainab5ca072011-05-19 19:47:53 +05303656
Archit Taneja4dd2da12011-08-05 19:06:01 +05303657 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3658 for (j = 0; j < 8; j++)
3659 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303660
Archit Taneja4dd2da12011-08-05 19:06:01 +05303661 for (j = 0; j < 8; j++)
3662 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
Amber Jainab5ca072011-05-19 19:47:53 +05303663
Archit Taneja4dd2da12011-08-05 19:06:01 +05303664 for (j = 0; j < 8; j++)
3665 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3666 }
Tomi Valkeinen332e9d72011-05-27 14:22:16 +03003667 }
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003668
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03003669 dispc_runtime_put();
Archit Taneja5010be82011-08-05 19:06:00 +05303670
3671#undef DISPC_REG
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003672#undef DUMPREG
3673}
3674
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003675/* calculate clock rates using dividers in cinfo */
3676int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3677 struct dispc_clock_info *cinfo)
3678{
3679 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3680 return -EINVAL;
Tomi Valkeinen9eaaf202011-08-29 15:56:04 +03003681 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003682 return -EINVAL;
3683
3684 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3685 cinfo->pck = cinfo->lck / cinfo->pck_div;
3686
3687 return 0;
3688}
3689
Tomi Valkeinen7c284e62013-03-05 16:32:08 +02003690bool dispc_div_calc(unsigned long dispc,
3691 unsigned long pck_min, unsigned long pck_max,
3692 dispc_div_calc_func func, void *data)
3693{
3694 int lckd, lckd_start, lckd_stop;
3695 int pckd, pckd_start, pckd_stop;
3696 unsigned long pck, lck;
3697 unsigned long lck_max;
3698 unsigned long pckd_hw_min, pckd_hw_max;
3699 unsigned min_fck_per_pck;
3700 unsigned long fck;
3701
3702#ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3703 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3704#else
3705 min_fck_per_pck = 0;
3706#endif
3707
3708 pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3709 pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3710
3711 lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
3712
3713 pck_min = pck_min ? pck_min : 1;
3714 pck_max = pck_max ? pck_max : ULONG_MAX;
3715
3716 lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul);
3717 lckd_stop = min(dispc / pck_min, 255ul);
3718
3719 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3720 lck = dispc / lckd;
3721
3722 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3723 pckd_stop = min(lck / pck_min, pckd_hw_max);
3724
3725 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3726 pck = lck / pckd;
3727
3728 /*
3729 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3730 * clock, which means we're configuring DISPC fclk here
3731 * also. Thus we need to use the calculated lck. For
3732 * OMAP4+ the DISPC fclk is a separate clock.
3733 */
3734 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3735 fck = dispc_core_clk_rate();
3736 else
3737 fck = lck;
3738
3739 if (fck < pck * min_fck_per_pck)
3740 continue;
3741
3742 if (func(lckd, pckd, lck, pck, data))
3743 return true;
3744 }
3745 }
3746
3747 return false;
3748}
3749
Archit Tanejaf0d08f82012-06-29 14:00:54 +05303750void dispc_mgr_set_clock_div(enum omap_channel channel,
Tomi Valkeinena8f3fcd2012-10-03 09:09:11 +02003751 const struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003752{
3753 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3754 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3755
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003756 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003757}
3758
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003759int dispc_mgr_get_clock_div(enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003760 struct dispc_clock_info *cinfo)
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003761{
3762 unsigned long fck;
3763
3764 fck = dispc_fclk_rate();
3765
Murthy, Raghuveerce7fa5e2011-03-03 09:27:59 -06003766 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3767 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003768
3769 cinfo->lck = fck / cinfo->lck_div;
3770 cinfo->pck = cinfo->lck / cinfo->pck_div;
3771
3772 return 0;
3773}
3774
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003775static u32 dispc_read_irqstatus(void)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003776{
3777 return dispc_read_reg(DISPC_IRQSTATUS);
3778}
3779
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003780static void dispc_clear_irqstatus(u32 mask)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003781{
3782 dispc_write_reg(DISPC_IRQSTATUS, mask);
3783}
3784
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003785static void dispc_write_irqenable(u32 mask)
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003786{
3787 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3788
3789 /* clear the irqstatus for newly enabled irqs */
3790 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3791
3792 dispc_write_reg(DISPC_IRQENABLE, mask);
Tomi Valkeinen2e953d82017-02-20 13:18:38 +02003793
3794 /* flush posted write */
3795 dispc_read_reg(DISPC_IRQENABLE);
Tomi Valkeinen4e0397c2012-10-10 15:13:14 +03003796}
3797
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003798void dispc_enable_sidle(void)
3799{
3800 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3801}
3802
3803void dispc_disable_sidle(void)
3804{
3805 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3806}
3807
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003808static u32 dispc_mgr_gamma_size(enum omap_channel channel)
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003809{
3810 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3811
3812 if (!dispc.feat->has_gamma_table)
3813 return 0;
3814
3815 return gdesc->len;
3816}
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003817
3818static void dispc_mgr_write_gamma_table(enum omap_channel channel)
3819{
3820 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3821 u32 *table = dispc.gamma_table[channel];
3822 unsigned int i;
3823
3824 DSSDBG("%s: channel %d\n", __func__, channel);
3825
3826 for (i = 0; i < gdesc->len; ++i) {
3827 u32 v = table[i];
3828
3829 if (gdesc->has_index)
3830 v |= i << 24;
3831 else if (i == 0)
3832 v |= 1 << 31;
3833
3834 dispc_write_reg(gdesc->reg, v);
3835 }
3836}
3837
3838static void dispc_restore_gamma_tables(void)
3839{
3840 DSSDBG("%s()\n", __func__);
3841
3842 if (!dispc.feat->has_gamma_table)
3843 return;
3844
3845 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD);
3846
3847 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_DIGIT);
3848
3849 if (dss_has_feature(FEAT_MGR_LCD2))
3850 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD2);
3851
3852 if (dss_has_feature(FEAT_MGR_LCD3))
3853 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD3);
3854}
3855
3856static const struct drm_color_lut dispc_mgr_gamma_default_lut[] = {
3857 { .red = 0, .green = 0, .blue = 0, },
3858 { .red = U16_MAX, .green = U16_MAX, .blue = U16_MAX, },
3859};
3860
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02003861static void dispc_mgr_set_gamma(enum omap_channel channel,
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003862 const struct drm_color_lut *lut,
3863 unsigned int length)
3864{
3865 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3866 u32 *table = dispc.gamma_table[channel];
3867 uint i;
3868
3869 DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__,
3870 channel, length, gdesc->len);
3871
3872 if (!dispc.feat->has_gamma_table)
3873 return;
3874
3875 if (lut == NULL || length < 2) {
3876 lut = dispc_mgr_gamma_default_lut;
3877 length = ARRAY_SIZE(dispc_mgr_gamma_default_lut);
3878 }
3879
3880 for (i = 0; i < length - 1; ++i) {
3881 uint first = i * (gdesc->len - 1) / (length - 1);
3882 uint last = (i + 1) * (gdesc->len - 1) / (length - 1);
3883 uint w = last - first;
3884 u16 r, g, b;
3885 uint j;
3886
3887 if (w == 0)
3888 continue;
3889
3890 for (j = 0; j <= w; j++) {
3891 r = (lut[i].red * (w - j) + lut[i+1].red * j) / w;
3892 g = (lut[i].green * (w - j) + lut[i+1].green * j) / w;
3893 b = (lut[i].blue * (w - j) + lut[i+1].blue * j) / w;
3894
3895 r >>= 16 - gdesc->bits;
3896 g >>= 16 - gdesc->bits;
3897 b >>= 16 - gdesc->bits;
3898
3899 table[first + j] = (r << (gdesc->bits * 2)) |
3900 (g << gdesc->bits) | b;
3901 }
3902 }
3903
3904 if (dispc.is_enabled)
3905 dispc_mgr_write_gamma_table(channel);
3906}
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003907
3908static int dispc_init_gamma_tables(void)
3909{
3910 int channel;
3911
3912 if (!dispc.feat->has_gamma_table)
3913 return 0;
3914
3915 for (channel = 0; channel < ARRAY_SIZE(dispc.gamma_table); channel++) {
3916 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3917 u32 *gt;
3918
3919 if (channel == OMAP_DSS_CHANNEL_LCD2 &&
3920 !dss_has_feature(FEAT_MGR_LCD2))
3921 continue;
3922
3923 if (channel == OMAP_DSS_CHANNEL_LCD3 &&
3924 !dss_has_feature(FEAT_MGR_LCD3))
3925 continue;
3926
3927 gt = devm_kmalloc_array(&dispc.pdev->dev, gdesc->len,
3928 sizeof(u32), GFP_KERNEL);
3929 if (!gt)
3930 return -ENOMEM;
3931
3932 dispc.gamma_table[channel] = gt;
3933
3934 dispc_mgr_set_gamma(channel, NULL, 0);
3935 }
3936 return 0;
3937}
3938
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003939static void _omap_dispc_initial_config(void)
3940{
3941 u32 l;
3942
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003943 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3944 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3945 l = dispc_read_reg(DISPC_DIVISOR);
3946 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3947 l = FLD_MOD(l, 1, 0, 0);
3948 l = FLD_MOD(l, 1, 23, 16);
3949 dispc_write_reg(DISPC_DIVISOR, l);
Tomi Valkeinen7b3926b2013-03-06 15:54:11 +02003950
3951 dispc.core_clk_rate = dispc_fclk_rate();
Murthy, Raghuveer0cf35df2011-03-03 09:28:00 -06003952 }
3953
Jyri Sarhaacc3a232016-06-07 15:09:15 +03003954 /* Use gamma table mode, instead of palette mode */
3955 if (dispc.feat->has_gamma_table)
3956 REG_FLD_MOD(DISPC_CONFIG, 1, 3, 3);
3957
3958 /* For older DSS versions (FEAT_FUNCGATED) this enables
3959 * func-clock auto-gating. For newer versions
3960 * (dispc.feat->has_gamma_table) this enables tv-out gamma tables.
3961 */
3962 if (dss_has_feature(FEAT_FUNCGATED) || dispc.feat->has_gamma_table)
Archit Taneja6ced40b2010-12-02 11:27:13 +00003963 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003964
Archit Taneja6e5264b2012-09-11 12:04:47 +05303965 dispc_setup_color_conv_coef();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003966
3967 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3968
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003969 dispc_init_fifos();
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03003970
3971 dispc_configure_burst_sizes();
Archit Taneja54128702011-09-08 11:29:17 +05303972
3973 dispc_ovl_enable_zorder_planes();
Archit Tanejad0df9a22013-03-26 19:15:25 +05303974
3975 if (dispc.feat->mstandby_workaround)
3976 REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0);
Tomi Valkeinenc64aa3a2014-09-29 20:46:18 +00003977
3978 if (dss_has_feature(FEAT_MFLAG))
3979 dispc_init_mflag();
Tomi Valkeinen80c39712009-11-12 11:41:42 +02003980}
3981
Tomi Valkeinenede92692015-06-04 14:12:16 +03003982static const struct dispc_features omap24xx_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303983 .sw_start = 5,
3984 .fp_start = 15,
3985 .bp_start = 27,
3986 .sw_max = 64,
3987 .vp_max = 255,
3988 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05303989 .mgr_width_start = 10,
3990 .mgr_height_start = 26,
3991 .mgr_width_max = 2048,
3992 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05303993 .max_lcd_pclk = 66500000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05303994 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3995 .calc_core_clk = calc_core_clk_24xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03003996 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02003997 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05303998 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03003999 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304000};
4001
Tomi Valkeinenede92692015-06-04 14:12:16 +03004002static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304003 .sw_start = 5,
4004 .fp_start = 15,
4005 .bp_start = 27,
4006 .sw_max = 64,
4007 .vp_max = 255,
4008 .hp_max = 256,
Archit Taneja33b89922012-11-14 13:50:15 +05304009 .mgr_width_start = 10,
4010 .mgr_height_start = 26,
4011 .mgr_width_max = 2048,
4012 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05304013 .max_lcd_pclk = 173000000,
4014 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304015 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4016 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004017 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02004018 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05304019 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03004020 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304021};
4022
Tomi Valkeinenede92692015-06-04 14:12:16 +03004023static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304024 .sw_start = 7,
4025 .fp_start = 19,
4026 .bp_start = 31,
4027 .sw_max = 256,
4028 .vp_max = 4095,
4029 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05304030 .mgr_width_start = 10,
4031 .mgr_height_start = 26,
4032 .mgr_width_max = 2048,
4033 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05304034 .max_lcd_pclk = 173000000,
4035 .max_tv_pclk = 59000000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304036 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4037 .calc_core_clk = calc_core_clk_34xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004038 .num_fifos = 3,
Tomi Valkeinencffa9472012-11-08 10:01:33 +02004039 .no_framedone_tv = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05304040 .set_max_preload = false,
Tomi Valkeinenf2aee312015-04-10 12:48:34 +03004041 .last_pixel_inc_missing = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304042};
4043
Tomi Valkeinenede92692015-06-04 14:12:16 +03004044static const struct dispc_features omap44xx_dispc_feats = {
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304045 .sw_start = 7,
4046 .fp_start = 19,
4047 .bp_start = 31,
4048 .sw_max = 256,
4049 .vp_max = 4095,
4050 .hp_max = 4096,
Archit Taneja33b89922012-11-14 13:50:15 +05304051 .mgr_width_start = 10,
4052 .mgr_height_start = 26,
4053 .mgr_width_max = 2048,
4054 .mgr_height_max = 2048,
Archit Tanejaca5ca692013-03-26 19:15:22 +05304055 .max_lcd_pclk = 170000000,
4056 .max_tv_pclk = 185625000,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304057 .calc_scaling = dispc_ovl_calc_scaling_44xx,
4058 .calc_core_clk = calc_core_clk_44xx,
Tomi Valkeinen42a69612012-08-22 16:56:57 +03004059 .num_fifos = 5,
Tomi Valkeinen66a0f9e2012-08-22 16:57:02 +03004060 .gfx_fifo_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05304061 .set_max_preload = true,
Tomi Valkeinene5f80912015-10-21 13:08:59 +03004062 .supports_sync_align = true,
Tomi Valkeinen20efbc32015-11-04 17:10:44 +02004063 .has_writeback = true,
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02004064 .supports_double_pixel = true,
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02004065 .reverse_ilace_field_order = true,
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004066 .has_gamma_table = true,
Jyri Sarhafbff0102016-06-07 15:09:16 +03004067 .has_gamma_i734_bug = true,
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304068};
4069
Tomi Valkeinenede92692015-06-04 14:12:16 +03004070static const struct dispc_features omap54xx_dispc_feats = {
Archit Taneja264236f2012-11-14 13:50:16 +05304071 .sw_start = 7,
4072 .fp_start = 19,
4073 .bp_start = 31,
4074 .sw_max = 256,
4075 .vp_max = 4095,
4076 .hp_max = 4096,
4077 .mgr_width_start = 11,
4078 .mgr_height_start = 27,
4079 .mgr_width_max = 4096,
4080 .mgr_height_max = 4096,
Archit Tanejaca5ca692013-03-26 19:15:22 +05304081 .max_lcd_pclk = 170000000,
4082 .max_tv_pclk = 186000000,
Archit Taneja264236f2012-11-14 13:50:16 +05304083 .calc_scaling = dispc_ovl_calc_scaling_44xx,
4084 .calc_core_clk = calc_core_clk_44xx,
4085 .num_fifos = 5,
4086 .gfx_fifo_workaround = true,
Archit Tanejad0df9a22013-03-26 19:15:25 +05304087 .mstandby_workaround = true,
Archit Taneja8bc65552013-12-17 16:40:21 +05304088 .set_max_preload = true,
Tomi Valkeinene5f80912015-10-21 13:08:59 +03004089 .supports_sync_align = true,
Tomi Valkeinen20efbc32015-11-04 17:10:44 +02004090 .has_writeback = true,
Tomi Valkeinen3a38ed532016-01-13 18:41:31 +02004091 .supports_double_pixel = true,
Tomi Valkeinenb7536d62016-01-13 18:41:36 +02004092 .reverse_ilace_field_order = true,
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004093 .has_gamma_table = true,
Jyri Sarhafbff0102016-06-07 15:09:16 +03004094 .has_gamma_i734_bug = true,
Archit Taneja264236f2012-11-14 13:50:16 +05304095};
4096
Tomi Valkeinenede92692015-06-04 14:12:16 +03004097static int dispc_init_features(struct platform_device *pdev)
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304098{
4099 const struct dispc_features *src;
4100 struct dispc_features *dst;
4101
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004102 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304103 if (!dst) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004104 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304105 return -ENOMEM;
4106 }
4107
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +03004108 switch (omapdss_get_version()) {
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004109 case OMAPDSS_VER_OMAP24xx:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304110 src = &omap24xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004111 break;
4112
4113 case OMAPDSS_VER_OMAP34xx_ES1:
4114 src = &omap34xx_rev1_0_dispc_feats;
4115 break;
4116
4117 case OMAPDSS_VER_OMAP34xx_ES3:
4118 case OMAPDSS_VER_OMAP3630:
4119 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +05304120 case OMAPDSS_VER_AM43xx:
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004121 src = &omap34xx_rev3_0_dispc_feats;
4122 break;
4123
4124 case OMAPDSS_VER_OMAP4430_ES1:
4125 case OMAPDSS_VER_OMAP4430_ES2:
4126 case OMAPDSS_VER_OMAP4:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304127 src = &omap44xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004128 break;
4129
4130 case OMAPDSS_VER_OMAP5:
Tomi Valkeinen93550922014-12-31 11:25:48 +02004131 case OMAPDSS_VER_DRA7xx:
Archit Taneja264236f2012-11-14 13:50:16 +05304132 src = &omap54xx_dispc_feats;
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004133 break;
4134
4135 default:
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304136 return -ENODEV;
4137 }
4138
4139 memcpy(dst, src, sizeof(*dst));
4140 dispc.feat = dst;
4141
4142 return 0;
4143}
4144
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004145static irqreturn_t dispc_irq_handler(int irq, void *arg)
4146{
4147 if (!dispc.is_enabled)
4148 return IRQ_NONE;
4149
4150 return dispc.user_handler(irq, dispc.user_data);
4151}
4152
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02004153static int dispc_request_irq(irq_handler_t handler, void *dev_id)
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03004154{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004155 int r;
4156
4157 if (dispc.user_handler != NULL)
4158 return -EBUSY;
4159
4160 dispc.user_handler = handler;
4161 dispc.user_data = dev_id;
4162
4163 /* ensure the dispc_irq_handler sees the values above */
4164 smp_wmb();
4165
4166 r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler,
4167 IRQF_SHARED, "OMAP DISPC", &dispc);
4168 if (r) {
4169 dispc.user_handler = NULL;
4170 dispc.user_data = NULL;
4171 }
4172
4173 return r;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03004174}
4175
Tomi Valkeinen5034b1f2015-11-05 20:06:06 +02004176static void dispc_free_irq(void *dev_id)
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03004177{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004178 devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc);
4179
4180 dispc.user_handler = NULL;
4181 dispc.user_data = NULL;
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03004182}
4183
Jyri Sarhafbff0102016-06-07 15:09:16 +03004184/*
4185 * Workaround for errata i734 in DSS dispc
4186 * - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled
4187 *
4188 * For gamma tables to work on LCD1 the GFX plane has to be used at
4189 * least once after DSS HW has come out of reset. The workaround
4190 * sets up a minimal LCD setup with GFX plane and waits for one
4191 * vertical sync irq before disabling the setup and continuing with
4192 * the context restore. The physical outputs are gated during the
4193 * operation. This workaround requires that gamma table's LOADMODE
4194 * is set to 0x2 in DISPC_CONTROL1 register.
4195 *
4196 * For details see:
4197 * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata
4198 * Literature Number: SWPZ037E
4199 * Or some other relevant errata document for the DSS IP version.
4200 */
4201
4202static const struct dispc_errata_i734_data {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03004203 struct videomode vm;
Jyri Sarhafbff0102016-06-07 15:09:16 +03004204 struct omap_overlay_info ovli;
4205 struct omap_overlay_manager_info mgri;
4206 struct dss_lcd_mgr_config lcd_conf;
4207} i734 = {
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03004208 .vm = {
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +03004209 .hactive = 8, .vactive = 1,
Jyri Sarhafbff0102016-06-07 15:09:16 +03004210 .pixelclock = 16000000,
Peter Ujfalusia85f4a82016-09-22 14:06:50 +03004211 .hsync_len = 8, .hfront_porch = 4, .hback_porch = 4,
Peter Ujfalusi458540c2016-09-22 14:06:53 +03004212 .vsync_len = 1, .vfront_porch = 1, .vback_porch = 1,
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +03004213
Peter Ujfalusi3fa3ab42016-09-22 14:06:58 +03004214 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
Peter Ujfalusid34afb72016-09-22 14:07:01 +03004215 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
4216 DISPLAY_FLAGS_PIXDATA_POSEDGE,
Jyri Sarhafbff0102016-06-07 15:09:16 +03004217 },
4218 .ovli = {
4219 .screen_width = 1,
4220 .width = 1, .height = 1,
4221 .color_mode = OMAP_DSS_COLOR_RGB24U,
4222 .rotation = OMAP_DSS_ROT_0,
4223 .rotation_type = OMAP_DSS_ROT_DMA,
4224 .mirror = 0,
4225 .pos_x = 0, .pos_y = 0,
4226 .out_width = 0, .out_height = 0,
4227 .global_alpha = 0xff,
4228 .pre_mult_alpha = 0,
4229 .zorder = 0,
4230 },
4231 .mgri = {
4232 .default_color = 0,
4233 .trans_enabled = false,
4234 .partial_alpha_enabled = false,
4235 .cpr_enable = false,
4236 },
4237 .lcd_conf = {
4238 .io_pad_mode = DSS_IO_PAD_MODE_BYPASS,
4239 .stallmode = false,
4240 .fifohandcheck = false,
4241 .clock_info = {
4242 .lck_div = 1,
4243 .pck_div = 2,
4244 },
4245 .video_port_width = 24,
4246 .lcden_sig_polarity = 0,
4247 },
4248};
4249
4250static struct i734_buf {
4251 size_t size;
4252 dma_addr_t paddr;
4253 void *vaddr;
4254} i734_buf;
4255
4256static int dispc_errata_i734_wa_init(void)
4257{
4258 if (!dispc.feat->has_gamma_i734_bug)
4259 return 0;
4260
4261 i734_buf.size = i734.ovli.width * i734.ovli.height *
4262 color_mode_to_bpp(i734.ovli.color_mode) / 8;
4263
4264 i734_buf.vaddr = dma_alloc_writecombine(&dispc.pdev->dev, i734_buf.size,
4265 &i734_buf.paddr, GFP_KERNEL);
4266 if (!i734_buf.vaddr) {
4267 dev_err(&dispc.pdev->dev, "%s: dma_alloc_writecombine failed",
4268 __func__);
4269 return -ENOMEM;
4270 }
4271
4272 return 0;
4273}
4274
4275static void dispc_errata_i734_wa_fini(void)
4276{
4277 if (!dispc.feat->has_gamma_i734_bug)
4278 return;
4279
4280 dma_free_writecombine(&dispc.pdev->dev, i734_buf.size, i734_buf.vaddr,
4281 i734_buf.paddr);
4282}
4283
4284static void dispc_errata_i734_wa(void)
4285{
4286 u32 framedone_irq = dispc_mgr_get_framedone_irq(OMAP_DSS_CHANNEL_LCD);
4287 struct omap_overlay_info ovli;
4288 struct dss_lcd_mgr_config lcd_conf;
4289 u32 gatestate;
4290 unsigned int count;
4291
4292 if (!dispc.feat->has_gamma_i734_bug)
4293 return;
4294
4295 gatestate = REG_GET(DISPC_CONFIG, 8, 4);
4296
4297 ovli = i734.ovli;
4298 ovli.paddr = i734_buf.paddr;
4299 lcd_conf = i734.lcd_conf;
4300
4301 /* Gate all LCD1 outputs */
4302 REG_FLD_MOD(DISPC_CONFIG, 0x1f, 8, 4);
4303
4304 /* Setup and enable GFX plane */
Tomi Valkeinen49a30572017-02-17 12:30:07 +02004305 dispc_ovl_setup(OMAP_DSS_GFX, &ovli, &i734.vm, false,
4306 OMAP_DSS_CHANNEL_LCD);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004307 dispc_ovl_enable(OMAP_DSS_GFX, true);
4308
4309 /* Set up and enable display manager for LCD1 */
4310 dispc_mgr_setup(OMAP_DSS_CHANNEL_LCD, &i734.mgri);
4311 dispc_calc_clock_rates(dss_get_dispc_clk_rate(),
4312 &lcd_conf.clock_info);
4313 dispc_mgr_set_lcd_config(OMAP_DSS_CHANNEL_LCD, &lcd_conf);
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +03004314 dispc_mgr_set_timings(OMAP_DSS_CHANNEL_LCD, &i734.vm);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004315
4316 dispc_clear_irqstatus(framedone_irq);
4317
4318 /* Enable and shut the channel to produce just one frame */
4319 dispc_mgr_enable(OMAP_DSS_CHANNEL_LCD, true);
4320 dispc_mgr_enable(OMAP_DSS_CHANNEL_LCD, false);
4321
4322 /* Busy wait for framedone. We can't fiddle with irq handlers
4323 * in PM resume. Typically the loop runs less than 5 times and
4324 * waits less than a micro second.
4325 */
4326 count = 0;
4327 while (!(dispc_read_irqstatus() & framedone_irq)) {
4328 if (count++ > 10000) {
4329 dev_err(&dispc.pdev->dev, "%s: framedone timeout\n",
4330 __func__);
4331 break;
4332 }
4333 }
4334 dispc_ovl_enable(OMAP_DSS_GFX, false);
4335
4336 /* Clear all irq bits before continuing */
4337 dispc_clear_irqstatus(0xffffffff);
4338
4339 /* Restore the original state to LCD1 output gates */
4340 REG_FLD_MOD(DISPC_CONFIG, gatestate, 8, 4);
4341}
4342
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004343static const struct dispc_ops dispc_ops = {
4344 .read_irqstatus = dispc_read_irqstatus,
4345 .clear_irqstatus = dispc_clear_irqstatus,
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004346 .write_irqenable = dispc_write_irqenable,
4347
4348 .request_irq = dispc_request_irq,
4349 .free_irq = dispc_free_irq,
4350
4351 .runtime_get = dispc_runtime_get,
4352 .runtime_put = dispc_runtime_put,
4353
4354 .get_num_ovls = dispc_get_num_ovls,
4355 .get_num_mgrs = dispc_get_num_mgrs,
4356
4357 .mgr_enable = dispc_mgr_enable,
4358 .mgr_is_enabled = dispc_mgr_is_enabled,
4359 .mgr_get_vsync_irq = dispc_mgr_get_vsync_irq,
4360 .mgr_get_framedone_irq = dispc_mgr_get_framedone_irq,
4361 .mgr_get_sync_lost_irq = dispc_mgr_get_sync_lost_irq,
4362 .mgr_go_busy = dispc_mgr_go_busy,
4363 .mgr_go = dispc_mgr_go,
4364 .mgr_set_lcd_config = dispc_mgr_set_lcd_config,
4365 .mgr_set_timings = dispc_mgr_set_timings,
4366 .mgr_setup = dispc_mgr_setup,
4367 .mgr_get_supported_outputs = dispc_mgr_get_supported_outputs,
4368 .mgr_gamma_size = dispc_mgr_gamma_size,
4369 .mgr_set_gamma = dispc_mgr_set_gamma,
4370
4371 .ovl_enable = dispc_ovl_enable,
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004372 .ovl_setup = dispc_ovl_setup,
4373 .ovl_get_color_modes = dispc_ovl_get_color_modes,
4374};
4375
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004376/* DISPC HW IP initialisation */
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004377static int dispc_bind(struct device *dev, struct device *master, void *data)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004378{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004379 struct platform_device *pdev = to_platform_device(dev);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004380 u32 rev;
archit tanejaaffe3602011-02-23 08:41:03 +00004381 int r = 0;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004382 struct resource *dispc_mem;
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004383 struct device_node *np = pdev->dev.of_node;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004384
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004385 dispc.pdev = pdev;
4386
Tomi Valkeinend49cd152014-11-10 12:23:00 +02004387 spin_lock_init(&dispc.control_lock);
4388
Tomi Valkeinen84b476232012-09-28 12:54:03 +03004389 r = dispc_init_features(dispc.pdev);
Chandrabhanu Mahapatradcbe7652012-07-03 12:26:51 +05304390 if (r)
4391 return r;
4392
Jyri Sarhafbff0102016-06-07 15:09:16 +03004393 r = dispc_errata_i734_wa_init();
4394 if (r)
4395 return r;
4396
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004397 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
Laurent Pinchartb22622f2017-05-07 00:29:09 +03004398 dispc.base = devm_ioremap_resource(&pdev->dev, dispc_mem);
4399 if (IS_ERR(dispc.base))
4400 return PTR_ERR(dispc.base);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004401
archit tanejaaffe3602011-02-23 08:41:03 +00004402 dispc.irq = platform_get_irq(dispc.pdev, 0);
4403 if (dispc.irq < 0) {
4404 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02004405 return -ENODEV;
archit tanejaaffe3602011-02-23 08:41:03 +00004406 }
4407
Tomi Valkeinen0006fd62014-09-05 19:15:03 +00004408 if (np && of_property_read_bool(np, "syscon-pol")) {
4409 dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
4410 if (IS_ERR(dispc.syscon_pol)) {
4411 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
4412 return PTR_ERR(dispc.syscon_pol);
4413 }
4414
4415 if (of_property_read_u32_index(np, "syscon-pol", 1,
4416 &dispc.syscon_pol_offset)) {
4417 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
4418 return -EINVAL;
4419 }
4420 }
4421
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004422 r = dispc_init_gamma_tables();
4423 if (r)
4424 return r;
4425
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004426 pm_runtime_enable(&pdev->dev);
4427
4428 r = dispc_runtime_get();
4429 if (r)
4430 goto err_runtime_get;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004431
4432 _omap_dispc_initial_config();
4433
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004434 rev = dispc_read_reg(DISPC_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00004435 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004436 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4437
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004438 dispc_runtime_put();
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004439
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004440 dispc_set_ops(&dispc_ops);
4441
Tomi Valkeinene40402c2012-03-02 18:01:07 +02004442 dss_debugfs_create_file("dispc", dispc_dump_regs);
4443
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004444 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004445
4446err_runtime_get:
4447 pm_runtime_disable(&pdev->dev);
archit tanejaaffe3602011-02-23 08:41:03 +00004448 return r;
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004449}
4450
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004451static void dispc_unbind(struct device *dev, struct device *master,
4452 void *data)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004453{
Tomi Valkeinena1a376472015-11-05 19:44:38 +02004454 dispc_set_ops(NULL);
4455
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004456 pm_runtime_disable(dev);
Jyri Sarhafbff0102016-06-07 15:09:16 +03004457
4458 dispc_errata_i734_wa_fini();
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004459}
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +03004460
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004461static const struct component_ops dispc_component_ops = {
4462 .bind = dispc_bind,
4463 .unbind = dispc_unbind,
4464};
4465
4466static int dispc_probe(struct platform_device *pdev)
4467{
4468 return component_add(&pdev->dev, &dispc_component_ops);
4469}
4470
4471static int dispc_remove(struct platform_device *pdev)
4472{
4473 component_del(&pdev->dev, &dispc_component_ops);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004474 return 0;
4475}
4476
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004477static int dispc_runtime_suspend(struct device *dev)
4478{
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004479 dispc.is_enabled = false;
4480 /* ensure the dispc_irq_handler sees the is_enabled value */
4481 smp_wmb();
4482 /* wait for current handler to finish before turning the DISPC off */
4483 synchronize_irq(dispc.irq);
4484
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004485 dispc_save_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004486
4487 return 0;
4488}
4489
4490static int dispc_runtime_resume(struct device *dev)
4491{
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004492 /*
4493 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4494 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4495 * _omap_dispc_initial_config(). We can thus use it to detect if
4496 * we have lost register context.
4497 */
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004498 if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
4499 _omap_dispc_initial_config();
Tomi Valkeinen9229b512014-02-14 09:37:09 +02004500
Jyri Sarhafbff0102016-06-07 15:09:16 +03004501 dispc_errata_i734_wa();
4502
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004503 dispc_restore_context();
Jyri Sarhaacc3a232016-06-07 15:09:15 +03004504
4505 dispc_restore_gamma_tables();
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004506 }
Tomi Valkeinenbe07dcd72013-11-21 16:01:40 +02004507
Tomi Valkeinen0925afc2014-04-11 13:49:55 +03004508 dispc.is_enabled = true;
4509 /* ensure the dispc_irq_handler sees the is_enabled value */
4510 smp_wmb();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004511
4512 return 0;
4513}
4514
4515static const struct dev_pm_ops dispc_pm_ops = {
4516 .runtime_suspend = dispc_runtime_suspend,
4517 .runtime_resume = dispc_runtime_resume,
4518};
4519
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004520static const struct of_device_id dispc_of_match[] = {
4521 { .compatible = "ti,omap2-dispc", },
4522 { .compatible = "ti,omap3-dispc", },
4523 { .compatible = "ti,omap4-dispc", },
Tomi Valkeinen2e7e6b62014-04-16 13:16:43 +03004524 { .compatible = "ti,omap5-dispc", },
Tomi Valkeinen93550922014-12-31 11:25:48 +02004525 { .compatible = "ti,dra7-dispc", },
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004526 {},
4527};
4528
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004529static struct platform_driver omap_dispchw_driver = {
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004530 .probe = dispc_probe,
4531 .remove = dispc_remove,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004532 .driver = {
4533 .name = "omapdss_dispc",
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004534 .pm = &dispc_pm_ops,
Tomi Valkeinend7977f82013-12-17 11:54:02 +02004535 .of_match_table = dispc_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +03004536 .suppress_bind_attrs = true,
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004537 },
4538};
4539
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02004540int __init dispc_init_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004541{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03004542 return platform_driver_register(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004543}
4544
Tomi Valkeinenede92692015-06-04 14:12:16 +03004545void dispc_uninit_platform_driver(void)
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004546{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02004547 platform_driver_unregister(&omap_dispchw_driver);
Senthilvadivu Guruswamy060b6d92011-01-24 06:22:00 +00004548}