12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2d8408326SSeung-Woo Kim /*
3d8408326SSeung-Woo Kim * Copyright (C) 2011 Samsung Electronics Co.Ltd
4d8408326SSeung-Woo Kim * Authors:
5d8408326SSeung-Woo Kim * Seung-Woo Kim <sw0312.kim@samsung.com>
6d8408326SSeung-Woo Kim * Inki Dae <inki.dae@samsung.com>
7d8408326SSeung-Woo Kim * Joonyoung Shim <jy0922.shim@samsung.com>
8d8408326SSeung-Woo Kim *
9d8408326SSeung-Woo Kim * Based on drivers/media/video/s5p-tv/mixer_reg.c
10d8408326SSeung-Woo Kim */
11d8408326SSeung-Woo Kim
122bda34d7SSam Ravnborg #include <linux/clk.h>
132bda34d7SSam Ravnborg #include <linux/component.h>
142bda34d7SSam Ravnborg #include <linux/delay.h>
15d8408326SSeung-Woo Kim #include <linux/i2c.h>
16d8408326SSeung-Woo Kim #include <linux/interrupt.h>
17d8408326SSeung-Woo Kim #include <linux/irq.h>
182bda34d7SSam Ravnborg #include <linux/kernel.h>
192bda34d7SSam Ravnborg #include <linux/ktime.h>
203f1c781dSSachin Kamat #include <linux/of.h>
212bda34d7SSam Ravnborg #include <linux/platform_device.h>
222bda34d7SSam Ravnborg #include <linux/pm_runtime.h>
232bda34d7SSam Ravnborg #include <linux/regulator/consumer.h>
242bda34d7SSam Ravnborg #include <linux/spinlock.h>
252bda34d7SSam Ravnborg #include <linux/wait.h>
26d8408326SSeung-Woo Kim
2790bb087fSVille Syrjälä #include <drm/drm_blend.h>
28255490f9SVille Syrjälä #include <drm/drm_edid.h>
292bda34d7SSam Ravnborg #include <drm/drm_fourcc.h>
30720cf96dSVille Syrjälä #include <drm/drm_framebuffer.h>
312bda34d7SSam Ravnborg #include <drm/drm_vblank.h>
32d8408326SSeung-Woo Kim #include <drm/exynos_drm.h>
33d8408326SSeung-Woo Kim
34663d8766SRahul Sharma #include "exynos_drm_crtc.h"
352bda34d7SSam Ravnborg #include "exynos_drm_drv.h"
360488f50eSMarek Szyprowski #include "exynos_drm_fb.h"
377ee14cdcSGustavo Padovan #include "exynos_drm_plane.h"
382bda34d7SSam Ravnborg #include "regs-mixer.h"
392bda34d7SSam Ravnborg #include "regs-vp.h"
4022b21ae6SJoonyoung Shim
41f041b257SSean Paul #define MIXER_WIN_NR 3
42fbbb1e1aSMarek Szyprowski #define VP_DEFAULT_WIN 2
43d8408326SSeung-Woo Kim
442a6e4cd5STobias Jakobi /*
452a6e4cd5STobias Jakobi * Mixer color space conversion coefficient triplet.
462a6e4cd5STobias Jakobi * Used for CSC from RGB to YCbCr.
472a6e4cd5STobias Jakobi * Each coefficient is a 10-bit fixed point number with
482a6e4cd5STobias Jakobi * sign and no integer part, i.e.
492a6e4cd5STobias Jakobi * [0:8] = fractional part (representing a value y = x / 2^9)
502a6e4cd5STobias Jakobi * [9] = sign
512a6e4cd5STobias Jakobi * Negative values are encoded with two's complement.
522a6e4cd5STobias Jakobi */
532a6e4cd5STobias Jakobi #define MXR_CSC_C(x) ((int)((x) * 512.0) & 0x3ff)
542a6e4cd5STobias Jakobi #define MXR_CSC_CT(a0, a1, a2) \
552a6e4cd5STobias Jakobi ((MXR_CSC_C(a0) << 20) | (MXR_CSC_C(a1) << 10) | (MXR_CSC_C(a2) << 0))
562a6e4cd5STobias Jakobi
572a6e4cd5STobias Jakobi /* YCbCr value, used for mixer background color configuration. */
582a6e4cd5STobias Jakobi #define MXR_YCBCR_VAL(y, cb, cr) (((y) << 16) | ((cb) << 8) | ((cr) << 0))
592a6e4cd5STobias Jakobi
607a57ca7cSTobias Jakobi /* The pixelformats that are natively supported by the mixer. */
617a57ca7cSTobias Jakobi #define MXR_FORMAT_RGB565 4
627a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB1555 5
637a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB4444 6
647a57ca7cSTobias Jakobi #define MXR_FORMAT_ARGB8888 7
657a57ca7cSTobias Jakobi
661e123441SRahul Sharma enum mixer_version_id {
671e123441SRahul Sharma MXR_VER_0_0_0_16,
681e123441SRahul Sharma MXR_VER_16_0_33_0,
69def5e095SRahul Sharma MXR_VER_128_0_0_184,
701e123441SRahul Sharma };
711e123441SRahul Sharma
72a44652e8SAndrzej Hajda enum mixer_flag_bits {
73a44652e8SAndrzej Hajda MXR_BIT_POWERED,
740df5e4acSAndrzej Hajda MXR_BIT_VSYNC,
75adeb6f44STobias Jakobi MXR_BIT_INTERLACE,
76adeb6f44STobias Jakobi MXR_BIT_VP_ENABLED,
77adeb6f44STobias Jakobi MXR_BIT_HAS_SCLK,
78a44652e8SAndrzej Hajda };
79a44652e8SAndrzej Hajda
80fbbb1e1aSMarek Szyprowski static const uint32_t mixer_formats[] = {
81fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB4444,
8226a7af3eSTobias Jakobi DRM_FORMAT_ARGB4444,
83fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB1555,
8426a7af3eSTobias Jakobi DRM_FORMAT_ARGB1555,
85fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGB565,
86fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB8888,
87fbbb1e1aSMarek Szyprowski DRM_FORMAT_ARGB8888,
88fbbb1e1aSMarek Szyprowski };
89fbbb1e1aSMarek Szyprowski
90fbbb1e1aSMarek Szyprowski static const uint32_t vp_formats[] = {
91fbbb1e1aSMarek Szyprowski DRM_FORMAT_NV12,
92fbbb1e1aSMarek Szyprowski DRM_FORMAT_NV21,
93fbbb1e1aSMarek Szyprowski };
94fbbb1e1aSMarek Szyprowski
9522b21ae6SJoonyoung Shim struct mixer_context {
964551789fSSean Paul struct platform_device *pdev;
97cf8fc4f1SJoonyoung Shim struct device *dev;
981055b39fSInki Dae struct drm_device *drm_dev;
9907dc3678SMarek Szyprowski void *dma_priv;
10093bca243SGustavo Padovan struct exynos_drm_crtc *crtc;
1017ee14cdcSGustavo Padovan struct exynos_drm_plane planes[MIXER_WIN_NR];
102a44652e8SAndrzej Hajda unsigned long flags;
10322b21ae6SJoonyoung Shim
104524c59f1SAndrzej Hajda int irq;
105524c59f1SAndrzej Hajda void __iomem *mixer_regs;
106524c59f1SAndrzej Hajda void __iomem *vp_regs;
107524c59f1SAndrzej Hajda spinlock_t reg_slock;
108524c59f1SAndrzej Hajda struct clk *mixer;
109524c59f1SAndrzej Hajda struct clk *vp;
110524c59f1SAndrzej Hajda struct clk *hdmi;
111524c59f1SAndrzej Hajda struct clk *sclk_mixer;
112524c59f1SAndrzej Hajda struct clk *sclk_hdmi;
113524c59f1SAndrzej Hajda struct clk *mout_mixer;
1141e123441SRahul Sharma enum mixer_version_id mxr_ver;
115acc8bf04SAndrzej Hajda int scan_value;
1161e123441SRahul Sharma };
1171e123441SRahul Sharma
1181e123441SRahul Sharma struct mixer_drv_data {
1191e123441SRahul Sharma enum mixer_version_id version;
1201b8e5747SRahul Sharma bool is_vp_enabled;
121ff830c96SMarek Szyprowski bool has_sclk;
12222b21ae6SJoonyoung Shim };
12322b21ae6SJoonyoung Shim
124fd2d2fc2SMarek Szyprowski static const struct exynos_drm_plane_config plane_configs[MIXER_WIN_NR] = {
125fd2d2fc2SMarek Szyprowski {
126fd2d2fc2SMarek Szyprowski .zpos = 0,
127fd2d2fc2SMarek Szyprowski .type = DRM_PLANE_TYPE_PRIMARY,
128fd2d2fc2SMarek Szyprowski .pixel_formats = mixer_formats,
129fd2d2fc2SMarek Szyprowski .num_pixel_formats = ARRAY_SIZE(mixer_formats),
130a2cb911eSMarek Szyprowski .capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
131482582c0SChristoph Manszewski EXYNOS_DRM_PLANE_CAP_ZPOS |
1326ac99a32SChristoph Manszewski EXYNOS_DRM_PLANE_CAP_PIX_BLEND |
1336ac99a32SChristoph Manszewski EXYNOS_DRM_PLANE_CAP_WIN_BLEND,
134fd2d2fc2SMarek Szyprowski }, {
135fd2d2fc2SMarek Szyprowski .zpos = 1,
136fd2d2fc2SMarek Szyprowski .type = DRM_PLANE_TYPE_CURSOR,
137fd2d2fc2SMarek Szyprowski .pixel_formats = mixer_formats,
138fd2d2fc2SMarek Szyprowski .num_pixel_formats = ARRAY_SIZE(mixer_formats),
139a2cb911eSMarek Szyprowski .capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
140482582c0SChristoph Manszewski EXYNOS_DRM_PLANE_CAP_ZPOS |
1416ac99a32SChristoph Manszewski EXYNOS_DRM_PLANE_CAP_PIX_BLEND |
1426ac99a32SChristoph Manszewski EXYNOS_DRM_PLANE_CAP_WIN_BLEND,
143fd2d2fc2SMarek Szyprowski }, {
144fd2d2fc2SMarek Szyprowski .zpos = 2,
145fd2d2fc2SMarek Szyprowski .type = DRM_PLANE_TYPE_OVERLAY,
146fd2d2fc2SMarek Szyprowski .pixel_formats = vp_formats,
147fd2d2fc2SMarek Szyprowski .num_pixel_formats = ARRAY_SIZE(vp_formats),
148a2cb911eSMarek Szyprowski .capabilities = EXYNOS_DRM_PLANE_CAP_SCALE |
149f40031c2STobias Jakobi EXYNOS_DRM_PLANE_CAP_ZPOS |
1506ac99a32SChristoph Manszewski EXYNOS_DRM_PLANE_CAP_TILE |
1516ac99a32SChristoph Manszewski EXYNOS_DRM_PLANE_CAP_WIN_BLEND,
152fd2d2fc2SMarek Szyprowski },
153fd2d2fc2SMarek Szyprowski };
154fd2d2fc2SMarek Szyprowski
155d8408326SSeung-Woo Kim static const u8 filter_y_horiz_tap8[] = {
156d8408326SSeung-Woo Kim 0, -1, -1, -1, -1, -1, -1, -1,
157d8408326SSeung-Woo Kim -1, -1, -1, -1, -1, 0, 0, 0,
158d8408326SSeung-Woo Kim 0, 2, 4, 5, 6, 6, 6, 6,
159d8408326SSeung-Woo Kim 6, 5, 5, 4, 3, 2, 1, 1,
160d8408326SSeung-Woo Kim 0, -6, -12, -16, -18, -20, -21, -20,
161d8408326SSeung-Woo Kim -20, -18, -16, -13, -10, -8, -5, -2,
162d8408326SSeung-Woo Kim 127, 126, 125, 121, 114, 107, 99, 89,
163d8408326SSeung-Woo Kim 79, 68, 57, 46, 35, 25, 16, 8,
164d8408326SSeung-Woo Kim };
165d8408326SSeung-Woo Kim
166d8408326SSeung-Woo Kim static const u8 filter_y_vert_tap4[] = {
167d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7,
168d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0,
169d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81,
170d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5,
171d8408326SSeung-Woo Kim 0, 5, 11, 19, 27, 37, 48, 59,
172d8408326SSeung-Woo Kim 70, 81, 92, 102, 111, 118, 124, 126,
173d8408326SSeung-Woo Kim 0, 0, -1, -1, -2, -3, -4, -5,
174d8408326SSeung-Woo Kim -6, -7, -8, -8, -8, -8, -6, -3,
175d8408326SSeung-Woo Kim };
176d8408326SSeung-Woo Kim
177d8408326SSeung-Woo Kim static const u8 filter_cr_horiz_tap4[] = {
178d8408326SSeung-Woo Kim 0, -3, -6, -8, -8, -8, -8, -7,
179d8408326SSeung-Woo Kim -6, -5, -4, -3, -2, -1, -1, 0,
180d8408326SSeung-Woo Kim 127, 126, 124, 118, 111, 102, 92, 81,
181d8408326SSeung-Woo Kim 70, 59, 48, 37, 27, 19, 11, 5,
182d8408326SSeung-Woo Kim };
183d8408326SSeung-Woo Kim
vp_reg_read(struct mixer_context * ctx,u32 reg_id)184524c59f1SAndrzej Hajda static inline u32 vp_reg_read(struct mixer_context *ctx, u32 reg_id)
185d8408326SSeung-Woo Kim {
186524c59f1SAndrzej Hajda return readl(ctx->vp_regs + reg_id);
187d8408326SSeung-Woo Kim }
188d8408326SSeung-Woo Kim
vp_reg_write(struct mixer_context * ctx,u32 reg_id,u32 val)189524c59f1SAndrzej Hajda static inline void vp_reg_write(struct mixer_context *ctx, u32 reg_id,
190d8408326SSeung-Woo Kim u32 val)
191d8408326SSeung-Woo Kim {
192524c59f1SAndrzej Hajda writel(val, ctx->vp_regs + reg_id);
193d8408326SSeung-Woo Kim }
194d8408326SSeung-Woo Kim
vp_reg_writemask(struct mixer_context * ctx,u32 reg_id,u32 val,u32 mask)195524c59f1SAndrzej Hajda static inline void vp_reg_writemask(struct mixer_context *ctx, u32 reg_id,
196d8408326SSeung-Woo Kim u32 val, u32 mask)
197d8408326SSeung-Woo Kim {
198524c59f1SAndrzej Hajda u32 old = vp_reg_read(ctx, reg_id);
199d8408326SSeung-Woo Kim
200d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask);
201524c59f1SAndrzej Hajda writel(val, ctx->vp_regs + reg_id);
202d8408326SSeung-Woo Kim }
203d8408326SSeung-Woo Kim
mixer_reg_read(struct mixer_context * ctx,u32 reg_id)204524c59f1SAndrzej Hajda static inline u32 mixer_reg_read(struct mixer_context *ctx, u32 reg_id)
205d8408326SSeung-Woo Kim {
206524c59f1SAndrzej Hajda return readl(ctx->mixer_regs + reg_id);
207d8408326SSeung-Woo Kim }
208d8408326SSeung-Woo Kim
mixer_reg_write(struct mixer_context * ctx,u32 reg_id,u32 val)209524c59f1SAndrzej Hajda static inline void mixer_reg_write(struct mixer_context *ctx, u32 reg_id,
210d8408326SSeung-Woo Kim u32 val)
211d8408326SSeung-Woo Kim {
212524c59f1SAndrzej Hajda writel(val, ctx->mixer_regs + reg_id);
213d8408326SSeung-Woo Kim }
214d8408326SSeung-Woo Kim
mixer_reg_writemask(struct mixer_context * ctx,u32 reg_id,u32 val,u32 mask)215524c59f1SAndrzej Hajda static inline void mixer_reg_writemask(struct mixer_context *ctx,
216d8408326SSeung-Woo Kim u32 reg_id, u32 val, u32 mask)
217d8408326SSeung-Woo Kim {
218524c59f1SAndrzej Hajda u32 old = mixer_reg_read(ctx, reg_id);
219d8408326SSeung-Woo Kim
220d8408326SSeung-Woo Kim val = (val & mask) | (old & ~mask);
221524c59f1SAndrzej Hajda writel(val, ctx->mixer_regs + reg_id);
222d8408326SSeung-Woo Kim }
223d8408326SSeung-Woo Kim
mixer_regs_dump(struct mixer_context * ctx)224d8408326SSeung-Woo Kim static void mixer_regs_dump(struct mixer_context *ctx)
225d8408326SSeung-Woo Kim {
226d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
227d8408326SSeung-Woo Kim do { \
2286be90056SInki Dae DRM_DEV_DEBUG_KMS(ctx->dev, #reg_id " = %08x\n", \
229524c59f1SAndrzej Hajda (u32)readl(ctx->mixer_regs + reg_id)); \
230d8408326SSeung-Woo Kim } while (0)
231d8408326SSeung-Woo Kim
232d8408326SSeung-Woo Kim DUMPREG(MXR_STATUS);
233d8408326SSeung-Woo Kim DUMPREG(MXR_CFG);
234d8408326SSeung-Woo Kim DUMPREG(MXR_INT_EN);
235d8408326SSeung-Woo Kim DUMPREG(MXR_INT_STATUS);
236d8408326SSeung-Woo Kim
237d8408326SSeung-Woo Kim DUMPREG(MXR_LAYER_CFG);
238d8408326SSeung-Woo Kim DUMPREG(MXR_VIDEO_CFG);
239d8408326SSeung-Woo Kim
240d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_CFG);
241d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_BASE);
242d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SPAN);
243d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_WH);
244d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_SXY);
245d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC0_DXY);
246d8408326SSeung-Woo Kim
247d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_CFG);
248d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_BASE);
249d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SPAN);
250d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_WH);
251d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_SXY);
252d8408326SSeung-Woo Kim DUMPREG(MXR_GRAPHIC1_DXY);
253d8408326SSeung-Woo Kim #undef DUMPREG
254d8408326SSeung-Woo Kim }
255d8408326SSeung-Woo Kim
vp_regs_dump(struct mixer_context * ctx)256d8408326SSeung-Woo Kim static void vp_regs_dump(struct mixer_context *ctx)
257d8408326SSeung-Woo Kim {
258d8408326SSeung-Woo Kim #define DUMPREG(reg_id) \
259d8408326SSeung-Woo Kim do { \
2606be90056SInki Dae DRM_DEV_DEBUG_KMS(ctx->dev, #reg_id " = %08x\n", \
261524c59f1SAndrzej Hajda (u32) readl(ctx->vp_regs + reg_id)); \
262d8408326SSeung-Woo Kim } while (0)
263d8408326SSeung-Woo Kim
264d8408326SSeung-Woo Kim DUMPREG(VP_ENABLE);
265d8408326SSeung-Woo Kim DUMPREG(VP_SRESET);
266d8408326SSeung-Woo Kim DUMPREG(VP_SHADOW_UPDATE);
267d8408326SSeung-Woo Kim DUMPREG(VP_FIELD_ID);
268d8408326SSeung-Woo Kim DUMPREG(VP_MODE);
269d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_Y);
270d8408326SSeung-Woo Kim DUMPREG(VP_IMG_SIZE_C);
271d8408326SSeung-Woo Kim DUMPREG(VP_PER_RATE_CTRL);
272d8408326SSeung-Woo Kim DUMPREG(VP_TOP_Y_PTR);
273d8408326SSeung-Woo Kim DUMPREG(VP_BOT_Y_PTR);
274d8408326SSeung-Woo Kim DUMPREG(VP_TOP_C_PTR);
275d8408326SSeung-Woo Kim DUMPREG(VP_BOT_C_PTR);
276d8408326SSeung-Woo Kim DUMPREG(VP_ENDIAN_MODE);
277d8408326SSeung-Woo Kim DUMPREG(VP_SRC_H_POSITION);
278d8408326SSeung-Woo Kim DUMPREG(VP_SRC_V_POSITION);
279d8408326SSeung-Woo Kim DUMPREG(VP_SRC_WIDTH);
280d8408326SSeung-Woo Kim DUMPREG(VP_SRC_HEIGHT);
281d8408326SSeung-Woo Kim DUMPREG(VP_DST_H_POSITION);
282d8408326SSeung-Woo Kim DUMPREG(VP_DST_V_POSITION);
283d8408326SSeung-Woo Kim DUMPREG(VP_DST_WIDTH);
284d8408326SSeung-Woo Kim DUMPREG(VP_DST_HEIGHT);
285d8408326SSeung-Woo Kim DUMPREG(VP_H_RATIO);
286d8408326SSeung-Woo Kim DUMPREG(VP_V_RATIO);
287d8408326SSeung-Woo Kim
288d8408326SSeung-Woo Kim #undef DUMPREG
289d8408326SSeung-Woo Kim }
290d8408326SSeung-Woo Kim
vp_filter_set(struct mixer_context * ctx,int reg_id,const u8 * data,unsigned int size)291524c59f1SAndrzej Hajda static inline void vp_filter_set(struct mixer_context *ctx,
292d8408326SSeung-Woo Kim int reg_id, const u8 *data, unsigned int size)
293d8408326SSeung-Woo Kim {
294d8408326SSeung-Woo Kim /* assure 4-byte align */
295d8408326SSeung-Woo Kim BUG_ON(size & 3);
296d8408326SSeung-Woo Kim for (; size; size -= 4, reg_id += 4, data += 4) {
297d8408326SSeung-Woo Kim u32 val = (data[0] << 24) | (data[1] << 16) |
298d8408326SSeung-Woo Kim (data[2] << 8) | data[3];
299524c59f1SAndrzej Hajda vp_reg_write(ctx, reg_id, val);
300d8408326SSeung-Woo Kim }
301d8408326SSeung-Woo Kim }
302d8408326SSeung-Woo Kim
vp_default_filter(struct mixer_context * ctx)303524c59f1SAndrzej Hajda static void vp_default_filter(struct mixer_context *ctx)
304d8408326SSeung-Woo Kim {
305524c59f1SAndrzej Hajda vp_filter_set(ctx, VP_POLY8_Y0_LL,
306e25e1b66SSachin Kamat filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
307524c59f1SAndrzej Hajda vp_filter_set(ctx, VP_POLY4_Y0_LL,
308e25e1b66SSachin Kamat filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
309524c59f1SAndrzej Hajda vp_filter_set(ctx, VP_POLY4_C0_LL,
310e25e1b66SSachin Kamat filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
311d8408326SSeung-Woo Kim }
312d8408326SSeung-Woo Kim
mixer_cfg_gfx_blend(struct mixer_context * ctx,unsigned int win,unsigned int pixel_alpha,unsigned int alpha)313f657a996SMarek Szyprowski static void mixer_cfg_gfx_blend(struct mixer_context *ctx, unsigned int win,
3146ac99a32SChristoph Manszewski unsigned int pixel_alpha, unsigned int alpha)
315f657a996SMarek Szyprowski {
3166ac99a32SChristoph Manszewski u32 win_alpha = alpha >> 8;
317f657a996SMarek Szyprowski u32 val;
318f657a996SMarek Szyprowski
319f657a996SMarek Szyprowski val = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
320482582c0SChristoph Manszewski switch (pixel_alpha) {
321482582c0SChristoph Manszewski case DRM_MODE_BLEND_PIXEL_NONE:
322482582c0SChristoph Manszewski break;
323482582c0SChristoph Manszewski case DRM_MODE_BLEND_COVERAGE:
324482582c0SChristoph Manszewski val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
325482582c0SChristoph Manszewski break;
326482582c0SChristoph Manszewski case DRM_MODE_BLEND_PREMULTI:
327482582c0SChristoph Manszewski default:
328f657a996SMarek Szyprowski val |= MXR_GRP_CFG_BLEND_PRE_MUL;
329f657a996SMarek Szyprowski val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
330482582c0SChristoph Manszewski break;
331f657a996SMarek Szyprowski }
3326ac99a32SChristoph Manszewski
3336ac99a32SChristoph Manszewski if (alpha != DRM_BLEND_ALPHA_OPAQUE) {
3346ac99a32SChristoph Manszewski val |= MXR_GRP_CFG_WIN_BLEND_EN;
3356ac99a32SChristoph Manszewski val |= win_alpha;
3366ac99a32SChristoph Manszewski }
337524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_GRAPHIC_CFG(win),
338f657a996SMarek Szyprowski val, MXR_GRP_CFG_MISC_MASK);
339f657a996SMarek Szyprowski }
340f657a996SMarek Szyprowski
mixer_cfg_vp_blend(struct mixer_context * ctx,unsigned int alpha)3416ac99a32SChristoph Manszewski static void mixer_cfg_vp_blend(struct mixer_context *ctx, unsigned int alpha)
342f657a996SMarek Szyprowski {
3436ac99a32SChristoph Manszewski u32 win_alpha = alpha >> 8;
3446ac99a32SChristoph Manszewski u32 val = 0;
345f657a996SMarek Szyprowski
3466ac99a32SChristoph Manszewski if (alpha != DRM_BLEND_ALPHA_OPAQUE) {
3476ac99a32SChristoph Manszewski val |= MXR_VID_CFG_BLEND_EN;
3486ac99a32SChristoph Manszewski val |= win_alpha;
3496ac99a32SChristoph Manszewski }
350524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_VIDEO_CFG, val);
351f657a996SMarek Szyprowski }
352f657a996SMarek Szyprowski
mixer_is_synced(struct mixer_context * ctx)3536a3b45adSAndrzej Hajda static bool mixer_is_synced(struct mixer_context *ctx)
354d8408326SSeung-Woo Kim {
3556a3b45adSAndrzej Hajda u32 base, shadow;
356d8408326SSeung-Woo Kim
3576a3b45adSAndrzej Hajda if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
3586a3b45adSAndrzej Hajda ctx->mxr_ver == MXR_VER_128_0_0_184)
3596a3b45adSAndrzej Hajda return !(mixer_reg_read(ctx, MXR_CFG) &
3606a3b45adSAndrzej Hajda MXR_CFG_LAYER_UPDATE_COUNT_MASK);
3616a3b45adSAndrzej Hajda
3626a3b45adSAndrzej Hajda if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags) &&
3636a3b45adSAndrzej Hajda vp_reg_read(ctx, VP_SHADOW_UPDATE))
3646a3b45adSAndrzej Hajda return false;
3656a3b45adSAndrzej Hajda
3666a3b45adSAndrzej Hajda base = mixer_reg_read(ctx, MXR_CFG);
3676a3b45adSAndrzej Hajda shadow = mixer_reg_read(ctx, MXR_CFG_S);
3686a3b45adSAndrzej Hajda if (base != shadow)
3696a3b45adSAndrzej Hajda return false;
3706a3b45adSAndrzej Hajda
3716a3b45adSAndrzej Hajda base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(0));
3726a3b45adSAndrzej Hajda shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(0));
3736a3b45adSAndrzej Hajda if (base != shadow)
3746a3b45adSAndrzej Hajda return false;
3756a3b45adSAndrzej Hajda
3766a3b45adSAndrzej Hajda base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(1));
3776a3b45adSAndrzej Hajda shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(1));
3786a3b45adSAndrzej Hajda if (base != shadow)
3796a3b45adSAndrzej Hajda return false;
3806a3b45adSAndrzej Hajda
3816a3b45adSAndrzej Hajda return true;
3826a3b45adSAndrzej Hajda }
3836a3b45adSAndrzej Hajda
mixer_wait_for_sync(struct mixer_context * ctx)3846a3b45adSAndrzej Hajda static int mixer_wait_for_sync(struct mixer_context *ctx)
3856a3b45adSAndrzej Hajda {
3866a3b45adSAndrzej Hajda ktime_t timeout = ktime_add_us(ktime_get(), 100000);
3876a3b45adSAndrzej Hajda
3886a3b45adSAndrzej Hajda while (!mixer_is_synced(ctx)) {
3896a3b45adSAndrzej Hajda usleep_range(1000, 2000);
3906a3b45adSAndrzej Hajda if (ktime_compare(ktime_get(), timeout) > 0)
3916a3b45adSAndrzej Hajda return -ETIMEDOUT;
3926a3b45adSAndrzej Hajda }
3936a3b45adSAndrzej Hajda return 0;
3946a3b45adSAndrzej Hajda }
3956a3b45adSAndrzej Hajda
mixer_disable_sync(struct mixer_context * ctx)3966a3b45adSAndrzej Hajda static void mixer_disable_sync(struct mixer_context *ctx)
3976a3b45adSAndrzej Hajda {
3986a3b45adSAndrzej Hajda mixer_reg_writemask(ctx, MXR_STATUS, 0, MXR_STATUS_SYNC_ENABLE);
3996a3b45adSAndrzej Hajda }
4006a3b45adSAndrzej Hajda
mixer_enable_sync(struct mixer_context * ctx)4016a3b45adSAndrzej Hajda static void mixer_enable_sync(struct mixer_context *ctx)
4026a3b45adSAndrzej Hajda {
4036a3b45adSAndrzej Hajda if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
4046a3b45adSAndrzej Hajda ctx->mxr_ver == MXR_VER_128_0_0_184)
4056a3b45adSAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
4066a3b45adSAndrzej Hajda mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_SYNC_ENABLE);
407adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
4086a3b45adSAndrzej Hajda vp_reg_write(ctx, VP_SHADOW_UPDATE, VP_SHADOW_UPDATE_ENABLE);
409d8408326SSeung-Woo Kim }
410d8408326SSeung-Woo Kim
mixer_cfg_scan(struct mixer_context * ctx,int width,int height)4113fc40ca9SAndrzej Hajda static void mixer_cfg_scan(struct mixer_context *ctx, int width, int height)
412d8408326SSeung-Woo Kim {
413d8408326SSeung-Woo Kim u32 val;
414d8408326SSeung-Woo Kim
415d8408326SSeung-Woo Kim /* choosing between interlace and progressive mode */
416adeb6f44STobias Jakobi val = test_bit(MXR_BIT_INTERLACE, &ctx->flags) ?
417adeb6f44STobias Jakobi MXR_CFG_SCAN_INTERLACE : MXR_CFG_SCAN_PROGRESSIVE;
418d8408326SSeung-Woo Kim
419acc8bf04SAndrzej Hajda if (ctx->mxr_ver == MXR_VER_128_0_0_184)
420524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_RESOLUTION,
4213fc40ca9SAndrzej Hajda MXR_MXR_RES_HEIGHT(height) | MXR_MXR_RES_WIDTH(width));
422d8408326SSeung-Woo Kim else
423acc8bf04SAndrzej Hajda val |= ctx->scan_value;
424d8408326SSeung-Woo Kim
425524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_SCAN_MASK);
426d8408326SSeung-Woo Kim }
427d8408326SSeung-Woo Kim
mixer_cfg_rgb_fmt(struct mixer_context * ctx,struct drm_display_mode * mode)42813e810f1SChristoph Manszewski static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, struct drm_display_mode *mode)
429d8408326SSeung-Woo Kim {
43013e810f1SChristoph Manszewski enum hdmi_quantization_range range = drm_default_rgb_quant_range(mode);
431d8408326SSeung-Woo Kim u32 val;
432d8408326SSeung-Woo Kim
43313e810f1SChristoph Manszewski if (mode->vdisplay < 720) {
43413e810f1SChristoph Manszewski val = MXR_CFG_RGB601;
435e9e5ba93SChristoph Manszewski } else {
43613e810f1SChristoph Manszewski val = MXR_CFG_RGB709;
43713e810f1SChristoph Manszewski
4382a6e4cd5STobias Jakobi /* Configure the BT.709 CSC matrix for full range RGB. */
439524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_CM_COEFF_Y,
4402a6e4cd5STobias Jakobi MXR_CSC_CT( 0.184, 0.614, 0.063) |
4412a6e4cd5STobias Jakobi MXR_CM_COEFF_RGB_FULL);
442524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_CM_COEFF_CB,
4432a6e4cd5STobias Jakobi MXR_CSC_CT(-0.102, -0.338, 0.440));
444524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_CM_COEFF_CR,
4452a6e4cd5STobias Jakobi MXR_CSC_CT( 0.440, -0.399, -0.040));
446d8408326SSeung-Woo Kim }
447d8408326SSeung-Woo Kim
44813e810f1SChristoph Manszewski if (range == HDMI_QUANTIZATION_RANGE_FULL)
44913e810f1SChristoph Manszewski val |= MXR_CFG_QUANT_RANGE_FULL;
45013e810f1SChristoph Manszewski else
45113e810f1SChristoph Manszewski val |= MXR_CFG_QUANT_RANGE_LIMITED;
45213e810f1SChristoph Manszewski
453524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
454d8408326SSeung-Woo Kim }
455d8408326SSeung-Woo Kim
mixer_cfg_layer(struct mixer_context * ctx,unsigned int win,unsigned int priority,bool enable)4565b1d5bc6STobias Jakobi static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win,
457a2cb911eSMarek Szyprowski unsigned int priority, bool enable)
458d8408326SSeung-Woo Kim {
459d8408326SSeung-Woo Kim u32 val = enable ? ~0 : 0;
460d8408326SSeung-Woo Kim
461d8408326SSeung-Woo Kim switch (win) {
462d8408326SSeung-Woo Kim case 0:
463524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
464524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_LAYER_CFG,
465a2cb911eSMarek Szyprowski MXR_LAYER_CFG_GRP0_VAL(priority),
466a2cb911eSMarek Szyprowski MXR_LAYER_CFG_GRP0_MASK);
467d8408326SSeung-Woo Kim break;
468d8408326SSeung-Woo Kim case 1:
469524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
470524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_LAYER_CFG,
471a2cb911eSMarek Szyprowski MXR_LAYER_CFG_GRP1_VAL(priority),
472a2cb911eSMarek Szyprowski MXR_LAYER_CFG_GRP1_MASK);
473adeb6f44STobias Jakobi
474d8408326SSeung-Woo Kim break;
4755e68fef2SMarek Szyprowski case VP_DEFAULT_WIN:
476adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
477524c59f1SAndrzej Hajda vp_reg_writemask(ctx, VP_ENABLE, val, VP_ENABLE_ON);
478524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, val,
4791b8e5747SRahul Sharma MXR_CFG_VP_ENABLE);
480524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_LAYER_CFG,
481a2cb911eSMarek Szyprowski MXR_LAYER_CFG_VP_VAL(priority),
482a2cb911eSMarek Szyprowski MXR_LAYER_CFG_VP_MASK);
4831b8e5747SRahul Sharma }
484d8408326SSeung-Woo Kim break;
485d8408326SSeung-Woo Kim }
486d8408326SSeung-Woo Kim }
487d8408326SSeung-Woo Kim
mixer_run(struct mixer_context * ctx)488d8408326SSeung-Woo Kim static void mixer_run(struct mixer_context *ctx)
489d8408326SSeung-Woo Kim {
490524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
491d8408326SSeung-Woo Kim }
492d8408326SSeung-Woo Kim
mixer_stop(struct mixer_context * ctx)493381be025SRahul Sharma static void mixer_stop(struct mixer_context *ctx)
494381be025SRahul Sharma {
495381be025SRahul Sharma int timeout = 20;
496381be025SRahul Sharma
497524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_STATUS, 0, MXR_STATUS_REG_RUN);
498381be025SRahul Sharma
499524c59f1SAndrzej Hajda while (!(mixer_reg_read(ctx, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
500381be025SRahul Sharma --timeout)
501381be025SRahul Sharma usleep_range(10000, 12000);
502381be025SRahul Sharma }
503381be025SRahul Sharma
mixer_commit(struct mixer_context * ctx)504521d98a3SAndrzej Hajda static void mixer_commit(struct mixer_context *ctx)
505521d98a3SAndrzej Hajda {
506521d98a3SAndrzej Hajda struct drm_display_mode *mode = &ctx->crtc->base.state->adjusted_mode;
507521d98a3SAndrzej Hajda
5083fc40ca9SAndrzej Hajda mixer_cfg_scan(ctx, mode->hdisplay, mode->vdisplay);
50913e810f1SChristoph Manszewski mixer_cfg_rgb_fmt(ctx, mode);
510521d98a3SAndrzej Hajda mixer_run(ctx);
511521d98a3SAndrzej Hajda }
512521d98a3SAndrzej Hajda
vp_video_buffer(struct mixer_context * ctx,struct exynos_drm_plane * plane)5132eeb2e5eSGustavo Padovan static void vp_video_buffer(struct mixer_context *ctx,
5142eeb2e5eSGustavo Padovan struct exynos_drm_plane *plane)
515d8408326SSeung-Woo Kim {
5160114f404SMarek Szyprowski struct exynos_drm_plane_state *state =
5170114f404SMarek Szyprowski to_exynos_plane_state(plane->base.state);
5180114f404SMarek Szyprowski struct drm_framebuffer *fb = state->base.fb;
519e47726a1SMarek Szyprowski unsigned int priority = state->base.normalized_zpos + 1;
520d8408326SSeung-Woo Kim unsigned long flags;
521d8408326SSeung-Woo Kim dma_addr_t luma_addr[2], chroma_addr[2];
5220f752694STobias Jakobi bool is_tiled, is_nv21;
523d8408326SSeung-Woo Kim u32 val;
524d8408326SSeung-Woo Kim
5250f752694STobias Jakobi is_nv21 = (fb->format->format == DRM_FORMAT_NV21);
5260f752694STobias Jakobi is_tiled = (fb->modifier == DRM_FORMAT_MOD_SAMSUNG_64_32_TILE);
527f40031c2STobias Jakobi
5280488f50eSMarek Szyprowski luma_addr[0] = exynos_drm_fb_dma_addr(fb, 0);
5290488f50eSMarek Szyprowski chroma_addr[0] = exynos_drm_fb_dma_addr(fb, 1);
530d8408326SSeung-Woo Kim
53171469944SAndrzej Hajda if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
5320f752694STobias Jakobi if (is_tiled) {
533d8408326SSeung-Woo Kim luma_addr[1] = luma_addr[0] + 0x40;
534d8408326SSeung-Woo Kim chroma_addr[1] = chroma_addr[0] + 0x40;
535d8408326SSeung-Woo Kim } else {
5362eeb2e5eSGustavo Padovan luma_addr[1] = luma_addr[0] + fb->pitches[0];
5370ccc1c8fSTobias Jakobi chroma_addr[1] = chroma_addr[0] + fb->pitches[1];
538d8408326SSeung-Woo Kim }
539d8408326SSeung-Woo Kim } else {
540d8408326SSeung-Woo Kim luma_addr[1] = 0;
541d8408326SSeung-Woo Kim chroma_addr[1] = 0;
542d8408326SSeung-Woo Kim }
543d8408326SSeung-Woo Kim
544524c59f1SAndrzej Hajda spin_lock_irqsave(&ctx->reg_slock, flags);
545d8408326SSeung-Woo Kim
546d8408326SSeung-Woo Kim /* interlace or progressive scan mode */
547adeb6f44STobias Jakobi val = (test_bit(MXR_BIT_INTERLACE, &ctx->flags) ? ~0 : 0);
548524c59f1SAndrzej Hajda vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_LINE_SKIP);
549d8408326SSeung-Woo Kim
550d8408326SSeung-Woo Kim /* setup format */
5510f752694STobias Jakobi val = (is_nv21 ? VP_MODE_NV21 : VP_MODE_NV12);
5520f752694STobias Jakobi val |= (is_tiled ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
553524c59f1SAndrzej Hajda vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_FMT_MASK);
554d8408326SSeung-Woo Kim
555d8408326SSeung-Woo Kim /* setting size of input image */
556524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) |
5572eeb2e5eSGustavo Padovan VP_IMG_VSIZE(fb->height));
558dc500cfbSTobias Jakobi /* chroma plane for NV12/NV21 is half the height of the luma plane */
5590ccc1c8fSTobias Jakobi vp_reg_write(ctx, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[1]) |
5602eeb2e5eSGustavo Padovan VP_IMG_VSIZE(fb->height / 2));
561d8408326SSeung-Woo Kim
562524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_SRC_WIDTH, state->src.w);
563524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_SRC_H_POSITION,
5640114f404SMarek Szyprowski VP_SRC_H_POSITION_VAL(state->src.x));
565524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_WIDTH, state->crtc.w);
566524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_H_POSITION, state->crtc.x);
5670ccc1c8fSTobias Jakobi
568adeb6f44STobias Jakobi if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) {
5690ccc1c8fSTobias Jakobi vp_reg_write(ctx, VP_SRC_HEIGHT, state->src.h / 2);
5700ccc1c8fSTobias Jakobi vp_reg_write(ctx, VP_SRC_V_POSITION, state->src.y / 2);
571524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_HEIGHT, state->crtc.h / 2);
572524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_V_POSITION, state->crtc.y / 2);
573d8408326SSeung-Woo Kim } else {
5740ccc1c8fSTobias Jakobi vp_reg_write(ctx, VP_SRC_HEIGHT, state->src.h);
5750ccc1c8fSTobias Jakobi vp_reg_write(ctx, VP_SRC_V_POSITION, state->src.y);
576524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_HEIGHT, state->crtc.h);
577524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_DST_V_POSITION, state->crtc.y);
578d8408326SSeung-Woo Kim }
579d8408326SSeung-Woo Kim
580524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_H_RATIO, state->h_ratio);
581524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_V_RATIO, state->v_ratio);
582d8408326SSeung-Woo Kim
583524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
584d8408326SSeung-Woo Kim
585d8408326SSeung-Woo Kim /* set buffer address to vp */
586524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_TOP_Y_PTR, luma_addr[0]);
587524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_BOT_Y_PTR, luma_addr[1]);
588524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_TOP_C_PTR, chroma_addr[0]);
589524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_BOT_C_PTR, chroma_addr[1]);
590d8408326SSeung-Woo Kim
591e47726a1SMarek Szyprowski mixer_cfg_layer(ctx, plane->index, priority, true);
5926ac99a32SChristoph Manszewski mixer_cfg_vp_blend(ctx, state->base.alpha);
593d8408326SSeung-Woo Kim
594524c59f1SAndrzej Hajda spin_unlock_irqrestore(&ctx->reg_slock, flags);
595d8408326SSeung-Woo Kim
596c0734fbaSTobias Jakobi mixer_regs_dump(ctx);
597d8408326SSeung-Woo Kim vp_regs_dump(ctx);
598d8408326SSeung-Woo Kim }
599d8408326SSeung-Woo Kim
mixer_graph_buffer(struct mixer_context * ctx,struct exynos_drm_plane * plane)6002eeb2e5eSGustavo Padovan static void mixer_graph_buffer(struct mixer_context *ctx,
6012eeb2e5eSGustavo Padovan struct exynos_drm_plane *plane)
602d8408326SSeung-Woo Kim {
6030114f404SMarek Szyprowski struct exynos_drm_plane_state *state =
6040114f404SMarek Szyprowski to_exynos_plane_state(plane->base.state);
6050114f404SMarek Szyprowski struct drm_framebuffer *fb = state->base.fb;
606e47726a1SMarek Szyprowski unsigned int priority = state->base.normalized_zpos + 1;
607d8408326SSeung-Woo Kim unsigned long flags;
60840bdfb0aSMarek Szyprowski unsigned int win = plane->index;
6092611015cSTobias Jakobi unsigned int x_ratio = 0, y_ratio = 0;
6105dff6905STobias Jakobi unsigned int dst_x_offset, dst_y_offset;
611482582c0SChristoph Manszewski unsigned int pixel_alpha;
612d8408326SSeung-Woo Kim dma_addr_t dma_addr;
613d8408326SSeung-Woo Kim unsigned int fmt;
614d8408326SSeung-Woo Kim u32 val;
615d8408326SSeung-Woo Kim
616482582c0SChristoph Manszewski if (fb->format->has_alpha)
617482582c0SChristoph Manszewski pixel_alpha = state->base.pixel_blend_mode;
618482582c0SChristoph Manszewski else
619482582c0SChristoph Manszewski pixel_alpha = DRM_MODE_BLEND_PIXEL_NONE;
620482582c0SChristoph Manszewski
621438b74a5SVille Syrjälä switch (fb->format->format) {
6227a57ca7cSTobias Jakobi case DRM_FORMAT_XRGB4444:
62326a7af3eSTobias Jakobi case DRM_FORMAT_ARGB4444:
6247a57ca7cSTobias Jakobi fmt = MXR_FORMAT_ARGB4444;
6257a57ca7cSTobias Jakobi break;
626d8408326SSeung-Woo Kim
6277a57ca7cSTobias Jakobi case DRM_FORMAT_XRGB1555:
62826a7af3eSTobias Jakobi case DRM_FORMAT_ARGB1555:
6297a57ca7cSTobias Jakobi fmt = MXR_FORMAT_ARGB1555;
630d8408326SSeung-Woo Kim break;
6317a57ca7cSTobias Jakobi
6327a57ca7cSTobias Jakobi case DRM_FORMAT_RGB565:
6337a57ca7cSTobias Jakobi fmt = MXR_FORMAT_RGB565;
634d8408326SSeung-Woo Kim break;
6357a57ca7cSTobias Jakobi
6367a57ca7cSTobias Jakobi case DRM_FORMAT_XRGB8888:
6377a57ca7cSTobias Jakobi case DRM_FORMAT_ARGB8888:
6381e60d62fSTobias Jakobi default:
6397a57ca7cSTobias Jakobi fmt = MXR_FORMAT_ARGB8888;
6407a57ca7cSTobias Jakobi break;
641d8408326SSeung-Woo Kim }
642d8408326SSeung-Woo Kim
643e463b069SMarek Szyprowski /* ratio is already checked by common plane code */
644e463b069SMarek Szyprowski x_ratio = state->h_ratio == (1 << 15);
645e463b069SMarek Szyprowski y_ratio = state->v_ratio == (1 << 15);
646d8408326SSeung-Woo Kim
6470114f404SMarek Szyprowski dst_x_offset = state->crtc.x;
6480114f404SMarek Szyprowski dst_y_offset = state->crtc.y;
649d8408326SSeung-Woo Kim
6505dff6905STobias Jakobi /* translate dma address base s.t. the source image offset is zero */
6510488f50eSMarek Szyprowski dma_addr = exynos_drm_fb_dma_addr(fb, 0)
652272725c7SVille Syrjälä + (state->src.x * fb->format->cpp[0])
6530114f404SMarek Szyprowski + (state->src.y * fb->pitches[0]);
654d8408326SSeung-Woo Kim
655524c59f1SAndrzej Hajda spin_lock_irqsave(&ctx->reg_slock, flags);
656d8408326SSeung-Woo Kim
657d8408326SSeung-Woo Kim /* setup format */
658524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_GRAPHIC_CFG(win),
659d8408326SSeung-Woo Kim MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
660d8408326SSeung-Woo Kim
661d8408326SSeung-Woo Kim /* setup geometry */
662524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_SPAN(win),
663272725c7SVille Syrjälä fb->pitches[0] / fb->format->cpp[0]);
664d8408326SSeung-Woo Kim
6650114f404SMarek Szyprowski val = MXR_GRP_WH_WIDTH(state->src.w);
6660114f404SMarek Szyprowski val |= MXR_GRP_WH_HEIGHT(state->src.h);
667d8408326SSeung-Woo Kim val |= MXR_GRP_WH_H_SCALE(x_ratio);
668d8408326SSeung-Woo Kim val |= MXR_GRP_WH_V_SCALE(y_ratio);
669524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_WH(win), val);
670d8408326SSeung-Woo Kim
671d8408326SSeung-Woo Kim /* setup offsets in display image */
672d8408326SSeung-Woo Kim val = MXR_GRP_DXY_DX(dst_x_offset);
673d8408326SSeung-Woo Kim val |= MXR_GRP_DXY_DY(dst_y_offset);
674524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_DXY(win), val);
675d8408326SSeung-Woo Kim
676d8408326SSeung-Woo Kim /* set buffer address to mixer */
677524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_BASE(win), dma_addr);
678d8408326SSeung-Woo Kim
679e47726a1SMarek Szyprowski mixer_cfg_layer(ctx, win, priority, true);
6806ac99a32SChristoph Manszewski mixer_cfg_gfx_blend(ctx, win, pixel_alpha, state->base.alpha);
681aaf8b49eSRahul Sharma
682524c59f1SAndrzej Hajda spin_unlock_irqrestore(&ctx->reg_slock, flags);
683c0734fbaSTobias Jakobi
684c0734fbaSTobias Jakobi mixer_regs_dump(ctx);
685d8408326SSeung-Woo Kim }
686d8408326SSeung-Woo Kim
vp_win_reset(struct mixer_context * ctx)687d8408326SSeung-Woo Kim static void vp_win_reset(struct mixer_context *ctx)
688d8408326SSeung-Woo Kim {
689a696394cSTobias Jakobi unsigned int tries = 100;
690d8408326SSeung-Woo Kim
691524c59f1SAndrzej Hajda vp_reg_write(ctx, VP_SRESET, VP_SRESET_PROCESSING);
6928646dcb8SDan Carpenter while (--tries) {
693d8408326SSeung-Woo Kim /* waiting until VP_SRESET_PROCESSING is 0 */
694524c59f1SAndrzej Hajda if (~vp_reg_read(ctx, VP_SRESET) & VP_SRESET_PROCESSING)
695d8408326SSeung-Woo Kim break;
69602b3de43STomasz Stanislawski mdelay(10);
697d8408326SSeung-Woo Kim }
698d8408326SSeung-Woo Kim WARN(tries == 0, "failed to reset Video Processor\n");
699d8408326SSeung-Woo Kim }
700d8408326SSeung-Woo Kim
mixer_win_reset(struct mixer_context * ctx)701cf8fc4f1SJoonyoung Shim static void mixer_win_reset(struct mixer_context *ctx)
702cf8fc4f1SJoonyoung Shim {
703cf8fc4f1SJoonyoung Shim unsigned long flags;
704cf8fc4f1SJoonyoung Shim
705524c59f1SAndrzej Hajda spin_lock_irqsave(&ctx->reg_slock, flags);
706cf8fc4f1SJoonyoung Shim
707524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
708cf8fc4f1SJoonyoung Shim
709cf8fc4f1SJoonyoung Shim /* set output in RGB888 mode */
710524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
711cf8fc4f1SJoonyoung Shim
712cf8fc4f1SJoonyoung Shim /* 16 beat burst in DMA */
713524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_STATUS, MXR_STATUS_16_BURST,
714cf8fc4f1SJoonyoung Shim MXR_STATUS_BURST_MASK);
715cf8fc4f1SJoonyoung Shim
716a2cb911eSMarek Szyprowski /* reset default layer priority */
717524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_LAYER_CFG, 0);
718cf8fc4f1SJoonyoung Shim
7192a6e4cd5STobias Jakobi /* set all background colors to RGB (0,0,0) */
720524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_BG_COLOR0, MXR_YCBCR_VAL(0, 128, 128));
721524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_BG_COLOR1, MXR_YCBCR_VAL(0, 128, 128));
722524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_BG_COLOR2, MXR_YCBCR_VAL(0, 128, 128));
723cf8fc4f1SJoonyoung Shim
724adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
725cf8fc4f1SJoonyoung Shim /* configuration of Video Processor Registers */
726cf8fc4f1SJoonyoung Shim vp_win_reset(ctx);
727524c59f1SAndrzej Hajda vp_default_filter(ctx);
7281b8e5747SRahul Sharma }
729cf8fc4f1SJoonyoung Shim
730cf8fc4f1SJoonyoung Shim /* disable all layers */
731524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
732524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
733adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
734524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
735cf8fc4f1SJoonyoung Shim
7365dff6905STobias Jakobi /* set all source image offsets to zero */
737524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_SXY(0), 0);
738524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_GRAPHIC_SXY(1), 0);
7395dff6905STobias Jakobi
740524c59f1SAndrzej Hajda spin_unlock_irqrestore(&ctx->reg_slock, flags);
741cf8fc4f1SJoonyoung Shim }
742cf8fc4f1SJoonyoung Shim
mixer_irq_handler(int irq,void * arg)7434551789fSSean Paul static irqreturn_t mixer_irq_handler(int irq, void *arg)
7444551789fSSean Paul {
7454551789fSSean Paul struct mixer_context *ctx = arg;
7466a3b45adSAndrzej Hajda u32 val;
7474551789fSSean Paul
748524c59f1SAndrzej Hajda spin_lock(&ctx->reg_slock);
7494551789fSSean Paul
7504551789fSSean Paul /* read interrupt status for handling and clearing flags for VSYNC */
751524c59f1SAndrzej Hajda val = mixer_reg_read(ctx, MXR_INT_STATUS);
7524551789fSSean Paul
7534551789fSSean Paul /* handling VSYNC */
7544551789fSSean Paul if (val & MXR_INT_STATUS_VSYNC) {
75581a464dfSAndrzej Hajda /* vsync interrupt use different bit for read and clear */
75681a464dfSAndrzej Hajda val |= MXR_INT_CLEAR_VSYNC;
75781a464dfSAndrzej Hajda val &= ~MXR_INT_STATUS_VSYNC;
75881a464dfSAndrzej Hajda
7594551789fSSean Paul /* interlace scan need to check shadow register */
7606a3b45adSAndrzej Hajda if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)
7616a3b45adSAndrzej Hajda && !mixer_is_synced(ctx))
7622eced8e9SAndrzej Hajda goto out;
7632eced8e9SAndrzej Hajda
764eafd540aSGustavo Padovan drm_crtc_handle_vblank(&ctx->crtc->base);
7654551789fSSean Paul }
7664551789fSSean Paul
7674551789fSSean Paul out:
7684551789fSSean Paul /* clear interrupts */
769524c59f1SAndrzej Hajda mixer_reg_write(ctx, MXR_INT_STATUS, val);
7704551789fSSean Paul
771524c59f1SAndrzej Hajda spin_unlock(&ctx->reg_slock);
7724551789fSSean Paul
7734551789fSSean Paul return IRQ_HANDLED;
7744551789fSSean Paul }
7754551789fSSean Paul
mixer_resources_init(struct mixer_context * mixer_ctx)7764551789fSSean Paul static int mixer_resources_init(struct mixer_context *mixer_ctx)
7774551789fSSean Paul {
7784551789fSSean Paul struct device *dev = &mixer_ctx->pdev->dev;
7794551789fSSean Paul struct resource *res;
7804551789fSSean Paul int ret;
7814551789fSSean Paul
782524c59f1SAndrzej Hajda spin_lock_init(&mixer_ctx->reg_slock);
7834551789fSSean Paul
784524c59f1SAndrzej Hajda mixer_ctx->mixer = devm_clk_get(dev, "mixer");
785524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->mixer)) {
7864551789fSSean Paul dev_err(dev, "failed to get clock 'mixer'\n");
7874551789fSSean Paul return -ENODEV;
7884551789fSSean Paul }
7894551789fSSean Paul
790524c59f1SAndrzej Hajda mixer_ctx->hdmi = devm_clk_get(dev, "hdmi");
791524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->hdmi)) {
79204427ec5SMarek Szyprowski dev_err(dev, "failed to get clock 'hdmi'\n");
793524c59f1SAndrzej Hajda return PTR_ERR(mixer_ctx->hdmi);
79404427ec5SMarek Szyprowski }
79504427ec5SMarek Szyprowski
796524c59f1SAndrzej Hajda mixer_ctx->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
797524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->sclk_hdmi)) {
7984551789fSSean Paul dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
7994551789fSSean Paul return -ENODEV;
8004551789fSSean Paul }
8014551789fSSean Paul res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
8024551789fSSean Paul if (res == NULL) {
8034551789fSSean Paul dev_err(dev, "get memory resource failed.\n");
8044551789fSSean Paul return -ENXIO;
8054551789fSSean Paul }
8064551789fSSean Paul
807524c59f1SAndrzej Hajda mixer_ctx->mixer_regs = devm_ioremap(dev, res->start,
8084551789fSSean Paul resource_size(res));
809524c59f1SAndrzej Hajda if (mixer_ctx->mixer_regs == NULL) {
8104551789fSSean Paul dev_err(dev, "register mapping failed.\n");
8114551789fSSean Paul return -ENXIO;
8124551789fSSean Paul }
8134551789fSSean Paul
814be52abd4SLad Prabhakar ret = platform_get_irq(mixer_ctx->pdev, 0);
815be52abd4SLad Prabhakar if (ret < 0)
816be52abd4SLad Prabhakar return ret;
817be52abd4SLad Prabhakar mixer_ctx->irq = ret;
8184551789fSSean Paul
819be52abd4SLad Prabhakar ret = devm_request_irq(dev, mixer_ctx->irq, mixer_irq_handler,
8204551789fSSean Paul 0, "drm_mixer", mixer_ctx);
8214551789fSSean Paul if (ret) {
8224551789fSSean Paul dev_err(dev, "request interrupt failed.\n");
8234551789fSSean Paul return ret;
8244551789fSSean Paul }
8254551789fSSean Paul
8264551789fSSean Paul return 0;
8274551789fSSean Paul }
8284551789fSSean Paul
vp_resources_init(struct mixer_context * mixer_ctx)8294551789fSSean Paul static int vp_resources_init(struct mixer_context *mixer_ctx)
8304551789fSSean Paul {
8314551789fSSean Paul struct device *dev = &mixer_ctx->pdev->dev;
8324551789fSSean Paul struct resource *res;
8334551789fSSean Paul
834524c59f1SAndrzej Hajda mixer_ctx->vp = devm_clk_get(dev, "vp");
835524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->vp)) {
8364551789fSSean Paul dev_err(dev, "failed to get clock 'vp'\n");
8374551789fSSean Paul return -ENODEV;
8384551789fSSean Paul }
839ff830c96SMarek Szyprowski
840adeb6f44STobias Jakobi if (test_bit(MXR_BIT_HAS_SCLK, &mixer_ctx->flags)) {
841524c59f1SAndrzej Hajda mixer_ctx->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
842524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->sclk_mixer)) {
8434551789fSSean Paul dev_err(dev, "failed to get clock 'sclk_mixer'\n");
8444551789fSSean Paul return -ENODEV;
8454551789fSSean Paul }
846524c59f1SAndrzej Hajda mixer_ctx->mout_mixer = devm_clk_get(dev, "mout_mixer");
847524c59f1SAndrzej Hajda if (IS_ERR(mixer_ctx->mout_mixer)) {
848ff830c96SMarek Szyprowski dev_err(dev, "failed to get clock 'mout_mixer'\n");
8494551789fSSean Paul return -ENODEV;
8504551789fSSean Paul }
8514551789fSSean Paul
852524c59f1SAndrzej Hajda if (mixer_ctx->sclk_hdmi && mixer_ctx->mout_mixer)
853524c59f1SAndrzej Hajda clk_set_parent(mixer_ctx->mout_mixer,
854524c59f1SAndrzej Hajda mixer_ctx->sclk_hdmi);
855ff830c96SMarek Szyprowski }
8564551789fSSean Paul
8574551789fSSean Paul res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
8584551789fSSean Paul if (res == NULL) {
8594551789fSSean Paul dev_err(dev, "get memory resource failed.\n");
8604551789fSSean Paul return -ENXIO;
8614551789fSSean Paul }
8624551789fSSean Paul
863524c59f1SAndrzej Hajda mixer_ctx->vp_regs = devm_ioremap(dev, res->start,
8644551789fSSean Paul resource_size(res));
865524c59f1SAndrzej Hajda if (mixer_ctx->vp_regs == NULL) {
8664551789fSSean Paul dev_err(dev, "register mapping failed.\n");
8674551789fSSean Paul return -ENXIO;
8684551789fSSean Paul }
8694551789fSSean Paul
8704551789fSSean Paul return 0;
8714551789fSSean Paul }
8724551789fSSean Paul
mixer_initialize(struct mixer_context * mixer_ctx,struct drm_device * drm_dev)87393bca243SGustavo Padovan static int mixer_initialize(struct mixer_context *mixer_ctx,
874f37cd5e8SInki Dae struct drm_device *drm_dev)
8754551789fSSean Paul {
8764551789fSSean Paul int ret;
8774551789fSSean Paul
878eb88e422SGustavo Padovan mixer_ctx->drm_dev = drm_dev;
8794551789fSSean Paul
8804551789fSSean Paul /* acquire resources: regs, irqs, clocks */
8814551789fSSean Paul ret = mixer_resources_init(mixer_ctx);
8824551789fSSean Paul if (ret) {
8836f83d208SInki Dae DRM_DEV_ERROR(mixer_ctx->dev,
8846f83d208SInki Dae "mixer_resources_init failed ret=%d\n", ret);
8854551789fSSean Paul return ret;
8864551789fSSean Paul }
8874551789fSSean Paul
888adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &mixer_ctx->flags)) {
8894551789fSSean Paul /* acquire vp resources: regs, irqs, clocks */
8904551789fSSean Paul ret = vp_resources_init(mixer_ctx);
8914551789fSSean Paul if (ret) {
8926f83d208SInki Dae DRM_DEV_ERROR(mixer_ctx->dev,
8936f83d208SInki Dae "vp_resources_init failed ret=%d\n", ret);
8944551789fSSean Paul return ret;
8954551789fSSean Paul }
8964551789fSSean Paul }
8974551789fSSean Paul
89807dc3678SMarek Szyprowski return exynos_drm_register_dma(drm_dev, mixer_ctx->dev,
89907dc3678SMarek Szyprowski &mixer_ctx->dma_priv);
9001055b39fSInki Dae }
9011055b39fSInki Dae
mixer_ctx_remove(struct mixer_context * mixer_ctx)90293bca243SGustavo Padovan static void mixer_ctx_remove(struct mixer_context *mixer_ctx)
903d8408326SSeung-Woo Kim {
90407dc3678SMarek Szyprowski exynos_drm_unregister_dma(mixer_ctx->drm_dev, mixer_ctx->dev,
90507dc3678SMarek Szyprowski &mixer_ctx->dma_priv);
906f041b257SSean Paul }
907f041b257SSean Paul
mixer_enable_vblank(struct exynos_drm_crtc * crtc)90893bca243SGustavo Padovan static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)
909f041b257SSean Paul {
91093bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx;
911d8408326SSeung-Woo Kim
9120df5e4acSAndrzej Hajda __set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9130df5e4acSAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
914f041b257SSean Paul return 0;
915d8408326SSeung-Woo Kim
916d8408326SSeung-Woo Kim /* enable vsync interrupt */
917524c59f1SAndrzej Hajda mixer_reg_writemask(mixer_ctx, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
918524c59f1SAndrzej Hajda mixer_reg_writemask(mixer_ctx, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
919d8408326SSeung-Woo Kim
920d8408326SSeung-Woo Kim return 0;
921d8408326SSeung-Woo Kim }
922d8408326SSeung-Woo Kim
mixer_disable_vblank(struct exynos_drm_crtc * crtc)92393bca243SGustavo Padovan static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
924d8408326SSeung-Woo Kim {
92593bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx;
926d8408326SSeung-Woo Kim
9270df5e4acSAndrzej Hajda __clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
9280df5e4acSAndrzej Hajda
9290df5e4acSAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
930947710c6SAndrzej Hajda return;
931947710c6SAndrzej Hajda
932d8408326SSeung-Woo Kim /* disable vsync interrupt */
933524c59f1SAndrzej Hajda mixer_reg_writemask(mixer_ctx, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
934524c59f1SAndrzej Hajda mixer_reg_writemask(mixer_ctx, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
935d8408326SSeung-Woo Kim }
936d8408326SSeung-Woo Kim
mixer_atomic_begin(struct exynos_drm_crtc * crtc)9373dbaab16SMarek Szyprowski static void mixer_atomic_begin(struct exynos_drm_crtc *crtc)
9383dbaab16SMarek Szyprowski {
9396a3b45adSAndrzej Hajda struct mixer_context *ctx = crtc->ctx;
9403dbaab16SMarek Szyprowski
9416a3b45adSAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
9423dbaab16SMarek Szyprowski return;
9433dbaab16SMarek Szyprowski
9446a3b45adSAndrzej Hajda if (mixer_wait_for_sync(ctx))
9456a3b45adSAndrzej Hajda dev_err(ctx->dev, "timeout waiting for VSYNC\n");
9466a3b45adSAndrzej Hajda mixer_disable_sync(ctx);
9473dbaab16SMarek Szyprowski }
9483dbaab16SMarek Szyprowski
mixer_update_plane(struct exynos_drm_crtc * crtc,struct exynos_drm_plane * plane)9491e1d1393SGustavo Padovan static void mixer_update_plane(struct exynos_drm_crtc *crtc,
9501e1d1393SGustavo Padovan struct exynos_drm_plane *plane)
951d8408326SSeung-Woo Kim {
95293bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx;
953d8408326SSeung-Woo Kim
9546be90056SInki Dae DRM_DEV_DEBUG_KMS(mixer_ctx->dev, "win: %d\n", plane->index);
955d8408326SSeung-Woo Kim
956a44652e8SAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
957dda9012bSShirish S return;
958dda9012bSShirish S
9595e68fef2SMarek Szyprowski if (plane->index == VP_DEFAULT_WIN)
9602eeb2e5eSGustavo Padovan vp_video_buffer(mixer_ctx, plane);
961d8408326SSeung-Woo Kim else
9622eeb2e5eSGustavo Padovan mixer_graph_buffer(mixer_ctx, plane);
963d8408326SSeung-Woo Kim }
964d8408326SSeung-Woo Kim
mixer_disable_plane(struct exynos_drm_crtc * crtc,struct exynos_drm_plane * plane)9651e1d1393SGustavo Padovan static void mixer_disable_plane(struct exynos_drm_crtc *crtc,
9661e1d1393SGustavo Padovan struct exynos_drm_plane *plane)
967d8408326SSeung-Woo Kim {
96893bca243SGustavo Padovan struct mixer_context *mixer_ctx = crtc->ctx;
969d8408326SSeung-Woo Kim unsigned long flags;
970d8408326SSeung-Woo Kim
9716be90056SInki Dae DRM_DEV_DEBUG_KMS(mixer_ctx->dev, "win: %d\n", plane->index);
972d8408326SSeung-Woo Kim
973a44652e8SAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
974db43fd16SPrathyush K return;
975db43fd16SPrathyush K
976524c59f1SAndrzej Hajda spin_lock_irqsave(&mixer_ctx->reg_slock, flags);
977a2cb911eSMarek Szyprowski mixer_cfg_layer(mixer_ctx, plane->index, 0, false);
978524c59f1SAndrzej Hajda spin_unlock_irqrestore(&mixer_ctx->reg_slock, flags);
9793dbaab16SMarek Szyprowski }
9803dbaab16SMarek Szyprowski
mixer_atomic_flush(struct exynos_drm_crtc * crtc)9813dbaab16SMarek Szyprowski static void mixer_atomic_flush(struct exynos_drm_crtc *crtc)
9823dbaab16SMarek Szyprowski {
9833dbaab16SMarek Szyprowski struct mixer_context *mixer_ctx = crtc->ctx;
9843dbaab16SMarek Szyprowski
9853dbaab16SMarek Szyprowski if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
9863dbaab16SMarek Szyprowski return;
987d8408326SSeung-Woo Kim
9886a3b45adSAndrzej Hajda mixer_enable_sync(mixer_ctx);
989a392276dSAndrzej Hajda exynos_crtc_handle_event(crtc);
990d8408326SSeung-Woo Kim }
991d8408326SSeung-Woo Kim
mixer_atomic_enable(struct exynos_drm_crtc * crtc)99211f95489SInki Dae static void mixer_atomic_enable(struct exynos_drm_crtc *crtc)
993db43fd16SPrathyush K {
9943cecda03SGustavo Padovan struct mixer_context *ctx = crtc->ctx;
995445d3bedSInki Dae int ret;
996db43fd16SPrathyush K
997a44652e8SAndrzej Hajda if (test_bit(MXR_BIT_POWERED, &ctx->flags))
998db43fd16SPrathyush K return;
999db43fd16SPrathyush K
1000445d3bedSInki Dae ret = pm_runtime_resume_and_get(ctx->dev);
1001445d3bedSInki Dae if (ret < 0) {
1002445d3bedSInki Dae dev_err(ctx->dev, "failed to enable MIXER device.\n");
1003445d3bedSInki Dae return;
1004445d3bedSInki Dae }
1005af65c804SSean Paul
1006a121d179SAndrzej Hajda exynos_drm_pipe_clk_enable(crtc, true);
1007a121d179SAndrzej Hajda
10086a3b45adSAndrzej Hajda mixer_disable_sync(ctx);
10093dbaab16SMarek Szyprowski
1010524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
1011d74ed937SRahul Sharma
10120df5e4acSAndrzej Hajda if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) {
1013524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_INT_STATUS, ~0,
1014524c59f1SAndrzej Hajda MXR_INT_CLEAR_VSYNC);
1015524c59f1SAndrzej Hajda mixer_reg_writemask(ctx, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
10160df5e4acSAndrzej Hajda }
1017db43fd16SPrathyush K mixer_win_reset(ctx);
1018ccf034a9SGustavo Padovan
101971469944SAndrzej Hajda mixer_commit(ctx);
102071469944SAndrzej Hajda
10216a3b45adSAndrzej Hajda mixer_enable_sync(ctx);
10223dbaab16SMarek Szyprowski
1023ccf034a9SGustavo Padovan set_bit(MXR_BIT_POWERED, &ctx->flags);
1024db43fd16SPrathyush K }
1025db43fd16SPrathyush K
mixer_atomic_disable(struct exynos_drm_crtc * crtc)102611f95489SInki Dae static void mixer_atomic_disable(struct exynos_drm_crtc *crtc)
1027db43fd16SPrathyush K {
10283cecda03SGustavo Padovan struct mixer_context *ctx = crtc->ctx;
1029c329f667SJoonyoung Shim int i;
1030db43fd16SPrathyush K
1031a44652e8SAndrzej Hajda if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
1032b4bfa3c7SRahul Sharma return;
1033db43fd16SPrathyush K
1034381be025SRahul Sharma mixer_stop(ctx);
1035c0734fbaSTobias Jakobi mixer_regs_dump(ctx);
1036c329f667SJoonyoung Shim
1037c329f667SJoonyoung Shim for (i = 0; i < MIXER_WIN_NR; i++)
10381e1d1393SGustavo Padovan mixer_disable_plane(crtc, &ctx->planes[i]);
1039db43fd16SPrathyush K
1040a121d179SAndrzej Hajda exynos_drm_pipe_clk_enable(crtc, false);
1041a121d179SAndrzej Hajda
1042ccf034a9SGustavo Padovan pm_runtime_put(ctx->dev);
1043ccf034a9SGustavo Padovan
1044a44652e8SAndrzej Hajda clear_bit(MXR_BIT_POWERED, &ctx->flags);
1045db43fd16SPrathyush K }
1046db43fd16SPrathyush K
mixer_mode_valid(struct exynos_drm_crtc * crtc,const struct drm_display_mode * mode)104712612555SNathan Huckleberry static enum drm_mode_status mixer_mode_valid(struct exynos_drm_crtc *crtc,
10486ace38a5SAndrzej Hajda const struct drm_display_mode *mode)
1049f041b257SSean Paul {
10506ace38a5SAndrzej Hajda struct mixer_context *ctx = crtc->ctx;
10516ace38a5SAndrzej Hajda u32 w = mode->hdisplay, h = mode->vdisplay;
1052f041b257SSean Paul
10536be90056SInki Dae DRM_DEV_DEBUG_KMS(ctx->dev, "xres=%d, yres=%d, refresh=%d, intl=%d\n",
10540425662fSVille Syrjälä w, h, drm_mode_vrefresh(mode),
10556be90056SInki Dae !!(mode->flags & DRM_MODE_FLAG_INTERLACE));
1056f041b257SSean Paul
10576ace38a5SAndrzej Hajda if (ctx->mxr_ver == MXR_VER_128_0_0_184)
10586ace38a5SAndrzej Hajda return MODE_OK;
1059f041b257SSean Paul
1060f041b257SSean Paul if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
1061f041b257SSean Paul (w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
1062f041b257SSean Paul (w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
10636ace38a5SAndrzej Hajda return MODE_OK;
1064f041b257SSean Paul
1065ae58c03eSDaniel Drake if ((w == 1024 && h == 768) ||
1066ae58c03eSDaniel Drake (w == 1366 && h == 768) ||
1067ae58c03eSDaniel Drake (w == 1280 && h == 1024))
10680900673eSAndrzej Hajda return MODE_OK;
10690900673eSAndrzej Hajda
10706ace38a5SAndrzej Hajda return MODE_BAD;
1071f041b257SSean Paul }
1072f041b257SSean Paul
mixer_mode_fixup(struct exynos_drm_crtc * crtc,const struct drm_display_mode * mode,struct drm_display_mode * adjusted_mode)1073acc8bf04SAndrzej Hajda static bool mixer_mode_fixup(struct exynos_drm_crtc *crtc,
1074acc8bf04SAndrzej Hajda const struct drm_display_mode *mode,
1075acc8bf04SAndrzej Hajda struct drm_display_mode *adjusted_mode)
1076acc8bf04SAndrzej Hajda {
1077acc8bf04SAndrzej Hajda struct mixer_context *ctx = crtc->ctx;
1078acc8bf04SAndrzej Hajda int width = mode->hdisplay, height = mode->vdisplay, i;
1079acc8bf04SAndrzej Hajda
10805a884be5SKrzysztof Wilczynski static const struct {
1081acc8bf04SAndrzej Hajda int hdisplay, vdisplay, htotal, vtotal, scan_val;
10825a884be5SKrzysztof Wilczynski } modes[] = {
1083acc8bf04SAndrzej Hajda { 720, 480, 858, 525, MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD },
1084acc8bf04SAndrzej Hajda { 720, 576, 864, 625, MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD },
1085acc8bf04SAndrzej Hajda { 1280, 720, 1650, 750, MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD },
1086acc8bf04SAndrzej Hajda { 1920, 1080, 2200, 1125, MXR_CFG_SCAN_HD_1080 |
1087acc8bf04SAndrzej Hajda MXR_CFG_SCAN_HD }
1088acc8bf04SAndrzej Hajda };
1089acc8bf04SAndrzej Hajda
1090acc8bf04SAndrzej Hajda if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1091acc8bf04SAndrzej Hajda __set_bit(MXR_BIT_INTERLACE, &ctx->flags);
1092acc8bf04SAndrzej Hajda else
1093acc8bf04SAndrzej Hajda __clear_bit(MXR_BIT_INTERLACE, &ctx->flags);
1094acc8bf04SAndrzej Hajda
1095acc8bf04SAndrzej Hajda if (ctx->mxr_ver == MXR_VER_128_0_0_184)
1096acc8bf04SAndrzej Hajda return true;
1097acc8bf04SAndrzej Hajda
1098acc8bf04SAndrzej Hajda for (i = 0; i < ARRAY_SIZE(modes); ++i)
1099acc8bf04SAndrzej Hajda if (width <= modes[i].hdisplay && height <= modes[i].vdisplay) {
1100acc8bf04SAndrzej Hajda ctx->scan_value = modes[i].scan_val;
1101acc8bf04SAndrzej Hajda if (width < modes[i].hdisplay ||
1102acc8bf04SAndrzej Hajda height < modes[i].vdisplay) {
1103acc8bf04SAndrzej Hajda adjusted_mode->hdisplay = modes[i].hdisplay;
1104acc8bf04SAndrzej Hajda adjusted_mode->hsync_start = modes[i].hdisplay;
1105acc8bf04SAndrzej Hajda adjusted_mode->hsync_end = modes[i].htotal;
1106acc8bf04SAndrzej Hajda adjusted_mode->htotal = modes[i].htotal;
1107acc8bf04SAndrzej Hajda adjusted_mode->vdisplay = modes[i].vdisplay;
1108acc8bf04SAndrzej Hajda adjusted_mode->vsync_start = modes[i].vdisplay;
1109acc8bf04SAndrzej Hajda adjusted_mode->vsync_end = modes[i].vtotal;
1110acc8bf04SAndrzej Hajda adjusted_mode->vtotal = modes[i].vtotal;
1111acc8bf04SAndrzej Hajda }
1112acc8bf04SAndrzej Hajda
1113acc8bf04SAndrzej Hajda return true;
1114acc8bf04SAndrzej Hajda }
1115acc8bf04SAndrzej Hajda
1116acc8bf04SAndrzej Hajda return false;
1117acc8bf04SAndrzej Hajda }
1118acc8bf04SAndrzej Hajda
1119f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops mixer_crtc_ops = {
112011f95489SInki Dae .atomic_enable = mixer_atomic_enable,
112111f95489SInki Dae .atomic_disable = mixer_atomic_disable,
1122d8408326SSeung-Woo Kim .enable_vblank = mixer_enable_vblank,
1123d8408326SSeung-Woo Kim .disable_vblank = mixer_disable_vblank,
11243dbaab16SMarek Szyprowski .atomic_begin = mixer_atomic_begin,
11259cc7610aSGustavo Padovan .update_plane = mixer_update_plane,
11269cc7610aSGustavo Padovan .disable_plane = mixer_disable_plane,
11273dbaab16SMarek Szyprowski .atomic_flush = mixer_atomic_flush,
11286ace38a5SAndrzej Hajda .mode_valid = mixer_mode_valid,
1129acc8bf04SAndrzej Hajda .mode_fixup = mixer_mode_fixup,
1130f041b257SSean Paul };
11310ea6822fSRahul Sharma
11325e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos5420_mxr_drv_data = {
1133def5e095SRahul Sharma .version = MXR_VER_128_0_0_184,
1134def5e095SRahul Sharma .is_vp_enabled = 0,
1135def5e095SRahul Sharma };
1136def5e095SRahul Sharma
11375e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos5250_mxr_drv_data = {
1138aaf8b49eSRahul Sharma .version = MXR_VER_16_0_33_0,
1139aaf8b49eSRahul Sharma .is_vp_enabled = 0,
1140aaf8b49eSRahul Sharma };
1141aaf8b49eSRahul Sharma
11425e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos4212_mxr_drv_data = {
1143ff830c96SMarek Szyprowski .version = MXR_VER_0_0_0_16,
1144ff830c96SMarek Szyprowski .is_vp_enabled = 1,
1145ff830c96SMarek Szyprowski };
1146ff830c96SMarek Szyprowski
11475e6cc1c5SArvind Yadav static const struct mixer_drv_data exynos4210_mxr_drv_data = {
11481e123441SRahul Sharma .version = MXR_VER_0_0_0_16,
11491b8e5747SRahul Sharma .is_vp_enabled = 1,
1150ff830c96SMarek Szyprowski .has_sclk = 1,
11511e123441SRahul Sharma };
11521e123441SRahul Sharma
11535e6cc1c5SArvind Yadav static const struct of_device_id mixer_match_types[] = {
1154aaf8b49eSRahul Sharma {
1155ff830c96SMarek Szyprowski .compatible = "samsung,exynos4210-mixer",
1156ff830c96SMarek Szyprowski .data = &exynos4210_mxr_drv_data,
1157ff830c96SMarek Szyprowski }, {
1158ff830c96SMarek Szyprowski .compatible = "samsung,exynos4212-mixer",
1159ff830c96SMarek Szyprowski .data = &exynos4212_mxr_drv_data,
1160ff830c96SMarek Szyprowski }, {
1161aaf8b49eSRahul Sharma .compatible = "samsung,exynos5-mixer",
1162cc57caf0SRahul Sharma .data = &exynos5250_mxr_drv_data,
1163cc57caf0SRahul Sharma }, {
1164cc57caf0SRahul Sharma .compatible = "samsung,exynos5250-mixer",
1165cc57caf0SRahul Sharma .data = &exynos5250_mxr_drv_data,
1166aaf8b49eSRahul Sharma }, {
1167def5e095SRahul Sharma .compatible = "samsung,exynos5420-mixer",
1168def5e095SRahul Sharma .data = &exynos5420_mxr_drv_data,
1169def5e095SRahul Sharma }, {
11701e123441SRahul Sharma /* end node */
11711e123441SRahul Sharma }
11721e123441SRahul Sharma };
117339b58a39SSjoerd Simons MODULE_DEVICE_TABLE(of, mixer_match_types);
11741e123441SRahul Sharma
mixer_bind(struct device * dev,struct device * manager,void * data)1175f37cd5e8SInki Dae static int mixer_bind(struct device *dev, struct device *manager, void *data)
1176d8408326SSeung-Woo Kim {
11778103ef1bSAndrzej Hajda struct mixer_context *ctx = dev_get_drvdata(dev);
1178f37cd5e8SInki Dae struct drm_device *drm_dev = data;
11797ee14cdcSGustavo Padovan struct exynos_drm_plane *exynos_plane;
1180fd2d2fc2SMarek Szyprowski unsigned int i;
11816e2a3b66SGustavo Padovan int ret;
1182d8408326SSeung-Woo Kim
1183e2dc3f72SAlban Browaeys ret = mixer_initialize(ctx, drm_dev);
1184e2dc3f72SAlban Browaeys if (ret)
1185e2dc3f72SAlban Browaeys return ret;
1186e2dc3f72SAlban Browaeys
1187fd2d2fc2SMarek Szyprowski for (i = 0; i < MIXER_WIN_NR; i++) {
1188adeb6f44STobias Jakobi if (i == VP_DEFAULT_WIN && !test_bit(MXR_BIT_VP_ENABLED,
1189adeb6f44STobias Jakobi &ctx->flags))
1190ab144201SMarek Szyprowski continue;
1191ab144201SMarek Szyprowski
119240bdfb0aSMarek Szyprowski ret = exynos_plane_init(drm_dev, &ctx->planes[i], i,
11932c82607bSAndrzej Hajda &plane_configs[i]);
11947ee14cdcSGustavo Padovan if (ret)
11957ee14cdcSGustavo Padovan return ret;
11967ee14cdcSGustavo Padovan }
11977ee14cdcSGustavo Padovan
11985d3d0995SGustavo Padovan exynos_plane = &ctx->planes[DEFAULT_WIN];
11997ee14cdcSGustavo Padovan ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
1200d644951cSAndrzej Hajda EXYNOS_DISPLAY_TYPE_HDMI, &mixer_crtc_ops, ctx);
120193bca243SGustavo Padovan if (IS_ERR(ctx->crtc)) {
1202e2dc3f72SAlban Browaeys mixer_ctx_remove(ctx);
120393bca243SGustavo Padovan ret = PTR_ERR(ctx->crtc);
120493bca243SGustavo Padovan goto free_ctx;
12058103ef1bSAndrzej Hajda }
12068103ef1bSAndrzej Hajda
12078103ef1bSAndrzej Hajda return 0;
120893bca243SGustavo Padovan
120993bca243SGustavo Padovan free_ctx:
121093bca243SGustavo Padovan devm_kfree(dev, ctx);
121193bca243SGustavo Padovan return ret;
12128103ef1bSAndrzej Hajda }
12138103ef1bSAndrzej Hajda
mixer_unbind(struct device * dev,struct device * master,void * data)12148103ef1bSAndrzej Hajda static void mixer_unbind(struct device *dev, struct device *master, void *data)
12158103ef1bSAndrzej Hajda {
12168103ef1bSAndrzej Hajda struct mixer_context *ctx = dev_get_drvdata(dev);
12178103ef1bSAndrzej Hajda
121893bca243SGustavo Padovan mixer_ctx_remove(ctx);
12198103ef1bSAndrzej Hajda }
12208103ef1bSAndrzej Hajda
12218103ef1bSAndrzej Hajda static const struct component_ops mixer_component_ops = {
12228103ef1bSAndrzej Hajda .bind = mixer_bind,
12238103ef1bSAndrzej Hajda .unbind = mixer_unbind,
12248103ef1bSAndrzej Hajda };
12258103ef1bSAndrzej Hajda
mixer_probe(struct platform_device * pdev)12268103ef1bSAndrzej Hajda static int mixer_probe(struct platform_device *pdev)
12278103ef1bSAndrzej Hajda {
12288103ef1bSAndrzej Hajda struct device *dev = &pdev->dev;
122948f6155aSMarek Szyprowski const struct mixer_drv_data *drv;
12308103ef1bSAndrzej Hajda struct mixer_context *ctx;
12318103ef1bSAndrzej Hajda int ret;
1232d8408326SSeung-Woo Kim
1233f041b257SSean Paul ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1234f041b257SSean Paul if (!ctx) {
12356f83d208SInki Dae DRM_DEV_ERROR(dev, "failed to alloc mixer context.\n");
1236d8408326SSeung-Woo Kim return -ENOMEM;
1237f041b257SSean Paul }
1238d8408326SSeung-Woo Kim
123948f6155aSMarek Szyprowski drv = of_device_get_match_data(dev);
1240aaf8b49eSRahul Sharma
12414551789fSSean Paul ctx->pdev = pdev;
1242d873ab99SSeung-Woo Kim ctx->dev = dev;
12431e123441SRahul Sharma ctx->mxr_ver = drv->version;
1244d8408326SSeung-Woo Kim
1245adeb6f44STobias Jakobi if (drv->is_vp_enabled)
1246adeb6f44STobias Jakobi __set_bit(MXR_BIT_VP_ENABLED, &ctx->flags);
1247adeb6f44STobias Jakobi if (drv->has_sclk)
1248adeb6f44STobias Jakobi __set_bit(MXR_BIT_HAS_SCLK, &ctx->flags);
1249adeb6f44STobias Jakobi
12508103ef1bSAndrzej Hajda platform_set_drvdata(pdev, ctx);
1251df5225bcSInki Dae
12528103ef1bSAndrzej Hajda pm_runtime_enable(dev);
1253df5225bcSInki Dae
1254fda02214SMarek Szyprowski ret = component_add(&pdev->dev, &mixer_component_ops);
1255fda02214SMarek Szyprowski if (ret)
1256fda02214SMarek Szyprowski pm_runtime_disable(dev);
1257fda02214SMarek Szyprowski
1258df5225bcSInki Dae return ret;
1259f37cd5e8SInki Dae }
1260f37cd5e8SInki Dae
mixer_remove(struct platform_device * pdev)1261*4fe7a1ecSUwe Kleine-König static void mixer_remove(struct platform_device *pdev)
1262d8408326SSeung-Woo Kim {
12638103ef1bSAndrzej Hajda pm_runtime_disable(&pdev->dev);
12648103ef1bSAndrzej Hajda
1265df5225bcSInki Dae component_del(&pdev->dev, &mixer_component_ops);
1266d8408326SSeung-Woo Kim }
1267d8408326SSeung-Woo Kim
exynos_mixer_suspend(struct device * dev)1268e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_suspend(struct device *dev)
1269ccf034a9SGustavo Padovan {
1270ccf034a9SGustavo Padovan struct mixer_context *ctx = dev_get_drvdata(dev);
1271ccf034a9SGustavo Padovan
1272524c59f1SAndrzej Hajda clk_disable_unprepare(ctx->hdmi);
1273524c59f1SAndrzej Hajda clk_disable_unprepare(ctx->mixer);
1274adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
1275524c59f1SAndrzej Hajda clk_disable_unprepare(ctx->vp);
1276adeb6f44STobias Jakobi if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags))
1277524c59f1SAndrzej Hajda clk_disable_unprepare(ctx->sclk_mixer);
1278ccf034a9SGustavo Padovan }
1279ccf034a9SGustavo Padovan
1280ccf034a9SGustavo Padovan return 0;
1281ccf034a9SGustavo Padovan }
1282ccf034a9SGustavo Padovan
exynos_mixer_resume(struct device * dev)1283e0fea7e7SArnd Bergmann static int __maybe_unused exynos_mixer_resume(struct device *dev)
1284ccf034a9SGustavo Padovan {
1285ccf034a9SGustavo Padovan struct mixer_context *ctx = dev_get_drvdata(dev);
1286ccf034a9SGustavo Padovan int ret;
1287ccf034a9SGustavo Padovan
1288524c59f1SAndrzej Hajda ret = clk_prepare_enable(ctx->mixer);
1289ccf034a9SGustavo Padovan if (ret < 0) {
12906f83d208SInki Dae DRM_DEV_ERROR(ctx->dev,
12916f83d208SInki Dae "Failed to prepare_enable the mixer clk [%d]\n",
12926f83d208SInki Dae ret);
1293ccf034a9SGustavo Padovan return ret;
1294ccf034a9SGustavo Padovan }
1295524c59f1SAndrzej Hajda ret = clk_prepare_enable(ctx->hdmi);
1296ccf034a9SGustavo Padovan if (ret < 0) {
12976f83d208SInki Dae DRM_DEV_ERROR(dev,
12986f83d208SInki Dae "Failed to prepare_enable the hdmi clk [%d]\n",
12996f83d208SInki Dae ret);
1300ccf034a9SGustavo Padovan return ret;
1301ccf034a9SGustavo Padovan }
1302adeb6f44STobias Jakobi if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) {
1303524c59f1SAndrzej Hajda ret = clk_prepare_enable(ctx->vp);
1304ccf034a9SGustavo Padovan if (ret < 0) {
13056f83d208SInki Dae DRM_DEV_ERROR(dev,
13066f83d208SInki Dae "Failed to prepare_enable the vp clk [%d]\n",
1307ccf034a9SGustavo Padovan ret);
1308ccf034a9SGustavo Padovan return ret;
1309ccf034a9SGustavo Padovan }
1310adeb6f44STobias Jakobi if (test_bit(MXR_BIT_HAS_SCLK, &ctx->flags)) {
1311524c59f1SAndrzej Hajda ret = clk_prepare_enable(ctx->sclk_mixer);
1312ccf034a9SGustavo Padovan if (ret < 0) {
13136f83d208SInki Dae DRM_DEV_ERROR(dev,
13146f83d208SInki Dae "Failed to prepare_enable the " \
1315ccf034a9SGustavo Padovan "sclk_mixer clk [%d]\n",
1316ccf034a9SGustavo Padovan ret);
1317ccf034a9SGustavo Padovan return ret;
1318ccf034a9SGustavo Padovan }
1319ccf034a9SGustavo Padovan }
1320ccf034a9SGustavo Padovan }
1321ccf034a9SGustavo Padovan
1322ccf034a9SGustavo Padovan return 0;
1323ccf034a9SGustavo Padovan }
1324ccf034a9SGustavo Padovan
1325ccf034a9SGustavo Padovan static const struct dev_pm_ops exynos_mixer_pm_ops = {
1326ccf034a9SGustavo Padovan SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL)
13277e915746SMarek Szyprowski SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
13287e915746SMarek Szyprowski pm_runtime_force_resume)
1329ccf034a9SGustavo Padovan };
1330ccf034a9SGustavo Padovan
1331d8408326SSeung-Woo Kim struct platform_driver mixer_driver = {
1332d8408326SSeung-Woo Kim .driver = {
1333aaf8b49eSRahul Sharma .name = "exynos-mixer",
1334ccf034a9SGustavo Padovan .pm = &exynos_mixer_pm_ops,
1335aaf8b49eSRahul Sharma .of_match_table = mixer_match_types,
1336d8408326SSeung-Woo Kim },
1337d8408326SSeung-Woo Kim .probe = mixer_probe,
1338*4fe7a1ecSUwe Kleine-König .remove_new = mixer_remove,
1339d8408326SSeung-Woo Kim };
1340