2019-06-04 08:11:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-08-15 12:59:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Russell King
|
|
|
|
*/
|
2019-08-04 09:41:31 +00:00
|
|
|
|
2012-08-15 12:59:49 +00:00
|
|
|
#include <linux/clk.h>
|
2014-02-04 11:57:06 +00:00
|
|
|
#include <linux/component.h>
|
2012-08-15 12:59:49 +00:00
|
|
|
#include <linux/module.h>
|
2014-02-04 11:57:06 +00:00
|
|
|
#include <linux/of_graph.h>
|
2019-08-04 09:41:31 +00:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2018-07-30 10:53:06 +00:00
|
|
|
#include <drm/drm_atomic_helper.h>
|
2019-08-04 09:41:31 +00:00
|
|
|
#include <drm/drm_drv.h>
|
|
|
|
#include <drm/drm_ioctl.h>
|
2020-03-23 14:49:17 +00:00
|
|
|
#include <drm/drm_managed.h>
|
2019-08-04 09:41:31 +00:00
|
|
|
#include <drm/drm_prime.h>
|
2019-01-17 21:03:34 +00:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2017-12-05 18:24:56 +00:00
|
|
|
#include <drm/drm_fb_helper.h>
|
2015-10-20 09:23:15 +00:00
|
|
|
#include <drm/drm_of.h>
|
2019-08-04 09:41:31 +00:00
|
|
|
#include <drm/drm_vblank.h>
|
|
|
|
|
2012-08-15 12:59:49 +00:00
|
|
|
#include "armada_crtc.h"
|
|
|
|
#include "armada_drm.h"
|
|
|
|
#include "armada_gem.h"
|
2018-07-30 10:52:34 +00:00
|
|
|
#include "armada_fb.h"
|
2012-08-15 12:59:49 +00:00
|
|
|
#include "armada_hw.h"
|
|
|
|
#include <drm/armada_drm.h>
|
|
|
|
#include "armada_ioctlP.h"
|
|
|
|
|
|
|
|
static struct drm_ioctl_desc armada_ioctls[] = {
|
2015-09-08 11:56:30 +00:00
|
|
|
DRM_IOCTL_DEF_DRV(ARMADA_GEM_CREATE, armada_gem_create_ioctl,0),
|
|
|
|
DRM_IOCTL_DEF_DRV(ARMADA_GEM_MMAP, armada_gem_mmap_ioctl, 0),
|
|
|
|
DRM_IOCTL_DEF_DRV(ARMADA_GEM_PWRITE, armada_gem_pwrite_ioctl, 0),
|
2012-08-15 12:59:49 +00:00
|
|
|
};
|
|
|
|
|
drm/gem: Add DEFINE_DRM_GEM_FOPS
Sadly there's only 1 driver which can use it, everyone else is special
for some reason:
- gma500 has a horrible runtime PM ioctl wrapper that probably doesn't
really work but meh.
- i915 needs special compat_ioctl handler because regrets.
- arcgpu needs to fixup the pgprot because (no idea why it can't do
that in the fault handler like everyone else).
- tegra does even worse stuff with pgprot
- udl does something with vm_flags too ...
- cma helpers, etnaviv, mtk, msm, rockchip, omap all implement some
variation on prefaulting.
- exynos is exynos, I got lost in the midlayers.
- vc4 has to reinvent half of cma helpers because those are too much
midlayer, plus vm_flags dances.
- vgem also seems unhappy with the default vm_flags.
So pretty sad divergence and I'm sure we could do better, but not
really an idea. Oh well, maybe this macro here helps to encourage more
consistency at least going forward.
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Liviu Dudau <Liviu.Dudau@arm.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170308141257.12119-25-daniel.vetter@ffwll.ch
2017-03-08 14:12:57 +00:00
|
|
|
DEFINE_DRM_GEM_FOPS(armada_drm_fops);
|
2012-08-15 12:59:49 +00:00
|
|
|
|
|
|
|
static struct drm_driver armada_drm_driver = {
|
2017-12-05 18:24:56 +00:00
|
|
|
.lastclose = drm_fb_helper_lastclose,
|
2016-05-30 17:52:53 +00:00
|
|
|
.gem_free_object_unlocked = armada_gem_free_object,
|
2012-08-15 12:59:49 +00:00
|
|
|
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
|
|
|
|
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
|
|
|
|
.gem_prime_export = armada_gem_prime_export,
|
|
|
|
.gem_prime_import = armada_gem_prime_import,
|
|
|
|
.dumb_create = armada_gem_dumb_create,
|
|
|
|
.gem_vm_ops = &armada_gem_vm_ops,
|
|
|
|
.major = 1,
|
|
|
|
.minor = 0,
|
|
|
|
.name = "armada-drm",
|
|
|
|
.desc = "Armada SoC DRM",
|
|
|
|
.date = "20120730",
|
2019-06-17 15:39:24 +00:00
|
|
|
.driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
|
2012-08-15 12:59:49 +00:00
|
|
|
.ioctls = armada_ioctls,
|
|
|
|
.fops = &armada_drm_fops,
|
|
|
|
};
|
|
|
|
|
2018-07-30 10:52:34 +00:00
|
|
|
static const struct drm_mode_config_funcs armada_drm_mode_config_funcs = {
|
|
|
|
.fb_create = armada_fb_create,
|
|
|
|
.output_poll_changed = drm_fb_helper_output_poll_changed,
|
2018-07-30 10:53:06 +00:00
|
|
|
.atomic_check = drm_atomic_helper_check,
|
|
|
|
.atomic_commit = drm_atomic_helper_commit,
|
2018-07-30 10:52:34 +00:00
|
|
|
};
|
|
|
|
|
2014-02-04 11:57:06 +00:00
|
|
|
static int armada_drm_bind(struct device *dev)
|
|
|
|
{
|
2016-11-01 20:05:47 +00:00
|
|
|
struct armada_private *priv;
|
|
|
|
struct resource *mem = NULL;
|
|
|
|
int ret, n;
|
|
|
|
|
|
|
|
for (n = 0; ; n++) {
|
|
|
|
struct resource *r = platform_get_resource(to_platform_device(dev),
|
|
|
|
IORESOURCE_MEM, n);
|
|
|
|
if (!r)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Resources above 64K are graphics memory */
|
|
|
|
if (resource_size(r) > SZ_64K)
|
|
|
|
mem = r;
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mem)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
if (!devm_request_mem_region(dev, mem->start, resource_size(mem),
|
|
|
|
"armada-drm"))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The drm_device structure must be at the start of
|
2018-07-30 10:52:31 +00:00
|
|
|
* armada_private for drm_dev_put() to work correctly.
|
2016-11-01 20:05:47 +00:00
|
|
|
*/
|
|
|
|
BUILD_BUG_ON(offsetof(struct armada_private, drm) != 0);
|
|
|
|
|
|
|
|
ret = drm_dev_init(&priv->drm, &armada_drm_driver, dev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "[" DRM_NAME ":%s] drm_dev_init failed: %d\n",
|
|
|
|
__func__, ret);
|
|
|
|
kfree(priv);
|
|
|
|
return ret;
|
|
|
|
}
|
2020-03-23 14:49:17 +00:00
|
|
|
drmm_add_final_kfree(&priv->drm, priv);
|
2016-11-01 20:05:47 +00:00
|
|
|
|
2019-01-21 06:01:57 +00:00
|
|
|
/* Remove early framebuffers */
|
|
|
|
ret = drm_fb_helper_remove_conflicting_framebuffers(NULL,
|
|
|
|
"armada-drm-fb",
|
|
|
|
false);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "[" DRM_NAME ":%s] can't kick out simple-fb: %d\n",
|
|
|
|
__func__, ret);
|
|
|
|
kfree(priv);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-11-01 20:05:47 +00:00
|
|
|
priv->drm.dev_private = priv;
|
|
|
|
|
2016-12-17 22:01:19 +00:00
|
|
|
dev_set_drvdata(dev, &priv->drm);
|
2016-11-01 20:05:47 +00:00
|
|
|
|
|
|
|
/* Mode setting support */
|
|
|
|
drm_mode_config_init(&priv->drm);
|
|
|
|
priv->drm.mode_config.min_width = 320;
|
|
|
|
priv->drm.mode_config.min_height = 200;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* With vscale enabled, the maximum width is 1920 due to the
|
|
|
|
* 1920 by 3 lines RAM
|
|
|
|
*/
|
|
|
|
priv->drm.mode_config.max_width = 1920;
|
|
|
|
priv->drm.mode_config.max_height = 2048;
|
|
|
|
|
|
|
|
priv->drm.mode_config.preferred_depth = 24;
|
|
|
|
priv->drm.mode_config.funcs = &armada_drm_mode_config_funcs;
|
|
|
|
drm_mm_init(&priv->linear, mem->start, resource_size(mem));
|
|
|
|
mutex_init(&priv->linear_lock);
|
|
|
|
|
|
|
|
ret = component_bind_all(dev, &priv->drm);
|
|
|
|
if (ret)
|
|
|
|
goto err_kms;
|
|
|
|
|
|
|
|
ret = drm_vblank_init(&priv->drm, priv->drm.mode_config.num_crtc);
|
|
|
|
if (ret)
|
|
|
|
goto err_comp;
|
|
|
|
|
|
|
|
priv->drm.irq_enabled = true;
|
|
|
|
|
2018-07-30 10:52:34 +00:00
|
|
|
drm_mode_config_reset(&priv->drm);
|
|
|
|
|
2016-11-01 20:05:47 +00:00
|
|
|
ret = armada_fbdev_init(&priv->drm);
|
|
|
|
if (ret)
|
|
|
|
goto err_comp;
|
|
|
|
|
|
|
|
drm_kms_helper_poll_init(&priv->drm);
|
|
|
|
|
|
|
|
ret = drm_dev_register(&priv->drm, 0);
|
|
|
|
if (ret)
|
|
|
|
goto err_poll;
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
armada_drm_debugfs_init(priv->drm.primary);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_poll:
|
|
|
|
drm_kms_helper_poll_fini(&priv->drm);
|
|
|
|
armada_fbdev_fini(&priv->drm);
|
|
|
|
err_comp:
|
|
|
|
component_unbind_all(dev, &priv->drm);
|
|
|
|
err_kms:
|
|
|
|
drm_mode_config_cleanup(&priv->drm);
|
|
|
|
drm_mm_takedown(&priv->linear);
|
2018-07-30 10:52:31 +00:00
|
|
|
drm_dev_put(&priv->drm);
|
2016-11-01 20:05:47 +00:00
|
|
|
return ret;
|
2014-02-04 11:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void armada_drm_unbind(struct device *dev)
|
|
|
|
{
|
2016-11-01 20:05:47 +00:00
|
|
|
struct drm_device *drm = dev_get_drvdata(dev);
|
|
|
|
struct armada_private *priv = drm->dev_private;
|
|
|
|
|
|
|
|
drm_kms_helper_poll_fini(&priv->drm);
|
|
|
|
armada_fbdev_fini(&priv->drm);
|
|
|
|
|
|
|
|
drm_dev_unregister(&priv->drm);
|
|
|
|
|
2018-07-02 16:27:46 +00:00
|
|
|
drm_atomic_helper_shutdown(&priv->drm);
|
|
|
|
|
2016-11-01 20:05:47 +00:00
|
|
|
component_unbind_all(dev, &priv->drm);
|
|
|
|
|
|
|
|
drm_mode_config_cleanup(&priv->drm);
|
|
|
|
drm_mm_takedown(&priv->linear);
|
|
|
|
|
2018-07-30 10:52:31 +00:00
|
|
|
drm_dev_put(&priv->drm);
|
2014-02-04 11:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int compare_of(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
return dev->of_node == data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compare_dev_name(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
const char *name = data;
|
|
|
|
return !strcmp(dev_name(dev), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void armada_add_endpoints(struct device *dev,
|
2019-01-24 09:56:46 +00:00
|
|
|
struct component_match **match, struct device_node *dev_node)
|
2014-02-04 11:57:06 +00:00
|
|
|
{
|
|
|
|
struct device_node *ep, *remote;
|
|
|
|
|
2019-01-24 09:56:46 +00:00
|
|
|
for_each_endpoint_of_node(dev_node, ep) {
|
2014-02-04 11:57:06 +00:00
|
|
|
remote = of_graph_get_remote_port_parent(ep);
|
2019-01-24 14:18:17 +00:00
|
|
|
if (remote && of_device_is_available(remote))
|
|
|
|
drm_of_component_match_add(dev, match, compare_of,
|
|
|
|
remote);
|
2014-02-04 11:57:06 +00:00
|
|
|
of_node_put(remote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 09:23:15 +00:00
|
|
|
static const struct component_master_ops armada_master_ops = {
|
|
|
|
.bind = armada_drm_bind,
|
|
|
|
.unbind = armada_drm_unbind,
|
|
|
|
};
|
2014-02-04 11:57:06 +00:00
|
|
|
|
2015-10-20 09:23:15 +00:00
|
|
|
static int armada_drm_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct component_match *match = NULL;
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
int ret;
|
2014-02-04 11:57:06 +00:00
|
|
|
|
2015-10-20 09:23:15 +00:00
|
|
|
ret = drm_of_component_probe(dev, compare_dev_name, &armada_master_ops);
|
|
|
|
if (ret != -EINVAL)
|
|
|
|
return ret;
|
2014-02-04 11:57:06 +00:00
|
|
|
|
2015-10-20 09:23:15 +00:00
|
|
|
if (dev->platform_data) {
|
2014-02-04 11:57:06 +00:00
|
|
|
char **devices = dev->platform_data;
|
|
|
|
struct device *d;
|
2015-10-20 09:23:15 +00:00
|
|
|
int i;
|
2014-02-04 11:57:06 +00:00
|
|
|
|
|
|
|
for (i = 0; devices[i]; i++)
|
2015-10-20 09:23:15 +00:00
|
|
|
component_match_add(dev, &match, compare_dev_name,
|
2014-02-04 11:57:06 +00:00
|
|
|
devices[i]);
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
dev_err(dev, "missing 'ports' property\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; devices[i]; i++) {
|
|
|
|
d = bus_find_device_by_name(&platform_bus_type, NULL,
|
2015-10-20 09:23:15 +00:00
|
|
|
devices[i]);
|
2019-01-24 09:56:46 +00:00
|
|
|
if (d && d->of_node)
|
|
|
|
armada_add_endpoints(dev, &match, d->of_node);
|
2014-02-04 11:57:06 +00:00
|
|
|
put_device(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 20:46:53 +00:00
|
|
|
return component_master_add_with_match(&pdev->dev, &armada_master_ops,
|
|
|
|
match);
|
2012-08-15 12:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int armada_drm_remove(struct platform_device *pdev)
|
|
|
|
{
|
2015-06-06 20:46:53 +00:00
|
|
|
component_master_del(&pdev->dev, &armada_master_ops);
|
2012-08-15 12:59:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct platform_device_id armada_drm_platform_ids[] = {
|
|
|
|
{
|
|
|
|
.name = "armada-drm",
|
|
|
|
}, {
|
|
|
|
.name = "armada-510-drm",
|
|
|
|
},
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(platform, armada_drm_platform_ids);
|
|
|
|
|
|
|
|
static struct platform_driver armada_drm_platform_driver = {
|
|
|
|
.probe = armada_drm_probe,
|
|
|
|
.remove = armada_drm_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = "armada-drm",
|
|
|
|
},
|
|
|
|
.id_table = armada_drm_platform_ids,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init armada_drm_init(void)
|
|
|
|
{
|
2014-04-22 10:10:15 +00:00
|
|
|
int ret;
|
|
|
|
|
2014-06-09 13:39:49 +00:00
|
|
|
armada_drm_driver.num_ioctls = ARRAY_SIZE(armada_ioctls);
|
2014-04-22 10:10:15 +00:00
|
|
|
|
|
|
|
ret = platform_driver_register(&armada_lcd_platform_driver);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = platform_driver_register(&armada_drm_platform_driver);
|
|
|
|
if (ret)
|
|
|
|
platform_driver_unregister(&armada_lcd_platform_driver);
|
|
|
|
return ret;
|
2012-08-15 12:59:49 +00:00
|
|
|
}
|
|
|
|
module_init(armada_drm_init);
|
|
|
|
|
|
|
|
static void __exit armada_drm_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&armada_drm_platform_driver);
|
2014-04-22 10:10:15 +00:00
|
|
|
platform_driver_unregister(&armada_lcd_platform_driver);
|
2012-08-15 12:59:49 +00:00
|
|
|
}
|
|
|
|
module_exit(armada_drm_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Russell King <rmk+kernel@arm.linux.org.uk>");
|
|
|
|
MODULE_DESCRIPTION("Armada DRM Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:armada-drm");
|