Den 12.02.2019 15.06, skrev Daniel Vetter: > On Sun, Feb 10, 2019 at 02:10:30PM +0100, Noralf Trønnes wrote: >> Add driver example that shows how devm_drm_dev_init() can be used. >> >> Signed-off-by: Noralf Trønnes <noralf@xxxxxxxxxxx> >> --- >> >> I'm not sure how detailed such an example such be and a description of >> some kind is also required. Help is needed :-) > > Personally I'd make it more minimal, pseudo-code style, removing most of > the boilerplate (e.g. the container_of wrapper). That way it can highlight > the important bits more. But it's already very minimal. > > Wrt text, maybe a minimal intro paragraph. Aside from that looks all good > to me. > > Acked-by: Daniel Vetter <daniel.vetter@xxxxxxxx> > > One question below. >> >> Noralf. >> >> drivers/gpu/drm/drm_drv.c | 118 ++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 118 insertions(+) >> >> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c >> index 351f128ec4b7..99ca3551688f 100644 >> --- a/drivers/gpu/drm/drm_drv.c >> +++ b/drivers/gpu/drm/drm_drv.c >> @@ -286,6 +286,124 @@ void drm_minor_release(struct drm_minor *minor) >> * Note that the lifetime rules for &drm_device instance has still a lot of >> * historical baggage. Hence use the reference counting provided by >> * drm_dev_get() and drm_dev_put() only carefully. >> + * >> + * Display driver example >> + * ~~~~~~~~~~~~~~~~~~~~~~ >> + * >> + * .. code-block:: c >> + * >> + * struct driver_device { >> + * struct drm_device drm; >> + * void *userspace_facing; >> + * struct clk *pclk; >> + * }; >> + * >> + * static inline struct driver_device *drm_to_priv(struct drm_device *drm) >> + * { >> + * return container_of(drm, struct driver_device, drm); >> + * } >> + * >> + * static void driver_drm_release(struct drm_device *drm) >> + * { >> + * struct driver_device *priv = drm_to_priv(drm); >> + * >> + * drm_mode_config_cleanup(drm); >> + * drm_dev_fini(drm); >> + * kfree(priv->userspace_facing); >> + * kfree(priv); >> + * } >> + * >> + * static struct drm_driver driver_drm_driver = { >> + * [...] >> + * .release = driver_drm_release, >> + * }; >> + * >> + * static int driver_probe(struct platform_device *pdev) >> + * { >> + * struct driver_device *priv; >> + * struct drm_device *drm; >> + * int ret; >> + * >> + * priv = kzalloc(sizeof(*priv), GFP_KERNEL); >> + * if (!priv) >> + * return -ENOMEM; >> + * >> + * drm = &priv->drm; >> + * >> + * ret = devm_drm_dev_init(&pdev->dev, drm, &driver_drm_driver); >> + * if (ret) { >> + * kfree(drm); >> + * return ret; >> + * } >> + * >> + * drm_mode_config_init(drm); >> + * >> + * priv->userspace_facing = kzalloc(..., GFP_KERNEL); >> + * if (!priv->userspace_facing) >> + * return -ENOMEM; >> + * >> + * priv->pclk = devm_clk_get(dev, "PCLK"); >> + * if (IS_ERR(priv->pclk)) >> + * return PTR_ERR(priv->pclk); >> + * >> + * [ Further setup, display pipeline etc ] >> + * >> + * drm_mode_config_reset(drm); >> + * >> + * ret = drm_dev_register(drm); >> + * if (ret) >> + * return ret; >> + * >> + * platform_set_drvdata(pdev, drm); > > Hm, don't we need to set that before registering? Or even before > drm_mode_config_reset? Kinda depends upon what the driver is using the > drvdata for. > Yeah, it depends. I can move up though, it doesn't hurt, since drvdata is cleared by the driver core if probe fails. Noralf. >> + * >> + * drm_fbdev_generic_setup(drm, 32); >> + * >> + * return 0; >> + * } >> + * >> + * [ This function is called before the devm_ resources are released ] >> + * static int driver_remove(struct platform_device *pdev) >> + * { >> + * struct drm_device *drm = platform_get_drvdata(pdev); >> + * >> + * drm_dev_unregister(drm); >> + * drm_atomic_helper_shutdown(drm) >> + * >> + * return 0; >> + * } >> + * >> + * static void driver_shutdown(struct platform_device *pdev) >> + * { >> + * drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); >> + * } >> + * >> + * static int __maybe_unused driver_pm_suspend(struct device *dev) >> + * { >> + * return drm_mode_config_helper_suspend(dev_get_drvdata(dev)); >> + * } >> + * >> + * static int __maybe_unused driver_pm_resume(struct device *dev) >> + * { >> + * drm_mode_config_helper_resume(dev_get_drvdata(dev)); >> + * >> + * return 0; >> + * } >> + * >> + * static const struct dev_pm_ops driver_pm_ops = { >> + * SET_SYSTEM_SLEEP_PM_OPS(driver_pm_suspend, driver_pm_resume) >> + * }; >> + * >> + * static struct platform_driver driver_driver = { >> + * .driver = { >> + * [...] >> + * .pm = &driver_pm_ops, >> + * }, >> + * .probe = driver_probe, >> + * .remove = driver_remove, >> + * .shutdown = driver_shutdown, >> + * }; >> + * module_platform_driver(driver_driver); >> + * >> */ >> >> /** >> -- >> 2.20.1 >> > _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel