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: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2020-12-03 18:21:55 +02:00
parent f5f16725ed
commit ea6aae1518
8 changed files with 29 additions and 33 deletions

View File

@ -1251,7 +1251,7 @@ int rcar_du_crtc_create(struct rcar_du_group *rgrp, unsigned int swindex,
else else
primary = &rgrp->planes[swindex % 2].plane; 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 ? rcdu->info->gen <= 2 ?
&crtc_funcs_gen2 : &crtc_funcs_gen3, &crtc_funcs_gen2 : &crtc_funcs_gen3,
NULL); NULL);

View File

@ -18,10 +18,11 @@
#include <linux/wait.h> #include <linux/wait.h>
#include <drm/drm_atomic_helper.h> #include <drm/drm_atomic_helper.h>
#include <drm/drm_drv.h>
#include <drm/drm_fb_cma_helper.h> #include <drm/drm_fb_cma_helper.h>
#include <drm/drm_fb_helper.h> #include <drm/drm_fb_helper.h>
#include <drm/drm_drv.h>
#include <drm/drm_gem_cma_helper.h> #include <drm/drm_gem_cma_helper.h>
#include <drm/drm_managed.h>
#include <drm/drm_probe_helper.h> #include <drm/drm_probe_helper.h>
#include "rcar_du_drv.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); 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) static int rcar_du_pm_resume(struct device *dev)
{ {
struct rcar_du_device *rcdu = dev_get_drvdata(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 #endif
@ -549,7 +550,7 @@ static const struct dev_pm_ops rcar_du_pm_ops = {
static int rcar_du_remove(struct platform_device *pdev) static int rcar_du_remove(struct platform_device *pdev)
{ {
struct rcar_du_device *rcdu = platform_get_drvdata(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); 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) static int rcar_du_probe(struct platform_device *pdev)
{ {
struct rcar_du_device *rcdu; struct rcar_du_device *rcdu;
struct drm_device *ddev;
struct resource *mem; struct resource *mem;
int ret; int ret;
/* Allocate and initialize the R-Car device structure. */ /* Allocate and initialize the R-Car device structure. */
rcdu = devm_kzalloc(&pdev->dev, sizeof(*rcdu), GFP_KERNEL); rcdu = devm_drm_dev_alloc(&pdev->dev, &rcar_du_driver,
if (rcdu == NULL) struct rcar_du_device, ddev);
return -ENOMEM; if (IS_ERR(rcdu))
return PTR_ERR(rcdu);
rcdu->dev = &pdev->dev; rcdu->dev = &pdev->dev;
rcdu->info = of_device_get_match_data(rcdu->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); return PTR_ERR(rcdu->mmio);
/* DRM/KMS objects */ /* DRM/KMS objects */
ddev = drm_dev_alloc(&rcar_du_driver, &pdev->dev); rcdu->ddev.dev_private = rcdu;
if (IS_ERR(ddev))
return PTR_ERR(ddev);
rcdu->ddev = ddev;
ddev->dev_private = rcdu;
ret = rcar_du_modeset_init(rcdu); ret = rcar_du_modeset_init(rcdu);
if (ret < 0) { if (ret < 0) {
@ -599,25 +595,24 @@ static int rcar_du_probe(struct platform_device *pdev)
goto error; goto error;
} }
ddev->irq_enabled = 1; rcdu->ddev.irq_enabled = 1;
/* /*
* Register the DRM device with the core and the connectors with * Register the DRM device with the core and the connectors with
* sysfs. * sysfs.
*/ */
ret = drm_dev_register(ddev, 0); ret = drm_dev_register(&rcdu->ddev, 0);
if (ret) if (ret)
goto error; goto error;
DRM_INFO("Device %s probed\n", dev_name(&pdev->dev)); 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; return 0;
error: error:
rcar_du_remove(pdev); drm_kms_helper_poll_fini(&rcdu->ddev);
return ret; return ret;
} }

View File

@ -13,6 +13,8 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <drm/drm_device.h>
#include "rcar_cmm.h" #include "rcar_cmm.h"
#include "rcar_du_crtc.h" #include "rcar_du_crtc.h"
#include "rcar_du_group.h" #include "rcar_du_group.h"
@ -21,7 +23,6 @@
struct clk; struct clk;
struct device; struct device;
struct drm_bridge; struct drm_bridge;
struct drm_device;
struct drm_property; struct drm_property;
struct rcar_du_device; struct rcar_du_device;
@ -79,7 +80,7 @@ struct rcar_du_device {
void __iomem *mmio; void __iomem *mmio;
struct drm_device *ddev; struct drm_device ddev;
struct rcar_du_crtc crtcs[RCAR_DU_MAX_CRTCS]; struct rcar_du_crtc crtcs[RCAR_DU_MAX_CRTCS];
unsigned int num_crtcs; unsigned int num_crtcs;

View File

@ -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); DRM_MODE_ENCODER_NONE, NULL);
if (ret < 0) if (ret < 0)
goto error; 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); renc);
if (ret) if (ret)
return ret; return ret;

View File

@ -583,7 +583,7 @@ static int rcar_du_properties_init(struct rcar_du_device *rcdu)
* or enable source color keying (1). * or enable source color keying (1).
*/ */
rcdu->props.colorkey = rcdu->props.colorkey =
drm_property_create_range(rcdu->ddev, 0, "colorkey", drm_property_create_range(&rcdu->ddev, 0, "colorkey",
0, 0x01ffffff); 0, 0x01ffffff);
if (rcdu->props.colorkey == NULL) if (rcdu->props.colorkey == NULL)
return -ENOMEM; return -ENOMEM;
@ -752,7 +752,7 @@ int rcar_du_modeset_init(struct rcar_du_device *rcdu)
DU0_REG_OFFSET, DU2_REG_OFFSET DU0_REG_OFFSET, DU2_REG_OFFSET
}; };
struct drm_device *dev = rcdu->ddev; struct drm_device *dev = &rcdu->ddev;
struct drm_encoder *encoder; struct drm_encoder *encoder;
unsigned int dpad0_sources; unsigned int dpad0_sources;
unsigned int num_encoders; unsigned int num_encoders;

View File

@ -773,9 +773,9 @@ int rcar_du_planes_init(struct rcar_du_group *rgrp)
plane->group = rgrp; plane->group = rgrp;
ret = drm_universal_plane_init(rcdu->ddev, &plane->plane, crtcs, ret = drm_universal_plane_init(&rcdu->ddev, &plane->plane,
&rcar_du_plane_funcs, formats, crtcs, &rcar_du_plane_funcs,
ARRAY_SIZE(formats), formats, ARRAY_SIZE(formats),
NULL, type, NULL); NULL, type, NULL);
if (ret < 0) if (ret < 0)
return ret; return ret;

View File

@ -375,7 +375,7 @@ int rcar_du_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np,
vsp->vsp = &pdev->dev; vsp->vsp = &pdev->dev;
ret = drmm_add_action_or_reset(rcdu->ddev, rcar_du_vsp_cleanup, vsp); ret = drmm_add_action_or_reset(&rcdu->ddev, rcar_du_vsp_cleanup, vsp);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -402,8 +402,8 @@ int rcar_du_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np,
plane->vsp = vsp; plane->vsp = vsp;
plane->index = i; plane->index = i;
ret = drm_universal_plane_init(rcdu->ddev, &plane->plane, crtcs, ret = drm_universal_plane_init(&rcdu->ddev, &plane->plane,
&rcar_du_vsp_plane_funcs, crtcs, &rcar_du_vsp_plane_funcs,
rcar_du_vsp_formats, rcar_du_vsp_formats,
ARRAY_SIZE(rcar_du_vsp_formats), ARRAY_SIZE(rcar_du_vsp_formats),
NULL, type, NULL); NULL, type, NULL);

View File

@ -204,7 +204,7 @@ int rcar_du_writeback_init(struct rcar_du_device *rcdu,
drm_connector_helper_add(&wb_conn->base, drm_connector_helper_add(&wb_conn->base,
&rcar_du_wb_conn_helper_funcs); &rcar_du_wb_conn_helper_funcs);
return drm_writeback_connector_init(rcdu->ddev, wb_conn, return drm_writeback_connector_init(&rcdu->ddev, wb_conn,
&rcar_du_wb_conn_funcs, &rcar_du_wb_conn_funcs,
&rcar_du_wb_enc_helper_funcs, &rcar_du_wb_enc_helper_funcs,
writeback_formats, writeback_formats,