* iio: STMicroelectronics iio drivers
@ 2013-01-08 16:30 Denis CIOCCA
0 siblings, 0 replies; 20+ messages in thread
From: Denis CIOCCA @ 2013-01-08 16:30 UTC (permalink / raw)
To: jic23, lars, linux-iio
Hi everybody,
I modified the ST drivers in accordance with Jonathan comments. I couldn't use
coccicheck because I have some problem when I run 'make coccichek' (I'm working on to
undestand why).
The others major updates are:
- delete of try_reenable_callback (was not necessary);
- trigger code moved to sensors common code;
- bugfix DMA buffer cacheline-aligned;
- check if the device probed is corrected to avoid confusion;
- improvement of code style;
Thanks,
Denis
^ permalink raw reply [flat|nested] 20+ messages in thread
* iio: STMicroelectronics iio drivers
@ 2013-01-15 8:30 Denis CIOCCA
2013-01-15 8:30 ` [PATCH 1/9] iio:common: Add STMicroelectronics common library Denis CIOCCA
` (4 more replies)
0 siblings, 5 replies; 20+ messages in thread
From: Denis CIOCCA @ 2013-01-15 8:30 UTC (permalink / raw)
To: jic23, lars, linux-iio
Hi Jonathan,
I sent to you the new patches to fix the u8 casting and a little bugfix in the header files (functions within #ifdef).
Thanks,
Denis
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 1/9] iio:common: Add STMicroelectronics common library
2013-01-15 8:30 iio: STMicroelectronics iio drivers Denis CIOCCA
@ 2013-01-15 8:30 ` Denis CIOCCA
2013-01-16 14:07 ` Lars-Peter Clausen
2013-01-16 14:18 ` Lars-Peter Clausen
2013-01-15 8:30 ` [PATCH 2/9] iio:accel: Add STMicroelectronics accelerometers driver Denis CIOCCA
` (3 subsequent siblings)
4 siblings, 2 replies; 20+ messages in thread
From: Denis CIOCCA @ 2013-01-15 8:30 UTC (permalink / raw)
To: jic23, lars, linux-iio; +Cc: Denis Ciocca
This patch add generic library for STMicroelectronics 3-axis sensors.
Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
drivers/iio/common/Kconfig | 1 +
drivers/iio/common/Makefile | 1 +
drivers/iio/common/st_sensors/Kconfig | 30 ++
drivers/iio/common/st_sensors/Makefile | 9 +
drivers/iio/common/st_sensors/st_sensors_buffer.c | 115 +++++++
drivers/iio/common/st_sensors/st_sensors_core.c | 329 ++++++++++++++++++++
drivers/iio/common/st_sensors/st_sensors_i2c.c | 81 +++++
drivers/iio/common/st_sensors/st_sensors_spi.c | 128 ++++++++
drivers/iio/common/st_sensors/st_sensors_trigger.c | 83 +++++
include/linux/iio/common/st_sensors.h | 278 +++++++++++++++++
10 files changed, 1055 insertions(+), 0 deletions(-)
create mode 100644 drivers/iio/common/st_sensors/Kconfig
create mode 100644 drivers/iio/common/st_sensors/Makefile
create mode 100644 drivers/iio/common/st_sensors/st_sensors_buffer.c
create mode 100644 drivers/iio/common/st_sensors/st_sensors_core.c
create mode 100644 drivers/iio/common/st_sensors/st_sensors_i2c.c
create mode 100644 drivers/iio/common/st_sensors/st_sensors_spi.c
create mode 100644 drivers/iio/common/st_sensors/st_sensors_trigger.c
create mode 100644 include/linux/iio/common/st_sensors.h
diff --git a/drivers/iio/common/Kconfig b/drivers/iio/common/Kconfig
index ed45ee5..0b6e97d 100644
--- a/drivers/iio/common/Kconfig
+++ b/drivers/iio/common/Kconfig
@@ -3,3 +3,4 @@
#
source "drivers/iio/common/hid-sensors/Kconfig"
+source "drivers/iio/common/st_sensors/Kconfig"
diff --git a/drivers/iio/common/Makefile b/drivers/iio/common/Makefile
index 8158400..c2352be 100644
--- a/drivers/iio/common/Makefile
+++ b/drivers/iio/common/Makefile
@@ -7,3 +7,4 @@
#
obj-y += hid-sensors/
+obj-y += st_sensors/
diff --git a/drivers/iio/common/st_sensors/Kconfig b/drivers/iio/common/st_sensors/Kconfig
new file mode 100644
index 0000000..1cf41fd
--- /dev/null
+++ b/drivers/iio/common/st_sensors/Kconfig
@@ -0,0 +1,30 @@
+#
+# Hid Sensor common modules
+#
+menu "STMicroelectronics sensors library"
+
+config IIO_ST_SENSORS_CORE
+ tristate "Common modules for all ST sensors IIO drivers"
+ help
+ Say yes here to build support for ST sensors to use
+ common core functions.
+
+config IIO_ST_SENSORS_I2C
+ tristate "I2C common library for ST Sensor IIO drivers"
+ help
+ Say yes here to build support for ST sensors to use
+ common i2c functions.
+
+config IIO_ST_SENSORS_SPI
+ tristate "SPI common library for ST Sensor IIO drivers"
+ help
+ Say yes here to build support for ST sensors to use
+ common spi functions.
+
+config IIO_ST_SENSORS_TRIGGERED_BUFFER
+ tristate "trigger and buffer common library for ST Sensor IIO drivers"
+ help
+ Say yes here to build support for ST sensors to use
+ common trigger and buffer functions.
+
+endmenu
diff --git a/drivers/iio/common/st_sensors/Makefile b/drivers/iio/common/st_sensors/Makefile
new file mode 100644
index 0000000..8418b6b
--- /dev/null
+++ b/drivers/iio/common/st_sensors/Makefile
@@ -0,0 +1,9 @@
+#
+# Makefile for the STMicroelectronics sensor common modules.
+#
+
+obj-$(CONFIG_IIO_ST_SENSORS_CORE) += st_sensors_core.o
+obj-$(CONFIG_IIO_ST_SENSORS_I2C) += st_sensors_i2c.o
+obj-$(CONFIG_IIO_ST_SENSORS_SPI) += st_sensors_spi.o
+obj-$(CONFIG_IIO_ST_SENSORS_TRIGGERED_BUFFER) += st_sensors_triggered_buffer.o
+st_sensors_triggered_buffer-y := st_sensors_trigger.o st_sensors_buffer.o
diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c
new file mode 100644
index 0000000..2170b1d
--- /dev/null
+++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c
@@ -0,0 +1,115 @@
+/*
+ * STMicroelectronics sensors buffer library driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+#include <linux/interrupt.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/irqreturn.h>
+
+#include <linux/iio/common/st_sensors.h>
+
+int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
+{
+ int i, n = 0, len;
+ u8 addr[ST_SENSORS_NUMBER_DATA_CHANNELS];
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+
+ for (i = 0; i < ST_SENSORS_NUMBER_DATA_CHANNELS; i++) {
+ if (test_bit(i, indio_dev->active_scan_mask)) {
+ addr[n] = indio_dev->channels[i].address;
+ n++;
+ }
+ }
+ switch (n) {
+ case 1:
+ len = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
+ addr[0], ST_SENSORS_BYTE_FOR_CHANNEL, buf,
+ sdata->multiread_bit);
+ break;
+ case 2:
+ if ((addr[1] - addr[0]) == ST_SENSORS_BYTE_FOR_CHANNEL) {
+ len = sdata->tf->read_multiple_byte(&sdata->tb,
+ sdata->dev, addr[0],
+ ST_SENSORS_BYTE_FOR_CHANNEL*n,
+ buf, sdata->multiread_bit);
+ } else {
+ u8 rx_array[ST_SENSORS_BYTE_FOR_CHANNEL*
+ ST_SENSORS_NUMBER_DATA_CHANNELS];
+ len = sdata->tf->read_multiple_byte(&sdata->tb,
+ sdata->dev, addr[0],
+ ST_SENSORS_BYTE_FOR_CHANNEL*
+ ST_SENSORS_NUMBER_DATA_CHANNELS,
+ rx_array, sdata->multiread_bit);
+ if (len < 0)
+ goto read_data_channels_error;
+
+ for (i = 0; i < n * ST_SENSORS_NUMBER_DATA_CHANNELS;
+ i++) {
+ if (i < n)
+ buf[i] = rx_array[i];
+ else
+ buf[i] = rx_array[n + i];
+ }
+ len = ST_SENSORS_BYTE_FOR_CHANNEL*n;
+ }
+ break;
+ case 3:
+ len = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
+ addr[0], ST_SENSORS_BYTE_FOR_CHANNEL*
+ ST_SENSORS_NUMBER_DATA_CHANNELS,
+ buf, sdata->multiread_bit);
+ break;
+ default:
+ len = -EINVAL;
+ goto read_data_channels_error;
+ }
+ if (len != ST_SENSORS_BYTE_FOR_CHANNEL*n) {
+ len = -EIO;
+ goto read_data_channels_error;
+ }
+
+read_data_channels_error:
+ return len;
+}
+EXPORT_SYMBOL(st_sensors_get_buffer_element);
+
+irqreturn_t st_sensors_trigger_handler(int irq, void *p)
+{
+ int len;
+ struct iio_poll_func *pf = p;
+ struct iio_dev *indio_dev = pf->indio_dev;
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+
+ len = st_sensors_get_buffer_element(indio_dev, sdata->buffer_data);
+ if (len < 0)
+ goto st_sensors_get_buffer_element_error;
+
+ if (indio_dev->scan_timestamp)
+ *(s64 *)((u8 *)sdata->buffer_data +
+ ALIGN(len, sizeof(s64))) = pf->timestamp;
+
+ iio_push_to_buffers(indio_dev, sdata->buffer_data);
+
+st_sensors_get_buffer_element_error:
+ iio_trigger_notify_done(indio_dev->trig);
+
+ return IRQ_HANDLED;
+}
+EXPORT_SYMBOL(st_sensors_trigger_handler);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics ST-sensors buffer");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
new file mode 100644
index 0000000..af3eb1f
--- /dev/null
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -0,0 +1,329 @@
+/*
+ * STMicroelectronics sensors core library driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/iio/iio.h>
+
+#include <linux/iio/common/st_sensors.h>
+
+
+#define ST_SENSORS_WAI_ADDRESS 0x0f
+#define ST_SENSORS_G_TO_MG(x) (x*1000000ULL)
+
+int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, u8 reg_addr,
+ u8 mask, short num_bit, u8 data)
+{
+ int err;
+ u8 new_data;
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+
+ err = sdata->tf->read_byte(&sdata->tb, sdata->dev, reg_addr, &new_data);
+ if (err < 0)
+ goto st_sensors_write_data_with_mask_error;
+
+ new_data = ((new_data & (~mask)) | ((data << __ffs(mask)) & mask));
+ err = sdata->tf->write_byte(&sdata->tb, sdata->dev, reg_addr, new_data);
+
+st_sensors_write_data_with_mask_error:
+ return err;
+}
+EXPORT_SYMBOL(st_sensors_write_data_with_mask);
+
+int st_sensors_get_sampling_frequency_avl(struct iio_dev *indio_dev,
+ const struct st_sensor_odr_avl *odr_avl, char *buf)
+{
+ int i, len = 0;
+
+ mutex_lock(&indio_dev->mlock);
+ for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) {
+ if (odr_avl[i].hz == 0)
+ break;
+
+ len += sprintf(buf + len, "%d ", odr_avl[i].hz);
+ }
+ mutex_unlock(&indio_dev->mlock);
+ buf[len - 1] = '\n';
+
+ return len;
+}
+EXPORT_SYMBOL(st_sensors_get_sampling_frequency_avl);
+
+int st_sensors_get_scale_avl(struct iio_dev *indio_dev,
+ const struct st_sensor_fullscale_avl *fullscale_avl, char *buf)
+{
+ int i, len = 0;
+
+ mutex_lock(&indio_dev->mlock);
+ for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
+ if (fullscale_avl[i].num == 0)
+ break;
+
+ len += sprintf(buf + len, "0.%06u ", fullscale_avl[i].gain);
+ }
+ mutex_unlock(&indio_dev->mlock);
+ buf[len - 1] = '\n';
+
+ return len;
+}
+EXPORT_SYMBOL(st_sensors_get_scale_avl);
+
+static int st_sensors_match_odr(const struct st_sensors *sensor,
+ unsigned int odr, struct st_sensor_odr_avl *odr_out)
+{
+ int i, ret = -EINVAL;
+
+ for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) {
+ if ((sensor->odr.odr_avl[i].hz == odr) &&
+ (sensor->odr.odr_avl[i].hz != 0)) {
+ odr_out->hz = sensor->odr.odr_avl[i].hz;
+ odr_out->value = sensor->odr.odr_avl[i].value;
+ ret = 0;
+ break;
+ }
+ }
+
+ return ret;
+}
+
+int st_sensors_set_odr(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, unsigned int odr)
+{
+ int err;
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+ struct st_sensor_odr_avl odr_out;
+
+ err = st_sensors_match_odr(sensor, odr, &odr_out);
+ if (err < 0)
+ goto st_sensors_match_odr_error;
+
+ if ((sensor->odr.addr == sensor->pw.addr) &&
+ (sensor->odr.mask == sensor->pw.mask)) {
+ if (sdata->enabled == true) {
+ err = st_sensors_write_data_with_mask(indio_dev,
+ sensor->odr.addr, sensor->odr.mask,
+ sensor->odr.num_bit,
+ odr_out.value);
+ } else {
+ err = 0;
+ }
+ } else {
+ err = st_sensors_write_data_with_mask(indio_dev,
+ sensor->odr.addr, sensor->odr.mask,
+ sensor->odr.num_bit, odr_out.value);
+ }
+ if (err >= 0)
+ sdata->odr = odr_out.hz;
+
+st_sensors_match_odr_error:
+ return err;
+}
+EXPORT_SYMBOL(st_sensors_set_odr);
+
+static int st_sensors_match_fs(const struct st_sensors *sensor,
+ unsigned int fs, int *index_fs_avl)
+{
+ int i, ret = -EINVAL;
+
+ for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
+ if ((sensor->fs.fs_avl[i].num == fs) &&
+ (sensor->fs.fs_avl[i].num != 0)) {
+ *index_fs_avl = i;
+ ret = 0;
+ break;
+ }
+ }
+
+ return ret;
+}
+
+int st_sensors_set_fullscale(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, unsigned int fs)
+{
+ int err, i;
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+
+ err = st_sensors_match_fs(sensor, fs, &i);
+ if (err < 0)
+ goto st_accel_set_fullscale_error;
+
+ err = st_sensors_write_data_with_mask(indio_dev,
+ sensor->fs.addr, sensor->fs.mask, sensor->fs.num_bit,
+ sensor->fs.fs_avl[i].value);
+ if (err < 0)
+ goto st_accel_set_fullscale_error;
+
+ sdata->current_fullscale = (struct st_sensor_fullscale_avl *)
+ &sensor->fs.fs_avl[i];
+ return err;
+
+st_accel_set_fullscale_error:
+ dev_err(&indio_dev->dev, "failed to set new fullscale.\n");
+ return err;
+}
+EXPORT_SYMBOL(st_sensors_set_fullscale);
+
+int st_sensors_set_enable(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, bool enable)
+{
+ int err = -EINVAL;
+ bool found;
+ u8 tmp_value;
+ struct st_sensor_odr_avl odr_out;
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+
+ if (enable) {
+ found = false;
+ tmp_value = sensor->pw.value_on;
+ if ((sensor->odr.addr == sensor->pw.addr) &&
+ (sensor->odr.mask == sensor->pw.mask)) {
+ err = st_sensors_match_odr(sensor,
+ sdata->odr, &odr_out);
+ if (err < 0)
+ goto set_enable_error;
+ tmp_value = odr_out.value;
+ found = true;
+ }
+ err = st_sensors_write_data_with_mask(indio_dev,
+ sensor->pw.addr, sensor->pw.mask,
+ sensor->pw.num_bit, tmp_value);
+ if (err < 0)
+ goto set_enable_error;
+ sdata->enabled = true;
+ if (found)
+ sdata->odr = odr_out.hz;
+ } else {
+ err = st_sensors_write_data_with_mask(indio_dev,
+ sensor->pw.addr, sensor->pw.mask,
+ sensor->pw.num_bit, sensor->pw.value_off);
+ if (err < 0)
+ goto set_enable_error;
+ sdata->enabled = false;
+ }
+
+set_enable_error:
+ return err;
+}
+EXPORT_SYMBOL(st_sensors_set_enable);
+
+int st_sensors_set_axis_enable(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, u8 axis_enable)
+{
+ return st_sensors_write_data_with_mask(indio_dev,
+ sensor->enable_axis.addr, sensor->enable_axis.mask,
+ 3, axis_enable);
+}
+EXPORT_SYMBOL(st_sensors_set_axis_enable);
+
+int st_sensors_init_sensor(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor)
+{
+ int err;
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+
+ mutex_init(&sdata->tb.buf_lock);
+
+ err = st_sensors_set_enable(indio_dev, sensor, false);
+ if (err < 0)
+ goto init_error;
+
+ err = st_sensors_set_fullscale(indio_dev, sensor,
+ sdata->current_fullscale->num);
+ if (err < 0)
+ goto init_error;
+
+ err = st_sensors_set_odr(indio_dev, sensor, sdata->odr);
+ if (err < 0)
+ goto init_error;
+
+ /* set BDU */
+ err = st_sensors_write_data_with_mask(indio_dev, sensor->bdu.addr,
+ sensor->bdu.mask, 1, true);
+ if (err < 0)
+ goto init_error;
+
+ err = st_sensors_set_axis_enable(indio_dev, sensor,
+ ST_SENSORS_ENABLE_ALL_CHANNELS);
+
+init_error:
+ return err;
+}
+EXPORT_SYMBOL(st_sensors_init_sensor);
+
+int st_sensors_set_dataready_irq(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, bool enable)
+{
+ int err;
+
+ /* Enable/Disable the interrupt generator 1. */
+ if (sensor->drdy_irq.ig1.en_addr > 0) {
+ err = st_sensors_write_data_with_mask(indio_dev,
+ sensor->drdy_irq.ig1.en_addr,
+ sensor->drdy_irq.ig1.en_mask, 1, (int)enable);
+ if (err < 0)
+ goto st_accel_set_dataready_irq_error;
+ }
+
+ /* Enable/Disable the interrupt generator for data ready. */
+ err = st_sensors_write_data_with_mask(indio_dev,
+ sensor->drdy_irq.addr,
+ sensor->drdy_irq.mask, 1, (int)enable);
+
+st_accel_set_dataready_irq_error:
+ return err;
+}
+EXPORT_SYMBOL(st_sensors_set_dataready_irq);
+
+int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, int scale)
+{
+ int err = -EINVAL, i;
+
+ for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
+ if ((sensor->fs.fs_avl[i].gain == scale) &&
+ (sensor->fs.fs_avl[i].gain != 0)) {
+ err = 0;
+ break;
+ }
+ }
+ if (err < 0)
+ goto st_sensors_match_scale_error;
+
+ err = st_sensors_set_fullscale(indio_dev,
+ sensor, sensor->fs.fs_avl[i].num);
+
+st_sensors_match_scale_error:
+ return err;
+}
+EXPORT_SYMBOL(st_sensors_set_fullscale_by_gain);
+
+int st_sensors_read_axis_data(struct iio_dev *indio_dev, u8 ch_addr, int *data)
+{
+ int err;
+ u8 outdata[ST_SENSORS_BYTE_FOR_CHANNEL];
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+
+ err = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
+ ch_addr, ST_SENSORS_BYTE_FOR_CHANNEL,
+ outdata, sdata->multiread_bit);
+ if (err < 0)
+ goto read_error;
+
+ *data = ((s16)le16_to_cpup((__le16 *)outdata));
+
+read_error:
+ return err;
+}
+EXPORT_SYMBOL(st_sensors_read_axis_data);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics ST-sensors core");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c
new file mode 100644
index 0000000..1498831
--- /dev/null
+++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c
@@ -0,0 +1,81 @@
+/*
+ * STMicroelectronics sensors i2c library driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/iio/iio.h>
+
+#include <linux/iio/common/st_sensors.h>
+
+
+#define ST_SENSORS_I2C_MULTIREAD 0x80
+
+unsigned int st_sensors_i2c_get_irq(struct iio_dev *indio_dev)
+{
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+
+ return to_i2c_client(sdata->dev)->irq;
+}
+
+static int st_sensors_i2c_read_byte(struct st_sensor_transfer_buffer *tb,
+ struct device *dev, u8 reg_addr, u8 *res_byte)
+{
+ int err;
+
+ err = i2c_smbus_read_byte_data(to_i2c_client(dev), reg_addr);
+ if (err < 0)
+ goto st_accel_i2c_read_byte_error;
+
+ *res_byte = err & 0xff;
+
+st_accel_i2c_read_byte_error:
+ return err < 0 ? err : 0;
+}
+
+static int st_sensors_i2c_read_multiple_byte(
+ struct st_sensor_transfer_buffer *tb, struct device *dev,
+ u8 reg_addr, int len, u8 *data, bool multiread_bit)
+{
+ if (multiread_bit == true)
+ reg_addr |= ST_SENSORS_I2C_MULTIREAD;
+
+ return i2c_smbus_read_i2c_block_data(to_i2c_client(dev),
+ reg_addr, len, data);
+}
+
+static int st_sensors_i2c_write_byte(struct st_sensor_transfer_buffer *tb,
+ struct device *dev, u8 reg_addr, u8 data)
+{
+ return i2c_smbus_write_byte_data(to_i2c_client(dev), reg_addr, data);
+}
+
+static const struct st_sensor_transfer_function st_sensors_tf_i2c = {
+ .read_byte = st_sensors_i2c_read_byte,
+ .write_byte = st_sensors_i2c_write_byte,
+ .read_multiple_byte = st_sensors_i2c_read_multiple_byte,
+};
+
+void st_sensors_i2c_configure(struct iio_dev *indio_dev,
+ struct i2c_client *client, struct st_sensor_data *sdata)
+{
+ i2c_set_clientdata(client, indio_dev);
+
+ indio_dev->dev.parent = &client->dev;
+ indio_dev->name = client->name;
+
+ sdata->tf = (struct st_sensor_transfer_function *)&st_sensors_tf_i2c;
+ sdata->get_irq_data_ready = st_sensors_i2c_get_irq;
+}
+EXPORT_SYMBOL(st_sensors_i2c_configure);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/common/st_sensors/st_sensors_spi.c b/drivers/iio/common/st_sensors/st_sensors_spi.c
new file mode 100644
index 0000000..2079f4b
--- /dev/null
+++ b/drivers/iio/common/st_sensors/st_sensors_spi.c
@@ -0,0 +1,128 @@
+/*
+ * STMicroelectronics sensors spi library driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/iio/iio.h>
+
+#include <linux/iio/common/st_sensors.h>
+
+
+#define ST_SENSORS_SPI_MULTIREAD 0xc0
+#define ST_SENSORS_SPI_READ 0x80
+
+unsigned int st_sensors_spi_get_irq(struct iio_dev *indio_dev)
+{
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+
+ return to_spi_device(sdata->dev)->irq;
+}
+
+static int st_sensors_spi_read(struct st_sensor_transfer_buffer *tb,
+ struct device *dev, u8 reg_addr, int len, u8 *data, bool multiread_bit)
+{
+ struct spi_message msg;
+ int err;
+
+ struct spi_transfer xfers[] = {
+ {
+ .tx_buf = tb->tx_buf,
+ .bits_per_word = 8,
+ .len = 1,
+ },
+ {
+ .rx_buf = tb->rx_buf,
+ .bits_per_word = 8,
+ .len = len,
+ }
+ };
+
+ mutex_lock(&tb->buf_lock);
+ if ((multiread_bit == true) && (len > 1))
+ tb->tx_buf[0] = reg_addr | ST_SENSORS_SPI_MULTIREAD;
+ else
+ tb->tx_buf[0] = reg_addr | ST_SENSORS_SPI_READ;
+
+ spi_message_init(&msg);
+ spi_message_add_tail(&xfers[0], &msg);
+ spi_message_add_tail(&xfers[1], &msg);
+ err = spi_sync(to_spi_device(dev), &msg);
+ if (err)
+ goto acc_spi_read_error;
+
+ memcpy(data, tb->rx_buf, len*sizeof(u8));
+ mutex_unlock(&tb->buf_lock);
+ return len;
+
+acc_spi_read_error:
+ mutex_unlock(&tb->buf_lock);
+ return err;
+}
+
+static int st_sensors_spi_read_byte(struct st_sensor_transfer_buffer *tb,
+ struct device *dev, u8 reg_addr, u8 *res_byte)
+{
+ return st_sensors_spi_read(tb, dev, reg_addr, 1, res_byte, false);
+}
+
+static int st_sensors_spi_read_multiple_byte(
+ struct st_sensor_transfer_buffer *tb, struct device *dev,
+ u8 reg_addr, int len, u8 *data, bool multiread_bit)
+{
+ return st_sensors_spi_read(tb, dev, reg_addr, len, data, multiread_bit);
+}
+
+static int st_sensors_spi_write_byte(struct st_sensor_transfer_buffer *tb,
+ struct device *dev, u8 reg_addr, u8 data)
+{
+ struct spi_message msg;
+ int err;
+
+ struct spi_transfer xfers = {
+ .tx_buf = tb->tx_buf,
+ .bits_per_word = 8,
+ .len = 2,
+ };
+
+ mutex_lock(&tb->buf_lock);
+ tb->tx_buf[0] = reg_addr;
+ tb->tx_buf[1] = data;
+
+ spi_message_init(&msg);
+ spi_message_add_tail(&xfers, &msg);
+ err = spi_sync(to_spi_device(dev), &msg);
+ mutex_unlock(&tb->buf_lock);
+
+ return err;
+}
+
+static const struct st_sensor_transfer_function st_sensors_tf_spi = {
+ .read_byte = st_sensors_spi_read_byte,
+ .write_byte = st_sensors_spi_write_byte,
+ .read_multiple_byte = st_sensors_spi_read_multiple_byte,
+};
+
+void st_sensors_spi_configure(struct iio_dev *indio_dev,
+ struct spi_device *spi, struct st_sensor_data *sdata)
+{
+ spi_set_drvdata(spi, indio_dev);
+
+ indio_dev->dev.parent = &spi->dev;
+ indio_dev->name = spi->modalias;
+
+ sdata->tf = (struct st_sensor_transfer_function *)&st_sensors_tf_spi;
+ sdata->get_irq_data_ready = st_sensors_spi_get_irq;
+}
+EXPORT_SYMBOL(st_sensors_spi_configure);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics ST-sensors spi driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c
new file mode 100644
index 0000000..1c69c63
--- /dev/null
+++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c
@@ -0,0 +1,83 @@
+/*
+ * STMicroelectronics sensors trigger library driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+#include <linux/interrupt.h>
+
+#include <linux/iio/common/st_sensors.h>
+
+static struct iio_trigger_ops st_sensors_trigger_ops = {
+ .owner = THIS_MODULE,
+};
+
+int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
+ int (*set_trigger_state)(struct iio_trigger *trig, bool state),
+ int (*try_reenable)(struct iio_trigger *trig))
+{
+ int err;
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+
+ sdata->trig = iio_trigger_alloc("%s-trigger", indio_dev->name);
+ if (sdata->trig == NULL) {
+ err = -ENOMEM;
+ dev_err(&indio_dev->dev, "failed to allocate iio trigger.\n");
+ goto iio_trigger_alloc_error;
+ }
+
+ err = request_threaded_irq(sdata->get_irq_data_ready(indio_dev),
+ iio_trigger_generic_data_rdy_poll,
+ NULL,
+ IRQF_TRIGGER_RISING,
+ sdata->trig->name,
+ sdata->trig);
+ if (err)
+ goto request_irq_error;
+
+ st_sensors_trigger_ops.set_trigger_state = set_trigger_state;
+ st_sensors_trigger_ops.try_reenable = try_reenable;
+ sdata->trig->private_data = indio_dev;
+ sdata->trig->ops = &st_sensors_trigger_ops;
+ sdata->trig->dev.parent = sdata->dev;
+
+ err = iio_trigger_register(sdata->trig);
+ if (err < 0) {
+ dev_err(&indio_dev->dev, "failed to register iio trigger.\n");
+ goto iio_trigger_register_error;
+ }
+ indio_dev->trig = sdata->trig;
+
+ return 0;
+
+iio_trigger_register_error:
+ free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig);
+request_irq_error:
+ iio_trigger_free(sdata->trig);
+iio_trigger_alloc_error:
+ return err;
+}
+EXPORT_SYMBOL(st_sensors_allocate_trigger);
+
+void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
+{
+ struct st_sensor_data *sdata = iio_priv(indio_dev);
+
+ iio_trigger_unregister(sdata->trig);
+ free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig);
+ iio_trigger_free(sdata->trig);
+}
+EXPORT_SYMBOL(st_sensors_deallocate_trigger);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics ST-sensors trigger");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
new file mode 100644
index 0000000..f396bc5
--- /dev/null
+++ b/include/linux/iio/common/st_sensors.h
@@ -0,0 +1,278 @@
+/*
+ * STMicroelectronics sensors library driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#ifndef ST_SENSORS_H
+#define ST_SENSORS_H
+
+#include <linux/i2c.h>
+#include <linux/spi/spi.h>
+#include <linux/irqreturn.h>
+#include <linux/iio/trigger.h>
+
+
+#define ST_SENSORS_TX_MAX_LENGHT 2
+#define ST_SENSORS_RX_MAX_LENGHT 6
+
+#define ST_SENSORS_ODR_LIST_MAX 10
+#define ST_SENSORS_FULLSCALE_AVL_MAX 10
+
+#define ST_SENSORS_NUMBER_ALL_CHANNELS 4
+#define ST_SENSORS_NUMBER_DATA_CHANNELS 3
+#define ST_SENSORS_ENABLE_ALL_CHANNELS 0x07
+#define ST_SENSORS_BYTE_FOR_CHANNEL 2
+#define ST_SENSORS_SCAN_X 0
+#define ST_SENSORS_SCAN_Y 1
+#define ST_SENSORS_SCAN_Z 2
+#define ST_SENSORS_DEFAULT_12_REALBITS 12
+#define ST_SENSORS_DEFAULT_16_REALBITS 16
+#define ST_SENSORS_DEFAULT_POWER_ON_VALUE 0x01
+#define ST_SENSORS_DEFAULT_POWER_OFF_VALUE 0x00
+#define ST_SENSORS_DEFAULT_WAI_ADDRESS 0x0f
+#define ST_SENSORS_DEFAULT_AXIS_ADDR 0x20
+#define ST_SENSORS_DEFAULT_AXIS_MASK 0x07
+#define ST_SENSORS_DEFAULT_AXIS_N_BIT 3
+
+#define ST_SENSORS_MAX_NAME 17
+#define ST_SENSORS_MAX_4WAI 7
+
+#define ST_SENSORS_LSM_CHANNELS(device_type, index, mod, endian, bits, addr) \
+{ \
+ .type = device_type, \
+ .modified = 1, \
+ .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
+ IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
+ .scan_index = index, \
+ .channel2 = mod, \
+ .address = addr, \
+ .scan_type = { \
+ .sign = 's', \
+ .realbits = bits, \
+ .shift = 16 - bits, \
+ .storagebits = 16, \
+ .endianness = endian, \
+ }, \
+}
+
+struct st_sensor_odr_avl {
+ unsigned int hz;
+ u8 value;
+};
+
+struct st_sensor_odr {
+ u8 addr;
+ u8 mask;
+ short num_bit;
+ struct st_sensor_odr_avl odr_avl[ST_SENSORS_ODR_LIST_MAX];
+};
+
+struct st_sensor_power {
+ u8 addr;
+ u8 mask;
+ unsigned short num_bit;
+ u8 value_off;
+ u8 value_on;
+};
+
+struct st_sensor_axis {
+ u8 addr;
+ u8 mask;
+};
+
+struct st_sensor_fullscale_avl {
+ unsigned int num;
+ u8 value;
+ unsigned int gain;
+ unsigned int gain2;
+};
+
+struct st_sensor_fullscale {
+ u8 addr;
+ u8 mask;
+ unsigned short num_bit;
+ struct st_sensor_fullscale_avl fs_avl[ST_SENSORS_FULLSCALE_AVL_MAX];
+};
+
+/**
+ * struct st_sensor_bdu - ST sensor device block data update
+ * @addr: address of the register.
+ * @mask: mask to write the block data update flag.
+ */
+struct st_sensor_bdu {
+ u8 addr;
+ u8 mask;
+};
+
+/**
+ * struct st_sensor_data_ready_irq - ST sensor device data-ready interrupt
+ * @addr: address of the register.
+ * @mask: mask to write the on/off value.
+ * struct ig1 - represents the Interrupt Generator 1 of sensors.
+ * @en_addr: address of the enable ig1 register.
+ * @en_mask: mask to write the on/off value for enable.
+ */
+struct st_sensor_data_ready_irq {
+ u8 addr;
+ u8 mask;
+ struct {
+ u8 en_addr;
+ u8 en_mask;
+ } ig1;
+};
+
+/**
+ * struct st_sensor_transfer_buffer - ST sensor device I/O buffer
+ * @buf_lock: Mutex to protect rx and tx buffers.
+ * @tx_buf: Buffer used by SPI transfer function to send data to the sensors.
+ * This buffer is used to avoid DMA not-aligned issue.
+ * @rx_buf: Buffer used by SPI transfer to receive data from sensors.
+ * This buffer is used to avoid DMA not-aligned issue.
+ */
+struct st_sensor_transfer_buffer {
+ struct mutex buf_lock;
+ u8 rx_buf[ST_SENSORS_RX_MAX_LENGHT];
+ u8 tx_buf[ST_SENSORS_TX_MAX_LENGHT] ____cacheline_aligned;
+};
+
+/**
+ * struct st_sensor_transfer_function - ST sensor device I/O function
+ * @read_byte: Function used to read one byte.
+ * @write_byte: Function used to write one byte.
+ * @read_multiple_byte: Function used to read multiple byte.
+ */
+struct st_sensor_transfer_function {
+ int (*read_byte) (struct st_sensor_transfer_buffer *tb,
+ struct device *dev, u8 reg_addr, u8 *res_byte);
+ int (*write_byte) (struct st_sensor_transfer_buffer *tb,
+ struct device *dev, u8 reg_addr, u8 data);
+ int (*read_multiple_byte) (struct st_sensor_transfer_buffer *tb,
+ struct device *dev, u8 reg_addr, int len, u8 *data,
+ bool multiread_bit);
+};
+
+/**
+ * struct st_sensor_data - ST sensor device status
+ * @dev: Pointer to instance of struct device (I2C or SPI).
+ * @trig: The trigger in use by the core driver.
+ * @current_fullscale: Maximum range of measure by the sensor.
+ * @enabled: Status of the sensor (false->off, true->on).
+ * @multiread_bit: Use or not particular bit for [I2C/SPI] multiread.
+ * @index: Number used to point the sensor being used in the st_sensors struct.
+ * @buffer_data: Data used by buffer part.
+ * @odr: Output data rate of the sensor [Hz].
+ * @get_irq_data_ready: Function to get the IRQ used for data ready signal.
+ * @tf: Transfer function structure used by I/O operations.
+ * @tb: Transfer buffers and mutex used by I/O operations.
+ */
+struct st_sensor_data {
+ struct device *dev;
+ struct iio_trigger *trig;
+ struct st_sensor_fullscale_avl *current_fullscale;
+
+ bool enabled;
+ bool multiread_bit;
+
+ short index;
+
+ char *buffer_data;
+
+ unsigned int odr;
+
+ unsigned int (*get_irq_data_ready) (struct iio_dev *indio_dev);
+
+ struct st_sensor_transfer_function *tf;
+ struct st_sensor_transfer_buffer tb;
+};
+
+/**
+ * struct st_sensors - ST sensors list
+ * @wai: Contents of WhoAmI register.
+ * @ch: IIO channels for the sensor.
+ * @odr: Output data rate register and ODR list available.
+ * @pw: Power register of the sensor.
+ * @enable_axis: Enable one or more axis of the sensor.
+ * @fs: Full scale register and full scale list available.
+ * @bdu: Block data update register.
+ * @drdy_irq: Data ready register of the sensor.
+ * @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read.
+ * @bootime: samples to discard when sensor passing from power-down to power-up.
+ */
+struct st_sensors {
+ u8 wai;
+ char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
+ struct iio_chan_spec *ch;
+ struct st_sensor_odr odr;
+ struct st_sensor_power pw;
+ struct st_sensor_axis enable_axis;
+ struct st_sensor_fullscale fs;
+ struct st_sensor_bdu bdu;
+ struct st_sensor_data_ready_irq drdy_irq;
+ bool multi_read_bit;
+ unsigned int bootime;
+};
+
+#ifdef CONFIG_IIO_ST_SENSORS_SPI
+void st_sensors_spi_configure(struct iio_dev *indio_dev,
+ struct spi_device *spi, struct st_sensor_data *sdata);
+
+unsigned int st_sensors_spi_get_irq(struct iio_dev *indio_dev);
+#endif
+
+#ifdef CONFIG_IIO_ST_SENSORS_I2C
+void st_sensors_i2c_configure(struct iio_dev *indio_dev,
+ struct i2c_client *client, struct st_sensor_data *sdata);
+
+unsigned int st_sensors_i2c_get_irq(struct iio_dev *indio_dev);
+#endif
+
+#ifdef CONFIG_IIO_ST_SENSORS_TRIGGERED_BUFFER
+int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
+ int (*set_trigger_state)(struct iio_trigger *trig, bool state),
+ int (*try_reenable)(struct iio_trigger *trig));
+
+void st_sensors_deallocate_trigger(struct iio_dev *indio_dev);
+
+irqreturn_t st_sensors_trigger_handler(int irq, void *p);
+
+int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf);
+#endif
+
+int st_sensors_init_sensor(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor);
+
+int st_sensors_set_enable(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, bool enable);
+
+int st_sensors_set_axis_enable(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, u8 axis_enable);
+
+int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, u8 reg_addr,
+ u8 mask, short num_bit, u8 data);
+
+int st_sensors_get_sampling_frequency_avl(struct iio_dev *indio_dev,
+ const struct st_sensor_odr_avl *odr_avl, char *buf);
+
+int st_sensors_get_scale_avl(struct iio_dev *indio_dev,
+ const struct st_sensor_fullscale_avl *fullscale_avl, char *buf);
+
+int st_sensors_set_fullscale(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, unsigned int fs);
+
+int st_sensors_set_odr(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, unsigned int odr);
+
+int st_sensors_set_dataready_irq(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, bool enable);
+
+int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev,
+ const struct st_sensors *sensor, int scale);
+
+int st_sensors_read_axis_data(struct iio_dev *indio_dev, u8 ch_addr, int *data);
+
+#endif /* ST_SENSORS_H */
--
1.7.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 2/9] iio:accel: Add STMicroelectronics accelerometers driver
2013-01-15 8:30 iio: STMicroelectronics iio drivers Denis CIOCCA
2013-01-15 8:30 ` [PATCH 1/9] iio:common: Add STMicroelectronics common library Denis CIOCCA
@ 2013-01-15 8:30 ` Denis CIOCCA
2013-01-16 14:28 ` Lars-Peter Clausen
2013-01-15 8:30 ` [PATCH 3/9] iio:gyro: Add STMicroelectronics gyroscopes driver Denis CIOCCA
` (2 subsequent siblings)
4 siblings, 1 reply; 20+ messages in thread
From: Denis CIOCCA @ 2013-01-15 8:30 UTC (permalink / raw)
To: jic23, lars, linux-iio; +Cc: Denis Ciocca
This patch adds generic accelerometer driver for STMicroelectronics
accelerometers, currently it supports:
LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC,
LIS331DLH, LSM303DL, LSM303DLM, LSM330.
Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
drivers/iio/accel/Kconfig | 41 +++
drivers/iio/accel/Makefile | 6 +
drivers/iio/accel/st_accel_buffer.c | 119 +++++++
drivers/iio/accel/st_accel_core.c | 652 +++++++++++++++++++++++++++++++++++
drivers/iio/accel/st_accel_i2c.c | 87 +++++
drivers/iio/accel/st_accel_spi.c | 86 +++++
include/linux/iio/accel/st_accel.h | 52 +++
7 files changed, 1043 insertions(+), 0 deletions(-)
create mode 100644 drivers/iio/accel/st_accel_buffer.c
create mode 100644 drivers/iio/accel/st_accel_core.c
create mode 100644 drivers/iio/accel/st_accel_i2c.c
create mode 100644 drivers/iio/accel/st_accel_spi.c
create mode 100644 include/linux/iio/accel/st_accel.h
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 05e996f..ab67379 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -14,4 +14,45 @@ config HID_SENSOR_ACCEL_3D
Say yes here to build support for the HID SENSOR
accelerometers 3D.
+config IIO_ST_ACCEL_3AXIS
+ tristate "STMicroelectronics accelerometers 3-Axis Driver"
+ depends on (I2C || SPI_MASTER) && SYSFS
+ select IIO_ST_SENSORS_CORE
+ help
+ Say yes here to build support for STMicroelectronics accelerometers:
+ LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC,
+ LIS331DLH, LSM303DL, LSM303DLM, LSM330.
+
+ This driver can also be built as a module. If so, the module
+ will be called st_accel.
+
+config IIO_ST_ACCEL_3AXIS_I2C
+ tristate "support I2C bus connection"
+ depends on IIO_ST_ACCEL_3AXIS && I2C
+ select IIO_ST_SENSORS_I2C
+ help
+ Say yes here to build I2C support for STMicroelectronics accelerometers.
+
+ To compile this driver as a module, choose M here: the
+ module will be called st_accel_i2c.
+
+config IIO_ST_ACCEL_3AXIS_SPI
+ tristate "support SPI bus connection"
+ depends on IIO_ST_ACCEL_3AXIS && SPI_MASTER
+ select IIO_ST_SENSORS_SPI
+ help
+ Say yes here to build SPI support for STMicroelectronics accelerometers.
+
+ To compile this driver as a module, choose M here: the
+ module will be called st_accel_spi.
+
+config IIO_ST_ACCEL_3AXIS_TRIGGERED_BUFFER
+ tristate "support triggered buffer"
+ depends on IIO_ST_ACCEL_3AXIS
+ select IIO_TRIGGERED_BUFFER
+ select IIO_BUFFER
+ select IIO_ST_SENSORS_TRIGGERED_BUFFER
+ help
+ Default trigger and buffer for STMicroelectronics accelerometers driver.
+
endmenu
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 5bc6855..bb1fa7e 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -3,3 +3,9 @@
#
obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
+
+st_accel-y := st_accel_core.o
+obj-$(CONFIG_IIO_ST_ACCEL_3AXIS_I2C) += st_accel_i2c.o
+obj-$(CONFIG_IIO_ST_ACCEL_3AXIS_SPI) += st_accel_spi.o
+obj-$(CONFIG_IIO_ST_ACCEL_3AXIS_TRIGGERED_BUFFER) += st_accel_buffer.o
+obj-$(CONFIG_IIO_ST_ACCEL_3AXIS) += st_accel.o
diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
new file mode 100644
index 0000000..4764d21
--- /dev/null
+++ b/drivers/iio/accel/st_accel_buffer.c
@@ -0,0 +1,119 @@
+/*
+ * STMicroelectronics accelerometers driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/stat.h>
+#include <linux/interrupt.h>
+#include <linux/byteorder/generic.h>
+#include <linux/i2c.h>
+#include <linux/delay.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+
+#include <linux/iio/accel/st_accel.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+int st_accel_trig_set_state(struct iio_trigger *trig, bool state)
+{
+ struct iio_dev *indio_dev = trig->private_data;
+ return st_accel_set_dataready_irq(indio_dev, state);
+}
+EXPORT_SYMBOL(st_accel_trig_set_state);
+
+static int st_accel_buffer_preenable(struct iio_dev *indio_dev)
+{
+ int err;
+
+ err = st_accel_set_enable(indio_dev, true);
+ if (err < 0)
+ goto st_accel_set_enable_error;
+
+ err = iio_sw_buffer_preenable(indio_dev);
+
+st_accel_set_enable_error:
+ return err;
+}
+
+static int st_accel_buffer_postenable(struct iio_dev *indio_dev)
+{
+ int err;
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ adata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
+ if (adata->buffer_data == NULL) {
+ err = -ENOMEM;
+ goto allocate_memory_error;
+ }
+
+ err = st_accel_set_axis_enable(indio_dev,
+ (u8)indio_dev->active_scan_mask[0]);
+ if (err < 0)
+ goto st_accel_buffer_postenable_error;
+
+ err = iio_triggered_buffer_postenable(indio_dev);
+ if (err < 0)
+ goto st_accel_buffer_postenable_error;
+
+ return err;
+
+st_accel_buffer_postenable_error:
+ kfree(adata->buffer_data);
+allocate_memory_error:
+ return err;
+}
+
+static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
+{
+ int err;
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ err = iio_triggered_buffer_predisable(indio_dev);
+ if (err < 0)
+ goto st_accel_buffer_predisable_error;
+
+ err = st_accel_set_axis_enable(indio_dev,
+ ST_SENSORS_ENABLE_ALL_CHANNELS);
+ if (err < 0)
+ goto st_accel_buffer_predisable_error;
+
+ err = st_accel_set_enable(indio_dev, false);
+
+st_accel_buffer_predisable_error:
+ kfree(adata->buffer_data);
+ return err;
+}
+
+static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = {
+ .preenable = &st_accel_buffer_preenable,
+ .postenable = &st_accel_buffer_postenable,
+ .predisable = &st_accel_buffer_predisable,
+};
+
+int st_accel_allocate_ring(struct iio_dev *indio_dev)
+{
+ return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+ &st_sensors_trigger_handler, &st_accel_buffer_setup_ops);
+}
+EXPORT_SYMBOL(st_accel_allocate_ring);
+
+void st_accel_deallocate_ring(struct iio_dev *indio_dev)
+{
+ iio_triggered_buffer_cleanup(indio_dev);
+}
+EXPORT_SYMBOL(st_accel_deallocate_ring);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics accelerometers buffer");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
new file mode 100644
index 0000000..4e7108a
--- /dev/null
+++ b/drivers/iio/accel/st_accel_core.c
@@ -0,0 +1,652 @@
+/*
+ * STMicroelectronics accelerometers driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/mutex.h>
+#include <linux/interrupt.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/irq.h>
+#include <linux/delay.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/buffer.h>
+
+#include <linux/iio/accel/st_accel.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+/* DEFAULT VALUE FOR SENSORS */
+#define ST_ACCEL_DEFAULT_OUT_X_L_ADDR 0x28
+#define ST_ACCEL_DEFAULT_OUT_Y_L_ADDR 0x2a
+#define ST_ACCEL_DEFAULT_OUT_Z_L_ADDR 0x2c
+
+/* FULLSCALE */
+#define ST_ACCEL_FS_AVL_2G 2
+#define ST_ACCEL_FS_AVL_4G 4
+#define ST_ACCEL_FS_AVL_6G 6
+#define ST_ACCEL_FS_AVL_8G 8
+#define ST_ACCEL_FS_AVL_16G 16
+
+/* CUSTOM VALUES FOR SENSOR 1 */
+#define ST_ACCEL_1_WAI_EXP 0x33
+#define ST_ACCEL_1_ODR_ADDR 0x20
+#define ST_ACCEL_1_ODR_MASK 0xf0
+#define ST_ACCEL_1_ODR_N_BIT 4
+#define ST_ACCEL_1_ODR_AVL_1HZ_VAL 0x01
+#define ST_ACCEL_1_ODR_AVL_10HZ_VAL 0x02
+#define ST_ACCEL_1_ODR_AVL_25HZ_VAL 0x03
+#define ST_ACCEL_1_ODR_AVL_50HZ_VAL 0x04
+#define ST_ACCEL_1_ODR_AVL_100HZ_VAL 0x05
+#define ST_ACCEL_1_ODR_AVL_200HZ_VAL 0x06
+#define ST_ACCEL_1_ODR_AVL_400HZ_VAL 0x07
+#define ST_ACCEL_1_ODR_AVL_1600HZ_VAL 0x08
+#define ST_ACCEL_1_FS_N_BIT 2
+#define ST_ACCEL_1_FS_ADDR 0x23
+#define ST_ACCEL_1_FS_MASK 0x30
+#define ST_ACCEL_1_FS_AVL_2_VAL 0x00
+#define ST_ACCEL_1_FS_AVL_4_VAL 0x01
+#define ST_ACCEL_1_FS_AVL_8_VAL 0x02
+#define ST_ACCEL_1_FS_AVL_16_VAL 0x03
+#define ST_ACCEL_1_FS_AVL_2_GAIN IIO_G_TO_M_S_2(1000)
+#define ST_ACCEL_1_FS_AVL_4_GAIN IIO_G_TO_M_S_2(2000)
+#define ST_ACCEL_1_FS_AVL_8_GAIN IIO_G_TO_M_S_2(4000)
+#define ST_ACCEL_1_FS_AVL_16_GAIN IIO_G_TO_M_S_2(12000)
+#define ST_ACCEL_1_BDU_ADDR 0x23
+#define ST_ACCEL_1_BDU_MASK 0x80
+#define ST_ACCEL_1_DRDY_IRQ_ADDR 0x22
+#define ST_ACCEL_1_DRDY_IRQ_MASK 0x10
+#define ST_ACCEL_1_MULTIREAD_BIT true
+
+/* CUSTOM VALUES FOR SENSOR 2 */
+#define ST_ACCEL_2_WAI_EXP 0x32
+#define ST_ACCEL_2_ODR_ADDR 0x20
+#define ST_ACCEL_2_ODR_MASK 0x18
+#define ST_ACCEL_2_ODR_N_BIT 2
+#define ST_ACCEL_2_ODR_AVL_50HZ_VAL 0x00
+#define ST_ACCEL_2_ODR_AVL_100HZ_VAL 0x01
+#define ST_ACCEL_2_ODR_AVL_400HZ_VAL 0x02
+#define ST_ACCEL_2_ODR_AVL_1000HZ_VAL 0x03
+#define ST_ACCEL_2_PW_ADDR 0x20
+#define ST_ACCEL_2_PW_MASK 0xe0
+#define ST_ACCEL_2_PW_N_BIT 3
+#define ST_ACCEL_2_FS_N_BIT 2
+#define ST_ACCEL_2_FS_ADDR 0x23
+#define ST_ACCEL_2_FS_MASK 0x30
+#define ST_ACCEL_2_FS_AVL_2_VAL 0X00
+#define ST_ACCEL_2_FS_AVL_4_VAL 0X01
+#define ST_ACCEL_2_FS_AVL_8_VAL 0x03
+#define ST_ACCEL_2_FS_AVL_2_GAIN IIO_G_TO_M_S_2(1000)
+#define ST_ACCEL_2_FS_AVL_4_GAIN IIO_G_TO_M_S_2(2000)
+#define ST_ACCEL_2_FS_AVL_8_GAIN IIO_G_TO_M_S_2(3900)
+#define ST_ACCEL_2_BDU_ADDR 0x23
+#define ST_ACCEL_2_BDU_MASK 0x80
+#define ST_ACCEL_2_DRDY_IRQ_ADDR 0x22
+#define ST_ACCEL_2_DRDY_IRQ_MASK 0x02
+#define ST_ACCEL_2_MULTIREAD_BIT true
+
+/* CUSTOM VALUES FOR SENSOR 3 */
+#define ST_ACCEL_3_WAI_EXP 0x40
+#define ST_ACCEL_3_ODR_ADDR 0x20
+#define ST_ACCEL_3_ODR_MASK 0xf0
+#define ST_ACCEL_3_ODR_N_BIT 4
+#define ST_ACCEL_3_ODR_AVL_3HZ_VAL 0x01
+#define ST_ACCEL_3_ODR_AVL_6HZ_VAL 0x02
+#define ST_ACCEL_3_ODR_AVL_12HZ_VAL 0x03
+#define ST_ACCEL_3_ODR_AVL_25HZ_VAL 0x04
+#define ST_ACCEL_3_ODR_AVL_50HZ_VAL 0x05
+#define ST_ACCEL_3_ODR_AVL_100HZ_VAL 0x06
+#define ST_ACCEL_3_ODR_AVL_200HZ_VAL 0x07
+#define ST_ACCEL_3_ODR_AVL_400HZ_VAL 0x08
+#define ST_ACCEL_3_ODR_AVL_800HZ_VAL 0x09
+#define ST_ACCEL_3_ODR_AVL_1600HZ_VAL 0x0a
+#define ST_ACCEL_3_FS_N_BIT 3
+#define ST_ACCEL_3_FS_ADDR 0x24
+#define ST_ACCEL_3_FS_MASK 0x38
+#define ST_ACCEL_3_FS_AVL_2_VAL 0X00
+#define ST_ACCEL_3_FS_AVL_4_VAL 0X01
+#define ST_ACCEL_3_FS_AVL_6_VAL 0x02
+#define ST_ACCEL_3_FS_AVL_8_VAL 0x03
+#define ST_ACCEL_3_FS_AVL_16_VAL 0x04
+#define ST_ACCEL_3_FS_AVL_2_GAIN IIO_G_TO_M_S_2(61)
+#define ST_ACCEL_3_FS_AVL_4_GAIN IIO_G_TO_M_S_2(122)
+#define ST_ACCEL_3_FS_AVL_6_GAIN IIO_G_TO_M_S_2(183)
+#define ST_ACCEL_3_FS_AVL_8_GAIN IIO_G_TO_M_S_2(244)
+#define ST_ACCEL_3_FS_AVL_16_GAIN IIO_G_TO_M_S_2(732)
+#define ST_ACCEL_3_BDU_ADDR 0x20
+#define ST_ACCEL_3_BDU_MASK 0x08
+#define ST_ACCEL_3_DRDY_IRQ_ADDR 0x23
+#define ST_ACCEL_3_DRDY_IRQ_MASK 0x80
+#define ST_ACCEL_3_IG1_EN_ADDR 0x23
+#define ST_ACCEL_3_IG1_EN_MASK 0x08
+#define ST_ACCEL_3_MULTIREAD_BIT false
+
+static const struct iio_chan_spec st_accel_12bit_channels[] = {
+ ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE,
+ ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_X_L_ADDR),
+ ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE,
+ ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_Y_L_ADDR),
+ ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE,
+ ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_Z_L_ADDR),
+ IIO_CHAN_SOFT_TIMESTAMP(3)
+};
+
+static const struct iio_chan_spec st_accel_16bit_channels[] = {
+ ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE,
+ ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_X_L_ADDR),
+ ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE,
+ ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_Y_L_ADDR),
+ ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE,
+ ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_Z_L_ADDR),
+ IIO_CHAN_SOFT_TIMESTAMP(3)
+};
+
+static const struct st_sensors st_accel_sensors[] = {
+ {
+ .wai = ST_ACCEL_1_WAI_EXP,
+ .sensors_supported = {
+ [0] = LIS3DH_ACCEL_DEV_NAME,
+ [1] = LSM303DLH_ACCEL_DEV_NAME,
+ [2] = LSM303DLHC_ACCEL_DEV_NAME,
+ [3] = LSM330D_ACCEL_DEV_NAME,
+ [4] = LSM330DL_ACCEL_DEV_NAME,
+ [5] = LSM330DLC_ACCEL_DEV_NAME,
+ },
+ .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
+ .odr = {
+ .addr = ST_ACCEL_1_ODR_ADDR,
+ .mask = ST_ACCEL_1_ODR_MASK,
+ .num_bit = ST_ACCEL_1_ODR_N_BIT,
+ .odr_avl = {
+ { 1, ST_ACCEL_1_ODR_AVL_1HZ_VAL, },
+ { 10, ST_ACCEL_1_ODR_AVL_10HZ_VAL, },
+ { 25, ST_ACCEL_1_ODR_AVL_25HZ_VAL, },
+ { 50, ST_ACCEL_1_ODR_AVL_50HZ_VAL, },
+ { 100, ST_ACCEL_1_ODR_AVL_100HZ_VAL, },
+ { 200, ST_ACCEL_1_ODR_AVL_200HZ_VAL, },
+ { 400, ST_ACCEL_1_ODR_AVL_400HZ_VAL, },
+ { 1600, ST_ACCEL_1_ODR_AVL_1600HZ_VAL, },
+ },
+ },
+ .pw = {
+ .addr = ST_ACCEL_1_ODR_ADDR,
+ .mask = ST_ACCEL_1_ODR_MASK,
+ .num_bit = ST_ACCEL_1_ODR_N_BIT,
+ .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
+ },
+ .enable_axis = {
+ .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
+ .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
+ },
+ .fs = {
+ .addr = ST_ACCEL_1_FS_ADDR,
+ .mask = ST_ACCEL_1_FS_MASK,
+ .num_bit = ST_ACCEL_1_FS_N_BIT,
+ .fs_avl = {
+ [0] = {
+ .num = ST_ACCEL_FS_AVL_2G,
+ .value = ST_ACCEL_1_FS_AVL_2_VAL,
+ .gain = ST_ACCEL_1_FS_AVL_2_GAIN,
+ },
+ [1] = {
+ .num = ST_ACCEL_FS_AVL_4G,
+ .value = ST_ACCEL_1_FS_AVL_4_VAL,
+ .gain = ST_ACCEL_1_FS_AVL_4_GAIN,
+ },
+ [2] = {
+ .num = ST_ACCEL_FS_AVL_8G,
+ .value = ST_ACCEL_1_FS_AVL_8_VAL,
+ .gain = ST_ACCEL_1_FS_AVL_8_GAIN,
+ },
+ [3] = {
+ .num = ST_ACCEL_FS_AVL_16G,
+ .value = ST_ACCEL_1_FS_AVL_16_VAL,
+ .gain = ST_ACCEL_1_FS_AVL_16_GAIN,
+ },
+ },
+ },
+ .bdu = {
+ .addr = ST_ACCEL_1_BDU_ADDR,
+ .mask = ST_ACCEL_1_BDU_MASK,
+ },
+ .drdy_irq = {
+ .addr = ST_ACCEL_1_DRDY_IRQ_ADDR,
+ .mask = ST_ACCEL_1_DRDY_IRQ_MASK,
+ },
+ .multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT,
+ .bootime = 2,
+ },
+ {
+ .wai = ST_ACCEL_2_WAI_EXP,
+ .sensors_supported = {
+ [0] = LIS331DLH_ACCEL_DEV_NAME,
+ [1] = LSM303DL_ACCEL_DEV_NAME,
+ [2] = LSM303DLM_ACCEL_DEV_NAME,
+ },
+ .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
+ .odr = {
+ .addr = ST_ACCEL_2_ODR_ADDR,
+ .mask = ST_ACCEL_2_ODR_MASK,
+ .num_bit = ST_ACCEL_2_ODR_N_BIT,
+ .odr_avl = {
+ { 50, ST_ACCEL_2_ODR_AVL_50HZ_VAL, },
+ { 100, ST_ACCEL_2_ODR_AVL_100HZ_VAL, },
+ { 400, ST_ACCEL_2_ODR_AVL_400HZ_VAL, },
+ { 1000, ST_ACCEL_2_ODR_AVL_1000HZ_VAL, },
+ },
+ },
+ .pw = {
+ .addr = ST_ACCEL_2_PW_ADDR,
+ .mask = ST_ACCEL_2_PW_MASK,
+ .num_bit = ST_ACCEL_2_PW_N_BIT,
+ .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
+ .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
+ },
+ .enable_axis = {
+ .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
+ .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
+ },
+ .fs = {
+ .addr = ST_ACCEL_2_FS_ADDR,
+ .mask = ST_ACCEL_2_FS_MASK,
+ .num_bit = ST_ACCEL_2_FS_N_BIT,
+ .fs_avl = {
+ [0] = {
+ .num = ST_ACCEL_FS_AVL_2G,
+ .value = ST_ACCEL_2_FS_AVL_2_VAL,
+ .gain = ST_ACCEL_2_FS_AVL_2_GAIN,
+ },
+ [1] = {
+ .num = ST_ACCEL_FS_AVL_4G,
+ .value = ST_ACCEL_2_FS_AVL_4_VAL,
+ .gain = ST_ACCEL_2_FS_AVL_4_GAIN,
+ },
+ [2] = {
+ .num = ST_ACCEL_FS_AVL_8G,
+ .value = ST_ACCEL_2_FS_AVL_8_VAL,
+ .gain = ST_ACCEL_2_FS_AVL_8_GAIN,
+ },
+ },
+ },
+ .bdu = {
+ .addr = ST_ACCEL_2_BDU_ADDR,
+ .mask = ST_ACCEL_2_BDU_MASK,
+ },
+ .drdy_irq = {
+ .addr = ST_ACCEL_2_DRDY_IRQ_ADDR,
+ .mask = ST_ACCEL_2_DRDY_IRQ_MASK,
+ },
+ .multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT,
+ .bootime = 2,
+ },
+ {
+ .wai = ST_ACCEL_3_WAI_EXP,
+ .sensors_supported = {
+ [0] = LSM330_ACCEL_DEV_NAME,
+ },
+ .ch = (struct iio_chan_spec *)st_accel_16bit_channels,
+ .odr = {
+ .addr = ST_ACCEL_3_ODR_ADDR,
+ .mask = ST_ACCEL_3_ODR_MASK,
+ .num_bit = ST_ACCEL_3_ODR_N_BIT,
+ .odr_avl = {
+ { 3, ST_ACCEL_3_ODR_AVL_3HZ_VAL },
+ { 6, ST_ACCEL_3_ODR_AVL_6HZ_VAL, },
+ { 12, ST_ACCEL_3_ODR_AVL_12HZ_VAL, },
+ { 25, ST_ACCEL_3_ODR_AVL_25HZ_VAL, },
+ { 50, ST_ACCEL_3_ODR_AVL_50HZ_VAL, },
+ { 100, ST_ACCEL_3_ODR_AVL_100HZ_VAL, },
+ { 200, ST_ACCEL_3_ODR_AVL_200HZ_VAL, },
+ { 400, ST_ACCEL_3_ODR_AVL_400HZ_VAL, },
+ { 800, ST_ACCEL_3_ODR_AVL_800HZ_VAL, },
+ { 1600, ST_ACCEL_3_ODR_AVL_1600HZ_VAL, },
+ },
+ },
+ .pw = {
+ .addr = ST_ACCEL_3_ODR_ADDR,
+ .mask = ST_ACCEL_3_ODR_MASK,
+ .num_bit = ST_ACCEL_3_ODR_N_BIT,
+ .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
+ },
+ .enable_axis = {
+ .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
+ .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
+ },
+ .fs = {
+ .addr = ST_ACCEL_3_FS_ADDR,
+ .mask = ST_ACCEL_3_FS_MASK,
+ .num_bit = ST_ACCEL_3_FS_N_BIT,
+ .fs_avl = {
+ [0] = {
+ .num = ST_ACCEL_FS_AVL_2G,
+ .value = ST_ACCEL_3_FS_AVL_2_VAL,
+ .gain = ST_ACCEL_3_FS_AVL_2_GAIN,
+ },
+ [1] = {
+ .num = ST_ACCEL_FS_AVL_4G,
+ .value = ST_ACCEL_3_FS_AVL_4_VAL,
+ .gain = ST_ACCEL_3_FS_AVL_4_GAIN,
+ },
+ [2] = {
+ .num = ST_ACCEL_FS_AVL_6G,
+ .value = ST_ACCEL_3_FS_AVL_6_VAL,
+ .gain = ST_ACCEL_3_FS_AVL_6_GAIN,
+ },
+ [3] = {
+ .num = ST_ACCEL_FS_AVL_8G,
+ .value = ST_ACCEL_3_FS_AVL_8_VAL,
+ .gain = ST_ACCEL_3_FS_AVL_8_GAIN,
+ },
+ [4] = {
+ .num = ST_ACCEL_FS_AVL_16G,
+ .value = ST_ACCEL_3_FS_AVL_16_VAL,
+ .gain = ST_ACCEL_3_FS_AVL_16_GAIN,
+ },
+ },
+ },
+ .bdu = {
+ .addr = ST_ACCEL_3_BDU_ADDR,
+ .mask = ST_ACCEL_3_BDU_MASK,
+ },
+ .drdy_irq = {
+ .addr = ST_ACCEL_3_DRDY_IRQ_ADDR,
+ .mask = ST_ACCEL_3_DRDY_IRQ_MASK,
+ .ig1 = {
+ .en_addr = ST_ACCEL_3_IG1_EN_ADDR,
+ .en_mask = ST_ACCEL_3_IG1_EN_MASK,
+ },
+ },
+ .multi_read_bit = ST_ACCEL_3_MULTIREAD_BIT,
+ .bootime = 2,
+ },
+};
+
+static int st_accel_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *ch, int *val,
+ int *val2, long mask)
+{
+ int err;
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW:
+ mutex_lock(&indio_dev->mlock);
+ if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
+ err = -EBUSY;
+ goto read_error;
+ } else {
+ err = st_sensors_set_enable(indio_dev,
+ &st_accel_sensors[adata->index], true);
+ if (err < 0)
+ goto read_error;
+
+ msleep((st_accel_sensors[adata->index].bootime * 1000)
+ / adata->odr);
+ err = st_sensors_read_axis_data(indio_dev,
+ ch->address, val);
+ if (err < 0)
+ goto read_error;
+
+ *val = *val >> ch->scan_type.shift;
+ }
+ mutex_unlock(&indio_dev->mlock);
+ return IIO_VAL_INT;
+ case IIO_CHAN_INFO_SCALE:
+ *val = 0;
+ *val2 = adata->current_fullscale->gain;
+ return IIO_VAL_INT_PLUS_MICRO;
+ default:
+ return -EINVAL;
+ }
+
+read_error:
+ mutex_unlock(&indio_dev->mlock);
+ return err;
+}
+
+static int st_accel_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan, int val, int val2, long mask)
+{
+ int err;
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ switch (mask) {
+ case IIO_CHAN_INFO_SCALE:
+ err = st_sensors_set_fullscale_by_gain(indio_dev,
+ &st_accel_sensors[adata->index], val2);
+ break;
+ default:
+ err = -EINVAL;
+ }
+
+ return err;
+}
+
+int st_accel_set_dataready_irq(struct iio_dev *indio_dev, bool state)
+{
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ return st_sensors_set_dataready_irq(indio_dev,
+ &st_accel_sensors[adata->index], state);
+}
+EXPORT_SYMBOL(st_accel_set_dataready_irq);
+
+int st_accel_set_axis_enable(struct iio_dev *indio_dev, u8 active_bit)
+{
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ return st_sensors_set_axis_enable(indio_dev,
+ &st_accel_sensors[adata->index], active_bit);
+}
+EXPORT_SYMBOL(st_accel_set_axis_enable);
+
+static int st_accel_check_device_support(struct iio_dev *indio_dev)
+{
+ int i, n, err;
+ u8 wai;
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ err = adata->tf->read_byte(&adata->tb, adata->dev,
+ ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai);
+ if (err < 0) {
+ dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
+ goto read_wai_error;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(st_accel_sensors); i++) {
+ if (st_accel_sensors[i].wai == wai)
+ break;
+ }
+ if (i == ARRAY_SIZE(st_accel_sensors))
+ goto device_not_supported;
+
+ for (n = 0; n < ARRAY_SIZE(st_accel_sensors[i].sensors_supported);
+ n++) {
+ if (strcmp(indio_dev->name,
+ &st_accel_sensors[i].sensors_supported[n][0]) == 0)
+ break;
+ }
+ if (n == ARRAY_SIZE(st_accel_sensors[i].sensors_supported)) {
+ dev_err(&indio_dev->dev, "device name and WhoAmI mismatch.\n");
+ goto sensor_name_mismatch;
+ }
+
+ adata->index = i;
+
+ return i;
+
+device_not_supported:
+ dev_err(&indio_dev->dev, "device not supported: WhoAmI (0x%x).\n", wai);
+sensor_name_mismatch:
+ err = -ENODEV;
+read_wai_error:
+ return err;
+}
+
+int st_accel_set_enable(struct iio_dev *indio_dev, bool enable)
+{
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ return st_sensors_set_enable(indio_dev,
+ &st_accel_sensors[adata->index], enable);
+}
+EXPORT_SYMBOL(st_accel_set_enable);
+
+static ssize_t st_accel_sysfs_set_sampling_frequency(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ int err;
+ unsigned int odr;
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ err = kstrtoint(buf, 10, &odr);
+ if (err < 0)
+ goto conversion_error;
+
+ mutex_lock(&indio_dev->mlock);
+ err = st_sensors_set_odr(indio_dev,
+ &st_accel_sensors[adata->index], odr);
+ mutex_unlock(&indio_dev->mlock);
+
+conversion_error:
+ return err < 0 ? err : size;
+}
+
+static ssize_t st_accel_sysfs_get_sampling_frequency(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ return sprintf(buf, "%d\n", adata->odr);
+}
+
+static ssize_t st_accel_sysfs_scale_avail(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ return st_sensors_get_scale_avl(indio_dev,
+ st_accel_sensors[adata->index].fs.fs_avl, buf);
+}
+
+static ssize_t st_accel_sysfs_sampling_frequency_avail(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ return st_sensors_get_sampling_frequency_avl(indio_dev,
+ st_accel_sensors[adata->index].odr.odr_avl, buf);
+}
+
+static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(st_accel_sysfs_sampling_frequency_avail);
+
+static IIO_DEVICE_ATTR(in_accel_scale_available, S_IRUGO,
+ st_accel_sysfs_scale_avail, NULL , 0);
+
+static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
+ st_accel_sysfs_get_sampling_frequency,
+ st_accel_sysfs_set_sampling_frequency);
+
+static struct attribute *st_accel_attributes[] = {
+ &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
+ &iio_dev_attr_in_accel_scale_available.dev_attr.attr,
+ &iio_dev_attr_sampling_frequency.dev_attr.attr,
+ NULL,
+};
+
+static const struct attribute_group st_accel_attribute_group = {
+ .attrs = st_accel_attributes,
+};
+
+static const struct iio_info accel_info = {
+ .driver_module = THIS_MODULE,
+ .attrs = &st_accel_attribute_group,
+ .read_raw = &st_accel_read_raw,
+ .write_raw = &st_accel_write_raw,
+};
+
+int st_accel_common_probe(struct iio_dev *indio_dev)
+{
+ int err;
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->info = &accel_info;
+
+ err = st_accel_check_device_support(indio_dev);
+ if (err < 0)
+ goto st_accel_common_probe_error;
+
+ adata->multiread_bit = st_accel_sensors[adata->index].multi_read_bit;
+ indio_dev->channels = st_accel_sensors[adata->index].ch;
+ indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
+
+ adata->current_fullscale = (struct st_sensor_fullscale_avl *)
+ &st_accel_sensors[adata->index].fs.fs_avl[0];
+ adata->odr = st_accel_sensors[adata->index].odr.odr_avl[0].hz;
+
+ err = st_sensors_init_sensor(indio_dev,
+ &st_accel_sensors[adata->index]);
+ if (err < 0)
+ goto st_accel_common_probe_error;
+
+ if (adata->get_irq_data_ready(indio_dev) > 0) {
+ err = st_accel_allocate_ring(indio_dev);
+ if (err < 0)
+ goto st_accel_common_probe_error;
+
+ err = st_sensors_allocate_trigger(indio_dev,
+ &st_accel_trig_set_state, NULL);
+ if (err < 0)
+ goto st_accel_probe_trigger_error;
+ }
+
+ err = iio_device_register(indio_dev);
+ if (err)
+ goto st_accel_device_register_error;
+
+ return err;
+
+st_accel_device_register_error:
+ if (adata->get_irq_data_ready(indio_dev) > 0)
+ st_sensors_deallocate_trigger(indio_dev);
+st_accel_probe_trigger_error:
+ if (adata->get_irq_data_ready(indio_dev) > 0)
+ st_accel_deallocate_ring(indio_dev);
+st_accel_common_probe_error:
+ return err;
+}
+EXPORT_SYMBOL(st_accel_common_probe);
+
+void st_accel_common_remove(struct iio_dev *indio_dev)
+{
+ struct st_sensor_data *adata = iio_priv(indio_dev);
+
+ iio_device_unregister(indio_dev);
+ if (adata->get_irq_data_ready(indio_dev) > 0) {
+ st_sensors_deallocate_trigger(indio_dev);
+ st_accel_deallocate_ring(indio_dev);
+ }
+ iio_device_free(indio_dev);
+}
+EXPORT_SYMBOL(st_accel_common_remove);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics accelerometers driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
new file mode 100644
index 0000000..d1000e8
--- /dev/null
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -0,0 +1,87 @@
+/*
+ * STMicroelectronics accelerometers driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+
+#include <linux/iio/accel/st_accel.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+static int st_accel_i2c_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct iio_dev *indio_dev;
+ struct st_sensor_data *adata;
+ int err;
+
+ indio_dev = iio_device_alloc(sizeof(*adata));
+ if (indio_dev == NULL) {
+ err = -ENOMEM;
+ goto iio_device_alloc_error;
+ }
+
+ adata = iio_priv(indio_dev);
+ adata->dev = &client->dev;
+
+ st_sensors_i2c_configure(indio_dev, client, adata);
+
+ err = st_accel_common_probe(indio_dev);
+ if (err < 0)
+ goto st_accel_common_probe_error;
+
+ return 0;
+
+st_accel_common_probe_error:
+ iio_device_free(indio_dev);
+iio_device_alloc_error:
+ return err;
+}
+
+static int st_accel_i2c_remove(struct i2c_client *client)
+{
+ st_accel_common_remove(i2c_get_clientdata(client));
+
+ return 0;
+}
+
+static const struct i2c_device_id st_accel_id_table[] = {
+ { LSM303DLH_ACCEL_DEV_NAME },
+ { LSM303DLHC_ACCEL_DEV_NAME },
+ { LIS3DH_ACCEL_DEV_NAME },
+ { LSM330D_ACCEL_DEV_NAME },
+ { LSM330DL_ACCEL_DEV_NAME },
+ { LSM330DLC_ACCEL_DEV_NAME },
+ { LIS331DLH_ACCEL_DEV_NAME },
+ { LSM303DL_ACCEL_DEV_NAME },
+ { LSM303DLM_ACCEL_DEV_NAME },
+ { LSM330_ACCEL_DEV_NAME },
+ {},
+};
+MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
+
+static struct i2c_driver st_accel_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "st-accel-i2c",
+ },
+ .probe = st_accel_i2c_probe,
+ .remove = st_accel_i2c_remove,
+ .id_table = st_accel_id_table,
+};
+module_i2c_driver(st_accel_driver);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics accelerometers i2c driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
new file mode 100644
index 0000000..011cc58
--- /dev/null
+++ b/drivers/iio/accel/st_accel_spi.c
@@ -0,0 +1,86 @@
+/*
+ * STMicroelectronics accelerometers driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/spi/spi.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+
+#include <linux/iio/accel/st_accel.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+static int st_accel_spi_probe(struct spi_device *spi)
+{
+ struct iio_dev *indio_dev;
+ struct st_sensor_data *adata;
+ int err;
+
+ indio_dev = iio_device_alloc(sizeof(*adata));
+ if (indio_dev == NULL) {
+ err = -ENOMEM;
+ goto iio_device_alloc_error;
+ }
+
+ adata = iio_priv(indio_dev);
+ adata->dev = &spi->dev;
+
+ st_sensors_spi_configure(indio_dev, spi, adata);
+
+ err = st_accel_common_probe(indio_dev);
+ if (err < 0)
+ goto st_accel_common_probe_error;
+
+ return 0;
+
+st_accel_common_probe_error:
+ iio_device_free(indio_dev);
+iio_device_alloc_error:
+ return err;
+}
+
+static int st_accel_spi_remove(struct spi_device *spi)
+{
+ st_accel_common_remove(spi_get_drvdata(spi));
+
+ return 0;
+}
+
+static const struct spi_device_id st_accel_id_table[] = {
+ { LSM303DLH_ACCEL_DEV_NAME },
+ { LSM303DLHC_ACCEL_DEV_NAME },
+ { LIS3DH_ACCEL_DEV_NAME },
+ { LSM330D_ACCEL_DEV_NAME },
+ { LSM330DL_ACCEL_DEV_NAME },
+ { LSM330DLC_ACCEL_DEV_NAME },
+ { LIS331DLH_ACCEL_DEV_NAME },
+ { LSM303DL_ACCEL_DEV_NAME },
+ { LSM303DLM_ACCEL_DEV_NAME },
+ { LSM330_ACCEL_DEV_NAME },
+ {},
+};
+MODULE_DEVICE_TABLE(spi, st_accel_id_table);
+
+static struct spi_driver st_accel_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "st-accel-spi",
+ },
+ .probe = st_accel_spi_probe,
+ .remove = st_accel_spi_remove,
+ .id_table = st_accel_id_table,
+};
+module_spi_driver(st_accel_driver);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics accelerometers spi driver");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/iio/accel/st_accel.h b/include/linux/iio/accel/st_accel.h
new file mode 100644
index 0000000..5bcbecc
--- /dev/null
+++ b/include/linux/iio/accel/st_accel.h
@@ -0,0 +1,52 @@
+/*
+ * STMicroelectronics accelerometers driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ * v. 1.0.0
+ * Licensed under the GPL-2.
+ */
+
+#ifndef ST_ACCEL_H
+#define ST_ACCEL_H
+
+#include <linux/types.h>
+#include "../common/st_sensors.h"
+
+#define LSM303DLH_ACCEL_DEV_NAME "lsm303dlh_accel"
+#define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel"
+#define LIS3DH_ACCEL_DEV_NAME "lis3dh"
+#define LSM330D_ACCEL_DEV_NAME "lsm330d_accel"
+#define LSM330DL_ACCEL_DEV_NAME "lsm330dl_accel"
+#define LSM330DLC_ACCEL_DEV_NAME "lsm330dlc_accel"
+#define LIS331DLH_ACCEL_DEV_NAME "lis331dlh"
+#define LSM303DL_ACCEL_DEV_NAME "lsm303dl_accel"
+#define LSM303DLM_ACCEL_DEV_NAME "lsm303dlm_accel"
+#define LSM330_ACCEL_DEV_NAME "lsm330_accel"
+
+int st_accel_common_probe(struct iio_dev *indio_dev);
+void st_accel_common_remove(struct iio_dev *indio_dev);
+int st_accel_set_dataready_irq(struct iio_dev *indio_dev, bool state);
+int st_accel_set_axis_enable(struct iio_dev *indio_dev, u8 active_bit);
+int st_accel_set_enable(struct iio_dev *indio_dev, bool enable);
+
+#ifdef CONFIG_IIO_ST_ACCEL_3AXIS_TRIGGERED_BUFFER
+int st_accel_allocate_ring(struct iio_dev *indio_dev);
+void st_accel_deallocate_ring(struct iio_dev *indio_dev);
+int st_accel_trig_set_state(struct iio_trigger *trig, bool state);
+#else /* CONFIG_IIO_ST_ACCEL_3AXIS_TRIGGERED_BUFFER */
+static inline int st_accel_allocate_ring(struct iio_dev *indio_dev)
+{
+ return 0;
+}
+static inline void st_accel_deallocate_ring(struct iio_dev *indio_dev)
+{
+}
+static inline int st_accel_trig_set_state(struct iio_trigger *trig, bool state)
+{
+ return 0;
+}
+#endif /* CONFIG_IIO_ST_ACCEL_3AXIS_TRIGGERED_BUFFER */
+
+#endif /* ST_ACCEL_H */
--
1.7.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 3/9] iio:gyro: Add STMicroelectronics gyroscopes driver
2013-01-15 8:30 iio: STMicroelectronics iio drivers Denis CIOCCA
2013-01-15 8:30 ` [PATCH 1/9] iio:common: Add STMicroelectronics common library Denis CIOCCA
2013-01-15 8:30 ` [PATCH 2/9] iio:accel: Add STMicroelectronics accelerometers driver Denis CIOCCA
@ 2013-01-15 8:30 ` Denis CIOCCA
2013-01-15 8:31 ` [PATCH 4/9] iio:magnetometer: Add STMicroelectronics magnetometers driver Denis CIOCCA
2013-01-15 22:33 ` iio: STMicroelectronics iio drivers Jonathan Cameron
4 siblings, 0 replies; 20+ messages in thread
From: Denis CIOCCA @ 2013-01-15 8:30 UTC (permalink / raw)
To: jic23, lars, linux-iio; +Cc: Denis Ciocca
This patch adds generic gyroscope driver for STMicroelectronics
gyroscopes, currently it supports:
L3G4200D, LSM330DL, L3GD20, L3GD20H, LSM330DLC, L3G4IS, LSM330.
Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
drivers/iio/gyro/Kconfig | 40 +++
drivers/iio/gyro/Makefile | 6 +
drivers/iio/gyro/st_gyro_buffer.c | 119 +++++++++
drivers/iio/gyro/st_gyro_core.c | 513 +++++++++++++++++++++++++++++++++++++
drivers/iio/gyro/st_gyro_i2c.c | 84 ++++++
drivers/iio/gyro/st_gyro_spi.c | 83 ++++++
include/linux/iio/gyro/st_gyro.h | 49 ++++
7 files changed, 894 insertions(+), 0 deletions(-)
create mode 100644 drivers/iio/gyro/st_gyro_buffer.c
create mode 100644 drivers/iio/gyro/st_gyro_core.c
create mode 100644 drivers/iio/gyro/st_gyro_i2c.c
create mode 100644 drivers/iio/gyro/st_gyro_spi.c
create mode 100644 include/linux/iio/gyro/st_gyro.h
diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
index 96b68f6..7a7eef5 100644
--- a/drivers/iio/gyro/Kconfig
+++ b/drivers/iio/gyro/Kconfig
@@ -23,4 +23,44 @@ config HID_SENSOR_GYRO_3D
Say yes here to build support for the HID SENSOR
Gyroscope 3D.
+config IIO_ST_GYRO_3AXIS
+ tristate "STMicroelectronics gyroscopes 3-Axis Driver"
+ depends on (I2C || SPI_MASTER) && SYSFS
+ select IIO_ST_SENSORS_CORE
+ help
+ Say yes here to build support for STMicroelectronics gyroscopes:
+ L3G4200D, LSM330DL, L3GD20, L3GD20H, LSM330DLC, L3G4IS, LSM330.
+
+ This driver can also be built as a module. If so, the module
+ will be called st_gyro.
+
+config IIO_ST_GYRO_3AXIS_I2C
+ tristate "support I2C bus connection"
+ depends on IIO_ST_GYRO_3AXIS && I2C
+ select IIO_ST_SENSORS_I2C
+ help
+ Say yes here to build I2C support for STMicroelectronics gyroscopes.
+
+ To compile this driver as a module, choose M here: the
+ module will be called st_gyro_i2c.
+
+config IIO_ST_GYRO_3AXIS_SPI
+ tristate "support SPI bus connection"
+ depends on IIO_ST_GYRO_3AXIS && SPI_MASTER
+ select IIO_ST_SENSORS_SPI
+ help
+ Say yes here to build SPI support for STMicroelectronics gyroscopes.
+
+ To compile this driver as a module, choose M here: the
+ module will be called st_gyro_spi.
+
+config IIO_ST_GYRO_3AXIS_TRIGGERED_BUFFER
+ tristate "support triggered buffer"
+ depends on IIO_ST_GYRO_3AXIS
+ select IIO_TRIGGERED_BUFFER
+ select IIO_BUFFER
+ select IIO_ST_SENSORS_TRIGGERED_BUFFER
+ help
+ Default trigger and buffer for STMicroelectronics gyroscopes driver.
+
endmenu
diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile
index 702a058..61d43ba 100644
--- a/drivers/iio/gyro/Makefile
+++ b/drivers/iio/gyro/Makefile
@@ -4,3 +4,9 @@
obj-$(CONFIG_ADIS16136) += adis16136.o
obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o
+
+st_gyro-y := st_gyro_core.o
+obj-$(CONFIG_IIO_ST_GYRO_3AXIS_I2C) += st_gyro_i2c.o
+obj-$(CONFIG_IIO_ST_GYRO_3AXIS_SPI) += st_gyro_spi.o
+obj-$(CONFIG_IIO_ST_GYRO_3AXIS_TRIGGERED_BUFFER) += st_gyro_buffer.o
+obj-$(CONFIG_IIO_ST_GYRO_3AXIS) += st_gyro.o
diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c
new file mode 100644
index 0000000..1293ca5
--- /dev/null
+++ b/drivers/iio/gyro/st_gyro_buffer.c
@@ -0,0 +1,119 @@
+/*
+ * STMicroelectronics gyroscopes driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/stat.h>
+#include <linux/interrupt.h>
+#include <linux/byteorder/generic.h>
+#include <linux/i2c.h>
+#include <linux/delay.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+
+#include <linux/iio/gyro/st_gyro.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+int st_gyro_trig_set_state(struct iio_trigger *trig, bool state)
+{
+ struct iio_dev *indio_dev = trig->private_data;
+ return st_gyro_set_dataready_irq(indio_dev, state);
+}
+EXPORT_SYMBOL(st_gyro_trig_set_state);
+
+static int st_gyro_buffer_preenable(struct iio_dev *indio_dev)
+{
+ int err;
+
+ err = st_gyro_set_enable(indio_dev, true);
+ if (err < 0)
+ goto st_gyro_set_enable_error;
+
+ err = iio_sw_buffer_preenable(indio_dev);
+
+st_gyro_set_enable_error:
+ return err;
+}
+
+static int st_gyro_buffer_postenable(struct iio_dev *indio_dev)
+{
+ int err;
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ gdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
+ if (gdata->buffer_data == NULL) {
+ err = -ENOMEM;
+ goto allocate_memory_error;
+ }
+
+ err = st_gyro_set_axis_enable(indio_dev,
+ (u8)indio_dev->active_scan_mask[0]);
+ if (err < 0)
+ goto st_gyro_buffer_postenable_error;
+
+ err = iio_triggered_buffer_postenable(indio_dev);
+ if (err < 0)
+ goto st_gyro_buffer_postenable_error;
+
+ return err;
+
+st_gyro_buffer_postenable_error:
+ kfree(gdata->buffer_data);
+allocate_memory_error:
+ return err;
+}
+
+static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)
+{
+ int err;
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ err = iio_triggered_buffer_predisable(indio_dev);
+ if (err < 0)
+ goto st_gyro_buffer_predisable_error;
+
+ err = st_gyro_set_axis_enable(indio_dev,
+ ST_SENSORS_ENABLE_ALL_CHANNELS);
+ if (err < 0)
+ goto st_gyro_buffer_predisable_error;
+
+ err = st_gyro_set_enable(indio_dev, false);
+
+st_gyro_buffer_predisable_error:
+ kfree(gdata->buffer_data);
+ return err;
+}
+
+static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = {
+ .preenable = &st_gyro_buffer_preenable,
+ .postenable = &st_gyro_buffer_postenable,
+ .predisable = &st_gyro_buffer_predisable,
+};
+
+int st_gyro_allocate_ring(struct iio_dev *indio_dev)
+{
+ return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+ &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops);
+}
+EXPORT_SYMBOL(st_gyro_allocate_ring);
+
+void st_gyro_deallocate_ring(struct iio_dev *indio_dev)
+{
+ iio_triggered_buffer_cleanup(indio_dev);
+}
+EXPORT_SYMBOL(st_gyro_deallocate_ring);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics gyroscopes buffer");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
new file mode 100644
index 0000000..d4b6c82
--- /dev/null
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -0,0 +1,513 @@
+/*
+ * STMicroelectronics gyroscopes driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/mutex.h>
+#include <linux/interrupt.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/irq.h>
+#include <linux/delay.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/buffer.h>
+
+#include <linux/iio/gyro/st_gyro.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+/* DEFAULT VALUE FOR SENSORS */
+#define ST_GYRO_DEFAULT_OUT_X_L_ADDR 0x28
+#define ST_GYRO_DEFAULT_OUT_Y_L_ADDR 0x2a
+#define ST_GYRO_DEFAULT_OUT_Z_L_ADDR 0x2c
+
+/* FULLSCALE */
+#define ST_GYRO_FS_AVL_250DPS 250
+#define ST_GYRO_FS_AVL_500DPS 500
+#define ST_GYRO_FS_AVL_2000DPS 2000
+
+/* CUSTOM VALUES FOR SENSOR 1 */
+#define ST_GYRO_1_WAI_EXP 0xd3
+#define ST_GYRO_1_ODR_ADDR 0x20
+#define ST_GYRO_1_ODR_MASK 0xc0
+#define ST_GYRO_1_ODR_N_BIT 2
+#define ST_GYRO_1_ODR_AVL_100HZ_VAL 0x00
+#define ST_GYRO_1_ODR_AVL_200HZ_VAL 0x01
+#define ST_GYRO_1_ODR_AVL_400HZ_VAL 0x02
+#define ST_GYRO_1_ODR_AVL_800HZ_VAL 0x03
+#define ST_GYRO_1_PW_ADDR 0x20
+#define ST_GYRO_1_PW_MASK 0x08
+#define ST_GYRO_1_PW_N_BIT 1
+#define ST_GYRO_1_FS_N_BIT 2
+#define ST_GYRO_1_FS_ADDR 0x23
+#define ST_GYRO_1_FS_MASK 0x30
+#define ST_GYRO_1_FS_AVL_250_VAL 0x00
+#define ST_GYRO_1_FS_AVL_500_VAL 0x01
+#define ST_GYRO_1_FS_AVL_2000_VAL 0x02
+#define ST_GYRO_1_FS_AVL_250_GAIN IIO_DEGREE_TO_RAD(8750)
+#define ST_GYRO_1_FS_AVL_500_GAIN IIO_DEGREE_TO_RAD(17500)
+#define ST_GYRO_1_FS_AVL_2000_GAIN IIO_DEGREE_TO_RAD(70000)
+#define ST_GYRO_1_BDU_ADDR 0x23
+#define ST_GYRO_1_BDU_MASK 0x80
+#define ST_GYRO_1_DRDY_IRQ_ADDR 0x22
+#define ST_GYRO_1_DRDY_IRQ_MASK 0x08
+#define ST_GYRO_1_MULTIREAD_BIT true
+
+/* CUSTOM VALUES FOR SENSOR 2 */
+#define ST_GYRO_2_WAI_EXP 0xd4
+#define ST_GYRO_2_ODR_ADDR 0x20
+#define ST_GYRO_2_ODR_MASK 0xc0
+#define ST_GYRO_2_ODR_N_BIT 2
+#define ST_GYRO_2_ODR_AVL_95HZ_VAL 0x00
+#define ST_GYRO_2_ODR_AVL_190HZ_VAL 0x01
+#define ST_GYRO_2_ODR_AVL_380HZ_VAL 0x02
+#define ST_GYRO_2_ODR_AVL_760HZ_VAL 0x03
+#define ST_GYRO_2_PW_ADDR 0x20
+#define ST_GYRO_2_PW_MASK 0x08
+#define ST_GYRO_2_PW_N_BIT 1
+#define ST_GYRO_2_FS_N_BIT 2
+#define ST_GYRO_2_FS_ADDR 0x23
+#define ST_GYRO_2_FS_MASK 0x30
+#define ST_GYRO_2_FS_AVL_250_VAL 0x00
+#define ST_GYRO_2_FS_AVL_500_VAL 0x01
+#define ST_GYRO_2_FS_AVL_2000_VAL 0x02
+#define ST_GYRO_2_FS_AVL_250_GAIN IIO_DEGREE_TO_RAD(8750)
+#define ST_GYRO_2_FS_AVL_500_GAIN IIO_DEGREE_TO_RAD(17500)
+#define ST_GYRO_2_FS_AVL_2000_GAIN IIO_DEGREE_TO_RAD(70000)
+#define ST_GYRO_2_BDU_ADDR 0x23
+#define ST_GYRO_2_BDU_MASK 0x80
+#define ST_GYRO_2_DRDY_IRQ_ADDR 0x22
+#define ST_GYRO_2_DRDY_IRQ_MASK 0x08
+#define ST_GYRO_2_MULTIREAD_BIT true
+
+static const struct iio_chan_spec st_gyro_16bit_channels[] = {
+ ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_X,
+ IIO_MOD_X, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS,
+ ST_GYRO_DEFAULT_OUT_X_L_ADDR),
+ ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_Y,
+ IIO_MOD_Y, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS,
+ ST_GYRO_DEFAULT_OUT_Y_L_ADDR),
+ ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_Z,
+ IIO_MOD_Z, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS,
+ ST_GYRO_DEFAULT_OUT_Z_L_ADDR),
+ IIO_CHAN_SOFT_TIMESTAMP(3)
+};
+
+static const struct st_sensors st_gyro_sensors[] = {
+ {
+ .wai = ST_GYRO_1_WAI_EXP,
+ .sensors_supported = {
+ [0] = L3G4200D_GYRO_DEV_NAME,
+ [1] = LSM330DL_GYRO_DEV_NAME,
+ },
+ .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
+ .odr = {
+ .addr = ST_GYRO_1_ODR_ADDR,
+ .mask = ST_GYRO_1_ODR_MASK,
+ .num_bit = ST_GYRO_1_ODR_N_BIT,
+ .odr_avl = {
+ { 100, ST_GYRO_1_ODR_AVL_100HZ_VAL, },
+ { 200, ST_GYRO_1_ODR_AVL_200HZ_VAL, },
+ { 400, ST_GYRO_1_ODR_AVL_400HZ_VAL, },
+ { 800, ST_GYRO_1_ODR_AVL_800HZ_VAL, },
+ },
+ },
+ .pw = {
+ .addr = ST_GYRO_1_PW_ADDR,
+ .mask = ST_GYRO_1_PW_MASK,
+ .num_bit = ST_GYRO_1_PW_N_BIT,
+ .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
+ .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
+ },
+ .enable_axis = {
+ .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
+ .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
+ },
+ .fs = {
+ .addr = ST_GYRO_1_FS_ADDR,
+ .mask = ST_GYRO_1_FS_MASK,
+ .num_bit = ST_GYRO_1_FS_N_BIT,
+ .fs_avl = {
+ [0] = {
+ .num = ST_GYRO_FS_AVL_250DPS,
+ .value = ST_GYRO_1_FS_AVL_250_VAL,
+ .gain = ST_GYRO_1_FS_AVL_250_GAIN,
+ },
+ [1] = {
+ .num = ST_GYRO_FS_AVL_500DPS,
+ .value = ST_GYRO_1_FS_AVL_500_VAL,
+ .gain = ST_GYRO_1_FS_AVL_500_GAIN,
+ },
+ [2] = {
+ .num = ST_GYRO_FS_AVL_2000DPS,
+ .value = ST_GYRO_1_FS_AVL_2000_VAL,
+ .gain = ST_GYRO_1_FS_AVL_2000_GAIN,
+ },
+ },
+ },
+ .bdu = {
+ .addr = ST_GYRO_1_BDU_ADDR,
+ .mask = ST_GYRO_1_BDU_MASK,
+ },
+ .drdy_irq = {
+ .addr = ST_GYRO_1_DRDY_IRQ_ADDR,
+ .mask = ST_GYRO_1_DRDY_IRQ_MASK,
+ },
+ .multi_read_bit = ST_GYRO_1_MULTIREAD_BIT,
+ .bootime = 2,
+ },
+ {
+ .wai = ST_GYRO_2_WAI_EXP,
+ .sensors_supported = {
+ [0] = L3GD20_GYRO_DEV_NAME,
+ [1] = L3GD20H_GYRO_DEV_NAME,
+ [2] = LSM330DLC_GYRO_DEV_NAME,
+ [3] = L3G4IS_GYRO_DEV_NAME,
+ [4] = LSM330_GYRO_DEV_NAME,
+ },
+ .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
+ .odr = {
+ .addr = ST_GYRO_2_ODR_ADDR,
+ .mask = ST_GYRO_2_ODR_MASK,
+ .num_bit = ST_GYRO_2_ODR_N_BIT,
+ .odr_avl = {
+ { 95, ST_GYRO_2_ODR_AVL_95HZ_VAL, },
+ { 190, ST_GYRO_2_ODR_AVL_190HZ_VAL, },
+ { 380, ST_GYRO_2_ODR_AVL_380HZ_VAL, },
+ { 760, ST_GYRO_2_ODR_AVL_760HZ_VAL, },
+ },
+ },
+ .pw = {
+ .addr = ST_GYRO_2_PW_ADDR,
+ .mask = ST_GYRO_2_PW_MASK,
+ .num_bit = ST_GYRO_2_PW_N_BIT,
+ .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
+ .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
+ },
+ .enable_axis = {
+ .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
+ .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
+ },
+ .fs = {
+ .addr = ST_GYRO_2_FS_ADDR,
+ .mask = ST_GYRO_2_FS_MASK,
+ .num_bit = ST_GYRO_2_FS_N_BIT,
+ .fs_avl = {
+ [0] = {
+ .num = ST_GYRO_FS_AVL_250DPS,
+ .value = ST_GYRO_2_FS_AVL_250_VAL,
+ .gain = ST_GYRO_2_FS_AVL_250_GAIN,
+ },
+ [1] = {
+ .num = ST_GYRO_FS_AVL_500DPS,
+ .value = ST_GYRO_2_FS_AVL_500_VAL,
+ .gain = ST_GYRO_2_FS_AVL_500_GAIN,
+ },
+ [2] = {
+ .num = ST_GYRO_FS_AVL_2000DPS,
+ .value = ST_GYRO_2_FS_AVL_2000_VAL,
+ .gain = ST_GYRO_2_FS_AVL_2000_GAIN,
+ },
+ },
+ },
+ .bdu = {
+ .addr = ST_GYRO_2_BDU_ADDR,
+ .mask = ST_GYRO_2_BDU_MASK,
+ },
+ .drdy_irq = {
+ .addr = ST_GYRO_2_DRDY_IRQ_ADDR,
+ .mask = ST_GYRO_2_DRDY_IRQ_MASK,
+ },
+ .multi_read_bit = ST_GYRO_2_MULTIREAD_BIT,
+ .bootime = 2,
+ },
+};
+
+static int st_gyro_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *ch, int *val,
+ int *val2, long mask)
+{
+ int err;
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW:
+ mutex_lock(&indio_dev->mlock);
+ if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
+ err = -EBUSY;
+ goto read_error;
+ } else {
+ err = st_sensors_set_enable(indio_dev,
+ &st_gyro_sensors[gdata->index], true);
+ if (err < 0)
+ goto read_error;
+
+ msleep((st_gyro_sensors[gdata->index].bootime * 1000)
+ / gdata->odr);
+ err = st_sensors_read_axis_data(indio_dev,
+ ch->address, val);
+ if (err < 0)
+ goto read_error;
+
+ *val = *val >> ch->scan_type.shift;
+ }
+ mutex_unlock(&indio_dev->mlock);
+ return IIO_VAL_INT;
+ case IIO_CHAN_INFO_SCALE:
+ *val = 0;
+ *val2 = gdata->current_fullscale->gain;
+ return IIO_VAL_INT_PLUS_MICRO;
+ default:
+ return -EINVAL;
+ }
+
+read_error:
+ mutex_unlock(&indio_dev->mlock);
+ return err;
+}
+
+static int st_gyro_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan, int val, int val2, long mask)
+{
+ int err;
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ switch (mask) {
+ case IIO_CHAN_INFO_SCALE:
+ err = st_sensors_set_fullscale_by_gain(indio_dev,
+ &st_gyro_sensors[gdata->index], val2);
+ break;
+ default:
+ err = -EINVAL;
+ }
+
+ return err;
+}
+
+int st_gyro_set_dataready_irq(struct iio_dev *indio_dev, bool state)
+{
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ return st_sensors_set_dataready_irq(indio_dev,
+ &st_gyro_sensors[gdata->index], state);
+}
+EXPORT_SYMBOL(st_gyro_set_dataready_irq);
+
+int st_gyro_set_axis_enable(struct iio_dev *indio_dev, u8 active_bit)
+{
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ return st_sensors_set_axis_enable(indio_dev,
+ &st_gyro_sensors[gdata->index], active_bit);
+}
+EXPORT_SYMBOL(st_gyro_set_axis_enable);
+
+static int st_gyro_check_device_support(struct iio_dev *indio_dev)
+{
+ int i, n, err;
+ u8 wai;
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ err = gdata->tf->read_byte(&gdata->tb, gdata->dev,
+ ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai);
+ if (err < 0) {
+ dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
+ goto read_wai_error;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(st_gyro_sensors); i++) {
+ if (st_gyro_sensors[i].wai == wai)
+ break;
+ }
+ if (i == ARRAY_SIZE(st_gyro_sensors))
+ goto device_not_supported;
+
+ for (n = 0; n < ARRAY_SIZE(st_gyro_sensors[i].sensors_supported);
+ n++) {
+ if (strcmp(indio_dev->name,
+ &st_gyro_sensors[i].sensors_supported[n][0]) == 0)
+ break;
+ }
+ if (n == ARRAY_SIZE(st_gyro_sensors[i].sensors_supported)) {
+ dev_err(&indio_dev->dev, "device name and WhoAmI mismatch.\n");
+ goto sensor_name_mismatch;
+ }
+
+ gdata->index = i;
+
+ return i;
+
+device_not_supported:
+ dev_err(&indio_dev->dev, "device not supported: WhoAmI (0x%x).\n", wai);
+sensor_name_mismatch:
+ err = -ENODEV;
+read_wai_error:
+ return err;
+}
+
+int st_gyro_set_enable(struct iio_dev *indio_dev, bool enable)
+{
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ return st_sensors_set_enable(indio_dev,
+ &st_gyro_sensors[gdata->index], enable);
+}
+EXPORT_SYMBOL(st_gyro_set_enable);
+
+static ssize_t st_gyro_sysfs_set_sampling_frequency(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ int err;
+ unsigned int odr;
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ err = kstrtoint(buf, 10, &odr);
+ if (err < 0)
+ goto conversion_error;
+
+ mutex_lock(&indio_dev->mlock);
+ err = st_sensors_set_odr(indio_dev,
+ &st_gyro_sensors[gdata->index], odr);
+ mutex_unlock(&indio_dev->mlock);
+
+conversion_error:
+ return err < 0 ? err : size;
+}
+
+static ssize_t st_gyro_sysfs_get_sampling_frequency(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ return sprintf(buf, "%d\n", gdata->odr);
+}
+
+static ssize_t st_gyro_sysfs_scale_avail(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ return st_sensors_get_scale_avl(indio_dev,
+ st_gyro_sensors[gdata->index].fs.fs_avl, buf);
+}
+
+static ssize_t st_gyro_sysfs_sampling_frequency_avail(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ return st_sensors_get_sampling_frequency_avl(indio_dev,
+ st_gyro_sensors[gdata->index].odr.odr_avl, buf);
+}
+
+static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(st_gyro_sysfs_sampling_frequency_avail);
+
+static IIO_DEVICE_ATTR(in_anglvel_scale_available, S_IRUGO,
+ st_gyro_sysfs_scale_avail, NULL , 0);
+
+static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
+ st_gyro_sysfs_get_sampling_frequency,
+ st_gyro_sysfs_set_sampling_frequency);
+
+static struct attribute *st_gyro_attributes[] = {
+ &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
+ &iio_dev_attr_in_anglvel_scale_available.dev_attr.attr,
+ &iio_dev_attr_sampling_frequency.dev_attr.attr,
+ NULL,
+};
+
+static const struct attribute_group st_gyro_attribute_group = {
+ .attrs = st_gyro_attributes,
+};
+
+static const struct iio_info gyro_info = {
+ .driver_module = THIS_MODULE,
+ .attrs = &st_gyro_attribute_group,
+ .read_raw = &st_gyro_read_raw,
+ .write_raw = &st_gyro_write_raw,
+};
+
+int st_gyro_common_probe(struct iio_dev *indio_dev)
+{
+ int err;
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->info = &gyro_info;
+
+ err = st_gyro_check_device_support(indio_dev);
+ if (err < 0)
+ goto st_gyro_common_probe_error;
+
+ gdata->multiread_bit = st_gyro_sensors[gdata->index].multi_read_bit;
+ indio_dev->channels = st_gyro_sensors[gdata->index].ch;
+ indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
+
+ gdata->current_fullscale = (struct st_sensor_fullscale_avl *)
+ &st_gyro_sensors[gdata->index].fs.fs_avl[0];
+ gdata->odr = st_gyro_sensors[gdata->index].odr.odr_avl[0].hz;
+
+ err = st_sensors_init_sensor(indio_dev, &st_gyro_sensors[gdata->index]);
+ if (err < 0)
+ goto st_gyro_common_probe_error;
+
+ if (gdata->get_irq_data_ready(indio_dev) > 0) {
+ err = st_gyro_allocate_ring(indio_dev);
+ if (err < 0)
+ goto st_gyro_common_probe_error;
+
+ err = st_sensors_allocate_trigger(indio_dev,
+ &st_gyro_trig_set_state, NULL);
+ if (err < 0)
+ goto st_gyro_probe_trigger_error;
+ }
+
+ err = iio_device_register(indio_dev);
+ if (err)
+ goto st_gyro_device_register_error;
+
+ return err;
+
+st_gyro_device_register_error:
+ if (gdata->get_irq_data_ready(indio_dev) > 0)
+ st_sensors_deallocate_trigger(indio_dev);
+st_gyro_probe_trigger_error:
+ if (gdata->get_irq_data_ready(indio_dev) > 0)
+ st_gyro_deallocate_ring(indio_dev);
+st_gyro_common_probe_error:
+ return err;
+}
+EXPORT_SYMBOL(st_gyro_common_probe);
+
+void st_gyro_common_remove(struct iio_dev *indio_dev)
+{
+ struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+ iio_device_unregister(indio_dev);
+ if (gdata->get_irq_data_ready(indio_dev) > 0) {
+ st_sensors_deallocate_trigger(indio_dev);
+ st_gyro_deallocate_ring(indio_dev);
+ }
+ iio_device_free(indio_dev);
+}
+EXPORT_SYMBOL(st_gyro_common_remove);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics gyroscopes driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
new file mode 100644
index 0000000..24cead1
--- /dev/null
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -0,0 +1,84 @@
+/*
+ * STMicroelectronics gyroscopes driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+
+#include <linux/iio/gyro/st_gyro.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+static int st_gyro_i2c_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct iio_dev *indio_dev;
+ struct st_sensor_data *gdata;
+ int err;
+
+ indio_dev = iio_device_alloc(sizeof(*gdata));
+ if (indio_dev == NULL) {
+ err = -ENOMEM;
+ goto iio_device_alloc_error;
+ }
+
+ gdata = iio_priv(indio_dev);
+ gdata->dev = &client->dev;
+
+ st_sensors_i2c_configure(indio_dev, client, gdata);
+
+ err = st_gyro_common_probe(indio_dev);
+ if (err < 0)
+ goto st_gyro_common_probe_error;
+
+ return 0;
+
+st_gyro_common_probe_error:
+ iio_device_free(indio_dev);
+iio_device_alloc_error:
+ return err;
+}
+
+static int st_gyro_i2c_remove(struct i2c_client *client)
+{
+ st_gyro_common_remove(i2c_get_clientdata(client));
+
+ return 0;
+}
+
+static const struct i2c_device_id st_gyro_id_table[] = {
+ { L3G4200D_GYRO_DEV_NAME },
+ { LSM330DL_GYRO_DEV_NAME },
+ { L3GD20_GYRO_DEV_NAME },
+ { L3GD20H_GYRO_DEV_NAME },
+ { LSM330DLC_GYRO_DEV_NAME },
+ { L3G4IS_GYRO_DEV_NAME },
+ { LSM330_GYRO_DEV_NAME },
+ {},
+};
+MODULE_DEVICE_TABLE(i2c, st_gyro_id_table);
+
+static struct i2c_driver st_gyro_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "st-gyro-i2c",
+ },
+ .probe = st_gyro_i2c_probe,
+ .remove = st_gyro_i2c_remove,
+ .id_table = st_gyro_id_table,
+};
+module_i2c_driver(st_gyro_driver);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics gyroscopes i2c driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c
new file mode 100644
index 0000000..38775e3
--- /dev/null
+++ b/drivers/iio/gyro/st_gyro_spi.c
@@ -0,0 +1,83 @@
+/*
+ * STMicroelectronics gyroscopes driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/spi/spi.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+
+#include <linux/iio/gyro/st_gyro.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+static int st_gyro_spi_probe(struct spi_device *spi)
+{
+ struct iio_dev *indio_dev;
+ struct st_sensor_data *gdata;
+ int err;
+
+ indio_dev = iio_device_alloc(sizeof(*gdata));
+ if (indio_dev == NULL) {
+ err = -ENOMEM;
+ goto iio_device_alloc_error;
+ }
+
+ gdata = iio_priv(indio_dev);
+ gdata->dev = &spi->dev;
+
+ st_sensors_spi_configure(indio_dev, spi, gdata);
+
+ err = st_gyro_common_probe(indio_dev);
+ if (err < 0)
+ goto st_gyro_common_probe_error;
+
+ return 0;
+
+st_gyro_common_probe_error:
+ iio_device_free(indio_dev);
+iio_device_alloc_error:
+ return err;
+}
+
+static int st_gyro_spi_remove(struct spi_device *spi)
+{
+ st_gyro_common_remove(spi_get_drvdata(spi));
+
+ return 0;
+}
+
+static const struct spi_device_id st_gyro_id_table[] = {
+ { L3G4200D_GYRO_DEV_NAME },
+ { LSM330DL_GYRO_DEV_NAME },
+ { L3GD20_GYRO_DEV_NAME },
+ { L3GD20H_GYRO_DEV_NAME },
+ { LSM330DLC_GYRO_DEV_NAME },
+ { L3G4IS_GYRO_DEV_NAME },
+ { LSM330_GYRO_DEV_NAME },
+ {},
+};
+MODULE_DEVICE_TABLE(spi, st_gyro_id_table);
+
+static struct spi_driver st_gyro_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "st-gyro-spi",
+ },
+ .probe = st_gyro_spi_probe,
+ .remove = st_gyro_spi_remove,
+ .id_table = st_gyro_id_table,
+};
+module_spi_driver(st_gyro_driver);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics gyroscopes spi driver");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/iio/gyro/st_gyro.h b/include/linux/iio/gyro/st_gyro.h
new file mode 100644
index 0000000..d7613ca
--- /dev/null
+++ b/include/linux/iio/gyro/st_gyro.h
@@ -0,0 +1,49 @@
+/*
+ * STMicroelectronics gyroscopes driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ * v. 1.0.0
+ * Licensed under the GPL-2.
+ */
+
+#ifndef ST_GYRO_H
+#define ST_GYRO_H
+
+#include <linux/types.h>
+#include "../common/st_sensors.h"
+
+#define L3G4200D_GYRO_DEV_NAME "l3g4200d"
+#define LSM330DL_GYRO_DEV_NAME "lsm330dl_gyro"
+#define L3GD20_GYRO_DEV_NAME "l3gd20"
+#define L3GD20H_GYRO_DEV_NAME "l3gd20h"
+#define LSM330DLC_GYRO_DEV_NAME "lsm330dlc_gyro"
+#define L3G4IS_GYRO_DEV_NAME "l3g4is_ui"
+#define LSM330_GYRO_DEV_NAME "lsm330_gyro"
+
+int st_gyro_common_probe(struct iio_dev *indio_dev);
+void st_gyro_common_remove(struct iio_dev *indio_dev);
+int st_gyro_set_dataready_irq(struct iio_dev *indio_dev, bool state);
+int st_gyro_set_axis_enable(struct iio_dev *indio_dev, u8 active_bit);
+int st_gyro_set_enable(struct iio_dev *indio_dev, bool enable);
+
+#ifdef CONFIG_IIO_ST_GYRO_3AXIS_TRIGGERED_BUFFER
+int st_gyro_allocate_ring(struct iio_dev *indio_dev);
+void st_gyro_deallocate_ring(struct iio_dev *indio_dev);
+int st_gyro_trig_set_state(struct iio_trigger *trig, bool state);
+#else /* CONFIG_IIO_ST_GYRO_3AXIS_TRIGGERED_BUFFER */
+static inline int st_gyro_allocate_ring(struct iio_dev *indio_dev)
+{
+ return 0;
+}
+static inline void st_gyro_deallocate_ring(struct iio_dev *indio_dev)
+{
+}
+static inline int st_gyro_trig_set_state(struct iio_trigger *trig, bool state)
+{
+ return 0;
+}
+#endif /* CONFIG_IIO_ST_GYRO_3AXIS_TRIGGERED_BUFFER */
+
+#endif /* ST_GYRO_H */
--
1.7.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 4/9] iio:magnetometer: Add STMicroelectronics magnetometers driver
2013-01-15 8:30 iio: STMicroelectronics iio drivers Denis CIOCCA
` (2 preceding siblings ...)
2013-01-15 8:30 ` [PATCH 3/9] iio:gyro: Add STMicroelectronics gyroscopes driver Denis CIOCCA
@ 2013-01-15 8:31 ` Denis CIOCCA
2013-01-15 22:33 ` iio: STMicroelectronics iio drivers Jonathan Cameron
4 siblings, 0 replies; 20+ messages in thread
From: Denis CIOCCA @ 2013-01-15 8:31 UTC (permalink / raw)
To: jic23, lars, linux-iio; +Cc: Denis Ciocca
This patch adds generic magnetometer driver for STMicroelectronics
magnetometers, currently it supports:
LSM303DLHC, LSM303DLM, LIS3MDL.
Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
drivers/iio/magnetometer/Kconfig | 40 +++
drivers/iio/magnetometer/Makefile | 6 +
drivers/iio/magnetometer/st_magn_buffer.c | 102 ++++++
drivers/iio/magnetometer/st_magn_core.c | 526 +++++++++++++++++++++++++++++
drivers/iio/magnetometer/st_magn_i2c.c | 81 +++++
drivers/iio/magnetometer/st_magn_spi.c | 80 +++++
include/linux/iio/magnetometer/st_magn.h | 47 +++
7 files changed, 882 insertions(+), 0 deletions(-)
create mode 100644 drivers/iio/magnetometer/st_magn_buffer.c
create mode 100644 drivers/iio/magnetometer/st_magn_core.c
create mode 100644 drivers/iio/magnetometer/st_magn_i2c.c
create mode 100644 drivers/iio/magnetometer/st_magn_spi.c
create mode 100644 include/linux/iio/magnetometer/st_magn.h
diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig
index ff11d68..02e1273 100644
--- a/drivers/iio/magnetometer/Kconfig
+++ b/drivers/iio/magnetometer/Kconfig
@@ -14,4 +14,44 @@ config HID_SENSOR_MAGNETOMETER_3D
Say yes here to build support for the HID SENSOR
Magnetometer 3D.
+config IIO_ST_MAGN_3AXIS
+ tristate "STMicroelectronics magnetometers 3-Axis Driver"
+ depends on (I2C || SPI_MASTER) && SYSFS
+ select IIO_ST_SENSORS_CORE
+ help
+ Say yes here to build support for STMicroelectronics magnetometers:
+ LSM303DLHC, LSM303DLM, LIS3MDL.
+
+ This driver can also be built as a module. If so, the module
+ will be called st_magn.
+
+config IIO_ST_MAGN_3AXIS_I2C
+ tristate "support I2C bus connection"
+ depends on IIO_ST_MAGN_3AXIS && I2C
+ select IIO_ST_SENSORS_I2C
+ help
+ Say yes here to build I2C support for STMicroelectronics magnetometers.
+
+ To compile this driver as a module, choose M here: the
+ module will be called st_magn_i2c.
+
+config IIO_ST_MAGN_3AXIS_SPI
+ tristate "support SPI bus connection"
+ depends on IIO_ST_MAGN_3AXIS && SPI_MASTER
+ select IIO_ST_SENSORS_SPI
+ help
+ Say yes here to build SPI support for STMicroelectronics magnetometers.
+
+ To compile this driver as a module, choose M here: the
+ module will be called st_magn_spi.
+
+config IIO_ST_MAGN_3AXIS_TRIGGERED_BUFFER
+ tristate "support triggered buffer"
+ depends on IIO_ST_MAGN_3AXIS
+ select IIO_TRIGGERED_BUFFER
+ select IIO_BUFFER
+ select IIO_ST_SENSORS_TRIGGERED_BUFFER
+ help
+ Default trigger and buffer for STMicroelectronics magnetometers driver.
+
endmenu
diff --git a/drivers/iio/magnetometer/Makefile b/drivers/iio/magnetometer/Makefile
index 60dc4f2..33d42e5 100644
--- a/drivers/iio/magnetometer/Makefile
+++ b/drivers/iio/magnetometer/Makefile
@@ -3,3 +3,9 @@
#
obj-$(CONFIG_HID_SENSOR_MAGNETOMETER_3D) += hid-sensor-magn-3d.o
+
+st_magn-y := st_magn_core.o
+obj-$(CONFIG_IIO_ST_MAGN_3AXIS_I2C) += st_magn_i2c.o
+obj-$(CONFIG_IIO_ST_MAGN_3AXIS_SPI) += st_magn_spi.o
+obj-$(CONFIG_IIO_ST_MAGN_3AXIS_TRIGGERED_BUFFER) += st_magn_buffer.o
+obj-$(CONFIG_IIO_ST_MAGN_3AXIS) += st_magn.o
diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c
new file mode 100644
index 0000000..2a59d86
--- /dev/null
+++ b/drivers/iio/magnetometer/st_magn_buffer.c
@@ -0,0 +1,102 @@
+/*
+ * STMicroelectronics magnetometers driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/stat.h>
+#include <linux/interrupt.h>
+#include <linux/byteorder/generic.h>
+#include <linux/i2c.h>
+#include <linux/delay.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+
+#include <linux/iio/magnetometer/st_magn.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+static int st_magn_buffer_preenable(struct iio_dev *indio_dev)
+{
+ int err;
+
+ err = st_magn_set_enable(indio_dev, true);
+ if (err < 0)
+ goto st_magn_set_enable_error;
+
+ err = iio_sw_buffer_preenable(indio_dev);
+
+st_magn_set_enable_error:
+ return err;
+}
+
+static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
+{
+ int err;
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ mdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
+ if (mdata->buffer_data == NULL) {
+ err = -ENOMEM;
+ goto allocate_memory_error;
+ }
+
+ err = iio_triggered_buffer_postenable(indio_dev);
+ if (err < 0)
+ goto st_magn_buffer_postenable_error;
+
+ return err;
+
+st_magn_buffer_postenable_error:
+ kfree(mdata->buffer_data);
+allocate_memory_error:
+ return err;
+}
+
+static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
+{
+ int err;
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ err = iio_triggered_buffer_predisable(indio_dev);
+ if (err < 0)
+ goto st_magn_buffer_predisable_error;
+
+ err = st_magn_set_enable(indio_dev, false);
+
+st_magn_buffer_predisable_error:
+ kfree(mdata->buffer_data);
+ return err;
+}
+
+static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = {
+ .preenable = &st_magn_buffer_preenable,
+ .postenable = &st_magn_buffer_postenable,
+ .predisable = &st_magn_buffer_predisable,
+};
+
+int st_magn_allocate_ring(struct iio_dev *indio_dev)
+{
+ return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+ &st_sensors_trigger_handler, &st_magn_buffer_setup_ops);
+}
+EXPORT_SYMBOL(st_magn_allocate_ring);
+
+void st_magn_deallocate_ring(struct iio_dev *indio_dev)
+{
+ iio_triggered_buffer_cleanup(indio_dev);
+}
+EXPORT_SYMBOL(st_magn_deallocate_ring);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics magnetometers buffer");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
new file mode 100644
index 0000000..0dd7f0c
--- /dev/null
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -0,0 +1,526 @@
+/*
+ * STMicroelectronics magnetometers driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/mutex.h>
+#include <linux/interrupt.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/irq.h>
+#include <linux/delay.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/buffer.h>
+
+#include <linux/iio/magnetometer/st_magn.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+/* DEFAULT VALUE FOR SENSORS */
+#define ST_MAGN_DEFAULT_OUT_X_L_ADDR 0X04
+#define ST_MAGN_DEFAULT_OUT_Y_L_ADDR 0X08
+#define ST_MAGN_DEFAULT_OUT_Z_L_ADDR 0X06
+
+/* FULLSCALE */
+#define ST_MAGN_FS_AVL_1300MG 1300
+#define ST_MAGN_FS_AVL_1900MG 1900
+#define ST_MAGN_FS_AVL_2500MG 2500
+#define ST_MAGN_FS_AVL_4000MG 4000
+#define ST_MAGN_FS_AVL_4700MG 4700
+#define ST_MAGN_FS_AVL_5600MG 5600
+#define ST_MAGN_FS_AVL_8000MG 8000
+#define ST_MAGN_FS_AVL_8100MG 8100
+#define ST_MAGN_FS_AVL_10000MG 10000
+
+/* CUSTOM VALUES FOR SENSOR 1 */
+#define ST_MAGN_1_WAI_EXP 0x3c
+#define ST_MAGN_1_ODR_ADDR 0x00
+#define ST_MAGN_1_ODR_MASK 0x1c
+#define ST_MAGN_1_ODR_N_BIT 3
+#define ST_MAGN_1_ODR_AVL_1HZ_VAL 0x00
+#define ST_MAGN_1_ODR_AVL_2HZ_VAL 0x01
+#define ST_MAGN_1_ODR_AVL_3HZ_VAL 0x02
+#define ST_MAGN_1_ODR_AVL_8HZ_VAL 0x03
+#define ST_MAGN_1_ODR_AVL_15HZ_VAL 0x04
+#define ST_MAGN_1_ODR_AVL_30HZ_VAL 0x05
+#define ST_MAGN_1_ODR_AVL_75HZ_VAL 0x06
+#define ST_MAGN_1_ODR_AVL_220HZ_VAL 0x07
+#define ST_MAGN_1_PW_ADDR 0x02
+#define ST_MAGN_1_PW_MASK 0x03
+#define ST_MAGN_1_PW_N_BIT 2
+#define ST_MAGN_1_PW_ON 0x00
+#define ST_MAGN_1_PW_OFF 0x03
+#define ST_MAGN_1_FS_N_BIT 3
+#define ST_MAGN_1_FS_ADDR 0x01
+#define ST_MAGN_1_FS_MASK 0xe0
+#define ST_MAGN_1_FS_AVL_1300_VAL 0x01
+#define ST_MAGN_1_FS_AVL_1900_VAL 0x02
+#define ST_MAGN_1_FS_AVL_2500_VAL 0x03
+#define ST_MAGN_1_FS_AVL_4000_VAL 0x04
+#define ST_MAGN_1_FS_AVL_4700_VAL 0x05
+#define ST_MAGN_1_FS_AVL_5600_VAL 0x06
+#define ST_MAGN_1_FS_AVL_8100_VAL 0x07
+#define ST_MAGN_1_FS_AVL_1300_GAIN_XY 1100
+#define ST_MAGN_1_FS_AVL_1900_GAIN_XY 855
+#define ST_MAGN_1_FS_AVL_2500_GAIN_XY 670
+#define ST_MAGN_1_FS_AVL_4000_GAIN_XY 450
+#define ST_MAGN_1_FS_AVL_4700_GAIN_XY 400
+#define ST_MAGN_1_FS_AVL_5600_GAIN_XY 330
+#define ST_MAGN_1_FS_AVL_8100_GAIN_XY 230
+#define ST_MAGN_1_FS_AVL_1300_GAIN_Z 980
+#define ST_MAGN_1_FS_AVL_1900_GAIN_Z 760
+#define ST_MAGN_1_FS_AVL_2500_GAIN_Z 600
+#define ST_MAGN_1_FS_AVL_4000_GAIN_Z 400
+#define ST_MAGN_1_FS_AVL_4700_GAIN_Z 355
+#define ST_MAGN_1_FS_AVL_5600_GAIN_Z 295
+#define ST_MAGN_1_FS_AVL_8100_GAIN_Z 205
+#define ST_MAGN_1_MULTIREAD_BIT false
+
+/* CUSTOM VALUES FOR SENSOR 2 */
+#define ST_MAGN_2_WAI_EXP 0x3d
+#define ST_MAGN_2_ODR_ADDR 0x20
+#define ST_MAGN_2_ODR_MASK 0x1c
+#define ST_MAGN_2_ODR_N_BIT 3
+#define ST_MAGN_2_ODR_AVL_1HZ_VAL 0x00
+#define ST_MAGN_2_ODR_AVL_2HZ_VAL 0x01
+#define ST_MAGN_2_ODR_AVL_3HZ_VAL 0x02
+#define ST_MAGN_2_ODR_AVL_5HZ_VAL 0x03
+#define ST_MAGN_2_ODR_AVL_10HZ_VAL 0x04
+#define ST_MAGN_2_ODR_AVL_20HZ_VAL 0x05
+#define ST_MAGN_2_ODR_AVL_40HZ_VAL 0x06
+#define ST_MAGN_2_ODR_AVL_80HZ_VAL 0x07
+#define ST_MAGN_2_PW_ADDR 0x22
+#define ST_MAGN_2_PW_MASK 0x03
+#define ST_MAGN_2_PW_N_BIT 2
+#define ST_MAGN_2_PW_ON 0x00
+#define ST_MAGN_2_PW_OFF 0x03
+#define ST_MAGN_2_FS_N_BIT 2
+#define ST_MAGN_2_FS_ADDR 0x21
+#define ST_MAGN_2_FS_MASK 0x60
+#define ST_MAGN_2_FS_AVL_4000_VAL 0x00
+#define ST_MAGN_2_FS_AVL_8000_VAL 0x01
+#define ST_MAGN_2_FS_AVL_10000_VAL 0x02
+#define ST_MAGN_2_FS_AVL_4000_GAIN 430
+#define ST_MAGN_2_FS_AVL_8000_GAIN 230
+#define ST_MAGN_2_FS_AVL_10000_GAIN 230
+#define ST_MAGN_2_MULTIREAD_BIT false
+#define ST_MAGN_2_OUT_X_L_ADDR 0x28
+#define ST_MAGN_2_OUT_Y_L_ADDR 0x2a
+#define ST_MAGN_2_OUT_Z_L_ADDR 0x2c
+
+static const struct iio_chan_spec st_magn_16bit_channels[] = {
+ ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE,
+ ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_X_L_ADDR),
+ ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE,
+ ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_Y_L_ADDR),
+ ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE,
+ ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_Z_L_ADDR),
+ IIO_CHAN_SOFT_TIMESTAMP(3)
+};
+
+static const struct iio_chan_spec st_magn_2_16bit_channels[] = {
+ ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE,
+ ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_X_L_ADDR),
+ ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE,
+ ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_Y_L_ADDR),
+ ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE,
+ ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_Z_L_ADDR),
+ IIO_CHAN_SOFT_TIMESTAMP(3)
+};
+
+static const struct st_sensors st_magn_sensors[] = {
+ {
+ .wai = ST_MAGN_1_WAI_EXP,
+ .ch = (struct iio_chan_spec *)st_magn_16bit_channels,
+ .odr = {
+ .addr = ST_MAGN_1_ODR_ADDR,
+ .mask = ST_MAGN_1_ODR_MASK,
+ .num_bit = ST_MAGN_1_ODR_N_BIT,
+ .odr_avl = {
+ { 1, ST_MAGN_1_ODR_AVL_1HZ_VAL, },
+ { 2, ST_MAGN_1_ODR_AVL_2HZ_VAL, },
+ { 3, ST_MAGN_1_ODR_AVL_3HZ_VAL, },
+ { 8, ST_MAGN_1_ODR_AVL_8HZ_VAL, },
+ { 15, ST_MAGN_1_ODR_AVL_15HZ_VAL, },
+ { 30, ST_MAGN_1_ODR_AVL_30HZ_VAL, },
+ { 75, ST_MAGN_1_ODR_AVL_75HZ_VAL, },
+ { 220, ST_MAGN_1_ODR_AVL_220HZ_VAL, },
+ },
+ },
+ .pw = {
+ .addr = ST_MAGN_1_PW_ADDR,
+ .mask = ST_MAGN_1_PW_MASK,
+ .num_bit = ST_MAGN_1_PW_N_BIT,
+ .value_on = ST_MAGN_1_PW_ON,
+ .value_off = ST_MAGN_1_PW_OFF,
+ },
+ .fs = {
+ .addr = ST_MAGN_1_FS_ADDR,
+ .mask = ST_MAGN_1_FS_MASK,
+ .num_bit = ST_MAGN_1_FS_N_BIT,
+ .fs_avl = {
+ [0] = {
+ .num = ST_MAGN_FS_AVL_1300MG,
+ .value = ST_MAGN_1_FS_AVL_1300_VAL,
+ .gain = ST_MAGN_1_FS_AVL_1300_GAIN_XY,
+ .gain2 = ST_MAGN_1_FS_AVL_1300_GAIN_Z,
+ },
+ [1] = {
+ .num = ST_MAGN_FS_AVL_1900MG,
+ .value = ST_MAGN_1_FS_AVL_1900_VAL,
+ .gain = ST_MAGN_1_FS_AVL_1900_GAIN_XY,
+ .gain2 = ST_MAGN_1_FS_AVL_1900_GAIN_Z,
+ },
+ [2] = {
+ .num = ST_MAGN_FS_AVL_2500MG,
+ .value = ST_MAGN_1_FS_AVL_2500_VAL,
+ .gain = ST_MAGN_1_FS_AVL_2500_GAIN_XY,
+ .gain2 = ST_MAGN_1_FS_AVL_2500_GAIN_Z,
+ },
+ [3] = {
+ .num = ST_MAGN_FS_AVL_4000MG,
+ .value = ST_MAGN_1_FS_AVL_4000_VAL,
+ .gain = ST_MAGN_1_FS_AVL_4000_GAIN_XY,
+ .gain2 = ST_MAGN_1_FS_AVL_4000_GAIN_Z,
+ },
+ [4] = {
+ .num = ST_MAGN_FS_AVL_4700MG,
+ .value = ST_MAGN_1_FS_AVL_4700_VAL,
+ .gain = ST_MAGN_1_FS_AVL_4700_GAIN_XY,
+ .gain2 = ST_MAGN_1_FS_AVL_4700_GAIN_Z,
+ },
+ [5] = {
+ .num = ST_MAGN_FS_AVL_5600MG,
+ .value = ST_MAGN_1_FS_AVL_5600_VAL,
+ .gain = ST_MAGN_1_FS_AVL_5600_GAIN_XY,
+ .gain2 = ST_MAGN_1_FS_AVL_5600_GAIN_Z,
+ },
+ [6] = {
+ .num = ST_MAGN_FS_AVL_8100MG,
+ .value = ST_MAGN_1_FS_AVL_8100_VAL,
+ .gain = ST_MAGN_1_FS_AVL_8100_GAIN_XY,
+ .gain2 = ST_MAGN_1_FS_AVL_8100_GAIN_Z,
+ },
+ },
+ },
+ .multi_read_bit = ST_MAGN_1_MULTIREAD_BIT,
+ .bootime = 2,
+ },
+ {
+ .wai = ST_MAGN_2_WAI_EXP,
+ .ch = (struct iio_chan_spec *)st_magn_2_16bit_channels,
+ .odr = {
+ .addr = ST_MAGN_2_ODR_ADDR,
+ .mask = ST_MAGN_2_ODR_MASK,
+ .num_bit = ST_MAGN_2_ODR_N_BIT,
+ .odr_avl = {
+ { 1, ST_MAGN_2_ODR_AVL_1HZ_VAL, },
+ { 2, ST_MAGN_2_ODR_AVL_2HZ_VAL, },
+ { 3, ST_MAGN_2_ODR_AVL_3HZ_VAL, },
+ { 5, ST_MAGN_2_ODR_AVL_5HZ_VAL, },
+ { 10, ST_MAGN_2_ODR_AVL_10HZ_VAL, },
+ { 20, ST_MAGN_2_ODR_AVL_20HZ_VAL, },
+ { 40, ST_MAGN_2_ODR_AVL_40HZ_VAL, },
+ { 80, ST_MAGN_2_ODR_AVL_80HZ_VAL, },
+ },
+ },
+ .pw = {
+ .addr = ST_MAGN_2_PW_ADDR,
+ .mask = ST_MAGN_2_PW_MASK,
+ .num_bit = ST_MAGN_2_PW_N_BIT,
+ .value_on = ST_MAGN_2_PW_ON,
+ .value_off = ST_MAGN_2_PW_OFF,
+ },
+ .fs = {
+ .addr = ST_MAGN_2_FS_ADDR,
+ .mask = ST_MAGN_2_FS_MASK,
+ .num_bit = ST_MAGN_2_FS_N_BIT,
+ .fs_avl = {
+ [0] = {
+ .num = ST_MAGN_FS_AVL_4000MG,
+ .value = ST_MAGN_2_FS_AVL_4000_VAL,
+ .gain = ST_MAGN_2_FS_AVL_4000_GAIN,
+ },
+ [1] = {
+ .num = ST_MAGN_FS_AVL_8000MG,
+ .value = ST_MAGN_2_FS_AVL_8000_VAL,
+ .gain = ST_MAGN_2_FS_AVL_8000_GAIN,
+ },
+ [2] = {
+ .num = ST_MAGN_FS_AVL_10000MG,
+ .value = ST_MAGN_2_FS_AVL_10000_VAL,
+ .gain = ST_MAGN_2_FS_AVL_10000_GAIN,
+ },
+ },
+ },
+ .multi_read_bit = ST_MAGN_2_MULTIREAD_BIT,
+ .bootime = 2,
+ },
+};
+
+static int st_magn_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *ch, int *val,
+ int *val2, long mask)
+{
+ int err;
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW:
+ mutex_lock(&indio_dev->mlock);
+ if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
+ err = -EBUSY;
+ goto read_error;
+ } else {
+ err = st_sensors_set_enable(indio_dev,
+ &st_magn_sensors[mdata->index], true);
+ if (err < 0)
+ goto read_error;
+
+ msleep((st_magn_sensors[mdata->index].bootime * 1000)
+ / mdata->odr);
+ err = st_sensors_read_axis_data(indio_dev,
+ ch->address, val);
+ if (err < 0)
+ goto read_error;
+
+ *val = *val >> ch->scan_type.shift;
+ }
+ mutex_unlock(&indio_dev->mlock);
+ return IIO_VAL_INT;
+ case IIO_CHAN_INFO_SCALE:
+ *val = 0;
+ if (ch->scan_index != ST_SENSORS_SCAN_Z)
+ *val2 = mdata->current_fullscale->gain;
+ else
+ *val2 = mdata->current_fullscale->gain2;
+ return IIO_VAL_INT_PLUS_MICRO;
+ default:
+ return -EINVAL;
+ }
+
+read_error:
+ mutex_unlock(&indio_dev->mlock);
+ return err;
+}
+
+static int st_magn_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan, int val, int val2, long mask)
+{
+ int err;
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ switch (mask) {
+ case IIO_CHAN_INFO_SCALE:
+ err = st_sensors_set_fullscale_by_gain(indio_dev,
+ &st_magn_sensors[mdata->index], val2);
+ break;
+ default:
+ err = -EINVAL;
+ }
+
+ return err;
+}
+
+int st_magn_set_axis_enable(struct iio_dev *indio_dev, u8 active_bit)
+{
+ return 0;
+}
+EXPORT_SYMBOL(st_magn_set_axis_enable);
+
+static int st_magn_check_device_support(struct iio_dev *indio_dev)
+{
+ int i, err;
+ u8 wai;
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ err = mdata->tf->read_byte(&mdata->tb, mdata->dev,
+ ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai);
+ if (err < 0) {
+ dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
+ goto read_wai_error;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(st_magn_sensors); i++) {
+ if (st_magn_sensors[i].wai == wai)
+ break;
+ }
+ if (i == ARRAY_SIZE(st_magn_sensors))
+ goto check_device_error;
+
+ mdata->index = i;
+
+ return i;
+
+check_device_error:
+ dev_err(&indio_dev->dev, "device not supported -> wai (0x%x).\n", wai);
+ err = -ENODEV;
+read_wai_error:
+ return err;
+}
+
+int st_magn_set_enable(struct iio_dev *indio_dev, bool enable)
+{
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ return st_sensors_set_enable(indio_dev,
+ &st_magn_sensors[mdata->index], enable);
+}
+EXPORT_SYMBOL(st_magn_set_enable);
+
+static ssize_t st_magn_sysfs_set_sampling_frequency(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ int err;
+ unsigned int odr;
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ err = kstrtoint(buf, 10, &odr);
+ if (err < 0)
+ goto conversion_error;
+
+ mutex_lock(&indio_dev->mlock);
+ err = st_sensors_set_odr(indio_dev,
+ &st_magn_sensors[mdata->index], odr);
+ mutex_unlock(&indio_dev->mlock);
+
+conversion_error:
+ return err < 0 ? err : size;
+}
+
+static ssize_t st_magn_sysfs_get_sampling_frequency(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ return sprintf(buf, "%d\n", mdata->odr);
+}
+
+static ssize_t st_magn_sysfs_scale_available(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ return st_sensors_get_scale_avl(indio_dev,
+ st_magn_sensors[mdata->index].fs.fs_avl, buf);
+}
+
+static ssize_t st_magn_sysfs_sampling_frequency_available(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ return st_sensors_get_sampling_frequency_avl(indio_dev,
+ st_magn_sensors[mdata->index].odr.odr_avl, buf);
+}
+
+static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(st_magn_sysfs_sampling_frequency_available);
+
+static IIO_DEVICE_ATTR(in_magn_scale_available, S_IRUGO,
+ st_magn_sysfs_scale_available, NULL , 0);
+
+static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
+ st_magn_sysfs_get_sampling_frequency,
+ st_magn_sysfs_set_sampling_frequency);
+
+static struct attribute *st_magn_attributes[] = {
+ &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
+ &iio_dev_attr_in_magn_scale_available.dev_attr.attr,
+ &iio_dev_attr_sampling_frequency.dev_attr.attr,
+ NULL,
+};
+
+static const struct attribute_group st_magn_attribute_group = {
+ .attrs = st_magn_attributes,
+};
+
+static const struct iio_info magn_info = {
+ .driver_module = THIS_MODULE,
+ .attrs = &st_magn_attribute_group,
+ .read_raw = &st_magn_read_raw,
+ .write_raw = &st_magn_write_raw,
+};
+
+int st_magn_common_probe(struct iio_dev *indio_dev)
+{
+ int err;
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->info = &magn_info;
+
+ err = st_magn_check_device_support(indio_dev);
+ if (err < 0)
+ goto st_magn_common_probe_error;
+
+ mdata->multiread_bit = st_magn_sensors[mdata->index].multi_read_bit;
+ indio_dev->channels = st_magn_sensors[mdata->index].ch;
+ indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
+
+ mdata->current_fullscale = (struct st_sensor_fullscale_avl *)
+ &st_magn_sensors[mdata->index].fs.fs_avl[0];
+ mdata->odr = st_magn_sensors[mdata->index].odr.odr_avl[0].hz;
+
+ err = st_sensors_init_sensor(indio_dev,
+ &st_magn_sensors[mdata->index]);
+ if (err < 0)
+ goto st_magn_common_probe_error;
+
+ if (mdata->get_irq_data_ready(indio_dev) > 0) {
+ err = st_magn_allocate_ring(indio_dev);
+ if (err < 0)
+ goto st_magn_common_probe_error;
+ err = st_sensors_allocate_trigger(indio_dev, NULL, NULL);
+ if (err < 0)
+ goto st_magn_probe_trigger_error;
+ }
+
+ err = iio_device_register(indio_dev);
+ if (err)
+ goto st_magn_device_register_error;
+
+ return err;
+
+st_magn_device_register_error:
+ if (mdata->get_irq_data_ready(indio_dev) > 0)
+ st_sensors_deallocate_trigger(indio_dev);
+st_magn_probe_trigger_error:
+ if (mdata->get_irq_data_ready(indio_dev) > 0)
+ st_magn_deallocate_ring(indio_dev);
+st_magn_common_probe_error:
+ return err;
+}
+EXPORT_SYMBOL(st_magn_common_probe);
+
+void st_magn_common_remove(struct iio_dev *indio_dev)
+{
+ struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+ iio_device_unregister(indio_dev);
+ if (mdata->get_irq_data_ready(indio_dev) > 0) {
+ st_sensors_deallocate_trigger(indio_dev);
+ st_magn_deallocate_ring(indio_dev);
+ }
+ iio_device_free(indio_dev);
+}
+EXPORT_SYMBOL(st_magn_common_remove);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics magnetometers driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
new file mode 100644
index 0000000..d090104
--- /dev/null
+++ b/drivers/iio/magnetometer/st_magn_i2c.c
@@ -0,0 +1,81 @@
+/*
+ * STMicroelectronics magnetometers driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+
+#include <linux/iio/magnetometer/st_magn.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+static int st_magn_i2c_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct iio_dev *indio_dev;
+ struct st_sensor_data *mdata;
+ int err;
+
+ indio_dev = iio_device_alloc(sizeof(*mdata));
+ if (indio_dev == NULL) {
+ err = -ENOMEM;
+ goto iio_device_alloc_error;
+ }
+
+ mdata = iio_priv(indio_dev);
+ mdata->dev = &client->dev;
+
+ st_sensors_i2c_configure(indio_dev, client, mdata);
+
+ err = st_magn_common_probe(indio_dev);
+ if (err < 0)
+ goto st_magn_common_probe_error;
+
+ return 0;
+
+st_magn_common_probe_error:
+ iio_device_free(indio_dev);
+iio_device_alloc_error:
+ return err;
+}
+
+static int st_magn_i2c_remove(struct i2c_client *client)
+{
+ struct iio_dev *indio_dev = i2c_get_clientdata(client);
+ st_magn_common_remove(indio_dev);
+
+ return 0;
+}
+
+static const struct i2c_device_id st_magn_id_table[] = {
+ { LSM303DLHC_MAGN_DEV_NAME },
+ { LSM303DLM_MAGN_DEV_NAME },
+ { LIS3MDL_MAGN_DEV_NAME },
+ {},
+};
+MODULE_DEVICE_TABLE(i2c, st_magn_id_table);
+
+static struct i2c_driver st_magn_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "st-magn-i2c",
+ },
+ .probe = st_magn_i2c_probe,
+ .remove = st_magn_i2c_remove,
+ .id_table = st_magn_id_table,
+};
+module_i2c_driver(st_magn_driver);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics magnetometers i2c driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c
new file mode 100644
index 0000000..3d3cdc7
--- /dev/null
+++ b/drivers/iio/magnetometer/st_magn_spi.c
@@ -0,0 +1,80 @@
+/*
+ * STMicroelectronics magnetometers driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/spi/spi.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+
+#include <linux/iio/magnetometer/st_magn.h>
+#include <linux/iio/common/st_sensors.h>
+
+
+static int st_magn_spi_probe(struct spi_device *spi)
+{
+ struct iio_dev *indio_dev;
+ struct st_sensor_data *mdata;
+ int err;
+
+ indio_dev = iio_device_alloc(sizeof(*mdata));
+ if (indio_dev == NULL) {
+ err = -ENOMEM;
+ goto iio_device_alloc_error;
+ }
+
+ mdata = iio_priv(indio_dev);
+ mdata->dev = &spi->dev;
+
+ st_sensors_spi_configure(indio_dev, spi, mdata);
+
+ err = st_magn_common_probe(indio_dev);
+ if (err < 0)
+ goto st_magn_common_probe_error;
+
+ return 0;
+
+st_magn_common_probe_error:
+ iio_device_free(indio_dev);
+iio_device_alloc_error:
+ return err;
+}
+
+static int st_magn_spi_remove(struct spi_device *spi)
+{
+ struct iio_dev *indio_dev = spi_get_drvdata(spi);
+ st_magn_common_remove(indio_dev);
+
+ return 0;
+}
+
+static const struct spi_device_id st_magn_id_table[] = {
+ { LSM303DLHC_MAGN_DEV_NAME },
+ { LSM303DLM_MAGN_DEV_NAME },
+ { LIS3MDL_MAGN_DEV_NAME },
+ {},
+};
+MODULE_DEVICE_TABLE(spi, st_magn_id_table);
+
+static struct spi_driver st_magn_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "st-magn-spi",
+ },
+ .probe = st_magn_spi_probe,
+ .remove = st_magn_spi_remove,
+ .id_table = st_magn_id_table,
+};
+module_spi_driver(st_magn_driver);
+
+MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics magnetometers spi driver");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/iio/magnetometer/st_magn.h b/include/linux/iio/magnetometer/st_magn.h
new file mode 100644
index 0000000..bba0d1d
--- /dev/null
+++ b/include/linux/iio/magnetometer/st_magn.h
@@ -0,0 +1,47 @@
+/*
+ * STMicroelectronics magnetometers driver
+ *
+ * Copyright 2012 STMicroelectronics Inc.
+ *
+ * Denis Ciocca <denis.ciocca@st.com>
+ * v. 1.0.0
+ * Licensed under the GPL-2.
+ */
+
+#ifndef ST_MAGN_H
+#define ST_MAGN_H
+
+#include <linux/types.h>
+#include "../common/st_sensors.h"
+
+#define LSM303DLHC_MAGN_DEV_NAME "lsm303dlhc_magn"
+#define LSM303DLM_MAGN_DEV_NAME "lsm303dlm_magn"
+#define LIS3MDL_MAGN_DEV_NAME "lis3mdl"
+
+int st_magn_common_probe(struct iio_dev *indio_dev);
+void st_magn_common_remove(struct iio_dev *indio_dev);
+int st_magn_set_axis_enable(struct iio_dev *indio_dev, u8 active_bit);
+int st_magn_set_enable(struct iio_dev *indio_dev, bool enable);
+
+#ifdef CONFIG_IIO_ST_MAGN_3AXIS_TRIGGERED_BUFFER
+int st_magn_allocate_ring(struct iio_dev *indio_dev);
+void st_magn_deallocate_ring(struct iio_dev *indio_dev);
+#else /* CONFIG_IIO_ST_MAGN_3AXIS_TRIGGERED_BUFFER */
+static inline int st_magn_probe_trigger(struct iio_dev *indio_dev, int irq)
+{
+ return 0;
+}
+static inline void st_magn_remove_trigger(struct iio_dev *indio_dev, int irq)
+{
+ return;
+}
+static inline int st_magn_allocate_ring(struct iio_dev *indio_dev)
+{
+ return 0;
+}
+static inline void st_magn_deallocate_ring(struct iio_dev *indio_dev)
+{
+}
+#endif /* CONFIG_IIO_ST_MAGN_3AXIS_TRIGGERED_BUFFER */
+
+#endif /* ST_MAGN_H */
--
1.7.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: iio: STMicroelectronics iio drivers
2013-01-15 8:30 iio: STMicroelectronics iio drivers Denis CIOCCA
` (3 preceding siblings ...)
2013-01-15 8:31 ` [PATCH 4/9] iio:magnetometer: Add STMicroelectronics magnetometers driver Denis CIOCCA
@ 2013-01-15 22:33 ` Jonathan Cameron
2013-01-15 23:01 ` Jonathan Cameron
4 siblings, 1 reply; 20+ messages in thread
From: Jonathan Cameron @ 2013-01-15 22:33 UTC (permalink / raw)
To: Denis CIOCCA; +Cc: lars, linux-iio
On 01/15/2013 08:30 AM, Denis CIOCCA wrote:
> Hi Jonathan,
>
> I sent to you the new patches to fix the u8 casting and a little bugfix in the header files (functions within #ifdef).
> Thanks,
>
> Denis
>
>
Denis,
Just been running some build tests on this. You need to
do a lot more testing of the various possible combinations
I think. Right now I can't build and so far I'm not entirely
sure why.
CHECK drivers/iio/accel/st_accel_i2c.c
drivers/iio/accel/st_accel_i2c.c:38:9: error: undefined identifier 'st_sensors_i2c_configure'
CC [M] drivers/iio/accel/st_accel_i2c.o
drivers/iio/accel/st_accel_i2c.c: In function 'st_accel_i2c_probe':
drivers/iio/accel/st_accel_i2c.c:38:2: error: implicit declaration of function 'st_sensors_i2c_configure'
make[3]: *** [drivers/iio/accel/st_accel_i2c.o] Error 1
make[2]: *** [drivers/iio/accel] Error 2
make[1]: *** [drivers/iio] Error 2
make: *** [drivers] Error 2
For reasons that aren't immediately clear ifdef CONFIG statements don't
seem to be working...
I also suspect we have too many complex build options in here in the first
place. It's probably not unreasonable for instance to build in buffered support
if buffering is enabled in general for IIO rather than explicitly.
Jonathan
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: iio: STMicroelectronics iio drivers
2013-01-15 22:33 ` iio: STMicroelectronics iio drivers Jonathan Cameron
@ 2013-01-15 23:01 ` Jonathan Cameron
2013-01-15 23:06 ` Jonathan Cameron
2013-01-16 8:48 ` Jonathan Cameron
0 siblings, 2 replies; 20+ messages in thread
From: Jonathan Cameron @ 2013-01-15 23:01 UTC (permalink / raw)
To: Denis CIOCCA; +Cc: lars, linux-iio
On 01/15/2013 10:33 PM, Jonathan Cameron wrote:
> On 01/15/2013 08:30 AM, Denis CIOCCA wrote:
>> Hi Jonathan,
>>
>> I sent to you the new patches to fix the u8 casting and a little bugfix in the header files (functions within #ifdef).
>> Thanks,
>>
>> Denis
>>
>>
> Denis,
>
> Just been running some build tests on this. You need to
> do a lot more testing of the various possible combinations
> I think. Right now I can't build and so far I'm not entirely
> sure why.
>
> CHECK drivers/iio/accel/st_accel_i2c.c
> drivers/iio/accel/st_accel_i2c.c:38:9: error: undefined identifier 'st_sensors_i2c_configure'
> CC [M] drivers/iio/accel/st_accel_i2c.o
> drivers/iio/accel/st_accel_i2c.c: In function 'st_accel_i2c_probe':
> drivers/iio/accel/st_accel_i2c.c:38:2: error: implicit declaration of function 'st_sensors_i2c_configure'
> make[3]: *** [drivers/iio/accel/st_accel_i2c.o] Error 1
> make[2]: *** [drivers/iio/accel] Error 2
> make[1]: *** [drivers/iio] Error 2
> make: *** [drivers] Error 2
>
> For reasons that aren't immediately clear ifdef CONFIG statements don't
> seem to be working...
Of course, I had relevant bits compiling as modules.
I think we should rethink the module structure here so that this mess doesn't occur.
One core driver with multiple files seems right to me.
so a make file looking something like.
obj-$(CONFIG_IIO_ST_SENSORS_CORE) += st_sensors.o
st_sensors-y := st_sensors_core.o
st_sensors-$(CONFIG_IIO_ST_SENSORS_I2C) += st_sensors_i2c.o
st_sensors-$(CONFIG_IIO_ST_SENSORS_SPI) += st_sensors_spi.o
st_sensors-$(CONFIG_IIO_ST_SENSORS_TRIGGERED_BUFFER) += st_sensors_trigger.o st_sensors_buffer.o
and a kconfig where all by the sensors_core entry are boolean.
Similarly for the drivers. Thus we end up with 4 modules rather than dozens and
hopefully the build logic will work fine in all cases.
Also note that I think you can't have buffering for accel and not gyro etc.
>
> I also suspect we have too many complex build options in here in the first
> place. It's probably not unreasonable for instance to build in buffered support
> if buffering is enabled in general for IIO rather than explicitly.
>
> Jonathan
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: iio: STMicroelectronics iio drivers
2013-01-15 23:01 ` Jonathan Cameron
@ 2013-01-15 23:06 ` Jonathan Cameron
2013-01-16 8:48 ` Jonathan Cameron
1 sibling, 0 replies; 20+ messages in thread
From: Jonathan Cameron @ 2013-01-15 23:06 UTC (permalink / raw)
To: Denis CIOCCA; +Cc: lars, linux-iio
On 01/15/2013 11:01 PM, Jonathan Cameron wrote:
> On 01/15/2013 10:33 PM, Jonathan Cameron wrote:
>> On 01/15/2013 08:30 AM, Denis CIOCCA wrote:
>>> Hi Jonathan,
>>>
>>> I sent to you the new patches to fix the u8 casting and a little bugfix in the header files (functions within #ifdef).
>>> Thanks,
>>>
>>> Denis
>>>
>>>
>> Denis,
>>
>> Just been running some build tests on this. You need to
>> do a lot more testing of the various possible combinations
>> I think. Right now I can't build and so far I'm not entirely
>> sure why.
>>
>> CHECK drivers/iio/accel/st_accel_i2c.c
>> drivers/iio/accel/st_accel_i2c.c:38:9: error: undefined identifier 'st_sensors_i2c_configure'
>> CC [M] drivers/iio/accel/st_accel_i2c.o
>> drivers/iio/accel/st_accel_i2c.c: In function 'st_accel_i2c_probe':
>> drivers/iio/accel/st_accel_i2c.c:38:2: error: implicit declaration of function 'st_sensors_i2c_configure'
>> make[3]: *** [drivers/iio/accel/st_accel_i2c.o] Error 1
>> make[2]: *** [drivers/iio/accel] Error 2
>> make[1]: *** [drivers/iio] Error 2
>> make: *** [drivers] Error 2
>>
>> For reasons that aren't immediately clear ifdef CONFIG statements don't
>> seem to be working...
>
> Of course, I had relevant bits compiling as modules.
>
> I think we should rethink the module structure here so that this mess doesn't occur.
> One core driver with multiple files seems right to me.
>
> so a make file looking something like.
> obj-$(CONFIG_IIO_ST_SENSORS_CORE) += st_sensors.o
> st_sensors-y := st_sensors_core.o
> st_sensors-$(CONFIG_IIO_ST_SENSORS_I2C) += st_sensors_i2c.o
> st_sensors-$(CONFIG_IIO_ST_SENSORS_SPI) += st_sensors_spi.o
> st_sensors-$(CONFIG_IIO_ST_SENSORS_TRIGGERED_BUFFER) += st_sensors_trigger.o st_sensors_buffer.o
>
> and a kconfig where all by the sensors_core entry are boolean.
>
> Similarly for the drivers. Thus we end up with 4 modules rather than dozens and
> hopefully the build logic will work fine in all cases.
Ah, can't have two module init's so need separate i2c and spi drivers for each type
+ a core module. Sorry, didn't think that through until I tried it out.
Anyhow, unify everything under common/st_sensors + deal with the problems different
combinations can give.
Jonathan
>
> Also note that I think you can't have buffering for accel and not gyro etc.
>
>
>
>>
>> I also suspect we have too many complex build options in here in the first
>> place. It's probably not unreasonable for instance to build in buffered support
>> if buffering is enabled in general for IIO rather than explicitly.
>>
>> Jonathan
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: iio: STMicroelectronics iio drivers
2013-01-15 23:01 ` Jonathan Cameron
2013-01-15 23:06 ` Jonathan Cameron
@ 2013-01-16 8:48 ` Jonathan Cameron
2013-01-16 11:48 ` Denis CIOCCA
1 sibling, 1 reply; 20+ messages in thread
From: Jonathan Cameron @ 2013-01-16 8:48 UTC (permalink / raw)
To: Denis CIOCCA; +Cc: lars, linux-iio
On 15/01/13 23:01, Jonathan Cameron wrote:
> On 01/15/2013 10:33 PM, Jonathan Cameron wrote:
>> On 01/15/2013 08:30 AM, Denis CIOCCA wrote:
>>> Hi Jonathan,
>>>
>>> I sent to you the new patches to fix the u8 casting and a little bugfix in the header files (functions within #ifdef).
>>> Thanks,
>>>
>>> Denis
>>>
>>>
>> Denis,
>>
>> Just been running some build tests on this. You need to
>> do a lot more testing of the various possible combinations
>> I think. Right now I can't build and so far I'm not entirely
>> sure why.
>>
>> CHECK drivers/iio/accel/st_accel_i2c.c
>> drivers/iio/accel/st_accel_i2c.c:38:9: error: undefined identifier 'st_sensors_i2c_configure'
>> CC [M] drivers/iio/accel/st_accel_i2c.o
>> drivers/iio/accel/st_accel_i2c.c: In function 'st_accel_i2c_probe':
>> drivers/iio/accel/st_accel_i2c.c:38:2: error: implicit declaration of function 'st_sensors_i2c_configure'
>> make[3]: *** [drivers/iio/accel/st_accel_i2c.o] Error 1
>> make[2]: *** [drivers/iio/accel] Error 2
>> make[1]: *** [drivers/iio] Error 2
>> make: *** [drivers] Error 2
>>
>> For reasons that aren't immediately clear ifdef CONFIG statements don't
>> seem to be working...
>
> Of course, I had relevant bits compiling as modules.
>
> I think we should rethink the module structure here so that this mess doesn't occur.
> One core driver with multiple files seems right to me.
>
> so a make file looking something like.
> obj-$(CONFIG_IIO_ST_SENSORS_CORE) += st_sensors.o
> st_sensors-y := st_sensors_core.o
> st_sensors-$(CONFIG_IIO_ST_SENSORS_I2C) += st_sensors_i2c.o
> st_sensors-$(CONFIG_IIO_ST_SENSORS_SPI) += st_sensors_spi.o
> st_sensors-$(CONFIG_IIO_ST_SENSORS_TRIGGERED_BUFFER) += st_sensors_trigger.o st_sensors_buffer.o
>
> and a kconfig where all by the sensors_core entry are boolean.
>
> Similarly for the drivers. Thus we end up with 4 modules rather than dozens and
> hopefully the build logic will work fine in all cases.
>
> Also note that I think you can't have buffering for accel and not gyro etc.
>
Thinking a little more on this, I can see why you'd want separate
library drivers for the i2c and spi parts. You would however benefit
from pulling the bits in the ifdefs out to separate headers without any
protection and then including them only where needed. The triggered
buffer bit still wants to be in the main st_sensors module though via
the boolean suggestion above. You may even want to hide away the
config options for the library support (don't give them a description
and they won't show up in make menuconfig etc). I can't see why
people would want to manually select them without the drivers.
From the buffered point of view, I'd go with the same trick for config
that most other drivers have and make it dependent on IIO_BUFFER on the
assumption that won't be there on a stripped down system anyway and it
makes life nice and simple without any interesting issues like will be
seen here.
Jonathan
>
>
>>
>> I also suspect we have too many complex build options in here in the first
>> place. It's probably not unreasonable for instance to build in buffered support
>> if buffering is enabled in general for IIO rather than explicitly.
>>
>> Jonathan
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: iio: STMicroelectronics iio drivers
2013-01-16 8:48 ` Jonathan Cameron
@ 2013-01-16 11:48 ` Denis CIOCCA
2013-01-16 12:25 ` Jonathan Cameron
0 siblings, 1 reply; 20+ messages in thread
From: Denis CIOCCA @ 2013-01-16 11:48 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: lars@metafoo.de, linux-iio@vger.kernel.org
Hi Jonathan,
I'm working on the problems that you described, but why if I compile one=20
file how module the #define IIO_CONFIG_*** aren't works?
For st_sensors I modified the Kconfig removing the description and=20
changed tristate option to bool, in drivers I want to leave 4 modules=20
(if it is possible) but if I compile as module the #define don't work.
Denis
On 01/16/2013 09:48 AM, Jonathan Cameron wrote:
> On 15/01/13 23:01, Jonathan Cameron wrote:
>> On 01/15/2013 10:33 PM, Jonathan Cameron wrote:
>>> On 01/15/2013 08:30 AM, Denis CIOCCA wrote:
>>>> Hi Jonathan,
>>>>
>>>> I sent to you the new patches to fix the u8 casting and a little bugfi=
x in the header files (functions within #ifdef).
>>>> Thanks,
>>>>
>>>> Denis
>>>>
>>>>
>>> Denis,
>>>
>>> Just been running some build tests on this. You need to
>>> do a lot more testing of the various possible combinations
>>> I think. Right now I can't build and so far I'm not entirely
>>> sure why.
>>>
>>> CHECK drivers/iio/accel/st_accel_i2c.c
>>> drivers/iio/accel/st_accel_i2c.c:38:9: error: undefined identifier 'st_=
sensors_i2c_configure'
>>> CC [M] drivers/iio/accel/st_accel_i2c.o
>>> drivers/iio/accel/st_accel_i2c.c: In function 'st_accel_i2c_probe':
>>> drivers/iio/accel/st_accel_i2c.c:38:2: error: implicit declaration of f=
unction 'st_sensors_i2c_configure'
>>> make[3]: *** [drivers/iio/accel/st_accel_i2c.o] Error 1
>>> make[2]: *** [drivers/iio/accel] Error 2
>>> make[1]: *** [drivers/iio] Error 2
>>> make: *** [drivers] Error 2
>>>
>>> For reasons that aren't immediately clear ifdef CONFIG statements don't
>>> seem to be working...
>>
>> Of course, I had relevant bits compiling as modules.
>>
>> I think we should rethink the module structure here so that this mess do=
esn't occur.
>> One core driver with multiple files seems right to me.
>>
>> so a make file looking something like.
>> obj-$(CONFIG_IIO_ST_SENSORS_CORE) +=3D st_sensors.o
>> st_sensors-y :=3D st_sensors_core.o
>> st_sensors-$(CONFIG_IIO_ST_SENSORS_I2C) +=3D st_sensors_i2c.o
>> st_sensors-$(CONFIG_IIO_ST_SENSORS_SPI) +=3D st_sensors_spi.o
>> st_sensors-$(CONFIG_IIO_ST_SENSORS_TRIGGERED_BUFFER) +=3D st_sensors_tri=
gger.o st_sensors_buffer.o
>>
>> and a kconfig where all by the sensors_core entry are boolean.
>>
>> Similarly for the drivers. Thus we end up with 4 modules rather than do=
zens and
>> hopefully the build logic will work fine in all cases.
>>
>> Also note that I think you can't have buffering for accel and not gyro e=
tc.
>>
> Thinking a little more on this, I can see why you'd want separate
> library drivers for the i2c and spi parts. You would however benefit
> from pulling the bits in the ifdefs out to separate headers without any
> protection and then including them only where needed. The triggered
> buffer bit still wants to be in the main st_sensors module though via
> the boolean suggestion above. You may even want to hide away the
> config options for the library support (don't give them a description
> and they won't show up in make menuconfig etc). I can't see why
> people would want to manually select them without the drivers.
>
> From the buffered point of view, I'd go with the same trick for config
> that most other drivers have and make it dependent on IIO_BUFFER on the
> assumption that won't be there on a stripped down system anyway and it
> makes life nice and simple without any interesting issues like will be
> seen here.
>
> Jonathan
>>
>>
>>>
>>> I also suspect we have too many complex build options in here in the fi=
rst
>>> place. It's probably not unreasonable for instance to build in buffered=
support
>>> if buffering is enabled in general for IIO rather than explicitly.
>>>
>>> Jonathan
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: iio: STMicroelectronics iio drivers
2013-01-16 11:48 ` Denis CIOCCA
@ 2013-01-16 12:25 ` Jonathan Cameron
2013-01-16 13:36 ` Lars-Peter Clausen
0 siblings, 1 reply; 20+ messages in thread
From: Jonathan Cameron @ 2013-01-16 12:25 UTC (permalink / raw)
To: Denis CIOCCA; +Cc: Jonathan Cameron, lars@metafoo.de, linux-iio@vger.kernel.org
On 16/01/13 11:48, Denis CIOCCA wrote:
> Hi Jonathan,
>
> I'm working on the problems that you described, but why if I compile one
> file how module the #define IIO_CONFIG_*** aren't works?
Because ifdef will only work for booleans. There are magic tricks to do
it for either y or m but I don't think we need them here.
> For st_sensors I modified the Kconfig removing the description and
> changed tristate option to bool, in drivers I want to leave 4 modules
> (if it is possible) but if I compile as module the #define don't work.
As far as I can see there is no disadvantage in ending up with the
following modules
st_sensors (with st_sensors.h as the header)
st_sensors_i2c (with st_sensors_i2c.h as the header)
st_sensors_spi (with st_sensors_spi.h as the header)
st_accel
st_accel_i2c
st_accel_spi
st_gyro
st_gyro_i2c
st_gyro_spi
st_magnetometer
st_magnetometer_i2c
st_magnetometer_spi
What do you gain by not rolling the triggered buffer into the core
libraries at both levels? If it's enabled for anything it has to
be there for all of them afaiks. So have one boolean variable
to enable it across all st_sensors drivers.
The i2c/spi defs don't need protection if they are in their own
headers as we can guarantee they are present whenever they are
used, hence no need for ifdefs.
Jonathan
>
> Denis
>
>
> On 01/16/2013 09:48 AM, Jonathan Cameron wrote:
>> On 15/01/13 23:01, Jonathan Cameron wrote:
>>> On 01/15/2013 10:33 PM, Jonathan Cameron wrote:
>>>> On 01/15/2013 08:30 AM, Denis CIOCCA wrote:
>>>>> Hi Jonathan,
>>>>>
>>>>> I sent to you the new patches to fix the u8 casting and a little bugfix in the header files (functions within #ifdef).
>>>>> Thanks,
>>>>>
>>>>> Denis
>>>>>
>>>>>
>>>> Denis,
>>>>
>>>> Just been running some build tests on this. You need to
>>>> do a lot more testing of the various possible combinations
>>>> I think. Right now I can't build and so far I'm not entirely
>>>> sure why.
>>>>
>>>> CHECK drivers/iio/accel/st_accel_i2c.c
>>>> drivers/iio/accel/st_accel_i2c.c:38:9: error: undefined identifier 'st_sensors_i2c_configure'
>>>> CC [M] drivers/iio/accel/st_accel_i2c.o
>>>> drivers/iio/accel/st_accel_i2c.c: In function 'st_accel_i2c_probe':
>>>> drivers/iio/accel/st_accel_i2c.c:38:2: error: implicit declaration of function 'st_sensors_i2c_configure'
>>>> make[3]: *** [drivers/iio/accel/st_accel_i2c.o] Error 1
>>>> make[2]: *** [drivers/iio/accel] Error 2
>>>> make[1]: *** [drivers/iio] Error 2
>>>> make: *** [drivers] Error 2
>>>>
>>>> For reasons that aren't immediately clear ifdef CONFIG statements don't
>>>> seem to be working...
>>>
>>> Of course, I had relevant bits compiling as modules.
>>>
>>> I think we should rethink the module structure here so that this mess doesn't occur.
>>> One core driver with multiple files seems right to me.
>>>
>>> so a make file looking something like.
>>> obj-$(CONFIG_IIO_ST_SENSORS_CORE) += st_sensors.o
>>> st_sensors-y := st_sensors_core.o
>>> st_sensors-$(CONFIG_IIO_ST_SENSORS_I2C) += st_sensors_i2c.o
>>> st_sensors-$(CONFIG_IIO_ST_SENSORS_SPI) += st_sensors_spi.o
>>> st_sensors-$(CONFIG_IIO_ST_SENSORS_TRIGGERED_BUFFER) += st_sensors_trigger.o st_sensors_buffer.o
>>>
>>> and a kconfig where all by the sensors_core entry are boolean.
>>>
>>> Similarly for the drivers. Thus we end up with 4 modules rather than dozens and
>>> hopefully the build logic will work fine in all cases.
>>>
>>> Also note that I think you can't have buffering for accel and not gyro etc.
>>>
>> Thinking a little more on this, I can see why you'd want separate
>> library drivers for the i2c and spi parts. You would however benefit
>> from pulling the bits in the ifdefs out to separate headers without any
>> protection and then including them only where needed. The triggered
>> buffer bit still wants to be in the main st_sensors module though via
>> the boolean suggestion above. You may even want to hide away the
>> config options for the library support (don't give them a description
>> and they won't show up in make menuconfig etc). I can't see why
>> people would want to manually select them without the drivers.
>>
>> From the buffered point of view, I'd go with the same trick for config
>> that most other drivers have and make it dependent on IIO_BUFFER on the
>> assumption that won't be there on a stripped down system anyway and it
>> makes life nice and simple without any interesting issues like will be
>> seen here.
>>
>> Jonathan
>>>
>>>
>>>>
>>>> I also suspect we have too many complex build options in here in the first
>>>> place. It's probably not unreasonable for instance to build in buffered support
>>>> if buffering is enabled in general for IIO rather than explicitly.
>>>>
>>>> Jonathan
>>>> --
>>>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>>>> the body of a message to majordomo@vger.kernel.org
>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>
>>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: iio: STMicroelectronics iio drivers
2013-01-16 12:25 ` Jonathan Cameron
@ 2013-01-16 13:36 ` Lars-Peter Clausen
0 siblings, 0 replies; 20+ messages in thread
From: Lars-Peter Clausen @ 2013-01-16 13:36 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Denis CIOCCA, Jonathan Cameron, linux-iio@vger.kernel.org
On 01/16/2013 01:25 PM, Jonathan Cameron wrote:
> On 16/01/13 11:48, Denis CIOCCA wrote:
>> Hi Jonathan,
>>
>> I'm working on the problems that you described, but why if I compile one
>> file how module the #define IIO_CONFIG_*** aren't works?
> Because ifdef will only work for booleans. There are magic tricks to do
> it for either y or m but I don't think we need them here.
>
>> For st_sensors I modified the Kconfig removing the description and
>> changed tristate option to bool, in drivers I want to leave 4 modules
>> (if it is possible) but if I compile as module the #define don't work.
> As far as I can see there is no disadvantage in ending up with the following
> modules
>
> st_sensors (with st_sensors.h as the header)
> st_sensors_i2c (with st_sensors_i2c.h as the header)
> st_sensors_spi (with st_sensors_spi.h as the header)
>
> st_accel
> st_accel_i2c
> st_accel_spi
>
> st_gyro
> st_gyro_i2c
> st_gyro_spi
>
> st_magnetometer
> st_magnetometer_i2c
> st_magnetometer_spi
As for the Kconfig entries what I would recommend doing is to have only one
user-selectable Kconfig option per driver. I2C, SPI and buffer support can
be auto-enabled if their dependencies are met. E.g. SPI support is enabled
if the kernel has SPI master support.
The Kconfig entry for the common code should not be user selectable, since
it doesn't do anything on it's own, just let the driver Kconfig entries
select it.
>
> What do you gain by not rolling the triggered buffer into the core
> libraries at both levels? If it's enabled for anything it has to
> be there for all of them afaiks. So have one boolean variable
> to enable it across all st_sensors drivers.
> The i2c/spi defs don't need protection if they are in their own
> headers as we can guarantee they are present whenever they are
> used, hence no need for ifdefs.
>
> Jonathan
>>
>> Denis
>>
>>
>> On 01/16/2013 09:48 AM, Jonathan Cameron wrote:
>>> On 15/01/13 23:01, Jonathan Cameron wrote:
>>>> On 01/15/2013 10:33 PM, Jonathan Cameron wrote:
>>>>> On 01/15/2013 08:30 AM, Denis CIOCCA wrote:
>>>>>> Hi Jonathan,
>>>>>>
>>>>>> I sent to you the new patches to fix the u8 casting and a little
>>>>>> bugfix in the header files (functions within #ifdef).
>>>>>> Thanks,
>>>>>>
>>>>>> Denis
>>>>>>
>>>>>>
>>>>> Denis,
>>>>>
>>>>> Just been running some build tests on this. You need to
>>>>> do a lot more testing of the various possible combinations
>>>>> I think. Right now I can't build and so far I'm not entirely
>>>>> sure why.
>>>>>
>>>>> CHECK drivers/iio/accel/st_accel_i2c.c
>>>>> drivers/iio/accel/st_accel_i2c.c:38:9: error: undefined identifier
>>>>> 'st_sensors_i2c_configure'
>>>>> CC [M] drivers/iio/accel/st_accel_i2c.o
>>>>> drivers/iio/accel/st_accel_i2c.c: In function 'st_accel_i2c_probe':
>>>>> drivers/iio/accel/st_accel_i2c.c:38:2: error: implicit declaration of
>>>>> function 'st_sensors_i2c_configure'
>>>>> make[3]: *** [drivers/iio/accel/st_accel_i2c.o] Error 1
>>>>> make[2]: *** [drivers/iio/accel] Error 2
>>>>> make[1]: *** [drivers/iio] Error 2
>>>>> make: *** [drivers] Error 2
>>>>>
>>>>> For reasons that aren't immediately clear ifdef CONFIG statements don't
>>>>> seem to be working...
>>>>
>>>> Of course, I had relevant bits compiling as modules.
>>>>
>>>> I think we should rethink the module structure here so that this mess
>>>> doesn't occur.
>>>> One core driver with multiple files seems right to me.
>>>>
>>>> so a make file looking something like.
>>>> obj-$(CONFIG_IIO_ST_SENSORS_CORE) += st_sensors.o
>>>> st_sensors-y := st_sensors_core.o
>>>> st_sensors-$(CONFIG_IIO_ST_SENSORS_I2C) += st_sensors_i2c.o
>>>> st_sensors-$(CONFIG_IIO_ST_SENSORS_SPI) += st_sensors_spi.o
>>>> st_sensors-$(CONFIG_IIO_ST_SENSORS_TRIGGERED_BUFFER) +=
>>>> st_sensors_trigger.o st_sensors_buffer.o
>>>>
>>>> and a kconfig where all by the sensors_core entry are boolean.
>>>>
>>>> Similarly for the drivers. Thus we end up with 4 modules rather than
>>>> dozens and
>>>> hopefully the build logic will work fine in all cases.
>>>>
>>>> Also note that I think you can't have buffering for accel and not gyro etc.
>>>>
>>> Thinking a little more on this, I can see why you'd want separate
>>> library drivers for the i2c and spi parts. You would however benefit
>>> from pulling the bits in the ifdefs out to separate headers without any
>>> protection and then including them only where needed. The triggered
>>> buffer bit still wants to be in the main st_sensors module though via
>>> the boolean suggestion above. You may even want to hide away the
>>> config options for the library support (don't give them a description
>>> and they won't show up in make menuconfig etc). I can't see why
>>> people would want to manually select them without the drivers.
>>>
>>> From the buffered point of view, I'd go with the same trick for config
>>> that most other drivers have and make it dependent on IIO_BUFFER on the
>>> assumption that won't be there on a stripped down system anyway and it
>>> makes life nice and simple without any interesting issues like will be
>>> seen here.
>>>
>>> Jonathan
>>>>
>>>>
>>>>>
>>>>> I also suspect we have too many complex build options in here in the first
>>>>> place. It's probably not unreasonable for instance to build in buffered
>>>>> support
>>>>> if buffering is enabled in general for IIO rather than explicitly.
>>>>>
>>>>> Jonathan
>>>>> --
>>>>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>>>>> the body of a message to majordomo@vger.kernel.org
>>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>>
>>>> --
>>>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>>>> the body of a message to majordomo@vger.kernel.org
>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>
>>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/9] iio:common: Add STMicroelectronics common library
2013-01-15 8:30 ` [PATCH 1/9] iio:common: Add STMicroelectronics common library Denis CIOCCA
@ 2013-01-16 14:07 ` Lars-Peter Clausen
2013-01-16 16:30 ` Denis CIOCCA
2013-01-16 14:18 ` Lars-Peter Clausen
1 sibling, 1 reply; 20+ messages in thread
From: Lars-Peter Clausen @ 2013-01-16 14:07 UTC (permalink / raw)
To: Denis CIOCCA; +Cc: jic23, linux-iio
Hi,
looks pretty good overall, just a few nitpicks.
On 01/15/2013 09:30 AM, Denis CIOCCA wrote:
> This patch add generic library for STMicroelectronics 3-axis sensors.
adds a
>
> Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> ---
[...]
> diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c
> new file mode 100644
> index 0000000..2170b1d
> --- /dev/null
> +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c
> @@ -0,0 +1,115 @@
> +/*
> + * STMicroelectronics sensors buffer library driver
> + *
> + * Copyright 2012 STMicroelectronics Inc.
2012-2013 ;)
> + *
> + * Denis Ciocca <denis.ciocca@st.com>
> + *
> + * Licensed under the GPL-2.
> + */
> +
[...]
> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
> new file mode 100644
> index 0000000..af3eb1f
> --- /dev/null
> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
> @@ -0,0 +1,329 @@
> +/*
> + * STMicroelectronics sensors core library driver
> + *
> + * Copyright 2012 STMicroelectronics Inc.
> + *
> + * Denis Ciocca <denis.ciocca@st.com>
> + *
> + * Licensed under the GPL-2.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/iio/iio.h>
> +
> +#include <linux/iio/common/st_sensors.h>
> +
> +
> +#define ST_SENSORS_WAI_ADDRESS 0x0f
> +#define ST_SENSORS_G_TO_MG(x) (x*1000000ULL)
It looks as if this macro is not used
> +
> +int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, u8 reg_addr,
> + u8 mask, short num_bit, u8 data)
> +{
The num_bit parameter is not used in this function.
> + int err;
> + u8 new_data;
> + struct st_sensor_data *sdata = iio_priv(indio_dev);
> +
> + err = sdata->tf->read_byte(&sdata->tb, sdata->dev, reg_addr, &new_data);
> + if (err < 0)
> + goto st_sensors_write_data_with_mask_error;
> +
> + new_data = ((new_data & (~mask)) | ((data << __ffs(mask)) & mask));
> + err = sdata->tf->write_byte(&sdata->tb, sdata->dev, reg_addr, new_data);
> +
> +st_sensors_write_data_with_mask_error:
> + return err;
> +}
> +EXPORT_SYMBOL(st_sensors_write_data_with_mask);
> +
> +int st_sensors_get_sampling_frequency_avl(struct iio_dev *indio_dev,
> + const struct st_sensor_odr_avl *odr_avl, char *buf)
> +{
> + int i, len = 0;
> +
> + mutex_lock(&indio_dev->mlock);
> + for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) {
> + if (odr_avl[i].hz == 0)
> + break;
> +
> + len += sprintf(buf + len, "%d ", odr_avl[i].hz);
Although a buffer overflow is more of a theoretical concern here, using
scnprintf is still a good idea.
len += scnprintf(buf + len, PAGE_SIZE - len, ...)
> + }
> + mutex_unlock(&indio_dev->mlock);
> + buf[len - 1] = '\n';
> +
> + return len;
> +}
> +EXPORT_SYMBOL(st_sensors_get_sampling_frequency_avl);
> +
> +int st_sensors_get_scale_avl(struct iio_dev *indio_dev,
> + const struct st_sensor_fullscale_avl *fullscale_avl, char *buf)
> +{
> + int i, len = 0;
> +
> + mutex_lock(&indio_dev->mlock);
> + for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
> + if (fullscale_avl[i].num == 0)
> + break;
> +
> + len += sprintf(buf + len, "0.%06u ", fullscale_avl[i].gain);
Same here
> + }
> + mutex_unlock(&indio_dev->mlock);
> + buf[len - 1] = '\n';
> +
> + return len;
> +}
> +EXPORT_SYMBOL(st_sensors_get_scale_avl);
> +
> +static int st_sensors_match_odr(const struct st_sensors *sensor,
> + unsigned int odr, struct st_sensor_odr_avl *odr_out)
> +{
> + int i, ret = -EINVAL;
> +
> + for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) {
> + if ((sensor->odr.odr_avl[i].hz == odr) &&
> + (sensor->odr.odr_avl[i].hz != 0)) {
I guess you could skip the second check here if you did a
if (odr == 0)
return -EINVAL;
earlier
> + odr_out->hz = sensor->odr.odr_avl[i].hz;
> + odr_out->value = sensor->odr.odr_avl[i].value;
> + ret = 0;
> + break;
> + }
> + }
> +
> + return ret;
> +}
> +
[...]
> +static int st_sensors_match_fs(const struct st_sensors *sensor,
> + unsigned int fs, int *index_fs_avl)
> +{
> + int i, ret = -EINVAL;
> +
> + for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
> + if ((sensor->fs.fs_avl[i].num == fs) &&
> + (sensor->fs.fs_avl[i].num != 0)) {
Same here
> + *index_fs_avl = i;
> + ret = 0;
> + break;
> + }
> + }
> +
> + return ret;
> +}
> +
[...]
> +
> +int st_sensors_read_axis_data(struct iio_dev *indio_dev, u8 ch_addr, int *data)
> +{
> + int err;
> + u8 outdata[ST_SENSORS_BYTE_FOR_CHANNEL];
> + struct st_sensor_data *sdata = iio_priv(indio_dev);
> +
> + err = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
> + ch_addr, ST_SENSORS_BYTE_FOR_CHANNEL,
> + outdata, sdata->multiread_bit);
> + if (err < 0)
> + goto read_error;
> +
> + *data = ((s16)le16_to_cpup((__le16 *)outdata));
Either make outdata a __le16 or use get_unaligned_le16.
> +
> +read_error:
> + return err;
> +}
> +EXPORT_SYMBOL(st_sensors_read_axis_data);
> +
> +MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
> +MODULE_DESCRIPTION("STMicroelectronics ST-sensors core");
> +MODULE_LICENSE("GPL v2");
> diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c
> new file mode 100644
> index 0000000..1498831
> --- /dev/null
> +++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c
> @@ -0,0 +1,81 @@
> +/*
> + * STMicroelectronics sensors i2c library driver
> + *
> + * Copyright 2012 STMicroelectronics Inc.
> + *
> + * Denis Ciocca <denis.ciocca@st.com>
> + *
> + * Licensed under the GPL-2.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/iio/iio.h>
> +
> +#include <linux/iio/common/st_sensors.h>
> +
> +
> +#define ST_SENSORS_I2C_MULTIREAD 0x80
> +
> +unsigned int st_sensors_i2c_get_irq(struct iio_dev *indio_dev)
static
> +{
> + struct st_sensor_data *sdata = iio_priv(indio_dev);
> +
> + return to_i2c_client(sdata->dev)->irq;
> +}
[...]
> +void st_sensors_i2c_configure(struct iio_dev *indio_dev,
> + struct i2c_client *client, struct st_sensor_data *sdata)
> +{
> + i2c_set_clientdata(client, indio_dev);
> +
> + indio_dev->dev.parent = &client->dev;
> + indio_dev->name = client->name;
> +
> + sdata->tf = (struct st_sensor_transfer_function *)&st_sensors_tf_i2c;
Don't cast the const away, just make tf const as well.
> + sdata->get_irq_data_ready = st_sensors_i2c_get_irq;
> +}
> +EXPORT_SYMBOL(st_sensors_i2c_configure);
> +
> +MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
> +MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver");
> +MODULE_LICENSE("GPL v2");
> diff --git a/drivers/iio/common/st_sensors/st_sensors_spi.c b/drivers/iio/common/st_sensors/st_sensors_spi.c
> new file mode 100644
> index 0000000..2079f4b
> --- /dev/null
> +++ b/drivers/iio/common/st_sensors/st_sensors_spi.c
> @@ -0,0 +1,128 @@
> +/*
> + * STMicroelectronics sensors spi library driver
> + *
> + * Copyright 2012 STMicroelectronics Inc.
> + *
> + * Denis Ciocca <denis.ciocca@st.com>
> + *
> + * Licensed under the GPL-2.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/iio/iio.h>
> +
> +#include <linux/iio/common/st_sensors.h>
> +
> +
> +#define ST_SENSORS_SPI_MULTIREAD 0xc0
> +#define ST_SENSORS_SPI_READ 0x80
> +
> +unsigned int st_sensors_spi_get_irq(struct iio_dev *indio_dev)
static
> +{
> + struct st_sensor_data *sdata = iio_priv(indio_dev);
> +
> + return to_spi_device(sdata->dev)->irq;
> +}
> +
> +void st_sensors_spi_configure(struct iio_dev *indio_dev,
> + struct spi_device *spi, struct st_sensor_data *sdata)
> +{
> + spi_set_drvdata(spi, indio_dev);
> +
> + indio_dev->dev.parent = &spi->dev;
> + indio_dev->name = spi->modalias;
> +
> + sdata->tf = (struct st_sensor_transfer_function *)&st_sensors_tf_spi;
Again, no cast.
> + sdata->get_irq_data_ready = st_sensors_spi_get_irq;
> +}
> +EXPORT_SYMBOL(st_sensors_spi_configure);
> +
> +MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
> +MODULE_DESCRIPTION("STMicroelectronics ST-sensors spi driver");
> +MODULE_LICENSE("GPL v2");
[...]
> diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
> new file mode 100644
> index 0000000..f396bc5
> --- /dev/null
> +++ b/include/linux/iio/common/st_sensors.h
> @@ -0,0 +1,278 @@
[...]
> +
> +/**
> + * struct st_sensor_data - ST sensor device status
> + * @dev: Pointer to instance of struct device (I2C or SPI).
> + * @trig: The trigger in use by the core driver.
> + * @current_fullscale: Maximum range of measure by the sensor.
> + * @enabled: Status of the sensor (false->off, true->on).
> + * @multiread_bit: Use or not particular bit for [I2C/SPI] multiread.
> + * @index: Number used to point the sensor being used in the st_sensors struct.
> + * @buffer_data: Data used by buffer part.
> + * @odr: Output data rate of the sensor [Hz].
> + * @get_irq_data_ready: Function to get the IRQ used for data ready signal.
> + * @tf: Transfer function structure used by I/O operations.
> + * @tb: Transfer buffers and mutex used by I/O operations.
> + */
> +struct st_sensor_data {
> + struct device *dev;
> + struct iio_trigger *trig;
> + struct st_sensor_fullscale_avl *current_fullscale;
> +
> + bool enabled;
> + bool multiread_bit;
> +
> + short index;
> +
> + char *buffer_data;
> +
> + unsigned int odr;
> +
> + unsigned int (*get_irq_data_ready) (struct iio_dev *indio_dev);
> +
> + struct st_sensor_transfer_function *tf;
const struct st_sensor_transfer_function *tf
> + struct st_sensor_transfer_buffer tb;
> +};
> +
> +/**
> + * struct st_sensors - ST sensors list
> + * @wai: Contents of WhoAmI register.
* @sensors_supported: ...
> + * @ch: IIO channels for the sensor.
> + * @odr: Output data rate register and ODR list available.
> + * @pw: Power register of the sensor.
> + * @enable_axis: Enable one or more axis of the sensor.
> + * @fs: Full scale register and full scale list available.
> + * @bdu: Block data update register.
> + * @drdy_irq: Data ready register of the sensor.
> + * @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read.
> + * @bootime: samples to discard when sensor passing from power-down to power-up.
> + */
> +struct st_sensors {
> + u8 wai;
> + char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
> + struct iio_chan_spec *ch;
> + struct st_sensor_odr odr;
> + struct st_sensor_power pw;
> + struct st_sensor_axis enable_axis;
> + struct st_sensor_fullscale fs;
> + struct st_sensor_bdu bdu;
> + struct st_sensor_data_ready_irq drdy_irq;
> + bool multi_read_bit;
> + unsigned int bootime;
> +};
> +
[...]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/9] iio:common: Add STMicroelectronics common library
2013-01-15 8:30 ` [PATCH 1/9] iio:common: Add STMicroelectronics common library Denis CIOCCA
2013-01-16 14:07 ` Lars-Peter Clausen
@ 2013-01-16 14:18 ` Lars-Peter Clausen
1 sibling, 0 replies; 20+ messages in thread
From: Lars-Peter Clausen @ 2013-01-16 14:18 UTC (permalink / raw)
To: Denis CIOCCA; +Cc: jic23, linux-iio
Just noticed something else while going through the individual drivers.
> diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> new file mode 100644
> index 0000000..1c69c63
> --- /dev/null
> +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> @@ -0,0 +1,83 @@
[...]
> +
> +static struct iio_trigger_ops st_sensors_trigger_ops = {
> + .owner = THIS_MODULE,
> +};
> +
> +int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
> + int (*set_trigger_state)(struct iio_trigger *trig, bool state),
> + int (*try_reenable)(struct iio_trigger *trig))
> +{
> + int err;
> + struct st_sensor_data *sdata = iio_priv(indio_dev);
> +
> + sdata->trig = iio_trigger_alloc("%s-trigger", indio_dev->name);
> + if (sdata->trig == NULL) {
> + err = -ENOMEM;
> + dev_err(&indio_dev->dev, "failed to allocate iio trigger.\n");
> + goto iio_trigger_alloc_error;
> + }
> +
> + err = request_threaded_irq(sdata->get_irq_data_ready(indio_dev),
> + iio_trigger_generic_data_rdy_poll,
> + NULL,
> + IRQF_TRIGGER_RISING,
> + sdata->trig->name,
> + sdata->trig);
> + if (err)
> + goto request_irq_error;
> +
> + st_sensors_trigger_ops.set_trigger_state = set_trigger_state;
> + st_sensors_trigger_ops.try_reenable = try_reenable;
This is bad idea. It will break as soon as you have e.g. a gyro and and
accel driver instantiated at the same time. If you need custom trigger ops
callbacks define a custom trigger ops set per driver.
> + sdata->trig->private_data = indio_dev;
> + sdata->trig->ops = &st_sensors_trigger_ops;
> + sdata->trig->dev.parent = sdata->dev;
> +
> + err = iio_trigger_register(sdata->trig);
> + if (err < 0) {
> + dev_err(&indio_dev->dev, "failed to register iio trigger.\n");
> + goto iio_trigger_register_error;
> + }
> + indio_dev->trig = sdata->trig;
> +
> + return 0;
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 2/9] iio:accel: Add STMicroelectronics accelerometers driver
2013-01-15 8:30 ` [PATCH 2/9] iio:accel: Add STMicroelectronics accelerometers driver Denis CIOCCA
@ 2013-01-16 14:28 ` Lars-Peter Clausen
2013-01-16 16:56 ` Denis CIOCCA
0 siblings, 1 reply; 20+ messages in thread
From: Lars-Peter Clausen @ 2013-01-16 14:28 UTC (permalink / raw)
To: Denis CIOCCA; +Cc: jic23, linux-iio
On 01/15/2013 09:30 AM, Denis CIOCCA wrote:
> This patch adds generic accelerometer driver for STMicroelectronics
> accelerometers, currently it supports:
> LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC,
> LIS331DLH, LSM303DL, LSM303DLM, LSM330.
>
> Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> ---
[...]
> diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
> new file mode 100644
> index 0000000..4764d21
> --- /dev/null
> +++ b/drivers/iio/accel/st_accel_buffer.c
> @@ -0,0 +1,119 @@
> +/*
> + * STMicroelectronics accelerometers driver
> + *
> + * Copyright 2012 STMicroelectronics Inc.
> + *
> + * Denis Ciocca <denis.ciocca@st.com>
> + *
> + * Licensed under the GPL-2.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/slab.h>
> +#include <linux/stat.h>
> +#include <linux/interrupt.h>
> +#include <linux/byteorder/generic.h>
> +#include <linux/i2c.h>
> +#include <linux/delay.h>
> +#include <linux/iio/iio.h>
> +#include <linux/iio/buffer.h>
> +#include <linux/iio/trigger_consumer.h>
> +#include <linux/iio/triggered_buffer.h>
> +
> +#include <linux/iio/accel/st_accel.h>
> +#include <linux/iio/common/st_sensors.h>
> +
This file looks pretty much the same for all drivers, any reason why it
can't be shared?
> +
> +int st_accel_trig_set_state(struct iio_trigger *trig, bool state)
> +{
> + struct iio_dev *indio_dev = trig->private_data;
> + return st_accel_set_dataready_irq(indio_dev, state);
> +}
> +EXPORT_SYMBOL(st_accel_trig_set_state);
> +
> +static int st_accel_buffer_preenable(struct iio_dev *indio_dev)
> +{
> + int err;
> +
> + err = st_accel_set_enable(indio_dev, true);
> + if (err < 0)
> + goto st_accel_set_enable_error;
> +
> + err = iio_sw_buffer_preenable(indio_dev);
> +
> +st_accel_set_enable_error:
> + return err;
> +}
> +
> +static int st_accel_buffer_postenable(struct iio_dev *indio_dev)
> +{
> + int err;
> + struct st_sensor_data *adata = iio_priv(indio_dev);
> +
> + adata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
> + if (adata->buffer_data == NULL) {
> + err = -ENOMEM;
> + goto allocate_memory_error;
> + }
> +
> + err = st_accel_set_axis_enable(indio_dev,
> + (u8)indio_dev->active_scan_mask[0]);
> + if (err < 0)
> + goto st_accel_buffer_postenable_error;
> +
> + err = iio_triggered_buffer_postenable(indio_dev);
> + if (err < 0)
> + goto st_accel_buffer_postenable_error;
> +
> + return err;
> +
> +st_accel_buffer_postenable_error:
> + kfree(adata->buffer_data);
> +allocate_memory_error:
> + return err;
> +}
> +
> +static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
> +{
> + int err;
> + struct st_sensor_data *adata = iio_priv(indio_dev);
> +
> + err = iio_triggered_buffer_predisable(indio_dev);
> + if (err < 0)
> + goto st_accel_buffer_predisable_error;
> +
> + err = st_accel_set_axis_enable(indio_dev,
> + ST_SENSORS_ENABLE_ALL_CHANNELS);
> + if (err < 0)
> + goto st_accel_buffer_predisable_error;
> +
> + err = st_accel_set_enable(indio_dev, false);
> +
> +st_accel_buffer_predisable_error:
> + kfree(adata->buffer_data);
> + return err;
> +}
> +
> +static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = {
> + .preenable = &st_accel_buffer_preenable,
> + .postenable = &st_accel_buffer_postenable,
> + .predisable = &st_accel_buffer_predisable,
> +};
> +
> +int st_accel_allocate_ring(struct iio_dev *indio_dev)
> +{
> + return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
> + &st_sensors_trigger_handler, &st_accel_buffer_setup_ops);
> +}
> +EXPORT_SYMBOL(st_accel_allocate_ring);
> +
> +void st_accel_deallocate_ring(struct iio_dev *indio_dev)
> +{
> + iio_triggered_buffer_cleanup(indio_dev);
> +}
> +EXPORT_SYMBOL(st_accel_deallocate_ring);
> +
> +MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
> +MODULE_DESCRIPTION("STMicroelectronics accelerometers buffer");
> +MODULE_LICENSE("GPL v2");
> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
> new file mode 100644
> index 0000000..4e7108a
> --- /dev/null
> +++ b/drivers/iio/accel/st_accel_core.c
[....]
> +
> +static int st_accel_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *ch, int *val,
> + int *val2, long mask)
> +{
> + int err;
> + struct st_sensor_data *adata = iio_priv(indio_dev);
> +
Here again the function looks exactly the same in all three drivers and
could probably be moved to the common library.
> + switch (mask) {
> + case IIO_CHAN_INFO_RAW:
> + mutex_lock(&indio_dev->mlock);
> + if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
> + err = -EBUSY;
> + goto read_error;
> + } else {
> + err = st_sensors_set_enable(indio_dev,
> + &st_accel_sensors[adata->index], true);
> + if (err < 0)
> + goto read_error;
> +
> + msleep((st_accel_sensors[adata->index].bootime * 1000)
> + / adata->odr);
> + err = st_sensors_read_axis_data(indio_dev,
> + ch->address, val);
> + if (err < 0)
> + goto read_error;
> +
> + *val = *val >> ch->scan_type.shift;
> + }
> + mutex_unlock(&indio_dev->mlock);
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_SCALE:
> + *val = 0;
> + *val2 = adata->current_fullscale->gain;
> + return IIO_VAL_INT_PLUS_MICRO;
> + default:
> + return -EINVAL;
> + }
> +
> +read_error:
> + mutex_unlock(&indio_dev->mlock);
> + return err;
> +}
> +
> +static int st_accel_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int val, int val2, long mask)
> +{
> + int err;
> + struct st_sensor_data *adata = iio_priv(indio_dev);
> +
Same here.
> + switch (mask) {
> + case IIO_CHAN_INFO_SCALE:
> + err = st_sensors_set_fullscale_by_gain(indio_dev,
> + &st_accel_sensors[adata->index], val2);
> + break;
> + default:
> + err = -EINVAL;
> + }
> +
> + return err;
> +}
> +
> +int st_accel_set_dataready_irq(struct iio_dev *indio_dev, bool state)
> +{
> + struct st_sensor_data *adata = iio_priv(indio_dev);
> +
and here
> + return st_sensors_set_dataready_irq(indio_dev,
> + &st_accel_sensors[adata->index], state);
> +}
> +EXPORT_SYMBOL(st_accel_set_dataready_irq);
> +
> +int st_accel_set_axis_enable(struct iio_dev *indio_dev, u8 active_bit)
> +{
> + struct st_sensor_data *adata = iio_priv(indio_dev);
> +
and here
> + return st_sensors_set_axis_enable(indio_dev,
> + &st_accel_sensors[adata->index], active_bit);
> +}
> +EXPORT_SYMBOL(st_accel_set_axis_enable);
> +
> +static int st_accel_check_device_support(struct iio_dev *indio_dev)
> +{
> + int i, n, err;
> + u8 wai;
> + struct st_sensor_data *adata = iio_priv(indio_dev);
and here.
> +
> + err = adata->tf->read_byte(&adata->tb, adata->dev,
> + ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai);
> + if (err < 0) {
> + dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
> + goto read_wai_error;
> + }
> +
> + for (i = 0; i < ARRAY_SIZE(st_accel_sensors); i++) {
> + if (st_accel_sensors[i].wai == wai)
> + break;
> + }
> + if (i == ARRAY_SIZE(st_accel_sensors))
> + goto device_not_supported;
> +
> + for (n = 0; n < ARRAY_SIZE(st_accel_sensors[i].sensors_supported);
> + n++) {
> + if (strcmp(indio_dev->name,
> + &st_accel_sensors[i].sensors_supported[n][0]) == 0)
> + break;
> + }
> + if (n == ARRAY_SIZE(st_accel_sensors[i].sensors_supported)) {
> + dev_err(&indio_dev->dev, "device name and WhoAmI mismatch.\n");
> + goto sensor_name_mismatch;
> + }
> +
> + adata->index = i;
> +
> + return i;
> +
> +device_not_supported:
> + dev_err(&indio_dev->dev, "device not supported: WhoAmI (0x%x).\n", wai);
> +sensor_name_mismatch:
> + err = -ENODEV;
> +read_wai_error:
> + return err;
> +}
> +
[...]
> +
> +static ssize_t st_accel_sysfs_set_sampling_frequency(struct device *dev,
> + struct device_attribute *attr, const char *buf, size_t size)
> +{
> + int err;
> + unsigned int odr;
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> + struct st_sensor_data *adata = iio_priv(indio_dev);
> +
and here
> + err = kstrtoint(buf, 10, &odr);
> + if (err < 0)
> + goto conversion_error;
> +
> + mutex_lock(&indio_dev->mlock);
> + err = st_sensors_set_odr(indio_dev,
> + &st_accel_sensors[adata->index], odr);
> + mutex_unlock(&indio_dev->mlock);
> +
> +conversion_error:
> + return err < 0 ? err : size;
> +}
> +
> +static ssize_t st_accel_sysfs_get_sampling_frequency(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> + struct st_sensor_data *adata = iio_priv(indio_dev);
> +
and here
> + return sprintf(buf, "%d\n", adata->odr);
> +}
> +
> +static ssize_t st_accel_sysfs_scale_avail(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> + struct st_sensor_data *adata = iio_priv(indio_dev);
> +
and here
> + return st_sensors_get_scale_avl(indio_dev,
> + st_accel_sensors[adata->index].fs.fs_avl, buf);
> +}
> +
> +static ssize_t st_accel_sysfs_sampling_frequency_avail(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> + struct st_sensor_data *adata = iio_priv(indio_dev);
> +
and here
> + return st_sensors_get_sampling_frequency_avl(indio_dev,
> + st_accel_sensors[adata->index].odr.odr_avl, buf);
> +}
> +
[...]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/9] iio:common: Add STMicroelectronics common library
2013-01-16 14:07 ` Lars-Peter Clausen
@ 2013-01-16 16:30 ` Denis CIOCCA
2013-01-16 17:13 ` Lars-Peter Clausen
0 siblings, 1 reply; 20+ messages in thread
From: Denis CIOCCA @ 2013-01-16 16:30 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: jic23@kernel.org, linux-iio@vger.kernel.org
Hi Lars-Peter,
thank you very much for your review!
>> +int st_sensors_read_axis_data(struct iio_dev *indio_dev, u8 ch_addr, int *data)
>> +{
>> + int err;
>> + u8 outdata[ST_SENSORS_BYTE_FOR_CHANNEL];
>> + struct st_sensor_data *sdata = iio_priv(indio_dev);
>> +
>> + err = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
>> + ch_addr, ST_SENSORS_BYTE_FOR_CHANNEL,
>> + outdata, sdata->multiread_bit);
>> + if (err < 0)
>> + goto read_error;
>> +
>> + *data = ((s16)le16_to_cpup((__le16 *)outdata));
>
> Either make outdata a __le16 or use get_unaligned_le16.
get_unaligned_le16 doesn't do what I have done?
Denis
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 2/9] iio:accel: Add STMicroelectronics accelerometers driver
2013-01-16 14:28 ` Lars-Peter Clausen
@ 2013-01-16 16:56 ` Denis CIOCCA
2013-01-16 17:16 ` Lars-Peter Clausen
0 siblings, 1 reply; 20+ messages in thread
From: Denis CIOCCA @ 2013-01-16 16:56 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: jic23@kernel.org, linux-iio@vger.kernel.org
Hi Lars-Peter,
>> diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
>
> This file looks pretty much the same for all drivers, any reason why it
> can't be shared?
>> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
>
> Here again the function looks exactly the same in all three drivers and
> could probably be moved to the common library.
You are right, but the idea is that:
one common library for all common functions, but leave the code clear (
easy to read).
In the future I want to patch the current driver to support other features.
What do you think about?
Denis
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/9] iio:common: Add STMicroelectronics common library
2013-01-16 16:30 ` Denis CIOCCA
@ 2013-01-16 17:13 ` Lars-Peter Clausen
0 siblings, 0 replies; 20+ messages in thread
From: Lars-Peter Clausen @ 2013-01-16 17:13 UTC (permalink / raw)
To: Denis CIOCCA; +Cc: jic23@kernel.org, linux-iio@vger.kernel.org
On 01/16/2013 05:30 PM, Denis CIOCCA wrote:
> Hi Lars-Peter,
>
> thank you very much for your review!
>
>>> +int st_sensors_read_axis_data(struct iio_dev *indio_dev, u8 ch_addr, int *data)
>>> +{
>>> + int err;
>>> + u8 outdata[ST_SENSORS_BYTE_FOR_CHANNEL];
>>> + struct st_sensor_data *sdata = iio_priv(indio_dev);
>>> +
>>> + err = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
>>> + ch_addr, ST_SENSORS_BYTE_FOR_CHANNEL,
>>> + outdata, sdata->multiread_bit);
>>> + if (err < 0)
>>> + goto read_error;
>>> +
>>> + *data = ((s16)le16_to_cpup((__le16 *)outdata));
>>
>> Either make outdata a __le16 or use get_unaligned_le16.
>
> get_unaligned_le16 doesn't do what I have done?
It does. But it takes a u8*. So you don't have to cast to __le16 *.
- Lars
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 2/9] iio:accel: Add STMicroelectronics accelerometers driver
2013-01-16 16:56 ` Denis CIOCCA
@ 2013-01-16 17:16 ` Lars-Peter Clausen
0 siblings, 0 replies; 20+ messages in thread
From: Lars-Peter Clausen @ 2013-01-16 17:16 UTC (permalink / raw)
To: Denis CIOCCA; +Cc: jic23@kernel.org, linux-iio@vger.kernel.org
On 01/16/2013 05:56 PM, Denis CIOCCA wrote:
> Hi Lars-Peter,
>
>
>>> diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
>>
>> This file looks pretty much the same for all drivers, any reason why it
>> can't be shared?
>
>
>>> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
>>
>> Here again the function looks exactly the same in all three drivers and
>> could probably be moved to the common library.
>
>
> You are right, but the idea is that:
> one common library for all common functions, but leave the code clear (
> easy to read).
> In the future I want to patch the current driver to support other features.
> What do you think about?
I'd move the common bits to the common library. Once you get to extending
the drivers you can still add custom variants of theses functions. Only
having one copy of a particular piece of code also makes the reviewers job
easier.
- Lars
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2013-01-16 17:15 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-15 8:30 iio: STMicroelectronics iio drivers Denis CIOCCA
2013-01-15 8:30 ` [PATCH 1/9] iio:common: Add STMicroelectronics common library Denis CIOCCA
2013-01-16 14:07 ` Lars-Peter Clausen
2013-01-16 16:30 ` Denis CIOCCA
2013-01-16 17:13 ` Lars-Peter Clausen
2013-01-16 14:18 ` Lars-Peter Clausen
2013-01-15 8:30 ` [PATCH 2/9] iio:accel: Add STMicroelectronics accelerometers driver Denis CIOCCA
2013-01-16 14:28 ` Lars-Peter Clausen
2013-01-16 16:56 ` Denis CIOCCA
2013-01-16 17:16 ` Lars-Peter Clausen
2013-01-15 8:30 ` [PATCH 3/9] iio:gyro: Add STMicroelectronics gyroscopes driver Denis CIOCCA
2013-01-15 8:31 ` [PATCH 4/9] iio:magnetometer: Add STMicroelectronics magnetometers driver Denis CIOCCA
2013-01-15 22:33 ` iio: STMicroelectronics iio drivers Jonathan Cameron
2013-01-15 23:01 ` Jonathan Cameron
2013-01-15 23:06 ` Jonathan Cameron
2013-01-16 8:48 ` Jonathan Cameron
2013-01-16 11:48 ` Denis CIOCCA
2013-01-16 12:25 ` Jonathan Cameron
2013-01-16 13:36 ` Lars-Peter Clausen
-- strict thread matches above, loose matches on Subject: below --
2013-01-08 16:30 Denis CIOCCA
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).