2 * leds-chromeos-keyboard.c - Keyboard backlight LED driver for Chrome OS.
4 * Copyright (C) 2012 Google, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/acpi.h>
23 #include <linux/leds.h>
24 #include <linux/delay.h>
25 #include <linux/err.h>
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/kernel.h>
29 #include <linux/platform_device.h>
30 #include <linux/slab.h>
32 /* Keyboard LED ACPI Device must be defined in firmware */
33 #define ACPI_KEYBOARD_BACKLIGHT_DEVICE "\\_SB.KBLT"
34 #define ACPI_KEYBOARD_BACKLIGHT_READ ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBQC"
35 #define ACPI_KEYBOARD_BACKLIGHT_WRITE ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBCM"
37 #define ACPI_KEYBOARD_BACKLIGHT_MAX 100
39 static void keyboard_led_set_brightness(struct led_classdev *cdev,
40 enum led_brightness brightness)
42 union acpi_object param;
43 struct acpi_object_list input;
46 if (!(cdev->flags & LED_SUSPENDED))
47 cdev->brightness = brightness;
49 param.type = ACPI_TYPE_INTEGER;
50 param.integer.value = brightness;
52 input.pointer = ¶m;
54 status = acpi_evaluate_object(NULL, ACPI_KEYBOARD_BACKLIGHT_WRITE,
56 if (ACPI_FAILURE(status))
57 dev_err(cdev->dev, "Error setting keyboard LED value");
60 static int keyboard_led_probe(struct platform_device *pdev)
62 struct led_classdev *cdev;
67 /* Look for the keyboard LED ACPI Device */
68 status = acpi_get_handle(ACPI_ROOT_OBJECT,
69 ACPI_KEYBOARD_BACKLIGHT_DEVICE,
71 if (ACPI_FAILURE(status)) {
72 dev_err(&pdev->dev, "Unable fo find ACPI device %s\n",
73 ACPI_KEYBOARD_BACKLIGHT_DEVICE);
77 cdev = kzalloc(sizeof(struct led_classdev), GFP_KERNEL);
80 cdev->name = "chromeos::kbd_backlight";
81 cdev->brightness_set = keyboard_led_set_brightness;
82 cdev->max_brightness = ACPI_KEYBOARD_BACKLIGHT_MAX;
83 cdev->brightness = cdev->max_brightness;
84 cdev->flags |= LED_CORE_SUSPENDRESUME;
86 ret = led_classdev_register(&pdev->dev, cdev);
90 platform_set_drvdata(pdev, cdev);
97 static int keyboard_led_remove(struct platform_device *pdev)
99 struct led_classdev *cdev = platform_get_drvdata(pdev);
101 platform_set_drvdata(pdev, NULL);
106 static struct platform_driver keyboard_led_driver = {
108 .name = "chromeos-keyboard-leds",
109 .owner = THIS_MODULE,
111 .probe = keyboard_led_probe,
112 .remove = keyboard_led_remove,
115 module_platform_driver(keyboard_led_driver);
117 MODULE_AUTHOR("Simon Que <sque@chromium.org>");
118 MODULE_DESCRIPTION("ChromeOS Keyboard LED Driver");
119 MODULE_LICENSE("GPL");
120 MODULE_ALIAS("platform:chromeos-keyboard-leds");