Linux Audio

Check our new training course

Loading...
v4.6
  1/*
  2 * dell_led.c - Dell LED Driver
  3 *
  4 * Copyright (C) 2010 Dell Inc.
  5 * Louis Davis <louis_davis@dell.com>
  6 * Jim Dailey <jim_dailey@dell.com>
  7 *
  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.
 11 *
 12 */
 13
 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"
 21
 22MODULE_AUTHOR("Louis Davis/Jim Dailey");
 23MODULE_DESCRIPTION("Dell LED Control Driver");
 24MODULE_LICENSE("GPL");
 25
 26#define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
 27#define DELL_APP_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
 28MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
 29
 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
 37
 38/* Device ID */
 39#define DEVICE_ID_PANEL_BACK	1
 40
 41/* LED Commands */
 42#define CMD_LED_ON	16
 43#define CMD_LED_OFF	17
 44#define CMD_LED_BLINK	18
 45
 46#define GLOBAL_MIC_MUTE_ENABLE	0x364
 47#define GLOBAL_MIC_MUTE_DISABLE	0x365
 48
 49static int dell_micmute_led_set(int state)
 50{
 51	struct calling_interface_buffer *buffer;
 52	struct calling_interface_token *token;
 53
 54	if (!wmi_has_guid(DELL_APP_GUID))
 55		return -ENODEV;
 56
 57	if (state == 0)
 58		token = dell_smbios_find_token(GLOBAL_MIC_MUTE_DISABLE);
 59	else if (state == 1)
 60		token = dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE);
 61	else
 62		return -EINVAL;
 63
 64	if (!token)
 65		return -ENODEV;
 66
 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();
 72
 73	return state;
 74}
 75
 76int dell_app_wmi_led_set(int whichled, int on)
 77{
 78	int state = 0;
 79
 80	switch (whichled) {
 81	case DELL_LED_MICMUTE:
 82		state = dell_micmute_led_set(on);
 83		break;
 84	default:
 85		pr_warn("led type %x is not supported\n", whichled);
 86		break;
 87	}
 88
 89	return state;
 90}
 91EXPORT_SYMBOL_GPL(dell_app_wmi_led_set);
 92
 93struct bios_args {
 94	unsigned char length;
 95	unsigned char result_code;
 96	unsigned char device_id;
 97	unsigned char command;
 98	unsigned char on_time;
 99	unsigned char off_time;
100};
101
102static int dell_led_perform_fn(u8 length,
103		u8 result_code,
104		u8 device_id,
105		u8 command,
106		u8 on_time,
107		u8 off_time)
108{
109	struct bios_args *bios_return;
110	u8 return_code;
111	union acpi_object *obj;
112	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
113	struct acpi_buffer input;
114	acpi_status status;
115
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;
123
124	input.length = sizeof(struct bios_args);
125	input.pointer = &args;
126
127	status = wmi_evaluate_method(DELL_LED_BIOS_GUID,
128		1,
129		1,
130		&input,
131		&output);
132
133	if (ACPI_FAILURE(status))
134		return status;
135
136	obj = output.pointer;
137
138	if (!obj)
139		return -EINVAL;
140	else if (obj->type != ACPI_TYPE_BUFFER) {
141		kfree(obj);
142		return -EINVAL;
143	}
144
145	bios_return = ((struct bios_args *)obj->buffer.pointer);
146	return_code = bios_return->result_code;
147
148	kfree(obj);
149
150	return return_code;
151}
152
153static int led_on(void)
154{
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 */
159		0,			/* not used */
160		0);			/* not used */
161}
162
163static int led_off(void)
164{
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 */
169		0,			/* not used */
170		0);			/* not used */
171}
172
173static int led_blink(unsigned char on_eighths,
174		unsigned char off_eighths)
175{
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 */
182}
183
184static void dell_led_set(struct led_classdev *led_cdev,
185		enum led_brightness value)
186{
187	if (value == LED_OFF)
188		led_off();
189	else
190		led_on();
191}
192
193static int dell_led_blink(struct led_classdev *led_cdev,
194		unsigned long *delay_on,
195		unsigned long *delay_off)
196{
197	unsigned long on_eighths;
198	unsigned long off_eighths;
199
200	/* The Dell LED delay is based on 125ms intervals.
201	   Need to round up to next interval. */
202
203	on_eighths = (*delay_on + 124) / 125;
204	if (0 == on_eighths)
205		on_eighths = 1;
206	if (on_eighths > 255)
207		on_eighths = 255;
208	*delay_on = on_eighths * 125;
209
210	off_eighths = (*delay_off + 124) / 125;
211	if (0 == off_eighths)
212		off_eighths = 1;
213	if (off_eighths > 255)
214		off_eighths = 255;
215	*delay_off = off_eighths * 125;
216
217	led_blink(on_eighths, off_eighths);
218
219	return 0;
220}
221
222static struct led_classdev dell_led = {
223	.name		= "dell::lid",
224	.brightness	= LED_OFF,
225	.max_brightness = 1,
226	.brightness_set = dell_led_set,
227	.blink_set	= dell_led_blink,
228	.flags		= LED_CORE_SUSPENDRESUME,
229};
230
231static int __init dell_led_init(void)
232{
233	int error = 0;
234
235	if (!wmi_has_guid(DELL_LED_BIOS_GUID) && !wmi_has_guid(DELL_APP_GUID))
236		return -ENODEV;
237
238	if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
239		error = led_off();
240		if (error != 0)
241			return -ENODEV;
242
243		error = led_classdev_register(NULL, &dell_led);
244	}
245
246	return error;
247}
248
249static void __exit dell_led_exit(void)
250{
251	int error = 0;
252
253	if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
254		error = led_off();
255		if (error == 0)
256			led_classdev_unregister(&dell_led);
257	}
258}
259
260module_init(dell_led_init);
261module_exit(dell_led_exit);
v3.5.6
  1/*
  2 * dell_led.c - Dell LED Driver
  3 *
  4 * Copyright (C) 2010 Dell Inc.
  5 * Louis Davis <louis_davis@dell.com>
  6 * Jim Dailey <jim_dailey@dell.com>
  7 *
  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.
 11 *
 12 */
 13
 14#include <linux/acpi.h>
 15#include <linux/leds.h>
 16#include <linux/slab.h>
 17#include <linux/module.h>
 
 
 
 18
 19MODULE_AUTHOR("Louis Davis/Jim Dailey");
 20MODULE_DESCRIPTION("Dell LED Control Driver");
 21MODULE_LICENSE("GPL");
 22
 23#define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
 
 24MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
 25
 26/* Error Result Codes: */
 27#define INVALID_DEVICE_ID	250
 28#define INVALID_PARAMETER	251
 29#define INVALID_BUFFER		252
 30#define INTERFACE_ERROR		253
 31#define UNSUPPORTED_COMMAND	254
 32#define UNSPECIFIED_ERROR	255
 33
 34/* Device ID */
 35#define DEVICE_ID_PANEL_BACK	1
 36
 37/* LED Commands */
 38#define CMD_LED_ON	16
 39#define CMD_LED_OFF	17
 40#define CMD_LED_BLINK	18
 41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 42struct bios_args {
 43	unsigned char length;
 44	unsigned char result_code;
 45	unsigned char device_id;
 46	unsigned char command;
 47	unsigned char on_time;
 48	unsigned char off_time;
 49};
 50
 51static int dell_led_perform_fn(u8 length,
 52		u8 result_code,
 53		u8 device_id,
 54		u8 command,
 55		u8 on_time,
 56		u8 off_time)
 57{
 58	struct bios_args *bios_return;
 59	u8 return_code;
 60	union acpi_object *obj;
 61	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
 62	struct acpi_buffer input;
 63	acpi_status status;
 64
 65	struct bios_args args;
 66	args.length = length;
 67	args.result_code = result_code;
 68	args.device_id = device_id;
 69	args.command = command;
 70	args.on_time = on_time;
 71	args.off_time = off_time;
 72
 73	input.length = sizeof(struct bios_args);
 74	input.pointer = &args;
 75
 76	status = wmi_evaluate_method(DELL_LED_BIOS_GUID,
 77		1,
 78		1,
 79		&input,
 80		&output);
 81
 82	if (ACPI_FAILURE(status))
 83		return status;
 84
 85	obj = output.pointer;
 86
 87	if (!obj)
 88		return -EINVAL;
 89	else if (obj->type != ACPI_TYPE_BUFFER) {
 90		kfree(obj);
 91		return -EINVAL;
 92	}
 93
 94	bios_return = ((struct bios_args *)obj->buffer.pointer);
 95	return_code = bios_return->result_code;
 96
 97	kfree(obj);
 98
 99	return return_code;
100}
101
102static int led_on(void)
103{
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_ON,		/* Command */
108		0,			/* not used */
109		0);			/* not used */
110}
111
112static int led_off(void)
113{
114	return dell_led_perform_fn(3,	/* Length of command */
115		INTERFACE_ERROR,	/* Init to  INTERFACE_ERROR */
116		DEVICE_ID_PANEL_BACK,	/* Device ID */
117		CMD_LED_OFF,		/* Command */
118		0,			/* not used */
119		0);			/* not used */
120}
121
122static int led_blink(unsigned char on_eighths,
123		unsigned char off_eighths)
124{
125	return dell_led_perform_fn(5,	/* Length of command */
126		INTERFACE_ERROR,	/* Init to  INTERFACE_ERROR */
127		DEVICE_ID_PANEL_BACK,	/* Device ID */
128		CMD_LED_BLINK,		/* Command */
129		on_eighths,		/* blink on in eigths of a second */
130		off_eighths);		/* blink off in eights of a second */
131}
132
133static void dell_led_set(struct led_classdev *led_cdev,
134		enum led_brightness value)
135{
136	if (value == LED_OFF)
137		led_off();
138	else
139		led_on();
140}
141
142static int dell_led_blink(struct led_classdev *led_cdev,
143		unsigned long *delay_on,
144		unsigned long *delay_off)
145{
146	unsigned long on_eighths;
147	unsigned long off_eighths;
148
149	/* The Dell LED delay is based on 125ms intervals.
150	   Need to round up to next interval. */
151
152	on_eighths = (*delay_on + 124) / 125;
153	if (0 == on_eighths)
154		on_eighths = 1;
155	if (on_eighths > 255)
156		on_eighths = 255;
157	*delay_on = on_eighths * 125;
158
159	off_eighths = (*delay_off + 124) / 125;
160	if (0 == off_eighths)
161		off_eighths = 1;
162	if (off_eighths > 255)
163		off_eighths = 255;
164	*delay_off = off_eighths * 125;
165
166	led_blink(on_eighths, off_eighths);
167
168	return 0;
169}
170
171static struct led_classdev dell_led = {
172	.name		= "dell::lid",
173	.brightness	= LED_OFF,
174	.max_brightness = 1,
175	.brightness_set = dell_led_set,
176	.blink_set	= dell_led_blink,
177	.flags		= LED_CORE_SUSPENDRESUME,
178};
179
180static int __init dell_led_init(void)
181{
182	int error = 0;
183
184	if (!wmi_has_guid(DELL_LED_BIOS_GUID))
185		return -ENODEV;
186
187	error = led_off();
188	if (error != 0)
189		return -ENODEV;
 
 
 
 
190
191	return led_classdev_register(NULL, &dell_led);
192}
193
194static void __exit dell_led_exit(void)
195{
196	led_classdev_unregister(&dell_led);
197
198	led_off();
 
 
 
 
199}
200
201module_init(dell_led_init);
202module_exit(dell_led_exit);