xref: /linux/drivers/gpu/drm/exynos/exynos_mixer.c (revision ab14420125c3cd1111f57731f0f9359c4e64d76a)
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"
400488f50eSMarek Szyprowski #include "exynos_drm_fb.h"
417ee14cdcSGustavo Padovan #include "exynos_drm_plane.h"
421055b39fSInki Dae #include "exynos_drm_iommu.h"
4322b21ae6SJoonyoung Shim 
44f041b257SSean Paul #define MIXER_WIN_NR		3
45fbbb1e1aSMarek Szyprowski #define VP_DEFAULT_WIN		2
46323db0edSGustavo Padovan #define CURSOR_WIN		1
47d8408326SSeung-Woo Kim 
487a57ca7cSTobias Jakobi /* The pixelformats that are natively supported by the mixer. */
497a57ca7cSTobias Jakobi #define MXR_FORMAT_RGB565	4
507a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB1555	5
517a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB4444	6
527a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB8888	7
537a57ca7cSTobias Jakobi 
5422b21ae6SJoonyoung Shim struct mixer_resources {
5522b21ae6SJoonyoung Shim 	int			irq;
5622b21ae6SJoonyoung Shim 	void __iomem		*mixer_regs;
5722b21ae6SJoonyoung Shim 	void __iomem		*vp_regs;
5822b21ae6SJoonyoung Shim 	spinlock_t		reg_slock;
5922b21ae6SJoonyoung Shim 	struct clk		*mixer;
6022b21ae6SJoonyoung Shim 	struct clk		*vp;
6104427ec5SMarek Szyprowski 	struct clk		*hdmi;
6222b21ae6SJoonyoung Shim 	struct clk		*sclk_mixer;
6322b21ae6SJoonyoung Shim 	struct clk		*sclk_hdmi;
64ff830c96SMarek Szyprowski 	struct clk		*mout_mixer;
6522b21ae6SJoonyoung Shim };
6622b21ae6SJoonyoung Shim 
671e123441SRahul Sharma enum mixer_version_id {
681e123441SRahul Sharma 	MXR_VER_0_0_0_16,
691e123441SRahul Sharma 	MXR_VER_16_0_33_0,
70def5e095SRahul Sharma 	MXR_VER_128_0_0_184,
711e123441SRahul Sharma };
721e123441SRahul Sharma 
73a44652e8SAndrzej Hajda enum mixer_flag_bits {
74a44652e8SAndrzej Hajda 	MXR_BIT_POWERED,
750df5e4acSAndrzej Hajda 	MXR_BIT_VSYNC,
76a44652e8SAndrzej Hajda };
77a44652e8SAndrzej Hajda 
78fbbb1e1aSMarek Szyprowski static const uint32_t mixer_formats[] = {
79fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB4444,
80fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB1555,
81fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_RGB565,
82fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB8888,
83fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_ARGB8888,
84fbbb1e1aSMarek Szyprowski };
85fbbb1e1aSMarek Szyprowski 
86fbbb1e1aSMarek Szyprowski static const uint32_t vp_formats[] = {
87fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_NV12,
88fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_NV21,
89fbbb1e1aSMarek Szyprowski };
90fbbb1e1aSMarek Szyprowski 
9122b21ae6SJoonyoung Shim struct mixer_context {
924551789fSSean Paul 	struct platform_device *pdev;
93cf8fc4f1SJoonyoung Shim 	struct device		*dev;
941055b39fSInki Dae 	struct drm_device	*drm_dev;
9593bca243SGustavo Padovan 	struct exynos_drm_crtc	*crtc;
967ee14cdcSGustavo Padovan 	struct exynos_drm_plane	planes[MIXER_WIN_NR];
9722b21ae6SJoonyoung Shim 	int			pipe;
98a44652e8SAndrzej Hajda 	unsigned long		flags;
9922b21ae6SJoonyoung Shim 	bool			interlace;
1001b8e5747SRahul Sharma 	bool			vp_enabled;
101ff830c96SMarek Szyprowski 	bool			has_sclk;
10222b21ae6SJoonyoung Shim 
10322b21ae6SJoonyoung Shim 	struct mixer_resources	mixer_res;
1041e123441SRahul Sharma 	enum mixer_version_id	mxr_ver;
1056e95d5e6SPrathyush K 	wait_queue_head_t	wait_vsync_queue;
1066e95d5e6SPrathyush K 	atomic_t		wait_vsync_event;
1071e123441SRahul Sharma };
1081e123441SRahul Sharma 
1091e123441SRahul Sharma struct mixer_drv_data {
1101e123441SRahul Sharma 	enum mixer_version_id	version;
1111b8e5747SRahul Sharma 	bool					is_vp_enabled;
112ff830c96SMarek Szyprowski 	bool					has_sclk;
11322b21ae6SJoonyoung Shim };
11422b21ae6SJoonyoung Shim 
115d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = {
116d8408326SSeung-Woo Kim 	0,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
117d8408326SSeung-Woo Kim 	-1,	-1,	-1,	-1,	-1,	0,	0,	0,
118d8408326SSeung-Woo Kim 	0,	2,	4,	5,	6,	6,	6,	6,
119d8408326SSeung-Woo Kim 	6,	5,	5,	4,	3,	2,	1,	1,
120d8408326SSeung-Woo Kim 	0,	-6,	-12,	-16,	-18,	-20,	-21,	-20,
121d8408326SSeung-Woo Kim 	-20,	-18,	-16,	-13,	-10,	-8,	-5,	-2,
122d8408326SSeung-Woo Kim 	127,	126,	125,	121,	114,	107,	99,	89,
123d8408326SSeung-Woo Kim 	79,	68,	57,	46,	35,	25,	16,	8,
124d8408326SSeung-Woo Kim };
125d8408326SSeung-Woo Kim 
126d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = {
127d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
128d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
129d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
130d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
131d8408326SSeung-Woo Kim 	0,	5,	11,	19,	27,	37,	48,	59,
132d8408326SSeung-Woo Kim 	70,	81,	92,	102,	111,	118,	124,	126,
133d8408326SSeung-Woo Kim 	0,	0,	-1,	-1,	-2,	-3,	-4,	-5,
134d8408326SSeung-Woo Kim 	-6,	-7,	-8,	-8,	-8,	-8,	-6,	-3,
135d8408326SSeung-Woo Kim };
136d8408326SSeung-Woo Kim 
137d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = {
138d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
139d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
140d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
141d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
142d8408326SSeung-Woo Kim };
143d8408326SSeung-Woo Kim 
144d8408326SSeung-Woo Kim static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id)
145d8408326SSeung-Woo Kim {
146d8408326SSeung-Woo Kim 	return readl(res->vp_regs + reg_id);
147d8408326SSeung-Woo Kim }
148d8408326SSeung-Woo Kim 
149d8408326SSeung-Woo Kim static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id,
150d8408326SSeung-Woo Kim 				 u32 val)
151d8408326SSeung-Woo Kim {
152d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
153d8408326SSeung-Woo Kim }
154d8408326SSeung-Woo Kim 
155d8408326SSeung-Woo Kim static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id,
156d8408326SSeung-Woo Kim 				 u32 val, u32 mask)
157d8408326SSeung-Woo Kim {
158d8408326SSeung-Woo Kim 	u32 old = vp_reg_read(res, reg_id);
159d8408326SSeung-Woo Kim 
160d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
161d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
162d8408326SSeung-Woo Kim }
163d8408326SSeung-Woo Kim 
164d8408326SSeung-Woo Kim static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id)
165d8408326SSeung-Woo Kim {
166d8408326SSeung-Woo Kim 	return readl(res->mixer_regs + reg_id);
167d8408326SSeung-Woo Kim }
168d8408326SSeung-Woo Kim 
169d8408326SSeung-Woo Kim static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id,
170d8408326SSeung-Woo Kim 				 u32 val)
171d8408326SSeung-Woo Kim {
172d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
173d8408326SSeung-Woo Kim }
174d8408326SSeung-Woo Kim 
175d8408326SSeung-Woo Kim static inline void mixer_reg_writemask(struct mixer_resources *res,
176d8408326SSeung-Woo Kim 				 u32 reg_id, u32 val, u32 mask)
177d8408326SSeung-Woo Kim {
178d8408326SSeung-Woo Kim 	u32 old = mixer_reg_read(res, reg_id);
179d8408326SSeung-Woo Kim 
180d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
181d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
182d8408326SSeung-Woo Kim }
183d8408326SSeung-Woo Kim 
184d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx)
185d8408326SSeung-Woo Kim {
186d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
187d8408326SSeung-Woo Kim do { \
188d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
189d8408326SSeung-Woo Kim 		(u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \
190d8408326SSeung-Woo Kim } while (0)
191d8408326SSeung-Woo Kim 
192d8408326SSeung-Woo Kim 	DUMPREG(MXR_STATUS);
193d8408326SSeung-Woo Kim 	DUMPREG(MXR_CFG);
194d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_EN);
195d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_STATUS);
196d8408326SSeung-Woo Kim 
197d8408326SSeung-Woo Kim 	DUMPREG(MXR_LAYER_CFG);
198d8408326SSeung-Woo Kim 	DUMPREG(MXR_VIDEO_CFG);
199d8408326SSeung-Woo Kim 
200d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_CFG);
201d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_BASE);
202d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SPAN);
203d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_WH);
204d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SXY);
205d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_DXY);
206d8408326SSeung-Woo Kim 
207d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_CFG);
208d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_BASE);
209d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SPAN);
210d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_WH);
211d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SXY);
212d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_DXY);
213d8408326SSeung-Woo Kim #undef DUMPREG
214d8408326SSeung-Woo Kim }
215d8408326SSeung-Woo Kim 
216d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx)
217d8408326SSeung-Woo Kim {
218d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
219d8408326SSeung-Woo Kim do { \
220d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
221d8408326SSeung-Woo Kim 		(u32) readl(ctx->mixer_res.vp_regs + reg_id)); \
222d8408326SSeung-Woo Kim } while (0)
223d8408326SSeung-Woo Kim 
224d8408326SSeung-Woo Kim 	DUMPREG(VP_ENABLE);
225d8408326SSeung-Woo Kim 	DUMPREG(VP_SRESET);
226d8408326SSeung-Woo Kim 	DUMPREG(VP_SHADOW_UPDATE);
227d8408326SSeung-Woo Kim 	DUMPREG(VP_FIELD_ID);
228d8408326SSeung-Woo Kim 	DUMPREG(VP_MODE);
229d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_Y);
230d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_C);
231d8408326SSeung-Woo Kim 	DUMPREG(VP_PER_RATE_CTRL);
232d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_Y_PTR);
233d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_Y_PTR);
234d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_C_PTR);
235d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_C_PTR);
236d8408326SSeung-Woo Kim 	DUMPREG(VP_ENDIAN_MODE);
237d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_H_POSITION);
238d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_V_POSITION);
239d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_WIDTH);
240d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_HEIGHT);
241d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_H_POSITION);
242d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_V_POSITION);
243d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_WIDTH);
244d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_HEIGHT);
245d8408326SSeung-Woo Kim 	DUMPREG(VP_H_RATIO);
246d8408326SSeung-Woo Kim 	DUMPREG(VP_V_RATIO);
247d8408326SSeung-Woo Kim 
248d8408326SSeung-Woo Kim #undef DUMPREG
249d8408326SSeung-Woo Kim }
250d8408326SSeung-Woo Kim 
251d8408326SSeung-Woo Kim static inline void vp_filter_set(struct mixer_resources *res,
252d8408326SSeung-Woo Kim 		int reg_id, const u8 *data, unsigned int size)
253d8408326SSeung-Woo Kim {
254d8408326SSeung-Woo Kim 	/* assure 4-byte align */
255d8408326SSeung-Woo Kim 	BUG_ON(size & 3);
256d8408326SSeung-Woo Kim 	for (; size; size -= 4, reg_id += 4, data += 4) {
257d8408326SSeung-Woo Kim 		u32 val = (data[0] << 24) |  (data[1] << 16) |
258d8408326SSeung-Woo Kim 			(data[2] << 8) | data[3];
259d8408326SSeung-Woo Kim 		vp_reg_write(res, reg_id, val);
260d8408326SSeung-Woo Kim 	}
261d8408326SSeung-Woo Kim }
262d8408326SSeung-Woo Kim 
263d8408326SSeung-Woo Kim static void vp_default_filter(struct mixer_resources *res)
264d8408326SSeung-Woo Kim {
265d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY8_Y0_LL,
266e25e1b66SSachin Kamat 		filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
267d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_Y0_LL,
268e25e1b66SSachin Kamat 		filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
269d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_C0_LL,
270e25e1b66SSachin Kamat 		filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
271d8408326SSeung-Woo Kim }
272d8408326SSeung-Woo Kim 
273d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable)
274d8408326SSeung-Woo Kim {
275d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
276d8408326SSeung-Woo Kim 
277d8408326SSeung-Woo Kim 	/* block update on vsync */
278d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, enable ?
279d8408326SSeung-Woo Kim 			MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE);
280d8408326SSeung-Woo Kim 
2811b8e5747SRahul Sharma 	if (ctx->vp_enabled)
282d8408326SSeung-Woo Kim 		vp_reg_write(res, VP_SHADOW_UPDATE, enable ?
283d8408326SSeung-Woo Kim 			VP_SHADOW_UPDATE_ENABLE : 0);
284d8408326SSeung-Woo Kim }
285d8408326SSeung-Woo Kim 
286d8408326SSeung-Woo Kim static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height)
287d8408326SSeung-Woo Kim {
288d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
289d8408326SSeung-Woo Kim 	u32 val;
290d8408326SSeung-Woo Kim 
291d8408326SSeung-Woo Kim 	/* choosing between interlace and progressive mode */
292d8408326SSeung-Woo Kim 	val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE :
2931e6d459dSTobias Jakobi 				MXR_CFG_SCAN_PROGRESSIVE);
294d8408326SSeung-Woo Kim 
295def5e095SRahul Sharma 	if (ctx->mxr_ver != MXR_VER_128_0_0_184) {
296def5e095SRahul Sharma 		/* choosing between proper HD and SD mode */
29729630743SRahul Sharma 		if (height <= 480)
298d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD;
29929630743SRahul Sharma 		else if (height <= 576)
300d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD;
30129630743SRahul Sharma 		else if (height <= 720)
302d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
30329630743SRahul Sharma 		else if (height <= 1080)
304d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD;
305d8408326SSeung-Woo Kim 		else
306d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
307def5e095SRahul Sharma 	}
308d8408326SSeung-Woo Kim 
309d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK);
310d8408326SSeung-Woo Kim }
311d8408326SSeung-Woo Kim 
312d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height)
313d8408326SSeung-Woo Kim {
314d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
315d8408326SSeung-Woo Kim 	u32 val;
316d8408326SSeung-Woo Kim 
317d8408326SSeung-Woo Kim 	if (height == 480) {
318d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
319d8408326SSeung-Woo Kim 	} else if (height == 576) {
320d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
321d8408326SSeung-Woo Kim 	} else if (height == 720) {
322d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
323d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
324d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
325d8408326SSeung-Woo Kim 				(32 << 0));
326d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
327d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
328d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
329d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
330d8408326SSeung-Woo Kim 	} else if (height == 1080) {
331d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
332d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
333d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
334d8408326SSeung-Woo Kim 				(32 << 0));
335d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
336d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
337d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
338d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
339d8408326SSeung-Woo Kim 	} else {
340d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
341d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
342d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
343d8408326SSeung-Woo Kim 				(32 << 0));
344d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
345d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
346d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
347d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
348d8408326SSeung-Woo Kim 	}
349d8408326SSeung-Woo Kim 
350d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
351d8408326SSeung-Woo Kim }
352d8408326SSeung-Woo Kim 
3535b1d5bc6STobias Jakobi static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win,
3545b1d5bc6STobias Jakobi 				bool enable)
355d8408326SSeung-Woo Kim {
356d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
357d8408326SSeung-Woo Kim 	u32 val = enable ? ~0 : 0;
358d8408326SSeung-Woo Kim 
359d8408326SSeung-Woo Kim 	switch (win) {
360d8408326SSeung-Woo Kim 	case 0:
361d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
362d8408326SSeung-Woo Kim 		break;
363d8408326SSeung-Woo Kim 	case 1:
364d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
365d8408326SSeung-Woo Kim 		break;
366d8408326SSeung-Woo Kim 	case 2:
3671b8e5747SRahul Sharma 		if (ctx->vp_enabled) {
368d8408326SSeung-Woo Kim 			vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON);
3691b8e5747SRahul Sharma 			mixer_reg_writemask(res, MXR_CFG, val,
3701b8e5747SRahul Sharma 				MXR_CFG_VP_ENABLE);
371f1e716d8SJoonyoung Shim 
372f1e716d8SJoonyoung Shim 			/* control blending of graphic layer 0 */
373f1e716d8SJoonyoung Shim 			mixer_reg_writemask(res, MXR_GRAPHIC_CFG(0), val,
374f1e716d8SJoonyoung Shim 					MXR_GRP_CFG_BLEND_PRE_MUL |
375f1e716d8SJoonyoung Shim 					MXR_GRP_CFG_PIXEL_BLEND_EN);
3761b8e5747SRahul Sharma 		}
377d8408326SSeung-Woo Kim 		break;
378d8408326SSeung-Woo Kim 	}
379d8408326SSeung-Woo Kim }
380d8408326SSeung-Woo Kim 
381d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx)
382d8408326SSeung-Woo Kim {
383d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
384d8408326SSeung-Woo Kim 
385d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
386d8408326SSeung-Woo Kim }
387d8408326SSeung-Woo Kim 
388381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx)
389381be025SRahul Sharma {
390381be025SRahul Sharma 	struct mixer_resources *res = &ctx->mixer_res;
391381be025SRahul Sharma 	int timeout = 20;
392381be025SRahul Sharma 
393381be025SRahul Sharma 	mixer_reg_writemask(res, MXR_STATUS, 0, MXR_STATUS_REG_RUN);
394381be025SRahul Sharma 
395381be025SRahul Sharma 	while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
396381be025SRahul Sharma 			--timeout)
397381be025SRahul Sharma 		usleep_range(10000, 12000);
398381be025SRahul Sharma }
399381be025SRahul Sharma 
4002eeb2e5eSGustavo Padovan static void vp_video_buffer(struct mixer_context *ctx,
4012eeb2e5eSGustavo Padovan 			    struct exynos_drm_plane *plane)
402d8408326SSeung-Woo Kim {
4030114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
4040114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
4052ee35d8bSMarek Szyprowski 	struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode;
406d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
4070114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
408d8408326SSeung-Woo Kim 	unsigned long flags;
409d8408326SSeung-Woo Kim 	dma_addr_t luma_addr[2], chroma_addr[2];
410d8408326SSeung-Woo Kim 	bool tiled_mode = false;
411d8408326SSeung-Woo Kim 	bool crcb_mode = false;
412d8408326SSeung-Woo Kim 	u32 val;
413d8408326SSeung-Woo Kim 
4142eeb2e5eSGustavo Padovan 	switch (fb->pixel_format) {
415363b06aaSVille Syrjälä 	case DRM_FORMAT_NV12:
416d8408326SSeung-Woo Kim 		crcb_mode = false;
417d8408326SSeung-Woo Kim 		break;
4188f2590f8STobias Jakobi 	case DRM_FORMAT_NV21:
4198f2590f8STobias Jakobi 		crcb_mode = true;
4208f2590f8STobias Jakobi 		break;
421d8408326SSeung-Woo Kim 	default:
422d8408326SSeung-Woo Kim 		DRM_ERROR("pixel format for vp is wrong [%d].\n",
4232eeb2e5eSGustavo Padovan 				fb->pixel_format);
424d8408326SSeung-Woo Kim 		return;
425d8408326SSeung-Woo Kim 	}
426d8408326SSeung-Woo Kim 
4270488f50eSMarek Szyprowski 	luma_addr[0] = exynos_drm_fb_dma_addr(fb, 0);
4280488f50eSMarek Szyprowski 	chroma_addr[0] = exynos_drm_fb_dma_addr(fb, 1);
429d8408326SSeung-Woo Kim 
4302eeb2e5eSGustavo Padovan 	if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
431d8408326SSeung-Woo Kim 		ctx->interlace = true;
432d8408326SSeung-Woo Kim 		if (tiled_mode) {
433d8408326SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + 0x40;
434d8408326SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + 0x40;
435d8408326SSeung-Woo Kim 		} else {
4362eeb2e5eSGustavo Padovan 			luma_addr[1] = luma_addr[0] + fb->pitches[0];
4372eeb2e5eSGustavo Padovan 			chroma_addr[1] = chroma_addr[0] + fb->pitches[0];
438d8408326SSeung-Woo Kim 		}
439d8408326SSeung-Woo Kim 	} else {
440d8408326SSeung-Woo Kim 		ctx->interlace = false;
441d8408326SSeung-Woo Kim 		luma_addr[1] = 0;
442d8408326SSeung-Woo Kim 		chroma_addr[1] = 0;
443d8408326SSeung-Woo Kim 	}
444d8408326SSeung-Woo Kim 
445d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
446d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
447d8408326SSeung-Woo Kim 
448d8408326SSeung-Woo Kim 	/* interlace or progressive scan mode */
449d8408326SSeung-Woo Kim 	val = (ctx->interlace ? ~0 : 0);
450d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP);
451d8408326SSeung-Woo Kim 
452d8408326SSeung-Woo Kim 	/* setup format */
453d8408326SSeung-Woo Kim 	val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12);
454d8408326SSeung-Woo Kim 	val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
455d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK);
456d8408326SSeung-Woo Kim 
457d8408326SSeung-Woo Kim 	/* setting size of input image */
4582eeb2e5eSGustavo Padovan 	vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) |
4592eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height));
460d8408326SSeung-Woo Kim 	/* chroma height has to reduced by 2 to avoid chroma distorions */
4612eeb2e5eSGustavo Padovan 	vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[0]) |
4622eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height / 2));
463d8408326SSeung-Woo Kim 
4640114f404SMarek Szyprowski 	vp_reg_write(res, VP_SRC_WIDTH, state->src.w);
4650114f404SMarek Szyprowski 	vp_reg_write(res, VP_SRC_HEIGHT, state->src.h);
466d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_H_POSITION,
4670114f404SMarek Szyprowski 			VP_SRC_H_POSITION_VAL(state->src.x));
4680114f404SMarek Szyprowski 	vp_reg_write(res, VP_SRC_V_POSITION, state->src.y);
469d8408326SSeung-Woo Kim 
4700114f404SMarek Szyprowski 	vp_reg_write(res, VP_DST_WIDTH, state->crtc.w);
4710114f404SMarek Szyprowski 	vp_reg_write(res, VP_DST_H_POSITION, state->crtc.x);
472d8408326SSeung-Woo Kim 	if (ctx->interlace) {
4730114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h / 2);
4740114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y / 2);
475d8408326SSeung-Woo Kim 	} else {
4760114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h);
4770114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y);
478d8408326SSeung-Woo Kim 	}
479d8408326SSeung-Woo Kim 
4800114f404SMarek Szyprowski 	vp_reg_write(res, VP_H_RATIO, state->h_ratio);
4810114f404SMarek Szyprowski 	vp_reg_write(res, VP_V_RATIO, state->v_ratio);
482d8408326SSeung-Woo Kim 
483d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
484d8408326SSeung-Woo Kim 
485d8408326SSeung-Woo Kim 	/* set buffer address to vp */
486d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]);
487d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]);
488d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]);
489d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]);
490d8408326SSeung-Woo Kim 
4912eeb2e5eSGustavo Padovan 	mixer_cfg_scan(ctx, mode->vdisplay);
4922eeb2e5eSGustavo Padovan 	mixer_cfg_rgb_fmt(ctx, mode->vdisplay);
4932eeb2e5eSGustavo Padovan 	mixer_cfg_layer(ctx, plane->zpos, true);
494d8408326SSeung-Woo Kim 	mixer_run(ctx);
495d8408326SSeung-Woo Kim 
496d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
497d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
498d8408326SSeung-Woo Kim 
499c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
500d8408326SSeung-Woo Kim 	vp_regs_dump(ctx);
501d8408326SSeung-Woo Kim }
502d8408326SSeung-Woo Kim 
503aaf8b49eSRahul Sharma static void mixer_layer_update(struct mixer_context *ctx)
504aaf8b49eSRahul Sharma {
505aaf8b49eSRahul Sharma 	struct mixer_resources *res = &ctx->mixer_res;
506aaf8b49eSRahul Sharma 
507aaf8b49eSRahul Sharma 	mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
508aaf8b49eSRahul Sharma }
509aaf8b49eSRahul Sharma 
5102611015cSTobias Jakobi static int mixer_setup_scale(const struct exynos_drm_plane *plane,
5112611015cSTobias Jakobi 		unsigned int *x_ratio, unsigned int *y_ratio)
5122611015cSTobias Jakobi {
5130114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
5140114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
5150114f404SMarek Szyprowski 
5160114f404SMarek Szyprowski 	if (state->crtc.w != state->src.w) {
5170114f404SMarek Szyprowski 		if (state->crtc.w == 2 * state->src.w)
5182611015cSTobias Jakobi 			*x_ratio = 1;
5192611015cSTobias Jakobi 		else
5202611015cSTobias Jakobi 			goto fail;
5212611015cSTobias Jakobi 	}
5222611015cSTobias Jakobi 
5230114f404SMarek Szyprowski 	if (state->crtc.h != state->src.h) {
5240114f404SMarek Szyprowski 		if (state->crtc.h == 2 * state->src.h)
5252611015cSTobias Jakobi 			*y_ratio = 1;
5262611015cSTobias Jakobi 		else
5272611015cSTobias Jakobi 			goto fail;
5282611015cSTobias Jakobi 	}
5292611015cSTobias Jakobi 
5302611015cSTobias Jakobi 	return 0;
5312611015cSTobias Jakobi 
5322611015cSTobias Jakobi fail:
5332611015cSTobias Jakobi 	DRM_DEBUG_KMS("only 2x width/height scaling of plane supported\n");
5342611015cSTobias Jakobi 	return -ENOTSUPP;
5352611015cSTobias Jakobi }
5362611015cSTobias Jakobi 
5372eeb2e5eSGustavo Padovan static void mixer_graph_buffer(struct mixer_context *ctx,
5382eeb2e5eSGustavo Padovan 			       struct exynos_drm_plane *plane)
539d8408326SSeung-Woo Kim {
5400114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
5410114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
5422ee35d8bSMarek Szyprowski 	struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode;
543d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
5440114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
545d8408326SSeung-Woo Kim 	unsigned long flags;
5462eeb2e5eSGustavo Padovan 	unsigned int win = plane->zpos;
5472611015cSTobias Jakobi 	unsigned int x_ratio = 0, y_ratio = 0;
548d8408326SSeung-Woo Kim 	unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset;
549d8408326SSeung-Woo Kim 	dma_addr_t dma_addr;
550d8408326SSeung-Woo Kim 	unsigned int fmt;
551d8408326SSeung-Woo Kim 	u32 val;
552d8408326SSeung-Woo Kim 
5532eeb2e5eSGustavo Padovan 	switch (fb->pixel_format) {
5547a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB4444:
5557a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB4444;
5567a57ca7cSTobias Jakobi 		break;
557d8408326SSeung-Woo Kim 
5587a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB1555:
5597a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB1555;
560d8408326SSeung-Woo Kim 		break;
5617a57ca7cSTobias Jakobi 
5627a57ca7cSTobias Jakobi 	case DRM_FORMAT_RGB565:
5637a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_RGB565;
564d8408326SSeung-Woo Kim 		break;
5657a57ca7cSTobias Jakobi 
5667a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB8888:
5677a57ca7cSTobias Jakobi 	case DRM_FORMAT_ARGB8888:
5687a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB8888;
5697a57ca7cSTobias Jakobi 		break;
5707a57ca7cSTobias Jakobi 
571d8408326SSeung-Woo Kim 	default:
5727a57ca7cSTobias Jakobi 		DRM_DEBUG_KMS("pixelformat unsupported by mixer\n");
5737a57ca7cSTobias Jakobi 		return;
574d8408326SSeung-Woo Kim 	}
575d8408326SSeung-Woo Kim 
5762611015cSTobias Jakobi 	/* check if mixer supports requested scaling setup */
5772611015cSTobias Jakobi 	if (mixer_setup_scale(plane, &x_ratio, &y_ratio))
5782611015cSTobias Jakobi 		return;
579d8408326SSeung-Woo Kim 
5800114f404SMarek Szyprowski 	dst_x_offset = state->crtc.x;
5810114f404SMarek Szyprowski 	dst_y_offset = state->crtc.y;
582d8408326SSeung-Woo Kim 
583d8408326SSeung-Woo Kim 	/* converting dma address base and source offset */
5840488f50eSMarek Szyprowski 	dma_addr = exynos_drm_fb_dma_addr(fb, 0)
5850114f404SMarek Szyprowski 		+ (state->src.x * fb->bits_per_pixel >> 3)
5860114f404SMarek Szyprowski 		+ (state->src.y * fb->pitches[0]);
587d8408326SSeung-Woo Kim 	src_x_offset = 0;
588d8408326SSeung-Woo Kim 	src_y_offset = 0;
589d8408326SSeung-Woo Kim 
5902eeb2e5eSGustavo Padovan 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
591d8408326SSeung-Woo Kim 		ctx->interlace = true;
592d8408326SSeung-Woo Kim 	else
593d8408326SSeung-Woo Kim 		ctx->interlace = false;
594d8408326SSeung-Woo Kim 
595d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
596d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
597d8408326SSeung-Woo Kim 
598d8408326SSeung-Woo Kim 	/* setup format */
599d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
600d8408326SSeung-Woo Kim 		MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
601d8408326SSeung-Woo Kim 
602d8408326SSeung-Woo Kim 	/* setup geometry */
603adacb228SDaniel Stone 	mixer_reg_write(res, MXR_GRAPHIC_SPAN(win),
6042eeb2e5eSGustavo Padovan 			fb->pitches[0] / (fb->bits_per_pixel >> 3));
605d8408326SSeung-Woo Kim 
606def5e095SRahul Sharma 	/* setup display size */
607def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_128_0_0_184 &&
6085d3d0995SGustavo Padovan 		win == DEFAULT_WIN) {
6092eeb2e5eSGustavo Padovan 		val  = MXR_MXR_RES_HEIGHT(mode->vdisplay);
6102eeb2e5eSGustavo Padovan 		val |= MXR_MXR_RES_WIDTH(mode->hdisplay);
611def5e095SRahul Sharma 		mixer_reg_write(res, MXR_RESOLUTION, val);
612def5e095SRahul Sharma 	}
613def5e095SRahul Sharma 
6140114f404SMarek Szyprowski 	val  = MXR_GRP_WH_WIDTH(state->src.w);
6150114f404SMarek Szyprowski 	val |= MXR_GRP_WH_HEIGHT(state->src.h);
616d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_H_SCALE(x_ratio);
617d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_V_SCALE(y_ratio);
618d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_WH(win), val);
619d8408326SSeung-Woo Kim 
620d8408326SSeung-Woo Kim 	/* setup offsets in source image */
621d8408326SSeung-Woo Kim 	val  = MXR_GRP_SXY_SX(src_x_offset);
622d8408326SSeung-Woo Kim 	val |= MXR_GRP_SXY_SY(src_y_offset);
623d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val);
624d8408326SSeung-Woo Kim 
625d8408326SSeung-Woo Kim 	/* setup offsets in display image */
626d8408326SSeung-Woo Kim 	val  = MXR_GRP_DXY_DX(dst_x_offset);
627d8408326SSeung-Woo Kim 	val |= MXR_GRP_DXY_DY(dst_y_offset);
628d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val);
629d8408326SSeung-Woo Kim 
630d8408326SSeung-Woo Kim 	/* set buffer address to mixer */
631d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr);
632d8408326SSeung-Woo Kim 
6332eeb2e5eSGustavo Padovan 	mixer_cfg_scan(ctx, mode->vdisplay);
6342eeb2e5eSGustavo Padovan 	mixer_cfg_rgb_fmt(ctx, mode->vdisplay);
635d8408326SSeung-Woo Kim 	mixer_cfg_layer(ctx, win, true);
636aaf8b49eSRahul Sharma 
637aaf8b49eSRahul Sharma 	/* layer update mandatory for mixer 16.0.33.0 */
638def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
639def5e095SRahul Sharma 		ctx->mxr_ver == MXR_VER_128_0_0_184)
640aaf8b49eSRahul Sharma 		mixer_layer_update(ctx);
641aaf8b49eSRahul Sharma 
642d8408326SSeung-Woo Kim 	mixer_run(ctx);
643d8408326SSeung-Woo Kim 
644d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
645d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
646c0734fbaSTobias Jakobi 
647c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
648d8408326SSeung-Woo Kim }
649d8408326SSeung-Woo Kim 
650d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx)
651d8408326SSeung-Woo Kim {
652d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
653d8408326SSeung-Woo Kim 	int tries = 100;
654d8408326SSeung-Woo Kim 
655d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING);
656d8408326SSeung-Woo Kim 	for (tries = 100; tries; --tries) {
657d8408326SSeung-Woo Kim 		/* waiting until VP_SRESET_PROCESSING is 0 */
658d8408326SSeung-Woo Kim 		if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING)
659d8408326SSeung-Woo Kim 			break;
66002b3de43STomasz Stanislawski 		mdelay(10);
661d8408326SSeung-Woo Kim 	}
662d8408326SSeung-Woo Kim 	WARN(tries == 0, "failed to reset Video Processor\n");
663d8408326SSeung-Woo Kim }
664d8408326SSeung-Woo Kim 
665cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx)
666cf8fc4f1SJoonyoung Shim {
667cf8fc4f1SJoonyoung Shim 	struct mixer_resources *res = &ctx->mixer_res;
668cf8fc4f1SJoonyoung Shim 	unsigned long flags;
669cf8fc4f1SJoonyoung Shim 	u32 val; /* value stored to register */
670cf8fc4f1SJoonyoung Shim 
671cf8fc4f1SJoonyoung Shim 	spin_lock_irqsave(&res->reg_slock, flags);
672cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, false);
673cf8fc4f1SJoonyoung Shim 
674cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
675cf8fc4f1SJoonyoung Shim 
676cf8fc4f1SJoonyoung Shim 	/* set output in RGB888 mode */
677cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
678cf8fc4f1SJoonyoung Shim 
679cf8fc4f1SJoonyoung Shim 	/* 16 beat burst in DMA */
680cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST,
681cf8fc4f1SJoonyoung Shim 		MXR_STATUS_BURST_MASK);
682cf8fc4f1SJoonyoung Shim 
683cf8fc4f1SJoonyoung Shim 	/* setting default layer priority: layer1 > layer0 > video
684cf8fc4f1SJoonyoung Shim 	 * because typical usage scenario would be
685cf8fc4f1SJoonyoung Shim 	 * layer1 - OSD
686cf8fc4f1SJoonyoung Shim 	 * layer0 - framebuffer
687cf8fc4f1SJoonyoung Shim 	 * video - video overlay
688cf8fc4f1SJoonyoung Shim 	 */
689cf8fc4f1SJoonyoung Shim 	val = MXR_LAYER_CFG_GRP1_VAL(3);
690cf8fc4f1SJoonyoung Shim 	val |= MXR_LAYER_CFG_GRP0_VAL(2);
6911b8e5747SRahul Sharma 	if (ctx->vp_enabled)
692cf8fc4f1SJoonyoung Shim 		val |= MXR_LAYER_CFG_VP_VAL(1);
693cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_LAYER_CFG, val);
694cf8fc4f1SJoonyoung Shim 
695cf8fc4f1SJoonyoung Shim 	/* setting background color */
696cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR0, 0x008080);
697cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR1, 0x008080);
698cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR2, 0x008080);
699cf8fc4f1SJoonyoung Shim 
700cf8fc4f1SJoonyoung Shim 	/* setting graphical layers */
701cf8fc4f1SJoonyoung Shim 	val  = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
702cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_WIN_BLEND_EN;
703cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_ALPHA_VAL(0xff); /* non-transparent alpha */
704cf8fc4f1SJoonyoung Shim 
7050377f4edSSean Paul 	/* Don't blend layer 0 onto the mixer background */
706cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(0), val);
7070377f4edSSean Paul 
7080377f4edSSean Paul 	/* Blend layer 1 into layer 0 */
7090377f4edSSean Paul 	val |= MXR_GRP_CFG_BLEND_PRE_MUL;
7100377f4edSSean Paul 	val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
711cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(1), val);
712cf8fc4f1SJoonyoung Shim 
7135736603bSSeung-Woo Kim 	/* setting video layers */
7145736603bSSeung-Woo Kim 	val = MXR_GRP_CFG_ALPHA_VAL(0);
7155736603bSSeung-Woo Kim 	mixer_reg_write(res, MXR_VIDEO_CFG, val);
7165736603bSSeung-Woo Kim 
7171b8e5747SRahul Sharma 	if (ctx->vp_enabled) {
718cf8fc4f1SJoonyoung Shim 		/* configuration of Video Processor Registers */
719cf8fc4f1SJoonyoung Shim 		vp_win_reset(ctx);
720cf8fc4f1SJoonyoung Shim 		vp_default_filter(res);
7211b8e5747SRahul Sharma 	}
722cf8fc4f1SJoonyoung Shim 
723cf8fc4f1SJoonyoung Shim 	/* disable all layers */
724cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
725cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
7261b8e5747SRahul Sharma 	if (ctx->vp_enabled)
727cf8fc4f1SJoonyoung Shim 		mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
728cf8fc4f1SJoonyoung Shim 
729cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, true);
730cf8fc4f1SJoonyoung Shim 	spin_unlock_irqrestore(&res->reg_slock, flags);
731cf8fc4f1SJoonyoung Shim }
732cf8fc4f1SJoonyoung Shim 
7334551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg)
7344551789fSSean Paul {
7354551789fSSean Paul 	struct mixer_context *ctx = arg;
7364551789fSSean Paul 	struct mixer_resources *res = &ctx->mixer_res;
7374551789fSSean Paul 	u32 val, base, shadow;
738822f6dfdSGustavo Padovan 	int win;
7394551789fSSean Paul 
7404551789fSSean Paul 	spin_lock(&res->reg_slock);
7414551789fSSean Paul 
7424551789fSSean Paul 	/* read interrupt status for handling and clearing flags for VSYNC */
7434551789fSSean Paul 	val = mixer_reg_read(res, MXR_INT_STATUS);
7444551789fSSean Paul 
7454551789fSSean Paul 	/* handling VSYNC */
7464551789fSSean Paul 	if (val & MXR_INT_STATUS_VSYNC) {
74781a464dfSAndrzej Hajda 		/* vsync interrupt use different bit for read and clear */
74881a464dfSAndrzej Hajda 		val |= MXR_INT_CLEAR_VSYNC;
74981a464dfSAndrzej Hajda 		val &= ~MXR_INT_STATUS_VSYNC;
75081a464dfSAndrzej Hajda 
7514551789fSSean Paul 		/* interlace scan need to check shadow register */
7524551789fSSean Paul 		if (ctx->interlace) {
7534551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0));
7544551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0));
7554551789fSSean Paul 			if (base != shadow)
7564551789fSSean Paul 				goto out;
7574551789fSSean Paul 
7584551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1));
7594551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1));
7604551789fSSean Paul 			if (base != shadow)
7614551789fSSean Paul 				goto out;
7624551789fSSean Paul 		}
7634551789fSSean Paul 
764eafd540aSGustavo Padovan 		drm_crtc_handle_vblank(&ctx->crtc->base);
765822f6dfdSGustavo Padovan 		for (win = 0 ; win < MIXER_WIN_NR ; win++) {
766822f6dfdSGustavo Padovan 			struct exynos_drm_plane *plane = &ctx->planes[win];
767822f6dfdSGustavo Padovan 
768822f6dfdSGustavo Padovan 			if (!plane->pending_fb)
769822f6dfdSGustavo Padovan 				continue;
770822f6dfdSGustavo Padovan 
771822f6dfdSGustavo Padovan 			exynos_drm_crtc_finish_update(ctx->crtc, plane);
772822f6dfdSGustavo Padovan 		}
7734551789fSSean Paul 
7744551789fSSean Paul 		/* set wait vsync event to zero and wake up queue. */
7754551789fSSean Paul 		if (atomic_read(&ctx->wait_vsync_event)) {
7764551789fSSean Paul 			atomic_set(&ctx->wait_vsync_event, 0);
7774551789fSSean Paul 			wake_up(&ctx->wait_vsync_queue);
7784551789fSSean Paul 		}
7794551789fSSean Paul 	}
7804551789fSSean Paul 
7814551789fSSean Paul out:
7824551789fSSean Paul 	/* clear interrupts */
7834551789fSSean Paul 	mixer_reg_write(res, MXR_INT_STATUS, val);
7844551789fSSean Paul 
7854551789fSSean Paul 	spin_unlock(&res->reg_slock);
7864551789fSSean Paul 
7874551789fSSean Paul 	return IRQ_HANDLED;
7884551789fSSean Paul }
7894551789fSSean Paul 
7904551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx)
7914551789fSSean Paul {
7924551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
7934551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
7944551789fSSean Paul 	struct resource *res;
7954551789fSSean Paul 	int ret;
7964551789fSSean Paul 
7974551789fSSean Paul 	spin_lock_init(&mixer_res->reg_slock);
7984551789fSSean Paul 
7994551789fSSean Paul 	mixer_res->mixer = devm_clk_get(dev, "mixer");
8004551789fSSean Paul 	if (IS_ERR(mixer_res->mixer)) {
8014551789fSSean Paul 		dev_err(dev, "failed to get clock 'mixer'\n");
8024551789fSSean Paul 		return -ENODEV;
8034551789fSSean Paul 	}
8044551789fSSean Paul 
80504427ec5SMarek Szyprowski 	mixer_res->hdmi = devm_clk_get(dev, "hdmi");
80604427ec5SMarek Szyprowski 	if (IS_ERR(mixer_res->hdmi)) {
80704427ec5SMarek Szyprowski 		dev_err(dev, "failed to get clock 'hdmi'\n");
80804427ec5SMarek Szyprowski 		return PTR_ERR(mixer_res->hdmi);
80904427ec5SMarek Szyprowski 	}
81004427ec5SMarek Szyprowski 
8114551789fSSean Paul 	mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
8124551789fSSean Paul 	if (IS_ERR(mixer_res->sclk_hdmi)) {
8134551789fSSean Paul 		dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
8144551789fSSean Paul 		return -ENODEV;
8154551789fSSean Paul 	}
8164551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
8174551789fSSean Paul 	if (res == NULL) {
8184551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8194551789fSSean Paul 		return -ENXIO;
8204551789fSSean Paul 	}
8214551789fSSean Paul 
8224551789fSSean Paul 	mixer_res->mixer_regs = devm_ioremap(dev, res->start,
8234551789fSSean Paul 							resource_size(res));
8244551789fSSean Paul 	if (mixer_res->mixer_regs == NULL) {
8254551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8264551789fSSean Paul 		return -ENXIO;
8274551789fSSean Paul 	}
8284551789fSSean Paul 
8294551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0);
8304551789fSSean Paul 	if (res == NULL) {
8314551789fSSean Paul 		dev_err(dev, "get interrupt resource failed.\n");
8324551789fSSean Paul 		return -ENXIO;
8334551789fSSean Paul 	}
8344551789fSSean Paul 
8354551789fSSean Paul 	ret = devm_request_irq(dev, res->start, mixer_irq_handler,
8364551789fSSean Paul 						0, "drm_mixer", mixer_ctx);
8374551789fSSean Paul 	if (ret) {
8384551789fSSean Paul 		dev_err(dev, "request interrupt failed.\n");
8394551789fSSean Paul 		return ret;
8404551789fSSean Paul 	}
8414551789fSSean Paul 	mixer_res->irq = res->start;
8424551789fSSean Paul 
8434551789fSSean Paul 	return 0;
8444551789fSSean Paul }
8454551789fSSean Paul 
8464551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx)
8474551789fSSean Paul {
8484551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
8494551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
8504551789fSSean Paul 	struct resource *res;
8514551789fSSean Paul 
8524551789fSSean Paul 	mixer_res->vp = devm_clk_get(dev, "vp");
8534551789fSSean Paul 	if (IS_ERR(mixer_res->vp)) {
8544551789fSSean Paul 		dev_err(dev, "failed to get clock 'vp'\n");
8554551789fSSean Paul 		return -ENODEV;
8564551789fSSean Paul 	}
857ff830c96SMarek Szyprowski 
858ff830c96SMarek Szyprowski 	if (mixer_ctx->has_sclk) {
8594551789fSSean Paul 		mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
8604551789fSSean Paul 		if (IS_ERR(mixer_res->sclk_mixer)) {
8614551789fSSean Paul 			dev_err(dev, "failed to get clock 'sclk_mixer'\n");
8624551789fSSean Paul 			return -ENODEV;
8634551789fSSean Paul 		}
864ff830c96SMarek Szyprowski 		mixer_res->mout_mixer = devm_clk_get(dev, "mout_mixer");
865ff830c96SMarek Szyprowski 		if (IS_ERR(mixer_res->mout_mixer)) {
866ff830c96SMarek Szyprowski 			dev_err(dev, "failed to get clock 'mout_mixer'\n");
8674551789fSSean Paul 			return -ENODEV;
8684551789fSSean Paul 		}
8694551789fSSean Paul 
870ff830c96SMarek Szyprowski 		if (mixer_res->sclk_hdmi && mixer_res->mout_mixer)
871ff830c96SMarek Szyprowski 			clk_set_parent(mixer_res->mout_mixer,
872ff830c96SMarek Szyprowski 				       mixer_res->sclk_hdmi);
873ff830c96SMarek Szyprowski 	}
8744551789fSSean Paul 
8754551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
8764551789fSSean Paul 	if (res == NULL) {
8774551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8784551789fSSean Paul 		return -ENXIO;
8794551789fSSean Paul 	}
8804551789fSSean Paul 
8814551789fSSean Paul 	mixer_res->vp_regs = devm_ioremap(dev, res->start,
8824551789fSSean Paul 							resource_size(res));
8834551789fSSean Paul 	if (mixer_res->vp_regs == NULL) {
8844551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8854551789fSSean Paul 		return -ENXIO;
8864551789fSSean Paul 	}
8874551789fSSean Paul 
8884551789fSSean Paul 	return 0;
8894551789fSSean Paul }
8904551789fSSean Paul 
89193bca243SGustavo Padovan static int mixer_initialize(struct mixer_context *mixer_ctx,
892f37cd5e8SInki Dae 			struct drm_device *drm_dev)
8934551789fSSean Paul {
8944551789fSSean Paul 	int ret;
895f37cd5e8SInki Dae 	struct exynos_drm_private *priv;
896f37cd5e8SInki Dae 	priv = drm_dev->dev_private;
8974551789fSSean Paul 
898eb88e422SGustavo Padovan 	mixer_ctx->drm_dev = drm_dev;
8998a326eddSGustavo Padovan 	mixer_ctx->pipe = priv->pipe++;
9004551789fSSean Paul 
9014551789fSSean Paul 	/* acquire resources: regs, irqs, clocks */
9024551789fSSean Paul 	ret = mixer_resources_init(mixer_ctx);
9034551789fSSean Paul 	if (ret) {
9044551789fSSean Paul 		DRM_ERROR("mixer_resources_init failed ret=%d\n", ret);
9054551789fSSean Paul 		return ret;
9064551789fSSean Paul 	}
9074551789fSSean Paul 
9084551789fSSean Paul 	if (mixer_ctx->vp_enabled) {
9094551789fSSean Paul 		/* acquire vp resources: regs, irqs, clocks */
9104551789fSSean Paul 		ret = vp_resources_init(mixer_ctx);
9114551789fSSean Paul 		if (ret) {
9124551789fSSean Paul 			DRM_ERROR("vp_resources_init failed ret=%d\n", ret);
9134551789fSSean Paul 			return ret;
9144551789fSSean Paul 		}
9154551789fSSean Paul 	}
9164551789fSSean Paul 
917eb7a3fc7SJoonyoung Shim 	ret = drm_iommu_attach_device(drm_dev, mixer_ctx->dev);
918fc2e013fSHyungwon Hwang 	if (ret)
919fc2e013fSHyungwon Hwang 		priv->pipe--;
920f041b257SSean Paul 
921fc2e013fSHyungwon Hwang 	return ret;
9221055b39fSInki Dae }
9231055b39fSInki Dae 
92493bca243SGustavo Padovan static void mixer_ctx_remove(struct mixer_context *mixer_ctx)
925d8408326SSeung-Woo Kim {
926f041b257SSean Paul 	drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev);
927f041b257SSean Paul }
928f041b257SSean Paul 
92993bca243SGustavo Padovan static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)
930f041b257SSean Paul {
93193bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
932d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
933d8408326SSeung-Woo Kim 
9340df5e4acSAndrzej Hajda 	__set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9350df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
936f041b257SSean Paul 		return 0;
937d8408326SSeung-Woo Kim 
938d8408326SSeung-Woo Kim 	/* enable vsync interrupt */
939fc073248SAndrzej Hajda 	mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
940fc073248SAndrzej Hajda 	mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
941d8408326SSeung-Woo Kim 
942d8408326SSeung-Woo Kim 	return 0;
943d8408326SSeung-Woo Kim }
944d8408326SSeung-Woo Kim 
94593bca243SGustavo Padovan static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
946d8408326SSeung-Woo Kim {
94793bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
948d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
949d8408326SSeung-Woo Kim 
9500df5e4acSAndrzej Hajda 	__clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9510df5e4acSAndrzej Hajda 
9520df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
953947710c6SAndrzej Hajda 		return;
954947710c6SAndrzej Hajda 
955d8408326SSeung-Woo Kim 	/* disable vsync interrupt */
956fc073248SAndrzej Hajda 	mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
957d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
958d8408326SSeung-Woo Kim }
959d8408326SSeung-Woo Kim 
9601e1d1393SGustavo Padovan static void mixer_update_plane(struct exynos_drm_crtc *crtc,
9611e1d1393SGustavo Padovan 			       struct exynos_drm_plane *plane)
962d8408326SSeung-Woo Kim {
96393bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
964d8408326SSeung-Woo Kim 
9651e1d1393SGustavo Padovan 	DRM_DEBUG_KMS("win: %d\n", plane->zpos);
966d8408326SSeung-Woo Kim 
967a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
968dda9012bSShirish S 		return;
969dda9012bSShirish S 
9701e1d1393SGustavo Padovan 	if (plane->zpos > 1 && mixer_ctx->vp_enabled)
9712eeb2e5eSGustavo Padovan 		vp_video_buffer(mixer_ctx, plane);
972d8408326SSeung-Woo Kim 	else
9732eeb2e5eSGustavo Padovan 		mixer_graph_buffer(mixer_ctx, plane);
974d8408326SSeung-Woo Kim }
975d8408326SSeung-Woo Kim 
9761e1d1393SGustavo Padovan static void mixer_disable_plane(struct exynos_drm_crtc *crtc,
9771e1d1393SGustavo Padovan 				struct exynos_drm_plane *plane)
978d8408326SSeung-Woo Kim {
97993bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
980d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
981d8408326SSeung-Woo Kim 	unsigned long flags;
982d8408326SSeung-Woo Kim 
9831e1d1393SGustavo Padovan 	DRM_DEBUG_KMS("win: %d\n", plane->zpos);
984d8408326SSeung-Woo Kim 
985a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
986db43fd16SPrathyush K 		return;
987db43fd16SPrathyush K 
988d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
989d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, false);
990d8408326SSeung-Woo Kim 
9911e1d1393SGustavo Padovan 	mixer_cfg_layer(mixer_ctx, plane->zpos, false);
992d8408326SSeung-Woo Kim 
993d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, true);
994d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
995d8408326SSeung-Woo Kim }
996d8408326SSeung-Woo Kim 
99793bca243SGustavo Padovan static void mixer_wait_for_vblank(struct exynos_drm_crtc *crtc)
9980ea6822fSRahul Sharma {
99993bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
10007c4c5584SJoonyoung Shim 	int err;
10018137a2e2SPrathyush K 
1002a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
10036e95d5e6SPrathyush K 		return;
10046e95d5e6SPrathyush K 
100593bca243SGustavo Padovan 	err = drm_vblank_get(mixer_ctx->drm_dev, mixer_ctx->pipe);
10067c4c5584SJoonyoung Shim 	if (err < 0) {
10077c4c5584SJoonyoung Shim 		DRM_DEBUG_KMS("failed to acquire vblank counter\n");
10087c4c5584SJoonyoung Shim 		return;
10097c4c5584SJoonyoung Shim 	}
10105d39b9eeSRahul Sharma 
10116e95d5e6SPrathyush K 	atomic_set(&mixer_ctx->wait_vsync_event, 1);
10126e95d5e6SPrathyush K 
10136e95d5e6SPrathyush K 	/*
10146e95d5e6SPrathyush K 	 * wait for MIXER to signal VSYNC interrupt or return after
10156e95d5e6SPrathyush K 	 * timeout which is set to 50ms (refresh rate of 20).
10166e95d5e6SPrathyush K 	 */
10176e95d5e6SPrathyush K 	if (!wait_event_timeout(mixer_ctx->wait_vsync_queue,
10186e95d5e6SPrathyush K 				!atomic_read(&mixer_ctx->wait_vsync_event),
1019bfd8303aSDaniel Vetter 				HZ/20))
10208137a2e2SPrathyush K 		DRM_DEBUG_KMS("vblank wait timed out.\n");
10215d39b9eeSRahul Sharma 
102293bca243SGustavo Padovan 	drm_vblank_put(mixer_ctx->drm_dev, mixer_ctx->pipe);
10238137a2e2SPrathyush K }
10248137a2e2SPrathyush K 
10253cecda03SGustavo Padovan static void mixer_enable(struct exynos_drm_crtc *crtc)
1026db43fd16SPrathyush K {
10273cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
1028db43fd16SPrathyush K 	struct mixer_resources *res = &ctx->mixer_res;
1029db43fd16SPrathyush K 
1030a44652e8SAndrzej Hajda 	if (test_bit(MXR_BIT_POWERED, &ctx->flags))
1031db43fd16SPrathyush K 		return;
1032db43fd16SPrathyush K 
1033af65c804SSean Paul 	pm_runtime_get_sync(ctx->dev);
1034af65c804SSean Paul 
1035d74ed937SRahul Sharma 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
1036d74ed937SRahul Sharma 
10370df5e4acSAndrzej Hajda 	if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) {
1038fc073248SAndrzej Hajda 		mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
10390df5e4acSAndrzej Hajda 		mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
10400df5e4acSAndrzej Hajda 	}
1041db43fd16SPrathyush K 	mixer_win_reset(ctx);
1042ccf034a9SGustavo Padovan 
1043ccf034a9SGustavo Padovan 	set_bit(MXR_BIT_POWERED, &ctx->flags);
1044db43fd16SPrathyush K }
1045db43fd16SPrathyush K 
10463cecda03SGustavo Padovan static void mixer_disable(struct exynos_drm_crtc *crtc)
1047db43fd16SPrathyush K {
10483cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
1049c329f667SJoonyoung Shim 	int i;
1050db43fd16SPrathyush K 
1051a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
1052b4bfa3c7SRahul Sharma 		return;
1053db43fd16SPrathyush K 
1054381be025SRahul Sharma 	mixer_stop(ctx);
1055c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
1056c329f667SJoonyoung Shim 
1057c329f667SJoonyoung Shim 	for (i = 0; i < MIXER_WIN_NR; i++)
10581e1d1393SGustavo Padovan 		mixer_disable_plane(crtc, &ctx->planes[i]);
1059db43fd16SPrathyush K 
1060ccf034a9SGustavo Padovan 	pm_runtime_put(ctx->dev);
1061ccf034a9SGustavo Padovan 
1062a44652e8SAndrzej Hajda 	clear_bit(MXR_BIT_POWERED, &ctx->flags);
1063db43fd16SPrathyush K }
1064db43fd16SPrathyush K 
1065f041b257SSean Paul /* Only valid for Mixer version 16.0.33.0 */
10663ae24362SAndrzej Hajda static int mixer_atomic_check(struct exynos_drm_crtc *crtc,
10673ae24362SAndrzej Hajda 		       struct drm_crtc_state *state)
1068f041b257SSean Paul {
10693ae24362SAndrzej Hajda 	struct drm_display_mode *mode = &state->adjusted_mode;
1070f041b257SSean Paul 	u32 w, h;
1071f041b257SSean Paul 
1072f041b257SSean Paul 	w = mode->hdisplay;
1073f041b257SSean Paul 	h = mode->vdisplay;
1074f041b257SSean Paul 
1075f041b257SSean Paul 	DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n",
1076f041b257SSean Paul 		mode->hdisplay, mode->vdisplay, mode->vrefresh,
1077f041b257SSean Paul 		(mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
1078f041b257SSean Paul 
1079f041b257SSean Paul 	if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
1080f041b257SSean Paul 		(w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
1081f041b257SSean Paul 		(w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
1082f041b257SSean Paul 		return 0;
1083f041b257SSean Paul 
1084f041b257SSean Paul 	return -EINVAL;
1085f041b257SSean Paul }
1086f041b257SSean Paul 
1087f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops mixer_crtc_ops = {
10883cecda03SGustavo Padovan 	.enable			= mixer_enable,
10893cecda03SGustavo Padovan 	.disable		= mixer_disable,
1090d8408326SSeung-Woo Kim 	.enable_vblank		= mixer_enable_vblank,
1091d8408326SSeung-Woo Kim 	.disable_vblank		= mixer_disable_vblank,
10928137a2e2SPrathyush K 	.wait_for_vblank	= mixer_wait_for_vblank,
10939cc7610aSGustavo Padovan 	.update_plane		= mixer_update_plane,
10949cc7610aSGustavo Padovan 	.disable_plane		= mixer_disable_plane,
10953ae24362SAndrzej Hajda 	.atomic_check		= mixer_atomic_check,
1096f041b257SSean Paul };
10970ea6822fSRahul Sharma 
1098def5e095SRahul Sharma static struct mixer_drv_data exynos5420_mxr_drv_data = {
1099def5e095SRahul Sharma 	.version = MXR_VER_128_0_0_184,
1100def5e095SRahul Sharma 	.is_vp_enabled = 0,
1101def5e095SRahul Sharma };
1102def5e095SRahul Sharma 
1103cc57caf0SRahul Sharma static struct mixer_drv_data exynos5250_mxr_drv_data = {
1104aaf8b49eSRahul Sharma 	.version = MXR_VER_16_0_33_0,
1105aaf8b49eSRahul Sharma 	.is_vp_enabled = 0,
1106aaf8b49eSRahul Sharma };
1107aaf8b49eSRahul Sharma 
1108ff830c96SMarek Szyprowski static struct mixer_drv_data exynos4212_mxr_drv_data = {
1109ff830c96SMarek Szyprowski 	.version = MXR_VER_0_0_0_16,
1110ff830c96SMarek Szyprowski 	.is_vp_enabled = 1,
1111ff830c96SMarek Szyprowski };
1112ff830c96SMarek Szyprowski 
1113cc57caf0SRahul Sharma static struct mixer_drv_data exynos4210_mxr_drv_data = {
11141e123441SRahul Sharma 	.version = MXR_VER_0_0_0_16,
11151b8e5747SRahul Sharma 	.is_vp_enabled = 1,
1116ff830c96SMarek Szyprowski 	.has_sclk = 1,
11171e123441SRahul Sharma };
11181e123441SRahul Sharma 
1119d6b16302SKrzysztof Kozlowski static const struct platform_device_id mixer_driver_types[] = {
11201e123441SRahul Sharma 	{
11211e123441SRahul Sharma 		.name		= "s5p-mixer",
1122cc57caf0SRahul Sharma 		.driver_data	= (unsigned long)&exynos4210_mxr_drv_data,
11231e123441SRahul Sharma 	}, {
1124aaf8b49eSRahul Sharma 		.name		= "exynos5-mixer",
1125cc57caf0SRahul Sharma 		.driver_data	= (unsigned long)&exynos5250_mxr_drv_data,
1126aaf8b49eSRahul Sharma 	}, {
1127aaf8b49eSRahul Sharma 		/* end node */
1128aaf8b49eSRahul Sharma 	}
1129aaf8b49eSRahul Sharma };
1130aaf8b49eSRahul Sharma 
1131aaf8b49eSRahul Sharma static struct of_device_id mixer_match_types[] = {
1132aaf8b49eSRahul Sharma 	{
1133ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4210-mixer",
1134ff830c96SMarek Szyprowski 		.data	= &exynos4210_mxr_drv_data,
1135ff830c96SMarek Szyprowski 	}, {
1136ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4212-mixer",
1137ff830c96SMarek Szyprowski 		.data	= &exynos4212_mxr_drv_data,
1138ff830c96SMarek Szyprowski 	}, {
1139aaf8b49eSRahul Sharma 		.compatible = "samsung,exynos5-mixer",
1140cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1141cc57caf0SRahul Sharma 	}, {
1142cc57caf0SRahul Sharma 		.compatible = "samsung,exynos5250-mixer",
1143cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1144aaf8b49eSRahul Sharma 	}, {
1145def5e095SRahul Sharma 		.compatible = "samsung,exynos5420-mixer",
1146def5e095SRahul Sharma 		.data	= &exynos5420_mxr_drv_data,
1147def5e095SRahul Sharma 	}, {
11481e123441SRahul Sharma 		/* end node */
11491e123441SRahul Sharma 	}
11501e123441SRahul Sharma };
115139b58a39SSjoerd Simons MODULE_DEVICE_TABLE(of, mixer_match_types);
11521e123441SRahul Sharma 
1153f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data)
1154d8408326SSeung-Woo Kim {
11558103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
1156f37cd5e8SInki Dae 	struct drm_device *drm_dev = data;
11577ee14cdcSGustavo Padovan 	struct exynos_drm_plane *exynos_plane;
11586e2a3b66SGustavo Padovan 	unsigned int zpos;
11596e2a3b66SGustavo Padovan 	int ret;
1160d8408326SSeung-Woo Kim 
1161e2dc3f72SAlban Browaeys 	ret = mixer_initialize(ctx, drm_dev);
1162e2dc3f72SAlban Browaeys 	if (ret)
1163e2dc3f72SAlban Browaeys 		return ret;
1164e2dc3f72SAlban Browaeys 
11657ee14cdcSGustavo Padovan 	for (zpos = 0; zpos < MIXER_WIN_NR; zpos++) {
1166fbbb1e1aSMarek Szyprowski 		enum drm_plane_type type;
1167fbbb1e1aSMarek Szyprowski 		const uint32_t *formats;
1168fbbb1e1aSMarek Szyprowski 		unsigned int fcount;
1169fbbb1e1aSMarek Szyprowski 
1170*ab144201SMarek Szyprowski 		if (zpos == VP_DEFAULT_WIN && !ctx->vp_enabled)
1171*ab144201SMarek Szyprowski 			continue;
1172*ab144201SMarek Szyprowski 
1173fbbb1e1aSMarek Szyprowski 		if (zpos < VP_DEFAULT_WIN) {
1174fbbb1e1aSMarek Szyprowski 			formats = mixer_formats;
1175fbbb1e1aSMarek Szyprowski 			fcount = ARRAY_SIZE(mixer_formats);
1176fbbb1e1aSMarek Szyprowski 		} else {
1177fbbb1e1aSMarek Szyprowski 			formats = vp_formats;
1178fbbb1e1aSMarek Szyprowski 			fcount = ARRAY_SIZE(vp_formats);
1179fbbb1e1aSMarek Szyprowski 		}
1180fbbb1e1aSMarek Szyprowski 
1181323db0edSGustavo Padovan 		type = exynos_plane_get_type(zpos, CURSOR_WIN);
11827ee14cdcSGustavo Padovan 		ret = exynos_plane_init(drm_dev, &ctx->planes[zpos],
1183fbbb1e1aSMarek Szyprowski 					1 << ctx->pipe, type, formats, fcount,
1184fbbb1e1aSMarek Szyprowski 					zpos);
11857ee14cdcSGustavo Padovan 		if (ret)
11867ee14cdcSGustavo Padovan 			return ret;
11877ee14cdcSGustavo Padovan 	}
11887ee14cdcSGustavo Padovan 
11895d3d0995SGustavo Padovan 	exynos_plane = &ctx->planes[DEFAULT_WIN];
11907ee14cdcSGustavo Padovan 	ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
11917ee14cdcSGustavo Padovan 					   ctx->pipe, EXYNOS_DISPLAY_TYPE_HDMI,
119293bca243SGustavo Padovan 					   &mixer_crtc_ops, ctx);
119393bca243SGustavo Padovan 	if (IS_ERR(ctx->crtc)) {
1194e2dc3f72SAlban Browaeys 		mixer_ctx_remove(ctx);
119593bca243SGustavo Padovan 		ret = PTR_ERR(ctx->crtc);
119693bca243SGustavo Padovan 		goto free_ctx;
11978103ef1bSAndrzej Hajda 	}
11988103ef1bSAndrzej Hajda 
11998103ef1bSAndrzej Hajda 	return 0;
120093bca243SGustavo Padovan 
120193bca243SGustavo Padovan free_ctx:
120293bca243SGustavo Padovan 	devm_kfree(dev, ctx);
120393bca243SGustavo Padovan 	return ret;
12048103ef1bSAndrzej Hajda }
12058103ef1bSAndrzej Hajda 
12068103ef1bSAndrzej Hajda static void mixer_unbind(struct device *dev, struct device *master, void *data)
12078103ef1bSAndrzej Hajda {
12088103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
12098103ef1bSAndrzej Hajda 
121093bca243SGustavo Padovan 	mixer_ctx_remove(ctx);
12118103ef1bSAndrzej Hajda }
12128103ef1bSAndrzej Hajda 
12138103ef1bSAndrzej Hajda static const struct component_ops mixer_component_ops = {
12148103ef1bSAndrzej Hajda 	.bind	= mixer_bind,
12158103ef1bSAndrzej Hajda 	.unbind	= mixer_unbind,
12168103ef1bSAndrzej Hajda };
12178103ef1bSAndrzej Hajda 
12188103ef1bSAndrzej Hajda static int mixer_probe(struct platform_device *pdev)
12198103ef1bSAndrzej Hajda {
12208103ef1bSAndrzej Hajda 	struct device *dev = &pdev->dev;
12218103ef1bSAndrzej Hajda 	struct mixer_drv_data *drv;
12228103ef1bSAndrzej Hajda 	struct mixer_context *ctx;
12238103ef1bSAndrzej Hajda 	int ret;
1224d8408326SSeung-Woo Kim 
1225f041b257SSean Paul 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1226f041b257SSean Paul 	if (!ctx) {
1227f041b257SSean Paul 		DRM_ERROR("failed to alloc mixer context.\n");
1228d8408326SSeung-Woo Kim 		return -ENOMEM;
1229f041b257SSean Paul 	}
1230d8408326SSeung-Woo Kim 
1231aaf8b49eSRahul Sharma 	if (dev->of_node) {
1232aaf8b49eSRahul Sharma 		const struct of_device_id *match;
12338103ef1bSAndrzej Hajda 
1234e436b09dSSachin Kamat 		match = of_match_node(mixer_match_types, dev->of_node);
12352cdc53b3SRahul Sharma 		drv = (struct mixer_drv_data *)match->data;
1236aaf8b49eSRahul Sharma 	} else {
1237aaf8b49eSRahul Sharma 		drv = (struct mixer_drv_data *)
1238aaf8b49eSRahul Sharma 			platform_get_device_id(pdev)->driver_data;
1239aaf8b49eSRahul Sharma 	}
1240aaf8b49eSRahul Sharma 
12414551789fSSean Paul 	ctx->pdev = pdev;
1242d873ab99SSeung-Woo Kim 	ctx->dev = dev;
12431b8e5747SRahul Sharma 	ctx->vp_enabled = drv->is_vp_enabled;
1244ff830c96SMarek Szyprowski 	ctx->has_sclk = drv->has_sclk;
12451e123441SRahul Sharma 	ctx->mxr_ver = drv->version;
124657ed0f7bSDaniel Vetter 	init_waitqueue_head(&ctx->wait_vsync_queue);
12476e95d5e6SPrathyush K 	atomic_set(&ctx->wait_vsync_event, 0);
1248d8408326SSeung-Woo Kim 
12498103ef1bSAndrzej Hajda 	platform_set_drvdata(pdev, ctx);
1250df5225bcSInki Dae 
1251df5225bcSInki Dae 	ret = component_add(&pdev->dev, &mixer_component_ops);
125286650408SAndrzej Hajda 	if (!ret)
12538103ef1bSAndrzej Hajda 		pm_runtime_enable(dev);
1254df5225bcSInki Dae 
1255df5225bcSInki Dae 	return ret;
1256f37cd5e8SInki Dae }
1257f37cd5e8SInki Dae 
1258d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev)
1259d8408326SSeung-Woo Kim {
12608103ef1bSAndrzej Hajda 	pm_runtime_disable(&pdev->dev);
12618103ef1bSAndrzej Hajda 
1262df5225bcSInki Dae 	component_del(&pdev->dev, &mixer_component_ops);
1263df5225bcSInki Dae 
1264d8408326SSeung-Woo Kim 	return 0;
1265d8408326SSeung-Woo Kim }
1266d8408326SSeung-Woo Kim 
1267ccf034a9SGustavo Padovan #ifdef CONFIG_PM_SLEEP
1268ccf034a9SGustavo Padovan static int exynos_mixer_suspend(struct device *dev)
1269ccf034a9SGustavo Padovan {
1270ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1271ccf034a9SGustavo Padovan 	struct mixer_resources *res = &ctx->mixer_res;
1272ccf034a9SGustavo Padovan 
1273ccf034a9SGustavo Padovan 	clk_disable_unprepare(res->hdmi);
1274ccf034a9SGustavo Padovan 	clk_disable_unprepare(res->mixer);
1275ccf034a9SGustavo Padovan 	if (ctx->vp_enabled) {
1276ccf034a9SGustavo Padovan 		clk_disable_unprepare(res->vp);
1277ccf034a9SGustavo Padovan 		if (ctx->has_sclk)
1278ccf034a9SGustavo Padovan 			clk_disable_unprepare(res->sclk_mixer);
1279ccf034a9SGustavo Padovan 	}
1280ccf034a9SGustavo Padovan 
1281ccf034a9SGustavo Padovan 	return 0;
1282ccf034a9SGustavo Padovan }
1283ccf034a9SGustavo Padovan 
1284ccf034a9SGustavo Padovan static int exynos_mixer_resume(struct device *dev)
1285ccf034a9SGustavo Padovan {
1286ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1287ccf034a9SGustavo Padovan 	struct mixer_resources *res = &ctx->mixer_res;
1288ccf034a9SGustavo Padovan 	int ret;
1289ccf034a9SGustavo Padovan 
1290ccf034a9SGustavo Padovan 	ret = clk_prepare_enable(res->mixer);
1291ccf034a9SGustavo Padovan 	if (ret < 0) {
1292ccf034a9SGustavo Padovan 		DRM_ERROR("Failed to prepare_enable the mixer clk [%d]\n", ret);
1293ccf034a9SGustavo Padovan 		return ret;
1294ccf034a9SGustavo Padovan 	}
1295ccf034a9SGustavo Padovan 	ret = clk_prepare_enable(res->hdmi);
1296ccf034a9SGustavo Padovan 	if (ret < 0) {
1297ccf034a9SGustavo Padovan 		DRM_ERROR("Failed to prepare_enable the hdmi clk [%d]\n", ret);
1298ccf034a9SGustavo Padovan 		return ret;
1299ccf034a9SGustavo Padovan 	}
1300ccf034a9SGustavo Padovan 	if (ctx->vp_enabled) {
1301ccf034a9SGustavo Padovan 		ret = clk_prepare_enable(res->vp);
1302ccf034a9SGustavo Padovan 		if (ret < 0) {
1303ccf034a9SGustavo Padovan 			DRM_ERROR("Failed to prepare_enable the vp clk [%d]\n",
1304ccf034a9SGustavo Padovan 				  ret);
1305ccf034a9SGustavo Padovan 			return ret;
1306ccf034a9SGustavo Padovan 		}
1307ccf034a9SGustavo Padovan 		if (ctx->has_sclk) {
1308ccf034a9SGustavo Padovan 			ret = clk_prepare_enable(res->sclk_mixer);
1309ccf034a9SGustavo Padovan 			if (ret < 0) {
1310ccf034a9SGustavo Padovan 				DRM_ERROR("Failed to prepare_enable the " \
1311ccf034a9SGustavo Padovan 					   "sclk_mixer clk [%d]\n",
1312ccf034a9SGustavo Padovan 					  ret);
1313ccf034a9SGustavo Padovan 				return ret;
1314ccf034a9SGustavo Padovan 			}
1315ccf034a9SGustavo Padovan 		}
1316ccf034a9SGustavo Padovan 	}
1317ccf034a9SGustavo Padovan 
1318ccf034a9SGustavo Padovan 	return 0;
1319ccf034a9SGustavo Padovan }
1320ccf034a9SGustavo Padovan #endif
1321ccf034a9SGustavo Padovan 
1322ccf034a9SGustavo Padovan static const struct dev_pm_ops exynos_mixer_pm_ops = {
1323ccf034a9SGustavo Padovan 	SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL)
1324ccf034a9SGustavo Padovan };
1325ccf034a9SGustavo Padovan 
1326d8408326SSeung-Woo Kim struct platform_driver mixer_driver = {
1327d8408326SSeung-Woo Kim 	.driver = {
1328aaf8b49eSRahul Sharma 		.name = "exynos-mixer",
1329d8408326SSeung-Woo Kim 		.owner = THIS_MODULE,
1330ccf034a9SGustavo Padovan 		.pm = &exynos_mixer_pm_ops,
1331aaf8b49eSRahul Sharma 		.of_match_table = mixer_match_types,
1332d8408326SSeung-Woo Kim 	},
1333d8408326SSeung-Woo Kim 	.probe = mixer_probe,
133456550d94SGreg Kroah-Hartman 	.remove = mixer_remove,
13351e123441SRahul Sharma 	.id_table	= mixer_driver_types,
1336d8408326SSeung-Woo Kim };
1337