Skip to contentSkip to conversation

Pegatron Lucid tablet acceleromter/ALS

PATCH In review Andy Ross 6 participants 12 messages Jan 24, 2011 – Jan 25, 2011 3 messages not in the archive

Subsystems (4)
lore
Share & tools
lore

Andy Ross

author
#0 lore raw

cover Pegatron Lucid tablet acceleromter/ALS

Resubmission and update of the Pegatron Lucid tablet accelerometer and ambient light sensor drivers.

Patches 1-3 are against asus-laptop, and apply in order.

Patch 4 is against input, and can be commited separately (obviously relies on the detection code in asus-laptop at runtime, but will build and load independently).

Andy

#2 lore raw

PATCH 1/4 asus-laptop: Device detection for Pegatron Lucid tablets

In reply to a message not in the archive

Recognize the Pegatron Lucid tablet devices (which share the same "\_SB.ATKD" namespace) by the result of their INIT method and the presence of some specific methods.

---
 drivers/platform/x86/asus-laptop.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)
drivers/platform/x86/asus-laptop.c +24 -1
index d235f44..6f542af 100644
@@ -4,6 +4,7 @@
  *
  *  Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
  *  Copyright (C) 2006-2007 Corentin Chary
+ *  Copyright (C) 2011 Wind River Systems
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -210,6 +211,18 @@ static char *display_get_paths[] = {
 #define METHOD_KBD_LIGHT_SET	"SLKB"
 #define METHOD_KBD_LIGHT_GET	"GLKB"
 
+/* For Pegatron Lucid tablet */
+#define DEVICE_NAME_PEGA	"Lucid"
+
+#define METHOD_PEGA_ENABLE	"ENPR"
+#define METHOD_PEGA_DISABLE	"DAPR"
+#define PEGA_ALS	0x04
+#define PEGA_ALS_POWER	0x05
+
+#define METHOD_PEGA_READ	"RDLN"
+#define PEGA_READ_ALS_H	0x02
+#define PEGA_READ_ALS_L	0x03
+
 /*
  * Define a specific led structure to keep the main structure clean
  */
@@ -246,6 +259,7 @@ struct asus_laptop {
 
 	int wireless_status;
 	bool have_rsts;
+	bool have_pega_lucid;
 	int lcd_state;
 
 	struct rfkill *gps_rfkill;
@@ -361,6 +375,14 @@ static int acpi_check_handle(acpi_handle handle, const char *method,
 	return 0;
 }
 
+static bool asus_check_pega_lucid(struct asus_laptop *asus)
+{
+	return !strcmp(asus->name, DEVICE_NAME_PEGA) &&
+	   !acpi_check_handle(asus->handle, METHOD_PEGA_ENABLE, NULL) &&
+	   !acpi_check_handle(asus->handle, METHOD_PEGA_DISABLE, NULL) &&
+	   !acpi_check_handle(asus->handle, METHOD_PEGA_READ, NULL);
+}
+
 /* Generic LED function */
 static int asus_led_set(struct asus_laptop *asus, const char *method,
 			 int value)
@@ -1334,7 +1356,6 @@ static mode_t asus_sysfs_is_visible(struct kobject *kobj,
 		   attr == &dev_attr_ls_level.attr) {
 		supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
 			    !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
-
 	} else if (attr == &dev_attr_gps.attr) {
 		supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
 			    !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
@@ -1605,6 +1626,8 @@ static int __devinit asus_acpi_add(struct acpi_device *device)
 	if (result)
 		goto fail_rfkill;
 
+	asus->have_pega_lucid = asus_check_pega_lucid(asus);
+
 	asus_device_present = true;
 	return 0;
 
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
author
#12 lore raw

PATCH 2/4 asus-laptop: Pegatron Lucid ALS support

In reply to Andy Ross

Add support for the ambient light sensor on the Pegatron Lucid tablet. This uses a different inteface but the same sysfs interface for ls_switch, has no equivalent to the existing ls_value threshold setting, and exports the actual brightness via a new attribute "ls_value".

---
 drivers/platform/x86/asus-laptop.c |   64 +++++++++++++++++++++++++++++++++---
 1 files changed, 59 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-laptop.c +59 -5
index 6f542af..b397a4c 100644
@@ -383,6 +383,12 @@ static bool asus_check_pega_lucid(struct asus_laptop *asus)
 	   !acpi_check_handle(asus->handle, METHOD_PEGA_READ, NULL);
 }
 
+static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable)
+{
+	char *method = enable ? METHOD_PEGA_ENABLE : METHOD_PEGA_DISABLE;
+	return write_acpi_int(asus->handle, method, unit);
+}
+
 /* Generic LED function */
 static int asus_led_set(struct asus_laptop *asus, const char *method,
 			 int value)
@@ -1051,7 +1057,15 @@ static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
  */
 static void asus_als_switch(struct asus_laptop *asus, int value)
 {
-	if (write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value))
+	int ret;
+	if (asus->have_pega_lucid) {
+		ret = asus_pega_lucid_set(asus, PEGA_ALS, value);
+		if (!ret)
+			ret = asus_pega_lucid_set(asus, PEGA_ALS_POWER, value);
+	} else {
+		ret = write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value);
+	}
+	if (ret)
 		pr_warning("Error setting light sensor switch\n");
 	asus->light_switch = value;
 }
@@ -1108,6 +1122,35 @@ static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
 	return rv;
 }
 
+static int pega_int_read(struct asus_laptop *asus, int arg, int *result)
+{
+	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	int err = write_acpi_int_ret(asus->handle, METHOD_PEGA_READ, arg,
+				     &buffer);
+	if (!err) {
+		union acpi_object *obj = buffer.pointer;
+		if (obj && obj->type == ACPI_TYPE_INTEGER)
+			*result = obj->integer.value;
+		else
+			err = -EIO;
+	}
+	return err;
+}
+
+static ssize_t show_lsvalue(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct asus_laptop *asus = dev_get_drvdata(dev);
+	int err, hi, lo;
+
+	err = pega_int_read(asus, PEGA_READ_ALS_H, &hi);
+	if (!err)
+		err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
+	if (!err)
+		return sprintf(buf, "%d\n", 10 * hi + lo);
+	return err;
+}
+
 /*
  * GPS
  */
@@ -1305,6 +1348,7 @@ static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
 static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
 static DEVICE_ATTR(display, S_IRUGO | S_IWUSR, show_disp, store_disp);
 static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
+static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL);
 static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
 static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
 static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
@@ -1317,6 +1361,7 @@ static struct attribute *asus_attributes[] = {
 	&dev_attr_wwan.attr,
 	&dev_attr_display.attr,
 	&dev_attr_ledd.attr,
+	&dev_attr_ls_value.attr,
 	&dev_attr_ls_level.attr,
 	&dev_attr_ls_switch.attr,
 	&dev_attr_gps.attr,
@@ -1354,8 +1399,15 @@ static mode_t asus_sysfs_is_visible(struct kobject *kobj,
 
 	} else if (attr == &dev_attr_ls_switch.attr ||
 		   attr == &dev_attr_ls_level.attr) {
-		supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
-			    !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
+		if (asus_check_pega_lucid(asus)) {
+			/* no ls_level interface on the Lucid */
+			supported = attr == &dev_attr_ls_switch.attr;
+		} else {
+			supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
+				    !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
+		}
+	} else if (attr == &dev_attr_ls_value.attr) {
+		supported = asus_check_pega_lucid(asus);
 	} else if (attr == &dev_attr_gps.attr) {
 		supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
 			    !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
@@ -1567,8 +1619,10 @@ static int __devinit asus_acpi_init(struct asus_laptop *asus)
 	asus->light_switch = 0;	/* Default to light sensor disabled */
 	asus->light_level = 5;	/* level 5 for sensor sensitivity */
 
-	if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
-	    !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
+	if (asus->have_pega_lucid) {
+		asus_als_switch(asus, asus->light_switch);
+	} else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
+		   !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
 		asus_als_switch(asus, asus->light_switch);
 		asus_als_level(asus, asus->light_level);
 	}
Signature · 1 line
1.7.1
author
#13 lore raw

PATCH 3/4 asus-laptop: Support pega_accel accelerometer driver

In reply to Andy Ross

Add device detecton for the ACPI accelerometer interface on Pegatron Lucid tablets.

---
 drivers/platform/x86/asus-laptop.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
drivers/platform/x86/asus-laptop.c +19 -0
index b397a4c..75c84f8 100644
@@ -261,6 +261,7 @@ struct asus_laptop {
 	bool have_rsts;
 	bool have_pega_lucid;
 	int lcd_state;
+	struct platform_device *pega_accel;
 
 	struct rfkill *gps_rfkill;
 
@@ -1631,6 +1632,19 @@ static int __devinit asus_acpi_init(struct asus_laptop *asus)
 	return result;
 }
 
+static void __devinit asus_pega_accel_init(struct asus_laptop *asus)
+{
+	/* Pegatron Lucid tablets expose their accelerometer through ACPI.
+	 * Check for XLR{X,Y,Z} methods */
+	if (acpi_check_handle(asus->handle, "XLRX", NULL) ||
+	    acpi_check_handle(asus->handle, "XLRY", NULL) ||
+	    acpi_check_handle(asus->handle, "XLRZ", NULL))
+		return;
+
+	asus->pega_accel = platform_device_register_simple("pega_accel", -1,
+							   NULL, 0);
+}
+
 static bool asus_device_present;
 
 static int __devinit asus_acpi_add(struct acpi_device *device)
@@ -1681,6 +1695,8 @@ static int __devinit asus_acpi_add(struct acpi_device *device)
 		goto fail_rfkill;
 
 	asus->have_pega_lucid = asus_check_pega_lucid(asus);
+	if (asus->have_pega_lucid)
+		asus_pega_accel_init(asus);
 
 	asus_device_present = true;
 	return 0;
@@ -1704,6 +1720,9 @@ static int asus_acpi_remove(struct acpi_device *device, int type)
 {
 	struct asus_laptop *asus = acpi_driver_data(device);
 
+	if (asus->pega_accel)
+		platform_device_unregister(asus->pega_accel);
+
 	asus_backlight_exit(asus);
 	asus_rfkill_exit(asus);
 	asus_led_exit(asus);
Signature · 1 line
1.7.1
author
#14 lore raw

PATCH 4/4 input: Pegatron Lucid accelerometer

In reply to Andy Ross

Add driver for the ACPI accelerometer interface on the Pegatron Lucid tablet.

---
 drivers/input/misc/Kconfig      |   10 +++
 drivers/input/misc/Makefile     |    2 +-
 drivers/input/misc/pega-accel.c |  130 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 141 insertions(+), 1 deletions(-)
 create mode 100644 drivers/input/misc/pega-accel.c
drivers/input/misc/Kconfig +10 -0
index b99b8cb..e60af95 100644
@@ -74,6 +74,16 @@ config INPUT_PCSPKR
 	  To compile this driver as a module, choose M here: the
 	  module will be called pcspkr.
 
+config INPUT_PEGA_ACCEL
+       tristate "Support Pegatron Lucid accelerometer"
+       depends on ASUS_LAPTOP
+       help
+         Say Y here if you want support for the built-in ACPI
+         accelerometer device on Pegatron Lucid tablet devices.
+
+	 To compile this driver as a module, choose M here: the module
+	 will be called pega_accel.
+
 config INPUT_SPARCSPKR
 	tristate "SPARC Speaker support"
 	depends on PCI && SPARC64
drivers/input/misc/Makefile +1 -1
index 1fe1f6c..79aca4d 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_INPUT_PCAP)		+= pcap_keys.o
 obj-$(CONFIG_INPUT_PCF50633_PMU)	+= pcf50633-input.o
 obj-$(CONFIG_INPUT_PCF8574)		+= pcf8574_keypad.o
 obj-$(CONFIG_INPUT_PCSPKR)		+= pcspkr.o
+obj-$(CONFIG_INPUT_PEGA_ACCEL)		+= pega-accel.o
 obj-$(CONFIG_INPUT_POWERMATE)		+= powermate.o
 obj-$(CONFIG_INPUT_PWM_BEEPER)		+= pwm-beeper.o
 obj-$(CONFIG_INPUT_RB532_BUTTON)	+= rb532_button.o
@@ -42,4 +43,3 @@ obj-$(CONFIG_INPUT_WINBOND_CIR)		+= winbond-cir.o
 obj-$(CONFIG_INPUT_WISTRON_BTNS)	+= wistron_btns.o
 obj-$(CONFIG_INPUT_WM831X_ON)		+= wm831x-on.o
 obj-$(CONFIG_INPUT_YEALINK)		+= yealink.o
-
drivers/input/misc/pega-accel.c new file +130 -0

130 lines not on this page · raw message

Signature · 1 line
1.7.1
#3 lore raw
In reply to a message not in the archive
Quoted 9 lines · Andy Ross

Resubmission and update of the Pegatron Lucid tablet accelerometer and ambient light sensor drivers.

Patches 1-3 are against asus-laptop, and apply in order.

Patch 4 is against input, and can be commited separately (obviously relies on the detection code in asus-laptop at runtime, but will build and load independently).

I am happy with the input part but I wonder if it really needs to be separate? If you roll it up into asus-laptop you would not need a new platform device and then it would be what - 20 lines of code?

Corentin, what do you think?

Thanks.

Signature · 8 lines
Dmitry

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
maintainer
#4 lore raw
Quoted 11 lines · Dmitry Torokhov
Quoted 9 lines · Andy Ross

Resubmission and update of the Pegatron Lucid tablet accelerometer and ambient light sensor drivers.

Patches 1-3 are against asus-laptop, and apply in order.

Patch 4 is against input, and can be commited separately (obviously relies on the detection code in asus-laptop at runtime, but will build and load independently).

Quoted 5 lines

I am happy with the input part but I wonder if it really needs to be separate? If you roll it up into asus-laptop you would not need a new platform device and then it would be what - 20 lines of code?

Corentin, what do you think?

I think that it should be consistent, if there is already some code for pegatron tablet in asus-laptop, then why a new platform device only for the accelerometer ?

On the other side, having to load "asus-laptop" on a pegatron tablet (or on a lenovo laptop) isn't very intuitive.

The real name of this module should be atk010x_acpi, but it's not really better, and it's probably too late for that.

Andy, what is shared with asus-laptop exactly ? What sysfs files are working and enabled ?
Are backlight and led classes working ?

Thanks,

Signature · 2 lines
Corentin Chary
http://xf.iksaif.net
author
#5 lore raw
Quoted 10 lines · Corentin Chary
Quoted 5 lines · Dmitry Torokhov

I am happy with the input part but I wonder if it really needs to be separate? If you roll it up into asus-laptop you would not need a new platform device and then it would be what - 20 lines of code?

Corentin, what do you think?

I think that it should be consistent, if there is already some code for pegatron tablet in asus-laptop, then why a new platform device only for the accelerometer ?

No strong feelings here. I made it a separate file because asus-laptop.c is already very large and this was something that could be fairly easily split out, but obviously it's a really trivial device.

Quoted 2 lines

Andy, what is shared with asus-laptop exactly ? What sysfs files are working and enabled ? Are backlight and led classes working ?

Just the key device, which exports the single touch area in the corner of the tablet as KEY_MEDIA. Some of the other sysfs devices (bluetooth, display, leds) appear because the methods exist, but they're stubbed out in the ASL and thus noops.

Andy

maintainer
#6 lore raw
Quoted 20 lines · Andy Ross
Quoted 10 lines · Corentin Chary
Quoted 5 lines · Dmitry Torokhov

I am happy with the input part but I wonder if it really needs to be separate? If you roll it up into asus-laptop you would not need a new platform device and then it would be what - 20 lines of code?

Corentin, what do you think?

I think that it should be consistent, if there is already some code for pegatron tablet in asus-laptop, then why a new platform device only for the accelerometer ?

No strong feelings here.  I made it a separate file because asus-laptop.c is already very large and this was something that could be fairly easily split out, but obviously it's a really trivial device.

Quoted 2 lines

Andy, what is shared with asus-laptop exactly ? What sysfs files are working and enabled ?  Are backlight and led classes working ?

Quoted 6 lines

Just the key device, which exports the single touch area in the corner of the tablet as KEY_MEDIA.  Some of the other sysfs devices (bluetooth, display, leds) appear because the methods exist, but they're stubbed out in the ASL and thus noops.

Andy

If everybody is ok with that, I think you should move the code back into asus-laptop.c. But if you do so, don't forget to modify the help text of ASUS_LAPTOP section in KConfig.

Should we also change the description to "Asus/Medion/JVC/Lenovo/Pegatron Extra" ? That seems really ugly but....

Signature · 2 lines
Corentin Chary
http://xf.iksaif.net
#8 lore raw
In reply to a message not in the archive
Quoted 3 lines · Corentin Chary

If everybody is ok with that, I think you should move the code back into asus-laptop.c. But if you do so, don't forget to modify the help text of ASUS_LAPTOP section in KConfig.

OK. Though one gotcha I just realized is that this will pull input-polldev into the dependency list for asus-laptop, which may not be desirable just to support one obscure device. But again, that's a small module...

I have a few things to take care of this morning first, hopefully I'll have another version ready in a few hours.

Andy

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d

#10 lore raw
In reply to a message not in the archive
Quoted 8 lines · Andy Ross
Quoted 3 lines · Corentin Chary

If everybody is ok with that, I think you should move the code back into asus-laptop.c. But if you do so, don't forget to modify the help text of ASUS_LAPTOP section in KConfig.

OK.  Though one gotcha I just realized is that this will pull input-polldev into the dependency list for asus-laptop, which may not be desirable just to support one obscure device.  But again, that's a small module...

Maybe you can make pegatron support optional in asus-laptop ? (with a checkbox or something like that)

Signature · 13 lines
Corentin Chary
http://xf.iksaif.net

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Acpi4asus-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/acpi4asus-user
maintainer
#11 lore raw
In reply to Corentin Chary
Quoted 28 lines · Corentin Chary
Quoted 20 lines · Andy Ross
Quoted 10 lines · Corentin Chary
Quoted 5 lines · Dmitry Torokhov

I am happy with the input part but I wonder if it really needs to be separate? If you roll it up into asus-laptop you would not need a new platform device and then it would be what - 20 lines of code?

Corentin, what do you think?

I think that it should be consistent, if there is already some code for pegatron tablet in asus-laptop, then why a new platform device only for the accelerometer ?

No strong feelings here.  I made it a separate file because asus-laptop.c is already very large and this was something that could be fairly easily split out, but obviously it's a really trivial device.

Quoted 2 lines

Andy, what is shared with asus-laptop exactly ? What sysfs files are working and enabled ?  Are backlight and led classes working ?

Quoted 6 lines

Just the key device, which exports the single touch area in the corner of the tablet as KEY_MEDIA.  Some of the other sysfs devices (bluetooth, display, leds) appear because the methods exist, but they're stubbed out in the ASL and thus noops.

Andy

Quoted 7 lines

If everybody is ok with that, I think you should move the code back into asus-laptop.c. But if you do so, don't forget to modify the help text of ASUS_LAPTOP section in KConfig.

Should we also change the description to "Asus/Medion/JVC/Lenovo/Pegatron Extra" ? That seems really ugly but....

"Kitchen sink" so we do not need to adjust the description going forward? ;P

Signature · 5 lines
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html