of/platform: Initialise default DMA masks
[linux/fpc-iii.git] / drivers / platform / chrome / cros_kbd_led_backlight.c
blobca3e4da852b44ac85e4c45b3fb220cab36f99715
1 /*
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;
39 acpi_status status;
41 param.type = ACPI_TYPE_INTEGER;
42 param.integer.value = brightness;
43 input.count = 1;
44 input.pointer = &param;
46 status = acpi_evaluate_object(NULL, ACPI_KEYBOARD_BACKLIGHT_WRITE,
47 &input, NULL);
48 if (ACPI_FAILURE(status))
49 dev_err(cdev->dev, "Error setting keyboard LED value: %d\n",
50 status);
53 static enum led_brightness
54 keyboard_led_get_brightness(struct led_classdev *cdev)
56 unsigned long long brightness;
57 acpi_status status;
59 status = acpi_evaluate_integer(NULL, ACPI_KEYBOARD_BACKLIGHT_READ,
60 NULL, &brightness);
61 if (ACPI_FAILURE(status)) {
62 dev_err(cdev->dev, "Error getting keyboard LED value: %d\n",
63 status);
64 return -EIO;
67 return brightness;
70 static int keyboard_led_probe(struct platform_device *pdev)
72 struct led_classdev *cdev;
73 acpi_handle handle;
74 acpi_status status;
75 int error;
77 /* Look for the keyboard LED ACPI Device */
78 status = acpi_get_handle(ACPI_ROOT_OBJECT,
79 ACPI_KEYBOARD_BACKLIGHT_DEVICE,
80 &handle);
81 if (ACPI_FAILURE(status)) {
82 dev_err(&pdev->dev, "Unable to find ACPI device %s: %d\n",
83 ACPI_KEYBOARD_BACKLIGHT_DEVICE, status);
84 return -ENXIO;
87 cdev = devm_kzalloc(&pdev->dev, sizeof(*cdev), GFP_KERNEL);
88 if (!cdev)
89 return -ENOMEM;
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);
98 if (error)
99 return error;
101 return 0;
104 static const struct acpi_device_id keyboard_led_id[] = {
105 { "GOOG0002", 0 },
108 MODULE_DEVICE_TABLE(acpi, keyboard_led_id);
110 static struct platform_driver keyboard_led_driver = {
111 .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");