1caab277bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2f76ee892STomi Valkeinen /*
3f76ee892STomi Valkeinen * linux/drivers/video/omap2/dss/dispc.c
4f76ee892STomi Valkeinen *
5f76ee892STomi Valkeinen * Copyright (C) 2009 Nokia Corporation
6f76ee892STomi Valkeinen * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7f76ee892STomi Valkeinen *
8f76ee892STomi Valkeinen * Some code and ideas taken from drivers/video/omap/ driver
9f76ee892STomi Valkeinen * by Imre Deak.
10f76ee892STomi Valkeinen */
11f76ee892STomi Valkeinen
12f76ee892STomi Valkeinen #define DSS_SUBSYS_NAME "DISPC"
13f76ee892STomi Valkeinen
14f76ee892STomi Valkeinen #include <linux/kernel.h>
15f76ee892STomi Valkeinen #include <linux/dma-mapping.h>
16f76ee892STomi Valkeinen #include <linux/vmalloc.h>
17f76ee892STomi Valkeinen #include <linux/export.h>
18f76ee892STomi Valkeinen #include <linux/clk.h>
19f76ee892STomi Valkeinen #include <linux/io.h>
20f76ee892STomi Valkeinen #include <linux/jiffies.h>
21f76ee892STomi Valkeinen #include <linux/seq_file.h>
22f76ee892STomi Valkeinen #include <linux/delay.h>
23f76ee892STomi Valkeinen #include <linux/workqueue.h>
24f76ee892STomi Valkeinen #include <linux/hardirq.h>
25f76ee892STomi Valkeinen #include <linux/platform_device.h>
26f76ee892STomi Valkeinen #include <linux/pm_runtime.h>
27f76ee892STomi Valkeinen #include <linux/sizes.h>
28f76ee892STomi Valkeinen #include <linux/mfd/syscon.h>
29f76ee892STomi Valkeinen #include <linux/regmap.h>
30f76ee892STomi Valkeinen #include <linux/of.h>
31f76ee892STomi Valkeinen #include <linux/component.h>
32f76ee892STomi Valkeinen
3362d9e44eSPeter Ujfalusi #include <video/omapfb_dss.h>
34f76ee892STomi Valkeinen
35f76ee892STomi Valkeinen #include "dss.h"
36f76ee892STomi Valkeinen #include "dss_features.h"
37f76ee892STomi Valkeinen #include "dispc.h"
38f76ee892STomi Valkeinen
39f76ee892STomi Valkeinen /* DISPC */
40f76ee892STomi Valkeinen #define DISPC_SZ_REGS SZ_4K
41f76ee892STomi Valkeinen
42f76ee892STomi Valkeinen enum omap_burst_size {
43f76ee892STomi Valkeinen BURST_SIZE_X2 = 0,
44f76ee892STomi Valkeinen BURST_SIZE_X4 = 1,
45f76ee892STomi Valkeinen BURST_SIZE_X8 = 2,
46f76ee892STomi Valkeinen };
47f76ee892STomi Valkeinen
48f76ee892STomi Valkeinen #define REG_GET(idx, start, end) \
49f76ee892STomi Valkeinen FLD_GET(dispc_read_reg(idx), start, end)
50f76ee892STomi Valkeinen
51f76ee892STomi Valkeinen #define REG_FLD_MOD(idx, val, start, end) \
52f76ee892STomi Valkeinen dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
53f76ee892STomi Valkeinen
54f76ee892STomi Valkeinen struct dispc_features {
55f76ee892STomi Valkeinen u8 sw_start;
56f76ee892STomi Valkeinen u8 fp_start;
57f76ee892STomi Valkeinen u8 bp_start;
58f76ee892STomi Valkeinen u16 sw_max;
59f76ee892STomi Valkeinen u16 vp_max;
60f76ee892STomi Valkeinen u16 hp_max;
61f76ee892STomi Valkeinen u8 mgr_width_start;
62f76ee892STomi Valkeinen u8 mgr_height_start;
63f76ee892STomi Valkeinen u16 mgr_width_max;
64f76ee892STomi Valkeinen u16 mgr_height_max;
65f76ee892STomi Valkeinen unsigned long max_lcd_pclk;
66f76ee892STomi Valkeinen unsigned long max_tv_pclk;
67f76ee892STomi Valkeinen int (*calc_scaling) (unsigned long pclk, unsigned long lclk,
68f76ee892STomi Valkeinen const struct omap_video_timings *mgr_timings,
69f76ee892STomi Valkeinen u16 width, u16 height, u16 out_width, u16 out_height,
70f76ee892STomi Valkeinen enum omap_color_mode color_mode, bool *five_taps,
71f76ee892STomi Valkeinen int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
72f76ee892STomi Valkeinen u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
73f76ee892STomi Valkeinen unsigned long (*calc_core_clk) (unsigned long pclk,
74f76ee892STomi Valkeinen u16 width, u16 height, u16 out_width, u16 out_height,
75f76ee892STomi Valkeinen bool mem_to_mem);
76f76ee892STomi Valkeinen u8 num_fifos;
77f76ee892STomi Valkeinen
78f76ee892STomi Valkeinen /* swap GFX & WB fifos */
79f76ee892STomi Valkeinen bool gfx_fifo_workaround:1;
80f76ee892STomi Valkeinen
81f76ee892STomi Valkeinen /* no DISPC_IRQ_FRAMEDONETV on this SoC */
82f76ee892STomi Valkeinen bool no_framedone_tv:1;
83f76ee892STomi Valkeinen
84f76ee892STomi Valkeinen /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
85f76ee892STomi Valkeinen bool mstandby_workaround:1;
86f76ee892STomi Valkeinen
87f76ee892STomi Valkeinen bool set_max_preload:1;
88f76ee892STomi Valkeinen
89f76ee892STomi Valkeinen /* PIXEL_INC is not added to the last pixel of a line */
90f76ee892STomi Valkeinen bool last_pixel_inc_missing:1;
91f76ee892STomi Valkeinen
92f76ee892STomi Valkeinen /* POL_FREQ has ALIGN bit */
93f76ee892STomi Valkeinen bool supports_sync_align:1;
94f76ee892STomi Valkeinen
95f76ee892STomi Valkeinen bool has_writeback:1;
96f76ee892STomi Valkeinen };
97f76ee892STomi Valkeinen
98f76ee892STomi Valkeinen #define DISPC_MAX_NR_FIFOS 5
99f76ee892STomi Valkeinen
100f76ee892STomi Valkeinen static struct {
101f76ee892STomi Valkeinen struct platform_device *pdev;
102f76ee892STomi Valkeinen void __iomem *base;
103f76ee892STomi Valkeinen
104f76ee892STomi Valkeinen int irq;
105f76ee892STomi Valkeinen irq_handler_t user_handler;
106f76ee892STomi Valkeinen void *user_data;
107f76ee892STomi Valkeinen
108f76ee892STomi Valkeinen unsigned long core_clk_rate;
109f76ee892STomi Valkeinen unsigned long tv_pclk_rate;
110f76ee892STomi Valkeinen
111f76ee892STomi Valkeinen u32 fifo_size[DISPC_MAX_NR_FIFOS];
112f76ee892STomi Valkeinen /* maps which plane is using a fifo. fifo-id -> plane-id */
113f76ee892STomi Valkeinen int fifo_assignment[DISPC_MAX_NR_FIFOS];
114f76ee892STomi Valkeinen
115f76ee892STomi Valkeinen bool ctx_valid;
116f76ee892STomi Valkeinen u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
117f76ee892STomi Valkeinen
118f76ee892STomi Valkeinen const struct dispc_features *feat;
119f76ee892STomi Valkeinen
120f76ee892STomi Valkeinen bool is_enabled;
121f76ee892STomi Valkeinen
122f76ee892STomi Valkeinen struct regmap *syscon_pol;
123f76ee892STomi Valkeinen u32 syscon_pol_offset;
124f76ee892STomi Valkeinen
125f76ee892STomi Valkeinen /* DISPC_CONTROL & DISPC_CONFIG lock*/
126f76ee892STomi Valkeinen spinlock_t control_lock;
127f76ee892STomi Valkeinen } dispc;
128f76ee892STomi Valkeinen
129f76ee892STomi Valkeinen enum omap_color_component {
130f76ee892STomi Valkeinen /* used for all color formats for OMAP3 and earlier
131f76ee892STomi Valkeinen * and for RGB and Y color component on OMAP4
132f76ee892STomi Valkeinen */
133f76ee892STomi Valkeinen DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
134f76ee892STomi Valkeinen /* used for UV component for
135f76ee892STomi Valkeinen * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
136f76ee892STomi Valkeinen * color formats on OMAP4
137f76ee892STomi Valkeinen */
138f76ee892STomi Valkeinen DISPC_COLOR_COMPONENT_UV = 1 << 1,
139f76ee892STomi Valkeinen };
140f76ee892STomi Valkeinen
141f76ee892STomi Valkeinen enum mgr_reg_fields {
142f76ee892STomi Valkeinen DISPC_MGR_FLD_ENABLE,
143f76ee892STomi Valkeinen DISPC_MGR_FLD_STNTFT,
144f76ee892STomi Valkeinen DISPC_MGR_FLD_GO,
145f76ee892STomi Valkeinen DISPC_MGR_FLD_TFTDATALINES,
146f76ee892STomi Valkeinen DISPC_MGR_FLD_STALLMODE,
147f76ee892STomi Valkeinen DISPC_MGR_FLD_TCKENABLE,
148f76ee892STomi Valkeinen DISPC_MGR_FLD_TCKSELECTION,
149f76ee892STomi Valkeinen DISPC_MGR_FLD_CPR,
150f76ee892STomi Valkeinen DISPC_MGR_FLD_FIFOHANDCHECK,
151f76ee892STomi Valkeinen /* used to maintain a count of the above fields */
152f76ee892STomi Valkeinen DISPC_MGR_FLD_NUM,
153f76ee892STomi Valkeinen };
154f76ee892STomi Valkeinen
155f76ee892STomi Valkeinen struct dispc_reg_field {
156f76ee892STomi Valkeinen u16 reg;
157f76ee892STomi Valkeinen u8 high;
158f76ee892STomi Valkeinen u8 low;
159f76ee892STomi Valkeinen };
160f76ee892STomi Valkeinen
161f76ee892STomi Valkeinen static const struct {
162f76ee892STomi Valkeinen const char *name;
163f76ee892STomi Valkeinen u32 vsync_irq;
164f76ee892STomi Valkeinen u32 framedone_irq;
165f76ee892STomi Valkeinen u32 sync_lost_irq;
166f76ee892STomi Valkeinen struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
167f76ee892STomi Valkeinen } mgr_desc[] = {
168f76ee892STomi Valkeinen [OMAP_DSS_CHANNEL_LCD] = {
169f76ee892STomi Valkeinen .name = "LCD",
170f76ee892STomi Valkeinen .vsync_irq = DISPC_IRQ_VSYNC,
171f76ee892STomi Valkeinen .framedone_irq = DISPC_IRQ_FRAMEDONE,
172f76ee892STomi Valkeinen .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
173f76ee892STomi Valkeinen .reg_desc = {
174f76ee892STomi Valkeinen [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
175f76ee892STomi Valkeinen [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
176f76ee892STomi Valkeinen [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
177f76ee892STomi Valkeinen [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
178f76ee892STomi Valkeinen [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
179f76ee892STomi Valkeinen [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
180f76ee892STomi Valkeinen [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
181f76ee892STomi Valkeinen [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
182f76ee892STomi Valkeinen [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
183f76ee892STomi Valkeinen },
184f76ee892STomi Valkeinen },
185f76ee892STomi Valkeinen [OMAP_DSS_CHANNEL_DIGIT] = {
186f76ee892STomi Valkeinen .name = "DIGIT",
187f76ee892STomi Valkeinen .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
188f76ee892STomi Valkeinen .framedone_irq = DISPC_IRQ_FRAMEDONETV,
189f76ee892STomi Valkeinen .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
190f76ee892STomi Valkeinen .reg_desc = {
191f76ee892STomi Valkeinen [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
192f76ee892STomi Valkeinen [DISPC_MGR_FLD_STNTFT] = { },
193f76ee892STomi Valkeinen [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
194f76ee892STomi Valkeinen [DISPC_MGR_FLD_TFTDATALINES] = { },
195f76ee892STomi Valkeinen [DISPC_MGR_FLD_STALLMODE] = { },
196f76ee892STomi Valkeinen [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
197f76ee892STomi Valkeinen [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
198f76ee892STomi Valkeinen [DISPC_MGR_FLD_CPR] = { },
199f76ee892STomi Valkeinen [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
200f76ee892STomi Valkeinen },
201f76ee892STomi Valkeinen },
202f76ee892STomi Valkeinen [OMAP_DSS_CHANNEL_LCD2] = {
203f76ee892STomi Valkeinen .name = "LCD2",
204f76ee892STomi Valkeinen .vsync_irq = DISPC_IRQ_VSYNC2,
205f76ee892STomi Valkeinen .framedone_irq = DISPC_IRQ_FRAMEDONE2,
206f76ee892STomi Valkeinen .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
207f76ee892STomi Valkeinen .reg_desc = {
208f76ee892STomi Valkeinen [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
209f76ee892STomi Valkeinen [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
210f76ee892STomi Valkeinen [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
211f76ee892STomi Valkeinen [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
212f76ee892STomi Valkeinen [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
213f76ee892STomi Valkeinen [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
214f76ee892STomi Valkeinen [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
215f76ee892STomi Valkeinen [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
216f76ee892STomi Valkeinen [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
217f76ee892STomi Valkeinen },
218f76ee892STomi Valkeinen },
219f76ee892STomi Valkeinen [OMAP_DSS_CHANNEL_LCD3] = {
220f76ee892STomi Valkeinen .name = "LCD3",
221f76ee892STomi Valkeinen .vsync_irq = DISPC_IRQ_VSYNC3,
222f76ee892STomi Valkeinen .framedone_irq = DISPC_IRQ_FRAMEDONE3,
223f76ee892STomi Valkeinen .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
224f76ee892STomi Valkeinen .reg_desc = {
225f76ee892STomi Valkeinen [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
226f76ee892STomi Valkeinen [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
227f76ee892STomi Valkeinen [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
228f76ee892STomi Valkeinen [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
229f76ee892STomi Valkeinen [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
230f76ee892STomi Valkeinen [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
231f76ee892STomi Valkeinen [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
232f76ee892STomi Valkeinen [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
233f76ee892STomi Valkeinen [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
234f76ee892STomi Valkeinen },
235f76ee892STomi Valkeinen },
236f76ee892STomi Valkeinen };
237f76ee892STomi Valkeinen
238f76ee892STomi Valkeinen struct color_conv_coef {
239f76ee892STomi Valkeinen int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
240f76ee892STomi Valkeinen int full_range;
241f76ee892STomi Valkeinen };
242f76ee892STomi Valkeinen
243f76ee892STomi Valkeinen static unsigned long dispc_fclk_rate(void);
244f76ee892STomi Valkeinen static unsigned long dispc_core_clk_rate(void);
245f76ee892STomi Valkeinen static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel);
246f76ee892STomi Valkeinen static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel);
247f76ee892STomi Valkeinen
248f76ee892STomi Valkeinen static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
249f76ee892STomi Valkeinen static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
250f76ee892STomi Valkeinen
dispc_write_reg(const u16 idx,u32 val)251f76ee892STomi Valkeinen static inline void dispc_write_reg(const u16 idx, u32 val)
252f76ee892STomi Valkeinen {
253f76ee892STomi Valkeinen __raw_writel(val, dispc.base + idx);
254f76ee892STomi Valkeinen }
255f76ee892STomi Valkeinen
dispc_read_reg(const u16 idx)256f76ee892STomi Valkeinen static inline u32 dispc_read_reg(const u16 idx)
257f76ee892STomi Valkeinen {
258f76ee892STomi Valkeinen return __raw_readl(dispc.base + idx);
259f76ee892STomi Valkeinen }
260f76ee892STomi Valkeinen
mgr_fld_read(enum omap_channel channel,enum mgr_reg_fields regfld)261f76ee892STomi Valkeinen static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
262f76ee892STomi Valkeinen {
263f76ee892STomi Valkeinen const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
264f76ee892STomi Valkeinen return REG_GET(rfld.reg, rfld.high, rfld.low);
265f76ee892STomi Valkeinen }
266f76ee892STomi Valkeinen
mgr_fld_write(enum omap_channel channel,enum mgr_reg_fields regfld,int val)267f76ee892STomi Valkeinen static void mgr_fld_write(enum omap_channel channel,
268f76ee892STomi Valkeinen enum mgr_reg_fields regfld, int val) {
269f76ee892STomi Valkeinen const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
270f76ee892STomi Valkeinen const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG;
271f76ee892STomi Valkeinen unsigned long flags;
272f76ee892STomi Valkeinen
273f76ee892STomi Valkeinen if (need_lock)
274f76ee892STomi Valkeinen spin_lock_irqsave(&dispc.control_lock, flags);
275f76ee892STomi Valkeinen
276f76ee892STomi Valkeinen REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
277f76ee892STomi Valkeinen
278f76ee892STomi Valkeinen if (need_lock)
279f76ee892STomi Valkeinen spin_unlock_irqrestore(&dispc.control_lock, flags);
280f76ee892STomi Valkeinen }
281f76ee892STomi Valkeinen
282f76ee892STomi Valkeinen #define SR(reg) \
283f76ee892STomi Valkeinen dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
284f76ee892STomi Valkeinen #define RR(reg) \
285f76ee892STomi Valkeinen dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
286f76ee892STomi Valkeinen
dispc_save_context(void)287f76ee892STomi Valkeinen static void dispc_save_context(void)
288f76ee892STomi Valkeinen {
289f76ee892STomi Valkeinen int i, j;
290f76ee892STomi Valkeinen
291f76ee892STomi Valkeinen DSSDBG("dispc_save_context\n");
292f76ee892STomi Valkeinen
293f76ee892STomi Valkeinen SR(IRQENABLE);
294f76ee892STomi Valkeinen SR(CONTROL);
295f76ee892STomi Valkeinen SR(CONFIG);
296f76ee892STomi Valkeinen SR(LINE_NUMBER);
297f76ee892STomi Valkeinen if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
298f76ee892STomi Valkeinen dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
299f76ee892STomi Valkeinen SR(GLOBAL_ALPHA);
300f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD2)) {
301f76ee892STomi Valkeinen SR(CONTROL2);
302f76ee892STomi Valkeinen SR(CONFIG2);
303f76ee892STomi Valkeinen }
304f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD3)) {
305f76ee892STomi Valkeinen SR(CONTROL3);
306f76ee892STomi Valkeinen SR(CONFIG3);
307f76ee892STomi Valkeinen }
308f76ee892STomi Valkeinen
309f76ee892STomi Valkeinen for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
310f76ee892STomi Valkeinen SR(DEFAULT_COLOR(i));
311f76ee892STomi Valkeinen SR(TRANS_COLOR(i));
312f76ee892STomi Valkeinen SR(SIZE_MGR(i));
313f76ee892STomi Valkeinen if (i == OMAP_DSS_CHANNEL_DIGIT)
314f76ee892STomi Valkeinen continue;
315f76ee892STomi Valkeinen SR(TIMING_H(i));
316f76ee892STomi Valkeinen SR(TIMING_V(i));
317f76ee892STomi Valkeinen SR(POL_FREQ(i));
318f76ee892STomi Valkeinen SR(DIVISORo(i));
319f76ee892STomi Valkeinen
320f76ee892STomi Valkeinen SR(DATA_CYCLE1(i));
321f76ee892STomi Valkeinen SR(DATA_CYCLE2(i));
322f76ee892STomi Valkeinen SR(DATA_CYCLE3(i));
323f76ee892STomi Valkeinen
324f76ee892STomi Valkeinen if (dss_has_feature(FEAT_CPR)) {
325f76ee892STomi Valkeinen SR(CPR_COEF_R(i));
326f76ee892STomi Valkeinen SR(CPR_COEF_G(i));
327f76ee892STomi Valkeinen SR(CPR_COEF_B(i));
328f76ee892STomi Valkeinen }
329f76ee892STomi Valkeinen }
330f76ee892STomi Valkeinen
331f76ee892STomi Valkeinen for (i = 0; i < dss_feat_get_num_ovls(); i++) {
332f76ee892STomi Valkeinen SR(OVL_BA0(i));
333f76ee892STomi Valkeinen SR(OVL_BA1(i));
334f76ee892STomi Valkeinen SR(OVL_POSITION(i));
335f76ee892STomi Valkeinen SR(OVL_SIZE(i));
336f76ee892STomi Valkeinen SR(OVL_ATTRIBUTES(i));
337f76ee892STomi Valkeinen SR(OVL_FIFO_THRESHOLD(i));
338f76ee892STomi Valkeinen SR(OVL_ROW_INC(i));
339f76ee892STomi Valkeinen SR(OVL_PIXEL_INC(i));
340f76ee892STomi Valkeinen if (dss_has_feature(FEAT_PRELOAD))
341f76ee892STomi Valkeinen SR(OVL_PRELOAD(i));
342f76ee892STomi Valkeinen if (i == OMAP_DSS_GFX) {
343f76ee892STomi Valkeinen SR(OVL_WINDOW_SKIP(i));
344f76ee892STomi Valkeinen SR(OVL_TABLE_BA(i));
345f76ee892STomi Valkeinen continue;
346f76ee892STomi Valkeinen }
347f76ee892STomi Valkeinen SR(OVL_FIR(i));
348f76ee892STomi Valkeinen SR(OVL_PICTURE_SIZE(i));
349f76ee892STomi Valkeinen SR(OVL_ACCU0(i));
350f76ee892STomi Valkeinen SR(OVL_ACCU1(i));
351f76ee892STomi Valkeinen
352f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
353f76ee892STomi Valkeinen SR(OVL_FIR_COEF_H(i, j));
354f76ee892STomi Valkeinen
355f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
356f76ee892STomi Valkeinen SR(OVL_FIR_COEF_HV(i, j));
357f76ee892STomi Valkeinen
358f76ee892STomi Valkeinen for (j = 0; j < 5; j++)
359f76ee892STomi Valkeinen SR(OVL_CONV_COEF(i, j));
360f76ee892STomi Valkeinen
361f76ee892STomi Valkeinen if (dss_has_feature(FEAT_FIR_COEF_V)) {
362f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
363f76ee892STomi Valkeinen SR(OVL_FIR_COEF_V(i, j));
364f76ee892STomi Valkeinen }
365f76ee892STomi Valkeinen
366f76ee892STomi Valkeinen if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
367f76ee892STomi Valkeinen SR(OVL_BA0_UV(i));
368f76ee892STomi Valkeinen SR(OVL_BA1_UV(i));
369f76ee892STomi Valkeinen SR(OVL_FIR2(i));
370f76ee892STomi Valkeinen SR(OVL_ACCU2_0(i));
371f76ee892STomi Valkeinen SR(OVL_ACCU2_1(i));
372f76ee892STomi Valkeinen
373f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
374f76ee892STomi Valkeinen SR(OVL_FIR_COEF_H2(i, j));
375f76ee892STomi Valkeinen
376f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
377f76ee892STomi Valkeinen SR(OVL_FIR_COEF_HV2(i, j));
378f76ee892STomi Valkeinen
379f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
380f76ee892STomi Valkeinen SR(OVL_FIR_COEF_V2(i, j));
381f76ee892STomi Valkeinen }
382f76ee892STomi Valkeinen if (dss_has_feature(FEAT_ATTR2))
383f76ee892STomi Valkeinen SR(OVL_ATTRIBUTES2(i));
384f76ee892STomi Valkeinen }
385f76ee892STomi Valkeinen
386f76ee892STomi Valkeinen if (dss_has_feature(FEAT_CORE_CLK_DIV))
387f76ee892STomi Valkeinen SR(DIVISOR);
388f76ee892STomi Valkeinen
389f76ee892STomi Valkeinen dispc.ctx_valid = true;
390f76ee892STomi Valkeinen
391f76ee892STomi Valkeinen DSSDBG("context saved\n");
392f76ee892STomi Valkeinen }
393f76ee892STomi Valkeinen
dispc_restore_context(void)394f76ee892STomi Valkeinen static void dispc_restore_context(void)
395f76ee892STomi Valkeinen {
396f76ee892STomi Valkeinen int i, j;
397f76ee892STomi Valkeinen
398f76ee892STomi Valkeinen DSSDBG("dispc_restore_context\n");
399f76ee892STomi Valkeinen
400f76ee892STomi Valkeinen if (!dispc.ctx_valid)
401f76ee892STomi Valkeinen return;
402f76ee892STomi Valkeinen
403f76ee892STomi Valkeinen /*RR(IRQENABLE);*/
404f76ee892STomi Valkeinen /*RR(CONTROL);*/
405f76ee892STomi Valkeinen RR(CONFIG);
406f76ee892STomi Valkeinen RR(LINE_NUMBER);
407f76ee892STomi Valkeinen if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
408f76ee892STomi Valkeinen dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
409f76ee892STomi Valkeinen RR(GLOBAL_ALPHA);
410f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD2))
411f76ee892STomi Valkeinen RR(CONFIG2);
412f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD3))
413f76ee892STomi Valkeinen RR(CONFIG3);
414f76ee892STomi Valkeinen
415f76ee892STomi Valkeinen for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
416f76ee892STomi Valkeinen RR(DEFAULT_COLOR(i));
417f76ee892STomi Valkeinen RR(TRANS_COLOR(i));
418f76ee892STomi Valkeinen RR(SIZE_MGR(i));
419f76ee892STomi Valkeinen if (i == OMAP_DSS_CHANNEL_DIGIT)
420f76ee892STomi Valkeinen continue;
421f76ee892STomi Valkeinen RR(TIMING_H(i));
422f76ee892STomi Valkeinen RR(TIMING_V(i));
423f76ee892STomi Valkeinen RR(POL_FREQ(i));
424f76ee892STomi Valkeinen RR(DIVISORo(i));
425f76ee892STomi Valkeinen
426f76ee892STomi Valkeinen RR(DATA_CYCLE1(i));
427f76ee892STomi Valkeinen RR(DATA_CYCLE2(i));
428f76ee892STomi Valkeinen RR(DATA_CYCLE3(i));
429f76ee892STomi Valkeinen
430f76ee892STomi Valkeinen if (dss_has_feature(FEAT_CPR)) {
431f76ee892STomi Valkeinen RR(CPR_COEF_R(i));
432f76ee892STomi Valkeinen RR(CPR_COEF_G(i));
433f76ee892STomi Valkeinen RR(CPR_COEF_B(i));
434f76ee892STomi Valkeinen }
435f76ee892STomi Valkeinen }
436f76ee892STomi Valkeinen
437f76ee892STomi Valkeinen for (i = 0; i < dss_feat_get_num_ovls(); i++) {
438f76ee892STomi Valkeinen RR(OVL_BA0(i));
439f76ee892STomi Valkeinen RR(OVL_BA1(i));
440f76ee892STomi Valkeinen RR(OVL_POSITION(i));
441f76ee892STomi Valkeinen RR(OVL_SIZE(i));
442f76ee892STomi Valkeinen RR(OVL_ATTRIBUTES(i));
443f76ee892STomi Valkeinen RR(OVL_FIFO_THRESHOLD(i));
444f76ee892STomi Valkeinen RR(OVL_ROW_INC(i));
445f76ee892STomi Valkeinen RR(OVL_PIXEL_INC(i));
446f76ee892STomi Valkeinen if (dss_has_feature(FEAT_PRELOAD))
447f76ee892STomi Valkeinen RR(OVL_PRELOAD(i));
448f76ee892STomi Valkeinen if (i == OMAP_DSS_GFX) {
449f76ee892STomi Valkeinen RR(OVL_WINDOW_SKIP(i));
450f76ee892STomi Valkeinen RR(OVL_TABLE_BA(i));
451f76ee892STomi Valkeinen continue;
452f76ee892STomi Valkeinen }
453f76ee892STomi Valkeinen RR(OVL_FIR(i));
454f76ee892STomi Valkeinen RR(OVL_PICTURE_SIZE(i));
455f76ee892STomi Valkeinen RR(OVL_ACCU0(i));
456f76ee892STomi Valkeinen RR(OVL_ACCU1(i));
457f76ee892STomi Valkeinen
458f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
459f76ee892STomi Valkeinen RR(OVL_FIR_COEF_H(i, j));
460f76ee892STomi Valkeinen
461f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
462f76ee892STomi Valkeinen RR(OVL_FIR_COEF_HV(i, j));
463f76ee892STomi Valkeinen
464f76ee892STomi Valkeinen for (j = 0; j < 5; j++)
465f76ee892STomi Valkeinen RR(OVL_CONV_COEF(i, j));
466f76ee892STomi Valkeinen
467f76ee892STomi Valkeinen if (dss_has_feature(FEAT_FIR_COEF_V)) {
468f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
469f76ee892STomi Valkeinen RR(OVL_FIR_COEF_V(i, j));
470f76ee892STomi Valkeinen }
471f76ee892STomi Valkeinen
472f76ee892STomi Valkeinen if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
473f76ee892STomi Valkeinen RR(OVL_BA0_UV(i));
474f76ee892STomi Valkeinen RR(OVL_BA1_UV(i));
475f76ee892STomi Valkeinen RR(OVL_FIR2(i));
476f76ee892STomi Valkeinen RR(OVL_ACCU2_0(i));
477f76ee892STomi Valkeinen RR(OVL_ACCU2_1(i));
478f76ee892STomi Valkeinen
479f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
480f76ee892STomi Valkeinen RR(OVL_FIR_COEF_H2(i, j));
481f76ee892STomi Valkeinen
482f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
483f76ee892STomi Valkeinen RR(OVL_FIR_COEF_HV2(i, j));
484f76ee892STomi Valkeinen
485f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
486f76ee892STomi Valkeinen RR(OVL_FIR_COEF_V2(i, j));
487f76ee892STomi Valkeinen }
488f76ee892STomi Valkeinen if (dss_has_feature(FEAT_ATTR2))
489f76ee892STomi Valkeinen RR(OVL_ATTRIBUTES2(i));
490f76ee892STomi Valkeinen }
491f76ee892STomi Valkeinen
492f76ee892STomi Valkeinen if (dss_has_feature(FEAT_CORE_CLK_DIV))
493f76ee892STomi Valkeinen RR(DIVISOR);
494f76ee892STomi Valkeinen
495f76ee892STomi Valkeinen /* enable last, because LCD & DIGIT enable are here */
496f76ee892STomi Valkeinen RR(CONTROL);
497f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD2))
498f76ee892STomi Valkeinen RR(CONTROL2);
499f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD3))
500f76ee892STomi Valkeinen RR(CONTROL3);
501f76ee892STomi Valkeinen /* clear spurious SYNC_LOST_DIGIT interrupts */
502f76ee892STomi Valkeinen dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
503f76ee892STomi Valkeinen
504f76ee892STomi Valkeinen /*
505f76ee892STomi Valkeinen * enable last so IRQs won't trigger before
506f76ee892STomi Valkeinen * the context is fully restored
507f76ee892STomi Valkeinen */
508f76ee892STomi Valkeinen RR(IRQENABLE);
509f76ee892STomi Valkeinen
510f76ee892STomi Valkeinen DSSDBG("context restored\n");
511f76ee892STomi Valkeinen }
512f76ee892STomi Valkeinen
513f76ee892STomi Valkeinen #undef SR
514f76ee892STomi Valkeinen #undef RR
515f76ee892STomi Valkeinen
dispc_runtime_get(void)516f76ee892STomi Valkeinen int dispc_runtime_get(void)
517f76ee892STomi Valkeinen {
518f76ee892STomi Valkeinen int r;
519f76ee892STomi Valkeinen
520f76ee892STomi Valkeinen DSSDBG("dispc_runtime_get\n");
521f76ee892STomi Valkeinen
522b0e07060SZhang Qilong r = pm_runtime_resume_and_get(&dispc.pdev->dev);
523b0e07060SZhang Qilong if (WARN_ON(r < 0))
52478c2ce9bSAditya Pakki return r;
52578c2ce9bSAditya Pakki return 0;
526f76ee892STomi Valkeinen }
527f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_runtime_get);
528f76ee892STomi Valkeinen
dispc_runtime_put(void)529f76ee892STomi Valkeinen void dispc_runtime_put(void)
530f76ee892STomi Valkeinen {
531f76ee892STomi Valkeinen int r;
532f76ee892STomi Valkeinen
533f76ee892STomi Valkeinen DSSDBG("dispc_runtime_put\n");
534f76ee892STomi Valkeinen
535f76ee892STomi Valkeinen r = pm_runtime_put_sync(&dispc.pdev->dev);
536f76ee892STomi Valkeinen WARN_ON(r < 0 && r != -ENOSYS);
537f76ee892STomi Valkeinen }
538f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_runtime_put);
539f76ee892STomi Valkeinen
dispc_mgr_get_vsync_irq(enum omap_channel channel)540f76ee892STomi Valkeinen u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
541f76ee892STomi Valkeinen {
542f76ee892STomi Valkeinen return mgr_desc[channel].vsync_irq;
543f76ee892STomi Valkeinen }
544f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_mgr_get_vsync_irq);
545f76ee892STomi Valkeinen
dispc_mgr_get_framedone_irq(enum omap_channel channel)546f76ee892STomi Valkeinen u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
547f76ee892STomi Valkeinen {
548f76ee892STomi Valkeinen if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv)
549f76ee892STomi Valkeinen return 0;
550f76ee892STomi Valkeinen
551f76ee892STomi Valkeinen return mgr_desc[channel].framedone_irq;
552f76ee892STomi Valkeinen }
553f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_mgr_get_framedone_irq);
554f76ee892STomi Valkeinen
dispc_mgr_get_sync_lost_irq(enum omap_channel channel)555f76ee892STomi Valkeinen u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
556f76ee892STomi Valkeinen {
557f76ee892STomi Valkeinen return mgr_desc[channel].sync_lost_irq;
558f76ee892STomi Valkeinen }
559f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_mgr_get_sync_lost_irq);
560f76ee892STomi Valkeinen
dispc_mgr_go_busy(enum omap_channel channel)561f76ee892STomi Valkeinen bool dispc_mgr_go_busy(enum omap_channel channel)
562f76ee892STomi Valkeinen {
563f76ee892STomi Valkeinen return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
564f76ee892STomi Valkeinen }
565f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_mgr_go_busy);
566f76ee892STomi Valkeinen
dispc_mgr_go(enum omap_channel channel)567f76ee892STomi Valkeinen void dispc_mgr_go(enum omap_channel channel)
568f76ee892STomi Valkeinen {
569f76ee892STomi Valkeinen WARN_ON(!dispc_mgr_is_enabled(channel));
570f76ee892STomi Valkeinen WARN_ON(dispc_mgr_go_busy(channel));
571f76ee892STomi Valkeinen
572f76ee892STomi Valkeinen DSSDBG("GO %s\n", mgr_desc[channel].name);
573f76ee892STomi Valkeinen
574f76ee892STomi Valkeinen mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
575f76ee892STomi Valkeinen }
576f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_mgr_go);
577f76ee892STomi Valkeinen
dispc_ovl_write_firh_reg(enum omap_plane plane,int reg,u32 value)578f76ee892STomi Valkeinen static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
579f76ee892STomi Valkeinen {
580f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
581f76ee892STomi Valkeinen }
582f76ee892STomi Valkeinen
dispc_ovl_write_firhv_reg(enum omap_plane plane,int reg,u32 value)583f76ee892STomi Valkeinen static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
584f76ee892STomi Valkeinen {
585f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
586f76ee892STomi Valkeinen }
587f76ee892STomi Valkeinen
dispc_ovl_write_firv_reg(enum omap_plane plane,int reg,u32 value)588f76ee892STomi Valkeinen static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
589f76ee892STomi Valkeinen {
590f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
591f76ee892STomi Valkeinen }
592f76ee892STomi Valkeinen
dispc_ovl_write_firh2_reg(enum omap_plane plane,int reg,u32 value)593f76ee892STomi Valkeinen static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
594f76ee892STomi Valkeinen {
595f76ee892STomi Valkeinen BUG_ON(plane == OMAP_DSS_GFX);
596f76ee892STomi Valkeinen
597f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
598f76ee892STomi Valkeinen }
599f76ee892STomi Valkeinen
dispc_ovl_write_firhv2_reg(enum omap_plane plane,int reg,u32 value)600f76ee892STomi Valkeinen static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
601f76ee892STomi Valkeinen u32 value)
602f76ee892STomi Valkeinen {
603f76ee892STomi Valkeinen BUG_ON(plane == OMAP_DSS_GFX);
604f76ee892STomi Valkeinen
605f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
606f76ee892STomi Valkeinen }
607f76ee892STomi Valkeinen
dispc_ovl_write_firv2_reg(enum omap_plane plane,int reg,u32 value)608f76ee892STomi Valkeinen static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
609f76ee892STomi Valkeinen {
610f76ee892STomi Valkeinen BUG_ON(plane == OMAP_DSS_GFX);
611f76ee892STomi Valkeinen
612f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
613f76ee892STomi Valkeinen }
614f76ee892STomi Valkeinen
dispc_ovl_set_scale_coef(enum omap_plane plane,int fir_hinc,int fir_vinc,int five_taps,enum omap_color_component color_comp)615f76ee892STomi Valkeinen static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
616f76ee892STomi Valkeinen int fir_vinc, int five_taps,
617f76ee892STomi Valkeinen enum omap_color_component color_comp)
618f76ee892STomi Valkeinen {
619f76ee892STomi Valkeinen const struct dispc_coef *h_coef, *v_coef;
620f76ee892STomi Valkeinen int i;
621f76ee892STomi Valkeinen
622f76ee892STomi Valkeinen h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
623f76ee892STomi Valkeinen v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
624f76ee892STomi Valkeinen
625f76ee892STomi Valkeinen for (i = 0; i < 8; i++) {
626f76ee892STomi Valkeinen u32 h, hv;
627f76ee892STomi Valkeinen
628f76ee892STomi Valkeinen h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
629f76ee892STomi Valkeinen | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
630f76ee892STomi Valkeinen | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
631f76ee892STomi Valkeinen | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
632f76ee892STomi Valkeinen hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
633f76ee892STomi Valkeinen | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
634f76ee892STomi Valkeinen | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
635f76ee892STomi Valkeinen | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
636f76ee892STomi Valkeinen
637f76ee892STomi Valkeinen if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
638f76ee892STomi Valkeinen dispc_ovl_write_firh_reg(plane, i, h);
639f76ee892STomi Valkeinen dispc_ovl_write_firhv_reg(plane, i, hv);
640f76ee892STomi Valkeinen } else {
641f76ee892STomi Valkeinen dispc_ovl_write_firh2_reg(plane, i, h);
642f76ee892STomi Valkeinen dispc_ovl_write_firhv2_reg(plane, i, hv);
643f76ee892STomi Valkeinen }
644f76ee892STomi Valkeinen
645f76ee892STomi Valkeinen }
646f76ee892STomi Valkeinen
647f76ee892STomi Valkeinen if (five_taps) {
648f76ee892STomi Valkeinen for (i = 0; i < 8; i++) {
649f76ee892STomi Valkeinen u32 v;
650f76ee892STomi Valkeinen v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
651f76ee892STomi Valkeinen | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
652f76ee892STomi Valkeinen if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
653f76ee892STomi Valkeinen dispc_ovl_write_firv_reg(plane, i, v);
654f76ee892STomi Valkeinen else
655f76ee892STomi Valkeinen dispc_ovl_write_firv2_reg(plane, i, v);
656f76ee892STomi Valkeinen }
657f76ee892STomi Valkeinen }
658f76ee892STomi Valkeinen }
659f76ee892STomi Valkeinen
660f76ee892STomi Valkeinen
dispc_ovl_write_color_conv_coef(enum omap_plane plane,const struct color_conv_coef * ct)661f76ee892STomi Valkeinen static void dispc_ovl_write_color_conv_coef(enum omap_plane plane,
662f76ee892STomi Valkeinen const struct color_conv_coef *ct)
663f76ee892STomi Valkeinen {
664f76ee892STomi Valkeinen #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
665f76ee892STomi Valkeinen
666f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
667f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
668f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
669f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
670f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
671f76ee892STomi Valkeinen
672f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
673f76ee892STomi Valkeinen
674f76ee892STomi Valkeinen #undef CVAL
675f76ee892STomi Valkeinen }
676f76ee892STomi Valkeinen
dispc_setup_color_conv_coef(void)677f76ee892STomi Valkeinen static void dispc_setup_color_conv_coef(void)
678f76ee892STomi Valkeinen {
679f76ee892STomi Valkeinen int i;
680f76ee892STomi Valkeinen int num_ovl = dss_feat_get_num_ovls();
681f76ee892STomi Valkeinen const struct color_conv_coef ctbl_bt601_5_ovl = {
682f76ee892STomi Valkeinen /* YUV -> RGB */
683f76ee892STomi Valkeinen 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
684f76ee892STomi Valkeinen };
685f76ee892STomi Valkeinen const struct color_conv_coef ctbl_bt601_5_wb = {
686f76ee892STomi Valkeinen /* RGB -> YUV */
687f76ee892STomi Valkeinen 66, 129, 25, 112, -94, -18, -38, -74, 112, 0,
688f76ee892STomi Valkeinen };
689f76ee892STomi Valkeinen
690f76ee892STomi Valkeinen for (i = 1; i < num_ovl; i++)
691f76ee892STomi Valkeinen dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
692f76ee892STomi Valkeinen
693f76ee892STomi Valkeinen if (dispc.feat->has_writeback)
694f76ee892STomi Valkeinen dispc_ovl_write_color_conv_coef(OMAP_DSS_WB, &ctbl_bt601_5_wb);
695f76ee892STomi Valkeinen }
696f76ee892STomi Valkeinen
dispc_ovl_set_ba0(enum omap_plane plane,u32 paddr)697f76ee892STomi Valkeinen static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
698f76ee892STomi Valkeinen {
699f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
700f76ee892STomi Valkeinen }
701f76ee892STomi Valkeinen
dispc_ovl_set_ba1(enum omap_plane plane,u32 paddr)702f76ee892STomi Valkeinen static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
703f76ee892STomi Valkeinen {
704f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
705f76ee892STomi Valkeinen }
706f76ee892STomi Valkeinen
dispc_ovl_set_ba0_uv(enum omap_plane plane,u32 paddr)707f76ee892STomi Valkeinen static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
708f76ee892STomi Valkeinen {
709f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
710f76ee892STomi Valkeinen }
711f76ee892STomi Valkeinen
dispc_ovl_set_ba1_uv(enum omap_plane plane,u32 paddr)712f76ee892STomi Valkeinen static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
713f76ee892STomi Valkeinen {
714f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
715f76ee892STomi Valkeinen }
716f76ee892STomi Valkeinen
dispc_ovl_set_pos(enum omap_plane plane,enum omap_overlay_caps caps,int x,int y)717f76ee892STomi Valkeinen static void dispc_ovl_set_pos(enum omap_plane plane,
718f76ee892STomi Valkeinen enum omap_overlay_caps caps, int x, int y)
719f76ee892STomi Valkeinen {
720f76ee892STomi Valkeinen u32 val;
721f76ee892STomi Valkeinen
722f76ee892STomi Valkeinen if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
723f76ee892STomi Valkeinen return;
724f76ee892STomi Valkeinen
725f76ee892STomi Valkeinen val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
726f76ee892STomi Valkeinen
727f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_POSITION(plane), val);
728f76ee892STomi Valkeinen }
729f76ee892STomi Valkeinen
dispc_ovl_set_input_size(enum omap_plane plane,int width,int height)730f76ee892STomi Valkeinen static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
731f76ee892STomi Valkeinen int height)
732f76ee892STomi Valkeinen {
733f76ee892STomi Valkeinen u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
734f76ee892STomi Valkeinen
735f76ee892STomi Valkeinen if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
736f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_SIZE(plane), val);
737f76ee892STomi Valkeinen else
738f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
739f76ee892STomi Valkeinen }
740f76ee892STomi Valkeinen
dispc_ovl_set_output_size(enum omap_plane plane,int width,int height)741f76ee892STomi Valkeinen static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
742f76ee892STomi Valkeinen int height)
743f76ee892STomi Valkeinen {
744f76ee892STomi Valkeinen u32 val;
745f76ee892STomi Valkeinen
746f76ee892STomi Valkeinen BUG_ON(plane == OMAP_DSS_GFX);
747f76ee892STomi Valkeinen
748f76ee892STomi Valkeinen val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
749f76ee892STomi Valkeinen
750f76ee892STomi Valkeinen if (plane == OMAP_DSS_WB)
751f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
752f76ee892STomi Valkeinen else
753f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_SIZE(plane), val);
754f76ee892STomi Valkeinen }
755f76ee892STomi Valkeinen
dispc_ovl_set_zorder(enum omap_plane plane,enum omap_overlay_caps caps,u8 zorder)756f76ee892STomi Valkeinen static void dispc_ovl_set_zorder(enum omap_plane plane,
757f76ee892STomi Valkeinen enum omap_overlay_caps caps, u8 zorder)
758f76ee892STomi Valkeinen {
759f76ee892STomi Valkeinen if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
760f76ee892STomi Valkeinen return;
761f76ee892STomi Valkeinen
762f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
763f76ee892STomi Valkeinen }
764f76ee892STomi Valkeinen
dispc_ovl_enable_zorder_planes(void)765f76ee892STomi Valkeinen static void dispc_ovl_enable_zorder_planes(void)
766f76ee892STomi Valkeinen {
767f76ee892STomi Valkeinen int i;
768f76ee892STomi Valkeinen
769f76ee892STomi Valkeinen if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
770f76ee892STomi Valkeinen return;
771f76ee892STomi Valkeinen
772f76ee892STomi Valkeinen for (i = 0; i < dss_feat_get_num_ovls(); i++)
773f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
774f76ee892STomi Valkeinen }
775f76ee892STomi Valkeinen
dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,enum omap_overlay_caps caps,bool enable)776f76ee892STomi Valkeinen static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
777f76ee892STomi Valkeinen enum omap_overlay_caps caps, bool enable)
778f76ee892STomi Valkeinen {
779f76ee892STomi Valkeinen if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
780f76ee892STomi Valkeinen return;
781f76ee892STomi Valkeinen
782f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
783f76ee892STomi Valkeinen }
784f76ee892STomi Valkeinen
dispc_ovl_setup_global_alpha(enum omap_plane plane,enum omap_overlay_caps caps,u8 global_alpha)785f76ee892STomi Valkeinen static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
786f76ee892STomi Valkeinen enum omap_overlay_caps caps, u8 global_alpha)
787f76ee892STomi Valkeinen {
788f76ee892STomi Valkeinen static const unsigned shifts[] = { 0, 8, 16, 24, };
789f76ee892STomi Valkeinen int shift;
790f76ee892STomi Valkeinen
791f76ee892STomi Valkeinen if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
792f76ee892STomi Valkeinen return;
793f76ee892STomi Valkeinen
794f76ee892STomi Valkeinen shift = shifts[plane];
795f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
796f76ee892STomi Valkeinen }
797f76ee892STomi Valkeinen
dispc_ovl_set_pix_inc(enum omap_plane plane,s32 inc)798f76ee892STomi Valkeinen static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
799f76ee892STomi Valkeinen {
800f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
801f76ee892STomi Valkeinen }
802f76ee892STomi Valkeinen
dispc_ovl_set_row_inc(enum omap_plane plane,s32 inc)803f76ee892STomi Valkeinen static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
804f76ee892STomi Valkeinen {
805f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
806f76ee892STomi Valkeinen }
807f76ee892STomi Valkeinen
dispc_ovl_set_color_mode(enum omap_plane plane,enum omap_color_mode color_mode)808f76ee892STomi Valkeinen static void dispc_ovl_set_color_mode(enum omap_plane plane,
809f76ee892STomi Valkeinen enum omap_color_mode color_mode)
810f76ee892STomi Valkeinen {
811f76ee892STomi Valkeinen u32 m = 0;
812f76ee892STomi Valkeinen if (plane != OMAP_DSS_GFX) {
813f76ee892STomi Valkeinen switch (color_mode) {
814f76ee892STomi Valkeinen case OMAP_DSS_COLOR_NV12:
815f76ee892STomi Valkeinen m = 0x0; break;
816f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBX16:
817f76ee892STomi Valkeinen m = 0x1; break;
818f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBA16:
819f76ee892STomi Valkeinen m = 0x2; break;
820f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB12U:
821f76ee892STomi Valkeinen m = 0x4; break;
822f76ee892STomi Valkeinen case OMAP_DSS_COLOR_ARGB16:
823f76ee892STomi Valkeinen m = 0x5; break;
824f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB16:
825f76ee892STomi Valkeinen m = 0x6; break;
826f76ee892STomi Valkeinen case OMAP_DSS_COLOR_ARGB16_1555:
827f76ee892STomi Valkeinen m = 0x7; break;
828f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB24U:
829f76ee892STomi Valkeinen m = 0x8; break;
830f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB24P:
831f76ee892STomi Valkeinen m = 0x9; break;
832f76ee892STomi Valkeinen case OMAP_DSS_COLOR_YUV2:
833f76ee892STomi Valkeinen m = 0xa; break;
834f76ee892STomi Valkeinen case OMAP_DSS_COLOR_UYVY:
835f76ee892STomi Valkeinen m = 0xb; break;
836f76ee892STomi Valkeinen case OMAP_DSS_COLOR_ARGB32:
837f76ee892STomi Valkeinen m = 0xc; break;
838f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBA32:
839f76ee892STomi Valkeinen m = 0xd; break;
840f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBX32:
841f76ee892STomi Valkeinen m = 0xe; break;
842f76ee892STomi Valkeinen case OMAP_DSS_COLOR_XRGB16_1555:
843f76ee892STomi Valkeinen m = 0xf; break;
844f76ee892STomi Valkeinen default:
845f76ee892STomi Valkeinen BUG(); return;
846f76ee892STomi Valkeinen }
847f76ee892STomi Valkeinen } else {
848f76ee892STomi Valkeinen switch (color_mode) {
849f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT1:
850f76ee892STomi Valkeinen m = 0x0; break;
851f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT2:
852f76ee892STomi Valkeinen m = 0x1; break;
853f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT4:
854f76ee892STomi Valkeinen m = 0x2; break;
855f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT8:
856f76ee892STomi Valkeinen m = 0x3; break;
857f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB12U:
858f76ee892STomi Valkeinen m = 0x4; break;
859f76ee892STomi Valkeinen case OMAP_DSS_COLOR_ARGB16:
860f76ee892STomi Valkeinen m = 0x5; break;
861f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB16:
862f76ee892STomi Valkeinen m = 0x6; break;
863f76ee892STomi Valkeinen case OMAP_DSS_COLOR_ARGB16_1555:
864f76ee892STomi Valkeinen m = 0x7; break;
865f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB24U:
866f76ee892STomi Valkeinen m = 0x8; break;
867f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB24P:
868f76ee892STomi Valkeinen m = 0x9; break;
869f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBX16:
870f76ee892STomi Valkeinen m = 0xa; break;
871f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBA16:
872f76ee892STomi Valkeinen m = 0xb; break;
873f76ee892STomi Valkeinen case OMAP_DSS_COLOR_ARGB32:
874f76ee892STomi Valkeinen m = 0xc; break;
875f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBA32:
876f76ee892STomi Valkeinen m = 0xd; break;
877f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBX32:
878f76ee892STomi Valkeinen m = 0xe; break;
879f76ee892STomi Valkeinen case OMAP_DSS_COLOR_XRGB16_1555:
880f76ee892STomi Valkeinen m = 0xf; break;
881f76ee892STomi Valkeinen default:
882f76ee892STomi Valkeinen BUG(); return;
883f76ee892STomi Valkeinen }
884f76ee892STomi Valkeinen }
885f76ee892STomi Valkeinen
886f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
887f76ee892STomi Valkeinen }
888f76ee892STomi Valkeinen
dispc_ovl_configure_burst_type(enum omap_plane plane,enum omap_dss_rotation_type rotation_type)889f76ee892STomi Valkeinen static void dispc_ovl_configure_burst_type(enum omap_plane plane,
890f76ee892STomi Valkeinen enum omap_dss_rotation_type rotation_type)
891f76ee892STomi Valkeinen {
892190070aeSJason Yan if (!dss_has_feature(FEAT_BURST_2D))
893f76ee892STomi Valkeinen return;
894f76ee892STomi Valkeinen
895f76ee892STomi Valkeinen if (rotation_type == OMAP_DSS_ROT_TILER)
896f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
897f76ee892STomi Valkeinen else
898f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
899f76ee892STomi Valkeinen }
900f76ee892STomi Valkeinen
dispc_ovl_set_channel_out(enum omap_plane plane,enum omap_channel channel)901f76ee892STomi Valkeinen void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
902f76ee892STomi Valkeinen {
903f76ee892STomi Valkeinen int shift;
904f76ee892STomi Valkeinen u32 val;
905f76ee892STomi Valkeinen int chan = 0, chan2 = 0;
906f76ee892STomi Valkeinen
907f76ee892STomi Valkeinen switch (plane) {
908f76ee892STomi Valkeinen case OMAP_DSS_GFX:
909f76ee892STomi Valkeinen shift = 8;
910f76ee892STomi Valkeinen break;
911f76ee892STomi Valkeinen case OMAP_DSS_VIDEO1:
912f76ee892STomi Valkeinen case OMAP_DSS_VIDEO2:
913f76ee892STomi Valkeinen case OMAP_DSS_VIDEO3:
914f76ee892STomi Valkeinen shift = 16;
915f76ee892STomi Valkeinen break;
916f76ee892STomi Valkeinen default:
917f76ee892STomi Valkeinen BUG();
918f76ee892STomi Valkeinen return;
919f76ee892STomi Valkeinen }
920f76ee892STomi Valkeinen
921f76ee892STomi Valkeinen val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
922f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD2)) {
923f76ee892STomi Valkeinen switch (channel) {
924f76ee892STomi Valkeinen case OMAP_DSS_CHANNEL_LCD:
925f76ee892STomi Valkeinen chan = 0;
926f76ee892STomi Valkeinen chan2 = 0;
927f76ee892STomi Valkeinen break;
928f76ee892STomi Valkeinen case OMAP_DSS_CHANNEL_DIGIT:
929f76ee892STomi Valkeinen chan = 1;
930f76ee892STomi Valkeinen chan2 = 0;
931f76ee892STomi Valkeinen break;
932f76ee892STomi Valkeinen case OMAP_DSS_CHANNEL_LCD2:
933f76ee892STomi Valkeinen chan = 0;
934f76ee892STomi Valkeinen chan2 = 1;
935f76ee892STomi Valkeinen break;
936f76ee892STomi Valkeinen case OMAP_DSS_CHANNEL_LCD3:
937f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD3)) {
938f76ee892STomi Valkeinen chan = 0;
939f76ee892STomi Valkeinen chan2 = 2;
940f76ee892STomi Valkeinen } else {
941f76ee892STomi Valkeinen BUG();
942f76ee892STomi Valkeinen return;
943f76ee892STomi Valkeinen }
944f76ee892STomi Valkeinen break;
945f76ee892STomi Valkeinen case OMAP_DSS_CHANNEL_WB:
946f76ee892STomi Valkeinen chan = 0;
947f76ee892STomi Valkeinen chan2 = 3;
948f76ee892STomi Valkeinen break;
949f76ee892STomi Valkeinen default:
950f76ee892STomi Valkeinen BUG();
951f76ee892STomi Valkeinen return;
952f76ee892STomi Valkeinen }
953f76ee892STomi Valkeinen
954f76ee892STomi Valkeinen val = FLD_MOD(val, chan, shift, shift);
955f76ee892STomi Valkeinen val = FLD_MOD(val, chan2, 31, 30);
956f76ee892STomi Valkeinen } else {
957f76ee892STomi Valkeinen val = FLD_MOD(val, channel, shift, shift);
958f76ee892STomi Valkeinen }
959f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
960f76ee892STomi Valkeinen }
961f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_ovl_set_channel_out);
962f76ee892STomi Valkeinen
dispc_ovl_get_channel_out(enum omap_plane plane)963f76ee892STomi Valkeinen static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
964f76ee892STomi Valkeinen {
965f76ee892STomi Valkeinen int shift;
966f76ee892STomi Valkeinen u32 val;
967f76ee892STomi Valkeinen
968f76ee892STomi Valkeinen switch (plane) {
969f76ee892STomi Valkeinen case OMAP_DSS_GFX:
970f76ee892STomi Valkeinen shift = 8;
971f76ee892STomi Valkeinen break;
972f76ee892STomi Valkeinen case OMAP_DSS_VIDEO1:
973f76ee892STomi Valkeinen case OMAP_DSS_VIDEO2:
974f76ee892STomi Valkeinen case OMAP_DSS_VIDEO3:
975f76ee892STomi Valkeinen shift = 16;
976f76ee892STomi Valkeinen break;
977f76ee892STomi Valkeinen default:
978f76ee892STomi Valkeinen BUG();
979f76ee892STomi Valkeinen return 0;
980f76ee892STomi Valkeinen }
981f76ee892STomi Valkeinen
982f76ee892STomi Valkeinen val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
983f76ee892STomi Valkeinen
984f76ee892STomi Valkeinen if (FLD_GET(val, shift, shift) == 1)
985f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_DIGIT;
986f76ee892STomi Valkeinen
987f76ee892STomi Valkeinen if (!dss_has_feature(FEAT_MGR_LCD2))
988f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD;
989f76ee892STomi Valkeinen
990f76ee892STomi Valkeinen switch (FLD_GET(val, 31, 30)) {
991f76ee892STomi Valkeinen case 0:
992f76ee892STomi Valkeinen default:
993f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD;
994f76ee892STomi Valkeinen case 1:
995f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD2;
996f76ee892STomi Valkeinen case 2:
997f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD3;
998f76ee892STomi Valkeinen case 3:
999f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_WB;
1000f76ee892STomi Valkeinen }
1001f76ee892STomi Valkeinen }
1002f76ee892STomi Valkeinen
dispc_ovl_set_burst_size(enum omap_plane plane,enum omap_burst_size burst_size)1003f76ee892STomi Valkeinen static void dispc_ovl_set_burst_size(enum omap_plane plane,
1004f76ee892STomi Valkeinen enum omap_burst_size burst_size)
1005f76ee892STomi Valkeinen {
1006f76ee892STomi Valkeinen static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
1007f76ee892STomi Valkeinen int shift;
1008f76ee892STomi Valkeinen
1009f76ee892STomi Valkeinen shift = shifts[plane];
1010f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
1011f76ee892STomi Valkeinen }
1012f76ee892STomi Valkeinen
dispc_configure_burst_sizes(void)1013f76ee892STomi Valkeinen static void dispc_configure_burst_sizes(void)
1014f76ee892STomi Valkeinen {
1015f76ee892STomi Valkeinen int i;
1016f76ee892STomi Valkeinen const int burst_size = BURST_SIZE_X8;
1017f76ee892STomi Valkeinen
1018f76ee892STomi Valkeinen /* Configure burst size always to maximum size */
1019f76ee892STomi Valkeinen for (i = 0; i < dss_feat_get_num_ovls(); ++i)
1020f76ee892STomi Valkeinen dispc_ovl_set_burst_size(i, burst_size);
1021f76ee892STomi Valkeinen if (dispc.feat->has_writeback)
1022f76ee892STomi Valkeinen dispc_ovl_set_burst_size(OMAP_DSS_WB, burst_size);
1023f76ee892STomi Valkeinen }
1024f76ee892STomi Valkeinen
dispc_ovl_get_burst_size(enum omap_plane plane)1025f76ee892STomi Valkeinen static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
1026f76ee892STomi Valkeinen {
1027f76ee892STomi Valkeinen unsigned unit = dss_feat_get_burst_size_unit();
1028f76ee892STomi Valkeinen /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1029f76ee892STomi Valkeinen return unit * 8;
1030f76ee892STomi Valkeinen }
1031f76ee892STomi Valkeinen
dispc_enable_gamma_table(bool enable)1032f76ee892STomi Valkeinen void dispc_enable_gamma_table(bool enable)
1033f76ee892STomi Valkeinen {
1034f76ee892STomi Valkeinen /*
1035f76ee892STomi Valkeinen * This is partially implemented to support only disabling of
1036f76ee892STomi Valkeinen * the gamma table.
1037f76ee892STomi Valkeinen */
1038f76ee892STomi Valkeinen if (enable) {
1039f76ee892STomi Valkeinen DSSWARN("Gamma table enabling for TV not yet supported");
1040f76ee892STomi Valkeinen return;
1041f76ee892STomi Valkeinen }
1042f76ee892STomi Valkeinen
1043f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1044f76ee892STomi Valkeinen }
1045f76ee892STomi Valkeinen
dispc_mgr_enable_cpr(enum omap_channel channel,bool enable)1046f76ee892STomi Valkeinen static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
1047f76ee892STomi Valkeinen {
1048f76ee892STomi Valkeinen if (channel == OMAP_DSS_CHANNEL_DIGIT)
1049f76ee892STomi Valkeinen return;
1050f76ee892STomi Valkeinen
1051f76ee892STomi Valkeinen mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
1052f76ee892STomi Valkeinen }
1053f76ee892STomi Valkeinen
dispc_mgr_set_cpr_coef(enum omap_channel channel,const struct omap_dss_cpr_coefs * coefs)1054f76ee892STomi Valkeinen static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
1055f76ee892STomi Valkeinen const struct omap_dss_cpr_coefs *coefs)
1056f76ee892STomi Valkeinen {
1057f76ee892STomi Valkeinen u32 coef_r, coef_g, coef_b;
1058f76ee892STomi Valkeinen
1059f76ee892STomi Valkeinen if (!dss_mgr_is_lcd(channel))
1060f76ee892STomi Valkeinen return;
1061f76ee892STomi Valkeinen
1062f76ee892STomi Valkeinen coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1063f76ee892STomi Valkeinen FLD_VAL(coefs->rb, 9, 0);
1064f76ee892STomi Valkeinen coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1065f76ee892STomi Valkeinen FLD_VAL(coefs->gb, 9, 0);
1066f76ee892STomi Valkeinen coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1067f76ee892STomi Valkeinen FLD_VAL(coefs->bb, 9, 0);
1068f76ee892STomi Valkeinen
1069f76ee892STomi Valkeinen dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1070f76ee892STomi Valkeinen dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1071f76ee892STomi Valkeinen dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1072f76ee892STomi Valkeinen }
1073f76ee892STomi Valkeinen
dispc_ovl_set_vid_color_conv(enum omap_plane plane,bool enable)1074f76ee892STomi Valkeinen static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
1075f76ee892STomi Valkeinen {
1076f76ee892STomi Valkeinen u32 val;
1077f76ee892STomi Valkeinen
1078f76ee892STomi Valkeinen BUG_ON(plane == OMAP_DSS_GFX);
1079f76ee892STomi Valkeinen
1080f76ee892STomi Valkeinen val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1081f76ee892STomi Valkeinen val = FLD_MOD(val, enable, 9, 9);
1082f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
1083f76ee892STomi Valkeinen }
1084f76ee892STomi Valkeinen
dispc_ovl_enable_replication(enum omap_plane plane,enum omap_overlay_caps caps,bool enable)1085f76ee892STomi Valkeinen static void dispc_ovl_enable_replication(enum omap_plane plane,
1086f76ee892STomi Valkeinen enum omap_overlay_caps caps, bool enable)
1087f76ee892STomi Valkeinen {
1088f76ee892STomi Valkeinen static const unsigned shifts[] = { 5, 10, 10, 10 };
1089f76ee892STomi Valkeinen int shift;
1090f76ee892STomi Valkeinen
1091f76ee892STomi Valkeinen if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1092f76ee892STomi Valkeinen return;
1093f76ee892STomi Valkeinen
1094f76ee892STomi Valkeinen shift = shifts[plane];
1095f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
1096f76ee892STomi Valkeinen }
1097f76ee892STomi Valkeinen
dispc_mgr_set_size(enum omap_channel channel,u16 width,u16 height)1098f76ee892STomi Valkeinen static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
1099f76ee892STomi Valkeinen u16 height)
1100f76ee892STomi Valkeinen {
1101f76ee892STomi Valkeinen u32 val;
1102f76ee892STomi Valkeinen
1103f76ee892STomi Valkeinen val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1104f76ee892STomi Valkeinen FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1105f76ee892STomi Valkeinen
1106f76ee892STomi Valkeinen dispc_write_reg(DISPC_SIZE_MGR(channel), val);
1107f76ee892STomi Valkeinen }
1108f76ee892STomi Valkeinen
dispc_init_fifos(void)1109f76ee892STomi Valkeinen static void dispc_init_fifos(void)
1110f76ee892STomi Valkeinen {
1111f76ee892STomi Valkeinen u32 size;
1112f76ee892STomi Valkeinen int fifo;
1113f76ee892STomi Valkeinen u8 start, end;
1114f76ee892STomi Valkeinen u32 unit;
1115f76ee892STomi Valkeinen int i;
1116f76ee892STomi Valkeinen
1117f76ee892STomi Valkeinen unit = dss_feat_get_buffer_size_unit();
1118f76ee892STomi Valkeinen
1119f76ee892STomi Valkeinen dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
1120f76ee892STomi Valkeinen
1121f76ee892STomi Valkeinen for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1122f76ee892STomi Valkeinen size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
1123f76ee892STomi Valkeinen size *= unit;
1124f76ee892STomi Valkeinen dispc.fifo_size[fifo] = size;
1125f76ee892STomi Valkeinen
1126f76ee892STomi Valkeinen /*
1127f76ee892STomi Valkeinen * By default fifos are mapped directly to overlays, fifo 0 to
1128f76ee892STomi Valkeinen * ovl 0, fifo 1 to ovl 1, etc.
1129f76ee892STomi Valkeinen */
1130f76ee892STomi Valkeinen dispc.fifo_assignment[fifo] = fifo;
1131f76ee892STomi Valkeinen }
1132f76ee892STomi Valkeinen
1133f76ee892STomi Valkeinen /*
1134f76ee892STomi Valkeinen * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1135f76ee892STomi Valkeinen * causes problems with certain use cases, like using the tiler in 2D
1136f76ee892STomi Valkeinen * mode. The below hack swaps the fifos of GFX and WB planes, thus
1137f76ee892STomi Valkeinen * giving GFX plane a larger fifo. WB but should work fine with a
1138f76ee892STomi Valkeinen * smaller fifo.
1139f76ee892STomi Valkeinen */
1140f76ee892STomi Valkeinen if (dispc.feat->gfx_fifo_workaround) {
1141f76ee892STomi Valkeinen u32 v;
1142f76ee892STomi Valkeinen
1143f76ee892STomi Valkeinen v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1144f76ee892STomi Valkeinen
1145f76ee892STomi Valkeinen v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1146f76ee892STomi Valkeinen v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1147f76ee892STomi Valkeinen v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1148f76ee892STomi Valkeinen v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1149f76ee892STomi Valkeinen
1150f76ee892STomi Valkeinen dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1151f76ee892STomi Valkeinen
1152f76ee892STomi Valkeinen dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1153f76ee892STomi Valkeinen dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1154f76ee892STomi Valkeinen }
1155f76ee892STomi Valkeinen
1156f76ee892STomi Valkeinen /*
1157f76ee892STomi Valkeinen * Setup default fifo thresholds.
1158f76ee892STomi Valkeinen */
1159f76ee892STomi Valkeinen for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1160f76ee892STomi Valkeinen u32 low, high;
1161f76ee892STomi Valkeinen const bool use_fifomerge = false;
1162f76ee892STomi Valkeinen const bool manual_update = false;
1163f76ee892STomi Valkeinen
1164f76ee892STomi Valkeinen dispc_ovl_compute_fifo_thresholds(i, &low, &high,
1165f76ee892STomi Valkeinen use_fifomerge, manual_update);
1166f76ee892STomi Valkeinen
1167f76ee892STomi Valkeinen dispc_ovl_set_fifo_threshold(i, low, high);
1168f76ee892STomi Valkeinen }
1169f76ee892STomi Valkeinen
1170f76ee892STomi Valkeinen if (dispc.feat->has_writeback) {
1171f76ee892STomi Valkeinen u32 low, high;
1172f76ee892STomi Valkeinen const bool use_fifomerge = false;
1173f76ee892STomi Valkeinen const bool manual_update = false;
1174f76ee892STomi Valkeinen
1175f76ee892STomi Valkeinen dispc_ovl_compute_fifo_thresholds(OMAP_DSS_WB, &low, &high,
1176f76ee892STomi Valkeinen use_fifomerge, manual_update);
1177f76ee892STomi Valkeinen
1178f76ee892STomi Valkeinen dispc_ovl_set_fifo_threshold(OMAP_DSS_WB, low, high);
1179f76ee892STomi Valkeinen }
1180f76ee892STomi Valkeinen }
1181f76ee892STomi Valkeinen
dispc_ovl_get_fifo_size(enum omap_plane plane)1182f76ee892STomi Valkeinen static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
1183f76ee892STomi Valkeinen {
1184f76ee892STomi Valkeinen int fifo;
1185f76ee892STomi Valkeinen u32 size = 0;
1186f76ee892STomi Valkeinen
1187f76ee892STomi Valkeinen for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1188f76ee892STomi Valkeinen if (dispc.fifo_assignment[fifo] == plane)
1189f76ee892STomi Valkeinen size += dispc.fifo_size[fifo];
1190f76ee892STomi Valkeinen }
1191f76ee892STomi Valkeinen
1192f76ee892STomi Valkeinen return size;
1193f76ee892STomi Valkeinen }
1194f76ee892STomi Valkeinen
dispc_ovl_set_fifo_threshold(enum omap_plane plane,u32 low,u32 high)1195f76ee892STomi Valkeinen void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
1196f76ee892STomi Valkeinen {
1197f76ee892STomi Valkeinen u8 hi_start, hi_end, lo_start, lo_end;
1198f76ee892STomi Valkeinen u32 unit;
1199f76ee892STomi Valkeinen
1200f76ee892STomi Valkeinen unit = dss_feat_get_buffer_size_unit();
1201f76ee892STomi Valkeinen
1202f76ee892STomi Valkeinen WARN_ON(low % unit != 0);
1203f76ee892STomi Valkeinen WARN_ON(high % unit != 0);
1204f76ee892STomi Valkeinen
1205f76ee892STomi Valkeinen low /= unit;
1206f76ee892STomi Valkeinen high /= unit;
1207f76ee892STomi Valkeinen
1208f76ee892STomi Valkeinen dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1209f76ee892STomi Valkeinen dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1210f76ee892STomi Valkeinen
1211f76ee892STomi Valkeinen DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1212f76ee892STomi Valkeinen plane,
1213f76ee892STomi Valkeinen REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1214f76ee892STomi Valkeinen lo_start, lo_end) * unit,
1215f76ee892STomi Valkeinen REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1216f76ee892STomi Valkeinen hi_start, hi_end) * unit,
1217f76ee892STomi Valkeinen low * unit, high * unit);
1218f76ee892STomi Valkeinen
1219f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
1220f76ee892STomi Valkeinen FLD_VAL(high, hi_start, hi_end) |
1221f76ee892STomi Valkeinen FLD_VAL(low, lo_start, lo_end));
1222f76ee892STomi Valkeinen
1223f76ee892STomi Valkeinen /*
1224f76ee892STomi Valkeinen * configure the preload to the pipeline's high threhold, if HT it's too
1225f76ee892STomi Valkeinen * large for the preload field, set the threshold to the maximum value
1226f76ee892STomi Valkeinen * that can be held by the preload register
1227f76ee892STomi Valkeinen */
1228f76ee892STomi Valkeinen if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload &&
1229f76ee892STomi Valkeinen plane != OMAP_DSS_WB)
1230f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu));
1231f76ee892STomi Valkeinen }
1232f76ee892STomi Valkeinen
dispc_enable_fifomerge(bool enable)1233f76ee892STomi Valkeinen void dispc_enable_fifomerge(bool enable)
1234f76ee892STomi Valkeinen {
1235f76ee892STomi Valkeinen if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1236f76ee892STomi Valkeinen WARN_ON(enable);
1237f76ee892STomi Valkeinen return;
1238f76ee892STomi Valkeinen }
1239f76ee892STomi Valkeinen
1240f76ee892STomi Valkeinen DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1241f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1242f76ee892STomi Valkeinen }
1243f76ee892STomi Valkeinen
dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,u32 * fifo_low,u32 * fifo_high,bool use_fifomerge,bool manual_update)1244f76ee892STomi Valkeinen void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1245f76ee892STomi Valkeinen u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1246f76ee892STomi Valkeinen bool manual_update)
1247f76ee892STomi Valkeinen {
1248f76ee892STomi Valkeinen /*
1249f76ee892STomi Valkeinen * All sizes are in bytes. Both the buffer and burst are made of
1250f76ee892STomi Valkeinen * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1251f76ee892STomi Valkeinen */
1252f76ee892STomi Valkeinen
1253f76ee892STomi Valkeinen unsigned buf_unit = dss_feat_get_buffer_size_unit();
1254f76ee892STomi Valkeinen unsigned ovl_fifo_size, total_fifo_size, burst_size;
1255f76ee892STomi Valkeinen int i;
1256f76ee892STomi Valkeinen
1257f76ee892STomi Valkeinen burst_size = dispc_ovl_get_burst_size(plane);
1258f76ee892STomi Valkeinen ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
1259f76ee892STomi Valkeinen
1260f76ee892STomi Valkeinen if (use_fifomerge) {
1261f76ee892STomi Valkeinen total_fifo_size = 0;
1262f76ee892STomi Valkeinen for (i = 0; i < dss_feat_get_num_ovls(); ++i)
1263f76ee892STomi Valkeinen total_fifo_size += dispc_ovl_get_fifo_size(i);
1264f76ee892STomi Valkeinen } else {
1265f76ee892STomi Valkeinen total_fifo_size = ovl_fifo_size;
1266f76ee892STomi Valkeinen }
1267f76ee892STomi Valkeinen
1268f76ee892STomi Valkeinen /*
1269f76ee892STomi Valkeinen * We use the same low threshold for both fifomerge and non-fifomerge
1270f76ee892STomi Valkeinen * cases, but for fifomerge we calculate the high threshold using the
1271f76ee892STomi Valkeinen * combined fifo size
1272f76ee892STomi Valkeinen */
1273f76ee892STomi Valkeinen
1274f76ee892STomi Valkeinen if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1275f76ee892STomi Valkeinen *fifo_low = ovl_fifo_size - burst_size * 2;
1276f76ee892STomi Valkeinen *fifo_high = total_fifo_size - burst_size;
1277f76ee892STomi Valkeinen } else if (plane == OMAP_DSS_WB) {
1278f76ee892STomi Valkeinen /*
1279f76ee892STomi Valkeinen * Most optimal configuration for writeback is to push out data
1280f76ee892STomi Valkeinen * to the interconnect the moment writeback pushes enough pixels
1281f76ee892STomi Valkeinen * in the FIFO to form a burst
1282f76ee892STomi Valkeinen */
1283f76ee892STomi Valkeinen *fifo_low = 0;
1284f76ee892STomi Valkeinen *fifo_high = burst_size;
1285f76ee892STomi Valkeinen } else {
1286f76ee892STomi Valkeinen *fifo_low = ovl_fifo_size - burst_size;
1287f76ee892STomi Valkeinen *fifo_high = total_fifo_size - buf_unit;
1288f76ee892STomi Valkeinen }
1289f76ee892STomi Valkeinen }
1290f76ee892STomi Valkeinen
dispc_ovl_set_mflag(enum omap_plane plane,bool enable)1291f76ee892STomi Valkeinen static void dispc_ovl_set_mflag(enum omap_plane plane, bool enable)
1292f76ee892STomi Valkeinen {
1293f76ee892STomi Valkeinen int bit;
1294f76ee892STomi Valkeinen
1295f76ee892STomi Valkeinen if (plane == OMAP_DSS_GFX)
1296f76ee892STomi Valkeinen bit = 14;
1297f76ee892STomi Valkeinen else
1298f76ee892STomi Valkeinen bit = 23;
1299f76ee892STomi Valkeinen
1300f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1301f76ee892STomi Valkeinen }
1302f76ee892STomi Valkeinen
dispc_ovl_set_mflag_threshold(enum omap_plane plane,int low,int high)1303f76ee892STomi Valkeinen static void dispc_ovl_set_mflag_threshold(enum omap_plane plane,
1304f76ee892STomi Valkeinen int low, int high)
1305f76ee892STomi Valkeinen {
1306f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane),
1307f76ee892STomi Valkeinen FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1308f76ee892STomi Valkeinen }
1309f76ee892STomi Valkeinen
dispc_init_mflag(void)1310f76ee892STomi Valkeinen static void dispc_init_mflag(void)
1311f76ee892STomi Valkeinen {
1312f76ee892STomi Valkeinen int i;
1313f76ee892STomi Valkeinen
1314f76ee892STomi Valkeinen /*
1315f76ee892STomi Valkeinen * HACK: NV12 color format and MFLAG seem to have problems working
1316f76ee892STomi Valkeinen * together: using two displays, and having an NV12 overlay on one of
1317f76ee892STomi Valkeinen * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1318f76ee892STomi Valkeinen * Changing MFLAG thresholds and PRELOAD to certain values seem to
1319f76ee892STomi Valkeinen * remove the errors, but there doesn't seem to be a clear logic on
1320f76ee892STomi Valkeinen * which values work and which not.
1321f76ee892STomi Valkeinen *
1322f76ee892STomi Valkeinen * As a work-around, set force MFLAG to always on.
1323f76ee892STomi Valkeinen */
1324f76ee892STomi Valkeinen dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE,
1325f76ee892STomi Valkeinen (1 << 0) | /* MFLAG_CTRL = force always on */
1326f76ee892STomi Valkeinen (0 << 2)); /* MFLAG_START = disable */
1327f76ee892STomi Valkeinen
1328f76ee892STomi Valkeinen for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1329f76ee892STomi Valkeinen u32 size = dispc_ovl_get_fifo_size(i);
1330f76ee892STomi Valkeinen u32 unit = dss_feat_get_buffer_size_unit();
1331f76ee892STomi Valkeinen u32 low, high;
1332f76ee892STomi Valkeinen
1333f76ee892STomi Valkeinen dispc_ovl_set_mflag(i, true);
1334f76ee892STomi Valkeinen
1335f76ee892STomi Valkeinen /*
1336f76ee892STomi Valkeinen * Simulation team suggests below thesholds:
1337f76ee892STomi Valkeinen * HT = fifosize * 5 / 8;
1338f76ee892STomi Valkeinen * LT = fifosize * 4 / 8;
1339f76ee892STomi Valkeinen */
1340f76ee892STomi Valkeinen
1341f76ee892STomi Valkeinen low = size * 4 / 8 / unit;
1342f76ee892STomi Valkeinen high = size * 5 / 8 / unit;
1343f76ee892STomi Valkeinen
1344f76ee892STomi Valkeinen dispc_ovl_set_mflag_threshold(i, low, high);
1345f76ee892STomi Valkeinen }
1346f76ee892STomi Valkeinen
1347f76ee892STomi Valkeinen if (dispc.feat->has_writeback) {
1348f76ee892STomi Valkeinen u32 size = dispc_ovl_get_fifo_size(OMAP_DSS_WB);
1349f76ee892STomi Valkeinen u32 unit = dss_feat_get_buffer_size_unit();
1350f76ee892STomi Valkeinen u32 low, high;
1351f76ee892STomi Valkeinen
1352f76ee892STomi Valkeinen dispc_ovl_set_mflag(OMAP_DSS_WB, true);
1353f76ee892STomi Valkeinen
1354f76ee892STomi Valkeinen /*
1355f76ee892STomi Valkeinen * Simulation team suggests below thesholds:
1356f76ee892STomi Valkeinen * HT = fifosize * 5 / 8;
1357f76ee892STomi Valkeinen * LT = fifosize * 4 / 8;
1358f76ee892STomi Valkeinen */
1359f76ee892STomi Valkeinen
1360f76ee892STomi Valkeinen low = size * 4 / 8 / unit;
1361f76ee892STomi Valkeinen high = size * 5 / 8 / unit;
1362f76ee892STomi Valkeinen
1363f76ee892STomi Valkeinen dispc_ovl_set_mflag_threshold(OMAP_DSS_WB, low, high);
1364f76ee892STomi Valkeinen }
1365f76ee892STomi Valkeinen }
1366f76ee892STomi Valkeinen
dispc_ovl_set_fir(enum omap_plane plane,int hinc,int vinc,enum omap_color_component color_comp)1367f76ee892STomi Valkeinen static void dispc_ovl_set_fir(enum omap_plane plane,
1368f76ee892STomi Valkeinen int hinc, int vinc,
1369f76ee892STomi Valkeinen enum omap_color_component color_comp)
1370f76ee892STomi Valkeinen {
1371f76ee892STomi Valkeinen u32 val;
1372f76ee892STomi Valkeinen
1373f76ee892STomi Valkeinen if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1374f76ee892STomi Valkeinen u8 hinc_start, hinc_end, vinc_start, vinc_end;
1375f76ee892STomi Valkeinen
1376f76ee892STomi Valkeinen dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1377f76ee892STomi Valkeinen &hinc_start, &hinc_end);
1378f76ee892STomi Valkeinen dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1379f76ee892STomi Valkeinen &vinc_start, &vinc_end);
1380f76ee892STomi Valkeinen val = FLD_VAL(vinc, vinc_start, vinc_end) |
1381f76ee892STomi Valkeinen FLD_VAL(hinc, hinc_start, hinc_end);
1382f76ee892STomi Valkeinen
1383f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_FIR(plane), val);
1384f76ee892STomi Valkeinen } else {
1385f76ee892STomi Valkeinen val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1386f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1387f76ee892STomi Valkeinen }
1388f76ee892STomi Valkeinen }
1389f76ee892STomi Valkeinen
dispc_ovl_set_vid_accu0(enum omap_plane plane,int haccu,int vaccu)1390f76ee892STomi Valkeinen static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1391f76ee892STomi Valkeinen {
1392f76ee892STomi Valkeinen u32 val;
1393f76ee892STomi Valkeinen u8 hor_start, hor_end, vert_start, vert_end;
1394f76ee892STomi Valkeinen
1395f76ee892STomi Valkeinen dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1396f76ee892STomi Valkeinen dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1397f76ee892STomi Valkeinen
1398f76ee892STomi Valkeinen val = FLD_VAL(vaccu, vert_start, vert_end) |
1399f76ee892STomi Valkeinen FLD_VAL(haccu, hor_start, hor_end);
1400f76ee892STomi Valkeinen
1401f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
1402f76ee892STomi Valkeinen }
1403f76ee892STomi Valkeinen
dispc_ovl_set_vid_accu1(enum omap_plane plane,int haccu,int vaccu)1404f76ee892STomi Valkeinen static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1405f76ee892STomi Valkeinen {
1406f76ee892STomi Valkeinen u32 val;
1407f76ee892STomi Valkeinen u8 hor_start, hor_end, vert_start, vert_end;
1408f76ee892STomi Valkeinen
1409f76ee892STomi Valkeinen dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1410f76ee892STomi Valkeinen dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1411f76ee892STomi Valkeinen
1412f76ee892STomi Valkeinen val = FLD_VAL(vaccu, vert_start, vert_end) |
1413f76ee892STomi Valkeinen FLD_VAL(haccu, hor_start, hor_end);
1414f76ee892STomi Valkeinen
1415f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
1416f76ee892STomi Valkeinen }
1417f76ee892STomi Valkeinen
dispc_ovl_set_vid_accu2_0(enum omap_plane plane,int haccu,int vaccu)1418f76ee892STomi Valkeinen static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1419f76ee892STomi Valkeinen int vaccu)
1420f76ee892STomi Valkeinen {
1421f76ee892STomi Valkeinen u32 val;
1422f76ee892STomi Valkeinen
1423f76ee892STomi Valkeinen val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1424f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1425f76ee892STomi Valkeinen }
1426f76ee892STomi Valkeinen
dispc_ovl_set_vid_accu2_1(enum omap_plane plane,int haccu,int vaccu)1427f76ee892STomi Valkeinen static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1428f76ee892STomi Valkeinen int vaccu)
1429f76ee892STomi Valkeinen {
1430f76ee892STomi Valkeinen u32 val;
1431f76ee892STomi Valkeinen
1432f76ee892STomi Valkeinen val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1433f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1434f76ee892STomi Valkeinen }
1435f76ee892STomi Valkeinen
dispc_ovl_set_scale_param(enum omap_plane plane,u16 orig_width,u16 orig_height,u16 out_width,u16 out_height,bool five_taps,u8 rotation,enum omap_color_component color_comp)1436f76ee892STomi Valkeinen static void dispc_ovl_set_scale_param(enum omap_plane plane,
1437f76ee892STomi Valkeinen u16 orig_width, u16 orig_height,
1438f76ee892STomi Valkeinen u16 out_width, u16 out_height,
1439f76ee892STomi Valkeinen bool five_taps, u8 rotation,
1440f76ee892STomi Valkeinen enum omap_color_component color_comp)
1441f76ee892STomi Valkeinen {
1442f76ee892STomi Valkeinen int fir_hinc, fir_vinc;
1443f76ee892STomi Valkeinen
1444f76ee892STomi Valkeinen fir_hinc = 1024 * orig_width / out_width;
1445f76ee892STomi Valkeinen fir_vinc = 1024 * orig_height / out_height;
1446f76ee892STomi Valkeinen
1447f76ee892STomi Valkeinen dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1448f76ee892STomi Valkeinen color_comp);
1449f76ee892STomi Valkeinen dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1450f76ee892STomi Valkeinen }
1451f76ee892STomi Valkeinen
dispc_ovl_set_accu_uv(enum omap_plane plane,u16 orig_width,u16 orig_height,u16 out_width,u16 out_height,bool ilace,enum omap_color_mode color_mode,u8 rotation)1452f76ee892STomi Valkeinen static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1453f76ee892STomi Valkeinen u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1454f76ee892STomi Valkeinen bool ilace, enum omap_color_mode color_mode, u8 rotation)
1455f76ee892STomi Valkeinen {
1456f76ee892STomi Valkeinen int h_accu2_0, h_accu2_1;
1457f76ee892STomi Valkeinen int v_accu2_0, v_accu2_1;
1458f76ee892STomi Valkeinen int chroma_hinc, chroma_vinc;
1459f76ee892STomi Valkeinen int idx;
1460f76ee892STomi Valkeinen
1461f76ee892STomi Valkeinen struct accu {
1462f76ee892STomi Valkeinen s8 h0_m, h0_n;
1463f76ee892STomi Valkeinen s8 h1_m, h1_n;
1464f76ee892STomi Valkeinen s8 v0_m, v0_n;
1465f76ee892STomi Valkeinen s8 v1_m, v1_n;
1466f76ee892STomi Valkeinen };
1467f76ee892STomi Valkeinen
1468f76ee892STomi Valkeinen const struct accu *accu_table;
1469f76ee892STomi Valkeinen const struct accu *accu_val;
1470f76ee892STomi Valkeinen
1471f76ee892STomi Valkeinen static const struct accu accu_nv12[4] = {
1472f76ee892STomi Valkeinen { 0, 1, 0, 1 , -1, 2, 0, 1 },
1473f76ee892STomi Valkeinen { 1, 2, -3, 4 , 0, 1, 0, 1 },
1474f76ee892STomi Valkeinen { -1, 1, 0, 1 , -1, 2, 0, 1 },
1475f76ee892STomi Valkeinen { -1, 2, -1, 2 , -1, 1, 0, 1 },
1476f76ee892STomi Valkeinen };
1477f76ee892STomi Valkeinen
1478f76ee892STomi Valkeinen static const struct accu accu_nv12_ilace[4] = {
1479f76ee892STomi Valkeinen { 0, 1, 0, 1 , -3, 4, -1, 4 },
1480f76ee892STomi Valkeinen { -1, 4, -3, 4 , 0, 1, 0, 1 },
1481f76ee892STomi Valkeinen { -1, 1, 0, 1 , -1, 4, -3, 4 },
1482f76ee892STomi Valkeinen { -3, 4, -3, 4 , -1, 1, 0, 1 },
1483f76ee892STomi Valkeinen };
1484f76ee892STomi Valkeinen
1485f76ee892STomi Valkeinen static const struct accu accu_yuv[4] = {
1486f76ee892STomi Valkeinen { 0, 1, 0, 1, 0, 1, 0, 1 },
1487f76ee892STomi Valkeinen { 0, 1, 0, 1, 0, 1, 0, 1 },
1488f76ee892STomi Valkeinen { -1, 1, 0, 1, 0, 1, 0, 1 },
1489f76ee892STomi Valkeinen { 0, 1, 0, 1, -1, 1, 0, 1 },
1490f76ee892STomi Valkeinen };
1491f76ee892STomi Valkeinen
1492f76ee892STomi Valkeinen switch (rotation) {
1493f76ee892STomi Valkeinen case OMAP_DSS_ROT_0:
1494f76ee892STomi Valkeinen idx = 0;
1495f76ee892STomi Valkeinen break;
1496f76ee892STomi Valkeinen case OMAP_DSS_ROT_90:
1497f76ee892STomi Valkeinen idx = 1;
1498f76ee892STomi Valkeinen break;
1499f76ee892STomi Valkeinen case OMAP_DSS_ROT_180:
1500f76ee892STomi Valkeinen idx = 2;
1501f76ee892STomi Valkeinen break;
1502f76ee892STomi Valkeinen case OMAP_DSS_ROT_270:
1503f76ee892STomi Valkeinen idx = 3;
1504f76ee892STomi Valkeinen break;
1505f76ee892STomi Valkeinen default:
1506f76ee892STomi Valkeinen BUG();
1507f76ee892STomi Valkeinen return;
1508f76ee892STomi Valkeinen }
1509f76ee892STomi Valkeinen
1510f76ee892STomi Valkeinen switch (color_mode) {
1511f76ee892STomi Valkeinen case OMAP_DSS_COLOR_NV12:
1512f76ee892STomi Valkeinen if (ilace)
1513f76ee892STomi Valkeinen accu_table = accu_nv12_ilace;
1514f76ee892STomi Valkeinen else
1515f76ee892STomi Valkeinen accu_table = accu_nv12;
1516f76ee892STomi Valkeinen break;
1517f76ee892STomi Valkeinen case OMAP_DSS_COLOR_YUV2:
1518f76ee892STomi Valkeinen case OMAP_DSS_COLOR_UYVY:
1519f76ee892STomi Valkeinen accu_table = accu_yuv;
1520f76ee892STomi Valkeinen break;
1521f76ee892STomi Valkeinen default:
1522f76ee892STomi Valkeinen BUG();
1523f76ee892STomi Valkeinen return;
1524f76ee892STomi Valkeinen }
1525f76ee892STomi Valkeinen
1526f76ee892STomi Valkeinen accu_val = &accu_table[idx];
1527f76ee892STomi Valkeinen
1528f76ee892STomi Valkeinen chroma_hinc = 1024 * orig_width / out_width;
1529f76ee892STomi Valkeinen chroma_vinc = 1024 * orig_height / out_height;
1530f76ee892STomi Valkeinen
1531f76ee892STomi Valkeinen h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1532f76ee892STomi Valkeinen h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1533f76ee892STomi Valkeinen v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1534f76ee892STomi Valkeinen v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1535f76ee892STomi Valkeinen
1536f76ee892STomi Valkeinen dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1537f76ee892STomi Valkeinen dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1538f76ee892STomi Valkeinen }
1539f76ee892STomi Valkeinen
dispc_ovl_set_scaling_common(enum omap_plane plane,u16 orig_width,u16 orig_height,u16 out_width,u16 out_height,bool ilace,bool five_taps,bool fieldmode,enum omap_color_mode color_mode,u8 rotation)1540f76ee892STomi Valkeinen static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1541f76ee892STomi Valkeinen u16 orig_width, u16 orig_height,
1542f76ee892STomi Valkeinen u16 out_width, u16 out_height,
1543f76ee892STomi Valkeinen bool ilace, bool five_taps,
1544f76ee892STomi Valkeinen bool fieldmode, enum omap_color_mode color_mode,
1545f76ee892STomi Valkeinen u8 rotation)
1546f76ee892STomi Valkeinen {
1547f76ee892STomi Valkeinen int accu0 = 0;
1548f76ee892STomi Valkeinen int accu1 = 0;
1549f76ee892STomi Valkeinen u32 l;
1550f76ee892STomi Valkeinen
1551f76ee892STomi Valkeinen dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1552f76ee892STomi Valkeinen out_width, out_height, five_taps,
1553f76ee892STomi Valkeinen rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1554f76ee892STomi Valkeinen l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1555f76ee892STomi Valkeinen
1556f76ee892STomi Valkeinen /* RESIZEENABLE and VERTICALTAPS */
1557f76ee892STomi Valkeinen l &= ~((0x3 << 5) | (0x1 << 21));
1558f76ee892STomi Valkeinen l |= (orig_width != out_width) ? (1 << 5) : 0;
1559f76ee892STomi Valkeinen l |= (orig_height != out_height) ? (1 << 6) : 0;
1560f76ee892STomi Valkeinen l |= five_taps ? (1 << 21) : 0;
1561f76ee892STomi Valkeinen
1562f76ee892STomi Valkeinen /* VRESIZECONF and HRESIZECONF */
1563f76ee892STomi Valkeinen if (dss_has_feature(FEAT_RESIZECONF)) {
1564f76ee892STomi Valkeinen l &= ~(0x3 << 7);
1565f76ee892STomi Valkeinen l |= (orig_width <= out_width) ? 0 : (1 << 7);
1566f76ee892STomi Valkeinen l |= (orig_height <= out_height) ? 0 : (1 << 8);
1567f76ee892STomi Valkeinen }
1568f76ee892STomi Valkeinen
1569f76ee892STomi Valkeinen /* LINEBUFFERSPLIT */
1570f76ee892STomi Valkeinen if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1571f76ee892STomi Valkeinen l &= ~(0x1 << 22);
1572f76ee892STomi Valkeinen l |= five_taps ? (1 << 22) : 0;
1573f76ee892STomi Valkeinen }
1574f76ee892STomi Valkeinen
1575f76ee892STomi Valkeinen dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
1576f76ee892STomi Valkeinen
1577f76ee892STomi Valkeinen /*
1578f76ee892STomi Valkeinen * field 0 = even field = bottom field
1579f76ee892STomi Valkeinen * field 1 = odd field = top field
1580f76ee892STomi Valkeinen */
1581f76ee892STomi Valkeinen if (ilace && !fieldmode) {
1582f76ee892STomi Valkeinen accu1 = 0;
1583f76ee892STomi Valkeinen accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1584f76ee892STomi Valkeinen if (accu0 >= 1024/2) {
1585f76ee892STomi Valkeinen accu1 = 1024/2;
1586f76ee892STomi Valkeinen accu0 -= accu1;
1587f76ee892STomi Valkeinen }
1588f76ee892STomi Valkeinen }
1589f76ee892STomi Valkeinen
1590f76ee892STomi Valkeinen dispc_ovl_set_vid_accu0(plane, 0, accu0);
1591f76ee892STomi Valkeinen dispc_ovl_set_vid_accu1(plane, 0, accu1);
1592f76ee892STomi Valkeinen }
1593f76ee892STomi Valkeinen
dispc_ovl_set_scaling_uv(enum omap_plane plane,u16 orig_width,u16 orig_height,u16 out_width,u16 out_height,bool ilace,bool five_taps,bool fieldmode,enum omap_color_mode color_mode,u8 rotation)1594f76ee892STomi Valkeinen static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1595f76ee892STomi Valkeinen u16 orig_width, u16 orig_height,
1596f76ee892STomi Valkeinen u16 out_width, u16 out_height,
1597f76ee892STomi Valkeinen bool ilace, bool five_taps,
1598f76ee892STomi Valkeinen bool fieldmode, enum omap_color_mode color_mode,
1599f76ee892STomi Valkeinen u8 rotation)
1600f76ee892STomi Valkeinen {
1601f76ee892STomi Valkeinen int scale_x = out_width != orig_width;
1602f76ee892STomi Valkeinen int scale_y = out_height != orig_height;
160380805774SAndrew F. Davis bool chroma_upscale = plane != OMAP_DSS_WB;
1604f76ee892STomi Valkeinen
1605f76ee892STomi Valkeinen if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1606f76ee892STomi Valkeinen return;
1607f76ee892STomi Valkeinen if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1608f76ee892STomi Valkeinen color_mode != OMAP_DSS_COLOR_UYVY &&
1609f76ee892STomi Valkeinen color_mode != OMAP_DSS_COLOR_NV12)) {
1610f76ee892STomi Valkeinen /* reset chroma resampling for RGB formats */
1611f76ee892STomi Valkeinen if (plane != OMAP_DSS_WB)
1612f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1613f76ee892STomi Valkeinen return;
1614f76ee892STomi Valkeinen }
1615f76ee892STomi Valkeinen
1616f76ee892STomi Valkeinen dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1617f76ee892STomi Valkeinen out_height, ilace, color_mode, rotation);
1618f76ee892STomi Valkeinen
1619f76ee892STomi Valkeinen switch (color_mode) {
1620f76ee892STomi Valkeinen case OMAP_DSS_COLOR_NV12:
1621f76ee892STomi Valkeinen if (chroma_upscale) {
1622f76ee892STomi Valkeinen /* UV is subsampled by 2 horizontally and vertically */
1623f76ee892STomi Valkeinen orig_height >>= 1;
1624f76ee892STomi Valkeinen orig_width >>= 1;
1625f76ee892STomi Valkeinen } else {
1626f76ee892STomi Valkeinen /* UV is downsampled by 2 horizontally and vertically */
1627f76ee892STomi Valkeinen orig_height <<= 1;
1628f76ee892STomi Valkeinen orig_width <<= 1;
1629f76ee892STomi Valkeinen }
1630f76ee892STomi Valkeinen
1631f76ee892STomi Valkeinen break;
1632f76ee892STomi Valkeinen case OMAP_DSS_COLOR_YUV2:
1633f76ee892STomi Valkeinen case OMAP_DSS_COLOR_UYVY:
1634f76ee892STomi Valkeinen /* For YUV422 with 90/270 rotation, we don't upsample chroma */
1635f76ee892STomi Valkeinen if (rotation == OMAP_DSS_ROT_0 ||
1636f76ee892STomi Valkeinen rotation == OMAP_DSS_ROT_180) {
1637f76ee892STomi Valkeinen if (chroma_upscale)
1638f76ee892STomi Valkeinen /* UV is subsampled by 2 horizontally */
1639f76ee892STomi Valkeinen orig_width >>= 1;
1640f76ee892STomi Valkeinen else
1641f76ee892STomi Valkeinen /* UV is downsampled by 2 horizontally */
1642f76ee892STomi Valkeinen orig_width <<= 1;
1643f76ee892STomi Valkeinen }
1644f76ee892STomi Valkeinen
1645f76ee892STomi Valkeinen /* must use FIR for YUV422 if rotated */
1646f76ee892STomi Valkeinen if (rotation != OMAP_DSS_ROT_0)
1647f76ee892STomi Valkeinen scale_x = scale_y = true;
1648f76ee892STomi Valkeinen
1649f76ee892STomi Valkeinen break;
1650f76ee892STomi Valkeinen default:
1651f76ee892STomi Valkeinen BUG();
1652f76ee892STomi Valkeinen return;
1653f76ee892STomi Valkeinen }
1654f76ee892STomi Valkeinen
1655f76ee892STomi Valkeinen if (out_width != orig_width)
1656f76ee892STomi Valkeinen scale_x = true;
1657f76ee892STomi Valkeinen if (out_height != orig_height)
1658f76ee892STomi Valkeinen scale_y = true;
1659f76ee892STomi Valkeinen
1660f76ee892STomi Valkeinen dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1661f76ee892STomi Valkeinen out_width, out_height, five_taps,
1662f76ee892STomi Valkeinen rotation, DISPC_COLOR_COMPONENT_UV);
1663f76ee892STomi Valkeinen
1664f76ee892STomi Valkeinen if (plane != OMAP_DSS_WB)
1665f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1666f76ee892STomi Valkeinen (scale_x || scale_y) ? 1 : 0, 8, 8);
1667f76ee892STomi Valkeinen
1668f76ee892STomi Valkeinen /* set H scaling */
1669f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1670f76ee892STomi Valkeinen /* set V scaling */
1671f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1672f76ee892STomi Valkeinen }
1673f76ee892STomi Valkeinen
dispc_ovl_set_scaling(enum omap_plane plane,u16 orig_width,u16 orig_height,u16 out_width,u16 out_height,bool ilace,bool five_taps,bool fieldmode,enum omap_color_mode color_mode,u8 rotation)1674f76ee892STomi Valkeinen static void dispc_ovl_set_scaling(enum omap_plane plane,
1675f76ee892STomi Valkeinen u16 orig_width, u16 orig_height,
1676f76ee892STomi Valkeinen u16 out_width, u16 out_height,
1677f76ee892STomi Valkeinen bool ilace, bool five_taps,
1678f76ee892STomi Valkeinen bool fieldmode, enum omap_color_mode color_mode,
1679f76ee892STomi Valkeinen u8 rotation)
1680f76ee892STomi Valkeinen {
1681f76ee892STomi Valkeinen BUG_ON(plane == OMAP_DSS_GFX);
1682f76ee892STomi Valkeinen
1683f76ee892STomi Valkeinen dispc_ovl_set_scaling_common(plane,
1684f76ee892STomi Valkeinen orig_width, orig_height,
1685f76ee892STomi Valkeinen out_width, out_height,
1686f76ee892STomi Valkeinen ilace, five_taps,
1687f76ee892STomi Valkeinen fieldmode, color_mode,
1688f76ee892STomi Valkeinen rotation);
1689f76ee892STomi Valkeinen
1690f76ee892STomi Valkeinen dispc_ovl_set_scaling_uv(plane,
1691f76ee892STomi Valkeinen orig_width, orig_height,
1692f76ee892STomi Valkeinen out_width, out_height,
1693f76ee892STomi Valkeinen ilace, five_taps,
1694f76ee892STomi Valkeinen fieldmode, color_mode,
1695f76ee892STomi Valkeinen rotation);
1696f76ee892STomi Valkeinen }
1697f76ee892STomi Valkeinen
dispc_ovl_set_rotation_attrs(enum omap_plane plane,u8 rotation,enum omap_dss_rotation_type rotation_type,bool mirroring,enum omap_color_mode color_mode)1698f76ee892STomi Valkeinen static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1699f76ee892STomi Valkeinen enum omap_dss_rotation_type rotation_type,
1700f76ee892STomi Valkeinen bool mirroring, enum omap_color_mode color_mode)
1701f76ee892STomi Valkeinen {
1702f76ee892STomi Valkeinen bool row_repeat = false;
1703f76ee892STomi Valkeinen int vidrot = 0;
1704f76ee892STomi Valkeinen
1705f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1706f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_UYVY) {
1707f76ee892STomi Valkeinen
1708f76ee892STomi Valkeinen if (mirroring) {
1709f76ee892STomi Valkeinen switch (rotation) {
1710f76ee892STomi Valkeinen case OMAP_DSS_ROT_0:
1711f76ee892STomi Valkeinen vidrot = 2;
1712f76ee892STomi Valkeinen break;
1713f76ee892STomi Valkeinen case OMAP_DSS_ROT_90:
1714f76ee892STomi Valkeinen vidrot = 1;
1715f76ee892STomi Valkeinen break;
1716f76ee892STomi Valkeinen case OMAP_DSS_ROT_180:
1717f76ee892STomi Valkeinen vidrot = 0;
1718f76ee892STomi Valkeinen break;
1719f76ee892STomi Valkeinen case OMAP_DSS_ROT_270:
1720f76ee892STomi Valkeinen vidrot = 3;
1721f76ee892STomi Valkeinen break;
1722f76ee892STomi Valkeinen }
1723f76ee892STomi Valkeinen } else {
1724f76ee892STomi Valkeinen switch (rotation) {
1725f76ee892STomi Valkeinen case OMAP_DSS_ROT_0:
1726f76ee892STomi Valkeinen vidrot = 0;
1727f76ee892STomi Valkeinen break;
1728f76ee892STomi Valkeinen case OMAP_DSS_ROT_90:
1729f76ee892STomi Valkeinen vidrot = 1;
1730f76ee892STomi Valkeinen break;
1731f76ee892STomi Valkeinen case OMAP_DSS_ROT_180:
1732f76ee892STomi Valkeinen vidrot = 2;
1733f76ee892STomi Valkeinen break;
1734f76ee892STomi Valkeinen case OMAP_DSS_ROT_270:
1735f76ee892STomi Valkeinen vidrot = 3;
1736f76ee892STomi Valkeinen break;
1737f76ee892STomi Valkeinen }
1738f76ee892STomi Valkeinen }
1739f76ee892STomi Valkeinen
1740f76ee892STomi Valkeinen if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1741f76ee892STomi Valkeinen row_repeat = true;
1742f76ee892STomi Valkeinen else
1743f76ee892STomi Valkeinen row_repeat = false;
1744f76ee892STomi Valkeinen }
1745f76ee892STomi Valkeinen
1746f76ee892STomi Valkeinen /*
1747f76ee892STomi Valkeinen * OMAP4/5 Errata i631:
1748f76ee892STomi Valkeinen * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
1749f76ee892STomi Valkeinen * rows beyond the framebuffer, which may cause OCP error.
1750f76ee892STomi Valkeinen */
1751f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_NV12 &&
1752f76ee892STomi Valkeinen rotation_type != OMAP_DSS_ROT_TILER)
1753f76ee892STomi Valkeinen vidrot = 1;
1754f76ee892STomi Valkeinen
1755f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
1756f76ee892STomi Valkeinen if (dss_has_feature(FEAT_ROWREPEATENABLE))
1757f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1758f76ee892STomi Valkeinen row_repeat ? 1 : 0, 18, 18);
1759f76ee892STomi Valkeinen
1760f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_NV12) {
1761f76ee892STomi Valkeinen bool doublestride = (rotation_type == OMAP_DSS_ROT_TILER) &&
1762f76ee892STomi Valkeinen (rotation == OMAP_DSS_ROT_0 ||
1763f76ee892STomi Valkeinen rotation == OMAP_DSS_ROT_180);
1764f76ee892STomi Valkeinen /* DOUBLESTRIDE */
1765f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22);
1766f76ee892STomi Valkeinen }
1767f76ee892STomi Valkeinen
1768f76ee892STomi Valkeinen }
1769f76ee892STomi Valkeinen
color_mode_to_bpp(enum omap_color_mode color_mode)1770f76ee892STomi Valkeinen static int color_mode_to_bpp(enum omap_color_mode color_mode)
1771f76ee892STomi Valkeinen {
1772f76ee892STomi Valkeinen switch (color_mode) {
1773f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT1:
1774f76ee892STomi Valkeinen return 1;
1775f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT2:
1776f76ee892STomi Valkeinen return 2;
1777f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT4:
1778f76ee892STomi Valkeinen return 4;
1779f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT8:
1780f76ee892STomi Valkeinen case OMAP_DSS_COLOR_NV12:
1781f76ee892STomi Valkeinen return 8;
1782f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB12U:
1783f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB16:
1784f76ee892STomi Valkeinen case OMAP_DSS_COLOR_ARGB16:
1785f76ee892STomi Valkeinen case OMAP_DSS_COLOR_YUV2:
1786f76ee892STomi Valkeinen case OMAP_DSS_COLOR_UYVY:
1787f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBA16:
1788f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBX16:
1789f76ee892STomi Valkeinen case OMAP_DSS_COLOR_ARGB16_1555:
1790f76ee892STomi Valkeinen case OMAP_DSS_COLOR_XRGB16_1555:
1791f76ee892STomi Valkeinen return 16;
1792f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB24P:
1793f76ee892STomi Valkeinen return 24;
1794f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGB24U:
1795f76ee892STomi Valkeinen case OMAP_DSS_COLOR_ARGB32:
1796f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBA32:
1797f76ee892STomi Valkeinen case OMAP_DSS_COLOR_RGBX32:
1798f76ee892STomi Valkeinen return 32;
1799f76ee892STomi Valkeinen default:
1800f76ee892STomi Valkeinen BUG();
1801f76ee892STomi Valkeinen return 0;
1802f76ee892STomi Valkeinen }
1803f76ee892STomi Valkeinen }
1804f76ee892STomi Valkeinen
pixinc(int pixels,u8 ps)1805f76ee892STomi Valkeinen static s32 pixinc(int pixels, u8 ps)
1806f76ee892STomi Valkeinen {
1807f76ee892STomi Valkeinen if (pixels == 1)
1808f76ee892STomi Valkeinen return 1;
1809f76ee892STomi Valkeinen else if (pixels > 1)
1810f76ee892STomi Valkeinen return 1 + (pixels - 1) * ps;
1811f76ee892STomi Valkeinen else if (pixels < 0)
1812f76ee892STomi Valkeinen return 1 - (-pixels + 1) * ps;
1813f76ee892STomi Valkeinen else
1814f76ee892STomi Valkeinen BUG();
1815f76ee892STomi Valkeinen return 0;
1816f76ee892STomi Valkeinen }
1817f76ee892STomi Valkeinen
calc_vrfb_rotation_offset(u8 rotation,bool mirror,u16 screen_width,u16 width,u16 height,enum omap_color_mode color_mode,bool fieldmode,unsigned int field_offset,unsigned * offset0,unsigned * offset1,s32 * row_inc,s32 * pix_inc,int x_predecim,int y_predecim)1818f76ee892STomi Valkeinen static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1819f76ee892STomi Valkeinen u16 screen_width,
1820f76ee892STomi Valkeinen u16 width, u16 height,
1821f76ee892STomi Valkeinen enum omap_color_mode color_mode, bool fieldmode,
1822f76ee892STomi Valkeinen unsigned int field_offset,
1823f76ee892STomi Valkeinen unsigned *offset0, unsigned *offset1,
1824f76ee892STomi Valkeinen s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1825f76ee892STomi Valkeinen {
1826f76ee892STomi Valkeinen u8 ps;
1827f76ee892STomi Valkeinen
1828f76ee892STomi Valkeinen /* FIXME CLUT formats */
1829f76ee892STomi Valkeinen switch (color_mode) {
1830f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT1:
1831f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT2:
1832f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT4:
1833f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT8:
1834f76ee892STomi Valkeinen BUG();
1835f76ee892STomi Valkeinen return;
1836f76ee892STomi Valkeinen case OMAP_DSS_COLOR_YUV2:
1837f76ee892STomi Valkeinen case OMAP_DSS_COLOR_UYVY:
1838f76ee892STomi Valkeinen ps = 4;
1839f76ee892STomi Valkeinen break;
1840f76ee892STomi Valkeinen default:
1841f76ee892STomi Valkeinen ps = color_mode_to_bpp(color_mode) / 8;
1842f76ee892STomi Valkeinen break;
1843f76ee892STomi Valkeinen }
1844f76ee892STomi Valkeinen
1845f76ee892STomi Valkeinen DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1846f76ee892STomi Valkeinen width, height);
1847f76ee892STomi Valkeinen
1848f76ee892STomi Valkeinen /*
1849f76ee892STomi Valkeinen * field 0 = even field = bottom field
1850f76ee892STomi Valkeinen * field 1 = odd field = top field
1851f76ee892STomi Valkeinen */
1852f76ee892STomi Valkeinen switch (rotation + mirror * 4) {
1853f76ee892STomi Valkeinen case OMAP_DSS_ROT_0:
1854f76ee892STomi Valkeinen case OMAP_DSS_ROT_180:
1855f76ee892STomi Valkeinen /*
1856f76ee892STomi Valkeinen * If the pixel format is YUV or UYVY divide the width
1857f76ee892STomi Valkeinen * of the image by 2 for 0 and 180 degree rotation.
1858f76ee892STomi Valkeinen */
1859f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1860f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_UYVY)
1861f76ee892STomi Valkeinen width = width >> 1;
1862df561f66SGustavo A. R. Silva fallthrough;
1863f76ee892STomi Valkeinen case OMAP_DSS_ROT_90:
1864f76ee892STomi Valkeinen case OMAP_DSS_ROT_270:
1865f76ee892STomi Valkeinen *offset1 = 0;
1866f76ee892STomi Valkeinen if (field_offset)
1867f76ee892STomi Valkeinen *offset0 = field_offset * screen_width * ps;
1868f76ee892STomi Valkeinen else
1869f76ee892STomi Valkeinen *offset0 = 0;
1870f76ee892STomi Valkeinen
1871f76ee892STomi Valkeinen *row_inc = pixinc(1 +
1872f76ee892STomi Valkeinen (y_predecim * screen_width - x_predecim * width) +
1873f76ee892STomi Valkeinen (fieldmode ? screen_width : 0), ps);
1874f76ee892STomi Valkeinen *pix_inc = pixinc(x_predecim, ps);
1875f76ee892STomi Valkeinen break;
1876f76ee892STomi Valkeinen
1877f76ee892STomi Valkeinen case OMAP_DSS_ROT_0 + 4:
1878f76ee892STomi Valkeinen case OMAP_DSS_ROT_180 + 4:
1879f76ee892STomi Valkeinen /* If the pixel format is YUV or UYVY divide the width
1880f76ee892STomi Valkeinen * of the image by 2 for 0 degree and 180 degree
1881f76ee892STomi Valkeinen */
1882f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1883f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_UYVY)
1884f76ee892STomi Valkeinen width = width >> 1;
1885df561f66SGustavo A. R. Silva fallthrough;
1886f76ee892STomi Valkeinen case OMAP_DSS_ROT_90 + 4:
1887f76ee892STomi Valkeinen case OMAP_DSS_ROT_270 + 4:
1888f76ee892STomi Valkeinen *offset1 = 0;
1889f76ee892STomi Valkeinen if (field_offset)
1890f76ee892STomi Valkeinen *offset0 = field_offset * screen_width * ps;
1891f76ee892STomi Valkeinen else
1892f76ee892STomi Valkeinen *offset0 = 0;
1893f76ee892STomi Valkeinen *row_inc = pixinc(1 -
1894f76ee892STomi Valkeinen (y_predecim * screen_width + x_predecim * width) -
1895f76ee892STomi Valkeinen (fieldmode ? screen_width : 0), ps);
1896f76ee892STomi Valkeinen *pix_inc = pixinc(x_predecim, ps);
1897f76ee892STomi Valkeinen break;
1898f76ee892STomi Valkeinen
1899f76ee892STomi Valkeinen default:
1900f76ee892STomi Valkeinen BUG();
1901f76ee892STomi Valkeinen return;
1902f76ee892STomi Valkeinen }
1903f76ee892STomi Valkeinen }
1904f76ee892STomi Valkeinen
calc_dma_rotation_offset(u8 rotation,bool mirror,u16 screen_width,u16 width,u16 height,enum omap_color_mode color_mode,bool fieldmode,unsigned int field_offset,unsigned * offset0,unsigned * offset1,s32 * row_inc,s32 * pix_inc,int x_predecim,int y_predecim)1905f76ee892STomi Valkeinen static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1906f76ee892STomi Valkeinen u16 screen_width,
1907f76ee892STomi Valkeinen u16 width, u16 height,
1908f76ee892STomi Valkeinen enum omap_color_mode color_mode, bool fieldmode,
1909f76ee892STomi Valkeinen unsigned int field_offset,
1910f76ee892STomi Valkeinen unsigned *offset0, unsigned *offset1,
1911f76ee892STomi Valkeinen s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1912f76ee892STomi Valkeinen {
1913f76ee892STomi Valkeinen u8 ps;
1914f76ee892STomi Valkeinen u16 fbw, fbh;
1915f76ee892STomi Valkeinen
1916f76ee892STomi Valkeinen /* FIXME CLUT formats */
1917f76ee892STomi Valkeinen switch (color_mode) {
1918f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT1:
1919f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT2:
1920f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT4:
1921f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT8:
1922f76ee892STomi Valkeinen BUG();
1923f76ee892STomi Valkeinen return;
1924f76ee892STomi Valkeinen default:
1925f76ee892STomi Valkeinen ps = color_mode_to_bpp(color_mode) / 8;
1926f76ee892STomi Valkeinen break;
1927f76ee892STomi Valkeinen }
1928f76ee892STomi Valkeinen
1929f76ee892STomi Valkeinen DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1930f76ee892STomi Valkeinen width, height);
1931f76ee892STomi Valkeinen
1932f76ee892STomi Valkeinen /* width & height are overlay sizes, convert to fb sizes */
1933f76ee892STomi Valkeinen
1934f76ee892STomi Valkeinen if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1935f76ee892STomi Valkeinen fbw = width;
1936f76ee892STomi Valkeinen fbh = height;
1937f76ee892STomi Valkeinen } else {
1938f76ee892STomi Valkeinen fbw = height;
1939f76ee892STomi Valkeinen fbh = width;
1940f76ee892STomi Valkeinen }
1941f76ee892STomi Valkeinen
1942f76ee892STomi Valkeinen /*
1943f76ee892STomi Valkeinen * field 0 = even field = bottom field
1944f76ee892STomi Valkeinen * field 1 = odd field = top field
1945f76ee892STomi Valkeinen */
1946f76ee892STomi Valkeinen switch (rotation + mirror * 4) {
1947f76ee892STomi Valkeinen case OMAP_DSS_ROT_0:
1948f76ee892STomi Valkeinen *offset1 = 0;
1949f76ee892STomi Valkeinen if (field_offset)
1950f76ee892STomi Valkeinen *offset0 = *offset1 + field_offset * screen_width * ps;
1951f76ee892STomi Valkeinen else
1952f76ee892STomi Valkeinen *offset0 = *offset1;
1953f76ee892STomi Valkeinen *row_inc = pixinc(1 +
1954f76ee892STomi Valkeinen (y_predecim * screen_width - fbw * x_predecim) +
1955f76ee892STomi Valkeinen (fieldmode ? screen_width : 0), ps);
1956f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1957f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_UYVY)
1958f76ee892STomi Valkeinen *pix_inc = pixinc(x_predecim, 2 * ps);
1959f76ee892STomi Valkeinen else
1960f76ee892STomi Valkeinen *pix_inc = pixinc(x_predecim, ps);
1961f76ee892STomi Valkeinen break;
1962f76ee892STomi Valkeinen case OMAP_DSS_ROT_90:
1963f76ee892STomi Valkeinen *offset1 = screen_width * (fbh - 1) * ps;
1964f76ee892STomi Valkeinen if (field_offset)
1965f76ee892STomi Valkeinen *offset0 = *offset1 + field_offset * ps;
1966f76ee892STomi Valkeinen else
1967f76ee892STomi Valkeinen *offset0 = *offset1;
1968f76ee892STomi Valkeinen *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1969f76ee892STomi Valkeinen y_predecim + (fieldmode ? 1 : 0), ps);
1970f76ee892STomi Valkeinen *pix_inc = pixinc(-x_predecim * screen_width, ps);
1971f76ee892STomi Valkeinen break;
1972f76ee892STomi Valkeinen case OMAP_DSS_ROT_180:
1973f76ee892STomi Valkeinen *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1974f76ee892STomi Valkeinen if (field_offset)
1975f76ee892STomi Valkeinen *offset0 = *offset1 - field_offset * screen_width * ps;
1976f76ee892STomi Valkeinen else
1977f76ee892STomi Valkeinen *offset0 = *offset1;
1978f76ee892STomi Valkeinen *row_inc = pixinc(-1 -
1979f76ee892STomi Valkeinen (y_predecim * screen_width - fbw * x_predecim) -
1980f76ee892STomi Valkeinen (fieldmode ? screen_width : 0), ps);
1981f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1982f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_UYVY)
1983f76ee892STomi Valkeinen *pix_inc = pixinc(-x_predecim, 2 * ps);
1984f76ee892STomi Valkeinen else
1985f76ee892STomi Valkeinen *pix_inc = pixinc(-x_predecim, ps);
1986f76ee892STomi Valkeinen break;
1987f76ee892STomi Valkeinen case OMAP_DSS_ROT_270:
1988f76ee892STomi Valkeinen *offset1 = (fbw - 1) * ps;
1989f76ee892STomi Valkeinen if (field_offset)
1990f76ee892STomi Valkeinen *offset0 = *offset1 - field_offset * ps;
1991f76ee892STomi Valkeinen else
1992f76ee892STomi Valkeinen *offset0 = *offset1;
1993f76ee892STomi Valkeinen *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1994f76ee892STomi Valkeinen y_predecim - (fieldmode ? 1 : 0), ps);
1995f76ee892STomi Valkeinen *pix_inc = pixinc(x_predecim * screen_width, ps);
1996f76ee892STomi Valkeinen break;
1997f76ee892STomi Valkeinen
1998f76ee892STomi Valkeinen /* mirroring */
1999f76ee892STomi Valkeinen case OMAP_DSS_ROT_0 + 4:
2000f76ee892STomi Valkeinen *offset1 = (fbw - 1) * ps;
2001f76ee892STomi Valkeinen if (field_offset)
2002f76ee892STomi Valkeinen *offset0 = *offset1 + field_offset * screen_width * ps;
2003f76ee892STomi Valkeinen else
2004f76ee892STomi Valkeinen *offset0 = *offset1;
2005f76ee892STomi Valkeinen *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
2006f76ee892STomi Valkeinen (fieldmode ? screen_width : 0),
2007f76ee892STomi Valkeinen ps);
2008f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2009f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_UYVY)
2010f76ee892STomi Valkeinen *pix_inc = pixinc(-x_predecim, 2 * ps);
2011f76ee892STomi Valkeinen else
2012f76ee892STomi Valkeinen *pix_inc = pixinc(-x_predecim, ps);
2013f76ee892STomi Valkeinen break;
2014f76ee892STomi Valkeinen
2015f76ee892STomi Valkeinen case OMAP_DSS_ROT_90 + 4:
2016f76ee892STomi Valkeinen *offset1 = 0;
2017f76ee892STomi Valkeinen if (field_offset)
2018f76ee892STomi Valkeinen *offset0 = *offset1 + field_offset * ps;
2019f76ee892STomi Valkeinen else
2020f76ee892STomi Valkeinen *offset0 = *offset1;
2021f76ee892STomi Valkeinen *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
2022f76ee892STomi Valkeinen y_predecim + (fieldmode ? 1 : 0),
2023f76ee892STomi Valkeinen ps);
2024f76ee892STomi Valkeinen *pix_inc = pixinc(x_predecim * screen_width, ps);
2025f76ee892STomi Valkeinen break;
2026f76ee892STomi Valkeinen
2027f76ee892STomi Valkeinen case OMAP_DSS_ROT_180 + 4:
2028f76ee892STomi Valkeinen *offset1 = screen_width * (fbh - 1) * ps;
2029f76ee892STomi Valkeinen if (field_offset)
2030f76ee892STomi Valkeinen *offset0 = *offset1 - field_offset * screen_width * ps;
2031f76ee892STomi Valkeinen else
2032f76ee892STomi Valkeinen *offset0 = *offset1;
2033f76ee892STomi Valkeinen *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
2034f76ee892STomi Valkeinen (fieldmode ? screen_width : 0),
2035f76ee892STomi Valkeinen ps);
2036f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2037f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_UYVY)
2038f76ee892STomi Valkeinen *pix_inc = pixinc(x_predecim, 2 * ps);
2039f76ee892STomi Valkeinen else
2040f76ee892STomi Valkeinen *pix_inc = pixinc(x_predecim, ps);
2041f76ee892STomi Valkeinen break;
2042f76ee892STomi Valkeinen
2043f76ee892STomi Valkeinen case OMAP_DSS_ROT_270 + 4:
2044f76ee892STomi Valkeinen *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
2045f76ee892STomi Valkeinen if (field_offset)
2046f76ee892STomi Valkeinen *offset0 = *offset1 - field_offset * ps;
2047f76ee892STomi Valkeinen else
2048f76ee892STomi Valkeinen *offset0 = *offset1;
2049f76ee892STomi Valkeinen *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
2050f76ee892STomi Valkeinen y_predecim - (fieldmode ? 1 : 0),
2051f76ee892STomi Valkeinen ps);
2052f76ee892STomi Valkeinen *pix_inc = pixinc(-x_predecim * screen_width, ps);
2053f76ee892STomi Valkeinen break;
2054f76ee892STomi Valkeinen
2055f76ee892STomi Valkeinen default:
2056f76ee892STomi Valkeinen BUG();
2057f76ee892STomi Valkeinen return;
2058f76ee892STomi Valkeinen }
2059f76ee892STomi Valkeinen }
2060f76ee892STomi Valkeinen
calc_tiler_rotation_offset(u16 screen_width,u16 width,enum omap_color_mode color_mode,bool fieldmode,unsigned int field_offset,unsigned * offset0,unsigned * offset1,s32 * row_inc,s32 * pix_inc,int x_predecim,int y_predecim)2061f76ee892STomi Valkeinen static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
2062f76ee892STomi Valkeinen enum omap_color_mode color_mode, bool fieldmode,
2063f76ee892STomi Valkeinen unsigned int field_offset, unsigned *offset0, unsigned *offset1,
2064f76ee892STomi Valkeinen s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
2065f76ee892STomi Valkeinen {
2066f76ee892STomi Valkeinen u8 ps;
2067f76ee892STomi Valkeinen
2068f76ee892STomi Valkeinen switch (color_mode) {
2069f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT1:
2070f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT2:
2071f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT4:
2072f76ee892STomi Valkeinen case OMAP_DSS_COLOR_CLUT8:
2073f76ee892STomi Valkeinen BUG();
2074f76ee892STomi Valkeinen return;
2075f76ee892STomi Valkeinen default:
2076f76ee892STomi Valkeinen ps = color_mode_to_bpp(color_mode) / 8;
2077f76ee892STomi Valkeinen break;
2078f76ee892STomi Valkeinen }
2079f76ee892STomi Valkeinen
2080f76ee892STomi Valkeinen DSSDBG("scrw %d, width %d\n", screen_width, width);
2081f76ee892STomi Valkeinen
2082f76ee892STomi Valkeinen /*
2083f76ee892STomi Valkeinen * field 0 = even field = bottom field
2084f76ee892STomi Valkeinen * field 1 = odd field = top field
2085f76ee892STomi Valkeinen */
2086f76ee892STomi Valkeinen *offset1 = 0;
2087f76ee892STomi Valkeinen if (field_offset)
2088f76ee892STomi Valkeinen *offset0 = *offset1 + field_offset * screen_width * ps;
2089f76ee892STomi Valkeinen else
2090f76ee892STomi Valkeinen *offset0 = *offset1;
2091f76ee892STomi Valkeinen *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
2092f76ee892STomi Valkeinen (fieldmode ? screen_width : 0), ps);
2093f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2094f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_UYVY)
2095f76ee892STomi Valkeinen *pix_inc = pixinc(x_predecim, 2 * ps);
2096f76ee892STomi Valkeinen else
2097f76ee892STomi Valkeinen *pix_inc = pixinc(x_predecim, ps);
2098f76ee892STomi Valkeinen }
2099f76ee892STomi Valkeinen
2100f76ee892STomi Valkeinen /*
2101f76ee892STomi Valkeinen * This function is used to avoid synclosts in OMAP3, because of some
2102f76ee892STomi Valkeinen * undocumented horizontal position and timing related limitations.
2103f76ee892STomi Valkeinen */
check_horiz_timing_omap3(unsigned long pclk,unsigned long lclk,const struct omap_video_timings * t,u16 pos_x,u16 width,u16 height,u16 out_width,u16 out_height,bool five_taps)2104f76ee892STomi Valkeinen static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
2105f76ee892STomi Valkeinen const struct omap_video_timings *t, u16 pos_x,
2106f76ee892STomi Valkeinen u16 width, u16 height, u16 out_width, u16 out_height,
2107f76ee892STomi Valkeinen bool five_taps)
2108f76ee892STomi Valkeinen {
2109f76ee892STomi Valkeinen const int ds = DIV_ROUND_UP(height, out_height);
2110f76ee892STomi Valkeinen unsigned long nonactive;
2111f76ee892STomi Valkeinen static const u8 limits[3] = { 8, 10, 20 };
2112f76ee892STomi Valkeinen u64 val, blank;
2113f76ee892STomi Valkeinen int i;
2114f76ee892STomi Valkeinen
2115f76ee892STomi Valkeinen nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
2116f76ee892STomi Valkeinen
2117f76ee892STomi Valkeinen i = 0;
2118f76ee892STomi Valkeinen if (out_height < height)
2119f76ee892STomi Valkeinen i++;
2120f76ee892STomi Valkeinen if (out_width < width)
2121f76ee892STomi Valkeinen i++;
2122f76ee892STomi Valkeinen blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
2123f76ee892STomi Valkeinen DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2124f76ee892STomi Valkeinen if (blank <= limits[i])
2125f76ee892STomi Valkeinen return -EINVAL;
2126f76ee892STomi Valkeinen
2127f76ee892STomi Valkeinen /* FIXME add checks for 3-tap filter once the limitations are known */
2128f76ee892STomi Valkeinen if (!five_taps)
2129f76ee892STomi Valkeinen return 0;
2130f76ee892STomi Valkeinen
2131f76ee892STomi Valkeinen /*
2132f76ee892STomi Valkeinen * Pixel data should be prepared before visible display point starts.
2133f76ee892STomi Valkeinen * So, atleast DS-2 lines must have already been fetched by DISPC
2134f76ee892STomi Valkeinen * during nonactive - pos_x period.
2135f76ee892STomi Valkeinen */
2136f76ee892STomi Valkeinen val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2137f76ee892STomi Valkeinen DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2138f76ee892STomi Valkeinen val, max(0, ds - 2) * width);
2139f76ee892STomi Valkeinen if (val < max(0, ds - 2) * width)
2140f76ee892STomi Valkeinen return -EINVAL;
2141f76ee892STomi Valkeinen
2142f76ee892STomi Valkeinen /*
2143f76ee892STomi Valkeinen * All lines need to be refilled during the nonactive period of which
2144f76ee892STomi Valkeinen * only one line can be loaded during the active period. So, atleast
2145f76ee892STomi Valkeinen * DS - 1 lines should be loaded during nonactive period.
2146f76ee892STomi Valkeinen */
2147f76ee892STomi Valkeinen val = div_u64((u64)nonactive * lclk, pclk);
2148f76ee892STomi Valkeinen DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
2149f76ee892STomi Valkeinen val, max(0, ds - 1) * width);
2150f76ee892STomi Valkeinen if (val < max(0, ds - 1) * width)
2151f76ee892STomi Valkeinen return -EINVAL;
2152f76ee892STomi Valkeinen
2153f76ee892STomi Valkeinen return 0;
2154f76ee892STomi Valkeinen }
2155f76ee892STomi Valkeinen
calc_core_clk_five_taps(unsigned long pclk,const struct omap_video_timings * mgr_timings,u16 width,u16 height,u16 out_width,u16 out_height,enum omap_color_mode color_mode)2156f76ee892STomi Valkeinen static unsigned long calc_core_clk_five_taps(unsigned long pclk,
2157f76ee892STomi Valkeinen const struct omap_video_timings *mgr_timings, u16 width,
2158f76ee892STomi Valkeinen u16 height, u16 out_width, u16 out_height,
2159f76ee892STomi Valkeinen enum omap_color_mode color_mode)
2160f76ee892STomi Valkeinen {
2161f76ee892STomi Valkeinen u32 core_clk = 0;
2162f76ee892STomi Valkeinen u64 tmp;
2163f76ee892STomi Valkeinen
2164f76ee892STomi Valkeinen if (height <= out_height && width <= out_width)
2165f76ee892STomi Valkeinen return (unsigned long) pclk;
2166f76ee892STomi Valkeinen
2167f76ee892STomi Valkeinen if (height > out_height) {
2168f76ee892STomi Valkeinen unsigned int ppl = mgr_timings->x_res;
2169f76ee892STomi Valkeinen
2170f76ee892STomi Valkeinen tmp = (u64)pclk * height * out_width;
2171f76ee892STomi Valkeinen do_div(tmp, 2 * out_height * ppl);
2172f76ee892STomi Valkeinen core_clk = tmp;
2173f76ee892STomi Valkeinen
2174f76ee892STomi Valkeinen if (height > 2 * out_height) {
2175f76ee892STomi Valkeinen if (ppl == out_width)
2176f76ee892STomi Valkeinen return 0;
2177f76ee892STomi Valkeinen
2178f76ee892STomi Valkeinen tmp = (u64)pclk * (height - 2 * out_height) * out_width;
2179f76ee892STomi Valkeinen do_div(tmp, 2 * out_height * (ppl - out_width));
2180f76ee892STomi Valkeinen core_clk = max_t(u32, core_clk, tmp);
2181f76ee892STomi Valkeinen }
2182f76ee892STomi Valkeinen }
2183f76ee892STomi Valkeinen
2184f76ee892STomi Valkeinen if (width > out_width) {
2185f76ee892STomi Valkeinen tmp = (u64)pclk * width;
2186f76ee892STomi Valkeinen do_div(tmp, out_width);
2187f76ee892STomi Valkeinen core_clk = max_t(u32, core_clk, tmp);
2188f76ee892STomi Valkeinen
2189f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_RGB24U)
2190f76ee892STomi Valkeinen core_clk <<= 1;
2191f76ee892STomi Valkeinen }
2192f76ee892STomi Valkeinen
2193f76ee892STomi Valkeinen return core_clk;
2194f76ee892STomi Valkeinen }
2195f76ee892STomi Valkeinen
calc_core_clk_24xx(unsigned long pclk,u16 width,u16 height,u16 out_width,u16 out_height,bool mem_to_mem)2196f76ee892STomi Valkeinen static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
2197f76ee892STomi Valkeinen u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2198f76ee892STomi Valkeinen {
2199f76ee892STomi Valkeinen if (height > out_height && width > out_width)
2200f76ee892STomi Valkeinen return pclk * 4;
2201f76ee892STomi Valkeinen else
2202f76ee892STomi Valkeinen return pclk * 2;
2203f76ee892STomi Valkeinen }
2204f76ee892STomi Valkeinen
calc_core_clk_34xx(unsigned long pclk,u16 width,u16 height,u16 out_width,u16 out_height,bool mem_to_mem)2205f76ee892STomi Valkeinen static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
2206f76ee892STomi Valkeinen u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2207f76ee892STomi Valkeinen {
2208f76ee892STomi Valkeinen unsigned int hf, vf;
2209f76ee892STomi Valkeinen
2210f76ee892STomi Valkeinen /*
2211f76ee892STomi Valkeinen * FIXME how to determine the 'A' factor
2212f76ee892STomi Valkeinen * for the no downscaling case ?
2213f76ee892STomi Valkeinen */
2214f76ee892STomi Valkeinen
2215f76ee892STomi Valkeinen if (width > 3 * out_width)
2216f76ee892STomi Valkeinen hf = 4;
2217f76ee892STomi Valkeinen else if (width > 2 * out_width)
2218f76ee892STomi Valkeinen hf = 3;
2219f76ee892STomi Valkeinen else if (width > out_width)
2220f76ee892STomi Valkeinen hf = 2;
2221f76ee892STomi Valkeinen else
2222f76ee892STomi Valkeinen hf = 1;
2223f76ee892STomi Valkeinen if (height > out_height)
2224f76ee892STomi Valkeinen vf = 2;
2225f76ee892STomi Valkeinen else
2226f76ee892STomi Valkeinen vf = 1;
2227f76ee892STomi Valkeinen
2228f76ee892STomi Valkeinen return pclk * vf * hf;
2229f76ee892STomi Valkeinen }
2230f76ee892STomi Valkeinen
calc_core_clk_44xx(unsigned long pclk,u16 width,u16 height,u16 out_width,u16 out_height,bool mem_to_mem)2231f76ee892STomi Valkeinen static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
2232f76ee892STomi Valkeinen u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2233f76ee892STomi Valkeinen {
2234f76ee892STomi Valkeinen /*
2235f76ee892STomi Valkeinen * If the overlay/writeback is in mem to mem mode, there are no
2236f76ee892STomi Valkeinen * downscaling limitations with respect to pixel clock, return 1 as
2237f76ee892STomi Valkeinen * required core clock to represent that we have sufficient enough
2238f76ee892STomi Valkeinen * core clock to do maximum downscaling
2239f76ee892STomi Valkeinen */
2240f76ee892STomi Valkeinen if (mem_to_mem)
2241f76ee892STomi Valkeinen return 1;
2242f76ee892STomi Valkeinen
2243f76ee892STomi Valkeinen if (width > out_width)
2244f76ee892STomi Valkeinen return DIV_ROUND_UP(pclk, out_width) * width;
2245f76ee892STomi Valkeinen else
2246f76ee892STomi Valkeinen return pclk;
2247f76ee892STomi Valkeinen }
2248f76ee892STomi Valkeinen
dispc_ovl_calc_scaling_24xx(unsigned long pclk,unsigned long lclk,const struct omap_video_timings * mgr_timings,u16 width,u16 height,u16 out_width,u16 out_height,enum omap_color_mode color_mode,bool * five_taps,int * x_predecim,int * y_predecim,int * decim_x,int * decim_y,u16 pos_x,unsigned long * core_clk,bool mem_to_mem)2249f76ee892STomi Valkeinen static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
2250f76ee892STomi Valkeinen const struct omap_video_timings *mgr_timings,
2251f76ee892STomi Valkeinen u16 width, u16 height, u16 out_width, u16 out_height,
2252f76ee892STomi Valkeinen enum omap_color_mode color_mode, bool *five_taps,
2253f76ee892STomi Valkeinen int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2254f76ee892STomi Valkeinen u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2255f76ee892STomi Valkeinen {
2256f76ee892STomi Valkeinen int error;
2257f76ee892STomi Valkeinen u16 in_width, in_height;
2258f76ee892STomi Valkeinen int min_factor = min(*decim_x, *decim_y);
2259f76ee892STomi Valkeinen const int maxsinglelinewidth =
2260f76ee892STomi Valkeinen dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2261f76ee892STomi Valkeinen
2262f76ee892STomi Valkeinen *five_taps = false;
2263f76ee892STomi Valkeinen
2264f76ee892STomi Valkeinen do {
2265f76ee892STomi Valkeinen in_height = height / *decim_y;
2266f76ee892STomi Valkeinen in_width = width / *decim_x;
2267f76ee892STomi Valkeinen *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
2268f76ee892STomi Valkeinen in_height, out_width, out_height, mem_to_mem);
2269f76ee892STomi Valkeinen error = (in_width > maxsinglelinewidth || !*core_clk ||
2270f76ee892STomi Valkeinen *core_clk > dispc_core_clk_rate());
2271f76ee892STomi Valkeinen if (error) {
2272f76ee892STomi Valkeinen if (*decim_x == *decim_y) {
2273f76ee892STomi Valkeinen *decim_x = min_factor;
2274f76ee892STomi Valkeinen ++*decim_y;
2275f76ee892STomi Valkeinen } else {
2276f76ee892STomi Valkeinen swap(*decim_x, *decim_y);
2277f76ee892STomi Valkeinen if (*decim_x < *decim_y)
2278f76ee892STomi Valkeinen ++*decim_x;
2279f76ee892STomi Valkeinen }
2280f76ee892STomi Valkeinen }
2281f76ee892STomi Valkeinen } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2282f76ee892STomi Valkeinen
2283f76ee892STomi Valkeinen if (error) {
2284f76ee892STomi Valkeinen DSSERR("failed to find scaling settings\n");
2285f76ee892STomi Valkeinen return -EINVAL;
2286f76ee892STomi Valkeinen }
2287f76ee892STomi Valkeinen
2288f76ee892STomi Valkeinen if (in_width > maxsinglelinewidth) {
2289f76ee892STomi Valkeinen DSSERR("Cannot scale max input width exceeded");
2290f76ee892STomi Valkeinen return -EINVAL;
2291f76ee892STomi Valkeinen }
2292f76ee892STomi Valkeinen return 0;
2293f76ee892STomi Valkeinen }
2294f76ee892STomi Valkeinen
dispc_ovl_calc_scaling_34xx(unsigned long pclk,unsigned long lclk,const struct omap_video_timings * mgr_timings,u16 width,u16 height,u16 out_width,u16 out_height,enum omap_color_mode color_mode,bool * five_taps,int * x_predecim,int * y_predecim,int * decim_x,int * decim_y,u16 pos_x,unsigned long * core_clk,bool mem_to_mem)2295f76ee892STomi Valkeinen static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
2296f76ee892STomi Valkeinen const struct omap_video_timings *mgr_timings,
2297f76ee892STomi Valkeinen u16 width, u16 height, u16 out_width, u16 out_height,
2298f76ee892STomi Valkeinen enum omap_color_mode color_mode, bool *five_taps,
2299f76ee892STomi Valkeinen int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2300f76ee892STomi Valkeinen u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2301f76ee892STomi Valkeinen {
2302f76ee892STomi Valkeinen int error;
2303f76ee892STomi Valkeinen u16 in_width, in_height;
2304f76ee892STomi Valkeinen const int maxsinglelinewidth =
2305f76ee892STomi Valkeinen dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2306f76ee892STomi Valkeinen
2307f76ee892STomi Valkeinen do {
2308f76ee892STomi Valkeinen in_height = height / *decim_y;
2309f76ee892STomi Valkeinen in_width = width / *decim_x;
2310f76ee892STomi Valkeinen *five_taps = in_height > out_height;
2311f76ee892STomi Valkeinen
2312f76ee892STomi Valkeinen if (in_width > maxsinglelinewidth)
2313f76ee892STomi Valkeinen if (in_height > out_height &&
2314f76ee892STomi Valkeinen in_height < out_height * 2)
2315f76ee892STomi Valkeinen *five_taps = false;
2316f76ee892STomi Valkeinen again:
2317f76ee892STomi Valkeinen if (*five_taps)
2318f76ee892STomi Valkeinen *core_clk = calc_core_clk_five_taps(pclk, mgr_timings,
2319f76ee892STomi Valkeinen in_width, in_height, out_width,
2320f76ee892STomi Valkeinen out_height, color_mode);
2321f76ee892STomi Valkeinen else
2322f76ee892STomi Valkeinen *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
2323f76ee892STomi Valkeinen in_height, out_width, out_height,
2324f76ee892STomi Valkeinen mem_to_mem);
2325f76ee892STomi Valkeinen
2326f76ee892STomi Valkeinen error = check_horiz_timing_omap3(pclk, lclk, mgr_timings,
2327f76ee892STomi Valkeinen pos_x, in_width, in_height, out_width,
2328f76ee892STomi Valkeinen out_height, *five_taps);
2329f76ee892STomi Valkeinen if (error && *five_taps) {
2330f76ee892STomi Valkeinen *five_taps = false;
2331f76ee892STomi Valkeinen goto again;
2332f76ee892STomi Valkeinen }
2333f76ee892STomi Valkeinen
2334f76ee892STomi Valkeinen error = (error || in_width > maxsinglelinewidth * 2 ||
2335f76ee892STomi Valkeinen (in_width > maxsinglelinewidth && *five_taps) ||
2336f76ee892STomi Valkeinen !*core_clk || *core_clk > dispc_core_clk_rate());
2337f76ee892STomi Valkeinen
2338f76ee892STomi Valkeinen if (!error) {
2339f76ee892STomi Valkeinen /* verify that we're inside the limits of scaler */
2340f76ee892STomi Valkeinen if (in_width / 4 > out_width)
2341f76ee892STomi Valkeinen error = 1;
2342f76ee892STomi Valkeinen
2343f76ee892STomi Valkeinen if (*five_taps) {
2344f76ee892STomi Valkeinen if (in_height / 4 > out_height)
2345f76ee892STomi Valkeinen error = 1;
2346f76ee892STomi Valkeinen } else {
2347f76ee892STomi Valkeinen if (in_height / 2 > out_height)
2348f76ee892STomi Valkeinen error = 1;
2349f76ee892STomi Valkeinen }
2350f76ee892STomi Valkeinen }
2351f76ee892STomi Valkeinen
2352f76ee892STomi Valkeinen if (error)
2353f76ee892STomi Valkeinen ++*decim_y;
2354f76ee892STomi Valkeinen } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2355f76ee892STomi Valkeinen
2356f76ee892STomi Valkeinen if (error) {
2357f76ee892STomi Valkeinen DSSERR("failed to find scaling settings\n");
2358f76ee892STomi Valkeinen return -EINVAL;
2359f76ee892STomi Valkeinen }
2360f76ee892STomi Valkeinen
2361f76ee892STomi Valkeinen if (check_horiz_timing_omap3(pclk, lclk, mgr_timings, pos_x, in_width,
2362f76ee892STomi Valkeinen in_height, out_width, out_height, *five_taps)) {
2363f76ee892STomi Valkeinen DSSERR("horizontal timing too tight\n");
2364f76ee892STomi Valkeinen return -EINVAL;
2365f76ee892STomi Valkeinen }
2366f76ee892STomi Valkeinen
2367f76ee892STomi Valkeinen if (in_width > (maxsinglelinewidth * 2)) {
2368f76ee892STomi Valkeinen DSSERR("Cannot setup scaling");
2369f76ee892STomi Valkeinen DSSERR("width exceeds maximum width possible");
2370f76ee892STomi Valkeinen return -EINVAL;
2371f76ee892STomi Valkeinen }
2372f76ee892STomi Valkeinen
2373f76ee892STomi Valkeinen if (in_width > maxsinglelinewidth && *five_taps) {
2374f76ee892STomi Valkeinen DSSERR("cannot setup scaling with five taps");
2375f76ee892STomi Valkeinen return -EINVAL;
2376f76ee892STomi Valkeinen }
2377f76ee892STomi Valkeinen return 0;
2378f76ee892STomi Valkeinen }
2379f76ee892STomi Valkeinen
dispc_ovl_calc_scaling_44xx(unsigned long pclk,unsigned long lclk,const struct omap_video_timings * mgr_timings,u16 width,u16 height,u16 out_width,u16 out_height,enum omap_color_mode color_mode,bool * five_taps,int * x_predecim,int * y_predecim,int * decim_x,int * decim_y,u16 pos_x,unsigned long * core_clk,bool mem_to_mem)2380f76ee892STomi Valkeinen static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
2381f76ee892STomi Valkeinen const struct omap_video_timings *mgr_timings,
2382f76ee892STomi Valkeinen u16 width, u16 height, u16 out_width, u16 out_height,
2383f76ee892STomi Valkeinen enum omap_color_mode color_mode, bool *five_taps,
2384f76ee892STomi Valkeinen int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2385f76ee892STomi Valkeinen u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2386f76ee892STomi Valkeinen {
2387f76ee892STomi Valkeinen u16 in_width, in_width_max;
2388f76ee892STomi Valkeinen int decim_x_min = *decim_x;
2389f76ee892STomi Valkeinen u16 in_height = height / *decim_y;
2390f76ee892STomi Valkeinen const int maxsinglelinewidth =
2391f76ee892STomi Valkeinen dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2392f76ee892STomi Valkeinen const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2393f76ee892STomi Valkeinen
2394f76ee892STomi Valkeinen if (mem_to_mem) {
2395f76ee892STomi Valkeinen in_width_max = out_width * maxdownscale;
2396f76ee892STomi Valkeinen } else {
2397f76ee892STomi Valkeinen in_width_max = dispc_core_clk_rate() /
2398f76ee892STomi Valkeinen DIV_ROUND_UP(pclk, out_width);
2399f76ee892STomi Valkeinen }
2400f76ee892STomi Valkeinen
2401f76ee892STomi Valkeinen *decim_x = DIV_ROUND_UP(width, in_width_max);
2402f76ee892STomi Valkeinen
2403f76ee892STomi Valkeinen *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2404f76ee892STomi Valkeinen if (*decim_x > *x_predecim)
2405f76ee892STomi Valkeinen return -EINVAL;
2406f76ee892STomi Valkeinen
2407f76ee892STomi Valkeinen do {
2408f76ee892STomi Valkeinen in_width = width / *decim_x;
2409f76ee892STomi Valkeinen } while (*decim_x <= *x_predecim &&
2410f76ee892STomi Valkeinen in_width > maxsinglelinewidth && ++*decim_x);
2411f76ee892STomi Valkeinen
2412f76ee892STomi Valkeinen if (in_width > maxsinglelinewidth) {
2413f76ee892STomi Valkeinen DSSERR("Cannot scale width exceeds max line width");
2414f76ee892STomi Valkeinen return -EINVAL;
2415f76ee892STomi Valkeinen }
2416f76ee892STomi Valkeinen
2417f76ee892STomi Valkeinen *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
2418f76ee892STomi Valkeinen out_width, out_height, mem_to_mem);
2419f76ee892STomi Valkeinen return 0;
2420f76ee892STomi Valkeinen }
2421f76ee892STomi Valkeinen
2422f76ee892STomi Valkeinen #define DIV_FRAC(dividend, divisor) \
2423f76ee892STomi Valkeinen ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2424f76ee892STomi Valkeinen
dispc_ovl_calc_scaling(unsigned long pclk,unsigned long lclk,enum omap_overlay_caps caps,const struct omap_video_timings * mgr_timings,u16 width,u16 height,u16 out_width,u16 out_height,enum omap_color_mode color_mode,bool * five_taps,int * x_predecim,int * y_predecim,u16 pos_x,enum omap_dss_rotation_type rotation_type,bool mem_to_mem)2425f76ee892STomi Valkeinen static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
2426f76ee892STomi Valkeinen enum omap_overlay_caps caps,
2427f76ee892STomi Valkeinen const struct omap_video_timings *mgr_timings,
2428f76ee892STomi Valkeinen u16 width, u16 height, u16 out_width, u16 out_height,
2429f76ee892STomi Valkeinen enum omap_color_mode color_mode, bool *five_taps,
2430f76ee892STomi Valkeinen int *x_predecim, int *y_predecim, u16 pos_x,
2431f76ee892STomi Valkeinen enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
2432f76ee892STomi Valkeinen {
2433f76ee892STomi Valkeinen const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2434f76ee892STomi Valkeinen const int max_decim_limit = 16;
2435f76ee892STomi Valkeinen unsigned long core_clk = 0;
2436f76ee892STomi Valkeinen int decim_x, decim_y, ret;
2437f76ee892STomi Valkeinen
2438f76ee892STomi Valkeinen if (width == out_width && height == out_height)
2439f76ee892STomi Valkeinen return 0;
2440f76ee892STomi Valkeinen
2441f76ee892STomi Valkeinen if (!mem_to_mem && (pclk == 0 || mgr_timings->pixelclock == 0)) {
2442f76ee892STomi Valkeinen DSSERR("cannot calculate scaling settings: pclk is zero\n");
2443f76ee892STomi Valkeinen return -EINVAL;
2444f76ee892STomi Valkeinen }
2445f76ee892STomi Valkeinen
2446f76ee892STomi Valkeinen if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
2447f76ee892STomi Valkeinen return -EINVAL;
2448f76ee892STomi Valkeinen
2449f76ee892STomi Valkeinen if (mem_to_mem) {
2450f76ee892STomi Valkeinen *x_predecim = *y_predecim = 1;
2451f76ee892STomi Valkeinen } else {
2452f76ee892STomi Valkeinen *x_predecim = max_decim_limit;
2453f76ee892STomi Valkeinen *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2454f76ee892STomi Valkeinen dss_has_feature(FEAT_BURST_2D)) ?
2455f76ee892STomi Valkeinen 2 : max_decim_limit;
2456f76ee892STomi Valkeinen }
2457f76ee892STomi Valkeinen
2458f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2459f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_CLUT2 ||
2460f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_CLUT4 ||
2461f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_CLUT8) {
2462f76ee892STomi Valkeinen *x_predecim = 1;
2463f76ee892STomi Valkeinen *y_predecim = 1;
2464f76ee892STomi Valkeinen *five_taps = false;
2465f76ee892STomi Valkeinen return 0;
2466f76ee892STomi Valkeinen }
2467f76ee892STomi Valkeinen
2468f76ee892STomi Valkeinen decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2469f76ee892STomi Valkeinen decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2470f76ee892STomi Valkeinen
2471f76ee892STomi Valkeinen if (decim_x > *x_predecim || out_width > width * 8)
2472f76ee892STomi Valkeinen return -EINVAL;
2473f76ee892STomi Valkeinen
2474f76ee892STomi Valkeinen if (decim_y > *y_predecim || out_height > height * 8)
2475f76ee892STomi Valkeinen return -EINVAL;
2476f76ee892STomi Valkeinen
2477f76ee892STomi Valkeinen ret = dispc.feat->calc_scaling(pclk, lclk, mgr_timings, width, height,
2478f76ee892STomi Valkeinen out_width, out_height, color_mode, five_taps,
2479f76ee892STomi Valkeinen x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2480f76ee892STomi Valkeinen mem_to_mem);
2481f76ee892STomi Valkeinen if (ret)
2482f76ee892STomi Valkeinen return ret;
2483f76ee892STomi Valkeinen
2484f76ee892STomi Valkeinen 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",
2485f76ee892STomi Valkeinen width, height,
2486f76ee892STomi Valkeinen out_width, out_height,
2487f76ee892STomi Valkeinen out_width / width, DIV_FRAC(out_width, width),
2488f76ee892STomi Valkeinen out_height / height, DIV_FRAC(out_height, height),
2489f76ee892STomi Valkeinen
2490f76ee892STomi Valkeinen decim_x, decim_y,
2491f76ee892STomi Valkeinen width / decim_x, height / decim_y,
2492f76ee892STomi Valkeinen out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
2493f76ee892STomi Valkeinen out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
2494f76ee892STomi Valkeinen
2495f76ee892STomi Valkeinen *five_taps ? 5 : 3,
2496f76ee892STomi Valkeinen core_clk, dispc_core_clk_rate());
2497f76ee892STomi Valkeinen
2498f76ee892STomi Valkeinen if (!core_clk || core_clk > dispc_core_clk_rate()) {
2499f76ee892STomi Valkeinen DSSERR("failed to set up scaling, "
2500f76ee892STomi Valkeinen "required core clk rate = %lu Hz, "
2501f76ee892STomi Valkeinen "current core clk rate = %lu Hz\n",
2502f76ee892STomi Valkeinen core_clk, dispc_core_clk_rate());
2503f76ee892STomi Valkeinen return -EINVAL;
2504f76ee892STomi Valkeinen }
2505f76ee892STomi Valkeinen
2506f76ee892STomi Valkeinen *x_predecim = decim_x;
2507f76ee892STomi Valkeinen *y_predecim = decim_y;
2508f76ee892STomi Valkeinen return 0;
2509f76ee892STomi Valkeinen }
2510f76ee892STomi Valkeinen
dispc_ovl_check(enum omap_plane plane,enum omap_channel channel,const struct omap_overlay_info * oi,const struct omap_video_timings * timings,int * x_predecim,int * y_predecim)2511f76ee892STomi Valkeinen int dispc_ovl_check(enum omap_plane plane, enum omap_channel channel,
2512f76ee892STomi Valkeinen const struct omap_overlay_info *oi,
2513f76ee892STomi Valkeinen const struct omap_video_timings *timings,
2514f76ee892STomi Valkeinen int *x_predecim, int *y_predecim)
2515f76ee892STomi Valkeinen {
2516f76ee892STomi Valkeinen enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2517f76ee892STomi Valkeinen bool five_taps = true;
2518f76ee892STomi Valkeinen bool fieldmode = false;
2519f76ee892STomi Valkeinen u16 in_height = oi->height;
2520f76ee892STomi Valkeinen u16 in_width = oi->width;
2521f76ee892STomi Valkeinen bool ilace = timings->interlace;
2522f76ee892STomi Valkeinen u16 out_width, out_height;
2523f76ee892STomi Valkeinen int pos_x = oi->pos_x;
2524f76ee892STomi Valkeinen unsigned long pclk = dispc_mgr_pclk_rate(channel);
2525f76ee892STomi Valkeinen unsigned long lclk = dispc_mgr_lclk_rate(channel);
2526f76ee892STomi Valkeinen
2527f76ee892STomi Valkeinen out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2528f76ee892STomi Valkeinen out_height = oi->out_height == 0 ? oi->height : oi->out_height;
2529f76ee892STomi Valkeinen
2530f76ee892STomi Valkeinen if (ilace && oi->height == out_height)
2531f76ee892STomi Valkeinen fieldmode = true;
2532f76ee892STomi Valkeinen
2533f76ee892STomi Valkeinen if (ilace) {
2534f76ee892STomi Valkeinen if (fieldmode)
2535f76ee892STomi Valkeinen in_height /= 2;
2536f76ee892STomi Valkeinen out_height /= 2;
2537f76ee892STomi Valkeinen
2538f76ee892STomi Valkeinen DSSDBG("adjusting for ilace: height %d, out_height %d\n",
2539f76ee892STomi Valkeinen in_height, out_height);
2540f76ee892STomi Valkeinen }
2541f76ee892STomi Valkeinen
2542f76ee892STomi Valkeinen if (!dss_feat_color_mode_supported(plane, oi->color_mode))
2543f76ee892STomi Valkeinen return -EINVAL;
2544f76ee892STomi Valkeinen
2545f76ee892STomi Valkeinen return dispc_ovl_calc_scaling(pclk, lclk, caps, timings, in_width,
2546f76ee892STomi Valkeinen in_height, out_width, out_height, oi->color_mode,
2547f76ee892STomi Valkeinen &five_taps, x_predecim, y_predecim, pos_x,
2548f76ee892STomi Valkeinen oi->rotation_type, false);
2549f76ee892STomi Valkeinen }
2550f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_ovl_check);
2551f76ee892STomi Valkeinen
dispc_ovl_setup_common(enum omap_plane plane,enum omap_overlay_caps caps,u32 paddr,u32 p_uv_addr,u16 screen_width,int pos_x,int pos_y,u16 width,u16 height,u16 out_width,u16 out_height,enum omap_color_mode color_mode,u8 rotation,bool mirror,u8 zorder,u8 pre_mult_alpha,u8 global_alpha,enum omap_dss_rotation_type rotation_type,bool replication,const struct omap_video_timings * mgr_timings,bool mem_to_mem)2552f76ee892STomi Valkeinen static int dispc_ovl_setup_common(enum omap_plane plane,
2553f76ee892STomi Valkeinen enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2554f76ee892STomi Valkeinen u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2555f76ee892STomi Valkeinen u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2556f76ee892STomi Valkeinen u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2557f76ee892STomi Valkeinen u8 global_alpha, enum omap_dss_rotation_type rotation_type,
2558f76ee892STomi Valkeinen bool replication, const struct omap_video_timings *mgr_timings,
2559f76ee892STomi Valkeinen bool mem_to_mem)
2560f76ee892STomi Valkeinen {
2561f76ee892STomi Valkeinen bool five_taps = true;
2562f76ee892STomi Valkeinen bool fieldmode = false;
2563f76ee892STomi Valkeinen int r, cconv = 0;
2564f76ee892STomi Valkeinen unsigned offset0, offset1;
2565f76ee892STomi Valkeinen s32 row_inc;
2566f76ee892STomi Valkeinen s32 pix_inc;
2567f76ee892STomi Valkeinen u16 frame_width, frame_height;
2568f76ee892STomi Valkeinen unsigned int field_offset = 0;
2569f76ee892STomi Valkeinen u16 in_height = height;
2570f76ee892STomi Valkeinen u16 in_width = width;
2571f76ee892STomi Valkeinen int x_predecim = 1, y_predecim = 1;
2572f76ee892STomi Valkeinen bool ilace = mgr_timings->interlace;
2573f76ee892STomi Valkeinen unsigned long pclk = dispc_plane_pclk_rate(plane);
2574f76ee892STomi Valkeinen unsigned long lclk = dispc_plane_lclk_rate(plane);
2575f76ee892STomi Valkeinen
2576f76ee892STomi Valkeinen if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
2577f76ee892STomi Valkeinen return -EINVAL;
2578f76ee892STomi Valkeinen
2579f76ee892STomi Valkeinen switch (color_mode) {
2580f76ee892STomi Valkeinen case OMAP_DSS_COLOR_YUV2:
2581f76ee892STomi Valkeinen case OMAP_DSS_COLOR_UYVY:
2582f76ee892STomi Valkeinen case OMAP_DSS_COLOR_NV12:
2583f76ee892STomi Valkeinen if (in_width & 1) {
2584f76ee892STomi Valkeinen DSSERR("input width %d is not even for YUV format\n",
2585f76ee892STomi Valkeinen in_width);
2586f76ee892STomi Valkeinen return -EINVAL;
2587f76ee892STomi Valkeinen }
2588f76ee892STomi Valkeinen break;
2589f76ee892STomi Valkeinen
2590f76ee892STomi Valkeinen default:
2591f76ee892STomi Valkeinen break;
2592f76ee892STomi Valkeinen }
2593f76ee892STomi Valkeinen
2594f76ee892STomi Valkeinen out_width = out_width == 0 ? width : out_width;
2595f76ee892STomi Valkeinen out_height = out_height == 0 ? height : out_height;
2596f76ee892STomi Valkeinen
2597f76ee892STomi Valkeinen if (ilace && height == out_height)
2598f76ee892STomi Valkeinen fieldmode = true;
2599f76ee892STomi Valkeinen
2600f76ee892STomi Valkeinen if (ilace) {
2601f76ee892STomi Valkeinen if (fieldmode)
2602f76ee892STomi Valkeinen in_height /= 2;
2603f76ee892STomi Valkeinen pos_y /= 2;
2604f76ee892STomi Valkeinen out_height /= 2;
2605f76ee892STomi Valkeinen
2606f76ee892STomi Valkeinen DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2607f76ee892STomi Valkeinen "out_height %d\n", in_height, pos_y,
2608f76ee892STomi Valkeinen out_height);
2609f76ee892STomi Valkeinen }
2610f76ee892STomi Valkeinen
2611f76ee892STomi Valkeinen if (!dss_feat_color_mode_supported(plane, color_mode))
2612f76ee892STomi Valkeinen return -EINVAL;
2613f76ee892STomi Valkeinen
2614f76ee892STomi Valkeinen r = dispc_ovl_calc_scaling(pclk, lclk, caps, mgr_timings, in_width,
2615f76ee892STomi Valkeinen in_height, out_width, out_height, color_mode,
2616f76ee892STomi Valkeinen &five_taps, &x_predecim, &y_predecim, pos_x,
2617f76ee892STomi Valkeinen rotation_type, mem_to_mem);
2618f76ee892STomi Valkeinen if (r)
2619f76ee892STomi Valkeinen return r;
2620f76ee892STomi Valkeinen
2621f76ee892STomi Valkeinen in_width = in_width / x_predecim;
2622f76ee892STomi Valkeinen in_height = in_height / y_predecim;
2623f76ee892STomi Valkeinen
2624f76ee892STomi Valkeinen if (x_predecim > 1 || y_predecim > 1)
2625f76ee892STomi Valkeinen DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2626f76ee892STomi Valkeinen x_predecim, y_predecim, in_width, in_height);
2627f76ee892STomi Valkeinen
2628f76ee892STomi Valkeinen switch (color_mode) {
2629f76ee892STomi Valkeinen case OMAP_DSS_COLOR_YUV2:
2630f76ee892STomi Valkeinen case OMAP_DSS_COLOR_UYVY:
2631f76ee892STomi Valkeinen case OMAP_DSS_COLOR_NV12:
2632f76ee892STomi Valkeinen if (in_width & 1) {
2633f76ee892STomi Valkeinen DSSDBG("predecimated input width is not even for YUV format\n");
2634f76ee892STomi Valkeinen DSSDBG("adjusting input width %d -> %d\n",
2635f76ee892STomi Valkeinen in_width, in_width & ~1);
2636f76ee892STomi Valkeinen
2637f76ee892STomi Valkeinen in_width &= ~1;
2638f76ee892STomi Valkeinen }
2639f76ee892STomi Valkeinen break;
2640f76ee892STomi Valkeinen
2641f76ee892STomi Valkeinen default:
2642f76ee892STomi Valkeinen break;
2643f76ee892STomi Valkeinen }
2644f76ee892STomi Valkeinen
2645f76ee892STomi Valkeinen if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2646f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_UYVY ||
2647f76ee892STomi Valkeinen color_mode == OMAP_DSS_COLOR_NV12)
2648f76ee892STomi Valkeinen cconv = 1;
2649f76ee892STomi Valkeinen
2650f76ee892STomi Valkeinen if (ilace && !fieldmode) {
2651f76ee892STomi Valkeinen /*
2652f76ee892STomi Valkeinen * when downscaling the bottom field may have to start several
2653f76ee892STomi Valkeinen * source lines below the top field. Unfortunately ACCUI
2654f76ee892STomi Valkeinen * registers will only hold the fractional part of the offset
2655f76ee892STomi Valkeinen * so the integer part must be added to the base address of the
2656f76ee892STomi Valkeinen * bottom field.
2657f76ee892STomi Valkeinen */
2658f76ee892STomi Valkeinen if (!in_height || in_height == out_height)
2659f76ee892STomi Valkeinen field_offset = 0;
2660f76ee892STomi Valkeinen else
2661f76ee892STomi Valkeinen field_offset = in_height / out_height / 2;
2662f76ee892STomi Valkeinen }
2663f76ee892STomi Valkeinen
2664f76ee892STomi Valkeinen /* Fields are independent but interleaved in memory. */
2665f76ee892STomi Valkeinen if (fieldmode)
2666f76ee892STomi Valkeinen field_offset = 1;
2667f76ee892STomi Valkeinen
2668f76ee892STomi Valkeinen offset0 = 0;
2669f76ee892STomi Valkeinen offset1 = 0;
2670f76ee892STomi Valkeinen row_inc = 0;
2671f76ee892STomi Valkeinen pix_inc = 0;
2672f76ee892STomi Valkeinen
2673f76ee892STomi Valkeinen if (plane == OMAP_DSS_WB) {
2674f76ee892STomi Valkeinen frame_width = out_width;
2675f76ee892STomi Valkeinen frame_height = out_height;
2676f76ee892STomi Valkeinen } else {
2677f76ee892STomi Valkeinen frame_width = in_width;
2678f76ee892STomi Valkeinen frame_height = height;
2679f76ee892STomi Valkeinen }
2680f76ee892STomi Valkeinen
2681f76ee892STomi Valkeinen if (rotation_type == OMAP_DSS_ROT_TILER)
2682f76ee892STomi Valkeinen calc_tiler_rotation_offset(screen_width, frame_width,
2683f76ee892STomi Valkeinen color_mode, fieldmode, field_offset,
2684f76ee892STomi Valkeinen &offset0, &offset1, &row_inc, &pix_inc,
2685f76ee892STomi Valkeinen x_predecim, y_predecim);
2686f76ee892STomi Valkeinen else if (rotation_type == OMAP_DSS_ROT_DMA)
2687f76ee892STomi Valkeinen calc_dma_rotation_offset(rotation, mirror, screen_width,
2688f76ee892STomi Valkeinen frame_width, frame_height,
2689f76ee892STomi Valkeinen color_mode, fieldmode, field_offset,
2690f76ee892STomi Valkeinen &offset0, &offset1, &row_inc, &pix_inc,
2691f76ee892STomi Valkeinen x_predecim, y_predecim);
2692f76ee892STomi Valkeinen else
2693f76ee892STomi Valkeinen calc_vrfb_rotation_offset(rotation, mirror,
2694f76ee892STomi Valkeinen screen_width, frame_width, frame_height,
2695f76ee892STomi Valkeinen color_mode, fieldmode, field_offset,
2696f76ee892STomi Valkeinen &offset0, &offset1, &row_inc, &pix_inc,
2697f76ee892STomi Valkeinen x_predecim, y_predecim);
2698f76ee892STomi Valkeinen
2699f76ee892STomi Valkeinen DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2700f76ee892STomi Valkeinen offset0, offset1, row_inc, pix_inc);
2701f76ee892STomi Valkeinen
2702f76ee892STomi Valkeinen dispc_ovl_set_color_mode(plane, color_mode);
2703f76ee892STomi Valkeinen
2704f76ee892STomi Valkeinen dispc_ovl_configure_burst_type(plane, rotation_type);
2705f76ee892STomi Valkeinen
2706f76ee892STomi Valkeinen dispc_ovl_set_ba0(plane, paddr + offset0);
2707f76ee892STomi Valkeinen dispc_ovl_set_ba1(plane, paddr + offset1);
2708f76ee892STomi Valkeinen
2709f76ee892STomi Valkeinen if (OMAP_DSS_COLOR_NV12 == color_mode) {
2710f76ee892STomi Valkeinen dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2711f76ee892STomi Valkeinen dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
2712f76ee892STomi Valkeinen }
2713f76ee892STomi Valkeinen
2714f76ee892STomi Valkeinen if (dispc.feat->last_pixel_inc_missing)
2715f76ee892STomi Valkeinen row_inc += pix_inc - 1;
2716f76ee892STomi Valkeinen
2717f76ee892STomi Valkeinen dispc_ovl_set_row_inc(plane, row_inc);
2718f76ee892STomi Valkeinen dispc_ovl_set_pix_inc(plane, pix_inc);
2719f76ee892STomi Valkeinen
2720f76ee892STomi Valkeinen DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
2721f76ee892STomi Valkeinen in_height, out_width, out_height);
2722f76ee892STomi Valkeinen
2723f76ee892STomi Valkeinen dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
2724f76ee892STomi Valkeinen
2725f76ee892STomi Valkeinen dispc_ovl_set_input_size(plane, in_width, in_height);
2726f76ee892STomi Valkeinen
2727f76ee892STomi Valkeinen if (caps & OMAP_DSS_OVL_CAP_SCALE) {
2728f76ee892STomi Valkeinen dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2729f76ee892STomi Valkeinen out_height, ilace, five_taps, fieldmode,
2730f76ee892STomi Valkeinen color_mode, rotation);
2731f76ee892STomi Valkeinen dispc_ovl_set_output_size(plane, out_width, out_height);
2732f76ee892STomi Valkeinen dispc_ovl_set_vid_color_conv(plane, cconv);
2733f76ee892STomi Valkeinen }
2734f76ee892STomi Valkeinen
2735f76ee892STomi Valkeinen dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, mirror,
2736f76ee892STomi Valkeinen color_mode);
2737f76ee892STomi Valkeinen
2738f76ee892STomi Valkeinen dispc_ovl_set_zorder(plane, caps, zorder);
2739f76ee892STomi Valkeinen dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2740f76ee892STomi Valkeinen dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
2741f76ee892STomi Valkeinen
2742f76ee892STomi Valkeinen dispc_ovl_enable_replication(plane, caps, replication);
2743f76ee892STomi Valkeinen
2744f76ee892STomi Valkeinen return 0;
2745f76ee892STomi Valkeinen }
2746f76ee892STomi Valkeinen
dispc_ovl_setup(enum omap_plane plane,const struct omap_overlay_info * oi,bool replication,const struct omap_video_timings * mgr_timings,bool mem_to_mem)2747f76ee892STomi Valkeinen int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
2748f76ee892STomi Valkeinen bool replication, const struct omap_video_timings *mgr_timings,
2749f76ee892STomi Valkeinen bool mem_to_mem)
2750f76ee892STomi Valkeinen {
2751f76ee892STomi Valkeinen int r;
2752f76ee892STomi Valkeinen enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2753f76ee892STomi Valkeinen enum omap_channel channel;
2754f76ee892STomi Valkeinen
2755f76ee892STomi Valkeinen channel = dispc_ovl_get_channel_out(plane);
2756f76ee892STomi Valkeinen
2757f76ee892STomi Valkeinen DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2758f76ee892STomi Valkeinen " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2759f76ee892STomi Valkeinen plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
2760f76ee892STomi Valkeinen oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2761f76ee892STomi Valkeinen oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2762f76ee892STomi Valkeinen
2763f76ee892STomi Valkeinen r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
2764f76ee892STomi Valkeinen oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2765f76ee892STomi Valkeinen oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2766f76ee892STomi Valkeinen oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
2767f76ee892STomi Valkeinen oi->rotation_type, replication, mgr_timings, mem_to_mem);
2768f76ee892STomi Valkeinen
2769f76ee892STomi Valkeinen return r;
2770f76ee892STomi Valkeinen }
2771f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_ovl_setup);
2772f76ee892STomi Valkeinen
dispc_ovl_enable(enum omap_plane plane,bool enable)2773f76ee892STomi Valkeinen int dispc_ovl_enable(enum omap_plane plane, bool enable)
2774f76ee892STomi Valkeinen {
2775f76ee892STomi Valkeinen DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2776f76ee892STomi Valkeinen
2777f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2778f76ee892STomi Valkeinen
2779f76ee892STomi Valkeinen return 0;
2780f76ee892STomi Valkeinen }
2781f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_ovl_enable);
2782f76ee892STomi Valkeinen
dispc_ovl_enabled(enum omap_plane plane)2783f76ee892STomi Valkeinen bool dispc_ovl_enabled(enum omap_plane plane)
2784f76ee892STomi Valkeinen {
2785f76ee892STomi Valkeinen return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2786f76ee892STomi Valkeinen }
2787f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_ovl_enabled);
2788f76ee892STomi Valkeinen
dispc_mgr_enable(enum omap_channel channel,bool enable)2789f76ee892STomi Valkeinen void dispc_mgr_enable(enum omap_channel channel, bool enable)
2790f76ee892STomi Valkeinen {
2791f76ee892STomi Valkeinen mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2792f76ee892STomi Valkeinen /* flush posted write */
2793f76ee892STomi Valkeinen mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2794f76ee892STomi Valkeinen }
2795f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_mgr_enable);
2796f76ee892STomi Valkeinen
dispc_mgr_is_enabled(enum omap_channel channel)2797f76ee892STomi Valkeinen bool dispc_mgr_is_enabled(enum omap_channel channel)
2798f76ee892STomi Valkeinen {
2799f76ee892STomi Valkeinen return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2800f76ee892STomi Valkeinen }
2801f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_mgr_is_enabled);
2802f76ee892STomi Valkeinen
dispc_lcd_enable_signal_polarity(bool act_high)2803f76ee892STomi Valkeinen static void dispc_lcd_enable_signal_polarity(bool act_high)
2804f76ee892STomi Valkeinen {
2805f76ee892STomi Valkeinen if (!dss_has_feature(FEAT_LCDENABLEPOL))
2806f76ee892STomi Valkeinen return;
2807f76ee892STomi Valkeinen
2808f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2809f76ee892STomi Valkeinen }
2810f76ee892STomi Valkeinen
dispc_lcd_enable_signal(bool enable)2811f76ee892STomi Valkeinen void dispc_lcd_enable_signal(bool enable)
2812f76ee892STomi Valkeinen {
2813f76ee892STomi Valkeinen if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2814f76ee892STomi Valkeinen return;
2815f76ee892STomi Valkeinen
2816f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2817f76ee892STomi Valkeinen }
2818f76ee892STomi Valkeinen
dispc_pck_free_enable(bool enable)2819f76ee892STomi Valkeinen void dispc_pck_free_enable(bool enable)
2820f76ee892STomi Valkeinen {
2821f76ee892STomi Valkeinen if (!dss_has_feature(FEAT_PCKFREEENABLE))
2822f76ee892STomi Valkeinen return;
2823f76ee892STomi Valkeinen
2824f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2825f76ee892STomi Valkeinen }
2826f76ee892STomi Valkeinen
dispc_mgr_enable_fifohandcheck(enum omap_channel channel,bool enable)2827f76ee892STomi Valkeinen static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
2828f76ee892STomi Valkeinen {
2829f76ee892STomi Valkeinen mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
2830f76ee892STomi Valkeinen }
2831f76ee892STomi Valkeinen
2832f76ee892STomi Valkeinen
dispc_mgr_set_lcd_type_tft(enum omap_channel channel)2833f76ee892STomi Valkeinen static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
2834f76ee892STomi Valkeinen {
2835f76ee892STomi Valkeinen mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
2836f76ee892STomi Valkeinen }
2837f76ee892STomi Valkeinen
dispc_set_loadmode(enum omap_dss_load_mode mode)2838f76ee892STomi Valkeinen static void dispc_set_loadmode(enum omap_dss_load_mode mode)
2839f76ee892STomi Valkeinen {
2840f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2841f76ee892STomi Valkeinen }
2842f76ee892STomi Valkeinen
2843f76ee892STomi Valkeinen
dispc_mgr_set_default_color(enum omap_channel channel,u32 color)2844f76ee892STomi Valkeinen static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
2845f76ee892STomi Valkeinen {
2846f76ee892STomi Valkeinen dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2847f76ee892STomi Valkeinen }
2848f76ee892STomi Valkeinen
dispc_mgr_set_trans_key(enum omap_channel ch,enum omap_dss_trans_key_type type,u32 trans_key)2849f76ee892STomi Valkeinen static void dispc_mgr_set_trans_key(enum omap_channel ch,
2850f76ee892STomi Valkeinen enum omap_dss_trans_key_type type,
2851f76ee892STomi Valkeinen u32 trans_key)
2852f76ee892STomi Valkeinen {
2853f76ee892STomi Valkeinen mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
2854f76ee892STomi Valkeinen
2855f76ee892STomi Valkeinen dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2856f76ee892STomi Valkeinen }
2857f76ee892STomi Valkeinen
dispc_mgr_enable_trans_key(enum omap_channel ch,bool enable)2858f76ee892STomi Valkeinen static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
2859f76ee892STomi Valkeinen {
2860f76ee892STomi Valkeinen mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
2861f76ee892STomi Valkeinen }
2862f76ee892STomi Valkeinen
dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,bool enable)2863f76ee892STomi Valkeinen static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2864f76ee892STomi Valkeinen bool enable)
2865f76ee892STomi Valkeinen {
2866f76ee892STomi Valkeinen if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
2867f76ee892STomi Valkeinen return;
2868f76ee892STomi Valkeinen
2869f76ee892STomi Valkeinen if (ch == OMAP_DSS_CHANNEL_LCD)
2870f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2871f76ee892STomi Valkeinen else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2872f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2873f76ee892STomi Valkeinen }
2874f76ee892STomi Valkeinen
dispc_mgr_setup(enum omap_channel channel,const struct omap_overlay_manager_info * info)2875f76ee892STomi Valkeinen void dispc_mgr_setup(enum omap_channel channel,
2876f76ee892STomi Valkeinen const struct omap_overlay_manager_info *info)
2877f76ee892STomi Valkeinen {
2878f76ee892STomi Valkeinen dispc_mgr_set_default_color(channel, info->default_color);
2879f76ee892STomi Valkeinen dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2880f76ee892STomi Valkeinen dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2881f76ee892STomi Valkeinen dispc_mgr_enable_alpha_fixed_zorder(channel,
2882f76ee892STomi Valkeinen info->partial_alpha_enabled);
2883f76ee892STomi Valkeinen if (dss_has_feature(FEAT_CPR)) {
2884f76ee892STomi Valkeinen dispc_mgr_enable_cpr(channel, info->cpr_enable);
2885f76ee892STomi Valkeinen dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2886f76ee892STomi Valkeinen }
2887f76ee892STomi Valkeinen }
2888f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_mgr_setup);
2889f76ee892STomi Valkeinen
dispc_mgr_set_tft_data_lines(enum omap_channel channel,u8 data_lines)2890f76ee892STomi Valkeinen static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2891f76ee892STomi Valkeinen {
2892f76ee892STomi Valkeinen int code;
2893f76ee892STomi Valkeinen
2894f76ee892STomi Valkeinen switch (data_lines) {
2895f76ee892STomi Valkeinen case 12:
2896f76ee892STomi Valkeinen code = 0;
2897f76ee892STomi Valkeinen break;
2898f76ee892STomi Valkeinen case 16:
2899f76ee892STomi Valkeinen code = 1;
2900f76ee892STomi Valkeinen break;
2901f76ee892STomi Valkeinen case 18:
2902f76ee892STomi Valkeinen code = 2;
2903f76ee892STomi Valkeinen break;
2904f76ee892STomi Valkeinen case 24:
2905f76ee892STomi Valkeinen code = 3;
2906f76ee892STomi Valkeinen break;
2907f76ee892STomi Valkeinen default:
2908f76ee892STomi Valkeinen BUG();
2909f76ee892STomi Valkeinen return;
2910f76ee892STomi Valkeinen }
2911f76ee892STomi Valkeinen
2912f76ee892STomi Valkeinen mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
2913f76ee892STomi Valkeinen }
2914f76ee892STomi Valkeinen
dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)2915f76ee892STomi Valkeinen static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
2916f76ee892STomi Valkeinen {
2917f76ee892STomi Valkeinen u32 l;
2918f76ee892STomi Valkeinen int gpout0, gpout1;
2919f76ee892STomi Valkeinen
2920f76ee892STomi Valkeinen switch (mode) {
2921f76ee892STomi Valkeinen case DSS_IO_PAD_MODE_RESET:
2922f76ee892STomi Valkeinen gpout0 = 0;
2923f76ee892STomi Valkeinen gpout1 = 0;
2924f76ee892STomi Valkeinen break;
2925f76ee892STomi Valkeinen case DSS_IO_PAD_MODE_RFBI:
2926f76ee892STomi Valkeinen gpout0 = 1;
2927f76ee892STomi Valkeinen gpout1 = 0;
2928f76ee892STomi Valkeinen break;
2929f76ee892STomi Valkeinen case DSS_IO_PAD_MODE_BYPASS:
2930f76ee892STomi Valkeinen gpout0 = 1;
2931f76ee892STomi Valkeinen gpout1 = 1;
2932f76ee892STomi Valkeinen break;
2933f76ee892STomi Valkeinen default:
2934f76ee892STomi Valkeinen BUG();
2935f76ee892STomi Valkeinen return;
2936f76ee892STomi Valkeinen }
2937f76ee892STomi Valkeinen
2938f76ee892STomi Valkeinen l = dispc_read_reg(DISPC_CONTROL);
2939f76ee892STomi Valkeinen l = FLD_MOD(l, gpout0, 15, 15);
2940f76ee892STomi Valkeinen l = FLD_MOD(l, gpout1, 16, 16);
2941f76ee892STomi Valkeinen dispc_write_reg(DISPC_CONTROL, l);
2942f76ee892STomi Valkeinen }
2943f76ee892STomi Valkeinen
dispc_mgr_enable_stallmode(enum omap_channel channel,bool enable)2944f76ee892STomi Valkeinen static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2945f76ee892STomi Valkeinen {
2946f76ee892STomi Valkeinen mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
2947f76ee892STomi Valkeinen }
2948f76ee892STomi Valkeinen
dispc_mgr_set_lcd_config(enum omap_channel channel,const struct dss_lcd_mgr_config * config)2949f76ee892STomi Valkeinen void dispc_mgr_set_lcd_config(enum omap_channel channel,
2950f76ee892STomi Valkeinen const struct dss_lcd_mgr_config *config)
2951f76ee892STomi Valkeinen {
2952f76ee892STomi Valkeinen dispc_mgr_set_io_pad_mode(config->io_pad_mode);
2953f76ee892STomi Valkeinen
2954f76ee892STomi Valkeinen dispc_mgr_enable_stallmode(channel, config->stallmode);
2955f76ee892STomi Valkeinen dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
2956f76ee892STomi Valkeinen
2957f76ee892STomi Valkeinen dispc_mgr_set_clock_div(channel, &config->clock_info);
2958f76ee892STomi Valkeinen
2959f76ee892STomi Valkeinen dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
2960f76ee892STomi Valkeinen
2961f76ee892STomi Valkeinen dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
2962f76ee892STomi Valkeinen
2963f76ee892STomi Valkeinen dispc_mgr_set_lcd_type_tft(channel);
2964f76ee892STomi Valkeinen }
2965f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_mgr_set_lcd_config);
2966f76ee892STomi Valkeinen
_dispc_mgr_size_ok(u16 width,u16 height)2967f76ee892STomi Valkeinen static bool _dispc_mgr_size_ok(u16 width, u16 height)
2968f76ee892STomi Valkeinen {
2969f76ee892STomi Valkeinen return width <= dispc.feat->mgr_width_max &&
2970f76ee892STomi Valkeinen height <= dispc.feat->mgr_height_max;
2971f76ee892STomi Valkeinen }
2972f76ee892STomi Valkeinen
_dispc_lcd_timings_ok(int hsw,int hfp,int hbp,int vsw,int vfp,int vbp)2973f76ee892STomi Valkeinen static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2974f76ee892STomi Valkeinen int vsw, int vfp, int vbp)
2975f76ee892STomi Valkeinen {
2976f76ee892STomi Valkeinen if (hsw < 1 || hsw > dispc.feat->sw_max ||
2977f76ee892STomi Valkeinen hfp < 1 || hfp > dispc.feat->hp_max ||
2978f76ee892STomi Valkeinen hbp < 1 || hbp > dispc.feat->hp_max ||
2979f76ee892STomi Valkeinen vsw < 1 || vsw > dispc.feat->sw_max ||
2980f76ee892STomi Valkeinen vfp < 0 || vfp > dispc.feat->vp_max ||
2981f76ee892STomi Valkeinen vbp < 0 || vbp > dispc.feat->vp_max)
2982f76ee892STomi Valkeinen return false;
2983f76ee892STomi Valkeinen return true;
2984f76ee892STomi Valkeinen }
2985f76ee892STomi Valkeinen
_dispc_mgr_pclk_ok(enum omap_channel channel,unsigned long pclk)2986f76ee892STomi Valkeinen static bool _dispc_mgr_pclk_ok(enum omap_channel channel,
2987f76ee892STomi Valkeinen unsigned long pclk)
2988f76ee892STomi Valkeinen {
2989f76ee892STomi Valkeinen if (dss_mgr_is_lcd(channel))
299080805774SAndrew F. Davis return pclk <= dispc.feat->max_lcd_pclk;
2991f76ee892STomi Valkeinen else
299280805774SAndrew F. Davis return pclk <= dispc.feat->max_tv_pclk;
2993f76ee892STomi Valkeinen }
2994f76ee892STomi Valkeinen
dispc_mgr_timings_ok(enum omap_channel channel,const struct omap_video_timings * timings)2995f76ee892STomi Valkeinen bool dispc_mgr_timings_ok(enum omap_channel channel,
2996f76ee892STomi Valkeinen const struct omap_video_timings *timings)
2997f76ee892STomi Valkeinen {
2998f76ee892STomi Valkeinen if (!_dispc_mgr_size_ok(timings->x_res, timings->y_res))
2999f76ee892STomi Valkeinen return false;
3000f76ee892STomi Valkeinen
3001f76ee892STomi Valkeinen if (!_dispc_mgr_pclk_ok(channel, timings->pixelclock))
3002f76ee892STomi Valkeinen return false;
3003f76ee892STomi Valkeinen
3004f76ee892STomi Valkeinen if (dss_mgr_is_lcd(channel)) {
3005f76ee892STomi Valkeinen /* TODO: OMAP4+ supports interlace for LCD outputs */
3006f76ee892STomi Valkeinen if (timings->interlace)
3007f76ee892STomi Valkeinen return false;
3008f76ee892STomi Valkeinen
3009f76ee892STomi Valkeinen if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
3010f76ee892STomi Valkeinen timings->hbp, timings->vsw, timings->vfp,
3011f76ee892STomi Valkeinen timings->vbp))
3012f76ee892STomi Valkeinen return false;
3013f76ee892STomi Valkeinen }
3014f76ee892STomi Valkeinen
3015f76ee892STomi Valkeinen return true;
3016f76ee892STomi Valkeinen }
3017f76ee892STomi Valkeinen
_dispc_mgr_set_lcd_timings(enum omap_channel channel,int hsw,int hfp,int hbp,int vsw,int vfp,int vbp,enum omap_dss_signal_level vsync_level,enum omap_dss_signal_level hsync_level,enum omap_dss_signal_edge data_pclk_edge,enum omap_dss_signal_level de_level,enum omap_dss_signal_edge sync_pclk_edge)3018f76ee892STomi Valkeinen static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
3019f76ee892STomi Valkeinen int hfp, int hbp, int vsw, int vfp, int vbp,
3020f76ee892STomi Valkeinen enum omap_dss_signal_level vsync_level,
3021f76ee892STomi Valkeinen enum omap_dss_signal_level hsync_level,
3022f76ee892STomi Valkeinen enum omap_dss_signal_edge data_pclk_edge,
3023f76ee892STomi Valkeinen enum omap_dss_signal_level de_level,
3024f76ee892STomi Valkeinen enum omap_dss_signal_edge sync_pclk_edge)
3025f76ee892STomi Valkeinen
3026f76ee892STomi Valkeinen {
3027f76ee892STomi Valkeinen u32 timing_h, timing_v, l;
3028f76ee892STomi Valkeinen bool onoff, rf, ipc, vs, hs, de;
3029f76ee892STomi Valkeinen
3030f76ee892STomi Valkeinen timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
3031f76ee892STomi Valkeinen FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
3032f76ee892STomi Valkeinen FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
3033f76ee892STomi Valkeinen timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
3034f76ee892STomi Valkeinen FLD_VAL(vfp, dispc.feat->fp_start, 8) |
3035f76ee892STomi Valkeinen FLD_VAL(vbp, dispc.feat->bp_start, 20);
3036f76ee892STomi Valkeinen
3037f76ee892STomi Valkeinen dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
3038f76ee892STomi Valkeinen dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
3039f76ee892STomi Valkeinen
3040f76ee892STomi Valkeinen switch (vsync_level) {
3041f76ee892STomi Valkeinen case OMAPDSS_SIG_ACTIVE_LOW:
3042f76ee892STomi Valkeinen vs = true;
3043f76ee892STomi Valkeinen break;
3044f76ee892STomi Valkeinen case OMAPDSS_SIG_ACTIVE_HIGH:
3045f76ee892STomi Valkeinen vs = false;
3046f76ee892STomi Valkeinen break;
3047f76ee892STomi Valkeinen default:
3048f76ee892STomi Valkeinen BUG();
3049f76ee892STomi Valkeinen }
3050f76ee892STomi Valkeinen
3051f76ee892STomi Valkeinen switch (hsync_level) {
3052f76ee892STomi Valkeinen case OMAPDSS_SIG_ACTIVE_LOW:
3053f76ee892STomi Valkeinen hs = true;
3054f76ee892STomi Valkeinen break;
3055f76ee892STomi Valkeinen case OMAPDSS_SIG_ACTIVE_HIGH:
3056f76ee892STomi Valkeinen hs = false;
3057f76ee892STomi Valkeinen break;
3058f76ee892STomi Valkeinen default:
3059f76ee892STomi Valkeinen BUG();
3060f76ee892STomi Valkeinen }
3061f76ee892STomi Valkeinen
3062f76ee892STomi Valkeinen switch (de_level) {
3063f76ee892STomi Valkeinen case OMAPDSS_SIG_ACTIVE_LOW:
3064f76ee892STomi Valkeinen de = true;
3065f76ee892STomi Valkeinen break;
3066f76ee892STomi Valkeinen case OMAPDSS_SIG_ACTIVE_HIGH:
3067f76ee892STomi Valkeinen de = false;
3068f76ee892STomi Valkeinen break;
3069f76ee892STomi Valkeinen default:
3070f76ee892STomi Valkeinen BUG();
3071f76ee892STomi Valkeinen }
3072f76ee892STomi Valkeinen
3073f76ee892STomi Valkeinen switch (data_pclk_edge) {
3074f76ee892STomi Valkeinen case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3075f76ee892STomi Valkeinen ipc = false;
3076f76ee892STomi Valkeinen break;
3077f76ee892STomi Valkeinen case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3078f76ee892STomi Valkeinen ipc = true;
3079f76ee892STomi Valkeinen break;
3080f76ee892STomi Valkeinen default:
3081f76ee892STomi Valkeinen BUG();
3082f76ee892STomi Valkeinen }
3083f76ee892STomi Valkeinen
3084f76ee892STomi Valkeinen /* always use the 'rf' setting */
3085f76ee892STomi Valkeinen onoff = true;
3086f76ee892STomi Valkeinen
3087f76ee892STomi Valkeinen switch (sync_pclk_edge) {
3088f76ee892STomi Valkeinen case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3089f76ee892STomi Valkeinen rf = false;
3090f76ee892STomi Valkeinen break;
3091f76ee892STomi Valkeinen case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3092f76ee892STomi Valkeinen rf = true;
3093f76ee892STomi Valkeinen break;
3094f76ee892STomi Valkeinen default:
3095f76ee892STomi Valkeinen BUG();
3096f76ee892STomi Valkeinen }
3097f76ee892STomi Valkeinen
3098f76ee892STomi Valkeinen l = FLD_VAL(onoff, 17, 17) |
3099f76ee892STomi Valkeinen FLD_VAL(rf, 16, 16) |
3100f76ee892STomi Valkeinen FLD_VAL(de, 15, 15) |
3101f76ee892STomi Valkeinen FLD_VAL(ipc, 14, 14) |
3102f76ee892STomi Valkeinen FLD_VAL(hs, 13, 13) |
3103f76ee892STomi Valkeinen FLD_VAL(vs, 12, 12);
3104f76ee892STomi Valkeinen
3105f76ee892STomi Valkeinen /* always set ALIGN bit when available */
3106f76ee892STomi Valkeinen if (dispc.feat->supports_sync_align)
3107f76ee892STomi Valkeinen l |= (1 << 18);
3108f76ee892STomi Valkeinen
3109f76ee892STomi Valkeinen dispc_write_reg(DISPC_POL_FREQ(channel), l);
3110f76ee892STomi Valkeinen
3111f76ee892STomi Valkeinen if (dispc.syscon_pol) {
3112f76ee892STomi Valkeinen const int shifts[] = {
3113f76ee892STomi Valkeinen [OMAP_DSS_CHANNEL_LCD] = 0,
3114f76ee892STomi Valkeinen [OMAP_DSS_CHANNEL_LCD2] = 1,
3115f76ee892STomi Valkeinen [OMAP_DSS_CHANNEL_LCD3] = 2,
3116f76ee892STomi Valkeinen };
3117f76ee892STomi Valkeinen
3118f76ee892STomi Valkeinen u32 mask, val;
3119f76ee892STomi Valkeinen
3120f76ee892STomi Valkeinen mask = (1 << 0) | (1 << 3) | (1 << 6);
3121f76ee892STomi Valkeinen val = (rf << 0) | (ipc << 3) | (onoff << 6);
3122f76ee892STomi Valkeinen
3123f76ee892STomi Valkeinen mask <<= 16 + shifts[channel];
3124f76ee892STomi Valkeinen val <<= 16 + shifts[channel];
3125f76ee892STomi Valkeinen
3126f76ee892STomi Valkeinen regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset,
3127f76ee892STomi Valkeinen mask, val);
3128f76ee892STomi Valkeinen }
3129f76ee892STomi Valkeinen }
3130f76ee892STomi Valkeinen
3131f76ee892STomi Valkeinen /* change name to mode? */
dispc_mgr_set_timings(enum omap_channel channel,const struct omap_video_timings * timings)3132f76ee892STomi Valkeinen void dispc_mgr_set_timings(enum omap_channel channel,
3133f76ee892STomi Valkeinen const struct omap_video_timings *timings)
3134f76ee892STomi Valkeinen {
3135f76ee892STomi Valkeinen unsigned xtot, ytot;
3136f76ee892STomi Valkeinen unsigned long ht, vt;
3137f76ee892STomi Valkeinen struct omap_video_timings t = *timings;
3138f76ee892STomi Valkeinen
3139f76ee892STomi Valkeinen DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
3140f76ee892STomi Valkeinen
3141f76ee892STomi Valkeinen if (!dispc_mgr_timings_ok(channel, &t)) {
3142f76ee892STomi Valkeinen BUG();
3143f76ee892STomi Valkeinen return;
3144f76ee892STomi Valkeinen }
3145f76ee892STomi Valkeinen
3146f76ee892STomi Valkeinen if (dss_mgr_is_lcd(channel)) {
3147f76ee892STomi Valkeinen _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
3148f76ee892STomi Valkeinen t.vfp, t.vbp, t.vsync_level, t.hsync_level,
3149f76ee892STomi Valkeinen t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
3150f76ee892STomi Valkeinen
3151f76ee892STomi Valkeinen xtot = t.x_res + t.hfp + t.hsw + t.hbp;
3152f76ee892STomi Valkeinen ytot = t.y_res + t.vfp + t.vsw + t.vbp;
3153f76ee892STomi Valkeinen
3154f76ee892STomi Valkeinen ht = timings->pixelclock / xtot;
3155f76ee892STomi Valkeinen vt = timings->pixelclock / xtot / ytot;
3156f76ee892STomi Valkeinen
3157f76ee892STomi Valkeinen DSSDBG("pck %u\n", timings->pixelclock);
3158f76ee892STomi Valkeinen DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
3159f76ee892STomi Valkeinen t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
3160f76ee892STomi Valkeinen DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3161f76ee892STomi Valkeinen t.vsync_level, t.hsync_level, t.data_pclk_edge,
3162f76ee892STomi Valkeinen t.de_level, t.sync_pclk_edge);
3163f76ee892STomi Valkeinen
3164f76ee892STomi Valkeinen DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
3165f76ee892STomi Valkeinen } else {
3166f76ee892STomi Valkeinen if (t.interlace)
3167f76ee892STomi Valkeinen t.y_res /= 2;
3168f76ee892STomi Valkeinen }
3169f76ee892STomi Valkeinen
3170f76ee892STomi Valkeinen dispc_mgr_set_size(channel, t.x_res, t.y_res);
3171f76ee892STomi Valkeinen }
3172f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_mgr_set_timings);
3173f76ee892STomi Valkeinen
dispc_mgr_set_lcd_divisor(enum omap_channel channel,u16 lck_div,u16 pck_div)3174f76ee892STomi Valkeinen static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
3175f76ee892STomi Valkeinen u16 pck_div)
3176f76ee892STomi Valkeinen {
3177f76ee892STomi Valkeinen BUG_ON(lck_div < 1);
3178f76ee892STomi Valkeinen BUG_ON(pck_div < 1);
3179f76ee892STomi Valkeinen
3180f76ee892STomi Valkeinen dispc_write_reg(DISPC_DIVISORo(channel),
3181f76ee892STomi Valkeinen FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
3182f76ee892STomi Valkeinen
3183f76ee892STomi Valkeinen if (!dss_has_feature(FEAT_CORE_CLK_DIV) &&
3184f76ee892STomi Valkeinen channel == OMAP_DSS_CHANNEL_LCD)
3185f76ee892STomi Valkeinen dispc.core_clk_rate = dispc_fclk_rate() / lck_div;
3186f76ee892STomi Valkeinen }
3187f76ee892STomi Valkeinen
dispc_mgr_get_lcd_divisor(enum omap_channel channel,int * lck_div,int * pck_div)3188f76ee892STomi Valkeinen static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
3189f76ee892STomi Valkeinen int *pck_div)
3190f76ee892STomi Valkeinen {
3191f76ee892STomi Valkeinen u32 l;
3192f76ee892STomi Valkeinen l = dispc_read_reg(DISPC_DIVISORo(channel));
3193f76ee892STomi Valkeinen *lck_div = FLD_GET(l, 23, 16);
3194f76ee892STomi Valkeinen *pck_div = FLD_GET(l, 7, 0);
3195f76ee892STomi Valkeinen }
3196f76ee892STomi Valkeinen
dispc_fclk_rate(void)3197f76ee892STomi Valkeinen static unsigned long dispc_fclk_rate(void)
3198f76ee892STomi Valkeinen {
3199f76ee892STomi Valkeinen struct dss_pll *pll;
3200f76ee892STomi Valkeinen unsigned long r = 0;
3201f76ee892STomi Valkeinen
3202f76ee892STomi Valkeinen switch (dss_get_dispc_clk_source()) {
3203f76ee892STomi Valkeinen case OMAP_DSS_CLK_SRC_FCK:
3204f76ee892STomi Valkeinen r = dss_get_dispc_clk_rate();
3205f76ee892STomi Valkeinen break;
3206f76ee892STomi Valkeinen case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
3207f76ee892STomi Valkeinen pll = dss_pll_find("dsi0");
3208f76ee892STomi Valkeinen if (!pll)
3209f76ee892STomi Valkeinen pll = dss_pll_find("video0");
3210f76ee892STomi Valkeinen
3211f76ee892STomi Valkeinen r = pll->cinfo.clkout[0];
3212f76ee892STomi Valkeinen break;
3213f76ee892STomi Valkeinen case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3214f76ee892STomi Valkeinen pll = dss_pll_find("dsi1");
3215f76ee892STomi Valkeinen if (!pll)
3216f76ee892STomi Valkeinen pll = dss_pll_find("video1");
3217f76ee892STomi Valkeinen
3218f76ee892STomi Valkeinen r = pll->cinfo.clkout[0];
3219f76ee892STomi Valkeinen break;
3220f76ee892STomi Valkeinen default:
3221f76ee892STomi Valkeinen BUG();
3222f76ee892STomi Valkeinen return 0;
3223f76ee892STomi Valkeinen }
3224f76ee892STomi Valkeinen
3225f76ee892STomi Valkeinen return r;
3226f76ee892STomi Valkeinen }
3227f76ee892STomi Valkeinen
dispc_mgr_lclk_rate(enum omap_channel channel)3228f76ee892STomi Valkeinen static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
3229f76ee892STomi Valkeinen {
3230f76ee892STomi Valkeinen struct dss_pll *pll;
3231f76ee892STomi Valkeinen int lcd;
3232f76ee892STomi Valkeinen unsigned long r;
3233f76ee892STomi Valkeinen u32 l;
3234f76ee892STomi Valkeinen
3235f76ee892STomi Valkeinen if (dss_mgr_is_lcd(channel)) {
3236f76ee892STomi Valkeinen l = dispc_read_reg(DISPC_DIVISORo(channel));
3237f76ee892STomi Valkeinen
3238f76ee892STomi Valkeinen lcd = FLD_GET(l, 23, 16);
3239f76ee892STomi Valkeinen
3240f76ee892STomi Valkeinen switch (dss_get_lcd_clk_source(channel)) {
3241f76ee892STomi Valkeinen case OMAP_DSS_CLK_SRC_FCK:
3242f76ee892STomi Valkeinen r = dss_get_dispc_clk_rate();
3243f76ee892STomi Valkeinen break;
3244f76ee892STomi Valkeinen case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
3245f76ee892STomi Valkeinen pll = dss_pll_find("dsi0");
3246f76ee892STomi Valkeinen if (!pll)
3247f76ee892STomi Valkeinen pll = dss_pll_find("video0");
3248f76ee892STomi Valkeinen
3249f76ee892STomi Valkeinen r = pll->cinfo.clkout[0];
3250f76ee892STomi Valkeinen break;
3251f76ee892STomi Valkeinen case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3252f76ee892STomi Valkeinen pll = dss_pll_find("dsi1");
3253f76ee892STomi Valkeinen if (!pll)
3254f76ee892STomi Valkeinen pll = dss_pll_find("video1");
3255f76ee892STomi Valkeinen
3256f76ee892STomi Valkeinen r = pll->cinfo.clkout[0];
3257f76ee892STomi Valkeinen break;
3258f76ee892STomi Valkeinen default:
3259f76ee892STomi Valkeinen BUG();
3260f76ee892STomi Valkeinen return 0;
3261f76ee892STomi Valkeinen }
3262f76ee892STomi Valkeinen
3263f76ee892STomi Valkeinen return r / lcd;
3264f76ee892STomi Valkeinen } else {
3265f76ee892STomi Valkeinen return dispc_fclk_rate();
3266f76ee892STomi Valkeinen }
3267f76ee892STomi Valkeinen }
3268f76ee892STomi Valkeinen
dispc_mgr_pclk_rate(enum omap_channel channel)3269f76ee892STomi Valkeinen static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
3270f76ee892STomi Valkeinen {
3271f76ee892STomi Valkeinen unsigned long r;
3272f76ee892STomi Valkeinen
3273f76ee892STomi Valkeinen if (dss_mgr_is_lcd(channel)) {
3274f76ee892STomi Valkeinen int pcd;
3275f76ee892STomi Valkeinen u32 l;
3276f76ee892STomi Valkeinen
3277f76ee892STomi Valkeinen l = dispc_read_reg(DISPC_DIVISORo(channel));
3278f76ee892STomi Valkeinen
3279f76ee892STomi Valkeinen pcd = FLD_GET(l, 7, 0);
3280f76ee892STomi Valkeinen
3281f76ee892STomi Valkeinen r = dispc_mgr_lclk_rate(channel);
3282f76ee892STomi Valkeinen
3283f76ee892STomi Valkeinen return r / pcd;
3284f76ee892STomi Valkeinen } else {
3285f76ee892STomi Valkeinen return dispc.tv_pclk_rate;
3286f76ee892STomi Valkeinen }
3287f76ee892STomi Valkeinen }
3288f76ee892STomi Valkeinen
dispc_set_tv_pclk(unsigned long pclk)3289f76ee892STomi Valkeinen void dispc_set_tv_pclk(unsigned long pclk)
3290f76ee892STomi Valkeinen {
3291f76ee892STomi Valkeinen dispc.tv_pclk_rate = pclk;
3292f76ee892STomi Valkeinen }
3293f76ee892STomi Valkeinen
dispc_core_clk_rate(void)3294f76ee892STomi Valkeinen static unsigned long dispc_core_clk_rate(void)
3295f76ee892STomi Valkeinen {
3296f76ee892STomi Valkeinen return dispc.core_clk_rate;
3297f76ee892STomi Valkeinen }
3298f76ee892STomi Valkeinen
dispc_plane_pclk_rate(enum omap_plane plane)3299f76ee892STomi Valkeinen static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3300f76ee892STomi Valkeinen {
3301f76ee892STomi Valkeinen enum omap_channel channel;
3302f76ee892STomi Valkeinen
3303f76ee892STomi Valkeinen if (plane == OMAP_DSS_WB)
3304f76ee892STomi Valkeinen return 0;
3305f76ee892STomi Valkeinen
3306f76ee892STomi Valkeinen channel = dispc_ovl_get_channel_out(plane);
3307f76ee892STomi Valkeinen
3308f76ee892STomi Valkeinen return dispc_mgr_pclk_rate(channel);
3309f76ee892STomi Valkeinen }
3310f76ee892STomi Valkeinen
dispc_plane_lclk_rate(enum omap_plane plane)3311f76ee892STomi Valkeinen static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3312f76ee892STomi Valkeinen {
3313f76ee892STomi Valkeinen enum omap_channel channel;
3314f76ee892STomi Valkeinen
3315f76ee892STomi Valkeinen if (plane == OMAP_DSS_WB)
3316f76ee892STomi Valkeinen return 0;
3317f76ee892STomi Valkeinen
3318f76ee892STomi Valkeinen channel = dispc_ovl_get_channel_out(plane);
3319f76ee892STomi Valkeinen
3320f76ee892STomi Valkeinen return dispc_mgr_lclk_rate(channel);
3321f76ee892STomi Valkeinen }
3322f76ee892STomi Valkeinen
dispc_dump_clocks_channel(struct seq_file * s,enum omap_channel channel)3323f76ee892STomi Valkeinen static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
3324f76ee892STomi Valkeinen {
3325f76ee892STomi Valkeinen int lcd, pcd;
3326f76ee892STomi Valkeinen enum omap_dss_clk_source lcd_clk_src;
3327f76ee892STomi Valkeinen
3328f76ee892STomi Valkeinen seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3329f76ee892STomi Valkeinen
3330f76ee892STomi Valkeinen lcd_clk_src = dss_get_lcd_clk_source(channel);
3331f76ee892STomi Valkeinen
3332f76ee892STomi Valkeinen seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3333f76ee892STomi Valkeinen dss_get_generic_clk_source_name(lcd_clk_src),
3334f76ee892STomi Valkeinen dss_feat_get_clk_source_name(lcd_clk_src));
3335f76ee892STomi Valkeinen
3336f76ee892STomi Valkeinen dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3337f76ee892STomi Valkeinen
3338f76ee892STomi Valkeinen seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3339f76ee892STomi Valkeinen dispc_mgr_lclk_rate(channel), lcd);
3340f76ee892STomi Valkeinen seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3341f76ee892STomi Valkeinen dispc_mgr_pclk_rate(channel), pcd);
3342f76ee892STomi Valkeinen }
3343f76ee892STomi Valkeinen
dispc_dump_clocks(struct seq_file * s)3344f76ee892STomi Valkeinen void dispc_dump_clocks(struct seq_file *s)
3345f76ee892STomi Valkeinen {
3346f76ee892STomi Valkeinen int lcd;
3347f76ee892STomi Valkeinen u32 l;
3348f76ee892STomi Valkeinen enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
3349f76ee892STomi Valkeinen
3350f76ee892STomi Valkeinen if (dispc_runtime_get())
3351f76ee892STomi Valkeinen return;
3352f76ee892STomi Valkeinen
3353f76ee892STomi Valkeinen seq_printf(s, "- DISPC -\n");
3354f76ee892STomi Valkeinen
3355f76ee892STomi Valkeinen seq_printf(s, "dispc fclk source = %s (%s)\n",
3356f76ee892STomi Valkeinen dss_get_generic_clk_source_name(dispc_clk_src),
3357f76ee892STomi Valkeinen dss_feat_get_clk_source_name(dispc_clk_src));
3358f76ee892STomi Valkeinen
3359f76ee892STomi Valkeinen seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
3360f76ee892STomi Valkeinen
3361f76ee892STomi Valkeinen if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3362f76ee892STomi Valkeinen seq_printf(s, "- DISPC-CORE-CLK -\n");
3363f76ee892STomi Valkeinen l = dispc_read_reg(DISPC_DIVISOR);
3364f76ee892STomi Valkeinen lcd = FLD_GET(l, 23, 16);
3365f76ee892STomi Valkeinen
3366f76ee892STomi Valkeinen seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3367f76ee892STomi Valkeinen (dispc_fclk_rate()/lcd), lcd);
3368f76ee892STomi Valkeinen }
3369f76ee892STomi Valkeinen
3370f76ee892STomi Valkeinen dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
3371f76ee892STomi Valkeinen
3372f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD2))
3373f76ee892STomi Valkeinen dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3374f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD3))
3375f76ee892STomi Valkeinen dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
3376f76ee892STomi Valkeinen
3377f76ee892STomi Valkeinen dispc_runtime_put();
3378f76ee892STomi Valkeinen }
3379f76ee892STomi Valkeinen
dispc_dump_regs(struct seq_file * s)3380f76ee892STomi Valkeinen static void dispc_dump_regs(struct seq_file *s)
3381f76ee892STomi Valkeinen {
3382f76ee892STomi Valkeinen int i, j;
3383f76ee892STomi Valkeinen const char *mgr_names[] = {
3384f76ee892STomi Valkeinen [OMAP_DSS_CHANNEL_LCD] = "LCD",
3385f76ee892STomi Valkeinen [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3386f76ee892STomi Valkeinen [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
3387f76ee892STomi Valkeinen [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
3388f76ee892STomi Valkeinen };
3389f76ee892STomi Valkeinen const char *ovl_names[] = {
3390f76ee892STomi Valkeinen [OMAP_DSS_GFX] = "GFX",
3391f76ee892STomi Valkeinen [OMAP_DSS_VIDEO1] = "VID1",
3392f76ee892STomi Valkeinen [OMAP_DSS_VIDEO2] = "VID2",
3393f76ee892STomi Valkeinen [OMAP_DSS_VIDEO3] = "VID3",
3394f76ee892STomi Valkeinen [OMAP_DSS_WB] = "WB",
3395f76ee892STomi Valkeinen };
3396f76ee892STomi Valkeinen const char **p_names;
3397f76ee892STomi Valkeinen
3398f76ee892STomi Valkeinen #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3399f76ee892STomi Valkeinen
3400f76ee892STomi Valkeinen if (dispc_runtime_get())
3401f76ee892STomi Valkeinen return;
3402f76ee892STomi Valkeinen
3403f76ee892STomi Valkeinen /* DISPC common registers */
3404f76ee892STomi Valkeinen DUMPREG(DISPC_REVISION);
3405f76ee892STomi Valkeinen DUMPREG(DISPC_SYSCONFIG);
3406f76ee892STomi Valkeinen DUMPREG(DISPC_SYSSTATUS);
3407f76ee892STomi Valkeinen DUMPREG(DISPC_IRQSTATUS);
3408f76ee892STomi Valkeinen DUMPREG(DISPC_IRQENABLE);
3409f76ee892STomi Valkeinen DUMPREG(DISPC_CONTROL);
3410f76ee892STomi Valkeinen DUMPREG(DISPC_CONFIG);
3411f76ee892STomi Valkeinen DUMPREG(DISPC_CAPABLE);
3412f76ee892STomi Valkeinen DUMPREG(DISPC_LINE_STATUS);
3413f76ee892STomi Valkeinen DUMPREG(DISPC_LINE_NUMBER);
3414f76ee892STomi Valkeinen if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3415f76ee892STomi Valkeinen dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
3416f76ee892STomi Valkeinen DUMPREG(DISPC_GLOBAL_ALPHA);
3417f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD2)) {
3418f76ee892STomi Valkeinen DUMPREG(DISPC_CONTROL2);
3419f76ee892STomi Valkeinen DUMPREG(DISPC_CONFIG2);
3420f76ee892STomi Valkeinen }
3421f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MGR_LCD3)) {
3422f76ee892STomi Valkeinen DUMPREG(DISPC_CONTROL3);
3423f76ee892STomi Valkeinen DUMPREG(DISPC_CONFIG3);
3424f76ee892STomi Valkeinen }
3425f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MFLAG))
3426f76ee892STomi Valkeinen DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE);
3427f76ee892STomi Valkeinen
3428f76ee892STomi Valkeinen #undef DUMPREG
3429f76ee892STomi Valkeinen
3430f76ee892STomi Valkeinen #define DISPC_REG(i, name) name(i)
3431f76ee892STomi Valkeinen #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3432f76ee892STomi Valkeinen (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
3433f76ee892STomi Valkeinen dispc_read_reg(DISPC_REG(i, r)))
3434f76ee892STomi Valkeinen
3435f76ee892STomi Valkeinen p_names = mgr_names;
3436f76ee892STomi Valkeinen
3437f76ee892STomi Valkeinen /* DISPC channel specific registers */
3438f76ee892STomi Valkeinen for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3439f76ee892STomi Valkeinen DUMPREG(i, DISPC_DEFAULT_COLOR);
3440f76ee892STomi Valkeinen DUMPREG(i, DISPC_TRANS_COLOR);
3441f76ee892STomi Valkeinen DUMPREG(i, DISPC_SIZE_MGR);
3442f76ee892STomi Valkeinen
3443f76ee892STomi Valkeinen if (i == OMAP_DSS_CHANNEL_DIGIT)
3444f76ee892STomi Valkeinen continue;
3445f76ee892STomi Valkeinen
3446f76ee892STomi Valkeinen DUMPREG(i, DISPC_TIMING_H);
3447f76ee892STomi Valkeinen DUMPREG(i, DISPC_TIMING_V);
3448f76ee892STomi Valkeinen DUMPREG(i, DISPC_POL_FREQ);
3449f76ee892STomi Valkeinen DUMPREG(i, DISPC_DIVISORo);
3450f76ee892STomi Valkeinen
3451f76ee892STomi Valkeinen DUMPREG(i, DISPC_DATA_CYCLE1);
3452f76ee892STomi Valkeinen DUMPREG(i, DISPC_DATA_CYCLE2);
3453f76ee892STomi Valkeinen DUMPREG(i, DISPC_DATA_CYCLE3);
3454f76ee892STomi Valkeinen
3455f76ee892STomi Valkeinen if (dss_has_feature(FEAT_CPR)) {
3456f76ee892STomi Valkeinen DUMPREG(i, DISPC_CPR_COEF_R);
3457f76ee892STomi Valkeinen DUMPREG(i, DISPC_CPR_COEF_G);
3458f76ee892STomi Valkeinen DUMPREG(i, DISPC_CPR_COEF_B);
3459f76ee892STomi Valkeinen }
3460f76ee892STomi Valkeinen }
3461f76ee892STomi Valkeinen
3462f76ee892STomi Valkeinen p_names = ovl_names;
3463f76ee892STomi Valkeinen
3464f76ee892STomi Valkeinen for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3465f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_BA0);
3466f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_BA1);
3467f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_POSITION);
3468f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_SIZE);
3469f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3470f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3471f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3472f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ROW_INC);
3473f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_PIXEL_INC);
3474f76ee892STomi Valkeinen
3475f76ee892STomi Valkeinen if (dss_has_feature(FEAT_PRELOAD))
3476f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_PRELOAD);
3477f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MFLAG))
3478f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
3479f76ee892STomi Valkeinen
3480f76ee892STomi Valkeinen if (i == OMAP_DSS_GFX) {
3481f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3482f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_TABLE_BA);
3483f76ee892STomi Valkeinen continue;
3484f76ee892STomi Valkeinen }
3485f76ee892STomi Valkeinen
3486f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIR);
3487f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3488f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ACCU0);
3489f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ACCU1);
3490f76ee892STomi Valkeinen if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3491f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_BA0_UV);
3492f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_BA1_UV);
3493f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIR2);
3494f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ACCU2_0);
3495f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ACCU2_1);
3496f76ee892STomi Valkeinen }
3497f76ee892STomi Valkeinen if (dss_has_feature(FEAT_ATTR2))
3498f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3499f76ee892STomi Valkeinen }
3500f76ee892STomi Valkeinen
3501f76ee892STomi Valkeinen if (dispc.feat->has_writeback) {
3502f76ee892STomi Valkeinen i = OMAP_DSS_WB;
3503f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_BA0);
3504f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_BA1);
3505f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_SIZE);
3506f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3507f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3508f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3509f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ROW_INC);
3510f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_PIXEL_INC);
3511f76ee892STomi Valkeinen
3512f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MFLAG))
3513f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
3514f76ee892STomi Valkeinen
3515f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIR);
3516f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3517f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ACCU0);
3518f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ACCU1);
3519f76ee892STomi Valkeinen if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3520f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_BA0_UV);
3521f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_BA1_UV);
3522f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIR2);
3523f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ACCU2_0);
3524f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ACCU2_1);
3525f76ee892STomi Valkeinen }
3526f76ee892STomi Valkeinen if (dss_has_feature(FEAT_ATTR2))
3527f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3528f76ee892STomi Valkeinen }
3529f76ee892STomi Valkeinen
3530f76ee892STomi Valkeinen #undef DISPC_REG
3531f76ee892STomi Valkeinen #undef DUMPREG
3532f76ee892STomi Valkeinen
3533f76ee892STomi Valkeinen #define DISPC_REG(plane, name, i) name(plane, i)
3534f76ee892STomi Valkeinen #define DUMPREG(plane, name, i) \
3535f76ee892STomi Valkeinen seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3536f76ee892STomi Valkeinen (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
3537f76ee892STomi Valkeinen dispc_read_reg(DISPC_REG(plane, name, i)))
3538f76ee892STomi Valkeinen
3539f76ee892STomi Valkeinen /* Video pipeline coefficient registers */
3540f76ee892STomi Valkeinen
3541f76ee892STomi Valkeinen /* start from OMAP_DSS_VIDEO1 */
3542f76ee892STomi Valkeinen for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3543f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
3544f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
3545f76ee892STomi Valkeinen
3546f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
3547f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
3548f76ee892STomi Valkeinen
3549f76ee892STomi Valkeinen for (j = 0; j < 5; j++)
3550f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_CONV_COEF, j);
3551f76ee892STomi Valkeinen
3552f76ee892STomi Valkeinen if (dss_has_feature(FEAT_FIR_COEF_V)) {
3553f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
3554f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3555f76ee892STomi Valkeinen }
3556f76ee892STomi Valkeinen
3557f76ee892STomi Valkeinen if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3558f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
3559f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
3560f76ee892STomi Valkeinen
3561f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
3562f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
3563f76ee892STomi Valkeinen
3564f76ee892STomi Valkeinen for (j = 0; j < 8; j++)
3565f76ee892STomi Valkeinen DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3566f76ee892STomi Valkeinen }
3567f76ee892STomi Valkeinen }
3568f76ee892STomi Valkeinen
3569f76ee892STomi Valkeinen dispc_runtime_put();
3570f76ee892STomi Valkeinen
3571f76ee892STomi Valkeinen #undef DISPC_REG
3572f76ee892STomi Valkeinen #undef DUMPREG
3573f76ee892STomi Valkeinen }
3574f76ee892STomi Valkeinen
3575f76ee892STomi Valkeinen /* calculate clock rates using dividers in cinfo */
dispc_calc_clock_rates(unsigned long dispc_fclk_rate,struct dispc_clock_info * cinfo)3576f76ee892STomi Valkeinen int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3577f76ee892STomi Valkeinen struct dispc_clock_info *cinfo)
3578f76ee892STomi Valkeinen {
3579f76ee892STomi Valkeinen if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3580f76ee892STomi Valkeinen return -EINVAL;
3581f76ee892STomi Valkeinen if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
3582f76ee892STomi Valkeinen return -EINVAL;
3583f76ee892STomi Valkeinen
3584f76ee892STomi Valkeinen cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3585f76ee892STomi Valkeinen cinfo->pck = cinfo->lck / cinfo->pck_div;
3586f76ee892STomi Valkeinen
3587f76ee892STomi Valkeinen return 0;
3588f76ee892STomi Valkeinen }
3589f76ee892STomi Valkeinen
dispc_div_calc(unsigned long dispc,unsigned long pck_min,unsigned long pck_max,dispc_div_calc_func func,void * data)3590f76ee892STomi Valkeinen bool dispc_div_calc(unsigned long dispc,
3591f76ee892STomi Valkeinen unsigned long pck_min, unsigned long pck_max,
3592f76ee892STomi Valkeinen dispc_div_calc_func func, void *data)
3593f76ee892STomi Valkeinen {
3594f76ee892STomi Valkeinen int lckd, lckd_start, lckd_stop;
3595f76ee892STomi Valkeinen int pckd, pckd_start, pckd_stop;
3596f76ee892STomi Valkeinen unsigned long pck, lck;
3597f76ee892STomi Valkeinen unsigned long lck_max;
3598f76ee892STomi Valkeinen unsigned long pckd_hw_min, pckd_hw_max;
3599f76ee892STomi Valkeinen unsigned min_fck_per_pck;
3600f76ee892STomi Valkeinen unsigned long fck;
3601f76ee892STomi Valkeinen
360235b522cfSTomi Valkeinen #ifdef CONFIG_FB_OMAP2_DSS_MIN_FCK_PER_PCK
360335b522cfSTomi Valkeinen min_fck_per_pck = CONFIG_FB_OMAP2_DSS_MIN_FCK_PER_PCK;
3604f76ee892STomi Valkeinen #else
3605f76ee892STomi Valkeinen min_fck_per_pck = 0;
3606f76ee892STomi Valkeinen #endif
3607f76ee892STomi Valkeinen
3608f76ee892STomi Valkeinen pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3609f76ee892STomi Valkeinen pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3610f76ee892STomi Valkeinen
3611f76ee892STomi Valkeinen lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
3612f76ee892STomi Valkeinen
3613f76ee892STomi Valkeinen pck_min = pck_min ? pck_min : 1;
3614f76ee892STomi Valkeinen pck_max = pck_max ? pck_max : ULONG_MAX;
3615f76ee892STomi Valkeinen
3616f76ee892STomi Valkeinen lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul);
3617f76ee892STomi Valkeinen lckd_stop = min(dispc / pck_min, 255ul);
3618f76ee892STomi Valkeinen
3619f76ee892STomi Valkeinen for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3620f76ee892STomi Valkeinen lck = dispc / lckd;
3621f76ee892STomi Valkeinen
3622f76ee892STomi Valkeinen pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3623f76ee892STomi Valkeinen pckd_stop = min(lck / pck_min, pckd_hw_max);
3624f76ee892STomi Valkeinen
3625f76ee892STomi Valkeinen for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3626f76ee892STomi Valkeinen pck = lck / pckd;
3627f76ee892STomi Valkeinen
3628f76ee892STomi Valkeinen /*
3629f76ee892STomi Valkeinen * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3630f76ee892STomi Valkeinen * clock, which means we're configuring DISPC fclk here
3631f76ee892STomi Valkeinen * also. Thus we need to use the calculated lck. For
3632f76ee892STomi Valkeinen * OMAP4+ the DISPC fclk is a separate clock.
3633f76ee892STomi Valkeinen */
3634f76ee892STomi Valkeinen if (dss_has_feature(FEAT_CORE_CLK_DIV))
3635f76ee892STomi Valkeinen fck = dispc_core_clk_rate();
3636f76ee892STomi Valkeinen else
3637f76ee892STomi Valkeinen fck = lck;
3638f76ee892STomi Valkeinen
3639f76ee892STomi Valkeinen if (fck < pck * min_fck_per_pck)
3640f76ee892STomi Valkeinen continue;
3641f76ee892STomi Valkeinen
3642f76ee892STomi Valkeinen if (func(lckd, pckd, lck, pck, data))
3643f76ee892STomi Valkeinen return true;
3644f76ee892STomi Valkeinen }
3645f76ee892STomi Valkeinen }
3646f76ee892STomi Valkeinen
3647f76ee892STomi Valkeinen return false;
3648f76ee892STomi Valkeinen }
3649f76ee892STomi Valkeinen
dispc_mgr_set_clock_div(enum omap_channel channel,const struct dispc_clock_info * cinfo)3650f76ee892STomi Valkeinen void dispc_mgr_set_clock_div(enum omap_channel channel,
3651f76ee892STomi Valkeinen const struct dispc_clock_info *cinfo)
3652f76ee892STomi Valkeinen {
3653f76ee892STomi Valkeinen DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3654f76ee892STomi Valkeinen DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3655f76ee892STomi Valkeinen
3656f76ee892STomi Valkeinen dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
3657f76ee892STomi Valkeinen }
3658f76ee892STomi Valkeinen
dispc_mgr_get_clock_div(enum omap_channel channel,struct dispc_clock_info * cinfo)3659f76ee892STomi Valkeinen int dispc_mgr_get_clock_div(enum omap_channel channel,
3660f76ee892STomi Valkeinen struct dispc_clock_info *cinfo)
3661f76ee892STomi Valkeinen {
3662f76ee892STomi Valkeinen unsigned long fck;
3663f76ee892STomi Valkeinen
3664f76ee892STomi Valkeinen fck = dispc_fclk_rate();
3665f76ee892STomi Valkeinen
3666f76ee892STomi Valkeinen cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3667f76ee892STomi Valkeinen cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
3668f76ee892STomi Valkeinen
3669f76ee892STomi Valkeinen cinfo->lck = fck / cinfo->lck_div;
3670f76ee892STomi Valkeinen cinfo->pck = cinfo->lck / cinfo->pck_div;
3671f76ee892STomi Valkeinen
3672f76ee892STomi Valkeinen return 0;
3673f76ee892STomi Valkeinen }
3674f76ee892STomi Valkeinen
dispc_read_irqstatus(void)3675f76ee892STomi Valkeinen u32 dispc_read_irqstatus(void)
3676f76ee892STomi Valkeinen {
3677f76ee892STomi Valkeinen return dispc_read_reg(DISPC_IRQSTATUS);
3678f76ee892STomi Valkeinen }
3679f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_read_irqstatus);
3680f76ee892STomi Valkeinen
dispc_clear_irqstatus(u32 mask)3681f76ee892STomi Valkeinen void dispc_clear_irqstatus(u32 mask)
3682f76ee892STomi Valkeinen {
3683f76ee892STomi Valkeinen dispc_write_reg(DISPC_IRQSTATUS, mask);
3684f76ee892STomi Valkeinen }
3685f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_clear_irqstatus);
3686f76ee892STomi Valkeinen
dispc_read_irqenable(void)3687f76ee892STomi Valkeinen u32 dispc_read_irqenable(void)
3688f76ee892STomi Valkeinen {
3689f76ee892STomi Valkeinen return dispc_read_reg(DISPC_IRQENABLE);
3690f76ee892STomi Valkeinen }
3691f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_read_irqenable);
3692f76ee892STomi Valkeinen
dispc_write_irqenable(u32 mask)3693f76ee892STomi Valkeinen void dispc_write_irqenable(u32 mask)
3694f76ee892STomi Valkeinen {
3695f76ee892STomi Valkeinen u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3696f76ee892STomi Valkeinen
3697f76ee892STomi Valkeinen /* clear the irqstatus for newly enabled irqs */
3698f76ee892STomi Valkeinen dispc_clear_irqstatus((mask ^ old_mask) & mask);
3699f76ee892STomi Valkeinen
3700f76ee892STomi Valkeinen dispc_write_reg(DISPC_IRQENABLE, mask);
3701f76ee892STomi Valkeinen }
3702f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_write_irqenable);
3703f76ee892STomi Valkeinen
dispc_enable_sidle(void)3704f76ee892STomi Valkeinen void dispc_enable_sidle(void)
3705f76ee892STomi Valkeinen {
3706f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3707f76ee892STomi Valkeinen }
3708f76ee892STomi Valkeinen
dispc_disable_sidle(void)3709f76ee892STomi Valkeinen void dispc_disable_sidle(void)
3710f76ee892STomi Valkeinen {
3711f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3712f76ee892STomi Valkeinen }
3713f76ee892STomi Valkeinen
_omap_dispc_initial_config(void)3714f76ee892STomi Valkeinen static void _omap_dispc_initial_config(void)
3715f76ee892STomi Valkeinen {
3716f76ee892STomi Valkeinen u32 l;
3717f76ee892STomi Valkeinen
3718f76ee892STomi Valkeinen /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3719f76ee892STomi Valkeinen if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3720f76ee892STomi Valkeinen l = dispc_read_reg(DISPC_DIVISOR);
3721f76ee892STomi Valkeinen /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3722f76ee892STomi Valkeinen l = FLD_MOD(l, 1, 0, 0);
3723f76ee892STomi Valkeinen l = FLD_MOD(l, 1, 23, 16);
3724f76ee892STomi Valkeinen dispc_write_reg(DISPC_DIVISOR, l);
3725f76ee892STomi Valkeinen
3726f76ee892STomi Valkeinen dispc.core_clk_rate = dispc_fclk_rate();
3727f76ee892STomi Valkeinen }
3728f76ee892STomi Valkeinen
3729f76ee892STomi Valkeinen /* FUNCGATED */
3730f76ee892STomi Valkeinen if (dss_has_feature(FEAT_FUNCGATED))
3731f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3732f76ee892STomi Valkeinen
3733f76ee892STomi Valkeinen dispc_setup_color_conv_coef();
3734f76ee892STomi Valkeinen
3735f76ee892STomi Valkeinen dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3736f76ee892STomi Valkeinen
3737f76ee892STomi Valkeinen dispc_init_fifos();
3738f76ee892STomi Valkeinen
3739f76ee892STomi Valkeinen dispc_configure_burst_sizes();
3740f76ee892STomi Valkeinen
3741f76ee892STomi Valkeinen dispc_ovl_enable_zorder_planes();
3742f76ee892STomi Valkeinen
3743f76ee892STomi Valkeinen if (dispc.feat->mstandby_workaround)
3744f76ee892STomi Valkeinen REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0);
3745f76ee892STomi Valkeinen
3746f76ee892STomi Valkeinen if (dss_has_feature(FEAT_MFLAG))
3747f76ee892STomi Valkeinen dispc_init_mflag();
3748f76ee892STomi Valkeinen }
3749f76ee892STomi Valkeinen
3750f76ee892STomi Valkeinen static const struct dispc_features omap24xx_dispc_feats = {
3751f76ee892STomi Valkeinen .sw_start = 5,
3752f76ee892STomi Valkeinen .fp_start = 15,
3753f76ee892STomi Valkeinen .bp_start = 27,
3754f76ee892STomi Valkeinen .sw_max = 64,
3755f76ee892STomi Valkeinen .vp_max = 255,
3756f76ee892STomi Valkeinen .hp_max = 256,
3757f76ee892STomi Valkeinen .mgr_width_start = 10,
3758f76ee892STomi Valkeinen .mgr_height_start = 26,
3759f76ee892STomi Valkeinen .mgr_width_max = 2048,
3760f76ee892STomi Valkeinen .mgr_height_max = 2048,
3761f76ee892STomi Valkeinen .max_lcd_pclk = 66500000,
3762f76ee892STomi Valkeinen .calc_scaling = dispc_ovl_calc_scaling_24xx,
3763f76ee892STomi Valkeinen .calc_core_clk = calc_core_clk_24xx,
3764f76ee892STomi Valkeinen .num_fifos = 3,
3765f76ee892STomi Valkeinen .no_framedone_tv = true,
3766f76ee892STomi Valkeinen .set_max_preload = false,
3767f76ee892STomi Valkeinen .last_pixel_inc_missing = true,
3768f76ee892STomi Valkeinen };
3769f76ee892STomi Valkeinen
3770f76ee892STomi Valkeinen static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
3771f76ee892STomi Valkeinen .sw_start = 5,
3772f76ee892STomi Valkeinen .fp_start = 15,
3773f76ee892STomi Valkeinen .bp_start = 27,
3774f76ee892STomi Valkeinen .sw_max = 64,
3775f76ee892STomi Valkeinen .vp_max = 255,
3776f76ee892STomi Valkeinen .hp_max = 256,
3777f76ee892STomi Valkeinen .mgr_width_start = 10,
3778f76ee892STomi Valkeinen .mgr_height_start = 26,
3779f76ee892STomi Valkeinen .mgr_width_max = 2048,
3780f76ee892STomi Valkeinen .mgr_height_max = 2048,
3781f76ee892STomi Valkeinen .max_lcd_pclk = 173000000,
3782f76ee892STomi Valkeinen .max_tv_pclk = 59000000,
3783f76ee892STomi Valkeinen .calc_scaling = dispc_ovl_calc_scaling_34xx,
3784f76ee892STomi Valkeinen .calc_core_clk = calc_core_clk_34xx,
3785f76ee892STomi Valkeinen .num_fifos = 3,
3786f76ee892STomi Valkeinen .no_framedone_tv = true,
3787f76ee892STomi Valkeinen .set_max_preload = false,
3788f76ee892STomi Valkeinen .last_pixel_inc_missing = true,
3789f76ee892STomi Valkeinen };
3790f76ee892STomi Valkeinen
3791f76ee892STomi Valkeinen static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
3792f76ee892STomi Valkeinen .sw_start = 7,
3793f76ee892STomi Valkeinen .fp_start = 19,
3794f76ee892STomi Valkeinen .bp_start = 31,
3795f76ee892STomi Valkeinen .sw_max = 256,
3796f76ee892STomi Valkeinen .vp_max = 4095,
3797f76ee892STomi Valkeinen .hp_max = 4096,
3798f76ee892STomi Valkeinen .mgr_width_start = 10,
3799f76ee892STomi Valkeinen .mgr_height_start = 26,
3800f76ee892STomi Valkeinen .mgr_width_max = 2048,
3801f76ee892STomi Valkeinen .mgr_height_max = 2048,
3802f76ee892STomi Valkeinen .max_lcd_pclk = 173000000,
3803f76ee892STomi Valkeinen .max_tv_pclk = 59000000,
3804f76ee892STomi Valkeinen .calc_scaling = dispc_ovl_calc_scaling_34xx,
3805f76ee892STomi Valkeinen .calc_core_clk = calc_core_clk_34xx,
3806f76ee892STomi Valkeinen .num_fifos = 3,
3807f76ee892STomi Valkeinen .no_framedone_tv = true,
3808f76ee892STomi Valkeinen .set_max_preload = false,
3809f76ee892STomi Valkeinen .last_pixel_inc_missing = true,
3810f76ee892STomi Valkeinen };
3811f76ee892STomi Valkeinen
3812f76ee892STomi Valkeinen static const struct dispc_features omap44xx_dispc_feats = {
3813f76ee892STomi Valkeinen .sw_start = 7,
3814f76ee892STomi Valkeinen .fp_start = 19,
3815f76ee892STomi Valkeinen .bp_start = 31,
3816f76ee892STomi Valkeinen .sw_max = 256,
3817f76ee892STomi Valkeinen .vp_max = 4095,
3818f76ee892STomi Valkeinen .hp_max = 4096,
3819f76ee892STomi Valkeinen .mgr_width_start = 10,
3820f76ee892STomi Valkeinen .mgr_height_start = 26,
3821f76ee892STomi Valkeinen .mgr_width_max = 2048,
3822f76ee892STomi Valkeinen .mgr_height_max = 2048,
3823f76ee892STomi Valkeinen .max_lcd_pclk = 170000000,
3824f76ee892STomi Valkeinen .max_tv_pclk = 185625000,
3825f76ee892STomi Valkeinen .calc_scaling = dispc_ovl_calc_scaling_44xx,
3826f76ee892STomi Valkeinen .calc_core_clk = calc_core_clk_44xx,
3827f76ee892STomi Valkeinen .num_fifos = 5,
3828f76ee892STomi Valkeinen .gfx_fifo_workaround = true,
3829f76ee892STomi Valkeinen .set_max_preload = true,
3830f76ee892STomi Valkeinen .supports_sync_align = true,
3831f76ee892STomi Valkeinen .has_writeback = true,
3832f76ee892STomi Valkeinen };
3833f76ee892STomi Valkeinen
3834f76ee892STomi Valkeinen static const struct dispc_features omap54xx_dispc_feats = {
3835f76ee892STomi Valkeinen .sw_start = 7,
3836f76ee892STomi Valkeinen .fp_start = 19,
3837f76ee892STomi Valkeinen .bp_start = 31,
3838f76ee892STomi Valkeinen .sw_max = 256,
3839f76ee892STomi Valkeinen .vp_max = 4095,
3840f76ee892STomi Valkeinen .hp_max = 4096,
3841f76ee892STomi Valkeinen .mgr_width_start = 11,
3842f76ee892STomi Valkeinen .mgr_height_start = 27,
3843f76ee892STomi Valkeinen .mgr_width_max = 4096,
3844f76ee892STomi Valkeinen .mgr_height_max = 4096,
3845f76ee892STomi Valkeinen .max_lcd_pclk = 170000000,
3846f76ee892STomi Valkeinen .max_tv_pclk = 186000000,
3847f76ee892STomi Valkeinen .calc_scaling = dispc_ovl_calc_scaling_44xx,
3848f76ee892STomi Valkeinen .calc_core_clk = calc_core_clk_44xx,
3849f76ee892STomi Valkeinen .num_fifos = 5,
3850f76ee892STomi Valkeinen .gfx_fifo_workaround = true,
3851f76ee892STomi Valkeinen .mstandby_workaround = true,
3852f76ee892STomi Valkeinen .set_max_preload = true,
3853f76ee892STomi Valkeinen .supports_sync_align = true,
3854f76ee892STomi Valkeinen .has_writeback = true,
3855f76ee892STomi Valkeinen };
3856f76ee892STomi Valkeinen
dispc_get_features(void)3857ee334e00SLadislav Michl static const struct dispc_features *dispc_get_features(void)
3858f76ee892STomi Valkeinen {
3859f76ee892STomi Valkeinen switch (omapdss_get_version()) {
3860f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP24xx:
3861ee334e00SLadislav Michl return &omap24xx_dispc_feats;
3862f76ee892STomi Valkeinen
3863f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP34xx_ES1:
3864ee334e00SLadislav Michl return &omap34xx_rev1_0_dispc_feats;
3865f76ee892STomi Valkeinen
3866f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP34xx_ES3:
3867f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP3630:
3868f76ee892STomi Valkeinen case OMAPDSS_VER_AM35xx:
3869f76ee892STomi Valkeinen case OMAPDSS_VER_AM43xx:
3870ee334e00SLadislav Michl return &omap34xx_rev3_0_dispc_feats;
3871f76ee892STomi Valkeinen
3872f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP4430_ES1:
3873f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP4430_ES2:
3874f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP4:
3875ee334e00SLadislav Michl return &omap44xx_dispc_feats;
3876f76ee892STomi Valkeinen
3877f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP5:
3878f76ee892STomi Valkeinen case OMAPDSS_VER_DRA7xx:
3879ee334e00SLadislav Michl return &omap54xx_dispc_feats;
3880f76ee892STomi Valkeinen
3881f76ee892STomi Valkeinen default:
3882ee334e00SLadislav Michl return NULL;
3883f76ee892STomi Valkeinen }
3884f76ee892STomi Valkeinen }
3885f76ee892STomi Valkeinen
dispc_irq_handler(int irq,void * arg)3886f76ee892STomi Valkeinen static irqreturn_t dispc_irq_handler(int irq, void *arg)
3887f76ee892STomi Valkeinen {
3888f76ee892STomi Valkeinen if (!dispc.is_enabled)
3889f76ee892STomi Valkeinen return IRQ_NONE;
3890f76ee892STomi Valkeinen
3891f76ee892STomi Valkeinen return dispc.user_handler(irq, dispc.user_data);
3892f76ee892STomi Valkeinen }
3893f76ee892STomi Valkeinen
dispc_request_irq(irq_handler_t handler,void * dev_id)3894f76ee892STomi Valkeinen int dispc_request_irq(irq_handler_t handler, void *dev_id)
3895f76ee892STomi Valkeinen {
3896f76ee892STomi Valkeinen int r;
3897f76ee892STomi Valkeinen
3898f76ee892STomi Valkeinen if (dispc.user_handler != NULL)
3899f76ee892STomi Valkeinen return -EBUSY;
3900f76ee892STomi Valkeinen
3901f76ee892STomi Valkeinen dispc.user_handler = handler;
3902f76ee892STomi Valkeinen dispc.user_data = dev_id;
3903f76ee892STomi Valkeinen
3904f76ee892STomi Valkeinen /* ensure the dispc_irq_handler sees the values above */
3905f76ee892STomi Valkeinen smp_wmb();
3906f76ee892STomi Valkeinen
3907f76ee892STomi Valkeinen r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler,
3908f76ee892STomi Valkeinen IRQF_SHARED, "OMAP DISPC", &dispc);
3909f76ee892STomi Valkeinen if (r) {
3910f76ee892STomi Valkeinen dispc.user_handler = NULL;
3911f76ee892STomi Valkeinen dispc.user_data = NULL;
3912f76ee892STomi Valkeinen }
3913f76ee892STomi Valkeinen
3914f76ee892STomi Valkeinen return r;
3915f76ee892STomi Valkeinen }
3916f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_request_irq);
3917f76ee892STomi Valkeinen
dispc_free_irq(void * dev_id)3918f76ee892STomi Valkeinen void dispc_free_irq(void *dev_id)
3919f76ee892STomi Valkeinen {
3920f76ee892STomi Valkeinen devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc);
3921f76ee892STomi Valkeinen
3922f76ee892STomi Valkeinen dispc.user_handler = NULL;
3923f76ee892STomi Valkeinen dispc.user_data = NULL;
3924f76ee892STomi Valkeinen }
3925f76ee892STomi Valkeinen EXPORT_SYMBOL(dispc_free_irq);
3926f76ee892STomi Valkeinen
3927f76ee892STomi Valkeinen /* DISPC HW IP initialisation */
dispc_bind(struct device * dev,struct device * master,void * data)3928f76ee892STomi Valkeinen static int dispc_bind(struct device *dev, struct device *master, void *data)
3929f76ee892STomi Valkeinen {
3930f76ee892STomi Valkeinen struct platform_device *pdev = to_platform_device(dev);
3931f76ee892STomi Valkeinen u32 rev;
3932f76ee892STomi Valkeinen int r = 0;
3933f76ee892STomi Valkeinen struct resource *dispc_mem;
3934f76ee892STomi Valkeinen struct device_node *np = pdev->dev.of_node;
3935f76ee892STomi Valkeinen
3936f76ee892STomi Valkeinen dispc.pdev = pdev;
3937f76ee892STomi Valkeinen
3938f76ee892STomi Valkeinen spin_lock_init(&dispc.control_lock);
3939f76ee892STomi Valkeinen
3940ee334e00SLadislav Michl dispc.feat = dispc_get_features();
3941ee334e00SLadislav Michl if (!dispc.feat)
3942ee334e00SLadislav Michl return -ENODEV;
3943f76ee892STomi Valkeinen
3944f76ee892STomi Valkeinen dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3945f76ee892STomi Valkeinen if (!dispc_mem) {
3946f76ee892STomi Valkeinen DSSERR("can't get IORESOURCE_MEM DISPC\n");
3947f76ee892STomi Valkeinen return -EINVAL;
3948f76ee892STomi Valkeinen }
3949f76ee892STomi Valkeinen
3950f76ee892STomi Valkeinen dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3951f76ee892STomi Valkeinen resource_size(dispc_mem));
3952f76ee892STomi Valkeinen if (!dispc.base) {
3953f76ee892STomi Valkeinen DSSERR("can't ioremap DISPC\n");
3954f76ee892STomi Valkeinen return -ENOMEM;
3955f76ee892STomi Valkeinen }
3956f76ee892STomi Valkeinen
3957f76ee892STomi Valkeinen dispc.irq = platform_get_irq(dispc.pdev, 0);
3958f76ee892STomi Valkeinen if (dispc.irq < 0) {
3959f76ee892STomi Valkeinen DSSERR("platform_get_irq failed\n");
3960f76ee892STomi Valkeinen return -ENODEV;
3961f76ee892STomi Valkeinen }
3962f76ee892STomi Valkeinen
3963f76ee892STomi Valkeinen if (np && of_property_read_bool(np, "syscon-pol")) {
3964f76ee892STomi Valkeinen dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
3965f76ee892STomi Valkeinen if (IS_ERR(dispc.syscon_pol)) {
3966f76ee892STomi Valkeinen dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
3967f76ee892STomi Valkeinen return PTR_ERR(dispc.syscon_pol);
3968f76ee892STomi Valkeinen }
3969f76ee892STomi Valkeinen
3970f76ee892STomi Valkeinen if (of_property_read_u32_index(np, "syscon-pol", 1,
3971f76ee892STomi Valkeinen &dispc.syscon_pol_offset)) {
3972f76ee892STomi Valkeinen dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
3973f76ee892STomi Valkeinen return -EINVAL;
3974f76ee892STomi Valkeinen }
3975f76ee892STomi Valkeinen }
3976f76ee892STomi Valkeinen
3977f76ee892STomi Valkeinen pm_runtime_enable(&pdev->dev);
3978f76ee892STomi Valkeinen
3979f76ee892STomi Valkeinen r = dispc_runtime_get();
3980f76ee892STomi Valkeinen if (r)
3981f76ee892STomi Valkeinen goto err_runtime_get;
3982f76ee892STomi Valkeinen
3983f76ee892STomi Valkeinen _omap_dispc_initial_config();
3984f76ee892STomi Valkeinen
3985f76ee892STomi Valkeinen rev = dispc_read_reg(DISPC_REVISION);
3986f76ee892STomi Valkeinen dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
3987f76ee892STomi Valkeinen FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3988f76ee892STomi Valkeinen
3989f76ee892STomi Valkeinen dispc_runtime_put();
3990f76ee892STomi Valkeinen
3991f76ee892STomi Valkeinen dss_init_overlay_managers();
3992f76ee892STomi Valkeinen
3993f76ee892STomi Valkeinen dss_debugfs_create_file("dispc", dispc_dump_regs);
3994f76ee892STomi Valkeinen
3995f76ee892STomi Valkeinen return 0;
3996f76ee892STomi Valkeinen
3997f76ee892STomi Valkeinen err_runtime_get:
3998f76ee892STomi Valkeinen pm_runtime_disable(&pdev->dev);
3999f76ee892STomi Valkeinen return r;
4000f76ee892STomi Valkeinen }
4001f76ee892STomi Valkeinen
dispc_unbind(struct device * dev,struct device * master,void * data)4002f76ee892STomi Valkeinen static void dispc_unbind(struct device *dev, struct device *master,
4003f76ee892STomi Valkeinen void *data)
4004f76ee892STomi Valkeinen {
4005f76ee892STomi Valkeinen pm_runtime_disable(dev);
4006f76ee892STomi Valkeinen
4007f76ee892STomi Valkeinen dss_uninit_overlay_managers();
4008f76ee892STomi Valkeinen }
4009f76ee892STomi Valkeinen
4010f76ee892STomi Valkeinen static const struct component_ops dispc_component_ops = {
4011f76ee892STomi Valkeinen .bind = dispc_bind,
4012f76ee892STomi Valkeinen .unbind = dispc_unbind,
4013f76ee892STomi Valkeinen };
4014f76ee892STomi Valkeinen
dispc_probe(struct platform_device * pdev)4015f76ee892STomi Valkeinen static int dispc_probe(struct platform_device *pdev)
4016f76ee892STomi Valkeinen {
4017f76ee892STomi Valkeinen return component_add(&pdev->dev, &dispc_component_ops);
4018f76ee892STomi Valkeinen }
4019f76ee892STomi Valkeinen
dispc_remove(struct platform_device * pdev)4020dc6b77baSUwe Kleine-König static void dispc_remove(struct platform_device *pdev)
4021f76ee892STomi Valkeinen {
4022f76ee892STomi Valkeinen component_del(&pdev->dev, &dispc_component_ops);
4023f76ee892STomi Valkeinen }
4024f76ee892STomi Valkeinen
dispc_runtime_suspend(struct device * dev)4025f76ee892STomi Valkeinen static int dispc_runtime_suspend(struct device *dev)
4026f76ee892STomi Valkeinen {
4027f76ee892STomi Valkeinen dispc.is_enabled = false;
4028f76ee892STomi Valkeinen /* ensure the dispc_irq_handler sees the is_enabled value */
4029f76ee892STomi Valkeinen smp_wmb();
4030f76ee892STomi Valkeinen /* wait for current handler to finish before turning the DISPC off */
4031f76ee892STomi Valkeinen synchronize_irq(dispc.irq);
4032f76ee892STomi Valkeinen
4033f76ee892STomi Valkeinen dispc_save_context();
4034f76ee892STomi Valkeinen
4035f76ee892STomi Valkeinen return 0;
4036f76ee892STomi Valkeinen }
4037f76ee892STomi Valkeinen
dispc_runtime_resume(struct device * dev)4038f76ee892STomi Valkeinen static int dispc_runtime_resume(struct device *dev)
4039f76ee892STomi Valkeinen {
4040f76ee892STomi Valkeinen /*
4041f76ee892STomi Valkeinen * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4042f76ee892STomi Valkeinen * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4043f76ee892STomi Valkeinen * _omap_dispc_initial_config(). We can thus use it to detect if
4044f76ee892STomi Valkeinen * we have lost register context.
4045f76ee892STomi Valkeinen */
4046f76ee892STomi Valkeinen if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
4047f76ee892STomi Valkeinen _omap_dispc_initial_config();
4048f76ee892STomi Valkeinen
4049f76ee892STomi Valkeinen dispc_restore_context();
4050f76ee892STomi Valkeinen }
4051f76ee892STomi Valkeinen
4052f76ee892STomi Valkeinen dispc.is_enabled = true;
4053f76ee892STomi Valkeinen /* ensure the dispc_irq_handler sees the is_enabled value */
4054f76ee892STomi Valkeinen smp_wmb();
4055f76ee892STomi Valkeinen
4056f76ee892STomi Valkeinen return 0;
4057f76ee892STomi Valkeinen }
4058f76ee892STomi Valkeinen
4059f76ee892STomi Valkeinen static const struct dev_pm_ops dispc_pm_ops = {
4060f76ee892STomi Valkeinen .runtime_suspend = dispc_runtime_suspend,
4061f76ee892STomi Valkeinen .runtime_resume = dispc_runtime_resume,
4062f76ee892STomi Valkeinen };
4063f76ee892STomi Valkeinen
4064f76ee892STomi Valkeinen static const struct of_device_id dispc_of_match[] = {
4065f76ee892STomi Valkeinen { .compatible = "ti,omap2-dispc", },
4066f76ee892STomi Valkeinen { .compatible = "ti,omap3-dispc", },
4067f76ee892STomi Valkeinen { .compatible = "ti,omap4-dispc", },
4068f76ee892STomi Valkeinen { .compatible = "ti,omap5-dispc", },
4069f76ee892STomi Valkeinen { .compatible = "ti,dra7-dispc", },
4070f76ee892STomi Valkeinen {},
4071f76ee892STomi Valkeinen };
4072f76ee892STomi Valkeinen
4073f76ee892STomi Valkeinen static struct platform_driver omap_dispchw_driver = {
4074f76ee892STomi Valkeinen .probe = dispc_probe,
4075*01ecc142SUwe Kleine-König .remove = dispc_remove,
4076f76ee892STomi Valkeinen .driver = {
4077f76ee892STomi Valkeinen .name = "omapdss_dispc",
4078f76ee892STomi Valkeinen .pm = &dispc_pm_ops,
4079f76ee892STomi Valkeinen .of_match_table = dispc_of_match,
4080f76ee892STomi Valkeinen .suppress_bind_attrs = true,
4081f76ee892STomi Valkeinen },
4082f76ee892STomi Valkeinen };
4083f76ee892STomi Valkeinen
dispc_init_platform_driver(void)4084f76ee892STomi Valkeinen int __init dispc_init_platform_driver(void)
4085f76ee892STomi Valkeinen {
4086f76ee892STomi Valkeinen return platform_driver_register(&omap_dispchw_driver);
4087f76ee892STomi Valkeinen }
4088f76ee892STomi Valkeinen
dispc_uninit_platform_driver(void)4089f76ee892STomi Valkeinen void dispc_uninit_platform_driver(void)
4090f76ee892STomi Valkeinen {
4091f76ee892STomi Valkeinen platform_driver_unregister(&omap_dispchw_driver);
4092f76ee892STomi Valkeinen }
4093