1d8408326SSeung-Woo Kim /* 2d8408326SSeung-Woo Kim * Copyright (C) 2011 Samsung Electronics Co.Ltd 3d8408326SSeung-Woo Kim * Authors: 4d8408326SSeung-Woo Kim * Seung-Woo Kim <sw0312.kim@samsung.com> 5d8408326SSeung-Woo Kim * Inki Dae <inki.dae@samsung.com> 6d8408326SSeung-Woo Kim * Joonyoung Shim <jy0922.shim@samsung.com> 7d8408326SSeung-Woo Kim * 8d8408326SSeung-Woo Kim * Based on drivers/media/video/s5p-tv/mixer_reg.c 9d8408326SSeung-Woo Kim * 10d8408326SSeung-Woo Kim * This program is free software; you can redistribute it and/or modify it 11d8408326SSeung-Woo Kim * under the terms of the GNU General Public License as published by the 12d8408326SSeung-Woo Kim * Free Software Foundation; either version 2 of the License, or (at your 13d8408326SSeung-Woo Kim * option) any later version. 14d8408326SSeung-Woo Kim * 15d8408326SSeung-Woo Kim */ 16d8408326SSeung-Woo Kim 17760285e7SDavid Howells #include <drm/drmP.h> 18d8408326SSeung-Woo Kim 19d8408326SSeung-Woo Kim #include "regs-mixer.h" 20d8408326SSeung-Woo Kim #include "regs-vp.h" 21d8408326SSeung-Woo Kim 22d8408326SSeung-Woo Kim #include <linux/kernel.h> 23d8408326SSeung-Woo Kim #include <linux/spinlock.h> 24d8408326SSeung-Woo Kim #include <linux/wait.h> 25d8408326SSeung-Woo Kim #include <linux/i2c.h> 26d8408326SSeung-Woo Kim #include <linux/platform_device.h> 27d8408326SSeung-Woo Kim #include <linux/interrupt.h> 28d8408326SSeung-Woo Kim #include <linux/irq.h> 29d8408326SSeung-Woo Kim #include <linux/delay.h> 30d8408326SSeung-Woo Kim #include <linux/pm_runtime.h> 31d8408326SSeung-Woo Kim #include <linux/clk.h> 32d8408326SSeung-Woo Kim #include <linux/regulator/consumer.h> 333f1c781dSSachin Kamat #include <linux/of.h> 3448f6155aSMarek Szyprowski #include <linux/of_device.h> 35f37cd5e8SInki Dae #include <linux/component.h> 36d8408326SSeung-Woo Kim 37d8408326SSeung-Woo Kim #include <drm/exynos_drm.h> 38d8408326SSeung-Woo Kim 39d8408326SSeung-Woo Kim #include "exynos_drm_drv.h" 40663d8766SRahul Sharma #include "exynos_drm_crtc.h" 410488f50eSMarek Szyprowski #include "exynos_drm_fb.h" 427ee14cdcSGustavo Padovan #include "exynos_drm_plane.h" 431055b39fSInki Dae #include "exynos_drm_iommu.h" 4422b21ae6SJoonyoung Shim 45f041b257SSean Paul #define MIXER_WIN_NR 3 46fbbb1e1aSMarek Szyprowski #define VP_DEFAULT_WIN 2 47d8408326SSeung-Woo Kim 482a6e4cd5STobias Jakobi /* 492a6e4cd5STobias Jakobi * Mixer color space conversion coefficient triplet. 502a6e4cd5STobias Jakobi * Used for CSC from RGB to YCbCr. 512a6e4cd5STobias Jakobi * Each coefficient is a 10-bit fixed point number with 522a6e4cd5STobias Jakobi * sign and no integer part, i.e. 532a6e4cd5STobias Jakobi * [0:8] = fractional part (representing a value y = x / 2^9) 542a6e4cd5STobias Jakobi * [9] = sign 552a6e4cd5STobias Jakobi * Negative values are encoded with two's complement. 562a6e4cd5STobias Jakobi */ 572a6e4cd5STobias Jakobi #define MXR_CSC_C(x) ((int)((x) * 512.0) & 0x3ff) 582a6e4cd5STobias Jakobi #define MXR_CSC_CT(a0, a1, a2) \ 592a6e4cd5STobias Jakobi ((MXR_CSC_C(a0) << 20) | (MXR_CSC_C(a1) << 10) | (MXR_CSC_C(a2) << 0)) 602a6e4cd5STobias Jakobi 612a6e4cd5STobias Jakobi /* YCbCr value, used for mixer background color configuration. */ 622a6e4cd5STobias Jakobi #define MXR_YCBCR_VAL(y, cb, cr) (((y) << 16) | ((cb) << 8) | ((cr) << 0)) 632a6e4cd5STobias Jakobi 647a57ca7cSTobias Jakobi /* The pixelformats that are natively supported by the mixer. */ 657a57ca7cSTobias Jakobi #define MXR_FORMAT_RGB565 4 667a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB1555 5 677a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB4444 6 687a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB8888 7 697a57ca7cSTobias Jakobi 701e123441SRahul Sharma enum mixer_version_id { 711e123441SRahul Sharma MXR_VER_0_0_0_16, 721e123441SRahul Sharma MXR_VER_16_0_33_0, 73def5e095SRahul Sharma MXR_VER_128_0_0_184, 741e123441SRahul Sharma }; 751e123441SRahul Sharma 76a44652e8SAndrzej Hajda enum mixer_flag_bits { 77a44652e8SAndrzej Hajda MXR_BIT_POWERED, 780df5e4acSAndrzej Hajda MXR_BIT_VSYNC, 79adeb6f44STobias Jakobi MXR_BIT_INTERLACE, 80adeb6f44STobias Jakobi MXR_BIT_VP_ENABLED, 81adeb6f44STobias Jakobi MXR_BIT_HAS_SCLK, 82a44652e8SAndrzej Hajda }; 83a44652e8SAndrzej Hajda 84fbbb1e1aSMarek Szyprowski static const uint32_t mixer_formats[] = { 85fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB4444, 8626a7af3eSTobias Jakobi DRM_FORMAT_ARGB4444, 87fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB1555, 8826a7af3eSTobias Jakobi DRM_FORMAT_ARGB1555, 89fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGB565, 90fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB8888, 91fbbb1e1aSMarek Szyprowski DRM_FORMAT_ARGB8888, 92fbbb1e1aSMarek Szyprowski }; 93fbbb1e1aSMarek Szyprowski 94fbbb1e1aSMarek Szyprowski static const uint32_t vp_formats[] = { 95fbbb1e1aSMarek Szyprowski DRM_FORMAT_NV12, 96fbbb1e1aSMarek Szyprowski DRM_FORMAT_NV21, 97fbbb1e1aSMarek Szyprowski }; 98fbbb1e1aSMarek Szyprowski 9922b21ae6SJoonyoung Shim struct mixer_context { 1004551789fSSean Paul struct platform_device *pdev; 101cf8fc4f1SJoonyoung Shim struct device *dev; 1021055b39fSInki Dae struct drm_device *drm_dev; 10393bca243SGustavo Padovan struct exynos_drm_crtc *crtc; 1047ee14cdcSGustavo Padovan struct exynos_drm_plane planes[MIXER_WIN_NR]; 105a44652e8SAndrzej Hajda unsigned long flags; 10622b21ae6SJoonyoung Shim 107*524c59f1SAndrzej Hajda int irq; 108*524c59f1SAndrzej Hajda void __iomem *mixer_regs; 109*524c59f1SAndrzej Hajda void __iomem *vp_regs; 110*524c59f1SAndrzej Hajda spinlock_t reg_slock; 111*524c59f1SAndrzej Hajda struct clk *mixer; 112*524c59f1SAndrzej Hajda struct clk *vp; 113*524c59f1SAndrzej Hajda struct clk *hdmi; 114*524c59f1SAndrzej Hajda struct clk *sclk_mixer; 115*524c59f1SAndrzej Hajda struct clk *sclk_hdmi; 116*524c59f1SAndrzej Hajda struct clk *mout_mixer; 1171e123441SRahul Sharma enum mixer_version_id mxr_ver; 1181e123441SRahul Sharma }; 1191e123441SRahul Sharma 1201e123441SRahul Sharma struct mixer_drv_data { 1211e123441SRahul Sharma enum mixer_version_id version; 1221b8e5747SRahul Sharma bool is_vp_enabled; 123ff830c96SMarek Szyprowski bool has_sclk; 12422b21ae6SJoonyoung Shim }; 12522b21ae6SJoonyoung Shim 126fd2d2fc2SMarek Szyprowski static const struct exynos_drm_plane_config plane_configs[MIXER_WIN_NR] = { 127fd2d2fc2SMarek Szyprowski { 128fd2d2fc2SMarek Szyprowski .zpos = 0, 129fd2d2fc2SMarek Szyprowski .type = DRM_PLANE_TYPE_PRIMARY, 130fd2d2fc2SMarek Szyprowski .pixel_formats = mixer_formats, 131fd2d2fc2SMarek Szyprowski .num_pixel_formats = ARRAY_SIZE(mixer_formats), 132a2cb911eSMarek Szyprowski .capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE | 133a2cb911eSMarek Szyprowski EXYNOS_DRM_PLANE_CAP_ZPOS, 134fd2d2fc2SMarek Szyprowski }, { 135fd2d2fc2SMarek Szyprowski .zpos = 1, 136fd2d2fc2SMarek Szyprowski .type = DRM_PLANE_TYPE_CURSOR, 137fd2d2fc2SMarek Szyprowski .pixel_formats = mixer_formats, 138fd2d2fc2SMarek Szyprowski .num_pixel_formats = ARRAY_SIZE(mixer_formats), 139a2cb911eSMarek Szyprowski .capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE | 140a2cb911eSMarek Szyprowski EXYNOS_DRM_PLANE_CAP_ZPOS, 141fd2d2fc2SMarek Szyprowski }, { 142fd2d2fc2SMarek Szyprowski .zpos = 2, 143fd2d2fc2SMarek Szyprowski .type = DRM_PLANE_TYPE_OVERLAY, 144fd2d2fc2SMarek Szyprowski .pixel_formats = vp_formats, 145fd2d2fc2SMarek Szyprowski .num_pixel_formats = ARRAY_SIZE(vp_formats), 146a2cb911eSMarek Szyprowski .capabilities = EXYNOS_DRM_PLANE_CAP_SCALE | 147f40031c2STobias Jakobi EXYNOS_DRM_PLANE_CAP_ZPOS | 148f40031c2STobias Jakobi EXYNOS_DRM_PLANE_CAP_TILE, 149fd2d2fc2SMarek Szyprowski }, 150fd2d2fc2SMarek Szyprowski }; 151fd2d2fc2SMarek Szyprowski 152d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = { 153d8408326SSeung-Woo Kim 0, -1, -1, -1, -1, -1, -1, -1, 154d8408326SSeung-Woo Kim -1, -1, -1, -1, -1, 0, 0, 0, 155d8408326SSeung-Woo Kim 0, 2, 4, 5, 6, 6, 6, 6, 156d8408326SSeung-Woo Kim 6, 5, 5, 4, 3, 2, 1, 1, 157d8408326SSeung-Woo Kim 0, -6, -12, -16, -18, -20, -21, -20, 158d8408326SSeung-Woo Kim -20, -18, -16, -13, -10, -8, -5, -2, 159d8408326SSeung-Woo Kim 127, 126, 125, 121, 114, 107, 99, 89, 160d8408326SSeung-Woo Kim 79, 68, 57, 46, 35, 25, 16, 8, 161d8408326SSeung-Woo Kim }; 162d8408326SSeung-Woo Kim 163d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = { 164d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7, 165d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0, 166d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81, 167d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5, 168d8408326SSeung-Woo Kim 0, 5, 11, 19, 27, 37, 48, 59, 169d8408326SSeung-Woo Kim 70, 81, 92, 102, 111, 118, 124, 126, 170d8408326SSeung-Woo Kim 0, 0, -1, -1, -2, -3, -4, -5, 171d8408326SSeung-Woo Kim -6, -7, -8, -8, -8, -8, -6, -3, 172d8408326SSeung-Woo Kim }; 173d8408326SSeung-Woo Kim 174d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = { 175d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7, 176d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0, 177d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81, 178d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5, 179d8408326SSeung-Woo Kim }; 180d8408326SSeung-Woo Kim 181f657a996SMarek Szyprowski static inline bool is_alpha_format(unsigned int pixel_format) 182f657a996SMarek Szyprowski { 183f657a996SMarek Szyprowski switch (pixel_format) { 184f657a996SMarek Szyprowski case DRM_FORMAT_ARGB8888: 18526a7af3eSTobias Jakobi case DRM_FORMAT_ARGB1555: 18626a7af3eSTobias Jakobi case DRM_FORMAT_ARGB4444: 187f657a996SMarek Szyprowski return true; 188f657a996SMarek Szyprowski default: 189f657a996SMarek Szyprowski return false; 190f657a996SMarek Szyprowski } 191f657a996SMarek Szyprowski } 192f657a996SMarek Szyprowski 193*524c59f1SAndrzej Hajda static inline u32 vp_reg_read(struct mixer_context *ctx, u32 reg_id) 194d8408326SSeung-Woo Kim { 195*524c59f1SAndrzej Hajda return readl(ctx->vp_regs + reg_id); 196d8408326SSeung-Woo Kim } 197d8408326SSeung-Woo Kim 198*524c59f1SAndrzej Hajda static inline void vp_reg_write(struct mixer_context *ctx, u32 reg_id, 199d8408326SSeung-Woo Kim u32 val) 200d8408326SSeung-Woo Kim { 201*524c59f1SAndrzej Hajda writel(val, ctx->vp_regs + reg_id); 202d8408326SSeung-Woo Kim } 203d8408326SSeung-Woo Kim 204*524c59f1SAndrzej Hajda static inline void vp_reg_writemask(struct mixer_context *ctx, u32 reg_id, 205d8408326SSeung-Woo Kim u32 val, u32 mask) 206d8408326SSeung-Woo Kim { 207*524c59f1SAndrzej Hajda u32 old = vp_reg_read(ctx, reg_id); 208d8408326SSeung-Woo Kim 209d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask); 210*524c59f1SAndrzej Hajda writel(val, ctx->vp_regs + reg_id); 211d8408326SSeung-Woo Kim } 212d8408326SSeung-Woo Kim 213*524c59f1SAndrzej Hajda static inline u32 mixer_reg_read(struct mixer_context *ctx, u32 reg_id) 214d8408326SSeung-Woo Kim { 215*524c59f1SAndrzej Hajda return readl(ctx->mixer_regs + reg_id); 216d8408326SSeung-Woo Kim } 217d8408326SSeung-Woo Kim 218*524c59f1SAndrzej Hajda static inline void mixer_reg_write(struct mixer_context *ctx, u32 reg_id, 219d8408326SSeung-Woo Kim u32 val) 220d8408326SSeung-Woo Kim { 221*524c59f1SAndrzej Hajda writel(val, ctx->mixer_regs + reg_id); 222d8408326SSeung-Woo Kim } 223d8408326SSeung-Woo Kim 224*524c59f1SAndrzej Hajda static inline void mixer_reg_writemask(struct mixer_context *ctx, 225d8408326SSeung-Woo Kim u32 reg_id, u32 val, u32 mask) 226d8408326SSeung-Woo Kim { 227*524c59f1SAndrzej Hajda u32 old = mixer_reg_read(ctx, reg_id); 228d8408326SSeung-Woo Kim 229d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask); 230*524c59f1SAndrzej Hajda writel(val, ctx->mixer_regs + reg_id); 231d8408326SSeung-Woo Kim } 232d8408326SSeung-Woo Kim 233d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx) 234d8408326SSeung-Woo Kim { 235d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \ 236d8408326SSeung-Woo Kim do { \ 237d8408326SSeung-Woo Kim DRM_DEBUG_KMS(#reg_id " = %08x\n", \ 238*524c59f1SAndrzej Hajda (u32)readl(ctx->mixer_regs + reg_id)); \ 239d8408326SSeung-Woo Kim } while (0) 240d8408326SSeung-Woo Kim 241d8408326SSeung-Woo Kim DUMPREG(MXR_STATUS); 242d8408326SSeung-Woo Kim DUMPREG(MXR_CFG); 243d8408326SSeung-Woo Kim DUMPREG(MXR_INT_EN); 244d8408326SSeung-Woo Kim DUMPREG(MXR_INT_STATUS); 245d8408326SSeung-Woo Kim 246d8408326SSeung-Woo Kim DUMPREG(MXR_LAYER_CFG); 247d8408326SSeung-Woo Kim DUMPREG(MXR_VIDEO_CFG); 248d8408326SSeung-Woo Kim 249d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_CFG); 250d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_BASE); 251d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SPAN); 252d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_WH); 253d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SXY); 254d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_DXY); 255d8408326SSeung-Woo Kim 256d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_CFG); 257d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_BASE); 258d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SPAN); 259d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_WH); 260d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SXY); 261d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_DXY); 262d8408326SSeung-Woo Kim #undef DUMPREG 263d8408326SSeung-Woo Kim } 264d8408326SSeung-Woo Kim 265d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx) 266d8408326SSeung-Woo Kim { 267d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \ 268d8408326SSeung-Woo Kim do { \ 269d8408326SSeung-Woo Kim DRM_DEBUG_KMS(#reg_id " = %08x\n", \ 270*524c59f1SAndrzej Hajda (u32) readl(ctx->vp_regs + reg_id)); \ 271d8408326SSeung-Woo Kim } while (0) 272d8408326SSeung-Woo Kim 273d8408326SSeung-Woo Kim DUMPREG(VP_ENABLE); 274d8408326SSeung-Woo Kim DUMPREG(VP_SRESET); 275d8408326SSeung-Woo Kim DUMPREG(VP_SHADOW_UPDATE); 276d8408326SSeung-Woo Kim DUMPREG(VP_FIELD_ID); 277d8408326SSeung-Woo Kim DUMPREG(VP_MODE); 278d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_Y); 279d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_C); 280d8408326SSeung-Woo Kim DUMPREG(VP_PER_RATE_CTRL); 281d8408326SSeung-Woo Kim DUMPREG(VP_TOP_Y_PTR); 282d8408326SSeung-Woo Kim DUMPREG(VP_BOT_Y_PTR); 283d8408326SSeung-Woo Kim DUMPREG(VP_TOP_C_PTR); 284d8408326SSeung-Woo Kim DUMPREG(VP_BOT_C_PTR); 285d8408326SSeung-Woo Kim DUMPREG(VP_ENDIAN_MODE); 286d8408326SSeung-Woo Kim DUMPREG(VP_SRC_H_POSITION); 287d8408326SSeung-Woo Kim DUMPREG(VP_SRC_V_POSITION); 288d8408326SSeung-Woo Kim DUMPREG(VP_SRC_WIDTH); 289d8408326SSeung-Woo Kim DUMPREG(VP_SRC_HEIGHT); 290d8408326SSeung-Woo Kim DUMPREG(VP_DST_H_POSITION); 291d8408326SSeung-Woo Kim DUMPREG(VP_DST_V_POSITION); 292d8408326SSeung-Woo Kim DUMPREG(VP_DST_WIDTH); 293d8408326SSeung-Woo Kim DUMPREG(VP_DST_HEIGHT); 294d8408326SSeung-Woo Kim DUMPREG(VP_H_RATIO); 295d8408326SSeung-Woo Kim DUMPREG(VP_V_RATIO); 296d8408326SSeung-Woo Kim 297d8408326SSeung-Woo Kim #undef DUMPREG 298d8408326SSeung-Woo Kim } 299d8408326SSeung-Woo Kim 300*524c59f1SAndrzej Hajda static inline void vp_filter_set(struct mixer_context *ctx, 301d8408326SSeung-Woo Kim int reg_id, const u8 *data, unsigned int size) 302d8408326SSeung-Woo Kim { 303d8408326SSeung-Woo Kim /* assure 4-byte align */ 304d8408326SSeung-Woo Kim BUG_ON(size & 3); 305d8408326SSeung-Woo Kim for (; size; size -= 4, reg_id += 4, data += 4) { 306d8408326SSeung-Woo Kim u32 val = (data[0] << 24) | (data[1] << 16) | 307d8408326SSeung-Woo Kim (data[2] << 8) | data[3]; 308*524c59f1SAndrzej Hajda vp_reg_write(ctx, reg_id, val); 309d8408326SSeung-Woo Kim } 310d8408326SSeung-Woo Kim } 311d8408326SSeung-Woo Kim 312*524c59f1SAndrzej Hajda static void vp_default_filter(struct mixer_context *ctx) 313d8408326SSeung-Woo Kim { 314*524c59f1SAndrzej Hajda vp_filter_set(ctx, VP_POLY8_Y0_LL, 315e25e1b66SSachin Kamat filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8)); 316*524c59f1SAndrzej Hajda vp_filter_set(ctx, VP_POLY4_Y0_LL, 317e25e1b66SSachin Kamat filter_y_vert_tap4, sizeof(filter_y_vert_tap4)); 318*524c59f1SAndrzej Hajda vp_filter_set(ctx, VP_POLY4_C0_LL, 319e25e1b66SSachin Kamat filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4)); 320d8408326SSeung-Woo Kim } 321d8408326SSeung-Woo Kim 322f657a996SMarek Szyprowski static void mixer_cfg_gfx_blend(struct mixer_context *ctx, unsigned int win, 323f657a996SMarek Szyprowski bool alpha) 324f657a996SMarek Szyprowski { 325f657a996SMarek Szyprowski u32 val; 326f657a996SMarek Szyprowski 327f657a996SMarek Szyprowski val = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */ 328f657a996SMarek Szyprowski if (alpha) { 329f657a996SMarek Szyprowski /* blending based on pixel alpha */ 330f657a996SMarek Szyprowski val |= MXR_GRP_CFG_BLEND_PRE_MUL; 331f657a996SMarek Szyprowski val |= MXR_GRP_CFG_PIXEL_BLEND_EN; 332f657a996SMarek Szyprowski } 333*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_GRAPHIC_CFG(win), 334f657a996SMarek Szyprowski val, MXR_GRP_CFG_MISC_MASK); 335f657a996SMarek Szyprowski } 336f657a996SMarek Szyprowski 337f657a996SMarek Szyprowski static void mixer_cfg_vp_blend(struct mixer_context *ctx) 338f657a996SMarek Szyprowski { 339f657a996SMarek Szyprowski u32 val; 340f657a996SMarek Szyprowski 341f657a996SMarek Szyprowski /* 342f657a996SMarek Szyprowski * No blending at the moment since the NV12/NV21 pixelformats don't 343f657a996SMarek Szyprowski * have an alpha channel. However the mixer supports a global alpha 344f657a996SMarek Szyprowski * value for a layer. Once this functionality is exposed, we can 345f657a996SMarek Szyprowski * support blending of the video layer through this. 346f657a996SMarek Szyprowski */ 347f657a996SMarek Szyprowski val = 0; 348*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_VIDEO_CFG, val); 349f657a996SMarek Szyprowski } 350f657a996SMarek Szyprowski 351d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable) 352d8408326SSeung-Woo Kim { 353d8408326SSeung-Woo Kim /* block update on vsync */ 354*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_STATUS, enable ? 355d8408326SSeung-Woo Kim MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE); 356d8408326SSeung-Woo Kim 357adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) 358*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_SHADOW_UPDATE, enable ? 359d8408326SSeung-Woo Kim VP_SHADOW_UPDATE_ENABLE : 0); 360d8408326SSeung-Woo Kim } 361d8408326SSeung-Woo Kim 3623fc40ca9SAndrzej Hajda static void mixer_cfg_scan(struct mixer_context *ctx, int width, int height) 363d8408326SSeung-Woo Kim { 364d8408326SSeung-Woo Kim u32 val; 365d8408326SSeung-Woo Kim 366d8408326SSeung-Woo Kim /* choosing between interlace and progressive mode */ 367adeb6f44STobias Jakobi val = test_bit(MXR_BIT_INTERLACE, &ctx->flags) ? 368adeb6f44STobias Jakobi MXR_CFG_SCAN_INTERLACE : MXR_CFG_SCAN_PROGRESSIVE; 369d8408326SSeung-Woo Kim 3703fc40ca9SAndrzej Hajda /* setup display size */ 3713fc40ca9SAndrzej Hajda if (ctx->mxr_ver == MXR_VER_128_0_0_184) { 372*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_RESOLUTION, 3733fc40ca9SAndrzej Hajda MXR_MXR_RES_HEIGHT(height) | MXR_MXR_RES_WIDTH(width)); 3743fc40ca9SAndrzej Hajda } else { 375def5e095SRahul Sharma /* choosing between proper HD and SD mode */ 37629630743SRahul Sharma if (height <= 480) 377d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD; 37829630743SRahul Sharma else if (height <= 576) 379d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD; 38029630743SRahul Sharma else if (height <= 720) 381d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; 38229630743SRahul Sharma else if (height <= 1080) 383d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD; 384d8408326SSeung-Woo Kim else 385d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; 386def5e095SRahul Sharma } 387d8408326SSeung-Woo Kim 388*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_SCAN_MASK); 389d8408326SSeung-Woo Kim } 390d8408326SSeung-Woo Kim 391d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height) 392d8408326SSeung-Woo Kim { 393d8408326SSeung-Woo Kim u32 val; 394d8408326SSeung-Woo Kim 3952a39db01STobias Jakobi switch (height) { 3962a39db01STobias Jakobi case 480: 3972a39db01STobias Jakobi case 576: 398d8408326SSeung-Woo Kim val = MXR_CFG_RGB601_0_255; 3992a39db01STobias Jakobi break; 4002a39db01STobias Jakobi case 720: 4012a39db01STobias Jakobi case 1080: 4022a39db01STobias Jakobi default: 403d8408326SSeung-Woo Kim val = MXR_CFG_RGB709_16_235; 4042a6e4cd5STobias Jakobi /* Configure the BT.709 CSC matrix for full range RGB. */ 405*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_CM_COEFF_Y, 4062a6e4cd5STobias Jakobi MXR_CSC_CT( 0.184, 0.614, 0.063) | 4072a6e4cd5STobias Jakobi MXR_CM_COEFF_RGB_FULL); 408*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_CM_COEFF_CB, 4092a6e4cd5STobias Jakobi MXR_CSC_CT(-0.102, -0.338, 0.440)); 410*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_CM_COEFF_CR, 4112a6e4cd5STobias Jakobi MXR_CSC_CT( 0.440, -0.399, -0.040)); 4122a39db01STobias Jakobi break; 413d8408326SSeung-Woo Kim } 414d8408326SSeung-Woo Kim 415*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK); 416d8408326SSeung-Woo Kim } 417d8408326SSeung-Woo Kim 4185b1d5bc6STobias Jakobi static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win, 419a2cb911eSMarek Szyprowski unsigned int priority, bool enable) 420d8408326SSeung-Woo Kim { 421d8408326SSeung-Woo Kim u32 val = enable ? ~0 : 0; 422d8408326SSeung-Woo Kim 423d8408326SSeung-Woo Kim switch (win) { 424d8408326SSeung-Woo Kim case 0: 425*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_GRP0_ENABLE); 426*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_LAYER_CFG, 427a2cb911eSMarek Szyprowski MXR_LAYER_CFG_GRP0_VAL(priority), 428a2cb911eSMarek Szyprowski MXR_LAYER_CFG_GRP0_MASK); 429d8408326SSeung-Woo Kim break; 430d8408326SSeung-Woo Kim case 1: 431*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_GRP1_ENABLE); 432*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_LAYER_CFG, 433a2cb911eSMarek Szyprowski MXR_LAYER_CFG_GRP1_VAL(priority), 434a2cb911eSMarek Szyprowski MXR_LAYER_CFG_GRP1_MASK); 435adeb6f44STobias Jakobi 436d8408326SSeung-Woo Kim break; 4375e68fef2SMarek Szyprowski case VP_DEFAULT_WIN: 438adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) { 439*524c59f1SAndrzej Hajda vp_reg_writemask(ctx, VP_ENABLE, val, VP_ENABLE_ON); 440*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, val, 4411b8e5747SRahul Sharma MXR_CFG_VP_ENABLE); 442*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_LAYER_CFG, 443a2cb911eSMarek Szyprowski MXR_LAYER_CFG_VP_VAL(priority), 444a2cb911eSMarek Szyprowski MXR_LAYER_CFG_VP_MASK); 4451b8e5747SRahul Sharma } 446d8408326SSeung-Woo Kim break; 447d8408326SSeung-Woo Kim } 448d8408326SSeung-Woo Kim } 449d8408326SSeung-Woo Kim 450d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx) 451d8408326SSeung-Woo Kim { 452*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_REG_RUN); 453d8408326SSeung-Woo Kim } 454d8408326SSeung-Woo Kim 455381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx) 456381be025SRahul Sharma { 457381be025SRahul Sharma int timeout = 20; 458381be025SRahul Sharma 459*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_STATUS, 0, MXR_STATUS_REG_RUN); 460381be025SRahul Sharma 461*524c59f1SAndrzej Hajda while (!(mixer_reg_read(ctx, MXR_STATUS) & MXR_STATUS_REG_IDLE) && 462381be025SRahul Sharma --timeout) 463381be025SRahul Sharma usleep_range(10000, 12000); 464381be025SRahul Sharma } 465381be025SRahul Sharma 466521d98a3SAndrzej Hajda static void mixer_commit(struct mixer_context *ctx) 467521d98a3SAndrzej Hajda { 468521d98a3SAndrzej Hajda struct drm_display_mode *mode = &ctx->crtc->base.state->adjusted_mode; 469521d98a3SAndrzej Hajda 47071469944SAndrzej Hajda if (mode->flags & DRM_MODE_FLAG_INTERLACE) 47171469944SAndrzej Hajda __set_bit(MXR_BIT_INTERLACE, &ctx->flags); 47271469944SAndrzej Hajda else 47371469944SAndrzej Hajda __clear_bit(MXR_BIT_INTERLACE, &ctx->flags); 47471469944SAndrzej Hajda 4753fc40ca9SAndrzej Hajda mixer_cfg_scan(ctx, mode->hdisplay, mode->vdisplay); 476521d98a3SAndrzej Hajda mixer_cfg_rgb_fmt(ctx, mode->vdisplay); 477521d98a3SAndrzej Hajda mixer_run(ctx); 478521d98a3SAndrzej Hajda } 479521d98a3SAndrzej Hajda 4802eeb2e5eSGustavo Padovan static void vp_video_buffer(struct mixer_context *ctx, 4812eeb2e5eSGustavo Padovan struct exynos_drm_plane *plane) 482d8408326SSeung-Woo Kim { 4830114f404SMarek Szyprowski struct exynos_drm_plane_state *state = 4840114f404SMarek Szyprowski to_exynos_plane_state(plane->base.state); 4850114f404SMarek Szyprowski struct drm_framebuffer *fb = state->base.fb; 486e47726a1SMarek Szyprowski unsigned int priority = state->base.normalized_zpos + 1; 487d8408326SSeung-Woo Kim unsigned long flags; 488d8408326SSeung-Woo Kim dma_addr_t luma_addr[2], chroma_addr[2]; 4890f752694STobias Jakobi bool is_tiled, is_nv21; 490d8408326SSeung-Woo Kim u32 val; 491d8408326SSeung-Woo Kim 4920f752694STobias Jakobi is_nv21 = (fb->format->format == DRM_FORMAT_NV21); 4930f752694STobias Jakobi is_tiled = (fb->modifier == DRM_FORMAT_MOD_SAMSUNG_64_32_TILE); 494f40031c2STobias Jakobi 4950488f50eSMarek Szyprowski luma_addr[0] = exynos_drm_fb_dma_addr(fb, 0); 4960488f50eSMarek Szyprowski chroma_addr[0] = exynos_drm_fb_dma_addr(fb, 1); 497d8408326SSeung-Woo Kim 49871469944SAndrzej Hajda if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) { 4990f752694STobias Jakobi if (is_tiled) { 500d8408326SSeung-Woo Kim luma_addr[1] = luma_addr[0] + 0x40; 501d8408326SSeung-Woo Kim chroma_addr[1] = chroma_addr[0] + 0x40; 502d8408326SSeung-Woo Kim } else { 5032eeb2e5eSGustavo Padovan luma_addr[1] = luma_addr[0] + fb->pitches[0]; 5042eeb2e5eSGustavo Padovan chroma_addr[1] = chroma_addr[0] + fb->pitches[0]; 505d8408326SSeung-Woo Kim } 506d8408326SSeung-Woo Kim } else { 507d8408326SSeung-Woo Kim luma_addr[1] = 0; 508d8408326SSeung-Woo Kim chroma_addr[1] = 0; 509d8408326SSeung-Woo Kim } 510d8408326SSeung-Woo Kim 511*524c59f1SAndrzej Hajda spin_lock_irqsave(&ctx->reg_slock, flags); 512d8408326SSeung-Woo Kim 513d8408326SSeung-Woo Kim /* interlace or progressive scan mode */ 514adeb6f44STobias Jakobi val = (test_bit(MXR_BIT_INTERLACE, &ctx->flags) ? ~0 : 0); 515*524c59f1SAndrzej Hajda vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_LINE_SKIP); 516d8408326SSeung-Woo Kim 517d8408326SSeung-Woo Kim /* setup format */ 5180f752694STobias Jakobi val = (is_nv21 ? VP_MODE_NV21 : VP_MODE_NV12); 5190f752694STobias Jakobi val |= (is_tiled ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR); 520*524c59f1SAndrzej Hajda vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_FMT_MASK); 521d8408326SSeung-Woo Kim 522d8408326SSeung-Woo Kim /* setting size of input image */ 523*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) | 5242eeb2e5eSGustavo Padovan VP_IMG_VSIZE(fb->height)); 525dc500cfbSTobias Jakobi /* chroma plane for NV12/NV21 is half the height of the luma plane */ 526*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[0]) | 5272eeb2e5eSGustavo Padovan VP_IMG_VSIZE(fb->height / 2)); 528d8408326SSeung-Woo Kim 529*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_SRC_WIDTH, state->src.w); 530*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_SRC_HEIGHT, state->src.h); 531*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_SRC_H_POSITION, 5320114f404SMarek Szyprowski VP_SRC_H_POSITION_VAL(state->src.x)); 533*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_SRC_V_POSITION, state->src.y); 534d8408326SSeung-Woo Kim 535*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_WIDTH, state->crtc.w); 536*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_H_POSITION, state->crtc.x); 537adeb6f44STobias Jakobi if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) { 538*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_HEIGHT, state->crtc.h / 2); 539*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_V_POSITION, state->crtc.y / 2); 540d8408326SSeung-Woo Kim } else { 541*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_HEIGHT, state->crtc.h); 542*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_V_POSITION, state->crtc.y); 543d8408326SSeung-Woo Kim } 544d8408326SSeung-Woo Kim 545*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_H_RATIO, state->h_ratio); 546*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_V_RATIO, state->v_ratio); 547d8408326SSeung-Woo Kim 548*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE); 549d8408326SSeung-Woo Kim 550d8408326SSeung-Woo Kim /* set buffer address to vp */ 551*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_TOP_Y_PTR, luma_addr[0]); 552*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_BOT_Y_PTR, luma_addr[1]); 553*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_TOP_C_PTR, chroma_addr[0]); 554*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_BOT_C_PTR, chroma_addr[1]); 555d8408326SSeung-Woo Kim 556e47726a1SMarek Szyprowski mixer_cfg_layer(ctx, plane->index, priority, true); 557f657a996SMarek Szyprowski mixer_cfg_vp_blend(ctx); 558d8408326SSeung-Woo Kim 559*524c59f1SAndrzej Hajda spin_unlock_irqrestore(&ctx->reg_slock, flags); 560d8408326SSeung-Woo Kim 561c0734fbaSTobias Jakobi mixer_regs_dump(ctx); 562d8408326SSeung-Woo Kim vp_regs_dump(ctx); 563d8408326SSeung-Woo Kim } 564d8408326SSeung-Woo Kim 565aaf8b49eSRahul Sharma static void mixer_layer_update(struct mixer_context *ctx) 566aaf8b49eSRahul Sharma { 567*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE); 568aaf8b49eSRahul Sharma } 569aaf8b49eSRahul Sharma 5702eeb2e5eSGustavo Padovan static void mixer_graph_buffer(struct mixer_context *ctx, 5712eeb2e5eSGustavo Padovan struct exynos_drm_plane *plane) 572d8408326SSeung-Woo Kim { 5730114f404SMarek Szyprowski struct exynos_drm_plane_state *state = 5740114f404SMarek Szyprowski to_exynos_plane_state(plane->base.state); 5750114f404SMarek Szyprowski struct drm_framebuffer *fb = state->base.fb; 576e47726a1SMarek Szyprowski unsigned int priority = state->base.normalized_zpos + 1; 577d8408326SSeung-Woo Kim unsigned long flags; 57840bdfb0aSMarek Szyprowski unsigned int win = plane->index; 5792611015cSTobias Jakobi unsigned int x_ratio = 0, y_ratio = 0; 5805dff6905STobias Jakobi unsigned int dst_x_offset, dst_y_offset; 581d8408326SSeung-Woo Kim dma_addr_t dma_addr; 582d8408326SSeung-Woo Kim unsigned int fmt; 583d8408326SSeung-Woo Kim u32 val; 584d8408326SSeung-Woo Kim 585438b74a5SVille Syrjälä switch (fb->format->format) { 5867a57ca7cSTobias Jakobi case DRM_FORMAT_XRGB4444: 58726a7af3eSTobias Jakobi case DRM_FORMAT_ARGB4444: 5887a57ca7cSTobias Jakobi fmt = MXR_FORMAT_ARGB4444; 5897a57ca7cSTobias Jakobi break; 590d8408326SSeung-Woo Kim 5917a57ca7cSTobias Jakobi case DRM_FORMAT_XRGB1555: 59226a7af3eSTobias Jakobi case DRM_FORMAT_ARGB1555: 5937a57ca7cSTobias Jakobi fmt = MXR_FORMAT_ARGB1555; 594d8408326SSeung-Woo Kim break; 5957a57ca7cSTobias Jakobi 5967a57ca7cSTobias Jakobi case DRM_FORMAT_RGB565: 5977a57ca7cSTobias Jakobi fmt = MXR_FORMAT_RGB565; 598d8408326SSeung-Woo Kim break; 5997a57ca7cSTobias Jakobi 6007a57ca7cSTobias Jakobi case DRM_FORMAT_XRGB8888: 6017a57ca7cSTobias Jakobi case DRM_FORMAT_ARGB8888: 6021e60d62fSTobias Jakobi default: 6037a57ca7cSTobias Jakobi fmt = MXR_FORMAT_ARGB8888; 6047a57ca7cSTobias Jakobi break; 605d8408326SSeung-Woo Kim } 606d8408326SSeung-Woo Kim 607e463b069SMarek Szyprowski /* ratio is already checked by common plane code */ 608e463b069SMarek Szyprowski x_ratio = state->h_ratio == (1 << 15); 609e463b069SMarek Szyprowski y_ratio = state->v_ratio == (1 << 15); 610d8408326SSeung-Woo Kim 6110114f404SMarek Szyprowski dst_x_offset = state->crtc.x; 6120114f404SMarek Szyprowski dst_y_offset = state->crtc.y; 613d8408326SSeung-Woo Kim 6145dff6905STobias Jakobi /* translate dma address base s.t. the source image offset is zero */ 6150488f50eSMarek Szyprowski dma_addr = exynos_drm_fb_dma_addr(fb, 0) 616272725c7SVille Syrjälä + (state->src.x * fb->format->cpp[0]) 6170114f404SMarek Szyprowski + (state->src.y * fb->pitches[0]); 618d8408326SSeung-Woo Kim 619*524c59f1SAndrzej Hajda spin_lock_irqsave(&ctx->reg_slock, flags); 620d8408326SSeung-Woo Kim 621d8408326SSeung-Woo Kim /* setup format */ 622*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_GRAPHIC_CFG(win), 623d8408326SSeung-Woo Kim MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK); 624d8408326SSeung-Woo Kim 625d8408326SSeung-Woo Kim /* setup geometry */ 626*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_SPAN(win), 627272725c7SVille Syrjälä fb->pitches[0] / fb->format->cpp[0]); 628d8408326SSeung-Woo Kim 6290114f404SMarek Szyprowski val = MXR_GRP_WH_WIDTH(state->src.w); 6300114f404SMarek Szyprowski val |= MXR_GRP_WH_HEIGHT(state->src.h); 631d8408326SSeung-Woo Kim val |= MXR_GRP_WH_H_SCALE(x_ratio); 632d8408326SSeung-Woo Kim val |= MXR_GRP_WH_V_SCALE(y_ratio); 633*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_WH(win), val); 634d8408326SSeung-Woo Kim 635d8408326SSeung-Woo Kim /* setup offsets in display image */ 636d8408326SSeung-Woo Kim val = MXR_GRP_DXY_DX(dst_x_offset); 637d8408326SSeung-Woo Kim val |= MXR_GRP_DXY_DY(dst_y_offset); 638*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_DXY(win), val); 639d8408326SSeung-Woo Kim 640d8408326SSeung-Woo Kim /* set buffer address to mixer */ 641*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_BASE(win), dma_addr); 642d8408326SSeung-Woo Kim 643e47726a1SMarek Szyprowski mixer_cfg_layer(ctx, win, priority, true); 644438b74a5SVille Syrjälä mixer_cfg_gfx_blend(ctx, win, is_alpha_format(fb->format->format)); 645aaf8b49eSRahul Sharma 646aaf8b49eSRahul Sharma /* layer update mandatory for mixer 16.0.33.0 */ 647def5e095SRahul Sharma if (ctx->mxr_ver == MXR_VER_16_0_33_0 || 648def5e095SRahul Sharma ctx->mxr_ver == MXR_VER_128_0_0_184) 649aaf8b49eSRahul Sharma mixer_layer_update(ctx); 650aaf8b49eSRahul Sharma 651*524c59f1SAndrzej Hajda spin_unlock_irqrestore(&ctx->reg_slock, flags); 652c0734fbaSTobias Jakobi 653c0734fbaSTobias Jakobi mixer_regs_dump(ctx); 654d8408326SSeung-Woo Kim } 655d8408326SSeung-Woo Kim 656d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx) 657d8408326SSeung-Woo Kim { 658a696394cSTobias Jakobi unsigned int tries = 100; 659d8408326SSeung-Woo Kim 660*524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_SRESET, VP_SRESET_PROCESSING); 6618646dcb8SDan Carpenter while (--tries) { 662d8408326SSeung-Woo Kim /* waiting until VP_SRESET_PROCESSING is 0 */ 663*524c59f1SAndrzej Hajda if (~vp_reg_read(ctx, VP_SRESET) & VP_SRESET_PROCESSING) 664d8408326SSeung-Woo Kim break; 66502b3de43STomasz Stanislawski mdelay(10); 666d8408326SSeung-Woo Kim } 667d8408326SSeung-Woo Kim WARN(tries == 0, "failed to reset Video Processor\n"); 668d8408326SSeung-Woo Kim } 669d8408326SSeung-Woo Kim 670cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx) 671cf8fc4f1SJoonyoung Shim { 672cf8fc4f1SJoonyoung Shim unsigned long flags; 673cf8fc4f1SJoonyoung Shim 674*524c59f1SAndrzej Hajda spin_lock_irqsave(&ctx->reg_slock, flags); 675cf8fc4f1SJoonyoung Shim 676*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK); 677cf8fc4f1SJoonyoung Shim 678cf8fc4f1SJoonyoung Shim /* set output in RGB888 mode */ 679*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK); 680cf8fc4f1SJoonyoung Shim 681cf8fc4f1SJoonyoung Shim /* 16 beat burst in DMA */ 682*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_STATUS, MXR_STATUS_16_BURST, 683cf8fc4f1SJoonyoung Shim MXR_STATUS_BURST_MASK); 684cf8fc4f1SJoonyoung Shim 685a2cb911eSMarek Szyprowski /* reset default layer priority */ 686*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_LAYER_CFG, 0); 687cf8fc4f1SJoonyoung Shim 6882a6e4cd5STobias Jakobi /* set all background colors to RGB (0,0,0) */ 689*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_BG_COLOR0, MXR_YCBCR_VAL(0, 128, 128)); 690*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_BG_COLOR1, MXR_YCBCR_VAL(0, 128, 128)); 691*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_BG_COLOR2, MXR_YCBCR_VAL(0, 128, 128)); 692cf8fc4f1SJoonyoung Shim 693adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) { 694cf8fc4f1SJoonyoung Shim /* configuration of Video Processor Registers */ 695cf8fc4f1SJoonyoung Shim vp_win_reset(ctx); 696*524c59f1SAndrzej Hajda vp_default_filter(ctx); 6971b8e5747SRahul Sharma } 698cf8fc4f1SJoonyoung Shim 699cf8fc4f1SJoonyoung Shim /* disable all layers */ 700*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE); 701*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE); 702adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) 703*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_VP_ENABLE); 704cf8fc4f1SJoonyoung Shim 7055dff6905STobias Jakobi /* set all source image offsets to zero */ 706*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_SXY(0), 0); 707*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_SXY(1), 0); 7085dff6905STobias Jakobi 709*524c59f1SAndrzej Hajda spin_unlock_irqrestore(&ctx->reg_slock, flags); 710cf8fc4f1SJoonyoung Shim } 711cf8fc4f1SJoonyoung Shim 7124551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg) 7134551789fSSean Paul { 7144551789fSSean Paul struct mixer_context *ctx = arg; 7154551789fSSean Paul u32 val, base, shadow; 7164551789fSSean Paul 717*524c59f1SAndrzej Hajda spin_lock(&ctx->reg_slock); 7184551789fSSean Paul 7194551789fSSean Paul /* read interrupt status for handling and clearing flags for VSYNC */ 720*524c59f1SAndrzej Hajda val = mixer_reg_read(ctx, MXR_INT_STATUS); 7214551789fSSean Paul 7224551789fSSean Paul /* handling VSYNC */ 7234551789fSSean Paul if (val & MXR_INT_STATUS_VSYNC) { 72481a464dfSAndrzej Hajda /* vsync interrupt use different bit for read and clear */ 72581a464dfSAndrzej Hajda val |= MXR_INT_CLEAR_VSYNC; 72681a464dfSAndrzej Hajda val &= ~MXR_INT_STATUS_VSYNC; 72781a464dfSAndrzej Hajda 7284551789fSSean Paul /* interlace scan need to check shadow register */ 729adeb6f44STobias Jakobi if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) { 730*524c59f1SAndrzej Hajda base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(0)); 731*524c59f1SAndrzej Hajda shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(0)); 7324551789fSSean Paul if (base != shadow) 7334551789fSSean Paul goto out; 7344551789fSSean Paul 735*524c59f1SAndrzej Hajda base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(1)); 736*524c59f1SAndrzej Hajda shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(1)); 7374551789fSSean Paul if (base != shadow) 7384551789fSSean Paul goto out; 7394551789fSSean Paul } 7404551789fSSean Paul 741eafd540aSGustavo Padovan drm_crtc_handle_vblank(&ctx->crtc->base); 7424551789fSSean Paul } 7434551789fSSean Paul 7444551789fSSean Paul out: 7454551789fSSean Paul /* clear interrupts */ 746*524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_INT_STATUS, val); 7474551789fSSean Paul 748*524c59f1SAndrzej Hajda spin_unlock(&ctx->reg_slock); 7494551789fSSean Paul 7504551789fSSean Paul return IRQ_HANDLED; 7514551789fSSean Paul } 7524551789fSSean Paul 7534551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx) 7544551789fSSean Paul { 7554551789fSSean Paul struct device *dev = &mixer_ctx->pdev->dev; 7564551789fSSean Paul struct resource *res; 7574551789fSSean Paul int ret; 7584551789fSSean Paul 759*524c59f1SAndrzej Hajda spin_lock_init(&mixer_ctx->reg_slock); 7604551789fSSean Paul 761*524c59f1SAndrzej Hajda mixer_ctx->mixer = devm_clk_get(dev, "mixer"); 762*524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->mixer)) { 7634551789fSSean Paul dev_err(dev, "failed to get clock 'mixer'\n"); 7644551789fSSean Paul return -ENODEV; 7654551789fSSean Paul } 7664551789fSSean Paul 767*524c59f1SAndrzej Hajda mixer_ctx->hdmi = devm_clk_get(dev, "hdmi"); 768*524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->hdmi)) { 76904427ec5SMarek Szyprowski dev_err(dev, "failed to get clock 'hdmi'\n"); 770*524c59f1SAndrzej Hajda return PTR_ERR(mixer_ctx->hdmi); 77104427ec5SMarek Szyprowski } 77204427ec5SMarek Szyprowski 773*524c59f1SAndrzej Hajda mixer_ctx->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi"); 774*524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->sclk_hdmi)) { 7754551789fSSean Paul dev_err(dev, "failed to get clock 'sclk_hdmi'\n"); 7764551789fSSean Paul return -ENODEV; 7774551789fSSean Paul } 7784551789fSSean Paul res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0); 7794551789fSSean Paul if (res == NULL) { 7804551789fSSean Paul dev_err(dev, "get memory resource failed.\n"); 7814551789fSSean Paul return -ENXIO; 7824551789fSSean Paul } 7834551789fSSean Paul 784*524c59f1SAndrzej Hajda mixer_ctx->mixer_regs = devm_ioremap(dev, res->start, 7854551789fSSean Paul resource_size(res)); 786*524c59f1SAndrzej Hajda if (mixer_ctx->mixer_regs == NULL) { 7874551789fSSean Paul dev_err(dev, "register mapping failed.\n"); 7884551789fSSean Paul return -ENXIO; 7894551789fSSean Paul } 7904551789fSSean Paul 7914551789fSSean Paul res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0); 7924551789fSSean Paul if (res == NULL) { 7934551789fSSean Paul dev_err(dev, "get interrupt resource failed.\n"); 7944551789fSSean Paul return -ENXIO; 7954551789fSSean Paul } 7964551789fSSean Paul 7974551789fSSean Paul ret = devm_request_irq(dev, res->start, mixer_irq_handler, 7984551789fSSean Paul 0, "drm_mixer", mixer_ctx); 7994551789fSSean Paul if (ret) { 8004551789fSSean Paul dev_err(dev, "request interrupt failed.\n"); 8014551789fSSean Paul return ret; 8024551789fSSean Paul } 803*524c59f1SAndrzej Hajda mixer_ctx->irq = res->start; 8044551789fSSean Paul 8054551789fSSean Paul return 0; 8064551789fSSean Paul } 8074551789fSSean Paul 8084551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx) 8094551789fSSean Paul { 8104551789fSSean Paul struct device *dev = &mixer_ctx->pdev->dev; 8114551789fSSean Paul struct resource *res; 8124551789fSSean Paul 813*524c59f1SAndrzej Hajda mixer_ctx->vp = devm_clk_get(dev, "vp"); 814*524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->vp)) { 8154551789fSSean Paul dev_err(dev, "failed to get clock 'vp'\n"); 8164551789fSSean Paul return -ENODEV; 8174551789fSSean Paul } 818ff830c96SMarek Szyprowski 819adeb6f44STobias Jakobi if (test_bit(MXR_BIT_HAS_SCLK, &mixer_ctx->flags)) { 820*524c59f1SAndrzej Hajda mixer_ctx->sclk_mixer = devm_clk_get(dev, "sclk_mixer"); 821*524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->sclk_mixer)) { 8224551789fSSean Paul dev_err(dev, "failed to get clock 'sclk_mixer'\n"); 8234551789fSSean Paul return -ENODEV; 8244551789fSSean Paul } 825*524c59f1SAndrzej Hajda mixer_ctx->mout_mixer = devm_clk_get(dev, "mout_mixer"); 826*524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->mout_mixer)) { 827ff830c96SMarek Szyprowski dev_err(dev, "failed to get clock 'mout_mixer'\n"); 8284551789fSSean Paul return -ENODEV; 8294551789fSSean Paul } 8304551789fSSean Paul 831*524c59f1SAndrzej Hajda if (mixer_ctx->sclk_hdmi && mixer_ctx->mout_mixer) 832*524c59f1SAndrzej Hajda clk_set_parent(mixer_ctx->mout_mixer, 833*524c59f1SAndrzej Hajda mixer_ctx->sclk_hdmi); 834ff830c96SMarek Szyprowski } 8354551789fSSean Paul 8364551789fSSean Paul res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1); 8374551789fSSean Paul if (res == NULL) { 8384551789fSSean Paul dev_err(dev, "get memory resource failed.\n"); 8394551789fSSean Paul return -ENXIO; 8404551789fSSean Paul } 8414551789fSSean Paul 842*524c59f1SAndrzej Hajda mixer_ctx->vp_regs = devm_ioremap(dev, res->start, 8434551789fSSean Paul resource_size(res)); 844*524c59f1SAndrzej Hajda if (mixer_ctx->vp_regs == NULL) { 8454551789fSSean Paul dev_err(dev, "register mapping failed.\n"); 8464551789fSSean Paul return -ENXIO; 8474551789fSSean Paul } 8484551789fSSean Paul 8494551789fSSean Paul return 0; 8504551789fSSean Paul } 8514551789fSSean Paul 85293bca243SGustavo Padovan static int mixer_initialize(struct mixer_context *mixer_ctx, 853f37cd5e8SInki Dae struct drm_device *drm_dev) 8544551789fSSean Paul { 8554551789fSSean Paul int ret; 856f37cd5e8SInki Dae struct exynos_drm_private *priv; 857f37cd5e8SInki Dae priv = drm_dev->dev_private; 8584551789fSSean Paul 859eb88e422SGustavo Padovan mixer_ctx->drm_dev = drm_dev; 8604551789fSSean Paul 8614551789fSSean Paul /* acquire resources: regs, irqs, clocks */ 8624551789fSSean Paul ret = mixer_resources_init(mixer_ctx); 8634551789fSSean Paul if (ret) { 8644551789fSSean Paul DRM_ERROR("mixer_resources_init failed ret=%d\n", ret); 8654551789fSSean Paul return ret; 8664551789fSSean Paul } 8674551789fSSean Paul 868adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &mixer_ctx->flags)) { 8694551789fSSean Paul /* acquire vp resources: regs, irqs, clocks */ 8704551789fSSean Paul ret = vp_resources_init(mixer_ctx); 8714551789fSSean Paul if (ret) { 8724551789fSSean Paul DRM_ERROR("vp_resources_init failed ret=%d\n", ret); 8734551789fSSean Paul return ret; 8744551789fSSean Paul } 8754551789fSSean Paul } 8764551789fSSean Paul 877f44d3d2fSAndrzej Hajda return drm_iommu_attach_device(drm_dev, mixer_ctx->dev); 8781055b39fSInki Dae } 8791055b39fSInki Dae 88093bca243SGustavo Padovan static void mixer_ctx_remove(struct mixer_context *mixer_ctx) 881d8408326SSeung-Woo Kim { 882f041b257SSean Paul drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev); 883f041b257SSean Paul } 884f041b257SSean Paul 88593bca243SGustavo Padovan static int mixer_enable_vblank(struct exynos_drm_crtc *crtc) 886f041b257SSean Paul { 88793bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx; 888d8408326SSeung-Woo Kim 8890df5e4acSAndrzej Hajda __set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags); 8900df5e4acSAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 891f041b257SSean Paul return 0; 892d8408326SSeung-Woo Kim 893d8408326SSeung-Woo Kim /* enable vsync interrupt */ 894*524c59f1SAndrzej Hajda mixer_reg_writemask(mixer_ctx, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC); 895*524c59f1SAndrzej Hajda mixer_reg_writemask(mixer_ctx, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC); 896d8408326SSeung-Woo Kim 897d8408326SSeung-Woo Kim return 0; 898d8408326SSeung-Woo Kim } 899d8408326SSeung-Woo Kim 90093bca243SGustavo Padovan static void mixer_disable_vblank(struct exynos_drm_crtc *crtc) 901d8408326SSeung-Woo Kim { 90293bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx; 903d8408326SSeung-Woo Kim 9040df5e4acSAndrzej Hajda __clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags); 9050df5e4acSAndrzej Hajda 9060df5e4acSAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 907947710c6SAndrzej Hajda return; 908947710c6SAndrzej Hajda 909d8408326SSeung-Woo Kim /* disable vsync interrupt */ 910*524c59f1SAndrzej Hajda mixer_reg_writemask(mixer_ctx, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC); 911*524c59f1SAndrzej Hajda mixer_reg_writemask(mixer_ctx, MXR_INT_EN, 0, MXR_INT_EN_VSYNC); 912d8408326SSeung-Woo Kim } 913d8408326SSeung-Woo Kim 9143dbaab16SMarek Szyprowski static void mixer_atomic_begin(struct exynos_drm_crtc *crtc) 9153dbaab16SMarek Szyprowski { 9163dbaab16SMarek Szyprowski struct mixer_context *mixer_ctx = crtc->ctx; 9173dbaab16SMarek Szyprowski 9183dbaab16SMarek Szyprowski if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 9193dbaab16SMarek Szyprowski return; 9203dbaab16SMarek Szyprowski 9213dbaab16SMarek Szyprowski mixer_vsync_set_update(mixer_ctx, false); 9223dbaab16SMarek Szyprowski } 9233dbaab16SMarek Szyprowski 9241e1d1393SGustavo Padovan static void mixer_update_plane(struct exynos_drm_crtc *crtc, 9251e1d1393SGustavo Padovan struct exynos_drm_plane *plane) 926d8408326SSeung-Woo Kim { 92793bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx; 928d8408326SSeung-Woo Kim 92940bdfb0aSMarek Szyprowski DRM_DEBUG_KMS("win: %d\n", plane->index); 930d8408326SSeung-Woo Kim 931a44652e8SAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 932dda9012bSShirish S return; 933dda9012bSShirish S 9345e68fef2SMarek Szyprowski if (plane->index == VP_DEFAULT_WIN) 9352eeb2e5eSGustavo Padovan vp_video_buffer(mixer_ctx, plane); 936d8408326SSeung-Woo Kim else 9372eeb2e5eSGustavo Padovan mixer_graph_buffer(mixer_ctx, plane); 938d8408326SSeung-Woo Kim } 939d8408326SSeung-Woo Kim 9401e1d1393SGustavo Padovan static void mixer_disable_plane(struct exynos_drm_crtc *crtc, 9411e1d1393SGustavo Padovan struct exynos_drm_plane *plane) 942d8408326SSeung-Woo Kim { 94393bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx; 944d8408326SSeung-Woo Kim unsigned long flags; 945d8408326SSeung-Woo Kim 94640bdfb0aSMarek Szyprowski DRM_DEBUG_KMS("win: %d\n", plane->index); 947d8408326SSeung-Woo Kim 948a44652e8SAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 949db43fd16SPrathyush K return; 950db43fd16SPrathyush K 951*524c59f1SAndrzej Hajda spin_lock_irqsave(&mixer_ctx->reg_slock, flags); 952a2cb911eSMarek Szyprowski mixer_cfg_layer(mixer_ctx, plane->index, 0, false); 953*524c59f1SAndrzej Hajda spin_unlock_irqrestore(&mixer_ctx->reg_slock, flags); 9543dbaab16SMarek Szyprowski } 9553dbaab16SMarek Szyprowski 9563dbaab16SMarek Szyprowski static void mixer_atomic_flush(struct exynos_drm_crtc *crtc) 9573dbaab16SMarek Szyprowski { 9583dbaab16SMarek Szyprowski struct mixer_context *mixer_ctx = crtc->ctx; 9593dbaab16SMarek Szyprowski 9603dbaab16SMarek Szyprowski if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 9613dbaab16SMarek Szyprowski return; 962d8408326SSeung-Woo Kim 963d8408326SSeung-Woo Kim mixer_vsync_set_update(mixer_ctx, true); 964a392276dSAndrzej Hajda exynos_crtc_handle_event(crtc); 965d8408326SSeung-Woo Kim } 966d8408326SSeung-Woo Kim 9673cecda03SGustavo Padovan static void mixer_enable(struct exynos_drm_crtc *crtc) 968db43fd16SPrathyush K { 9693cecda03SGustavo Padovan struct mixer_context *ctx = crtc->ctx; 970db43fd16SPrathyush K 971a44652e8SAndrzej Hajda if (test_bit(MXR_BIT_POWERED, &ctx->flags)) 972db43fd16SPrathyush K return; 973db43fd16SPrathyush K 974af65c804SSean Paul pm_runtime_get_sync(ctx->dev); 975af65c804SSean Paul 976a121d179SAndrzej Hajda exynos_drm_pipe_clk_enable(crtc, true); 977a121d179SAndrzej Hajda 9783dbaab16SMarek Szyprowski mixer_vsync_set_update(ctx, false); 9793dbaab16SMarek Szyprowski 980*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET); 981d74ed937SRahul Sharma 9820df5e4acSAndrzej Hajda if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) { 983*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_INT_STATUS, ~0, 984*524c59f1SAndrzej Hajda MXR_INT_CLEAR_VSYNC); 985*524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC); 9860df5e4acSAndrzej Hajda } 987db43fd16SPrathyush K mixer_win_reset(ctx); 988ccf034a9SGustavo Padovan 98971469944SAndrzej Hajda mixer_commit(ctx); 99071469944SAndrzej Hajda 9913dbaab16SMarek Szyprowski mixer_vsync_set_update(ctx, true); 9923dbaab16SMarek Szyprowski 993ccf034a9SGustavo Padovan set_bit(MXR_BIT_POWERED, &ctx->flags); 994db43fd16SPrathyush K } 995db43fd16SPrathyush K 9963cecda03SGustavo Padovan static void mixer_disable(struct exynos_drm_crtc *crtc) 997db43fd16SPrathyush K { 9983cecda03SGustavo Padovan struct mixer_context *ctx = crtc->ctx; 999c329f667SJoonyoung Shim int i; 1000db43fd16SPrathyush K 1001a44652e8SAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &ctx->flags)) 1002b4bfa3c7SRahul Sharma return; 1003db43fd16SPrathyush K 1004381be025SRahul Sharma mixer_stop(ctx); 1005c0734fbaSTobias Jakobi mixer_regs_dump(ctx); 1006c329f667SJoonyoung Shim 1007c329f667SJoonyoung Shim for (i = 0; i < MIXER_WIN_NR; i++) 10081e1d1393SGustavo Padovan mixer_disable_plane(crtc, &ctx->planes[i]); 1009db43fd16SPrathyush K 1010a121d179SAndrzej Hajda exynos_drm_pipe_clk_enable(crtc, false); 1011a121d179SAndrzej Hajda 1012ccf034a9SGustavo Padovan pm_runtime_put(ctx->dev); 1013ccf034a9SGustavo Padovan 1014a44652e8SAndrzej Hajda clear_bit(MXR_BIT_POWERED, &ctx->flags); 1015db43fd16SPrathyush K } 1016db43fd16SPrathyush K 10176ace38a5SAndrzej Hajda static int mixer_mode_valid(struct exynos_drm_crtc *crtc, 10186ace38a5SAndrzej Hajda const struct drm_display_mode *mode) 1019f041b257SSean Paul { 10206ace38a5SAndrzej Hajda struct mixer_context *ctx = crtc->ctx; 10216ace38a5SAndrzej Hajda u32 w = mode->hdisplay, h = mode->vdisplay; 1022f041b257SSean Paul 10236ace38a5SAndrzej Hajda DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n", w, h, 10246ace38a5SAndrzej Hajda mode->vrefresh, !!(mode->flags & DRM_MODE_FLAG_INTERLACE)); 1025f041b257SSean Paul 10266ace38a5SAndrzej Hajda if (ctx->mxr_ver == MXR_VER_128_0_0_184) 10276ace38a5SAndrzej Hajda return MODE_OK; 1028f041b257SSean Paul 1029f041b257SSean Paul if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) || 1030f041b257SSean Paul (w >= 1024 && w <= 1280 && h >= 576 && h <= 720) || 1031f041b257SSean Paul (w >= 1664 && w <= 1920 && h >= 936 && h <= 1080)) 10326ace38a5SAndrzej Hajda return MODE_OK; 1033f041b257SSean Paul 10346ace38a5SAndrzej Hajda return MODE_BAD; 1035f041b257SSean Paul } 1036f041b257SSean Paul 1037f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops mixer_crtc_ops = { 10383cecda03SGustavo Padovan .enable = mixer_enable, 10393cecda03SGustavo Padovan .disable = mixer_disable, 1040d8408326SSeung-Woo Kim .enable_vblank = mixer_enable_vblank, 1041d8408326SSeung-Woo Kim .disable_vblank = mixer_disable_vblank, 10423dbaab16SMarek Szyprowski .atomic_begin = mixer_atomic_begin, 10439cc7610aSGustavo Padovan .update_plane = mixer_update_plane, 10449cc7610aSGustavo Padovan .disable_plane = mixer_disable_plane, 10453dbaab16SMarek Szyprowski .atomic_flush = mixer_atomic_flush, 10466ace38a5SAndrzej Hajda .mode_valid = mixer_mode_valid, 1047f041b257SSean Paul }; 10480ea6822fSRahul Sharma 10495e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos5420_mxr_drv_data = { 1050def5e095SRahul Sharma .version = MXR_VER_128_0_0_184, 1051def5e095SRahul Sharma .is_vp_enabled = 0, 1052def5e095SRahul Sharma }; 1053def5e095SRahul Sharma 10545e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos5250_mxr_drv_data = { 1055aaf8b49eSRahul Sharma .version = MXR_VER_16_0_33_0, 1056aaf8b49eSRahul Sharma .is_vp_enabled = 0, 1057aaf8b49eSRahul Sharma }; 1058aaf8b49eSRahul Sharma 10595e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos4212_mxr_drv_data = { 1060ff830c96SMarek Szyprowski .version = MXR_VER_0_0_0_16, 1061ff830c96SMarek Szyprowski .is_vp_enabled = 1, 1062ff830c96SMarek Szyprowski }; 1063ff830c96SMarek Szyprowski 10645e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos4210_mxr_drv_data = { 10651e123441SRahul Sharma .version = MXR_VER_0_0_0_16, 10661b8e5747SRahul Sharma .is_vp_enabled = 1, 1067ff830c96SMarek Szyprowski .has_sclk = 1, 10681e123441SRahul Sharma }; 10691e123441SRahul Sharma 10705e6cc1c5SArvind Yadav static const struct of_device_id mixer_match_types[] = { 1071aaf8b49eSRahul Sharma { 1072ff830c96SMarek Szyprowski .compatible = "samsung,exynos4210-mixer", 1073ff830c96SMarek Szyprowski .data = &exynos4210_mxr_drv_data, 1074ff830c96SMarek Szyprowski }, { 1075ff830c96SMarek Szyprowski .compatible = "samsung,exynos4212-mixer", 1076ff830c96SMarek Szyprowski .data = &exynos4212_mxr_drv_data, 1077ff830c96SMarek Szyprowski }, { 1078aaf8b49eSRahul Sharma .compatible = "samsung,exynos5-mixer", 1079cc57caf0SRahul Sharma .data = &exynos5250_mxr_drv_data, 1080cc57caf0SRahul Sharma }, { 1081cc57caf0SRahul Sharma .compatible = "samsung,exynos5250-mixer", 1082cc57caf0SRahul Sharma .data = &exynos5250_mxr_drv_data, 1083aaf8b49eSRahul Sharma }, { 1084def5e095SRahul Sharma .compatible = "samsung,exynos5420-mixer", 1085def5e095SRahul Sharma .data = &exynos5420_mxr_drv_data, 1086def5e095SRahul Sharma }, { 10871e123441SRahul Sharma /* end node */ 10881e123441SRahul Sharma } 10891e123441SRahul Sharma }; 109039b58a39SSjoerd Simons MODULE_DEVICE_TABLE(of, mixer_match_types); 10911e123441SRahul Sharma 1092f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data) 1093d8408326SSeung-Woo Kim { 10948103ef1bSAndrzej Hajda struct mixer_context *ctx = dev_get_drvdata(dev); 1095f37cd5e8SInki Dae struct drm_device *drm_dev = data; 10967ee14cdcSGustavo Padovan struct exynos_drm_plane *exynos_plane; 1097fd2d2fc2SMarek Szyprowski unsigned int i; 10986e2a3b66SGustavo Padovan int ret; 1099d8408326SSeung-Woo Kim 1100e2dc3f72SAlban Browaeys ret = mixer_initialize(ctx, drm_dev); 1101e2dc3f72SAlban Browaeys if (ret) 1102e2dc3f72SAlban Browaeys return ret; 1103e2dc3f72SAlban Browaeys 1104fd2d2fc2SMarek Szyprowski for (i = 0; i < MIXER_WIN_NR; i++) { 1105adeb6f44STobias Jakobi if (i == VP_DEFAULT_WIN && !test_bit(MXR_BIT_VP_ENABLED, 1106adeb6f44STobias Jakobi &ctx->flags)) 1107ab144201SMarek Szyprowski continue; 1108ab144201SMarek Szyprowski 110940bdfb0aSMarek Szyprowski ret = exynos_plane_init(drm_dev, &ctx->planes[i], i, 11102c82607bSAndrzej Hajda &plane_configs[i]); 11117ee14cdcSGustavo Padovan if (ret) 11127ee14cdcSGustavo Padovan return ret; 11137ee14cdcSGustavo Padovan } 11147ee14cdcSGustavo Padovan 11155d3d0995SGustavo Padovan exynos_plane = &ctx->planes[DEFAULT_WIN]; 11167ee14cdcSGustavo Padovan ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, 1117d644951cSAndrzej Hajda EXYNOS_DISPLAY_TYPE_HDMI, &mixer_crtc_ops, ctx); 111893bca243SGustavo Padovan if (IS_ERR(ctx->crtc)) { 1119e2dc3f72SAlban Browaeys mixer_ctx_remove(ctx); 112093bca243SGustavo Padovan ret = PTR_ERR(ctx->crtc); 112193bca243SGustavo Padovan goto free_ctx; 11228103ef1bSAndrzej Hajda } 11238103ef1bSAndrzej Hajda 11248103ef1bSAndrzej Hajda return 0; 112593bca243SGustavo Padovan 112693bca243SGustavo Padovan free_ctx: 112793bca243SGustavo Padovan devm_kfree(dev, ctx); 112893bca243SGustavo Padovan return ret; 11298103ef1bSAndrzej Hajda } 11308103ef1bSAndrzej Hajda 11318103ef1bSAndrzej Hajda static void mixer_unbind(struct device *dev, struct device *master, void *data) 11328103ef1bSAndrzej Hajda { 11338103ef1bSAndrzej Hajda struct mixer_context *ctx = dev_get_drvdata(dev); 11348103ef1bSAndrzej Hajda 113593bca243SGustavo Padovan mixer_ctx_remove(ctx); 11368103ef1bSAndrzej Hajda } 11378103ef1bSAndrzej Hajda 11388103ef1bSAndrzej Hajda static const struct component_ops mixer_component_ops = { 11398103ef1bSAndrzej Hajda .bind = mixer_bind, 11408103ef1bSAndrzej Hajda .unbind = mixer_unbind, 11418103ef1bSAndrzej Hajda }; 11428103ef1bSAndrzej Hajda 11438103ef1bSAndrzej Hajda static int mixer_probe(struct platform_device *pdev) 11448103ef1bSAndrzej Hajda { 11458103ef1bSAndrzej Hajda struct device *dev = &pdev->dev; 114648f6155aSMarek Szyprowski const struct mixer_drv_data *drv; 11478103ef1bSAndrzej Hajda struct mixer_context *ctx; 11488103ef1bSAndrzej Hajda int ret; 1149d8408326SSeung-Woo Kim 1150f041b257SSean Paul ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 1151f041b257SSean Paul if (!ctx) { 1152f041b257SSean Paul DRM_ERROR("failed to alloc mixer context.\n"); 1153d8408326SSeung-Woo Kim return -ENOMEM; 1154f041b257SSean Paul } 1155d8408326SSeung-Woo Kim 115648f6155aSMarek Szyprowski drv = of_device_get_match_data(dev); 1157aaf8b49eSRahul Sharma 11584551789fSSean Paul ctx->pdev = pdev; 1159d873ab99SSeung-Woo Kim ctx->dev = dev; 11601e123441SRahul Sharma ctx->mxr_ver = drv->version; 1161d8408326SSeung-Woo Kim 1162adeb6f44STobias Jakobi if (drv->is_vp_enabled) 1163adeb6f44STobias Jakobi __set_bit(MXR_BIT_VP_ENABLED, &ctx->flags); 1164adeb6f44STobias Jakobi if (drv->has_sclk) 1165adeb6f44STobias Jakobi __set_bit(MXR_BIT_HAS_SCLK, &ctx->flags); 1166adeb6f44STobias Jakobi 11678103ef1bSAndrzej Hajda platform_set_drvdata(pdev, ctx); 1168df5225bcSInki Dae 1169df5225bcSInki Dae ret = component_add(&pdev->dev, &mixer_component_ops); 117086650408SAndrzej Hajda if (!ret) 11718103ef1bSAndrzej Hajda pm_runtime_enable(dev); 1172df5225bcSInki Dae 1173df5225bcSInki Dae return ret; 1174f37cd5e8SInki Dae } 1175f37cd5e8SInki Dae 1176d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev) 1177d8408326SSeung-Woo Kim { 11788103ef1bSAndrzej Hajda pm_runtime_disable(&pdev->dev); 11798103ef1bSAndrzej Hajda 1180df5225bcSInki Dae component_del(&pdev->dev, &mixer_component_ops); 1181df5225bcSInki Dae 1182d8408326SSeung-Woo Kim return 0; 1183d8408326SSeung-Woo Kim } 1184d8408326SSeung-Woo Kim 1185e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_suspend(struct device *dev) 1186ccf034a9SGustavo Padovan { 1187ccf034a9SGustavo Padovan struct mixer_context *ctx = dev_get_drvdata(dev); 1188ccf034a9SGustavo Padovan 1189*524c59f1SAndrzej Hajda clk_disable_unprepare(ctx->hdmi); 1190*524c59f1SAndrzej Hajda clk_disable_unprepare(ctx->mixer); 1191adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) { 1192*524c59f1SAndrzej Hajda clk_disable_unprepare(ctx->vp); 1193adeb6f44STobias Jakobi if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags)) 1194*524c59f1SAndrzej Hajda clk_disable_unprepare(ctx->sclk_mixer); 1195ccf034a9SGustavo Padovan } 1196ccf034a9SGustavo Padovan 1197ccf034a9SGustavo Padovan return 0; 1198ccf034a9SGustavo Padovan } 1199ccf034a9SGustavo Padovan 1200e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_resume(struct device *dev) 1201ccf034a9SGustavo Padovan { 1202ccf034a9SGustavo Padovan struct mixer_context *ctx = dev_get_drvdata(dev); 1203ccf034a9SGustavo Padovan int ret; 1204ccf034a9SGustavo Padovan 1205*524c59f1SAndrzej Hajda ret = clk_prepare_enable(ctx->mixer); 1206ccf034a9SGustavo Padovan if (ret < 0) { 1207ccf034a9SGustavo Padovan DRM_ERROR("Failed to prepare_enable the mixer clk [%d]\n", ret); 1208ccf034a9SGustavo Padovan return ret; 1209ccf034a9SGustavo Padovan } 1210*524c59f1SAndrzej Hajda ret = clk_prepare_enable(ctx->hdmi); 1211ccf034a9SGustavo Padovan if (ret < 0) { 1212ccf034a9SGustavo Padovan DRM_ERROR("Failed to prepare_enable the hdmi clk [%d]\n", ret); 1213ccf034a9SGustavo Padovan return ret; 1214ccf034a9SGustavo Padovan } 1215adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) { 1216*524c59f1SAndrzej Hajda ret = clk_prepare_enable(ctx->vp); 1217ccf034a9SGustavo Padovan if (ret < 0) { 1218ccf034a9SGustavo Padovan DRM_ERROR("Failed to prepare_enable the vp clk [%d]\n", 1219ccf034a9SGustavo Padovan ret); 1220ccf034a9SGustavo Padovan return ret; 1221ccf034a9SGustavo Padovan } 1222adeb6f44STobias Jakobi if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags)) { 1223*524c59f1SAndrzej Hajda ret = clk_prepare_enable(ctx->sclk_mixer); 1224ccf034a9SGustavo Padovan if (ret < 0) { 1225ccf034a9SGustavo Padovan DRM_ERROR("Failed to prepare_enable the " \ 1226ccf034a9SGustavo Padovan "sclk_mixer clk [%d]\n", 1227ccf034a9SGustavo Padovan ret); 1228ccf034a9SGustavo Padovan return ret; 1229ccf034a9SGustavo Padovan } 1230ccf034a9SGustavo Padovan } 1231ccf034a9SGustavo Padovan } 1232ccf034a9SGustavo Padovan 1233ccf034a9SGustavo Padovan return 0; 1234ccf034a9SGustavo Padovan } 1235ccf034a9SGustavo Padovan 1236ccf034a9SGustavo Padovan static const struct dev_pm_ops exynos_mixer_pm_ops = { 1237ccf034a9SGustavo Padovan SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL) 1238ccf034a9SGustavo Padovan }; 1239ccf034a9SGustavo Padovan 1240d8408326SSeung-Woo Kim struct platform_driver mixer_driver = { 1241d8408326SSeung-Woo Kim .driver = { 1242aaf8b49eSRahul Sharma .name = "exynos-mixer", 1243d8408326SSeung-Woo Kim .owner = THIS_MODULE, 1244ccf034a9SGustavo Padovan .pm = &exynos_mixer_pm_ops, 1245aaf8b49eSRahul Sharma .of_match_table = mixer_match_types, 1246d8408326SSeung-Woo Kim }, 1247d8408326SSeung-Woo Kim .probe = mixer_probe, 124856550d94SGreg Kroah-Hartman .remove = mixer_remove, 1249d8408326SSeung-Woo Kim }; 1250