From patchwork Tue Sep 14 14:38:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 511285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFB67C43217 for ; Tue, 14 Sep 2021 14:39:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9CD1D6113B for ; Tue, 14 Sep 2021 14:39:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234173AbhINOkV (ORCPT ); Tue, 14 Sep 2021 10:40:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233748AbhINOkL (ORCPT ); Tue, 14 Sep 2021 10:40:11 -0400 Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E441BC0613A2 for ; Tue, 14 Sep 2021 07:38:44 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed20:d46f:7eb5:4a37:9d14]) by albert.telenet-ops.be with bizsmtp id tqeg2500b2aSKa106qegwG; Tue, 14 Sep 2021 16:38:43 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mQ9a4-004VHB-3E; Tue, 14 Sep 2021 16:38:40 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1mQ9a2-0028zh-Si; Tue, 14 Sep 2021 16:38:38 +0200 From: Geert Uytterhoeven To: Robin van der Gracht , Miguel Ojeda , Rob Herring , Paul Burton Cc: Greg Kroah-Hartman , Pavel Machek , Marek Behun , devicetree@vger.kernel.org, linux-leds@vger.kernel.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v6 15/19] auxdisplay: ht16k33: Extract ht16k33_brightness_set() Date: Tue, 14 Sep 2021 16:38:31 +0200 Message-Id: <20210914143835.511051-16-geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210914143835.511051-1-geert@linux-m68k.org> References: <20210914143835.511051-1-geert@linux-m68k.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Extract brightness handling into a helper function, so it can be called from multiple places. Signed-off-by: Geert Uytterhoeven Reviewed-by: Robin van der Gracht --- 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)