From patchwork Mon Sep 2 12:40:57 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: 13787224 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 55D24CA0ED3 for ; Mon, 2 Sep 2024 12:41:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 1B897C4CEC6; Mon, 2 Sep 2024 12:41:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B197C4CECB; Mon, 2 Sep 2024 12:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725280874; bh=LGlbCKVOmIJwH0zlTYzZgAvT4zf+IZH9aosAqMtBae8=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=OVJ6KQU+S9YVw5F8pqYvIKJZ0aBOK1pLY9kcH6CuyGDUXbd+zwKZZTepCMS550WsZ uNUBgf0uQ/bTMM83Fa0VK0rO+g2zAFJ+DvgBoO8ACab5gh/C/ce7wdbS+ShruYu+I4 IbHDaSJAj3HwZxPpF988/0BhBtjdWRa5nTtZKahr4/dAOZmhHkBqaFrnXj7asUELD5 G9fDOA0n0LV6UpyxYOOPZRAIG4+yo+vWiwQ5p3swRdLAjTHIT83DEP/xc4ZUv96J1W VF818x2dEh5DOR0G3RPFEFz/5nyEkVg7uxfcJVUlRQfRrVHE7TGI3IlN+ZT04AHL90 Qm8Ec6TAuEwNg== 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 1/8] turris-omnia-mcu-interface.h: Move command execution function to global header Date: Mon, 2 Sep 2024 14:40:57 +0200 Message-ID: <20240902124104.14297-2-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 Move the command execution functions from the turris-omnia-mcu platform driver private header to the global turris-omnia-mcu-interface.h header, so that they can be used by the LED driver. Signed-off-by: Marek Behún --- .../platform/cznic/turris-omnia-mcu-base.c | 1 + drivers/platform/cznic/turris-omnia-mcu.h | 130 ----------------- include/linux/turris-omnia-mcu-interface.h | 135 ++++++++++++++++++ 3 files changed, 136 insertions(+), 130 deletions(-) diff --git a/drivers/platform/cznic/turris-omnia-mcu-base.c b/drivers/platform/cznic/turris-omnia-mcu-base.c index 58f9afae2867..bb871226e357 100644 --- a/drivers/platform/cznic/turris-omnia-mcu-base.c +++ b/drivers/platform/cznic/turris-omnia-mcu-base.c @@ -52,6 +52,7 @@ int omnia_cmd_write_read(const struct i2c_client *client, return 0; } +EXPORT_SYMBOL_GPL(omnia_cmd_write_read); static int omnia_get_version_hash(struct omnia_mcu *mcu, bool bootloader, char version[static OMNIA_FW_VERSION_HEX_LEN]) diff --git a/drivers/platform/cznic/turris-omnia-mcu.h b/drivers/platform/cznic/turris-omnia-mcu.h index fed0d357fea3..b36f9626e660 100644 --- a/drivers/platform/cznic/turris-omnia-mcu.h +++ b/drivers/platform/cznic/turris-omnia-mcu.h @@ -8,7 +8,6 @@ #ifndef __TURRIS_OMNIA_MCU_H #define __TURRIS_OMNIA_MCU_H -#include #include #include #include @@ -17,8 +16,6 @@ #include #include #include -#include -#include struct i2c_client; struct rtc_device; @@ -63,133 +60,6 @@ struct omnia_mcu { #endif }; -int omnia_cmd_write_read(const struct i2c_client *client, - void *cmd, unsigned int cmd_len, - void *reply, unsigned int reply_len); - -static inline int omnia_cmd_write(const struct i2c_client *client, void *cmd, - unsigned int len) -{ - return omnia_cmd_write_read(client, cmd, len, NULL, 0); -} - -static inline int omnia_cmd_write_u8(const struct i2c_client *client, u8 cmd, - u8 val) -{ - u8 buf[2] = { cmd, val }; - - return omnia_cmd_write(client, buf, sizeof(buf)); -} - -static inline int omnia_cmd_write_u16(const struct i2c_client *client, u8 cmd, - u16 val) -{ - u8 buf[3]; - - buf[0] = cmd; - put_unaligned_le16(val, &buf[1]); - - return omnia_cmd_write(client, buf, sizeof(buf)); -} - -static inline int omnia_cmd_write_u32(const struct i2c_client *client, u8 cmd, - u32 val) -{ - u8 buf[5]; - - buf[0] = cmd; - put_unaligned_le32(val, &buf[1]); - - return omnia_cmd_write(client, buf, sizeof(buf)); -} - -static inline int omnia_cmd_read(const struct i2c_client *client, u8 cmd, - void *reply, unsigned int len) -{ - return omnia_cmd_write_read(client, &cmd, 1, reply, len); -} - -static inline unsigned int -omnia_compute_reply_length(unsigned long mask, bool interleaved, - unsigned int offset) -{ - if (!mask) - return 0; - - return ((__fls(mask) >> 3) << interleaved) + 1 + offset; -} - -/* Returns 0 on success */ -static inline int omnia_cmd_read_bits(const struct i2c_client *client, u8 cmd, - unsigned long bits, unsigned long *dst) -{ - __le32 reply; - int err; - - if (!bits) { - *dst = 0; - return 0; - } - - err = omnia_cmd_read(client, cmd, &reply, - omnia_compute_reply_length(bits, false, 0)); - if (err) - return err; - - *dst = le32_to_cpu(reply) & bits; - - return 0; -} - -static inline int omnia_cmd_read_bit(const struct i2c_client *client, u8 cmd, - unsigned long bit) -{ - unsigned long reply; - int err; - - err = omnia_cmd_read_bits(client, cmd, bit, &reply); - if (err) - return err; - - return !!reply; -} - -static inline int omnia_cmd_read_u32(const struct i2c_client *client, u8 cmd, - u32 *dst) -{ - __le32 reply; - int err; - - err = omnia_cmd_read(client, cmd, &reply, sizeof(reply)); - if (err) - return err; - - *dst = le32_to_cpu(reply); - - return 0; -} - -static inline int omnia_cmd_read_u16(const struct i2c_client *client, u8 cmd, - u16 *dst) -{ - __le16 reply; - int err; - - err = omnia_cmd_read(client, cmd, &reply, sizeof(reply)); - if (err) - return err; - - *dst = le16_to_cpu(reply); - - return 0; -} - -static inline int omnia_cmd_read_u8(const struct i2c_client *client, u8 cmd, - u8 *reply) -{ - return omnia_cmd_read(client, cmd, reply, sizeof(*reply)); -} - #ifdef CONFIG_TURRIS_OMNIA_MCU_GPIO extern const u8 omnia_int_to_gpio_idx[32]; extern const struct attribute_group omnia_mcu_gpio_group; diff --git a/include/linux/turris-omnia-mcu-interface.h b/include/linux/turris-omnia-mcu-interface.h index 2da8cbeb158a..eab67b81f310 100644 --- a/include/linux/turris-omnia-mcu-interface.h +++ b/include/linux/turris-omnia-mcu-interface.h @@ -9,7 +9,11 @@ #define __TURRIS_OMNIA_MCU_INTERFACE_H #include +#include #include +#include +#include +#include enum omnia_commands_e { OMNIA_CMD_GET_STATUS_WORD = 0x01, /* slave sends status word back */ @@ -246,4 +250,135 @@ enum omnia_cmd_usb_ovc_prot_e { OMNIA_CMD_xET_USB_OVC_PROT_ENABLE = BIT(4), }; +/* Command execution functions */ + +struct i2c_client; + +int omnia_cmd_write_read(const struct i2c_client *client, + void *cmd, unsigned int cmd_len, + void *reply, unsigned int reply_len); + +static inline int omnia_cmd_write(const struct i2c_client *client, void *cmd, + unsigned int len) +{ + return omnia_cmd_write_read(client, cmd, len, NULL, 0); +} + +static inline int omnia_cmd_write_u8(const struct i2c_client *client, u8 cmd, + u8 val) +{ + u8 buf[2] = { cmd, val }; + + return omnia_cmd_write(client, buf, sizeof(buf)); +} + +static inline int omnia_cmd_write_u16(const struct i2c_client *client, u8 cmd, + u16 val) +{ + u8 buf[3]; + + buf[0] = cmd; + put_unaligned_le16(val, &buf[1]); + + return omnia_cmd_write(client, buf, sizeof(buf)); +} + +static inline int omnia_cmd_write_u32(const struct i2c_client *client, u8 cmd, + u32 val) +{ + u8 buf[5]; + + buf[0] = cmd; + put_unaligned_le32(val, &buf[1]); + + return omnia_cmd_write(client, buf, sizeof(buf)); +} + +static inline int omnia_cmd_read(const struct i2c_client *client, u8 cmd, + void *reply, unsigned int len) +{ + return omnia_cmd_write_read(client, &cmd, 1, reply, len); +} + +static inline unsigned int +omnia_compute_reply_length(unsigned long mask, bool interleaved, + unsigned int offset) +{ + if (!mask) + return 0; + + return ((__fls(mask) >> 3) << interleaved) + 1 + offset; +} + +/* Returns 0 on success */ +static inline int omnia_cmd_read_bits(const struct i2c_client *client, u8 cmd, + unsigned long bits, unsigned long *dst) +{ + __le32 reply; + int err; + + if (!bits) { + *dst = 0; + return 0; + } + + err = omnia_cmd_read(client, cmd, &reply, + omnia_compute_reply_length(bits, false, 0)); + if (err) + return err; + + *dst = le32_to_cpu(reply) & bits; + + return 0; +} + +static inline int omnia_cmd_read_bit(const struct i2c_client *client, u8 cmd, + unsigned long bit) +{ + unsigned long reply; + int err; + + err = omnia_cmd_read_bits(client, cmd, bit, &reply); + if (err) + return err; + + return !!reply; +} + +static inline int omnia_cmd_read_u32(const struct i2c_client *client, u8 cmd, + u32 *dst) +{ + __le32 reply; + int err; + + err = omnia_cmd_read(client, cmd, &reply, sizeof(reply)); + if (err) + return err; + + *dst = le32_to_cpu(reply); + + return 0; +} + +static inline int omnia_cmd_read_u16(const struct i2c_client *client, u8 cmd, + u16 *dst) +{ + __le16 reply; + int err; + + err = omnia_cmd_read(client, cmd, &reply, sizeof(reply)); + if (err) + return err; + + *dst = le16_to_cpu(reply); + + return 0; +} + +static inline int omnia_cmd_read_u8(const struct i2c_client *client, u8 cmd, + u8 *reply) +{ + return omnia_cmd_read(client, cmd, reply, sizeof(*reply)); +} + #endif /* __TURRIS_OMNIA_MCU_INTERFACE_H */ 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) From patchwork Mon Sep 2 12:40:59 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: 13787226 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 7560DCD13CF for ; Mon, 2 Sep 2024 12:41:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 66BD7C4AF0D; Mon, 2 Sep 2024 12:41:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9989BC4CEC6; Mon, 2 Sep 2024 12:41:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725280880; bh=zvOuyojDJja+UDOztElDzMX9QR22CMLU+PdeXgp60gI=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=NnrTSWQWJEmeYEj9rX7vvXnaSy6BG1e5ifZxHI7r5v2wykWYAHpyKIOyZMwanu8Oz HqRcnPSgN8V+J5Ki47jfchoiOaoc5s00eIDz5a9Wn13cTBNaeDuntG+E7ruNcfJ8Tk jyp+mJAHRTBGcu9/SxC0hlSV+qj+Q2DOGYEDOqwIGqC7YPRfmL99/LKTLO94PFTf1k /QZsDxx57hf0bUZ4TgDmdBfZ4zkUhjLGe5t6kIzRZkh82NpHfFfxwFJ4EXWHCkIfMH 4TzoScqrXwJ21b/7i2jnSi5iosZtWnbn9FUOk69/xlTVMxMdYpV4FTiQna72PCVHDs teIYuOKh4bRcA== 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 3/8] turris-omnia-mcu-interface.h: Add LED commands related definitions to global header Date: Mon, 2 Sep 2024 14:40:59 +0200 Message-ID: <20240902124104.14297-4-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 Add definitions for contents of the OMNIA_CMD_LED_MODE and OMNIA_CMD_LED_STATE commands to the global turris-omnia-mcu-interface.h header. Signed-off-by: Marek Behún --- include/linux/turris-omnia-mcu-interface.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/turris-omnia-mcu-interface.h b/include/linux/turris-omnia-mcu-interface.h index eab67b81f310..bf5d04e53809 100644 --- a/include/linux/turris-omnia-mcu-interface.h +++ b/include/linux/turris-omnia-mcu-interface.h @@ -240,6 +240,18 @@ enum omnia_int_e { OMNIA_INT_LAN5_LED1 = BIT(31), }; +enum omnia_cmd_led_mode_e { + OMNIA_CMD_LED_MODE_LED_MASK = GENMASK(3, 0), +#define OMNIA_CMD_LED_MODE_LED(_l) FIELD_PREP(OMNIA_CMD_LED_MODE_LED_MASK, _l) + OMNIA_CMD_LED_MODE_USER = BIT(4), +}; + +enum omnia_cmd_led_state_e { + OMNIA_CMD_LED_STATE_LED_MASK = GENMASK(3, 0), +#define OMNIA_CMD_LED_STATE_LED(_l) FIELD_PREP(OMNIA_CMD_LED_STATE_LED_MASK, _l) + OMNIA_CMD_LED_STATE_ON = BIT(4), +}; + enum omnia_cmd_poweroff_e { OMNIA_CMD_POWER_OFF_POWERON_BUTTON = BIT(0), OMNIA_CMD_POWER_OFF_MAGIC = 0xdead, From patchwork Mon Sep 2 12:41:00 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: 13787227 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 98867CD13CF for ; Mon, 2 Sep 2024 12:41:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 8BAC3C4CEC6; Mon, 2 Sep 2024 12:41:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF634C4CEC8; Mon, 2 Sep 2024 12:41:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725280883; bh=7ATrjqRkBkWgvWCJYEN3yq7p5vBUVfgyg/PNRKEzajo=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=U5U9mA/GuH6b/NJC26b3Ay9jSvmcUHHr2N0msYc43yIYVTx4jOBcuqkat8hzYFIuX 6VKHFcUoeTNBZqUWbW9Wk3MAst7G1ub+uank/8UCvvZnY77Bd0nse9GZm/kC/OrZC9 L04vUY5ky+K3DtffO1v3nzRIqDogm39mZNjWNL3WrLPhn9Z4KrmnOXl7Nhrjcfq/3T x7TujzRuYxqIvF2cIWFkbEYHjkdeMR6jtTSrrxhBDIlWAKvwANzulp4INNIZBguCyB qROVGznAh9cEYmOXosmGXPUfTsXaXEnYiKUuhAYuMrK9ty7pruIFB/aOvabA6EF94F TFHDb5u5vhpFQ== 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 4/8] leds: turris-omnia: Use global header for MCU command definitions Date: Mon, 2 Sep 2024 14:41:00 +0200 Message-ID: <20240902124104.14297-5-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 The global turris-omnia-mcu-interface.h header file contains the definitions for MCU commands. Drop the driver-internal definitions and use the global ones. Signed-off-by: Marek Behún --- drivers/leds/leds-turris-omnia.c | 78 ++++++++++++-------------------- 1 file changed, 28 insertions(+), 50 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index b9dd971a9e5f..14e8fbb5bb69 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -16,30 +16,8 @@ #define OMNIA_BOARD_LEDS 12 #define OMNIA_LED_NUM_CHANNELS 3 -/* MCU controller commands at I2C address 0x2a */ -#define OMNIA_MCU_I2C_ADDR 0x2a - -#define CMD_GET_STATUS_WORD 0x01 -#define STS_FEATURES_SUPPORTED BIT(2) - -#define CMD_GET_FEATURES 0x10 -#define FEAT_LED_GAMMA_CORRECTION BIT(5) - -/* LED controller commands at I2C address 0x2b */ -#define CMD_LED_MODE 0x03 -#define CMD_LED_MODE_LED(l) ((l) & 0x0f) -#define CMD_LED_MODE_USER 0x10 - -#define CMD_LED_STATE 0x04 -#define CMD_LED_STATE_LED(l) ((l) & 0x0f) -#define CMD_LED_STATE_ON 0x10 - -#define CMD_LED_COLOR 0x05 -#define CMD_LED_SET_BRIGHTNESS 0x07 -#define CMD_LED_GET_BRIGHTNESS 0x08 - -#define CMD_SET_GAMMA_CORRECTION 0x30 -#define CMD_GET_GAMMA_CORRECTION 0x31 +/* MCU controller I2C address 0x2a, needed for detecting MCU features */ +#define OMNIA_MCU_I2C_ADDR 0x2a struct omnia_led { struct led_classdev_mc mc_cdev; @@ -64,7 +42,7 @@ static int omnia_led_send_color_cmd(const struct i2c_client *client, char cmd[5]; int ret; - cmd[0] = CMD_LED_COLOR; + cmd[0] = OMNIA_CMD_LED_COLOR; cmd[1] = led->reg; cmd[2] = led->subled_info[0].brightness; cmd[3] = led->subled_info[1].brightness; @@ -126,12 +104,12 @@ static int omnia_led_brightness_set_blocking(struct led_classdev *cdev, * is not being blinked by HW. */ if (!err && !led->hwtrig && !brightness != !led->on) { - u8 state = CMD_LED_STATE_LED(led->reg); + u8 state = OMNIA_CMD_LED_STATE_LED(led->reg); if (brightness) - state |= CMD_LED_STATE_ON; + state |= OMNIA_CMD_LED_STATE_ON; - err = omnia_cmd_write_u8(leds->client, CMD_LED_STATE, state); + err = omnia_cmd_write_u8(leds->client, OMNIA_CMD_LED_STATE, state); if (!err) led->on = !!brightness; } @@ -166,8 +144,8 @@ static int omnia_hwtrig_activate(struct led_classdev *cdev) if (!err) { /* Put the LED into MCU controlled mode */ - err = omnia_cmd_write_u8(leds->client, CMD_LED_MODE, - CMD_LED_MODE_LED(led->reg)); + err = omnia_cmd_write_u8(leds->client, OMNIA_CMD_LED_MODE, + OMNIA_CMD_LED_MODE_LED(led->reg)); if (!err) led->hwtrig = true; } @@ -188,9 +166,9 @@ static void omnia_hwtrig_deactivate(struct led_classdev *cdev) led->hwtrig = false; /* Put the LED into software mode */ - err = omnia_cmd_write_u8(leds->client, CMD_LED_MODE, - CMD_LED_MODE_LED(led->reg) | - CMD_LED_MODE_USER); + err = omnia_cmd_write_u8(leds->client, OMNIA_CMD_LED_MODE, + OMNIA_CMD_LED_MODE_LED(led->reg) | + OMNIA_CMD_LED_MODE_USER); mutex_unlock(&leds->lock); @@ -257,9 +235,9 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, cdev->default_trigger = omnia_hw_trigger.name; /* put the LED into software mode */ - ret = omnia_cmd_write_u8(client, CMD_LED_MODE, - CMD_LED_MODE_LED(led->reg) | - CMD_LED_MODE_USER); + ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, + OMNIA_CMD_LED_MODE_LED(led->reg) | + OMNIA_CMD_LED_MODE_USER); if (ret) { dev_err(dev, "Cannot set LED %pOF to software mode: %i\n", np, ret); @@ -267,8 +245,8 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, } /* disable the LED */ - ret = omnia_cmd_write_u8(client, CMD_LED_STATE, - CMD_LED_STATE_LED(led->reg)); + ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_STATE, + OMNIA_CMD_LED_STATE_LED(led->reg)); if (ret) { dev_err(dev, "Cannot set LED %pOF brightness: %i\n", np, ret); return ret; @@ -310,7 +288,7 @@ static ssize_t brightness_show(struct device *dev, struct device_attribute *a, u8 reply; int err; - err = omnia_cmd_read_u8(client, CMD_LED_GET_BRIGHTNESS, &reply); + err = omnia_cmd_read_u8(client, OMNIA_CMD_GET_BRIGHTNESS, &reply); if (err < 0) return err; @@ -330,7 +308,7 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *a, if (brightness > 100) return -EINVAL; - err = omnia_cmd_write_u8(client, CMD_LED_SET_BRIGHTNESS, brightness); + err = omnia_cmd_write_u8(client, OMNIA_CMD_SET_BRIGHTNESS, brightness); return err ?: count; } @@ -345,7 +323,7 @@ static ssize_t gamma_correction_show(struct device *dev, int err; if (leds->has_gamma_correction) { - err = omnia_cmd_read_u8(client, CMD_GET_GAMMA_CORRECTION, &reply); + err = omnia_cmd_read_u8(client, OMNIA_CMD_GET_GAMMA_CORRECTION, &reply); if (err < 0) return err; } @@ -368,7 +346,7 @@ static ssize_t gamma_correction_store(struct device *dev, if (kstrtobool(buf, &val) < 0) return -EINVAL; - err = omnia_cmd_write_u8(client, CMD_SET_GAMMA_CORRECTION, val); + err = omnia_cmd_write_u8(client, OMNIA_CMD_SET_GAMMA_CORRECTION, val); return err ?: count; } @@ -390,15 +368,15 @@ static int omnia_mcu_get_features(const struct i2c_client *client) /* 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); + err = omnia_cmd_read_u16(&mcu_client, OMNIA_CMD_GET_STATUS_WORD, &reply); if (err) return err; - /* Check whether MCU firmware supports the CMD_GET_FEAUTRES command */ - if (!(reply & STS_FEATURES_SUPPORTED)) + /* Check whether MCU firmware supports the OMNIA_CMD_GET_FEAUTRES command */ + if (!(reply & OMNIA_STS_FEATURES_SUPPORTED)) return 0; - err = omnia_cmd_read_u16(&mcu_client, CMD_GET_FEATURES, &reply); + err = omnia_cmd_read_u16(&mcu_client, OMNIA_CMD_GET_FEATURES, &reply); if (err) return err; @@ -436,7 +414,7 @@ static int omnia_leds_probe(struct i2c_client *client) return ret; } - leds->has_gamma_correction = ret & FEAT_LED_GAMMA_CORRECTION; + leds->has_gamma_correction = ret & OMNIA_FEAT_LED_GAMMA_CORRECTION; if (!leds->has_gamma_correction) { dev_info(dev, "Your board's MCU firmware does not support the LED gamma correction feature.\n"); @@ -469,11 +447,11 @@ static void omnia_leds_remove(struct i2c_client *client) u8 buf[5]; /* put all LEDs into default (HW triggered) mode */ - omnia_cmd_write_u8(client, CMD_LED_MODE, - CMD_LED_MODE_LED(OMNIA_BOARD_LEDS)); + omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, + OMNIA_CMD_LED_MODE_LED(OMNIA_BOARD_LEDS)); /* set all LEDs color to [255, 255, 255] */ - buf[0] = CMD_LED_COLOR; + buf[0] = OMNIA_CMD_LED_COLOR; buf[1] = OMNIA_BOARD_LEDS; buf[2] = 255; buf[3] = 255; From patchwork Mon Sep 2 12:41:01 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: 13787228 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 CA2B3CD13CF for ; Mon, 2 Sep 2024 12:41:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id B216BC4AF09; Mon, 2 Sep 2024 12:41:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4820C4CEC7; Mon, 2 Sep 2024 12:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725280886; bh=KxLoPvRTqutF1mR3o8geQ+QlfWUbc6g26YQYee6tbfw=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=f58GFhGP0J4vb0P5ZGq4rEaZLiPdhLCE95g9qjRUCWNf07PvPrc2jNhyxK8B5ZdOE w7kXOOM58GukcAx3vJ5VvzrY3ko28rvJzSwiG63QzhGXLh51mujRLQyPVuSGrNbUzz Vr2i0jsVyQF/TVTpQsT4YUGFiLN1eQ2RmFlK17ImXaCVOIm+60rrM/0Uo7qCwgrH0U tw+iCDwIxqZgfpKER2QA8hjtnNlxQ/ODSLfsLuFjUMmCprRb/3aL9hqTju0D4ZUspQ Ob6R/jXVrOYChu0gNQMtMdFGZXhALchbFsklobARRcvrO4m8nRtIhP0AWtY34cmqPC 1YY73H93h/19g== 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 5/8] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change Date: Mon, 2 Sep 2024 14:41:01 +0200 Message-ID: <20240902124104.14297-6-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 Recall that on Turris Omnia, the LED controller has a global brightness property, which allows the user to make the front LED panel dimmer. There is also a button on the front panel, which by default is configured so that pressing it changes the global brightness to a lower value (unless it is at 0%, in which case pressing the button changes the global brightness to 100%). Newer versions of the MCU firmware support informing the SOC that the brightness was changed by button press event via an interrupt. Now that we have the turris-omnia-mcu driver, which adds support for MCU interrupts, add the ability to inform the userspace (via a sysfs notification) that the global brightness was changed. Signed-off-by: Marek Behún --- drivers/leds/leds-turris-omnia.c | 67 ++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 14e8fbb5bb69..bf8635cec72e 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -357,7 +357,57 @@ static struct attribute *omnia_led_controller_attrs[] = { &dev_attr_gamma_correction.attr, NULL, }; -ATTRIBUTE_GROUPS(omnia_led_controller); + +static const struct attribute_group omnia_led_controller_group = { + .attrs = omnia_led_controller_attrs, +}; + +static irqreturn_t omnia_brightness_changed_handler(int irq, void *dev_id) +{ + struct kernfs_node *brightness_kn = dev_id; + + sysfs_notify_dirent(brightness_kn); + + return IRQ_HANDLED; +} + +static void brightness_kn_release(struct device *dev, void *res) +{ + struct kernfs_node **brightness_kn = res; + + sysfs_put(*brightness_kn); +} + +static int omnia_probe_brightness_interrupt(struct i2c_client *client) +{ + struct kernfs_node **brightness_kn; + struct device *dev = &client->dev; + int ret; + + brightness_kn = devres_alloc(brightness_kn_release, + sizeof(*brightness_kn), GFP_KERNEL); + if (!brightness_kn) + return -ENOMEM; + + *brightness_kn = sysfs_get_dirent(dev->kobj.sd, "brightness"); + if (!*brightness_kn) { + devres_free(brightness_kn); + return -EIO; + } + + devres_add(dev, brightness_kn); + + ret = devm_request_any_context_irq(dev, client->irq, + omnia_brightness_changed_handler, + IRQF_ONESHOT, "leds-turris-omnia", + *brightness_kn); + if (ret < 0) { + dev_err(dev, "Cannot request IRQ: %d\n", ret); + return ret; + } + + return 0; +} static int omnia_mcu_get_features(const struct i2c_client *client) { @@ -387,6 +437,7 @@ static int omnia_leds_probe(struct i2c_client *client) { struct device *dev = &client->dev; struct device_node *np = dev_of_node(dev); + bool has_brightness_interrupt; struct omnia_leds *leds; struct omnia_led *led; int ret, count; @@ -414,6 +465,8 @@ static int omnia_leds_probe(struct i2c_client *client) return ret; } + has_brightness_interrupt = ret & OMNIA_FEAT_BRIGHTNESS_INT; + leds->has_gamma_correction = ret & OMNIA_FEAT_LED_GAMMA_CORRECTION; if (!leds->has_gamma_correction) { dev_info(dev, @@ -439,7 +492,16 @@ static int omnia_leds_probe(struct i2c_client *client) led += ret; } - return 0; + ret = devm_device_add_group(dev, &omnia_led_controller_group); + if (ret < 0) { + dev_err(dev, "Cannot add sysfs attribute group: %d\n", ret); + return ret; + } + + if (has_brightness_interrupt) + ret = omnia_probe_brightness_interrupt(client); + + return ret; } static void omnia_leds_remove(struct i2c_client *client) @@ -479,7 +541,6 @@ static struct i2c_driver omnia_leds_driver = { .driver = { .name = "leds-turris-omnia", .of_match_table = of_omnia_leds_match, - .dev_groups = omnia_led_controller_groups, }, }; From patchwork Mon Sep 2 12:41:02 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: 13787229 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 039B8CD13CF for ; Mon, 2 Sep 2024 12:41:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id D7EF5C4AF0E; Mon, 2 Sep 2024 12:41:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16A1CC4CECB; Mon, 2 Sep 2024 12:41:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725280889; bh=FxPKGWWRKbnhjKzH3b2LpLpPDFpRJp5XiJc4PKVXMLI=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=QMYd37xbwdXjQmo5aXiTwUllE1/0slL2Q3a/d13ZYiGqG7ZwwUjOHZFnuPkFvepmK vYABZAGxVUcZzxqIvPd155wNqxvXj2dog/Kjzy2MwOsJtrvZYma+MxKkS5Si/KWedt 97vhc0IHo7CfKw6WFEQe1d8OX62yq+L1wk2vhNMjd3Ep7Hll4YMUmb01q0HbcG5vls iAftGjuwrYEzkMVgfZxtR0k2LQzQ+cTel4mOOxQidGRSb+D7RA83v3G9NrmGu+gAf/ Ht3qQcMRthwzYU7f1/5GXXbfY9KKDZJnrB4lxb5yXT6GKvtwPCnwDKfnVFC1hmF6Nr B+avQQnT8eR7Q== 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 6/8] platform: cznic: turris-omnia-mcu: Inform about missing LED panel brightness change interrupt feature Date: Mon, 2 Sep 2024 14:41:02 +0200 Message-ID: <20240902124104.14297-7-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 When reading MCU firmware features, check also for the LED panel brightness change interrupt feature, and suggest upgrading the firmware if it is missing. Signed-off-by: Marek Behún --- drivers/platform/cznic/turris-omnia-mcu-base.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/platform/cznic/turris-omnia-mcu-base.c b/drivers/platform/cznic/turris-omnia-mcu-base.c index bb871226e357..3bb4a3cfdb29 100644 --- a/drivers/platform/cznic/turris-omnia-mcu-base.c +++ b/drivers/platform/cznic/turris-omnia-mcu-base.c @@ -258,6 +258,7 @@ static int omnia_mcu_read_features(struct omnia_mcu *mcu) _DEF_FEAT(NEW_INT_API, "new interrupt API"), _DEF_FEAT(POWEROFF_WAKEUP, "poweroff and wakeup"), _DEF_FEAT(TRNG, "true random number generator"), + _DEF_FEAT(BRIGHTNESS_INT, "LED panel brightness change interrupt"), #undef _DEF_FEAT }; struct i2c_client *client = mcu->client; From patchwork Mon Sep 2 12:41:03 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: 13787230 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 1A56FCA0ED3 for ; Mon, 2 Sep 2024 12:41:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 08F73C4CEC6; Mon, 2 Sep 2024 12:41:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C584C4CEC7; Mon, 2 Sep 2024 12:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725280892; bh=uTYJGwS6gkq0hTSsIoEjD5EwGJH188e8KYtruqHsaHM=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=F0GzgIRB6w2CvYOraSJszSpQ8kE+I6hMtw30JwD2PvUJ36wED0G34QwhOCGd0dNgV yrHm4y0aL1EZmp6uV3uqWa9h3OwbIlqHQSrNr6ZL6EbFruSTqQ/M94zQnSWoy+3Tx0 uqI4quEGzSgJ8/WkBz3K0O/CxeWtadtu1dYfTP5uU2WfyP3Fm0pBq2dvkxa66Jk9Dc EELxhR7CF6swkftC25TybMBlDyhNAfnuZ7ppmI1Q6BuF3o+rvFzZV1DnjbsZR75syE 9u7HrDMeLaxXq/ZJHg4BdE4/mzTjbWIx3BrHiRS1wYV4iQGbQYrmZhONWQOR2T4c6M 6EF4GfF0L16Pw== 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 7/8] leds: turris-omnia: Inform about missing LED gamma correction feature in the MCU driver Date: Mon, 2 Sep 2024 14:41:03 +0200 Message-ID: <20240902124104.14297-8-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 If the LED gamma correction feature is missing in the MCU firmware, inform about this in the MCU firmware probe function instead of LED driver probe function, so that all the feature checks are in one place. Signed-off-by: Marek Behún --- drivers/leds/leds-turris-omnia.c | 9 +-------- drivers/platform/cznic/turris-omnia-mcu-base.c | 1 + 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index bf8635cec72e..7b5c1484924e 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -465,15 +465,8 @@ static int omnia_leds_probe(struct i2c_client *client) return ret; } - has_brightness_interrupt = ret & OMNIA_FEAT_BRIGHTNESS_INT; - leds->has_gamma_correction = ret & OMNIA_FEAT_LED_GAMMA_CORRECTION; - if (!leds->has_gamma_correction) { - dev_info(dev, - "Your board's MCU firmware does not support the LED gamma correction feature.\n"); - dev_info(dev, - "Consider upgrading MCU firmware with the omnia-mcutool utility.\n"); - } + has_brightness_interrupt = ret & OMNIA_FEAT_BRIGHTNESS_INT; mutex_init(&leds->lock); diff --git a/drivers/platform/cznic/turris-omnia-mcu-base.c b/drivers/platform/cznic/turris-omnia-mcu-base.c index 3bb4a3cfdb29..770e680b96f9 100644 --- a/drivers/platform/cznic/turris-omnia-mcu-base.c +++ b/drivers/platform/cznic/turris-omnia-mcu-base.c @@ -259,6 +259,7 @@ static int omnia_mcu_read_features(struct omnia_mcu *mcu) _DEF_FEAT(POWEROFF_WAKEUP, "poweroff and wakeup"), _DEF_FEAT(TRNG, "true random number generator"), _DEF_FEAT(BRIGHTNESS_INT, "LED panel brightness change interrupt"), + _DEF_FEAT(LED_GAMMA_CORRECTION, "LED gamma correction"), #undef _DEF_FEAT }; struct i2c_client *client = mcu->client; From patchwork Mon Sep 2 12:41:04 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: 13787231 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 3BC82CA0ED3 for ; Mon, 2 Sep 2024 12:41:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 2E912C4CEC6; Mon, 2 Sep 2024 12:41:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61B17C4CEC8; Mon, 2 Sep 2024 12:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725280896; bh=s3xJG6D/pwss0IUNp6uxa7NHr8odZ+slvD78tK31x2M=; h=From:To:List-Id:Cc:Subject:Date:In-Reply-To:References:From; b=ncGJVafgq3pAFr4frXFxnmwzS09xLKQfsQrJpDNwLKC1RPI+aD26idsLYqyaSYj0A D1wjMiXwiQ4jQFVkZDDIx5nJEpC0gtAlCFtWvbH10xV3Afu6Wh2bOjjJP7PKRIyCXG lef7Q2AHmKouj0UPFJLW0EEX403QvukTwpNd+AVyx7E7ysVpZ/kO2qRNGDQd5W+xeP YlUEsMIr+FxQ/XM7RsY9ClVAW2R7PYhMr5A+QWcSK8+iikFEahDrM36SQaEKHUIM5G FAOIzWWe+3Iu4vjKppxdk3DhPakl/dDp12+shp9K5ctNo9IAGVUREZD3g80Yj735FG lnAS1xFUIxLig== 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 8/8] ARM: dts: turris-omnia: Add global LED brightness change interrupt Date: Mon, 2 Sep 2024 14:41:04 +0200 Message-ID: <20240902124104.14297-9-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 When global LED brightness is changed by pressing the front button on Turris Omnia, the MCU can produce an interrupt to the CPU. Add the description of this interrupt to the LED controller node. Signed-off-by: Marek Behún --- arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts b/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts index 43202890c959..83fe00abd652 100644 --- a/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts +++ b/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts @@ -251,6 +251,7 @@ mcu: system-controller@2a { led-controller@2b { compatible = "cznic,turris-omnia-leds"; reg = <0x2b>; + interrupts-extended = <&mcu 11 IRQ_TYPE_NONE>; #address-cells = <1>; #size-cells = <0>; status = "okay";