2018-09-28 19:13:25 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-09-21 08:07:47 +00:00
|
|
|
/*
|
|
|
|
* Freescale i.MX drm driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Sascha Hauer, Pengutronix
|
|
|
|
*/
|
2019-07-16 06:42:18 +00:00
|
|
|
|
2013-11-03 11:23:34 +00:00
|
|
|
#include <linux/component.h>
|
2012-09-21 08:07:47 +00:00
|
|
|
#include <linux/device.h>
|
2016-07-08 09:40:59 +00:00
|
|
|
#include <linux/dma-buf.h>
|
2013-11-03 15:38:09 +00:00
|
|
|
#include <linux/module.h>
|
2012-09-21 08:07:47 +00:00
|
|
|
#include <linux/platform_device.h>
|
2019-07-16 06:42:18 +00:00
|
|
|
|
|
|
|
#include <video/imx-ipu-v3.h>
|
|
|
|
|
2016-07-08 09:40:59 +00:00
|
|
|
#include <drm/drm_atomic.h>
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
2019-07-16 06:42:18 +00:00
|
|
|
#include <drm/drm_drv.h>
|
2019-01-17 21:03:34 +00:00
|
|
|
#include <drm/drm_fb_cma_helper.h>
|
2012-09-21 08:07:47 +00:00
|
|
|
#include <drm/drm_fb_helper.h>
|
|
|
|
#include <drm/drm_gem_cma_helper.h>
|
2017-08-13 13:31:53 +00:00
|
|
|
#include <drm/drm_gem_framebuffer_helper.h>
|
2014-07-03 16:52:57 +00:00
|
|
|
#include <drm/drm_of.h>
|
2019-01-17 21:03:34 +00:00
|
|
|
#include <drm/drm_plane_helper.h>
|
|
|
|
#include <drm/drm_probe_helper.h>
|
2019-07-16 06:42:18 +00:00
|
|
|
#include <drm/drm_vblank.h>
|
2012-09-21 08:07:47 +00:00
|
|
|
|
|
|
|
#include "imx-drm.h"
|
2017-02-24 17:31:05 +00:00
|
|
|
#include "ipuv3-plane.h"
|
2012-09-21 08:07:47 +00:00
|
|
|
|
|
|
|
#define MAX_CRTC 4
|
|
|
|
|
2013-11-03 12:13:47 +00:00
|
|
|
static int legacyfb_depth = 16;
|
|
|
|
module_param(legacyfb_depth, int, 0444);
|
|
|
|
|
2017-03-08 14:12:56 +00:00
|
|
|
DEFINE_DRM_GEM_CMA_FOPS(imx_drm_driver_fops);
|
2012-09-21 08:07:47 +00:00
|
|
|
|
2013-11-03 13:28:24 +00:00
|
|
|
void imx_drm_connector_destroy(struct drm_connector *connector)
|
|
|
|
{
|
2014-05-29 15:57:41 +00:00
|
|
|
drm_connector_unregister(connector);
|
2013-11-03 13:28:24 +00:00
|
|
|
drm_connector_cleanup(connector);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(imx_drm_connector_destroy);
|
|
|
|
|
2016-08-26 07:30:44 +00:00
|
|
|
static int imx_drm_atomic_check(struct drm_device *dev,
|
|
|
|
struct drm_atomic_state *state)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2018-01-10 15:20:01 +00:00
|
|
|
ret = drm_atomic_helper_check(dev, state);
|
2016-08-26 07:30:44 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check modeset again in case crtc_state->mode_changed is
|
|
|
|
* updated in plane's ->atomic_check callback.
|
|
|
|
*/
|
|
|
|
ret = drm_atomic_helper_check_modeset(dev, state);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-03-08 11:13:21 +00:00
|
|
|
/* Assign PRG/PRE channels and check if all constrains are satisfied. */
|
|
|
|
ret = ipu_planes_assign_pre(dev, state);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-08-26 07:30:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-12-15 11:21:09 +00:00
|
|
|
static const struct drm_mode_config_funcs imx_drm_mode_config_funcs = {
|
2017-08-13 13:31:53 +00:00
|
|
|
.fb_create = drm_gem_fb_create,
|
2016-08-26 07:30:44 +00:00
|
|
|
.atomic_check = imx_drm_atomic_check,
|
2016-11-14 10:07:32 +00:00
|
|
|
.atomic_commit = drm_atomic_helper_commit,
|
2016-07-08 09:40:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void imx_drm_atomic_commit_tail(struct drm_atomic_state *state)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = state->dev;
|
2017-02-24 17:31:05 +00:00
|
|
|
struct drm_plane *plane;
|
2017-07-12 08:13:40 +00:00
|
|
|
struct drm_plane_state *old_plane_state, *new_plane_state;
|
2017-02-24 17:31:05 +00:00
|
|
|
bool plane_disabling = false;
|
|
|
|
int i;
|
2016-07-08 09:40:59 +00:00
|
|
|
|
|
|
|
drm_atomic_helper_commit_modeset_disables(dev, state);
|
|
|
|
|
2016-08-29 09:12:03 +00:00
|
|
|
drm_atomic_helper_commit_planes(dev, state,
|
2016-08-26 07:30:43 +00:00
|
|
|
DRM_PLANE_COMMIT_ACTIVE_ONLY |
|
|
|
|
DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET);
|
2016-07-08 09:40:59 +00:00
|
|
|
|
|
|
|
drm_atomic_helper_commit_modeset_enables(dev, state);
|
|
|
|
|
2017-07-12 08:13:40 +00:00
|
|
|
for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
|
|
|
|
if (drm_atomic_plane_disabling(old_plane_state, new_plane_state))
|
2017-02-24 17:31:05 +00:00
|
|
|
plane_disabling = true;
|
|
|
|
}
|
|
|
|
|
2017-11-30 13:31:46 +00:00
|
|
|
/*
|
|
|
|
* The flip done wait is only strictly required by imx-drm if a deferred
|
|
|
|
* plane disable is in-flight. As the core requires blocking commits
|
|
|
|
* to wait for the flip it is done here unconditionally. This keeps the
|
|
|
|
* workitem around a bit longer than required for the majority of
|
|
|
|
* non-blocking commits, but we accept that for the sake of simplicity.
|
|
|
|
*/
|
|
|
|
drm_atomic_helper_wait_for_flip_done(dev, state);
|
2017-02-24 17:31:05 +00:00
|
|
|
|
2017-11-30 13:31:46 +00:00
|
|
|
if (plane_disabling) {
|
2017-07-12 08:13:40 +00:00
|
|
|
for_each_old_plane_in_state(state, plane, old_plane_state, i)
|
2017-02-24 17:31:05 +00:00
|
|
|
ipu_plane_disable_deferred(plane);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-08 09:40:59 +00:00
|
|
|
drm_atomic_helper_commit_hw_done(state);
|
|
|
|
}
|
|
|
|
|
2017-01-02 09:16:13 +00:00
|
|
|
static const struct drm_mode_config_helper_funcs imx_drm_mode_config_helpers = {
|
2016-07-08 09:40:59 +00:00
|
|
|
.atomic_commit_tail = imx_drm_atomic_commit_tail,
|
2013-11-03 16:04:48 +00:00
|
|
|
};
|
|
|
|
|
2012-09-21 08:07:47 +00:00
|
|
|
|
2014-07-03 16:52:57 +00:00
|
|
|
int imx_drm_encoder_parse_of(struct drm_device *drm,
|
|
|
|
struct drm_encoder *encoder, struct device_node *np)
|
2013-11-03 14:04:47 +00:00
|
|
|
{
|
2014-07-03 16:52:57 +00:00
|
|
|
uint32_t crtc_mask = drm_of_find_possible_crtcs(drm, np);
|
2013-11-03 14:04:47 +00:00
|
|
|
|
2014-07-03 16:52:57 +00:00
|
|
|
/*
|
|
|
|
* If we failed to find the CRTC(s) which this encoder is
|
|
|
|
* supposed to be connected to, it's because the CRTC has
|
|
|
|
* not been registered yet. Defer probing, and hope that
|
|
|
|
* the required CRTC is added later.
|
|
|
|
*/
|
|
|
|
if (crtc_mask == 0)
|
|
|
|
return -EPROBE_DEFER;
|
2014-03-05 09:20:52 +00:00
|
|
|
|
2014-07-03 16:52:57 +00:00
|
|
|
encoder->possible_crtcs = crtc_mask;
|
2014-08-04 19:07:07 +00:00
|
|
|
|
2020-02-11 16:22:05 +00:00
|
|
|
/* FIXME: cloning support not clear, disable it all for now */
|
|
|
|
encoder->possible_clones = 0;
|
2013-11-03 14:04:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-03 16:52:57 +00:00
|
|
|
EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of);
|
2013-11-03 14:04:47 +00:00
|
|
|
|
2013-08-02 17:27:49 +00:00
|
|
|
static const struct drm_ioctl_desc imx_drm_ioctls[] = {
|
2012-09-21 08:07:47 +00:00
|
|
|
/* none so far */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct drm_driver imx_drm_driver = {
|
2019-06-17 15:39:24 +00:00
|
|
|
.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
|
2020-06-05 07:32:20 +00:00
|
|
|
DRM_GEM_CMA_DRIVER_OPS,
|
2012-09-21 08:07:47 +00:00
|
|
|
.ioctls = imx_drm_ioctls,
|
|
|
|
.num_ioctls = ARRAY_SIZE(imx_drm_ioctls),
|
|
|
|
.fops = &imx_drm_driver_fops,
|
|
|
|
.name = "imx-drm",
|
|
|
|
.desc = "i.MX DRM graphics",
|
|
|
|
.date = "20120507",
|
|
|
|
.major = 1,
|
|
|
|
.minor = 0,
|
|
|
|
.patchlevel = 0,
|
|
|
|
};
|
|
|
|
|
2013-11-03 11:23:34 +00:00
|
|
|
static int compare_of(struct device *dev, void *data)
|
|
|
|
{
|
2014-03-05 09:20:52 +00:00
|
|
|
struct device_node *np = data;
|
2013-11-03 11:23:34 +00:00
|
|
|
|
2016-05-12 13:00:44 +00:00
|
|
|
/* Special case for DI, dev->of_node may not be set yet */
|
|
|
|
if (strcmp(dev->driver->name, "imx-ipuv3-crtc") == 0) {
|
|
|
|
struct ipu_client_platformdata *pdata = dev->platform_data;
|
|
|
|
|
|
|
|
return pdata->of_node == np;
|
|
|
|
}
|
|
|
|
|
2014-03-05 09:20:52 +00:00
|
|
|
/* Special case for LDB, one device for two channels */
|
2018-12-05 19:50:23 +00:00
|
|
|
if (of_node_name_eq(np, "lvds-channel")) {
|
2014-03-05 09:20:52 +00:00
|
|
|
np = of_get_parent(np);
|
|
|
|
of_node_put(np);
|
2013-11-03 11:23:34 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 09:20:52 +00:00
|
|
|
return dev->of_node == np;
|
|
|
|
}
|
2013-11-03 11:23:34 +00:00
|
|
|
|
|
|
|
static int imx_drm_bind(struct device *dev)
|
|
|
|
{
|
2016-08-11 09:18:48 +00:00
|
|
|
struct drm_device *drm;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
drm = drm_dev_alloc(&imx_drm_driver, dev);
|
2016-10-13 08:53:21 +00:00
|
|
|
if (IS_ERR(drm))
|
|
|
|
return PTR_ERR(drm);
|
2016-08-11 09:18:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* enable drm irq mode.
|
|
|
|
* - with irq_enabled = true, we can use the vblank feature.
|
|
|
|
*
|
|
|
|
* P.S. note that we wouldn't use drm irq handler but
|
|
|
|
* just specific driver own one instead because
|
|
|
|
* drm framework supports only one irq handler and
|
|
|
|
* drivers can well take care of their interrupts
|
|
|
|
*/
|
|
|
|
drm->irq_enabled = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set max width and height as default value(4096x4096).
|
|
|
|
* this value would be used to check framebuffer size limitation
|
|
|
|
* at drm_mode_addfb().
|
|
|
|
*/
|
2017-01-27 10:57:19 +00:00
|
|
|
drm->mode_config.min_width = 1;
|
|
|
|
drm->mode_config.min_height = 1;
|
2016-08-11 09:18:48 +00:00
|
|
|
drm->mode_config.max_width = 4096;
|
|
|
|
drm->mode_config.max_height = 4096;
|
|
|
|
drm->mode_config.funcs = &imx_drm_mode_config_funcs;
|
|
|
|
drm->mode_config.helper_private = &imx_drm_mode_config_helpers;
|
2017-11-10 16:10:00 +00:00
|
|
|
drm->mode_config.allow_fb_modifiers = true;
|
2018-01-10 15:20:01 +00:00
|
|
|
drm->mode_config.normalize_zpos = true;
|
2016-08-11 09:18:48 +00:00
|
|
|
|
|
|
|
drm_mode_config_init(drm);
|
|
|
|
|
|
|
|
ret = drm_vblank_init(drm, MAX_CRTC);
|
|
|
|
if (ret)
|
|
|
|
goto err_kms;
|
|
|
|
|
|
|
|
dev_set_drvdata(dev, drm);
|
|
|
|
|
|
|
|
/* Now try and bind all our sub-components */
|
|
|
|
ret = component_bind_all(dev, drm);
|
|
|
|
if (ret)
|
2017-05-24 14:51:58 +00:00
|
|
|
goto err_kms;
|
2016-08-11 09:18:48 +00:00
|
|
|
|
|
|
|
drm_mode_config_reset(drm);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All components are now initialised, so setup the fb helper.
|
|
|
|
* The fb helper takes copies of key hardware information, so the
|
|
|
|
* crtcs/connectors/encoders must not change after this point.
|
|
|
|
*/
|
|
|
|
if (legacyfb_depth != 16 && legacyfb_depth != 32) {
|
|
|
|
dev_warn(dev, "Invalid legacyfb_depth. Defaulting to 16bpp\n");
|
|
|
|
legacyfb_depth = 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_kms_helper_poll_init(drm);
|
|
|
|
|
|
|
|
ret = drm_dev_register(drm, 0);
|
|
|
|
if (ret)
|
2018-09-08 13:46:39 +00:00
|
|
|
goto err_poll_fini;
|
|
|
|
|
|
|
|
drm_fbdev_generic_setup(drm, legacyfb_depth);
|
2016-08-11 09:18:48 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2018-09-08 13:46:39 +00:00
|
|
|
err_poll_fini:
|
2016-08-11 09:18:48 +00:00
|
|
|
drm_kms_helper_poll_fini(drm);
|
|
|
|
component_unbind_all(drm->dev, drm);
|
|
|
|
err_kms:
|
|
|
|
drm_mode_config_cleanup(drm);
|
2018-07-17 08:33:49 +00:00
|
|
|
drm_dev_put(drm);
|
2016-08-11 09:18:48 +00:00
|
|
|
|
|
|
|
return ret;
|
2013-11-03 11:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void imx_drm_unbind(struct device *dev)
|
|
|
|
{
|
2016-08-11 09:18:48 +00:00
|
|
|
struct drm_device *drm = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
drm_dev_unregister(drm);
|
|
|
|
|
|
|
|
drm_kms_helper_poll_fini(drm);
|
|
|
|
|
2020-06-11 12:43:31 +00:00
|
|
|
component_unbind_all(drm->dev, drm);
|
|
|
|
|
2016-08-11 09:18:49 +00:00
|
|
|
drm_mode_config_cleanup(drm);
|
|
|
|
|
2016-08-11 09:18:48 +00:00
|
|
|
dev_set_drvdata(dev, NULL);
|
|
|
|
|
2018-07-17 08:33:49 +00:00
|
|
|
drm_dev_put(drm);
|
2013-11-03 11:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct component_master_ops imx_drm_ops = {
|
|
|
|
.bind = imx_drm_bind,
|
|
|
|
.unbind = imx_drm_unbind,
|
|
|
|
};
|
|
|
|
|
2012-09-21 08:07:47 +00:00
|
|
|
static int imx_drm_platform_probe(struct platform_device *pdev)
|
|
|
|
{
|
2015-10-20 09:23:13 +00:00
|
|
|
int ret = drm_of_component_probe(&pdev->dev, compare_of, &imx_drm_ops);
|
2014-03-05 09:20:52 +00:00
|
|
|
|
2015-10-20 09:23:13 +00:00
|
|
|
if (!ret)
|
|
|
|
ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
|
2014-03-05 09:20:52 +00:00
|
|
|
|
2015-10-20 09:23:13 +00:00
|
|
|
return ret;
|
2012-09-21 08:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_drm_platform_remove(struct platform_device *pdev)
|
|
|
|
{
|
2013-11-03 11:23:34 +00:00
|
|
|
component_master_del(&pdev->dev, &imx_drm_ops);
|
2012-09-21 08:07:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-10 14:43:51 +00:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int imx_drm_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct drm_device *drm_dev = dev_get_drvdata(dev);
|
|
|
|
|
2018-07-31 19:28:33 +00:00
|
|
|
return drm_mode_config_helper_suspend(drm_dev);
|
2014-09-10 14:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_drm_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct drm_device *drm_dev = dev_get_drvdata(dev);
|
|
|
|
|
2018-07-31 19:28:33 +00:00
|
|
|
return drm_mode_config_helper_resume(drm_dev);
|
2014-09-10 14:43:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(imx_drm_pm_ops, imx_drm_suspend, imx_drm_resume);
|
|
|
|
|
2013-11-03 11:23:34 +00:00
|
|
|
static const struct of_device_id imx_drm_dt_ids[] = {
|
2014-03-05 09:20:52 +00:00
|
|
|
{ .compatible = "fsl,imx-display-subsystem", },
|
2013-11-03 11:23:34 +00:00
|
|
|
{ /* sentinel */ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, imx_drm_dt_ids);
|
|
|
|
|
2012-09-21 08:07:47 +00:00
|
|
|
static struct platform_driver imx_drm_pdrv = {
|
|
|
|
.probe = imx_drm_platform_probe,
|
2012-11-19 18:20:51 +00:00
|
|
|
.remove = imx_drm_platform_remove,
|
2012-09-21 08:07:47 +00:00
|
|
|
.driver = {
|
|
|
|
.name = "imx-drm",
|
2014-09-10 14:43:51 +00:00
|
|
|
.pm = &imx_drm_pm_ops,
|
2013-11-03 11:23:34 +00:00
|
|
|
.of_match_table = imx_drm_dt_ids,
|
2012-09-21 08:07:47 +00:00
|
|
|
},
|
|
|
|
};
|
2017-03-23 16:18:37 +00:00
|
|
|
|
|
|
|
static struct platform_driver * const drivers[] = {
|
|
|
|
&imx_drm_pdrv,
|
|
|
|
&ipu_drm_driver,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init imx_drm_init(void)
|
|
|
|
{
|
|
|
|
return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
|
|
|
|
}
|
|
|
|
module_init(imx_drm_init);
|
|
|
|
|
|
|
|
static void __exit imx_drm_exit(void)
|
|
|
|
{
|
|
|
|
platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
|
|
|
|
}
|
|
|
|
module_exit(imx_drm_exit);
|
2012-09-21 08:07:47 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
|
|
|
|
MODULE_DESCRIPTION("i.MX drm driver core");
|
|
|
|
MODULE_LICENSE("GPL");
|