make ams work with latest kernels
PATCH 1/1 make ams work with latest kernels
For those who don't know: ams, written by Stelian Pop, is a driver for the motion sensor present in some PowerBooks (the series the PowerBook5,6 falls into, later ones have a slightly different one the driver doesn't handle).
Even though we still don't seem to have a client that can actually use this data (something to actually tell the hd to protect itself) I updated the ams code to compile against the latest linux kernel versions. I also fixed a buglet (the interrupt handler should return IRQ_HANDLED even if the init flag isn't set yet since we own the interrupts, they can't be shared).
Stelian and all, how about adding this driver to linux? hdaps seems to be there even if it too doesn't serve a useful purpose at this time.
ams.c +25 -21
@@ -97,7 +97,7 @@ struct ams {int irq1;/* first irq line */ int irq2;/* second irq line */ struct work_struct worker;/* worker thread */ -struct input_dev idev;/* input device */ +struct input_dev *idev;/* input device */ char iactive;/* is the input device active ? */ int xcalib;/* calibrated null value for x */ int ycalib;/* calibrated null value for y */
@@ -110,9 +110,10 @@ static int ams_attach(struct i2c_adapterstatic int ams_detach (struct i2c_adapter *adapter);static struct i2c_driver ams_driver = { - .owner =THIS_MODULE , - .name ="ams" , - .flags =I2C_DF_NOTIFY , + .driver = { + .owner =THIS_MODULE , + .name ="ams" , + }, .attach_adapter = ams_attach, .detach_adapter = ams_detach, };
@@ -210,10 +211,10 @@ static int ams_mouse_kthread(void *data)while (!kthread_should_stop ()) {ams_sensors (&x, &y, &z); -input_report_abs (&ams.idev,ABS_X , x - ams.xcalib); -input_report_abs (&ams.idev,ABS_Y , y - ams.ycalib); +input_report_abs (ams.idev,ABS_X , x - ams.xcalib); +input_report_abs (ams.idev,ABS_Y , y - ams.ycalib); -input_sync (&ams.idev); +input_sync (ams.idev);msleep (25 ); }
@@ -231,22 +232,24 @@ static void ams_mouse_enable(void) ams.xcalib = x; ams.ycalib = y; -init_input_dev (&ams.idev); - ams.idev.name ="ams" ; - ams.idev.dev = &ams.client.dev; - -input_set_abs_params (&ams.idev,ABS_X ,-50 ,50 ,3 ,0 ); -input_set_abs_params (&ams.idev,ABS_Y ,-50 ,50 ,3 ,0 ); - -set_bit (EV_ABS , ams.idev.evbit); -set_bit (EV_KEY , ams.idev.evbit); -set_bit (BTN_TOUCH , ams.idev.keybit); + ams.idev =input_allocate_device (); +if (!ams.idev) +return ; + ams.idev->name ="Apple Motion Sensor" ; + ams.idev->dev = &ams.client.dev; + +input_set_abs_params (ams.idev,ABS_X ,-50 ,50 ,3 ,0 ); +input_set_abs_params (ams.idev,ABS_Y ,-50 ,50 ,3 ,0 ); + +set_bit (EV_ABS , ams.idev->evbit); +set_bit (EV_KEY , ams.idev->evbit); +set_bit (BTN_TOUCH , ams.idev->keybit); ams.kthread =kthread_run (ams_mouse_kthread,NULL ,"kams" );if (IS_ERR (ams.kthread))return ; -input_register_device (&ams.idev); +input_register_device (ams.idev); ams.iactive =1 ; }
@@ -257,7 +260,8 @@ static void ams_mouse_disable(void)kthread_stop (ams.kthread); -input_unregister_device (&ams.idev); +if (ams.idev) +input_unregister_device (ams.idev); ams.iactive =0 ; }
@@ -300,7 +304,7 @@ static void ams_worker(void *data)static irqreturn_t ams_interrupt (int irq,void *devid,struct pt_regs *regs) {if (!ams.init) -return IRQ_NONE ; +return IRQ_HANDLED ;schedule_work (&ams.worker);return IRQ_HANDLED ; }
@@ -471,7 +475,7 @@ static int __init ams_init(void)INIT_WORK (&ams.worker, ams_worker,NULL ); -if ((ams.of_dev =of_platform_device_create (np,"ams" )) ==NULL ) { +if ((ams.of_dev =of_platform_device_create (np,"ams" ,NULL )) ==NULL ) {free_irq (ams.irq1,NULL );free_irq (ams.irq2,NULL );return -ENODEV ;
Quoted 11 lines · Johannes Berg
For those who don't know: ams, written by Stelian Pop, is a driver for the motion sensor present in some PowerBooks (the series the PowerBook5,6 falls into, later ones have a slightly different one the driver doesn't handle).
Even though we still don't seem to have a client that can actually use this data (something to actually tell the hd to protect itself) I updated the ams code to compile against the latest linux kernel versions. I also fixed a buglet (the interrupt handler should return
IRQ_HANDLEDeven if the init flag isn't set yet since we own the interrupts, they can't be shared).
Version 0.3 of ams (from http://popies.net/ams/) already had all those changes :)
The latest version (0.4) has some additionnal changes (fixes a double free induced by the use of input_free_device(), some other more cosmetic changes).
Quoted 2 lines
Stelian and all, how about adding this driver to linux? hdaps seems to be there even if it too doesn't serve a useful purpose at this time.
Ah, I wasn't aware that hdaps was already in. Oh, in this case let's submit it.
Here it comes, along with proper kernel integration (Johannes, I've kept your Signed-off-by since the code is almost the same, feel free to disagree loudly if you must :) ).
---
From: Stelian Pop <[email protected]>
This driver provides support for the Apple Motion Sensor (ams), which provides an accelerometer and other misc. data. Some Apple PowerBooks (the series the PowerBook5,6 falls into, later ones have a slightly different one the driver doesn't handle) are supported. The accelerometer data is readable via sysfs.
This driver also provides an absolute input class device, allowing the laptop to act as a pinball machine-esque joystick.
In the future (once the proper API exist in the block layer) this driver will tell the laptop disk to protect its heads in the event of a catastrophic fall.
---
drivers/hwmon/ams.c | 519 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/hwmon/Kconfig | 17 + drivers/hwmon/Makefile | 1 3 files changed, 537 insertions(+)
drivers/hwmon/Kconfig +17 -0
@@ -450,6 +450,23 @@ config SENSORS_HDAPS Say Y here if you have an applicable laptop and want to experience the awesome power of hdaps. +config SENSORS_AMS + tristate "Apple Motion Sensor (ams)" + depends on HWMON && INPUT && PPC32 + default n + help + This driver provides support for the Apple Motion Sensor (ams), + which provides an accelerometer and other misc. data. + Some Apple PowerBooks (the series the PowerBook5,6 falls into, + later ones have a slightly different one the driver doesn't handle) + are supported. The accelerometer data is readable via sysfs. + + This driver also provides an absolute input class device, allowing + the laptop to act as a pinball machine-esque joystick. + + Say Y here if you have an applicable laptop and want to experience + the awesome power of ams. + config HWMON_DEBUG_CHIP bool "Hardware Monitoring Chip debugging messages" depends on HWMON
drivers/hwmon/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_SENSORS_ADM1026) += adm1026 obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o +obj-$(CONFIG_SENSORS_AMS) += ams.o obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o obj-$(CONFIG_SENSORS_DS1621) += ds1621.o obj-$(CONFIG_SENSORS_F71805F) += f71805f.o
drivers/hwmon/ams.c new file +519 -0
519 lines not on this page · raw message
Signature · 1 line
Stelian Pop <[email protected]>
Quoted 2 lines · Stelian Pop
Version 0.3 of ams (from http://popies.net/ams/) already had all those changes :)
Oh heh. :I downloaded the 2 version a while ago and forgot to check for updates before fixing it up.
Quoted 3 lines
The latest version (0.4) has some additionnal changes (fixes a double free induced by the use of
input_free_device(), some other more cosmetic changes).
Nice :)
Quoted 3 lines
Here it comes, along with proper kernel integration (Johannes, I've kept your Signed-off-by since the code is almost the same, feel free to disagree loudly if you must :) ).
:)
Patch looks good, thanks.
johannes
Hi!
Quoted 10 lines
From: Stelian Pop <[email protected]>
This driver provides support for the Apple Motion Sensor (ams), which provides an accelerometer and other misc. data. Some Apple PowerBooks (the series the PowerBook5,6 falls into, later ones have a slightly different one the driver doesn't handle) are supported. The accelerometer data is readable via sysfs.
This driver also provides an absolute input class device, allowing the laptop to act as a pinball machine-esque joystick.
Is it useful to have /sysfs interface when we already have same data available as joystick?
Signature · 1 line
Thanks for all the (sleeping) penguins.
Quoted 5 lines · Pavel Machek
Quoted 2 lines
This driver also provides an absolute input class device, allowing the laptop to act as a pinball machine-esque joystick.
Is it useful to have /sysfs interface when we already have same data available as joystick?
Might be useful if you need to turn off the "joystick" because X gets confused with it. Other than that, no.
johannes
Quoted 10 lines · Johannes Berg
Quoted 5 lines · Pavel Machek
Quoted 2 lines
This driver also provides an absolute input class device, allowing the laptop to act as a pinball machine-esque joystick.
Is it useful to have /sysfs interface when we already have same data available as joystick?
Might be useful if you need to turn off the "joystick" because X gets confused with it. Other than that, no.
/sysfs interface also exports the 'z' coordinate, the input interface does not.
Stelian.
Signature · 1 line
Stelian Pop <[email protected]>
Quoted 6 lines · Stelian Pop
Quoted 5 lines · Johannes Berg
Quoted 3 lines · Pavel Machek
Quoted 2 lines
This driver also provides an absolute input class device, allowing the laptop to act as a pinball machine-esque joystick.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Is it useful to have /sysfs interface when we already have same data available as joystick?
Might be useful if you need to turn off the "joystick" because X gets confused with it. Other than that, no.
/sysfs interface also exports the 'z' coordinate, the input interface does not.
Can that be fixed? z coordinate should be useful for input, too.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html