Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp737442pxb; Tue, 14 Sep 2021 07:43:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLYtQqMyQiy6Ln19Mucf9cRCPkQ74/42U1mbX8JO1IMjBDfQiUARfebPM//J/Kp1aNJy/u X-Received: by 2002:a17:906:c7d0:: with SMTP id dc16mr18967845ejb.555.1631630592755; Tue, 14 Sep 2021 07:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631630592; cv=none; d=google.com; s=arc-20160816; b=qoCulcNeA9/mcgnu3hYxaO/JaHABUbEZyEhZPYKRY2EgBKLRJRga4euWGMrtr02hLj lpPG/OPSPrDRe2RXnaDUHwpCxL1KutIvpsbM/wD3YwDqjN49o9v+GI+diJJssg4FEN8i 7ImXH5CXZj8BDri8sLOo95nt3gjerVRNigUGx8nBmTKN3Q0L0DZNXLnp9S9pWOEaVA9x GSmkG9Df9pVIWv1tPWy9PXvk6RDCUAJGxdqv7tixUdMqLLbP0AfwJSaqTafHNg0HyQNu 4pmoO4NpyJhqpRXMi2sSNnpwnmXQR/lwGpG3zJLZ0M/LLKZ+7zWteHpq1wNPPxknlbuk C8kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LNh0785zTz9YvFR7R0jl/3nnyfVVmeb48E/+uVxWSck=; b=lQtaIam3N9qmIlEvwO0PGzj5DTX1lrXoG7qDjDXQmB8/ayN9TSVY/QeC7HZ9avar9I Fgy269aZhkXx5313KYHK5GWxLlKGYj3wOUf4cfxgyv2vZCHI5Yu+8ETIPikKCwQyZGYL 4qycSUntlPbCSbGmkMyX0iTvu/XkItZWl09jrTMbpwNaTqc2ENOmwiGIqCgJVQYXeMdj 7vPt4p8CHDo5tP9UkzMI1/gaR7F09ywLYKhb4zvEFJoISu1i0jcFC+mI6lRNXoY9w2ky mmXW0bMcYTZiZlxeExgTvTF3Txnjw/+nhKC5wbnVcbsk1ALa4EIbbCGZoybtHA4+tQxo yG/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v4si11248065ejv.670.2021.09.14.07.42.49; Tue, 14 Sep 2021 07:43:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234726AbhINOkn (ORCPT + 99 others); Tue, 14 Sep 2021 10:40:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234088AbhINOkL (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 E4E2CC0613A4 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Extract brightness handling into a helper function, so it can be called from multiple places. Signed-off-by: Geert Uytterhoeven --- 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) -- 2.25.1