staging: iio: ad2s1210: Switch to the gpio descriptor interface
Subsystems (4)
PATCH v2 1/1 staging: iio: ad2s1210: Switch to the gpio descriptor interface
Use the gpiod interface instead of the deprecated old non-descriptor interface.
---
Changes in v2:
- Use the spi_device struct embedded in st instead of passing it as an argument to ad2s1210_setup_gpios().
- Use an array of structs to reduce redundant code in in ad2s1210_setup_gpios().
- Remove ad2s1210_free_gpios() as devm API is being used.
--- drivers/staging/iio/resolver/ad2s1210.c | 91 +++++++++++++------------ drivers/staging/iio/resolver/ad2s1210.h | 3 - 2 files changed, 48 insertions(+), 46 deletions(-)
drivers/staging/iio/resolver/ad2s1210.c +48 -43
@@ -15,7 +15,7 @@#include <linux/slab.h> #include <linux/sysfs.h> #include <linux/delay.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/module.h> #include <linux/iio/iio.h>
@@ -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; +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 (&st->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 (&st->lock);
@@ -466,7 +477,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev,s16 vel;mutex_lock (&st->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 (&st->lock);
@@ -630,30 +641,30 @@ 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 =0 , i =0 ; +struct spi_device *spi = st->sdev; +unsigned long flags = st->pdata->gpioin ?GPIOD_IN :GPIOD_OUT_LOW ; + +struct ad2s1210_gpio gpios[] = { + {st->sample,"sample" ,GPIOD_IN }, + {st->a0,"a0" , flags}, + {st->a1,"a1" , flags}, + {st->res0,"res0" , flags}, + {st->res1,"res1" , flags}, }; -return gpio_request_array (ad2s1210_gpios,ARRAY_SIZE (ad2s1210_gpios)); -} - -static void ad2s1210_free_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" }, - }; +for (i =0 ; i <ARRAY_SIZE (gpios); i++) { + gpios[i].ptr =devm_gpiod_get (&spi->dev, gpios[i].name, + gpios[i].flags); +if (IS_ERR (gpios[i].ptr)) { + ret =PTR_ERR (gpios[i].ptr); +dev_err (&spi->dev,"Failed to request %s GPIO: %d\n" , + gpios[i].name, ret); +return ret; + } + } -gpio_free_array (ad2s1210_gpios,ARRAY_SIZE (ad2s1210_gpios)); +return ret; }static int ad2s1210_probe (struct spi_device *spi)
@@ -692,18 +703,13 @@ static int ad2s1210_probe(struct spi_device *spi) ret =iio_device_register (indio_dev);if (ret) - goto error_free_gpios; - +return ret; st->fclkin = spi->max_speed_hz; spi->mode =SPI_MODE_3 ;spi_setup (spi);ad2s1210_initial (st);return 0 ; - -error_free_gpios: -ad2s1210_free_gpios (st); -return ret; }static int ad2s1210_remove (struct spi_device *spi)
@@ -711,7 +717,6 @@ static int ad2s1210_remove(struct spi_device *spi)struct iio_dev *indio_dev =spi_get_drvdata (spi);iio_device_unregister (indio_dev); -ad2s1210_free_gpios (iio_priv (indio_dev));return 0 ; }
drivers/staging/iio/resolver/ad2s1210.h +0 -3
@@ -12,9 +12,6 @@#define _AD2S1210_Hstruct ad2s1210_platform_data { -unsigned int sample; -unsigned int a[2 ]; -unsigned int res[2 ];bool gpioin; };#endif /* _AD2S1210_H */
Signature · 1 line
2.17.1
Quoted 2 lines · Nishad Kamdar
Use the gpiod interface instead of the deprecated old non-descriptor interface.
Hi
Quoted 8 lines
Signed-off-by Nishad Kamdar <[email protected]>---
Changes in v2:
- Use thespi_devicestruct embedded in st instead of passing it as an argument toad2s1210_setup_gpios().
- Use an array of structs to reduce redundant code in inad2s1210_setup_gpios().
- Removead2s1210_free_gpios()as devm API is being used.
Some few more comments on that changes below.
Quoted 19 lines
--- drivers/staging/iio/resolver/ad2s1210.c | 91 +++++++++++++------------ drivers/staging/iio/resolver/ad2s1210.h | 3 - 2 files changed, 48 insertions(+), 46 deletions(-)drivers/staging/iio/resolver/ad2s1210.c +1
-1@@ -15,7 +15,7 @@#include <linux/slab.h> #include <linux/sysfs.h> #include <linux/delay.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/module.h> #include <linux/iio/iio.h>
drivers/staging/iio/resolver/ad2s1210.c enum ad2s1210_mode { · line 73
Quoted 5 lines
drivers/staging/iio/resolver/ad2s1210.c +2
-0@@ -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;
You are going to use this ptr to change a pointer it points to. So it must be a pointer to pointer: **ptr;
drivers/staging/iio/resolver/ad2s1210.c enum ad2s1210_mode { · line 74
Quoted 1 line
drivers/staging/iio/resolver/ad2s1210.c +1
-0+char *name;
I guess it should be const char *.
Quoted 92 lines
drivers/staging/iio/resolver/ad2s1210.c +22
-14+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 (&st->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 (&st->lock);@@ -466,7 +477,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev,s16 vel;mutex_lock (&st->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 (&st->lock);@@ -630,30 +641,30 @@ static const struct iio_info ad2s1210_info = {
drivers/staging/iio/resolver/ad2s1210.c static const struct iio_info ad2s1210_info = { · line 644
Quoted 10 lines
drivers/staging/iio/resolver/ad2s1210.c +1
-7static 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 =0 , i =0 ;
You do not need to init that i with 0.
Also the ret do not have to be 0. If you return just 0 at the on this function.
drivers/staging/iio/resolver/ad2s1210.c static const struct iio_info ad2s1210_info = { · line 653
Quoted 9 lines
drivers/staging/iio/resolver/ad2s1210.c +9
-0+struct spi_device *spi = st->sdev; +unsigned long flags = st->pdata->gpioin ?GPIOD_IN :GPIOD_OUT_LOW ; + +struct ad2s1210_gpio gpios[] = { + {st->sample,"sample" ,GPIOD_IN }, + {st->a0,"a0" , flags}, + {st->a1,"a1" , flags}, + {st->res0,"res0" , flags}, + {st->res1,"res1" , flags},
To change a pointer, you need to pass an address of that pointer. I think you should you . notation when initializing the struct.
Quoted 6 lines
drivers/staging/iio/resolver/ad2s1210.c +0
-4}; -return gpio_request_array (ad2s1210_gpios,ARRAY_SIZE (ad2s1210_gpios)); -} - -static void ad2s1210_free_gpios (struct ad2s1210_state *st)
drivers/staging/iio/resolver/ad2s1210.c static const struct iio_info ad2s1210_info = { · line 656
Quoted 10 lines
drivers/staging/iio/resolver/ad2s1210.c +1
-9-{ -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" }, - }; +for (i =0 ; i <ARRAY_SIZE (gpios); i++) {
I do not know if that is a common practise, but you can set a pointer to gpio[i] as the first instruction in this for, so you would not have to write this whole gpio[i]:
pin = &gpios[i]
and then: pin->ptr, etc.
Quoted 16 lines
drivers/staging/iio/resolver/ad2s1210.c +10
-1+ gpios[i].ptr =devm_gpiod_get (&spi->dev, gpios[i].name, + gpios[i].flags); +if (IS_ERR (gpios[i].ptr)) { + ret =PTR_ERR (gpios[i].ptr); +dev_err (&spi->dev,"Failed to request %s GPIO: %d\n" , + gpios[i].name, ret); +return ret; + } + } -gpio_free_array (ad2s1210_gpios,ARRAY_SIZE (ad2s1210_gpios)); +return ret; }static int ad2s1210_probe (struct spi_device *spi)
drivers/staging/iio/resolver/ad2s1210.c static int ad2s1210_probe(struct spi_device *spi) · line 696
Quoted 5 lines
drivers/staging/iio/resolver/ad2s1210.c +0
-2@@ -692,18 +703,13 @@ static int ad2s1210_probe(struct spi_device *spi) ret =iio_device_register (indio_dev);if (ret) - goto error_free_gpios; -
Removing a empty line here, that is here to make it more readable.
Quoted 36 lines
drivers/staging/iio/resolver/ad2s1210.c +1
-5+return ret; st->fclkin = spi->max_speed_hz; spi->mode =SPI_MODE_3 ;spi_setup (spi);ad2s1210_initial (st);return 0 ; - -error_free_gpios: -ad2s1210_free_gpios (st); -return ret; }static int ad2s1210_remove (struct spi_device *spi)@@ -711,7 +717,6 @@ static int ad2s1210_remove(struct spi_device *spi)struct iio_dev *indio_dev =spi_get_drvdata (spi);iio_device_unregister (indio_dev); -ad2s1210_free_gpios (iio_priv (indio_dev));return 0 ; }drivers/staging/iio/resolver/ad2s1210.h +0
-3@@ -12,9 +12,6 @@#define _AD2S1210_Hstruct ad2s1210_platform_data { -unsigned int sample; -unsigned int a[2 ]; -unsigned int res[2 ];bool gpioin; };#endif /* _AD2S1210_H */
Signature · 1 line
Slawomir Stepien
Quoted 246 lines · Slawomir Stepien
Quoted 2 lines · Nishad Kamdar
Use the gpiod interface instead of the deprecated old non-descriptor interface.
Hi
Quoted 8 lines
Signed-off-by Nishad Kamdar <[email protected]>---
Changes in v2:
- Use thespi_devicestruct embedded in st instead of passing it as an argument toad2s1210_setup_gpios().
- Use an array of structs to reduce redundant code in inad2s1210_setup_gpios().
- Removead2s1210_free_gpios()as devm API is being used.Some few more comments on that changes below.
Quoted 19 lines
--- drivers/staging/iio/resolver/ad2s1210.c | 91 +++++++++++++------------ drivers/staging/iio/resolver/ad2s1210.h | 3 - 2 files changed, 48 insertions(+), 46 deletions(-)drivers/staging/iio/resolver/ad2s1210.c +1
-1@@ -15,7 +15,7 @@#include <linux/slab.h> #include <linux/sysfs.h> #include <linux/delay.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/module.h> #include <linux/iio/iio.h> drivers/staging/iio/resolver/ad2s1210.c enum ad2s1210_mode { · line 73
Quoted 5 lines
drivers/staging/iio/resolver/ad2s1210.c +2
-0@@ -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;You are going to use this ptr to change a pointer it points to. So it must be a pointer to pointer: **ptr;
drivers/staging/iio/resolver/ad2s1210.c enum ad2s1210_mode { · line 74
Quoted 1 line
drivers/staging/iio/resolver/ad2s1210.c +1
-0+char *name;I guess it should be const char *.
Quoted 92 lines
drivers/staging/iio/resolver/ad2s1210.c +22
-14+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 (&st->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 (&st->lock);@@ -466,7 +477,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev,s16 vel;mutex_lock (&st->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 (&st->lock);@@ -630,30 +641,30 @@ static const struct iio_info ad2s1210_info = {drivers/staging/iio/resolver/ad2s1210.c static const struct iio_info ad2s1210_info = { · line 644
Quoted 10 lines
drivers/staging/iio/resolver/ad2s1210.c +1
-7static 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 =0 , i =0 ;You do not need to init that i with 0.
Also the ret do not have to be 0. If you return just 0 at the on this function.drivers/staging/iio/resolver/ad2s1210.c static const struct iio_info ad2s1210_info = { · line 653
Quoted 9 lines
drivers/staging/iio/resolver/ad2s1210.c +9
-0+struct spi_device *spi = st->sdev; +unsigned long flags = st->pdata->gpioin ?GPIOD_IN :GPIOD_OUT_LOW ; + +struct ad2s1210_gpio gpios[] = { + {st->sample,"sample" ,GPIOD_IN }, + {st->a0,"a0" , flags}, + {st->a1,"a1" , flags}, + {st->res0,"res0" , flags}, + {st->res1,"res1" , flags},To change a pointer, you need to pass an address of that pointer. I think you should you . notation when initializing the struct.
Quoted 6 lines
drivers/staging/iio/resolver/ad2s1210.c +0
-4}; -return gpio_request_array (ad2s1210_gpios,ARRAY_SIZE (ad2s1210_gpios)); -} - -static void ad2s1210_free_gpios (struct ad2s1210_state *st)drivers/staging/iio/resolver/ad2s1210.c static const struct iio_info ad2s1210_info = { · line 656
Quoted 10 lines
drivers/staging/iio/resolver/ad2s1210.c +1
-9-{ -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" }, - }; +for (i =0 ; i <ARRAY_SIZE (gpios); i++) {I do not know if that is a common practise, but you can set a pointer to gpio[i] as the first instruction in this for, so you would not have to write this whole gpio[i]:
pin = &gpios[i]
and then:
pin->ptr, etc.Quoted 16 lines
drivers/staging/iio/resolver/ad2s1210.c +10
-1+ gpios[i].ptr =devm_gpiod_get (&spi->dev, gpios[i].name, + gpios[i].flags); +if (IS_ERR (gpios[i].ptr)) { + ret =PTR_ERR (gpios[i].ptr); +dev_err (&spi->dev,"Failed to request %s GPIO: %d\n" , + gpios[i].name, ret); +return ret; + } + } -gpio_free_array (ad2s1210_gpios,ARRAY_SIZE (ad2s1210_gpios)); +return ret; }static int ad2s1210_probe (struct spi_device *spi)drivers/staging/iio/resolver/ad2s1210.c static int ad2s1210_probe(struct spi_device *spi) · line 696
Quoted 5 lines
drivers/staging/iio/resolver/ad2s1210.c +0
-2@@ -692,18 +703,13 @@ static int ad2s1210_probe(struct spi_device *spi) ret =iio_device_register (indio_dev);if (ret) - goto error_free_gpios; -Removing a empty line here, that is here to make it more readable.
Quoted 29 lines
drivers/staging/iio/resolver/ad2s1210.c +1
-5+return ret; st->fclkin = spi->max_speed_hz; spi->mode =SPI_MODE_3 ;spi_setup (spi);ad2s1210_initial (st);return 0 ; - -error_free_gpios: -ad2s1210_free_gpios (st); -return ret; }static int ad2s1210_remove (struct spi_device *spi)@@ -711,7 +717,6 @@ static int ad2s1210_remove(struct spi_device *spi)struct iio_dev *indio_dev =spi_get_drvdata (spi);iio_device_unregister (indio_dev); -ad2s1210_free_gpios (iio_priv (indio_dev));return 0 ; }drivers/staging/iio/resolver/ad2s1210.h +0
-0@@ -12,9 +12,6 @@#define _AD2S1210_H
Quoted 10 lines
Quoted 7 lines
drivers/staging/iio/resolver/ad2s1210.h +0
-3struct ad2s1210_platform_data { -unsigned int sample; -unsigned int a[2 ]; -unsigned int res[2 ];bool gpioin; };#endif /* _AD2S1210_H */ Signature · 1 line
Slawomir Stepien
Hello,
Ok, I'll make the changes.
Thanks for the review.
regards,
Nishad