Skip to contentSkip to conversation

iio: accel: add Freescale MMA7455L 3-axis accelerometer driver

PATCH Superseded Joachim Eastwood 6 participants 36 messages Oct 17, 2015 – Nov 8, 2015 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: accel: add Freescale MMA7455L 3-axis accelerometer driver

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

---

 drivers/iio/accel/Kconfig   |  14 ++
 drivers/iio/accel/Makefile  |   1 +
 drivers/iio/accel/mma7455.c | 424 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 439 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.c
drivers/iio/accel/Kconfig +14 -0
index a59047d7657e..8ccb3de85484 100644
@@ -99,6 +99,20 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate "Freescale MMA7455L Accelerometer Driver"
+	depends on I2C || SPI_MASTER
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	select REGMAP_I2C if I2C
+	select REGMAP_SPI if SPI_MASTER
+	help
+	  Say yes here to build support for the Freescale MMA7455L 3-axis
+	  accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455.
+
 config MMA8452
 	tristate "Freescale MMA8452Q Accelerometer Driver"
 	depends on I2C
drivers/iio/accel/Makefile +1 -0
index ebd2675b2a02..6ac9382761f8 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+obj-$(CONFIG_MMA7455)	+= mma7455.o
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.c new file +424 -0

424 lines not on this page · raw message

Signature · 1 line
1.8.0
#1 lore raw
Quoted 7 lines · Joachim Eastwood

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

Looks pretty good in general.

[...];

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+
+static int mma7455_drdy(struct mma7455_data *mma7455)
+{
+	unsigned int reg;
+	int tries = 10;
+	int ret;

drivers/iio/accel/mma7455.c line 78

Quoted 10 lines
drivers/iio/accel/mma7455.c new file +10 -0
+
+	while (tries-- > 0) {
+		ret = regmap_read(mma7455->regmap, MMA7455_REG_STATUS, &reg);
+		if (ret)
+			return ret;
+
+		if (reg & MMA7455_STATUS_DRDY)
+			return 0;
+
+		msleep(20);

I'm not to sure about this, when the IRQ fires the data should either be ready or not, no? Are there any corner cases where waiting for up to 200 ms will generate valid data, whereas not waiting wont?

Quoted 7 lines
drivers/iio/accel/mma7455.c new file +7 -0
+	}
+
+	dev_warn(mma7455->dev, "data not ready\n");
+
+	return -EIO;
+}
+

[...]

Quoted 9 lines
drivers/iio/accel/mma7455.c new file +9 -0
+static int mma7455_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long mask)
+{
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	unsigned int reg = 0;
+	int ret;
+
+	switch (mask) {

drivers/iio/accel/mma7455.c line 129

Quoted 10 lines
drivers/iio/accel/mma7455.c new file +10 -0
+	case IIO_CHAN_INFO_RAW:
+		if (iio_buffer_enabled(indio_dev))
+			return -EBUSY;
+
+		ret = mma7455_drdy(mma7455);
+		if (ret)
+			return ret;
+
+		ret = regmap_bulk_read(mma7455->regmap, chan->scan_index * 2,
+				       &reg, sizeof(s16));

reg is unsigned int while you only read 16 bit. This will cause endianess issues. If you read a hardware register from a external peripheral always use __{be,le}{8,16,32} according to the hardware layout and then use the proper conversion functions {be,le}{8,16,32}_to_cpu() to convert the value to CPU endianness.

Quoted 7 lines
drivers/iio/accel/mma7455.c new file +7 -0
+		if (ret)
+			return ret;
+
+		*val = sign_extend32(reg, 9);
+
+		return IIO_VAL_INT;
+

[...]

drivers/iio/accel/mma7455.c line 203

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+static ssize_t mma7455_show_scale_avail(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	return scnprintf(buf, PAGE_SIZE, "0.%u\n", MMA7455_10BIT_SCALE);
+}

It doesn't make sense to have this at the moment when there is only one valid scale available.

[...]

drivers/iio/accel/mma7455.c line 406

Quoted 13 lines
drivers/iio/accel/mma7455.c new file +13 -0
+static int __init mma7455_modinit(void)
+{
+	int ret;
+#if IS_ENABLED(CONFIG_I2C)
+	ret = i2c_add_driver(&mma7455_i2c_driver);
+	if (ret)
+		pr_err("failed to register MMA7455L I2C driver: %d\n", ret);
+#endif
+#if IS_ENABLED(CONFIG_SPI_MASTER)
+	ret = spi_register_driver(&mma7455_spi_driver);
+	if (ret)
+		pr_err("failed to register MMA7455L SPI driver: %d\n", ret);
+#endif

I know there are a fair amount of bad examples in the IIO tree for this, which do the same thing. But the SPI and the I2C parts should go into different modules, otherwise you run into issues if one of them is built-in while the other is built as a module. The bmg160 gyro driver is a good example on how to do handle this.

Quoted 3 lines
drivers/iio/accel/mma7455.c new file +3 -0
+	return ret;
+}
+module_init(mma7455_modinit);
#2 lore raw

Hi Lars-Peter,

Quoted 24 lines · Lars-Peter Clausen
Quoted 7 lines · Joachim Eastwood

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

Looks pretty good in general.

[...];

Quoted 12 lines
drivers/iio/accel/mma7455.c new file +12 -0
+
+static int mma7455_drdy(struct mma7455_data *mma7455)
+{
+     unsigned int reg;
+     int tries = 10;
+     int ret;
+
+     while (tries-- > 0) {
+             ret = regmap_read(mma7455->regmap, MMA7455_REG_STATUS, &reg);
+             if (ret)
+                     return ret;
+
Quoted 8 lines

drivers/iio/accel/mma7455.c line 78

Quoted 4 lines
drivers/iio/accel/mma7455.c new file +4 -0
+             if (reg & MMA7455_STATUS_DRDY)
+                     return 0;
+
+             msleep(20);

I'm not to sure about this, when the IRQ fires the data should either be ready or not, no? Are there any corner cases where waiting for up to 200 ms will generate valid data, whereas not waiting wont?

At the moment there is no IRQ support and when used in poll mode I think checking DRDY is the safest thing to do.
'tries' is probably set a bit high here. I can lower it to 3. Generating a sample at the lowest sample rate (125 Hz) should take 8ms.

Quoted 25 lines
Quoted 7 lines
drivers/iio/accel/mma7455.c new file +7 -0
+     }
+
+     dev_warn(mma7455->dev, "data not ready\n");
+
+     return -EIO;
+}
+

[...]

Quoted 17 lines
drivers/iio/accel/mma7455.c new file +17 -0
+static int mma7455_read_raw(struct iio_dev *indio_dev,
+                         struct iio_chan_spec const *chan,
+                         int *val, int *val2, long mask)
+{
+     struct mma7455_data *mma7455 = iio_priv(indio_dev);
+     unsigned int reg = 0;
+     int ret;
+
+     switch (mask) {
+     case IIO_CHAN_INFO_RAW:
+             if (iio_buffer_enabled(indio_dev))
+                     return -EBUSY;
+
+             ret = mma7455_drdy(mma7455);
+             if (ret)
+                     return ret;
+
Quoted 8 lines

drivers/iio/accel/mma7455.c line 129

Quoted 2 lines
drivers/iio/accel/mma7455.c new file +2 -0
+             ret = regmap_bulk_read(mma7455->regmap, chan->scan_index * 2,
+                                    &reg, sizeof(s16));

reg is unsigned int while you only read 16 bit. This will cause endianess issues. If you read a hardware register from a external peripheral always use __{be,le}{8,16,32} according to the hardware layout and then use the proper conversion functions {be,le}{8,16,32}_to_cpu() to convert the value to CPU endianness.

Ok, will do.

Quoted 8 lines
Quoted 7 lines
drivers/iio/accel/mma7455.c new file +7 -0
+             if (ret)
+                     return ret;
+
+             *val = sign_extend32(reg, 9);
+
+             return IIO_VAL_INT;
+

[...]

Quoted 9 lines

drivers/iio/accel/mma7455.c line 203

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+static ssize_t mma7455_show_scale_avail(struct device *dev,
+                                     struct device_attribute *attr,
+                                     char *buf)
+{
+     return scnprintf(buf, PAGE_SIZE, "0.%u\n", MMA7455_10BIT_SCALE);
+}

It doesn't make sense to have this at the moment when there is only one valid scale available.

Ok, I'll remove it.

Quoted 12 lines

[...]

Quoted 11 lines
drivers/iio/accel/mma7455.c new file +11 -0
+static int __init mma7455_modinit(void)
+{
+     int ret;
+#if IS_ENABLED(CONFIG_I2C)
+     ret = i2c_add_driver(&mma7455_i2c_driver);
+     if (ret)
+             pr_err("failed to register MMA7455L I2C driver: %d\n", ret);
+#endif
+#if IS_ENABLED(CONFIG_SPI_MASTER)
+     ret = spi_register_driver(&mma7455_spi_driver);
+     if (ret)
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             pr_err("failed to register MMA7455L SPI driver: %d\n", ret);
+#endif

I know there are a fair amount of bad examples in the IIO tree for this, which do the same thing. But the SPI and the I2C parts should go into different modules, otherwise you run into issues if one of them is built-in while the other is built as a module. The bmg160 gyro driver is a good example on how to do handle this.

Ok, I semi-copied from a ASoC CODEC driver. I'll take a look at how bmg160 handles it.

Thanks for reviewing, I'll implement the changes in the next version.

regards,
Joachim Eastwood

#3 lore raw
Quoted 20 lines · Joachim Eastwood
Quoted 11 lines
Quoted 11 lines
drivers/iio/accel/mma7455.c new file +11 -0
+static int __init mma7455_modinit(void)
+{
+     int ret;
+#if IS_ENABLED(CONFIG_I2C)
+     ret = i2c_add_driver(&mma7455_i2c_driver);
+     if (ret)
+             pr_err("failed to register MMA7455L I2C driver: %d\n", ret);
+#endif
+#if IS_ENABLED(CONFIG_SPI_MASTER)
+     ret = spi_register_driver(&mma7455_spi_driver);
+     if (ret)
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             pr_err("failed to register MMA7455L SPI driver: %d\n", ret);
+#endif

I know there are a fair amount of bad examples in the IIO tree for this, which do the same thing. But the SPI and the I2C parts should go into different modules, otherwise you run into issues if one of them is built-in while the other is built as a module. The bmg160 gyro driver is a good example on how to do handle this.

Quoted 2 lines

Ok, I semi-copied from a ASoC CODEC driver. I'll take a look at how bmg160 handles it.

We deprecated this style in ASoC as well. All new drivers that support both SPI and I2C always come with a foobar-spi.c and foobar-i2c.c file. Not all drivers have been updated to this new scheme yet, but I think the majority follows it by now.

#4 lore raw
Quoted 21 lines · Lars-Peter Clausen
Quoted 20 lines · Joachim Eastwood
Quoted 19 lines

drivers/iio/accel/mma7455.c line 406

Quoted 13 lines
drivers/iio/accel/mma7455.c new file +13 -0
+static int __init mma7455_modinit(void)
+{
+     int ret;
+#if IS_ENABLED(CONFIG_I2C)
+     ret = i2c_add_driver(&mma7455_i2c_driver);
+     if (ret)
+             pr_err("failed to register MMA7455L I2C driver: %d\n", ret);
+#endif
+#if IS_ENABLED(CONFIG_SPI_MASTER)
+     ret = spi_register_driver(&mma7455_spi_driver);
+     if (ret)
+             pr_err("failed to register MMA7455L SPI driver: %d\n", ret);
+#endif

I know there are a fair amount of bad examples in the IIO tree for this, which do the same thing. But the SPI and the I2C parts should go into different modules, otherwise you run into issues if one of them is built-in while the other is built as a module. The bmg160 gyro driver is a good example on how to do handle this.

Quoted 7 lines
Quoted 2 lines

Ok, I semi-copied from a ASoC CODEC driver. I'll take a look at how bmg160 handles it.

We deprecated this style in ASoC as well. All new drivers that support both SPI and I2C always come with a foobar-spi.c and foobar-i2c.c file. Not all drivers have been updated to this new scheme yet, but I think the majority follows it by now.

I see.

Only one of the Wolfson CODEC drivers has been split this way in Linus master it seems and it was one of these I took as a template.

regards,
Joachim Eastwood

#5 lore raw
In reply to Joachim Eastwood
Quoted 4 lines

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

please add a link to the datasheet

comments below

Quoted 82 lines

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

---

 drivers/iio/accel/Kconfig   |  14 ++
 drivers/iio/accel/Makefile  |   1 +
 drivers/iio/accel/mma7455.c | 424 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 439 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.c
drivers/iio/accel/Kconfig +14 -0
index a59047d7657e..8ccb3de85484 100644
@@ -99,6 +99,20 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate "Freescale MMA7455L Accelerometer Driver"
+	depends on I2C || SPI_MASTER
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	select REGMAP_I2C if I2C
+	select REGMAP_SPI if SPI_MASTER
+	help
+	  Say yes here to build support for the Freescale MMA7455L 3-axis
+	  accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455.
+
 config MMA8452
 	tristate "Freescale MMA8452Q Accelerometer Driver"
 	depends on I2C
drivers/iio/accel/Makefile +1 -0
index ebd2675b2a02..6ac9382761f8 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+obj-$(CONFIG_MMA7455)	+= mma7455.o
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.c new file +28 -0
new file mode 100644
index 000000000000..fa62f2bcb54a
@@ -0,0 +1,424 @@
+/*
+ * mma7455.c - Support for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * Based on MMA8452Q IIO driver
+ * Copyright 2014 Peter Meerwald <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * UNSUPPORTED hardware features:
+ *  - 8-bit mode with different scales
+ *  - INT1/INT2 interrupts
+ *  - Offset calibration
+ *  - Events
+ */
+
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/module.h>
+#include <linux/regmap.h>

drivers/iio/accel/mma7455.c line 38

Quoted 10 lines
drivers/iio/accel/mma7455.c new file +10 -0
+#include <linux/spi/spi.h>
+
+#define MMA7455_REG_XOUTL		0x00
+#define MMA7455_REG_XOUTH		0x01
+#define MMA7455_REG_YOUTL		0x02
+#define MMA7455_REG_YOUTH		0x03
+#define MMA7455_REG_ZOUTL		0x04
+#define MMA7455_REG_ZOUTH		0x05
+#define MMA7455_REG_STATUS		0x09
+#define  MMA7455_STATUS_DRDY		BIT(0)

whitespace inconsistencies

Quoted 51 lines
drivers/iio/accel/mma7455.c new file +51 -0
+#define MMA7455_REG_WHOAMI		0x0f
+#define  MMA7455_WHOAMI_ID		0x55
+#define MMA7455_REG_MCTL		0x16
+#define  MMA7455_MCTL_MODE_STANDBY	0x00
+#define  MMA7455_MCTL_MODE_MEASURE	0x01
+#define MMA7455_REG_CTL1		0x18
+#define  MMA7455_CTL1_DFBW_MASK		BIT(7)
+#define  MMA7455_CTL1_DFBW_125HZ	BIT(7)
+#define  MMA7455_CTL1_DFBW_62_5HZ	0
+#define MMA7455_REG_TW			0x1e
+
+/*
+ * When MMA7455 is used in 10-bit it has a fullscale of -8g
+ * corresponding to raw value -512. The userspace interface
+ * uses m/s^2 and we declare micro units.
+ * So scale factor is given by:
+ *       g * 8 * 1e6 / 512 = 153228.90625, with g = 9.80665
+ */
+#define MMA7455_10BIT_SCALE	153229
+
+struct mma7455_data {
+	struct regmap *regmap;
+	struct device *dev;
+};
+
+static int mma7455_drdy(struct mma7455_data *mma7455)
+{
+	unsigned int reg;
+	int tries = 10;
+	int ret;
+
+	while (tries-- > 0) {
+		ret = regmap_read(mma7455->regmap, MMA7455_REG_STATUS, &reg);
+		if (ret)
+			return ret;
+
+		if (reg & MMA7455_STATUS_DRDY)
+			return 0;
+
+		msleep(20);
+	}
+
+	dev_warn(mma7455->dev, "data not ready\n");
+
+	return -EIO;
+}
+
+static irqreturn_t mma7455_trigger_handler(int irq, void *p)
+{
+	struct iio_poll_func *pf = p;
+	struct iio_dev *indio_dev = pf->indio_dev;

drivers/iio/accel/mma7455.c line 99

Quoted 10 lines
drivers/iio/accel/mma7455.c new file +10 -0
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	u8 buf[16]; /* 3 x 16-bit channels + padding + ts */
+	int ret;
+
+	ret = mma7455_drdy(mma7455);
+	if (ret)
+		goto done;
+
+	ret = regmap_bulk_read(mma7455->regmap, MMA7455_REG_XOUTL, buf,
+			       sizeof(s16) * 3);

use le16 to hint which endianness the device registers have

Quoted 7 lines
drivers/iio/accel/mma7455.c new file +7 -0
+	if (ret)
+		goto done;
+
+	iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+
+done:
+	iio_trigger_notify_done(indio_dev->trig);

drivers/iio/accel/mma7455.c line 116

Quoted 10 lines
drivers/iio/accel/mma7455.c new file +10 -0
+
+	return IRQ_HANDLED;
+}
+
+static int mma7455_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long mask)
+{
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	unsigned int reg = 0;

initialization not needed

drivers/iio/accel/mma7455.c line 128

Quoted 12 lines
drivers/iio/accel/mma7455.c new file +12 -0
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		if (iio_buffer_enabled(indio_dev))
+			return -EBUSY;
+
+		ret = mma7455_drdy(mma7455);
+		if (ret)
+			return ret;
+
+		ret = regmap_bulk_read(mma7455->regmap, chan->scan_index * 2,

it would be clearer to use chan->address instead of computing the register

instead of s16 I suggest to use le16

using regmap_bulk_read(), there is no endianness conversion; the driver will only work when chip endianness equals CPU endianness

Quoted 32 lines
drivers/iio/accel/mma7455.c new file +32 -0
+				       &reg, sizeof(s16));
+		if (ret)
+			return ret;
+
+		*val = sign_extend32(reg, 9);
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE:
+		*val = 0;
+		*val2 = MMA7455_10BIT_SCALE;
+
+		return IIO_VAL_INT_PLUS_MICRO;
+
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		ret = regmap_read(mma7455->regmap, MMA7455_REG_CTL1, &reg);
+		if (ret)
+			return ret;
+
+		if (reg & MMA7455_CTL1_DFBW_MASK)
+			*val = 250;
+		else
+			*val = 125;
+
+		return IIO_VAL_INT;
+	}
+
+	return -EINVAL;
+}
+
+static int mma7455_write_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,

drivers/iio/accel/mma7455.c line 170

Quoted 10 lines
drivers/iio/accel/mma7455.c new file +10 -0
+			     int val, int val2, long mask)
+{
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	int i;
+
+	if (iio_buffer_enabled(indio_dev))
+		return -EBUSY;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ:

check val2 == 0

Quoted 255 lines
drivers/iio/accel/mma7455.c new file +254 -0
+		if (val == 250)
+			i = MMA7455_CTL1_DFBW_125HZ;
+		else if (val == 125)
+			i = MMA7455_CTL1_DFBW_62_5HZ;
+		else
+			return -EINVAL;
+
+		return regmap_update_bits(mma7455->regmap, MMA7455_REG_CTL1,
+					  MMA7455_CTL1_DFBW_MASK, i);
+
+	case IIO_CHAN_INFO_SCALE:
+		/* In 10-bit mode there is only one scale available */
+		if (val == 0 && val2 == MMA7455_10BIT_SCALE)
+			return 0;
+		break;
+	}
+
+	return -EINVAL;
+}
+
+static ssize_t mma7455_show_samp_freq_avail(struct device *dev,
+					    struct device_attribute *attr,
+					    char *buf)
+{
+	return scnprintf(buf, PAGE_SIZE, "125 250\n");
+}
+
+static ssize_t mma7455_show_scale_avail(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	return scnprintf(buf, PAGE_SIZE, "0.%u\n", MMA7455_10BIT_SCALE);
+}
+
+static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(mma7455_show_samp_freq_avail);
+static IIO_DEVICE_ATTR(in_accel_scale_available, S_IRUGO,
+		       mma7455_show_scale_avail, NULL, 0);
+
+static struct attribute *mma7455_attributes[] = {
+	&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
+	&iio_dev_attr_in_accel_scale_available.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group mma7455_group = {
+	.attrs = mma7455_attributes,
+};
+
+static const struct iio_info mma7455_info = {
+	.attrs = &mma7455_group,
+	.read_raw = mma7455_read_raw,
+	.write_raw = mma7455_write_raw,
+	.driver_module = THIS_MODULE,
+};
+
+#define MMA7455_CHANNEL(axis, idx) { \
+	.type = IIO_ACCEL, \
+	.modified = 1, \
+	.channel2 = IIO_MOD_##axis, \
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
+				    BIT(IIO_CHAN_INFO_SCALE), \
+	.scan_index = idx, \
+	.scan_type = { \
+		.sign = 's', \
+		.realbits = 10, \
+		.storagebits = 16, \
+		.shift = 0, \
+		.endianness = IIO_LE, \
+	}, \
+}
+
+static const struct iio_chan_spec mma7455_channels[] = {
+	MMA7455_CHANNEL(X, 0),
+	MMA7455_CHANNEL(Y, 1),
+	MMA7455_CHANNEL(Z, 2),
+	IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
+static const unsigned long mma7455_scan_masks[] = {0x7, 0};
+
+static int mma7455_probe(struct device *dev, struct regmap *regmap)
+{
+	struct mma7455_data *mma7455;
+	struct iio_dev *indio_dev;
+	unsigned int reg;
+	int ret;
+
+	ret = regmap_read(regmap, MMA7455_REG_WHOAMI, &reg);
+	if (ret) {
+		dev_err(dev, "unable to read reg\n");
+		return ret;
+	}
+
+	if (reg != MMA7455_WHOAMI_ID) {
+		dev_err(dev, "device id mismatch\n");
+		return -ENODEV;
+	}
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*mma7455));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, indio_dev);
+	mma7455 = iio_priv(indio_dev);
+	mma7455->regmap = regmap;
+	mma7455->dev = dev;
+
+	indio_dev->info = &mma7455_info;
+	indio_dev->name = "mma7455l";
+	indio_dev->dev.parent = dev;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = mma7455_channels;
+	indio_dev->num_channels = ARRAY_SIZE(mma7455_channels);
+	indio_dev->available_scan_masks = mma7455_scan_masks;
+
+	regmap_write(mma7455->regmap, MMA7455_REG_MCTL,
+		     MMA7455_MCTL_MODE_MEASURE);
+
+	ret = iio_triggered_buffer_setup(indio_dev, NULL,
+					 mma7455_trigger_handler, NULL);
+	if (ret) {
+		dev_err(dev, "unable to setup triggered buffer\n");
+		return ret;
+	}
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		dev_err(dev, "unable to register device\n");
+		iio_triggered_buffer_cleanup(indio_dev);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int mma7455_remove(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+
+	iio_device_unregister(indio_dev);
+	iio_triggered_buffer_cleanup(indio_dev);
+
+	regmap_write(mma7455->regmap, MMA7455_REG_MCTL,
+		     MMA7455_MCTL_MODE_STANDBY);
+
+	return 0;
+}
+
+static const struct regmap_config mma7455_regmap = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = MMA7455_REG_TW,
+};
+
+#if IS_ENABLED(CONFIG_SPI_MASTER)
+static int mma7455_spi_probe(struct spi_device *spi)
+{
+	struct regmap *regmap;
+
+	regmap = devm_regmap_init_spi(spi, &mma7455_regmap);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	return mma7455_probe(&spi->dev, regmap);
+}
+
+static int mma7455_spi_remove(struct spi_device *spi)
+{
+	return mma7455_remove(&spi->dev);
+}
+
+static const struct spi_device_id mma7455_spi_id[] = {
+	{ "mma7455", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(spi, mma7455_spi_id);
+
+static struct spi_driver mma7455_spi_driver = {
+	.probe = mma7455_spi_probe,
+	.remove = mma7455_spi_remove,
+	.id_table = mma7455_spi_id,
+	.driver = {
+		.name = "mma7455-spi",
+	},
+};
+#endif
+
+#if IS_ENABLED(CONFIG_I2C)
+static int mma7455_i2c_probe(struct i2c_client *i2c,
+			     const struct i2c_device_id *id)
+{
+	struct regmap *regmap;
+
+	regmap = devm_regmap_init_i2c(i2c, &mma7455_regmap);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	return mma7455_probe(&i2c->dev, regmap);
+}
+
+static int mma7455_i2c_remove(struct i2c_client *i2c)
+{
+	return mma7455_remove(&i2c->dev);
+}
+
+static const struct i2c_device_id mma7455_i2c_id[] = {
+	{ "mma7455", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, mma7455_i2c_id);
+
+static struct i2c_driver mma7455_i2c_driver = {
+	.probe = mma7455_i2c_probe,
+	.remove = mma7455_i2c_remove,
+	.id_table = mma7455_i2c_id,
+	.driver = {
+		.name	= "mma7455-i2c",
+	},
+};
+#endif
+
+static int __init mma7455_modinit(void)
+{
+	int ret;
+#if IS_ENABLED(CONFIG_I2C)
+	ret = i2c_add_driver(&mma7455_i2c_driver);
+	if (ret)
+		pr_err("failed to register MMA7455L I2C driver: %d\n", ret);
+#endif
+#if IS_ENABLED(CONFIG_SPI_MASTER)
+	ret = spi_register_driver(&mma7455_spi_driver);
+	if (ret)
+		pr_err("failed to register MMA7455L SPI driver: %d\n", ret);
+#endif
+	return ret;
+}
+module_init(mma7455_modinit);
+
+static void __exit mma7455_exit(void)
+{
+#if IS_ENABLED(CONFIG_I2C)
+	i2c_del_driver(&mma7455_i2c_driver);
+#endif
+#if IS_ENABLED(CONFIG_SPI_MASTER)
+	spi_unregister_driver(&mma7455_spi_driver);
+#endif
+}
+module_exit(mma7455_exit);
+
+MODULE_AUTHOR("Joachim Eastwood <[email protected]>");
+MODULE_DESCRIPTION("Freescale MMA7455L I2C/SPI accelerometer driver");
+MODULE_LICENSE("GPL v2");
Signature · 2 lines
Peter Meerwald
+43-664-2444418 (mobile)
#6 lore raw

Hi Peter,

Quoted 6 lines · Peter Meerwald
Quoted 4 lines

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

please add a link to the datasheet

Sure.

Quoted 89 lines

comments below

Quoted 86 lines

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

---

 drivers/iio/accel/Kconfig   |  14 ++
 drivers/iio/accel/Makefile  |   1 +
 drivers/iio/accel/mma7455.c | 424 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 439 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.c
drivers/iio/accel/Kconfig +14 -0
index a59047d7657e..8ccb3de85484 100644
@@ -99,6 +99,20 @@ config KXCJK1013
        To compile this driver as a module, choose M here: the module will
        be called kxcjk-1013.
 
+config MMA7455
+     tristate "Freescale MMA7455L Accelerometer Driver"
+     depends on I2C || SPI_MASTER
+     select IIO_BUFFER
+     select IIO_TRIGGERED_BUFFER
+     select REGMAP_I2C if I2C
+     select REGMAP_SPI if SPI_MASTER
+     help
+       Say yes here to build support for the Freescale MMA7455L 3-axis
+       accelerometer.
+
+       To compile this driver as a module, choose M here: the module
+       will be called mma7455.
+
 config MMA8452
      tristate "Freescale MMA8452Q Accelerometer Driver"
      depends on I2C
drivers/iio/accel/Makefile +1 -0
index ebd2675b2a02..6ac9382761f8 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)  += kxsd9.o
+obj-$(CONFIG_MMA7455)        += mma7455.o
 obj-$(CONFIG_MMA8452)        += mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)   += mma9551_core.o
drivers/iio/accel/mma7455.c new file +32 -0
new file mode 100644
index 000000000000..fa62f2bcb54a
@@ -0,0 +1,424 @@
+/*
+ * mma7455.c - Support for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * Based on MMA8452Q IIO driver
+ * Copyright 2014 Peter Meerwald <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * UNSUPPORTED hardware features:
+ *  - 8-bit mode with different scales
+ *  - INT1/INT2 interrupts
+ *  - Offset calibration
+ *  - Events
+ */
+
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/spi/spi.h>
+
+#define MMA7455_REG_XOUTL            0x00
+#define MMA7455_REG_XOUTH            0x01
Quoted 8 lines

drivers/iio/accel/mma7455.c line 38

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+#define MMA7455_REG_YOUTL            0x02
+#define MMA7455_REG_YOUTH            0x03
+#define MMA7455_REG_ZOUTL            0x04
+#define MMA7455_REG_ZOUTH            0x05
+#define MMA7455_REG_STATUS           0x09
+#define  MMA7455_STATUS_DRDY         BIT(0)

whitespace inconsistencies

This is actually intentional and used to show that it is a field in a register. If you don't like it I can remove it.

Quoted 55 lines
Quoted 55 lines
drivers/iio/accel/mma7455.c new file +55 -0
+#define MMA7455_REG_WHOAMI           0x0f
+#define  MMA7455_WHOAMI_ID           0x55
+#define MMA7455_REG_MCTL             0x16
+#define  MMA7455_MCTL_MODE_STANDBY   0x00
+#define  MMA7455_MCTL_MODE_MEASURE   0x01
+#define MMA7455_REG_CTL1             0x18
+#define  MMA7455_CTL1_DFBW_MASK              BIT(7)
+#define  MMA7455_CTL1_DFBW_125HZ     BIT(7)
+#define  MMA7455_CTL1_DFBW_62_5HZ    0
+#define MMA7455_REG_TW                       0x1e
+
+/*
+ * When MMA7455 is used in 10-bit it has a fullscale of -8g
+ * corresponding to raw value -512. The userspace interface
+ * uses m/s^2 and we declare micro units.
+ * So scale factor is given by:
+ *       g * 8 * 1e6 / 512 = 153228.90625, with g = 9.80665
+ */
+#define MMA7455_10BIT_SCALE  153229
+
+struct mma7455_data {
+     struct regmap *regmap;
+     struct device *dev;
+};
+
+static int mma7455_drdy(struct mma7455_data *mma7455)
+{
+     unsigned int reg;
+     int tries = 10;
+     int ret;
+
+     while (tries-- > 0) {
+             ret = regmap_read(mma7455->regmap, MMA7455_REG_STATUS, &reg);
+             if (ret)
+                     return ret;
+
+             if (reg & MMA7455_STATUS_DRDY)
+                     return 0;
+
+             msleep(20);
+     }
+
+     dev_warn(mma7455->dev, "data not ready\n");
+
+     return -EIO;
+}
+
+static irqreturn_t mma7455_trigger_handler(int irq, void *p)
+{
+     struct iio_poll_func *pf = p;
+     struct iio_dev *indio_dev = pf->indio_dev;
+     struct mma7455_data *mma7455 = iio_priv(indio_dev);
+     u8 buf[16]; /* 3 x 16-bit channels + padding + ts */
+     int ret;
+
Quoted 8 lines

drivers/iio/accel/mma7455.c line 99

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+     ret = mma7455_drdy(mma7455);
+     if (ret)
+             goto done;
+
+     ret = regmap_bulk_read(mma7455->regmap, MMA7455_REG_XOUTL, buf,
+                            sizeof(s16) * 3);

use le16 to hint which endianness the device registers have

OK.

Quoted 11 lines
Quoted 11 lines
drivers/iio/accel/mma7455.c new file +11 -0
+     if (ret)
+             goto done;
+
+     iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+
+done:
+     iio_trigger_notify_done(indio_dev->trig);
+
+     return IRQ_HANDLED;
+}
+
Quoted 8 lines

drivers/iio/accel/mma7455.c line 116

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+static int mma7455_read_raw(struct iio_dev *indio_dev,
+                         struct iio_chan_spec const *chan,
+                         int *val, int *val2, long mask)
+{
+     struct mma7455_data *mma7455 = iio_priv(indio_dev);
+     unsigned int reg = 0;

initialization not needed

I think it may complain when used in regmap_bulk_read() later. I'll check.

Quoted 6 lines
Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+     int ret;
+
+     switch (mask) {
+     case IIO_CHAN_INFO_RAW:
+             if (iio_buffer_enabled(indio_dev))
+                     return -EBUSY;
Quoted 8 lines

drivers/iio/accel/mma7455.c line 128

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+
+             ret = mma7455_drdy(mma7455);
+             if (ret)
+                     return ret;
+
+             ret = regmap_bulk_read(mma7455->regmap, chan->scan_index * 2,

it would be clearer to use chan->address instead of computing the register

ah, I didn't noticed the address field in chan_spec. I'll use that in the next version.

Quoted 2 lines

instead of s16 I suggest to use le16

OK.

Quoted 2 lines

using regmap_bulk_read(), there is no endianness conversion; the driver will only work when chip endianness equals CPU endianness

I'll add conversion using the to_cpu-functions in the next version.

Quoted 37 lines
Quoted 37 lines
drivers/iio/accel/mma7455.c new file +36 -0
+                                    &reg, sizeof(s16));
+             if (ret)
+                     return ret;
+
+             *val = sign_extend32(reg, 9);
+
+             return IIO_VAL_INT;
+
+     case IIO_CHAN_INFO_SCALE:
+             *val = 0;
+             *val2 = MMA7455_10BIT_SCALE;
+
+             return IIO_VAL_INT_PLUS_MICRO;
+
+     case IIO_CHAN_INFO_SAMP_FREQ:
+             ret = regmap_read(mma7455->regmap, MMA7455_REG_CTL1, &reg);
+             if (ret)
+                     return ret;
+
+             if (reg & MMA7455_CTL1_DFBW_MASK)
+                     *val = 250;
+             else
+                     *val = 125;
+
+             return IIO_VAL_INT;
+     }
+
+     return -EINVAL;
+}
+
+static int mma7455_write_raw(struct iio_dev *indio_dev,
+                          struct iio_chan_spec const *chan,
+                          int val, int val2, long mask)
+{
+     struct mma7455_data *mma7455 = iio_priv(indio_dev);
+     int i;
Quoted 8 lines

drivers/iio/accel/mma7455.c line 170

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+
+     if (iio_buffer_enabled(indio_dev))
+             return -EBUSY;
+
+     switch (mask) {
+     case IIO_CHAN_INFO_SAMP_FREQ:

check val2 == 0

OK.

Quoted 11 lines
Quoted 11 lines
drivers/iio/accel/mma7455.c new file +11 -0
+             if (val == 250)
+                     i = MMA7455_CTL1_DFBW_125HZ;
+             else if (val == 125)
+                     i = MMA7455_CTL1_DFBW_62_5HZ;
+             else
+                     return -EINVAL;
+
+             return regmap_update_bits(mma7455->regmap, MMA7455_REG_CTL1,
+                                       MMA7455_CTL1_DFBW_MASK, i);
+
+     case IIO_CHAN_INFO_SCALE:
Quoted 8 lines

drivers/iio/accel/mma7455.c line 189

Quoted 8 lines
drivers/iio/accel/mma7455.c new file +8 -0
+             /* In 10-bit mode there is only one scale available */
+             if (val == 0 && val2 == MMA7455_10BIT_SCALE)
+                     return 0;
+             break;
+     }
+
+     return -EINVAL;
+}

Thanks for reviewing, I'll implement the changes in the next version.

regards,
Joachim Eastwood

#7 lore raw
Quoted 107 lines
Quoted 6 lines
Quoted 4 lines

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

please add a link to the datasheet

Sure.

Quoted 89 lines

comments below

Quoted 86 lines

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

---

 drivers/iio/accel/Kconfig   |  14 ++
 drivers/iio/accel/Makefile  |   1 +
 drivers/iio/accel/mma7455.c | 424 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 439 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.c
drivers/iio/accel/Kconfig +14 -0
index a59047d7657e..8ccb3de85484 100644
@@ -99,6 +99,20 @@ config KXCJK1013
        To compile this driver as a module, choose M here: the module will
        be called kxcjk-1013.
 
+config MMA7455
+     tristate "Freescale MMA7455L Accelerometer Driver"
+     depends on I2C || SPI_MASTER
+     select IIO_BUFFER
+     select IIO_TRIGGERED_BUFFER
+     select REGMAP_I2C if I2C
+     select REGMAP_SPI if SPI_MASTER
+     help
+       Say yes here to build support for the Freescale MMA7455L 3-axis
+       accelerometer.
+
+       To compile this driver as a module, choose M here: the module
+       will be called mma7455.
+
 config MMA8452
      tristate "Freescale MMA8452Q Accelerometer Driver"
      depends on I2C
drivers/iio/accel/Makefile +1 -0
index ebd2675b2a02..6ac9382761f8 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)  += kxsd9.o
+obj-$(CONFIG_MMA7455)        += mma7455.o
 obj-$(CONFIG_MMA8452)        += mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)   += mma9551_core.o
drivers/iio/accel/mma7455.c new file +32 -0
new file mode 100644
index 000000000000..fa62f2bcb54a
@@ -0,0 +1,424 @@
+/*
+ * mma7455.c - Support for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * Based on MMA8452Q IIO driver
+ * Copyright 2014 Peter Meerwald <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * UNSUPPORTED hardware features:
+ *  - 8-bit mode with different scales
+ *  - INT1/INT2 interrupts
+ *  - Offset calibration
+ *  - Events
+ */
+
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/spi/spi.h>
+
+#define MMA7455_REG_XOUTL            0x00
+#define MMA7455_REG_XOUTH            0x01
Quoted 8 lines

drivers/iio/accel/mma7455.c line 38

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+#define MMA7455_REG_YOUTL            0x02
+#define MMA7455_REG_YOUTH            0x03
+#define MMA7455_REG_ZOUTL            0x04
+#define MMA7455_REG_ZOUTH            0x05
+#define MMA7455_REG_STATUS           0x09
+#define  MMA7455_STATUS_DRDY         BIT(0)

whitespace inconsistencies

Quoted 2 lines

This is actually intentional and used to show that it is a field in a register. If you don't like it I can remove it.

hm, I didn't get it; it's probably a good idea :)

Quoted 86 lines
Quoted 55 lines
Quoted 55 lines
drivers/iio/accel/mma7455.c new file +55 -0
+#define MMA7455_REG_WHOAMI           0x0f
+#define  MMA7455_WHOAMI_ID           0x55
+#define MMA7455_REG_MCTL             0x16
+#define  MMA7455_MCTL_MODE_STANDBY   0x00
+#define  MMA7455_MCTL_MODE_MEASURE   0x01
+#define MMA7455_REG_CTL1             0x18
+#define  MMA7455_CTL1_DFBW_MASK              BIT(7)
+#define  MMA7455_CTL1_DFBW_125HZ     BIT(7)
+#define  MMA7455_CTL1_DFBW_62_5HZ    0
+#define MMA7455_REG_TW                       0x1e
+
+/*
+ * When MMA7455 is used in 10-bit it has a fullscale of -8g
+ * corresponding to raw value -512. The userspace interface
+ * uses m/s^2 and we declare micro units.
+ * So scale factor is given by:
+ *       g * 8 * 1e6 / 512 = 153228.90625, with g = 9.80665
+ */
+#define MMA7455_10BIT_SCALE  153229
+
+struct mma7455_data {
+     struct regmap *regmap;
+     struct device *dev;
+};
+
+static int mma7455_drdy(struct mma7455_data *mma7455)
+{
+     unsigned int reg;
+     int tries = 10;
+     int ret;
+
+     while (tries-- > 0) {
+             ret = regmap_read(mma7455->regmap, MMA7455_REG_STATUS, &reg);
+             if (ret)
+                     return ret;
+
+             if (reg & MMA7455_STATUS_DRDY)
+                     return 0;
+
+             msleep(20);
+     }
+
+     dev_warn(mma7455->dev, "data not ready\n");
+
+     return -EIO;
+}
+
+static irqreturn_t mma7455_trigger_handler(int irq, void *p)
+{
+     struct iio_poll_func *pf = p;
+     struct iio_dev *indio_dev = pf->indio_dev;
+     struct mma7455_data *mma7455 = iio_priv(indio_dev);
+     u8 buf[16]; /* 3 x 16-bit channels + padding + ts */
+     int ret;
+
Quoted 8 lines

drivers/iio/accel/mma7455.c line 99

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+     ret = mma7455_drdy(mma7455);
+     if (ret)
+             goto done;
+
+     ret = regmap_bulk_read(mma7455->regmap, MMA7455_REG_XOUTL, buf,
+                            sizeof(s16) * 3);

use le16 to hint which endianness the device registers have

OK.

Quoted 11 lines
Quoted 11 lines
drivers/iio/accel/mma7455.c new file +11 -0
+     if (ret)
+             goto done;
+
+     iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+
+done:
+     iio_trigger_notify_done(indio_dev->trig);
+
+     return IRQ_HANDLED;
+}
+
Quoted 8 lines

drivers/iio/accel/mma7455.c line 116

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+static int mma7455_read_raw(struct iio_dev *indio_dev,
+                         struct iio_chan_spec const *chan,
+                         int *val, int *val2, long mask)
+{
+     struct mma7455_data *mma7455 = iio_priv(indio_dev);
+     unsigned int reg = 0;

initialization not needed

Quoted 1 line

I think it may complain when used in regmap_bulk_read() later. I'll check.

yes, better leave it in; not sure how _read() is implemented when less then sizeof(unsigned int) is read

Quoted 104 lines
Quoted 15 lines

drivers/iio/accel/mma7455.c line 128

Quoted 13 lines
drivers/iio/accel/mma7455.c new file +12 -0
+     int ret;
+
+     switch (mask) {
+     case IIO_CHAN_INFO_RAW:
+             if (iio_buffer_enabled(indio_dev))
+                     return -EBUSY;
+
+             ret = mma7455_drdy(mma7455);
+             if (ret)
+                     return ret;
+
+             ret = regmap_bulk_read(mma7455->regmap, chan->scan_index * 2,

it would be clearer to use chan->address instead of computing the register

ah, I didn't noticed the address field in chan_spec. I'll use that in the next version.

Quoted 2 lines

instead of s16 I suggest to use le16

OK.

Quoted 2 lines

using regmap_bulk_read(), there is no endianness conversion; the driver will only work when chip endianness equals CPU endianness

I'll add conversion using the to_cpu-functions in the next version.

Quoted 37 lines
Quoted 37 lines
drivers/iio/accel/mma7455.c new file +36 -0
+                                    &reg, sizeof(s16));
+             if (ret)
+                     return ret;
+
+             *val = sign_extend32(reg, 9);
+
+             return IIO_VAL_INT;
+
+     case IIO_CHAN_INFO_SCALE:
+             *val = 0;
+             *val2 = MMA7455_10BIT_SCALE;
+
+             return IIO_VAL_INT_PLUS_MICRO;
+
+     case IIO_CHAN_INFO_SAMP_FREQ:
+             ret = regmap_read(mma7455->regmap, MMA7455_REG_CTL1, &reg);
+             if (ret)
+                     return ret;
+
+             if (reg & MMA7455_CTL1_DFBW_MASK)
+                     *val = 250;
+             else
+                     *val = 125;
+
+             return IIO_VAL_INT;
+     }
+
+     return -EINVAL;
+}
+
+static int mma7455_write_raw(struct iio_dev *indio_dev,
+                          struct iio_chan_spec const *chan,
+                          int val, int val2, long mask)
+{
+     struct mma7455_data *mma7455 = iio_priv(indio_dev);
+     int i;
Quoted 8 lines

drivers/iio/accel/mma7455.c line 170

Quoted 6 lines
drivers/iio/accel/mma7455.c new file +6 -0
+
+     if (iio_buffer_enabled(indio_dev))
+             return -EBUSY;
+
+     switch (mask) {
+     case IIO_CHAN_INFO_SAMP_FREQ:

check val2 == 0

OK.

Quoted 11 lines
Quoted 11 lines
drivers/iio/accel/mma7455.c new file +11 -0
+             if (val == 250)
+                     i = MMA7455_CTL1_DFBW_125HZ;
+             else if (val == 125)
+                     i = MMA7455_CTL1_DFBW_62_5HZ;
+             else
+                     return -EINVAL;
+
+             return regmap_update_bits(mma7455->regmap, MMA7455_REG_CTL1,
+                                       MMA7455_CTL1_DFBW_MASK, i);
+
+     case IIO_CHAN_INFO_SCALE:
Quoted 8 lines

drivers/iio/accel/mma7455.c line 189

Quoted 8 lines
drivers/iio/accel/mma7455.c new file +8 -0
+             /* In 10-bit mode there is only one scale available */
+             if (val == 0 && val2 == MMA7455_10BIT_SCALE)
+                     return 0;
+             break;
+     }
+
+     return -EINVAL;
+}

Thanks for reviewing, I'll implement the changes in the next version.

regards,
Joachim Eastwood

Signature · 2 lines
Peter Meerwald
+43-664-2444418 (mobile)
#8 lore raw
In reply to Joachim Eastwood

Am 2015-10-18 um 00:25 schrieb Joachim Eastwood:

Quoted 8 lines

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

---

Think about adding support for MMA7456L as well. What's the difference between the two, except for the ID?

thanks
martin

#9 lore raw

Hi Martin,

Quoted 5 lines · Martin Kepplinger

Am 2015-10-18 um 00:25 schrieb Joachim Eastwood:

Quoted 4 lines

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

Quoted 7 lines
Quoted 4 lines

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

---

Think about adding support for MMA7456L as well. What's the difference between the two, except for the ID?

I think the driver should work with MMA7456L as well.
I have tried to figure out the difference between the two devices, but the Freescale doesn't list them. One another annoying thing is that the ID isn't actually stated in the data sheet (!). So for MMA7456L I would guess it is 0x56, but there is no way to be sure.

regards,
Joachim Eastwood

#10 lore raw

Am 2015-10-19 um 14:34 schrieb Joachim Eastwood:

Quoted 13 lines

Hi Martin,

Quoted 10 lines · Martin Kepplinger

Am 2015-10-18 um 00:25 schrieb Joachim Eastwood:

Quoted 8 lines

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

---

Quoted 9 lines
Quoted 2 lines

Think about adding support for MMA7456L as well. What's the difference between the two, except for the ID?

I think the driver should work with MMA7456L as well.
I have tried to figure out the difference between the two devices, but the Freescale doesn't list them. One another annoying thing is that the ID isn't actually stated in the data sheet (!). So for MMA7456L I would guess it is 0x56, but there is no way to be sure.

You're right, that's messy. I asked freescale about it and we'll see if/when there's an answer.

thanks
martin

#11 lore raw
Quoted 24 lines · Martin Kepplinger

Am 2015-10-19 um 14:34 schrieb Joachim Eastwood:

Quoted 13 lines

Hi Martin,

Quoted 10 lines · Martin Kepplinger

Am 2015-10-18 um 00:25 schrieb Joachim Eastwood:

Quoted 8 lines

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

---

Quoted 9 lines
Quoted 2 lines

Think about adding support for MMA7456L as well. What's the difference between the two, except for the ID?

I think the driver should work with MMA7456L as well.
I have tried to figure out the difference between the two devices, but the Freescale doesn't list them. One another annoying thing is that the ID isn't actually stated in the data sheet (!). So for MMA7456L I would guess it is 0x56, but there is no way to be sure.

Quoted 2 lines

You're right, that's messy. I asked freescale about it and we'll see if/when there's an answer.

ah, nice. Thanks for taking the time to doing that.

regards,
Joachim Eastwood

#12 lore raw

Am 2015-10-19 um 15:43 schrieb Joachim Eastwood:

Quoted 25 lines · Martin Kepplinger
Quoted 24 lines

Am 2015-10-19 um 14:34 schrieb Joachim Eastwood:

Quoted 22 lines

Hi Martin,

Quoted 5 lines · Martin Kepplinger

Am 2015-10-18 um 00:25 schrieb Joachim Eastwood:

Quoted 4 lines

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

Quoted 7 lines
Quoted 4 lines

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

---

Think about adding support for MMA7456L as well. What's the difference between the two, except for the ID?

I think the driver should work with MMA7456L as well.
I have tried to figure out the difference between the two devices, but the Freescale doesn't list them. One another annoying thing is that the ID isn't actually stated in the data sheet (!). So for MMA7456L I would guess it is 0x56, but there is no way to be sure.

Quoted 5 lines
Quoted 2 lines

You're right, that's messy. I asked freescale about it and we'll see if/when there's an answer.

ah, nice. Thanks for taking the time to doing that.

MMA7456L's WHO_AM_I value should also be 0x55, see
https://community.freescale.com/thread/378035

You could think about renaming the driver to mma745xl which is this "series".

At least you can add MMA7456L to your Kconfig and all your docs.

martin

#13 lore raw
Quoted 29 lines · Martin Kepplinger

Am 2015-10-19 um 15:43 schrieb Joachim Eastwood:

Quoted 28 lines · Martin Kepplinger
Quoted 26 lines

Am 2015-10-19 um 14:34 schrieb Joachim Eastwood:

Quoted 13 lines

Hi Martin,

Quoted 10 lines · Martin Kepplinger

Am 2015-10-18 um 00:25 schrieb Joachim Eastwood:

Quoted 8 lines

Add support for Freescale MMA7455L 3-axis in 10-bit mode with both I2C and SPI bus support. This is a rather simple driver that currently doesn't support all the hardware features of MMA7455L.

Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.

---

Quoted 9 lines
Quoted 2 lines

Think about adding support for MMA7456L as well. What's the difference between the two, except for the ID?

I think the driver should work with MMA7456L as well.
I have tried to figure out the difference between the two devices, but the Freescale doesn't list them. One another annoying thing is that the ID isn't actually stated in the data sheet (!). So for MMA7456L I would guess it is 0x56, but there is no way to be sure.

You're right, that's messy. I asked freescale about it and we'll see if/when there's an answer.

Quoted 8 lines
Quoted 2 lines

ah, nice. Thanks for taking the time to doing that.

MMA7456L's WHO_AM_I value should also be 0x55, see
https://community.freescale.com/thread/378035

You could think about renaming the driver to mma745xl which is this "series".

Please no X's in driver names. That's always a mess if multiple different types of devices match the name. E.g. lets say they release a MMA7459 which is a gyro or whatever in the future.

Just name the driver after the first device supported.

#14 lore raw

PATCH v2 1/1 iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

In reply to Joachim Eastwood

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

---
Hi,

This version address the comments from Lars-Peter Clausen, Peter Meerwald and Martin Kepplinger. Thanks for all the constructive feedback!

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

I compared the register summary for MMA7455L/MMA7456L and I am unable to find any difference at all.

 drivers/iio/accel/Kconfig        |  22 +++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 321 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 478 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/Kconfig +22 -0
index a59047d7657e..3c87a4ae317a 100644
@@ -99,6 +99,28 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer Driver"
+	depends on I2C || SPI_MASTER
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	select MMA7455_I2C if I2C
+	select MMA7455_SPI if SPI
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c or mma7455_spi.
+
+config MMA7455_I2C
+	tristate
+	select REGMAP_I2C
+
+config MMA7455_SPI
+	tristate
+	select REGMAP_SPI
+
 config MMA8452
 	tristate "Freescale MMA8452Q Accelerometer Driver"
 	depends on I2C
drivers/iio/accel/Makefile +5 -0
index ebd2675b2a02..dfb9289393fb 100644
@@ -8,6 +8,11 @@ obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+
+obj-$(CONFIG_MMA7455)		+= mma7455_core.o
+obj-$(CONFIG_MMA7455_I2C)	+= mma7455_i2c.o
+obj-$(CONFIG_MMA7455_SPI)	+= mma7455_spi.o
+
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.h new file +20 -0
new file mode 100644
index 000000000000..8fae9345da88
@@ -0,0 +1,20 @@
+/*
+ * IIO accel header for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#ifndef __MMA7455_H
+#define __MMA7455_H
+
+extern const struct regmap_config mma7455_core_regmap;
+
+int mma7455_core_probe(struct device *dev, struct regmap *regmap,
+		       const char *name);
+int mma7455_core_remove(struct device *dev);
+
+#endif
drivers/iio/accel/mma7455_core.c new file +321 -0

321 lines not on this page · raw message

drivers/iio/accel/mma7455_i2c.c new file +57 -0

57 lines not on this page · raw message

drivers/iio/accel/mma7455_spi.c new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
1.8.0
#15 lore raw

Re: [PATCH v2] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 46 lines · Joachim Eastwood

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

---
Hi,

This version address the comments from Lars-Peter Clausen, Peter Meerwald and Martin Kepplinger. Thanks for all the constructive feedback!

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

I compared the register summary for MMA7455L/MMA7456L and I am unable to find any difference at all.

 drivers/iio/accel/Kconfig        |  22 +++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 321 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 478 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/mma7455_i2c.c new file +3 -0
+static const struct i2c_device_id mma7455_i2c_ids[] = {
+       { "mma7455", 0 },
+       { "mma7456", 0 },

drivers/iio/accel/mma7455_i2c.c

Quoted 10 lines
drivers/iio/accel/mma7455_i2c.c new file +9 -0
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, mma7455_i2c_id);
 
+static const struct spi_device_id mma7455_spi_ids[] = {
+       { "mma7455", 0 },
+       { "mma7456", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(spi, mma7455_spi_id);

Seems like I forgot to do a modular and the kbuild bot caught me. Renamed to *_ids, but forgot to update variable in MODULE_DEVICE_TABLE macro...

I'll send out a new version after people have had a chance to comment on any other issues.

regards,
Joachim Eastwood

#16 lore raw

Re: [PATCH v2] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

In reply to Joachim Eastwood

Am 2015-10-19 um 21:00 schrieb Joachim Eastwood:

Quoted 78 lines

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

---
Hi,

This version address the comments from Lars-Peter Clausen, Peter Meerwald and Martin Kepplinger. Thanks for all the constructive feedback!

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

I compared the register summary for MMA7455L/MMA7456L and I am unable to find any difference at all.

 drivers/iio/accel/Kconfig        |  22 +++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 321 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 478 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/Kconfig +22 -0
index a59047d7657e..3c87a4ae317a 100644
@@ -99,6 +99,28 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer Driver"
+	depends on I2C || SPI_MASTER
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	select MMA7455_I2C if I2C
+	select MMA7455_SPI if SPI
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c or mma7455_spi.
+
+config MMA7455_I2C
+	tristate
+	select REGMAP_I2C
+
+config MMA7455_SPI
+	tristate
+	select REGMAP_SPI
+
 config MMA8452
 	tristate "Freescale MMA8452Q Accelerometer Driver"
 	depends on I2C
drivers/iio/accel/Makefile +0 -0
index ebd2675b2a02..dfb9289393fb 100644

drivers/iio/accel/Makefile

Quoted 1 line
drivers/iio/accel/Makefile +0 -1
--- a/drivers/iio/accel/Makefile

You don't base your work on top of the current -next tree. But that's where this most likely will go, if integrated. Please make it apply to linux-next.

#17 lore raw

Re: [PATCH v2] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 44 lines · Martin Kepplinger

Am 2015-10-19 um 21:00 schrieb Joachim Eastwood:

Quoted 43 lines

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

---
Hi,

This version address the comments from Lars-Peter Clausen, Peter Meerwald and Martin Kepplinger. Thanks for all the constructive feedback!

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

I compared the register summary for MMA7455L/MMA7456L and I am unable to find any difference at all.

 drivers/iio/accel/Kconfig        |  22 +++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 321 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 478 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
Quoted 10 lines

drivers/iio/accel/Makefile

Quoted 6 lines

config MMA8452
tristate "Freescale MMA8452Q Accelerometer Driver" depends on I2C

drivers/iio/accel/Makefile +0 -1
index ebd2675b2a02..dfb9289393fb 100644
--- a/drivers/iio/accel/Makefile

You don't base your work on top of the current -next tree. But that's where this most likely will go, if integrated. Please make it apply to linux-next.

Sure I can based it off linux-next or would one of the branches on git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git be better?

regards,
Joachim Eastwood

maintainer
#18 lore raw

Re: [PATCH v2] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 56 lines · Joachim Eastwood
Quoted 44 lines · Martin Kepplinger

Am 2015-10-19 um 21:00 schrieb Joachim Eastwood:

Quoted 43 lines

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

---
Hi,

This version address the comments from Lars-Peter Clausen, Peter Meerwald and Martin Kepplinger. Thanks for all the constructive feedback!

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

I compared the register summary for MMA7455L/MMA7456L and I am unable to find any difference at all.

 drivers/iio/accel/Kconfig        |  22 +++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 321 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 478 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
Quoted 10 lines

drivers/iio/accel/Makefile

Quoted 6 lines

config MMA8452
tristate "Freescale MMA8452Q Accelerometer Driver" depends on I2C

drivers/iio/accel/Makefile +0 -1
index ebd2675b2a02..dfb9289393fb 100644
--- a/drivers/iio/accel/Makefile

You don't base your work on top of the current -next tree. But that's where this most likely will go, if integrated. Please make it apply to linux-next.

Quoted 2 lines

Sure I can based it off linux-next or would one of the branches on git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git be better?

It doesn't matter that much unless lots of work is being done on a given driver. Either linux-next or the togreg branch of the above.

The testing branch usually contains the latest stuff but may rebase as it's really there for automated builds.

Actually I don't really mind basing on last full kernel release either or on staging-next which is our upstream.

At worst you get a tiny bit of merge fun.

Jonathan

Quoted 5 lines

regards,
Joachim Eastwood

#19 lore raw

Re: [PATCH v2] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

In reply to Joachim Eastwood

On 10/19/2015 09:00 PM, Joachim Eastwood wrote:
[...]

drivers/iio/accel/Kconfig config KXCJK1013 · line 108

Quoted 7 lines
drivers/iio/accel/Kconfig +7 -0
+config MMA7455
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer Driver"
+	depends on I2C || SPI_MASTER
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	select MMA7455_I2C if I2C
+	select MMA7455_SPI if SPI

Ah, damm, I shouldn't have said bmg160 is a good example without actually looking at its Kconfig entry. Only saw the C files and those looked good.

This is still problematic. The depends on clause allows this driver to be built-in if either I2C is built-in or SPI_MASTER is built-in. And then the respective I2C and SPI modules will also be selected as built-in even though the I2C symbol is only selected as a module. So you now have built-in code that tries to reference code that is only available as a module.

A better solution is to make the Kconfig entries for the I2C and SPI modules user selectable and then let them select the main module.

Quoted 15 lines
drivers/iio/accel/Kconfig +15 -0
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c or mma7455_spi.
+
+config MMA7455_I2C
+	tristate
+	select REGMAP_I2C
+
+config MMA7455_SPI
+	tristate
+	select REGMAP_SPI
+
#20 lore raw

Re: [PATCH v2] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 13 lines · Lars-Peter Clausen

On 10/19/2015 09:00 PM, Joachim Eastwood wrote:
[...]

drivers/iio/accel/Kconfig config KXCJK1013 · line 108

Quoted 7 lines
drivers/iio/accel/Kconfig +7 -0
+config MMA7455
+     tristate "Freescale MMA7455L/MMA7456L Accelerometer Driver"
+     depends on I2C || SPI_MASTER
+     select IIO_BUFFER
+     select IIO_TRIGGERED_BUFFER
+     select MMA7455_I2C if I2C
+     select MMA7455_SPI if SPI

Ah, damm, I shouldn't have said bmg160 is a good example without actually looking at its Kconfig entry. Only saw the C files and those looked good.

Quoted 8 lines

This is still problematic. The depends on clause allows this driver to be built-in if either I2C is built-in or SPI_MASTER is built-in. And then the respective I2C and SPI modules will also be selected as built-in even though the I2C symbol is only selected as a module. So you now have built-in code that tries to reference code that is only available as a module.

A better solution is to make the Kconfig entries for the I2C and SPI modules user selectable and then let them select the main module.

Something like this:

config MMA7455
tristate

config MMA7455_I2C
tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver" depends on I2C
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
select MMA7455
select REGMAP_I2C
help
...

config MMA7455_SPI
tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver" depends on SPI_MASTER
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
select MMA7455
select REGMAP_SPI
help
...

regards,
Joachim Eastwood

#21 lore raw

Re: [PATCH v2] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 38 lines · Joachim Eastwood
Quoted 13 lines · Lars-Peter Clausen

On 10/19/2015 09:00 PM, Joachim Eastwood wrote:
[...]

drivers/iio/accel/Kconfig config KXCJK1013 · line 108

Quoted 7 lines
drivers/iio/accel/Kconfig +7 -0
+config MMA7455
+     tristate "Freescale MMA7455L/MMA7456L Accelerometer Driver"
+     depends on I2C || SPI_MASTER
+     select IIO_BUFFER
+     select IIO_TRIGGERED_BUFFER
+     select MMA7455_I2C if I2C
+     select MMA7455_SPI if SPI

Ah, damm, I shouldn't have said bmg160 is a good example without actually looking at its Kconfig entry. Only saw the C files and those looked good.

Quoted 8 lines

This is still problematic. The depends on clause allows this driver to be built-in if either I2C is built-in or SPI_MASTER is built-in. And then the respective I2C and SPI modules will also be selected as built-in even though the I2C symbol is only selected as a module. So you now have built-in code that tries to reference code that is only available as a module.

A better solution is to make the Kconfig entries for the I2C and SPI modules user selectable and then let them select the main module.

Something like this:

config MMA7455
tristate

config MMA7455_I2C
tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver" depends on I2C
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
select MMA7455
select REGMAP_I2C
help
...

Quoted 9 lines

config MMA7455_SPI
tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver" depends on SPI_MASTER
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
select MMA7455
select REGMAP_SPI
help
...

Yes, but move the select IIO_BUFFER and IIO_TRIGGERED_BUFFER to the shared symbol.

#22 lore raw

Re: [PATCH v2] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 49 lines · Lars-Peter Clausen
Quoted 38 lines · Joachim Eastwood
Quoted 13 lines · Lars-Peter Clausen

On 10/19/2015 09:00 PM, Joachim Eastwood wrote:
[...]

drivers/iio/accel/Kconfig config KXCJK1013 · line 108

Quoted 7 lines
drivers/iio/accel/Kconfig +7 -0
+config MMA7455
+     tristate "Freescale MMA7455L/MMA7456L Accelerometer Driver"
+     depends on I2C || SPI_MASTER
+     select IIO_BUFFER
+     select IIO_TRIGGERED_BUFFER
+     select MMA7455_I2C if I2C
+     select MMA7455_SPI if SPI

Ah, damm, I shouldn't have said bmg160 is a good example without actually looking at its Kconfig entry. Only saw the C files and those looked good.

Quoted 8 lines

This is still problematic. The depends on clause allows this driver to be built-in if either I2C is built-in or SPI_MASTER is built-in. And then the respective I2C and SPI modules will also be selected as built-in even though the I2C symbol is only selected as a module. So you now have built-in code that tries to reference code that is only available as a module.

A better solution is to make the Kconfig entries for the I2C and SPI modules user selectable and then let them select the main module.

Something like this:

config MMA7455
tristate

config MMA7455_I2C
tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver" depends on I2C
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
select MMA7455
select REGMAP_I2C
help
...

Quoted 9 lines

config MMA7455_SPI
tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver" depends on SPI_MASTER
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
select MMA7455
select REGMAP_SPI
help
...

Quoted 2 lines

Yes, but move the select IIO_BUFFER and IIO_TRIGGERED_BUFFER to the shared symbol.

ah, yes, that is better. Thanks.

regards,
Joachim Eastwood

#23 lore raw

PATCH v3 1/1 iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

In reply to Joachim Eastwood

Add support for Freescale MMA7455L/MMA7456L 3-axis accelerometer in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/ MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

---
Hi,

This version address the comments from Lars-Peter Clausen and Martin Kepplinger. Plus a build fix for modular and a rebase.

Changes since v2:
* fix id variable name in MODULE_DEVICE_TABLE
* make MMA7455_{I2C,SPI} symbols selectable
* rebase on linux-next (tag next-20151020)

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

 drivers/iio/accel/Kconfig        |  29 ++++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 321 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 485 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/Kconfig +29 -0
index 969428dd6329..728a7761aaa6 100644
@@ -107,6 +107,35 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+
+config MMA7455_I2C
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver"
+	depends on I2C
+	select MMA7455
+	select REGMAP_I2C
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c.
+
+config MMA7455_SPI
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver"
+	depends on SPI_MASTER
+	select MMA7455
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_spi.
+
 config MMA8452
 	tristate "Freescale MMA8452Q and similar Accelerometers Driver"
 	depends on I2C
drivers/iio/accel/Makefile +5 -0
index 7925f166e6e9..7ea21f8b7d98 100644
@@ -10,6 +10,11 @@ obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+
+obj-$(CONFIG_MMA7455)		+= mma7455_core.o
+obj-$(CONFIG_MMA7455_I2C)	+= mma7455_i2c.o
+obj-$(CONFIG_MMA7455_SPI)	+= mma7455_spi.o
+
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.h new file +20 -0
new file mode 100644
index 000000000000..8fae9345da88
@@ -0,0 +1,20 @@
+/*
+ * IIO accel header for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#ifndef __MMA7455_H
+#define __MMA7455_H
+
+extern const struct regmap_config mma7455_core_regmap;
+
+int mma7455_core_probe(struct device *dev, struct regmap *regmap,
+		       const char *name);
+int mma7455_core_remove(struct device *dev);
+
+#endif
drivers/iio/accel/mma7455_core.c new file +321 -0

321 lines not on this page · raw message

drivers/iio/accel/mma7455_i2c.c new file +57 -0

57 lines not on this page · raw message

drivers/iio/accel/mma7455_spi.c new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
1.8.0
maintainer
#24 lore raw

Re: [PATCH v3] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 5 lines · Joachim Eastwood

Add support for Freescale MMA7455L/MMA7456L 3-axis accelerometer in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/ MMA7456L.

Quoted 7 lines

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

Looks pretty good to me. A few comments inline.
If we hadn't unfortunately just missed the merge window for IIO I'd have probably taken it as is, but now we have plenty of time to tidy up a few corners without effecting when people get to play with it in distros.

Jonathan

Quoted 277 lines

---
Hi,

This version address the comments from Lars-Peter Clausen and Martin Kepplinger. Plus a build fix for modular and a rebase.

Changes since v2:
* fix id variable name in MODULE_DEVICE_TABLE
* make MMA7455_{I2C,SPI} symbols selectable
* rebase on linux-next (tag next-20151020)

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

 drivers/iio/accel/Kconfig        |  29 ++++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 321 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 485 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/Kconfig +29 -0
index 969428dd6329..728a7761aaa6 100644
@@ -107,6 +107,35 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+
+config MMA7455_I2C
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver"
+	depends on I2C
+	select MMA7455
+	select REGMAP_I2C
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c.
+
+config MMA7455_SPI
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver"
+	depends on SPI_MASTER
+	select MMA7455
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_spi.
+
 config MMA8452
 	tristate "Freescale MMA8452Q and similar Accelerometers Driver"
 	depends on I2C
drivers/iio/accel/Makefile +5 -0
index 7925f166e6e9..7ea21f8b7d98 100644
@@ -10,6 +10,11 @@ obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+
+obj-$(CONFIG_MMA7455)		+= mma7455_core.o
+obj-$(CONFIG_MMA7455_I2C)	+= mma7455_i2c.o
+obj-$(CONFIG_MMA7455_SPI)	+= mma7455_spi.o
+
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.h new file +20 -0
new file mode 100644
index 000000000000..8fae9345da88
@@ -0,0 +1,20 @@
+/*
+ * IIO accel header for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#ifndef __MMA7455_H
+#define __MMA7455_H
+
+extern const struct regmap_config mma7455_core_regmap;
+
+int mma7455_core_probe(struct device *dev, struct regmap *regmap,
+		       const char *name);
+int mma7455_core_remove(struct device *dev);
+
+#endif
drivers/iio/accel/mma7455_core.c new file +155 -0
new file mode 100644
index 000000000000..dbe5db9a8322
@@ -0,0 +1,321 @@
+/*
+ * IIO accel core driver for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * UNSUPPORTED hardware features:
+ *  - 8-bit mode with different scales
+ *  - INT1/INT2 interrupts
+ *  - Offset calibration
+ *  - Events
+ */
+
+#include <linux/delay.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+
+#include "mma7455.h"
+
+#define MMA7455_REG_XOUTL		0x00
+#define MMA7455_REG_XOUTH		0x01
+#define MMA7455_REG_YOUTL		0x02
+#define MMA7455_REG_YOUTH		0x03
+#define MMA7455_REG_ZOUTL		0x04
+#define MMA7455_REG_ZOUTH		0x05
+#define MMA7455_REG_STATUS		0x09
+#define  MMA7455_STATUS_DRDY		BIT(0)
+#define MMA7455_REG_WHOAMI		0x0f
+#define  MMA7455_WHOAMI_ID		0x55
+#define MMA7455_REG_MCTL		0x16
+#define  MMA7455_MCTL_MODE_STANDBY	0x00
+#define  MMA7455_MCTL_MODE_MEASURE	0x01
+#define MMA7455_REG_CTL1		0x18
+#define  MMA7455_CTL1_DFBW_MASK		BIT(7)
+#define  MMA7455_CTL1_DFBW_125HZ	BIT(7)
+#define  MMA7455_CTL1_DFBW_62_5HZ	0
+#define MMA7455_REG_TW			0x1e
+
+/*
+ * When MMA7455 is used in 10-bit it has a fullscale of -8g
+ * corresponding to raw value -512. The userspace interface
+ * uses m/s^2 and we declare micro units.
+ * So scale factor is given by:
+ *       g * 8 * 1e6 / 512 = 153228.90625, with g = 9.80665
+ */
+#define MMA7455_10BIT_SCALE	153229
+
+struct mma7455_data {
+	struct regmap *regmap;
+	struct device *dev;
+};
+
+static int mma7455_drdy(struct mma7455_data *mma7455)
+{
+	unsigned int reg;
+	int tries = 3;
+	int ret;
+
+	while (tries-- > 0) {
+		ret = regmap_read(mma7455->regmap, MMA7455_REG_STATUS, &reg);
+		if (ret)
+			return ret;
+
+		if (reg & MMA7455_STATUS_DRDY)
+			return 0;
+
+		msleep(20);
+	}
+
+	dev_warn(mma7455->dev, "data not ready\n");
+
+	return -EIO;
+}
+
+static irqreturn_t mma7455_trigger_handler(int irq, void *p)
+{
+	struct iio_poll_func *pf = p;
+	struct iio_dev *indio_dev = pf->indio_dev;
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	u8 buf[16]; /* 3 x 16-bit channels + padding + ts */
+	int ret;
+
+	ret = mma7455_drdy(mma7455);
+	if (ret)
+		goto done;
+
+	ret = regmap_bulk_read(mma7455->regmap, MMA7455_REG_XOUTL, buf,
+			       sizeof(__le16) * 3);
+	if (ret)
+		goto done;
+
+	iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+
+done:
+	iio_trigger_notify_done(indio_dev->trig);
+
+	return IRQ_HANDLED;
+}
+
+static int mma7455_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long mask)
+{
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	unsigned int reg;
+	__le16 data;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		if (iio_buffer_enabled(indio_dev))
+			return -EBUSY;
+
+		ret = mma7455_drdy(mma7455);
+		if (ret)
+			return ret;
+
+		ret = regmap_bulk_read(mma7455->regmap, chan->address, &data,
+				       sizeof(data));
+		if (ret)
+			return ret;
+
+		*val = sign_extend32(le16_to_cpu(data), 9);
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE:
+		*val = 0;
+		*val2 = MMA7455_10BIT_SCALE;
+
+		return IIO_VAL_INT_PLUS_MICRO;
+
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		ret = regmap_read(mma7455->regmap, MMA7455_REG_CTL1, &reg);
+		if (ret)
+			return ret;
+
+		if (reg & MMA7455_CTL1_DFBW_MASK)
+			*val = 250;
+		else
+			*val = 125;
+
+		return IIO_VAL_INT;
+	}
+
+	return -EINVAL;
+}

drivers/iio/accel/mma7455_core.c line 165

Quoted 10 lines
drivers/iio/accel/mma7455_core.c new file +10 -0
+
+static int mma7455_write_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     int val, int val2, long mask)
+{
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	int i;
+
+	if (iio_buffer_enabled(indio_dev))
+		return -EBUSY;

Whilst it is probably 'unwise' to prevent changes to samping frequency and scale whilst the buffer is running, is there a hardware restriction to prevent us doing so? If so add a comment here.

Quoted 21 lines
drivers/iio/accel/mma7455_core.c new file +21 -0
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		if (val == 250 && val2 == 0)
+			i = MMA7455_CTL1_DFBW_125HZ;
+		else if (val == 125 && val2 == 0)
+			i = MMA7455_CTL1_DFBW_62_5HZ;
+		else
+			return -EINVAL;
+
+		return regmap_update_bits(mma7455->regmap, MMA7455_REG_CTL1,
+					  MMA7455_CTL1_DFBW_MASK, i);
+
+	case IIO_CHAN_INFO_SCALE:
+		/* In 10-bit mode there is only one scale available */
+		if (val == 0 && val2 == MMA7455_10BIT_SCALE)
+			return 0;
+		break;
+	}
+
+	return -EINVAL;

drivers/iio/accel/mma7455_core.c line 196

Quoted 10 lines
drivers/iio/accel/mma7455_core.c new file +10 -0
+}
+
+static ssize_t mma7455_show_samp_freq_avail(struct device *dev,
+					    struct device_attribute *attr,
+					    char *buf)
+{
+	return scnprintf(buf, PAGE_SIZE, "125 250\n");
+}
+
+static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(mma7455_show_samp_freq_avail);

There is IIO_CONST_ATTR for this sort of usage, but I guess you might know this is going to get more complex in future?

Quoted 37 lines
drivers/iio/accel/mma7455_core.c new file +37 -0
+
+static struct attribute *mma7455_attributes[] = {
+	&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group mma7455_group = {
+	.attrs = mma7455_attributes,
+};
+
+static const struct iio_info mma7455_info = {
+	.attrs = &mma7455_group,
+	.read_raw = mma7455_read_raw,
+	.write_raw = mma7455_write_raw,
+	.driver_module = THIS_MODULE,
+};
+
+#define MMA7455_CHANNEL(axis, idx) { \
+	.type = IIO_ACCEL, \
+	.modified = 1, \
+	.address = MMA7455_REG_##axis##OUTL,\
+	.channel2 = IIO_MOD_##axis, \
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
+				    BIT(IIO_CHAN_INFO_SCALE), \
+	.scan_index = idx, \
+	.scan_type = { \
+		.sign = 's', \
+		.realbits = 10, \
+		.storagebits = 16, \
+		.endianness = IIO_LE, \
+	}, \
+}
+
+static const struct iio_chan_spec mma7455_channels[] = {
+	MMA7455_CHANNEL(X, 0),
+	MMA7455_CHANNEL(Y, 1),

drivers/iio/accel/mma7455_core.c line 243

Quoted 10 lines
drivers/iio/accel/mma7455_core.c new file +10 -0
+	MMA7455_CHANNEL(Z, 2),
+	IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
+static const unsigned long mma7455_scan_masks[] = {0x7, 0};
+
+const struct regmap_config mma7455_core_regmap = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = MMA7455_REG_TW,

It does seem a little bit of a shame to not make use of more regmap magic (e.g. caching) but I suppose this is just an initial implementation of the driver and you can always add that stuff later!

Quoted 201 lines
drivers/iio/accel/mma7455_core.c new file +78 -0
+};
+EXPORT_SYMBOL_GPL(mma7455_core_regmap);
+
+int mma7455_core_probe(struct device *dev, struct regmap *regmap,
+		       const char *name)
+{
+	struct mma7455_data *mma7455;
+	struct iio_dev *indio_dev;
+	unsigned int reg;
+	int ret;
+
+	ret = regmap_read(regmap, MMA7455_REG_WHOAMI, &reg);
+	if (ret) {
+		dev_err(dev, "unable to read reg\n");
+		return ret;
+	}
+
+	if (reg != MMA7455_WHOAMI_ID) {
+		dev_err(dev, "device id mismatch\n");
+		return -ENODEV;
+	}
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*mma7455));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, indio_dev);
+	mma7455 = iio_priv(indio_dev);
+	mma7455->regmap = regmap;
+	mma7455->dev = dev;
+
+	indio_dev->info = &mma7455_info;
+	indio_dev->name = name;
+	indio_dev->dev.parent = dev;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = mma7455_channels;
+	indio_dev->num_channels = ARRAY_SIZE(mma7455_channels);
+	indio_dev->available_scan_masks = mma7455_scan_masks;
+
+	regmap_write(mma7455->regmap, MMA7455_REG_MCTL,
+		     MMA7455_MCTL_MODE_MEASURE);
+
+	ret = iio_triggered_buffer_setup(indio_dev, NULL,
+					 mma7455_trigger_handler, NULL);
+	if (ret) {
+		dev_err(dev, "unable to setup triggered buffer\n");
+		return ret;
+	}
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		dev_err(dev, "unable to register device\n");
+		iio_triggered_buffer_cleanup(indio_dev);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mma7455_core_probe);
+
+int mma7455_core_remove(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+
+	iio_device_unregister(indio_dev);
+	iio_triggered_buffer_cleanup(indio_dev);
+
+	regmap_write(mma7455->regmap, MMA7455_REG_MCTL,
+		     MMA7455_MCTL_MODE_STANDBY);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mma7455_core_remove);
+
+MODULE_AUTHOR("Joachim Eastwood <[email protected]>");
+MODULE_DESCRIPTION("Freescale MMA7455L core accelerometer driver");
+MODULE_LICENSE("GPL v2");
drivers/iio/accel/mma7455_i2c.c new file +57 -0
new file mode 100644
index 000000000000..ce4ad0d45f98
@@ -0,0 +1,57 @@
+/*
+ * IIO accel I2C driver for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+
+#include "mma7455.h"
+
+static int mma7455_i2c_probe(struct i2c_client *i2c,
+			     const struct i2c_device_id *id)
+{
+	struct regmap *regmap;
+	const char *name = NULL;
+
+	regmap = devm_regmap_init_i2c(i2c, &mma7455_core_regmap);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	if (id)
+		name = id->name;
+
+	return mma7455_core_probe(&i2c->dev, regmap, name);
+}
+
+static int mma7455_i2c_remove(struct i2c_client *i2c)
+{
+	return mma7455_core_remove(&i2c->dev);
+}
+
+static const struct i2c_device_id mma7455_i2c_ids[] = {
+	{ "mma7455", 0 },
+	{ "mma7456", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, mma7455_i2c_ids);
+
+static struct i2c_driver mma7455_i2c_driver = {
+	.probe = mma7455_i2c_probe,
+	.remove = mma7455_i2c_remove,
+	.id_table = mma7455_i2c_ids,
+	.driver = {
+		.name	= "mma7455-i2c",
+	},
+};
+module_i2c_driver(mma7455_i2c_driver);
+
+MODULE_AUTHOR("Joachim Eastwood <[email protected]>");
+MODULE_DESCRIPTION("Freescale MMA7455L I2C accelerometer driver");
+MODULE_LICENSE("GPL v2");
drivers/iio/accel/mma7455_spi.c new file +53 -0
new file mode 100644
index 000000000000..5dc0bb75d289
@@ -0,0 +1,53 @@
+/*
+ * IIO accel SPI driver for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/spi/spi.h>
+
+#include "mma7455.h"
+
+static int mma7455_spi_probe(struct spi_device *spi)
+{
+	const struct spi_device_id *id = spi_get_device_id(spi);
+	struct regmap *regmap;
+
+	regmap = devm_regmap_init_spi(spi, &mma7455_core_regmap);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	return mma7455_core_probe(&spi->dev, regmap, id->name);
+}
+
+static int mma7455_spi_remove(struct spi_device *spi)
+{
+	return mma7455_core_remove(&spi->dev);
+}
+
+static const struct spi_device_id mma7455_spi_ids[] = {
+	{ "mma7455", 0 },
+	{ "mma7456", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(spi, mma7455_spi_ids);
+
+static struct spi_driver mma7455_spi_driver = {
+	.probe = mma7455_spi_probe,
+	.remove = mma7455_spi_remove,
+	.id_table = mma7455_spi_ids,
+	.driver = {
+		.name = "mma7455-spi",
+	},
+};
+module_spi_driver(mma7455_spi_driver);
+
+MODULE_AUTHOR("Joachim Eastwood <[email protected]>");
+MODULE_DESCRIPTION("Freescale MMA7455L SPI accelerometer driver");
+MODULE_LICENSE("GPL v2");
#25 lore raw

Re: [PATCH v3] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Hi Jonathan,

Quoted 12 lines · Jonathan Cameron
Quoted 11 lines · Joachim Eastwood

Add support for Freescale MMA7455L/MMA7456L 3-axis accelerometer in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/ MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

Quoted 6 lines
Quoted 1 line

Looks pretty good to me. A few comments inline.
If we hadn't unfortunately just missed the merge window for IIO I'd have probably taken it as is, but now we have plenty of time to tidy up a few corners without effecting when people get to play with it in distros.

No, problem. I wasn't expecting it to go upstream during the upcoming window.

Quoted 5 lines
Quoted 5 lines
drivers/iio/accel/mma7455_core.c new file +5 -0
+static int mma7455_write_raw(struct iio_dev *indio_dev,
+                          struct iio_chan_spec const *chan,
+                          int val, int val2, long mask)
+{
+     struct mma7455_data *mma7455 = iio_priv(indio_dev);
Quoted 8 lines

drivers/iio/accel/mma7455_core.c line 165

Quoted 4 lines
drivers/iio/accel/mma7455_core.c new file +4 -0
+     int i;
+
+     if (iio_buffer_enabled(indio_dev))
+             return -EBUSY;

Whilst it is probably 'unwise' to prevent changes to samping frequency and scale whilst the buffer is running, is there a hardware restriction to prevent us doing so? If so add a comment here.

The data sheet doesn't really say one way or the other. So I think it should work, but as you say it's probably not a very good idea to change it during sampling. I'll change to code to allow it.

Quoted 25 lines
Quoted 25 lines
drivers/iio/accel/mma7455_core.c new file +25 -0
+
+     switch (mask) {
+     case IIO_CHAN_INFO_SAMP_FREQ:
+             if (val == 250 && val2 == 0)
+                     i = MMA7455_CTL1_DFBW_125HZ;
+             else if (val == 125 && val2 == 0)
+                     i = MMA7455_CTL1_DFBW_62_5HZ;
+             else
+                     return -EINVAL;
+
+             return regmap_update_bits(mma7455->regmap, MMA7455_REG_CTL1,
+                                       MMA7455_CTL1_DFBW_MASK, i);
+
+     case IIO_CHAN_INFO_SCALE:
+             /* In 10-bit mode there is only one scale available */
+             if (val == 0 && val2 == MMA7455_10BIT_SCALE)
+                     return 0;
+             break;
+     }
+
+     return -EINVAL;
+}
+
+static ssize_t mma7455_show_samp_freq_avail(struct device *dev,
+                                         struct device_attribute *attr,
Quoted 8 lines

drivers/iio/accel/mma7455_core.c line 196

Quoted 6 lines
drivers/iio/accel/mma7455_core.c new file +6 -0
+                                         char *buf)
+{
+     return scnprintf(buf, PAGE_SIZE, "125 250\n");
+}
+
+static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(mma7455_show_samp_freq_avail);

There is IIO_CONST_ATTR for this sort of usage, but I guess you might know this is going to get more complex in future?

ah, nice, didn't know about IIO_CONST_ATTR. The hardware only support two sample rates so IIO_CONST_ATTR will do just fine.

Quoted 8 lines

drivers/iio/accel/mma7455_core.c line 243

Quoted 4 lines
drivers/iio/accel/mma7455_core.c new file +4 -0
+const struct regmap_config mma7455_core_regmap = {
+     .reg_bits = 8,
+     .val_bits = 8,
+     .max_register = MMA7455_REG_TW,

It does seem a little bit of a shame to not make use of more regmap magic (e.g. caching) but I suppose this is just an initial implementation of the driver and you can always add that stuff later!

I agree. If more properties like scaling and calibration is added using caching would be a good idea.

I'll make a new version and send it within a couple of days or do want me to wait until the upcoming merge window closes?

regards,
Joachim Eastwood

#26 lore raw

Re: [PATCH v3] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 97 lines · Joachim Eastwood

Hi Jonathan,

Quoted 7 lines · Jonathan Cameron
Quoted 6 lines · Joachim Eastwood

Add support for Freescale MMA7455L/MMA7456L 3-axis accelerometer in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/ MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C

bus.

Quoted 11 lines
Quoted 6 lines

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

Looks pretty good to me. A few comments inline.
If we hadn't unfortunately just missed the merge window for IIO I'd have probably taken it as is, but now we have plenty of time to tidy up a few corners without effecting when people get to play with it in distros.

No, problem. I wasn't expecting it to go upstream during the upcoming window.

Quoted 11 lines

drivers/iio/accel/mma7455_core.c line 165

Quoted 9 lines
drivers/iio/accel/mma7455_core.c new file +9 -0
+static int mma7455_write_raw(struct iio_dev *indio_dev,
+                          struct iio_chan_spec const *chan,
+                          int val, int val2, long mask)
+{
+     struct mma7455_data *mma7455 = iio_priv(indio_dev);
+     int i;
+
+     if (iio_buffer_enabled(indio_dev))
+             return -EBUSY;

Whilst it is probably 'unwise' to prevent changes to samping

frequency

Quoted 1 line

and scale whilst the buffer is running, is there a hardware

restriction

Quoted 1 line

to prevent us doing so? If so add a comment here.

The data sheet doesn't really say one way or the other. So I think it should work, but as you say it's probably not a very good idea to change it during sampling. I'll change to code to allow it.

Quoted 11 lines

drivers/iio/accel/mma7455_core.c

Quoted 11 lines
drivers/iio/accel/mma7455_core.c new file +11 -0
+
+     switch (mask) {
+     case IIO_CHAN_INFO_SAMP_FREQ:
+             if (val == 250 && val2 == 0)
+                     i = MMA7455_CTL1_DFBW_125HZ;
+             else if (val == 125 && val2 == 0)
+                     i = MMA7455_CTL1_DFBW_62_5HZ;
+             else
+                     return -EINVAL;
+
+             return regmap_update_bits(mma7455->regmap,

MMA7455_REG_CTL1,

Quoted 6 lines
Quoted 6 lines
drivers/iio/accel/mma7455_core.c new file +6 -0
+                                       MMA7455_CTL1_DFBW_MASK, i);
+
+     case IIO_CHAN_INFO_SCALE:
+             /* In 10-bit mode there is only one scale available */
+             if (val == 0 && val2 == MMA7455_10BIT_SCALE)
+                     return 0;
Quoted 8 lines

drivers/iio/accel/mma7455_core.c

Quoted 8 lines
drivers/iio/accel/mma7455_core.c new file +8 -0
+             break;
+     }
+
+     return -EINVAL;
+}
+
+static ssize_t mma7455_show_samp_freq_avail(struct device *dev,
+                                         struct device_attribute

*attr,

Quoted 8 lines

drivers/iio/accel/mma7455_core.c line 196

Quoted 6 lines
drivers/iio/accel/mma7455_core.c new file +6 -0
+                                         char *buf)
+{
+     return scnprintf(buf, PAGE_SIZE, "125 250\n");
+}
+
+static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(mma7455_show_samp_freq_avail);

There is IIO_CONST_ATTR for this sort of usage, but I guess you might know this is going to get more complex in future?

ah, nice, didn't know about IIO_CONST_ATTR. The hardware only support two sample rates so IIO_CONST_ATTR will do just fine.

Quoted 8 lines

drivers/iio/accel/mma7455_core.c line 243

Quoted 4 lines
drivers/iio/accel/mma7455_core.c new file +4 -0
+const struct regmap_config mma7455_core_regmap = {
+     .reg_bits = 8,
+     .val_bits = 8,
+     .max_register = MMA7455_REG_TW,

It does seem a little bit of a shame to not make use of more regmap magic (e.g. caching) but I suppose this is just an initial implementation of the driver and you can always add that stuff later!

Quoted 6 lines

I agree. If more properties like scaling and calibration is added using caching would be a good idea.

I'll make a new version and send it within a couple of days or do want me to wait until the upcoming merge window closes?

Whenever you are ready.

Quoted 4 lines

regards,
Joachim Eastwood

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
#27 lore raw

PATCH v4 1/1 iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

In reply to Joachim Eastwood

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

---
Hi,

This version address the comments from Jonathan Cameron.

Changes since v3:
* use IIO_CONST_ATTR on sampling_frequency_available
* allow changing of rate and scaling while buffer is running

Changes since v2:
* fix id variable name in MODULE_DEVICE_TABLE
* make MMA7455_{I2C,SPI} symbols selectable
* rebase on linux-next (tag next-20151020)

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

 drivers/iio/accel/Kconfig        |  29 ++++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 311 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 475 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/Kconfig +29 -0
index 969428dd6329..728a7761aaa6 100644
@@ -107,6 +107,35 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+
+config MMA7455_I2C
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver"
+	depends on I2C
+	select MMA7455
+	select REGMAP_I2C
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c.
+
+config MMA7455_SPI
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver"
+	depends on SPI_MASTER
+	select MMA7455
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_spi.
+
 config MMA8452
 	tristate "Freescale MMA8452Q and similar Accelerometers Driver"
 	depends on I2C
drivers/iio/accel/Makefile +5 -0
index 7925f166e6e9..7ea21f8b7d98 100644
@@ -10,6 +10,11 @@ obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+
+obj-$(CONFIG_MMA7455)		+= mma7455_core.o
+obj-$(CONFIG_MMA7455_I2C)	+= mma7455_i2c.o
+obj-$(CONFIG_MMA7455_SPI)	+= mma7455_spi.o
+
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.h new file +20 -0
new file mode 100644
index 000000000000..8fae9345da88
@@ -0,0 +1,20 @@
+/*
+ * IIO accel header for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#ifndef __MMA7455_H
+#define __MMA7455_H
+
+extern const struct regmap_config mma7455_core_regmap;
+
+int mma7455_core_probe(struct device *dev, struct regmap *regmap,
+		       const char *name);
+int mma7455_core_remove(struct device *dev);
+
+#endif
drivers/iio/accel/mma7455_core.c new file +311 -0

311 lines not on this page · raw message

drivers/iio/accel/mma7455_i2c.c new file +57 -0

57 lines not on this page · raw message

drivers/iio/accel/mma7455_spi.c new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
1.8.0
#28 lore raw

Re: [PATCH v4] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Am 2015-10-31 um 13:49 schrieb Joachim Eastwood:

Quoted 110 lines

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

---
Hi,

This version address the comments from Jonathan Cameron.

Changes since v3:
* use IIO_CONST_ATTR on sampling_frequency_available
* allow changing of rate and scaling while buffer is running

Changes since v2:
* fix id variable name in MODULE_DEVICE_TABLE
* make MMA7455_{I2C,SPI} symbols selectable
* rebase on linux-next (tag next-20151020)

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

 drivers/iio/accel/Kconfig        |  29 ++++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 311 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 475 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/Kconfig +29 -0
index 969428dd6329..728a7761aaa6 100644
@@ -107,6 +107,35 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+
+config MMA7455_I2C
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver"
+	depends on I2C
+	select MMA7455
+	select REGMAP_I2C
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c.
+
+config MMA7455_SPI
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver"
+	depends on SPI_MASTER
+	select MMA7455
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_spi.
+
 config MMA8452
 	tristate "Freescale MMA8452Q and similar Accelerometers Driver"
 	depends on I2C
drivers/iio/accel/Makefile +5 -0
index 7925f166e6e9..7ea21f8b7d98 100644
@@ -10,6 +10,11 @@ obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+
+obj-$(CONFIG_MMA7455)		+= mma7455_core.o
+obj-$(CONFIG_MMA7455_I2C)	+= mma7455_i2c.o
+obj-$(CONFIG_MMA7455_SPI)	+= mma7455_spi.o
+
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.h new file +0 -0
new file mode 100644
index 000000000000..8fae9345da88

drivers/iio/accel/mma7455.h line 4

Quoted 4 lines
drivers/iio/accel/mma7455.h new file +4 -0
@@ -0,0 +1,20 @@
+/*
+ * IIO accel header for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *

Even though they are very similar (internal technological differences), you could mention both supported chips here and in the other files. Btw, I would also s/header/driver here.

That is, in case you get to do another version.

thanks
martin

maintainer
#29 lore raw

Re: [PATCH v4] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 120 lines · Martin Kepplinger

Am 2015-10-31 um 13:49 schrieb Joachim Eastwood:

Quoted 110 lines

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

---
Hi,

This version address the comments from Jonathan Cameron.

Changes since v3:
* use IIO_CONST_ATTR on sampling_frequency_available
* allow changing of rate and scaling while buffer is running

Changes since v2:
* fix id variable name in MODULE_DEVICE_TABLE
* make MMA7455_{I2C,SPI} symbols selectable
* rebase on linux-next (tag next-20151020)

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

 drivers/iio/accel/Kconfig        |  29 ++++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 311 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 475 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/Kconfig +29 -0
index 969428dd6329..728a7761aaa6 100644
@@ -107,6 +107,35 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+
+config MMA7455_I2C
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver"
+	depends on I2C
+	select MMA7455
+	select REGMAP_I2C
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c.
+
+config MMA7455_SPI
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver"
+	depends on SPI_MASTER
+	select MMA7455
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_spi.
+
 config MMA8452
 	tristate "Freescale MMA8452Q and similar Accelerometers Driver"
 	depends on I2C
drivers/iio/accel/Makefile +5 -0
index 7925f166e6e9..7ea21f8b7d98 100644
@@ -10,6 +10,11 @@ obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+
+obj-$(CONFIG_MMA7455)		+= mma7455_core.o
+obj-$(CONFIG_MMA7455_I2C)	+= mma7455_i2c.o
+obj-$(CONFIG_MMA7455_SPI)	+= mma7455_spi.o
+
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.h new file +0 -0
new file mode 100644
index 000000000000..8fae9345da88

drivers/iio/accel/mma7455.h line 4

Quoted 4 lines
drivers/iio/accel/mma7455.h new file +4 -0
@@ -0,0 +1,20 @@
+/*
+ * IIO accel header for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *

Even though they are very similar (internal technological differences), you could mention both supported chips here and in the other files. Btw, I would also s/header/driver here.

Quoted 2 lines

That is, in case you get to do another version.

Hi Martin,

I can see where you are coming from, but typically I'd actually advocate mentioning the list of supported parts in as few a places as possible as they tend to get out of sync if we end up with a driver supporting lots of parts. We have gotten round this in the past but saying something like **** and similar or *** and compatible but that's always a bit clunky.

I'll switch header to driver in the application of the patch.

Jonathan

#30 lore raw

Re: [PATCH v4] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Am 2015-11-01 um 19:01 schrieb Jonathan Cameron:

Quoted 123 lines · Martin Kepplinger
Quoted 120 lines

Am 2015-10-31 um 13:49 schrieb Joachim Eastwood:

Quoted 110 lines

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

---
Hi,

This version address the comments from Jonathan Cameron.

Changes since v3:
* use IIO_CONST_ATTR on sampling_frequency_available
* allow changing of rate and scaling while buffer is running

Changes since v2:
* fix id variable name in MODULE_DEVICE_TABLE
* make MMA7455_{I2C,SPI} symbols selectable
* rebase on linux-next (tag next-20151020)

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

 drivers/iio/accel/Kconfig        |  29 ++++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 311 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 475 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/Kconfig +29 -0
index 969428dd6329..728a7761aaa6 100644
@@ -107,6 +107,35 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+
+config MMA7455_I2C
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver"
+	depends on I2C
+	select MMA7455
+	select REGMAP_I2C
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c.
+
+config MMA7455_SPI
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver"
+	depends on SPI_MASTER
+	select MMA7455
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_spi.
+
 config MMA8452
 	tristate "Freescale MMA8452Q and similar Accelerometers Driver"
 	depends on I2C
drivers/iio/accel/Makefile +5 -0
index 7925f166e6e9..7ea21f8b7d98 100644
@@ -10,6 +10,11 @@ obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+
+obj-$(CONFIG_MMA7455)		+= mma7455_core.o
+obj-$(CONFIG_MMA7455_I2C)	+= mma7455_i2c.o
+obj-$(CONFIG_MMA7455_SPI)	+= mma7455_spi.o
+
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.h new file +0 -0
new file mode 100644
index 000000000000..8fae9345da88

drivers/iio/accel/mma7455.h line 4

Quoted 4 lines
drivers/iio/accel/mma7455.h new file +4 -0
@@ -0,0 +1,20 @@
+/*
+ * IIO accel header for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *

Even though they are very similar (internal technological differences), you could mention both supported chips here and in the other files. Btw, I would also s/header/driver here.

Quoted 2 lines

That is, in case you get to do another version.

Quoted 7 lines

Hi Martin,

I can see where you are coming from, but typically I'd actually advocate mentioning the list of supported parts in as few a places as possible as they tend to get out of sync if we end up with a driver supporting lots of parts. We have gotten round this in the past but saying something like **** and similar or *** and compatible but that's always a bit clunky.

I see. Kconfig should probably contain all supported products, so refering to Kconfig would be scalable...

In this case, I don't really fear that this driver will support more chips. These 2 are all (that are very similar / equal) there are, and are relatively old, not "recommended" by the vendor anymore.

Nothing I don't like about the driver, just thoughts.

martin

Quoted 5 lines

I'll switch header to driver in the application of the patch.

Jonathan

maintainer
#31 lore raw

Re: [PATCH v4] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 126 lines · Martin Kepplinger

Am 2015-11-01 um 19:01 schrieb Jonathan Cameron:

Quoted 125 lines · Martin Kepplinger
Quoted 120 lines

Am 2015-10-31 um 13:49 schrieb Joachim Eastwood:

Quoted 110 lines

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

---
Hi,

This version address the comments from Jonathan Cameron.

Changes since v3:
* use IIO_CONST_ATTR on sampling_frequency_available
* allow changing of rate and scaling while buffer is running

Changes since v2:
* fix id variable name in MODULE_DEVICE_TABLE
* make MMA7455_{I2C,SPI} symbols selectable
* rebase on linux-next (tag next-20151020)

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

 drivers/iio/accel/Kconfig        |  29 ++++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 311 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 475 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/Kconfig +29 -0
index 969428dd6329..728a7761aaa6 100644
@@ -107,6 +107,35 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+
+config MMA7455_I2C
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver"
+	depends on I2C
+	select MMA7455
+	select REGMAP_I2C
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c.
+
+config MMA7455_SPI
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver"
+	depends on SPI_MASTER
+	select MMA7455
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_spi.
+
 config MMA8452
 	tristate "Freescale MMA8452Q and similar Accelerometers Driver"
 	depends on I2C
drivers/iio/accel/Makefile +5 -0
index 7925f166e6e9..7ea21f8b7d98 100644
@@ -10,6 +10,11 @@ obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+
+obj-$(CONFIG_MMA7455)		+= mma7455_core.o
+obj-$(CONFIG_MMA7455_I2C)	+= mma7455_i2c.o
+obj-$(CONFIG_MMA7455_SPI)	+= mma7455_spi.o
+
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.h new file +0 -0
new file mode 100644
index 000000000000..8fae9345da88

drivers/iio/accel/mma7455.h line 4

Quoted 4 lines
drivers/iio/accel/mma7455.h new file +4 -0
@@ -0,0 +1,20 @@
+/*
+ * IIO accel header for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *

Even though they are very similar (internal technological differences), you could mention both supported chips here and in the other files. Btw, I would also s/header/driver here.

Quoted 2 lines

That is, in case you get to do another version.

Hi Martin,

Quoted 8 lines
Quoted 5 lines

I can see where you are coming from, but typically I'd actually advocate mentioning the list of supported parts in as few a places as possible as they tend to get out of sync if we end up with a driver supporting lots of parts. We have gotten round this in the past but saying something like **** and similar or *** and compatible but that's always a bit clunky.

I see. Kconfig should probably contain all supported products, so refering to Kconfig would be scalable...

Yes, could reference to Kconfig - though typically they are all only listed in the help description as the list rapidly gets too long to go in the menu item name.

Quoted 4 lines

In this case, I don't really fear that this driver will support more chips. These 2 are all (that are very similar / equal) there are, and are relatively old, not "recommended" by the vendor anymore.

Indeed, seems unlikely unless someone gets some old freescale IP in the future ;)

Quoted 11 lines

Nothing I don't like about the driver, just thoughts.

martin

Quoted 5 lines

I'll switch header to driver in the application of the patch.

Jonathan

maintainer
#32 lore raw

Re: [PATCH v4] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

In reply to Joachim Eastwood
Quoted 11 lines · Joachim Eastwood

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

A few really trivial gripes I'll deal with when applying.

+ the s/header/driver thing Martin picked up on.

Jonathan

Quoted 99 lines

---
Hi,

This version address the comments from Jonathan Cameron.

Changes since v3:
* use IIO_CONST_ATTR on sampling_frequency_available
* allow changing of rate and scaling while buffer is running

Changes since v2:
* fix id variable name in MODULE_DEVICE_TABLE
* make MMA7455_{I2C,SPI} symbols selectable
* rebase on linux-next (tag next-20151020)

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

 drivers/iio/accel/Kconfig        |  29 ++++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 311 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 475 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/Kconfig +29 -0
index 969428dd6329..728a7761aaa6 100644
@@ -107,6 +107,35 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+
+config MMA7455_I2C
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver"
+	depends on I2C
+	select MMA7455
+	select REGMAP_I2C
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c.
+
+config MMA7455_SPI
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver"
+	depends on SPI_MASTER
+	select MMA7455
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_spi.
+
 config MMA8452
 	tristate "Freescale MMA8452Q and similar Accelerometers Driver"
 	depends on I2C
drivers/iio/accel/Makefile +5 -0
index 7925f166e6e9..7ea21f8b7d98 100644
@@ -10,6 +10,11 @@ obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+
+obj-$(CONFIG_MMA7455)		+= mma7455_core.o
+obj-$(CONFIG_MMA7455_I2C)	+= mma7455_i2c.o
+obj-$(CONFIG_MMA7455_SPI)	+= mma7455_spi.o
+
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.h new file +0 -0
new file mode 100644
index 000000000000..8fae9345da88

drivers/iio/accel/mma7455.h line 7

Quoted 7 lines
drivers/iio/accel/mma7455.h new file +7 -0
@@ -0,0 +1,20 @@
+/*
+ * IIO accel header for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

and another one...

Quoted 336 lines
drivers/iio/accel/mma7455.h new file +13 -0
+ *
+ */
+
+#ifndef __MMA7455_H
+#define __MMA7455_H
+
+extern const struct regmap_config mma7455_core_regmap;
+
+int mma7455_core_probe(struct device *dev, struct regmap *regmap,
+		       const char *name);
+int mma7455_core_remove(struct device *dev);
+
+#endif
drivers/iio/accel/mma7455_core.c new file +311 -0
new file mode 100644
index 000000000000..c633cc2c0789
@@ -0,0 +1,311 @@
+/*
+ * IIO accel core driver for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * UNSUPPORTED hardware features:
+ *  - 8-bit mode with different scales
+ *  - INT1/INT2 interrupts
+ *  - Offset calibration
+ *  - Events
+ */
+
+#include <linux/delay.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+
+#include "mma7455.h"
+
+#define MMA7455_REG_XOUTL		0x00
+#define MMA7455_REG_XOUTH		0x01
+#define MMA7455_REG_YOUTL		0x02
+#define MMA7455_REG_YOUTH		0x03
+#define MMA7455_REG_ZOUTL		0x04
+#define MMA7455_REG_ZOUTH		0x05
+#define MMA7455_REG_STATUS		0x09
+#define  MMA7455_STATUS_DRDY		BIT(0)
+#define MMA7455_REG_WHOAMI		0x0f
+#define  MMA7455_WHOAMI_ID		0x55
+#define MMA7455_REG_MCTL		0x16
+#define  MMA7455_MCTL_MODE_STANDBY	0x00
+#define  MMA7455_MCTL_MODE_MEASURE	0x01
+#define MMA7455_REG_CTL1		0x18
+#define  MMA7455_CTL1_DFBW_MASK		BIT(7)
+#define  MMA7455_CTL1_DFBW_125HZ	BIT(7)
+#define  MMA7455_CTL1_DFBW_62_5HZ	0
+#define MMA7455_REG_TW			0x1e
+
+/*
+ * When MMA7455 is used in 10-bit it has a fullscale of -8g
+ * corresponding to raw value -512. The userspace interface
+ * uses m/s^2 and we declare micro units.
+ * So scale factor is given by:
+ *       g * 8 * 1e6 / 512 = 153228.90625, with g = 9.80665
+ */
+#define MMA7455_10BIT_SCALE	153229
+
+struct mma7455_data {
+	struct regmap *regmap;
+	struct device *dev;
+};
+
+static int mma7455_drdy(struct mma7455_data *mma7455)
+{
+	unsigned int reg;
+	int tries = 3;
+	int ret;
+
+	while (tries-- > 0) {
+		ret = regmap_read(mma7455->regmap, MMA7455_REG_STATUS, &reg);
+		if (ret)
+			return ret;
+
+		if (reg & MMA7455_STATUS_DRDY)
+			return 0;
+
+		msleep(20);
+	}
+
+	dev_warn(mma7455->dev, "data not ready\n");
+
+	return -EIO;
+}
+
+static irqreturn_t mma7455_trigger_handler(int irq, void *p)
+{
+	struct iio_poll_func *pf = p;
+	struct iio_dev *indio_dev = pf->indio_dev;
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	u8 buf[16]; /* 3 x 16-bit channels + padding + ts */
+	int ret;
+
+	ret = mma7455_drdy(mma7455);
+	if (ret)
+		goto done;
+
+	ret = regmap_bulk_read(mma7455->regmap, MMA7455_REG_XOUTL, buf,
+			       sizeof(__le16) * 3);
+	if (ret)
+		goto done;
+
+	iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+
+done:
+	iio_trigger_notify_done(indio_dev->trig);
+
+	return IRQ_HANDLED;
+}
+
+static int mma7455_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long mask)
+{
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	unsigned int reg;
+	__le16 data;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		if (iio_buffer_enabled(indio_dev))
+			return -EBUSY;
+
+		ret = mma7455_drdy(mma7455);
+		if (ret)
+			return ret;
+
+		ret = regmap_bulk_read(mma7455->regmap, chan->address, &data,
+				       sizeof(data));
+		if (ret)
+			return ret;
+
+		*val = sign_extend32(le16_to_cpu(data), 9);
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE:
+		*val = 0;
+		*val2 = MMA7455_10BIT_SCALE;
+
+		return IIO_VAL_INT_PLUS_MICRO;
+
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		ret = regmap_read(mma7455->regmap, MMA7455_REG_CTL1, &reg);
+		if (ret)
+			return ret;
+
+		if (reg & MMA7455_CTL1_DFBW_MASK)
+			*val = 250;
+		else
+			*val = 125;
+
+		return IIO_VAL_INT;
+	}
+
+	return -EINVAL;
+}
+
+static int mma7455_write_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     int val, int val2, long mask)
+{
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	int i;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		if (val == 250 && val2 == 0)
+			i = MMA7455_CTL1_DFBW_125HZ;
+		else if (val == 125 && val2 == 0)
+			i = MMA7455_CTL1_DFBW_62_5HZ;
+		else
+			return -EINVAL;
+
+		return regmap_update_bits(mma7455->regmap, MMA7455_REG_CTL1,
+					  MMA7455_CTL1_DFBW_MASK, i);
+
+	case IIO_CHAN_INFO_SCALE:
+		/* In 10-bit mode there is only one scale available */
+		if (val == 0 && val2 == MMA7455_10BIT_SCALE)
+			return 0;
+		break;
+	}
+
+	return -EINVAL;
+}
+
+static IIO_CONST_ATTR(sampling_frequency_available, "125 250");
+
+static struct attribute *mma7455_attributes[] = {
+	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group mma7455_group = {
+	.attrs = mma7455_attributes,
+};
+
+static const struct iio_info mma7455_info = {
+	.attrs = &mma7455_group,
+	.read_raw = mma7455_read_raw,
+	.write_raw = mma7455_write_raw,
+	.driver_module = THIS_MODULE,
+};
+
+#define MMA7455_CHANNEL(axis, idx) { \
+	.type = IIO_ACCEL, \
+	.modified = 1, \
+	.address = MMA7455_REG_##axis##OUTL,\
+	.channel2 = IIO_MOD_##axis, \
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
+				    BIT(IIO_CHAN_INFO_SCALE), \
+	.scan_index = idx, \
+	.scan_type = { \
+		.sign = 's', \
+		.realbits = 10, \
+		.storagebits = 16, \
+		.endianness = IIO_LE, \
+	}, \
+}
+
+static const struct iio_chan_spec mma7455_channels[] = {
+	MMA7455_CHANNEL(X, 0),
+	MMA7455_CHANNEL(Y, 1),
+	MMA7455_CHANNEL(Z, 2),
+	IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
+static const unsigned long mma7455_scan_masks[] = {0x7, 0};
+
+const struct regmap_config mma7455_core_regmap = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = MMA7455_REG_TW,
+};
+EXPORT_SYMBOL_GPL(mma7455_core_regmap);
+
+int mma7455_core_probe(struct device *dev, struct regmap *regmap,
+		       const char *name)
+{
+	struct mma7455_data *mma7455;
+	struct iio_dev *indio_dev;
+	unsigned int reg;
+	int ret;
+
+	ret = regmap_read(regmap, MMA7455_REG_WHOAMI, &reg);
+	if (ret) {
+		dev_err(dev, "unable to read reg\n");
+		return ret;
+	}
+
+	if (reg != MMA7455_WHOAMI_ID) {
+		dev_err(dev, "device id mismatch\n");
+		return -ENODEV;
+	}
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*mma7455));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, indio_dev);
+	mma7455 = iio_priv(indio_dev);
+	mma7455->regmap = regmap;
+	mma7455->dev = dev;
+
+	indio_dev->info = &mma7455_info;
+	indio_dev->name = name;
+	indio_dev->dev.parent = dev;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = mma7455_channels;
+	indio_dev->num_channels = ARRAY_SIZE(mma7455_channels);
+	indio_dev->available_scan_masks = mma7455_scan_masks;
+
+	regmap_write(mma7455->regmap, MMA7455_REG_MCTL,
+		     MMA7455_MCTL_MODE_MEASURE);
+
+	ret = iio_triggered_buffer_setup(indio_dev, NULL,
+					 mma7455_trigger_handler, NULL);
+	if (ret) {
+		dev_err(dev, "unable to setup triggered buffer\n");
+		return ret;
+	}
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		dev_err(dev, "unable to register device\n");
+		iio_triggered_buffer_cleanup(indio_dev);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mma7455_core_probe);
+
+int mma7455_core_remove(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+
+	iio_device_unregister(indio_dev);
+	iio_triggered_buffer_cleanup(indio_dev);
+
+	regmap_write(mma7455->regmap, MMA7455_REG_MCTL,
+		     MMA7455_MCTL_MODE_STANDBY);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mma7455_core_remove);
+
+MODULE_AUTHOR("Joachim Eastwood <[email protected]>");
+MODULE_DESCRIPTION("Freescale MMA7455L core accelerometer driver");
+MODULE_LICENSE("GPL v2");
drivers/iio/accel/mma7455_i2c.c new file +0 -0
new file mode 100644
index 000000000000..ce4ad0d45f98

drivers/iio/accel/mma7455_i2c.c line 8

Quoted 8 lines
drivers/iio/accel/mma7455_i2c.c new file +8 -0
@@ -0,0 +1,57 @@
+/*
+ * IIO accel I2C driver for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *

And this one (see below, I review backwards as drivers usually make more sense that way around).

Quoted 55 lines
drivers/iio/accel/mma7455_i2c.c new file +49 -0
+ */
+
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+
+#include "mma7455.h"
+
+static int mma7455_i2c_probe(struct i2c_client *i2c,
+			     const struct i2c_device_id *id)
+{
+	struct regmap *regmap;
+	const char *name = NULL;
+
+	regmap = devm_regmap_init_i2c(i2c, &mma7455_core_regmap);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	if (id)
+		name = id->name;
+
+	return mma7455_core_probe(&i2c->dev, regmap, name);
+}
+
+static int mma7455_i2c_remove(struct i2c_client *i2c)
+{
+	return mma7455_core_remove(&i2c->dev);
+}
+
+static const struct i2c_device_id mma7455_i2c_ids[] = {
+	{ "mma7455", 0 },
+	{ "mma7456", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, mma7455_i2c_ids);
+
+static struct i2c_driver mma7455_i2c_driver = {
+	.probe = mma7455_i2c_probe,
+	.remove = mma7455_i2c_remove,
+	.id_table = mma7455_i2c_ids,
+	.driver = {
+		.name	= "mma7455-i2c",
+	},
+};
+module_i2c_driver(mma7455_i2c_driver);
+
+MODULE_AUTHOR("Joachim Eastwood <[email protected]>");
+MODULE_DESCRIPTION("Freescale MMA7455L I2C accelerometer driver");
+MODULE_LICENSE("GPL v2");
drivers/iio/accel/mma7455_spi.c new file +0 -0
new file mode 100644
index 000000000000..5dc0bb75d289

drivers/iio/accel/mma7455_spi.c line 7

Quoted 7 lines
drivers/iio/accel/mma7455_spi.c new file +7 -0
@@ -0,0 +1,53 @@
+/*
+ * IIO accel SPI driver for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

My quest against blank lines with no purpose continues. I'll edit this one out in the appy.

Quoted 47 lines
drivers/iio/accel/mma7455_spi.c new file +46 -0
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/spi/spi.h>
+
+#include "mma7455.h"
+
+static int mma7455_spi_probe(struct spi_device *spi)
+{
+	const struct spi_device_id *id = spi_get_device_id(spi);
+	struct regmap *regmap;
+
+	regmap = devm_regmap_init_spi(spi, &mma7455_core_regmap);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	return mma7455_core_probe(&spi->dev, regmap, id->name);
+}
+
+static int mma7455_spi_remove(struct spi_device *spi)
+{
+	return mma7455_core_remove(&spi->dev);
+}
+
+static const struct spi_device_id mma7455_spi_ids[] = {
+	{ "mma7455", 0 },
+	{ "mma7456", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(spi, mma7455_spi_ids);
+
+static struct spi_driver mma7455_spi_driver = {
+	.probe = mma7455_spi_probe,
+	.remove = mma7455_spi_remove,
+	.id_table = mma7455_spi_ids,
+	.driver = {
+		.name = "mma7455-spi",
+	},
+};
+module_spi_driver(mma7455_spi_driver);
+
+MODULE_AUTHOR("Joachim Eastwood <[email protected]>");
+MODULE_DESCRIPTION("Freescale MMA7455L SPI accelerometer driver");
+MODULE_LICENSE("GPL v2");
maintainer Applied
#33 lore raw

Re: [PATCH v4] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 7 lines · Jonathan Cameron
Quoted 6 lines · Joachim Eastwood

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Quoted 8 lines
Quoted 5 lines

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

A few really trivial gripes I'll deal with when applying.

+ the s/header/driver thing Martin picked up on.

Forgot the important bit:

Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.

Jonathan

Quoted 572 lines

Jonathan

Quoted 99 lines

---
Hi,

This version address the comments from Jonathan Cameron.

Changes since v3:
* use IIO_CONST_ATTR on sampling_frequency_available
* allow changing of rate and scaling while buffer is running

Changes since v2:
* fix id variable name in MODULE_DEVICE_TABLE
* make MMA7455_{I2C,SPI} symbols selectable
* rebase on linux-next (tag next-20151020)

Changes since v1:
* limit retries to 3 in mma7455_drdy
* remove mma7455_show_scale_avail
* use chan->address instead of chan->scan_index for reg addr
* check that val2 is 0 when setting sample freq
* use __le16 to hint about endianess in mma7455_trigger_handler
* fix endianess in mma7455_read_raw function
* add mma7456 id
* split it into several source files to support both i2c and spi

 drivers/iio/accel/Kconfig        |  29 ++++
 drivers/iio/accel/Makefile       |   5 +
 drivers/iio/accel/mma7455.h      |  20 +++
 drivers/iio/accel/mma7455_core.c | 311 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/mma7455_i2c.c  |  57 +++++++
 drivers/iio/accel/mma7455_spi.c  |  53 +++++++
 6 files changed, 475 insertions(+)
 create mode 100644 drivers/iio/accel/mma7455.h
 create mode 100644 drivers/iio/accel/mma7455_core.c
 create mode 100644 drivers/iio/accel/mma7455_i2c.c
 create mode 100644 drivers/iio/accel/mma7455_spi.c
drivers/iio/accel/Kconfig +29 -0
index 969428dd6329..728a7761aaa6 100644
@@ -107,6 +107,35 @@ config KXCJK1013
 	  To compile this driver as a module, choose M here: the module will
 	  be called kxcjk-1013.
 
+config MMA7455
+	tristate
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+
+config MMA7455_I2C
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer I2C Driver"
+	depends on I2C
+	select MMA7455
+	select REGMAP_I2C
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_i2c.
+
+config MMA7455_SPI
+	tristate "Freescale MMA7455L/MMA7456L Accelerometer SPI Driver"
+	depends on SPI_MASTER
+	select MMA7455
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for the Freescale MMA7455L and
+	  MMA7456L 3-axis accelerometer.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mma7455_spi.
+
 config MMA8452
 	tristate "Freescale MMA8452Q and similar Accelerometers Driver"
 	depends on I2C
drivers/iio/accel/Makefile +5 -0
index 7925f166e6e9..7ea21f8b7d98 100644
@@ -10,6 +10,11 @@ obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)	+= kxsd9.o
+
+obj-$(CONFIG_MMA7455)		+= mma7455_core.o
+obj-$(CONFIG_MMA7455_I2C)	+= mma7455_i2c.o
+obj-$(CONFIG_MMA7455_SPI)	+= mma7455_spi.o
+
 obj-$(CONFIG_MMA8452)	+= mma8452.o
 
 obj-$(CONFIG_MMA9551_CORE)	+= mma9551_core.o
drivers/iio/accel/mma7455.h new file +0 -0
new file mode 100644
index 000000000000..8fae9345da88

drivers/iio/accel/mma7455.h line 7

Quoted 7 lines
drivers/iio/accel/mma7455.h new file +7 -0
@@ -0,0 +1,20 @@
+/*
+ * IIO accel header for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

and another one...

Quoted 336 lines
drivers/iio/accel/mma7455.h new file +13 -0
+ *
+ */
+
+#ifndef __MMA7455_H
+#define __MMA7455_H
+
+extern const struct regmap_config mma7455_core_regmap;
+
+int mma7455_core_probe(struct device *dev, struct regmap *regmap,
+		       const char *name);
+int mma7455_core_remove(struct device *dev);
+
+#endif
drivers/iio/accel/mma7455_core.c new file +311 -0
new file mode 100644
index 000000000000..c633cc2c0789
@@ -0,0 +1,311 @@
+/*
+ * IIO accel core driver for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * UNSUPPORTED hardware features:
+ *  - 8-bit mode with different scales
+ *  - INT1/INT2 interrupts
+ *  - Offset calibration
+ *  - Events
+ */
+
+#include <linux/delay.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+
+#include "mma7455.h"
+
+#define MMA7455_REG_XOUTL		0x00
+#define MMA7455_REG_XOUTH		0x01
+#define MMA7455_REG_YOUTL		0x02
+#define MMA7455_REG_YOUTH		0x03
+#define MMA7455_REG_ZOUTL		0x04
+#define MMA7455_REG_ZOUTH		0x05
+#define MMA7455_REG_STATUS		0x09
+#define  MMA7455_STATUS_DRDY		BIT(0)
+#define MMA7455_REG_WHOAMI		0x0f
+#define  MMA7455_WHOAMI_ID		0x55
+#define MMA7455_REG_MCTL		0x16
+#define  MMA7455_MCTL_MODE_STANDBY	0x00
+#define  MMA7455_MCTL_MODE_MEASURE	0x01
+#define MMA7455_REG_CTL1		0x18
+#define  MMA7455_CTL1_DFBW_MASK		BIT(7)
+#define  MMA7455_CTL1_DFBW_125HZ	BIT(7)
+#define  MMA7455_CTL1_DFBW_62_5HZ	0
+#define MMA7455_REG_TW			0x1e
+
+/*
+ * When MMA7455 is used in 10-bit it has a fullscale of -8g
+ * corresponding to raw value -512. The userspace interface
+ * uses m/s^2 and we declare micro units.
+ * So scale factor is given by:
+ *       g * 8 * 1e6 / 512 = 153228.90625, with g = 9.80665
+ */
+#define MMA7455_10BIT_SCALE	153229
+
+struct mma7455_data {
+	struct regmap *regmap;
+	struct device *dev;
+};
+
+static int mma7455_drdy(struct mma7455_data *mma7455)
+{
+	unsigned int reg;
+	int tries = 3;
+	int ret;
+
+	while (tries-- > 0) {
+		ret = regmap_read(mma7455->regmap, MMA7455_REG_STATUS, &reg);
+		if (ret)
+			return ret;
+
+		if (reg & MMA7455_STATUS_DRDY)
+			return 0;
+
+		msleep(20);
+	}
+
+	dev_warn(mma7455->dev, "data not ready\n");
+
+	return -EIO;
+}
+
+static irqreturn_t mma7455_trigger_handler(int irq, void *p)
+{
+	struct iio_poll_func *pf = p;
+	struct iio_dev *indio_dev = pf->indio_dev;
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	u8 buf[16]; /* 3 x 16-bit channels + padding + ts */
+	int ret;
+
+	ret = mma7455_drdy(mma7455);
+	if (ret)
+		goto done;
+
+	ret = regmap_bulk_read(mma7455->regmap, MMA7455_REG_XOUTL, buf,
+			       sizeof(__le16) * 3);
+	if (ret)
+		goto done;
+
+	iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+
+done:
+	iio_trigger_notify_done(indio_dev->trig);
+
+	return IRQ_HANDLED;
+}
+
+static int mma7455_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long mask)
+{
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	unsigned int reg;
+	__le16 data;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		if (iio_buffer_enabled(indio_dev))
+			return -EBUSY;
+
+		ret = mma7455_drdy(mma7455);
+		if (ret)
+			return ret;
+
+		ret = regmap_bulk_read(mma7455->regmap, chan->address, &data,
+				       sizeof(data));
+		if (ret)
+			return ret;
+
+		*val = sign_extend32(le16_to_cpu(data), 9);
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE:
+		*val = 0;
+		*val2 = MMA7455_10BIT_SCALE;
+
+		return IIO_VAL_INT_PLUS_MICRO;
+
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		ret = regmap_read(mma7455->regmap, MMA7455_REG_CTL1, &reg);
+		if (ret)
+			return ret;
+
+		if (reg & MMA7455_CTL1_DFBW_MASK)
+			*val = 250;
+		else
+			*val = 125;
+
+		return IIO_VAL_INT;
+	}
+
+	return -EINVAL;
+}
+
+static int mma7455_write_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     int val, int val2, long mask)
+{
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+	int i;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		if (val == 250 && val2 == 0)
+			i = MMA7455_CTL1_DFBW_125HZ;
+		else if (val == 125 && val2 == 0)
+			i = MMA7455_CTL1_DFBW_62_5HZ;
+		else
+			return -EINVAL;
+
+		return regmap_update_bits(mma7455->regmap, MMA7455_REG_CTL1,
+					  MMA7455_CTL1_DFBW_MASK, i);
+
+	case IIO_CHAN_INFO_SCALE:
+		/* In 10-bit mode there is only one scale available */
+		if (val == 0 && val2 == MMA7455_10BIT_SCALE)
+			return 0;
+		break;
+	}
+
+	return -EINVAL;
+}
+
+static IIO_CONST_ATTR(sampling_frequency_available, "125 250");
+
+static struct attribute *mma7455_attributes[] = {
+	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group mma7455_group = {
+	.attrs = mma7455_attributes,
+};
+
+static const struct iio_info mma7455_info = {
+	.attrs = &mma7455_group,
+	.read_raw = mma7455_read_raw,
+	.write_raw = mma7455_write_raw,
+	.driver_module = THIS_MODULE,
+};
+
+#define MMA7455_CHANNEL(axis, idx) { \
+	.type = IIO_ACCEL, \
+	.modified = 1, \
+	.address = MMA7455_REG_##axis##OUTL,\
+	.channel2 = IIO_MOD_##axis, \
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
+				    BIT(IIO_CHAN_INFO_SCALE), \
+	.scan_index = idx, \
+	.scan_type = { \
+		.sign = 's', \
+		.realbits = 10, \
+		.storagebits = 16, \
+		.endianness = IIO_LE, \
+	}, \
+}
+
+static const struct iio_chan_spec mma7455_channels[] = {
+	MMA7455_CHANNEL(X, 0),
+	MMA7455_CHANNEL(Y, 1),
+	MMA7455_CHANNEL(Z, 2),
+	IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
+static const unsigned long mma7455_scan_masks[] = {0x7, 0};
+
+const struct regmap_config mma7455_core_regmap = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = MMA7455_REG_TW,
+};
+EXPORT_SYMBOL_GPL(mma7455_core_regmap);
+
+int mma7455_core_probe(struct device *dev, struct regmap *regmap,
+		       const char *name)
+{
+	struct mma7455_data *mma7455;
+	struct iio_dev *indio_dev;
+	unsigned int reg;
+	int ret;
+
+	ret = regmap_read(regmap, MMA7455_REG_WHOAMI, &reg);
+	if (ret) {
+		dev_err(dev, "unable to read reg\n");
+		return ret;
+	}
+
+	if (reg != MMA7455_WHOAMI_ID) {
+		dev_err(dev, "device id mismatch\n");
+		return -ENODEV;
+	}
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*mma7455));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, indio_dev);
+	mma7455 = iio_priv(indio_dev);
+	mma7455->regmap = regmap;
+	mma7455->dev = dev;
+
+	indio_dev->info = &mma7455_info;
+	indio_dev->name = name;
+	indio_dev->dev.parent = dev;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = mma7455_channels;
+	indio_dev->num_channels = ARRAY_SIZE(mma7455_channels);
+	indio_dev->available_scan_masks = mma7455_scan_masks;
+
+	regmap_write(mma7455->regmap, MMA7455_REG_MCTL,
+		     MMA7455_MCTL_MODE_MEASURE);
+
+	ret = iio_triggered_buffer_setup(indio_dev, NULL,
+					 mma7455_trigger_handler, NULL);
+	if (ret) {
+		dev_err(dev, "unable to setup triggered buffer\n");
+		return ret;
+	}
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		dev_err(dev, "unable to register device\n");
+		iio_triggered_buffer_cleanup(indio_dev);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mma7455_core_probe);
+
+int mma7455_core_remove(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct mma7455_data *mma7455 = iio_priv(indio_dev);
+
+	iio_device_unregister(indio_dev);
+	iio_triggered_buffer_cleanup(indio_dev);
+
+	regmap_write(mma7455->regmap, MMA7455_REG_MCTL,
+		     MMA7455_MCTL_MODE_STANDBY);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mma7455_core_remove);
+
+MODULE_AUTHOR("Joachim Eastwood <[email protected]>");
+MODULE_DESCRIPTION("Freescale MMA7455L core accelerometer driver");
+MODULE_LICENSE("GPL v2");
drivers/iio/accel/mma7455_i2c.c new file +0 -0
new file mode 100644
index 000000000000..ce4ad0d45f98

drivers/iio/accel/mma7455_i2c.c line 8

Quoted 8 lines
drivers/iio/accel/mma7455_i2c.c new file +8 -0
@@ -0,0 +1,57 @@
+/*
+ * IIO accel I2C driver for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *

And this one (see below, I review backwards as drivers usually make more sense that way around).

Quoted 55 lines
drivers/iio/accel/mma7455_i2c.c new file +49 -0
+ */
+
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+
+#include "mma7455.h"
+
+static int mma7455_i2c_probe(struct i2c_client *i2c,
+			     const struct i2c_device_id *id)
+{
+	struct regmap *regmap;
+	const char *name = NULL;
+
+	regmap = devm_regmap_init_i2c(i2c, &mma7455_core_regmap);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	if (id)
+		name = id->name;
+
+	return mma7455_core_probe(&i2c->dev, regmap, name);
+}
+
+static int mma7455_i2c_remove(struct i2c_client *i2c)
+{
+	return mma7455_core_remove(&i2c->dev);
+}
+
+static const struct i2c_device_id mma7455_i2c_ids[] = {
+	{ "mma7455", 0 },
+	{ "mma7456", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, mma7455_i2c_ids);
+
+static struct i2c_driver mma7455_i2c_driver = {
+	.probe = mma7455_i2c_probe,
+	.remove = mma7455_i2c_remove,
+	.id_table = mma7455_i2c_ids,
+	.driver = {
+		.name	= "mma7455-i2c",
+	},
+};
+module_i2c_driver(mma7455_i2c_driver);
+
+MODULE_AUTHOR("Joachim Eastwood <[email protected]>");
+MODULE_DESCRIPTION("Freescale MMA7455L I2C accelerometer driver");
+MODULE_LICENSE("GPL v2");
drivers/iio/accel/mma7455_spi.c new file +0 -0
new file mode 100644
index 000000000000..5dc0bb75d289

drivers/iio/accel/mma7455_spi.c line 7

Quoted 7 lines
drivers/iio/accel/mma7455_spi.c new file +7 -0
@@ -0,0 +1,53 @@
+/*
+ * IIO accel SPI driver for Freescale MMA7455L 3-axis 10-bit accelerometer
+ * Copyright 2015 Joachim Eastwood <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

My quest against blank lines with no purpose continues. I'll edit this one out in the appy.

Quoted 37 lines
drivers/iio/accel/mma7455_spi.c new file +36 -0
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/spi/spi.h>
+
+#include "mma7455.h"
+
+static int mma7455_spi_probe(struct spi_device *spi)
+{
+	const struct spi_device_id *id = spi_get_device_id(spi);
+	struct regmap *regmap;
+
+	regmap = devm_regmap_init_spi(spi, &mma7455_core_regmap);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	return mma7455_core_probe(&spi->dev, regmap, id->name);
+}
+
+static int mma7455_spi_remove(struct spi_device *spi)
+{
+	return mma7455_core_remove(&spi->dev);
+}
+
+static const struct spi_device_id mma7455_spi_ids[] = {
+	{ "mma7455", 0 },
+	{ "mma7456", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(spi, mma7455_spi_ids);
+
+static struct spi_driver mma7455_spi_driver = {
+	.probe = mma7455_spi_probe,
+	.remove = mma7455_spi_remove,

drivers/iio/accel/mma7455_spi.c line 53

Quoted 10 lines
drivers/iio/accel/mma7455_spi.c new file +10 -0
+	.id_table = mma7455_spi_ids,
+	.driver = {
+		.name = "mma7455-spi",
+	},
+};
+module_spi_driver(mma7455_spi_driver);
+
+MODULE_AUTHOR("Joachim Eastwood <[email protected]>");
+MODULE_DESCRIPTION("Freescale MMA7455L SPI accelerometer driver");
+MODULE_LICENSE("GPL v2");

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#34 lore raw

Re: [PATCH v4] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Hi Jonathan,

Quoted 12 lines · Jonathan Cameron
Quoted 11 lines · Jonathan Cameron
Quoted 10 lines · Joachim Eastwood

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

A few really trivial gripes I'll deal with when applying.

+ the s/header/driver thing Martin picked up on.

Forgot the important bit:

Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.

Thanks for fixing up and applying.

I can't seem to find it in your testing branch on
kernel/git/jic23/iio.git, though.

regards,
Joachim Eastwood

maintainer
#35 lore raw

Re: [PATCH v4] iio: accel: add Freescale MMA7455L/MMA7456L 3-axis accelerometer driver

Quoted 21 lines · Joachim Eastwood

Hi Jonathan,

Quoted 18 lines · Jonathan Cameron
Quoted 7 lines · Jonathan Cameron
Quoted 6 lines · Joachim Eastwood

Add support for Freescale MMA7455L/MMA7456L 3-axis in 10-bit mode for I2C and SPI bus. This rather simple driver that currently doesn't support all the hardware features of MMA7455L/MMA7456L.

Tested on Embedded Artist's LPC4357 Dev Kit with MMA7455L on I2C bus.

Quoted 8 lines
Quoted 5 lines

Data sheets for the two devices can be found here:
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7455L.pdf
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7456L.pdf

A few really trivial gripes I'll deal with when applying.

+ the s/header/driver thing Martin picked up on.

Forgot the important bit:

Quoted 7 lines
Quoted 2 lines

Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.

Thanks for fixing up and applying.

I can't seem to find it in your testing branch on
kernel/git/jic23/iio.git, though.

Sorry, more than likely I failed to push out. Once my local build tests are done I'll be pushing out today.

Have a habit of reaching the end of a review time when someone shouts dinner then failing to remember to come back later and push stuff out.

oops.

Jonathan

Quoted 9 lines

regards,
Joachim Eastwood
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html