Re: [PATCH v4 2/3] iio: adc: mt2701: Add Mediatek auxadc driver for mt2701.

2016-07-20 Thread zhiyong tao
On Wed, 2016-07-20 at 14:02 +0800, zhiyong tao wrote:
> On Mon, 2016-07-18 at 18:12 +0100, Jonathan Cameron wrote:
> > On 11/07/16 07:39, Zhiyong Tao wrote:
> > > Add Mediatek auxadc driver based on iio.
> > > It will register a device in iio and support iio.
> > > So thermal can read auxadc channel to sample data by iio device.
> > > It is tested successfully on mt2701 platform.
> > > Mt8173 and mt6577 platforms are not tested.
> > > But the expectation is compatible.
> > > 
> > > Signed-off-by: Zhiyong Tao 
> > Looks good to me.  Couple of really minor points / questions inline...
> > 
> > Just one thing to confirm... (you probably already answered this!)
> > What are the units of the voltage channels?
> > 
> > Jonathan
> 
> The units of the voltage channels are mv. 
> 
> > > ---
> > >  drivers/iio/adc/Kconfig |   13 ++
> > >  drivers/iio/adc/Makefile|1 +
> > >  drivers/iio/adc/mt6577_auxadc.c |  294 
> > > +++
> > >  3 files changed, 308 insertions(+)
> > >  create mode 100644 drivers/iio/adc/mt6577_auxadc.c
> > > 
> > > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> > > index 25378c5..14929fc 100644
> > > --- a/drivers/iio/adc/Kconfig
> > > +++ b/drivers/iio/adc/Kconfig
> > > @@ -305,6 +305,19 @@ config MCP3422
> > > This driver can also be built as a module. If so, the module will be
> > > called mcp3422.
> > >  
> > > +config MEDIATEK_MT6577_AUXADC
> > > +tristate "MediaTek AUXADC driver"
> > > +depends on ARCH_MEDIATEK || COMPILE_TEST
> > > +depends on HAS_IOMEM
> > > +help
> > > +  Say yes here to enable support for MediaTek mt65xx AUXADC.
> > > +
> > > +  The driver supports immediate mode operation to read from one 
> > > of sixteen
> > > +  channels (external or internal).
> > > +
> > > +  This driver can also be built as a module. If so, the module 
> > > will be
> > > +  called mt6577_auxadc.
> > > +
> > >  config MEN_Z188_ADC
> > >   tristate "MEN 16z188 ADC IP Core support"
> > >   depends on MCB
> > > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> > > index 38638d4..8306347 100644
> > > --- a/drivers/iio/adc/Makefile
> > > +++ b/drivers/iio/adc/Makefile
> > > @@ -30,6 +30,7 @@ obj-$(CONFIG_MAX1027) += max1027.o
> > >  obj-$(CONFIG_MAX1363) += max1363.o
> > >  obj-$(CONFIG_MCP320X) += mcp320x.o
> > >  obj-$(CONFIG_MCP3422) += mcp3422.o
> > > +obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
> > >  obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
> > >  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
> > >  obj-$(CONFIG_NAU7802) += nau7802.o
> > > diff --git a/drivers/iio/adc/mt6577_auxadc.c 
> > > b/drivers/iio/adc/mt6577_auxadc.c
> > > new file mode 100644
> > > index 000..c7cc901
> > > --- /dev/null
> > > +++ b/drivers/iio/adc/mt6577_auxadc.c
> > > @@ -0,0 +1,294 @@
> > > +/*
> > > + * Copyright (c) 2016 MediaTek Inc.
> > > + * Author: Zhiyong Tao 
> > > + *
> > > + * 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.
> > > + *
> > > + * This program is distributed in the hope that it will be useful,
> > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > + * GNU General Public License for more details.
> > > + */
> > > +
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +
> > > +/* Register definitions */
> > > +#define MT6577_AUXADC_CON00x00
> > > +#define MT6577_AUXADC_CON10x04
> > > +#define MT6577_AUXADC_CON20x10
> > > +#define MT6577_AUXADC_STA BIT(0)
> > > +
> > > +#define MT6577_AUXADC_DAT00x14
> > > +#define MT6577_AUXADC_RDY0BIT(12)
> > > +
> > > +#define MT6577_AUXADC_MISC0x94
> > > +#define MT6577_AUXADC_PDN_EN  BIT(14)
> > > +
> > > +#define MT6577_AUXADC_DAT_MASK0xfff
> > > +#define MT6577_AUXADC_SLEEP_US1000
> > > +#define MT6577_AUXADC_TIMEOUT_US  1
> > > +#define MT6577_AUXADC_POWER_READY_MS  1
> > > +#define MT6577_AUXADC_SAMPLE_READY_US 25
> > > +
> > > +struct mt6577_auxadc_device {
> > > + void __iomem *reg_base;
> > > + struct clk *adc_clk;
> > > + struct mutex lock;
> > > +};
> > > +
> > > +#define MT6577_AUXADC_CHANNEL(idx) { \
> > > + .type = IIO_VOLTAGE,\
> > > + .indexed = 1,   \
> > > + .channel = (idx),

Re: [PATCH v4 2/3] iio: adc: mt2701: Add Mediatek auxadc driver for mt2701.

2016-07-20 Thread zhiyong tao
On Wed, 2016-07-20 at 14:02 +0800, zhiyong tao wrote:
> On Mon, 2016-07-18 at 18:12 +0100, Jonathan Cameron wrote:
> > On 11/07/16 07:39, Zhiyong Tao wrote:
> > > Add Mediatek auxadc driver based on iio.
> > > It will register a device in iio and support iio.
> > > So thermal can read auxadc channel to sample data by iio device.
> > > It is tested successfully on mt2701 platform.
> > > Mt8173 and mt6577 platforms are not tested.
> > > But the expectation is compatible.
> > > 
> > > Signed-off-by: Zhiyong Tao 
> > Looks good to me.  Couple of really minor points / questions inline...
> > 
> > Just one thing to confirm... (you probably already answered this!)
> > What are the units of the voltage channels?
> > 
> > Jonathan
> 
> The units of the voltage channels are mv. 
> 
> > > ---
> > >  drivers/iio/adc/Kconfig |   13 ++
> > >  drivers/iio/adc/Makefile|1 +
> > >  drivers/iio/adc/mt6577_auxadc.c |  294 
> > > +++
> > >  3 files changed, 308 insertions(+)
> > >  create mode 100644 drivers/iio/adc/mt6577_auxadc.c
> > > 
> > > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> > > index 25378c5..14929fc 100644
> > > --- a/drivers/iio/adc/Kconfig
> > > +++ b/drivers/iio/adc/Kconfig
> > > @@ -305,6 +305,19 @@ config MCP3422
> > > This driver can also be built as a module. If so, the module will be
> > > called mcp3422.
> > >  
> > > +config MEDIATEK_MT6577_AUXADC
> > > +tristate "MediaTek AUXADC driver"
> > > +depends on ARCH_MEDIATEK || COMPILE_TEST
> > > +depends on HAS_IOMEM
> > > +help
> > > +  Say yes here to enable support for MediaTek mt65xx AUXADC.
> > > +
> > > +  The driver supports immediate mode operation to read from one 
> > > of sixteen
> > > +  channels (external or internal).
> > > +
> > > +  This driver can also be built as a module. If so, the module 
> > > will be
> > > +  called mt6577_auxadc.
> > > +
> > >  config MEN_Z188_ADC
> > >   tristate "MEN 16z188 ADC IP Core support"
> > >   depends on MCB
> > > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> > > index 38638d4..8306347 100644
> > > --- a/drivers/iio/adc/Makefile
> > > +++ b/drivers/iio/adc/Makefile
> > > @@ -30,6 +30,7 @@ obj-$(CONFIG_MAX1027) += max1027.o
> > >  obj-$(CONFIG_MAX1363) += max1363.o
> > >  obj-$(CONFIG_MCP320X) += mcp320x.o
> > >  obj-$(CONFIG_MCP3422) += mcp3422.o
> > > +obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
> > >  obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
> > >  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
> > >  obj-$(CONFIG_NAU7802) += nau7802.o
> > > diff --git a/drivers/iio/adc/mt6577_auxadc.c 
> > > b/drivers/iio/adc/mt6577_auxadc.c
> > > new file mode 100644
> > > index 000..c7cc901
> > > --- /dev/null
> > > +++ b/drivers/iio/adc/mt6577_auxadc.c
> > > @@ -0,0 +1,294 @@
> > > +/*
> > > + * Copyright (c) 2016 MediaTek Inc.
> > > + * Author: Zhiyong Tao 
> > > + *
> > > + * 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.
> > > + *
> > > + * This program is distributed in the hope that it will be useful,
> > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > + * GNU General Public License for more details.
> > > + */
> > > +
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +
> > > +/* Register definitions */
> > > +#define MT6577_AUXADC_CON00x00
> > > +#define MT6577_AUXADC_CON10x04
> > > +#define MT6577_AUXADC_CON20x10
> > > +#define MT6577_AUXADC_STA BIT(0)
> > > +
> > > +#define MT6577_AUXADC_DAT00x14
> > > +#define MT6577_AUXADC_RDY0BIT(12)
> > > +
> > > +#define MT6577_AUXADC_MISC0x94
> > > +#define MT6577_AUXADC_PDN_EN  BIT(14)
> > > +
> > > +#define MT6577_AUXADC_DAT_MASK0xfff
> > > +#define MT6577_AUXADC_SLEEP_US1000
> > > +#define MT6577_AUXADC_TIMEOUT_US  1
> > > +#define MT6577_AUXADC_POWER_READY_MS  1
> > > +#define MT6577_AUXADC_SAMPLE_READY_US 25
> > > +
> > > +struct mt6577_auxadc_device {
> > > + void __iomem *reg_base;
> > > + struct clk *adc_clk;
> > > + struct mutex lock;
> > > +};
> > > +
> > > +#define MT6577_AUXADC_CHANNEL(idx) { \
> > > + .type = IIO_VOLTAGE,\
> > > + .indexed = 1,   \
> > > + .channel = (idx),   \
> > > + .info_mask_separate = 

Re: [PATCH v4 2/3] iio: adc: mt2701: Add Mediatek auxadc driver for mt2701.

2016-07-20 Thread zhiyong tao
On Mon, 2016-07-18 at 18:12 +0100, Jonathan Cameron wrote:
> On 11/07/16 07:39, Zhiyong Tao wrote:
> > Add Mediatek auxadc driver based on iio.
> > It will register a device in iio and support iio.
> > So thermal can read auxadc channel to sample data by iio device.
> > It is tested successfully on mt2701 platform.
> > Mt8173 and mt6577 platforms are not tested.
> > But the expectation is compatible.
> > 
> > Signed-off-by: Zhiyong Tao 
> Looks good to me.  Couple of really minor points / questions inline...
> 
> Just one thing to confirm... (you probably already answered this!)
> What are the units of the voltage channels?
> 
> Jonathan

The units of the voltage channels are mv. 

> > ---
> >  drivers/iio/adc/Kconfig |   13 ++
> >  drivers/iio/adc/Makefile|1 +
> >  drivers/iio/adc/mt6577_auxadc.c |  294 
> > +++
> >  3 files changed, 308 insertions(+)
> >  create mode 100644 drivers/iio/adc/mt6577_auxadc.c
> > 
> > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> > index 25378c5..14929fc 100644
> > --- a/drivers/iio/adc/Kconfig
> > +++ b/drivers/iio/adc/Kconfig
> > @@ -305,6 +305,19 @@ config MCP3422
> >   This driver can also be built as a module. If so, the module will be
> >   called mcp3422.
> >  
> > +config MEDIATEK_MT6577_AUXADC
> > +tristate "MediaTek AUXADC driver"
> > +depends on ARCH_MEDIATEK || COMPILE_TEST
> > +depends on HAS_IOMEM
> > +help
> > +  Say yes here to enable support for MediaTek mt65xx AUXADC.
> > +
> > +  The driver supports immediate mode operation to read from one of 
> > sixteen
> > +  channels (external or internal).
> > +
> > +  This driver can also be built as a module. If so, the module 
> > will be
> > +  called mt6577_auxadc.
> > +
> >  config MEN_Z188_ADC
> > tristate "MEN 16z188 ADC IP Core support"
> > depends on MCB
> > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> > index 38638d4..8306347 100644
> > --- a/drivers/iio/adc/Makefile
> > +++ b/drivers/iio/adc/Makefile
> > @@ -30,6 +30,7 @@ obj-$(CONFIG_MAX1027) += max1027.o
> >  obj-$(CONFIG_MAX1363) += max1363.o
> >  obj-$(CONFIG_MCP320X) += mcp320x.o
> >  obj-$(CONFIG_MCP3422) += mcp3422.o
> > +obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
> >  obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
> >  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
> >  obj-$(CONFIG_NAU7802) += nau7802.o
> > diff --git a/drivers/iio/adc/mt6577_auxadc.c 
> > b/drivers/iio/adc/mt6577_auxadc.c
> > new file mode 100644
> > index 000..c7cc901
> > --- /dev/null
> > +++ b/drivers/iio/adc/mt6577_auxadc.c
> > @@ -0,0 +1,294 @@
> > +/*
> > + * Copyright (c) 2016 MediaTek Inc.
> > + * Author: Zhiyong Tao 
> > + *
> > + * 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.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/* Register definitions */
> > +#define MT6577_AUXADC_CON00x00
> > +#define MT6577_AUXADC_CON10x04
> > +#define MT6577_AUXADC_CON20x10
> > +#define MT6577_AUXADC_STA BIT(0)
> > +
> > +#define MT6577_AUXADC_DAT00x14
> > +#define MT6577_AUXADC_RDY0BIT(12)
> > +
> > +#define MT6577_AUXADC_MISC0x94
> > +#define MT6577_AUXADC_PDN_EN  BIT(14)
> > +
> > +#define MT6577_AUXADC_DAT_MASK0xfff
> > +#define MT6577_AUXADC_SLEEP_US1000
> > +#define MT6577_AUXADC_TIMEOUT_US  1
> > +#define MT6577_AUXADC_POWER_READY_MS  1
> > +#define MT6577_AUXADC_SAMPLE_READY_US 25
> > +
> > +struct mt6577_auxadc_device {
> > +   void __iomem *reg_base;
> > +   struct clk *adc_clk;
> > +   struct mutex lock;
> > +};
> > +
> > +#define MT6577_AUXADC_CHANNEL(idx) {   \
> > +   .type = IIO_VOLTAGE,\
> > +   .indexed = 1,   \
> > +   .channel = (idx),   \
> > +   .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
> > +}
> > +
> > +static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {
> > +   MT6577_AUXADC_CHANNEL(0),
> > +   MT6577_AUXADC_CHANNEL(1),
> > +   MT6577_AUXADC_CHANNEL(2),
> > +   

Re: [PATCH v4 2/3] iio: adc: mt2701: Add Mediatek auxadc driver for mt2701.

2016-07-20 Thread zhiyong tao
On Mon, 2016-07-18 at 18:12 +0100, Jonathan Cameron wrote:
> On 11/07/16 07:39, Zhiyong Tao wrote:
> > Add Mediatek auxadc driver based on iio.
> > It will register a device in iio and support iio.
> > So thermal can read auxadc channel to sample data by iio device.
> > It is tested successfully on mt2701 platform.
> > Mt8173 and mt6577 platforms are not tested.
> > But the expectation is compatible.
> > 
> > Signed-off-by: Zhiyong Tao 
> Looks good to me.  Couple of really minor points / questions inline...
> 
> Just one thing to confirm... (you probably already answered this!)
> What are the units of the voltage channels?
> 
> Jonathan

The units of the voltage channels are mv. 

> > ---
> >  drivers/iio/adc/Kconfig |   13 ++
> >  drivers/iio/adc/Makefile|1 +
> >  drivers/iio/adc/mt6577_auxadc.c |  294 
> > +++
> >  3 files changed, 308 insertions(+)
> >  create mode 100644 drivers/iio/adc/mt6577_auxadc.c
> > 
> > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> > index 25378c5..14929fc 100644
> > --- a/drivers/iio/adc/Kconfig
> > +++ b/drivers/iio/adc/Kconfig
> > @@ -305,6 +305,19 @@ config MCP3422
> >   This driver can also be built as a module. If so, the module will be
> >   called mcp3422.
> >  
> > +config MEDIATEK_MT6577_AUXADC
> > +tristate "MediaTek AUXADC driver"
> > +depends on ARCH_MEDIATEK || COMPILE_TEST
> > +depends on HAS_IOMEM
> > +help
> > +  Say yes here to enable support for MediaTek mt65xx AUXADC.
> > +
> > +  The driver supports immediate mode operation to read from one of 
> > sixteen
> > +  channels (external or internal).
> > +
> > +  This driver can also be built as a module. If so, the module 
> > will be
> > +  called mt6577_auxadc.
> > +
> >  config MEN_Z188_ADC
> > tristate "MEN 16z188 ADC IP Core support"
> > depends on MCB
> > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> > index 38638d4..8306347 100644
> > --- a/drivers/iio/adc/Makefile
> > +++ b/drivers/iio/adc/Makefile
> > @@ -30,6 +30,7 @@ obj-$(CONFIG_MAX1027) += max1027.o
> >  obj-$(CONFIG_MAX1363) += max1363.o
> >  obj-$(CONFIG_MCP320X) += mcp320x.o
> >  obj-$(CONFIG_MCP3422) += mcp3422.o
> > +obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
> >  obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
> >  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
> >  obj-$(CONFIG_NAU7802) += nau7802.o
> > diff --git a/drivers/iio/adc/mt6577_auxadc.c 
> > b/drivers/iio/adc/mt6577_auxadc.c
> > new file mode 100644
> > index 000..c7cc901
> > --- /dev/null
> > +++ b/drivers/iio/adc/mt6577_auxadc.c
> > @@ -0,0 +1,294 @@
> > +/*
> > + * Copyright (c) 2016 MediaTek Inc.
> > + * Author: Zhiyong Tao 
> > + *
> > + * 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.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/* Register definitions */
> > +#define MT6577_AUXADC_CON00x00
> > +#define MT6577_AUXADC_CON10x04
> > +#define MT6577_AUXADC_CON20x10
> > +#define MT6577_AUXADC_STA BIT(0)
> > +
> > +#define MT6577_AUXADC_DAT00x14
> > +#define MT6577_AUXADC_RDY0BIT(12)
> > +
> > +#define MT6577_AUXADC_MISC0x94
> > +#define MT6577_AUXADC_PDN_EN  BIT(14)
> > +
> > +#define MT6577_AUXADC_DAT_MASK0xfff
> > +#define MT6577_AUXADC_SLEEP_US1000
> > +#define MT6577_AUXADC_TIMEOUT_US  1
> > +#define MT6577_AUXADC_POWER_READY_MS  1
> > +#define MT6577_AUXADC_SAMPLE_READY_US 25
> > +
> > +struct mt6577_auxadc_device {
> > +   void __iomem *reg_base;
> > +   struct clk *adc_clk;
> > +   struct mutex lock;
> > +};
> > +
> > +#define MT6577_AUXADC_CHANNEL(idx) {   \
> > +   .type = IIO_VOLTAGE,\
> > +   .indexed = 1,   \
> > +   .channel = (idx),   \
> > +   .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
> > +}
> > +
> > +static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {
> > +   MT6577_AUXADC_CHANNEL(0),
> > +   MT6577_AUXADC_CHANNEL(1),
> > +   MT6577_AUXADC_CHANNEL(2),
> > +   MT6577_AUXADC_CHANNEL(3),
> > +   

Re: [PATCH v4 2/3] iio: adc: mt2701: Add Mediatek auxadc driver for mt2701.

2016-07-18 Thread Jonathan Cameron
On 11/07/16 07:39, Zhiyong Tao wrote:
> Add Mediatek auxadc driver based on iio.
> It will register a device in iio and support iio.
> So thermal can read auxadc channel to sample data by iio device.
> It is tested successfully on mt2701 platform.
> Mt8173 and mt6577 platforms are not tested.
> But the expectation is compatible.
> 
> Signed-off-by: Zhiyong Tao 
Looks good to me.  Couple of really minor points / questions inline...

Just one thing to confirm... (you probably already answered this!)
What are the units of the voltage channels?

Jonathan
> ---
>  drivers/iio/adc/Kconfig |   13 ++
>  drivers/iio/adc/Makefile|1 +
>  drivers/iio/adc/mt6577_auxadc.c |  294 
> +++
>  3 files changed, 308 insertions(+)
>  create mode 100644 drivers/iio/adc/mt6577_auxadc.c
> 
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 25378c5..14929fc 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -305,6 +305,19 @@ config MCP3422
> This driver can also be built as a module. If so, the module will be
> called mcp3422.
>  
> +config MEDIATEK_MT6577_AUXADC
> +tristate "MediaTek AUXADC driver"
> +depends on ARCH_MEDIATEK || COMPILE_TEST
> +depends on HAS_IOMEM
> +help
> +  Say yes here to enable support for MediaTek mt65xx AUXADC.
> +
> +  The driver supports immediate mode operation to read from one of 
> sixteen
> +  channels (external or internal).
> +
> +  This driver can also be built as a module. If so, the module will 
> be
> +  called mt6577_auxadc.
> +
>  config MEN_Z188_ADC
>   tristate "MEN 16z188 ADC IP Core support"
>   depends on MCB
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index 38638d4..8306347 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -30,6 +30,7 @@ obj-$(CONFIG_MAX1027) += max1027.o
>  obj-$(CONFIG_MAX1363) += max1363.o
>  obj-$(CONFIG_MCP320X) += mcp320x.o
>  obj-$(CONFIG_MCP3422) += mcp3422.o
> +obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
>  obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
>  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
>  obj-$(CONFIG_NAU7802) += nau7802.o
> diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c
> new file mode 100644
> index 000..c7cc901
> --- /dev/null
> +++ b/drivers/iio/adc/mt6577_auxadc.c
> @@ -0,0 +1,294 @@
> +/*
> + * Copyright (c) 2016 MediaTek Inc.
> + * Author: Zhiyong Tao 
> + *
> + * 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.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/* Register definitions */
> +#define MT6577_AUXADC_CON00x00
> +#define MT6577_AUXADC_CON10x04
> +#define MT6577_AUXADC_CON20x10
> +#define MT6577_AUXADC_STA BIT(0)
> +
> +#define MT6577_AUXADC_DAT00x14
> +#define MT6577_AUXADC_RDY0BIT(12)
> +
> +#define MT6577_AUXADC_MISC0x94
> +#define MT6577_AUXADC_PDN_EN  BIT(14)
> +
> +#define MT6577_AUXADC_DAT_MASK0xfff
> +#define MT6577_AUXADC_SLEEP_US1000
> +#define MT6577_AUXADC_TIMEOUT_US  1
> +#define MT6577_AUXADC_POWER_READY_MS  1
> +#define MT6577_AUXADC_SAMPLE_READY_US 25
> +
> +struct mt6577_auxadc_device {
> + void __iomem *reg_base;
> + struct clk *adc_clk;
> + struct mutex lock;
> +};
> +
> +#define MT6577_AUXADC_CHANNEL(idx) { \
> + .type = IIO_VOLTAGE,\
> + .indexed = 1,   \
> + .channel = (idx),   \
> + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
> +}
> +
> +static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {
> + MT6577_AUXADC_CHANNEL(0),
> + MT6577_AUXADC_CHANNEL(1),
> + MT6577_AUXADC_CHANNEL(2),
> + MT6577_AUXADC_CHANNEL(3),
> + MT6577_AUXADC_CHANNEL(4),
> + MT6577_AUXADC_CHANNEL(5),
> + MT6577_AUXADC_CHANNEL(6),
> + MT6577_AUXADC_CHANNEL(7),
> + MT6577_AUXADC_CHANNEL(8),
> + MT6577_AUXADC_CHANNEL(9),
> + MT6577_AUXADC_CHANNEL(10),
> + MT6577_AUXADC_CHANNEL(11),
> + MT6577_AUXADC_CHANNEL(12),
> + 

Re: [PATCH v4 2/3] iio: adc: mt2701: Add Mediatek auxadc driver for mt2701.

2016-07-18 Thread Jonathan Cameron
On 11/07/16 07:39, Zhiyong Tao wrote:
> Add Mediatek auxadc driver based on iio.
> It will register a device in iio and support iio.
> So thermal can read auxadc channel to sample data by iio device.
> It is tested successfully on mt2701 platform.
> Mt8173 and mt6577 platforms are not tested.
> But the expectation is compatible.
> 
> Signed-off-by: Zhiyong Tao 
Looks good to me.  Couple of really minor points / questions inline...

Just one thing to confirm... (you probably already answered this!)
What are the units of the voltage channels?

Jonathan
> ---
>  drivers/iio/adc/Kconfig |   13 ++
>  drivers/iio/adc/Makefile|1 +
>  drivers/iio/adc/mt6577_auxadc.c |  294 
> +++
>  3 files changed, 308 insertions(+)
>  create mode 100644 drivers/iio/adc/mt6577_auxadc.c
> 
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 25378c5..14929fc 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -305,6 +305,19 @@ config MCP3422
> This driver can also be built as a module. If so, the module will be
> called mcp3422.
>  
> +config MEDIATEK_MT6577_AUXADC
> +tristate "MediaTek AUXADC driver"
> +depends on ARCH_MEDIATEK || COMPILE_TEST
> +depends on HAS_IOMEM
> +help
> +  Say yes here to enable support for MediaTek mt65xx AUXADC.
> +
> +  The driver supports immediate mode operation to read from one of 
> sixteen
> +  channels (external or internal).
> +
> +  This driver can also be built as a module. If so, the module will 
> be
> +  called mt6577_auxadc.
> +
>  config MEN_Z188_ADC
>   tristate "MEN 16z188 ADC IP Core support"
>   depends on MCB
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index 38638d4..8306347 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -30,6 +30,7 @@ obj-$(CONFIG_MAX1027) += max1027.o
>  obj-$(CONFIG_MAX1363) += max1363.o
>  obj-$(CONFIG_MCP320X) += mcp320x.o
>  obj-$(CONFIG_MCP3422) += mcp3422.o
> +obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
>  obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
>  obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
>  obj-$(CONFIG_NAU7802) += nau7802.o
> diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c
> new file mode 100644
> index 000..c7cc901
> --- /dev/null
> +++ b/drivers/iio/adc/mt6577_auxadc.c
> @@ -0,0 +1,294 @@
> +/*
> + * Copyright (c) 2016 MediaTek Inc.
> + * Author: Zhiyong Tao 
> + *
> + * 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.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/* Register definitions */
> +#define MT6577_AUXADC_CON00x00
> +#define MT6577_AUXADC_CON10x04
> +#define MT6577_AUXADC_CON20x10
> +#define MT6577_AUXADC_STA BIT(0)
> +
> +#define MT6577_AUXADC_DAT00x14
> +#define MT6577_AUXADC_RDY0BIT(12)
> +
> +#define MT6577_AUXADC_MISC0x94
> +#define MT6577_AUXADC_PDN_EN  BIT(14)
> +
> +#define MT6577_AUXADC_DAT_MASK0xfff
> +#define MT6577_AUXADC_SLEEP_US1000
> +#define MT6577_AUXADC_TIMEOUT_US  1
> +#define MT6577_AUXADC_POWER_READY_MS  1
> +#define MT6577_AUXADC_SAMPLE_READY_US 25
> +
> +struct mt6577_auxadc_device {
> + void __iomem *reg_base;
> + struct clk *adc_clk;
> + struct mutex lock;
> +};
> +
> +#define MT6577_AUXADC_CHANNEL(idx) { \
> + .type = IIO_VOLTAGE,\
> + .indexed = 1,   \
> + .channel = (idx),   \
> + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
> +}
> +
> +static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {
> + MT6577_AUXADC_CHANNEL(0),
> + MT6577_AUXADC_CHANNEL(1),
> + MT6577_AUXADC_CHANNEL(2),
> + MT6577_AUXADC_CHANNEL(3),
> + MT6577_AUXADC_CHANNEL(4),
> + MT6577_AUXADC_CHANNEL(5),
> + MT6577_AUXADC_CHANNEL(6),
> + MT6577_AUXADC_CHANNEL(7),
> + MT6577_AUXADC_CHANNEL(8),
> + MT6577_AUXADC_CHANNEL(9),
> + MT6577_AUXADC_CHANNEL(10),
> + MT6577_AUXADC_CHANNEL(11),
> + MT6577_AUXADC_CHANNEL(12),
> + MT6577_AUXADC_CHANNEL(13),
> + 

[PATCH v4 2/3] iio: adc: mt2701: Add Mediatek auxadc driver for mt2701.

2016-07-11 Thread Zhiyong Tao
Add Mediatek auxadc driver based on iio.
It will register a device in iio and support iio.
So thermal can read auxadc channel to sample data by iio device.
It is tested successfully on mt2701 platform.
Mt8173 and mt6577 platforms are not tested.
But the expectation is compatible.

Signed-off-by: Zhiyong Tao 
---
 drivers/iio/adc/Kconfig |   13 ++
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/mt6577_auxadc.c |  294 +++
 3 files changed, 308 insertions(+)
 create mode 100644 drivers/iio/adc/mt6577_auxadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 25378c5..14929fc 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -305,6 +305,19 @@ config MCP3422
  This driver can also be built as a module. If so, the module will be
  called mcp3422.
 
+config MEDIATEK_MT6577_AUXADC
+tristate "MediaTek AUXADC driver"
+depends on ARCH_MEDIATEK || COMPILE_TEST
+depends on HAS_IOMEM
+help
+  Say yes here to enable support for MediaTek mt65xx AUXADC.
+
+  The driver supports immediate mode operation to read from one of 
sixteen
+  channels (external or internal).
+
+  This driver can also be built as a module. If so, the module will be
+  called mt6577_auxadc.
+
 config MEN_Z188_ADC
tristate "MEN 16z188 ADC IP Core support"
depends on MCB
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 38638d4..8306347 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_MAX1027) += max1027.o
 obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_MCP320X) += mcp320x.o
 obj-$(CONFIG_MCP3422) += mcp3422.o
+obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
 obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
 obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
 obj-$(CONFIG_NAU7802) += nau7802.o
diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c
new file mode 100644
index 000..c7cc901
--- /dev/null
+++ b/drivers/iio/adc/mt6577_auxadc.c
@@ -0,0 +1,294 @@
+/*
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Zhiyong Tao 
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Register definitions */
+#define MT6577_AUXADC_CON00x00
+#define MT6577_AUXADC_CON10x04
+#define MT6577_AUXADC_CON20x10
+#define MT6577_AUXADC_STA BIT(0)
+
+#define MT6577_AUXADC_DAT00x14
+#define MT6577_AUXADC_RDY0BIT(12)
+
+#define MT6577_AUXADC_MISC0x94
+#define MT6577_AUXADC_PDN_EN  BIT(14)
+
+#define MT6577_AUXADC_DAT_MASK0xfff
+#define MT6577_AUXADC_SLEEP_US1000
+#define MT6577_AUXADC_TIMEOUT_US  1
+#define MT6577_AUXADC_POWER_READY_MS  1
+#define MT6577_AUXADC_SAMPLE_READY_US 25
+
+struct mt6577_auxadc_device {
+   void __iomem *reg_base;
+   struct clk *adc_clk;
+   struct mutex lock;
+};
+
+#define MT6577_AUXADC_CHANNEL(idx) {   \
+   .type = IIO_VOLTAGE,\
+   .indexed = 1,   \
+   .channel = (idx),   \
+   .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
+}
+
+static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {
+   MT6577_AUXADC_CHANNEL(0),
+   MT6577_AUXADC_CHANNEL(1),
+   MT6577_AUXADC_CHANNEL(2),
+   MT6577_AUXADC_CHANNEL(3),
+   MT6577_AUXADC_CHANNEL(4),
+   MT6577_AUXADC_CHANNEL(5),
+   MT6577_AUXADC_CHANNEL(6),
+   MT6577_AUXADC_CHANNEL(7),
+   MT6577_AUXADC_CHANNEL(8),
+   MT6577_AUXADC_CHANNEL(9),
+   MT6577_AUXADC_CHANNEL(10),
+   MT6577_AUXADC_CHANNEL(11),
+   MT6577_AUXADC_CHANNEL(12),
+   MT6577_AUXADC_CHANNEL(13),
+   MT6577_AUXADC_CHANNEL(14),
+   MT6577_AUXADC_CHANNEL(15),
+};
+
+static int mt6577_auxadc_read(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan)
+{
+   u32 rawdata, val;
+   void __iomem *reg_channel;
+   int ret;
+   struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev);
+
+   reg_channel = adc_dev->reg_base + MT6577_AUXADC_DAT0 +
+   

[PATCH v4 2/3] iio: adc: mt2701: Add Mediatek auxadc driver for mt2701.

2016-07-11 Thread Zhiyong Tao
Add Mediatek auxadc driver based on iio.
It will register a device in iio and support iio.
So thermal can read auxadc channel to sample data by iio device.
It is tested successfully on mt2701 platform.
Mt8173 and mt6577 platforms are not tested.
But the expectation is compatible.

Signed-off-by: Zhiyong Tao 
---
 drivers/iio/adc/Kconfig |   13 ++
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/mt6577_auxadc.c |  294 +++
 3 files changed, 308 insertions(+)
 create mode 100644 drivers/iio/adc/mt6577_auxadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 25378c5..14929fc 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -305,6 +305,19 @@ config MCP3422
  This driver can also be built as a module. If so, the module will be
  called mcp3422.
 
+config MEDIATEK_MT6577_AUXADC
+tristate "MediaTek AUXADC driver"
+depends on ARCH_MEDIATEK || COMPILE_TEST
+depends on HAS_IOMEM
+help
+  Say yes here to enable support for MediaTek mt65xx AUXADC.
+
+  The driver supports immediate mode operation to read from one of 
sixteen
+  channels (external or internal).
+
+  This driver can also be built as a module. If so, the module will be
+  called mt6577_auxadc.
+
 config MEN_Z188_ADC
tristate "MEN 16z188 ADC IP Core support"
depends on MCB
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 38638d4..8306347 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_MAX1027) += max1027.o
 obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_MCP320X) += mcp320x.o
 obj-$(CONFIG_MCP3422) += mcp3422.o
+obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
 obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
 obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
 obj-$(CONFIG_NAU7802) += nau7802.o
diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c
new file mode 100644
index 000..c7cc901
--- /dev/null
+++ b/drivers/iio/adc/mt6577_auxadc.c
@@ -0,0 +1,294 @@
+/*
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Zhiyong Tao 
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Register definitions */
+#define MT6577_AUXADC_CON00x00
+#define MT6577_AUXADC_CON10x04
+#define MT6577_AUXADC_CON20x10
+#define MT6577_AUXADC_STA BIT(0)
+
+#define MT6577_AUXADC_DAT00x14
+#define MT6577_AUXADC_RDY0BIT(12)
+
+#define MT6577_AUXADC_MISC0x94
+#define MT6577_AUXADC_PDN_EN  BIT(14)
+
+#define MT6577_AUXADC_DAT_MASK0xfff
+#define MT6577_AUXADC_SLEEP_US1000
+#define MT6577_AUXADC_TIMEOUT_US  1
+#define MT6577_AUXADC_POWER_READY_MS  1
+#define MT6577_AUXADC_SAMPLE_READY_US 25
+
+struct mt6577_auxadc_device {
+   void __iomem *reg_base;
+   struct clk *adc_clk;
+   struct mutex lock;
+};
+
+#define MT6577_AUXADC_CHANNEL(idx) {   \
+   .type = IIO_VOLTAGE,\
+   .indexed = 1,   \
+   .channel = (idx),   \
+   .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
+}
+
+static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {
+   MT6577_AUXADC_CHANNEL(0),
+   MT6577_AUXADC_CHANNEL(1),
+   MT6577_AUXADC_CHANNEL(2),
+   MT6577_AUXADC_CHANNEL(3),
+   MT6577_AUXADC_CHANNEL(4),
+   MT6577_AUXADC_CHANNEL(5),
+   MT6577_AUXADC_CHANNEL(6),
+   MT6577_AUXADC_CHANNEL(7),
+   MT6577_AUXADC_CHANNEL(8),
+   MT6577_AUXADC_CHANNEL(9),
+   MT6577_AUXADC_CHANNEL(10),
+   MT6577_AUXADC_CHANNEL(11),
+   MT6577_AUXADC_CHANNEL(12),
+   MT6577_AUXADC_CHANNEL(13),
+   MT6577_AUXADC_CHANNEL(14),
+   MT6577_AUXADC_CHANNEL(15),
+};
+
+static int mt6577_auxadc_read(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan)
+{
+   u32 rawdata, val;
+   void __iomem *reg_channel;
+   int ret;
+   struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev);
+
+   reg_channel = adc_dev->reg_base + MT6577_AUXADC_DAT0 +
+ chan->channel * 0x04;
+
+