2 * dell_led.c - Dell LED Driver
4 * Copyright (C) 2010 Dell Inc.
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>
17 #include <linux/module.h>
18 #include <linux/dmi.h>
19 #include <linux/dell-led.h>
20 #include "../platform/x86/dell-smbios.h"
22 MODULE_AUTHOR("Louis Davis/Jim Dailey");
23 MODULE_DESCRIPTION("Dell LED Control Driver");
24 MODULE_LICENSE("GPL");
26 #define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
27 #define DELL_APP_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
28 MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
30 /* Error Result Codes: */
31 #define INVALID_DEVICE_ID 250
32 #define INVALID_PARAMETER 251
33 #define INVALID_BUFFER 252
34 #define INTERFACE_ERROR 253
35 #define UNSUPPORTED_COMMAND 254
36 #define UNSPECIFIED_ERROR 255
39 #define DEVICE_ID_PANEL_BACK 1
43 #define CMD_LED_OFF 17
44 #define CMD_LED_BLINK 18
46 #define GLOBAL_MIC_MUTE_ENABLE 0x364
47 #define GLOBAL_MIC_MUTE_DISABLE 0x365
49 static int dell_micmute_led_set(int state)
51 struct calling_interface_buffer *buffer;
52 struct calling_interface_token *token;
54 if (!wmi_has_guid(DELL_APP_GUID))
58 token = dell_smbios_find_token(GLOBAL_MIC_MUTE_DISABLE);
60 token = dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE);
67 buffer = dell_smbios_get_buffer();
68 buffer->input[0] = token->location;
69 buffer->input[1] = token->value;
70 dell_smbios_send_request(1, 0);
71 dell_smbios_release_buffer();
76 int dell_app_wmi_led_set(int whichled, int on)
81 case DELL_LED_MICMUTE:
82 state = dell_micmute_led_set(on);
85 pr_warn("led type %x is not supported\n", whichled);
91 EXPORT_SYMBOL_GPL(dell_app_wmi_led_set);
95 unsigned char result_code;
96 unsigned char device_id;
97 unsigned char command;
98 unsigned char on_time;
99 unsigned char off_time;
102 static int dell_led_perform_fn(u8 length,
109 struct bios_args *bios_return;
111 union acpi_object *obj;
112 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
113 struct acpi_buffer input;
116 struct bios_args args;
117 args.length = length;
118 args.result_code = result_code;
119 args.device_id = device_id;
120 args.command = command;
121 args.on_time = on_time;
122 args.off_time = off_time;
124 input.length = sizeof(struct bios_args);
125 input.pointer = &args;
127 status = wmi_evaluate_method(DELL_LED_BIOS_GUID,
133 if (ACPI_FAILURE(status))
136 obj = output.pointer;
140 else if (obj->type != ACPI_TYPE_BUFFER) {
145 bios_return = ((struct bios_args *)obj->buffer.pointer);
146 return_code = bios_return->result_code;
153 static int led_on(void)
155 return dell_led_perform_fn(3, /* Length of command */
156 INTERFACE_ERROR, /* Init to INTERFACE_ERROR */
157 DEVICE_ID_PANEL_BACK, /* Device ID */
158 CMD_LED_ON, /* Command */
163 static int led_off(void)
165 return dell_led_perform_fn(3, /* Length of command */
166 INTERFACE_ERROR, /* Init to INTERFACE_ERROR */
167 DEVICE_ID_PANEL_BACK, /* Device ID */
168 CMD_LED_OFF, /* Command */
173 static int led_blink(unsigned char on_eighths,
174 unsigned char off_eighths)
176 return dell_led_perform_fn(5, /* Length of command */
177 INTERFACE_ERROR, /* Init to INTERFACE_ERROR */
178 DEVICE_ID_PANEL_BACK, /* Device ID */
179 CMD_LED_BLINK, /* Command */
180 on_eighths, /* blink on in eigths of a second */
181 off_eighths); /* blink off in eights of a second */
184 static void dell_led_set(struct led_classdev *led_cdev,
185 enum led_brightness value)
187 if (value == LED_OFF)
193 static int dell_led_blink(struct led_classdev *led_cdev,
194 unsigned long *delay_on,
195 unsigned long *delay_off)
197 unsigned long on_eighths;
198 unsigned long off_eighths;
200 /* The Dell LED delay is based on 125ms intervals.
201 Need to round up to next interval. */
203 on_eighths = (*delay_on + 124) / 125;
206 if (on_eighths > 255)
208 *delay_on = on_eighths * 125;
210 off_eighths = (*delay_off + 124) / 125;
211 if (0 == off_eighths)
213 if (off_eighths > 255)
215 *delay_off = off_eighths * 125;
217 led_blink(on_eighths, off_eighths);
222 static struct led_classdev dell_led = {
224 .brightness = LED_OFF,
226 .brightness_set = dell_led_set,
227 .blink_set = dell_led_blink,
228 .flags = LED_CORE_SUSPENDRESUME,
231 static int __init dell_led_init(void)
235 if (!wmi_has_guid(DELL_LED_BIOS_GUID) && !wmi_has_guid(DELL_APP_GUID))
238 if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
243 error = led_classdev_register(NULL, &dell_led);
249 static void __exit dell_led_exit(void)
253 if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
256 led_classdev_unregister(&dell_led);
260 module_init(dell_led_init);
261 module_exit(dell_led_exit);