1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
4 * Copyright (C) 2013 Red Hat
5 * Author: Rob Clark <robdclark@gmail.com>
8 #include <linux/sort.h>
10 #include <drm/drm_mode.h>
11 #include <drm/drm_crtc.h>
12 #include <drm/drm_flip_work.h>
13 #include <drm/drm_fourcc.h>
14 #include <drm/drm_probe_helper.h>
15 #include <drm/drm_vblank.h>
19 #define CURSOR_WIDTH 64
20 #define CURSOR_HEIGHT 64
27 spinlock_t lm_lock
; /* protect REG_MDP5_LM_* registers */
29 /* if there is a pending flip, these will be non-null: */
30 struct drm_pending_vblank_event
*event
;
32 /* Bits have been flushed at the last commit,
33 * used to decide if a vsync has happened since last commit.
37 #define PENDING_CURSOR 0x1
38 #define PENDING_FLIP 0x2
41 /* for unref'ing cursor bo's after scanout completes: */
42 struct drm_flip_work unref_cursor_work
;
44 struct mdp_irq vblank
;
46 struct mdp_irq pp_done
;
48 struct completion pp_completion
;
50 bool lm_cursor_enabled
;
53 /* protect REG_MDP5_LM_CURSOR* registers and cursor scanout_bo*/
56 /* current cursor being scanned out: */
57 struct drm_gem_object
*scanout_bo
;
59 uint32_t width
, height
;
63 #define to_mdp5_crtc(x) container_of(x, struct mdp5_crtc, base)
65 static void mdp5_crtc_restore_cursor(struct drm_crtc
*crtc
);
67 static struct mdp5_kms
*get_kms(struct drm_crtc
*crtc
)
69 struct msm_drm_private
*priv
= crtc
->dev
->dev_private
;
70 return to_mdp5_kms(to_mdp_kms(priv
->kms
));
73 static void request_pending(struct drm_crtc
*crtc
, uint32_t pending
)
75 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
77 atomic_or(pending
, &mdp5_crtc
->pending
);
78 mdp_irq_register(&get_kms(crtc
)->base
, &mdp5_crtc
->vblank
);
81 static void request_pp_done_pending(struct drm_crtc
*crtc
)
83 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
84 reinit_completion(&mdp5_crtc
->pp_completion
);
87 static u32
crtc_flush(struct drm_crtc
*crtc
, u32 flush_mask
)
89 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
90 struct mdp5_ctl
*ctl
= mdp5_cstate
->ctl
;
91 struct mdp5_pipeline
*pipeline
= &mdp5_cstate
->pipeline
;
92 bool start
= !mdp5_cstate
->defer_start
;
94 mdp5_cstate
->defer_start
= false;
96 DBG("%s: flush=%08x", crtc
->name
, flush_mask
);
98 return mdp5_ctl_commit(ctl
, pipeline
, flush_mask
, start
);
102 * flush updates, to make sure hw is updated to new scanout fb,
103 * so that we can safely queue unref to current fb (ie. next
104 * vblank we know hw is done w/ previous scanout_fb).
106 static u32
crtc_flush_all(struct drm_crtc
*crtc
)
108 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
109 struct mdp5_hw_mixer
*mixer
, *r_mixer
;
110 struct drm_plane
*plane
;
111 uint32_t flush_mask
= 0;
113 /* this should not happen: */
114 if (WARN_ON(!mdp5_cstate
->ctl
))
117 drm_atomic_crtc_for_each_plane(plane
, crtc
) {
118 if (!plane
->state
->visible
)
120 flush_mask
|= mdp5_plane_get_flush(plane
);
123 mixer
= mdp5_cstate
->pipeline
.mixer
;
124 flush_mask
|= mdp_ctl_flush_mask_lm(mixer
->lm
);
126 r_mixer
= mdp5_cstate
->pipeline
.r_mixer
;
128 flush_mask
|= mdp_ctl_flush_mask_lm(r_mixer
->lm
);
130 return crtc_flush(crtc
, flush_mask
);
133 /* if file!=NULL, this is preclose potential cancel-flip path */
134 static void complete_flip(struct drm_crtc
*crtc
, struct drm_file
*file
)
136 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
137 struct mdp5_pipeline
*pipeline
= &mdp5_cstate
->pipeline
;
138 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
139 struct mdp5_ctl
*ctl
= mdp5_cstate
->ctl
;
140 struct drm_device
*dev
= crtc
->dev
;
141 struct drm_pending_vblank_event
*event
;
144 spin_lock_irqsave(&dev
->event_lock
, flags
);
145 event
= mdp5_crtc
->event
;
147 mdp5_crtc
->event
= NULL
;
148 DBG("%s: send event: %p", crtc
->name
, event
);
149 drm_crtc_send_vblank_event(crtc
, event
);
151 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
153 if (ctl
&& !crtc
->state
->enable
) {
154 /* set STAGE_UNUSED for all layers */
155 mdp5_ctl_blend(ctl
, pipeline
, NULL
, NULL
, 0, 0);
156 /* XXX: What to do here? */
157 /* mdp5_crtc->ctl = NULL; */
161 static void unref_cursor_worker(struct drm_flip_work
*work
, void *val
)
163 struct mdp5_crtc
*mdp5_crtc
=
164 container_of(work
, struct mdp5_crtc
, unref_cursor_work
);
165 struct mdp5_kms
*mdp5_kms
= get_kms(&mdp5_crtc
->base
);
166 struct msm_kms
*kms
= &mdp5_kms
->base
.base
;
168 msm_gem_unpin_iova(val
, kms
->aspace
);
169 drm_gem_object_put_unlocked(val
);
172 static void mdp5_crtc_destroy(struct drm_crtc
*crtc
)
174 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
176 drm_crtc_cleanup(crtc
);
177 drm_flip_work_cleanup(&mdp5_crtc
->unref_cursor_work
);
182 static inline u32
mdp5_lm_use_fg_alpha_mask(enum mdp_mixer_stage_id stage
)
185 case STAGE0
: return MDP5_LM_BLEND_COLOR_OUT_STAGE0_FG_ALPHA
;
186 case STAGE1
: return MDP5_LM_BLEND_COLOR_OUT_STAGE1_FG_ALPHA
;
187 case STAGE2
: return MDP5_LM_BLEND_COLOR_OUT_STAGE2_FG_ALPHA
;
188 case STAGE3
: return MDP5_LM_BLEND_COLOR_OUT_STAGE3_FG_ALPHA
;
189 case STAGE4
: return MDP5_LM_BLEND_COLOR_OUT_STAGE4_FG_ALPHA
;
190 case STAGE5
: return MDP5_LM_BLEND_COLOR_OUT_STAGE5_FG_ALPHA
;
191 case STAGE6
: return MDP5_LM_BLEND_COLOR_OUT_STAGE6_FG_ALPHA
;
198 * left/right pipe offsets for the stage array used in blend_setup()
204 * blend_setup() - blend all the planes of a CRTC
206 * If no base layer is available, border will be enabled as the base layer.
207 * Otherwise all layers will be blended based on their stage calculated
208 * in mdp5_crtc_atomic_check.
210 static void blend_setup(struct drm_crtc
*crtc
)
212 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
213 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
214 struct mdp5_pipeline
*pipeline
= &mdp5_cstate
->pipeline
;
215 struct mdp5_kms
*mdp5_kms
= get_kms(crtc
);
216 struct drm_plane
*plane
;
217 struct mdp5_plane_state
*pstate
, *pstates
[STAGE_MAX
+ 1] = {NULL
};
218 const struct mdp_format
*format
;
219 struct mdp5_hw_mixer
*mixer
= pipeline
->mixer
;
220 uint32_t lm
= mixer
->lm
;
221 struct mdp5_hw_mixer
*r_mixer
= pipeline
->r_mixer
;
222 uint32_t r_lm
= r_mixer
? r_mixer
->lm
: 0;
223 struct mdp5_ctl
*ctl
= mdp5_cstate
->ctl
;
224 uint32_t blend_op
, fg_alpha
, bg_alpha
, ctl_blend_flags
= 0;
226 enum mdp5_pipe stage
[STAGE_MAX
+ 1][MAX_PIPE_STAGE
] = { { SSPP_NONE
} };
227 enum mdp5_pipe r_stage
[STAGE_MAX
+ 1][MAX_PIPE_STAGE
] = { { SSPP_NONE
} };
228 int i
, plane_cnt
= 0;
229 bool bg_alpha_enabled
= false;
230 u32 mixer_op_mode
= 0;
232 #define blender(stage) ((stage) - STAGE0)
234 spin_lock_irqsave(&mdp5_crtc
->lm_lock
, flags
);
236 /* ctl could be released already when we are shutting down: */
237 /* XXX: Can this happen now? */
241 /* Collect all plane information */
242 drm_atomic_crtc_for_each_plane(plane
, crtc
) {
243 enum mdp5_pipe right_pipe
;
245 if (!plane
->state
->visible
)
248 pstate
= to_mdp5_plane_state(plane
->state
);
249 pstates
[pstate
->stage
] = pstate
;
250 stage
[pstate
->stage
][PIPE_LEFT
] = mdp5_plane_pipe(plane
);
252 * if we have a right mixer, stage the same pipe as we
253 * have on the left mixer
256 r_stage
[pstate
->stage
][PIPE_LEFT
] =
257 mdp5_plane_pipe(plane
);
259 * if we have a right pipe (i.e, the plane comprises of 2
260 * hwpipes, then stage the right pipe on the right side of both
263 right_pipe
= mdp5_plane_right_pipe(plane
);
265 stage
[pstate
->stage
][PIPE_RIGHT
] = right_pipe
;
266 r_stage
[pstate
->stage
][PIPE_RIGHT
] = right_pipe
;
272 if (!pstates
[STAGE_BASE
]) {
273 ctl_blend_flags
|= MDP5_CTL_BLEND_OP_FLAG_BORDER_OUT
;
274 DBG("Border Color is enabled");
275 } else if (plane_cnt
) {
276 format
= to_mdp_format(msm_framebuffer_format(pstates
[STAGE_BASE
]->base
.fb
));
278 if (format
->alpha_enable
)
279 bg_alpha_enabled
= true;
282 /* The reset for blending */
283 for (i
= STAGE0
; i
<= STAGE_MAX
; i
++) {
287 format
= to_mdp_format(
288 msm_framebuffer_format(pstates
[i
]->base
.fb
));
289 plane
= pstates
[i
]->base
.plane
;
290 blend_op
= MDP5_LM_BLEND_OP_MODE_FG_ALPHA(FG_CONST
) |
291 MDP5_LM_BLEND_OP_MODE_BG_ALPHA(BG_CONST
);
292 fg_alpha
= pstates
[i
]->alpha
;
293 bg_alpha
= 0xFF - pstates
[i
]->alpha
;
295 if (!format
->alpha_enable
&& bg_alpha_enabled
)
298 mixer_op_mode
|= mdp5_lm_use_fg_alpha_mask(i
);
300 DBG("Stage %d fg_alpha %x bg_alpha %x", i
, fg_alpha
, bg_alpha
);
302 if (format
->alpha_enable
&& pstates
[i
]->premultiplied
) {
303 blend_op
= MDP5_LM_BLEND_OP_MODE_FG_ALPHA(FG_CONST
) |
304 MDP5_LM_BLEND_OP_MODE_BG_ALPHA(FG_PIXEL
);
305 if (fg_alpha
!= 0xff) {
308 MDP5_LM_BLEND_OP_MODE_BG_MOD_ALPHA
|
309 MDP5_LM_BLEND_OP_MODE_BG_INV_MOD_ALPHA
;
311 blend_op
|= MDP5_LM_BLEND_OP_MODE_BG_INV_ALPHA
;
313 } else if (format
->alpha_enable
) {
314 blend_op
= MDP5_LM_BLEND_OP_MODE_FG_ALPHA(FG_PIXEL
) |
315 MDP5_LM_BLEND_OP_MODE_BG_ALPHA(FG_PIXEL
);
316 if (fg_alpha
!= 0xff) {
319 MDP5_LM_BLEND_OP_MODE_FG_MOD_ALPHA
|
320 MDP5_LM_BLEND_OP_MODE_FG_INV_MOD_ALPHA
|
321 MDP5_LM_BLEND_OP_MODE_BG_MOD_ALPHA
|
322 MDP5_LM_BLEND_OP_MODE_BG_INV_MOD_ALPHA
;
324 blend_op
|= MDP5_LM_BLEND_OP_MODE_BG_INV_ALPHA
;
328 mdp5_write(mdp5_kms
, REG_MDP5_LM_BLEND_OP_MODE(lm
,
329 blender(i
)), blend_op
);
330 mdp5_write(mdp5_kms
, REG_MDP5_LM_BLEND_FG_ALPHA(lm
,
331 blender(i
)), fg_alpha
);
332 mdp5_write(mdp5_kms
, REG_MDP5_LM_BLEND_BG_ALPHA(lm
,
333 blender(i
)), bg_alpha
);
335 mdp5_write(mdp5_kms
, REG_MDP5_LM_BLEND_OP_MODE(r_lm
,
336 blender(i
)), blend_op
);
337 mdp5_write(mdp5_kms
, REG_MDP5_LM_BLEND_FG_ALPHA(r_lm
,
338 blender(i
)), fg_alpha
);
339 mdp5_write(mdp5_kms
, REG_MDP5_LM_BLEND_BG_ALPHA(r_lm
,
340 blender(i
)), bg_alpha
);
344 val
= mdp5_read(mdp5_kms
, REG_MDP5_LM_BLEND_COLOR_OUT(lm
));
345 mdp5_write(mdp5_kms
, REG_MDP5_LM_BLEND_COLOR_OUT(lm
),
346 val
| mixer_op_mode
);
348 val
= mdp5_read(mdp5_kms
, REG_MDP5_LM_BLEND_COLOR_OUT(r_lm
));
349 mdp5_write(mdp5_kms
, REG_MDP5_LM_BLEND_COLOR_OUT(r_lm
),
350 val
| mixer_op_mode
);
353 mdp5_ctl_blend(ctl
, pipeline
, stage
, r_stage
, plane_cnt
,
356 spin_unlock_irqrestore(&mdp5_crtc
->lm_lock
, flags
);
359 static void mdp5_crtc_mode_set_nofb(struct drm_crtc
*crtc
)
361 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
362 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
363 struct mdp5_kms
*mdp5_kms
= get_kms(crtc
);
364 struct mdp5_hw_mixer
*mixer
= mdp5_cstate
->pipeline
.mixer
;
365 struct mdp5_hw_mixer
*r_mixer
= mdp5_cstate
->pipeline
.r_mixer
;
366 uint32_t lm
= mixer
->lm
;
367 u32 mixer_width
, val
;
369 struct drm_display_mode
*mode
;
371 if (WARN_ON(!crtc
->state
))
374 mode
= &crtc
->state
->adjusted_mode
;
376 DBG("%s: set mode: " DRM_MODE_FMT
, crtc
->name
, DRM_MODE_ARG(mode
));
378 mixer_width
= mode
->hdisplay
;
382 spin_lock_irqsave(&mdp5_crtc
->lm_lock
, flags
);
383 mdp5_write(mdp5_kms
, REG_MDP5_LM_OUT_SIZE(lm
),
384 MDP5_LM_OUT_SIZE_WIDTH(mixer_width
) |
385 MDP5_LM_OUT_SIZE_HEIGHT(mode
->vdisplay
));
387 /* Assign mixer to LEFT side in source split mode */
388 val
= mdp5_read(mdp5_kms
, REG_MDP5_LM_BLEND_COLOR_OUT(lm
));
389 val
&= ~MDP5_LM_BLEND_COLOR_OUT_SPLIT_LEFT_RIGHT
;
390 mdp5_write(mdp5_kms
, REG_MDP5_LM_BLEND_COLOR_OUT(lm
), val
);
393 u32 r_lm
= r_mixer
->lm
;
395 mdp5_write(mdp5_kms
, REG_MDP5_LM_OUT_SIZE(r_lm
),
396 MDP5_LM_OUT_SIZE_WIDTH(mixer_width
) |
397 MDP5_LM_OUT_SIZE_HEIGHT(mode
->vdisplay
));
399 /* Assign mixer to RIGHT side in source split mode */
400 val
= mdp5_read(mdp5_kms
, REG_MDP5_LM_BLEND_COLOR_OUT(r_lm
));
401 val
|= MDP5_LM_BLEND_COLOR_OUT_SPLIT_LEFT_RIGHT
;
402 mdp5_write(mdp5_kms
, REG_MDP5_LM_BLEND_COLOR_OUT(r_lm
), val
);
405 spin_unlock_irqrestore(&mdp5_crtc
->lm_lock
, flags
);
408 static void mdp5_crtc_atomic_disable(struct drm_crtc
*crtc
,
409 struct drm_crtc_state
*old_state
)
411 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
412 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
413 struct mdp5_kms
*mdp5_kms
= get_kms(crtc
);
414 struct device
*dev
= &mdp5_kms
->pdev
->dev
;
417 DBG("%s", crtc
->name
);
419 if (WARN_ON(!mdp5_crtc
->enabled
))
422 /* Disable/save vblank irq handling before power is disabled */
423 drm_crtc_vblank_off(crtc
);
425 if (mdp5_cstate
->cmd_mode
)
426 mdp_irq_unregister(&mdp5_kms
->base
, &mdp5_crtc
->pp_done
);
428 mdp_irq_unregister(&mdp5_kms
->base
, &mdp5_crtc
->err
);
429 pm_runtime_put_sync(dev
);
431 if (crtc
->state
->event
&& !crtc
->state
->active
) {
432 WARN_ON(mdp5_crtc
->event
);
433 spin_lock_irqsave(&mdp5_kms
->dev
->event_lock
, flags
);
434 drm_crtc_send_vblank_event(crtc
, crtc
->state
->event
);
435 crtc
->state
->event
= NULL
;
436 spin_unlock_irqrestore(&mdp5_kms
->dev
->event_lock
, flags
);
439 mdp5_crtc
->enabled
= false;
442 static void mdp5_crtc_vblank_on(struct drm_crtc
*crtc
)
444 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
445 struct mdp5_interface
*intf
= mdp5_cstate
->pipeline
.intf
;
448 count
= intf
->mode
== MDP5_INTF_DSI_MODE_COMMAND
? 0 : 0xffffffff;
449 drm_crtc_set_max_vblank_count(crtc
, count
);
451 drm_crtc_vblank_on(crtc
);
454 static void mdp5_crtc_atomic_enable(struct drm_crtc
*crtc
,
455 struct drm_crtc_state
*old_state
)
457 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
458 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
459 struct mdp5_kms
*mdp5_kms
= get_kms(crtc
);
460 struct device
*dev
= &mdp5_kms
->pdev
->dev
;
462 DBG("%s", crtc
->name
);
464 if (WARN_ON(mdp5_crtc
->enabled
))
467 pm_runtime_get_sync(dev
);
469 if (mdp5_crtc
->lm_cursor_enabled
) {
471 * Restore LM cursor state, as it might have been lost
474 if (mdp5_crtc
->cursor
.iova
) {
477 spin_lock_irqsave(&mdp5_crtc
->cursor
.lock
, flags
);
478 mdp5_crtc_restore_cursor(crtc
);
479 spin_unlock_irqrestore(&mdp5_crtc
->cursor
.lock
, flags
);
481 mdp5_ctl_set_cursor(mdp5_cstate
->ctl
,
482 &mdp5_cstate
->pipeline
, 0, true);
484 mdp5_ctl_set_cursor(mdp5_cstate
->ctl
,
485 &mdp5_cstate
->pipeline
, 0, false);
489 /* Restore vblank irq handling after power is enabled */
490 mdp5_crtc_vblank_on(crtc
);
492 mdp5_crtc_mode_set_nofb(crtc
);
494 mdp_irq_register(&mdp5_kms
->base
, &mdp5_crtc
->err
);
496 if (mdp5_cstate
->cmd_mode
)
497 mdp_irq_register(&mdp5_kms
->base
, &mdp5_crtc
->pp_done
);
499 mdp5_crtc
->enabled
= true;
502 int mdp5_crtc_setup_pipeline(struct drm_crtc
*crtc
,
503 struct drm_crtc_state
*new_crtc_state
,
504 bool need_right_mixer
)
506 struct mdp5_crtc_state
*mdp5_cstate
=
507 to_mdp5_crtc_state(new_crtc_state
);
508 struct mdp5_pipeline
*pipeline
= &mdp5_cstate
->pipeline
;
509 struct mdp5_interface
*intf
;
510 bool new_mixer
= false;
512 new_mixer
= !pipeline
->mixer
;
514 if ((need_right_mixer
&& !pipeline
->r_mixer
) ||
515 (!need_right_mixer
&& pipeline
->r_mixer
))
519 struct mdp5_hw_mixer
*old_mixer
= pipeline
->mixer
;
520 struct mdp5_hw_mixer
*old_r_mixer
= pipeline
->r_mixer
;
524 caps
= MDP_LM_CAP_DISPLAY
;
525 if (need_right_mixer
)
526 caps
|= MDP_LM_CAP_PAIR
;
528 ret
= mdp5_mixer_assign(new_crtc_state
->state
, crtc
, caps
,
529 &pipeline
->mixer
, need_right_mixer
?
530 &pipeline
->r_mixer
: NULL
);
534 mdp5_mixer_release(new_crtc_state
->state
, old_mixer
);
536 mdp5_mixer_release(new_crtc_state
->state
, old_r_mixer
);
537 if (!need_right_mixer
)
538 pipeline
->r_mixer
= NULL
;
543 * these should have been already set up in the encoder's atomic
544 * check (called by drm_atomic_helper_check_modeset)
546 intf
= pipeline
->intf
;
548 mdp5_cstate
->err_irqmask
= intf2err(intf
->num
);
549 mdp5_cstate
->vblank_irqmask
= intf2vblank(pipeline
->mixer
, intf
);
551 if ((intf
->type
== INTF_DSI
) &&
552 (intf
->mode
== MDP5_INTF_DSI_MODE_COMMAND
)) {
553 mdp5_cstate
->pp_done_irqmask
= lm2ppdone(pipeline
->mixer
);
554 mdp5_cstate
->cmd_mode
= true;
556 mdp5_cstate
->pp_done_irqmask
= 0;
557 mdp5_cstate
->cmd_mode
= false;
564 struct drm_plane
*plane
;
565 struct mdp5_plane_state
*state
;
568 static int pstate_cmp(const void *a
, const void *b
)
570 struct plane_state
*pa
= (struct plane_state
*)a
;
571 struct plane_state
*pb
= (struct plane_state
*)b
;
572 return pa
->state
->zpos
- pb
->state
->zpos
;
575 /* is there a helper for this? */
576 static bool is_fullscreen(struct drm_crtc_state
*cstate
,
577 struct drm_plane_state
*pstate
)
579 return (pstate
->crtc_x
<= 0) && (pstate
->crtc_y
<= 0) &&
580 ((pstate
->crtc_x
+ pstate
->crtc_w
) >= cstate
->mode
.hdisplay
) &&
581 ((pstate
->crtc_y
+ pstate
->crtc_h
) >= cstate
->mode
.vdisplay
);
584 static enum mdp_mixer_stage_id
get_start_stage(struct drm_crtc
*crtc
,
585 struct drm_crtc_state
*new_crtc_state
,
586 struct drm_plane_state
*bpstate
)
588 struct mdp5_crtc_state
*mdp5_cstate
=
589 to_mdp5_crtc_state(new_crtc_state
);
592 * if we're in source split mode, it's mandatory to have
593 * border out on the base stage
595 if (mdp5_cstate
->pipeline
.r_mixer
)
598 /* if the bottom-most layer is not fullscreen, we need to use
599 * it for solid-color:
601 if (!is_fullscreen(new_crtc_state
, bpstate
))
607 static int mdp5_crtc_atomic_check(struct drm_crtc
*crtc
,
608 struct drm_crtc_state
*state
)
610 struct mdp5_kms
*mdp5_kms
= get_kms(crtc
);
611 struct drm_plane
*plane
;
612 struct drm_device
*dev
= crtc
->dev
;
613 struct plane_state pstates
[STAGE_MAX
+ 1];
614 const struct mdp5_cfg_hw
*hw_cfg
;
615 const struct drm_plane_state
*pstate
;
616 const struct drm_display_mode
*mode
= &state
->adjusted_mode
;
617 bool cursor_plane
= false;
618 bool need_right_mixer
= false;
621 enum mdp_mixer_stage_id start
;
623 DBG("%s: check", crtc
->name
);
625 drm_atomic_crtc_state_for_each_plane_state(plane
, pstate
, state
) {
626 if (!pstate
->visible
)
629 pstates
[cnt
].plane
= plane
;
630 pstates
[cnt
].state
= to_mdp5_plane_state(pstate
);
633 * if any plane on this crtc uses 2 hwpipes, then we need
634 * the crtc to have a right hwmixer.
636 if (pstates
[cnt
].state
->r_hwpipe
)
637 need_right_mixer
= true;
640 if (plane
->type
== DRM_PLANE_TYPE_CURSOR
)
644 /* bail out early if there aren't any planes */
648 hw_cfg
= mdp5_cfg_get_hw_config(mdp5_kms
->cfg
);
651 * we need a right hwmixer if the mode's width is greater than a single
654 if (mode
->hdisplay
> hw_cfg
->lm
.max_width
)
655 need_right_mixer
= true;
657 ret
= mdp5_crtc_setup_pipeline(crtc
, state
, need_right_mixer
);
659 DRM_DEV_ERROR(dev
->dev
, "couldn't assign mixers %d\n", ret
);
663 /* assign a stage based on sorted zpos property */
664 sort(pstates
, cnt
, sizeof(pstates
[0]), pstate_cmp
, NULL
);
666 /* trigger a warning if cursor isn't the highest zorder */
667 WARN_ON(cursor_plane
&&
668 (pstates
[cnt
- 1].plane
->type
!= DRM_PLANE_TYPE_CURSOR
));
670 start
= get_start_stage(crtc
, state
, &pstates
[0].state
->base
);
672 /* verify that there are not too many planes attached to crtc
673 * and that we don't have conflicting mixer stages:
675 if ((cnt
+ start
- 1) >= hw_cfg
->lm
.nb_stages
) {
676 DRM_DEV_ERROR(dev
->dev
, "too many planes! cnt=%d, start stage=%d\n",
681 for (i
= 0; i
< cnt
; i
++) {
682 if (cursor_plane
&& (i
== (cnt
- 1)))
683 pstates
[i
].state
->stage
= hw_cfg
->lm
.nb_stages
;
685 pstates
[i
].state
->stage
= start
+ i
;
686 DBG("%s: assign pipe %s on stage=%d", crtc
->name
,
687 pstates
[i
].plane
->name
,
688 pstates
[i
].state
->stage
);
694 static void mdp5_crtc_atomic_begin(struct drm_crtc
*crtc
,
695 struct drm_crtc_state
*old_crtc_state
)
697 DBG("%s: begin", crtc
->name
);
700 static void mdp5_crtc_atomic_flush(struct drm_crtc
*crtc
,
701 struct drm_crtc_state
*old_crtc_state
)
703 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
704 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
705 struct drm_device
*dev
= crtc
->dev
;
708 DBG("%s: event: %p", crtc
->name
, crtc
->state
->event
);
710 WARN_ON(mdp5_crtc
->event
);
712 spin_lock_irqsave(&dev
->event_lock
, flags
);
713 mdp5_crtc
->event
= crtc
->state
->event
;
714 crtc
->state
->event
= NULL
;
715 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
718 * If no CTL has been allocated in mdp5_crtc_atomic_check(),
719 * it means we are trying to flush a CRTC whose state is disabled:
720 * nothing else needs to be done.
722 /* XXX: Can this happen now ? */
723 if (unlikely(!mdp5_cstate
->ctl
))
728 /* PP_DONE irq is only used by command mode for now.
729 * It is better to request pending before FLUSH and START trigger
730 * to make sure no pp_done irq missed.
731 * This is safe because no pp_done will happen before SW trigger
734 if (mdp5_cstate
->cmd_mode
)
735 request_pp_done_pending(crtc
);
737 mdp5_crtc
->flushed_mask
= crtc_flush_all(crtc
);
739 /* XXX are we leaking out state here? */
740 mdp5_crtc
->vblank
.irqmask
= mdp5_cstate
->vblank_irqmask
;
741 mdp5_crtc
->err
.irqmask
= mdp5_cstate
->err_irqmask
;
742 mdp5_crtc
->pp_done
.irqmask
= mdp5_cstate
->pp_done_irqmask
;
744 request_pending(crtc
, PENDING_FLIP
);
747 static void get_roi(struct drm_crtc
*crtc
, uint32_t *roi_w
, uint32_t *roi_h
)
749 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
750 uint32_t xres
= crtc
->mode
.hdisplay
;
751 uint32_t yres
= crtc
->mode
.vdisplay
;
754 * Cursor Region Of Interest (ROI) is a plane read from cursor
755 * buffer to render. The ROI region is determined by the visibility of
756 * the cursor point. In the default Cursor image the cursor point will
757 * be at the top left of the cursor image.
760 * If the cursor point reaches the right (xres - x < cursor.width) or
761 * bottom (yres - y < cursor.height) boundary of the screen, then ROI
762 * width and ROI height need to be evaluated to crop the cursor image
764 * (xres-x) will be new cursor width when x > (xres - cursor.width)
765 * (yres-y) will be new cursor height when y > (yres - cursor.height)
768 * We get negative x and/or y coordinates.
769 * (cursor.width - abs(x)) will be new cursor width when x < 0
770 * (cursor.height - abs(y)) will be new cursor width when y < 0
772 if (mdp5_crtc
->cursor
.x
>= 0)
773 *roi_w
= min(mdp5_crtc
->cursor
.width
, xres
-
774 mdp5_crtc
->cursor
.x
);
776 *roi_w
= mdp5_crtc
->cursor
.width
- abs(mdp5_crtc
->cursor
.x
);
777 if (mdp5_crtc
->cursor
.y
>= 0)
778 *roi_h
= min(mdp5_crtc
->cursor
.height
, yres
-
779 mdp5_crtc
->cursor
.y
);
781 *roi_h
= mdp5_crtc
->cursor
.height
- abs(mdp5_crtc
->cursor
.y
);
784 static void mdp5_crtc_restore_cursor(struct drm_crtc
*crtc
)
786 const struct drm_format_info
*info
= drm_format_info(DRM_FORMAT_ARGB8888
);
787 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
788 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
789 struct mdp5_kms
*mdp5_kms
= get_kms(crtc
);
790 const enum mdp5_cursor_alpha cur_alpha
= CURSOR_ALPHA_PER_PIXEL
;
791 uint32_t blendcfg
, stride
;
792 uint32_t x
, y
, src_x
, src_y
, width
, height
;
793 uint32_t roi_w
, roi_h
;
796 assert_spin_locked(&mdp5_crtc
->cursor
.lock
);
798 lm
= mdp5_cstate
->pipeline
.mixer
->lm
;
800 x
= mdp5_crtc
->cursor
.x
;
801 y
= mdp5_crtc
->cursor
.y
;
802 width
= mdp5_crtc
->cursor
.width
;
803 height
= mdp5_crtc
->cursor
.height
;
805 stride
= width
* info
->cpp
[0];
807 get_roi(crtc
, &roi_w
, &roi_h
);
809 /* If cusror buffer overlaps due to rotation on the
810 * upper or left screen border the pixel offset inside
811 * the cursor buffer of the ROI is the positive overlap
814 if (mdp5_crtc
->cursor
.x
< 0) {
815 src_x
= abs(mdp5_crtc
->cursor
.x
);
820 if (mdp5_crtc
->cursor
.y
< 0) {
821 src_y
= abs(mdp5_crtc
->cursor
.y
);
826 DBG("%s: x=%d, y=%d roi_w=%d roi_h=%d src_x=%d src_y=%d",
827 crtc
->name
, x
, y
, roi_w
, roi_h
, src_x
, src_y
);
829 mdp5_write(mdp5_kms
, REG_MDP5_LM_CURSOR_STRIDE(lm
), stride
);
830 mdp5_write(mdp5_kms
, REG_MDP5_LM_CURSOR_FORMAT(lm
),
831 MDP5_LM_CURSOR_FORMAT_FORMAT(CURSOR_FMT_ARGB8888
));
832 mdp5_write(mdp5_kms
, REG_MDP5_LM_CURSOR_IMG_SIZE(lm
),
833 MDP5_LM_CURSOR_IMG_SIZE_SRC_H(height
) |
834 MDP5_LM_CURSOR_IMG_SIZE_SRC_W(width
));
835 mdp5_write(mdp5_kms
, REG_MDP5_LM_CURSOR_SIZE(lm
),
836 MDP5_LM_CURSOR_SIZE_ROI_H(roi_h
) |
837 MDP5_LM_CURSOR_SIZE_ROI_W(roi_w
));
838 mdp5_write(mdp5_kms
, REG_MDP5_LM_CURSOR_START_XY(lm
),
839 MDP5_LM_CURSOR_START_XY_Y_START(y
) |
840 MDP5_LM_CURSOR_START_XY_X_START(x
));
841 mdp5_write(mdp5_kms
, REG_MDP5_LM_CURSOR_XY(lm
),
842 MDP5_LM_CURSOR_XY_SRC_Y(src_y
) |
843 MDP5_LM_CURSOR_XY_SRC_X(src_x
));
844 mdp5_write(mdp5_kms
, REG_MDP5_LM_CURSOR_BASE_ADDR(lm
),
845 mdp5_crtc
->cursor
.iova
);
847 blendcfg
= MDP5_LM_CURSOR_BLEND_CONFIG_BLEND_EN
;
848 blendcfg
|= MDP5_LM_CURSOR_BLEND_CONFIG_BLEND_ALPHA_SEL(cur_alpha
);
849 mdp5_write(mdp5_kms
, REG_MDP5_LM_CURSOR_BLEND_CONFIG(lm
), blendcfg
);
852 static int mdp5_crtc_cursor_set(struct drm_crtc
*crtc
,
853 struct drm_file
*file
, uint32_t handle
,
854 uint32_t width
, uint32_t height
)
856 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
857 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
858 struct mdp5_pipeline
*pipeline
= &mdp5_cstate
->pipeline
;
859 struct drm_device
*dev
= crtc
->dev
;
860 struct mdp5_kms
*mdp5_kms
= get_kms(crtc
);
861 struct platform_device
*pdev
= mdp5_kms
->pdev
;
862 struct msm_kms
*kms
= &mdp5_kms
->base
.base
;
863 struct drm_gem_object
*cursor_bo
, *old_bo
= NULL
;
864 struct mdp5_ctl
*ctl
;
866 uint32_t flush_mask
= mdp_ctl_flush_mask_cursor(0);
867 bool cursor_enable
= true;
870 if (!mdp5_crtc
->lm_cursor_enabled
) {
872 "cursor_set is deprecated with cursor planes\n");
876 if ((width
> CURSOR_WIDTH
) || (height
> CURSOR_HEIGHT
)) {
877 DRM_DEV_ERROR(dev
->dev
, "bad cursor size: %dx%d\n", width
, height
);
881 ctl
= mdp5_cstate
->ctl
;
885 /* don't support LM cursors when we we have source split enabled */
886 if (mdp5_cstate
->pipeline
.r_mixer
)
891 cursor_enable
= false;
892 mdp5_crtc
->cursor
.iova
= 0;
893 pm_runtime_get_sync(&pdev
->dev
);
897 cursor_bo
= drm_gem_object_lookup(file
, handle
);
901 ret
= msm_gem_get_and_pin_iova(cursor_bo
, kms
->aspace
,
902 &mdp5_crtc
->cursor
.iova
);
906 pm_runtime_get_sync(&pdev
->dev
);
908 spin_lock_irqsave(&mdp5_crtc
->cursor
.lock
, flags
);
909 old_bo
= mdp5_crtc
->cursor
.scanout_bo
;
911 mdp5_crtc
->cursor
.scanout_bo
= cursor_bo
;
912 mdp5_crtc
->cursor
.width
= width
;
913 mdp5_crtc
->cursor
.height
= height
;
915 mdp5_crtc_restore_cursor(crtc
);
917 spin_unlock_irqrestore(&mdp5_crtc
->cursor
.lock
, flags
);
920 ret
= mdp5_ctl_set_cursor(ctl
, pipeline
, 0, cursor_enable
);
922 DRM_DEV_ERROR(dev
->dev
, "failed to %sable cursor: %d\n",
923 cursor_enable
? "en" : "dis", ret
);
927 crtc_flush(crtc
, flush_mask
);
930 pm_runtime_put_sync(&pdev
->dev
);
932 drm_flip_work_queue(&mdp5_crtc
->unref_cursor_work
, old_bo
);
933 /* enable vblank to complete cursor work: */
934 request_pending(crtc
, PENDING_CURSOR
);
939 static int mdp5_crtc_cursor_move(struct drm_crtc
*crtc
, int x
, int y
)
941 struct mdp5_kms
*mdp5_kms
= get_kms(crtc
);
942 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
943 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
944 uint32_t flush_mask
= mdp_ctl_flush_mask_cursor(0);
945 struct drm_device
*dev
= crtc
->dev
;
950 if (!mdp5_crtc
->lm_cursor_enabled
) {
952 "cursor_move is deprecated with cursor planes\n");
956 /* don't support LM cursors when we we have source split enabled */
957 if (mdp5_cstate
->pipeline
.r_mixer
)
960 /* In case the CRTC is disabled, just drop the cursor update */
961 if (unlikely(!crtc
->state
->enable
))
964 /* accept negative x/y coordinates up to maximum cursor overlap */
965 mdp5_crtc
->cursor
.x
= x
= max(x
, -(int)mdp5_crtc
->cursor
.width
);
966 mdp5_crtc
->cursor
.y
= y
= max(y
, -(int)mdp5_crtc
->cursor
.height
);
968 get_roi(crtc
, &roi_w
, &roi_h
);
970 pm_runtime_get_sync(&mdp5_kms
->pdev
->dev
);
972 spin_lock_irqsave(&mdp5_crtc
->cursor
.lock
, flags
);
973 mdp5_crtc_restore_cursor(crtc
);
974 spin_unlock_irqrestore(&mdp5_crtc
->cursor
.lock
, flags
);
976 crtc_flush(crtc
, flush_mask
);
978 pm_runtime_put_sync(&mdp5_kms
->pdev
->dev
);
984 mdp5_crtc_atomic_print_state(struct drm_printer
*p
,
985 const struct drm_crtc_state
*state
)
987 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(state
);
988 struct mdp5_pipeline
*pipeline
= &mdp5_cstate
->pipeline
;
989 struct mdp5_kms
*mdp5_kms
= get_kms(state
->crtc
);
991 if (WARN_ON(!pipeline
))
994 if (mdp5_cstate
->ctl
)
995 drm_printf(p
, "\tctl=%d\n", mdp5_ctl_get_ctl_id(mdp5_cstate
->ctl
));
997 drm_printf(p
, "\thwmixer=%s\n", pipeline
->mixer
?
998 pipeline
->mixer
->name
: "(null)");
1000 if (mdp5_kms
->caps
& MDP_CAP_SRC_SPLIT
)
1001 drm_printf(p
, "\tright hwmixer=%s\n", pipeline
->r_mixer
?
1002 pipeline
->r_mixer
->name
: "(null)");
1004 drm_printf(p
, "\tcmd_mode=%d\n", mdp5_cstate
->cmd_mode
);
1007 static struct drm_crtc_state
*
1008 mdp5_crtc_duplicate_state(struct drm_crtc
*crtc
)
1010 struct mdp5_crtc_state
*mdp5_cstate
;
1012 if (WARN_ON(!crtc
->state
))
1015 mdp5_cstate
= kmemdup(to_mdp5_crtc_state(crtc
->state
),
1016 sizeof(*mdp5_cstate
), GFP_KERNEL
);
1020 __drm_atomic_helper_crtc_duplicate_state(crtc
, &mdp5_cstate
->base
);
1022 return &mdp5_cstate
->base
;
1025 static void mdp5_crtc_destroy_state(struct drm_crtc
*crtc
, struct drm_crtc_state
*state
)
1027 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(state
);
1029 __drm_atomic_helper_crtc_destroy_state(state
);
1034 static void mdp5_crtc_reset(struct drm_crtc
*crtc
)
1036 struct mdp5_crtc_state
*mdp5_cstate
=
1037 kzalloc(sizeof(*mdp5_cstate
), GFP_KERNEL
);
1040 mdp5_crtc_destroy_state(crtc
, crtc
->state
);
1042 __drm_atomic_helper_crtc_reset(crtc
, &mdp5_cstate
->base
);
1044 drm_crtc_vblank_reset(crtc
);
1047 static const struct drm_crtc_funcs mdp5_crtc_funcs
= {
1048 .set_config
= drm_atomic_helper_set_config
,
1049 .destroy
= mdp5_crtc_destroy
,
1050 .page_flip
= drm_atomic_helper_page_flip
,
1051 .reset
= mdp5_crtc_reset
,
1052 .atomic_duplicate_state
= mdp5_crtc_duplicate_state
,
1053 .atomic_destroy_state
= mdp5_crtc_destroy_state
,
1054 .cursor_set
= mdp5_crtc_cursor_set
,
1055 .cursor_move
= mdp5_crtc_cursor_move
,
1056 .atomic_print_state
= mdp5_crtc_atomic_print_state
,
1059 static const struct drm_crtc_helper_funcs mdp5_crtc_helper_funcs
= {
1060 .mode_set_nofb
= mdp5_crtc_mode_set_nofb
,
1061 .atomic_check
= mdp5_crtc_atomic_check
,
1062 .atomic_begin
= mdp5_crtc_atomic_begin
,
1063 .atomic_flush
= mdp5_crtc_atomic_flush
,
1064 .atomic_enable
= mdp5_crtc_atomic_enable
,
1065 .atomic_disable
= mdp5_crtc_atomic_disable
,
1068 static void mdp5_crtc_vblank_irq(struct mdp_irq
*irq
, uint32_t irqstatus
)
1070 struct mdp5_crtc
*mdp5_crtc
= container_of(irq
, struct mdp5_crtc
, vblank
);
1071 struct drm_crtc
*crtc
= &mdp5_crtc
->base
;
1072 struct msm_drm_private
*priv
= crtc
->dev
->dev_private
;
1075 mdp_irq_unregister(&get_kms(crtc
)->base
, &mdp5_crtc
->vblank
);
1077 pending
= atomic_xchg(&mdp5_crtc
->pending
, 0);
1079 if (pending
& PENDING_FLIP
) {
1080 complete_flip(crtc
, NULL
);
1083 if (pending
& PENDING_CURSOR
)
1084 drm_flip_work_commit(&mdp5_crtc
->unref_cursor_work
, priv
->wq
);
1087 static void mdp5_crtc_err_irq(struct mdp_irq
*irq
, uint32_t irqstatus
)
1089 struct mdp5_crtc
*mdp5_crtc
= container_of(irq
, struct mdp5_crtc
, err
);
1091 DBG("%s: error: %08x", mdp5_crtc
->base
.name
, irqstatus
);
1094 static void mdp5_crtc_pp_done_irq(struct mdp_irq
*irq
, uint32_t irqstatus
)
1096 struct mdp5_crtc
*mdp5_crtc
= container_of(irq
, struct mdp5_crtc
,
1099 complete(&mdp5_crtc
->pp_completion
);
1102 static void mdp5_crtc_wait_for_pp_done(struct drm_crtc
*crtc
)
1104 struct drm_device
*dev
= crtc
->dev
;
1105 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
1106 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
1109 ret
= wait_for_completion_timeout(&mdp5_crtc
->pp_completion
,
1110 msecs_to_jiffies(50));
1112 dev_warn(dev
->dev
, "pp done time out, lm=%d\n",
1113 mdp5_cstate
->pipeline
.mixer
->lm
);
1116 static void mdp5_crtc_wait_for_flush_done(struct drm_crtc
*crtc
)
1118 struct drm_device
*dev
= crtc
->dev
;
1119 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
1120 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
1121 struct mdp5_ctl
*ctl
= mdp5_cstate
->ctl
;
1124 /* Should not call this function if crtc is disabled. */
1128 ret
= drm_crtc_vblank_get(crtc
);
1132 ret
= wait_event_timeout(dev
->vblank
[drm_crtc_index(crtc
)].queue
,
1133 ((mdp5_ctl_get_commit_status(ctl
) &
1134 mdp5_crtc
->flushed_mask
) == 0),
1135 msecs_to_jiffies(50));
1137 dev_warn(dev
->dev
, "vblank time out, crtc=%d\n", mdp5_crtc
->id
);
1139 mdp5_crtc
->flushed_mask
= 0;
1141 drm_crtc_vblank_put(crtc
);
1144 uint32_t mdp5_crtc_vblank(struct drm_crtc
*crtc
)
1146 struct mdp5_crtc
*mdp5_crtc
= to_mdp5_crtc(crtc
);
1147 return mdp5_crtc
->vblank
.irqmask
;
1150 void mdp5_crtc_set_pipeline(struct drm_crtc
*crtc
)
1152 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
1153 struct mdp5_kms
*mdp5_kms
= get_kms(crtc
);
1155 /* should this be done elsewhere ? */
1156 mdp_irq_update(&mdp5_kms
->base
);
1158 mdp5_ctl_set_pipeline(mdp5_cstate
->ctl
, &mdp5_cstate
->pipeline
);
1161 struct mdp5_ctl
*mdp5_crtc_get_ctl(struct drm_crtc
*crtc
)
1163 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
1165 return mdp5_cstate
->ctl
;
1168 struct mdp5_hw_mixer
*mdp5_crtc_get_mixer(struct drm_crtc
*crtc
)
1170 struct mdp5_crtc_state
*mdp5_cstate
;
1173 return ERR_PTR(-EINVAL
);
1175 mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
1177 return WARN_ON(!mdp5_cstate
->pipeline
.mixer
) ?
1178 ERR_PTR(-EINVAL
) : mdp5_cstate
->pipeline
.mixer
;
1181 struct mdp5_pipeline
*mdp5_crtc_get_pipeline(struct drm_crtc
*crtc
)
1183 struct mdp5_crtc_state
*mdp5_cstate
;
1186 return ERR_PTR(-EINVAL
);
1188 mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
1190 return &mdp5_cstate
->pipeline
;
1193 void mdp5_crtc_wait_for_commit_done(struct drm_crtc
*crtc
)
1195 struct mdp5_crtc_state
*mdp5_cstate
= to_mdp5_crtc_state(crtc
->state
);
1197 if (mdp5_cstate
->cmd_mode
)
1198 mdp5_crtc_wait_for_pp_done(crtc
);
1200 mdp5_crtc_wait_for_flush_done(crtc
);
1203 /* initialize crtc */
1204 struct drm_crtc
*mdp5_crtc_init(struct drm_device
*dev
,
1205 struct drm_plane
*plane
,
1206 struct drm_plane
*cursor_plane
, int id
)
1208 struct drm_crtc
*crtc
= NULL
;
1209 struct mdp5_crtc
*mdp5_crtc
;
1211 mdp5_crtc
= kzalloc(sizeof(*mdp5_crtc
), GFP_KERNEL
);
1213 return ERR_PTR(-ENOMEM
);
1215 crtc
= &mdp5_crtc
->base
;
1219 spin_lock_init(&mdp5_crtc
->lm_lock
);
1220 spin_lock_init(&mdp5_crtc
->cursor
.lock
);
1221 init_completion(&mdp5_crtc
->pp_completion
);
1223 mdp5_crtc
->vblank
.irq
= mdp5_crtc_vblank_irq
;
1224 mdp5_crtc
->err
.irq
= mdp5_crtc_err_irq
;
1225 mdp5_crtc
->pp_done
.irq
= mdp5_crtc_pp_done_irq
;
1227 mdp5_crtc
->lm_cursor_enabled
= cursor_plane
? false : true;
1229 drm_crtc_init_with_planes(dev
, crtc
, plane
, cursor_plane
,
1230 &mdp5_crtc_funcs
, NULL
);
1232 drm_flip_work_init(&mdp5_crtc
->unref_cursor_work
,
1233 "unref cursor", unref_cursor_worker
);
1235 drm_crtc_helper_add(crtc
, &mdp5_crtc_helper_funcs
);