1 // SPDX-License-Identifier: GPL-2.0+
3 * R-Car Display Unit DRM driver
5 * Copyright (C) 2013-2015 Renesas Electronics Corporation
7 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
10 #include <linux/clk.h>
11 #include <linux/dma-mapping.h>
14 #include <linux/module.h>
15 #include <linux/of_device.h>
16 #include <linux/platform_device.h>
18 #include <linux/slab.h>
19 #include <linux/wait.h>
21 #include <drm/drm_atomic_helper.h>
22 #include <drm/drm_drv.h>
23 #include <drm/drm_fbdev_generic.h>
24 #include <drm/drm_gem_dma_helper.h>
25 #include <drm/drm_managed.h>
26 #include <drm/drm_probe_helper.h>
28 #include "rcar_du_drv.h"
29 #include "rcar_du_kms.h"
31 /* -----------------------------------------------------------------------------
35 static const struct rcar_du_device_info rzg1_du_r8a7743_info = {
37 .features = RCAR_DU_FEATURE_CRTC_IRQ
38 | RCAR_DU_FEATURE_CRTC_CLOCK
39 | RCAR_DU_FEATURE_INTERLACED
40 | RCAR_DU_FEATURE_TVM_SYNC,
41 .channels_mask = BIT(1) | BIT(0),
44 * R8A774[34] has one RGB output and one LVDS output
46 [RCAR_DU_OUTPUT_DPAD0] = {
47 .possible_crtcs = BIT(1) | BIT(0),
50 [RCAR_DU_OUTPUT_LVDS0] = {
51 .possible_crtcs = BIT(0),
59 static const struct rcar_du_device_info rzg1_du_r8a7745_info = {
61 .features = RCAR_DU_FEATURE_CRTC_IRQ
62 | RCAR_DU_FEATURE_CRTC_CLOCK
63 | RCAR_DU_FEATURE_INTERLACED
64 | RCAR_DU_FEATURE_TVM_SYNC,
65 .channels_mask = BIT(1) | BIT(0),
68 * R8A7745 has two RGB outputs
70 [RCAR_DU_OUTPUT_DPAD0] = {
71 .possible_crtcs = BIT(0),
74 [RCAR_DU_OUTPUT_DPAD1] = {
75 .possible_crtcs = BIT(1),
82 static const struct rcar_du_device_info rzg1_du_r8a77470_info = {
84 .features = RCAR_DU_FEATURE_CRTC_IRQ
85 | RCAR_DU_FEATURE_CRTC_CLOCK
86 | RCAR_DU_FEATURE_INTERLACED
87 | RCAR_DU_FEATURE_TVM_SYNC,
88 .channels_mask = BIT(1) | BIT(0),
91 * R8A77470 has two RGB outputs, one LVDS output, and
92 * one (currently unsupported) analog video output
94 [RCAR_DU_OUTPUT_DPAD0] = {
95 .possible_crtcs = BIT(0),
98 [RCAR_DU_OUTPUT_DPAD1] = {
99 .possible_crtcs = BIT(1),
102 [RCAR_DU_OUTPUT_LVDS0] = {
103 .possible_crtcs = BIT(0) | BIT(1),
110 static const struct rcar_du_device_info rcar_du_r8a774a1_info = {
112 .features = RCAR_DU_FEATURE_CRTC_IRQ
113 | RCAR_DU_FEATURE_CRTC_CLOCK
114 | RCAR_DU_FEATURE_VSP1_SOURCE
115 | RCAR_DU_FEATURE_INTERLACED
116 | RCAR_DU_FEATURE_TVM_SYNC,
117 .channels_mask = BIT(2) | BIT(1) | BIT(0),
120 * R8A774A1 has one RGB output, one LVDS output and one HDMI
123 [RCAR_DU_OUTPUT_DPAD0] = {
124 .possible_crtcs = BIT(2),
127 [RCAR_DU_OUTPUT_HDMI0] = {
128 .possible_crtcs = BIT(1),
131 [RCAR_DU_OUTPUT_LVDS0] = {
132 .possible_crtcs = BIT(0),
141 static const struct rcar_du_device_info rcar_du_r8a774b1_info = {
143 .features = RCAR_DU_FEATURE_CRTC_IRQ
144 | RCAR_DU_FEATURE_CRTC_CLOCK
145 | RCAR_DU_FEATURE_VSP1_SOURCE
146 | RCAR_DU_FEATURE_INTERLACED
147 | RCAR_DU_FEATURE_TVM_SYNC,
148 .channels_mask = BIT(3) | BIT(1) | BIT(0),
151 * R8A774B1 has one RGB output, one LVDS output and one HDMI
154 [RCAR_DU_OUTPUT_DPAD0] = {
155 .possible_crtcs = BIT(2),
158 [RCAR_DU_OUTPUT_HDMI0] = {
159 .possible_crtcs = BIT(1),
162 [RCAR_DU_OUTPUT_LVDS0] = {
163 .possible_crtcs = BIT(0),
172 static const struct rcar_du_device_info rcar_du_r8a774c0_info = {
174 .features = RCAR_DU_FEATURE_CRTC_IRQ
175 | RCAR_DU_FEATURE_CRTC_CLOCK
176 | RCAR_DU_FEATURE_VSP1_SOURCE,
177 .channels_mask = BIT(1) | BIT(0),
180 * R8A774C0 has one RGB output and two LVDS outputs
182 [RCAR_DU_OUTPUT_DPAD0] = {
183 .possible_crtcs = BIT(0) | BIT(1),
186 [RCAR_DU_OUTPUT_LVDS0] = {
187 .possible_crtcs = BIT(0),
190 [RCAR_DU_OUTPUT_LVDS1] = {
191 .possible_crtcs = BIT(1),
197 .lvds_clk_mask = BIT(1) | BIT(0),
200 static const struct rcar_du_device_info rcar_du_r8a774e1_info = {
202 .features = RCAR_DU_FEATURE_CRTC_IRQ
203 | RCAR_DU_FEATURE_CRTC_CLOCK
204 | RCAR_DU_FEATURE_VSP1_SOURCE
205 | RCAR_DU_FEATURE_INTERLACED
206 | RCAR_DU_FEATURE_TVM_SYNC,
207 .channels_mask = BIT(3) | BIT(1) | BIT(0),
210 * R8A774E1 has one RGB output, one LVDS output and one HDMI
213 [RCAR_DU_OUTPUT_DPAD0] = {
214 .possible_crtcs = BIT(2),
217 [RCAR_DU_OUTPUT_HDMI0] = {
218 .possible_crtcs = BIT(1),
221 [RCAR_DU_OUTPUT_LVDS0] = {
222 .possible_crtcs = BIT(0),
231 static const struct rcar_du_device_info rcar_du_r8a7779_info = {
233 .features = RCAR_DU_FEATURE_INTERLACED
234 | RCAR_DU_FEATURE_TVM_SYNC,
235 .channels_mask = BIT(1) | BIT(0),
238 * R8A7779 has two RGB outputs and one (currently unsupported)
241 [RCAR_DU_OUTPUT_DPAD0] = {
242 .possible_crtcs = BIT(0),
245 [RCAR_DU_OUTPUT_DPAD1] = {
246 .possible_crtcs = BIT(1) | BIT(0),
252 static const struct rcar_du_device_info rcar_du_r8a7790_info = {
254 .features = RCAR_DU_FEATURE_CRTC_IRQ
255 | RCAR_DU_FEATURE_CRTC_CLOCK
256 | RCAR_DU_FEATURE_INTERLACED
257 | RCAR_DU_FEATURE_TVM_SYNC,
258 .quirks = RCAR_DU_QUIRK_ALIGN_128B,
259 .channels_mask = BIT(2) | BIT(1) | BIT(0),
262 * R8A7742 and R8A7790 each have one RGB output and two LVDS
263 * outputs. Additionally R8A7790 supports one TCON output
264 * (currently unsupported by the driver).
266 [RCAR_DU_OUTPUT_DPAD0] = {
267 .possible_crtcs = BIT(2) | BIT(1) | BIT(0),
270 [RCAR_DU_OUTPUT_LVDS0] = {
271 .possible_crtcs = BIT(0),
274 [RCAR_DU_OUTPUT_LVDS1] = {
275 .possible_crtcs = BIT(2) | BIT(1),
283 /* M2-W (r8a7791) and M2-N (r8a7793) are identical */
284 static const struct rcar_du_device_info rcar_du_r8a7791_info = {
286 .features = RCAR_DU_FEATURE_CRTC_IRQ
287 | RCAR_DU_FEATURE_CRTC_CLOCK
288 | RCAR_DU_FEATURE_INTERLACED
289 | RCAR_DU_FEATURE_TVM_SYNC,
290 .channels_mask = BIT(1) | BIT(0),
293 * R8A779[13] has one RGB output, one LVDS output and one
294 * (currently unsupported) TCON output.
296 [RCAR_DU_OUTPUT_DPAD0] = {
297 .possible_crtcs = BIT(1) | BIT(0),
300 [RCAR_DU_OUTPUT_LVDS0] = {
301 .possible_crtcs = BIT(0),
309 static const struct rcar_du_device_info rcar_du_r8a7792_info = {
311 .features = RCAR_DU_FEATURE_CRTC_IRQ
312 | RCAR_DU_FEATURE_CRTC_CLOCK
313 | RCAR_DU_FEATURE_INTERLACED
314 | RCAR_DU_FEATURE_TVM_SYNC,
315 .channels_mask = BIT(1) | BIT(0),
317 /* R8A7792 has two RGB outputs. */
318 [RCAR_DU_OUTPUT_DPAD0] = {
319 .possible_crtcs = BIT(0),
322 [RCAR_DU_OUTPUT_DPAD1] = {
323 .possible_crtcs = BIT(1),
330 static const struct rcar_du_device_info rcar_du_r8a7794_info = {
332 .features = RCAR_DU_FEATURE_CRTC_IRQ
333 | RCAR_DU_FEATURE_CRTC_CLOCK
334 | RCAR_DU_FEATURE_INTERLACED
335 | RCAR_DU_FEATURE_TVM_SYNC,
336 .channels_mask = BIT(1) | BIT(0),
339 * R8A7794 has two RGB outputs and one (currently unsupported)
342 [RCAR_DU_OUTPUT_DPAD0] = {
343 .possible_crtcs = BIT(0),
346 [RCAR_DU_OUTPUT_DPAD1] = {
347 .possible_crtcs = BIT(1),
354 static const struct rcar_du_device_info rcar_du_r8a7795_info = {
356 .features = RCAR_DU_FEATURE_CRTC_IRQ
357 | RCAR_DU_FEATURE_CRTC_CLOCK
358 | RCAR_DU_FEATURE_VSP1_SOURCE
359 | RCAR_DU_FEATURE_INTERLACED
360 | RCAR_DU_FEATURE_TVM_SYNC,
361 .channels_mask = BIT(3) | BIT(2) | BIT(1) | BIT(0),
364 * R8A7795 has one RGB output, two HDMI outputs and one
367 [RCAR_DU_OUTPUT_DPAD0] = {
368 .possible_crtcs = BIT(3),
371 [RCAR_DU_OUTPUT_HDMI0] = {
372 .possible_crtcs = BIT(1),
375 [RCAR_DU_OUTPUT_HDMI1] = {
376 .possible_crtcs = BIT(2),
379 [RCAR_DU_OUTPUT_LVDS0] = {
380 .possible_crtcs = BIT(0),
386 .dpll_mask = BIT(2) | BIT(1),
389 static const struct rcar_du_device_info rcar_du_r8a7796_info = {
391 .features = RCAR_DU_FEATURE_CRTC_IRQ
392 | RCAR_DU_FEATURE_CRTC_CLOCK
393 | RCAR_DU_FEATURE_VSP1_SOURCE
394 | RCAR_DU_FEATURE_INTERLACED
395 | RCAR_DU_FEATURE_TVM_SYNC,
396 .channels_mask = BIT(2) | BIT(1) | BIT(0),
399 * R8A7796 has one RGB output, one LVDS output and one HDMI
402 [RCAR_DU_OUTPUT_DPAD0] = {
403 .possible_crtcs = BIT(2),
406 [RCAR_DU_OUTPUT_HDMI0] = {
407 .possible_crtcs = BIT(1),
410 [RCAR_DU_OUTPUT_LVDS0] = {
411 .possible_crtcs = BIT(0),
420 static const struct rcar_du_device_info rcar_du_r8a77965_info = {
422 .features = RCAR_DU_FEATURE_CRTC_IRQ
423 | RCAR_DU_FEATURE_CRTC_CLOCK
424 | RCAR_DU_FEATURE_VSP1_SOURCE
425 | RCAR_DU_FEATURE_INTERLACED
426 | RCAR_DU_FEATURE_TVM_SYNC,
427 .channels_mask = BIT(3) | BIT(1) | BIT(0),
430 * R8A77965 has one RGB output, one LVDS output and one HDMI
433 [RCAR_DU_OUTPUT_DPAD0] = {
434 .possible_crtcs = BIT(2),
437 [RCAR_DU_OUTPUT_HDMI0] = {
438 .possible_crtcs = BIT(1),
441 [RCAR_DU_OUTPUT_LVDS0] = {
442 .possible_crtcs = BIT(0),
451 static const struct rcar_du_device_info rcar_du_r8a77970_info = {
453 .features = RCAR_DU_FEATURE_CRTC_IRQ
454 | RCAR_DU_FEATURE_CRTC_CLOCK
455 | RCAR_DU_FEATURE_VSP1_SOURCE
456 | RCAR_DU_FEATURE_INTERLACED
457 | RCAR_DU_FEATURE_TVM_SYNC,
458 .channels_mask = BIT(0),
461 * R8A77970 and R8A77980 have one RGB output and one LVDS
464 [RCAR_DU_OUTPUT_DPAD0] = {
465 .possible_crtcs = BIT(0),
468 [RCAR_DU_OUTPUT_LVDS0] = {
469 .possible_crtcs = BIT(0),
477 static const struct rcar_du_device_info rcar_du_r8a7799x_info = {
479 .features = RCAR_DU_FEATURE_CRTC_IRQ
480 | RCAR_DU_FEATURE_CRTC_CLOCK
481 | RCAR_DU_FEATURE_VSP1_SOURCE,
482 .channels_mask = BIT(1) | BIT(0),
485 * R8A77990 and R8A77995 have one RGB output and two LVDS
488 [RCAR_DU_OUTPUT_DPAD0] = {
489 .possible_crtcs = BIT(0) | BIT(1),
492 [RCAR_DU_OUTPUT_LVDS0] = {
493 .possible_crtcs = BIT(0),
496 [RCAR_DU_OUTPUT_LVDS1] = {
497 .possible_crtcs = BIT(1),
503 .lvds_clk_mask = BIT(1) | BIT(0),
506 static const struct rcar_du_device_info rcar_du_r8a779a0_info = {
508 .features = RCAR_DU_FEATURE_CRTC_IRQ
509 | RCAR_DU_FEATURE_VSP1_SOURCE
510 | RCAR_DU_FEATURE_NO_BLENDING,
511 .channels_mask = BIT(1) | BIT(0),
513 /* R8A779A0 has two MIPI DSI outputs. */
514 [RCAR_DU_OUTPUT_DSI0] = {
515 .possible_crtcs = BIT(0),
518 [RCAR_DU_OUTPUT_DSI1] = {
519 .possible_crtcs = BIT(1),
524 .dsi_clk_mask = BIT(1) | BIT(0),
527 static const struct of_device_id rcar_du_of_table[] = {
528 { .compatible = "renesas,du-r8a7742", .data = &rcar_du_r8a7790_info },
529 { .compatible = "renesas,du-r8a7743", .data = &rzg1_du_r8a7743_info },
530 { .compatible = "renesas,du-r8a7744", .data = &rzg1_du_r8a7743_info },
531 { .compatible = "renesas,du-r8a7745", .data = &rzg1_du_r8a7745_info },
532 { .compatible = "renesas,du-r8a77470", .data = &rzg1_du_r8a77470_info },
533 { .compatible = "renesas,du-r8a774a1", .data = &rcar_du_r8a774a1_info },
534 { .compatible = "renesas,du-r8a774b1", .data = &rcar_du_r8a774b1_info },
535 { .compatible = "renesas,du-r8a774c0", .data = &rcar_du_r8a774c0_info },
536 { .compatible = "renesas,du-r8a774e1", .data = &rcar_du_r8a774e1_info },
537 { .compatible = "renesas,du-r8a7779", .data = &rcar_du_r8a7779_info },
538 { .compatible = "renesas,du-r8a7790", .data = &rcar_du_r8a7790_info },
539 { .compatible = "renesas,du-r8a7791", .data = &rcar_du_r8a7791_info },
540 { .compatible = "renesas,du-r8a7792", .data = &rcar_du_r8a7792_info },
541 { .compatible = "renesas,du-r8a7793", .data = &rcar_du_r8a7791_info },
542 { .compatible = "renesas,du-r8a7794", .data = &rcar_du_r8a7794_info },
543 { .compatible = "renesas,du-r8a7795", .data = &rcar_du_r8a7795_info },
544 { .compatible = "renesas,du-r8a7796", .data = &rcar_du_r8a7796_info },
545 { .compatible = "renesas,du-r8a77961", .data = &rcar_du_r8a7796_info },
546 { .compatible = "renesas,du-r8a77965", .data = &rcar_du_r8a77965_info },
547 { .compatible = "renesas,du-r8a77970", .data = &rcar_du_r8a77970_info },
548 { .compatible = "renesas,du-r8a77980", .data = &rcar_du_r8a77970_info },
549 { .compatible = "renesas,du-r8a77990", .data = &rcar_du_r8a7799x_info },
550 { .compatible = "renesas,du-r8a77995", .data = &rcar_du_r8a7799x_info },
551 { .compatible = "renesas,du-r8a779a0", .data = &rcar_du_r8a779a0_info },
555 MODULE_DEVICE_TABLE(of, rcar_du_of_table);
557 const char *rcar_du_output_name(enum rcar_du_output output)
559 static const char * const names[] = {
560 [RCAR_DU_OUTPUT_DPAD0] = "DPAD0",
561 [RCAR_DU_OUTPUT_DPAD1] = "DPAD1",
562 [RCAR_DU_OUTPUT_DSI0] = "DSI0",
563 [RCAR_DU_OUTPUT_DSI1] = "DSI1",
564 [RCAR_DU_OUTPUT_HDMI0] = "HDMI0",
565 [RCAR_DU_OUTPUT_HDMI1] = "HDMI1",
566 [RCAR_DU_OUTPUT_LVDS0] = "LVDS0",
567 [RCAR_DU_OUTPUT_LVDS1] = "LVDS1",
568 [RCAR_DU_OUTPUT_TCON] = "TCON",
571 if (output >= ARRAY_SIZE(names) || !names[output])
574 return names[output];
577 /* -----------------------------------------------------------------------------
581 DEFINE_DRM_GEM_DMA_FOPS(rcar_du_fops);
583 static const struct drm_driver rcar_du_driver = {
584 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
585 .dumb_create = rcar_du_dumb_create,
586 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
587 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
588 .gem_prime_import_sg_table = rcar_du_gem_prime_import_sg_table,
589 .gem_prime_mmap = drm_gem_prime_mmap,
590 .fops = &rcar_du_fops,
592 .desc = "Renesas R-Car Display Unit",
598 /* -----------------------------------------------------------------------------
602 #ifdef CONFIG_PM_SLEEP
603 static int rcar_du_pm_suspend(struct device *dev)
605 struct rcar_du_device *rcdu = dev_get_drvdata(dev);
607 return drm_mode_config_helper_suspend(&rcdu->ddev);
610 static int rcar_du_pm_resume(struct device *dev)
612 struct rcar_du_device *rcdu = dev_get_drvdata(dev);
614 return drm_mode_config_helper_resume(&rcdu->ddev);
618 static const struct dev_pm_ops rcar_du_pm_ops = {
619 SET_SYSTEM_SLEEP_PM_OPS(rcar_du_pm_suspend, rcar_du_pm_resume)
622 /* -----------------------------------------------------------------------------
626 static int rcar_du_remove(struct platform_device *pdev)
628 struct rcar_du_device *rcdu = platform_get_drvdata(pdev);
629 struct drm_device *ddev = &rcdu->ddev;
631 drm_dev_unregister(ddev);
632 drm_atomic_helper_shutdown(ddev);
634 drm_kms_helper_poll_fini(ddev);
639 static void rcar_du_shutdown(struct platform_device *pdev)
641 struct rcar_du_device *rcdu = platform_get_drvdata(pdev);
643 drm_atomic_helper_shutdown(&rcdu->ddev);
646 static int rcar_du_probe(struct platform_device *pdev)
648 struct rcar_du_device *rcdu;
652 if (drm_firmware_drivers_only())
655 /* Allocate and initialize the R-Car device structure. */
656 rcdu = devm_drm_dev_alloc(&pdev->dev, &rcar_du_driver,
657 struct rcar_du_device, ddev);
659 return PTR_ERR(rcdu);
661 rcdu->dev = &pdev->dev;
662 rcdu->info = of_device_get_match_data(rcdu->dev);
664 platform_set_drvdata(pdev, rcdu);
667 rcdu->mmio = devm_platform_ioremap_resource(pdev, 0);
668 if (IS_ERR(rcdu->mmio))
669 return PTR_ERR(rcdu->mmio);
672 * Set the DMA coherent mask to reflect the DU 32-bit DMA address space
673 * limitations. When sourcing frames from a VSP the DU doesn't perform
674 * any memory access so set the mask to 40 bits to accept all buffers.
676 mask = rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE) ? 40 : 32;
677 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(mask));
681 /* DRM/KMS objects */
682 ret = rcar_du_modeset_init(rcdu);
684 if (ret != -EPROBE_DEFER)
686 "failed to initialize DRM/KMS (%d)\n", ret);
691 * Register the DRM device with the core and the connectors with
694 ret = drm_dev_register(&rcdu->ddev, 0);
698 DRM_INFO("Device %s probed\n", dev_name(&pdev->dev));
700 drm_fbdev_generic_setup(&rcdu->ddev, 32);
705 drm_kms_helper_poll_fini(&rcdu->ddev);
709 static struct platform_driver rcar_du_platform_driver = {
710 .probe = rcar_du_probe,
711 .remove = rcar_du_remove,
712 .shutdown = rcar_du_shutdown,
715 .pm = &rcar_du_pm_ops,
716 .of_match_table = rcar_du_of_table,
720 module_platform_driver(rcar_du_platform_driver);
722 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
723 MODULE_DESCRIPTION("Renesas R-Car Display Unit DRM Driver");
724 MODULE_LICENSE("GPL");