Commit 06c77f56 authored by Nishad Kamdar's avatar Nishad Kamdar Committed by Jonathan Cameron

staging: iio: ad7816: Do not use busy_pin in case of AD7818

AD7818 does not support busy_pin functionality as per datasheet.
Hence drop busy_pin when AD7818 is used.
Signed-off-by: default avatarNishad Kamdar <nishadkamdar@gmail.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 723a61e0
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
*/ */
struct ad7816_chip_info { struct ad7816_chip_info {
kernel_ulong_t id;
struct spi_device *spi_dev; struct spi_device *spi_dev;
struct gpio_desc *rdwr_pin; struct gpio_desc *rdwr_pin;
struct gpio_desc *convert_pin; struct gpio_desc *convert_pin;
...@@ -52,6 +53,12 @@ struct ad7816_chip_info { ...@@ -52,6 +53,12 @@ struct ad7816_chip_info {
u8 mode; u8 mode;
}; };
enum ad7816_type {
ID_AD7816,
ID_AD7817,
ID_AD7818,
};
/* /*
* ad7816 data access by SPI * ad7816 data access by SPI
*/ */
...@@ -78,8 +85,10 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data) ...@@ -78,8 +85,10 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data)
gpiod_set_value(chip->convert_pin, 1); gpiod_set_value(chip->convert_pin, 1);
} }
if (chip->id == ID_AD7816 || chip->id == ID_AD7817) {
while (gpiod_get_value(chip->busy_pin)) while (gpiod_get_value(chip->busy_pin))
cpu_relax(); cpu_relax();
}
gpiod_set_value(chip->rdwr_pin, 0); gpiod_set_value(chip->rdwr_pin, 0);
gpiod_set_value(chip->rdwr_pin, 1); gpiod_set_value(chip->rdwr_pin, 1);
...@@ -359,6 +368,7 @@ static int ad7816_probe(struct spi_device *spi_dev) ...@@ -359,6 +368,7 @@ static int ad7816_probe(struct spi_device *spi_dev)
for (i = 0; i <= AD7816_CS_MAX; i++) for (i = 0; i <= AD7816_CS_MAX; i++)
chip->oti_data[i] = 203; chip->oti_data[i] = 203;
chip->id = spi_get_device_id(spi_dev)->driver_data;
chip->rdwr_pin = devm_gpiod_get(&spi_dev->dev, "rdwr", GPIOD_IN); chip->rdwr_pin = devm_gpiod_get(&spi_dev->dev, "rdwr", GPIOD_IN);
if (IS_ERR(chip->rdwr_pin)) { if (IS_ERR(chip->rdwr_pin)) {
ret = PTR_ERR(chip->rdwr_pin); ret = PTR_ERR(chip->rdwr_pin);
...@@ -373,13 +383,16 @@ static int ad7816_probe(struct spi_device *spi_dev) ...@@ -373,13 +383,16 @@ static int ad7816_probe(struct spi_device *spi_dev)
ret); ret);
return ret; return ret;
} }
chip->busy_pin = devm_gpiod_get(&spi_dev->dev, "busy", GPIOD_IN); if (chip->id == ID_AD7816 || chip->id == ID_AD7817) {
chip->busy_pin = devm_gpiod_get(&spi_dev->dev, "busy",
GPIOD_IN);
if (IS_ERR(chip->busy_pin)) { if (IS_ERR(chip->busy_pin)) {
ret = PTR_ERR(chip->busy_pin); ret = PTR_ERR(chip->busy_pin);
dev_err(&spi_dev->dev, "Failed to request busy GPIO: %d\n", dev_err(&spi_dev->dev, "Failed to request busy GPIO: %d\n",
ret); ret);
return ret; return ret;
} }
}
indio_dev->name = spi_get_device_id(spi_dev)->name; indio_dev->name = spi_get_device_id(spi_dev)->name;
indio_dev->dev.parent = &spi_dev->dev; indio_dev->dev.parent = &spi_dev->dev;
...@@ -409,9 +422,9 @@ static int ad7816_probe(struct spi_device *spi_dev) ...@@ -409,9 +422,9 @@ static int ad7816_probe(struct spi_device *spi_dev)
} }
static const struct spi_device_id ad7816_id[] = { static const struct spi_device_id ad7816_id[] = {
{ "ad7816", 0 }, { "ad7816", ID_AD7816 },
{ "ad7817", 0 }, { "ad7817", ID_AD7817 },
{ "ad7818", 0 }, { "ad7818", ID_AD7818 },
{} {}
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment