Re: [PATCH] staging: iio: ad7816: Switch to the gpio descriptor interface

2018-10-17 Thread Nishad Kamdar
On Tue, Oct 16, 2018 at 05:10:14PM +0200, Lars-Peter Clausen wrote:
> On 10/16/2018 04:46 PM, Nishad Kamdar wrote:
> > Use the gpiod interface for rdwr_pin, convert_pin and busy_pin
> > instead of the deprecated old non-descriptor interface.
> > 
> > Signed-off-by: Nishad Kamdar 
> 
> Hi,
> 
> Thanks for the patch, this looks good.
> 
> One thing about the error messages though.
> 
> > +   chip->rdwr_pin = devm_gpiod_get(_dev->dev, "rdwr", GPIOD_IN);
> > +   if (IS_ERR(chip->rdwr_pin)) {
> > +   ret = PTR_ERR(chip->rdwr_pin);
> > dev_err(_dev->dev, "Fail to request rdwr gpio PIN %d.\n",
> > -   chip->rdwr_pin);
> > +   ret);
> 
> This previously showed the pin number which has now been replaced with the
> error code. The message doesn't make that much sense semantically anymore.
> Maybe replace it with something like
> 
>   "Failed to request rdwr GPIO: %d\n", ret
> 
> > return ret;

Hello,

Ok, I'll do that.

Thanks for the review.

regards,
Nishad


Re: [PATCH] staging: iio: ad7816: Switch to the gpio descriptor interface

2018-10-17 Thread Nishad Kamdar
On Tue, Oct 16, 2018 at 05:10:14PM +0200, Lars-Peter Clausen wrote:
> On 10/16/2018 04:46 PM, Nishad Kamdar wrote:
> > Use the gpiod interface for rdwr_pin, convert_pin and busy_pin
> > instead of the deprecated old non-descriptor interface.
> > 
> > Signed-off-by: Nishad Kamdar 
> 
> Hi,
> 
> Thanks for the patch, this looks good.
> 
> One thing about the error messages though.
> 
> > +   chip->rdwr_pin = devm_gpiod_get(_dev->dev, "rdwr", GPIOD_IN);
> > +   if (IS_ERR(chip->rdwr_pin)) {
> > +   ret = PTR_ERR(chip->rdwr_pin);
> > dev_err(_dev->dev, "Fail to request rdwr gpio PIN %d.\n",
> > -   chip->rdwr_pin);
> > +   ret);
> 
> This previously showed the pin number which has now been replaced with the
> error code. The message doesn't make that much sense semantically anymore.
> Maybe replace it with something like
> 
>   "Failed to request rdwr GPIO: %d\n", ret
> 
> > return ret;

Hello,

Ok, I'll do that.

Thanks for the review.

regards,
Nishad


Re: [PATCH] staging: iio: ad7816: Switch to the gpio descriptor interface

2018-10-16 Thread Lars-Peter Clausen
On 10/16/2018 04:46 PM, Nishad Kamdar wrote:
> Use the gpiod interface for rdwr_pin, convert_pin and busy_pin
> instead of the deprecated old non-descriptor interface.
> 
> Signed-off-by: Nishad Kamdar 

Hi,

Thanks for the patch, this looks good.

One thing about the error messages though.

> + chip->rdwr_pin = devm_gpiod_get(_dev->dev, "rdwr", GPIOD_IN);
> + if (IS_ERR(chip->rdwr_pin)) {
> + ret = PTR_ERR(chip->rdwr_pin);
>   dev_err(_dev->dev, "Fail to request rdwr gpio PIN %d.\n",
> - chip->rdwr_pin);
> + ret);

This previously showed the pin number which has now been replaced with the
error code. The message doesn't make that much sense semantically anymore.
Maybe replace it with something like

"Failed to request rdwr GPIO: %d\n", ret

>   return ret;


Re: [PATCH] staging: iio: ad7816: Switch to the gpio descriptor interface

2018-10-16 Thread Lars-Peter Clausen
On 10/16/2018 04:46 PM, Nishad Kamdar wrote:
> Use the gpiod interface for rdwr_pin, convert_pin and busy_pin
> instead of the deprecated old non-descriptor interface.
> 
> Signed-off-by: Nishad Kamdar 

Hi,

Thanks for the patch, this looks good.

One thing about the error messages though.

> + chip->rdwr_pin = devm_gpiod_get(_dev->dev, "rdwr", GPIOD_IN);
> + if (IS_ERR(chip->rdwr_pin)) {
> + ret = PTR_ERR(chip->rdwr_pin);
>   dev_err(_dev->dev, "Fail to request rdwr gpio PIN %d.\n",
> - chip->rdwr_pin);
> + ret);

This previously showed the pin number which has now been replaced with the
error code. The message doesn't make that much sense semantically anymore.
Maybe replace it with something like

"Failed to request rdwr GPIO: %d\n", ret

>   return ret;


[PATCH] staging: iio: ad7816: Switch to the gpio descriptor interface

2018-10-16 Thread Nishad Kamdar
Use the gpiod interface for rdwr_pin, convert_pin and busy_pin
instead of the deprecated old non-descriptor interface.

Signed-off-by: Nishad Kamdar 
---
 drivers/staging/iio/adc/ad7816.c | 72 +---
 1 file changed, 30 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index bf76a8620bdb..190b751af866 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -7,7 +7,7 @@
  */
 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -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;
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);
ret = spi_write(spi_dev, >channel_id, sizeof(chip->channel_id));
if (ret < 0) {
dev_err(_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, , sizeof(*data));
if (ret < 0) {
dev_err(_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, , sizeof(data));
if (ret < 0)
dev_err(_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(_dev->dev);
int ret = 0;
int i;
 
-   if (!pins) {
-   dev_err(_dev->dev, "No necessary GPIO platform data.\n");
-   return -EINVAL;
-   }
-
indio_dev = devm_iio_device_alloc(_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(_dev->dev, chip->rdwr_pin,
-   spi_get_device_id(spi_dev)->name);
-   if (ret) {
+   chip->rdwr_pin = devm_gpiod_get(_dev->dev, "rdwr", GPIOD_IN);
+   if (IS_ERR(chip->rdwr_pin)) {
+   ret = PTR_ERR(chip->rdwr_pin);
dev_err(_dev->dev, "Fail to request rdwr gpio PIN %d.\n",
-   chip->rdwr_pin);
+   ret);
return ret;
}
-   gpio_direction_input(chip->rdwr_pin);
-   ret = devm_gpio_request(_dev->dev, chip->convert_pin,
-   spi_get_device_id(spi_dev)->name);
-   if (ret) {
+   

[PATCH] staging: iio: ad7816: Switch to the gpio descriptor interface

2018-10-16 Thread Nishad Kamdar
Use the gpiod interface for rdwr_pin, convert_pin and busy_pin
instead of the deprecated old non-descriptor interface.

Signed-off-by: Nishad Kamdar 
---
 drivers/staging/iio/adc/ad7816.c | 72 +---
 1 file changed, 30 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index bf76a8620bdb..190b751af866 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -7,7 +7,7 @@
  */
 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -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;
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);
ret = spi_write(spi_dev, >channel_id, sizeof(chip->channel_id));
if (ret < 0) {
dev_err(_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, , sizeof(*data));
if (ret < 0) {
dev_err(_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, , sizeof(data));
if (ret < 0)
dev_err(_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(_dev->dev);
int ret = 0;
int i;
 
-   if (!pins) {
-   dev_err(_dev->dev, "No necessary GPIO platform data.\n");
-   return -EINVAL;
-   }
-
indio_dev = devm_iio_device_alloc(_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(_dev->dev, chip->rdwr_pin,
-   spi_get_device_id(spi_dev)->name);
-   if (ret) {
+   chip->rdwr_pin = devm_gpiod_get(_dev->dev, "rdwr", GPIOD_IN);
+   if (IS_ERR(chip->rdwr_pin)) {
+   ret = PTR_ERR(chip->rdwr_pin);
dev_err(_dev->dev, "Fail to request rdwr gpio PIN %d.\n",
-   chip->rdwr_pin);
+   ret);
return ret;
}
-   gpio_direction_input(chip->rdwr_pin);
-   ret = devm_gpio_request(_dev->dev, chip->convert_pin,
-   spi_get_device_id(spi_dev)->name);
-   if (ret) {
+