xref: /linux/drivers/gpu/drm/exynos/exynos_mixer.c (revision 6ac99a328ee16d3f8cc253f1df62623cee3e9ea5)
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>
3448f6155aSMarek Szyprowski #include <linux/of_device.h>
35f37cd5e8SInki Dae #include <linux/component.h>
36d8408326SSeung-Woo Kim 
37d8408326SSeung-Woo Kim #include <drm/exynos_drm.h>
38d8408326SSeung-Woo Kim 
39d8408326SSeung-Woo Kim #include "exynos_drm_drv.h"
40663d8766SRahul Sharma #include "exynos_drm_crtc.h"
410488f50eSMarek Szyprowski #include "exynos_drm_fb.h"
427ee14cdcSGustavo Padovan #include "exynos_drm_plane.h"
431055b39fSInki Dae #include "exynos_drm_iommu.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 |
135*6ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_PIX_BLEND |
136*6ac99a32SChristoph 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 |
144*6ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_PIX_BLEND |
145*6ac99a32SChristoph 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 |
153*6ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_TILE |
154*6ac99a32SChristoph 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 { \
231d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#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 { \
263d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#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,
317*6ac99a32SChristoph Manszewski 				unsigned int pixel_alpha, unsigned int alpha)
318f657a996SMarek Szyprowski {
319*6ac99a32SChristoph 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 	}
335*6ac99a32SChristoph Manszewski 
336*6ac99a32SChristoph Manszewski 	if (alpha != DRM_BLEND_ALPHA_OPAQUE) {
337*6ac99a32SChristoph Manszewski 		val |= MXR_GRP_CFG_WIN_BLEND_EN;
338*6ac99a32SChristoph Manszewski 		val |= win_alpha;
339*6ac99a32SChristoph Manszewski 	}
340524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_GRAPHIC_CFG(win),
341f657a996SMarek Szyprowski 			    val, MXR_GRP_CFG_MISC_MASK);
342f657a996SMarek Szyprowski }
343f657a996SMarek Szyprowski 
344*6ac99a32SChristoph Manszewski static void mixer_cfg_vp_blend(struct mixer_context *ctx, unsigned int alpha)
345f657a996SMarek Szyprowski {
346*6ac99a32SChristoph Manszewski 	u32 win_alpha = alpha >> 8;
347*6ac99a32SChristoph Manszewski 	u32 val = 0;
348f657a996SMarek Szyprowski 
349*6ac99a32SChristoph Manszewski 	if (alpha != DRM_BLEND_ALPHA_OPAQUE) {
350*6ac99a32SChristoph Manszewski 		val |= MXR_VID_CFG_BLEND_EN;
351*6ac99a32SChristoph Manszewski 		val |= win_alpha;
352*6ac99a32SChristoph Manszewski 	}
353524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_VIDEO_CFG, val);
354f657a996SMarek Szyprowski }
355f657a996SMarek Szyprowski 
356d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable)
357d8408326SSeung-Woo Kim {
358d8408326SSeung-Woo Kim 	/* block update on vsync */
359524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, enable ?
360d8408326SSeung-Woo Kim 			MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE);
361d8408326SSeung-Woo Kim 
362adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
363524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_SHADOW_UPDATE, enable ?
364d8408326SSeung-Woo Kim 			VP_SHADOW_UPDATE_ENABLE : 0);
365d8408326SSeung-Woo Kim }
366d8408326SSeung-Woo Kim 
3673fc40ca9SAndrzej Hajda static void mixer_cfg_scan(struct mixer_context *ctx, int width, int height)
368d8408326SSeung-Woo Kim {
369d8408326SSeung-Woo Kim 	u32 val;
370d8408326SSeung-Woo Kim 
371d8408326SSeung-Woo Kim 	/* choosing between interlace and progressive mode */
372adeb6f44STobias Jakobi 	val = test_bit(MXR_BIT_INTERLACE, &ctx->flags) ?
373adeb6f44STobias Jakobi 		MXR_CFG_SCAN_INTERLACE : MXR_CFG_SCAN_PROGRESSIVE;
374d8408326SSeung-Woo Kim 
375acc8bf04SAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_128_0_0_184)
376524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_RESOLUTION,
3773fc40ca9SAndrzej Hajda 			MXR_MXR_RES_HEIGHT(height) | MXR_MXR_RES_WIDTH(width));
378d8408326SSeung-Woo Kim 	else
379acc8bf04SAndrzej Hajda 		val |= ctx->scan_value;
380d8408326SSeung-Woo Kim 
381524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_SCAN_MASK);
382d8408326SSeung-Woo Kim }
383d8408326SSeung-Woo Kim 
384d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height)
385d8408326SSeung-Woo Kim {
386d8408326SSeung-Woo Kim 	u32 val;
387d8408326SSeung-Woo Kim 
3882a39db01STobias Jakobi 	switch (height) {
3892a39db01STobias Jakobi 	case 480:
3902a39db01STobias Jakobi 	case 576:
391d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
3922a39db01STobias Jakobi 		break;
3932a39db01STobias Jakobi 	case 720:
3942a39db01STobias Jakobi 	case 1080:
3952a39db01STobias Jakobi 	default:
396d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
3972a6e4cd5STobias Jakobi 		/* Configure the BT.709 CSC matrix for full range RGB. */
398524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_CM_COEFF_Y,
3992a6e4cd5STobias Jakobi 			MXR_CSC_CT( 0.184,  0.614,  0.063) |
4002a6e4cd5STobias Jakobi 			MXR_CM_COEFF_RGB_FULL);
401524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_CM_COEFF_CB,
4022a6e4cd5STobias Jakobi 			MXR_CSC_CT(-0.102, -0.338,  0.440));
403524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_CM_COEFF_CR,
4042a6e4cd5STobias Jakobi 			MXR_CSC_CT( 0.440, -0.399, -0.040));
4052a39db01STobias Jakobi 		break;
406d8408326SSeung-Woo Kim 	}
407d8408326SSeung-Woo Kim 
408524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
409d8408326SSeung-Woo Kim }
410d8408326SSeung-Woo Kim 
4115b1d5bc6STobias Jakobi static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win,
412a2cb911eSMarek Szyprowski 			    unsigned int priority, bool enable)
413d8408326SSeung-Woo Kim {
414d8408326SSeung-Woo Kim 	u32 val = enable ? ~0 : 0;
415d8408326SSeung-Woo Kim 
416d8408326SSeung-Woo Kim 	switch (win) {
417d8408326SSeung-Woo Kim 	case 0:
418524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
419524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_LAYER_CFG,
420a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP0_VAL(priority),
421a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP0_MASK);
422d8408326SSeung-Woo Kim 		break;
423d8408326SSeung-Woo Kim 	case 1:
424524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
425524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_LAYER_CFG,
426a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP1_VAL(priority),
427a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP1_MASK);
428adeb6f44STobias Jakobi 
429d8408326SSeung-Woo Kim 		break;
4305e68fef2SMarek Szyprowski 	case VP_DEFAULT_WIN:
431adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
432524c59f1SAndrzej Hajda 			vp_reg_writemask(ctx, VP_ENABLE, val, VP_ENABLE_ON);
433524c59f1SAndrzej Hajda 			mixer_reg_writemask(ctx, MXR_CFG, val,
4341b8e5747SRahul Sharma 				MXR_CFG_VP_ENABLE);
435524c59f1SAndrzej Hajda 			mixer_reg_writemask(ctx, MXR_LAYER_CFG,
436a2cb911eSMarek Szyprowski 					    MXR_LAYER_CFG_VP_VAL(priority),
437a2cb911eSMarek Szyprowski 					    MXR_LAYER_CFG_VP_MASK);
4381b8e5747SRahul Sharma 		}
439d8408326SSeung-Woo Kim 		break;
440d8408326SSeung-Woo Kim 	}
441d8408326SSeung-Woo Kim }
442d8408326SSeung-Woo Kim 
443d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx)
444d8408326SSeung-Woo Kim {
445524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
446d8408326SSeung-Woo Kim }
447d8408326SSeung-Woo Kim 
448381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx)
449381be025SRahul Sharma {
450381be025SRahul Sharma 	int timeout = 20;
451381be025SRahul Sharma 
452524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, 0, MXR_STATUS_REG_RUN);
453381be025SRahul Sharma 
454524c59f1SAndrzej Hajda 	while (!(mixer_reg_read(ctx, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
455381be025SRahul Sharma 			--timeout)
456381be025SRahul Sharma 		usleep_range(10000, 12000);
457381be025SRahul Sharma }
458381be025SRahul Sharma 
459521d98a3SAndrzej Hajda static void mixer_commit(struct mixer_context *ctx)
460521d98a3SAndrzej Hajda {
461521d98a3SAndrzej Hajda 	struct drm_display_mode *mode = &ctx->crtc->base.state->adjusted_mode;
462521d98a3SAndrzej Hajda 
4633fc40ca9SAndrzej Hajda 	mixer_cfg_scan(ctx, mode->hdisplay, mode->vdisplay);
464521d98a3SAndrzej Hajda 	mixer_cfg_rgb_fmt(ctx, mode->vdisplay);
465521d98a3SAndrzej Hajda 	mixer_run(ctx);
466521d98a3SAndrzej Hajda }
467521d98a3SAndrzej Hajda 
4682eeb2e5eSGustavo Padovan static void vp_video_buffer(struct mixer_context *ctx,
4692eeb2e5eSGustavo Padovan 			    struct exynos_drm_plane *plane)
470d8408326SSeung-Woo Kim {
4710114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
4720114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
4730114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
474e47726a1SMarek Szyprowski 	unsigned int priority = state->base.normalized_zpos + 1;
475d8408326SSeung-Woo Kim 	unsigned long flags;
476d8408326SSeung-Woo Kim 	dma_addr_t luma_addr[2], chroma_addr[2];
4770f752694STobias Jakobi 	bool is_tiled, is_nv21;
478d8408326SSeung-Woo Kim 	u32 val;
479d8408326SSeung-Woo Kim 
4800f752694STobias Jakobi 	is_nv21 = (fb->format->format == DRM_FORMAT_NV21);
4810f752694STobias Jakobi 	is_tiled = (fb->modifier == DRM_FORMAT_MOD_SAMSUNG_64_32_TILE);
482f40031c2STobias Jakobi 
4830488f50eSMarek Szyprowski 	luma_addr[0] = exynos_drm_fb_dma_addr(fb, 0);
4840488f50eSMarek Szyprowski 	chroma_addr[0] = exynos_drm_fb_dma_addr(fb, 1);
485d8408326SSeung-Woo Kim 
48671469944SAndrzej Hajda 	if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
4870f752694STobias Jakobi 		if (is_tiled) {
488d8408326SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + 0x40;
489d8408326SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + 0x40;
490d8408326SSeung-Woo Kim 		} else {
4912eeb2e5eSGustavo Padovan 			luma_addr[1] = luma_addr[0] + fb->pitches[0];
4920ccc1c8fSTobias Jakobi 			chroma_addr[1] = chroma_addr[0] + fb->pitches[1];
493d8408326SSeung-Woo Kim 		}
494d8408326SSeung-Woo Kim 	} else {
495d8408326SSeung-Woo Kim 		luma_addr[1] = 0;
496d8408326SSeung-Woo Kim 		chroma_addr[1] = 0;
497d8408326SSeung-Woo Kim 	}
498d8408326SSeung-Woo Kim 
499524c59f1SAndrzej Hajda 	spin_lock_irqsave(&ctx->reg_slock, flags);
500d8408326SSeung-Woo Kim 
5012eced8e9SAndrzej Hajda 	vp_reg_write(ctx, VP_SHADOW_UPDATE, 1);
502d8408326SSeung-Woo Kim 	/* interlace or progressive scan mode */
503adeb6f44STobias Jakobi 	val = (test_bit(MXR_BIT_INTERLACE, &ctx->flags) ? ~0 : 0);
504524c59f1SAndrzej Hajda 	vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_LINE_SKIP);
505d8408326SSeung-Woo Kim 
506d8408326SSeung-Woo Kim 	/* setup format */
5070f752694STobias Jakobi 	val = (is_nv21 ? VP_MODE_NV21 : VP_MODE_NV12);
5080f752694STobias Jakobi 	val |= (is_tiled ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
509524c59f1SAndrzej Hajda 	vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_FMT_MASK);
510d8408326SSeung-Woo Kim 
511d8408326SSeung-Woo Kim 	/* setting size of input image */
512524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) |
5132eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height));
514dc500cfbSTobias Jakobi 	/* chroma plane for NV12/NV21 is half the height of the luma plane */
5150ccc1c8fSTobias Jakobi 	vp_reg_write(ctx, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[1]) |
5162eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height / 2));
517d8408326SSeung-Woo Kim 
518524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_SRC_WIDTH, state->src.w);
519524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_SRC_H_POSITION,
5200114f404SMarek Szyprowski 			VP_SRC_H_POSITION_VAL(state->src.x));
521524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_DST_WIDTH, state->crtc.w);
522524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_DST_H_POSITION, state->crtc.x);
5230ccc1c8fSTobias Jakobi 
524adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
5250ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_HEIGHT, state->src.h / 2);
5260ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_V_POSITION, state->src.y / 2);
527524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_HEIGHT, state->crtc.h / 2);
528524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_V_POSITION, state->crtc.y / 2);
529d8408326SSeung-Woo Kim 	} else {
5300ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_HEIGHT, state->src.h);
5310ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_V_POSITION, state->src.y);
532524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_HEIGHT, state->crtc.h);
533524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_V_POSITION, state->crtc.y);
534d8408326SSeung-Woo Kim 	}
535d8408326SSeung-Woo Kim 
536524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_H_RATIO, state->h_ratio);
537524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_V_RATIO, state->v_ratio);
538d8408326SSeung-Woo Kim 
539524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
540d8408326SSeung-Woo Kim 
541d8408326SSeung-Woo Kim 	/* set buffer address to vp */
542524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_TOP_Y_PTR, luma_addr[0]);
543524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_BOT_Y_PTR, luma_addr[1]);
544524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_TOP_C_PTR, chroma_addr[0]);
545524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_BOT_C_PTR, chroma_addr[1]);
546d8408326SSeung-Woo Kim 
547e47726a1SMarek Szyprowski 	mixer_cfg_layer(ctx, plane->index, priority, true);
548*6ac99a32SChristoph Manszewski 	mixer_cfg_vp_blend(ctx, state->base.alpha);
549d8408326SSeung-Woo Kim 
550524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&ctx->reg_slock, flags);
551d8408326SSeung-Woo Kim 
552c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
553d8408326SSeung-Woo Kim 	vp_regs_dump(ctx);
554d8408326SSeung-Woo Kim }
555d8408326SSeung-Woo Kim 
556aaf8b49eSRahul Sharma static void mixer_layer_update(struct mixer_context *ctx)
557aaf8b49eSRahul Sharma {
558524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
559aaf8b49eSRahul Sharma }
560aaf8b49eSRahul Sharma 
5612eeb2e5eSGustavo Padovan static void mixer_graph_buffer(struct mixer_context *ctx,
5622eeb2e5eSGustavo Padovan 			       struct exynos_drm_plane *plane)
563d8408326SSeung-Woo Kim {
5640114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
5650114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
5660114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
567e47726a1SMarek Szyprowski 	unsigned int priority = state->base.normalized_zpos + 1;
568d8408326SSeung-Woo Kim 	unsigned long flags;
56940bdfb0aSMarek Szyprowski 	unsigned int win = plane->index;
5702611015cSTobias Jakobi 	unsigned int x_ratio = 0, y_ratio = 0;
5715dff6905STobias Jakobi 	unsigned int dst_x_offset, dst_y_offset;
572482582c0SChristoph Manszewski 	unsigned int pixel_alpha;
573d8408326SSeung-Woo Kim 	dma_addr_t dma_addr;
574d8408326SSeung-Woo Kim 	unsigned int fmt;
575d8408326SSeung-Woo Kim 	u32 val;
576d8408326SSeung-Woo Kim 
577482582c0SChristoph Manszewski 	if (fb->format->has_alpha)
578482582c0SChristoph Manszewski 		pixel_alpha = state->base.pixel_blend_mode;
579482582c0SChristoph Manszewski 	else
580482582c0SChristoph Manszewski 		pixel_alpha = DRM_MODE_BLEND_PIXEL_NONE;
581482582c0SChristoph Manszewski 
582438b74a5SVille Syrjälä 	switch (fb->format->format) {
5837a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB4444:
58426a7af3eSTobias Jakobi 	case DRM_FORMAT_ARGB4444:
5857a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB4444;
5867a57ca7cSTobias Jakobi 		break;
587d8408326SSeung-Woo Kim 
5887a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB1555:
58926a7af3eSTobias Jakobi 	case DRM_FORMAT_ARGB1555:
5907a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB1555;
591d8408326SSeung-Woo Kim 		break;
5927a57ca7cSTobias Jakobi 
5937a57ca7cSTobias Jakobi 	case DRM_FORMAT_RGB565:
5947a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_RGB565;
595d8408326SSeung-Woo Kim 		break;
5967a57ca7cSTobias Jakobi 
5977a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB8888:
5987a57ca7cSTobias Jakobi 	case DRM_FORMAT_ARGB8888:
5991e60d62fSTobias Jakobi 	default:
6007a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB8888;
6017a57ca7cSTobias Jakobi 		break;
602d8408326SSeung-Woo Kim 	}
603d8408326SSeung-Woo Kim 
604e463b069SMarek Szyprowski 	/* ratio is already checked by common plane code */
605e463b069SMarek Szyprowski 	x_ratio = state->h_ratio == (1 << 15);
606e463b069SMarek Szyprowski 	y_ratio = state->v_ratio == (1 << 15);
607d8408326SSeung-Woo Kim 
6080114f404SMarek Szyprowski 	dst_x_offset = state->crtc.x;
6090114f404SMarek Szyprowski 	dst_y_offset = state->crtc.y;
610d8408326SSeung-Woo Kim 
6115dff6905STobias Jakobi 	/* translate dma address base s.t. the source image offset is zero */
6120488f50eSMarek Szyprowski 	dma_addr = exynos_drm_fb_dma_addr(fb, 0)
613272725c7SVille Syrjälä 		+ (state->src.x * fb->format->cpp[0])
6140114f404SMarek Szyprowski 		+ (state->src.y * fb->pitches[0]);
615d8408326SSeung-Woo Kim 
616524c59f1SAndrzej Hajda 	spin_lock_irqsave(&ctx->reg_slock, flags);
617d8408326SSeung-Woo Kim 
618d8408326SSeung-Woo Kim 	/* setup format */
619524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_GRAPHIC_CFG(win),
620d8408326SSeung-Woo Kim 		MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
621d8408326SSeung-Woo Kim 
622d8408326SSeung-Woo Kim 	/* setup geometry */
623524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_SPAN(win),
624272725c7SVille Syrjälä 			fb->pitches[0] / fb->format->cpp[0]);
625d8408326SSeung-Woo Kim 
6260114f404SMarek Szyprowski 	val  = MXR_GRP_WH_WIDTH(state->src.w);
6270114f404SMarek Szyprowski 	val |= MXR_GRP_WH_HEIGHT(state->src.h);
628d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_H_SCALE(x_ratio);
629d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_V_SCALE(y_ratio);
630524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_WH(win), val);
631d8408326SSeung-Woo Kim 
632d8408326SSeung-Woo Kim 	/* setup offsets in display image */
633d8408326SSeung-Woo Kim 	val  = MXR_GRP_DXY_DX(dst_x_offset);
634d8408326SSeung-Woo Kim 	val |= MXR_GRP_DXY_DY(dst_y_offset);
635524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_DXY(win), val);
636d8408326SSeung-Woo Kim 
637d8408326SSeung-Woo Kim 	/* set buffer address to mixer */
638524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_BASE(win), dma_addr);
639d8408326SSeung-Woo Kim 
640e47726a1SMarek Szyprowski 	mixer_cfg_layer(ctx, win, priority, true);
641*6ac99a32SChristoph Manszewski 	mixer_cfg_gfx_blend(ctx, win, pixel_alpha, state->base.alpha);
642aaf8b49eSRahul Sharma 
643aaf8b49eSRahul Sharma 	/* layer update mandatory for mixer 16.0.33.0 */
644def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
645def5e095SRahul Sharma 		ctx->mxr_ver == MXR_VER_128_0_0_184)
646aaf8b49eSRahul Sharma 		mixer_layer_update(ctx);
647aaf8b49eSRahul Sharma 
648524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&ctx->reg_slock, flags);
649c0734fbaSTobias Jakobi 
650c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
651d8408326SSeung-Woo Kim }
652d8408326SSeung-Woo Kim 
653d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx)
654d8408326SSeung-Woo Kim {
655a696394cSTobias Jakobi 	unsigned int tries = 100;
656d8408326SSeung-Woo Kim 
657524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_SRESET, VP_SRESET_PROCESSING);
6588646dcb8SDan Carpenter 	while (--tries) {
659d8408326SSeung-Woo Kim 		/* waiting until VP_SRESET_PROCESSING is 0 */
660524c59f1SAndrzej Hajda 		if (~vp_reg_read(ctx, VP_SRESET) & VP_SRESET_PROCESSING)
661d8408326SSeung-Woo Kim 			break;
66202b3de43STomasz Stanislawski 		mdelay(10);
663d8408326SSeung-Woo Kim 	}
664d8408326SSeung-Woo Kim 	WARN(tries == 0, "failed to reset Video Processor\n");
665d8408326SSeung-Woo Kim }
666d8408326SSeung-Woo Kim 
667cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx)
668cf8fc4f1SJoonyoung Shim {
669cf8fc4f1SJoonyoung Shim 	unsigned long flags;
670cf8fc4f1SJoonyoung Shim 
671524c59f1SAndrzej Hajda 	spin_lock_irqsave(&ctx->reg_slock, flags);
672cf8fc4f1SJoonyoung Shim 
673524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
674cf8fc4f1SJoonyoung Shim 
675cf8fc4f1SJoonyoung Shim 	/* set output in RGB888 mode */
676524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
677cf8fc4f1SJoonyoung Shim 
678cf8fc4f1SJoonyoung Shim 	/* 16 beat burst in DMA */
679524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, MXR_STATUS_16_BURST,
680cf8fc4f1SJoonyoung Shim 		MXR_STATUS_BURST_MASK);
681cf8fc4f1SJoonyoung Shim 
682a2cb911eSMarek Szyprowski 	/* reset default layer priority */
683524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_LAYER_CFG, 0);
684cf8fc4f1SJoonyoung Shim 
6852a6e4cd5STobias Jakobi 	/* set all background colors to RGB (0,0,0) */
686524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_BG_COLOR0, MXR_YCBCR_VAL(0, 128, 128));
687524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_BG_COLOR1, MXR_YCBCR_VAL(0, 128, 128));
688524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_BG_COLOR2, MXR_YCBCR_VAL(0, 128, 128));
689cf8fc4f1SJoonyoung Shim 
690adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
691cf8fc4f1SJoonyoung Shim 		/* configuration of Video Processor Registers */
692cf8fc4f1SJoonyoung Shim 		vp_win_reset(ctx);
693524c59f1SAndrzej Hajda 		vp_default_filter(ctx);
6941b8e5747SRahul Sharma 	}
695cf8fc4f1SJoonyoung Shim 
696cf8fc4f1SJoonyoung Shim 	/* disable all layers */
697524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
698524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
699adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
700524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
701cf8fc4f1SJoonyoung Shim 
7025dff6905STobias Jakobi 	/* set all source image offsets to zero */
703524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_SXY(0), 0);
704524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_SXY(1), 0);
7055dff6905STobias Jakobi 
706524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&ctx->reg_slock, flags);
707cf8fc4f1SJoonyoung Shim }
708cf8fc4f1SJoonyoung Shim 
7094551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg)
7104551789fSSean Paul {
7114551789fSSean Paul 	struct mixer_context *ctx = arg;
7124551789fSSean Paul 	u32 val, base, shadow;
7134551789fSSean Paul 
714524c59f1SAndrzej Hajda 	spin_lock(&ctx->reg_slock);
7154551789fSSean Paul 
7164551789fSSean Paul 	/* read interrupt status for handling and clearing flags for VSYNC */
717524c59f1SAndrzej Hajda 	val = mixer_reg_read(ctx, MXR_INT_STATUS);
7184551789fSSean Paul 
7194551789fSSean Paul 	/* handling VSYNC */
7204551789fSSean Paul 	if (val & MXR_INT_STATUS_VSYNC) {
72181a464dfSAndrzej Hajda 		/* vsync interrupt use different bit for read and clear */
72281a464dfSAndrzej Hajda 		val |= MXR_INT_CLEAR_VSYNC;
72381a464dfSAndrzej Hajda 		val &= ~MXR_INT_STATUS_VSYNC;
72481a464dfSAndrzej Hajda 
7254551789fSSean Paul 		/* interlace scan need to check shadow register */
726adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
7272eced8e9SAndrzej Hajda 			if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags) &&
7282eced8e9SAndrzej Hajda 			    vp_reg_read(ctx, VP_SHADOW_UPDATE))
7292eced8e9SAndrzej Hajda 				goto out;
7302eced8e9SAndrzej Hajda 
7312eced8e9SAndrzej Hajda 			base = mixer_reg_read(ctx, MXR_CFG);
7322eced8e9SAndrzej Hajda 			shadow = mixer_reg_read(ctx, MXR_CFG_S);
7332eced8e9SAndrzej Hajda 			if (base != shadow)
7342eced8e9SAndrzej Hajda 				goto out;
7352eced8e9SAndrzej Hajda 
736524c59f1SAndrzej Hajda 			base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(0));
737524c59f1SAndrzej Hajda 			shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(0));
7384551789fSSean Paul 			if (base != shadow)
7394551789fSSean Paul 				goto out;
7404551789fSSean Paul 
741524c59f1SAndrzej Hajda 			base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(1));
742524c59f1SAndrzej Hajda 			shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(1));
7434551789fSSean Paul 			if (base != shadow)
7444551789fSSean Paul 				goto out;
7454551789fSSean Paul 		}
7464551789fSSean Paul 
747eafd540aSGustavo Padovan 		drm_crtc_handle_vblank(&ctx->crtc->base);
7484551789fSSean Paul 	}
7494551789fSSean Paul 
7504551789fSSean Paul out:
7514551789fSSean Paul 	/* clear interrupts */
752524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_INT_STATUS, val);
7534551789fSSean Paul 
754524c59f1SAndrzej Hajda 	spin_unlock(&ctx->reg_slock);
7554551789fSSean Paul 
7564551789fSSean Paul 	return IRQ_HANDLED;
7574551789fSSean Paul }
7584551789fSSean Paul 
7594551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx)
7604551789fSSean Paul {
7614551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
7624551789fSSean Paul 	struct resource *res;
7634551789fSSean Paul 	int ret;
7644551789fSSean Paul 
765524c59f1SAndrzej Hajda 	spin_lock_init(&mixer_ctx->reg_slock);
7664551789fSSean Paul 
767524c59f1SAndrzej Hajda 	mixer_ctx->mixer = devm_clk_get(dev, "mixer");
768524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->mixer)) {
7694551789fSSean Paul 		dev_err(dev, "failed to get clock 'mixer'\n");
7704551789fSSean Paul 		return -ENODEV;
7714551789fSSean Paul 	}
7724551789fSSean Paul 
773524c59f1SAndrzej Hajda 	mixer_ctx->hdmi = devm_clk_get(dev, "hdmi");
774524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->hdmi)) {
77504427ec5SMarek Szyprowski 		dev_err(dev, "failed to get clock 'hdmi'\n");
776524c59f1SAndrzej Hajda 		return PTR_ERR(mixer_ctx->hdmi);
77704427ec5SMarek Szyprowski 	}
77804427ec5SMarek Szyprowski 
779524c59f1SAndrzej Hajda 	mixer_ctx->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
780524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->sclk_hdmi)) {
7814551789fSSean Paul 		dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
7824551789fSSean Paul 		return -ENODEV;
7834551789fSSean Paul 	}
7844551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
7854551789fSSean Paul 	if (res == NULL) {
7864551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
7874551789fSSean Paul 		return -ENXIO;
7884551789fSSean Paul 	}
7894551789fSSean Paul 
790524c59f1SAndrzej Hajda 	mixer_ctx->mixer_regs = devm_ioremap(dev, res->start,
7914551789fSSean Paul 							resource_size(res));
792524c59f1SAndrzej Hajda 	if (mixer_ctx->mixer_regs == NULL) {
7934551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
7944551789fSSean Paul 		return -ENXIO;
7954551789fSSean Paul 	}
7964551789fSSean Paul 
7974551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0);
7984551789fSSean Paul 	if (res == NULL) {
7994551789fSSean Paul 		dev_err(dev, "get interrupt resource failed.\n");
8004551789fSSean Paul 		return -ENXIO;
8014551789fSSean Paul 	}
8024551789fSSean Paul 
8034551789fSSean Paul 	ret = devm_request_irq(dev, res->start, mixer_irq_handler,
8044551789fSSean Paul 						0, "drm_mixer", mixer_ctx);
8054551789fSSean Paul 	if (ret) {
8064551789fSSean Paul 		dev_err(dev, "request interrupt failed.\n");
8074551789fSSean Paul 		return ret;
8084551789fSSean Paul 	}
809524c59f1SAndrzej Hajda 	mixer_ctx->irq = res->start;
8104551789fSSean Paul 
8114551789fSSean Paul 	return 0;
8124551789fSSean Paul }
8134551789fSSean Paul 
8144551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx)
8154551789fSSean Paul {
8164551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
8174551789fSSean Paul 	struct resource *res;
8184551789fSSean Paul 
819524c59f1SAndrzej Hajda 	mixer_ctx->vp = devm_clk_get(dev, "vp");
820524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->vp)) {
8214551789fSSean Paul 		dev_err(dev, "failed to get clock 'vp'\n");
8224551789fSSean Paul 		return -ENODEV;
8234551789fSSean Paul 	}
824ff830c96SMarek Szyprowski 
825adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_HAS_SCLK, &mixer_ctx->flags)) {
826524c59f1SAndrzej Hajda 		mixer_ctx->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
827524c59f1SAndrzej Hajda 		if (IS_ERR(mixer_ctx->sclk_mixer)) {
8284551789fSSean Paul 			dev_err(dev, "failed to get clock 'sclk_mixer'\n");
8294551789fSSean Paul 			return -ENODEV;
8304551789fSSean Paul 		}
831524c59f1SAndrzej Hajda 		mixer_ctx->mout_mixer = devm_clk_get(dev, "mout_mixer");
832524c59f1SAndrzej Hajda 		if (IS_ERR(mixer_ctx->mout_mixer)) {
833ff830c96SMarek Szyprowski 			dev_err(dev, "failed to get clock 'mout_mixer'\n");
8344551789fSSean Paul 			return -ENODEV;
8354551789fSSean Paul 		}
8364551789fSSean Paul 
837524c59f1SAndrzej Hajda 		if (mixer_ctx->sclk_hdmi && mixer_ctx->mout_mixer)
838524c59f1SAndrzej Hajda 			clk_set_parent(mixer_ctx->mout_mixer,
839524c59f1SAndrzej Hajda 				       mixer_ctx->sclk_hdmi);
840ff830c96SMarek Szyprowski 	}
8414551789fSSean Paul 
8424551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
8434551789fSSean Paul 	if (res == NULL) {
8444551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8454551789fSSean Paul 		return -ENXIO;
8464551789fSSean Paul 	}
8474551789fSSean Paul 
848524c59f1SAndrzej Hajda 	mixer_ctx->vp_regs = devm_ioremap(dev, res->start,
8494551789fSSean Paul 							resource_size(res));
850524c59f1SAndrzej Hajda 	if (mixer_ctx->vp_regs == NULL) {
8514551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8524551789fSSean Paul 		return -ENXIO;
8534551789fSSean Paul 	}
8544551789fSSean Paul 
8554551789fSSean Paul 	return 0;
8564551789fSSean Paul }
8574551789fSSean Paul 
85893bca243SGustavo Padovan static int mixer_initialize(struct mixer_context *mixer_ctx,
859f37cd5e8SInki Dae 			struct drm_device *drm_dev)
8604551789fSSean Paul {
8614551789fSSean Paul 	int ret;
8624551789fSSean Paul 
863eb88e422SGustavo Padovan 	mixer_ctx->drm_dev = drm_dev;
8644551789fSSean Paul 
8654551789fSSean Paul 	/* acquire resources: regs, irqs, clocks */
8664551789fSSean Paul 	ret = mixer_resources_init(mixer_ctx);
8674551789fSSean Paul 	if (ret) {
8684551789fSSean Paul 		DRM_ERROR("mixer_resources_init failed ret=%d\n", ret);
8694551789fSSean Paul 		return ret;
8704551789fSSean Paul 	}
8714551789fSSean Paul 
872adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &mixer_ctx->flags)) {
8734551789fSSean Paul 		/* acquire vp resources: regs, irqs, clocks */
8744551789fSSean Paul 		ret = vp_resources_init(mixer_ctx);
8754551789fSSean Paul 		if (ret) {
8764551789fSSean Paul 			DRM_ERROR("vp_resources_init failed ret=%d\n", ret);
8774551789fSSean Paul 			return ret;
8784551789fSSean Paul 		}
8794551789fSSean Paul 	}
8804551789fSSean Paul 
881f44d3d2fSAndrzej Hajda 	return drm_iommu_attach_device(drm_dev, mixer_ctx->dev);
8821055b39fSInki Dae }
8831055b39fSInki Dae 
88493bca243SGustavo Padovan static void mixer_ctx_remove(struct mixer_context *mixer_ctx)
885d8408326SSeung-Woo Kim {
886f041b257SSean Paul 	drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev);
887f041b257SSean Paul }
888f041b257SSean Paul 
88993bca243SGustavo Padovan static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)
890f041b257SSean Paul {
89193bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
892d8408326SSeung-Woo Kim 
8930df5e4acSAndrzej Hajda 	__set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
8940df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
895f041b257SSean Paul 		return 0;
896d8408326SSeung-Woo Kim 
897d8408326SSeung-Woo Kim 	/* enable vsync interrupt */
898524c59f1SAndrzej Hajda 	mixer_reg_writemask(mixer_ctx, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
899524c59f1SAndrzej Hajda 	mixer_reg_writemask(mixer_ctx, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
900d8408326SSeung-Woo Kim 
901d8408326SSeung-Woo Kim 	return 0;
902d8408326SSeung-Woo Kim }
903d8408326SSeung-Woo Kim 
90493bca243SGustavo Padovan static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
905d8408326SSeung-Woo Kim {
90693bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
907d8408326SSeung-Woo Kim 
9080df5e4acSAndrzej Hajda 	__clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9090df5e4acSAndrzej Hajda 
9100df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
911947710c6SAndrzej Hajda 		return;
912947710c6SAndrzej Hajda 
913d8408326SSeung-Woo Kim 	/* disable vsync interrupt */
914524c59f1SAndrzej Hajda 	mixer_reg_writemask(mixer_ctx, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
915524c59f1SAndrzej Hajda 	mixer_reg_writemask(mixer_ctx, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
916d8408326SSeung-Woo Kim }
917d8408326SSeung-Woo Kim 
9183dbaab16SMarek Szyprowski static void mixer_atomic_begin(struct exynos_drm_crtc *crtc)
9193dbaab16SMarek Szyprowski {
9203dbaab16SMarek Szyprowski 	struct mixer_context *mixer_ctx = crtc->ctx;
9213dbaab16SMarek Szyprowski 
9223dbaab16SMarek Szyprowski 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
9233dbaab16SMarek Szyprowski 		return;
9243dbaab16SMarek Szyprowski 
9253dbaab16SMarek Szyprowski 	mixer_vsync_set_update(mixer_ctx, false);
9263dbaab16SMarek Szyprowski }
9273dbaab16SMarek Szyprowski 
9281e1d1393SGustavo Padovan static void mixer_update_plane(struct exynos_drm_crtc *crtc,
9291e1d1393SGustavo Padovan 			       struct exynos_drm_plane *plane)
930d8408326SSeung-Woo Kim {
93193bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
932d8408326SSeung-Woo Kim 
93340bdfb0aSMarek Szyprowski 	DRM_DEBUG_KMS("win: %d\n", plane->index);
934d8408326SSeung-Woo Kim 
935a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
936dda9012bSShirish S 		return;
937dda9012bSShirish S 
9385e68fef2SMarek Szyprowski 	if (plane->index == VP_DEFAULT_WIN)
9392eeb2e5eSGustavo Padovan 		vp_video_buffer(mixer_ctx, plane);
940d8408326SSeung-Woo Kim 	else
9412eeb2e5eSGustavo Padovan 		mixer_graph_buffer(mixer_ctx, plane);
942d8408326SSeung-Woo Kim }
943d8408326SSeung-Woo Kim 
9441e1d1393SGustavo Padovan static void mixer_disable_plane(struct exynos_drm_crtc *crtc,
9451e1d1393SGustavo Padovan 				struct exynos_drm_plane *plane)
946d8408326SSeung-Woo Kim {
94793bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
948d8408326SSeung-Woo Kim 	unsigned long flags;
949d8408326SSeung-Woo Kim 
95040bdfb0aSMarek Szyprowski 	DRM_DEBUG_KMS("win: %d\n", plane->index);
951d8408326SSeung-Woo Kim 
952a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
953db43fd16SPrathyush K 		return;
954db43fd16SPrathyush K 
955524c59f1SAndrzej Hajda 	spin_lock_irqsave(&mixer_ctx->reg_slock, flags);
956a2cb911eSMarek Szyprowski 	mixer_cfg_layer(mixer_ctx, plane->index, 0, false);
957524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&mixer_ctx->reg_slock, flags);
9583dbaab16SMarek Szyprowski }
9593dbaab16SMarek Szyprowski 
9603dbaab16SMarek Szyprowski static void mixer_atomic_flush(struct exynos_drm_crtc *crtc)
9613dbaab16SMarek Szyprowski {
9623dbaab16SMarek Szyprowski 	struct mixer_context *mixer_ctx = crtc->ctx;
9633dbaab16SMarek Szyprowski 
9643dbaab16SMarek Szyprowski 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
9653dbaab16SMarek Szyprowski 		return;
966d8408326SSeung-Woo Kim 
967d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, true);
968a392276dSAndrzej Hajda 	exynos_crtc_handle_event(crtc);
969d8408326SSeung-Woo Kim }
970d8408326SSeung-Woo Kim 
9713cecda03SGustavo Padovan static void mixer_enable(struct exynos_drm_crtc *crtc)
972db43fd16SPrathyush K {
9733cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
974db43fd16SPrathyush K 
975a44652e8SAndrzej Hajda 	if (test_bit(MXR_BIT_POWERED, &ctx->flags))
976db43fd16SPrathyush K 		return;
977db43fd16SPrathyush K 
978af65c804SSean Paul 	pm_runtime_get_sync(ctx->dev);
979af65c804SSean Paul 
980a121d179SAndrzej Hajda 	exynos_drm_pipe_clk_enable(crtc, true);
981a121d179SAndrzej Hajda 
9823dbaab16SMarek Szyprowski 	mixer_vsync_set_update(ctx, false);
9833dbaab16SMarek Szyprowski 
984524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
985d74ed937SRahul Sharma 
9860df5e4acSAndrzej Hajda 	if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) {
987524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_INT_STATUS, ~0,
988524c59f1SAndrzej Hajda 					MXR_INT_CLEAR_VSYNC);
989524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
9900df5e4acSAndrzej Hajda 	}
991db43fd16SPrathyush K 	mixer_win_reset(ctx);
992ccf034a9SGustavo Padovan 
99371469944SAndrzej Hajda 	mixer_commit(ctx);
99471469944SAndrzej Hajda 
9953dbaab16SMarek Szyprowski 	mixer_vsync_set_update(ctx, true);
9963dbaab16SMarek Szyprowski 
997ccf034a9SGustavo Padovan 	set_bit(MXR_BIT_POWERED, &ctx->flags);
998db43fd16SPrathyush K }
999db43fd16SPrathyush K 
10003cecda03SGustavo Padovan static void mixer_disable(struct exynos_drm_crtc *crtc)
1001db43fd16SPrathyush K {
10023cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
1003c329f667SJoonyoung Shim 	int i;
1004db43fd16SPrathyush K 
1005a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
1006b4bfa3c7SRahul Sharma 		return;
1007db43fd16SPrathyush K 
1008381be025SRahul Sharma 	mixer_stop(ctx);
1009c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
1010c329f667SJoonyoung Shim 
1011c329f667SJoonyoung Shim 	for (i = 0; i < MIXER_WIN_NR; i++)
10121e1d1393SGustavo Padovan 		mixer_disable_plane(crtc, &ctx->planes[i]);
1013db43fd16SPrathyush K 
1014a121d179SAndrzej Hajda 	exynos_drm_pipe_clk_enable(crtc, false);
1015a121d179SAndrzej Hajda 
1016ccf034a9SGustavo Padovan 	pm_runtime_put(ctx->dev);
1017ccf034a9SGustavo Padovan 
1018a44652e8SAndrzej Hajda 	clear_bit(MXR_BIT_POWERED, &ctx->flags);
1019db43fd16SPrathyush K }
1020db43fd16SPrathyush K 
10216ace38a5SAndrzej Hajda static int mixer_mode_valid(struct exynos_drm_crtc *crtc,
10226ace38a5SAndrzej Hajda 		const struct drm_display_mode *mode)
1023f041b257SSean Paul {
10246ace38a5SAndrzej Hajda 	struct mixer_context *ctx = crtc->ctx;
10256ace38a5SAndrzej Hajda 	u32 w = mode->hdisplay, h = mode->vdisplay;
1026f041b257SSean Paul 
10276ace38a5SAndrzej Hajda 	DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n", w, h,
10286ace38a5SAndrzej Hajda 		mode->vrefresh, !!(mode->flags & DRM_MODE_FLAG_INTERLACE));
1029f041b257SSean Paul 
10306ace38a5SAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_128_0_0_184)
10316ace38a5SAndrzej Hajda 		return MODE_OK;
1032f041b257SSean Paul 
1033f041b257SSean Paul 	if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
1034f041b257SSean Paul 	    (w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
1035f041b257SSean Paul 	    (w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
10366ace38a5SAndrzej Hajda 		return MODE_OK;
1037f041b257SSean Paul 
1038ae58c03eSDaniel Drake 	if ((w == 1024 && h == 768) ||
1039ae58c03eSDaniel Drake 	    (w == 1366 && h == 768) ||
1040ae58c03eSDaniel Drake 	    (w == 1280 && h == 1024))
10410900673eSAndrzej Hajda 		return MODE_OK;
10420900673eSAndrzej Hajda 
10436ace38a5SAndrzej Hajda 	return MODE_BAD;
1044f041b257SSean Paul }
1045f041b257SSean Paul 
1046acc8bf04SAndrzej Hajda static bool mixer_mode_fixup(struct exynos_drm_crtc *crtc,
1047acc8bf04SAndrzej Hajda 		   const struct drm_display_mode *mode,
1048acc8bf04SAndrzej Hajda 		   struct drm_display_mode *adjusted_mode)
1049acc8bf04SAndrzej Hajda {
1050acc8bf04SAndrzej Hajda 	struct mixer_context *ctx = crtc->ctx;
1051acc8bf04SAndrzej Hajda 	int width = mode->hdisplay, height = mode->vdisplay, i;
1052acc8bf04SAndrzej Hajda 
1053acc8bf04SAndrzej Hajda 	struct {
1054acc8bf04SAndrzej Hajda 		int hdisplay, vdisplay, htotal, vtotal, scan_val;
1055acc8bf04SAndrzej Hajda 	} static const modes[] = {
1056acc8bf04SAndrzej Hajda 		{ 720, 480, 858, 525, MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD },
1057acc8bf04SAndrzej Hajda 		{ 720, 576, 864, 625, MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD },
1058acc8bf04SAndrzej Hajda 		{ 1280, 720, 1650, 750, MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD },
1059acc8bf04SAndrzej Hajda 		{ 1920, 1080, 2200, 1125, MXR_CFG_SCAN_HD_1080 |
1060acc8bf04SAndrzej Hajda 						MXR_CFG_SCAN_HD }
1061acc8bf04SAndrzej Hajda 	};
1062acc8bf04SAndrzej Hajda 
1063acc8bf04SAndrzej Hajda 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1064acc8bf04SAndrzej Hajda 		__set_bit(MXR_BIT_INTERLACE, &ctx->flags);
1065acc8bf04SAndrzej Hajda 	else
1066acc8bf04SAndrzej Hajda 		__clear_bit(MXR_BIT_INTERLACE, &ctx->flags);
1067acc8bf04SAndrzej Hajda 
1068acc8bf04SAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_128_0_0_184)
1069acc8bf04SAndrzej Hajda 		return true;
1070acc8bf04SAndrzej Hajda 
1071acc8bf04SAndrzej Hajda 	for (i = 0; i < ARRAY_SIZE(modes); ++i)
1072acc8bf04SAndrzej Hajda 		if (width <= modes[i].hdisplay && height <= modes[i].vdisplay) {
1073acc8bf04SAndrzej Hajda 			ctx->scan_value = modes[i].scan_val;
1074acc8bf04SAndrzej Hajda 			if (width < modes[i].hdisplay ||
1075acc8bf04SAndrzej Hajda 			    height < modes[i].vdisplay) {
1076acc8bf04SAndrzej Hajda 				adjusted_mode->hdisplay = modes[i].hdisplay;
1077acc8bf04SAndrzej Hajda 				adjusted_mode->hsync_start = modes[i].hdisplay;
1078acc8bf04SAndrzej Hajda 				adjusted_mode->hsync_end = modes[i].htotal;
1079acc8bf04SAndrzej Hajda 				adjusted_mode->htotal = modes[i].htotal;
1080acc8bf04SAndrzej Hajda 				adjusted_mode->vdisplay = modes[i].vdisplay;
1081acc8bf04SAndrzej Hajda 				adjusted_mode->vsync_start = modes[i].vdisplay;
1082acc8bf04SAndrzej Hajda 				adjusted_mode->vsync_end = modes[i].vtotal;
1083acc8bf04SAndrzej Hajda 				adjusted_mode->vtotal = modes[i].vtotal;
1084acc8bf04SAndrzej Hajda 			}
1085acc8bf04SAndrzej Hajda 
1086acc8bf04SAndrzej Hajda 			return true;
1087acc8bf04SAndrzej Hajda 		}
1088acc8bf04SAndrzej Hajda 
1089acc8bf04SAndrzej Hajda 	return false;
1090acc8bf04SAndrzej Hajda }
1091acc8bf04SAndrzej Hajda 
1092f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops mixer_crtc_ops = {
10933cecda03SGustavo Padovan 	.enable			= mixer_enable,
10943cecda03SGustavo Padovan 	.disable		= mixer_disable,
1095d8408326SSeung-Woo Kim 	.enable_vblank		= mixer_enable_vblank,
1096d8408326SSeung-Woo Kim 	.disable_vblank		= mixer_disable_vblank,
10973dbaab16SMarek Szyprowski 	.atomic_begin		= mixer_atomic_begin,
10989cc7610aSGustavo Padovan 	.update_plane		= mixer_update_plane,
10999cc7610aSGustavo Padovan 	.disable_plane		= mixer_disable_plane,
11003dbaab16SMarek Szyprowski 	.atomic_flush		= mixer_atomic_flush,
11016ace38a5SAndrzej Hajda 	.mode_valid		= mixer_mode_valid,
1102acc8bf04SAndrzej Hajda 	.mode_fixup		= mixer_mode_fixup,
1103f041b257SSean Paul };
11040ea6822fSRahul Sharma 
11055e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos5420_mxr_drv_data = {
1106def5e095SRahul Sharma 	.version = MXR_VER_128_0_0_184,
1107def5e095SRahul Sharma 	.is_vp_enabled = 0,
1108def5e095SRahul Sharma };
1109def5e095SRahul Sharma 
11105e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos5250_mxr_drv_data = {
1111aaf8b49eSRahul Sharma 	.version = MXR_VER_16_0_33_0,
1112aaf8b49eSRahul Sharma 	.is_vp_enabled = 0,
1113aaf8b49eSRahul Sharma };
1114aaf8b49eSRahul Sharma 
11155e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos4212_mxr_drv_data = {
1116ff830c96SMarek Szyprowski 	.version = MXR_VER_0_0_0_16,
1117ff830c96SMarek Szyprowski 	.is_vp_enabled = 1,
1118ff830c96SMarek Szyprowski };
1119ff830c96SMarek Szyprowski 
11205e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos4210_mxr_drv_data = {
11211e123441SRahul Sharma 	.version = MXR_VER_0_0_0_16,
11221b8e5747SRahul Sharma 	.is_vp_enabled = 1,
1123ff830c96SMarek Szyprowski 	.has_sclk = 1,
11241e123441SRahul Sharma };
11251e123441SRahul Sharma 
11265e6cc1c5SArvind Yadav static const struct of_device_id mixer_match_types[] = {
1127aaf8b49eSRahul Sharma 	{
1128ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4210-mixer",
1129ff830c96SMarek Szyprowski 		.data	= &exynos4210_mxr_drv_data,
1130ff830c96SMarek Szyprowski 	}, {
1131ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4212-mixer",
1132ff830c96SMarek Szyprowski 		.data	= &exynos4212_mxr_drv_data,
1133ff830c96SMarek Szyprowski 	}, {
1134aaf8b49eSRahul Sharma 		.compatible = "samsung,exynos5-mixer",
1135cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1136cc57caf0SRahul Sharma 	}, {
1137cc57caf0SRahul Sharma 		.compatible = "samsung,exynos5250-mixer",
1138cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1139aaf8b49eSRahul Sharma 	}, {
1140def5e095SRahul Sharma 		.compatible = "samsung,exynos5420-mixer",
1141def5e095SRahul Sharma 		.data	= &exynos5420_mxr_drv_data,
1142def5e095SRahul Sharma 	}, {
11431e123441SRahul Sharma 		/* end node */
11441e123441SRahul Sharma 	}
11451e123441SRahul Sharma };
114639b58a39SSjoerd Simons MODULE_DEVICE_TABLE(of, mixer_match_types);
11471e123441SRahul Sharma 
1148f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data)
1149d8408326SSeung-Woo Kim {
11508103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
1151f37cd5e8SInki Dae 	struct drm_device *drm_dev = data;
11527ee14cdcSGustavo Padovan 	struct exynos_drm_plane *exynos_plane;
1153fd2d2fc2SMarek Szyprowski 	unsigned int i;
11546e2a3b66SGustavo Padovan 	int ret;
1155d8408326SSeung-Woo Kim 
1156e2dc3f72SAlban Browaeys 	ret = mixer_initialize(ctx, drm_dev);
1157e2dc3f72SAlban Browaeys 	if (ret)
1158e2dc3f72SAlban Browaeys 		return ret;
1159e2dc3f72SAlban Browaeys 
1160fd2d2fc2SMarek Szyprowski 	for (i = 0; i < MIXER_WIN_NR; i++) {
1161adeb6f44STobias Jakobi 		if (i == VP_DEFAULT_WIN && !test_bit(MXR_BIT_VP_ENABLED,
1162adeb6f44STobias Jakobi 						     &ctx->flags))
1163ab144201SMarek Szyprowski 			continue;
1164ab144201SMarek Szyprowski 
116540bdfb0aSMarek Szyprowski 		ret = exynos_plane_init(drm_dev, &ctx->planes[i], i,
11662c82607bSAndrzej Hajda 					&plane_configs[i]);
11677ee14cdcSGustavo Padovan 		if (ret)
11687ee14cdcSGustavo Padovan 			return ret;
11697ee14cdcSGustavo Padovan 	}
11707ee14cdcSGustavo Padovan 
11715d3d0995SGustavo Padovan 	exynos_plane = &ctx->planes[DEFAULT_WIN];
11727ee14cdcSGustavo Padovan 	ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
1173d644951cSAndrzej Hajda 			EXYNOS_DISPLAY_TYPE_HDMI, &mixer_crtc_ops, ctx);
117493bca243SGustavo Padovan 	if (IS_ERR(ctx->crtc)) {
1175e2dc3f72SAlban Browaeys 		mixer_ctx_remove(ctx);
117693bca243SGustavo Padovan 		ret = PTR_ERR(ctx->crtc);
117793bca243SGustavo Padovan 		goto free_ctx;
11788103ef1bSAndrzej Hajda 	}
11798103ef1bSAndrzej Hajda 
11808103ef1bSAndrzej Hajda 	return 0;
118193bca243SGustavo Padovan 
118293bca243SGustavo Padovan free_ctx:
118393bca243SGustavo Padovan 	devm_kfree(dev, ctx);
118493bca243SGustavo Padovan 	return ret;
11858103ef1bSAndrzej Hajda }
11868103ef1bSAndrzej Hajda 
11878103ef1bSAndrzej Hajda static void mixer_unbind(struct device *dev, struct device *master, void *data)
11888103ef1bSAndrzej Hajda {
11898103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
11908103ef1bSAndrzej Hajda 
119193bca243SGustavo Padovan 	mixer_ctx_remove(ctx);
11928103ef1bSAndrzej Hajda }
11938103ef1bSAndrzej Hajda 
11948103ef1bSAndrzej Hajda static const struct component_ops mixer_component_ops = {
11958103ef1bSAndrzej Hajda 	.bind	= mixer_bind,
11968103ef1bSAndrzej Hajda 	.unbind	= mixer_unbind,
11978103ef1bSAndrzej Hajda };
11988103ef1bSAndrzej Hajda 
11998103ef1bSAndrzej Hajda static int mixer_probe(struct platform_device *pdev)
12008103ef1bSAndrzej Hajda {
12018103ef1bSAndrzej Hajda 	struct device *dev = &pdev->dev;
120248f6155aSMarek Szyprowski 	const struct mixer_drv_data *drv;
12038103ef1bSAndrzej Hajda 	struct mixer_context *ctx;
12048103ef1bSAndrzej Hajda 	int ret;
1205d8408326SSeung-Woo Kim 
1206f041b257SSean Paul 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1207f041b257SSean Paul 	if (!ctx) {
1208f041b257SSean Paul 		DRM_ERROR("failed to alloc mixer context.\n");
1209d8408326SSeung-Woo Kim 		return -ENOMEM;
1210f041b257SSean Paul 	}
1211d8408326SSeung-Woo Kim 
121248f6155aSMarek Szyprowski 	drv = of_device_get_match_data(dev);
1213aaf8b49eSRahul Sharma 
12144551789fSSean Paul 	ctx->pdev = pdev;
1215d873ab99SSeung-Woo Kim 	ctx->dev = dev;
12161e123441SRahul Sharma 	ctx->mxr_ver = drv->version;
1217d8408326SSeung-Woo Kim 
1218adeb6f44STobias Jakobi 	if (drv->is_vp_enabled)
1219adeb6f44STobias Jakobi 		__set_bit(MXR_BIT_VP_ENABLED, &ctx->flags);
1220adeb6f44STobias Jakobi 	if (drv->has_sclk)
1221adeb6f44STobias Jakobi 		__set_bit(MXR_BIT_HAS_SCLK, &ctx->flags);
1222adeb6f44STobias Jakobi 
12238103ef1bSAndrzej Hajda 	platform_set_drvdata(pdev, ctx);
1224df5225bcSInki Dae 
1225df5225bcSInki Dae 	ret = component_add(&pdev->dev, &mixer_component_ops);
122686650408SAndrzej Hajda 	if (!ret)
12278103ef1bSAndrzej Hajda 		pm_runtime_enable(dev);
1228df5225bcSInki Dae 
1229df5225bcSInki Dae 	return ret;
1230f37cd5e8SInki Dae }
1231f37cd5e8SInki Dae 
1232d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev)
1233d8408326SSeung-Woo Kim {
12348103ef1bSAndrzej Hajda 	pm_runtime_disable(&pdev->dev);
12358103ef1bSAndrzej Hajda 
1236df5225bcSInki Dae 	component_del(&pdev->dev, &mixer_component_ops);
1237df5225bcSInki Dae 
1238d8408326SSeung-Woo Kim 	return 0;
1239d8408326SSeung-Woo Kim }
1240d8408326SSeung-Woo Kim 
1241e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_suspend(struct device *dev)
1242ccf034a9SGustavo Padovan {
1243ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1244ccf034a9SGustavo Padovan 
1245524c59f1SAndrzej Hajda 	clk_disable_unprepare(ctx->hdmi);
1246524c59f1SAndrzej Hajda 	clk_disable_unprepare(ctx->mixer);
1247adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
1248524c59f1SAndrzej Hajda 		clk_disable_unprepare(ctx->vp);
1249adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags))
1250524c59f1SAndrzej Hajda 			clk_disable_unprepare(ctx->sclk_mixer);
1251ccf034a9SGustavo Padovan 	}
1252ccf034a9SGustavo Padovan 
1253ccf034a9SGustavo Padovan 	return 0;
1254ccf034a9SGustavo Padovan }
1255ccf034a9SGustavo Padovan 
1256e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_resume(struct device *dev)
1257ccf034a9SGustavo Padovan {
1258ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1259ccf034a9SGustavo Padovan 	int ret;
1260ccf034a9SGustavo Padovan 
1261524c59f1SAndrzej Hajda 	ret = clk_prepare_enable(ctx->mixer);
1262ccf034a9SGustavo Padovan 	if (ret < 0) {
1263ccf034a9SGustavo Padovan 		DRM_ERROR("Failed to prepare_enable the mixer clk [%d]\n", ret);
1264ccf034a9SGustavo Padovan 		return ret;
1265ccf034a9SGustavo Padovan 	}
1266524c59f1SAndrzej Hajda 	ret = clk_prepare_enable(ctx->hdmi);
1267ccf034a9SGustavo Padovan 	if (ret < 0) {
1268ccf034a9SGustavo Padovan 		DRM_ERROR("Failed to prepare_enable the hdmi clk [%d]\n", ret);
1269ccf034a9SGustavo Padovan 		return ret;
1270ccf034a9SGustavo Padovan 	}
1271adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
1272524c59f1SAndrzej Hajda 		ret = clk_prepare_enable(ctx->vp);
1273ccf034a9SGustavo Padovan 		if (ret < 0) {
1274ccf034a9SGustavo Padovan 			DRM_ERROR("Failed to prepare_enable the vp clk [%d]\n",
1275ccf034a9SGustavo Padovan 				  ret);
1276ccf034a9SGustavo Padovan 			return ret;
1277ccf034a9SGustavo Padovan 		}
1278adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags)) {
1279524c59f1SAndrzej Hajda 			ret = clk_prepare_enable(ctx->sclk_mixer);
1280ccf034a9SGustavo Padovan 			if (ret < 0) {
1281ccf034a9SGustavo Padovan 				DRM_ERROR("Failed to prepare_enable the " \
1282ccf034a9SGustavo Padovan 					   "sclk_mixer clk [%d]\n",
1283ccf034a9SGustavo Padovan 					  ret);
1284ccf034a9SGustavo Padovan 				return ret;
1285ccf034a9SGustavo Padovan 			}
1286ccf034a9SGustavo Padovan 		}
1287ccf034a9SGustavo Padovan 	}
1288ccf034a9SGustavo Padovan 
1289ccf034a9SGustavo Padovan 	return 0;
1290ccf034a9SGustavo Padovan }
1291ccf034a9SGustavo Padovan 
1292ccf034a9SGustavo Padovan static const struct dev_pm_ops exynos_mixer_pm_ops = {
1293ccf034a9SGustavo Padovan 	SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL)
12947e915746SMarek Szyprowski 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
12957e915746SMarek Szyprowski 				pm_runtime_force_resume)
1296ccf034a9SGustavo Padovan };
1297ccf034a9SGustavo Padovan 
1298d8408326SSeung-Woo Kim struct platform_driver mixer_driver = {
1299d8408326SSeung-Woo Kim 	.driver = {
1300aaf8b49eSRahul Sharma 		.name = "exynos-mixer",
1301d8408326SSeung-Woo Kim 		.owner = THIS_MODULE,
1302ccf034a9SGustavo Padovan 		.pm = &exynos_mixer_pm_ops,
1303aaf8b49eSRahul Sharma 		.of_match_table = mixer_match_types,
1304d8408326SSeung-Woo Kim 	},
1305d8408326SSeung-Woo Kim 	.probe = mixer_probe,
130656550d94SGreg Kroah-Hartman 	.remove = mixer_remove,
1307d8408326SSeung-Woo Kim };
1308