diff mbox series

[v6,15/19] auxdisplay: ht16k33: Extract ht16k33_brightness_set()

Message ID 20210914143835.511051-16-geert@linux-m68k.org (mailing list archive)
State Superseded
Headers show
Series auxdisplay: ht16k33: Add character display support | expand

Commit Message

Geert Uytterhoeven Sept. 14, 2021, 2:38 p.m. UTC
Extract brightness handling into a helper function, so it can be called
from multiple places.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
v6:
  - No changes,

v5:
  - No changes,

v4:
  - No changes,

v3:
  - Use "err" instead of "error" to be consistent with existing driver
    naming style,

v2:
  - No changes.
---
 drivers/auxdisplay/ht16k33.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

Comments

Robin van der Gracht Sept. 30, 2021, 6:58 a.m. UTC | #1
Reviewed-by: Robin van der Gracht <robin@protonic.nl>

On 2021-09-14 16:38, Geert Uytterhoeven wrote:
> Extract brightness handling into a helper function, so it can be called
> from multiple places.
> 
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> v6:
>   - No changes,
> 
> v5:
>   - No changes,
> 
> v4:
>   - No changes,
> 
> v3:
>   - Use "err" instead of "error" to be consistent with existing driver
>     naming style,
> 
> v2:
>   - No changes.
> ---
>  drivers/auxdisplay/ht16k33.c | 25 +++++++++++++++++++------
>  1 file changed, 19 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c
> index c7a3a0e1fbb5d03e..928ac9722c142855 100644
> --- a/drivers/auxdisplay/ht16k33.c
> +++ b/drivers/auxdisplay/ht16k33.c
> @@ -113,6 +113,22 @@ static int ht16k33_display_off(struct ht16k33_priv 
> *priv)
>  	return i2c_smbus_write_byte(priv->client, REG_DISPLAY_SETUP);
>  }
> 
> +static int ht16k33_brightness_set(struct ht16k33_priv *priv,
> +				  unsigned int brightness)
> +{
> +	int err;
> +
> +	if (brightness == 0)
> +		return ht16k33_display_off(priv);
> +
> +	err = ht16k33_display_on(priv);
> +	if (err)
> +		return err;
> +
> +	return i2c_smbus_write_byte(priv->client,
> +				    REG_BRIGHTNESS | (brightness - 1));
> +}
> +
>  static void ht16k33_fb_queue(struct ht16k33_priv *priv)
>  {
>  	struct ht16k33_fbdev *fbdev = &priv->fbdev;
> @@ -197,13 +213,10 @@ static int ht16k33_bl_update_status(struct 
> backlight_device *bl)
> 
>  	if (bl->props.power != FB_BLANK_UNBLANK ||
>  	    bl->props.fb_blank != FB_BLANK_UNBLANK ||
> -	    bl->props.state & BL_CORE_FBBLANK || brightness == 0) {
> -		return ht16k33_display_off(priv);
> -	}
> +	    bl->props.state & BL_CORE_FBBLANK)
> +		brightness = 0;
> 
> -	ht16k33_display_on(priv);
> -	return i2c_smbus_write_byte(priv->client,
> -				    REG_BRIGHTNESS | (brightness - 1));
> +	return ht16k33_brightness_set(priv, brightness);
>  }
> 
>  static int ht16k33_bl_check_fb(struct backlight_device *bl, struct fb_info 
> *fi)

Met vriendelijke groet,
Robin van der Gracht
diff mbox series

Patch

diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c
index c7a3a0e1fbb5d03e..928ac9722c142855 100644
--- a/drivers/auxdisplay/ht16k33.c
+++ b/drivers/auxdisplay/ht16k33.c
@@ -113,6 +113,22 @@  static int ht16k33_display_off(struct ht16k33_priv *priv)
 	return i2c_smbus_write_byte(priv->client, REG_DISPLAY_SETUP);
 }
 
+static int ht16k33_brightness_set(struct ht16k33_priv *priv,
+				  unsigned int brightness)
+{
+	int err;
+
+	if (brightness == 0)
+		return ht16k33_display_off(priv);
+
+	err = ht16k33_display_on(priv);
+	if (err)
+		return err;
+
+	return i2c_smbus_write_byte(priv->client,
+				    REG_BRIGHTNESS | (brightness - 1));
+}
+
 static void ht16k33_fb_queue(struct ht16k33_priv *priv)
 {
 	struct ht16k33_fbdev *fbdev = &priv->fbdev;
@@ -197,13 +213,10 @@  static int ht16k33_bl_update_status(struct backlight_device *bl)
 
 	if (bl->props.power != FB_BLANK_UNBLANK ||
 	    bl->props.fb_blank != FB_BLANK_UNBLANK ||
-	    bl->props.state & BL_CORE_FBBLANK || brightness == 0) {
-		return ht16k33_display_off(priv);
-	}
+	    bl->props.state & BL_CORE_FBBLANK)
+		brightness = 0;
 
-	ht16k33_display_on(priv);
-	return i2c_smbus_write_byte(priv->client,
-				    REG_BRIGHTNESS | (brightness - 1));
+	return ht16k33_brightness_set(priv, brightness);
 }
 
 static int ht16k33_bl_check_fb(struct backlight_device *bl, struct fb_info *fi)