xref: /linux/drivers/gpu/drm/exynos/exynos_mixer.c (revision 11f954899d55c622afbbf23925ce1faf5d647c81)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2d8408326SSeung-Woo Kim /*
3d8408326SSeung-Woo Kim  * Copyright (C) 2011 Samsung Electronics Co.Ltd
4d8408326SSeung-Woo Kim  * Authors:
5d8408326SSeung-Woo Kim  * Seung-Woo Kim <sw0312.kim@samsung.com>
6d8408326SSeung-Woo Kim  *	Inki Dae <inki.dae@samsung.com>
7d8408326SSeung-Woo Kim  *	Joonyoung Shim <jy0922.shim@samsung.com>
8d8408326SSeung-Woo Kim  *
9d8408326SSeung-Woo Kim  * Based on drivers/media/video/s5p-tv/mixer_reg.c
10d8408326SSeung-Woo Kim  */
11d8408326SSeung-Woo Kim 
122bda34d7SSam Ravnborg #include <linux/clk.h>
132bda34d7SSam Ravnborg #include <linux/component.h>
142bda34d7SSam Ravnborg #include <linux/delay.h>
15d8408326SSeung-Woo Kim #include <linux/i2c.h>
16d8408326SSeung-Woo Kim #include <linux/interrupt.h>
17d8408326SSeung-Woo Kim #include <linux/irq.h>
182bda34d7SSam Ravnborg #include <linux/kernel.h>
192bda34d7SSam Ravnborg #include <linux/ktime.h>
203f1c781dSSachin Kamat #include <linux/of.h>
2148f6155aSMarek Szyprowski #include <linux/of_device.h>
222bda34d7SSam Ravnborg #include <linux/platform_device.h>
232bda34d7SSam Ravnborg #include <linux/pm_runtime.h>
242bda34d7SSam Ravnborg #include <linux/regulator/consumer.h>
252bda34d7SSam Ravnborg #include <linux/spinlock.h>
262bda34d7SSam Ravnborg #include <linux/wait.h>
27d8408326SSeung-Woo Kim 
282bda34d7SSam Ravnborg #include <drm/drm_fourcc.h>
292bda34d7SSam Ravnborg #include <drm/drm_vblank.h>
30d8408326SSeung-Woo Kim #include <drm/exynos_drm.h>
31d8408326SSeung-Woo Kim 
32663d8766SRahul Sharma #include "exynos_drm_crtc.h"
332bda34d7SSam Ravnborg #include "exynos_drm_drv.h"
340488f50eSMarek Szyprowski #include "exynos_drm_fb.h"
357ee14cdcSGustavo Padovan #include "exynos_drm_plane.h"
362bda34d7SSam Ravnborg #include "regs-mixer.h"
372bda34d7SSam Ravnborg #include "regs-vp.h"
3822b21ae6SJoonyoung Shim 
39f041b257SSean Paul #define MIXER_WIN_NR		3
40fbbb1e1aSMarek Szyprowski #define VP_DEFAULT_WIN		2
41d8408326SSeung-Woo Kim 
422a6e4cd5STobias Jakobi /*
432a6e4cd5STobias Jakobi  * Mixer color space conversion coefficient triplet.
442a6e4cd5STobias Jakobi  * Used for CSC from RGB to YCbCr.
452a6e4cd5STobias Jakobi  * Each coefficient is a 10-bit fixed point number with
462a6e4cd5STobias Jakobi  * sign and no integer part, i.e.
472a6e4cd5STobias Jakobi  * [0:8] = fractional part (representing a value y = x / 2^9)
482a6e4cd5STobias Jakobi  * [9] = sign
492a6e4cd5STobias Jakobi  * Negative values are encoded with two's complement.
502a6e4cd5STobias Jakobi  */
512a6e4cd5STobias Jakobi #define MXR_CSC_C(x) ((int)((x) * 512.0) & 0x3ff)
522a6e4cd5STobias Jakobi #define MXR_CSC_CT(a0, a1, a2) \
532a6e4cd5STobias Jakobi   ((MXR_CSC_C(a0) << 20) | (MXR_CSC_C(a1) << 10) | (MXR_CSC_C(a2) << 0))
542a6e4cd5STobias Jakobi 
552a6e4cd5STobias Jakobi /* YCbCr value, used for mixer background color configuration. */
562a6e4cd5STobias Jakobi #define MXR_YCBCR_VAL(y, cb, cr) (((y) << 16) | ((cb) << 8) | ((cr) << 0))
572a6e4cd5STobias Jakobi 
587a57ca7cSTobias Jakobi /* The pixelformats that are natively supported by the mixer. */
597a57ca7cSTobias Jakobi #define MXR_FORMAT_RGB565	4
607a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB1555	5
617a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB4444	6
627a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB8888	7
637a57ca7cSTobias Jakobi 
641e123441SRahul Sharma enum mixer_version_id {
651e123441SRahul Sharma 	MXR_VER_0_0_0_16,
661e123441SRahul Sharma 	MXR_VER_16_0_33_0,
67def5e095SRahul Sharma 	MXR_VER_128_0_0_184,
681e123441SRahul Sharma };
691e123441SRahul Sharma 
70a44652e8SAndrzej Hajda enum mixer_flag_bits {
71a44652e8SAndrzej Hajda 	MXR_BIT_POWERED,
720df5e4acSAndrzej Hajda 	MXR_BIT_VSYNC,
73adeb6f44STobias Jakobi 	MXR_BIT_INTERLACE,
74adeb6f44STobias Jakobi 	MXR_BIT_VP_ENABLED,
75adeb6f44STobias Jakobi 	MXR_BIT_HAS_SCLK,
76a44652e8SAndrzej Hajda };
77a44652e8SAndrzej Hajda 
78fbbb1e1aSMarek Szyprowski static const uint32_t mixer_formats[] = {
79fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB4444,
8026a7af3eSTobias Jakobi 	DRM_FORMAT_ARGB4444,
81fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB1555,
8226a7af3eSTobias Jakobi 	DRM_FORMAT_ARGB1555,
83fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_RGB565,
84fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB8888,
85fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_ARGB8888,
86fbbb1e1aSMarek Szyprowski };
87fbbb1e1aSMarek Szyprowski 
88fbbb1e1aSMarek Szyprowski static const uint32_t vp_formats[] = {
89fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_NV12,
90fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_NV21,
91fbbb1e1aSMarek Szyprowski };
92fbbb1e1aSMarek Szyprowski 
9322b21ae6SJoonyoung Shim struct mixer_context {
944551789fSSean Paul 	struct platform_device *pdev;
95cf8fc4f1SJoonyoung Shim 	struct device		*dev;
961055b39fSInki Dae 	struct drm_device	*drm_dev;
9793bca243SGustavo Padovan 	struct exynos_drm_crtc	*crtc;
987ee14cdcSGustavo Padovan 	struct exynos_drm_plane	planes[MIXER_WIN_NR];
99a44652e8SAndrzej Hajda 	unsigned long		flags;
10022b21ae6SJoonyoung Shim 
101524c59f1SAndrzej Hajda 	int			irq;
102524c59f1SAndrzej Hajda 	void __iomem		*mixer_regs;
103524c59f1SAndrzej Hajda 	void __iomem		*vp_regs;
104524c59f1SAndrzej Hajda 	spinlock_t		reg_slock;
105524c59f1SAndrzej Hajda 	struct clk		*mixer;
106524c59f1SAndrzej Hajda 	struct clk		*vp;
107524c59f1SAndrzej Hajda 	struct clk		*hdmi;
108524c59f1SAndrzej Hajda 	struct clk		*sclk_mixer;
109524c59f1SAndrzej Hajda 	struct clk		*sclk_hdmi;
110524c59f1SAndrzej Hajda 	struct clk		*mout_mixer;
1111e123441SRahul Sharma 	enum mixer_version_id	mxr_ver;
112acc8bf04SAndrzej Hajda 	int			scan_value;
1131e123441SRahul Sharma };
1141e123441SRahul Sharma 
1151e123441SRahul Sharma struct mixer_drv_data {
1161e123441SRahul Sharma 	enum mixer_version_id	version;
1171b8e5747SRahul Sharma 	bool					is_vp_enabled;
118ff830c96SMarek Szyprowski 	bool					has_sclk;
11922b21ae6SJoonyoung Shim };
12022b21ae6SJoonyoung Shim 
121fd2d2fc2SMarek Szyprowski static const struct exynos_drm_plane_config plane_configs[MIXER_WIN_NR] = {
122fd2d2fc2SMarek Szyprowski 	{
123fd2d2fc2SMarek Szyprowski 		.zpos = 0,
124fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_PRIMARY,
125fd2d2fc2SMarek Szyprowski 		.pixel_formats = mixer_formats,
126fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(mixer_formats),
127a2cb911eSMarek Szyprowski 		.capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
128482582c0SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_ZPOS |
1296ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_PIX_BLEND |
1306ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_WIN_BLEND,
131fd2d2fc2SMarek Szyprowski 	}, {
132fd2d2fc2SMarek Szyprowski 		.zpos = 1,
133fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_CURSOR,
134fd2d2fc2SMarek Szyprowski 		.pixel_formats = mixer_formats,
135fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(mixer_formats),
136a2cb911eSMarek Szyprowski 		.capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
137482582c0SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_ZPOS |
1386ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_PIX_BLEND |
1396ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_WIN_BLEND,
140fd2d2fc2SMarek Szyprowski 	}, {
141fd2d2fc2SMarek Szyprowski 		.zpos = 2,
142fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_OVERLAY,
143fd2d2fc2SMarek Szyprowski 		.pixel_formats = vp_formats,
144fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(vp_formats),
145a2cb911eSMarek Szyprowski 		.capabilities = EXYNOS_DRM_PLANE_CAP_SCALE |
146f40031c2STobias Jakobi 				EXYNOS_DRM_PLANE_CAP_ZPOS |
1476ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_TILE |
1486ac99a32SChristoph Manszewski 				EXYNOS_DRM_PLANE_CAP_WIN_BLEND,
149fd2d2fc2SMarek Szyprowski 	},
150fd2d2fc2SMarek Szyprowski };
151fd2d2fc2SMarek Szyprowski 
152d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = {
153d8408326SSeung-Woo Kim 	0,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
154d8408326SSeung-Woo Kim 	-1,	-1,	-1,	-1,	-1,	0,	0,	0,
155d8408326SSeung-Woo Kim 	0,	2,	4,	5,	6,	6,	6,	6,
156d8408326SSeung-Woo Kim 	6,	5,	5,	4,	3,	2,	1,	1,
157d8408326SSeung-Woo Kim 	0,	-6,	-12,	-16,	-18,	-20,	-21,	-20,
158d8408326SSeung-Woo Kim 	-20,	-18,	-16,	-13,	-10,	-8,	-5,	-2,
159d8408326SSeung-Woo Kim 	127,	126,	125,	121,	114,	107,	99,	89,
160d8408326SSeung-Woo Kim 	79,	68,	57,	46,	35,	25,	16,	8,
161d8408326SSeung-Woo Kim };
162d8408326SSeung-Woo Kim 
163d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = {
164d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
165d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
166d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
167d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
168d8408326SSeung-Woo Kim 	0,	5,	11,	19,	27,	37,	48,	59,
169d8408326SSeung-Woo Kim 	70,	81,	92,	102,	111,	118,	124,	126,
170d8408326SSeung-Woo Kim 	0,	0,	-1,	-1,	-2,	-3,	-4,	-5,
171d8408326SSeung-Woo Kim 	-6,	-7,	-8,	-8,	-8,	-8,	-6,	-3,
172d8408326SSeung-Woo Kim };
173d8408326SSeung-Woo Kim 
174d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = {
175d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
176d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
177d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
178d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
179d8408326SSeung-Woo Kim };
180d8408326SSeung-Woo Kim 
181524c59f1SAndrzej Hajda static inline u32 vp_reg_read(struct mixer_context *ctx, u32 reg_id)
182d8408326SSeung-Woo Kim {
183524c59f1SAndrzej Hajda 	return readl(ctx->vp_regs + reg_id);
184d8408326SSeung-Woo Kim }
185d8408326SSeung-Woo Kim 
186524c59f1SAndrzej Hajda static inline void vp_reg_write(struct mixer_context *ctx, u32 reg_id,
187d8408326SSeung-Woo Kim 				 u32 val)
188d8408326SSeung-Woo Kim {
189524c59f1SAndrzej Hajda 	writel(val, ctx->vp_regs + reg_id);
190d8408326SSeung-Woo Kim }
191d8408326SSeung-Woo Kim 
192524c59f1SAndrzej Hajda static inline void vp_reg_writemask(struct mixer_context *ctx, u32 reg_id,
193d8408326SSeung-Woo Kim 				 u32 val, u32 mask)
194d8408326SSeung-Woo Kim {
195524c59f1SAndrzej Hajda 	u32 old = vp_reg_read(ctx, reg_id);
196d8408326SSeung-Woo Kim 
197d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
198524c59f1SAndrzej Hajda 	writel(val, ctx->vp_regs + reg_id);
199d8408326SSeung-Woo Kim }
200d8408326SSeung-Woo Kim 
201524c59f1SAndrzej Hajda static inline u32 mixer_reg_read(struct mixer_context *ctx, u32 reg_id)
202d8408326SSeung-Woo Kim {
203524c59f1SAndrzej Hajda 	return readl(ctx->mixer_regs + reg_id);
204d8408326SSeung-Woo Kim }
205d8408326SSeung-Woo Kim 
206524c59f1SAndrzej Hajda static inline void mixer_reg_write(struct mixer_context *ctx, u32 reg_id,
207d8408326SSeung-Woo Kim 				 u32 val)
208d8408326SSeung-Woo Kim {
209524c59f1SAndrzej Hajda 	writel(val, ctx->mixer_regs + reg_id);
210d8408326SSeung-Woo Kim }
211d8408326SSeung-Woo Kim 
212524c59f1SAndrzej Hajda static inline void mixer_reg_writemask(struct mixer_context *ctx,
213d8408326SSeung-Woo Kim 				 u32 reg_id, u32 val, u32 mask)
214d8408326SSeung-Woo Kim {
215524c59f1SAndrzej Hajda 	u32 old = mixer_reg_read(ctx, reg_id);
216d8408326SSeung-Woo Kim 
217d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
218524c59f1SAndrzej Hajda 	writel(val, ctx->mixer_regs + reg_id);
219d8408326SSeung-Woo Kim }
220d8408326SSeung-Woo Kim 
221d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx)
222d8408326SSeung-Woo Kim {
223d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
224d8408326SSeung-Woo Kim do { \
2256be90056SInki Dae 	DRM_DEV_DEBUG_KMS(ctx->dev, #reg_id " = %08x\n", \
226524c59f1SAndrzej Hajda 			 (u32)readl(ctx->mixer_regs + reg_id)); \
227d8408326SSeung-Woo Kim } while (0)
228d8408326SSeung-Woo Kim 
229d8408326SSeung-Woo Kim 	DUMPREG(MXR_STATUS);
230d8408326SSeung-Woo Kim 	DUMPREG(MXR_CFG);
231d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_EN);
232d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_STATUS);
233d8408326SSeung-Woo Kim 
234d8408326SSeung-Woo Kim 	DUMPREG(MXR_LAYER_CFG);
235d8408326SSeung-Woo Kim 	DUMPREG(MXR_VIDEO_CFG);
236d8408326SSeung-Woo Kim 
237d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_CFG);
238d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_BASE);
239d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SPAN);
240d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_WH);
241d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SXY);
242d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_DXY);
243d8408326SSeung-Woo Kim 
244d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_CFG);
245d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_BASE);
246d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SPAN);
247d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_WH);
248d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SXY);
249d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_DXY);
250d8408326SSeung-Woo Kim #undef DUMPREG
251d8408326SSeung-Woo Kim }
252d8408326SSeung-Woo Kim 
253d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx)
254d8408326SSeung-Woo Kim {
255d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
256d8408326SSeung-Woo Kim do { \
2576be90056SInki Dae 	DRM_DEV_DEBUG_KMS(ctx->dev, #reg_id " = %08x\n", \
258524c59f1SAndrzej Hajda 			 (u32) readl(ctx->vp_regs + reg_id)); \
259d8408326SSeung-Woo Kim } while (0)
260d8408326SSeung-Woo Kim 
261d8408326SSeung-Woo Kim 	DUMPREG(VP_ENABLE);
262d8408326SSeung-Woo Kim 	DUMPREG(VP_SRESET);
263d8408326SSeung-Woo Kim 	DUMPREG(VP_SHADOW_UPDATE);
264d8408326SSeung-Woo Kim 	DUMPREG(VP_FIELD_ID);
265d8408326SSeung-Woo Kim 	DUMPREG(VP_MODE);
266d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_Y);
267d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_C);
268d8408326SSeung-Woo Kim 	DUMPREG(VP_PER_RATE_CTRL);
269d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_Y_PTR);
270d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_Y_PTR);
271d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_C_PTR);
272d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_C_PTR);
273d8408326SSeung-Woo Kim 	DUMPREG(VP_ENDIAN_MODE);
274d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_H_POSITION);
275d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_V_POSITION);
276d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_WIDTH);
277d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_HEIGHT);
278d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_H_POSITION);
279d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_V_POSITION);
280d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_WIDTH);
281d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_HEIGHT);
282d8408326SSeung-Woo Kim 	DUMPREG(VP_H_RATIO);
283d8408326SSeung-Woo Kim 	DUMPREG(VP_V_RATIO);
284d8408326SSeung-Woo Kim 
285d8408326SSeung-Woo Kim #undef DUMPREG
286d8408326SSeung-Woo Kim }
287d8408326SSeung-Woo Kim 
288524c59f1SAndrzej Hajda static inline void vp_filter_set(struct mixer_context *ctx,
289d8408326SSeung-Woo Kim 		int reg_id, const u8 *data, unsigned int size)
290d8408326SSeung-Woo Kim {
291d8408326SSeung-Woo Kim 	/* assure 4-byte align */
292d8408326SSeung-Woo Kim 	BUG_ON(size & 3);
293d8408326SSeung-Woo Kim 	for (; size; size -= 4, reg_id += 4, data += 4) {
294d8408326SSeung-Woo Kim 		u32 val = (data[0] << 24) |  (data[1] << 16) |
295d8408326SSeung-Woo Kim 			(data[2] << 8) | data[3];
296524c59f1SAndrzej Hajda 		vp_reg_write(ctx, reg_id, val);
297d8408326SSeung-Woo Kim 	}
298d8408326SSeung-Woo Kim }
299d8408326SSeung-Woo Kim 
300524c59f1SAndrzej Hajda static void vp_default_filter(struct mixer_context *ctx)
301d8408326SSeung-Woo Kim {
302524c59f1SAndrzej Hajda 	vp_filter_set(ctx, VP_POLY8_Y0_LL,
303e25e1b66SSachin Kamat 		filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
304524c59f1SAndrzej Hajda 	vp_filter_set(ctx, VP_POLY4_Y0_LL,
305e25e1b66SSachin Kamat 		filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
306524c59f1SAndrzej Hajda 	vp_filter_set(ctx, VP_POLY4_C0_LL,
307e25e1b66SSachin Kamat 		filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
308d8408326SSeung-Woo Kim }
309d8408326SSeung-Woo Kim 
310f657a996SMarek Szyprowski static void mixer_cfg_gfx_blend(struct mixer_context *ctx, unsigned int win,
3116ac99a32SChristoph Manszewski 				unsigned int pixel_alpha, unsigned int alpha)
312f657a996SMarek Szyprowski {
3136ac99a32SChristoph Manszewski 	u32 win_alpha = alpha >> 8;
314f657a996SMarek Szyprowski 	u32 val;
315f657a996SMarek Szyprowski 
316f657a996SMarek Szyprowski 	val  = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
317482582c0SChristoph Manszewski 	switch (pixel_alpha) {
318482582c0SChristoph Manszewski 	case DRM_MODE_BLEND_PIXEL_NONE:
319482582c0SChristoph Manszewski 		break;
320482582c0SChristoph Manszewski 	case DRM_MODE_BLEND_COVERAGE:
321482582c0SChristoph Manszewski 		val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
322482582c0SChristoph Manszewski 		break;
323482582c0SChristoph Manszewski 	case DRM_MODE_BLEND_PREMULTI:
324482582c0SChristoph Manszewski 	default:
325f657a996SMarek Szyprowski 		val |= MXR_GRP_CFG_BLEND_PRE_MUL;
326f657a996SMarek Szyprowski 		val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
327482582c0SChristoph Manszewski 		break;
328f657a996SMarek Szyprowski 	}
3296ac99a32SChristoph Manszewski 
3306ac99a32SChristoph Manszewski 	if (alpha != DRM_BLEND_ALPHA_OPAQUE) {
3316ac99a32SChristoph Manszewski 		val |= MXR_GRP_CFG_WIN_BLEND_EN;
3326ac99a32SChristoph Manszewski 		val |= win_alpha;
3336ac99a32SChristoph Manszewski 	}
334524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_GRAPHIC_CFG(win),
335f657a996SMarek Szyprowski 			    val, MXR_GRP_CFG_MISC_MASK);
336f657a996SMarek Szyprowski }
337f657a996SMarek Szyprowski 
3386ac99a32SChristoph Manszewski static void mixer_cfg_vp_blend(struct mixer_context *ctx, unsigned int alpha)
339f657a996SMarek Szyprowski {
3406ac99a32SChristoph Manszewski 	u32 win_alpha = alpha >> 8;
3416ac99a32SChristoph Manszewski 	u32 val = 0;
342f657a996SMarek Szyprowski 
3436ac99a32SChristoph Manszewski 	if (alpha != DRM_BLEND_ALPHA_OPAQUE) {
3446ac99a32SChristoph Manszewski 		val |= MXR_VID_CFG_BLEND_EN;
3456ac99a32SChristoph Manszewski 		val |= win_alpha;
3466ac99a32SChristoph Manszewski 	}
347524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_VIDEO_CFG, val);
348f657a996SMarek Szyprowski }
349f657a996SMarek Szyprowski 
3506a3b45adSAndrzej Hajda static bool mixer_is_synced(struct mixer_context *ctx)
351d8408326SSeung-Woo Kim {
3526a3b45adSAndrzej Hajda 	u32 base, shadow;
353d8408326SSeung-Woo Kim 
3546a3b45adSAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
3556a3b45adSAndrzej Hajda 	    ctx->mxr_ver == MXR_VER_128_0_0_184)
3566a3b45adSAndrzej Hajda 		return !(mixer_reg_read(ctx, MXR_CFG) &
3576a3b45adSAndrzej Hajda 			 MXR_CFG_LAYER_UPDATE_COUNT_MASK);
3586a3b45adSAndrzej Hajda 
3596a3b45adSAndrzej Hajda 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags) &&
3606a3b45adSAndrzej Hajda 	    vp_reg_read(ctx, VP_SHADOW_UPDATE))
3616a3b45adSAndrzej Hajda 		return false;
3626a3b45adSAndrzej Hajda 
3636a3b45adSAndrzej Hajda 	base = mixer_reg_read(ctx, MXR_CFG);
3646a3b45adSAndrzej Hajda 	shadow = mixer_reg_read(ctx, MXR_CFG_S);
3656a3b45adSAndrzej Hajda 	if (base != shadow)
3666a3b45adSAndrzej Hajda 		return false;
3676a3b45adSAndrzej Hajda 
3686a3b45adSAndrzej Hajda 	base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(0));
3696a3b45adSAndrzej Hajda 	shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(0));
3706a3b45adSAndrzej Hajda 	if (base != shadow)
3716a3b45adSAndrzej Hajda 		return false;
3726a3b45adSAndrzej Hajda 
3736a3b45adSAndrzej Hajda 	base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(1));
3746a3b45adSAndrzej Hajda 	shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(1));
3756a3b45adSAndrzej Hajda 	if (base != shadow)
3766a3b45adSAndrzej Hajda 		return false;
3776a3b45adSAndrzej Hajda 
3786a3b45adSAndrzej Hajda 	return true;
3796a3b45adSAndrzej Hajda }
3806a3b45adSAndrzej Hajda 
3816a3b45adSAndrzej Hajda static int mixer_wait_for_sync(struct mixer_context *ctx)
3826a3b45adSAndrzej Hajda {
3836a3b45adSAndrzej Hajda 	ktime_t timeout = ktime_add_us(ktime_get(), 100000);
3846a3b45adSAndrzej Hajda 
3856a3b45adSAndrzej Hajda 	while (!mixer_is_synced(ctx)) {
3866a3b45adSAndrzej Hajda 		usleep_range(1000, 2000);
3876a3b45adSAndrzej Hajda 		if (ktime_compare(ktime_get(), timeout) > 0)
3886a3b45adSAndrzej Hajda 			return -ETIMEDOUT;
3896a3b45adSAndrzej Hajda 	}
3906a3b45adSAndrzej Hajda 	return 0;
3916a3b45adSAndrzej Hajda }
3926a3b45adSAndrzej Hajda 
3936a3b45adSAndrzej Hajda static void mixer_disable_sync(struct mixer_context *ctx)
3946a3b45adSAndrzej Hajda {
3956a3b45adSAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, 0, MXR_STATUS_SYNC_ENABLE);
3966a3b45adSAndrzej Hajda }
3976a3b45adSAndrzej Hajda 
3986a3b45adSAndrzej Hajda static void mixer_enable_sync(struct mixer_context *ctx)
3996a3b45adSAndrzej Hajda {
4006a3b45adSAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
4016a3b45adSAndrzej Hajda 	    ctx->mxr_ver == MXR_VER_128_0_0_184)
4026a3b45adSAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
4036a3b45adSAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_SYNC_ENABLE);
404adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
4056a3b45adSAndrzej Hajda 		vp_reg_write(ctx, VP_SHADOW_UPDATE, VP_SHADOW_UPDATE_ENABLE);
406d8408326SSeung-Woo Kim }
407d8408326SSeung-Woo Kim 
4083fc40ca9SAndrzej Hajda static void mixer_cfg_scan(struct mixer_context *ctx, int width, int height)
409d8408326SSeung-Woo Kim {
410d8408326SSeung-Woo Kim 	u32 val;
411d8408326SSeung-Woo Kim 
412d8408326SSeung-Woo Kim 	/* choosing between interlace and progressive mode */
413adeb6f44STobias Jakobi 	val = test_bit(MXR_BIT_INTERLACE, &ctx->flags) ?
414adeb6f44STobias Jakobi 		MXR_CFG_SCAN_INTERLACE : MXR_CFG_SCAN_PROGRESSIVE;
415d8408326SSeung-Woo Kim 
416acc8bf04SAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_128_0_0_184)
417524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_RESOLUTION,
4183fc40ca9SAndrzej Hajda 			MXR_MXR_RES_HEIGHT(height) | MXR_MXR_RES_WIDTH(width));
419d8408326SSeung-Woo Kim 	else
420acc8bf04SAndrzej Hajda 		val |= ctx->scan_value;
421d8408326SSeung-Woo Kim 
422524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_SCAN_MASK);
423d8408326SSeung-Woo Kim }
424d8408326SSeung-Woo Kim 
42513e810f1SChristoph Manszewski static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, struct drm_display_mode *mode)
426d8408326SSeung-Woo Kim {
42713e810f1SChristoph Manszewski 	enum hdmi_quantization_range range = drm_default_rgb_quant_range(mode);
428d8408326SSeung-Woo Kim 	u32 val;
429d8408326SSeung-Woo Kim 
43013e810f1SChristoph Manszewski 	if (mode->vdisplay < 720) {
43113e810f1SChristoph Manszewski 		val = MXR_CFG_RGB601;
432e9e5ba93SChristoph Manszewski 	} else {
43313e810f1SChristoph Manszewski 		val = MXR_CFG_RGB709;
43413e810f1SChristoph Manszewski 
4352a6e4cd5STobias Jakobi 		/* Configure the BT.709 CSC matrix for full range RGB. */
436524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_CM_COEFF_Y,
4372a6e4cd5STobias Jakobi 			MXR_CSC_CT( 0.184,  0.614,  0.063) |
4382a6e4cd5STobias Jakobi 			MXR_CM_COEFF_RGB_FULL);
439524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_CM_COEFF_CB,
4402a6e4cd5STobias Jakobi 			MXR_CSC_CT(-0.102, -0.338,  0.440));
441524c59f1SAndrzej Hajda 		mixer_reg_write(ctx, MXR_CM_COEFF_CR,
4422a6e4cd5STobias Jakobi 			MXR_CSC_CT( 0.440, -0.399, -0.040));
443d8408326SSeung-Woo Kim 	}
444d8408326SSeung-Woo Kim 
44513e810f1SChristoph Manszewski 	if (range == HDMI_QUANTIZATION_RANGE_FULL)
44613e810f1SChristoph Manszewski 		val |= MXR_CFG_QUANT_RANGE_FULL;
44713e810f1SChristoph Manszewski 	else
44813e810f1SChristoph Manszewski 		val |= MXR_CFG_QUANT_RANGE_LIMITED;
44913e810f1SChristoph Manszewski 
450524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
451d8408326SSeung-Woo Kim }
452d8408326SSeung-Woo Kim 
4535b1d5bc6STobias Jakobi static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win,
454a2cb911eSMarek Szyprowski 			    unsigned int priority, bool enable)
455d8408326SSeung-Woo Kim {
456d8408326SSeung-Woo Kim 	u32 val = enable ? ~0 : 0;
457d8408326SSeung-Woo Kim 
458d8408326SSeung-Woo Kim 	switch (win) {
459d8408326SSeung-Woo Kim 	case 0:
460524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
461524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_LAYER_CFG,
462a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP0_VAL(priority),
463a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP0_MASK);
464d8408326SSeung-Woo Kim 		break;
465d8408326SSeung-Woo Kim 	case 1:
466524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
467524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_LAYER_CFG,
468a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP1_VAL(priority),
469a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP1_MASK);
470adeb6f44STobias Jakobi 
471d8408326SSeung-Woo Kim 		break;
4725e68fef2SMarek Szyprowski 	case VP_DEFAULT_WIN:
473adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
474524c59f1SAndrzej Hajda 			vp_reg_writemask(ctx, VP_ENABLE, val, VP_ENABLE_ON);
475524c59f1SAndrzej Hajda 			mixer_reg_writemask(ctx, MXR_CFG, val,
4761b8e5747SRahul Sharma 				MXR_CFG_VP_ENABLE);
477524c59f1SAndrzej Hajda 			mixer_reg_writemask(ctx, MXR_LAYER_CFG,
478a2cb911eSMarek Szyprowski 					    MXR_LAYER_CFG_VP_VAL(priority),
479a2cb911eSMarek Szyprowski 					    MXR_LAYER_CFG_VP_MASK);
4801b8e5747SRahul Sharma 		}
481d8408326SSeung-Woo Kim 		break;
482d8408326SSeung-Woo Kim 	}
483d8408326SSeung-Woo Kim }
484d8408326SSeung-Woo Kim 
485d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx)
486d8408326SSeung-Woo Kim {
487524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
488d8408326SSeung-Woo Kim }
489d8408326SSeung-Woo Kim 
490381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx)
491381be025SRahul Sharma {
492381be025SRahul Sharma 	int timeout = 20;
493381be025SRahul Sharma 
494524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, 0, MXR_STATUS_REG_RUN);
495381be025SRahul Sharma 
496524c59f1SAndrzej Hajda 	while (!(mixer_reg_read(ctx, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
497381be025SRahul Sharma 			--timeout)
498381be025SRahul Sharma 		usleep_range(10000, 12000);
499381be025SRahul Sharma }
500381be025SRahul Sharma 
501521d98a3SAndrzej Hajda static void mixer_commit(struct mixer_context *ctx)
502521d98a3SAndrzej Hajda {
503521d98a3SAndrzej Hajda 	struct drm_display_mode *mode = &ctx->crtc->base.state->adjusted_mode;
504521d98a3SAndrzej Hajda 
5053fc40ca9SAndrzej Hajda 	mixer_cfg_scan(ctx, mode->hdisplay, mode->vdisplay);
50613e810f1SChristoph Manszewski 	mixer_cfg_rgb_fmt(ctx, mode);
507521d98a3SAndrzej Hajda 	mixer_run(ctx);
508521d98a3SAndrzej Hajda }
509521d98a3SAndrzej Hajda 
5102eeb2e5eSGustavo Padovan static void vp_video_buffer(struct mixer_context *ctx,
5112eeb2e5eSGustavo Padovan 			    struct exynos_drm_plane *plane)
512d8408326SSeung-Woo Kim {
5130114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
5140114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
5150114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
516e47726a1SMarek Szyprowski 	unsigned int priority = state->base.normalized_zpos + 1;
517d8408326SSeung-Woo Kim 	unsigned long flags;
518d8408326SSeung-Woo Kim 	dma_addr_t luma_addr[2], chroma_addr[2];
5190f752694STobias Jakobi 	bool is_tiled, is_nv21;
520d8408326SSeung-Woo Kim 	u32 val;
521d8408326SSeung-Woo Kim 
5220f752694STobias Jakobi 	is_nv21 = (fb->format->format == DRM_FORMAT_NV21);
5230f752694STobias Jakobi 	is_tiled = (fb->modifier == DRM_FORMAT_MOD_SAMSUNG_64_32_TILE);
524f40031c2STobias Jakobi 
5250488f50eSMarek Szyprowski 	luma_addr[0] = exynos_drm_fb_dma_addr(fb, 0);
5260488f50eSMarek Szyprowski 	chroma_addr[0] = exynos_drm_fb_dma_addr(fb, 1);
527d8408326SSeung-Woo Kim 
52871469944SAndrzej Hajda 	if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
5290f752694STobias Jakobi 		if (is_tiled) {
530d8408326SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + 0x40;
531d8408326SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + 0x40;
532d8408326SSeung-Woo Kim 		} else {
5332eeb2e5eSGustavo Padovan 			luma_addr[1] = luma_addr[0] + fb->pitches[0];
5340ccc1c8fSTobias Jakobi 			chroma_addr[1] = chroma_addr[0] + fb->pitches[1];
535d8408326SSeung-Woo Kim 		}
536d8408326SSeung-Woo Kim 	} else {
537d8408326SSeung-Woo Kim 		luma_addr[1] = 0;
538d8408326SSeung-Woo Kim 		chroma_addr[1] = 0;
539d8408326SSeung-Woo Kim 	}
540d8408326SSeung-Woo Kim 
541524c59f1SAndrzej Hajda 	spin_lock_irqsave(&ctx->reg_slock, flags);
542d8408326SSeung-Woo Kim 
543d8408326SSeung-Woo Kim 	/* interlace or progressive scan mode */
544adeb6f44STobias Jakobi 	val = (test_bit(MXR_BIT_INTERLACE, &ctx->flags) ? ~0 : 0);
545524c59f1SAndrzej Hajda 	vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_LINE_SKIP);
546d8408326SSeung-Woo Kim 
547d8408326SSeung-Woo Kim 	/* setup format */
5480f752694STobias Jakobi 	val = (is_nv21 ? VP_MODE_NV21 : VP_MODE_NV12);
5490f752694STobias Jakobi 	val |= (is_tiled ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
550524c59f1SAndrzej Hajda 	vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_FMT_MASK);
551d8408326SSeung-Woo Kim 
552d8408326SSeung-Woo Kim 	/* setting size of input image */
553524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) |
5542eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height));
555dc500cfbSTobias Jakobi 	/* chroma plane for NV12/NV21 is half the height of the luma plane */
5560ccc1c8fSTobias Jakobi 	vp_reg_write(ctx, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[1]) |
5572eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height / 2));
558d8408326SSeung-Woo Kim 
559524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_SRC_WIDTH, state->src.w);
560524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_SRC_H_POSITION,
5610114f404SMarek Szyprowski 			VP_SRC_H_POSITION_VAL(state->src.x));
562524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_DST_WIDTH, state->crtc.w);
563524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_DST_H_POSITION, state->crtc.x);
5640ccc1c8fSTobias Jakobi 
565adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
5660ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_HEIGHT, state->src.h / 2);
5670ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_V_POSITION, state->src.y / 2);
568524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_HEIGHT, state->crtc.h / 2);
569524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_V_POSITION, state->crtc.y / 2);
570d8408326SSeung-Woo Kim 	} else {
5710ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_HEIGHT, state->src.h);
5720ccc1c8fSTobias Jakobi 		vp_reg_write(ctx, VP_SRC_V_POSITION, state->src.y);
573524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_HEIGHT, state->crtc.h);
574524c59f1SAndrzej Hajda 		vp_reg_write(ctx, VP_DST_V_POSITION, state->crtc.y);
575d8408326SSeung-Woo Kim 	}
576d8408326SSeung-Woo Kim 
577524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_H_RATIO, state->h_ratio);
578524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_V_RATIO, state->v_ratio);
579d8408326SSeung-Woo Kim 
580524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
581d8408326SSeung-Woo Kim 
582d8408326SSeung-Woo Kim 	/* set buffer address to vp */
583524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_TOP_Y_PTR, luma_addr[0]);
584524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_BOT_Y_PTR, luma_addr[1]);
585524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_TOP_C_PTR, chroma_addr[0]);
586524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_BOT_C_PTR, chroma_addr[1]);
587d8408326SSeung-Woo Kim 
588e47726a1SMarek Szyprowski 	mixer_cfg_layer(ctx, plane->index, priority, true);
5896ac99a32SChristoph Manszewski 	mixer_cfg_vp_blend(ctx, state->base.alpha);
590d8408326SSeung-Woo Kim 
591524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&ctx->reg_slock, flags);
592d8408326SSeung-Woo Kim 
593c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
594d8408326SSeung-Woo Kim 	vp_regs_dump(ctx);
595d8408326SSeung-Woo Kim }
596d8408326SSeung-Woo Kim 
5972eeb2e5eSGustavo Padovan static void mixer_graph_buffer(struct mixer_context *ctx,
5982eeb2e5eSGustavo Padovan 			       struct exynos_drm_plane *plane)
599d8408326SSeung-Woo Kim {
6000114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
6010114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
6020114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
603e47726a1SMarek Szyprowski 	unsigned int priority = state->base.normalized_zpos + 1;
604d8408326SSeung-Woo Kim 	unsigned long flags;
60540bdfb0aSMarek Szyprowski 	unsigned int win = plane->index;
6062611015cSTobias Jakobi 	unsigned int x_ratio = 0, y_ratio = 0;
6075dff6905STobias Jakobi 	unsigned int dst_x_offset, dst_y_offset;
608482582c0SChristoph Manszewski 	unsigned int pixel_alpha;
609d8408326SSeung-Woo Kim 	dma_addr_t dma_addr;
610d8408326SSeung-Woo Kim 	unsigned int fmt;
611d8408326SSeung-Woo Kim 	u32 val;
612d8408326SSeung-Woo Kim 
613482582c0SChristoph Manszewski 	if (fb->format->has_alpha)
614482582c0SChristoph Manszewski 		pixel_alpha = state->base.pixel_blend_mode;
615482582c0SChristoph Manszewski 	else
616482582c0SChristoph Manszewski 		pixel_alpha = DRM_MODE_BLEND_PIXEL_NONE;
617482582c0SChristoph Manszewski 
618438b74a5SVille Syrjälä 	switch (fb->format->format) {
6197a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB4444:
62026a7af3eSTobias Jakobi 	case DRM_FORMAT_ARGB4444:
6217a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB4444;
6227a57ca7cSTobias Jakobi 		break;
623d8408326SSeung-Woo Kim 
6247a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB1555:
62526a7af3eSTobias Jakobi 	case DRM_FORMAT_ARGB1555:
6267a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB1555;
627d8408326SSeung-Woo Kim 		break;
6287a57ca7cSTobias Jakobi 
6297a57ca7cSTobias Jakobi 	case DRM_FORMAT_RGB565:
6307a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_RGB565;
631d8408326SSeung-Woo Kim 		break;
6327a57ca7cSTobias Jakobi 
6337a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB8888:
6347a57ca7cSTobias Jakobi 	case DRM_FORMAT_ARGB8888:
6351e60d62fSTobias Jakobi 	default:
6367a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB8888;
6377a57ca7cSTobias Jakobi 		break;
638d8408326SSeung-Woo Kim 	}
639d8408326SSeung-Woo Kim 
640e463b069SMarek Szyprowski 	/* ratio is already checked by common plane code */
641e463b069SMarek Szyprowski 	x_ratio = state->h_ratio == (1 << 15);
642e463b069SMarek Szyprowski 	y_ratio = state->v_ratio == (1 << 15);
643d8408326SSeung-Woo Kim 
6440114f404SMarek Szyprowski 	dst_x_offset = state->crtc.x;
6450114f404SMarek Szyprowski 	dst_y_offset = state->crtc.y;
646d8408326SSeung-Woo Kim 
6475dff6905STobias Jakobi 	/* translate dma address base s.t. the source image offset is zero */
6480488f50eSMarek Szyprowski 	dma_addr = exynos_drm_fb_dma_addr(fb, 0)
649272725c7SVille Syrjälä 		+ (state->src.x * fb->format->cpp[0])
6500114f404SMarek Szyprowski 		+ (state->src.y * fb->pitches[0]);
651d8408326SSeung-Woo Kim 
652524c59f1SAndrzej Hajda 	spin_lock_irqsave(&ctx->reg_slock, flags);
653d8408326SSeung-Woo Kim 
654d8408326SSeung-Woo Kim 	/* setup format */
655524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_GRAPHIC_CFG(win),
656d8408326SSeung-Woo Kim 		MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
657d8408326SSeung-Woo Kim 
658d8408326SSeung-Woo Kim 	/* setup geometry */
659524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_SPAN(win),
660272725c7SVille Syrjälä 			fb->pitches[0] / fb->format->cpp[0]);
661d8408326SSeung-Woo Kim 
6620114f404SMarek Szyprowski 	val  = MXR_GRP_WH_WIDTH(state->src.w);
6630114f404SMarek Szyprowski 	val |= MXR_GRP_WH_HEIGHT(state->src.h);
664d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_H_SCALE(x_ratio);
665d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_V_SCALE(y_ratio);
666524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_WH(win), val);
667d8408326SSeung-Woo Kim 
668d8408326SSeung-Woo Kim 	/* setup offsets in display image */
669d8408326SSeung-Woo Kim 	val  = MXR_GRP_DXY_DX(dst_x_offset);
670d8408326SSeung-Woo Kim 	val |= MXR_GRP_DXY_DY(dst_y_offset);
671524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_DXY(win), val);
672d8408326SSeung-Woo Kim 
673d8408326SSeung-Woo Kim 	/* set buffer address to mixer */
674524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_BASE(win), dma_addr);
675d8408326SSeung-Woo Kim 
676e47726a1SMarek Szyprowski 	mixer_cfg_layer(ctx, win, priority, true);
6776ac99a32SChristoph Manszewski 	mixer_cfg_gfx_blend(ctx, win, pixel_alpha, state->base.alpha);
678aaf8b49eSRahul Sharma 
679524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&ctx->reg_slock, flags);
680c0734fbaSTobias Jakobi 
681c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
682d8408326SSeung-Woo Kim }
683d8408326SSeung-Woo Kim 
684d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx)
685d8408326SSeung-Woo Kim {
686a696394cSTobias Jakobi 	unsigned int tries = 100;
687d8408326SSeung-Woo Kim 
688524c59f1SAndrzej Hajda 	vp_reg_write(ctx, VP_SRESET, VP_SRESET_PROCESSING);
6898646dcb8SDan Carpenter 	while (--tries) {
690d8408326SSeung-Woo Kim 		/* waiting until VP_SRESET_PROCESSING is 0 */
691524c59f1SAndrzej Hajda 		if (~vp_reg_read(ctx, VP_SRESET) & VP_SRESET_PROCESSING)
692d8408326SSeung-Woo Kim 			break;
69302b3de43STomasz Stanislawski 		mdelay(10);
694d8408326SSeung-Woo Kim 	}
695d8408326SSeung-Woo Kim 	WARN(tries == 0, "failed to reset Video Processor\n");
696d8408326SSeung-Woo Kim }
697d8408326SSeung-Woo Kim 
698cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx)
699cf8fc4f1SJoonyoung Shim {
700cf8fc4f1SJoonyoung Shim 	unsigned long flags;
701cf8fc4f1SJoonyoung Shim 
702524c59f1SAndrzej Hajda 	spin_lock_irqsave(&ctx->reg_slock, flags);
703cf8fc4f1SJoonyoung Shim 
704524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
705cf8fc4f1SJoonyoung Shim 
706cf8fc4f1SJoonyoung Shim 	/* set output in RGB888 mode */
707524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
708cf8fc4f1SJoonyoung Shim 
709cf8fc4f1SJoonyoung Shim 	/* 16 beat burst in DMA */
710524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, MXR_STATUS_16_BURST,
711cf8fc4f1SJoonyoung Shim 		MXR_STATUS_BURST_MASK);
712cf8fc4f1SJoonyoung Shim 
713a2cb911eSMarek Szyprowski 	/* reset default layer priority */
714524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_LAYER_CFG, 0);
715cf8fc4f1SJoonyoung Shim 
7162a6e4cd5STobias Jakobi 	/* set all background colors to RGB (0,0,0) */
717524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_BG_COLOR0, MXR_YCBCR_VAL(0, 128, 128));
718524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_BG_COLOR1, MXR_YCBCR_VAL(0, 128, 128));
719524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_BG_COLOR2, MXR_YCBCR_VAL(0, 128, 128));
720cf8fc4f1SJoonyoung Shim 
721adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
722cf8fc4f1SJoonyoung Shim 		/* configuration of Video Processor Registers */
723cf8fc4f1SJoonyoung Shim 		vp_win_reset(ctx);
724524c59f1SAndrzej Hajda 		vp_default_filter(ctx);
7251b8e5747SRahul Sharma 	}
726cf8fc4f1SJoonyoung Shim 
727cf8fc4f1SJoonyoung Shim 	/* disable all layers */
728524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
729524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
730adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
731524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
732cf8fc4f1SJoonyoung Shim 
7335dff6905STobias Jakobi 	/* set all source image offsets to zero */
734524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_SXY(0), 0);
735524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_GRAPHIC_SXY(1), 0);
7365dff6905STobias Jakobi 
737524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&ctx->reg_slock, flags);
738cf8fc4f1SJoonyoung Shim }
739cf8fc4f1SJoonyoung Shim 
7404551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg)
7414551789fSSean Paul {
7424551789fSSean Paul 	struct mixer_context *ctx = arg;
7436a3b45adSAndrzej Hajda 	u32 val;
7444551789fSSean Paul 
745524c59f1SAndrzej Hajda 	spin_lock(&ctx->reg_slock);
7464551789fSSean Paul 
7474551789fSSean Paul 	/* read interrupt status for handling and clearing flags for VSYNC */
748524c59f1SAndrzej Hajda 	val = mixer_reg_read(ctx, MXR_INT_STATUS);
7494551789fSSean Paul 
7504551789fSSean Paul 	/* handling VSYNC */
7514551789fSSean Paul 	if (val & MXR_INT_STATUS_VSYNC) {
75281a464dfSAndrzej Hajda 		/* vsync interrupt use different bit for read and clear */
75381a464dfSAndrzej Hajda 		val |= MXR_INT_CLEAR_VSYNC;
75481a464dfSAndrzej Hajda 		val &= ~MXR_INT_STATUS_VSYNC;
75581a464dfSAndrzej Hajda 
7564551789fSSean Paul 		/* interlace scan need to check shadow register */
7576a3b45adSAndrzej Hajda 		if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)
7586a3b45adSAndrzej Hajda 		    && !mixer_is_synced(ctx))
7592eced8e9SAndrzej Hajda 			goto out;
7602eced8e9SAndrzej Hajda 
761eafd540aSGustavo Padovan 		drm_crtc_handle_vblank(&ctx->crtc->base);
7624551789fSSean Paul 	}
7634551789fSSean Paul 
7644551789fSSean Paul out:
7654551789fSSean Paul 	/* clear interrupts */
766524c59f1SAndrzej Hajda 	mixer_reg_write(ctx, MXR_INT_STATUS, val);
7674551789fSSean Paul 
768524c59f1SAndrzej Hajda 	spin_unlock(&ctx->reg_slock);
7694551789fSSean Paul 
7704551789fSSean Paul 	return IRQ_HANDLED;
7714551789fSSean Paul }
7724551789fSSean Paul 
7734551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx)
7744551789fSSean Paul {
7754551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
7764551789fSSean Paul 	struct resource *res;
7774551789fSSean Paul 	int ret;
7784551789fSSean Paul 
779524c59f1SAndrzej Hajda 	spin_lock_init(&mixer_ctx->reg_slock);
7804551789fSSean Paul 
781524c59f1SAndrzej Hajda 	mixer_ctx->mixer = devm_clk_get(dev, "mixer");
782524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->mixer)) {
7834551789fSSean Paul 		dev_err(dev, "failed to get clock 'mixer'\n");
7844551789fSSean Paul 		return -ENODEV;
7854551789fSSean Paul 	}
7864551789fSSean Paul 
787524c59f1SAndrzej Hajda 	mixer_ctx->hdmi = devm_clk_get(dev, "hdmi");
788524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->hdmi)) {
78904427ec5SMarek Szyprowski 		dev_err(dev, "failed to get clock 'hdmi'\n");
790524c59f1SAndrzej Hajda 		return PTR_ERR(mixer_ctx->hdmi);
79104427ec5SMarek Szyprowski 	}
79204427ec5SMarek Szyprowski 
793524c59f1SAndrzej Hajda 	mixer_ctx->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
794524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->sclk_hdmi)) {
7954551789fSSean Paul 		dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
7964551789fSSean Paul 		return -ENODEV;
7974551789fSSean Paul 	}
7984551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
7994551789fSSean Paul 	if (res == NULL) {
8004551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8014551789fSSean Paul 		return -ENXIO;
8024551789fSSean Paul 	}
8034551789fSSean Paul 
804524c59f1SAndrzej Hajda 	mixer_ctx->mixer_regs = devm_ioremap(dev, res->start,
8054551789fSSean Paul 							resource_size(res));
806524c59f1SAndrzej Hajda 	if (mixer_ctx->mixer_regs == NULL) {
8074551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8084551789fSSean Paul 		return -ENXIO;
8094551789fSSean Paul 	}
8104551789fSSean Paul 
8114551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0);
8124551789fSSean Paul 	if (res == NULL) {
8134551789fSSean Paul 		dev_err(dev, "get interrupt resource failed.\n");
8144551789fSSean Paul 		return -ENXIO;
8154551789fSSean Paul 	}
8164551789fSSean Paul 
8174551789fSSean Paul 	ret = devm_request_irq(dev, res->start, mixer_irq_handler,
8184551789fSSean Paul 						0, "drm_mixer", mixer_ctx);
8194551789fSSean Paul 	if (ret) {
8204551789fSSean Paul 		dev_err(dev, "request interrupt failed.\n");
8214551789fSSean Paul 		return ret;
8224551789fSSean Paul 	}
823524c59f1SAndrzej Hajda 	mixer_ctx->irq = res->start;
8244551789fSSean Paul 
8254551789fSSean Paul 	return 0;
8264551789fSSean Paul }
8274551789fSSean Paul 
8284551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx)
8294551789fSSean Paul {
8304551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
8314551789fSSean Paul 	struct resource *res;
8324551789fSSean Paul 
833524c59f1SAndrzej Hajda 	mixer_ctx->vp = devm_clk_get(dev, "vp");
834524c59f1SAndrzej Hajda 	if (IS_ERR(mixer_ctx->vp)) {
8354551789fSSean Paul 		dev_err(dev, "failed to get clock 'vp'\n");
8364551789fSSean Paul 		return -ENODEV;
8374551789fSSean Paul 	}
838ff830c96SMarek Szyprowski 
839adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_HAS_SCLK, &mixer_ctx->flags)) {
840524c59f1SAndrzej Hajda 		mixer_ctx->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
841524c59f1SAndrzej Hajda 		if (IS_ERR(mixer_ctx->sclk_mixer)) {
8424551789fSSean Paul 			dev_err(dev, "failed to get clock 'sclk_mixer'\n");
8434551789fSSean Paul 			return -ENODEV;
8444551789fSSean Paul 		}
845524c59f1SAndrzej Hajda 		mixer_ctx->mout_mixer = devm_clk_get(dev, "mout_mixer");
846524c59f1SAndrzej Hajda 		if (IS_ERR(mixer_ctx->mout_mixer)) {
847ff830c96SMarek Szyprowski 			dev_err(dev, "failed to get clock 'mout_mixer'\n");
8484551789fSSean Paul 			return -ENODEV;
8494551789fSSean Paul 		}
8504551789fSSean Paul 
851524c59f1SAndrzej Hajda 		if (mixer_ctx->sclk_hdmi && mixer_ctx->mout_mixer)
852524c59f1SAndrzej Hajda 			clk_set_parent(mixer_ctx->mout_mixer,
853524c59f1SAndrzej Hajda 				       mixer_ctx->sclk_hdmi);
854ff830c96SMarek Szyprowski 	}
8554551789fSSean Paul 
8564551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
8574551789fSSean Paul 	if (res == NULL) {
8584551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8594551789fSSean Paul 		return -ENXIO;
8604551789fSSean Paul 	}
8614551789fSSean Paul 
862524c59f1SAndrzej Hajda 	mixer_ctx->vp_regs = devm_ioremap(dev, res->start,
8634551789fSSean Paul 							resource_size(res));
864524c59f1SAndrzej Hajda 	if (mixer_ctx->vp_regs == NULL) {
8654551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8664551789fSSean Paul 		return -ENXIO;
8674551789fSSean Paul 	}
8684551789fSSean Paul 
8694551789fSSean Paul 	return 0;
8704551789fSSean Paul }
8714551789fSSean Paul 
87293bca243SGustavo Padovan static int mixer_initialize(struct mixer_context *mixer_ctx,
873f37cd5e8SInki Dae 			struct drm_device *drm_dev)
8744551789fSSean Paul {
8754551789fSSean Paul 	int ret;
8764551789fSSean Paul 
877eb88e422SGustavo Padovan 	mixer_ctx->drm_dev = drm_dev;
8784551789fSSean Paul 
8794551789fSSean Paul 	/* acquire resources: regs, irqs, clocks */
8804551789fSSean Paul 	ret = mixer_resources_init(mixer_ctx);
8814551789fSSean Paul 	if (ret) {
8826f83d208SInki Dae 		DRM_DEV_ERROR(mixer_ctx->dev,
8836f83d208SInki Dae 			      "mixer_resources_init failed ret=%d\n", ret);
8844551789fSSean Paul 		return ret;
8854551789fSSean Paul 	}
8864551789fSSean Paul 
887adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &mixer_ctx->flags)) {
8884551789fSSean Paul 		/* acquire vp resources: regs, irqs, clocks */
8894551789fSSean Paul 		ret = vp_resources_init(mixer_ctx);
8904551789fSSean Paul 		if (ret) {
8916f83d208SInki Dae 			DRM_DEV_ERROR(mixer_ctx->dev,
8926f83d208SInki Dae 				      "vp_resources_init failed ret=%d\n", ret);
8934551789fSSean Paul 			return ret;
8944551789fSSean Paul 		}
8954551789fSSean Paul 	}
8964551789fSSean Paul 
89729cbf24aSAndrzej Hajda 	return exynos_drm_register_dma(drm_dev, mixer_ctx->dev);
8981055b39fSInki Dae }
8991055b39fSInki Dae 
90093bca243SGustavo Padovan static void mixer_ctx_remove(struct mixer_context *mixer_ctx)
901d8408326SSeung-Woo Kim {
90223755696SAndrzej Hajda 	exynos_drm_unregister_dma(mixer_ctx->drm_dev, mixer_ctx->dev);
903f041b257SSean Paul }
904f041b257SSean Paul 
90593bca243SGustavo Padovan static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)
906f041b257SSean Paul {
90793bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
908d8408326SSeung-Woo Kim 
9090df5e4acSAndrzej Hajda 	__set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9100df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
911f041b257SSean Paul 		return 0;
912d8408326SSeung-Woo Kim 
913d8408326SSeung-Woo Kim 	/* enable 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 	return 0;
918d8408326SSeung-Woo Kim }
919d8408326SSeung-Woo Kim 
92093bca243SGustavo Padovan static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
921d8408326SSeung-Woo Kim {
92293bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
923d8408326SSeung-Woo Kim 
9240df5e4acSAndrzej Hajda 	__clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9250df5e4acSAndrzej Hajda 
9260df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
927947710c6SAndrzej Hajda 		return;
928947710c6SAndrzej Hajda 
929d8408326SSeung-Woo Kim 	/* disable vsync interrupt */
930524c59f1SAndrzej Hajda 	mixer_reg_writemask(mixer_ctx, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
931524c59f1SAndrzej Hajda 	mixer_reg_writemask(mixer_ctx, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
932d8408326SSeung-Woo Kim }
933d8408326SSeung-Woo Kim 
9343dbaab16SMarek Szyprowski static void mixer_atomic_begin(struct exynos_drm_crtc *crtc)
9353dbaab16SMarek Szyprowski {
9366a3b45adSAndrzej Hajda 	struct mixer_context *ctx = crtc->ctx;
9373dbaab16SMarek Szyprowski 
9386a3b45adSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
9393dbaab16SMarek Szyprowski 		return;
9403dbaab16SMarek Szyprowski 
9416a3b45adSAndrzej Hajda 	if (mixer_wait_for_sync(ctx))
9426a3b45adSAndrzej Hajda 		dev_err(ctx->dev, "timeout waiting for VSYNC\n");
9436a3b45adSAndrzej Hajda 	mixer_disable_sync(ctx);
9443dbaab16SMarek Szyprowski }
9453dbaab16SMarek Szyprowski 
9461e1d1393SGustavo Padovan static void mixer_update_plane(struct exynos_drm_crtc *crtc,
9471e1d1393SGustavo Padovan 			       struct exynos_drm_plane *plane)
948d8408326SSeung-Woo Kim {
94993bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
950d8408326SSeung-Woo Kim 
9516be90056SInki Dae 	DRM_DEV_DEBUG_KMS(mixer_ctx->dev, "win: %d\n", plane->index);
952d8408326SSeung-Woo Kim 
953a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
954dda9012bSShirish S 		return;
955dda9012bSShirish S 
9565e68fef2SMarek Szyprowski 	if (plane->index == VP_DEFAULT_WIN)
9572eeb2e5eSGustavo Padovan 		vp_video_buffer(mixer_ctx, plane);
958d8408326SSeung-Woo Kim 	else
9592eeb2e5eSGustavo Padovan 		mixer_graph_buffer(mixer_ctx, plane);
960d8408326SSeung-Woo Kim }
961d8408326SSeung-Woo Kim 
9621e1d1393SGustavo Padovan static void mixer_disable_plane(struct exynos_drm_crtc *crtc,
9631e1d1393SGustavo Padovan 				struct exynos_drm_plane *plane)
964d8408326SSeung-Woo Kim {
96593bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
966d8408326SSeung-Woo Kim 	unsigned long flags;
967d8408326SSeung-Woo Kim 
9686be90056SInki Dae 	DRM_DEV_DEBUG_KMS(mixer_ctx->dev, "win: %d\n", plane->index);
969d8408326SSeung-Woo Kim 
970a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
971db43fd16SPrathyush K 		return;
972db43fd16SPrathyush K 
973524c59f1SAndrzej Hajda 	spin_lock_irqsave(&mixer_ctx->reg_slock, flags);
974a2cb911eSMarek Szyprowski 	mixer_cfg_layer(mixer_ctx, plane->index, 0, false);
975524c59f1SAndrzej Hajda 	spin_unlock_irqrestore(&mixer_ctx->reg_slock, flags);
9763dbaab16SMarek Szyprowski }
9773dbaab16SMarek Szyprowski 
9783dbaab16SMarek Szyprowski static void mixer_atomic_flush(struct exynos_drm_crtc *crtc)
9793dbaab16SMarek Szyprowski {
9803dbaab16SMarek Szyprowski 	struct mixer_context *mixer_ctx = crtc->ctx;
9813dbaab16SMarek Szyprowski 
9823dbaab16SMarek Szyprowski 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
9833dbaab16SMarek Szyprowski 		return;
984d8408326SSeung-Woo Kim 
9856a3b45adSAndrzej Hajda 	mixer_enable_sync(mixer_ctx);
986a392276dSAndrzej Hajda 	exynos_crtc_handle_event(crtc);
987d8408326SSeung-Woo Kim }
988d8408326SSeung-Woo Kim 
989*11f95489SInki Dae static void mixer_atomic_enable(struct exynos_drm_crtc *crtc)
990db43fd16SPrathyush K {
9913cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
992db43fd16SPrathyush K 
993a44652e8SAndrzej Hajda 	if (test_bit(MXR_BIT_POWERED, &ctx->flags))
994db43fd16SPrathyush K 		return;
995db43fd16SPrathyush K 
996af65c804SSean Paul 	pm_runtime_get_sync(ctx->dev);
997af65c804SSean Paul 
998a121d179SAndrzej Hajda 	exynos_drm_pipe_clk_enable(crtc, true);
999a121d179SAndrzej Hajda 
10006a3b45adSAndrzej Hajda 	mixer_disable_sync(ctx);
10013dbaab16SMarek Szyprowski 
1002524c59f1SAndrzej Hajda 	mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
1003d74ed937SRahul Sharma 
10040df5e4acSAndrzej Hajda 	if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) {
1005524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_INT_STATUS, ~0,
1006524c59f1SAndrzej Hajda 					MXR_INT_CLEAR_VSYNC);
1007524c59f1SAndrzej Hajda 		mixer_reg_writemask(ctx, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
10080df5e4acSAndrzej Hajda 	}
1009db43fd16SPrathyush K 	mixer_win_reset(ctx);
1010ccf034a9SGustavo Padovan 
101171469944SAndrzej Hajda 	mixer_commit(ctx);
101271469944SAndrzej Hajda 
10136a3b45adSAndrzej Hajda 	mixer_enable_sync(ctx);
10143dbaab16SMarek Szyprowski 
1015ccf034a9SGustavo Padovan 	set_bit(MXR_BIT_POWERED, &ctx->flags);
1016db43fd16SPrathyush K }
1017db43fd16SPrathyush K 
1018*11f95489SInki Dae static void mixer_atomic_disable(struct exynos_drm_crtc *crtc)
1019db43fd16SPrathyush K {
10203cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
1021c329f667SJoonyoung Shim 	int i;
1022db43fd16SPrathyush K 
1023a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
1024b4bfa3c7SRahul Sharma 		return;
1025db43fd16SPrathyush K 
1026381be025SRahul Sharma 	mixer_stop(ctx);
1027c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
1028c329f667SJoonyoung Shim 
1029c329f667SJoonyoung Shim 	for (i = 0; i < MIXER_WIN_NR; i++)
10301e1d1393SGustavo Padovan 		mixer_disable_plane(crtc, &ctx->planes[i]);
1031db43fd16SPrathyush K 
1032a121d179SAndrzej Hajda 	exynos_drm_pipe_clk_enable(crtc, false);
1033a121d179SAndrzej Hajda 
1034ccf034a9SGustavo Padovan 	pm_runtime_put(ctx->dev);
1035ccf034a9SGustavo Padovan 
1036a44652e8SAndrzej Hajda 	clear_bit(MXR_BIT_POWERED, &ctx->flags);
1037db43fd16SPrathyush K }
1038db43fd16SPrathyush K 
10396ace38a5SAndrzej Hajda static int mixer_mode_valid(struct exynos_drm_crtc *crtc,
10406ace38a5SAndrzej Hajda 		const struct drm_display_mode *mode)
1041f041b257SSean Paul {
10426ace38a5SAndrzej Hajda 	struct mixer_context *ctx = crtc->ctx;
10436ace38a5SAndrzej Hajda 	u32 w = mode->hdisplay, h = mode->vdisplay;
1044f041b257SSean Paul 
10456be90056SInki Dae 	DRM_DEV_DEBUG_KMS(ctx->dev, "xres=%d, yres=%d, refresh=%d, intl=%d\n",
10466be90056SInki Dae 			  w, h, mode->vrefresh,
10476be90056SInki Dae 			  !!(mode->flags & DRM_MODE_FLAG_INTERLACE));
1048f041b257SSean Paul 
10496ace38a5SAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_128_0_0_184)
10506ace38a5SAndrzej Hajda 		return MODE_OK;
1051f041b257SSean Paul 
1052f041b257SSean Paul 	if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
1053f041b257SSean Paul 	    (w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
1054f041b257SSean Paul 	    (w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
10556ace38a5SAndrzej Hajda 		return MODE_OK;
1056f041b257SSean Paul 
1057ae58c03eSDaniel Drake 	if ((w == 1024 && h == 768) ||
1058ae58c03eSDaniel Drake 	    (w == 1366 && h == 768) ||
1059ae58c03eSDaniel Drake 	    (w == 1280 && h == 1024))
10600900673eSAndrzej Hajda 		return MODE_OK;
10610900673eSAndrzej Hajda 
10626ace38a5SAndrzej Hajda 	return MODE_BAD;
1063f041b257SSean Paul }
1064f041b257SSean Paul 
1065acc8bf04SAndrzej Hajda static bool mixer_mode_fixup(struct exynos_drm_crtc *crtc,
1066acc8bf04SAndrzej Hajda 		   const struct drm_display_mode *mode,
1067acc8bf04SAndrzej Hajda 		   struct drm_display_mode *adjusted_mode)
1068acc8bf04SAndrzej Hajda {
1069acc8bf04SAndrzej Hajda 	struct mixer_context *ctx = crtc->ctx;
1070acc8bf04SAndrzej Hajda 	int width = mode->hdisplay, height = mode->vdisplay, i;
1071acc8bf04SAndrzej Hajda 
10725a884be5SKrzysztof Wilczynski 	static const struct {
1073acc8bf04SAndrzej Hajda 		int hdisplay, vdisplay, htotal, vtotal, scan_val;
10745a884be5SKrzysztof Wilczynski 	} modes[] = {
1075acc8bf04SAndrzej Hajda 		{ 720, 480, 858, 525, MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD },
1076acc8bf04SAndrzej Hajda 		{ 720, 576, 864, 625, MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD },
1077acc8bf04SAndrzej Hajda 		{ 1280, 720, 1650, 750, MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD },
1078acc8bf04SAndrzej Hajda 		{ 1920, 1080, 2200, 1125, MXR_CFG_SCAN_HD_1080 |
1079acc8bf04SAndrzej Hajda 						MXR_CFG_SCAN_HD }
1080acc8bf04SAndrzej Hajda 	};
1081acc8bf04SAndrzej Hajda 
1082acc8bf04SAndrzej Hajda 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1083acc8bf04SAndrzej Hajda 		__set_bit(MXR_BIT_INTERLACE, &ctx->flags);
1084acc8bf04SAndrzej Hajda 	else
1085acc8bf04SAndrzej Hajda 		__clear_bit(MXR_BIT_INTERLACE, &ctx->flags);
1086acc8bf04SAndrzej Hajda 
1087acc8bf04SAndrzej Hajda 	if (ctx->mxr_ver == MXR_VER_128_0_0_184)
1088acc8bf04SAndrzej Hajda 		return true;
1089acc8bf04SAndrzej Hajda 
1090acc8bf04SAndrzej Hajda 	for (i = 0; i < ARRAY_SIZE(modes); ++i)
1091acc8bf04SAndrzej Hajda 		if (width <= modes[i].hdisplay && height <= modes[i].vdisplay) {
1092acc8bf04SAndrzej Hajda 			ctx->scan_value = modes[i].scan_val;
1093acc8bf04SAndrzej Hajda 			if (width < modes[i].hdisplay ||
1094acc8bf04SAndrzej Hajda 			    height < modes[i].vdisplay) {
1095acc8bf04SAndrzej Hajda 				adjusted_mode->hdisplay = modes[i].hdisplay;
1096acc8bf04SAndrzej Hajda 				adjusted_mode->hsync_start = modes[i].hdisplay;
1097acc8bf04SAndrzej Hajda 				adjusted_mode->hsync_end = modes[i].htotal;
1098acc8bf04SAndrzej Hajda 				adjusted_mode->htotal = modes[i].htotal;
1099acc8bf04SAndrzej Hajda 				adjusted_mode->vdisplay = modes[i].vdisplay;
1100acc8bf04SAndrzej Hajda 				adjusted_mode->vsync_start = modes[i].vdisplay;
1101acc8bf04SAndrzej Hajda 				adjusted_mode->vsync_end = modes[i].vtotal;
1102acc8bf04SAndrzej Hajda 				adjusted_mode->vtotal = modes[i].vtotal;
1103acc8bf04SAndrzej Hajda 			}
1104acc8bf04SAndrzej Hajda 
1105acc8bf04SAndrzej Hajda 			return true;
1106acc8bf04SAndrzej Hajda 		}
1107acc8bf04SAndrzej Hajda 
1108acc8bf04SAndrzej Hajda 	return false;
1109acc8bf04SAndrzej Hajda }
1110acc8bf04SAndrzej Hajda 
1111f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops mixer_crtc_ops = {
1112*11f95489SInki Dae 	.atomic_enable		= mixer_atomic_enable,
1113*11f95489SInki Dae 	.atomic_disable		= mixer_atomic_disable,
1114d8408326SSeung-Woo Kim 	.enable_vblank		= mixer_enable_vblank,
1115d8408326SSeung-Woo Kim 	.disable_vblank		= mixer_disable_vblank,
11163dbaab16SMarek Szyprowski 	.atomic_begin		= mixer_atomic_begin,
11179cc7610aSGustavo Padovan 	.update_plane		= mixer_update_plane,
11189cc7610aSGustavo Padovan 	.disable_plane		= mixer_disable_plane,
11193dbaab16SMarek Szyprowski 	.atomic_flush		= mixer_atomic_flush,
11206ace38a5SAndrzej Hajda 	.mode_valid		= mixer_mode_valid,
1121acc8bf04SAndrzej Hajda 	.mode_fixup		= mixer_mode_fixup,
1122f041b257SSean Paul };
11230ea6822fSRahul Sharma 
11245e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos5420_mxr_drv_data = {
1125def5e095SRahul Sharma 	.version = MXR_VER_128_0_0_184,
1126def5e095SRahul Sharma 	.is_vp_enabled = 0,
1127def5e095SRahul Sharma };
1128def5e095SRahul Sharma 
11295e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos5250_mxr_drv_data = {
1130aaf8b49eSRahul Sharma 	.version = MXR_VER_16_0_33_0,
1131aaf8b49eSRahul Sharma 	.is_vp_enabled = 0,
1132aaf8b49eSRahul Sharma };
1133aaf8b49eSRahul Sharma 
11345e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos4212_mxr_drv_data = {
1135ff830c96SMarek Szyprowski 	.version = MXR_VER_0_0_0_16,
1136ff830c96SMarek Szyprowski 	.is_vp_enabled = 1,
1137ff830c96SMarek Szyprowski };
1138ff830c96SMarek Szyprowski 
11395e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos4210_mxr_drv_data = {
11401e123441SRahul Sharma 	.version = MXR_VER_0_0_0_16,
11411b8e5747SRahul Sharma 	.is_vp_enabled = 1,
1142ff830c96SMarek Szyprowski 	.has_sclk = 1,
11431e123441SRahul Sharma };
11441e123441SRahul Sharma 
11455e6cc1c5SArvind Yadav static const struct of_device_id mixer_match_types[] = {
1146aaf8b49eSRahul Sharma 	{
1147ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4210-mixer",
1148ff830c96SMarek Szyprowski 		.data	= &exynos4210_mxr_drv_data,
1149ff830c96SMarek Szyprowski 	}, {
1150ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4212-mixer",
1151ff830c96SMarek Szyprowski 		.data	= &exynos4212_mxr_drv_data,
1152ff830c96SMarek Szyprowski 	}, {
1153aaf8b49eSRahul Sharma 		.compatible = "samsung,exynos5-mixer",
1154cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1155cc57caf0SRahul Sharma 	}, {
1156cc57caf0SRahul Sharma 		.compatible = "samsung,exynos5250-mixer",
1157cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1158aaf8b49eSRahul Sharma 	}, {
1159def5e095SRahul Sharma 		.compatible = "samsung,exynos5420-mixer",
1160def5e095SRahul Sharma 		.data	= &exynos5420_mxr_drv_data,
1161def5e095SRahul Sharma 	}, {
11621e123441SRahul Sharma 		/* end node */
11631e123441SRahul Sharma 	}
11641e123441SRahul Sharma };
116539b58a39SSjoerd Simons MODULE_DEVICE_TABLE(of, mixer_match_types);
11661e123441SRahul Sharma 
1167f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data)
1168d8408326SSeung-Woo Kim {
11698103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
1170f37cd5e8SInki Dae 	struct drm_device *drm_dev = data;
11717ee14cdcSGustavo Padovan 	struct exynos_drm_plane *exynos_plane;
1172fd2d2fc2SMarek Szyprowski 	unsigned int i;
11736e2a3b66SGustavo Padovan 	int ret;
1174d8408326SSeung-Woo Kim 
1175e2dc3f72SAlban Browaeys 	ret = mixer_initialize(ctx, drm_dev);
1176e2dc3f72SAlban Browaeys 	if (ret)
1177e2dc3f72SAlban Browaeys 		return ret;
1178e2dc3f72SAlban Browaeys 
1179fd2d2fc2SMarek Szyprowski 	for (i = 0; i < MIXER_WIN_NR; i++) {
1180adeb6f44STobias Jakobi 		if (i == VP_DEFAULT_WIN && !test_bit(MXR_BIT_VP_ENABLED,
1181adeb6f44STobias Jakobi 						     &ctx->flags))
1182ab144201SMarek Szyprowski 			continue;
1183ab144201SMarek Szyprowski 
118440bdfb0aSMarek Szyprowski 		ret = exynos_plane_init(drm_dev, &ctx->planes[i], i,
11852c82607bSAndrzej Hajda 					&plane_configs[i]);
11867ee14cdcSGustavo Padovan 		if (ret)
11877ee14cdcSGustavo Padovan 			return ret;
11887ee14cdcSGustavo Padovan 	}
11897ee14cdcSGustavo Padovan 
11905d3d0995SGustavo Padovan 	exynos_plane = &ctx->planes[DEFAULT_WIN];
11917ee14cdcSGustavo Padovan 	ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
1192d644951cSAndrzej Hajda 			EXYNOS_DISPLAY_TYPE_HDMI, &mixer_crtc_ops, ctx);
119393bca243SGustavo Padovan 	if (IS_ERR(ctx->crtc)) {
1194e2dc3f72SAlban Browaeys 		mixer_ctx_remove(ctx);
119593bca243SGustavo Padovan 		ret = PTR_ERR(ctx->crtc);
119693bca243SGustavo Padovan 		goto free_ctx;
11978103ef1bSAndrzej Hajda 	}
11988103ef1bSAndrzej Hajda 
11998103ef1bSAndrzej Hajda 	return 0;
120093bca243SGustavo Padovan 
120193bca243SGustavo Padovan free_ctx:
120293bca243SGustavo Padovan 	devm_kfree(dev, ctx);
120393bca243SGustavo Padovan 	return ret;
12048103ef1bSAndrzej Hajda }
12058103ef1bSAndrzej Hajda 
12068103ef1bSAndrzej Hajda static void mixer_unbind(struct device *dev, struct device *master, void *data)
12078103ef1bSAndrzej Hajda {
12088103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
12098103ef1bSAndrzej Hajda 
121093bca243SGustavo Padovan 	mixer_ctx_remove(ctx);
12118103ef1bSAndrzej Hajda }
12128103ef1bSAndrzej Hajda 
12138103ef1bSAndrzej Hajda static const struct component_ops mixer_component_ops = {
12148103ef1bSAndrzej Hajda 	.bind	= mixer_bind,
12158103ef1bSAndrzej Hajda 	.unbind	= mixer_unbind,
12168103ef1bSAndrzej Hajda };
12178103ef1bSAndrzej Hajda 
12188103ef1bSAndrzej Hajda static int mixer_probe(struct platform_device *pdev)
12198103ef1bSAndrzej Hajda {
12208103ef1bSAndrzej Hajda 	struct device *dev = &pdev->dev;
122148f6155aSMarek Szyprowski 	const struct mixer_drv_data *drv;
12228103ef1bSAndrzej Hajda 	struct mixer_context *ctx;
12238103ef1bSAndrzej Hajda 	int ret;
1224d8408326SSeung-Woo Kim 
1225f041b257SSean Paul 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1226f041b257SSean Paul 	if (!ctx) {
12276f83d208SInki Dae 		DRM_DEV_ERROR(dev, "failed to alloc mixer context.\n");
1228d8408326SSeung-Woo Kim 		return -ENOMEM;
1229f041b257SSean Paul 	}
1230d8408326SSeung-Woo Kim 
123148f6155aSMarek Szyprowski 	drv = of_device_get_match_data(dev);
1232aaf8b49eSRahul Sharma 
12334551789fSSean Paul 	ctx->pdev = pdev;
1234d873ab99SSeung-Woo Kim 	ctx->dev = dev;
12351e123441SRahul Sharma 	ctx->mxr_ver = drv->version;
1236d8408326SSeung-Woo Kim 
1237adeb6f44STobias Jakobi 	if (drv->is_vp_enabled)
1238adeb6f44STobias Jakobi 		__set_bit(MXR_BIT_VP_ENABLED, &ctx->flags);
1239adeb6f44STobias Jakobi 	if (drv->has_sclk)
1240adeb6f44STobias Jakobi 		__set_bit(MXR_BIT_HAS_SCLK, &ctx->flags);
1241adeb6f44STobias Jakobi 
12428103ef1bSAndrzej Hajda 	platform_set_drvdata(pdev, ctx);
1243df5225bcSInki Dae 
1244df5225bcSInki Dae 	ret = component_add(&pdev->dev, &mixer_component_ops);
124586650408SAndrzej Hajda 	if (!ret)
12468103ef1bSAndrzej Hajda 		pm_runtime_enable(dev);
1247df5225bcSInki Dae 
1248df5225bcSInki Dae 	return ret;
1249f37cd5e8SInki Dae }
1250f37cd5e8SInki Dae 
1251d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev)
1252d8408326SSeung-Woo Kim {
12538103ef1bSAndrzej Hajda 	pm_runtime_disable(&pdev->dev);
12548103ef1bSAndrzej Hajda 
1255df5225bcSInki Dae 	component_del(&pdev->dev, &mixer_component_ops);
1256df5225bcSInki Dae 
1257d8408326SSeung-Woo Kim 	return 0;
1258d8408326SSeung-Woo Kim }
1259d8408326SSeung-Woo Kim 
1260e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_suspend(struct device *dev)
1261ccf034a9SGustavo Padovan {
1262ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1263ccf034a9SGustavo Padovan 
1264524c59f1SAndrzej Hajda 	clk_disable_unprepare(ctx->hdmi);
1265524c59f1SAndrzej Hajda 	clk_disable_unprepare(ctx->mixer);
1266adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
1267524c59f1SAndrzej Hajda 		clk_disable_unprepare(ctx->vp);
1268adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags))
1269524c59f1SAndrzej Hajda 			clk_disable_unprepare(ctx->sclk_mixer);
1270ccf034a9SGustavo Padovan 	}
1271ccf034a9SGustavo Padovan 
1272ccf034a9SGustavo Padovan 	return 0;
1273ccf034a9SGustavo Padovan }
1274ccf034a9SGustavo Padovan 
1275e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_resume(struct device *dev)
1276ccf034a9SGustavo Padovan {
1277ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1278ccf034a9SGustavo Padovan 	int ret;
1279ccf034a9SGustavo Padovan 
1280524c59f1SAndrzej Hajda 	ret = clk_prepare_enable(ctx->mixer);
1281ccf034a9SGustavo Padovan 	if (ret < 0) {
12826f83d208SInki Dae 		DRM_DEV_ERROR(ctx->dev,
12836f83d208SInki Dae 			      "Failed to prepare_enable the mixer clk [%d]\n",
12846f83d208SInki Dae 			      ret);
1285ccf034a9SGustavo Padovan 		return ret;
1286ccf034a9SGustavo Padovan 	}
1287524c59f1SAndrzej Hajda 	ret = clk_prepare_enable(ctx->hdmi);
1288ccf034a9SGustavo Padovan 	if (ret < 0) {
12896f83d208SInki Dae 		DRM_DEV_ERROR(dev,
12906f83d208SInki Dae 			      "Failed to prepare_enable the hdmi clk [%d]\n",
12916f83d208SInki Dae 			      ret);
1292ccf034a9SGustavo Padovan 		return ret;
1293ccf034a9SGustavo Padovan 	}
1294adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
1295524c59f1SAndrzej Hajda 		ret = clk_prepare_enable(ctx->vp);
1296ccf034a9SGustavo Padovan 		if (ret < 0) {
12976f83d208SInki Dae 			DRM_DEV_ERROR(dev,
12986f83d208SInki Dae 				      "Failed to prepare_enable the vp clk [%d]\n",
1299ccf034a9SGustavo Padovan 				      ret);
1300ccf034a9SGustavo Padovan 			return ret;
1301ccf034a9SGustavo Padovan 		}
1302adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags)) {
1303524c59f1SAndrzej Hajda 			ret = clk_prepare_enable(ctx->sclk_mixer);
1304ccf034a9SGustavo Padovan 			if (ret < 0) {
13056f83d208SInki Dae 				DRM_DEV_ERROR(dev,
13066f83d208SInki Dae 					   "Failed to prepare_enable the " \
1307ccf034a9SGustavo Padovan 					   "sclk_mixer clk [%d]\n",
1308ccf034a9SGustavo Padovan 					   ret);
1309ccf034a9SGustavo Padovan 				return ret;
1310ccf034a9SGustavo Padovan 			}
1311ccf034a9SGustavo Padovan 		}
1312ccf034a9SGustavo Padovan 	}
1313ccf034a9SGustavo Padovan 
1314ccf034a9SGustavo Padovan 	return 0;
1315ccf034a9SGustavo Padovan }
1316ccf034a9SGustavo Padovan 
1317ccf034a9SGustavo Padovan static const struct dev_pm_ops exynos_mixer_pm_ops = {
1318ccf034a9SGustavo Padovan 	SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL)
13197e915746SMarek Szyprowski 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
13207e915746SMarek Szyprowski 				pm_runtime_force_resume)
1321ccf034a9SGustavo Padovan };
1322ccf034a9SGustavo Padovan 
1323d8408326SSeung-Woo Kim struct platform_driver mixer_driver = {
1324d8408326SSeung-Woo Kim 	.driver = {
1325aaf8b49eSRahul Sharma 		.name = "exynos-mixer",
1326d8408326SSeung-Woo Kim 		.owner = THIS_MODULE,
1327ccf034a9SGustavo Padovan 		.pm = &exynos_mixer_pm_ops,
1328aaf8b49eSRahul Sharma 		.of_match_table = mixer_match_types,
1329d8408326SSeung-Woo Kim 	},
1330d8408326SSeung-Woo Kim 	.probe = mixer_probe,
133156550d94SGreg Kroah-Hartman 	.remove = mixer_remove,
1332d8408326SSeung-Woo Kim };
1333