All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Denis CIOCCA <denis.ciocca@st.com>
Cc: jic23@kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH 1/4] iio:common: Add STMicroelectronics common library
Date: Wed, 23 Jan 2013 10:33:10 +0100	[thread overview]
Message-ID: <50FFAE56.4070803@metafoo.de> (raw)
In-Reply-To: <1358757380-3187-2-git-send-email-denis.ciocca@st.com>

Hi,

I guess we are almost there now. A couple of small things, which need to be
fixed though.

On 01/21/2013 09:36 AM, Denis CIOCCA wrote:
> This patch add a 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              |  14 +
>  drivers/iio/common/st_sensors/Makefile             |  10 +
>  drivers/iio/common/st_sensors/st_sensors_buffer.c  | 115 ++++++
>  drivers/iio/common/st_sensors/st_sensors_core.c    | 411 +++++++++++++++++++++
>  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 |  77 ++++
>  include/linux/iio/common/st_sensors.h              | 266 +++++++++++++
>  include/linux/iio/common/st_sensors_i2c.h          |  20 +
>  include/linux/iio/common/st_sensors_spi.h          |  20 +
>  12 files changed, 1144 insertions(+)
>  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
>  create mode 100644 include/linux/iio/common/st_sensors_i2c.h
>  create mode 100644 include/linux/iio/common/st_sensors_spi.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..84b2dca
> --- /dev/null
> +++ b/drivers/iio/common/st_sensors/Kconfig
> @@ -0,0 +1,14 @@
> +#
> +# Hid Sensor common modules
> +#
> +
> +config IIO_ST_SENSORS_I2C
> +	tristate
> +
> +config IIO_ST_SENSORS_SPI
> +	tristate
> +
> +config IIO_ST_SENSORS_CORE
> +	tristate
> +	select IIO_ST_SENSORS_I2C if I2C
> +	select IIO_ST_SENSORS_SPI if SPI_MASTER
> diff --git a/drivers/iio/common/st_sensors/Makefile b/drivers/iio/common/st_sensors/Makefile
> new file mode 100644
> index 0000000..9f3e24f
> --- /dev/null
> +++ b/drivers/iio/common/st_sensors/Makefile
> @@ -0,0 +1,10 @@
> +#
> +# Makefile for the STMicroelectronics sensor common modules.
> +#
> +
> +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_CORE) += st_sensors.o
> +st_sensors-y := st_sensors_core.o
> +st_sensors-$(CONFIG_IIO_BUFFER) += st_sensors_buffer.o
> +st_sensors-$(CONFIG_IIO_TRIGGER) += st_sensors_trigger.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..f4a5adc
> --- /dev/null
> +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c
> @@ -0,0 +1,115 @@
> +/*
> + * STMicroelectronics sensors buffer library driver
> + *
> + * Copyright 2012-2013 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..661cc2b
> --- /dev/null
> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
> @@ -0,0 +1,411 @@
> +/*
> + * STMicroelectronics sensors core library driver
> + *
> + * Copyright 2012-2013 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/delay.h>
> +#include <linux/unaligned/le_byteshift.h>

Never include that file directly. Use asm/unaligned.h, it will provide the
best suited implementation of the unaligned functions for the current
architecture.

> +#include <linux/iio/iio.h>
> +
> +#include <linux/iio/common/st_sensors.h>
> +
> +
[...]

> 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..9c62c6a
> --- /dev/null
> +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c
> @@ -0,0 +1,77 @@
> +/*
> + * STMicroelectronics sensors trigger library driver
> + *
> + * Copyright 2012-2013 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>
> +
> +
> +int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
> +					struct iio_trigger_ops *trigger_ops)

const

> +{
[...]

  parent reply	other threads:[~2013-01-23  9:32 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-21  8:36 STMicroelectronics driver kconfig-makefile bugfix Denis CIOCCA
2013-01-21  8:36 ` [PATCH 1/4] iio:common: Add STMicroelectronics common library Denis CIOCCA
2013-01-22 16:15   ` Jonathan Cameron
2013-01-22 16:16     ` [PATCH 00/10] Some little cleanups and fixlets for the ST sensor drivers Jonathan Cameron
2013-01-22 16:16       ` [PATCH 01/10] iio:st_sensors drop some unused exports Jonathan Cameron
2013-01-22 16:16       ` [PATCH 02/10] iio:accel:st_accel move the header from include/iio/common to Jonathan Cameron
2013-01-22 16:16       ` [PATCH 03/10] iio:gyro:st_gyro move header from linux/iio/gyro to Jonathan Cameron
2013-01-22 16:16       ` [PATCH 04/10] iio:magn:st_magn move header from linux/iio/magn/ to Jonathan Cameron
2013-01-22 16:16       ` [PATCH 05/10] iio:accel:st_accel drop unwanted EXPORT_SYMBOLS Jonathan Cameron
2013-01-22 16:16       ` [PATCH 06/10] iio:gyro:st_gyro drop unwanted EXPORT_SYMBOLs Jonathan Cameron
2013-01-22 16:16       ` [PATCH 07/10] iio:magn:st_magn " Jonathan Cameron
2013-01-22 16:16       ` [PATCH 08/10] iio:accel:st_accel drop incorrect line from kconfig comment Jonathan Cameron
2013-01-22 16:16       ` [PATCH 09/10] iio:gyro:st_gyro " Jonathan Cameron
2013-01-22 16:16       ` [PATCH 10/10] iio:magn:st_magn drop incorrect line from Kconfig Jonathan Cameron
2013-01-23  9:33   ` Lars-Peter Clausen [this message]
2013-01-21  8:36 ` [PATCH 2/4] iio:accel: Add STMicroelectronics accelerometers driver Denis CIOCCA
2013-01-23  9:45   ` Lars-Peter Clausen
2013-01-21  8:36 ` [PATCH 3/4] iio:gyro: Add STMicroelectronics gyroscopes driver Denis CIOCCA
2013-01-21  8:36 ` [PATCH 4/4] iio:magnetometer: Add STMicroelectronics magnetometers driver Denis CIOCCA
  -- strict thread matches above, loose matches on Subject: below --
2013-01-25 23:44 STMicroelectronics IIO driver Denis Ciocca
2013-01-25 23:44 ` [PATCH 1/4] iio:common: Add STMicroelectronics common library Denis Ciocca
2013-01-29 21:45   ` Lars-Peter Clausen
2013-01-18 16:58 STMicroelectronics drivers Denis CIOCCA
2013-01-18 16:58 ` [PATCH 1/4] iio:common: Add STMicroelectronics common library Denis CIOCCA
2013-01-18  9:31 STMicroelectronics drivers bugfix Denis CIOCCA
2013-01-18  9:31 ` [PATCH 1/4] iio:common: Add STMicroelectronics common library Denis CIOCCA
2013-01-09 12:06 iio: STMicroelectronics iio drivers bugfix Denis CIOCCA
2013-01-09 12:06 ` [PATCH 1/4] iio:common: Add STMicroelectronics common library Denis CIOCCA
2013-01-12 21:59   ` Jonathan Cameron
2013-01-08 16:30 iio: STMicroelectronics iio drivers Denis CIOCCA
2013-01-08 16:30 ` [PATCH 1/4] iio:common: Add STMicroelectronics common library Denis CIOCCA
2012-12-13 13:11 STMicroelectronics sensors driver Denis CIOCCA
2012-12-13 13:11 ` [PATCH 1/4] iio:common: Add STMicroelectronics common library Denis CIOCCA
2012-12-16 12:15   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50FFAE56.4070803@metafoo.de \
    --to=lars@metafoo.de \
    --cc=denis.ciocca@st.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.