* [PATCH] leds: Add driver for Chrome OS keyboard LEDs
@ 2016-01-08 19:39 Simon Que
0 siblings, 0 replies; 3+ messages in thread
From: Simon Que @ 2016-01-08 19:39 UTC (permalink / raw)
To: Bryan Wu, Richard Purdie
Cc: linux-leds, Sameer Nanda, Todd Broch, Duncan Laurie, Simon Que
Some Chrome OS devices use ACPI-based keyboard backlight LEDs.
Signed-off-by: Simon Que <sque@chromium.org>
---
drivers/leds/Kconfig | 7 +++
drivers/leds/Makefile | 1 +
drivers/leds/leds-chromeos-keyboard.c | 115 ++++++++++++++++++++++++++++++++++
3 files changed, 123 insertions(+)
create mode 100644 drivers/leds/leds-chromeos-keyboard.c
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 72156c1..4b64e80 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -5,6 +5,13 @@ config LEDS_GPIO_REGISTER
As this function is used by arch code it must not be compiled as a
module.
+config LEDS_CHROMEOS_KEYBOARD
+ tristate "LED support for Chrome OS keyboards"
+ depends on LEDS_CLASS && ACPI
+ help
+ This option enables support for the LEDs on Chrome OS keyboards.
+ Say Y to enable keyboard LEDs on Chrome OS systems.
+
menuconfig NEW_LEDS
bool "LED Support"
help
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3cd76db..bf88b27 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -54,6 +54,7 @@ obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o
obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o
obj-$(CONFIG_LEDS_LM355x) += leds-lm355x.o
obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o
+obj-$(CONFIG_LEDS_CHROMEOS_KEYBOARD) += leds-chromeos-keyboard.o
# LED SPI Drivers
obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
diff --git a/drivers/leds/leds-chromeos-keyboard.c b/drivers/leds/leds-chromeos-keyboard.c
new file mode 100644
index 0000000..32d70c0
--- /dev/null
+++ b/drivers/leds/leds-chromeos-keyboard.c
@@ -0,0 +1,115 @@
+/*
+ * LED driver for Chrome OS keyboard backlight
+ *
+ * Copyright (C) 2012 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/acpi.h>
+#include <linux/leds.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+/* Keyboard LED ACPI Device must be defined in firmware */
+#define ACPI_KEYBOARD_BACKLIGHT_DEVICE "\\_SB.KBLT"
+#define ACPI_KEYBOARD_BACKLIGHT_READ ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBQC"
+#define ACPI_KEYBOARD_BACKLIGHT_WRITE ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBCM"
+
+#define ACPI_KEYBOARD_BACKLIGHT_MAX 100
+
+static void keyboard_led_set_brightness(struct led_classdev *cdev,
+ enum led_brightness brightness)
+{
+ union acpi_object param;
+ struct acpi_object_list input;
+ acpi_status status;
+
+ if (!(cdev->flags & LED_SUSPENDED))
+ cdev->brightness = brightness;
+
+ param.type = ACPI_TYPE_INTEGER;
+ param.integer.value = brightness;
+ input.count = 1;
+ input.pointer = ¶m;
+
+ status = acpi_evaluate_object(NULL, ACPI_KEYBOARD_BACKLIGHT_WRITE,
+ &input, NULL);
+ if (ACPI_FAILURE(status))
+ dev_err(cdev->dev, "Error setting keyboard LED value");
+}
+
+static int keyboard_led_probe(struct platform_device *pdev)
+{
+ struct led_classdev *cdev;
+ acpi_handle handle;
+ acpi_status status;
+ int ret;
+
+ /* Look for the keyboard LED ACPI Device */
+ status = acpi_get_handle(ACPI_ROOT_OBJECT,
+ ACPI_KEYBOARD_BACKLIGHT_DEVICE,
+ &handle);
+ if (ACPI_FAILURE(status)) {
+ dev_err(&pdev->dev, "Unable fo find ACPI device %s\n",
+ ACPI_KEYBOARD_BACKLIGHT_DEVICE);
+ return -ENODEV;
+ }
+
+ cdev = kzalloc(sizeof(struct led_classdev), GFP_KERNEL);
+ if (!cdev)
+ return -ENOMEM;
+ cdev->name = "chromeos::kbd_backlight";
+ cdev->brightness_set = keyboard_led_set_brightness;
+ cdev->max_brightness = ACPI_KEYBOARD_BACKLIGHT_MAX;
+ cdev->brightness = cdev->max_brightness;
+ cdev->flags |= LED_CORE_SUSPENDRESUME;
+
+ ret = led_classdev_register(&pdev->dev, cdev);
+ if (ret)
+ goto err;
+
+ platform_set_drvdata(pdev, cdev);
+ return 0;
+err:
+ kfree(cdev);
+ return ret;
+}
+
+static int keyboard_led_remove(struct platform_device *pdev)
+{
+ struct led_classdev *cdev = platform_get_drvdata(pdev);
+
+ platform_set_drvdata(pdev, NULL);
+ kfree(cdev);
+ return 0;
+}
+
+static struct platform_driver keyboard_led_driver = {
+ .driver = {
+ .name = "chromeos-keyboard-leds",
+ .owner = THIS_MODULE,
+ },
+ .probe = keyboard_led_probe,
+ .remove = keyboard_led_remove,
+};
+
+module_platform_driver(keyboard_led_driver);
+
+MODULE_AUTHOR("Simon Que <sque@chromium.org>");
+MODULE_DESCRIPTION("ChromeOS Keyboard LED Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:chromeos-keyboard-leds");
--
2.1.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] leds: Add driver for Chrome OS keyboard LEDs
@ 2016-01-08 19:49 Simon Que
2016-01-09 19:38 ` Evan McClain
0 siblings, 1 reply; 3+ messages in thread
From: Simon Que @ 2016-01-08 19:49 UTC (permalink / raw)
To: Bryan Wu, Richard Purdie
Cc: linux-leds, Sameer Nanda, Todd Broch, Duncan Laurie, Simon Que
Some Chrome OS devices use ACPI-based keyboard backlight LEDs.
Signed-off-by: Simon Que <sque@chromium.org>
---
drivers/leds/Kconfig | 7 +++
drivers/leds/Makefile | 1 +
drivers/leds/leds-chromeos-keyboard.c | 115 ++++++++++++++++++++++++++++++++++
3 files changed, 123 insertions(+)
create mode 100644 drivers/leds/leds-chromeos-keyboard.c
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 72156c1..4b64e80 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -5,6 +5,13 @@ config LEDS_GPIO_REGISTER
As this function is used by arch code it must not be compiled as a
module.
+config LEDS_CHROMEOS_KEYBOARD
+ tristate "LED support for Chrome OS keyboards"
+ depends on LEDS_CLASS && ACPI
+ help
+ This option enables support for the LEDs on Chrome OS keyboards.
+ Say Y to enable keyboard LEDs on Chrome OS systems.
+
menuconfig NEW_LEDS
bool "LED Support"
help
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3cd76db..bf88b27 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -54,6 +54,7 @@ obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o
obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o
obj-$(CONFIG_LEDS_LM355x) += leds-lm355x.o
obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o
+obj-$(CONFIG_LEDS_CHROMEOS_KEYBOARD) += leds-chromeos-keyboard.o
# LED SPI Drivers
obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
diff --git a/drivers/leds/leds-chromeos-keyboard.c b/drivers/leds/leds-chromeos-keyboard.c
new file mode 100644
index 0000000..32d70c0
--- /dev/null
+++ b/drivers/leds/leds-chromeos-keyboard.c
@@ -0,0 +1,115 @@
+/*
+ * LED driver for Chrome OS keyboard backlight
+ *
+ * Copyright (C) 2012 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/acpi.h>
+#include <linux/leds.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+/* Keyboard LED ACPI Device must be defined in firmware */
+#define ACPI_KEYBOARD_BACKLIGHT_DEVICE "\\_SB.KBLT"
+#define ACPI_KEYBOARD_BACKLIGHT_READ ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBQC"
+#define ACPI_KEYBOARD_BACKLIGHT_WRITE ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBCM"
+
+#define ACPI_KEYBOARD_BACKLIGHT_MAX 100
+
+static void keyboard_led_set_brightness(struct led_classdev *cdev,
+ enum led_brightness brightness)
+{
+ union acpi_object param;
+ struct acpi_object_list input;
+ acpi_status status;
+
+ if (!(cdev->flags & LED_SUSPENDED))
+ cdev->brightness = brightness;
+
+ param.type = ACPI_TYPE_INTEGER;
+ param.integer.value = brightness;
+ input.count = 1;
+ input.pointer = ¶m;
+
+ status = acpi_evaluate_object(NULL, ACPI_KEYBOARD_BACKLIGHT_WRITE,
+ &input, NULL);
+ if (ACPI_FAILURE(status))
+ dev_err(cdev->dev, "Error setting keyboard LED value");
+}
+
+static int keyboard_led_probe(struct platform_device *pdev)
+{
+ struct led_classdev *cdev;
+ acpi_handle handle;
+ acpi_status status;
+ int ret;
+
+ /* Look for the keyboard LED ACPI Device */
+ status = acpi_get_handle(ACPI_ROOT_OBJECT,
+ ACPI_KEYBOARD_BACKLIGHT_DEVICE,
+ &handle);
+ if (ACPI_FAILURE(status)) {
+ dev_err(&pdev->dev, "Unable fo find ACPI device %s\n",
+ ACPI_KEYBOARD_BACKLIGHT_DEVICE);
+ return -ENODEV;
+ }
+
+ cdev = kzalloc(sizeof(struct led_classdev), GFP_KERNEL);
+ if (!cdev)
+ return -ENOMEM;
+ cdev->name = "chromeos::kbd_backlight";
+ cdev->brightness_set = keyboard_led_set_brightness;
+ cdev->max_brightness = ACPI_KEYBOARD_BACKLIGHT_MAX;
+ cdev->brightness = cdev->max_brightness;
+ cdev->flags |= LED_CORE_SUSPENDRESUME;
+
+ ret = led_classdev_register(&pdev->dev, cdev);
+ if (ret)
+ goto err;
+
+ platform_set_drvdata(pdev, cdev);
+ return 0;
+err:
+ kfree(cdev);
+ return ret;
+}
+
+static int keyboard_led_remove(struct platform_device *pdev)
+{
+ struct led_classdev *cdev = platform_get_drvdata(pdev);
+
+ platform_set_drvdata(pdev, NULL);
+ kfree(cdev);
+ return 0;
+}
+
+static struct platform_driver keyboard_led_driver = {
+ .driver = {
+ .name = "chromeos-keyboard-leds",
+ .owner = THIS_MODULE,
+ },
+ .probe = keyboard_led_probe,
+ .remove = keyboard_led_remove,
+};
+
+module_platform_driver(keyboard_led_driver);
+
+MODULE_AUTHOR("Simon Que <sque@chromium.org>");
+MODULE_DESCRIPTION("ChromeOS Keyboard LED Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:chromeos-keyboard-leds");
--
2.1.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] leds: Add driver for Chrome OS keyboard LEDs
2016-01-08 19:49 [PATCH] leds: Add driver for Chrome OS keyboard LEDs Simon Que
@ 2016-01-09 19:38 ` Evan McClain
0 siblings, 0 replies; 3+ messages in thread
From: Evan McClain @ 2016-01-09 19:38 UTC (permalink / raw)
To: Simon Que, Bryan Wu, Richard Purdie
Cc: linux-leds, Sameer Nanda, Todd Broch, Duncan Laurie
[-- Attachment #1: Type: text/plain, Size: 1443 bytes --]
On Fri, 2016-01-08 at 11:49 -0800, Simon Que wrote:
> Some Chrome OS devices use ACPI-based keyboard backlight LEDs.
>
> Signed-off-by: Simon Que <sque@chromium.org>
> ---
> drivers/leds/Kconfig | 7 +++
> drivers/leds/Makefile | 1 +
> drivers/leds/leds-chromeos-keyboard.c | 115
> ++++++++++++++++++++++++++++++++++
> 3 files changed, 123 insertions(+)
> create mode 100644 drivers/leds/leds-chromeos-keyboard.c
>
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index 72156c1..4b64e80 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -5,6 +5,13 @@ config LEDS_GPIO_REGISTER
> As this function is used by arch code it must not be
> compiled as a
> module.
>
> +config LEDS_CHROMEOS_KEYBOARD
> + tristate "LED support for Chrome OS keyboards"
> + depends on LEDS_CLASS && ACPI
> + help
> + This option enables support for the LEDs on Chrome OS
> keyboards.
> + Say Y to enable keyboard LEDs on Chrome OS systems.
> +
> menuconfig NEW_LEDS
> bool "LED Support"
> help
This config option should be in the NEW_LEDS menu.
And it probably shouldn't get merged until:
https://chromium.googlesource.com/chromiumos/third_party/kernel/+/85142
c8507ec367b2283ad2398aa7fc6d8ec1765
is also submitted.
Thanks
--
Evan McClain
https://keybase.io/aeroevan
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-01-09 19:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-08 19:49 [PATCH] leds: Add driver for Chrome OS keyboard LEDs Simon Que
2016-01-09 19:38 ` Evan McClain
-- strict thread matches above, loose matches on Subject: below --
2016-01-08 19:39 Simon Que
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).