diff mbox

[12/48] drm: omapdrm: Split init and cleanup from probe and remove functions

Message ID 20171013145944.26557-13-laurent.pinchart@ideasonboard.com (mailing list archive)
State New, archived
Headers show

Commit Message

Laurent Pinchart Oct. 13, 2017, 2:59 p.m. UTC
When merging the omapdrm and omapdss drivers there will be not omapdrm
platform device anymore, and thus no associated probe and remove
functions. To prepare for that, split all the initialization code from
the probe function to make it usable without a platform device.
Similarly, split the cleanup code from the remove function.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/omapdrm/omap_drv.c | 83 +++++++++++++++++++++++---------------
 drivers/gpu/drm/omapdrm/omap_drv.h |  2 +
 2 files changed, 53 insertions(+), 32 deletions(-)

Comments

Sebastian Reichel Oct. 14, 2017, 12:41 p.m. UTC | #1
Hi,

On Fri, Oct 13, 2017 at 05:59:08PM +0300, Laurent Pinchart wrote:
> When merging the omapdrm and omapdss drivers there will be not omapdrm
> platform device anymore, and thus no associated probe and remove
> functions. To prepare for that, split all the initialization code from
> the probe function to make it usable without a platform device.
> Similarly, split the cleanup code from the remove function.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---

Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>

-- Sebastian

>  drivers/gpu/drm/omapdrm/omap_drv.c | 83 +++++++++++++++++++++++---------------
>  drivers/gpu/drm/omapdrm/omap_drv.h |  2 +
>  2 files changed, 53 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c
> index 2d15ea1d6c92..cbca70f80d8e 100644
> --- a/drivers/gpu/drm/omapdrm/omap_drv.c
> +++ b/drivers/gpu/drm/omapdrm/omap_drv.c
> @@ -542,24 +542,16 @@ static const struct soc_device_attribute omapdrm_soc_devices[] = {
>  	{ /* sentinel */ }
>  };
>  
> -static int pdev_probe(struct platform_device *pdev)
> +static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
>  {
>  	const struct soc_device_attribute *soc;
> -	struct omap_drm_private *priv;
>  	struct drm_device *ddev;
>  	unsigned int i;
>  	int ret;
>  
> -	DBG("%s", pdev->name);
> -
> -	if (omapdss_is_initialized() == false)
> -		return -EPROBE_DEFER;
> +	DBG("%s", dev_name(dev));
>  
> -	ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
> -	if (ret) {
> -		dev_err(&pdev->dev, "Failed to set the DMA mask\n");
> -		return ret;
> -	}
> +	priv->dev = dev;
>  
>  	omap_crtc_pre_init();
>  
> @@ -567,13 +559,6 @@ static int pdev_probe(struct platform_device *pdev)
>  	if (ret)
>  		goto err_crtc_uninit;
>  
> -	/* Allocate and initialize the driver private structure. */
> -	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> -	if (!priv) {
> -		ret = -ENOMEM;
> -		goto err_disconnect_dssdevs;
> -	}
> -
>  	priv->dispc_ops = dispc_get_ops();
>  
>  	soc = soc_device_match(omapdrm_soc_devices);
> @@ -584,27 +569,27 @@ static int pdev_probe(struct platform_device *pdev)
>  	INIT_LIST_HEAD(&priv->obj_list);
>  
>  	/* Allocate and initialize the DRM device. */
> -	ddev = drm_dev_alloc(&omap_drm_driver, &pdev->dev);
> +	ddev = drm_dev_alloc(&omap_drm_driver, priv->dev);
>  	if (IS_ERR(ddev)) {
>  		ret = PTR_ERR(ddev);
> -		goto err_free_priv;
> +		goto err_destroy_wq;
>  	}
>  
> +	priv->ddev = ddev;
>  	ddev->dev_private = priv;
> -	platform_set_drvdata(pdev, ddev);
>  
>  	omap_gem_init(ddev);
>  
>  	ret = omap_modeset_init(ddev);
>  	if (ret) {
> -		dev_err(&pdev->dev, "omap_modeset_init failed: ret=%d\n", ret);
> +		dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
>  		goto err_free_drm_dev;
>  	}
>  
>  	/* Initialize vblank handling, start with all CRTCs disabled. */
>  	ret = drm_vblank_init(ddev, priv->num_crtcs);
>  	if (ret) {
> -		dev_err(&pdev->dev, "could not init vblank\n");
> +		dev_err(priv->dev, "could not init vblank\n");
>  		goto err_cleanup_modeset;
>  	}
>  
> @@ -637,20 +622,17 @@ static int pdev_probe(struct platform_device *pdev)
>  err_free_drm_dev:
>  	omap_gem_deinit(ddev);
>  	drm_dev_unref(ddev);
> -err_free_priv:
> +err_destroy_wq:
>  	destroy_workqueue(priv->wq);
> -	kfree(priv);
> -err_disconnect_dssdevs:
>  	omap_disconnect_dssdevs();
>  err_crtc_uninit:
>  	omap_crtc_pre_uninit();
>  	return ret;
>  }
>  
> -static int pdev_remove(struct platform_device *pdev)
> +static void omapdrm_cleanup(struct omap_drm_private *priv)
>  {
> -	struct drm_device *ddev = platform_get_drvdata(pdev);
> -	struct omap_drm_private *priv = ddev->dev_private;
> +	struct drm_device *ddev = priv->ddev;
>  
>  	DBG("");
>  
> @@ -672,10 +654,45 @@ static int pdev_remove(struct platform_device *pdev)
>  	drm_dev_unref(ddev);
>  
>  	destroy_workqueue(priv->wq);
> -	kfree(priv);
>  
>  	omap_disconnect_dssdevs();
>  	omap_crtc_pre_uninit();
> +}
> +
> +static int pdev_probe(struct platform_device *pdev)
> +{
> +	struct omap_drm_private *priv;
> +	int ret;
> +
> +	if (omapdss_is_initialized() == false)
> +		return -EPROBE_DEFER;
> +
> +	ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
> +	if (ret) {
> +		dev_err(&pdev->dev, "Failed to set the DMA mask\n");
> +		return ret;
> +	}
> +
> +	/* Allocate and initialize the driver private structure. */
> +	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	platform_set_drvdata(pdev, priv);
> +
> +	ret = omapdrm_init(priv, &pdev->dev);
> +	if (ret < 0)
> +		kfree(priv);
> +
> +	return ret;
> +}
> +
> +static int pdev_remove(struct platform_device *pdev)
> +{
> +	struct omap_drm_private *priv = platform_get_drvdata(pdev);
> +
> +	omapdrm_cleanup(priv);
> +	kfree(priv);
>  
>  	return 0;
>  }
> @@ -719,7 +736,8 @@ static int omap_drm_resume_all_displays(void)
>  
>  static int omap_drm_suspend(struct device *dev)
>  {
> -	struct drm_device *drm_dev = dev_get_drvdata(dev);
> +	struct omap_drm_private *priv = dev_get_drvdata(dev);
> +	struct drm_device *drm_dev = priv->ddev;
>  
>  	drm_kms_helper_poll_disable(drm_dev);
>  
> @@ -732,7 +750,8 @@ static int omap_drm_suspend(struct device *dev)
>  
>  static int omap_drm_resume(struct device *dev)
>  {
> -	struct drm_device *drm_dev = dev_get_drvdata(dev);
> +	struct omap_drm_private *priv = dev_get_drvdata(dev);
> +	struct drm_device *drm_dev = priv->ddev;
>  
>  	drm_modeset_lock_all(drm_dev);
>  	omap_drm_resume_all_displays();
> diff --git a/drivers/gpu/drm/omapdrm/omap_drv.h b/drivers/gpu/drm/omapdrm/omap_drv.h
> index 7bf008f02a77..2c06533a2d0a 100644
> --- a/drivers/gpu/drm/omapdrm/omap_drv.h
> +++ b/drivers/gpu/drm/omapdrm/omap_drv.h
> @@ -48,6 +48,8 @@
>  struct omap_drm_usergart;
>  
>  struct omap_drm_private {
> +	struct drm_device *ddev;
> +	struct device *dev;
>  	u32 omaprev;
>  
>  	const struct dispc_ops *dispc_ops;
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox

Patch

diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c
index 2d15ea1d6c92..cbca70f80d8e 100644
--- a/drivers/gpu/drm/omapdrm/omap_drv.c
+++ b/drivers/gpu/drm/omapdrm/omap_drv.c
@@ -542,24 +542,16 @@  static const struct soc_device_attribute omapdrm_soc_devices[] = {
 	{ /* sentinel */ }
 };
 
-static int pdev_probe(struct platform_device *pdev)
+static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
 {
 	const struct soc_device_attribute *soc;
-	struct omap_drm_private *priv;
 	struct drm_device *ddev;
 	unsigned int i;
 	int ret;
 
-	DBG("%s", pdev->name);
-
-	if (omapdss_is_initialized() == false)
-		return -EPROBE_DEFER;
+	DBG("%s", dev_name(dev));
 
-	ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
-	if (ret) {
-		dev_err(&pdev->dev, "Failed to set the DMA mask\n");
-		return ret;
-	}
+	priv->dev = dev;
 
 	omap_crtc_pre_init();
 
@@ -567,13 +559,6 @@  static int pdev_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_crtc_uninit;
 
-	/* Allocate and initialize the driver private structure. */
-	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-	if (!priv) {
-		ret = -ENOMEM;
-		goto err_disconnect_dssdevs;
-	}
-
 	priv->dispc_ops = dispc_get_ops();
 
 	soc = soc_device_match(omapdrm_soc_devices);
@@ -584,27 +569,27 @@  static int pdev_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&priv->obj_list);
 
 	/* Allocate and initialize the DRM device. */
-	ddev = drm_dev_alloc(&omap_drm_driver, &pdev->dev);
+	ddev = drm_dev_alloc(&omap_drm_driver, priv->dev);
 	if (IS_ERR(ddev)) {
 		ret = PTR_ERR(ddev);
-		goto err_free_priv;
+		goto err_destroy_wq;
 	}
 
+	priv->ddev = ddev;
 	ddev->dev_private = priv;
-	platform_set_drvdata(pdev, ddev);
 
 	omap_gem_init(ddev);
 
 	ret = omap_modeset_init(ddev);
 	if (ret) {
-		dev_err(&pdev->dev, "omap_modeset_init failed: ret=%d\n", ret);
+		dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
 		goto err_free_drm_dev;
 	}
 
 	/* Initialize vblank handling, start with all CRTCs disabled. */
 	ret = drm_vblank_init(ddev, priv->num_crtcs);
 	if (ret) {
-		dev_err(&pdev->dev, "could not init vblank\n");
+		dev_err(priv->dev, "could not init vblank\n");
 		goto err_cleanup_modeset;
 	}
 
@@ -637,20 +622,17 @@  static int pdev_probe(struct platform_device *pdev)
 err_free_drm_dev:
 	omap_gem_deinit(ddev);
 	drm_dev_unref(ddev);
-err_free_priv:
+err_destroy_wq:
 	destroy_workqueue(priv->wq);
-	kfree(priv);
-err_disconnect_dssdevs:
 	omap_disconnect_dssdevs();
 err_crtc_uninit:
 	omap_crtc_pre_uninit();
 	return ret;
 }
 
-static int pdev_remove(struct platform_device *pdev)
+static void omapdrm_cleanup(struct omap_drm_private *priv)
 {
-	struct drm_device *ddev = platform_get_drvdata(pdev);
-	struct omap_drm_private *priv = ddev->dev_private;
+	struct drm_device *ddev = priv->ddev;
 
 	DBG("");
 
@@ -672,10 +654,45 @@  static int pdev_remove(struct platform_device *pdev)
 	drm_dev_unref(ddev);
 
 	destroy_workqueue(priv->wq);
-	kfree(priv);
 
 	omap_disconnect_dssdevs();
 	omap_crtc_pre_uninit();
+}
+
+static int pdev_probe(struct platform_device *pdev)
+{
+	struct omap_drm_private *priv;
+	int ret;
+
+	if (omapdss_is_initialized() == false)
+		return -EPROBE_DEFER;
+
+	ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to set the DMA mask\n");
+		return ret;
+	}
+
+	/* Allocate and initialize the driver private structure. */
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, priv);
+
+	ret = omapdrm_init(priv, &pdev->dev);
+	if (ret < 0)
+		kfree(priv);
+
+	return ret;
+}
+
+static int pdev_remove(struct platform_device *pdev)
+{
+	struct omap_drm_private *priv = platform_get_drvdata(pdev);
+
+	omapdrm_cleanup(priv);
+	kfree(priv);
 
 	return 0;
 }
@@ -719,7 +736,8 @@  static int omap_drm_resume_all_displays(void)
 
 static int omap_drm_suspend(struct device *dev)
 {
-	struct drm_device *drm_dev = dev_get_drvdata(dev);
+	struct omap_drm_private *priv = dev_get_drvdata(dev);
+	struct drm_device *drm_dev = priv->ddev;
 
 	drm_kms_helper_poll_disable(drm_dev);
 
@@ -732,7 +750,8 @@  static int omap_drm_suspend(struct device *dev)
 
 static int omap_drm_resume(struct device *dev)
 {
-	struct drm_device *drm_dev = dev_get_drvdata(dev);
+	struct omap_drm_private *priv = dev_get_drvdata(dev);
+	struct drm_device *drm_dev = priv->ddev;
 
 	drm_modeset_lock_all(drm_dev);
 	omap_drm_resume_all_displays();
diff --git a/drivers/gpu/drm/omapdrm/omap_drv.h b/drivers/gpu/drm/omapdrm/omap_drv.h
index 7bf008f02a77..2c06533a2d0a 100644
--- a/drivers/gpu/drm/omapdrm/omap_drv.h
+++ b/drivers/gpu/drm/omapdrm/omap_drv.h
@@ -48,6 +48,8 @@ 
 struct omap_drm_usergart;
 
 struct omap_drm_private {
+	struct drm_device *ddev;
+	struct device *dev;
 	u32 omaprev;
 
 	const struct dispc_ops *dispc_ops;