Merge branch 'irq-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / gpu / drm / vc4 / vc4_crtc.c
blob265064c62d493b54023947d49597852a16328a5f
1 /*
2 * Copyright (C) 2015 Broadcom
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
9 /**
10 * DOC: VC4 CRTC module
12 * In VC4, the Pixel Valve is what most closely corresponds to the
13 * DRM's concept of a CRTC. The PV generates video timings from the
14 * output's clock plus its configuration. It pulls scaled pixels from
15 * the HVS at that timing, and feeds it to the encoder.
17 * However, the DRM CRTC also collects the configuration of all the
18 * DRM planes attached to it. As a result, this file also manages
19 * setup of the VC4 HVS's display elements on the CRTC.
21 * The 2835 has 3 different pixel valves. pv0 in the audio power
22 * domain feeds DSI0 or DPI, while pv1 feeds DS1 or SMI. pv2 in the
23 * image domain can feed either HDMI or the SDTV controller. The
24 * pixel valve chooses from the CPRMAN clocks (HSM for HDMI, VEC for
25 * SDTV, etc.) according to which output type is chosen in the mux.
27 * For power management, the pixel valve's registers are all clocked
28 * by the AXI clock, while the timings and FIFOs make use of the
29 * output-specific clock. Since the encoders also directly consume
30 * the CPRMAN clocks, and know what timings they need, they are the
31 * ones that set the clock.
34 #include "drm_atomic.h"
35 #include "drm_atomic_helper.h"
36 #include "drm_crtc_helper.h"
37 #include "linux/clk.h"
38 #include "linux/component.h"
39 #include "linux/of_device.h"
40 #include "vc4_drv.h"
41 #include "vc4_regs.h"
43 struct vc4_crtc {
44 struct drm_crtc base;
45 const struct vc4_crtc_data *data;
46 void __iomem *regs;
48 /* Which HVS channel we're using for our CRTC. */
49 int channel;
51 /* Pointer to the actual hardware display list memory for the
52 * crtc.
54 u32 __iomem *dlist;
56 u32 dlist_size; /* in dwords */
58 struct drm_pending_vblank_event *event;
61 static inline struct vc4_crtc *
62 to_vc4_crtc(struct drm_crtc *crtc)
64 return (struct vc4_crtc *)crtc;
67 struct vc4_crtc_data {
68 /* Which channel of the HVS this pixelvalve sources from. */
69 int hvs_channel;
71 enum vc4_encoder_type encoder0_type;
72 enum vc4_encoder_type encoder1_type;
75 #define CRTC_WRITE(offset, val) writel(val, vc4_crtc->regs + (offset))
76 #define CRTC_READ(offset) readl(vc4_crtc->regs + (offset))
78 #define CRTC_REG(reg) { reg, #reg }
79 static const struct {
80 u32 reg;
81 const char *name;
82 } crtc_regs[] = {
83 CRTC_REG(PV_CONTROL),
84 CRTC_REG(PV_V_CONTROL),
85 CRTC_REG(PV_VSYNCD),
86 CRTC_REG(PV_HORZA),
87 CRTC_REG(PV_HORZB),
88 CRTC_REG(PV_VERTA),
89 CRTC_REG(PV_VERTB),
90 CRTC_REG(PV_VERTA_EVEN),
91 CRTC_REG(PV_VERTB_EVEN),
92 CRTC_REG(PV_INTEN),
93 CRTC_REG(PV_INTSTAT),
94 CRTC_REG(PV_STAT),
95 CRTC_REG(PV_HACT_ACT),
98 static void vc4_crtc_dump_regs(struct vc4_crtc *vc4_crtc)
100 int i;
102 for (i = 0; i < ARRAY_SIZE(crtc_regs); i++) {
103 DRM_INFO("0x%04x (%s): 0x%08x\n",
104 crtc_regs[i].reg, crtc_regs[i].name,
105 CRTC_READ(crtc_regs[i].reg));
109 #ifdef CONFIG_DEBUG_FS
110 int vc4_crtc_debugfs_regs(struct seq_file *m, void *unused)
112 struct drm_info_node *node = (struct drm_info_node *)m->private;
113 struct drm_device *dev = node->minor->dev;
114 int crtc_index = (uintptr_t)node->info_ent->data;
115 struct drm_crtc *crtc;
116 struct vc4_crtc *vc4_crtc;
117 int i;
119 i = 0;
120 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
121 if (i == crtc_index)
122 break;
123 i++;
125 if (!crtc)
126 return 0;
127 vc4_crtc = to_vc4_crtc(crtc);
129 for (i = 0; i < ARRAY_SIZE(crtc_regs); i++) {
130 seq_printf(m, "%s (0x%04x): 0x%08x\n",
131 crtc_regs[i].name, crtc_regs[i].reg,
132 CRTC_READ(crtc_regs[i].reg));
135 return 0;
137 #endif
139 static void vc4_crtc_destroy(struct drm_crtc *crtc)
141 drm_crtc_cleanup(crtc);
144 static u32 vc4_get_fifo_full_level(u32 format)
146 static const u32 fifo_len_bytes = 64;
147 static const u32 hvs_latency_pix = 6;
149 switch (format) {
150 case PV_CONTROL_FORMAT_DSIV_16:
151 case PV_CONTROL_FORMAT_DSIC_16:
152 return fifo_len_bytes - 2 * hvs_latency_pix;
153 case PV_CONTROL_FORMAT_DSIV_18:
154 return fifo_len_bytes - 14;
155 case PV_CONTROL_FORMAT_24:
156 case PV_CONTROL_FORMAT_DSIV_24:
157 default:
158 return fifo_len_bytes - 3 * hvs_latency_pix;
163 * Returns the clock select bit for the connector attached to the
164 * CRTC.
166 static int vc4_get_clock_select(struct drm_crtc *crtc)
168 struct drm_connector *connector;
170 drm_for_each_connector(connector, crtc->dev) {
171 if (connector->state->crtc == crtc) {
172 struct drm_encoder *encoder = connector->encoder;
173 struct vc4_encoder *vc4_encoder =
174 to_vc4_encoder(encoder);
176 return vc4_encoder->clock_select;
180 return -1;
183 static void vc4_crtc_mode_set_nofb(struct drm_crtc *crtc)
185 struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
186 struct drm_crtc_state *state = crtc->state;
187 struct drm_display_mode *mode = &state->adjusted_mode;
188 bool interlace = mode->flags & DRM_MODE_FLAG_INTERLACE;
189 u32 vactive = (mode->vdisplay >> (interlace ? 1 : 0));
190 u32 format = PV_CONTROL_FORMAT_24;
191 bool debug_dump_regs = false;
192 int clock_select = vc4_get_clock_select(crtc);
194 if (debug_dump_regs) {
195 DRM_INFO("CRTC %d regs before:\n", drm_crtc_index(crtc));
196 vc4_crtc_dump_regs(vc4_crtc);
199 /* Reset the PV fifo. */
200 CRTC_WRITE(PV_CONTROL, 0);
201 CRTC_WRITE(PV_CONTROL, PV_CONTROL_FIFO_CLR | PV_CONTROL_EN);
202 CRTC_WRITE(PV_CONTROL, 0);
204 CRTC_WRITE(PV_HORZA,
205 VC4_SET_FIELD(mode->htotal - mode->hsync_end,
206 PV_HORZA_HBP) |
207 VC4_SET_FIELD(mode->hsync_end - mode->hsync_start,
208 PV_HORZA_HSYNC));
209 CRTC_WRITE(PV_HORZB,
210 VC4_SET_FIELD(mode->hsync_start - mode->hdisplay,
211 PV_HORZB_HFP) |
212 VC4_SET_FIELD(mode->hdisplay, PV_HORZB_HACTIVE));
214 if (interlace) {
215 CRTC_WRITE(PV_VERTA_EVEN,
216 VC4_SET_FIELD(mode->vtotal - mode->vsync_end - 1,
217 PV_VERTA_VBP) |
218 VC4_SET_FIELD(mode->vsync_end - mode->vsync_start,
219 PV_VERTA_VSYNC));
220 CRTC_WRITE(PV_VERTB_EVEN,
221 VC4_SET_FIELD(mode->vsync_start - mode->vdisplay,
222 PV_VERTB_VFP) |
223 VC4_SET_FIELD(vactive, PV_VERTB_VACTIVE));
226 CRTC_WRITE(PV_HACT_ACT, mode->hdisplay);
228 CRTC_WRITE(PV_V_CONTROL,
229 PV_VCONTROL_CONTINUOUS |
230 (interlace ? PV_VCONTROL_INTERLACE : 0));
232 CRTC_WRITE(PV_CONTROL,
233 VC4_SET_FIELD(format, PV_CONTROL_FORMAT) |
234 VC4_SET_FIELD(vc4_get_fifo_full_level(format),
235 PV_CONTROL_FIFO_LEVEL) |
236 PV_CONTROL_CLR_AT_START |
237 PV_CONTROL_TRIGGER_UNDERFLOW |
238 PV_CONTROL_WAIT_HSTART |
239 VC4_SET_FIELD(clock_select, PV_CONTROL_CLK_SELECT) |
240 PV_CONTROL_FIFO_CLR |
241 PV_CONTROL_EN);
243 if (debug_dump_regs) {
244 DRM_INFO("CRTC %d regs after:\n", drm_crtc_index(crtc));
245 vc4_crtc_dump_regs(vc4_crtc);
249 static void require_hvs_enabled(struct drm_device *dev)
251 struct vc4_dev *vc4 = to_vc4_dev(dev);
253 WARN_ON_ONCE((HVS_READ(SCALER_DISPCTRL) & SCALER_DISPCTRL_ENABLE) !=
254 SCALER_DISPCTRL_ENABLE);
257 static void vc4_crtc_disable(struct drm_crtc *crtc)
259 struct drm_device *dev = crtc->dev;
260 struct vc4_dev *vc4 = to_vc4_dev(dev);
261 struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
262 u32 chan = vc4_crtc->channel;
263 int ret;
264 require_hvs_enabled(dev);
266 CRTC_WRITE(PV_V_CONTROL,
267 CRTC_READ(PV_V_CONTROL) & ~PV_VCONTROL_VIDEN);
268 ret = wait_for(!(CRTC_READ(PV_V_CONTROL) & PV_VCONTROL_VIDEN), 1);
269 WARN_ONCE(ret, "Timeout waiting for !PV_VCONTROL_VIDEN\n");
271 if (HVS_READ(SCALER_DISPCTRLX(chan)) &
272 SCALER_DISPCTRLX_ENABLE) {
273 HVS_WRITE(SCALER_DISPCTRLX(chan),
274 SCALER_DISPCTRLX_RESET);
276 /* While the docs say that reset is self-clearing, it
277 * seems it doesn't actually.
279 HVS_WRITE(SCALER_DISPCTRLX(chan), 0);
282 /* Once we leave, the scaler should be disabled and its fifo empty. */
284 WARN_ON_ONCE(HVS_READ(SCALER_DISPCTRLX(chan)) & SCALER_DISPCTRLX_RESET);
286 WARN_ON_ONCE(VC4_GET_FIELD(HVS_READ(SCALER_DISPSTATX(chan)),
287 SCALER_DISPSTATX_MODE) !=
288 SCALER_DISPSTATX_MODE_DISABLED);
290 WARN_ON_ONCE((HVS_READ(SCALER_DISPSTATX(chan)) &
291 (SCALER_DISPSTATX_FULL | SCALER_DISPSTATX_EMPTY)) !=
292 SCALER_DISPSTATX_EMPTY);
295 static void vc4_crtc_enable(struct drm_crtc *crtc)
297 struct drm_device *dev = crtc->dev;
298 struct vc4_dev *vc4 = to_vc4_dev(dev);
299 struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
300 struct drm_crtc_state *state = crtc->state;
301 struct drm_display_mode *mode = &state->adjusted_mode;
303 require_hvs_enabled(dev);
305 /* Turn on the scaler, which will wait for vstart to start
306 * compositing.
308 HVS_WRITE(SCALER_DISPCTRLX(vc4_crtc->channel),
309 VC4_SET_FIELD(mode->hdisplay, SCALER_DISPCTRLX_WIDTH) |
310 VC4_SET_FIELD(mode->vdisplay, SCALER_DISPCTRLX_HEIGHT) |
311 SCALER_DISPCTRLX_ENABLE);
313 /* Turn on the pixel valve, which will emit the vstart signal. */
314 CRTC_WRITE(PV_V_CONTROL,
315 CRTC_READ(PV_V_CONTROL) | PV_VCONTROL_VIDEN);
318 static int vc4_crtc_atomic_check(struct drm_crtc *crtc,
319 struct drm_crtc_state *state)
321 struct drm_device *dev = crtc->dev;
322 struct vc4_dev *vc4 = to_vc4_dev(dev);
323 struct drm_plane *plane;
324 struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
325 u32 dlist_count = 0;
327 /* The pixelvalve can only feed one encoder (and encoders are
328 * 1:1 with connectors.)
330 if (drm_atomic_connectors_for_crtc(state->state, crtc) > 1)
331 return -EINVAL;
333 drm_atomic_crtc_state_for_each_plane(plane, state) {
334 struct drm_plane_state *plane_state =
335 state->state->plane_states[drm_plane_index(plane)];
337 /* plane might not have changed, in which case take
338 * current state:
340 if (!plane_state)
341 plane_state = plane->state;
343 dlist_count += vc4_plane_dlist_size(plane_state);
346 dlist_count++; /* Account for SCALER_CTL0_END. */
348 if (!vc4_crtc->dlist || dlist_count > vc4_crtc->dlist_size) {
349 vc4_crtc->dlist = ((u32 __iomem *)vc4->hvs->dlist +
350 HVS_BOOTLOADER_DLIST_END);
351 vc4_crtc->dlist_size = ((SCALER_DLIST_SIZE >> 2) -
352 HVS_BOOTLOADER_DLIST_END);
354 if (dlist_count > vc4_crtc->dlist_size) {
355 DRM_DEBUG_KMS("dlist too large for CRTC (%d > %d).\n",
356 dlist_count, vc4_crtc->dlist_size);
357 return -EINVAL;
361 return 0;
364 static void vc4_crtc_atomic_flush(struct drm_crtc *crtc,
365 struct drm_crtc_state *old_state)
367 struct drm_device *dev = crtc->dev;
368 struct vc4_dev *vc4 = to_vc4_dev(dev);
369 struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
370 struct drm_plane *plane;
371 bool debug_dump_regs = false;
372 u32 __iomem *dlist_next = vc4_crtc->dlist;
374 if (debug_dump_regs) {
375 DRM_INFO("CRTC %d HVS before:\n", drm_crtc_index(crtc));
376 vc4_hvs_dump_state(dev);
379 /* Copy all the active planes' dlist contents to the hardware dlist.
381 * XXX: If the new display list was large enough that it
382 * overlapped a currently-read display list, we need to do
383 * something like disable scanout before putting in the new
384 * list. For now, we're safe because we only have the two
385 * planes.
387 drm_atomic_crtc_for_each_plane(plane, crtc) {
388 dlist_next += vc4_plane_write_dlist(plane, dlist_next);
391 if (dlist_next == vc4_crtc->dlist) {
392 /* If no planes were enabled, use the SCALER_CTL0_END
393 * at the start of the display list memory (in the
394 * bootloader section). We'll rewrite that
395 * SCALER_CTL0_END, just in case, though.
397 writel(SCALER_CTL0_END, vc4->hvs->dlist);
398 HVS_WRITE(SCALER_DISPLISTX(vc4_crtc->channel), 0);
399 } else {
400 writel(SCALER_CTL0_END, dlist_next);
401 dlist_next++;
403 HVS_WRITE(SCALER_DISPLISTX(vc4_crtc->channel),
404 (u32 __iomem *)vc4_crtc->dlist -
405 (u32 __iomem *)vc4->hvs->dlist);
407 /* Make the next display list start after ours. */
408 vc4_crtc->dlist_size -= (dlist_next - vc4_crtc->dlist);
409 vc4_crtc->dlist = dlist_next;
412 if (debug_dump_regs) {
413 DRM_INFO("CRTC %d HVS after:\n", drm_crtc_index(crtc));
414 vc4_hvs_dump_state(dev);
417 if (crtc->state->event) {
418 unsigned long flags;
420 crtc->state->event->pipe = drm_crtc_index(crtc);
422 WARN_ON(drm_crtc_vblank_get(crtc) != 0);
424 spin_lock_irqsave(&dev->event_lock, flags);
425 vc4_crtc->event = crtc->state->event;
426 spin_unlock_irqrestore(&dev->event_lock, flags);
427 crtc->state->event = NULL;
431 int vc4_enable_vblank(struct drm_device *dev, unsigned int crtc_id)
433 struct vc4_dev *vc4 = to_vc4_dev(dev);
434 struct vc4_crtc *vc4_crtc = vc4->crtc[crtc_id];
436 CRTC_WRITE(PV_INTEN, PV_INT_VFP_START);
438 return 0;
441 void vc4_disable_vblank(struct drm_device *dev, unsigned int crtc_id)
443 struct vc4_dev *vc4 = to_vc4_dev(dev);
444 struct vc4_crtc *vc4_crtc = vc4->crtc[crtc_id];
446 CRTC_WRITE(PV_INTEN, 0);
449 static void vc4_crtc_handle_page_flip(struct vc4_crtc *vc4_crtc)
451 struct drm_crtc *crtc = &vc4_crtc->base;
452 struct drm_device *dev = crtc->dev;
453 unsigned long flags;
455 spin_lock_irqsave(&dev->event_lock, flags);
456 if (vc4_crtc->event) {
457 drm_crtc_send_vblank_event(crtc, vc4_crtc->event);
458 vc4_crtc->event = NULL;
460 spin_unlock_irqrestore(&dev->event_lock, flags);
463 static irqreturn_t vc4_crtc_irq_handler(int irq, void *data)
465 struct vc4_crtc *vc4_crtc = data;
466 u32 stat = CRTC_READ(PV_INTSTAT);
467 irqreturn_t ret = IRQ_NONE;
469 if (stat & PV_INT_VFP_START) {
470 CRTC_WRITE(PV_INTSTAT, PV_INT_VFP_START);
471 drm_crtc_handle_vblank(&vc4_crtc->base);
472 vc4_crtc_handle_page_flip(vc4_crtc);
473 ret = IRQ_HANDLED;
476 return ret;
479 static const struct drm_crtc_funcs vc4_crtc_funcs = {
480 .set_config = drm_atomic_helper_set_config,
481 .destroy = vc4_crtc_destroy,
482 .page_flip = drm_atomic_helper_page_flip,
483 .set_property = NULL,
484 .cursor_set = NULL, /* handled by drm_mode_cursor_universal */
485 .cursor_move = NULL, /* handled by drm_mode_cursor_universal */
486 .reset = drm_atomic_helper_crtc_reset,
487 .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
488 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
491 static const struct drm_crtc_helper_funcs vc4_crtc_helper_funcs = {
492 .mode_set_nofb = vc4_crtc_mode_set_nofb,
493 .disable = vc4_crtc_disable,
494 .enable = vc4_crtc_enable,
495 .atomic_check = vc4_crtc_atomic_check,
496 .atomic_flush = vc4_crtc_atomic_flush,
499 /* Frees the page flip event when the DRM device is closed with the
500 * event still outstanding.
502 void vc4_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file)
504 struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
505 struct drm_device *dev = crtc->dev;
506 unsigned long flags;
508 spin_lock_irqsave(&dev->event_lock, flags);
510 if (vc4_crtc->event && vc4_crtc->event->base.file_priv == file) {
511 vc4_crtc->event->base.destroy(&vc4_crtc->event->base);
512 drm_crtc_vblank_put(crtc);
513 vc4_crtc->event = NULL;
516 spin_unlock_irqrestore(&dev->event_lock, flags);
519 static const struct vc4_crtc_data pv0_data = {
520 .hvs_channel = 0,
521 .encoder0_type = VC4_ENCODER_TYPE_DSI0,
522 .encoder1_type = VC4_ENCODER_TYPE_DPI,
525 static const struct vc4_crtc_data pv1_data = {
526 .hvs_channel = 2,
527 .encoder0_type = VC4_ENCODER_TYPE_DSI1,
528 .encoder1_type = VC4_ENCODER_TYPE_SMI,
531 static const struct vc4_crtc_data pv2_data = {
532 .hvs_channel = 1,
533 .encoder0_type = VC4_ENCODER_TYPE_VEC,
534 .encoder1_type = VC4_ENCODER_TYPE_HDMI,
537 static const struct of_device_id vc4_crtc_dt_match[] = {
538 { .compatible = "brcm,bcm2835-pixelvalve0", .data = &pv0_data },
539 { .compatible = "brcm,bcm2835-pixelvalve1", .data = &pv1_data },
540 { .compatible = "brcm,bcm2835-pixelvalve2", .data = &pv2_data },
544 static void vc4_set_crtc_possible_masks(struct drm_device *drm,
545 struct drm_crtc *crtc)
547 struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
548 struct drm_encoder *encoder;
550 drm_for_each_encoder(encoder, drm) {
551 struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder);
553 if (vc4_encoder->type == vc4_crtc->data->encoder0_type) {
554 vc4_encoder->clock_select = 0;
555 encoder->possible_crtcs |= drm_crtc_mask(crtc);
556 } else if (vc4_encoder->type == vc4_crtc->data->encoder1_type) {
557 vc4_encoder->clock_select = 1;
558 encoder->possible_crtcs |= drm_crtc_mask(crtc);
563 static int vc4_crtc_bind(struct device *dev, struct device *master, void *data)
565 struct platform_device *pdev = to_platform_device(dev);
566 struct drm_device *drm = dev_get_drvdata(master);
567 struct vc4_dev *vc4 = to_vc4_dev(drm);
568 struct vc4_crtc *vc4_crtc;
569 struct drm_crtc *crtc;
570 struct drm_plane *primary_plane, *cursor_plane;
571 const struct of_device_id *match;
572 int ret;
574 vc4_crtc = devm_kzalloc(dev, sizeof(*vc4_crtc), GFP_KERNEL);
575 if (!vc4_crtc)
576 return -ENOMEM;
577 crtc = &vc4_crtc->base;
579 match = of_match_device(vc4_crtc_dt_match, dev);
580 if (!match)
581 return -ENODEV;
582 vc4_crtc->data = match->data;
584 vc4_crtc->regs = vc4_ioremap_regs(pdev, 0);
585 if (IS_ERR(vc4_crtc->regs))
586 return PTR_ERR(vc4_crtc->regs);
588 /* For now, we create just the primary and the legacy cursor
589 * planes. We should be able to stack more planes on easily,
590 * but to do that we would need to compute the bandwidth
591 * requirement of the plane configuration, and reject ones
592 * that will take too much.
594 primary_plane = vc4_plane_init(drm, DRM_PLANE_TYPE_PRIMARY);
595 if (IS_ERR(primary_plane)) {
596 dev_err(dev, "failed to construct primary plane\n");
597 ret = PTR_ERR(primary_plane);
598 goto err;
601 cursor_plane = vc4_plane_init(drm, DRM_PLANE_TYPE_CURSOR);
602 if (IS_ERR(cursor_plane)) {
603 dev_err(dev, "failed to construct cursor plane\n");
604 ret = PTR_ERR(cursor_plane);
605 goto err_primary;
608 drm_crtc_init_with_planes(drm, crtc, primary_plane, cursor_plane,
609 &vc4_crtc_funcs);
610 drm_crtc_helper_add(crtc, &vc4_crtc_helper_funcs);
611 primary_plane->crtc = crtc;
612 cursor_plane->crtc = crtc;
613 vc4->crtc[drm_crtc_index(crtc)] = vc4_crtc;
614 vc4_crtc->channel = vc4_crtc->data->hvs_channel;
616 CRTC_WRITE(PV_INTEN, 0);
617 CRTC_WRITE(PV_INTSTAT, PV_INT_VFP_START);
618 ret = devm_request_irq(dev, platform_get_irq(pdev, 0),
619 vc4_crtc_irq_handler, 0, "vc4 crtc", vc4_crtc);
620 if (ret)
621 goto err_cursor;
623 vc4_set_crtc_possible_masks(drm, crtc);
625 platform_set_drvdata(pdev, vc4_crtc);
627 return 0;
629 err_cursor:
630 cursor_plane->funcs->destroy(cursor_plane);
631 err_primary:
632 primary_plane->funcs->destroy(primary_plane);
633 err:
634 return ret;
637 static void vc4_crtc_unbind(struct device *dev, struct device *master,
638 void *data)
640 struct platform_device *pdev = to_platform_device(dev);
641 struct vc4_crtc *vc4_crtc = dev_get_drvdata(dev);
643 vc4_crtc_destroy(&vc4_crtc->base);
645 CRTC_WRITE(PV_INTEN, 0);
647 platform_set_drvdata(pdev, NULL);
650 static const struct component_ops vc4_crtc_ops = {
651 .bind = vc4_crtc_bind,
652 .unbind = vc4_crtc_unbind,
655 static int vc4_crtc_dev_probe(struct platform_device *pdev)
657 return component_add(&pdev->dev, &vc4_crtc_ops);
660 static int vc4_crtc_dev_remove(struct platform_device *pdev)
662 component_del(&pdev->dev, &vc4_crtc_ops);
663 return 0;
666 struct platform_driver vc4_crtc_driver = {
667 .probe = vc4_crtc_dev_probe,
668 .remove = vc4_crtc_dev_remove,
669 .driver = {
670 .name = "vc4_crtc",
671 .of_match_table = vc4_crtc_dt_match,