From: "Ardelean, Alexandru" <alexandru.Ardelean@analog.com>
To: "lars@metafoo.de" <lars@metafoo.de>,
"nishadkamdar@gmail.com" <nishadkamdar@gmail.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"knaack.h@gmx.de" <knaack.h@gmx.de>,
"jic23@kernel.org" <jic23@kernel.org>,
"Hennerich, Michael" <Michael.Hennerich@analog.com>,
"devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"pmeerw@pmeerw.net" <pmeerw@pmeerw.net>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v3 1/4] staging: iio: ad7816: Switch to the gpio descriptor interface
Date: Fri, 9 Nov 2018 08:05:23 +0000 [thread overview]
Message-ID: <5dc38ef5d09e176e720b3f3e31642f7c68ecb4a4.camel@analog.com> (raw)
In-Reply-To: <3f9ea18864230b2758f86899b9bd1acb020dd176.1541733949.git.nishadkamdar@gmail.com>
On Fri, 2018-11-09 at 13:05 +0530, Nishad Kamdar wrote:
> Use the gpiod interface for rdwr_pin, convert_pin and busy_pin
> instead of the deprecated old non-descriptor interface.
>
Patch looks good.
I do have some thoughts about it. See inline.
> Signed-off-by: Nishad Kamdar <nishadkamdar@gmail.com>
> ---
> drivers/staging/iio/adc/ad7816.c | 80 ++++++++++++++------------------
> 1 file changed, 34 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7816.c
> b/drivers/staging/iio/adc/ad7816.c
> index bf76a8620bdb..12c4e0ab4713 100644
> --- a/drivers/staging/iio/adc/ad7816.c
> +++ b/drivers/staging/iio/adc/ad7816.c
> @@ -7,7 +7,7 @@
> */
>
> #include <linux/interrupt.h>
> -#include <linux/gpio.h>
> +#include <linux/gpio/consumer.h>
> #include <linux/device.h>
> #include <linux/kernel.h>
> #include <linux/slab.h>
> @@ -44,9 +44,9 @@
>
> struct ad7816_chip_info {
> struct spi_device *spi_dev;
> - u16 rdwr_pin;
> - u16 convert_pin;
> - u16 busy_pin;
> + struct gpio_desc *rdwr_pin;
> + struct gpio_desc *convert_pin;
> + struct gpio_desc *busy_pin;
Only if you want to do a re-spin, here's an idea.
If you don't want to, feel free to disregard, since your patch is good.
You could compact things a bit; I know this wasn't what the initial code
was doing, but it's an option.
Something like:
enum {
GPIO_RWDR,
GPIO_CONVERT,
GPIO_BUSY,
__GPIO_MAX,
}
Then, what you end up having is:
struct ad7816_chip_info {
struct spi_device *spi_dev;
- u16 rdwr_pin;
- u16 convert_pin;
- u16 busy_pin;
+ struct gpio_desc *gpios[__GPIO_MAX];
// Continued below
> u8 oti_data[AD7816_CS_MAX + 1];
> u8 channel_id; /* 0 always be temperature */
> u8 mode;
> @@ -61,28 +61,28 @@ static int ad7816_spi_read(struct ad7816_chip_info
> *chip, u16 *data)
> int ret = 0;
> __be16 buf;
>
> - gpio_set_value(chip->rdwr_pin, 1);
> - gpio_set_value(chip->rdwr_pin, 0);
> + gpiod_set_value(chip->rdwr_pin, 1);
> + gpiod_set_value(chip->rdwr_pin, 0);
Obviously, in the above context, this becomes:
+ gpiod_set_value(chip->gpios[GPIO_RWDR], 1);
+ gpiod_set_value(chip->gpios[GPIO_RWDR], 0);
> ret = spi_write(spi_dev, &chip->channel_id, sizeof(chip-
> >channel_id));
> if (ret < 0) {
> dev_err(&spi_dev->dev, "SPI channel setting error\n");
> return ret;
> }
> - gpio_set_value(chip->rdwr_pin, 1);
> + gpiod_set_value(chip->rdwr_pin, 1);
>
> if (chip->mode == AD7816_PD) { /* operating mode 2 */
> - gpio_set_value(chip->convert_pin, 1);
> - gpio_set_value(chip->convert_pin, 0);
> + gpiod_set_value(chip->convert_pin, 1);
> + gpiod_set_value(chip->convert_pin, 0);
> } else { /* operating mode 1 */
> - gpio_set_value(chip->convert_pin, 0);
> - gpio_set_value(chip->convert_pin, 1);
> + gpiod_set_value(chip->convert_pin, 0);
> + gpiod_set_value(chip->convert_pin, 1);
> }
>
> - while (gpio_get_value(chip->busy_pin))
> + while (gpiod_get_value(chip->busy_pin))
> cpu_relax();
>
> - gpio_set_value(chip->rdwr_pin, 0);
> - gpio_set_value(chip->rdwr_pin, 1);
> + gpiod_set_value(chip->rdwr_pin, 0);
> + gpiod_set_value(chip->rdwr_pin, 1);
> ret = spi_read(spi_dev, &buf, sizeof(*data));
> if (ret < 0) {
> dev_err(&spi_dev->dev, "SPI data read error\n");
> @@ -99,8 +99,8 @@ static int ad7816_spi_write(struct ad7816_chip_info
> *chip, u8 data)
> struct spi_device *spi_dev = chip->spi_dev;
> int ret = 0;
>
> - gpio_set_value(chip->rdwr_pin, 1);
> - gpio_set_value(chip->rdwr_pin, 0);
> + gpiod_set_value(chip->rdwr_pin, 1);
> + gpiod_set_value(chip->rdwr_pin, 0);
> ret = spi_write(spi_dev, &data, sizeof(data));
> if (ret < 0)
> dev_err(&spi_dev->dev, "SPI oti data write error\n");
> @@ -129,10 +129,10 @@ static ssize_t ad7816_store_mode(struct device
> *dev,
> struct ad7816_chip_info *chip = iio_priv(indio_dev);
>
> if (strcmp(buf, "full")) {
> - gpio_set_value(chip->rdwr_pin, 1);
> + gpiod_set_value(chip->rdwr_pin, 1);
> chip->mode = AD7816_FULL;
> } else {
> - gpio_set_value(chip->rdwr_pin, 0);
> + gpiod_set_value(chip->rdwr_pin, 0);
> chip->mode = AD7816_PD;
> }
>
> @@ -345,15 +345,9 @@ static int ad7816_probe(struct spi_device *spi_dev)
> {
> struct ad7816_chip_info *chip;
> struct iio_dev *indio_dev;
> - unsigned short *pins = dev_get_platdata(&spi_dev->dev);
> int ret = 0;
> int i;
>
> - if (!pins) {
> - dev_err(&spi_dev->dev, "No necessary GPIO platform
> data.\n");
> - return -EINVAL;
> - }
> -
> indio_dev = devm_iio_device_alloc(&spi_dev->dev, sizeof(*chip));
> if (!indio_dev)
> return -ENOMEM;
> @@ -364,34 +358,28 @@ static int ad7816_probe(struct spi_device *spi_dev)
> chip->spi_dev = spi_dev;
> for (i = 0; i <= AD7816_CS_MAX; i++)
> chip->oti_data[i] = 203;
> - chip->rdwr_pin = pins[0];
> - chip->convert_pin = pins[1];
> - chip->busy_pin = pins[2];
> -
> - ret = devm_gpio_request(&spi_dev->dev, chip->rdwr_pin,
> - spi_get_device_id(spi_dev)->name);
> - if (ret) {
> - dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN
> %d.\n",
> - chip->rdwr_pin);
> +
> + chip->rdwr_pin = devm_gpiod_get(&spi_dev->dev, "rdwr", GPIOD_IN);
> + if (IS_ERR(chip->rdwr_pin)) {
> + ret = PTR_ERR(chip->rdwr_pin);
> + dev_err(&spi_dev->dev, "Failed to request rdwr GPIO: %d\n",
> + ret);
> return ret;
> }
But the real benefit if this approach comes here.
You could do:
static const char *gpio_names[__GPIO_MAX] = {
[GPIO_RWDR] = "rwdr",
[GPIO_CONVERT] = "convert",
[GPIO_BUSY] = "busy",
};
// code for patch2
bool have_busy_pin = (chip->id == ID_AD7816 || chip->id == ID_AD7817);
// end code for patch2
for (i = 0; i < __GPIO_MAX; i++) {
// code for patch2
if (i == GPIO_BUSY && !have_busy_pin)
continue;
// end code for patch2
chip->gpios[i] = devm_gpiod_get(&spi_dev->dev, gpio_names[i],
GPIOD_IN);
if (IS_ERR(chip->gpios[i])) {
ret = PTR_ERR(chip->gpios[i]);
dev_err(&spi_dev->dev, "Failed to request rdwr GPIO: %d\n",
ret;
return ret;
}
}
Then, in your patch2 (i.e " staging: iio: ad7816: Do not use busy_pin in
case of AD7818"), what you could do, is to add that code (along with the
other ID code).
And finaly what you could do in patch2, is:
while (chip->gpios[GPIO_BUSY] &&
gpiod_get_value(chip->busy_pin))
cpu_relax();
> - gpio_direction_input(chip->rdwr_pin);
> - ret = devm_gpio_request(&spi_dev->dev, chip->convert_pin,
> - spi_get_device_id(spi_dev)->name);
> - if (ret) {
> - dev_err(&spi_dev->dev, "Fail to request convert gpio PIN
> %d.\n",
> - chip->convert_pin);
> + chip->convert_pin = devm_gpiod_get(&spi_dev->dev, "convert",
> GPIOD_IN);
> + if (IS_ERR(chip->convert_pin)) {
> + ret = PTR_ERR(chip->convert_pin);
> + dev_err(&spi_dev->dev, "Failed to request convert GPIO:
> %d\n",
> + ret);
> return ret;
> }
> - gpio_direction_input(chip->convert_pin);
> - ret = devm_gpio_request(&spi_dev->dev, chip->busy_pin,
> - spi_get_device_id(spi_dev)->name);
> - if (ret) {
> - dev_err(&spi_dev->dev, "Fail to request busy gpio PIN
> %d.\n",
> - chip->busy_pin);
> + chip->busy_pin = devm_gpiod_get(&spi_dev->dev, "busy", GPIOD_IN);
> + if (IS_ERR(chip->busy_pin)) {
> + ret = PTR_ERR(chip->busy_pin);
> + dev_err(&spi_dev->dev, "Failed to request busy GPIO: %d\n",
> + ret);
> return ret;
> }
> - gpio_direction_input(chip->busy_pin);
>
> indio_dev->name = spi_get_device_id(spi_dev)->name;
> indio_dev->dev.parent = &spi_dev->dev;
next prev parent reply other threads:[~2018-11-09 8:05 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-09 7:34 [PATCH v3 0/4] staging: iio: ad7816: Switch to the gpio descriptor interface Nishad Kamdar
2018-11-09 7:35 ` [PATCH v3 1/4] " Nishad Kamdar
2018-11-09 8:05 ` Ardelean, Alexandru [this message]
2018-11-09 8:08 ` Ardelean, Alexandru
2018-11-11 12:24 ` Jonathan Cameron
2018-11-11 12:31 ` Jonathan Cameron
2018-11-14 17:06 ` Nishad Kamdar
2018-11-09 7:36 ` [PATCH v3 2/4] staging: iio: ad7816: Do not use busy_pin in case of AD7818 Nishad Kamdar
2018-11-11 12:35 ` Jonathan Cameron
2018-11-09 7:37 ` [PATCH v3 3/4] staging: iio: ad7816: Set RD/WR pin and CONVST pin as outputs Nishad Kamdar
2018-11-11 12:36 ` Jonathan Cameron
2018-11-09 7:38 ` [PATCH v3 4/4] staging: iio: ad7816: Add device tree table Nishad Kamdar
2018-11-09 8:11 ` Ardelean, Alexandru
2018-11-11 12:38 ` Jonathan Cameron
2018-11-14 16:54 ` Nishad Kamdar
2018-11-14 16:29 ` Nishad Kamdar
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=5dc38ef5d09e176e720b3f3e31642f7c68ecb4a4.camel@analog.com \
--to=alexandru.ardelean@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nishadkamdar@gmail.com \
--cc=pmeerw@pmeerw.net \
/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).