@@ -41,4 +41,42 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
int drm_mode_config_helper_suspend(struct drm_device *dev);
int drm_mode_config_helper_resume(struct drm_device *dev);
+/**
+ * DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS - Generate simple PM callbacks
+ *
+ * This macro can be used by simple drivers that would otherwise only call
+ * drm_mode_config_helper_suspend / drm_mode_config_helper_resume in their PM
+ * callbacks. It will generate a struct dev_pm_ops of the given name, that can
+ * then be referenced in the device_driver structure.
+ *
+ * Note that it is only valid if the driver's drm_device has been registered as
+ * the struct device's drvdata.
+ *
+ * Additionally, the generated dev_pm_ops structure should not be referenced
+ * directly; instead, the pm_sleep_ptr() macro should be used, like this:
+ *
+ * DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS(foo_pm_ops);
+ *
+ * static struct platform_driver foo_driver = {
+ * .driver.pm = pm_sleep_ptr(&foo_pm_ops),
+ * ...
+ * };
+ *
+ * This ensures that the generated code will be dropped by the compiler in the
+ * case where CONFIG_PM has been disabled in the config.
++ */
+
+#define DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS(_name) \
+ static int __##_name##_drm_mode_config_pm_suspend(struct device *dev) \
+ { \
+ return drm_mode_config_helper_suspend(dev_get_drvdata(dev)); \
+ } \
+ static int __##_name##_drm_mode_config_pm_resume(struct device *dev) \
+ { \
+ return drm_mode_config_helper_resume(dev_get_drvdata(dev)); \
+ } \
+ static DEFINE_SIMPLE_DEV_PM_OPS(_name, \
+ __##_name##_drm_mode_config_pm_suspend, \
+ __##_name##_drm_mode_config_pm_resume)
+
#endif
This macro can be used with simple drivers, which have their "struct drm_device" registered as their "struct device"'s drvdata, and only call drm_mode_config_pm_{suspend,resume}. The macro will define a "struct dev_pm_ops" with the name passed as argument. This object cannot be referenced directly; instead, the pm_sleep_ptr() macro should be used, like this: DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS(foo_pm_ops); static struct platform_driver foo_driver = { .driver.pm = pm_sleep_ptr(&foo_pm_ops), ... }; This ensures that the generated code will be dropped by the compiler in the case where CONFIG_PM has been disabled in the config. v2: instead of exporting a dev_pm_ops, introduce the DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS() macro. Signed-off-by: Paul Cercueil <paul@crapouillou.net> --- include/drm/drm_modeset_helper.h | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)