From: Lars-Peter Clausen <lars@metafoo.de>
To: Mario Domenech Goulart <mario@ossystems.com.br>
Cc: Otavio Salvador <otavio@ossystems.com.br>,
Jonathan Cameron <jic23@kernel.org>,
linux-iio@vger.kernel.org
Subject: Re: RFC: driver for TI ADS124x ADC series
Date: Sun, 04 Aug 2013 15:54:01 +0200 [thread overview]
Message-ID: <51FE5CF9.3000608@metafoo.de> (raw)
In-Reply-To: <8761vrymzo.fsf@parenteses.org>
On 07/31/2013 01:42 PM, Mario Domenech Goulart wrote:
[...]
>
> +static void wait_for_drdy(int drdy_gpio)
> +{
> + u8 drdy;
> +
> + for (;;) {
> + drdy = gpio_get_value(drdy_gpio);
> + if (!drdy)
> + return;
> + usleep_range(1000, 2000);
> + }
As Jonathan said, using a interrupt here is better. But even of you fallback
to polling you need a timeout, otherwise you can easily be stuck here
forever in case the device mallfunctions.
> +}
[...]
> +
> +static int ads124x_probe(struct spi_device *spi)
> +{
> + struct device_node *np = spi->dev.of_node;
> + struct iio_dev *indio_dev;
> + struct ads124x_state *st;
> + int ret;
> +
> + indio_dev = iio_device_alloc(sizeof(*st));
> + if (indio_dev == NULL)
> + return -ENOMEM;
> +
> + st = iio_priv(indio_dev);
> +
> + /* Initialize GPIO pins */
> + st->drdy_gpio = of_get_named_gpio(np, "drdy-gpio", 0);
> + st->start_gpio = of_get_named_gpio(np, "start-gpio", 0);
> + st->reset_gpio = of_get_named_gpio(np, "reset-gpio", 0);
All custom properties need a vendor prefix.
> +
> + ret = devm_gpio_request_one(&indio_dev->dev, st->drdy_gpio,
> + GPIOF_IN, "adc-drdy");
> + if (ret) {
> + dev_err(&indio_dev->dev, "failed to get adc-drdy-gpios: %d\n",
> + ret);
> + goto error;
> + }
> +
> + ret = devm_gpio_request_one(&indio_dev->dev, st->start_gpio,
> + GPIOF_OUT_INIT_LOW, "adc-start");
> + if (ret) {
> + dev_err(&indio_dev->dev, "failed to get adc-start-gpios: %d\n",
> + ret);
> + goto error;
> + }
> +
> + ret = devm_gpio_request_one(&indio_dev->dev, st->reset_gpio,
> + GPIOF_OUT_INIT_LOW, "adc-reset");
> + if (ret) {
> + dev_err(&indio_dev->dev, "failed to get adc-reset-gpios: %d\n",
> + ret);
> + goto error;
> + }
> +
> + ret = of_property_read_u32(np, "vref-mv", &st->vref_mv);
> + if (ret < 0)
> + goto error;
> +
> + /* Initialize SPI */
> + spi_set_drvdata(spi, indio_dev);
> + st->spi = spi;
> + st->spi->mode = SPI_MODE_1;
> + st->spi->bits_per_word = 8;
> + ret = spi_setup(spi);
> +
> + indio_dev->dev.parent = &spi->dev;
> + indio_dev->name = np->name;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->info = &ads124x_iio_info;
> +
> + /* Setup the ADC channels available on the board */
> + ret = of_property_read_u32(np, "#channels", &indio_dev->num_channels);
> + if (ret < 0)
> + goto error;
> +
> + ret = ads124x_init_chan_array(indio_dev, np);
> + if (ret < 0)
> + goto error;
> +
> + ret = iio_device_register(indio_dev);
> + if (ret)
> + goto error;
> +
> + ads124x_reset(st);
> + ads124x_start(st);
> + ads124x_stop_reading_continuously(st);
> +
> + mutex_init(&st->lock);
> +
> + return 0;
> +
> +error:
> + iio_device_free(indio_dev);
> + dev_err(&spi->dev, "ADS124x: Error while probing.\n");
> +
> + return ret;
> +}
> +
> +static int ads124x_remove(struct spi_device *spi)
> +{
> + struct iio_dev *indio_dev = spi_get_drvdata(spi);
> + struct ads124x_state *st;
Maybe do the initialization of st here instead of a few lines down.
> +
> + iio_device_unregister(indio_dev);
> + iio_device_free(indio_dev);
> +
> + st = iio_priv(indio_dev);
> + mutex_destroy(&st->lock);
> +
> + return 0;
> +}
next prev parent reply other threads:[~2013-08-04 13:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-26 21:10 RFC: driver for TI ADS124x ADC series Mario Domenech Goulart
2013-07-30 22:46 ` Otavio Salvador
2013-07-31 6:54 ` Lars-Peter Clausen
2013-07-31 11:42 ` Mario Domenech Goulart
2013-08-04 13:54 ` Lars-Peter Clausen [this message]
2013-07-31 21:08 ` Jonathan Cameron
2013-08-08 13:53 ` Mario Domenech Goulart
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=51FE5CF9.3000608@metafoo.de \
--to=lars@metafoo.de \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=mario@ossystems.com.br \
--cc=otavio@ossystems.com.br \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).