1 // SPDX-License-Identifier: GPL-2.0-only
2 /* drivers/gpu/drm/exynos5433_drm_decon.c
4 * Copyright (C) 2015 Samsung Electronics Co.Ltd
6 * Joonyoung Shim <jy0922.shim@samsung.com>
7 * Hyungwon Hwang <human.hwang@samsung.com>
10 #include <linux/clk.h>
11 #include <linux/component.h>
12 #include <linux/iopoll.h>
13 #include <linux/irq.h>
14 #include <linux/mfd/syscon.h>
16 #include <linux/platform_device.h>
17 #include <linux/pm_runtime.h>
18 #include <linux/regmap.h>
20 #include <drm/drm_blend.h>
21 #include <drm/drm_fourcc.h>
22 #include <drm/drm_framebuffer.h>
23 #include <drm/drm_vblank.h>
25 #include "exynos_drm_crtc.h"
26 #include "exynos_drm_drv.h"
27 #include "exynos_drm_fb.h"
28 #include "exynos_drm_plane.h"
29 #include "regs-decon5433.h"
31 #define DSD_CFG_MUX 0x1004
32 #define DSD_CFG_MUX_TE_UNMASK_GLOBAL BIT(13)
38 #define MIN_FB_WIDTH_FOR_16WORD_BURST 128
40 #define I80_HW_TRG (1 << 0)
41 #define IFTYPE_HDMI (1 << 1)
43 static const char * const decon_clks_name
[] = {
56 struct decon_context
{
58 struct drm_device
*drm_dev
;
60 struct exynos_drm_crtc
*crtc
;
61 struct exynos_drm_plane planes
[WINDOWS_NR
];
62 struct exynos_drm_plane_config configs
[WINDOWS_NR
];
64 struct regmap
*sysreg
;
65 struct clk
*clks
[ARRAY_SIZE(decon_clks_name
)];
67 unsigned int irq_vsync
;
68 unsigned int irq_lcd_sys
;
70 unsigned long out_type
;
72 spinlock_t vblank_lock
;
76 static const uint32_t decon_formats
[] = {
83 static const enum drm_plane_type decon_win_types
[WINDOWS_NR
] = {
84 [PRIMARY_WIN
] = DRM_PLANE_TYPE_PRIMARY
,
85 [CURSON_WIN
] = DRM_PLANE_TYPE_CURSOR
,
88 static const unsigned int capabilities
[WINDOWS_NR
] = {
90 EXYNOS_DRM_PLANE_CAP_WIN_BLEND
| EXYNOS_DRM_PLANE_CAP_PIX_BLEND
,
91 EXYNOS_DRM_PLANE_CAP_WIN_BLEND
| EXYNOS_DRM_PLANE_CAP_PIX_BLEND
,
92 EXYNOS_DRM_PLANE_CAP_WIN_BLEND
| EXYNOS_DRM_PLANE_CAP_PIX_BLEND
,
93 EXYNOS_DRM_PLANE_CAP_WIN_BLEND
| EXYNOS_DRM_PLANE_CAP_PIX_BLEND
,
96 static inline void decon_set_bits(struct decon_context
*ctx
, u32 reg
, u32 mask
,
99 val
= (val
& mask
) | (readl(ctx
->addr
+ reg
) & ~mask
);
100 writel(val
, ctx
->addr
+ reg
);
103 static int decon_enable_vblank(struct exynos_drm_crtc
*crtc
)
105 struct decon_context
*ctx
= crtc
->ctx
;
108 val
= VIDINTCON0_INTEN
;
110 val
|= VIDINTCON0_FRAMEDONE
;
112 val
|= VIDINTCON0_INTFRMEN
| VIDINTCON0_FRAMESEL_FP
;
114 writel(val
, ctx
->addr
+ DECON_VIDINTCON0
);
116 enable_irq(ctx
->irq
);
117 if (!(ctx
->out_type
& I80_HW_TRG
))
118 enable_irq(ctx
->te_irq
);
123 static void decon_disable_vblank(struct exynos_drm_crtc
*crtc
)
125 struct decon_context
*ctx
= crtc
->ctx
;
127 if (!(ctx
->out_type
& I80_HW_TRG
))
128 disable_irq_nosync(ctx
->te_irq
);
129 disable_irq_nosync(ctx
->irq
);
131 writel(0, ctx
->addr
+ DECON_VIDINTCON0
);
134 /* return number of starts/ends of frame transmissions since reset */
135 static u32
decon_get_frame_count(struct decon_context
*ctx
, bool end
)
137 u32 frm
, pfrm
, status
, cnt
= 2;
139 /* To get consistent result repeat read until frame id is stable.
140 * Usually the loop will be executed once, in rare cases when the loop
141 * is executed at frame change time 2nd pass will be needed.
143 frm
= readl(ctx
->addr
+ DECON_CRFMID
);
145 status
= readl(ctx
->addr
+ DECON_VIDCON1
);
147 frm
= readl(ctx
->addr
+ DECON_CRFMID
);
148 } while (frm
!= pfrm
&& --cnt
);
150 /* CRFMID is incremented on BPORCH in case of I80 and on VSYNC in case
151 * of RGB, it should be taken into account.
156 switch (status
& (VIDCON1_VSTATUS_MASK
| VIDCON1_I80_ACTIVE
)) {
157 case VIDCON1_VSTATUS_VS
:
158 if (!(ctx
->crtc
->i80_mode
))
161 case VIDCON1_VSTATUS_BP
:
164 case VIDCON1_I80_ACTIVE
:
165 case VIDCON1_VSTATUS_AC
:
176 static void decon_setup_trigger(struct decon_context
*ctx
)
178 if (!ctx
->crtc
->i80_mode
&& !(ctx
->out_type
& I80_HW_TRG
))
181 if (!(ctx
->out_type
& I80_HW_TRG
)) {
182 writel(TRIGCON_TRIGEN_PER_F
| TRIGCON_TRIGEN_F
|
183 TRIGCON_TE_AUTO_MASK
| TRIGCON_SWTRIGEN
,
184 ctx
->addr
+ DECON_TRIGCON
);
188 writel(TRIGCON_TRIGEN_PER_F
| TRIGCON_TRIGEN_F
| TRIGCON_HWTRIGMASK
189 | TRIGCON_HWTRIGEN
, ctx
->addr
+ DECON_TRIGCON
);
191 if (regmap_update_bits(ctx
->sysreg
, DSD_CFG_MUX
,
192 DSD_CFG_MUX_TE_UNMASK_GLOBAL
, ~0))
193 DRM_DEV_ERROR(ctx
->dev
, "Cannot update sysreg.\n");
196 static void decon_commit(struct exynos_drm_crtc
*crtc
)
198 struct decon_context
*ctx
= crtc
->ctx
;
199 struct drm_display_mode
*m
= &crtc
->base
.mode
;
200 bool interlaced
= false;
203 if (ctx
->out_type
& IFTYPE_HDMI
) {
204 m
->crtc_hsync_start
= m
->crtc_hdisplay
+ 10;
205 m
->crtc_hsync_end
= m
->crtc_htotal
- 92;
206 m
->crtc_vsync_start
= m
->crtc_vdisplay
+ 1;
207 m
->crtc_vsync_end
= m
->crtc_vsync_start
+ 1;
208 if (m
->flags
& DRM_MODE_FLAG_INTERLACE
)
212 decon_setup_trigger(ctx
);
214 /* lcd on and use command if */
217 val
|= VIDOUT_INTERLACE_EN_F
;
218 if (crtc
->i80_mode
) {
219 val
|= VIDOUT_COMMAND_IF
;
221 val
|= VIDOUT_RGB_IF
;
224 writel(val
, ctx
->addr
+ DECON_VIDOUTCON0
);
227 val
= VIDTCON2_LINEVAL(m
->vdisplay
/ 2 - 1) |
228 VIDTCON2_HOZVAL(m
->hdisplay
- 1);
230 val
= VIDTCON2_LINEVAL(m
->vdisplay
- 1) |
231 VIDTCON2_HOZVAL(m
->hdisplay
- 1);
232 writel(val
, ctx
->addr
+ DECON_VIDTCON2
);
234 if (!crtc
->i80_mode
) {
235 int vbp
= m
->crtc_vtotal
- m
->crtc_vsync_end
;
236 int vfp
= m
->crtc_vsync_start
- m
->crtc_vdisplay
;
240 val
= VIDTCON00_VBPD_F(vbp
- 1) | VIDTCON00_VFPD_F(vfp
- 1);
241 writel(val
, ctx
->addr
+ DECON_VIDTCON00
);
243 val
= VIDTCON01_VSPW_F(
244 m
->crtc_vsync_end
- m
->crtc_vsync_start
- 1);
245 writel(val
, ctx
->addr
+ DECON_VIDTCON01
);
247 val
= VIDTCON10_HBPD_F(
248 m
->crtc_htotal
- m
->crtc_hsync_end
- 1) |
250 m
->crtc_hsync_start
- m
->crtc_hdisplay
- 1);
251 writel(val
, ctx
->addr
+ DECON_VIDTCON10
);
253 val
= VIDTCON11_HSPW_F(
254 m
->crtc_hsync_end
- m
->crtc_hsync_start
- 1);
255 writel(val
, ctx
->addr
+ DECON_VIDTCON11
);
258 /* enable output and display signal */
259 decon_set_bits(ctx
, DECON_VIDCON0
, VIDCON0_ENVID
| VIDCON0_ENVID_F
, ~0);
261 decon_set_bits(ctx
, DECON_UPDATE
, STANDALONE_UPDATE_F
, ~0);
264 static void decon_win_set_bldeq(struct decon_context
*ctx
, unsigned int win
,
265 unsigned int alpha
, unsigned int pixel_alpha
)
267 u32 mask
= BLENDERQ_A_FUNC_F(0xf) | BLENDERQ_B_FUNC_F(0xf);
270 switch (pixel_alpha
) {
271 case DRM_MODE_BLEND_PIXEL_NONE
:
272 case DRM_MODE_BLEND_COVERAGE
:
273 val
|= BLENDERQ_A_FUNC_F(BLENDERQ_ALPHA_A
);
274 val
|= BLENDERQ_B_FUNC_F(BLENDERQ_ONE_MINUS_ALPHA_A
);
276 case DRM_MODE_BLEND_PREMULTI
:
278 if (alpha
!= DRM_BLEND_ALPHA_OPAQUE
) {
279 val
|= BLENDERQ_A_FUNC_F(BLENDERQ_ALPHA0
);
280 val
|= BLENDERQ_B_FUNC_F(BLENDERQ_ONE_MINUS_ALPHA_A
);
282 val
|= BLENDERQ_A_FUNC_F(BLENDERQ_ONE
);
283 val
|= BLENDERQ_B_FUNC_F(BLENDERQ_ONE_MINUS_ALPHA_A
);
287 decon_set_bits(ctx
, DECON_BLENDERQx(win
), mask
, val
);
290 static void decon_win_set_bldmod(struct decon_context
*ctx
, unsigned int win
,
291 unsigned int alpha
, unsigned int pixel_alpha
)
293 u32 win_alpha
= alpha
>> 8;
296 switch (pixel_alpha
) {
297 case DRM_MODE_BLEND_PIXEL_NONE
:
299 case DRM_MODE_BLEND_COVERAGE
:
300 case DRM_MODE_BLEND_PREMULTI
:
302 val
|= WINCONx_ALPHA_SEL_F
;
303 val
|= WINCONx_BLD_PIX_F
;
304 val
|= WINCONx_ALPHA_MUL_F
;
307 decon_set_bits(ctx
, DECON_WINCONx(win
), WINCONx_BLEND_MODE_MASK
, val
);
309 if (alpha
!= DRM_BLEND_ALPHA_OPAQUE
) {
310 val
= VIDOSD_Wx_ALPHA_R_F(win_alpha
) |
311 VIDOSD_Wx_ALPHA_G_F(win_alpha
) |
312 VIDOSD_Wx_ALPHA_B_F(win_alpha
);
313 decon_set_bits(ctx
, DECON_VIDOSDxC(win
),
314 VIDOSDxC_ALPHA0_RGB_MASK
, val
);
315 decon_set_bits(ctx
, DECON_BLENDCON
, BLEND_NEW
, BLEND_NEW
);
319 static void decon_win_set_pixfmt(struct decon_context
*ctx
, unsigned int win
,
320 struct drm_framebuffer
*fb
)
322 struct exynos_drm_plane
*plane
= &ctx
->planes
[win
];
323 struct exynos_drm_plane_state
*state
=
324 to_exynos_plane_state(plane
->base
.state
);
325 unsigned int alpha
= state
->base
.alpha
;
326 unsigned int pixel_alpha
;
329 if (fb
->format
->has_alpha
)
330 pixel_alpha
= state
->base
.pixel_blend_mode
;
332 pixel_alpha
= DRM_MODE_BLEND_PIXEL_NONE
;
334 val
= readl(ctx
->addr
+ DECON_WINCONx(win
));
335 val
&= WINCONx_ENWIN_F
;
337 switch (fb
->format
->format
) {
338 case DRM_FORMAT_XRGB1555
:
339 val
|= WINCONx_BPPMODE_16BPP_I1555
;
340 val
|= WINCONx_HAWSWP_F
;
341 val
|= WINCONx_BURSTLEN_16WORD
;
343 case DRM_FORMAT_RGB565
:
344 val
|= WINCONx_BPPMODE_16BPP_565
;
345 val
|= WINCONx_HAWSWP_F
;
346 val
|= WINCONx_BURSTLEN_16WORD
;
348 case DRM_FORMAT_XRGB8888
:
349 val
|= WINCONx_BPPMODE_24BPP_888
;
350 val
|= WINCONx_WSWP_F
;
351 val
|= WINCONx_BURSTLEN_16WORD
;
353 case DRM_FORMAT_ARGB8888
:
355 val
|= WINCONx_BPPMODE_32BPP_A8888
;
356 val
|= WINCONx_WSWP_F
;
357 val
|= WINCONx_BURSTLEN_16WORD
;
361 DRM_DEV_DEBUG_KMS(ctx
->dev
, "cpp = %u\n", fb
->format
->cpp
[0]);
364 * In case of exynos, setting dma-burst to 16Word causes permanent
365 * tearing for very small buffers, e.g. cursor buffer. Burst Mode
366 * switching which is based on plane size is not recommended as
367 * plane size varies a lot towards the end of the screen and rapid
368 * movement causes unstable DMA which results into iommu crash/tear.
371 if (fb
->width
< MIN_FB_WIDTH_FOR_16WORD_BURST
) {
372 val
&= ~WINCONx_BURSTLEN_MASK
;
373 val
|= WINCONx_BURSTLEN_8WORD
;
375 decon_set_bits(ctx
, DECON_WINCONx(win
), ~WINCONx_BLEND_MODE_MASK
, val
);
378 decon_win_set_bldmod(ctx
, win
, alpha
, pixel_alpha
);
379 decon_win_set_bldeq(ctx
, win
, alpha
, pixel_alpha
);
383 static void decon_shadow_protect(struct decon_context
*ctx
, bool protect
)
385 decon_set_bits(ctx
, DECON_SHADOWCON
, SHADOWCON_PROTECT_MASK
,
389 static void decon_atomic_begin(struct exynos_drm_crtc
*crtc
)
391 struct decon_context
*ctx
= crtc
->ctx
;
393 decon_shadow_protect(ctx
, true);
396 #define BIT_VAL(x, e, s) (((x) & ((1 << ((e) - (s) + 1)) - 1)) << (s))
397 #define COORDINATE_X(x) BIT_VAL((x), 23, 12)
398 #define COORDINATE_Y(x) BIT_VAL((x), 11, 0)
400 static void decon_update_plane(struct exynos_drm_crtc
*crtc
,
401 struct exynos_drm_plane
*plane
)
403 struct exynos_drm_plane_state
*state
=
404 to_exynos_plane_state(plane
->base
.state
);
405 struct decon_context
*ctx
= crtc
->ctx
;
406 struct drm_framebuffer
*fb
= state
->base
.fb
;
407 unsigned int win
= plane
->index
;
408 unsigned int cpp
= fb
->format
->cpp
[0];
409 unsigned int pitch
= fb
->pitches
[0];
410 dma_addr_t dma_addr
= exynos_drm_fb_dma_addr(fb
, 0);
413 if (crtc
->base
.mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
414 val
= COORDINATE_X(state
->crtc
.x
) |
415 COORDINATE_Y(state
->crtc
.y
/ 2);
416 writel(val
, ctx
->addr
+ DECON_VIDOSDxA(win
));
418 val
= COORDINATE_X(state
->crtc
.x
+ state
->crtc
.w
- 1) |
419 COORDINATE_Y((state
->crtc
.y
+ state
->crtc
.h
) / 2 - 1);
420 writel(val
, ctx
->addr
+ DECON_VIDOSDxB(win
));
422 val
= COORDINATE_X(state
->crtc
.x
) | COORDINATE_Y(state
->crtc
.y
);
423 writel(val
, ctx
->addr
+ DECON_VIDOSDxA(win
));
425 val
= COORDINATE_X(state
->crtc
.x
+ state
->crtc
.w
- 1) |
426 COORDINATE_Y(state
->crtc
.y
+ state
->crtc
.h
- 1);
427 writel(val
, ctx
->addr
+ DECON_VIDOSDxB(win
));
430 val
= VIDOSD_Wx_ALPHA_R_F(0xff) | VIDOSD_Wx_ALPHA_G_F(0xff) |
431 VIDOSD_Wx_ALPHA_B_F(0xff);
432 writel(val
, ctx
->addr
+ DECON_VIDOSDxC(win
));
434 val
= VIDOSD_Wx_ALPHA_R_F(0x0) | VIDOSD_Wx_ALPHA_G_F(0x0) |
435 VIDOSD_Wx_ALPHA_B_F(0x0);
436 writel(val
, ctx
->addr
+ DECON_VIDOSDxD(win
));
438 writel(dma_addr
, ctx
->addr
+ DECON_VIDW0xADD0B0(win
));
440 val
= dma_addr
+ pitch
* state
->src
.h
;
441 writel(val
, ctx
->addr
+ DECON_VIDW0xADD1B0(win
));
443 if (!(ctx
->out_type
& IFTYPE_HDMI
))
444 val
= BIT_VAL(pitch
- state
->crtc
.w
* cpp
, 27, 14)
445 | BIT_VAL(state
->crtc
.w
* cpp
, 13, 0);
447 val
= BIT_VAL(pitch
- state
->crtc
.w
* cpp
, 29, 15)
448 | BIT_VAL(state
->crtc
.w
* cpp
, 14, 0);
449 writel(val
, ctx
->addr
+ DECON_VIDW0xADD2(win
));
451 decon_win_set_pixfmt(ctx
, win
, fb
);
454 decon_set_bits(ctx
, DECON_WINCONx(win
), WINCONx_ENWIN_F
, ~0);
457 static void decon_disable_plane(struct exynos_drm_crtc
*crtc
,
458 struct exynos_drm_plane
*plane
)
460 struct decon_context
*ctx
= crtc
->ctx
;
461 unsigned int win
= plane
->index
;
463 decon_set_bits(ctx
, DECON_WINCONx(win
), WINCONx_ENWIN_F
, 0);
466 static void decon_atomic_flush(struct exynos_drm_crtc
*crtc
)
468 struct decon_context
*ctx
= crtc
->ctx
;
471 spin_lock_irqsave(&ctx
->vblank_lock
, flags
);
473 decon_shadow_protect(ctx
, false);
475 decon_set_bits(ctx
, DECON_UPDATE
, STANDALONE_UPDATE_F
, ~0);
477 ctx
->frame_id
= decon_get_frame_count(ctx
, true);
479 exynos_crtc_handle_event(crtc
);
481 spin_unlock_irqrestore(&ctx
->vblank_lock
, flags
);
484 static void decon_swreset(struct decon_context
*ctx
)
490 writel(0, ctx
->addr
+ DECON_VIDCON0
);
491 readl_poll_timeout(ctx
->addr
+ DECON_VIDCON0
, val
,
492 ~val
& VIDCON0_STOP_STATUS
, 12, 20000);
494 writel(VIDCON0_SWRESET
, ctx
->addr
+ DECON_VIDCON0
);
495 ret
= readl_poll_timeout(ctx
->addr
+ DECON_VIDCON0
, val
,
496 ~val
& VIDCON0_SWRESET
, 12, 20000);
498 WARN(ret
< 0, "failed to software reset DECON\n");
500 spin_lock_irqsave(&ctx
->vblank_lock
, flags
);
502 spin_unlock_irqrestore(&ctx
->vblank_lock
, flags
);
504 if (!(ctx
->out_type
& IFTYPE_HDMI
))
507 writel(VIDCON0_CLKVALUP
| VIDCON0_VLCKFREE
, ctx
->addr
+ DECON_VIDCON0
);
508 decon_set_bits(ctx
, DECON_CMU
,
509 CMU_CLKGAGE_MODE_SFR_F
| CMU_CLKGAGE_MODE_MEM_F
, ~0);
510 writel(VIDCON1_VCLK_RUN_VDEN_DISABLE
, ctx
->addr
+ DECON_VIDCON1
);
511 writel(CRCCTRL_CRCEN
| CRCCTRL_CRCSTART_F
| CRCCTRL_CRCCLKEN
,
512 ctx
->addr
+ DECON_CRCCTRL
);
515 static void decon_atomic_enable(struct exynos_drm_crtc
*crtc
)
517 struct decon_context
*ctx
= crtc
->ctx
;
520 ret
= pm_runtime_resume_and_get(ctx
->dev
);
522 DRM_DEV_ERROR(ctx
->dev
, "failed to enable DECON device.\n");
526 exynos_drm_pipe_clk_enable(crtc
, true);
530 decon_commit(ctx
->crtc
);
533 static void decon_atomic_disable(struct exynos_drm_crtc
*crtc
)
535 struct decon_context
*ctx
= crtc
->ctx
;
538 if (!(ctx
->out_type
& I80_HW_TRG
))
539 synchronize_irq(ctx
->te_irq
);
540 synchronize_irq(ctx
->irq
);
543 * We need to make sure that all windows are disabled before we
544 * suspend that connector. Otherwise we might try to scan from
545 * a destroyed buffer later.
547 for (i
= ctx
->first_win
; i
< WINDOWS_NR
; i
++)
548 decon_disable_plane(crtc
, &ctx
->planes
[i
]);
552 exynos_drm_pipe_clk_enable(crtc
, false);
554 pm_runtime_put_sync(ctx
->dev
);
557 static irqreturn_t
decon_te_irq_handler(int irq
, void *dev_id
)
559 struct decon_context
*ctx
= dev_id
;
561 decon_set_bits(ctx
, DECON_TRIGCON
, TRIGCON_SWTRIGCMD
, ~0);
566 static void decon_clear_channels(struct exynos_drm_crtc
*crtc
)
568 struct decon_context
*ctx
= crtc
->ctx
;
571 for (i
= 0; i
< ARRAY_SIZE(decon_clks_name
); i
++) {
572 ret
= clk_prepare_enable(ctx
->clks
[i
]);
577 decon_shadow_protect(ctx
, true);
578 for (win
= 0; win
< WINDOWS_NR
; win
++)
579 decon_set_bits(ctx
, DECON_WINCONx(win
), WINCONx_ENWIN_F
, 0);
580 decon_shadow_protect(ctx
, false);
582 decon_set_bits(ctx
, DECON_UPDATE
, STANDALONE_UPDATE_F
, ~0);
584 /* TODO: wait for possible vsync */
589 clk_disable_unprepare(ctx
->clks
[i
]);
592 static enum drm_mode_status
decon_mode_valid(struct exynos_drm_crtc
*crtc
,
593 const struct drm_display_mode
*mode
)
595 struct decon_context
*ctx
= crtc
->ctx
;
597 ctx
->irq
= crtc
->i80_mode
? ctx
->irq_lcd_sys
: ctx
->irq_vsync
;
602 dev_info(ctx
->dev
, "Sink requires %s mode, but appropriate interrupt is not provided.\n",
603 crtc
->i80_mode
? "command" : "video");
608 static const struct exynos_drm_crtc_ops decon_crtc_ops
= {
609 .atomic_enable
= decon_atomic_enable
,
610 .atomic_disable
= decon_atomic_disable
,
611 .enable_vblank
= decon_enable_vblank
,
612 .disable_vblank
= decon_disable_vblank
,
613 .atomic_begin
= decon_atomic_begin
,
614 .update_plane
= decon_update_plane
,
615 .disable_plane
= decon_disable_plane
,
616 .mode_valid
= decon_mode_valid
,
617 .atomic_flush
= decon_atomic_flush
,
620 static int decon_bind(struct device
*dev
, struct device
*master
, void *data
)
622 struct decon_context
*ctx
= dev_get_drvdata(dev
);
623 struct drm_device
*drm_dev
= data
;
624 struct exynos_drm_plane
*exynos_plane
;
625 enum exynos_drm_output_type out_type
;
629 ctx
->drm_dev
= drm_dev
;
631 for (win
= ctx
->first_win
; win
< WINDOWS_NR
; win
++) {
632 ctx
->configs
[win
].pixel_formats
= decon_formats
;
633 ctx
->configs
[win
].num_pixel_formats
= ARRAY_SIZE(decon_formats
);
634 ctx
->configs
[win
].zpos
= win
- ctx
->first_win
;
635 ctx
->configs
[win
].type
= decon_win_types
[win
];
636 ctx
->configs
[win
].capabilities
= capabilities
[win
];
638 ret
= exynos_plane_init(drm_dev
, &ctx
->planes
[win
], win
,
644 exynos_plane
= &ctx
->planes
[PRIMARY_WIN
];
645 out_type
= (ctx
->out_type
& IFTYPE_HDMI
) ? EXYNOS_DISPLAY_TYPE_HDMI
646 : EXYNOS_DISPLAY_TYPE_LCD
;
647 ctx
->crtc
= exynos_drm_crtc_create(drm_dev
, &exynos_plane
->base
,
648 out_type
, &decon_crtc_ops
, ctx
);
649 if (IS_ERR(ctx
->crtc
))
650 return PTR_ERR(ctx
->crtc
);
652 decon_clear_channels(ctx
->crtc
);
654 return exynos_drm_register_dma(drm_dev
, dev
, &ctx
->dma_priv
);
657 static void decon_unbind(struct device
*dev
, struct device
*master
, void *data
)
659 struct decon_context
*ctx
= dev_get_drvdata(dev
);
661 decon_atomic_disable(ctx
->crtc
);
663 /* detach this sub driver from iommu mapping if supported. */
664 exynos_drm_unregister_dma(ctx
->drm_dev
, ctx
->dev
, &ctx
->dma_priv
);
667 static const struct component_ops decon_component_ops
= {
669 .unbind
= decon_unbind
,
672 static void decon_handle_vblank(struct decon_context
*ctx
)
676 spin_lock(&ctx
->vblank_lock
);
678 frm
= decon_get_frame_count(ctx
, true);
680 if (frm
!= ctx
->frame_id
) {
681 /* handle only if incremented, take care of wrap-around */
682 if ((s32
)(frm
- ctx
->frame_id
) > 0)
683 drm_crtc_handle_vblank(&ctx
->crtc
->base
);
687 spin_unlock(&ctx
->vblank_lock
);
690 static irqreturn_t
decon_irq_handler(int irq
, void *dev_id
)
692 struct decon_context
*ctx
= dev_id
;
695 val
= readl(ctx
->addr
+ DECON_VIDINTCON1
);
696 val
&= VIDINTCON1_INTFRMDONEPEND
| VIDINTCON1_INTFRMPEND
;
699 writel(val
, ctx
->addr
+ DECON_VIDINTCON1
);
700 if (ctx
->out_type
& IFTYPE_HDMI
) {
701 val
= readl(ctx
->addr
+ DECON_VIDOUTCON0
);
702 val
&= VIDOUT_INTERLACE_EN_F
| VIDOUT_INTERLACE_FIELD_F
;
704 (VIDOUT_INTERLACE_EN_F
| VIDOUT_INTERLACE_FIELD_F
))
707 decon_handle_vblank(ctx
);
713 static int exynos5433_decon_suspend(struct device
*dev
)
715 struct decon_context
*ctx
= dev_get_drvdata(dev
);
716 int i
= ARRAY_SIZE(decon_clks_name
);
719 clk_disable_unprepare(ctx
->clks
[i
]);
724 static int exynos5433_decon_resume(struct device
*dev
)
726 struct decon_context
*ctx
= dev_get_drvdata(dev
);
729 for (i
= 0; i
< ARRAY_SIZE(decon_clks_name
); i
++) {
730 ret
= clk_prepare_enable(ctx
->clks
[i
]);
739 clk_disable_unprepare(ctx
->clks
[i
]);
744 static DEFINE_RUNTIME_DEV_PM_OPS(exynos5433_decon_pm_ops
,
745 exynos5433_decon_suspend
,
746 exynos5433_decon_resume
, NULL
);
748 static const struct of_device_id exynos5433_decon_driver_dt_match
[] = {
750 .compatible
= "samsung,exynos5433-decon",
751 .data
= (void *)I80_HW_TRG
754 .compatible
= "samsung,exynos5433-decon-tv",
755 .data
= (void *)(I80_HW_TRG
| IFTYPE_HDMI
)
759 MODULE_DEVICE_TABLE(of
, exynos5433_decon_driver_dt_match
);
761 static int decon_conf_irq(struct decon_context
*ctx
, const char *name
,
762 irq_handler_t handler
, unsigned long int flags
)
764 struct platform_device
*pdev
= to_platform_device(ctx
->dev
);
765 int ret
, irq
= platform_get_irq_byname(pdev
, name
);
775 dev_err(ctx
->dev
, "IRQ %s get failed, %d\n", name
, irq
);
779 ret
= devm_request_irq(ctx
->dev
, irq
, handler
,
780 flags
| IRQF_NO_AUTOEN
, "drm_decon", ctx
);
782 dev_err(ctx
->dev
, "IRQ %s request failed\n", name
);
789 static int exynos5433_decon_probe(struct platform_device
*pdev
)
791 struct device
*dev
= &pdev
->dev
;
792 struct decon_context
*ctx
;
796 ctx
= devm_kzalloc(dev
, sizeof(*ctx
), GFP_KERNEL
);
801 ctx
->out_type
= (unsigned long)of_device_get_match_data(dev
);
802 spin_lock_init(&ctx
->vblank_lock
);
804 if (ctx
->out_type
& IFTYPE_HDMI
)
807 for (i
= 0; i
< ARRAY_SIZE(decon_clks_name
); i
++) {
810 clk
= devm_clk_get(ctx
->dev
, decon_clks_name
[i
]);
817 ctx
->addr
= devm_platform_ioremap_resource(pdev
, 0);
818 if (IS_ERR(ctx
->addr
))
819 return PTR_ERR(ctx
->addr
);
821 ret
= decon_conf_irq(ctx
, "vsync", decon_irq_handler
, 0);
824 ctx
->irq_vsync
= ret
;
826 ret
= decon_conf_irq(ctx
, "lcd_sys", decon_irq_handler
, 0);
829 ctx
->irq_lcd_sys
= ret
;
831 ret
= decon_conf_irq(ctx
, "te", decon_te_irq_handler
,
832 IRQF_TRIGGER_RISING
);
837 ctx
->out_type
&= ~I80_HW_TRG
;
840 if (ctx
->out_type
& I80_HW_TRG
) {
841 ctx
->sysreg
= syscon_regmap_lookup_by_phandle(dev
->of_node
,
842 "samsung,disp-sysreg");
843 if (IS_ERR(ctx
->sysreg
)) {
844 dev_err(dev
, "failed to get system register\n");
845 return PTR_ERR(ctx
->sysreg
);
849 platform_set_drvdata(pdev
, ctx
);
851 pm_runtime_enable(dev
);
853 ret
= component_add(dev
, &decon_component_ops
);
855 goto err_disable_pm_runtime
;
859 err_disable_pm_runtime
:
860 pm_runtime_disable(dev
);
865 static void exynos5433_decon_remove(struct platform_device
*pdev
)
867 pm_runtime_disable(&pdev
->dev
);
869 component_del(&pdev
->dev
, &decon_component_ops
);
872 struct platform_driver exynos5433_decon_driver
= {
873 .probe
= exynos5433_decon_probe
,
874 .remove
= exynos5433_decon_remove
,
876 .name
= "exynos5433-decon",
877 .pm
= pm_ptr(&exynos5433_decon_pm_ops
),
878 .of_match_table
= exynos5433_decon_driver_dt_match
,