xref: /linux/drivers/gpu/drm/exynos/exynos_mixer.c (revision ff830c961d44cd0b3cf483a6c7a5a175c3419427)
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 get_mixer_manager(dev)	platform_get_drvdata(to_platform_device(dev))
44f041b257SSean Paul 
45f041b257SSean Paul #define MIXER_WIN_NR		3
46f041b257SSean Paul #define MIXER_DEFAULT_WIN	0
47d8408326SSeung-Woo Kim 
4822b21ae6SJoonyoung Shim struct hdmi_win_data {
4922b21ae6SJoonyoung Shim 	dma_addr_t		dma_addr;
5022b21ae6SJoonyoung Shim 	dma_addr_t		chroma_dma_addr;
5122b21ae6SJoonyoung Shim 	uint32_t		pixel_format;
5222b21ae6SJoonyoung Shim 	unsigned int		bpp;
5322b21ae6SJoonyoung Shim 	unsigned int		crtc_x;
5422b21ae6SJoonyoung Shim 	unsigned int		crtc_y;
5522b21ae6SJoonyoung Shim 	unsigned int		crtc_width;
5622b21ae6SJoonyoung Shim 	unsigned int		crtc_height;
5722b21ae6SJoonyoung Shim 	unsigned int		fb_x;
5822b21ae6SJoonyoung Shim 	unsigned int		fb_y;
5922b21ae6SJoonyoung Shim 	unsigned int		fb_width;
6022b21ae6SJoonyoung Shim 	unsigned int		fb_height;
618dcb96b6SSeung-Woo Kim 	unsigned int		src_width;
628dcb96b6SSeung-Woo Kim 	unsigned int		src_height;
6322b21ae6SJoonyoung Shim 	unsigned int		mode_width;
6422b21ae6SJoonyoung Shim 	unsigned int		mode_height;
6522b21ae6SJoonyoung Shim 	unsigned int		scan_flags;
66db43fd16SPrathyush K 	bool			enabled;
67db43fd16SPrathyush K 	bool			resume;
6822b21ae6SJoonyoung Shim };
6922b21ae6SJoonyoung Shim 
7022b21ae6SJoonyoung Shim struct mixer_resources {
7122b21ae6SJoonyoung Shim 	int			irq;
7222b21ae6SJoonyoung Shim 	void __iomem		*mixer_regs;
7322b21ae6SJoonyoung Shim 	void __iomem		*vp_regs;
7422b21ae6SJoonyoung Shim 	spinlock_t		reg_slock;
7522b21ae6SJoonyoung Shim 	struct clk		*mixer;
7622b21ae6SJoonyoung Shim 	struct clk		*vp;
7722b21ae6SJoonyoung Shim 	struct clk		*sclk_mixer;
7822b21ae6SJoonyoung Shim 	struct clk		*sclk_hdmi;
79*ff830c96SMarek Szyprowski 	struct clk		*mout_mixer;
8022b21ae6SJoonyoung Shim };
8122b21ae6SJoonyoung Shim 
821e123441SRahul Sharma enum mixer_version_id {
831e123441SRahul Sharma 	MXR_VER_0_0_0_16,
841e123441SRahul Sharma 	MXR_VER_16_0_33_0,
85def5e095SRahul Sharma 	MXR_VER_128_0_0_184,
861e123441SRahul Sharma };
871e123441SRahul Sharma 
8822b21ae6SJoonyoung Shim struct mixer_context {
894551789fSSean Paul 	struct platform_device *pdev;
90cf8fc4f1SJoonyoung Shim 	struct device		*dev;
911055b39fSInki Dae 	struct drm_device	*drm_dev;
9222b21ae6SJoonyoung Shim 	int			pipe;
9322b21ae6SJoonyoung Shim 	bool			interlace;
94cf8fc4f1SJoonyoung Shim 	bool			powered;
951b8e5747SRahul Sharma 	bool			vp_enabled;
96*ff830c96SMarek Szyprowski 	bool			has_sclk;
97cf8fc4f1SJoonyoung Shim 	u32			int_en;
9822b21ae6SJoonyoung Shim 
99cf8fc4f1SJoonyoung Shim 	struct mutex		mixer_mutex;
10022b21ae6SJoonyoung Shim 	struct mixer_resources	mixer_res;
101a634dd54SJoonyoung Shim 	struct hdmi_win_data	win_data[MIXER_WIN_NR];
1021e123441SRahul Sharma 	enum mixer_version_id	mxr_ver;
1036e95d5e6SPrathyush K 	wait_queue_head_t	wait_vsync_queue;
1046e95d5e6SPrathyush K 	atomic_t		wait_vsync_event;
1051e123441SRahul Sharma };
1061e123441SRahul Sharma 
1071e123441SRahul Sharma struct mixer_drv_data {
1081e123441SRahul Sharma 	enum mixer_version_id	version;
1091b8e5747SRahul Sharma 	bool					is_vp_enabled;
110*ff830c96SMarek Szyprowski 	bool					has_sclk;
11122b21ae6SJoonyoung Shim };
11222b21ae6SJoonyoung Shim 
113d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = {
114d8408326SSeung-Woo Kim 	0,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
115d8408326SSeung-Woo Kim 	-1,	-1,	-1,	-1,	-1,	0,	0,	0,
116d8408326SSeung-Woo Kim 	0,	2,	4,	5,	6,	6,	6,	6,
117d8408326SSeung-Woo Kim 	6,	5,	5,	4,	3,	2,	1,	1,
118d8408326SSeung-Woo Kim 	0,	-6,	-12,	-16,	-18,	-20,	-21,	-20,
119d8408326SSeung-Woo Kim 	-20,	-18,	-16,	-13,	-10,	-8,	-5,	-2,
120d8408326SSeung-Woo Kim 	127,	126,	125,	121,	114,	107,	99,	89,
121d8408326SSeung-Woo Kim 	79,	68,	57,	46,	35,	25,	16,	8,
122d8408326SSeung-Woo Kim };
123d8408326SSeung-Woo Kim 
124d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = {
125d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
126d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
127d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
128d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
129d8408326SSeung-Woo Kim 	0,	5,	11,	19,	27,	37,	48,	59,
130d8408326SSeung-Woo Kim 	70,	81,	92,	102,	111,	118,	124,	126,
131d8408326SSeung-Woo Kim 	0,	0,	-1,	-1,	-2,	-3,	-4,	-5,
132d8408326SSeung-Woo Kim 	-6,	-7,	-8,	-8,	-8,	-8,	-6,	-3,
133d8408326SSeung-Woo Kim };
134d8408326SSeung-Woo Kim 
135d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = {
136d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
137d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
138d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
139d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
140d8408326SSeung-Woo Kim };
141d8408326SSeung-Woo Kim 
142d8408326SSeung-Woo Kim static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id)
143d8408326SSeung-Woo Kim {
144d8408326SSeung-Woo Kim 	return readl(res->vp_regs + reg_id);
145d8408326SSeung-Woo Kim }
146d8408326SSeung-Woo Kim 
147d8408326SSeung-Woo Kim static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id,
148d8408326SSeung-Woo Kim 				 u32 val)
149d8408326SSeung-Woo Kim {
150d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
151d8408326SSeung-Woo Kim }
152d8408326SSeung-Woo Kim 
153d8408326SSeung-Woo Kim static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id,
154d8408326SSeung-Woo Kim 				 u32 val, u32 mask)
155d8408326SSeung-Woo Kim {
156d8408326SSeung-Woo Kim 	u32 old = vp_reg_read(res, reg_id);
157d8408326SSeung-Woo Kim 
158d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
159d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
160d8408326SSeung-Woo Kim }
161d8408326SSeung-Woo Kim 
162d8408326SSeung-Woo Kim static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id)
163d8408326SSeung-Woo Kim {
164d8408326SSeung-Woo Kim 	return readl(res->mixer_regs + reg_id);
165d8408326SSeung-Woo Kim }
166d8408326SSeung-Woo Kim 
167d8408326SSeung-Woo Kim static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id,
168d8408326SSeung-Woo Kim 				 u32 val)
169d8408326SSeung-Woo Kim {
170d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
171d8408326SSeung-Woo Kim }
172d8408326SSeung-Woo Kim 
173d8408326SSeung-Woo Kim static inline void mixer_reg_writemask(struct mixer_resources *res,
174d8408326SSeung-Woo Kim 				 u32 reg_id, u32 val, u32 mask)
175d8408326SSeung-Woo Kim {
176d8408326SSeung-Woo Kim 	u32 old = mixer_reg_read(res, reg_id);
177d8408326SSeung-Woo Kim 
178d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
179d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
180d8408326SSeung-Woo Kim }
181d8408326SSeung-Woo Kim 
182d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx)
183d8408326SSeung-Woo Kim {
184d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
185d8408326SSeung-Woo Kim do { \
186d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
187d8408326SSeung-Woo Kim 		(u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \
188d8408326SSeung-Woo Kim } while (0)
189d8408326SSeung-Woo Kim 
190d8408326SSeung-Woo Kim 	DUMPREG(MXR_STATUS);
191d8408326SSeung-Woo Kim 	DUMPREG(MXR_CFG);
192d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_EN);
193d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_STATUS);
194d8408326SSeung-Woo Kim 
195d8408326SSeung-Woo Kim 	DUMPREG(MXR_LAYER_CFG);
196d8408326SSeung-Woo Kim 	DUMPREG(MXR_VIDEO_CFG);
197d8408326SSeung-Woo Kim 
198d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_CFG);
199d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_BASE);
200d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SPAN);
201d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_WH);
202d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SXY);
203d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_DXY);
204d8408326SSeung-Woo Kim 
205d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_CFG);
206d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_BASE);
207d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SPAN);
208d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_WH);
209d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SXY);
210d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_DXY);
211d8408326SSeung-Woo Kim #undef DUMPREG
212d8408326SSeung-Woo Kim }
213d8408326SSeung-Woo Kim 
214d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx)
215d8408326SSeung-Woo Kim {
216d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
217d8408326SSeung-Woo Kim do { \
218d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
219d8408326SSeung-Woo Kim 		(u32) readl(ctx->mixer_res.vp_regs + reg_id)); \
220d8408326SSeung-Woo Kim } while (0)
221d8408326SSeung-Woo Kim 
222d8408326SSeung-Woo Kim 	DUMPREG(VP_ENABLE);
223d8408326SSeung-Woo Kim 	DUMPREG(VP_SRESET);
224d8408326SSeung-Woo Kim 	DUMPREG(VP_SHADOW_UPDATE);
225d8408326SSeung-Woo Kim 	DUMPREG(VP_FIELD_ID);
226d8408326SSeung-Woo Kim 	DUMPREG(VP_MODE);
227d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_Y);
228d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_C);
229d8408326SSeung-Woo Kim 	DUMPREG(VP_PER_RATE_CTRL);
230d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_Y_PTR);
231d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_Y_PTR);
232d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_C_PTR);
233d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_C_PTR);
234d8408326SSeung-Woo Kim 	DUMPREG(VP_ENDIAN_MODE);
235d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_H_POSITION);
236d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_V_POSITION);
237d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_WIDTH);
238d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_HEIGHT);
239d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_H_POSITION);
240d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_V_POSITION);
241d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_WIDTH);
242d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_HEIGHT);
243d8408326SSeung-Woo Kim 	DUMPREG(VP_H_RATIO);
244d8408326SSeung-Woo Kim 	DUMPREG(VP_V_RATIO);
245d8408326SSeung-Woo Kim 
246d8408326SSeung-Woo Kim #undef DUMPREG
247d8408326SSeung-Woo Kim }
248d8408326SSeung-Woo Kim 
249d8408326SSeung-Woo Kim static inline void vp_filter_set(struct mixer_resources *res,
250d8408326SSeung-Woo Kim 		int reg_id, const u8 *data, unsigned int size)
251d8408326SSeung-Woo Kim {
252d8408326SSeung-Woo Kim 	/* assure 4-byte align */
253d8408326SSeung-Woo Kim 	BUG_ON(size & 3);
254d8408326SSeung-Woo Kim 	for (; size; size -= 4, reg_id += 4, data += 4) {
255d8408326SSeung-Woo Kim 		u32 val = (data[0] << 24) |  (data[1] << 16) |
256d8408326SSeung-Woo Kim 			(data[2] << 8) | data[3];
257d8408326SSeung-Woo Kim 		vp_reg_write(res, reg_id, val);
258d8408326SSeung-Woo Kim 	}
259d8408326SSeung-Woo Kim }
260d8408326SSeung-Woo Kim 
261d8408326SSeung-Woo Kim static void vp_default_filter(struct mixer_resources *res)
262d8408326SSeung-Woo Kim {
263d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY8_Y0_LL,
264e25e1b66SSachin Kamat 		filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
265d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_Y0_LL,
266e25e1b66SSachin Kamat 		filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
267d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_C0_LL,
268e25e1b66SSachin Kamat 		filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
269d8408326SSeung-Woo Kim }
270d8408326SSeung-Woo Kim 
271d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable)
272d8408326SSeung-Woo Kim {
273d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
274d8408326SSeung-Woo Kim 
275d8408326SSeung-Woo Kim 	/* block update on vsync */
276d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, enable ?
277d8408326SSeung-Woo Kim 			MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE);
278d8408326SSeung-Woo Kim 
2791b8e5747SRahul Sharma 	if (ctx->vp_enabled)
280d8408326SSeung-Woo Kim 		vp_reg_write(res, VP_SHADOW_UPDATE, enable ?
281d8408326SSeung-Woo Kim 			VP_SHADOW_UPDATE_ENABLE : 0);
282d8408326SSeung-Woo Kim }
283d8408326SSeung-Woo Kim 
284d8408326SSeung-Woo Kim static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height)
285d8408326SSeung-Woo Kim {
286d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
287d8408326SSeung-Woo Kim 	u32 val;
288d8408326SSeung-Woo Kim 
289d8408326SSeung-Woo Kim 	/* choosing between interlace and progressive mode */
290d8408326SSeung-Woo Kim 	val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE :
291d8408326SSeung-Woo Kim 				MXR_CFG_SCAN_PROGRASSIVE);
292d8408326SSeung-Woo Kim 
293def5e095SRahul Sharma 	if (ctx->mxr_ver != MXR_VER_128_0_0_184) {
294def5e095SRahul Sharma 		/* choosing between proper HD and SD mode */
29529630743SRahul Sharma 		if (height <= 480)
296d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD;
29729630743SRahul Sharma 		else if (height <= 576)
298d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD;
29929630743SRahul Sharma 		else if (height <= 720)
300d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
30129630743SRahul Sharma 		else if (height <= 1080)
302d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD;
303d8408326SSeung-Woo Kim 		else
304d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
305def5e095SRahul Sharma 	}
306d8408326SSeung-Woo Kim 
307d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK);
308d8408326SSeung-Woo Kim }
309d8408326SSeung-Woo Kim 
310d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height)
311d8408326SSeung-Woo Kim {
312d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
313d8408326SSeung-Woo Kim 	u32 val;
314d8408326SSeung-Woo Kim 
315d8408326SSeung-Woo Kim 	if (height == 480) {
316d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
317d8408326SSeung-Woo Kim 	} else if (height == 576) {
318d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
319d8408326SSeung-Woo Kim 	} else if (height == 720) {
320d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
321d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
322d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
323d8408326SSeung-Woo Kim 				(32 << 0));
324d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
325d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
326d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
327d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
328d8408326SSeung-Woo Kim 	} else if (height == 1080) {
329d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
330d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
331d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
332d8408326SSeung-Woo Kim 				(32 << 0));
333d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
334d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
335d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
336d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
337d8408326SSeung-Woo Kim 	} else {
338d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
339d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
340d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
341d8408326SSeung-Woo Kim 				(32 << 0));
342d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
343d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
344d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
345d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
346d8408326SSeung-Woo Kim 	}
347d8408326SSeung-Woo Kim 
348d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
349d8408326SSeung-Woo Kim }
350d8408326SSeung-Woo Kim 
351d8408326SSeung-Woo Kim static void mixer_cfg_layer(struct mixer_context *ctx, int win, bool enable)
352d8408326SSeung-Woo Kim {
353d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
354d8408326SSeung-Woo Kim 	u32 val = enable ? ~0 : 0;
355d8408326SSeung-Woo Kim 
356d8408326SSeung-Woo Kim 	switch (win) {
357d8408326SSeung-Woo Kim 	case 0:
358d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
359d8408326SSeung-Woo Kim 		break;
360d8408326SSeung-Woo Kim 	case 1:
361d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
362d8408326SSeung-Woo Kim 		break;
363d8408326SSeung-Woo Kim 	case 2:
3641b8e5747SRahul Sharma 		if (ctx->vp_enabled) {
365d8408326SSeung-Woo Kim 			vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON);
3661b8e5747SRahul Sharma 			mixer_reg_writemask(res, MXR_CFG, val,
3671b8e5747SRahul Sharma 				MXR_CFG_VP_ENABLE);
3681b8e5747SRahul Sharma 		}
369d8408326SSeung-Woo Kim 		break;
370d8408326SSeung-Woo Kim 	}
371d8408326SSeung-Woo Kim }
372d8408326SSeung-Woo Kim 
373d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx)
374d8408326SSeung-Woo Kim {
375d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
376d8408326SSeung-Woo Kim 
377d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
378d8408326SSeung-Woo Kim 
379d8408326SSeung-Woo Kim 	mixer_regs_dump(ctx);
380d8408326SSeung-Woo Kim }
381d8408326SSeung-Woo Kim 
382381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx)
383381be025SRahul Sharma {
384381be025SRahul Sharma 	struct mixer_resources *res = &ctx->mixer_res;
385381be025SRahul Sharma 	int timeout = 20;
386381be025SRahul Sharma 
387381be025SRahul Sharma 	mixer_reg_writemask(res, MXR_STATUS, 0, MXR_STATUS_REG_RUN);
388381be025SRahul Sharma 
389381be025SRahul Sharma 	while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
390381be025SRahul Sharma 			--timeout)
391381be025SRahul Sharma 		usleep_range(10000, 12000);
392381be025SRahul Sharma 
393381be025SRahul Sharma 	mixer_regs_dump(ctx);
394381be025SRahul Sharma }
395381be025SRahul Sharma 
396d8408326SSeung-Woo Kim static void vp_video_buffer(struct mixer_context *ctx, int win)
397d8408326SSeung-Woo Kim {
398d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
399d8408326SSeung-Woo Kim 	unsigned long flags;
400d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
401d8408326SSeung-Woo Kim 	unsigned int x_ratio, y_ratio;
402782953ecSYoungJun Cho 	unsigned int buf_num = 1;
403d8408326SSeung-Woo Kim 	dma_addr_t luma_addr[2], chroma_addr[2];
404d8408326SSeung-Woo Kim 	bool tiled_mode = false;
405d8408326SSeung-Woo Kim 	bool crcb_mode = false;
406d8408326SSeung-Woo Kim 	u32 val;
407d8408326SSeung-Woo Kim 
408d8408326SSeung-Woo Kim 	win_data = &ctx->win_data[win];
409d8408326SSeung-Woo Kim 
410d8408326SSeung-Woo Kim 	switch (win_data->pixel_format) {
411d8408326SSeung-Woo Kim 	case DRM_FORMAT_NV12MT:
412d8408326SSeung-Woo Kim 		tiled_mode = true;
413363b06aaSVille Syrjälä 	case DRM_FORMAT_NV12:
414d8408326SSeung-Woo Kim 		crcb_mode = false;
415d8408326SSeung-Woo Kim 		buf_num = 2;
416d8408326SSeung-Woo Kim 		break;
417d8408326SSeung-Woo Kim 	/* TODO: single buffer format NV12, NV21 */
418d8408326SSeung-Woo Kim 	default:
419d8408326SSeung-Woo Kim 		/* ignore pixel format at disable time */
420d8408326SSeung-Woo Kim 		if (!win_data->dma_addr)
421d8408326SSeung-Woo Kim 			break;
422d8408326SSeung-Woo Kim 
423d8408326SSeung-Woo Kim 		DRM_ERROR("pixel format for vp is wrong [%d].\n",
424d8408326SSeung-Woo Kim 				win_data->pixel_format);
425d8408326SSeung-Woo Kim 		return;
426d8408326SSeung-Woo Kim 	}
427d8408326SSeung-Woo Kim 
428d8408326SSeung-Woo Kim 	/* scaling feature: (src << 16) / dst */
4298dcb96b6SSeung-Woo Kim 	x_ratio = (win_data->src_width << 16) / win_data->crtc_width;
4308dcb96b6SSeung-Woo Kim 	y_ratio = (win_data->src_height << 16) / win_data->crtc_height;
431d8408326SSeung-Woo Kim 
432d8408326SSeung-Woo Kim 	if (buf_num == 2) {
433d8408326SSeung-Woo Kim 		luma_addr[0] = win_data->dma_addr;
434d8408326SSeung-Woo Kim 		chroma_addr[0] = win_data->chroma_dma_addr;
435d8408326SSeung-Woo Kim 	} else {
436d8408326SSeung-Woo Kim 		luma_addr[0] = win_data->dma_addr;
437d8408326SSeung-Woo Kim 		chroma_addr[0] = win_data->dma_addr
4388dcb96b6SSeung-Woo Kim 			+ (win_data->fb_width * win_data->fb_height);
439d8408326SSeung-Woo Kim 	}
440d8408326SSeung-Woo Kim 
441d8408326SSeung-Woo Kim 	if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE) {
442d8408326SSeung-Woo Kim 		ctx->interlace = true;
443d8408326SSeung-Woo Kim 		if (tiled_mode) {
444d8408326SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + 0x40;
445d8408326SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + 0x40;
446d8408326SSeung-Woo Kim 		} else {
4478dcb96b6SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + win_data->fb_width;
4488dcb96b6SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + win_data->fb_width;
449d8408326SSeung-Woo Kim 		}
450d8408326SSeung-Woo Kim 	} else {
451d8408326SSeung-Woo Kim 		ctx->interlace = false;
452d8408326SSeung-Woo Kim 		luma_addr[1] = 0;
453d8408326SSeung-Woo Kim 		chroma_addr[1] = 0;
454d8408326SSeung-Woo Kim 	}
455d8408326SSeung-Woo Kim 
456d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
457d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
458d8408326SSeung-Woo Kim 
459d8408326SSeung-Woo Kim 	/* interlace or progressive scan mode */
460d8408326SSeung-Woo Kim 	val = (ctx->interlace ? ~0 : 0);
461d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP);
462d8408326SSeung-Woo Kim 
463d8408326SSeung-Woo Kim 	/* setup format */
464d8408326SSeung-Woo Kim 	val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12);
465d8408326SSeung-Woo Kim 	val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
466d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK);
467d8408326SSeung-Woo Kim 
468d8408326SSeung-Woo Kim 	/* setting size of input image */
4698dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(win_data->fb_width) |
4708dcb96b6SSeung-Woo Kim 		VP_IMG_VSIZE(win_data->fb_height));
471d8408326SSeung-Woo Kim 	/* chroma height has to reduced by 2 to avoid chroma distorions */
4728dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(win_data->fb_width) |
4738dcb96b6SSeung-Woo Kim 		VP_IMG_VSIZE(win_data->fb_height / 2));
474d8408326SSeung-Woo Kim 
4758dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_WIDTH, win_data->src_width);
4768dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_HEIGHT, win_data->src_height);
477d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_H_POSITION,
4788dcb96b6SSeung-Woo Kim 			VP_SRC_H_POSITION_VAL(win_data->fb_x));
4798dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_V_POSITION, win_data->fb_y);
480d8408326SSeung-Woo Kim 
4818dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_DST_WIDTH, win_data->crtc_width);
4828dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_DST_H_POSITION, win_data->crtc_x);
483d8408326SSeung-Woo Kim 	if (ctx->interlace) {
4848dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height / 2);
4858dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y / 2);
486d8408326SSeung-Woo Kim 	} else {
4878dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height);
4888dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y);
489d8408326SSeung-Woo Kim 	}
490d8408326SSeung-Woo Kim 
491d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_H_RATIO, x_ratio);
492d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_V_RATIO, y_ratio);
493d8408326SSeung-Woo Kim 
494d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
495d8408326SSeung-Woo Kim 
496d8408326SSeung-Woo Kim 	/* set buffer address to vp */
497d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]);
498d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]);
499d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]);
500d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]);
501d8408326SSeung-Woo Kim 
5028dcb96b6SSeung-Woo Kim 	mixer_cfg_scan(ctx, win_data->mode_height);
5038dcb96b6SSeung-Woo Kim 	mixer_cfg_rgb_fmt(ctx, win_data->mode_height);
504d8408326SSeung-Woo Kim 	mixer_cfg_layer(ctx, win, true);
505d8408326SSeung-Woo Kim 	mixer_run(ctx);
506d8408326SSeung-Woo Kim 
507d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
508d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
509d8408326SSeung-Woo Kim 
510d8408326SSeung-Woo Kim 	vp_regs_dump(ctx);
511d8408326SSeung-Woo Kim }
512d8408326SSeung-Woo Kim 
513aaf8b49eSRahul Sharma static void mixer_layer_update(struct mixer_context *ctx)
514aaf8b49eSRahul Sharma {
515aaf8b49eSRahul Sharma 	struct mixer_resources *res = &ctx->mixer_res;
516aaf8b49eSRahul Sharma 
517aaf8b49eSRahul Sharma 	mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
518aaf8b49eSRahul Sharma }
519aaf8b49eSRahul Sharma 
520d8408326SSeung-Woo Kim static void mixer_graph_buffer(struct mixer_context *ctx, int win)
521d8408326SSeung-Woo Kim {
522d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
523d8408326SSeung-Woo Kim 	unsigned long flags;
524d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
525d8408326SSeung-Woo Kim 	unsigned int x_ratio, y_ratio;
526d8408326SSeung-Woo Kim 	unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset;
527d8408326SSeung-Woo Kim 	dma_addr_t dma_addr;
528d8408326SSeung-Woo Kim 	unsigned int fmt;
529d8408326SSeung-Woo Kim 	u32 val;
530d8408326SSeung-Woo Kim 
531d8408326SSeung-Woo Kim 	win_data = &ctx->win_data[win];
532d8408326SSeung-Woo Kim 
533d8408326SSeung-Woo Kim 	#define RGB565 4
534d8408326SSeung-Woo Kim 	#define ARGB1555 5
535d8408326SSeung-Woo Kim 	#define ARGB4444 6
536d8408326SSeung-Woo Kim 	#define ARGB8888 7
537d8408326SSeung-Woo Kim 
538d8408326SSeung-Woo Kim 	switch (win_data->bpp) {
539d8408326SSeung-Woo Kim 	case 16:
540d8408326SSeung-Woo Kim 		fmt = ARGB4444;
541d8408326SSeung-Woo Kim 		break;
542d8408326SSeung-Woo Kim 	case 32:
543d8408326SSeung-Woo Kim 		fmt = ARGB8888;
544d8408326SSeung-Woo Kim 		break;
545d8408326SSeung-Woo Kim 	default:
546d8408326SSeung-Woo Kim 		fmt = ARGB8888;
547d8408326SSeung-Woo Kim 	}
548d8408326SSeung-Woo Kim 
549d8408326SSeung-Woo Kim 	/* 2x scaling feature */
550d8408326SSeung-Woo Kim 	x_ratio = 0;
551d8408326SSeung-Woo Kim 	y_ratio = 0;
552d8408326SSeung-Woo Kim 
553d8408326SSeung-Woo Kim 	dst_x_offset = win_data->crtc_x;
554d8408326SSeung-Woo Kim 	dst_y_offset = win_data->crtc_y;
555d8408326SSeung-Woo Kim 
556d8408326SSeung-Woo Kim 	/* converting dma address base and source offset */
5578dcb96b6SSeung-Woo Kim 	dma_addr = win_data->dma_addr
5588dcb96b6SSeung-Woo Kim 		+ (win_data->fb_x * win_data->bpp >> 3)
5598dcb96b6SSeung-Woo Kim 		+ (win_data->fb_y * win_data->fb_width * win_data->bpp >> 3);
560d8408326SSeung-Woo Kim 	src_x_offset = 0;
561d8408326SSeung-Woo Kim 	src_y_offset = 0;
562d8408326SSeung-Woo Kim 
563d8408326SSeung-Woo Kim 	if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE)
564d8408326SSeung-Woo Kim 		ctx->interlace = true;
565d8408326SSeung-Woo Kim 	else
566d8408326SSeung-Woo Kim 		ctx->interlace = false;
567d8408326SSeung-Woo Kim 
568d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
569d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
570d8408326SSeung-Woo Kim 
571d8408326SSeung-Woo Kim 	/* setup format */
572d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
573d8408326SSeung-Woo Kim 		MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
574d8408326SSeung-Woo Kim 
575d8408326SSeung-Woo Kim 	/* setup geometry */
5768dcb96b6SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_SPAN(win), win_data->fb_width);
577d8408326SSeung-Woo Kim 
578def5e095SRahul Sharma 	/* setup display size */
579def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_128_0_0_184 &&
580def5e095SRahul Sharma 		win == MIXER_DEFAULT_WIN) {
581def5e095SRahul Sharma 		val  = MXR_MXR_RES_HEIGHT(win_data->fb_height);
582def5e095SRahul Sharma 		val |= MXR_MXR_RES_WIDTH(win_data->fb_width);
583def5e095SRahul Sharma 		mixer_reg_write(res, MXR_RESOLUTION, val);
584def5e095SRahul Sharma 	}
585def5e095SRahul Sharma 
5868dcb96b6SSeung-Woo Kim 	val  = MXR_GRP_WH_WIDTH(win_data->crtc_width);
5878dcb96b6SSeung-Woo Kim 	val |= MXR_GRP_WH_HEIGHT(win_data->crtc_height);
588d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_H_SCALE(x_ratio);
589d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_V_SCALE(y_ratio);
590d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_WH(win), val);
591d8408326SSeung-Woo Kim 
592d8408326SSeung-Woo Kim 	/* setup offsets in source image */
593d8408326SSeung-Woo Kim 	val  = MXR_GRP_SXY_SX(src_x_offset);
594d8408326SSeung-Woo Kim 	val |= MXR_GRP_SXY_SY(src_y_offset);
595d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val);
596d8408326SSeung-Woo Kim 
597d8408326SSeung-Woo Kim 	/* setup offsets in display image */
598d8408326SSeung-Woo Kim 	val  = MXR_GRP_DXY_DX(dst_x_offset);
599d8408326SSeung-Woo Kim 	val |= MXR_GRP_DXY_DY(dst_y_offset);
600d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val);
601d8408326SSeung-Woo Kim 
602d8408326SSeung-Woo Kim 	/* set buffer address to mixer */
603d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr);
604d8408326SSeung-Woo Kim 
6058dcb96b6SSeung-Woo Kim 	mixer_cfg_scan(ctx, win_data->mode_height);
6068dcb96b6SSeung-Woo Kim 	mixer_cfg_rgb_fmt(ctx, win_data->mode_height);
607d8408326SSeung-Woo Kim 	mixer_cfg_layer(ctx, win, true);
608aaf8b49eSRahul Sharma 
609aaf8b49eSRahul Sharma 	/* layer update mandatory for mixer 16.0.33.0 */
610def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
611def5e095SRahul Sharma 		ctx->mxr_ver == MXR_VER_128_0_0_184)
612aaf8b49eSRahul Sharma 		mixer_layer_update(ctx);
613aaf8b49eSRahul Sharma 
614d8408326SSeung-Woo Kim 	mixer_run(ctx);
615d8408326SSeung-Woo Kim 
616d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
617d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
618d8408326SSeung-Woo Kim }
619d8408326SSeung-Woo Kim 
620d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx)
621d8408326SSeung-Woo Kim {
622d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
623d8408326SSeung-Woo Kim 	int tries = 100;
624d8408326SSeung-Woo Kim 
625d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING);
626d8408326SSeung-Woo Kim 	for (tries = 100; tries; --tries) {
627d8408326SSeung-Woo Kim 		/* waiting until VP_SRESET_PROCESSING is 0 */
628d8408326SSeung-Woo Kim 		if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING)
629d8408326SSeung-Woo Kim 			break;
63009760ea3SSean Paul 		usleep_range(10000, 12000);
631d8408326SSeung-Woo Kim 	}
632d8408326SSeung-Woo Kim 	WARN(tries == 0, "failed to reset Video Processor\n");
633d8408326SSeung-Woo Kim }
634d8408326SSeung-Woo Kim 
635cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx)
636cf8fc4f1SJoonyoung Shim {
637cf8fc4f1SJoonyoung Shim 	struct mixer_resources *res = &ctx->mixer_res;
638cf8fc4f1SJoonyoung Shim 	unsigned long flags;
639cf8fc4f1SJoonyoung Shim 	u32 val; /* value stored to register */
640cf8fc4f1SJoonyoung Shim 
641cf8fc4f1SJoonyoung Shim 	spin_lock_irqsave(&res->reg_slock, flags);
642cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, false);
643cf8fc4f1SJoonyoung Shim 
644cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
645cf8fc4f1SJoonyoung Shim 
646cf8fc4f1SJoonyoung Shim 	/* set output in RGB888 mode */
647cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
648cf8fc4f1SJoonyoung Shim 
649cf8fc4f1SJoonyoung Shim 	/* 16 beat burst in DMA */
650cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST,
651cf8fc4f1SJoonyoung Shim 		MXR_STATUS_BURST_MASK);
652cf8fc4f1SJoonyoung Shim 
653cf8fc4f1SJoonyoung Shim 	/* setting default layer priority: layer1 > layer0 > video
654cf8fc4f1SJoonyoung Shim 	 * because typical usage scenario would be
655cf8fc4f1SJoonyoung Shim 	 * layer1 - OSD
656cf8fc4f1SJoonyoung Shim 	 * layer0 - framebuffer
657cf8fc4f1SJoonyoung Shim 	 * video - video overlay
658cf8fc4f1SJoonyoung Shim 	 */
659cf8fc4f1SJoonyoung Shim 	val = MXR_LAYER_CFG_GRP1_VAL(3);
660cf8fc4f1SJoonyoung Shim 	val |= MXR_LAYER_CFG_GRP0_VAL(2);
6611b8e5747SRahul Sharma 	if (ctx->vp_enabled)
662cf8fc4f1SJoonyoung Shim 		val |= MXR_LAYER_CFG_VP_VAL(1);
663cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_LAYER_CFG, val);
664cf8fc4f1SJoonyoung Shim 
665cf8fc4f1SJoonyoung Shim 	/* setting background color */
666cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR0, 0x008080);
667cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR1, 0x008080);
668cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR2, 0x008080);
669cf8fc4f1SJoonyoung Shim 
670cf8fc4f1SJoonyoung Shim 	/* setting graphical layers */
671cf8fc4f1SJoonyoung Shim 	val  = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
672cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_WIN_BLEND_EN;
673cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_ALPHA_VAL(0xff); /* non-transparent alpha */
674cf8fc4f1SJoonyoung Shim 
6750377f4edSSean Paul 	/* Don't blend layer 0 onto the mixer background */
676cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(0), val);
6770377f4edSSean Paul 
6780377f4edSSean Paul 	/* Blend layer 1 into layer 0 */
6790377f4edSSean Paul 	val |= MXR_GRP_CFG_BLEND_PRE_MUL;
6800377f4edSSean Paul 	val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
681cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(1), val);
682cf8fc4f1SJoonyoung Shim 
6835736603bSSeung-Woo Kim 	/* setting video layers */
6845736603bSSeung-Woo Kim 	val = MXR_GRP_CFG_ALPHA_VAL(0);
6855736603bSSeung-Woo Kim 	mixer_reg_write(res, MXR_VIDEO_CFG, val);
6865736603bSSeung-Woo Kim 
6871b8e5747SRahul Sharma 	if (ctx->vp_enabled) {
688cf8fc4f1SJoonyoung Shim 		/* configuration of Video Processor Registers */
689cf8fc4f1SJoonyoung Shim 		vp_win_reset(ctx);
690cf8fc4f1SJoonyoung Shim 		vp_default_filter(res);
6911b8e5747SRahul Sharma 	}
692cf8fc4f1SJoonyoung Shim 
693cf8fc4f1SJoonyoung Shim 	/* disable all layers */
694cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
695cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
6961b8e5747SRahul Sharma 	if (ctx->vp_enabled)
697cf8fc4f1SJoonyoung Shim 		mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
698cf8fc4f1SJoonyoung Shim 
699cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, true);
700cf8fc4f1SJoonyoung Shim 	spin_unlock_irqrestore(&res->reg_slock, flags);
701cf8fc4f1SJoonyoung Shim }
702cf8fc4f1SJoonyoung Shim 
7034551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg)
7044551789fSSean Paul {
7054551789fSSean Paul 	struct mixer_context *ctx = arg;
7064551789fSSean Paul 	struct mixer_resources *res = &ctx->mixer_res;
7074551789fSSean Paul 	u32 val, base, shadow;
7084551789fSSean Paul 
7094551789fSSean Paul 	spin_lock(&res->reg_slock);
7104551789fSSean Paul 
7114551789fSSean Paul 	/* read interrupt status for handling and clearing flags for VSYNC */
7124551789fSSean Paul 	val = mixer_reg_read(res, MXR_INT_STATUS);
7134551789fSSean Paul 
7144551789fSSean Paul 	/* handling VSYNC */
7154551789fSSean Paul 	if (val & MXR_INT_STATUS_VSYNC) {
7164551789fSSean Paul 		/* interlace scan need to check shadow register */
7174551789fSSean Paul 		if (ctx->interlace) {
7184551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0));
7194551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0));
7204551789fSSean Paul 			if (base != shadow)
7214551789fSSean Paul 				goto out;
7224551789fSSean Paul 
7234551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1));
7244551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1));
7254551789fSSean Paul 			if (base != shadow)
7264551789fSSean Paul 				goto out;
7274551789fSSean Paul 		}
7284551789fSSean Paul 
7294551789fSSean Paul 		drm_handle_vblank(ctx->drm_dev, ctx->pipe);
7304551789fSSean Paul 		exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe);
7314551789fSSean Paul 
7324551789fSSean Paul 		/* set wait vsync event to zero and wake up queue. */
7334551789fSSean Paul 		if (atomic_read(&ctx->wait_vsync_event)) {
7344551789fSSean Paul 			atomic_set(&ctx->wait_vsync_event, 0);
7354551789fSSean Paul 			wake_up(&ctx->wait_vsync_queue);
7364551789fSSean Paul 		}
7374551789fSSean Paul 	}
7384551789fSSean Paul 
7394551789fSSean Paul out:
7404551789fSSean Paul 	/* clear interrupts */
7414551789fSSean Paul 	if (~val & MXR_INT_EN_VSYNC) {
7424551789fSSean Paul 		/* vsync interrupt use different bit for read and clear */
7434551789fSSean Paul 		val &= ~MXR_INT_EN_VSYNC;
7444551789fSSean Paul 		val |= MXR_INT_CLEAR_VSYNC;
7454551789fSSean Paul 	}
7464551789fSSean Paul 	mixer_reg_write(res, MXR_INT_STATUS, val);
7474551789fSSean Paul 
7484551789fSSean Paul 	spin_unlock(&res->reg_slock);
7494551789fSSean Paul 
7504551789fSSean Paul 	return IRQ_HANDLED;
7514551789fSSean Paul }
7524551789fSSean Paul 
7534551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx)
7544551789fSSean Paul {
7554551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
7564551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
7574551789fSSean Paul 	struct resource *res;
7584551789fSSean Paul 	int ret;
7594551789fSSean Paul 
7604551789fSSean Paul 	spin_lock_init(&mixer_res->reg_slock);
7614551789fSSean Paul 
7624551789fSSean Paul 	mixer_res->mixer = devm_clk_get(dev, "mixer");
7634551789fSSean Paul 	if (IS_ERR(mixer_res->mixer)) {
7644551789fSSean Paul 		dev_err(dev, "failed to get clock 'mixer'\n");
7654551789fSSean Paul 		return -ENODEV;
7664551789fSSean Paul 	}
7674551789fSSean Paul 
7684551789fSSean Paul 	mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
7694551789fSSean Paul 	if (IS_ERR(mixer_res->sclk_hdmi)) {
7704551789fSSean Paul 		dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
7714551789fSSean Paul 		return -ENODEV;
7724551789fSSean Paul 	}
7734551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
7744551789fSSean Paul 	if (res == NULL) {
7754551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
7764551789fSSean Paul 		return -ENXIO;
7774551789fSSean Paul 	}
7784551789fSSean Paul 
7794551789fSSean Paul 	mixer_res->mixer_regs = devm_ioremap(dev, res->start,
7804551789fSSean Paul 							resource_size(res));
7814551789fSSean Paul 	if (mixer_res->mixer_regs == NULL) {
7824551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
7834551789fSSean Paul 		return -ENXIO;
7844551789fSSean Paul 	}
7854551789fSSean Paul 
7864551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0);
7874551789fSSean Paul 	if (res == NULL) {
7884551789fSSean Paul 		dev_err(dev, "get interrupt resource failed.\n");
7894551789fSSean Paul 		return -ENXIO;
7904551789fSSean Paul 	}
7914551789fSSean Paul 
7924551789fSSean Paul 	ret = devm_request_irq(dev, res->start, mixer_irq_handler,
7934551789fSSean Paul 						0, "drm_mixer", mixer_ctx);
7944551789fSSean Paul 	if (ret) {
7954551789fSSean Paul 		dev_err(dev, "request interrupt failed.\n");
7964551789fSSean Paul 		return ret;
7974551789fSSean Paul 	}
7984551789fSSean Paul 	mixer_res->irq = res->start;
7994551789fSSean Paul 
8004551789fSSean Paul 	return 0;
8014551789fSSean Paul }
8024551789fSSean Paul 
8034551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx)
8044551789fSSean Paul {
8054551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
8064551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
8074551789fSSean Paul 	struct resource *res;
8084551789fSSean Paul 
8094551789fSSean Paul 	mixer_res->vp = devm_clk_get(dev, "vp");
8104551789fSSean Paul 	if (IS_ERR(mixer_res->vp)) {
8114551789fSSean Paul 		dev_err(dev, "failed to get clock 'vp'\n");
8124551789fSSean Paul 		return -ENODEV;
8134551789fSSean Paul 	}
814*ff830c96SMarek Szyprowski 
815*ff830c96SMarek Szyprowski 	if (mixer_ctx->has_sclk) {
8164551789fSSean Paul 		mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
8174551789fSSean Paul 		if (IS_ERR(mixer_res->sclk_mixer)) {
8184551789fSSean Paul 			dev_err(dev, "failed to get clock 'sclk_mixer'\n");
8194551789fSSean Paul 			return -ENODEV;
8204551789fSSean Paul 		}
821*ff830c96SMarek Szyprowski 		mixer_res->mout_mixer = devm_clk_get(dev, "mout_mixer");
822*ff830c96SMarek Szyprowski 		if (IS_ERR(mixer_res->mout_mixer)) {
823*ff830c96SMarek Szyprowski 			dev_err(dev, "failed to get clock 'mout_mixer'\n");
8244551789fSSean Paul 			return -ENODEV;
8254551789fSSean Paul 		}
8264551789fSSean Paul 
827*ff830c96SMarek Szyprowski 		if (mixer_res->sclk_hdmi && mixer_res->mout_mixer)
828*ff830c96SMarek Szyprowski 			clk_set_parent(mixer_res->mout_mixer,
829*ff830c96SMarek Szyprowski 				       mixer_res->sclk_hdmi);
830*ff830c96SMarek Szyprowski 	}
8314551789fSSean Paul 
8324551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
8334551789fSSean Paul 	if (res == NULL) {
8344551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8354551789fSSean Paul 		return -ENXIO;
8364551789fSSean Paul 	}
8374551789fSSean Paul 
8384551789fSSean Paul 	mixer_res->vp_regs = devm_ioremap(dev, res->start,
8394551789fSSean Paul 							resource_size(res));
8404551789fSSean Paul 	if (mixer_res->vp_regs == NULL) {
8414551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8424551789fSSean Paul 		return -ENXIO;
8434551789fSSean Paul 	}
8444551789fSSean Paul 
8454551789fSSean Paul 	return 0;
8464551789fSSean Paul }
8474551789fSSean Paul 
848f041b257SSean Paul static int mixer_initialize(struct exynos_drm_manager *mgr,
849f37cd5e8SInki Dae 			struct drm_device *drm_dev)
8504551789fSSean Paul {
8514551789fSSean Paul 	int ret;
852f041b257SSean Paul 	struct mixer_context *mixer_ctx = mgr->ctx;
853f37cd5e8SInki Dae 	struct exynos_drm_private *priv;
854f37cd5e8SInki Dae 	priv = drm_dev->dev_private;
8554551789fSSean Paul 
856f37cd5e8SInki Dae 	mgr->drm_dev = mixer_ctx->drm_dev = drm_dev;
857f37cd5e8SInki Dae 	mgr->pipe = mixer_ctx->pipe = priv->pipe++;
8584551789fSSean Paul 
8594551789fSSean Paul 	/* acquire resources: regs, irqs, clocks */
8604551789fSSean Paul 	ret = mixer_resources_init(mixer_ctx);
8614551789fSSean Paul 	if (ret) {
8624551789fSSean Paul 		DRM_ERROR("mixer_resources_init failed ret=%d\n", ret);
8634551789fSSean Paul 		return ret;
8644551789fSSean Paul 	}
8654551789fSSean Paul 
8664551789fSSean Paul 	if (mixer_ctx->vp_enabled) {
8674551789fSSean Paul 		/* acquire vp resources: regs, irqs, clocks */
8684551789fSSean Paul 		ret = vp_resources_init(mixer_ctx);
8694551789fSSean Paul 		if (ret) {
8704551789fSSean Paul 			DRM_ERROR("vp_resources_init failed ret=%d\n", ret);
8714551789fSSean Paul 			return ret;
8724551789fSSean Paul 		}
8734551789fSSean Paul 	}
8744551789fSSean Paul 
875f041b257SSean Paul 	if (!is_drm_iommu_supported(mixer_ctx->drm_dev))
8761055b39fSInki Dae 		return 0;
877f041b257SSean Paul 
878f041b257SSean Paul 	return drm_iommu_attach_device(mixer_ctx->drm_dev, mixer_ctx->dev);
8791055b39fSInki Dae }
8801055b39fSInki Dae 
881f041b257SSean Paul static void mixer_mgr_remove(struct exynos_drm_manager *mgr)
882d8408326SSeung-Woo Kim {
883f041b257SSean Paul 	struct mixer_context *mixer_ctx = mgr->ctx;
884f041b257SSean Paul 
885f041b257SSean Paul 	if (is_drm_iommu_supported(mixer_ctx->drm_dev))
886f041b257SSean Paul 		drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev);
887f041b257SSean Paul }
888f041b257SSean Paul 
889f041b257SSean Paul static int mixer_enable_vblank(struct exynos_drm_manager *mgr)
890f041b257SSean Paul {
891f041b257SSean Paul 	struct mixer_context *mixer_ctx = mgr->ctx;
892d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
893d8408326SSeung-Woo Kim 
894f041b257SSean Paul 	if (!mixer_ctx->powered) {
895f041b257SSean Paul 		mixer_ctx->int_en |= MXR_INT_EN_VSYNC;
896f041b257SSean Paul 		return 0;
897f041b257SSean Paul 	}
898d8408326SSeung-Woo Kim 
899d8408326SSeung-Woo Kim 	/* enable vsync interrupt */
900d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_INT_EN, MXR_INT_EN_VSYNC,
901d8408326SSeung-Woo Kim 			MXR_INT_EN_VSYNC);
902d8408326SSeung-Woo Kim 
903d8408326SSeung-Woo Kim 	return 0;
904d8408326SSeung-Woo Kim }
905d8408326SSeung-Woo Kim 
906f041b257SSean Paul static void mixer_disable_vblank(struct exynos_drm_manager *mgr)
907d8408326SSeung-Woo Kim {
908f041b257SSean Paul 	struct mixer_context *mixer_ctx = mgr->ctx;
909d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
910d8408326SSeung-Woo Kim 
911d8408326SSeung-Woo Kim 	/* disable vsync interrupt */
912d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
913d8408326SSeung-Woo Kim }
914d8408326SSeung-Woo Kim 
915f041b257SSean Paul static void mixer_win_mode_set(struct exynos_drm_manager *mgr,
916d8408326SSeung-Woo Kim 			struct exynos_drm_overlay *overlay)
917d8408326SSeung-Woo Kim {
918f041b257SSean Paul 	struct mixer_context *mixer_ctx = mgr->ctx;
919d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
920d8408326SSeung-Woo Kim 	int win;
921d8408326SSeung-Woo Kim 
922d8408326SSeung-Woo Kim 	if (!overlay) {
923d8408326SSeung-Woo Kim 		DRM_ERROR("overlay is NULL\n");
924d8408326SSeung-Woo Kim 		return;
925d8408326SSeung-Woo Kim 	}
926d8408326SSeung-Woo Kim 
927d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS("set [%d]x[%d] at (%d,%d) to [%d]x[%d] at (%d,%d)\n",
928d8408326SSeung-Woo Kim 				 overlay->fb_width, overlay->fb_height,
929d8408326SSeung-Woo Kim 				 overlay->fb_x, overlay->fb_y,
930d8408326SSeung-Woo Kim 				 overlay->crtc_width, overlay->crtc_height,
931d8408326SSeung-Woo Kim 				 overlay->crtc_x, overlay->crtc_y);
932d8408326SSeung-Woo Kim 
933d8408326SSeung-Woo Kim 	win = overlay->zpos;
934d8408326SSeung-Woo Kim 	if (win == DEFAULT_ZPOS)
935a2ee151bSJoonyoung Shim 		win = MIXER_DEFAULT_WIN;
936d8408326SSeung-Woo Kim 
9371586d80cSKrzysztof Kozlowski 	if (win < 0 || win >= MIXER_WIN_NR) {
938cf8fc4f1SJoonyoung Shim 		DRM_ERROR("mixer window[%d] is wrong\n", win);
939d8408326SSeung-Woo Kim 		return;
940d8408326SSeung-Woo Kim 	}
941d8408326SSeung-Woo Kim 
942d8408326SSeung-Woo Kim 	win_data = &mixer_ctx->win_data[win];
943d8408326SSeung-Woo Kim 
944d8408326SSeung-Woo Kim 	win_data->dma_addr = overlay->dma_addr[0];
945d8408326SSeung-Woo Kim 	win_data->chroma_dma_addr = overlay->dma_addr[1];
946d8408326SSeung-Woo Kim 	win_data->pixel_format = overlay->pixel_format;
947d8408326SSeung-Woo Kim 	win_data->bpp = overlay->bpp;
948d8408326SSeung-Woo Kim 
949d8408326SSeung-Woo Kim 	win_data->crtc_x = overlay->crtc_x;
950d8408326SSeung-Woo Kim 	win_data->crtc_y = overlay->crtc_y;
951d8408326SSeung-Woo Kim 	win_data->crtc_width = overlay->crtc_width;
952d8408326SSeung-Woo Kim 	win_data->crtc_height = overlay->crtc_height;
953d8408326SSeung-Woo Kim 
954d8408326SSeung-Woo Kim 	win_data->fb_x = overlay->fb_x;
955d8408326SSeung-Woo Kim 	win_data->fb_y = overlay->fb_y;
956d8408326SSeung-Woo Kim 	win_data->fb_width = overlay->fb_width;
957d8408326SSeung-Woo Kim 	win_data->fb_height = overlay->fb_height;
9588dcb96b6SSeung-Woo Kim 	win_data->src_width = overlay->src_width;
9598dcb96b6SSeung-Woo Kim 	win_data->src_height = overlay->src_height;
960d8408326SSeung-Woo Kim 
961d8408326SSeung-Woo Kim 	win_data->mode_width = overlay->mode_width;
962d8408326SSeung-Woo Kim 	win_data->mode_height = overlay->mode_height;
963d8408326SSeung-Woo Kim 
964d8408326SSeung-Woo Kim 	win_data->scan_flags = overlay->scan_flag;
965d8408326SSeung-Woo Kim }
966d8408326SSeung-Woo Kim 
967f041b257SSean Paul static void mixer_win_commit(struct exynos_drm_manager *mgr, int zpos)
968d8408326SSeung-Woo Kim {
969f041b257SSean Paul 	struct mixer_context *mixer_ctx = mgr->ctx;
970f041b257SSean Paul 	int win = zpos == DEFAULT_ZPOS ? MIXER_DEFAULT_WIN : zpos;
971d8408326SSeung-Woo Kim 
972cbc4c33dSYoungJun Cho 	DRM_DEBUG_KMS("win: %d\n", win);
973d8408326SSeung-Woo Kim 
974dda9012bSShirish S 	mutex_lock(&mixer_ctx->mixer_mutex);
975dda9012bSShirish S 	if (!mixer_ctx->powered) {
976dda9012bSShirish S 		mutex_unlock(&mixer_ctx->mixer_mutex);
977dda9012bSShirish S 		return;
978dda9012bSShirish S 	}
979dda9012bSShirish S 	mutex_unlock(&mixer_ctx->mixer_mutex);
980dda9012bSShirish S 
9811b8e5747SRahul Sharma 	if (win > 1 && mixer_ctx->vp_enabled)
982d8408326SSeung-Woo Kim 		vp_video_buffer(mixer_ctx, win);
983d8408326SSeung-Woo Kim 	else
984d8408326SSeung-Woo Kim 		mixer_graph_buffer(mixer_ctx, win);
985db43fd16SPrathyush K 
986db43fd16SPrathyush K 	mixer_ctx->win_data[win].enabled = true;
987d8408326SSeung-Woo Kim }
988d8408326SSeung-Woo Kim 
989f041b257SSean Paul static void mixer_win_disable(struct exynos_drm_manager *mgr, int zpos)
990d8408326SSeung-Woo Kim {
991f041b257SSean Paul 	struct mixer_context *mixer_ctx = mgr->ctx;
992d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
993f041b257SSean Paul 	int win = zpos == DEFAULT_ZPOS ? MIXER_DEFAULT_WIN : zpos;
994d8408326SSeung-Woo Kim 	unsigned long flags;
995d8408326SSeung-Woo Kim 
996cbc4c33dSYoungJun Cho 	DRM_DEBUG_KMS("win: %d\n", win);
997d8408326SSeung-Woo Kim 
998db43fd16SPrathyush K 	mutex_lock(&mixer_ctx->mixer_mutex);
999db43fd16SPrathyush K 	if (!mixer_ctx->powered) {
1000db43fd16SPrathyush K 		mutex_unlock(&mixer_ctx->mixer_mutex);
1001db43fd16SPrathyush K 		mixer_ctx->win_data[win].resume = false;
1002db43fd16SPrathyush K 		return;
1003db43fd16SPrathyush K 	}
1004db43fd16SPrathyush K 	mutex_unlock(&mixer_ctx->mixer_mutex);
1005db43fd16SPrathyush K 
1006d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
1007d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, false);
1008d8408326SSeung-Woo Kim 
1009d8408326SSeung-Woo Kim 	mixer_cfg_layer(mixer_ctx, win, false);
1010d8408326SSeung-Woo Kim 
1011d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, true);
1012d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
1013db43fd16SPrathyush K 
1014db43fd16SPrathyush K 	mixer_ctx->win_data[win].enabled = false;
1015d8408326SSeung-Woo Kim }
1016d8408326SSeung-Woo Kim 
1017f041b257SSean Paul static void mixer_wait_for_vblank(struct exynos_drm_manager *mgr)
10180ea6822fSRahul Sharma {
1019f041b257SSean Paul 	struct mixer_context *mixer_ctx = mgr->ctx;
10208137a2e2SPrathyush K 
10216e95d5e6SPrathyush K 	mutex_lock(&mixer_ctx->mixer_mutex);
10226e95d5e6SPrathyush K 	if (!mixer_ctx->powered) {
10236e95d5e6SPrathyush K 		mutex_unlock(&mixer_ctx->mixer_mutex);
10246e95d5e6SPrathyush K 		return;
10256e95d5e6SPrathyush K 	}
10266e95d5e6SPrathyush K 	mutex_unlock(&mixer_ctx->mixer_mutex);
10276e95d5e6SPrathyush K 
10285d39b9eeSRahul Sharma 	drm_vblank_get(mgr->crtc->dev, mixer_ctx->pipe);
10295d39b9eeSRahul Sharma 
10306e95d5e6SPrathyush K 	atomic_set(&mixer_ctx->wait_vsync_event, 1);
10316e95d5e6SPrathyush K 
10326e95d5e6SPrathyush K 	/*
10336e95d5e6SPrathyush K 	 * wait for MIXER to signal VSYNC interrupt or return after
10346e95d5e6SPrathyush K 	 * timeout which is set to 50ms (refresh rate of 20).
10356e95d5e6SPrathyush K 	 */
10366e95d5e6SPrathyush K 	if (!wait_event_timeout(mixer_ctx->wait_vsync_queue,
10376e95d5e6SPrathyush K 				!atomic_read(&mixer_ctx->wait_vsync_event),
1038bfd8303aSDaniel Vetter 				HZ/20))
10398137a2e2SPrathyush K 		DRM_DEBUG_KMS("vblank wait timed out.\n");
10405d39b9eeSRahul Sharma 
10415d39b9eeSRahul Sharma 	drm_vblank_put(mgr->crtc->dev, mixer_ctx->pipe);
10428137a2e2SPrathyush K }
10438137a2e2SPrathyush K 
1044f041b257SSean Paul static void mixer_window_suspend(struct exynos_drm_manager *mgr)
1045db43fd16SPrathyush K {
1046f041b257SSean Paul 	struct mixer_context *ctx = mgr->ctx;
1047db43fd16SPrathyush K 	struct hdmi_win_data *win_data;
1048db43fd16SPrathyush K 	int i;
1049db43fd16SPrathyush K 
1050db43fd16SPrathyush K 	for (i = 0; i < MIXER_WIN_NR; i++) {
1051db43fd16SPrathyush K 		win_data = &ctx->win_data[i];
1052db43fd16SPrathyush K 		win_data->resume = win_data->enabled;
1053f041b257SSean Paul 		mixer_win_disable(mgr, i);
1054db43fd16SPrathyush K 	}
1055f041b257SSean Paul 	mixer_wait_for_vblank(mgr);
1056db43fd16SPrathyush K }
1057db43fd16SPrathyush K 
1058f041b257SSean Paul static void mixer_window_resume(struct exynos_drm_manager *mgr)
1059db43fd16SPrathyush K {
1060f041b257SSean Paul 	struct mixer_context *ctx = mgr->ctx;
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->enabled = win_data->resume;
1067db43fd16SPrathyush K 		win_data->resume = false;
106887244fa6SSean Paul 		if (win_data->enabled)
1069f041b257SSean Paul 			mixer_win_commit(mgr, i);
1070db43fd16SPrathyush K 	}
1071db43fd16SPrathyush K }
1072db43fd16SPrathyush K 
1073f041b257SSean Paul static void mixer_poweron(struct exynos_drm_manager *mgr)
1074db43fd16SPrathyush K {
1075f041b257SSean Paul 	struct mixer_context *ctx = mgr->ctx;
1076db43fd16SPrathyush K 	struct mixer_resources *res = &ctx->mixer_res;
1077db43fd16SPrathyush K 
1078db43fd16SPrathyush K 	mutex_lock(&ctx->mixer_mutex);
1079db43fd16SPrathyush K 	if (ctx->powered) {
1080db43fd16SPrathyush K 		mutex_unlock(&ctx->mixer_mutex);
1081db43fd16SPrathyush K 		return;
1082db43fd16SPrathyush K 	}
1083b4bfa3c7SRahul Sharma 
1084db43fd16SPrathyush K 	mutex_unlock(&ctx->mixer_mutex);
1085db43fd16SPrathyush K 
1086af65c804SSean Paul 	pm_runtime_get_sync(ctx->dev);
1087af65c804SSean Paul 
10880bfb1f8bSSean Paul 	clk_prepare_enable(res->mixer);
1089db43fd16SPrathyush K 	if (ctx->vp_enabled) {
10900bfb1f8bSSean Paul 		clk_prepare_enable(res->vp);
1091*ff830c96SMarek Szyprowski 		if (ctx->has_sclk)
10920bfb1f8bSSean Paul 			clk_prepare_enable(res->sclk_mixer);
1093db43fd16SPrathyush K 	}
1094db43fd16SPrathyush K 
1095b4bfa3c7SRahul Sharma 	mutex_lock(&ctx->mixer_mutex);
1096b4bfa3c7SRahul Sharma 	ctx->powered = true;
1097b4bfa3c7SRahul Sharma 	mutex_unlock(&ctx->mixer_mutex);
1098b4bfa3c7SRahul Sharma 
1099d74ed937SRahul Sharma 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
1100d74ed937SRahul Sharma 
1101db43fd16SPrathyush K 	mixer_reg_write(res, MXR_INT_EN, ctx->int_en);
1102db43fd16SPrathyush K 	mixer_win_reset(ctx);
1103db43fd16SPrathyush K 
1104f041b257SSean Paul 	mixer_window_resume(mgr);
1105db43fd16SPrathyush K }
1106db43fd16SPrathyush K 
1107f041b257SSean Paul static void mixer_poweroff(struct exynos_drm_manager *mgr)
1108db43fd16SPrathyush K {
1109f041b257SSean Paul 	struct mixer_context *ctx = mgr->ctx;
1110db43fd16SPrathyush K 	struct mixer_resources *res = &ctx->mixer_res;
1111db43fd16SPrathyush K 
1112db43fd16SPrathyush K 	mutex_lock(&ctx->mixer_mutex);
1113b4bfa3c7SRahul Sharma 	if (!ctx->powered) {
1114b4bfa3c7SRahul Sharma 		mutex_unlock(&ctx->mixer_mutex);
1115b4bfa3c7SRahul Sharma 		return;
1116b4bfa3c7SRahul Sharma 	}
1117db43fd16SPrathyush K 	mutex_unlock(&ctx->mixer_mutex);
1118db43fd16SPrathyush K 
1119381be025SRahul Sharma 	mixer_stop(ctx);
1120f041b257SSean Paul 	mixer_window_suspend(mgr);
1121db43fd16SPrathyush K 
1122db43fd16SPrathyush K 	ctx->int_en = mixer_reg_read(res, MXR_INT_EN);
1123db43fd16SPrathyush K 
1124b4bfa3c7SRahul Sharma 	mutex_lock(&ctx->mixer_mutex);
1125b4bfa3c7SRahul Sharma 	ctx->powered = false;
1126b4bfa3c7SRahul Sharma 	mutex_unlock(&ctx->mixer_mutex);
1127b4bfa3c7SRahul Sharma 
11280bfb1f8bSSean Paul 	clk_disable_unprepare(res->mixer);
1129db43fd16SPrathyush K 	if (ctx->vp_enabled) {
11300bfb1f8bSSean Paul 		clk_disable_unprepare(res->vp);
1131*ff830c96SMarek Szyprowski 		if (ctx->has_sclk)
11320bfb1f8bSSean Paul 			clk_disable_unprepare(res->sclk_mixer);
1133db43fd16SPrathyush K 	}
1134db43fd16SPrathyush K 
1135af65c804SSean Paul 	pm_runtime_put_sync(ctx->dev);
1136db43fd16SPrathyush K }
1137db43fd16SPrathyush K 
1138f041b257SSean Paul static void mixer_dpms(struct exynos_drm_manager *mgr, int mode)
1139db43fd16SPrathyush K {
1140db43fd16SPrathyush K 	switch (mode) {
1141db43fd16SPrathyush K 	case DRM_MODE_DPMS_ON:
1142af65c804SSean Paul 		mixer_poweron(mgr);
1143db43fd16SPrathyush K 		break;
1144db43fd16SPrathyush K 	case DRM_MODE_DPMS_STANDBY:
1145db43fd16SPrathyush K 	case DRM_MODE_DPMS_SUSPEND:
1146db43fd16SPrathyush K 	case DRM_MODE_DPMS_OFF:
1147af65c804SSean Paul 		mixer_poweroff(mgr);
1148db43fd16SPrathyush K 		break;
1149db43fd16SPrathyush K 	default:
1150db43fd16SPrathyush K 		DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode);
1151db43fd16SPrathyush K 		break;
1152db43fd16SPrathyush K 	}
1153db43fd16SPrathyush K }
1154db43fd16SPrathyush K 
1155f041b257SSean Paul /* Only valid for Mixer version 16.0.33.0 */
1156f041b257SSean Paul int mixer_check_mode(struct drm_display_mode *mode)
1157f041b257SSean Paul {
1158f041b257SSean Paul 	u32 w, h;
1159f041b257SSean Paul 
1160f041b257SSean Paul 	w = mode->hdisplay;
1161f041b257SSean Paul 	h = mode->vdisplay;
1162f041b257SSean Paul 
1163f041b257SSean Paul 	DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n",
1164f041b257SSean Paul 		mode->hdisplay, mode->vdisplay, mode->vrefresh,
1165f041b257SSean Paul 		(mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
1166f041b257SSean Paul 
1167f041b257SSean Paul 	if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
1168f041b257SSean Paul 		(w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
1169f041b257SSean Paul 		(w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
1170f041b257SSean Paul 		return 0;
1171f041b257SSean Paul 
1172f041b257SSean Paul 	return -EINVAL;
1173f041b257SSean Paul }
1174f041b257SSean Paul 
1175f041b257SSean Paul static struct exynos_drm_manager_ops mixer_manager_ops = {
1176f041b257SSean Paul 	.dpms			= mixer_dpms,
1177d8408326SSeung-Woo Kim 	.enable_vblank		= mixer_enable_vblank,
1178d8408326SSeung-Woo Kim 	.disable_vblank		= mixer_disable_vblank,
11798137a2e2SPrathyush K 	.wait_for_vblank	= mixer_wait_for_vblank,
1180d8408326SSeung-Woo Kim 	.win_mode_set		= mixer_win_mode_set,
1181d8408326SSeung-Woo Kim 	.win_commit		= mixer_win_commit,
1182d8408326SSeung-Woo Kim 	.win_disable		= mixer_win_disable,
1183f041b257SSean Paul };
11840ea6822fSRahul Sharma 
1185f041b257SSean Paul static struct exynos_drm_manager mixer_manager = {
1186f041b257SSean Paul 	.type			= EXYNOS_DISPLAY_TYPE_HDMI,
1187f041b257SSean Paul 	.ops			= &mixer_manager_ops,
1188d8408326SSeung-Woo Kim };
1189d8408326SSeung-Woo Kim 
1190def5e095SRahul Sharma static struct mixer_drv_data exynos5420_mxr_drv_data = {
1191def5e095SRahul Sharma 	.version = MXR_VER_128_0_0_184,
1192def5e095SRahul Sharma 	.is_vp_enabled = 0,
1193def5e095SRahul Sharma };
1194def5e095SRahul Sharma 
1195cc57caf0SRahul Sharma static struct mixer_drv_data exynos5250_mxr_drv_data = {
1196aaf8b49eSRahul Sharma 	.version = MXR_VER_16_0_33_0,
1197aaf8b49eSRahul Sharma 	.is_vp_enabled = 0,
1198aaf8b49eSRahul Sharma };
1199aaf8b49eSRahul Sharma 
1200*ff830c96SMarek Szyprowski static struct mixer_drv_data exynos4212_mxr_drv_data = {
1201*ff830c96SMarek Szyprowski 	.version = MXR_VER_0_0_0_16,
1202*ff830c96SMarek Szyprowski 	.is_vp_enabled = 1,
1203*ff830c96SMarek Szyprowski };
1204*ff830c96SMarek Szyprowski 
1205cc57caf0SRahul Sharma static struct mixer_drv_data exynos4210_mxr_drv_data = {
12061e123441SRahul Sharma 	.version = MXR_VER_0_0_0_16,
12071b8e5747SRahul Sharma 	.is_vp_enabled = 1,
1208*ff830c96SMarek Szyprowski 	.has_sclk = 1,
12091e123441SRahul Sharma };
12101e123441SRahul Sharma 
12111e123441SRahul Sharma static struct platform_device_id mixer_driver_types[] = {
12121e123441SRahul Sharma 	{
12131e123441SRahul Sharma 		.name		= "s5p-mixer",
1214cc57caf0SRahul Sharma 		.driver_data	= (unsigned long)&exynos4210_mxr_drv_data,
12151e123441SRahul Sharma 	}, {
1216aaf8b49eSRahul Sharma 		.name		= "exynos5-mixer",
1217cc57caf0SRahul Sharma 		.driver_data	= (unsigned long)&exynos5250_mxr_drv_data,
1218aaf8b49eSRahul Sharma 	}, {
1219aaf8b49eSRahul Sharma 		/* end node */
1220aaf8b49eSRahul Sharma 	}
1221aaf8b49eSRahul Sharma };
1222aaf8b49eSRahul Sharma 
1223aaf8b49eSRahul Sharma static struct of_device_id mixer_match_types[] = {
1224aaf8b49eSRahul Sharma 	{
1225*ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4210-mixer",
1226*ff830c96SMarek Szyprowski 		.data	= &exynos4210_mxr_drv_data,
1227*ff830c96SMarek Szyprowski 	}, {
1228*ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4212-mixer",
1229*ff830c96SMarek Szyprowski 		.data	= &exynos4212_mxr_drv_data,
1230*ff830c96SMarek Szyprowski 	}, {
1231aaf8b49eSRahul Sharma 		.compatible = "samsung,exynos5-mixer",
1232cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1233cc57caf0SRahul Sharma 	}, {
1234cc57caf0SRahul Sharma 		.compatible = "samsung,exynos5250-mixer",
1235cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1236aaf8b49eSRahul Sharma 	}, {
1237def5e095SRahul Sharma 		.compatible = "samsung,exynos5420-mixer",
1238def5e095SRahul Sharma 		.data	= &exynos5420_mxr_drv_data,
1239def5e095SRahul Sharma 	}, {
12401e123441SRahul Sharma 		/* end node */
12411e123441SRahul Sharma 	}
12421e123441SRahul Sharma };
12431e123441SRahul Sharma 
1244f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data)
1245d8408326SSeung-Woo Kim {
1246f37cd5e8SInki Dae 	struct platform_device *pdev = to_platform_device(dev);
1247f37cd5e8SInki Dae 	struct drm_device *drm_dev = data;
1248d8408326SSeung-Woo Kim 	struct mixer_context *ctx;
12491e123441SRahul Sharma 	struct mixer_drv_data *drv;
1250f37cd5e8SInki Dae 	int ret;
1251d8408326SSeung-Woo Kim 
1252d8408326SSeung-Woo Kim 	dev_info(dev, "probe start\n");
1253d8408326SSeung-Woo Kim 
1254f041b257SSean Paul 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1255f041b257SSean Paul 	if (!ctx) {
1256f041b257SSean Paul 		DRM_ERROR("failed to alloc mixer context.\n");
1257d8408326SSeung-Woo Kim 		return -ENOMEM;
1258f041b257SSean Paul 	}
1259d8408326SSeung-Woo Kim 
1260cf8fc4f1SJoonyoung Shim 	mutex_init(&ctx->mixer_mutex);
1261cf8fc4f1SJoonyoung Shim 
1262aaf8b49eSRahul Sharma 	if (dev->of_node) {
1263aaf8b49eSRahul Sharma 		const struct of_device_id *match;
1264e436b09dSSachin Kamat 		match = of_match_node(mixer_match_types, dev->of_node);
12652cdc53b3SRahul Sharma 		drv = (struct mixer_drv_data *)match->data;
1266aaf8b49eSRahul Sharma 	} else {
1267aaf8b49eSRahul Sharma 		drv = (struct mixer_drv_data *)
1268aaf8b49eSRahul Sharma 			platform_get_device_id(pdev)->driver_data;
1269aaf8b49eSRahul Sharma 	}
1270aaf8b49eSRahul Sharma 
12714551789fSSean Paul 	ctx->pdev = pdev;
1272d873ab99SSeung-Woo Kim 	ctx->dev = dev;
12731b8e5747SRahul Sharma 	ctx->vp_enabled = drv->is_vp_enabled;
1274*ff830c96SMarek Szyprowski 	ctx->has_sclk = drv->has_sclk;
12751e123441SRahul Sharma 	ctx->mxr_ver = drv->version;
127657ed0f7bSDaniel Vetter 	init_waitqueue_head(&ctx->wait_vsync_queue);
12776e95d5e6SPrathyush K 	atomic_set(&ctx->wait_vsync_event, 0);
1278d8408326SSeung-Woo Kim 
1279f041b257SSean Paul 	mixer_manager.ctx = ctx;
1280f37cd5e8SInki Dae 	ret = mixer_initialize(&mixer_manager, drm_dev);
1281f37cd5e8SInki Dae 	if (ret)
1282f37cd5e8SInki Dae 		return ret;
1283f37cd5e8SInki Dae 
1284f041b257SSean Paul 	platform_set_drvdata(pdev, &mixer_manager);
1285f37cd5e8SInki Dae 	ret = exynos_drm_crtc_create(&mixer_manager);
1286f37cd5e8SInki Dae 	if (ret) {
1287f37cd5e8SInki Dae 		mixer_mgr_remove(&mixer_manager);
1288f37cd5e8SInki Dae 		return ret;
1289f37cd5e8SInki Dae 	}
1290d8408326SSeung-Woo Kim 
1291cf8fc4f1SJoonyoung Shim 	pm_runtime_enable(dev);
1292d8408326SSeung-Woo Kim 
1293d8408326SSeung-Woo Kim 	return 0;
1294d8408326SSeung-Woo Kim }
1295d8408326SSeung-Woo Kim 
1296f37cd5e8SInki Dae static void mixer_unbind(struct device *dev, struct device *master, void *data)
1297f37cd5e8SInki Dae {
1298f37cd5e8SInki Dae 	struct exynos_drm_manager *mgr = dev_get_drvdata(dev);
1299f37cd5e8SInki Dae 	struct drm_crtc *crtc = mgr->crtc;
1300f37cd5e8SInki Dae 
1301f37cd5e8SInki Dae 	dev_info(dev, "remove successful\n");
1302f37cd5e8SInki Dae 
1303f37cd5e8SInki Dae 	mixer_mgr_remove(mgr);
1304f37cd5e8SInki Dae 
1305f37cd5e8SInki Dae 	pm_runtime_disable(dev);
1306f37cd5e8SInki Dae 
1307f37cd5e8SInki Dae 	crtc->funcs->destroy(crtc);
1308f37cd5e8SInki Dae }
1309f37cd5e8SInki Dae 
1310f37cd5e8SInki Dae static const struct component_ops mixer_component_ops = {
1311f37cd5e8SInki Dae 	.bind	= mixer_bind,
1312f37cd5e8SInki Dae 	.unbind	= mixer_unbind,
1313f37cd5e8SInki Dae };
1314f37cd5e8SInki Dae 
1315f37cd5e8SInki Dae static int mixer_probe(struct platform_device *pdev)
1316f37cd5e8SInki Dae {
1317df5225bcSInki Dae 	int ret;
1318df5225bcSInki Dae 
1319df5225bcSInki Dae 	ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC,
1320df5225bcSInki Dae 					mixer_manager.type);
1321df5225bcSInki Dae 	if (ret)
1322df5225bcSInki Dae 		return ret;
1323df5225bcSInki Dae 
1324df5225bcSInki Dae 	ret = component_add(&pdev->dev, &mixer_component_ops);
1325df5225bcSInki Dae 	if (ret)
1326df5225bcSInki Dae 		exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC);
1327df5225bcSInki Dae 
1328df5225bcSInki Dae 	return ret;
1329f37cd5e8SInki Dae }
1330f37cd5e8SInki Dae 
1331d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev)
1332d8408326SSeung-Woo Kim {
1333df5225bcSInki Dae 	component_del(&pdev->dev, &mixer_component_ops);
1334df5225bcSInki Dae 	exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC);
1335df5225bcSInki Dae 
1336d8408326SSeung-Woo Kim 	return 0;
1337d8408326SSeung-Woo Kim }
1338d8408326SSeung-Woo Kim 
1339d8408326SSeung-Woo Kim struct platform_driver mixer_driver = {
1340d8408326SSeung-Woo Kim 	.driver = {
1341aaf8b49eSRahul Sharma 		.name = "exynos-mixer",
1342d8408326SSeung-Woo Kim 		.owner = THIS_MODULE,
1343aaf8b49eSRahul Sharma 		.of_match_table = mixer_match_types,
1344d8408326SSeung-Woo Kim 	},
1345d8408326SSeung-Woo Kim 	.probe = mixer_probe,
134656550d94SGreg Kroah-Hartman 	.remove = mixer_remove,
13471e123441SRahul Sharma 	.id_table	= mixer_driver_types,
1348d8408326SSeung-Woo Kim };
1349