2013-06-19 19:54:11 +08:00
|
|
|
/*
|
|
|
|
* rcar_du_drv.c -- R-Car Display Unit DRM driver
|
|
|
|
*
|
2015-09-07 22:34:26 +08:00
|
|
|
* Copyright (C) 2013-2015 Renesas Electronics Corporation
|
2013-06-19 19:54:11 +08:00
|
|
|
*
|
|
|
|
* Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/module.h>
|
2014-01-21 22:57:26 +08:00
|
|
|
#include <linux/of_device.h>
|
2013-06-19 19:54:11 +08:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/slab.h>
|
2015-02-23 07:02:15 +08:00
|
|
|
#include <linux/wait.h>
|
2013-06-19 19:54:11 +08:00
|
|
|
|
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/drm_crtc_helper.h>
|
2013-03-15 05:45:22 +08:00
|
|
|
#include <drm/drm_fb_cma_helper.h>
|
2013-06-19 19:54:11 +08:00
|
|
|
#include <drm/drm_gem_cma_helper.h>
|
|
|
|
|
|
|
|
#include "rcar_du_crtc.h"
|
|
|
|
#include "rcar_du_drv.h"
|
|
|
|
#include "rcar_du_kms.h"
|
|
|
|
#include "rcar_du_regs.h"
|
|
|
|
|
2014-01-21 22:57:26 +08:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Device Information
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const struct rcar_du_device_info rcar_du_r8a7779_info = {
|
2015-09-07 22:34:26 +08:00
|
|
|
.gen = 2,
|
2014-01-21 22:57:26 +08:00
|
|
|
.features = 0,
|
|
|
|
.num_crtcs = 2,
|
|
|
|
.routes = {
|
|
|
|
/* R8A7779 has two RGB outputs and one (currently unsupported)
|
|
|
|
* TCON output.
|
|
|
|
*/
|
|
|
|
[RCAR_DU_OUTPUT_DPAD0] = {
|
|
|
|
.possible_crtcs = BIT(0),
|
|
|
|
.encoder_type = DRM_MODE_ENCODER_NONE,
|
|
|
|
.port = 0,
|
|
|
|
},
|
|
|
|
[RCAR_DU_OUTPUT_DPAD1] = {
|
|
|
|
.possible_crtcs = BIT(1) | BIT(0),
|
|
|
|
.encoder_type = DRM_MODE_ENCODER_NONE,
|
|
|
|
.port = 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.num_lvds = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct rcar_du_device_info rcar_du_r8a7790_info = {
|
2015-09-07 22:34:26 +08:00
|
|
|
.gen = 2,
|
2014-12-09 06:21:12 +08:00
|
|
|
.features = RCAR_DU_FEATURE_CRTC_IRQ_CLOCK
|
|
|
|
| RCAR_DU_FEATURE_EXT_CTRL_REGS,
|
2014-01-21 22:57:26 +08:00
|
|
|
.quirks = RCAR_DU_QUIRK_ALIGN_128B | RCAR_DU_QUIRK_LVDS_LANES,
|
|
|
|
.num_crtcs = 3,
|
|
|
|
.routes = {
|
|
|
|
/* R8A7790 has one RGB output, two LVDS outputs and one
|
|
|
|
* (currently unsupported) TCON output.
|
|
|
|
*/
|
|
|
|
[RCAR_DU_OUTPUT_DPAD0] = {
|
|
|
|
.possible_crtcs = BIT(2) | BIT(1) | BIT(0),
|
|
|
|
.encoder_type = DRM_MODE_ENCODER_NONE,
|
|
|
|
.port = 0,
|
|
|
|
},
|
|
|
|
[RCAR_DU_OUTPUT_LVDS0] = {
|
|
|
|
.possible_crtcs = BIT(0),
|
|
|
|
.encoder_type = DRM_MODE_ENCODER_LVDS,
|
|
|
|
.port = 1,
|
|
|
|
},
|
|
|
|
[RCAR_DU_OUTPUT_LVDS1] = {
|
|
|
|
.possible_crtcs = BIT(2) | BIT(1),
|
|
|
|
.encoder_type = DRM_MODE_ENCODER_LVDS,
|
|
|
|
.port = 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.num_lvds = 2,
|
|
|
|
};
|
|
|
|
|
2015-07-17 15:44:33 +08:00
|
|
|
/* M2-W (r8a7791) and M2-N (r8a7793) are identical */
|
2014-01-21 22:57:26 +08:00
|
|
|
static const struct rcar_du_device_info rcar_du_r8a7791_info = {
|
2015-09-07 22:34:26 +08:00
|
|
|
.gen = 2,
|
2014-12-09 06:21:12 +08:00
|
|
|
.features = RCAR_DU_FEATURE_CRTC_IRQ_CLOCK
|
|
|
|
| RCAR_DU_FEATURE_EXT_CTRL_REGS,
|
2014-01-21 22:57:26 +08:00
|
|
|
.num_crtcs = 2,
|
|
|
|
.routes = {
|
2015-07-17 15:44:33 +08:00
|
|
|
/* R8A779[13] has one RGB output, one LVDS output and one
|
2014-01-21 22:57:26 +08:00
|
|
|
* (currently unsupported) TCON output.
|
|
|
|
*/
|
|
|
|
[RCAR_DU_OUTPUT_DPAD0] = {
|
2015-04-28 20:26:33 +08:00
|
|
|
.possible_crtcs = BIT(1) | BIT(0),
|
2014-01-21 22:57:26 +08:00
|
|
|
.encoder_type = DRM_MODE_ENCODER_NONE,
|
|
|
|
.port = 0,
|
|
|
|
},
|
|
|
|
[RCAR_DU_OUTPUT_LVDS0] = {
|
|
|
|
.possible_crtcs = BIT(0),
|
|
|
|
.encoder_type = DRM_MODE_ENCODER_LVDS,
|
|
|
|
.port = 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.num_lvds = 1,
|
|
|
|
};
|
|
|
|
|
2015-07-17 15:44:33 +08:00
|
|
|
static const struct rcar_du_device_info rcar_du_r8a7794_info = {
|
2015-09-07 22:34:26 +08:00
|
|
|
.gen = 2,
|
2015-07-17 15:44:33 +08:00
|
|
|
.features = RCAR_DU_FEATURE_CRTC_IRQ_CLOCK
|
|
|
|
| RCAR_DU_FEATURE_EXT_CTRL_REGS,
|
|
|
|
.num_crtcs = 2,
|
|
|
|
.routes = {
|
|
|
|
/* R8A7794 has two RGB outputs and one (currently unsupported)
|
|
|
|
* TCON output.
|
|
|
|
*/
|
|
|
|
[RCAR_DU_OUTPUT_DPAD0] = {
|
|
|
|
.possible_crtcs = BIT(0),
|
|
|
|
.encoder_type = DRM_MODE_ENCODER_NONE,
|
|
|
|
.port = 0,
|
|
|
|
},
|
|
|
|
[RCAR_DU_OUTPUT_DPAD1] = {
|
|
|
|
.possible_crtcs = BIT(1),
|
|
|
|
.encoder_type = DRM_MODE_ENCODER_NONE,
|
|
|
|
.port = 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.num_lvds = 0,
|
|
|
|
};
|
|
|
|
|
2015-09-07 22:34:26 +08:00
|
|
|
static const struct rcar_du_device_info rcar_du_r8a7795_info = {
|
|
|
|
.gen = 3,
|
|
|
|
.features = RCAR_DU_FEATURE_CRTC_IRQ_CLOCK
|
|
|
|
| RCAR_DU_FEATURE_EXT_CTRL_REGS
|
|
|
|
| RCAR_DU_FEATURE_VSP1_SOURCE,
|
|
|
|
.num_crtcs = 4,
|
|
|
|
.routes = {
|
2015-07-28 19:12:43 +08:00
|
|
|
/* R8A7795 has one RGB output, one LVDS output and two
|
|
|
|
* (currently unsupported) HDMI outputs.
|
2015-09-07 22:34:26 +08:00
|
|
|
*/
|
|
|
|
[RCAR_DU_OUTPUT_DPAD0] = {
|
|
|
|
.possible_crtcs = BIT(3),
|
|
|
|
.encoder_type = DRM_MODE_ENCODER_NONE,
|
|
|
|
.port = 0,
|
|
|
|
},
|
2015-07-28 19:12:43 +08:00
|
|
|
[RCAR_DU_OUTPUT_LVDS0] = {
|
|
|
|
.possible_crtcs = BIT(0),
|
|
|
|
.encoder_type = DRM_MODE_ENCODER_LVDS,
|
|
|
|
.port = 3,
|
|
|
|
},
|
2015-09-07 22:34:26 +08:00
|
|
|
},
|
2015-07-28 19:12:43 +08:00
|
|
|
.num_lvds = 1,
|
2015-09-07 22:34:26 +08:00
|
|
|
};
|
|
|
|
|
2014-01-21 22:57:26 +08:00
|
|
|
static const struct of_device_id rcar_du_of_table[] = {
|
|
|
|
{ .compatible = "renesas,du-r8a7779", .data = &rcar_du_r8a7779_info },
|
|
|
|
{ .compatible = "renesas,du-r8a7790", .data = &rcar_du_r8a7790_info },
|
|
|
|
{ .compatible = "renesas,du-r8a7791", .data = &rcar_du_r8a7791_info },
|
2015-07-17 15:44:33 +08:00
|
|
|
{ .compatible = "renesas,du-r8a7793", .data = &rcar_du_r8a7791_info },
|
2015-07-17 15:44:33 +08:00
|
|
|
{ .compatible = "renesas,du-r8a7794", .data = &rcar_du_r8a7794_info },
|
2015-09-07 22:34:26 +08:00
|
|
|
{ .compatible = "renesas,du-r8a7795", .data = &rcar_du_r8a7795_info },
|
2014-01-21 22:57:26 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(of, rcar_du_of_table);
|
|
|
|
|
2013-06-19 19:54:11 +08:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* DRM operations
|
|
|
|
*/
|
|
|
|
|
2013-03-15 05:45:22 +08:00
|
|
|
static void rcar_du_lastclose(struct drm_device *dev)
|
2013-06-19 19:54:11 +08:00
|
|
|
{
|
|
|
|
struct rcar_du_device *rcdu = dev->dev_private;
|
|
|
|
|
2013-03-15 05:45:22 +08:00
|
|
|
drm_fbdev_cma_restore_mode(rcdu->fbdev);
|
2013-06-19 19:54:11 +08:00
|
|
|
}
|
|
|
|
|
2015-09-25 00:35:31 +08:00
|
|
|
static int rcar_du_enable_vblank(struct drm_device *dev, unsigned int pipe)
|
2013-06-19 19:54:11 +08:00
|
|
|
{
|
|
|
|
struct rcar_du_device *rcdu = dev->dev_private;
|
|
|
|
|
2015-09-25 00:35:31 +08:00
|
|
|
rcar_du_crtc_enable_vblank(&rcdu->crtcs[pipe], true);
|
2013-06-19 19:54:11 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-25 00:35:31 +08:00
|
|
|
static void rcar_du_disable_vblank(struct drm_device *dev, unsigned int pipe)
|
2013-06-19 19:54:11 +08:00
|
|
|
{
|
|
|
|
struct rcar_du_device *rcdu = dev->dev_private;
|
|
|
|
|
2015-09-25 00:35:31 +08:00
|
|
|
rcar_du_crtc_enable_vblank(&rcdu->crtcs[pipe], false);
|
2013-06-19 19:54:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations rcar_du_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = drm_open,
|
|
|
|
.release = drm_release,
|
|
|
|
.unlocked_ioctl = drm_ioctl,
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
.compat_ioctl = drm_compat_ioctl,
|
|
|
|
#endif
|
|
|
|
.poll = drm_poll,
|
|
|
|
.read = drm_read,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.mmap = drm_gem_cma_mmap,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct drm_driver rcar_du_driver = {
|
2015-02-27 03:22:10 +08:00
|
|
|
.driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME
|
|
|
|
| DRIVER_ATOMIC,
|
2013-03-15 05:45:22 +08:00
|
|
|
.lastclose = rcar_du_lastclose,
|
2015-09-30 21:46:48 +08:00
|
|
|
.get_vblank_counter = drm_vblank_no_hw_counter,
|
2013-06-19 19:54:11 +08:00
|
|
|
.enable_vblank = rcar_du_enable_vblank,
|
|
|
|
.disable_vblank = rcar_du_disable_vblank,
|
2016-05-31 01:53:02 +08:00
|
|
|
.gem_free_object_unlocked = drm_gem_cma_free_object,
|
2013-06-19 19:54:11 +08:00
|
|
|
.gem_vm_ops = &drm_gem_cma_vm_ops,
|
|
|
|
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
|
|
|
|
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
|
2013-07-10 21:23:35 +08:00
|
|
|
.gem_prime_import = drm_gem_prime_import,
|
|
|
|
.gem_prime_export = drm_gem_prime_export,
|
|
|
|
.gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
|
|
|
|
.gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
|
|
|
|
.gem_prime_vmap = drm_gem_cma_prime_vmap,
|
|
|
|
.gem_prime_vunmap = drm_gem_cma_prime_vunmap,
|
|
|
|
.gem_prime_mmap = drm_gem_cma_prime_mmap,
|
2013-07-05 02:05:51 +08:00
|
|
|
.dumb_create = rcar_du_dumb_create,
|
2013-06-19 19:54:11 +08:00
|
|
|
.dumb_map_offset = drm_gem_cma_dumb_map_offset,
|
2013-07-16 15:12:04 +08:00
|
|
|
.dumb_destroy = drm_gem_dumb_destroy,
|
2013-06-19 19:54:11 +08:00
|
|
|
.fops = &rcar_du_fops,
|
|
|
|
.name = "rcar-du",
|
|
|
|
.desc = "Renesas R-Car Display Unit",
|
|
|
|
.date = "20130110",
|
|
|
|
.major = 1,
|
|
|
|
.minor = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Power management
|
|
|
|
*/
|
|
|
|
|
2014-07-13 19:18:58 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2013-06-19 19:54:11 +08:00
|
|
|
static int rcar_du_pm_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct rcar_du_device *rcdu = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
drm_kms_helper_poll_disable(rcdu->ddev);
|
|
|
|
/* TODO Suspend the CRTC */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rcar_du_pm_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct rcar_du_device *rcdu = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
/* TODO Resume the CRTC */
|
|
|
|
|
|
|
|
drm_kms_helper_poll_enable(rcdu->ddev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct dev_pm_ops rcar_du_pm_ops = {
|
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(rcar_du_pm_suspend, rcar_du_pm_resume)
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Platform driver
|
|
|
|
*/
|
|
|
|
|
2015-09-28 23:39:53 +08:00
|
|
|
static int rcar_du_remove(struct platform_device *pdev)
|
2013-06-19 19:54:11 +08:00
|
|
|
{
|
2015-09-28 23:39:53 +08:00
|
|
|
struct rcar_du_device *rcdu = platform_get_drvdata(pdev);
|
|
|
|
struct drm_device *ddev = rcdu->ddev;
|
|
|
|
|
|
|
|
drm_dev_unregister(ddev);
|
|
|
|
|
|
|
|
if (rcdu->fbdev)
|
|
|
|
drm_fbdev_cma_fini(rcdu->fbdev);
|
|
|
|
|
|
|
|
drm_kms_helper_poll_fini(ddev);
|
|
|
|
drm_mode_config_cleanup(ddev);
|
|
|
|
|
|
|
|
drm_dev_unref(ddev);
|
|
|
|
|
|
|
|
return 0;
|
2013-06-19 19:54:11 +08:00
|
|
|
}
|
|
|
|
|
2015-09-28 23:39:53 +08:00
|
|
|
static int rcar_du_probe(struct platform_device *pdev)
|
2013-06-19 19:54:11 +08:00
|
|
|
{
|
2015-09-28 23:39:53 +08:00
|
|
|
struct rcar_du_device *rcdu;
|
|
|
|
struct drm_device *ddev;
|
|
|
|
struct resource *mem;
|
|
|
|
int ret;
|
|
|
|
|
2016-10-19 05:51:35 +08:00
|
|
|
/* Allocate and initialize the R-Car device structure. */
|
2015-09-28 23:39:53 +08:00
|
|
|
rcdu = devm_kzalloc(&pdev->dev, sizeof(*rcdu), GFP_KERNEL);
|
|
|
|
if (rcdu == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
init_waitqueue_head(&rcdu->commit.wait);
|
|
|
|
|
|
|
|
rcdu->dev = &pdev->dev;
|
|
|
|
rcdu->info = of_match_device(rcar_du_of_table, rcdu->dev)->data;
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, rcdu);
|
|
|
|
|
|
|
|
/* I/O resources */
|
|
|
|
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
rcdu->mmio = devm_ioremap_resource(&pdev->dev, mem);
|
2016-10-19 05:51:35 +08:00
|
|
|
if (IS_ERR(rcdu->mmio))
|
|
|
|
return PTR_ERR(rcdu->mmio);
|
2015-09-28 23:39:53 +08:00
|
|
|
|
|
|
|
/* DRM/KMS objects */
|
2016-10-19 05:51:35 +08:00
|
|
|
ddev = drm_dev_alloc(&rcar_du_driver, &pdev->dev);
|
|
|
|
if (IS_ERR(ddev))
|
|
|
|
return PTR_ERR(ddev);
|
|
|
|
|
|
|
|
rcdu->ddev = ddev;
|
|
|
|
ddev->dev_private = rcdu;
|
|
|
|
|
2015-09-28 23:39:53 +08:00
|
|
|
ret = rcar_du_modeset_init(rcdu);
|
|
|
|
if (ret < 0) {
|
2016-05-25 08:41:18 +08:00
|
|
|
if (ret != -EPROBE_DEFER)
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"failed to initialize DRM/KMS (%d)\n", ret);
|
2015-09-28 23:39:53 +08:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ddev->irq_enabled = 1;
|
|
|
|
|
|
|
|
/* Register the DRM device with the core and the connectors with
|
|
|
|
* sysfs.
|
|
|
|
*/
|
|
|
|
ret = drm_dev_register(ddev, 0);
|
|
|
|
if (ret)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
DRM_INFO("Device %s probed\n", dev_name(&pdev->dev));
|
2013-06-19 19:54:11 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-09-28 23:39:53 +08:00
|
|
|
|
|
|
|
error:
|
|
|
|
rcar_du_remove(pdev);
|
|
|
|
|
|
|
|
return ret;
|
2013-06-19 19:54:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver rcar_du_platform_driver = {
|
|
|
|
.probe = rcar_du_probe,
|
|
|
|
.remove = rcar_du_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = "rcar-du",
|
|
|
|
.pm = &rcar_du_pm_ops,
|
2014-01-21 22:57:26 +08:00
|
|
|
.of_match_table = rcar_du_of_table,
|
2013-06-19 19:54:11 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(rcar_du_platform_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
|
|
|
|
MODULE_DESCRIPTION("Renesas R-Car Display Unit DRM Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|