1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014-2018 The Linux Foundation. All rights reserved.
4 * Copyright (C) 2013 Red Hat
5 * Author: Rob Clark <robdclark@gmail.com>
8 #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
9 #include <linux/sort.h>
10 #include <linux/debugfs.h>
11 #include <linux/ktime.h>
12 #include <linux/bits.h>
14 #include <drm/drm_atomic.h>
15 #include <drm/drm_crtc.h>
16 #include <drm/drm_flip_work.h>
17 #include <drm/drm_mode.h>
18 #include <drm/drm_probe_helper.h>
19 #include <drm/drm_rect.h>
20 #include <drm/drm_vblank.h>
23 #include "dpu_hw_lm.h"
24 #include "dpu_hw_ctl.h"
25 #include "dpu_hw_dspp.h"
27 #include "dpu_plane.h"
28 #include "dpu_encoder.h"
30 #include "dpu_core_perf.h"
31 #include "dpu_trace.h"
33 /* layer mixer index on dpu_crtc */
37 /* timeout in ms waiting for frame done */
38 #define DPU_CRTC_FRAME_DONE_TIMEOUT_MS 60
40 #define CONVERT_S3_15(val) \
41 (((((u64)val) & ~BIT_ULL(63)) >> 17) & GENMASK_ULL(17, 0))
43 static struct dpu_kms *_dpu_crtc_get_kms(struct drm_crtc *crtc)
45 struct msm_drm_private *priv = crtc->dev->dev_private;
47 return to_dpu_kms(priv->kms);
50 static void dpu_crtc_destroy(struct drm_crtc *crtc)
52 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
57 drm_crtc_cleanup(crtc);
61 static struct drm_encoder *get_encoder_from_crtc(struct drm_crtc *crtc)
63 struct drm_device *dev = crtc->dev;
64 struct drm_encoder *encoder;
66 drm_for_each_encoder(encoder, dev)
67 if (encoder->crtc == crtc)
73 static u32 dpu_crtc_get_vblank_counter(struct drm_crtc *crtc)
75 struct drm_encoder *encoder;
77 encoder = get_encoder_from_crtc(crtc);
79 DRM_ERROR("no encoder found for crtc %d\n", crtc->index);
83 return dpu_encoder_get_frame_count(encoder);
86 static bool dpu_crtc_get_scanout_position(struct drm_crtc *crtc,
89 ktime_t *stime, ktime_t *etime,
90 const struct drm_display_mode *mode)
92 unsigned int pipe = crtc->index;
93 struct drm_encoder *encoder;
94 int line, vsw, vbp, vactive_start, vactive_end, vfp_end;
96 encoder = get_encoder_from_crtc(crtc);
98 DRM_ERROR("no encoder found for crtc %d\n", pipe);
102 vsw = mode->crtc_vsync_end - mode->crtc_vsync_start;
103 vbp = mode->crtc_vtotal - mode->crtc_vsync_end;
106 * the line counter is 1 at the start of the VSYNC pulse and VTOTAL at
107 * the end of VFP. Translate the porch values relative to the line
111 vactive_start = vsw + vbp + 1;
112 vactive_end = vactive_start + mode->crtc_vdisplay;
114 /* last scan line before VSYNC */
115 vfp_end = mode->crtc_vtotal;
118 *stime = ktime_get();
120 line = dpu_encoder_get_linecount(encoder);
122 if (line < vactive_start)
123 line -= vactive_start;
124 else if (line > vactive_end)
125 line = line - vfp_end - vactive_start;
127 line -= vactive_start;
133 *etime = ktime_get();
138 static void _dpu_crtc_setup_blend_cfg(struct dpu_crtc_mixer *mixer,
139 struct dpu_plane_state *pstate, struct dpu_format *format)
141 struct dpu_hw_mixer *lm = mixer->hw_lm;
143 uint32_t fg_alpha, bg_alpha;
145 fg_alpha = pstate->base.alpha >> 8;
146 bg_alpha = 0xff - fg_alpha;
148 /* default to opaque blending */
149 if (pstate->base.pixel_blend_mode == DRM_MODE_BLEND_PIXEL_NONE ||
150 !format->alpha_enable) {
151 blend_op = DPU_BLEND_FG_ALPHA_FG_CONST |
152 DPU_BLEND_BG_ALPHA_BG_CONST;
153 } else if (pstate->base.pixel_blend_mode == DRM_MODE_BLEND_PREMULTI) {
154 blend_op = DPU_BLEND_FG_ALPHA_FG_CONST |
155 DPU_BLEND_BG_ALPHA_FG_PIXEL;
156 if (fg_alpha != 0xff) {
158 blend_op |= DPU_BLEND_BG_MOD_ALPHA |
159 DPU_BLEND_BG_INV_MOD_ALPHA;
161 blend_op |= DPU_BLEND_BG_INV_ALPHA;
164 /* coverage blending */
165 blend_op = DPU_BLEND_FG_ALPHA_FG_PIXEL |
166 DPU_BLEND_BG_ALPHA_FG_PIXEL;
167 if (fg_alpha != 0xff) {
169 blend_op |= DPU_BLEND_FG_MOD_ALPHA |
170 DPU_BLEND_FG_INV_MOD_ALPHA |
171 DPU_BLEND_BG_MOD_ALPHA |
172 DPU_BLEND_BG_INV_MOD_ALPHA;
174 blend_op |= DPU_BLEND_BG_INV_ALPHA;
178 lm->ops.setup_blend_config(lm, pstate->stage,
179 fg_alpha, bg_alpha, blend_op);
181 DRM_DEBUG_ATOMIC("format:%p4cc, alpha_en:%u blend_op:0x%x\n",
182 &format->base.pixel_format, format->alpha_enable, blend_op);
185 static void _dpu_crtc_program_lm_output_roi(struct drm_crtc *crtc)
187 struct dpu_crtc_state *crtc_state;
188 int lm_idx, lm_horiz_position;
190 crtc_state = to_dpu_crtc_state(crtc->state);
192 lm_horiz_position = 0;
193 for (lm_idx = 0; lm_idx < crtc_state->num_mixers; lm_idx++) {
194 const struct drm_rect *lm_roi = &crtc_state->lm_bounds[lm_idx];
195 struct dpu_hw_mixer *hw_lm = crtc_state->mixers[lm_idx].hw_lm;
196 struct dpu_hw_mixer_cfg cfg;
198 if (!lm_roi || !drm_rect_visible(lm_roi))
201 cfg.out_width = drm_rect_width(lm_roi);
202 cfg.out_height = drm_rect_height(lm_roi);
203 cfg.right_mixer = lm_horiz_position++;
205 hw_lm->ops.setup_mixer_out(hw_lm, &cfg);
209 static void _dpu_crtc_blend_setup_mixer(struct drm_crtc *crtc,
210 struct dpu_crtc *dpu_crtc, struct dpu_crtc_mixer *mixer)
212 struct drm_plane *plane;
213 struct drm_framebuffer *fb;
214 struct drm_plane_state *state;
215 struct dpu_crtc_state *cstate = to_dpu_crtc_state(crtc->state);
216 struct dpu_plane_state *pstate = NULL;
217 struct dpu_format *format;
218 struct dpu_hw_ctl *ctl = mixer->lm_ctl;
219 struct dpu_hw_stage_cfg *stage_cfg = &dpu_crtc->stage_cfg;
222 uint32_t stage_idx, lm_idx;
223 int zpos_cnt[DPU_STAGE_MAX + 1] = { 0 };
224 bool bg_alpha_enable = false;
225 DECLARE_BITMAP(fetch_active, SSPP_MAX);
227 memset(fetch_active, 0, sizeof(fetch_active));
228 drm_atomic_crtc_for_each_plane(plane, crtc) {
229 state = plane->state;
233 pstate = to_dpu_plane_state(state);
236 dpu_plane_get_ctl_flush(plane, ctl, &flush_mask);
237 set_bit(dpu_plane_pipe(plane), fetch_active);
239 DRM_DEBUG_ATOMIC("crtc %d stage:%d - plane %d sspp %d fb %d\n",
243 dpu_plane_pipe(plane) - SSPP_VIG0,
244 state->fb ? state->fb->base.id : -1);
246 format = to_dpu_format(msm_framebuffer_format(pstate->base.fb));
248 if (pstate->stage == DPU_STAGE_BASE && format->alpha_enable)
249 bg_alpha_enable = true;
251 stage_idx = zpos_cnt[pstate->stage]++;
252 stage_cfg->stage[pstate->stage][stage_idx] =
253 dpu_plane_pipe(plane);
254 stage_cfg->multirect_index[pstate->stage][stage_idx] =
255 pstate->multirect_index;
257 trace_dpu_crtc_setup_mixer(DRMID(crtc), DRMID(plane),
258 state, pstate, stage_idx,
259 dpu_plane_pipe(plane) - SSPP_VIG0,
260 format->base.pixel_format,
261 fb ? fb->modifier : 0);
263 /* blend config update */
264 for (lm_idx = 0; lm_idx < cstate->num_mixers; lm_idx++) {
265 _dpu_crtc_setup_blend_cfg(mixer + lm_idx,
268 mixer[lm_idx].flush_mask |= flush_mask;
270 if (bg_alpha_enable && !format->alpha_enable)
271 mixer[lm_idx].mixer_op_mode = 0;
273 mixer[lm_idx].mixer_op_mode |=
278 if (ctl->ops.set_active_pipes)
279 ctl->ops.set_active_pipes(ctl, fetch_active);
281 _dpu_crtc_program_lm_output_roi(crtc);
285 * _dpu_crtc_blend_setup - configure crtc mixers
286 * @crtc: Pointer to drm crtc structure
288 static void _dpu_crtc_blend_setup(struct drm_crtc *crtc)
290 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
291 struct dpu_crtc_state *cstate = to_dpu_crtc_state(crtc->state);
292 struct dpu_crtc_mixer *mixer = cstate->mixers;
293 struct dpu_hw_ctl *ctl;
294 struct dpu_hw_mixer *lm;
297 DRM_DEBUG_ATOMIC("%s\n", dpu_crtc->name);
299 for (i = 0; i < cstate->num_mixers; i++) {
300 mixer[i].mixer_op_mode = 0;
301 mixer[i].flush_mask = 0;
302 if (mixer[i].lm_ctl->ops.clear_all_blendstages)
303 mixer[i].lm_ctl->ops.clear_all_blendstages(
307 /* initialize stage cfg */
308 memset(&dpu_crtc->stage_cfg, 0, sizeof(struct dpu_hw_stage_cfg));
310 _dpu_crtc_blend_setup_mixer(crtc, dpu_crtc, mixer);
312 for (i = 0; i < cstate->num_mixers; i++) {
313 ctl = mixer[i].lm_ctl;
316 lm->ops.setup_alpha_out(lm, mixer[i].mixer_op_mode);
318 mixer[i].flush_mask |= ctl->ops.get_bitmask_mixer(ctl,
319 mixer[i].hw_lm->idx);
321 /* stage config flush mask */
322 ctl->ops.update_pending_flush(ctl, mixer[i].flush_mask);
324 DRM_DEBUG_ATOMIC("lm %d, op_mode 0x%X, ctl %d, flush mask 0x%x\n",
325 mixer[i].hw_lm->idx - LM_0,
326 mixer[i].mixer_op_mode,
328 mixer[i].flush_mask);
330 ctl->ops.setup_blendstage(ctl, mixer[i].hw_lm->idx,
331 &dpu_crtc->stage_cfg);
336 * _dpu_crtc_complete_flip - signal pending page_flip events
337 * Any pending vblank events are added to the vblank_event_list
338 * so that the next vblank interrupt shall signal them.
339 * However PAGE_FLIP events are not handled through the vblank_event_list.
340 * This API signals any pending PAGE_FLIP events requested through
341 * DRM_IOCTL_MODE_PAGE_FLIP and are cached in the dpu_crtc->event.
342 * @crtc: Pointer to drm crtc structure
344 static void _dpu_crtc_complete_flip(struct drm_crtc *crtc)
346 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
347 struct drm_device *dev = crtc->dev;
350 spin_lock_irqsave(&dev->event_lock, flags);
351 if (dpu_crtc->event) {
352 DRM_DEBUG_VBL("%s: send event: %pK\n", dpu_crtc->name,
354 trace_dpu_crtc_complete_flip(DRMID(crtc));
355 drm_crtc_send_vblank_event(crtc, dpu_crtc->event);
356 dpu_crtc->event = NULL;
358 spin_unlock_irqrestore(&dev->event_lock, flags);
361 enum dpu_intf_mode dpu_crtc_get_intf_mode(struct drm_crtc *crtc)
363 struct drm_encoder *encoder;
366 * TODO: This function is called from dpu debugfs and as part of atomic
367 * check. When called from debugfs, the crtc->mutex must be held to
368 * read crtc->state. However reading crtc->state from atomic check isn't
369 * allowed (unless you have a good reason, a big comment, and a deep
370 * understanding of how the atomic/modeset locks work (<- and this is
371 * probably not possible)). So we'll keep the WARN_ON here for now, but
372 * really we need to figure out a better way to track our operating mode
374 WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
376 /* TODO: Returns the first INTF_MODE, could there be multiple values? */
377 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask)
378 return dpu_encoder_get_intf_mode(encoder);
380 return INTF_MODE_NONE;
383 void dpu_crtc_vblank_callback(struct drm_crtc *crtc)
385 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
387 /* keep statistics on vblank callback - with auto reset via debugfs */
388 if (ktime_compare(dpu_crtc->vblank_cb_time, ktime_set(0, 0)) == 0)
389 dpu_crtc->vblank_cb_time = ktime_get();
391 dpu_crtc->vblank_cb_count++;
392 drm_crtc_handle_vblank(crtc);
393 trace_dpu_crtc_vblank_cb(DRMID(crtc));
396 static void dpu_crtc_frame_event_work(struct kthread_work *work)
398 struct dpu_crtc_frame_event *fevent = container_of(work,
399 struct dpu_crtc_frame_event, work);
400 struct drm_crtc *crtc = fevent->crtc;
401 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
403 bool frame_done = false;
405 DPU_ATRACE_BEGIN("crtc_frame_event");
407 DRM_DEBUG_ATOMIC("crtc%d event:%u ts:%lld\n", crtc->base.id, fevent->event,
408 ktime_to_ns(fevent->ts));
410 if (fevent->event & (DPU_ENCODER_FRAME_EVENT_DONE
411 | DPU_ENCODER_FRAME_EVENT_ERROR
412 | DPU_ENCODER_FRAME_EVENT_PANEL_DEAD)) {
414 if (atomic_read(&dpu_crtc->frame_pending) < 1) {
415 /* ignore vblank when not pending */
416 } else if (atomic_dec_return(&dpu_crtc->frame_pending) == 0) {
417 /* release bandwidth and other resources */
418 trace_dpu_crtc_frame_event_done(DRMID(crtc),
420 dpu_core_perf_crtc_release_bw(crtc);
422 trace_dpu_crtc_frame_event_more_pending(DRMID(crtc),
426 if (fevent->event & (DPU_ENCODER_FRAME_EVENT_DONE
427 | DPU_ENCODER_FRAME_EVENT_ERROR))
431 if (fevent->event & DPU_ENCODER_FRAME_EVENT_PANEL_DEAD)
432 DPU_ERROR("crtc%d ts:%lld received panel dead event\n",
433 crtc->base.id, ktime_to_ns(fevent->ts));
436 complete_all(&dpu_crtc->frame_done_comp);
438 spin_lock_irqsave(&dpu_crtc->spin_lock, flags);
439 list_add_tail(&fevent->list, &dpu_crtc->frame_event_list);
440 spin_unlock_irqrestore(&dpu_crtc->spin_lock, flags);
441 DPU_ATRACE_END("crtc_frame_event");
445 * dpu_crtc_frame_event_cb - crtc frame event callback API. CRTC module
446 * registers this API to encoder for all frame event callbacks like
447 * frame_error, frame_done, idle_timeout, etc. Encoder may call different events
448 * from different context - IRQ, user thread, commit_thread, etc. Each event
449 * should be carefully reviewed and should be processed in proper task context
450 * to avoid schedulin delay or properly manage the irq context's bottom half
453 static void dpu_crtc_frame_event_cb(void *data, u32 event)
455 struct drm_crtc *crtc = (struct drm_crtc *)data;
456 struct dpu_crtc *dpu_crtc;
457 struct msm_drm_private *priv;
458 struct dpu_crtc_frame_event *fevent;
462 /* Nothing to do on idle event */
463 if (event & DPU_ENCODER_FRAME_EVENT_IDLE)
466 dpu_crtc = to_dpu_crtc(crtc);
467 priv = crtc->dev->dev_private;
468 crtc_id = drm_crtc_index(crtc);
470 trace_dpu_crtc_frame_event_cb(DRMID(crtc), event);
472 spin_lock_irqsave(&dpu_crtc->spin_lock, flags);
473 fevent = list_first_entry_or_null(&dpu_crtc->frame_event_list,
474 struct dpu_crtc_frame_event, list);
476 list_del_init(&fevent->list);
477 spin_unlock_irqrestore(&dpu_crtc->spin_lock, flags);
480 DRM_ERROR_RATELIMITED("crtc%d event %d overflow\n", crtc->base.id, event);
484 fevent->event = event;
486 fevent->ts = ktime_get();
487 kthread_queue_work(priv->event_thread[crtc_id].worker, &fevent->work);
490 void dpu_crtc_complete_commit(struct drm_crtc *crtc)
492 trace_dpu_crtc_complete_commit(DRMID(crtc));
493 dpu_core_perf_crtc_update(crtc, 0, false);
494 _dpu_crtc_complete_flip(crtc);
497 static void _dpu_crtc_setup_lm_bounds(struct drm_crtc *crtc,
498 struct drm_crtc_state *state)
500 struct dpu_crtc_state *cstate = to_dpu_crtc_state(state);
501 struct drm_display_mode *adj_mode = &state->adjusted_mode;
502 u32 crtc_split_width = adj_mode->hdisplay / cstate->num_mixers;
505 for (i = 0; i < cstate->num_mixers; i++) {
506 struct drm_rect *r = &cstate->lm_bounds[i];
507 r->x1 = crtc_split_width * i;
509 r->x2 = r->x1 + crtc_split_width;
510 r->y2 = adj_mode->vdisplay;
512 trace_dpu_crtc_setup_lm_bounds(DRMID(crtc), i, r);
516 static void _dpu_crtc_get_pcc_coeff(struct drm_crtc_state *state,
517 struct dpu_hw_pcc_cfg *cfg)
519 struct drm_color_ctm *ctm;
521 memset(cfg, 0, sizeof(struct dpu_hw_pcc_cfg));
523 ctm = (struct drm_color_ctm *)state->ctm->data;
528 cfg->r.r = CONVERT_S3_15(ctm->matrix[0]);
529 cfg->g.r = CONVERT_S3_15(ctm->matrix[1]);
530 cfg->b.r = CONVERT_S3_15(ctm->matrix[2]);
532 cfg->r.g = CONVERT_S3_15(ctm->matrix[3]);
533 cfg->g.g = CONVERT_S3_15(ctm->matrix[4]);
534 cfg->b.g = CONVERT_S3_15(ctm->matrix[5]);
536 cfg->r.b = CONVERT_S3_15(ctm->matrix[6]);
537 cfg->g.b = CONVERT_S3_15(ctm->matrix[7]);
538 cfg->b.b = CONVERT_S3_15(ctm->matrix[8]);
541 static void _dpu_crtc_setup_cp_blocks(struct drm_crtc *crtc)
543 struct drm_crtc_state *state = crtc->state;
544 struct dpu_crtc_state *cstate = to_dpu_crtc_state(crtc->state);
545 struct dpu_crtc_mixer *mixer = cstate->mixers;
546 struct dpu_hw_pcc_cfg cfg;
547 struct dpu_hw_ctl *ctl;
548 struct dpu_hw_dspp *dspp;
552 if (!state->color_mgmt_changed)
555 for (i = 0; i < cstate->num_mixers; i++) {
556 ctl = mixer[i].lm_ctl;
557 dspp = mixer[i].hw_dspp;
559 if (!dspp || !dspp->ops.setup_pcc)
563 dspp->ops.setup_pcc(dspp, NULL);
565 _dpu_crtc_get_pcc_coeff(state, &cfg);
566 dspp->ops.setup_pcc(dspp, &cfg);
569 mixer[i].flush_mask |= ctl->ops.get_bitmask_dspp(ctl,
570 mixer[i].hw_dspp->idx);
572 /* stage config flush mask */
573 ctl->ops.update_pending_flush(ctl, mixer[i].flush_mask);
575 DRM_DEBUG_ATOMIC("lm %d, ctl %d, flush mask 0x%x\n",
576 mixer[i].hw_lm->idx - DSPP_0,
578 mixer[i].flush_mask);
582 static void dpu_crtc_atomic_begin(struct drm_crtc *crtc,
583 struct drm_atomic_state *state)
585 struct dpu_crtc_state *cstate = to_dpu_crtc_state(crtc->state);
586 struct drm_encoder *encoder;
588 if (!crtc->state->enable) {
589 DRM_DEBUG_ATOMIC("crtc%d -> enable %d, skip atomic_begin\n",
590 crtc->base.id, crtc->state->enable);
594 DRM_DEBUG_ATOMIC("crtc%d\n", crtc->base.id);
596 _dpu_crtc_setup_lm_bounds(crtc, crtc->state);
598 /* encoder will trigger pending mask now */
599 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask)
600 dpu_encoder_trigger_kickoff_pending(encoder);
603 * If no mixers have been allocated in dpu_crtc_atomic_check(),
604 * it means we are trying to flush a CRTC whose state is disabled:
605 * nothing else needs to be done.
607 if (unlikely(!cstate->num_mixers))
610 _dpu_crtc_blend_setup(crtc);
612 _dpu_crtc_setup_cp_blocks(crtc);
615 * PP_DONE irq is only used by command mode for now.
616 * It is better to request pending before FLUSH and START trigger
617 * to make sure no pp_done irq missed.
618 * This is safe because no pp_done will happen before SW trigger
623 static void dpu_crtc_atomic_flush(struct drm_crtc *crtc,
624 struct drm_atomic_state *state)
626 struct dpu_crtc *dpu_crtc;
627 struct drm_device *dev;
628 struct drm_plane *plane;
629 struct msm_drm_private *priv;
631 struct dpu_crtc_state *cstate;
633 if (!crtc->state->enable) {
634 DRM_DEBUG_ATOMIC("crtc%d -> enable %d, skip atomic_flush\n",
635 crtc->base.id, crtc->state->enable);
639 DRM_DEBUG_ATOMIC("crtc%d\n", crtc->base.id);
641 dpu_crtc = to_dpu_crtc(crtc);
642 cstate = to_dpu_crtc_state(crtc->state);
644 priv = dev->dev_private;
646 if (crtc->index >= ARRAY_SIZE(priv->event_thread)) {
647 DPU_ERROR("invalid crtc index[%d]\n", crtc->index);
651 WARN_ON(dpu_crtc->event);
652 spin_lock_irqsave(&dev->event_lock, flags);
653 dpu_crtc->event = crtc->state->event;
654 crtc->state->event = NULL;
655 spin_unlock_irqrestore(&dev->event_lock, flags);
658 * If no mixers has been allocated in dpu_crtc_atomic_check(),
659 * it means we are trying to flush a CRTC whose state is disabled:
660 * nothing else needs to be done.
662 if (unlikely(!cstate->num_mixers))
665 /* update performance setting before crtc kickoff */
666 dpu_core_perf_crtc_update(crtc, 1, false);
669 * Final plane updates: Give each plane a chance to complete all
670 * required writes/flushing before crtc's "flush
671 * everything" call below.
673 drm_atomic_crtc_for_each_plane(plane, crtc) {
674 if (dpu_crtc->smmu_state.transition_error)
675 dpu_plane_set_error(plane, true);
676 dpu_plane_flush(plane);
679 /* Kickoff will be scheduled by outer layer */
683 * dpu_crtc_destroy_state - state destroy hook
685 * @state: CRTC state object to release
687 static void dpu_crtc_destroy_state(struct drm_crtc *crtc,
688 struct drm_crtc_state *state)
690 struct dpu_crtc_state *cstate = to_dpu_crtc_state(state);
692 DRM_DEBUG_ATOMIC("crtc%d\n", crtc->base.id);
694 __drm_atomic_helper_crtc_destroy_state(state);
699 static int _dpu_crtc_wait_for_frame_done(struct drm_crtc *crtc)
701 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
704 if (!atomic_read(&dpu_crtc->frame_pending)) {
705 DRM_DEBUG_ATOMIC("no frames pending\n");
709 DPU_ATRACE_BEGIN("frame done completion wait");
710 ret = wait_for_completion_timeout(&dpu_crtc->frame_done_comp,
711 msecs_to_jiffies(DPU_CRTC_FRAME_DONE_TIMEOUT_MS));
713 DRM_ERROR("frame done wait timed out, ret:%d\n", ret);
716 DPU_ATRACE_END("frame done completion wait");
721 void dpu_crtc_commit_kickoff(struct drm_crtc *crtc)
723 struct drm_encoder *encoder;
724 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
725 struct dpu_kms *dpu_kms = _dpu_crtc_get_kms(crtc);
726 struct dpu_crtc_state *cstate = to_dpu_crtc_state(crtc->state);
729 * If no mixers has been allocated in dpu_crtc_atomic_check(),
730 * it means we are trying to start a CRTC whose state is disabled:
731 * nothing else needs to be done.
733 if (unlikely(!cstate->num_mixers))
736 DPU_ATRACE_BEGIN("crtc_commit");
739 * Encoder will flush/start now, unless it has a tx pending. If so, it
740 * may delay and flush at an irq event (e.g. ppdone)
742 drm_for_each_encoder_mask(encoder, crtc->dev,
743 crtc->state->encoder_mask)
744 dpu_encoder_prepare_for_kickoff(encoder);
746 if (atomic_inc_return(&dpu_crtc->frame_pending) == 1) {
747 /* acquire bandwidth and other resources */
748 DRM_DEBUG_ATOMIC("crtc%d first commit\n", crtc->base.id);
750 DRM_DEBUG_ATOMIC("crtc%d commit\n", crtc->base.id);
752 dpu_crtc->play_count++;
754 dpu_vbif_clear_errors(dpu_kms);
756 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask)
757 dpu_encoder_kickoff(encoder);
759 reinit_completion(&dpu_crtc->frame_done_comp);
760 DPU_ATRACE_END("crtc_commit");
763 static void dpu_crtc_reset(struct drm_crtc *crtc)
765 struct dpu_crtc_state *cstate = kzalloc(sizeof(*cstate), GFP_KERNEL);
768 dpu_crtc_destroy_state(crtc, crtc->state);
770 __drm_atomic_helper_crtc_reset(crtc, &cstate->base);
774 * dpu_crtc_duplicate_state - state duplicate hook
775 * @crtc: Pointer to drm crtc structure
777 static struct drm_crtc_state *dpu_crtc_duplicate_state(struct drm_crtc *crtc)
779 struct dpu_crtc_state *cstate, *old_cstate = to_dpu_crtc_state(crtc->state);
781 cstate = kmemdup(old_cstate, sizeof(*old_cstate), GFP_KERNEL);
783 DPU_ERROR("failed to allocate state\n");
787 /* duplicate base helper */
788 __drm_atomic_helper_crtc_duplicate_state(crtc, &cstate->base);
790 return &cstate->base;
793 static void dpu_crtc_disable(struct drm_crtc *crtc,
794 struct drm_atomic_state *state)
796 struct drm_crtc_state *old_crtc_state = drm_atomic_get_old_crtc_state(state,
798 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
799 struct dpu_crtc_state *cstate = to_dpu_crtc_state(crtc->state);
800 struct drm_encoder *encoder;
802 bool release_bandwidth = false;
804 DRM_DEBUG_KMS("crtc%d\n", crtc->base.id);
806 /* Disable/save vblank irq handling */
807 drm_crtc_vblank_off(crtc);
809 drm_for_each_encoder_mask(encoder, crtc->dev,
810 old_crtc_state->encoder_mask) {
811 /* in video mode, we hold an extra bandwidth reference
812 * as we cannot drop bandwidth at frame-done if any
813 * crtc is being used in video mode.
815 if (dpu_encoder_get_intf_mode(encoder) == INTF_MODE_VIDEO)
816 release_bandwidth = true;
817 dpu_encoder_assign_crtc(encoder, NULL);
820 /* wait for frame_event_done completion */
821 if (_dpu_crtc_wait_for_frame_done(crtc))
822 DPU_ERROR("crtc%d wait for frame done failed;frame_pending%d\n",
824 atomic_read(&dpu_crtc->frame_pending));
826 trace_dpu_crtc_disable(DRMID(crtc), false, dpu_crtc);
827 dpu_crtc->enabled = false;
829 if (atomic_read(&dpu_crtc->frame_pending)) {
830 trace_dpu_crtc_disable_frame_pending(DRMID(crtc),
831 atomic_read(&dpu_crtc->frame_pending));
832 if (release_bandwidth)
833 dpu_core_perf_crtc_release_bw(crtc);
834 atomic_set(&dpu_crtc->frame_pending, 0);
837 dpu_core_perf_crtc_update(crtc, 0, true);
839 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask)
840 dpu_encoder_register_frame_event_callback(encoder, NULL, NULL);
842 memset(cstate->mixers, 0, sizeof(cstate->mixers));
843 cstate->num_mixers = 0;
845 /* disable clk & bw control until clk & bw properties are set */
846 cstate->bw_control = false;
847 cstate->bw_split_vote = false;
849 if (crtc->state->event && !crtc->state->active) {
850 spin_lock_irqsave(&crtc->dev->event_lock, flags);
851 drm_crtc_send_vblank_event(crtc, crtc->state->event);
852 crtc->state->event = NULL;
853 spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
856 pm_runtime_put_sync(crtc->dev->dev);
859 static void dpu_crtc_enable(struct drm_crtc *crtc,
860 struct drm_atomic_state *state)
862 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
863 struct drm_encoder *encoder;
864 bool request_bandwidth = false;
866 pm_runtime_get_sync(crtc->dev->dev);
868 DRM_DEBUG_KMS("crtc%d\n", crtc->base.id);
870 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask) {
871 /* in video mode, we hold an extra bandwidth reference
872 * as we cannot drop bandwidth at frame-done if any
873 * crtc is being used in video mode.
875 if (dpu_encoder_get_intf_mode(encoder) == INTF_MODE_VIDEO)
876 request_bandwidth = true;
877 dpu_encoder_register_frame_event_callback(encoder,
878 dpu_crtc_frame_event_cb, (void *)crtc);
881 if (request_bandwidth)
882 atomic_inc(&_dpu_crtc_get_kms(crtc)->bandwidth_ref);
884 trace_dpu_crtc_enable(DRMID(crtc), true, dpu_crtc);
885 dpu_crtc->enabled = true;
887 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask)
888 dpu_encoder_assign_crtc(encoder, crtc);
890 /* Enable/restore vblank irq handling */
891 drm_crtc_vblank_on(crtc);
895 struct dpu_plane_state *dpu_pstate;
896 const struct drm_plane_state *drm_pstate;
901 static int dpu_crtc_atomic_check(struct drm_crtc *crtc,
902 struct drm_atomic_state *state)
904 struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state,
906 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
907 struct dpu_crtc_state *cstate = to_dpu_crtc_state(crtc_state);
908 struct plane_state *pstates;
910 const struct drm_plane_state *pstate;
911 struct drm_plane *plane;
912 struct drm_display_mode *mode;
914 int cnt = 0, rc = 0, mixer_width = 0, i, z_pos;
916 struct dpu_multirect_plane_states multirect_plane[DPU_STAGE_MAX * 2];
917 int multirect_count = 0;
918 const struct drm_plane_state *pipe_staged[SSPP_MAX];
919 int left_zpos_cnt = 0, right_zpos_cnt = 0;
920 struct drm_rect crtc_rect = { 0 };
922 pstates = kzalloc(sizeof(*pstates) * DPU_STAGE_MAX * 4, GFP_KERNEL);
924 if (!crtc_state->enable || !crtc_state->active) {
925 DRM_DEBUG_ATOMIC("crtc%d -> enable %d, active %d, skip atomic_check\n",
926 crtc->base.id, crtc_state->enable,
928 memset(&cstate->new_perf, 0, sizeof(cstate->new_perf));
932 mode = &crtc_state->adjusted_mode;
933 DRM_DEBUG_ATOMIC("%s: check\n", dpu_crtc->name);
935 /* force a full mode set if active state changed */
936 if (crtc_state->active_changed)
937 crtc_state->mode_changed = true;
939 memset(pipe_staged, 0, sizeof(pipe_staged));
941 if (cstate->num_mixers) {
942 mixer_width = mode->hdisplay / cstate->num_mixers;
944 _dpu_crtc_setup_lm_bounds(crtc, crtc_state);
947 crtc_rect.x2 = mode->hdisplay;
948 crtc_rect.y2 = mode->vdisplay;
950 /* get plane state for all drm planes associated with crtc state */
951 drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) {
952 struct drm_rect dst, clip = crtc_rect;
954 if (IS_ERR_OR_NULL(pstate)) {
955 rc = PTR_ERR(pstate);
956 DPU_ERROR("%s: failed to get plane%d state, %d\n",
957 dpu_crtc->name, plane->base.id, rc);
960 if (cnt >= DPU_STAGE_MAX * 4)
963 pstates[cnt].dpu_pstate = to_dpu_plane_state(pstate);
964 pstates[cnt].drm_pstate = pstate;
965 pstates[cnt].stage = pstate->normalized_zpos;
966 pstates[cnt].pipe_id = dpu_plane_pipe(plane);
968 if (pipe_staged[pstates[cnt].pipe_id]) {
969 multirect_plane[multirect_count].r0 =
970 pipe_staged[pstates[cnt].pipe_id];
971 multirect_plane[multirect_count].r1 = pstate;
974 pipe_staged[pstates[cnt].pipe_id] = NULL;
976 pipe_staged[pstates[cnt].pipe_id] = pstate;
981 dst = drm_plane_state_dest(pstate);
982 if (!drm_rect_intersect(&clip, &dst)) {
983 DPU_ERROR("invalid vertical/horizontal destination\n");
984 DPU_ERROR("display: " DRM_RECT_FMT " plane: "
985 DRM_RECT_FMT "\n", DRM_RECT_ARG(&crtc_rect),
992 for (i = 1; i < SSPP_MAX; i++) {
993 if (pipe_staged[i]) {
994 dpu_plane_clear_multirect(pipe_staged[i]);
996 if (is_dpu_plane_virtual(pipe_staged[i]->plane)) {
998 "r1 only virt plane:%d not supported\n",
999 pipe_staged[i]->plane->base.id);
1007 for (i = 0; i < cnt; i++) {
1008 /* reset counts at every new blend stage */
1009 if (pstates[i].stage != z_pos) {
1012 z_pos = pstates[i].stage;
1015 /* verify z_pos setting before using it */
1016 if (z_pos >= DPU_STAGE_MAX - DPU_STAGE_0) {
1017 DPU_ERROR("> %d plane stages assigned\n",
1018 DPU_STAGE_MAX - DPU_STAGE_0);
1021 } else if (pstates[i].drm_pstate->crtc_x < mixer_width) {
1022 if (left_zpos_cnt == 2) {
1023 DPU_ERROR("> 2 planes @ stage %d on left\n",
1031 if (right_zpos_cnt == 2) {
1032 DPU_ERROR("> 2 planes @ stage %d on right\n",
1040 pstates[i].dpu_pstate->stage = z_pos + DPU_STAGE_0;
1041 DRM_DEBUG_ATOMIC("%s: zpos %d\n", dpu_crtc->name, z_pos);
1044 for (i = 0; i < multirect_count; i++) {
1045 if (dpu_plane_validate_multirect_v2(&multirect_plane[i])) {
1047 "multirect validation failed for planes (%d - %d)\n",
1048 multirect_plane[i].r0->plane->base.id,
1049 multirect_plane[i].r1->plane->base.id);
1055 atomic_inc(&_dpu_crtc_get_kms(crtc)->bandwidth_ref);
1057 rc = dpu_core_perf_crtc_check(crtc, crtc_state);
1059 DPU_ERROR("crtc%d failed performance check %d\n",
1064 /* validate source split:
1065 * use pstates sorted by stage to check planes on same stage
1066 * we assume that all pipes are in source split so its valid to compare
1067 * without taking into account left/right mixer placement
1069 for (i = 1; i < cnt; i++) {
1070 struct plane_state *prv_pstate, *cur_pstate;
1071 struct drm_rect left_rect, right_rect;
1072 int32_t left_pid, right_pid;
1075 prv_pstate = &pstates[i - 1];
1076 cur_pstate = &pstates[i];
1077 if (prv_pstate->stage != cur_pstate->stage)
1080 stage = cur_pstate->stage;
1082 left_pid = prv_pstate->dpu_pstate->base.plane->base.id;
1083 left_rect = drm_plane_state_dest(prv_pstate->drm_pstate);
1085 right_pid = cur_pstate->dpu_pstate->base.plane->base.id;
1086 right_rect = drm_plane_state_dest(cur_pstate->drm_pstate);
1088 if (right_rect.x1 < left_rect.x1) {
1089 swap(left_pid, right_pid);
1090 swap(left_rect, right_rect);
1094 * - planes are enumerated in pipe-priority order such that
1095 * planes with lower drm_id must be left-most in a shared
1096 * blend-stage when using source split.
1097 * - planes in source split must be contiguous in width
1098 * - planes in source split must have same dest yoff and height
1100 if (right_pid < left_pid) {
1102 "invalid src split cfg. priority mismatch. stage: %d left: %d right: %d\n",
1103 stage, left_pid, right_pid);
1106 } else if (right_rect.x1 != drm_rect_width(&left_rect)) {
1107 DPU_ERROR("non-contiguous coordinates for src split. "
1108 "stage: %d left: " DRM_RECT_FMT " right: "
1109 DRM_RECT_FMT "\n", stage,
1110 DRM_RECT_ARG(&left_rect),
1111 DRM_RECT_ARG(&right_rect));
1114 } else if (left_rect.y1 != right_rect.y1 ||
1115 drm_rect_height(&left_rect) != drm_rect_height(&right_rect)) {
1116 DPU_ERROR("source split at stage: %d. invalid "
1117 "yoff/height: left: " DRM_RECT_FMT " right: "
1118 DRM_RECT_FMT "\n", stage,
1119 DRM_RECT_ARG(&left_rect),
1120 DRM_RECT_ARG(&right_rect));
1131 int dpu_crtc_vblank(struct drm_crtc *crtc, bool en)
1133 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
1134 struct drm_encoder *enc;
1136 trace_dpu_crtc_vblank(DRMID(&dpu_crtc->base), en, dpu_crtc);
1139 * Normally we would iterate through encoder_mask in crtc state to find
1140 * attached encoders. In this case, we might be disabling vblank _after_
1141 * encoder_mask has been cleared.
1143 * Instead, we "assign" a crtc to the encoder in enable and clear it in
1144 * disable (which is also after encoder_mask is cleared). So instead of
1145 * using encoder mask, we'll ask the encoder to toggle itself iff it's
1146 * currently assigned to our crtc.
1148 * Note also that this function cannot be called while crtc is disabled
1149 * since we use drm_crtc_vblank_on/off. So we don't need to worry
1150 * about the assigned crtcs being inconsistent with the current state
1151 * (which means no need to worry about modeset locks).
1153 list_for_each_entry(enc, &crtc->dev->mode_config.encoder_list, head) {
1154 trace_dpu_crtc_vblank_enable(DRMID(crtc), DRMID(enc), en,
1157 dpu_encoder_toggle_vblank_for_crtc(enc, crtc, en);
1163 #ifdef CONFIG_DEBUG_FS
1164 static int _dpu_debugfs_status_show(struct seq_file *s, void *data)
1166 struct dpu_crtc *dpu_crtc;
1167 struct dpu_plane_state *pstate = NULL;
1168 struct dpu_crtc_mixer *m;
1170 struct drm_crtc *crtc;
1171 struct drm_plane *plane;
1172 struct drm_display_mode *mode;
1173 struct drm_framebuffer *fb;
1174 struct drm_plane_state *state;
1175 struct dpu_crtc_state *cstate;
1179 dpu_crtc = s->private;
1180 crtc = &dpu_crtc->base;
1182 drm_modeset_lock_all(crtc->dev);
1183 cstate = to_dpu_crtc_state(crtc->state);
1185 mode = &crtc->state->adjusted_mode;
1186 out_width = mode->hdisplay / cstate->num_mixers;
1188 seq_printf(s, "crtc:%d width:%d height:%d\n", crtc->base.id,
1189 mode->hdisplay, mode->vdisplay);
1193 for (i = 0; i < cstate->num_mixers; ++i) {
1194 m = &cstate->mixers[i];
1195 seq_printf(s, "\tmixer:%d ctl:%d width:%d height:%d\n",
1196 m->hw_lm->idx - LM_0, m->lm_ctl->idx - CTL_0,
1197 out_width, mode->vdisplay);
1202 drm_atomic_crtc_for_each_plane(plane, crtc) {
1203 pstate = to_dpu_plane_state(plane->state);
1204 state = plane->state;
1206 if (!pstate || !state)
1209 seq_printf(s, "\tplane:%u stage:%d\n", plane->base.id,
1212 if (plane->state->fb) {
1213 fb = plane->state->fb;
1215 seq_printf(s, "\tfb:%d image format:%4.4s wxh:%ux%u ",
1216 fb->base.id, (char *) &fb->format->format,
1217 fb->width, fb->height);
1218 for (i = 0; i < ARRAY_SIZE(fb->format->cpp); ++i)
1219 seq_printf(s, "cpp[%d]:%u ",
1220 i, fb->format->cpp[i]);
1221 seq_puts(s, "\n\t");
1223 seq_printf(s, "modifier:%8llu ", fb->modifier);
1227 for (i = 0; i < ARRAY_SIZE(fb->pitches); i++)
1228 seq_printf(s, "pitches[%d]:%8u ", i,
1233 for (i = 0; i < ARRAY_SIZE(fb->offsets); i++)
1234 seq_printf(s, "offsets[%d]:%8u ", i,
1239 seq_printf(s, "\tsrc_x:%4d src_y:%4d src_w:%4d src_h:%4d\n",
1240 state->src_x, state->src_y, state->src_w, state->src_h);
1242 seq_printf(s, "\tdst x:%4d dst_y:%4d dst_w:%4d dst_h:%4d\n",
1243 state->crtc_x, state->crtc_y, state->crtc_w,
1245 seq_printf(s, "\tmultirect: mode: %d index: %d\n",
1246 pstate->multirect_mode, pstate->multirect_index);
1250 if (dpu_crtc->vblank_cb_count) {
1251 ktime_t diff = ktime_sub(ktime_get(), dpu_crtc->vblank_cb_time);
1252 s64 diff_ms = ktime_to_ms(diff);
1253 s64 fps = diff_ms ? div_s64(
1254 dpu_crtc->vblank_cb_count * 1000, diff_ms) : 0;
1257 "vblank fps:%lld count:%u total:%llums total_framecount:%llu\n",
1258 fps, dpu_crtc->vblank_cb_count,
1259 ktime_to_ms(diff), dpu_crtc->play_count);
1261 /* reset time & count for next measurement */
1262 dpu_crtc->vblank_cb_count = 0;
1263 dpu_crtc->vblank_cb_time = ktime_set(0, 0);
1266 drm_modeset_unlock_all(crtc->dev);
1271 DEFINE_SHOW_ATTRIBUTE(_dpu_debugfs_status);
1273 static int dpu_crtc_debugfs_state_show(struct seq_file *s, void *v)
1275 struct drm_crtc *crtc = (struct drm_crtc *) s->private;
1276 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
1278 seq_printf(s, "client type: %d\n", dpu_crtc_get_client_type(crtc));
1279 seq_printf(s, "intf_mode: %d\n", dpu_crtc_get_intf_mode(crtc));
1280 seq_printf(s, "core_clk_rate: %llu\n",
1281 dpu_crtc->cur_perf.core_clk_rate);
1282 seq_printf(s, "bw_ctl: %llu\n", dpu_crtc->cur_perf.bw_ctl);
1283 seq_printf(s, "max_per_pipe_ib: %llu\n",
1284 dpu_crtc->cur_perf.max_per_pipe_ib);
1288 DEFINE_SHOW_ATTRIBUTE(dpu_crtc_debugfs_state);
1290 static int _dpu_crtc_init_debugfs(struct drm_crtc *crtc)
1292 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
1294 dpu_crtc->debugfs_root = debugfs_create_dir(dpu_crtc->name,
1295 crtc->dev->primary->debugfs_root);
1297 debugfs_create_file("status", 0400,
1298 dpu_crtc->debugfs_root,
1299 dpu_crtc, &_dpu_debugfs_status_fops);
1300 debugfs_create_file("state", 0600,
1301 dpu_crtc->debugfs_root,
1303 &dpu_crtc_debugfs_state_fops);
1308 static int _dpu_crtc_init_debugfs(struct drm_crtc *crtc)
1312 #endif /* CONFIG_DEBUG_FS */
1314 static int dpu_crtc_late_register(struct drm_crtc *crtc)
1316 return _dpu_crtc_init_debugfs(crtc);
1319 static void dpu_crtc_early_unregister(struct drm_crtc *crtc)
1321 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc);
1323 debugfs_remove_recursive(dpu_crtc->debugfs_root);
1326 static const struct drm_crtc_funcs dpu_crtc_funcs = {
1327 .set_config = drm_atomic_helper_set_config,
1328 .destroy = dpu_crtc_destroy,
1329 .page_flip = drm_atomic_helper_page_flip,
1330 .reset = dpu_crtc_reset,
1331 .atomic_duplicate_state = dpu_crtc_duplicate_state,
1332 .atomic_destroy_state = dpu_crtc_destroy_state,
1333 .late_register = dpu_crtc_late_register,
1334 .early_unregister = dpu_crtc_early_unregister,
1335 .enable_vblank = msm_crtc_enable_vblank,
1336 .disable_vblank = msm_crtc_disable_vblank,
1337 .get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp,
1338 .get_vblank_counter = dpu_crtc_get_vblank_counter,
1341 static const struct drm_crtc_helper_funcs dpu_crtc_helper_funcs = {
1342 .atomic_disable = dpu_crtc_disable,
1343 .atomic_enable = dpu_crtc_enable,
1344 .atomic_check = dpu_crtc_atomic_check,
1345 .atomic_begin = dpu_crtc_atomic_begin,
1346 .atomic_flush = dpu_crtc_atomic_flush,
1347 .get_scanout_position = dpu_crtc_get_scanout_position,
1350 /* initialize crtc */
1351 struct drm_crtc *dpu_crtc_init(struct drm_device *dev, struct drm_plane *plane,
1352 struct drm_plane *cursor)
1354 struct drm_crtc *crtc = NULL;
1355 struct dpu_crtc *dpu_crtc = NULL;
1358 dpu_crtc = kzalloc(sizeof(*dpu_crtc), GFP_KERNEL);
1360 return ERR_PTR(-ENOMEM);
1362 crtc = &dpu_crtc->base;
1365 spin_lock_init(&dpu_crtc->spin_lock);
1366 atomic_set(&dpu_crtc->frame_pending, 0);
1368 init_completion(&dpu_crtc->frame_done_comp);
1370 INIT_LIST_HEAD(&dpu_crtc->frame_event_list);
1372 for (i = 0; i < ARRAY_SIZE(dpu_crtc->frame_events); i++) {
1373 INIT_LIST_HEAD(&dpu_crtc->frame_events[i].list);
1374 list_add(&dpu_crtc->frame_events[i].list,
1375 &dpu_crtc->frame_event_list);
1376 kthread_init_work(&dpu_crtc->frame_events[i].work,
1377 dpu_crtc_frame_event_work);
1380 drm_crtc_init_with_planes(dev, crtc, plane, cursor, &dpu_crtc_funcs,
1383 drm_crtc_helper_add(crtc, &dpu_crtc_helper_funcs);
1385 drm_crtc_enable_color_mgmt(crtc, 0, true, 0);
1387 /* save user friendly CRTC name for later */
1388 snprintf(dpu_crtc->name, DPU_CRTC_NAME_SIZE, "crtc%u", crtc->base.id);
1390 /* initialize event handling */
1391 spin_lock_init(&dpu_crtc->event_lock);
1393 DRM_DEBUG_KMS("%s: successfully initialized crtc\n", dpu_crtc->name);