Re: [PATCH 1/3] iio:adc: add iio driver for Palmas (twl6035/7) gpadc

2015-10-11 Thread Jonathan Cameron
On 04/10/15 17:04, H. Nikolaus Schaller wrote:
> 
> Am 27.09.2015 um 17:21 schrieb Jonathan Cameron :
> 
>> On 23/09/15 13:48, H. Nikolaus Schaller wrote:
>>> This driver code was found as:
>>>
>>> https://android.googlesource.com/kernel/tegra/+/aaabb2e045f31e5a970109ffdaae900dd403d17e/drivers/staging/iio/adc
>>>
>>> Fixed various compilation issues and test this driver on omap5 evm.
>>>
>>> Signed-off-by: Pradeep Goudagunta 
>>> Signed-off-by: H. Nikolaus Schaller 
>>> Signed-off-by: Marek Belisko 
>> Various bits inline.
> 
> Thanks again!
> 
> Worked into V2 (coming right after this mail).
> Comments below, where/why we have not exactly followed your feedback.
Responses inline, but we haven't disagreed on anything important
so none of it really matters!

Jonathan
> 
> BR,
> Nikolaus
> 
>>
>> Jonathan
>>> ---
>>> drivers/iio/adc/Kconfig|   9 +
>>> drivers/iio/adc/Makefile   |   1 +
>>> drivers/iio/adc/palmas_gpadc.c | 797 
>>> +
>>> include/linux/mfd/palmas.h |  59 ++-
>>> 4 files changed, 862 insertions(+), 4 deletions(-)
>>> create mode 100644 drivers/iio/adc/palmas_gpadc.c
>>>
>>> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
>>> index eb0cd89..f6df9db 100644
>>> --- a/drivers/iio/adc/Kconfig
>>> +++ b/drivers/iio/adc/Kconfig
>>> @@ -242,6 +242,15 @@ config NAU7802
>>>   To compile this driver as a module, choose M here: the
>>>   module will be called nau7802.
>>>
>>> +config PALMAS_GPADC
>>> +   tristate "TI Palmas General Purpose ADC"
>>> +   depends on MFD_PALMAS
>>> +   help
>>> + Palmas series pmic chip by texas Instruments (twl6035/6037)
>>> + is used in smartphones and tablets and supports a 16 channel
>>> + general purpose ADC. Add iio driver to read different channel
>>> + of the GPADCs.
>>> +
>>> config QCOM_SPMI_IADC
>>> tristate "Qualcomm SPMI PMIC current ADC"
>>> depends on SPMI
>>> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
>>> index a096210..716f112 100644
>>> --- a/drivers/iio/adc/Makefile
>>> +++ b/drivers/iio/adc/Makefile
>>> @@ -26,6 +26,7 @@ obj-$(CONFIG_MCP320X) += mcp320x.o
>>> obj-$(CONFIG_MCP3422) += mcp3422.o
>>> obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
>>> obj-$(CONFIG_NAU7802) += nau7802.o
>>> +obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o
>>> obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
>>> obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
>>> obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
>>> diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
>>> new file mode 100644
>>> index 000..17abb28
>>> --- /dev/null
>>> +++ b/drivers/iio/adc/palmas_gpadc.c
>>> @@ -0,0 +1,797 @@
>>> +/*
>>> + * palmas-adc.c -- TI PALMAS GPADC.
>>> + *
>>> + * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
>>> + *
>>> + * Author: Pradeep Goudagunta 
>>> + *
>>> + * This program is free software; you can redistribute it and/or
>>> + * modify it under the terms of the GNU General Public License as
>>> + * published by the Free Software Foundation version 2.
>>> + */
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#define MOD_NAME "palmas-gpadc"
>>> +#define ADC_CONVERSION_TIMEOUT (msecs_to_jiffies(5000))
>>> +#define TO_BE_CALCULATED 0
>>> +
>>> +struct palmas_gpadc_info {
>>> +/* calibration codes and regs */
>> Full docs on this would be appreciated.
> Is mostly defined in the Palmas data sheet but I have added some comments.
>>> +   int x1;
>>> +   int x2;
>>> +   int v1;
>>> +   int v2;
>>> +   u8 trim1_reg;
>>> +   u8 trim2_reg;
>>> +   int gain;
>>> +   int offset;
>>> +   int gain_error;
>>> +   bool is_correct_code;
>>> +};
>>> +
>>> +#define PALMAS_ADC_INFO(_chan, _x1, _x2, _v1, _v2, _t1, _t2, 
>>> _is_correct_code)\
>>> +[PALMAS_ADC_CH_##_chan] = {
>>> \
>>> +   .x1 = _x1,  \
>>> +   .x2 = _x2,  \
>>> +   .v1 = _v1,  \
>>> +   .v2 = _v2,  \
>>> +   .gain = TO_BE_CALCULATED,   \
>>> +   .offset = TO_BE_CALCULATED, \
>>> +   .gain_error = TO_BE_CALCULATED, \
>>> +   .trim1_reg = PALMAS_GPADC_TRIM##_t1,\
>>> +   .trim2_reg = PALMAS_GPADC_TRIM##_t2,\
>>> +   .is_correct_code = _is_correct_code \
>>> +   }
>>> +
>>> +static struct palmas_gpadc_info palmas_gpadc_info[] = {
>>> +   PALMAS_ADC_INFO(IN0, 

Re: [PATCH 1/3] iio:adc: add iio driver for Palmas (twl6035/7) gpadc

2015-09-28 Thread H. Nikolaus Schaller
Hi,

Am 27.09.2015 um 17:21 schrieb Jonathan Cameron :

> On 23/09/15 13:48, H. Nikolaus Schaller wrote:
>> This driver code was found as:
>> 
>> https://android.googlesource.com/kernel/tegra/+/aaabb2e045f31e5a970109ffdaae900dd403d17e/drivers/staging/iio/adc
>> 
>> Fixed various compilation issues and test this driver on omap5 evm.
>> 
>> Signed-off-by: Pradeep Goudagunta 
>> Signed-off-by: H. Nikolaus Schaller 
>> Signed-off-by: Marek Belisko 
> Various bits inline.

thanks for the valuable comments!

Will work into V2.

Nikolaus

> 
> Jonathan
>> ---
>> drivers/iio/adc/Kconfig|   9 +
>> drivers/iio/adc/Makefile   |   1 +
>> drivers/iio/adc/palmas_gpadc.c | 797 
>> +
>> include/linux/mfd/palmas.h |  59 ++-
>> 4 files changed, 862 insertions(+), 4 deletions(-)
>> create mode 100644 drivers/iio/adc/palmas_gpadc.c
>> 
>> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
>> index eb0cd89..f6df9db 100644
>> --- a/drivers/iio/adc/Kconfig
>> +++ b/drivers/iio/adc/Kconfig
>> @@ -242,6 +242,15 @@ config NAU7802
>>To compile this driver as a module, choose M here: the
>>module will be called nau7802.
>> 
>> +config PALMAS_GPADC
>> +tristate "TI Palmas General Purpose ADC"
>> +depends on MFD_PALMAS
>> +help
>> +  Palmas series pmic chip by texas Instruments (twl6035/6037)
>> +  is used in smartphones and tablets and supports a 16 channel
>> +  general purpose ADC. Add iio driver to read different channel
>> +  of the GPADCs.
>> +
>> config QCOM_SPMI_IADC
>>  tristate "Qualcomm SPMI PMIC current ADC"
>>  depends on SPMI
>> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
>> index a096210..716f112 100644
>> --- a/drivers/iio/adc/Makefile
>> +++ b/drivers/iio/adc/Makefile
>> @@ -26,6 +26,7 @@ obj-$(CONFIG_MCP320X) += mcp320x.o
>> obj-$(CONFIG_MCP3422) += mcp3422.o
>> obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
>> obj-$(CONFIG_NAU7802) += nau7802.o
>> +obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o
>> obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
>> obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
>> obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
>> diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
>> new file mode 100644
>> index 000..17abb28
>> --- /dev/null
>> +++ b/drivers/iio/adc/palmas_gpadc.c
>> @@ -0,0 +1,797 @@
>> +/*
>> + * palmas-adc.c -- TI PALMAS GPADC.
>> + *
>> + * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
>> + *
>> + * Author: Pradeep Goudagunta 
>> + *
>> + * This program is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU General Public License as
>> + * published by the Free Software Foundation version 2.
>> + */
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define MOD_NAME "palmas-gpadc"
>> +#define ADC_CONVERSION_TIMEOUT  (msecs_to_jiffies(5000))
>> +#define TO_BE_CALCULATED 0
>> +
>> +struct palmas_gpadc_info {
>> +/* calibration codes and regs */
> Full docs on this would be appreciated.
>> +int x1;
>> +int x2;
>> +int v1;
>> +int v2;
>> +u8 trim1_reg;
>> +u8 trim2_reg;
>> +int gain;
>> +int offset;
>> +int gain_error;
>> +bool is_correct_code;
>> +};
>> +
>> +#define PALMAS_ADC_INFO(_chan, _x1, _x2, _v1, _v2, _t1, _t2, 
>> _is_correct_code)\
>> +[PALMAS_ADC_CH_##_chan] = { \
>> +.x1 = _x1,  \
>> +.x2 = _x2,  \
>> +.v1 = _v1,  \
>> +.v2 = _v2,  \
>> +.gain = TO_BE_CALCULATED,   \
>> +.offset = TO_BE_CALCULATED, \
>> +.gain_error = TO_BE_CALCULATED, \
>> +.trim1_reg = PALMAS_GPADC_TRIM##_t1,\
>> +.trim2_reg = PALMAS_GPADC_TRIM##_t2,\
>> +.is_correct_code = _is_correct_code \
>> +}
>> +
>> +static struct palmas_gpadc_info palmas_gpadc_info[] = {
>> +PALMAS_ADC_INFO(IN0, 2064, 3112, 630, 950, 1, 2, false),
>> +PALMAS_ADC_INFO(IN1, 2064, 3112, 630, 950, 1, 2, false),
>> +PALMAS_ADC_INFO(IN2, 2064, 3112, 1260, 1900, 3, 4, false),
>> +PALMAS_ADC_INFO(IN3, 2064, 3112, 630, 950, 1, 2, false),
>> +PALMAS_ADC_INFO(IN4, 2064, 3112, 630, 950, 1, 2, false),
>> +PALMAS_ADC_INFO(IN5, 2064, 3112, 630, 950, 1, 2, false),
>> +PALMAS_ADC_INFO(IN6, 2064, 3112, 2520, 3800, 5, 6, 

Re: [PATCH 1/3] iio:adc: add iio driver for Palmas (twl6035/7) gpadc

2015-09-27 Thread Jonathan Cameron
On 23/09/15 13:48, H. Nikolaus Schaller wrote:
> This driver code was found as:
> 
> https://android.googlesource.com/kernel/tegra/+/aaabb2e045f31e5a970109ffdaae900dd403d17e/drivers/staging/iio/adc
> 
> Fixed various compilation issues and test this driver on omap5 evm.
> 
> Signed-off-by: Pradeep Goudagunta 
> Signed-off-by: H. Nikolaus Schaller 
> Signed-off-by: Marek Belisko 
Various bits inline.

Jonathan
> ---
> drivers/iio/adc/Kconfig|   9 +
> drivers/iio/adc/Makefile   |   1 +
> drivers/iio/adc/palmas_gpadc.c | 797 +
> include/linux/mfd/palmas.h |  59 ++-
> 4 files changed, 862 insertions(+), 4 deletions(-)
> create mode 100644 drivers/iio/adc/palmas_gpadc.c
> 
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index eb0cd89..f6df9db 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -242,6 +242,15 @@ config NAU7802
> To compile this driver as a module, choose M here: the
> module will be called nau7802.
> 
> +config PALMAS_GPADC
> + tristate "TI Palmas General Purpose ADC"
> + depends on MFD_PALMAS
> + help
> +   Palmas series pmic chip by texas Instruments (twl6035/6037)
> +   is used in smartphones and tablets and supports a 16 channel
> +   general purpose ADC. Add iio driver to read different channel
> +   of the GPADCs.
> +
> config QCOM_SPMI_IADC
>   tristate "Qualcomm SPMI PMIC current ADC"
>   depends on SPMI
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index a096210..716f112 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -26,6 +26,7 @@ obj-$(CONFIG_MCP320X) += mcp320x.o
> obj-$(CONFIG_MCP3422) += mcp3422.o
> obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
> obj-$(CONFIG_NAU7802) += nau7802.o
> +obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o
> obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
> obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
> obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
> diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
> new file mode 100644
> index 000..17abb28
> --- /dev/null
> +++ b/drivers/iio/adc/palmas_gpadc.c
> @@ -0,0 +1,797 @@
> +/*
> + * palmas-adc.c -- TI PALMAS GPADC.
> + *
> + * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
> + *
> + * Author: Pradeep Goudagunta 
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation version 2.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MOD_NAME "palmas-gpadc"
> +#define ADC_CONVERSION_TIMEOUT   (msecs_to_jiffies(5000))
> +#define TO_BE_CALCULATED 0
> +
> +struct palmas_gpadc_info {
> +/* calibration codes and regs */
Full docs on this would be appreciated.
> + int x1;
> + int x2;
> + int v1;
> + int v2;
> + u8 trim1_reg;
> + u8 trim2_reg;
> + int gain;
> + int offset;
> + int gain_error;
> + bool is_correct_code;
> +};
> +
> +#define PALMAS_ADC_INFO(_chan, _x1, _x2, _v1, _v2, _t1, _t2, 
> _is_correct_code)\
> +[PALMAS_ADC_CH_##_chan] = {  \
> + .x1 = _x1,  \
> + .x2 = _x2,  \
> + .v1 = _v1,  \
> + .v2 = _v2,  \
> + .gain = TO_BE_CALCULATED,   \
> + .offset = TO_BE_CALCULATED, \
> + .gain_error = TO_BE_CALCULATED, \
> + .trim1_reg = PALMAS_GPADC_TRIM##_t1,\
> + .trim2_reg = PALMAS_GPADC_TRIM##_t2,\
> + .is_correct_code = _is_correct_code \
> + }
> +
> +static struct palmas_gpadc_info palmas_gpadc_info[] = {
> + PALMAS_ADC_INFO(IN0, 2064, 3112, 630, 950, 1, 2, false),
> + PALMAS_ADC_INFO(IN1, 2064, 3112, 630, 950, 1, 2, false),
> + PALMAS_ADC_INFO(IN2, 2064, 3112, 1260, 1900, 3, 4, false),
> + PALMAS_ADC_INFO(IN3, 2064, 3112, 630, 950, 1, 2, false),
> + PALMAS_ADC_INFO(IN4, 2064, 3112, 630, 950, 1, 2, false),
> + PALMAS_ADC_INFO(IN5, 2064, 3112, 630, 950, 1, 2, false),
> + PALMAS_ADC_INFO(IN6, 2064, 3112, 2520, 3800, 5, 6, false),
> + PALMAS_ADC_INFO(IN7, 2064, 3112, 2520, 3800, 7, 8, false),
> + PALMAS_ADC_INFO(IN8, 2064, 3112, 3150, 4750, 9, 10, false),
> + PALMAS_ADC_INFO(IN9, 2064, 3112, 5670, 8550, 11, 12, false),
> + 

Re: [PATCH 1/3] iio:adc: add iio driver for Palmas (twl6035/7) gpadc

2015-09-24 Thread H. Nikolaus Schaller

Am 23.09.2015 um 15:26 schrieb Peter Meerwald :

> 
>> This driver code was found as:
>> 
>> https://android.googlesource.com/kernel/tegra/+/aaabb2e045f31e5a970109ffdaae900dd403d17e/drivers/staging/iio/adc
>> 
>> Fixed various compilation issues and test this driver on omap5 evm.
> 
> several minor comments below

thanks!
I have worked in for a V2 but will wait a little for further comments until I 
post it.

> probably the mfd part should be split out in a separate patch

well, I think those changes should stay bundled in a single patch
since they depend on each other.

> 
>> Signed-off-by: Pradeep Goudagunta 
>> Signed-off-by: H. Nikolaus Schaller 
>> Signed-off-by: Marek Belisko 
>> ---
>> drivers/iio/adc/Kconfig|   9 +
>> drivers/iio/adc/Makefile   |   1 +
>> drivers/iio/adc/palmas_gpadc.c | 797 
>> +
>> include/linux/mfd/palmas.h |  59 ++-
>> 4 files changed, 862 insertions(+), 4 deletions(-)
>> create mode 100644 drivers/iio/adc/palmas_gpadc.c
>> 
>> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
>> index eb0cd89..f6df9db 100644
>> --- a/drivers/iio/adc/Kconfig
>> +++ b/drivers/iio/adc/Kconfig
>> @@ -242,6 +242,15 @@ config NAU7802
>>To compile this driver as a module, choose M here: the
>>module will be called nau7802.
>> 
>> +config PALMAS_GPADC
>> +tristate "TI Palmas General Purpose ADC"
>> +depends on MFD_PALMAS
>> +help
>> +  Palmas series pmic chip by texas Instruments (twl6035/6037)
>> +  is used in smartphones and tablets and supports a 16 channel
>> +  general purpose ADC. Add iio driver to read different channel
>> +  of the GPADCs.
> 
> PMIC
> _T_exas
> 
> drop meaningless "Add iio driver to read different channel of the GPADCs."
> 
>> +
>> config QCOM_SPMI_IADC
>>  tristate "Qualcomm SPMI PMIC current ADC"
>>  depends on SPMI
>> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
>> index a096210..716f112 100644
>> --- a/drivers/iio/adc/Makefile
>> +++ b/drivers/iio/adc/Makefile
>> @@ -26,6 +26,7 @@ obj-$(CONFIG_MCP320X) += mcp320x.o
>> obj-$(CONFIG_MCP3422) += mcp3422.o
>> obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
>> obj-$(CONFIG_NAU7802) += nau7802.o
>> +obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o
>> obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
>> obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
>> obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
>> diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
>> new file mode 100644
>> index 000..17abb28
>> --- /dev/null
>> +++ b/drivers/iio/adc/palmas_gpadc.c
>> @@ -0,0 +1,797 @@
>> +/*
>> + * palmas-adc.c -- TI PALMAS GPADC.
>> + *
>> + * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
>> + *
>> + * Author: Pradeep Goudagunta 
>> + *
>> + * This program is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU General Public License as
>> + * published by the Free Software Foundation version 2.
>> + */
> 
> newline
> 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define MOD_NAME "palmas-gpadc"
>> +#define ADC_CONVERSION_TIMEOUT  (msecs_to_jiffies(5000))
>> +#define TO_BE_CALCULATED 0
> 
> add prefix PALMAS_
> 
>> +
>> +struct palmas_gpadc_info {
>> +/* calibration codes and regs */
>> +int x1;
>> +int x2;
>> +int v1;
>> +int v2;
>> +u8 trim1_reg;
>> +u8 trim2_reg;
>> +int gain;
>> +int offset;
>> +int gain_error;
>> +bool is_correct_code;
>> +};
>> +
>> +#define PALMAS_ADC_INFO(_chan, _x1, _x2, _v1, _v2, _t1, _t2, 
>> _is_correct_code)\
> 
> whitespace and indentation
> 
>> +[PALMAS_ADC_CH_##_chan] = { \
>> +.x1 = _x1,  \
>> +.x2 = _x2,  \
>> +.v1 = _v1,  \
>> +.v2 = _v2,  \
>> +.gain = TO_BE_CALCULATED,   \
>> +.offset = TO_BE_CALCULATED, \
>> +.gain_error = TO_BE_CALCULATED, \
>> +.trim1_reg = PALMAS_GPADC_TRIM##_t1,\
>> +.trim2_reg = PALMAS_GPADC_TRIM##_t2,\
>> +.is_correct_code = _is_correct_code \
>> +}
>> +
>> +static struct palmas_gpadc_info palmas_gpadc_info[] = {
>> +PALMAS_ADC_INFO(IN0, 2064, 3112, 630, 950, 1, 2, false),
>> +PALMAS_ADC_INFO(IN1, 2064, 3112, 630, 950, 1, 2, false),
>> +PALMAS_ADC_INFO(IN2, 2064, 3112, 

[PATCH 1/3] iio:adc: add iio driver for Palmas (twl6035/7) gpadc

2015-09-23 Thread H. Nikolaus Schaller
This driver code was found as:

https://android.googlesource.com/kernel/tegra/+/aaabb2e045f31e5a970109ffdaae900dd403d17e/drivers/staging/iio/adc

Fixed various compilation issues and test this driver on omap5 evm.

Signed-off-by: Pradeep Goudagunta 
Signed-off-by: H. Nikolaus Schaller 
Signed-off-by: Marek Belisko 
---
drivers/iio/adc/Kconfig|   9 +
drivers/iio/adc/Makefile   |   1 +
drivers/iio/adc/palmas_gpadc.c | 797 +
include/linux/mfd/palmas.h |  59 ++-
4 files changed, 862 insertions(+), 4 deletions(-)
create mode 100644 drivers/iio/adc/palmas_gpadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index eb0cd89..f6df9db 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -242,6 +242,15 @@ config NAU7802
  To compile this driver as a module, choose M here: the
  module will be called nau7802.

+config PALMAS_GPADC
+   tristate "TI Palmas General Purpose ADC"
+   depends on MFD_PALMAS
+   help
+ Palmas series pmic chip by texas Instruments (twl6035/6037)
+ is used in smartphones and tablets and supports a 16 channel
+ general purpose ADC. Add iio driver to read different channel
+ of the GPADCs.
+
config QCOM_SPMI_IADC
tristate "Qualcomm SPMI PMIC current ADC"
depends on SPMI
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index a096210..716f112 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_MCP320X) += mcp320x.o
obj-$(CONFIG_MCP3422) += mcp3422.o
obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
obj-$(CONFIG_NAU7802) += nau7802.o
+obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o
obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
new file mode 100644
index 000..17abb28
--- /dev/null
+++ b/drivers/iio/adc/palmas_gpadc.c
@@ -0,0 +1,797 @@
+/*
+ * palmas-adc.c -- TI PALMAS GPADC.
+ *
+ * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
+ *
+ * Author: Pradeep Goudagunta 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MOD_NAME "palmas-gpadc"
+#define ADC_CONVERSION_TIMEOUT (msecs_to_jiffies(5000))
+#define TO_BE_CALCULATED 0
+
+struct palmas_gpadc_info {
+/* calibration codes and regs */
+   int x1;
+   int x2;
+   int v1;
+   int v2;
+   u8 trim1_reg;
+   u8 trim2_reg;
+   int gain;
+   int offset;
+   int gain_error;
+   bool is_correct_code;
+};
+
+#define PALMAS_ADC_INFO(_chan, _x1, _x2, _v1, _v2, _t1, _t2, _is_correct_code)\
+[PALMAS_ADC_CH_##_chan] = {\
+   .x1 = _x1,  \
+   .x2 = _x2,  \
+   .v1 = _v1,  \
+   .v2 = _v2,  \
+   .gain = TO_BE_CALCULATED,   \
+   .offset = TO_BE_CALCULATED, \
+   .gain_error = TO_BE_CALCULATED, \
+   .trim1_reg = PALMAS_GPADC_TRIM##_t1,\
+   .trim2_reg = PALMAS_GPADC_TRIM##_t2,\
+   .is_correct_code = _is_correct_code \
+   }
+
+static struct palmas_gpadc_info palmas_gpadc_info[] = {
+   PALMAS_ADC_INFO(IN0, 2064, 3112, 630, 950, 1, 2, false),
+   PALMAS_ADC_INFO(IN1, 2064, 3112, 630, 950, 1, 2, false),
+   PALMAS_ADC_INFO(IN2, 2064, 3112, 1260, 1900, 3, 4, false),
+   PALMAS_ADC_INFO(IN3, 2064, 3112, 630, 950, 1, 2, false),
+   PALMAS_ADC_INFO(IN4, 2064, 3112, 630, 950, 1, 2, false),
+   PALMAS_ADC_INFO(IN5, 2064, 3112, 630, 950, 1, 2, false),
+   PALMAS_ADC_INFO(IN6, 2064, 3112, 2520, 3800, 5, 6, false),
+   PALMAS_ADC_INFO(IN7, 2064, 3112, 2520, 3800, 7, 8, false),
+   PALMAS_ADC_INFO(IN8, 2064, 3112, 3150, 4750, 9, 10, false),
+   PALMAS_ADC_INFO(IN9, 2064, 3112, 5670, 8550, 11, 12, false),
+   PALMAS_ADC_INFO(IN10, 2064, 3112, 3465, 5225, 13, 14, false),
+   PALMAS_ADC_INFO(IN11, 0, 0, 0, 0, INVALID, INVALID, true),
+   PALMAS_ADC_INFO(IN12, 0, 0, 0, 0, INVALID, INVALID, true),
+   PALMAS_ADC_INFO(IN13, 0, 0, 0, 0, INVALID, INVALID, true),
+   PALMAS_ADC_INFO(IN14, 2064, 3112, 

Re: [PATCH 1/3] iio:adc: add iio driver for Palmas (twl6035/7) gpadc

2015-09-23 Thread Peter Meerwald

> This driver code was found as:
> 
> https://android.googlesource.com/kernel/tegra/+/aaabb2e045f31e5a970109ffdaae900dd403d17e/drivers/staging/iio/adc
> 
> Fixed various compilation issues and test this driver on omap5 evm.

several minor comments below
probably the mfd part should be split out in a separate patch
 
> Signed-off-by: Pradeep Goudagunta 
> Signed-off-by: H. Nikolaus Schaller 
> Signed-off-by: Marek Belisko 
> ---
> drivers/iio/adc/Kconfig|   9 +
> drivers/iio/adc/Makefile   |   1 +
> drivers/iio/adc/palmas_gpadc.c | 797 +
> include/linux/mfd/palmas.h |  59 ++-
> 4 files changed, 862 insertions(+), 4 deletions(-)
> create mode 100644 drivers/iio/adc/palmas_gpadc.c
> 
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index eb0cd89..f6df9db 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -242,6 +242,15 @@ config NAU7802
> To compile this driver as a module, choose M here: the
> module will be called nau7802.
> 
> +config PALMAS_GPADC
> + tristate "TI Palmas General Purpose ADC"
> + depends on MFD_PALMAS
> + help
> +   Palmas series pmic chip by texas Instruments (twl6035/6037)
> +   is used in smartphones and tablets and supports a 16 channel
> +   general purpose ADC. Add iio driver to read different channel
> +   of the GPADCs.

PMIC
_T_exas

drop meaningless "Add iio driver to read different channel of the GPADCs."

> +
> config QCOM_SPMI_IADC
>   tristate "Qualcomm SPMI PMIC current ADC"
>   depends on SPMI
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index a096210..716f112 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -26,6 +26,7 @@ obj-$(CONFIG_MCP320X) += mcp320x.o
> obj-$(CONFIG_MCP3422) += mcp3422.o
> obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
> obj-$(CONFIG_NAU7802) += nau7802.o
> +obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o
> obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
> obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
> obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
> diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
> new file mode 100644
> index 000..17abb28
> --- /dev/null
> +++ b/drivers/iio/adc/palmas_gpadc.c
> @@ -0,0 +1,797 @@
> +/*
> + * palmas-adc.c -- TI PALMAS GPADC.
> + *
> + * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
> + *
> + * Author: Pradeep Goudagunta 
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation version 2.
> + */

newline

> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MOD_NAME "palmas-gpadc"
> +#define ADC_CONVERSION_TIMEOUT   (msecs_to_jiffies(5000))
> +#define TO_BE_CALCULATED 0

add prefix PALMAS_

> +
> +struct palmas_gpadc_info {
> +/* calibration codes and regs */
> + int x1;
> + int x2;
> + int v1;
> + int v2;
> + u8 trim1_reg;
> + u8 trim2_reg;
> + int gain;
> + int offset;
> + int gain_error;
> + bool is_correct_code;
> +};
> +
> +#define PALMAS_ADC_INFO(_chan, _x1, _x2, _v1, _v2, _t1, _t2, 
> _is_correct_code)\

whitespace and indentation

> +[PALMAS_ADC_CH_##_chan] = {  \
> + .x1 = _x1,  \
> + .x2 = _x2,  \
> + .v1 = _v1,  \
> + .v2 = _v2,  \
> + .gain = TO_BE_CALCULATED,   \
> + .offset = TO_BE_CALCULATED, \
> + .gain_error = TO_BE_CALCULATED, \
> + .trim1_reg = PALMAS_GPADC_TRIM##_t1,\
> + .trim2_reg = PALMAS_GPADC_TRIM##_t2,\
> + .is_correct_code = _is_correct_code \
> + }
> +
> +static struct palmas_gpadc_info palmas_gpadc_info[] = {
> + PALMAS_ADC_INFO(IN0, 2064, 3112, 630, 950, 1, 2, false),
> + PALMAS_ADC_INFO(IN1, 2064, 3112, 630, 950, 1, 2, false),
> + PALMAS_ADC_INFO(IN2, 2064, 3112, 1260, 1900, 3, 4, false),
> + PALMAS_ADC_INFO(IN3, 2064, 3112, 630, 950, 1, 2, false),
> + PALMAS_ADC_INFO(IN4, 2064, 3112, 630, 950, 1, 2, false),
> + PALMAS_ADC_INFO(IN5, 2064, 3112, 630, 950, 1, 2, false),
> + PALMAS_ADC_INFO(IN6, 2064, 3112, 2520, 3800, 5, 6, false),
> + PALMAS_ADC_INFO(IN7, 2064, 3112, 2520, 3800, 7, 8, false),
> + PALMAS_ADC_INFO(IN8, 2064, 3112,