xref: /linux/drivers/gpu/drm/exynos/exynos_mixer.c (revision 87244fa604201c7eee643e5e5e1a19e1f7fc5e3a)
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>
34d8408326SSeung-Woo Kim 
35d8408326SSeung-Woo Kim #include <drm/exynos_drm.h>
36d8408326SSeung-Woo Kim 
37d8408326SSeung-Woo Kim #include "exynos_drm_drv.h"
38663d8766SRahul Sharma #include "exynos_drm_crtc.h"
39d8408326SSeung-Woo Kim #include "exynos_drm_hdmi.h"
401055b39fSInki Dae #include "exynos_drm_iommu.h"
4122b21ae6SJoonyoung Shim 
42d8408326SSeung-Woo Kim #define get_mixer_context(dev)	platform_get_drvdata(to_platform_device(dev))
43d8408326SSeung-Woo Kim 
4422b21ae6SJoonyoung Shim struct hdmi_win_data {
4522b21ae6SJoonyoung Shim 	dma_addr_t		dma_addr;
4622b21ae6SJoonyoung Shim 	dma_addr_t		chroma_dma_addr;
4722b21ae6SJoonyoung Shim 	uint32_t		pixel_format;
4822b21ae6SJoonyoung Shim 	unsigned int		bpp;
4922b21ae6SJoonyoung Shim 	unsigned int		crtc_x;
5022b21ae6SJoonyoung Shim 	unsigned int		crtc_y;
5122b21ae6SJoonyoung Shim 	unsigned int		crtc_width;
5222b21ae6SJoonyoung Shim 	unsigned int		crtc_height;
5322b21ae6SJoonyoung Shim 	unsigned int		fb_x;
5422b21ae6SJoonyoung Shim 	unsigned int		fb_y;
5522b21ae6SJoonyoung Shim 	unsigned int		fb_width;
5622b21ae6SJoonyoung Shim 	unsigned int		fb_height;
578dcb96b6SSeung-Woo Kim 	unsigned int		src_width;
588dcb96b6SSeung-Woo Kim 	unsigned int		src_height;
5922b21ae6SJoonyoung Shim 	unsigned int		mode_width;
6022b21ae6SJoonyoung Shim 	unsigned int		mode_height;
6122b21ae6SJoonyoung Shim 	unsigned int		scan_flags;
62db43fd16SPrathyush K 	bool			enabled;
63db43fd16SPrathyush K 	bool			resume;
6422b21ae6SJoonyoung Shim };
6522b21ae6SJoonyoung Shim 
6622b21ae6SJoonyoung Shim struct mixer_resources {
6722b21ae6SJoonyoung Shim 	int			irq;
6822b21ae6SJoonyoung Shim 	void __iomem		*mixer_regs;
6922b21ae6SJoonyoung Shim 	void __iomem		*vp_regs;
7022b21ae6SJoonyoung Shim 	spinlock_t		reg_slock;
7122b21ae6SJoonyoung Shim 	struct clk		*mixer;
7222b21ae6SJoonyoung Shim 	struct clk		*vp;
7322b21ae6SJoonyoung Shim 	struct clk		*sclk_mixer;
7422b21ae6SJoonyoung Shim 	struct clk		*sclk_hdmi;
7522b21ae6SJoonyoung Shim 	struct clk		*sclk_dac;
7622b21ae6SJoonyoung Shim };
7722b21ae6SJoonyoung Shim 
781e123441SRahul Sharma enum mixer_version_id {
791e123441SRahul Sharma 	MXR_VER_0_0_0_16,
801e123441SRahul Sharma 	MXR_VER_16_0_33_0,
81def5e095SRahul Sharma 	MXR_VER_128_0_0_184,
821e123441SRahul Sharma };
831e123441SRahul Sharma 
8422b21ae6SJoonyoung Shim struct mixer_context {
854551789fSSean Paul 	struct platform_device *pdev;
86cf8fc4f1SJoonyoung Shim 	struct device		*dev;
871055b39fSInki Dae 	struct drm_device	*drm_dev;
8822b21ae6SJoonyoung Shim 	int			pipe;
8922b21ae6SJoonyoung Shim 	bool			interlace;
90cf8fc4f1SJoonyoung Shim 	bool			powered;
911b8e5747SRahul Sharma 	bool			vp_enabled;
92cf8fc4f1SJoonyoung Shim 	u32			int_en;
9322b21ae6SJoonyoung Shim 
94cf8fc4f1SJoonyoung Shim 	struct mutex		mixer_mutex;
9522b21ae6SJoonyoung Shim 	struct mixer_resources	mixer_res;
96a634dd54SJoonyoung Shim 	struct hdmi_win_data	win_data[MIXER_WIN_NR];
971e123441SRahul Sharma 	enum mixer_version_id	mxr_ver;
981055b39fSInki Dae 	void			*parent_ctx;
996e95d5e6SPrathyush K 	wait_queue_head_t	wait_vsync_queue;
1006e95d5e6SPrathyush K 	atomic_t		wait_vsync_event;
1011e123441SRahul Sharma };
1021e123441SRahul Sharma 
1031e123441SRahul Sharma struct mixer_drv_data {
1041e123441SRahul Sharma 	enum mixer_version_id	version;
1051b8e5747SRahul Sharma 	bool					is_vp_enabled;
10622b21ae6SJoonyoung Shim };
10722b21ae6SJoonyoung Shim 
108d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = {
109d8408326SSeung-Woo Kim 	0,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
110d8408326SSeung-Woo Kim 	-1,	-1,	-1,	-1,	-1,	0,	0,	0,
111d8408326SSeung-Woo Kim 	0,	2,	4,	5,	6,	6,	6,	6,
112d8408326SSeung-Woo Kim 	6,	5,	5,	4,	3,	2,	1,	1,
113d8408326SSeung-Woo Kim 	0,	-6,	-12,	-16,	-18,	-20,	-21,	-20,
114d8408326SSeung-Woo Kim 	-20,	-18,	-16,	-13,	-10,	-8,	-5,	-2,
115d8408326SSeung-Woo Kim 	127,	126,	125,	121,	114,	107,	99,	89,
116d8408326SSeung-Woo Kim 	79,	68,	57,	46,	35,	25,	16,	8,
117d8408326SSeung-Woo Kim };
118d8408326SSeung-Woo Kim 
119d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = {
120d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
121d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
122d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
123d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
124d8408326SSeung-Woo Kim 	0,	5,	11,	19,	27,	37,	48,	59,
125d8408326SSeung-Woo Kim 	70,	81,	92,	102,	111,	118,	124,	126,
126d8408326SSeung-Woo Kim 	0,	0,	-1,	-1,	-2,	-3,	-4,	-5,
127d8408326SSeung-Woo Kim 	-6,	-7,	-8,	-8,	-8,	-8,	-6,	-3,
128d8408326SSeung-Woo Kim };
129d8408326SSeung-Woo Kim 
130d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = {
131d8408326SSeung-Woo Kim 	0,	-3,	-6,	-8,	-8,	-8,	-8,	-7,
132d8408326SSeung-Woo Kim 	-6,	-5,	-4,	-3,	-2,	-1,	-1,	0,
133d8408326SSeung-Woo Kim 	127,	126,	124,	118,	111,	102,	92,	81,
134d8408326SSeung-Woo Kim 	70,	59,	48,	37,	27,	19,	11,	5,
135d8408326SSeung-Woo Kim };
136d8408326SSeung-Woo Kim 
137d8408326SSeung-Woo Kim static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id)
138d8408326SSeung-Woo Kim {
139d8408326SSeung-Woo Kim 	return readl(res->vp_regs + reg_id);
140d8408326SSeung-Woo Kim }
141d8408326SSeung-Woo Kim 
142d8408326SSeung-Woo Kim static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id,
143d8408326SSeung-Woo Kim 				 u32 val)
144d8408326SSeung-Woo Kim {
145d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
146d8408326SSeung-Woo Kim }
147d8408326SSeung-Woo Kim 
148d8408326SSeung-Woo Kim static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id,
149d8408326SSeung-Woo Kim 				 u32 val, u32 mask)
150d8408326SSeung-Woo Kim {
151d8408326SSeung-Woo Kim 	u32 old = vp_reg_read(res, reg_id);
152d8408326SSeung-Woo Kim 
153d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
154d8408326SSeung-Woo Kim 	writel(val, res->vp_regs + reg_id);
155d8408326SSeung-Woo Kim }
156d8408326SSeung-Woo Kim 
157d8408326SSeung-Woo Kim static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id)
158d8408326SSeung-Woo Kim {
159d8408326SSeung-Woo Kim 	return readl(res->mixer_regs + reg_id);
160d8408326SSeung-Woo Kim }
161d8408326SSeung-Woo Kim 
162d8408326SSeung-Woo Kim static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id,
163d8408326SSeung-Woo Kim 				 u32 val)
164d8408326SSeung-Woo Kim {
165d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
166d8408326SSeung-Woo Kim }
167d8408326SSeung-Woo Kim 
168d8408326SSeung-Woo Kim static inline void mixer_reg_writemask(struct mixer_resources *res,
169d8408326SSeung-Woo Kim 				 u32 reg_id, u32 val, u32 mask)
170d8408326SSeung-Woo Kim {
171d8408326SSeung-Woo Kim 	u32 old = mixer_reg_read(res, reg_id);
172d8408326SSeung-Woo Kim 
173d8408326SSeung-Woo Kim 	val = (val & mask) | (old & ~mask);
174d8408326SSeung-Woo Kim 	writel(val, res->mixer_regs + reg_id);
175d8408326SSeung-Woo Kim }
176d8408326SSeung-Woo Kim 
177d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx)
178d8408326SSeung-Woo Kim {
179d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
180d8408326SSeung-Woo Kim do { \
181d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
182d8408326SSeung-Woo Kim 		(u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \
183d8408326SSeung-Woo Kim } while (0)
184d8408326SSeung-Woo Kim 
185d8408326SSeung-Woo Kim 	DUMPREG(MXR_STATUS);
186d8408326SSeung-Woo Kim 	DUMPREG(MXR_CFG);
187d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_EN);
188d8408326SSeung-Woo Kim 	DUMPREG(MXR_INT_STATUS);
189d8408326SSeung-Woo Kim 
190d8408326SSeung-Woo Kim 	DUMPREG(MXR_LAYER_CFG);
191d8408326SSeung-Woo Kim 	DUMPREG(MXR_VIDEO_CFG);
192d8408326SSeung-Woo Kim 
193d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_CFG);
194d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_BASE);
195d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SPAN);
196d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_WH);
197d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_SXY);
198d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC0_DXY);
199d8408326SSeung-Woo Kim 
200d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_CFG);
201d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_BASE);
202d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SPAN);
203d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_WH);
204d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_SXY);
205d8408326SSeung-Woo Kim 	DUMPREG(MXR_GRAPHIC1_DXY);
206d8408326SSeung-Woo Kim #undef DUMPREG
207d8408326SSeung-Woo Kim }
208d8408326SSeung-Woo Kim 
209d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx)
210d8408326SSeung-Woo Kim {
211d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
212d8408326SSeung-Woo Kim do { \
213d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS(#reg_id " = %08x\n", \
214d8408326SSeung-Woo Kim 		(u32) readl(ctx->mixer_res.vp_regs + reg_id)); \
215d8408326SSeung-Woo Kim } while (0)
216d8408326SSeung-Woo Kim 
217d8408326SSeung-Woo Kim 	DUMPREG(VP_ENABLE);
218d8408326SSeung-Woo Kim 	DUMPREG(VP_SRESET);
219d8408326SSeung-Woo Kim 	DUMPREG(VP_SHADOW_UPDATE);
220d8408326SSeung-Woo Kim 	DUMPREG(VP_FIELD_ID);
221d8408326SSeung-Woo Kim 	DUMPREG(VP_MODE);
222d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_Y);
223d8408326SSeung-Woo Kim 	DUMPREG(VP_IMG_SIZE_C);
224d8408326SSeung-Woo Kim 	DUMPREG(VP_PER_RATE_CTRL);
225d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_Y_PTR);
226d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_Y_PTR);
227d8408326SSeung-Woo Kim 	DUMPREG(VP_TOP_C_PTR);
228d8408326SSeung-Woo Kim 	DUMPREG(VP_BOT_C_PTR);
229d8408326SSeung-Woo Kim 	DUMPREG(VP_ENDIAN_MODE);
230d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_H_POSITION);
231d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_V_POSITION);
232d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_WIDTH);
233d8408326SSeung-Woo Kim 	DUMPREG(VP_SRC_HEIGHT);
234d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_H_POSITION);
235d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_V_POSITION);
236d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_WIDTH);
237d8408326SSeung-Woo Kim 	DUMPREG(VP_DST_HEIGHT);
238d8408326SSeung-Woo Kim 	DUMPREG(VP_H_RATIO);
239d8408326SSeung-Woo Kim 	DUMPREG(VP_V_RATIO);
240d8408326SSeung-Woo Kim 
241d8408326SSeung-Woo Kim #undef DUMPREG
242d8408326SSeung-Woo Kim }
243d8408326SSeung-Woo Kim 
244d8408326SSeung-Woo Kim static inline void vp_filter_set(struct mixer_resources *res,
245d8408326SSeung-Woo Kim 		int reg_id, const u8 *data, unsigned int size)
246d8408326SSeung-Woo Kim {
247d8408326SSeung-Woo Kim 	/* assure 4-byte align */
248d8408326SSeung-Woo Kim 	BUG_ON(size & 3);
249d8408326SSeung-Woo Kim 	for (; size; size -= 4, reg_id += 4, data += 4) {
250d8408326SSeung-Woo Kim 		u32 val = (data[0] << 24) |  (data[1] << 16) |
251d8408326SSeung-Woo Kim 			(data[2] << 8) | data[3];
252d8408326SSeung-Woo Kim 		vp_reg_write(res, reg_id, val);
253d8408326SSeung-Woo Kim 	}
254d8408326SSeung-Woo Kim }
255d8408326SSeung-Woo Kim 
256d8408326SSeung-Woo Kim static void vp_default_filter(struct mixer_resources *res)
257d8408326SSeung-Woo Kim {
258d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY8_Y0_LL,
259e25e1b66SSachin Kamat 		filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
260d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_Y0_LL,
261e25e1b66SSachin Kamat 		filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
262d8408326SSeung-Woo Kim 	vp_filter_set(res, VP_POLY4_C0_LL,
263e25e1b66SSachin Kamat 		filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
264d8408326SSeung-Woo Kim }
265d8408326SSeung-Woo Kim 
266d8408326SSeung-Woo Kim static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable)
267d8408326SSeung-Woo Kim {
268d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
269d8408326SSeung-Woo Kim 
270d8408326SSeung-Woo Kim 	/* block update on vsync */
271d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, enable ?
272d8408326SSeung-Woo Kim 			MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE);
273d8408326SSeung-Woo Kim 
2741b8e5747SRahul Sharma 	if (ctx->vp_enabled)
275d8408326SSeung-Woo Kim 		vp_reg_write(res, VP_SHADOW_UPDATE, enable ?
276d8408326SSeung-Woo Kim 			VP_SHADOW_UPDATE_ENABLE : 0);
277d8408326SSeung-Woo Kim }
278d8408326SSeung-Woo Kim 
279d8408326SSeung-Woo Kim static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height)
280d8408326SSeung-Woo Kim {
281d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
282d8408326SSeung-Woo Kim 	u32 val;
283d8408326SSeung-Woo Kim 
284d8408326SSeung-Woo Kim 	/* choosing between interlace and progressive mode */
285d8408326SSeung-Woo Kim 	val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE :
286d8408326SSeung-Woo Kim 				MXR_CFG_SCAN_PROGRASSIVE);
287d8408326SSeung-Woo Kim 
288def5e095SRahul Sharma 	if (ctx->mxr_ver != MXR_VER_128_0_0_184) {
289def5e095SRahul Sharma 		/* choosing between proper HD and SD mode */
29029630743SRahul Sharma 		if (height <= 480)
291d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD;
29229630743SRahul Sharma 		else if (height <= 576)
293d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD;
29429630743SRahul Sharma 		else if (height <= 720)
295d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
29629630743SRahul Sharma 		else if (height <= 1080)
297d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD;
298d8408326SSeung-Woo Kim 		else
299d8408326SSeung-Woo Kim 			val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
300def5e095SRahul Sharma 	}
301d8408326SSeung-Woo Kim 
302d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK);
303d8408326SSeung-Woo Kim }
304d8408326SSeung-Woo Kim 
305d8408326SSeung-Woo Kim static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height)
306d8408326SSeung-Woo Kim {
307d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
308d8408326SSeung-Woo Kim 	u32 val;
309d8408326SSeung-Woo Kim 
310d8408326SSeung-Woo Kim 	if (height == 480) {
311d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
312d8408326SSeung-Woo Kim 	} else if (height == 576) {
313d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB601_0_255;
314d8408326SSeung-Woo Kim 	} else if (height == 720) {
315d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
316d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
317d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
318d8408326SSeung-Woo Kim 				(32 << 0));
319d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
320d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
321d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
322d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
323d8408326SSeung-Woo Kim 	} else if (height == 1080) {
324d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
325d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
326d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
327d8408326SSeung-Woo Kim 				(32 << 0));
328d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
329d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
330d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
331d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
332d8408326SSeung-Woo Kim 	} else {
333d8408326SSeung-Woo Kim 		val = MXR_CFG_RGB709_16_235;
334d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_Y,
335d8408326SSeung-Woo Kim 				(1 << 30) | (94 << 20) | (314 << 10) |
336d8408326SSeung-Woo Kim 				(32 << 0));
337d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CB,
338d8408326SSeung-Woo Kim 				(972 << 20) | (851 << 10) | (225 << 0));
339d8408326SSeung-Woo Kim 		mixer_reg_write(res, MXR_CM_COEFF_CR,
340d8408326SSeung-Woo Kim 				(225 << 20) | (820 << 10) | (1004 << 0));
341d8408326SSeung-Woo Kim 	}
342d8408326SSeung-Woo Kim 
343d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
344d8408326SSeung-Woo Kim }
345d8408326SSeung-Woo Kim 
346d8408326SSeung-Woo Kim static void mixer_cfg_layer(struct mixer_context *ctx, int win, bool enable)
347d8408326SSeung-Woo Kim {
348d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
349d8408326SSeung-Woo Kim 	u32 val = enable ? ~0 : 0;
350d8408326SSeung-Woo Kim 
351d8408326SSeung-Woo Kim 	switch (win) {
352d8408326SSeung-Woo Kim 	case 0:
353d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
354d8408326SSeung-Woo Kim 		break;
355d8408326SSeung-Woo Kim 	case 1:
356d8408326SSeung-Woo Kim 		mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
357d8408326SSeung-Woo Kim 		break;
358d8408326SSeung-Woo Kim 	case 2:
3591b8e5747SRahul Sharma 		if (ctx->vp_enabled) {
360d8408326SSeung-Woo Kim 			vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON);
3611b8e5747SRahul Sharma 			mixer_reg_writemask(res, MXR_CFG, val,
3621b8e5747SRahul Sharma 				MXR_CFG_VP_ENABLE);
3631b8e5747SRahul Sharma 		}
364d8408326SSeung-Woo Kim 		break;
365d8408326SSeung-Woo Kim 	}
366d8408326SSeung-Woo Kim }
367d8408326SSeung-Woo Kim 
368d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx)
369d8408326SSeung-Woo Kim {
370d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
371d8408326SSeung-Woo Kim 
372d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
373d8408326SSeung-Woo Kim 
374d8408326SSeung-Woo Kim 	mixer_regs_dump(ctx);
375d8408326SSeung-Woo Kim }
376d8408326SSeung-Woo Kim 
377d8408326SSeung-Woo Kim static void vp_video_buffer(struct mixer_context *ctx, int win)
378d8408326SSeung-Woo Kim {
379d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
380d8408326SSeung-Woo Kim 	unsigned long flags;
381d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
382d8408326SSeung-Woo Kim 	unsigned int x_ratio, y_ratio;
383782953ecSYoungJun Cho 	unsigned int buf_num = 1;
384d8408326SSeung-Woo Kim 	dma_addr_t luma_addr[2], chroma_addr[2];
385d8408326SSeung-Woo Kim 	bool tiled_mode = false;
386d8408326SSeung-Woo Kim 	bool crcb_mode = false;
387d8408326SSeung-Woo Kim 	u32 val;
388d8408326SSeung-Woo Kim 
389d8408326SSeung-Woo Kim 	win_data = &ctx->win_data[win];
390d8408326SSeung-Woo Kim 
391d8408326SSeung-Woo Kim 	switch (win_data->pixel_format) {
392d8408326SSeung-Woo Kim 	case DRM_FORMAT_NV12MT:
393d8408326SSeung-Woo Kim 		tiled_mode = true;
394363b06aaSVille Syrjälä 	case DRM_FORMAT_NV12:
395d8408326SSeung-Woo Kim 		crcb_mode = false;
396d8408326SSeung-Woo Kim 		buf_num = 2;
397d8408326SSeung-Woo Kim 		break;
398d8408326SSeung-Woo Kim 	/* TODO: single buffer format NV12, NV21 */
399d8408326SSeung-Woo Kim 	default:
400d8408326SSeung-Woo Kim 		/* ignore pixel format at disable time */
401d8408326SSeung-Woo Kim 		if (!win_data->dma_addr)
402d8408326SSeung-Woo Kim 			break;
403d8408326SSeung-Woo Kim 
404d8408326SSeung-Woo Kim 		DRM_ERROR("pixel format for vp is wrong [%d].\n",
405d8408326SSeung-Woo Kim 				win_data->pixel_format);
406d8408326SSeung-Woo Kim 		return;
407d8408326SSeung-Woo Kim 	}
408d8408326SSeung-Woo Kim 
409d8408326SSeung-Woo Kim 	/* scaling feature: (src << 16) / dst */
4108dcb96b6SSeung-Woo Kim 	x_ratio = (win_data->src_width << 16) / win_data->crtc_width;
4118dcb96b6SSeung-Woo Kim 	y_ratio = (win_data->src_height << 16) / win_data->crtc_height;
412d8408326SSeung-Woo Kim 
413d8408326SSeung-Woo Kim 	if (buf_num == 2) {
414d8408326SSeung-Woo Kim 		luma_addr[0] = win_data->dma_addr;
415d8408326SSeung-Woo Kim 		chroma_addr[0] = win_data->chroma_dma_addr;
416d8408326SSeung-Woo Kim 	} else {
417d8408326SSeung-Woo Kim 		luma_addr[0] = win_data->dma_addr;
418d8408326SSeung-Woo Kim 		chroma_addr[0] = win_data->dma_addr
4198dcb96b6SSeung-Woo Kim 			+ (win_data->fb_width * win_data->fb_height);
420d8408326SSeung-Woo Kim 	}
421d8408326SSeung-Woo Kim 
422d8408326SSeung-Woo Kim 	if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE) {
423d8408326SSeung-Woo Kim 		ctx->interlace = true;
424d8408326SSeung-Woo Kim 		if (tiled_mode) {
425d8408326SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + 0x40;
426d8408326SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + 0x40;
427d8408326SSeung-Woo Kim 		} else {
4288dcb96b6SSeung-Woo Kim 			luma_addr[1] = luma_addr[0] + win_data->fb_width;
4298dcb96b6SSeung-Woo Kim 			chroma_addr[1] = chroma_addr[0] + win_data->fb_width;
430d8408326SSeung-Woo Kim 		}
431d8408326SSeung-Woo Kim 	} else {
432d8408326SSeung-Woo Kim 		ctx->interlace = false;
433d8408326SSeung-Woo Kim 		luma_addr[1] = 0;
434d8408326SSeung-Woo Kim 		chroma_addr[1] = 0;
435d8408326SSeung-Woo Kim 	}
436d8408326SSeung-Woo Kim 
437d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
438d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
439d8408326SSeung-Woo Kim 
440d8408326SSeung-Woo Kim 	/* interlace or progressive scan mode */
441d8408326SSeung-Woo Kim 	val = (ctx->interlace ? ~0 : 0);
442d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP);
443d8408326SSeung-Woo Kim 
444d8408326SSeung-Woo Kim 	/* setup format */
445d8408326SSeung-Woo Kim 	val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12);
446d8408326SSeung-Woo Kim 	val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
447d8408326SSeung-Woo Kim 	vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK);
448d8408326SSeung-Woo Kim 
449d8408326SSeung-Woo Kim 	/* setting size of input image */
4508dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(win_data->fb_width) |
4518dcb96b6SSeung-Woo Kim 		VP_IMG_VSIZE(win_data->fb_height));
452d8408326SSeung-Woo Kim 	/* chroma height has to reduced by 2 to avoid chroma distorions */
4538dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(win_data->fb_width) |
4548dcb96b6SSeung-Woo Kim 		VP_IMG_VSIZE(win_data->fb_height / 2));
455d8408326SSeung-Woo Kim 
4568dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_WIDTH, win_data->src_width);
4578dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_HEIGHT, win_data->src_height);
458d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_H_POSITION,
4598dcb96b6SSeung-Woo Kim 			VP_SRC_H_POSITION_VAL(win_data->fb_x));
4608dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_SRC_V_POSITION, win_data->fb_y);
461d8408326SSeung-Woo Kim 
4628dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_DST_WIDTH, win_data->crtc_width);
4638dcb96b6SSeung-Woo Kim 	vp_reg_write(res, VP_DST_H_POSITION, win_data->crtc_x);
464d8408326SSeung-Woo Kim 	if (ctx->interlace) {
4658dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height / 2);
4668dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y / 2);
467d8408326SSeung-Woo Kim 	} else {
4688dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_HEIGHT, win_data->crtc_height);
4698dcb96b6SSeung-Woo Kim 		vp_reg_write(res, VP_DST_V_POSITION, win_data->crtc_y);
470d8408326SSeung-Woo Kim 	}
471d8408326SSeung-Woo Kim 
472d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_H_RATIO, x_ratio);
473d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_V_RATIO, y_ratio);
474d8408326SSeung-Woo Kim 
475d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
476d8408326SSeung-Woo Kim 
477d8408326SSeung-Woo Kim 	/* set buffer address to vp */
478d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]);
479d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]);
480d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]);
481d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]);
482d8408326SSeung-Woo Kim 
4838dcb96b6SSeung-Woo Kim 	mixer_cfg_scan(ctx, win_data->mode_height);
4848dcb96b6SSeung-Woo Kim 	mixer_cfg_rgb_fmt(ctx, win_data->mode_height);
485d8408326SSeung-Woo Kim 	mixer_cfg_layer(ctx, win, true);
486d8408326SSeung-Woo Kim 	mixer_run(ctx);
487d8408326SSeung-Woo Kim 
488d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
489d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
490d8408326SSeung-Woo Kim 
491d8408326SSeung-Woo Kim 	vp_regs_dump(ctx);
492d8408326SSeung-Woo Kim }
493d8408326SSeung-Woo Kim 
494aaf8b49eSRahul Sharma static void mixer_layer_update(struct mixer_context *ctx)
495aaf8b49eSRahul Sharma {
496aaf8b49eSRahul Sharma 	struct mixer_resources *res = &ctx->mixer_res;
497aaf8b49eSRahul Sharma 	u32 val;
498aaf8b49eSRahul Sharma 
499aaf8b49eSRahul Sharma 	val = mixer_reg_read(res, MXR_CFG);
500aaf8b49eSRahul Sharma 
501aaf8b49eSRahul Sharma 	/* allow one update per vsync only */
502aaf8b49eSRahul Sharma 	if (!(val & MXR_CFG_LAYER_UPDATE_COUNT_MASK))
503aaf8b49eSRahul Sharma 		mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
504aaf8b49eSRahul Sharma }
505aaf8b49eSRahul Sharma 
506d8408326SSeung-Woo Kim static void mixer_graph_buffer(struct mixer_context *ctx, int win)
507d8408326SSeung-Woo Kim {
508d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
509d8408326SSeung-Woo Kim 	unsigned long flags;
510d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
511d8408326SSeung-Woo Kim 	unsigned int x_ratio, y_ratio;
512d8408326SSeung-Woo Kim 	unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset;
513d8408326SSeung-Woo Kim 	dma_addr_t dma_addr;
514d8408326SSeung-Woo Kim 	unsigned int fmt;
515d8408326SSeung-Woo Kim 	u32 val;
516d8408326SSeung-Woo Kim 
517d8408326SSeung-Woo Kim 	win_data = &ctx->win_data[win];
518d8408326SSeung-Woo Kim 
519d8408326SSeung-Woo Kim 	#define RGB565 4
520d8408326SSeung-Woo Kim 	#define ARGB1555 5
521d8408326SSeung-Woo Kim 	#define ARGB4444 6
522d8408326SSeung-Woo Kim 	#define ARGB8888 7
523d8408326SSeung-Woo Kim 
524d8408326SSeung-Woo Kim 	switch (win_data->bpp) {
525d8408326SSeung-Woo Kim 	case 16:
526d8408326SSeung-Woo Kim 		fmt = ARGB4444;
527d8408326SSeung-Woo Kim 		break;
528d8408326SSeung-Woo Kim 	case 32:
529d8408326SSeung-Woo Kim 		fmt = ARGB8888;
530d8408326SSeung-Woo Kim 		break;
531d8408326SSeung-Woo Kim 	default:
532d8408326SSeung-Woo Kim 		fmt = ARGB8888;
533d8408326SSeung-Woo Kim 	}
534d8408326SSeung-Woo Kim 
535d8408326SSeung-Woo Kim 	/* 2x scaling feature */
536d8408326SSeung-Woo Kim 	x_ratio = 0;
537d8408326SSeung-Woo Kim 	y_ratio = 0;
538d8408326SSeung-Woo Kim 
539d8408326SSeung-Woo Kim 	dst_x_offset = win_data->crtc_x;
540d8408326SSeung-Woo Kim 	dst_y_offset = win_data->crtc_y;
541d8408326SSeung-Woo Kim 
542d8408326SSeung-Woo Kim 	/* converting dma address base and source offset */
5438dcb96b6SSeung-Woo Kim 	dma_addr = win_data->dma_addr
5448dcb96b6SSeung-Woo Kim 		+ (win_data->fb_x * win_data->bpp >> 3)
5458dcb96b6SSeung-Woo Kim 		+ (win_data->fb_y * win_data->fb_width * win_data->bpp >> 3);
546d8408326SSeung-Woo Kim 	src_x_offset = 0;
547d8408326SSeung-Woo Kim 	src_y_offset = 0;
548d8408326SSeung-Woo Kim 
549d8408326SSeung-Woo Kim 	if (win_data->scan_flags & DRM_MODE_FLAG_INTERLACE)
550d8408326SSeung-Woo Kim 		ctx->interlace = true;
551d8408326SSeung-Woo Kim 	else
552d8408326SSeung-Woo Kim 		ctx->interlace = false;
553d8408326SSeung-Woo Kim 
554d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
555d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, false);
556d8408326SSeung-Woo Kim 
557d8408326SSeung-Woo Kim 	/* setup format */
558d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
559d8408326SSeung-Woo Kim 		MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
560d8408326SSeung-Woo Kim 
561d8408326SSeung-Woo Kim 	/* setup geometry */
5628dcb96b6SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_SPAN(win), win_data->fb_width);
563d8408326SSeung-Woo Kim 
564def5e095SRahul Sharma 	/* setup display size */
565def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_128_0_0_184 &&
566def5e095SRahul Sharma 		win == MIXER_DEFAULT_WIN) {
567def5e095SRahul Sharma 		val  = MXR_MXR_RES_HEIGHT(win_data->fb_height);
568def5e095SRahul Sharma 		val |= MXR_MXR_RES_WIDTH(win_data->fb_width);
569def5e095SRahul Sharma 		mixer_reg_write(res, MXR_RESOLUTION, val);
570def5e095SRahul Sharma 	}
571def5e095SRahul Sharma 
5728dcb96b6SSeung-Woo Kim 	val  = MXR_GRP_WH_WIDTH(win_data->crtc_width);
5738dcb96b6SSeung-Woo Kim 	val |= MXR_GRP_WH_HEIGHT(win_data->crtc_height);
574d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_H_SCALE(x_ratio);
575d8408326SSeung-Woo Kim 	val |= MXR_GRP_WH_V_SCALE(y_ratio);
576d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_WH(win), val);
577d8408326SSeung-Woo Kim 
578d8408326SSeung-Woo Kim 	/* setup offsets in source image */
579d8408326SSeung-Woo Kim 	val  = MXR_GRP_SXY_SX(src_x_offset);
580d8408326SSeung-Woo Kim 	val |= MXR_GRP_SXY_SY(src_y_offset);
581d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val);
582d8408326SSeung-Woo Kim 
583d8408326SSeung-Woo Kim 	/* setup offsets in display image */
584d8408326SSeung-Woo Kim 	val  = MXR_GRP_DXY_DX(dst_x_offset);
585d8408326SSeung-Woo Kim 	val |= MXR_GRP_DXY_DY(dst_y_offset);
586d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val);
587d8408326SSeung-Woo Kim 
588d8408326SSeung-Woo Kim 	/* set buffer address to mixer */
589d8408326SSeung-Woo Kim 	mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr);
590d8408326SSeung-Woo Kim 
5918dcb96b6SSeung-Woo Kim 	mixer_cfg_scan(ctx, win_data->mode_height);
5928dcb96b6SSeung-Woo Kim 	mixer_cfg_rgb_fmt(ctx, win_data->mode_height);
593d8408326SSeung-Woo Kim 	mixer_cfg_layer(ctx, win, true);
594aaf8b49eSRahul Sharma 
595aaf8b49eSRahul Sharma 	/* layer update mandatory for mixer 16.0.33.0 */
596def5e095SRahul Sharma 	if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
597def5e095SRahul Sharma 		ctx->mxr_ver == MXR_VER_128_0_0_184)
598aaf8b49eSRahul Sharma 		mixer_layer_update(ctx);
599aaf8b49eSRahul Sharma 
600d8408326SSeung-Woo Kim 	mixer_run(ctx);
601d8408326SSeung-Woo Kim 
602d8408326SSeung-Woo Kim 	mixer_vsync_set_update(ctx, true);
603d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
604d8408326SSeung-Woo Kim }
605d8408326SSeung-Woo Kim 
606d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx)
607d8408326SSeung-Woo Kim {
608d8408326SSeung-Woo Kim 	struct mixer_resources *res = &ctx->mixer_res;
609d8408326SSeung-Woo Kim 	int tries = 100;
610d8408326SSeung-Woo Kim 
611d8408326SSeung-Woo Kim 	vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING);
612d8408326SSeung-Woo Kim 	for (tries = 100; tries; --tries) {
613d8408326SSeung-Woo Kim 		/* waiting until VP_SRESET_PROCESSING is 0 */
614d8408326SSeung-Woo Kim 		if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING)
615d8408326SSeung-Woo Kim 			break;
61609760ea3SSean Paul 		usleep_range(10000, 12000);
617d8408326SSeung-Woo Kim 	}
618d8408326SSeung-Woo Kim 	WARN(tries == 0, "failed to reset Video Processor\n");
619d8408326SSeung-Woo Kim }
620d8408326SSeung-Woo Kim 
621cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx)
622cf8fc4f1SJoonyoung Shim {
623cf8fc4f1SJoonyoung Shim 	struct mixer_resources *res = &ctx->mixer_res;
624cf8fc4f1SJoonyoung Shim 	unsigned long flags;
625cf8fc4f1SJoonyoung Shim 	u32 val; /* value stored to register */
626cf8fc4f1SJoonyoung Shim 
627cf8fc4f1SJoonyoung Shim 	spin_lock_irqsave(&res->reg_slock, flags);
628cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, false);
629cf8fc4f1SJoonyoung Shim 
630cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
631cf8fc4f1SJoonyoung Shim 
632cf8fc4f1SJoonyoung Shim 	/* set output in RGB888 mode */
633cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
634cf8fc4f1SJoonyoung Shim 
635cf8fc4f1SJoonyoung Shim 	/* 16 beat burst in DMA */
636cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST,
637cf8fc4f1SJoonyoung Shim 		MXR_STATUS_BURST_MASK);
638cf8fc4f1SJoonyoung Shim 
639cf8fc4f1SJoonyoung Shim 	/* setting default layer priority: layer1 > layer0 > video
640cf8fc4f1SJoonyoung Shim 	 * because typical usage scenario would be
641cf8fc4f1SJoonyoung Shim 	 * layer1 - OSD
642cf8fc4f1SJoonyoung Shim 	 * layer0 - framebuffer
643cf8fc4f1SJoonyoung Shim 	 * video - video overlay
644cf8fc4f1SJoonyoung Shim 	 */
645cf8fc4f1SJoonyoung Shim 	val = MXR_LAYER_CFG_GRP1_VAL(3);
646cf8fc4f1SJoonyoung Shim 	val |= MXR_LAYER_CFG_GRP0_VAL(2);
6471b8e5747SRahul Sharma 	if (ctx->vp_enabled)
648cf8fc4f1SJoonyoung Shim 		val |= MXR_LAYER_CFG_VP_VAL(1);
649cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_LAYER_CFG, val);
650cf8fc4f1SJoonyoung Shim 
651cf8fc4f1SJoonyoung Shim 	/* setting background color */
652cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR0, 0x008080);
653cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR1, 0x008080);
654cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_BG_COLOR2, 0x008080);
655cf8fc4f1SJoonyoung Shim 
656cf8fc4f1SJoonyoung Shim 	/* setting graphical layers */
657cf8fc4f1SJoonyoung Shim 	val  = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
658cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_WIN_BLEND_EN;
659cf8fc4f1SJoonyoung Shim 	val |= MXR_GRP_CFG_ALPHA_VAL(0xff); /* non-transparent alpha */
660cf8fc4f1SJoonyoung Shim 
6610377f4edSSean Paul 	/* Don't blend layer 0 onto the mixer background */
662cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(0), val);
6630377f4edSSean Paul 
6640377f4edSSean Paul 	/* Blend layer 1 into layer 0 */
6650377f4edSSean Paul 	val |= MXR_GRP_CFG_BLEND_PRE_MUL;
6660377f4edSSean Paul 	val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
667cf8fc4f1SJoonyoung Shim 	mixer_reg_write(res, MXR_GRAPHIC_CFG(1), val);
668cf8fc4f1SJoonyoung Shim 
6695736603bSSeung-Woo Kim 	/* setting video layers */
6705736603bSSeung-Woo Kim 	val = MXR_GRP_CFG_ALPHA_VAL(0);
6715736603bSSeung-Woo Kim 	mixer_reg_write(res, MXR_VIDEO_CFG, val);
6725736603bSSeung-Woo Kim 
6731b8e5747SRahul Sharma 	if (ctx->vp_enabled) {
674cf8fc4f1SJoonyoung Shim 		/* configuration of Video Processor Registers */
675cf8fc4f1SJoonyoung Shim 		vp_win_reset(ctx);
676cf8fc4f1SJoonyoung Shim 		vp_default_filter(res);
6771b8e5747SRahul Sharma 	}
678cf8fc4f1SJoonyoung Shim 
679cf8fc4f1SJoonyoung Shim 	/* disable all layers */
680cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
681cf8fc4f1SJoonyoung Shim 	mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
6821b8e5747SRahul Sharma 	if (ctx->vp_enabled)
683cf8fc4f1SJoonyoung Shim 		mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
684cf8fc4f1SJoonyoung Shim 
685cf8fc4f1SJoonyoung Shim 	mixer_vsync_set_update(ctx, true);
686cf8fc4f1SJoonyoung Shim 	spin_unlock_irqrestore(&res->reg_slock, flags);
687cf8fc4f1SJoonyoung Shim }
688cf8fc4f1SJoonyoung Shim 
6894551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg)
6904551789fSSean Paul {
6914551789fSSean Paul 	struct mixer_context *ctx = arg;
6924551789fSSean Paul 	struct mixer_resources *res = &ctx->mixer_res;
6934551789fSSean Paul 	u32 val, base, shadow;
6944551789fSSean Paul 
6954551789fSSean Paul 	spin_lock(&res->reg_slock);
6964551789fSSean Paul 
6974551789fSSean Paul 	/* read interrupt status for handling and clearing flags for VSYNC */
6984551789fSSean Paul 	val = mixer_reg_read(res, MXR_INT_STATUS);
6994551789fSSean Paul 
7004551789fSSean Paul 	/* handling VSYNC */
7014551789fSSean Paul 	if (val & MXR_INT_STATUS_VSYNC) {
7024551789fSSean Paul 		/* interlace scan need to check shadow register */
7034551789fSSean Paul 		if (ctx->interlace) {
7044551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0));
7054551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0));
7064551789fSSean Paul 			if (base != shadow)
7074551789fSSean Paul 				goto out;
7084551789fSSean Paul 
7094551789fSSean Paul 			base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1));
7104551789fSSean Paul 			shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1));
7114551789fSSean Paul 			if (base != shadow)
7124551789fSSean Paul 				goto out;
7134551789fSSean Paul 		}
7144551789fSSean Paul 
7154551789fSSean Paul 		drm_handle_vblank(ctx->drm_dev, ctx->pipe);
7164551789fSSean Paul 		exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe);
7174551789fSSean Paul 
7184551789fSSean Paul 		/* set wait vsync event to zero and wake up queue. */
7194551789fSSean Paul 		if (atomic_read(&ctx->wait_vsync_event)) {
7204551789fSSean Paul 			atomic_set(&ctx->wait_vsync_event, 0);
7214551789fSSean Paul 			wake_up(&ctx->wait_vsync_queue);
7224551789fSSean Paul 		}
7234551789fSSean Paul 	}
7244551789fSSean Paul 
7254551789fSSean Paul out:
7264551789fSSean Paul 	/* clear interrupts */
7274551789fSSean Paul 	if (~val & MXR_INT_EN_VSYNC) {
7284551789fSSean Paul 		/* vsync interrupt use different bit for read and clear */
7294551789fSSean Paul 		val &= ~MXR_INT_EN_VSYNC;
7304551789fSSean Paul 		val |= MXR_INT_CLEAR_VSYNC;
7314551789fSSean Paul 	}
7324551789fSSean Paul 	mixer_reg_write(res, MXR_INT_STATUS, val);
7334551789fSSean Paul 
7344551789fSSean Paul 	spin_unlock(&res->reg_slock);
7354551789fSSean Paul 
7364551789fSSean Paul 	return IRQ_HANDLED;
7374551789fSSean Paul }
7384551789fSSean Paul 
7394551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx)
7404551789fSSean Paul {
7414551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
7424551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
7434551789fSSean Paul 	struct resource *res;
7444551789fSSean Paul 	int ret;
7454551789fSSean Paul 
7464551789fSSean Paul 	spin_lock_init(&mixer_res->reg_slock);
7474551789fSSean Paul 
7484551789fSSean Paul 	mixer_res->mixer = devm_clk_get(dev, "mixer");
7494551789fSSean Paul 	if (IS_ERR(mixer_res->mixer)) {
7504551789fSSean Paul 		dev_err(dev, "failed to get clock 'mixer'\n");
7514551789fSSean Paul 		return -ENODEV;
7524551789fSSean Paul 	}
7534551789fSSean Paul 
7544551789fSSean Paul 	mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
7554551789fSSean Paul 	if (IS_ERR(mixer_res->sclk_hdmi)) {
7564551789fSSean Paul 		dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
7574551789fSSean Paul 		return -ENODEV;
7584551789fSSean Paul 	}
7594551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
7604551789fSSean Paul 	if (res == NULL) {
7614551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
7624551789fSSean Paul 		return -ENXIO;
7634551789fSSean Paul 	}
7644551789fSSean Paul 
7654551789fSSean Paul 	mixer_res->mixer_regs = devm_ioremap(dev, res->start,
7664551789fSSean Paul 							resource_size(res));
7674551789fSSean Paul 	if (mixer_res->mixer_regs == NULL) {
7684551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
7694551789fSSean Paul 		return -ENXIO;
7704551789fSSean Paul 	}
7714551789fSSean Paul 
7724551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0);
7734551789fSSean Paul 	if (res == NULL) {
7744551789fSSean Paul 		dev_err(dev, "get interrupt resource failed.\n");
7754551789fSSean Paul 		return -ENXIO;
7764551789fSSean Paul 	}
7774551789fSSean Paul 
7784551789fSSean Paul 	ret = devm_request_irq(dev, res->start, mixer_irq_handler,
7794551789fSSean Paul 						0, "drm_mixer", mixer_ctx);
7804551789fSSean Paul 	if (ret) {
7814551789fSSean Paul 		dev_err(dev, "request interrupt failed.\n");
7824551789fSSean Paul 		return ret;
7834551789fSSean Paul 	}
7844551789fSSean Paul 	mixer_res->irq = res->start;
7854551789fSSean Paul 
7864551789fSSean Paul 	return 0;
7874551789fSSean Paul }
7884551789fSSean Paul 
7894551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx)
7904551789fSSean Paul {
7914551789fSSean Paul 	struct device *dev = &mixer_ctx->pdev->dev;
7924551789fSSean Paul 	struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
7934551789fSSean Paul 	struct resource *res;
7944551789fSSean Paul 
7954551789fSSean Paul 	mixer_res->vp = devm_clk_get(dev, "vp");
7964551789fSSean Paul 	if (IS_ERR(mixer_res->vp)) {
7974551789fSSean Paul 		dev_err(dev, "failed to get clock 'vp'\n");
7984551789fSSean Paul 		return -ENODEV;
7994551789fSSean Paul 	}
8004551789fSSean Paul 	mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
8014551789fSSean Paul 	if (IS_ERR(mixer_res->sclk_mixer)) {
8024551789fSSean Paul 		dev_err(dev, "failed to get clock 'sclk_mixer'\n");
8034551789fSSean Paul 		return -ENODEV;
8044551789fSSean Paul 	}
8054551789fSSean Paul 	mixer_res->sclk_dac = devm_clk_get(dev, "sclk_dac");
8064551789fSSean Paul 	if (IS_ERR(mixer_res->sclk_dac)) {
8074551789fSSean Paul 		dev_err(dev, "failed to get clock 'sclk_dac'\n");
8084551789fSSean Paul 		return -ENODEV;
8094551789fSSean Paul 	}
8104551789fSSean Paul 
8114551789fSSean Paul 	if (mixer_res->sclk_hdmi)
8124551789fSSean Paul 		clk_set_parent(mixer_res->sclk_mixer, mixer_res->sclk_hdmi);
8134551789fSSean Paul 
8144551789fSSean Paul 	res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
8154551789fSSean Paul 	if (res == NULL) {
8164551789fSSean Paul 		dev_err(dev, "get memory resource failed.\n");
8174551789fSSean Paul 		return -ENXIO;
8184551789fSSean Paul 	}
8194551789fSSean Paul 
8204551789fSSean Paul 	mixer_res->vp_regs = devm_ioremap(dev, res->start,
8214551789fSSean Paul 							resource_size(res));
8224551789fSSean Paul 	if (mixer_res->vp_regs == NULL) {
8234551789fSSean Paul 		dev_err(dev, "register mapping failed.\n");
8244551789fSSean Paul 		return -ENXIO;
8254551789fSSean Paul 	}
8264551789fSSean Paul 
8274551789fSSean Paul 	return 0;
8284551789fSSean Paul }
8294551789fSSean Paul 
8304551789fSSean Paul static int mixer_initialize(void *ctx, struct drm_device *drm_dev)
8314551789fSSean Paul {
8324551789fSSean Paul 	int ret;
8334551789fSSean Paul 	struct mixer_context *mixer_ctx = ctx;
8344551789fSSean Paul 
8354551789fSSean Paul 	mixer_ctx->drm_dev = drm_dev;
8364551789fSSean Paul 
8374551789fSSean Paul 	/* acquire resources: regs, irqs, clocks */
8384551789fSSean Paul 	ret = mixer_resources_init(mixer_ctx);
8394551789fSSean Paul 	if (ret) {
8404551789fSSean Paul 		DRM_ERROR("mixer_resources_init failed ret=%d\n", ret);
8414551789fSSean Paul 		return ret;
8424551789fSSean Paul 	}
8434551789fSSean Paul 
8444551789fSSean Paul 	if (mixer_ctx->vp_enabled) {
8454551789fSSean Paul 		/* acquire vp resources: regs, irqs, clocks */
8464551789fSSean Paul 		ret = vp_resources_init(mixer_ctx);
8474551789fSSean Paul 		if (ret) {
8484551789fSSean Paul 			DRM_ERROR("vp_resources_init failed ret=%d\n", ret);
8494551789fSSean Paul 			return ret;
8504551789fSSean Paul 		}
8514551789fSSean Paul 	}
8524551789fSSean Paul 
8534551789fSSean Paul 	return ret;
8544551789fSSean Paul }
8554551789fSSean Paul 
8561055b39fSInki Dae static int mixer_iommu_on(void *ctx, bool enable)
8571055b39fSInki Dae {
8581055b39fSInki Dae 	struct mixer_context *mdata = ctx;
8591055b39fSInki Dae 
8604551789fSSean Paul 	if (is_drm_iommu_supported(mdata->drm_dev)) {
8611055b39fSInki Dae 		if (enable)
8624551789fSSean Paul 			return drm_iommu_attach_device(mdata->drm_dev,
8634551789fSSean Paul 					mdata->dev);
8641055b39fSInki Dae 
8654551789fSSean Paul 		drm_iommu_detach_device(mdata->drm_dev, mdata->dev);
8661055b39fSInki Dae 	}
8671055b39fSInki Dae 	return 0;
8681055b39fSInki Dae }
8691055b39fSInki Dae 
870d8408326SSeung-Woo Kim static int mixer_enable_vblank(void *ctx, int pipe)
871d8408326SSeung-Woo Kim {
872d8408326SSeung-Woo Kim 	struct mixer_context *mixer_ctx = ctx;
873d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
874d8408326SSeung-Woo Kim 
875d8408326SSeung-Woo Kim 	mixer_ctx->pipe = pipe;
876d8408326SSeung-Woo Kim 
877d8408326SSeung-Woo Kim 	/* enable vsync interrupt */
878d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_INT_EN, MXR_INT_EN_VSYNC,
879d8408326SSeung-Woo Kim 			MXR_INT_EN_VSYNC);
880d8408326SSeung-Woo Kim 
881d8408326SSeung-Woo Kim 	return 0;
882d8408326SSeung-Woo Kim }
883d8408326SSeung-Woo Kim 
884d8408326SSeung-Woo Kim static void mixer_disable_vblank(void *ctx)
885d8408326SSeung-Woo Kim {
886d8408326SSeung-Woo Kim 	struct mixer_context *mixer_ctx = ctx;
887d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
888d8408326SSeung-Woo Kim 
889d8408326SSeung-Woo Kim 	/* disable vsync interrupt */
890d8408326SSeung-Woo Kim 	mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
891d8408326SSeung-Woo Kim }
892d8408326SSeung-Woo Kim 
893d8408326SSeung-Woo Kim static void mixer_win_mode_set(void *ctx,
894d8408326SSeung-Woo Kim 			      struct exynos_drm_overlay *overlay)
895d8408326SSeung-Woo Kim {
896d8408326SSeung-Woo Kim 	struct mixer_context *mixer_ctx = ctx;
897d8408326SSeung-Woo Kim 	struct hdmi_win_data *win_data;
898d8408326SSeung-Woo Kim 	int win;
899d8408326SSeung-Woo Kim 
900d8408326SSeung-Woo Kim 	if (!overlay) {
901d8408326SSeung-Woo Kim 		DRM_ERROR("overlay is NULL\n");
902d8408326SSeung-Woo Kim 		return;
903d8408326SSeung-Woo Kim 	}
904d8408326SSeung-Woo Kim 
905d8408326SSeung-Woo Kim 	DRM_DEBUG_KMS("set [%d]x[%d] at (%d,%d) to [%d]x[%d] at (%d,%d)\n",
906d8408326SSeung-Woo Kim 				 overlay->fb_width, overlay->fb_height,
907d8408326SSeung-Woo Kim 				 overlay->fb_x, overlay->fb_y,
908d8408326SSeung-Woo Kim 				 overlay->crtc_width, overlay->crtc_height,
909d8408326SSeung-Woo Kim 				 overlay->crtc_x, overlay->crtc_y);
910d8408326SSeung-Woo Kim 
911d8408326SSeung-Woo Kim 	win = overlay->zpos;
912d8408326SSeung-Woo Kim 	if (win == DEFAULT_ZPOS)
913a2ee151bSJoonyoung Shim 		win = MIXER_DEFAULT_WIN;
914d8408326SSeung-Woo Kim 
9151586d80cSKrzysztof Kozlowski 	if (win < 0 || win >= MIXER_WIN_NR) {
916cf8fc4f1SJoonyoung Shim 		DRM_ERROR("mixer window[%d] is wrong\n", win);
917d8408326SSeung-Woo Kim 		return;
918d8408326SSeung-Woo Kim 	}
919d8408326SSeung-Woo Kim 
920d8408326SSeung-Woo Kim 	win_data = &mixer_ctx->win_data[win];
921d8408326SSeung-Woo Kim 
922d8408326SSeung-Woo Kim 	win_data->dma_addr = overlay->dma_addr[0];
923d8408326SSeung-Woo Kim 	win_data->chroma_dma_addr = overlay->dma_addr[1];
924d8408326SSeung-Woo Kim 	win_data->pixel_format = overlay->pixel_format;
925d8408326SSeung-Woo Kim 	win_data->bpp = overlay->bpp;
926d8408326SSeung-Woo Kim 
927d8408326SSeung-Woo Kim 	win_data->crtc_x = overlay->crtc_x;
928d8408326SSeung-Woo Kim 	win_data->crtc_y = overlay->crtc_y;
929d8408326SSeung-Woo Kim 	win_data->crtc_width = overlay->crtc_width;
930d8408326SSeung-Woo Kim 	win_data->crtc_height = overlay->crtc_height;
931d8408326SSeung-Woo Kim 
932d8408326SSeung-Woo Kim 	win_data->fb_x = overlay->fb_x;
933d8408326SSeung-Woo Kim 	win_data->fb_y = overlay->fb_y;
934d8408326SSeung-Woo Kim 	win_data->fb_width = overlay->fb_width;
935d8408326SSeung-Woo Kim 	win_data->fb_height = overlay->fb_height;
9368dcb96b6SSeung-Woo Kim 	win_data->src_width = overlay->src_width;
9378dcb96b6SSeung-Woo Kim 	win_data->src_height = overlay->src_height;
938d8408326SSeung-Woo Kim 
939d8408326SSeung-Woo Kim 	win_data->mode_width = overlay->mode_width;
940d8408326SSeung-Woo Kim 	win_data->mode_height = overlay->mode_height;
941d8408326SSeung-Woo Kim 
942d8408326SSeung-Woo Kim 	win_data->scan_flags = overlay->scan_flag;
943d8408326SSeung-Woo Kim }
944d8408326SSeung-Woo Kim 
945cf8fc4f1SJoonyoung Shim static void mixer_win_commit(void *ctx, int win)
946d8408326SSeung-Woo Kim {
947d8408326SSeung-Woo Kim 	struct mixer_context *mixer_ctx = ctx;
948d8408326SSeung-Woo Kim 
949cbc4c33dSYoungJun Cho 	DRM_DEBUG_KMS("win: %d\n", win);
950d8408326SSeung-Woo Kim 
951dda9012bSShirish S 	mutex_lock(&mixer_ctx->mixer_mutex);
952dda9012bSShirish S 	if (!mixer_ctx->powered) {
953dda9012bSShirish S 		mutex_unlock(&mixer_ctx->mixer_mutex);
954dda9012bSShirish S 		return;
955dda9012bSShirish S 	}
956dda9012bSShirish S 	mutex_unlock(&mixer_ctx->mixer_mutex);
957dda9012bSShirish S 
9581b8e5747SRahul Sharma 	if (win > 1 && mixer_ctx->vp_enabled)
959d8408326SSeung-Woo Kim 		vp_video_buffer(mixer_ctx, win);
960d8408326SSeung-Woo Kim 	else
961d8408326SSeung-Woo Kim 		mixer_graph_buffer(mixer_ctx, win);
962db43fd16SPrathyush K 
963db43fd16SPrathyush K 	mixer_ctx->win_data[win].enabled = true;
964d8408326SSeung-Woo Kim }
965d8408326SSeung-Woo Kim 
966cf8fc4f1SJoonyoung Shim static void mixer_win_disable(void *ctx, int win)
967d8408326SSeung-Woo Kim {
968d8408326SSeung-Woo Kim 	struct mixer_context *mixer_ctx = ctx;
969d8408326SSeung-Woo Kim 	struct mixer_resources *res = &mixer_ctx->mixer_res;
970d8408326SSeung-Woo Kim 	unsigned long flags;
971d8408326SSeung-Woo Kim 
972cbc4c33dSYoungJun Cho 	DRM_DEBUG_KMS("win: %d\n", win);
973d8408326SSeung-Woo Kim 
974db43fd16SPrathyush K 	mutex_lock(&mixer_ctx->mixer_mutex);
975db43fd16SPrathyush K 	if (!mixer_ctx->powered) {
976db43fd16SPrathyush K 		mutex_unlock(&mixer_ctx->mixer_mutex);
977db43fd16SPrathyush K 		mixer_ctx->win_data[win].resume = false;
978db43fd16SPrathyush K 		return;
979db43fd16SPrathyush K 	}
980db43fd16SPrathyush K 	mutex_unlock(&mixer_ctx->mixer_mutex);
981db43fd16SPrathyush K 
982d8408326SSeung-Woo Kim 	spin_lock_irqsave(&res->reg_slock, flags);
983d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, false);
984d8408326SSeung-Woo Kim 
985d8408326SSeung-Woo Kim 	mixer_cfg_layer(mixer_ctx, win, false);
986d8408326SSeung-Woo Kim 
987d8408326SSeung-Woo Kim 	mixer_vsync_set_update(mixer_ctx, true);
988d8408326SSeung-Woo Kim 	spin_unlock_irqrestore(&res->reg_slock, flags);
989db43fd16SPrathyush K 
990db43fd16SPrathyush K 	mixer_ctx->win_data[win].enabled = false;
991d8408326SSeung-Woo Kim }
992d8408326SSeung-Woo Kim 
99316844fb1SRahul Sharma static int mixer_check_mode(void *ctx, struct drm_display_mode *mode)
9940ea6822fSRahul Sharma {
995def5e095SRahul Sharma 	struct mixer_context *mixer_ctx = ctx;
9960ea6822fSRahul Sharma 	u32 w, h;
9970ea6822fSRahul Sharma 
99816844fb1SRahul Sharma 	w = mode->hdisplay;
99916844fb1SRahul Sharma 	h = mode->vdisplay;
10000ea6822fSRahul Sharma 
100116844fb1SRahul Sharma 	DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n",
100216844fb1SRahul Sharma 		mode->hdisplay, mode->vdisplay, mode->vrefresh,
100316844fb1SRahul Sharma 		(mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
10040ea6822fSRahul Sharma 
1005def5e095SRahul Sharma 	if (mixer_ctx->mxr_ver == MXR_VER_0_0_0_16 ||
1006def5e095SRahul Sharma 		mixer_ctx->mxr_ver == MXR_VER_128_0_0_184)
1007def5e095SRahul Sharma 		return 0;
1008def5e095SRahul Sharma 
10090ea6822fSRahul Sharma 	if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
10100ea6822fSRahul Sharma 		(w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
10110ea6822fSRahul Sharma 		(w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
10120ea6822fSRahul Sharma 		return 0;
10130ea6822fSRahul Sharma 
10140ea6822fSRahul Sharma 	return -EINVAL;
10150ea6822fSRahul Sharma }
10168137a2e2SPrathyush K static void mixer_wait_for_vblank(void *ctx)
10178137a2e2SPrathyush K {
10188137a2e2SPrathyush K 	struct mixer_context *mixer_ctx = ctx;
10198137a2e2SPrathyush K 
10206e95d5e6SPrathyush K 	mutex_lock(&mixer_ctx->mixer_mutex);
10216e95d5e6SPrathyush K 	if (!mixer_ctx->powered) {
10226e95d5e6SPrathyush K 		mutex_unlock(&mixer_ctx->mixer_mutex);
10236e95d5e6SPrathyush K 		return;
10246e95d5e6SPrathyush K 	}
10256e95d5e6SPrathyush K 	mutex_unlock(&mixer_ctx->mixer_mutex);
10266e95d5e6SPrathyush K 
10276e95d5e6SPrathyush K 	atomic_set(&mixer_ctx->wait_vsync_event, 1);
10286e95d5e6SPrathyush K 
10296e95d5e6SPrathyush K 	/*
10306e95d5e6SPrathyush K 	 * wait for MIXER to signal VSYNC interrupt or return after
10316e95d5e6SPrathyush K 	 * timeout which is set to 50ms (refresh rate of 20).
10326e95d5e6SPrathyush K 	 */
10336e95d5e6SPrathyush K 	if (!wait_event_timeout(mixer_ctx->wait_vsync_queue,
10346e95d5e6SPrathyush K 				!atomic_read(&mixer_ctx->wait_vsync_event),
1035bfd8303aSDaniel Vetter 				HZ/20))
10368137a2e2SPrathyush K 		DRM_DEBUG_KMS("vblank wait timed out.\n");
10378137a2e2SPrathyush K }
10388137a2e2SPrathyush K 
1039db43fd16SPrathyush K static void mixer_window_suspend(struct mixer_context *ctx)
1040db43fd16SPrathyush K {
1041db43fd16SPrathyush K 	struct hdmi_win_data *win_data;
1042db43fd16SPrathyush K 	int i;
1043db43fd16SPrathyush K 
1044db43fd16SPrathyush K 	for (i = 0; i < MIXER_WIN_NR; i++) {
1045db43fd16SPrathyush K 		win_data = &ctx->win_data[i];
1046db43fd16SPrathyush K 		win_data->resume = win_data->enabled;
1047db43fd16SPrathyush K 		mixer_win_disable(ctx, i);
1048db43fd16SPrathyush K 	}
1049db43fd16SPrathyush K 	mixer_wait_for_vblank(ctx);
1050db43fd16SPrathyush K }
1051db43fd16SPrathyush K 
1052db43fd16SPrathyush K static void mixer_window_resume(struct mixer_context *ctx)
1053db43fd16SPrathyush K {
1054db43fd16SPrathyush K 	struct hdmi_win_data *win_data;
1055db43fd16SPrathyush K 	int i;
1056db43fd16SPrathyush K 
1057db43fd16SPrathyush K 	for (i = 0; i < MIXER_WIN_NR; i++) {
1058db43fd16SPrathyush K 		win_data = &ctx->win_data[i];
1059db43fd16SPrathyush K 		win_data->enabled = win_data->resume;
1060db43fd16SPrathyush K 		win_data->resume = false;
1061*87244fa6SSean Paul 		if (win_data->enabled)
1062*87244fa6SSean Paul 			mixer_win_commit(ctx, i);
1063db43fd16SPrathyush K 	}
1064db43fd16SPrathyush K }
1065db43fd16SPrathyush K 
1066db43fd16SPrathyush K static void mixer_poweron(struct mixer_context *ctx)
1067db43fd16SPrathyush K {
1068db43fd16SPrathyush K 	struct mixer_resources *res = &ctx->mixer_res;
1069db43fd16SPrathyush K 
1070db43fd16SPrathyush K 	mutex_lock(&ctx->mixer_mutex);
1071db43fd16SPrathyush K 	if (ctx->powered) {
1072db43fd16SPrathyush K 		mutex_unlock(&ctx->mixer_mutex);
1073db43fd16SPrathyush K 		return;
1074db43fd16SPrathyush K 	}
1075db43fd16SPrathyush K 	ctx->powered = true;
1076db43fd16SPrathyush K 	mutex_unlock(&ctx->mixer_mutex);
1077db43fd16SPrathyush K 
10780bfb1f8bSSean Paul 	clk_prepare_enable(res->mixer);
1079db43fd16SPrathyush K 	if (ctx->vp_enabled) {
10800bfb1f8bSSean Paul 		clk_prepare_enable(res->vp);
10810bfb1f8bSSean Paul 		clk_prepare_enable(res->sclk_mixer);
1082db43fd16SPrathyush K 	}
1083db43fd16SPrathyush K 
1084db43fd16SPrathyush K 	mixer_reg_write(res, MXR_INT_EN, ctx->int_en);
1085db43fd16SPrathyush K 	mixer_win_reset(ctx);
1086db43fd16SPrathyush K 
1087db43fd16SPrathyush K 	mixer_window_resume(ctx);
1088db43fd16SPrathyush K }
1089db43fd16SPrathyush K 
1090db43fd16SPrathyush K static void mixer_poweroff(struct mixer_context *ctx)
1091db43fd16SPrathyush K {
1092db43fd16SPrathyush K 	struct mixer_resources *res = &ctx->mixer_res;
1093db43fd16SPrathyush K 
1094db43fd16SPrathyush K 	mutex_lock(&ctx->mixer_mutex);
1095db43fd16SPrathyush K 	if (!ctx->powered)
1096db43fd16SPrathyush K 		goto out;
1097db43fd16SPrathyush K 	mutex_unlock(&ctx->mixer_mutex);
1098db43fd16SPrathyush K 
1099db43fd16SPrathyush K 	mixer_window_suspend(ctx);
1100db43fd16SPrathyush K 
1101db43fd16SPrathyush K 	ctx->int_en = mixer_reg_read(res, MXR_INT_EN);
1102db43fd16SPrathyush K 
11030bfb1f8bSSean Paul 	clk_disable_unprepare(res->mixer);
1104db43fd16SPrathyush K 	if (ctx->vp_enabled) {
11050bfb1f8bSSean Paul 		clk_disable_unprepare(res->vp);
11060bfb1f8bSSean Paul 		clk_disable_unprepare(res->sclk_mixer);
1107db43fd16SPrathyush K 	}
1108db43fd16SPrathyush K 
1109db43fd16SPrathyush K 	mutex_lock(&ctx->mixer_mutex);
1110db43fd16SPrathyush K 	ctx->powered = false;
1111db43fd16SPrathyush K 
1112db43fd16SPrathyush K out:
1113db43fd16SPrathyush K 	mutex_unlock(&ctx->mixer_mutex);
1114db43fd16SPrathyush K }
1115db43fd16SPrathyush K 
1116db43fd16SPrathyush K static void mixer_dpms(void *ctx, int mode)
1117db43fd16SPrathyush K {
1118db43fd16SPrathyush K 	struct mixer_context *mixer_ctx = ctx;
1119db43fd16SPrathyush K 
1120db43fd16SPrathyush K 	switch (mode) {
1121db43fd16SPrathyush K 	case DRM_MODE_DPMS_ON:
1122000f1308SRahul Sharma 		if (pm_runtime_suspended(mixer_ctx->dev))
1123000f1308SRahul Sharma 			pm_runtime_get_sync(mixer_ctx->dev);
1124db43fd16SPrathyush K 		break;
1125db43fd16SPrathyush K 	case DRM_MODE_DPMS_STANDBY:
1126db43fd16SPrathyush K 	case DRM_MODE_DPMS_SUSPEND:
1127db43fd16SPrathyush K 	case DRM_MODE_DPMS_OFF:
1128000f1308SRahul Sharma 		if (!pm_runtime_suspended(mixer_ctx->dev))
1129000f1308SRahul Sharma 			pm_runtime_put_sync(mixer_ctx->dev);
1130db43fd16SPrathyush K 		break;
1131db43fd16SPrathyush K 	default:
1132db43fd16SPrathyush K 		DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode);
1133db43fd16SPrathyush K 		break;
1134db43fd16SPrathyush K 	}
1135db43fd16SPrathyush K }
1136db43fd16SPrathyush K 
1137578b6065SJoonyoung Shim static struct exynos_mixer_ops mixer_ops = {
1138578b6065SJoonyoung Shim 	/* manager */
11394551789fSSean Paul 	.initialize		= mixer_initialize,
11401055b39fSInki Dae 	.iommu_on		= mixer_iommu_on,
1141d8408326SSeung-Woo Kim 	.enable_vblank		= mixer_enable_vblank,
1142d8408326SSeung-Woo Kim 	.disable_vblank		= mixer_disable_vblank,
11438137a2e2SPrathyush K 	.wait_for_vblank	= mixer_wait_for_vblank,
1144cf8fc4f1SJoonyoung Shim 	.dpms			= mixer_dpms,
1145d8408326SSeung-Woo Kim 	.win_mode_set		= mixer_win_mode_set,
1146d8408326SSeung-Woo Kim 	.win_commit		= mixer_win_commit,
1147d8408326SSeung-Woo Kim 	.win_disable		= mixer_win_disable,
11480ea6822fSRahul Sharma 
11490ea6822fSRahul Sharma 	/* display */
115016844fb1SRahul Sharma 	.check_mode		= mixer_check_mode,
1151d8408326SSeung-Woo Kim };
1152d8408326SSeung-Woo Kim 
1153def5e095SRahul Sharma static struct mixer_drv_data exynos5420_mxr_drv_data = {
1154def5e095SRahul Sharma 	.version = MXR_VER_128_0_0_184,
1155def5e095SRahul Sharma 	.is_vp_enabled = 0,
1156def5e095SRahul Sharma };
1157def5e095SRahul Sharma 
1158cc57caf0SRahul Sharma static struct mixer_drv_data exynos5250_mxr_drv_data = {
1159aaf8b49eSRahul Sharma 	.version = MXR_VER_16_0_33_0,
1160aaf8b49eSRahul Sharma 	.is_vp_enabled = 0,
1161aaf8b49eSRahul Sharma };
1162aaf8b49eSRahul Sharma 
1163cc57caf0SRahul Sharma static struct mixer_drv_data exynos4210_mxr_drv_data = {
11641e123441SRahul Sharma 	.version = MXR_VER_0_0_0_16,
11651b8e5747SRahul Sharma 	.is_vp_enabled = 1,
11661e123441SRahul Sharma };
11671e123441SRahul Sharma 
11681e123441SRahul Sharma static struct platform_device_id mixer_driver_types[] = {
11691e123441SRahul Sharma 	{
11701e123441SRahul Sharma 		.name		= "s5p-mixer",
1171cc57caf0SRahul Sharma 		.driver_data	= (unsigned long)&exynos4210_mxr_drv_data,
11721e123441SRahul Sharma 	}, {
1173aaf8b49eSRahul Sharma 		.name		= "exynos5-mixer",
1174cc57caf0SRahul Sharma 		.driver_data	= (unsigned long)&exynos5250_mxr_drv_data,
1175aaf8b49eSRahul Sharma 	}, {
1176aaf8b49eSRahul Sharma 		/* end node */
1177aaf8b49eSRahul Sharma 	}
1178aaf8b49eSRahul Sharma };
1179aaf8b49eSRahul Sharma 
1180aaf8b49eSRahul Sharma static struct of_device_id mixer_match_types[] = {
1181aaf8b49eSRahul Sharma 	{
1182aaf8b49eSRahul Sharma 		.compatible = "samsung,exynos5-mixer",
1183cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1184cc57caf0SRahul Sharma 	}, {
1185cc57caf0SRahul Sharma 		.compatible = "samsung,exynos5250-mixer",
1186cc57caf0SRahul Sharma 		.data	= &exynos5250_mxr_drv_data,
1187aaf8b49eSRahul Sharma 	}, {
1188def5e095SRahul Sharma 		.compatible = "samsung,exynos5420-mixer",
1189def5e095SRahul Sharma 		.data	= &exynos5420_mxr_drv_data,
1190def5e095SRahul Sharma 	}, {
11911e123441SRahul Sharma 		/* end node */
11921e123441SRahul Sharma 	}
11931e123441SRahul Sharma };
11941e123441SRahul Sharma 
119556550d94SGreg Kroah-Hartman static int mixer_probe(struct platform_device *pdev)
1196d8408326SSeung-Woo Kim {
1197d8408326SSeung-Woo Kim 	struct device *dev = &pdev->dev;
1198d8408326SSeung-Woo Kim 	struct exynos_drm_hdmi_context *drm_hdmi_ctx;
1199d8408326SSeung-Woo Kim 	struct mixer_context *ctx;
12001e123441SRahul Sharma 	struct mixer_drv_data *drv;
1201d8408326SSeung-Woo Kim 
1202d8408326SSeung-Woo Kim 	dev_info(dev, "probe start\n");
1203d8408326SSeung-Woo Kim 
1204d873ab99SSeung-Woo Kim 	drm_hdmi_ctx = devm_kzalloc(dev, sizeof(*drm_hdmi_ctx),
12059416dfa7SSachin Kamat 								GFP_KERNEL);
120638bb5253SSachin Kamat 	if (!drm_hdmi_ctx)
1207d8408326SSeung-Woo Kim 		return -ENOMEM;
1208d8408326SSeung-Woo Kim 
1209d873ab99SSeung-Woo Kim 	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
121038bb5253SSachin Kamat 	if (!ctx)
1211d8408326SSeung-Woo Kim 		return -ENOMEM;
1212d8408326SSeung-Woo Kim 
1213cf8fc4f1SJoonyoung Shim 	mutex_init(&ctx->mixer_mutex);
1214cf8fc4f1SJoonyoung Shim 
1215aaf8b49eSRahul Sharma 	if (dev->of_node) {
1216aaf8b49eSRahul Sharma 		const struct of_device_id *match;
1217e436b09dSSachin Kamat 		match = of_match_node(mixer_match_types, dev->of_node);
12182cdc53b3SRahul Sharma 		drv = (struct mixer_drv_data *)match->data;
1219aaf8b49eSRahul Sharma 	} else {
1220aaf8b49eSRahul Sharma 		drv = (struct mixer_drv_data *)
1221aaf8b49eSRahul Sharma 			platform_get_device_id(pdev)->driver_data;
1222aaf8b49eSRahul Sharma 	}
1223aaf8b49eSRahul Sharma 
12244551789fSSean Paul 	ctx->pdev = pdev;
1225d873ab99SSeung-Woo Kim 	ctx->dev = dev;
12261055b39fSInki Dae 	ctx->parent_ctx = (void *)drm_hdmi_ctx;
1227d8408326SSeung-Woo Kim 	drm_hdmi_ctx->ctx = (void *)ctx;
12281b8e5747SRahul Sharma 	ctx->vp_enabled = drv->is_vp_enabled;
12291e123441SRahul Sharma 	ctx->mxr_ver = drv->version;
123057ed0f7bSDaniel Vetter 	init_waitqueue_head(&ctx->wait_vsync_queue);
12316e95d5e6SPrathyush K 	atomic_set(&ctx->wait_vsync_event, 0);
1232d8408326SSeung-Woo Kim 
1233d8408326SSeung-Woo Kim 	platform_set_drvdata(pdev, drm_hdmi_ctx);
1234d8408326SSeung-Woo Kim 
1235768c3059SRahul Sharma 	/* attach mixer driver to common hdmi. */
1236768c3059SRahul Sharma 	exynos_mixer_drv_attach(drm_hdmi_ctx);
1237d8408326SSeung-Woo Kim 
1238d8408326SSeung-Woo Kim 	/* register specific callback point to common hdmi. */
1239578b6065SJoonyoung Shim 	exynos_mixer_ops_register(&mixer_ops);
1240d8408326SSeung-Woo Kim 
1241cf8fc4f1SJoonyoung Shim 	pm_runtime_enable(dev);
1242d8408326SSeung-Woo Kim 
1243d8408326SSeung-Woo Kim 	return 0;
1244d8408326SSeung-Woo Kim }
1245d8408326SSeung-Woo Kim 
1246d8408326SSeung-Woo Kim static int mixer_remove(struct platform_device *pdev)
1247d8408326SSeung-Woo Kim {
12489416dfa7SSachin Kamat 	dev_info(&pdev->dev, "remove successful\n");
1249d8408326SSeung-Woo Kim 
1250cf8fc4f1SJoonyoung Shim 	pm_runtime_disable(&pdev->dev);
1251cf8fc4f1SJoonyoung Shim 
1252d8408326SSeung-Woo Kim 	return 0;
1253d8408326SSeung-Woo Kim }
1254d8408326SSeung-Woo Kim 
1255ab27af85SJoonyoung Shim #ifdef CONFIG_PM_SLEEP
1256ab27af85SJoonyoung Shim static int mixer_suspend(struct device *dev)
1257ab27af85SJoonyoung Shim {
1258ab27af85SJoonyoung Shim 	struct exynos_drm_hdmi_context *drm_hdmi_ctx = get_mixer_context(dev);
1259ab27af85SJoonyoung Shim 	struct mixer_context *ctx = drm_hdmi_ctx->ctx;
1260ab27af85SJoonyoung Shim 
1261000f1308SRahul Sharma 	if (pm_runtime_suspended(dev)) {
1262cbc4c33dSYoungJun Cho 		DRM_DEBUG_KMS("Already suspended\n");
1263000f1308SRahul Sharma 		return 0;
1264000f1308SRahul Sharma 	}
1265000f1308SRahul Sharma 
1266ab27af85SJoonyoung Shim 	mixer_poweroff(ctx);
1267ab27af85SJoonyoung Shim 
1268ab27af85SJoonyoung Shim 	return 0;
1269ab27af85SJoonyoung Shim }
1270000f1308SRahul Sharma 
1271000f1308SRahul Sharma static int mixer_resume(struct device *dev)
1272000f1308SRahul Sharma {
1273000f1308SRahul Sharma 	struct exynos_drm_hdmi_context *drm_hdmi_ctx = get_mixer_context(dev);
1274000f1308SRahul Sharma 	struct mixer_context *ctx = drm_hdmi_ctx->ctx;
1275000f1308SRahul Sharma 
1276000f1308SRahul Sharma 	if (!pm_runtime_suspended(dev)) {
1277cbc4c33dSYoungJun Cho 		DRM_DEBUG_KMS("Already resumed\n");
1278000f1308SRahul Sharma 		return 0;
1279000f1308SRahul Sharma 	}
1280000f1308SRahul Sharma 
1281000f1308SRahul Sharma 	mixer_poweron(ctx);
1282000f1308SRahul Sharma 
1283000f1308SRahul Sharma 	return 0;
1284000f1308SRahul Sharma }
1285ab27af85SJoonyoung Shim #endif
1286ab27af85SJoonyoung Shim 
1287000f1308SRahul Sharma #ifdef CONFIG_PM_RUNTIME
1288000f1308SRahul Sharma static int mixer_runtime_suspend(struct device *dev)
1289000f1308SRahul Sharma {
1290000f1308SRahul Sharma 	struct exynos_drm_hdmi_context *drm_hdmi_ctx = get_mixer_context(dev);
1291000f1308SRahul Sharma 	struct mixer_context *ctx = drm_hdmi_ctx->ctx;
1292000f1308SRahul Sharma 
1293000f1308SRahul Sharma 	mixer_poweroff(ctx);
1294000f1308SRahul Sharma 
1295000f1308SRahul Sharma 	return 0;
1296000f1308SRahul Sharma }
1297000f1308SRahul Sharma 
1298000f1308SRahul Sharma static int mixer_runtime_resume(struct device *dev)
1299000f1308SRahul Sharma {
1300000f1308SRahul Sharma 	struct exynos_drm_hdmi_context *drm_hdmi_ctx = get_mixer_context(dev);
1301000f1308SRahul Sharma 	struct mixer_context *ctx = drm_hdmi_ctx->ctx;
1302000f1308SRahul Sharma 
1303000f1308SRahul Sharma 	mixer_poweron(ctx);
1304000f1308SRahul Sharma 
1305000f1308SRahul Sharma 	return 0;
1306000f1308SRahul Sharma }
1307000f1308SRahul Sharma #endif
1308000f1308SRahul Sharma 
1309000f1308SRahul Sharma static const struct dev_pm_ops mixer_pm_ops = {
1310000f1308SRahul Sharma 	SET_SYSTEM_SLEEP_PM_OPS(mixer_suspend, mixer_resume)
1311000f1308SRahul Sharma 	SET_RUNTIME_PM_OPS(mixer_runtime_suspend, mixer_runtime_resume, NULL)
1312000f1308SRahul Sharma };
1313ab27af85SJoonyoung Shim 
1314d8408326SSeung-Woo Kim struct platform_driver mixer_driver = {
1315d8408326SSeung-Woo Kim 	.driver = {
1316aaf8b49eSRahul Sharma 		.name = "exynos-mixer",
1317d8408326SSeung-Woo Kim 		.owner = THIS_MODULE,
1318ab27af85SJoonyoung Shim 		.pm = &mixer_pm_ops,
1319aaf8b49eSRahul Sharma 		.of_match_table = mixer_match_types,
1320d8408326SSeung-Woo Kim 	},
1321d8408326SSeung-Woo Kim 	.probe = mixer_probe,
132256550d94SGreg Kroah-Hartman 	.remove = mixer_remove,
13231e123441SRahul Sharma 	.id_table	= mixer_driver_types,
1324d8408326SSeung-Woo Kim };
1325