1 // SPDX-License-Identifier: GPL-2.0+
2 // Keyboard backlight LED driver for ChromeOS
4 // Copyright (C) 2012 Google, Inc.
6 #include <linux/acpi.h>
7 #include <linux/leds.h>
8 #include <linux/delay.h>
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/platform_device.h>
14 #include <linux/slab.h>
16 /* Keyboard LED ACPI Device must be defined in firmware */
17 #define ACPI_KEYBOARD_BACKLIGHT_DEVICE "\\_SB.KBLT"
18 #define ACPI_KEYBOARD_BACKLIGHT_READ ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBQC"
19 #define ACPI_KEYBOARD_BACKLIGHT_WRITE ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBCM"
21 #define ACPI_KEYBOARD_BACKLIGHT_MAX 100
23 static void keyboard_led_set_brightness(struct led_classdev
*cdev
,
24 enum led_brightness brightness
)
26 union acpi_object param
;
27 struct acpi_object_list input
;
30 param
.type
= ACPI_TYPE_INTEGER
;
31 param
.integer
.value
= brightness
;
33 input
.pointer
= ¶m
;
35 status
= acpi_evaluate_object(NULL
, ACPI_KEYBOARD_BACKLIGHT_WRITE
,
37 if (ACPI_FAILURE(status
))
38 dev_err(cdev
->dev
, "Error setting keyboard LED value: %d\n",
42 static enum led_brightness
43 keyboard_led_get_brightness(struct led_classdev
*cdev
)
45 unsigned long long brightness
;
48 status
= acpi_evaluate_integer(NULL
, ACPI_KEYBOARD_BACKLIGHT_READ
,
50 if (ACPI_FAILURE(status
)) {
51 dev_err(cdev
->dev
, "Error getting keyboard LED value: %d\n",
59 static int keyboard_led_probe(struct platform_device
*pdev
)
61 struct led_classdev
*cdev
;
66 /* Look for the keyboard LED ACPI Device */
67 status
= acpi_get_handle(ACPI_ROOT_OBJECT
,
68 ACPI_KEYBOARD_BACKLIGHT_DEVICE
,
70 if (ACPI_FAILURE(status
)) {
71 dev_err(&pdev
->dev
, "Unable to find ACPI device %s: %d\n",
72 ACPI_KEYBOARD_BACKLIGHT_DEVICE
, status
);
76 cdev
= devm_kzalloc(&pdev
->dev
, sizeof(*cdev
), GFP_KERNEL
);
80 cdev
->name
= "chromeos::kbd_backlight";
81 cdev
->max_brightness
= ACPI_KEYBOARD_BACKLIGHT_MAX
;
82 cdev
->flags
|= LED_CORE_SUSPENDRESUME
;
83 cdev
->brightness_set
= keyboard_led_set_brightness
;
84 cdev
->brightness_get
= keyboard_led_get_brightness
;
86 error
= devm_led_classdev_register(&pdev
->dev
, cdev
);
93 static const struct acpi_device_id keyboard_led_id
[] = {
97 MODULE_DEVICE_TABLE(acpi
, keyboard_led_id
);
99 static struct platform_driver keyboard_led_driver
= {
101 .name
= "chromeos-keyboard-leds",
102 .acpi_match_table
= ACPI_PTR(keyboard_led_id
),
104 .probe
= keyboard_led_probe
,
106 module_platform_driver(keyboard_led_driver
);
108 MODULE_AUTHOR("Simon Que <sque@chromium.org>");
109 MODULE_DESCRIPTION("ChromeOS Keyboard backlight LED Driver");
110 MODULE_LICENSE("GPL");
111 MODULE_ALIAS("platform:chromeos-keyboard-leds");