UPSTREAM: USB: option: add Huawei "ACM" devices using protocol = vendor
[cascardo/linux.git] / drivers / leds / leds-chromeos-keyboard.c
1 /*
2  *  leds-chromeos-keyboard.c - Keyboard backlight LED driver for Chrome OS.
3  *
4  *  Copyright (C) 2012 Google, Inc.
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
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>
31
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"
36
37 #define ACPI_KEYBOARD_BACKLIGHT_MAX             100
38
39 static void keyboard_led_set_brightness(struct led_classdev *cdev,
40         enum led_brightness brightness)
41 {
42         union acpi_object param;
43         struct acpi_object_list input;
44         acpi_status status;
45
46         if (!(cdev->flags & LED_SUSPENDED))
47                 cdev->brightness = brightness;
48
49         param.type = ACPI_TYPE_INTEGER;
50         param.integer.value = brightness;
51         input.count = 1;
52         input.pointer = &param;
53
54         status = acpi_evaluate_object(NULL, ACPI_KEYBOARD_BACKLIGHT_WRITE,
55                                           &input, NULL);
56         if (ACPI_FAILURE(status))
57                 dev_err(cdev->dev, "Error setting keyboard LED value");
58 }
59
60 static int keyboard_led_probe(struct platform_device *pdev)
61 {
62         struct led_classdev *cdev;
63         acpi_handle handle;
64         acpi_status status;
65         int ret;
66
67         /* Look for the keyboard LED ACPI Device */
68         status = acpi_get_handle(ACPI_ROOT_OBJECT,
69                                  ACPI_KEYBOARD_BACKLIGHT_DEVICE,
70                                  &handle);
71         if (ACPI_FAILURE(status)) {
72                 dev_err(&pdev->dev, "Unable fo find ACPI device %s\n",
73                         ACPI_KEYBOARD_BACKLIGHT_DEVICE);
74                 return -ENODEV;
75         }
76
77         cdev = kzalloc(sizeof(struct led_classdev), GFP_KERNEL);
78         if (!cdev)
79                 return -ENOMEM;
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;
85
86         ret = led_classdev_register(&pdev->dev, cdev);
87         if (ret)
88                 goto err;
89
90         platform_set_drvdata(pdev, cdev);
91         return 0;
92 err:
93         kfree(cdev);
94         return ret;
95 }
96
97 static int keyboard_led_remove(struct platform_device *pdev)
98 {
99         struct led_classdev *cdev = platform_get_drvdata(pdev);
100
101         platform_set_drvdata(pdev, NULL);
102         kfree(cdev);
103         return 0;
104 }
105
106 static struct platform_driver keyboard_led_driver = {
107         .driver         = {
108                 .name   = "chromeos-keyboard-leds",
109                 .owner  = THIS_MODULE,
110         },
111         .probe          = keyboard_led_probe,
112         .remove         = keyboard_led_remove,
113 };
114
115 module_platform_driver(keyboard_led_driver);
116
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");