2 * Copyright (C) 2010 Dell Inc.
3 * Louis Davis <louis_davis@dell.com>
4 * Jim Dailey <jim_dailey@dell.com>
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
8 * published by the Free Software Foundation.
12 #include <linux/acpi.h>
13 #include <linux/leds.h>
14 #include <linux/slab.h>
15 #include <linux/module.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
, u8 result_code
, u8 device_id
,
50 u8 command
, u8 on_time
, u8 off_time
)
52 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
53 struct bios_args
*bios_return
;
54 struct acpi_buffer input
;
55 union acpi_object
*obj
;
59 struct bios_args args
= {
61 .result_code
= result_code
,
62 .device_id
= device_id
,
68 input
.length
= sizeof(struct bios_args
);
69 input
.pointer
= &args
;
71 status
= wmi_evaluate_method(DELL_LED_BIOS_GUID
, 0, 1, &input
, &output
);
72 if (ACPI_FAILURE(status
))
79 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
84 bios_return
= ((struct bios_args
*)obj
->buffer
.pointer
);
85 return_code
= bios_return
->result_code
;
92 static int led_on(void)
94 return dell_led_perform_fn(3, /* Length of command */
95 INTERFACE_ERROR
, /* Init to INTERFACE_ERROR */
96 DEVICE_ID_PANEL_BACK
, /* Device ID */
97 CMD_LED_ON
, /* Command */
102 static int led_off(void)
104 return dell_led_perform_fn(3, /* Length of command */
105 INTERFACE_ERROR
, /* Init to INTERFACE_ERROR */
106 DEVICE_ID_PANEL_BACK
, /* Device ID */
107 CMD_LED_OFF
, /* Command */
112 static int led_blink(unsigned char on_eighths
, unsigned char off_eighths
)
114 return dell_led_perform_fn(5, /* Length of command */
115 INTERFACE_ERROR
, /* Init to INTERFACE_ERROR */
116 DEVICE_ID_PANEL_BACK
, /* Device ID */
117 CMD_LED_BLINK
, /* Command */
118 on_eighths
, /* blink on in eigths of a second */
119 off_eighths
); /* blink off in eights of a second */
122 static void dell_led_set(struct led_classdev
*led_cdev
,
123 enum led_brightness value
)
125 if (value
== LED_OFF
)
131 static int dell_led_blink(struct led_classdev
*led_cdev
,
132 unsigned long *delay_on
, unsigned long *delay_off
)
134 unsigned long on_eighths
;
135 unsigned long off_eighths
;
138 * The Dell LED delay is based on 125ms intervals.
139 * Need to round up to next interval.
142 on_eighths
= DIV_ROUND_UP(*delay_on
, 125);
143 on_eighths
= clamp_t(unsigned long, on_eighths
, 1, 255);
144 *delay_on
= on_eighths
* 125;
146 off_eighths
= DIV_ROUND_UP(*delay_off
, 125);
147 off_eighths
= clamp_t(unsigned long, off_eighths
, 1, 255);
148 *delay_off
= off_eighths
* 125;
150 led_blink(on_eighths
, off_eighths
);
155 static struct led_classdev dell_led
= {
157 .brightness
= LED_OFF
,
159 .brightness_set
= dell_led_set
,
160 .blink_set
= dell_led_blink
,
161 .flags
= LED_CORE_SUSPENDRESUME
,
164 static int __init
dell_led_init(void)
168 if (!wmi_has_guid(DELL_LED_BIOS_GUID
))
175 return led_classdev_register(NULL
, &dell_led
);
178 static void __exit
dell_led_exit(void)
180 led_classdev_unregister(&dell_led
);
185 module_init(dell_led_init
);
186 module_exit(dell_led_exit
);