Commit ea6aae15 authored by Laurent Pinchart's avatar Laurent Pinchart
Browse files

drm: rcar-du: Embed drm_device in rcar_du_device



Embedding drm_device in rcar_du_device allows usage of the DRM managed
API to allocate both structures in one go, simplifying error handling.

Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: default avatarJacopo Mondi <jacopo+renesas@jmondi.org>
Reviewed-by: default avatarKieran Bingham <kieran.bingham+renesas@ideasonboard.com>
parent f5f16725
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1251,7 +1251,7 @@ int rcar_du_crtc_create(struct rcar_du_group *rgrp, unsigned int swindex,
	else
		primary = &rgrp->planes[swindex % 2].plane;

	ret = drm_crtc_init_with_planes(rcdu->ddev, crtc, primary, NULL,
	ret = drm_crtc_init_with_planes(&rcdu->ddev, crtc, primary, NULL,
					rcdu->info->gen <= 2 ?
					&crtc_funcs_gen2 : &crtc_funcs_gen3,
					NULL);
+14 −19
Original line number Diff line number Diff line
@@ -18,10 +18,11 @@
#include <linux/wait.h>

#include <drm/drm_atomic_helper.h>
#include <drm/drm_drv.h>
#include <drm/drm_fb_cma_helper.h>
#include <drm/drm_fb_helper.h>
#include <drm/drm_drv.h>
#include <drm/drm_gem_cma_helper.h>
#include <drm/drm_managed.h>
#include <drm/drm_probe_helper.h>

#include "rcar_du_drv.h"
@@ -527,14 +528,14 @@ static int rcar_du_pm_suspend(struct device *dev)
{
	struct rcar_du_device *rcdu = dev_get_drvdata(dev);

	return drm_mode_config_helper_suspend(rcdu->ddev);
	return drm_mode_config_helper_suspend(&rcdu->ddev);
}

static int rcar_du_pm_resume(struct device *dev)
{
	struct rcar_du_device *rcdu = dev_get_drvdata(dev);

	return drm_mode_config_helper_resume(rcdu->ddev);
	return drm_mode_config_helper_resume(&rcdu->ddev);
}
#endif

@@ -549,7 +550,7 @@ static const struct dev_pm_ops rcar_du_pm_ops = {
static int rcar_du_remove(struct platform_device *pdev)
{
	struct rcar_du_device *rcdu = platform_get_drvdata(pdev);
	struct drm_device *ddev = rcdu->ddev;
	struct drm_device *ddev = &rcdu->ddev;

	drm_dev_unregister(ddev);

@@ -563,14 +564,14 @@ static int rcar_du_remove(struct platform_device *pdev)
static int rcar_du_probe(struct platform_device *pdev)
{
	struct rcar_du_device *rcdu;
	struct drm_device *ddev;
	struct resource *mem;
	int ret;

	/* Allocate and initialize the R-Car device structure. */
	rcdu = devm_kzalloc(&pdev->dev, sizeof(*rcdu), GFP_KERNEL);
	if (rcdu == NULL)
		return -ENOMEM;
	rcdu = devm_drm_dev_alloc(&pdev->dev, &rcar_du_driver,
				  struct rcar_du_device, ddev);
	if (IS_ERR(rcdu))
		return PTR_ERR(rcdu);

	rcdu->dev = &pdev->dev;
	rcdu->info = of_device_get_match_data(rcdu->dev);
@@ -584,12 +585,7 @@ static int rcar_du_probe(struct platform_device *pdev)
		return PTR_ERR(rcdu->mmio);

	/* DRM/KMS objects */
	ddev = drm_dev_alloc(&rcar_du_driver, &pdev->dev);
	if (IS_ERR(ddev))
		return PTR_ERR(ddev);

	rcdu->ddev = ddev;
	ddev->dev_private = rcdu;
	rcdu->ddev.dev_private = rcdu;

	ret = rcar_du_modeset_init(rcdu);
	if (ret < 0) {
@@ -599,25 +595,24 @@ static int rcar_du_probe(struct platform_device *pdev)
		goto error;
	}

	ddev->irq_enabled = 1;
	rcdu->ddev.irq_enabled = 1;

	/*
	 * Register the DRM device with the core and the connectors with
	 * sysfs.
	 */
	ret = drm_dev_register(ddev, 0);
	ret = drm_dev_register(&rcdu->ddev, 0);
	if (ret)
		goto error;

	DRM_INFO("Device %s probed\n", dev_name(&pdev->dev));

	drm_fbdev_generic_setup(ddev, 32);
	drm_fbdev_generic_setup(&rcdu->ddev, 32);

	return 0;

error:
	rcar_du_remove(pdev);

	drm_kms_helper_poll_fini(&rcdu->ddev);
	return ret;
}

+3 −2
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@
#include <linux/kernel.h>
#include <linux/wait.h>

#include <drm/drm_device.h>

#include "rcar_cmm.h"
#include "rcar_du_crtc.h"
#include "rcar_du_group.h"
@@ -21,7 +23,6 @@
struct clk;
struct device;
struct drm_bridge;
struct drm_device;
struct drm_property;
struct rcar_du_device;

@@ -79,7 +80,7 @@ struct rcar_du_device {

	void __iomem *mmio;

	struct drm_device *ddev;
	struct drm_device ddev;

	struct rcar_du_crtc crtcs[RCAR_DU_MAX_CRTCS];
	unsigned int num_crtcs;
+2 −2
Original line number Diff line number Diff line
@@ -119,12 +119,12 @@ int rcar_du_encoder_init(struct rcar_du_device *rcdu,
		}
	}

	ret = drm_encoder_init(rcdu->ddev, encoder, &rcar_du_encoder_funcs,
	ret = drm_encoder_init(&rcdu->ddev, encoder, &rcar_du_encoder_funcs,
			       DRM_MODE_ENCODER_NONE, NULL);
	if (ret < 0)
		goto error;

	ret = drmm_add_action_or_reset(rcdu->ddev, rcar_du_encoder_release,
	ret = drmm_add_action_or_reset(&rcdu->ddev, rcar_du_encoder_release,
				       renc);
	if (ret)
		return ret;
+2 −2
Original line number Diff line number Diff line
@@ -583,7 +583,7 @@ static int rcar_du_properties_init(struct rcar_du_device *rcdu)
	 * or enable source color keying (1).
	 */
	rcdu->props.colorkey =
		drm_property_create_range(rcdu->ddev, 0, "colorkey",
		drm_property_create_range(&rcdu->ddev, 0, "colorkey",
					  0, 0x01ffffff);
	if (rcdu->props.colorkey == NULL)
		return -ENOMEM;
@@ -752,7 +752,7 @@ int rcar_du_modeset_init(struct rcar_du_device *rcdu)
		DU0_REG_OFFSET, DU2_REG_OFFSET
	};

	struct drm_device *dev = rcdu->ddev;
	struct drm_device *dev = &rcdu->ddev;
	struct drm_encoder *encoder;
	unsigned int dpad0_sources;
	unsigned int num_encoders;
Loading