linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver
@ 2016-02-22 15:00 Evan McClain
  2016-02-22 15:00 ` [PATCH 2/3] leds: leds-chromeos-keyboard: Add ACPI _HID probing Evan McClain
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Evan McClain @ 2016-02-22 15:00 UTC (permalink / raw)
  To: linux-leds; +Cc: Simon Que, Jacek Anaszewski

From: Simon Que <sque@chromium.org>

Some Chrome OS devices use ACPI-based keyboard backlight LEDs.

Enable with menuconfig option under Device Drivers -> LED Support.

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 7f940c2..38d2997 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -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"
 
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index e9d53092..2d7f73a 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -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
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 = &param;
+
+	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.5.0

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

* [PATCH 2/3] leds: leds-chromeos-keyboard: Add ACPI _HID probing
  2016-02-22 15:00 [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver Evan McClain
@ 2016-02-22 15:00 ` Evan McClain
  2016-02-22 15:01 ` [PATCH 3/3] leds: chromeos: Use devm_led_classdev_register Evan McClain
  2016-02-22 15:46 ` [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver Jacek Anaszewski
  2 siblings, 0 replies; 6+ messages in thread
From: Evan McClain @ 2016-02-22 15:00 UTC (permalink / raw)
  To: linux-leds; +Cc: Simon Que, Jacek Anaszewski, Duncan Laurie, Evan McClain

From: Duncan Laurie <dlaurie@chromium.org>

Add an ACPI ID to probe the keyboard backlight driver without
needing a platform level driver to force it on.

Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Signed-off-by: Evan McClain <aeroevan@gmail.com>
---
 drivers/leds/leds-chromeos-keyboard.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/leds/leds-chromeos-keyboard.c b/drivers/leds/leds-chromeos-keyboard.c
index 32d70c0..6a6ff75 100644
--- a/drivers/leds/leds-chromeos-keyboard.c
+++ b/drivers/leds/leds-chromeos-keyboard.c
@@ -98,10 +98,17 @@ static int keyboard_led_remove(struct platform_device *pdev)
 	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,
-- 
2.5.0

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

* [PATCH 3/3] leds: chromeos: Use devm_led_classdev_register.
  2016-02-22 15:00 [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver Evan McClain
  2016-02-22 15:00 ` [PATCH 2/3] leds: leds-chromeos-keyboard: Add ACPI _HID probing Evan McClain
@ 2016-02-22 15:01 ` Evan McClain
  2016-02-22 15:46 ` [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver Jacek Anaszewski
  2 siblings, 0 replies; 6+ messages in thread
From: Evan McClain @ 2016-02-22 15:01 UTC (permalink / raw)
  To: linux-leds; +Cc: Simon Que, Jacek Anaszewski, Evan McClain

Also use managed devm_kzalloc.

Signed-off-by: Evan McClain <aeroevan@gmail.com>
---
 drivers/leds/leds-chromeos-keyboard.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/leds-chromeos-keyboard.c b/drivers/leds/leds-chromeos-keyboard.c
index 6a6ff75..4e56ede 100644
--- a/drivers/leds/leds-chromeos-keyboard.c
+++ b/drivers/leds/leds-chromeos-keyboard.c
@@ -69,7 +69,7 @@ static int keyboard_led_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	cdev = kzalloc(sizeof(struct led_classdev), GFP_KERNEL);
+	cdev = devm_kzalloc(&pdev->dev, sizeof(struct led_classdev), GFP_KERNEL);
 	if (!cdev)
 		return -ENOMEM;
 	cdev->name = "chromeos::kbd_backlight";
@@ -78,15 +78,12 @@ static int keyboard_led_probe(struct platform_device *pdev)
 	cdev->brightness = cdev->max_brightness;
 	cdev->flags |= LED_CORE_SUSPENDRESUME;
 
-	ret = led_classdev_register(&pdev->dev, cdev);
+	ret = devm_led_classdev_register(&pdev->dev, cdev);
 	if (ret)
-		goto err;
+		return ret;
 
 	platform_set_drvdata(pdev, cdev);
 	return 0;
-err:
-	kfree(cdev);
-	return ret;
 }
 
 static int keyboard_led_remove(struct platform_device *pdev)
@@ -94,7 +91,6 @@ 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;
 }
 
-- 
2.5.0

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

* Re: [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver
  2016-02-22 15:00 [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver Evan McClain
  2016-02-22 15:00 ` [PATCH 2/3] leds: leds-chromeos-keyboard: Add ACPI _HID probing Evan McClain
  2016-02-22 15:01 ` [PATCH 3/3] leds: chromeos: Use devm_led_classdev_register Evan McClain
@ 2016-02-22 15:46 ` Jacek Anaszewski
  2016-02-22 16:02   ` Evan McClain
  2 siblings, 1 reply; 6+ messages in thread
From: Jacek Anaszewski @ 2016-02-22 15:46 UTC (permalink / raw)
  To: Evan McClain; +Cc: linux-leds, Simon Que

Hi Evan,

Please merge these three patches into a single one, if that's not
a problem. You're adding a new driver and we don't need to retain
the development history.

Thanks,
Jacek Anaszewski

On 02/22/2016 04:00 PM, Evan McClain wrote:
> From: Simon Que <sque@chromium.org>
>
> Some Chrome OS devices use ACPI-based keyboard backlight LEDs.
>
> Enable with menuconfig option under Device Drivers -> LED Support.
>
> 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 7f940c2..38d2997 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -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"
>
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index e9d53092..2d7f73a 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -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
> 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 = &param;
> +
> +	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");
>

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

* Re: [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver
  2016-02-22 15:46 ` [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver Jacek Anaszewski
@ 2016-02-22 16:02   ` Evan McClain
  2016-02-23  8:21     ` Jacek Anaszewski
  0 siblings, 1 reply; 6+ messages in thread
From: Evan McClain @ 2016-02-22 16:02 UTC (permalink / raw)
  To: Jacek Anaszewski; +Cc: linux-leds, Simon Que

[-- Attachment #1: Type: text/plain, Size: 391 bytes --]

On Mon, 2016-02-22 at 16:46 +0100, Jacek Anaszewski wrote:
> Hi Evan,
> 
> Please merge these three patches into a single one, if that's not
> a problem. You're adding a new driver and we don't need to retain
> the development history.

Squashed patch sent. Sorry for the confusion; I'm not that familiar
with this process.

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] 6+ messages in thread

* Re: [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver
  2016-02-22 16:02   ` Evan McClain
@ 2016-02-23  8:21     ` Jacek Anaszewski
  0 siblings, 0 replies; 6+ messages in thread
From: Jacek Anaszewski @ 2016-02-23  8:21 UTC (permalink / raw)
  To: Evan McClain; +Cc: linux-leds, Simon Que

On 02/22/2016 05:02 PM, Evan McClain wrote:
> On Mon, 2016-02-22 at 16:46 +0100, Jacek Anaszewski wrote:
>> Hi Evan,
>>
>> Please merge these three patches into a single one, if that's not
>> a problem. You're adding a new driver and we don't need to retain
>> the development history.
>
> Squashed patch sent. Sorry for the confusion; I'm not that familiar
> with this process.

No problem. You can always refer to Documentation/SubmittingPatches
in case of any doubts.

-- 
Best regards,
Jacek Anaszewski

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

end of thread, other threads:[~2016-02-23  8:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-22 15:00 [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver Evan McClain
2016-02-22 15:00 ` [PATCH 2/3] leds: leds-chromeos-keyboard: Add ACPI _HID probing Evan McClain
2016-02-22 15:01 ` [PATCH 3/3] leds: chromeos: Use devm_led_classdev_register Evan McClain
2016-02-22 15:46 ` [PATCH 1/3] leds: Add Chrome OS keyboard LEDs driver Jacek Anaszewski
2016-02-22 16:02   ` Evan McClain
2016-02-23  8:21     ` Jacek Anaszewski

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).