leds: Add Chrome OS keyboard LEDs driver
PATCH 1/1 leds: Add Chrome OS keyboard LEDs driver
From: Simon Que <[email protected]>
Some Chrome OS devices use ACPI-based keyboard backlight LEDs.
Enable with menuconfig option under Device Drivers -> LED Support.
--- drivers/leds/Kconfig | 7 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-chromeos-keyboard.c | 118 ++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 drivers/leds/leds-chromeos-keyboard.c
drivers/leds/Kconfig +7 -0
@@ -607,6 +607,13 @@ config LEDS_VERSATILE This option enabled support for the LEDs on the ARM Versatile and RealView boards. Say Y to enabled these. +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. + comment "LED Triggers" source "drivers/leds/trigger/Kconfig"
drivers/leds/Makefile +1 -0
@@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o +obj-$(CONFIG_LEDS_CHROMEOS_KEYBOARD) += leds-chromeos-keyboard.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
drivers/leds/leds-chromeos-keyboard.c new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.5.0
Hi Evan,
There are still problems - the patch doesn't apply cleanly due to conflicts with drivers/leds/Kconfig and drivers/leds/Makefile. Please rebase the patch on top of LED git, for-next branch:
git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds.git
Best regards,
Jacek Anaszewski
Quoted 171 lines · Evan McClain
From: Simon Que <[email protected]>
Some Chrome OS devices use ACPI-based keyboard backlight LEDs.
Enable with menuconfig option under Device Drivers -> LED Support.
Signed-off-by Simon Que <[email protected]>Signed-off-by Duncan Laurie <[email protected]>Signed-off-by Evan McClain <[email protected]>--- drivers/leds/Kconfig | 7 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-chromeos-keyboard.c | 118 ++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+)create mode 100644
drivers/leds/leds-chromeos-keyboard.cdrivers/leds/Kconfig +7
-0@@ -607,6 +607,13 @@ config LEDS_VERSATILE This option enabled support for the LEDs on the ARM Versatile and RealView boards. Say Y to enabled these. +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. + comment "LED Triggers" source "drivers/leds/trigger/Kconfig"drivers/leds/Makefile +1
-0@@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o +obj-$(CONFIG_LEDS_CHROMEOS_KEYBOARD) += leds-chromeos-keyboard.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.odrivers/leds/leds-chromeos-keyboard.c new file +118
-0@@ -0,0 +1,118 @@ +/* +* 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 =devm_kzalloc (&pdev->dev,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 =devm_led_classdev_register (&pdev->dev, cdev); +if (ret) +return ret; + +platform_set_drvdata (pdev, cdev); +return 0 ; +} + +static int keyboard_led_remove (struct platform_device *pdev) +{ +struct led_classdev *cdev =platform_get_drvdata (pdev); + +platform_set_drvdata (pdev,NULL ); +return 0 ; +} + +static const struct acpi_device_id keyboard_led_id[] = { + {"GOOG0002" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (acpi, keyboard_led_id); + +static struct platform_driver keyboard_led_driver = { + .driver = { + .name ="chromeos-keyboard-leds" , + .owner =THIS_MODULE , + .acpi_match_table =ACPI_PTR (keyboard_led_id), + }, + .probe = keyboard_led_probe, + .remove = keyboard_led_remove, +}; + +module_platform_driver (keyboard_led_driver); + +MODULE_AUTHOR ("Simon Que <[email protected]>" ); +MODULE_DESCRIPTION ("ChromeOS Keyboard LED Driver" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:chromeos-keyboard-leds" );
Hi Evan, Simon
Please find few additional remarks below.
Quoted 67 lines · Evan McClain
From: Simon Que <[email protected]>
Some Chrome OS devices use ACPI-based keyboard backlight LEDs.
Enable with menuconfig option under Device Drivers -> LED Support.
Signed-off-by Simon Que <[email protected]>Signed-off-by Duncan Laurie <[email protected]>Signed-off-by Evan McClain <[email protected]>--- drivers/leds/Kconfig | 7 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-chromeos-keyboard.c | 118 ++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+)create mode 100644
drivers/leds/leds-chromeos-keyboard.cdrivers/leds/Kconfig +7
-0@@ -607,6 +607,13 @@ config LEDS_VERSATILE This option enabled support for the LEDs on the ARM Versatile and RealView boards. Say Y to enabled these. +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. + comment "LED Triggers" source "drivers/leds/trigger/Kconfig"drivers/leds/Makefile +1
-0@@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o +obj-$(CONFIG_LEDS_CHROMEOS_KEYBOARD) += leds-chromeos-keyboard.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.odrivers/leds/leds-chromeos-keyboard.c new file +15
-0@@ -0,0 +1,118 @@ +/* +* 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. +*/
drivers/leds/leds-chromeos-keyboard.c line 25
Quoted 10 lines
drivers/leds/leds-chromeos-keyboard.c new file +10
-0+ +#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>
Please keep alphabetical order.
Quoted 38 lines
drivers/leds/leds-chromeos-keyboard.c new file +38
-0+/* 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,
drivers/leds/leds-chromeos-keyboard.c line 74
Quoted 10 lines
drivers/leds/leds-chromeos-keyboard.c new file +10
-0+ &handle); +if (ACPI_FAILURE (status)) { +dev_err (&pdev->dev,"Unable fo find ACPI device %s\n" , +ACPI_KEYBOARD_BACKLIGHT_DEVICE ); +return -ENODEV ; + } + + cdev =devm_kzalloc (&pdev->dev,sizeof (struct led_classdev ),GFP_KERNEL ); +if (!cdev) +return -ENOMEM ;
Please add empty line here.
drivers/leds/leds-chromeos-keyboard.c line 78
Quoted 4 lines
drivers/leds/leds-chromeos-keyboard.c new file +4
-0+ cdev->name ="chromeos::kbd_backlight" ; + cdev->brightness_set = keyboard_led_set_brightness; + cdev->max_brightness =ACPI_KEYBOARD_BACKLIGHT_MAX ; + cdev->brightness = cdev->max_brightness;
Should this LED be turned on by default?
drivers/leds/leds-chromeos-keyboard.c line 85
Quoted 7 lines
drivers/leds/leds-chromeos-keyboard.c new file +7
-0+ cdev->flags |=LED_CORE_SUSPENDRESUME ; + + ret =devm_led_classdev_register (&pdev->dev, cdev); +if (ret) +return ret; + +platform_set_drvdata (pdev, cdev);
Empty line here please.
drivers/leds/leds-chromeos-keyboard.c line 93
Quoted 8 lines
drivers/leds/leds-chromeos-keyboard.c new file +8
-0+return 0 ; +} + +static int keyboard_led_remove (struct platform_device *pdev) +{ +struct led_classdev *cdev =platform_get_drvdata (pdev); + +platform_set_drvdata (pdev,NULL );
Empty line here please.
Quoted 14 lines
drivers/leds/leds-chromeos-keyboard.c new file +14
-0+return 0 ; +} + +static const struct acpi_device_id keyboard_led_id[] = { + {"GOOG0002" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (acpi, keyboard_led_id); + +static struct platform_driver keyboard_led_driver = { + .driver = { + .name ="chromeos-keyboard-leds" , + .owner =THIS_MODULE , + .acpi_match_table =ACPI_PTR (keyboard_led_id),
drivers/leds/leds-chromeos-keyboard.c line 117
Quoted 10 lines
drivers/leds/leds-chromeos-keyboard.c new file +10
-0+ }, + .probe = keyboard_led_probe, + .remove = keyboard_led_remove, +}; + +module_platform_driver (keyboard_led_driver); + +MODULE_AUTHOR ("Simon Que <[email protected]>" ); +MODULE_DESCRIPTION ("ChromeOS Keyboard LED Driver" ); +MODULE_LICENSE ("GPL" );
s/GPL/GPL v2/ to match the statement at the top of the file.
Quoted 2 lines
drivers/leds/leds-chromeos-keyboard.c new file +1
-0+MODULE_ALIAS ("platform:chromeos-keyboard-leds" );
Signature · 2 lines
Best regards, Jacek Anaszewski
Quoted 8 lines · Jacek Anaszewski
drivers/leds/leds-chromeos-keyboard.c line 93
Quoted 5 lines · Evan McClain
drivers/leds/leds-chromeos-keyboard.c new file +5
-0+static int keyboard_led_remove (struct platform_device *pdev) +{ +struct led_classdev *cdev =platform_get_drvdata (pdev); + +platform_set_drvdata (pdev,NULL );Empty line here please.
Unless I'm reading things wrong, I don't think keyboard_led_remove is needed at all.
Signature · 2 lines
Evan McClain https://keybase.io/aeroevan
Quoted 10 lines · Evan McClain
Quoted 8 lines · Jacek Anaszewski
drivers/leds/leds-chromeos-keyboard.c line 93
Quoted 5 lines · Evan McClain
drivers/leds/leds-chromeos-keyboard.c new file +5
-0+static int keyboard_led_remove (struct platform_device *pdev) +{ +struct led_classdev *cdev =platform_get_drvdata (pdev); + +platform_set_drvdata (pdev,NULL );Empty line here please.
Quoted 3 lines
Unless I'm reading things wrong, I don't think
keyboard_led_removeis needed at all.
Indeed, we can remove it.
Signature · 2 lines
Best regards, Jacek Anaszewski