xref: /linux/drivers/gpu/drm/exynos/exynos_mixer.c (revision 760285e7e7ab282c25b5e90816f7c47000557f4f)
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 
17*760285e7SDavid 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"
3922b21ae6SJoonyoung Shim 
40d8408326SSeung-Woo Kim #define get_mixer_context(dev)	platform_get_drvdata(to_platform_device(dev))
41d8408326SSeung-Woo Kim 
4222b21ae6SJoonyoung Shim struct hdmi_win_data {
4322b21ae6SJoonyoung Shim 	dma_addr_t		dma_addr;
4422b21ae6SJoonyoung Shim 	void __iomem		*vaddr;
4522b21ae6SJoonyoung Shim 	dma_addr_t		chroma_dma_addr;
4622b21ae6SJoonyoung Shim 	void __iomem		*chroma_vaddr;
4722b21ae6SJoonyoung Shim 	uint32_t		pixel_format;
4822b21ae6SJoonyoung Shim 	unsigned int		bpp;
4922b21ae6SJoonyoung Shim 	unsigned int		crtc_x;
5022b21ae6SJoonyoung Shim 	unsigned int		crtc_y;
5122b21ae6SJoonyoung Shim 	unsigned int		crtc_width;
5222b21ae6SJoonyoung Shim 	unsigned int		crtc_height;
5322b21ae6SJoonyoung Shim 	unsigned int		fb_x;
5422b21ae6SJoonyoung Shim 	unsigned int		fb_y;
5522b21ae6SJoonyoung Shim 	unsigned int		fb_width;
5622b21ae6SJoonyoung Shim 	unsigned int		fb_height;
578dcb96b6SSeung-Woo Kim 	unsigned int		src_width;
588dcb96b6SSeung-Woo Kim 	unsigned int		src_height;
5922b21ae6SJoonyoung Shim 	unsigned int		mode_width;
6022b21ae6SJoonyoung Shim 	unsigned int		mode_height;
6122b21ae6SJoonyoung Shim 	unsigned int		scan_flags;
6222b21ae6SJoonyoung Shim };
6322b21ae6SJoonyoung Shim 
6422b21ae6SJoonyoung Shim struct mixer_resources {
6522b21ae6SJoonyoung Shim 	int			irq;
6622b21ae6SJoonyoung Shim 	void __iomem		*mixer_regs;
6722b21ae6SJoonyoung Shim 	void __iomem		*vp_regs;
6822b21ae6SJoonyoung Shim 	spinlock_t		reg_slock;
6922b21ae6SJoonyoung Shim 	struct clk		*mixer;
7022b21ae6SJoonyoung Shim 	struct clk		*vp;
7122b21ae6SJoonyoung Shim 	struct clk		*sclk_mixer;
7222b21ae6SJoonyoung Shim 	struct clk		*sclk_hdmi;
7322b21ae6SJoonyoung Shim 	struct clk		*sclk_dac;
7422b21ae6SJoonyoung Shim };
7522b21ae6SJoonyoung Shim 
7622b21ae6SJoonyoung Shim struct mixer_context {
77cf8fc4f1SJoonyoung Shim 	struct device		*dev;
7822b21ae6SJoonyoung Shim 	int			pipe;
7922b21ae6SJoonyoung Shim 	bool			interlace;
80cf8fc4f1SJoonyoung Shim 	bool			powered;
81cf8fc4f1SJoonyoung Shim 	u32			int_en;
8222b21ae6SJoonyoung Shim 
83cf8fc4f1SJoonyoung Shim 	struct mutex		mixer_mutex;
8422b21ae6SJoonyoung Shim 	struct mixer_resources	mixer_res;
85a634dd54SJoonyoung Shim 	struct hdmi_win_data	win_data[MIXER_WIN_NR];
8622b21ae6SJoonyoung Shim };
8722b21ae6SJoonyoung Shim 
88d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = {
89d8408326SSeung-Woo Kim 	0,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
90d8408326SSeung-Woo Kim 	-1,	-1,	-1,	-1,	-1,	0,	0,	0,
91d8408326SSeung-Woo Kim 	0,	2,	4,	5,	6,	6,	6,	6,
92d8408326SSeung-Woo Kim 	6,	5,	5,	4,	3,	2,	1,	1,
93d8408326SSeung-Woo Kim 	0,	-6,	-12,	-16,	-18,	-20,	-21,	-20,
94d8408326SSeung-Woo Kim 	-20,	-18,	-16,	-13,	-10,	-8,	-5,	-2,
95d8408326SSeung-Woo Kim 	127,	126,	125,	121,	114,	107,	99,	89,
96d8408326SSeung-Woo Kim 	79,	68,	57,	46,	35,	25,	16,	8,
97d8408326SSeung-Woo Kim };
98d8408326SSeung-Woo Kim 
99d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = {
100d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
101d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
102d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
103d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
104d8408326SSeung-Woo Kim 	0,	5,	11,	19,	27,	37,	48,	59,
105d8408326SSeung-Woo Kim 	70,	81,	92,	102,	111,	118,	124,	126,
106d8408326SSeung-Woo Kim 	0,	0,	-1,	-1,	-2,	-3,	-4,	-5,
107d8408326SSeung-Woo Kim 	-6,	-7,	-8,	-8,	-8,	-8,	-6,	-3,
108d8408326SSeung-Woo Kim };
109d8408326SSeung-Woo Kim 
110d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = {
111d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
112d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
113d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
114d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
115d8408326SSeung-Woo Kim };
116d8408326SSeung-Woo Kim 
117d8408326SSeung-Woo Kim static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id)
118d8408326SSeung-Woo Kim {
119d8408326SSeung-Woo Kim 	return readl(res->vp_regs + reg_id);
120d8408326SSeung-Woo Kim }
121d8408326SSeung-Woo Kim 
122d8408326SSeung-Woo Kim static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id,
123d8408326SSeung-Woo Kim 				 u32 val)
124d8408326SSeung-Woo Kim {
125d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
126d8408326SSeung-Woo Kim }
127d8408326SSeung-Woo Kim 
128d8408326SSeung-Woo Kim static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id,
129d8408326SSeung-Woo Kim 				 u32 val, u32 mask)
130d8408326SSeung-Woo Kim {
131d8408326SSeung-Woo Kim 	u32 old = vp_reg_read(res, reg_id);
132d8408326SSeung-Woo Kim 
133d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
134d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
135d8408326SSeung-Woo Kim }
136d8408326SSeung-Woo Kim 
137d8408326SSeung-Woo Kim static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id)
138d8408326SSeung-Woo Kim {
139d8408326SSeung-Woo Kim 	return readl(res->mixer_regs + reg_id);
140d8408326SSeung-Woo Kim }
141d8408326SSeung-Woo Kim 
142d8408326SSeung-Woo Kim static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id,
143d8408326SSeung-Woo Kim 				 u32 val)
144d8408326SSeung-Woo Kim {
145d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
146d8408326SSeung-Woo Kim }
147d8408326SSeung-Woo Kim 
148d8408326SSeung-Woo Kim static inline void mixer_reg_writemask(struct mixer_resources *res,
149d8408326SSeung-Woo Kim 				 u32 reg_id, u32 val, u32 mask)
150d8408326SSeung-Woo Kim {
151d8408326SSeung-Woo Kim 	u32 old = mixer_reg_read(res, reg_id);
152d8408326SSeung-Woo Kim 
153d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
154d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
155d8408326SSeung-Woo Kim }
156d8408326SSeung-Woo Kim 
157d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx)
158d8408326SSeung-Woo Kim {
159d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
160d8408326SSeung-Woo Kim do { \
161d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
162d8408326SSeung-Woo Kim 		(u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \
163d8408326SSeung-Woo Kim } while (0)
164d8408326SSeung-Woo Kim 
165d8408326SSeung-Woo Kim 	DUMPREG(MXR_STATUS);
166d8408326SSeung-Woo Kim 	DUMPREG(MXR_CFG);
167d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_EN);
168d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_STATUS);
169d8408326SSeung-Woo Kim 
170d8408326SSeung-Woo Kim 	DUMPREG(MXR_LAYER_CFG);
171d8408326SSeung-Woo Kim 	DUMPREG(MXR_VIDEO_CFG);
172d8408326SSeung-Woo Kim 
173d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_CFG);
174d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_BASE);
175d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SPAN);
176d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_WH);
177d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SXY);
178d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_DXY);
179d8408326SSeung-Woo Kim 
180d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_CFG);
181d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_BASE);
182d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SPAN);
183d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_WH);
184d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SXY);
185d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_DXY);
186d8408326SSeung-Woo Kim #undef DUMPREG
187d8408326SSeung-Woo Kim }
188d8408326SSeung-Woo Kim 
189d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx)
190d8408326SSeung-Woo Kim {
191d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
192d8408326SSeung-Woo Kim do { \
193d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
194d8408326SSeung-Woo Kim 		(u32) readl(ctx->mixer_res.vp_regs + reg_id)); \
195d8408326SSeung-Woo Kim } while (0)
196d8408326SSeung-Woo Kim 
197d8408326SSeung-Woo Kim 	DUMPREG(VP_ENABLE);
198d8408326SSeung-Woo Kim 	DUMPREG(VP_SRESET);
199d8408326SSeung-Woo Kim 	DUMPREG(VP_SHADOW_UPDATE);
200d8408326SSeung-Woo Kim 	DUMPREG(VP_FIELD_ID);
201d8408326SSeung-Woo Kim 	DUMPREG(VP_MODE);
202d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_Y);
203d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_C);
204d8408326SSeung-Woo Kim 	DUMPREG(VP_PER_RATE_CTRL);
205d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_Y_PTR);
206d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_Y_PTR);
207d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_C_PTR);
208d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_C_PTR);
209d8408326SSeung-Woo Kim 	DUMPREG(VP_ENDIAN_MODE);
210d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_H_POSITION);
211d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_V_POSITION);
212d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_WIDTH);
213d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_HEIGHT);
214d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_H_POSITION);
215d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_V_POSITION);
216d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_WIDTH);
217d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_HEIGHT);
218d8408326SSeung-Woo Kim 	DUMPREG(VP_H_RATIO);
219d8408326SSeung-Woo Kim 	DUMPREG(VP_V_RATIO);
220d8408326SSeung-Woo Kim 
221d8408326SSeung-Woo Kim #undef DUMPREG
222d8408326SSeung-Woo Kim }
223d8408326SSeung-Woo Kim 
224d8408326SSeung-Woo Kim static inline void vp_filter_set(struct mixer_resources *res,
225d8408326SSeung-Woo Kim 		int reg_id, const u8 *data, unsigned int size)
226d8408326SSeung-Woo Kim {
227d8408326SSeung-Woo Kim 	/* assure 4-byte align */
228d8408326SSeung-Woo Kim 	BUG_ON(size & 3);
229d8408326SSeung-Woo Kim 	for (; size; size -= 4, reg_id += 4, data += 4) {
230d8408326SSeung-Woo Kim 		u32 val = (data[0] << 24) |  (data[1] << 16) |
231d8408326SSeung-Woo Kim 			(data[2] << 8) | data[3];
232d8408326SSeung-Woo Kim 		vp_reg_write(res, reg_id, val);
233d8408326SSeung-Woo Kim 	}
234d8408326SSeung-Woo Kim }
235d8408326SSeung-Woo Kim 
236d8408326SSeung-Woo Kim static void vp_default_filter(struct mixer_resources *res)
237d8408326SSeung-Woo Kim {
238d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY8_Y0_LL,
239e25e1b66SSachin Kamat 		filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
240d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_Y0_LL,
241e25e1b66SSachin Kamat 		filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
242d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_C0_LL,
243e25e1b66SSachin Kamat 		filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
244d8408326SSeung-Woo Kim }
245d8408326SSeung-Woo Kim 
246d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable)
247d8408326SSeung-Woo Kim {
248d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
249d8408326SSeung-Woo Kim 
250d8408326SSeung-Woo Kim 	/* block update on vsync */
251d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, enable ?
252d8408326SSeung-Woo Kim 			MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE);
253d8408326SSeung-Woo Kim 
254d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SHADOW_UPDATE, enable ?
255d8408326SSeung-Woo Kim 			VP_SHADOW_UPDATE_ENABLE : 0);
256d8408326SSeung-Woo Kim }
257d8408326SSeung-Woo Kim 
258d8408326SSeung-Woo Kim static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height)
259d8408326SSeung-Woo Kim {
260d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
261d8408326SSeung-Woo Kim 	u32 val;
262d8408326SSeung-Woo Kim 
263d8408326SSeung-Woo Kim 	/* choosing between interlace and progressive mode */
264d8408326SSeung-Woo Kim 	val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE :
265d8408326SSeung-Woo Kim 				MXR_CFG_SCAN_PROGRASSIVE);
266d8408326SSeung-Woo Kim 
267d8408326SSeung-Woo Kim 	/* choosing between porper HD and SD mode */
268d8408326SSeung-Woo Kim 	if (height == 480)
269d8408326SSeung-Woo Kim 		val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD;
270d8408326SSeung-Woo Kim 	else if (height == 576)
271d8408326SSeung-Woo Kim 		val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD;
272d8408326SSeung-Woo Kim 	else if (height == 720)
273d8408326SSeung-Woo Kim 		val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
274d8408326SSeung-Woo Kim 	else if (height == 1080)
275d8408326SSeung-Woo Kim 		val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD;
276d8408326SSeung-Woo Kim 	else
277d8408326SSeung-Woo Kim 		val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
278d8408326SSeung-Woo Kim 
279d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK);
280d8408326SSeung-Woo Kim }
281d8408326SSeung-Woo Kim 
282d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height)
283d8408326SSeung-Woo Kim {
284d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
285d8408326SSeung-Woo Kim 	u32 val;
286d8408326SSeung-Woo Kim 
287d8408326SSeung-Woo Kim 	if (height == 480) {
288d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
289d8408326SSeung-Woo Kim 	} else if (height == 576) {
290d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
291d8408326SSeung-Woo Kim 	} else if (height == 720) {
292d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
293d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
294d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
295d8408326SSeung-Woo Kim 				(32 << 0));
296d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
297d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
298d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
299d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
300d8408326SSeung-Woo Kim 	} else if (height == 1080) {
301d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
302d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
303d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
304d8408326SSeung-Woo Kim 				(32 << 0));
305d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
306d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
307d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
308d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
309d8408326SSeung-Woo Kim 	} else {
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 	}
319d8408326SSeung-Woo Kim 
320d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
321d8408326SSeung-Woo Kim }
322d8408326SSeung-Woo Kim 
323d8408326SSeung-Woo Kim static void mixer_cfg_layer(struct mixer_context *ctx, int win, bool enable)
324d8408326SSeung-Woo Kim {
325d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
326d8408326SSeung-Woo Kim 	u32 val = enable ? ~0 : 0;
327d8408326SSeung-Woo Kim 
328d8408326SSeung-Woo Kim 	switch (win) {
329d8408326SSeung-Woo Kim 	case 0:
330d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
331d8408326SSeung-Woo Kim 		break;
332d8408326SSeung-Woo Kim 	case 1:
333d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
334d8408326SSeung-Woo Kim 		break;
335d8408326SSeung-Woo Kim 	case 2:
336d8408326SSeung-Woo Kim 		vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON);
337d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_VP_ENABLE);
338d8408326SSeung-Woo Kim 		break;
339d8408326SSeung-Woo Kim 	}
340d8408326SSeung-Woo Kim }
341d8408326SSeung-Woo Kim 
342d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx)
343d8408326SSeung-Woo Kim {
344d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
345d8408326SSeung-Woo Kim 
346d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
347d8408326SSeung-Woo Kim 
348d8408326SSeung-Woo Kim 	mixer_regs_dump(ctx);
349d8408326SSeung-Woo Kim }
350d8408326SSeung-Woo Kim 
351d8408326SSeung-Woo Kim static void vp_video_buffer(struct mixer_context *ctx, int win)
352d8408326SSeung-Woo Kim {
353d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
354d8408326SSeung-Woo Kim 	unsigned long flags;
355d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
356d8408326SSeung-Woo Kim 	unsigned int x_ratio, y_ratio;
357d8408326SSeung-Woo Kim 	unsigned int buf_num;
358d8408326SSeung-Woo Kim 	dma_addr_t luma_addr[2], chroma_addr[2];
359d8408326SSeung-Woo Kim 	bool tiled_mode = false;
360d8408326SSeung-Woo Kim 	bool crcb_mode = false;
361d8408326SSeung-Woo Kim 	u32 val;
362d8408326SSeung-Woo Kim 
363d8408326SSeung-Woo Kim 	win_data = &ctx->win_data[win];
364d8408326SSeung-Woo Kim 
365d8408326SSeung-Woo Kim 	switch (win_data->pixel_format) {
366d8408326SSeung-Woo Kim 	case DRM_FORMAT_NV12MT:
367d8408326SSeung-Woo Kim 		tiled_mode = true;
368363b06aaSVille Syrjälä 	case DRM_FORMAT_NV12:
369d8408326SSeung-Woo Kim 		crcb_mode = false;
370d8408326SSeung-Woo Kim 		buf_num = 2;
371d8408326SSeung-Woo Kim 		break;
372d8408326SSeung-Woo Kim 	/* TODO: single buffer format NV12, NV21 */
373d8408326SSeung-Woo Kim 	default:
374d8408326SSeung-Woo Kim 		/* ignore pixel format at disable time */
375d8408326SSeung-Woo Kim 		if (!win_data->dma_addr)
376d8408326SSeung-Woo Kim 			break;
377d8408326SSeung-Woo Kim 
378d8408326SSeung-Woo Kim 		DRM_ERROR("pixel format for vp is wrong [%d].\n",
379d8408326SSeung-Woo Kim 				win_data->pixel_format);
380d8408326SSeung-Woo Kim 		return;
381d8408326SSeung-Woo Kim 	}
382d8408326SSeung-Woo Kim 
383d8408326SSeung-Woo Kim 	/* scaling feature: (src << 16) / dst */
3848dcb96b6SSeung-Woo Kim 	x_ratio = (win_data->src_width << 16) / win_data->crtc_width;
3858dcb96b6SSeung-Woo Kim 	y_ratio = (win_data->src_height << 16) / win_data->crtc_height;
386d8408326SSeung-Woo Kim 
387d8408326SSeung-Woo Kim 	if (buf_num == 2) {
388d8408326SSeung-Woo Kim 		luma_addr[0] = win_data->dma_addr;
389d8408326SSeung-Woo Kim 		chroma_addr[0] = win_data->chroma_dma_addr;
390d8408326SSeung-Woo Kim 	} else {
391d8408326SSeung-Woo Kim 		luma_addr[0] = win_data->dma_addr;
392d8408326SSeung-Woo Kim 		chroma_addr[0] = win_data->dma_addr
3938dcb96b6SSeung-Woo Kim 			+ (win_data->fb_width * win_data->fb_height);
394d8408326SSeung-Woo Kim 	}
395d8408326SSeung-Woo Kim 
396d8408326SSeung-Woo Kim 	if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE) {
397d8408326SSeung-Woo Kim 		ctx->interlace = true;
398d8408326SSeung-Woo Kim 		if (tiled_mode) {
399d8408326SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + 0x40;
400d8408326SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + 0x40;
401d8408326SSeung-Woo Kim 		} else {
4028dcb96b6SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + win_data->fb_width;
4038dcb96b6SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + win_data->fb_width;
404d8408326SSeung-Woo Kim 		}
405d8408326SSeung-Woo Kim 	} else {
406d8408326SSeung-Woo Kim 		ctx->interlace = false;
407d8408326SSeung-Woo Kim 		luma_addr[1] = 0;
408d8408326SSeung-Woo Kim 		chroma_addr[1] = 0;
409d8408326SSeung-Woo Kim 	}
410d8408326SSeung-Woo Kim 
411d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
412d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
413d8408326SSeung-Woo Kim 
414d8408326SSeung-Woo Kim 	/* interlace or progressive scan mode */
415d8408326SSeung-Woo Kim 	val = (ctx->interlace ? ~0 : 0);
416d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP);
417d8408326SSeung-Woo Kim 
418d8408326SSeung-Woo Kim 	/* setup format */
419d8408326SSeung-Woo Kim 	val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12);
420d8408326SSeung-Woo Kim 	val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
421d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK);
422d8408326SSeung-Woo Kim 
423d8408326SSeung-Woo Kim 	/* setting size of input image */
4248dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(win_data->fb_width) |
4258dcb96b6SSeung-Woo Kim 		VP_IMG_VSIZE(win_data->fb_height));
426d8408326SSeung-Woo Kim 	/* chroma height has to reduced by 2 to avoid chroma distorions */
4278dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(win_data->fb_width) |
4288dcb96b6SSeung-Woo Kim 		VP_IMG_VSIZE(win_data->fb_height / 2));
429d8408326SSeung-Woo Kim 
4308dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_WIDTH, win_data->src_width);
4318dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_HEIGHT, win_data->src_height);
432d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_H_POSITION,
4338dcb96b6SSeung-Woo Kim 			VP_SRC_H_POSITION_VAL(win_data->fb_x));
4348dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_V_POSITION, win_data->fb_y);
435d8408326SSeung-Woo Kim 
4368dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_DST_WIDTH, win_data->crtc_width);
4378dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_DST_H_POSITION, win_data->crtc_x);
438d8408326SSeung-Woo Kim 	if (ctx->interlace) {
4398dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height / 2);
4408dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y / 2);
441d8408326SSeung-Woo Kim 	} else {
4428dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height);
4438dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y);
444d8408326SSeung-Woo Kim 	}
445d8408326SSeung-Woo Kim 
446d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_H_RATIO, x_ratio);
447d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_V_RATIO, y_ratio);
448d8408326SSeung-Woo Kim 
449d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
450d8408326SSeung-Woo Kim 
451d8408326SSeung-Woo Kim 	/* set buffer address to vp */
452d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]);
453d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]);
454d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]);
455d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]);
456d8408326SSeung-Woo Kim 
4578dcb96b6SSeung-Woo Kim 	mixer_cfg_scan(ctx, win_data->mode_height);
4588dcb96b6SSeung-Woo Kim 	mixer_cfg_rgb_fmt(ctx, win_data->mode_height);
459d8408326SSeung-Woo Kim 	mixer_cfg_layer(ctx, win, true);
460d8408326SSeung-Woo Kim 	mixer_run(ctx);
461d8408326SSeung-Woo Kim 
462d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
463d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
464d8408326SSeung-Woo Kim 
465d8408326SSeung-Woo Kim 	vp_regs_dump(ctx);
466d8408326SSeung-Woo Kim }
467d8408326SSeung-Woo Kim 
468d8408326SSeung-Woo Kim static void mixer_graph_buffer(struct mixer_context *ctx, int win)
469d8408326SSeung-Woo Kim {
470d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
471d8408326SSeung-Woo Kim 	unsigned long flags;
472d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
473d8408326SSeung-Woo Kim 	unsigned int x_ratio, y_ratio;
474d8408326SSeung-Woo Kim 	unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset;
475d8408326SSeung-Woo Kim 	dma_addr_t dma_addr;
476d8408326SSeung-Woo Kim 	unsigned int fmt;
477d8408326SSeung-Woo Kim 	u32 val;
478d8408326SSeung-Woo Kim 
479d8408326SSeung-Woo Kim 	win_data = &ctx->win_data[win];
480d8408326SSeung-Woo Kim 
481d8408326SSeung-Woo Kim 	#define RGB565 4
482d8408326SSeung-Woo Kim 	#define ARGB1555 5
483d8408326SSeung-Woo Kim 	#define ARGB4444 6
484d8408326SSeung-Woo Kim 	#define ARGB8888 7
485d8408326SSeung-Woo Kim 
486d8408326SSeung-Woo Kim 	switch (win_data->bpp) {
487d8408326SSeung-Woo Kim 	case 16:
488d8408326SSeung-Woo Kim 		fmt = ARGB4444;
489d8408326SSeung-Woo Kim 		break;
490d8408326SSeung-Woo Kim 	case 32:
491d8408326SSeung-Woo Kim 		fmt = ARGB8888;
492d8408326SSeung-Woo Kim 		break;
493d8408326SSeung-Woo Kim 	default:
494d8408326SSeung-Woo Kim 		fmt = ARGB8888;
495d8408326SSeung-Woo Kim 	}
496d8408326SSeung-Woo Kim 
497d8408326SSeung-Woo Kim 	/* 2x scaling feature */
498d8408326SSeung-Woo Kim 	x_ratio = 0;
499d8408326SSeung-Woo Kim 	y_ratio = 0;
500d8408326SSeung-Woo Kim 
501d8408326SSeung-Woo Kim 	dst_x_offset = win_data->crtc_x;
502d8408326SSeung-Woo Kim 	dst_y_offset = win_data->crtc_y;
503d8408326SSeung-Woo Kim 
504d8408326SSeung-Woo Kim 	/* converting dma address base and source offset */
5058dcb96b6SSeung-Woo Kim 	dma_addr = win_data->dma_addr
5068dcb96b6SSeung-Woo Kim 		+ (win_data->fb_x * win_data->bpp >> 3)
5078dcb96b6SSeung-Woo Kim 		+ (win_data->fb_y * win_data->fb_width * win_data->bpp >> 3);
508d8408326SSeung-Woo Kim 	src_x_offset = 0;
509d8408326SSeung-Woo Kim 	src_y_offset = 0;
510d8408326SSeung-Woo Kim 
511d8408326SSeung-Woo Kim 	if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE)
512d8408326SSeung-Woo Kim 		ctx->interlace = true;
513d8408326SSeung-Woo Kim 	else
514d8408326SSeung-Woo Kim 		ctx->interlace = false;
515d8408326SSeung-Woo Kim 
516d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
517d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
518d8408326SSeung-Woo Kim 
519d8408326SSeung-Woo Kim 	/* setup format */
520d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
521d8408326SSeung-Woo Kim 		MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
522d8408326SSeung-Woo Kim 
523d8408326SSeung-Woo Kim 	/* setup geometry */
5248dcb96b6SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_SPAN(win), win_data->fb_width);
525d8408326SSeung-Woo Kim 
5268dcb96b6SSeung-Woo Kim 	val  = MXR_GRP_WH_WIDTH(win_data->crtc_width);
5278dcb96b6SSeung-Woo Kim 	val |= MXR_GRP_WH_HEIGHT(win_data->crtc_height);
528d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_H_SCALE(x_ratio);
529d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_V_SCALE(y_ratio);
530d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_WH(win), val);
531d8408326SSeung-Woo Kim 
532d8408326SSeung-Woo Kim 	/* setup offsets in source image */
533d8408326SSeung-Woo Kim 	val  = MXR_GRP_SXY_SX(src_x_offset);
534d8408326SSeung-Woo Kim 	val |= MXR_GRP_SXY_SY(src_y_offset);
535d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val);
536d8408326SSeung-Woo Kim 
537d8408326SSeung-Woo Kim 	/* setup offsets in display image */
538d8408326SSeung-Woo Kim 	val  = MXR_GRP_DXY_DX(dst_x_offset);
539d8408326SSeung-Woo Kim 	val |= MXR_GRP_DXY_DY(dst_y_offset);
540d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val);
541d8408326SSeung-Woo Kim 
542d8408326SSeung-Woo Kim 	/* set buffer address to mixer */
543d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr);
544d8408326SSeung-Woo Kim 
5458dcb96b6SSeung-Woo Kim 	mixer_cfg_scan(ctx, win_data->mode_height);
5468dcb96b6SSeung-Woo Kim 	mixer_cfg_rgb_fmt(ctx, win_data->mode_height);
547d8408326SSeung-Woo Kim 	mixer_cfg_layer(ctx, win, true);
548d8408326SSeung-Woo Kim 	mixer_run(ctx);
549d8408326SSeung-Woo Kim 
550d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
551d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
552d8408326SSeung-Woo Kim }
553d8408326SSeung-Woo Kim 
554d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx)
555d8408326SSeung-Woo Kim {
556d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
557d8408326SSeung-Woo Kim 	int tries = 100;
558d8408326SSeung-Woo Kim 
559d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING);
560d8408326SSeung-Woo Kim 	for (tries = 100; tries; --tries) {
561d8408326SSeung-Woo Kim 		/* waiting until VP_SRESET_PROCESSING is 0 */
562d8408326SSeung-Woo Kim 		if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING)
563d8408326SSeung-Woo Kim 			break;
564d8408326SSeung-Woo Kim 		mdelay(10);
565d8408326SSeung-Woo Kim 	}
566d8408326SSeung-Woo Kim 	WARN(tries == 0, "failed to reset Video Processor\n");
567d8408326SSeung-Woo Kim }
568d8408326SSeung-Woo Kim 
569cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx)
570cf8fc4f1SJoonyoung Shim {
571cf8fc4f1SJoonyoung Shim 	struct mixer_resources *res = &ctx->mixer_res;
572cf8fc4f1SJoonyoung Shim 	unsigned long flags;
573cf8fc4f1SJoonyoung Shim 	u32 val; /* value stored to register */
574cf8fc4f1SJoonyoung Shim 
575cf8fc4f1SJoonyoung Shim 	spin_lock_irqsave(&res->reg_slock, flags);
576cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, false);
577cf8fc4f1SJoonyoung Shim 
578cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
579cf8fc4f1SJoonyoung Shim 
580cf8fc4f1SJoonyoung Shim 	/* set output in RGB888 mode */
581cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
582cf8fc4f1SJoonyoung Shim 
583cf8fc4f1SJoonyoung Shim 	/* 16 beat burst in DMA */
584cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST,
585cf8fc4f1SJoonyoung Shim 		MXR_STATUS_BURST_MASK);
586cf8fc4f1SJoonyoung Shim 
587cf8fc4f1SJoonyoung Shim 	/* setting default layer priority: layer1 > layer0 > video
588cf8fc4f1SJoonyoung Shim 	 * because typical usage scenario would be
589cf8fc4f1SJoonyoung Shim 	 * layer1 - OSD
590cf8fc4f1SJoonyoung Shim 	 * layer0 - framebuffer
591cf8fc4f1SJoonyoung Shim 	 * video - video overlay
592cf8fc4f1SJoonyoung Shim 	 */
593cf8fc4f1SJoonyoung Shim 	val = MXR_LAYER_CFG_GRP1_VAL(3);
594cf8fc4f1SJoonyoung Shim 	val |= MXR_LAYER_CFG_GRP0_VAL(2);
595cf8fc4f1SJoonyoung Shim 	val |= MXR_LAYER_CFG_VP_VAL(1);
596cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_LAYER_CFG, val);
597cf8fc4f1SJoonyoung Shim 
598cf8fc4f1SJoonyoung Shim 	/* setting background color */
599cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR0, 0x008080);
600cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR1, 0x008080);
601cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR2, 0x008080);
602cf8fc4f1SJoonyoung Shim 
603cf8fc4f1SJoonyoung Shim 	/* setting graphical layers */
604cf8fc4f1SJoonyoung Shim 	val  = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
605cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_WIN_BLEND_EN;
6065736603bSSeung-Woo Kim 	val |= MXR_GRP_CFG_BLEND_PRE_MUL;
6075736603bSSeung-Woo Kim 	val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
608cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_ALPHA_VAL(0xff); /* non-transparent alpha */
609cf8fc4f1SJoonyoung Shim 
610cf8fc4f1SJoonyoung Shim 	/* the same configuration for both layers */
611cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(0), val);
612cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(1), val);
613cf8fc4f1SJoonyoung Shim 
6145736603bSSeung-Woo Kim 	/* setting video layers */
6155736603bSSeung-Woo Kim 	val = MXR_GRP_CFG_ALPHA_VAL(0);
6165736603bSSeung-Woo Kim 	mixer_reg_write(res, MXR_VIDEO_CFG, val);
6175736603bSSeung-Woo Kim 
618cf8fc4f1SJoonyoung Shim 	/* configuration of Video Processor Registers */
619cf8fc4f1SJoonyoung Shim 	vp_win_reset(ctx);
620cf8fc4f1SJoonyoung Shim 	vp_default_filter(res);
621cf8fc4f1SJoonyoung Shim 
622cf8fc4f1SJoonyoung Shim 	/* disable all layers */
623cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
624cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
625cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
626cf8fc4f1SJoonyoung Shim 
627cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, true);
628cf8fc4f1SJoonyoung Shim 	spin_unlock_irqrestore(&res->reg_slock, flags);
629cf8fc4f1SJoonyoung Shim }
630cf8fc4f1SJoonyoung Shim 
631cf8fc4f1SJoonyoung Shim static void mixer_poweron(struct mixer_context *ctx)
632cf8fc4f1SJoonyoung Shim {
633cf8fc4f1SJoonyoung Shim 	struct mixer_resources *res = &ctx->mixer_res;
634cf8fc4f1SJoonyoung Shim 
635cf8fc4f1SJoonyoung Shim 	DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
636cf8fc4f1SJoonyoung Shim 
637cf8fc4f1SJoonyoung Shim 	mutex_lock(&ctx->mixer_mutex);
638cf8fc4f1SJoonyoung Shim 	if (ctx->powered) {
639cf8fc4f1SJoonyoung Shim 		mutex_unlock(&ctx->mixer_mutex);
640cf8fc4f1SJoonyoung Shim 		return;
641cf8fc4f1SJoonyoung Shim 	}
642cf8fc4f1SJoonyoung Shim 	ctx->powered = true;
643cf8fc4f1SJoonyoung Shim 	mutex_unlock(&ctx->mixer_mutex);
644cf8fc4f1SJoonyoung Shim 
645cf8fc4f1SJoonyoung Shim 	pm_runtime_get_sync(ctx->dev);
646cf8fc4f1SJoonyoung Shim 
647cf8fc4f1SJoonyoung Shim 	clk_enable(res->mixer);
648cf8fc4f1SJoonyoung Shim 	clk_enable(res->vp);
649cf8fc4f1SJoonyoung Shim 	clk_enable(res->sclk_mixer);
650cf8fc4f1SJoonyoung Shim 
651cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_INT_EN, ctx->int_en);
652cf8fc4f1SJoonyoung Shim 	mixer_win_reset(ctx);
653cf8fc4f1SJoonyoung Shim }
654cf8fc4f1SJoonyoung Shim 
655cf8fc4f1SJoonyoung Shim static void mixer_poweroff(struct mixer_context *ctx)
656cf8fc4f1SJoonyoung Shim {
657cf8fc4f1SJoonyoung Shim 	struct mixer_resources *res = &ctx->mixer_res;
658cf8fc4f1SJoonyoung Shim 
659cf8fc4f1SJoonyoung Shim 	DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
660cf8fc4f1SJoonyoung Shim 
661cf8fc4f1SJoonyoung Shim 	mutex_lock(&ctx->mixer_mutex);
662cf8fc4f1SJoonyoung Shim 	if (!ctx->powered)
663cf8fc4f1SJoonyoung Shim 		goto out;
664cf8fc4f1SJoonyoung Shim 	mutex_unlock(&ctx->mixer_mutex);
665cf8fc4f1SJoonyoung Shim 
666cf8fc4f1SJoonyoung Shim 	ctx->int_en = mixer_reg_read(res, MXR_INT_EN);
667cf8fc4f1SJoonyoung Shim 
668cf8fc4f1SJoonyoung Shim 	clk_disable(res->mixer);
669cf8fc4f1SJoonyoung Shim 	clk_disable(res->vp);
670cf8fc4f1SJoonyoung Shim 	clk_disable(res->sclk_mixer);
671cf8fc4f1SJoonyoung Shim 
672cf8fc4f1SJoonyoung Shim 	pm_runtime_put_sync(ctx->dev);
673cf8fc4f1SJoonyoung Shim 
674cf8fc4f1SJoonyoung Shim 	mutex_lock(&ctx->mixer_mutex);
675cf8fc4f1SJoonyoung Shim 	ctx->powered = false;
676cf8fc4f1SJoonyoung Shim 
677cf8fc4f1SJoonyoung Shim out:
678cf8fc4f1SJoonyoung Shim 	mutex_unlock(&ctx->mixer_mutex);
679cf8fc4f1SJoonyoung Shim }
680cf8fc4f1SJoonyoung Shim 
681d8408326SSeung-Woo Kim static int mixer_enable_vblank(void *ctx, int pipe)
682d8408326SSeung-Woo Kim {
683d8408326SSeung-Woo Kim 	struct mixer_context *mixer_ctx = ctx;
684d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
685d8408326SSeung-Woo Kim 
686d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
687d8408326SSeung-Woo Kim 
688d8408326SSeung-Woo Kim 	mixer_ctx->pipe = pipe;
689d8408326SSeung-Woo Kim 
690d8408326SSeung-Woo Kim 	/* enable vsync interrupt */
691d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_INT_EN, MXR_INT_EN_VSYNC,
692d8408326SSeung-Woo Kim 			MXR_INT_EN_VSYNC);
693d8408326SSeung-Woo Kim 
694d8408326SSeung-Woo Kim 	return 0;
695d8408326SSeung-Woo Kim }
696d8408326SSeung-Woo Kim 
697d8408326SSeung-Woo Kim static void mixer_disable_vblank(void *ctx)
698d8408326SSeung-Woo Kim {
699d8408326SSeung-Woo Kim 	struct mixer_context *mixer_ctx = ctx;
700d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
701d8408326SSeung-Woo Kim 
702d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
703d8408326SSeung-Woo Kim 
704d8408326SSeung-Woo Kim 	/* disable vsync interrupt */
705d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
706d8408326SSeung-Woo Kim }
707d8408326SSeung-Woo Kim 
708cf8fc4f1SJoonyoung Shim static void mixer_dpms(void *ctx, int mode)
709cf8fc4f1SJoonyoung Shim {
710cf8fc4f1SJoonyoung Shim 	struct mixer_context *mixer_ctx = ctx;
711cf8fc4f1SJoonyoung Shim 
712cf8fc4f1SJoonyoung Shim 	DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
713cf8fc4f1SJoonyoung Shim 
714cf8fc4f1SJoonyoung Shim 	switch (mode) {
715cf8fc4f1SJoonyoung Shim 	case DRM_MODE_DPMS_ON:
716cf8fc4f1SJoonyoung Shim 		mixer_poweron(mixer_ctx);
717cf8fc4f1SJoonyoung Shim 		break;
718cf8fc4f1SJoonyoung Shim 	case DRM_MODE_DPMS_STANDBY:
719cf8fc4f1SJoonyoung Shim 	case DRM_MODE_DPMS_SUSPEND:
720cf8fc4f1SJoonyoung Shim 	case DRM_MODE_DPMS_OFF:
721cf8fc4f1SJoonyoung Shim 		mixer_poweroff(mixer_ctx);
722cf8fc4f1SJoonyoung Shim 		break;
723cf8fc4f1SJoonyoung Shim 	default:
724cf8fc4f1SJoonyoung Shim 		DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode);
725cf8fc4f1SJoonyoung Shim 		break;
726cf8fc4f1SJoonyoung Shim 	}
727cf8fc4f1SJoonyoung Shim }
728cf8fc4f1SJoonyoung Shim 
729d8408326SSeung-Woo Kim static void mixer_win_mode_set(void *ctx,
730d8408326SSeung-Woo Kim 			      struct exynos_drm_overlay *overlay)
731d8408326SSeung-Woo Kim {
732d8408326SSeung-Woo Kim 	struct mixer_context *mixer_ctx = ctx;
733d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
734d8408326SSeung-Woo Kim 	int win;
735d8408326SSeung-Woo Kim 
736d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
737d8408326SSeung-Woo Kim 
738d8408326SSeung-Woo Kim 	if (!overlay) {
739d8408326SSeung-Woo Kim 		DRM_ERROR("overlay is NULL\n");
740d8408326SSeung-Woo Kim 		return;
741d8408326SSeung-Woo Kim 	}
742d8408326SSeung-Woo Kim 
743d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS("set [%d]x[%d] at (%d,%d) to [%d]x[%d] at (%d,%d)\n",
744d8408326SSeung-Woo Kim 				 overlay->fb_width, overlay->fb_height,
745d8408326SSeung-Woo Kim 				 overlay->fb_x, overlay->fb_y,
746d8408326SSeung-Woo Kim 				 overlay->crtc_width, overlay->crtc_height,
747d8408326SSeung-Woo Kim 				 overlay->crtc_x, overlay->crtc_y);
748d8408326SSeung-Woo Kim 
749d8408326SSeung-Woo Kim 	win = overlay->zpos;
750d8408326SSeung-Woo Kim 	if (win == DEFAULT_ZPOS)
751a2ee151bSJoonyoung Shim 		win = MIXER_DEFAULT_WIN;
752d8408326SSeung-Woo Kim 
753a634dd54SJoonyoung Shim 	if (win < 0 || win > MIXER_WIN_NR) {
754cf8fc4f1SJoonyoung Shim 		DRM_ERROR("mixer window[%d] is wrong\n", win);
755d8408326SSeung-Woo Kim 		return;
756d8408326SSeung-Woo Kim 	}
757d8408326SSeung-Woo Kim 
758d8408326SSeung-Woo Kim 	win_data = &mixer_ctx->win_data[win];
759d8408326SSeung-Woo Kim 
760d8408326SSeung-Woo Kim 	win_data->dma_addr = overlay->dma_addr[0];
761d8408326SSeung-Woo Kim 	win_data->vaddr = overlay->vaddr[0];
762d8408326SSeung-Woo Kim 	win_data->chroma_dma_addr = overlay->dma_addr[1];
763d8408326SSeung-Woo Kim 	win_data->chroma_vaddr = overlay->vaddr[1];
764d8408326SSeung-Woo Kim 	win_data->pixel_format = overlay->pixel_format;
765d8408326SSeung-Woo Kim 	win_data->bpp = overlay->bpp;
766d8408326SSeung-Woo Kim 
767d8408326SSeung-Woo Kim 	win_data->crtc_x = overlay->crtc_x;
768d8408326SSeung-Woo Kim 	win_data->crtc_y = overlay->crtc_y;
769d8408326SSeung-Woo Kim 	win_data->crtc_width = overlay->crtc_width;
770d8408326SSeung-Woo Kim 	win_data->crtc_height = overlay->crtc_height;
771d8408326SSeung-Woo Kim 
772d8408326SSeung-Woo Kim 	win_data->fb_x = overlay->fb_x;
773d8408326SSeung-Woo Kim 	win_data->fb_y = overlay->fb_y;
774d8408326SSeung-Woo Kim 	win_data->fb_width = overlay->fb_width;
775d8408326SSeung-Woo Kim 	win_data->fb_height = overlay->fb_height;
7768dcb96b6SSeung-Woo Kim 	win_data->src_width = overlay->src_width;
7778dcb96b6SSeung-Woo Kim 	win_data->src_height = overlay->src_height;
778d8408326SSeung-Woo Kim 
779d8408326SSeung-Woo Kim 	win_data->mode_width = overlay->mode_width;
780d8408326SSeung-Woo Kim 	win_data->mode_height = overlay->mode_height;
781d8408326SSeung-Woo Kim 
782d8408326SSeung-Woo Kim 	win_data->scan_flags = overlay->scan_flag;
783d8408326SSeung-Woo Kim }
784d8408326SSeung-Woo Kim 
785cf8fc4f1SJoonyoung Shim static void mixer_win_commit(void *ctx, int win)
786d8408326SSeung-Woo Kim {
787d8408326SSeung-Woo Kim 	struct mixer_context *mixer_ctx = ctx;
788d8408326SSeung-Woo Kim 
789d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS("[%d] %s, win: %d\n", __LINE__, __func__, win);
790d8408326SSeung-Woo Kim 
791d8408326SSeung-Woo Kim 	if (win > 1)
792d8408326SSeung-Woo Kim 		vp_video_buffer(mixer_ctx, win);
793d8408326SSeung-Woo Kim 	else
794d8408326SSeung-Woo Kim 		mixer_graph_buffer(mixer_ctx, win);
795d8408326SSeung-Woo Kim }
796d8408326SSeung-Woo Kim 
797cf8fc4f1SJoonyoung Shim static void mixer_win_disable(void *ctx, int win)
798d8408326SSeung-Woo Kim {
799d8408326SSeung-Woo Kim 	struct mixer_context *mixer_ctx = ctx;
800d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
801d8408326SSeung-Woo Kim 	unsigned long flags;
802d8408326SSeung-Woo Kim 
803d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS("[%d] %s, win: %d\n", __LINE__, __func__, win);
804d8408326SSeung-Woo Kim 
805d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
806d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, false);
807d8408326SSeung-Woo Kim 
808d8408326SSeung-Woo Kim 	mixer_cfg_layer(mixer_ctx, win, false);
809d8408326SSeung-Woo Kim 
810d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, true);
811d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
812d8408326SSeung-Woo Kim }
813d8408326SSeung-Woo Kim 
814578b6065SJoonyoung Shim static struct exynos_mixer_ops mixer_ops = {
815578b6065SJoonyoung Shim 	/* manager */
816d8408326SSeung-Woo Kim 	.enable_vblank		= mixer_enable_vblank,
817d8408326SSeung-Woo Kim 	.disable_vblank		= mixer_disable_vblank,
818cf8fc4f1SJoonyoung Shim 	.dpms			= mixer_dpms,
819578b6065SJoonyoung Shim 
820578b6065SJoonyoung Shim 	/* overlay */
821d8408326SSeung-Woo Kim 	.win_mode_set		= mixer_win_mode_set,
822d8408326SSeung-Woo Kim 	.win_commit		= mixer_win_commit,
823d8408326SSeung-Woo Kim 	.win_disable		= mixer_win_disable,
824d8408326SSeung-Woo Kim };
825d8408326SSeung-Woo Kim 
826d8408326SSeung-Woo Kim /* for pageflip event */
827d8408326SSeung-Woo Kim static void mixer_finish_pageflip(struct drm_device *drm_dev, int crtc)
828d8408326SSeung-Woo Kim {
829d8408326SSeung-Woo Kim 	struct exynos_drm_private *dev_priv = drm_dev->dev_private;
830d8408326SSeung-Woo Kim 	struct drm_pending_vblank_event *e, *t;
831d8408326SSeung-Woo Kim 	struct timeval now;
832d8408326SSeung-Woo Kim 	unsigned long flags;
833d8408326SSeung-Woo Kim 	bool is_checked = false;
834d8408326SSeung-Woo Kim 
835d8408326SSeung-Woo Kim 	spin_lock_irqsave(&drm_dev->event_lock, flags);
836d8408326SSeung-Woo Kim 
837d8408326SSeung-Woo Kim 	list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list,
838d8408326SSeung-Woo Kim 			base.link) {
839d8408326SSeung-Woo Kim 		/* if event's pipe isn't same as crtc then ignore it. */
840d8408326SSeung-Woo Kim 		if (crtc != e->pipe)
841d8408326SSeung-Woo Kim 			continue;
842d8408326SSeung-Woo Kim 
843d8408326SSeung-Woo Kim 		is_checked = true;
844d8408326SSeung-Woo Kim 		do_gettimeofday(&now);
845d8408326SSeung-Woo Kim 		e->event.sequence = 0;
846d8408326SSeung-Woo Kim 		e->event.tv_sec = now.tv_sec;
847d8408326SSeung-Woo Kim 		e->event.tv_usec = now.tv_usec;
848d8408326SSeung-Woo Kim 
849d8408326SSeung-Woo Kim 		list_move_tail(&e->base.link, &e->base.file_priv->event_list);
850d8408326SSeung-Woo Kim 		wake_up_interruptible(&e->base.file_priv->event_wait);
851d8408326SSeung-Woo Kim 	}
852d8408326SSeung-Woo Kim 
853d8408326SSeung-Woo Kim 	if (is_checked)
854c5614ae3SInki Dae 		/*
855c5614ae3SInki Dae 		 * call drm_vblank_put only in case that drm_vblank_get was
856c5614ae3SInki Dae 		 * called.
857c5614ae3SInki Dae 		 */
858c5614ae3SInki Dae 		if (atomic_read(&drm_dev->vblank_refcount[crtc]) > 0)
859d8408326SSeung-Woo Kim 			drm_vblank_put(drm_dev, crtc);
860d8408326SSeung-Woo Kim 
861d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&drm_dev->event_lock, flags);
862d8408326SSeung-Woo Kim }
863d8408326SSeung-Woo Kim 
864d8408326SSeung-Woo Kim static irqreturn_t mixer_irq_handler(int irq, void *arg)
865d8408326SSeung-Woo Kim {
866d8408326SSeung-Woo Kim 	struct exynos_drm_hdmi_context *drm_hdmi_ctx = arg;
867f9309d1bSJoonyoung Shim 	struct mixer_context *ctx = drm_hdmi_ctx->ctx;
868d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
8698379e482SSeung-Woo Kim 	u32 val, base, shadow;
870d8408326SSeung-Woo Kim 
871d8408326SSeung-Woo Kim 	spin_lock(&res->reg_slock);
872d8408326SSeung-Woo Kim 
873d8408326SSeung-Woo Kim 	/* read interrupt status for handling and clearing flags for VSYNC */
874d8408326SSeung-Woo Kim 	val = mixer_reg_read(res, MXR_INT_STATUS);
875d8408326SSeung-Woo Kim 
876d8408326SSeung-Woo Kim 	/* handling VSYNC */
877d8408326SSeung-Woo Kim 	if (val & MXR_INT_STATUS_VSYNC) {
878d8408326SSeung-Woo Kim 		/* interlace scan need to check shadow register */
879d8408326SSeung-Woo Kim 		if (ctx->interlace) {
8808379e482SSeung-Woo Kim 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0));
8818379e482SSeung-Woo Kim 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0));
8828379e482SSeung-Woo Kim 			if (base != shadow)
883d8408326SSeung-Woo Kim 				goto out;
884d8408326SSeung-Woo Kim 
8858379e482SSeung-Woo Kim 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1));
8868379e482SSeung-Woo Kim 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1));
8878379e482SSeung-Woo Kim 			if (base != shadow)
888d8408326SSeung-Woo Kim 				goto out;
889d8408326SSeung-Woo Kim 		}
890d8408326SSeung-Woo Kim 
891d8408326SSeung-Woo Kim 		drm_handle_vblank(drm_hdmi_ctx->drm_dev, ctx->pipe);
892d8408326SSeung-Woo Kim 		mixer_finish_pageflip(drm_hdmi_ctx->drm_dev, ctx->pipe);
893d8408326SSeung-Woo Kim 	}
894d8408326SSeung-Woo Kim 
895d8408326SSeung-Woo Kim out:
896d8408326SSeung-Woo Kim 	/* clear interrupts */
897d8408326SSeung-Woo Kim 	if (~val & MXR_INT_EN_VSYNC) {
898d8408326SSeung-Woo Kim 		/* vsync interrupt use different bit for read and clear */
899d8408326SSeung-Woo Kim 		val &= ~MXR_INT_EN_VSYNC;
900d8408326SSeung-Woo Kim 		val |= MXR_INT_CLEAR_VSYNC;
901d8408326SSeung-Woo Kim 	}
902d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_INT_STATUS, val);
903d8408326SSeung-Woo Kim 
904d8408326SSeung-Woo Kim 	spin_unlock(&res->reg_slock);
905d8408326SSeung-Woo Kim 
906d8408326SSeung-Woo Kim 	return IRQ_HANDLED;
907d8408326SSeung-Woo Kim }
908d8408326SSeung-Woo Kim 
909d8408326SSeung-Woo Kim static int __devinit mixer_resources_init(struct exynos_drm_hdmi_context *ctx,
910d8408326SSeung-Woo Kim 				 struct platform_device *pdev)
911d8408326SSeung-Woo Kim {
912f9309d1bSJoonyoung Shim 	struct mixer_context *mixer_ctx = ctx->ctx;
913d8408326SSeung-Woo Kim 	struct device *dev = &pdev->dev;
914d8408326SSeung-Woo Kim 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
915d8408326SSeung-Woo Kim 	struct resource *res;
916d8408326SSeung-Woo Kim 	int ret;
917d8408326SSeung-Woo Kim 
918d8408326SSeung-Woo Kim 	spin_lock_init(&mixer_res->reg_slock);
919d8408326SSeung-Woo Kim 
920d8408326SSeung-Woo Kim 	mixer_res->mixer = clk_get(dev, "mixer");
921d8408326SSeung-Woo Kim 	if (IS_ERR_OR_NULL(mixer_res->mixer)) {
922d8408326SSeung-Woo Kim 		dev_err(dev, "failed to get clock 'mixer'\n");
923d8408326SSeung-Woo Kim 		ret = -ENODEV;
924d8408326SSeung-Woo Kim 		goto fail;
925d8408326SSeung-Woo Kim 	}
926d8408326SSeung-Woo Kim 	mixer_res->vp = clk_get(dev, "vp");
927d8408326SSeung-Woo Kim 	if (IS_ERR_OR_NULL(mixer_res->vp)) {
928d8408326SSeung-Woo Kim 		dev_err(dev, "failed to get clock 'vp'\n");
929d8408326SSeung-Woo Kim 		ret = -ENODEV;
930d8408326SSeung-Woo Kim 		goto fail;
931d8408326SSeung-Woo Kim 	}
932d8408326SSeung-Woo Kim 	mixer_res->sclk_mixer = clk_get(dev, "sclk_mixer");
933d8408326SSeung-Woo Kim 	if (IS_ERR_OR_NULL(mixer_res->sclk_mixer)) {
934d8408326SSeung-Woo Kim 		dev_err(dev, "failed to get clock 'sclk_mixer'\n");
935d8408326SSeung-Woo Kim 		ret = -ENODEV;
936d8408326SSeung-Woo Kim 		goto fail;
937d8408326SSeung-Woo Kim 	}
938d8408326SSeung-Woo Kim 	mixer_res->sclk_hdmi = clk_get(dev, "sclk_hdmi");
939d8408326SSeung-Woo Kim 	if (IS_ERR_OR_NULL(mixer_res->sclk_hdmi)) {
940d8408326SSeung-Woo Kim 		dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
941d8408326SSeung-Woo Kim 		ret = -ENODEV;
942d8408326SSeung-Woo Kim 		goto fail;
943d8408326SSeung-Woo Kim 	}
944d8408326SSeung-Woo Kim 	mixer_res->sclk_dac = clk_get(dev, "sclk_dac");
945d8408326SSeung-Woo Kim 	if (IS_ERR_OR_NULL(mixer_res->sclk_dac)) {
946d8408326SSeung-Woo Kim 		dev_err(dev, "failed to get clock 'sclk_dac'\n");
947d8408326SSeung-Woo Kim 		ret = -ENODEV;
948d8408326SSeung-Woo Kim 		goto fail;
949d8408326SSeung-Woo Kim 	}
950d8408326SSeung-Woo Kim 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mxr");
951d8408326SSeung-Woo Kim 	if (res == NULL) {
952d8408326SSeung-Woo Kim 		dev_err(dev, "get memory resource failed.\n");
953d8408326SSeung-Woo Kim 		ret = -ENXIO;
954d8408326SSeung-Woo Kim 		goto fail;
955d8408326SSeung-Woo Kim 	}
956d8408326SSeung-Woo Kim 
957d8408326SSeung-Woo Kim 	clk_set_parent(mixer_res->sclk_mixer, mixer_res->sclk_hdmi);
958d8408326SSeung-Woo Kim 
9599416dfa7SSachin Kamat 	mixer_res->mixer_regs = devm_ioremap(&pdev->dev, res->start,
9609416dfa7SSachin Kamat 							resource_size(res));
961d8408326SSeung-Woo Kim 	if (mixer_res->mixer_regs == NULL) {
962d8408326SSeung-Woo Kim 		dev_err(dev, "register mapping failed.\n");
963d8408326SSeung-Woo Kim 		ret = -ENXIO;
964d8408326SSeung-Woo Kim 		goto fail;
965d8408326SSeung-Woo Kim 	}
966d8408326SSeung-Woo Kim 
967d8408326SSeung-Woo Kim 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vp");
968d8408326SSeung-Woo Kim 	if (res == NULL) {
969d8408326SSeung-Woo Kim 		dev_err(dev, "get memory resource failed.\n");
970d8408326SSeung-Woo Kim 		ret = -ENXIO;
9719416dfa7SSachin Kamat 		goto fail;
972d8408326SSeung-Woo Kim 	}
973d8408326SSeung-Woo Kim 
9749416dfa7SSachin Kamat 	mixer_res->vp_regs = devm_ioremap(&pdev->dev, res->start,
9759416dfa7SSachin Kamat 							resource_size(res));
976d8408326SSeung-Woo Kim 	if (mixer_res->vp_regs == NULL) {
977d8408326SSeung-Woo Kim 		dev_err(dev, "register mapping failed.\n");
978d8408326SSeung-Woo Kim 		ret = -ENXIO;
9799416dfa7SSachin Kamat 		goto fail;
980d8408326SSeung-Woo Kim 	}
981d8408326SSeung-Woo Kim 
982d8408326SSeung-Woo Kim 	res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "irq");
983d8408326SSeung-Woo Kim 	if (res == NULL) {
984d8408326SSeung-Woo Kim 		dev_err(dev, "get interrupt resource failed.\n");
985d8408326SSeung-Woo Kim 		ret = -ENXIO;
9869416dfa7SSachin Kamat 		goto fail;
987d8408326SSeung-Woo Kim 	}
988d8408326SSeung-Woo Kim 
9899416dfa7SSachin Kamat 	ret = devm_request_irq(&pdev->dev, res->start, mixer_irq_handler,
9909416dfa7SSachin Kamat 							0, "drm_mixer", ctx);
991d8408326SSeung-Woo Kim 	if (ret) {
992d8408326SSeung-Woo Kim 		dev_err(dev, "request interrupt failed.\n");
9939416dfa7SSachin Kamat 		goto fail;
994d8408326SSeung-Woo Kim 	}
995d8408326SSeung-Woo Kim 	mixer_res->irq = res->start;
996d8408326SSeung-Woo Kim 
997d8408326SSeung-Woo Kim 	return 0;
998d8408326SSeung-Woo Kim 
999d8408326SSeung-Woo Kim fail:
1000d8408326SSeung-Woo Kim 	if (!IS_ERR_OR_NULL(mixer_res->sclk_dac))
1001d8408326SSeung-Woo Kim 		clk_put(mixer_res->sclk_dac);
1002d8408326SSeung-Woo Kim 	if (!IS_ERR_OR_NULL(mixer_res->sclk_hdmi))
1003d8408326SSeung-Woo Kim 		clk_put(mixer_res->sclk_hdmi);
1004d8408326SSeung-Woo Kim 	if (!IS_ERR_OR_NULL(mixer_res->sclk_mixer))
1005d8408326SSeung-Woo Kim 		clk_put(mixer_res->sclk_mixer);
1006d8408326SSeung-Woo Kim 	if (!IS_ERR_OR_NULL(mixer_res->vp))
1007d8408326SSeung-Woo Kim 		clk_put(mixer_res->vp);
1008d8408326SSeung-Woo Kim 	if (!IS_ERR_OR_NULL(mixer_res->mixer))
1009d8408326SSeung-Woo Kim 		clk_put(mixer_res->mixer);
1010d8408326SSeung-Woo Kim 	return ret;
1011d8408326SSeung-Woo Kim }
1012d8408326SSeung-Woo Kim 
1013d8408326SSeung-Woo Kim static int __devinit mixer_probe(struct platform_device *pdev)
1014d8408326SSeung-Woo Kim {
1015d8408326SSeung-Woo Kim 	struct device *dev = &pdev->dev;
1016d8408326SSeung-Woo Kim 	struct exynos_drm_hdmi_context *drm_hdmi_ctx;
1017d8408326SSeung-Woo Kim 	struct mixer_context *ctx;
1018d8408326SSeung-Woo Kim 	int ret;
1019d8408326SSeung-Woo Kim 
1020d8408326SSeung-Woo Kim 	dev_info(dev, "probe start\n");
1021d8408326SSeung-Woo Kim 
10229416dfa7SSachin Kamat 	drm_hdmi_ctx = devm_kzalloc(&pdev->dev, sizeof(*drm_hdmi_ctx),
10239416dfa7SSachin Kamat 								GFP_KERNEL);
1024d8408326SSeung-Woo Kim 	if (!drm_hdmi_ctx) {
1025d8408326SSeung-Woo Kim 		DRM_ERROR("failed to allocate common hdmi context.\n");
1026d8408326SSeung-Woo Kim 		return -ENOMEM;
1027d8408326SSeung-Woo Kim 	}
1028d8408326SSeung-Woo Kim 
10299416dfa7SSachin Kamat 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1030d8408326SSeung-Woo Kim 	if (!ctx) {
1031d8408326SSeung-Woo Kim 		DRM_ERROR("failed to alloc mixer context.\n");
1032d8408326SSeung-Woo Kim 		return -ENOMEM;
1033d8408326SSeung-Woo Kim 	}
1034d8408326SSeung-Woo Kim 
1035cf8fc4f1SJoonyoung Shim 	mutex_init(&ctx->mixer_mutex);
1036cf8fc4f1SJoonyoung Shim 
1037cf8fc4f1SJoonyoung Shim 	ctx->dev = &pdev->dev;
1038d8408326SSeung-Woo Kim 	drm_hdmi_ctx->ctx = (void *)ctx;
1039d8408326SSeung-Woo Kim 
1040d8408326SSeung-Woo Kim 	platform_set_drvdata(pdev, drm_hdmi_ctx);
1041d8408326SSeung-Woo Kim 
1042d8408326SSeung-Woo Kim 	/* acquire resources: regs, irqs, clocks */
1043d8408326SSeung-Woo Kim 	ret = mixer_resources_init(drm_hdmi_ctx, pdev);
1044d8408326SSeung-Woo Kim 	if (ret)
1045d8408326SSeung-Woo Kim 		goto fail;
1046d8408326SSeung-Woo Kim 
1047d8408326SSeung-Woo Kim 	/* register specific callback point to common hdmi. */
1048578b6065SJoonyoung Shim 	exynos_mixer_ops_register(&mixer_ops);
1049d8408326SSeung-Woo Kim 
1050cf8fc4f1SJoonyoung Shim 	pm_runtime_enable(dev);
1051d8408326SSeung-Woo Kim 
1052d8408326SSeung-Woo Kim 	return 0;
1053d8408326SSeung-Woo Kim 
1054d8408326SSeung-Woo Kim 
1055d8408326SSeung-Woo Kim fail:
1056d8408326SSeung-Woo Kim 	dev_info(dev, "probe failed\n");
1057d8408326SSeung-Woo Kim 	return ret;
1058d8408326SSeung-Woo Kim }
1059d8408326SSeung-Woo Kim 
1060d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev)
1061d8408326SSeung-Woo Kim {
10629416dfa7SSachin Kamat 	dev_info(&pdev->dev, "remove successful\n");
1063d8408326SSeung-Woo Kim 
1064cf8fc4f1SJoonyoung Shim 	pm_runtime_disable(&pdev->dev);
1065cf8fc4f1SJoonyoung Shim 
1066d8408326SSeung-Woo Kim 	return 0;
1067d8408326SSeung-Woo Kim }
1068d8408326SSeung-Woo Kim 
1069ab27af85SJoonyoung Shim #ifdef CONFIG_PM_SLEEP
1070ab27af85SJoonyoung Shim static int mixer_suspend(struct device *dev)
1071ab27af85SJoonyoung Shim {
1072ab27af85SJoonyoung Shim 	struct exynos_drm_hdmi_context *drm_hdmi_ctx = get_mixer_context(dev);
1073ab27af85SJoonyoung Shim 	struct mixer_context *ctx = drm_hdmi_ctx->ctx;
1074ab27af85SJoonyoung Shim 
1075ab27af85SJoonyoung Shim 	mixer_poweroff(ctx);
1076ab27af85SJoonyoung Shim 
1077ab27af85SJoonyoung Shim 	return 0;
1078ab27af85SJoonyoung Shim }
1079ab27af85SJoonyoung Shim #endif
1080ab27af85SJoonyoung Shim 
1081ab27af85SJoonyoung Shim static SIMPLE_DEV_PM_OPS(mixer_pm_ops, mixer_suspend, NULL);
1082ab27af85SJoonyoung Shim 
1083d8408326SSeung-Woo Kim struct platform_driver mixer_driver = {
1084d8408326SSeung-Woo Kim 	.driver = {
1085d8408326SSeung-Woo Kim 		.name = "s5p-mixer",
1086d8408326SSeung-Woo Kim 		.owner = THIS_MODULE,
1087ab27af85SJoonyoung Shim 		.pm = &mixer_pm_ops,
1088d8408326SSeung-Woo Kim 	},
1089d8408326SSeung-Woo Kim 	.probe = mixer_probe,
1090d8408326SSeung-Woo Kim 	.remove = __devexit_p(mixer_remove),
1091d8408326SSeung-Woo Kim };
1092