target: Convert ->transport_wait_for_tasks usage to transport_generic_free_cmd
[linux/fpc-iii.git] / drivers / leds / dell-led.c
blob52590296af33e4a3f3af3b5de975741c3ffb1fc4
1 /*
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
33 /* Device ID */
34 #define DEVICE_ID_PANEL_BACK 1
36 /* LED Commands */
37 #define CMD_LED_ON 16
38 #define CMD_LED_OFF 17
39 #define CMD_LED_BLINK 18
41 struct bios_args {
42 unsigned char length;
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,
51 u8 result_code,
52 u8 device_id,
53 u8 command,
54 u8 on_time,
55 u8 off_time)
57 struct bios_args *bios_return;
58 u8 return_code;
59 union acpi_object *obj;
60 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
61 struct acpi_buffer input;
62 acpi_status status;
64 struct bios_args args;
65 args.length = length;
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,
78 &input,
79 &output);
81 if (ACPI_FAILURE(status))
82 return status;
84 obj = output.pointer;
86 if (!obj)
87 return -EINVAL;
88 else if (obj->type != ACPI_TYPE_BUFFER) {
89 kfree(obj);
90 return -EINVAL;
93 bios_return = ((struct bios_args *)obj->buffer.pointer);
94 return_code = bios_return->result_code;
96 kfree(obj);
98 return return_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 */
107 0, /* not used */
108 0); /* not used */
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 */
117 0, /* not used */
118 0); /* not used */
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)
136 led_off();
137 else
138 led_on();
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;
152 if (0 == on_eighths)
153 on_eighths = 1;
154 if (on_eighths > 255)
155 on_eighths = 255;
156 *delay_on = on_eighths * 125;
158 off_eighths = (*delay_off + 124) / 125;
159 if (0 == off_eighths)
160 off_eighths = 1;
161 if (off_eighths > 255)
162 off_eighths = 255;
163 *delay_off = off_eighths * 125;
165 led_blink(on_eighths, off_eighths);
167 return 0;
170 static struct led_classdev dell_led = {
171 .name = "dell::lid",
172 .brightness = LED_OFF,
173 .max_brightness = 1,
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)
181 int error = 0;
183 if (!wmi_has_guid(DELL_LED_BIOS_GUID))
184 return -ENODEV;
186 error = led_off();
187 if (error != 0)
188 return -ENODEV;
190 return led_classdev_register(NULL, &dell_led);
193 static void __exit dell_led_exit(void)
195 led_classdev_unregister(&dell_led);
197 led_off();
200 module_init(dell_led_init);
201 module_exit(dell_led_exit);