diff mbox series

video: fbdev: imxfb: ensure balanced regulator usage

Message ID 20200323211626.24812-1-u.kleine-koenig@pengutronix.de (mailing list archive)
State Accepted, archived
Commit 5c694f8094e4
Headers show
Series video: fbdev: imxfb: ensure balanced regulator usage | expand

Commit Message

Uwe Kleine-König March 23, 2020, 9:16 p.m. UTC
The fbdev framework doesn't care to call the .set_power callback only on
changes. So the driver has to care for itself that the regulator doesn't
get disabled more often than enabled.

This fixes the regulator warning

	unbalanced disables for lcd supply

which can be triggered by doing

	echo 4 > /sys/class/lcd/imxfb-lcd/lcd_power

twice.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/video/fbdev/imxfb.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

Comments

Bartlomiej Zolnierkiewicz April 17, 2020, 2:07 p.m. UTC | #1
On 3/23/20 10:16 PM, Uwe Kleine-König wrote:
> The fbdev framework doesn't care to call the .set_power callback only on
> changes. So the driver has to care for itself that the regulator doesn't
> get disabled more often than enabled.
> 
> This fixes the regulator warning
> 
> 	unbalanced disables for lcd supply
> 
> which can be triggered by doing
> 
> 	echo 4 > /sys/class/lcd/imxfb-lcd/lcd_power
> 
> twice.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Patch queued for v5.8, thanks.

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

> ---
>  drivers/video/fbdev/imxfb.c | 27 +++++++++++++++++++++------
>  1 file changed, 21 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c
> index 370bf2553d43..884b16efa7e8 100644
> --- a/drivers/video/fbdev/imxfb.c
> +++ b/drivers/video/fbdev/imxfb.c
> @@ -172,6 +172,7 @@ struct imxfb_info {
>  	int			num_modes;
>  
>  	struct regulator	*lcd_pwr;
> +	int			lcd_pwr_enabled;
>  };
>  
>  static const struct platform_device_id imxfb_devtype[] = {
> @@ -801,16 +802,30 @@ static int imxfb_lcd_get_power(struct lcd_device *lcddev)
>  	return FB_BLANK_UNBLANK;
>  }
>  
> +static int imxfb_regulator_set(struct imxfb_info *fbi, int enable)
> +{
> +	int ret;
> +
> +	if (enable == fbi->lcd_pwr_enabled)
> +		return 0;
> +
> +	if (enable)
> +		ret = regulator_enable(fbi->lcd_pwr);
> +	else
> +		ret = regulator_disable(fbi->lcd_pwr);
> +
> +	if (ret == 0)
> +		fbi->lcd_pwr_enabled = enable;
> +
> +	return ret;
> +}
> +
>  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 == FB_BLANK_UNBLANK)
> -			return regulator_enable(fbi->lcd_pwr);
> -		else
> -			return regulator_disable(fbi->lcd_pwr);
> -	}
> +	if (!IS_ERR(fbi->lcd_pwr))
> +		return imxfb_regulator_set(fbi, power == FB_BLANK_UNBLANK);
>  
>  	return 0;
>  }
>
diff mbox series

Patch

diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c
index 370bf2553d43..884b16efa7e8 100644
--- a/drivers/video/fbdev/imxfb.c
+++ b/drivers/video/fbdev/imxfb.c
@@ -172,6 +172,7 @@  struct imxfb_info {
 	int			num_modes;
 
 	struct regulator	*lcd_pwr;
+	int			lcd_pwr_enabled;
 };
 
 static const struct platform_device_id imxfb_devtype[] = {
@@ -801,16 +802,30 @@  static int imxfb_lcd_get_power(struct lcd_device *lcddev)
 	return FB_BLANK_UNBLANK;
 }
 
+static int imxfb_regulator_set(struct imxfb_info *fbi, int enable)
+{
+	int ret;
+
+	if (enable == fbi->lcd_pwr_enabled)
+		return 0;
+
+	if (enable)
+		ret = regulator_enable(fbi->lcd_pwr);
+	else
+		ret = regulator_disable(fbi->lcd_pwr);
+
+	if (ret == 0)
+		fbi->lcd_pwr_enabled = enable;
+
+	return ret;
+}
+
 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 == FB_BLANK_UNBLANK)
-			return regulator_enable(fbi->lcd_pwr);
-		else
-			return regulator_disable(fbi->lcd_pwr);
-	}
+	if (!IS_ERR(fbi->lcd_pwr))
+		return imxfb_regulator_set(fbi, power == FB_BLANK_UNBLANK);
 
 	return 0;
 }