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 17d8408326SSeung-Woo Kim #include "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" 39d8408326SSeung-Woo Kim #include "exynos_hdmi.h" 40*22b21ae6SJoonyoung Shim 41*22b21ae6SJoonyoung Shim #define HDMI_OVERLAY_NUMBER 3 42d8408326SSeung-Woo Kim 43d8408326SSeung-Woo Kim #define get_mixer_context(dev) platform_get_drvdata(to_platform_device(dev)) 44d8408326SSeung-Woo Kim 45*22b21ae6SJoonyoung Shim struct hdmi_win_data { 46*22b21ae6SJoonyoung Shim dma_addr_t dma_addr; 47*22b21ae6SJoonyoung Shim void __iomem *vaddr; 48*22b21ae6SJoonyoung Shim dma_addr_t chroma_dma_addr; 49*22b21ae6SJoonyoung Shim void __iomem *chroma_vaddr; 50*22b21ae6SJoonyoung Shim uint32_t pixel_format; 51*22b21ae6SJoonyoung Shim unsigned int bpp; 52*22b21ae6SJoonyoung Shim unsigned int crtc_x; 53*22b21ae6SJoonyoung Shim unsigned int crtc_y; 54*22b21ae6SJoonyoung Shim unsigned int crtc_width; 55*22b21ae6SJoonyoung Shim unsigned int crtc_height; 56*22b21ae6SJoonyoung Shim unsigned int fb_x; 57*22b21ae6SJoonyoung Shim unsigned int fb_y; 58*22b21ae6SJoonyoung Shim unsigned int fb_width; 59*22b21ae6SJoonyoung Shim unsigned int fb_height; 60*22b21ae6SJoonyoung Shim unsigned int mode_width; 61*22b21ae6SJoonyoung Shim unsigned int mode_height; 62*22b21ae6SJoonyoung Shim unsigned int scan_flags; 63*22b21ae6SJoonyoung Shim }; 64*22b21ae6SJoonyoung Shim 65*22b21ae6SJoonyoung Shim struct mixer_resources { 66*22b21ae6SJoonyoung Shim struct device *dev; 67*22b21ae6SJoonyoung Shim int irq; 68*22b21ae6SJoonyoung Shim void __iomem *mixer_regs; 69*22b21ae6SJoonyoung Shim void __iomem *vp_regs; 70*22b21ae6SJoonyoung Shim spinlock_t reg_slock; 71*22b21ae6SJoonyoung Shim struct clk *mixer; 72*22b21ae6SJoonyoung Shim struct clk *vp; 73*22b21ae6SJoonyoung Shim struct clk *sclk_mixer; 74*22b21ae6SJoonyoung Shim struct clk *sclk_hdmi; 75*22b21ae6SJoonyoung Shim struct clk *sclk_dac; 76*22b21ae6SJoonyoung Shim }; 77*22b21ae6SJoonyoung Shim 78*22b21ae6SJoonyoung Shim struct mixer_context { 79*22b21ae6SJoonyoung Shim struct fb_videomode *default_timing; 80*22b21ae6SJoonyoung Shim unsigned int default_win; 81*22b21ae6SJoonyoung Shim unsigned int default_bpp; 82*22b21ae6SJoonyoung Shim unsigned int irq; 83*22b21ae6SJoonyoung Shim int pipe; 84*22b21ae6SJoonyoung Shim bool interlace; 85*22b21ae6SJoonyoung Shim bool vp_enabled; 86*22b21ae6SJoonyoung Shim 87*22b21ae6SJoonyoung Shim struct mixer_resources mixer_res; 88*22b21ae6SJoonyoung Shim struct hdmi_win_data win_data[HDMI_OVERLAY_NUMBER]; 89*22b21ae6SJoonyoung Shim }; 90*22b21ae6SJoonyoung Shim 91d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = { 92d8408326SSeung-Woo Kim 0, -1, -1, -1, -1, -1, -1, -1, 93d8408326SSeung-Woo Kim -1, -1, -1, -1, -1, 0, 0, 0, 94d8408326SSeung-Woo Kim 0, 2, 4, 5, 6, 6, 6, 6, 95d8408326SSeung-Woo Kim 6, 5, 5, 4, 3, 2, 1, 1, 96d8408326SSeung-Woo Kim 0, -6, -12, -16, -18, -20, -21, -20, 97d8408326SSeung-Woo Kim -20, -18, -16, -13, -10, -8, -5, -2, 98d8408326SSeung-Woo Kim 127, 126, 125, 121, 114, 107, 99, 89, 99d8408326SSeung-Woo Kim 79, 68, 57, 46, 35, 25, 16, 8, 100d8408326SSeung-Woo Kim }; 101d8408326SSeung-Woo Kim 102d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = { 103d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7, 104d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0, 105d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81, 106d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5, 107d8408326SSeung-Woo Kim 0, 5, 11, 19, 27, 37, 48, 59, 108d8408326SSeung-Woo Kim 70, 81, 92, 102, 111, 118, 124, 126, 109d8408326SSeung-Woo Kim 0, 0, -1, -1, -2, -3, -4, -5, 110d8408326SSeung-Woo Kim -6, -7, -8, -8, -8, -8, -6, -3, 111d8408326SSeung-Woo Kim }; 112d8408326SSeung-Woo Kim 113d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = { 114d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7, 115d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0, 116d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81, 117d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5, 118d8408326SSeung-Woo Kim }; 119d8408326SSeung-Woo Kim 120d8408326SSeung-Woo Kim static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id) 121d8408326SSeung-Woo Kim { 122d8408326SSeung-Woo Kim return readl(res->vp_regs + reg_id); 123d8408326SSeung-Woo Kim } 124d8408326SSeung-Woo Kim 125d8408326SSeung-Woo Kim static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id, 126d8408326SSeung-Woo Kim u32 val) 127d8408326SSeung-Woo Kim { 128d8408326SSeung-Woo Kim writel(val, res->vp_regs + reg_id); 129d8408326SSeung-Woo Kim } 130d8408326SSeung-Woo Kim 131d8408326SSeung-Woo Kim static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id, 132d8408326SSeung-Woo Kim u32 val, u32 mask) 133d8408326SSeung-Woo Kim { 134d8408326SSeung-Woo Kim u32 old = vp_reg_read(res, reg_id); 135d8408326SSeung-Woo Kim 136d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask); 137d8408326SSeung-Woo Kim writel(val, res->vp_regs + reg_id); 138d8408326SSeung-Woo Kim } 139d8408326SSeung-Woo Kim 140d8408326SSeung-Woo Kim static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id) 141d8408326SSeung-Woo Kim { 142d8408326SSeung-Woo Kim return readl(res->mixer_regs + reg_id); 143d8408326SSeung-Woo Kim } 144d8408326SSeung-Woo Kim 145d8408326SSeung-Woo Kim static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id, 146d8408326SSeung-Woo Kim u32 val) 147d8408326SSeung-Woo Kim { 148d8408326SSeung-Woo Kim writel(val, res->mixer_regs + reg_id); 149d8408326SSeung-Woo Kim } 150d8408326SSeung-Woo Kim 151d8408326SSeung-Woo Kim static inline void mixer_reg_writemask(struct mixer_resources *res, 152d8408326SSeung-Woo Kim u32 reg_id, u32 val, u32 mask) 153d8408326SSeung-Woo Kim { 154d8408326SSeung-Woo Kim u32 old = mixer_reg_read(res, reg_id); 155d8408326SSeung-Woo Kim 156d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask); 157d8408326SSeung-Woo Kim writel(val, res->mixer_regs + reg_id); 158d8408326SSeung-Woo Kim } 159d8408326SSeung-Woo Kim 160d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx) 161d8408326SSeung-Woo Kim { 162d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \ 163d8408326SSeung-Woo Kim do { \ 164d8408326SSeung-Woo Kim DRM_DEBUG_KMS(#reg_id " = %08x\n", \ 165d8408326SSeung-Woo Kim (u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \ 166d8408326SSeung-Woo Kim } while (0) 167d8408326SSeung-Woo Kim 168d8408326SSeung-Woo Kim DUMPREG(MXR_STATUS); 169d8408326SSeung-Woo Kim DUMPREG(MXR_CFG); 170d8408326SSeung-Woo Kim DUMPREG(MXR_INT_EN); 171d8408326SSeung-Woo Kim DUMPREG(MXR_INT_STATUS); 172d8408326SSeung-Woo Kim 173d8408326SSeung-Woo Kim DUMPREG(MXR_LAYER_CFG); 174d8408326SSeung-Woo Kim DUMPREG(MXR_VIDEO_CFG); 175d8408326SSeung-Woo Kim 176d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_CFG); 177d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_BASE); 178d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SPAN); 179d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_WH); 180d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SXY); 181d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_DXY); 182d8408326SSeung-Woo Kim 183d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_CFG); 184d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_BASE); 185d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SPAN); 186d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_WH); 187d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SXY); 188d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_DXY); 189d8408326SSeung-Woo Kim #undef DUMPREG 190d8408326SSeung-Woo Kim } 191d8408326SSeung-Woo Kim 192d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx) 193d8408326SSeung-Woo Kim { 194d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \ 195d8408326SSeung-Woo Kim do { \ 196d8408326SSeung-Woo Kim DRM_DEBUG_KMS(#reg_id " = %08x\n", \ 197d8408326SSeung-Woo Kim (u32) readl(ctx->mixer_res.vp_regs + reg_id)); \ 198d8408326SSeung-Woo Kim } while (0) 199d8408326SSeung-Woo Kim 200d8408326SSeung-Woo Kim DUMPREG(VP_ENABLE); 201d8408326SSeung-Woo Kim DUMPREG(VP_SRESET); 202d8408326SSeung-Woo Kim DUMPREG(VP_SHADOW_UPDATE); 203d8408326SSeung-Woo Kim DUMPREG(VP_FIELD_ID); 204d8408326SSeung-Woo Kim DUMPREG(VP_MODE); 205d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_Y); 206d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_C); 207d8408326SSeung-Woo Kim DUMPREG(VP_PER_RATE_CTRL); 208d8408326SSeung-Woo Kim DUMPREG(VP_TOP_Y_PTR); 209d8408326SSeung-Woo Kim DUMPREG(VP_BOT_Y_PTR); 210d8408326SSeung-Woo Kim DUMPREG(VP_TOP_C_PTR); 211d8408326SSeung-Woo Kim DUMPREG(VP_BOT_C_PTR); 212d8408326SSeung-Woo Kim DUMPREG(VP_ENDIAN_MODE); 213d8408326SSeung-Woo Kim DUMPREG(VP_SRC_H_POSITION); 214d8408326SSeung-Woo Kim DUMPREG(VP_SRC_V_POSITION); 215d8408326SSeung-Woo Kim DUMPREG(VP_SRC_WIDTH); 216d8408326SSeung-Woo Kim DUMPREG(VP_SRC_HEIGHT); 217d8408326SSeung-Woo Kim DUMPREG(VP_DST_H_POSITION); 218d8408326SSeung-Woo Kim DUMPREG(VP_DST_V_POSITION); 219d8408326SSeung-Woo Kim DUMPREG(VP_DST_WIDTH); 220d8408326SSeung-Woo Kim DUMPREG(VP_DST_HEIGHT); 221d8408326SSeung-Woo Kim DUMPREG(VP_H_RATIO); 222d8408326SSeung-Woo Kim DUMPREG(VP_V_RATIO); 223d8408326SSeung-Woo Kim 224d8408326SSeung-Woo Kim #undef DUMPREG 225d8408326SSeung-Woo Kim } 226d8408326SSeung-Woo Kim 227d8408326SSeung-Woo Kim static inline void vp_filter_set(struct mixer_resources *res, 228d8408326SSeung-Woo Kim int reg_id, const u8 *data, unsigned int size) 229d8408326SSeung-Woo Kim { 230d8408326SSeung-Woo Kim /* assure 4-byte align */ 231d8408326SSeung-Woo Kim BUG_ON(size & 3); 232d8408326SSeung-Woo Kim for (; size; size -= 4, reg_id += 4, data += 4) { 233d8408326SSeung-Woo Kim u32 val = (data[0] << 24) | (data[1] << 16) | 234d8408326SSeung-Woo Kim (data[2] << 8) | data[3]; 235d8408326SSeung-Woo Kim vp_reg_write(res, reg_id, val); 236d8408326SSeung-Woo Kim } 237d8408326SSeung-Woo Kim } 238d8408326SSeung-Woo Kim 239d8408326SSeung-Woo Kim static void vp_default_filter(struct mixer_resources *res) 240d8408326SSeung-Woo Kim { 241d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY8_Y0_LL, 242d8408326SSeung-Woo Kim filter_y_horiz_tap8, sizeof filter_y_horiz_tap8); 243d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY4_Y0_LL, 244d8408326SSeung-Woo Kim filter_y_vert_tap4, sizeof filter_y_vert_tap4); 245d8408326SSeung-Woo Kim vp_filter_set(res, VP_POLY4_C0_LL, 246d8408326SSeung-Woo Kim filter_cr_horiz_tap4, sizeof filter_cr_horiz_tap4); 247d8408326SSeung-Woo Kim } 248d8408326SSeung-Woo Kim 249d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable) 250d8408326SSeung-Woo Kim { 251d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 252d8408326SSeung-Woo Kim 253d8408326SSeung-Woo Kim /* block update on vsync */ 254d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_STATUS, enable ? 255d8408326SSeung-Woo Kim MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE); 256d8408326SSeung-Woo Kim 257d8408326SSeung-Woo Kim vp_reg_write(res, VP_SHADOW_UPDATE, enable ? 258d8408326SSeung-Woo Kim VP_SHADOW_UPDATE_ENABLE : 0); 259d8408326SSeung-Woo Kim } 260d8408326SSeung-Woo Kim 261d8408326SSeung-Woo Kim static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height) 262d8408326SSeung-Woo Kim { 263d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 264d8408326SSeung-Woo Kim u32 val; 265d8408326SSeung-Woo Kim 266d8408326SSeung-Woo Kim /* choosing between interlace and progressive mode */ 267d8408326SSeung-Woo Kim val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE : 268d8408326SSeung-Woo Kim MXR_CFG_SCAN_PROGRASSIVE); 269d8408326SSeung-Woo Kim 270d8408326SSeung-Woo Kim /* choosing between porper HD and SD mode */ 271d8408326SSeung-Woo Kim if (height == 480) 272d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD; 273d8408326SSeung-Woo Kim else if (height == 576) 274d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD; 275d8408326SSeung-Woo Kim else if (height == 720) 276d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; 277d8408326SSeung-Woo Kim else if (height == 1080) 278d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD; 279d8408326SSeung-Woo Kim else 280d8408326SSeung-Woo Kim val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD; 281d8408326SSeung-Woo Kim 282d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK); 283d8408326SSeung-Woo Kim } 284d8408326SSeung-Woo Kim 285d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height) 286d8408326SSeung-Woo Kim { 287d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 288d8408326SSeung-Woo Kim u32 val; 289d8408326SSeung-Woo Kim 290d8408326SSeung-Woo Kim if (height == 480) { 291d8408326SSeung-Woo Kim val = MXR_CFG_RGB601_0_255; 292d8408326SSeung-Woo Kim } else if (height == 576) { 293d8408326SSeung-Woo Kim val = MXR_CFG_RGB601_0_255; 294d8408326SSeung-Woo Kim } else if (height == 720) { 295d8408326SSeung-Woo Kim val = MXR_CFG_RGB709_16_235; 296d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_Y, 297d8408326SSeung-Woo Kim (1 << 30) | (94 << 20) | (314 << 10) | 298d8408326SSeung-Woo Kim (32 << 0)); 299d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CB, 300d8408326SSeung-Woo Kim (972 << 20) | (851 << 10) | (225 << 0)); 301d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CR, 302d8408326SSeung-Woo Kim (225 << 20) | (820 << 10) | (1004 << 0)); 303d8408326SSeung-Woo Kim } else if (height == 1080) { 304d8408326SSeung-Woo Kim val = MXR_CFG_RGB709_16_235; 305d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_Y, 306d8408326SSeung-Woo Kim (1 << 30) | (94 << 20) | (314 << 10) | 307d8408326SSeung-Woo Kim (32 << 0)); 308d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CB, 309d8408326SSeung-Woo Kim (972 << 20) | (851 << 10) | (225 << 0)); 310d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CR, 311d8408326SSeung-Woo Kim (225 << 20) | (820 << 10) | (1004 << 0)); 312d8408326SSeung-Woo Kim } else { 313d8408326SSeung-Woo Kim val = MXR_CFG_RGB709_16_235; 314d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_Y, 315d8408326SSeung-Woo Kim (1 << 30) | (94 << 20) | (314 << 10) | 316d8408326SSeung-Woo Kim (32 << 0)); 317d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CB, 318d8408326SSeung-Woo Kim (972 << 20) | (851 << 10) | (225 << 0)); 319d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_CM_COEFF_CR, 320d8408326SSeung-Woo Kim (225 << 20) | (820 << 10) | (1004 << 0)); 321d8408326SSeung-Woo Kim } 322d8408326SSeung-Woo Kim 323d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK); 324d8408326SSeung-Woo Kim } 325d8408326SSeung-Woo Kim 326d8408326SSeung-Woo Kim static void mixer_cfg_layer(struct mixer_context *ctx, int win, bool enable) 327d8408326SSeung-Woo Kim { 328d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 329d8408326SSeung-Woo Kim u32 val = enable ? ~0 : 0; 330d8408326SSeung-Woo Kim 331d8408326SSeung-Woo Kim switch (win) { 332d8408326SSeung-Woo Kim case 0: 333d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE); 334d8408326SSeung-Woo Kim break; 335d8408326SSeung-Woo Kim case 1: 336d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE); 337d8408326SSeung-Woo Kim break; 338d8408326SSeung-Woo Kim case 2: 339d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON); 340d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_VP_ENABLE); 341d8408326SSeung-Woo Kim break; 342d8408326SSeung-Woo Kim } 343d8408326SSeung-Woo Kim } 344d8408326SSeung-Woo Kim 345d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx) 346d8408326SSeung-Woo Kim { 347d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 348d8408326SSeung-Woo Kim 349d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN); 350d8408326SSeung-Woo Kim 351d8408326SSeung-Woo Kim mixer_regs_dump(ctx); 352d8408326SSeung-Woo Kim } 353d8408326SSeung-Woo Kim 354d8408326SSeung-Woo Kim static void vp_video_buffer(struct mixer_context *ctx, int win) 355d8408326SSeung-Woo Kim { 356d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 357d8408326SSeung-Woo Kim unsigned long flags; 358d8408326SSeung-Woo Kim struct hdmi_win_data *win_data; 359d8408326SSeung-Woo Kim unsigned int full_width, full_height, width, height; 360d8408326SSeung-Woo Kim unsigned int x_ratio, y_ratio; 361d8408326SSeung-Woo Kim unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset; 362d8408326SSeung-Woo Kim unsigned int mode_width, mode_height; 363d8408326SSeung-Woo Kim unsigned int buf_num; 364d8408326SSeung-Woo Kim dma_addr_t luma_addr[2], chroma_addr[2]; 365d8408326SSeung-Woo Kim bool tiled_mode = false; 366d8408326SSeung-Woo Kim bool crcb_mode = false; 367d8408326SSeung-Woo Kim u32 val; 368d8408326SSeung-Woo Kim 369d8408326SSeung-Woo Kim win_data = &ctx->win_data[win]; 370d8408326SSeung-Woo Kim 371d8408326SSeung-Woo Kim switch (win_data->pixel_format) { 372d8408326SSeung-Woo Kim case DRM_FORMAT_NV12MT: 373d8408326SSeung-Woo Kim tiled_mode = true; 374d8408326SSeung-Woo Kim case DRM_FORMAT_NV12M: 375d8408326SSeung-Woo Kim crcb_mode = false; 376d8408326SSeung-Woo Kim buf_num = 2; 377d8408326SSeung-Woo Kim break; 378d8408326SSeung-Woo Kim /* TODO: single buffer format NV12, NV21 */ 379d8408326SSeung-Woo Kim default: 380d8408326SSeung-Woo Kim /* ignore pixel format at disable time */ 381d8408326SSeung-Woo Kim if (!win_data->dma_addr) 382d8408326SSeung-Woo Kim break; 383d8408326SSeung-Woo Kim 384d8408326SSeung-Woo Kim DRM_ERROR("pixel format for vp is wrong [%d].\n", 385d8408326SSeung-Woo Kim win_data->pixel_format); 386d8408326SSeung-Woo Kim return; 387d8408326SSeung-Woo Kim } 388d8408326SSeung-Woo Kim 389d8408326SSeung-Woo Kim full_width = win_data->fb_width; 390d8408326SSeung-Woo Kim full_height = win_data->fb_height; 391d8408326SSeung-Woo Kim width = win_data->crtc_width; 392d8408326SSeung-Woo Kim height = win_data->crtc_height; 393d8408326SSeung-Woo Kim mode_width = win_data->mode_width; 394d8408326SSeung-Woo Kim mode_height = win_data->mode_height; 395d8408326SSeung-Woo Kim 396d8408326SSeung-Woo Kim /* scaling feature: (src << 16) / dst */ 397d8408326SSeung-Woo Kim x_ratio = (width << 16) / width; 398d8408326SSeung-Woo Kim y_ratio = (height << 16) / height; 399d8408326SSeung-Woo Kim 400d8408326SSeung-Woo Kim src_x_offset = win_data->fb_x; 401d8408326SSeung-Woo Kim src_y_offset = win_data->fb_y; 402d8408326SSeung-Woo Kim dst_x_offset = win_data->crtc_x; 403d8408326SSeung-Woo Kim dst_y_offset = win_data->crtc_y; 404d8408326SSeung-Woo Kim 405d8408326SSeung-Woo Kim if (buf_num == 2) { 406d8408326SSeung-Woo Kim luma_addr[0] = win_data->dma_addr; 407d8408326SSeung-Woo Kim chroma_addr[0] = win_data->chroma_dma_addr; 408d8408326SSeung-Woo Kim } else { 409d8408326SSeung-Woo Kim luma_addr[0] = win_data->dma_addr; 410d8408326SSeung-Woo Kim chroma_addr[0] = win_data->dma_addr 411d8408326SSeung-Woo Kim + (full_width * full_height); 412d8408326SSeung-Woo Kim } 413d8408326SSeung-Woo Kim 414d8408326SSeung-Woo Kim if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE) { 415d8408326SSeung-Woo Kim ctx->interlace = true; 416d8408326SSeung-Woo Kim if (tiled_mode) { 417d8408326SSeung-Woo Kim luma_addr[1] = luma_addr[0] + 0x40; 418d8408326SSeung-Woo Kim chroma_addr[1] = chroma_addr[0] + 0x40; 419d8408326SSeung-Woo Kim } else { 420d8408326SSeung-Woo Kim luma_addr[1] = luma_addr[0] + full_width; 421d8408326SSeung-Woo Kim chroma_addr[1] = chroma_addr[0] + full_width; 422d8408326SSeung-Woo Kim } 423d8408326SSeung-Woo Kim } else { 424d8408326SSeung-Woo Kim ctx->interlace = false; 425d8408326SSeung-Woo Kim luma_addr[1] = 0; 426d8408326SSeung-Woo Kim chroma_addr[1] = 0; 427d8408326SSeung-Woo Kim } 428d8408326SSeung-Woo Kim 429d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 430d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, false); 431d8408326SSeung-Woo Kim 432d8408326SSeung-Woo Kim /* interlace or progressive scan mode */ 433d8408326SSeung-Woo Kim val = (ctx->interlace ? ~0 : 0); 434d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP); 435d8408326SSeung-Woo Kim 436d8408326SSeung-Woo Kim /* setup format */ 437d8408326SSeung-Woo Kim val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12); 438d8408326SSeung-Woo Kim val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR); 439d8408326SSeung-Woo Kim vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK); 440d8408326SSeung-Woo Kim 441d8408326SSeung-Woo Kim /* setting size of input image */ 442d8408326SSeung-Woo Kim vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(full_width) | 443d8408326SSeung-Woo Kim VP_IMG_VSIZE(full_height)); 444d8408326SSeung-Woo Kim /* chroma height has to reduced by 2 to avoid chroma distorions */ 445d8408326SSeung-Woo Kim vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(full_width) | 446d8408326SSeung-Woo Kim VP_IMG_VSIZE(full_height / 2)); 447d8408326SSeung-Woo Kim 448d8408326SSeung-Woo Kim vp_reg_write(res, VP_SRC_WIDTH, width); 449d8408326SSeung-Woo Kim vp_reg_write(res, VP_SRC_HEIGHT, height); 450d8408326SSeung-Woo Kim vp_reg_write(res, VP_SRC_H_POSITION, 451d8408326SSeung-Woo Kim VP_SRC_H_POSITION_VAL(src_x_offset)); 452d8408326SSeung-Woo Kim vp_reg_write(res, VP_SRC_V_POSITION, src_y_offset); 453d8408326SSeung-Woo Kim 454d8408326SSeung-Woo Kim vp_reg_write(res, VP_DST_WIDTH, width); 455d8408326SSeung-Woo Kim vp_reg_write(res, VP_DST_H_POSITION, dst_x_offset); 456d8408326SSeung-Woo Kim if (ctx->interlace) { 457d8408326SSeung-Woo Kim vp_reg_write(res, VP_DST_HEIGHT, height / 2); 458d8408326SSeung-Woo Kim vp_reg_write(res, VP_DST_V_POSITION, dst_y_offset / 2); 459d8408326SSeung-Woo Kim } else { 460d8408326SSeung-Woo Kim vp_reg_write(res, VP_DST_HEIGHT, height); 461d8408326SSeung-Woo Kim vp_reg_write(res, VP_DST_V_POSITION, dst_y_offset); 462d8408326SSeung-Woo Kim } 463d8408326SSeung-Woo Kim 464d8408326SSeung-Woo Kim vp_reg_write(res, VP_H_RATIO, x_ratio); 465d8408326SSeung-Woo Kim vp_reg_write(res, VP_V_RATIO, y_ratio); 466d8408326SSeung-Woo Kim 467d8408326SSeung-Woo Kim vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE); 468d8408326SSeung-Woo Kim 469d8408326SSeung-Woo Kim /* set buffer address to vp */ 470d8408326SSeung-Woo Kim vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]); 471d8408326SSeung-Woo Kim vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]); 472d8408326SSeung-Woo Kim vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]); 473d8408326SSeung-Woo Kim vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]); 474d8408326SSeung-Woo Kim 475d8408326SSeung-Woo Kim mixer_cfg_scan(ctx, mode_height); 476d8408326SSeung-Woo Kim mixer_cfg_rgb_fmt(ctx, mode_height); 477d8408326SSeung-Woo Kim mixer_cfg_layer(ctx, win, true); 478d8408326SSeung-Woo Kim mixer_run(ctx); 479d8408326SSeung-Woo Kim 480d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, true); 481d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 482d8408326SSeung-Woo Kim 483d8408326SSeung-Woo Kim vp_regs_dump(ctx); 484d8408326SSeung-Woo Kim } 485d8408326SSeung-Woo Kim 486d8408326SSeung-Woo Kim static void mixer_graph_buffer(struct mixer_context *ctx, int win) 487d8408326SSeung-Woo Kim { 488d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 489d8408326SSeung-Woo Kim unsigned long flags; 490d8408326SSeung-Woo Kim struct hdmi_win_data *win_data; 491d8408326SSeung-Woo Kim unsigned int full_width, width, height; 492d8408326SSeung-Woo Kim unsigned int x_ratio, y_ratio; 493d8408326SSeung-Woo Kim unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset; 494d8408326SSeung-Woo Kim unsigned int mode_width, mode_height; 495d8408326SSeung-Woo Kim dma_addr_t dma_addr; 496d8408326SSeung-Woo Kim unsigned int fmt; 497d8408326SSeung-Woo Kim u32 val; 498d8408326SSeung-Woo Kim 499d8408326SSeung-Woo Kim win_data = &ctx->win_data[win]; 500d8408326SSeung-Woo Kim 501d8408326SSeung-Woo Kim #define RGB565 4 502d8408326SSeung-Woo Kim #define ARGB1555 5 503d8408326SSeung-Woo Kim #define ARGB4444 6 504d8408326SSeung-Woo Kim #define ARGB8888 7 505d8408326SSeung-Woo Kim 506d8408326SSeung-Woo Kim switch (win_data->bpp) { 507d8408326SSeung-Woo Kim case 16: 508d8408326SSeung-Woo Kim fmt = ARGB4444; 509d8408326SSeung-Woo Kim break; 510d8408326SSeung-Woo Kim case 32: 511d8408326SSeung-Woo Kim fmt = ARGB8888; 512d8408326SSeung-Woo Kim break; 513d8408326SSeung-Woo Kim default: 514d8408326SSeung-Woo Kim fmt = ARGB8888; 515d8408326SSeung-Woo Kim } 516d8408326SSeung-Woo Kim 517d8408326SSeung-Woo Kim dma_addr = win_data->dma_addr; 518d8408326SSeung-Woo Kim full_width = win_data->fb_width; 519d8408326SSeung-Woo Kim width = win_data->crtc_width; 520d8408326SSeung-Woo Kim height = win_data->crtc_height; 521d8408326SSeung-Woo Kim mode_width = win_data->mode_width; 522d8408326SSeung-Woo Kim mode_height = win_data->mode_height; 523d8408326SSeung-Woo Kim 524d8408326SSeung-Woo Kim /* 2x scaling feature */ 525d8408326SSeung-Woo Kim x_ratio = 0; 526d8408326SSeung-Woo Kim y_ratio = 0; 527d8408326SSeung-Woo Kim 528d8408326SSeung-Woo Kim src_x_offset = win_data->fb_x; 529d8408326SSeung-Woo Kim src_y_offset = win_data->fb_y; 530d8408326SSeung-Woo Kim dst_x_offset = win_data->crtc_x; 531d8408326SSeung-Woo Kim dst_y_offset = win_data->crtc_y; 532d8408326SSeung-Woo Kim 533d8408326SSeung-Woo Kim /* converting dma address base and source offset */ 534d8408326SSeung-Woo Kim dma_addr = dma_addr 535d8408326SSeung-Woo Kim + (src_x_offset * win_data->bpp >> 3) 536d8408326SSeung-Woo Kim + (src_y_offset * full_width * win_data->bpp >> 3); 537d8408326SSeung-Woo Kim src_x_offset = 0; 538d8408326SSeung-Woo Kim src_y_offset = 0; 539d8408326SSeung-Woo Kim 540d8408326SSeung-Woo Kim if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE) 541d8408326SSeung-Woo Kim ctx->interlace = true; 542d8408326SSeung-Woo Kim else 543d8408326SSeung-Woo Kim ctx->interlace = false; 544d8408326SSeung-Woo Kim 545d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 546d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, false); 547d8408326SSeung-Woo Kim 548d8408326SSeung-Woo Kim /* setup format */ 549d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win), 550d8408326SSeung-Woo Kim MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK); 551d8408326SSeung-Woo Kim 552d8408326SSeung-Woo Kim /* setup geometry */ 553d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_SPAN(win), full_width); 554d8408326SSeung-Woo Kim 555d8408326SSeung-Woo Kim val = MXR_GRP_WH_WIDTH(width); 556d8408326SSeung-Woo Kim val |= MXR_GRP_WH_HEIGHT(height); 557d8408326SSeung-Woo Kim val |= MXR_GRP_WH_H_SCALE(x_ratio); 558d8408326SSeung-Woo Kim val |= MXR_GRP_WH_V_SCALE(y_ratio); 559d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_WH(win), val); 560d8408326SSeung-Woo Kim 561d8408326SSeung-Woo Kim /* setup offsets in source image */ 562d8408326SSeung-Woo Kim val = MXR_GRP_SXY_SX(src_x_offset); 563d8408326SSeung-Woo Kim val |= MXR_GRP_SXY_SY(src_y_offset); 564d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val); 565d8408326SSeung-Woo Kim 566d8408326SSeung-Woo Kim /* setup offsets in display image */ 567d8408326SSeung-Woo Kim val = MXR_GRP_DXY_DX(dst_x_offset); 568d8408326SSeung-Woo Kim val |= MXR_GRP_DXY_DY(dst_y_offset); 569d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val); 570d8408326SSeung-Woo Kim 571d8408326SSeung-Woo Kim /* set buffer address to mixer */ 572d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr); 573d8408326SSeung-Woo Kim 574d8408326SSeung-Woo Kim mixer_cfg_scan(ctx, mode_height); 575d8408326SSeung-Woo Kim mixer_cfg_rgb_fmt(ctx, mode_height); 576d8408326SSeung-Woo Kim mixer_cfg_layer(ctx, win, true); 577d8408326SSeung-Woo Kim mixer_run(ctx); 578d8408326SSeung-Woo Kim 579d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, true); 580d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 581d8408326SSeung-Woo Kim } 582d8408326SSeung-Woo Kim 583d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx) 584d8408326SSeung-Woo Kim { 585d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 586d8408326SSeung-Woo Kim int tries = 100; 587d8408326SSeung-Woo Kim 588d8408326SSeung-Woo Kim vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING); 589d8408326SSeung-Woo Kim for (tries = 100; tries; --tries) { 590d8408326SSeung-Woo Kim /* waiting until VP_SRESET_PROCESSING is 0 */ 591d8408326SSeung-Woo Kim if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING) 592d8408326SSeung-Woo Kim break; 593d8408326SSeung-Woo Kim mdelay(10); 594d8408326SSeung-Woo Kim } 595d8408326SSeung-Woo Kim WARN(tries == 0, "failed to reset Video Processor\n"); 596d8408326SSeung-Woo Kim } 597d8408326SSeung-Woo Kim 598d8408326SSeung-Woo Kim static int mixer_enable_vblank(void *ctx, int pipe) 599d8408326SSeung-Woo Kim { 600d8408326SSeung-Woo Kim struct mixer_context *mixer_ctx = ctx; 601d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 602d8408326SSeung-Woo Kim 603d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 604d8408326SSeung-Woo Kim 605d8408326SSeung-Woo Kim mixer_ctx->pipe = pipe; 606d8408326SSeung-Woo Kim 607d8408326SSeung-Woo Kim /* enable vsync interrupt */ 608d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_INT_EN, MXR_INT_EN_VSYNC, 609d8408326SSeung-Woo Kim MXR_INT_EN_VSYNC); 610d8408326SSeung-Woo Kim 611d8408326SSeung-Woo Kim return 0; 612d8408326SSeung-Woo Kim } 613d8408326SSeung-Woo Kim 614d8408326SSeung-Woo Kim static void mixer_disable_vblank(void *ctx) 615d8408326SSeung-Woo Kim { 616d8408326SSeung-Woo Kim struct mixer_context *mixer_ctx = ctx; 617d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 618d8408326SSeung-Woo Kim 619d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 620d8408326SSeung-Woo Kim 621d8408326SSeung-Woo Kim /* disable vsync interrupt */ 622d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC); 623d8408326SSeung-Woo Kim } 624d8408326SSeung-Woo Kim 625d8408326SSeung-Woo Kim static void mixer_win_mode_set(void *ctx, 626d8408326SSeung-Woo Kim struct exynos_drm_overlay *overlay) 627d8408326SSeung-Woo Kim { 628d8408326SSeung-Woo Kim struct mixer_context *mixer_ctx = ctx; 629d8408326SSeung-Woo Kim struct hdmi_win_data *win_data; 630d8408326SSeung-Woo Kim int win; 631d8408326SSeung-Woo Kim 632d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 633d8408326SSeung-Woo Kim 634d8408326SSeung-Woo Kim if (!overlay) { 635d8408326SSeung-Woo Kim DRM_ERROR("overlay is NULL\n"); 636d8408326SSeung-Woo Kim return; 637d8408326SSeung-Woo Kim } 638d8408326SSeung-Woo Kim 639d8408326SSeung-Woo Kim DRM_DEBUG_KMS("set [%d]x[%d] at (%d,%d) to [%d]x[%d] at (%d,%d)\n", 640d8408326SSeung-Woo Kim overlay->fb_width, overlay->fb_height, 641d8408326SSeung-Woo Kim overlay->fb_x, overlay->fb_y, 642d8408326SSeung-Woo Kim overlay->crtc_width, overlay->crtc_height, 643d8408326SSeung-Woo Kim overlay->crtc_x, overlay->crtc_y); 644d8408326SSeung-Woo Kim 645d8408326SSeung-Woo Kim win = overlay->zpos; 646d8408326SSeung-Woo Kim if (win == DEFAULT_ZPOS) 647d8408326SSeung-Woo Kim win = mixer_ctx->default_win; 648d8408326SSeung-Woo Kim 649d8408326SSeung-Woo Kim if (win < 0 || win > HDMI_OVERLAY_NUMBER) { 650d8408326SSeung-Woo Kim DRM_ERROR("overlay plane[%d] is wrong\n", win); 651d8408326SSeung-Woo Kim return; 652d8408326SSeung-Woo Kim } 653d8408326SSeung-Woo Kim 654d8408326SSeung-Woo Kim win_data = &mixer_ctx->win_data[win]; 655d8408326SSeung-Woo Kim 656d8408326SSeung-Woo Kim win_data->dma_addr = overlay->dma_addr[0]; 657d8408326SSeung-Woo Kim win_data->vaddr = overlay->vaddr[0]; 658d8408326SSeung-Woo Kim win_data->chroma_dma_addr = overlay->dma_addr[1]; 659d8408326SSeung-Woo Kim win_data->chroma_vaddr = overlay->vaddr[1]; 660d8408326SSeung-Woo Kim win_data->pixel_format = overlay->pixel_format; 661d8408326SSeung-Woo Kim win_data->bpp = overlay->bpp; 662d8408326SSeung-Woo Kim 663d8408326SSeung-Woo Kim win_data->crtc_x = overlay->crtc_x; 664d8408326SSeung-Woo Kim win_data->crtc_y = overlay->crtc_y; 665d8408326SSeung-Woo Kim win_data->crtc_width = overlay->crtc_width; 666d8408326SSeung-Woo Kim win_data->crtc_height = overlay->crtc_height; 667d8408326SSeung-Woo Kim 668d8408326SSeung-Woo Kim win_data->fb_x = overlay->fb_x; 669d8408326SSeung-Woo Kim win_data->fb_y = overlay->fb_y; 670d8408326SSeung-Woo Kim win_data->fb_width = overlay->fb_width; 671d8408326SSeung-Woo Kim win_data->fb_height = overlay->fb_height; 672d8408326SSeung-Woo Kim 673d8408326SSeung-Woo Kim win_data->mode_width = overlay->mode_width; 674d8408326SSeung-Woo Kim win_data->mode_height = overlay->mode_height; 675d8408326SSeung-Woo Kim 676d8408326SSeung-Woo Kim win_data->scan_flags = overlay->scan_flag; 677d8408326SSeung-Woo Kim } 678d8408326SSeung-Woo Kim 679d8408326SSeung-Woo Kim static void mixer_win_commit(void *ctx, int zpos) 680d8408326SSeung-Woo Kim { 681d8408326SSeung-Woo Kim struct mixer_context *mixer_ctx = ctx; 682d8408326SSeung-Woo Kim int win = zpos; 683d8408326SSeung-Woo Kim 684d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s, win: %d\n", __LINE__, __func__, win); 685d8408326SSeung-Woo Kim 686d8408326SSeung-Woo Kim if (win == DEFAULT_ZPOS) 687d8408326SSeung-Woo Kim win = mixer_ctx->default_win; 688d8408326SSeung-Woo Kim 689d8408326SSeung-Woo Kim if (win < 0 || win > HDMI_OVERLAY_NUMBER) { 690d8408326SSeung-Woo Kim DRM_ERROR("overlay plane[%d] is wrong\n", win); 691d8408326SSeung-Woo Kim return; 692d8408326SSeung-Woo Kim } 693d8408326SSeung-Woo Kim 694d8408326SSeung-Woo Kim if (win > 1) 695d8408326SSeung-Woo Kim vp_video_buffer(mixer_ctx, win); 696d8408326SSeung-Woo Kim else 697d8408326SSeung-Woo Kim mixer_graph_buffer(mixer_ctx, win); 698d8408326SSeung-Woo Kim } 699d8408326SSeung-Woo Kim 700d8408326SSeung-Woo Kim static void mixer_win_disable(void *ctx, int zpos) 701d8408326SSeung-Woo Kim { 702d8408326SSeung-Woo Kim struct mixer_context *mixer_ctx = ctx; 703d8408326SSeung-Woo Kim struct mixer_resources *res = &mixer_ctx->mixer_res; 704d8408326SSeung-Woo Kim unsigned long flags; 705d8408326SSeung-Woo Kim int win = zpos; 706d8408326SSeung-Woo Kim 707d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s, win: %d\n", __LINE__, __func__, win); 708d8408326SSeung-Woo Kim 709d8408326SSeung-Woo Kim if (win == DEFAULT_ZPOS) 710d8408326SSeung-Woo Kim win = mixer_ctx->default_win; 711d8408326SSeung-Woo Kim 712d8408326SSeung-Woo Kim if (win < 0 || win > HDMI_OVERLAY_NUMBER) { 713d8408326SSeung-Woo Kim DRM_ERROR("overlay plane[%d] is wrong\n", win); 714d8408326SSeung-Woo Kim return; 715d8408326SSeung-Woo Kim } 716d8408326SSeung-Woo Kim 717d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 718d8408326SSeung-Woo Kim mixer_vsync_set_update(mixer_ctx, false); 719d8408326SSeung-Woo Kim 720d8408326SSeung-Woo Kim mixer_cfg_layer(mixer_ctx, win, false); 721d8408326SSeung-Woo Kim 722d8408326SSeung-Woo Kim mixer_vsync_set_update(mixer_ctx, true); 723d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 724d8408326SSeung-Woo Kim } 725d8408326SSeung-Woo Kim 726d8408326SSeung-Woo Kim static struct exynos_hdmi_overlay_ops overlay_ops = { 727d8408326SSeung-Woo Kim .enable_vblank = mixer_enable_vblank, 728d8408326SSeung-Woo Kim .disable_vblank = mixer_disable_vblank, 729d8408326SSeung-Woo Kim .win_mode_set = mixer_win_mode_set, 730d8408326SSeung-Woo Kim .win_commit = mixer_win_commit, 731d8408326SSeung-Woo Kim .win_disable = mixer_win_disable, 732d8408326SSeung-Woo Kim }; 733d8408326SSeung-Woo Kim 734d8408326SSeung-Woo Kim /* for pageflip event */ 735d8408326SSeung-Woo Kim static void mixer_finish_pageflip(struct drm_device *drm_dev, int crtc) 736d8408326SSeung-Woo Kim { 737d8408326SSeung-Woo Kim struct exynos_drm_private *dev_priv = drm_dev->dev_private; 738d8408326SSeung-Woo Kim struct drm_pending_vblank_event *e, *t; 739d8408326SSeung-Woo Kim struct timeval now; 740d8408326SSeung-Woo Kim unsigned long flags; 741d8408326SSeung-Woo Kim bool is_checked = false; 742d8408326SSeung-Woo Kim 743d8408326SSeung-Woo Kim spin_lock_irqsave(&drm_dev->event_lock, flags); 744d8408326SSeung-Woo Kim 745d8408326SSeung-Woo Kim list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list, 746d8408326SSeung-Woo Kim base.link) { 747d8408326SSeung-Woo Kim /* if event's pipe isn't same as crtc then ignore it. */ 748d8408326SSeung-Woo Kim if (crtc != e->pipe) 749d8408326SSeung-Woo Kim continue; 750d8408326SSeung-Woo Kim 751d8408326SSeung-Woo Kim is_checked = true; 752d8408326SSeung-Woo Kim do_gettimeofday(&now); 753d8408326SSeung-Woo Kim e->event.sequence = 0; 754d8408326SSeung-Woo Kim e->event.tv_sec = now.tv_sec; 755d8408326SSeung-Woo Kim e->event.tv_usec = now.tv_usec; 756d8408326SSeung-Woo Kim 757d8408326SSeung-Woo Kim list_move_tail(&e->base.link, &e->base.file_priv->event_list); 758d8408326SSeung-Woo Kim wake_up_interruptible(&e->base.file_priv->event_wait); 759d8408326SSeung-Woo Kim } 760d8408326SSeung-Woo Kim 761d8408326SSeung-Woo Kim if (is_checked) 762c5614ae3SInki Dae /* 763c5614ae3SInki Dae * call drm_vblank_put only in case that drm_vblank_get was 764c5614ae3SInki Dae * called. 765c5614ae3SInki Dae */ 766c5614ae3SInki Dae if (atomic_read(&drm_dev->vblank_refcount[crtc]) > 0) 767d8408326SSeung-Woo Kim drm_vblank_put(drm_dev, crtc); 768d8408326SSeung-Woo Kim 769d8408326SSeung-Woo Kim spin_unlock_irqrestore(&drm_dev->event_lock, flags); 770d8408326SSeung-Woo Kim } 771d8408326SSeung-Woo Kim 772d8408326SSeung-Woo Kim static irqreturn_t mixer_irq_handler(int irq, void *arg) 773d8408326SSeung-Woo Kim { 774d8408326SSeung-Woo Kim struct exynos_drm_hdmi_context *drm_hdmi_ctx = arg; 775d8408326SSeung-Woo Kim struct mixer_context *ctx = 776d8408326SSeung-Woo Kim (struct mixer_context *)drm_hdmi_ctx->ctx; 777d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 778d8408326SSeung-Woo Kim u32 val, val_base; 779d8408326SSeung-Woo Kim 780d8408326SSeung-Woo Kim spin_lock(&res->reg_slock); 781d8408326SSeung-Woo Kim 782d8408326SSeung-Woo Kim /* read interrupt status for handling and clearing flags for VSYNC */ 783d8408326SSeung-Woo Kim val = mixer_reg_read(res, MXR_INT_STATUS); 784d8408326SSeung-Woo Kim 785d8408326SSeung-Woo Kim /* handling VSYNC */ 786d8408326SSeung-Woo Kim if (val & MXR_INT_STATUS_VSYNC) { 787d8408326SSeung-Woo Kim /* interlace scan need to check shadow register */ 788d8408326SSeung-Woo Kim if (ctx->interlace) { 789d8408326SSeung-Woo Kim val_base = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0)); 790d8408326SSeung-Woo Kim if (ctx->win_data[0].dma_addr != val_base) 791d8408326SSeung-Woo Kim goto out; 792d8408326SSeung-Woo Kim 793d8408326SSeung-Woo Kim val_base = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1)); 794d8408326SSeung-Woo Kim if (ctx->win_data[1].dma_addr != val_base) 795d8408326SSeung-Woo Kim goto out; 796d8408326SSeung-Woo Kim } 797d8408326SSeung-Woo Kim 798d8408326SSeung-Woo Kim drm_handle_vblank(drm_hdmi_ctx->drm_dev, ctx->pipe); 799d8408326SSeung-Woo Kim mixer_finish_pageflip(drm_hdmi_ctx->drm_dev, ctx->pipe); 800d8408326SSeung-Woo Kim } 801d8408326SSeung-Woo Kim 802d8408326SSeung-Woo Kim out: 803d8408326SSeung-Woo Kim /* clear interrupts */ 804d8408326SSeung-Woo Kim if (~val & MXR_INT_EN_VSYNC) { 805d8408326SSeung-Woo Kim /* vsync interrupt use different bit for read and clear */ 806d8408326SSeung-Woo Kim val &= ~MXR_INT_EN_VSYNC; 807d8408326SSeung-Woo Kim val |= MXR_INT_CLEAR_VSYNC; 808d8408326SSeung-Woo Kim } 809d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_INT_STATUS, val); 810d8408326SSeung-Woo Kim 811d8408326SSeung-Woo Kim spin_unlock(&res->reg_slock); 812d8408326SSeung-Woo Kim 813d8408326SSeung-Woo Kim return IRQ_HANDLED; 814d8408326SSeung-Woo Kim } 815d8408326SSeung-Woo Kim 816d8408326SSeung-Woo Kim static void mixer_win_reset(struct mixer_context *ctx) 817d8408326SSeung-Woo Kim { 818d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 819d8408326SSeung-Woo Kim unsigned long flags; 820d8408326SSeung-Woo Kim u32 val; /* value stored to register */ 821d8408326SSeung-Woo Kim 822d8408326SSeung-Woo Kim spin_lock_irqsave(&res->reg_slock, flags); 823d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, false); 824d8408326SSeung-Woo Kim 825d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK); 826d8408326SSeung-Woo Kim 827d8408326SSeung-Woo Kim /* set output in RGB888 mode */ 828d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK); 829d8408326SSeung-Woo Kim 830d8408326SSeung-Woo Kim /* 16 beat burst in DMA */ 831d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST, 832d8408326SSeung-Woo Kim MXR_STATUS_BURST_MASK); 833d8408326SSeung-Woo Kim 83444a0e022SJoonyoung Shim /* setting default layer priority: layer1 > layer0 > video 835d8408326SSeung-Woo Kim * because typical usage scenario would be 83644a0e022SJoonyoung Shim * layer1 - OSD 837d8408326SSeung-Woo Kim * layer0 - framebuffer 838d8408326SSeung-Woo Kim * video - video overlay 839d8408326SSeung-Woo Kim */ 84044a0e022SJoonyoung Shim val = MXR_LAYER_CFG_GRP1_VAL(3); 84144a0e022SJoonyoung Shim val |= MXR_LAYER_CFG_GRP0_VAL(2); 84244a0e022SJoonyoung Shim val |= MXR_LAYER_CFG_VP_VAL(1); 843d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_LAYER_CFG, val); 844d8408326SSeung-Woo Kim 845d8408326SSeung-Woo Kim /* setting background color */ 846d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_BG_COLOR0, 0x008080); 847d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_BG_COLOR1, 0x008080); 848d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_BG_COLOR2, 0x008080); 849d8408326SSeung-Woo Kim 850d8408326SSeung-Woo Kim /* setting graphical layers */ 851d8408326SSeung-Woo Kim 852d8408326SSeung-Woo Kim val = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */ 853d8408326SSeung-Woo Kim val |= MXR_GRP_CFG_WIN_BLEND_EN; 854d8408326SSeung-Woo Kim val |= MXR_GRP_CFG_ALPHA_VAL(0xff); /* non-transparent alpha */ 855d8408326SSeung-Woo Kim 856d8408326SSeung-Woo Kim /* the same configuration for both layers */ 857d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_CFG(0), val); 858d8408326SSeung-Woo Kim 859d8408326SSeung-Woo Kim val |= MXR_GRP_CFG_BLEND_PRE_MUL; 860d8408326SSeung-Woo Kim val |= MXR_GRP_CFG_PIXEL_BLEND_EN; 861d8408326SSeung-Woo Kim mixer_reg_write(res, MXR_GRAPHIC_CFG(1), val); 862d8408326SSeung-Woo Kim 863d8408326SSeung-Woo Kim /* configuration of Video Processor Registers */ 864d8408326SSeung-Woo Kim vp_win_reset(ctx); 865d8408326SSeung-Woo Kim vp_default_filter(res); 866d8408326SSeung-Woo Kim 867d8408326SSeung-Woo Kim /* disable all layers */ 868d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE); 869d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE); 870d8408326SSeung-Woo Kim mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE); 871d8408326SSeung-Woo Kim 872d8408326SSeung-Woo Kim mixer_vsync_set_update(ctx, true); 873d8408326SSeung-Woo Kim spin_unlock_irqrestore(&res->reg_slock, flags); 874d8408326SSeung-Woo Kim } 875d8408326SSeung-Woo Kim 876d8408326SSeung-Woo Kim static void mixer_resource_poweron(struct mixer_context *ctx) 877d8408326SSeung-Woo Kim { 878d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 879d8408326SSeung-Woo Kim 880d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 881d8408326SSeung-Woo Kim 882d8408326SSeung-Woo Kim clk_enable(res->mixer); 883d8408326SSeung-Woo Kim clk_enable(res->vp); 884d8408326SSeung-Woo Kim clk_enable(res->sclk_mixer); 885d8408326SSeung-Woo Kim 886d8408326SSeung-Woo Kim mixer_win_reset(ctx); 887d8408326SSeung-Woo Kim } 888d8408326SSeung-Woo Kim 889d8408326SSeung-Woo Kim static void mixer_resource_poweroff(struct mixer_context *ctx) 890d8408326SSeung-Woo Kim { 891d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 892d8408326SSeung-Woo Kim 893d8408326SSeung-Woo Kim DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); 894d8408326SSeung-Woo Kim 895d8408326SSeung-Woo Kim clk_disable(res->mixer); 896d8408326SSeung-Woo Kim clk_disable(res->vp); 897d8408326SSeung-Woo Kim clk_disable(res->sclk_mixer); 898d8408326SSeung-Woo Kim } 899d8408326SSeung-Woo Kim 900d8408326SSeung-Woo Kim static int mixer_runtime_resume(struct device *dev) 901d8408326SSeung-Woo Kim { 902d8408326SSeung-Woo Kim struct exynos_drm_hdmi_context *ctx = get_mixer_context(dev); 903d8408326SSeung-Woo Kim 904d8408326SSeung-Woo Kim DRM_DEBUG_KMS("resume - start\n"); 905d8408326SSeung-Woo Kim 906d8408326SSeung-Woo Kim mixer_resource_poweron((struct mixer_context *)ctx->ctx); 907d8408326SSeung-Woo Kim 908d8408326SSeung-Woo Kim return 0; 909d8408326SSeung-Woo Kim } 910d8408326SSeung-Woo Kim 911d8408326SSeung-Woo Kim static int mixer_runtime_suspend(struct device *dev) 912d8408326SSeung-Woo Kim { 913d8408326SSeung-Woo Kim struct exynos_drm_hdmi_context *ctx = get_mixer_context(dev); 914d8408326SSeung-Woo Kim 915d8408326SSeung-Woo Kim DRM_DEBUG_KMS("suspend - start\n"); 916d8408326SSeung-Woo Kim 917d8408326SSeung-Woo Kim mixer_resource_poweroff((struct mixer_context *)ctx->ctx); 918d8408326SSeung-Woo Kim 919d8408326SSeung-Woo Kim return 0; 920d8408326SSeung-Woo Kim } 921d8408326SSeung-Woo Kim 922d8408326SSeung-Woo Kim static const struct dev_pm_ops mixer_pm_ops = { 923d8408326SSeung-Woo Kim .runtime_suspend = mixer_runtime_suspend, 924d8408326SSeung-Woo Kim .runtime_resume = mixer_runtime_resume, 925d8408326SSeung-Woo Kim }; 926d8408326SSeung-Woo Kim 927d8408326SSeung-Woo Kim static int __devinit mixer_resources_init(struct exynos_drm_hdmi_context *ctx, 928d8408326SSeung-Woo Kim struct platform_device *pdev) 929d8408326SSeung-Woo Kim { 930d8408326SSeung-Woo Kim struct mixer_context *mixer_ctx = 931d8408326SSeung-Woo Kim (struct mixer_context *)ctx->ctx; 932d8408326SSeung-Woo Kim struct device *dev = &pdev->dev; 933d8408326SSeung-Woo Kim struct mixer_resources *mixer_res = &mixer_ctx->mixer_res; 934d8408326SSeung-Woo Kim struct resource *res; 935d8408326SSeung-Woo Kim int ret; 936d8408326SSeung-Woo Kim 937d8408326SSeung-Woo Kim mixer_res->dev = dev; 938d8408326SSeung-Woo Kim spin_lock_init(&mixer_res->reg_slock); 939d8408326SSeung-Woo Kim 940d8408326SSeung-Woo Kim mixer_res->mixer = clk_get(dev, "mixer"); 941d8408326SSeung-Woo Kim if (IS_ERR_OR_NULL(mixer_res->mixer)) { 942d8408326SSeung-Woo Kim dev_err(dev, "failed to get clock 'mixer'\n"); 943d8408326SSeung-Woo Kim ret = -ENODEV; 944d8408326SSeung-Woo Kim goto fail; 945d8408326SSeung-Woo Kim } 946d8408326SSeung-Woo Kim mixer_res->vp = clk_get(dev, "vp"); 947d8408326SSeung-Woo Kim if (IS_ERR_OR_NULL(mixer_res->vp)) { 948d8408326SSeung-Woo Kim dev_err(dev, "failed to get clock 'vp'\n"); 949d8408326SSeung-Woo Kim ret = -ENODEV; 950d8408326SSeung-Woo Kim goto fail; 951d8408326SSeung-Woo Kim } 952d8408326SSeung-Woo Kim mixer_res->sclk_mixer = clk_get(dev, "sclk_mixer"); 953d8408326SSeung-Woo Kim if (IS_ERR_OR_NULL(mixer_res->sclk_mixer)) { 954d8408326SSeung-Woo Kim dev_err(dev, "failed to get clock 'sclk_mixer'\n"); 955d8408326SSeung-Woo Kim ret = -ENODEV; 956d8408326SSeung-Woo Kim goto fail; 957d8408326SSeung-Woo Kim } 958d8408326SSeung-Woo Kim mixer_res->sclk_hdmi = clk_get(dev, "sclk_hdmi"); 959d8408326SSeung-Woo Kim if (IS_ERR_OR_NULL(mixer_res->sclk_hdmi)) { 960d8408326SSeung-Woo Kim dev_err(dev, "failed to get clock 'sclk_hdmi'\n"); 961d8408326SSeung-Woo Kim ret = -ENODEV; 962d8408326SSeung-Woo Kim goto fail; 963d8408326SSeung-Woo Kim } 964d8408326SSeung-Woo Kim mixer_res->sclk_dac = clk_get(dev, "sclk_dac"); 965d8408326SSeung-Woo Kim if (IS_ERR_OR_NULL(mixer_res->sclk_dac)) { 966d8408326SSeung-Woo Kim dev_err(dev, "failed to get clock 'sclk_dac'\n"); 967d8408326SSeung-Woo Kim ret = -ENODEV; 968d8408326SSeung-Woo Kim goto fail; 969d8408326SSeung-Woo Kim } 970d8408326SSeung-Woo Kim res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mxr"); 971d8408326SSeung-Woo Kim if (res == NULL) { 972d8408326SSeung-Woo Kim dev_err(dev, "get memory resource failed.\n"); 973d8408326SSeung-Woo Kim ret = -ENXIO; 974d8408326SSeung-Woo Kim goto fail; 975d8408326SSeung-Woo Kim } 976d8408326SSeung-Woo Kim 977d8408326SSeung-Woo Kim clk_set_parent(mixer_res->sclk_mixer, mixer_res->sclk_hdmi); 978d8408326SSeung-Woo Kim 979d8408326SSeung-Woo Kim mixer_res->mixer_regs = ioremap(res->start, resource_size(res)); 980d8408326SSeung-Woo Kim if (mixer_res->mixer_regs == NULL) { 981d8408326SSeung-Woo Kim dev_err(dev, "register mapping failed.\n"); 982d8408326SSeung-Woo Kim ret = -ENXIO; 983d8408326SSeung-Woo Kim goto fail; 984d8408326SSeung-Woo Kim } 985d8408326SSeung-Woo Kim 986d8408326SSeung-Woo Kim res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vp"); 987d8408326SSeung-Woo Kim if (res == NULL) { 988d8408326SSeung-Woo Kim dev_err(dev, "get memory resource failed.\n"); 989d8408326SSeung-Woo Kim ret = -ENXIO; 990d8408326SSeung-Woo Kim goto fail_mixer_regs; 991d8408326SSeung-Woo Kim } 992d8408326SSeung-Woo Kim 993d8408326SSeung-Woo Kim mixer_res->vp_regs = ioremap(res->start, resource_size(res)); 994d8408326SSeung-Woo Kim if (mixer_res->vp_regs == NULL) { 995d8408326SSeung-Woo Kim dev_err(dev, "register mapping failed.\n"); 996d8408326SSeung-Woo Kim ret = -ENXIO; 997d8408326SSeung-Woo Kim goto fail_mixer_regs; 998d8408326SSeung-Woo Kim } 999d8408326SSeung-Woo Kim 1000d8408326SSeung-Woo Kim res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "irq"); 1001d8408326SSeung-Woo Kim if (res == NULL) { 1002d8408326SSeung-Woo Kim dev_err(dev, "get interrupt resource failed.\n"); 1003d8408326SSeung-Woo Kim ret = -ENXIO; 1004d8408326SSeung-Woo Kim goto fail_vp_regs; 1005d8408326SSeung-Woo Kim } 1006d8408326SSeung-Woo Kim 1007d8408326SSeung-Woo Kim ret = request_irq(res->start, mixer_irq_handler, 0, "drm_mixer", ctx); 1008d8408326SSeung-Woo Kim if (ret) { 1009d8408326SSeung-Woo Kim dev_err(dev, "request interrupt failed.\n"); 1010d8408326SSeung-Woo Kim goto fail_vp_regs; 1011d8408326SSeung-Woo Kim } 1012d8408326SSeung-Woo Kim mixer_res->irq = res->start; 1013d8408326SSeung-Woo Kim 1014d8408326SSeung-Woo Kim return 0; 1015d8408326SSeung-Woo Kim 1016d8408326SSeung-Woo Kim fail_vp_regs: 1017d8408326SSeung-Woo Kim iounmap(mixer_res->vp_regs); 1018d8408326SSeung-Woo Kim 1019d8408326SSeung-Woo Kim fail_mixer_regs: 1020d8408326SSeung-Woo Kim iounmap(mixer_res->mixer_regs); 1021d8408326SSeung-Woo Kim 1022d8408326SSeung-Woo Kim fail: 1023d8408326SSeung-Woo Kim if (!IS_ERR_OR_NULL(mixer_res->sclk_dac)) 1024d8408326SSeung-Woo Kim clk_put(mixer_res->sclk_dac); 1025d8408326SSeung-Woo Kim if (!IS_ERR_OR_NULL(mixer_res->sclk_hdmi)) 1026d8408326SSeung-Woo Kim clk_put(mixer_res->sclk_hdmi); 1027d8408326SSeung-Woo Kim if (!IS_ERR_OR_NULL(mixer_res->sclk_mixer)) 1028d8408326SSeung-Woo Kim clk_put(mixer_res->sclk_mixer); 1029d8408326SSeung-Woo Kim if (!IS_ERR_OR_NULL(mixer_res->vp)) 1030d8408326SSeung-Woo Kim clk_put(mixer_res->vp); 1031d8408326SSeung-Woo Kim if (!IS_ERR_OR_NULL(mixer_res->mixer)) 1032d8408326SSeung-Woo Kim clk_put(mixer_res->mixer); 1033d8408326SSeung-Woo Kim mixer_res->dev = NULL; 1034d8408326SSeung-Woo Kim return ret; 1035d8408326SSeung-Woo Kim } 1036d8408326SSeung-Woo Kim 1037d8408326SSeung-Woo Kim static void mixer_resources_cleanup(struct mixer_context *ctx) 1038d8408326SSeung-Woo Kim { 1039d8408326SSeung-Woo Kim struct mixer_resources *res = &ctx->mixer_res; 1040d8408326SSeung-Woo Kim 1041d8408326SSeung-Woo Kim disable_irq(res->irq); 1042d8408326SSeung-Woo Kim free_irq(res->irq, ctx); 1043d8408326SSeung-Woo Kim 1044d8408326SSeung-Woo Kim iounmap(res->vp_regs); 1045d8408326SSeung-Woo Kim iounmap(res->mixer_regs); 1046d8408326SSeung-Woo Kim } 1047d8408326SSeung-Woo Kim 1048d8408326SSeung-Woo Kim static int __devinit mixer_probe(struct platform_device *pdev) 1049d8408326SSeung-Woo Kim { 1050d8408326SSeung-Woo Kim struct device *dev = &pdev->dev; 1051d8408326SSeung-Woo Kim struct exynos_drm_hdmi_context *drm_hdmi_ctx; 1052d8408326SSeung-Woo Kim struct mixer_context *ctx; 1053d8408326SSeung-Woo Kim int ret; 1054d8408326SSeung-Woo Kim 1055d8408326SSeung-Woo Kim dev_info(dev, "probe start\n"); 1056d8408326SSeung-Woo Kim 1057d8408326SSeung-Woo Kim drm_hdmi_ctx = kzalloc(sizeof(*drm_hdmi_ctx), GFP_KERNEL); 1058d8408326SSeung-Woo Kim if (!drm_hdmi_ctx) { 1059d8408326SSeung-Woo Kim DRM_ERROR("failed to allocate common hdmi context.\n"); 1060d8408326SSeung-Woo Kim return -ENOMEM; 1061d8408326SSeung-Woo Kim } 1062d8408326SSeung-Woo Kim 1063d8408326SSeung-Woo Kim ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 1064d8408326SSeung-Woo Kim if (!ctx) { 1065d8408326SSeung-Woo Kim DRM_ERROR("failed to alloc mixer context.\n"); 1066d8408326SSeung-Woo Kim kfree(drm_hdmi_ctx); 1067d8408326SSeung-Woo Kim return -ENOMEM; 1068d8408326SSeung-Woo Kim } 1069d8408326SSeung-Woo Kim 1070d8408326SSeung-Woo Kim drm_hdmi_ctx->ctx = (void *)ctx; 1071d8408326SSeung-Woo Kim 1072d8408326SSeung-Woo Kim platform_set_drvdata(pdev, drm_hdmi_ctx); 1073d8408326SSeung-Woo Kim 1074d8408326SSeung-Woo Kim /* acquire resources: regs, irqs, clocks */ 1075d8408326SSeung-Woo Kim ret = mixer_resources_init(drm_hdmi_ctx, pdev); 1076d8408326SSeung-Woo Kim if (ret) 1077d8408326SSeung-Woo Kim goto fail; 1078d8408326SSeung-Woo Kim 1079d8408326SSeung-Woo Kim /* register specific callback point to common hdmi. */ 1080d8408326SSeung-Woo Kim exynos_drm_overlay_ops_register(&overlay_ops); 1081d8408326SSeung-Woo Kim 1082d8408326SSeung-Woo Kim mixer_resource_poweron(ctx); 1083d8408326SSeung-Woo Kim 1084d8408326SSeung-Woo Kim return 0; 1085d8408326SSeung-Woo Kim 1086d8408326SSeung-Woo Kim 1087d8408326SSeung-Woo Kim fail: 1088d8408326SSeung-Woo Kim dev_info(dev, "probe failed\n"); 1089d8408326SSeung-Woo Kim return ret; 1090d8408326SSeung-Woo Kim } 1091d8408326SSeung-Woo Kim 1092d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev) 1093d8408326SSeung-Woo Kim { 1094d8408326SSeung-Woo Kim struct device *dev = &pdev->dev; 1095d8408326SSeung-Woo Kim struct exynos_drm_hdmi_context *drm_hdmi_ctx = 1096d8408326SSeung-Woo Kim platform_get_drvdata(pdev); 1097d8408326SSeung-Woo Kim struct mixer_context *ctx = (struct mixer_context *)drm_hdmi_ctx->ctx; 1098d8408326SSeung-Woo Kim 10991109bf8bSMasanari Iida dev_info(dev, "remove successful\n"); 1100d8408326SSeung-Woo Kim 1101d8408326SSeung-Woo Kim mixer_resource_poweroff(ctx); 1102d8408326SSeung-Woo Kim mixer_resources_cleanup(ctx); 1103d8408326SSeung-Woo Kim 1104d8408326SSeung-Woo Kim return 0; 1105d8408326SSeung-Woo Kim } 1106d8408326SSeung-Woo Kim 1107d8408326SSeung-Woo Kim struct platform_driver mixer_driver = { 1108d8408326SSeung-Woo Kim .driver = { 1109d8408326SSeung-Woo Kim .name = "s5p-mixer", 1110d8408326SSeung-Woo Kim .owner = THIS_MODULE, 1111d8408326SSeung-Woo Kim .pm = &mixer_pm_ops, 1112d8408326SSeung-Woo Kim }, 1113d8408326SSeung-Woo Kim .probe = mixer_probe, 1114d8408326SSeung-Woo Kim .remove = __devexit_p(mixer_remove), 1115d8408326SSeung-Woo Kim }; 1116d8408326SSeung-Woo Kim EXPORT_SYMBOL(mixer_driver); 1117d8408326SSeung-Woo Kim 1118d8408326SSeung-Woo Kim MODULE_AUTHOR("Seung-Woo Kim, <sw0312.kim@samsung.com>"); 1119d8408326SSeung-Woo Kim MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>"); 1120d8408326SSeung-Woo Kim MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); 1121d8408326SSeung-Woo Kim MODULE_DESCRIPTION("Samsung DRM HDMI mixer Driver"); 1122d8408326SSeung-Woo Kim MODULE_LICENSE("GPL"); 1123