video: imxfb: Fix unbalanced regulators
PATCH v2 1/2 video: imxfb: Fix unbalanced regulators
Both regulator_enable and regulator_disable's comments say that they must be balanced with its counterpart enable/disable function.
Not doing it result in kernel warnings each time the lcd is powered off twice, for instance trough sysfs.
---
Changelog v1->v2:
- None
--- drivers/video/fbdev/imxfb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/video/fbdev/imxfb.c +2 -2
@@ -769,9 +769,9 @@ static int imxfb_lcd_set_power(struct lcd_device *lcddev, int power)struct imxfb_info *fbi =dev_get_drvdata (&lcddev->dev);if (!IS_ERR (fbi->lcd_pwr)) { -if (power) +if (power && !regulator_is_enabled (fbi->lcd_pwr))return regulator_enable (fbi->lcd_pwr); -else +else if (regulator_is_enabled (fbi->lcd_pwr))return regulator_disable (fbi->lcd_pwr); }
Signature · 1 line
1.7.9.5
PATCH v2 2/2 video: imxfb: Fix lcd_ops .set_power and .get_power on/off inversion
.set_power takes the blank level as argument instead of an on/off parameter:fb_blank calls fb_notifier_call_chain with the blank level encoded in its parameters, which is then sent as-is to the set_power callback.
imxfb_lcd_set_power was expecting an on/off parameter instead.
This resulted in the inversion of the on/off behaviour.
.get_power was also fixed in the same way.
---
Changelog v1->v2:
- get_power which has the same issue, was also fixed as requested.
- The commit message was updated to reflect that.
--- drivers/video/fbdev/imxfb.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/video/fbdev/imxfb.c +19 -8
@@ -758,21 +758,32 @@ static int imxfb_lcd_get_power(struct lcd_device *lcddev) {struct imxfb_info *fbi =dev_get_drvdata (&lcddev->dev); -if (!IS_ERR (fbi->lcd_pwr)) -return regulator_is_enabled (fbi->lcd_pwr); +if (!IS_ERR_OR_NULL (fbi->lcd_pwr)) +if (!regulator_is_enabled (fbi->lcd_pwr)) +return FB_BLANK_NORMAL ; -return 1 ; +return FB_BLANK_UNBLANK ; } -static int imxfb_lcd_set_power (struct lcd_device *lcddev,int power) +static int imxfb_lcd_set_power (struct lcd_device *lcddev,int blank) {struct imxfb_info *fbi =dev_get_drvdata (&lcddev->dev);if (!IS_ERR (fbi->lcd_pwr)) { -if (power && !regulator_is_enabled (fbi->lcd_pwr)) -return regulator_enable (fbi->lcd_pwr); -else if (regulator_is_enabled (fbi->lcd_pwr)) -return regulator_disable (fbi->lcd_pwr); +switch (blank) { +case FB_BLANK_VSYNC_SUSPEND : +case FB_BLANK_HSYNC_SUSPEND : +case FB_BLANK_NORMAL : +case FB_BLANK_POWERDOWN : +if (regulator_is_enabled (fbi->lcd_pwr)) +return regulator_disable (fbi->lcd_pwr); +break ; + +case FB_BLANK_UNBLANK : +if (!regulator_is_enabled (fbi->lcd_pwr)) +return regulator_enable (fbi->lcd_pwr); +break ; + } }return 0 ;
Signature · 1 line
1.7.9.5
Sascha Hauer
maintainerPATCH v2 2/2 video: imxfb: Fix lcd_ops .set_power and .get_power on/off inversion
Quoted 26 lines · Denis Carikli
.set_power takes the blank level as argument instead of an on/off parameter:
fb_blankcallsfb_notifier_call_chainwith the blank level encoded in its parameters, which is then sent as-is to theset_powercallback.
imxfb_lcd_set_powerwas expecting an on/off parameter instead.
This resulted in the inversion of the on/off behaviour..get_power was also fixed in the same way.
Signed-off-by Denis Carikli <[email protected]>---
Changelogv1->v2:
-get_powerwhich has the same issue, was also fixed as requested.
- The commit message was updated to reflect that.--- drivers/video/fbdev/imxfb.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)drivers/video/fbdev/imxfb.c +0
-0
drivers/video/fbdev/imxfb.c static int imxfb_lcd_get_power(struct lcd_device *lcddev) · line 763
Quoted 8 lines
drivers/video/fbdev/imxfb.c +3
-2@@ -758,21 +758,32 @@ static int imxfb_lcd_get_power(struct lcd_device *lcddev) {struct imxfb_info *fbi =dev_get_drvdata (&lcddev->dev); -if (!IS_ERR (fbi->lcd_pwr)) -return regulator_is_enabled (fbi->lcd_pwr); +if (!IS_ERR_OR_NULL (fbi->lcd_pwr)) +if (!regulator_is_enabled (fbi->lcd_pwr)) +return FB_BLANK_NORMAL ;
You use IS_ERR_OR_NULL() here. imxfb_lcd_set_power uses IS_ERR(). One of both must be wrong.
Quoted 20 lines
drivers/video/fbdev/imxfb.c +7
-6-return 1 ; +return FB_BLANK_UNBLANK ; } -static int imxfb_lcd_set_power (struct lcd_device *lcddev,int power) +static int imxfb_lcd_set_power (struct lcd_device *lcddev,int blank) {struct imxfb_info *fbi =dev_get_drvdata (&lcddev->dev);if (!IS_ERR (fbi->lcd_pwr)) { -if (power && !regulator_is_enabled (fbi->lcd_pwr)) -return regulator_enable (fbi->lcd_pwr); -else if (regulator_is_enabled (fbi->lcd_pwr)) -return regulator_disable (fbi->lcd_pwr); +switch (blank) { +case FB_BLANK_VSYNC_SUSPEND : +case FB_BLANK_HSYNC_SUSPEND : +case FB_BLANK_NORMAL : +case FB_BLANK_POWERDOWN :
drivers/video/fbdev/imxfb.c static int imxfb_lcd_get_power(struct lcd_device *lcddev) · line 787
Quoted 10 lines
drivers/video/fbdev/imxfb.c +9
-0+if (regulator_is_enabled (fbi->lcd_pwr)) +return regulator_disable (fbi->lcd_pwr); +break ; + +case FB_BLANK_UNBLANK : +if (!regulator_is_enabled (fbi->lcd_pwr)) +return regulator_enable (fbi->lcd_pwr); +break ; + } }
You could reduce indentation by bailing out early:
if (IS_ERR(fbi->lcd_pwr)) return 0;
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH v2 2/2 video: imxfb: Fix lcd_ops .set_power and .get_power on/off inversion
Quoted 2 lines · Sascha Hauer
You use
IS_ERR_OR_NULL()here.imxfb_lcd_set_powerusesIS_ERR(). One of both must be wrong.
Fixed by using IS_ERR_OR_NULL.
Quoted 4 lines
You could reduce indentation by bailing out early:
if (IS_ERR(fbi->lcd_pwr)) return 0;
Fixed (with IS_ERR_OR_NULL).
Denis.
Sascha Hauer
maintainerPATCH v2 1/2 video: imxfb: Fix unbalanced regulators
In reply to Denis CarikliQuoted 20 lines · Denis Carikli
Both
regulator_enableand regulator_disable's comments say that they must be balanced with its counterpart enable/disable function.Not doing it result in kernel warnings each time the lcd is powered off twice, for instance trough sysfs.
Signed-off-by Denis Carikli <[email protected]>---
Changelogv1->v2:
- None--- drivers/video/fbdev/imxfb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/video/fbdev/imxfb.c +0
-0
drivers/video/fbdev/imxfb.c static int imxfb_lcd_set_power(struct lcd_device *lcddev, int power) · line 775
Quoted 9 lines
drivers/video/fbdev/imxfb.c +2
-2@@ -769,9 +769,9 @@ static int imxfb_lcd_set_power(struct lcd_device *lcddev, int power)struct imxfb_info *fbi =dev_get_drvdata (&lcddev->dev);if (!IS_ERR (fbi->lcd_pwr)) { -if (power) +if (power && !regulator_is_enabled (fbi->lcd_pwr))return regulator_enable (fbi->lcd_pwr); -else +else if (regulator_is_enabled (fbi->lcd_pwr))return regulator_disable (fbi->lcd_pwr);
It's a shame that the LCD controller doesn't do the reference counting. I really think it should be fixed there and not in the drivers. If for whatever reason this is not acceptable then it should be done in the imxfb driver instead of shifting it further to the regulator core.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH v2 1/2 video: imxfb: Fix unbalanced regulators
Quoted 4 lines · Sascha Hauer
It's a shame that the LCD controller doesn't do the reference counting. I really think it should be fixed there and not in the drivers.If for whatever reason this is not acceptable then it should be done in the imxfb driver instead of shifting it further to the regulator core.
I'm not sure that doing reference counting in the LCD class would be enough for the regulator case. Still it seems to be a good thing to do.
If I understood well, that assumes that the LCD driver is the only consumer and owner of that regulator.
There is also the fact that the regulator core also enables or disables regulators by itself:
For instance at boot it tries to disable the regulators that can be disabled, including this regulator.
So I don't see any ways to handle it correctly in the LCD.
Denis.
PATCH v2 1/2 video: imxfb: Fix unbalanced regulators
Quoted 2 lines · Denis Carikli
Quoted 1 line · Sascha Hauer
It's a shame that the LCD controller doesn't do the reference counting.
[...]
Quoted 1 line
So I don't see any ways to handle it correctly in the LCD.
Unless if the LCD core, instead of doing reference counting, does the check by itself, by using get_power().
But I doubt that it would be a good solution (I fear that it would have race conditions).
Denis.
Sascha Hauer
maintainerPATCH v2 1/2 video: imxfb: Fix unbalanced regulators
In reply to Denis CarikliQuoted 11 lines · Denis Carikli
Quoted 4 lines · Sascha Hauer
It's a shame that the LCD controller doesn't do the reference counting. I really think it should be fixed there and not in the drivers.If for whatever reason this is not acceptable then it should be done in the imxfb driver instead of shifting it further to the regulator core.
I'm not sure that doing reference counting in the LCD class would be enough for the regulator case. Still it seems to be a good thing to do.
If I understood well, that assumes that the LCD driver is the only consumer and owner of that regulator.
No. All consumers of a regulator must make sure the regulator enable count is balanced.
Image that the regulator in the imxfb is used by multiple consumers. When you want to enable the backlight you must make sure that you take a reference to the regulator yourself. Otherwise it may happen that 'if (regulator_is_enabled())' is true because another consumer has enabled it and your code does nothing. Then the other consumer decides to disable the regulator which in this case will accidently disable the backlight.
Quoted 7 lines
There is also the fact that the regulator core also enables or disables regulators by itself:
For instance at boot it tries to disable the regulators that can be disabled, including this regulator.So I don't see any ways to handle it correctly in the LCD.
It's simple. Add an lcd_enable flag to struct lcd_device. Make sure you only call into the drivers when it differs from the current state.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH v2 1/2 video: imxfb: Fix unbalanced regulators
In reply to Denis CarikliQuoted 7 lines · Denis Carikli
Both
regulator_enableand regulator_disable's comments say that they must be balanced with its counterpart enable/disable function.Not doing it result in kernel warnings each time the lcd is powered off twice, for instance trough sysfs.
Quoted 7 lines
Signed-off-by Denis Carikli <[email protected]>---
Changelogv1->v2:
- None--- drivers/video/fbdev/imxfb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
This two patches should have fbdev maintainers and list on copy.
Shawn