xref: /linux/drivers/gpu/drm/exynos/exynos_mixer.c (revision 5d1741ad4b61bc5a7fbc783199aa2b8805877e76)
1d8408326SSeung-Woo Kim /*
2d8408326SSeung-Woo Kim  * Copyright (C) 2011 Samsung Electronics Co.Ltd
3d8408326SSeung-Woo Kim  * Authors:
4d8408326SSeung-Woo Kim  * Seung-Woo Kim <sw0312.kim@samsung.com>
5d8408326SSeung-Woo Kim  *	Inki Dae <inki.dae@samsung.com>
6d8408326SSeung-Woo Kim  *	Joonyoung Shim <jy0922.shim@samsung.com>
7d8408326SSeung-Woo Kim  *
8d8408326SSeung-Woo Kim  * Based on drivers/media/video/s5p-tv/mixer_reg.c
9d8408326SSeung-Woo Kim  *
10d8408326SSeung-Woo Kim  * This program is free software; you can redistribute  it and/or modify it
11d8408326SSeung-Woo Kim  * under  the terms of  the GNU General  Public License as published by the
12d8408326SSeung-Woo Kim  * Free Software Foundation;  either version 2 of the  License, or (at your
13d8408326SSeung-Woo Kim  * option) any later version.
14d8408326SSeung-Woo Kim  *
15d8408326SSeung-Woo Kim  */
16d8408326SSeung-Woo Kim 
17760285e7SDavid Howells #include <drm/drmP.h>
18d8408326SSeung-Woo Kim 
19d8408326SSeung-Woo Kim #include "regs-mixer.h"
20d8408326SSeung-Woo Kim #include "regs-vp.h"
21d8408326SSeung-Woo Kim 
22d8408326SSeung-Woo Kim #include <linux/kernel.h>
23d8408326SSeung-Woo Kim #include <linux/spinlock.h>
24d8408326SSeung-Woo Kim #include <linux/wait.h>
25d8408326SSeung-Woo Kim #include <linux/i2c.h>
26d8408326SSeung-Woo Kim #include <linux/platform_device.h>
27d8408326SSeung-Woo Kim #include <linux/interrupt.h>
28d8408326SSeung-Woo Kim #include <linux/irq.h>
29d8408326SSeung-Woo Kim #include <linux/delay.h>
30d8408326SSeung-Woo Kim #include <linux/pm_runtime.h>
31d8408326SSeung-Woo Kim #include <linux/clk.h>
32d8408326SSeung-Woo Kim #include <linux/regulator/consumer.h>
333f1c781dSSachin Kamat #include <linux/of.h>
34f37cd5e8SInki Dae #include <linux/component.h>
35d8408326SSeung-Woo Kim 
36d8408326SSeung-Woo Kim #include <drm/exynos_drm.h>
37d8408326SSeung-Woo Kim 
38d8408326SSeung-Woo Kim #include "exynos_drm_drv.h"
39663d8766SRahul Sharma #include "exynos_drm_crtc.h"
401055b39fSInki Dae #include "exynos_drm_iommu.h"
41f041b257SSean Paul #include "exynos_mixer.h"
4222b21ae6SJoonyoung Shim 
43f041b257SSean Paul #define MIXER_WIN_NR		3
44f041b257SSean Paul #define MIXER_DEFAULT_WIN	0
45d8408326SSeung-Woo Kim 
4622b21ae6SJoonyoung Shim struct hdmi_win_data {
4722b21ae6SJoonyoung Shim 	dma_addr_t		dma_addr;
4822b21ae6SJoonyoung Shim 	dma_addr_t		chroma_dma_addr;
4922b21ae6SJoonyoung Shim 	uint32_t		pixel_format;
5022b21ae6SJoonyoung Shim 	unsigned int		bpp;
5122b21ae6SJoonyoung Shim 	unsigned int		crtc_x;
5222b21ae6SJoonyoung Shim 	unsigned int		crtc_y;
5322b21ae6SJoonyoung Shim 	unsigned int		crtc_width;
5422b21ae6SJoonyoung Shim 	unsigned int		crtc_height;
5522b21ae6SJoonyoung Shim 	unsigned int		fb_x;
5622b21ae6SJoonyoung Shim 	unsigned int		fb_y;
5722b21ae6SJoonyoung Shim 	unsigned int		fb_width;
5822b21ae6SJoonyoung Shim 	unsigned int		fb_height;
598dcb96b6SSeung-Woo Kim 	unsigned int		src_width;
608dcb96b6SSeung-Woo Kim 	unsigned int		src_height;
6122b21ae6SJoonyoung Shim 	unsigned int		mode_width;
6222b21ae6SJoonyoung Shim 	unsigned int		mode_height;
6322b21ae6SJoonyoung Shim 	unsigned int		scan_flags;
64db43fd16SPrathyush K 	bool			enabled;
65db43fd16SPrathyush K 	bool			resume;
6622b21ae6SJoonyoung Shim };
6722b21ae6SJoonyoung Shim 
6822b21ae6SJoonyoung Shim struct mixer_resources {
6922b21ae6SJoonyoung Shim 	int			irq;
7022b21ae6SJoonyoung Shim 	void __iomem		*mixer_regs;
7122b21ae6SJoonyoung Shim 	void __iomem		*vp_regs;
7222b21ae6SJoonyoung Shim 	spinlock_t		reg_slock;
7322b21ae6SJoonyoung Shim 	struct clk		*mixer;
7422b21ae6SJoonyoung Shim 	struct clk		*vp;
7522b21ae6SJoonyoung Shim 	struct clk		*sclk_mixer;
7622b21ae6SJoonyoung Shim 	struct clk		*sclk_hdmi;
77ff830c96SMarek Szyprowski 	struct clk		*mout_mixer;
7822b21ae6SJoonyoung Shim };
7922b21ae6SJoonyoung Shim 
801e123441SRahul Sharma enum mixer_version_id {
811e123441SRahul Sharma 	MXR_VER_0_0_0_16,
821e123441SRahul Sharma 	MXR_VER_16_0_33_0,
83def5e095SRahul Sharma 	MXR_VER_128_0_0_184,
841e123441SRahul Sharma };
851e123441SRahul Sharma 
8622b21ae6SJoonyoung Shim struct mixer_context {
878103ef1bSAndrzej Hajda 	struct exynos_drm_manager manager;
884551789fSSean Paul 	struct platform_device *pdev;
89cf8fc4f1SJoonyoung Shim 	struct device		*dev;
901055b39fSInki Dae 	struct drm_device	*drm_dev;
9122b21ae6SJoonyoung Shim 	int			pipe;
9222b21ae6SJoonyoung Shim 	bool			interlace;
93cf8fc4f1SJoonyoung Shim 	bool			powered;
941b8e5747SRahul Sharma 	bool			vp_enabled;
95ff830c96SMarek Szyprowski 	bool			has_sclk;
96cf8fc4f1SJoonyoung Shim 	u32			int_en;
9722b21ae6SJoonyoung Shim 
98cf8fc4f1SJoonyoung Shim 	struct mutex		mixer_mutex;
9922b21ae6SJoonyoung Shim 	struct mixer_resources	mixer_res;
100a634dd54SJoonyoung Shim 	struct hdmi_win_data	win_data[MIXER_WIN_NR];
1011e123441SRahul Sharma 	enum mixer_version_id	mxr_ver;
1026e95d5e6SPrathyush K 	wait_queue_head_t	wait_vsync_queue;
1036e95d5e6SPrathyush K 	atomic_t		wait_vsync_event;
1041e123441SRahul Sharma };
1051e123441SRahul Sharma 
1068f0be830SAndrzej Hajda static inline struct mixer_context *mgr_to_mixer(struct exynos_drm_manager *mgr)
1078f0be830SAndrzej Hajda {
1088f0be830SAndrzej Hajda 	return container_of(mgr, struct mixer_context, manager);
1098f0be830SAndrzej Hajda }
1108f0be830SAndrzej Hajda 
1111e123441SRahul Sharma struct mixer_drv_data {
1121e123441SRahul Sharma 	enum mixer_version_id	version;
1131b8e5747SRahul Sharma 	bool					is_vp_enabled;
114ff830c96SMarek Szyprowski 	bool					has_sclk;
11522b21ae6SJoonyoung Shim };
11622b21ae6SJoonyoung Shim 
117d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = {
118d8408326SSeung-Woo Kim 	0,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
119d8408326SSeung-Woo Kim 	-1,	-1,	-1,	-1,	-1,	0,	0,	0,
120d8408326SSeung-Woo Kim 	0,	2,	4,	5,	6,	6,	6,	6,
121d8408326SSeung-Woo Kim 	6,	5,	5,	4,	3,	2,	1,	1,
122d8408326SSeung-Woo Kim 	0,	-6,	-12,	-16,	-18,	-20,	-21,	-20,
123d8408326SSeung-Woo Kim 	-20,	-18,	-16,	-13,	-10,	-8,	-5,	-2,
124d8408326SSeung-Woo Kim 	127,	126,	125,	121,	114,	107,	99,	89,
125d8408326SSeung-Woo Kim 	79,	68,	57,	46,	35,	25,	16,	8,
126d8408326SSeung-Woo Kim };
127d8408326SSeung-Woo Kim 
128d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = {
129d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
130d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
131d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
132d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
133d8408326SSeung-Woo Kim 	0,	5,	11,	19,	27,	37,	48,	59,
134d8408326SSeung-Woo Kim 	70,	81,	92,	102,	111,	118,	124,	126,
135d8408326SSeung-Woo Kim 	0,	0,	-1,	-1,	-2,	-3,	-4,	-5,
136d8408326SSeung-Woo Kim 	-6,	-7,	-8,	-8,	-8,	-8,	-6,	-3,
137d8408326SSeung-Woo Kim };
138d8408326SSeung-Woo Kim 
139d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = {
140d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
141d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
142d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
143d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
144d8408326SSeung-Woo Kim };
145d8408326SSeung-Woo Kim 
146d8408326SSeung-Woo Kim static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id)
147d8408326SSeung-Woo Kim {
148d8408326SSeung-Woo Kim 	return readl(res->vp_regs + reg_id);
149d8408326SSeung-Woo Kim }
150d8408326SSeung-Woo Kim 
151d8408326SSeung-Woo Kim static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id,
152d8408326SSeung-Woo Kim 				 u32 val)
153d8408326SSeung-Woo Kim {
154d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
155d8408326SSeung-Woo Kim }
156d8408326SSeung-Woo Kim 
157d8408326SSeung-Woo Kim static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id,
158d8408326SSeung-Woo Kim 				 u32 val, u32 mask)
159d8408326SSeung-Woo Kim {
160d8408326SSeung-Woo Kim 	u32 old = vp_reg_read(res, reg_id);
161d8408326SSeung-Woo Kim 
162d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
163d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
164d8408326SSeung-Woo Kim }
165d8408326SSeung-Woo Kim 
166d8408326SSeung-Woo Kim static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id)
167d8408326SSeung-Woo Kim {
168d8408326SSeung-Woo Kim 	return readl(res->mixer_regs + reg_id);
169d8408326SSeung-Woo Kim }
170d8408326SSeung-Woo Kim 
171d8408326SSeung-Woo Kim static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id,
172d8408326SSeung-Woo Kim 				 u32 val)
173d8408326SSeung-Woo Kim {
174d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
175d8408326SSeung-Woo Kim }
176d8408326SSeung-Woo Kim 
177d8408326SSeung-Woo Kim static inline void mixer_reg_writemask(struct mixer_resources *res,
178d8408326SSeung-Woo Kim 				 u32 reg_id, u32 val, u32 mask)
179d8408326SSeung-Woo Kim {
180d8408326SSeung-Woo Kim 	u32 old = mixer_reg_read(res, reg_id);
181d8408326SSeung-Woo Kim 
182d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
183d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
184d8408326SSeung-Woo Kim }
185d8408326SSeung-Woo Kim 
186d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx)
187d8408326SSeung-Woo Kim {
188d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
189d8408326SSeung-Woo Kim do { \
190d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
191d8408326SSeung-Woo Kim 		(u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \
192d8408326SSeung-Woo Kim } while (0)
193d8408326SSeung-Woo Kim 
194d8408326SSeung-Woo Kim 	DUMPREG(MXR_STATUS);
195d8408326SSeung-Woo Kim 	DUMPREG(MXR_CFG);
196d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_EN);
197d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_STATUS);
198d8408326SSeung-Woo Kim 
199d8408326SSeung-Woo Kim 	DUMPREG(MXR_LAYER_CFG);
200d8408326SSeung-Woo Kim 	DUMPREG(MXR_VIDEO_CFG);
201d8408326SSeung-Woo Kim 
202d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_CFG);
203d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_BASE);
204d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SPAN);
205d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_WH);
206d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SXY);
207d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_DXY);
208d8408326SSeung-Woo Kim 
209d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_CFG);
210d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_BASE);
211d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SPAN);
212d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_WH);
213d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SXY);
214d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_DXY);
215d8408326SSeung-Woo Kim #undef DUMPREG
216d8408326SSeung-Woo Kim }
217d8408326SSeung-Woo Kim 
218d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx)
219d8408326SSeung-Woo Kim {
220d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
221d8408326SSeung-Woo Kim do { \
222d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
223d8408326SSeung-Woo Kim 		(u32) readl(ctx->mixer_res.vp_regs + reg_id)); \
224d8408326SSeung-Woo Kim } while (0)
225d8408326SSeung-Woo Kim 
226d8408326SSeung-Woo Kim 	DUMPREG(VP_ENABLE);
227d8408326SSeung-Woo Kim 	DUMPREG(VP_SRESET);
228d8408326SSeung-Woo Kim 	DUMPREG(VP_SHADOW_UPDATE);
229d8408326SSeung-Woo Kim 	DUMPREG(VP_FIELD_ID);
230d8408326SSeung-Woo Kim 	DUMPREG(VP_MODE);
231d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_Y);
232d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_C);
233d8408326SSeung-Woo Kim 	DUMPREG(VP_PER_RATE_CTRL);
234d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_Y_PTR);
235d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_Y_PTR);
236d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_C_PTR);
237d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_C_PTR);
238d8408326SSeung-Woo Kim 	DUMPREG(VP_ENDIAN_MODE);
239d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_H_POSITION);
240d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_V_POSITION);
241d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_WIDTH);
242d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_HEIGHT);
243d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_H_POSITION);
244d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_V_POSITION);
245d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_WIDTH);
246d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_HEIGHT);
247d8408326SSeung-Woo Kim 	DUMPREG(VP_H_RATIO);
248d8408326SSeung-Woo Kim 	DUMPREG(VP_V_RATIO);
249d8408326SSeung-Woo Kim 
250d8408326SSeung-Woo Kim #undef DUMPREG
251d8408326SSeung-Woo Kim }
252d8408326SSeung-Woo Kim 
253d8408326SSeung-Woo Kim static inline void vp_filter_set(struct mixer_resources *res,
254d8408326SSeung-Woo Kim 		int reg_id, const u8 *data, unsigned int size)
255d8408326SSeung-Woo Kim {
256d8408326SSeung-Woo Kim 	/* assure 4-byte align */
257d8408326SSeung-Woo Kim 	BUG_ON(size & 3);
258d8408326SSeung-Woo Kim 	for (; size; size -= 4, reg_id += 4, data += 4) {
259d8408326SSeung-Woo Kim 		u32 val = (data[0] << 24) |  (data[1] << 16) |
260d8408326SSeung-Woo Kim 			(data[2] << 8) | data[3];
261d8408326SSeung-Woo Kim 		vp_reg_write(res, reg_id, val);
262d8408326SSeung-Woo Kim 	}
263d8408326SSeung-Woo Kim }
264d8408326SSeung-Woo Kim 
265d8408326SSeung-Woo Kim static void vp_default_filter(struct mixer_resources *res)
266d8408326SSeung-Woo Kim {
267d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY8_Y0_LL,
268e25e1b66SSachin Kamat 		filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
269d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_Y0_LL,
270e25e1b66SSachin Kamat 		filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
271d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_C0_LL,
272e25e1b66SSachin Kamat 		filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
273d8408326SSeung-Woo Kim }
274d8408326SSeung-Woo Kim 
275d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable)
276d8408326SSeung-Woo Kim {
277d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
278d8408326SSeung-Woo Kim 
279d8408326SSeung-Woo Kim 	/* block update on vsync */
280d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, enable ?
281d8408326SSeung-Woo Kim 			MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE);
282d8408326SSeung-Woo Kim 
2831b8e5747SRahul Sharma 	if (ctx->vp_enabled)
284d8408326SSeung-Woo Kim 		vp_reg_write(res, VP_SHADOW_UPDATE, enable ?
285d8408326SSeung-Woo Kim 			VP_SHADOW_UPDATE_ENABLE : 0);
286d8408326SSeung-Woo Kim }
287d8408326SSeung-Woo Kim 
288d8408326SSeung-Woo Kim static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height)
289d8408326SSeung-Woo Kim {
290d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
291d8408326SSeung-Woo Kim 	u32 val;
292d8408326SSeung-Woo Kim 
293d8408326SSeung-Woo Kim 	/* choosing between interlace and progressive mode */
294d8408326SSeung-Woo Kim 	val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE :
295d8408326SSeung-Woo Kim 				MXR_CFG_SCAN_PROGRASSIVE);
296d8408326SSeung-Woo Kim 
297def5e095SRahul Sharma 	if (ctx->mxr_ver != MXR_VER_128_0_0_184) {
298def5e095SRahul Sharma 		/* choosing between proper HD and SD mode */
29929630743SRahul Sharma 		if (height <= 480)
300d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD;
30129630743SRahul Sharma 		else if (height <= 576)
302d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD;
30329630743SRahul Sharma 		else if (height <= 720)
304d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
30529630743SRahul Sharma 		else if (height <= 1080)
306d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD;
307d8408326SSeung-Woo Kim 		else
308d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
309def5e095SRahul Sharma 	}
310d8408326SSeung-Woo Kim 
311d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK);
312d8408326SSeung-Woo Kim }
313d8408326SSeung-Woo Kim 
314d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height)
315d8408326SSeung-Woo Kim {
316d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
317d8408326SSeung-Woo Kim 	u32 val;
318d8408326SSeung-Woo Kim 
319d8408326SSeung-Woo Kim 	if (height == 480) {
320d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
321d8408326SSeung-Woo Kim 	} else if (height == 576) {
322d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
323d8408326SSeung-Woo Kim 	} else if (height == 720) {
324d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
325d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
326d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
327d8408326SSeung-Woo Kim 				(32 << 0));
328d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
329d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
330d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
331d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
332d8408326SSeung-Woo Kim 	} else if (height == 1080) {
333d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
334d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
335d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
336d8408326SSeung-Woo Kim 				(32 << 0));
337d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
338d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
339d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
340d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
341d8408326SSeung-Woo Kim 	} else {
342d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
343d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
344d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
345d8408326SSeung-Woo Kim 				(32 << 0));
346d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
347d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
348d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
349d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
350d8408326SSeung-Woo Kim 	}
351d8408326SSeung-Woo Kim 
352d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
353d8408326SSeung-Woo Kim }
354d8408326SSeung-Woo Kim 
355d8408326SSeung-Woo Kim static void mixer_cfg_layer(struct mixer_context *ctx, int win, bool enable)
356d8408326SSeung-Woo Kim {
357d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
358d8408326SSeung-Woo Kim 	u32 val = enable ? ~0 : 0;
359d8408326SSeung-Woo Kim 
360d8408326SSeung-Woo Kim 	switch (win) {
361d8408326SSeung-Woo Kim 	case 0:
362d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
363d8408326SSeung-Woo Kim 		break;
364d8408326SSeung-Woo Kim 	case 1:
365d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
366d8408326SSeung-Woo Kim 		break;
367d8408326SSeung-Woo Kim 	case 2:
3681b8e5747SRahul Sharma 		if (ctx->vp_enabled) {
369d8408326SSeung-Woo Kim 			vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON);
3701b8e5747SRahul Sharma 			mixer_reg_writemask(res, MXR_CFG, val,
3711b8e5747SRahul Sharma 				MXR_CFG_VP_ENABLE);
372f1e716d8SJoonyoung Shim 
373f1e716d8SJoonyoung Shim 			/* control blending of graphic layer 0 */
374f1e716d8SJoonyoung Shim 			mixer_reg_writemask(res, MXR_GRAPHIC_CFG(0), val,
375f1e716d8SJoonyoung Shim 					MXR_GRP_CFG_BLEND_PRE_MUL |
376f1e716d8SJoonyoung Shim 					MXR_GRP_CFG_PIXEL_BLEND_EN);
3771b8e5747SRahul Sharma 		}
378d8408326SSeung-Woo Kim 		break;
379d8408326SSeung-Woo Kim 	}
380d8408326SSeung-Woo Kim }
381d8408326SSeung-Woo Kim 
382d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx)
383d8408326SSeung-Woo Kim {
384d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
385d8408326SSeung-Woo Kim 
386d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
387d8408326SSeung-Woo Kim 
388d8408326SSeung-Woo Kim 	mixer_regs_dump(ctx);
389d8408326SSeung-Woo Kim }
390d8408326SSeung-Woo Kim 
391381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx)
392381be025SRahul Sharma {
393381be025SRahul Sharma 	struct mixer_resources *res = &ctx->mixer_res;
394381be025SRahul Sharma 	int timeout = 20;
395381be025SRahul Sharma 
396381be025SRahul Sharma 	mixer_reg_writemask(res, MXR_STATUS, 0, MXR_STATUS_REG_RUN);
397381be025SRahul Sharma 
398381be025SRahul Sharma 	while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
399381be025SRahul Sharma 			--timeout)
400381be025SRahul Sharma 		usleep_range(10000, 12000);
401381be025SRahul Sharma 
402381be025SRahul Sharma 	mixer_regs_dump(ctx);
403381be025SRahul Sharma }
404381be025SRahul Sharma 
405d8408326SSeung-Woo Kim static void vp_video_buffer(struct mixer_context *ctx, int win)
406d8408326SSeung-Woo Kim {
407d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
408d8408326SSeung-Woo Kim 	unsigned long flags;
409d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
410d8408326SSeung-Woo Kim 	unsigned int x_ratio, y_ratio;
411782953ecSYoungJun Cho 	unsigned int buf_num = 1;
412d8408326SSeung-Woo Kim 	dma_addr_t luma_addr[2], chroma_addr[2];
413d8408326SSeung-Woo Kim 	bool tiled_mode = false;
414d8408326SSeung-Woo Kim 	bool crcb_mode = false;
415d8408326SSeung-Woo Kim 	u32 val;
416d8408326SSeung-Woo Kim 
417d8408326SSeung-Woo Kim 	win_data = &ctx->win_data[win];
418d8408326SSeung-Woo Kim 
419d8408326SSeung-Woo Kim 	switch (win_data->pixel_format) {
420d8408326SSeung-Woo Kim 	case DRM_FORMAT_NV12MT:
421d8408326SSeung-Woo Kim 		tiled_mode = true;
422363b06aaSVille Syrjälä 	case DRM_FORMAT_NV12:
423d8408326SSeung-Woo Kim 		crcb_mode = false;
424d8408326SSeung-Woo Kim 		buf_num = 2;
425d8408326SSeung-Woo Kim 		break;
426d8408326SSeung-Woo Kim 	/* TODO: single buffer format NV12, NV21 */
427d8408326SSeung-Woo Kim 	default:
428d8408326SSeung-Woo Kim 		/* ignore pixel format at disable time */
429d8408326SSeung-Woo Kim 		if (!win_data->dma_addr)
430d8408326SSeung-Woo Kim 			break;
431d8408326SSeung-Woo Kim 
432d8408326SSeung-Woo Kim 		DRM_ERROR("pixel format for vp is wrong [%d].\n",
433d8408326SSeung-Woo Kim 				win_data->pixel_format);
434d8408326SSeung-Woo Kim 		return;
435d8408326SSeung-Woo Kim 	}
436d8408326SSeung-Woo Kim 
437d8408326SSeung-Woo Kim 	/* scaling feature: (src << 16) / dst */
4388dcb96b6SSeung-Woo Kim 	x_ratio = (win_data->src_width << 16) / win_data->crtc_width;
4398dcb96b6SSeung-Woo Kim 	y_ratio = (win_data->src_height << 16) / win_data->crtc_height;
440d8408326SSeung-Woo Kim 
441d8408326SSeung-Woo Kim 	if (buf_num == 2) {
442d8408326SSeung-Woo Kim 		luma_addr[0] = win_data->dma_addr;
443d8408326SSeung-Woo Kim 		chroma_addr[0] = win_data->chroma_dma_addr;
444d8408326SSeung-Woo Kim 	} else {
445d8408326SSeung-Woo Kim 		luma_addr[0] = win_data->dma_addr;
446d8408326SSeung-Woo Kim 		chroma_addr[0] = win_data->dma_addr
4478dcb96b6SSeung-Woo Kim 			+ (win_data->fb_width * win_data->fb_height);
448d8408326SSeung-Woo Kim 	}
449d8408326SSeung-Woo Kim 
450d8408326SSeung-Woo Kim 	if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE) {
451d8408326SSeung-Woo Kim 		ctx->interlace = true;
452d8408326SSeung-Woo Kim 		if (tiled_mode) {
453d8408326SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + 0x40;
454d8408326SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + 0x40;
455d8408326SSeung-Woo Kim 		} else {
4568dcb96b6SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + win_data->fb_width;
4578dcb96b6SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + win_data->fb_width;
458d8408326SSeung-Woo Kim 		}
459d8408326SSeung-Woo Kim 	} else {
460d8408326SSeung-Woo Kim 		ctx->interlace = false;
461d8408326SSeung-Woo Kim 		luma_addr[1] = 0;
462d8408326SSeung-Woo Kim 		chroma_addr[1] = 0;
463d8408326SSeung-Woo Kim 	}
464d8408326SSeung-Woo Kim 
465d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
466d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
467d8408326SSeung-Woo Kim 
468d8408326SSeung-Woo Kim 	/* interlace or progressive scan mode */
469d8408326SSeung-Woo Kim 	val = (ctx->interlace ? ~0 : 0);
470d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP);
471d8408326SSeung-Woo Kim 
472d8408326SSeung-Woo Kim 	/* setup format */
473d8408326SSeung-Woo Kim 	val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12);
474d8408326SSeung-Woo Kim 	val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
475d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK);
476d8408326SSeung-Woo Kim 
477d8408326SSeung-Woo Kim 	/* setting size of input image */
4788dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(win_data->fb_width) |
4798dcb96b6SSeung-Woo Kim 		VP_IMG_VSIZE(win_data->fb_height));
480d8408326SSeung-Woo Kim 	/* chroma height has to reduced by 2 to avoid chroma distorions */
4818dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(win_data->fb_width) |
4828dcb96b6SSeung-Woo Kim 		VP_IMG_VSIZE(win_data->fb_height / 2));
483d8408326SSeung-Woo Kim 
4848dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_WIDTH, win_data->src_width);
4858dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_HEIGHT, win_data->src_height);
486d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_H_POSITION,
4878dcb96b6SSeung-Woo Kim 			VP_SRC_H_POSITION_VAL(win_data->fb_x));
4888dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_V_POSITION, win_data->fb_y);
489d8408326SSeung-Woo Kim 
4908dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_DST_WIDTH, win_data->crtc_width);
4918dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_DST_H_POSITION, win_data->crtc_x);
492d8408326SSeung-Woo Kim 	if (ctx->interlace) {
4938dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height / 2);
4948dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y / 2);
495d8408326SSeung-Woo Kim 	} else {
4968dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height);
4978dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y);
498d8408326SSeung-Woo Kim 	}
499d8408326SSeung-Woo Kim 
500d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_H_RATIO, x_ratio);
501d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_V_RATIO, y_ratio);
502d8408326SSeung-Woo Kim 
503d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
504d8408326SSeung-Woo Kim 
505d8408326SSeung-Woo Kim 	/* set buffer address to vp */
506d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]);
507d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]);
508d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]);
509d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]);
510d8408326SSeung-Woo Kim 
5118dcb96b6SSeung-Woo Kim 	mixer_cfg_scan(ctx, win_data->mode_height);
5128dcb96b6SSeung-Woo Kim 	mixer_cfg_rgb_fmt(ctx, win_data->mode_height);
513d8408326SSeung-Woo Kim 	mixer_cfg_layer(ctx, win, true);
514d8408326SSeung-Woo Kim 	mixer_run(ctx);
515d8408326SSeung-Woo Kim 
516d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
517d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
518d8408326SSeung-Woo Kim 
519d8408326SSeung-Woo Kim 	vp_regs_dump(ctx);
520d8408326SSeung-Woo Kim }
521d8408326SSeung-Woo Kim 
522aaf8b49eSRahul Sharma static void mixer_layer_update(struct mixer_context *ctx)
523aaf8b49eSRahul Sharma {
524aaf8b49eSRahul Sharma 	struct mixer_resources *res = &ctx->mixer_res;
525aaf8b49eSRahul Sharma 
526aaf8b49eSRahul Sharma 	mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
527aaf8b49eSRahul Sharma }
528aaf8b49eSRahul Sharma 
529d8408326SSeung-Woo Kim static void mixer_graph_buffer(struct mixer_context *ctx, int win)
530d8408326SSeung-Woo Kim {
531d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
532d8408326SSeung-Woo Kim 	unsigned long flags;
533d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
534d8408326SSeung-Woo Kim 	unsigned int x_ratio, y_ratio;
535d8408326SSeung-Woo Kim 	unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset;
536d8408326SSeung-Woo Kim 	dma_addr_t dma_addr;
537d8408326SSeung-Woo Kim 	unsigned int fmt;
538d8408326SSeung-Woo Kim 	u32 val;
539d8408326SSeung-Woo Kim 
540d8408326SSeung-Woo Kim 	win_data = &ctx->win_data[win];
541d8408326SSeung-Woo Kim 
542d8408326SSeung-Woo Kim 	#define RGB565 4
543d8408326SSeung-Woo Kim 	#define ARGB1555 5
544d8408326SSeung-Woo Kim 	#define ARGB4444 6
545d8408326SSeung-Woo Kim 	#define ARGB8888 7
546d8408326SSeung-Woo Kim 
547d8408326SSeung-Woo Kim 	switch (win_data->bpp) {
548d8408326SSeung-Woo Kim 	case 16:
549d8408326SSeung-Woo Kim 		fmt = ARGB4444;
550d8408326SSeung-Woo Kim 		break;
551d8408326SSeung-Woo Kim 	case 32:
552d8408326SSeung-Woo Kim 		fmt = ARGB8888;
553d8408326SSeung-Woo Kim 		break;
554d8408326SSeung-Woo Kim 	default:
555d8408326SSeung-Woo Kim 		fmt = ARGB8888;
556d8408326SSeung-Woo Kim 	}
557d8408326SSeung-Woo Kim 
558d8408326SSeung-Woo Kim 	/* 2x scaling feature */
559d8408326SSeung-Woo Kim 	x_ratio = 0;
560d8408326SSeung-Woo Kim 	y_ratio = 0;
561d8408326SSeung-Woo Kim 
562d8408326SSeung-Woo Kim 	dst_x_offset = win_data->crtc_x;
563d8408326SSeung-Woo Kim 	dst_y_offset = win_data->crtc_y;
564d8408326SSeung-Woo Kim 
565d8408326SSeung-Woo Kim 	/* converting dma address base and source offset */
5668dcb96b6SSeung-Woo Kim 	dma_addr = win_data->dma_addr
5678dcb96b6SSeung-Woo Kim 		+ (win_data->fb_x * win_data->bpp >> 3)
5688dcb96b6SSeung-Woo Kim 		+ (win_data->fb_y * win_data->fb_width * win_data->bpp >> 3);
569d8408326SSeung-Woo Kim 	src_x_offset = 0;
570d8408326SSeung-Woo Kim 	src_y_offset = 0;
571d8408326SSeung-Woo Kim 
572d8408326SSeung-Woo Kim 	if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE)
573d8408326SSeung-Woo Kim 		ctx->interlace = true;
574d8408326SSeung-Woo Kim 	else
575d8408326SSeung-Woo Kim 		ctx->interlace = false;
576d8408326SSeung-Woo Kim 
577d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
578d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
579d8408326SSeung-Woo Kim 
580d8408326SSeung-Woo Kim 	/* setup format */
581d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
582d8408326SSeung-Woo Kim 		MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
583d8408326SSeung-Woo Kim 
584d8408326SSeung-Woo Kim 	/* setup geometry */
5858dcb96b6SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_SPAN(win), win_data->fb_width);
586d8408326SSeung-Woo Kim 
587def5e095SRahul Sharma 	/* setup display size */
588def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_128_0_0_184 &&
589def5e095SRahul Sharma 		win == MIXER_DEFAULT_WIN) {
590def5e095SRahul Sharma 		val  = MXR_MXR_RES_HEIGHT(win_data->fb_height);
591def5e095SRahul Sharma 		val |= MXR_MXR_RES_WIDTH(win_data->fb_width);
592def5e095SRahul Sharma 		mixer_reg_write(res, MXR_RESOLUTION, val);
593def5e095SRahul Sharma 	}
594def5e095SRahul Sharma 
5958dcb96b6SSeung-Woo Kim 	val  = MXR_GRP_WH_WIDTH(win_data->crtc_width);
5968dcb96b6SSeung-Woo Kim 	val |= MXR_GRP_WH_HEIGHT(win_data->crtc_height);
597d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_H_SCALE(x_ratio);
598d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_V_SCALE(y_ratio);
599d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_WH(win), val);
600d8408326SSeung-Woo Kim 
601d8408326SSeung-Woo Kim 	/* setup offsets in source image */
602d8408326SSeung-Woo Kim 	val  = MXR_GRP_SXY_SX(src_x_offset);
603d8408326SSeung-Woo Kim 	val |= MXR_GRP_SXY_SY(src_y_offset);
604d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val);
605d8408326SSeung-Woo Kim 
606d8408326SSeung-Woo Kim 	/* setup offsets in display image */
607d8408326SSeung-Woo Kim 	val  = MXR_GRP_DXY_DX(dst_x_offset);
608d8408326SSeung-Woo Kim 	val |= MXR_GRP_DXY_DY(dst_y_offset);
609d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val);
610d8408326SSeung-Woo Kim 
611d8408326SSeung-Woo Kim 	/* set buffer address to mixer */
612d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr);
613d8408326SSeung-Woo Kim 
6148dcb96b6SSeung-Woo Kim 	mixer_cfg_scan(ctx, win_data->mode_height);
6158dcb96b6SSeung-Woo Kim 	mixer_cfg_rgb_fmt(ctx, win_data->mode_height);
616d8408326SSeung-Woo Kim 	mixer_cfg_layer(ctx, win, true);
617aaf8b49eSRahul Sharma 
618aaf8b49eSRahul Sharma 	/* layer update mandatory for mixer 16.0.33.0 */
619def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
620def5e095SRahul Sharma 		ctx->mxr_ver == MXR_VER_128_0_0_184)
621aaf8b49eSRahul Sharma 		mixer_layer_update(ctx);
622aaf8b49eSRahul Sharma 
623d8408326SSeung-Woo Kim 	mixer_run(ctx);
624d8408326SSeung-Woo Kim 
625d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
626d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
627d8408326SSeung-Woo Kim }
628d8408326SSeung-Woo Kim 
629d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx)
630d8408326SSeung-Woo Kim {
631d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
632d8408326SSeung-Woo Kim 	int tries = 100;
633d8408326SSeung-Woo Kim 
634d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING);
635d8408326SSeung-Woo Kim 	for (tries = 100; tries; --tries) {
636d8408326SSeung-Woo Kim 		/* waiting until VP_SRESET_PROCESSING is 0 */
637d8408326SSeung-Woo Kim 		if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING)
638d8408326SSeung-Woo Kim 			break;
63909760ea3SSean Paul 		usleep_range(10000, 12000);
640d8408326SSeung-Woo Kim 	}
641d8408326SSeung-Woo Kim 	WARN(tries == 0, "failed to reset Video Processor\n");
642d8408326SSeung-Woo Kim }
643d8408326SSeung-Woo Kim 
644cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx)
645cf8fc4f1SJoonyoung Shim {
646cf8fc4f1SJoonyoung Shim 	struct mixer_resources *res = &ctx->mixer_res;
647cf8fc4f1SJoonyoung Shim 	unsigned long flags;
648cf8fc4f1SJoonyoung Shim 	u32 val; /* value stored to register */
649cf8fc4f1SJoonyoung Shim 
650cf8fc4f1SJoonyoung Shim 	spin_lock_irqsave(&res->reg_slock, flags);
651cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, false);
652cf8fc4f1SJoonyoung Shim 
653cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
654cf8fc4f1SJoonyoung Shim 
655cf8fc4f1SJoonyoung Shim 	/* set output in RGB888 mode */
656cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
657cf8fc4f1SJoonyoung Shim 
658cf8fc4f1SJoonyoung Shim 	/* 16 beat burst in DMA */
659cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST,
660cf8fc4f1SJoonyoung Shim 		MXR_STATUS_BURST_MASK);
661cf8fc4f1SJoonyoung Shim 
662cf8fc4f1SJoonyoung Shim 	/* setting default layer priority: layer1 > layer0 > video
663cf8fc4f1SJoonyoung Shim 	 * because typical usage scenario would be
664cf8fc4f1SJoonyoung Shim 	 * layer1 - OSD
665cf8fc4f1SJoonyoung Shim 	 * layer0 - framebuffer
666cf8fc4f1SJoonyoung Shim 	 * video - video overlay
667cf8fc4f1SJoonyoung Shim 	 */
668cf8fc4f1SJoonyoung Shim 	val = MXR_LAYER_CFG_GRP1_VAL(3);
669cf8fc4f1SJoonyoung Shim 	val |= MXR_LAYER_CFG_GRP0_VAL(2);
6701b8e5747SRahul Sharma 	if (ctx->vp_enabled)
671cf8fc4f1SJoonyoung Shim 		val |= MXR_LAYER_CFG_VP_VAL(1);
672cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_LAYER_CFG, val);
673cf8fc4f1SJoonyoung Shim 
674cf8fc4f1SJoonyoung Shim 	/* setting background color */
675cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR0, 0x008080);
676cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR1, 0x008080);
677cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR2, 0x008080);
678cf8fc4f1SJoonyoung Shim 
679cf8fc4f1SJoonyoung Shim 	/* setting graphical layers */
680cf8fc4f1SJoonyoung Shim 	val  = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
681cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_WIN_BLEND_EN;
682cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_ALPHA_VAL(0xff); /* non-transparent alpha */
683cf8fc4f1SJoonyoung Shim 
6840377f4edSSean Paul 	/* Don't blend layer 0 onto the mixer background */
685cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(0), val);
6860377f4edSSean Paul 
6870377f4edSSean Paul 	/* Blend layer 1 into layer 0 */
6880377f4edSSean Paul 	val |= MXR_GRP_CFG_BLEND_PRE_MUL;
6890377f4edSSean Paul 	val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
690cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(1), val);
691cf8fc4f1SJoonyoung Shim 
6925736603bSSeung-Woo Kim 	/* setting video layers */
6935736603bSSeung-Woo Kim 	val = MXR_GRP_CFG_ALPHA_VAL(0);
6945736603bSSeung-Woo Kim 	mixer_reg_write(res, MXR_VIDEO_CFG, val);
6955736603bSSeung-Woo Kim 
6961b8e5747SRahul Sharma 	if (ctx->vp_enabled) {
697cf8fc4f1SJoonyoung Shim 		/* configuration of Video Processor Registers */
698cf8fc4f1SJoonyoung Shim 		vp_win_reset(ctx);
699cf8fc4f1SJoonyoung Shim 		vp_default_filter(res);
7001b8e5747SRahul Sharma 	}
701cf8fc4f1SJoonyoung Shim 
702cf8fc4f1SJoonyoung Shim 	/* disable all layers */
703cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
704cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
7051b8e5747SRahul Sharma 	if (ctx->vp_enabled)
706cf8fc4f1SJoonyoung Shim 		mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
707cf8fc4f1SJoonyoung Shim 
708cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, true);
709cf8fc4f1SJoonyoung Shim 	spin_unlock_irqrestore(&res->reg_slock, flags);
710cf8fc4f1SJoonyoung Shim }
711cf8fc4f1SJoonyoung Shim 
7124551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg)
7134551789fSSean Paul {
7144551789fSSean Paul 	struct mixer_context *ctx = arg;
7154551789fSSean Paul 	struct mixer_resources *res = &ctx->mixer_res;
7164551789fSSean Paul 	u32 val, base, shadow;
7174551789fSSean Paul 
7184551789fSSean Paul 	spin_lock(&res->reg_slock);
7194551789fSSean Paul 
7204551789fSSean Paul 	/* read interrupt status for handling and clearing flags for VSYNC */
7214551789fSSean Paul 	val = mixer_reg_read(res, MXR_INT_STATUS);
7224551789fSSean Paul 
7234551789fSSean Paul 	/* handling VSYNC */
7244551789fSSean Paul 	if (val & MXR_INT_STATUS_VSYNC) {
7254551789fSSean Paul 		/* interlace scan need to check shadow register */
7264551789fSSean Paul 		if (ctx->interlace) {
7274551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0));
7284551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0));
7294551789fSSean Paul 			if (base != shadow)
7304551789fSSean Paul 				goto out;
7314551789fSSean Paul 
7324551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1));
7334551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1));
7344551789fSSean Paul 			if (base != shadow)
7354551789fSSean Paul 				goto out;
7364551789fSSean Paul 		}
7374551789fSSean Paul 
7384551789fSSean Paul 		drm_handle_vblank(ctx->drm_dev, ctx->pipe);
7394551789fSSean Paul 		exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe);
7404551789fSSean Paul 
7414551789fSSean Paul 		/* set wait vsync event to zero and wake up queue. */
7424551789fSSean Paul 		if (atomic_read(&ctx->wait_vsync_event)) {
7434551789fSSean Paul 			atomic_set(&ctx->wait_vsync_event, 0);
7444551789fSSean Paul 			wake_up(&ctx->wait_vsync_queue);
7454551789fSSean Paul 		}
7464551789fSSean Paul 	}
7474551789fSSean Paul 
7484551789fSSean Paul out:
7494551789fSSean Paul 	/* clear interrupts */
7504551789fSSean Paul 	if (~val & MXR_INT_EN_VSYNC) {
7514551789fSSean Paul 		/* vsync interrupt use different bit for read and clear */
7524551789fSSean Paul 		val &= ~MXR_INT_EN_VSYNC;
7534551789fSSean Paul 		val |= MXR_INT_CLEAR_VSYNC;
7544551789fSSean Paul 	}
7554551789fSSean Paul 	mixer_reg_write(res, MXR_INT_STATUS, val);
7564551789fSSean Paul 
7574551789fSSean Paul 	spin_unlock(&res->reg_slock);
7584551789fSSean Paul 
7594551789fSSean Paul 	return IRQ_HANDLED;
7604551789fSSean Paul }
7614551789fSSean Paul 
7624551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx)
7634551789fSSean Paul {
7644551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
7654551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
7664551789fSSean Paul 	struct resource *res;
7674551789fSSean Paul 	int ret;
7684551789fSSean Paul 
7694551789fSSean Paul 	spin_lock_init(&mixer_res->reg_slock);
7704551789fSSean Paul 
7714551789fSSean Paul 	mixer_res->mixer = devm_clk_get(dev, "mixer");
7724551789fSSean Paul 	if (IS_ERR(mixer_res->mixer)) {
7734551789fSSean Paul 		dev_err(dev, "failed to get clock 'mixer'\n");
7744551789fSSean Paul 		return -ENODEV;
7754551789fSSean Paul 	}
7764551789fSSean Paul 
7774551789fSSean Paul 	mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
7784551789fSSean Paul 	if (IS_ERR(mixer_res->sclk_hdmi)) {
7794551789fSSean Paul 		dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
7804551789fSSean Paul 		return -ENODEV;
7814551789fSSean Paul 	}
7824551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
7834551789fSSean Paul 	if (res == NULL) {
7844551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
7854551789fSSean Paul 		return -ENXIO;
7864551789fSSean Paul 	}
7874551789fSSean Paul 
7884551789fSSean Paul 	mixer_res->mixer_regs = devm_ioremap(dev, res->start,
7894551789fSSean Paul 							resource_size(res));
7904551789fSSean Paul 	if (mixer_res->mixer_regs == NULL) {
7914551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
7924551789fSSean Paul 		return -ENXIO;
7934551789fSSean Paul 	}
7944551789fSSean Paul 
7954551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0);
7964551789fSSean Paul 	if (res == NULL) {
7974551789fSSean Paul 		dev_err(dev, "get interrupt resource failed.\n");
7984551789fSSean Paul 		return -ENXIO;
7994551789fSSean Paul 	}
8004551789fSSean Paul 
8014551789fSSean Paul 	ret = devm_request_irq(dev, res->start, mixer_irq_handler,
8024551789fSSean Paul 						0, "drm_mixer", mixer_ctx);
8034551789fSSean Paul 	if (ret) {
8044551789fSSean Paul 		dev_err(dev, "request interrupt failed.\n");
8054551789fSSean Paul 		return ret;
8064551789fSSean Paul 	}
8074551789fSSean Paul 	mixer_res->irq = res->start;
8084551789fSSean Paul 
8094551789fSSean Paul 	return 0;
8104551789fSSean Paul }
8114551789fSSean Paul 
8124551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx)
8134551789fSSean Paul {
8144551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
8154551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
8164551789fSSean Paul 	struct resource *res;
8174551789fSSean Paul 
8184551789fSSean Paul 	mixer_res->vp = devm_clk_get(dev, "vp");
8194551789fSSean Paul 	if (IS_ERR(mixer_res->vp)) {
8204551789fSSean Paul 		dev_err(dev, "failed to get clock 'vp'\n");
8214551789fSSean Paul 		return -ENODEV;
8224551789fSSean Paul 	}
823ff830c96SMarek Szyprowski 
824ff830c96SMarek Szyprowski 	if (mixer_ctx->has_sclk) {
8254551789fSSean Paul 		mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
8264551789fSSean Paul 		if (IS_ERR(mixer_res->sclk_mixer)) {
8274551789fSSean Paul 			dev_err(dev, "failed to get clock 'sclk_mixer'\n");
8284551789fSSean Paul 			return -ENODEV;
8294551789fSSean Paul 		}
830ff830c96SMarek Szyprowski 		mixer_res->mout_mixer = devm_clk_get(dev, "mout_mixer");
831ff830c96SMarek Szyprowski 		if (IS_ERR(mixer_res->mout_mixer)) {
832ff830c96SMarek Szyprowski 			dev_err(dev, "failed to get clock 'mout_mixer'\n");
8334551789fSSean Paul 			return -ENODEV;
8344551789fSSean Paul 		}
8354551789fSSean Paul 
836ff830c96SMarek Szyprowski 		if (mixer_res->sclk_hdmi && mixer_res->mout_mixer)
837ff830c96SMarek Szyprowski 			clk_set_parent(mixer_res->mout_mixer,
838ff830c96SMarek Szyprowski 				       mixer_res->sclk_hdmi);
839ff830c96SMarek Szyprowski 	}
8404551789fSSean Paul 
8414551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
8424551789fSSean Paul 	if (res == NULL) {
8434551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8444551789fSSean Paul 		return -ENXIO;
8454551789fSSean Paul 	}
8464551789fSSean Paul 
8474551789fSSean Paul 	mixer_res->vp_regs = devm_ioremap(dev, res->start,
8484551789fSSean Paul 							resource_size(res));
8494551789fSSean Paul 	if (mixer_res->vp_regs == NULL) {
8504551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8514551789fSSean Paul 		return -ENXIO;
8524551789fSSean Paul 	}
8534551789fSSean Paul 
8544551789fSSean Paul 	return 0;
8554551789fSSean Paul }
8564551789fSSean Paul 
857f041b257SSean Paul static int mixer_initialize(struct exynos_drm_manager *mgr,
858f37cd5e8SInki Dae 			struct drm_device *drm_dev)
8594551789fSSean Paul {
8604551789fSSean Paul 	int ret;
8618f0be830SAndrzej Hajda 	struct mixer_context *mixer_ctx = mgr_to_mixer(mgr);
862f37cd5e8SInki Dae 	struct exynos_drm_private *priv;
863f37cd5e8SInki Dae 	priv = drm_dev->dev_private;
8644551789fSSean Paul 
865f37cd5e8SInki Dae 	mgr->drm_dev = mixer_ctx->drm_dev = drm_dev;
8668a326eddSGustavo Padovan 	mixer_ctx->pipe = priv->pipe++;
8674551789fSSean Paul 
8684551789fSSean Paul 	/* acquire resources: regs, irqs, clocks */
8694551789fSSean Paul 	ret = mixer_resources_init(mixer_ctx);
8704551789fSSean Paul 	if (ret) {
8714551789fSSean Paul 		DRM_ERROR("mixer_resources_init failed ret=%d\n", ret);
8724551789fSSean Paul 		return ret;
8734551789fSSean Paul 	}
8744551789fSSean Paul 
8754551789fSSean Paul 	if (mixer_ctx->vp_enabled) {
8764551789fSSean Paul 		/* acquire vp resources: regs, irqs, clocks */
8774551789fSSean Paul 		ret = vp_resources_init(mixer_ctx);
8784551789fSSean Paul 		if (ret) {
8794551789fSSean Paul 			DRM_ERROR("vp_resources_init failed ret=%d\n", ret);
8804551789fSSean Paul 			return ret;
8814551789fSSean Paul 		}
8824551789fSSean Paul 	}
8834551789fSSean Paul 
884f041b257SSean Paul 	if (!is_drm_iommu_supported(mixer_ctx->drm_dev))
8851055b39fSInki Dae 		return 0;
886f041b257SSean Paul 
887f041b257SSean Paul 	return drm_iommu_attach_device(mixer_ctx->drm_dev, mixer_ctx->dev);
8881055b39fSInki Dae }
8891055b39fSInki Dae 
890f041b257SSean Paul static void mixer_mgr_remove(struct exynos_drm_manager *mgr)
891d8408326SSeung-Woo Kim {
8928f0be830SAndrzej Hajda 	struct mixer_context *mixer_ctx = mgr_to_mixer(mgr);
893f041b257SSean Paul 
894f041b257SSean Paul 	if (is_drm_iommu_supported(mixer_ctx->drm_dev))
895f041b257SSean Paul 		drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev);
896f041b257SSean Paul }
897f041b257SSean Paul 
898f041b257SSean Paul static int mixer_enable_vblank(struct exynos_drm_manager *mgr)
899f041b257SSean Paul {
9008f0be830SAndrzej Hajda 	struct mixer_context *mixer_ctx = mgr_to_mixer(mgr);
901d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
902d8408326SSeung-Woo Kim 
903f041b257SSean Paul 	if (!mixer_ctx->powered) {
904f041b257SSean Paul 		mixer_ctx->int_en |= MXR_INT_EN_VSYNC;
905f041b257SSean Paul 		return 0;
906f041b257SSean Paul 	}
907d8408326SSeung-Woo Kim 
908d8408326SSeung-Woo Kim 	/* enable vsync interrupt */
909d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_INT_EN, MXR_INT_EN_VSYNC,
910d8408326SSeung-Woo Kim 			MXR_INT_EN_VSYNC);
911d8408326SSeung-Woo Kim 
912d8408326SSeung-Woo Kim 	return 0;
913d8408326SSeung-Woo Kim }
914d8408326SSeung-Woo Kim 
915f041b257SSean Paul static void mixer_disable_vblank(struct exynos_drm_manager *mgr)
916d8408326SSeung-Woo Kim {
9178f0be830SAndrzej Hajda 	struct mixer_context *mixer_ctx = mgr_to_mixer(mgr);
918d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
919d8408326SSeung-Woo Kim 
920d8408326SSeung-Woo Kim 	/* disable vsync interrupt */
921d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
922d8408326SSeung-Woo Kim }
923d8408326SSeung-Woo Kim 
924f041b257SSean Paul static void mixer_win_mode_set(struct exynos_drm_manager *mgr,
9258837deeaSGustavo Padovan 			struct exynos_drm_plane *plane)
926d8408326SSeung-Woo Kim {
9278f0be830SAndrzej Hajda 	struct mixer_context *mixer_ctx = mgr_to_mixer(mgr);
928d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
929d8408326SSeung-Woo Kim 	int win;
930d8408326SSeung-Woo Kim 
9318837deeaSGustavo Padovan 	if (!plane) {
9328837deeaSGustavo Padovan 		DRM_ERROR("plane is NULL\n");
933d8408326SSeung-Woo Kim 		return;
934d8408326SSeung-Woo Kim 	}
935d8408326SSeung-Woo Kim 
936d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS("set [%d]x[%d] at (%d,%d) to [%d]x[%d] at (%d,%d)\n",
9378837deeaSGustavo Padovan 				 plane->fb_width, plane->fb_height,
9388837deeaSGustavo Padovan 				 plane->fb_x, plane->fb_y,
9398837deeaSGustavo Padovan 				 plane->crtc_width, plane->crtc_height,
9408837deeaSGustavo Padovan 				 plane->crtc_x, plane->crtc_y);
941d8408326SSeung-Woo Kim 
9428837deeaSGustavo Padovan 	win = plane->zpos;
943d8408326SSeung-Woo Kim 	if (win == DEFAULT_ZPOS)
944a2ee151bSJoonyoung Shim 		win = MIXER_DEFAULT_WIN;
945d8408326SSeung-Woo Kim 
9461586d80cSKrzysztof Kozlowski 	if (win < 0 || win >= MIXER_WIN_NR) {
947cf8fc4f1SJoonyoung Shim 		DRM_ERROR("mixer window[%d] is wrong\n", win);
948d8408326SSeung-Woo Kim 		return;
949d8408326SSeung-Woo Kim 	}
950d8408326SSeung-Woo Kim 
951d8408326SSeung-Woo Kim 	win_data = &mixer_ctx->win_data[win];
952d8408326SSeung-Woo Kim 
9538837deeaSGustavo Padovan 	win_data->dma_addr = plane->dma_addr[0];
9548837deeaSGustavo Padovan 	win_data->chroma_dma_addr = plane->dma_addr[1];
9558837deeaSGustavo Padovan 	win_data->pixel_format = plane->pixel_format;
9568837deeaSGustavo Padovan 	win_data->bpp = plane->bpp;
957d8408326SSeung-Woo Kim 
9588837deeaSGustavo Padovan 	win_data->crtc_x = plane->crtc_x;
9598837deeaSGustavo Padovan 	win_data->crtc_y = plane->crtc_y;
9608837deeaSGustavo Padovan 	win_data->crtc_width = plane->crtc_width;
9618837deeaSGustavo Padovan 	win_data->crtc_height = plane->crtc_height;
962d8408326SSeung-Woo Kim 
9638837deeaSGustavo Padovan 	win_data->fb_x = plane->fb_x;
9648837deeaSGustavo Padovan 	win_data->fb_y = plane->fb_y;
9658837deeaSGustavo Padovan 	win_data->fb_width = plane->fb_width;
9668837deeaSGustavo Padovan 	win_data->fb_height = plane->fb_height;
9678837deeaSGustavo Padovan 	win_data->src_width = plane->src_width;
9688837deeaSGustavo Padovan 	win_data->src_height = plane->src_height;
969d8408326SSeung-Woo Kim 
9708837deeaSGustavo Padovan 	win_data->mode_width = plane->mode_width;
9718837deeaSGustavo Padovan 	win_data->mode_height = plane->mode_height;
972d8408326SSeung-Woo Kim 
9738837deeaSGustavo Padovan 	win_data->scan_flags = plane->scan_flag;
974d8408326SSeung-Woo Kim }
975d8408326SSeung-Woo Kim 
976f041b257SSean Paul static void mixer_win_commit(struct exynos_drm_manager *mgr, int zpos)
977d8408326SSeung-Woo Kim {
9788f0be830SAndrzej Hajda 	struct mixer_context *mixer_ctx = mgr_to_mixer(mgr);
979f041b257SSean Paul 	int win = zpos == DEFAULT_ZPOS ? MIXER_DEFAULT_WIN : zpos;
980d8408326SSeung-Woo Kim 
981cbc4c33dSYoungJun Cho 	DRM_DEBUG_KMS("win: %d\n", win);
982d8408326SSeung-Woo Kim 
983dda9012bSShirish S 	mutex_lock(&mixer_ctx->mixer_mutex);
984dda9012bSShirish S 	if (!mixer_ctx->powered) {
985dda9012bSShirish S 		mutex_unlock(&mixer_ctx->mixer_mutex);
986dda9012bSShirish S 		return;
987dda9012bSShirish S 	}
988dda9012bSShirish S 	mutex_unlock(&mixer_ctx->mixer_mutex);
989dda9012bSShirish S 
9901b8e5747SRahul Sharma 	if (win > 1 && mixer_ctx->vp_enabled)
991d8408326SSeung-Woo Kim 		vp_video_buffer(mixer_ctx, win);
992d8408326SSeung-Woo Kim 	else
993d8408326SSeung-Woo Kim 		mixer_graph_buffer(mixer_ctx, win);
994db43fd16SPrathyush K 
995db43fd16SPrathyush K 	mixer_ctx->win_data[win].enabled = true;
996d8408326SSeung-Woo Kim }
997d8408326SSeung-Woo Kim 
998f041b257SSean Paul static void mixer_win_disable(struct exynos_drm_manager *mgr, int zpos)
999d8408326SSeung-Woo Kim {
10008f0be830SAndrzej Hajda 	struct mixer_context *mixer_ctx = mgr_to_mixer(mgr);
1001d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
1002f041b257SSean Paul 	int win = zpos == DEFAULT_ZPOS ? MIXER_DEFAULT_WIN : zpos;
1003d8408326SSeung-Woo Kim 	unsigned long flags;
1004d8408326SSeung-Woo Kim 
1005cbc4c33dSYoungJun Cho 	DRM_DEBUG_KMS("win: %d\n", win);
1006d8408326SSeung-Woo Kim 
1007db43fd16SPrathyush K 	mutex_lock(&mixer_ctx->mixer_mutex);
1008db43fd16SPrathyush K 	if (!mixer_ctx->powered) {
1009db43fd16SPrathyush K 		mutex_unlock(&mixer_ctx->mixer_mutex);
1010db43fd16SPrathyush K 		mixer_ctx->win_data[win].resume = false;
1011db43fd16SPrathyush K 		return;
1012db43fd16SPrathyush K 	}
1013db43fd16SPrathyush K 	mutex_unlock(&mixer_ctx->mixer_mutex);
1014db43fd16SPrathyush K 
1015d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
1016d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, false);
1017d8408326SSeung-Woo Kim 
1018d8408326SSeung-Woo Kim 	mixer_cfg_layer(mixer_ctx, win, false);
1019d8408326SSeung-Woo Kim 
1020d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, true);
1021d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
1022db43fd16SPrathyush K 
1023db43fd16SPrathyush K 	mixer_ctx->win_data[win].enabled = false;
1024d8408326SSeung-Woo Kim }
1025d8408326SSeung-Woo Kim 
1026f041b257SSean Paul static void mixer_wait_for_vblank(struct exynos_drm_manager *mgr)
10270ea6822fSRahul Sharma {
10288f0be830SAndrzej Hajda 	struct mixer_context *mixer_ctx = mgr_to_mixer(mgr);
10297c4c5584SJoonyoung Shim 	int err;
10308137a2e2SPrathyush K 
10316e95d5e6SPrathyush K 	mutex_lock(&mixer_ctx->mixer_mutex);
10326e95d5e6SPrathyush K 	if (!mixer_ctx->powered) {
10336e95d5e6SPrathyush K 		mutex_unlock(&mixer_ctx->mixer_mutex);
10346e95d5e6SPrathyush K 		return;
10356e95d5e6SPrathyush K 	}
10366e95d5e6SPrathyush K 	mutex_unlock(&mixer_ctx->mixer_mutex);
10376e95d5e6SPrathyush K 
10387c4c5584SJoonyoung Shim 	err = drm_vblank_get(mgr->crtc->dev, mixer_ctx->pipe);
10397c4c5584SJoonyoung Shim 	if (err < 0) {
10407c4c5584SJoonyoung Shim 		DRM_DEBUG_KMS("failed to acquire vblank counter\n");
10417c4c5584SJoonyoung Shim 		return;
10427c4c5584SJoonyoung Shim 	}
10435d39b9eeSRahul Sharma 
10446e95d5e6SPrathyush K 	atomic_set(&mixer_ctx->wait_vsync_event, 1);
10456e95d5e6SPrathyush K 
10466e95d5e6SPrathyush K 	/*
10476e95d5e6SPrathyush K 	 * wait for MIXER to signal VSYNC interrupt or return after
10486e95d5e6SPrathyush K 	 * timeout which is set to 50ms (refresh rate of 20).
10496e95d5e6SPrathyush K 	 */
10506e95d5e6SPrathyush K 	if (!wait_event_timeout(mixer_ctx->wait_vsync_queue,
10516e95d5e6SPrathyush K 				!atomic_read(&mixer_ctx->wait_vsync_event),
1052bfd8303aSDaniel Vetter 				HZ/20))
10538137a2e2SPrathyush K 		DRM_DEBUG_KMS("vblank wait timed out.\n");
10545d39b9eeSRahul Sharma 
10555d39b9eeSRahul Sharma 	drm_vblank_put(mgr->crtc->dev, mixer_ctx->pipe);
10568137a2e2SPrathyush K }
10578137a2e2SPrathyush K 
1058f041b257SSean Paul static void mixer_window_suspend(struct exynos_drm_manager *mgr)
1059db43fd16SPrathyush K {
10608f0be830SAndrzej Hajda 	struct mixer_context *ctx = mgr_to_mixer(mgr);
1061db43fd16SPrathyush K 	struct hdmi_win_data *win_data;
1062db43fd16SPrathyush K 	int i;
1063db43fd16SPrathyush K 
1064db43fd16SPrathyush K 	for (i = 0; i < MIXER_WIN_NR; i++) {
1065db43fd16SPrathyush K 		win_data = &ctx->win_data[i];
1066db43fd16SPrathyush K 		win_data->resume = win_data->enabled;
1067f041b257SSean Paul 		mixer_win_disable(mgr, i);
1068db43fd16SPrathyush K 	}
1069f041b257SSean Paul 	mixer_wait_for_vblank(mgr);
1070db43fd16SPrathyush K }
1071db43fd16SPrathyush K 
1072f041b257SSean Paul static void mixer_window_resume(struct exynos_drm_manager *mgr)
1073db43fd16SPrathyush K {
10748f0be830SAndrzej Hajda 	struct mixer_context *ctx = mgr_to_mixer(mgr);
1075db43fd16SPrathyush K 	struct hdmi_win_data *win_data;
1076db43fd16SPrathyush K 	int i;
1077db43fd16SPrathyush K 
1078db43fd16SPrathyush K 	for (i = 0; i < MIXER_WIN_NR; i++) {
1079db43fd16SPrathyush K 		win_data = &ctx->win_data[i];
1080db43fd16SPrathyush K 		win_data->enabled = win_data->resume;
1081db43fd16SPrathyush K 		win_data->resume = false;
108287244fa6SSean Paul 		if (win_data->enabled)
1083f041b257SSean Paul 			mixer_win_commit(mgr, i);
1084db43fd16SPrathyush K 	}
1085db43fd16SPrathyush K }
1086db43fd16SPrathyush K 
1087f041b257SSean Paul static void mixer_poweron(struct exynos_drm_manager *mgr)
1088db43fd16SPrathyush K {
10898f0be830SAndrzej Hajda 	struct mixer_context *ctx = mgr_to_mixer(mgr);
1090db43fd16SPrathyush K 	struct mixer_resources *res = &ctx->mixer_res;
1091db43fd16SPrathyush K 
1092db43fd16SPrathyush K 	mutex_lock(&ctx->mixer_mutex);
1093db43fd16SPrathyush K 	if (ctx->powered) {
1094db43fd16SPrathyush K 		mutex_unlock(&ctx->mixer_mutex);
1095db43fd16SPrathyush K 		return;
1096db43fd16SPrathyush K 	}
1097b4bfa3c7SRahul Sharma 
1098db43fd16SPrathyush K 	mutex_unlock(&ctx->mixer_mutex);
1099db43fd16SPrathyush K 
1100af65c804SSean Paul 	pm_runtime_get_sync(ctx->dev);
1101af65c804SSean Paul 
11020bfb1f8bSSean Paul 	clk_prepare_enable(res->mixer);
1103db43fd16SPrathyush K 	if (ctx->vp_enabled) {
11040bfb1f8bSSean Paul 		clk_prepare_enable(res->vp);
1105ff830c96SMarek Szyprowski 		if (ctx->has_sclk)
11060bfb1f8bSSean Paul 			clk_prepare_enable(res->sclk_mixer);
1107db43fd16SPrathyush K 	}
1108db43fd16SPrathyush K 
1109b4bfa3c7SRahul Sharma 	mutex_lock(&ctx->mixer_mutex);
1110b4bfa3c7SRahul Sharma 	ctx->powered = true;
1111b4bfa3c7SRahul Sharma 	mutex_unlock(&ctx->mixer_mutex);
1112b4bfa3c7SRahul Sharma 
1113d74ed937SRahul Sharma 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
1114d74ed937SRahul Sharma 
1115db43fd16SPrathyush K 	mixer_reg_write(res, MXR_INT_EN, ctx->int_en);
1116db43fd16SPrathyush K 	mixer_win_reset(ctx);
1117db43fd16SPrathyush K 
1118f041b257SSean Paul 	mixer_window_resume(mgr);
1119db43fd16SPrathyush K }
1120db43fd16SPrathyush K 
1121f041b257SSean Paul static void mixer_poweroff(struct exynos_drm_manager *mgr)
1122db43fd16SPrathyush K {
11238f0be830SAndrzej Hajda 	struct mixer_context *ctx = mgr_to_mixer(mgr);
1124db43fd16SPrathyush K 	struct mixer_resources *res = &ctx->mixer_res;
1125db43fd16SPrathyush K 
1126db43fd16SPrathyush K 	mutex_lock(&ctx->mixer_mutex);
1127b4bfa3c7SRahul Sharma 	if (!ctx->powered) {
1128b4bfa3c7SRahul Sharma 		mutex_unlock(&ctx->mixer_mutex);
1129b4bfa3c7SRahul Sharma 		return;
1130b4bfa3c7SRahul Sharma 	}
1131db43fd16SPrathyush K 	mutex_unlock(&ctx->mixer_mutex);
1132db43fd16SPrathyush K 
1133381be025SRahul Sharma 	mixer_stop(ctx);
1134f041b257SSean Paul 	mixer_window_suspend(mgr);
1135db43fd16SPrathyush K 
1136db43fd16SPrathyush K 	ctx->int_en = mixer_reg_read(res, MXR_INT_EN);
1137db43fd16SPrathyush K 
1138b4bfa3c7SRahul Sharma 	mutex_lock(&ctx->mixer_mutex);
1139b4bfa3c7SRahul Sharma 	ctx->powered = false;
1140b4bfa3c7SRahul Sharma 	mutex_unlock(&ctx->mixer_mutex);
1141b4bfa3c7SRahul Sharma 
11420bfb1f8bSSean Paul 	clk_disable_unprepare(res->mixer);
1143db43fd16SPrathyush K 	if (ctx->vp_enabled) {
11440bfb1f8bSSean Paul 		clk_disable_unprepare(res->vp);
1145ff830c96SMarek Szyprowski 		if (ctx->has_sclk)
11460bfb1f8bSSean Paul 			clk_disable_unprepare(res->sclk_mixer);
1147db43fd16SPrathyush K 	}
1148db43fd16SPrathyush K 
1149af65c804SSean Paul 	pm_runtime_put_sync(ctx->dev);
1150db43fd16SPrathyush K }
1151db43fd16SPrathyush K 
1152f041b257SSean Paul static void mixer_dpms(struct exynos_drm_manager *mgr, int mode)
1153db43fd16SPrathyush K {
1154db43fd16SPrathyush K 	switch (mode) {
1155db43fd16SPrathyush K 	case DRM_MODE_DPMS_ON:
1156af65c804SSean Paul 		mixer_poweron(mgr);
1157db43fd16SPrathyush K 		break;
1158db43fd16SPrathyush K 	case DRM_MODE_DPMS_STANDBY:
1159db43fd16SPrathyush K 	case DRM_MODE_DPMS_SUSPEND:
1160db43fd16SPrathyush K 	case DRM_MODE_DPMS_OFF:
1161af65c804SSean Paul 		mixer_poweroff(mgr);
1162db43fd16SPrathyush K 		break;
1163db43fd16SPrathyush K 	default:
1164db43fd16SPrathyush K 		DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode);
1165db43fd16SPrathyush K 		break;
1166db43fd16SPrathyush K 	}
1167db43fd16SPrathyush K }
1168db43fd16SPrathyush K 
1169f041b257SSean Paul /* Only valid for Mixer version 16.0.33.0 */
1170f041b257SSean Paul int mixer_check_mode(struct drm_display_mode *mode)
1171f041b257SSean Paul {
1172f041b257SSean Paul 	u32 w, h;
1173f041b257SSean Paul 
1174f041b257SSean Paul 	w = mode->hdisplay;
1175f041b257SSean Paul 	h = mode->vdisplay;
1176f041b257SSean Paul 
1177f041b257SSean Paul 	DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n",
1178f041b257SSean Paul 		mode->hdisplay, mode->vdisplay, mode->vrefresh,
1179f041b257SSean Paul 		(mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
1180f041b257SSean Paul 
1181f041b257SSean Paul 	if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
1182f041b257SSean Paul 		(w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
1183f041b257SSean Paul 		(w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
1184f041b257SSean Paul 		return 0;
1185f041b257SSean Paul 
1186f041b257SSean Paul 	return -EINVAL;
1187f041b257SSean Paul }
1188f041b257SSean Paul 
1189f041b257SSean Paul static struct exynos_drm_manager_ops mixer_manager_ops = {
1190f041b257SSean Paul 	.dpms			= mixer_dpms,
1191d8408326SSeung-Woo Kim 	.enable_vblank		= mixer_enable_vblank,
1192d8408326SSeung-Woo Kim 	.disable_vblank		= mixer_disable_vblank,
11938137a2e2SPrathyush K 	.wait_for_vblank	= mixer_wait_for_vblank,
1194d8408326SSeung-Woo Kim 	.win_mode_set		= mixer_win_mode_set,
1195d8408326SSeung-Woo Kim 	.win_commit		= mixer_win_commit,
1196d8408326SSeung-Woo Kim 	.win_disable		= mixer_win_disable,
1197f041b257SSean Paul };
11980ea6822fSRahul Sharma 
1199def5e095SRahul Sharma static struct mixer_drv_data exynos5420_mxr_drv_data = {
1200def5e095SRahul Sharma 	.version = MXR_VER_128_0_0_184,
1201def5e095SRahul Sharma 	.is_vp_enabled = 0,
1202def5e095SRahul Sharma };
1203def5e095SRahul Sharma 
1204cc57caf0SRahul Sharma static struct mixer_drv_data exynos5250_mxr_drv_data = {
1205aaf8b49eSRahul Sharma 	.version = MXR_VER_16_0_33_0,
1206aaf8b49eSRahul Sharma 	.is_vp_enabled = 0,
1207aaf8b49eSRahul Sharma };
1208aaf8b49eSRahul Sharma 
1209ff830c96SMarek Szyprowski static struct mixer_drv_data exynos4212_mxr_drv_data = {
1210ff830c96SMarek Szyprowski 	.version = MXR_VER_0_0_0_16,
1211ff830c96SMarek Szyprowski 	.is_vp_enabled = 1,
1212ff830c96SMarek Szyprowski };
1213ff830c96SMarek Szyprowski 
1214cc57caf0SRahul Sharma static struct mixer_drv_data exynos4210_mxr_drv_data = {
12151e123441SRahul Sharma 	.version = MXR_VER_0_0_0_16,
12161b8e5747SRahul Sharma 	.is_vp_enabled = 1,
1217ff830c96SMarek Szyprowski 	.has_sclk = 1,
12181e123441SRahul Sharma };
12191e123441SRahul Sharma 
12201e123441SRahul Sharma static struct platform_device_id mixer_driver_types[] = {
12211e123441SRahul Sharma 	{
12221e123441SRahul Sharma 		.name		= "s5p-mixer",
1223cc57caf0SRahul Sharma 		.driver_data	= (unsigned long)&exynos4210_mxr_drv_data,
12241e123441SRahul Sharma 	}, {
1225aaf8b49eSRahul Sharma 		.name		= "exynos5-mixer",
1226cc57caf0SRahul Sharma 		.driver_data	= (unsigned long)&exynos5250_mxr_drv_data,
1227aaf8b49eSRahul Sharma 	}, {
1228aaf8b49eSRahul Sharma 		/* end node */
1229aaf8b49eSRahul Sharma 	}
1230aaf8b49eSRahul Sharma };
1231aaf8b49eSRahul Sharma 
1232aaf8b49eSRahul Sharma static struct of_device_id mixer_match_types[] = {
1233aaf8b49eSRahul Sharma 	{
1234ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4210-mixer",
1235ff830c96SMarek Szyprowski 		.data	= &exynos4210_mxr_drv_data,
1236ff830c96SMarek Szyprowski 	}, {
1237ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4212-mixer",
1238ff830c96SMarek Szyprowski 		.data	= &exynos4212_mxr_drv_data,
1239ff830c96SMarek Szyprowski 	}, {
1240aaf8b49eSRahul Sharma 		.compatible = "samsung,exynos5-mixer",
1241cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1242cc57caf0SRahul Sharma 	}, {
1243cc57caf0SRahul Sharma 		.compatible = "samsung,exynos5250-mixer",
1244cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1245aaf8b49eSRahul Sharma 	}, {
1246def5e095SRahul Sharma 		.compatible = "samsung,exynos5420-mixer",
1247def5e095SRahul Sharma 		.data	= &exynos5420_mxr_drv_data,
1248def5e095SRahul Sharma 	}, {
12491e123441SRahul Sharma 		/* end node */
12501e123441SRahul Sharma 	}
12511e123441SRahul Sharma };
125239b58a39SSjoerd Simons MODULE_DEVICE_TABLE(of, mixer_match_types);
12531e123441SRahul Sharma 
1254f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data)
1255d8408326SSeung-Woo Kim {
12568103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
1257f37cd5e8SInki Dae 	struct drm_device *drm_dev = data;
1258f37cd5e8SInki Dae 	int ret;
1259d8408326SSeung-Woo Kim 
12608103ef1bSAndrzej Hajda 	ret = mixer_initialize(&ctx->manager, drm_dev);
12618103ef1bSAndrzej Hajda 	if (ret)
12628103ef1bSAndrzej Hajda 		return ret;
12638103ef1bSAndrzej Hajda 
1264*5d1741adSGustavo Padovan 	ret = exynos_drm_crtc_create(&ctx->manager, ctx->pipe,
1265*5d1741adSGustavo Padovan 				     EXYNOS_DISPLAY_TYPE_HDMI);
12668103ef1bSAndrzej Hajda 	if (ret) {
12678103ef1bSAndrzej Hajda 		mixer_mgr_remove(&ctx->manager);
12688103ef1bSAndrzej Hajda 		return ret;
12698103ef1bSAndrzej Hajda 	}
12708103ef1bSAndrzej Hajda 
12718103ef1bSAndrzej Hajda 	return 0;
12728103ef1bSAndrzej Hajda }
12738103ef1bSAndrzej Hajda 
12748103ef1bSAndrzej Hajda static void mixer_unbind(struct device *dev, struct device *master, void *data)
12758103ef1bSAndrzej Hajda {
12768103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
12778103ef1bSAndrzej Hajda 
12788103ef1bSAndrzej Hajda 	mixer_mgr_remove(&ctx->manager);
12798103ef1bSAndrzej Hajda }
12808103ef1bSAndrzej Hajda 
12818103ef1bSAndrzej Hajda static const struct component_ops mixer_component_ops = {
12828103ef1bSAndrzej Hajda 	.bind	= mixer_bind,
12838103ef1bSAndrzej Hajda 	.unbind	= mixer_unbind,
12848103ef1bSAndrzej Hajda };
12858103ef1bSAndrzej Hajda 
12868103ef1bSAndrzej Hajda static int mixer_probe(struct platform_device *pdev)
12878103ef1bSAndrzej Hajda {
12888103ef1bSAndrzej Hajda 	struct device *dev = &pdev->dev;
12898103ef1bSAndrzej Hajda 	struct mixer_drv_data *drv;
12908103ef1bSAndrzej Hajda 	struct mixer_context *ctx;
12918103ef1bSAndrzej Hajda 	int ret;
1292d8408326SSeung-Woo Kim 
1293f041b257SSean Paul 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1294f041b257SSean Paul 	if (!ctx) {
1295f041b257SSean Paul 		DRM_ERROR("failed to alloc mixer context.\n");
1296d8408326SSeung-Woo Kim 		return -ENOMEM;
1297f041b257SSean Paul 	}
1298d8408326SSeung-Woo Kim 
1299cf8fc4f1SJoonyoung Shim 	mutex_init(&ctx->mixer_mutex);
1300cf8fc4f1SJoonyoung Shim 
13018103ef1bSAndrzej Hajda 	ctx->manager.ops = &mixer_manager_ops;
13028103ef1bSAndrzej Hajda 
1303aaf8b49eSRahul Sharma 	if (dev->of_node) {
1304aaf8b49eSRahul Sharma 		const struct of_device_id *match;
13058103ef1bSAndrzej Hajda 
1306e436b09dSSachin Kamat 		match = of_match_node(mixer_match_types, dev->of_node);
13072cdc53b3SRahul Sharma 		drv = (struct mixer_drv_data *)match->data;
1308aaf8b49eSRahul Sharma 	} else {
1309aaf8b49eSRahul Sharma 		drv = (struct mixer_drv_data *)
1310aaf8b49eSRahul Sharma 			platform_get_device_id(pdev)->driver_data;
1311aaf8b49eSRahul Sharma 	}
1312aaf8b49eSRahul Sharma 
13134551789fSSean Paul 	ctx->pdev = pdev;
1314d873ab99SSeung-Woo Kim 	ctx->dev = dev;
13151b8e5747SRahul Sharma 	ctx->vp_enabled = drv->is_vp_enabled;
1316ff830c96SMarek Szyprowski 	ctx->has_sclk = drv->has_sclk;
13171e123441SRahul Sharma 	ctx->mxr_ver = drv->version;
131857ed0f7bSDaniel Vetter 	init_waitqueue_head(&ctx->wait_vsync_queue);
13196e95d5e6SPrathyush K 	atomic_set(&ctx->wait_vsync_event, 0);
1320d8408326SSeung-Woo Kim 
13218103ef1bSAndrzej Hajda 	platform_set_drvdata(pdev, ctx);
1322df5225bcSInki Dae 
1323df5225bcSInki Dae 	ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC,
1324*5d1741adSGustavo Padovan 					EXYNOS_DISPLAY_TYPE_HDMI);
1325df5225bcSInki Dae 	if (ret)
1326df5225bcSInki Dae 		return ret;
1327df5225bcSInki Dae 
1328df5225bcSInki Dae 	ret = component_add(&pdev->dev, &mixer_component_ops);
13298103ef1bSAndrzej Hajda 	if (ret) {
1330df5225bcSInki Dae 		exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC);
13318103ef1bSAndrzej Hajda 		return ret;
13328103ef1bSAndrzej Hajda 	}
13338103ef1bSAndrzej Hajda 
13348103ef1bSAndrzej Hajda 	pm_runtime_enable(dev);
1335df5225bcSInki Dae 
1336df5225bcSInki Dae 	return ret;
1337f37cd5e8SInki Dae }
1338f37cd5e8SInki Dae 
1339d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev)
1340d8408326SSeung-Woo Kim {
13418103ef1bSAndrzej Hajda 	pm_runtime_disable(&pdev->dev);
13428103ef1bSAndrzej Hajda 
1343df5225bcSInki Dae 	component_del(&pdev->dev, &mixer_component_ops);
1344df5225bcSInki Dae 	exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC);
1345df5225bcSInki Dae 
1346d8408326SSeung-Woo Kim 	return 0;
1347d8408326SSeung-Woo Kim }
1348d8408326SSeung-Woo Kim 
1349d8408326SSeung-Woo Kim struct platform_driver mixer_driver = {
1350d8408326SSeung-Woo Kim 	.driver = {
1351aaf8b49eSRahul Sharma 		.name = "exynos-mixer",
1352d8408326SSeung-Woo Kim 		.owner = THIS_MODULE,
1353aaf8b49eSRahul Sharma 		.of_match_table = mixer_match_types,
1354d8408326SSeung-Woo Kim 	},
1355d8408326SSeung-Woo Kim 	.probe = mixer_probe,
135656550d94SGreg Kroah-Hartman 	.remove = mixer_remove,
13571e123441SRahul Sharma 	.id_table	= mixer_driver_types,
1358d8408326SSeung-Woo Kim };
1359