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" 401055b39fSInki Dae #include "exynos_drm_iommu.h" 41f041b257SSean Paul #include "exynos_mixer.h" 4222b21ae6SJoonyoung Shim 43f041b257SSean Paul #define MIXER_WIN_NR 3 44f041b257SSean Paul #define MIXER_DEFAULT_WIN 0 45d8408326SSeung-Woo Kim 4622b21ae6SJoonyoung Shim struct hdmi_win_data { 4722b21ae6SJoonyoung Shim dma_addr_t dma_addr; 4822b21ae6SJoonyoung Shim dma_addr_t chroma_dma_addr; 4922b21ae6SJoonyoung Shim uint32_t pixel_format; 5022b21ae6SJoonyoung Shim unsigned int bpp; 5122b21ae6SJoonyoung Shim unsigned int crtc_x; 5222b21ae6SJoonyoung Shim unsigned int crtc_y; 5322b21ae6SJoonyoung Shim unsigned int crtc_width; 5422b21ae6SJoonyoung Shim unsigned int crtc_height; 5522b21ae6SJoonyoung Shim unsigned int fb_x; 5622b21ae6SJoonyoung Shim unsigned int fb_y; 5722b21ae6SJoonyoung Shim unsigned int fb_width; 5822b21ae6SJoonyoung Shim unsigned int fb_height; 598dcb96b6SSeung-Woo Kim unsigned int src_width; 608dcb96b6SSeung-Woo Kim unsigned int src_height; 6122b21ae6SJoonyoung Shim unsigned int mode_width; 6222b21ae6SJoonyoung Shim unsigned int mode_height; 6322b21ae6SJoonyoung Shim unsigned int scan_flags; 64db43fd16SPrathyush K bool enabled; 65db43fd16SPrathyush K bool resume; 6622b21ae6SJoonyoung Shim }; 6722b21ae6SJoonyoung Shim 6822b21ae6SJoonyoung Shim struct mixer_resources { 6922b21ae6SJoonyoung Shim int irq; 7022b21ae6SJoonyoung Shim void __iomem *mixer_regs; 7122b21ae6SJoonyoung Shim void __iomem *vp_regs; 7222b21ae6SJoonyoung Shim spinlock_t reg_slock; 7322b21ae6SJoonyoung Shim struct clk *mixer; 7422b21ae6SJoonyoung Shim struct clk *vp; 7522b21ae6SJoonyoung Shim struct clk *sclk_mixer; 7622b21ae6SJoonyoung Shim struct clk *sclk_hdmi; 77ff830c96SMarek Szyprowski struct clk *mout_mixer; 7822b21ae6SJoonyoung Shim }; 7922b21ae6SJoonyoung Shim 801e123441SRahul Sharma enum mixer_version_id { 811e123441SRahul Sharma MXR_VER_0_0_0_16, 821e123441SRahul Sharma MXR_VER_16_0_33_0, 83def5e095SRahul Sharma MXR_VER_128_0_0_184, 841e123441SRahul Sharma }; 851e123441SRahul Sharma 8622b21ae6SJoonyoung Shim struct mixer_context { 87*8103ef1bSAndrzej Hajda struct exynos_drm_manager manager; 884551789fSSean Paul struct platform_device *pdev; 89cf8fc4f1SJoonyoung Shim struct device *dev; 901055b39fSInki Dae struct drm_device *drm_dev; 9122b21ae6SJoonyoung Shim int pipe; 9222b21ae6SJoonyoung Shim bool interlace; 93cf8fc4f1SJoonyoung Shim bool powered; 941b8e5747SRahul Sharma bool vp_enabled; 95ff830c96SMarek Szyprowski bool has_sclk; 96cf8fc4f1SJoonyoung Shim u32 int_en; 9722b21ae6SJoonyoung Shim 98cf8fc4f1SJoonyoung Shim struct mutex mixer_mutex; 9922b21ae6SJoonyoung Shim struct mixer_resources mixer_res; 100a634dd54SJoonyoung Shim struct hdmi_win_data win_data[MIXER_WIN_NR]; 1011e123441SRahul Sharma enum mixer_version_id mxr_ver; 1026e95d5e6SPrathyush K wait_queue_head_t wait_vsync_queue; 1036e95d5e6SPrathyush K atomic_t wait_vsync_event; 1041e123441SRahul Sharma }; 1051e123441SRahul Sharma 1061e123441SRahul Sharma struct mixer_drv_data { 1071e123441SRahul Sharma enum mixer_version_id version; 1081b8e5747SRahul Sharma bool is_vp_enabled; 109ff830c96SMarek Szyprowski bool has_sclk; 11022b21ae6SJoonyoung Shim }; 11122b21ae6SJoonyoung Shim 112d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = { 113d8408326SSeung-Woo Kim 0, -1, -1, -1, -1, -1, -1, -1, 114d8408326SSeung-Woo Kim -1, -1, -1, -1, -1, 0, 0, 0, 115d8408326SSeung-Woo Kim 0, 2, 4, 5, 6, 6, 6, 6, 116d8408326SSeung-Woo Kim 6, 5, 5, 4, 3, 2, 1, 1, 117d8408326SSeung-Woo Kim 0, -6, -12, -16, -18, -20, -21, -20, 118d8408326SSeung-Woo Kim -20, -18, -16, -13, -10, -8, -5, -2, 119d8408326SSeung-Woo Kim 127, 126, 125, 121, 114, 107, 99, 89, 120d8408326SSeung-Woo Kim 79, 68, 57, 46, 35, 25, 16, 8, 121d8408326SSeung-Woo Kim }; 122d8408326SSeung-Woo Kim 123d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = { 124d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7, 125d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0, 126d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81, 127d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5, 128d8408326SSeung-Woo Kim 0, 5, 11, 19, 27, 37, 48, 59, 129d8408326SSeung-Woo Kim 70, 81, 92, 102, 111, 118, 124, 126, 130d8408326SSeung-Woo Kim 0, 0, -1, -1, -2, -3, -4, -5, 131d8408326SSeung-Woo Kim -6, -7, -8, -8, -8, -8, -6, -3, 132d8408326SSeung-Woo Kim }; 133d8408326SSeung-Woo Kim 134d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = { 135d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7, 136d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0, 137d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81, 138d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5, 139d8408326SSeung-Woo Kim }; 140d8408326SSeung-Woo Kim 141d8408326SSeung-Woo Kim static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id) 142d8408326SSeung-Woo Kim { 143d8408326SSeung-Woo Kim return readl(res->vp_regs + reg_id); 144d8408326SSeung-Woo Kim } 145d8408326SSeung-Woo Kim 146d8408326SSeung-Woo Kim static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id, 147d8408326SSeung-Woo Kim u32 val) 148d8408326SSeung-Woo Kim { 149d8408326SSeung-Woo Kim writel(val, res->vp_regs + reg_id); 150d8408326SSeung-Woo Kim } 151d8408326SSeung-Woo Kim 152d8408326SSeung-Woo Kim static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id, 153d8408326SSeung-Woo Kim u32 val, u32 mask) 154d8408326SSeung-Woo Kim { 155d8408326SSeung-Woo Kim u32 old = vp_reg_read(res, reg_id); 156d8408326SSeung-Woo Kim 157d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask); 158d8408326SSeung-Woo Kim writel(val, res->vp_regs + reg_id); 159d8408326SSeung-Woo Kim } 160d8408326SSeung-Woo Kim 161d8408326SSeung-Woo Kim static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id) 162d8408326SSeung-Woo Kim { 163d8408326SSeung-Woo Kim return readl(res->mixer_regs + reg_id); 164d8408326SSeung-Woo Kim } 165d8408326SSeung-Woo Kim 166d8408326SSeung-Woo Kim static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id, 167d8408326SSeung-Woo Kim u32 val) 168d8408326SSeung-Woo Kim { 169d8408326SSeung-Woo Kim writel(val, res->mixer_regs + reg_id); 170d8408326SSeung-Woo Kim } 171d8408326SSeung-Woo Kim 172d8408326SSeung-Woo Kim static inline void mixer_reg_writemask(struct mixer_resources *res, 173d8408326SSeung-Woo Kim u32 reg_id, u32 val, u32 mask) 174d8408326SSeung-Woo Kim { 175d8408326SSeung-Woo Kim u32 old = mixer_reg_read(res, reg_id); 176d8408326SSeung-Woo Kim 177d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask); 178d8408326SSeung-Woo Kim writel(val, res->mixer_regs + reg_id); 179d8408326SSeung-Woo Kim } 180d8408326SSeung-Woo Kim 181d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx) 182d8408326SSeung-Woo Kim { 183d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \ 184d8408326SSeung-Woo Kim do { \ 185d8408326SSeung-Woo Kim DRM_DEBUG_KMS(#reg_id " = %08x\n", \ 186d8408326SSeung-Woo Kim (u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \ 187d8408326SSeung-Woo Kim } while (0) 188d8408326SSeung-Woo Kim 189d8408326SSeung-Woo Kim DUMPREG(MXR_STATUS); 190d8408326SSeung-Woo Kim DUMPREG(MXR_CFG); 191d8408326SSeung-Woo Kim DUMPREG(MXR_INT_EN); 192d8408326SSeung-Woo Kim DUMPREG(MXR_INT_STATUS); 193d8408326SSeung-Woo Kim 194d8408326SSeung-Woo Kim DUMPREG(MXR_LAYER_CFG); 195d8408326SSeung-Woo Kim DUMPREG(MXR_VIDEO_CFG); 196d8408326SSeung-Woo Kim 197d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_CFG); 198d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_BASE); 199d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SPAN); 200d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_WH); 201d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SXY); 202d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_DXY); 203d8408326SSeung-Woo Kim 204d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_CFG); 205d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_BASE); 206d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SPAN); 207d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_WH); 208d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SXY); 209d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_DXY); 210d8408326SSeung-Woo Kim #undef DUMPREG 211d8408326SSeung-Woo Kim } 212d8408326SSeung-Woo Kim 213d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx) 214d8408326SSeung-Woo Kim { 215d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \ 216d8408326SSeung-Woo Kim do { \ 217d8408326SSeung-Woo Kim DRM_DEBUG_KMS(#reg_id " = %08x\n", \ 218d8408326SSeung-Woo Kim (u32) readl(ctx->mixer_res.vp_regs + reg_id)); \ 219d8408326SSeung-Woo Kim } while (0) 220d8408326SSeung-Woo Kim 221d8408326SSeung-Woo Kim DUMPREG(VP_ENABLE); 222d8408326SSeung-Woo Kim DUMPREG(VP_SRESET); 223d8408326SSeung-Woo Kim DUMPREG(VP_SHADOW_UPDATE); 224d8408326SSeung-Woo Kim DUMPREG(VP_FIELD_ID); 225d8408326SSeung-Woo Kim DUMPREG(VP_MODE); 226d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_Y); 227d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_C); 228d8408326SSeung-Woo Kim DUMPREG(VP_PER_RATE_CTRL); 229d8408326SSeung-Woo Kim DUMPREG(VP_TOP_Y_PTR); 230d8408326SSeung-Woo Kim DUMPREG(VP_BOT_Y_PTR); 231d8408326SSeung-Woo Kim DUMPREG(VP_TOP_C_PTR); 232d8408326SSeung-Woo Kim DUMPREG(VP_BOT_C_PTR); 233d8408326SSeung-Woo Kim DUMPREG(VP_ENDIAN_MODE); 234d8408326SSeung-Woo Kim DUMPREG(VP_SRC_H_POSITION); 235d8408326SSeung-Woo Kim DUMPREG(VP_SRC_V_POSITION); 236d8408326SSeung-Woo Kim DUMPREG(VP_SRC_WIDTH); 237d8408326SSeung-Woo Kim DUMPREG(VP_SRC_HEIGHT); 238d8408326SSeung-Woo Kim DUMPREG(VP_DST_H_POSITION); 239d8408326SSeung-Woo Kim DUMPREG(VP_DST_V_POSITION); 240d8408326SSeung-Woo Kim DUMPREG(VP_DST_WIDTH); 241d8408326SSeung-Woo Kim DUMPREG(VP_DST_HEIGHT); 242d8408326SSeung-Woo Kim DUMPREG(VP_H_RATIO); 243d8408326SSeung-Woo Kim DUMPREG(VP_V_RATIO); 244d8408326SSeung-Woo Kim 245d8408326SSeung-Woo Kim #undef DUMPREG 246d8408326SSeung-Woo Kim } 247d8408326SSeung-Woo Kim 248d8408326SSeung-Woo Kim static inline void vp_filter_set(struct mixer_resources *res, 249d8408326SSeung-Woo Kim int reg_id, const u8 *data, unsigned int size) 250d8408326SSeung-Woo Kim { 251d8408326SSeung-Woo Kim /* assure 4-byte align */ 252d8408326SSeung-Woo Kim BUG_ON(size & 3); 253d8408326SSeung-Woo Kim for (; size; size -= 4, reg_id += 4, data += 4) { 254d8408326SSeung-Woo Kim u32 val = (data[0] << 24) | (data[1] << 16) | 255d8408326SSeung-Woo Kim (data[2] << 8) | data[3]; 256d8408326SSeung-Woo Kim vp_reg_write(res, reg_id, val); 257d8408326SSeung-Woo Kim } 258d8408326SSeung-Woo Kim } 259d8408326SSeung-Woo Kim 260d8408326SSeung-Woo Kim static void vp_default_filter(struct mixer_resources *res) 261d8408326SSeung-Woo Kim { 262d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY8_Y0_LL, 263e25e1b66SSachin Kamat filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8)); 264d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY4_Y0_LL, 265e25e1b66SSachin Kamat filter_y_vert_tap4, sizeof(filter_y_vert_tap4)); 266d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY4_C0_LL, 267e25e1b66SSachin Kamat filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4)); 268d8408326SSeung-Woo Kim } 269d8408326SSeung-Woo Kim 270d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable) 271d8408326SSeung-Woo Kim { 272d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 273d8408326SSeung-Woo Kim 274d8408326SSeung-Woo Kim /* block update on vsync */ 275d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_STATUS, enable ? 276d8408326SSeung-Woo Kim MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE); 277d8408326SSeung-Woo Kim 2781b8e5747SRahul Sharma if (ctx->vp_enabled) 279d8408326SSeung-Woo Kim vp_reg_write(res, VP_SHADOW_UPDATE, enable ? 280d8408326SSeung-Woo Kim VP_SHADOW_UPDATE_ENABLE : 0); 281d8408326SSeung-Woo Kim } 282d8408326SSeung-Woo Kim 283d8408326SSeung-Woo Kim static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height) 284d8408326SSeung-Woo Kim { 285d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 286d8408326SSeung-Woo Kim u32 val; 287d8408326SSeung-Woo Kim 288d8408326SSeung-Woo Kim /* choosing between interlace and progressive mode */ 289d8408326SSeung-Woo Kim val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE : 290d8408326SSeung-Woo Kim MXR_CFG_SCAN_PROGRASSIVE); 291d8408326SSeung-Woo Kim 292def5e095SRahul Sharma if (ctx->mxr_ver != MXR_VER_128_0_0_184) { 293def5e095SRahul Sharma /* choosing between proper HD and SD mode */ 29429630743SRahul Sharma if (height <= 480) 295d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD; 29629630743SRahul Sharma else if (height <= 576) 297d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD; 29829630743SRahul Sharma else if (height <= 720) 299d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; 30029630743SRahul Sharma else if (height <= 1080) 301d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD; 302d8408326SSeung-Woo Kim else 303d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; 304def5e095SRahul Sharma } 305d8408326SSeung-Woo Kim 306d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK); 307d8408326SSeung-Woo Kim } 308d8408326SSeung-Woo Kim 309d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height) 310d8408326SSeung-Woo Kim { 311d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 312d8408326SSeung-Woo Kim u32 val; 313d8408326SSeung-Woo Kim 314d8408326SSeung-Woo Kim if (height == 480) { 315d8408326SSeung-Woo Kim val = MXR_CFG_RGB601_0_255; 316d8408326SSeung-Woo Kim } else if (height == 576) { 317d8408326SSeung-Woo Kim val = MXR_CFG_RGB601_0_255; 318d8408326SSeung-Woo Kim } else if (height == 720) { 319d8408326SSeung-Woo Kim val = MXR_CFG_RGB709_16_235; 320d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_Y, 321d8408326SSeung-Woo Kim (1 << 30) | (94 << 20) | (314 << 10) | 322d8408326SSeung-Woo Kim (32 << 0)); 323d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CB, 324d8408326SSeung-Woo Kim (972 << 20) | (851 << 10) | (225 << 0)); 325d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CR, 326d8408326SSeung-Woo Kim (225 << 20) | (820 << 10) | (1004 << 0)); 327d8408326SSeung-Woo Kim } else if (height == 1080) { 328d8408326SSeung-Woo Kim val = MXR_CFG_RGB709_16_235; 329d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_Y, 330d8408326SSeung-Woo Kim (1 << 30) | (94 << 20) | (314 << 10) | 331d8408326SSeung-Woo Kim (32 << 0)); 332d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CB, 333d8408326SSeung-Woo Kim (972 << 20) | (851 << 10) | (225 << 0)); 334d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CR, 335d8408326SSeung-Woo Kim (225 << 20) | (820 << 10) | (1004 << 0)); 336d8408326SSeung-Woo Kim } else { 337d8408326SSeung-Woo Kim val = MXR_CFG_RGB709_16_235; 338d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_Y, 339d8408326SSeung-Woo Kim (1 << 30) | (94 << 20) | (314 << 10) | 340d8408326SSeung-Woo Kim (32 << 0)); 341d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CB, 342d8408326SSeung-Woo Kim (972 << 20) | (851 << 10) | (225 << 0)); 343d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CR, 344d8408326SSeung-Woo Kim (225 << 20) | (820 << 10) | (1004 << 0)); 345d8408326SSeung-Woo Kim } 346d8408326SSeung-Woo Kim 347d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK); 348d8408326SSeung-Woo Kim } 349d8408326SSeung-Woo Kim 350d8408326SSeung-Woo Kim static void mixer_cfg_layer(struct mixer_context *ctx, int win, bool enable) 351d8408326SSeung-Woo Kim { 352d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 353d8408326SSeung-Woo Kim u32 val = enable ? ~0 : 0; 354d8408326SSeung-Woo Kim 355d8408326SSeung-Woo Kim switch (win) { 356d8408326SSeung-Woo Kim case 0: 357d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE); 358d8408326SSeung-Woo Kim break; 359d8408326SSeung-Woo Kim case 1: 360d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE); 361d8408326SSeung-Woo Kim break; 362d8408326SSeung-Woo Kim case 2: 3631b8e5747SRahul Sharma if (ctx->vp_enabled) { 364d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON); 3651b8e5747SRahul Sharma mixer_reg_writemask(res, MXR_CFG, val, 3661b8e5747SRahul Sharma MXR_CFG_VP_ENABLE); 367f1e716d8SJoonyoung Shim 368f1e716d8SJoonyoung Shim /* control blending of graphic layer 0 */ 369f1e716d8SJoonyoung Shim mixer_reg_writemask(res, MXR_GRAPHIC_CFG(0), val, 370f1e716d8SJoonyoung Shim MXR_GRP_CFG_BLEND_PRE_MUL | 371f1e716d8SJoonyoung Shim MXR_GRP_CFG_PIXEL_BLEND_EN); 3721b8e5747SRahul Sharma } 373d8408326SSeung-Woo Kim break; 374d8408326SSeung-Woo Kim } 375d8408326SSeung-Woo Kim } 376d8408326SSeung-Woo Kim 377d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx) 378d8408326SSeung-Woo Kim { 379d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 380d8408326SSeung-Woo Kim 381d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN); 382d8408326SSeung-Woo Kim 383d8408326SSeung-Woo Kim mixer_regs_dump(ctx); 384d8408326SSeung-Woo Kim } 385d8408326SSeung-Woo Kim 386381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx) 387381be025SRahul Sharma { 388381be025SRahul Sharma struct mixer_resources *res = &ctx->mixer_res; 389381be025SRahul Sharma int timeout = 20; 390381be025SRahul Sharma 391381be025SRahul Sharma mixer_reg_writemask(res, MXR_STATUS, 0, MXR_STATUS_REG_RUN); 392381be025SRahul Sharma 393381be025SRahul Sharma while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) && 394381be025SRahul Sharma --timeout) 395381be025SRahul Sharma usleep_range(10000, 12000); 396381be025SRahul Sharma 397381be025SRahul Sharma mixer_regs_dump(ctx); 398381be025SRahul Sharma } 399381be025SRahul Sharma 400d8408326SSeung-Woo Kim static void vp_video_buffer(struct mixer_context *ctx, int win) 401d8408326SSeung-Woo Kim { 402d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 403d8408326SSeung-Woo Kim unsigned long flags; 404d8408326SSeung-Woo Kim struct hdmi_win_data *win_data; 405d8408326SSeung-Woo Kim unsigned int x_ratio, y_ratio; 406782953ecSYoungJun Cho unsigned int buf_num = 1; 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 412d8408326SSeung-Woo Kim win_data = &ctx->win_data[win]; 413d8408326SSeung-Woo Kim 414d8408326SSeung-Woo Kim switch (win_data->pixel_format) { 415d8408326SSeung-Woo Kim case DRM_FORMAT_NV12MT: 416d8408326SSeung-Woo Kim tiled_mode = true; 417363b06aaSVille Syrjälä case DRM_FORMAT_NV12: 418d8408326SSeung-Woo Kim crcb_mode = false; 419d8408326SSeung-Woo Kim buf_num = 2; 420d8408326SSeung-Woo Kim break; 421d8408326SSeung-Woo Kim /* TODO: single buffer format NV12, NV21 */ 422d8408326SSeung-Woo Kim default: 423d8408326SSeung-Woo Kim /* ignore pixel format at disable time */ 424d8408326SSeung-Woo Kim if (!win_data->dma_addr) 425d8408326SSeung-Woo Kim break; 426d8408326SSeung-Woo Kim 427d8408326SSeung-Woo Kim DRM_ERROR("pixel format for vp is wrong [%d].\n", 428d8408326SSeung-Woo Kim win_data->pixel_format); 429d8408326SSeung-Woo Kim return; 430d8408326SSeung-Woo Kim } 431d8408326SSeung-Woo Kim 432d8408326SSeung-Woo Kim /* scaling feature: (src << 16) / dst */ 4338dcb96b6SSeung-Woo Kim x_ratio = (win_data->src_width << 16) / win_data->crtc_width; 4348dcb96b6SSeung-Woo Kim y_ratio = (win_data->src_height << 16) / win_data->crtc_height; 435d8408326SSeung-Woo Kim 436d8408326SSeung-Woo Kim if (buf_num == 2) { 437d8408326SSeung-Woo Kim luma_addr[0] = win_data->dma_addr; 438d8408326SSeung-Woo Kim chroma_addr[0] = win_data->chroma_dma_addr; 439d8408326SSeung-Woo Kim } else { 440d8408326SSeung-Woo Kim luma_addr[0] = win_data->dma_addr; 441d8408326SSeung-Woo Kim chroma_addr[0] = win_data->dma_addr 4428dcb96b6SSeung-Woo Kim + (win_data->fb_width * win_data->fb_height); 443d8408326SSeung-Woo Kim } 444d8408326SSeung-Woo Kim 445d8408326SSeung-Woo Kim if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE) { 446d8408326SSeung-Woo Kim ctx->interlace = true; 447d8408326SSeung-Woo Kim if (tiled_mode) { 448d8408326SSeung-Woo Kim luma_addr[1] = luma_addr[0] + 0x40; 449d8408326SSeung-Woo Kim chroma_addr[1] = chroma_addr[0] + 0x40; 450d8408326SSeung-Woo Kim } else { 4518dcb96b6SSeung-Woo Kim luma_addr[1] = luma_addr[0] + win_data->fb_width; 4528dcb96b6SSeung-Woo Kim chroma_addr[1] = chroma_addr[0] + win_data->fb_width; 453d8408326SSeung-Woo Kim } 454d8408326SSeung-Woo Kim } else { 455d8408326SSeung-Woo Kim ctx->interlace = false; 456d8408326SSeung-Woo Kim luma_addr[1] = 0; 457d8408326SSeung-Woo Kim chroma_addr[1] = 0; 458d8408326SSeung-Woo Kim } 459d8408326SSeung-Woo Kim 460d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 461d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, false); 462d8408326SSeung-Woo Kim 463d8408326SSeung-Woo Kim /* interlace or progressive scan mode */ 464d8408326SSeung-Woo Kim val = (ctx->interlace ? ~0 : 0); 465d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP); 466d8408326SSeung-Woo Kim 467d8408326SSeung-Woo Kim /* setup format */ 468d8408326SSeung-Woo Kim val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12); 469d8408326SSeung-Woo Kim val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR); 470d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK); 471d8408326SSeung-Woo Kim 472d8408326SSeung-Woo Kim /* setting size of input image */ 4738dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(win_data->fb_width) | 4748dcb96b6SSeung-Woo Kim VP_IMG_VSIZE(win_data->fb_height)); 475d8408326SSeung-Woo Kim /* chroma height has to reduced by 2 to avoid chroma distorions */ 4768dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(win_data->fb_width) | 4778dcb96b6SSeung-Woo Kim VP_IMG_VSIZE(win_data->fb_height / 2)); 478d8408326SSeung-Woo Kim 4798dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_SRC_WIDTH, win_data->src_width); 4808dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_SRC_HEIGHT, win_data->src_height); 481d8408326SSeung-Woo Kim vp_reg_write(res, VP_SRC_H_POSITION, 4828dcb96b6SSeung-Woo Kim VP_SRC_H_POSITION_VAL(win_data->fb_x)); 4838dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_SRC_V_POSITION, win_data->fb_y); 484d8408326SSeung-Woo Kim 4858dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_WIDTH, win_data->crtc_width); 4868dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_H_POSITION, win_data->crtc_x); 487d8408326SSeung-Woo Kim if (ctx->interlace) { 4888dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height / 2); 4898dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y / 2); 490d8408326SSeung-Woo Kim } else { 4918dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height); 4928dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y); 493d8408326SSeung-Woo Kim } 494d8408326SSeung-Woo Kim 495d8408326SSeung-Woo Kim vp_reg_write(res, VP_H_RATIO, x_ratio); 496d8408326SSeung-Woo Kim vp_reg_write(res, VP_V_RATIO, y_ratio); 497d8408326SSeung-Woo Kim 498d8408326SSeung-Woo Kim vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE); 499d8408326SSeung-Woo Kim 500d8408326SSeung-Woo Kim /* set buffer address to vp */ 501d8408326SSeung-Woo Kim vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]); 502d8408326SSeung-Woo Kim vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]); 503d8408326SSeung-Woo Kim vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]); 504d8408326SSeung-Woo Kim vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]); 505d8408326SSeung-Woo Kim 5068dcb96b6SSeung-Woo Kim mixer_cfg_scan(ctx, win_data->mode_height); 5078dcb96b6SSeung-Woo Kim mixer_cfg_rgb_fmt(ctx, win_data->mode_height); 508d8408326SSeung-Woo Kim mixer_cfg_layer(ctx, win, true); 509d8408326SSeung-Woo Kim mixer_run(ctx); 510d8408326SSeung-Woo Kim 511d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, true); 512d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 513d8408326SSeung-Woo Kim 514d8408326SSeung-Woo Kim vp_regs_dump(ctx); 515d8408326SSeung-Woo Kim } 516d8408326SSeung-Woo Kim 517aaf8b49eSRahul Sharma static void mixer_layer_update(struct mixer_context *ctx) 518aaf8b49eSRahul Sharma { 519aaf8b49eSRahul Sharma struct mixer_resources *res = &ctx->mixer_res; 520aaf8b49eSRahul Sharma 521aaf8b49eSRahul Sharma mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE); 522aaf8b49eSRahul Sharma } 523aaf8b49eSRahul Sharma 524d8408326SSeung-Woo Kim static void mixer_graph_buffer(struct mixer_context *ctx, int win) 525d8408326SSeung-Woo Kim { 526d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 527d8408326SSeung-Woo Kim unsigned long flags; 528d8408326SSeung-Woo Kim struct hdmi_win_data *win_data; 529d8408326SSeung-Woo Kim unsigned int x_ratio, y_ratio; 530d8408326SSeung-Woo Kim unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset; 531d8408326SSeung-Woo Kim dma_addr_t dma_addr; 532d8408326SSeung-Woo Kim unsigned int fmt; 533d8408326SSeung-Woo Kim u32 val; 534d8408326SSeung-Woo Kim 535d8408326SSeung-Woo Kim win_data = &ctx->win_data[win]; 536d8408326SSeung-Woo Kim 537d8408326SSeung-Woo Kim #define RGB565 4 538d8408326SSeung-Woo Kim #define ARGB1555 5 539d8408326SSeung-Woo Kim #define ARGB4444 6 540d8408326SSeung-Woo Kim #define ARGB8888 7 541d8408326SSeung-Woo Kim 542d8408326SSeung-Woo Kim switch (win_data->bpp) { 543d8408326SSeung-Woo Kim case 16: 544d8408326SSeung-Woo Kim fmt = ARGB4444; 545d8408326SSeung-Woo Kim break; 546d8408326SSeung-Woo Kim case 32: 547d8408326SSeung-Woo Kim fmt = ARGB8888; 548d8408326SSeung-Woo Kim break; 549d8408326SSeung-Woo Kim default: 550d8408326SSeung-Woo Kim fmt = ARGB8888; 551d8408326SSeung-Woo Kim } 552d8408326SSeung-Woo Kim 553d8408326SSeung-Woo Kim /* 2x scaling feature */ 554d8408326SSeung-Woo Kim x_ratio = 0; 555d8408326SSeung-Woo Kim y_ratio = 0; 556d8408326SSeung-Woo Kim 557d8408326SSeung-Woo Kim dst_x_offset = win_data->crtc_x; 558d8408326SSeung-Woo Kim dst_y_offset = win_data->crtc_y; 559d8408326SSeung-Woo Kim 560d8408326SSeung-Woo Kim /* converting dma address base and source offset */ 5618dcb96b6SSeung-Woo Kim dma_addr = win_data->dma_addr 5628dcb96b6SSeung-Woo Kim + (win_data->fb_x * win_data->bpp >> 3) 5638dcb96b6SSeung-Woo Kim + (win_data->fb_y * win_data->fb_width * win_data->bpp >> 3); 564d8408326SSeung-Woo Kim src_x_offset = 0; 565d8408326SSeung-Woo Kim src_y_offset = 0; 566d8408326SSeung-Woo Kim 567d8408326SSeung-Woo Kim if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE) 568d8408326SSeung-Woo Kim ctx->interlace = true; 569d8408326SSeung-Woo Kim else 570d8408326SSeung-Woo Kim ctx->interlace = false; 571d8408326SSeung-Woo Kim 572d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 573d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, false); 574d8408326SSeung-Woo Kim 575d8408326SSeung-Woo Kim /* setup format */ 576d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win), 577d8408326SSeung-Woo Kim MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK); 578d8408326SSeung-Woo Kim 579d8408326SSeung-Woo Kim /* setup geometry */ 5808dcb96b6SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_SPAN(win), win_data->fb_width); 581d8408326SSeung-Woo Kim 582def5e095SRahul Sharma /* setup display size */ 583def5e095SRahul Sharma if (ctx->mxr_ver == MXR_VER_128_0_0_184 && 584def5e095SRahul Sharma win == MIXER_DEFAULT_WIN) { 585def5e095SRahul Sharma val = MXR_MXR_RES_HEIGHT(win_data->fb_height); 586def5e095SRahul Sharma val |= MXR_MXR_RES_WIDTH(win_data->fb_width); 587def5e095SRahul Sharma mixer_reg_write(res, MXR_RESOLUTION, val); 588def5e095SRahul Sharma } 589def5e095SRahul Sharma 5908dcb96b6SSeung-Woo Kim val = MXR_GRP_WH_WIDTH(win_data->crtc_width); 5918dcb96b6SSeung-Woo Kim val |= MXR_GRP_WH_HEIGHT(win_data->crtc_height); 592d8408326SSeung-Woo Kim val |= MXR_GRP_WH_H_SCALE(x_ratio); 593d8408326SSeung-Woo Kim val |= MXR_GRP_WH_V_SCALE(y_ratio); 594d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_WH(win), val); 595d8408326SSeung-Woo Kim 596d8408326SSeung-Woo Kim /* setup offsets in source image */ 597d8408326SSeung-Woo Kim val = MXR_GRP_SXY_SX(src_x_offset); 598d8408326SSeung-Woo Kim val |= MXR_GRP_SXY_SY(src_y_offset); 599d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val); 600d8408326SSeung-Woo Kim 601d8408326SSeung-Woo Kim /* setup offsets in display image */ 602d8408326SSeung-Woo Kim val = MXR_GRP_DXY_DX(dst_x_offset); 603d8408326SSeung-Woo Kim val |= MXR_GRP_DXY_DY(dst_y_offset); 604d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val); 605d8408326SSeung-Woo Kim 606d8408326SSeung-Woo Kim /* set buffer address to mixer */ 607d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr); 608d8408326SSeung-Woo Kim 6098dcb96b6SSeung-Woo Kim mixer_cfg_scan(ctx, win_data->mode_height); 6108dcb96b6SSeung-Woo Kim mixer_cfg_rgb_fmt(ctx, win_data->mode_height); 611d8408326SSeung-Woo Kim mixer_cfg_layer(ctx, win, true); 612aaf8b49eSRahul Sharma 613aaf8b49eSRahul Sharma /* layer update mandatory for mixer 16.0.33.0 */ 614def5e095SRahul Sharma if (ctx->mxr_ver == MXR_VER_16_0_33_0 || 615def5e095SRahul Sharma ctx->mxr_ver == MXR_VER_128_0_0_184) 616aaf8b49eSRahul Sharma mixer_layer_update(ctx); 617aaf8b49eSRahul Sharma 618d8408326SSeung-Woo Kim mixer_run(ctx); 619d8408326SSeung-Woo Kim 620d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, true); 621d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 622d8408326SSeung-Woo Kim } 623d8408326SSeung-Woo Kim 624d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx) 625d8408326SSeung-Woo Kim { 626d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 627d8408326SSeung-Woo Kim int tries = 100; 628d8408326SSeung-Woo Kim 629d8408326SSeung-Woo Kim vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING); 630d8408326SSeung-Woo Kim for (tries = 100; tries; --tries) { 631d8408326SSeung-Woo Kim /* waiting until VP_SRESET_PROCESSING is 0 */ 632d8408326SSeung-Woo Kim if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING) 633d8408326SSeung-Woo Kim break; 63409760ea3SSean Paul usleep_range(10000, 12000); 635d8408326SSeung-Woo Kim } 636d8408326SSeung-Woo Kim WARN(tries == 0, "failed to reset Video Processor\n"); 637d8408326SSeung-Woo Kim } 638d8408326SSeung-Woo Kim 639cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx) 640cf8fc4f1SJoonyoung Shim { 641cf8fc4f1SJoonyoung Shim struct mixer_resources *res = &ctx->mixer_res; 642cf8fc4f1SJoonyoung Shim unsigned long flags; 643cf8fc4f1SJoonyoung Shim u32 val; /* value stored to register */ 644cf8fc4f1SJoonyoung Shim 645cf8fc4f1SJoonyoung Shim spin_lock_irqsave(&res->reg_slock, flags); 646cf8fc4f1SJoonyoung Shim mixer_vsync_set_update(ctx, false); 647cf8fc4f1SJoonyoung Shim 648cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK); 649cf8fc4f1SJoonyoung Shim 650cf8fc4f1SJoonyoung Shim /* set output in RGB888 mode */ 651cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK); 652cf8fc4f1SJoonyoung Shim 653cf8fc4f1SJoonyoung Shim /* 16 beat burst in DMA */ 654cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST, 655cf8fc4f1SJoonyoung Shim MXR_STATUS_BURST_MASK); 656cf8fc4f1SJoonyoung Shim 657cf8fc4f1SJoonyoung Shim /* setting default layer priority: layer1 > layer0 > video 658cf8fc4f1SJoonyoung Shim * because typical usage scenario would be 659cf8fc4f1SJoonyoung Shim * layer1 - OSD 660cf8fc4f1SJoonyoung Shim * layer0 - framebuffer 661cf8fc4f1SJoonyoung Shim * video - video overlay 662cf8fc4f1SJoonyoung Shim */ 663cf8fc4f1SJoonyoung Shim val = MXR_LAYER_CFG_GRP1_VAL(3); 664cf8fc4f1SJoonyoung Shim val |= MXR_LAYER_CFG_GRP0_VAL(2); 6651b8e5747SRahul Sharma if (ctx->vp_enabled) 666cf8fc4f1SJoonyoung Shim val |= MXR_LAYER_CFG_VP_VAL(1); 667cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_LAYER_CFG, val); 668cf8fc4f1SJoonyoung Shim 669cf8fc4f1SJoonyoung Shim /* setting background color */ 670cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_BG_COLOR0, 0x008080); 671cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_BG_COLOR1, 0x008080); 672cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_BG_COLOR2, 0x008080); 673cf8fc4f1SJoonyoung Shim 674cf8fc4f1SJoonyoung Shim /* setting graphical layers */ 675cf8fc4f1SJoonyoung Shim val = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */ 676cf8fc4f1SJoonyoung Shim val |= MXR_GRP_CFG_WIN_BLEND_EN; 677cf8fc4f1SJoonyoung Shim val |= MXR_GRP_CFG_ALPHA_VAL(0xff); /* non-transparent alpha */ 678cf8fc4f1SJoonyoung Shim 6790377f4edSSean Paul /* Don't blend layer 0 onto the mixer background */ 680cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_GRAPHIC_CFG(0), val); 6810377f4edSSean Paul 6820377f4edSSean Paul /* Blend layer 1 into layer 0 */ 6830377f4edSSean Paul val |= MXR_GRP_CFG_BLEND_PRE_MUL; 6840377f4edSSean Paul val |= MXR_GRP_CFG_PIXEL_BLEND_EN; 685cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_GRAPHIC_CFG(1), val); 686cf8fc4f1SJoonyoung Shim 6875736603bSSeung-Woo Kim /* setting video layers */ 6885736603bSSeung-Woo Kim val = MXR_GRP_CFG_ALPHA_VAL(0); 6895736603bSSeung-Woo Kim mixer_reg_write(res, MXR_VIDEO_CFG, val); 6905736603bSSeung-Woo Kim 6911b8e5747SRahul Sharma if (ctx->vp_enabled) { 692cf8fc4f1SJoonyoung Shim /* configuration of Video Processor Registers */ 693cf8fc4f1SJoonyoung Shim vp_win_reset(ctx); 694cf8fc4f1SJoonyoung Shim vp_default_filter(res); 6951b8e5747SRahul Sharma } 696cf8fc4f1SJoonyoung Shim 697cf8fc4f1SJoonyoung Shim /* disable all layers */ 698cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE); 699cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE); 7001b8e5747SRahul Sharma if (ctx->vp_enabled) 701cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE); 702cf8fc4f1SJoonyoung Shim 703cf8fc4f1SJoonyoung Shim mixer_vsync_set_update(ctx, true); 704cf8fc4f1SJoonyoung Shim spin_unlock_irqrestore(&res->reg_slock, flags); 705cf8fc4f1SJoonyoung Shim } 706cf8fc4f1SJoonyoung Shim 7074551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg) 7084551789fSSean Paul { 7094551789fSSean Paul struct mixer_context *ctx = arg; 7104551789fSSean Paul struct mixer_resources *res = &ctx->mixer_res; 7114551789fSSean Paul u32 val, base, shadow; 7124551789fSSean Paul 7134551789fSSean Paul spin_lock(&res->reg_slock); 7144551789fSSean Paul 7154551789fSSean Paul /* read interrupt status for handling and clearing flags for VSYNC */ 7164551789fSSean Paul val = mixer_reg_read(res, MXR_INT_STATUS); 7174551789fSSean Paul 7184551789fSSean Paul /* handling VSYNC */ 7194551789fSSean Paul if (val & MXR_INT_STATUS_VSYNC) { 7204551789fSSean Paul /* interlace scan need to check shadow register */ 7214551789fSSean Paul if (ctx->interlace) { 7224551789fSSean Paul base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0)); 7234551789fSSean Paul shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0)); 7244551789fSSean Paul if (base != shadow) 7254551789fSSean Paul goto out; 7264551789fSSean Paul 7274551789fSSean Paul base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1)); 7284551789fSSean Paul shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1)); 7294551789fSSean Paul if (base != shadow) 7304551789fSSean Paul goto out; 7314551789fSSean Paul } 7324551789fSSean Paul 7334551789fSSean Paul drm_handle_vblank(ctx->drm_dev, ctx->pipe); 7344551789fSSean Paul exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe); 7354551789fSSean Paul 7364551789fSSean Paul /* set wait vsync event to zero and wake up queue. */ 7374551789fSSean Paul if (atomic_read(&ctx->wait_vsync_event)) { 7384551789fSSean Paul atomic_set(&ctx->wait_vsync_event, 0); 7394551789fSSean Paul wake_up(&ctx->wait_vsync_queue); 7404551789fSSean Paul } 7414551789fSSean Paul } 7424551789fSSean Paul 7434551789fSSean Paul out: 7444551789fSSean Paul /* clear interrupts */ 7454551789fSSean Paul if (~val & MXR_INT_EN_VSYNC) { 7464551789fSSean Paul /* vsync interrupt use different bit for read and clear */ 7474551789fSSean Paul val &= ~MXR_INT_EN_VSYNC; 7484551789fSSean Paul val |= MXR_INT_CLEAR_VSYNC; 7494551789fSSean Paul } 7504551789fSSean Paul mixer_reg_write(res, MXR_INT_STATUS, val); 7514551789fSSean Paul 7524551789fSSean Paul spin_unlock(&res->reg_slock); 7534551789fSSean Paul 7544551789fSSean Paul return IRQ_HANDLED; 7554551789fSSean Paul } 7564551789fSSean Paul 7574551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx) 7584551789fSSean Paul { 7594551789fSSean Paul struct device *dev = &mixer_ctx->pdev->dev; 7604551789fSSean Paul struct mixer_resources *mixer_res = &mixer_ctx->mixer_res; 7614551789fSSean Paul struct resource *res; 7624551789fSSean Paul int ret; 7634551789fSSean Paul 7644551789fSSean Paul spin_lock_init(&mixer_res->reg_slock); 7654551789fSSean Paul 7664551789fSSean Paul mixer_res->mixer = devm_clk_get(dev, "mixer"); 7674551789fSSean Paul if (IS_ERR(mixer_res->mixer)) { 7684551789fSSean Paul dev_err(dev, "failed to get clock 'mixer'\n"); 7694551789fSSean Paul return -ENODEV; 7704551789fSSean Paul } 7714551789fSSean Paul 7724551789fSSean Paul mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi"); 7734551789fSSean Paul if (IS_ERR(mixer_res->sclk_hdmi)) { 7744551789fSSean Paul dev_err(dev, "failed to get clock 'sclk_hdmi'\n"); 7754551789fSSean Paul return -ENODEV; 7764551789fSSean Paul } 7774551789fSSean Paul res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0); 7784551789fSSean Paul if (res == NULL) { 7794551789fSSean Paul dev_err(dev, "get memory resource failed.\n"); 7804551789fSSean Paul return -ENXIO; 7814551789fSSean Paul } 7824551789fSSean Paul 7834551789fSSean Paul mixer_res->mixer_regs = devm_ioremap(dev, res->start, 7844551789fSSean Paul resource_size(res)); 7854551789fSSean Paul if (mixer_res->mixer_regs == NULL) { 7864551789fSSean Paul dev_err(dev, "register mapping failed.\n"); 7874551789fSSean Paul return -ENXIO; 7884551789fSSean Paul } 7894551789fSSean Paul 7904551789fSSean Paul res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0); 7914551789fSSean Paul if (res == NULL) { 7924551789fSSean Paul dev_err(dev, "get interrupt resource failed.\n"); 7934551789fSSean Paul return -ENXIO; 7944551789fSSean Paul } 7954551789fSSean Paul 7964551789fSSean Paul ret = devm_request_irq(dev, res->start, mixer_irq_handler, 7974551789fSSean Paul 0, "drm_mixer", mixer_ctx); 7984551789fSSean Paul if (ret) { 7994551789fSSean Paul dev_err(dev, "request interrupt failed.\n"); 8004551789fSSean Paul return ret; 8014551789fSSean Paul } 8024551789fSSean Paul mixer_res->irq = res->start; 8034551789fSSean Paul 8044551789fSSean Paul return 0; 8054551789fSSean Paul } 8064551789fSSean Paul 8074551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx) 8084551789fSSean Paul { 8094551789fSSean Paul struct device *dev = &mixer_ctx->pdev->dev; 8104551789fSSean Paul struct mixer_resources *mixer_res = &mixer_ctx->mixer_res; 8114551789fSSean Paul struct resource *res; 8124551789fSSean Paul 8134551789fSSean Paul mixer_res->vp = devm_clk_get(dev, "vp"); 8144551789fSSean Paul if (IS_ERR(mixer_res->vp)) { 8154551789fSSean Paul dev_err(dev, "failed to get clock 'vp'\n"); 8164551789fSSean Paul return -ENODEV; 8174551789fSSean Paul } 818ff830c96SMarek Szyprowski 819ff830c96SMarek Szyprowski if (mixer_ctx->has_sclk) { 8204551789fSSean Paul mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer"); 8214551789fSSean Paul if (IS_ERR(mixer_res->sclk_mixer)) { 8224551789fSSean Paul dev_err(dev, "failed to get clock 'sclk_mixer'\n"); 8234551789fSSean Paul return -ENODEV; 8244551789fSSean Paul } 825ff830c96SMarek Szyprowski mixer_res->mout_mixer = devm_clk_get(dev, "mout_mixer"); 826ff830c96SMarek Szyprowski if (IS_ERR(mixer_res->mout_mixer)) { 827ff830c96SMarek Szyprowski dev_err(dev, "failed to get clock 'mout_mixer'\n"); 8284551789fSSean Paul return -ENODEV; 8294551789fSSean Paul } 8304551789fSSean Paul 831ff830c96SMarek Szyprowski if (mixer_res->sclk_hdmi && mixer_res->mout_mixer) 832ff830c96SMarek Szyprowski clk_set_parent(mixer_res->mout_mixer, 833ff830c96SMarek Szyprowski mixer_res->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 8424551789fSSean Paul mixer_res->vp_regs = devm_ioremap(dev, res->start, 8434551789fSSean Paul resource_size(res)); 8444551789fSSean Paul if (mixer_res->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 852f041b257SSean Paul static int mixer_initialize(struct exynos_drm_manager *mgr, 853f37cd5e8SInki Dae struct drm_device *drm_dev) 8544551789fSSean Paul { 8554551789fSSean Paul int ret; 856f041b257SSean Paul struct mixer_context *mixer_ctx = mgr->ctx; 857f37cd5e8SInki Dae struct exynos_drm_private *priv; 858f37cd5e8SInki Dae priv = drm_dev->dev_private; 8594551789fSSean Paul 860f37cd5e8SInki Dae mgr->drm_dev = mixer_ctx->drm_dev = drm_dev; 861f37cd5e8SInki Dae mgr->pipe = mixer_ctx->pipe = priv->pipe++; 8624551789fSSean Paul 8634551789fSSean Paul /* acquire resources: regs, irqs, clocks */ 8644551789fSSean Paul ret = mixer_resources_init(mixer_ctx); 8654551789fSSean Paul if (ret) { 8664551789fSSean Paul DRM_ERROR("mixer_resources_init failed ret=%d\n", ret); 8674551789fSSean Paul return ret; 8684551789fSSean Paul } 8694551789fSSean Paul 8704551789fSSean Paul if (mixer_ctx->vp_enabled) { 8714551789fSSean Paul /* acquire vp resources: regs, irqs, clocks */ 8724551789fSSean Paul ret = vp_resources_init(mixer_ctx); 8734551789fSSean Paul if (ret) { 8744551789fSSean Paul DRM_ERROR("vp_resources_init failed ret=%d\n", ret); 8754551789fSSean Paul return ret; 8764551789fSSean Paul } 8774551789fSSean Paul } 8784551789fSSean Paul 879f041b257SSean Paul if (!is_drm_iommu_supported(mixer_ctx->drm_dev)) 8801055b39fSInki Dae return 0; 881f041b257SSean Paul 882f041b257SSean Paul return drm_iommu_attach_device(mixer_ctx->drm_dev, mixer_ctx->dev); 8831055b39fSInki Dae } 8841055b39fSInki Dae 885f041b257SSean Paul static void mixer_mgr_remove(struct exynos_drm_manager *mgr) 886d8408326SSeung-Woo Kim { 887f041b257SSean Paul struct mixer_context *mixer_ctx = mgr->ctx; 888f041b257SSean Paul 889f041b257SSean Paul if (is_drm_iommu_supported(mixer_ctx->drm_dev)) 890f041b257SSean Paul drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev); 891f041b257SSean Paul } 892f041b257SSean Paul 893f041b257SSean Paul static int mixer_enable_vblank(struct exynos_drm_manager *mgr) 894f041b257SSean Paul { 895f041b257SSean Paul struct mixer_context *mixer_ctx = mgr->ctx; 896d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 897d8408326SSeung-Woo Kim 898f041b257SSean Paul if (!mixer_ctx->powered) { 899f041b257SSean Paul mixer_ctx->int_en |= MXR_INT_EN_VSYNC; 900f041b257SSean Paul return 0; 901f041b257SSean Paul } 902d8408326SSeung-Woo Kim 903d8408326SSeung-Woo Kim /* enable vsync interrupt */ 904d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_INT_EN, MXR_INT_EN_VSYNC, 905d8408326SSeung-Woo Kim MXR_INT_EN_VSYNC); 906d8408326SSeung-Woo Kim 907d8408326SSeung-Woo Kim return 0; 908d8408326SSeung-Woo Kim } 909d8408326SSeung-Woo Kim 910f041b257SSean Paul static void mixer_disable_vblank(struct exynos_drm_manager *mgr) 911d8408326SSeung-Woo Kim { 912f041b257SSean Paul struct mixer_context *mixer_ctx = mgr->ctx; 913d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 914d8408326SSeung-Woo Kim 915d8408326SSeung-Woo Kim /* disable vsync interrupt */ 916d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC); 917d8408326SSeung-Woo Kim } 918d8408326SSeung-Woo Kim 919f041b257SSean Paul static void mixer_win_mode_set(struct exynos_drm_manager *mgr, 920d8408326SSeung-Woo Kim struct exynos_drm_overlay *overlay) 921d8408326SSeung-Woo Kim { 922f041b257SSean Paul struct mixer_context *mixer_ctx = mgr->ctx; 923d8408326SSeung-Woo Kim struct hdmi_win_data *win_data; 924d8408326SSeung-Woo Kim int win; 925d8408326SSeung-Woo Kim 926d8408326SSeung-Woo Kim if (!overlay) { 927d8408326SSeung-Woo Kim DRM_ERROR("overlay is NULL\n"); 928d8408326SSeung-Woo Kim return; 929d8408326SSeung-Woo Kim } 930d8408326SSeung-Woo Kim 931d8408326SSeung-Woo Kim DRM_DEBUG_KMS("set [%d]x[%d] at (%d,%d) to [%d]x[%d] at (%d,%d)\n", 932d8408326SSeung-Woo Kim overlay->fb_width, overlay->fb_height, 933d8408326SSeung-Woo Kim overlay->fb_x, overlay->fb_y, 934d8408326SSeung-Woo Kim overlay->crtc_width, overlay->crtc_height, 935d8408326SSeung-Woo Kim overlay->crtc_x, overlay->crtc_y); 936d8408326SSeung-Woo Kim 937d8408326SSeung-Woo Kim win = overlay->zpos; 938d8408326SSeung-Woo Kim if (win == DEFAULT_ZPOS) 939a2ee151bSJoonyoung Shim win = MIXER_DEFAULT_WIN; 940d8408326SSeung-Woo Kim 9411586d80cSKrzysztof Kozlowski if (win < 0 || win >= MIXER_WIN_NR) { 942cf8fc4f1SJoonyoung Shim DRM_ERROR("mixer window[%d] is wrong\n", win); 943d8408326SSeung-Woo Kim return; 944d8408326SSeung-Woo Kim } 945d8408326SSeung-Woo Kim 946d8408326SSeung-Woo Kim win_data = &mixer_ctx->win_data[win]; 947d8408326SSeung-Woo Kim 948d8408326SSeung-Woo Kim win_data->dma_addr = overlay->dma_addr[0]; 949d8408326SSeung-Woo Kim win_data->chroma_dma_addr = overlay->dma_addr[1]; 950d8408326SSeung-Woo Kim win_data->pixel_format = overlay->pixel_format; 951d8408326SSeung-Woo Kim win_data->bpp = overlay->bpp; 952d8408326SSeung-Woo Kim 953d8408326SSeung-Woo Kim win_data->crtc_x = overlay->crtc_x; 954d8408326SSeung-Woo Kim win_data->crtc_y = overlay->crtc_y; 955d8408326SSeung-Woo Kim win_data->crtc_width = overlay->crtc_width; 956d8408326SSeung-Woo Kim win_data->crtc_height = overlay->crtc_height; 957d8408326SSeung-Woo Kim 958d8408326SSeung-Woo Kim win_data->fb_x = overlay->fb_x; 959d8408326SSeung-Woo Kim win_data->fb_y = overlay->fb_y; 960d8408326SSeung-Woo Kim win_data->fb_width = overlay->fb_width; 961d8408326SSeung-Woo Kim win_data->fb_height = overlay->fb_height; 9628dcb96b6SSeung-Woo Kim win_data->src_width = overlay->src_width; 9638dcb96b6SSeung-Woo Kim win_data->src_height = overlay->src_height; 964d8408326SSeung-Woo Kim 965d8408326SSeung-Woo Kim win_data->mode_width = overlay->mode_width; 966d8408326SSeung-Woo Kim win_data->mode_height = overlay->mode_height; 967d8408326SSeung-Woo Kim 968d8408326SSeung-Woo Kim win_data->scan_flags = overlay->scan_flag; 969d8408326SSeung-Woo Kim } 970d8408326SSeung-Woo Kim 971f041b257SSean Paul static void mixer_win_commit(struct exynos_drm_manager *mgr, int zpos) 972d8408326SSeung-Woo Kim { 973f041b257SSean Paul struct mixer_context *mixer_ctx = mgr->ctx; 974f041b257SSean Paul int win = zpos == DEFAULT_ZPOS ? MIXER_DEFAULT_WIN : zpos; 975d8408326SSeung-Woo Kim 976cbc4c33dSYoungJun Cho DRM_DEBUG_KMS("win: %d\n", win); 977d8408326SSeung-Woo Kim 978dda9012bSShirish S mutex_lock(&mixer_ctx->mixer_mutex); 979dda9012bSShirish S if (!mixer_ctx->powered) { 980dda9012bSShirish S mutex_unlock(&mixer_ctx->mixer_mutex); 981dda9012bSShirish S return; 982dda9012bSShirish S } 983dda9012bSShirish S mutex_unlock(&mixer_ctx->mixer_mutex); 984dda9012bSShirish S 9851b8e5747SRahul Sharma if (win > 1 && mixer_ctx->vp_enabled) 986d8408326SSeung-Woo Kim vp_video_buffer(mixer_ctx, win); 987d8408326SSeung-Woo Kim else 988d8408326SSeung-Woo Kim mixer_graph_buffer(mixer_ctx, win); 989db43fd16SPrathyush K 990db43fd16SPrathyush K mixer_ctx->win_data[win].enabled = true; 991d8408326SSeung-Woo Kim } 992d8408326SSeung-Woo Kim 993f041b257SSean Paul static void mixer_win_disable(struct exynos_drm_manager *mgr, int zpos) 994d8408326SSeung-Woo Kim { 995f041b257SSean Paul struct mixer_context *mixer_ctx = mgr->ctx; 996d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 997f041b257SSean Paul int win = zpos == DEFAULT_ZPOS ? MIXER_DEFAULT_WIN : zpos; 998d8408326SSeung-Woo Kim unsigned long flags; 999d8408326SSeung-Woo Kim 1000cbc4c33dSYoungJun Cho DRM_DEBUG_KMS("win: %d\n", win); 1001d8408326SSeung-Woo Kim 1002db43fd16SPrathyush K mutex_lock(&mixer_ctx->mixer_mutex); 1003db43fd16SPrathyush K if (!mixer_ctx->powered) { 1004db43fd16SPrathyush K mutex_unlock(&mixer_ctx->mixer_mutex); 1005db43fd16SPrathyush K mixer_ctx->win_data[win].resume = false; 1006db43fd16SPrathyush K return; 1007db43fd16SPrathyush K } 1008db43fd16SPrathyush K mutex_unlock(&mixer_ctx->mixer_mutex); 1009db43fd16SPrathyush K 1010d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 1011d8408326SSeung-Woo Kim mixer_vsync_set_update(mixer_ctx, false); 1012d8408326SSeung-Woo Kim 1013d8408326SSeung-Woo Kim mixer_cfg_layer(mixer_ctx, win, false); 1014d8408326SSeung-Woo Kim 1015d8408326SSeung-Woo Kim mixer_vsync_set_update(mixer_ctx, true); 1016d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 1017db43fd16SPrathyush K 1018db43fd16SPrathyush K mixer_ctx->win_data[win].enabled = false; 1019d8408326SSeung-Woo Kim } 1020d8408326SSeung-Woo Kim 1021f041b257SSean Paul static void mixer_wait_for_vblank(struct exynos_drm_manager *mgr) 10220ea6822fSRahul Sharma { 1023f041b257SSean Paul struct mixer_context *mixer_ctx = mgr->ctx; 10248137a2e2SPrathyush K 10256e95d5e6SPrathyush K mutex_lock(&mixer_ctx->mixer_mutex); 10266e95d5e6SPrathyush K if (!mixer_ctx->powered) { 10276e95d5e6SPrathyush K mutex_unlock(&mixer_ctx->mixer_mutex); 10286e95d5e6SPrathyush K return; 10296e95d5e6SPrathyush K } 10306e95d5e6SPrathyush K mutex_unlock(&mixer_ctx->mixer_mutex); 10316e95d5e6SPrathyush K 10325d39b9eeSRahul Sharma drm_vblank_get(mgr->crtc->dev, mixer_ctx->pipe); 10335d39b9eeSRahul Sharma 10346e95d5e6SPrathyush K atomic_set(&mixer_ctx->wait_vsync_event, 1); 10356e95d5e6SPrathyush K 10366e95d5e6SPrathyush K /* 10376e95d5e6SPrathyush K * wait for MIXER to signal VSYNC interrupt or return after 10386e95d5e6SPrathyush K * timeout which is set to 50ms (refresh rate of 20). 10396e95d5e6SPrathyush K */ 10406e95d5e6SPrathyush K if (!wait_event_timeout(mixer_ctx->wait_vsync_queue, 10416e95d5e6SPrathyush K !atomic_read(&mixer_ctx->wait_vsync_event), 1042bfd8303aSDaniel Vetter HZ/20)) 10438137a2e2SPrathyush K DRM_DEBUG_KMS("vblank wait timed out.\n"); 10445d39b9eeSRahul Sharma 10455d39b9eeSRahul Sharma drm_vblank_put(mgr->crtc->dev, mixer_ctx->pipe); 10468137a2e2SPrathyush K } 10478137a2e2SPrathyush K 1048f041b257SSean Paul static void mixer_window_suspend(struct exynos_drm_manager *mgr) 1049db43fd16SPrathyush K { 1050f041b257SSean Paul struct mixer_context *ctx = mgr->ctx; 1051db43fd16SPrathyush K struct hdmi_win_data *win_data; 1052db43fd16SPrathyush K int i; 1053db43fd16SPrathyush K 1054db43fd16SPrathyush K for (i = 0; i < MIXER_WIN_NR; i++) { 1055db43fd16SPrathyush K win_data = &ctx->win_data[i]; 1056db43fd16SPrathyush K win_data->resume = win_data->enabled; 1057f041b257SSean Paul mixer_win_disable(mgr, i); 1058db43fd16SPrathyush K } 1059f041b257SSean Paul mixer_wait_for_vblank(mgr); 1060db43fd16SPrathyush K } 1061db43fd16SPrathyush K 1062f041b257SSean Paul static void mixer_window_resume(struct exynos_drm_manager *mgr) 1063db43fd16SPrathyush K { 1064f041b257SSean Paul struct mixer_context *ctx = mgr->ctx; 1065db43fd16SPrathyush K struct hdmi_win_data *win_data; 1066db43fd16SPrathyush K int i; 1067db43fd16SPrathyush K 1068db43fd16SPrathyush K for (i = 0; i < MIXER_WIN_NR; i++) { 1069db43fd16SPrathyush K win_data = &ctx->win_data[i]; 1070db43fd16SPrathyush K win_data->enabled = win_data->resume; 1071db43fd16SPrathyush K win_data->resume = false; 107287244fa6SSean Paul if (win_data->enabled) 1073f041b257SSean Paul mixer_win_commit(mgr, i); 1074db43fd16SPrathyush K } 1075db43fd16SPrathyush K } 1076db43fd16SPrathyush K 1077f041b257SSean Paul static void mixer_poweron(struct exynos_drm_manager *mgr) 1078db43fd16SPrathyush K { 1079f041b257SSean Paul struct mixer_context *ctx = mgr->ctx; 1080db43fd16SPrathyush K struct mixer_resources *res = &ctx->mixer_res; 1081db43fd16SPrathyush K 1082db43fd16SPrathyush K mutex_lock(&ctx->mixer_mutex); 1083db43fd16SPrathyush K if (ctx->powered) { 1084db43fd16SPrathyush K mutex_unlock(&ctx->mixer_mutex); 1085db43fd16SPrathyush K return; 1086db43fd16SPrathyush K } 1087b4bfa3c7SRahul Sharma 1088db43fd16SPrathyush K mutex_unlock(&ctx->mixer_mutex); 1089db43fd16SPrathyush K 1090af65c804SSean Paul pm_runtime_get_sync(ctx->dev); 1091af65c804SSean Paul 10920bfb1f8bSSean Paul clk_prepare_enable(res->mixer); 1093db43fd16SPrathyush K if (ctx->vp_enabled) { 10940bfb1f8bSSean Paul clk_prepare_enable(res->vp); 1095ff830c96SMarek Szyprowski if (ctx->has_sclk) 10960bfb1f8bSSean Paul clk_prepare_enable(res->sclk_mixer); 1097db43fd16SPrathyush K } 1098db43fd16SPrathyush K 1099b4bfa3c7SRahul Sharma mutex_lock(&ctx->mixer_mutex); 1100b4bfa3c7SRahul Sharma ctx->powered = true; 1101b4bfa3c7SRahul Sharma mutex_unlock(&ctx->mixer_mutex); 1102b4bfa3c7SRahul Sharma 1103d74ed937SRahul Sharma mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET); 1104d74ed937SRahul Sharma 1105db43fd16SPrathyush K mixer_reg_write(res, MXR_INT_EN, ctx->int_en); 1106db43fd16SPrathyush K mixer_win_reset(ctx); 1107db43fd16SPrathyush K 1108f041b257SSean Paul mixer_window_resume(mgr); 1109db43fd16SPrathyush K } 1110db43fd16SPrathyush K 1111f041b257SSean Paul static void mixer_poweroff(struct exynos_drm_manager *mgr) 1112db43fd16SPrathyush K { 1113f041b257SSean Paul struct mixer_context *ctx = mgr->ctx; 1114db43fd16SPrathyush K struct mixer_resources *res = &ctx->mixer_res; 1115db43fd16SPrathyush K 1116db43fd16SPrathyush K mutex_lock(&ctx->mixer_mutex); 1117b4bfa3c7SRahul Sharma if (!ctx->powered) { 1118b4bfa3c7SRahul Sharma mutex_unlock(&ctx->mixer_mutex); 1119b4bfa3c7SRahul Sharma return; 1120b4bfa3c7SRahul Sharma } 1121db43fd16SPrathyush K mutex_unlock(&ctx->mixer_mutex); 1122db43fd16SPrathyush K 1123381be025SRahul Sharma mixer_stop(ctx); 1124f041b257SSean Paul mixer_window_suspend(mgr); 1125db43fd16SPrathyush K 1126db43fd16SPrathyush K ctx->int_en = mixer_reg_read(res, MXR_INT_EN); 1127db43fd16SPrathyush K 1128b4bfa3c7SRahul Sharma mutex_lock(&ctx->mixer_mutex); 1129b4bfa3c7SRahul Sharma ctx->powered = false; 1130b4bfa3c7SRahul Sharma mutex_unlock(&ctx->mixer_mutex); 1131b4bfa3c7SRahul Sharma 11320bfb1f8bSSean Paul clk_disable_unprepare(res->mixer); 1133db43fd16SPrathyush K if (ctx->vp_enabled) { 11340bfb1f8bSSean Paul clk_disable_unprepare(res->vp); 1135ff830c96SMarek Szyprowski if (ctx->has_sclk) 11360bfb1f8bSSean Paul clk_disable_unprepare(res->sclk_mixer); 1137db43fd16SPrathyush K } 1138db43fd16SPrathyush K 1139af65c804SSean Paul pm_runtime_put_sync(ctx->dev); 1140db43fd16SPrathyush K } 1141db43fd16SPrathyush K 1142f041b257SSean Paul static void mixer_dpms(struct exynos_drm_manager *mgr, int mode) 1143db43fd16SPrathyush K { 1144db43fd16SPrathyush K switch (mode) { 1145db43fd16SPrathyush K case DRM_MODE_DPMS_ON: 1146af65c804SSean Paul mixer_poweron(mgr); 1147db43fd16SPrathyush K break; 1148db43fd16SPrathyush K case DRM_MODE_DPMS_STANDBY: 1149db43fd16SPrathyush K case DRM_MODE_DPMS_SUSPEND: 1150db43fd16SPrathyush K case DRM_MODE_DPMS_OFF: 1151af65c804SSean Paul mixer_poweroff(mgr); 1152db43fd16SPrathyush K break; 1153db43fd16SPrathyush K default: 1154db43fd16SPrathyush K DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode); 1155db43fd16SPrathyush K break; 1156db43fd16SPrathyush K } 1157db43fd16SPrathyush K } 1158db43fd16SPrathyush K 1159f041b257SSean Paul /* Only valid for Mixer version 16.0.33.0 */ 1160f041b257SSean Paul int mixer_check_mode(struct drm_display_mode *mode) 1161f041b257SSean Paul { 1162f041b257SSean Paul u32 w, h; 1163f041b257SSean Paul 1164f041b257SSean Paul w = mode->hdisplay; 1165f041b257SSean Paul h = mode->vdisplay; 1166f041b257SSean Paul 1167f041b257SSean Paul DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n", 1168f041b257SSean Paul mode->hdisplay, mode->vdisplay, mode->vrefresh, 1169f041b257SSean Paul (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0); 1170f041b257SSean Paul 1171f041b257SSean Paul if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) || 1172f041b257SSean Paul (w >= 1024 && w <= 1280 && h >= 576 && h <= 720) || 1173f041b257SSean Paul (w >= 1664 && w <= 1920 && h >= 936 && h <= 1080)) 1174f041b257SSean Paul return 0; 1175f041b257SSean Paul 1176f041b257SSean Paul return -EINVAL; 1177f041b257SSean Paul } 1178f041b257SSean Paul 1179f041b257SSean Paul static struct exynos_drm_manager_ops mixer_manager_ops = { 1180f041b257SSean Paul .dpms = mixer_dpms, 1181d8408326SSeung-Woo Kim .enable_vblank = mixer_enable_vblank, 1182d8408326SSeung-Woo Kim .disable_vblank = mixer_disable_vblank, 11838137a2e2SPrathyush K .wait_for_vblank = mixer_wait_for_vblank, 1184d8408326SSeung-Woo Kim .win_mode_set = mixer_win_mode_set, 1185d8408326SSeung-Woo Kim .win_commit = mixer_win_commit, 1186d8408326SSeung-Woo Kim .win_disable = mixer_win_disable, 1187f041b257SSean Paul }; 11880ea6822fSRahul Sharma 1189def5e095SRahul Sharma static struct mixer_drv_data exynos5420_mxr_drv_data = { 1190def5e095SRahul Sharma .version = MXR_VER_128_0_0_184, 1191def5e095SRahul Sharma .is_vp_enabled = 0, 1192def5e095SRahul Sharma }; 1193def5e095SRahul Sharma 1194cc57caf0SRahul Sharma static struct mixer_drv_data exynos5250_mxr_drv_data = { 1195aaf8b49eSRahul Sharma .version = MXR_VER_16_0_33_0, 1196aaf8b49eSRahul Sharma .is_vp_enabled = 0, 1197aaf8b49eSRahul Sharma }; 1198aaf8b49eSRahul Sharma 1199ff830c96SMarek Szyprowski static struct mixer_drv_data exynos4212_mxr_drv_data = { 1200ff830c96SMarek Szyprowski .version = MXR_VER_0_0_0_16, 1201ff830c96SMarek Szyprowski .is_vp_enabled = 1, 1202ff830c96SMarek Szyprowski }; 1203ff830c96SMarek Szyprowski 1204cc57caf0SRahul Sharma static struct mixer_drv_data exynos4210_mxr_drv_data = { 12051e123441SRahul Sharma .version = MXR_VER_0_0_0_16, 12061b8e5747SRahul Sharma .is_vp_enabled = 1, 1207ff830c96SMarek Szyprowski .has_sclk = 1, 12081e123441SRahul Sharma }; 12091e123441SRahul Sharma 12101e123441SRahul Sharma static struct platform_device_id mixer_driver_types[] = { 12111e123441SRahul Sharma { 12121e123441SRahul Sharma .name = "s5p-mixer", 1213cc57caf0SRahul Sharma .driver_data = (unsigned long)&exynos4210_mxr_drv_data, 12141e123441SRahul Sharma }, { 1215aaf8b49eSRahul Sharma .name = "exynos5-mixer", 1216cc57caf0SRahul Sharma .driver_data = (unsigned long)&exynos5250_mxr_drv_data, 1217aaf8b49eSRahul Sharma }, { 1218aaf8b49eSRahul Sharma /* end node */ 1219aaf8b49eSRahul Sharma } 1220aaf8b49eSRahul Sharma }; 1221aaf8b49eSRahul Sharma 1222aaf8b49eSRahul Sharma static struct of_device_id mixer_match_types[] = { 1223aaf8b49eSRahul Sharma { 1224ff830c96SMarek Szyprowski .compatible = "samsung,exynos4210-mixer", 1225ff830c96SMarek Szyprowski .data = &exynos4210_mxr_drv_data, 1226ff830c96SMarek Szyprowski }, { 1227ff830c96SMarek Szyprowski .compatible = "samsung,exynos4212-mixer", 1228ff830c96SMarek Szyprowski .data = &exynos4212_mxr_drv_data, 1229ff830c96SMarek Szyprowski }, { 1230aaf8b49eSRahul Sharma .compatible = "samsung,exynos5-mixer", 1231cc57caf0SRahul Sharma .data = &exynos5250_mxr_drv_data, 1232cc57caf0SRahul Sharma }, { 1233cc57caf0SRahul Sharma .compatible = "samsung,exynos5250-mixer", 1234cc57caf0SRahul Sharma .data = &exynos5250_mxr_drv_data, 1235aaf8b49eSRahul Sharma }, { 1236def5e095SRahul Sharma .compatible = "samsung,exynos5420-mixer", 1237def5e095SRahul Sharma .data = &exynos5420_mxr_drv_data, 1238def5e095SRahul Sharma }, { 12391e123441SRahul Sharma /* end node */ 12401e123441SRahul Sharma } 12411e123441SRahul Sharma }; 124239b58a39SSjoerd Simons MODULE_DEVICE_TABLE(of, mixer_match_types); 12431e123441SRahul Sharma 1244f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data) 1245d8408326SSeung-Woo Kim { 1246*8103ef1bSAndrzej Hajda struct mixer_context *ctx = dev_get_drvdata(dev); 1247f37cd5e8SInki Dae struct drm_device *drm_dev = data; 1248f37cd5e8SInki Dae int ret; 1249d8408326SSeung-Woo Kim 1250*8103ef1bSAndrzej Hajda ret = mixer_initialize(&ctx->manager, drm_dev); 1251*8103ef1bSAndrzej Hajda if (ret) 1252*8103ef1bSAndrzej Hajda return ret; 1253*8103ef1bSAndrzej Hajda 1254*8103ef1bSAndrzej Hajda ret = exynos_drm_crtc_create(&ctx->manager); 1255*8103ef1bSAndrzej Hajda if (ret) { 1256*8103ef1bSAndrzej Hajda mixer_mgr_remove(&ctx->manager); 1257*8103ef1bSAndrzej Hajda return ret; 1258*8103ef1bSAndrzej Hajda } 1259*8103ef1bSAndrzej Hajda 1260*8103ef1bSAndrzej Hajda pm_runtime_enable(dev); 1261*8103ef1bSAndrzej Hajda 1262*8103ef1bSAndrzej Hajda return 0; 1263*8103ef1bSAndrzej Hajda } 1264*8103ef1bSAndrzej Hajda 1265*8103ef1bSAndrzej Hajda static void mixer_unbind(struct device *dev, struct device *master, void *data) 1266*8103ef1bSAndrzej Hajda { 1267*8103ef1bSAndrzej Hajda struct mixer_context *ctx = dev_get_drvdata(dev); 1268*8103ef1bSAndrzej Hajda 1269*8103ef1bSAndrzej Hajda mixer_mgr_remove(&ctx->manager); 1270*8103ef1bSAndrzej Hajda 1271*8103ef1bSAndrzej Hajda pm_runtime_disable(dev); 1272*8103ef1bSAndrzej Hajda } 1273*8103ef1bSAndrzej Hajda 1274*8103ef1bSAndrzej Hajda static const struct component_ops mixer_component_ops = { 1275*8103ef1bSAndrzej Hajda .bind = mixer_bind, 1276*8103ef1bSAndrzej Hajda .unbind = mixer_unbind, 1277*8103ef1bSAndrzej Hajda }; 1278*8103ef1bSAndrzej Hajda 1279*8103ef1bSAndrzej Hajda static int mixer_probe(struct platform_device *pdev) 1280*8103ef1bSAndrzej Hajda { 1281*8103ef1bSAndrzej Hajda struct device *dev = &pdev->dev; 1282*8103ef1bSAndrzej Hajda struct mixer_drv_data *drv; 1283*8103ef1bSAndrzej Hajda struct mixer_context *ctx; 1284*8103ef1bSAndrzej Hajda int ret; 1285d8408326SSeung-Woo Kim 1286f041b257SSean Paul ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 1287f041b257SSean Paul if (!ctx) { 1288f041b257SSean Paul DRM_ERROR("failed to alloc mixer context.\n"); 1289d8408326SSeung-Woo Kim return -ENOMEM; 1290f041b257SSean Paul } 1291d8408326SSeung-Woo Kim 1292cf8fc4f1SJoonyoung Shim mutex_init(&ctx->mixer_mutex); 1293cf8fc4f1SJoonyoung Shim 1294*8103ef1bSAndrzej Hajda ctx->manager.type = EXYNOS_DISPLAY_TYPE_HDMI; 1295*8103ef1bSAndrzej Hajda ctx->manager.ops = &mixer_manager_ops; 1296*8103ef1bSAndrzej Hajda 1297aaf8b49eSRahul Sharma if (dev->of_node) { 1298aaf8b49eSRahul Sharma const struct of_device_id *match; 1299*8103ef1bSAndrzej Hajda 1300e436b09dSSachin Kamat match = of_match_node(mixer_match_types, dev->of_node); 13012cdc53b3SRahul Sharma drv = (struct mixer_drv_data *)match->data; 1302aaf8b49eSRahul Sharma } else { 1303aaf8b49eSRahul Sharma drv = (struct mixer_drv_data *) 1304aaf8b49eSRahul Sharma platform_get_device_id(pdev)->driver_data; 1305aaf8b49eSRahul Sharma } 1306aaf8b49eSRahul Sharma 13074551789fSSean Paul ctx->pdev = pdev; 1308d873ab99SSeung-Woo Kim ctx->dev = dev; 13091b8e5747SRahul Sharma ctx->vp_enabled = drv->is_vp_enabled; 1310ff830c96SMarek Szyprowski ctx->has_sclk = drv->has_sclk; 13111e123441SRahul Sharma ctx->mxr_ver = drv->version; 131257ed0f7bSDaniel Vetter init_waitqueue_head(&ctx->wait_vsync_queue); 13136e95d5e6SPrathyush K atomic_set(&ctx->wait_vsync_event, 0); 1314*8103ef1bSAndrzej Hajda ctx->manager.ctx = ctx; 1315d8408326SSeung-Woo Kim 1316*8103ef1bSAndrzej Hajda platform_set_drvdata(pdev, ctx); 1317df5225bcSInki Dae 1318df5225bcSInki Dae ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC, 1319*8103ef1bSAndrzej Hajda ctx->manager.type); 1320df5225bcSInki Dae if (ret) 1321df5225bcSInki Dae return ret; 1322df5225bcSInki Dae 1323df5225bcSInki Dae ret = component_add(&pdev->dev, &mixer_component_ops); 1324*8103ef1bSAndrzej Hajda if (ret) { 1325df5225bcSInki Dae exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC); 1326*8103ef1bSAndrzej Hajda return ret; 1327*8103ef1bSAndrzej Hajda } 1328*8103ef1bSAndrzej Hajda 1329*8103ef1bSAndrzej Hajda pm_runtime_enable(dev); 1330df5225bcSInki Dae 1331df5225bcSInki Dae return ret; 1332f37cd5e8SInki Dae } 1333f37cd5e8SInki Dae 1334d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev) 1335d8408326SSeung-Woo Kim { 1336*8103ef1bSAndrzej Hajda pm_runtime_disable(&pdev->dev); 1337*8103ef1bSAndrzej Hajda 1338df5225bcSInki Dae component_del(&pdev->dev, &mixer_component_ops); 1339df5225bcSInki Dae exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC); 1340df5225bcSInki Dae 1341d8408326SSeung-Woo Kim return 0; 1342d8408326SSeung-Woo Kim } 1343d8408326SSeung-Woo Kim 1344d8408326SSeung-Woo Kim struct platform_driver mixer_driver = { 1345d8408326SSeung-Woo Kim .driver = { 1346aaf8b49eSRahul Sharma .name = "exynos-mixer", 1347d8408326SSeung-Woo Kim .owner = THIS_MODULE, 1348aaf8b49eSRahul Sharma .of_match_table = mixer_match_types, 1349d8408326SSeung-Woo Kim }, 1350d8408326SSeung-Woo Kim .probe = mixer_probe, 135156550d94SGreg Kroah-Hartman .remove = mixer_remove, 13521e123441SRahul Sharma .id_table = mixer_driver_types, 1353d8408326SSeung-Woo Kim }; 1354