From: Lars-Peter Clausen <lars@metafoo.de>
To: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Shawn Guo <shawn.guo@linaro.org>,
Grant Likely <grant.likely@secretlab.ca>,
jimwall@q.com, brian@crystalfontz.com,
Maxime Ripard <maxime.ripard@free-electrons.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
devicetree-discuss@lists.ozlabs.org,
Jonathan Cameron <jic23@cam.ac.uk>, Rob Landley <rob@landley.net>,
Rob Herring <rob.herring@calxeda.com>
Subject: Re: [PATCHv2 1/3] iio: Add Nuvoton NAU7802 ADC driver
Date: Mon, 24 Jun 2013 08:41:39 +0200 [thread overview]
Message-ID: <51C7EA23.1040707@metafoo.de> (raw)
In-Reply-To: <1371754675-12242-2-git-send-email-alexandre.belloni@free-electrons.com>
On 06/20/2013 08:57 PM, Alexandre Belloni wrote:
> The Nuvoton NAU7802 ADC is a 24-bit 2-channels I2C ADC, with adjustable
> gain and sampling rates.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> ---
> .../bindings/iio/adc/nuvoton-nau7802.txt | 17 +
> drivers/iio/adc/Kconfig | 9 +
> drivers/iio/adc/Makefile | 1 +
> drivers/iio/adc/nau7802.c | 603 +++++++++++++++++++++
> 4 files changed, 630 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/iio/adc/nuvoton-nau7802.txt
> create mode 100644 drivers/iio/adc/nau7802.c
>
> diff --git a/Documentation/devicetree/bindings/iio/adc/nuvoton-nau7802.txt b/Documentation/devicetree/bindings/iio/adc/nuvoton-nau7802.txt
> new file mode 100644
> index 0000000..9bc4218
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/adc/nuvoton-nau7802.txt
> @@ -0,0 +1,17 @@
> +* Nuvoton NAU7802 Analog to Digital Converter (ADC)use
> +
> +Required properties:
> + - compatible: Should be "nuvoton,nau7802"
> + - reg: Should contain the ADC I2C address
> +
> +Optional properties:
> + - nuvoton,vldo: Reference voltage in millivolts (integer)
> + - interrupts: IRQ line for the ADC. If not used the driver will use
> + polling.
> +
> +Example:
> +adc2: nau7802@2a {
> + compatible = "nuvoton,nau7802";
> + reg = <0x2a>;
> + nuvoton,vldo = <3000>;
We usually use the regulator framework for specifying the reference voltage.
> +};
[...]
> diff --git a/drivers/iio/adc/nau7802.c b/drivers/iio/adc/nau7802.c
> new file mode 100644
> index 0000000..e1b6981
> --- /dev/null
> +++ b/drivers/iio/adc/nau7802.c
> @@ -0,0 +1,603 @@
[...]
> +static int nau7802_set_gain(struct nau7802_state *st, int gain)
> +{
> + u8 data;
> + int ret;
> +
> + mutex_lock(&st->lock);
> + st->conversion_count = 0;
> +
> + data = i2c_smbus_read_byte_data(st->client, NAU7802_REG_CTRL1);
> + if (data < 0)
> + goto nau7802_sysfs_set_gain_out;
ret will be uninitialized if the goto above is taken
> + ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_CTRL1,
> + (data & (~NAU7802_CTRL1_GAINS_BITS)) |
> + gain);
> +
> +nau7802_sysfs_set_gain_out:
> + mutex_unlock(&st->lock);
> +
> + return ret ? ret : 0;
> +}
[...]
> +static int nau7802_read_irq(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int *val)
> +{
> + struct nau7802_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + INIT_COMPLETION(st->value_ok);
> + enable_irq(st->client->irq);
Is it really necessary to enable/disable the IRQ or could you keep it
enabled all the time?
> +
> + nau7802_sync(st);
> +
> + /* read registers to ensure we flush everything */
> + ret = nau7802_read_conversion(st);
> + if (ret < 0)
> + goto read_chan_info_failure;
> +
> + /* Wait for a conversion to finish */
> + ret = wait_for_completion_interruptible_timeout(&st->value_ok,
> + msecs_to_jiffies(1000));
> + if (ret == 0)
> + ret = -ETIMEDOUT;
> +
> + if (ret < 0)
> + goto read_chan_info_failure;
> +
> + disable_irq(st->client->irq);
> +
> + *val = st->last_value;
> +
> + return IIO_VAL_INT;
> +
> +read_chan_info_failure:
> + disable_irq(st->client->irq);
> +
> + return ret;
> +}
[...]
[...]
> +static int nau7802_probe(struct i2c_client *client,
> + const struct i2c_device_id *id)
> +{
> + struct iio_dev *indio_dev;
> + struct nau7802_state *st;
> + struct device_node *np = client->dev.of_node;
> + int i, ret;
> + u8 data;
> + u32 tmp;
> +
> + if (!client->dev.of_node) {
> + dev_err(&client->dev, "No device tree node available.\n");
> + return -EINVAL;
> + }
Except for getting the vref the is no direct dependency on devicetree, if
you switch to the regulator framework for the vref this check can be removed.
[...]
> + /* Setup the ADC channels available on the board */
> + indio_dev->num_channels = 2;
ARRAY_SIZE(nau7802_chan_array)
> + indio_dev->channels = nau7802_chan_array;
> +
> + init_completion(&st->value_ok);
You need to initialize the completion before requesting the IRQ handler.
[...]
> +}
WARNING: multiple messages have this Message-ID (diff)
From: lars@metafoo.de (Lars-Peter Clausen)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv2 1/3] iio: Add Nuvoton NAU7802 ADC driver
Date: Mon, 24 Jun 2013 08:41:39 +0200 [thread overview]
Message-ID: <51C7EA23.1040707@metafoo.de> (raw)
In-Reply-To: <1371754675-12242-2-git-send-email-alexandre.belloni@free-electrons.com>
On 06/20/2013 08:57 PM, Alexandre Belloni wrote:
> The Nuvoton NAU7802 ADC is a 24-bit 2-channels I2C ADC, with adjustable
> gain and sampling rates.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> ---
> .../bindings/iio/adc/nuvoton-nau7802.txt | 17 +
> drivers/iio/adc/Kconfig | 9 +
> drivers/iio/adc/Makefile | 1 +
> drivers/iio/adc/nau7802.c | 603 +++++++++++++++++++++
> 4 files changed, 630 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/iio/adc/nuvoton-nau7802.txt
> create mode 100644 drivers/iio/adc/nau7802.c
>
> diff --git a/Documentation/devicetree/bindings/iio/adc/nuvoton-nau7802.txt b/Documentation/devicetree/bindings/iio/adc/nuvoton-nau7802.txt
> new file mode 100644
> index 0000000..9bc4218
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/adc/nuvoton-nau7802.txt
> @@ -0,0 +1,17 @@
> +* Nuvoton NAU7802 Analog to Digital Converter (ADC)use
> +
> +Required properties:
> + - compatible: Should be "nuvoton,nau7802"
> + - reg: Should contain the ADC I2C address
> +
> +Optional properties:
> + - nuvoton,vldo: Reference voltage in millivolts (integer)
> + - interrupts: IRQ line for the ADC. If not used the driver will use
> + polling.
> +
> +Example:
> +adc2: nau7802 at 2a {
> + compatible = "nuvoton,nau7802";
> + reg = <0x2a>;
> + nuvoton,vldo = <3000>;
We usually use the regulator framework for specifying the reference voltage.
> +};
[...]
> diff --git a/drivers/iio/adc/nau7802.c b/drivers/iio/adc/nau7802.c
> new file mode 100644
> index 0000000..e1b6981
> --- /dev/null
> +++ b/drivers/iio/adc/nau7802.c
> @@ -0,0 +1,603 @@
[...]
> +static int nau7802_set_gain(struct nau7802_state *st, int gain)
> +{
> + u8 data;
> + int ret;
> +
> + mutex_lock(&st->lock);
> + st->conversion_count = 0;
> +
> + data = i2c_smbus_read_byte_data(st->client, NAU7802_REG_CTRL1);
> + if (data < 0)
> + goto nau7802_sysfs_set_gain_out;
ret will be uninitialized if the goto above is taken
> + ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_CTRL1,
> + (data & (~NAU7802_CTRL1_GAINS_BITS)) |
> + gain);
> +
> +nau7802_sysfs_set_gain_out:
> + mutex_unlock(&st->lock);
> +
> + return ret ? ret : 0;
> +}
[...]
> +static int nau7802_read_irq(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int *val)
> +{
> + struct nau7802_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + INIT_COMPLETION(st->value_ok);
> + enable_irq(st->client->irq);
Is it really necessary to enable/disable the IRQ or could you keep it
enabled all the time?
> +
> + nau7802_sync(st);
> +
> + /* read registers to ensure we flush everything */
> + ret = nau7802_read_conversion(st);
> + if (ret < 0)
> + goto read_chan_info_failure;
> +
> + /* Wait for a conversion to finish */
> + ret = wait_for_completion_interruptible_timeout(&st->value_ok,
> + msecs_to_jiffies(1000));
> + if (ret == 0)
> + ret = -ETIMEDOUT;
> +
> + if (ret < 0)
> + goto read_chan_info_failure;
> +
> + disable_irq(st->client->irq);
> +
> + *val = st->last_value;
> +
> + return IIO_VAL_INT;
> +
> +read_chan_info_failure:
> + disable_irq(st->client->irq);
> +
> + return ret;
> +}
[...]
[...]
> +static int nau7802_probe(struct i2c_client *client,
> + const struct i2c_device_id *id)
> +{
> + struct iio_dev *indio_dev;
> + struct nau7802_state *st;
> + struct device_node *np = client->dev.of_node;
> + int i, ret;
> + u8 data;
> + u32 tmp;
> +
> + if (!client->dev.of_node) {
> + dev_err(&client->dev, "No device tree node available.\n");
> + return -EINVAL;
> + }
Except for getting the vref the is no direct dependency on devicetree, if
you switch to the regulator framework for the vref this check can be removed.
[...]
> + /* Setup the ADC channels available on the board */
> + indio_dev->num_channels = 2;
ARRAY_SIZE(nau7802_chan_array)
> + indio_dev->channels = nau7802_chan_array;
> +
> + init_completion(&st->value_ok);
You need to initialize the completion before requesting the IRQ handler.
[...]
> +}
next prev parent reply other threads:[~2013-06-24 6:41 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-20 18:57 [PATCHv2 0/3] Add support for the Nuvoton NAU7802 ADC to the cfa10049 Alexandre Belloni
2013-06-20 18:57 ` Alexandre Belloni
2013-06-20 18:57 ` Alexandre Belloni
2013-06-20 18:57 ` [PATCHv2 1/3] iio: Add Nuvoton NAU7802 ADC driver Alexandre Belloni
2013-06-20 18:57 ` Alexandre Belloni
2013-06-22 11:55 ` Jonathan Cameron
2013-06-22 11:55 ` Jonathan Cameron
2013-06-22 11:55 ` Jonathan Cameron
2013-06-22 12:02 ` Lars-Peter Clausen
2013-06-22 12:02 ` Lars-Peter Clausen
2013-06-22 12:02 ` Lars-Peter Clausen
2013-06-22 13:07 ` Alexandre Belloni
2013-06-22 13:07 ` Alexandre Belloni
2013-06-22 13:07 ` Alexandre Belloni
2013-06-22 13:20 ` Lars-Peter Clausen
2013-06-22 13:20 ` Lars-Peter Clausen
2013-06-22 13:28 ` Alexandre Belloni
2013-06-22 13:28 ` Alexandre Belloni
2013-06-23 13:54 ` Lars-Peter Clausen
2013-06-23 13:54 ` Lars-Peter Clausen
2013-06-23 17:33 ` Jonathan Cameron
2013-06-23 17:33 ` Jonathan Cameron
2013-06-23 17:33 ` Jonathan Cameron
2013-06-24 6:41 ` Lars-Peter Clausen [this message]
2013-06-24 6:41 ` Lars-Peter Clausen
2013-06-24 10:37 ` Alexandre Belloni
2013-06-24 10:37 ` Alexandre Belloni
2013-06-24 16:41 ` Lars-Peter Clausen
2013-06-24 16:41 ` Lars-Peter Clausen
2013-06-24 16:41 ` Lars-Peter Clausen
2013-06-24 17:26 ` Alexandre Belloni
2013-06-24 17:26 ` Alexandre Belloni
2013-06-20 18:57 ` [PATCHv2 2/3] ARM: mxs: cfa10049: Switch bus i2c1 to bitbanging Alexandre Belloni
2013-06-20 18:57 ` Alexandre Belloni
2013-06-21 22:27 ` Fabio Estevam
2013-06-21 22:27 ` Fabio Estevam
2013-06-21 22:27 ` Fabio Estevam
2013-07-02 13:29 ` Christoph G. Baumann
2013-07-02 13:57 ` Fabio Estevam
2013-07-02 14:09 ` Christoph G. Baumann
2013-07-02 16:04 ` Fabio Estevam
2013-06-20 18:57 ` [PATCHv2 3/3] ARM: mxs: cfa10049: Add NAU7802 ADCs to the device tree Alexandre Belloni
2013-06-20 18:57 ` Alexandre Belloni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51C7EA23.1040707@metafoo.de \
--to=lars@metafoo.de \
--cc=alexandre.belloni@free-electrons.com \
--cc=brian@crystalfontz.com \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=grant.likely@secretlab.ca \
--cc=jic23@cam.ac.uk \
--cc=jimwall@q.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.ripard@free-electrons.com \
--cc=rob.herring@calxeda.com \
--cc=rob@landley.net \
--cc=shawn.guo@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.