devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH leds v4 00/12] Turris Omnia LED driver changes
@ 2024-10-29 13:56 Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 01/12] turris-omnia-mcu-interface.h: Move command execution function to global header Marek Behún
                   ` (11 more replies)
  0 siblings, 12 replies; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

Hello Lee,

this is v4 of Turris Omnia LED driver changes.
v1, v2 and v3 can be found at
  https://lore.kernel.org/linux-leds/20240902124104.14297-1-kabel@kernel.org/
  https://lore.kernel.org/linux-leds/20240903101930.16251-1-kabel@kernel.org/
  https://lore.kernel.org/linux-leds/20240913123103.21226-1-kabel@kernel.org/

Changes since v3:
- fixed kernel test robot warning for patch 2 by adding dependency to
  the TURRIS_OMNIA_MCU module
- added Krzysztof's Acked-by to patch 5
- added patch documenting driver private `struct omnia_leds` and
  `struct omnia_led`
- addressed your notes for patch 7 (6 in v3)
- added `select TURRIS_OMNIA_MCU_GPIO` to KConfig. The driver already
  depends on TURRIS_OMNIA_MCU, but for the global brightness changed
  interrupt it needs the GPIO functionality from the turris-omnia-mcu
  driver

Marek

Marek Behún (12):
  turris-omnia-mcu-interface.h: Move command execution function to
    global header
  leds: turris-omnia: Use command execution functions from the MCU
    driver
  turris-omnia-mcu-interface.h: Add LED commands related definitions to
    global header
  leds: turris-omnia: Use global header for MCU command definitions
  dt-bindings: leds: cznic,turris-omnia-leds: Allow interrupts property
  leds: turris-omnia: Document driver private structures
  leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change
  platform: cznic: turris-omnia-mcu: Inform about missing LED panel
    brightness change interrupt feature
  leds: turris-omnia: Inform about missing LED gamma correction feature
    in the MCU driver
  leds: turris-omnia: Use dev_err_probe() where appropriate
  leds: turris-omnia: Use uppercase first letter in all comments
  ARM: dts: turris-omnia: Add global LED brightness change interrupt

 .../leds/cznic,turris-omnia-leds.yaml         |   8 +
 .../dts/marvell/armada-385-turris-omnia.dts   |   1 +
 drivers/leds/Kconfig                          |   2 +
 drivers/leds/leds-turris-omnia.c              | 291 ++++++++----------
 .../platform/cznic/turris-omnia-mcu-base.c    |   3 +
 drivers/platform/cznic/turris-omnia-mcu.h     | 130 --------
 include/linux/turris-omnia-mcu-interface.h    | 148 ++++++++-
 7 files changed, 288 insertions(+), 295 deletions(-)

-- 
2.45.2


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH leds v4 01/12] turris-omnia-mcu-interface.h: Move command execution function to global header
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 02/12] leds: turris-omnia: Use command execution functions from the MCU driver Marek Behún
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

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 <kabel@kernel.org>
---
 .../platform/cznic/turris-omnia-mcu-base.c    |   1 +
 drivers/platform/cznic/turris-omnia-mcu.h     | 130 -----------------
 include/linux/turris-omnia-mcu-interface.h    | 136 +++++++++++++++++-
 3 files changed, 136 insertions(+), 131 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 57ef5d350043..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 <linux/bitops.h>
 #include <linux/completion.h>
 #include <linux/gpio/driver.h>
 #include <linux/hw_random.h>
@@ -17,8 +16,6 @@
 #include <linux/types.h>
 #include <linux/watchdog.h>
 #include <linux/workqueue.h>
-#include <asm/byteorder.h>
-#include <linux/unaligned.h>
 
 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..7f24cc682780 100644
--- a/include/linux/turris-omnia-mcu-interface.h
+++ b/include/linux/turris-omnia-mcu-interface.h
@@ -9,7 +9,10 @@
 #define __TURRIS_OMNIA_MCU_INTERFACE_H
 
 #include <linux/bitfield.h>
-#include <linux/bits.h>
+#include <linux/bitops.h>
+#include <linux/types.h>
+#include <linux/unaligned.h>
+#include <asm/byteorder.h>
 
 enum omnia_commands_e {
 	OMNIA_CMD_GET_STATUS_WORD		= 0x01, /* slave sends status word back */
@@ -246,4 +249,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 */
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH leds v4 02/12] leds: turris-omnia: Use command execution functions from the MCU driver
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 01/12] turris-omnia-mcu-interface.h: Move command execution function to global header Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  2024-10-31  9:01   ` kernel test robot
  2024-10-29 13:56 ` [PATCH leds v4 03/12] turris-omnia-mcu-interface.h: Add LED commands related definitions to global header Marek Behún
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

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 <kabel@kernel.org>
---
 drivers/leds/Kconfig             |   1 +
 drivers/leds/leds-turris-omnia.c | 110 ++++++++-----------------------
 2 files changed, 30 insertions(+), 81 deletions(-)

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index b784bb74a837..fcbe93b61e49 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -217,6 +217,7 @@ config LEDS_TURRIS_OMNIA
 	depends on I2C
 	depends on MACH_ARMADA_38X || COMPILE_TEST
 	depends on OF
+	depends on TURRIS_OMNIA_MCU
 	select LEDS_TRIGGERS
 	help
 	  This option enables basic support for the LEDs found on the front
diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index 4cff8c4b020c..0b71848930dd 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 <kabel@kernel.org>
+ * 2020, 2023, 2024 by Marek Behún <kabel@kernel.org>
  */
 
 #include <linux/i2c.h>
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/of.h>
+#include <linux/turris-omnia-mcu-interface.h>
 #include "leds.h"
 
 #define OMNIA_BOARD_LEDS	12
@@ -57,66 +58,21 @@ struct omnia_leds {
 	struct omnia_led leds[];
 };
 
-static int omnia_cmd_write_u8(const struct i2c_client *client, u8 cmd, u8 val)
+static int omnia_cmd_set_color(const struct i2c_client *client, u8 led, u8 r, u8 g, u8 b)
 {
-	u8 buf[2] = { cmd, val };
-	int ret;
-
-	ret = i2c_master_send(client, buf, sizeof(buf));
+	u8 buf[5] = { CMD_LED_COLOR, led, r, g, b };
 
-	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;
+	return omnia_cmd_write(client, buf, sizeof(buf));
 }
 
 static int omnia_led_send_color_cmd(const struct i2c_client *client,
 				    struct omnia_led *led)
 {
-	char cmd[5];
 	int ret;
 
-	cmd[0] = CMD_LED_COLOR;
-	cmd[1] = led->reg;
-	cmd[2] = led->subled_info[0].brightness;
-	cmd[3] = led->subled_info[1].brightness;
-	cmd[4] = led->subled_info[2].brightness;
-
 	/* Send the color change command */
-	ret = i2c_master_send(client, cmd, 5);
+	ret = omnia_cmd_set_color(client, led->reg, led->subled_info[0].brightness,
+				  led->subled_info[1].brightness, led->subled_info[2].brightness);
 	if (ret < 0)
 		return ret;
 
@@ -352,14 +308,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 +342,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 +384,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)
@@ -510,20 +467,11 @@ static int omnia_leds_probe(struct i2c_client *client)
 
 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, CMD_LED_MODE, CMD_LED_MODE_LED(OMNIA_BOARD_LEDS));
 
 	/* set all LEDs color to [255, 255, 255] */
-	buf[0] = CMD_LED_COLOR;
-	buf[1] = OMNIA_BOARD_LEDS;
-	buf[2] = 255;
-	buf[3] = 255;
-	buf[4] = 255;
-
-	i2c_master_send(client, buf, 5);
+	omnia_cmd_set_color(client, OMNIA_BOARD_LEDS, 255, 255, 255);
 }
 
 static const struct of_device_id of_omnia_leds_match[] = {
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH leds v4 03/12] turris-omnia-mcu-interface.h: Add LED commands related definitions to global header
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 01/12] turris-omnia-mcu-interface.h: Move command execution function to global header Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 02/12] leds: turris-omnia: Use command execution functions from the MCU driver Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 04/12] leds: turris-omnia: Use global header for MCU command definitions Marek Behún
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

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 <kabel@kernel.org>
---
 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 7f24cc682780..06c94e032c6f 100644
--- a/include/linux/turris-omnia-mcu-interface.h
+++ b/include/linux/turris-omnia-mcu-interface.h
@@ -239,6 +239,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,
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH leds v4 04/12] leds: turris-omnia: Use global header for MCU command definitions
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
                   ` (2 preceding siblings ...)
  2024-10-29 13:56 ` [PATCH leds v4 03/12] turris-omnia-mcu-interface.h: Add LED commands related definitions to global header Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 05/12] dt-bindings: leds: cznic,turris-omnia-leds: Allow interrupts property Marek Behún
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

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 <kabel@kernel.org>
---
 drivers/leds/leds-turris-omnia.c | 71 +++++++++++---------------------
 1 file changed, 23 insertions(+), 48 deletions(-)

diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index 0b71848930dd..82cf58fbe946 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;
@@ -60,7 +38,7 @@ struct omnia_leds {
 
 static int omnia_cmd_set_color(const struct i2c_client *client, u8 led, u8 r, u8 g, u8 b)
 {
-	u8 buf[5] = { CMD_LED_COLOR, led, r, g, b };
+	u8 buf[5] = { OMNIA_CMD_LED_COLOR, led, r, g, b };
 
 	return omnia_cmd_write(client, buf, sizeof(buf));
 }
@@ -127,12 +105,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;
 	}
@@ -167,8 +145,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;
 	}
@@ -189,9 +167,8 @@ 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);
 
@@ -258,9 +235,8 @@ 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);
@@ -268,8 +244,7 @@ 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;
@@ -311,7 +286,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;
 
@@ -331,7 +306,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;
 }
@@ -346,7 +321,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;
 	}
@@ -369,7 +344,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;
 }
@@ -391,15 +366,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;
 
@@ -437,7 +412,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");
@@ -468,7 +443,7 @@ static int omnia_leds_probe(struct i2c_client *client)
 static void omnia_leds_remove(struct i2c_client *client)
 {
 	/* 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] */
 	omnia_cmd_set_color(client, OMNIA_BOARD_LEDS, 255, 255, 255);
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH leds v4 05/12] dt-bindings: leds: cznic,turris-omnia-leds: Allow interrupts property
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
                   ` (3 preceding siblings ...)
  2024-10-29 13:56 ` [PATCH leds v4 04/12] leds: turris-omnia: Use global header for MCU command definitions Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 06/12] leds: turris-omnia: Document driver private structures Marek Behún
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún,
	Krzysztof Kozlowski

Extend the cznic,turris-omnia-leds binding with interrupts property,
specifying the global LED brightness changed by button press interrupt.

Signed-off-by: Marek Behún <kabel@kernel.org>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 .../devicetree/bindings/leds/cznic,turris-omnia-leds.yaml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Documentation/devicetree/bindings/leds/cznic,turris-omnia-leds.yaml b/Documentation/devicetree/bindings/leds/cznic,turris-omnia-leds.yaml
index 34ef5215c150..f52f6304c79e 100644
--- a/Documentation/devicetree/bindings/leds/cznic,turris-omnia-leds.yaml
+++ b/Documentation/devicetree/bindings/leds/cznic,turris-omnia-leds.yaml
@@ -23,6 +23,12 @@ properties:
     description: I2C slave address of the microcontroller.
     maxItems: 1
 
+  interrupts:
+    description:
+      Specifier for the global LED brightness changed by front button press
+      interrupt.
+    maxItems: 1
+
   "#address-cells":
     const: 1
 
@@ -56,6 +62,7 @@ additionalProperties: false
 examples:
   - |
 
+    #include <dt-bindings/interrupt-controller/irq.h>
     #include <dt-bindings/leds/common.h>
 
     i2c {
@@ -65,6 +72,7 @@ examples:
         led-controller@2b {
             compatible = "cznic,turris-omnia-leds";
             reg = <0x2b>;
+            interrupts-extended = <&mcu 11 IRQ_TYPE_NONE>;
             #address-cells = <1>;
             #size-cells = <0>;
 
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH leds v4 06/12] leds: turris-omnia: Document driver private structures
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
                   ` (4 preceding siblings ...)
  2024-10-29 13:56 ` [PATCH leds v4 05/12] dt-bindings: leds: cznic,turris-omnia-leds: Allow interrupts property Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 07/12] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change Marek Behún
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

Add documentation for driver private structures, `struct omnia_leds` and
`struct omnia_led`.

Signed-off-by: Marek Behún <kabel@kernel.org>
---
 drivers/leds/leds-turris-omnia.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index 82cf58fbe946..b13b3b269ae9 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -19,6 +19,15 @@
 /* MCU controller I2C address 0x2a, needed for detecting MCU features */
 #define OMNIA_MCU_I2C_ADDR	0x2a
 
+/**
+ * struct omnia_led - per-LED part of driver private data structure
+ * @mc_cdev:		multi-color LED class device
+ * @subled_info:	per-channel information
+ * @cached_channels:	cached values of per-channel brightness that was sent to the MCU
+ * @on:			whether the LED was set on
+ * @hwtrig:		whether the LED blinking was offloaded to the MCU
+ * @reg:		LED identifier to the MCU
+ */
 struct omnia_led {
 	struct led_classdev_mc mc_cdev;
 	struct mc_subled subled_info[OMNIA_LED_NUM_CHANNELS];
@@ -29,6 +38,13 @@ struct omnia_led {
 
 #define to_omnia_led(l)		container_of(l, struct omnia_led, mc_cdev)
 
+/**
+ * struct omnia_leds - driver private data structure
+ * @client:			I2C client device
+ * @lock:			mutex to protect
+ * @has_gamma_correction:	whether the MCU firmware supports gamma correction
+ * @leds:			flexible array of per-LED data
+ */
 struct omnia_leds {
 	struct i2c_client *client;
 	struct mutex lock;
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH leds v4 07/12] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
                   ` (5 preceding siblings ...)
  2024-10-29 13:56 ` [PATCH leds v4 06/12] leds: turris-omnia: Document driver private structures Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  2024-10-30 20:34   ` kernel test robot
  2024-10-29 13:56 ` [PATCH leds v4 08/12] platform: cznic: turris-omnia-mcu: Inform about missing LED panel brightness change interrupt feature Marek Behún
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

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 <kabel@kernel.org>
---
 drivers/leds/Kconfig             |  1 +
 drivers/leds/leds-turris-omnia.c | 48 ++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index fcbe93b61e49..443aaf948bb8 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -219,6 +219,7 @@ config LEDS_TURRIS_OMNIA
 	depends on OF
 	depends on TURRIS_OMNIA_MCU
 	select LEDS_TRIGGERS
+	select TURRIS_OMNIA_MCU_GPIO
 	help
 	  This option enables basic support for the LEDs found on the front
 	  side of CZ.NIC's Turris Omnia router. There are 12 RGB LEDs on the
diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index b13b3b269ae9..ac7938f57bfe 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -43,12 +43,15 @@ struct omnia_led {
  * @client:			I2C client device
  * @lock:			mutex to protect
  * @has_gamma_correction:	whether the MCU firmware supports gamma correction
+ * @brightness_knode:		kernel node of the "brightness" device sysfs attribute (this is the
+ *				driver specific global brightness, not the LED classdev brightness)
  * @leds:			flexible array of per-LED data
  */
 struct omnia_leds {
 	struct i2c_client *client;
 	struct mutex lock;
 	bool has_gamma_correction;
+	struct kernfs_node *brightness_knode;
 	struct omnia_led leds[];
 };
 
@@ -373,6 +376,30 @@ static struct attribute *omnia_led_controller_attrs[] = {
 };
 ATTRIBUTE_GROUPS(omnia_led_controller);
 
+static irqreturn_t omnia_brightness_changed_threaded_fn(int irq, void *data)
+{
+	struct omnia_leds *leds = data;
+
+	if (unlikely(!leds->brightness_knode)) {
+		/*
+		 * It would be nicer to get this dirent in the driver probe method, before the IRQ
+		 * is requested. But the really_probe() function in drivers/base/dd.c registers
+		 * driver's .dev_groups only after probe is finished, so during driver probe the
+		 * "brightness" sysfs node is not yet present.
+		 *
+		 * Note that sysfs_get_dirent() may sleep. This is okay, because we are in threaded
+		 * context.
+		 */
+		leds->brightness_knode = sysfs_get_dirent(leds->client->dev.kobj.sd, "brightness");
+		if (!leds->brightness_knode)
+			return IRQ_NONE;
+	}
+
+	sysfs_notify_dirent(leds->brightness_knode);
+
+	return IRQ_HANDLED;
+}
+
 static int omnia_mcu_get_features(const struct i2c_client *client)
 {
 	struct i2c_client mcu_client = *client;
@@ -436,6 +463,14 @@ static int omnia_leds_probe(struct i2c_client *client)
 			 "Consider upgrading MCU firmware with the omnia-mcutool utility.\n");
 	}
 
+	if (ret & OMNIA_FEAT_BRIGHTNESS_INT) {
+		ret = devm_request_threaded_irq(dev, client->irq, NULL,
+						omnia_brightness_changed_threaded_fn, IRQF_ONESHOT,
+						"leds-turris-omnia", leds);
+		if (ret <= 0)
+			return dev_err_probe(dev, ret ?: -ENXIO, "Cannot request brightness IRQ\n");
+	}
+
 	mutex_init(&leds->lock);
 
 	ret = devm_led_trigger_register(dev, &omnia_hw_trigger);
@@ -458,6 +493,19 @@ static int omnia_leds_probe(struct i2c_client *client)
 
 static void omnia_leds_remove(struct i2c_client *client)
 {
+	struct omnia_leds *leds = i2c_get_clientdata(client);
+
+	/*
+	 * We need to free the brightness IRQ here, before putting away the brightness sysfs node.
+	 * Otherwise devres would free the interrupt only after the sysfs node is removed, and if
+	 * an interrupt occurred between those two events, it would use a removed sysfs node.
+	 */
+	devm_free_irq(&client->dev, client->irq, leds);
+
+	/* Now put away the sysfs node we got the first time the interrupt handler was called */
+	if (leds->brightness_knode)
+		sysfs_put(leds->brightness_knode);
+
 	/* put all LEDs into default (HW triggered) mode */
 	omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, OMNIA_CMD_LED_MODE_LED(OMNIA_BOARD_LEDS));
 
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH leds v4 08/12] platform: cznic: turris-omnia-mcu: Inform about missing LED panel brightness change interrupt feature
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
                   ` (6 preceding siblings ...)
  2024-10-29 13:56 ` [PATCH leds v4 07/12] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 09/12] leds: turris-omnia: Inform about missing LED gamma correction feature in the MCU driver Marek Behún
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

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 <kabel@kernel.org>
---
 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;
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH leds v4 09/12] leds: turris-omnia: Inform about missing LED gamma correction feature in the MCU driver
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
                   ` (7 preceding siblings ...)
  2024-10-29 13:56 ` [PATCH leds v4 08/12] platform: cznic: turris-omnia-mcu: Inform about missing LED panel brightness change interrupt feature Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 10/12] leds: turris-omnia: Use dev_err_probe() where appropriate Marek Behún
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

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 <kabel@kernel.org>
---
 drivers/leds/leds-turris-omnia.c               | 6 ------
 drivers/platform/cznic/turris-omnia-mcu-base.c | 1 +
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index ac7938f57bfe..0b0cf592557a 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -456,12 +456,6 @@ static int omnia_leds_probe(struct i2c_client *client)
 	}
 
 	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");
-	}
 
 	if (ret & OMNIA_FEAT_BRIGHTNESS_INT) {
 		ret = devm_request_threaded_irq(dev, client->irq, NULL,
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;
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH leds v4 10/12] leds: turris-omnia: Use dev_err_probe() where appropriate
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
                   ` (8 preceding siblings ...)
  2024-10-29 13:56 ` [PATCH leds v4 09/12] leds: turris-omnia: Inform about missing LED gamma correction feature in the MCU driver Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 11/12] leds: turris-omnia: Use uppercase first letter in all comments Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 12/12] ARM: dts: turris-omnia: Add global LED brightness change interrupt Marek Behún
  11 siblings, 0 replies; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

Use dev_err_probe() instead of dev_err() + separate return where
appropriate.

Signed-off-by: Marek Behún <kabel@kernel.org>
---
 drivers/leds/leds-turris-omnia.c | 50 ++++++++++----------------------
 1 file changed, 16 insertions(+), 34 deletions(-)

diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index 0b0cf592557a..515ba2991cf5 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -256,33 +256,23 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led,
 	/* put the LED into software mode */
 	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);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Cannot set LED %pOF to software mode\n", np);
 
 	/* disable the LED */
 	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;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Cannot set LED %pOF brightness\n", np);
 
 	/* Set initial color and cache it */
 	ret = omnia_led_send_color_cmd(client, led);
-	if (ret < 0) {
-		dev_err(dev, "Cannot set LED %pOF initial color: %i\n", np,
-			ret);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Cannot set LED %pOF initial color\n", np);
 
 	ret = devm_led_classdev_multicolor_register_ext(dev, &led->mc_cdev,
 							&init_data);
-	if (ret < 0) {
-		dev_err(dev, "Cannot register LED %pOF: %i\n", np, ret);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Cannot register LED %pOF\n", np);
 
 	return 1;
 }
@@ -433,13 +423,10 @@ static int omnia_leds_probe(struct i2c_client *client)
 	int ret, count;
 
 	count = of_get_available_child_count(np);
-	if (!count) {
-		dev_err(dev, "LEDs are not defined in device tree!\n");
-		return -ENODEV;
-	} else if (count > OMNIA_BOARD_LEDS) {
-		dev_err(dev, "Too many LEDs defined in device tree!\n");
-		return -EINVAL;
-	}
+	if (count == 0)
+		return dev_err_probe(dev, -ENODEV, "LEDs are not defined in device tree!\n");
+	if (count > OMNIA_BOARD_LEDS)
+		return dev_err_probe(dev, -EINVAL, "Too many LEDs defined in device tree!\n");
 
 	leds = devm_kzalloc(dev, struct_size(leds, leds, count), GFP_KERNEL);
 	if (!leds)
@@ -449,11 +436,8 @@ static int omnia_leds_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, leds);
 
 	ret = omnia_mcu_get_features(client);
-	if (ret < 0) {
-		dev_err(dev, "Cannot determine MCU supported features: %d\n",
-			ret);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Cannot determine MCU supported features\n");
 
 	leds->has_gamma_correction = ret & OMNIA_FEAT_LED_GAMMA_CORRECTION;
 
@@ -468,10 +452,8 @@ static int omnia_leds_probe(struct i2c_client *client)
 	mutex_init(&leds->lock);
 
 	ret = devm_led_trigger_register(dev, &omnia_hw_trigger);
-	if (ret < 0) {
-		dev_err(dev, "Cannot register private LED trigger: %d\n", ret);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Cannot register private LED trigger\n");
 
 	led = &leds->leds[0];
 	for_each_available_child_of_node_scoped(np, child) {
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH leds v4 11/12] leds: turris-omnia: Use uppercase first letter in all comments
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
                   ` (9 preceding siblings ...)
  2024-10-29 13:56 ` [PATCH leds v4 10/12] leds: turris-omnia: Use dev_err_probe() where appropriate Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  2024-10-29 13:56 ` [PATCH leds v4 12/12] ARM: dts: turris-omnia: Add global LED brightness change interrupt Marek Behún
  11 siblings, 0 replies; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

Change first letter of 4 more comments to uppercase to make the driver
comments uniform.

Signed-off-by: Marek Behún <kabel@kernel.org>
---
 drivers/leds/leds-turris-omnia.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index 515ba2991cf5..326958e099c9 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -253,13 +253,13 @@ 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 */
+	/* Put the LED into software mode */
 	ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, OMNIA_CMD_LED_MODE_LED(led->reg) |
 							     OMNIA_CMD_LED_MODE_USER);
 	if (ret)
 		return dev_err_probe(dev, ret, "Cannot set LED %pOF to software mode\n", np);
 
-	/* disable the LED */
+	/* Disable the LED */
 	ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_STATE, OMNIA_CMD_LED_STATE_LED(led->reg));
 	if (ret)
 		return dev_err_probe(dev, ret, "Cannot set LED %pOF brightness\n", np);
@@ -482,10 +482,10 @@ static void omnia_leds_remove(struct i2c_client *client)
 	if (leds->brightness_knode)
 		sysfs_put(leds->brightness_knode);
 
-	/* put all LEDs into default (HW triggered) mode */
+	/* Put all LEDs into default (HW triggered) mode */
 	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] */
+	/* Set all LEDs color to [255, 255, 255] */
 	omnia_cmd_set_color(client, OMNIA_BOARD_LEDS, 255, 255, 255);
 }
 
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH leds v4 12/12] ARM: dts: turris-omnia: Add global LED brightness change interrupt
  2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
                   ` (10 preceding siblings ...)
  2024-10-29 13:56 ` [PATCH leds v4 11/12] leds: turris-omnia: Use uppercase first letter in all comments Marek Behún
@ 2024-10-29 13:56 ` Marek Behún
  11 siblings, 0 replies; 17+ messages in thread
From: Marek Behún @ 2024-10-29 13:56 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, linux-leds, Arnd Bergmann, soc, Gregory CLEMENT,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree, Marek Behún

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 <kabel@kernel.org>
---
 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";
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH leds v4 07/12] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change
  2024-10-29 13:56 ` [PATCH leds v4 07/12] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change Marek Behún
@ 2024-10-30 20:34   ` kernel test robot
  0 siblings, 0 replies; 17+ messages in thread
From: kernel test robot @ 2024-10-30 20:34 UTC (permalink / raw)
  To: Marek Behún, Lee Jones
  Cc: Paul Gazzillo, Necip Fazil Yildiran, oe-kbuild-all, Pavel Machek,
	linux-leds, Arnd Bergmann, soc, Gregory CLEMENT, arm,
	Andy Shevchenko, Hans de Goede, Ilpo Järvinen, Andrew Lunn,
	Sebastian Hesselbarth, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, devicetree, Marek Behún

Hi Marek,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.12-rc5]
[cannot apply to lee-leds/for-leds-next robh/for-next next-20241030]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Marek-Beh-n/turris-omnia-mcu-interface-h-Move-command-execution-function-to-global-header/20241029-215858
base:   linus/master
patch link:    https://lore.kernel.org/r/20241029135621.12546-8-kabel%40kernel.org
patch subject: [PATCH leds v4 07/12] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change
config: x86_64-kismet-CONFIG_TURRIS_OMNIA_MCU_GPIO-CONFIG_LEDS_TURRIS_OMNIA-0-0 (https://download.01.org/0day-ci/archive/20241031/202410310400.K6KRpgOx-lkp@intel.com/config)
reproduce: (https://download.01.org/0day-ci/archive/20241031/202410310400.K6KRpgOx-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410310400.K6KRpgOx-lkp@intel.com/

kismet warnings: (new ones prefixed by >>)
>> kismet: WARNING: unmet direct dependencies detected for TURRIS_OMNIA_MCU_GPIO when selected by LEDS_TURRIS_OMNIA
   WARNING: unmet direct dependencies detected for TURRIS_OMNIA_MCU_GPIO
     Depends on [n]: CZNIC_PLATFORMS [=y] && TURRIS_OMNIA_MCU [=y] && GPIOLIB [=n] && OF [=y]
     Selected by [y]:
     - LEDS_TURRIS_OMNIA [=y] && NEW_LEDS [=y] && LEDS_CLASS_MULTICOLOR [=y] && I2C [=y] && (MACH_ARMADA_38X || COMPILE_TEST [=y]) && OF [=y] && TURRIS_OMNIA_MCU [=y]

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH leds v4 02/12] leds: turris-omnia: Use command execution functions from the MCU driver
  2024-10-29 13:56 ` [PATCH leds v4 02/12] leds: turris-omnia: Use command execution functions from the MCU driver Marek Behún
@ 2024-10-31  9:01   ` kernel test robot
  2024-11-01  9:06     ` Arnd Bergmann
  0 siblings, 1 reply; 17+ messages in thread
From: kernel test robot @ 2024-10-31  9:01 UTC (permalink / raw)
  To: Marek Behún, Lee Jones
  Cc: llvm, oe-kbuild-all, Pavel Machek, linux-leds, Arnd Bergmann, soc,
	Gregory CLEMENT, arm, Andy Shevchenko, Hans de Goede,
	Ilpo Järvinen, Andrew Lunn, Sebastian Hesselbarth,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
	Marek Behún

Hi Marek,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.12-rc5]
[cannot apply to lee-leds/for-leds-next robh/for-next next-20241030]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Marek-Beh-n/turris-omnia-mcu-interface-h-Move-command-execution-function-to-global-header/20241029-215858
base:   linus/master
patch link:    https://lore.kernel.org/r/20241029135621.12546-3-kabel%40kernel.org
patch subject: [PATCH leds v4 02/12] leds: turris-omnia: Use command execution functions from the MCU driver
config: riscv-allmodconfig (https://download.01.org/0day-ci/archive/20241031/202410311612.0OkxKVgC-lkp@intel.com/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 639a7ac648f1e50ccd2556e17d401c04f9cce625)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241031/202410311612.0OkxKVgC-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410311612.0OkxKVgC-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from drivers/leds/leds-turris-omnia.c:8:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:8:
   In file included from include/linux/interrupt.h:22:
   In file included from arch/riscv/include/asm/sections.h:9:
   In file included from include/linux/mm.h:2213:
   include/linux/vmstat.h:504:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     504 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     505 |                            item];
         |                            ~~~~
   include/linux/vmstat.h:511:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     511 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     512 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     518 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   include/linux/vmstat.h:524:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     524 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     525 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
>> drivers/leds/leds-turris-omnia.c:409:12: warning: stack frame size (2064) exceeds limit (2048) in 'omnia_leds_probe' [-Wframe-larger-than]
     409 | static int omnia_leds_probe(struct i2c_client *client)
         |            ^
   5 warnings generated.


vim +/omnia_leds_probe +409 drivers/leds/leds-turris-omnia.c

43e9082fbccc7d Marek Behún         2023-09-18  408  
4934630409cb60 Uwe Kleine-König    2022-11-18 @409  static int omnia_leds_probe(struct i2c_client *client)
089381b27abe28 Marek Behún         2020-07-23  410  {
089381b27abe28 Marek Behún         2020-07-23  411  	struct device *dev = &client->dev;
122d57e2960c81 Krzysztof Kozlowski 2024-08-16  412  	struct device_node *np = dev_of_node(dev);
089381b27abe28 Marek Behún         2020-07-23  413  	struct omnia_leds *leds;
089381b27abe28 Marek Behún         2020-07-23  414  	struct omnia_led *led;
089381b27abe28 Marek Behún         2020-07-23  415  	int ret, count;
089381b27abe28 Marek Behún         2020-07-23  416  
089381b27abe28 Marek Behún         2020-07-23  417  	count = of_get_available_child_count(np);
089381b27abe28 Marek Behún         2020-07-23  418  	if (!count) {
089381b27abe28 Marek Behún         2020-07-23  419  		dev_err(dev, "LEDs are not defined in device tree!\n");
089381b27abe28 Marek Behún         2020-07-23  420  		return -ENODEV;
089381b27abe28 Marek Behún         2020-07-23  421  	} else if (count > OMNIA_BOARD_LEDS) {
089381b27abe28 Marek Behún         2020-07-23  422  		dev_err(dev, "Too many LEDs defined in device tree!\n");
089381b27abe28 Marek Behún         2020-07-23  423  		return -EINVAL;
089381b27abe28 Marek Behún         2020-07-23  424  	}
089381b27abe28 Marek Behún         2020-07-23  425  
089381b27abe28 Marek Behún         2020-07-23  426  	leds = devm_kzalloc(dev, struct_size(leds, leds, count), GFP_KERNEL);
089381b27abe28 Marek Behún         2020-07-23  427  	if (!leds)
089381b27abe28 Marek Behún         2020-07-23  428  		return -ENOMEM;
089381b27abe28 Marek Behún         2020-07-23  429  
089381b27abe28 Marek Behún         2020-07-23  430  	leds->client = client;
089381b27abe28 Marek Behún         2020-07-23  431  	i2c_set_clientdata(client, leds);
089381b27abe28 Marek Behún         2020-07-23  432  
43e9082fbccc7d Marek Behún         2023-09-18  433  	ret = omnia_mcu_get_features(client);
43e9082fbccc7d Marek Behún         2023-09-18  434  	if (ret < 0) {
43e9082fbccc7d Marek Behún         2023-09-18  435  		dev_err(dev, "Cannot determine MCU supported features: %d\n",
43e9082fbccc7d Marek Behún         2023-09-18  436  			ret);
43e9082fbccc7d Marek Behún         2023-09-18  437  		return ret;
43e9082fbccc7d Marek Behún         2023-09-18  438  	}
43e9082fbccc7d Marek Behún         2023-09-18  439  
43e9082fbccc7d Marek Behún         2023-09-18  440  	leds->has_gamma_correction = ret & FEAT_LED_GAMMA_CORRECTION;
43e9082fbccc7d Marek Behún         2023-09-18  441  	if (!leds->has_gamma_correction) {
43e9082fbccc7d Marek Behún         2023-09-18  442  		dev_info(dev,
43e9082fbccc7d Marek Behún         2023-09-18  443  			 "Your board's MCU firmware does not support the LED gamma correction feature.\n");
43e9082fbccc7d Marek Behún         2023-09-18  444  		dev_info(dev,
43e9082fbccc7d Marek Behún         2023-09-18  445  			 "Consider upgrading MCU firmware with the omnia-mcutool utility.\n");
43e9082fbccc7d Marek Behún         2023-09-18  446  	}
43e9082fbccc7d Marek Behún         2023-09-18  447  
089381b27abe28 Marek Behún         2020-07-23  448  	mutex_init(&leds->lock);
089381b27abe28 Marek Behún         2020-07-23  449  
cbd6954fecbeb8 Marek Behún         2023-09-18  450  	ret = devm_led_trigger_register(dev, &omnia_hw_trigger);
cbd6954fecbeb8 Marek Behún         2023-09-18  451  	if (ret < 0) {
cbd6954fecbeb8 Marek Behún         2023-09-18  452  		dev_err(dev, "Cannot register private LED trigger: %d\n", ret);
cbd6954fecbeb8 Marek Behún         2023-09-18  453  		return ret;
cbd6954fecbeb8 Marek Behún         2023-09-18  454  	}
cbd6954fecbeb8 Marek Behún         2023-09-18  455  
089381b27abe28 Marek Behún         2020-07-23  456  	led = &leds->leds[0];
122d57e2960c81 Krzysztof Kozlowski 2024-08-16  457  	for_each_available_child_of_node_scoped(np, child) {
089381b27abe28 Marek Behún         2020-07-23  458  		ret = omnia_led_register(client, led, child);
122d57e2960c81 Krzysztof Kozlowski 2024-08-16  459  		if (ret < 0)
089381b27abe28 Marek Behún         2020-07-23  460  			return ret;
089381b27abe28 Marek Behún         2020-07-23  461  
089381b27abe28 Marek Behún         2020-07-23  462  		led += ret;
089381b27abe28 Marek Behún         2020-07-23  463  	}
089381b27abe28 Marek Behún         2020-07-23  464  
089381b27abe28 Marek Behún         2020-07-23  465  	return 0;
089381b27abe28 Marek Behún         2020-07-23  466  }
089381b27abe28 Marek Behún         2020-07-23  467  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH leds v4 02/12] leds: turris-omnia: Use command execution functions from the MCU driver
  2024-10-31  9:01   ` kernel test robot
@ 2024-11-01  9:06     ` Arnd Bergmann
  2024-11-01 11:06       ` Marek Behún
  0 siblings, 1 reply; 17+ messages in thread
From: Arnd Bergmann @ 2024-11-01  9:06 UTC (permalink / raw)
  To: kernel test robot, Marek Behún, Lee Jones
  Cc: llvm, oe-kbuild-all, Pavel Machek, linux-leds, soc,
	Gregory Clement, arm, Andy Shevchenko, Hans de Goede,
	Ilpo Järvinen, Andrew Lunn, Sebastian Hesselbarth,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree

On Thu, Oct 31, 2024, at 10:01, kernel test robot wrote:
>
> kernel test robot noticed the following build warnings:

>>> drivers/leds/leds-turris-omnia.c:409:12: warning: stack frame size (2064) exceeds limit (2048) in 'omnia_leds_probe' [-Wframe-larger-than]
>      409 | static int omnia_leds_probe(struct i2c_client *client)
>          |            ^

The problem here is the i2c_client on the stack, you can't
do that:

 static int omnia_mcu_get_features(const struct i2c_client *client)
 {
+	struct i2c_client mcu_client = *client;
 	u16 reply;

I haven't looked at this in detail, but there is usually a
trivial alternative.

     Arnd

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH leds v4 02/12] leds: turris-omnia: Use command execution functions from the MCU driver
  2024-11-01  9:06     ` Arnd Bergmann
@ 2024-11-01 11:06       ` Marek Behún
  0 siblings, 0 replies; 17+ messages in thread
From: Marek Behún @ 2024-11-01 11:06 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: kernel test robot, Marek Behún, Lee Jones, llvm,
	oe-kbuild-all, Pavel Machek, linux-leds, soc, Gregory Clement,
	arm, Andy Shevchenko, Hans de Goede, Ilpo Järvinen,
	Andrew Lunn, Sebastian Hesselbarth, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, devicetree

On Fri, Nov 01, 2024 at 10:06:40AM +0100, Arnd Bergmann wrote:
> On Thu, Oct 31, 2024, at 10:01, kernel test robot wrote:
> >
> > kernel test robot noticed the following build warnings:
> 
> >>> drivers/leds/leds-turris-omnia.c:409:12: warning: stack frame size (2064) exceeds limit (2048) in 'omnia_leds_probe' [-Wframe-larger-than]
> >      409 | static int omnia_leds_probe(struct i2c_client *client)
> >          |            ^
> 
> The problem here is the i2c_client on the stack, you can't
> do that:
> 
>  static int omnia_mcu_get_features(const struct i2c_client *client)
>  {
> +	struct i2c_client mcu_client = *client;
>  	u16 reply;

OMG, I see. struct i2c_client contains struct device.
OK, I will do this correctly by finding the MCU device on the I2C bus.

Marek

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-11-01 11:07 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-29 13:56 [PATCH leds v4 00/12] Turris Omnia LED driver changes Marek Behún
2024-10-29 13:56 ` [PATCH leds v4 01/12] turris-omnia-mcu-interface.h: Move command execution function to global header Marek Behún
2024-10-29 13:56 ` [PATCH leds v4 02/12] leds: turris-omnia: Use command execution functions from the MCU driver Marek Behún
2024-10-31  9:01   ` kernel test robot
2024-11-01  9:06     ` Arnd Bergmann
2024-11-01 11:06       ` Marek Behún
2024-10-29 13:56 ` [PATCH leds v4 03/12] turris-omnia-mcu-interface.h: Add LED commands related definitions to global header Marek Behún
2024-10-29 13:56 ` [PATCH leds v4 04/12] leds: turris-omnia: Use global header for MCU command definitions Marek Behún
2024-10-29 13:56 ` [PATCH leds v4 05/12] dt-bindings: leds: cznic,turris-omnia-leds: Allow interrupts property Marek Behún
2024-10-29 13:56 ` [PATCH leds v4 06/12] leds: turris-omnia: Document driver private structures Marek Behún
2024-10-29 13:56 ` [PATCH leds v4 07/12] leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change Marek Behún
2024-10-30 20:34   ` kernel test robot
2024-10-29 13:56 ` [PATCH leds v4 08/12] platform: cznic: turris-omnia-mcu: Inform about missing LED panel brightness change interrupt feature Marek Behún
2024-10-29 13:56 ` [PATCH leds v4 09/12] leds: turris-omnia: Inform about missing LED gamma correction feature in the MCU driver Marek Behún
2024-10-29 13:56 ` [PATCH leds v4 10/12] leds: turris-omnia: Use dev_err_probe() where appropriate Marek Behún
2024-10-29 13:56 ` [PATCH leds v4 11/12] leds: turris-omnia: Use uppercase first letter in all comments Marek Behún
2024-10-29 13:56 ` [PATCH leds v4 12/12] ARM: dts: turris-omnia: Add global LED brightness change interrupt Marek Behún

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).