Commit baa19b65 authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Lee Jones

platform/chrome: cros_kbd_led_backlight: allow binding through MFD

The ChromeOS EC used in Framework laptops supports the standard CrOS EC
keyboard backlight protocol.
However the firmware on these laptops doesn't implement the ACPI ID
GOOG0002 that is recognized by cros_kbd_led_backlight and they also
don't use device tree.

Prepare the existing cros_kbd_led_backlight driver to be probed through
the CrOS EC MFD device which works without ACPI or OF support.
Signed-off-by: default avatarThomas Weißschuh <linux@weissschuh.net>
Acked-by: default avatarTzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20240526-cros_ec-kbd-led-framework-v3-3-ee577415a521@weissschuh.netSigned-off-by: default avatarLee Jones <lee@kernel.org>
parent 6b0d3355
...@@ -150,7 +150,7 @@ config CROS_EC_PROTO ...@@ -150,7 +150,7 @@ config CROS_EC_PROTO
config CROS_KBD_LED_BACKLIGHT config CROS_KBD_LED_BACKLIGHT
tristate "Backlight LED support for Chrome OS keyboards" tristate "Backlight LED support for Chrome OS keyboards"
depends on LEDS_CLASS && (ACPI || CROS_EC) depends on LEDS_CLASS && (ACPI || CROS_EC || MFD_CROS_EC_DEV)
help help
This option enables support for the keyboard backlight LEDs on This option enables support for the keyboard backlight LEDs on
select Chrome OS systems. select Chrome OS systems.
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/leds.h> #include <linux/leds.h>
#include <linux/mfd/core.h>
#include <linux/mod_devicetable.h> #include <linux/mod_devicetable.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
...@@ -194,12 +195,45 @@ static const __maybe_unused struct keyboard_led_drvdata keyboard_led_drvdata_ec_ ...@@ -194,12 +195,45 @@ static const __maybe_unused struct keyboard_led_drvdata keyboard_led_drvdata_ec_
#endif /* IS_ENABLED(CONFIG_CROS_EC) */ #endif /* IS_ENABLED(CONFIG_CROS_EC) */
#if IS_ENABLED(CONFIG_MFD_CROS_EC_DEV)
static int keyboard_led_init_ec_pwm_mfd(struct platform_device *pdev)
{
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;
return 0;
}
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) */
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);
}
static int keyboard_led_probe(struct platform_device *pdev) static int keyboard_led_probe(struct platform_device *pdev)
{ {
const struct keyboard_led_drvdata *drvdata; const struct keyboard_led_drvdata *drvdata;
struct keyboard_led *keyboard_led; struct keyboard_led *keyboard_led;
int error; int error;
if (keyboard_led_is_mfd_device(pdev))
drvdata = &keyboard_led_drvdata_ec_pwm_mfd;
else
drvdata = device_get_match_data(&pdev->dev); drvdata = device_get_match_data(&pdev->dev);
if (!drvdata) if (!drvdata)
return -EINVAL; return -EINVAL;
...@@ -216,13 +250,15 @@ static int keyboard_led_probe(struct platform_device *pdev) ...@@ -216,13 +250,15 @@ static int keyboard_led_probe(struct platform_device *pdev)
} }
keyboard_led->cdev.name = "chromeos::kbd_backlight"; keyboard_led->cdev.name = "chromeos::kbd_backlight";
keyboard_led->cdev.flags |= LED_CORE_SUSPENDRESUME; keyboard_led->cdev.flags |= LED_CORE_SUSPENDRESUME | LED_REJECT_NAME_CONFLICT;
keyboard_led->cdev.max_brightness = drvdata->max_brightness; keyboard_led->cdev.max_brightness = drvdata->max_brightness;
keyboard_led->cdev.brightness_set = drvdata->brightness_set; keyboard_led->cdev.brightness_set = drvdata->brightness_set;
keyboard_led->cdev.brightness_set_blocking = drvdata->brightness_set_blocking; keyboard_led->cdev.brightness_set_blocking = drvdata->brightness_set_blocking;
keyboard_led->cdev.brightness_get = drvdata->brightness_get; keyboard_led->cdev.brightness_get = drvdata->brightness_get;
error = devm_led_classdev_register(&pdev->dev, &keyboard_led->cdev); error = devm_led_classdev_register(&pdev->dev, &keyboard_led->cdev);
if (error == -EEXIST) /* Already bound via other mechanism */
return -ENODEV;
if (error) if (error)
return error; return error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment