2 * dell_led.c - Dell LED Driver
4 * Copyright (C) 2010 Dell Inc.
5 * Louis Davis <louis_davis@dell.com>
6 * Jim Dailey <jim_dailey@dell.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation.
14 #include <linux/acpi.h>
15 #include <linux/leds.h>
16 #include <linux/slab.h>
18 MODULE_AUTHOR("Louis Davis/Jim Dailey");
19 MODULE_DESCRIPTION("Dell LED Control Driver");
20 MODULE_LICENSE("GPL");
22 #define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
23 MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID
);
25 /* Error Result Codes: */
26 #define INVALID_DEVICE_ID 250
27 #define INVALID_PARAMETER 251
28 #define INVALID_BUFFER 252
29 #define INTERFACE_ERROR 253
30 #define UNSUPPORTED_COMMAND 254
31 #define UNSPECIFIED_ERROR 255
34 #define DEVICE_ID_PANEL_BACK 1
38 #define CMD_LED_OFF 17
39 #define CMD_LED_BLINK 18
43 unsigned char result_code
;
44 unsigned char device_id
;
45 unsigned char command
;
46 unsigned char on_time
;
47 unsigned char off_time
;
50 static int dell_led_perform_fn(u8 length
,
57 struct bios_args
*bios_return
;
59 union acpi_object
*obj
;
60 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
61 struct acpi_buffer input
;
64 struct bios_args args
;
66 args
.result_code
= result_code
;
67 args
.device_id
= device_id
;
68 args
.command
= command
;
69 args
.on_time
= on_time
;
70 args
.off_time
= off_time
;
72 input
.length
= sizeof(struct bios_args
);
73 input
.pointer
= &args
;
75 status
= wmi_evaluate_method(DELL_LED_BIOS_GUID
,
81 if (ACPI_FAILURE(status
))
88 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
93 bios_return
= ((struct bios_args
*)obj
->buffer
.pointer
);
94 return_code
= bios_return
->result_code
;
101 static int led_on(void)
103 return dell_led_perform_fn(3, /* Length of command */
104 INTERFACE_ERROR
, /* Init to INTERFACE_ERROR */
105 DEVICE_ID_PANEL_BACK
, /* Device ID */
106 CMD_LED_ON
, /* Command */
111 static int led_off(void)
113 return dell_led_perform_fn(3, /* Length of command */
114 INTERFACE_ERROR
, /* Init to INTERFACE_ERROR */
115 DEVICE_ID_PANEL_BACK
, /* Device ID */
116 CMD_LED_OFF
, /* Command */
121 static int led_blink(unsigned char on_eighths
,
122 unsigned char off_eighths
)
124 return dell_led_perform_fn(5, /* Length of command */
125 INTERFACE_ERROR
, /* Init to INTERFACE_ERROR */
126 DEVICE_ID_PANEL_BACK
, /* Device ID */
127 CMD_LED_BLINK
, /* Command */
128 on_eighths
, /* blink on in eigths of a second */
129 off_eighths
); /* blink off in eights of a second */
132 static void dell_led_set(struct led_classdev
*led_cdev
,
133 enum led_brightness value
)
135 if (value
== LED_OFF
)
141 static int dell_led_blink(struct led_classdev
*led_cdev
,
142 unsigned long *delay_on
,
143 unsigned long *delay_off
)
145 unsigned long on_eighths
;
146 unsigned long off_eighths
;
148 /* The Dell LED delay is based on 125ms intervals.
149 Need to round up to next interval. */
151 on_eighths
= (*delay_on
+ 124) / 125;
154 if (on_eighths
> 255)
156 *delay_on
= on_eighths
* 125;
158 off_eighths
= (*delay_off
+ 124) / 125;
159 if (0 == off_eighths
)
161 if (off_eighths
> 255)
163 *delay_off
= off_eighths
* 125;
165 led_blink(on_eighths
, off_eighths
);
170 static struct led_classdev dell_led
= {
172 .brightness
= LED_OFF
,
174 .brightness_set
= dell_led_set
,
175 .blink_set
= dell_led_blink
,
176 .flags
= LED_CORE_SUSPENDRESUME
,
179 static int __init
dell_led_init(void)
183 if (!wmi_has_guid(DELL_LED_BIOS_GUID
))
190 return led_classdev_register(NULL
, &dell_led
);
193 static void __exit
dell_led_exit(void)
195 led_classdev_unregister(&dell_led
);
200 module_init(dell_led_init
);
201 module_exit(dell_led_exit
);