Skip to contentSkip to conversation

backlight: da903x_bl: switch to using SIMPLE_DEV_PM_OPS

PATCH In review Jingoo Han 2 participants 4 messages Mar 12, 2013 – Mar 13, 2013

Subsystems (3)
lore
Share & tools
lore

Jingoo Han

author
#0 lore raw

PATCH 1/1 backlight: da903x_bl: switch to using SIMPLE_DEV_PM_OPS

This reduces #ifdefs in the code. Also, CONFIG_PM_SLEEP is used to avoid warnings of unused functions if CONFIG_PM_SLEEP is not defined.

---
 drivers/video/backlight/da903x_bl.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
drivers/video/backlight/da903x_bl.c +4 -8
index 8179cef..c625f6d 100644
@@ -161,7 +161,7 @@ static int da903x_backlight_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM
+#ifdef CONFIG_PM_SLEEP
 static int da903x_backlight_suspend(struct device *dev)
 {
 	struct backlight_device *bl = dev_get_drvdata(dev);
@@ -176,20 +176,16 @@ static int da903x_backlight_resume(struct device *dev)
 	backlight_update_status(bl);
 	return 0;
 }
-
-static const struct dev_pm_ops da903x_backlight_pm_ops = {
-	.suspend	= da903x_backlight_suspend,
-	.resume		= da903x_backlight_resume,
-};
 #endif
 
+static SIMPLE_DEV_PM_OPS(da903x_backlight_pm_ops, da903x_backlight_suspend,
+			da903x_backlight_resume);
+
 static struct platform_driver da903x_backlight_driver = {
 	.driver		= {
 		.name	= "da903x-backlight",
 		.owner	= THIS_MODULE,
-#ifdef CONFIG_PM
 		.pm	= &da903x_backlight_pm_ops,
-#endif
 	},
 	.probe		= da903x_backlight_probe,
 	.remove		= da903x_backlight_remove,
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 5 lines · Jingoo Han

This reduces #ifdefs in the code. Also, CONFIG_PM_SLEEP is used to avoid warnings of unused functions if CONFIG_PM_SLEEP is not defined.

I think you can eliminate the suspend/resume functions all together by using the blacklight subsystems CORE_SUSPENDRESUME feature.

E.g.

(quoted diff) +0 -0

b/drivers/video/backlight/da903x_bl.c
index 8179cef..80ba6b3 100644

drivers/video/backlight/da903x_bl.c +4 -25
@@ -88,6 +88,9 @@ static int da903x_backlight_update_status(struct
 	if (bl->props.fb_blank != FB_BLANK_UNBLANK)
 		brightness = 0;
 
+	if (bl->props.state & BL_CORE_SUSPENDED)
+		brightness = 0;
+
 	return da903x_backlight_set(bl, brightness);
 }
 
@@ -100,6 +103,7 @@ static int da903x_backlight_get_brightness(struct
 static const struct backlight_ops da903x_backlight_ops = {
 	.update_status	= da903x_backlight_update_status,
 	.get_brightness	= da903x_backlight_get_brightness,
+	.options	= BL_CORE_SUSPENDRESUME,
 };
 
 static int da903x_backlight_probe(struct platform_device *pdev)
@@ -161,35 +165,10 @@ static int da903x_backlight_remove(struct
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int da903x_backlight_suspend(struct device *dev)
-{
-	struct backlight_device *bl = dev_get_drvdata(dev);
-
-	return da903x_backlight_set(bl, 0);
-}
-
-static int da903x_backlight_resume(struct device *dev)
-{
-	struct backlight_device *bl = dev_get_drvdata(dev);
-
-	backlight_update_status(bl);
-	return 0;
-}
-
-static const struct dev_pm_ops da903x_backlight_pm_ops = {
-	.suspend	= da903x_backlight_suspend,
-	.resume		= da903x_backlight_resume,
-};
-#endif
-
 static struct platform_driver da903x_backlight_driver = {
 	.driver		= {
 		.name	= "da903x-backlight",
 		.owner	= THIS_MODULE,
-#ifdef CONFIG_PM
-		.pm	= &da903x_backlight_pm_ops,
-#endif
 	},
 	.probe		= da903x_backlight_probe,
 	.remove		= da903x_backlight_remove,
author
#2 lore raw
Quoted 10 lines · Lars-Peter Clausen
Quoted 5 lines · Jingoo Han

This reduces #ifdefs in the code. Also, CONFIG_PM_SLEEP is used to avoid warnings of unused functions if CONFIG_PM_SLEEP is not defined.

I think you can eliminate the suspend/resume functions all together by using the blacklight subsystems CORE_SUSPENDRESUME feature.

Hi Lars-Peter Clausen,

Yes, you're right.
I will use CORE_SUSPENDRESUME feature.
Thank you for your comment :)

Best regards,
Jingoo Han

Quoted 62 lines

E.g.

drivers/video/backlight/da903x_bl.c +4 -25
index 8179cef..80ba6b3 100644
@@ -88,6 +88,9 @@ static int da903x_backlight_update_status(struct
 	if (bl->props.fb_blank != FB_BLANK_UNBLANK)
 		brightness = 0;
 
+	if (bl->props.state & BL_CORE_SUSPENDED)
+		brightness = 0;
+
 	return da903x_backlight_set(bl, brightness);
 }
 
@@ -100,6 +103,7 @@ static int da903x_backlight_get_brightness(struct
 static const struct backlight_ops da903x_backlight_ops = {
 	.update_status	= da903x_backlight_update_status,
 	.get_brightness	= da903x_backlight_get_brightness,
+	.options	= BL_CORE_SUSPENDRESUME,
 };
 
 static int da903x_backlight_probe(struct platform_device *pdev)
@@ -161,35 +165,10 @@ static int da903x_backlight_remove(struct
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int da903x_backlight_suspend(struct device *dev)
-{
-	struct backlight_device *bl = dev_get_drvdata(dev);
-
-	return da903x_backlight_set(bl, 0);
-}
-
-static int da903x_backlight_resume(struct device *dev)
-{
-	struct backlight_device *bl = dev_get_drvdata(dev);
-
-	backlight_update_status(bl);
-	return 0;
-}
-
-static const struct dev_pm_ops da903x_backlight_pm_ops = {
-	.suspend	= da903x_backlight_suspend,
-	.resume		= da903x_backlight_resume,
-};
-#endif
-
 static struct platform_driver da903x_backlight_driver = {
 	.driver		= {
 		.name	= "da903x-backlight",
 		.owner	= THIS_MODULE,
-#ifdef CONFIG_PM
-		.pm	= &da903x_backlight_pm_ops,
-#endif
 	},
 	.probe		= da903x_backlight_probe,
 	.remove		= da903x_backlight_remove,
author
#3 lore raw

PATCH 1/1 backlight: da903x_bl: use BL_CORE_SUSPENDRESUME option

In reply to Jingoo Han

Use BL_CORE_SUSPENDRESUME option to support suspend/resume. It reduces code size.

Cc Lars-Peter Clausen <[email protected]>
---
 drivers/video/backlight/da903x_bl.c |   30 +++++-------------------------
 1 files changed, 5 insertions(+), 25 deletions(-)
drivers/video/backlight/da903x_bl.c +5 -25
index 8179cef..67cadd3 100644
@@ -88,16 +88,21 @@ static int da903x_backlight_update_status(struct backlight_device *bl)
 	if (bl->props.fb_blank != FB_BLANK_UNBLANK)
 		brightness = 0;
 
+	if (bl->props.state & BL_CORE_SUSPENDED)
+		brightness = 0;
+
 	return da903x_backlight_set(bl, brightness);
 }
 
 static int da903x_backlight_get_brightness(struct backlight_device *bl)
 {
 	struct da903x_backlight_data *data = bl_get_data(bl);
+
 	return data->current_brightness;
 }
 
 static const struct backlight_ops da903x_backlight_ops = {
+	.options	= BL_CORE_SUSPENDRESUME,
 	.update_status	= da903x_backlight_update_status,
 	.get_brightness	= da903x_backlight_get_brightness,
 };
@@ -161,35 +166,10 @@ static int da903x_backlight_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int da903x_backlight_suspend(struct device *dev)
-{
-	struct backlight_device *bl = dev_get_drvdata(dev);
-
-	return da903x_backlight_set(bl, 0);
-}
-
-static int da903x_backlight_resume(struct device *dev)
-{
-	struct backlight_device *bl = dev_get_drvdata(dev);
-
-	backlight_update_status(bl);
-	return 0;
-}
-
-static const struct dev_pm_ops da903x_backlight_pm_ops = {
-	.suspend	= da903x_backlight_suspend,
-	.resume		= da903x_backlight_resume,
-};
-#endif
-
 static struct platform_driver da903x_backlight_driver = {
 	.driver		= {
 		.name	= "da903x-backlight",
 		.owner	= THIS_MODULE,
-#ifdef CONFIG_PM
-		.pm	= &da903x_backlight_pm_ops,
-#endif
 	},
 	.probe		= da903x_backlight_probe,
 	.remove		= da903x_backlight_remove,
Signature · 1 line
1.7.2.5