Intel Moorestown Analog Accelerometer driver
Subsystems (2)
Hello,
Attached is the patch that adds support for the Analog accelerometer on Intel's Moorestown platform. This has a dependency on the Langwell driver that was submitted to the kernel mailing list but is still not in the mainstream. The patch can be found at
http://lkml.org/lkml/2009/7/20/396. Sending this out here to get any early review comments on the code.
Thanks,
Ramesh
------------------------------------------------------------------------------------
From 3bd9a4332cfd7ec1471cc8beb9495fb2fe7ff84b Mon Sep 17 00:00:00 2001
From: Ramesh Agarwal <[email protected]>
Date: Mon, 10 Aug 2009 11:09:43 +0530
Subject: [PATCH] Intel Moorestown Analog Accelerometer Driver
This patch adds the driver support for the Analog accelerometer on the Moorestown platform. The acceleromater output is hooked to the ADC lines on the PMIC and the driver uses the Langwell IPC to communicate with the PMIC to get the output from the accelerometer.
--- Documentation/hwmon/mrst_analog_accel | 29 +++ drivers/hwmon/Kconfig | 7 + drivers/hwmon/Makefile | 1 + drivers/hwmon/mrst_analog_accel.c | 331 +++++++++++++++++++++++++++++++++ 4 files changed, 368 insertions(+), 0 deletions(-) create mode 100644 Documentation/hwmon/mrst_analog_accel create mode 100644 drivers/hwmon/mrst_analog_accel.c
(quoted diff) +0 -0
b/Documentation/hwmon/mrst_analog_accel
new file mode 100644
index 0000000..a98a861
Documentation/hwmon/mrst_analog_accel new file +28 -0
@@ -0,0 +1,29 @@ +Kernel driver mrst_analog_accel +===============+ +Supported chips: + * PMIC accelerometer for Langwell + Prefix: 'mrst_analog_accel' + +Author: Ramesh Agarwal <[email protected]> + +Description +----------- + +This driver provides support for the analog accelerometer connected +to the Moorestown Platform. The accelerometer is a Freescale MMA7341L +analog device whose Xout, Yout and Zout are connected to the ADC on the +PMIC of the Moorestown platform. + +The driver registers as a platform device driver and presents a single +attribute 'position'. This attribute contains the uncalibrated values +for the x, y and z co-ordinates as read from the ADC. The driver uses +the Langwell IPC driver (LANGWELL_IPC)to read the values from the ADC. +The accelerometer data is readable at /sys/devices/platform/mrst_analog_accel + +The accelerometer operates in the polling mode. This is to say that sampling +by the driver will be done only if a user application has requested for the +values. The driver does not register as an input device, and hence input +calibration and fixing the sampling rate is left to the user level +framework/application. The sysfs interface only provides the decimal values +of the voltage read from the ADC where each bit is equivalent to 2mV.
drivers/hwmon/Kconfig +7 -0
@@ -652,6 +652,13 @@ config SENSORS_MAX6650 This driver can also be built as a module. If so, the module will be called max6650. +config SENSORS_MRST_ANALOG_ACCEL + tristate "Moorestown Analog Accelerometer" + depends on LANGWELL_IPC + help + If you say yes here you get support for the Analog Accelerometer + Device x y Z data can be accessed via sysfs. + config SENSORS_PC87360 tristate "National Semiconductor PC87360 family" select HWMON_VID
drivers/hwmon/Makefile +1 -0
@@ -73,6 +73,7 @@ obj-$(CONFIG_SENSORS_LTC4245) += ltc4245.o obj-$(CONFIG_SENSORS_MAX1111) += max1111.o obj-$(CONFIG_SENSORS_MAX1619) += max1619.o obj-$(CONFIG_SENSORS_MAX6650) += max6650.o +obj-$(CONFIG_SENSORS_MRST_ANALOG_ACCEL) += mrst_analog_accel.o obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
(quoted diff) +0 -0
b/drivers/hwmon/mrst_analog_accel.c
new file mode 100644
index 0000000..366c086
drivers/hwmon/mrst_analog_accel.c new file +319 -0
319 lines not on this page · raw message
Signature · 6 lines
1.5.6 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Ramesh Agarwal says:
Quoted 6 lines
Documentation/hwmon/mrst_analog_accel new file +6
-0+The accelerometer operates in the polling mode. This is to say that sampling +by the driver will be done only if a user application has requested for the +values. The driver does not register as an input device, and hence input +calibration and fixing the sampling rate is left to the user level +framework/application. The sysfs interface only provides the decimal values +of the voltage read from the ADC where each bit is equivalent to 2mV.
...
drivers/hwmon/mrst_analog_accel.c line 41
Quoted 2 lines
drivers/hwmon/mrst_analog_accel.c new file +2
-0+/* PMIC ADC INTERRUPT REGISTERS */ +#define PMIC_ADC_ACC_REG_ADCINT 0x5F/*ADC interrupt register */
Does the accelerometer itself actually provide an interrupt for the data? Can the interrupt be used?
The "ADC interrupt register" seem to hint at that.
Forcing people to poll for interactive data (and that seems to be a very common use for accelerometers these days) is not very nice.
Quoted 5 lines
drivers/hwmon/mrst_analog_accel.c new file +5
-0+static unsigned int analog_accel_read (int offset) +{ +unsigned int ret_val; +struct mrst_pmic_reg_data ipc_data; +
drivers/hwmon/mrst_analog_accel.c line 99
Quoted 10 lines
drivers/hwmon/mrst_analog_accel.c new file +10
-0+ ipc_data.ioc =0 ;/* No need to generate MSI */ + ipc_data.num_entries =2 ; + ipc_data.pmic_reg_data[0 ].register_address > +PMIC_ADC_REG_HIGH (mrst_analog_reg_idx, + offset);/* Higher 8 bits */ + ipc_data.pmic_reg_data[1 ].register_address > +PMIC_ADC_REG_LOW (mrst_analog_reg_idx, + offset);/* Lower 3 bits */ +if (mrst_pmic_ioread (&ipc_data) !=0 ) { +printk (KERN_ERR +"mrst_analog_accel:PMIC reg read using IPC failed\n" ); +return -1 ;
You return -1 in a function returning unsigned?
And you don't handle the -1 anyway, so maybe a more useful value can be returned (like one you'd return when there is no acceleration). Or you can handle the error more sensibly, and return error (if it's possible) from sysfs' _show().
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Alex,
Please see my response inline.
Quoted 23 lines
-----Original Message-----
From: Alex Riesen [mailto:[email protected]]
Sent: Friday, August 14, 2009 12:44 AM
To: Agarwal, Ramesh
Cc: [email protected]; Mark Brown
Subject: Re: Intel Moorestown Analog Accelerometer driverRamesh Agarwal says:
Quoted 1 line
+The accelerometer operates in the polling mode. This is to say that
sampling
Quoted 1 line
+by the driver will be done only if a user application has requested for
the
Quoted 1 line
+values. The driver does not register as an input device, and hence
input
Review
Quoted 2 lines
(quoted diff) +2
-0+calibration and fixing the sampling rate is left to the user level +framework/application. The sysfs interface only provides the decimalvalues
Quoted 1 line
+of the voltage read from the ADC where each bit is equivalent to 2mV.
...
Review
Quoted 2 lines
(quoted diff) +2
-0+/* PMIC ADC INTERRUPT REGISTERS */ +#define PMIC_ADC_ACC_REG_ADCINT 0x5F /*ADC interrupt register*/
Quoted 7 lines
Does the accelerometer itself actually provide an interrupt for the data? Can the interrupt be used?
The "ADC interrupt register" seem to hint at that.
Forcing people to poll for interactive data (and that seems to be a very common use for accelerometers these days) is not very nice.
[Agarwal, Ramesh] The accelerometer unfortunately does not have any interrupt. It just gives the voltage for the current value of the g on the three co-ordinates. The Interrupt being referred to is for the ADC. Once the ADC is started it will sample all the channels (including others which are used by other analog devices) in a round robin fashion. The interrupt is raised when one round of sampling completes.
Quoted 14 lines
Quoted 14 lines
drivers/hwmon/mrst_analog_accel.c new file +13
-0+static unsigned int analog_accel_read (int offset) +{ +unsigned int ret_val; +struct mrst_pmic_reg_data ipc_data; + + ipc_data.ioc =0 ;/* No need to generate MSI */ + ipc_data.num_entries =2 ; + ipc_data.pmic_reg_data[0].register_address > > + PMIC_ADC_REG_HIGH(mrst_analog_reg_idx, + offset);/* Higher 8 bits */ + ipc_data.pmic_reg_data[1].register_address > > + PMIC_ADC_REG_LOW(mrst_analog_reg_idx, + offset);/* Lower 3 bits */ +if (mrst_pmic_ioread (&ipc_data) !=0 ) { + printk(KERN_ERR
Quoted 9 lines
drivers/hwmon/mrst_analog_accel.c line 99
Quoted 2 lines
drivers/hwmon/mrst_analog_accel.c new file +2
-0+ "mrst_analog_accel:PMIC reg read using IPC failed\n"); +return -1 ;You return -1 in a function returning unsigned?
And you don't handle the -1 anyway, so maybe a more useful value can be returned (like one you'd return when there is no acceleration). Or you can handle the error more sensibly, and return error (if it's possible) from sysfs'_show().
[Agarwal, Ramesh] Sending 0xffffffff was kind of my way of indicating an error because the values coming out of the ADC are just 10 bits, so anything larger than that would indicate that there was an error reading the values.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 12 lines · Ramesh
Quoted 5 lines
Ramesh Agarwal says:
Review
Quoted 2 lines
(quoted diff) +2
-0+/* PMIC ADC INTERRUPT REGISTERS */ +#define PMIC_ADC_ACC_REG_ADCINT 0x5F /*ADC interrupt register*/
Quoted 7 lines
Does the accelerometer itself actually provide an interrupt for the data? Can the interrupt be used?
The "ADC interrupt register" seem to hint at that.
Forcing people to poll for interactive data (and that seems to be a very common use for accelerometers these days) is not very nice.
Quoted 7 lines
[Agarwal, Ramesh] The accelerometer unfortunately does not have any interrupt. It just gives the voltage for the current value of the g on the three co-ordinates. The Interrupt being referred to is for the ADC. Once the ADC is started it will sample all the channels (including others which are used by other analog devices) in a round robin fashion. The interrupt is raised when one round of sampling completes.
So, the kernel could activate the line, but the interrupt will cause the ISR be called every sampling cycle irrespective of whether the measured g-values have changed?
Still, it could be interesting to see how the register is programmed:
maybe someone would like to know the values as soon as possible. Maybe someone even implements buffering/filtering of them in the driver, so that the sysfs file can send inotify notifications (or even be polled with poll(2)).
Quoted 1 line
Quoted 1 line
Quoted 1 line
+static unsigned int
analog_accel_read(int offset)
...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
+ if (
mrst_pmic_ioread(&ipc_data)!= 0) {
+ printk(KERN_ERR
+ "mrst_analog_accel:PMIC reg read using IPC failed\n");
+ return -1;
Quoted 8 lines
Quoted 6 lines
You return -1 in a function returning unsigned?
And you don't handle the -1 anyway, so maybe a more useful value can be returned (like one you'd return when there is no acceleration). Or you can handle the error more sensibly, and return error (if it's possible) from sysfs'_show().[Agarwal, Ramesh] Sending
0xffffffffwas kind of my way of indicating an error because the values coming out of the ADC are just 10 bits, so
If they are just 10bits, they certainly fit into any int, so you can use negative
values normally.
Quoted 2 lines
anything larger than that would indicate that there was an error reading the values.
It does not match the sprintf pattern you use.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 32 lines
-----Original Message-----
From: Alex Riesen [mailto:[email protected]]
Sent: Monday, August 17, 2009 2:21 PM
To: Agarwal, Ramesh
Cc: [email protected]; Mark Brown
Subject: Re: Intel Moorestown Analog Accelerometer driverQuoted 3 lines · Ramesh
Quoted 3 lines
Ramesh Agarwal says:
Review
Quoted 2 lines
(quoted diff) +2
-0+/* PMIC ADC INTERRUPT REGISTERS */ +#define PMIC_ADC_ACC_REG_ADCINT 0x5F /*ADC interruptregister
Quoted 9 lines
Quoted 9 lines
*/
Does the accelerometer itself actually provide an interrupt for the data? Can the interrupt be used?
The "ADC interrupt register" seem to hint at that.
Forcing people to poll for interactive data (and that seems to be a very common use for accelerometers these days) is not very nice.
Quoted 7 lines
[Agarwal, Ramesh] The accelerometer unfortunately does not have any interrupt. It just gives the voltage for the current value of the g on the three co-ordinates. The Interrupt being referred to is for the ADC. Once the ADC is started it will sample all the channels (including others which are used by other analog devices) in a round robin fashion. The interrupt is raised when one round of sampling completes.
Quoted 8 lines
So, the kernel could activate the line, but the interrupt will cause the ISR be called every sampling cycle irrespective of whether the measured g-values have changed?
Still, it could be interesting to see how the register is programmed:
maybe someone would like to know the values as soon as possible. Maybe someone even implements buffering/filtering of them in the driver, so that the sysfs file can send inotify notifications (or even be polled with poll(2)).
[Agarwal, Ramesh] You got it right. The interrupt will come no matter what. Also the interrupt will come to the firmware and not directly to the OS since there are multiple devices using the ADC channels. As of now a read on the sysfs attribute will return the last sampled value.
Quoted 17 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+static unsigned int
analog_accel_read(int offset)...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
+ if (
mrst_pmic_ioread(&ipc_data)!= 0) {
+ printk(KERN_ERR
+ "mrst_analog_accel:PMIC reg read using IPC failed\n");
+ return -1;Quoted 8 lines
Quoted 6 lines
You return -1 in a function returning unsigned?
And you don't handle the -1 anyway, so maybe a more useful value can be returned (like one you'd return when there is no acceleration). Or you can handle the error more sensibly, and return error (if it's possible) from sysfs'_show().[Agarwal, Ramesh] Sending
0xffffffffwas kind of my way of indicating an error because the values coming out of the ADC are just 10 bits, so
Quoted 8 lines
If they are just 10bits, they certainly fit into any int, so you can use negative
values normally.Quoted 2 lines
anything larger than that would indicate that there was an error reading the values.
It does not match the sprintf pattern you use.
[Agarwal, Ramesh] I realize that the values are not very explicit right now. I will make the modifications to make them a little more explicit.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors