leds: Add driver for HP harddisk protection LEDs
[linux-2.6/mini2440.git] / drivers / leds / leds-hp-disk.c
blobd636280198ab349ba0df20c4a18ee5aed32b53c4
1 /*
2 * leds-hp-disk.c - driver for HP "hard disk protection" LED
4 * Copyright (C) 2008 Pavel Machek
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
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/dmi.h>
24 #include <linux/module.h>
25 #include <linux/types.h>
26 #include <linux/platform_device.h>
27 #include <linux/interrupt.h>
28 #include <linux/input.h>
29 #include <linux/kthread.h>
30 #include <linux/version.h>
31 #include <linux/leds.h>
32 #include <acpi/acpi_drivers.h>
34 #define DRIVER_NAME "leds-hp-disk"
35 #define ACPI_MDPS_CLASS "led"
37 /* For automatic insertion of the module */
38 static struct acpi_device_id hpled_device_ids[] = {
39 {"HPQ0004", 0}, /* HP Mobile Data Protection System PNP */
40 {"", 0},
42 MODULE_DEVICE_TABLE(acpi, hpled_device_ids);
44 struct acpi_hpled {
45 struct acpi_device *device; /* The ACPI device */
48 static struct acpi_hpled adev;
50 static acpi_status hpled_acpi_write(acpi_handle handle, int reg)
52 unsigned long ret; /* Not used when writing */
53 union acpi_object in_obj[1];
54 struct acpi_object_list args = { 1, in_obj };
56 in_obj[0].type = ACPI_TYPE_INTEGER;
57 in_obj[0].integer.value = reg;
59 return acpi_evaluate_integer(handle, "ALED", &args, &ret);
62 static void hpled_set(struct led_classdev *led_cdev,
63 enum led_brightness value)
65 hpled_acpi_write(adev.device->handle, !!value);
68 static struct led_classdev hpled_led = {
69 .name = "hp:red:hddprotection",
70 .default_trigger = "heartbeat",
71 .brightness_set = hpled_set,
74 #ifdef CONFIG_PM
75 static int hpled_suspend(struct acpi_device *dev, pm_message_t state)
77 led_classdev_suspend(&hpled_led);
78 return 0;
81 static int hpled_resume(struct acpi_device *dev)
83 led_classdev_resume(&hpled_led);
84 return 0;
86 #else
87 #define hpled_suspend NULL
88 #define hpled_resume NULL
89 #endif
91 static int hpled_add(struct acpi_device *device)
93 int ret;
95 if (!device)
96 return -EINVAL;
98 adev.device = device;
99 strcpy(acpi_device_name(device), DRIVER_NAME);
100 strcpy(acpi_device_class(device), ACPI_MDPS_CLASS);
101 acpi_driver_data(device) = &adev;
103 ret = led_classdev_register(NULL, &hpled_led);
104 return ret;
107 static int hpled_remove(struct acpi_device *device, int type)
109 if (!device)
110 return -EINVAL;
112 led_classdev_unregister(&hpled_led);
113 return 0;
118 static struct acpi_driver leds_hp_driver = {
119 .name = DRIVER_NAME,
120 .class = ACPI_MDPS_CLASS,
121 .ids = hpled_device_ids,
122 .ops = {
123 .add = hpled_add,
124 .remove = hpled_remove,
125 .suspend = hpled_suspend,
126 .resume = hpled_resume,
130 static int __init hpled_init_module(void)
132 int ret;
134 if (acpi_disabled)
135 return -ENODEV;
137 ret = acpi_bus_register_driver(&leds_hp_driver);
138 if (ret < 0)
139 return ret;
141 printk(KERN_INFO DRIVER_NAME " driver loaded.\n");
143 return 0;
146 static void __exit hpled_exit_module(void)
148 acpi_bus_unregister_driver(&leds_hp_driver);
151 MODULE_DESCRIPTION("Driver for HP disk protection LED");
152 MODULE_AUTHOR("Pavel Machek <pavel@suse.cz>");
153 MODULE_LICENSE("GPL");
155 module_init(hpled_init_module);
156 module_exit(hpled_exit_module);