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> 34f37cd5e8SInki Dae #include <linux/component.h> 35d8408326SSeung-Woo Kim 36d8408326SSeung-Woo Kim #include <drm/exynos_drm.h> 37d8408326SSeung-Woo Kim 38d8408326SSeung-Woo Kim #include "exynos_drm_drv.h" 39663d8766SRahul Sharma #include "exynos_drm_crtc.h" 407ee14cdcSGustavo Padovan #include "exynos_drm_plane.h" 411055b39fSInki Dae #include "exynos_drm_iommu.h" 4222b21ae6SJoonyoung Shim 43f041b257SSean Paul #define MIXER_WIN_NR 3 44fbbb1e1aSMarek Szyprowski #define VP_DEFAULT_WIN 2 45323db0edSGustavo Padovan #define CURSOR_WIN 1 46d8408326SSeung-Woo Kim 477a57ca7cSTobias Jakobi /* The pixelformats that are natively supported by the mixer. */ 487a57ca7cSTobias Jakobi #define MXR_FORMAT_RGB565 4 497a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB1555 5 507a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB4444 6 517a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB8888 7 527a57ca7cSTobias Jakobi 5322b21ae6SJoonyoung Shim struct mixer_resources { 5422b21ae6SJoonyoung Shim int irq; 5522b21ae6SJoonyoung Shim void __iomem *mixer_regs; 5622b21ae6SJoonyoung Shim void __iomem *vp_regs; 5722b21ae6SJoonyoung Shim spinlock_t reg_slock; 5822b21ae6SJoonyoung Shim struct clk *mixer; 5922b21ae6SJoonyoung Shim struct clk *vp; 6004427ec5SMarek Szyprowski struct clk *hdmi; 6122b21ae6SJoonyoung Shim struct clk *sclk_mixer; 6222b21ae6SJoonyoung Shim struct clk *sclk_hdmi; 63ff830c96SMarek Szyprowski struct clk *mout_mixer; 6422b21ae6SJoonyoung Shim }; 6522b21ae6SJoonyoung Shim 661e123441SRahul Sharma enum mixer_version_id { 671e123441SRahul Sharma MXR_VER_0_0_0_16, 681e123441SRahul Sharma MXR_VER_16_0_33_0, 69def5e095SRahul Sharma MXR_VER_128_0_0_184, 701e123441SRahul Sharma }; 711e123441SRahul Sharma 72a44652e8SAndrzej Hajda enum mixer_flag_bits { 73a44652e8SAndrzej Hajda MXR_BIT_POWERED, 740df5e4acSAndrzej Hajda MXR_BIT_VSYNC, 75a44652e8SAndrzej Hajda }; 76a44652e8SAndrzej Hajda 77fbbb1e1aSMarek Szyprowski static const uint32_t mixer_formats[] = { 78fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB4444, 79fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB1555, 80fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGB565, 81fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB8888, 82fbbb1e1aSMarek Szyprowski DRM_FORMAT_ARGB8888, 83fbbb1e1aSMarek Szyprowski }; 84fbbb1e1aSMarek Szyprowski 85fbbb1e1aSMarek Szyprowski static const uint32_t vp_formats[] = { 86fbbb1e1aSMarek Szyprowski DRM_FORMAT_NV12, 87fbbb1e1aSMarek Szyprowski DRM_FORMAT_NV21, 88fbbb1e1aSMarek Szyprowski }; 89fbbb1e1aSMarek Szyprowski 9022b21ae6SJoonyoung Shim struct mixer_context { 914551789fSSean Paul struct platform_device *pdev; 92cf8fc4f1SJoonyoung Shim struct device *dev; 931055b39fSInki Dae struct drm_device *drm_dev; 9493bca243SGustavo Padovan struct exynos_drm_crtc *crtc; 957ee14cdcSGustavo Padovan struct exynos_drm_plane planes[MIXER_WIN_NR]; 9622b21ae6SJoonyoung Shim int pipe; 97a44652e8SAndrzej Hajda unsigned long flags; 9822b21ae6SJoonyoung Shim bool interlace; 991b8e5747SRahul Sharma bool vp_enabled; 100ff830c96SMarek Szyprowski bool has_sclk; 10122b21ae6SJoonyoung Shim 10222b21ae6SJoonyoung Shim struct mixer_resources mixer_res; 1031e123441SRahul Sharma enum mixer_version_id mxr_ver; 1046e95d5e6SPrathyush K wait_queue_head_t wait_vsync_queue; 1056e95d5e6SPrathyush K atomic_t wait_vsync_event; 1061e123441SRahul Sharma }; 1071e123441SRahul Sharma 1081e123441SRahul Sharma struct mixer_drv_data { 1091e123441SRahul Sharma enum mixer_version_id version; 1101b8e5747SRahul Sharma bool is_vp_enabled; 111ff830c96SMarek Szyprowski bool has_sclk; 11222b21ae6SJoonyoung Shim }; 11322b21ae6SJoonyoung Shim 114d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = { 115d8408326SSeung-Woo Kim 0, -1, -1, -1, -1, -1, -1, -1, 116d8408326SSeung-Woo Kim -1, -1, -1, -1, -1, 0, 0, 0, 117d8408326SSeung-Woo Kim 0, 2, 4, 5, 6, 6, 6, 6, 118d8408326SSeung-Woo Kim 6, 5, 5, 4, 3, 2, 1, 1, 119d8408326SSeung-Woo Kim 0, -6, -12, -16, -18, -20, -21, -20, 120d8408326SSeung-Woo Kim -20, -18, -16, -13, -10, -8, -5, -2, 121d8408326SSeung-Woo Kim 127, 126, 125, 121, 114, 107, 99, 89, 122d8408326SSeung-Woo Kim 79, 68, 57, 46, 35, 25, 16, 8, 123d8408326SSeung-Woo Kim }; 124d8408326SSeung-Woo Kim 125d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = { 126d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7, 127d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0, 128d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81, 129d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5, 130d8408326SSeung-Woo Kim 0, 5, 11, 19, 27, 37, 48, 59, 131d8408326SSeung-Woo Kim 70, 81, 92, 102, 111, 118, 124, 126, 132d8408326SSeung-Woo Kim 0, 0, -1, -1, -2, -3, -4, -5, 133d8408326SSeung-Woo Kim -6, -7, -8, -8, -8, -8, -6, -3, 134d8408326SSeung-Woo Kim }; 135d8408326SSeung-Woo Kim 136d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = { 137d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7, 138d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0, 139d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81, 140d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5, 141d8408326SSeung-Woo Kim }; 142d8408326SSeung-Woo Kim 143d8408326SSeung-Woo Kim static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id) 144d8408326SSeung-Woo Kim { 145d8408326SSeung-Woo Kim return readl(res->vp_regs + reg_id); 146d8408326SSeung-Woo Kim } 147d8408326SSeung-Woo Kim 148d8408326SSeung-Woo Kim static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id, 149d8408326SSeung-Woo Kim u32 val) 150d8408326SSeung-Woo Kim { 151d8408326SSeung-Woo Kim writel(val, res->vp_regs + reg_id); 152d8408326SSeung-Woo Kim } 153d8408326SSeung-Woo Kim 154d8408326SSeung-Woo Kim static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id, 155d8408326SSeung-Woo Kim u32 val, u32 mask) 156d8408326SSeung-Woo Kim { 157d8408326SSeung-Woo Kim u32 old = vp_reg_read(res, reg_id); 158d8408326SSeung-Woo Kim 159d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask); 160d8408326SSeung-Woo Kim writel(val, res->vp_regs + reg_id); 161d8408326SSeung-Woo Kim } 162d8408326SSeung-Woo Kim 163d8408326SSeung-Woo Kim static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id) 164d8408326SSeung-Woo Kim { 165d8408326SSeung-Woo Kim return readl(res->mixer_regs + reg_id); 166d8408326SSeung-Woo Kim } 167d8408326SSeung-Woo Kim 168d8408326SSeung-Woo Kim static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id, 169d8408326SSeung-Woo Kim u32 val) 170d8408326SSeung-Woo Kim { 171d8408326SSeung-Woo Kim writel(val, res->mixer_regs + reg_id); 172d8408326SSeung-Woo Kim } 173d8408326SSeung-Woo Kim 174d8408326SSeung-Woo Kim static inline void mixer_reg_writemask(struct mixer_resources *res, 175d8408326SSeung-Woo Kim u32 reg_id, u32 val, u32 mask) 176d8408326SSeung-Woo Kim { 177d8408326SSeung-Woo Kim u32 old = mixer_reg_read(res, reg_id); 178d8408326SSeung-Woo Kim 179d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask); 180d8408326SSeung-Woo Kim writel(val, res->mixer_regs + reg_id); 181d8408326SSeung-Woo Kim } 182d8408326SSeung-Woo Kim 183d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx) 184d8408326SSeung-Woo Kim { 185d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \ 186d8408326SSeung-Woo Kim do { \ 187d8408326SSeung-Woo Kim DRM_DEBUG_KMS(#reg_id " = %08x\n", \ 188d8408326SSeung-Woo Kim (u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \ 189d8408326SSeung-Woo Kim } while (0) 190d8408326SSeung-Woo Kim 191d8408326SSeung-Woo Kim DUMPREG(MXR_STATUS); 192d8408326SSeung-Woo Kim DUMPREG(MXR_CFG); 193d8408326SSeung-Woo Kim DUMPREG(MXR_INT_EN); 194d8408326SSeung-Woo Kim DUMPREG(MXR_INT_STATUS); 195d8408326SSeung-Woo Kim 196d8408326SSeung-Woo Kim DUMPREG(MXR_LAYER_CFG); 197d8408326SSeung-Woo Kim DUMPREG(MXR_VIDEO_CFG); 198d8408326SSeung-Woo Kim 199d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_CFG); 200d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_BASE); 201d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SPAN); 202d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_WH); 203d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SXY); 204d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_DXY); 205d8408326SSeung-Woo Kim 206d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_CFG); 207d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_BASE); 208d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SPAN); 209d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_WH); 210d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SXY); 211d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_DXY); 212d8408326SSeung-Woo Kim #undef DUMPREG 213d8408326SSeung-Woo Kim } 214d8408326SSeung-Woo Kim 215d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx) 216d8408326SSeung-Woo Kim { 217d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \ 218d8408326SSeung-Woo Kim do { \ 219d8408326SSeung-Woo Kim DRM_DEBUG_KMS(#reg_id " = %08x\n", \ 220d8408326SSeung-Woo Kim (u32) readl(ctx->mixer_res.vp_regs + reg_id)); \ 221d8408326SSeung-Woo Kim } while (0) 222d8408326SSeung-Woo Kim 223d8408326SSeung-Woo Kim DUMPREG(VP_ENABLE); 224d8408326SSeung-Woo Kim DUMPREG(VP_SRESET); 225d8408326SSeung-Woo Kim DUMPREG(VP_SHADOW_UPDATE); 226d8408326SSeung-Woo Kim DUMPREG(VP_FIELD_ID); 227d8408326SSeung-Woo Kim DUMPREG(VP_MODE); 228d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_Y); 229d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_C); 230d8408326SSeung-Woo Kim DUMPREG(VP_PER_RATE_CTRL); 231d8408326SSeung-Woo Kim DUMPREG(VP_TOP_Y_PTR); 232d8408326SSeung-Woo Kim DUMPREG(VP_BOT_Y_PTR); 233d8408326SSeung-Woo Kim DUMPREG(VP_TOP_C_PTR); 234d8408326SSeung-Woo Kim DUMPREG(VP_BOT_C_PTR); 235d8408326SSeung-Woo Kim DUMPREG(VP_ENDIAN_MODE); 236d8408326SSeung-Woo Kim DUMPREG(VP_SRC_H_POSITION); 237d8408326SSeung-Woo Kim DUMPREG(VP_SRC_V_POSITION); 238d8408326SSeung-Woo Kim DUMPREG(VP_SRC_WIDTH); 239d8408326SSeung-Woo Kim DUMPREG(VP_SRC_HEIGHT); 240d8408326SSeung-Woo Kim DUMPREG(VP_DST_H_POSITION); 241d8408326SSeung-Woo Kim DUMPREG(VP_DST_V_POSITION); 242d8408326SSeung-Woo Kim DUMPREG(VP_DST_WIDTH); 243d8408326SSeung-Woo Kim DUMPREG(VP_DST_HEIGHT); 244d8408326SSeung-Woo Kim DUMPREG(VP_H_RATIO); 245d8408326SSeung-Woo Kim DUMPREG(VP_V_RATIO); 246d8408326SSeung-Woo Kim 247d8408326SSeung-Woo Kim #undef DUMPREG 248d8408326SSeung-Woo Kim } 249d8408326SSeung-Woo Kim 250d8408326SSeung-Woo Kim static inline void vp_filter_set(struct mixer_resources *res, 251d8408326SSeung-Woo Kim int reg_id, const u8 *data, unsigned int size) 252d8408326SSeung-Woo Kim { 253d8408326SSeung-Woo Kim /* assure 4-byte align */ 254d8408326SSeung-Woo Kim BUG_ON(size & 3); 255d8408326SSeung-Woo Kim for (; size; size -= 4, reg_id += 4, data += 4) { 256d8408326SSeung-Woo Kim u32 val = (data[0] << 24) | (data[1] << 16) | 257d8408326SSeung-Woo Kim (data[2] << 8) | data[3]; 258d8408326SSeung-Woo Kim vp_reg_write(res, reg_id, val); 259d8408326SSeung-Woo Kim } 260d8408326SSeung-Woo Kim } 261d8408326SSeung-Woo Kim 262d8408326SSeung-Woo Kim static void vp_default_filter(struct mixer_resources *res) 263d8408326SSeung-Woo Kim { 264d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY8_Y0_LL, 265e25e1b66SSachin Kamat filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8)); 266d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY4_Y0_LL, 267e25e1b66SSachin Kamat filter_y_vert_tap4, sizeof(filter_y_vert_tap4)); 268d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY4_C0_LL, 269e25e1b66SSachin Kamat filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4)); 270d8408326SSeung-Woo Kim } 271d8408326SSeung-Woo Kim 272d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable) 273d8408326SSeung-Woo Kim { 274d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 275d8408326SSeung-Woo Kim 276d8408326SSeung-Woo Kim /* block update on vsync */ 277d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_STATUS, enable ? 278d8408326SSeung-Woo Kim MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE); 279d8408326SSeung-Woo Kim 2801b8e5747SRahul Sharma if (ctx->vp_enabled) 281d8408326SSeung-Woo Kim vp_reg_write(res, VP_SHADOW_UPDATE, enable ? 282d8408326SSeung-Woo Kim VP_SHADOW_UPDATE_ENABLE : 0); 283d8408326SSeung-Woo Kim } 284d8408326SSeung-Woo Kim 285d8408326SSeung-Woo Kim static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height) 286d8408326SSeung-Woo Kim { 287d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 288d8408326SSeung-Woo Kim u32 val; 289d8408326SSeung-Woo Kim 290d8408326SSeung-Woo Kim /* choosing between interlace and progressive mode */ 291d8408326SSeung-Woo Kim val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE : 2921e6d459dSTobias Jakobi MXR_CFG_SCAN_PROGRESSIVE); 293d8408326SSeung-Woo Kim 294def5e095SRahul Sharma if (ctx->mxr_ver != MXR_VER_128_0_0_184) { 295def5e095SRahul Sharma /* choosing between proper HD and SD mode */ 29629630743SRahul Sharma if (height <= 480) 297d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD; 29829630743SRahul Sharma else if (height <= 576) 299d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD; 30029630743SRahul Sharma else if (height <= 720) 301d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; 30229630743SRahul Sharma else if (height <= 1080) 303d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD; 304d8408326SSeung-Woo Kim else 305d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; 306def5e095SRahul Sharma } 307d8408326SSeung-Woo Kim 308d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK); 309d8408326SSeung-Woo Kim } 310d8408326SSeung-Woo Kim 311d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height) 312d8408326SSeung-Woo Kim { 313d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 314d8408326SSeung-Woo Kim u32 val; 315d8408326SSeung-Woo Kim 316d8408326SSeung-Woo Kim if (height == 480) { 317d8408326SSeung-Woo Kim val = MXR_CFG_RGB601_0_255; 318d8408326SSeung-Woo Kim } else if (height == 576) { 319d8408326SSeung-Woo Kim val = MXR_CFG_RGB601_0_255; 320d8408326SSeung-Woo Kim } else if (height == 720) { 321d8408326SSeung-Woo Kim val = MXR_CFG_RGB709_16_235; 322d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_Y, 323d8408326SSeung-Woo Kim (1 << 30) | (94 << 20) | (314 << 10) | 324d8408326SSeung-Woo Kim (32 << 0)); 325d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CB, 326d8408326SSeung-Woo Kim (972 << 20) | (851 << 10) | (225 << 0)); 327d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CR, 328d8408326SSeung-Woo Kim (225 << 20) | (820 << 10) | (1004 << 0)); 329d8408326SSeung-Woo Kim } else if (height == 1080) { 330d8408326SSeung-Woo Kim val = MXR_CFG_RGB709_16_235; 331d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_Y, 332d8408326SSeung-Woo Kim (1 << 30) | (94 << 20) | (314 << 10) | 333d8408326SSeung-Woo Kim (32 << 0)); 334d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CB, 335d8408326SSeung-Woo Kim (972 << 20) | (851 << 10) | (225 << 0)); 336d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CR, 337d8408326SSeung-Woo Kim (225 << 20) | (820 << 10) | (1004 << 0)); 338d8408326SSeung-Woo Kim } else { 339d8408326SSeung-Woo Kim val = MXR_CFG_RGB709_16_235; 340d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_Y, 341d8408326SSeung-Woo Kim (1 << 30) | (94 << 20) | (314 << 10) | 342d8408326SSeung-Woo Kim (32 << 0)); 343d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CB, 344d8408326SSeung-Woo Kim (972 << 20) | (851 << 10) | (225 << 0)); 345d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CR, 346d8408326SSeung-Woo Kim (225 << 20) | (820 << 10) | (1004 << 0)); 347d8408326SSeung-Woo Kim } 348d8408326SSeung-Woo Kim 349d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK); 350d8408326SSeung-Woo Kim } 351d8408326SSeung-Woo Kim 3525b1d5bc6STobias Jakobi static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win, 3535b1d5bc6STobias Jakobi bool enable) 354d8408326SSeung-Woo Kim { 355d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 356d8408326SSeung-Woo Kim u32 val = enable ? ~0 : 0; 357d8408326SSeung-Woo Kim 358d8408326SSeung-Woo Kim switch (win) { 359d8408326SSeung-Woo Kim case 0: 360d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE); 361d8408326SSeung-Woo Kim break; 362d8408326SSeung-Woo Kim case 1: 363d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE); 364d8408326SSeung-Woo Kim break; 365d8408326SSeung-Woo Kim case 2: 3661b8e5747SRahul Sharma if (ctx->vp_enabled) { 367d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON); 3681b8e5747SRahul Sharma mixer_reg_writemask(res, MXR_CFG, val, 3691b8e5747SRahul Sharma MXR_CFG_VP_ENABLE); 370f1e716d8SJoonyoung Shim 371f1e716d8SJoonyoung Shim /* control blending of graphic layer 0 */ 372f1e716d8SJoonyoung Shim mixer_reg_writemask(res, MXR_GRAPHIC_CFG(0), val, 373f1e716d8SJoonyoung Shim MXR_GRP_CFG_BLEND_PRE_MUL | 374f1e716d8SJoonyoung Shim MXR_GRP_CFG_PIXEL_BLEND_EN); 3751b8e5747SRahul Sharma } 376d8408326SSeung-Woo Kim break; 377d8408326SSeung-Woo Kim } 378d8408326SSeung-Woo Kim } 379d8408326SSeung-Woo Kim 380d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx) 381d8408326SSeung-Woo Kim { 382d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 383d8408326SSeung-Woo Kim 384d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN); 385d8408326SSeung-Woo Kim } 386d8408326SSeung-Woo Kim 387381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx) 388381be025SRahul Sharma { 389381be025SRahul Sharma struct mixer_resources *res = &ctx->mixer_res; 390381be025SRahul Sharma int timeout = 20; 391381be025SRahul Sharma 392381be025SRahul Sharma mixer_reg_writemask(res, MXR_STATUS, 0, MXR_STATUS_REG_RUN); 393381be025SRahul Sharma 394381be025SRahul Sharma while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) && 395381be025SRahul Sharma --timeout) 396381be025SRahul Sharma usleep_range(10000, 12000); 397381be025SRahul Sharma } 398381be025SRahul Sharma 3992eeb2e5eSGustavo Padovan static void vp_video_buffer(struct mixer_context *ctx, 4002eeb2e5eSGustavo Padovan struct exynos_drm_plane *plane) 401d8408326SSeung-Woo Kim { 402d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 4032eeb2e5eSGustavo Padovan struct drm_plane_state *state = plane->base.state; 4042eeb2e5eSGustavo Padovan struct drm_framebuffer *fb = state->fb; 4052eeb2e5eSGustavo Padovan struct drm_display_mode *mode = &state->crtc->mode; 406d8408326SSeung-Woo Kim unsigned long flags; 407d8408326SSeung-Woo Kim dma_addr_t luma_addr[2], chroma_addr[2]; 408d8408326SSeung-Woo Kim bool tiled_mode = false; 409d8408326SSeung-Woo Kim bool crcb_mode = false; 410d8408326SSeung-Woo Kim u32 val; 411d8408326SSeung-Woo Kim 4122eeb2e5eSGustavo Padovan switch (fb->pixel_format) { 413363b06aaSVille Syrjälä case DRM_FORMAT_NV12: 414d8408326SSeung-Woo Kim crcb_mode = false; 415d8408326SSeung-Woo Kim break; 4168f2590f8STobias Jakobi case DRM_FORMAT_NV21: 4178f2590f8STobias Jakobi crcb_mode = true; 4188f2590f8STobias Jakobi break; 419d8408326SSeung-Woo Kim default: 420d8408326SSeung-Woo Kim DRM_ERROR("pixel format for vp is wrong [%d].\n", 4212eeb2e5eSGustavo Padovan fb->pixel_format); 422d8408326SSeung-Woo Kim return; 423d8408326SSeung-Woo Kim } 424d8408326SSeung-Woo Kim 4257ee14cdcSGustavo Padovan luma_addr[0] = plane->dma_addr[0]; 4267ee14cdcSGustavo Padovan chroma_addr[0] = plane->dma_addr[1]; 427d8408326SSeung-Woo Kim 4282eeb2e5eSGustavo Padovan if (mode->flags & DRM_MODE_FLAG_INTERLACE) { 429d8408326SSeung-Woo Kim ctx->interlace = true; 430d8408326SSeung-Woo Kim if (tiled_mode) { 431d8408326SSeung-Woo Kim luma_addr[1] = luma_addr[0] + 0x40; 432d8408326SSeung-Woo Kim chroma_addr[1] = chroma_addr[0] + 0x40; 433d8408326SSeung-Woo Kim } else { 4342eeb2e5eSGustavo Padovan luma_addr[1] = luma_addr[0] + fb->pitches[0]; 4352eeb2e5eSGustavo Padovan chroma_addr[1] = chroma_addr[0] + fb->pitches[0]; 436d8408326SSeung-Woo Kim } 437d8408326SSeung-Woo Kim } else { 438d8408326SSeung-Woo Kim ctx->interlace = false; 439d8408326SSeung-Woo Kim luma_addr[1] = 0; 440d8408326SSeung-Woo Kim chroma_addr[1] = 0; 441d8408326SSeung-Woo Kim } 442d8408326SSeung-Woo Kim 443d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 444d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, false); 445d8408326SSeung-Woo Kim 446d8408326SSeung-Woo Kim /* interlace or progressive scan mode */ 447d8408326SSeung-Woo Kim val = (ctx->interlace ? ~0 : 0); 448d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP); 449d8408326SSeung-Woo Kim 450d8408326SSeung-Woo Kim /* setup format */ 451d8408326SSeung-Woo Kim val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12); 452d8408326SSeung-Woo Kim val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR); 453d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK); 454d8408326SSeung-Woo Kim 455d8408326SSeung-Woo Kim /* setting size of input image */ 4562eeb2e5eSGustavo Padovan vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) | 4572eeb2e5eSGustavo Padovan VP_IMG_VSIZE(fb->height)); 458d8408326SSeung-Woo Kim /* chroma height has to reduced by 2 to avoid chroma distorions */ 4592eeb2e5eSGustavo Padovan vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[0]) | 4602eeb2e5eSGustavo Padovan VP_IMG_VSIZE(fb->height / 2)); 461d8408326SSeung-Woo Kim 462d88d2463SGustavo Padovan vp_reg_write(res, VP_SRC_WIDTH, plane->src_w); 463d88d2463SGustavo Padovan vp_reg_write(res, VP_SRC_HEIGHT, plane->src_h); 464d8408326SSeung-Woo Kim vp_reg_write(res, VP_SRC_H_POSITION, 465cb8a3db2SJoonyoung Shim VP_SRC_H_POSITION_VAL(plane->src_x)); 466cb8a3db2SJoonyoung Shim vp_reg_write(res, VP_SRC_V_POSITION, plane->src_y); 467d8408326SSeung-Woo Kim 468d88d2463SGustavo Padovan vp_reg_write(res, VP_DST_WIDTH, plane->crtc_w); 4697ee14cdcSGustavo Padovan vp_reg_write(res, VP_DST_H_POSITION, plane->crtc_x); 470d8408326SSeung-Woo Kim if (ctx->interlace) { 471d88d2463SGustavo Padovan vp_reg_write(res, VP_DST_HEIGHT, plane->crtc_h / 2); 4727ee14cdcSGustavo Padovan vp_reg_write(res, VP_DST_V_POSITION, plane->crtc_y / 2); 473d8408326SSeung-Woo Kim } else { 474d88d2463SGustavo Padovan vp_reg_write(res, VP_DST_HEIGHT, plane->crtc_h); 4757ee14cdcSGustavo Padovan vp_reg_write(res, VP_DST_V_POSITION, plane->crtc_y); 476d8408326SSeung-Woo Kim } 477d8408326SSeung-Woo Kim 4783cabaf7eSJoonyoung Shim vp_reg_write(res, VP_H_RATIO, plane->h_ratio); 4793cabaf7eSJoonyoung Shim vp_reg_write(res, VP_V_RATIO, plane->v_ratio); 480d8408326SSeung-Woo Kim 481d8408326SSeung-Woo Kim vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE); 482d8408326SSeung-Woo Kim 483d8408326SSeung-Woo Kim /* set buffer address to vp */ 484d8408326SSeung-Woo Kim vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]); 485d8408326SSeung-Woo Kim vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]); 486d8408326SSeung-Woo Kim vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]); 487d8408326SSeung-Woo Kim vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]); 488d8408326SSeung-Woo Kim 4892eeb2e5eSGustavo Padovan mixer_cfg_scan(ctx, mode->vdisplay); 4902eeb2e5eSGustavo Padovan mixer_cfg_rgb_fmt(ctx, mode->vdisplay); 4912eeb2e5eSGustavo Padovan mixer_cfg_layer(ctx, plane->zpos, true); 492d8408326SSeung-Woo Kim mixer_run(ctx); 493d8408326SSeung-Woo Kim 494d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, true); 495d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 496d8408326SSeung-Woo Kim 497c0734fbaSTobias Jakobi mixer_regs_dump(ctx); 498d8408326SSeung-Woo Kim vp_regs_dump(ctx); 499d8408326SSeung-Woo Kim } 500d8408326SSeung-Woo Kim 501aaf8b49eSRahul Sharma static void mixer_layer_update(struct mixer_context *ctx) 502aaf8b49eSRahul Sharma { 503aaf8b49eSRahul Sharma struct mixer_resources *res = &ctx->mixer_res; 504aaf8b49eSRahul Sharma 505aaf8b49eSRahul Sharma mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE); 506aaf8b49eSRahul Sharma } 507aaf8b49eSRahul Sharma 5082611015cSTobias Jakobi static int mixer_setup_scale(const struct exynos_drm_plane *plane, 5092611015cSTobias Jakobi unsigned int *x_ratio, unsigned int *y_ratio) 5102611015cSTobias Jakobi { 511d88d2463SGustavo Padovan if (plane->crtc_w != plane->src_w) { 512d88d2463SGustavo Padovan if (plane->crtc_w == 2 * plane->src_w) 5132611015cSTobias Jakobi *x_ratio = 1; 5142611015cSTobias Jakobi else 5152611015cSTobias Jakobi goto fail; 5162611015cSTobias Jakobi } 5172611015cSTobias Jakobi 518d88d2463SGustavo Padovan if (plane->crtc_h != plane->src_h) { 519d88d2463SGustavo Padovan if (plane->crtc_h == 2 * plane->src_h) 5202611015cSTobias Jakobi *y_ratio = 1; 5212611015cSTobias Jakobi else 5222611015cSTobias Jakobi goto fail; 5232611015cSTobias Jakobi } 5242611015cSTobias Jakobi 5252611015cSTobias Jakobi return 0; 5262611015cSTobias Jakobi 5272611015cSTobias Jakobi fail: 5282611015cSTobias Jakobi DRM_DEBUG_KMS("only 2x width/height scaling of plane supported\n"); 5292611015cSTobias Jakobi return -ENOTSUPP; 5302611015cSTobias Jakobi } 5312611015cSTobias Jakobi 5322eeb2e5eSGustavo Padovan static void mixer_graph_buffer(struct mixer_context *ctx, 5332eeb2e5eSGustavo Padovan struct exynos_drm_plane *plane) 534d8408326SSeung-Woo Kim { 535d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 5362eeb2e5eSGustavo Padovan struct drm_plane_state *state = plane->base.state; 5372eeb2e5eSGustavo Padovan struct drm_framebuffer *fb = state->fb; 5382eeb2e5eSGustavo Padovan struct drm_display_mode *mode = &state->crtc->mode; 539d8408326SSeung-Woo Kim unsigned long flags; 5402eeb2e5eSGustavo Padovan unsigned int win = plane->zpos; 5412611015cSTobias Jakobi unsigned int x_ratio = 0, y_ratio = 0; 542d8408326SSeung-Woo Kim unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset; 543d8408326SSeung-Woo Kim dma_addr_t dma_addr; 544d8408326SSeung-Woo Kim unsigned int fmt; 545d8408326SSeung-Woo Kim u32 val; 546d8408326SSeung-Woo Kim 5472eeb2e5eSGustavo Padovan switch (fb->pixel_format) { 5487a57ca7cSTobias Jakobi case DRM_FORMAT_XRGB4444: 5497a57ca7cSTobias Jakobi fmt = MXR_FORMAT_ARGB4444; 5507a57ca7cSTobias Jakobi break; 551d8408326SSeung-Woo Kim 5527a57ca7cSTobias Jakobi case DRM_FORMAT_XRGB1555: 5537a57ca7cSTobias Jakobi fmt = MXR_FORMAT_ARGB1555; 554d8408326SSeung-Woo Kim break; 5557a57ca7cSTobias Jakobi 5567a57ca7cSTobias Jakobi case DRM_FORMAT_RGB565: 5577a57ca7cSTobias Jakobi fmt = MXR_FORMAT_RGB565; 558d8408326SSeung-Woo Kim break; 5597a57ca7cSTobias Jakobi 5607a57ca7cSTobias Jakobi case DRM_FORMAT_XRGB8888: 5617a57ca7cSTobias Jakobi case DRM_FORMAT_ARGB8888: 5627a57ca7cSTobias Jakobi fmt = MXR_FORMAT_ARGB8888; 5637a57ca7cSTobias Jakobi break; 5647a57ca7cSTobias Jakobi 565d8408326SSeung-Woo Kim default: 5667a57ca7cSTobias Jakobi DRM_DEBUG_KMS("pixelformat unsupported by mixer\n"); 5677a57ca7cSTobias Jakobi return; 568d8408326SSeung-Woo Kim } 569d8408326SSeung-Woo Kim 5702611015cSTobias Jakobi /* check if mixer supports requested scaling setup */ 5712611015cSTobias Jakobi if (mixer_setup_scale(plane, &x_ratio, &y_ratio)) 5722611015cSTobias Jakobi return; 573d8408326SSeung-Woo Kim 5747ee14cdcSGustavo Padovan dst_x_offset = plane->crtc_x; 5757ee14cdcSGustavo Padovan dst_y_offset = plane->crtc_y; 576d8408326SSeung-Woo Kim 577d8408326SSeung-Woo Kim /* converting dma address base and source offset */ 5787ee14cdcSGustavo Padovan dma_addr = plane->dma_addr[0] 5792eeb2e5eSGustavo Padovan + (plane->src_x * fb->bits_per_pixel >> 3) 5802eeb2e5eSGustavo Padovan + (plane->src_y * fb->pitches[0]); 581d8408326SSeung-Woo Kim src_x_offset = 0; 582d8408326SSeung-Woo Kim src_y_offset = 0; 583d8408326SSeung-Woo Kim 5842eeb2e5eSGustavo Padovan if (mode->flags & DRM_MODE_FLAG_INTERLACE) 585d8408326SSeung-Woo Kim ctx->interlace = true; 586d8408326SSeung-Woo Kim else 587d8408326SSeung-Woo Kim ctx->interlace = false; 588d8408326SSeung-Woo Kim 589d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 590d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, false); 591d8408326SSeung-Woo Kim 592d8408326SSeung-Woo Kim /* setup format */ 593d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win), 594d8408326SSeung-Woo Kim MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK); 595d8408326SSeung-Woo Kim 596d8408326SSeung-Woo Kim /* setup geometry */ 597adacb228SDaniel Stone mixer_reg_write(res, MXR_GRAPHIC_SPAN(win), 5982eeb2e5eSGustavo Padovan fb->pitches[0] / (fb->bits_per_pixel >> 3)); 599d8408326SSeung-Woo Kim 600def5e095SRahul Sharma /* setup display size */ 601def5e095SRahul Sharma if (ctx->mxr_ver == MXR_VER_128_0_0_184 && 6025d3d0995SGustavo Padovan win == DEFAULT_WIN) { 6032eeb2e5eSGustavo Padovan val = MXR_MXR_RES_HEIGHT(mode->vdisplay); 6042eeb2e5eSGustavo Padovan val |= MXR_MXR_RES_WIDTH(mode->hdisplay); 605def5e095SRahul Sharma mixer_reg_write(res, MXR_RESOLUTION, val); 606def5e095SRahul Sharma } 607def5e095SRahul Sharma 608d88d2463SGustavo Padovan val = MXR_GRP_WH_WIDTH(plane->src_w); 609d88d2463SGustavo Padovan val |= MXR_GRP_WH_HEIGHT(plane->src_h); 610d8408326SSeung-Woo Kim val |= MXR_GRP_WH_H_SCALE(x_ratio); 611d8408326SSeung-Woo Kim val |= MXR_GRP_WH_V_SCALE(y_ratio); 612d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_WH(win), val); 613d8408326SSeung-Woo Kim 614d8408326SSeung-Woo Kim /* setup offsets in source image */ 615d8408326SSeung-Woo Kim val = MXR_GRP_SXY_SX(src_x_offset); 616d8408326SSeung-Woo Kim val |= MXR_GRP_SXY_SY(src_y_offset); 617d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val); 618d8408326SSeung-Woo Kim 619d8408326SSeung-Woo Kim /* setup offsets in display image */ 620d8408326SSeung-Woo Kim val = MXR_GRP_DXY_DX(dst_x_offset); 621d8408326SSeung-Woo Kim val |= MXR_GRP_DXY_DY(dst_y_offset); 622d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val); 623d8408326SSeung-Woo Kim 624d8408326SSeung-Woo Kim /* set buffer address to mixer */ 625d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr); 626d8408326SSeung-Woo Kim 6272eeb2e5eSGustavo Padovan mixer_cfg_scan(ctx, mode->vdisplay); 6282eeb2e5eSGustavo Padovan mixer_cfg_rgb_fmt(ctx, mode->vdisplay); 629d8408326SSeung-Woo Kim mixer_cfg_layer(ctx, win, true); 630aaf8b49eSRahul Sharma 631aaf8b49eSRahul Sharma /* layer update mandatory for mixer 16.0.33.0 */ 632def5e095SRahul Sharma if (ctx->mxr_ver == MXR_VER_16_0_33_0 || 633def5e095SRahul Sharma ctx->mxr_ver == MXR_VER_128_0_0_184) 634aaf8b49eSRahul Sharma mixer_layer_update(ctx); 635aaf8b49eSRahul Sharma 636d8408326SSeung-Woo Kim mixer_run(ctx); 637d8408326SSeung-Woo Kim 638d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, true); 639d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 640c0734fbaSTobias Jakobi 641c0734fbaSTobias Jakobi mixer_regs_dump(ctx); 642d8408326SSeung-Woo Kim } 643d8408326SSeung-Woo Kim 644d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx) 645d8408326SSeung-Woo Kim { 646d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 647d8408326SSeung-Woo Kim int tries = 100; 648d8408326SSeung-Woo Kim 649d8408326SSeung-Woo Kim vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING); 650d8408326SSeung-Woo Kim for (tries = 100; tries; --tries) { 651d8408326SSeung-Woo Kim /* waiting until VP_SRESET_PROCESSING is 0 */ 652d8408326SSeung-Woo Kim if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING) 653d8408326SSeung-Woo Kim break; 65402b3de43STomasz Stanislawski mdelay(10); 655d8408326SSeung-Woo Kim } 656d8408326SSeung-Woo Kim WARN(tries == 0, "failed to reset Video Processor\n"); 657d8408326SSeung-Woo Kim } 658d8408326SSeung-Woo Kim 659cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx) 660cf8fc4f1SJoonyoung Shim { 661cf8fc4f1SJoonyoung Shim struct mixer_resources *res = &ctx->mixer_res; 662cf8fc4f1SJoonyoung Shim unsigned long flags; 663cf8fc4f1SJoonyoung Shim u32 val; /* value stored to register */ 664cf8fc4f1SJoonyoung Shim 665cf8fc4f1SJoonyoung Shim spin_lock_irqsave(&res->reg_slock, flags); 666cf8fc4f1SJoonyoung Shim mixer_vsync_set_update(ctx, false); 667cf8fc4f1SJoonyoung Shim 668cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK); 669cf8fc4f1SJoonyoung Shim 670cf8fc4f1SJoonyoung Shim /* set output in RGB888 mode */ 671cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK); 672cf8fc4f1SJoonyoung Shim 673cf8fc4f1SJoonyoung Shim /* 16 beat burst in DMA */ 674cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST, 675cf8fc4f1SJoonyoung Shim MXR_STATUS_BURST_MASK); 676cf8fc4f1SJoonyoung Shim 677cf8fc4f1SJoonyoung Shim /* setting default layer priority: layer1 > layer0 > video 678cf8fc4f1SJoonyoung Shim * because typical usage scenario would be 679cf8fc4f1SJoonyoung Shim * layer1 - OSD 680cf8fc4f1SJoonyoung Shim * layer0 - framebuffer 681cf8fc4f1SJoonyoung Shim * video - video overlay 682cf8fc4f1SJoonyoung Shim */ 683cf8fc4f1SJoonyoung Shim val = MXR_LAYER_CFG_GRP1_VAL(3); 684cf8fc4f1SJoonyoung Shim val |= MXR_LAYER_CFG_GRP0_VAL(2); 6851b8e5747SRahul Sharma if (ctx->vp_enabled) 686cf8fc4f1SJoonyoung Shim val |= MXR_LAYER_CFG_VP_VAL(1); 687cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_LAYER_CFG, val); 688cf8fc4f1SJoonyoung Shim 689cf8fc4f1SJoonyoung Shim /* setting background color */ 690cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_BG_COLOR0, 0x008080); 691cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_BG_COLOR1, 0x008080); 692cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_BG_COLOR2, 0x008080); 693cf8fc4f1SJoonyoung Shim 694cf8fc4f1SJoonyoung Shim /* setting graphical layers */ 695cf8fc4f1SJoonyoung Shim val = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */ 696cf8fc4f1SJoonyoung Shim val |= MXR_GRP_CFG_WIN_BLEND_EN; 697cf8fc4f1SJoonyoung Shim val |= MXR_GRP_CFG_ALPHA_VAL(0xff); /* non-transparent alpha */ 698cf8fc4f1SJoonyoung Shim 6990377f4edSSean Paul /* Don't blend layer 0 onto the mixer background */ 700cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_GRAPHIC_CFG(0), val); 7010377f4edSSean Paul 7020377f4edSSean Paul /* Blend layer 1 into layer 0 */ 7030377f4edSSean Paul val |= MXR_GRP_CFG_BLEND_PRE_MUL; 7040377f4edSSean Paul val |= MXR_GRP_CFG_PIXEL_BLEND_EN; 705cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_GRAPHIC_CFG(1), val); 706cf8fc4f1SJoonyoung Shim 7075736603bSSeung-Woo Kim /* setting video layers */ 7085736603bSSeung-Woo Kim val = MXR_GRP_CFG_ALPHA_VAL(0); 7095736603bSSeung-Woo Kim mixer_reg_write(res, MXR_VIDEO_CFG, val); 7105736603bSSeung-Woo Kim 7111b8e5747SRahul Sharma if (ctx->vp_enabled) { 712cf8fc4f1SJoonyoung Shim /* configuration of Video Processor Registers */ 713cf8fc4f1SJoonyoung Shim vp_win_reset(ctx); 714cf8fc4f1SJoonyoung Shim vp_default_filter(res); 7151b8e5747SRahul Sharma } 716cf8fc4f1SJoonyoung Shim 717cf8fc4f1SJoonyoung Shim /* disable all layers */ 718cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE); 719cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE); 7201b8e5747SRahul Sharma if (ctx->vp_enabled) 721cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE); 722cf8fc4f1SJoonyoung Shim 723cf8fc4f1SJoonyoung Shim mixer_vsync_set_update(ctx, true); 724cf8fc4f1SJoonyoung Shim spin_unlock_irqrestore(&res->reg_slock, flags); 725cf8fc4f1SJoonyoung Shim } 726cf8fc4f1SJoonyoung Shim 7274551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg) 7284551789fSSean Paul { 7294551789fSSean Paul struct mixer_context *ctx = arg; 7304551789fSSean Paul struct mixer_resources *res = &ctx->mixer_res; 7314551789fSSean Paul u32 val, base, shadow; 732822f6dfdSGustavo Padovan int win; 7334551789fSSean Paul 7344551789fSSean Paul spin_lock(&res->reg_slock); 7354551789fSSean Paul 7364551789fSSean Paul /* read interrupt status for handling and clearing flags for VSYNC */ 7374551789fSSean Paul val = mixer_reg_read(res, MXR_INT_STATUS); 7384551789fSSean Paul 7394551789fSSean Paul /* handling VSYNC */ 7404551789fSSean Paul if (val & MXR_INT_STATUS_VSYNC) { 74181a464dfSAndrzej Hajda /* vsync interrupt use different bit for read and clear */ 74281a464dfSAndrzej Hajda val |= MXR_INT_CLEAR_VSYNC; 74381a464dfSAndrzej Hajda val &= ~MXR_INT_STATUS_VSYNC; 74481a464dfSAndrzej Hajda 7454551789fSSean Paul /* interlace scan need to check shadow register */ 7464551789fSSean Paul if (ctx->interlace) { 7474551789fSSean Paul base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0)); 7484551789fSSean Paul shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0)); 7494551789fSSean Paul if (base != shadow) 7504551789fSSean Paul goto out; 7514551789fSSean Paul 7524551789fSSean Paul base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1)); 7534551789fSSean Paul shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1)); 7544551789fSSean Paul if (base != shadow) 7554551789fSSean Paul goto out; 7564551789fSSean Paul } 7574551789fSSean Paul 758eafd540aSGustavo Padovan drm_crtc_handle_vblank(&ctx->crtc->base); 759822f6dfdSGustavo Padovan for (win = 0 ; win < MIXER_WIN_NR ; win++) { 760822f6dfdSGustavo Padovan struct exynos_drm_plane *plane = &ctx->planes[win]; 761822f6dfdSGustavo Padovan 762822f6dfdSGustavo Padovan if (!plane->pending_fb) 763822f6dfdSGustavo Padovan continue; 764822f6dfdSGustavo Padovan 765822f6dfdSGustavo Padovan exynos_drm_crtc_finish_update(ctx->crtc, plane); 766822f6dfdSGustavo Padovan } 7674551789fSSean Paul 7684551789fSSean Paul /* set wait vsync event to zero and wake up queue. */ 7694551789fSSean Paul if (atomic_read(&ctx->wait_vsync_event)) { 7704551789fSSean Paul atomic_set(&ctx->wait_vsync_event, 0); 7714551789fSSean Paul wake_up(&ctx->wait_vsync_queue); 7724551789fSSean Paul } 7734551789fSSean Paul } 7744551789fSSean Paul 7754551789fSSean Paul out: 7764551789fSSean Paul /* clear interrupts */ 7774551789fSSean Paul mixer_reg_write(res, MXR_INT_STATUS, val); 7784551789fSSean Paul 7794551789fSSean Paul spin_unlock(&res->reg_slock); 7804551789fSSean Paul 7814551789fSSean Paul return IRQ_HANDLED; 7824551789fSSean Paul } 7834551789fSSean Paul 7844551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx) 7854551789fSSean Paul { 7864551789fSSean Paul struct device *dev = &mixer_ctx->pdev->dev; 7874551789fSSean Paul struct mixer_resources *mixer_res = &mixer_ctx->mixer_res; 7884551789fSSean Paul struct resource *res; 7894551789fSSean Paul int ret; 7904551789fSSean Paul 7914551789fSSean Paul spin_lock_init(&mixer_res->reg_slock); 7924551789fSSean Paul 7934551789fSSean Paul mixer_res->mixer = devm_clk_get(dev, "mixer"); 7944551789fSSean Paul if (IS_ERR(mixer_res->mixer)) { 7954551789fSSean Paul dev_err(dev, "failed to get clock 'mixer'\n"); 7964551789fSSean Paul return -ENODEV; 7974551789fSSean Paul } 7984551789fSSean Paul 79904427ec5SMarek Szyprowski mixer_res->hdmi = devm_clk_get(dev, "hdmi"); 80004427ec5SMarek Szyprowski if (IS_ERR(mixer_res->hdmi)) { 80104427ec5SMarek Szyprowski dev_err(dev, "failed to get clock 'hdmi'\n"); 80204427ec5SMarek Szyprowski return PTR_ERR(mixer_res->hdmi); 80304427ec5SMarek Szyprowski } 80404427ec5SMarek Szyprowski 8054551789fSSean Paul mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi"); 8064551789fSSean Paul if (IS_ERR(mixer_res->sclk_hdmi)) { 8074551789fSSean Paul dev_err(dev, "failed to get clock 'sclk_hdmi'\n"); 8084551789fSSean Paul return -ENODEV; 8094551789fSSean Paul } 8104551789fSSean Paul res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0); 8114551789fSSean Paul if (res == NULL) { 8124551789fSSean Paul dev_err(dev, "get memory resource failed.\n"); 8134551789fSSean Paul return -ENXIO; 8144551789fSSean Paul } 8154551789fSSean Paul 8164551789fSSean Paul mixer_res->mixer_regs = devm_ioremap(dev, res->start, 8174551789fSSean Paul resource_size(res)); 8184551789fSSean Paul if (mixer_res->mixer_regs == NULL) { 8194551789fSSean Paul dev_err(dev, "register mapping failed.\n"); 8204551789fSSean Paul return -ENXIO; 8214551789fSSean Paul } 8224551789fSSean Paul 8234551789fSSean Paul res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0); 8244551789fSSean Paul if (res == NULL) { 8254551789fSSean Paul dev_err(dev, "get interrupt resource failed.\n"); 8264551789fSSean Paul return -ENXIO; 8274551789fSSean Paul } 8284551789fSSean Paul 8294551789fSSean Paul ret = devm_request_irq(dev, res->start, mixer_irq_handler, 8304551789fSSean Paul 0, "drm_mixer", mixer_ctx); 8314551789fSSean Paul if (ret) { 8324551789fSSean Paul dev_err(dev, "request interrupt failed.\n"); 8334551789fSSean Paul return ret; 8344551789fSSean Paul } 8354551789fSSean Paul mixer_res->irq = res->start; 8364551789fSSean Paul 8374551789fSSean Paul return 0; 8384551789fSSean Paul } 8394551789fSSean Paul 8404551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx) 8414551789fSSean Paul { 8424551789fSSean Paul struct device *dev = &mixer_ctx->pdev->dev; 8434551789fSSean Paul struct mixer_resources *mixer_res = &mixer_ctx->mixer_res; 8444551789fSSean Paul struct resource *res; 8454551789fSSean Paul 8464551789fSSean Paul mixer_res->vp = devm_clk_get(dev, "vp"); 8474551789fSSean Paul if (IS_ERR(mixer_res->vp)) { 8484551789fSSean Paul dev_err(dev, "failed to get clock 'vp'\n"); 8494551789fSSean Paul return -ENODEV; 8504551789fSSean Paul } 851ff830c96SMarek Szyprowski 852ff830c96SMarek Szyprowski if (mixer_ctx->has_sclk) { 8534551789fSSean Paul mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer"); 8544551789fSSean Paul if (IS_ERR(mixer_res->sclk_mixer)) { 8554551789fSSean Paul dev_err(dev, "failed to get clock 'sclk_mixer'\n"); 8564551789fSSean Paul return -ENODEV; 8574551789fSSean Paul } 858ff830c96SMarek Szyprowski mixer_res->mout_mixer = devm_clk_get(dev, "mout_mixer"); 859ff830c96SMarek Szyprowski if (IS_ERR(mixer_res->mout_mixer)) { 860ff830c96SMarek Szyprowski dev_err(dev, "failed to get clock 'mout_mixer'\n"); 8614551789fSSean Paul return -ENODEV; 8624551789fSSean Paul } 8634551789fSSean Paul 864ff830c96SMarek Szyprowski if (mixer_res->sclk_hdmi && mixer_res->mout_mixer) 865ff830c96SMarek Szyprowski clk_set_parent(mixer_res->mout_mixer, 866ff830c96SMarek Szyprowski mixer_res->sclk_hdmi); 867ff830c96SMarek Szyprowski } 8684551789fSSean Paul 8694551789fSSean Paul res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1); 8704551789fSSean Paul if (res == NULL) { 8714551789fSSean Paul dev_err(dev, "get memory resource failed.\n"); 8724551789fSSean Paul return -ENXIO; 8734551789fSSean Paul } 8744551789fSSean Paul 8754551789fSSean Paul mixer_res->vp_regs = devm_ioremap(dev, res->start, 8764551789fSSean Paul resource_size(res)); 8774551789fSSean Paul if (mixer_res->vp_regs == NULL) { 8784551789fSSean Paul dev_err(dev, "register mapping failed.\n"); 8794551789fSSean Paul return -ENXIO; 8804551789fSSean Paul } 8814551789fSSean Paul 8824551789fSSean Paul return 0; 8834551789fSSean Paul } 8844551789fSSean Paul 88593bca243SGustavo Padovan static int mixer_initialize(struct mixer_context *mixer_ctx, 886f37cd5e8SInki Dae struct drm_device *drm_dev) 8874551789fSSean Paul { 8884551789fSSean Paul int ret; 889f37cd5e8SInki Dae struct exynos_drm_private *priv; 890f37cd5e8SInki Dae priv = drm_dev->dev_private; 8914551789fSSean Paul 892eb88e422SGustavo Padovan mixer_ctx->drm_dev = drm_dev; 8938a326eddSGustavo Padovan mixer_ctx->pipe = priv->pipe++; 8944551789fSSean Paul 8954551789fSSean Paul /* acquire resources: regs, irqs, clocks */ 8964551789fSSean Paul ret = mixer_resources_init(mixer_ctx); 8974551789fSSean Paul if (ret) { 8984551789fSSean Paul DRM_ERROR("mixer_resources_init failed ret=%d\n", ret); 8994551789fSSean Paul return ret; 9004551789fSSean Paul } 9014551789fSSean Paul 9024551789fSSean Paul if (mixer_ctx->vp_enabled) { 9034551789fSSean Paul /* acquire vp resources: regs, irqs, clocks */ 9044551789fSSean Paul ret = vp_resources_init(mixer_ctx); 9054551789fSSean Paul if (ret) { 9064551789fSSean Paul DRM_ERROR("vp_resources_init failed ret=%d\n", ret); 9074551789fSSean Paul return ret; 9084551789fSSean Paul } 9094551789fSSean Paul } 9104551789fSSean Paul 911eb7a3fc7SJoonyoung Shim ret = drm_iommu_attach_device(drm_dev, mixer_ctx->dev); 912fc2e013fSHyungwon Hwang if (ret) 913fc2e013fSHyungwon Hwang priv->pipe--; 914f041b257SSean Paul 915fc2e013fSHyungwon Hwang return ret; 9161055b39fSInki Dae } 9171055b39fSInki Dae 91893bca243SGustavo Padovan static void mixer_ctx_remove(struct mixer_context *mixer_ctx) 919d8408326SSeung-Woo Kim { 920f041b257SSean Paul drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev); 921f041b257SSean Paul } 922f041b257SSean Paul 92393bca243SGustavo Padovan static int mixer_enable_vblank(struct exynos_drm_crtc *crtc) 924f041b257SSean Paul { 92593bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx; 926d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 927d8408326SSeung-Woo Kim 9280df5e4acSAndrzej Hajda __set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags); 9290df5e4acSAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 930f041b257SSean Paul return 0; 931d8408326SSeung-Woo Kim 932d8408326SSeung-Woo Kim /* enable vsync interrupt */ 933fc073248SAndrzej Hajda mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC); 934fc073248SAndrzej Hajda mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC); 935d8408326SSeung-Woo Kim 936d8408326SSeung-Woo Kim return 0; 937d8408326SSeung-Woo Kim } 938d8408326SSeung-Woo Kim 93993bca243SGustavo Padovan static void mixer_disable_vblank(struct exynos_drm_crtc *crtc) 940d8408326SSeung-Woo Kim { 94193bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx; 942d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 943d8408326SSeung-Woo Kim 9440df5e4acSAndrzej Hajda __clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags); 9450df5e4acSAndrzej Hajda 9460df5e4acSAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 947947710c6SAndrzej Hajda return; 948947710c6SAndrzej Hajda 949d8408326SSeung-Woo Kim /* disable vsync interrupt */ 950fc073248SAndrzej Hajda mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC); 951d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC); 952d8408326SSeung-Woo Kim } 953d8408326SSeung-Woo Kim 9541e1d1393SGustavo Padovan static void mixer_update_plane(struct exynos_drm_crtc *crtc, 9551e1d1393SGustavo Padovan struct exynos_drm_plane *plane) 956d8408326SSeung-Woo Kim { 95793bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx; 958d8408326SSeung-Woo Kim 9591e1d1393SGustavo Padovan DRM_DEBUG_KMS("win: %d\n", plane->zpos); 960d8408326SSeung-Woo Kim 961a44652e8SAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 962dda9012bSShirish S return; 963dda9012bSShirish S 9641e1d1393SGustavo Padovan if (plane->zpos > 1 && mixer_ctx->vp_enabled) 9652eeb2e5eSGustavo Padovan vp_video_buffer(mixer_ctx, plane); 966d8408326SSeung-Woo Kim else 9672eeb2e5eSGustavo Padovan mixer_graph_buffer(mixer_ctx, plane); 968d8408326SSeung-Woo Kim } 969d8408326SSeung-Woo Kim 9701e1d1393SGustavo Padovan static void mixer_disable_plane(struct exynos_drm_crtc *crtc, 9711e1d1393SGustavo Padovan struct exynos_drm_plane *plane) 972d8408326SSeung-Woo Kim { 97393bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx; 974d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 975d8408326SSeung-Woo Kim unsigned long flags; 976d8408326SSeung-Woo Kim 9771e1d1393SGustavo Padovan DRM_DEBUG_KMS("win: %d\n", plane->zpos); 978d8408326SSeung-Woo Kim 979a44652e8SAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 980db43fd16SPrathyush K return; 981db43fd16SPrathyush K 982d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 983d8408326SSeung-Woo Kim mixer_vsync_set_update(mixer_ctx, false); 984d8408326SSeung-Woo Kim 9851e1d1393SGustavo Padovan mixer_cfg_layer(mixer_ctx, plane->zpos, false); 986d8408326SSeung-Woo Kim 987d8408326SSeung-Woo Kim mixer_vsync_set_update(mixer_ctx, true); 988d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 989d8408326SSeung-Woo Kim } 990d8408326SSeung-Woo Kim 99193bca243SGustavo Padovan static void mixer_wait_for_vblank(struct exynos_drm_crtc *crtc) 9920ea6822fSRahul Sharma { 99393bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx; 9947c4c5584SJoonyoung Shim int err; 9958137a2e2SPrathyush K 996a44652e8SAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 9976e95d5e6SPrathyush K return; 9986e95d5e6SPrathyush K 99993bca243SGustavo Padovan err = drm_vblank_get(mixer_ctx->drm_dev, mixer_ctx->pipe); 10007c4c5584SJoonyoung Shim if (err < 0) { 10017c4c5584SJoonyoung Shim DRM_DEBUG_KMS("failed to acquire vblank counter\n"); 10027c4c5584SJoonyoung Shim return; 10037c4c5584SJoonyoung Shim } 10045d39b9eeSRahul Sharma 10056e95d5e6SPrathyush K atomic_set(&mixer_ctx->wait_vsync_event, 1); 10066e95d5e6SPrathyush K 10076e95d5e6SPrathyush K /* 10086e95d5e6SPrathyush K * wait for MIXER to signal VSYNC interrupt or return after 10096e95d5e6SPrathyush K * timeout which is set to 50ms (refresh rate of 20). 10106e95d5e6SPrathyush K */ 10116e95d5e6SPrathyush K if (!wait_event_timeout(mixer_ctx->wait_vsync_queue, 10126e95d5e6SPrathyush K !atomic_read(&mixer_ctx->wait_vsync_event), 1013bfd8303aSDaniel Vetter HZ/20)) 10148137a2e2SPrathyush K DRM_DEBUG_KMS("vblank wait timed out.\n"); 10155d39b9eeSRahul Sharma 101693bca243SGustavo Padovan drm_vblank_put(mixer_ctx->drm_dev, mixer_ctx->pipe); 10178137a2e2SPrathyush K } 10188137a2e2SPrathyush K 10193cecda03SGustavo Padovan static void mixer_enable(struct exynos_drm_crtc *crtc) 1020db43fd16SPrathyush K { 10213cecda03SGustavo Padovan struct mixer_context *ctx = crtc->ctx; 1022db43fd16SPrathyush K struct mixer_resources *res = &ctx->mixer_res; 1023db43fd16SPrathyush K 1024a44652e8SAndrzej Hajda if (test_bit(MXR_BIT_POWERED, &ctx->flags)) 1025db43fd16SPrathyush K return; 1026db43fd16SPrathyush K 1027af65c804SSean Paul pm_runtime_get_sync(ctx->dev); 1028af65c804SSean Paul 1029d74ed937SRahul Sharma mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET); 1030d74ed937SRahul Sharma 10310df5e4acSAndrzej Hajda if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) { 1032fc073248SAndrzej Hajda mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC); 10330df5e4acSAndrzej Hajda mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC); 10340df5e4acSAndrzej Hajda } 1035db43fd16SPrathyush K mixer_win_reset(ctx); 1036*ccf034a9SGustavo Padovan 1037*ccf034a9SGustavo Padovan set_bit(MXR_BIT_POWERED, &ctx->flags); 1038db43fd16SPrathyush K } 1039db43fd16SPrathyush K 10403cecda03SGustavo Padovan static void mixer_disable(struct exynos_drm_crtc *crtc) 1041db43fd16SPrathyush K { 10423cecda03SGustavo Padovan struct mixer_context *ctx = crtc->ctx; 1043c329f667SJoonyoung Shim int i; 1044db43fd16SPrathyush K 1045a44652e8SAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &ctx->flags)) 1046b4bfa3c7SRahul Sharma return; 1047db43fd16SPrathyush K 1048381be025SRahul Sharma mixer_stop(ctx); 1049c0734fbaSTobias Jakobi mixer_regs_dump(ctx); 1050c329f667SJoonyoung Shim 1051c329f667SJoonyoung Shim for (i = 0; i < MIXER_WIN_NR; i++) 10521e1d1393SGustavo Padovan mixer_disable_plane(crtc, &ctx->planes[i]); 1053db43fd16SPrathyush K 1054*ccf034a9SGustavo Padovan pm_runtime_put(ctx->dev); 1055*ccf034a9SGustavo Padovan 1056a44652e8SAndrzej Hajda clear_bit(MXR_BIT_POWERED, &ctx->flags); 1057db43fd16SPrathyush K } 1058db43fd16SPrathyush K 1059f041b257SSean Paul /* Only valid for Mixer version 16.0.33.0 */ 10603ae24362SAndrzej Hajda static int mixer_atomic_check(struct exynos_drm_crtc *crtc, 10613ae24362SAndrzej Hajda struct drm_crtc_state *state) 1062f041b257SSean Paul { 10633ae24362SAndrzej Hajda struct drm_display_mode *mode = &state->adjusted_mode; 1064f041b257SSean Paul u32 w, h; 1065f041b257SSean Paul 1066f041b257SSean Paul w = mode->hdisplay; 1067f041b257SSean Paul h = mode->vdisplay; 1068f041b257SSean Paul 1069f041b257SSean Paul DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n", 1070f041b257SSean Paul mode->hdisplay, mode->vdisplay, mode->vrefresh, 1071f041b257SSean Paul (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0); 1072f041b257SSean Paul 1073f041b257SSean Paul if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) || 1074f041b257SSean Paul (w >= 1024 && w <= 1280 && h >= 576 && h <= 720) || 1075f041b257SSean Paul (w >= 1664 && w <= 1920 && h >= 936 && h <= 1080)) 1076f041b257SSean Paul return 0; 1077f041b257SSean Paul 1078f041b257SSean Paul return -EINVAL; 1079f041b257SSean Paul } 1080f041b257SSean Paul 1081f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops mixer_crtc_ops = { 10823cecda03SGustavo Padovan .enable = mixer_enable, 10833cecda03SGustavo Padovan .disable = mixer_disable, 1084d8408326SSeung-Woo Kim .enable_vblank = mixer_enable_vblank, 1085d8408326SSeung-Woo Kim .disable_vblank = mixer_disable_vblank, 10868137a2e2SPrathyush K .wait_for_vblank = mixer_wait_for_vblank, 10879cc7610aSGustavo Padovan .update_plane = mixer_update_plane, 10889cc7610aSGustavo Padovan .disable_plane = mixer_disable_plane, 10893ae24362SAndrzej Hajda .atomic_check = mixer_atomic_check, 1090f041b257SSean Paul }; 10910ea6822fSRahul Sharma 1092def5e095SRahul Sharma static struct mixer_drv_data exynos5420_mxr_drv_data = { 1093def5e095SRahul Sharma .version = MXR_VER_128_0_0_184, 1094def5e095SRahul Sharma .is_vp_enabled = 0, 1095def5e095SRahul Sharma }; 1096def5e095SRahul Sharma 1097cc57caf0SRahul Sharma static struct mixer_drv_data exynos5250_mxr_drv_data = { 1098aaf8b49eSRahul Sharma .version = MXR_VER_16_0_33_0, 1099aaf8b49eSRahul Sharma .is_vp_enabled = 0, 1100aaf8b49eSRahul Sharma }; 1101aaf8b49eSRahul Sharma 1102ff830c96SMarek Szyprowski static struct mixer_drv_data exynos4212_mxr_drv_data = { 1103ff830c96SMarek Szyprowski .version = MXR_VER_0_0_0_16, 1104ff830c96SMarek Szyprowski .is_vp_enabled = 1, 1105ff830c96SMarek Szyprowski }; 1106ff830c96SMarek Szyprowski 1107cc57caf0SRahul Sharma static struct mixer_drv_data exynos4210_mxr_drv_data = { 11081e123441SRahul Sharma .version = MXR_VER_0_0_0_16, 11091b8e5747SRahul Sharma .is_vp_enabled = 1, 1110ff830c96SMarek Szyprowski .has_sclk = 1, 11111e123441SRahul Sharma }; 11121e123441SRahul Sharma 1113d6b16302SKrzysztof Kozlowski static const struct platform_device_id mixer_driver_types[] = { 11141e123441SRahul Sharma { 11151e123441SRahul Sharma .name = "s5p-mixer", 1116cc57caf0SRahul Sharma .driver_data = (unsigned long)&exynos4210_mxr_drv_data, 11171e123441SRahul Sharma }, { 1118aaf8b49eSRahul Sharma .name = "exynos5-mixer", 1119cc57caf0SRahul Sharma .driver_data = (unsigned long)&exynos5250_mxr_drv_data, 1120aaf8b49eSRahul Sharma }, { 1121aaf8b49eSRahul Sharma /* end node */ 1122aaf8b49eSRahul Sharma } 1123aaf8b49eSRahul Sharma }; 1124aaf8b49eSRahul Sharma 1125aaf8b49eSRahul Sharma static struct of_device_id mixer_match_types[] = { 1126aaf8b49eSRahul Sharma { 1127ff830c96SMarek Szyprowski .compatible = "samsung,exynos4210-mixer", 1128ff830c96SMarek Szyprowski .data = &exynos4210_mxr_drv_data, 1129ff830c96SMarek Szyprowski }, { 1130ff830c96SMarek Szyprowski .compatible = "samsung,exynos4212-mixer", 1131ff830c96SMarek Szyprowski .data = &exynos4212_mxr_drv_data, 1132ff830c96SMarek Szyprowski }, { 1133aaf8b49eSRahul Sharma .compatible = "samsung,exynos5-mixer", 1134cc57caf0SRahul Sharma .data = &exynos5250_mxr_drv_data, 1135cc57caf0SRahul Sharma }, { 1136cc57caf0SRahul Sharma .compatible = "samsung,exynos5250-mixer", 1137cc57caf0SRahul Sharma .data = &exynos5250_mxr_drv_data, 1138aaf8b49eSRahul Sharma }, { 1139def5e095SRahul Sharma .compatible = "samsung,exynos5420-mixer", 1140def5e095SRahul Sharma .data = &exynos5420_mxr_drv_data, 1141def5e095SRahul Sharma }, { 11421e123441SRahul Sharma /* end node */ 11431e123441SRahul Sharma } 11441e123441SRahul Sharma }; 114539b58a39SSjoerd Simons MODULE_DEVICE_TABLE(of, mixer_match_types); 11461e123441SRahul Sharma 1147f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data) 1148d8408326SSeung-Woo Kim { 11498103ef1bSAndrzej Hajda struct mixer_context *ctx = dev_get_drvdata(dev); 1150f37cd5e8SInki Dae struct drm_device *drm_dev = data; 11517ee14cdcSGustavo Padovan struct exynos_drm_plane *exynos_plane; 11526e2a3b66SGustavo Padovan unsigned int zpos; 11536e2a3b66SGustavo Padovan int ret; 1154d8408326SSeung-Woo Kim 1155e2dc3f72SAlban Browaeys ret = mixer_initialize(ctx, drm_dev); 1156e2dc3f72SAlban Browaeys if (ret) 1157e2dc3f72SAlban Browaeys return ret; 1158e2dc3f72SAlban Browaeys 11597ee14cdcSGustavo Padovan for (zpos = 0; zpos < MIXER_WIN_NR; zpos++) { 1160fbbb1e1aSMarek Szyprowski enum drm_plane_type type; 1161fbbb1e1aSMarek Szyprowski const uint32_t *formats; 1162fbbb1e1aSMarek Szyprowski unsigned int fcount; 1163fbbb1e1aSMarek Szyprowski 1164fbbb1e1aSMarek Szyprowski if (zpos < VP_DEFAULT_WIN) { 1165fbbb1e1aSMarek Szyprowski formats = mixer_formats; 1166fbbb1e1aSMarek Szyprowski fcount = ARRAY_SIZE(mixer_formats); 1167fbbb1e1aSMarek Szyprowski } else { 1168fbbb1e1aSMarek Szyprowski formats = vp_formats; 1169fbbb1e1aSMarek Szyprowski fcount = ARRAY_SIZE(vp_formats); 1170fbbb1e1aSMarek Szyprowski } 1171fbbb1e1aSMarek Szyprowski 1172323db0edSGustavo Padovan type = exynos_plane_get_type(zpos, CURSOR_WIN); 11737ee14cdcSGustavo Padovan ret = exynos_plane_init(drm_dev, &ctx->planes[zpos], 1174fbbb1e1aSMarek Szyprowski 1 << ctx->pipe, type, formats, fcount, 1175fbbb1e1aSMarek Szyprowski zpos); 11767ee14cdcSGustavo Padovan if (ret) 11777ee14cdcSGustavo Padovan return ret; 11787ee14cdcSGustavo Padovan } 11797ee14cdcSGustavo Padovan 11805d3d0995SGustavo Padovan exynos_plane = &ctx->planes[DEFAULT_WIN]; 11817ee14cdcSGustavo Padovan ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, 11827ee14cdcSGustavo Padovan ctx->pipe, EXYNOS_DISPLAY_TYPE_HDMI, 118393bca243SGustavo Padovan &mixer_crtc_ops, ctx); 118493bca243SGustavo Padovan if (IS_ERR(ctx->crtc)) { 1185e2dc3f72SAlban Browaeys mixer_ctx_remove(ctx); 118693bca243SGustavo Padovan ret = PTR_ERR(ctx->crtc); 118793bca243SGustavo Padovan goto free_ctx; 11888103ef1bSAndrzej Hajda } 11898103ef1bSAndrzej Hajda 11908103ef1bSAndrzej Hajda return 0; 119193bca243SGustavo Padovan 119293bca243SGustavo Padovan free_ctx: 119393bca243SGustavo Padovan devm_kfree(dev, ctx); 119493bca243SGustavo Padovan return ret; 11958103ef1bSAndrzej Hajda } 11968103ef1bSAndrzej Hajda 11978103ef1bSAndrzej Hajda static void mixer_unbind(struct device *dev, struct device *master, void *data) 11988103ef1bSAndrzej Hajda { 11998103ef1bSAndrzej Hajda struct mixer_context *ctx = dev_get_drvdata(dev); 12008103ef1bSAndrzej Hajda 120193bca243SGustavo Padovan mixer_ctx_remove(ctx); 12028103ef1bSAndrzej Hajda } 12038103ef1bSAndrzej Hajda 12048103ef1bSAndrzej Hajda static const struct component_ops mixer_component_ops = { 12058103ef1bSAndrzej Hajda .bind = mixer_bind, 12068103ef1bSAndrzej Hajda .unbind = mixer_unbind, 12078103ef1bSAndrzej Hajda }; 12088103ef1bSAndrzej Hajda 12098103ef1bSAndrzej Hajda static int mixer_probe(struct platform_device *pdev) 12108103ef1bSAndrzej Hajda { 12118103ef1bSAndrzej Hajda struct device *dev = &pdev->dev; 12128103ef1bSAndrzej Hajda struct mixer_drv_data *drv; 12138103ef1bSAndrzej Hajda struct mixer_context *ctx; 12148103ef1bSAndrzej Hajda int ret; 1215d8408326SSeung-Woo Kim 1216f041b257SSean Paul ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 1217f041b257SSean Paul if (!ctx) { 1218f041b257SSean Paul DRM_ERROR("failed to alloc mixer context.\n"); 1219d8408326SSeung-Woo Kim return -ENOMEM; 1220f041b257SSean Paul } 1221d8408326SSeung-Woo Kim 1222aaf8b49eSRahul Sharma if (dev->of_node) { 1223aaf8b49eSRahul Sharma const struct of_device_id *match; 12248103ef1bSAndrzej Hajda 1225e436b09dSSachin Kamat match = of_match_node(mixer_match_types, dev->of_node); 12262cdc53b3SRahul Sharma drv = (struct mixer_drv_data *)match->data; 1227aaf8b49eSRahul Sharma } else { 1228aaf8b49eSRahul Sharma drv = (struct mixer_drv_data *) 1229aaf8b49eSRahul Sharma platform_get_device_id(pdev)->driver_data; 1230aaf8b49eSRahul Sharma } 1231aaf8b49eSRahul Sharma 12324551789fSSean Paul ctx->pdev = pdev; 1233d873ab99SSeung-Woo Kim ctx->dev = dev; 12341b8e5747SRahul Sharma ctx->vp_enabled = drv->is_vp_enabled; 1235ff830c96SMarek Szyprowski ctx->has_sclk = drv->has_sclk; 12361e123441SRahul Sharma ctx->mxr_ver = drv->version; 123757ed0f7bSDaniel Vetter init_waitqueue_head(&ctx->wait_vsync_queue); 12386e95d5e6SPrathyush K atomic_set(&ctx->wait_vsync_event, 0); 1239d8408326SSeung-Woo Kim 12408103ef1bSAndrzej Hajda platform_set_drvdata(pdev, ctx); 1241df5225bcSInki Dae 1242df5225bcSInki Dae ret = component_add(&pdev->dev, &mixer_component_ops); 124386650408SAndrzej Hajda if (!ret) 12448103ef1bSAndrzej Hajda pm_runtime_enable(dev); 1245df5225bcSInki Dae 1246df5225bcSInki Dae return ret; 1247f37cd5e8SInki Dae } 1248f37cd5e8SInki Dae 1249d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev) 1250d8408326SSeung-Woo Kim { 12518103ef1bSAndrzej Hajda pm_runtime_disable(&pdev->dev); 12528103ef1bSAndrzej Hajda 1253df5225bcSInki Dae component_del(&pdev->dev, &mixer_component_ops); 1254df5225bcSInki Dae 1255d8408326SSeung-Woo Kim return 0; 1256d8408326SSeung-Woo Kim } 1257d8408326SSeung-Woo Kim 1258*ccf034a9SGustavo Padovan #ifdef CONFIG_PM_SLEEP 1259*ccf034a9SGustavo Padovan static int exynos_mixer_suspend(struct device *dev) 1260*ccf034a9SGustavo Padovan { 1261*ccf034a9SGustavo Padovan struct mixer_context *ctx = dev_get_drvdata(dev); 1262*ccf034a9SGustavo Padovan struct mixer_resources *res = &ctx->mixer_res; 1263*ccf034a9SGustavo Padovan 1264*ccf034a9SGustavo Padovan clk_disable_unprepare(res->hdmi); 1265*ccf034a9SGustavo Padovan clk_disable_unprepare(res->mixer); 1266*ccf034a9SGustavo Padovan if (ctx->vp_enabled) { 1267*ccf034a9SGustavo Padovan clk_disable_unprepare(res->vp); 1268*ccf034a9SGustavo Padovan if (ctx->has_sclk) 1269*ccf034a9SGustavo Padovan clk_disable_unprepare(res->sclk_mixer); 1270*ccf034a9SGustavo Padovan } 1271*ccf034a9SGustavo Padovan 1272*ccf034a9SGustavo Padovan return 0; 1273*ccf034a9SGustavo Padovan } 1274*ccf034a9SGustavo Padovan 1275*ccf034a9SGustavo Padovan static int exynos_mixer_resume(struct device *dev) 1276*ccf034a9SGustavo Padovan { 1277*ccf034a9SGustavo Padovan struct mixer_context *ctx = dev_get_drvdata(dev); 1278*ccf034a9SGustavo Padovan struct mixer_resources *res = &ctx->mixer_res; 1279*ccf034a9SGustavo Padovan int ret; 1280*ccf034a9SGustavo Padovan 1281*ccf034a9SGustavo Padovan ret = clk_prepare_enable(res->mixer); 1282*ccf034a9SGustavo Padovan if (ret < 0) { 1283*ccf034a9SGustavo Padovan DRM_ERROR("Failed to prepare_enable the mixer clk [%d]\n", ret); 1284*ccf034a9SGustavo Padovan return ret; 1285*ccf034a9SGustavo Padovan } 1286*ccf034a9SGustavo Padovan ret = clk_prepare_enable(res->hdmi); 1287*ccf034a9SGustavo Padovan if (ret < 0) { 1288*ccf034a9SGustavo Padovan DRM_ERROR("Failed to prepare_enable the hdmi clk [%d]\n", ret); 1289*ccf034a9SGustavo Padovan return ret; 1290*ccf034a9SGustavo Padovan } 1291*ccf034a9SGustavo Padovan if (ctx->vp_enabled) { 1292*ccf034a9SGustavo Padovan ret = clk_prepare_enable(res->vp); 1293*ccf034a9SGustavo Padovan if (ret < 0) { 1294*ccf034a9SGustavo Padovan DRM_ERROR("Failed to prepare_enable the vp clk [%d]\n", 1295*ccf034a9SGustavo Padovan ret); 1296*ccf034a9SGustavo Padovan return ret; 1297*ccf034a9SGustavo Padovan } 1298*ccf034a9SGustavo Padovan if (ctx->has_sclk) { 1299*ccf034a9SGustavo Padovan ret = clk_prepare_enable(res->sclk_mixer); 1300*ccf034a9SGustavo Padovan if (ret < 0) { 1301*ccf034a9SGustavo Padovan DRM_ERROR("Failed to prepare_enable the " \ 1302*ccf034a9SGustavo Padovan "sclk_mixer clk [%d]\n", 1303*ccf034a9SGustavo Padovan ret); 1304*ccf034a9SGustavo Padovan return ret; 1305*ccf034a9SGustavo Padovan } 1306*ccf034a9SGustavo Padovan } 1307*ccf034a9SGustavo Padovan } 1308*ccf034a9SGustavo Padovan 1309*ccf034a9SGustavo Padovan return 0; 1310*ccf034a9SGustavo Padovan } 1311*ccf034a9SGustavo Padovan #endif 1312*ccf034a9SGustavo Padovan 1313*ccf034a9SGustavo Padovan static const struct dev_pm_ops exynos_mixer_pm_ops = { 1314*ccf034a9SGustavo Padovan SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL) 1315*ccf034a9SGustavo Padovan }; 1316*ccf034a9SGustavo Padovan 1317d8408326SSeung-Woo Kim struct platform_driver mixer_driver = { 1318d8408326SSeung-Woo Kim .driver = { 1319aaf8b49eSRahul Sharma .name = "exynos-mixer", 1320d8408326SSeung-Woo Kim .owner = THIS_MODULE, 1321*ccf034a9SGustavo Padovan .pm = &exynos_mixer_pm_ops, 1322aaf8b49eSRahul Sharma .of_match_table = mixer_match_types, 1323d8408326SSeung-Woo Kim }, 1324d8408326SSeung-Woo Kim .probe = mixer_probe, 132556550d94SGreg Kroah-Hartman .remove = mixer_remove, 13261e123441SRahul Sharma .id_table = mixer_driver_types, 1327d8408326SSeung-Woo Kim }; 1328