Re: [PATCH v3] iio: adc: Add TI ADS1015 ADC driver support

2016-02-06 Thread Jonathan Cameron
On 04/02/16 12:51, Daniel Baluta wrote:
>> Would it be more consistent to handle the mutex outside of the switch above 
>> similar
>> to how it is handled in ads1015_write_raw?
>>
>> Also the ads1015_set_power_state(data, false) is called either way so why 
>> not just
>> use one call?
>>
> 
> I don't have a strong preference for that. I think across IIO drivers
> we can find both coding practices.
Often we move it into the switch because in most driver some of the read_raw
elements don't need to query the hardware (scales are often fixed for example) 
so
we don't need to take the lock for them.  Here it makes sense to take the lock.

(Not that I care much either way!)
> 
> Indeed consistency with ads1015_write_raw is a good argument. Will fix it.
> 
> I will leave the code here for one more day and then send an updated version.
> 
> thanks,
> Daniel.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 



Re: [PATCH v3] iio: adc: Add TI ADS1015 ADC driver support

2016-02-06 Thread Jonathan Cameron
On 04/02/16 12:51, Daniel Baluta wrote:
>> Would it be more consistent to handle the mutex outside of the switch above 
>> similar
>> to how it is handled in ads1015_write_raw?
>>
>> Also the ads1015_set_power_state(data, false) is called either way so why 
>> not just
>> use one call?
>>
> 
> I don't have a strong preference for that. I think across IIO drivers
> we can find both coding practices.
Often we move it into the switch because in most driver some of the read_raw
elements don't need to query the hardware (scales are often fixed for example) 
so
we don't need to take the lock for them.  Here it makes sense to take the lock.

(Not that I care much either way!)
> 
> Indeed consistency with ads1015_write_raw is a good argument. Will fix it.
> 
> I will leave the code here for one more day and then send an updated version.
> 
> thanks,
> Daniel.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 



Re: [PATCH v3] iio: adc: Add TI ADS1015 ADC driver support

2016-02-04 Thread Daniel Baluta
> Would it be more consistent to handle the mutex outside of the switch above 
> similar
> to how it is handled in ads1015_write_raw?
>
> Also the ads1015_set_power_state(data, false) is called either way so why not 
> just
> use one call?
>

I don't have a strong preference for that. I think across IIO drivers
we can find both coding practices.

Indeed consistency with ads1015_write_raw is a good argument. Will fix it.

I will leave the code here for one more day and then send an updated version.

thanks,
Daniel.


Re: [PATCH v3] iio: adc: Add TI ADS1015 ADC driver support

2016-02-04 Thread Daniel Baluta
> Would it be more consistent to handle the mutex outside of the switch above 
> similar
> to how it is handled in ads1015_write_raw?
>
> Also the ads1015_set_power_state(data, false) is called either way so why not 
> just
> use one call?
>

I don't have a strong preference for that. I think across IIO drivers
we can find both coding practices.

Indeed consistency with ads1015_write_raw is a good argument. Will fix it.

I will leave the code here for one more day and then send an updated version.

thanks,
Daniel.


Re: [PATCH v3] iio: adc: Add TI ADS1015 ADC driver support

2016-02-03 Thread Matt Ranostay
On Wed, Feb 3, 2016 at 8:59 AM, Daniel Baluta  wrote:
> The driver has sysfs readings with runtime PM support for power saving.
> It also offers buffer support that can be used together with IIO software
> triggers.
>
> Datasheet can be found here:
> http://www.ti.com.cn/cn/lit/ds/symlink/ads1015.pdf
>
> Signed-off-by: Daniel Baluta 
> ---
> Changes since v2:
> * push locking out of the switch in write_raw
> * fix  buf allocation in triggered buffer's handler
>
> Changes since v1:
> * addressed concerns about replacing the ads1015 hwmon driver
> * For the moment the IIO driver is compatible with hwmon
>   driver (dt bindings) the only thing left is to also add
>   support for ads1115.
> * DT bindings are described in Documentation/devicetree/
>   bindings/hwmon/ads1015.txt. If needed will copy this file
>   in a later patch to the IIO corresponding location.
> * addressed comments from Jonathan
> * added proper locking
> * added timestamp channel
> * removed magic constants
> * added some new lines to increase readability
> * used regmap_get_device instead of keeping a copy of
> i2c_client pointer.
> * used non-devm function to correct the cleanup order
>
>  drivers/iio/adc/Kconfig  |  13 +
>  drivers/iio/adc/Makefile |   1 +
>  drivers/iio/adc/ti-ads1015.c | 616 
> +++
>  3 files changed, 630 insertions(+)
>  create mode 100644 drivers/iio/adc/ti-ads1015.c
>
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 60673b4..fad7e6a 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -370,6 +370,19 @@ config TI_ADC128S052
>   This driver can also be built as a module. If so, the module will be
>   called ti-adc128s052.
>
> +config TI_ADS1015
> +   tristate "Texas Instruments ADS1015 ADC"
> +   depends on I2C && !SENSORS_ADS1015
> +   select REGMAP_I2C
> +   select IIO_BUFFER
> +   select IIO_TRIGGERED_BUFFER
> +   help
> + If you say yes here you get support for Texas Instruments ADS1015
> + ADC chip.
> +
> + This driver can also be built as a module. If so, the module will be
> + called ti-ads1015.
> +
>  config TI_ADS8688
> tristate "Texas Instruments ADS8688"
> depends on SPI && OF
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index fb57e12..2ff70a3 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -36,6 +36,7 @@ obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
>  obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
>  obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
>  obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o
> +obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o
>  obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o
>  obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
>  obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o
> diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> new file mode 100644
> index 000..abe78d3
> --- /dev/null
> +++ b/drivers/iio/adc/ti-ads1015.c
> @@ -0,0 +1,616 @@
> +/*
> + * ADS1015 - Texas Instruments Analog-to-Digital Converter
> + *
> + * Copyright (c) 2016, Intel Corporation.
> + *
> + * This file is subject to the terms and conditions of version 2 of
> + * the GNU General Public License.  See the file COPYING in the main
> + * directory of this archive for more details.
> + *
> + * IIO driver for ADS1015 ADC 7-bit I2C slave address:
> + * * 0x48 - ADDR connectd to Ground

typo here :).


> + * * 0x49 - ADDR connected to Vdd
> + * * 0x4A - ADDR connected to SDA
> + * * 0x4B - ADDR connected to SCL
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define ADS1015_DRV_NAME "ads1015"
> +
> +#define ADS1015_CONV_REG   0x00
> +#define ADS1015_CFG_REG0x01
> +
> +#define ADS1015_CFG_DR_SHIFT   5
> +#define ADS1015_CFG_MOD_SHIFT  8
> +#define ADS1015_CFG_PGA_SHIFT  9
> +#define ADS1015_CFG_MUX_SHIFT  12
> +
> +#define ADS1015_CFG_DR_MASKGENMASK(7, 5)
> +#define ADS1015_CFG_MOD_MASK   BIT(8)
> +#define ADS1015_CFG_PGA_MASK   GENMASK(11, 9)
> +#define ADS1015_CFG_MUX_MASK   GENMASK(14, 12)
> +
> +/* device operating modes */
> +#define ADS1015_CONTINUOUS 0
> +#define ADS1015_SINGLESHOT 1
> +
> +#define ADS1015_SLEEP_DELAY_MS 2000
> +#define ADS1015_DEFAULT_PGA2
> +#define ADS1015_DEFAULT_DATA_RATE  4
> +#define ADS1015_DEFAULT_CHAN   0
> +
> +enum ads1015_channels {
> +   ADS1015_AIN0_AIN1 = 0,
> +   ADS1015_AIN0_AIN3,
> +   ADS1015_AIN1_AIN3,
> +   ADS1015_AIN2_AIN3,
> +  

Re: [PATCH v3] iio: adc: Add TI ADS1015 ADC driver support

2016-02-03 Thread Michael Welling
On Wed, Feb 03, 2016 at 06:59:56PM +0200, Daniel Baluta wrote:
> The driver has sysfs readings with runtime PM support for power saving.
> It also offers buffer support that can be used together with IIO software
> triggers.
> 
> Datasheet can be found here:
>   http://www.ti.com.cn/cn/lit/ds/symlink/ads1015.pdf
> 
> Signed-off-by: Daniel Baluta 
> ---
> Changes since v2:
>   * push locking out of the switch in write_raw
>   * fix  buf allocation in triggered buffer's handler
> 
> Changes since v1:
>   * addressed concerns about replacing the ads1015 hwmon driver
>   * For the moment the IIO driver is compatible with hwmon
> driver (dt bindings) the only thing left is to also add
> support for ads1115.
>   * DT bindings are described in Documentation/devicetree/
> bindings/hwmon/ads1015.txt. If needed will copy this file
> in a later patch to the IIO corresponding location.
>   * addressed comments from Jonathan
>   * added proper locking
>   * added timestamp channel
>   * removed magic constants
>   * added some new lines to increase readability
>   * used regmap_get_device instead of keeping a copy of
>   i2c_client pointer.
>   * used non-devm function to correct the cleanup order
> 
>  drivers/iio/adc/Kconfig  |  13 +
>  drivers/iio/adc/Makefile |   1 +
>  drivers/iio/adc/ti-ads1015.c | 616 
> +++
>  3 files changed, 630 insertions(+)
>  create mode 100644 drivers/iio/adc/ti-ads1015.c
> 
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 60673b4..fad7e6a 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -370,6 +370,19 @@ config TI_ADC128S052
> This driver can also be built as a module. If so, the module will be
> called ti-adc128s052.
>  
> +config TI_ADS1015
> + tristate "Texas Instruments ADS1015 ADC"
> + depends on I2C && !SENSORS_ADS1015
> + select REGMAP_I2C
> + select IIO_BUFFER
> + select IIO_TRIGGERED_BUFFER
> + help
> +   If you say yes here you get support for Texas Instruments ADS1015
> +   ADC chip.
> +
> +   This driver can also be built as a module. If so, the module will be
> +   called ti-ads1015.
> +
>  config TI_ADS8688
>   tristate "Texas Instruments ADS8688"
>   depends on SPI && OF
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index fb57e12..2ff70a3 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -36,6 +36,7 @@ obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
>  obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
>  obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
>  obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o
> +obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o
>  obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o
>  obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
>  obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o
> diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> new file mode 100644
> index 000..abe78d3
> --- /dev/null
> +++ b/drivers/iio/adc/ti-ads1015.c
> @@ -0,0 +1,616 @@
> +/*
> + * ADS1015 - Texas Instruments Analog-to-Digital Converter
> + *
> + * Copyright (c) 2016, Intel Corporation.
> + *
> + * This file is subject to the terms and conditions of version 2 of
> + * the GNU General Public License.  See the file COPYING in the main
> + * directory of this archive for more details.
> + *
> + * IIO driver for ADS1015 ADC 7-bit I2C slave address:
> + *   * 0x48 - ADDR connectd to Ground
> + *   * 0x49 - ADDR connected to Vdd
> + *   * 0x4A - ADDR connected to SDA
> + *   * 0x4B - ADDR connected to SCL
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define ADS1015_DRV_NAME "ads1015"
> +
> +#define ADS1015_CONV_REG 0x00
> +#define ADS1015_CFG_REG  0x01
> +
> +#define ADS1015_CFG_DR_SHIFT 5
> +#define ADS1015_CFG_MOD_SHIFT8
> +#define ADS1015_CFG_PGA_SHIFT9
> +#define ADS1015_CFG_MUX_SHIFT12
> +
> +#define ADS1015_CFG_DR_MASK  GENMASK(7, 5)
> +#define ADS1015_CFG_MOD_MASK BIT(8)
> +#define ADS1015_CFG_PGA_MASK GENMASK(11, 9)
> +#define ADS1015_CFG_MUX_MASK GENMASK(14, 12)
> +
> +/* device operating modes */
> +#define ADS1015_CONTINUOUS   0
> +#define ADS1015_SINGLESHOT   1
> +
> +#define ADS1015_SLEEP_DELAY_MS   2000
> +#define ADS1015_DEFAULT_PGA  2
> +#define ADS1015_DEFAULT_DATA_RATE4
> +#define ADS1015_DEFAULT_CHAN 0
> +
> +enum ads1015_channels {
> + ADS1015_AIN0_AIN1 = 0,
> + ADS1015_AIN0_AIN3,
> + ADS1015_AIN1_AIN3,
> + ADS1015_AIN2_AIN3,
> + ADS1015_AIN0,
> + ADS1015_AIN1,
> + ADS1015_AIN2,
> + ADS1015_AIN3,
> 

[PATCH v3] iio: adc: Add TI ADS1015 ADC driver support

2016-02-03 Thread Daniel Baluta
The driver has sysfs readings with runtime PM support for power saving.
It also offers buffer support that can be used together with IIO software
triggers.

Datasheet can be found here:
http://www.ti.com.cn/cn/lit/ds/symlink/ads1015.pdf

Signed-off-by: Daniel Baluta 
---
Changes since v2:
* push locking out of the switch in write_raw
* fix  buf allocation in triggered buffer's handler

Changes since v1:
* addressed concerns about replacing the ads1015 hwmon driver
* For the moment the IIO driver is compatible with hwmon
  driver (dt bindings) the only thing left is to also add
  support for ads1115.
* DT bindings are described in Documentation/devicetree/
  bindings/hwmon/ads1015.txt. If needed will copy this file
  in a later patch to the IIO corresponding location.
* addressed comments from Jonathan
* added proper locking
* added timestamp channel
* removed magic constants
* added some new lines to increase readability
* used regmap_get_device instead of keeping a copy of
i2c_client pointer.
* used non-devm function to correct the cleanup order

 drivers/iio/adc/Kconfig  |  13 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ti-ads1015.c | 616 +++
 3 files changed, 630 insertions(+)
 create mode 100644 drivers/iio/adc/ti-ads1015.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 60673b4..fad7e6a 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -370,6 +370,19 @@ config TI_ADC128S052
  This driver can also be built as a module. If so, the module will be
  called ti-adc128s052.
 
+config TI_ADS1015
+   tristate "Texas Instruments ADS1015 ADC"
+   depends on I2C && !SENSORS_ADS1015
+   select REGMAP_I2C
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+   help
+ If you say yes here you get support for Texas Instruments ADS1015
+ ADC chip.
+
+ This driver can also be built as a module. If so, the module will be
+ called ti-ads1015.
+
 config TI_ADS8688
tristate "Texas Instruments ADS8688"
depends on SPI && OF
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index fb57e12..2ff70a3 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
 obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o
+obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o
 obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
 obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
new file mode 100644
index 000..abe78d3
--- /dev/null
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -0,0 +1,616 @@
+/*
+ * ADS1015 - Texas Instruments Analog-to-Digital Converter
+ *
+ * Copyright (c) 2016, Intel Corporation.
+ *
+ * This file is subject to the terms and conditions of version 2 of
+ * the GNU General Public License.  See the file COPYING in the main
+ * directory of this archive for more details.
+ *
+ * IIO driver for ADS1015 ADC 7-bit I2C slave address:
+ * * 0x48 - ADDR connectd to Ground
+ * * 0x49 - ADDR connected to Vdd
+ * * 0x4A - ADDR connected to SDA
+ * * 0x4B - ADDR connected to SCL
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ADS1015_DRV_NAME "ads1015"
+
+#define ADS1015_CONV_REG   0x00
+#define ADS1015_CFG_REG0x01
+
+#define ADS1015_CFG_DR_SHIFT   5
+#define ADS1015_CFG_MOD_SHIFT  8
+#define ADS1015_CFG_PGA_SHIFT  9
+#define ADS1015_CFG_MUX_SHIFT  12
+
+#define ADS1015_CFG_DR_MASKGENMASK(7, 5)
+#define ADS1015_CFG_MOD_MASK   BIT(8)
+#define ADS1015_CFG_PGA_MASK   GENMASK(11, 9)
+#define ADS1015_CFG_MUX_MASK   GENMASK(14, 12)
+
+/* device operating modes */
+#define ADS1015_CONTINUOUS 0
+#define ADS1015_SINGLESHOT 1
+
+#define ADS1015_SLEEP_DELAY_MS 2000
+#define ADS1015_DEFAULT_PGA2
+#define ADS1015_DEFAULT_DATA_RATE  4
+#define ADS1015_DEFAULT_CHAN   0
+
+enum ads1015_channels {
+   ADS1015_AIN0_AIN1 = 0,
+   ADS1015_AIN0_AIN3,
+   ADS1015_AIN1_AIN3,
+   ADS1015_AIN2_AIN3,
+   ADS1015_AIN0,
+   ADS1015_AIN1,
+   ADS1015_AIN2,
+   ADS1015_AIN3,
+   ADS1015_TIMESTAMP,
+};
+
+static const unsigned int ads1015_data_rate[] = {
+   128, 250, 490, 920, 1600, 2400, 3300, 3300
+};
+
+static const struct {
+   int scale;
+   int uscale;
+} ads1015_scale[] = {
+   {3, 0},
+   {2, 0},
+   

Re: [PATCH v3] iio: adc: Add TI ADS1015 ADC driver support

2016-02-03 Thread Matt Ranostay
On Wed, Feb 3, 2016 at 8:59 AM, Daniel Baluta  wrote:
> The driver has sysfs readings with runtime PM support for power saving.
> It also offers buffer support that can be used together with IIO software
> triggers.
>
> Datasheet can be found here:
> http://www.ti.com.cn/cn/lit/ds/symlink/ads1015.pdf
>
> Signed-off-by: Daniel Baluta 
> ---
> Changes since v2:
> * push locking out of the switch in write_raw
> * fix  buf allocation in triggered buffer's handler
>
> Changes since v1:
> * addressed concerns about replacing the ads1015 hwmon driver
> * For the moment the IIO driver is compatible with hwmon
>   driver (dt bindings) the only thing left is to also add
>   support for ads1115.
> * DT bindings are described in Documentation/devicetree/
>   bindings/hwmon/ads1015.txt. If needed will copy this file
>   in a later patch to the IIO corresponding location.
> * addressed comments from Jonathan
> * added proper locking
> * added timestamp channel
> * removed magic constants
> * added some new lines to increase readability
> * used regmap_get_device instead of keeping a copy of
> i2c_client pointer.
> * used non-devm function to correct the cleanup order
>
>  drivers/iio/adc/Kconfig  |  13 +
>  drivers/iio/adc/Makefile |   1 +
>  drivers/iio/adc/ti-ads1015.c | 616 
> +++
>  3 files changed, 630 insertions(+)
>  create mode 100644 drivers/iio/adc/ti-ads1015.c
>
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 60673b4..fad7e6a 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -370,6 +370,19 @@ config TI_ADC128S052
>   This driver can also be built as a module. If so, the module will be
>   called ti-adc128s052.
>
> +config TI_ADS1015
> +   tristate "Texas Instruments ADS1015 ADC"
> +   depends on I2C && !SENSORS_ADS1015
> +   select REGMAP_I2C
> +   select IIO_BUFFER
> +   select IIO_TRIGGERED_BUFFER
> +   help
> + If you say yes here you get support for Texas Instruments ADS1015
> + ADC chip.
> +
> + This driver can also be built as a module. If so, the module will be
> + called ti-ads1015.
> +
>  config TI_ADS8688
> tristate "Texas Instruments ADS8688"
> depends on SPI && OF
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index fb57e12..2ff70a3 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -36,6 +36,7 @@ obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
>  obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
>  obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
>  obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o
> +obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o
>  obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o
>  obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
>  obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o
> diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> new file mode 100644
> index 000..abe78d3
> --- /dev/null
> +++ b/drivers/iio/adc/ti-ads1015.c
> @@ -0,0 +1,616 @@
> +/*
> + * ADS1015 - Texas Instruments Analog-to-Digital Converter
> + *
> + * Copyright (c) 2016, Intel Corporation.
> + *
> + * This file is subject to the terms and conditions of version 2 of
> + * the GNU General Public License.  See the file COPYING in the main
> + * directory of this archive for more details.
> + *
> + * IIO driver for ADS1015 ADC 7-bit I2C slave address:
> + * * 0x48 - ADDR connectd to Ground

typo here :).


> + * * 0x49 - ADDR connected to Vdd
> + * * 0x4A - ADDR connected to SDA
> + * * 0x4B - ADDR connected to SCL
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define ADS1015_DRV_NAME "ads1015"
> +
> +#define ADS1015_CONV_REG   0x00
> +#define ADS1015_CFG_REG0x01
> +
> +#define ADS1015_CFG_DR_SHIFT   5
> +#define ADS1015_CFG_MOD_SHIFT  8
> +#define ADS1015_CFG_PGA_SHIFT  9
> +#define ADS1015_CFG_MUX_SHIFT  12
> +
> +#define ADS1015_CFG_DR_MASKGENMASK(7, 5)
> +#define ADS1015_CFG_MOD_MASK   BIT(8)
> +#define ADS1015_CFG_PGA_MASK   GENMASK(11, 9)
> +#define ADS1015_CFG_MUX_MASK   GENMASK(14, 12)
> +
> +/* device operating modes */
> +#define ADS1015_CONTINUOUS 0
> +#define ADS1015_SINGLESHOT 1
> +
> +#define ADS1015_SLEEP_DELAY_MS 2000
> +#define ADS1015_DEFAULT_PGA2
> +#define ADS1015_DEFAULT_DATA_RATE  4
> +#define ADS1015_DEFAULT_CHAN   0
> +
> +enum ads1015_channels {
> +   ADS1015_AIN0_AIN1 = 0,
> +   ADS1015_AIN0_AIN3,
> +   

[PATCH v3] iio: adc: Add TI ADS1015 ADC driver support

2016-02-03 Thread Daniel Baluta
The driver has sysfs readings with runtime PM support for power saving.
It also offers buffer support that can be used together with IIO software
triggers.

Datasheet can be found here:
http://www.ti.com.cn/cn/lit/ds/symlink/ads1015.pdf

Signed-off-by: Daniel Baluta 
---
Changes since v2:
* push locking out of the switch in write_raw
* fix  buf allocation in triggered buffer's handler

Changes since v1:
* addressed concerns about replacing the ads1015 hwmon driver
* For the moment the IIO driver is compatible with hwmon
  driver (dt bindings) the only thing left is to also add
  support for ads1115.
* DT bindings are described in Documentation/devicetree/
  bindings/hwmon/ads1015.txt. If needed will copy this file
  in a later patch to the IIO corresponding location.
* addressed comments from Jonathan
* added proper locking
* added timestamp channel
* removed magic constants
* added some new lines to increase readability
* used regmap_get_device instead of keeping a copy of
i2c_client pointer.
* used non-devm function to correct the cleanup order

 drivers/iio/adc/Kconfig  |  13 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ti-ads1015.c | 616 +++
 3 files changed, 630 insertions(+)
 create mode 100644 drivers/iio/adc/ti-ads1015.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 60673b4..fad7e6a 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -370,6 +370,19 @@ config TI_ADC128S052
  This driver can also be built as a module. If so, the module will be
  called ti-adc128s052.
 
+config TI_ADS1015
+   tristate "Texas Instruments ADS1015 ADC"
+   depends on I2C && !SENSORS_ADS1015
+   select REGMAP_I2C
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+   help
+ If you say yes here you get support for Texas Instruments ADS1015
+ ADC chip.
+
+ This driver can also be built as a module. If so, the module will be
+ called ti-ads1015.
+
 config TI_ADS8688
tristate "Texas Instruments ADS8688"
depends on SPI && OF
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index fb57e12..2ff70a3 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
 obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o
+obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o
 obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
 obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
new file mode 100644
index 000..abe78d3
--- /dev/null
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -0,0 +1,616 @@
+/*
+ * ADS1015 - Texas Instruments Analog-to-Digital Converter
+ *
+ * Copyright (c) 2016, Intel Corporation.
+ *
+ * This file is subject to the terms and conditions of version 2 of
+ * the GNU General Public License.  See the file COPYING in the main
+ * directory of this archive for more details.
+ *
+ * IIO driver for ADS1015 ADC 7-bit I2C slave address:
+ * * 0x48 - ADDR connectd to Ground
+ * * 0x49 - ADDR connected to Vdd
+ * * 0x4A - ADDR connected to SDA
+ * * 0x4B - ADDR connected to SCL
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ADS1015_DRV_NAME "ads1015"
+
+#define ADS1015_CONV_REG   0x00
+#define ADS1015_CFG_REG0x01
+
+#define ADS1015_CFG_DR_SHIFT   5
+#define ADS1015_CFG_MOD_SHIFT  8
+#define ADS1015_CFG_PGA_SHIFT  9
+#define ADS1015_CFG_MUX_SHIFT  12
+
+#define ADS1015_CFG_DR_MASKGENMASK(7, 5)
+#define ADS1015_CFG_MOD_MASK   BIT(8)
+#define ADS1015_CFG_PGA_MASK   GENMASK(11, 9)
+#define ADS1015_CFG_MUX_MASK   GENMASK(14, 12)
+
+/* device operating modes */
+#define ADS1015_CONTINUOUS 0
+#define ADS1015_SINGLESHOT 1
+
+#define ADS1015_SLEEP_DELAY_MS 2000
+#define ADS1015_DEFAULT_PGA2
+#define ADS1015_DEFAULT_DATA_RATE  4
+#define ADS1015_DEFAULT_CHAN   0
+
+enum ads1015_channels {
+   ADS1015_AIN0_AIN1 = 0,
+   ADS1015_AIN0_AIN3,
+   ADS1015_AIN1_AIN3,
+   ADS1015_AIN2_AIN3,
+   ADS1015_AIN0,
+   ADS1015_AIN1,
+   ADS1015_AIN2,
+   ADS1015_AIN3,
+   ADS1015_TIMESTAMP,
+};
+
+static const unsigned int ads1015_data_rate[] = {
+   128, 250, 490, 920, 1600, 2400, 3300, 3300
+};
+
+static const struct {
+   int scale;
+   int uscale;
+} ads1015_scale[] = {
+   {3, 0},

Re: [PATCH v3] iio: adc: Add TI ADS1015 ADC driver support

2016-02-03 Thread Michael Welling
On Wed, Feb 03, 2016 at 06:59:56PM +0200, Daniel Baluta wrote:
> The driver has sysfs readings with runtime PM support for power saving.
> It also offers buffer support that can be used together with IIO software
> triggers.
> 
> Datasheet can be found here:
>   http://www.ti.com.cn/cn/lit/ds/symlink/ads1015.pdf
> 
> Signed-off-by: Daniel Baluta 
> ---
> Changes since v2:
>   * push locking out of the switch in write_raw
>   * fix  buf allocation in triggered buffer's handler
> 
> Changes since v1:
>   * addressed concerns about replacing the ads1015 hwmon driver
>   * For the moment the IIO driver is compatible with hwmon
> driver (dt bindings) the only thing left is to also add
> support for ads1115.
>   * DT bindings are described in Documentation/devicetree/
> bindings/hwmon/ads1015.txt. If needed will copy this file
> in a later patch to the IIO corresponding location.
>   * addressed comments from Jonathan
>   * added proper locking
>   * added timestamp channel
>   * removed magic constants
>   * added some new lines to increase readability
>   * used regmap_get_device instead of keeping a copy of
>   i2c_client pointer.
>   * used non-devm function to correct the cleanup order
> 
>  drivers/iio/adc/Kconfig  |  13 +
>  drivers/iio/adc/Makefile |   1 +
>  drivers/iio/adc/ti-ads1015.c | 616 
> +++
>  3 files changed, 630 insertions(+)
>  create mode 100644 drivers/iio/adc/ti-ads1015.c
> 
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 60673b4..fad7e6a 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -370,6 +370,19 @@ config TI_ADC128S052
> This driver can also be built as a module. If so, the module will be
> called ti-adc128s052.
>  
> +config TI_ADS1015
> + tristate "Texas Instruments ADS1015 ADC"
> + depends on I2C && !SENSORS_ADS1015
> + select REGMAP_I2C
> + select IIO_BUFFER
> + select IIO_TRIGGERED_BUFFER
> + help
> +   If you say yes here you get support for Texas Instruments ADS1015
> +   ADC chip.
> +
> +   This driver can also be built as a module. If so, the module will be
> +   called ti-ads1015.
> +
>  config TI_ADS8688
>   tristate "Texas Instruments ADS8688"
>   depends on SPI && OF
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index fb57e12..2ff70a3 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -36,6 +36,7 @@ obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
>  obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
>  obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
>  obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o
> +obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o
>  obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o
>  obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
>  obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o
> diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> new file mode 100644
> index 000..abe78d3
> --- /dev/null
> +++ b/drivers/iio/adc/ti-ads1015.c
> @@ -0,0 +1,616 @@
> +/*
> + * ADS1015 - Texas Instruments Analog-to-Digital Converter
> + *
> + * Copyright (c) 2016, Intel Corporation.
> + *
> + * This file is subject to the terms and conditions of version 2 of
> + * the GNU General Public License.  See the file COPYING in the main
> + * directory of this archive for more details.
> + *
> + * IIO driver for ADS1015 ADC 7-bit I2C slave address:
> + *   * 0x48 - ADDR connectd to Ground
> + *   * 0x49 - ADDR connected to Vdd
> + *   * 0x4A - ADDR connected to SDA
> + *   * 0x4B - ADDR connected to SCL
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define ADS1015_DRV_NAME "ads1015"
> +
> +#define ADS1015_CONV_REG 0x00
> +#define ADS1015_CFG_REG  0x01
> +
> +#define ADS1015_CFG_DR_SHIFT 5
> +#define ADS1015_CFG_MOD_SHIFT8
> +#define ADS1015_CFG_PGA_SHIFT9
> +#define ADS1015_CFG_MUX_SHIFT12
> +
> +#define ADS1015_CFG_DR_MASK  GENMASK(7, 5)
> +#define ADS1015_CFG_MOD_MASK BIT(8)
> +#define ADS1015_CFG_PGA_MASK GENMASK(11, 9)
> +#define ADS1015_CFG_MUX_MASK GENMASK(14, 12)
> +
> +/* device operating modes */
> +#define ADS1015_CONTINUOUS   0
> +#define ADS1015_SINGLESHOT   1
> +
> +#define ADS1015_SLEEP_DELAY_MS   2000
> +#define ADS1015_DEFAULT_PGA  2
> +#define ADS1015_DEFAULT_DATA_RATE4
> +#define ADS1015_DEFAULT_CHAN 0
> +
> +enum ads1015_channels {
> + ADS1015_AIN0_AIN1 = 0,
> + ADS1015_AIN0_AIN3,
> + ADS1015_AIN1_AIN3,
> + ADS1015_AIN2_AIN3,
> + ADS1015_AIN0,
> + ADS1015_AIN1,
> +