All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] wistron_btns: add led support
@ 2007-04-18 22:22 Éric Piel
  0 siblings, 0 replies; 4+ messages in thread
From: Éric Piel @ 2007-04-18 22:22 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: mitr, otauber, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 442 bytes --]

This patch adds support for mail and wifi leds. It modifies the Kconfig
file to automatically pull led_class with wistron_btns, hopefully
everyone is fine with this.

It doesn't add support for bluetooth led because, so far, it seems all 
the laptops with bluetooth have led and bluetooth system linked (meaning 
it is already managed by the driver).

This was tested on a TM 610 and a Aspire 3020.

Eric
(sorry for the multiple receptions)


[-- Attachment #2: wistron_btns-led-2.6.21.patch --]
[-- Type: text/x-patch, Size: 5174 bytes --]

From: Eric Piel <eric.piel@tremplin-utc.net>

wriston_btns: Add led support
Add support to wistron_btns for leds that comes with the multimedia keys. Mail
and wifi leds are supported, on laptops which have them. Depending on the
laptop, wifi subsystem may control just the led, or both the led and the wifi
card. Wifi led interface is activated only for the former type of laptops, as
the latter type is already managed. Leds are controled by the interface in
/sys/class/leds. 

Signed-off-by: Eric Piel <eric.piel@tremplin-utc.net>

--- linux-2.6.21/drivers/input/misc/wistron_btns.c.bak	2007-04-07 15:09:30.000000000 +0200
+++ linux-2.6.21/drivers/input/misc/wistron_btns.c	2007-04-14 12:42:38.000000000 +0200
@@ -30,6 +30,7 @@
 #include <linux/timer.h>
 #include <linux/types.h>
 #include <linux/platform_device.h>
+#include <linux/leds.h>
 
 /*
  * Number of attempts to read data from queue per poll;
@@ -46,11 +47,12 @@
 /* BIOS subsystem IDs */
 #define WIFI		0x35
 #define BLUETOOTH	0x34
+#define MAIL_LED	0x31
 
 MODULE_AUTHOR("Miloslav Trmac <mitr@volny.cz>");
 MODULE_DESCRIPTION("Wistron laptop button driver");
 MODULE_LICENSE("GPL v2");
-MODULE_VERSION("0.2");
+MODULE_VERSION("0.3");
 
 static int force; /* = 0; */
 module_param(force, bool, 0);
@@ -251,6 +253,7 @@
 static const struct key_entry *keymap; /* = NULL; Current key map */
 static int have_wifi;
 static int have_bluetooth;
+static int have_leds;
 
 static int __init dmi_matched(struct dmi_system_id *dmi)
 {
@@ -263,6 +266,8 @@
 		else if (key->type == KE_BLUETOOTH)
 			have_bluetooth = 1;
 	}
+	have_leds = key->code & (FE_MAIL_LED | FE_WIFI_LED);
+
 	return 1;
 }
 
@@ -1028,6 +1033,83 @@
 	input_sync(input_dev);
 }
 
+
+ /* led management */
+static void wistron_mail_led_set(struct led_classdev *led_cdev,
+				enum led_brightness value)
+{
+	bios_set_state(MAIL_LED, (value != LED_OFF) ? 1 : 0);
+}
+
+/* same as setting up wifi card, but for laptops on which the led is managed */
+static void wistron_wifi_led_set(struct led_classdev *led_cdev,
+				enum led_brightness value)
+{
+	bios_set_state(WIFI, (value != LED_OFF) ? 1 : 0);
+}
+
+static struct led_classdev wistron_mail_led = {
+	.name			= "mail:green",
+	.brightness_set		= wistron_mail_led_set,
+};
+
+static struct led_classdev wistron_wifi_led = {
+	.name			= "wifi:red",
+	.brightness_set		= wistron_wifi_led_set,
+};
+
+static void __devinit wistron_led_init(struct device *parent)
+{
+	if (have_leds & FE_WIFI_LED) {
+		u16 wifi = bios_get_default_setting(WIFI);
+		if (wifi & 1) {
+			wistron_wifi_led.brightness = (wifi & 2) ? LED_FULL : LED_OFF;
+			if (led_classdev_register(parent, &wistron_wifi_led))
+				have_leds &= ~FE_WIFI_LED;
+			else
+				bios_set_state(WIFI, wistron_wifi_led.brightness);
+
+		} else
+			have_leds &= ~FE_WIFI_LED;
+	}
+
+	if (have_leds & FE_MAIL_LED) {
+		/* bios_get_default_setting(MAIL) always retuns 0, so just turn the led off */
+		wistron_mail_led.brightness = LED_OFF;
+		if (led_classdev_register(parent, &wistron_mail_led))
+			have_leds &= ~FE_MAIL_LED;
+		else
+			bios_set_state(MAIL_LED, wistron_mail_led.brightness);
+	}
+}
+
+static void __devexit wistron_led_remove(void)
+{
+	if (have_leds & FE_MAIL_LED)
+		led_classdev_unregister(&wistron_mail_led);
+
+	if (have_leds & FE_WIFI_LED)
+		led_classdev_unregister(&wistron_wifi_led);
+}
+
+static inline void wistron_led_suspend(void)
+{
+	if (have_leds & FE_MAIL_LED)
+		led_classdev_suspend(&wistron_mail_led);
+
+	if (have_leds & FE_WIFI_LED)
+		led_classdev_suspend(&wistron_wifi_led);
+}
+
+static inline void wistron_led_resume(void)
+{
+	if (have_leds & FE_MAIL_LED)
+		led_classdev_resume(&wistron_mail_led);
+
+	if (have_leds & FE_WIFI_LED)
+		led_classdev_resume(&wistron_wifi_led);
+}
+
  /* Driver core */
 
 static int wifi_enabled;
@@ -1125,6 +1207,7 @@
 			bios_set_state(BLUETOOTH, bluetooth_enabled);
 	}
 
+	wistron_led_init(&dev->dev);
 	poll_bios(1); /* Flush stale event queue and arm timer */
 
 	return 0;
@@ -1133,6 +1216,7 @@
 static int __devexit wistron_remove(struct platform_device *dev)
 {
 	del_timer_sync(&poll_timer);
+	wistron_led_remove();
 	input_unregister_device(input_dev);
 	bios_detach();

@@ -1150,6 +1233,7 @@
 	if (have_bluetooth)
 		bios_set_state(BLUETOOTH, 0);
 
+	wistron_led_suspend();
 	return 0;
 }
 
@@ -1161,6 +1245,7 @@
 	if (have_bluetooth)
 		bios_set_state(BLUETOOTH, bluetooth_enabled);
 
+	wistron_led_resume();
 	poll_bios(1);
 
 	return 0;
--- linux-2.6.21/drivers/input/misc/Kconfig.bak	2007-04-09 23:18:49.000000000 +0200
+++ linux-2.6.21/drivers/input/misc/Kconfig	2007-04-14 02:53:01.000000000 +0200
@@ -43,9 +43,12 @@
 config INPUT_WISTRON_BTNS
 	tristate "x86 Wistron laptop button interface"
 	depends on X86 && !X86_64
+	select NEW_LEDS
+	select LEDS_CLASS
 	help
 	  Say Y here for support of Winstron laptop button interface, used on
-	  laptops of various brands, including Acer and Fujitsu-Siemens.
+	  laptops of various brands, including Acer and Fujitsu-Siemens. If 
+	  available, mail and wifi leds will be controlable via /sys/class/leds.
 
 	  To compile this driver as a module, choose M here: the module will
 	  be called wistron_btns.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] wistron_btns: add led support
  2007-04-18  4:25 ` Dmitry Torokhov
@ 2007-04-18  8:22   ` Éric Piel
  0 siblings, 0 replies; 4+ messages in thread
From: Éric Piel @ 2007-04-18  8:22 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: mitr, otauber, linux-kernel

18.04.2007 06:25, Dmitry Torokhov wrote/a écrit:
> On Saturday 14 April 2007 12:09, Éric Piel wrote:
>> This patch adds support for mail and wifi leds. It modifies the Kconfig 
>> file to automatically pull led_class with wistron_btns, hopefully 
>> everyone is fine with this.
>>
> 
> Was there 1/2 file?

Ooops, sorry, this mail was not mean to be sent yet (my thunderbird and 
I misunderstood each other). It works here but I'll try it on another 
laptop to confirm the patch is good.

Hopefully, I'll come back to you tomorrow with no changes and a little 
1/2 patch :-)

Eric

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] wistron_btns: add led support
  2007-04-14 16:09 Éric Piel
@ 2007-04-18  4:25 ` Dmitry Torokhov
  2007-04-18  8:22   ` Éric Piel
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2007-04-18  4:25 UTC (permalink / raw)
  To: Éric Piel; +Cc: mitr, otauber, linux-kernel

On Saturday 14 April 2007 12:09, Éric Piel wrote:
> This patch adds support for mail and wifi leds. It modifies the Kconfig 
> file to automatically pull led_class with wistron_btns, hopefully 
> everyone is fine with this.
> 

Was there 1/2 file?

-- 
Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] wistron_btns: add led support
@ 2007-04-14 16:09 Éric Piel
  2007-04-18  4:25 ` Dmitry Torokhov
  0 siblings, 1 reply; 4+ messages in thread
From: Éric Piel @ 2007-04-14 16:09 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: mitr, otauber, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 174 bytes --]

This patch adds support for mail and wifi leds. It modifies the Kconfig 
file to automatically pull led_class with wistron_btns, hopefully 
everyone is fine with this.

Eric

[-- Attachment #2: wistron_btns-led-2.6.21.patch --]
[-- Type: text/x-patch, Size: 5173 bytes --]

From: Eric Piel <eric.piel@tremplin-utc.net>

wriston_btns: Add led support
Add support to wistron_btns for leds that comes with the multimedia keys. Mail
and wifi leds are supported, on laptops which have them. Depending on the
laptop, wifi subsystem may control just the led, or both the led and the wifi
card. Wifi led interface is activated only for the former type of laptops, as
the latter type is already managed. Leds are controled by the interface in
/sys/class/leds. 

Signed-off-by: Eric Piel <eric.piel@tremplin-utc.net>

--- linux-2.6.21/drivers/input/misc/wistron_btns.c.bak	2007-04-07 15:09:30.000000000 +0200
+++ linux-2.6.21/drivers/input/misc/wistron_btns.c	2007-04-14 12:42:38.000000000 +0200
@@ -30,6 +30,7 @@
 #include <linux/timer.h>
 #include <linux/types.h>
 #include <linux/platform_device.h>
+#include <linux/leds.h>
 
 /*
  * Number of attempts to read data from queue per poll;
@@ -46,11 +47,12 @@
 /* BIOS subsystem IDs */
 #define WIFI		0x35
 #define BLUETOOTH	0x34
+#define MAIL_LED	0x31
 
 MODULE_AUTHOR("Miloslav Trmac <mitr@volny.cz>");
 MODULE_DESCRIPTION("Wistron laptop button driver");
 MODULE_LICENSE("GPL v2");
-MODULE_VERSION("0.2");
+MODULE_VERSION("0.3");
 
 static int force; /* = 0; */
 module_param(force, bool, 0);
@@ -251,6 +253,7 @@
 static const struct key_entry *keymap; /* = NULL; Current key map */
 static int have_wifi;
 static int have_bluetooth;
+static int have_leds;
 
 static int __init dmi_matched(struct dmi_system_id *dmi)
 {
@@ -263,6 +266,8 @@
 		else if (key->type == KE_BLUETOOTH)
 			have_bluetooth = 1;
 	}
+	have_leds = key->code & (FE_MAIL_LED | FE_WIFI_LED);
+
 	return 1;
 }
 
@@ -1028,6 +1033,83 @@
 	input_sync(input_dev);
 }
 
+
+ /* led management */
+static void wistron_mail_led_set(struct led_classdev *led_cdev,
+				enum led_brightness value)
+{
+	bios_set_state(MAIL_LED, (value != LED_OFF) ? 1 : 0);
+}
+
+/* same as setting up wifi card, but for laptops on which the led is managed */
+static void wistron_wifi_led_set(struct led_classdev *led_cdev,
+				enum led_brightness value)
+{
+	bios_set_state(WIFI, (value != LED_OFF) ? 1 : 0);
+}
+
+static struct led_classdev wistron_mail_led = {
+	.name			= "mail:green",
+	.brightness_set		= wistron_mail_led_set,
+};
+
+static struct led_classdev wistron_wifi_led = {
+	.name			= "wifi:red",
+	.brightness_set		= wistron_wifi_led_set,
+};
+
+static void __devinit wistron_led_init(struct device *parent)
+{
+	if (have_leds & FE_WIFI_LED) {
+		u16 wifi = bios_get_default_setting(WIFI);
+		if (wifi & 1) {
+			wistron_wifi_led.brightness = (wifi & 2) ? LED_FULL : LED_OFF;
+			if (led_classdev_register(parent, &wistron_wifi_led))
+				have_leds &= ~FE_WIFI_LED;
+			else
+				bios_set_state(WIFI, wistron_wifi_led.brightness);
+
+		} else
+			have_leds &= ~FE_WIFI_LED;
+	}
+
+	if (have_leds & FE_MAIL_LED) {
+		/* bios_get_default_setting(MAIL) always retuns 0, so just turn the led off */
+		wistron_mail_led.brightness = LED_OFF;
+		if (led_classdev_register(parent, &wistron_mail_led))
+			have_leds &= ~FE_MAIL_LED;
+		else
+			bios_set_state(MAIL_LED, wistron_mail_led.brightness);
+	}
+}
+
+static void __devexit wistron_led_remove(void)
+{
+	if (have_leds & FE_MAIL_LED)
+		led_classdev_unregister(&wistron_mail_led);
+
+	if (have_leds & FE_WIFI_LED)
+		led_classdev_unregister(&wistron_wifi_led);
+}
+
+static inline void wistron_led_suspend(void)
+{
+	if (have_leds & FE_MAIL_LED)
+		led_classdev_suspend(&wistron_mail_led);
+
+	if (have_leds & FE_WIFI_LED)
+		led_classdev_suspend(&wistron_wifi_led);
+}
+
+static inline void wistron_led_resume(void)
+{
+	if (have_leds & FE_MAIL_LED)
+		led_classdev_resume(&wistron_mail_led);
+
+	if (have_leds & FE_WIFI_LED)
+		led_classdev_resume(&wistron_wifi_led);
+}
+
  /* Driver core */
 
 static int wifi_enabled;
@@ -1125,6 +1207,7 @@
 			bios_set_state(BLUETOOTH, bluetooth_enabled);
 	}
 
+	wistron_led_init(&dev->dev);
 	poll_bios(1); /* Flush stale event queue and arm timer */
 
 	return 0;
@@ -1133,6 +1216,7 @@
 static int __devexit wistron_remove(struct platform_device *dev)
 {
 	del_timer_sync(&poll_timer);
+	wistron_led_remove();
 	input_unregister_device(input_dev);
 	bios_detach();

@@ -1150,6 +1233,7 @@
 	if (have_bluetooth)
 		bios_set_state(BLUETOOTH, 0);
 
+	wistron_led_suspend();
 	return 0;
 }
 
@@ -1161,6 +1245,7 @@
 	if (have_bluetooth)
 		bios_set_state(BLUETOOTH, bluetooth_enabled);
 
+	wistron_led_resume();
 	poll_bios(1);
 
 	return 0;
--- linux-2.6.21/drivers/input/misc/Kconfig.bak	2007-04-09 23:18:49.000000000 +0200
+++ linux-2.6.21/drivers/input/misc/Kconfig	2007-04-14 02:53:01.000000000 +0200
@@ -43,9 +43,12 @@
 config INPUT_WISTRON_BTNS
 	tristate "x86 Wistron laptop button interface"
 	depends on X86 && !X86_64
+	select NEW_LEDS
+	select LEDS_CLASS
 	help
 	  Say Y here for support of Winstron laptop button interface, used on
-	  laptops of various brands, including Acer and Fujitsu-Siemens.
+	  laptops of various brands, including Acer and Fujitsu-Siemens. If 
+	  available, mail and wifi leds will be controlable via /sys/class/leds.
 
 	  To compile this driver as a module, choose M here: the module will
 	  be called wistron_btns.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-04-18 22:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-18 22:22 [PATCH 2/2] wistron_btns: add led support Éric Piel
  -- strict thread matches above, loose matches on Subject: below --
2007-04-14 16:09 Éric Piel
2007-04-18  4:25 ` Dmitry Torokhov
2007-04-18  8:22   ` Éric Piel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.