Re: [PATCH v6 1/3] staging: iio: ad2s1210: Switch to the gpio descriptor interface

2018-10-28 Thread Nishad Kamdar
On Sun, Oct 28, 2018 at 02:36:07PM +, Jonathan Cameron wrote:
> On Sun, 28 Oct 2018 13:21:25 +0530
> Nishad Kamdar  wrote:
> 
> > Use the gpiod interface instead of the deprecated old non-descriptor
> > interface.
> > 
> > Signed-off-by: Nishad Kamdar 
> Hi Nishad,
> 
> Sorry it took me most of the week to get to this.  It's a trade off when you
> want to make fast progress, but I would suggest always leaving a few days
> between patches to see if there are other review comments coming in.
>

Ok, I'll keep that in mind.
> I don't particularly mind myself (as I'm very good at ignoring older versions 
> ;)
> but I do feel some time got wasted here on your part.
> 
> Anyhow, what you have here is correct but the drive to get things as a nice
> array has lead to a weird mixture of being all array based and not being at 
> all.
> Some suggestions in line that will hopefully tidy this up for you.
> 
> I'm basically suggesting adding a layer of indirection where you don't 
> currently
> have one (on the actual reads and writes) so that you get more consistency
> with the setup code rather than adding a lot of fiddly indirection just in
> the setup code.
> 
> Note, what I've given is very much meant to be an illustration.  It's probably
> full of bugs and silly naming etc, so don't take it as being right!
> 
> Jonathan
> 
> > ---
> >  drivers/staging/iio/resolver/ad2s1210.c | 92 ++---
> >  drivers/staging/iio/resolver/ad2s1210.h |  3 -
> >  2 files changed, 50 insertions(+), 45 deletions(-)
> > 
> > diff --git a/drivers/staging/iio/resolver/ad2s1210.c 
> > b/drivers/staging/iio/resolver/ad2s1210.c
> > index ac13b99bd9cb..93c3c70ce62e 100644
> > --- a/drivers/staging/iio/resolver/ad2s1210.c
> > +++ b/drivers/staging/iio/resolver/ad2s1210.c
> > @@ -15,7 +15,7 @@
> >  #include 
> >  #include 
> >  #include 
> > -#include 
> > +#include 
> >  #include 
> >  
> >  #include 
> > @@ -69,10 +69,21 @@ enum ad2s1210_mode {
> >  
> >  static const unsigned int ad2s1210_resolution_value[] = { 10, 12, 14, 16 };
> >  
> > +struct ad2s1210_gpio {
> > +   struct gpio_desc **ptr;
> > +   const char *name;
> > +   unsigned long flags;
> > +};
> > +
> >  struct ad2s1210_state {
> > const struct ad2s1210_platform_data *pdata;
> > struct mutex lock;
> > struct spi_device *sdev;
> 
> With the setup below this becomes
>   struct gpio_desc *gpios[5];
> 
> > +   struct gpio_desc *sample;
> > +   struct gpio_desc *a0;
> > +   struct gpio_desc *a1;
> > +   struct gpio_desc *res0;
> > +   struct gpio_desc *res1;
> > unsigned int fclkin;
> > unsigned int fexcit;
> > bool hysteresis;
> > @@ -91,8 +102,8 @@ static const int ad2s1210_mode_vals[4][2] = {
> >  static inline void ad2s1210_set_mode(enum ad2s1210_mode mode,
> >  struct ad2s1210_state *st)
> >  {
> > -   gpio_set_value(st->pdata->a[0], ad2s1210_mode_vals[mode][0]);
> > -   gpio_set_value(st->pdata->a[1], ad2s1210_mode_vals[mode][1]);
> > +   gpiod_set_value(st->a0, ad2s1210_mode_vals[mode][0]);
> > +   gpiod_set_value(st->a1, ad2s1210_mode_vals[mode][1]);
> > st->mode = mode;
> >  }
> >  
> > @@ -152,8 +163,8 @@ int ad2s1210_update_frequency_control_word(struct 
> > ad2s1210_state *st)
> >  
> >  static unsigned char ad2s1210_read_resolution_pin(struct ad2s1210_state 
> > *st)
> >  {
> > -   int resolution = (gpio_get_value(st->pdata->res[0]) << 1) |
> > - gpio_get_value(st->pdata->res[1]);
> > +   int resolution = (gpiod_get_value(st->res0) << 1) |
> > + gpiod_get_value(st->res1);
> >  
> > return ad2s1210_resolution_value[resolution];
> >  }
> > @@ -164,10 +175,10 @@ static const int ad2s1210_res_pins[4][2] = {
> >  
> >  static inline void ad2s1210_set_resolution_pin(struct ad2s1210_state *st)
> >  {
> > -   gpio_set_value(st->pdata->res[0],
> > -  ad2s1210_res_pins[(st->resolution - 10) / 2][0]);
> > -   gpio_set_value(st->pdata->res[1],
> > -  ad2s1210_res_pins[(st->resolution - 10) / 2][1]);
> > +   gpiod_set_value(st->res0,
> > +   ad2s1210_res_pins[(st->resolution - 10) / 2][0]);
> > +   gpiod_set_value(st->res1,
> > +   ad2s1210_res_pins[(st->resolution - 10) / 2][1]);
> >  }
> >  
> >  static inline int ad2s1210_soft_reset(struct ad2s1210_state *st)
> > @@ -401,15 +412,15 @@ static ssize_t ad2s1210_clear_fault(struct device 
> > *dev,
> > int ret;
> >  
> > mutex_lock(>lock);
> > -   gpio_set_value(st->pdata->sample, 0);
> > +   gpiod_set_value(st->sample, 0);
> > /* delay (2 * tck + 20) nano seconds */
> > udelay(1);
> > -   gpio_set_value(st->pdata->sample, 1);
> > +   gpiod_set_value(st->sample, 1);
> > ret = ad2s1210_config_read(st, AD2S1210_REG_FAULT);
> > if (ret < 0)
> > goto error_ret;
> > -   gpio_set_value(st->pdata->sample, 0);
> > -   gpio_set_value(st->pdata->sample, 1);
> > +   gpiod_set_value(st->sample, 0);
> > +   

Re: [PATCH v6 1/3] staging: iio: ad2s1210: Switch to the gpio descriptor interface

2018-10-28 Thread Jonathan Cameron
On Sun, 28 Oct 2018 13:21:25 +0530
Nishad Kamdar  wrote:

> Use the gpiod interface instead of the deprecated old non-descriptor
> interface.
> 
> Signed-off-by: Nishad Kamdar 
Hi Nishad,

Sorry it took me most of the week to get to this.  It's a trade off when you
want to make fast progress, but I would suggest always leaving a few days
between patches to see if there are other review comments coming in.

I don't particularly mind myself (as I'm very good at ignoring older versions ;)
but I do feel some time got wasted here on your part.

Anyhow, what you have here is correct but the drive to get things as a nice
array has lead to a weird mixture of being all array based and not being at all.
Some suggestions in line that will hopefully tidy this up for you.

I'm basically suggesting adding a layer of indirection where you don't currently
have one (on the actual reads and writes) so that you get more consistency
with the setup code rather than adding a lot of fiddly indirection just in
the setup code.

Note, what I've given is very much meant to be an illustration.  It's probably
full of bugs and silly naming etc, so don't take it as being right!

Jonathan

> ---
>  drivers/staging/iio/resolver/ad2s1210.c | 92 ++---
>  drivers/staging/iio/resolver/ad2s1210.h |  3 -
>  2 files changed, 50 insertions(+), 45 deletions(-)
> 
> diff --git a/drivers/staging/iio/resolver/ad2s1210.c 
> b/drivers/staging/iio/resolver/ad2s1210.c
> index ac13b99bd9cb..93c3c70ce62e 100644
> --- a/drivers/staging/iio/resolver/ad2s1210.c
> +++ b/drivers/staging/iio/resolver/ad2s1210.c
> @@ -15,7 +15,7 @@
>  #include 
>  #include 
>  #include 
> -#include 
> +#include 
>  #include 
>  
>  #include 
> @@ -69,10 +69,21 @@ enum ad2s1210_mode {
>  
>  static const unsigned int ad2s1210_resolution_value[] = { 10, 12, 14, 16 };
>  
> +struct ad2s1210_gpio {
> + struct gpio_desc **ptr;
> + const char *name;
> + unsigned long flags;
> +};
> +
>  struct ad2s1210_state {
>   const struct ad2s1210_platform_data *pdata;
>   struct mutex lock;
>   struct spi_device *sdev;

With the setup below this becomes
struct gpio_desc *gpios[5];

> + struct gpio_desc *sample;
> + struct gpio_desc *a0;
> + struct gpio_desc *a1;
> + struct gpio_desc *res0;
> + struct gpio_desc *res1;
>   unsigned int fclkin;
>   unsigned int fexcit;
>   bool hysteresis;
> @@ -91,8 +102,8 @@ static const int ad2s1210_mode_vals[4][2] = {
>  static inline void ad2s1210_set_mode(enum ad2s1210_mode mode,
>struct ad2s1210_state *st)
>  {
> - gpio_set_value(st->pdata->a[0], ad2s1210_mode_vals[mode][0]);
> - gpio_set_value(st->pdata->a[1], ad2s1210_mode_vals[mode][1]);
> + gpiod_set_value(st->a0, ad2s1210_mode_vals[mode][0]);
> + gpiod_set_value(st->a1, ad2s1210_mode_vals[mode][1]);
>   st->mode = mode;
>  }
>  
> @@ -152,8 +163,8 @@ int ad2s1210_update_frequency_control_word(struct 
> ad2s1210_state *st)
>  
>  static unsigned char ad2s1210_read_resolution_pin(struct ad2s1210_state *st)
>  {
> - int resolution = (gpio_get_value(st->pdata->res[0]) << 1) |
> -   gpio_get_value(st->pdata->res[1]);
> + int resolution = (gpiod_get_value(st->res0) << 1) |
> +   gpiod_get_value(st->res1);
>  
>   return ad2s1210_resolution_value[resolution];
>  }
> @@ -164,10 +175,10 @@ static const int ad2s1210_res_pins[4][2] = {
>  
>  static inline void ad2s1210_set_resolution_pin(struct ad2s1210_state *st)
>  {
> - gpio_set_value(st->pdata->res[0],
> -ad2s1210_res_pins[(st->resolution - 10) / 2][0]);
> - gpio_set_value(st->pdata->res[1],
> -ad2s1210_res_pins[(st->resolution - 10) / 2][1]);
> + gpiod_set_value(st->res0,
> + ad2s1210_res_pins[(st->resolution - 10) / 2][0]);
> + gpiod_set_value(st->res1,
> + ad2s1210_res_pins[(st->resolution - 10) / 2][1]);
>  }
>  
>  static inline int ad2s1210_soft_reset(struct ad2s1210_state *st)
> @@ -401,15 +412,15 @@ static ssize_t ad2s1210_clear_fault(struct device *dev,
>   int ret;
>  
>   mutex_lock(>lock);
> - gpio_set_value(st->pdata->sample, 0);
> + gpiod_set_value(st->sample, 0);
>   /* delay (2 * tck + 20) nano seconds */
>   udelay(1);
> - gpio_set_value(st->pdata->sample, 1);
> + gpiod_set_value(st->sample, 1);
>   ret = ad2s1210_config_read(st, AD2S1210_REG_FAULT);
>   if (ret < 0)
>   goto error_ret;
> - gpio_set_value(st->pdata->sample, 0);
> - gpio_set_value(st->pdata->sample, 1);
> + gpiod_set_value(st->sample, 0);
> + gpiod_set_value(st->sample, 1);
>  error_ret:
>   mutex_unlock(>lock);
>  
> @@ -466,7 +477,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev,
>   s16 vel;
>  
>   mutex_lock(>lock);
> - gpio_set_value(st->pdata->sample, 0);
> + gpiod_set_value(st->sample, 0);

[PATCH v6 1/3] staging: iio: ad2s1210: Switch to the gpio descriptor interface

2018-10-28 Thread Nishad Kamdar
Use the gpiod interface instead of the deprecated old non-descriptor
interface.

Signed-off-by: Nishad Kamdar 
---
 drivers/staging/iio/resolver/ad2s1210.c | 92 ++---
 drivers/staging/iio/resolver/ad2s1210.h |  3 -
 2 files changed, 50 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/iio/resolver/ad2s1210.c 
b/drivers/staging/iio/resolver/ad2s1210.c
index ac13b99bd9cb..93c3c70ce62e 100644
--- a/drivers/staging/iio/resolver/ad2s1210.c
+++ b/drivers/staging/iio/resolver/ad2s1210.c
@@ -15,7 +15,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 #include 
@@ -69,10 +69,21 @@ enum ad2s1210_mode {
 
 static const unsigned int ad2s1210_resolution_value[] = { 10, 12, 14, 16 };
 
+struct ad2s1210_gpio {
+   struct gpio_desc **ptr;
+   const char *name;
+   unsigned long flags;
+};
+
 struct ad2s1210_state {
const struct ad2s1210_platform_data *pdata;
struct mutex lock;
struct spi_device *sdev;
+   struct gpio_desc *sample;
+   struct gpio_desc *a0;
+   struct gpio_desc *a1;
+   struct gpio_desc *res0;
+   struct gpio_desc *res1;
unsigned int fclkin;
unsigned int fexcit;
bool hysteresis;
@@ -91,8 +102,8 @@ static const int ad2s1210_mode_vals[4][2] = {
 static inline void ad2s1210_set_mode(enum ad2s1210_mode mode,
 struct ad2s1210_state *st)
 {
-   gpio_set_value(st->pdata->a[0], ad2s1210_mode_vals[mode][0]);
-   gpio_set_value(st->pdata->a[1], ad2s1210_mode_vals[mode][1]);
+   gpiod_set_value(st->a0, ad2s1210_mode_vals[mode][0]);
+   gpiod_set_value(st->a1, ad2s1210_mode_vals[mode][1]);
st->mode = mode;
 }
 
@@ -152,8 +163,8 @@ int ad2s1210_update_frequency_control_word(struct 
ad2s1210_state *st)
 
 static unsigned char ad2s1210_read_resolution_pin(struct ad2s1210_state *st)
 {
-   int resolution = (gpio_get_value(st->pdata->res[0]) << 1) |
- gpio_get_value(st->pdata->res[1]);
+   int resolution = (gpiod_get_value(st->res0) << 1) |
+ gpiod_get_value(st->res1);
 
return ad2s1210_resolution_value[resolution];
 }
@@ -164,10 +175,10 @@ static const int ad2s1210_res_pins[4][2] = {
 
 static inline void ad2s1210_set_resolution_pin(struct ad2s1210_state *st)
 {
-   gpio_set_value(st->pdata->res[0],
-  ad2s1210_res_pins[(st->resolution - 10) / 2][0]);
-   gpio_set_value(st->pdata->res[1],
-  ad2s1210_res_pins[(st->resolution - 10) / 2][1]);
+   gpiod_set_value(st->res0,
+   ad2s1210_res_pins[(st->resolution - 10) / 2][0]);
+   gpiod_set_value(st->res1,
+   ad2s1210_res_pins[(st->resolution - 10) / 2][1]);
 }
 
 static inline int ad2s1210_soft_reset(struct ad2s1210_state *st)
@@ -401,15 +412,15 @@ static ssize_t ad2s1210_clear_fault(struct device *dev,
int ret;
 
mutex_lock(>lock);
-   gpio_set_value(st->pdata->sample, 0);
+   gpiod_set_value(st->sample, 0);
/* delay (2 * tck + 20) nano seconds */
udelay(1);
-   gpio_set_value(st->pdata->sample, 1);
+   gpiod_set_value(st->sample, 1);
ret = ad2s1210_config_read(st, AD2S1210_REG_FAULT);
if (ret < 0)
goto error_ret;
-   gpio_set_value(st->pdata->sample, 0);
-   gpio_set_value(st->pdata->sample, 1);
+   gpiod_set_value(st->sample, 0);
+   gpiod_set_value(st->sample, 1);
 error_ret:
mutex_unlock(>lock);
 
@@ -466,7 +477,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev,
s16 vel;
 
mutex_lock(>lock);
-   gpio_set_value(st->pdata->sample, 0);
+   gpiod_set_value(st->sample, 0);
/* delay (6 * tck + 20) nano seconds */
udelay(1);
 
@@ -512,7 +523,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev,
}
 
 error_ret:
-   gpio_set_value(st->pdata->sample, 1);
+   gpiod_set_value(st->sample, 1);
/* delay (2 * tck + 20) nano seconds */
udelay(1);
mutex_unlock(>lock);
@@ -630,30 +641,32 @@ static const struct iio_info ad2s1210_info = {
 
 static int ad2s1210_setup_gpios(struct ad2s1210_state *st)
 {
-   unsigned long flags = st->pdata->gpioin ? GPIOF_DIR_IN : GPIOF_DIR_OUT;
-   struct gpio ad2s1210_gpios[] = {
-   { st->pdata->sample, GPIOF_DIR_IN, "sample" },
-   { st->pdata->a[0], flags, "a0" },
-   { st->pdata->a[1], flags, "a1" },
-   { st->pdata->res[0], flags, "res0" },
-   { st->pdata->res[0], flags, "res1" },
+   int ret, i;
+   struct spi_device *spi = st->sdev;
+   struct ad2s1210_gpio *pin;
+   unsigned long flags = st->pdata->gpioin ? GPIOD_IN : GPIOD_OUT_LOW;
+
+   struct ad2s1210_gpio gpios[] = {
+   { .ptr = >sample, .name = "sample", .flags = GPIOD_IN },
+   { .ptr = >a0, .name = "a0", .flags = flags },
+