blob: 31a9a228744e7d09140a5f77d713ebdd18749809 [file] [log] [blame]
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001/*
2 * Copyright (C) 2011 Samsung Electronics Co.Ltd
3 * Authors:
4 * Seung-Woo Kim <sw0312.kim@samsung.com>
5 * Inki Dae <inki.dae@samsung.com>
6 * Joonyoung Shim <jy0922.shim@samsung.com>
7 *
8 * Based on drivers/media/video/s5p-tv/mixer_reg.c
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 *
15 */
16
David Howells760285e2012-10-02 18:01:07 +010017#include <drm/drmP.h>
Seung-Woo Kimd8408322011-12-21 17:39:39 +090018
19#include "regs-mixer.h"
20#include "regs-vp.h"
21
22#include <linux/kernel.h>
23#include <linux/spinlock.h>
24#include <linux/wait.h>
25#include <linux/i2c.h>
Seung-Woo Kimd8408322011-12-21 17:39:39 +090026#include <linux/platform_device.h>
27#include <linux/interrupt.h>
28#include <linux/irq.h>
29#include <linux/delay.h>
30#include <linux/pm_runtime.h>
31#include <linux/clk.h>
32#include <linux/regulator/consumer.h>
Sachin Kamat3f1c7812013-08-14 16:38:01 +053033#include <linux/of.h>
Inki Daef37cd5e2014-05-09 14:25:20 +090034#include <linux/component.h>
Seung-Woo Kimd8408322011-12-21 17:39:39 +090035
36#include <drm/exynos_drm.h>
37
38#include "exynos_drm_drv.h"
Rahul Sharma663d8762013-01-03 05:44:04 -050039#include "exynos_drm_crtc.h"
Marek Szyprowski0488f502015-11-30 14:53:21 +010040#include "exynos_drm_fb.h"
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +090041#include "exynos_drm_plane.h"
Inki Dae1055b392012-10-19 17:37:35 +090042#include "exynos_drm_iommu.h"
Joonyoung Shim22b21ae2012-03-15 17:19:04 +090043
Sean Paulf041b252014-01-30 16:19:15 -050044#define MIXER_WIN_NR 3
Marek Szyprowskifbbb1e12015-08-31 00:53:57 +090045#define VP_DEFAULT_WIN 2
Seung-Woo Kimd8408322011-12-21 17:39:39 +090046
Tobias Jakobi7a57ca72015-04-27 23:11:59 +020047/* The pixelformats that are natively supported by the mixer. */
48#define MXR_FORMAT_RGB565 4
49#define MXR_FORMAT_ARGB1555 5
50#define MXR_FORMAT_ARGB4444 6
51#define MXR_FORMAT_ARGB8888 7
52
Joonyoung Shim22b21ae2012-03-15 17:19:04 +090053struct mixer_resources {
Joonyoung Shim22b21ae2012-03-15 17:19:04 +090054 int irq;
55 void __iomem *mixer_regs;
56 void __iomem *vp_regs;
57 spinlock_t reg_slock;
58 struct clk *mixer;
59 struct clk *vp;
Marek Szyprowski04427ec2015-02-02 14:20:28 +010060 struct clk *hdmi;
Joonyoung Shim22b21ae2012-03-15 17:19:04 +090061 struct clk *sclk_mixer;
62 struct clk *sclk_hdmi;
Marek Szyprowskiff830c92014-07-01 10:10:07 +020063 struct clk *mout_mixer;
Joonyoung Shim22b21ae2012-03-15 17:19:04 +090064};
65
Rahul Sharma1e123442012-10-04 20:48:51 +053066enum mixer_version_id {
67 MXR_VER_0_0_0_16,
68 MXR_VER_16_0_33_0,
Rahul Sharmadef5e092013-06-19 18:21:08 +053069 MXR_VER_128_0_0_184,
Rahul Sharma1e123442012-10-04 20:48:51 +053070};
71
Andrzej Hajdaa44652e2015-07-09 08:25:42 +020072enum mixer_flag_bits {
73 MXR_BIT_POWERED,
Andrzej Hajda0df5e4a2015-07-09 08:25:43 +020074 MXR_BIT_VSYNC,
Andrzej Hajdaa44652e2015-07-09 08:25:42 +020075};
76
Marek Szyprowskifbbb1e12015-08-31 00:53:57 +090077static const uint32_t mixer_formats[] = {
78 DRM_FORMAT_XRGB4444,
Tobias Jakobi26a7af32015-12-16 13:21:47 +010079 DRM_FORMAT_ARGB4444,
Marek Szyprowskifbbb1e12015-08-31 00:53:57 +090080 DRM_FORMAT_XRGB1555,
Tobias Jakobi26a7af32015-12-16 13:21:47 +010081 DRM_FORMAT_ARGB1555,
Marek Szyprowskifbbb1e12015-08-31 00:53:57 +090082 DRM_FORMAT_RGB565,
83 DRM_FORMAT_XRGB8888,
84 DRM_FORMAT_ARGB8888,
85};
86
87static const uint32_t vp_formats[] = {
88 DRM_FORMAT_NV12,
89 DRM_FORMAT_NV21,
90};
91
Joonyoung Shim22b21ae2012-03-15 17:19:04 +090092struct mixer_context {
Sean Paul45517892014-01-30 16:19:05 -050093 struct platform_device *pdev;
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +090094 struct device *dev;
Inki Dae1055b392012-10-19 17:37:35 +090095 struct drm_device *drm_dev;
Gustavo Padovan93bca242015-01-18 18:16:23 +090096 struct exynos_drm_crtc *crtc;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +090097 struct exynos_drm_plane planes[MIXER_WIN_NR];
Joonyoung Shim22b21ae2012-03-15 17:19:04 +090098 int pipe;
Andrzej Hajdaa44652e2015-07-09 08:25:42 +020099 unsigned long flags;
Joonyoung Shim22b21ae2012-03-15 17:19:04 +0900100 bool interlace;
Rahul Sharma1b8e5742012-10-04 20:48:52 +0530101 bool vp_enabled;
Marek Szyprowskiff830c92014-07-01 10:10:07 +0200102 bool has_sclk;
Joonyoung Shim22b21ae2012-03-15 17:19:04 +0900103
104 struct mixer_resources mixer_res;
Rahul Sharma1e123442012-10-04 20:48:51 +0530105 enum mixer_version_id mxr_ver;
Prathyush K6e95d5e2012-12-06 20:16:03 +0530106 wait_queue_head_t wait_vsync_queue;
107 atomic_t wait_vsync_event;
Rahul Sharma1e123442012-10-04 20:48:51 +0530108};
109
110struct mixer_drv_data {
111 enum mixer_version_id version;
Rahul Sharma1b8e5742012-10-04 20:48:52 +0530112 bool is_vp_enabled;
Marek Szyprowskiff830c92014-07-01 10:10:07 +0200113 bool has_sclk;
Joonyoung Shim22b21ae2012-03-15 17:19:04 +0900114};
115
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +0100116static const struct exynos_drm_plane_config plane_configs[MIXER_WIN_NR] = {
117 {
118 .zpos = 0,
119 .type = DRM_PLANE_TYPE_PRIMARY,
120 .pixel_formats = mixer_formats,
121 .num_pixel_formats = ARRAY_SIZE(mixer_formats),
Marek Szyprowskia2cb9112015-12-16 13:21:44 +0100122 .capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
123 EXYNOS_DRM_PLANE_CAP_ZPOS,
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +0100124 }, {
125 .zpos = 1,
126 .type = DRM_PLANE_TYPE_CURSOR,
127 .pixel_formats = mixer_formats,
128 .num_pixel_formats = ARRAY_SIZE(mixer_formats),
Marek Szyprowskia2cb9112015-12-16 13:21:44 +0100129 .capabilities = EXYNOS_DRM_PLANE_CAP_DOUBLE |
130 EXYNOS_DRM_PLANE_CAP_ZPOS,
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +0100131 }, {
132 .zpos = 2,
133 .type = DRM_PLANE_TYPE_OVERLAY,
134 .pixel_formats = vp_formats,
135 .num_pixel_formats = ARRAY_SIZE(vp_formats),
Marek Szyprowskia2cb9112015-12-16 13:21:44 +0100136 .capabilities = EXYNOS_DRM_PLANE_CAP_SCALE |
137 EXYNOS_DRM_PLANE_CAP_ZPOS,
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +0100138 },
139};
140
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900141static const u8 filter_y_horiz_tap8[] = {
142 0, -1, -1, -1, -1, -1, -1, -1,
143 -1, -1, -1, -1, -1, 0, 0, 0,
144 0, 2, 4, 5, 6, 6, 6, 6,
145 6, 5, 5, 4, 3, 2, 1, 1,
146 0, -6, -12, -16, -18, -20, -21, -20,
147 -20, -18, -16, -13, -10, -8, -5, -2,
148 127, 126, 125, 121, 114, 107, 99, 89,
149 79, 68, 57, 46, 35, 25, 16, 8,
150};
151
152static const u8 filter_y_vert_tap4[] = {
153 0, -3, -6, -8, -8, -8, -8, -7,
154 -6, -5, -4, -3, -2, -1, -1, 0,
155 127, 126, 124, 118, 111, 102, 92, 81,
156 70, 59, 48, 37, 27, 19, 11, 5,
157 0, 5, 11, 19, 27, 37, 48, 59,
158 70, 81, 92, 102, 111, 118, 124, 126,
159 0, 0, -1, -1, -2, -3, -4, -5,
160 -6, -7, -8, -8, -8, -8, -6, -3,
161};
162
163static const u8 filter_cr_horiz_tap4[] = {
164 0, -3, -6, -8, -8, -8, -8, -7,
165 -6, -5, -4, -3, -2, -1, -1, 0,
166 127, 126, 124, 118, 111, 102, 92, 81,
167 70, 59, 48, 37, 27, 19, 11, 5,
168};
169
Marek Szyprowskif657a992015-12-16 13:21:46 +0100170static inline bool is_alpha_format(unsigned int pixel_format)
171{
172 switch (pixel_format) {
173 case DRM_FORMAT_ARGB8888:
Tobias Jakobi26a7af32015-12-16 13:21:47 +0100174 case DRM_FORMAT_ARGB1555:
175 case DRM_FORMAT_ARGB4444:
Marek Szyprowskif657a992015-12-16 13:21:46 +0100176 return true;
177 default:
178 return false;
179 }
180}
181
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900182static inline u32 vp_reg_read(struct mixer_resources *res, u32 reg_id)
183{
184 return readl(res->vp_regs + reg_id);
185}
186
187static inline void vp_reg_write(struct mixer_resources *res, u32 reg_id,
188 u32 val)
189{
190 writel(val, res->vp_regs + reg_id);
191}
192
193static inline void vp_reg_writemask(struct mixer_resources *res, u32 reg_id,
194 u32 val, u32 mask)
195{
196 u32 old = vp_reg_read(res, reg_id);
197
198 val = (val & mask) | (old & ~mask);
199 writel(val, res->vp_regs + reg_id);
200}
201
202static inline u32 mixer_reg_read(struct mixer_resources *res, u32 reg_id)
203{
204 return readl(res->mixer_regs + reg_id);
205}
206
207static inline void mixer_reg_write(struct mixer_resources *res, u32 reg_id,
208 u32 val)
209{
210 writel(val, res->mixer_regs + reg_id);
211}
212
213static inline void mixer_reg_writemask(struct mixer_resources *res,
214 u32 reg_id, u32 val, u32 mask)
215{
216 u32 old = mixer_reg_read(res, reg_id);
217
218 val = (val & mask) | (old & ~mask);
219 writel(val, res->mixer_regs + reg_id);
220}
221
222static void mixer_regs_dump(struct mixer_context *ctx)
223{
224#define DUMPREG(reg_id) \
225do { \
226 DRM_DEBUG_KMS(#reg_id " = %08x\n", \
227 (u32)readl(ctx->mixer_res.mixer_regs + reg_id)); \
228} while (0)
229
230 DUMPREG(MXR_STATUS);
231 DUMPREG(MXR_CFG);
232 DUMPREG(MXR_INT_EN);
233 DUMPREG(MXR_INT_STATUS);
234
235 DUMPREG(MXR_LAYER_CFG);
236 DUMPREG(MXR_VIDEO_CFG);
237
238 DUMPREG(MXR_GRAPHIC0_CFG);
239 DUMPREG(MXR_GRAPHIC0_BASE);
240 DUMPREG(MXR_GRAPHIC0_SPAN);
241 DUMPREG(MXR_GRAPHIC0_WH);
242 DUMPREG(MXR_GRAPHIC0_SXY);
243 DUMPREG(MXR_GRAPHIC0_DXY);
244
245 DUMPREG(MXR_GRAPHIC1_CFG);
246 DUMPREG(MXR_GRAPHIC1_BASE);
247 DUMPREG(MXR_GRAPHIC1_SPAN);
248 DUMPREG(MXR_GRAPHIC1_WH);
249 DUMPREG(MXR_GRAPHIC1_SXY);
250 DUMPREG(MXR_GRAPHIC1_DXY);
251#undef DUMPREG
252}
253
254static void vp_regs_dump(struct mixer_context *ctx)
255{
256#define DUMPREG(reg_id) \
257do { \
258 DRM_DEBUG_KMS(#reg_id " = %08x\n", \
259 (u32) readl(ctx->mixer_res.vp_regs + reg_id)); \
260} while (0)
261
262 DUMPREG(VP_ENABLE);
263 DUMPREG(VP_SRESET);
264 DUMPREG(VP_SHADOW_UPDATE);
265 DUMPREG(VP_FIELD_ID);
266 DUMPREG(VP_MODE);
267 DUMPREG(VP_IMG_SIZE_Y);
268 DUMPREG(VP_IMG_SIZE_C);
269 DUMPREG(VP_PER_RATE_CTRL);
270 DUMPREG(VP_TOP_Y_PTR);
271 DUMPREG(VP_BOT_Y_PTR);
272 DUMPREG(VP_TOP_C_PTR);
273 DUMPREG(VP_BOT_C_PTR);
274 DUMPREG(VP_ENDIAN_MODE);
275 DUMPREG(VP_SRC_H_POSITION);
276 DUMPREG(VP_SRC_V_POSITION);
277 DUMPREG(VP_SRC_WIDTH);
278 DUMPREG(VP_SRC_HEIGHT);
279 DUMPREG(VP_DST_H_POSITION);
280 DUMPREG(VP_DST_V_POSITION);
281 DUMPREG(VP_DST_WIDTH);
282 DUMPREG(VP_DST_HEIGHT);
283 DUMPREG(VP_H_RATIO);
284 DUMPREG(VP_V_RATIO);
285
286#undef DUMPREG
287}
288
289static inline void vp_filter_set(struct mixer_resources *res,
290 int reg_id, const u8 *data, unsigned int size)
291{
292 /* assure 4-byte align */
293 BUG_ON(size & 3);
294 for (; size; size -= 4, reg_id += 4, data += 4) {
295 u32 val = (data[0] << 24) | (data[1] << 16) |
296 (data[2] << 8) | data[3];
297 vp_reg_write(res, reg_id, val);
298 }
299}
300
301static void vp_default_filter(struct mixer_resources *res)
302{
303 vp_filter_set(res, VP_POLY8_Y0_LL,
Sachin Kamate25e1b62012-08-31 15:50:48 +0530304 filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900305 vp_filter_set(res, VP_POLY4_Y0_LL,
Sachin Kamate25e1b62012-08-31 15:50:48 +0530306 filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900307 vp_filter_set(res, VP_POLY4_C0_LL,
Sachin Kamate25e1b62012-08-31 15:50:48 +0530308 filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900309}
310
Marek Szyprowskif657a992015-12-16 13:21:46 +0100311static void mixer_cfg_gfx_blend(struct mixer_context *ctx, unsigned int win,
312 bool alpha)
313{
314 struct mixer_resources *res = &ctx->mixer_res;
315 u32 val;
316
317 val = MXR_GRP_CFG_COLOR_KEY_DISABLE; /* no blank key */
318 if (alpha) {
319 /* blending based on pixel alpha */
320 val |= MXR_GRP_CFG_BLEND_PRE_MUL;
321 val |= MXR_GRP_CFG_PIXEL_BLEND_EN;
322 }
323 mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
324 val, MXR_GRP_CFG_MISC_MASK);
325}
326
327static void mixer_cfg_vp_blend(struct mixer_context *ctx)
328{
329 struct mixer_resources *res = &ctx->mixer_res;
330 u32 val;
331
332 /*
333 * No blending at the moment since the NV12/NV21 pixelformats don't
334 * have an alpha channel. However the mixer supports a global alpha
335 * value for a layer. Once this functionality is exposed, we can
336 * support blending of the video layer through this.
337 */
338 val = 0;
339 mixer_reg_write(res, MXR_VIDEO_CFG, val);
340}
341
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900342static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable)
343{
344 struct mixer_resources *res = &ctx->mixer_res;
345
346 /* block update on vsync */
347 mixer_reg_writemask(res, MXR_STATUS, enable ?
348 MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE);
349
Rahul Sharma1b8e5742012-10-04 20:48:52 +0530350 if (ctx->vp_enabled)
351 vp_reg_write(res, VP_SHADOW_UPDATE, enable ?
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900352 VP_SHADOW_UPDATE_ENABLE : 0);
353}
354
355static void mixer_cfg_scan(struct mixer_context *ctx, unsigned int height)
356{
357 struct mixer_resources *res = &ctx->mixer_res;
358 u32 val;
359
360 /* choosing between interlace and progressive mode */
361 val = (ctx->interlace ? MXR_CFG_SCAN_INTERLACE :
Tobias Jakobi1e6d4592015-04-07 01:14:50 +0200362 MXR_CFG_SCAN_PROGRESSIVE);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900363
Rahul Sharmadef5e092013-06-19 18:21:08 +0530364 if (ctx->mxr_ver != MXR_VER_128_0_0_184) {
365 /* choosing between proper HD and SD mode */
366 if (height <= 480)
367 val |= MXR_CFG_SCAN_NTSC | MXR_CFG_SCAN_SD;
368 else if (height <= 576)
369 val |= MXR_CFG_SCAN_PAL | MXR_CFG_SCAN_SD;
370 else if (height <= 720)
371 val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
372 else if (height <= 1080)
373 val |= MXR_CFG_SCAN_HD_1080 | MXR_CFG_SCAN_HD;
374 else
375 val |= MXR_CFG_SCAN_HD_720 | MXR_CFG_SCAN_HD;
376 }
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900377
378 mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_SCAN_MASK);
379}
380
381static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height)
382{
383 struct mixer_resources *res = &ctx->mixer_res;
384 u32 val;
385
386 if (height == 480) {
387 val = MXR_CFG_RGB601_0_255;
388 } else if (height == 576) {
389 val = MXR_CFG_RGB601_0_255;
390 } else if (height == 720) {
391 val = MXR_CFG_RGB709_16_235;
392 mixer_reg_write(res, MXR_CM_COEFF_Y,
393 (1 << 30) | (94 << 20) | (314 << 10) |
394 (32 << 0));
395 mixer_reg_write(res, MXR_CM_COEFF_CB,
396 (972 << 20) | (851 << 10) | (225 << 0));
397 mixer_reg_write(res, MXR_CM_COEFF_CR,
398 (225 << 20) | (820 << 10) | (1004 << 0));
399 } else if (height == 1080) {
400 val = MXR_CFG_RGB709_16_235;
401 mixer_reg_write(res, MXR_CM_COEFF_Y,
402 (1 << 30) | (94 << 20) | (314 << 10) |
403 (32 << 0));
404 mixer_reg_write(res, MXR_CM_COEFF_CB,
405 (972 << 20) | (851 << 10) | (225 << 0));
406 mixer_reg_write(res, MXR_CM_COEFF_CR,
407 (225 << 20) | (820 << 10) | (1004 << 0));
408 } else {
409 val = MXR_CFG_RGB709_16_235;
410 mixer_reg_write(res, MXR_CM_COEFF_Y,
411 (1 << 30) | (94 << 20) | (314 << 10) |
412 (32 << 0));
413 mixer_reg_write(res, MXR_CM_COEFF_CB,
414 (972 << 20) | (851 << 10) | (225 << 0));
415 mixer_reg_write(res, MXR_CM_COEFF_CR,
416 (225 << 20) | (820 << 10) | (1004 << 0));
417 }
418
419 mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
420}
421
Tobias Jakobi5b1d5bc2015-05-06 14:10:22 +0200422static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win,
Marek Szyprowskia2cb9112015-12-16 13:21:44 +0100423 unsigned int priority, bool enable)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900424{
425 struct mixer_resources *res = &ctx->mixer_res;
426 u32 val = enable ? ~0 : 0;
427
428 switch (win) {
429 case 0:
430 mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP0_ENABLE);
Marek Szyprowskia2cb9112015-12-16 13:21:44 +0100431 mixer_reg_writemask(res, MXR_LAYER_CFG,
432 MXR_LAYER_CFG_GRP0_VAL(priority),
433 MXR_LAYER_CFG_GRP0_MASK);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900434 break;
435 case 1:
436 mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_GRP1_ENABLE);
Marek Szyprowskia2cb9112015-12-16 13:21:44 +0100437 mixer_reg_writemask(res, MXR_LAYER_CFG,
438 MXR_LAYER_CFG_GRP1_VAL(priority),
439 MXR_LAYER_CFG_GRP1_MASK);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900440 break;
441 case 2:
Rahul Sharma1b8e5742012-10-04 20:48:52 +0530442 if (ctx->vp_enabled) {
443 vp_reg_writemask(res, VP_ENABLE, val, VP_ENABLE_ON);
444 mixer_reg_writemask(res, MXR_CFG, val,
445 MXR_CFG_VP_ENABLE);
Marek Szyprowskia2cb9112015-12-16 13:21:44 +0100446 mixer_reg_writemask(res, MXR_LAYER_CFG,
447 MXR_LAYER_CFG_VP_VAL(priority),
448 MXR_LAYER_CFG_VP_MASK);
Rahul Sharma1b8e5742012-10-04 20:48:52 +0530449 }
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900450 break;
451 }
452}
453
454static void mixer_run(struct mixer_context *ctx)
455{
456 struct mixer_resources *res = &ctx->mixer_res;
457
458 mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900459}
460
Rahul Sharma381be022014-06-23 11:02:22 +0530461static void mixer_stop(struct mixer_context *ctx)
462{
463 struct mixer_resources *res = &ctx->mixer_res;
464 int timeout = 20;
465
466 mixer_reg_writemask(res, MXR_STATUS, 0, MXR_STATUS_REG_RUN);
467
468 while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
469 --timeout)
470 usleep_range(10000, 12000);
Rahul Sharma381be022014-06-23 11:02:22 +0530471}
472
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900473static void vp_video_buffer(struct mixer_context *ctx,
474 struct exynos_drm_plane *plane)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900475{
Marek Szyprowski0114f402015-11-30 14:53:22 +0100476 struct exynos_drm_plane_state *state =
477 to_exynos_plane_state(plane->base.state);
Marek Szyprowski2ee35d82015-11-30 14:53:23 +0100478 struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900479 struct mixer_resources *res = &ctx->mixer_res;
Marek Szyprowski0114f402015-11-30 14:53:22 +0100480 struct drm_framebuffer *fb = state->base.fb;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900481 unsigned long flags;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900482 dma_addr_t luma_addr[2], chroma_addr[2];
483 bool tiled_mode = false;
484 bool crcb_mode = false;
485 u32 val;
486
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900487 switch (fb->pixel_format) {
Ville Syrjälä363b06a2012-05-14 11:08:51 +0900488 case DRM_FORMAT_NV12:
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900489 crcb_mode = false;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900490 break;
Tobias Jakobi8f2590f2015-04-27 23:10:16 +0200491 case DRM_FORMAT_NV21:
492 crcb_mode = true;
493 break;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900494 default:
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900495 DRM_ERROR("pixel format for vp is wrong [%d].\n",
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900496 fb->pixel_format);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900497 return;
498 }
499
Marek Szyprowski0488f502015-11-30 14:53:21 +0100500 luma_addr[0] = exynos_drm_fb_dma_addr(fb, 0);
501 chroma_addr[0] = exynos_drm_fb_dma_addr(fb, 1);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900502
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900503 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900504 ctx->interlace = true;
505 if (tiled_mode) {
506 luma_addr[1] = luma_addr[0] + 0x40;
507 chroma_addr[1] = chroma_addr[0] + 0x40;
508 } else {
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900509 luma_addr[1] = luma_addr[0] + fb->pitches[0];
510 chroma_addr[1] = chroma_addr[0] + fb->pitches[0];
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900511 }
512 } else {
513 ctx->interlace = false;
514 luma_addr[1] = 0;
515 chroma_addr[1] = 0;
516 }
517
518 spin_lock_irqsave(&res->reg_slock, flags);
519 mixer_vsync_set_update(ctx, false);
520
521 /* interlace or progressive scan mode */
522 val = (ctx->interlace ? ~0 : 0);
523 vp_reg_writemask(res, VP_MODE, val, VP_MODE_LINE_SKIP);
524
525 /* setup format */
526 val = (crcb_mode ? VP_MODE_NV21 : VP_MODE_NV12);
527 val |= (tiled_mode ? VP_MODE_MEM_TILED : VP_MODE_MEM_LINEAR);
528 vp_reg_writemask(res, VP_MODE, val, VP_MODE_FMT_MASK);
529
530 /* setting size of input image */
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900531 vp_reg_write(res, VP_IMG_SIZE_Y, VP_IMG_HSIZE(fb->pitches[0]) |
532 VP_IMG_VSIZE(fb->height));
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900533 /* chroma height has to reduced by 2 to avoid chroma distorions */
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900534 vp_reg_write(res, VP_IMG_SIZE_C, VP_IMG_HSIZE(fb->pitches[0]) |
535 VP_IMG_VSIZE(fb->height / 2));
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900536
Marek Szyprowski0114f402015-11-30 14:53:22 +0100537 vp_reg_write(res, VP_SRC_WIDTH, state->src.w);
538 vp_reg_write(res, VP_SRC_HEIGHT, state->src.h);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900539 vp_reg_write(res, VP_SRC_H_POSITION,
Marek Szyprowski0114f402015-11-30 14:53:22 +0100540 VP_SRC_H_POSITION_VAL(state->src.x));
541 vp_reg_write(res, VP_SRC_V_POSITION, state->src.y);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900542
Marek Szyprowski0114f402015-11-30 14:53:22 +0100543 vp_reg_write(res, VP_DST_WIDTH, state->crtc.w);
544 vp_reg_write(res, VP_DST_H_POSITION, state->crtc.x);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900545 if (ctx->interlace) {
Marek Szyprowski0114f402015-11-30 14:53:22 +0100546 vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h / 2);
547 vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y / 2);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900548 } else {
Marek Szyprowski0114f402015-11-30 14:53:22 +0100549 vp_reg_write(res, VP_DST_HEIGHT, state->crtc.h);
550 vp_reg_write(res, VP_DST_V_POSITION, state->crtc.y);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900551 }
552
Marek Szyprowski0114f402015-11-30 14:53:22 +0100553 vp_reg_write(res, VP_H_RATIO, state->h_ratio);
554 vp_reg_write(res, VP_V_RATIO, state->v_ratio);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900555
556 vp_reg_write(res, VP_ENDIAN_MODE, VP_ENDIAN_MODE_LITTLE);
557
558 /* set buffer address to vp */
559 vp_reg_write(res, VP_TOP_Y_PTR, luma_addr[0]);
560 vp_reg_write(res, VP_BOT_Y_PTR, luma_addr[1]);
561 vp_reg_write(res, VP_TOP_C_PTR, chroma_addr[0]);
562 vp_reg_write(res, VP_BOT_C_PTR, chroma_addr[1]);
563
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900564 mixer_cfg_scan(ctx, mode->vdisplay);
565 mixer_cfg_rgb_fmt(ctx, mode->vdisplay);
Marek Szyprowskia2cb9112015-12-16 13:21:44 +0100566 mixer_cfg_layer(ctx, plane->index, state->zpos + 1, true);
Marek Szyprowskif657a992015-12-16 13:21:46 +0100567 mixer_cfg_vp_blend(ctx);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900568 mixer_run(ctx);
569
570 mixer_vsync_set_update(ctx, true);
571 spin_unlock_irqrestore(&res->reg_slock, flags);
572
Tobias Jakobic0734fb2015-05-06 14:10:21 +0200573 mixer_regs_dump(ctx);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900574 vp_regs_dump(ctx);
575}
576
Rahul Sharmaaaf8b492012-10-04 20:48:53 +0530577static void mixer_layer_update(struct mixer_context *ctx)
578{
579 struct mixer_resources *res = &ctx->mixer_res;
Rahul Sharmaaaf8b492012-10-04 20:48:53 +0530580
Rahul Sharma5c0f4822014-06-23 11:02:23 +0530581 mixer_reg_writemask(res, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
Rahul Sharmaaaf8b492012-10-04 20:48:53 +0530582}
583
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900584static void mixer_graph_buffer(struct mixer_context *ctx,
585 struct exynos_drm_plane *plane)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900586{
Marek Szyprowski0114f402015-11-30 14:53:22 +0100587 struct exynos_drm_plane_state *state =
588 to_exynos_plane_state(plane->base.state);
Marek Szyprowski2ee35d82015-11-30 14:53:23 +0100589 struct drm_display_mode *mode = &state->base.crtc->state->adjusted_mode;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900590 struct mixer_resources *res = &ctx->mixer_res;
Marek Szyprowski0114f402015-11-30 14:53:22 +0100591 struct drm_framebuffer *fb = state->base.fb;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900592 unsigned long flags;
Marek Szyprowski40bdfb02015-12-16 13:21:42 +0100593 unsigned int win = plane->index;
Tobias Jakobi26110152015-04-07 01:14:52 +0200594 unsigned int x_ratio = 0, y_ratio = 0;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900595 unsigned int src_x_offset, src_y_offset, dst_x_offset, dst_y_offset;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900596 dma_addr_t dma_addr;
597 unsigned int fmt;
598 u32 val;
599
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900600 switch (fb->pixel_format) {
Tobias Jakobi7a57ca72015-04-27 23:11:59 +0200601 case DRM_FORMAT_XRGB4444:
Tobias Jakobi26a7af32015-12-16 13:21:47 +0100602 case DRM_FORMAT_ARGB4444:
Tobias Jakobi7a57ca72015-04-27 23:11:59 +0200603 fmt = MXR_FORMAT_ARGB4444;
604 break;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900605
Tobias Jakobi7a57ca72015-04-27 23:11:59 +0200606 case DRM_FORMAT_XRGB1555:
Tobias Jakobi26a7af32015-12-16 13:21:47 +0100607 case DRM_FORMAT_ARGB1555:
Tobias Jakobi7a57ca72015-04-27 23:11:59 +0200608 fmt = MXR_FORMAT_ARGB1555;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900609 break;
Tobias Jakobi7a57ca72015-04-27 23:11:59 +0200610
611 case DRM_FORMAT_RGB565:
612 fmt = MXR_FORMAT_RGB565;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900613 break;
Tobias Jakobi7a57ca72015-04-27 23:11:59 +0200614
615 case DRM_FORMAT_XRGB8888:
616 case DRM_FORMAT_ARGB8888:
617 fmt = MXR_FORMAT_ARGB8888;
618 break;
619
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900620 default:
Tobias Jakobi7a57ca72015-04-27 23:11:59 +0200621 DRM_DEBUG_KMS("pixelformat unsupported by mixer\n");
622 return;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900623 }
624
Marek Szyprowskie463b062015-11-30 14:53:27 +0100625 /* ratio is already checked by common plane code */
626 x_ratio = state->h_ratio == (1 << 15);
627 y_ratio = state->v_ratio == (1 << 15);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900628
Marek Szyprowski0114f402015-11-30 14:53:22 +0100629 dst_x_offset = state->crtc.x;
630 dst_y_offset = state->crtc.y;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900631
632 /* converting dma address base and source offset */
Marek Szyprowski0488f502015-11-30 14:53:21 +0100633 dma_addr = exynos_drm_fb_dma_addr(fb, 0)
Marek Szyprowski0114f402015-11-30 14:53:22 +0100634 + (state->src.x * fb->bits_per_pixel >> 3)
635 + (state->src.y * fb->pitches[0]);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900636 src_x_offset = 0;
637 src_y_offset = 0;
638
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900639 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900640 ctx->interlace = true;
641 else
642 ctx->interlace = false;
643
644 spin_lock_irqsave(&res->reg_slock, flags);
645 mixer_vsync_set_update(ctx, false);
646
647 /* setup format */
648 mixer_reg_writemask(res, MXR_GRAPHIC_CFG(win),
649 MXR_GRP_CFG_FORMAT_VAL(fmt), MXR_GRP_CFG_FORMAT_MASK);
650
651 /* setup geometry */
Daniel Stoneadacb222015-03-17 13:24:58 +0000652 mixer_reg_write(res, MXR_GRAPHIC_SPAN(win),
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900653 fb->pitches[0] / (fb->bits_per_pixel >> 3));
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900654
Rahul Sharmadef5e092013-06-19 18:21:08 +0530655 /* setup display size */
656 if (ctx->mxr_ver == MXR_VER_128_0_0_184 &&
Gustavo Padovan5d3d0992015-10-12 22:07:48 +0900657 win == DEFAULT_WIN) {
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900658 val = MXR_MXR_RES_HEIGHT(mode->vdisplay);
659 val |= MXR_MXR_RES_WIDTH(mode->hdisplay);
Rahul Sharmadef5e092013-06-19 18:21:08 +0530660 mixer_reg_write(res, MXR_RESOLUTION, val);
661 }
662
Marek Szyprowski0114f402015-11-30 14:53:22 +0100663 val = MXR_GRP_WH_WIDTH(state->src.w);
664 val |= MXR_GRP_WH_HEIGHT(state->src.h);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900665 val |= MXR_GRP_WH_H_SCALE(x_ratio);
666 val |= MXR_GRP_WH_V_SCALE(y_ratio);
667 mixer_reg_write(res, MXR_GRAPHIC_WH(win), val);
668
669 /* setup offsets in source image */
670 val = MXR_GRP_SXY_SX(src_x_offset);
671 val |= MXR_GRP_SXY_SY(src_y_offset);
672 mixer_reg_write(res, MXR_GRAPHIC_SXY(win), val);
673
674 /* setup offsets in display image */
675 val = MXR_GRP_DXY_DX(dst_x_offset);
676 val |= MXR_GRP_DXY_DY(dst_y_offset);
677 mixer_reg_write(res, MXR_GRAPHIC_DXY(win), val);
678
679 /* set buffer address to mixer */
680 mixer_reg_write(res, MXR_GRAPHIC_BASE(win), dma_addr);
681
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900682 mixer_cfg_scan(ctx, mode->vdisplay);
683 mixer_cfg_rgb_fmt(ctx, mode->vdisplay);
Marek Szyprowskia2cb9112015-12-16 13:21:44 +0100684 mixer_cfg_layer(ctx, win, state->zpos + 1, true);
Marek Szyprowskif657a992015-12-16 13:21:46 +0100685 mixer_cfg_gfx_blend(ctx, win, is_alpha_format(fb->pixel_format));
Rahul Sharmaaaf8b492012-10-04 20:48:53 +0530686
687 /* layer update mandatory for mixer 16.0.33.0 */
Rahul Sharmadef5e092013-06-19 18:21:08 +0530688 if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
689 ctx->mxr_ver == MXR_VER_128_0_0_184)
Rahul Sharmaaaf8b492012-10-04 20:48:53 +0530690 mixer_layer_update(ctx);
691
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900692 mixer_run(ctx);
693
694 mixer_vsync_set_update(ctx, true);
695 spin_unlock_irqrestore(&res->reg_slock, flags);
Tobias Jakobic0734fb2015-05-06 14:10:21 +0200696
697 mixer_regs_dump(ctx);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900698}
699
700static void vp_win_reset(struct mixer_context *ctx)
701{
702 struct mixer_resources *res = &ctx->mixer_res;
703 int tries = 100;
704
705 vp_reg_write(res, VP_SRESET, VP_SRESET_PROCESSING);
706 for (tries = 100; tries; --tries) {
707 /* waiting until VP_SRESET_PROCESSING is 0 */
708 if (~vp_reg_read(res, VP_SRESET) & VP_SRESET_PROCESSING)
709 break;
Tomasz Stanislawski02b3de42015-09-25 14:48:29 +0200710 mdelay(10);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900711 }
712 WARN(tries == 0, "failed to reset Video Processor\n");
713}
714
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900715static void mixer_win_reset(struct mixer_context *ctx)
716{
717 struct mixer_resources *res = &ctx->mixer_res;
718 unsigned long flags;
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900719
720 spin_lock_irqsave(&res->reg_slock, flags);
721 mixer_vsync_set_update(ctx, false);
722
723 mixer_reg_writemask(res, MXR_CFG, MXR_CFG_DST_HDMI, MXR_CFG_DST_MASK);
724
725 /* set output in RGB888 mode */
726 mixer_reg_writemask(res, MXR_CFG, MXR_CFG_OUT_RGB888, MXR_CFG_OUT_MASK);
727
728 /* 16 beat burst in DMA */
729 mixer_reg_writemask(res, MXR_STATUS, MXR_STATUS_16_BURST,
730 MXR_STATUS_BURST_MASK);
731
Marek Szyprowskia2cb9112015-12-16 13:21:44 +0100732 /* reset default layer priority */
733 mixer_reg_write(res, MXR_LAYER_CFG, 0);
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900734
735 /* setting background color */
736 mixer_reg_write(res, MXR_BG_COLOR0, 0x008080);
737 mixer_reg_write(res, MXR_BG_COLOR1, 0x008080);
738 mixer_reg_write(res, MXR_BG_COLOR2, 0x008080);
739
Rahul Sharma1b8e5742012-10-04 20:48:52 +0530740 if (ctx->vp_enabled) {
741 /* configuration of Video Processor Registers */
742 vp_win_reset(ctx);
743 vp_default_filter(res);
744 }
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900745
746 /* disable all layers */
747 mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP0_ENABLE);
748 mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_GRP1_ENABLE);
Rahul Sharma1b8e5742012-10-04 20:48:52 +0530749 if (ctx->vp_enabled)
750 mixer_reg_writemask(res, MXR_CFG, 0, MXR_CFG_VP_ENABLE);
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900751
752 mixer_vsync_set_update(ctx, true);
753 spin_unlock_irqrestore(&res->reg_slock, flags);
754}
755
Sean Paul45517892014-01-30 16:19:05 -0500756static irqreturn_t mixer_irq_handler(int irq, void *arg)
757{
758 struct mixer_context *ctx = arg;
759 struct mixer_resources *res = &ctx->mixer_res;
760 u32 val, base, shadow;
Gustavo Padovan822f6df2015-08-15 13:26:14 -0300761 int win;
Sean Paul45517892014-01-30 16:19:05 -0500762
763 spin_lock(&res->reg_slock);
764
765 /* read interrupt status for handling and clearing flags for VSYNC */
766 val = mixer_reg_read(res, MXR_INT_STATUS);
767
768 /* handling VSYNC */
769 if (val & MXR_INT_STATUS_VSYNC) {
Andrzej Hajda81a464d2015-07-09 10:07:53 +0200770 /* vsync interrupt use different bit for read and clear */
771 val |= MXR_INT_CLEAR_VSYNC;
772 val &= ~MXR_INT_STATUS_VSYNC;
773
Sean Paul45517892014-01-30 16:19:05 -0500774 /* interlace scan need to check shadow register */
775 if (ctx->interlace) {
776 base = mixer_reg_read(res, MXR_GRAPHIC_BASE(0));
777 shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(0));
778 if (base != shadow)
779 goto out;
780
781 base = mixer_reg_read(res, MXR_GRAPHIC_BASE(1));
782 shadow = mixer_reg_read(res, MXR_GRAPHIC_BASE_S(1));
783 if (base != shadow)
784 goto out;
785 }
786
Gustavo Padovaneafd5402015-07-16 12:23:32 -0300787 drm_crtc_handle_vblank(&ctx->crtc->base);
Gustavo Padovan822f6df2015-08-15 13:26:14 -0300788 for (win = 0 ; win < MIXER_WIN_NR ; win++) {
789 struct exynos_drm_plane *plane = &ctx->planes[win];
790
791 if (!plane->pending_fb)
792 continue;
793
794 exynos_drm_crtc_finish_update(ctx->crtc, plane);
795 }
Sean Paul45517892014-01-30 16:19:05 -0500796
797 /* set wait vsync event to zero and wake up queue. */
798 if (atomic_read(&ctx->wait_vsync_event)) {
799 atomic_set(&ctx->wait_vsync_event, 0);
800 wake_up(&ctx->wait_vsync_queue);
801 }
802 }
803
804out:
805 /* clear interrupts */
Sean Paul45517892014-01-30 16:19:05 -0500806 mixer_reg_write(res, MXR_INT_STATUS, val);
807
808 spin_unlock(&res->reg_slock);
809
810 return IRQ_HANDLED;
811}
812
813static int mixer_resources_init(struct mixer_context *mixer_ctx)
814{
815 struct device *dev = &mixer_ctx->pdev->dev;
816 struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
817 struct resource *res;
818 int ret;
819
820 spin_lock_init(&mixer_res->reg_slock);
821
822 mixer_res->mixer = devm_clk_get(dev, "mixer");
823 if (IS_ERR(mixer_res->mixer)) {
824 dev_err(dev, "failed to get clock 'mixer'\n");
825 return -ENODEV;
826 }
827
Marek Szyprowski04427ec2015-02-02 14:20:28 +0100828 mixer_res->hdmi = devm_clk_get(dev, "hdmi");
829 if (IS_ERR(mixer_res->hdmi)) {
830 dev_err(dev, "failed to get clock 'hdmi'\n");
831 return PTR_ERR(mixer_res->hdmi);
832 }
833
Sean Paul45517892014-01-30 16:19:05 -0500834 mixer_res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
835 if (IS_ERR(mixer_res->sclk_hdmi)) {
836 dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
837 return -ENODEV;
838 }
839 res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 0);
840 if (res == NULL) {
841 dev_err(dev, "get memory resource failed.\n");
842 return -ENXIO;
843 }
844
845 mixer_res->mixer_regs = devm_ioremap(dev, res->start,
846 resource_size(res));
847 if (mixer_res->mixer_regs == NULL) {
848 dev_err(dev, "register mapping failed.\n");
849 return -ENXIO;
850 }
851
852 res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_IRQ, 0);
853 if (res == NULL) {
854 dev_err(dev, "get interrupt resource failed.\n");
855 return -ENXIO;
856 }
857
858 ret = devm_request_irq(dev, res->start, mixer_irq_handler,
859 0, "drm_mixer", mixer_ctx);
860 if (ret) {
861 dev_err(dev, "request interrupt failed.\n");
862 return ret;
863 }
864 mixer_res->irq = res->start;
865
866 return 0;
867}
868
869static int vp_resources_init(struct mixer_context *mixer_ctx)
870{
871 struct device *dev = &mixer_ctx->pdev->dev;
872 struct mixer_resources *mixer_res = &mixer_ctx->mixer_res;
873 struct resource *res;
874
875 mixer_res->vp = devm_clk_get(dev, "vp");
876 if (IS_ERR(mixer_res->vp)) {
877 dev_err(dev, "failed to get clock 'vp'\n");
878 return -ENODEV;
879 }
Sean Paul45517892014-01-30 16:19:05 -0500880
Marek Szyprowskiff830c92014-07-01 10:10:07 +0200881 if (mixer_ctx->has_sclk) {
882 mixer_res->sclk_mixer = devm_clk_get(dev, "sclk_mixer");
883 if (IS_ERR(mixer_res->sclk_mixer)) {
884 dev_err(dev, "failed to get clock 'sclk_mixer'\n");
885 return -ENODEV;
886 }
887 mixer_res->mout_mixer = devm_clk_get(dev, "mout_mixer");
888 if (IS_ERR(mixer_res->mout_mixer)) {
889 dev_err(dev, "failed to get clock 'mout_mixer'\n");
890 return -ENODEV;
891 }
892
893 if (mixer_res->sclk_hdmi && mixer_res->mout_mixer)
894 clk_set_parent(mixer_res->mout_mixer,
895 mixer_res->sclk_hdmi);
896 }
Sean Paul45517892014-01-30 16:19:05 -0500897
898 res = platform_get_resource(mixer_ctx->pdev, IORESOURCE_MEM, 1);
899 if (res == NULL) {
900 dev_err(dev, "get memory resource failed.\n");
901 return -ENXIO;
902 }
903
904 mixer_res->vp_regs = devm_ioremap(dev, res->start,
905 resource_size(res));
906 if (mixer_res->vp_regs == NULL) {
907 dev_err(dev, "register mapping failed.\n");
908 return -ENXIO;
909 }
910
911 return 0;
912}
913
Gustavo Padovan93bca242015-01-18 18:16:23 +0900914static int mixer_initialize(struct mixer_context *mixer_ctx,
Inki Daef37cd5e2014-05-09 14:25:20 +0900915 struct drm_device *drm_dev)
Sean Paul45517892014-01-30 16:19:05 -0500916{
917 int ret;
Inki Daef37cd5e2014-05-09 14:25:20 +0900918 struct exynos_drm_private *priv;
919 priv = drm_dev->dev_private;
Sean Paul45517892014-01-30 16:19:05 -0500920
Gustavo Padovaneb88e422014-11-26 16:43:27 -0200921 mixer_ctx->drm_dev = drm_dev;
Gustavo Padovan8a326ed2014-11-04 18:44:47 -0200922 mixer_ctx->pipe = priv->pipe++;
Sean Paul45517892014-01-30 16:19:05 -0500923
924 /* acquire resources: regs, irqs, clocks */
925 ret = mixer_resources_init(mixer_ctx);
926 if (ret) {
927 DRM_ERROR("mixer_resources_init failed ret=%d\n", ret);
928 return ret;
929 }
930
931 if (mixer_ctx->vp_enabled) {
932 /* acquire vp resources: regs, irqs, clocks */
933 ret = vp_resources_init(mixer_ctx);
934 if (ret) {
935 DRM_ERROR("vp_resources_init failed ret=%d\n", ret);
936 return ret;
937 }
938 }
939
Joonyoung Shimeb7a3fc2015-07-02 21:49:39 +0900940 ret = drm_iommu_attach_device(drm_dev, mixer_ctx->dev);
Hyungwon Hwangfc2e0132015-06-22 19:05:04 +0900941 if (ret)
942 priv->pipe--;
Sean Paulf041b252014-01-30 16:19:15 -0500943
Hyungwon Hwangfc2e0132015-06-22 19:05:04 +0900944 return ret;
Sean Paul45517892014-01-30 16:19:05 -0500945}
946
Gustavo Padovan93bca242015-01-18 18:16:23 +0900947static void mixer_ctx_remove(struct mixer_context *mixer_ctx)
Inki Dae1055b392012-10-19 17:37:35 +0900948{
Joonyoung Shimbf566082015-07-02 21:49:38 +0900949 drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev);
Inki Dae1055b392012-10-19 17:37:35 +0900950}
951
Gustavo Padovan93bca242015-01-18 18:16:23 +0900952static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900953{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900954 struct mixer_context *mixer_ctx = crtc->ctx;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900955 struct mixer_resources *res = &mixer_ctx->mixer_res;
956
Andrzej Hajda0df5e4a2015-07-09 08:25:43 +0200957 __set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
958 if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
Sean Paulf041b252014-01-30 16:19:15 -0500959 return 0;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900960
961 /* enable vsync interrupt */
Andrzej Hajdafc0732482015-07-09 08:25:40 +0200962 mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
963 mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900964
965 return 0;
966}
967
Gustavo Padovan93bca242015-01-18 18:16:23 +0900968static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900969{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900970 struct mixer_context *mixer_ctx = crtc->ctx;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900971 struct mixer_resources *res = &mixer_ctx->mixer_res;
972
Andrzej Hajda0df5e4a2015-07-09 08:25:43 +0200973 __clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
974
975 if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
Andrzej Hajda947710c2015-07-09 08:25:41 +0200976 return;
Andrzej Hajda947710c2015-07-09 08:25:41 +0200977
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900978 /* disable vsync interrupt */
Andrzej Hajdafc0732482015-07-09 08:25:40 +0200979 mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900980 mixer_reg_writemask(res, MXR_INT_EN, 0, MXR_INT_EN_VSYNC);
981}
982
Gustavo Padovan1e1d1392015-08-03 14:39:36 +0900983static void mixer_update_plane(struct exynos_drm_crtc *crtc,
984 struct exynos_drm_plane *plane)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900985{
Gustavo Padovan93bca242015-01-18 18:16:23 +0900986 struct mixer_context *mixer_ctx = crtc->ctx;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900987
Marek Szyprowski40bdfb02015-12-16 13:21:42 +0100988 DRM_DEBUG_KMS("win: %d\n", plane->index);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900989
Andrzej Hajdaa44652e2015-07-09 08:25:42 +0200990 if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
Shirish Sdda90122013-01-23 22:03:18 -0500991 return;
Shirish Sdda90122013-01-23 22:03:18 -0500992
Marek Szyprowski40bdfb02015-12-16 13:21:42 +0100993 if (plane->index > 1 && mixer_ctx->vp_enabled)
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900994 vp_video_buffer(mixer_ctx, plane);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900995 else
Gustavo Padovan2eeb2e52015-08-03 14:40:44 +0900996 mixer_graph_buffer(mixer_ctx, plane);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900997}
998
Gustavo Padovan1e1d1392015-08-03 14:39:36 +0900999static void mixer_disable_plane(struct exynos_drm_crtc *crtc,
1000 struct exynos_drm_plane *plane)
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001001{
Gustavo Padovan93bca242015-01-18 18:16:23 +09001002 struct mixer_context *mixer_ctx = crtc->ctx;
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001003 struct mixer_resources *res = &mixer_ctx->mixer_res;
1004 unsigned long flags;
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001005
Marek Szyprowski40bdfb02015-12-16 13:21:42 +01001006 DRM_DEBUG_KMS("win: %d\n", plane->index);
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001007
Andrzej Hajdaa44652e2015-07-09 08:25:42 +02001008 if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
Prathyush Kdb43fd12012-12-06 20:16:05 +05301009 return;
Prathyush Kdb43fd12012-12-06 20:16:05 +05301010
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001011 spin_lock_irqsave(&res->reg_slock, flags);
1012 mixer_vsync_set_update(mixer_ctx, false);
1013
Marek Szyprowskia2cb9112015-12-16 13:21:44 +01001014 mixer_cfg_layer(mixer_ctx, plane->index, 0, false);
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001015
1016 mixer_vsync_set_update(mixer_ctx, true);
1017 spin_unlock_irqrestore(&res->reg_slock, flags);
1018}
1019
Gustavo Padovan93bca242015-01-18 18:16:23 +09001020static void mixer_wait_for_vblank(struct exynos_drm_crtc *crtc)
Rahul Sharma0ea68222013-01-15 08:11:06 -05001021{
Gustavo Padovan93bca242015-01-18 18:16:23 +09001022 struct mixer_context *mixer_ctx = crtc->ctx;
Joonyoung Shim7c4c5582015-01-18 17:48:29 +09001023 int err;
Prathyush K8137a2e2012-12-06 20:16:01 +05301024
Andrzej Hajdaa44652e2015-07-09 08:25:42 +02001025 if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
Prathyush K6e95d5e2012-12-06 20:16:03 +05301026 return;
Prathyush K6e95d5e2012-12-06 20:16:03 +05301027
Gustavo Padovan93bca242015-01-18 18:16:23 +09001028 err = drm_vblank_get(mixer_ctx->drm_dev, mixer_ctx->pipe);
Joonyoung Shim7c4c5582015-01-18 17:48:29 +09001029 if (err < 0) {
1030 DRM_DEBUG_KMS("failed to acquire vblank counter\n");
1031 return;
1032 }
Rahul Sharma5d39b9e2014-06-23 11:02:25 +05301033
Prathyush K6e95d5e2012-12-06 20:16:03 +05301034 atomic_set(&mixer_ctx->wait_vsync_event, 1);
1035
1036 /*
1037 * wait for MIXER to signal VSYNC interrupt or return after
1038 * timeout which is set to 50ms (refresh rate of 20).
1039 */
1040 if (!wait_event_timeout(mixer_ctx->wait_vsync_queue,
1041 !atomic_read(&mixer_ctx->wait_vsync_event),
Daniel Vetterbfd83032013-12-11 11:34:41 +01001042 HZ/20))
Prathyush K8137a2e2012-12-06 20:16:01 +05301043 DRM_DEBUG_KMS("vblank wait timed out.\n");
Rahul Sharma5d39b9e2014-06-23 11:02:25 +05301044
Gustavo Padovan93bca242015-01-18 18:16:23 +09001045 drm_vblank_put(mixer_ctx->drm_dev, mixer_ctx->pipe);
Prathyush K8137a2e2012-12-06 20:16:01 +05301046}
1047
Gustavo Padovan3cecda02015-06-01 12:04:55 -03001048static void mixer_enable(struct exynos_drm_crtc *crtc)
Prathyush Kdb43fd12012-12-06 20:16:05 +05301049{
Gustavo Padovan3cecda02015-06-01 12:04:55 -03001050 struct mixer_context *ctx = crtc->ctx;
Prathyush Kdb43fd12012-12-06 20:16:05 +05301051 struct mixer_resources *res = &ctx->mixer_res;
1052
Andrzej Hajdaa44652e2015-07-09 08:25:42 +02001053 if (test_bit(MXR_BIT_POWERED, &ctx->flags))
Prathyush Kdb43fd12012-12-06 20:16:05 +05301054 return;
Prathyush Kdb43fd12012-12-06 20:16:05 +05301055
Sean Paulaf65c802014-01-30 16:19:27 -05001056 pm_runtime_get_sync(ctx->dev);
1057
Rahul Sharmad74ed932014-06-23 11:02:24 +05301058 mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
1059
Andrzej Hajda0df5e4a2015-07-09 08:25:43 +02001060 if (test_bit(MXR_BIT_VSYNC, &ctx->flags)) {
Andrzej Hajdafc0732482015-07-09 08:25:40 +02001061 mixer_reg_writemask(res, MXR_INT_STATUS, ~0, MXR_INT_CLEAR_VSYNC);
Andrzej Hajda0df5e4a2015-07-09 08:25:43 +02001062 mixer_reg_writemask(res, MXR_INT_EN, ~0, MXR_INT_EN_VSYNC);
1063 }
Prathyush Kdb43fd12012-12-06 20:16:05 +05301064 mixer_win_reset(ctx);
Gustavo Padovanccf034a2015-09-04 17:15:46 -03001065
1066 set_bit(MXR_BIT_POWERED, &ctx->flags);
Prathyush Kdb43fd12012-12-06 20:16:05 +05301067}
1068
Gustavo Padovan3cecda02015-06-01 12:04:55 -03001069static void mixer_disable(struct exynos_drm_crtc *crtc)
Prathyush Kdb43fd12012-12-06 20:16:05 +05301070{
Gustavo Padovan3cecda02015-06-01 12:04:55 -03001071 struct mixer_context *ctx = crtc->ctx;
Joonyoung Shimc329f662015-06-12 20:34:28 +09001072 int i;
Prathyush Kdb43fd12012-12-06 20:16:05 +05301073
Andrzej Hajdaa44652e2015-07-09 08:25:42 +02001074 if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
Rahul Sharmab4bfa3c2014-06-23 11:02:21 +05301075 return;
Prathyush Kdb43fd12012-12-06 20:16:05 +05301076
Rahul Sharma381be022014-06-23 11:02:22 +05301077 mixer_stop(ctx);
Tobias Jakobic0734fb2015-05-06 14:10:21 +02001078 mixer_regs_dump(ctx);
Joonyoung Shimc329f662015-06-12 20:34:28 +09001079
1080 for (i = 0; i < MIXER_WIN_NR; i++)
Gustavo Padovan1e1d1392015-08-03 14:39:36 +09001081 mixer_disable_plane(crtc, &ctx->planes[i]);
Prathyush Kdb43fd12012-12-06 20:16:05 +05301082
Gustavo Padovanccf034a2015-09-04 17:15:46 -03001083 pm_runtime_put(ctx->dev);
1084
Andrzej Hajdaa44652e2015-07-09 08:25:42 +02001085 clear_bit(MXR_BIT_POWERED, &ctx->flags);
Prathyush Kdb43fd12012-12-06 20:16:05 +05301086}
1087
Sean Paulf041b252014-01-30 16:19:15 -05001088/* Only valid for Mixer version 16.0.33.0 */
Andrzej Hajda3ae24362015-10-26 13:03:40 +01001089static int mixer_atomic_check(struct exynos_drm_crtc *crtc,
1090 struct drm_crtc_state *state)
Sean Paulf041b252014-01-30 16:19:15 -05001091{
Andrzej Hajda3ae24362015-10-26 13:03:40 +01001092 struct drm_display_mode *mode = &state->adjusted_mode;
Sean Paulf041b252014-01-30 16:19:15 -05001093 u32 w, h;
1094
1095 w = mode->hdisplay;
1096 h = mode->vdisplay;
1097
1098 DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n",
1099 mode->hdisplay, mode->vdisplay, mode->vrefresh,
1100 (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
1101
1102 if ((w >= 464 && w <= 720 && h >= 261 && h <= 576) ||
1103 (w >= 1024 && w <= 1280 && h >= 576 && h <= 720) ||
1104 (w >= 1664 && w <= 1920 && h >= 936 && h <= 1080))
1105 return 0;
1106
1107 return -EINVAL;
1108}
1109
Krzysztof Kozlowskif3aaf762015-05-07 09:04:45 +09001110static const struct exynos_drm_crtc_ops mixer_crtc_ops = {
Gustavo Padovan3cecda02015-06-01 12:04:55 -03001111 .enable = mixer_enable,
1112 .disable = mixer_disable,
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001113 .enable_vblank = mixer_enable_vblank,
1114 .disable_vblank = mixer_disable_vblank,
Prathyush K8137a2e2012-12-06 20:16:01 +05301115 .wait_for_vblank = mixer_wait_for_vblank,
Gustavo Padovan9cc76102015-08-03 14:38:05 +09001116 .update_plane = mixer_update_plane,
1117 .disable_plane = mixer_disable_plane,
Andrzej Hajda3ae24362015-10-26 13:03:40 +01001118 .atomic_check = mixer_atomic_check,
Sean Paulf041b252014-01-30 16:19:15 -05001119};
Rahul Sharma0ea68222013-01-15 08:11:06 -05001120
Rahul Sharmadef5e092013-06-19 18:21:08 +05301121static struct mixer_drv_data exynos5420_mxr_drv_data = {
1122 .version = MXR_VER_128_0_0_184,
1123 .is_vp_enabled = 0,
1124};
1125
Rahul Sharmacc57caf2013-06-19 18:21:07 +05301126static struct mixer_drv_data exynos5250_mxr_drv_data = {
Rahul Sharmaaaf8b492012-10-04 20:48:53 +05301127 .version = MXR_VER_16_0_33_0,
1128 .is_vp_enabled = 0,
1129};
1130
Marek Szyprowskiff830c92014-07-01 10:10:07 +02001131static struct mixer_drv_data exynos4212_mxr_drv_data = {
1132 .version = MXR_VER_0_0_0_16,
1133 .is_vp_enabled = 1,
1134};
1135
Rahul Sharmacc57caf2013-06-19 18:21:07 +05301136static struct mixer_drv_data exynos4210_mxr_drv_data = {
Rahul Sharma1e123442012-10-04 20:48:51 +05301137 .version = MXR_VER_0_0_0_16,
Rahul Sharma1b8e5742012-10-04 20:48:52 +05301138 .is_vp_enabled = 1,
Marek Szyprowskiff830c92014-07-01 10:10:07 +02001139 .has_sclk = 1,
Rahul Sharma1e123442012-10-04 20:48:51 +05301140};
1141
Krzysztof Kozlowskid6b16302015-05-02 00:56:36 +09001142static const struct platform_device_id mixer_driver_types[] = {
Rahul Sharma1e123442012-10-04 20:48:51 +05301143 {
1144 .name = "s5p-mixer",
Rahul Sharmacc57caf2013-06-19 18:21:07 +05301145 .driver_data = (unsigned long)&exynos4210_mxr_drv_data,
Rahul Sharma1e123442012-10-04 20:48:51 +05301146 }, {
Rahul Sharmaaaf8b492012-10-04 20:48:53 +05301147 .name = "exynos5-mixer",
Rahul Sharmacc57caf2013-06-19 18:21:07 +05301148 .driver_data = (unsigned long)&exynos5250_mxr_drv_data,
Rahul Sharmaaaf8b492012-10-04 20:48:53 +05301149 }, {
1150 /* end node */
1151 }
1152};
1153
1154static struct of_device_id mixer_match_types[] = {
1155 {
Marek Szyprowskiff830c92014-07-01 10:10:07 +02001156 .compatible = "samsung,exynos4210-mixer",
1157 .data = &exynos4210_mxr_drv_data,
1158 }, {
1159 .compatible = "samsung,exynos4212-mixer",
1160 .data = &exynos4212_mxr_drv_data,
1161 }, {
Rahul Sharmaaaf8b492012-10-04 20:48:53 +05301162 .compatible = "samsung,exynos5-mixer",
Rahul Sharmacc57caf2013-06-19 18:21:07 +05301163 .data = &exynos5250_mxr_drv_data,
1164 }, {
1165 .compatible = "samsung,exynos5250-mixer",
1166 .data = &exynos5250_mxr_drv_data,
Rahul Sharmaaaf8b492012-10-04 20:48:53 +05301167 }, {
Rahul Sharmadef5e092013-06-19 18:21:08 +05301168 .compatible = "samsung,exynos5420-mixer",
1169 .data = &exynos5420_mxr_drv_data,
1170 }, {
Rahul Sharma1e123442012-10-04 20:48:51 +05301171 /* end node */
1172 }
1173};
Sjoerd Simons39b58a32014-07-18 22:36:41 +02001174MODULE_DEVICE_TABLE(of, mixer_match_types);
Rahul Sharma1e123442012-10-04 20:48:51 +05301175
Inki Daef37cd5e2014-05-09 14:25:20 +09001176static int mixer_bind(struct device *dev, struct device *manager, void *data)
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001177{
Andrzej Hajda8103ef12014-11-24 14:12:46 +09001178 struct mixer_context *ctx = dev_get_drvdata(dev);
Inki Daef37cd5e2014-05-09 14:25:20 +09001179 struct drm_device *drm_dev = data;
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +09001180 struct exynos_drm_plane *exynos_plane;
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +01001181 unsigned int i;
Gustavo Padovan6e2a3b62015-04-03 21:05:52 +09001182 int ret;
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001183
Alban Browaeyse2dc3f72015-01-29 22:18:40 +01001184 ret = mixer_initialize(ctx, drm_dev);
1185 if (ret)
1186 return ret;
1187
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +01001188 for (i = 0; i < MIXER_WIN_NR; i++) {
1189 if (i == VP_DEFAULT_WIN && !ctx->vp_enabled)
Marek Szyprowskiab144202015-11-30 14:53:24 +01001190 continue;
1191
Marek Szyprowski40bdfb02015-12-16 13:21:42 +01001192 ret = exynos_plane_init(drm_dev, &ctx->planes[i], i,
Marek Szyprowskifd2d2fc2015-11-30 14:53:25 +01001193 1 << ctx->pipe, &plane_configs[i]);
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +09001194 if (ret)
1195 return ret;
1196 }
1197
Gustavo Padovan5d3d0992015-10-12 22:07:48 +09001198 exynos_plane = &ctx->planes[DEFAULT_WIN];
Gustavo Padovan7ee14cd2015-04-03 21:03:40 +09001199 ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
1200 ctx->pipe, EXYNOS_DISPLAY_TYPE_HDMI,
1201 &mixer_crtc_ops, ctx);
Gustavo Padovan93bca242015-01-18 18:16:23 +09001202 if (IS_ERR(ctx->crtc)) {
Alban Browaeyse2dc3f72015-01-29 22:18:40 +01001203 mixer_ctx_remove(ctx);
Gustavo Padovan93bca242015-01-18 18:16:23 +09001204 ret = PTR_ERR(ctx->crtc);
1205 goto free_ctx;
Andrzej Hajda8103ef12014-11-24 14:12:46 +09001206 }
1207
Andrzej Hajda8103ef12014-11-24 14:12:46 +09001208 return 0;
Gustavo Padovan93bca242015-01-18 18:16:23 +09001209
1210free_ctx:
1211 devm_kfree(dev, ctx);
1212 return ret;
Andrzej Hajda8103ef12014-11-24 14:12:46 +09001213}
1214
1215static void mixer_unbind(struct device *dev, struct device *master, void *data)
1216{
1217 struct mixer_context *ctx = dev_get_drvdata(dev);
1218
Gustavo Padovan93bca242015-01-18 18:16:23 +09001219 mixer_ctx_remove(ctx);
Andrzej Hajda8103ef12014-11-24 14:12:46 +09001220}
1221
1222static const struct component_ops mixer_component_ops = {
1223 .bind = mixer_bind,
1224 .unbind = mixer_unbind,
1225};
1226
1227static int mixer_probe(struct platform_device *pdev)
1228{
1229 struct device *dev = &pdev->dev;
1230 struct mixer_drv_data *drv;
1231 struct mixer_context *ctx;
1232 int ret;
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001233
Sean Paulf041b252014-01-30 16:19:15 -05001234 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1235 if (!ctx) {
1236 DRM_ERROR("failed to alloc mixer context.\n");
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001237 return -ENOMEM;
Sean Paulf041b252014-01-30 16:19:15 -05001238 }
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001239
Rahul Sharmaaaf8b492012-10-04 20:48:53 +05301240 if (dev->of_node) {
1241 const struct of_device_id *match;
Andrzej Hajda8103ef12014-11-24 14:12:46 +09001242
Sachin Kamate436b092013-06-05 16:00:23 +09001243 match = of_match_node(mixer_match_types, dev->of_node);
Rahul Sharma2cdc53b2012-10-31 09:36:26 +05301244 drv = (struct mixer_drv_data *)match->data;
Rahul Sharmaaaf8b492012-10-04 20:48:53 +05301245 } else {
1246 drv = (struct mixer_drv_data *)
1247 platform_get_device_id(pdev)->driver_data;
1248 }
1249
Sean Paul45517892014-01-30 16:19:05 -05001250 ctx->pdev = pdev;
Seung-Woo Kimd873ab92013-05-22 21:14:14 +09001251 ctx->dev = dev;
Rahul Sharma1b8e5742012-10-04 20:48:52 +05301252 ctx->vp_enabled = drv->is_vp_enabled;
Marek Szyprowskiff830c92014-07-01 10:10:07 +02001253 ctx->has_sclk = drv->has_sclk;
Rahul Sharma1e123442012-10-04 20:48:51 +05301254 ctx->mxr_ver = drv->version;
Daniel Vetter57ed0f72013-12-11 11:34:43 +01001255 init_waitqueue_head(&ctx->wait_vsync_queue);
Prathyush K6e95d5e2012-12-06 20:16:03 +05301256 atomic_set(&ctx->wait_vsync_event, 0);
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001257
Andrzej Hajda8103ef12014-11-24 14:12:46 +09001258 platform_set_drvdata(pdev, ctx);
Inki Daedf5225b2014-05-29 18:28:02 +09001259
Inki Daedf5225b2014-05-29 18:28:02 +09001260 ret = component_add(&pdev->dev, &mixer_component_ops);
Andrzej Hajda86650402015-06-11 23:23:37 +09001261 if (!ret)
1262 pm_runtime_enable(dev);
Inki Daedf5225b2014-05-29 18:28:02 +09001263
1264 return ret;
Inki Daef37cd5e2014-05-09 14:25:20 +09001265}
1266
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001267static int mixer_remove(struct platform_device *pdev)
1268{
Andrzej Hajda8103ef12014-11-24 14:12:46 +09001269 pm_runtime_disable(&pdev->dev);
1270
Inki Daedf5225b2014-05-29 18:28:02 +09001271 component_del(&pdev->dev, &mixer_component_ops);
Inki Daedf5225b2014-05-29 18:28:02 +09001272
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001273 return 0;
1274}
1275
Gustavo Padovanccf034a2015-09-04 17:15:46 -03001276#ifdef CONFIG_PM_SLEEP
1277static int exynos_mixer_suspend(struct device *dev)
1278{
1279 struct mixer_context *ctx = dev_get_drvdata(dev);
1280 struct mixer_resources *res = &ctx->mixer_res;
1281
1282 clk_disable_unprepare(res->hdmi);
1283 clk_disable_unprepare(res->mixer);
1284 if (ctx->vp_enabled) {
1285 clk_disable_unprepare(res->vp);
1286 if (ctx->has_sclk)
1287 clk_disable_unprepare(res->sclk_mixer);
1288 }
1289
1290 return 0;
1291}
1292
1293static int exynos_mixer_resume(struct device *dev)
1294{
1295 struct mixer_context *ctx = dev_get_drvdata(dev);
1296 struct mixer_resources *res = &ctx->mixer_res;
1297 int ret;
1298
1299 ret = clk_prepare_enable(res->mixer);
1300 if (ret < 0) {
1301 DRM_ERROR("Failed to prepare_enable the mixer clk [%d]\n", ret);
1302 return ret;
1303 }
1304 ret = clk_prepare_enable(res->hdmi);
1305 if (ret < 0) {
1306 DRM_ERROR("Failed to prepare_enable the hdmi clk [%d]\n", ret);
1307 return ret;
1308 }
1309 if (ctx->vp_enabled) {
1310 ret = clk_prepare_enable(res->vp);
1311 if (ret < 0) {
1312 DRM_ERROR("Failed to prepare_enable the vp clk [%d]\n",
1313 ret);
1314 return ret;
1315 }
1316 if (ctx->has_sclk) {
1317 ret = clk_prepare_enable(res->sclk_mixer);
1318 if (ret < 0) {
1319 DRM_ERROR("Failed to prepare_enable the " \
1320 "sclk_mixer clk [%d]\n",
1321 ret);
1322 return ret;
1323 }
1324 }
1325 }
1326
1327 return 0;
1328}
1329#endif
1330
1331static const struct dev_pm_ops exynos_mixer_pm_ops = {
1332 SET_RUNTIME_PM_OPS(exynos_mixer_suspend, exynos_mixer_resume, NULL)
1333};
1334
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001335struct platform_driver mixer_driver = {
1336 .driver = {
Rahul Sharmaaaf8b492012-10-04 20:48:53 +05301337 .name = "exynos-mixer",
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001338 .owner = THIS_MODULE,
Gustavo Padovanccf034a2015-09-04 17:15:46 -03001339 .pm = &exynos_mixer_pm_ops,
Rahul Sharmaaaf8b492012-10-04 20:48:53 +05301340 .of_match_table = mixer_match_types,
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001341 },
1342 .probe = mixer_probe,
Greg Kroah-Hartman56550d92012-12-21 15:09:25 -08001343 .remove = mixer_remove,
Rahul Sharma1e123442012-10-04 20:48:51 +05301344 .id_table = mixer_driver_types,
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001345};