Skip to contentSkip to conversation

add support for Freescale's MMA8653FC 10 bit accelerometer

PATCH Superseded Martin Kepplinger 3 participants 3 messages Mar 18, 2015 – Mar 20, 2015

Subsystems (4)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 add support for Freescale's MMA8653FC 10 bit accelerometer

From: Martin Kepplinger <martin.kepplinger-SN7IsUiht6C/[email protected]>

The MMA8653FC is a low-power, three-axis, capacitive micromachined accelerometer with 10 bits of resolution with flexible user-programmable options.

Embedded interrupt functions enable overall power savings, by relieving the host processor from continuously polling data, for example using the poll() system call.

The device can be configured to generate wake-up interrupt signals from any combination of the configurable embedded functions, enabling the MMA8653FC to monitor events while remaining in a low-power mode during periods of inactivity.

This driver provides devicetree properties to program the device's behaviour and a simple, tested and documented sysfs interface. The data sheet and more information is available on Freescale's website.

---
applies to v4.0-rc4 and the current -next.

patch revision history
......................
v3 moves the driver from drivers/input/misc to drivers/misc v2 corrects licensing and commit messages and adds appropriate recipients

 .../testing/sysfs-bus-i2c-devices-fsl-mma8653fc    |  39 +
 .../devicetree/bindings/misc/fsl,mma8653fc.txt     |  96 +++
 MAINTAINERS                                        |   5 +
 drivers/misc/Kconfig                               |  11 +
 drivers/misc/Makefile                              |   1 +
 drivers/misc/mma8653fc.c                           | 913 +++++++++++++++++++++
 6 files changed, 1065 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c-devices-fsl-mma8653fc
 create mode 100644 Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt
 create mode 100644 drivers/misc/mma8653fc.c
Documentation/ABI/testing/sysfs-bus-i2c-devices-fsl-mma8653fc new file +39 -0
new file mode 100644
index 0000000..8172c27
@@ -0,0 +1,39 @@
+What:		/sys/bus/i2c/drivers/mma8653fc/*/standby
+Date:		March 2015
+Contact:	Martin Kepplinger <martin.kepplinger-SN7IsUiht6C/[email protected]>
+Description:
+		Write 0 to this in order to turn on the device, and 1 to turn
+		it off. Read to see if it is turned on or off.
+
+
+What:		/sys/bus/i2c/drivers/mma8653fc/*/currentmode
+Date:		March 2015
+Contact:	Martin Kepplinger <martin.kepplinger-SN7IsUiht6C/[email protected]>
+Description:
+		Reading this provides the current state of the device, read
+		directly from a register. This can be "standby", "wake" or
+		"sleep".
+
+
+What:		/sys/bus/i2c/drivers/mma8653fc/*/position
+Date:		March 2015
+Contact:	Martin Kepplinger <martin.kepplinger-SN7IsUiht6C/[email protected]>
+Description:
+		Read only. Without interrupts enabled gets current position
+		values by reading. Poll "position" with interrupt conditions
+		set, to get notified; see Documentation/.../fsl,mma8653fc.txt
+
+		position file format:
+		"x y z [landscape/portrait status] [front/back status]"
+
+		x y z values:
+			in mg
+		landscape/portrait status char:
+			r	landscape right
+			d	portrait down
+			u	portrait up
+			l	landscape left
+		front/back status char:
+			f	front facing
+			b	back facing
+
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +96 -0

96 lines not on this page · raw message

MAINTAINERS +5 -0
index 0e1abe8..04c080d 100644
@@ -4104,6 +4104,11 @@ S:	Maintained
 F:	include/linux/platform_data/video-imxfb.h
 F:	drivers/video/fbdev/imxfb.c
 
+FREESCALE MMA8653FC ACCELEROMETER I2C DRIVER
+M:	Martin Kepplinger <martin.kepplinger-SN7IsUiht6C/[email protected]>
+S:	Maintained
+F:	drivers/input/misc/mma8653fc.c
+
 FREESCALE QUAD SPI DRIVER
 M:	Han Xu <[email protected]>
 L:	[email protected]
drivers/misc/Kconfig +11 -0
index 006242c..05ef1c1 100644
@@ -324,6 +324,17 @@ config ISL29020
 	  This driver can also be built as a module.  If so, the module
 	  will be called isl29020.
 
+config MMA8653FC
+	tristate "MMA8653FC - Freescale's 3-Axis, 10-bit Digital Accelerometer"
+	depends on I2C
+	default n
+	help
+	  Say Y here if you want to support Freescale's MMA8653FC Accelerometer
+	  through I2C interface.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mma8653fc.
+
 config SENSORS_TSL2550
 	tristate "Taos TSL2550 ambient light sensor"
 	depends on I2C && SYSFS
drivers/misc/Makefile +1 -0
index 7d5c4cd..044c8fc 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_ICS932S401)	+= ics932s401.o
 obj-$(CONFIG_LKDTM)		+= lkdtm.o
 obj-$(CONFIG_TIFM_CORE)       	+= tifm_core.o
 obj-$(CONFIG_TIFM_7XX1)       	+= tifm_7xx1.o
+obj-$(CONFIG_MMA8653FC)		+= mma8653fc.o
 obj-$(CONFIG_PHANTOM)		+= phantom.o
 obj-$(CONFIG_SENSORS_BH1780)	+= bh1780gli.o
 obj-$(CONFIG_SENSORS_BH1770)	+= bh1770glc.o
drivers/misc/mma8653fc.c new file +913 -0

913 lines not on this page · raw message

Signature · 1 line
2.1.4
#1 lore raw
Quoted 13 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +7 -0
new file mode 100644
index 0000000..3921acb
@@ -0,0 +1,96 @@
+Freescale MMA8653FC 3-axis Accelerometer
+
+Required properties:
+- compatible
+       "fsl,mma8653fc"
+- reg
+       I2C address

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 17

Quoted 10 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +10 -0
+
+Optional properties:
+
+- interrupt-parent
+       a phandle for the interrupt controller (see
+       Documentation/devicetree/bindings/interrupt-controller/interrupts.txt)
+- interrupts
+       interrupt line to which the chip is connected
+- int1
+       set to use interrupt line 1 instead of 2

If you have two interrupt output lines, you should have two entries in interrupts.

You can use interrupt-names to determine which line(s) are wired up.

I don't believe that you need this property.

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 19

Quoted 2 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +2 -0
+- int_active_high
+       set interrupt line active high

s/_/-/ in property names please.

What happens if this isn't set? Is it active-low, or edge-triggered?

It feels like we should be able to query when we need to set this from the IRQ(s).

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 32

Quoted 13 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +13 -0
+- ir_freefall_motion_x
+       activate freefall/motion interrupts on x axis
+- ir_freefall_motion_y
+       activate freefall/motion interrupts on y axis
+- ir_freefall_motion_z
+       activate freefall/motion interrupts on z axis
+- irq_threshold
+       0 < value < 8000: threshold for motion interrupts in mg
+- ir_landscape_portrait
+       activate landscape/portrait interrupts
+- ir_data_ready:
+       activate data-ready interrupts
+       Interrupt events can be activated in any combination.

These all sounds like they would be better as runtime options. I don't see why these should necessarily be in the DT.

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 34

Quoted 2 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +2 -0
+- range
+       2, 4, or 8: range in g, default: 2

Likewise.

It would be nice to have a better qualified name than "range".

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 44

Quoted 10 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +10 -0
+- auto_wake_sleep
+       auto sleep mode (lower frequency)
+- motion_mode
+       use motion mode instead of freefall mode (trigger if >threshold).
+       per default an interrupt occurs if motion values fall below the
+       value set in "threshold" and therefore can detect free fall on the
+       vertical axis (depending on the position of the device).
+       Setting this values inverts the behaviour and an interrupt occurs
+       above the threshold value, so usually activate horizontal axis in
+       this case.

These both sound like they would be better as runtime options.

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 53

Quoted 9 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +9 -0
+
+- x-offset
+       0 < value < 500: calibration offset in mg
+       this value has an offset of 250 itself:
+       0 is -250mg, 250 is 0 mg, 500 is 250mg
+- y-offset
+       see x-offset
+- z-offset
+       see x-offset

I'm unsure about these; it really depends on what the calibration is for.

Mark.

#2 lore raw

Am 2015-03-19 um 17:03 schrieb Mark Rutland:

Quoted 27 lines
Quoted 13 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +7 -0
new file mode 100644
index 0000000..3921acb
@@ -0,0 +1,96 @@
+Freescale MMA8653FC 3-axis Accelerometer
+
+Required properties:
+- compatible
+       "fsl,mma8653fc"
+- reg
+       I2C address

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 17

Quoted 10 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +10 -0
+
+Optional properties:
+
+- interrupt-parent
+       a phandle for the interrupt controller (see
+       Documentation/devicetree/bindings/interrupt-controller/interrupts.txt)
+- interrupts
+       interrupt line to which the chip is connected
+- int1
+       set to use interrupt line 1 instead of 2

If you have two interrupt output lines, you should have two entries in interrupts.

Quoted 2 lines

You can use interrupt-names to determine which line(s) are wired up.

You can't use both interrupt lines. You have to decide on one and all your selected interrupt sources will be on this one line.

Quoted 11 lines

I don't believe that you need this property.

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 19

Quoted 2 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +2 -0
+- int_active_high
+       set interrupt line active high

s/_/-/ in property names please.

What happens if this isn't set? Is it active-low, or edge-triggered?

It feels like we should be able to query when we need to set this from the IRQ(s).

It's active low per default. I investigated and couldn't successfully use active high. In v4 of the patch, this option is gone and documented.

Quoted 15 lines
Quoted 4 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +3 -0
+- ir_freefall_motion_x
+       activate freefall/motion interrupts on x axis
+- ir_freefall_motion_y

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 32

Quoted 10 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +10 -0
+       activate freefall/motion interrupts on y axis
+- ir_freefall_motion_z
+       activate freefall/motion interrupts on z axis
+- irq_threshold
+       0 < value < 8000: threshold for motion interrupts in mg
+- ir_landscape_portrait
+       activate landscape/portrait interrupts
+- ir_data_ready:
+       activate data-ready interrupts
+       Interrupt events can be activated in any combination.
Quoted 2 lines

These all sounds like they would be better as runtime options. I don't see why these should necessarily be in the DT.

First, I don't really want to expand the sysfs ABI much. Second, there are use cases that don't need these at runtime and it would seem to make it even harder for systems to use this driver.

Quoted 7 lines

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 34

Quoted 3 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +2 -0
+- range
+       2, 4, or 8: range in g, default: 2

Likewise.

It would be nice to have a better qualified name than "range".

I use "dynamic-range" in v4 of the patch.

Quoted 24 lines

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 44

Quoted 11 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +10 -0
+- auto_wake_sleep
+       auto sleep mode (lower frequency)
+- motion_mode
+       use motion mode instead of freefall mode (trigger if >threshold).
+       per default an interrupt occurs if motion values fall below the
+       value set in "threshold" and therefore can detect free fall on the
+       vertical axis (depending on the position of the device).
+       Setting this values inverts the behaviour and an interrupt occurs
+       above the threshold value, so usually activate horizontal axis in
+       this case.

These both sound like they would be better as runtime options.

Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt line 53

Quoted 9 lines
Documentation/devicetree/bindings/misc/fsl,mma8653fc.txt new file +9 -0
+
+- x-offset
+       0 < value < 500: calibration offset in mg
+       this value has an offset of 250 itself:
+       0 is -250mg, 250 is 0 mg, 500 is 250mg
+- y-offset
+       see x-offset
+- z-offset
+       see x-offset
Quoted 2 lines

I'm unsure about these; it really depends on what the calibration is for.

this is better documented in v4 of the patch.

Quoted 3 lines

Mark.

thanks for reviewing!

martin