2 * rcar_du_drv.c -- R-Car Display Unit DRM driver
4 * Copyright (C) 2013 Renesas Corporation
6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/clk.h>
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
20 #include <linux/slab.h>
23 #include <drm/drm_crtc_helper.h>
24 #include <drm/drm_gem_cma_helper.h>
26 #include "rcar_du_crtc.h"
27 #include "rcar_du_drv.h"
28 #include "rcar_du_kms.h"
29 #include "rcar_du_regs.h"
31 /* -----------------------------------------------------------------------------
35 static int rcar_du_unload(struct drm_device *dev)
37 drm_kms_helper_poll_fini(dev);
38 drm_mode_config_cleanup(dev);
39 drm_vblank_cleanup(dev);
42 dev->dev_private = NULL;
47 static int rcar_du_load(struct drm_device *dev, unsigned long flags)
49 struct platform_device *pdev = dev->platformdev;
50 struct rcar_du_platform_data *pdata = pdev->dev.platform_data;
51 struct rcar_du_device *rcdu;
56 dev_err(dev->dev, "no platform data\n");
60 rcdu = devm_kzalloc(&pdev->dev, sizeof(*rcdu), GFP_KERNEL);
62 dev_err(dev->dev, "failed to allocate private data\n");
66 rcdu->dev = &pdev->dev;
68 rcdu->info = (struct rcar_du_device_info *)pdev->id_entry->driver_data;
70 dev->dev_private = rcdu;
73 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
74 rcdu->mmio = devm_ioremap_resource(&pdev->dev, mem);
75 if (IS_ERR(rcdu->mmio))
76 return PTR_ERR(rcdu->mmio);
79 ret = rcar_du_modeset_init(rcdu);
81 dev_err(&pdev->dev, "failed to initialize DRM/KMS\n");
86 ret = drm_vblank_init(dev, (1 << rcdu->num_crtcs) - 1);
88 dev_err(&pdev->dev, "failed to initialize vblank\n");
94 platform_set_drvdata(pdev, rcdu);
103 static void rcar_du_preclose(struct drm_device *dev, struct drm_file *file)
105 struct rcar_du_device *rcdu = dev->dev_private;
108 for (i = 0; i < rcdu->num_crtcs; ++i)
109 rcar_du_crtc_cancel_page_flip(&rcdu->crtcs[i], file);
112 static int rcar_du_enable_vblank(struct drm_device *dev, int crtc)
114 struct rcar_du_device *rcdu = dev->dev_private;
116 rcar_du_crtc_enable_vblank(&rcdu->crtcs[crtc], true);
121 static void rcar_du_disable_vblank(struct drm_device *dev, int crtc)
123 struct rcar_du_device *rcdu = dev->dev_private;
125 rcar_du_crtc_enable_vblank(&rcdu->crtcs[crtc], false);
128 static const struct file_operations rcar_du_fops = {
129 .owner = THIS_MODULE,
131 .release = drm_release,
132 .unlocked_ioctl = drm_ioctl,
134 .compat_ioctl = drm_compat_ioctl,
138 .fasync = drm_fasync,
140 .mmap = drm_gem_cma_mmap,
143 static struct drm_driver rcar_du_driver = {
144 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME,
145 .load = rcar_du_load,
146 .unload = rcar_du_unload,
147 .preclose = rcar_du_preclose,
148 .get_vblank_counter = drm_vblank_count,
149 .enable_vblank = rcar_du_enable_vblank,
150 .disable_vblank = rcar_du_disable_vblank,
151 .gem_free_object = drm_gem_cma_free_object,
152 .gem_vm_ops = &drm_gem_cma_vm_ops,
153 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
154 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
155 .gem_prime_import = drm_gem_prime_import,
156 .gem_prime_export = drm_gem_prime_export,
157 .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
158 .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
159 .gem_prime_vmap = drm_gem_cma_prime_vmap,
160 .gem_prime_vunmap = drm_gem_cma_prime_vunmap,
161 .gem_prime_mmap = drm_gem_cma_prime_mmap,
162 .dumb_create = rcar_du_dumb_create,
163 .dumb_map_offset = drm_gem_cma_dumb_map_offset,
164 .dumb_destroy = drm_gem_cma_dumb_destroy,
165 .fops = &rcar_du_fops,
167 .desc = "Renesas R-Car Display Unit",
173 /* -----------------------------------------------------------------------------
178 static int rcar_du_pm_suspend(struct device *dev)
180 struct rcar_du_device *rcdu = dev_get_drvdata(dev);
182 drm_kms_helper_poll_disable(rcdu->ddev);
183 /* TODO Suspend the CRTC */
188 static int rcar_du_pm_resume(struct device *dev)
190 struct rcar_du_device *rcdu = dev_get_drvdata(dev);
192 /* TODO Resume the CRTC */
194 drm_kms_helper_poll_enable(rcdu->ddev);
199 static const struct dev_pm_ops rcar_du_pm_ops = {
200 SET_SYSTEM_SLEEP_PM_OPS(rcar_du_pm_suspend, rcar_du_pm_resume)
203 /* -----------------------------------------------------------------------------
207 static int rcar_du_probe(struct platform_device *pdev)
209 return drm_platform_init(&rcar_du_driver, pdev);
212 static int rcar_du_remove(struct platform_device *pdev)
214 drm_platform_exit(&rcar_du_driver, pdev);
219 static const struct rcar_du_device_info rcar_du_r8a7779_info = {
223 /* R8A7779 has two RGB outputs and one (currently unsupported)
226 [RCAR_DU_OUTPUT_DPAD0] = {
227 .possible_crtcs = BIT(0),
228 .encoder_type = DRM_MODE_ENCODER_NONE,
230 [RCAR_DU_OUTPUT_DPAD1] = {
231 .possible_crtcs = BIT(1) | BIT(0),
232 .encoder_type = DRM_MODE_ENCODER_NONE,
237 static const struct rcar_du_device_info rcar_du_r8a7790_info = {
238 .features = RCAR_DU_FEATURE_CRTC_IRQ_CLOCK | RCAR_DU_FEATURE_ALIGN_128B
239 | RCAR_DU_FEATURE_DEFR8,
242 /* R8A7790 has one RGB output, two LVDS outputs and one
243 * (currently unsupported) TCON output.
245 [RCAR_DU_OUTPUT_DPAD0] = {
246 .possible_crtcs = BIT(2) | BIT(1) | BIT(0),
247 .encoder_type = DRM_MODE_ENCODER_NONE,
249 [RCAR_DU_OUTPUT_LVDS0] = {
250 .possible_crtcs = BIT(0),
251 .encoder_type = DRM_MODE_ENCODER_LVDS,
253 [RCAR_DU_OUTPUT_LVDS1] = {
254 .possible_crtcs = BIT(2) | BIT(1),
255 .encoder_type = DRM_MODE_ENCODER_LVDS,
260 static const struct platform_device_id rcar_du_id_table[] = {
261 { "rcar-du-r8a7779", (kernel_ulong_t)&rcar_du_r8a7779_info },
262 { "rcar-du-r8a7790", (kernel_ulong_t)&rcar_du_r8a7790_info },
266 MODULE_DEVICE_TABLE(platform, rcar_du_id_table);
268 static struct platform_driver rcar_du_platform_driver = {
269 .probe = rcar_du_probe,
270 .remove = rcar_du_remove,
272 .owner = THIS_MODULE,
274 .pm = &rcar_du_pm_ops,
276 .id_table = rcar_du_id_table,
279 module_platform_driver(rcar_du_platform_driver);
281 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
282 MODULE_DESCRIPTION("Renesas R-Car Display Unit DRM Driver");
283 MODULE_LICENSE("GPL");