drm/exynos: add drm_iommu_attach_device_if_possible()
[deliverable/linux.git] / drivers / gpu / drm / exynos / exynos_drm_fimd.c
CommitLineData
1c248b7d
ID
1/* exynos_drm_fimd.c
2 *
3 * Copyright (C) 2011 Samsung Electronics Co.Ltd
4 * Authors:
5 * Joonyoung Shim <jy0922.shim@samsung.com>
6 * Inki Dae <inki.dae@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 */
760285e7 14#include <drm/drmP.h>
1c248b7d
ID
15
16#include <linux/kernel.h>
1c248b7d
ID
17#include <linux/platform_device.h>
18#include <linux/clk.h>
3f1c781d 19#include <linux/of.h>
d636ead8 20#include <linux/of_device.h>
cb91f6a0 21#include <linux/pm_runtime.h>
f37cd5e8 22#include <linux/component.h>
3854fab2
YC
23#include <linux/mfd/syscon.h>
24#include <linux/regmap.h>
1c248b7d 25
7f4596f4 26#include <video/of_display_timing.h>
111e6055 27#include <video/of_videomode.h>
5a213a55 28#include <video/samsung_fimd.h>
1c248b7d 29#include <drm/exynos_drm.h>
1c248b7d
ID
30
31#include "exynos_drm_drv.h"
32#include "exynos_drm_fbdev.h"
33#include "exynos_drm_crtc.h"
7ee14cdc 34#include "exynos_drm_plane.h"
bcc5cd1c 35#include "exynos_drm_iommu.h"
1c248b7d
ID
36
37/*
b8654b37 38 * FIMD stands for Fully Interactive Mobile Display and
1c248b7d
ID
39 * as a display controller, it transfers contents drawn on memory
40 * to a LCD Panel through Display Interfaces such as RGB or
41 * CPU Interface.
42 */
43
111e6055 44#define FIMD_DEFAULT_FRAMERATE 60
66367461 45#define MIN_FB_WIDTH_FOR_16WORD_BURST 128
111e6055 46
1c248b7d
ID
47/* position control register for hardware window 0, 2 ~ 4.*/
48#define VIDOSD_A(win) (VIDOSD_BASE + 0x00 + (win) * 16)
49#define VIDOSD_B(win) (VIDOSD_BASE + 0x04 + (win) * 16)
0f10cf14
LKA
50/*
51 * size control register for hardware windows 0 and alpha control register
52 * for hardware windows 1 ~ 4
53 */
54#define VIDOSD_C(win) (VIDOSD_BASE + 0x08 + (win) * 16)
55/* size control register for hardware windows 1 ~ 2. */
1c248b7d
ID
56#define VIDOSD_D(win) (VIDOSD_BASE + 0x0C + (win) * 16)
57
453b44a3
GP
58#define VIDWnALPHA0(win) (VIDW_ALPHA + 0x00 + (win) * 8)
59#define VIDWnALPHA1(win) (VIDW_ALPHA + 0x04 + (win) * 8)
60
1c248b7d
ID
61#define VIDWx_BUF_START(win, buf) (VIDW_BUF_START(buf) + (win) * 8)
62#define VIDWx_BUF_END(win, buf) (VIDW_BUF_END(buf) + (win) * 8)
63#define VIDWx_BUF_SIZE(win, buf) (VIDW_BUF_SIZE(buf) + (win) * 4)
64
65/* color key control register for hardware window 1 ~ 4. */
0f10cf14 66#define WKEYCON0_BASE(x) ((WKEYCON0 + 0x140) + ((x - 1) * 8))
1c248b7d 67/* color key value register for hardware window 1 ~ 4. */
0f10cf14 68#define WKEYCON1_BASE(x) ((WKEYCON1 + 0x140) + ((x - 1) * 8))
1c248b7d 69
3854fab2
YC
70/* I80 / RGB trigger control register */
71#define TRIGCON 0x1A4
72#define TRGMODE_I80_RGB_ENABLE_I80 (1 << 0)
73#define SWTRGCMD_I80_RGB_ENABLE (1 << 1)
74
75/* display mode change control register except exynos4 */
76#define VIDOUT_CON 0x000
77#define VIDOUT_CON_F_I80_LDI0 (0x2 << 8)
78
79/* I80 interface control for main LDI register */
80#define I80IFCONFAx(x) (0x1B0 + (x) * 4)
81#define I80IFCONFBx(x) (0x1B8 + (x) * 4)
82#define LCD_CS_SETUP(x) ((x) << 16)
83#define LCD_WR_SETUP(x) ((x) << 12)
84#define LCD_WR_ACTIVE(x) ((x) << 8)
85#define LCD_WR_HOLD(x) ((x) << 4)
86#define I80IFEN_ENABLE (1 << 0)
87
1c248b7d
ID
88/* FIMD has totally five hardware windows. */
89#define WINDOWS_NR 5
90
e2e13389
LKA
91struct fimd_driver_data {
92 unsigned int timing_base;
3854fab2
YC
93 unsigned int lcdblk_offset;
94 unsigned int lcdblk_vt_shift;
95 unsigned int lcdblk_bypass_shift;
de7af100
TF
96
97 unsigned int has_shadowcon:1;
411d9ed4 98 unsigned int has_clksel:1;
5cc4621a 99 unsigned int has_limited_fmt:1;
3854fab2 100 unsigned int has_vidoutcon:1;
3c3c9c1d 101 unsigned int has_vtsel:1;
e2e13389
LKA
102};
103
725ddead
TF
104static struct fimd_driver_data s3c64xx_fimd_driver_data = {
105 .timing_base = 0x0,
106 .has_clksel = 1,
5cc4621a 107 .has_limited_fmt = 1,
725ddead
TF
108};
109
d6ce7b58
ID
110static struct fimd_driver_data exynos3_fimd_driver_data = {
111 .timing_base = 0x20000,
112 .lcdblk_offset = 0x210,
113 .lcdblk_bypass_shift = 1,
114 .has_shadowcon = 1,
115 .has_vidoutcon = 1,
116};
117
6ecf18f9 118static struct fimd_driver_data exynos4_fimd_driver_data = {
e2e13389 119 .timing_base = 0x0,
3854fab2
YC
120 .lcdblk_offset = 0x210,
121 .lcdblk_vt_shift = 10,
122 .lcdblk_bypass_shift = 1,
de7af100 123 .has_shadowcon = 1,
3c3c9c1d 124 .has_vtsel = 1,
e2e13389
LKA
125};
126
dcb622aa
YC
127static struct fimd_driver_data exynos4415_fimd_driver_data = {
128 .timing_base = 0x20000,
129 .lcdblk_offset = 0x210,
130 .lcdblk_vt_shift = 10,
131 .lcdblk_bypass_shift = 1,
132 .has_shadowcon = 1,
133 .has_vidoutcon = 1,
3c3c9c1d 134 .has_vtsel = 1,
dcb622aa
YC
135};
136
6ecf18f9 137static struct fimd_driver_data exynos5_fimd_driver_data = {
e2e13389 138 .timing_base = 0x20000,
3854fab2
YC
139 .lcdblk_offset = 0x214,
140 .lcdblk_vt_shift = 24,
141 .lcdblk_bypass_shift = 15,
de7af100 142 .has_shadowcon = 1,
3854fab2 143 .has_vidoutcon = 1,
3c3c9c1d 144 .has_vtsel = 1,
e2e13389
LKA
145};
146
1c248b7d 147struct fimd_context {
bb7704d6 148 struct device *dev;
40c8ab4b 149 struct drm_device *drm_dev;
93bca243 150 struct exynos_drm_crtc *crtc;
7ee14cdc 151 struct exynos_drm_plane planes[WINDOWS_NR];
1c248b7d
ID
152 struct clk *bus_clk;
153 struct clk *lcd_clk;
1c248b7d 154 void __iomem *regs;
3854fab2 155 struct regmap *sysreg;
1c248b7d
ID
156 unsigned int default_win;
157 unsigned long irq_flags;
3854fab2 158 u32 vidcon0;
1c248b7d 159 u32 vidcon1;
3854fab2
YC
160 u32 vidout_con;
161 u32 i80ifcon;
162 bool i80_if;
cb91f6a0 163 bool suspended;
080be03d 164 int pipe;
01ce113c
P
165 wait_queue_head_t wait_vsync_queue;
166 atomic_t wait_vsync_event;
3854fab2
YC
167 atomic_t win_updated;
168 atomic_t triggering;
1c248b7d 169
562ad9f4 170 struct exynos_drm_panel_info panel;
18873465 171 struct fimd_driver_data *driver_data;
000cc920 172 struct exynos_drm_display *display;
1c248b7d
ID
173};
174
d636ead8 175static const struct of_device_id fimd_driver_dt_match[] = {
725ddead
TF
176 { .compatible = "samsung,s3c6400-fimd",
177 .data = &s3c64xx_fimd_driver_data },
d6ce7b58
ID
178 { .compatible = "samsung,exynos3250-fimd",
179 .data = &exynos3_fimd_driver_data },
5830daf8 180 { .compatible = "samsung,exynos4210-fimd",
d636ead8 181 .data = &exynos4_fimd_driver_data },
dcb622aa
YC
182 { .compatible = "samsung,exynos4415-fimd",
183 .data = &exynos4415_fimd_driver_data },
5830daf8 184 { .compatible = "samsung,exynos5250-fimd",
d636ead8
JS
185 .data = &exynos5_fimd_driver_data },
186 {},
187};
0262ceeb 188MODULE_DEVICE_TABLE(of, fimd_driver_dt_match);
d636ead8 189
e2e13389
LKA
190static inline struct fimd_driver_data *drm_fimd_get_driver_data(
191 struct platform_device *pdev)
192{
d636ead8
JS
193 const struct of_device_id *of_id =
194 of_match_device(fimd_driver_dt_match, &pdev->dev);
195
2d3f173c 196 return (struct fimd_driver_data *)of_id->data;
e2e13389
LKA
197}
198
fb88e214
MS
199static int fimd_enable_vblank(struct exynos_drm_crtc *crtc)
200{
201 struct fimd_context *ctx = crtc->ctx;
202 u32 val;
203
204 if (ctx->suspended)
205 return -EPERM;
206
207 if (!test_and_set_bit(0, &ctx->irq_flags)) {
208 val = readl(ctx->regs + VIDINTCON0);
209
210 val |= VIDINTCON0_INT_ENABLE;
211
212 if (ctx->i80_if) {
213 val |= VIDINTCON0_INT_I80IFDONE;
214 val |= VIDINTCON0_INT_SYSMAINCON;
215 val &= ~VIDINTCON0_INT_SYSSUBCON;
216 } else {
217 val |= VIDINTCON0_INT_FRAME;
218
219 val &= ~VIDINTCON0_FRAMESEL0_MASK;
220 val |= VIDINTCON0_FRAMESEL0_VSYNC;
221 val &= ~VIDINTCON0_FRAMESEL1_MASK;
222 val |= VIDINTCON0_FRAMESEL1_NONE;
223 }
224
225 writel(val, ctx->regs + VIDINTCON0);
226 }
227
228 return 0;
229}
230
231static void fimd_disable_vblank(struct exynos_drm_crtc *crtc)
232{
233 struct fimd_context *ctx = crtc->ctx;
234 u32 val;
235
236 if (ctx->suspended)
237 return;
238
239 if (test_and_clear_bit(0, &ctx->irq_flags)) {
240 val = readl(ctx->regs + VIDINTCON0);
241
242 val &= ~VIDINTCON0_INT_ENABLE;
243
244 if (ctx->i80_if) {
245 val &= ~VIDINTCON0_INT_I80IFDONE;
246 val &= ~VIDINTCON0_INT_SYSMAINCON;
247 val &= ~VIDINTCON0_INT_SYSSUBCON;
248 } else
249 val &= ~VIDINTCON0_INT_FRAME;
250
251 writel(val, ctx->regs + VIDINTCON0);
252 }
253}
254
93bca243 255static void fimd_wait_for_vblank(struct exynos_drm_crtc *crtc)
f13bdbd1 256{
93bca243 257 struct fimd_context *ctx = crtc->ctx;
f13bdbd1
AA
258
259 if (ctx->suspended)
260 return;
261
262 atomic_set(&ctx->wait_vsync_event, 1);
263
264 /*
265 * wait for FIMD to signal VSYNC interrupt or return after
266 * timeout which is set to 50ms (refresh rate of 20).
267 */
268 if (!wait_event_timeout(ctx->wait_vsync_queue,
269 !atomic_read(&ctx->wait_vsync_event),
270 HZ/20))
271 DRM_DEBUG_KMS("vblank wait timed out.\n");
272}
273
5b1d5bc6 274static void fimd_enable_video_output(struct fimd_context *ctx, unsigned int win,
f181a543
YC
275 bool enable)
276{
277 u32 val = readl(ctx->regs + WINCON(win));
278
279 if (enable)
280 val |= WINCONx_ENWIN;
281 else
282 val &= ~WINCONx_ENWIN;
283
284 writel(val, ctx->regs + WINCON(win));
285}
286
5b1d5bc6
TJ
287static void fimd_enable_shadow_channel_path(struct fimd_context *ctx,
288 unsigned int win,
999d8b31
YC
289 bool enable)
290{
291 u32 val = readl(ctx->regs + SHADOWCON);
292
293 if (enable)
294 val |= SHADOWCON_CHx_ENABLE(win);
295 else
296 val &= ~SHADOWCON_CHx_ENABLE(win);
297
298 writel(val, ctx->regs + SHADOWCON);
299}
300
fc2e013f 301static void fimd_clear_channels(struct exynos_drm_crtc *crtc)
f13bdbd1 302{
fc2e013f 303 struct fimd_context *ctx = crtc->ctx;
5b1d5bc6 304 unsigned int win, ch_enabled = 0;
f13bdbd1
AA
305
306 DRM_DEBUG_KMS("%s\n", __FILE__);
307
fb88e214
MS
308 /* Hardware is in unknown state, so ensure it gets enabled properly */
309 pm_runtime_get_sync(ctx->dev);
310
311 clk_prepare_enable(ctx->bus_clk);
312 clk_prepare_enable(ctx->lcd_clk);
313
f13bdbd1
AA
314 /* Check if any channel is enabled. */
315 for (win = 0; win < WINDOWS_NR; win++) {
eb8a3bf7
MS
316 u32 val = readl(ctx->regs + WINCON(win));
317
318 if (val & WINCONx_ENWIN) {
f181a543 319 fimd_enable_video_output(ctx, win, false);
eb8a3bf7 320
999d8b31
YC
321 if (ctx->driver_data->has_shadowcon)
322 fimd_enable_shadow_channel_path(ctx, win,
323 false);
324
f13bdbd1
AA
325 ch_enabled = 1;
326 }
327 }
328
329 /* Wait for vsync, as disable channel takes effect at next vsync */
eb8a3bf7 330 if (ch_enabled) {
fb88e214
MS
331 int pipe = ctx->pipe;
332
333 /* ensure that vblank interrupt won't be reported to core */
334 ctx->suspended = false;
335 ctx->pipe = -1;
eb8a3bf7 336
fb88e214 337 fimd_enable_vblank(ctx->crtc);
92dc7a04 338 fimd_wait_for_vblank(ctx->crtc);
fb88e214
MS
339 fimd_disable_vblank(ctx->crtc);
340
341 ctx->suspended = true;
342 ctx->pipe = pipe;
eb8a3bf7 343 }
fb88e214
MS
344
345 clk_disable_unprepare(ctx->lcd_clk);
346 clk_disable_unprepare(ctx->bus_clk);
347
348 pm_runtime_put(ctx->dev);
f13bdbd1
AA
349}
350
cdbfca89 351static void fimd_iommu_detach_devices(struct fimd_context *ctx)
ec05da95 352{
080be03d
SP
353 /* detach this sub driver from iommu mapping if supported. */
354 if (is_drm_iommu_supported(ctx->drm_dev))
355 drm_iommu_detach_device(ctx->drm_dev, ctx->dev);
ec05da95
ID
356}
357
a968e727
SP
358static u32 fimd_calc_clkdiv(struct fimd_context *ctx,
359 const struct drm_display_mode *mode)
360{
361 unsigned long ideal_clk = mode->htotal * mode->vtotal * mode->vrefresh;
362 u32 clkdiv;
363
3854fab2
YC
364 if (ctx->i80_if) {
365 /*
366 * The frame done interrupt should be occurred prior to the
367 * next TE signal.
368 */
369 ideal_clk *= 2;
370 }
371
a968e727
SP
372 /* Find the clock divider value that gets us closest to ideal_clk */
373 clkdiv = DIV_ROUND_UP(clk_get_rate(ctx->lcd_clk), ideal_clk);
374
375 return (clkdiv < 0x100) ? clkdiv : 0xff;
376}
377
93bca243 378static bool fimd_mode_fixup(struct exynos_drm_crtc *crtc,
a968e727
SP
379 const struct drm_display_mode *mode,
380 struct drm_display_mode *adjusted_mode)
381{
382 if (adjusted_mode->vrefresh == 0)
383 adjusted_mode->vrefresh = FIMD_DEFAULT_FRAMERATE;
384
385 return true;
386}
387
93bca243 388static void fimd_commit(struct exynos_drm_crtc *crtc)
1c248b7d 389{
93bca243 390 struct fimd_context *ctx = crtc->ctx;
020e79de 391 struct drm_display_mode *mode = &crtc->base.state->adjusted_mode;
3854fab2
YC
392 struct fimd_driver_data *driver_data = ctx->driver_data;
393 void *timing_base = ctx->regs + driver_data->timing_base;
394 u32 val, clkdiv;
1c248b7d 395
e30d4bcf
ID
396 if (ctx->suspended)
397 return;
398
a968e727
SP
399 /* nothing to do if we haven't set the mode yet */
400 if (mode->htotal == 0 || mode->vtotal == 0)
401 return;
402
3854fab2
YC
403 if (ctx->i80_if) {
404 val = ctx->i80ifcon | I80IFEN_ENABLE;
405 writel(val, timing_base + I80IFCONFAx(0));
406
407 /* disable auto frame rate */
408 writel(0, timing_base + I80IFCONFBx(0));
409
410 /* set video type selection to I80 interface */
3c3c9c1d
JS
411 if (driver_data->has_vtsel && ctx->sysreg &&
412 regmap_update_bits(ctx->sysreg,
3854fab2
YC
413 driver_data->lcdblk_offset,
414 0x3 << driver_data->lcdblk_vt_shift,
415 0x1 << driver_data->lcdblk_vt_shift)) {
416 DRM_ERROR("Failed to update sysreg for I80 i/f.\n");
417 return;
418 }
419 } else {
420 int vsync_len, vbpd, vfpd, hsync_len, hbpd, hfpd;
421 u32 vidcon1;
422
423 /* setup polarity values */
424 vidcon1 = ctx->vidcon1;
425 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
426 vidcon1 |= VIDCON1_INV_VSYNC;
427 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
428 vidcon1 |= VIDCON1_INV_HSYNC;
429 writel(vidcon1, ctx->regs + driver_data->timing_base + VIDCON1);
430
431 /* setup vertical timing values. */
432 vsync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
433 vbpd = mode->crtc_vtotal - mode->crtc_vsync_end;
434 vfpd = mode->crtc_vsync_start - mode->crtc_vdisplay;
435
436 val = VIDTCON0_VBPD(vbpd - 1) |
437 VIDTCON0_VFPD(vfpd - 1) |
438 VIDTCON0_VSPW(vsync_len - 1);
439 writel(val, ctx->regs + driver_data->timing_base + VIDTCON0);
440
441 /* setup horizontal timing values. */
442 hsync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
443 hbpd = mode->crtc_htotal - mode->crtc_hsync_end;
444 hfpd = mode->crtc_hsync_start - mode->crtc_hdisplay;
445
446 val = VIDTCON1_HBPD(hbpd - 1) |
447 VIDTCON1_HFPD(hfpd - 1) |
448 VIDTCON1_HSPW(hsync_len - 1);
449 writel(val, ctx->regs + driver_data->timing_base + VIDTCON1);
450 }
451
452 if (driver_data->has_vidoutcon)
453 writel(ctx->vidout_con, timing_base + VIDOUT_CON);
454
455 /* set bypass selection */
456 if (ctx->sysreg && regmap_update_bits(ctx->sysreg,
457 driver_data->lcdblk_offset,
458 0x1 << driver_data->lcdblk_bypass_shift,
459 0x1 << driver_data->lcdblk_bypass_shift)) {
460 DRM_ERROR("Failed to update sysreg for bypass setting.\n");
461 return;
462 }
1c248b7d
ID
463
464 /* setup horizontal and vertical display size. */
a968e727
SP
465 val = VIDTCON2_LINEVAL(mode->vdisplay - 1) |
466 VIDTCON2_HOZVAL(mode->hdisplay - 1) |
467 VIDTCON2_LINEVAL_E(mode->vdisplay - 1) |
468 VIDTCON2_HOZVAL_E(mode->hdisplay - 1);
e2e13389 469 writel(val, ctx->regs + driver_data->timing_base + VIDTCON2);
1c248b7d 470
1d531062
AH
471 /*
472 * fields of register with prefix '_F' would be updated
473 * at vsync(same as dma start)
474 */
3854fab2
YC
475 val = ctx->vidcon0;
476 val |= VIDCON0_ENVID | VIDCON0_ENVID_F;
1c248b7d 477
1d531062 478 if (ctx->driver_data->has_clksel)
411d9ed4 479 val |= VIDCON0_CLKSEL_LCD;
411d9ed4 480
a968e727
SP
481 clkdiv = fimd_calc_clkdiv(ctx, mode);
482 if (clkdiv > 1)
483 val |= VIDCON0_CLKVAL_F(clkdiv - 1) | VIDCON0_CLKDIR;
1c248b7d 484
1c248b7d
ID
485 writel(val, ctx->regs + VIDCON0);
486}
487
1c248b7d 488
bb7704d6 489static void fimd_win_set_pixfmt(struct fimd_context *ctx, unsigned int win)
1c248b7d 490{
7ee14cdc 491 struct exynos_drm_plane *plane = &ctx->planes[win];
1c248b7d
ID
492 unsigned long val;
493
1c248b7d
ID
494 val = WINCONx_ENWIN;
495
5cc4621a
ID
496 /*
497 * In case of s3c64xx, window 0 doesn't support alpha channel.
498 * So the request format is ARGB8888 then change it to XRGB8888.
499 */
500 if (ctx->driver_data->has_limited_fmt && !win) {
7ee14cdc
GP
501 if (plane->pixel_format == DRM_FORMAT_ARGB8888)
502 plane->pixel_format = DRM_FORMAT_XRGB8888;
5cc4621a
ID
503 }
504
7ee14cdc 505 switch (plane->pixel_format) {
a4f38a80 506 case DRM_FORMAT_C8:
1c248b7d
ID
507 val |= WINCON0_BPPMODE_8BPP_PALETTE;
508 val |= WINCONx_BURSTLEN_8WORD;
509 val |= WINCONx_BYTSWP;
510 break;
a4f38a80
ID
511 case DRM_FORMAT_XRGB1555:
512 val |= WINCON0_BPPMODE_16BPP_1555;
513 val |= WINCONx_HAWSWP;
514 val |= WINCONx_BURSTLEN_16WORD;
515 break;
516 case DRM_FORMAT_RGB565:
1c248b7d
ID
517 val |= WINCON0_BPPMODE_16BPP_565;
518 val |= WINCONx_HAWSWP;
519 val |= WINCONx_BURSTLEN_16WORD;
520 break;
a4f38a80 521 case DRM_FORMAT_XRGB8888:
1c248b7d
ID
522 val |= WINCON0_BPPMODE_24BPP_888;
523 val |= WINCONx_WSWP;
524 val |= WINCONx_BURSTLEN_16WORD;
525 break;
a4f38a80
ID
526 case DRM_FORMAT_ARGB8888:
527 val |= WINCON1_BPPMODE_25BPP_A1888
1c248b7d
ID
528 | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL;
529 val |= WINCONx_WSWP;
530 val |= WINCONx_BURSTLEN_16WORD;
531 break;
532 default:
533 DRM_DEBUG_KMS("invalid pixel size so using unpacked 24bpp.\n");
534
535 val |= WINCON0_BPPMODE_24BPP_888;
536 val |= WINCONx_WSWP;
537 val |= WINCONx_BURSTLEN_16WORD;
538 break;
539 }
540
7ee14cdc 541 DRM_DEBUG_KMS("bpp = %d\n", plane->bpp);
1c248b7d 542
66367461
RS
543 /*
544 * In case of exynos, setting dma-burst to 16Word causes permanent
545 * tearing for very small buffers, e.g. cursor buffer. Burst Mode
8837deea
GP
546 * switching which is based on plane size is not recommended as
547 * plane size varies alot towards the end of the screen and rapid
66367461
RS
548 * movement causes unstable DMA which results into iommu crash/tear.
549 */
550
7ee14cdc 551 if (plane->fb_width < MIN_FB_WIDTH_FOR_16WORD_BURST) {
66367461
RS
552 val &= ~WINCONx_BURSTLEN_MASK;
553 val |= WINCONx_BURSTLEN_4WORD;
554 }
555
1c248b7d 556 writel(val, ctx->regs + WINCON(win));
453b44a3
GP
557
558 /* hardware window 0 doesn't support alpha channel. */
559 if (win != 0) {
560 /* OSD alpha */
561 val = VIDISD14C_ALPHA0_R(0xf) |
562 VIDISD14C_ALPHA0_G(0xf) |
563 VIDISD14C_ALPHA0_B(0xf) |
564 VIDISD14C_ALPHA1_R(0xf) |
565 VIDISD14C_ALPHA1_G(0xf) |
566 VIDISD14C_ALPHA1_B(0xf);
567
568 writel(val, ctx->regs + VIDOSD_C(win));
569
570 val = VIDW_ALPHA_R(0xf) | VIDW_ALPHA_G(0xf) |
571 VIDW_ALPHA_G(0xf);
572 writel(val, ctx->regs + VIDWnALPHA0(win));
573 writel(val, ctx->regs + VIDWnALPHA1(win));
574 }
1c248b7d
ID
575}
576
bb7704d6 577static void fimd_win_set_colkey(struct fimd_context *ctx, unsigned int win)
1c248b7d 578{
1c248b7d
ID
579 unsigned int keycon0 = 0, keycon1 = 0;
580
1c248b7d
ID
581 keycon0 = ~(WxKEYCON0_KEYBL_EN | WxKEYCON0_KEYEN_F |
582 WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
583
584 keycon1 = WxKEYCON1_COLVAL(0xffffffff);
585
586 writel(keycon0, ctx->regs + WKEYCON0_BASE(win));
587 writel(keycon1, ctx->regs + WKEYCON1_BASE(win));
588}
589
de7af100
TF
590/**
591 * shadow_protect_win() - disable updating values from shadow registers at vsync
592 *
593 * @win: window to protect registers for
594 * @protect: 1 to protect (disable updates)
595 */
596static void fimd_shadow_protect_win(struct fimd_context *ctx,
6e2a3b66 597 unsigned int win, bool protect)
de7af100
TF
598{
599 u32 reg, bits, val;
600
601 if (ctx->driver_data->has_shadowcon) {
602 reg = SHADOWCON;
603 bits = SHADOWCON_WINx_PROTECT(win);
604 } else {
605 reg = PRTCON;
606 bits = PRTCON_PROTECT;
607 }
608
609 val = readl(ctx->regs + reg);
610 if (protect)
611 val |= bits;
612 else
613 val &= ~bits;
614 writel(val, ctx->regs + reg);
615}
616
6e2a3b66 617static void fimd_win_commit(struct exynos_drm_crtc *crtc, unsigned int win)
1c248b7d 618{
93bca243 619 struct fimd_context *ctx = crtc->ctx;
7ee14cdc 620 struct exynos_drm_plane *plane;
7ee14cdc
GP
621 dma_addr_t dma_addr;
622 unsigned long val, size, offset;
623 unsigned int last_x, last_y, buf_offsize, line_size;
1c248b7d 624
e30d4bcf
ID
625 if (ctx->suspended)
626 return;
627
37b006e8 628 if (win < 0 || win >= WINDOWS_NR)
1c248b7d
ID
629 return;
630
7ee14cdc 631 plane = &ctx->planes[win];
1c248b7d 632
c329f667 633 if (ctx->suspended)
a43b933b 634 return;
a43b933b 635
1c248b7d 636 /*
de7af100 637 * SHADOWCON/PRTCON register is used for enabling timing.
1c248b7d
ID
638 *
639 * for example, once only width value of a register is set,
640 * if the dma is started then fimd hardware could malfunction so
641 * with protect window setting, the register fields with prefix '_F'
642 * wouldn't be updated at vsync also but updated once unprotect window
643 * is set.
644 */
645
646 /* protect windows */
de7af100 647 fimd_shadow_protect_win(ctx, win, true);
1c248b7d 648
7ee14cdc 649
cb8a3db2
JS
650 offset = plane->src_x * (plane->bpp >> 3);
651 offset += plane->src_y * plane->pitch;
7ee14cdc 652
1c248b7d 653 /* buffer start address */
7ee14cdc
GP
654 dma_addr = plane->dma_addr[0] + offset;
655 val = (unsigned long)dma_addr;
1c248b7d
ID
656 writel(val, ctx->regs + VIDWx_BUF_START(win, 0));
657
658 /* buffer end address */
68a29134 659 size = plane->pitch * plane->crtc_height;
7ee14cdc 660 val = (unsigned long)(dma_addr + size);
1c248b7d
ID
661 writel(val, ctx->regs + VIDWx_BUF_END(win, 0));
662
663 DRM_DEBUG_KMS("start addr = 0x%lx, end addr = 0x%lx, size = 0x%lx\n",
7ee14cdc 664 (unsigned long)dma_addr, val, size);
19c8b834 665 DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n",
7ee14cdc 666 plane->crtc_width, plane->crtc_height);
1c248b7d
ID
667
668 /* buffer size */
68a29134 669 buf_offsize = plane->pitch - (plane->crtc_width * (plane->bpp >> 3));
7ee14cdc
GP
670 line_size = plane->crtc_width * (plane->bpp >> 3);
671 val = VIDW_BUF_SIZE_OFFSET(buf_offsize) |
672 VIDW_BUF_SIZE_PAGEWIDTH(line_size) |
673 VIDW_BUF_SIZE_OFFSET_E(buf_offsize) |
674 VIDW_BUF_SIZE_PAGEWIDTH_E(line_size);
1c248b7d
ID
675 writel(val, ctx->regs + VIDWx_BUF_SIZE(win, 0));
676
677 /* OSD position */
7ee14cdc
GP
678 val = VIDOSDxA_TOPLEFT_X(plane->crtc_x) |
679 VIDOSDxA_TOPLEFT_Y(plane->crtc_y) |
680 VIDOSDxA_TOPLEFT_X_E(plane->crtc_x) |
681 VIDOSDxA_TOPLEFT_Y_E(plane->crtc_y);
1c248b7d
ID
682 writel(val, ctx->regs + VIDOSD_A(win));
683
7ee14cdc 684 last_x = plane->crtc_x + plane->crtc_width;
f56aad3a
JS
685 if (last_x)
686 last_x--;
7ee14cdc 687 last_y = plane->crtc_y + plane->crtc_height;
f56aad3a
JS
688 if (last_y)
689 last_y--;
690
ca555e5a
JS
691 val = VIDOSDxB_BOTRIGHT_X(last_x) | VIDOSDxB_BOTRIGHT_Y(last_y) |
692 VIDOSDxB_BOTRIGHT_X_E(last_x) | VIDOSDxB_BOTRIGHT_Y_E(last_y);
693
1c248b7d
ID
694 writel(val, ctx->regs + VIDOSD_B(win));
695
19c8b834 696 DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n",
7ee14cdc 697 plane->crtc_x, plane->crtc_y, last_x, last_y);
1c248b7d 698
1c248b7d
ID
699 /* OSD size */
700 if (win != 3 && win != 4) {
701 u32 offset = VIDOSD_D(win);
702 if (win == 0)
0f10cf14 703 offset = VIDOSD_C(win);
7ee14cdc 704 val = plane->crtc_width * plane->crtc_height;
1c248b7d
ID
705 writel(val, ctx->regs + offset);
706
707 DRM_DEBUG_KMS("osd size = 0x%x\n", (unsigned int)val);
708 }
709
bb7704d6 710 fimd_win_set_pixfmt(ctx, win);
1c248b7d
ID
711
712 /* hardware window 0 doesn't support color key. */
713 if (win != 0)
bb7704d6 714 fimd_win_set_colkey(ctx, win);
1c248b7d 715
f181a543 716 fimd_enable_video_output(ctx, win, true);
ec05da95 717
999d8b31
YC
718 if (ctx->driver_data->has_shadowcon)
719 fimd_enable_shadow_channel_path(ctx, win, true);
ec05da95 720
74944a58
YC
721 /* Enable DMA channel and unprotect windows */
722 fimd_shadow_protect_win(ctx, win, false);
723
3854fab2
YC
724 if (ctx->i80_if)
725 atomic_set(&ctx->win_updated, 1);
1c248b7d
ID
726}
727
6e2a3b66 728static void fimd_win_disable(struct exynos_drm_crtc *crtc, unsigned int win)
1c248b7d 729{
93bca243 730 struct fimd_context *ctx = crtc->ctx;
7ee14cdc 731 struct exynos_drm_plane *plane;
864ee9e6 732
37b006e8 733 if (win < 0 || win >= WINDOWS_NR)
1c248b7d
ID
734 return;
735
7ee14cdc 736 plane = &ctx->planes[win];
ec05da95 737
c329f667 738 if (ctx->suspended)
db7e55ae 739 return;
db7e55ae 740
1c248b7d 741 /* protect windows */
de7af100 742 fimd_shadow_protect_win(ctx, win, true);
1c248b7d 743
f181a543 744 fimd_enable_video_output(ctx, win, false);
1c248b7d 745
999d8b31
YC
746 if (ctx->driver_data->has_shadowcon)
747 fimd_enable_shadow_channel_path(ctx, win, false);
de7af100 748
999d8b31 749 /* unprotect windows */
de7af100 750 fimd_shadow_protect_win(ctx, win, false);
a43b933b
SP
751}
752
3cecda03 753static void fimd_enable(struct exynos_drm_crtc *crtc)
a43b933b 754{
3cecda03 755 struct fimd_context *ctx = crtc->ctx;
38000dbb 756 int ret;
a43b933b
SP
757
758 if (!ctx->suspended)
3cecda03 759 return;
a43b933b
SP
760
761 ctx->suspended = false;
762
af65c804
SP
763 pm_runtime_get_sync(ctx->dev);
764
38000dbb
GP
765 ret = clk_prepare_enable(ctx->bus_clk);
766 if (ret < 0) {
767 DRM_ERROR("Failed to prepare_enable the bus clk [%d]\n", ret);
768 return;
769 }
770
771 ret = clk_prepare_enable(ctx->lcd_clk);
772 if (ret < 0) {
773 DRM_ERROR("Failed to prepare_enable the lcd clk [%d]\n", ret);
774 return;
775 }
a43b933b
SP
776
777 /* if vblank was enabled status, enable it again. */
3cecda03
GP
778 if (test_and_clear_bit(0, &ctx->irq_flags))
779 fimd_enable_vblank(ctx->crtc);
a43b933b 780
c329f667 781 fimd_commit(ctx->crtc);
a43b933b
SP
782}
783
3cecda03 784static void fimd_disable(struct exynos_drm_crtc *crtc)
a43b933b 785{
3cecda03 786 struct fimd_context *ctx = crtc->ctx;
c329f667 787 int i;
3cecda03 788
a43b933b 789 if (ctx->suspended)
3cecda03 790 return;
a43b933b
SP
791
792 /*
793 * We need to make sure that all windows are disabled before we
794 * suspend that connector. Otherwise we might try to scan from
795 * a destroyed buffer later.
796 */
c329f667
JS
797 for (i = 0; i < WINDOWS_NR; i++)
798 fimd_win_disable(crtc, i);
a43b933b 799
94ab95a9
ID
800 fimd_enable_vblank(crtc);
801 fimd_wait_for_vblank(crtc);
802 fimd_disable_vblank(crtc);
803
b74f14fd
JS
804 writel(0, ctx->regs + VIDCON0);
805
a43b933b
SP
806 clk_disable_unprepare(ctx->lcd_clk);
807 clk_disable_unprepare(ctx->bus_clk);
808
af65c804
SP
809 pm_runtime_put_sync(ctx->dev);
810
a43b933b 811 ctx->suspended = true;
080be03d
SP
812}
813
3854fab2
YC
814static void fimd_trigger(struct device *dev)
815{
e152dbd7 816 struct fimd_context *ctx = dev_get_drvdata(dev);
3854fab2
YC
817 struct fimd_driver_data *driver_data = ctx->driver_data;
818 void *timing_base = ctx->regs + driver_data->timing_base;
819 u32 reg;
820
9b67eb73 821 /*
1c905d95
YC
822 * Skips triggering if in triggering state, because multiple triggering
823 * requests can cause panel reset.
824 */
9b67eb73
JS
825 if (atomic_read(&ctx->triggering))
826 return;
827
1c905d95 828 /* Enters triggering mode */
3854fab2
YC
829 atomic_set(&ctx->triggering, 1);
830
3854fab2
YC
831 reg = readl(timing_base + TRIGCON);
832 reg |= (TRGMODE_I80_RGB_ENABLE_I80 | SWTRGCMD_I80_RGB_ENABLE);
833 writel(reg, timing_base + TRIGCON);
87ab85b3
YC
834
835 /*
836 * Exits triggering mode if vblank is not enabled yet, because when the
837 * VIDINTCON0 register is not set, it can not exit from triggering mode.
838 */
839 if (!test_bit(0, &ctx->irq_flags))
840 atomic_set(&ctx->triggering, 0);
3854fab2
YC
841}
842
93bca243 843static void fimd_te_handler(struct exynos_drm_crtc *crtc)
3854fab2 844{
93bca243 845 struct fimd_context *ctx = crtc->ctx;
3854fab2
YC
846
847 /* Checks the crtc is detached already from encoder */
848 if (ctx->pipe < 0 || !ctx->drm_dev)
849 return;
850
3854fab2
YC
851 /*
852 * If there is a page flip request, triggers and handles the page flip
853 * event so that current fb can be updated into panel GRAM.
854 */
855 if (atomic_add_unless(&ctx->win_updated, -1, 0))
856 fimd_trigger(ctx->dev);
857
858 /* Wakes up vsync event queue */
859 if (atomic_read(&ctx->wait_vsync_event)) {
860 atomic_set(&ctx->wait_vsync_event, 0);
861 wake_up(&ctx->wait_vsync_queue);
3854fab2 862 }
b301ae24 863
adf67abf 864 if (test_bit(0, &ctx->irq_flags))
b301ae24 865 drm_handle_vblank(ctx->drm_dev, ctx->pipe);
3854fab2
YC
866}
867
48107d7b
KK
868static void fimd_dp_clock_enable(struct exynos_drm_crtc *crtc, bool enable)
869{
870 struct fimd_context *ctx = crtc->ctx;
871 u32 val;
872
873 /*
874 * Only Exynos 5250, 5260, 5410 and 542x requires enabling DP/MIE
875 * clock. On these SoCs the bootloader may enable it but any
876 * power domain off/on will reset it to disable state.
877 */
878 if (ctx->driver_data != &exynos5_fimd_driver_data)
879 return;
880
881 val = enable ? DP_MIE_CLK_DP_ENABLE : DP_MIE_CLK_DISABLE;
882 writel(DP_MIE_CLK_DP_ENABLE, ctx->regs + DP_MIE_CLKCON);
883}
884
f3aaf762 885static const struct exynos_drm_crtc_ops fimd_crtc_ops = {
3cecda03
GP
886 .enable = fimd_enable,
887 .disable = fimd_disable,
a968e727 888 .mode_fixup = fimd_mode_fixup,
1c6244c3
SP
889 .commit = fimd_commit,
890 .enable_vblank = fimd_enable_vblank,
891 .disable_vblank = fimd_disable_vblank,
892 .wait_for_vblank = fimd_wait_for_vblank,
1c6244c3
SP
893 .win_commit = fimd_win_commit,
894 .win_disable = fimd_win_disable,
3854fab2 895 .te_handler = fimd_te_handler,
48107d7b 896 .clock_enable = fimd_dp_clock_enable,
fc2e013f 897 .clear_channels = fimd_clear_channels,
1c248b7d
ID
898};
899
1c248b7d
ID
900static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
901{
902 struct fimd_context *ctx = (struct fimd_context *)dev_id;
3854fab2 903 u32 val, clear_bit;
1c248b7d
ID
904
905 val = readl(ctx->regs + VIDINTCON1);
906
3854fab2
YC
907 clear_bit = ctx->i80_if ? VIDINTCON1_INT_I80 : VIDINTCON1_INT_FRAME;
908 if (val & clear_bit)
909 writel(clear_bit, ctx->regs + VIDINTCON1);
1c248b7d 910
ec05da95 911 /* check the crtc is detached already from encoder */
080be03d 912 if (ctx->pipe < 0 || !ctx->drm_dev)
ec05da95 913 goto out;
483b88f8 914
1c905d95 915 if (ctx->i80_if) {
adf67abf
JS
916 exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe);
917
1c905d95 918 /* Exits triggering mode */
3854fab2 919 atomic_set(&ctx->triggering, 0);
3854fab2 920 } else {
adf67abf
JS
921 drm_handle_vblank(ctx->drm_dev, ctx->pipe);
922 exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe);
923
3854fab2
YC
924 /* set wait vsync event to zero and wake up queue. */
925 if (atomic_read(&ctx->wait_vsync_event)) {
926 atomic_set(&ctx->wait_vsync_event, 0);
927 wake_up(&ctx->wait_vsync_queue);
928 }
01ce113c 929 }
3854fab2 930
ec05da95 931out:
1c248b7d
ID
932 return IRQ_HANDLED;
933}
934
f37cd5e8 935static int fimd_bind(struct device *dev, struct device *master, void *data)
562ad9f4 936{
e152dbd7 937 struct fimd_context *ctx = dev_get_drvdata(dev);
f37cd5e8 938 struct drm_device *drm_dev = data;
cdbfca89 939 struct exynos_drm_private *priv = drm_dev->dev_private;
7ee14cdc
GP
940 struct exynos_drm_plane *exynos_plane;
941 enum drm_plane_type type;
6e2a3b66
GP
942 unsigned int zpos;
943 int ret;
000cc920 944
cdbfca89
HH
945 ctx->drm_dev = drm_dev;
946 ctx->pipe = priv->pipe++;
efa75bcd 947
7ee14cdc
GP
948 for (zpos = 0; zpos < WINDOWS_NR; zpos++) {
949 type = (zpos == ctx->default_win) ? DRM_PLANE_TYPE_PRIMARY :
950 DRM_PLANE_TYPE_OVERLAY;
951 ret = exynos_plane_init(drm_dev, &ctx->planes[zpos],
6e2a3b66 952 1 << ctx->pipe, type, zpos);
7ee14cdc
GP
953 if (ret)
954 return ret;
955 }
956
957 exynos_plane = &ctx->planes[ctx->default_win];
958 ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
959 ctx->pipe, EXYNOS_DISPLAY_TYPE_LCD,
0f04cf8d 960 &fimd_crtc_ops, ctx);
d1222842
HH
961 if (IS_ERR(ctx->crtc))
962 return PTR_ERR(ctx->crtc);
93bca243 963
000cc920
AH
964 if (ctx->display)
965 exynos_drm_create_enc_conn(drm_dev, ctx->display);
966
fc2e013f
HH
967 ret = drm_iommu_attach_device_if_possible(ctx->crtc, drm_dev, dev);
968 if (ret)
969 priv->pipe--;
970
971 return ret;
000cc920
AH
972}
973
974static void fimd_unbind(struct device *dev, struct device *master,
975 void *data)
976{
e152dbd7 977 struct fimd_context *ctx = dev_get_drvdata(dev);
000cc920 978
3cecda03 979 fimd_disable(ctx->crtc);
000cc920 980
cdbfca89
HH
981 fimd_iommu_detach_devices(ctx);
982
000cc920 983 if (ctx->display)
4cfde1f2 984 exynos_dpi_remove(ctx->display);
000cc920
AH
985}
986
987static const struct component_ops fimd_component_ops = {
988 .bind = fimd_bind,
989 .unbind = fimd_unbind,
990};
991
992static int fimd_probe(struct platform_device *pdev)
993{
994 struct device *dev = &pdev->dev;
562ad9f4 995 struct fimd_context *ctx;
3854fab2 996 struct device_node *i80_if_timings;
562ad9f4 997 struct resource *res;
fe42cfb4 998 int ret;
1c248b7d 999
e152dbd7
AH
1000 if (!dev->of_node)
1001 return -ENODEV;
2d3f173c 1002
d873ab99 1003 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
e152dbd7
AH
1004 if (!ctx)
1005 return -ENOMEM;
1006
bb7704d6 1007 ctx->dev = dev;
a43b933b 1008 ctx->suspended = true;
3854fab2 1009 ctx->driver_data = drm_fimd_get_driver_data(pdev);
bb7704d6 1010
1417f109
SP
1011 if (of_property_read_bool(dev->of_node, "samsung,invert-vden"))
1012 ctx->vidcon1 |= VIDCON1_INV_VDEN;
1013 if (of_property_read_bool(dev->of_node, "samsung,invert-vclk"))
1014 ctx->vidcon1 |= VIDCON1_INV_VCLK;
562ad9f4 1015
3854fab2
YC
1016 i80_if_timings = of_get_child_by_name(dev->of_node, "i80-if-timings");
1017 if (i80_if_timings) {
1018 u32 val;
1019
1020 ctx->i80_if = true;
1021
1022 if (ctx->driver_data->has_vidoutcon)
1023 ctx->vidout_con |= VIDOUT_CON_F_I80_LDI0;
1024 else
1025 ctx->vidcon0 |= VIDCON0_VIDOUT_I80_LDI0;
1026 /*
1027 * The user manual describes that this "DSI_EN" bit is required
1028 * to enable I80 24-bit data interface.
1029 */
1030 ctx->vidcon0 |= VIDCON0_DSI_EN;
1031
1032 if (of_property_read_u32(i80_if_timings, "cs-setup", &val))
1033 val = 0;
1034 ctx->i80ifcon = LCD_CS_SETUP(val);
1035 if (of_property_read_u32(i80_if_timings, "wr-setup", &val))
1036 val = 0;
1037 ctx->i80ifcon |= LCD_WR_SETUP(val);
1038 if (of_property_read_u32(i80_if_timings, "wr-active", &val))
1039 val = 1;
1040 ctx->i80ifcon |= LCD_WR_ACTIVE(val);
1041 if (of_property_read_u32(i80_if_timings, "wr-hold", &val))
1042 val = 0;
1043 ctx->i80ifcon |= LCD_WR_HOLD(val);
1044 }
1045 of_node_put(i80_if_timings);
1046
1047 ctx->sysreg = syscon_regmap_lookup_by_phandle(dev->of_node,
1048 "samsung,sysreg");
1049 if (IS_ERR(ctx->sysreg)) {
1050 dev_warn(dev, "failed to get system register.\n");
1051 ctx->sysreg = NULL;
1052 }
1053
a968e727
SP
1054 ctx->bus_clk = devm_clk_get(dev, "fimd");
1055 if (IS_ERR(ctx->bus_clk)) {
1056 dev_err(dev, "failed to get bus clock\n");
86650408 1057 return PTR_ERR(ctx->bus_clk);
a968e727
SP
1058 }
1059
1060 ctx->lcd_clk = devm_clk_get(dev, "sclk_fimd");
1061 if (IS_ERR(ctx->lcd_clk)) {
1062 dev_err(dev, "failed to get lcd clock\n");
86650408 1063 return PTR_ERR(ctx->lcd_clk);
a968e727 1064 }
1c248b7d 1065
1c248b7d 1066 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1c248b7d 1067
d873ab99 1068 ctx->regs = devm_ioremap_resource(dev, res);
86650408
AH
1069 if (IS_ERR(ctx->regs))
1070 return PTR_ERR(ctx->regs);
1c248b7d 1071
3854fab2
YC
1072 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1073 ctx->i80_if ? "lcd_sys" : "vsync");
1c248b7d
ID
1074 if (!res) {
1075 dev_err(dev, "irq request failed.\n");
86650408 1076 return -ENXIO;
1c248b7d
ID
1077 }
1078
055e0c06 1079 ret = devm_request_irq(dev, res->start, fimd_irq_handler,
edc57266
SK
1080 0, "drm_fimd", ctx);
1081 if (ret) {
1c248b7d 1082 dev_err(dev, "irq request failed.\n");
86650408 1083 return ret;
1c248b7d
ID
1084 }
1085
57ed0f7b 1086 init_waitqueue_head(&ctx->wait_vsync_queue);
01ce113c 1087 atomic_set(&ctx->wait_vsync_event, 0);
1c248b7d 1088
e152dbd7 1089 platform_set_drvdata(pdev, ctx);
14b6873a 1090
000cc920 1091 ctx->display = exynos_dpi_probe(dev);
5baf5d44 1092 if (IS_ERR(ctx->display)) {
86650408 1093 return PTR_ERR(ctx->display);
5baf5d44 1094 }
f37cd5e8 1095
e152dbd7 1096 pm_runtime_enable(dev);
f37cd5e8 1097
e152dbd7 1098 ret = component_add(dev, &fimd_component_ops);
df5225bc
ID
1099 if (ret)
1100 goto err_disable_pm_runtime;
1101
1102 return ret;
1103
1104err_disable_pm_runtime:
e152dbd7 1105 pm_runtime_disable(dev);
df5225bc 1106
df5225bc 1107 return ret;
f37cd5e8 1108}
cb91f6a0 1109
f37cd5e8
ID
1110static int fimd_remove(struct platform_device *pdev)
1111{
af65c804 1112 pm_runtime_disable(&pdev->dev);
5d55393a 1113
df5225bc 1114 component_del(&pdev->dev, &fimd_component_ops);
df5225bc 1115
5d55393a 1116 return 0;
e30d4bcf
ID
1117}
1118
132a5b91 1119struct platform_driver fimd_driver = {
1c248b7d 1120 .probe = fimd_probe,
56550d94 1121 .remove = fimd_remove,
1c248b7d
ID
1122 .driver = {
1123 .name = "exynos4-fb",
1124 .owner = THIS_MODULE,
2d3f173c 1125 .of_match_table = fimd_driver_dt_match,
1c248b7d
ID
1126 },
1127};
This page took 0.263286 seconds and 5 git commands to generate.