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/module.h> 27d8408326SSeung-Woo Kim #include <linux/platform_device.h> 28d8408326SSeung-Woo Kim #include <linux/interrupt.h> 29d8408326SSeung-Woo Kim #include <linux/irq.h> 30d8408326SSeung-Woo Kim #include <linux/delay.h> 31d8408326SSeung-Woo Kim #include <linux/pm_runtime.h> 32d8408326SSeung-Woo Kim #include <linux/clk.h> 33d8408326SSeung-Woo Kim #include <linux/regulator/consumer.h> 34d8408326SSeung-Woo Kim 35d8408326SSeung-Woo Kim #include <drm/exynos_drm.h> 36d8408326SSeung-Woo Kim 37d8408326SSeung-Woo Kim #include "exynos_drm_drv.h" 38d8408326SSeung-Woo Kim #include "exynos_drm_hdmi.h" 391055b39fSInki Dae #include "exynos_drm_iommu.h" 4022b21ae6SJoonyoung Shim 41d8408326SSeung-Woo Kim #define get_mixer_context(dev) platform_get_drvdata(to_platform_device(dev)) 42d8408326SSeung-Woo Kim 4322b21ae6SJoonyoung Shim struct hdmi_win_data { 4422b21ae6SJoonyoung Shim dma_addr_t dma_addr; 4522b21ae6SJoonyoung Shim dma_addr_t chroma_dma_addr; 4622b21ae6SJoonyoung Shim uint32_t pixel_format; 4722b21ae6SJoonyoung Shim unsigned int bpp; 4822b21ae6SJoonyoung Shim unsigned int crtc_x; 4922b21ae6SJoonyoung Shim unsigned int crtc_y; 5022b21ae6SJoonyoung Shim unsigned int crtc_width; 5122b21ae6SJoonyoung Shim unsigned int crtc_height; 5222b21ae6SJoonyoung Shim unsigned int fb_x; 5322b21ae6SJoonyoung Shim unsigned int fb_y; 5422b21ae6SJoonyoung Shim unsigned int fb_width; 5522b21ae6SJoonyoung Shim unsigned int fb_height; 568dcb96b6SSeung-Woo Kim unsigned int src_width; 578dcb96b6SSeung-Woo Kim unsigned int src_height; 5822b21ae6SJoonyoung Shim unsigned int mode_width; 5922b21ae6SJoonyoung Shim unsigned int mode_height; 6022b21ae6SJoonyoung Shim unsigned int scan_flags; 61db43fd16SPrathyush K bool enabled; 62db43fd16SPrathyush K bool resume; 6322b21ae6SJoonyoung Shim }; 6422b21ae6SJoonyoung Shim 6522b21ae6SJoonyoung Shim struct mixer_resources { 6622b21ae6SJoonyoung Shim int irq; 6722b21ae6SJoonyoung Shim void __iomem *mixer_regs; 6822b21ae6SJoonyoung Shim void __iomem *vp_regs; 6922b21ae6SJoonyoung Shim spinlock_t reg_slock; 7022b21ae6SJoonyoung Shim struct clk *mixer; 7122b21ae6SJoonyoung Shim struct clk *vp; 7222b21ae6SJoonyoung Shim struct clk *sclk_mixer; 7322b21ae6SJoonyoung Shim struct clk *sclk_hdmi; 7422b21ae6SJoonyoung Shim struct clk *sclk_dac; 7522b21ae6SJoonyoung Shim }; 7622b21ae6SJoonyoung Shim 771e123441SRahul Sharma enum mixer_version_id { 781e123441SRahul Sharma MXR_VER_0_0_0_16, 791e123441SRahul Sharma MXR_VER_16_0_33_0, 801e123441SRahul Sharma }; 811e123441SRahul Sharma 8222b21ae6SJoonyoung Shim struct mixer_context { 83cf8fc4f1SJoonyoung Shim struct device *dev; 841055b39fSInki Dae struct drm_device *drm_dev; 8522b21ae6SJoonyoung Shim int pipe; 8622b21ae6SJoonyoung Shim bool interlace; 87cf8fc4f1SJoonyoung Shim bool powered; 881b8e5747SRahul Sharma bool vp_enabled; 89cf8fc4f1SJoonyoung Shim u32 int_en; 9022b21ae6SJoonyoung Shim 91cf8fc4f1SJoonyoung Shim struct mutex mixer_mutex; 9222b21ae6SJoonyoung Shim struct mixer_resources mixer_res; 93a634dd54SJoonyoung Shim struct hdmi_win_data win_data[MIXER_WIN_NR]; 941e123441SRahul Sharma enum mixer_version_id mxr_ver; 951055b39fSInki Dae void *parent_ctx; 966e95d5e6SPrathyush K wait_queue_head_t wait_vsync_queue; 976e95d5e6SPrathyush K atomic_t wait_vsync_event; 981e123441SRahul Sharma }; 991e123441SRahul Sharma 1001e123441SRahul Sharma struct mixer_drv_data { 1011e123441SRahul Sharma enum mixer_version_id version; 1021b8e5747SRahul Sharma bool is_vp_enabled; 10322b21ae6SJoonyoung Shim }; 10422b21ae6SJoonyoung Shim 105d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = { 106d8408326SSeung-Woo Kim 0, -1, -1, -1, -1, -1, -1, -1, 107d8408326SSeung-Woo Kim -1, -1, -1, -1, -1, 0, 0, 0, 108d8408326SSeung-Woo Kim 0, 2, 4, 5, 6, 6, 6, 6, 109d8408326SSeung-Woo Kim 6, 5, 5, 4, 3, 2, 1, 1, 110d8408326SSeung-Woo Kim 0, -6, -12, -16, -18, -20, -21, -20, 111d8408326SSeung-Woo Kim -20, -18, -16, -13, -10, -8, -5, -2, 112d8408326SSeung-Woo Kim 127, 126, 125, 121, 114, 107, 99, 89, 113d8408326SSeung-Woo Kim 79, 68, 57, 46, 35, 25, 16, 8, 114d8408326SSeung-Woo Kim }; 115d8408326SSeung-Woo Kim 116d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = { 117d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7, 118d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0, 119d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81, 120d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5, 121d8408326SSeung-Woo Kim 0, 5, 11, 19, 27, 37, 48, 59, 122d8408326SSeung-Woo Kim 70, 81, 92, 102, 111, 118, 124, 126, 123d8408326SSeung-Woo Kim 0, 0, -1, -1, -2, -3, -4, -5, 124d8408326SSeung-Woo Kim -6, -7, -8, -8, -8, -8, -6, -3, 125d8408326SSeung-Woo Kim }; 126d8408326SSeung-Woo Kim 127d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = { 128d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7, 129d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0, 130d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81, 131d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5, 132d8408326SSeung-Woo Kim }; 133d8408326SSeung-Woo Kim 134d8408326SSeung-Woo Kim static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id) 135d8408326SSeung-Woo Kim { 136d8408326SSeung-Woo Kim return readl(res->vp_regs + reg_id); 137d8408326SSeung-Woo Kim } 138d8408326SSeung-Woo Kim 139d8408326SSeung-Woo Kim static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id, 140d8408326SSeung-Woo Kim u32 val) 141d8408326SSeung-Woo Kim { 142d8408326SSeung-Woo Kim writel(val, res->vp_regs + reg_id); 143d8408326SSeung-Woo Kim } 144d8408326SSeung-Woo Kim 145d8408326SSeung-Woo Kim static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id, 146d8408326SSeung-Woo Kim u32 val, u32 mask) 147d8408326SSeung-Woo Kim { 148d8408326SSeung-Woo Kim u32 old = vp_reg_read(res, reg_id); 149d8408326SSeung-Woo Kim 150d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask); 151d8408326SSeung-Woo Kim writel(val, res->vp_regs + reg_id); 152d8408326SSeung-Woo Kim } 153d8408326SSeung-Woo Kim 154d8408326SSeung-Woo Kim static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id) 155d8408326SSeung-Woo Kim { 156d8408326SSeung-Woo Kim return readl(res->mixer_regs + reg_id); 157d8408326SSeung-Woo Kim } 158d8408326SSeung-Woo Kim 159d8408326SSeung-Woo Kim static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id, 160d8408326SSeung-Woo Kim u32 val) 161d8408326SSeung-Woo Kim { 162d8408326SSeung-Woo Kim writel(val, res->mixer_regs + reg_id); 163d8408326SSeung-Woo Kim } 164d8408326SSeung-Woo Kim 165d8408326SSeung-Woo Kim static inline void mixer_reg_writemask(struct mixer_resources *res, 166d8408326SSeung-Woo Kim u32 reg_id, u32 val, u32 mask) 167d8408326SSeung-Woo Kim { 168d8408326SSeung-Woo Kim u32 old = mixer_reg_read(res, reg_id); 169d8408326SSeung-Woo Kim 170d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask); 171d8408326SSeung-Woo Kim writel(val, res->mixer_regs + reg_id); 172d8408326SSeung-Woo Kim } 173d8408326SSeung-Woo Kim 174d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx) 175d8408326SSeung-Woo Kim { 176d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \ 177d8408326SSeung-Woo Kim do { \ 178d8408326SSeung-Woo Kim DRM_DEBUG_KMS(#reg_id " = %08x\n", \ 179d8408326SSeung-Woo Kim (u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \ 180d8408326SSeung-Woo Kim } while (0) 181d8408326SSeung-Woo Kim 182d8408326SSeung-Woo Kim DUMPREG(MXR_STATUS); 183d8408326SSeung-Woo Kim DUMPREG(MXR_CFG); 184d8408326SSeung-Woo Kim DUMPREG(MXR_INT_EN); 185d8408326SSeung-Woo Kim DUMPREG(MXR_INT_STATUS); 186d8408326SSeung-Woo Kim 187d8408326SSeung-Woo Kim DUMPREG(MXR_LAYER_CFG); 188d8408326SSeung-Woo Kim DUMPREG(MXR_VIDEO_CFG); 189d8408326SSeung-Woo Kim 190d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_CFG); 191d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_BASE); 192d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SPAN); 193d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_WH); 194d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SXY); 195d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_DXY); 196d8408326SSeung-Woo Kim 197d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_CFG); 198d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_BASE); 199d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SPAN); 200d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_WH); 201d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SXY); 202d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_DXY); 203d8408326SSeung-Woo Kim #undef DUMPREG 204d8408326SSeung-Woo Kim } 205d8408326SSeung-Woo Kim 206d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx) 207d8408326SSeung-Woo Kim { 208d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \ 209d8408326SSeung-Woo Kim do { \ 210d8408326SSeung-Woo Kim DRM_DEBUG_KMS(#reg_id " = %08x\n", \ 211d8408326SSeung-Woo Kim (u32) readl(ctx->mixer_res.vp_regs + reg_id)); \ 212d8408326SSeung-Woo Kim } while (0) 213d8408326SSeung-Woo Kim 214d8408326SSeung-Woo Kim DUMPREG(VP_ENABLE); 215d8408326SSeung-Woo Kim DUMPREG(VP_SRESET); 216d8408326SSeung-Woo Kim DUMPREG(VP_SHADOW_UPDATE); 217d8408326SSeung-Woo Kim DUMPREG(VP_FIELD_ID); 218d8408326SSeung-Woo Kim DUMPREG(VP_MODE); 219d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_Y); 220d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_C); 221d8408326SSeung-Woo Kim DUMPREG(VP_PER_RATE_CTRL); 222d8408326SSeung-Woo Kim DUMPREG(VP_TOP_Y_PTR); 223d8408326SSeung-Woo Kim DUMPREG(VP_BOT_Y_PTR); 224d8408326SSeung-Woo Kim DUMPREG(VP_TOP_C_PTR); 225d8408326SSeung-Woo Kim DUMPREG(VP_BOT_C_PTR); 226d8408326SSeung-Woo Kim DUMPREG(VP_ENDIAN_MODE); 227d8408326SSeung-Woo Kim DUMPREG(VP_SRC_H_POSITION); 228d8408326SSeung-Woo Kim DUMPREG(VP_SRC_V_POSITION); 229d8408326SSeung-Woo Kim DUMPREG(VP_SRC_WIDTH); 230d8408326SSeung-Woo Kim DUMPREG(VP_SRC_HEIGHT); 231d8408326SSeung-Woo Kim DUMPREG(VP_DST_H_POSITION); 232d8408326SSeung-Woo Kim DUMPREG(VP_DST_V_POSITION); 233d8408326SSeung-Woo Kim DUMPREG(VP_DST_WIDTH); 234d8408326SSeung-Woo Kim DUMPREG(VP_DST_HEIGHT); 235d8408326SSeung-Woo Kim DUMPREG(VP_H_RATIO); 236d8408326SSeung-Woo Kim DUMPREG(VP_V_RATIO); 237d8408326SSeung-Woo Kim 238d8408326SSeung-Woo Kim #undef DUMPREG 239d8408326SSeung-Woo Kim } 240d8408326SSeung-Woo Kim 241d8408326SSeung-Woo Kim static inline void vp_filter_set(struct mixer_resources *res, 242d8408326SSeung-Woo Kim int reg_id, const u8 *data, unsigned int size) 243d8408326SSeung-Woo Kim { 244d8408326SSeung-Woo Kim /* assure 4-byte align */ 245d8408326SSeung-Woo Kim BUG_ON(size & 3); 246d8408326SSeung-Woo Kim for (; size; size -= 4, reg_id += 4, data += 4) { 247d8408326SSeung-Woo Kim u32 val = (data[0] << 24) | (data[1] << 16) | 248d8408326SSeung-Woo Kim (data[2] << 8) | data[3]; 249d8408326SSeung-Woo Kim vp_reg_write(res, reg_id, val); 250d8408326SSeung-Woo Kim } 251d8408326SSeung-Woo Kim } 252d8408326SSeung-Woo Kim 253d8408326SSeung-Woo Kim static void vp_default_filter(struct mixer_resources *res) 254d8408326SSeung-Woo Kim { 255d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY8_Y0_LL, 256e25e1b66SSachin Kamat filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8)); 257d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY4_Y0_LL, 258e25e1b66SSachin Kamat filter_y_vert_tap4, sizeof(filter_y_vert_tap4)); 259d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY4_C0_LL, 260e25e1b66SSachin Kamat filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4)); 261d8408326SSeung-Woo Kim } 262d8408326SSeung-Woo Kim 263d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable) 264d8408326SSeung-Woo Kim { 265d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 266d8408326SSeung-Woo Kim 267d8408326SSeung-Woo Kim /* block update on vsync */ 268d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_STATUS, enable ? 269d8408326SSeung-Woo Kim MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE); 270d8408326SSeung-Woo Kim 2711b8e5747SRahul Sharma if (ctx->vp_enabled) 272d8408326SSeung-Woo Kim vp_reg_write(res, VP_SHADOW_UPDATE, enable ? 273d8408326SSeung-Woo Kim VP_SHADOW_UPDATE_ENABLE : 0); 274d8408326SSeung-Woo Kim } 275d8408326SSeung-Woo Kim 276d8408326SSeung-Woo Kim static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height) 277d8408326SSeung-Woo Kim { 278d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 279d8408326SSeung-Woo Kim u32 val; 280d8408326SSeung-Woo Kim 281d8408326SSeung-Woo Kim /* choosing between interlace and progressive mode */ 282d8408326SSeung-Woo Kim val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE : 283d8408326SSeung-Woo Kim MXR_CFG_SCAN_PROGRASSIVE); 284d8408326SSeung-Woo Kim 285d8408326SSeung-Woo Kim /* choosing between porper HD and SD mode */ 286d8408326SSeung-Woo Kim if (height == 480) 287d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD; 288d8408326SSeung-Woo Kim else if (height == 576) 289d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD; 290d8408326SSeung-Woo Kim else if (height == 720) 291d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; 292d8408326SSeung-Woo Kim else if (height == 1080) 293d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD; 294d8408326SSeung-Woo Kim else 295d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; 296d8408326SSeung-Woo Kim 297d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK); 298d8408326SSeung-Woo Kim } 299d8408326SSeung-Woo Kim 300d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height) 301d8408326SSeung-Woo Kim { 302d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 303d8408326SSeung-Woo Kim u32 val; 304d8408326SSeung-Woo Kim 305d8408326SSeung-Woo Kim if (height == 480) { 306d8408326SSeung-Woo Kim val = MXR_CFG_RGB601_0_255; 307d8408326SSeung-Woo Kim } else if (height == 576) { 308d8408326SSeung-Woo Kim val = MXR_CFG_RGB601_0_255; 309d8408326SSeung-Woo Kim } else if (height == 720) { 310d8408326SSeung-Woo Kim val = MXR_CFG_RGB709_16_235; 311d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_Y, 312d8408326SSeung-Woo Kim (1 << 30) | (94 << 20) | (314 << 10) | 313d8408326SSeung-Woo Kim (32 << 0)); 314d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CB, 315d8408326SSeung-Woo Kim (972 << 20) | (851 << 10) | (225 << 0)); 316d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CR, 317d8408326SSeung-Woo Kim (225 << 20) | (820 << 10) | (1004 << 0)); 318d8408326SSeung-Woo Kim } else if (height == 1080) { 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 { 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 } 337d8408326SSeung-Woo Kim 338d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK); 339d8408326SSeung-Woo Kim } 340d8408326SSeung-Woo Kim 341d8408326SSeung-Woo Kim static void mixer_cfg_layer(struct mixer_context *ctx, int win, bool enable) 342d8408326SSeung-Woo Kim { 343d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 344d8408326SSeung-Woo Kim u32 val = enable ? ~0 : 0; 345d8408326SSeung-Woo Kim 346d8408326SSeung-Woo Kim switch (win) { 347d8408326SSeung-Woo Kim case 0: 348d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE); 349d8408326SSeung-Woo Kim break; 350d8408326SSeung-Woo Kim case 1: 351d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE); 352d8408326SSeung-Woo Kim break; 353d8408326SSeung-Woo Kim case 2: 3541b8e5747SRahul Sharma if (ctx->vp_enabled) { 355d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON); 3561b8e5747SRahul Sharma mixer_reg_writemask(res, MXR_CFG, val, 3571b8e5747SRahul Sharma MXR_CFG_VP_ENABLE); 3581b8e5747SRahul Sharma } 359d8408326SSeung-Woo Kim break; 360d8408326SSeung-Woo Kim } 361d8408326SSeung-Woo Kim } 362d8408326SSeung-Woo Kim 363d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx) 364d8408326SSeung-Woo Kim { 365d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 366d8408326SSeung-Woo Kim 367d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN); 368d8408326SSeung-Woo Kim 369d8408326SSeung-Woo Kim mixer_regs_dump(ctx); 370d8408326SSeung-Woo Kim } 371d8408326SSeung-Woo Kim 372d8408326SSeung-Woo Kim static void vp_video_buffer(struct mixer_context *ctx, int win) 373d8408326SSeung-Woo Kim { 374d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 375d8408326SSeung-Woo Kim unsigned long flags; 376d8408326SSeung-Woo Kim struct hdmi_win_data *win_data; 377d8408326SSeung-Woo Kim unsigned int x_ratio, y_ratio; 378d8408326SSeung-Woo Kim unsigned int buf_num; 379d8408326SSeung-Woo Kim dma_addr_t luma_addr[2], chroma_addr[2]; 380d8408326SSeung-Woo Kim bool tiled_mode = false; 381d8408326SSeung-Woo Kim bool crcb_mode = false; 382d8408326SSeung-Woo Kim u32 val; 383d8408326SSeung-Woo Kim 384d8408326SSeung-Woo Kim win_data = &ctx->win_data[win]; 385d8408326SSeung-Woo Kim 386d8408326SSeung-Woo Kim switch (win_data->pixel_format) { 387d8408326SSeung-Woo Kim case DRM_FORMAT_NV12MT: 388d8408326SSeung-Woo Kim tiled_mode = true; 389363b06aaSVille Syrjälä case DRM_FORMAT_NV12: 390d8408326SSeung-Woo Kim crcb_mode = false; 391d8408326SSeung-Woo Kim buf_num = 2; 392d8408326SSeung-Woo Kim break; 393d8408326SSeung-Woo Kim /* TODO: single buffer format NV12, NV21 */ 394d8408326SSeung-Woo Kim default: 395d8408326SSeung-Woo Kim /* ignore pixel format at disable time */ 396d8408326SSeung-Woo Kim if (!win_data->dma_addr) 397d8408326SSeung-Woo Kim break; 398d8408326SSeung-Woo Kim 399d8408326SSeung-Woo Kim DRM_ERROR("pixel format for vp is wrong [%d].\n", 400d8408326SSeung-Woo Kim win_data->pixel_format); 401d8408326SSeung-Woo Kim return; 402d8408326SSeung-Woo Kim } 403d8408326SSeung-Woo Kim 404d8408326SSeung-Woo Kim /* scaling feature: (src << 16) / dst */ 4058dcb96b6SSeung-Woo Kim x_ratio = (win_data->src_width << 16) / win_data->crtc_width; 4068dcb96b6SSeung-Woo Kim y_ratio = (win_data->src_height << 16) / win_data->crtc_height; 407d8408326SSeung-Woo Kim 408d8408326SSeung-Woo Kim if (buf_num == 2) { 409d8408326SSeung-Woo Kim luma_addr[0] = win_data->dma_addr; 410d8408326SSeung-Woo Kim chroma_addr[0] = win_data->chroma_dma_addr; 411d8408326SSeung-Woo Kim } else { 412d8408326SSeung-Woo Kim luma_addr[0] = win_data->dma_addr; 413d8408326SSeung-Woo Kim chroma_addr[0] = win_data->dma_addr 4148dcb96b6SSeung-Woo Kim + (win_data->fb_width * win_data->fb_height); 415d8408326SSeung-Woo Kim } 416d8408326SSeung-Woo Kim 417d8408326SSeung-Woo Kim if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE) { 418d8408326SSeung-Woo Kim ctx->interlace = true; 419d8408326SSeung-Woo Kim if (tiled_mode) { 420d8408326SSeung-Woo Kim luma_addr[1] = luma_addr[0] + 0x40; 421d8408326SSeung-Woo Kim chroma_addr[1] = chroma_addr[0] + 0x40; 422d8408326SSeung-Woo Kim } else { 4238dcb96b6SSeung-Woo Kim luma_addr[1] = luma_addr[0] + win_data->fb_width; 4248dcb96b6SSeung-Woo Kim chroma_addr[1] = chroma_addr[0] + win_data->fb_width; 425d8408326SSeung-Woo Kim } 426d8408326SSeung-Woo Kim } else { 427d8408326SSeung-Woo Kim ctx->interlace = false; 428d8408326SSeung-Woo Kim luma_addr[1] = 0; 429d8408326SSeung-Woo Kim chroma_addr[1] = 0; 430d8408326SSeung-Woo Kim } 431d8408326SSeung-Woo Kim 432d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 433d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, false); 434d8408326SSeung-Woo Kim 435d8408326SSeung-Woo Kim /* interlace or progressive scan mode */ 436d8408326SSeung-Woo Kim val = (ctx->interlace ? ~0 : 0); 437d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP); 438d8408326SSeung-Woo Kim 439d8408326SSeung-Woo Kim /* setup format */ 440d8408326SSeung-Woo Kim val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12); 441d8408326SSeung-Woo Kim val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR); 442d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK); 443d8408326SSeung-Woo Kim 444d8408326SSeung-Woo Kim /* setting size of input image */ 4458dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(win_data->fb_width) | 4468dcb96b6SSeung-Woo Kim VP_IMG_VSIZE(win_data->fb_height)); 447d8408326SSeung-Woo Kim /* chroma height has to reduced by 2 to avoid chroma distorions */ 4488dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(win_data->fb_width) | 4498dcb96b6SSeung-Woo Kim VP_IMG_VSIZE(win_data->fb_height / 2)); 450d8408326SSeung-Woo Kim 4518dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_SRC_WIDTH, win_data->src_width); 4528dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_SRC_HEIGHT, win_data->src_height); 453d8408326SSeung-Woo Kim vp_reg_write(res, VP_SRC_H_POSITION, 4548dcb96b6SSeung-Woo Kim VP_SRC_H_POSITION_VAL(win_data->fb_x)); 4558dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_SRC_V_POSITION, win_data->fb_y); 456d8408326SSeung-Woo Kim 4578dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_WIDTH, win_data->crtc_width); 4588dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_H_POSITION, win_data->crtc_x); 459d8408326SSeung-Woo Kim if (ctx->interlace) { 4608dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height / 2); 4618dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y / 2); 462d8408326SSeung-Woo Kim } else { 4638dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height); 4648dcb96b6SSeung-Woo Kim vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y); 465d8408326SSeung-Woo Kim } 466d8408326SSeung-Woo Kim 467d8408326SSeung-Woo Kim vp_reg_write(res, VP_H_RATIO, x_ratio); 468d8408326SSeung-Woo Kim vp_reg_write(res, VP_V_RATIO, y_ratio); 469d8408326SSeung-Woo Kim 470d8408326SSeung-Woo Kim vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE); 471d8408326SSeung-Woo Kim 472d8408326SSeung-Woo Kim /* set buffer address to vp */ 473d8408326SSeung-Woo Kim vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]); 474d8408326SSeung-Woo Kim vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]); 475d8408326SSeung-Woo Kim vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]); 476d8408326SSeung-Woo Kim vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]); 477d8408326SSeung-Woo Kim 4788dcb96b6SSeung-Woo Kim mixer_cfg_scan(ctx, win_data->mode_height); 4798dcb96b6SSeung-Woo Kim mixer_cfg_rgb_fmt(ctx, win_data->mode_height); 480d8408326SSeung-Woo Kim mixer_cfg_layer(ctx, win, true); 481d8408326SSeung-Woo Kim mixer_run(ctx); 482d8408326SSeung-Woo Kim 483d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, true); 484d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 485d8408326SSeung-Woo Kim 486d8408326SSeung-Woo Kim vp_regs_dump(ctx); 487d8408326SSeung-Woo Kim } 488d8408326SSeung-Woo Kim 489aaf8b49eSRahul Sharma static void mixer_layer_update(struct mixer_context *ctx) 490aaf8b49eSRahul Sharma { 491aaf8b49eSRahul Sharma struct mixer_resources *res = &ctx->mixer_res; 492aaf8b49eSRahul Sharma u32 val; 493aaf8b49eSRahul Sharma 494aaf8b49eSRahul Sharma val = mixer_reg_read(res, MXR_CFG); 495aaf8b49eSRahul Sharma 496aaf8b49eSRahul Sharma /* allow one update per vsync only */ 497aaf8b49eSRahul Sharma if (!(val & MXR_CFG_LAYER_UPDATE_COUNT_MASK)) 498aaf8b49eSRahul Sharma mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE); 499aaf8b49eSRahul Sharma } 500aaf8b49eSRahul Sharma 501d8408326SSeung-Woo Kim static void mixer_graph_buffer(struct mixer_context *ctx, int win) 502d8408326SSeung-Woo Kim { 503d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 504d8408326SSeung-Woo Kim unsigned long flags; 505d8408326SSeung-Woo Kim struct hdmi_win_data *win_data; 506d8408326SSeung-Woo Kim unsigned int x_ratio, y_ratio; 507d8408326SSeung-Woo Kim unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset; 508d8408326SSeung-Woo Kim dma_addr_t dma_addr; 509d8408326SSeung-Woo Kim unsigned int fmt; 510d8408326SSeung-Woo Kim u32 val; 511d8408326SSeung-Woo Kim 512d8408326SSeung-Woo Kim win_data = &ctx->win_data[win]; 513d8408326SSeung-Woo Kim 514d8408326SSeung-Woo Kim #define RGB565 4 515d8408326SSeung-Woo Kim #define ARGB1555 5 516d8408326SSeung-Woo Kim #define ARGB4444 6 517d8408326SSeung-Woo Kim #define ARGB8888 7 518d8408326SSeung-Woo Kim 519d8408326SSeung-Woo Kim switch (win_data->bpp) { 520d8408326SSeung-Woo Kim case 16: 521d8408326SSeung-Woo Kim fmt = ARGB4444; 522d8408326SSeung-Woo Kim break; 523d8408326SSeung-Woo Kim case 32: 524d8408326SSeung-Woo Kim fmt = ARGB8888; 525d8408326SSeung-Woo Kim break; 526d8408326SSeung-Woo Kim default: 527d8408326SSeung-Woo Kim fmt = ARGB8888; 528d8408326SSeung-Woo Kim } 529d8408326SSeung-Woo Kim 530d8408326SSeung-Woo Kim /* 2x scaling feature */ 531d8408326SSeung-Woo Kim x_ratio = 0; 532d8408326SSeung-Woo Kim y_ratio = 0; 533d8408326SSeung-Woo Kim 534d8408326SSeung-Woo Kim dst_x_offset = win_data->crtc_x; 535d8408326SSeung-Woo Kim dst_y_offset = win_data->crtc_y; 536d8408326SSeung-Woo Kim 537d8408326SSeung-Woo Kim /* converting dma address base and source offset */ 5388dcb96b6SSeung-Woo Kim dma_addr = win_data->dma_addr 5398dcb96b6SSeung-Woo Kim + (win_data->fb_x * win_data->bpp >> 3) 5408dcb96b6SSeung-Woo Kim + (win_data->fb_y * win_data->fb_width * win_data->bpp >> 3); 541d8408326SSeung-Woo Kim src_x_offset = 0; 542d8408326SSeung-Woo Kim src_y_offset = 0; 543d8408326SSeung-Woo Kim 544d8408326SSeung-Woo Kim if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE) 545d8408326SSeung-Woo Kim ctx->interlace = true; 546d8408326SSeung-Woo Kim else 547d8408326SSeung-Woo Kim ctx->interlace = false; 548d8408326SSeung-Woo Kim 549d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 550d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, false); 551d8408326SSeung-Woo Kim 552d8408326SSeung-Woo Kim /* setup format */ 553d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win), 554d8408326SSeung-Woo Kim MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK); 555d8408326SSeung-Woo Kim 556d8408326SSeung-Woo Kim /* setup geometry */ 5578dcb96b6SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_SPAN(win), win_data->fb_width); 558d8408326SSeung-Woo Kim 5598dcb96b6SSeung-Woo Kim val = MXR_GRP_WH_WIDTH(win_data->crtc_width); 5608dcb96b6SSeung-Woo Kim val |= MXR_GRP_WH_HEIGHT(win_data->crtc_height); 561d8408326SSeung-Woo Kim val |= MXR_GRP_WH_H_SCALE(x_ratio); 562d8408326SSeung-Woo Kim val |= MXR_GRP_WH_V_SCALE(y_ratio); 563d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_WH(win), val); 564d8408326SSeung-Woo Kim 565d8408326SSeung-Woo Kim /* setup offsets in source image */ 566d8408326SSeung-Woo Kim val = MXR_GRP_SXY_SX(src_x_offset); 567d8408326SSeung-Woo Kim val |= MXR_GRP_SXY_SY(src_y_offset); 568d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val); 569d8408326SSeung-Woo Kim 570d8408326SSeung-Woo Kim /* setup offsets in display image */ 571d8408326SSeung-Woo Kim val = MXR_GRP_DXY_DX(dst_x_offset); 572d8408326SSeung-Woo Kim val |= MXR_GRP_DXY_DY(dst_y_offset); 573d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val); 574d8408326SSeung-Woo Kim 575d8408326SSeung-Woo Kim /* set buffer address to mixer */ 576d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr); 577d8408326SSeung-Woo Kim 5788dcb96b6SSeung-Woo Kim mixer_cfg_scan(ctx, win_data->mode_height); 5798dcb96b6SSeung-Woo Kim mixer_cfg_rgb_fmt(ctx, win_data->mode_height); 580d8408326SSeung-Woo Kim mixer_cfg_layer(ctx, win, true); 581aaf8b49eSRahul Sharma 582aaf8b49eSRahul Sharma /* layer update mandatory for mixer 16.0.33.0 */ 583aaf8b49eSRahul Sharma if (ctx->mxr_ver == MXR_VER_16_0_33_0) 584aaf8b49eSRahul Sharma mixer_layer_update(ctx); 585aaf8b49eSRahul Sharma 586d8408326SSeung-Woo Kim mixer_run(ctx); 587d8408326SSeung-Woo Kim 588d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, true); 589d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 590d8408326SSeung-Woo Kim } 591d8408326SSeung-Woo Kim 592d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx) 593d8408326SSeung-Woo Kim { 594d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 595d8408326SSeung-Woo Kim int tries = 100; 596d8408326SSeung-Woo Kim 597d8408326SSeung-Woo Kim vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING); 598d8408326SSeung-Woo Kim for (tries = 100; tries; --tries) { 599d8408326SSeung-Woo Kim /* waiting until VP_SRESET_PROCESSING is 0 */ 600d8408326SSeung-Woo Kim if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING) 601d8408326SSeung-Woo Kim break; 602d8408326SSeung-Woo Kim mdelay(10); 603d8408326SSeung-Woo Kim } 604d8408326SSeung-Woo Kim WARN(tries == 0, "failed to reset Video Processor\n"); 605d8408326SSeung-Woo Kim } 606d8408326SSeung-Woo Kim 607cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx) 608cf8fc4f1SJoonyoung Shim { 609cf8fc4f1SJoonyoung Shim struct mixer_resources *res = &ctx->mixer_res; 610cf8fc4f1SJoonyoung Shim unsigned long flags; 611cf8fc4f1SJoonyoung Shim u32 val; /* value stored to register */ 612cf8fc4f1SJoonyoung Shim 613cf8fc4f1SJoonyoung Shim spin_lock_irqsave(&res->reg_slock, flags); 614cf8fc4f1SJoonyoung Shim mixer_vsync_set_update(ctx, false); 615cf8fc4f1SJoonyoung Shim 616cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK); 617cf8fc4f1SJoonyoung Shim 618cf8fc4f1SJoonyoung Shim /* set output in RGB888 mode */ 619cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK); 620cf8fc4f1SJoonyoung Shim 621cf8fc4f1SJoonyoung Shim /* 16 beat burst in DMA */ 622cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST, 623cf8fc4f1SJoonyoung Shim MXR_STATUS_BURST_MASK); 624cf8fc4f1SJoonyoung Shim 625cf8fc4f1SJoonyoung Shim /* setting default layer priority: layer1 > layer0 > video 626cf8fc4f1SJoonyoung Shim * because typical usage scenario would be 627cf8fc4f1SJoonyoung Shim * layer1 - OSD 628cf8fc4f1SJoonyoung Shim * layer0 - framebuffer 629cf8fc4f1SJoonyoung Shim * video - video overlay 630cf8fc4f1SJoonyoung Shim */ 631cf8fc4f1SJoonyoung Shim val = MXR_LAYER_CFG_GRP1_VAL(3); 632cf8fc4f1SJoonyoung Shim val |= MXR_LAYER_CFG_GRP0_VAL(2); 6331b8e5747SRahul Sharma if (ctx->vp_enabled) 634cf8fc4f1SJoonyoung Shim val |= MXR_LAYER_CFG_VP_VAL(1); 635cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_LAYER_CFG, val); 636cf8fc4f1SJoonyoung Shim 637cf8fc4f1SJoonyoung Shim /* setting background color */ 638cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_BG_COLOR0, 0x008080); 639cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_BG_COLOR1, 0x008080); 640cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_BG_COLOR2, 0x008080); 641cf8fc4f1SJoonyoung Shim 642cf8fc4f1SJoonyoung Shim /* setting graphical layers */ 643cf8fc4f1SJoonyoung Shim val = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */ 644cf8fc4f1SJoonyoung Shim val |= MXR_GRP_CFG_WIN_BLEND_EN; 6455736603bSSeung-Woo Kim val |= MXR_GRP_CFG_BLEND_PRE_MUL; 6465736603bSSeung-Woo Kim val |= MXR_GRP_CFG_PIXEL_BLEND_EN; 647cf8fc4f1SJoonyoung Shim val |= MXR_GRP_CFG_ALPHA_VAL(0xff); /* non-transparent alpha */ 648cf8fc4f1SJoonyoung Shim 649cf8fc4f1SJoonyoung Shim /* the same configuration for both layers */ 650cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_GRAPHIC_CFG(0), val); 651cf8fc4f1SJoonyoung Shim mixer_reg_write(res, MXR_GRAPHIC_CFG(1), val); 652cf8fc4f1SJoonyoung Shim 6535736603bSSeung-Woo Kim /* setting video layers */ 6545736603bSSeung-Woo Kim val = MXR_GRP_CFG_ALPHA_VAL(0); 6555736603bSSeung-Woo Kim mixer_reg_write(res, MXR_VIDEO_CFG, val); 6565736603bSSeung-Woo Kim 6571b8e5747SRahul Sharma if (ctx->vp_enabled) { 658cf8fc4f1SJoonyoung Shim /* configuration of Video Processor Registers */ 659cf8fc4f1SJoonyoung Shim vp_win_reset(ctx); 660cf8fc4f1SJoonyoung Shim vp_default_filter(res); 6611b8e5747SRahul Sharma } 662cf8fc4f1SJoonyoung Shim 663cf8fc4f1SJoonyoung Shim /* disable all layers */ 664cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE); 665cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE); 6661b8e5747SRahul Sharma if (ctx->vp_enabled) 667cf8fc4f1SJoonyoung Shim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE); 668cf8fc4f1SJoonyoung Shim 669cf8fc4f1SJoonyoung Shim mixer_vsync_set_update(ctx, true); 670cf8fc4f1SJoonyoung Shim spin_unlock_irqrestore(&res->reg_slock, flags); 671cf8fc4f1SJoonyoung Shim } 672cf8fc4f1SJoonyoung Shim 6731055b39fSInki Dae static int mixer_iommu_on(void *ctx, bool enable) 6741055b39fSInki Dae { 6751055b39fSInki Dae struct exynos_drm_hdmi_context *drm_hdmi_ctx; 6761055b39fSInki Dae struct mixer_context *mdata = ctx; 6771055b39fSInki Dae struct drm_device *drm_dev; 6781055b39fSInki Dae 6791055b39fSInki Dae drm_hdmi_ctx = mdata->parent_ctx; 6801055b39fSInki Dae drm_dev = drm_hdmi_ctx->drm_dev; 6811055b39fSInki Dae 6821055b39fSInki Dae if (is_drm_iommu_supported(drm_dev)) { 6831055b39fSInki Dae if (enable) 6841055b39fSInki Dae return drm_iommu_attach_device(drm_dev, mdata->dev); 6851055b39fSInki Dae 6861055b39fSInki Dae drm_iommu_detach_device(drm_dev, mdata->dev); 6871055b39fSInki Dae } 6881055b39fSInki Dae return 0; 6891055b39fSInki Dae } 6901055b39fSInki Dae 691d8408326SSeung-Woo Kim static int mixer_enable_vblank(void *ctx, int pipe) 692d8408326SSeung-Woo Kim { 693d8408326SSeung-Woo Kim struct mixer_context *mixer_ctx = ctx; 694d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 695d8408326SSeung-Woo Kim 696d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 697d8408326SSeung-Woo Kim 698d8408326SSeung-Woo Kim mixer_ctx->pipe = pipe; 699d8408326SSeung-Woo Kim 700d8408326SSeung-Woo Kim /* enable vsync interrupt */ 701d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_INT_EN, MXR_INT_EN_VSYNC, 702d8408326SSeung-Woo Kim MXR_INT_EN_VSYNC); 703d8408326SSeung-Woo Kim 704d8408326SSeung-Woo Kim return 0; 705d8408326SSeung-Woo Kim } 706d8408326SSeung-Woo Kim 707d8408326SSeung-Woo Kim static void mixer_disable_vblank(void *ctx) 708d8408326SSeung-Woo Kim { 709d8408326SSeung-Woo Kim struct mixer_context *mixer_ctx = ctx; 710d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 711d8408326SSeung-Woo Kim 712d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 713d8408326SSeung-Woo Kim 714d8408326SSeung-Woo Kim /* disable vsync interrupt */ 715d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC); 716d8408326SSeung-Woo Kim } 717d8408326SSeung-Woo Kim 718d8408326SSeung-Woo Kim static void mixer_win_mode_set(void *ctx, 719d8408326SSeung-Woo Kim struct exynos_drm_overlay *overlay) 720d8408326SSeung-Woo Kim { 721d8408326SSeung-Woo Kim struct mixer_context *mixer_ctx = ctx; 722d8408326SSeung-Woo Kim struct hdmi_win_data *win_data; 723d8408326SSeung-Woo Kim int win; 724d8408326SSeung-Woo Kim 725d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 726d8408326SSeung-Woo Kim 727d8408326SSeung-Woo Kim if (!overlay) { 728d8408326SSeung-Woo Kim DRM_ERROR("overlay is NULL\n"); 729d8408326SSeung-Woo Kim return; 730d8408326SSeung-Woo Kim } 731d8408326SSeung-Woo Kim 732d8408326SSeung-Woo Kim DRM_DEBUG_KMS("set [%d]x[%d] at (%d,%d) to [%d]x[%d] at (%d,%d)\n", 733d8408326SSeung-Woo Kim overlay->fb_width, overlay->fb_height, 734d8408326SSeung-Woo Kim overlay->fb_x, overlay->fb_y, 735d8408326SSeung-Woo Kim overlay->crtc_width, overlay->crtc_height, 736d8408326SSeung-Woo Kim overlay->crtc_x, overlay->crtc_y); 737d8408326SSeung-Woo Kim 738d8408326SSeung-Woo Kim win = overlay->zpos; 739d8408326SSeung-Woo Kim if (win == DEFAULT_ZPOS) 740a2ee151bSJoonyoung Shim win = MIXER_DEFAULT_WIN; 741d8408326SSeung-Woo Kim 742a634dd54SJoonyoung Shim if (win < 0 || win > MIXER_WIN_NR) { 743cf8fc4f1SJoonyoung Shim DRM_ERROR("mixer window[%d] is wrong\n", win); 744d8408326SSeung-Woo Kim return; 745d8408326SSeung-Woo Kim } 746d8408326SSeung-Woo Kim 747d8408326SSeung-Woo Kim win_data = &mixer_ctx->win_data[win]; 748d8408326SSeung-Woo Kim 749d8408326SSeung-Woo Kim win_data->dma_addr = overlay->dma_addr[0]; 750d8408326SSeung-Woo Kim win_data->chroma_dma_addr = overlay->dma_addr[1]; 751d8408326SSeung-Woo Kim win_data->pixel_format = overlay->pixel_format; 752d8408326SSeung-Woo Kim win_data->bpp = overlay->bpp; 753d8408326SSeung-Woo Kim 754d8408326SSeung-Woo Kim win_data->crtc_x = overlay->crtc_x; 755d8408326SSeung-Woo Kim win_data->crtc_y = overlay->crtc_y; 756d8408326SSeung-Woo Kim win_data->crtc_width = overlay->crtc_width; 757d8408326SSeung-Woo Kim win_data->crtc_height = overlay->crtc_height; 758d8408326SSeung-Woo Kim 759d8408326SSeung-Woo Kim win_data->fb_x = overlay->fb_x; 760d8408326SSeung-Woo Kim win_data->fb_y = overlay->fb_y; 761d8408326SSeung-Woo Kim win_data->fb_width = overlay->fb_width; 762d8408326SSeung-Woo Kim win_data->fb_height = overlay->fb_height; 7638dcb96b6SSeung-Woo Kim win_data->src_width = overlay->src_width; 7648dcb96b6SSeung-Woo Kim win_data->src_height = overlay->src_height; 765d8408326SSeung-Woo Kim 766d8408326SSeung-Woo Kim win_data->mode_width = overlay->mode_width; 767d8408326SSeung-Woo Kim win_data->mode_height = overlay->mode_height; 768d8408326SSeung-Woo Kim 769d8408326SSeung-Woo Kim win_data->scan_flags = overlay->scan_flag; 770d8408326SSeung-Woo Kim } 771d8408326SSeung-Woo Kim 772cf8fc4f1SJoonyoung Shim static void mixer_win_commit(void *ctx, int win) 773d8408326SSeung-Woo Kim { 774d8408326SSeung-Woo Kim struct mixer_context *mixer_ctx = ctx; 775d8408326SSeung-Woo Kim 776d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s, win: %d\n", __LINE__, __func__, win); 777d8408326SSeung-Woo Kim 7781b8e5747SRahul Sharma if (win > 1 && mixer_ctx->vp_enabled) 779d8408326SSeung-Woo Kim vp_video_buffer(mixer_ctx, win); 780d8408326SSeung-Woo Kim else 781d8408326SSeung-Woo Kim mixer_graph_buffer(mixer_ctx, win); 782db43fd16SPrathyush K 783db43fd16SPrathyush K mixer_ctx->win_data[win].enabled = true; 784d8408326SSeung-Woo Kim } 785d8408326SSeung-Woo Kim 786cf8fc4f1SJoonyoung Shim static void mixer_win_disable(void *ctx, int win) 787d8408326SSeung-Woo Kim { 788d8408326SSeung-Woo Kim struct mixer_context *mixer_ctx = ctx; 789d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 790d8408326SSeung-Woo Kim unsigned long flags; 791d8408326SSeung-Woo Kim 792d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s, win: %d\n", __LINE__, __func__, win); 793d8408326SSeung-Woo Kim 794db43fd16SPrathyush K mutex_lock(&mixer_ctx->mixer_mutex); 795db43fd16SPrathyush K if (!mixer_ctx->powered) { 796db43fd16SPrathyush K mutex_unlock(&mixer_ctx->mixer_mutex); 797db43fd16SPrathyush K mixer_ctx->win_data[win].resume = false; 798db43fd16SPrathyush K return; 799db43fd16SPrathyush K } 800db43fd16SPrathyush K mutex_unlock(&mixer_ctx->mixer_mutex); 801db43fd16SPrathyush K 802d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 803d8408326SSeung-Woo Kim mixer_vsync_set_update(mixer_ctx, false); 804d8408326SSeung-Woo Kim 805d8408326SSeung-Woo Kim mixer_cfg_layer(mixer_ctx, win, false); 806d8408326SSeung-Woo Kim 807d8408326SSeung-Woo Kim mixer_vsync_set_update(mixer_ctx, true); 808d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 809db43fd16SPrathyush K 810db43fd16SPrathyush K mixer_ctx->win_data[win].enabled = false; 811d8408326SSeung-Woo Kim } 812d8408326SSeung-Woo Kim 8138137a2e2SPrathyush K static void mixer_wait_for_vblank(void *ctx) 8148137a2e2SPrathyush K { 8158137a2e2SPrathyush K struct mixer_context *mixer_ctx = ctx; 8168137a2e2SPrathyush K 8176e95d5e6SPrathyush K mutex_lock(&mixer_ctx->mixer_mutex); 8186e95d5e6SPrathyush K if (!mixer_ctx->powered) { 8196e95d5e6SPrathyush K mutex_unlock(&mixer_ctx->mixer_mutex); 8206e95d5e6SPrathyush K return; 8216e95d5e6SPrathyush K } 8226e95d5e6SPrathyush K mutex_unlock(&mixer_ctx->mixer_mutex); 8236e95d5e6SPrathyush K 8246e95d5e6SPrathyush K atomic_set(&mixer_ctx->wait_vsync_event, 1); 8256e95d5e6SPrathyush K 8266e95d5e6SPrathyush K /* 8276e95d5e6SPrathyush K * wait for MIXER to signal VSYNC interrupt or return after 8286e95d5e6SPrathyush K * timeout which is set to 50ms (refresh rate of 20). 8296e95d5e6SPrathyush K */ 8306e95d5e6SPrathyush K if (!wait_event_timeout(mixer_ctx->wait_vsync_queue, 8316e95d5e6SPrathyush K !atomic_read(&mixer_ctx->wait_vsync_event), 8326e95d5e6SPrathyush K DRM_HZ/20)) 8338137a2e2SPrathyush K DRM_DEBUG_KMS("vblank wait timed out.\n"); 8348137a2e2SPrathyush K } 8358137a2e2SPrathyush K 836db43fd16SPrathyush K static void mixer_window_suspend(struct mixer_context *ctx) 837db43fd16SPrathyush K { 838db43fd16SPrathyush K struct hdmi_win_data *win_data; 839db43fd16SPrathyush K int i; 840db43fd16SPrathyush K 841db43fd16SPrathyush K for (i = 0; i < MIXER_WIN_NR; i++) { 842db43fd16SPrathyush K win_data = &ctx->win_data[i]; 843db43fd16SPrathyush K win_data->resume = win_data->enabled; 844db43fd16SPrathyush K mixer_win_disable(ctx, i); 845db43fd16SPrathyush K } 846db43fd16SPrathyush K mixer_wait_for_vblank(ctx); 847db43fd16SPrathyush K } 848db43fd16SPrathyush K 849db43fd16SPrathyush K static void mixer_window_resume(struct mixer_context *ctx) 850db43fd16SPrathyush K { 851db43fd16SPrathyush K struct hdmi_win_data *win_data; 852db43fd16SPrathyush K int i; 853db43fd16SPrathyush K 854db43fd16SPrathyush K for (i = 0; i < MIXER_WIN_NR; i++) { 855db43fd16SPrathyush K win_data = &ctx->win_data[i]; 856db43fd16SPrathyush K win_data->enabled = win_data->resume; 857db43fd16SPrathyush K win_data->resume = false; 858db43fd16SPrathyush K } 859db43fd16SPrathyush K } 860db43fd16SPrathyush K 861db43fd16SPrathyush K static void mixer_poweron(struct mixer_context *ctx) 862db43fd16SPrathyush K { 863db43fd16SPrathyush K struct mixer_resources *res = &ctx->mixer_res; 864db43fd16SPrathyush K 865db43fd16SPrathyush K DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 866db43fd16SPrathyush K 867db43fd16SPrathyush K mutex_lock(&ctx->mixer_mutex); 868db43fd16SPrathyush K if (ctx->powered) { 869db43fd16SPrathyush K mutex_unlock(&ctx->mixer_mutex); 870db43fd16SPrathyush K return; 871db43fd16SPrathyush K } 872db43fd16SPrathyush K ctx->powered = true; 873db43fd16SPrathyush K mutex_unlock(&ctx->mixer_mutex); 874db43fd16SPrathyush K 875db43fd16SPrathyush K clk_enable(res->mixer); 876db43fd16SPrathyush K if (ctx->vp_enabled) { 877db43fd16SPrathyush K clk_enable(res->vp); 878db43fd16SPrathyush K clk_enable(res->sclk_mixer); 879db43fd16SPrathyush K } 880db43fd16SPrathyush K 881db43fd16SPrathyush K mixer_reg_write(res, MXR_INT_EN, ctx->int_en); 882db43fd16SPrathyush K mixer_win_reset(ctx); 883db43fd16SPrathyush K 884db43fd16SPrathyush K mixer_window_resume(ctx); 885db43fd16SPrathyush K } 886db43fd16SPrathyush K 887db43fd16SPrathyush K static void mixer_poweroff(struct mixer_context *ctx) 888db43fd16SPrathyush K { 889db43fd16SPrathyush K struct mixer_resources *res = &ctx->mixer_res; 890db43fd16SPrathyush K 891db43fd16SPrathyush K DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 892db43fd16SPrathyush K 893db43fd16SPrathyush K mutex_lock(&ctx->mixer_mutex); 894db43fd16SPrathyush K if (!ctx->powered) 895db43fd16SPrathyush K goto out; 896db43fd16SPrathyush K mutex_unlock(&ctx->mixer_mutex); 897db43fd16SPrathyush K 898db43fd16SPrathyush K mixer_window_suspend(ctx); 899db43fd16SPrathyush K 900db43fd16SPrathyush K ctx->int_en = mixer_reg_read(res, MXR_INT_EN); 901db43fd16SPrathyush K 902db43fd16SPrathyush K clk_disable(res->mixer); 903db43fd16SPrathyush K if (ctx->vp_enabled) { 904db43fd16SPrathyush K clk_disable(res->vp); 905db43fd16SPrathyush K clk_disable(res->sclk_mixer); 906db43fd16SPrathyush K } 907db43fd16SPrathyush K 908db43fd16SPrathyush K mutex_lock(&ctx->mixer_mutex); 909db43fd16SPrathyush K ctx->powered = false; 910db43fd16SPrathyush K 911db43fd16SPrathyush K out: 912db43fd16SPrathyush K mutex_unlock(&ctx->mixer_mutex); 913db43fd16SPrathyush K } 914db43fd16SPrathyush K 915db43fd16SPrathyush K static void mixer_dpms(void *ctx, int mode) 916db43fd16SPrathyush K { 917db43fd16SPrathyush K struct mixer_context *mixer_ctx = ctx; 918db43fd16SPrathyush K 919db43fd16SPrathyush K DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 920db43fd16SPrathyush K 921db43fd16SPrathyush K switch (mode) { 922db43fd16SPrathyush K case DRM_MODE_DPMS_ON: 923000f1308SRahul Sharma if (pm_runtime_suspended(mixer_ctx->dev)) 924000f1308SRahul Sharma pm_runtime_get_sync(mixer_ctx->dev); 925db43fd16SPrathyush K break; 926db43fd16SPrathyush K case DRM_MODE_DPMS_STANDBY: 927db43fd16SPrathyush K case DRM_MODE_DPMS_SUSPEND: 928db43fd16SPrathyush K case DRM_MODE_DPMS_OFF: 929000f1308SRahul Sharma if (!pm_runtime_suspended(mixer_ctx->dev)) 930000f1308SRahul Sharma pm_runtime_put_sync(mixer_ctx->dev); 931db43fd16SPrathyush K break; 932db43fd16SPrathyush K default: 933db43fd16SPrathyush K DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode); 934db43fd16SPrathyush K break; 935db43fd16SPrathyush K } 936db43fd16SPrathyush K } 937db43fd16SPrathyush K 938578b6065SJoonyoung Shim static struct exynos_mixer_ops mixer_ops = { 939578b6065SJoonyoung Shim /* manager */ 9401055b39fSInki Dae .iommu_on = mixer_iommu_on, 941d8408326SSeung-Woo Kim .enable_vblank = mixer_enable_vblank, 942d8408326SSeung-Woo Kim .disable_vblank = mixer_disable_vblank, 9438137a2e2SPrathyush K .wait_for_vblank = mixer_wait_for_vblank, 944cf8fc4f1SJoonyoung Shim .dpms = mixer_dpms, 945578b6065SJoonyoung Shim 946578b6065SJoonyoung Shim /* overlay */ 947d8408326SSeung-Woo Kim .win_mode_set = mixer_win_mode_set, 948d8408326SSeung-Woo Kim .win_commit = mixer_win_commit, 949d8408326SSeung-Woo Kim .win_disable = mixer_win_disable, 950d8408326SSeung-Woo Kim }; 951d8408326SSeung-Woo Kim 952d8408326SSeung-Woo Kim /* for pageflip event */ 953d8408326SSeung-Woo Kim static void mixer_finish_pageflip(struct drm_device *drm_dev, int crtc) 954d8408326SSeung-Woo Kim { 955d8408326SSeung-Woo Kim struct exynos_drm_private *dev_priv = drm_dev->dev_private; 956d8408326SSeung-Woo Kim struct drm_pending_vblank_event *e, *t; 957d8408326SSeung-Woo Kim struct timeval now; 958d8408326SSeung-Woo Kim unsigned long flags; 959d8408326SSeung-Woo Kim 960d8408326SSeung-Woo Kim spin_lock_irqsave(&drm_dev->event_lock, flags); 961d8408326SSeung-Woo Kim 962d8408326SSeung-Woo Kim list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list, 963d8408326SSeung-Woo Kim base.link) { 964d8408326SSeung-Woo Kim /* if event's pipe isn't same as crtc then ignore it. */ 965d8408326SSeung-Woo Kim if (crtc != e->pipe) 966d8408326SSeung-Woo Kim continue; 967d8408326SSeung-Woo Kim 968d8408326SSeung-Woo Kim do_gettimeofday(&now); 969d8408326SSeung-Woo Kim e->event.sequence = 0; 970d8408326SSeung-Woo Kim e->event.tv_sec = now.tv_sec; 971d8408326SSeung-Woo Kim e->event.tv_usec = now.tv_usec; 972d8408326SSeung-Woo Kim 973d8408326SSeung-Woo Kim list_move_tail(&e->base.link, &e->base.file_priv->event_list); 974d8408326SSeung-Woo Kim wake_up_interruptible(&e->base.file_priv->event_wait); 975d8408326SSeung-Woo Kim drm_vblank_put(drm_dev, crtc); 976e1f48ee5SImre Deak } 977d8408326SSeung-Woo Kim 978d8408326SSeung-Woo Kim spin_unlock_irqrestore(&drm_dev->event_lock, flags); 979d8408326SSeung-Woo Kim } 980d8408326SSeung-Woo Kim 981d8408326SSeung-Woo Kim static irqreturn_t mixer_irq_handler(int irq, void *arg) 982d8408326SSeung-Woo Kim { 983d8408326SSeung-Woo Kim struct exynos_drm_hdmi_context *drm_hdmi_ctx = arg; 984f9309d1bSJoonyoung Shim struct mixer_context *ctx = drm_hdmi_ctx->ctx; 985d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 9868379e482SSeung-Woo Kim u32 val, base, shadow; 987d8408326SSeung-Woo Kim 988d8408326SSeung-Woo Kim spin_lock(&res->reg_slock); 989d8408326SSeung-Woo Kim 990d8408326SSeung-Woo Kim /* read interrupt status for handling and clearing flags for VSYNC */ 991d8408326SSeung-Woo Kim val = mixer_reg_read(res, MXR_INT_STATUS); 992d8408326SSeung-Woo Kim 993d8408326SSeung-Woo Kim /* handling VSYNC */ 994d8408326SSeung-Woo Kim if (val & MXR_INT_STATUS_VSYNC) { 995d8408326SSeung-Woo Kim /* interlace scan need to check shadow register */ 996d8408326SSeung-Woo Kim if (ctx->interlace) { 9978379e482SSeung-Woo Kim base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0)); 9988379e482SSeung-Woo Kim shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0)); 9998379e482SSeung-Woo Kim if (base != shadow) 1000d8408326SSeung-Woo Kim goto out; 1001d8408326SSeung-Woo Kim 10028379e482SSeung-Woo Kim base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1)); 10038379e482SSeung-Woo Kim shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1)); 10048379e482SSeung-Woo Kim if (base != shadow) 1005d8408326SSeung-Woo Kim goto out; 1006d8408326SSeung-Woo Kim } 1007d8408326SSeung-Woo Kim 1008d8408326SSeung-Woo Kim drm_handle_vblank(drm_hdmi_ctx->drm_dev, ctx->pipe); 1009d8408326SSeung-Woo Kim mixer_finish_pageflip(drm_hdmi_ctx->drm_dev, ctx->pipe); 10106e95d5e6SPrathyush K 10116e95d5e6SPrathyush K /* set wait vsync event to zero and wake up queue. */ 10126e95d5e6SPrathyush K if (atomic_read(&ctx->wait_vsync_event)) { 10136e95d5e6SPrathyush K atomic_set(&ctx->wait_vsync_event, 0); 10146e95d5e6SPrathyush K DRM_WAKEUP(&ctx->wait_vsync_queue); 10156e95d5e6SPrathyush K } 1016d8408326SSeung-Woo Kim } 1017d8408326SSeung-Woo Kim 1018d8408326SSeung-Woo Kim out: 1019d8408326SSeung-Woo Kim /* clear interrupts */ 1020d8408326SSeung-Woo Kim if (~val & MXR_INT_EN_VSYNC) { 1021d8408326SSeung-Woo Kim /* vsync interrupt use different bit for read and clear */ 1022d8408326SSeung-Woo Kim val &= ~MXR_INT_EN_VSYNC; 1023d8408326SSeung-Woo Kim val |= MXR_INT_CLEAR_VSYNC; 1024d8408326SSeung-Woo Kim } 1025d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_INT_STATUS, val); 1026d8408326SSeung-Woo Kim 1027d8408326SSeung-Woo Kim spin_unlock(&res->reg_slock); 1028d8408326SSeung-Woo Kim 1029d8408326SSeung-Woo Kim return IRQ_HANDLED; 1030d8408326SSeung-Woo Kim } 1031d8408326SSeung-Woo Kim 1032*56550d94SGreg Kroah-Hartman static int mixer_resources_init(struct exynos_drm_hdmi_context *ctx, 1033d8408326SSeung-Woo Kim struct platform_device *pdev) 1034d8408326SSeung-Woo Kim { 1035f9309d1bSJoonyoung Shim struct mixer_context *mixer_ctx = ctx->ctx; 1036d8408326SSeung-Woo Kim struct device *dev = &pdev->dev; 1037d8408326SSeung-Woo Kim struct mixer_resources *mixer_res = &mixer_ctx->mixer_res; 1038d8408326SSeung-Woo Kim struct resource *res; 1039d8408326SSeung-Woo Kim int ret; 1040d8408326SSeung-Woo Kim 1041d8408326SSeung-Woo Kim spin_lock_init(&mixer_res->reg_slock); 1042d8408326SSeung-Woo Kim 104337f50861SSachin Kamat mixer_res->mixer = devm_clk_get(dev, "mixer"); 1044d8408326SSeung-Woo Kim if (IS_ERR_OR_NULL(mixer_res->mixer)) { 1045d8408326SSeung-Woo Kim dev_err(dev, "failed to get clock 'mixer'\n"); 104637f50861SSachin Kamat return -ENODEV; 1047d8408326SSeung-Woo Kim } 10481b8e5747SRahul Sharma 104937f50861SSachin Kamat mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi"); 1050d8408326SSeung-Woo Kim if (IS_ERR_OR_NULL(mixer_res->sclk_hdmi)) { 1051d8408326SSeung-Woo Kim dev_err(dev, "failed to get clock 'sclk_hdmi'\n"); 105237f50861SSachin Kamat return -ENODEV; 1053d8408326SSeung-Woo Kim } 10541b8e5747SRahul Sharma res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1055d8408326SSeung-Woo Kim if (res == NULL) { 1056d8408326SSeung-Woo Kim dev_err(dev, "get memory resource failed.\n"); 105737f50861SSachin Kamat return -ENXIO; 1058d8408326SSeung-Woo Kim } 1059d8408326SSeung-Woo Kim 10609416dfa7SSachin Kamat mixer_res->mixer_regs = devm_ioremap(&pdev->dev, res->start, 10619416dfa7SSachin Kamat resource_size(res)); 1062d8408326SSeung-Woo Kim if (mixer_res->mixer_regs == NULL) { 1063d8408326SSeung-Woo Kim dev_err(dev, "register mapping failed.\n"); 106437f50861SSachin Kamat return -ENXIO; 1065d8408326SSeung-Woo Kim } 1066d8408326SSeung-Woo Kim 10671b8e5747SRahul Sharma res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1068d8408326SSeung-Woo Kim if (res == NULL) { 1069d8408326SSeung-Woo Kim dev_err(dev, "get interrupt resource failed.\n"); 107037f50861SSachin Kamat return -ENXIO; 1071d8408326SSeung-Woo Kim } 1072d8408326SSeung-Woo Kim 10739416dfa7SSachin Kamat ret = devm_request_irq(&pdev->dev, res->start, mixer_irq_handler, 10749416dfa7SSachin Kamat 0, "drm_mixer", ctx); 1075d8408326SSeung-Woo Kim if (ret) { 1076d8408326SSeung-Woo Kim dev_err(dev, "request interrupt failed.\n"); 107737f50861SSachin Kamat return ret; 1078d8408326SSeung-Woo Kim } 1079d8408326SSeung-Woo Kim mixer_res->irq = res->start; 1080d8408326SSeung-Woo Kim 1081d8408326SSeung-Woo Kim return 0; 1082d8408326SSeung-Woo Kim } 1083d8408326SSeung-Woo Kim 1084*56550d94SGreg Kroah-Hartman static int vp_resources_init(struct exynos_drm_hdmi_context *ctx, 10851b8e5747SRahul Sharma struct platform_device *pdev) 10861b8e5747SRahul Sharma { 10871b8e5747SRahul Sharma struct mixer_context *mixer_ctx = ctx->ctx; 10881b8e5747SRahul Sharma struct device *dev = &pdev->dev; 10891b8e5747SRahul Sharma struct mixer_resources *mixer_res = &mixer_ctx->mixer_res; 10901b8e5747SRahul Sharma struct resource *res; 10911b8e5747SRahul Sharma 109237f50861SSachin Kamat mixer_res->vp = devm_clk_get(dev, "vp"); 10931b8e5747SRahul Sharma if (IS_ERR_OR_NULL(mixer_res->vp)) { 10941b8e5747SRahul Sharma dev_err(dev, "failed to get clock 'vp'\n"); 109537f50861SSachin Kamat return -ENODEV; 10961b8e5747SRahul Sharma } 109737f50861SSachin Kamat mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer"); 10981b8e5747SRahul Sharma if (IS_ERR_OR_NULL(mixer_res->sclk_mixer)) { 10991b8e5747SRahul Sharma dev_err(dev, "failed to get clock 'sclk_mixer'\n"); 110037f50861SSachin Kamat return -ENODEV; 11011b8e5747SRahul Sharma } 110237f50861SSachin Kamat mixer_res->sclk_dac = devm_clk_get(dev, "sclk_dac"); 11031b8e5747SRahul Sharma if (IS_ERR_OR_NULL(mixer_res->sclk_dac)) { 11041b8e5747SRahul Sharma dev_err(dev, "failed to get clock 'sclk_dac'\n"); 110537f50861SSachin Kamat return -ENODEV; 11061b8e5747SRahul Sharma } 11071b8e5747SRahul Sharma 11081b8e5747SRahul Sharma if (mixer_res->sclk_hdmi) 11091b8e5747SRahul Sharma clk_set_parent(mixer_res->sclk_mixer, mixer_res->sclk_hdmi); 11101b8e5747SRahul Sharma 11111b8e5747SRahul Sharma res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 11121b8e5747SRahul Sharma if (res == NULL) { 11131b8e5747SRahul Sharma dev_err(dev, "get memory resource failed.\n"); 111437f50861SSachin Kamat return -ENXIO; 11151b8e5747SRahul Sharma } 11161b8e5747SRahul Sharma 11171b8e5747SRahul Sharma mixer_res->vp_regs = devm_ioremap(&pdev->dev, res->start, 11181b8e5747SRahul Sharma resource_size(res)); 11191b8e5747SRahul Sharma if (mixer_res->vp_regs == NULL) { 11201b8e5747SRahul Sharma dev_err(dev, "register mapping failed.\n"); 112137f50861SSachin Kamat return -ENXIO; 11221b8e5747SRahul Sharma } 11231b8e5747SRahul Sharma 11241b8e5747SRahul Sharma return 0; 11251b8e5747SRahul Sharma } 11261b8e5747SRahul Sharma 1127aaf8b49eSRahul Sharma static struct mixer_drv_data exynos5_mxr_drv_data = { 1128aaf8b49eSRahul Sharma .version = MXR_VER_16_0_33_0, 1129aaf8b49eSRahul Sharma .is_vp_enabled = 0, 1130aaf8b49eSRahul Sharma }; 1131aaf8b49eSRahul Sharma 11321e123441SRahul Sharma static struct mixer_drv_data exynos4_mxr_drv_data = { 11331e123441SRahul Sharma .version = MXR_VER_0_0_0_16, 11341b8e5747SRahul Sharma .is_vp_enabled = 1, 11351e123441SRahul Sharma }; 11361e123441SRahul Sharma 11371e123441SRahul Sharma static struct platform_device_id mixer_driver_types[] = { 11381e123441SRahul Sharma { 11391e123441SRahul Sharma .name = "s5p-mixer", 11401e123441SRahul Sharma .driver_data = (unsigned long)&exynos4_mxr_drv_data, 11411e123441SRahul Sharma }, { 1142aaf8b49eSRahul Sharma .name = "exynos5-mixer", 1143aaf8b49eSRahul Sharma .driver_data = (unsigned long)&exynos5_mxr_drv_data, 1144aaf8b49eSRahul Sharma }, { 1145aaf8b49eSRahul Sharma /* end node */ 1146aaf8b49eSRahul Sharma } 1147aaf8b49eSRahul Sharma }; 1148aaf8b49eSRahul Sharma 1149aaf8b49eSRahul Sharma static struct of_device_id mixer_match_types[] = { 1150aaf8b49eSRahul Sharma { 1151aaf8b49eSRahul Sharma .compatible = "samsung,exynos5-mixer", 1152aaf8b49eSRahul Sharma .data = &exynos5_mxr_drv_data, 1153aaf8b49eSRahul Sharma }, { 11541e123441SRahul Sharma /* end node */ 11551e123441SRahul Sharma } 11561e123441SRahul Sharma }; 11571e123441SRahul Sharma 1158*56550d94SGreg Kroah-Hartman static int mixer_probe(struct platform_device *pdev) 1159d8408326SSeung-Woo Kim { 1160d8408326SSeung-Woo Kim struct device *dev = &pdev->dev; 1161d8408326SSeung-Woo Kim struct exynos_drm_hdmi_context *drm_hdmi_ctx; 1162d8408326SSeung-Woo Kim struct mixer_context *ctx; 11631e123441SRahul Sharma struct mixer_drv_data *drv; 1164d8408326SSeung-Woo Kim int ret; 1165d8408326SSeung-Woo Kim 1166d8408326SSeung-Woo Kim dev_info(dev, "probe start\n"); 1167d8408326SSeung-Woo Kim 11689416dfa7SSachin Kamat drm_hdmi_ctx = devm_kzalloc(&pdev->dev, sizeof(*drm_hdmi_ctx), 11699416dfa7SSachin Kamat GFP_KERNEL); 1170d8408326SSeung-Woo Kim if (!drm_hdmi_ctx) { 1171d8408326SSeung-Woo Kim DRM_ERROR("failed to allocate common hdmi context.\n"); 1172d8408326SSeung-Woo Kim return -ENOMEM; 1173d8408326SSeung-Woo Kim } 1174d8408326SSeung-Woo Kim 11759416dfa7SSachin Kamat ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 1176d8408326SSeung-Woo Kim if (!ctx) { 1177d8408326SSeung-Woo Kim DRM_ERROR("failed to alloc mixer context.\n"); 1178d8408326SSeung-Woo Kim return -ENOMEM; 1179d8408326SSeung-Woo Kim } 1180d8408326SSeung-Woo Kim 1181cf8fc4f1SJoonyoung Shim mutex_init(&ctx->mixer_mutex); 1182cf8fc4f1SJoonyoung Shim 1183aaf8b49eSRahul Sharma if (dev->of_node) { 1184aaf8b49eSRahul Sharma const struct of_device_id *match; 1185aaf8b49eSRahul Sharma match = of_match_node(of_match_ptr(mixer_match_types), 1186aaf8b49eSRahul Sharma pdev->dev.of_node); 11872cdc53b3SRahul Sharma drv = (struct mixer_drv_data *)match->data; 1188aaf8b49eSRahul Sharma } else { 1189aaf8b49eSRahul Sharma drv = (struct mixer_drv_data *) 1190aaf8b49eSRahul Sharma platform_get_device_id(pdev)->driver_data; 1191aaf8b49eSRahul Sharma } 1192aaf8b49eSRahul Sharma 1193cf8fc4f1SJoonyoung Shim ctx->dev = &pdev->dev; 11941055b39fSInki Dae ctx->parent_ctx = (void *)drm_hdmi_ctx; 1195d8408326SSeung-Woo Kim drm_hdmi_ctx->ctx = (void *)ctx; 11961b8e5747SRahul Sharma ctx->vp_enabled = drv->is_vp_enabled; 11971e123441SRahul Sharma ctx->mxr_ver = drv->version; 11986e95d5e6SPrathyush K DRM_INIT_WAITQUEUE(&ctx->wait_vsync_queue); 11996e95d5e6SPrathyush K atomic_set(&ctx->wait_vsync_event, 0); 1200d8408326SSeung-Woo Kim 1201d8408326SSeung-Woo Kim platform_set_drvdata(pdev, drm_hdmi_ctx); 1202d8408326SSeung-Woo Kim 1203d8408326SSeung-Woo Kim /* acquire resources: regs, irqs, clocks */ 1204d8408326SSeung-Woo Kim ret = mixer_resources_init(drm_hdmi_ctx, pdev); 12051b8e5747SRahul Sharma if (ret) { 12061b8e5747SRahul Sharma DRM_ERROR("mixer_resources_init failed\n"); 1207d8408326SSeung-Woo Kim goto fail; 12081b8e5747SRahul Sharma } 12091b8e5747SRahul Sharma 12101b8e5747SRahul Sharma if (ctx->vp_enabled) { 12111b8e5747SRahul Sharma /* acquire vp resources: regs, irqs, clocks */ 12121b8e5747SRahul Sharma ret = vp_resources_init(drm_hdmi_ctx, pdev); 12131b8e5747SRahul Sharma if (ret) { 12141b8e5747SRahul Sharma DRM_ERROR("vp_resources_init failed\n"); 12151b8e5747SRahul Sharma goto fail; 12161b8e5747SRahul Sharma } 12171b8e5747SRahul Sharma } 1218d8408326SSeung-Woo Kim 1219768c3059SRahul Sharma /* attach mixer driver to common hdmi. */ 1220768c3059SRahul Sharma exynos_mixer_drv_attach(drm_hdmi_ctx); 1221d8408326SSeung-Woo Kim 1222d8408326SSeung-Woo Kim /* register specific callback point to common hdmi. */ 1223578b6065SJoonyoung Shim exynos_mixer_ops_register(&mixer_ops); 1224d8408326SSeung-Woo Kim 1225cf8fc4f1SJoonyoung Shim pm_runtime_enable(dev); 1226d8408326SSeung-Woo Kim 1227d8408326SSeung-Woo Kim return 0; 1228d8408326SSeung-Woo Kim 1229d8408326SSeung-Woo Kim 1230d8408326SSeung-Woo Kim fail: 1231d8408326SSeung-Woo Kim dev_info(dev, "probe failed\n"); 1232d8408326SSeung-Woo Kim return ret; 1233d8408326SSeung-Woo Kim } 1234d8408326SSeung-Woo Kim 1235d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev) 1236d8408326SSeung-Woo Kim { 12379416dfa7SSachin Kamat dev_info(&pdev->dev, "remove successful\n"); 1238d8408326SSeung-Woo Kim 1239cf8fc4f1SJoonyoung Shim pm_runtime_disable(&pdev->dev); 1240cf8fc4f1SJoonyoung Shim 1241d8408326SSeung-Woo Kim return 0; 1242d8408326SSeung-Woo Kim } 1243d8408326SSeung-Woo Kim 1244ab27af85SJoonyoung Shim #ifdef CONFIG_PM_SLEEP 1245ab27af85SJoonyoung Shim static int mixer_suspend(struct device *dev) 1246ab27af85SJoonyoung Shim { 1247ab27af85SJoonyoung Shim struct exynos_drm_hdmi_context *drm_hdmi_ctx = get_mixer_context(dev); 1248ab27af85SJoonyoung Shim struct mixer_context *ctx = drm_hdmi_ctx->ctx; 1249ab27af85SJoonyoung Shim 1250000f1308SRahul Sharma DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 1251000f1308SRahul Sharma 1252000f1308SRahul Sharma if (pm_runtime_suspended(dev)) { 1253000f1308SRahul Sharma DRM_DEBUG_KMS("%s : Already suspended\n", __func__); 1254000f1308SRahul Sharma return 0; 1255000f1308SRahul Sharma } 1256000f1308SRahul Sharma 1257ab27af85SJoonyoung Shim mixer_poweroff(ctx); 1258ab27af85SJoonyoung Shim 1259ab27af85SJoonyoung Shim return 0; 1260ab27af85SJoonyoung Shim } 1261000f1308SRahul Sharma 1262000f1308SRahul Sharma static int mixer_resume(struct device *dev) 1263000f1308SRahul Sharma { 1264000f1308SRahul Sharma struct exynos_drm_hdmi_context *drm_hdmi_ctx = get_mixer_context(dev); 1265000f1308SRahul Sharma struct mixer_context *ctx = drm_hdmi_ctx->ctx; 1266000f1308SRahul Sharma 1267000f1308SRahul Sharma DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 1268000f1308SRahul Sharma 1269000f1308SRahul Sharma if (!pm_runtime_suspended(dev)) { 1270000f1308SRahul Sharma DRM_DEBUG_KMS("%s : Already resumed\n", __func__); 1271000f1308SRahul Sharma return 0; 1272000f1308SRahul Sharma } 1273000f1308SRahul Sharma 1274000f1308SRahul Sharma mixer_poweron(ctx); 1275000f1308SRahul Sharma 1276000f1308SRahul Sharma return 0; 1277000f1308SRahul Sharma } 1278ab27af85SJoonyoung Shim #endif 1279ab27af85SJoonyoung Shim 1280000f1308SRahul Sharma #ifdef CONFIG_PM_RUNTIME 1281000f1308SRahul Sharma static int mixer_runtime_suspend(struct device *dev) 1282000f1308SRahul Sharma { 1283000f1308SRahul Sharma struct exynos_drm_hdmi_context *drm_hdmi_ctx = get_mixer_context(dev); 1284000f1308SRahul Sharma struct mixer_context *ctx = drm_hdmi_ctx->ctx; 1285000f1308SRahul Sharma 1286000f1308SRahul Sharma DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 1287000f1308SRahul Sharma 1288000f1308SRahul Sharma mixer_poweroff(ctx); 1289000f1308SRahul Sharma 1290000f1308SRahul Sharma return 0; 1291000f1308SRahul Sharma } 1292000f1308SRahul Sharma 1293000f1308SRahul Sharma static int mixer_runtime_resume(struct device *dev) 1294000f1308SRahul Sharma { 1295000f1308SRahul Sharma struct exynos_drm_hdmi_context *drm_hdmi_ctx = get_mixer_context(dev); 1296000f1308SRahul Sharma struct mixer_context *ctx = drm_hdmi_ctx->ctx; 1297000f1308SRahul Sharma 1298000f1308SRahul Sharma DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 1299000f1308SRahul Sharma 1300000f1308SRahul Sharma mixer_poweron(ctx); 1301000f1308SRahul Sharma 1302000f1308SRahul Sharma return 0; 1303000f1308SRahul Sharma } 1304000f1308SRahul Sharma #endif 1305000f1308SRahul Sharma 1306000f1308SRahul Sharma static const struct dev_pm_ops mixer_pm_ops = { 1307000f1308SRahul Sharma SET_SYSTEM_SLEEP_PM_OPS(mixer_suspend, mixer_resume) 1308000f1308SRahul Sharma SET_RUNTIME_PM_OPS(mixer_runtime_suspend, mixer_runtime_resume, NULL) 1309000f1308SRahul Sharma }; 1310ab27af85SJoonyoung Shim 1311d8408326SSeung-Woo Kim struct platform_driver mixer_driver = { 1312d8408326SSeung-Woo Kim .driver = { 1313aaf8b49eSRahul Sharma .name = "exynos-mixer", 1314d8408326SSeung-Woo Kim .owner = THIS_MODULE, 1315ab27af85SJoonyoung Shim .pm = &mixer_pm_ops, 1316aaf8b49eSRahul Sharma .of_match_table = mixer_match_types, 1317d8408326SSeung-Woo Kim }, 1318d8408326SSeung-Woo Kim .probe = mixer_probe, 1319*56550d94SGreg Kroah-Hartman .remove = mixer_remove, 13201e123441SRahul Sharma .id_table = mixer_driver_types, 1321d8408326SSeung-Woo Kim }; 1322