xref: /linux/drivers/gpu/drm/exynos/exynos_mixer.c (revision 6be900563a9e7420ead7de5737a004e1878ef145)
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>
236a3b45adSAndrzej Hajda #include <linux/ktime.h>
24d8408326SSeung-Woo Kim #include <linux/spinlock.h>
25d8408326SSeung-Woo Kim #include <linux/wait.h>
26d8408326SSeung-Woo Kim #include <linux/i2c.h>
27d8408326SSeung-Woo Kim #include <linux/platform_device.h>
28d8408326SSeung-Woo Kim #include <linux/interrupt.h>
29d8408326SSeung-Woo Kim #include <linux/irq.h>
30d8408326SSeung-Woo Kim #include <linux/delay.h>
31d8408326SSeung-Woo Kim #include <linux/pm_runtime.h>
32d8408326SSeung-Woo Kim #include <linux/clk.h>
33d8408326SSeung-Woo Kim #include <linux/regulator/consumer.h>
343f1c781dSSachin Kamat #include <linux/of.h>
3548f6155aSMarek Szyprowski #include <linux/of_device.h>
36f37cd5e8SInki Dae #include <linux/component.h>
37d8408326SSeung-Woo Kim 
38d8408326SSeung-Woo Kim #include <drm/exynos_drm.h>
39d8408326SSeung-Woo Kim 
40d8408326SSeung-Woo Kim #include "exynos_drm_drv.h"
41663d8766SRahul Sharma #include "exynos_drm_crtc.h"
420488f50eSMarek Szyprowski #include "exynos_drm_fb.h"
437ee14cdcSGustavo Padovan #include "exynos_drm_plane.h"
4422b21ae6SJoonyoung Shim 
45f041b257SSean Paul #define MIXER_WIN_NR		3
46fbbb1e1aSMarek Szyprowski #define VP_DEFAULT_WIN		2
47d8408326SSeung-Woo Kim 
482a6e4cd5STobias Jakobi /*
492a6e4cd5STobias Jakobi  * Mixer color space conversion coefficient triplet.
502a6e4cd5STobias Jakobi  * Used for CSC from RGB to YCbCr.
512a6e4cd5STobias Jakobi  * Each coefficient is a 10-bit fixed point number with
522a6e4cd5STobias Jakobi  * sign and no integer part, i.e.
532a6e4cd5STobias Jakobi  * [0:8] = fractional part (representing a value y = x / 2^9)
542a6e4cd5STobias Jakobi  * [9] = sign
552a6e4cd5STobias Jakobi  * Negative values are encoded with two's complement.
562a6e4cd5STobias Jakobi  */
572a6e4cd5STobias Jakobi #define MXR_CSC_C(x) ((int)((x) * 512.0) & 0x3ff)
582a6e4cd5STobias Jakobi #define MXR_CSC_CT(a0, a1, a2) \
592a6e4cd5STobias Jakobi   ((MXR_CSC_C(a0) << 20) | (MXR_CSC_C(a1) << 10) | (MXR_CSC_C(a2) << 0))
602a6e4cd5STobias Jakobi 
612a6e4cd5STobias Jakobi /* YCbCr value, used for mixer background color configuration. */
622a6e4cd5STobias Jakobi #define MXR_YCBCR_VAL(y, cb, cr) (((y) << 16) | ((cb) << 8) | ((cr) << 0))
632a6e4cd5STobias Jakobi 
647a57ca7cSTobias Jakobi /* The pixelformats that are natively supported by the mixer. */
657a57ca7cSTobias Jakobi #define MXR_FORMAT_RGB565	4
667a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB1555	5
677a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB4444	6
687a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB8888	7
697a57ca7cSTobias Jakobi 
701e123441SRahul Sharma enum mixer_version_id {
711e123441SRahul Sharma 	MXR_VER_0_0_0_16,
721e123441SRahul Sharma 	MXR_VER_16_0_33_0,
73def5e095SRahul Sharma 	MXR_VER_128_0_0_184,
741e123441SRahul Sharma };
751e123441SRahul Sharma 
76a44652e8SAndrzej Hajda enum mixer_flag_bits {
77a44652e8SAndrzej Hajda 	MXR_BIT_POWERED,
780df5e4acSAndrzej Hajda 	MXR_BIT_VSYNC,
79adeb6f44STobias Jakobi 	MXR_BIT_INTERLACE,
80adeb6f44STobias Jakobi 	MXR_BIT_VP_ENABLED,
81adeb6f44STobias Jakobi 	MXR_BIT_HAS_SCLK,
82a44652e8SAndrzej Hajda };
83a44652e8SAndrzej Hajda 
84fbbb1e1aSMarek Szyprowski static const uint32_t mixer_formats[] = {
85fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB4444,
8626a7af3eSTobias Jakobi 	DRM_FORMAT_ARGB4444,
87fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB1555,
8826a7af3eSTobias Jakobi 	DRM_FORMAT_ARGB1555,
89fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_RGB565,
90fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB8888,
91fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_ARGB8888,
92fbbb1e1aSMarek Szyprowski };
93fbbb1e1aSMarek Szyprowski 
94fbbb1e1aSMarek Szyprowski static const uint32_t vp_formats[] = {
95fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_NV12,
96fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_NV21,
97fbbb1e1aSMarek Szyprowski };
98fbbb1e1aSMarek Szyprowski 
9922b21ae6SJoonyoung Shim struct mixer_context {
1004551789fSSean Paul 	struct platform_device *pdev;
101cf8fc4f1SJoonyoung Shim 	struct device		*dev;
1021055b39fSInki Dae 	struct drm_device	*drm_dev;
10393bca243SGustavo Padovan 	struct exynos_drm_crtc	*crtc;
1047ee14cdcSGustavo Padovan 	struct exynos_drm_plane	planes[MIXER_WIN_NR];
105a44652e8SAndrzej Hajda 	unsigned long		flags;
10622b21ae6SJoonyoung Shim 
107524c59f1SAndrzej Hajda 	int			irq;
108524c59f1SAndrzej Hajda 	void __iomem		*mixer_regs;
109524c59f1SAndrzej Hajda 	void __iomem		*vp_regs;
110524c59f1SAndrzej Hajda 	spinlock_t		reg_slock;
111524c59f1SAndrzej Hajda 	struct clk		*mixer;
112524c59f1SAndrzej Hajda 	struct clk		*vp;
113524c59f1SAndrzej Hajda 	struct clk		*hdmi;
114524c59f1SAndrzej Hajda 	struct clk		*sclk_mixer;
115524c59f1SAndrzej Hajda 	struct clk		*sclk_hdmi;
116524c59f1SAndrzej Hajda 	struct clk		*mout_mixer;
1171e123441SRahul Sharma 	enum mixer_version_id	mxr_ver;
118acc8bf04SAndrzej Hajda 	int			scan_value;
1191e123441SRahul Sharma };
1201e123441SRahul Sharma 
1211e123441SRahul Sharma struct mixer_drv_data {
1221e123441SRahul Sharma 	enum mixer_version_id	version;
1231b8e5747SRahul Sharma 	bool					is_vp_enabled;
124ff830c96SMarek Szyprowski 	bool					has_sclk;
12522b21ae6SJoonyoung Shim };
12622b21ae6SJoonyoung Shim 
127fd2d2fc2SMarek Szyprowski static const struct exynos_drm_plane_config plane_configs[MIXER_WIN_NR] = {
128fd2d2fc2SMarek Szyprowski 	{
129fd2d2fc2SMarek Szyprowski 		.zpos = 0,
130fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_PRIMARY,
131fd2d2fc2SMarek Szyprowski 		.pixel_formats = mixer_formats,
132fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(mixer_formats),
133a2cb911eSMarek Szyprowski 		.capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
134482582c0SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_ZPOS |
1356ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_PIX_BLEND |
1366ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_WIN_BLEND,
137fd2d2fc2SMarek Szyprowski 	}, {
138fd2d2fc2SMarek Szyprowski 		.zpos = 1,
139fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_CURSOR,
140fd2d2fc2SMarek Szyprowski 		.pixel_formats = mixer_formats,
141fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(mixer_formats),
142a2cb911eSMarek Szyprowski 		.capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
143482582c0SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_ZPOS |
1446ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_PIX_BLEND |
1456ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_WIN_BLEND,
146fd2d2fc2SMarek Szyprowski 	}, {
147fd2d2fc2SMarek Szyprowski 		.zpos = 2,
148fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_OVERLAY,
149fd2d2fc2SMarek Szyprowski 		.pixel_formats = vp_formats,
150fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(vp_formats),
151a2cb911eSMarek Szyprowski 		.capabilities = EXYNOS_DRM_PLANE_CAP_SCALE |
152f40031c2STobias Jakobi 				EXYNOS_DRM_PLANE_CAP_ZPOS |
1536ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_TILE |
1546ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_WIN_BLEND,
155fd2d2fc2SMarek Szyprowski 	},
156fd2d2fc2SMarek Szyprowski };
157fd2d2fc2SMarek Szyprowski 
158d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = {
159d8408326SSeung-Woo Kim 	0,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
160d8408326SSeung-Woo Kim 	-1,	-1,	-1,	-1,	-1,	0,	0,	0,
161d8408326SSeung-Woo Kim 	0,	2,	4,	5,	6,	6,	6,	6,
162d8408326SSeung-Woo Kim 	6,	5,	5,	4,	3,	2,	1,	1,
163d8408326SSeung-Woo Kim 	0,	-6,	-12,	-16,	-18,	-20,	-21,	-20,
164d8408326SSeung-Woo Kim 	-20,	-18,	-16,	-13,	-10,	-8,	-5,	-2,
165d8408326SSeung-Woo Kim 	127,	126,	125,	121,	114,	107,	99,	89,
166d8408326SSeung-Woo Kim 	79,	68,	57,	46,	35,	25,	16,	8,
167d8408326SSeung-Woo Kim };
168d8408326SSeung-Woo Kim 
169d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = {
170d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
171d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
172d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
173d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
174d8408326SSeung-Woo Kim 	0,	5,	11,	19,	27,	37,	48,	59,
175d8408326SSeung-Woo Kim 	70,	81,	92,	102,	111,	118,	124,	126,
176d8408326SSeung-Woo Kim 	0,	0,	-1,	-1,	-2,	-3,	-4,	-5,
177d8408326SSeung-Woo Kim 	-6,	-7,	-8,	-8,	-8,	-8,	-6,	-3,
178d8408326SSeung-Woo Kim };
179d8408326SSeung-Woo Kim 
180d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = {
181d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
182d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
183d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
184d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
185d8408326SSeung-Woo Kim };
186d8408326SSeung-Woo Kim 
187524c59f1SAndrzej Hajda static inline u32 vp_reg_read(struct mixer_context *ctx, u32 reg_id)
188d8408326SSeung-Woo Kim {
189524c59f1SAndrzej Hajda 	return readl(ctx->vp_regs + reg_id);
190d8408326SSeung-Woo Kim }
191d8408326SSeung-Woo Kim 
192524c59f1SAndrzej Hajda static inline void vp_reg_write(struct mixer_context *ctx, u32 reg_id,
193d8408326SSeung-Woo Kim 				 u32 val)
194d8408326SSeung-Woo Kim {
195524c59f1SAndrzej Hajda 	writel(val, ctx->vp_regs + reg_id);
196d8408326SSeung-Woo Kim }
197d8408326SSeung-Woo Kim 
198524c59f1SAndrzej Hajda static inline void vp_reg_writemask(struct mixer_context *ctx, u32 reg_id,
199d8408326SSeung-Woo Kim 				 u32 val, u32 mask)
200d8408326SSeung-Woo Kim {
201524c59f1SAndrzej Hajda 	u32 old = vp_reg_read(ctx, reg_id);
202d8408326SSeung-Woo Kim 
203d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
204524c59f1SAndrzej Hajda 	writel(val, ctx->vp_regs + reg_id);
205d8408326SSeung-Woo Kim }
206d8408326SSeung-Woo Kim 
207524c59f1SAndrzej Hajda static inline u32 mixer_reg_read(struct mixer_context *ctx, u32 reg_id)
208d8408326SSeung-Woo Kim {
209524c59f1SAndrzej Hajda 	return readl(ctx->mixer_regs + reg_id);
210d8408326SSeung-Woo Kim }
211d8408326SSeung-Woo Kim 
212524c59f1SAndrzej Hajda static inline void mixer_reg_write(struct mixer_context *ctx, u32 reg_id,
213d8408326SSeung-Woo Kim 				 u32 val)
214d8408326SSeung-Woo Kim {
215524c59f1SAndrzej Hajda 	writel(val, ctx->mixer_regs + reg_id);
216d8408326SSeung-Woo Kim }
217d8408326SSeung-Woo Kim 
218524c59f1SAndrzej Hajda static inline void mixer_reg_writemask(struct mixer_context *ctx,
219d8408326SSeung-Woo Kim 				 u32 reg_id, u32 val, u32 mask)
220d8408326SSeung-Woo Kim {
221524c59f1SAndrzej Hajda 	u32 old = mixer_reg_read(ctx, reg_id);
222d8408326SSeung-Woo Kim 
223d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
224524c59f1SAndrzej Hajda 	writel(val, ctx->mixer_regs + reg_id);
225d8408326SSeung-Woo Kim }
226d8408326SSeung-Woo Kim 
227d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx)
228d8408326SSeung-Woo Kim {
229d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
230d8408326SSeung-Woo Kim do { \
231*6be90056SInki Dae 	DRM_DEV_DEBUG_KMS(ctx->dev, #reg_id " = %08x\n", \
232524c59f1SAndrzej Hajda 			 (u32)readl(ctx->mixer_regs + reg_id)); \
233d8408326SSeung-Woo Kim } while (0)
234d8408326SSeung-Woo Kim 
235d8408326SSeung-Woo Kim 	DUMPREG(MXR_STATUS);
236d8408326SSeung-Woo Kim 	DUMPREG(MXR_CFG);
237d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_EN);
238d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_STATUS);
239d8408326SSeung-Woo Kim 
240d8408326SSeung-Woo Kim 	DUMPREG(MXR_LAYER_CFG);
241d8408326SSeung-Woo Kim 	DUMPREG(MXR_VIDEO_CFG);
242d8408326SSeung-Woo Kim 
243d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_CFG);
244d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_BASE);
245d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SPAN);
246d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_WH);
247d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SXY);
248d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_DXY);
249d8408326SSeung-Woo Kim 
250d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_CFG);
251d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_BASE);
252d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SPAN);
253d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_WH);
254d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SXY);
255d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_DXY);
256d8408326SSeung-Woo Kim #undef DUMPREG
257d8408326SSeung-Woo Kim }
258d8408326SSeung-Woo Kim 
259d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx)
260d8408326SSeung-Woo Kim {
261d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
262d8408326SSeung-Woo Kim do { \
263*6be90056SInki Dae 	DRM_DEV_DEBUG_KMS(ctx->dev, #reg_id " = %08x\n", \
264524c59f1SAndrzej Hajda 			 (u32) readl(ctx->vp_regs + reg_id)); \
265d8408326SSeung-Woo Kim } while (0)
266d8408326SSeung-Woo Kim 
267d8408326SSeung-Woo Kim 	DUMPREG(VP_ENABLE);
268d8408326SSeung-Woo Kim 	DUMPREG(VP_SRESET);
269d8408326SSeung-Woo Kim 	DUMPREG(VP_SHADOW_UPDATE);
270d8408326SSeung-Woo Kim 	DUMPREG(VP_FIELD_ID);
271d8408326SSeung-Woo Kim 	DUMPREG(VP_MODE);
272d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_Y);
273d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_C);
274d8408326SSeung-Woo Kim 	DUMPREG(VP_PER_RATE_CTRL);
275d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_Y_PTR);
276d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_Y_PTR);
277d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_C_PTR);
278d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_C_PTR);
279d8408326SSeung-Woo Kim 	DUMPREG(VP_ENDIAN_MODE);
280d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_H_POSITION);
281d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_V_POSITION);
282d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_WIDTH);
283d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_HEIGHT);
284d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_H_POSITION);
285d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_V_POSITION);
286d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_WIDTH);
287d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_HEIGHT);
288d8408326SSeung-Woo Kim 	DUMPREG(VP_H_RATIO);
289d8408326SSeung-Woo Kim 	DUMPREG(VP_V_RATIO);
290d8408326SSeung-Woo Kim 
291d8408326SSeung-Woo Kim #undef DUMPREG
292d8408326SSeung-Woo Kim }
293d8408326SSeung-Woo Kim 
294524c59f1SAndrzej Hajda static inline void vp_filter_set(struct mixer_context *ctx,
295d8408326SSeung-Woo Kim 		int reg_id, const u8 *data, unsigned int size)
296d8408326SSeung-Woo Kim {
297d8408326SSeung-Woo Kim 	/* assure 4-byte align */
298d8408326SSeung-Woo Kim 	BUG_ON(size & 3);
299d8408326SSeung-Woo Kim 	for (; size; size -= 4, reg_id += 4, data += 4) {
300d8408326SSeung-Woo Kim 		u32 val = (data[0] << 24) |  (data[1] << 16) |
301d8408326SSeung-Woo Kim 			(data[2] << 8) | data[3];
302524c59f1SAndrzej Hajda 		vp_reg_write(ctx, reg_id, val);
303d8408326SSeung-Woo Kim 	}
304d8408326SSeung-Woo Kim }
305d8408326SSeung-Woo Kim 
306524c59f1SAndrzej Hajda static void vp_default_filter(struct mixer_context *ctx)
307d8408326SSeung-Woo Kim {
308524c59f1SAndrzej Hajda 	vp_filter_set(ctx, VP_POLY8_Y0_LL,
309e25e1b66SSachin Kamat 		filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
310524c59f1SAndrzej Hajda 	vp_filter_set(ctx, VP_POLY4_Y0_LL,
311e25e1b66SSachin Kamat 		filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
312524c59f1SAndrzej Hajda 	vp_filter_set(ctx, VP_POLY4_C0_LL,
313e25e1b66SSachin Kamat 		filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
314d8408326SSeung-Woo Kim }
315d8408326SSeung-Woo Kim 
316f657a996SMarek Szyprowski static void mixer_cfg_gfx_blend(struct mixer_context *ctx, unsigned int win,
3176ac99a32SChristoph Manszewski 				unsigned int pixel_alpha, unsigned int alpha)
318f657a996SMarek Szyprowski {
3196ac99a32SChristoph Manszewski 	u32 win_alpha = alpha >> 8;
320f657a996SMarek Szyprowski 	u32 val;
321f657a996SMarek Szyprowski 
322f657a996SMarek Szyprowski 	val  = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
323482582c0SChristoph Manszewski 	switch (pixel_alpha) {
324482582c0SChristoph Manszewski 	case DRM_MODE_BLEND_PIXEL_NONE:
325482582c0SChristoph Manszewski 		break;
326482582c0SChristoph Manszewski 	case DRM_MODE_BLEND_COVERAGE:
327482582c0SChristoph Manszewski 		val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
328482582c0SChristoph Manszewski 		break;
329482582c0SChristoph Manszewski 	case DRM_MODE_BLEND_PREMULTI:
330482582c0SChristoph Manszewski 	default:
331f657a996SMarek Szyprowski 		val |= MXR_GRP_CFG_BLEND_PRE_MUL;
332f657a996SMarek Szyprowski 		val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
333482582c0SChristoph Manszewski 		break;
334f657a996SMarek Szyprowski 	}
3356ac99a32SChristoph Manszewski 
3366ac99a32SChristoph Manszewski 	if (alpha != DRM_BLEND_ALPHA_OPAQUE) {
3376ac99a32SChristoph Manszewski 		val |= MXR_GRP_CFG_WIN_BLEND_EN;
3386ac99a32SChristoph Manszewski 		val |= win_alpha;
3396ac99a32SChristoph Manszewski 	}
340524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_GRAPHIC_CFG(win),
341f657a996SMarek Szyprowski 			    val, MXR_GRP_CFG_MISC_MASK);
342f657a996SMarek Szyprowski }
343f657a996SMarek Szyprowski 
3446ac99a32SChristoph Manszewski static void mixer_cfg_vp_blend(struct mixer_context *ctx, unsigned int alpha)
345f657a996SMarek Szyprowski {
3466ac99a32SChristoph Manszewski 	u32 win_alpha = alpha >> 8;
3476ac99a32SChristoph Manszewski 	u32 val = 0;
348f657a996SMarek Szyprowski 
3496ac99a32SChristoph Manszewski 	if (alpha != DRM_BLEND_ALPHA_OPAQUE) {
3506ac99a32SChristoph Manszewski 		val |= MXR_VID_CFG_BLEND_EN;
3516ac99a32SChristoph Manszewski 		val |= win_alpha;
3526ac99a32SChristoph Manszewski 	}
353524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_VIDEO_CFG, val);
354f657a996SMarek Szyprowski }
355f657a996SMarek Szyprowski 
3566a3b45adSAndrzej Hajda static bool mixer_is_synced(struct mixer_context *ctx)
357d8408326SSeung-Woo Kim {
3586a3b45adSAndrzej Hajda 	u32 base, shadow;
359d8408326SSeung-Woo Kim 
3606a3b45adSAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
3616a3b45adSAndrzej Hajda 	    ctx->mxr_ver == MXR_VER_128_0_0_184)
3626a3b45adSAndrzej Hajda 		return !(mixer_reg_read(ctx, MXR_CFG) &
3636a3b45adSAndrzej Hajda 			 MXR_CFG_LAYER_UPDATE_COUNT_MASK);
3646a3b45adSAndrzej Hajda 
3656a3b45adSAndrzej Hajda 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags) &&
3666a3b45adSAndrzej Hajda 	    vp_reg_read(ctx, VP_SHADOW_UPDATE))
3676a3b45adSAndrzej Hajda 		return false;
3686a3b45adSAndrzej Hajda 
3696a3b45adSAndrzej Hajda 	base = mixer_reg_read(ctx, MXR_CFG);
3706a3b45adSAndrzej Hajda 	shadow = mixer_reg_read(ctx, MXR_CFG_S);
3716a3b45adSAndrzej Hajda 	if (base != shadow)
3726a3b45adSAndrzej Hajda 		return false;
3736a3b45adSAndrzej Hajda 
3746a3b45adSAndrzej Hajda 	base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(0));
3756a3b45adSAndrzej Hajda 	shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(0));
3766a3b45adSAndrzej Hajda 	if (base != shadow)
3776a3b45adSAndrzej Hajda 		return false;
3786a3b45adSAndrzej Hajda 
3796a3b45adSAndrzej Hajda 	base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(1));
3806a3b45adSAndrzej Hajda 	shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(1));
3816a3b45adSAndrzej Hajda 	if (base != shadow)
3826a3b45adSAndrzej Hajda 		return false;
3836a3b45adSAndrzej Hajda 
3846a3b45adSAndrzej Hajda 	return true;
3856a3b45adSAndrzej Hajda }
3866a3b45adSAndrzej Hajda 
3876a3b45adSAndrzej Hajda static int mixer_wait_for_sync(struct mixer_context *ctx)
3886a3b45adSAndrzej Hajda {
3896a3b45adSAndrzej Hajda 	ktime_t timeout = ktime_add_us(ktime_get(), 100000);
3906a3b45adSAndrzej Hajda 
3916a3b45adSAndrzej Hajda 	while (!mixer_is_synced(ctx)) {
3926a3b45adSAndrzej Hajda 		usleep_range(1000, 2000);
3936a3b45adSAndrzej Hajda 		if (ktime_compare(ktime_get(), timeout) > 0)
3946a3b45adSAndrzej Hajda 			return -ETIMEDOUT;
3956a3b45adSAndrzej Hajda 	}
3966a3b45adSAndrzej Hajda 	return 0;
3976a3b45adSAndrzej Hajda }
3986a3b45adSAndrzej Hajda 
3996a3b45adSAndrzej Hajda static void mixer_disable_sync(struct mixer_context *ctx)
4006a3b45adSAndrzej Hajda {
4016a3b45adSAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, 0, MXR_STATUS_SYNC_ENABLE);
4026a3b45adSAndrzej Hajda }
4036a3b45adSAndrzej Hajda 
4046a3b45adSAndrzej Hajda static void mixer_enable_sync(struct mixer_context *ctx)
4056a3b45adSAndrzej Hajda {
4066a3b45adSAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
4076a3b45adSAndrzej Hajda 	    ctx->mxr_ver == MXR_VER_128_0_0_184)
4086a3b45adSAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
4096a3b45adSAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_SYNC_ENABLE);
410adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
4116a3b45adSAndrzej Hajda 		vp_reg_write(ctx, VP_SHADOW_UPDATE, VP_SHADOW_UPDATE_ENABLE);
412d8408326SSeung-Woo Kim }
413d8408326SSeung-Woo Kim 
4143fc40ca9SAndrzej Hajda static void mixer_cfg_scan(struct mixer_context *ctx, int width, int height)
415d8408326SSeung-Woo Kim {
416d8408326SSeung-Woo Kim 	u32 val;
417d8408326SSeung-Woo Kim 
418d8408326SSeung-Woo Kim 	/* choosing between interlace and progressive mode */
419adeb6f44STobias Jakobi 	val = test_bit(MXR_BIT_INTERLACE, &ctx->flags) ?
420adeb6f44STobias Jakobi 		MXR_CFG_SCAN_INTERLACE : MXR_CFG_SCAN_PROGRESSIVE;
421d8408326SSeung-Woo Kim 
422acc8bf04SAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_128_0_0_184)
423524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_RESOLUTION,
4243fc40ca9SAndrzej Hajda 			MXR_MXR_RES_HEIGHT(height) | MXR_MXR_RES_WIDTH(width));
425d8408326SSeung-Woo Kim 	else
426acc8bf04SAndrzej Hajda 		val |= ctx->scan_value;
427d8408326SSeung-Woo Kim 
428524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_SCAN_MASK);
429d8408326SSeung-Woo Kim }
430d8408326SSeung-Woo Kim 
43113e810f1SChristoph Manszewski static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, struct drm_display_mode *mode)
432d8408326SSeung-Woo Kim {
43313e810f1SChristoph Manszewski 	enum hdmi_quantization_range range = drm_default_rgb_quant_range(mode);
434d8408326SSeung-Woo Kim 	u32 val;
435d8408326SSeung-Woo Kim 
43613e810f1SChristoph Manszewski 	if (mode->vdisplay < 720) {
43713e810f1SChristoph Manszewski 		val = MXR_CFG_RGB601;
438e9e5ba93SChristoph Manszewski 	} else {
43913e810f1SChristoph Manszewski 		val = MXR_CFG_RGB709;
44013e810f1SChristoph Manszewski 
4412a6e4cd5STobias Jakobi 		/* Configure the BT.709 CSC matrix for full range RGB. */
442524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_CM_COEFF_Y,
4432a6e4cd5STobias Jakobi 			MXR_CSC_CT( 0.184,  0.614,  0.063) |
4442a6e4cd5STobias Jakobi 			MXR_CM_COEFF_RGB_FULL);
445524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_CM_COEFF_CB,
4462a6e4cd5STobias Jakobi 			MXR_CSC_CT(-0.102, -0.338,  0.440));
447524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_CM_COEFF_CR,
4482a6e4cd5STobias Jakobi 			MXR_CSC_CT( 0.440, -0.399, -0.040));
449d8408326SSeung-Woo Kim 	}
450d8408326SSeung-Woo Kim 
45113e810f1SChristoph Manszewski 	if (range == HDMI_QUANTIZATION_RANGE_FULL)
45213e810f1SChristoph Manszewski 		val |= MXR_CFG_QUANT_RANGE_FULL;
45313e810f1SChristoph Manszewski 	else
45413e810f1SChristoph Manszewski 		val |= MXR_CFG_QUANT_RANGE_LIMITED;
45513e810f1SChristoph Manszewski 
456524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
457d8408326SSeung-Woo Kim }
458d8408326SSeung-Woo Kim 
4595b1d5bc6STobias Jakobi static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win,
460a2cb911eSMarek Szyprowski 			    unsigned int priority, bool enable)
461d8408326SSeung-Woo Kim {
462d8408326SSeung-Woo Kim 	u32 val = enable ? ~0 : 0;
463d8408326SSeung-Woo Kim 
464d8408326SSeung-Woo Kim 	switch (win) {
465d8408326SSeung-Woo Kim 	case 0:
466524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
467524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_LAYER_CFG,
468a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP0_VAL(priority),
469a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP0_MASK);
470d8408326SSeung-Woo Kim 		break;
471d8408326SSeung-Woo Kim 	case 1:
472524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
473524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_LAYER_CFG,
474a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP1_VAL(priority),
475a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP1_MASK);
476adeb6f44STobias Jakobi 
477d8408326SSeung-Woo Kim 		break;
4785e68fef2SMarek Szyprowski 	case VP_DEFAULT_WIN:
479adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
480524c59f1SAndrzej Hajda 			vp_reg_writemask(ctx, VP_ENABLE, val, VP_ENABLE_ON);
481524c59f1SAndrzej Hajda 			mixer_reg_writemask(ctx, MXR_CFG, val,
4821b8e5747SRahul Sharma 				MXR_CFG_VP_ENABLE);
483524c59f1SAndrzej Hajda 			mixer_reg_writemask(ctx, MXR_LAYER_CFG,
484a2cb911eSMarek Szyprowski 					    MXR_LAYER_CFG_VP_VAL(priority),
485a2cb911eSMarek Szyprowski 					    MXR_LAYER_CFG_VP_MASK);
4861b8e5747SRahul Sharma 		}
487d8408326SSeung-Woo Kim 		break;
488d8408326SSeung-Woo Kim 	}
489d8408326SSeung-Woo Kim }
490d8408326SSeung-Woo Kim 
491d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx)
492d8408326SSeung-Woo Kim {
493524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
494d8408326SSeung-Woo Kim }
495d8408326SSeung-Woo Kim 
496381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx)
497381be025SRahul Sharma {
498381be025SRahul Sharma 	int timeout = 20;
499381be025SRahul Sharma 
500524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, 0, MXR_STATUS_REG_RUN);
501381be025SRahul Sharma 
502524c59f1SAndrzej Hajda 	while (!(mixer_reg_read(ctx, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
503381be025SRahul Sharma 			--timeout)
504381be025SRahul Sharma 		usleep_range(10000, 12000);
505381be025SRahul Sharma }
506381be025SRahul Sharma 
507521d98a3SAndrzej Hajda static void mixer_commit(struct mixer_context *ctx)
508521d98a3SAndrzej Hajda {
509521d98a3SAndrzej Hajda 	struct drm_display_mode *mode = &ctx->crtc->base.state->adjusted_mode;
510521d98a3SAndrzej Hajda 
5113fc40ca9SAndrzej Hajda 	mixer_cfg_scan(ctx, mode->hdisplay, mode->vdisplay);
51213e810f1SChristoph Manszewski 	mixer_cfg_rgb_fmt(ctx, mode);
513521d98a3SAndrzej Hajda 	mixer_run(ctx);
514521d98a3SAndrzej Hajda }
515521d98a3SAndrzej Hajda 
5162eeb2e5eSGustavo Padovan static void vp_video_buffer(struct mixer_context *ctx,
5172eeb2e5eSGustavo Padovan 			    struct exynos_drm_plane *plane)
518d8408326SSeung-Woo Kim {
5190114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
5200114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
5210114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
522e47726a1SMarek Szyprowski 	unsigned int priority = state->base.normalized_zpos + 1;
523d8408326SSeung-Woo Kim 	unsigned long flags;
524d8408326SSeung-Woo Kim 	dma_addr_t luma_addr[2], chroma_addr[2];
5250f752694STobias Jakobi 	bool is_tiled, is_nv21;
526d8408326SSeung-Woo Kim 	u32 val;
527d8408326SSeung-Woo Kim 
5280f752694STobias Jakobi 	is_nv21 = (fb->format->format == DRM_FORMAT_NV21);
5290f752694STobias Jakobi 	is_tiled = (fb->modifier == DRM_FORMAT_MOD_SAMSUNG_64_32_TILE);
530f40031c2STobias Jakobi 
5310488f50eSMarek Szyprowski 	luma_addr[0] = exynos_drm_fb_dma_addr(fb, 0);
5320488f50eSMarek Szyprowski 	chroma_addr[0] = exynos_drm_fb_dma_addr(fb, 1);
533d8408326SSeung-Woo Kim 
53471469944SAndrzej Hajda 	if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
5350f752694STobias Jakobi 		if (is_tiled) {
536d8408326SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + 0x40;
537d8408326SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + 0x40;
538d8408326SSeung-Woo Kim 		} else {
5392eeb2e5eSGustavo Padovan 			luma_addr[1] = luma_addr[0] + fb->pitches[0];
5400ccc1c8fSTobias Jakobi 			chroma_addr[1] = chroma_addr[0] + fb->pitches[1];
541d8408326SSeung-Woo Kim 		}
542d8408326SSeung-Woo Kim 	} else {
543d8408326SSeung-Woo Kim 		luma_addr[1] = 0;
544d8408326SSeung-Woo Kim 		chroma_addr[1] = 0;
545d8408326SSeung-Woo Kim 	}
546d8408326SSeung-Woo Kim 
547524c59f1SAndrzej Hajda 	spin_lock_irqsave(&ctx->reg_slock, flags);
548d8408326SSeung-Woo Kim 
549d8408326SSeung-Woo Kim 	/* interlace or progressive scan mode */
550adeb6f44STobias Jakobi 	val = (test_bit(MXR_BIT_INTERLACE, &ctx->flags) ? ~0 : 0);
551524c59f1SAndrzej Hajda 	vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_LINE_SKIP);
552d8408326SSeung-Woo Kim 
553d8408326SSeung-Woo Kim 	/* setup format */
5540f752694STobias Jakobi 	val = (is_nv21 ? VP_MODE_NV21 : VP_MODE_NV12);
5550f752694STobias Jakobi 	val |= (is_tiled ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
556524c59f1SAndrzej Hajda 	vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_FMT_MASK);
557d8408326SSeung-Woo Kim 
558d8408326SSeung-Woo Kim 	/* setting size of input image */
559524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) |
5602eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height));
561dc500cfbSTobias Jakobi 	/* chroma plane for NV12/NV21 is half the height of the luma plane */
5620ccc1c8fSTobias Jakobi 	vp_reg_write(ctx, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[1]) |
5632eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height / 2));
564d8408326SSeung-Woo Kim 
565524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_SRC_WIDTH, state->src.w);
566524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_SRC_H_POSITION,
5670114f404SMarek Szyprowski 			VP_SRC_H_POSITION_VAL(state->src.x));
568524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_DST_WIDTH, state->crtc.w);
569524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_DST_H_POSITION, state->crtc.x);
5700ccc1c8fSTobias Jakobi 
571adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
5720ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_HEIGHT, state->src.h / 2);
5730ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_V_POSITION, state->src.y / 2);
574524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_HEIGHT, state->crtc.h / 2);
575524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_V_POSITION, state->crtc.y / 2);
576d8408326SSeung-Woo Kim 	} else {
5770ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_HEIGHT, state->src.h);
5780ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_V_POSITION, state->src.y);
579524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_HEIGHT, state->crtc.h);
580524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_V_POSITION, state->crtc.y);
581d8408326SSeung-Woo Kim 	}
582d8408326SSeung-Woo Kim 
583524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_H_RATIO, state->h_ratio);
584524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_V_RATIO, state->v_ratio);
585d8408326SSeung-Woo Kim 
586524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
587d8408326SSeung-Woo Kim 
588d8408326SSeung-Woo Kim 	/* set buffer address to vp */
589524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_TOP_Y_PTR, luma_addr[0]);
590524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_BOT_Y_PTR, luma_addr[1]);
591524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_TOP_C_PTR, chroma_addr[0]);
592524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_BOT_C_PTR, chroma_addr[1]);
593d8408326SSeung-Woo Kim 
594e47726a1SMarek Szyprowski 	mixer_cfg_layer(ctx, plane->index, priority, true);
5956ac99a32SChristoph Manszewski 	mixer_cfg_vp_blend(ctx, state->base.alpha);
596d8408326SSeung-Woo Kim 
597524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&ctx->reg_slock, flags);
598d8408326SSeung-Woo Kim 
599c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
600d8408326SSeung-Woo Kim 	vp_regs_dump(ctx);
601d8408326SSeung-Woo Kim }
602d8408326SSeung-Woo Kim 
6032eeb2e5eSGustavo Padovan static void mixer_graph_buffer(struct mixer_context *ctx,
6042eeb2e5eSGustavo Padovan 			       struct exynos_drm_plane *plane)
605d8408326SSeung-Woo Kim {
6060114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
6070114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
6080114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
609e47726a1SMarek Szyprowski 	unsigned int priority = state->base.normalized_zpos + 1;
610d8408326SSeung-Woo Kim 	unsigned long flags;
61140bdfb0aSMarek Szyprowski 	unsigned int win = plane->index;
6122611015cSTobias Jakobi 	unsigned int x_ratio = 0, y_ratio = 0;
6135dff6905STobias Jakobi 	unsigned int dst_x_offset, dst_y_offset;
614482582c0SChristoph Manszewski 	unsigned int pixel_alpha;
615d8408326SSeung-Woo Kim 	dma_addr_t dma_addr;
616d8408326SSeung-Woo Kim 	unsigned int fmt;
617d8408326SSeung-Woo Kim 	u32 val;
618d8408326SSeung-Woo Kim 
619482582c0SChristoph Manszewski 	if (fb->format->has_alpha)
620482582c0SChristoph Manszewski 		pixel_alpha = state->base.pixel_blend_mode;
621482582c0SChristoph Manszewski 	else
622482582c0SChristoph Manszewski 		pixel_alpha = DRM_MODE_BLEND_PIXEL_NONE;
623482582c0SChristoph Manszewski 
624438b74a5SVille Syrjälä 	switch (fb->format->format) {
6257a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB4444:
62626a7af3eSTobias Jakobi 	case DRM_FORMAT_ARGB4444:
6277a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB4444;
6287a57ca7cSTobias Jakobi 		break;
629d8408326SSeung-Woo Kim 
6307a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB1555:
63126a7af3eSTobias Jakobi 	case DRM_FORMAT_ARGB1555:
6327a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB1555;
633d8408326SSeung-Woo Kim 		break;
6347a57ca7cSTobias Jakobi 
6357a57ca7cSTobias Jakobi 	case DRM_FORMAT_RGB565:
6367a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_RGB565;
637d8408326SSeung-Woo Kim 		break;
6387a57ca7cSTobias Jakobi 
6397a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB8888:
6407a57ca7cSTobias Jakobi 	case DRM_FORMAT_ARGB8888:
6411e60d62fSTobias Jakobi 	default:
6427a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB8888;
6437a57ca7cSTobias Jakobi 		break;
644d8408326SSeung-Woo Kim 	}
645d8408326SSeung-Woo Kim 
646e463b069SMarek Szyprowski 	/* ratio is already checked by common plane code */
647e463b069SMarek Szyprowski 	x_ratio = state->h_ratio == (1 << 15);
648e463b069SMarek Szyprowski 	y_ratio = state->v_ratio == (1 << 15);
649d8408326SSeung-Woo Kim 
6500114f404SMarek Szyprowski 	dst_x_offset = state->crtc.x;
6510114f404SMarek Szyprowski 	dst_y_offset = state->crtc.y;
652d8408326SSeung-Woo Kim 
6535dff6905STobias Jakobi 	/* translate dma address base s.t. the source image offset is zero */
6540488f50eSMarek Szyprowski 	dma_addr = exynos_drm_fb_dma_addr(fb, 0)
655272725c7SVille Syrjälä 		+ (state->src.x * fb->format->cpp[0])
6560114f404SMarek Szyprowski 		+ (state->src.y * fb->pitches[0]);
657d8408326SSeung-Woo Kim 
658524c59f1SAndrzej Hajda 	spin_lock_irqsave(&ctx->reg_slock, flags);
659d8408326SSeung-Woo Kim 
660d8408326SSeung-Woo Kim 	/* setup format */
661524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_GRAPHIC_CFG(win),
662d8408326SSeung-Woo Kim 		MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
663d8408326SSeung-Woo Kim 
664d8408326SSeung-Woo Kim 	/* setup geometry */
665524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_SPAN(win),
666272725c7SVille Syrjälä 			fb->pitches[0] / fb->format->cpp[0]);
667d8408326SSeung-Woo Kim 
6680114f404SMarek Szyprowski 	val  = MXR_GRP_WH_WIDTH(state->src.w);
6690114f404SMarek Szyprowski 	val |= MXR_GRP_WH_HEIGHT(state->src.h);
670d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_H_SCALE(x_ratio);
671d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_V_SCALE(y_ratio);
672524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_WH(win), val);
673d8408326SSeung-Woo Kim 
674d8408326SSeung-Woo Kim 	/* setup offsets in display image */
675d8408326SSeung-Woo Kim 	val  = MXR_GRP_DXY_DX(dst_x_offset);
676d8408326SSeung-Woo Kim 	val |= MXR_GRP_DXY_DY(dst_y_offset);
677524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_DXY(win), val);
678d8408326SSeung-Woo Kim 
679d8408326SSeung-Woo Kim 	/* set buffer address to mixer */
680524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_BASE(win), dma_addr);
681d8408326SSeung-Woo Kim 
682e47726a1SMarek Szyprowski 	mixer_cfg_layer(ctx, win, priority, true);
6836ac99a32SChristoph Manszewski 	mixer_cfg_gfx_blend(ctx, win, pixel_alpha, state->base.alpha);
684aaf8b49eSRahul Sharma 
685524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&ctx->reg_slock, flags);
686c0734fbaSTobias Jakobi 
687c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
688d8408326SSeung-Woo Kim }
689d8408326SSeung-Woo Kim 
690d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx)
691d8408326SSeung-Woo Kim {
692a696394cSTobias Jakobi 	unsigned int tries = 100;
693d8408326SSeung-Woo Kim 
694524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_SRESET, VP_SRESET_PROCESSING);
6958646dcb8SDan Carpenter 	while (--tries) {
696d8408326SSeung-Woo Kim 		/* waiting until VP_SRESET_PROCESSING is 0 */
697524c59f1SAndrzej Hajda 		if (~vp_reg_read(ctx, VP_SRESET) & VP_SRESET_PROCESSING)
698d8408326SSeung-Woo Kim 			break;
69902b3de43STomasz Stanislawski 		mdelay(10);
700d8408326SSeung-Woo Kim 	}
701d8408326SSeung-Woo Kim 	WARN(tries == 0, "failed to reset Video Processor\n");
702d8408326SSeung-Woo Kim }
703d8408326SSeung-Woo Kim 
704cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx)
705cf8fc4f1SJoonyoung Shim {
706cf8fc4f1SJoonyoung Shim 	unsigned long flags;
707cf8fc4f1SJoonyoung Shim 
708524c59f1SAndrzej Hajda 	spin_lock_irqsave(&ctx->reg_slock, flags);
709cf8fc4f1SJoonyoung Shim 
710524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
711cf8fc4f1SJoonyoung Shim 
712cf8fc4f1SJoonyoung Shim 	/* set output in RGB888 mode */
713524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
714cf8fc4f1SJoonyoung Shim 
715cf8fc4f1SJoonyoung Shim 	/* 16 beat burst in DMA */
716524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, MXR_STATUS_16_BURST,
717cf8fc4f1SJoonyoung Shim 		MXR_STATUS_BURST_MASK);
718cf8fc4f1SJoonyoung Shim 
719a2cb911eSMarek Szyprowski 	/* reset default layer priority */
720524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_LAYER_CFG, 0);
721cf8fc4f1SJoonyoung Shim 
7222a6e4cd5STobias Jakobi 	/* set all background colors to RGB (0,0,0) */
723524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_BG_COLOR0, MXR_YCBCR_VAL(0, 128, 128));
724524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_BG_COLOR1, MXR_YCBCR_VAL(0, 128, 128));
725524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_BG_COLOR2, MXR_YCBCR_VAL(0, 128, 128));
726cf8fc4f1SJoonyoung Shim 
727adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
728cf8fc4f1SJoonyoung Shim 		/* configuration of Video Processor Registers */
729cf8fc4f1SJoonyoung Shim 		vp_win_reset(ctx);
730524c59f1SAndrzej Hajda 		vp_default_filter(ctx);
7311b8e5747SRahul Sharma 	}
732cf8fc4f1SJoonyoung Shim 
733cf8fc4f1SJoonyoung Shim 	/* disable all layers */
734524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
735524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
736adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
737524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
738cf8fc4f1SJoonyoung Shim 
7395dff6905STobias Jakobi 	/* set all source image offsets to zero */
740524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_SXY(0), 0);
741524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_SXY(1), 0);
7425dff6905STobias Jakobi 
743524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&ctx->reg_slock, flags);
744cf8fc4f1SJoonyoung Shim }
745cf8fc4f1SJoonyoung Shim 
7464551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg)
7474551789fSSean Paul {
7484551789fSSean Paul 	struct mixer_context *ctx = arg;
7496a3b45adSAndrzej Hajda 	u32 val;
7504551789fSSean Paul 
751524c59f1SAndrzej Hajda 	spin_lock(&ctx->reg_slock);
7524551789fSSean Paul 
7534551789fSSean Paul 	/* read interrupt status for handling and clearing flags for VSYNC */
754524c59f1SAndrzej Hajda 	val = mixer_reg_read(ctx, MXR_INT_STATUS);
7554551789fSSean Paul 
7564551789fSSean Paul 	/* handling VSYNC */
7574551789fSSean Paul 	if (val & MXR_INT_STATUS_VSYNC) {
75881a464dfSAndrzej Hajda 		/* vsync interrupt use different bit for read and clear */
75981a464dfSAndrzej Hajda 		val |= MXR_INT_CLEAR_VSYNC;
76081a464dfSAndrzej Hajda 		val &= ~MXR_INT_STATUS_VSYNC;
76181a464dfSAndrzej Hajda 
7624551789fSSean Paul 		/* interlace scan need to check shadow register */
7636a3b45adSAndrzej Hajda 		if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)
7646a3b45adSAndrzej Hajda 		    && !mixer_is_synced(ctx))
7652eced8e9SAndrzej Hajda 			goto out;
7662eced8e9SAndrzej Hajda 
767eafd540aSGustavo Padovan 		drm_crtc_handle_vblank(&ctx->crtc->base);
7684551789fSSean Paul 	}
7694551789fSSean Paul 
7704551789fSSean Paul out:
7714551789fSSean Paul 	/* clear interrupts */
772524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_INT_STATUS, val);
7734551789fSSean Paul 
774524c59f1SAndrzej Hajda 	spin_unlock(&ctx->reg_slock);
7754551789fSSean Paul 
7764551789fSSean Paul 	return IRQ_HANDLED;
7774551789fSSean Paul }
7784551789fSSean Paul 
7794551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx)
7804551789fSSean Paul {
7814551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
7824551789fSSean Paul 	struct resource *res;
7834551789fSSean Paul 	int ret;
7844551789fSSean Paul 
785524c59f1SAndrzej Hajda 	spin_lock_init(&mixer_ctx->reg_slock);
7864551789fSSean Paul 
787524c59f1SAndrzej Hajda 	mixer_ctx->mixer = devm_clk_get(dev, "mixer");
788524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->mixer)) {
7894551789fSSean Paul 		dev_err(dev, "failed to get clock 'mixer'\n");
7904551789fSSean Paul 		return -ENODEV;
7914551789fSSean Paul 	}
7924551789fSSean Paul 
793524c59f1SAndrzej Hajda 	mixer_ctx->hdmi = devm_clk_get(dev, "hdmi");
794524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->hdmi)) {
79504427ec5SMarek Szyprowski 		dev_err(dev, "failed to get clock 'hdmi'\n");
796524c59f1SAndrzej Hajda 		return PTR_ERR(mixer_ctx->hdmi);
79704427ec5SMarek Szyprowski 	}
79804427ec5SMarek Szyprowski 
799524c59f1SAndrzej Hajda 	mixer_ctx->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
800524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->sclk_hdmi)) {
8014551789fSSean Paul 		dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
8024551789fSSean Paul 		return -ENODEV;
8034551789fSSean Paul 	}
8044551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
8054551789fSSean Paul 	if (res == NULL) {
8064551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8074551789fSSean Paul 		return -ENXIO;
8084551789fSSean Paul 	}
8094551789fSSean Paul 
810524c59f1SAndrzej Hajda 	mixer_ctx->mixer_regs = devm_ioremap(dev, res->start,
8114551789fSSean Paul 							resource_size(res));
812524c59f1SAndrzej Hajda 	if (mixer_ctx->mixer_regs == NULL) {
8134551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8144551789fSSean Paul 		return -ENXIO;
8154551789fSSean Paul 	}
8164551789fSSean Paul 
8174551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0);
8184551789fSSean Paul 	if (res == NULL) {
8194551789fSSean Paul 		dev_err(dev, "get interrupt resource failed.\n");
8204551789fSSean Paul 		return -ENXIO;
8214551789fSSean Paul 	}
8224551789fSSean Paul 
8234551789fSSean Paul 	ret = devm_request_irq(dev, res->start, mixer_irq_handler,
8244551789fSSean Paul 						0, "drm_mixer", mixer_ctx);
8254551789fSSean Paul 	if (ret) {
8264551789fSSean Paul 		dev_err(dev, "request interrupt failed.\n");
8274551789fSSean Paul 		return ret;
8284551789fSSean Paul 	}
829524c59f1SAndrzej Hajda 	mixer_ctx->irq = res->start;
8304551789fSSean Paul 
8314551789fSSean Paul 	return 0;
8324551789fSSean Paul }
8334551789fSSean Paul 
8344551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx)
8354551789fSSean Paul {
8364551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
8374551789fSSean Paul 	struct resource *res;
8384551789fSSean Paul 
839524c59f1SAndrzej Hajda 	mixer_ctx->vp = devm_clk_get(dev, "vp");
840524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->vp)) {
8414551789fSSean Paul 		dev_err(dev, "failed to get clock 'vp'\n");
8424551789fSSean Paul 		return -ENODEV;
8434551789fSSean Paul 	}
844ff830c96SMarek Szyprowski 
845adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_HAS_SCLK, &mixer_ctx->flags)) {
846524c59f1SAndrzej Hajda 		mixer_ctx->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
847524c59f1SAndrzej Hajda 		if (IS_ERR(mixer_ctx->sclk_mixer)) {
8484551789fSSean Paul 			dev_err(dev, "failed to get clock 'sclk_mixer'\n");
8494551789fSSean Paul 			return -ENODEV;
8504551789fSSean Paul 		}
851524c59f1SAndrzej Hajda 		mixer_ctx->mout_mixer = devm_clk_get(dev, "mout_mixer");
852524c59f1SAndrzej Hajda 		if (IS_ERR(mixer_ctx->mout_mixer)) {
853ff830c96SMarek Szyprowski 			dev_err(dev, "failed to get clock 'mout_mixer'\n");
8544551789fSSean Paul 			return -ENODEV;
8554551789fSSean Paul 		}
8564551789fSSean Paul 
857524c59f1SAndrzej Hajda 		if (mixer_ctx->sclk_hdmi && mixer_ctx->mout_mixer)
858524c59f1SAndrzej Hajda 			clk_set_parent(mixer_ctx->mout_mixer,
859524c59f1SAndrzej Hajda 				       mixer_ctx->sclk_hdmi);
860ff830c96SMarek Szyprowski 	}
8614551789fSSean Paul 
8624551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
8634551789fSSean Paul 	if (res == NULL) {
8644551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8654551789fSSean Paul 		return -ENXIO;
8664551789fSSean Paul 	}
8674551789fSSean Paul 
868524c59f1SAndrzej Hajda 	mixer_ctx->vp_regs = devm_ioremap(dev, res->start,
8694551789fSSean Paul 							resource_size(res));
870524c59f1SAndrzej Hajda 	if (mixer_ctx->vp_regs == NULL) {
8714551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8724551789fSSean Paul 		return -ENXIO;
8734551789fSSean Paul 	}
8744551789fSSean Paul 
8754551789fSSean Paul 	return 0;
8764551789fSSean Paul }
8774551789fSSean Paul 
87893bca243SGustavo Padovan static int mixer_initialize(struct mixer_context *mixer_ctx,
879f37cd5e8SInki Dae 			struct drm_device *drm_dev)
8804551789fSSean Paul {
8814551789fSSean Paul 	int ret;
8824551789fSSean Paul 
883eb88e422SGustavo Padovan 	mixer_ctx->drm_dev = drm_dev;
8844551789fSSean Paul 
8854551789fSSean Paul 	/* acquire resources: regs, irqs, clocks */
8864551789fSSean Paul 	ret = mixer_resources_init(mixer_ctx);
8874551789fSSean Paul 	if (ret) {
8886f83d208SInki Dae 		DRM_DEV_ERROR(mixer_ctx->dev,
8896f83d208SInki Dae 			      "mixer_resources_init failed ret=%d\n", ret);
8904551789fSSean Paul 		return ret;
8914551789fSSean Paul 	}
8924551789fSSean Paul 
893adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &mixer_ctx->flags)) {
8944551789fSSean Paul 		/* acquire vp resources: regs, irqs, clocks */
8954551789fSSean Paul 		ret = vp_resources_init(mixer_ctx);
8964551789fSSean Paul 		if (ret) {
8976f83d208SInki Dae 			DRM_DEV_ERROR(mixer_ctx->dev,
8986f83d208SInki Dae 				      "vp_resources_init failed ret=%d\n", ret);
8994551789fSSean Paul 			return ret;
9004551789fSSean Paul 		}
9014551789fSSean Paul 	}
9024551789fSSean Paul 
90329cbf24aSAndrzej Hajda 	return exynos_drm_register_dma(drm_dev, mixer_ctx->dev);
9041055b39fSInki Dae }
9051055b39fSInki Dae 
90693bca243SGustavo Padovan static void mixer_ctx_remove(struct mixer_context *mixer_ctx)
907d8408326SSeung-Woo Kim {
90823755696SAndrzej Hajda 	exynos_drm_unregister_dma(mixer_ctx->drm_dev, mixer_ctx->dev);
909f041b257SSean Paul }
910f041b257SSean Paul 
91193bca243SGustavo Padovan static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)
912f041b257SSean Paul {
91393bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
914d8408326SSeung-Woo Kim 
9150df5e4acSAndrzej Hajda 	__set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9160df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
917f041b257SSean Paul 		return 0;
918d8408326SSeung-Woo Kim 
919d8408326SSeung-Woo Kim 	/* enable vsync interrupt */
920524c59f1SAndrzej Hajda 	mixer_reg_writemask(mixer_ctx, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
921524c59f1SAndrzej Hajda 	mixer_reg_writemask(mixer_ctx, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
922d8408326SSeung-Woo Kim 
923d8408326SSeung-Woo Kim 	return 0;
924d8408326SSeung-Woo Kim }
925d8408326SSeung-Woo Kim 
92693bca243SGustavo Padovan static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
927d8408326SSeung-Woo Kim {
92893bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
929d8408326SSeung-Woo Kim 
9300df5e4acSAndrzej Hajda 	__clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9310df5e4acSAndrzej Hajda 
9320df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
933947710c6SAndrzej Hajda 		return;
934947710c6SAndrzej Hajda 
935d8408326SSeung-Woo Kim 	/* disable vsync interrupt */
936524c59f1SAndrzej Hajda 	mixer_reg_writemask(mixer_ctx, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
937524c59f1SAndrzej Hajda 	mixer_reg_writemask(mixer_ctx, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
938d8408326SSeung-Woo Kim }
939d8408326SSeung-Woo Kim 
9403dbaab16SMarek Szyprowski static void mixer_atomic_begin(struct exynos_drm_crtc *crtc)
9413dbaab16SMarek Szyprowski {
9426a3b45adSAndrzej Hajda 	struct mixer_context *ctx = crtc->ctx;
9433dbaab16SMarek Szyprowski 
9446a3b45adSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
9453dbaab16SMarek Szyprowski 		return;
9463dbaab16SMarek Szyprowski 
9476a3b45adSAndrzej Hajda 	if (mixer_wait_for_sync(ctx))
9486a3b45adSAndrzej Hajda 		dev_err(ctx->dev, "timeout waiting for VSYNC\n");
9496a3b45adSAndrzej Hajda 	mixer_disable_sync(ctx);
9503dbaab16SMarek Szyprowski }
9513dbaab16SMarek Szyprowski 
9521e1d1393SGustavo Padovan static void mixer_update_plane(struct exynos_drm_crtc *crtc,
9531e1d1393SGustavo Padovan 			       struct exynos_drm_plane *plane)
954d8408326SSeung-Woo Kim {
95593bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
956d8408326SSeung-Woo Kim 
957*6be90056SInki Dae 	DRM_DEV_DEBUG_KMS(mixer_ctx->dev, "win: %d\n", plane->index);
958d8408326SSeung-Woo Kim 
959a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
960dda9012bSShirish S 		return;
961dda9012bSShirish S 
9625e68fef2SMarek Szyprowski 	if (plane->index == VP_DEFAULT_WIN)
9632eeb2e5eSGustavo Padovan 		vp_video_buffer(mixer_ctx, plane);
964d8408326SSeung-Woo Kim 	else
9652eeb2e5eSGustavo Padovan 		mixer_graph_buffer(mixer_ctx, plane);
966d8408326SSeung-Woo Kim }
967d8408326SSeung-Woo Kim 
9681e1d1393SGustavo Padovan static void mixer_disable_plane(struct exynos_drm_crtc *crtc,
9691e1d1393SGustavo Padovan 				struct exynos_drm_plane *plane)
970d8408326SSeung-Woo Kim {
97193bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
972d8408326SSeung-Woo Kim 	unsigned long flags;
973d8408326SSeung-Woo Kim 
974*6be90056SInki Dae 	DRM_DEV_DEBUG_KMS(mixer_ctx->dev, "win: %d\n", plane->index);
975d8408326SSeung-Woo Kim 
976a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
977db43fd16SPrathyush K 		return;
978db43fd16SPrathyush K 
979524c59f1SAndrzej Hajda 	spin_lock_irqsave(&mixer_ctx->reg_slock, flags);
980a2cb911eSMarek Szyprowski 	mixer_cfg_layer(mixer_ctx, plane->index, 0, false);
981524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&mixer_ctx->reg_slock, flags);
9823dbaab16SMarek Szyprowski }
9833dbaab16SMarek Szyprowski 
9843dbaab16SMarek Szyprowski static void mixer_atomic_flush(struct exynos_drm_crtc *crtc)
9853dbaab16SMarek Szyprowski {
9863dbaab16SMarek Szyprowski 	struct mixer_context *mixer_ctx = crtc->ctx;
9873dbaab16SMarek Szyprowski 
9883dbaab16SMarek Szyprowski 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
9893dbaab16SMarek Szyprowski 		return;
990d8408326SSeung-Woo Kim 
9916a3b45adSAndrzej Hajda 	mixer_enable_sync(mixer_ctx);
992a392276dSAndrzej Hajda 	exynos_crtc_handle_event(crtc);
993d8408326SSeung-Woo Kim }
994d8408326SSeung-Woo Kim 
9953cecda03SGustavo Padovan static void mixer_enable(struct exynos_drm_crtc *crtc)
996db43fd16SPrathyush K {
9973cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
998db43fd16SPrathyush K 
999a44652e8SAndrzej Hajda 	if (test_bit(MXR_BIT_POWERED, &ctx->flags))
1000db43fd16SPrathyush K 		return;
1001db43fd16SPrathyush K 
1002af65c804SSean Paul 	pm_runtime_get_sync(ctx->dev);
1003af65c804SSean Paul 
1004a121d179SAndrzej Hajda 	exynos_drm_pipe_clk_enable(crtc, true);
1005a121d179SAndrzej Hajda 
10066a3b45adSAndrzej Hajda 	mixer_disable_sync(ctx);
10073dbaab16SMarek Szyprowski 
1008524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
1009d74ed937SRahul Sharma 
10100df5e4acSAndrzej Hajda 	if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) {
1011524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_INT_STATUS, ~0,
1012524c59f1SAndrzej Hajda 					MXR_INT_CLEAR_VSYNC);
1013524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
10140df5e4acSAndrzej Hajda 	}
1015db43fd16SPrathyush K 	mixer_win_reset(ctx);
1016ccf034a9SGustavo Padovan 
101771469944SAndrzej Hajda 	mixer_commit(ctx);
101871469944SAndrzej Hajda 
10196a3b45adSAndrzej Hajda 	mixer_enable_sync(ctx);
10203dbaab16SMarek Szyprowski 
1021ccf034a9SGustavo Padovan 	set_bit(MXR_BIT_POWERED, &ctx->flags);
1022db43fd16SPrathyush K }
1023db43fd16SPrathyush K 
10243cecda03SGustavo Padovan static void mixer_disable(struct exynos_drm_crtc *crtc)
1025db43fd16SPrathyush K {
10263cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
1027c329f667SJoonyoung Shim 	int i;
1028db43fd16SPrathyush K 
1029a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
1030b4bfa3c7SRahul Sharma 		return;
1031db43fd16SPrathyush K 
1032381be025SRahul Sharma 	mixer_stop(ctx);
1033c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
1034c329f667SJoonyoung Shim 
1035c329f667SJoonyoung Shim 	for (i = 0; i < MIXER_WIN_NR; i++)
10361e1d1393SGustavo Padovan 		mixer_disable_plane(crtc, &ctx->planes[i]);
1037db43fd16SPrathyush K 
1038a121d179SAndrzej Hajda 	exynos_drm_pipe_clk_enable(crtc, false);
1039a121d179SAndrzej Hajda 
1040ccf034a9SGustavo Padovan 	pm_runtime_put(ctx->dev);
1041ccf034a9SGustavo Padovan 
1042a44652e8SAndrzej Hajda 	clear_bit(MXR_BIT_POWERED, &ctx->flags);
1043db43fd16SPrathyush K }
1044db43fd16SPrathyush K 
10456ace38a5SAndrzej Hajda static int mixer_mode_valid(struct exynos_drm_crtc *crtc,
10466ace38a5SAndrzej Hajda 		const struct drm_display_mode *mode)
1047f041b257SSean Paul {
10486ace38a5SAndrzej Hajda 	struct mixer_context *ctx = crtc->ctx;
10496ace38a5SAndrzej Hajda 	u32 w = mode->hdisplay, h = mode->vdisplay;
1050f041b257SSean Paul 
1051*6be90056SInki Dae 	DRM_DEV_DEBUG_KMS(ctx->dev, "xres=%d, yres=%d, refresh=%d, intl=%d\n",
1052*6be90056SInki Dae 			  w, h, mode->vrefresh,
1053*6be90056SInki Dae 			  !!(mode->flags & DRM_MODE_FLAG_INTERLACE));
1054f041b257SSean Paul 
10556ace38a5SAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_128_0_0_184)
10566ace38a5SAndrzej Hajda 		return MODE_OK;
1057f041b257SSean Paul 
1058f041b257SSean Paul 	if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
1059f041b257SSean Paul 	    (w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
1060f041b257SSean Paul 	    (w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
10616ace38a5SAndrzej Hajda 		return MODE_OK;
1062f041b257SSean Paul 
1063ae58c03eSDaniel Drake 	if ((w == 1024 && h == 768) ||
1064ae58c03eSDaniel Drake 	    (w == 1366 && h == 768) ||
1065ae58c03eSDaniel Drake 	    (w == 1280 && h == 1024))
10660900673eSAndrzej Hajda 		return MODE_OK;
10670900673eSAndrzej Hajda 
10686ace38a5SAndrzej Hajda 	return MODE_BAD;
1069f041b257SSean Paul }
1070f041b257SSean Paul 
1071acc8bf04SAndrzej Hajda static bool mixer_mode_fixup(struct exynos_drm_crtc *crtc,
1072acc8bf04SAndrzej Hajda 		   const struct drm_display_mode *mode,
1073acc8bf04SAndrzej Hajda 		   struct drm_display_mode *adjusted_mode)
1074acc8bf04SAndrzej Hajda {
1075acc8bf04SAndrzej Hajda 	struct mixer_context *ctx = crtc->ctx;
1076acc8bf04SAndrzej Hajda 	int width = mode->hdisplay, height = mode->vdisplay, i;
1077acc8bf04SAndrzej Hajda 
1078acc8bf04SAndrzej Hajda 	struct {
1079acc8bf04SAndrzej Hajda 		int hdisplay, vdisplay, htotal, vtotal, scan_val;
1080acc8bf04SAndrzej Hajda 	} static const modes[] = {
1081acc8bf04SAndrzej Hajda 		{ 720, 480, 858, 525, MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD },
1082acc8bf04SAndrzej Hajda 		{ 720, 576, 864, 625, MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD },
1083acc8bf04SAndrzej Hajda 		{ 1280, 720, 1650, 750, MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD },
1084acc8bf04SAndrzej Hajda 		{ 1920, 1080, 2200, 1125, MXR_CFG_SCAN_HD_1080 |
1085acc8bf04SAndrzej Hajda 						MXR_CFG_SCAN_HD }
1086acc8bf04SAndrzej Hajda 	};
1087acc8bf04SAndrzej Hajda 
1088acc8bf04SAndrzej Hajda 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1089acc8bf04SAndrzej Hajda 		__set_bit(MXR_BIT_INTERLACE, &ctx->flags);
1090acc8bf04SAndrzej Hajda 	else
1091acc8bf04SAndrzej Hajda 		__clear_bit(MXR_BIT_INTERLACE, &ctx->flags);
1092acc8bf04SAndrzej Hajda 
1093acc8bf04SAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_128_0_0_184)
1094acc8bf04SAndrzej Hajda 		return true;
1095acc8bf04SAndrzej Hajda 
1096acc8bf04SAndrzej Hajda 	for (i = 0; i < ARRAY_SIZE(modes); ++i)
1097acc8bf04SAndrzej Hajda 		if (width <= modes[i].hdisplay && height <= modes[i].vdisplay) {
1098acc8bf04SAndrzej Hajda 			ctx->scan_value = modes[i].scan_val;
1099acc8bf04SAndrzej Hajda 			if (width < modes[i].hdisplay ||
1100acc8bf04SAndrzej Hajda 			    height < modes[i].vdisplay) {
1101acc8bf04SAndrzej Hajda 				adjusted_mode->hdisplay = modes[i].hdisplay;
1102acc8bf04SAndrzej Hajda 				adjusted_mode->hsync_start = modes[i].hdisplay;
1103acc8bf04SAndrzej Hajda 				adjusted_mode->hsync_end = modes[i].htotal;
1104acc8bf04SAndrzej Hajda 				adjusted_mode->htotal = modes[i].htotal;
1105acc8bf04SAndrzej Hajda 				adjusted_mode->vdisplay = modes[i].vdisplay;
1106acc8bf04SAndrzej Hajda 				adjusted_mode->vsync_start = modes[i].vdisplay;
1107acc8bf04SAndrzej Hajda 				adjusted_mode->vsync_end = modes[i].vtotal;
1108acc8bf04SAndrzej Hajda 				adjusted_mode->vtotal = modes[i].vtotal;
1109acc8bf04SAndrzej Hajda 			}
1110acc8bf04SAndrzej Hajda 
1111acc8bf04SAndrzej Hajda 			return true;
1112acc8bf04SAndrzej Hajda 		}
1113acc8bf04SAndrzej Hajda 
1114acc8bf04SAndrzej Hajda 	return false;
1115acc8bf04SAndrzej Hajda }
1116acc8bf04SAndrzej Hajda 
1117f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops mixer_crtc_ops = {
11183cecda03SGustavo Padovan 	.enable			= mixer_enable,
11193cecda03SGustavo Padovan 	.disable		= mixer_disable,
1120d8408326SSeung-Woo Kim 	.enable_vblank		= mixer_enable_vblank,
1121d8408326SSeung-Woo Kim 	.disable_vblank		= mixer_disable_vblank,
11223dbaab16SMarek Szyprowski 	.atomic_begin		= mixer_atomic_begin,
11239cc7610aSGustavo Padovan 	.update_plane		= mixer_update_plane,
11249cc7610aSGustavo Padovan 	.disable_plane		= mixer_disable_plane,
11253dbaab16SMarek Szyprowski 	.atomic_flush		= mixer_atomic_flush,
11266ace38a5SAndrzej Hajda 	.mode_valid		= mixer_mode_valid,
1127acc8bf04SAndrzej Hajda 	.mode_fixup		= mixer_mode_fixup,
1128f041b257SSean Paul };
11290ea6822fSRahul Sharma 
11305e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos5420_mxr_drv_data = {
1131def5e095SRahul Sharma 	.version = MXR_VER_128_0_0_184,
1132def5e095SRahul Sharma 	.is_vp_enabled = 0,
1133def5e095SRahul Sharma };
1134def5e095SRahul Sharma 
11355e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos5250_mxr_drv_data = {
1136aaf8b49eSRahul Sharma 	.version = MXR_VER_16_0_33_0,
1137aaf8b49eSRahul Sharma 	.is_vp_enabled = 0,
1138aaf8b49eSRahul Sharma };
1139aaf8b49eSRahul Sharma 
11405e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos4212_mxr_drv_data = {
1141ff830c96SMarek Szyprowski 	.version = MXR_VER_0_0_0_16,
1142ff830c96SMarek Szyprowski 	.is_vp_enabled = 1,
1143ff830c96SMarek Szyprowski };
1144ff830c96SMarek Szyprowski 
11455e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos4210_mxr_drv_data = {
11461e123441SRahul Sharma 	.version = MXR_VER_0_0_0_16,
11471b8e5747SRahul Sharma 	.is_vp_enabled = 1,
1148ff830c96SMarek Szyprowski 	.has_sclk = 1,
11491e123441SRahul Sharma };
11501e123441SRahul Sharma 
11515e6cc1c5SArvind Yadav static const struct of_device_id mixer_match_types[] = {
1152aaf8b49eSRahul Sharma 	{
1153ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4210-mixer",
1154ff830c96SMarek Szyprowski 		.data	= &exynos4210_mxr_drv_data,
1155ff830c96SMarek Szyprowski 	}, {
1156ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4212-mixer",
1157ff830c96SMarek Szyprowski 		.data	= &exynos4212_mxr_drv_data,
1158ff830c96SMarek Szyprowski 	}, {
1159aaf8b49eSRahul Sharma 		.compatible = "samsung,exynos5-mixer",
1160cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1161cc57caf0SRahul Sharma 	}, {
1162cc57caf0SRahul Sharma 		.compatible = "samsung,exynos5250-mixer",
1163cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1164aaf8b49eSRahul Sharma 	}, {
1165def5e095SRahul Sharma 		.compatible = "samsung,exynos5420-mixer",
1166def5e095SRahul Sharma 		.data	= &exynos5420_mxr_drv_data,
1167def5e095SRahul Sharma 	}, {
11681e123441SRahul Sharma 		/* end node */
11691e123441SRahul Sharma 	}
11701e123441SRahul Sharma };
117139b58a39SSjoerd Simons MODULE_DEVICE_TABLE(of, mixer_match_types);
11721e123441SRahul Sharma 
1173f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data)
1174d8408326SSeung-Woo Kim {
11758103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
1176f37cd5e8SInki Dae 	struct drm_device *drm_dev = data;
11777ee14cdcSGustavo Padovan 	struct exynos_drm_plane *exynos_plane;
1178fd2d2fc2SMarek Szyprowski 	unsigned int i;
11796e2a3b66SGustavo Padovan 	int ret;
1180d8408326SSeung-Woo Kim 
1181e2dc3f72SAlban Browaeys 	ret = mixer_initialize(ctx, drm_dev);
1182e2dc3f72SAlban Browaeys 	if (ret)
1183e2dc3f72SAlban Browaeys 		return ret;
1184e2dc3f72SAlban Browaeys 
1185fd2d2fc2SMarek Szyprowski 	for (i = 0; i < MIXER_WIN_NR; i++) {
1186adeb6f44STobias Jakobi 		if (i == VP_DEFAULT_WIN && !test_bit(MXR_BIT_VP_ENABLED,
1187adeb6f44STobias Jakobi 						     &ctx->flags))
1188ab144201SMarek Szyprowski 			continue;
1189ab144201SMarek Szyprowski 
119040bdfb0aSMarek Szyprowski 		ret = exynos_plane_init(drm_dev, &ctx->planes[i], i,
11912c82607bSAndrzej Hajda 					&plane_configs[i]);
11927ee14cdcSGustavo Padovan 		if (ret)
11937ee14cdcSGustavo Padovan 			return ret;
11947ee14cdcSGustavo Padovan 	}
11957ee14cdcSGustavo Padovan 
11965d3d0995SGustavo Padovan 	exynos_plane = &ctx->planes[DEFAULT_WIN];
11977ee14cdcSGustavo Padovan 	ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
1198d644951cSAndrzej Hajda 			EXYNOS_DISPLAY_TYPE_HDMI, &mixer_crtc_ops, ctx);
119993bca243SGustavo Padovan 	if (IS_ERR(ctx->crtc)) {
1200e2dc3f72SAlban Browaeys 		mixer_ctx_remove(ctx);
120193bca243SGustavo Padovan 		ret = PTR_ERR(ctx->crtc);
120293bca243SGustavo Padovan 		goto free_ctx;
12038103ef1bSAndrzej Hajda 	}
12048103ef1bSAndrzej Hajda 
12058103ef1bSAndrzej Hajda 	return 0;
120693bca243SGustavo Padovan 
120793bca243SGustavo Padovan free_ctx:
120893bca243SGustavo Padovan 	devm_kfree(dev, ctx);
120993bca243SGustavo Padovan 	return ret;
12108103ef1bSAndrzej Hajda }
12118103ef1bSAndrzej Hajda 
12128103ef1bSAndrzej Hajda static void mixer_unbind(struct device *dev, struct device *master, void *data)
12138103ef1bSAndrzej Hajda {
12148103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
12158103ef1bSAndrzej Hajda 
121693bca243SGustavo Padovan 	mixer_ctx_remove(ctx);
12178103ef1bSAndrzej Hajda }
12188103ef1bSAndrzej Hajda 
12198103ef1bSAndrzej Hajda static const struct component_ops mixer_component_ops = {
12208103ef1bSAndrzej Hajda 	.bind	= mixer_bind,
12218103ef1bSAndrzej Hajda 	.unbind	= mixer_unbind,
12228103ef1bSAndrzej Hajda };
12238103ef1bSAndrzej Hajda 
12248103ef1bSAndrzej Hajda static int mixer_probe(struct platform_device *pdev)
12258103ef1bSAndrzej Hajda {
12268103ef1bSAndrzej Hajda 	struct device *dev = &pdev->dev;
122748f6155aSMarek Szyprowski 	const struct mixer_drv_data *drv;
12288103ef1bSAndrzej Hajda 	struct mixer_context *ctx;
12298103ef1bSAndrzej Hajda 	int ret;
1230d8408326SSeung-Woo Kim 
1231f041b257SSean Paul 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1232f041b257SSean Paul 	if (!ctx) {
12336f83d208SInki Dae 		DRM_DEV_ERROR(dev, "failed to alloc mixer context.\n");
1234d8408326SSeung-Woo Kim 		return -ENOMEM;
1235f041b257SSean Paul 	}
1236d8408326SSeung-Woo Kim 
123748f6155aSMarek Szyprowski 	drv = of_device_get_match_data(dev);
1238aaf8b49eSRahul Sharma 
12394551789fSSean Paul 	ctx->pdev = pdev;
1240d873ab99SSeung-Woo Kim 	ctx->dev = dev;
12411e123441SRahul Sharma 	ctx->mxr_ver = drv->version;
1242d8408326SSeung-Woo Kim 
1243adeb6f44STobias Jakobi 	if (drv->is_vp_enabled)
1244adeb6f44STobias Jakobi 		__set_bit(MXR_BIT_VP_ENABLED, &ctx->flags);
1245adeb6f44STobias Jakobi 	if (drv->has_sclk)
1246adeb6f44STobias Jakobi 		__set_bit(MXR_BIT_HAS_SCLK, &ctx->flags);
1247adeb6f44STobias Jakobi 
12488103ef1bSAndrzej Hajda 	platform_set_drvdata(pdev, ctx);
1249df5225bcSInki Dae 
1250df5225bcSInki Dae 	ret = component_add(&pdev->dev, &mixer_component_ops);
125186650408SAndrzej Hajda 	if (!ret)
12528103ef1bSAndrzej Hajda 		pm_runtime_enable(dev);
1253df5225bcSInki Dae 
1254df5225bcSInki Dae 	return ret;
1255f37cd5e8SInki Dae }
1256f37cd5e8SInki Dae 
1257d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev)
1258d8408326SSeung-Woo Kim {
12598103ef1bSAndrzej Hajda 	pm_runtime_disable(&pdev->dev);
12608103ef1bSAndrzej Hajda 
1261df5225bcSInki Dae 	component_del(&pdev->dev, &mixer_component_ops);
1262df5225bcSInki Dae 
1263d8408326SSeung-Woo Kim 	return 0;
1264d8408326SSeung-Woo Kim }
1265d8408326SSeung-Woo Kim 
1266e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_suspend(struct device *dev)
1267ccf034a9SGustavo Padovan {
1268ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1269ccf034a9SGustavo Padovan 
1270524c59f1SAndrzej Hajda 	clk_disable_unprepare(ctx->hdmi);
1271524c59f1SAndrzej Hajda 	clk_disable_unprepare(ctx->mixer);
1272adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
1273524c59f1SAndrzej Hajda 		clk_disable_unprepare(ctx->vp);
1274adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags))
1275524c59f1SAndrzej Hajda 			clk_disable_unprepare(ctx->sclk_mixer);
1276ccf034a9SGustavo Padovan 	}
1277ccf034a9SGustavo Padovan 
1278ccf034a9SGustavo Padovan 	return 0;
1279ccf034a9SGustavo Padovan }
1280ccf034a9SGustavo Padovan 
1281e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_resume(struct device *dev)
1282ccf034a9SGustavo Padovan {
1283ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1284ccf034a9SGustavo Padovan 	int ret;
1285ccf034a9SGustavo Padovan 
1286524c59f1SAndrzej Hajda 	ret = clk_prepare_enable(ctx->mixer);
1287ccf034a9SGustavo Padovan 	if (ret < 0) {
12886f83d208SInki Dae 		DRM_DEV_ERROR(ctx->dev,
12896f83d208SInki Dae 			      "Failed to prepare_enable the mixer clk [%d]\n",
12906f83d208SInki Dae 			      ret);
1291ccf034a9SGustavo Padovan 		return ret;
1292ccf034a9SGustavo Padovan 	}
1293524c59f1SAndrzej Hajda 	ret = clk_prepare_enable(ctx->hdmi);
1294ccf034a9SGustavo Padovan 	if (ret < 0) {
12956f83d208SInki Dae 		DRM_DEV_ERROR(dev,
12966f83d208SInki Dae 			      "Failed to prepare_enable the hdmi clk [%d]\n",
12976f83d208SInki Dae 			      ret);
1298ccf034a9SGustavo Padovan 		return ret;
1299ccf034a9SGustavo Padovan 	}
1300adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
1301524c59f1SAndrzej Hajda 		ret = clk_prepare_enable(ctx->vp);
1302ccf034a9SGustavo Padovan 		if (ret < 0) {
13036f83d208SInki Dae 			DRM_DEV_ERROR(dev,
13046f83d208SInki Dae 				      "Failed to prepare_enable the vp clk [%d]\n",
1305ccf034a9SGustavo Padovan 				      ret);
1306ccf034a9SGustavo Padovan 			return ret;
1307ccf034a9SGustavo Padovan 		}
1308adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags)) {
1309524c59f1SAndrzej Hajda 			ret = clk_prepare_enable(ctx->sclk_mixer);
1310ccf034a9SGustavo Padovan 			if (ret < 0) {
13116f83d208SInki Dae 				DRM_DEV_ERROR(dev,
13126f83d208SInki Dae 					   "Failed to prepare_enable the " \
1313ccf034a9SGustavo Padovan 					   "sclk_mixer clk [%d]\n",
1314ccf034a9SGustavo Padovan 					   ret);
1315ccf034a9SGustavo Padovan 				return ret;
1316ccf034a9SGustavo Padovan 			}
1317ccf034a9SGustavo Padovan 		}
1318ccf034a9SGustavo Padovan 	}
1319ccf034a9SGustavo Padovan 
1320ccf034a9SGustavo Padovan 	return 0;
1321ccf034a9SGustavo Padovan }
1322ccf034a9SGustavo Padovan 
1323ccf034a9SGustavo Padovan static const struct dev_pm_ops exynos_mixer_pm_ops = {
1324ccf034a9SGustavo Padovan 	SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL)
13257e915746SMarek Szyprowski 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
13267e915746SMarek Szyprowski 				pm_runtime_force_resume)
1327ccf034a9SGustavo Padovan };
1328ccf034a9SGustavo Padovan 
1329d8408326SSeung-Woo Kim struct platform_driver mixer_driver = {
1330d8408326SSeung-Woo Kim 	.driver = {
1331aaf8b49eSRahul Sharma 		.name = "exynos-mixer",
1332d8408326SSeung-Woo Kim 		.owner = THIS_MODULE,
1333ccf034a9SGustavo Padovan 		.pm = &exynos_mixer_pm_ops,
1334aaf8b49eSRahul Sharma 		.of_match_table = mixer_match_types,
1335d8408326SSeung-Woo Kim 	},
1336d8408326SSeung-Woo Kim 	.probe = mixer_probe,
133756550d94SGreg Kroah-Hartman 	.remove = mixer_remove,
1338d8408326SSeung-Woo Kim };
1339