Re: [PATCH v2] iio: add support of the max1027

2014-05-27 Thread Jonathan Cameron


On May 27, 2014 8:24:11 PM CEST, trem  wrote:
>Hi,
>
>
>On 26/05/14 22:27, Lars-Peter Clausen wrote:
>> On 05/20/2014 11:27 PM, Philippe Reynes wrote:
>>> This driver add partial support of the
>>> maxim 1027/1029/1031. Differential mode is not
>>> supported.
>>>
>>> It was tested on armadeus apf27 board.
>>>
>>> Signed-off-by: Philippe Reynes
>>> ---
>>>.../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
>>>drivers/staging/iio/adc/Kconfig|9 +
>>>drivers/staging/iio/adc/Makefile   |1 +
>>>drivers/staging/iio/adc/max1027.c  |  553
>
>>
>> New drivers should go into drivers/iio/
>
>I'll be pleased to add this driver in drivers/iio/
>Everybody agrees ??
I do. 

Jonathan
>  
>>>4 files changed, 584 insertions(+), 0 deletions(-)
>>>create mode 100644
>Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
>>>create mode 100644 drivers/staging/iio/adc/max1027.c
>> [...]
>>
>
>Regards,
>Philippe

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
--
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 v2] iio: add support of the max1027

2014-05-27 Thread trem

Hi,


On 26/05/14 22:27, Lars-Peter Clausen wrote:

On 05/20/2014 11:27 PM, Philippe Reynes wrote:

This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynes
---
   .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
   drivers/staging/iio/adc/Kconfig|9 +
   drivers/staging/iio/adc/Makefile   |1 +
   drivers/staging/iio/adc/max1027.c  |  553 



New drivers should go into drivers/iio/


I'll be pleased to add this driver in drivers/iio/
Everybody agrees ??
 

   4 files changed, 584 insertions(+), 0 deletions(-)
   create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
   create mode 100644 drivers/staging/iio/adc/max1027.c

[...]



Regards,
Philippe
--
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 v2] iio: add support of the max1027

2014-05-27 Thread trem

Hi Harmut,


On 27/05/14 00:33, Hartmut Knaack wrote:

trem schrieb:

Hi Hartmut,

First, thanks a lot for this feedback, I really appreciate it.


On 26/05/14 00:52, Hartmut Knaack wrote:

Philippe Reynes schrieb:

This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynes
---
   .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
   drivers/staging/iio/adc/Kconfig|9 +
   drivers/staging/iio/adc/Makefile   |1 +
   drivers/staging/iio/adc/max1027.c  |  553 

   4 files changed, 584 insertions(+), 0 deletions(-)
   create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
   create mode 100644 drivers/staging/iio/adc/max1027.c

Changelog:
v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
- really use devm_*
- use demux magic
- use spi_read and spi_write (instead of spi_sync)
- use define for register (instead of hardcoded value)

diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
new file mode 100644
index 000..2e8b9f3
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
@@ -0,0 +1,21 @@
+* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
+
+Required properties:
+  - compatible: Should be "maxim,max1027" or "maxim,max1029" or "maxim,max1031"
+  - reg: Should contain the ADC SPI address
+  - interrupt-parent: the phandle for the gpio controller
+  - interrupts: (gpio) interrupt to which the chip is connected
+
+Example:
+adc@0 {
+   compatible = "maxim,max1027";
+   reg =<0>;
+   interrupt-parent =<>;
+   interrupts =<15 IRQ_TYPE_EDGE_RISING>;
+   pinctrl-names = "default";
+   pinctrl-0 =<_max1027>;
+   /* SPI mode = 0 */
+   spi-cpol =<0>;
+   spi-cpha =<0>;
+   spi-max-frequency =<100>;
+};
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 3633298..12a78eb 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -112,6 +112,15 @@ config LPC32XX_ADC
  activate only one via device tree selection.  Provides direct access
  via sysfs.

+config MAX1027
+   tristate "Maxim max1027 ADC driver"
+   depends on SPI
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say yes here to build support for Maxim SPI ADC models
+ max1027, max1029 and max1031.
+
   config MXS_LRADC
tristate "Freescale i.MX23/i.MX28 LRADC"
depends on ARCH_MXS || COMPILE_TEST
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index 3e9fb14..22fbd0c 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) += ad7816.o
   obj-$(CONFIG_AD7192) += ad7192.o
   obj-$(CONFIG_AD7280) += ad7280a.o
   obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
+obj-$(CONFIG_MAX1027) += max1027.o
   obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
   obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
diff --git a/drivers/staging/iio/adc/max1027.c 
b/drivers/staging/iio/adc/max1027.c
new file mode 100644
index 000..c2e5936
--- /dev/null
+++ b/drivers/staging/iio/adc/max1027.c
@@ -0,0 +1,553 @@
+ /*
+  * iio/adc/max1027.c
+  * Copyright (C) 2014 Philippe Reynes
+  *
+  * based on linux/drivers/iio/ad7923.c
+  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
+  * Copyright 2012 CS Systemes d'Information
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License version 2 as
+  * published by the Free Software Foundation.
+  *
+  * max1027.c
+  *
+  * Partial support for max1027 and similar chips.
+  */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#define MAX1027_CONV_REG  0x80
+#define MAX1027_SETUP_REG 0x40
+#define MAX1027_AVG_REG   0x20
+#define MAX1027_RST_REG   0x10
+
+/* conversion register */
+#define MAX1027_TEMP  0x01
+#define MAX1027_SCAN_0_N  (0x00<<   1)
+#define MAX1027_SCAN_N_M  (0x01<<   1)
+#define MAX1027_SCAN_N(0x02<<   1)
+#define MAX1027_NOSCAN(0x03<<   1)
+#define MAX1027_CHAN(n)   ((n)<<   3)
+
+/* setup register */
+#define MAX1027_UNIPOLAR  0x02
+#define MAX1027_BIPOLAR   0x03
+#define MAX1027_REF_MODE0 (0x00<<   2)
+#define MAX1027_REF_MODE1 (0x01<<   2)
+#define MAX1027_REF_MODE2 (0x02<<   2)
+#define MAX1027_REF_MODE3 (0x03<<   2)
+#define MAX1027_CKS_MODE0 (0x00<<   4)
+#define MAX1027_CKS_MODE1 (0x01<<   4)
+#define MAX1027_CKS_MODE2 (0x02<<   4)
+#define MAX1027_CKS_MODE3 (0x03<<   4)
+
+/* averaging register */
+#define MAX1027_NSCAN_4   0x00
+#define MAX1027_NSCAN_8   0x01
+#define MAX1027_NSCAN_12  0x02
+#define MAX1027_NSCAN_16 

Re: [PATCH v2] iio: add support of the max1027

2014-05-27 Thread trem

Hi Harmut,


On 27/05/14 00:33, Hartmut Knaack wrote:

trem schrieb:

Hi Hartmut,

First, thanks a lot for this feedback, I really appreciate it.


On 26/05/14 00:52, Hartmut Knaack wrote:

Philippe Reynes schrieb:

This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynestrem...@yahoo.fr
---
   .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
   drivers/staging/iio/adc/Kconfig|9 +
   drivers/staging/iio/adc/Makefile   |1 +
   drivers/staging/iio/adc/max1027.c  |  553 

   4 files changed, 584 insertions(+), 0 deletions(-)
   create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
   create mode 100644 drivers/staging/iio/adc/max1027.c

Changelog:
v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
- really use devm_*
- use demux magic
- use spi_read and spi_write (instead of spi_sync)
- use define for register (instead of hardcoded value)

diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
new file mode 100644
index 000..2e8b9f3
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
@@ -0,0 +1,21 @@
+* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
+
+Required properties:
+  - compatible: Should be maxim,max1027 or maxim,max1029 or maxim,max1031
+  - reg: Should contain the ADC SPI address
+  - interrupt-parent: the phandle for the gpio controller
+  - interrupts: (gpio) interrupt to which the chip is connected
+
+Example:
+adc@0 {
+   compatible = maxim,max1027;
+   reg =0;
+   interrupt-parent =gpio5;
+   interrupts =15 IRQ_TYPE_EDGE_RISING;
+   pinctrl-names = default;
+   pinctrl-0 =pinctrl_max1027;
+   /* SPI mode = 0 */
+   spi-cpol =0;
+   spi-cpha =0;
+   spi-max-frequency =100;
+};
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 3633298..12a78eb 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -112,6 +112,15 @@ config LPC32XX_ADC
  activate only one via device tree selection.  Provides direct access
  via sysfs.

+config MAX1027
+   tristate Maxim max1027 ADC driver
+   depends on SPI
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say yes here to build support for Maxim SPI ADC models
+ max1027, max1029 and max1031.
+
   config MXS_LRADC
tristate Freescale i.MX23/i.MX28 LRADC
depends on ARCH_MXS || COMPILE_TEST
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index 3e9fb14..22fbd0c 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) += ad7816.o
   obj-$(CONFIG_AD7192) += ad7192.o
   obj-$(CONFIG_AD7280) += ad7280a.o
   obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
+obj-$(CONFIG_MAX1027) += max1027.o
   obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
   obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
diff --git a/drivers/staging/iio/adc/max1027.c 
b/drivers/staging/iio/adc/max1027.c
new file mode 100644
index 000..c2e5936
--- /dev/null
+++ b/drivers/staging/iio/adc/max1027.c
@@ -0,0 +1,553 @@
+ /*
+  * iio/adc/max1027.c
+  * Copyright (C) 2014 Philippe Reynes
+  *
+  * based on linux/drivers/iio/ad7923.c
+  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
+  * Copyright 2012 CS Systemes d'Information
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License version 2 as
+  * published by the Free Software Foundation.
+  *
+  * max1027.c
+  *
+  * Partial support for max1027 and similar chips.
+  */
+
+#includelinux/kernel.h
+#includelinux/spi/spi.h
+#includelinux/module.h
+#includelinux/interrupt.h
+#includelinux/mutex.h
+#includelinux/of.h
+#includelinux/of_gpio.h
+#includelinux/platform_device.h
+#includelinux/delay.h
+#includelinux/gpio.h
+
+#includelinux/iio/iio.h
+#includelinux/iio/buffer.h
+#includelinux/iio/trigger.h
+#includelinux/iio/trigger_consumer.h
+#includelinux/iio/triggered_buffer.h
+
+#define MAX1027_CONV_REG  0x80
+#define MAX1027_SETUP_REG 0x40
+#define MAX1027_AVG_REG   0x20
+#define MAX1027_RST_REG   0x10
+
+/* conversion register */
+#define MAX1027_TEMP  0x01
+#define MAX1027_SCAN_0_N  (0x00   1)
+#define MAX1027_SCAN_N_M  (0x01   1)
+#define MAX1027_SCAN_N(0x02   1)
+#define MAX1027_NOSCAN(0x03   1)
+#define MAX1027_CHAN(n)   ((n)   3)
+
+/* setup register */
+#define MAX1027_UNIPOLAR  0x02
+#define MAX1027_BIPOLAR   0x03
+#define MAX1027_REF_MODE0 (0x00   2)
+#define MAX1027_REF_MODE1 (0x01   2)
+#define MAX1027_REF_MODE2 (0x02   2)
+#define MAX1027_REF_MODE3 (0x03   2)
+#define MAX1027_CKS_MODE0 (0x00   4)
+#define MAX1027_CKS_MODE1 (0x01   

Re: [PATCH v2] iio: add support of the max1027

2014-05-27 Thread trem

Hi,


On 26/05/14 22:27, Lars-Peter Clausen wrote:

On 05/20/2014 11:27 PM, Philippe Reynes wrote:

This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynestrem...@yahoo.fr
---
   .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
   drivers/staging/iio/adc/Kconfig|9 +
   drivers/staging/iio/adc/Makefile   |1 +
   drivers/staging/iio/adc/max1027.c  |  553 



New drivers should go into drivers/iio/


I'll be pleased to add this driver in drivers/iio/
Everybody agrees ??
 

   4 files changed, 584 insertions(+), 0 deletions(-)
   create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
   create mode 100644 drivers/staging/iio/adc/max1027.c

[...]



Regards,
Philippe
--
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 v2] iio: add support of the max1027

2014-05-27 Thread Jonathan Cameron


On May 27, 2014 8:24:11 PM CEST, trem trem...@yahoo.fr wrote:
Hi,


On 26/05/14 22:27, Lars-Peter Clausen wrote:
 On 05/20/2014 11:27 PM, Philippe Reynes wrote:
 This driver add partial support of the
 maxim 1027/1029/1031. Differential mode is not
 supported.

 It was tested on armadeus apf27 board.

 Signed-off-by: Philippe Reynestrem...@yahoo.fr
 ---
.../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
drivers/staging/iio/adc/Kconfig|9 +
drivers/staging/iio/adc/Makefile   |1 +
drivers/staging/iio/adc/max1027.c  |  553


 New drivers should go into drivers/iio/

I'll be pleased to add this driver in drivers/iio/
Everybody agrees ??
I do. 

Jonathan
  
4 files changed, 584 insertions(+), 0 deletions(-)
create mode 100644
Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
create mode 100644 drivers/staging/iio/adc/max1027.c
 [...]


Regards,
Philippe

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
--
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 v2] iio: add support of the max1027

2014-05-26 Thread Hartmut Knaack
trem schrieb:
> Hi Hartmut,
>
> First, thanks a lot for this feedback, I really appreciate it.
>
>
> On 26/05/14 00:52, Hartmut Knaack wrote:
>> Philippe Reynes schrieb:
>>> This driver add partial support of the
>>> maxim 1027/1029/1031. Differential mode is not
>>> supported.
>>>
>>> It was tested on armadeus apf27 board.
>>>
>>> Signed-off-by: Philippe Reynes
>>> ---
>>>   .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
>>>   drivers/staging/iio/adc/Kconfig|9 +
>>>   drivers/staging/iio/adc/Makefile   |1 +
>>>   drivers/staging/iio/adc/max1027.c  |  553 
>>> 
>>>   4 files changed, 584 insertions(+), 0 deletions(-)
>>>   create mode 100644 
>>> Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
>>>   create mode 100644 drivers/staging/iio/adc/max1027.c
>>>
>>> Changelog:
>>> v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
>>> - really use devm_*
>>> - use demux magic
>>> - use spi_read and spi_write (instead of spi_sync)
>>> - use define for register (instead of hardcoded value)
>>>
>>> diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
>>> b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
>>> new file mode 100644
>>> index 000..2e8b9f3
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
>>> @@ -0,0 +1,21 @@
>>> +* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
>>> +
>>> +Required properties:
>>> +  - compatible: Should be "maxim,max1027" or "maxim,max1029" or 
>>> "maxim,max1031"
>>> +  - reg: Should contain the ADC SPI address
>>> +  - interrupt-parent: the phandle for the gpio controller
>>> +  - interrupts: (gpio) interrupt to which the chip is connected
>>> +
>>> +Example:
>>> +adc@0 {
>>> +   compatible = "maxim,max1027";
>>> +   reg =<0>;
>>> +   interrupt-parent =<>;
>>> +   interrupts =<15 IRQ_TYPE_EDGE_RISING>;
>>> +   pinctrl-names = "default";
>>> +   pinctrl-0 =<_max1027>;
>>> +   /* SPI mode = 0 */
>>> +   spi-cpol =<0>;
>>> +   spi-cpha =<0>;
>>> +   spi-max-frequency =<100>;
>>> +};
>>> diff --git a/drivers/staging/iio/adc/Kconfig 
>>> b/drivers/staging/iio/adc/Kconfig
>>> index 3633298..12a78eb 100644
>>> --- a/drivers/staging/iio/adc/Kconfig
>>> +++ b/drivers/staging/iio/adc/Kconfig
>>> @@ -112,6 +112,15 @@ config LPC32XX_ADC
>>>   activate only one via device tree selection.  Provides direct access
>>>   via sysfs.
>>>
>>> +config MAX1027
>>> +   tristate "Maxim max1027 ADC driver"
>>> +   depends on SPI
>>> +   select IIO_BUFFER
>>> +   select IIO_TRIGGERED_BUFFER
>>> +   help
>>> + Say yes here to build support for Maxim SPI ADC models
>>> + max1027, max1029 and max1031.
>>> +
>>>   config MXS_LRADC
>>> tristate "Freescale i.MX23/i.MX28 LRADC"
>>> depends on ARCH_MXS || COMPILE_TEST
>>> diff --git a/drivers/staging/iio/adc/Makefile 
>>> b/drivers/staging/iio/adc/Makefile
>>> index 3e9fb14..22fbd0c 100644
>>> --- a/drivers/staging/iio/adc/Makefile
>>> +++ b/drivers/staging/iio/adc/Makefile
>>> @@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) += ad7816.o
>>>   obj-$(CONFIG_AD7192) += ad7192.o
>>>   obj-$(CONFIG_AD7280) += ad7280a.o
>>>   obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
>>> +obj-$(CONFIG_MAX1027) += max1027.o
>>>   obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
>>>   obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
>>> diff --git a/drivers/staging/iio/adc/max1027.c 
>>> b/drivers/staging/iio/adc/max1027.c
>>> new file mode 100644
>>> index 000..c2e5936
>>> --- /dev/null
>>> +++ b/drivers/staging/iio/adc/max1027.c
>>> @@ -0,0 +1,553 @@
>>> + /*
>>> +  * iio/adc/max1027.c
>>> +  * Copyright (C) 2014 Philippe Reynes
>>> +  *
>>> +  * based on linux/drivers/iio/ad7923.c
>>> +  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
>>> +  * Copyright 2012 CS Systemes d'Information
>>> +  *
>>> +  * This program is free software; you can redistribute it and/or modify
>>> +  * it under the terms of the GNU General Public License version 2 as
>>> +  * published by the Free Software Foundation.
>>> +  *
>>> +  * max1027.c
>>> +  *
>>> +  * Partial support for max1027 and similar chips.
>>> +  */
>>> +
>>> +#include
>>> +#include
>>> +#include
>>> +#include
>>> +#include
>>> +#include
>>> +#include
>>> +#include
>>> +#include
>>> +#include
>>> +
>>> +#include
>>> +#include
>>> +#include
>>> +#include
>>> +#include
>>> +
>>> +#define MAX1027_CONV_REG  0x80
>>> +#define MAX1027_SETUP_REG 0x40
>>> +#define MAX1027_AVG_REG   0x20
>>> +#define MAX1027_RST_REG   0x10
>>> +
>>> +/* conversion register */
>>> +#define MAX1027_TEMP  0x01
>>> +#define MAX1027_SCAN_0_N  (0x00<<  1)
>>> +#define MAX1027_SCAN_N_M  (0x01<<  1)
>>> +#define MAX1027_SCAN_N(0x02<<  1)
>>> +#define MAX1027_NOSCAN(0x03<<  1)
>>> +#define MAX1027_CHAN(n)   ((n)<<  3)
>>> +
>>> +/* setup register */
>>> +#define MAX1027_UNIPOLAR  0x02
>>> +#define MAX1027_BIPOLAR   0x03
>>> +#define MAX1027_REF_MODE0 (0x00<<  2)

Re: [PATCH v2] iio: add support of the max1027

2014-05-26 Thread Lars-Peter Clausen

On 05/20/2014 11:27 PM, Philippe Reynes wrote:

This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynes 
---
  .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
  drivers/staging/iio/adc/Kconfig|9 +
  drivers/staging/iio/adc/Makefile   |1 +
  drivers/staging/iio/adc/max1027.c  |  553 


New drivers should go into drivers/iio/


  4 files changed, 584 insertions(+), 0 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
  create mode 100644 drivers/staging/iio/adc/max1027.c

[...]
--
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 v2] iio: add support of the max1027

2014-05-26 Thread trem

Hi Hartmut,

First, thanks a lot for this feedback, I really appreciate it.


On 26/05/14 00:52, Hartmut Knaack wrote:

Philippe Reynes schrieb:

This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynes
---
  .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
  drivers/staging/iio/adc/Kconfig|9 +
  drivers/staging/iio/adc/Makefile   |1 +
  drivers/staging/iio/adc/max1027.c  |  553 
  4 files changed, 584 insertions(+), 0 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
  create mode 100644 drivers/staging/iio/adc/max1027.c

Changelog:
v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
- really use devm_*
- use demux magic
- use spi_read and spi_write (instead of spi_sync)
- use define for register (instead of hardcoded value)

diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
new file mode 100644
index 000..2e8b9f3
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
@@ -0,0 +1,21 @@
+* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
+
+Required properties:
+  - compatible: Should be "maxim,max1027" or "maxim,max1029" or "maxim,max1031"
+  - reg: Should contain the ADC SPI address
+  - interrupt-parent: the phandle for the gpio controller
+  - interrupts: (gpio) interrupt to which the chip is connected
+
+Example:
+adc@0 {
+   compatible = "maxim,max1027";
+   reg =<0>;
+   interrupt-parent =<>;
+   interrupts =<15 IRQ_TYPE_EDGE_RISING>;
+   pinctrl-names = "default";
+   pinctrl-0 =<_max1027>;
+   /* SPI mode = 0 */
+   spi-cpol =<0>;
+   spi-cpha =<0>;
+   spi-max-frequency =<100>;
+};
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 3633298..12a78eb 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -112,6 +112,15 @@ config LPC32XX_ADC
  activate only one via device tree selection.  Provides direct access
  via sysfs.

+config MAX1027
+   tristate "Maxim max1027 ADC driver"
+   depends on SPI
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say yes here to build support for Maxim SPI ADC models
+ max1027, max1029 and max1031.
+
  config MXS_LRADC
tristate "Freescale i.MX23/i.MX28 LRADC"
depends on ARCH_MXS || COMPILE_TEST
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index 3e9fb14..22fbd0c 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) += ad7816.o
  obj-$(CONFIG_AD7192) += ad7192.o
  obj-$(CONFIG_AD7280) += ad7280a.o
  obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
+obj-$(CONFIG_MAX1027) += max1027.o
  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
  obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
diff --git a/drivers/staging/iio/adc/max1027.c 
b/drivers/staging/iio/adc/max1027.c
new file mode 100644
index 000..c2e5936
--- /dev/null
+++ b/drivers/staging/iio/adc/max1027.c
@@ -0,0 +1,553 @@
+ /*
+  * iio/adc/max1027.c
+  * Copyright (C) 2014 Philippe Reynes
+  *
+  * based on linux/drivers/iio/ad7923.c
+  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
+  * Copyright 2012 CS Systemes d'Information
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License version 2 as
+  * published by the Free Software Foundation.
+  *
+  * max1027.c
+  *
+  * Partial support for max1027 and similar chips.
+  */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#define MAX1027_CONV_REG  0x80
+#define MAX1027_SETUP_REG 0x40
+#define MAX1027_AVG_REG   0x20
+#define MAX1027_RST_REG   0x10
+
+/* conversion register */
+#define MAX1027_TEMP  0x01
+#define MAX1027_SCAN_0_N  (0x00<<  1)
+#define MAX1027_SCAN_N_M  (0x01<<  1)
+#define MAX1027_SCAN_N(0x02<<  1)
+#define MAX1027_NOSCAN(0x03<<  1)
+#define MAX1027_CHAN(n)   ((n)<<  3)
+
+/* setup register */
+#define MAX1027_UNIPOLAR  0x02
+#define MAX1027_BIPOLAR   0x03
+#define MAX1027_REF_MODE0 (0x00<<  2)
+#define MAX1027_REF_MODE1 (0x01<<  2)
+#define MAX1027_REF_MODE2 (0x02<<  2)
+#define MAX1027_REF_MODE3 (0x03<<  2)
+#define MAX1027_CKS_MODE0 (0x00<<  4)
+#define MAX1027_CKS_MODE1 (0x01<<  4)
+#define MAX1027_CKS_MODE2 (0x02<<  4)
+#define MAX1027_CKS_MODE3 (0x03<<  4)
+
+/* averaging register */
+#define MAX1027_NSCAN_4   0x00
+#define MAX1027_NSCAN_8   0x01
+#define MAX1027_NSCAN_12  0x02
+#define MAX1027_NSCAN_16  0x03
+#define MAX1027_NAVG_4(0x00<<  2)
+#define MAX1027_NAVG_8(0x01<<  2)
+#define 

Re: [PATCH v2] iio: add support of the max1027

2014-05-26 Thread trem

Hi Hartmut,

First, thanks a lot for this feedback, I really appreciate it.


On 26/05/14 00:52, Hartmut Knaack wrote:

Philippe Reynes schrieb:

This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynestrem...@yahoo.fr
---
  .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
  drivers/staging/iio/adc/Kconfig|9 +
  drivers/staging/iio/adc/Makefile   |1 +
  drivers/staging/iio/adc/max1027.c  |  553 
  4 files changed, 584 insertions(+), 0 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
  create mode 100644 drivers/staging/iio/adc/max1027.c

Changelog:
v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
- really use devm_*
- use demux magic
- use spi_read and spi_write (instead of spi_sync)
- use define for register (instead of hardcoded value)

diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
new file mode 100644
index 000..2e8b9f3
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
@@ -0,0 +1,21 @@
+* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
+
+Required properties:
+  - compatible: Should be maxim,max1027 or maxim,max1029 or maxim,max1031
+  - reg: Should contain the ADC SPI address
+  - interrupt-parent: the phandle for the gpio controller
+  - interrupts: (gpio) interrupt to which the chip is connected
+
+Example:
+adc@0 {
+   compatible = maxim,max1027;
+   reg =0;
+   interrupt-parent =gpio5;
+   interrupts =15 IRQ_TYPE_EDGE_RISING;
+   pinctrl-names = default;
+   pinctrl-0 =pinctrl_max1027;
+   /* SPI mode = 0 */
+   spi-cpol =0;
+   spi-cpha =0;
+   spi-max-frequency =100;
+};
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 3633298..12a78eb 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -112,6 +112,15 @@ config LPC32XX_ADC
  activate only one via device tree selection.  Provides direct access
  via sysfs.

+config MAX1027
+   tristate Maxim max1027 ADC driver
+   depends on SPI
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say yes here to build support for Maxim SPI ADC models
+ max1027, max1029 and max1031.
+
  config MXS_LRADC
tristate Freescale i.MX23/i.MX28 LRADC
depends on ARCH_MXS || COMPILE_TEST
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index 3e9fb14..22fbd0c 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) += ad7816.o
  obj-$(CONFIG_AD7192) += ad7192.o
  obj-$(CONFIG_AD7280) += ad7280a.o
  obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
+obj-$(CONFIG_MAX1027) += max1027.o
  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
  obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
diff --git a/drivers/staging/iio/adc/max1027.c 
b/drivers/staging/iio/adc/max1027.c
new file mode 100644
index 000..c2e5936
--- /dev/null
+++ b/drivers/staging/iio/adc/max1027.c
@@ -0,0 +1,553 @@
+ /*
+  * iio/adc/max1027.c
+  * Copyright (C) 2014 Philippe Reynes
+  *
+  * based on linux/drivers/iio/ad7923.c
+  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
+  * Copyright 2012 CS Systemes d'Information
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License version 2 as
+  * published by the Free Software Foundation.
+  *
+  * max1027.c
+  *
+  * Partial support for max1027 and similar chips.
+  */
+
+#includelinux/kernel.h
+#includelinux/spi/spi.h
+#includelinux/module.h
+#includelinux/interrupt.h
+#includelinux/mutex.h
+#includelinux/of.h
+#includelinux/of_gpio.h
+#includelinux/platform_device.h
+#includelinux/delay.h
+#includelinux/gpio.h
+
+#includelinux/iio/iio.h
+#includelinux/iio/buffer.h
+#includelinux/iio/trigger.h
+#includelinux/iio/trigger_consumer.h
+#includelinux/iio/triggered_buffer.h
+
+#define MAX1027_CONV_REG  0x80
+#define MAX1027_SETUP_REG 0x40
+#define MAX1027_AVG_REG   0x20
+#define MAX1027_RST_REG   0x10
+
+/* conversion register */
+#define MAX1027_TEMP  0x01
+#define MAX1027_SCAN_0_N  (0x00  1)
+#define MAX1027_SCAN_N_M  (0x01  1)
+#define MAX1027_SCAN_N(0x02  1)
+#define MAX1027_NOSCAN(0x03  1)
+#define MAX1027_CHAN(n)   ((n)  3)
+
+/* setup register */
+#define MAX1027_UNIPOLAR  0x02
+#define MAX1027_BIPOLAR   0x03
+#define MAX1027_REF_MODE0 (0x00  2)
+#define MAX1027_REF_MODE1 (0x01  2)
+#define MAX1027_REF_MODE2 (0x02  2)
+#define MAX1027_REF_MODE3 (0x03  2)
+#define MAX1027_CKS_MODE0 (0x00  4)
+#define MAX1027_CKS_MODE1 (0x01  4)
+#define MAX1027_CKS_MODE2 (0x02  4)
+#define MAX1027_CKS_MODE3 (0x03  4)
+
+/* averaging 

Re: [PATCH v2] iio: add support of the max1027

2014-05-26 Thread Lars-Peter Clausen

On 05/20/2014 11:27 PM, Philippe Reynes wrote:

This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynes trem...@yahoo.fr
---
  .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
  drivers/staging/iio/adc/Kconfig|9 +
  drivers/staging/iio/adc/Makefile   |1 +
  drivers/staging/iio/adc/max1027.c  |  553 


New drivers should go into drivers/iio/


  4 files changed, 584 insertions(+), 0 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
  create mode 100644 drivers/staging/iio/adc/max1027.c

[...]
--
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 v2] iio: add support of the max1027

2014-05-26 Thread Hartmut Knaack
trem schrieb:
 Hi Hartmut,

 First, thanks a lot for this feedback, I really appreciate it.


 On 26/05/14 00:52, Hartmut Knaack wrote:
 Philippe Reynes schrieb:
 This driver add partial support of the
 maxim 1027/1029/1031. Differential mode is not
 supported.

 It was tested on armadeus apf27 board.

 Signed-off-by: Philippe Reynestrem...@yahoo.fr
 ---
   .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
   drivers/staging/iio/adc/Kconfig|9 +
   drivers/staging/iio/adc/Makefile   |1 +
   drivers/staging/iio/adc/max1027.c  |  553 
 
   4 files changed, 584 insertions(+), 0 deletions(-)
   create mode 100644 
 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
   create mode 100644 drivers/staging/iio/adc/max1027.c

 Changelog:
 v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
 - really use devm_*
 - use demux magic
 - use spi_read and spi_write (instead of spi_sync)
 - use define for register (instead of hardcoded value)

 diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
 b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
 new file mode 100644
 index 000..2e8b9f3
 --- /dev/null
 +++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
 @@ -0,0 +1,21 @@
 +* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
 +
 +Required properties:
 +  - compatible: Should be maxim,max1027 or maxim,max1029 or 
 maxim,max1031
 +  - reg: Should contain the ADC SPI address
 +  - interrupt-parent: the phandle for the gpio controller
 +  - interrupts: (gpio) interrupt to which the chip is connected
 +
 +Example:
 +adc@0 {
 +   compatible = maxim,max1027;
 +   reg =0;
 +   interrupt-parent =gpio5;
 +   interrupts =15 IRQ_TYPE_EDGE_RISING;
 +   pinctrl-names = default;
 +   pinctrl-0 =pinctrl_max1027;
 +   /* SPI mode = 0 */
 +   spi-cpol =0;
 +   spi-cpha =0;
 +   spi-max-frequency =100;
 +};
 diff --git a/drivers/staging/iio/adc/Kconfig 
 b/drivers/staging/iio/adc/Kconfig
 index 3633298..12a78eb 100644
 --- a/drivers/staging/iio/adc/Kconfig
 +++ b/drivers/staging/iio/adc/Kconfig
 @@ -112,6 +112,15 @@ config LPC32XX_ADC
   activate only one via device tree selection.  Provides direct access
   via sysfs.

 +config MAX1027
 +   tristate Maxim max1027 ADC driver
 +   depends on SPI
 +   select IIO_BUFFER
 +   select IIO_TRIGGERED_BUFFER
 +   help
 + Say yes here to build support for Maxim SPI ADC models
 + max1027, max1029 and max1031.
 +
   config MXS_LRADC
 tristate Freescale i.MX23/i.MX28 LRADC
 depends on ARCH_MXS || COMPILE_TEST
 diff --git a/drivers/staging/iio/adc/Makefile 
 b/drivers/staging/iio/adc/Makefile
 index 3e9fb14..22fbd0c 100644
 --- a/drivers/staging/iio/adc/Makefile
 +++ b/drivers/staging/iio/adc/Makefile
 @@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) += ad7816.o
   obj-$(CONFIG_AD7192) += ad7192.o
   obj-$(CONFIG_AD7280) += ad7280a.o
   obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
 +obj-$(CONFIG_MAX1027) += max1027.o
   obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
   obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
 diff --git a/drivers/staging/iio/adc/max1027.c 
 b/drivers/staging/iio/adc/max1027.c
 new file mode 100644
 index 000..c2e5936
 --- /dev/null
 +++ b/drivers/staging/iio/adc/max1027.c
 @@ -0,0 +1,553 @@
 + /*
 +  * iio/adc/max1027.c
 +  * Copyright (C) 2014 Philippe Reynes
 +  *
 +  * based on linux/drivers/iio/ad7923.c
 +  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
 +  * Copyright 2012 CS Systemes d'Information
 +  *
 +  * This program is free software; you can redistribute it and/or modify
 +  * it under the terms of the GNU General Public License version 2 as
 +  * published by the Free Software Foundation.
 +  *
 +  * max1027.c
 +  *
 +  * Partial support for max1027 and similar chips.
 +  */
 +
 +#includelinux/kernel.h
 +#includelinux/spi/spi.h
 +#includelinux/module.h
 +#includelinux/interrupt.h
 +#includelinux/mutex.h
 +#includelinux/of.h
 +#includelinux/of_gpio.h
 +#includelinux/platform_device.h
 +#includelinux/delay.h
 +#includelinux/gpio.h
 +
 +#includelinux/iio/iio.h
 +#includelinux/iio/buffer.h
 +#includelinux/iio/trigger.h
 +#includelinux/iio/trigger_consumer.h
 +#includelinux/iio/triggered_buffer.h
 +
 +#define MAX1027_CONV_REG  0x80
 +#define MAX1027_SETUP_REG 0x40
 +#define MAX1027_AVG_REG   0x20
 +#define MAX1027_RST_REG   0x10
 +
 +/* conversion register */
 +#define MAX1027_TEMP  0x01
 +#define MAX1027_SCAN_0_N  (0x00  1)
 +#define MAX1027_SCAN_N_M  (0x01  1)
 +#define MAX1027_SCAN_N(0x02  1)
 +#define MAX1027_NOSCAN(0x03  1)
 +#define MAX1027_CHAN(n)   ((n)  3)
 +
 +/* setup register */
 +#define MAX1027_UNIPOLAR  0x02
 +#define MAX1027_BIPOLAR   0x03
 +#define MAX1027_REF_MODE0 (0x00  2)
 +#define MAX1027_REF_MODE1 (0x01  2)
 +#define MAX1027_REF_MODE2 (0x02  2)
 +#define MAX1027_REF_MODE3 (0x03  2)
 +#define MAX1027_CKS_MODE0 (0x00  4)
 +#define MAX1027_CKS_MODE1 (0x01  4)
 +#define 

Re: [PATCH v2] iio: add support of the max1027

2014-05-25 Thread Hartmut Knaack
Philippe Reynes schrieb:
> This driver add partial support of the
> maxim 1027/1029/1031. Differential mode is not
> supported.
>
> It was tested on armadeus apf27 board.
>
> Signed-off-by: Philippe Reynes 
> ---
>  .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
>  drivers/staging/iio/adc/Kconfig|9 +
>  drivers/staging/iio/adc/Makefile   |1 +
>  drivers/staging/iio/adc/max1027.c  |  553 
> 
>  4 files changed, 584 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
>  create mode 100644 drivers/staging/iio/adc/max1027.c
>
> Changelog:
> v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
> - really use devm_* 
> - use demux magic
> - use spi_read and spi_write (instead of spi_sync)
> - use define for register (instead of hardcoded value)
>
> diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
> b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
> new file mode 100644
> index 000..2e8b9f3
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
> @@ -0,0 +1,21 @@
> +* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
> +
> +Required properties:
> +  - compatible: Should be "maxim,max1027" or "maxim,max1029" or 
> "maxim,max1031"
> +  - reg: Should contain the ADC SPI address
> +  - interrupt-parent: the phandle for the gpio controller
> +  - interrupts: (gpio) interrupt to which the chip is connected
> +
> +Example:
> +adc@0 {
> + compatible = "maxim,max1027";
> + reg = <0>;
> + interrupt-parent = <>;
> + interrupts = <15 IRQ_TYPE_EDGE_RISING>;
> + pinctrl-names = "default";
> + pinctrl-0 = <_max1027>;
> + /* SPI mode = 0 */
> + spi-cpol = <0>;
> + spi-cpha = <0>;
> + spi-max-frequency = <100>;
> +};
> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
> index 3633298..12a78eb 100644
> --- a/drivers/staging/iio/adc/Kconfig
> +++ b/drivers/staging/iio/adc/Kconfig
> @@ -112,6 +112,15 @@ config LPC32XX_ADC
> activate only one via device tree selection.  Provides direct access
> via sysfs.
>  
> +config MAX1027
> + tristate "Maxim max1027 ADC driver"
> + depends on SPI
> + select IIO_BUFFER
> + select IIO_TRIGGERED_BUFFER
> + help
> +   Say yes here to build support for Maxim SPI ADC models
> +   max1027, max1029 and max1031.
> +
>  config MXS_LRADC
>   tristate "Freescale i.MX23/i.MX28 LRADC"
>   depends on ARCH_MXS || COMPILE_TEST
> diff --git a/drivers/staging/iio/adc/Makefile 
> b/drivers/staging/iio/adc/Makefile
> index 3e9fb14..22fbd0c 100644
> --- a/drivers/staging/iio/adc/Makefile
> +++ b/drivers/staging/iio/adc/Makefile
> @@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) += ad7816.o
>  obj-$(CONFIG_AD7192) += ad7192.o
>  obj-$(CONFIG_AD7280) += ad7280a.o
>  obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
> +obj-$(CONFIG_MAX1027) += max1027.o
>  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
>  obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
> diff --git a/drivers/staging/iio/adc/max1027.c 
> b/drivers/staging/iio/adc/max1027.c
> new file mode 100644
> index 000..c2e5936
> --- /dev/null
> +++ b/drivers/staging/iio/adc/max1027.c
> @@ -0,0 +1,553 @@
> + /*
> +  * iio/adc/max1027.c
> +  * Copyright (C) 2014 Philippe Reynes
> +  *
> +  * based on linux/drivers/iio/ad7923.c
> +  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
> +  * Copyright 2012 CS Systemes d'Information
> +  *
> +  * This program is free software; you can redistribute it and/or modify
> +  * it under the terms of the GNU General Public License version 2 as
> +  * published by the Free Software Foundation.
> +  *
> +  * max1027.c
> +  *
> +  * Partial support for max1027 and similar chips.
> +  */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MAX1027_CONV_REG  0x80
> +#define MAX1027_SETUP_REG 0x40
> +#define MAX1027_AVG_REG   0x20
> +#define MAX1027_RST_REG   0x10
> +
> +/* conversion register */
> +#define MAX1027_TEMP  0x01
> +#define MAX1027_SCAN_0_N  (0x00 << 1)
> +#define MAX1027_SCAN_N_M  (0x01 << 1)
> +#define MAX1027_SCAN_N(0x02 << 1)
> +#define MAX1027_NOSCAN(0x03 << 1)
> +#define MAX1027_CHAN(n)   ((n) << 3)
> +
> +/* setup register */
> +#define MAX1027_UNIPOLAR  0x02
> +#define MAX1027_BIPOLAR   0x03
> +#define MAX1027_REF_MODE0 (0x00 << 2)
> +#define MAX1027_REF_MODE1 (0x01 << 2)
> +#define MAX1027_REF_MODE2 (0x02 << 2)
> +#define MAX1027_REF_MODE3 (0x03 << 2)
> +#define MAX1027_CKS_MODE0 (0x00 << 4)
> +#define MAX1027_CKS_MODE1 (0x01 << 4)
> +#define MAX1027_CKS_MODE2 (0x02 << 4)
> +#define MAX1027_CKS_MODE3 (0x03 << 4)
> +
> +/* averaging register */
> +#define MAX1027_NSCAN_4   0x00
> +#define MAX1027_NSCAN_8   0x01

Re: [PATCH v2] iio: add support of the max1027

2014-05-25 Thread Hartmut Knaack
Philippe Reynes schrieb:
 This driver add partial support of the
 maxim 1027/1029/1031. Differential mode is not
 supported.

 It was tested on armadeus apf27 board.

 Signed-off-by: Philippe Reynes trem...@yahoo.fr
 ---
  .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
  drivers/staging/iio/adc/Kconfig|9 +
  drivers/staging/iio/adc/Makefile   |1 +
  drivers/staging/iio/adc/max1027.c  |  553 
 
  4 files changed, 584 insertions(+), 0 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
  create mode 100644 drivers/staging/iio/adc/max1027.c

 Changelog:
 v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
 - really use devm_* 
 - use demux magic
 - use spi_read and spi_write (instead of spi_sync)
 - use define for register (instead of hardcoded value)

 diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
 b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
 new file mode 100644
 index 000..2e8b9f3
 --- /dev/null
 +++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
 @@ -0,0 +1,21 @@
 +* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
 +
 +Required properties:
 +  - compatible: Should be maxim,max1027 or maxim,max1029 or 
 maxim,max1031
 +  - reg: Should contain the ADC SPI address
 +  - interrupt-parent: the phandle for the gpio controller
 +  - interrupts: (gpio) interrupt to which the chip is connected
 +
 +Example:
 +adc@0 {
 + compatible = maxim,max1027;
 + reg = 0;
 + interrupt-parent = gpio5;
 + interrupts = 15 IRQ_TYPE_EDGE_RISING;
 + pinctrl-names = default;
 + pinctrl-0 = pinctrl_max1027;
 + /* SPI mode = 0 */
 + spi-cpol = 0;
 + spi-cpha = 0;
 + spi-max-frequency = 100;
 +};
 diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
 index 3633298..12a78eb 100644
 --- a/drivers/staging/iio/adc/Kconfig
 +++ b/drivers/staging/iio/adc/Kconfig
 @@ -112,6 +112,15 @@ config LPC32XX_ADC
 activate only one via device tree selection.  Provides direct access
 via sysfs.
  
 +config MAX1027
 + tristate Maxim max1027 ADC driver
 + depends on SPI
 + select IIO_BUFFER
 + select IIO_TRIGGERED_BUFFER
 + help
 +   Say yes here to build support for Maxim SPI ADC models
 +   max1027, max1029 and max1031.
 +
  config MXS_LRADC
   tristate Freescale i.MX23/i.MX28 LRADC
   depends on ARCH_MXS || COMPILE_TEST
 diff --git a/drivers/staging/iio/adc/Makefile 
 b/drivers/staging/iio/adc/Makefile
 index 3e9fb14..22fbd0c 100644
 --- a/drivers/staging/iio/adc/Makefile
 +++ b/drivers/staging/iio/adc/Makefile
 @@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) += ad7816.o
  obj-$(CONFIG_AD7192) += ad7192.o
  obj-$(CONFIG_AD7280) += ad7280a.o
  obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
 +obj-$(CONFIG_MAX1027) += max1027.o
  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
  obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
 diff --git a/drivers/staging/iio/adc/max1027.c 
 b/drivers/staging/iio/adc/max1027.c
 new file mode 100644
 index 000..c2e5936
 --- /dev/null
 +++ b/drivers/staging/iio/adc/max1027.c
 @@ -0,0 +1,553 @@
 + /*
 +  * iio/adc/max1027.c
 +  * Copyright (C) 2014 Philippe Reynes
 +  *
 +  * based on linux/drivers/iio/ad7923.c
 +  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
 +  * Copyright 2012 CS Systemes d'Information
 +  *
 +  * This program is free software; you can redistribute it and/or modify
 +  * it under the terms of the GNU General Public License version 2 as
 +  * published by the Free Software Foundation.
 +  *
 +  * max1027.c
 +  *
 +  * Partial support for max1027 and similar chips.
 +  */
 +
 +#include linux/kernel.h
 +#include linux/spi/spi.h
 +#include linux/module.h
 +#include linux/interrupt.h
 +#include linux/mutex.h
 +#include linux/of.h
 +#include linux/of_gpio.h
 +#include linux/platform_device.h
 +#include linux/delay.h
 +#include linux/gpio.h
 +
 +#include linux/iio/iio.h
 +#include linux/iio/buffer.h
 +#include linux/iio/trigger.h
 +#include linux/iio/trigger_consumer.h
 +#include linux/iio/triggered_buffer.h
 +
 +#define MAX1027_CONV_REG  0x80
 +#define MAX1027_SETUP_REG 0x40
 +#define MAX1027_AVG_REG   0x20
 +#define MAX1027_RST_REG   0x10
 +
 +/* conversion register */
 +#define MAX1027_TEMP  0x01
 +#define MAX1027_SCAN_0_N  (0x00  1)
 +#define MAX1027_SCAN_N_M  (0x01  1)
 +#define MAX1027_SCAN_N(0x02  1)
 +#define MAX1027_NOSCAN(0x03  1)
 +#define MAX1027_CHAN(n)   ((n)  3)
 +
 +/* setup register */
 +#define MAX1027_UNIPOLAR  0x02
 +#define MAX1027_BIPOLAR   0x03
 +#define MAX1027_REF_MODE0 (0x00  2)
 +#define MAX1027_REF_MODE1 (0x01  2)
 +#define MAX1027_REF_MODE2 (0x02  2)
 +#define MAX1027_REF_MODE3 (0x03  2)
 +#define MAX1027_CKS_MODE0 (0x00  4)
 +#define MAX1027_CKS_MODE1 (0x01  4)
 +#define MAX1027_CKS_MODE2 (0x02  4)
 +#define MAX1027_CKS_MODE3 (0x03  4)
 +
 +/* averaging 

Re: [PATCH v2] iio: add support of the max1027

2014-05-24 Thread Jonathan Cameron

On 20/05/14 22:27, Philippe Reynes wrote:

This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynes 
---
  .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
  drivers/staging/iio/adc/Kconfig|9 +
  drivers/staging/iio/adc/Makefile   |1 +
  drivers/staging/iio/adc/max1027.c  |  553 
  4 files changed, 584 insertions(+), 0 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
  create mode 100644 drivers/staging/iio/adc/max1027.c

Changelog:
v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
- really use devm_*
- use demux magic
- use spi_read and spi_write (instead of spi_sync)
- use define for register (instead of hardcoded value)

Much improved.   A few more bits and pieces inline.  Also the bindings doc
needs a bit of tidying up.  Note that we'll either need an ack from a device
tree maintainer or to wait for 3+ weeks after anyone who has commented is
happy.  That will mean this is unlikely to make the next merge window I'm
afraid.

Anyhow in summary:
1) Drop the empty update_scan_mode callback.
2) Locking needed in the single channel reading code (maybe elsewhere?)
3) Get rid of the wrappers around the spi_read and spi_write.  They add
   code but no real advantages over directly calling the spi_read/write
   instead.
4) Check the available can masks - I think you've missed one bit because
   we have a temperature channel as well as the adc channels.
5) Check the headers you have included and remove any that aren't actually
   necessary.

So other than the device tree binding review, not more than 10 mins work
to my eyes!

Looking forward to the next version.

Jonathan


diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
new file mode 100644
index 000..2e8b9f3
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
@@ -0,0 +1,21 @@
+* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
+
+Required properties:
+  - compatible: Should be "maxim,max1027" or "maxim,max1029" or "maxim,max1031"
+  - reg: Should contain the ADC SPI address

I'm lost - what's an SPI address?

+  - interrupt-parent: the phandle for the gpio controller
+  - interrupts: (gpio) interrupt to which the chip is connected

Doesn't need to be a gpio that I can see so don't specify that.
Also, I believe the general convention is to just reference the interrupts
device tree docs rather than attempting to repeat the information here.

+
+Example:
+adc@0 {
+   compatible = "maxim,max1027";
+   reg = <0>;
+   interrupt-parent = <>;
+   interrupts = <15 IRQ_TYPE_EDGE_RISING>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_max1027>;

I'd have a simpler example without the pinctrl stuff.
 

+   /* SPI mode = 0 */
+   spi-cpol = <0>;
+   spi-cpha = <0>;
+   spi-max-frequency = <100>;

Should probably reference the spi docs in the description above for this
bit.

+};
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 3633298..12a78eb 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -112,6 +112,15 @@ config LPC32XX_ADC
  activate only one via device tree selection.  Provides direct access
  via sysfs.

+config MAX1027
+   tristate "Maxim max1027 ADC driver"
+   depends on SPI
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say yes here to build support for Maxim SPI ADC models
+ max1027, max1029 and max1031.
+
  config MXS_LRADC
tristate "Freescale i.MX23/i.MX28 LRADC"
depends on ARCH_MXS || COMPILE_TEST
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index 3e9fb14..22fbd0c 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile> @@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) 
+= ad7816.o
  obj-$(CONFIG_AD7192) += ad7192.o
  obj-$(CONFIG_AD7280) += ad7280a.o
  obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
+obj-$(CONFIG_MAX1027) += max1027.o
  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
  obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
diff --git a/drivers/staging/iio/adc/max1027.c 
b/drivers/staging/iio/adc/max1027.c
new file mode 100644
index 000..c2e5936
--- /dev/null
+++ b/drivers/staging/iio/adc/max1027.c
@@ -0,0 +1,553 @@
+ /*
+  * iio/adc/max1027.c
+  * Copyright (C) 2014 Philippe Reynes
+  *
+  * based on linux/drivers/iio/ad7923.c
+  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
+  * Copyright 2012 CS Systemes d'Information
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License version 2 as
+  * published by the Free Software Foundation.
+  *
+  * 

Re: [PATCH v2] iio: add support of the max1027

2014-05-24 Thread Jonathan Cameron

On 20/05/14 22:27, Philippe Reynes wrote:

This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynes trem...@yahoo.fr
---
  .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
  drivers/staging/iio/adc/Kconfig|9 +
  drivers/staging/iio/adc/Makefile   |1 +
  drivers/staging/iio/adc/max1027.c  |  553 
  4 files changed, 584 insertions(+), 0 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
  create mode 100644 drivers/staging/iio/adc/max1027.c

Changelog:
v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
- really use devm_*
- use demux magic
- use spi_read and spi_write (instead of spi_sync)
- use define for register (instead of hardcoded value)

Much improved.   A few more bits and pieces inline.  Also the bindings doc
needs a bit of tidying up.  Note that we'll either need an ack from a device
tree maintainer or to wait for 3+ weeks after anyone who has commented is
happy.  That will mean this is unlikely to make the next merge window I'm
afraid.

Anyhow in summary:
1) Drop the empty update_scan_mode callback.
2) Locking needed in the single channel reading code (maybe elsewhere?)
3) Get rid of the wrappers around the spi_read and spi_write.  They add
   code but no real advantages over directly calling the spi_read/write
   instead.
4) Check the available can masks - I think you've missed one bit because
   we have a temperature channel as well as the adc channels.
5) Check the headers you have included and remove any that aren't actually
   necessary.

So other than the device tree binding review, not more than 10 mins work
to my eyes!

Looking forward to the next version.

Jonathan


diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
new file mode 100644
index 000..2e8b9f3
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
@@ -0,0 +1,21 @@
+* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
+
+Required properties:
+  - compatible: Should be maxim,max1027 or maxim,max1029 or maxim,max1031
+  - reg: Should contain the ADC SPI address

I'm lost - what's an SPI address?

+  - interrupt-parent: the phandle for the gpio controller
+  - interrupts: (gpio) interrupt to which the chip is connected

Doesn't need to be a gpio that I can see so don't specify that.
Also, I believe the general convention is to just reference the interrupts
device tree docs rather than attempting to repeat the information here.

+
+Example:
+adc@0 {
+   compatible = maxim,max1027;
+   reg = 0;
+   interrupt-parent = gpio5;
+   interrupts = 15 IRQ_TYPE_EDGE_RISING;
+   pinctrl-names = default;
+   pinctrl-0 = pinctrl_max1027;

I'd have a simpler example without the pinctrl stuff.
 

+   /* SPI mode = 0 */
+   spi-cpol = 0;
+   spi-cpha = 0;
+   spi-max-frequency = 100;

Should probably reference the spi docs in the description above for this
bit.

+};
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 3633298..12a78eb 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -112,6 +112,15 @@ config LPC32XX_ADC
  activate only one via device tree selection.  Provides direct access
  via sysfs.

+config MAX1027
+   tristate Maxim max1027 ADC driver
+   depends on SPI
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say yes here to build support for Maxim SPI ADC models
+ max1027, max1029 and max1031.
+
  config MXS_LRADC
tristate Freescale i.MX23/i.MX28 LRADC
depends on ARCH_MXS || COMPILE_TEST
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index 3e9fb14..22fbd0c 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile @@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) 
+= ad7816.o
  obj-$(CONFIG_AD7192) += ad7192.o
  obj-$(CONFIG_AD7280) += ad7280a.o
  obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
+obj-$(CONFIG_MAX1027) += max1027.o
  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
  obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
diff --git a/drivers/staging/iio/adc/max1027.c 
b/drivers/staging/iio/adc/max1027.c
new file mode 100644
index 000..c2e5936
--- /dev/null
+++ b/drivers/staging/iio/adc/max1027.c
@@ -0,0 +1,553 @@
+ /*
+  * iio/adc/max1027.c
+  * Copyright (C) 2014 Philippe Reynes
+  *
+  * based on linux/drivers/iio/ad7923.c
+  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
+  * Copyright 2012 CS Systemes d'Information
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License version 2 as
+  * published by the Free Software Foundation.
+  *
+  * 

[PATCH v2] iio: add support of the max1027

2014-05-20 Thread Philippe Reynes
This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynes 
---
 .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
 drivers/staging/iio/adc/Kconfig|9 +
 drivers/staging/iio/adc/Makefile   |1 +
 drivers/staging/iio/adc/max1027.c  |  553 
 4 files changed, 584 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
 create mode 100644 drivers/staging/iio/adc/max1027.c

Changelog:
v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
- really use devm_* 
- use demux magic
- use spi_read and spi_write (instead of spi_sync)
- use define for register (instead of hardcoded value)

diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
new file mode 100644
index 000..2e8b9f3
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
@@ -0,0 +1,21 @@
+* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
+
+Required properties:
+  - compatible: Should be "maxim,max1027" or "maxim,max1029" or "maxim,max1031"
+  - reg: Should contain the ADC SPI address
+  - interrupt-parent: the phandle for the gpio controller
+  - interrupts: (gpio) interrupt to which the chip is connected
+
+Example:
+adc@0 {
+   compatible = "maxim,max1027";
+   reg = <0>;
+   interrupt-parent = <>;
+   interrupts = <15 IRQ_TYPE_EDGE_RISING>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_max1027>;
+   /* SPI mode = 0 */
+   spi-cpol = <0>;
+   spi-cpha = <0>;
+   spi-max-frequency = <100>;
+};
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 3633298..12a78eb 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -112,6 +112,15 @@ config LPC32XX_ADC
  activate only one via device tree selection.  Provides direct access
  via sysfs.
 
+config MAX1027
+   tristate "Maxim max1027 ADC driver"
+   depends on SPI
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say yes here to build support for Maxim SPI ADC models
+ max1027, max1029 and max1031.
+
 config MXS_LRADC
tristate "Freescale i.MX23/i.MX28 LRADC"
depends on ARCH_MXS || COMPILE_TEST
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index 3e9fb14..22fbd0c 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) += ad7816.o
 obj-$(CONFIG_AD7192) += ad7192.o
 obj-$(CONFIG_AD7280) += ad7280a.o
 obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
+obj-$(CONFIG_MAX1027) += max1027.o
 obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
 obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
diff --git a/drivers/staging/iio/adc/max1027.c 
b/drivers/staging/iio/adc/max1027.c
new file mode 100644
index 000..c2e5936
--- /dev/null
+++ b/drivers/staging/iio/adc/max1027.c
@@ -0,0 +1,553 @@
+ /*
+  * iio/adc/max1027.c
+  * Copyright (C) 2014 Philippe Reynes
+  *
+  * based on linux/drivers/iio/ad7923.c
+  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
+  * Copyright 2012 CS Systemes d'Information
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License version 2 as
+  * published by the Free Software Foundation.
+  *
+  * max1027.c
+  *
+  * Partial support for max1027 and similar chips.
+  */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MAX1027_CONV_REG  0x80
+#define MAX1027_SETUP_REG 0x40
+#define MAX1027_AVG_REG   0x20
+#define MAX1027_RST_REG   0x10
+
+/* conversion register */
+#define MAX1027_TEMP  0x01
+#define MAX1027_SCAN_0_N  (0x00 << 1)
+#define MAX1027_SCAN_N_M  (0x01 << 1)
+#define MAX1027_SCAN_N(0x02 << 1)
+#define MAX1027_NOSCAN(0x03 << 1)
+#define MAX1027_CHAN(n)   ((n) << 3)
+
+/* setup register */
+#define MAX1027_UNIPOLAR  0x02
+#define MAX1027_BIPOLAR   0x03
+#define MAX1027_REF_MODE0 (0x00 << 2)
+#define MAX1027_REF_MODE1 (0x01 << 2)
+#define MAX1027_REF_MODE2 (0x02 << 2)
+#define MAX1027_REF_MODE3 (0x03 << 2)
+#define MAX1027_CKS_MODE0 (0x00 << 4)
+#define MAX1027_CKS_MODE1 (0x01 << 4)
+#define MAX1027_CKS_MODE2 (0x02 << 4)
+#define MAX1027_CKS_MODE3 (0x03 << 4)
+
+/* averaging register */
+#define MAX1027_NSCAN_4   0x00
+#define MAX1027_NSCAN_8   0x01
+#define MAX1027_NSCAN_12  0x02
+#define MAX1027_NSCAN_16  0x03
+#define MAX1027_NAVG_4(0x00 << 2)
+#define MAX1027_NAVG_8(0x01 << 2)
+#define MAX1027_NAVG_12   (0x02 << 2)
+#define MAX1027_NAVG_16   (0x03 << 2)
+#define MAX1027_AVG_EN(0x01 << 4)
+
+enum max1027_id {
+   

[PATCH v2] iio: add support of the max1027

2014-05-20 Thread Philippe Reynes
This driver add partial support of the
maxim 1027/1029/1031. Differential mode is not
supported.

It was tested on armadeus apf27 board.

Signed-off-by: Philippe Reynes trem...@yahoo.fr
---
 .../devicetree/bindings/iio/adc/max1027-adc.txt|   21 +
 drivers/staging/iio/adc/Kconfig|9 +
 drivers/staging/iio/adc/Makefile   |1 +
 drivers/staging/iio/adc/max1027.c  |  553 
 4 files changed, 584 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
 create mode 100644 drivers/staging/iio/adc/max1027.c

Changelog:
v2: (thanks Hartmut Knaack and Jonathan Cameron for the feedback)
- really use devm_* 
- use demux magic
- use spi_read and spi_write (instead of spi_sync)
- use define for register (instead of hardcoded value)

diff --git a/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
new file mode 100644
index 000..2e8b9f3
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/max1027-adc.txt
@@ -0,0 +1,21 @@
+* Maxim 1027/1029/1031 Analog to Digital Converter (ADC)
+
+Required properties:
+  - compatible: Should be maxim,max1027 or maxim,max1029 or maxim,max1031
+  - reg: Should contain the ADC SPI address
+  - interrupt-parent: the phandle for the gpio controller
+  - interrupts: (gpio) interrupt to which the chip is connected
+
+Example:
+adc@0 {
+   compatible = maxim,max1027;
+   reg = 0;
+   interrupt-parent = gpio5;
+   interrupts = 15 IRQ_TYPE_EDGE_RISING;
+   pinctrl-names = default;
+   pinctrl-0 = pinctrl_max1027;
+   /* SPI mode = 0 */
+   spi-cpol = 0;
+   spi-cpha = 0;
+   spi-max-frequency = 100;
+};
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 3633298..12a78eb 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -112,6 +112,15 @@ config LPC32XX_ADC
  activate only one via device tree selection.  Provides direct access
  via sysfs.
 
+config MAX1027
+   tristate Maxim max1027 ADC driver
+   depends on SPI
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say yes here to build support for Maxim SPI ADC models
+ max1027, max1029 and max1031.
+
 config MXS_LRADC
tristate Freescale i.MX23/i.MX28 LRADC
depends on ARCH_MXS || COMPILE_TEST
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index 3e9fb14..22fbd0c 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -18,5 +18,6 @@ obj-$(CONFIG_AD7816) += ad7816.o
 obj-$(CONFIG_AD7192) += ad7192.o
 obj-$(CONFIG_AD7280) += ad7280a.o
 obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
+obj-$(CONFIG_MAX1027) += max1027.o
 obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
 obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
diff --git a/drivers/staging/iio/adc/max1027.c 
b/drivers/staging/iio/adc/max1027.c
new file mode 100644
index 000..c2e5936
--- /dev/null
+++ b/drivers/staging/iio/adc/max1027.c
@@ -0,0 +1,553 @@
+ /*
+  * iio/adc/max1027.c
+  * Copyright (C) 2014 Philippe Reynes
+  *
+  * based on linux/drivers/iio/ad7923.c
+  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
+  * Copyright 2012 CS Systemes d'Information
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License version 2 as
+  * published by the Free Software Foundation.
+  *
+  * max1027.c
+  *
+  * Partial support for max1027 and similar chips.
+  */
+
+#include linux/kernel.h
+#include linux/spi/spi.h
+#include linux/module.h
+#include linux/interrupt.h
+#include linux/mutex.h
+#include linux/of.h
+#include linux/of_gpio.h
+#include linux/platform_device.h
+#include linux/delay.h
+#include linux/gpio.h
+
+#include linux/iio/iio.h
+#include linux/iio/buffer.h
+#include linux/iio/trigger.h
+#include linux/iio/trigger_consumer.h
+#include linux/iio/triggered_buffer.h
+
+#define MAX1027_CONV_REG  0x80
+#define MAX1027_SETUP_REG 0x40
+#define MAX1027_AVG_REG   0x20
+#define MAX1027_RST_REG   0x10
+
+/* conversion register */
+#define MAX1027_TEMP  0x01
+#define MAX1027_SCAN_0_N  (0x00  1)
+#define MAX1027_SCAN_N_M  (0x01  1)
+#define MAX1027_SCAN_N(0x02  1)
+#define MAX1027_NOSCAN(0x03  1)
+#define MAX1027_CHAN(n)   ((n)  3)
+
+/* setup register */
+#define MAX1027_UNIPOLAR  0x02
+#define MAX1027_BIPOLAR   0x03
+#define MAX1027_REF_MODE0 (0x00  2)
+#define MAX1027_REF_MODE1 (0x01  2)
+#define MAX1027_REF_MODE2 (0x02  2)
+#define MAX1027_REF_MODE3 (0x03  2)
+#define MAX1027_CKS_MODE0 (0x00  4)
+#define MAX1027_CKS_MODE1 (0x01  4)
+#define MAX1027_CKS_MODE2 (0x02  4)
+#define MAX1027_CKS_MODE3 (0x03  4)
+
+/* averaging register */
+#define MAX1027_NSCAN_4   0x00
+#define MAX1027_NSCAN_8   0x01
+#define MAX1027_NSCAN_12  0x02
+#define MAX1027_NSCAN_16