public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [patch 7/7] asus-laptop: add  light sensor support
@ 2007-01-25 11:54 Corentin CHARY
  2007-01-26 13:04 ` Corentin CHARY
  0 siblings, 1 reply; 5+ messages in thread
From: Corentin CHARY @ 2007-01-25 11:54 UTC (permalink / raw)
  To: Len Brown; +Cc: linux-acpi, acpi4asus-user

/proc/acpi/asus/lslvl is now /sys/.../asus-laptop/ls_level
/proc/acpi/asus/lssw is now /sys/.../asus-laptop/ls_switch
nothing else ..

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
 asus-laptop.c |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 88 insertions(+), 4 deletions(-)
---

diff -Naur a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c
--- a/drivers/misc/asus-laptop.c	2007-01-21 15:39:24.000000000 +0100
+++ b/drivers/misc/asus-laptop.c	2007-01-21 15:44:54.000000000 +0100
@@ -145,6 +145,9 @@
 	    "\\INFB", /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
 	    "\\SSTE"); /* A3F A6F A3N A3L M6N W3N W6A */
 
+ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
+ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */
+
 /*
  * This is the main structure, we can use it to store anything interesting
  * about the hotk device
@@ -155,6 +158,8 @@
 	acpi_handle handle;	//the handle of the hotk device
 	char status;		//status of the hotk, for LEDs, ...
 	u32 ledd_status;	//status of the LED display
+	u8 light_level;    //light sensor level
+	u8 light_switch;    //light sensor switch value
 	u16 event_count[128];	//count for each event TODO make this better
 };
 
@@ -588,6 +593,62 @@
 	return rv;
 }
 
+/*
+ * Light Sens
+ */
+static void set_light_sens_switch(int value)
+{
+	if (!write_acpi_int(ls_switch_handle, NULL, value, NULL))
+		printk(ASUS_WARNING "Error setting light sensor switch\n");
+	hotk->light_switch = value;
+}
+
+static ssize_t show_lssw(struct device *dev,
+			 struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", hotk->light_switch);
+}
+
+static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
+			  const char *buf, size_t count)
+{
+	int rv, value;
+
+	rv = parse_arg(buf, count, &value);
+	if (rv > 0)
+		set_light_sens_switch(value ? 1 : 0);
+
+	return rv;
+}
+
+static void set_light_sens_level(int value)
+{
+	if (!write_acpi_int(ls_level_handle, NULL, value, NULL))
+		printk(ASUS_WARNING "Error setting light sensor level\n");
+	hotk->light_level = value;
+}
+
+static ssize_t show_lslvl(struct device *dev,
+			  struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", hotk->light_level);
+}
+
+static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
+			   const char *buf, size_t count)
+{
+	int rv, value;
+
+	rv = parse_arg(buf, count, &value);
+	if (rv > 0) {
+		value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
+		/* 0 <= value <= 15 */
+		set_light_sens_level(value);
+	}
+
+	return rv;
+}
+
 static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
 {
 	/* TODO Find a better way to handle events count. */
@@ -634,6 +695,8 @@
 static ASUS_CREATE_DEVICE_ATTR(bluetooth);
 static ASUS_CREATE_DEVICE_ATTR(display);
 static ASUS_CREATE_DEVICE_ATTR(ledd);
+static ASUS_CREATE_DEVICE_ATTR(ls_switch);
+static ASUS_CREATE_DEVICE_ATTR(ls_level);
 
 static struct attribute *asuspf_attributes[] = {
         &dev_attr_infos.attr,
@@ -641,6 +704,8 @@
         &dev_attr_bluetooth.attr,
         &dev_attr_display.attr,
         &dev_attr_ledd.attr,
+        &dev_attr_ls_switch.attr,
+        &dev_attr_ls_level.attr,
         NULL
 };
 
@@ -677,6 +742,10 @@
 	if (ledd_set_handle)
 		ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
 
+	if (ls_switch_handle && ls_level_handle) {
+		ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
+		ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
+	}
 }
 
 static int asus_handle_init(char *name, acpi_handle *handle,
@@ -798,6 +867,11 @@
 	ASUS_HANDLE_INIT(display_set);
 	ASUS_HANDLE_INIT(display_get);
 
+	/* There is a lot of models with "ALSL", but a few get
+	   a real light sens, so we need to check it. */
+	if(ASUS_HANDLE_INIT(ls_switch))
+		ASUS_HANDLE_INIT(ls_level);
+
 	kfree(model);
 
 	return AE_OK;
@@ -865,17 +939,27 @@
 	/* WLED and BLED are on by default */
 	hotk->status |= WL_ON | BT_ON;
 
+	if(wl_switch_handle)
+		write_acpi_int(wl_switch_handle, NULL, 1, NULL);
+
+	if(bt_switch_handle)
+		write_acpi_int(bt_switch_handle, NULL, 1, NULL);
+
 	/* LCD Backlight is on by default */
 	hotk->status |= LCD_ON;
 
 	/* LED display is off by default */
 	hotk->ledd_status = 0xFFF;
 
-	if(wl_switch_handle)
-		write_acpi_int(wl_switch_handle, NULL, 1, NULL);
+	/* Set initial values of light sensor and level */
+	hotk->light_switch = 1; /* Default to light sensor disabled */
+	hotk->light_level = 0; /* level 5 for sensor sensitivity */
 
-	if(bt_switch_handle)
-		write_acpi_int(bt_switch_handle, NULL, 1, NULL);
+	if (ls_switch_handle)
+		set_light_sens_switch(hotk->light_switch);
+
+	if (ls_level_handle)
+		set_light_sens_level(hotk->light_level);
 
       end:
 	if (result) {

-- 
CHARY 'Iksaif' Corentin
http://xf.iksaif.net

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

* Re: [patch 7/7] asus-laptop: add  light sensor support
  2007-01-25 11:54 [patch 7/7] asus-laptop: add light sensor support Corentin CHARY
@ 2007-01-26 13:04 ` Corentin CHARY
  2007-01-26 22:53   ` [Acpi4asus-user] " Johannes Engel
  2007-01-30  6:42   ` Len Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Corentin CHARY @ 2007-01-26 13:04 UTC (permalink / raw)
  To: Len Brown; +Cc: linux-acpi, acpi4asus-user

From: Corentin Chary <corentincj@iksaif.net>

/proc/acpi/asus/lslvl is now /sys/.../asus-laptop/ls_level
/proc/acpi/asus/lssw is now /sys/.../asus-laptop/ls_switch nothing
else ..

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
---
 drivers/misc/asus-laptop.c |   84 +++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff -Naur a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c
--- a/drivers/misc/asus-laptop.c	2007-01-26 13:05:53.000000000 +0100
+++ b/drivers/misc/asus-laptop.c	2007-01-26 13:04:54.000000000 +0100
@@ -145,6 +145,9 @@
 	    "\\INFB", /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
 	    "\\SSTE"); /* A3F A6F A3N A3L M6N W3N W6A */
 
+ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
+ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */
+
 /*
  * This is the main structure, we can use it to store anything interesting
  * about the hotk device
@@ -155,6 +158,8 @@
 	acpi_handle handle;	//the handle of the hotk device
 	char status;		//status of the hotk, for LEDs, ...
 	u32 ledd_status;	//status of the LED display
+	u8 light_level;    //light sensor level
+	u8 light_switch;    //light sensor switch value
 	u16 event_count[128];	//count for each event TODO make this better
 };
 
@@ -590,6 +595,62 @@
 	return rv;
 }
 
+/*
+ * Light Sens
+ */
+static void set_light_sens_switch(int value)
+{
+	if (!write_acpi_int(ls_switch_handle, NULL, value, NULL))
+		printk(ASUS_WARNING "Error setting light sensor switch\n");
+	hotk->light_switch = value;
+}
+
+static ssize_t show_lssw(struct device *dev,
+			 struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", hotk->light_switch);
+}
+
+static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
+			  const char *buf, size_t count)
+{
+	int rv, value;
+
+	rv = parse_arg(buf, count, &value);
+	if (rv > 0)
+		set_light_sens_switch(value ? 1 : 0);
+
+	return rv;
+}
+
+static void set_light_sens_level(int value)
+{
+	if (!write_acpi_int(ls_level_handle, NULL, value, NULL))
+		printk(ASUS_WARNING "Error setting light sensor level\n");
+	hotk->light_level = value;
+}
+
+static ssize_t show_lslvl(struct device *dev,
+			  struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", hotk->light_level);
+}
+
+static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
+			   const char *buf, size_t count)
+{
+	int rv, value;
+
+	rv = parse_arg(buf, count, &value);
+	if (rv > 0) {
+		value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
+		/* 0 <= value <= 15 */
+		set_light_sens_level(value);
+	}
+
+	return rv;
+}
+
 static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
 {
 	/* TODO Find a better way to handle events count. */
@@ -636,6 +697,8 @@
 static ASUS_CREATE_DEVICE_ATTR(bluetooth);
 static ASUS_CREATE_DEVICE_ATTR(display);
 static ASUS_CREATE_DEVICE_ATTR(ledd);
+static ASUS_CREATE_DEVICE_ATTR(ls_switch);
+static ASUS_CREATE_DEVICE_ATTR(ls_level);
 
 static struct attribute *asuspf_attributes[] = {
         &dev_attr_infos.attr,
@@ -643,6 +706,8 @@
         &dev_attr_bluetooth.attr,
         &dev_attr_display.attr,
         &dev_attr_ledd.attr,
+        &dev_attr_ls_switch.attr,
+        &dev_attr_ls_level.attr,
         NULL
 };
 
@@ -679,6 +744,10 @@
 	if (ledd_set_handle)
 		ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
 
+	if (ls_switch_handle && ls_level_handle) {
+		ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
+		ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
+	}
 }
 
 static int asus_handle_init(char *name, acpi_handle *handle,
@@ -800,6 +869,11 @@
 	ASUS_HANDLE_INIT(display_set);
 	ASUS_HANDLE_INIT(display_get);
 
+	/* There is a lot of models with "ALSL", but a few get
+	   a real light sens, so we need to check it. */
+	if(ASUS_HANDLE_INIT(ls_switch))
+		ASUS_HANDLE_INIT(ls_level);
+
 	kfree(model);
 
 	return AE_OK;
@@ -874,6 +948,16 @@
  	/* LED display is off by default */
  	hotk->ledd_status = 0xFFF;
 
+ 	/* Set initial values of light sensor and level */
+ 	hotk->light_switch = 1; /* Default to light sensor disabled */
+ 	hotk->light_level = 0; /* level 5 for sensor sensitivity */
+
+ 	if (ls_switch_handle)
+ 		set_light_sens_switch(hotk->light_switch);
+
+ 	if (ls_level_handle)
+ 		set_light_sens_level(hotk->light_level);
+
       end:
 	if (result) {
 		kfree(hotk->name);

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

* Re: [Acpi4asus-user] [patch 7/7] asus-laptop: add light sensor support
  2007-01-26 13:04 ` Corentin CHARY
@ 2007-01-26 22:53   ` Johannes Engel
  2007-01-27  8:46     ` Corentin CHARY
  2007-01-30  6:42   ` Len Brown
  1 sibling, 1 reply; 5+ messages in thread
From: Johannes Engel @ 2007-01-26 22:53 UTC (permalink / raw)
  To: corentincj; +Cc: Len Brown, linux-acpi, acpi4asus-user

Hi, Corentin!

Some remarks on your patch which upto now works great for me!

1.) configuration seems to have a "circle": Warning! Found recursive
dependency: ACPI_ASUS ASUS_LAPTOP ACPI_ASUS

2.) The dependency X86 makes it necessary to enable generic
X86-optimizations. Is that intended?

3.) With recent BIOS versions the implementation of the value for the
Touchpad LED has switched. So an "echo 0 > .../led" results in the led
to light. Maybe there is a way to deal with that in kernel space. But I
think we already had that discussion some months ago.

Greetings, Johannes

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

* Re: [Acpi4asus-user] [patch 7/7] asus-laptop: add light sensor support
  2007-01-26 22:53   ` [Acpi4asus-user] " Johannes Engel
@ 2007-01-27  8:46     ` Corentin CHARY
  0 siblings, 0 replies; 5+ messages in thread
From: Corentin CHARY @ 2007-01-27  8:46 UTC (permalink / raw)
  To: Johannes Engel; +Cc: Len Brown, linux-acpi, acpi4asus-user

Le vendredi 26 janvier 2007 23:53, Johannes Engel a écrit :
> Hi, Corentin!
>
> Some remarks on your patch which upto now works great for me!
>
> 1.) configuration seems to have a "circle": Warning! Found recursive
> dependency: ACPI_ASUS ASUS_LAPTOP ACPI_ASUS
Yep I know, I already fixed that in the new patch (posted as an answer of the 
first).

> 2.) The dependency X86 makes it necessary to enable generic
> X86-optimizations. Is that intended?
Is that a problem ?

> 3.) With recent BIOS versions the implementation of the value for the
> Touchpad LED has switched. So an "echo 0 > .../led" results in the led
> to light. Maybe there is a way to deal with that in kernel space. But I
> think we already had that discussion some months ago.
I think we should make it work in most of the case, but it's not really a 
problem if the led doesn't work exactly as excepted ^^

-- 
CHARY 'Iksaif' Corentin
http://xf.iksaif.net
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [patch 7/7] asus-laptop: add  light sensor support
  2007-01-26 13:04 ` Corentin CHARY
  2007-01-26 22:53   ` [Acpi4asus-user] " Johannes Engel
@ 2007-01-30  6:42   ` Len Brown
  1 sibling, 0 replies; 5+ messages in thread
From: Len Brown @ 2007-01-30  6:42 UTC (permalink / raw)
  To: corentincj; +Cc: linux-acpi, acpi4asus-user

note the corrected whitespace errors:

Applying 'asus-laptop: add light sensor support'

Space in indent is followed by a tab.
.dotest/patch:135:      /* Set initial values of light sensor and level */
Space in indent is followed by a tab.
.dotest/patch:136:      hotk->light_switch = 1; /* Default to light sensor disabled */
Space in indent is followed by a tab.
.dotest/patch:137:      hotk->light_level = 0; /* level 5 for sensor sensitivity */
Space in indent is followed by a tab.
.dotest/patch:139:      if (ls_switch_handle)
Space in indent is followed by a tab.
.dotest/patch:140:              set_light_sens_switch(hotk->light_switch);

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

end of thread, other threads:[~2007-01-30  6:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-25 11:54 [patch 7/7] asus-laptop: add light sensor support Corentin CHARY
2007-01-26 13:04 ` Corentin CHARY
2007-01-26 22:53   ` [Acpi4asus-user] " Johannes Engel
2007-01-27  8:46     ` Corentin CHARY
2007-01-30  6:42   ` Len Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox