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>
17 MODULE_AUTHOR("Louis Davis/Jim Dailey");
18 MODULE_DESCRIPTION("Dell LED Control Driver");
19 MODULE_LICENSE("GPL");
21 #define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
22 MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID
);
24 /* Error Result Codes: */
25 #define INVALID_DEVICE_ID 250
26 #define INVALID_PARAMETER 251
27 #define INVALID_BUFFER 252
28 #define INTERFACE_ERROR 253
29 #define UNSUPPORTED_COMMAND 254
30 #define UNSPECIFIED_ERROR 255
33 #define DEVICE_ID_PANEL_BACK 1
37 #define CMD_LED_OFF 17
38 #define CMD_LED_BLINK 18
42 unsigned char result_code
;
43 unsigned char device_id
;
44 unsigned char command
;
45 unsigned char on_time
;
46 unsigned char off_time
;
49 static int dell_led_perform_fn(u8 length
,
56 struct bios_args
*bios_return
;
58 union acpi_object
*obj
;
59 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
60 struct acpi_buffer input
;
63 struct bios_args args
;
65 args
.result_code
= result_code
;
66 args
.device_id
= device_id
;
67 args
.command
= command
;
68 args
.on_time
= on_time
;
69 args
.off_time
= off_time
;
71 input
.length
= sizeof(struct bios_args
);
72 input
.pointer
= &args
;
74 status
= wmi_evaluate_method(DELL_LED_BIOS_GUID
,
80 if (ACPI_FAILURE(status
))
87 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
92 bios_return
= ((struct bios_args
*)obj
->buffer
.pointer
);
93 return_code
= bios_return
->result_code
;
100 static int led_on(void)
102 return dell_led_perform_fn(3, /* Length of command */
103 INTERFACE_ERROR
, /* Init to INTERFACE_ERROR */
104 DEVICE_ID_PANEL_BACK
, /* Device ID */
105 CMD_LED_ON
, /* Command */
110 static int led_off(void)
112 return dell_led_perform_fn(3, /* Length of command */
113 INTERFACE_ERROR
, /* Init to INTERFACE_ERROR */
114 DEVICE_ID_PANEL_BACK
, /* Device ID */
115 CMD_LED_OFF
, /* Command */
120 static int led_blink(unsigned char on_eighths
,
121 unsigned char off_eighths
)
123 return dell_led_perform_fn(5, /* Length of command */
124 INTERFACE_ERROR
, /* Init to INTERFACE_ERROR */
125 DEVICE_ID_PANEL_BACK
, /* Device ID */
126 CMD_LED_BLINK
, /* Command */
127 on_eighths
, /* blink on in eigths of a second */
128 off_eighths
); /* blink off in eights of a second */
131 static void dell_led_set(struct led_classdev
*led_cdev
,
132 enum led_brightness value
)
134 if (value
== LED_OFF
)
140 static int dell_led_blink(struct led_classdev
*led_cdev
,
141 unsigned long *delay_on
,
142 unsigned long *delay_off
)
144 unsigned long on_eighths
;
145 unsigned long off_eighths
;
147 /* The Dell LED delay is based on 125ms intervals.
148 Need to round up to next interval. */
150 on_eighths
= (*delay_on
+ 124) / 125;
153 if (on_eighths
> 255)
155 *delay_on
= on_eighths
* 125;
157 off_eighths
= (*delay_off
+ 124) / 125;
158 if (0 == off_eighths
)
160 if (off_eighths
> 255)
162 *delay_off
= off_eighths
* 125;
164 led_blink(on_eighths
, off_eighths
);
169 static struct led_classdev dell_led
= {
171 .brightness
= LED_OFF
,
173 .brightness_set
= dell_led_set
,
174 .blink_set
= dell_led_blink
,
175 .flags
= LED_CORE_SUSPENDRESUME
,
178 static int __init
dell_led_init(void)
182 if (!wmi_has_guid(DELL_LED_BIOS_GUID
))
189 return led_classdev_register(NULL
, &dell_led
);
192 static void __exit
dell_led_exit(void)
194 led_classdev_unregister(&dell_led
);
199 module_init(dell_led_init
);
200 module_exit(dell_led_exit
);