ACER: Add support for accelerometer sensor
Subsystems (2)
PATCH 1/1 ACER: Add support for accelerometer sensor
This device is present on Iconia Tab W500.
--- drivers/platform/x86/acer-wmi.c | 110 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+)
drivers/platform/x86/acer-wmi.c +110 -0
@@ -95,6 +95,7 @@ MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");enum acer_wmi_event_ids {WMID_HOTKEY_EVENT =0x1 , +WMID_ACCEL_EVENT =0x5 , };static const struct key_entry acer_wmi_keymap[] = {
@@ -130,6 +131,7 @@ static const struct key_entry acer_wmi_keymap[] = { };static struct input_dev *acer_wmi_input_dev; +static struct input_dev *acer_wmi_accel_dev;struct event_return_value {u8 function;
@@ -145,6 +147,7 @@ struct event_return_value {#define ACER_WMID3_GDS_THREEG (1<<6)/* 3G */ #define ACER_WMID3_GDS_WIMAX (1<<7)/* WiMAX */ #define ACER_WMID3_GDS_BLUETOOTH (1<<11)/* BT */ +#define ACER_WMID3_GDS_ACCEL (1<<2)/* Accelerometer */ struct lm_input_params {u8 function_num;/* Function Number */
@@ -200,6 +203,7 @@ struct hotkey_function_type_aa {#define ACER_CAP_BLUETOOTH (1<<2)#define ACER_CAP_BRIGHTNESS (1<<3)#define ACER_CAP_THREEG (1<<4) +#define ACER_CAP_ACCEL (1<<5)#define ACER_CAP_ANY (0xFFFFFFFF)/*
@@ -1150,6 +1154,8 @@ static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy) interface->capability |=ACER_CAP_THREEG ;if (type_aa->commun_func_bitmap &ACER_WMID3_GDS_BLUETOOTH ) interface->capability |=ACER_CAP_BLUETOOTH ; +if (type_aa->others_func_bitmap &ACER_WMID3_GDS_ACCEL ) + interface->capability |=ACER_CAP_ACCEL ; commun_fn_key_number = type_aa->commun_fn_key_number; }
@@ -1375,6 +1381,61 @@ static void acer_backlight_exit(void) }/* +* Accelerometer device +*/ +#define ACER_GSENSOR_HANDLE "\\_SB.PCI0.LPC0.SENR" +#define ACER_GSENSOR_INIT "\\_SB.PCI0.LPC0.SENR._INI" +#define ACER_GSENSOR_RDVL "\\_SB.PCI0.LPC0.SENR.RDVL" +static int __devinit acer_gsensor_open (struct input_dev *input) +{ +acpi_handle handle; +acpi_status status; +struct acpi_buffer output; +union acpi_object out_obj; + + status =acpi_get_handle (NULL ,ACER_GSENSOR_HANDLE , &handle); +if (ACPI_FAILURE (status)) +return -1 ; + + output.length =sizeof (out_obj); + output.pointer = &out_obj; + status =acpi_evaluate_object (NULL ,ACER_GSENSOR_INIT ,NULL , &output); +if (ACPI_FAILURE (status)) +return -1 ; + +return 0 ; +} + +static int acer_gsensor_event (void ) +{ +acpi_status status; +struct acpi_buffer output; +union acpi_object out_obj[5 ]; + +if (!has_cap (ACER_CAP_ACCEL )) +return -1 ; + + output.length =sizeof (out_obj); + output.pointer = out_obj; + + status =acpi_evaluate_object (NULL ,ACER_GSENSOR_RDVL ,NULL , &output); +if (ACPI_FAILURE (status)) +return -1 ; + +if (out_obj->package.count !=4 ) +return -1 ; + +input_report_abs (acer_wmi_accel_dev,ABS_X , + (s16 )out_obj->package.elements[0 ].integer.value); +input_report_abs (acer_wmi_accel_dev,ABS_Y , + (s16 )out_obj->package.elements[1 ].integer.value); +input_report_abs (acer_wmi_accel_dev,ABS_Z , + (s16 )out_obj->package.elements[2 ].integer.value); +input_sync (acer_wmi_accel_dev); +return 0 ; +} + +/* * Rfkill devices */ static void acer_rfkill_update (struct work_struct *ignored);
@@ -1649,6 +1710,9 @@ static void acer_wmi_notify(u32 value, void *context) 1, true); }break ; +case WMID_ACCEL_EVENT : +acer_gsensor_event (); +break ;default :pr_warn ("Unknown function number - %d - %d\n" , return_value.function, return_value.key_num);
@@ -1734,6 +1798,41 @@ static int acer_wmi_enable_lm(void)return status; } +static int __init acer_wmi_accel_setup (void ) +{ +int err; + + acer_wmi_accel_dev =input_allocate_device (); +if (!acer_wmi_accel_dev) +return -ENOMEM ; + + acer_wmi_accel_dev->open = acer_gsensor_open; + + acer_wmi_accel_dev->name ="Acer BMA150 accelerometer" ; + acer_wmi_accel_dev->phys ="wmi/input1" ; + acer_wmi_accel_dev->id.bustype =BUS_HOST ; + acer_wmi_accel_dev->evbit[0 ] =BIT_MASK (EV_ABS ); +input_set_abs_params (acer_wmi_accel_dev,ABS_X ,-16384 ,16384 ,0 ,0 ); +input_set_abs_params (acer_wmi_accel_dev,ABS_Y ,-16384 ,16384 ,0 ,0 ); +input_set_abs_params (acer_wmi_accel_dev,ABS_Z ,-16384 ,16384 ,0 ,0 ); + + err =input_register_device (acer_wmi_accel_dev); +if (err) + goto err_free_dev; + +return 0 ; + +err_free_dev: +input_free_device (acer_wmi_accel_dev); +return err; +} + +static void acer_wmi_accel_destroy (void ) +{ +input_unregister_device (acer_wmi_accel_dev); +input_free_device (acer_wmi_accel_dev); +} +static int __init acer_wmi_input_setup (void ) {acpi_status status;
@@ -2066,6 +2165,12 @@ static int __init acer_wmi_init(void)return err; } +if (has_cap (ACER_CAP_ACCEL )) { + err =acer_wmi_accel_setup (); +if (err) + goto error_platform_register; + } + err =platform_driver_register (&acer_platform_driver);if (err) {pr_err ("Unable to register platform driver\n" );
@@ -2109,6 +2214,8 @@ error_device_alloc: error_platform_register:if (wmi_has_guid (ACERWMID_EVENT_GUID ))acer_wmi_input_destroy (); +if (has_cap (ACER_CAP_ACCEL )) +acer_wmi_accel_destroy ();return err; }
@@ -2118,6 +2225,9 @@ static void __exit acer_wmi_exit(void)if (wmi_has_guid (ACERWMID_EVENT_GUID ))acer_wmi_input_destroy (); +if (has_cap (ACER_CAP_ACCEL )) +acer_wmi_accel_destroy (); +remove_sysfs (acer_platform_device);remove_debugfs ();platform_device_unregister (acer_platform_device);
Signature · 1 line
1.7.10
joeyli
maintainerHi Marek,
於 一,2012-05-28 於 01:44 +0200,Marek Vasut 提到:
Quoted 29 lines
This device is present on Iconia Tab W500.
Signed-off-by Marek Vasut <[email protected]>Cc joeyli <[email protected]>--- drivers/platform/x86/acer-wmi.c | 110 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+)drivers/platform/x86/acer-wmi.c +2
-0@@ -95,6 +95,7 @@ MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");enum acer_wmi_event_ids {WMID_HOTKEY_EVENT =0x1 , +WMID_ACCEL_EVENT =0x5 , };static const struct key_entry acer_wmi_keymap[] = {@@ -130,6 +131,7 @@ static const struct key_entry acer_wmi_keymap[] = { };static struct input_dev *acer_wmi_input_dev; +static struct input_dev *acer_wmi_accel_dev;struct event_return_value {u8 function;
drivers/platform/x86/acer-wmi.c struct event_return_value { · line 151
Quoted 5 lines
drivers/platform/x86/acer-wmi.c +1
-0@@ -145,6 +147,7 @@ struct event_return_value {#define ACER_WMID3_GDS_THREEG (1<<6)/* 3G */ #define ACER_WMID3_GDS_WIMAX (1<<7)/* WiMAX */ #define ACER_WMID3_GDS_BLUETOOTH (1<<11)/* BT */ +#define ACER_WMID3_GDS_ACCEL (1<<2)/* Accelerometer */
Please kindly share your dmidecode information:
# dmidecode > dmidecode.log
How did you know '1<<2' reflects to G-sensor? As I know this is a reserved bit did not use before.
Quoted 20 lines
drivers/platform/x86/acer-wmi.c +3
-0struct lm_input_params {u8 function_num;/* Function Number */ @@ -200,6 +203,7 @@ struct hotkey_function_type_aa {#define ACER_CAP_BLUETOOTH (1<<2)#define ACER_CAP_BRIGHTNESS (1<<3)#define ACER_CAP_THREEG (1<<4) +#define ACER_CAP_ACCEL (1<<5)#define ACER_CAP_ANY (0xFFFFFFFF)/* @@ -1150,6 +1154,8 @@ static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy) interface->capability |=ACER_CAP_THREEG ;if (type_aa->commun_func_bitmap &ACER_WMID3_GDS_BLUETOOTH ) interface->capability |=ACER_CAP_BLUETOOTH ; +if (type_aa->others_func_bitmap &ACER_WMID3_GDS_ACCEL ) + interface->capability |=ACER_CAP_ACCEL ; commun_fn_key_number = type_aa->commun_fn_key_number; }
drivers/platform/x86/acer-wmi.c static void acer_backlight_exit(void) · line 1388
Quoted 8 lines
drivers/platform/x86/acer-wmi.c +5
-0@@ -1375,6 +1381,61 @@ static void acer_backlight_exit(void) }/* +* Accelerometer device +*/ +#define ACER_GSENSOR_HANDLE "\\_SB.PCI0.LPC0.SENR" +#define ACER_GSENSOR_INIT "\\_SB.PCI0.LPC0.SENR._INI" +#define ACER_GSENSOR_RDVL "\\_SB.PCI0.LPC0.SENR.RDVL"
I think that will be better don't hard code the path of device in driver, because different models have different path naming.
IMHO, please reference thinkpad_acpi driver like the following:
vi drivers/platform/x86/thinkpad_acpi.c
#define TPACPI_ACPI_EC_HID "PNP0C09"
...
static acpi_handle ec_handle;
...
static int __init probe_for_thinkpad(void)
{
...
/* The EC handler is required */
tpacpi_acpi_handle_locate("ec", TPACPI_ACPI_EC_HID, &ec_handle);static void __init tpacpi_acpi_handle_locate(const char *name, {
...
memset(&device_found, 0, sizeof(device_found));
status = acpi_get_devices(hid, tpacpi_acpi_handle_locate_callback,
(void *)name, &device_found);Quoted 128 lines
drivers/platform/x86/acer-wmi.c +96
-0+static int __devinit acer_gsensor_open (struct input_dev *input) +{ +acpi_handle handle; +acpi_status status; +struct acpi_buffer output; +union acpi_object out_obj; + + status =acpi_get_handle (NULL ,ACER_GSENSOR_HANDLE , &handle); +if (ACPI_FAILURE (status)) +return -1 ; + + output.length =sizeof (out_obj); + output.pointer = &out_obj; + status =acpi_evaluate_object (NULL ,ACER_GSENSOR_INIT ,NULL , &output); +if (ACPI_FAILURE (status)) +return -1 ; + +return 0 ; +} + +static int acer_gsensor_event (void ) +{ +acpi_status status; +struct acpi_buffer output; +union acpi_object out_obj[5 ]; + +if (!has_cap (ACER_CAP_ACCEL )) +return -1 ; + + output.length =sizeof (out_obj); + output.pointer = out_obj; + + status =acpi_evaluate_object (NULL ,ACER_GSENSOR_RDVL ,NULL , &output); +if (ACPI_FAILURE (status)) +return -1 ; + +if (out_obj->package.count !=4 ) +return -1 ; + +input_report_abs (acer_wmi_accel_dev,ABS_X , + (s16 )out_obj->package.elements[0 ].integer.value); +input_report_abs (acer_wmi_accel_dev,ABS_Y , + (s16 )out_obj->package.elements[1 ].integer.value); +input_report_abs (acer_wmi_accel_dev,ABS_Z , + (s16 )out_obj->package.elements[2 ].integer.value); +input_sync (acer_wmi_accel_dev); +return 0 ; +} + +/* * Rfkill devices */ static void acer_rfkill_update (struct work_struct *ignored);@@ -1649,6 +1710,9 @@ static void acer_wmi_notify(u32 value, void *context) 1, true); }break ; +case WMID_ACCEL_EVENT : +acer_gsensor_event (); +break ;default :pr_warn ("Unknown function number - %d - %d\n" , return_value.function, return_value.key_num);@@ -1734,6 +1798,41 @@ static int acer_wmi_enable_lm(void)return status; } +static int __init acer_wmi_accel_setup (void ) +{ +int err; + + acer_wmi_accel_dev =input_allocate_device (); +if (!acer_wmi_accel_dev) +return -ENOMEM ; + + acer_wmi_accel_dev->open = acer_gsensor_open; + + acer_wmi_accel_dev->name ="Acer BMA150 accelerometer" ; + acer_wmi_accel_dev->phys ="wmi/input1" ; + acer_wmi_accel_dev->id.bustype =BUS_HOST ; + acer_wmi_accel_dev->evbit[0 ] =BIT_MASK (EV_ABS ); +input_set_abs_params (acer_wmi_accel_dev,ABS_X ,-16384 ,16384 ,0 ,0 ); +input_set_abs_params (acer_wmi_accel_dev,ABS_Y ,-16384 ,16384 ,0 ,0 ); +input_set_abs_params (acer_wmi_accel_dev,ABS_Z ,-16384 ,16384 ,0 ,0 ); + + err =input_register_device (acer_wmi_accel_dev); +if (err) + goto err_free_dev; + +return 0 ; + +err_free_dev: +input_free_device (acer_wmi_accel_dev); +return err; +} + +static void acer_wmi_accel_destroy (void ) +{ +input_unregister_device (acer_wmi_accel_dev); +input_free_device (acer_wmi_accel_dev); +} +static int __init acer_wmi_input_setup (void ) {acpi_status status;@@ -2066,6 +2165,12 @@ static int __init acer_wmi_init(void)return err; } +if (has_cap (ACER_CAP_ACCEL )) { + err =acer_wmi_accel_setup (); +if (err) + goto error_platform_register; + } + err =platform_driver_register (&acer_platform_driver);if (err) {pr_err ("Unable to register platform driver\n" );@@ -2109,6 +2214,8 @@ error_device_alloc: error_platform_register:if (wmi_has_guid (ACERWMID_EVENT_GUID ))acer_wmi_input_destroy (); +if (has_cap (ACER_CAP_ACCEL )) +acer_wmi_accel_destroy ();return err; }
drivers/platform/x86/acer-wmi.c static void __exit acer_wmi_exit(void) · line 2233
Quoted 9 lines
drivers/platform/x86/acer-wmi.c +3
-0@@ -2118,6 +2225,9 @@ static void __exit acer_wmi_exit(void)if (wmi_has_guid (ACERWMID_EVENT_GUID ))acer_wmi_input_destroy (); +if (has_cap (ACER_CAP_ACCEL )) +acer_wmi_accel_destroy (); +remove_sysfs (acer_platform_device);remove_debugfs ();platform_device_unregister (acer_platform_device);
other stuff looks good to me.
Thanks a lot!
Joey Lee
Dear joeyli,
Quoted 45 lines
Hi Marek,
於 一,2012-05-28 於 01:44 +0200,Marek Vasut 提到:
Quoted 41 lines
This device is present on Iconia Tab W500.
Signed-off-by Marek Vasut <[email protected]>Cc joeyli <[email protected]>---
drivers/platform/x86/acer-wmi.c | 110+++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+)
(quoted diff) +0
-0
b/drivers/platform/x86/acer-wmi.cindex c1a3fd8..2df0673 100644drivers/platform/x86/acer-wmi.c +1
-0@@ -95,6 +95,7 @@MODULE_ALIAS ("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026" );enum acer_wmi_event_ids {WMID_HOTKEY_EVENT =0x1 , +WMID_ACCEL_EVENT =0x5 ,};
static const struct
key_entryacer_wmi_keymap[] = {drivers/platform/x86/acer-wmi.c +1
-0@@ -130,6 +131,7 @@ static const struct key_entry acer_wmi_keymap[] = { };static struct input_dev *acer_wmi_input_dev; +static struct input_dev *acer_wmi_accel_dev;struct
event_return_value{drivers/platform/x86/acer-wmi.c +0
-0u8 function;@@ -145,6 +147,7 @@ struct event_return_value {
Quoted 8 lines
drivers/platform/x86/acer-wmi.c struct event_return_value {
Quoted 5 lines
drivers/platform/x86/acer-wmi.c +1
-0#define ACER_WMID3_GDS_THREEG (1<<6)/* 3G */ #define ACER_WMID3_GDS_WIMAX (1<<7)/* WiMAX */ #define ACER_WMID3_GDS_BLUETOOTH (1<<11)/* BT */ +#define ACER_WMID3_GDS_ACCEL (1<<2)/* Accelerometer */ Please kindly share your dmidecode information:
# dmidecode > dmidecode.log
Will do.
Quoted 2 lines
How did you know '1<<2' reflects to G-sensor? As I know this is a reserved bit did not use before.
Honestly? Wild guess.
Quoted 38 lines
Quoted 38 lines
drivers/platform/x86/acer-wmi.c +0
-0struct lm_input_params {drivers/platform/x86/acer-wmi.c +1
-0u8 function_num;/* Function Number */ @@ -200,6 +203,7 @@ struct hotkey_function_type_aa {#define ACER_CAP_BLUETOOTH (1<<2)#define ACER_CAP_BRIGHTNESS (1<<3)#define ACER_CAP_THREEG (1<<4) +#define ACER_CAP_ACCEL (1<<5)#define
ACER_CAP_ANY(0xFFFFFFFF)/*
drivers/platform/x86/acer-wmi.c +2
-0@@ -1150,6 +1154,8 @@ static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy) interface->capability |=ACER_CAP_THREEG ;if (type_aa->commun_func_bitmap &ACER_WMID3_GDS_BLUETOOTH ) interface->capability |=ACER_CAP_BLUETOOTH ; +if (type_aa->others_func_bitmap &ACER_WMID3_GDS_ACCEL ) + interface->capability |=ACER_CAP_ACCEL ; commun_fn_key_number = type_aa->commun_fn_key_number; }@@ -1375,6 +1381,61 @@ static void acer_backlight_exit(void) }/*
Quoted 8 lines
drivers/platform/x86/acer-wmi.c static void acer_backlight_exit(void) · line 1388
Quoted 5 lines
drivers/platform/x86/acer-wmi.c +5
-0+* Accelerometer device +*/ +#define ACER_GSENSOR_HANDLE "\\_SB.PCI0.LPC0.SENR" +#define ACER_GSENSOR_INIT "\\_SB.PCI0.LPC0.SENR._INI" +#define ACER_GSENSOR_RDVL "\\_SB.PCI0.LPC0.SENR.RDVL"I think that will be better don't hard code the path of device in driver, because different models have different path naming.
Certainly, how should I do it the correct way please?
Quoted 15 lines
IMHO, please reference
thinkpad_acpidriver like the following:vi
drivers/platform/x86/thinkpad_acpi.c#define
TPACPI_ACPI_EC_HID"PNP0C09"
...
staticacpi_handleec_handle;
...static int
__initprobe_for_thinkpad(void)
{
.../* The EC handler is required */ tpacpi_acpi_handle_locate("ec", TPACPI_ACPI_EC_HID, &ec_handle);
Quoted 6 lines
static void
__inittpacpi_acpi_handle_locate(const char *name, {
...memset(&device_found, 0, sizeof(device_found)); status = acpi_get_devices(hid, tpacpi_acpi_handle_locate_callback, (void *)name, &device_found);
I see! Will do (incl. the other driver) Thanks for your guidance here, really, thanks a lot!
Quoted 10 lines
Quoted 10 lines
drivers/platform/x86/acer-wmi.c +3
-0@@ -2118,6 +2225,9 @@ static void __exit acer_wmi_exit(void)if (wmi_has_guid (ACERWMID_EVENT_GUID ))acer_wmi_input_destroy (); +if (has_cap (ACER_CAP_ACCEL )) +acer_wmi_accel_destroy (); +
Quoted 5 lines
drivers/platform/x86/acer-wmi.c static void __exit acer_wmi_exit(void) · line 2233
Quoted 3 lines
drivers/platform/x86/acer-wmi.c +0
-0remove_sysfs (acer_platform_device);remove_debugfs ();platform_device_unregister (acer_platform_device);other stuff looks good to me.
Thanks. Btw I'll update the CC list in V2.
Quoted 3 lines
Thanks a lot!
Joey Lee
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
joeyli
maintainer於 二,2012-05-29 於 07:22 +0200,Marek Vasut 提到:
Quoted 15 lines
Dear joeyli,
Quoted 4 lines
Hi Marek,
於 一,2012-05-28 於 12:34 +0200,Marek Vasut 提到:
[...]
Quoted 6 lines
information about BST0001 and RDVL. I think BST0001 is a special device handle by G-sensor driver on Windows.
But, as our trace on W500 TAB, they didn't return this information through wmi event.
Quoted 9 lines
Quoted 1 line
Currently, only way is GUESS what's the result from RDVL.
Well, I finally figured that out. It's a rotation vector sensor, the result is sin(angle) in x/y/z direction.
It maps to this rotation around a ball:
http://developer.android.com/reference/android/hardware/SensorEvent.html (see Sensor.TYPE_ROTATION_VECTOR: )
I see!
Per my colleague's information, udev should calculate orientation and raise it to X-window.
Quoted 35 lines
Quoted 35 lines
For how to detect G-sensor in machine, BIOS write the device information to type ABh in POST stage, on your machine like this:
OEM-specific Type
Header and Data: AB 27 19 00 01 02 10 04 98 05 02 10 83 43 07 8C 16 2B 00 03 DA 0B 38 01 04 4E 06 0C D2 04 4E 06 0C D2 08 F3 0C 19 E0You can reference my
type_aa_dmi_decodefunction in acer-wmi to parse type AB:The format is:
offset 00: type AB
offset 01: length 27
offset 02 (WORD): HandleThen, follow many devices type and vid/pid, on your machine:
05 02 10 83 43
05 = Audio
1002 = VID
4383 = PID07 8C 16 2B 00
07 = Wireless LAN
168C
002B
...We can guess what's the device type through vid/pid.
Per their document, G-sensor's type is0x0E, but, I didn't see this device from your dmidecode log. It should like this:
Quoted 7 lines
Quoted 3 lines
0E xx xx xx xx
Did you disable G-sensor when you capture dmidecode log?
I don't think it's possible to disable it, it's always enabled it seems to me. It's only possible to flip a switch that makes it stop producing ACPI events.
I am not sure does it possible walk through pci or USB bus to detect G-sensor exist?
If not, then the only one way is always run acer_wmi_accel_setup() to detect "BST0001" exist or not.
Thanks a lot!
Joey Lee