2 * 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.
17 #include <linux/acpi.h>
18 #include <linux/leds.h>
19 #include <linux/delay.h>
20 #include <linux/err.h>
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/platform_device.h>
25 #include <linux/slab.h>
27 /* Keyboard LED ACPI Device must be defined in firmware */
28 #define ACPI_KEYBOARD_BACKLIGHT_DEVICE "\\_SB.KBLT"
29 #define ACPI_KEYBOARD_BACKLIGHT_READ ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBQC"
30 #define ACPI_KEYBOARD_BACKLIGHT_WRITE ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBCM"
32 #define ACPI_KEYBOARD_BACKLIGHT_MAX 100
34 static void keyboard_led_set_brightness(struct led_classdev
*cdev
,
35 enum led_brightness brightness
)
37 union acpi_object param
;
38 struct acpi_object_list input
;
41 param
.type
= ACPI_TYPE_INTEGER
;
42 param
.integer
.value
= brightness
;
44 input
.pointer
= ¶m
;
46 status
= acpi_evaluate_object(NULL
, ACPI_KEYBOARD_BACKLIGHT_WRITE
,
48 if (ACPI_FAILURE(status
))
49 dev_err(cdev
->dev
, "Error setting keyboard LED value: %d\n",
53 static enum led_brightness
54 keyboard_led_get_brightness(struct led_classdev
*cdev
)
56 unsigned long long brightness
;
59 status
= acpi_evaluate_integer(NULL
, ACPI_KEYBOARD_BACKLIGHT_READ
,
61 if (ACPI_FAILURE(status
)) {
62 dev_err(cdev
->dev
, "Error getting keyboard LED value: %d\n",
70 static int keyboard_led_probe(struct platform_device
*pdev
)
72 struct led_classdev
*cdev
;
77 /* Look for the keyboard LED ACPI Device */
78 status
= acpi_get_handle(ACPI_ROOT_OBJECT
,
79 ACPI_KEYBOARD_BACKLIGHT_DEVICE
,
81 if (ACPI_FAILURE(status
)) {
82 dev_err(&pdev
->dev
, "Unable to find ACPI device %s: %d\n",
83 ACPI_KEYBOARD_BACKLIGHT_DEVICE
, status
);
87 cdev
= devm_kzalloc(&pdev
->dev
, sizeof(*cdev
), GFP_KERNEL
);
91 cdev
->name
= "chromeos::kbd_backlight";
92 cdev
->max_brightness
= ACPI_KEYBOARD_BACKLIGHT_MAX
;
93 cdev
->flags
|= LED_CORE_SUSPENDRESUME
;
94 cdev
->brightness_set
= keyboard_led_set_brightness
;
95 cdev
->brightness_get
= keyboard_led_get_brightness
;
97 error
= devm_led_classdev_register(&pdev
->dev
, cdev
);
104 static const struct acpi_device_id keyboard_led_id
[] = {
108 MODULE_DEVICE_TABLE(acpi
, keyboard_led_id
);
110 static struct platform_driver keyboard_led_driver
= {
112 .name
= "chromeos-keyboard-leds",
113 .acpi_match_table
= ACPI_PTR(keyboard_led_id
),
115 .probe
= keyboard_led_probe
,
117 module_platform_driver(keyboard_led_driver
);
119 MODULE_AUTHOR("Simon Que <sque@chromium.org>");
120 MODULE_DESCRIPTION("ChromeOS Keyboard backlight LED Driver");
121 MODULE_LICENSE("GPL");
122 MODULE_ALIAS("platform:chromeos-keyboard-leds");