From patchwork Tue Jun 1 00:51:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 453171 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=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 8F6D0C47082 for ; Tue, 1 Jun 2021 00:52:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73FC66128A for ; Tue, 1 Jun 2021 00:52:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232625AbhFAAyC (ORCPT ); Mon, 31 May 2021 20:54:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:46182 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232559AbhFAAxz (ORCPT ); Mon, 31 May 2021 20:53:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3341D61364; Tue, 1 Jun 2021 00:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622508734; bh=thmtUafonYJfxBh+qZjVikVs+8hrEVyZs31+MWKROxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lEVzPQPdMkCfq71Ex4q1U6MrqdEchhLnNrNIneo8BxRTzNwqw4GQlNGUxwH4rsSzk EDWYLjbXLp18w94EHr7xGzF2qQjyUcFjgz99qJtLaYuuEt+bT6Od9EjCM+CkEFeVRi QAn9u09ri+/66y3Ayq/mHvVCCnFQVGbquNi8wUvi0tNOgsM8wEp4kfkZZ+uApO3Sm0 epOZg9yA5DspB8rsN5LTaJsXImwx7a9g1dYFHf+mhiSqwkI49/Ed/53fuBJbGgkM0A nSGkVOYkmVEFfFBrCGfOc9dRsNuvtlVvYj7cWn/KjzMMMnr1oHN1R8immtZ1sjLIcn 5jPDdCXDpgNKA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-leds@vger.kernel.org Cc: netdev@vger.kernel.org, Pavel Machek , Dan Murphy , Russell King , Andrew Lunn , Matthias Schiffer , Jacek Anaszewski , Mauro Carvalho Chehab , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH leds v2 07/10] leds: turris-omnia: refactor sw mode setting code into separate function Date: Tue, 1 Jun 2021 02:51:52 +0200 Message-Id: <20210601005155.27997-8-kabel@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210601005155.27997-1-kabel@kernel.org> References: <20210601005155.27997-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In order to make trigger offloading code more readable, put the code that sets/unsets software mode into a separate function. Signed-off-by: Marek BehĂșn --- drivers/leds/leds-turris-omnia.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 2f9a289ab245..c5a40afe5d45 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -73,6 +73,13 @@ static int omnia_led_brightness_set_blocking(struct led_classdev *cdev, return ret; } +static int omnia_led_set_sw_mode(struct i2c_client *client, int led, bool sw) +{ + return i2c_smbus_write_byte_data(client, CMD_LED_MODE, + CMD_LED_MODE_LED(led) | + (sw ? CMD_LED_MODE_USER : 0)); +} + static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, struct device_node *np) { @@ -114,9 +121,7 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, cdev->brightness_set_blocking = omnia_led_brightness_set_blocking; /* put the LED into software mode */ - ret = i2c_smbus_write_byte_data(client, CMD_LED_MODE, - CMD_LED_MODE_LED(led->reg) | - CMD_LED_MODE_USER); + ret = omnia_led_set_sw_mode(client, led->reg, true); if (ret < 0) { dev_err(dev, "Cannot set LED %pOF to software mode: %i\n", np, ret); @@ -250,8 +255,7 @@ static int omnia_leds_remove(struct i2c_client *client) u8 buf[5]; /* put all LEDs into default (HW triggered) mode */ - i2c_smbus_write_byte_data(client, CMD_LED_MODE, - CMD_LED_MODE_LED(OMNIA_BOARD_LEDS)); + omnia_led_set_sw_mode(client, OMNIA_BOARD_LEDS, false); /* set all LEDs color to [255, 255, 255] */ buf[0] = CMD_LED_COLOR;