From patchwork Mon Sep 2 12:40:58 2024 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: 13787225 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 57F7BCA0ED3 for ; Mon, 2 Sep 2024 12:41:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 40B80C4CEC8; Mon, 2 Sep 2024 12:41:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 745CAC4CEC7; Mon, 2 Sep 2024 12:41:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725280877; bh=RjZ+1WJB2EUKn7jyb3aFTmlnKkdDzgHeHg+x4CLEAoA=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=h6Na3fB8gir0Sr1UFgZLXXKY3UpWAMRo2KRiygo0jiVBEfqgVBfAgDI6xZ2JJLcw5 QavqIOHl0dxfy2AitRPtKPdhrnWun9DPI+kj+p6y73Z+zE78TtQVGxiPC4qb4gYoJJ rwQ9JSkO9G5efLtD6vLWexaKs7CxQhKQQ76IfpAyFC28bnCUZ2xNkGK+WjgXil0qfq LFC8k7VFSwU8fltocJUMHI1YZuhWpd2zIDuRv4kmLFfcLvBrHxSXSxpawospByhvkO YE/ipgMFmzmnKoevQQQxcmHccUi4orIYSCIvzxy3iXpwoeBSTNX7dmabw61F4R4U/U 3FBaEksxBxpcg== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lee Jones List-Id: Cc: Pavel Machek , linux-leds@vger.kernel.org, Arnd Bergmann , soc@kernel.org, Gregory CLEMENT , arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andrew Lunn , Sebastian Hesselbarth , =?utf-8?q?Marek_Be?= =?utf-8?q?h=C3=BAn?= Subject: [PATCH leds 2/8] leds: turris-omnia: Use command execution functions from the MCU driver Date: Mon, 2 Sep 2024 14:40:58 +0200 Message-ID: <20240902124104.14297-3-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240902124104.14297-1-kabel@kernel.org> References: <20240902124104.14297-1-kabel@kernel.org> MIME-Version: 1.0 Use the MCU command execution functions from the MCU driver instead of the ad-hoc implementation in the LED driver. This allows as to drop the LED driver implementation, which is a duplicate. Signed-off-by: Marek Behún --- drivers/leds/leds-turris-omnia.c | 88 ++++++++------------------------ 1 file changed, 22 insertions(+), 66 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 4cff8c4b020c..b9dd971a9e5f 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -2,7 +2,7 @@ /* * CZ.NIC's Turris Omnia LEDs driver * - * 2020, 2023 by Marek Behún + * 2020, 2023, 2024 by Marek Behún */ #include @@ -10,6 +10,7 @@ #include #include #include +#include #include "leds.h" #define OMNIA_BOARD_LEDS 12 @@ -57,52 +58,6 @@ struct omnia_leds { struct omnia_led leds[]; }; -static int omnia_cmd_write_u8(const struct i2c_client *client, u8 cmd, u8 val) -{ - u8 buf[2] = { cmd, val }; - int ret; - - ret = i2c_master_send(client, buf, sizeof(buf)); - - return ret < 0 ? ret : 0; -} - -static int omnia_cmd_read_raw(struct i2c_adapter *adapter, u8 addr, u8 cmd, - void *reply, size_t len) -{ - struct i2c_msg msgs[2]; - int ret; - - msgs[0].addr = addr; - msgs[0].flags = 0; - msgs[0].len = 1; - msgs[0].buf = &cmd; - msgs[1].addr = addr; - msgs[1].flags = I2C_M_RD; - msgs[1].len = len; - msgs[1].buf = reply; - - ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs)); - if (likely(ret == ARRAY_SIZE(msgs))) - return 0; - else if (ret < 0) - return ret; - else - return -EIO; -} - -static int omnia_cmd_read_u8(const struct i2c_client *client, u8 cmd) -{ - u8 reply; - int err; - - err = omnia_cmd_read_raw(client->adapter, client->addr, cmd, &reply, 1); - if (err) - return err; - - return reply; -} - static int omnia_led_send_color_cmd(const struct i2c_client *client, struct omnia_led *led) { @@ -352,14 +307,14 @@ static ssize_t brightness_show(struct device *dev, struct device_attribute *a, char *buf) { struct i2c_client *client = to_i2c_client(dev); - int ret; - - ret = omnia_cmd_read_u8(client, CMD_LED_GET_BRIGHTNESS); + u8 reply; + int err; - if (ret < 0) - return ret; + err = omnia_cmd_read_u8(client, CMD_LED_GET_BRIGHTNESS, &reply); + if (err < 0) + return err; - return sysfs_emit(buf, "%d\n", ret); + return sysfs_emit(buf, "%d\n", reply); } static ssize_t brightness_store(struct device *dev, struct device_attribute *a, @@ -386,17 +341,16 @@ static ssize_t gamma_correction_show(struct device *dev, { struct i2c_client *client = to_i2c_client(dev); struct omnia_leds *leds = i2c_get_clientdata(client); - int ret; + u8 reply = 0; + int err; if (leds->has_gamma_correction) { - ret = omnia_cmd_read_u8(client, CMD_GET_GAMMA_CORRECTION); - if (ret < 0) - return ret; - } else { - ret = 0; + err = omnia_cmd_read_u8(client, CMD_GET_GAMMA_CORRECTION, &reply); + if (err < 0) + return err; } - return sysfs_emit(buf, "%d\n", !!ret); + return sysfs_emit(buf, "%d\n", !!reply); } static ssize_t gamma_correction_store(struct device *dev, @@ -429,24 +383,26 @@ ATTRIBUTE_GROUPS(omnia_led_controller); static int omnia_mcu_get_features(const struct i2c_client *client) { + struct i2c_client mcu_client = *client; u16 reply; int err; - err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR, - CMD_GET_STATUS_WORD, &reply, sizeof(reply)); + /* We have to read features from different I2C address */ + mcu_client.addr = OMNIA_MCU_I2C_ADDR; + + err = omnia_cmd_read_u16(&mcu_client, CMD_GET_STATUS_WORD, &reply); if (err) return err; /* Check whether MCU firmware supports the CMD_GET_FEAUTRES command */ - if (!(le16_to_cpu(reply) & STS_FEATURES_SUPPORTED)) + if (!(reply & STS_FEATURES_SUPPORTED)) return 0; - err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR, - CMD_GET_FEATURES, &reply, sizeof(reply)); + err = omnia_cmd_read_u16(&mcu_client, CMD_GET_FEATURES, &reply); if (err) return err; - return le16_to_cpu(reply); + return reply; } static int omnia_leds_probe(struct i2c_client *client)