xref: /linux/drivers/gpu/drm/exynos/exynos_mixer.c (revision fd2d2fc2db28d3a2a18b7504e2d6d8b0753f90e8)
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
46d8408326SSeung-Woo Kim 
477a57ca7cSTobias Jakobi /* The pixelformats that are natively supported by the mixer. */
487a57ca7cSTobias Jakobi #define MXR_FORMAT_RGB565	4
497a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB1555	5
507a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB4444	6
517a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB8888	7
527a57ca7cSTobias Jakobi 
5322b21ae6SJoonyoung Shim struct mixer_resources {
5422b21ae6SJoonyoung Shim 	int			irq;
5522b21ae6SJoonyoung Shim 	void __iomem		*mixer_regs;
5622b21ae6SJoonyoung Shim 	void __iomem		*vp_regs;
5722b21ae6SJoonyoung Shim 	spinlock_t		reg_slock;
5822b21ae6SJoonyoung Shim 	struct clk		*mixer;
5922b21ae6SJoonyoung Shim 	struct clk		*vp;
6004427ec5SMarek Szyprowski 	struct clk		*hdmi;
6122b21ae6SJoonyoung Shim 	struct clk		*sclk_mixer;
6222b21ae6SJoonyoung Shim 	struct clk		*sclk_hdmi;
63ff830c96SMarek Szyprowski 	struct clk		*mout_mixer;
6422b21ae6SJoonyoung Shim };
6522b21ae6SJoonyoung Shim 
661e123441SRahul Sharma enum mixer_version_id {
671e123441SRahul Sharma 	MXR_VER_0_0_0_16,
681e123441SRahul Sharma 	MXR_VER_16_0_33_0,
69def5e095SRahul Sharma 	MXR_VER_128_0_0_184,
701e123441SRahul Sharma };
711e123441SRahul Sharma 
72a44652e8SAndrzej Hajda enum mixer_flag_bits {
73a44652e8SAndrzej Hajda 	MXR_BIT_POWERED,
740df5e4acSAndrzej Hajda 	MXR_BIT_VSYNC,
75a44652e8SAndrzej Hajda };
76a44652e8SAndrzej Hajda 
77fbbb1e1aSMarek Szyprowski static const uint32_t mixer_formats[] = {
78fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB4444,
79fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB1555,
80fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_RGB565,
81fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB8888,
82fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_ARGB8888,
83fbbb1e1aSMarek Szyprowski };
84fbbb1e1aSMarek Szyprowski 
85fbbb1e1aSMarek Szyprowski static const uint32_t vp_formats[] = {
86fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_NV12,
87fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_NV21,
88fbbb1e1aSMarek Szyprowski };
89fbbb1e1aSMarek Szyprowski 
9022b21ae6SJoonyoung Shim struct mixer_context {
914551789fSSean Paul 	struct platform_device *pdev;
92cf8fc4f1SJoonyoung Shim 	struct device		*dev;
931055b39fSInki Dae 	struct drm_device	*drm_dev;
9493bca243SGustavo Padovan 	struct exynos_drm_crtc	*crtc;
957ee14cdcSGustavo Padovan 	struct exynos_drm_plane	planes[MIXER_WIN_NR];
9622b21ae6SJoonyoung Shim 	int			pipe;
97a44652e8SAndrzej Hajda 	unsigned long		flags;
9822b21ae6SJoonyoung Shim 	bool			interlace;
991b8e5747SRahul Sharma 	bool			vp_enabled;
100ff830c96SMarek Szyprowski 	bool			has_sclk;
10122b21ae6SJoonyoung Shim 
10222b21ae6SJoonyoung Shim 	struct mixer_resources	mixer_res;
1031e123441SRahul Sharma 	enum mixer_version_id	mxr_ver;
1046e95d5e6SPrathyush K 	wait_queue_head_t	wait_vsync_queue;
1056e95d5e6SPrathyush K 	atomic_t		wait_vsync_event;
1061e123441SRahul Sharma };
1071e123441SRahul Sharma 
1081e123441SRahul Sharma struct mixer_drv_data {
1091e123441SRahul Sharma 	enum mixer_version_id	version;
1101b8e5747SRahul Sharma 	bool					is_vp_enabled;
111ff830c96SMarek Szyprowski 	bool					has_sclk;
11222b21ae6SJoonyoung Shim };
11322b21ae6SJoonyoung Shim 
114*fd2d2fc2SMarek Szyprowski static const struct exynos_drm_plane_config plane_configs[MIXER_WIN_NR] = {
115*fd2d2fc2SMarek Szyprowski 	{
116*fd2d2fc2SMarek Szyprowski 		.zpos = 0,
117*fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_PRIMARY,
118*fd2d2fc2SMarek Szyprowski 		.pixel_formats = mixer_formats,
119*fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(mixer_formats),
120*fd2d2fc2SMarek Szyprowski 	}, {
121*fd2d2fc2SMarek Szyprowski 		.zpos = 1,
122*fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_CURSOR,
123*fd2d2fc2SMarek Szyprowski 		.pixel_formats = mixer_formats,
124*fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(mixer_formats),
125*fd2d2fc2SMarek Szyprowski 	}, {
126*fd2d2fc2SMarek Szyprowski 		.zpos = 2,
127*fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_OVERLAY,
128*fd2d2fc2SMarek Szyprowski 		.pixel_formats = vp_formats,
129*fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(vp_formats),
130*fd2d2fc2SMarek Szyprowski 	},
131*fd2d2fc2SMarek Szyprowski };
132*fd2d2fc2SMarek Szyprowski 
133d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = {
134d8408326SSeung-Woo Kim 	0,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
135d8408326SSeung-Woo Kim 	-1,	-1,	-1,	-1,	-1,	0,	0,	0,
136d8408326SSeung-Woo Kim 	0,	2,	4,	5,	6,	6,	6,	6,
137d8408326SSeung-Woo Kim 	6,	5,	5,	4,	3,	2,	1,	1,
138d8408326SSeung-Woo Kim 	0,	-6,	-12,	-16,	-18,	-20,	-21,	-20,
139d8408326SSeung-Woo Kim 	-20,	-18,	-16,	-13,	-10,	-8,	-5,	-2,
140d8408326SSeung-Woo Kim 	127,	126,	125,	121,	114,	107,	99,	89,
141d8408326SSeung-Woo Kim 	79,	68,	57,	46,	35,	25,	16,	8,
142d8408326SSeung-Woo Kim };
143d8408326SSeung-Woo Kim 
144d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = {
145d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
146d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
147d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
148d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
149d8408326SSeung-Woo Kim 	0,	5,	11,	19,	27,	37,	48,	59,
150d8408326SSeung-Woo Kim 	70,	81,	92,	102,	111,	118,	124,	126,
151d8408326SSeung-Woo Kim 	0,	0,	-1,	-1,	-2,	-3,	-4,	-5,
152d8408326SSeung-Woo Kim 	-6,	-7,	-8,	-8,	-8,	-8,	-6,	-3,
153d8408326SSeung-Woo Kim };
154d8408326SSeung-Woo Kim 
155d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = {
156d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
157d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
158d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
159d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
160d8408326SSeung-Woo Kim };
161d8408326SSeung-Woo Kim 
162d8408326SSeung-Woo Kim static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id)
163d8408326SSeung-Woo Kim {
164d8408326SSeung-Woo Kim 	return readl(res->vp_regs + reg_id);
165d8408326SSeung-Woo Kim }
166d8408326SSeung-Woo Kim 
167d8408326SSeung-Woo Kim static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id,
168d8408326SSeung-Woo Kim 				 u32 val)
169d8408326SSeung-Woo Kim {
170d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
171d8408326SSeung-Woo Kim }
172d8408326SSeung-Woo Kim 
173d8408326SSeung-Woo Kim static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id,
174d8408326SSeung-Woo Kim 				 u32 val, u32 mask)
175d8408326SSeung-Woo Kim {
176d8408326SSeung-Woo Kim 	u32 old = vp_reg_read(res, reg_id);
177d8408326SSeung-Woo Kim 
178d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
179d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
180d8408326SSeung-Woo Kim }
181d8408326SSeung-Woo Kim 
182d8408326SSeung-Woo Kim static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id)
183d8408326SSeung-Woo Kim {
184d8408326SSeung-Woo Kim 	return readl(res->mixer_regs + reg_id);
185d8408326SSeung-Woo Kim }
186d8408326SSeung-Woo Kim 
187d8408326SSeung-Woo Kim static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id,
188d8408326SSeung-Woo Kim 				 u32 val)
189d8408326SSeung-Woo Kim {
190d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
191d8408326SSeung-Woo Kim }
192d8408326SSeung-Woo Kim 
193d8408326SSeung-Woo Kim static inline void mixer_reg_writemask(struct mixer_resources *res,
194d8408326SSeung-Woo Kim 				 u32 reg_id, u32 val, u32 mask)
195d8408326SSeung-Woo Kim {
196d8408326SSeung-Woo Kim 	u32 old = mixer_reg_read(res, reg_id);
197d8408326SSeung-Woo Kim 
198d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
199d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
200d8408326SSeung-Woo Kim }
201d8408326SSeung-Woo Kim 
202d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx)
203d8408326SSeung-Woo Kim {
204d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
205d8408326SSeung-Woo Kim do { \
206d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
207d8408326SSeung-Woo Kim 		(u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \
208d8408326SSeung-Woo Kim } while (0)
209d8408326SSeung-Woo Kim 
210d8408326SSeung-Woo Kim 	DUMPREG(MXR_STATUS);
211d8408326SSeung-Woo Kim 	DUMPREG(MXR_CFG);
212d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_EN);
213d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_STATUS);
214d8408326SSeung-Woo Kim 
215d8408326SSeung-Woo Kim 	DUMPREG(MXR_LAYER_CFG);
216d8408326SSeung-Woo Kim 	DUMPREG(MXR_VIDEO_CFG);
217d8408326SSeung-Woo Kim 
218d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_CFG);
219d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_BASE);
220d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SPAN);
221d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_WH);
222d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SXY);
223d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_DXY);
224d8408326SSeung-Woo Kim 
225d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_CFG);
226d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_BASE);
227d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SPAN);
228d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_WH);
229d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SXY);
230d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_DXY);
231d8408326SSeung-Woo Kim #undef DUMPREG
232d8408326SSeung-Woo Kim }
233d8408326SSeung-Woo Kim 
234d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx)
235d8408326SSeung-Woo Kim {
236d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
237d8408326SSeung-Woo Kim do { \
238d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
239d8408326SSeung-Woo Kim 		(u32) readl(ctx->mixer_res.vp_regs + reg_id)); \
240d8408326SSeung-Woo Kim } while (0)
241d8408326SSeung-Woo Kim 
242d8408326SSeung-Woo Kim 	DUMPREG(VP_ENABLE);
243d8408326SSeung-Woo Kim 	DUMPREG(VP_SRESET);
244d8408326SSeung-Woo Kim 	DUMPREG(VP_SHADOW_UPDATE);
245d8408326SSeung-Woo Kim 	DUMPREG(VP_FIELD_ID);
246d8408326SSeung-Woo Kim 	DUMPREG(VP_MODE);
247d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_Y);
248d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_C);
249d8408326SSeung-Woo Kim 	DUMPREG(VP_PER_RATE_CTRL);
250d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_Y_PTR);
251d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_Y_PTR);
252d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_C_PTR);
253d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_C_PTR);
254d8408326SSeung-Woo Kim 	DUMPREG(VP_ENDIAN_MODE);
255d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_H_POSITION);
256d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_V_POSITION);
257d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_WIDTH);
258d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_HEIGHT);
259d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_H_POSITION);
260d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_V_POSITION);
261d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_WIDTH);
262d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_HEIGHT);
263d8408326SSeung-Woo Kim 	DUMPREG(VP_H_RATIO);
264d8408326SSeung-Woo Kim 	DUMPREG(VP_V_RATIO);
265d8408326SSeung-Woo Kim 
266d8408326SSeung-Woo Kim #undef DUMPREG
267d8408326SSeung-Woo Kim }
268d8408326SSeung-Woo Kim 
269d8408326SSeung-Woo Kim static inline void vp_filter_set(struct mixer_resources *res,
270d8408326SSeung-Woo Kim 		int reg_id, const u8 *data, unsigned int size)
271d8408326SSeung-Woo Kim {
272d8408326SSeung-Woo Kim 	/* assure 4-byte align */
273d8408326SSeung-Woo Kim 	BUG_ON(size & 3);
274d8408326SSeung-Woo Kim 	for (; size; size -= 4, reg_id += 4, data += 4) {
275d8408326SSeung-Woo Kim 		u32 val = (data[0] << 24) |  (data[1] << 16) |
276d8408326SSeung-Woo Kim 			(data[2] << 8) | data[3];
277d8408326SSeung-Woo Kim 		vp_reg_write(res, reg_id, val);
278d8408326SSeung-Woo Kim 	}
279d8408326SSeung-Woo Kim }
280d8408326SSeung-Woo Kim 
281d8408326SSeung-Woo Kim static void vp_default_filter(struct mixer_resources *res)
282d8408326SSeung-Woo Kim {
283d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY8_Y0_LL,
284e25e1b66SSachin Kamat 		filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
285d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_Y0_LL,
286e25e1b66SSachin Kamat 		filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
287d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_C0_LL,
288e25e1b66SSachin Kamat 		filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
289d8408326SSeung-Woo Kim }
290d8408326SSeung-Woo Kim 
291d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable)
292d8408326SSeung-Woo Kim {
293d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
294d8408326SSeung-Woo Kim 
295d8408326SSeung-Woo Kim 	/* block update on vsync */
296d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, enable ?
297d8408326SSeung-Woo Kim 			MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE);
298d8408326SSeung-Woo Kim 
2991b8e5747SRahul Sharma 	if (ctx->vp_enabled)
300d8408326SSeung-Woo Kim 		vp_reg_write(res, VP_SHADOW_UPDATE, enable ?
301d8408326SSeung-Woo Kim 			VP_SHADOW_UPDATE_ENABLE : 0);
302d8408326SSeung-Woo Kim }
303d8408326SSeung-Woo Kim 
304d8408326SSeung-Woo Kim static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height)
305d8408326SSeung-Woo Kim {
306d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
307d8408326SSeung-Woo Kim 	u32 val;
308d8408326SSeung-Woo Kim 
309d8408326SSeung-Woo Kim 	/* choosing between interlace and progressive mode */
310d8408326SSeung-Woo Kim 	val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE :
3111e6d459dSTobias Jakobi 				MXR_CFG_SCAN_PROGRESSIVE);
312d8408326SSeung-Woo Kim 
313def5e095SRahul Sharma 	if (ctx->mxr_ver != MXR_VER_128_0_0_184) {
314def5e095SRahul Sharma 		/* choosing between proper HD and SD mode */
31529630743SRahul Sharma 		if (height <= 480)
316d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD;
31729630743SRahul Sharma 		else if (height <= 576)
318d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD;
31929630743SRahul Sharma 		else if (height <= 720)
320d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
32129630743SRahul Sharma 		else if (height <= 1080)
322d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD;
323d8408326SSeung-Woo Kim 		else
324d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
325def5e095SRahul Sharma 	}
326d8408326SSeung-Woo Kim 
327d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK);
328d8408326SSeung-Woo Kim }
329d8408326SSeung-Woo Kim 
330d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height)
331d8408326SSeung-Woo Kim {
332d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
333d8408326SSeung-Woo Kim 	u32 val;
334d8408326SSeung-Woo Kim 
335d8408326SSeung-Woo Kim 	if (height == 480) {
336d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
337d8408326SSeung-Woo Kim 	} else if (height == 576) {
338d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
339d8408326SSeung-Woo Kim 	} else if (height == 720) {
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 	} else if (height == 1080) {
349d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
350d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
351d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
352d8408326SSeung-Woo Kim 				(32 << 0));
353d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
354d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
355d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
356d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
357d8408326SSeung-Woo Kim 	} else {
358d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
359d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
360d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
361d8408326SSeung-Woo Kim 				(32 << 0));
362d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
363d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
364d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
365d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
366d8408326SSeung-Woo Kim 	}
367d8408326SSeung-Woo Kim 
368d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
369d8408326SSeung-Woo Kim }
370d8408326SSeung-Woo Kim 
3715b1d5bc6STobias Jakobi static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win,
3725b1d5bc6STobias Jakobi 				bool enable)
373d8408326SSeung-Woo Kim {
374d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
375d8408326SSeung-Woo Kim 	u32 val = enable ? ~0 : 0;
376d8408326SSeung-Woo Kim 
377d8408326SSeung-Woo Kim 	switch (win) {
378d8408326SSeung-Woo Kim 	case 0:
379d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
380d8408326SSeung-Woo Kim 		break;
381d8408326SSeung-Woo Kim 	case 1:
382d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
383d8408326SSeung-Woo Kim 		break;
384d8408326SSeung-Woo Kim 	case 2:
3851b8e5747SRahul Sharma 		if (ctx->vp_enabled) {
386d8408326SSeung-Woo Kim 			vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON);
3871b8e5747SRahul Sharma 			mixer_reg_writemask(res, MXR_CFG, val,
3881b8e5747SRahul Sharma 				MXR_CFG_VP_ENABLE);
389f1e716d8SJoonyoung Shim 
390f1e716d8SJoonyoung Shim 			/* control blending of graphic layer 0 */
391f1e716d8SJoonyoung Shim 			mixer_reg_writemask(res, MXR_GRAPHIC_CFG(0), val,
392f1e716d8SJoonyoung Shim 					MXR_GRP_CFG_BLEND_PRE_MUL |
393f1e716d8SJoonyoung Shim 					MXR_GRP_CFG_PIXEL_BLEND_EN);
3941b8e5747SRahul Sharma 		}
395d8408326SSeung-Woo Kim 		break;
396d8408326SSeung-Woo Kim 	}
397d8408326SSeung-Woo Kim }
398d8408326SSeung-Woo Kim 
399d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx)
400d8408326SSeung-Woo Kim {
401d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
402d8408326SSeung-Woo Kim 
403d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
404d8408326SSeung-Woo Kim }
405d8408326SSeung-Woo Kim 
406381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx)
407381be025SRahul Sharma {
408381be025SRahul Sharma 	struct mixer_resources *res = &ctx->mixer_res;
409381be025SRahul Sharma 	int timeout = 20;
410381be025SRahul Sharma 
411381be025SRahul Sharma 	mixer_reg_writemask(res, MXR_STATUS, 0, MXR_STATUS_REG_RUN);
412381be025SRahul Sharma 
413381be025SRahul Sharma 	while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
414381be025SRahul Sharma 			--timeout)
415381be025SRahul Sharma 		usleep_range(10000, 12000);
416381be025SRahul Sharma }
417381be025SRahul Sharma 
4182eeb2e5eSGustavo Padovan static void vp_video_buffer(struct mixer_context *ctx,
4192eeb2e5eSGustavo Padovan 			    struct exynos_drm_plane *plane)
420d8408326SSeung-Woo Kim {
4210114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
4220114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
4232ee35d8bSMarek Szyprowski 	struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode;
424d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
4250114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
426d8408326SSeung-Woo Kim 	unsigned long flags;
427d8408326SSeung-Woo Kim 	dma_addr_t luma_addr[2], chroma_addr[2];
428d8408326SSeung-Woo Kim 	bool tiled_mode = false;
429d8408326SSeung-Woo Kim 	bool crcb_mode = false;
430d8408326SSeung-Woo Kim 	u32 val;
431d8408326SSeung-Woo Kim 
4322eeb2e5eSGustavo Padovan 	switch (fb->pixel_format) {
433363b06aaSVille Syrjälä 	case DRM_FORMAT_NV12:
434d8408326SSeung-Woo Kim 		crcb_mode = false;
435d8408326SSeung-Woo Kim 		break;
4368f2590f8STobias Jakobi 	case DRM_FORMAT_NV21:
4378f2590f8STobias Jakobi 		crcb_mode = true;
4388f2590f8STobias Jakobi 		break;
439d8408326SSeung-Woo Kim 	default:
440d8408326SSeung-Woo Kim 		DRM_ERROR("pixel format for vp is wrong [%d].\n",
4412eeb2e5eSGustavo Padovan 				fb->pixel_format);
442d8408326SSeung-Woo Kim 		return;
443d8408326SSeung-Woo Kim 	}
444d8408326SSeung-Woo Kim 
4450488f50eSMarek Szyprowski 	luma_addr[0] = exynos_drm_fb_dma_addr(fb, 0);
4460488f50eSMarek Szyprowski 	chroma_addr[0] = exynos_drm_fb_dma_addr(fb, 1);
447d8408326SSeung-Woo Kim 
4482eeb2e5eSGustavo Padovan 	if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
449d8408326SSeung-Woo Kim 		ctx->interlace = true;
450d8408326SSeung-Woo Kim 		if (tiled_mode) {
451d8408326SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + 0x40;
452d8408326SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + 0x40;
453d8408326SSeung-Woo Kim 		} else {
4542eeb2e5eSGustavo Padovan 			luma_addr[1] = luma_addr[0] + fb->pitches[0];
4552eeb2e5eSGustavo Padovan 			chroma_addr[1] = chroma_addr[0] + fb->pitches[0];
456d8408326SSeung-Woo Kim 		}
457d8408326SSeung-Woo Kim 	} else {
458d8408326SSeung-Woo Kim 		ctx->interlace = false;
459d8408326SSeung-Woo Kim 		luma_addr[1] = 0;
460d8408326SSeung-Woo Kim 		chroma_addr[1] = 0;
461d8408326SSeung-Woo Kim 	}
462d8408326SSeung-Woo Kim 
463d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
464d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
465d8408326SSeung-Woo Kim 
466d8408326SSeung-Woo Kim 	/* interlace or progressive scan mode */
467d8408326SSeung-Woo Kim 	val = (ctx->interlace ? ~0 : 0);
468d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP);
469d8408326SSeung-Woo Kim 
470d8408326SSeung-Woo Kim 	/* setup format */
471d8408326SSeung-Woo Kim 	val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12);
472d8408326SSeung-Woo Kim 	val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
473d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK);
474d8408326SSeung-Woo Kim 
475d8408326SSeung-Woo Kim 	/* setting size of input image */
4762eeb2e5eSGustavo Padovan 	vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) |
4772eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height));
478d8408326SSeung-Woo Kim 	/* chroma height has to reduced by 2 to avoid chroma distorions */
4792eeb2e5eSGustavo Padovan 	vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[0]) |
4802eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height / 2));
481d8408326SSeung-Woo Kim 
4820114f404SMarek Szyprowski 	vp_reg_write(res, VP_SRC_WIDTH, state->src.w);
4830114f404SMarek Szyprowski 	vp_reg_write(res, VP_SRC_HEIGHT, state->src.h);
484d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_H_POSITION,
4850114f404SMarek Szyprowski 			VP_SRC_H_POSITION_VAL(state->src.x));
4860114f404SMarek Szyprowski 	vp_reg_write(res, VP_SRC_V_POSITION, state->src.y);
487d8408326SSeung-Woo Kim 
4880114f404SMarek Szyprowski 	vp_reg_write(res, VP_DST_WIDTH, state->crtc.w);
4890114f404SMarek Szyprowski 	vp_reg_write(res, VP_DST_H_POSITION, state->crtc.x);
490d8408326SSeung-Woo Kim 	if (ctx->interlace) {
4910114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h / 2);
4920114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y / 2);
493d8408326SSeung-Woo Kim 	} else {
4940114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h);
4950114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y);
496d8408326SSeung-Woo Kim 	}
497d8408326SSeung-Woo Kim 
4980114f404SMarek Szyprowski 	vp_reg_write(res, VP_H_RATIO, state->h_ratio);
4990114f404SMarek Szyprowski 	vp_reg_write(res, VP_V_RATIO, state->v_ratio);
500d8408326SSeung-Woo Kim 
501d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
502d8408326SSeung-Woo Kim 
503d8408326SSeung-Woo Kim 	/* set buffer address to vp */
504d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]);
505d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]);
506d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]);
507d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]);
508d8408326SSeung-Woo Kim 
5092eeb2e5eSGustavo Padovan 	mixer_cfg_scan(ctx, mode->vdisplay);
5102eeb2e5eSGustavo Padovan 	mixer_cfg_rgb_fmt(ctx, mode->vdisplay);
5112eeb2e5eSGustavo Padovan 	mixer_cfg_layer(ctx, plane->zpos, true);
512d8408326SSeung-Woo Kim 	mixer_run(ctx);
513d8408326SSeung-Woo Kim 
514d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
515d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
516d8408326SSeung-Woo Kim 
517c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
518d8408326SSeung-Woo Kim 	vp_regs_dump(ctx);
519d8408326SSeung-Woo Kim }
520d8408326SSeung-Woo Kim 
521aaf8b49eSRahul Sharma static void mixer_layer_update(struct mixer_context *ctx)
522aaf8b49eSRahul Sharma {
523aaf8b49eSRahul Sharma 	struct mixer_resources *res = &ctx->mixer_res;
524aaf8b49eSRahul Sharma 
525aaf8b49eSRahul Sharma 	mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
526aaf8b49eSRahul Sharma }
527aaf8b49eSRahul Sharma 
5282611015cSTobias Jakobi static int mixer_setup_scale(const struct exynos_drm_plane *plane,
5292611015cSTobias Jakobi 		unsigned int *x_ratio, unsigned int *y_ratio)
5302611015cSTobias Jakobi {
5310114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
5320114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
5330114f404SMarek Szyprowski 
5340114f404SMarek Szyprowski 	if (state->crtc.w != state->src.w) {
5350114f404SMarek Szyprowski 		if (state->crtc.w == 2 * state->src.w)
5362611015cSTobias Jakobi 			*x_ratio = 1;
5372611015cSTobias Jakobi 		else
5382611015cSTobias Jakobi 			goto fail;
5392611015cSTobias Jakobi 	}
5402611015cSTobias Jakobi 
5410114f404SMarek Szyprowski 	if (state->crtc.h != state->src.h) {
5420114f404SMarek Szyprowski 		if (state->crtc.h == 2 * state->src.h)
5432611015cSTobias Jakobi 			*y_ratio = 1;
5442611015cSTobias Jakobi 		else
5452611015cSTobias Jakobi 			goto fail;
5462611015cSTobias Jakobi 	}
5472611015cSTobias Jakobi 
5482611015cSTobias Jakobi 	return 0;
5492611015cSTobias Jakobi 
5502611015cSTobias Jakobi fail:
5512611015cSTobias Jakobi 	DRM_DEBUG_KMS("only 2x width/height scaling of plane supported\n");
5522611015cSTobias Jakobi 	return -ENOTSUPP;
5532611015cSTobias Jakobi }
5542611015cSTobias Jakobi 
5552eeb2e5eSGustavo Padovan static void mixer_graph_buffer(struct mixer_context *ctx,
5562eeb2e5eSGustavo Padovan 			       struct exynos_drm_plane *plane)
557d8408326SSeung-Woo Kim {
5580114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
5590114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
5602ee35d8bSMarek Szyprowski 	struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode;
561d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
5620114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
563d8408326SSeung-Woo Kim 	unsigned long flags;
5642eeb2e5eSGustavo Padovan 	unsigned int win = plane->zpos;
5652611015cSTobias Jakobi 	unsigned int x_ratio = 0, y_ratio = 0;
566d8408326SSeung-Woo Kim 	unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset;
567d8408326SSeung-Woo Kim 	dma_addr_t dma_addr;
568d8408326SSeung-Woo Kim 	unsigned int fmt;
569d8408326SSeung-Woo Kim 	u32 val;
570d8408326SSeung-Woo Kim 
5712eeb2e5eSGustavo Padovan 	switch (fb->pixel_format) {
5727a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB4444:
5737a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB4444;
5747a57ca7cSTobias Jakobi 		break;
575d8408326SSeung-Woo Kim 
5767a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB1555:
5777a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB1555;
578d8408326SSeung-Woo Kim 		break;
5797a57ca7cSTobias Jakobi 
5807a57ca7cSTobias Jakobi 	case DRM_FORMAT_RGB565:
5817a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_RGB565;
582d8408326SSeung-Woo Kim 		break;
5837a57ca7cSTobias Jakobi 
5847a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB8888:
5857a57ca7cSTobias Jakobi 	case DRM_FORMAT_ARGB8888:
5867a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB8888;
5877a57ca7cSTobias Jakobi 		break;
5887a57ca7cSTobias Jakobi 
589d8408326SSeung-Woo Kim 	default:
5907a57ca7cSTobias Jakobi 		DRM_DEBUG_KMS("pixelformat unsupported by mixer\n");
5917a57ca7cSTobias Jakobi 		return;
592d8408326SSeung-Woo Kim 	}
593d8408326SSeung-Woo Kim 
5942611015cSTobias Jakobi 	/* check if mixer supports requested scaling setup */
5952611015cSTobias Jakobi 	if (mixer_setup_scale(plane, &x_ratio, &y_ratio))
5962611015cSTobias Jakobi 		return;
597d8408326SSeung-Woo Kim 
5980114f404SMarek Szyprowski 	dst_x_offset = state->crtc.x;
5990114f404SMarek Szyprowski 	dst_y_offset = state->crtc.y;
600d8408326SSeung-Woo Kim 
601d8408326SSeung-Woo Kim 	/* converting dma address base and source offset */
6020488f50eSMarek Szyprowski 	dma_addr = exynos_drm_fb_dma_addr(fb, 0)
6030114f404SMarek Szyprowski 		+ (state->src.x * fb->bits_per_pixel >> 3)
6040114f404SMarek Szyprowski 		+ (state->src.y * fb->pitches[0]);
605d8408326SSeung-Woo Kim 	src_x_offset = 0;
606d8408326SSeung-Woo Kim 	src_y_offset = 0;
607d8408326SSeung-Woo Kim 
6082eeb2e5eSGustavo Padovan 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
609d8408326SSeung-Woo Kim 		ctx->interlace = true;
610d8408326SSeung-Woo Kim 	else
611d8408326SSeung-Woo Kim 		ctx->interlace = false;
612d8408326SSeung-Woo Kim 
613d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
614d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
615d8408326SSeung-Woo Kim 
616d8408326SSeung-Woo Kim 	/* setup format */
617d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
618d8408326SSeung-Woo Kim 		MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
619d8408326SSeung-Woo Kim 
620d8408326SSeung-Woo Kim 	/* setup geometry */
621adacb228SDaniel Stone 	mixer_reg_write(res, MXR_GRAPHIC_SPAN(win),
6222eeb2e5eSGustavo Padovan 			fb->pitches[0] / (fb->bits_per_pixel >> 3));
623d8408326SSeung-Woo Kim 
624def5e095SRahul Sharma 	/* setup display size */
625def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_128_0_0_184 &&
6265d3d0995SGustavo Padovan 		win == DEFAULT_WIN) {
6272eeb2e5eSGustavo Padovan 		val  = MXR_MXR_RES_HEIGHT(mode->vdisplay);
6282eeb2e5eSGustavo Padovan 		val |= MXR_MXR_RES_WIDTH(mode->hdisplay);
629def5e095SRahul Sharma 		mixer_reg_write(res, MXR_RESOLUTION, val);
630def5e095SRahul Sharma 	}
631def5e095SRahul Sharma 
6320114f404SMarek Szyprowski 	val  = MXR_GRP_WH_WIDTH(state->src.w);
6330114f404SMarek Szyprowski 	val |= MXR_GRP_WH_HEIGHT(state->src.h);
634d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_H_SCALE(x_ratio);
635d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_V_SCALE(y_ratio);
636d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_WH(win), val);
637d8408326SSeung-Woo Kim 
638d8408326SSeung-Woo Kim 	/* setup offsets in source image */
639d8408326SSeung-Woo Kim 	val  = MXR_GRP_SXY_SX(src_x_offset);
640d8408326SSeung-Woo Kim 	val |= MXR_GRP_SXY_SY(src_y_offset);
641d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val);
642d8408326SSeung-Woo Kim 
643d8408326SSeung-Woo Kim 	/* setup offsets in display image */
644d8408326SSeung-Woo Kim 	val  = MXR_GRP_DXY_DX(dst_x_offset);
645d8408326SSeung-Woo Kim 	val |= MXR_GRP_DXY_DY(dst_y_offset);
646d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val);
647d8408326SSeung-Woo Kim 
648d8408326SSeung-Woo Kim 	/* set buffer address to mixer */
649d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr);
650d8408326SSeung-Woo Kim 
6512eeb2e5eSGustavo Padovan 	mixer_cfg_scan(ctx, mode->vdisplay);
6522eeb2e5eSGustavo Padovan 	mixer_cfg_rgb_fmt(ctx, mode->vdisplay);
653d8408326SSeung-Woo Kim 	mixer_cfg_layer(ctx, win, true);
654aaf8b49eSRahul Sharma 
655aaf8b49eSRahul Sharma 	/* layer update mandatory for mixer 16.0.33.0 */
656def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
657def5e095SRahul Sharma 		ctx->mxr_ver == MXR_VER_128_0_0_184)
658aaf8b49eSRahul Sharma 		mixer_layer_update(ctx);
659aaf8b49eSRahul Sharma 
660d8408326SSeung-Woo Kim 	mixer_run(ctx);
661d8408326SSeung-Woo Kim 
662d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
663d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
664c0734fbaSTobias Jakobi 
665c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
666d8408326SSeung-Woo Kim }
667d8408326SSeung-Woo Kim 
668d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx)
669d8408326SSeung-Woo Kim {
670d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
671d8408326SSeung-Woo Kim 	int tries = 100;
672d8408326SSeung-Woo Kim 
673d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING);
674d8408326SSeung-Woo Kim 	for (tries = 100; tries; --tries) {
675d8408326SSeung-Woo Kim 		/* waiting until VP_SRESET_PROCESSING is 0 */
676d8408326SSeung-Woo Kim 		if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING)
677d8408326SSeung-Woo Kim 			break;
67802b3de43STomasz Stanislawski 		mdelay(10);
679d8408326SSeung-Woo Kim 	}
680d8408326SSeung-Woo Kim 	WARN(tries == 0, "failed to reset Video Processor\n");
681d8408326SSeung-Woo Kim }
682d8408326SSeung-Woo Kim 
683cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx)
684cf8fc4f1SJoonyoung Shim {
685cf8fc4f1SJoonyoung Shim 	struct mixer_resources *res = &ctx->mixer_res;
686cf8fc4f1SJoonyoung Shim 	unsigned long flags;
687cf8fc4f1SJoonyoung Shim 	u32 val; /* value stored to register */
688cf8fc4f1SJoonyoung Shim 
689cf8fc4f1SJoonyoung Shim 	spin_lock_irqsave(&res->reg_slock, flags);
690cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, false);
691cf8fc4f1SJoonyoung Shim 
692cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
693cf8fc4f1SJoonyoung Shim 
694cf8fc4f1SJoonyoung Shim 	/* set output in RGB888 mode */
695cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
696cf8fc4f1SJoonyoung Shim 
697cf8fc4f1SJoonyoung Shim 	/* 16 beat burst in DMA */
698cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST,
699cf8fc4f1SJoonyoung Shim 		MXR_STATUS_BURST_MASK);
700cf8fc4f1SJoonyoung Shim 
701cf8fc4f1SJoonyoung Shim 	/* setting default layer priority: layer1 > layer0 > video
702cf8fc4f1SJoonyoung Shim 	 * because typical usage scenario would be
703cf8fc4f1SJoonyoung Shim 	 * layer1 - OSD
704cf8fc4f1SJoonyoung Shim 	 * layer0 - framebuffer
705cf8fc4f1SJoonyoung Shim 	 * video - video overlay
706cf8fc4f1SJoonyoung Shim 	 */
707cf8fc4f1SJoonyoung Shim 	val = MXR_LAYER_CFG_GRP1_VAL(3);
708cf8fc4f1SJoonyoung Shim 	val |= MXR_LAYER_CFG_GRP0_VAL(2);
7091b8e5747SRahul Sharma 	if (ctx->vp_enabled)
710cf8fc4f1SJoonyoung Shim 		val |= MXR_LAYER_CFG_VP_VAL(1);
711cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_LAYER_CFG, val);
712cf8fc4f1SJoonyoung Shim 
713cf8fc4f1SJoonyoung Shim 	/* setting background color */
714cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR0, 0x008080);
715cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR1, 0x008080);
716cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR2, 0x008080);
717cf8fc4f1SJoonyoung Shim 
718cf8fc4f1SJoonyoung Shim 	/* setting graphical layers */
719cf8fc4f1SJoonyoung Shim 	val  = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
720cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_WIN_BLEND_EN;
721cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_ALPHA_VAL(0xff); /* non-transparent alpha */
722cf8fc4f1SJoonyoung Shim 
7230377f4edSSean Paul 	/* Don't blend layer 0 onto the mixer background */
724cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(0), val);
7250377f4edSSean Paul 
7260377f4edSSean Paul 	/* Blend layer 1 into layer 0 */
7270377f4edSSean Paul 	val |= MXR_GRP_CFG_BLEND_PRE_MUL;
7280377f4edSSean Paul 	val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
729cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(1), val);
730cf8fc4f1SJoonyoung Shim 
7315736603bSSeung-Woo Kim 	/* setting video layers */
7325736603bSSeung-Woo Kim 	val = MXR_GRP_CFG_ALPHA_VAL(0);
7335736603bSSeung-Woo Kim 	mixer_reg_write(res, MXR_VIDEO_CFG, val);
7345736603bSSeung-Woo Kim 
7351b8e5747SRahul Sharma 	if (ctx->vp_enabled) {
736cf8fc4f1SJoonyoung Shim 		/* configuration of Video Processor Registers */
737cf8fc4f1SJoonyoung Shim 		vp_win_reset(ctx);
738cf8fc4f1SJoonyoung Shim 		vp_default_filter(res);
7391b8e5747SRahul Sharma 	}
740cf8fc4f1SJoonyoung Shim 
741cf8fc4f1SJoonyoung Shim 	/* disable all layers */
742cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
743cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
7441b8e5747SRahul Sharma 	if (ctx->vp_enabled)
745cf8fc4f1SJoonyoung Shim 		mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
746cf8fc4f1SJoonyoung Shim 
747cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, true);
748cf8fc4f1SJoonyoung Shim 	spin_unlock_irqrestore(&res->reg_slock, flags);
749cf8fc4f1SJoonyoung Shim }
750cf8fc4f1SJoonyoung Shim 
7514551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg)
7524551789fSSean Paul {
7534551789fSSean Paul 	struct mixer_context *ctx = arg;
7544551789fSSean Paul 	struct mixer_resources *res = &ctx->mixer_res;
7554551789fSSean Paul 	u32 val, base, shadow;
756822f6dfdSGustavo Padovan 	int win;
7574551789fSSean Paul 
7584551789fSSean Paul 	spin_lock(&res->reg_slock);
7594551789fSSean Paul 
7604551789fSSean Paul 	/* read interrupt status for handling and clearing flags for VSYNC */
7614551789fSSean Paul 	val = mixer_reg_read(res, MXR_INT_STATUS);
7624551789fSSean Paul 
7634551789fSSean Paul 	/* handling VSYNC */
7644551789fSSean Paul 	if (val & MXR_INT_STATUS_VSYNC) {
76581a464dfSAndrzej Hajda 		/* vsync interrupt use different bit for read and clear */
76681a464dfSAndrzej Hajda 		val |= MXR_INT_CLEAR_VSYNC;
76781a464dfSAndrzej Hajda 		val &= ~MXR_INT_STATUS_VSYNC;
76881a464dfSAndrzej Hajda 
7694551789fSSean Paul 		/* interlace scan need to check shadow register */
7704551789fSSean Paul 		if (ctx->interlace) {
7714551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0));
7724551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0));
7734551789fSSean Paul 			if (base != shadow)
7744551789fSSean Paul 				goto out;
7754551789fSSean Paul 
7764551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1));
7774551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1));
7784551789fSSean Paul 			if (base != shadow)
7794551789fSSean Paul 				goto out;
7804551789fSSean Paul 		}
7814551789fSSean Paul 
782eafd540aSGustavo Padovan 		drm_crtc_handle_vblank(&ctx->crtc->base);
783822f6dfdSGustavo Padovan 		for (win = 0 ; win < MIXER_WIN_NR ; win++) {
784822f6dfdSGustavo Padovan 			struct exynos_drm_plane *plane = &ctx->planes[win];
785822f6dfdSGustavo Padovan 
786822f6dfdSGustavo Padovan 			if (!plane->pending_fb)
787822f6dfdSGustavo Padovan 				continue;
788822f6dfdSGustavo Padovan 
789822f6dfdSGustavo Padovan 			exynos_drm_crtc_finish_update(ctx->crtc, plane);
790822f6dfdSGustavo Padovan 		}
7914551789fSSean Paul 
7924551789fSSean Paul 		/* set wait vsync event to zero and wake up queue. */
7934551789fSSean Paul 		if (atomic_read(&ctx->wait_vsync_event)) {
7944551789fSSean Paul 			atomic_set(&ctx->wait_vsync_event, 0);
7954551789fSSean Paul 			wake_up(&ctx->wait_vsync_queue);
7964551789fSSean Paul 		}
7974551789fSSean Paul 	}
7984551789fSSean Paul 
7994551789fSSean Paul out:
8004551789fSSean Paul 	/* clear interrupts */
8014551789fSSean Paul 	mixer_reg_write(res, MXR_INT_STATUS, val);
8024551789fSSean Paul 
8034551789fSSean Paul 	spin_unlock(&res->reg_slock);
8044551789fSSean Paul 
8054551789fSSean Paul 	return IRQ_HANDLED;
8064551789fSSean Paul }
8074551789fSSean Paul 
8084551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx)
8094551789fSSean Paul {
8104551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
8114551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
8124551789fSSean Paul 	struct resource *res;
8134551789fSSean Paul 	int ret;
8144551789fSSean Paul 
8154551789fSSean Paul 	spin_lock_init(&mixer_res->reg_slock);
8164551789fSSean Paul 
8174551789fSSean Paul 	mixer_res->mixer = devm_clk_get(dev, "mixer");
8184551789fSSean Paul 	if (IS_ERR(mixer_res->mixer)) {
8194551789fSSean Paul 		dev_err(dev, "failed to get clock 'mixer'\n");
8204551789fSSean Paul 		return -ENODEV;
8214551789fSSean Paul 	}
8224551789fSSean Paul 
82304427ec5SMarek Szyprowski 	mixer_res->hdmi = devm_clk_get(dev, "hdmi");
82404427ec5SMarek Szyprowski 	if (IS_ERR(mixer_res->hdmi)) {
82504427ec5SMarek Szyprowski 		dev_err(dev, "failed to get clock 'hdmi'\n");
82604427ec5SMarek Szyprowski 		return PTR_ERR(mixer_res->hdmi);
82704427ec5SMarek Szyprowski 	}
82804427ec5SMarek Szyprowski 
8294551789fSSean Paul 	mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
8304551789fSSean Paul 	if (IS_ERR(mixer_res->sclk_hdmi)) {
8314551789fSSean Paul 		dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
8324551789fSSean Paul 		return -ENODEV;
8334551789fSSean Paul 	}
8344551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
8354551789fSSean Paul 	if (res == NULL) {
8364551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8374551789fSSean Paul 		return -ENXIO;
8384551789fSSean Paul 	}
8394551789fSSean Paul 
8404551789fSSean Paul 	mixer_res->mixer_regs = devm_ioremap(dev, res->start,
8414551789fSSean Paul 							resource_size(res));
8424551789fSSean Paul 	if (mixer_res->mixer_regs == NULL) {
8434551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8444551789fSSean Paul 		return -ENXIO;
8454551789fSSean Paul 	}
8464551789fSSean Paul 
8474551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0);
8484551789fSSean Paul 	if (res == NULL) {
8494551789fSSean Paul 		dev_err(dev, "get interrupt resource failed.\n");
8504551789fSSean Paul 		return -ENXIO;
8514551789fSSean Paul 	}
8524551789fSSean Paul 
8534551789fSSean Paul 	ret = devm_request_irq(dev, res->start, mixer_irq_handler,
8544551789fSSean Paul 						0, "drm_mixer", mixer_ctx);
8554551789fSSean Paul 	if (ret) {
8564551789fSSean Paul 		dev_err(dev, "request interrupt failed.\n");
8574551789fSSean Paul 		return ret;
8584551789fSSean Paul 	}
8594551789fSSean Paul 	mixer_res->irq = res->start;
8604551789fSSean Paul 
8614551789fSSean Paul 	return 0;
8624551789fSSean Paul }
8634551789fSSean Paul 
8644551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx)
8654551789fSSean Paul {
8664551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
8674551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
8684551789fSSean Paul 	struct resource *res;
8694551789fSSean Paul 
8704551789fSSean Paul 	mixer_res->vp = devm_clk_get(dev, "vp");
8714551789fSSean Paul 	if (IS_ERR(mixer_res->vp)) {
8724551789fSSean Paul 		dev_err(dev, "failed to get clock 'vp'\n");
8734551789fSSean Paul 		return -ENODEV;
8744551789fSSean Paul 	}
875ff830c96SMarek Szyprowski 
876ff830c96SMarek Szyprowski 	if (mixer_ctx->has_sclk) {
8774551789fSSean Paul 		mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
8784551789fSSean Paul 		if (IS_ERR(mixer_res->sclk_mixer)) {
8794551789fSSean Paul 			dev_err(dev, "failed to get clock 'sclk_mixer'\n");
8804551789fSSean Paul 			return -ENODEV;
8814551789fSSean Paul 		}
882ff830c96SMarek Szyprowski 		mixer_res->mout_mixer = devm_clk_get(dev, "mout_mixer");
883ff830c96SMarek Szyprowski 		if (IS_ERR(mixer_res->mout_mixer)) {
884ff830c96SMarek Szyprowski 			dev_err(dev, "failed to get clock 'mout_mixer'\n");
8854551789fSSean Paul 			return -ENODEV;
8864551789fSSean Paul 		}
8874551789fSSean Paul 
888ff830c96SMarek Szyprowski 		if (mixer_res->sclk_hdmi && mixer_res->mout_mixer)
889ff830c96SMarek Szyprowski 			clk_set_parent(mixer_res->mout_mixer,
890ff830c96SMarek Szyprowski 				       mixer_res->sclk_hdmi);
891ff830c96SMarek Szyprowski 	}
8924551789fSSean Paul 
8934551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
8944551789fSSean Paul 	if (res == NULL) {
8954551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8964551789fSSean Paul 		return -ENXIO;
8974551789fSSean Paul 	}
8984551789fSSean Paul 
8994551789fSSean Paul 	mixer_res->vp_regs = devm_ioremap(dev, res->start,
9004551789fSSean Paul 							resource_size(res));
9014551789fSSean Paul 	if (mixer_res->vp_regs == NULL) {
9024551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
9034551789fSSean Paul 		return -ENXIO;
9044551789fSSean Paul 	}
9054551789fSSean Paul 
9064551789fSSean Paul 	return 0;
9074551789fSSean Paul }
9084551789fSSean Paul 
90993bca243SGustavo Padovan static int mixer_initialize(struct mixer_context *mixer_ctx,
910f37cd5e8SInki Dae 			struct drm_device *drm_dev)
9114551789fSSean Paul {
9124551789fSSean Paul 	int ret;
913f37cd5e8SInki Dae 	struct exynos_drm_private *priv;
914f37cd5e8SInki Dae 	priv = drm_dev->dev_private;
9154551789fSSean Paul 
916eb88e422SGustavo Padovan 	mixer_ctx->drm_dev = drm_dev;
9178a326eddSGustavo Padovan 	mixer_ctx->pipe = priv->pipe++;
9184551789fSSean Paul 
9194551789fSSean Paul 	/* acquire resources: regs, irqs, clocks */
9204551789fSSean Paul 	ret = mixer_resources_init(mixer_ctx);
9214551789fSSean Paul 	if (ret) {
9224551789fSSean Paul 		DRM_ERROR("mixer_resources_init failed ret=%d\n", ret);
9234551789fSSean Paul 		return ret;
9244551789fSSean Paul 	}
9254551789fSSean Paul 
9264551789fSSean Paul 	if (mixer_ctx->vp_enabled) {
9274551789fSSean Paul 		/* acquire vp resources: regs, irqs, clocks */
9284551789fSSean Paul 		ret = vp_resources_init(mixer_ctx);
9294551789fSSean Paul 		if (ret) {
9304551789fSSean Paul 			DRM_ERROR("vp_resources_init failed ret=%d\n", ret);
9314551789fSSean Paul 			return ret;
9324551789fSSean Paul 		}
9334551789fSSean Paul 	}
9344551789fSSean Paul 
935eb7a3fc7SJoonyoung Shim 	ret = drm_iommu_attach_device(drm_dev, mixer_ctx->dev);
936fc2e013fSHyungwon Hwang 	if (ret)
937fc2e013fSHyungwon Hwang 		priv->pipe--;
938f041b257SSean Paul 
939fc2e013fSHyungwon Hwang 	return ret;
9401055b39fSInki Dae }
9411055b39fSInki Dae 
94293bca243SGustavo Padovan static void mixer_ctx_remove(struct mixer_context *mixer_ctx)
943d8408326SSeung-Woo Kim {
944f041b257SSean Paul 	drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev);
945f041b257SSean Paul }
946f041b257SSean Paul 
94793bca243SGustavo Padovan static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)
948f041b257SSean Paul {
94993bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
950d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
951d8408326SSeung-Woo Kim 
9520df5e4acSAndrzej Hajda 	__set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9530df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
954f041b257SSean Paul 		return 0;
955d8408326SSeung-Woo Kim 
956d8408326SSeung-Woo Kim 	/* enable vsync interrupt */
957fc073248SAndrzej Hajda 	mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
958fc073248SAndrzej Hajda 	mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
959d8408326SSeung-Woo Kim 
960d8408326SSeung-Woo Kim 	return 0;
961d8408326SSeung-Woo Kim }
962d8408326SSeung-Woo Kim 
96393bca243SGustavo Padovan static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
964d8408326SSeung-Woo Kim {
96593bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
966d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
967d8408326SSeung-Woo Kim 
9680df5e4acSAndrzej Hajda 	__clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9690df5e4acSAndrzej Hajda 
9700df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
971947710c6SAndrzej Hajda 		return;
972947710c6SAndrzej Hajda 
973d8408326SSeung-Woo Kim 	/* disable vsync interrupt */
974fc073248SAndrzej Hajda 	mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
975d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
976d8408326SSeung-Woo Kim }
977d8408326SSeung-Woo Kim 
9781e1d1393SGustavo Padovan static void mixer_update_plane(struct exynos_drm_crtc *crtc,
9791e1d1393SGustavo Padovan 			       struct exynos_drm_plane *plane)
980d8408326SSeung-Woo Kim {
98193bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
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))
986dda9012bSShirish S 		return;
987dda9012bSShirish S 
9881e1d1393SGustavo Padovan 	if (plane->zpos > 1 && mixer_ctx->vp_enabled)
9892eeb2e5eSGustavo Padovan 		vp_video_buffer(mixer_ctx, plane);
990d8408326SSeung-Woo Kim 	else
9912eeb2e5eSGustavo Padovan 		mixer_graph_buffer(mixer_ctx, plane);
992d8408326SSeung-Woo Kim }
993d8408326SSeung-Woo Kim 
9941e1d1393SGustavo Padovan static void mixer_disable_plane(struct exynos_drm_crtc *crtc,
9951e1d1393SGustavo Padovan 				struct exynos_drm_plane *plane)
996d8408326SSeung-Woo Kim {
99793bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
998d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
999d8408326SSeung-Woo Kim 	unsigned long flags;
1000d8408326SSeung-Woo Kim 
10011e1d1393SGustavo Padovan 	DRM_DEBUG_KMS("win: %d\n", plane->zpos);
1002d8408326SSeung-Woo Kim 
1003a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
1004db43fd16SPrathyush K 		return;
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 
10091e1d1393SGustavo Padovan 	mixer_cfg_layer(mixer_ctx, plane->zpos, false);
1010d8408326SSeung-Woo Kim 
1011d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, true);
1012d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
1013d8408326SSeung-Woo Kim }
1014d8408326SSeung-Woo Kim 
101593bca243SGustavo Padovan static void mixer_wait_for_vblank(struct exynos_drm_crtc *crtc)
10160ea6822fSRahul Sharma {
101793bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
10187c4c5584SJoonyoung Shim 	int err;
10198137a2e2SPrathyush K 
1020a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
10216e95d5e6SPrathyush K 		return;
10226e95d5e6SPrathyush K 
102393bca243SGustavo Padovan 	err = drm_vblank_get(mixer_ctx->drm_dev, mixer_ctx->pipe);
10247c4c5584SJoonyoung Shim 	if (err < 0) {
10257c4c5584SJoonyoung Shim 		DRM_DEBUG_KMS("failed to acquire vblank counter\n");
10267c4c5584SJoonyoung Shim 		return;
10277c4c5584SJoonyoung Shim 	}
10285d39b9eeSRahul Sharma 
10296e95d5e6SPrathyush K 	atomic_set(&mixer_ctx->wait_vsync_event, 1);
10306e95d5e6SPrathyush K 
10316e95d5e6SPrathyush K 	/*
10326e95d5e6SPrathyush K 	 * wait for MIXER to signal VSYNC interrupt or return after
10336e95d5e6SPrathyush K 	 * timeout which is set to 50ms (refresh rate of 20).
10346e95d5e6SPrathyush K 	 */
10356e95d5e6SPrathyush K 	if (!wait_event_timeout(mixer_ctx->wait_vsync_queue,
10366e95d5e6SPrathyush K 				!atomic_read(&mixer_ctx->wait_vsync_event),
1037bfd8303aSDaniel Vetter 				HZ/20))
10388137a2e2SPrathyush K 		DRM_DEBUG_KMS("vblank wait timed out.\n");
10395d39b9eeSRahul Sharma 
104093bca243SGustavo Padovan 	drm_vblank_put(mixer_ctx->drm_dev, mixer_ctx->pipe);
10418137a2e2SPrathyush K }
10428137a2e2SPrathyush K 
10433cecda03SGustavo Padovan static void mixer_enable(struct exynos_drm_crtc *crtc)
1044db43fd16SPrathyush K {
10453cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
1046db43fd16SPrathyush K 	struct mixer_resources *res = &ctx->mixer_res;
1047db43fd16SPrathyush K 
1048a44652e8SAndrzej Hajda 	if (test_bit(MXR_BIT_POWERED, &ctx->flags))
1049db43fd16SPrathyush K 		return;
1050db43fd16SPrathyush K 
1051af65c804SSean Paul 	pm_runtime_get_sync(ctx->dev);
1052af65c804SSean Paul 
1053d74ed937SRahul Sharma 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
1054d74ed937SRahul Sharma 
10550df5e4acSAndrzej Hajda 	if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) {
1056fc073248SAndrzej Hajda 		mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
10570df5e4acSAndrzej Hajda 		mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
10580df5e4acSAndrzej Hajda 	}
1059db43fd16SPrathyush K 	mixer_win_reset(ctx);
1060ccf034a9SGustavo Padovan 
1061ccf034a9SGustavo Padovan 	set_bit(MXR_BIT_POWERED, &ctx->flags);
1062db43fd16SPrathyush K }
1063db43fd16SPrathyush K 
10643cecda03SGustavo Padovan static void mixer_disable(struct exynos_drm_crtc *crtc)
1065db43fd16SPrathyush K {
10663cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
1067c329f667SJoonyoung Shim 	int i;
1068db43fd16SPrathyush K 
1069a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
1070b4bfa3c7SRahul Sharma 		return;
1071db43fd16SPrathyush K 
1072381be025SRahul Sharma 	mixer_stop(ctx);
1073c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
1074c329f667SJoonyoung Shim 
1075c329f667SJoonyoung Shim 	for (i = 0; i < MIXER_WIN_NR; i++)
10761e1d1393SGustavo Padovan 		mixer_disable_plane(crtc, &ctx->planes[i]);
1077db43fd16SPrathyush K 
1078ccf034a9SGustavo Padovan 	pm_runtime_put(ctx->dev);
1079ccf034a9SGustavo Padovan 
1080a44652e8SAndrzej Hajda 	clear_bit(MXR_BIT_POWERED, &ctx->flags);
1081db43fd16SPrathyush K }
1082db43fd16SPrathyush K 
1083f041b257SSean Paul /* Only valid for Mixer version 16.0.33.0 */
10843ae24362SAndrzej Hajda static int mixer_atomic_check(struct exynos_drm_crtc *crtc,
10853ae24362SAndrzej Hajda 		       struct drm_crtc_state *state)
1086f041b257SSean Paul {
10873ae24362SAndrzej Hajda 	struct drm_display_mode *mode = &state->adjusted_mode;
1088f041b257SSean Paul 	u32 w, h;
1089f041b257SSean Paul 
1090f041b257SSean Paul 	w = mode->hdisplay;
1091f041b257SSean Paul 	h = mode->vdisplay;
1092f041b257SSean Paul 
1093f041b257SSean Paul 	DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n",
1094f041b257SSean Paul 		mode->hdisplay, mode->vdisplay, mode->vrefresh,
1095f041b257SSean Paul 		(mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
1096f041b257SSean Paul 
1097f041b257SSean Paul 	if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
1098f041b257SSean Paul 		(w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
1099f041b257SSean Paul 		(w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
1100f041b257SSean Paul 		return 0;
1101f041b257SSean Paul 
1102f041b257SSean Paul 	return -EINVAL;
1103f041b257SSean Paul }
1104f041b257SSean Paul 
1105f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops mixer_crtc_ops = {
11063cecda03SGustavo Padovan 	.enable			= mixer_enable,
11073cecda03SGustavo Padovan 	.disable		= mixer_disable,
1108d8408326SSeung-Woo Kim 	.enable_vblank		= mixer_enable_vblank,
1109d8408326SSeung-Woo Kim 	.disable_vblank		= mixer_disable_vblank,
11108137a2e2SPrathyush K 	.wait_for_vblank	= mixer_wait_for_vblank,
11119cc7610aSGustavo Padovan 	.update_plane		= mixer_update_plane,
11129cc7610aSGustavo Padovan 	.disable_plane		= mixer_disable_plane,
11133ae24362SAndrzej Hajda 	.atomic_check		= mixer_atomic_check,
1114f041b257SSean Paul };
11150ea6822fSRahul Sharma 
1116def5e095SRahul Sharma static struct mixer_drv_data exynos5420_mxr_drv_data = {
1117def5e095SRahul Sharma 	.version = MXR_VER_128_0_0_184,
1118def5e095SRahul Sharma 	.is_vp_enabled = 0,
1119def5e095SRahul Sharma };
1120def5e095SRahul Sharma 
1121cc57caf0SRahul Sharma static struct mixer_drv_data exynos5250_mxr_drv_data = {
1122aaf8b49eSRahul Sharma 	.version = MXR_VER_16_0_33_0,
1123aaf8b49eSRahul Sharma 	.is_vp_enabled = 0,
1124aaf8b49eSRahul Sharma };
1125aaf8b49eSRahul Sharma 
1126ff830c96SMarek Szyprowski static struct mixer_drv_data exynos4212_mxr_drv_data = {
1127ff830c96SMarek Szyprowski 	.version = MXR_VER_0_0_0_16,
1128ff830c96SMarek Szyprowski 	.is_vp_enabled = 1,
1129ff830c96SMarek Szyprowski };
1130ff830c96SMarek Szyprowski 
1131cc57caf0SRahul Sharma static struct mixer_drv_data exynos4210_mxr_drv_data = {
11321e123441SRahul Sharma 	.version = MXR_VER_0_0_0_16,
11331b8e5747SRahul Sharma 	.is_vp_enabled = 1,
1134ff830c96SMarek Szyprowski 	.has_sclk = 1,
11351e123441SRahul Sharma };
11361e123441SRahul Sharma 
1137d6b16302SKrzysztof Kozlowski static const struct platform_device_id mixer_driver_types[] = {
11381e123441SRahul Sharma 	{
11391e123441SRahul Sharma 		.name		= "s5p-mixer",
1140cc57caf0SRahul Sharma 		.driver_data	= (unsigned long)&exynos4210_mxr_drv_data,
11411e123441SRahul Sharma 	}, {
1142aaf8b49eSRahul Sharma 		.name		= "exynos5-mixer",
1143cc57caf0SRahul Sharma 		.driver_data	= (unsigned long)&exynos5250_mxr_drv_data,
1144aaf8b49eSRahul Sharma 	}, {
1145aaf8b49eSRahul Sharma 		/* end node */
1146aaf8b49eSRahul Sharma 	}
1147aaf8b49eSRahul Sharma };
1148aaf8b49eSRahul Sharma 
1149aaf8b49eSRahul Sharma static struct of_device_id mixer_match_types[] = {
1150aaf8b49eSRahul Sharma 	{
1151ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4210-mixer",
1152ff830c96SMarek Szyprowski 		.data	= &exynos4210_mxr_drv_data,
1153ff830c96SMarek Szyprowski 	}, {
1154ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4212-mixer",
1155ff830c96SMarek Szyprowski 		.data	= &exynos4212_mxr_drv_data,
1156ff830c96SMarek Szyprowski 	}, {
1157aaf8b49eSRahul Sharma 		.compatible = "samsung,exynos5-mixer",
1158cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1159cc57caf0SRahul Sharma 	}, {
1160cc57caf0SRahul Sharma 		.compatible = "samsung,exynos5250-mixer",
1161cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1162aaf8b49eSRahul Sharma 	}, {
1163def5e095SRahul Sharma 		.compatible = "samsung,exynos5420-mixer",
1164def5e095SRahul Sharma 		.data	= &exynos5420_mxr_drv_data,
1165def5e095SRahul Sharma 	}, {
11661e123441SRahul Sharma 		/* end node */
11671e123441SRahul Sharma 	}
11681e123441SRahul Sharma };
116939b58a39SSjoerd Simons MODULE_DEVICE_TABLE(of, mixer_match_types);
11701e123441SRahul Sharma 
1171f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data)
1172d8408326SSeung-Woo Kim {
11738103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
1174f37cd5e8SInki Dae 	struct drm_device *drm_dev = data;
11757ee14cdcSGustavo Padovan 	struct exynos_drm_plane *exynos_plane;
1176*fd2d2fc2SMarek Szyprowski 	unsigned int i;
11776e2a3b66SGustavo Padovan 	int ret;
1178d8408326SSeung-Woo Kim 
1179e2dc3f72SAlban Browaeys 	ret = mixer_initialize(ctx, drm_dev);
1180e2dc3f72SAlban Browaeys 	if (ret)
1181e2dc3f72SAlban Browaeys 		return ret;
1182e2dc3f72SAlban Browaeys 
1183*fd2d2fc2SMarek Szyprowski 	for (i = 0; i < MIXER_WIN_NR; i++) {
1184*fd2d2fc2SMarek Szyprowski 		if (i == VP_DEFAULT_WIN && !ctx->vp_enabled)
1185ab144201SMarek Szyprowski 			continue;
1186ab144201SMarek Szyprowski 
1187*fd2d2fc2SMarek Szyprowski 		ret = exynos_plane_init(drm_dev, &ctx->planes[i],
1188*fd2d2fc2SMarek Szyprowski 					1 << ctx->pipe, &plane_configs[i]);
11897ee14cdcSGustavo Padovan 		if (ret)
11907ee14cdcSGustavo Padovan 			return ret;
11917ee14cdcSGustavo Padovan 	}
11927ee14cdcSGustavo Padovan 
11935d3d0995SGustavo Padovan 	exynos_plane = &ctx->planes[DEFAULT_WIN];
11947ee14cdcSGustavo Padovan 	ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
11957ee14cdcSGustavo Padovan 					   ctx->pipe, EXYNOS_DISPLAY_TYPE_HDMI,
119693bca243SGustavo Padovan 					   &mixer_crtc_ops, ctx);
119793bca243SGustavo Padovan 	if (IS_ERR(ctx->crtc)) {
1198e2dc3f72SAlban Browaeys 		mixer_ctx_remove(ctx);
119993bca243SGustavo Padovan 		ret = PTR_ERR(ctx->crtc);
120093bca243SGustavo Padovan 		goto free_ctx;
12018103ef1bSAndrzej Hajda 	}
12028103ef1bSAndrzej Hajda 
12038103ef1bSAndrzej Hajda 	return 0;
120493bca243SGustavo Padovan 
120593bca243SGustavo Padovan free_ctx:
120693bca243SGustavo Padovan 	devm_kfree(dev, ctx);
120793bca243SGustavo Padovan 	return ret;
12088103ef1bSAndrzej Hajda }
12098103ef1bSAndrzej Hajda 
12108103ef1bSAndrzej Hajda static void mixer_unbind(struct device *dev, struct device *master, void *data)
12118103ef1bSAndrzej Hajda {
12128103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
12138103ef1bSAndrzej Hajda 
121493bca243SGustavo Padovan 	mixer_ctx_remove(ctx);
12158103ef1bSAndrzej Hajda }
12168103ef1bSAndrzej Hajda 
12178103ef1bSAndrzej Hajda static const struct component_ops mixer_component_ops = {
12188103ef1bSAndrzej Hajda 	.bind	= mixer_bind,
12198103ef1bSAndrzej Hajda 	.unbind	= mixer_unbind,
12208103ef1bSAndrzej Hajda };
12218103ef1bSAndrzej Hajda 
12228103ef1bSAndrzej Hajda static int mixer_probe(struct platform_device *pdev)
12238103ef1bSAndrzej Hajda {
12248103ef1bSAndrzej Hajda 	struct device *dev = &pdev->dev;
12258103ef1bSAndrzej Hajda 	struct mixer_drv_data *drv;
12268103ef1bSAndrzej Hajda 	struct mixer_context *ctx;
12278103ef1bSAndrzej Hajda 	int ret;
1228d8408326SSeung-Woo Kim 
1229f041b257SSean Paul 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1230f041b257SSean Paul 	if (!ctx) {
1231f041b257SSean Paul 		DRM_ERROR("failed to alloc mixer context.\n");
1232d8408326SSeung-Woo Kim 		return -ENOMEM;
1233f041b257SSean Paul 	}
1234d8408326SSeung-Woo Kim 
1235aaf8b49eSRahul Sharma 	if (dev->of_node) {
1236aaf8b49eSRahul Sharma 		const struct of_device_id *match;
12378103ef1bSAndrzej Hajda 
1238e436b09dSSachin Kamat 		match = of_match_node(mixer_match_types, dev->of_node);
12392cdc53b3SRahul Sharma 		drv = (struct mixer_drv_data *)match->data;
1240aaf8b49eSRahul Sharma 	} else {
1241aaf8b49eSRahul Sharma 		drv = (struct mixer_drv_data *)
1242aaf8b49eSRahul Sharma 			platform_get_device_id(pdev)->driver_data;
1243aaf8b49eSRahul Sharma 	}
1244aaf8b49eSRahul Sharma 
12454551789fSSean Paul 	ctx->pdev = pdev;
1246d873ab99SSeung-Woo Kim 	ctx->dev = dev;
12471b8e5747SRahul Sharma 	ctx->vp_enabled = drv->is_vp_enabled;
1248ff830c96SMarek Szyprowski 	ctx->has_sclk = drv->has_sclk;
12491e123441SRahul Sharma 	ctx->mxr_ver = drv->version;
125057ed0f7bSDaniel Vetter 	init_waitqueue_head(&ctx->wait_vsync_queue);
12516e95d5e6SPrathyush K 	atomic_set(&ctx->wait_vsync_event, 0);
1252d8408326SSeung-Woo Kim 
12538103ef1bSAndrzej Hajda 	platform_set_drvdata(pdev, ctx);
1254df5225bcSInki Dae 
1255df5225bcSInki Dae 	ret = component_add(&pdev->dev, &mixer_component_ops);
125686650408SAndrzej Hajda 	if (!ret)
12578103ef1bSAndrzej Hajda 		pm_runtime_enable(dev);
1258df5225bcSInki Dae 
1259df5225bcSInki Dae 	return ret;
1260f37cd5e8SInki Dae }
1261f37cd5e8SInki Dae 
1262d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev)
1263d8408326SSeung-Woo Kim {
12648103ef1bSAndrzej Hajda 	pm_runtime_disable(&pdev->dev);
12658103ef1bSAndrzej Hajda 
1266df5225bcSInki Dae 	component_del(&pdev->dev, &mixer_component_ops);
1267df5225bcSInki Dae 
1268d8408326SSeung-Woo Kim 	return 0;
1269d8408326SSeung-Woo Kim }
1270d8408326SSeung-Woo Kim 
1271ccf034a9SGustavo Padovan #ifdef CONFIG_PM_SLEEP
1272ccf034a9SGustavo Padovan static int exynos_mixer_suspend(struct device *dev)
1273ccf034a9SGustavo Padovan {
1274ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1275ccf034a9SGustavo Padovan 	struct mixer_resources *res = &ctx->mixer_res;
1276ccf034a9SGustavo Padovan 
1277ccf034a9SGustavo Padovan 	clk_disable_unprepare(res->hdmi);
1278ccf034a9SGustavo Padovan 	clk_disable_unprepare(res->mixer);
1279ccf034a9SGustavo Padovan 	if (ctx->vp_enabled) {
1280ccf034a9SGustavo Padovan 		clk_disable_unprepare(res->vp);
1281ccf034a9SGustavo Padovan 		if (ctx->has_sclk)
1282ccf034a9SGustavo Padovan 			clk_disable_unprepare(res->sclk_mixer);
1283ccf034a9SGustavo Padovan 	}
1284ccf034a9SGustavo Padovan 
1285ccf034a9SGustavo Padovan 	return 0;
1286ccf034a9SGustavo Padovan }
1287ccf034a9SGustavo Padovan 
1288ccf034a9SGustavo Padovan static int exynos_mixer_resume(struct device *dev)
1289ccf034a9SGustavo Padovan {
1290ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1291ccf034a9SGustavo Padovan 	struct mixer_resources *res = &ctx->mixer_res;
1292ccf034a9SGustavo Padovan 	int ret;
1293ccf034a9SGustavo Padovan 
1294ccf034a9SGustavo Padovan 	ret = clk_prepare_enable(res->mixer);
1295ccf034a9SGustavo Padovan 	if (ret < 0) {
1296ccf034a9SGustavo Padovan 		DRM_ERROR("Failed to prepare_enable the mixer clk [%d]\n", ret);
1297ccf034a9SGustavo Padovan 		return ret;
1298ccf034a9SGustavo Padovan 	}
1299ccf034a9SGustavo Padovan 	ret = clk_prepare_enable(res->hdmi);
1300ccf034a9SGustavo Padovan 	if (ret < 0) {
1301ccf034a9SGustavo Padovan 		DRM_ERROR("Failed to prepare_enable the hdmi clk [%d]\n", ret);
1302ccf034a9SGustavo Padovan 		return ret;
1303ccf034a9SGustavo Padovan 	}
1304ccf034a9SGustavo Padovan 	if (ctx->vp_enabled) {
1305ccf034a9SGustavo Padovan 		ret = clk_prepare_enable(res->vp);
1306ccf034a9SGustavo Padovan 		if (ret < 0) {
1307ccf034a9SGustavo Padovan 			DRM_ERROR("Failed to prepare_enable the vp clk [%d]\n",
1308ccf034a9SGustavo Padovan 				  ret);
1309ccf034a9SGustavo Padovan 			return ret;
1310ccf034a9SGustavo Padovan 		}
1311ccf034a9SGustavo Padovan 		if (ctx->has_sclk) {
1312ccf034a9SGustavo Padovan 			ret = clk_prepare_enable(res->sclk_mixer);
1313ccf034a9SGustavo Padovan 			if (ret < 0) {
1314ccf034a9SGustavo Padovan 				DRM_ERROR("Failed to prepare_enable the " \
1315ccf034a9SGustavo Padovan 					   "sclk_mixer clk [%d]\n",
1316ccf034a9SGustavo Padovan 					  ret);
1317ccf034a9SGustavo Padovan 				return ret;
1318ccf034a9SGustavo Padovan 			}
1319ccf034a9SGustavo Padovan 		}
1320ccf034a9SGustavo Padovan 	}
1321ccf034a9SGustavo Padovan 
1322ccf034a9SGustavo Padovan 	return 0;
1323ccf034a9SGustavo Padovan }
1324ccf034a9SGustavo Padovan #endif
1325ccf034a9SGustavo Padovan 
1326ccf034a9SGustavo Padovan static const struct dev_pm_ops exynos_mixer_pm_ops = {
1327ccf034a9SGustavo Padovan 	SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL)
1328ccf034a9SGustavo Padovan };
1329ccf034a9SGustavo Padovan 
1330d8408326SSeung-Woo Kim struct platform_driver mixer_driver = {
1331d8408326SSeung-Woo Kim 	.driver = {
1332aaf8b49eSRahul Sharma 		.name = "exynos-mixer",
1333d8408326SSeung-Woo Kim 		.owner = THIS_MODULE,
1334ccf034a9SGustavo Padovan 		.pm = &exynos_mixer_pm_ops,
1335aaf8b49eSRahul Sharma 		.of_match_table = mixer_match_types,
1336d8408326SSeung-Woo Kim 	},
1337d8408326SSeung-Woo Kim 	.probe = mixer_probe,
133856550d94SGreg Kroah-Hartman 	.remove = mixer_remove,
13391e123441SRahul Sharma 	.id_table	= mixer_driver_types,
1340d8408326SSeung-Woo Kim };
1341