mirror of
https://github.com/torvalds/linux.git
synced 2026-05-22 06:01:53 +02:00
drm/tilcdc: Modernize driver initialization and cleanup paths
Refactor the driver initialization to use modern DRM managed resource APIs, simplifying the code. The tilcdc_init and tilcdc_fini wrapper functions are removed since they served no purpose after the component framework was eliminated. Their logic is integrated directly into probe and remove. Key changes: - Use devm_drm_dev_alloc() instead of drm_dev_alloc(). - Use drmm_mode_config_init() instead of drm_mode_config_init(). - Align the remove path with the probe error path to ensure consistent cleanup ordering in both success and failure cases. - Adjust platform_set_drvdata() to store the private structure instead of the drm_device, matching the new allocation pattern. These changes reduce error-prone code while maintaining the same functional behavior. Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> Link: https://patch.msgid.link/20260123-feature_tilcdc-v5-16-5a44d2aa3f6f@bootlin.com Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
This commit is contained in:
parent
e41591e747
commit
3301302060
|
|
@ -259,68 +259,33 @@ static int tilcdc_pm_resume(struct device *dev)
|
|||
static DEFINE_SIMPLE_DEV_PM_OPS(tilcdc_pm_ops,
|
||||
tilcdc_pm_suspend, tilcdc_pm_resume);
|
||||
|
||||
static void tilcdc_fini(struct drm_device *dev)
|
||||
static int tilcdc_pdev_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct tilcdc_drm_private *priv = dev->dev_private;
|
||||
|
||||
#ifdef CONFIG_CPU_FREQ
|
||||
if (priv->freq_transition.notifier_call)
|
||||
cpufreq_unregister_notifier(&priv->freq_transition,
|
||||
CPUFREQ_TRANSITION_NOTIFIER);
|
||||
#endif
|
||||
|
||||
if (priv->crtc)
|
||||
tilcdc_crtc_shutdown(priv->crtc);
|
||||
|
||||
drm_dev_unregister(dev);
|
||||
|
||||
drm_kms_helper_poll_fini(dev);
|
||||
drm_atomic_helper_shutdown(dev);
|
||||
tilcdc_irq_uninstall(dev);
|
||||
drm_mode_config_cleanup(dev);
|
||||
|
||||
if (priv->clk)
|
||||
clk_put(priv->clk);
|
||||
|
||||
if (priv->wq)
|
||||
destroy_workqueue(priv->wq);
|
||||
|
||||
dev->dev_private = NULL;
|
||||
|
||||
pm_runtime_disable(dev->dev);
|
||||
|
||||
drm_dev_put(dev);
|
||||
}
|
||||
|
||||
static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev)
|
||||
{
|
||||
struct drm_device *ddev;
|
||||
struct platform_device *pdev = to_platform_device(dev);
|
||||
struct device_node *node = dev->of_node;
|
||||
struct device_node *node = pdev->dev.of_node;
|
||||
struct tilcdc_drm_private *priv;
|
||||
struct device *dev = &pdev->dev;
|
||||
enum tilcdc_variant variant;
|
||||
struct drm_device *ddev;
|
||||
u32 bpp = 0;
|
||||
int ret;
|
||||
|
||||
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return -ENOMEM;
|
||||
|
||||
ddev = drm_dev_alloc(ddrv, dev);
|
||||
if (IS_ERR(ddev))
|
||||
return PTR_ERR(ddev);
|
||||
priv = devm_drm_dev_alloc(dev, &tilcdc_driver,
|
||||
struct tilcdc_drm_private, ddev);
|
||||
if (IS_ERR(priv))
|
||||
return PTR_ERR(priv);
|
||||
|
||||
variant = (uintptr_t)of_device_get_match_data(dev);
|
||||
|
||||
ddev->dev_private = priv;
|
||||
platform_set_drvdata(pdev, ddev);
|
||||
drm_mode_config_init(ddev);
|
||||
platform_set_drvdata(pdev, priv);
|
||||
ddev = &priv->ddev;
|
||||
ret = drmm_mode_config_init(ddev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
priv->wq = alloc_ordered_workqueue("tilcdc", 0);
|
||||
if (!priv->wq) {
|
||||
ret = -ENOMEM;
|
||||
goto put_drm;
|
||||
}
|
||||
if (!priv->wq)
|
||||
return -ENOMEM;
|
||||
|
||||
priv->mmio = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(priv->mmio)) {
|
||||
|
|
@ -486,33 +451,34 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev)
|
|||
clk_put(priv->clk);
|
||||
free_wq:
|
||||
destroy_workqueue(priv->wq);
|
||||
put_drm:
|
||||
platform_set_drvdata(pdev, NULL);
|
||||
ddev->dev_private = NULL;
|
||||
drm_dev_put(ddev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int tilcdc_pdev_probe(struct platform_device *pdev)
|
||||
{
|
||||
/* bail out early if no DT data: */
|
||||
if (!pdev->dev.of_node) {
|
||||
dev_err(&pdev->dev, "device-tree data is missing\n");
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
return tilcdc_init(&tilcdc_driver, &pdev->dev);
|
||||
}
|
||||
|
||||
static void tilcdc_pdev_remove(struct platform_device *pdev)
|
||||
{
|
||||
tilcdc_fini(platform_get_drvdata(pdev));
|
||||
struct tilcdc_drm_private *priv = platform_get_drvdata(pdev);
|
||||
struct drm_device *ddev = &priv->ddev;
|
||||
|
||||
drm_dev_unregister(ddev);
|
||||
drm_kms_helper_poll_fini(ddev);
|
||||
tilcdc_irq_uninstall(ddev);
|
||||
#ifdef CONFIG_CPU_FREQ
|
||||
cpufreq_unregister_notifier(&priv->freq_transition,
|
||||
CPUFREQ_TRANSITION_NOTIFIER);
|
||||
#endif
|
||||
tilcdc_crtc_destroy(priv->crtc);
|
||||
pm_runtime_disable(&pdev->dev);
|
||||
clk_put(priv->clk);
|
||||
destroy_workqueue(priv->wq);
|
||||
}
|
||||
|
||||
static void tilcdc_pdev_shutdown(struct platform_device *pdev)
|
||||
{
|
||||
drm_atomic_helper_shutdown(platform_get_drvdata(pdev));
|
||||
struct tilcdc_drm_private *priv = platform_get_drvdata(pdev);
|
||||
struct drm_device *ddev = &priv->ddev;
|
||||
|
||||
drm_atomic_helper_shutdown(ddev);
|
||||
}
|
||||
|
||||
static const struct of_device_id tilcdc_of_match[] = {
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ struct tilcdc_drm_private {
|
|||
|
||||
unsigned int irq;
|
||||
|
||||
struct drm_device ddev;
|
||||
|
||||
/* don't attempt resolutions w/ higher W * H * Hz: */
|
||||
uint32_t max_bandwidth;
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user