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