xref: /linux/drivers/gpu/drm/exynos/exynos_mixer.c (revision 272725c7db4da1fd3229d944fc76d2e98e3a144e)
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 
487a57ca7cSTobias Jakobi /* The pixelformats that are natively supported by the mixer. */
497a57ca7cSTobias Jakobi #define MXR_FORMAT_RGB565	4
507a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB1555	5
517a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB4444	6
527a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB8888	7
537a57ca7cSTobias Jakobi 
5422b21ae6SJoonyoung Shim struct mixer_resources {
5522b21ae6SJoonyoung Shim 	int			irq;
5622b21ae6SJoonyoung Shim 	void __iomem		*mixer_regs;
5722b21ae6SJoonyoung Shim 	void __iomem		*vp_regs;
5822b21ae6SJoonyoung Shim 	spinlock_t		reg_slock;
5922b21ae6SJoonyoung Shim 	struct clk		*mixer;
6022b21ae6SJoonyoung Shim 	struct clk		*vp;
6104427ec5SMarek Szyprowski 	struct clk		*hdmi;
6222b21ae6SJoonyoung Shim 	struct clk		*sclk_mixer;
6322b21ae6SJoonyoung Shim 	struct clk		*sclk_hdmi;
64ff830c96SMarek Szyprowski 	struct clk		*mout_mixer;
6522b21ae6SJoonyoung Shim };
6622b21ae6SJoonyoung Shim 
671e123441SRahul Sharma enum mixer_version_id {
681e123441SRahul Sharma 	MXR_VER_0_0_0_16,
691e123441SRahul Sharma 	MXR_VER_16_0_33_0,
70def5e095SRahul Sharma 	MXR_VER_128_0_0_184,
711e123441SRahul Sharma };
721e123441SRahul Sharma 
73a44652e8SAndrzej Hajda enum mixer_flag_bits {
74a44652e8SAndrzej Hajda 	MXR_BIT_POWERED,
750df5e4acSAndrzej Hajda 	MXR_BIT_VSYNC,
76adeb6f44STobias Jakobi 	MXR_BIT_INTERLACE,
77adeb6f44STobias Jakobi 	MXR_BIT_VP_ENABLED,
78adeb6f44STobias Jakobi 	MXR_BIT_HAS_SCLK,
79a44652e8SAndrzej Hajda };
80a44652e8SAndrzej Hajda 
81fbbb1e1aSMarek Szyprowski static const uint32_t mixer_formats[] = {
82fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB4444,
8326a7af3eSTobias Jakobi 	DRM_FORMAT_ARGB4444,
84fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB1555,
8526a7af3eSTobias Jakobi 	DRM_FORMAT_ARGB1555,
86fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_RGB565,
87fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_XRGB8888,
88fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_ARGB8888,
89fbbb1e1aSMarek Szyprowski };
90fbbb1e1aSMarek Szyprowski 
91fbbb1e1aSMarek Szyprowski static const uint32_t vp_formats[] = {
92fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_NV12,
93fbbb1e1aSMarek Szyprowski 	DRM_FORMAT_NV21,
94fbbb1e1aSMarek Szyprowski };
95fbbb1e1aSMarek Szyprowski 
9622b21ae6SJoonyoung Shim struct mixer_context {
974551789fSSean Paul 	struct platform_device *pdev;
98cf8fc4f1SJoonyoung Shim 	struct device		*dev;
991055b39fSInki Dae 	struct drm_device	*drm_dev;
10093bca243SGustavo Padovan 	struct exynos_drm_crtc	*crtc;
1017ee14cdcSGustavo Padovan 	struct exynos_drm_plane	planes[MIXER_WIN_NR];
10222b21ae6SJoonyoung Shim 	int			pipe;
103a44652e8SAndrzej Hajda 	unsigned long		flags;
10422b21ae6SJoonyoung Shim 
10522b21ae6SJoonyoung Shim 	struct mixer_resources	mixer_res;
1061e123441SRahul Sharma 	enum mixer_version_id	mxr_ver;
1071e123441SRahul Sharma };
1081e123441SRahul Sharma 
1091e123441SRahul Sharma struct mixer_drv_data {
1101e123441SRahul Sharma 	enum mixer_version_id	version;
1111b8e5747SRahul Sharma 	bool					is_vp_enabled;
112ff830c96SMarek Szyprowski 	bool					has_sclk;
11322b21ae6SJoonyoung Shim };
11422b21ae6SJoonyoung Shim 
115fd2d2fc2SMarek Szyprowski static const struct exynos_drm_plane_config plane_configs[MIXER_WIN_NR] = {
116fd2d2fc2SMarek Szyprowski 	{
117fd2d2fc2SMarek Szyprowski 		.zpos = 0,
118fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_PRIMARY,
119fd2d2fc2SMarek Szyprowski 		.pixel_formats = mixer_formats,
120fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(mixer_formats),
121a2cb911eSMarek Szyprowski 		.capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
122a2cb911eSMarek Szyprowski 				EXYNOS_DRM_PLANE_CAP_ZPOS,
123fd2d2fc2SMarek Szyprowski 	}, {
124fd2d2fc2SMarek Szyprowski 		.zpos = 1,
125fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_CURSOR,
126fd2d2fc2SMarek Szyprowski 		.pixel_formats = mixer_formats,
127fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(mixer_formats),
128a2cb911eSMarek Szyprowski 		.capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
129a2cb911eSMarek Szyprowski 				EXYNOS_DRM_PLANE_CAP_ZPOS,
130fd2d2fc2SMarek Szyprowski 	}, {
131fd2d2fc2SMarek Szyprowski 		.zpos = 2,
132fd2d2fc2SMarek Szyprowski 		.type = DRM_PLANE_TYPE_OVERLAY,
133fd2d2fc2SMarek Szyprowski 		.pixel_formats = vp_formats,
134fd2d2fc2SMarek Szyprowski 		.num_pixel_formats = ARRAY_SIZE(vp_formats),
135a2cb911eSMarek Szyprowski 		.capabilities = EXYNOS_DRM_PLANE_CAP_SCALE |
136a2cb911eSMarek Szyprowski 				EXYNOS_DRM_PLANE_CAP_ZPOS,
137fd2d2fc2SMarek Szyprowski 	},
138fd2d2fc2SMarek Szyprowski };
139fd2d2fc2SMarek Szyprowski 
140d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = {
141d8408326SSeung-Woo Kim 	0,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
142d8408326SSeung-Woo Kim 	-1,	-1,	-1,	-1,	-1,	0,	0,	0,
143d8408326SSeung-Woo Kim 	0,	2,	4,	5,	6,	6,	6,	6,
144d8408326SSeung-Woo Kim 	6,	5,	5,	4,	3,	2,	1,	1,
145d8408326SSeung-Woo Kim 	0,	-6,	-12,	-16,	-18,	-20,	-21,	-20,
146d8408326SSeung-Woo Kim 	-20,	-18,	-16,	-13,	-10,	-8,	-5,	-2,
147d8408326SSeung-Woo Kim 	127,	126,	125,	121,	114,	107,	99,	89,
148d8408326SSeung-Woo Kim 	79,	68,	57,	46,	35,	25,	16,	8,
149d8408326SSeung-Woo Kim };
150d8408326SSeung-Woo Kim 
151d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = {
152d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
153d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
154d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
155d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
156d8408326SSeung-Woo Kim 	0,	5,	11,	19,	27,	37,	48,	59,
157d8408326SSeung-Woo Kim 	70,	81,	92,	102,	111,	118,	124,	126,
158d8408326SSeung-Woo Kim 	0,	0,	-1,	-1,	-2,	-3,	-4,	-5,
159d8408326SSeung-Woo Kim 	-6,	-7,	-8,	-8,	-8,	-8,	-6,	-3,
160d8408326SSeung-Woo Kim };
161d8408326SSeung-Woo Kim 
162d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = {
163d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
164d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
165d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
166d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
167d8408326SSeung-Woo Kim };
168d8408326SSeung-Woo Kim 
169f657a996SMarek Szyprowski static inline bool is_alpha_format(unsigned int pixel_format)
170f657a996SMarek Szyprowski {
171f657a996SMarek Szyprowski 	switch (pixel_format) {
172f657a996SMarek Szyprowski 	case DRM_FORMAT_ARGB8888:
17326a7af3eSTobias Jakobi 	case DRM_FORMAT_ARGB1555:
17426a7af3eSTobias Jakobi 	case DRM_FORMAT_ARGB4444:
175f657a996SMarek Szyprowski 		return true;
176f657a996SMarek Szyprowski 	default:
177f657a996SMarek Szyprowski 		return false;
178f657a996SMarek Szyprowski 	}
179f657a996SMarek Szyprowski }
180f657a996SMarek Szyprowski 
181d8408326SSeung-Woo Kim static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id)
182d8408326SSeung-Woo Kim {
183d8408326SSeung-Woo Kim 	return readl(res->vp_regs + reg_id);
184d8408326SSeung-Woo Kim }
185d8408326SSeung-Woo Kim 
186d8408326SSeung-Woo Kim static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id,
187d8408326SSeung-Woo Kim 				 u32 val)
188d8408326SSeung-Woo Kim {
189d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
190d8408326SSeung-Woo Kim }
191d8408326SSeung-Woo Kim 
192d8408326SSeung-Woo Kim static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id,
193d8408326SSeung-Woo Kim 				 u32 val, u32 mask)
194d8408326SSeung-Woo Kim {
195d8408326SSeung-Woo Kim 	u32 old = vp_reg_read(res, reg_id);
196d8408326SSeung-Woo Kim 
197d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
198d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
199d8408326SSeung-Woo Kim }
200d8408326SSeung-Woo Kim 
201d8408326SSeung-Woo Kim static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id)
202d8408326SSeung-Woo Kim {
203d8408326SSeung-Woo Kim 	return readl(res->mixer_regs + reg_id);
204d8408326SSeung-Woo Kim }
205d8408326SSeung-Woo Kim 
206d8408326SSeung-Woo Kim static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id,
207d8408326SSeung-Woo Kim 				 u32 val)
208d8408326SSeung-Woo Kim {
209d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
210d8408326SSeung-Woo Kim }
211d8408326SSeung-Woo Kim 
212d8408326SSeung-Woo Kim static inline void mixer_reg_writemask(struct mixer_resources *res,
213d8408326SSeung-Woo Kim 				 u32 reg_id, u32 val, u32 mask)
214d8408326SSeung-Woo Kim {
215d8408326SSeung-Woo Kim 	u32 old = mixer_reg_read(res, reg_id);
216d8408326SSeung-Woo Kim 
217d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
218d8408326SSeung-Woo Kim 	writel(val, res->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 { \
225d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
226d8408326SSeung-Woo Kim 		(u32)readl(ctx->mixer_res.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 { \
257d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
258d8408326SSeung-Woo Kim 		(u32) readl(ctx->mixer_res.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 
288d8408326SSeung-Woo Kim static inline void vp_filter_set(struct mixer_resources *res,
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];
296d8408326SSeung-Woo Kim 		vp_reg_write(res, reg_id, val);
297d8408326SSeung-Woo Kim 	}
298d8408326SSeung-Woo Kim }
299d8408326SSeung-Woo Kim 
300d8408326SSeung-Woo Kim static void vp_default_filter(struct mixer_resources *res)
301d8408326SSeung-Woo Kim {
302d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY8_Y0_LL,
303e25e1b66SSachin Kamat 		filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
304d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_Y0_LL,
305e25e1b66SSachin Kamat 		filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
306d8408326SSeung-Woo Kim 	vp_filter_set(res, 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,
311f657a996SMarek Szyprowski 				bool alpha)
312f657a996SMarek Szyprowski {
313f657a996SMarek Szyprowski 	struct mixer_resources *res = &ctx->mixer_res;
314f657a996SMarek Szyprowski 	u32 val;
315f657a996SMarek Szyprowski 
316f657a996SMarek Szyprowski 	val  = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
317f657a996SMarek Szyprowski 	if (alpha) {
318f657a996SMarek Szyprowski 		/* blending based on pixel alpha */
319f657a996SMarek Szyprowski 		val |= MXR_GRP_CFG_BLEND_PRE_MUL;
320f657a996SMarek Szyprowski 		val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
321f657a996SMarek Szyprowski 	}
322f657a996SMarek Szyprowski 	mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
323f657a996SMarek Szyprowski 			    val, MXR_GRP_CFG_MISC_MASK);
324f657a996SMarek Szyprowski }
325f657a996SMarek Szyprowski 
326f657a996SMarek Szyprowski static void mixer_cfg_vp_blend(struct mixer_context *ctx)
327f657a996SMarek Szyprowski {
328f657a996SMarek Szyprowski 	struct mixer_resources *res = &ctx->mixer_res;
329f657a996SMarek Szyprowski 	u32 val;
330f657a996SMarek Szyprowski 
331f657a996SMarek Szyprowski 	/*
332f657a996SMarek Szyprowski 	 * No blending at the moment since the NV12/NV21 pixelformats don't
333f657a996SMarek Szyprowski 	 * have an alpha channel. However the mixer supports a global alpha
334f657a996SMarek Szyprowski 	 * value for a layer. Once this functionality is exposed, we can
335f657a996SMarek Szyprowski 	 * support blending of the video layer through this.
336f657a996SMarek Szyprowski 	 */
337f657a996SMarek Szyprowski 	val = 0;
338f657a996SMarek Szyprowski 	mixer_reg_write(res, MXR_VIDEO_CFG, val);
339f657a996SMarek Szyprowski }
340f657a996SMarek Szyprowski 
341d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable)
342d8408326SSeung-Woo Kim {
343d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
344d8408326SSeung-Woo Kim 
345d8408326SSeung-Woo Kim 	/* block update on vsync */
346d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, enable ?
347d8408326SSeung-Woo Kim 			MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE);
348d8408326SSeung-Woo Kim 
349adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
350d8408326SSeung-Woo Kim 		vp_reg_write(res, VP_SHADOW_UPDATE, enable ?
351d8408326SSeung-Woo Kim 			VP_SHADOW_UPDATE_ENABLE : 0);
352d8408326SSeung-Woo Kim }
353d8408326SSeung-Woo Kim 
354d8408326SSeung-Woo Kim static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height)
355d8408326SSeung-Woo Kim {
356d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
357d8408326SSeung-Woo Kim 	u32 val;
358d8408326SSeung-Woo Kim 
359d8408326SSeung-Woo Kim 	/* choosing between interlace and progressive mode */
360adeb6f44STobias Jakobi 	val = test_bit(MXR_BIT_INTERLACE, &ctx->flags) ?
361adeb6f44STobias Jakobi 		MXR_CFG_SCAN_INTERLACE : MXR_CFG_SCAN_PROGRESSIVE;
362d8408326SSeung-Woo Kim 
363def5e095SRahul Sharma 	if (ctx->mxr_ver != MXR_VER_128_0_0_184) {
364def5e095SRahul Sharma 		/* choosing between proper HD and SD mode */
36529630743SRahul Sharma 		if (height <= 480)
366d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD;
36729630743SRahul Sharma 		else if (height <= 576)
368d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD;
36929630743SRahul Sharma 		else if (height <= 720)
370d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
37129630743SRahul Sharma 		else if (height <= 1080)
372d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD;
373d8408326SSeung-Woo Kim 		else
374d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
375def5e095SRahul Sharma 	}
376d8408326SSeung-Woo Kim 
377d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK);
378d8408326SSeung-Woo Kim }
379d8408326SSeung-Woo Kim 
380d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height)
381d8408326SSeung-Woo Kim {
382d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
383d8408326SSeung-Woo Kim 	u32 val;
384d8408326SSeung-Woo Kim 
385d8408326SSeung-Woo Kim 	if (height == 480) {
386d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
387d8408326SSeung-Woo Kim 	} else if (height == 576) {
388d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
389d8408326SSeung-Woo Kim 	} else if (height == 720) {
390d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
391d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
392d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
393d8408326SSeung-Woo Kim 				(32 << 0));
394d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
395d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
396d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
397d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
398d8408326SSeung-Woo Kim 	} else if (height == 1080) {
399d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
400d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
401d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
402d8408326SSeung-Woo Kim 				(32 << 0));
403d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
404d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
405d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
406d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
407d8408326SSeung-Woo Kim 	} else {
408d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
409d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
410d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
411d8408326SSeung-Woo Kim 				(32 << 0));
412d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
413d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
414d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
415d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
416d8408326SSeung-Woo Kim 	}
417d8408326SSeung-Woo Kim 
418d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
419d8408326SSeung-Woo Kim }
420d8408326SSeung-Woo Kim 
4215b1d5bc6STobias Jakobi static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win,
422a2cb911eSMarek Szyprowski 			    unsigned int priority, bool enable)
423d8408326SSeung-Woo Kim {
424d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
425d8408326SSeung-Woo Kim 	u32 val = enable ? ~0 : 0;
426d8408326SSeung-Woo Kim 
427d8408326SSeung-Woo Kim 	switch (win) {
428d8408326SSeung-Woo Kim 	case 0:
429d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
430a2cb911eSMarek Szyprowski 		mixer_reg_writemask(res, MXR_LAYER_CFG,
431a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP0_VAL(priority),
432a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP0_MASK);
433d8408326SSeung-Woo Kim 		break;
434d8408326SSeung-Woo Kim 	case 1:
435d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
436a2cb911eSMarek Szyprowski 		mixer_reg_writemask(res, MXR_LAYER_CFG,
437a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP1_VAL(priority),
438a2cb911eSMarek Szyprowski 				    MXR_LAYER_CFG_GRP1_MASK);
439adeb6f44STobias Jakobi 
440d8408326SSeung-Woo Kim 		break;
4415e68fef2SMarek Szyprowski 	case VP_DEFAULT_WIN:
442adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
443d8408326SSeung-Woo Kim 			vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON);
4441b8e5747SRahul Sharma 			mixer_reg_writemask(res, MXR_CFG, val,
4451b8e5747SRahul Sharma 				MXR_CFG_VP_ENABLE);
446a2cb911eSMarek Szyprowski 			mixer_reg_writemask(res, MXR_LAYER_CFG,
447a2cb911eSMarek Szyprowski 					    MXR_LAYER_CFG_VP_VAL(priority),
448a2cb911eSMarek Szyprowski 					    MXR_LAYER_CFG_VP_MASK);
4491b8e5747SRahul Sharma 		}
450d8408326SSeung-Woo Kim 		break;
451d8408326SSeung-Woo Kim 	}
452d8408326SSeung-Woo Kim }
453d8408326SSeung-Woo Kim 
454d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx)
455d8408326SSeung-Woo Kim {
456d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
457d8408326SSeung-Woo Kim 
458d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
459d8408326SSeung-Woo Kim }
460d8408326SSeung-Woo Kim 
461381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx)
462381be025SRahul Sharma {
463381be025SRahul Sharma 	struct mixer_resources *res = &ctx->mixer_res;
464381be025SRahul Sharma 	int timeout = 20;
465381be025SRahul Sharma 
466381be025SRahul Sharma 	mixer_reg_writemask(res, MXR_STATUS, 0, MXR_STATUS_REG_RUN);
467381be025SRahul Sharma 
468381be025SRahul Sharma 	while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
469381be025SRahul Sharma 			--timeout)
470381be025SRahul Sharma 		usleep_range(10000, 12000);
471381be025SRahul Sharma }
472381be025SRahul Sharma 
4732eeb2e5eSGustavo Padovan static void vp_video_buffer(struct mixer_context *ctx,
4742eeb2e5eSGustavo Padovan 			    struct exynos_drm_plane *plane)
475d8408326SSeung-Woo Kim {
4760114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
4770114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
4782ee35d8bSMarek Szyprowski 	struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode;
479d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
4800114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
481e47726a1SMarek Szyprowski 	unsigned int priority = state->base.normalized_zpos + 1;
482d8408326SSeung-Woo Kim 	unsigned long flags;
483d8408326SSeung-Woo Kim 	dma_addr_t luma_addr[2], chroma_addr[2];
484d8408326SSeung-Woo Kim 	bool tiled_mode = false;
485d8408326SSeung-Woo Kim 	bool crcb_mode = false;
486d8408326SSeung-Woo Kim 	u32 val;
487d8408326SSeung-Woo Kim 
4882eeb2e5eSGustavo Padovan 	switch (fb->pixel_format) {
489363b06aaSVille Syrjälä 	case DRM_FORMAT_NV12:
490d8408326SSeung-Woo Kim 		crcb_mode = false;
491d8408326SSeung-Woo Kim 		break;
4928f2590f8STobias Jakobi 	case DRM_FORMAT_NV21:
4938f2590f8STobias Jakobi 		crcb_mode = true;
4948f2590f8STobias Jakobi 		break;
495d8408326SSeung-Woo Kim 	default:
496d8408326SSeung-Woo Kim 		DRM_ERROR("pixel format for vp is wrong [%d].\n",
4972eeb2e5eSGustavo Padovan 				fb->pixel_format);
498d8408326SSeung-Woo Kim 		return;
499d8408326SSeung-Woo Kim 	}
500d8408326SSeung-Woo Kim 
5010488f50eSMarek Szyprowski 	luma_addr[0] = exynos_drm_fb_dma_addr(fb, 0);
5020488f50eSMarek Szyprowski 	chroma_addr[0] = exynos_drm_fb_dma_addr(fb, 1);
503d8408326SSeung-Woo Kim 
5042eeb2e5eSGustavo Padovan 	if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
505adeb6f44STobias Jakobi 		__set_bit(MXR_BIT_INTERLACE, &ctx->flags);
506d8408326SSeung-Woo Kim 		if (tiled_mode) {
507d8408326SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + 0x40;
508d8408326SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + 0x40;
509d8408326SSeung-Woo Kim 		} else {
5102eeb2e5eSGustavo Padovan 			luma_addr[1] = luma_addr[0] + fb->pitches[0];
5112eeb2e5eSGustavo Padovan 			chroma_addr[1] = chroma_addr[0] + fb->pitches[0];
512d8408326SSeung-Woo Kim 		}
513d8408326SSeung-Woo Kim 	} else {
514adeb6f44STobias Jakobi 		__clear_bit(MXR_BIT_INTERLACE, &ctx->flags);
515d8408326SSeung-Woo Kim 		luma_addr[1] = 0;
516d8408326SSeung-Woo Kim 		chroma_addr[1] = 0;
517d8408326SSeung-Woo Kim 	}
518d8408326SSeung-Woo Kim 
519d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
520d8408326SSeung-Woo Kim 
521d8408326SSeung-Woo Kim 	/* interlace or progressive scan mode */
522adeb6f44STobias Jakobi 	val = (test_bit(MXR_BIT_INTERLACE, &ctx->flags) ? ~0 : 0);
523d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP);
524d8408326SSeung-Woo Kim 
525d8408326SSeung-Woo Kim 	/* setup format */
526d8408326SSeung-Woo Kim 	val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12);
527d8408326SSeung-Woo Kim 	val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
528d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK);
529d8408326SSeung-Woo Kim 
530d8408326SSeung-Woo Kim 	/* setting size of input image */
5312eeb2e5eSGustavo Padovan 	vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) |
5322eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height));
533d8408326SSeung-Woo Kim 	/* chroma height has to reduced by 2 to avoid chroma distorions */
5342eeb2e5eSGustavo Padovan 	vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[0]) |
5352eeb2e5eSGustavo Padovan 		VP_IMG_VSIZE(fb->height / 2));
536d8408326SSeung-Woo Kim 
5370114f404SMarek Szyprowski 	vp_reg_write(res, VP_SRC_WIDTH, state->src.w);
5380114f404SMarek Szyprowski 	vp_reg_write(res, VP_SRC_HEIGHT, state->src.h);
539d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_H_POSITION,
5400114f404SMarek Szyprowski 			VP_SRC_H_POSITION_VAL(state->src.x));
5410114f404SMarek Szyprowski 	vp_reg_write(res, VP_SRC_V_POSITION, state->src.y);
542d8408326SSeung-Woo Kim 
5430114f404SMarek Szyprowski 	vp_reg_write(res, VP_DST_WIDTH, state->crtc.w);
5440114f404SMarek Szyprowski 	vp_reg_write(res, VP_DST_H_POSITION, state->crtc.x);
545adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
5460114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h / 2);
5470114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y / 2);
548d8408326SSeung-Woo Kim 	} else {
5490114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h);
5500114f404SMarek Szyprowski 		vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y);
551d8408326SSeung-Woo Kim 	}
552d8408326SSeung-Woo Kim 
5530114f404SMarek Szyprowski 	vp_reg_write(res, VP_H_RATIO, state->h_ratio);
5540114f404SMarek Szyprowski 	vp_reg_write(res, VP_V_RATIO, state->v_ratio);
555d8408326SSeung-Woo Kim 
556d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
557d8408326SSeung-Woo Kim 
558d8408326SSeung-Woo Kim 	/* set buffer address to vp */
559d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]);
560d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]);
561d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]);
562d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]);
563d8408326SSeung-Woo Kim 
5642eeb2e5eSGustavo Padovan 	mixer_cfg_scan(ctx, mode->vdisplay);
5652eeb2e5eSGustavo Padovan 	mixer_cfg_rgb_fmt(ctx, mode->vdisplay);
566e47726a1SMarek Szyprowski 	mixer_cfg_layer(ctx, plane->index, priority, true);
567f657a996SMarek Szyprowski 	mixer_cfg_vp_blend(ctx);
568d8408326SSeung-Woo Kim 	mixer_run(ctx);
569d8408326SSeung-Woo Kim 
570d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
571d8408326SSeung-Woo Kim 
572c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
573d8408326SSeung-Woo Kim 	vp_regs_dump(ctx);
574d8408326SSeung-Woo Kim }
575d8408326SSeung-Woo Kim 
576aaf8b49eSRahul Sharma static void mixer_layer_update(struct mixer_context *ctx)
577aaf8b49eSRahul Sharma {
578aaf8b49eSRahul Sharma 	struct mixer_resources *res = &ctx->mixer_res;
579aaf8b49eSRahul Sharma 
580aaf8b49eSRahul Sharma 	mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
581aaf8b49eSRahul Sharma }
582aaf8b49eSRahul Sharma 
5832eeb2e5eSGustavo Padovan static void mixer_graph_buffer(struct mixer_context *ctx,
5842eeb2e5eSGustavo Padovan 			       struct exynos_drm_plane *plane)
585d8408326SSeung-Woo Kim {
5860114f404SMarek Szyprowski 	struct exynos_drm_plane_state *state =
5870114f404SMarek Szyprowski 				to_exynos_plane_state(plane->base.state);
5882ee35d8bSMarek Szyprowski 	struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode;
589d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
5900114f404SMarek Szyprowski 	struct drm_framebuffer *fb = state->base.fb;
591e47726a1SMarek Szyprowski 	unsigned int priority = state->base.normalized_zpos + 1;
592d8408326SSeung-Woo Kim 	unsigned long flags;
59340bdfb0aSMarek Szyprowski 	unsigned int win = plane->index;
5942611015cSTobias Jakobi 	unsigned int x_ratio = 0, y_ratio = 0;
595d8408326SSeung-Woo Kim 	unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset;
596d8408326SSeung-Woo Kim 	dma_addr_t dma_addr;
597d8408326SSeung-Woo Kim 	unsigned int fmt;
598d8408326SSeung-Woo Kim 	u32 val;
599d8408326SSeung-Woo Kim 
6002eeb2e5eSGustavo Padovan 	switch (fb->pixel_format) {
6017a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB4444:
60226a7af3eSTobias Jakobi 	case DRM_FORMAT_ARGB4444:
6037a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB4444;
6047a57ca7cSTobias Jakobi 		break;
605d8408326SSeung-Woo Kim 
6067a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB1555:
60726a7af3eSTobias Jakobi 	case DRM_FORMAT_ARGB1555:
6087a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB1555;
609d8408326SSeung-Woo Kim 		break;
6107a57ca7cSTobias Jakobi 
6117a57ca7cSTobias Jakobi 	case DRM_FORMAT_RGB565:
6127a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_RGB565;
613d8408326SSeung-Woo Kim 		break;
6147a57ca7cSTobias Jakobi 
6157a57ca7cSTobias Jakobi 	case DRM_FORMAT_XRGB8888:
6167a57ca7cSTobias Jakobi 	case DRM_FORMAT_ARGB8888:
6177a57ca7cSTobias Jakobi 		fmt = MXR_FORMAT_ARGB8888;
6187a57ca7cSTobias Jakobi 		break;
6197a57ca7cSTobias Jakobi 
620d8408326SSeung-Woo Kim 	default:
6217a57ca7cSTobias Jakobi 		DRM_DEBUG_KMS("pixelformat unsupported by mixer\n");
6227a57ca7cSTobias Jakobi 		return;
623d8408326SSeung-Woo Kim 	}
624d8408326SSeung-Woo Kim 
625e463b069SMarek Szyprowski 	/* ratio is already checked by common plane code */
626e463b069SMarek Szyprowski 	x_ratio = state->h_ratio == (1 << 15);
627e463b069SMarek Szyprowski 	y_ratio = state->v_ratio == (1 << 15);
628d8408326SSeung-Woo Kim 
6290114f404SMarek Szyprowski 	dst_x_offset = state->crtc.x;
6300114f404SMarek Szyprowski 	dst_y_offset = state->crtc.y;
631d8408326SSeung-Woo Kim 
632d8408326SSeung-Woo Kim 	/* converting dma address base and source offset */
6330488f50eSMarek Szyprowski 	dma_addr = exynos_drm_fb_dma_addr(fb, 0)
634*272725c7SVille Syrjälä 		+ (state->src.x * fb->format->cpp[0])
6350114f404SMarek Szyprowski 		+ (state->src.y * fb->pitches[0]);
636d8408326SSeung-Woo Kim 	src_x_offset = 0;
637d8408326SSeung-Woo Kim 	src_y_offset = 0;
638d8408326SSeung-Woo Kim 
6392eeb2e5eSGustavo Padovan 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
640adeb6f44STobias Jakobi 		__set_bit(MXR_BIT_INTERLACE, &ctx->flags);
641d8408326SSeung-Woo Kim 	else
642adeb6f44STobias Jakobi 		__clear_bit(MXR_BIT_INTERLACE, &ctx->flags);
643d8408326SSeung-Woo Kim 
644d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
645d8408326SSeung-Woo Kim 
646d8408326SSeung-Woo Kim 	/* setup format */
647d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
648d8408326SSeung-Woo Kim 		MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
649d8408326SSeung-Woo Kim 
650d8408326SSeung-Woo Kim 	/* setup geometry */
651adacb228SDaniel Stone 	mixer_reg_write(res, MXR_GRAPHIC_SPAN(win),
652*272725c7SVille Syrjälä 			fb->pitches[0] / fb->format->cpp[0]);
653d8408326SSeung-Woo Kim 
654def5e095SRahul Sharma 	/* setup display size */
655def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_128_0_0_184 &&
6565d3d0995SGustavo Padovan 		win == DEFAULT_WIN) {
6572eeb2e5eSGustavo Padovan 		val  = MXR_MXR_RES_HEIGHT(mode->vdisplay);
6582eeb2e5eSGustavo Padovan 		val |= MXR_MXR_RES_WIDTH(mode->hdisplay);
659def5e095SRahul Sharma 		mixer_reg_write(res, MXR_RESOLUTION, val);
660def5e095SRahul Sharma 	}
661def5e095SRahul Sharma 
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);
666d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_WH(win), val);
667d8408326SSeung-Woo Kim 
668d8408326SSeung-Woo Kim 	/* setup offsets in source image */
669d8408326SSeung-Woo Kim 	val  = MXR_GRP_SXY_SX(src_x_offset);
670d8408326SSeung-Woo Kim 	val |= MXR_GRP_SXY_SY(src_y_offset);
671d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val);
672d8408326SSeung-Woo Kim 
673d8408326SSeung-Woo Kim 	/* setup offsets in display image */
674d8408326SSeung-Woo Kim 	val  = MXR_GRP_DXY_DX(dst_x_offset);
675d8408326SSeung-Woo Kim 	val |= MXR_GRP_DXY_DY(dst_y_offset);
676d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val);
677d8408326SSeung-Woo Kim 
678d8408326SSeung-Woo Kim 	/* set buffer address to mixer */
679d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr);
680d8408326SSeung-Woo Kim 
6812eeb2e5eSGustavo Padovan 	mixer_cfg_scan(ctx, mode->vdisplay);
6822eeb2e5eSGustavo Padovan 	mixer_cfg_rgb_fmt(ctx, mode->vdisplay);
683e47726a1SMarek Szyprowski 	mixer_cfg_layer(ctx, win, priority, true);
684f657a996SMarek Szyprowski 	mixer_cfg_gfx_blend(ctx, win, is_alpha_format(fb->pixel_format));
685aaf8b49eSRahul Sharma 
686aaf8b49eSRahul Sharma 	/* layer update mandatory for mixer 16.0.33.0 */
687def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
688def5e095SRahul Sharma 		ctx->mxr_ver == MXR_VER_128_0_0_184)
689aaf8b49eSRahul Sharma 		mixer_layer_update(ctx);
690aaf8b49eSRahul Sharma 
691d8408326SSeung-Woo Kim 	mixer_run(ctx);
692d8408326SSeung-Woo Kim 
693d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
694c0734fbaSTobias Jakobi 
695c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
696d8408326SSeung-Woo Kim }
697d8408326SSeung-Woo Kim 
698d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx)
699d8408326SSeung-Woo Kim {
700d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
701a696394cSTobias Jakobi 	unsigned int tries = 100;
702d8408326SSeung-Woo Kim 
703d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING);
704a696394cSTobias Jakobi 	while (tries--) {
705d8408326SSeung-Woo Kim 		/* waiting until VP_SRESET_PROCESSING is 0 */
706d8408326SSeung-Woo Kim 		if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING)
707d8408326SSeung-Woo Kim 			break;
70802b3de43STomasz Stanislawski 		mdelay(10);
709d8408326SSeung-Woo Kim 	}
710d8408326SSeung-Woo Kim 	WARN(tries == 0, "failed to reset Video Processor\n");
711d8408326SSeung-Woo Kim }
712d8408326SSeung-Woo Kim 
713cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx)
714cf8fc4f1SJoonyoung Shim {
715cf8fc4f1SJoonyoung Shim 	struct mixer_resources *res = &ctx->mixer_res;
716cf8fc4f1SJoonyoung Shim 	unsigned long flags;
717cf8fc4f1SJoonyoung Shim 
718cf8fc4f1SJoonyoung Shim 	spin_lock_irqsave(&res->reg_slock, flags);
719cf8fc4f1SJoonyoung Shim 
720cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
721cf8fc4f1SJoonyoung Shim 
722cf8fc4f1SJoonyoung Shim 	/* set output in RGB888 mode */
723cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
724cf8fc4f1SJoonyoung Shim 
725cf8fc4f1SJoonyoung Shim 	/* 16 beat burst in DMA */
726cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST,
727cf8fc4f1SJoonyoung Shim 		MXR_STATUS_BURST_MASK);
728cf8fc4f1SJoonyoung Shim 
729a2cb911eSMarek Szyprowski 	/* reset default layer priority */
730a2cb911eSMarek Szyprowski 	mixer_reg_write(res, MXR_LAYER_CFG, 0);
731cf8fc4f1SJoonyoung Shim 
732cf8fc4f1SJoonyoung Shim 	/* setting background color */
733cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR0, 0x008080);
734cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR1, 0x008080);
735cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR2, 0x008080);
736cf8fc4f1SJoonyoung Shim 
737adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
738cf8fc4f1SJoonyoung Shim 		/* configuration of Video Processor Registers */
739cf8fc4f1SJoonyoung Shim 		vp_win_reset(ctx);
740cf8fc4f1SJoonyoung Shim 		vp_default_filter(res);
7411b8e5747SRahul Sharma 	}
742cf8fc4f1SJoonyoung Shim 
743cf8fc4f1SJoonyoung Shim 	/* disable all layers */
744cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
745cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
746adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
747cf8fc4f1SJoonyoung Shim 		mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
748cf8fc4f1SJoonyoung Shim 
749cf8fc4f1SJoonyoung Shim 	spin_unlock_irqrestore(&res->reg_slock, flags);
750cf8fc4f1SJoonyoung Shim }
751cf8fc4f1SJoonyoung Shim 
7524551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg)
7534551789fSSean Paul {
7544551789fSSean Paul 	struct mixer_context *ctx = arg;
7554551789fSSean Paul 	struct mixer_resources *res = &ctx->mixer_res;
7564551789fSSean Paul 	u32 val, base, shadow;
7574551789fSSean Paul 
7584551789fSSean Paul 	spin_lock(&res->reg_slock);
7594551789fSSean Paul 
7604551789fSSean Paul 	/* read interrupt status for handling and clearing flags for VSYNC */
7614551789fSSean Paul 	val = mixer_reg_read(res, MXR_INT_STATUS);
7624551789fSSean Paul 
7634551789fSSean Paul 	/* handling VSYNC */
7644551789fSSean Paul 	if (val & MXR_INT_STATUS_VSYNC) {
76581a464dfSAndrzej Hajda 		/* vsync interrupt use different bit for read and clear */
76681a464dfSAndrzej Hajda 		val |= MXR_INT_CLEAR_VSYNC;
76781a464dfSAndrzej Hajda 		val &= ~MXR_INT_STATUS_VSYNC;
76881a464dfSAndrzej Hajda 
7694551789fSSean Paul 		/* interlace scan need to check shadow register */
770adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
7714551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0));
7724551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0));
7734551789fSSean Paul 			if (base != shadow)
7744551789fSSean Paul 				goto out;
7754551789fSSean Paul 
7764551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1));
7774551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1));
7784551789fSSean Paul 			if (base != shadow)
7794551789fSSean Paul 				goto out;
7804551789fSSean Paul 		}
7814551789fSSean Paul 
782eafd540aSGustavo Padovan 		drm_crtc_handle_vblank(&ctx->crtc->base);
7834551789fSSean Paul 	}
7844551789fSSean Paul 
7854551789fSSean Paul out:
7864551789fSSean Paul 	/* clear interrupts */
7874551789fSSean Paul 	mixer_reg_write(res, MXR_INT_STATUS, val);
7884551789fSSean Paul 
7894551789fSSean Paul 	spin_unlock(&res->reg_slock);
7904551789fSSean Paul 
7914551789fSSean Paul 	return IRQ_HANDLED;
7924551789fSSean Paul }
7934551789fSSean Paul 
7944551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx)
7954551789fSSean Paul {
7964551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
7974551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
7984551789fSSean Paul 	struct resource *res;
7994551789fSSean Paul 	int ret;
8004551789fSSean Paul 
8014551789fSSean Paul 	spin_lock_init(&mixer_res->reg_slock);
8024551789fSSean Paul 
8034551789fSSean Paul 	mixer_res->mixer = devm_clk_get(dev, "mixer");
8044551789fSSean Paul 	if (IS_ERR(mixer_res->mixer)) {
8054551789fSSean Paul 		dev_err(dev, "failed to get clock 'mixer'\n");
8064551789fSSean Paul 		return -ENODEV;
8074551789fSSean Paul 	}
8084551789fSSean Paul 
80904427ec5SMarek Szyprowski 	mixer_res->hdmi = devm_clk_get(dev, "hdmi");
81004427ec5SMarek Szyprowski 	if (IS_ERR(mixer_res->hdmi)) {
81104427ec5SMarek Szyprowski 		dev_err(dev, "failed to get clock 'hdmi'\n");
81204427ec5SMarek Szyprowski 		return PTR_ERR(mixer_res->hdmi);
81304427ec5SMarek Szyprowski 	}
81404427ec5SMarek Szyprowski 
8154551789fSSean Paul 	mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
8164551789fSSean Paul 	if (IS_ERR(mixer_res->sclk_hdmi)) {
8174551789fSSean Paul 		dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
8184551789fSSean Paul 		return -ENODEV;
8194551789fSSean Paul 	}
8204551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
8214551789fSSean Paul 	if (res == NULL) {
8224551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8234551789fSSean Paul 		return -ENXIO;
8244551789fSSean Paul 	}
8254551789fSSean Paul 
8264551789fSSean Paul 	mixer_res->mixer_regs = devm_ioremap(dev, res->start,
8274551789fSSean Paul 							resource_size(res));
8284551789fSSean Paul 	if (mixer_res->mixer_regs == NULL) {
8294551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8304551789fSSean Paul 		return -ENXIO;
8314551789fSSean Paul 	}
8324551789fSSean Paul 
8334551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0);
8344551789fSSean Paul 	if (res == NULL) {
8354551789fSSean Paul 		dev_err(dev, "get interrupt resource failed.\n");
8364551789fSSean Paul 		return -ENXIO;
8374551789fSSean Paul 	}
8384551789fSSean Paul 
8394551789fSSean Paul 	ret = devm_request_irq(dev, res->start, mixer_irq_handler,
8404551789fSSean Paul 						0, "drm_mixer", mixer_ctx);
8414551789fSSean Paul 	if (ret) {
8424551789fSSean Paul 		dev_err(dev, "request interrupt failed.\n");
8434551789fSSean Paul 		return ret;
8444551789fSSean Paul 	}
8454551789fSSean Paul 	mixer_res->irq = res->start;
8464551789fSSean Paul 
8474551789fSSean Paul 	return 0;
8484551789fSSean Paul }
8494551789fSSean Paul 
8504551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx)
8514551789fSSean Paul {
8524551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
8534551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
8544551789fSSean Paul 	struct resource *res;
8554551789fSSean Paul 
8564551789fSSean Paul 	mixer_res->vp = devm_clk_get(dev, "vp");
8574551789fSSean Paul 	if (IS_ERR(mixer_res->vp)) {
8584551789fSSean Paul 		dev_err(dev, "failed to get clock 'vp'\n");
8594551789fSSean Paul 		return -ENODEV;
8604551789fSSean Paul 	}
861ff830c96SMarek Szyprowski 
862adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_HAS_SCLK, &mixer_ctx->flags)) {
8634551789fSSean Paul 		mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
8644551789fSSean Paul 		if (IS_ERR(mixer_res->sclk_mixer)) {
8654551789fSSean Paul 			dev_err(dev, "failed to get clock 'sclk_mixer'\n");
8664551789fSSean Paul 			return -ENODEV;
8674551789fSSean Paul 		}
868ff830c96SMarek Szyprowski 		mixer_res->mout_mixer = devm_clk_get(dev, "mout_mixer");
869ff830c96SMarek Szyprowski 		if (IS_ERR(mixer_res->mout_mixer)) {
870ff830c96SMarek Szyprowski 			dev_err(dev, "failed to get clock 'mout_mixer'\n");
8714551789fSSean Paul 			return -ENODEV;
8724551789fSSean Paul 		}
8734551789fSSean Paul 
874ff830c96SMarek Szyprowski 		if (mixer_res->sclk_hdmi && mixer_res->mout_mixer)
875ff830c96SMarek Szyprowski 			clk_set_parent(mixer_res->mout_mixer,
876ff830c96SMarek Szyprowski 				       mixer_res->sclk_hdmi);
877ff830c96SMarek Szyprowski 	}
8784551789fSSean Paul 
8794551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
8804551789fSSean Paul 	if (res == NULL) {
8814551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8824551789fSSean Paul 		return -ENXIO;
8834551789fSSean Paul 	}
8844551789fSSean Paul 
8854551789fSSean Paul 	mixer_res->vp_regs = devm_ioremap(dev, res->start,
8864551789fSSean Paul 							resource_size(res));
8874551789fSSean Paul 	if (mixer_res->vp_regs == NULL) {
8884551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8894551789fSSean Paul 		return -ENXIO;
8904551789fSSean Paul 	}
8914551789fSSean Paul 
8924551789fSSean Paul 	return 0;
8934551789fSSean Paul }
8944551789fSSean Paul 
89593bca243SGustavo Padovan static int mixer_initialize(struct mixer_context *mixer_ctx,
896f37cd5e8SInki Dae 			struct drm_device *drm_dev)
8974551789fSSean Paul {
8984551789fSSean Paul 	int ret;
899f37cd5e8SInki Dae 	struct exynos_drm_private *priv;
900f37cd5e8SInki Dae 	priv = drm_dev->dev_private;
9014551789fSSean Paul 
902eb88e422SGustavo Padovan 	mixer_ctx->drm_dev = drm_dev;
9038a326eddSGustavo Padovan 	mixer_ctx->pipe = priv->pipe++;
9044551789fSSean Paul 
9054551789fSSean Paul 	/* acquire resources: regs, irqs, clocks */
9064551789fSSean Paul 	ret = mixer_resources_init(mixer_ctx);
9074551789fSSean Paul 	if (ret) {
9084551789fSSean Paul 		DRM_ERROR("mixer_resources_init failed ret=%d\n", ret);
9094551789fSSean Paul 		return ret;
9104551789fSSean Paul 	}
9114551789fSSean Paul 
912adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &mixer_ctx->flags)) {
9134551789fSSean Paul 		/* acquire vp resources: regs, irqs, clocks */
9144551789fSSean Paul 		ret = vp_resources_init(mixer_ctx);
9154551789fSSean Paul 		if (ret) {
9164551789fSSean Paul 			DRM_ERROR("vp_resources_init failed ret=%d\n", ret);
9174551789fSSean Paul 			return ret;
9184551789fSSean Paul 		}
9194551789fSSean Paul 	}
9204551789fSSean Paul 
921eb7a3fc7SJoonyoung Shim 	ret = drm_iommu_attach_device(drm_dev, mixer_ctx->dev);
922fc2e013fSHyungwon Hwang 	if (ret)
923fc2e013fSHyungwon Hwang 		priv->pipe--;
924f041b257SSean Paul 
925fc2e013fSHyungwon Hwang 	return ret;
9261055b39fSInki Dae }
9271055b39fSInki Dae 
92893bca243SGustavo Padovan static void mixer_ctx_remove(struct mixer_context *mixer_ctx)
929d8408326SSeung-Woo Kim {
930f041b257SSean Paul 	drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev);
931f041b257SSean Paul }
932f041b257SSean Paul 
93393bca243SGustavo Padovan static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)
934f041b257SSean Paul {
93593bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
936d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
937d8408326SSeung-Woo Kim 
9380df5e4acSAndrzej Hajda 	__set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9390df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
940f041b257SSean Paul 		return 0;
941d8408326SSeung-Woo Kim 
942d8408326SSeung-Woo Kim 	/* enable vsync interrupt */
943fc073248SAndrzej Hajda 	mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
944fc073248SAndrzej Hajda 	mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
945d8408326SSeung-Woo Kim 
946d8408326SSeung-Woo Kim 	return 0;
947d8408326SSeung-Woo Kim }
948d8408326SSeung-Woo Kim 
94993bca243SGustavo Padovan static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
950d8408326SSeung-Woo Kim {
95193bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
952d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
953d8408326SSeung-Woo Kim 
9540df5e4acSAndrzej Hajda 	__clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9550df5e4acSAndrzej Hajda 
9560df5e4acSAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
957947710c6SAndrzej Hajda 		return;
958947710c6SAndrzej Hajda 
959d8408326SSeung-Woo Kim 	/* disable vsync interrupt */
960fc073248SAndrzej Hajda 	mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
961d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
962d8408326SSeung-Woo Kim }
963d8408326SSeung-Woo Kim 
9643dbaab16SMarek Szyprowski static void mixer_atomic_begin(struct exynos_drm_crtc *crtc)
9653dbaab16SMarek Szyprowski {
9663dbaab16SMarek Szyprowski 	struct mixer_context *mixer_ctx = crtc->ctx;
9673dbaab16SMarek Szyprowski 
9683dbaab16SMarek Szyprowski 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
9693dbaab16SMarek Szyprowski 		return;
9703dbaab16SMarek Szyprowski 
9713dbaab16SMarek Szyprowski 	mixer_vsync_set_update(mixer_ctx, false);
9723dbaab16SMarek Szyprowski }
9733dbaab16SMarek Szyprowski 
9741e1d1393SGustavo Padovan static void mixer_update_plane(struct exynos_drm_crtc *crtc,
9751e1d1393SGustavo Padovan 			       struct exynos_drm_plane *plane)
976d8408326SSeung-Woo Kim {
97793bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
978d8408326SSeung-Woo Kim 
97940bdfb0aSMarek Szyprowski 	DRM_DEBUG_KMS("win: %d\n", plane->index);
980d8408326SSeung-Woo Kim 
981a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
982dda9012bSShirish S 		return;
983dda9012bSShirish S 
9845e68fef2SMarek Szyprowski 	if (plane->index == VP_DEFAULT_WIN)
9852eeb2e5eSGustavo Padovan 		vp_video_buffer(mixer_ctx, plane);
986d8408326SSeung-Woo Kim 	else
9872eeb2e5eSGustavo Padovan 		mixer_graph_buffer(mixer_ctx, plane);
988d8408326SSeung-Woo Kim }
989d8408326SSeung-Woo Kim 
9901e1d1393SGustavo Padovan static void mixer_disable_plane(struct exynos_drm_crtc *crtc,
9911e1d1393SGustavo Padovan 				struct exynos_drm_plane *plane)
992d8408326SSeung-Woo Kim {
99393bca243SGustavo Padovan 	struct mixer_context *mixer_ctx = crtc->ctx;
994d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
995d8408326SSeung-Woo Kim 	unsigned long flags;
996d8408326SSeung-Woo Kim 
99740bdfb0aSMarek Szyprowski 	DRM_DEBUG_KMS("win: %d\n", plane->index);
998d8408326SSeung-Woo Kim 
999a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
1000db43fd16SPrathyush K 		return;
1001db43fd16SPrathyush K 
1002d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
1003a2cb911eSMarek Szyprowski 	mixer_cfg_layer(mixer_ctx, plane->index, 0, false);
10043dbaab16SMarek Szyprowski 	spin_unlock_irqrestore(&res->reg_slock, flags);
10053dbaab16SMarek Szyprowski }
10063dbaab16SMarek Szyprowski 
10073dbaab16SMarek Szyprowski static void mixer_atomic_flush(struct exynos_drm_crtc *crtc)
10083dbaab16SMarek Szyprowski {
10093dbaab16SMarek Szyprowski 	struct mixer_context *mixer_ctx = crtc->ctx;
10103dbaab16SMarek Szyprowski 
10113dbaab16SMarek Szyprowski 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
10123dbaab16SMarek Szyprowski 		return;
1013d8408326SSeung-Woo Kim 
1014d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, true);
1015d8408326SSeung-Woo Kim }
1016d8408326SSeung-Woo Kim 
10173cecda03SGustavo Padovan static void mixer_enable(struct exynos_drm_crtc *crtc)
1018db43fd16SPrathyush K {
10193cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
1020db43fd16SPrathyush K 	struct mixer_resources *res = &ctx->mixer_res;
1021db43fd16SPrathyush K 
1022a44652e8SAndrzej Hajda 	if (test_bit(MXR_BIT_POWERED, &ctx->flags))
1023db43fd16SPrathyush K 		return;
1024db43fd16SPrathyush K 
1025af65c804SSean Paul 	pm_runtime_get_sync(ctx->dev);
1026af65c804SSean Paul 
1027a121d179SAndrzej Hajda 	exynos_drm_pipe_clk_enable(crtc, true);
1028a121d179SAndrzej Hajda 
10293dbaab16SMarek Szyprowski 	mixer_vsync_set_update(ctx, false);
10303dbaab16SMarek Szyprowski 
1031d74ed937SRahul Sharma 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
1032d74ed937SRahul Sharma 
10330df5e4acSAndrzej Hajda 	if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) {
1034fc073248SAndrzej Hajda 		mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
10350df5e4acSAndrzej Hajda 		mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
10360df5e4acSAndrzej Hajda 	}
1037db43fd16SPrathyush K 	mixer_win_reset(ctx);
1038ccf034a9SGustavo Padovan 
10393dbaab16SMarek Szyprowski 	mixer_vsync_set_update(ctx, true);
10403dbaab16SMarek Szyprowski 
1041ccf034a9SGustavo Padovan 	set_bit(MXR_BIT_POWERED, &ctx->flags);
1042db43fd16SPrathyush K }
1043db43fd16SPrathyush K 
10443cecda03SGustavo Padovan static void mixer_disable(struct exynos_drm_crtc *crtc)
1045db43fd16SPrathyush K {
10463cecda03SGustavo Padovan 	struct mixer_context *ctx = crtc->ctx;
1047c329f667SJoonyoung Shim 	int i;
1048db43fd16SPrathyush K 
1049a44652e8SAndrzej Hajda 	if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
1050b4bfa3c7SRahul Sharma 		return;
1051db43fd16SPrathyush K 
1052381be025SRahul Sharma 	mixer_stop(ctx);
1053c0734fbaSTobias Jakobi 	mixer_regs_dump(ctx);
1054c329f667SJoonyoung Shim 
1055c329f667SJoonyoung Shim 	for (i = 0; i < MIXER_WIN_NR; i++)
10561e1d1393SGustavo Padovan 		mixer_disable_plane(crtc, &ctx->planes[i]);
1057db43fd16SPrathyush K 
1058a121d179SAndrzej Hajda 	exynos_drm_pipe_clk_enable(crtc, false);
1059a121d179SAndrzej Hajda 
1060ccf034a9SGustavo Padovan 	pm_runtime_put(ctx->dev);
1061ccf034a9SGustavo Padovan 
1062a44652e8SAndrzej Hajda 	clear_bit(MXR_BIT_POWERED, &ctx->flags);
1063db43fd16SPrathyush K }
1064db43fd16SPrathyush K 
1065f041b257SSean Paul /* Only valid for Mixer version 16.0.33.0 */
10663ae24362SAndrzej Hajda static int mixer_atomic_check(struct exynos_drm_crtc *crtc,
10673ae24362SAndrzej Hajda 		       struct drm_crtc_state *state)
1068f041b257SSean Paul {
10693ae24362SAndrzej Hajda 	struct drm_display_mode *mode = &state->adjusted_mode;
1070f041b257SSean Paul 	u32 w, h;
1071f041b257SSean Paul 
1072f041b257SSean Paul 	w = mode->hdisplay;
1073f041b257SSean Paul 	h = mode->vdisplay;
1074f041b257SSean Paul 
1075f041b257SSean Paul 	DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n",
1076f041b257SSean Paul 		mode->hdisplay, mode->vdisplay, mode->vrefresh,
1077f041b257SSean Paul 		(mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
1078f041b257SSean Paul 
1079f041b257SSean Paul 	if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
1080f041b257SSean Paul 		(w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
1081f041b257SSean Paul 		(w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
1082f041b257SSean Paul 		return 0;
1083f041b257SSean Paul 
1084f041b257SSean Paul 	return -EINVAL;
1085f041b257SSean Paul }
1086f041b257SSean Paul 
1087f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops mixer_crtc_ops = {
10883cecda03SGustavo Padovan 	.enable			= mixer_enable,
10893cecda03SGustavo Padovan 	.disable		= mixer_disable,
1090d8408326SSeung-Woo Kim 	.enable_vblank		= mixer_enable_vblank,
1091d8408326SSeung-Woo Kim 	.disable_vblank		= mixer_disable_vblank,
10923dbaab16SMarek Szyprowski 	.atomic_begin		= mixer_atomic_begin,
10939cc7610aSGustavo Padovan 	.update_plane		= mixer_update_plane,
10949cc7610aSGustavo Padovan 	.disable_plane		= mixer_disable_plane,
10953dbaab16SMarek Szyprowski 	.atomic_flush		= mixer_atomic_flush,
10963ae24362SAndrzej Hajda 	.atomic_check		= mixer_atomic_check,
1097f041b257SSean Paul };
10980ea6822fSRahul Sharma 
1099def5e095SRahul Sharma static struct mixer_drv_data exynos5420_mxr_drv_data = {
1100def5e095SRahul Sharma 	.version = MXR_VER_128_0_0_184,
1101def5e095SRahul Sharma 	.is_vp_enabled = 0,
1102def5e095SRahul Sharma };
1103def5e095SRahul Sharma 
1104cc57caf0SRahul Sharma static struct mixer_drv_data exynos5250_mxr_drv_data = {
1105aaf8b49eSRahul Sharma 	.version = MXR_VER_16_0_33_0,
1106aaf8b49eSRahul Sharma 	.is_vp_enabled = 0,
1107aaf8b49eSRahul Sharma };
1108aaf8b49eSRahul Sharma 
1109ff830c96SMarek Szyprowski static struct mixer_drv_data exynos4212_mxr_drv_data = {
1110ff830c96SMarek Szyprowski 	.version = MXR_VER_0_0_0_16,
1111ff830c96SMarek Szyprowski 	.is_vp_enabled = 1,
1112ff830c96SMarek Szyprowski };
1113ff830c96SMarek Szyprowski 
1114cc57caf0SRahul Sharma static struct mixer_drv_data exynos4210_mxr_drv_data = {
11151e123441SRahul Sharma 	.version = MXR_VER_0_0_0_16,
11161b8e5747SRahul Sharma 	.is_vp_enabled = 1,
1117ff830c96SMarek Szyprowski 	.has_sclk = 1,
11181e123441SRahul Sharma };
11191e123441SRahul Sharma 
1120aaf8b49eSRahul Sharma static struct of_device_id mixer_match_types[] = {
1121aaf8b49eSRahul Sharma 	{
1122ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4210-mixer",
1123ff830c96SMarek Szyprowski 		.data	= &exynos4210_mxr_drv_data,
1124ff830c96SMarek Szyprowski 	}, {
1125ff830c96SMarek Szyprowski 		.compatible = "samsung,exynos4212-mixer",
1126ff830c96SMarek Szyprowski 		.data	= &exynos4212_mxr_drv_data,
1127ff830c96SMarek Szyprowski 	}, {
1128aaf8b49eSRahul Sharma 		.compatible = "samsung,exynos5-mixer",
1129cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1130cc57caf0SRahul Sharma 	}, {
1131cc57caf0SRahul Sharma 		.compatible = "samsung,exynos5250-mixer",
1132cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1133aaf8b49eSRahul Sharma 	}, {
1134def5e095SRahul Sharma 		.compatible = "samsung,exynos5420-mixer",
1135def5e095SRahul Sharma 		.data	= &exynos5420_mxr_drv_data,
1136def5e095SRahul Sharma 	}, {
11371e123441SRahul Sharma 		/* end node */
11381e123441SRahul Sharma 	}
11391e123441SRahul Sharma };
114039b58a39SSjoerd Simons MODULE_DEVICE_TABLE(of, mixer_match_types);
11411e123441SRahul Sharma 
1142f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data)
1143d8408326SSeung-Woo Kim {
11448103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
1145f37cd5e8SInki Dae 	struct drm_device *drm_dev = data;
11467ee14cdcSGustavo Padovan 	struct exynos_drm_plane *exynos_plane;
1147fd2d2fc2SMarek Szyprowski 	unsigned int i;
11486e2a3b66SGustavo Padovan 	int ret;
1149d8408326SSeung-Woo Kim 
1150e2dc3f72SAlban Browaeys 	ret = mixer_initialize(ctx, drm_dev);
1151e2dc3f72SAlban Browaeys 	if (ret)
1152e2dc3f72SAlban Browaeys 		return ret;
1153e2dc3f72SAlban Browaeys 
1154fd2d2fc2SMarek Szyprowski 	for (i = 0; i < MIXER_WIN_NR; i++) {
1155adeb6f44STobias Jakobi 		if (i == VP_DEFAULT_WIN && !test_bit(MXR_BIT_VP_ENABLED,
1156adeb6f44STobias Jakobi 						     &ctx->flags))
1157ab144201SMarek Szyprowski 			continue;
1158ab144201SMarek Szyprowski 
115940bdfb0aSMarek Szyprowski 		ret = exynos_plane_init(drm_dev, &ctx->planes[i], i,
1160fd2d2fc2SMarek Szyprowski 					1 << ctx->pipe, &plane_configs[i]);
11617ee14cdcSGustavo Padovan 		if (ret)
11627ee14cdcSGustavo Padovan 			return ret;
11637ee14cdcSGustavo Padovan 	}
11647ee14cdcSGustavo Padovan 
11655d3d0995SGustavo Padovan 	exynos_plane = &ctx->planes[DEFAULT_WIN];
11667ee14cdcSGustavo Padovan 	ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
11677ee14cdcSGustavo Padovan 					   ctx->pipe, EXYNOS_DISPLAY_TYPE_HDMI,
116893bca243SGustavo Padovan 					   &mixer_crtc_ops, ctx);
116993bca243SGustavo Padovan 	if (IS_ERR(ctx->crtc)) {
1170e2dc3f72SAlban Browaeys 		mixer_ctx_remove(ctx);
117193bca243SGustavo Padovan 		ret = PTR_ERR(ctx->crtc);
117293bca243SGustavo Padovan 		goto free_ctx;
11738103ef1bSAndrzej Hajda 	}
11748103ef1bSAndrzej Hajda 
11758103ef1bSAndrzej Hajda 	return 0;
117693bca243SGustavo Padovan 
117793bca243SGustavo Padovan free_ctx:
117893bca243SGustavo Padovan 	devm_kfree(dev, ctx);
117993bca243SGustavo Padovan 	return ret;
11808103ef1bSAndrzej Hajda }
11818103ef1bSAndrzej Hajda 
11828103ef1bSAndrzej Hajda static void mixer_unbind(struct device *dev, struct device *master, void *data)
11838103ef1bSAndrzej Hajda {
11848103ef1bSAndrzej Hajda 	struct mixer_context *ctx = dev_get_drvdata(dev);
11858103ef1bSAndrzej Hajda 
118693bca243SGustavo Padovan 	mixer_ctx_remove(ctx);
11878103ef1bSAndrzej Hajda }
11888103ef1bSAndrzej Hajda 
11898103ef1bSAndrzej Hajda static const struct component_ops mixer_component_ops = {
11908103ef1bSAndrzej Hajda 	.bind	= mixer_bind,
11918103ef1bSAndrzej Hajda 	.unbind	= mixer_unbind,
11928103ef1bSAndrzej Hajda };
11938103ef1bSAndrzej Hajda 
11948103ef1bSAndrzej Hajda static int mixer_probe(struct platform_device *pdev)
11958103ef1bSAndrzej Hajda {
11968103ef1bSAndrzej Hajda 	struct device *dev = &pdev->dev;
119748f6155aSMarek Szyprowski 	const struct mixer_drv_data *drv;
11988103ef1bSAndrzej Hajda 	struct mixer_context *ctx;
11998103ef1bSAndrzej Hajda 	int ret;
1200d8408326SSeung-Woo Kim 
1201f041b257SSean Paul 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1202f041b257SSean Paul 	if (!ctx) {
1203f041b257SSean Paul 		DRM_ERROR("failed to alloc mixer context.\n");
1204d8408326SSeung-Woo Kim 		return -ENOMEM;
1205f041b257SSean Paul 	}
1206d8408326SSeung-Woo Kim 
120748f6155aSMarek Szyprowski 	drv = of_device_get_match_data(dev);
1208aaf8b49eSRahul Sharma 
12094551789fSSean Paul 	ctx->pdev = pdev;
1210d873ab99SSeung-Woo Kim 	ctx->dev = dev;
12111e123441SRahul Sharma 	ctx->mxr_ver = drv->version;
1212d8408326SSeung-Woo Kim 
1213adeb6f44STobias Jakobi 	if (drv->is_vp_enabled)
1214adeb6f44STobias Jakobi 		__set_bit(MXR_BIT_VP_ENABLED, &ctx->flags);
1215adeb6f44STobias Jakobi 	if (drv->has_sclk)
1216adeb6f44STobias Jakobi 		__set_bit(MXR_BIT_HAS_SCLK, &ctx->flags);
1217adeb6f44STobias Jakobi 
12188103ef1bSAndrzej Hajda 	platform_set_drvdata(pdev, ctx);
1219df5225bcSInki Dae 
1220df5225bcSInki Dae 	ret = component_add(&pdev->dev, &mixer_component_ops);
122186650408SAndrzej Hajda 	if (!ret)
12228103ef1bSAndrzej Hajda 		pm_runtime_enable(dev);
1223df5225bcSInki Dae 
1224df5225bcSInki Dae 	return ret;
1225f37cd5e8SInki Dae }
1226f37cd5e8SInki Dae 
1227d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev)
1228d8408326SSeung-Woo Kim {
12298103ef1bSAndrzej Hajda 	pm_runtime_disable(&pdev->dev);
12308103ef1bSAndrzej Hajda 
1231df5225bcSInki Dae 	component_del(&pdev->dev, &mixer_component_ops);
1232df5225bcSInki Dae 
1233d8408326SSeung-Woo Kim 	return 0;
1234d8408326SSeung-Woo Kim }
1235d8408326SSeung-Woo Kim 
1236e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_suspend(struct device *dev)
1237ccf034a9SGustavo Padovan {
1238ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1239ccf034a9SGustavo Padovan 	struct mixer_resources *res = &ctx->mixer_res;
1240ccf034a9SGustavo Padovan 
1241ccf034a9SGustavo Padovan 	clk_disable_unprepare(res->hdmi);
1242ccf034a9SGustavo Padovan 	clk_disable_unprepare(res->mixer);
1243adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
1244ccf034a9SGustavo Padovan 		clk_disable_unprepare(res->vp);
1245adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags))
1246ccf034a9SGustavo Padovan 			clk_disable_unprepare(res->sclk_mixer);
1247ccf034a9SGustavo Padovan 	}
1248ccf034a9SGustavo Padovan 
1249ccf034a9SGustavo Padovan 	return 0;
1250ccf034a9SGustavo Padovan }
1251ccf034a9SGustavo Padovan 
1252e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_resume(struct device *dev)
1253ccf034a9SGustavo Padovan {
1254ccf034a9SGustavo Padovan 	struct mixer_context *ctx = dev_get_drvdata(dev);
1255ccf034a9SGustavo Padovan 	struct mixer_resources *res = &ctx->mixer_res;
1256ccf034a9SGustavo Padovan 	int ret;
1257ccf034a9SGustavo Padovan 
1258ccf034a9SGustavo Padovan 	ret = clk_prepare_enable(res->mixer);
1259ccf034a9SGustavo Padovan 	if (ret < 0) {
1260ccf034a9SGustavo Padovan 		DRM_ERROR("Failed to prepare_enable the mixer clk [%d]\n", ret);
1261ccf034a9SGustavo Padovan 		return ret;
1262ccf034a9SGustavo Padovan 	}
1263ccf034a9SGustavo Padovan 	ret = clk_prepare_enable(res->hdmi);
1264ccf034a9SGustavo Padovan 	if (ret < 0) {
1265ccf034a9SGustavo Padovan 		DRM_ERROR("Failed to prepare_enable the hdmi clk [%d]\n", ret);
1266ccf034a9SGustavo Padovan 		return ret;
1267ccf034a9SGustavo Padovan 	}
1268adeb6f44STobias Jakobi 	if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
1269ccf034a9SGustavo Padovan 		ret = clk_prepare_enable(res->vp);
1270ccf034a9SGustavo Padovan 		if (ret < 0) {
1271ccf034a9SGustavo Padovan 			DRM_ERROR("Failed to prepare_enable the vp clk [%d]\n",
1272ccf034a9SGustavo Padovan 				  ret);
1273ccf034a9SGustavo Padovan 			return ret;
1274ccf034a9SGustavo Padovan 		}
1275adeb6f44STobias Jakobi 		if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags)) {
1276ccf034a9SGustavo Padovan 			ret = clk_prepare_enable(res->sclk_mixer);
1277ccf034a9SGustavo Padovan 			if (ret < 0) {
1278ccf034a9SGustavo Padovan 				DRM_ERROR("Failed to prepare_enable the " \
1279ccf034a9SGustavo Padovan 					   "sclk_mixer clk [%d]\n",
1280ccf034a9SGustavo Padovan 					  ret);
1281ccf034a9SGustavo Padovan 				return ret;
1282ccf034a9SGustavo Padovan 			}
1283ccf034a9SGustavo Padovan 		}
1284ccf034a9SGustavo Padovan 	}
1285ccf034a9SGustavo Padovan 
1286ccf034a9SGustavo Padovan 	return 0;
1287ccf034a9SGustavo Padovan }
1288ccf034a9SGustavo Padovan 
1289ccf034a9SGustavo Padovan static const struct dev_pm_ops exynos_mixer_pm_ops = {
1290ccf034a9SGustavo Padovan 	SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL)
1291ccf034a9SGustavo Padovan };
1292ccf034a9SGustavo Padovan 
1293d8408326SSeung-Woo Kim struct platform_driver mixer_driver = {
1294d8408326SSeung-Woo Kim 	.driver = {
1295aaf8b49eSRahul Sharma 		.name = "exynos-mixer",
1296d8408326SSeung-Woo Kim 		.owner = THIS_MODULE,
1297ccf034a9SGustavo Padovan 		.pm = &exynos_mixer_pm_ops,
1298aaf8b49eSRahul Sharma 		.of_match_table = mixer_match_types,
1299d8408326SSeung-Woo Kim 	},
1300d8408326SSeung-Woo Kim 	.probe = mixer_probe,
130156550d94SGreg Kroah-Hartman 	.remove = mixer_remove,
1302d8408326SSeung-Woo Kim };
1303