Extend the cros_ec MFD device to also load cros_kbd_led_backlight
when the EC reports EC_FEATURE_PWM_KEYB.
As the driver can now be probed multiple times, some preparation in the
LED core is necessary to avoid name collisions.
Patch 1 is a general cleanup for the LED core.
Patch 2 modifies the LED core to skip the default collision handling.
Patch 3 adds the new probing logic to cros_kbd_led_backlight.
Patch 4 wires up the driver to the cros_ec mfd devices.
The helper keyboard_led_is_mfd_device is a bit iffy.
But using match data doesn't work.
* driver_data from platform_device_id is overwritten by the mfd platform data
* Setting the driver_data in drivers/mfd/cros_ec_dev.c would expose the
internals of cros_kbd_led_backlight
Tested on a Framework 13 AMD, Firmware 3.05, and a Jinlon Chromebook.
To: Lee Jones <[email protected]>
To: Benson Leung <[email protected]>
To: Guenter Roeck <[email protected]>
To: Tzung-Bi Shih <[email protected]>
To: Pavel Machek <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Dustin Howett <[email protected]>
Cc: Mario Limonciello <[email protected]>
Cc: [email protected]
Cc: Rajas Paranjpe <[email protected]>
Signed-off-by: Thomas Weißschuh <[email protected]>
Changes in v3:
- Avoid probing multiple times (Confirmed by Rajas)
- Add Kconfig dependency on MFD_CROS_EC_DEV
- Link to v2: https://lore.kernel.org/r/20240511-cros_ec-kbd-led-framework-v2-0-b20c48109e46@weissschuh.net
Changes in v2:
- Fix build with CONFIG_MFD_CROS_EC_DEV=n (kernel test robot)
- Split out mfd registration into own commit (Lee)
- Simplify keyboard_led_is_mfd_device() with mfd_get_cell()
- Link to v1: https://lore.kernel.org/r/20240505-cros_ec-kbd-led-framework-v1-1-bfcca69013d2@weissschuh.net
---
Thomas Weißschuh (4):
leds: class: warn about name collisions earlier
leds: add flag to avoid automatic renaming of led devices
platform/chrome: cros_kbd_led_backlight: allow binding through mfd device
mfd: cros_ec: Register keyboard backlight subdevice
drivers/leds/led-class.c | 9 +++---
drivers/mfd/cros_ec_dev.c | 9 ++++++
drivers/platform/chrome/Kconfig | 2 +-
drivers/platform/chrome/cros_kbd_led_backlight.c | 40 ++++++++++++++++++++++--
include/linux/leds.h | 1 +
5 files changed, 54 insertions(+), 7 deletions(-)
---
base-commit: 6fbf71854e2ddea7c99397772fbbb3783bfe15b5
change-id: 20240505-cros_ec-kbd-led-framework-7e2e831bc79c
Best regards,
--
Thomas Weißschuh <[email protected]>
Add a mechanism for drivers to opt-out of the automatic device renaming
on conflicts.
Those drivers will provide their own conflict resolution.
Signed-off-by: Thomas Weißschuh <[email protected]>
---
drivers/leds/led-class.c | 2 ++
include/linux/leds.h | 1 +
2 files changed, 3 insertions(+)
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index c298355d5b7d..2f08c20702f3 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -503,6 +503,8 @@ int led_classdev_register_ext(struct device *parent,
ret = led_classdev_next_name(proposed_name, final_name, sizeof(final_name));
if (ret < 0)
return ret;
+ else if (ret && led_cdev->flags & LED_REJECT_NAME_CONFLICT)
+ return -EEXIST;
else if (ret)
dev_warn(parent, "Led %s renamed to %s due to name collision\n",
proposed_name, final_name);
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 6300313c46b7..36663ac6c58a 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -107,6 +107,7 @@ struct led_classdev {
#define LED_BRIGHT_HW_CHANGED BIT(21)
#define LED_RETAIN_AT_SHUTDOWN BIT(22)
#define LED_INIT_DEFAULT_TRIGGER BIT(23)
+#define LED_REJECT_NAME_CONFLICT BIT(24)
/* set_brightness_work / blink_timer flags, atomic, private. */
unsigned long work_flags;
--
2.45.1
Load cros_kbd_led_backlight when the EC reports EC_FEATURE_PWM_KEYB.
This makes cros_kbd_led_backlight work on machines without specific
ACPI or OF support for the keyboard backlight.
Signed-off-by: Thomas Weißschuh <[email protected]>
---
drivers/mfd/cros_ec_dev.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
index a52d59cc2b1e..4444b361aeae 100644
--- a/drivers/mfd/cros_ec_dev.c
+++ b/drivers/mfd/cros_ec_dev.c
@@ -99,6 +99,10 @@ static const struct mfd_cell cros_ec_wdt_cells[] = {
{ .name = "cros-ec-wdt", }
};
+static const struct mfd_cell cros_ec_keyboard_leds_cells[] = {
+ { .name = "cros-keyboard-leds", },
+};
+
static const struct cros_feature_to_cells cros_subdevices[] = {
{
.id = EC_FEATURE_CEC,
@@ -125,6 +129,11 @@ static const struct cros_feature_to_cells cros_subdevices[] = {
.mfd_cells = cros_ec_wdt_cells,
.num_cells = ARRAY_SIZE(cros_ec_wdt_cells),
},
+ {
+ .id = EC_FEATURE_PWM_KEYB,
+ .mfd_cells = cros_ec_keyboard_leds_cells,
+ .num_cells = ARRAY_SIZE(cros_ec_keyboard_leds_cells),
+ },
};
static const struct mfd_cell cros_ec_platform_cells[] = {
--
2.45.1
On Sun, 26 May 2024, Thomas Weißschuh wrote:
> Extend the cros_ec MFD device to also load cros_kbd_led_backlight
> when the EC reports EC_FEATURE_PWM_KEYB.
> As the driver can now be probed multiple times, some preparation in the
> LED core is necessary to avoid name collisions.
>
> Patch 1 is a general cleanup for the LED core.
> Patch 2 modifies the LED core to skip the default collision handling.
> Patch 3 adds the new probing logic to cros_kbd_led_backlight.
> Patch 4 wires up the driver to the cros_ec mfd devices.
>
> The helper keyboard_led_is_mfd_device is a bit iffy.
> But using match data doesn't work.
>
> * driver_data from platform_device_id is overwritten by the mfd platform data
> * Setting the driver_data in drivers/mfd/cros_ec_dev.c would expose the
> internals of cros_kbd_led_backlight
>
> Tested on a Framework 13 AMD, Firmware 3.05, and a Jinlon Chromebook.
>
> To: Lee Jones <[email protected]>
> To: Benson Leung <[email protected]>
> To: Guenter Roeck <[email protected]>
> To: Tzung-Bi Shih <[email protected]>
> To: Pavel Machek <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: Dustin Howett <[email protected]>
> Cc: Mario Limonciello <[email protected]>
> Cc: [email protected]
> Cc: Rajas Paranjpe <[email protected]>
> Signed-off-by: Thomas Weißschuh <[email protected]>
>
> Changes in v3:
> - Avoid probing multiple times (Confirmed by Rajas)
> - Add Kconfig dependency on MFD_CROS_EC_DEV
> - Link to v2: https://lore.kernel.org/r/20240511-cros_ec-kbd-led-framework-v2-0-b20c48109e46@weissschuh.net
>
> Changes in v2:
> - Fix build with CONFIG_MFD_CROS_EC_DEV=n (kernel test robot)
> - Split out mfd registration into own commit (Lee)
> - Simplify keyboard_led_is_mfd_device() with mfd_get_cell()
> - Link to v1: https://lore.kernel.org/r/20240505-cros_ec-kbd-led-framework-v1-1-bfcca69013d2@weissschuh.net
>
> ---
> Thomas Weißschuh (4):
> leds: class: warn about name collisions earlier
> leds: add flag to avoid automatic renaming of led devices
> platform/chrome: cros_kbd_led_backlight: allow binding through mfd device
> mfd: cros_ec: Register keyboard backlight subdevice
>
> drivers/leds/led-class.c | 9 +++---
> drivers/mfd/cros_ec_dev.c | 9 ++++++
> drivers/platform/chrome/Kconfig | 2 +-
> drivers/platform/chrome/cros_kbd_led_backlight.c | 40 ++++++++++++++++++++++--
> include/linux/leds.h | 1 +
> 5 files changed, 54 insertions(+), 7 deletions(-)
Looks okay.
Does the platform patch need to be applied with the others?
--
Lee Jones [李琼斯]
On 2024-05-31 16:35:30+0000, Lee Jones wrote:
> On Sun, 26 May 2024, Thomas Weißschuh wrote:
>
> > Extend the cros_ec MFD device to also load cros_kbd_led_backlight
> > when the EC reports EC_FEATURE_PWM_KEYB.
> > As the driver can now be probed multiple times, some preparation in the
> > LED core is necessary to avoid name collisions.
> >
> > Patch 1 is a general cleanup for the LED core.
> > Patch 2 modifies the LED core to skip the default collision handling.
> > Patch 3 adds the new probing logic to cros_kbd_led_backlight.
> > Patch 4 wires up the driver to the cros_ec mfd devices.
> >
> > The helper keyboard_led_is_mfd_device is a bit iffy.
> > But using match data doesn't work.
> >
> > * driver_data from platform_device_id is overwritten by the mfd platform data
> > * Setting the driver_data in drivers/mfd/cros_ec_dev.c would expose the
> > internals of cros_kbd_led_backlight
> >
> > Tested on a Framework 13 AMD, Firmware 3.05, and a Jinlon Chromebook.
> >
> > To: Lee Jones <[email protected]>
> > To: Benson Leung <[email protected]>
> > To: Guenter Roeck <[email protected]>
> > To: Tzung-Bi Shih <[email protected]>
> > To: Pavel Machek <[email protected]>
> > Cc: [email protected]
> > Cc: [email protected]
> > Cc: Dustin Howett <[email protected]>
> > Cc: Mario Limonciello <[email protected]>
> > Cc: [email protected]
> > Cc: Rajas Paranjpe <[email protected]>
> > Signed-off-by: Thomas Weißschuh <[email protected]>
> >
> > Changes in v3:
> > - Avoid probing multiple times (Confirmed by Rajas)
> > - Add Kconfig dependency on MFD_CROS_EC_DEV
> > - Link to v2: https://lore.kernel.org/r/20240511-cros_ec-kbd-led-framework-v2-0-b20c48109e46@weissschuh.net
> >
> > Changes in v2:
> > - Fix build with CONFIG_MFD_CROS_EC_DEV=n (kernel test robot)
> > - Split out mfd registration into own commit (Lee)
> > - Simplify keyboard_led_is_mfd_device() with mfd_get_cell()
> > - Link to v1: https://lore.kernel.org/r/20240505-cros_ec-kbd-led-framework-v1-1-bfcca69013d2@weissschuh.net
> >
> > ---
> > Thomas Weißschuh (4):
> > leds: class: warn about name collisions earlier
> > leds: add flag to avoid automatic renaming of led devices
> > platform/chrome: cros_kbd_led_backlight: allow binding through mfd device
> > mfd: cros_ec: Register keyboard backlight subdevice
> >
> > drivers/leds/led-class.c | 9 +++---
> > drivers/mfd/cros_ec_dev.c | 9 ++++++
> > drivers/platform/chrome/Kconfig | 2 +-
> > drivers/platform/chrome/cros_kbd_led_backlight.c | 40 ++++++++++++++++++++++--
> > include/linux/leds.h | 1 +
> > 5 files changed, 54 insertions(+), 7 deletions(-)
>
> Looks okay.
Thanks.
> Does the platform patch need to be applied with the others?
Each patch depends on all its predecessors.
(but I'm not sure I understood your question)
On Fri, 31 May 2024, Thomas Weißschuh wrote:
> On 2024-05-31 16:35:30+0000, Lee Jones wrote:
> > On Sun, 26 May 2024, Thomas Weißschuh wrote:
> >
> > > Extend the cros_ec MFD device to also load cros_kbd_led_backlight
> > > when the EC reports EC_FEATURE_PWM_KEYB.
> > > As the driver can now be probed multiple times, some preparation in the
> > > LED core is necessary to avoid name collisions.
> > >
> > > Patch 1 is a general cleanup for the LED core.
> > > Patch 2 modifies the LED core to skip the default collision handling.
> > > Patch 3 adds the new probing logic to cros_kbd_led_backlight.
> > > Patch 4 wires up the driver to the cros_ec mfd devices.
> > >
> > > The helper keyboard_led_is_mfd_device is a bit iffy.
> > > But using match data doesn't work.
> > >
> > > * driver_data from platform_device_id is overwritten by the mfd platform data
> > > * Setting the driver_data in drivers/mfd/cros_ec_dev.c would expose the
> > > internals of cros_kbd_led_backlight
> > >
> > > Tested on a Framework 13 AMD, Firmware 3.05, and a Jinlon Chromebook.
> > >
> > > To: Lee Jones <[email protected]>
> > > To: Benson Leung <[email protected]>
> > > To: Guenter Roeck <[email protected]>
> > > To: Tzung-Bi Shih <[email protected]>
> > > To: Pavel Machek <[email protected]>
> > > Cc: [email protected]
> > > Cc: [email protected]
> > > Cc: Dustin Howett <[email protected]>
> > > Cc: Mario Limonciello <[email protected]>
> > > Cc: [email protected]
> > > Cc: Rajas Paranjpe <[email protected]>
> > > Signed-off-by: Thomas Weißschuh <[email protected]>
> > >
> > > Changes in v3:
> > > - Avoid probing multiple times (Confirmed by Rajas)
> > > - Add Kconfig dependency on MFD_CROS_EC_DEV
> > > - Link to v2: https://lore.kernel.org/r/20240511-cros_ec-kbd-led-framework-v2-0-b20c48109e46@weissschuh.net
> > >
> > > Changes in v2:
> > > - Fix build with CONFIG_MFD_CROS_EC_DEV=n (kernel test robot)
> > > - Split out mfd registration into own commit (Lee)
> > > - Simplify keyboard_led_is_mfd_device() with mfd_get_cell()
> > > - Link to v1: https://lore.kernel.org/r/20240505-cros_ec-kbd-led-framework-v1-1-bfcca69013d2@weissschuh.net
> > >
> > > ---
> > > Thomas Weißschuh (4):
> > > leds: class: warn about name collisions earlier
> > > leds: add flag to avoid automatic renaming of led devices
> > > platform/chrome: cros_kbd_led_backlight: allow binding through mfd device
> > > mfd: cros_ec: Register keyboard backlight subdevice
> > >
> > > drivers/leds/led-class.c | 9 +++---
> > > drivers/mfd/cros_ec_dev.c | 9 ++++++
> > > drivers/platform/chrome/Kconfig | 2 +-
> > > drivers/platform/chrome/cros_kbd_led_backlight.c | 40 ++++++++++++++++++++++--
> > > include/linux/leds.h | 1 +
> > > 5 files changed, 54 insertions(+), 7 deletions(-)
> >
> > Looks okay.
>
> Thanks.
>
> > Does the platform patch need to be applied with the others?
>
> Each patch depends on all its predecessors.
> (but I'm not sure I understood your question)
Does the Platform patch have 'build-time' deps on the others?
--
Lee Jones [李琼斯]
On 2024-05-31 16:53:56+0000, Lee Jones wrote:
> On Fri, 31 May 2024, Thomas Weißschuh wrote:
>
> > On 2024-05-31 16:35:30+0000, Lee Jones wrote:
> > > On Sun, 26 May 2024, Thomas Weißschuh wrote:
> > >
> > > > Extend the cros_ec MFD device to also load cros_kbd_led_backlight
> > > > when the EC reports EC_FEATURE_PWM_KEYB.
> > > > As the driver can now be probed multiple times, some preparation in the
> > > > LED core is necessary to avoid name collisions.
> > > >
> > > > Patch 1 is a general cleanup for the LED core.
> > > > Patch 2 modifies the LED core to skip the default collision handling.
> > > > Patch 3 adds the new probing logic to cros_kbd_led_backlight.
> > > > Patch 4 wires up the driver to the cros_ec mfd devices.
> > > >
> > > > The helper keyboard_led_is_mfd_device is a bit iffy.
> > > > But using match data doesn't work.
> > > >
> > > > * driver_data from platform_device_id is overwritten by the mfd platform data
> > > > * Setting the driver_data in drivers/mfd/cros_ec_dev.c would expose the
> > > > internals of cros_kbd_led_backlight
> > > >
> > > > Tested on a Framework 13 AMD, Firmware 3.05, and a Jinlon Chromebook.
> > > >
> > > > To: Lee Jones <[email protected]>
> > > > To: Benson Leung <[email protected]>
> > > > To: Guenter Roeck <[email protected]>
> > > > To: Tzung-Bi Shih <[email protected]>
> > > > To: Pavel Machek <[email protected]>
> > > > Cc: [email protected]
> > > > Cc: [email protected]
> > > > Cc: Dustin Howett <[email protected]>
> > > > Cc: Mario Limonciello <[email protected]>
> > > > Cc: [email protected]
> > > > Cc: Rajas Paranjpe <[email protected]>
> > > > Signed-off-by: Thomas Weißschuh <[email protected]>
> > > >
> > > > Changes in v3:
> > > > - Avoid probing multiple times (Confirmed by Rajas)
> > > > - Add Kconfig dependency on MFD_CROS_EC_DEV
> > > > - Link to v2: https://lore.kernel.org/r/20240511-cros_ec-kbd-led-framework-v2-0-b20c48109e46@weissschuh.net
> > > >
> > > > Changes in v2:
> > > > - Fix build with CONFIG_MFD_CROS_EC_DEV=n (kernel test robot)
> > > > - Split out mfd registration into own commit (Lee)
> > > > - Simplify keyboard_led_is_mfd_device() with mfd_get_cell()
> > > > - Link to v1: https://lore.kernel.org/r/20240505-cros_ec-kbd-led-framework-v1-1-bfcca69013d2@weissschuh.net
> > > >
> > > > ---
> > > > Thomas Weißschuh (4):
> > > > leds: class: warn about name collisions earlier
> > > > leds: add flag to avoid automatic renaming of led devices
> > > > platform/chrome: cros_kbd_led_backlight: allow binding through mfd device
> > > > mfd: cros_ec: Register keyboard backlight subdevice
> > > >
> > > > drivers/leds/led-class.c | 9 +++---
> > > > drivers/mfd/cros_ec_dev.c | 9 ++++++
> > > > drivers/platform/chrome/Kconfig | 2 +-
> > > > drivers/platform/chrome/cros_kbd_led_backlight.c | 40 ++++++++++++++++++++++--
> > > > include/linux/leds.h | 1 +
> > > > 5 files changed, 54 insertions(+), 7 deletions(-)
> > >
> > > Looks okay.
> >
> > Thanks.
> >
> > > Does the platform patch need to be applied with the others?
> >
> > Each patch depends on all its predecessors.
> > (but I'm not sure I understood your question)
>
> Does the Platform patch have 'build-time' deps on the others?
Yes.
Patch 3 makes use of LED_REJECT_NAME_CONFLICT which was introduced in Patch 2.
Patch 1, 2, 3 have build-time deps on their predecessors.
Patch 4 has a run-time deps on Patch 3.
On Fri, May 31, 2024 at 05:59:01PM +0200, Thomas Wei?schuh wrote:
> On 2024-05-31 16:53:56+0000, Lee Jones wrote:
> > On Fri, 31 May 2024, Thomas Wei?schuh wrote:
> >
> > > On 2024-05-31 16:35:30+0000, Lee Jones wrote:
> > > > On Sun, 26 May 2024, Thomas Wei?schuh wrote:
> > > >
> > > > > Extend the cros_ec MFD device to also load cros_kbd_led_backlight
> > > > > when the EC reports EC_FEATURE_PWM_KEYB.
> > > > > As the driver can now be probed multiple times, some preparation in the
> > > > > LED core is necessary to avoid name collisions.
> > > > >
> > > > > Patch 1 is a general cleanup for the LED core.
> > > > > Patch 2 modifies the LED core to skip the default collision handling.
> > > > > Patch 3 adds the new probing logic to cros_kbd_led_backlight.
> > > > > Patch 4 wires up the driver to the cros_ec mfd devices.
> > > > >
> > > > > The helper keyboard_led_is_mfd_device is a bit iffy.
> > > > > But using match data doesn't work.
> > > > >
> > > > > * driver_data from platform_device_id is overwritten by the mfd platform data
> > > > > * Setting the driver_data in drivers/mfd/cros_ec_dev.c would expose the
> > > > > internals of cros_kbd_led_backlight
> > > > >
> > > > > Tested on a Framework 13 AMD, Firmware 3.05, and a Jinlon Chromebook.
> > > > >
> > > > > To: Lee Jones <[email protected]>
> > > > > To: Benson Leung <[email protected]>
> > > > > To: Guenter Roeck <[email protected]>
> > > > > To: Tzung-Bi Shih <[email protected]>
> > > > > To: Pavel Machek <[email protected]>
> > > > > Cc: [email protected]
> > > > > Cc: [email protected]
> > > > > Cc: Dustin Howett <[email protected]>
> > > > > Cc: Mario Limonciello <[email protected]>
> > > > > Cc: [email protected]
> > > > > Cc: Rajas Paranjpe <[email protected]>
> > > > > Signed-off-by: Thomas Wei?schuh <[email protected]>
> > > > >
> > > > > Changes in v3:
> > > > > - Avoid probing multiple times (Confirmed by Rajas)
> > > > > - Add Kconfig dependency on MFD_CROS_EC_DEV
> > > > > - Link to v2: https://lore.kernel.org/r/20240511-cros_ec-kbd-led-framework-v2-0-b20c48109e46@weissschuh.net
> > > > >
> > > > > Changes in v2:
> > > > > - Fix build with CONFIG_MFD_CROS_EC_DEV=n (kernel test robot)
> > > > > - Split out mfd registration into own commit (Lee)
> > > > > - Simplify keyboard_led_is_mfd_device() with mfd_get_cell()
> > > > > - Link to v1: https://lore.kernel.org/r/20240505-cros_ec-kbd-led-framework-v1-1-bfcca69013d2@weissschuh.net
> > > > >
> > > > > ---
> > > > > Thomas Wei?schuh (4):
> > > > > leds: class: warn about name collisions earlier
> > > > > leds: add flag to avoid automatic renaming of led devices
> > > > > platform/chrome: cros_kbd_led_backlight: allow binding through mfd device
> > > > > mfd: cros_ec: Register keyboard backlight subdevice
> > > > >
> > > > > drivers/leds/led-class.c | 9 +++---
> > > > > drivers/mfd/cros_ec_dev.c | 9 ++++++
> > > > > drivers/platform/chrome/Kconfig | 2 +-
> > > > > drivers/platform/chrome/cros_kbd_led_backlight.c | 40 ++++++++++++++++++++++--
> > > > > include/linux/leds.h | 1 +
> > > > > 5 files changed, 54 insertions(+), 7 deletions(-)
> > > >
> > > > Looks okay.
> > >
> > > Thanks.
> > >
> > > > Does the platform patch need to be applied with the others?
> > >
> > > Each patch depends on all its predecessors.
> > > (but I'm not sure I understood your question)
> >
> > Does the Platform patch have 'build-time' deps on the others?
>
> Yes.
>
> Patch 3 makes use of LED_REJECT_NAME_CONFLICT which was introduced in Patch 2.
>
> Patch 1, 2, 3 have build-time deps on their predecessors.
> Patch 4 has a run-time deps on Patch 3.
Patch 1 is independent actually.