[Trusty] dell-led: add mic mute led interface
diff mbox

Message ID 1397612766-9728-1-git-send-email-hui.wang@canonical.com
State New
Headers show

Commit Message

Hui Wang April 16, 2014, 1:46 a.m. UTC
From: Alex Hung <alex.hung@canonical.com>

BugLink: http://bugs.launchpad.net/bugs/1308297

commit de8021d313eb0dd4aab3cb4cad3224703970be1b of linux-leds

This patch provides similar led functional of

  420f973 thinkpad-acpi: Add mute and mic-mute LED functionality

Signed-off-by: Alex Hung <alex.hung@canonical.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
Signed-off-by: Hui Wang <hui.wang@canonical.com>
---
This patch has already been accepted by linux-leds repository and is
going to be merged by upstream linux-3.16. But we have an OEM preload
project to ask for this feature, so I try to backport it to ubuntu
kernel before it shows up in the upstream.

 drivers/leds/dell-led.c  | 171 +++++++++++++++++++++++++++++++++++++++++++++--
 include/linux/dell-led.h |  10 +++
 2 files changed, 174 insertions(+), 7 deletions(-)
 create mode 100644 include/linux/dell-led.h

Comments

Brad Figg April 16, 2014, 2:32 a.m. UTC | #1
You have an OEM project that requires this in both Saucy and Trusty?

Brad

On 04/15/2014 06:46 PM, Hui Wang wrote:
> From: Alex Hung <alex.hung@canonical.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1308297
> 
> commit de8021d313eb0dd4aab3cb4cad3224703970be1b of linux-leds
> 
> This patch provides similar led functional of
> 
>   420f973 thinkpad-acpi: Add mute and mic-mute LED functionality
> 
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> Signed-off-by: Bryan Wu <cooloney@gmail.com>
> Signed-off-by: Hui Wang <hui.wang@canonical.com>
> ---
> This patch has already been accepted by linux-leds repository and is
> going to be merged by upstream linux-3.16. But we have an OEM preload
> project to ask for this feature, so I try to backport it to ubuntu
> kernel before it shows up in the upstream.
> 
>  drivers/leds/dell-led.c  | 171 +++++++++++++++++++++++++++++++++++++++++++++--
>  include/linux/dell-led.h |  10 +++
>  2 files changed, 174 insertions(+), 7 deletions(-)
>  create mode 100644 include/linux/dell-led.h
> 
> diff --git a/drivers/leds/dell-led.c b/drivers/leds/dell-led.c
> index e5c5738..c36acaf 100644
> --- a/drivers/leds/dell-led.c
> +++ b/drivers/leds/dell-led.c
> @@ -15,12 +15,15 @@
>  #include <linux/leds.h>
>  #include <linux/slab.h>
>  #include <linux/module.h>
> +#include <linux/dmi.h>
> +#include <linux/dell-led.h>
>  
>  MODULE_AUTHOR("Louis Davis/Jim Dailey");
>  MODULE_DESCRIPTION("Dell LED Control Driver");
>  MODULE_LICENSE("GPL");
>  
>  #define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
> +#define DELL_APP_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
>  MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
>  
>  /* Error Result Codes: */
> @@ -39,6 +42,149 @@ MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
>  #define CMD_LED_OFF	17
>  #define CMD_LED_BLINK	18
>  
> +struct app_wmi_args {
> +	u16 class;
> +	u16 selector;
> +	u32 arg1;
> +	u32 arg2;
> +	u32 arg3;
> +	u32 arg4;
> +	u32 res1;
> +	u32 res2;
> +	u32 res3;
> +	u32 res4;
> +	char dummy[92];
> +};
> +
> +#define GLOBAL_MIC_MUTE_ENABLE	0x364
> +#define GLOBAL_MIC_MUTE_DISABLE	0x365
> +
> +struct dell_bios_data_token {
> +	u16 tokenid;
> +	u16 location;
> +	u16 value;
> +};
> +
> +struct __attribute__ ((__packed__)) dell_bios_calling_interface {
> +	struct	dmi_header header;
> +	u16	cmd_io_addr;
> +	u8	cmd_io_code;
> +	u32	supported_cmds;
> +	struct	dell_bios_data_token damap[];
> +};
> +
> +static struct dell_bios_data_token dell_mic_tokens[2];
> +
> +static int dell_wmi_perform_query(struct app_wmi_args *args)
> +{
> +	struct app_wmi_args *bios_return;
> +	union acpi_object *obj;
> +	struct acpi_buffer input;
> +	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
> +	acpi_status status;
> +	u32 rc = -EINVAL;
> +
> +	input.length = 128;
> +	input.pointer = args;
> +
> +	status = wmi_evaluate_method(DELL_APP_GUID, 0, 1, &input, &output);
> +	if (!ACPI_SUCCESS(status))
> +		goto err_out0;
> +
> +	obj = output.pointer;
> +	if (!obj)
> +		goto err_out0;
> +
> +	if (obj->type != ACPI_TYPE_BUFFER)
> +		goto err_out1;
> +
> +	bios_return = (struct app_wmi_args *)obj->buffer.pointer;
> +	rc = bios_return->res1;
> +	if (rc)
> +		goto err_out1;
> +
> +	memcpy(args, bios_return, sizeof(struct app_wmi_args));
> +	rc = 0;
> +
> + err_out1:
> +	kfree(obj);
> + err_out0:
> +	return rc;
> +}
> +
> +static void __init find_micmute_tokens(const struct dmi_header *dm, void *dummy)
> +{
> +	struct dell_bios_calling_interface *calling_interface;
> +	struct dell_bios_data_token *token;
> +	int token_size = sizeof(struct dell_bios_data_token);
> +	int i = 0;
> +
> +	if (dm->type == 0xda && dm->length > 17) {
> +		calling_interface = container_of(dm,
> +				struct dell_bios_calling_interface, header);
> +
> +		token = &calling_interface->damap[i];
> +		while (token->tokenid != 0xffff) {
> +			if (token->tokenid == GLOBAL_MIC_MUTE_DISABLE)
> +				memcpy(&dell_mic_tokens[0], token, token_size);
> +			else if (token->tokenid == GLOBAL_MIC_MUTE_ENABLE)
> +				memcpy(&dell_mic_tokens[1], token, token_size);
> +
> +			i++;
> +			token = &calling_interface->damap[i];
> +		}
> +	}
> +}
> +
> +static int dell_micmute_led_set(int state)
> +{
> +	struct app_wmi_args args;
> +	struct dell_bios_data_token *token;
> +
> +	if (!wmi_has_guid(DELL_APP_GUID))
> +		return -ENODEV;
> +
> +	if (state == 0 || state == 1)
> +		token = &dell_mic_tokens[state];
> +	else
> +		return -EINVAL;
> +
> +	memset(&args, 0, sizeof(struct app_wmi_args));
> +
> +	args.class = 1;
> +	args.arg1 = token->location;
> +	args.arg2 = token->value;
> +
> +	dell_wmi_perform_query(&args);
> +
> +	return state;
> +}
> +
> +int dell_app_wmi_led_set(int whichled, int on)
> +{
> +	int state = 0;
> +
> +	switch (whichled) {
> +	case DELL_LED_MICMUTE:
> +		state = dell_micmute_led_set(on);
> +		break;
> +	default:
> +		pr_warn("led type %x is not supported\n", whichled);
> +		break;
> +	}
> +
> +	return state;
> +}
> +EXPORT_SYMBOL_GPL(dell_app_wmi_led_set);
> +
> +static int __init dell_micmute_led_init(void)
> +{
> +	memset(dell_mic_tokens, 0, sizeof(struct dell_bios_data_token) * 2);
> +	dmi_walk(find_micmute_tokens, NULL);
> +
> +	return 0;
> +}
> +
>  struct bios_args {
>  	unsigned char length;
>  	unsigned char result_code;
> @@ -181,21 +327,32 @@ static int __init dell_led_init(void)
>  {
>  	int error = 0;
>  
> -	if (!wmi_has_guid(DELL_LED_BIOS_GUID))
> +	if (!wmi_has_guid(DELL_LED_BIOS_GUID) && !wmi_has_guid(DELL_APP_GUID))
>  		return -ENODEV;
>  
> -	error = led_off();
> -	if (error != 0)
> -		return -ENODEV;
> +	if (wmi_has_guid(DELL_APP_GUID))
> +		error = dell_micmute_led_init();
>  
> -	return led_classdev_register(NULL, &dell_led);
> +	if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
> +		error = led_off();
> +		if (error != 0)
> +			return -ENODEV;
> +
> +		error = led_classdev_register(NULL, &dell_led);
> +	}
> +
> +	return error;
>  }
>  
>  static void __exit dell_led_exit(void)
>  {
> -	led_classdev_unregister(&dell_led);
> +	int error = 0;
>  
> -	led_off();
> +	if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
> +		error = led_off();
> +		if (error == 0)
> +			led_classdev_unregister(&dell_led);
> +	}
>  }
>  
>  module_init(dell_led_init);
> diff --git a/include/linux/dell-led.h b/include/linux/dell-led.h
> new file mode 100644
> index 0000000..7009b8b
> --- /dev/null
> +++ b/include/linux/dell-led.h
> @@ -0,0 +1,10 @@
> +#ifndef __DELL_LED_H__
> +#define __DELL_LED_H__
> +
> +enum {
> +	DELL_LED_MICMUTE,
> +};
> +
> +int dell_app_wmi_led_set(int whichled, int on);
> +
> +#endif
>
Hui Wang April 16, 2014, 3:10 a.m. UTC | #2
On 04/16/2014 10:32 AM, Brad Figg wrote:
> You have an OEM project that requires this in both Saucy and Trusty?
So far, the Trusty needs it.

Thanks,
Hui.
>
> Brad
>
> On 04/15/2014 06:46 PM, Hui Wang wrote:
>> From: Alex Hung <alex.hung@canonical.com>
>>
>> BugLink: http://bugs.launchpad.net/bugs/1308297
>>
>> commit de8021d313eb0dd4aab3cb4cad3224703970be1b of linux-leds
>>
>> This patch provides similar led functional of
>>
>>    420f973 thinkpad-acpi: Add mute and mic-mute LED functionality
>>
>> Signed-off-by: Alex Hung <alex.hung@canonical.com>
>> Signed-off-by: Bryan Wu <cooloney@gmail.com>
>> Signed-off-by: Hui Wang <hui.wang@canonical.com>
>> ---
>> This patch has already been accepted by linux-leds repository and is
>> going to be merged by upstream linux-3.16. But we have an OEM preload
>> project to ask for this feature, so I try to backport it to ubuntu
>> kernel before it shows up in the upstream.
>>
>>   drivers/leds/dell-led.c  | 171 +++++++++++++++++++++++++++++++++++++++++++++--
>>   include/linux/dell-led.h |  10 +++
>>   2 files changed, 174 insertions(+), 7 deletions(-)
>>   create mode 100644 include/linux/dell-led.h
>>
>> diff --git a/drivers/leds/dell-led.c b/drivers/leds/dell-led.c
>> index e5c5738..c36acaf 100644
>> --- a/drivers/leds/dell-led.c
>> +++ b/drivers/leds/dell-led.c
>> @@ -15,12 +15,15 @@
>>   #include <linux/leds.h>
>>   #include <linux/slab.h>
>>   #include <linux/module.h>
>> +#include <linux/dmi.h>
>> +#include <linux/dell-led.h>
>>   
>>   MODULE_AUTHOR("Louis Davis/Jim Dailey");
>>   MODULE_DESCRIPTION("Dell LED Control Driver");
>>   MODULE_LICENSE("GPL");
>>   
>>   #define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
>> +#define DELL_APP_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
>>   MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
>>   
>>   /* Error Result Codes: */
>> @@ -39,6 +42,149 @@ MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
>>   #define CMD_LED_OFF	17
>>   #define CMD_LED_BLINK	18
>>   
>> +struct app_wmi_args {
>> +	u16 class;
>> +	u16 selector;
>> +	u32 arg1;
>> +	u32 arg2;
>> +	u32 arg3;
>> +	u32 arg4;
>> +	u32 res1;
>> +	u32 res2;
>> +	u32 res3;
>> +	u32 res4;
>> +	char dummy[92];
>> +};
>> +
>> +#define GLOBAL_MIC_MUTE_ENABLE	0x364
>> +#define GLOBAL_MIC_MUTE_DISABLE	0x365
>> +
>> +struct dell_bios_data_token {
>> +	u16 tokenid;
>> +	u16 location;
>> +	u16 value;
>> +};
>> +
>> +struct __attribute__ ((__packed__)) dell_bios_calling_interface {
>> +	struct	dmi_header header;
>> +	u16	cmd_io_addr;
>> +	u8	cmd_io_code;
>> +	u32	supported_cmds;
>> +	struct	dell_bios_data_token damap[];
>> +};
>> +
>> +static struct dell_bios_data_token dell_mic_tokens[2];
>> +
>> +static int dell_wmi_perform_query(struct app_wmi_args *args)
>> +{
>> +	struct app_wmi_args *bios_return;
>> +	union acpi_object *obj;
>> +	struct acpi_buffer input;
>> +	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
>> +	acpi_status status;
>> +	u32 rc = -EINVAL;
>> +
>> +	input.length = 128;
>> +	input.pointer = args;
>> +
>> +	status = wmi_evaluate_method(DELL_APP_GUID, 0, 1, &input, &output);
>> +	if (!ACPI_SUCCESS(status))
>> +		goto err_out0;
>> +
>> +	obj = output.pointer;
>> +	if (!obj)
>> +		goto err_out0;
>> +
>> +	if (obj->type != ACPI_TYPE_BUFFER)
>> +		goto err_out1;
>> +
>> +	bios_return = (struct app_wmi_args *)obj->buffer.pointer;
>> +	rc = bios_return->res1;
>> +	if (rc)
>> +		goto err_out1;
>> +
>> +	memcpy(args, bios_return, sizeof(struct app_wmi_args));
>> +	rc = 0;
>> +
>> + err_out1:
>> +	kfree(obj);
>> + err_out0:
>> +	return rc;
>> +}
>> +
>> +static void __init find_micmute_tokens(const struct dmi_header *dm, void *dummy)
>> +{
>> +	struct dell_bios_calling_interface *calling_interface;
>> +	struct dell_bios_data_token *token;
>> +	int token_size = sizeof(struct dell_bios_data_token);
>> +	int i = 0;
>> +
>> +	if (dm->type == 0xda && dm->length > 17) {
>> +		calling_interface = container_of(dm,
>> +				struct dell_bios_calling_interface, header);
>> +
>> +		token = &calling_interface->damap[i];
>> +		while (token->tokenid != 0xffff) {
>> +			if (token->tokenid == GLOBAL_MIC_MUTE_DISABLE)
>> +				memcpy(&dell_mic_tokens[0], token, token_size);
>> +			else if (token->tokenid == GLOBAL_MIC_MUTE_ENABLE)
>> +				memcpy(&dell_mic_tokens[1], token, token_size);
>> +
>> +			i++;
>> +			token = &calling_interface->damap[i];
>> +		}
>> +	}
>> +}
>> +
>> +static int dell_micmute_led_set(int state)
>> +{
>> +	struct app_wmi_args args;
>> +	struct dell_bios_data_token *token;
>> +
>> +	if (!wmi_has_guid(DELL_APP_GUID))
>> +		return -ENODEV;
>> +
>> +	if (state == 0 || state == 1)
>> +		token = &dell_mic_tokens[state];
>> +	else
>> +		return -EINVAL;
>> +
>> +	memset(&args, 0, sizeof(struct app_wmi_args));
>> +
>> +	args.class = 1;
>> +	args.arg1 = token->location;
>> +	args.arg2 = token->value;
>> +
>> +	dell_wmi_perform_query(&args);
>> +
>> +	return state;
>> +}
>> +
>> +int dell_app_wmi_led_set(int whichled, int on)
>> +{
>> +	int state = 0;
>> +
>> +	switch (whichled) {
>> +	case DELL_LED_MICMUTE:
>> +		state = dell_micmute_led_set(on);
>> +		break;
>> +	default:
>> +		pr_warn("led type %x is not supported\n", whichled);
>> +		break;
>> +	}
>> +
>> +	return state;
>> +}
>> +EXPORT_SYMBOL_GPL(dell_app_wmi_led_set);
>> +
>> +static int __init dell_micmute_led_init(void)
>> +{
>> +	memset(dell_mic_tokens, 0, sizeof(struct dell_bios_data_token) * 2);
>> +	dmi_walk(find_micmute_tokens, NULL);
>> +
>> +	return 0;
>> +}
>> +
>>   struct bios_args {
>>   	unsigned char length;
>>   	unsigned char result_code;
>> @@ -181,21 +327,32 @@ static int __init dell_led_init(void)
>>   {
>>   	int error = 0;
>>   
>> -	if (!wmi_has_guid(DELL_LED_BIOS_GUID))
>> +	if (!wmi_has_guid(DELL_LED_BIOS_GUID) && !wmi_has_guid(DELL_APP_GUID))
>>   		return -ENODEV;
>>   
>> -	error = led_off();
>> -	if (error != 0)
>> -		return -ENODEV;
>> +	if (wmi_has_guid(DELL_APP_GUID))
>> +		error = dell_micmute_led_init();
>>   
>> -	return led_classdev_register(NULL, &dell_led);
>> +	if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
>> +		error = led_off();
>> +		if (error != 0)
>> +			return -ENODEV;
>> +
>> +		error = led_classdev_register(NULL, &dell_led);
>> +	}
>> +
>> +	return error;
>>   }
>>   
>>   static void __exit dell_led_exit(void)
>>   {
>> -	led_classdev_unregister(&dell_led);
>> +	int error = 0;
>>   
>> -	led_off();
>> +	if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
>> +		error = led_off();
>> +		if (error == 0)
>> +			led_classdev_unregister(&dell_led);
>> +	}
>>   }
>>   
>>   module_init(dell_led_init);
>> diff --git a/include/linux/dell-led.h b/include/linux/dell-led.h
>> new file mode 100644
>> index 0000000..7009b8b
>> --- /dev/null
>> +++ b/include/linux/dell-led.h
>> @@ -0,0 +1,10 @@
>> +#ifndef __DELL_LED_H__
>> +#define __DELL_LED_H__
>> +
>> +enum {
>> +	DELL_LED_MICMUTE,
>> +};
>> +
>> +int dell_app_wmi_led_set(int whichled, int on);
>> +
>> +#endif
>>
>
Tim Gardner April 16, 2014, 1:01 p.m. UTC | #3
A clean cherry-pick from linux-next.
Brad Figg April 16, 2014, 2:23 p.m. UTC | #4
On 04/15/2014 06:46 PM, Hui Wang wrote:
> From: Alex Hung <alex.hung@canonical.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1308297
> 
> commit de8021d313eb0dd4aab3cb4cad3224703970be1b of linux-leds
> 
> This patch provides similar led functional of
> 
>   420f973 thinkpad-acpi: Add mute and mic-mute LED functionality
> 
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> Signed-off-by: Bryan Wu <cooloney@gmail.com>
> Signed-off-by: Hui Wang <hui.wang@canonical.com>
> ---
> This patch has already been accepted by linux-leds repository and is
> going to be merged by upstream linux-3.16. But we have an OEM preload
> project to ask for this feature, so I try to backport it to ubuntu
> kernel before it shows up in the upstream.
> 
>  drivers/leds/dell-led.c  | 171 +++++++++++++++++++++++++++++++++++++++++++++--
>  include/linux/dell-led.h |  10 +++
>  2 files changed, 174 insertions(+), 7 deletions(-)
>  create mode 100644 include/linux/dell-led.h
> 
> diff --git a/drivers/leds/dell-led.c b/drivers/leds/dell-led.c
> index e5c5738..c36acaf 100644
> --- a/drivers/leds/dell-led.c
> +++ b/drivers/leds/dell-led.c
> @@ -15,12 +15,15 @@
>  #include <linux/leds.h>
>  #include <linux/slab.h>
>  #include <linux/module.h>
> +#include <linux/dmi.h>
> +#include <linux/dell-led.h>
>  
>  MODULE_AUTHOR("Louis Davis/Jim Dailey");
>  MODULE_DESCRIPTION("Dell LED Control Driver");
>  MODULE_LICENSE("GPL");
>  
>  #define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
> +#define DELL_APP_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
>  MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
>  
>  /* Error Result Codes: */
> @@ -39,6 +42,149 @@ MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
>  #define CMD_LED_OFF	17
>  #define CMD_LED_BLINK	18
>  
> +struct app_wmi_args {
> +	u16 class;
> +	u16 selector;
> +	u32 arg1;
> +	u32 arg2;
> +	u32 arg3;
> +	u32 arg4;
> +	u32 res1;
> +	u32 res2;
> +	u32 res3;
> +	u32 res4;
> +	char dummy[92];
> +};
> +
> +#define GLOBAL_MIC_MUTE_ENABLE	0x364
> +#define GLOBAL_MIC_MUTE_DISABLE	0x365
> +
> +struct dell_bios_data_token {
> +	u16 tokenid;
> +	u16 location;
> +	u16 value;
> +};
> +
> +struct __attribute__ ((__packed__)) dell_bios_calling_interface {
> +	struct	dmi_header header;
> +	u16	cmd_io_addr;
> +	u8	cmd_io_code;
> +	u32	supported_cmds;
> +	struct	dell_bios_data_token damap[];
> +};
> +
> +static struct dell_bios_data_token dell_mic_tokens[2];
> +
> +static int dell_wmi_perform_query(struct app_wmi_args *args)
> +{
> +	struct app_wmi_args *bios_return;
> +	union acpi_object *obj;
> +	struct acpi_buffer input;
> +	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
> +	acpi_status status;
> +	u32 rc = -EINVAL;
> +
> +	input.length = 128;
> +	input.pointer = args;
> +
> +	status = wmi_evaluate_method(DELL_APP_GUID, 0, 1, &input, &output);
> +	if (!ACPI_SUCCESS(status))
> +		goto err_out0;
> +
> +	obj = output.pointer;
> +	if (!obj)
> +		goto err_out0;
> +
> +	if (obj->type != ACPI_TYPE_BUFFER)
> +		goto err_out1;
> +
> +	bios_return = (struct app_wmi_args *)obj->buffer.pointer;
> +	rc = bios_return->res1;
> +	if (rc)
> +		goto err_out1;
> +
> +	memcpy(args, bios_return, sizeof(struct app_wmi_args));
> +	rc = 0;
> +
> + err_out1:
> +	kfree(obj);
> + err_out0:
> +	return rc;
> +}
> +
> +static void __init find_micmute_tokens(const struct dmi_header *dm, void *dummy)
> +{
> +	struct dell_bios_calling_interface *calling_interface;
> +	struct dell_bios_data_token *token;
> +	int token_size = sizeof(struct dell_bios_data_token);
> +	int i = 0;
> +
> +	if (dm->type == 0xda && dm->length > 17) {
> +		calling_interface = container_of(dm,
> +				struct dell_bios_calling_interface, header);
> +
> +		token = &calling_interface->damap[i];
> +		while (token->tokenid != 0xffff) {
> +			if (token->tokenid == GLOBAL_MIC_MUTE_DISABLE)
> +				memcpy(&dell_mic_tokens[0], token, token_size);
> +			else if (token->tokenid == GLOBAL_MIC_MUTE_ENABLE)
> +				memcpy(&dell_mic_tokens[1], token, token_size);
> +
> +			i++;
> +			token = &calling_interface->damap[i];
> +		}
> +	}
> +}
> +
> +static int dell_micmute_led_set(int state)
> +{
> +	struct app_wmi_args args;
> +	struct dell_bios_data_token *token;
> +
> +	if (!wmi_has_guid(DELL_APP_GUID))
> +		return -ENODEV;
> +
> +	if (state == 0 || state == 1)
> +		token = &dell_mic_tokens[state];
> +	else
> +		return -EINVAL;
> +
> +	memset(&args, 0, sizeof(struct app_wmi_args));
> +
> +	args.class = 1;
> +	args.arg1 = token->location;
> +	args.arg2 = token->value;
> +
> +	dell_wmi_perform_query(&args);
> +
> +	return state;
> +}
> +
> +int dell_app_wmi_led_set(int whichled, int on)
> +{
> +	int state = 0;
> +
> +	switch (whichled) {
> +	case DELL_LED_MICMUTE:
> +		state = dell_micmute_led_set(on);
> +		break;
> +	default:
> +		pr_warn("led type %x is not supported\n", whichled);
> +		break;
> +	}
> +
> +	return state;
> +}
> +EXPORT_SYMBOL_GPL(dell_app_wmi_led_set);
> +
> +static int __init dell_micmute_led_init(void)
> +{
> +	memset(dell_mic_tokens, 0, sizeof(struct dell_bios_data_token) * 2);
> +	dmi_walk(find_micmute_tokens, NULL);
> +
> +	return 0;
> +}
> +
>  struct bios_args {
>  	unsigned char length;
>  	unsigned char result_code;
> @@ -181,21 +327,32 @@ static int __init dell_led_init(void)
>  {
>  	int error = 0;
>  
> -	if (!wmi_has_guid(DELL_LED_BIOS_GUID))
> +	if (!wmi_has_guid(DELL_LED_BIOS_GUID) && !wmi_has_guid(DELL_APP_GUID))
>  		return -ENODEV;
>  
> -	error = led_off();
> -	if (error != 0)
> -		return -ENODEV;
> +	if (wmi_has_guid(DELL_APP_GUID))
> +		error = dell_micmute_led_init();
>  
> -	return led_classdev_register(NULL, &dell_led);
> +	if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
> +		error = led_off();
> +		if (error != 0)
> +			return -ENODEV;
> +
> +		error = led_classdev_register(NULL, &dell_led);
> +	}
> +
> +	return error;
>  }
>  
>  static void __exit dell_led_exit(void)
>  {
> -	led_classdev_unregister(&dell_led);
> +	int error = 0;
>  
> -	led_off();
> +	if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
> +		error = led_off();
> +		if (error == 0)
> +			led_classdev_unregister(&dell_led);
> +	}
>  }
>  
>  module_init(dell_led_init);
> diff --git a/include/linux/dell-led.h b/include/linux/dell-led.h
> new file mode 100644
> index 0000000..7009b8b
> --- /dev/null
> +++ b/include/linux/dell-led.h
> @@ -0,0 +1,10 @@
> +#ifndef __DELL_LED_H__
> +#define __DELL_LED_H__
> +
> +enum {
> +	DELL_LED_MICMUTE,
> +};
> +
> +int dell_app_wmi_led_set(int whichled, int on);
> +
> +#endif
>
Tim Gardner April 17, 2014, 2:12 p.m. UTC | #5
Trusty only
Hui Wang April 18, 2014, 1:25 a.m. UTC | #6
On 04/17/2014 10:12 PM, Tim Gardner wrote:
> Trusty only
>
  Got it, thanks.

Patch
diff mbox

diff --git a/drivers/leds/dell-led.c b/drivers/leds/dell-led.c
index e5c5738..c36acaf 100644
--- a/drivers/leds/dell-led.c
+++ b/drivers/leds/dell-led.c
@@ -15,12 +15,15 @@ 
 #include <linux/leds.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/dmi.h>
+#include <linux/dell-led.h>
 
 MODULE_AUTHOR("Louis Davis/Jim Dailey");
 MODULE_DESCRIPTION("Dell LED Control Driver");
 MODULE_LICENSE("GPL");
 
 #define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
+#define DELL_APP_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
 MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
 
 /* Error Result Codes: */
@@ -39,6 +42,149 @@  MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
 #define CMD_LED_OFF	17
 #define CMD_LED_BLINK	18
 
+struct app_wmi_args {
+	u16 class;
+	u16 selector;
+	u32 arg1;
+	u32 arg2;
+	u32 arg3;
+	u32 arg4;
+	u32 res1;
+	u32 res2;
+	u32 res3;
+	u32 res4;
+	char dummy[92];
+};
+
+#define GLOBAL_MIC_MUTE_ENABLE	0x364
+#define GLOBAL_MIC_MUTE_DISABLE	0x365
+
+struct dell_bios_data_token {
+	u16 tokenid;
+	u16 location;
+	u16 value;
+};
+
+struct __attribute__ ((__packed__)) dell_bios_calling_interface {
+	struct	dmi_header header;
+	u16	cmd_io_addr;
+	u8	cmd_io_code;
+	u32	supported_cmds;
+	struct	dell_bios_data_token damap[];
+};
+
+static struct dell_bios_data_token dell_mic_tokens[2];
+
+static int dell_wmi_perform_query(struct app_wmi_args *args)
+{
+	struct app_wmi_args *bios_return;
+	union acpi_object *obj;
+	struct acpi_buffer input;
+	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
+	acpi_status status;
+	u32 rc = -EINVAL;
+
+	input.length = 128;
+	input.pointer = args;
+
+	status = wmi_evaluate_method(DELL_APP_GUID, 0, 1, &input, &output);
+	if (!ACPI_SUCCESS(status))
+		goto err_out0;
+
+	obj = output.pointer;
+	if (!obj)
+		goto err_out0;
+
+	if (obj->type != ACPI_TYPE_BUFFER)
+		goto err_out1;
+
+	bios_return = (struct app_wmi_args *)obj->buffer.pointer;
+	rc = bios_return->res1;
+	if (rc)
+		goto err_out1;
+
+	memcpy(args, bios_return, sizeof(struct app_wmi_args));
+	rc = 0;
+
+ err_out1:
+	kfree(obj);
+ err_out0:
+	return rc;
+}
+
+static void __init find_micmute_tokens(const struct dmi_header *dm, void *dummy)
+{
+	struct dell_bios_calling_interface *calling_interface;
+	struct dell_bios_data_token *token;
+	int token_size = sizeof(struct dell_bios_data_token);
+	int i = 0;
+
+	if (dm->type == 0xda && dm->length > 17) {
+		calling_interface = container_of(dm,
+				struct dell_bios_calling_interface, header);
+
+		token = &calling_interface->damap[i];
+		while (token->tokenid != 0xffff) {
+			if (token->tokenid == GLOBAL_MIC_MUTE_DISABLE)
+				memcpy(&dell_mic_tokens[0], token, token_size);
+			else if (token->tokenid == GLOBAL_MIC_MUTE_ENABLE)
+				memcpy(&dell_mic_tokens[1], token, token_size);
+
+			i++;
+			token = &calling_interface->damap[i];
+		}
+	}
+}
+
+static int dell_micmute_led_set(int state)
+{
+	struct app_wmi_args args;
+	struct dell_bios_data_token *token;
+
+	if (!wmi_has_guid(DELL_APP_GUID))
+		return -ENODEV;
+
+	if (state == 0 || state == 1)
+		token = &dell_mic_tokens[state];
+	else
+		return -EINVAL;
+
+	memset(&args, 0, sizeof(struct app_wmi_args));
+
+	args.class = 1;
+	args.arg1 = token->location;
+	args.arg2 = token->value;
+
+	dell_wmi_perform_query(&args);
+
+	return state;
+}
+
+int dell_app_wmi_led_set(int whichled, int on)
+{
+	int state = 0;
+
+	switch (whichled) {
+	case DELL_LED_MICMUTE:
+		state = dell_micmute_led_set(on);
+		break;
+	default:
+		pr_warn("led type %x is not supported\n", whichled);
+		break;
+	}
+
+	return state;
+}
+EXPORT_SYMBOL_GPL(dell_app_wmi_led_set);
+
+static int __init dell_micmute_led_init(void)
+{
+	memset(dell_mic_tokens, 0, sizeof(struct dell_bios_data_token) * 2);
+	dmi_walk(find_micmute_tokens, NULL);
+
+	return 0;
+}
+
 struct bios_args {
 	unsigned char length;
 	unsigned char result_code;
@@ -181,21 +327,32 @@  static int __init dell_led_init(void)
 {
 	int error = 0;
 
-	if (!wmi_has_guid(DELL_LED_BIOS_GUID))
+	if (!wmi_has_guid(DELL_LED_BIOS_GUID) && !wmi_has_guid(DELL_APP_GUID))
 		return -ENODEV;
 
-	error = led_off();
-	if (error != 0)
-		return -ENODEV;
+	if (wmi_has_guid(DELL_APP_GUID))
+		error = dell_micmute_led_init();
 
-	return led_classdev_register(NULL, &dell_led);
+	if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
+		error = led_off();
+		if (error != 0)
+			return -ENODEV;
+
+		error = led_classdev_register(NULL, &dell_led);
+	}
+
+	return error;
 }
 
 static void __exit dell_led_exit(void)
 {
-	led_classdev_unregister(&dell_led);
+	int error = 0;
 
-	led_off();
+	if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
+		error = led_off();
+		if (error == 0)
+			led_classdev_unregister(&dell_led);
+	}
 }
 
 module_init(dell_led_init);
diff --git a/include/linux/dell-led.h b/include/linux/dell-led.h
new file mode 100644
index 0000000..7009b8b
--- /dev/null
+++ b/include/linux/dell-led.h
@@ -0,0 +1,10 @@ 
+#ifndef __DELL_LED_H__
+#define __DELL_LED_H__
+
+enum {
+	DELL_LED_MICMUTE,
+};
+
+int dell_app_wmi_led_set(int whichled, int on);
+
+#endif