public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups
@ 2026-04-04  7:55 Thomas Weißschuh
  2026-04-04  7:55 ` [PATCH 1/5] platform/chrome: cros_kbd_led_backlight: Drop max_brightness from driver data Thomas Weißschuh
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  7:55 UTC (permalink / raw)
  To: Benson Leung, Tzung-Bi Shih, Lee Jones, Guenter Roeck
  Cc: chrome-platform, linux-kernel, Thomas Weißschuh

Some cleanups for the cros_kbd_led_backlight driver.

Patches 1-3 should go through platform-chrome.
Patch 4 and 5 should go either through platform-chrome or MFD.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (5):
      platform/chrome: cros_kbd_led_backlight: Drop max_brightness from driver data
      platform/chrome: cros_kbd_led_backlight: Pass keyboard_led as parameter
      platform/chrome: cros_kbd_led_backlight: Drop CONFIG_MFD_CROS_EC_DEV ifdeffery
      mfd: cros_ec: Add a helper to retrieve the EC device from the MFD parent
      platform/chrome: cros_kbd_led_backlight: Use cros_ec_mfd_get_ec_dev()

 drivers/platform/chrome/cros_kbd_led_backlight.c | 31 +++++++-----------------
 include/linux/mfd/cros_ec.h                      | 16 ++++++++++++
 2 files changed, 25 insertions(+), 22 deletions(-)
---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260228-cros_kbd_led-cleanup-f0a13282b58d

Best regards,
--  
Thomas Weißschuh <linux@weissschuh.net>


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

* [PATCH 1/5] platform/chrome: cros_kbd_led_backlight: Drop max_brightness from driver data
  2026-04-04  7:55 [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups Thomas Weißschuh
@ 2026-04-04  7:55 ` Thomas Weißschuh
  2026-04-04  7:55 ` [PATCH 2/5] platform/chrome: cros_kbd_led_backlight: Pass keyboard_led as parameter Thomas Weißschuh
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  7:55 UTC (permalink / raw)
  To: Benson Leung, Tzung-Bi Shih, Lee Jones, Guenter Roeck
  Cc: chrome-platform, linux-kernel, Thomas Weißschuh

The maximum brightness is always 100. There is no need to read that from
the driver data.

Remove the superfluous driver data.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/platform/chrome/cros_kbd_led_backlight.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c
index f4c2282129f5..39e98e4b9ce6 100644
--- a/drivers/platform/chrome/cros_kbd_led_backlight.c
+++ b/drivers/platform/chrome/cros_kbd_led_backlight.c
@@ -32,7 +32,6 @@ struct keyboard_led {
  * @brightness_set_blocking:	Set LED brightness level.  It can block the
  *				caller for the time required for accessing a
  *				LED device register
- * @max_brightness:		Maximum brightness.
  *
  * See struct led_classdev in include/linux/leds.h for more details.
  */
@@ -45,12 +44,8 @@ struct keyboard_led_drvdata {
 			       enum led_brightness brightness);
 	int (*brightness_set_blocking)(struct led_classdev *led_cdev,
 				       enum led_brightness brightness);
-
-	enum led_brightness max_brightness;
 };
 
-#define KEYBOARD_BACKLIGHT_MAX 100
-
 #ifdef CONFIG_ACPI
 
 /* Keyboard LED ACPI Device must be defined in firmware */
@@ -116,7 +111,6 @@ static const struct keyboard_led_drvdata keyboard_led_drvdata_acpi = {
 	.init = keyboard_led_init_acpi,
 	.brightness_set = keyboard_led_set_brightness_acpi,
 	.brightness_get = keyboard_led_get_brightness_acpi,
-	.max_brightness = KEYBOARD_BACKLIGHT_MAX,
 };
 
 #endif /* CONFIG_ACPI */
@@ -175,7 +169,6 @@ static const struct keyboard_led_drvdata keyboard_led_drvdata_ec_pwm_mfd = {
 	.init = keyboard_led_init_ec_pwm_mfd,
 	.brightness_set_blocking = keyboard_led_set_brightness_ec_pwm,
 	.brightness_get = keyboard_led_get_brightness_ec_pwm,
-	.max_brightness = KEYBOARD_BACKLIGHT_MAX,
 };
 
 #else /* IS_ENABLED(CONFIG_MFD_CROS_EC_DEV) */
@@ -215,7 +208,7 @@ static int keyboard_led_probe(struct platform_device *pdev)
 
 	keyboard_led->cdev.name = "chromeos::kbd_backlight";
 	keyboard_led->cdev.flags |= LED_CORE_SUSPENDRESUME | LED_REJECT_NAME_CONFLICT;
-	keyboard_led->cdev.max_brightness = drvdata->max_brightness;
+	keyboard_led->cdev.max_brightness = 100;
 	keyboard_led->cdev.brightness_set = drvdata->brightness_set;
 	keyboard_led->cdev.brightness_set_blocking = drvdata->brightness_set_blocking;
 	keyboard_led->cdev.brightness_get = drvdata->brightness_get;

-- 
2.53.0


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

* [PATCH 2/5] platform/chrome: cros_kbd_led_backlight: Pass keyboard_led as parameter
  2026-04-04  7:55 [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups Thomas Weißschuh
  2026-04-04  7:55 ` [PATCH 1/5] platform/chrome: cros_kbd_led_backlight: Drop max_brightness from driver data Thomas Weißschuh
@ 2026-04-04  7:55 ` Thomas Weißschuh
  2026-04-04  7:55 ` [PATCH 3/5] platform/chrome: cros_kbd_led_backlight: Drop CONFIG_MFD_CROS_EC_DEV ifdeffery Thomas Weißschuh
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  7:55 UTC (permalink / raw)
  To: Benson Leung, Tzung-Bi Shih, Lee Jones, Guenter Roeck
  Cc: chrome-platform, linux-kernel, Thomas Weißschuh

Make the code simpler to read by passing the 'struct keyboard_led' as
a parameter to the 'init' callbacks instead of relying on the platform
device driver data.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/platform/chrome/cros_kbd_led_backlight.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c
index 39e98e4b9ce6..cca1ed0e00bd 100644
--- a/drivers/platform/chrome/cros_kbd_led_backlight.c
+++ b/drivers/platform/chrome/cros_kbd_led_backlight.c
@@ -36,7 +36,7 @@ struct keyboard_led {
  * See struct led_classdev in include/linux/leds.h for more details.
  */
 struct keyboard_led_drvdata {
-	int (*init)(struct platform_device *pdev);
+	int (*init)(struct platform_device *pdev, struct keyboard_led *keyboard_led);
 
 	enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
 
@@ -89,7 +89,8 @@ keyboard_led_get_brightness_acpi(struct led_classdev *cdev)
 	return brightness;
 }
 
-static int keyboard_led_init_acpi(struct platform_device *pdev)
+static int keyboard_led_init_acpi(struct platform_device *pdev,
+				  struct keyboard_led *keyboard_led)
 {
 	acpi_handle handle;
 	acpi_status status;
@@ -116,11 +117,11 @@ static const struct keyboard_led_drvdata keyboard_led_drvdata_acpi = {
 #endif /* CONFIG_ACPI */
 
 #if IS_ENABLED(CONFIG_MFD_CROS_EC_DEV)
-static int keyboard_led_init_ec_pwm_mfd(struct platform_device *pdev)
+static int keyboard_led_init_ec_pwm_mfd(struct platform_device *pdev,
+					struct keyboard_led *keyboard_led)
 {
 	struct cros_ec_dev *ec_dev = dev_get_drvdata(pdev->dev.parent);
 	struct cros_ec_device *cros_ec = ec_dev->ec_dev;
-	struct keyboard_led *keyboard_led = platform_get_drvdata(pdev);
 
 	keyboard_led->ec = cros_ec;
 
@@ -198,10 +199,9 @@ static int keyboard_led_probe(struct platform_device *pdev)
 	keyboard_led = devm_kzalloc(&pdev->dev, sizeof(*keyboard_led), GFP_KERNEL);
 	if (!keyboard_led)
 		return -ENOMEM;
-	platform_set_drvdata(pdev, keyboard_led);
 
 	if (drvdata->init) {
-		err = drvdata->init(pdev);
+		err = drvdata->init(pdev, keyboard_led);
 		if (err)
 			return err;
 	}

-- 
2.53.0


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

* [PATCH 3/5] platform/chrome: cros_kbd_led_backlight: Drop CONFIG_MFD_CROS_EC_DEV ifdeffery
  2026-04-04  7:55 [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups Thomas Weißschuh
  2026-04-04  7:55 ` [PATCH 1/5] platform/chrome: cros_kbd_led_backlight: Drop max_brightness from driver data Thomas Weißschuh
  2026-04-04  7:55 ` [PATCH 2/5] platform/chrome: cros_kbd_led_backlight: Pass keyboard_led as parameter Thomas Weißschuh
@ 2026-04-04  7:55 ` Thomas Weißschuh
  2026-04-04  7:55 ` [PATCH 4/5] mfd: cros_ec: Add a helper to retrieve the EC device from the MFD parent Thomas Weißschuh
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  7:55 UTC (permalink / raw)
  To: Benson Leung, Tzung-Bi Shih, Lee Jones, Guenter Roeck
  Cc: chrome-platform, linux-kernel, Thomas Weißschuh

The ifdeffery is unnecessary, as the compiler can already optimize away
all of the mfd-specific code based on the IS_ENABLED() in
keyboard_led_is_mfd_device().

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/platform/chrome/cros_kbd_led_backlight.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c
index cca1ed0e00bd..80dc52833dc9 100644
--- a/drivers/platform/chrome/cros_kbd_led_backlight.c
+++ b/drivers/platform/chrome/cros_kbd_led_backlight.c
@@ -116,7 +116,6 @@ static const struct keyboard_led_drvdata keyboard_led_drvdata_acpi = {
 
 #endif /* CONFIG_ACPI */
 
-#if IS_ENABLED(CONFIG_MFD_CROS_EC_DEV)
 static int keyboard_led_init_ec_pwm_mfd(struct platform_device *pdev,
 					struct keyboard_led *keyboard_led)
 {
@@ -172,12 +171,6 @@ static const struct keyboard_led_drvdata keyboard_led_drvdata_ec_pwm_mfd = {
 	.brightness_get = keyboard_led_get_brightness_ec_pwm,
 };
 
-#else /* IS_ENABLED(CONFIG_MFD_CROS_EC_DEV) */
-
-static const struct keyboard_led_drvdata keyboard_led_drvdata_ec_pwm_mfd = {};
-
-#endif /* IS_ENABLED(CONFIG_MFD_CROS_EC_DEV) */
-
 static int keyboard_led_is_mfd_device(struct platform_device *pdev)
 {
 	return IS_ENABLED(CONFIG_MFD_CROS_EC_DEV) && mfd_get_cell(pdev);

-- 
2.53.0


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

* [PATCH 4/5] mfd: cros_ec: Add a helper to retrieve the EC device from the MFD parent
  2026-04-04  7:55 [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups Thomas Weißschuh
                   ` (2 preceding siblings ...)
  2026-04-04  7:55 ` [PATCH 3/5] platform/chrome: cros_kbd_led_backlight: Drop CONFIG_MFD_CROS_EC_DEV ifdeffery Thomas Weißschuh
@ 2026-04-04  7:55 ` Thomas Weißschuh
  2026-04-04  7:55 ` [PATCH 5/5] platform/chrome: cros_kbd_led_backlight: Use cros_ec_mfd_get_ec_dev() Thomas Weißschuh
  2026-04-07  6:19 ` [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups Tzung-Bi Shih
  5 siblings, 0 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  7:55 UTC (permalink / raw)
  To: Benson Leung, Tzung-Bi Shih, Lee Jones, Guenter Roeck
  Cc: chrome-platform, linux-kernel, Thomas Weißschuh

The 'struct cros_ec_dev' needs to be retrieved from the MFD parent
device through a non-typesafe API. This logic is duplicated over all
CrOS EC drivers and it is not obvious what is going on.

Add a dedicated helper function which makes clear what is happening.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 include/linux/mfd/cros_ec.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
new file mode 100644
index 000000000000..ea5b007accfc
--- /dev/null
+++ b/include/linux/mfd/cros_ec.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __LINUX_MFD_CROS_EC_H
+#define __LINUX_MFD_CROS_EC_H
+
+#include <linux/compiler_attributes.h>
+
+struct cros_ec_dev;
+struct platform_device;
+
+static __always_inline struct cros_ec_dev *cros_ec_mfd_get_ec_dev(struct platform_device *pdev)
+{
+	return dev_get_drvdata(pdev->dev.parent);
+}
+
+#endif /* __LINUX_MFD_CROS_EC_H */

-- 
2.53.0


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

* [PATCH 5/5] platform/chrome: cros_kbd_led_backlight: Use cros_ec_mfd_get_ec_dev()
  2026-04-04  7:55 [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups Thomas Weißschuh
                   ` (3 preceding siblings ...)
  2026-04-04  7:55 ` [PATCH 4/5] mfd: cros_ec: Add a helper to retrieve the EC device from the MFD parent Thomas Weißschuh
@ 2026-04-04  7:55 ` Thomas Weißschuh
  2026-04-07  6:19 ` [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups Tzung-Bi Shih
  5 siblings, 0 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  7:55 UTC (permalink / raw)
  To: Benson Leung, Tzung-Bi Shih, Lee Jones, Guenter Roeck
  Cc: chrome-platform, linux-kernel, Thomas Weißschuh

Use the new standard helper to make the code a bit easier to read.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/platform/chrome/cros_kbd_led_backlight.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c
index 80dc52833dc9..f97dc4cf6bbb 100644
--- a/drivers/platform/chrome/cros_kbd_led_backlight.c
+++ b/drivers/platform/chrome/cros_kbd_led_backlight.c
@@ -10,6 +10,7 @@
 #include <linux/kernel.h>
 #include <linux/leds.h>
 #include <linux/mfd/core.h>
+#include <linux/mfd/cros_ec.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/of.h>
@@ -119,7 +120,7 @@ static const struct keyboard_led_drvdata keyboard_led_drvdata_acpi = {
 static int keyboard_led_init_ec_pwm_mfd(struct platform_device *pdev,
 					struct keyboard_led *keyboard_led)
 {
-	struct cros_ec_dev *ec_dev = dev_get_drvdata(pdev->dev.parent);
+	struct cros_ec_dev *ec_dev = cros_ec_mfd_get_ec_dev(pdev);
 	struct cros_ec_device *cros_ec = ec_dev->ec_dev;
 
 	keyboard_led->ec = cros_ec;

-- 
2.53.0


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

* Re: [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups
  2026-04-04  7:55 [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups Thomas Weißschuh
                   ` (4 preceding siblings ...)
  2026-04-04  7:55 ` [PATCH 5/5] platform/chrome: cros_kbd_led_backlight: Use cros_ec_mfd_get_ec_dev() Thomas Weißschuh
@ 2026-04-07  6:19 ` Tzung-Bi Shih
  5 siblings, 0 replies; 7+ messages in thread
From: Tzung-Bi Shih @ 2026-04-07  6:19 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Benson Leung, Lee Jones, Guenter Roeck, chrome-platform,
	linux-kernel

On Sat, Apr 04, 2026 at 09:55:25AM +0200, Thomas Weißschuh wrote:
> Some cleanups for the cros_kbd_led_backlight driver.
> 
> Patches 1-3 should go through platform-chrome.
> Patch 4 and 5 should go either through platform-chrome or MFD.

The series looks good to me.  I plan to apply at least patches 1-3 after
v7.1-rc1.

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

end of thread, other threads:[~2026-04-07  6:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-04  7:55 [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups Thomas Weißschuh
2026-04-04  7:55 ` [PATCH 1/5] platform/chrome: cros_kbd_led_backlight: Drop max_brightness from driver data Thomas Weißschuh
2026-04-04  7:55 ` [PATCH 2/5] platform/chrome: cros_kbd_led_backlight: Pass keyboard_led as parameter Thomas Weißschuh
2026-04-04  7:55 ` [PATCH 3/5] platform/chrome: cros_kbd_led_backlight: Drop CONFIG_MFD_CROS_EC_DEV ifdeffery Thomas Weißschuh
2026-04-04  7:55 ` [PATCH 4/5] mfd: cros_ec: Add a helper to retrieve the EC device from the MFD parent Thomas Weißschuh
2026-04-04  7:55 ` [PATCH 5/5] platform/chrome: cros_kbd_led_backlight: Use cros_ec_mfd_get_ec_dev() Thomas Weißschuh
2026-04-07  6:19 ` [PATCH 0/5] platform/chrome: cros_kbd_led_backlight: Some cleanups Tzung-Bi Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox