Pegatron Lucid tablet accelerometer
Subsystems (4)
cover Pegatron Lucid tablet accelerometer
Driver for the ACPI interface to the accelerometer on the Pegatron Lucid tablets (sold as WeTab and ExoPC). I put detection into asus-laptop, as that seems to be the owner of the "\_SB.ATKD." space in ACPI. Hopefully that's the right choice.
Andy
PATCH 1/2 input: Pegatron Lucid accelerometer
From: Andy Ross <[email protected]>
Add driver for the ACPI accelerometer interface on the Pegatron Lucid tablet.
--- drivers/input/misc/Kconfig | 11 +++ drivers/input/misc/Makefile | 2 +- drivers/input/misc/pega-accel.c | 133 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 1 deletions(-) create mode 100644 drivers/input/misc/pega-accel.c
drivers/input/misc/Kconfig +11 -0
@@ -448,4 +448,15 @@ config INPUT_ADXL34X_SPI To compile this driver as a module, choose M here: the module will be called adxl34x-spi. +config INPUT_PEGA_ACCEL + tristate "Support Pegatron Lucid accelerometer" + depends on ASUS_LAPTOP + default y + 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. + endif
drivers/input/misc/Makefile +1 -1
@@ -42,4 +42,4 @@ 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 - +obj-$(CONFIG_INPUT_PEGA_ACCEL) += pega-accel.o
drivers/input/misc/pega-accel.c new file +133 -0
133 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 2/2 asus-laptop: Support pega_accel driver
From: Andy Ross <[email protected]>
Add device detection for the ACPI accelerometer interface on Pegatron Lucid tablets.
--- drivers/platform/x86/asus-laptop.c | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-)
drivers/platform/x86/asus-laptop.c +27 -0
@@ -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
@@ -31,6 +32,7 @@* Josh Green - Light Sens support * Thomas Tuttle - His first patch for led support was very helpfull * Sam Lin - GPS support +* Andy Ross - Pegatron Lucid accelerometer */ #define pr_fmt (fmt) KBUILD_MODNAME ": " fmt
@@ -246,6 +248,7 @@ struct asus_laptop {int wireless_status;bool have_rsts; +bool have_pega_accel;int lcd_state;struct rfkill *gps_rfkill;
@@ -1352,6 +1355,7 @@ static const struct attribute_group asus_attr_group = { .attrs = asus_attributes, }; +static int asus_platform_init (struct asus_laptop *asus) {int result;
@@ -1556,6 +1560,24 @@ static int __devinit asus_acpi_init(struct asus_laptop *asus)return result; } +static struct platform_device pega_accel_dev = { + .name ="pega_accel" , + .id =-1 , +}; + +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 ; + +if (!platform_device_register (&pega_accel_dev)) + asus->have_pega_accel = true; +} +static bool asus_device_present;static int __devinit asus_acpi_add (struct acpi_device *device)
@@ -1605,6 +1627,8 @@ static int __devinit asus_acpi_add(struct acpi_device *device)if (result) goto fail_rfkill; +asus_pega_accel_init (asus); + asus_device_present = true;return 0 ;
@@ -1627,6 +1651,9 @@ static int asus_acpi_remove(struct acpi_device *device, int type) {struct asus_laptop *asus =acpi_driver_data (device); +if (asus->have_pega_accel) +platform_device_unregister (&pega_accel_dev); +asus_backlight_exit (asus);asus_rfkill_exit (asus);asus_led_exit (asus);
Signature · 1 line
1.7.1
Corentin Chary
maintainerRe: [PATCH 1/2] input: Pegatron Lucid accelerometer
In reply to Andy RossQuoted 93 lines · Andy Ross
From: Andy Ross <[email protected]>
Add driver for the ACPI accelerometer interface on the Pegatron Lucid tablet.
Signed-off-by Andy Ross <[email protected]>---
drivers/input/misc/Kconfig | 11 +++drivers/input/misc/Makefile| 2 +-drivers/input/misc/pega-accel.c| 133 +++++++++++++++++++++++++++++++++++++++3 files changed, 145 insertions(+), 1 deletions(-)create mode 100644
drivers/input/misc/pega-accel.cdrivers/input/misc/Kconfig +0
-0@@ -448,4 +448,15 @@ config INPUT_ADXL34X_SPITo compile this driver as a module, choose M here: the module will be called adxl34x-spi.
drivers/input/misc/Kconfig +11
-0+config INPUT_PEGA_ACCEL + tristate "Support Pegatron Lucid accelerometer" + depends on ASUS_LAPTOP + default y + 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. +endif
drivers/input/misc/Makefile +0
-0@@ -42,4 +42,4 @@ obj-$(CONFIG_INPUT_WINBOND_CIR) += winbond-cir.oobj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o obj-$(CONFIG_INPUT_YEALINK) += yealink.o
drivers/input/misc/Makefile +1
-1- +obj-$(CONFIG_INPUT_PEGA_ACCEL) += pega-accel.odrivers/input/misc/pega-accel.c new file +44
-0@@ -0,0 +1,133 @@ +/* +* pega_accel.c - driver for accelerometer in Pegatron Lucid tablets +* +* Copyright (c) 2011 Wind River Systems +* +* Author: Andy Ross <[email protected]> +* +* 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 +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/input-polldev.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <acpi/acpi_bus.h> + +#define DRIVER_NAME "pega_accel" +#define DRIVER_DESC "Pegatron Lucid Tablet Accelerometer" + +/* 1G accel is reported as ~256, so clamp to 2G */ +#define CLAMP 512 + +static struct input_polled_dev *ipdev; + +/* FIXME: this mechanism is *very* slow: ~50ms to read the three +* values. Pre-caching an acpi handle with acpi_get_handle has no +* effect, so the issue isn't in the parsing or tree walking... */ +static int acpi_s16 (char *method) +{ + unsigned long long val = 0; + acpi_evaluate_integer(NULL, method, NULL, &val); + return (short)val; +}
drivers/input/misc/pega-accel.c line 54
Quoted 10 lines
drivers/input/misc/pega-accel.c new file +10
-0+ +static void pega_accel_poll (struct input_polled_dev *ipdev) +{ + /* Note transform, convert to "right/up/out" in the native + * landscape orientation (i.e. the vector is the direction of + * "real up" in the device's cartiesian coordinates). FIXME: + * is there a relevant convention to adhere to? */ + int x = -acpi_s16("\\_SB.ATKD.XLRX"); + int y = -acpi_s16("\\_SB.ATKD.XLRY"); + int z = acpi_s16("\\_SB.ATKD.XLRZ");
Using the absolute path (\\_SB.ATKD) may not work on new hardware, you should find the path of the device using the HID (AKT0100, or something like that). But we may not core in this case since it's pega specific.
drivers/input/misc/pega-accel.c line 60
Quoted 5 lines
drivers/input/misc/pega-accel.c new file +5
-0+ x = clamp_val(x, -CLAMP, CLAMP); + y = clamp_val(y, -CLAMP, CLAMP); + z = clamp_val(z, -CLAMP, CLAMP); + + input_report_abs(ipdev->input, ABS_X, x);
y> + input_report_abs(ipdev->input, ABS_Y, y);
drivers/input/misc/pega-accel.c line 70
Quoted 9 lines
drivers/input/misc/pega-accel.c new file +9
-0+ input_report_abs(ipdev->input, ABS_Z, z); + input_sync(ipdev->input); +} + +static void dev_noop_release (struct device *d) {} + +static int __devinit platform_probe (struct platform_device *pd) +{ + int err = 0;
You should check if the device exists here, before trying to do anything, (using the path or the HID, depending of what you'll do about my previous comment)
Quoted 70 lines
drivers/input/misc/pega-accel.c new file +62
-1+ ipdev = input_allocate_polled_device(); + if (!ipdev) + return -ENOMEM; + + ipdev->poll = pega_accel_poll; + ipdev->poll_interval = 100; + ipdev->poll_interval_min = 10; + ipdev->poll_interval_max = 2000; + + ipdev->input->dev.parent = &pd->dev; + ipdev->input->dev.release = dev_noop_release; + ipdev->input->id.bustype = BUS_HOST; + + ipdev->input->name = DRIVER_DESC; + ipdev->input->phys = DRIVER_NAME "/input0"; + + set_bit(EV_ABS, ipdev->input->evbit); + input_set_abs_params(ipdev->input, ABS_X, -CLAMP, CLAMP, 0, 0); + input_set_abs_params(ipdev->input, ABS_Y, -CLAMP, CLAMP, 0, 0); + input_set_abs_params(ipdev->input, ABS_Z, -CLAMP, CLAMP, 0, 0); + + err = input_register_polled_device(ipdev); + if (err) + input_free_polled_device(ipdev); + + return err; +} + +static int __devexit platform_remove(struct platform_device *pd) +{ + input_unregister_polled_device(ipdev); + input_free_polled_device(ipdev); + ipdev = NULL; + return 0; +} + +static struct platform_driver platform_driver = { + .driver = { + .owner = THIS_MODULE, + .name = DRIVER_NAME, + }, + .probe = platform_probe, + .remove = __devexit_p(platform_remove), +}; + +static int __init mod_init (void ) +{ + return platform_driver_register(&platform_driver); +} + +static void __exit mod_exit(void) +{ + platform_driver_unregister(&platform_driver); +} + +module_init (mod_init); +module_exit (mod_exit); + +MODULE_AUTHOR ("Andy Ross <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION (DRIVER_DESC ); +MODULE_ALIAS ("dmi:*:bvrLucid-CE-133:*" ); --1.7.1
--
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
Signature · 2 lines
Corentin Chary http://xf.iksaif.net
Dmitry Torokhov
maintainerRe: [PATCH 1/2] input: Pegatron Lucid accelerometer
In reply to Andy RossQuoted 18 lines · Andy Ross
From: Andy Ross <[email protected]>
Add driver for the ACPI accelerometer interface on the Pegatron Lucid tablet.
Signed-off-by Andy Ross <[email protected]>--- drivers/input/misc/Kconfig | 11 +++ drivers/input/misc/Makefile | 2 +- drivers/input/misc/pega-accel.c | 133 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 1 deletions(-) create mode 100644 drivers/input/misc/pega-accel.cdrivers/input/misc/Kconfig +0
-0
drivers/input/misc/Kconfig config INPUT_ADXL34X_SPI · line 454
Quoted 7 lines
drivers/input/misc/Kconfig +4
-0@@ -448,4 +448,15 @@ config INPUT_ADXL34X_SPI To compile this driver as a module, choose M here: the module will be called adxl34x-spi. +config INPUT_PEGA_ACCEL + tristate "Support Pegatron Lucid accelerometer" + depends on ASUS_LAPTOP + default y
This is not a critical component; default should be 'n' (or just omit default statement).
Quoted 13 lines
drivers/input/misc/Kconfig +7
-0+ 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. + endifdrivers/input/misc/Makefile +0
-0
drivers/input/misc/Makefile obj-$(CONFIG_INPUT_WINBOND_CIR) += winbond-cir.o · line 45
Quoted 5 lines
drivers/input/misc/Makefile +1
-1@@ -42,4 +42,4 @@ 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 - +obj-$(CONFIG_INPUT_PEGA_ACCEL) += pega-accel.o
Please keep Kconfig and Makefile sorted alphabetically.
drivers/input/misc/pega-accel.c line 2
Quoted 8 lines
drivers/input/misc/pega-accel.c new file +2
-0@@ -0,0 +1,133 @@ +/* +* pega_accel.c - driver for accelerometer in Pegatron Lucid tablets
What's up with people loving to put filename into comments? It just makes renaming files more4 difficult.
Quoted 58 lines
drivers/input/misc/pega-accel.c new file +58
-0+* +* Copyright (c) 2011 Wind River Systems +* +* Author: Andy Ross <[email protected]> +* +* 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 +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/input-polldev.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <acpi/acpi_bus.h> + +#define DRIVER_NAME "pega_accel" +#define DRIVER_DESC "Pegatron Lucid Tablet Accelerometer" + +/* 1G accel is reported as ~256, so clamp to 2G */ +#define CLAMP 512 + +static struct input_polled_dev *ipdev; + +/* FIXME: this mechanism is *very* slow: ~50ms to read the three +* values. Pre-caching an acpi handle with acpi_get_handle has no +* effect, so the issue isn't in the parsing or tree walking... */ +static int acpi_s16 (char *method) +{ +unsigned long long val =0 ; +acpi_evaluate_integer (NULL , method,NULL , &val); +return (short )val; +} + +static void pega_accel_poll (struct input_polled_dev *ipdev) +{ +/* Note transform, convert to "right/up/out" in the native +* landscape orientation (i.e. the vector is the direction of +* "real up" in the device's cartiesian coordinates). FIXME: +* is there a relevant convention to adhere to? */ +int x = -acpi_s16 ("\\_SB.ATKD.XLRX" ); +int y = -acpi_s16 ("\\_SB.ATKD.XLRY" ); +int z =acpi_s16 ("\\_SB.ATKD.XLRZ" ); + + x =clamp_val (x, -CLAMP ,CLAMP ); + y =clamp_val (y, -CLAMP ,CLAMP ); + z =clamp_val (z, -CLAMP ,CLAMP ); + +input_report_abs (ipdev->input,ABS_X , x);
drivers/input/misc/pega-accel.c line 70
Quoted 10 lines
drivers/input/misc/pega-accel.c new file +10
-0+input_report_abs (ipdev->input,ABS_Y , y); +input_report_abs (ipdev->input,ABS_Z , z); +input_sync (ipdev->input); +} + +static void dev_noop_release (struct device *d) {} + +static int __devinit platform_probe (struct platform_device *pd) +{ +int err =0 ;
No need to initialize to 0, in fact, it is quite often dangerous as it masks compiler warnings.
drivers/input/misc/pega-accel.c line 82
Quoted 12 lines
drivers/input/misc/pega-accel.c new file +12
-0+ + ipdev =input_allocate_polled_device (); +if (!ipdev) +return -ENOMEM ; + + ipdev->poll = pega_accel_poll; + ipdev->poll_interval =100 ; + ipdev->poll_interval_min =10 ; + ipdev->poll_interval_max =2000 ; + + ipdev->input->dev.parent = &pd->dev; + ipdev->input->dev.release = dev_noop_release;
WTH is this???
Quoted 54 lines
drivers/input/misc/pega-accel.c new file +51
-0+ ipdev->input->id.bustype =BUS_HOST ; + + ipdev->input->name =DRIVER_DESC ; + ipdev->input->phys =DRIVER_NAME "/input0" ; + +set_bit (EV_ABS , ipdev->input->evbit); +input_set_abs_params (ipdev->input,ABS_X , -CLAMP ,CLAMP ,0 ,0 ); +input_set_abs_params (ipdev->input,ABS_Y , -CLAMP ,CLAMP ,0 ,0 ); +input_set_abs_params (ipdev->input,ABS_Z , -CLAMP ,CLAMP ,0 ,0 ); + + err =input_register_polled_device (ipdev); +if (err) +input_free_polled_device (ipdev); + +return err; +} + +static int __devexit platform_remove(struct platform_device *pd) +{ +input_unregister_polled_device (ipdev); +input_free_polled_device (ipdev); + ipdev =NULL ; +return 0 ; +} + +static struct platform_driver platform_driver = { + .driver = { + .owner =THIS_MODULE , + .name =DRIVER_NAME , + }, + .probe = platform_probe, + .remove =__devexit_p (platform_remove), +}; + +static int __init mod_init (void ) +{ +return platform_driver_register (&platform_driver); +} + +static void __exit mod_exit(void) +{ +platform_driver_unregister (&platform_driver); +} + +module_init (mod_init); +module_exit (mod_exit); + +MODULE_AUTHOR ("Andy Ross <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION (DRIVER_DESC ); +MODULE_ALIAS ("dmi:*:bvrLucid-CE-133:*" );Signature · 1 line
1.7.1
Thanks.
Signature · 1 line
Dmitry