Re: [PATCH v3 3/5] iio: common: ssp_sensors: Add sensorhub iio commons

2015-01-14 Thread Jonathan Cameron
On 13/01/15 16:03, Karol Wrona wrote:
> [...]
>>> +EXPORT_SYMBOL(ssp_common_setup_buffer);
>>> diff --git a/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h 
>>> b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
>>> new file mode 100644
>>> index 000..4b79be0
>>> --- /dev/null
>>> +++ b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
>>> @@ -0,0 +1,56 @@
>>> +#ifndef __SSP_IIO_SENSOR_H__
>>> +#define __SSP_IIO_SENSOR_H__
>>> +
>>> +#define SSP_CHANNEL_AG(_type, _mod, _index) \
>>> +{ \
>>> +   .type = _type,\
>>> +   .modified = 1,\
>>> +   .channel2 = _mod,\
>>> +   .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
>>> +   .scan_index = _index,\
>>> +   .scan_type = {\
>>> +   .sign = 's',\
>>> +   .realbits = 16,\
>> Seems a little unlikely unless the device is padding appropriately. Even
>> then it is generally a bad idea to claim more accuracy than is real. Very
>> few accelerometers etc are 16 bit.  Please confirm.
>>> +   .storagebits = 16,\
> Physically it is mpu6500:
> http://www.invensense.com/mems/gyro/documents/PS-MPU-6500A-01.pdf.
> It has 16-bit ADC.  Other thing linux device does not get these data directly
> but after some processing by sensorhub and in this case it always will be 
> 16-bit
> sample.
Fair enough, it'll be somewhat noisy but there might be some value in those low
bits ;)
> 
> 
> 
>>> +   .shift = 0,\
>>> +   .endianness = IIO_LE,\
>>> +   },\
>>> +}
>>> +
>>> +#define SSP_DIVISOR100ULL
>>> +#define SSP_MS_PER_S   1000
> [...]
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 3/5] iio: common: ssp_sensors: Add sensorhub iio commons

2015-01-14 Thread Jonathan Cameron
On 13/01/15 16:03, Karol Wrona wrote:
 [...]
 +EXPORT_SYMBOL(ssp_common_setup_buffer);
 diff --git a/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h 
 b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
 new file mode 100644
 index 000..4b79be0
 --- /dev/null
 +++ b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
 @@ -0,0 +1,56 @@
 +#ifndef __SSP_IIO_SENSOR_H__
 +#define __SSP_IIO_SENSOR_H__
 +
 +#define SSP_CHANNEL_AG(_type, _mod, _index) \
 +{ \
 +   .type = _type,\
 +   .modified = 1,\
 +   .channel2 = _mod,\
 +   .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
 +   .scan_index = _index,\
 +   .scan_type = {\
 +   .sign = 's',\
 +   .realbits = 16,\
 Seems a little unlikely unless the device is padding appropriately. Even
 then it is generally a bad idea to claim more accuracy than is real. Very
 few accelerometers etc are 16 bit.  Please confirm.
 +   .storagebits = 16,\
 Physically it is mpu6500:
 http://www.invensense.com/mems/gyro/documents/PS-MPU-6500A-01.pdf.
 It has 16-bit ADC.  Other thing linux device does not get these data directly
 but after some processing by sensorhub and in this case it always will be 
 16-bit
 sample.
Fair enough, it'll be somewhat noisy but there might be some value in those low
bits ;)
 
 
 
 +   .shift = 0,\
 +   .endianness = IIO_LE,\
 +   },\
 +}
 +
 +#define SSP_DIVISOR100ULL
 +#define SSP_MS_PER_S   1000
 [...]
 

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 3/5] iio: common: ssp_sensors: Add sensorhub iio commons

2015-01-13 Thread Karol Wrona
[...]
>> +EXPORT_SYMBOL(ssp_common_setup_buffer);
>> diff --git a/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h 
>> b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
>> new file mode 100644
>> index 000..4b79be0
>> --- /dev/null
>> +++ b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
>> @@ -0,0 +1,56 @@
>> +#ifndef __SSP_IIO_SENSOR_H__
>> +#define __SSP_IIO_SENSOR_H__
>> +
>> +#define SSP_CHANNEL_AG(_type, _mod, _index) \
>> +{ \
>> +.type = _type,\
>> +.modified = 1,\
>> +.channel2 = _mod,\
>> +.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
>> +.scan_index = _index,\
>> +.scan_type = {\
>> +.sign = 's',\
>> +.realbits = 16,\
> Seems a little unlikely unless the device is padding appropriately. Even
> then it is generally a bad idea to claim more accuracy than is real. Very
> few accelerometers etc are 16 bit.  Please confirm.
>> +.storagebits = 16,\
Physically it is mpu6500:
http://www.invensense.com/mems/gyro/documents/PS-MPU-6500A-01.pdf.
It has 16-bit ADC.  Other thing linux device does not get these data directly
but after some processing by sensorhub and in this case it always will be 16-bit
sample.



>> +.shift = 0,\
>> +.endianness = IIO_LE,\
>> +},\
>> +}
>> +
>> +#define SSP_DIVISOR 100ULL
>> +#define SSP_MS_PER_S1000
[...]
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 3/5] iio: common: ssp_sensors: Add sensorhub iio commons

2015-01-13 Thread Karol Wrona
[...]
 +EXPORT_SYMBOL(ssp_common_setup_buffer);
 diff --git a/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h 
 b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
 new file mode 100644
 index 000..4b79be0
 --- /dev/null
 +++ b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
 @@ -0,0 +1,56 @@
 +#ifndef __SSP_IIO_SENSOR_H__
 +#define __SSP_IIO_SENSOR_H__
 +
 +#define SSP_CHANNEL_AG(_type, _mod, _index) \
 +{ \
 +.type = _type,\
 +.modified = 1,\
 +.channel2 = _mod,\
 +.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
 +.scan_index = _index,\
 +.scan_type = {\
 +.sign = 's',\
 +.realbits = 16,\
 Seems a little unlikely unless the device is padding appropriately. Even
 then it is generally a bad idea to claim more accuracy than is real. Very
 few accelerometers etc are 16 bit.  Please confirm.
 +.storagebits = 16,\
Physically it is mpu6500:
http://www.invensense.com/mems/gyro/documents/PS-MPU-6500A-01.pdf.
It has 16-bit ADC.  Other thing linux device does not get these data directly
but after some processing by sensorhub and in this case it always will be 16-bit
sample.



 +.shift = 0,\
 +.endianness = IIO_LE,\
 +},\
 +}
 +
 +#define SSP_DIVISOR 100ULL
 +#define SSP_MS_PER_S1000
[...]
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 3/5] iio: common: ssp_sensors: Add sensorhub iio commons

2014-12-17 Thread Hartmut Knaack
Karol Wrona schrieb am 05.12.2014 um 20:54:
> This patch adds common library for sensorhub iio drivers.
> 
Looks good to me, overall. Just one very small nitpick.
> Change-Id: I1038cb31c051f7e8ffde696a4121518daa5af081
> Signed-off-by: Karol Wrona 
> Acked-by: Kyungmin Park 
> ---
>  drivers/iio/common/ssp_sensors/ssp_iio.c|   82 
> +++
>  drivers/iio/common/ssp_sensors/ssp_iio_sensor.h |   56 
>  2 files changed, 138 insertions(+)
>  create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio.c
>  create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
> 

> +/* Converts time in ms to frequency */
> +static inline void ssp_convert_to_freq(u32 time, int *integer_part,
> +int *fractional)
> +{
> + if (time == 0) {
> + *fractional = 0;
> + *integer_part = 0;
> + return;
> + }
> +
> + *integer_part = SSP_DIVIDEND / time;
> + *fractional = do_div(*integer_part, SSP_DIVISOR);
> +}
> +
> +/* Converts frequency to time in ms*/
Missing whitespace at end of comment.
> +static inline int ssp_convert_to_time(int integer_part, int fractional)
> +{
> + u64 value;
> +
> + value = integer_part * SSP_DIVISOR + fractional;
> + if (value == 0)
> + return 0;
> +
> + return div_u64(SSP_DIVIDEND, value);
> +}
> +#endif /* __SSP_IIO_SENSOR_H__ */
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 3/5] iio: common: ssp_sensors: Add sensorhub iio commons

2014-12-17 Thread Hartmut Knaack
Karol Wrona schrieb am 05.12.2014 um 20:54:
 This patch adds common library for sensorhub iio drivers.
 
Looks good to me, overall. Just one very small nitpick.
 Change-Id: I1038cb31c051f7e8ffde696a4121518daa5af081
 Signed-off-by: Karol Wrona k.wr...@samsung.com
 Acked-by: Kyungmin Park kyungmin.p...@samsung.com
 ---
  drivers/iio/common/ssp_sensors/ssp_iio.c|   82 
 +++
  drivers/iio/common/ssp_sensors/ssp_iio_sensor.h |   56 
  2 files changed, 138 insertions(+)
  create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio.c
  create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
 

 +/* Converts time in ms to frequency */
 +static inline void ssp_convert_to_freq(u32 time, int *integer_part,
 +int *fractional)
 +{
 + if (time == 0) {
 + *fractional = 0;
 + *integer_part = 0;
 + return;
 + }
 +
 + *integer_part = SSP_DIVIDEND / time;
 + *fractional = do_div(*integer_part, SSP_DIVISOR);
 +}
 +
 +/* Converts frequency to time in ms*/
Missing whitespace at end of comment.
 +static inline int ssp_convert_to_time(int integer_part, int fractional)
 +{
 + u64 value;
 +
 + value = integer_part * SSP_DIVISOR + fractional;
 + if (value == 0)
 + return 0;
 +
 + return div_u64(SSP_DIVIDEND, value);
 +}
 +#endif /* __SSP_IIO_SENSOR_H__ */
 

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 3/5] iio: common: ssp_sensors: Add sensorhub iio commons

2014-12-07 Thread Jonathan Cameron
On 05/12/14 19:54, Karol Wrona wrote:
> This patch adds common library for sensorhub iio drivers.
> 
> Change-Id: I1038cb31c051f7e8ffde696a4121518daa5af081
> Signed-off-by: Karol Wrona 
> Acked-by: Kyungmin Park 
Few minor bits inline.

> ---
>  drivers/iio/common/ssp_sensors/ssp_iio.c|   82 
> +++
>  drivers/iio/common/ssp_sensors/ssp_iio_sensor.h |   56 
>  2 files changed, 138 insertions(+)
>  create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio.c
>  create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
> 
> diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c 
> b/drivers/iio/common/ssp_sensors/ssp_iio.c
> new file mode 100644
> index 000..036be12
> --- /dev/null
> +++ b/drivers/iio/common/ssp_sensors/ssp_iio.c
> @@ -0,0 +1,82 @@
> +/*
> + *  Copyright (C) 2014, Samsung Electronics Co. Ltd. All Rights Reserved.
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation; either version 2 of the License, or
> + *  (at your option) any later version.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + */
> +
> +#include 
> +#include 
> +#include "ssp_iio_sensor.h"
> +
> +/**
> + * ssp_common_buffer_postenable() - generic postenable callback for ssp 
> buffer
> + *
> + * @indio_dev:   iio device
> + *
> + * Returns 0 or negative value in case of error
> + */
> +int ssp_common_buffer_postenable(struct iio_dev *indio_dev)
> +{
> + struct ssp_sensor_data *spd = iio_priv(indio_dev);
> + struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
> +
> + return ssp_enable_sensor(data, spd->type,
> +  ssp_get_sensor_delay(data, spd->type));
> +}
> +EXPORT_SYMBOL(ssp_common_buffer_postenable);
> +
> +/**
> + * ssp_common_buffer_predisable() - generic predisable callback for ssp 
> buffer
> + *
> + * @indio_dev:   iio device
> + *
> + * Returns 0 or negative value in case of error
> + */
> +int ssp_common_buffer_predisable(struct iio_dev *indio_dev)
> +{
> + struct ssp_sensor_data *spd = iio_priv(indio_dev);
> + struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
> +
> + return ssp_disable_sensor(data, spd->type);
> +}
> +EXPORT_SYMBOL(ssp_common_buffer_predisable);
> +
> +/**
> + * ssp_common_setup_buffer() - creates iio kfifo and registers the buffer
> + * for device
> + *
> + * @indio_dev:   iio device
> + *
> + * Returns 0 or negative value in case of error
> + */
> +int ssp_common_setup_buffer(struct iio_dev *indio_dev,
> + const struct iio_buffer_setup_ops *ops)
> +{
> + int ret;
> + struct iio_buffer *buffer;
Whilst we aren't specifying a trigger, I wonder if the standard 
triggered_buffer helper can be modified to check for pollfuncs?  That
would allow us to drop this local function in favour of central support.
I'm sure we'll get more devices over time that can use it.

Maybe even a little wrapper function for the normal iio_triggered_buffer_setup
such as iio_notrigger_buffer_setup?
> +
> + buffer = iio_kfifo_allocate(indio_dev);
> + if (!buffer)
> + return -ENOMEM;
> +
> + iio_device_attach_buffer(indio_dev, buffer);
> +
> + indio_dev->setup_ops = ops;
> +
> + ret = iio_buffer_register(indio_dev, indio_dev->channels,
> +   indio_dev->num_channels);
> + if (ret)
> + iio_kfifo_free(buffer);
> +
> + return ret;
> +}
> +EXPORT_SYMBOL(ssp_common_setup_buffer);
> diff --git a/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h 
> b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
> new file mode 100644
> index 000..4b79be0
> --- /dev/null
> +++ b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
> @@ -0,0 +1,56 @@
> +#ifndef __SSP_IIO_SENSOR_H__
> +#define __SSP_IIO_SENSOR_H__
> +
> +#define SSP_CHANNEL_AG(_type, _mod, _index) \
> +{ \
> + .type = _type,\
> + .modified = 1,\
> + .channel2 = _mod,\
> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
> + .scan_index = _index,\
> + .scan_type = {\
> + .sign = 's',\
> + .realbits = 16,\
Seems a little unlikely unless the device is padding appropriately. Even
then it is generally a bad idea to claim more accuracy than is real. Very
few accelerometers etc are 16 bit.  Please confirm.
> + .storagebits = 16,\
> + .shift = 0,\
> + .endianness = IIO_LE,\
> + },\
> +}
> +
> +#define SSP_DIVISOR  100ULL

Re: [PATCH v3 3/5] iio: common: ssp_sensors: Add sensorhub iio commons

2014-12-07 Thread Jonathan Cameron
On 05/12/14 19:54, Karol Wrona wrote:
 This patch adds common library for sensorhub iio drivers.
 
 Change-Id: I1038cb31c051f7e8ffde696a4121518daa5af081
 Signed-off-by: Karol Wrona k.wr...@samsung.com
 Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Few minor bits inline.

 ---
  drivers/iio/common/ssp_sensors/ssp_iio.c|   82 
 +++
  drivers/iio/common/ssp_sensors/ssp_iio_sensor.h |   56 
  2 files changed, 138 insertions(+)
  create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio.c
  create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
 
 diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c 
 b/drivers/iio/common/ssp_sensors/ssp_iio.c
 new file mode 100644
 index 000..036be12
 --- /dev/null
 +++ b/drivers/iio/common/ssp_sensors/ssp_iio.c
 @@ -0,0 +1,82 @@
 +/*
 + *  Copyright (C) 2014, Samsung Electronics Co. Ltd. All Rights Reserved.
 + *
 + *  This program is free software; you can redistribute it and/or modify
 + *  it under the terms of the GNU General Public License as published by
 + *  the Free Software Foundation; either version 2 of the License, or
 + *  (at your option) any later version.
 + *
 + *  This program is distributed in the hope that it will be useful,
 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + *  GNU General Public License for more details.
 + *
 + */
 +
 +#include linux/iio/common/ssp_sensors.h
 +#include linux/iio/kfifo_buf.h
 +#include ssp_iio_sensor.h
 +
 +/**
 + * ssp_common_buffer_postenable() - generic postenable callback for ssp 
 buffer
 + *
 + * @indio_dev:   iio device
 + *
 + * Returns 0 or negative value in case of error
 + */
 +int ssp_common_buffer_postenable(struct iio_dev *indio_dev)
 +{
 + struct ssp_sensor_data *spd = iio_priv(indio_dev);
 + struct ssp_data *data = dev_get_drvdata(indio_dev-dev.parent-parent);
 +
 + return ssp_enable_sensor(data, spd-type,
 +  ssp_get_sensor_delay(data, spd-type));
 +}
 +EXPORT_SYMBOL(ssp_common_buffer_postenable);
 +
 +/**
 + * ssp_common_buffer_predisable() - generic predisable callback for ssp 
 buffer
 + *
 + * @indio_dev:   iio device
 + *
 + * Returns 0 or negative value in case of error
 + */
 +int ssp_common_buffer_predisable(struct iio_dev *indio_dev)
 +{
 + struct ssp_sensor_data *spd = iio_priv(indio_dev);
 + struct ssp_data *data = dev_get_drvdata(indio_dev-dev.parent-parent);
 +
 + return ssp_disable_sensor(data, spd-type);
 +}
 +EXPORT_SYMBOL(ssp_common_buffer_predisable);
 +
 +/**
 + * ssp_common_setup_buffer() - creates iio kfifo and registers the buffer
 + * for device
 + *
 + * @indio_dev:   iio device
 + *
 + * Returns 0 or negative value in case of error
 + */
 +int ssp_common_setup_buffer(struct iio_dev *indio_dev,
 + const struct iio_buffer_setup_ops *ops)
 +{
 + int ret;
 + struct iio_buffer *buffer;
Whilst we aren't specifying a trigger, I wonder if the standard 
triggered_buffer helper can be modified to check for pollfuncs?  That
would allow us to drop this local function in favour of central support.
I'm sure we'll get more devices over time that can use it.

Maybe even a little wrapper function for the normal iio_triggered_buffer_setup
such as iio_notrigger_buffer_setup?
 +
 + buffer = iio_kfifo_allocate(indio_dev);
 + if (!buffer)
 + return -ENOMEM;
 +
 + iio_device_attach_buffer(indio_dev, buffer);
 +
 + indio_dev-setup_ops = ops;
 +
 + ret = iio_buffer_register(indio_dev, indio_dev-channels,
 +   indio_dev-num_channels);
 + if (ret)
 + iio_kfifo_free(buffer);
 +
 + return ret;
 +}
 +EXPORT_SYMBOL(ssp_common_setup_buffer);
 diff --git a/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h 
 b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
 new file mode 100644
 index 000..4b79be0
 --- /dev/null
 +++ b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
 @@ -0,0 +1,56 @@
 +#ifndef __SSP_IIO_SENSOR_H__
 +#define __SSP_IIO_SENSOR_H__
 +
 +#define SSP_CHANNEL_AG(_type, _mod, _index) \
 +{ \
 + .type = _type,\
 + .modified = 1,\
 + .channel2 = _mod,\
 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
 + .scan_index = _index,\
 + .scan_type = {\
 + .sign = 's',\
 + .realbits = 16,\
Seems a little unlikely unless the device is padding appropriately. Even
then it is generally a bad idea to claim more accuracy than is real. Very
few accelerometers etc are 16 bit.  Please confirm.
 + .storagebits = 16,\
 + .shift = 0,\
 + .endianness = IIO_LE,\
 + },\
 +}
 +
 +#define SSP_DIVISOR  100ULL
 +#define SSP_MS_PER_S 1000
The name of the next 

[PATCH v3 3/5] iio: common: ssp_sensors: Add sensorhub iio commons

2014-12-05 Thread Karol Wrona
This patch adds common library for sensorhub iio drivers.

Change-Id: I1038cb31c051f7e8ffde696a4121518daa5af081
Signed-off-by: Karol Wrona 
Acked-by: Kyungmin Park 
---
 drivers/iio/common/ssp_sensors/ssp_iio.c|   82 +++
 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h |   56 
 2 files changed, 138 insertions(+)
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio.c
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h

diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c 
b/drivers/iio/common/ssp_sensors/ssp_iio.c
new file mode 100644
index 000..036be12
--- /dev/null
+++ b/drivers/iio/common/ssp_sensors/ssp_iio.c
@@ -0,0 +1,82 @@
+/*
+ *  Copyright (C) 2014, Samsung Electronics Co. Ltd. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include "ssp_iio_sensor.h"
+
+/**
+ * ssp_common_buffer_postenable() - generic postenable callback for ssp buffer
+ *
+ * @indio_dev: iio device
+ *
+ * Returns 0 or negative value in case of error
+ */
+int ssp_common_buffer_postenable(struct iio_dev *indio_dev)
+{
+   struct ssp_sensor_data *spd = iio_priv(indio_dev);
+   struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
+
+   return ssp_enable_sensor(data, spd->type,
+ssp_get_sensor_delay(data, spd->type));
+}
+EXPORT_SYMBOL(ssp_common_buffer_postenable);
+
+/**
+ * ssp_common_buffer_predisable() - generic predisable callback for ssp buffer
+ *
+ * @indio_dev: iio device
+ *
+ * Returns 0 or negative value in case of error
+ */
+int ssp_common_buffer_predisable(struct iio_dev *indio_dev)
+{
+   struct ssp_sensor_data *spd = iio_priv(indio_dev);
+   struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
+
+   return ssp_disable_sensor(data, spd->type);
+}
+EXPORT_SYMBOL(ssp_common_buffer_predisable);
+
+/**
+ * ssp_common_setup_buffer() - creates iio kfifo and registers the buffer
+ * for device
+ *
+ * @indio_dev: iio device
+ *
+ * Returns 0 or negative value in case of error
+ */
+int ssp_common_setup_buffer(struct iio_dev *indio_dev,
+   const struct iio_buffer_setup_ops *ops)
+{
+   int ret;
+   struct iio_buffer *buffer;
+
+   buffer = iio_kfifo_allocate(indio_dev);
+   if (!buffer)
+   return -ENOMEM;
+
+   iio_device_attach_buffer(indio_dev, buffer);
+
+   indio_dev->setup_ops = ops;
+
+   ret = iio_buffer_register(indio_dev, indio_dev->channels,
+ indio_dev->num_channels);
+   if (ret)
+   iio_kfifo_free(buffer);
+
+   return ret;
+}
+EXPORT_SYMBOL(ssp_common_setup_buffer);
diff --git a/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h 
b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
new file mode 100644
index 000..4b79be0
--- /dev/null
+++ b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
@@ -0,0 +1,56 @@
+#ifndef __SSP_IIO_SENSOR_H__
+#define __SSP_IIO_SENSOR_H__
+
+#define SSP_CHANNEL_AG(_type, _mod, _index) \
+{ \
+   .type = _type,\
+   .modified = 1,\
+   .channel2 = _mod,\
+   .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
+   .scan_index = _index,\
+   .scan_type = {\
+   .sign = 's',\
+   .realbits = 16,\
+   .storagebits = 16,\
+   .shift = 0,\
+   .endianness = IIO_LE,\
+   },\
+}
+
+#define SSP_DIVISOR100ULL
+#define SSP_MS_PER_S   1000
+#define SSP_DIVIDEND   (SSP_DIVISOR * SSP_MS_PER_S)
+
+int ssp_common_buffer_postenable(struct iio_dev *indio_dev);
+
+int ssp_common_buffer_predisable(struct iio_dev *indio_dev);
+
+int ssp_common_setup_buffer(struct iio_dev *indio_dev,
+   const struct iio_buffer_setup_ops *ops);
+
+/* Converts time in ms to frequency */
+static inline void ssp_convert_to_freq(u32 time, int *integer_part,
+  int *fractional)
+{
+   if (time == 0) {
+   *fractional = 0;
+   *integer_part = 0;
+   return;
+   }
+
+   *integer_part = SSP_DIVIDEND / time;
+   *fractional = do_div(*integer_part, SSP_DIVISOR);
+}
+
+/* Converts frequency to time in ms*/
+static inline int ssp_convert_to_time(int integer_part, int fractional)
+{
+  

[PATCH v3 3/5] iio: common: ssp_sensors: Add sensorhub iio commons

2014-12-05 Thread Karol Wrona
This patch adds common library for sensorhub iio drivers.

Change-Id: I1038cb31c051f7e8ffde696a4121518daa5af081
Signed-off-by: Karol Wrona k.wr...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/iio/common/ssp_sensors/ssp_iio.c|   82 +++
 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h |   56 
 2 files changed, 138 insertions(+)
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio.c
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h

diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c 
b/drivers/iio/common/ssp_sensors/ssp_iio.c
new file mode 100644
index 000..036be12
--- /dev/null
+++ b/drivers/iio/common/ssp_sensors/ssp_iio.c
@@ -0,0 +1,82 @@
+/*
+ *  Copyright (C) 2014, Samsung Electronics Co. Ltd. All Rights Reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ */
+
+#include linux/iio/common/ssp_sensors.h
+#include linux/iio/kfifo_buf.h
+#include ssp_iio_sensor.h
+
+/**
+ * ssp_common_buffer_postenable() - generic postenable callback for ssp buffer
+ *
+ * @indio_dev: iio device
+ *
+ * Returns 0 or negative value in case of error
+ */
+int ssp_common_buffer_postenable(struct iio_dev *indio_dev)
+{
+   struct ssp_sensor_data *spd = iio_priv(indio_dev);
+   struct ssp_data *data = dev_get_drvdata(indio_dev-dev.parent-parent);
+
+   return ssp_enable_sensor(data, spd-type,
+ssp_get_sensor_delay(data, spd-type));
+}
+EXPORT_SYMBOL(ssp_common_buffer_postenable);
+
+/**
+ * ssp_common_buffer_predisable() - generic predisable callback for ssp buffer
+ *
+ * @indio_dev: iio device
+ *
+ * Returns 0 or negative value in case of error
+ */
+int ssp_common_buffer_predisable(struct iio_dev *indio_dev)
+{
+   struct ssp_sensor_data *spd = iio_priv(indio_dev);
+   struct ssp_data *data = dev_get_drvdata(indio_dev-dev.parent-parent);
+
+   return ssp_disable_sensor(data, spd-type);
+}
+EXPORT_SYMBOL(ssp_common_buffer_predisable);
+
+/**
+ * ssp_common_setup_buffer() - creates iio kfifo and registers the buffer
+ * for device
+ *
+ * @indio_dev: iio device
+ *
+ * Returns 0 or negative value in case of error
+ */
+int ssp_common_setup_buffer(struct iio_dev *indio_dev,
+   const struct iio_buffer_setup_ops *ops)
+{
+   int ret;
+   struct iio_buffer *buffer;
+
+   buffer = iio_kfifo_allocate(indio_dev);
+   if (!buffer)
+   return -ENOMEM;
+
+   iio_device_attach_buffer(indio_dev, buffer);
+
+   indio_dev-setup_ops = ops;
+
+   ret = iio_buffer_register(indio_dev, indio_dev-channels,
+ indio_dev-num_channels);
+   if (ret)
+   iio_kfifo_free(buffer);
+
+   return ret;
+}
+EXPORT_SYMBOL(ssp_common_setup_buffer);
diff --git a/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h 
b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
new file mode 100644
index 000..4b79be0
--- /dev/null
+++ b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
@@ -0,0 +1,56 @@
+#ifndef __SSP_IIO_SENSOR_H__
+#define __SSP_IIO_SENSOR_H__
+
+#define SSP_CHANNEL_AG(_type, _mod, _index) \
+{ \
+   .type = _type,\
+   .modified = 1,\
+   .channel2 = _mod,\
+   .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
+   .scan_index = _index,\
+   .scan_type = {\
+   .sign = 's',\
+   .realbits = 16,\
+   .storagebits = 16,\
+   .shift = 0,\
+   .endianness = IIO_LE,\
+   },\
+}
+
+#define SSP_DIVISOR100ULL
+#define SSP_MS_PER_S   1000
+#define SSP_DIVIDEND   (SSP_DIVISOR * SSP_MS_PER_S)
+
+int ssp_common_buffer_postenable(struct iio_dev *indio_dev);
+
+int ssp_common_buffer_predisable(struct iio_dev *indio_dev);
+
+int ssp_common_setup_buffer(struct iio_dev *indio_dev,
+   const struct iio_buffer_setup_ops *ops);
+
+/* Converts time in ms to frequency */
+static inline void ssp_convert_to_freq(u32 time, int *integer_part,
+  int *fractional)
+{
+   if (time == 0) {
+   *fractional = 0;
+   *integer_part = 0;
+   return;
+   }
+
+   *integer_part = SSP_DIVIDEND / time;
+   *fractional = do_div(*integer_part, SSP_DIVISOR);
+}
+
+/* Converts frequency to time in