* [PATCH] iio: humidity: Replace older GPIO APIs with GPIO Consumer APIs for the dht11 sensor
@ 2019-06-11 3:55 Shobhit Kukreti
2019-06-11 11:30 ` Harald Geyer
0 siblings, 1 reply; 3+ messages in thread
From: Shobhit Kukreti @ 2019-06-11 3:55 UTC (permalink / raw)
To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, linux-iio, linux-kernel, harald
Cc: shobhitkukreti
The dht11 driver uses a single gpio to make measurements. It was
using the older global gpio numberspace. The patch replaces the
old gpio api with the new gpio descriptor based api.
Removed header files "linux/gpio.h" and "linux/of_gpio.h"
Signed-off-by: Shobhit Kukreti <shobhitkukreti@gmail.com>
---
drivers/iio/humidity/dht11.c | 28 ++++++++++------------------
1 file changed, 10 insertions(+), 18 deletions(-)
diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
index c815920..f5128d8 100644
--- a/drivers/iio/humidity/dht11.c
+++ b/drivers/iio/humidity/dht11.c
@@ -22,8 +22,7 @@
#include <linux/completion.h>
#include <linux/mutex.h>
#include <linux/delay.h>
-#include <linux/gpio.h>
-#include <linux/of_gpio.h>
+#include <linux/gpio/consumer.h>
#include <linux/timekeeping.h>
#include <linux/iio/iio.h>
@@ -72,7 +71,7 @@
struct dht11 {
struct device *dev;
- int gpio;
+ struct gpio_desc *gpiod;
int irq;
struct completion completion;
@@ -179,7 +178,7 @@ static irqreturn_t dht11_handle_irq(int irq, void *data)
if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) {
dht11->edges[dht11->num_edges].ts = ktime_get_boot_ns();
dht11->edges[dht11->num_edges++].value =
- gpio_get_value(dht11->gpio);
+ gpiod_get_value(dht11->gpiod);
if (dht11->num_edges >= DHT11_EDGES_PER_READ)
complete(&dht11->completion);
@@ -217,12 +216,12 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
reinit_completion(&dht11->completion);
dht11->num_edges = 0;
- ret = gpio_direction_output(dht11->gpio, 0);
+ ret = gpiod_direction_output(dht11->gpiod, 0);
if (ret)
goto err;
usleep_range(DHT11_START_TRANSMISSION_MIN,
DHT11_START_TRANSMISSION_MAX);
- ret = gpio_direction_input(dht11->gpio);
+ ret = gpiod_direction_input(dht11->gpiod);
if (ret)
goto err;
@@ -294,10 +293,8 @@ MODULE_DEVICE_TABLE(of, dht11_dt_ids);
static int dht11_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *node = dev->of_node;
struct dht11 *dht11;
struct iio_dev *iio;
- int ret;
iio = devm_iio_device_alloc(dev, sizeof(*dht11));
if (!iio) {
@@ -307,18 +304,13 @@ static int dht11_probe(struct platform_device *pdev)
dht11 = iio_priv(iio);
dht11->dev = dev;
+ dht11->gpiod = devm_gpiod_get(dev, NULL, GPIOD_IN);
+ if (IS_ERR(dht11->gpiod))
+ return PTR_ERR(dht11->gpiod);
- ret = of_get_gpio(node, 0);
- if (ret < 0)
- return ret;
- dht11->gpio = ret;
- ret = devm_gpio_request_one(dev, dht11->gpio, GPIOF_IN, pdev->name);
- if (ret)
- return ret;
-
- dht11->irq = gpio_to_irq(dht11->gpio);
+ dht11->irq = gpiod_to_irq(dht11->gpiod);
if (dht11->irq < 0) {
- dev_err(dev, "GPIO %d has no interrupt\n", dht11->gpio);
+ dev_err(dev, "GPIO %d has no interrupt\n", desc_to_gpio(dht11->gpiod));
return -EINVAL;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: humidity: Replace older GPIO APIs with GPIO Consumer APIs for the dht11 sensor
2019-06-11 3:55 [PATCH] iio: humidity: Replace older GPIO APIs with GPIO Consumer APIs for the dht11 sensor Shobhit Kukreti
@ 2019-06-11 11:30 ` Harald Geyer
2019-06-16 15:18 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Harald Geyer @ 2019-06-11 11:30 UTC (permalink / raw)
To: Shobhit Kukreti
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, linux-iio, linux-kernel
Shobhit Kukreti writes:
> The dht11 driver uses a single gpio to make measurements. It was
> using the older global gpio numberspace. The patch replaces the
> old gpio api with the new gpio descriptor based api.
>
> Removed header files "linux/gpio.h" and "linux/of_gpio.h"
>
> Signed-off-by: Shobhit Kukreti <shobhitkukreti@gmail.com>
Acked-by: Harald Geyer <harald@ccbib.org>
> ---
> drivers/iio/humidity/dht11.c | 28 ++++++++++------------------
> 1 file changed, 10 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
> index c815920..f5128d8 100644
> --- a/drivers/iio/humidity/dht11.c
> +++ b/drivers/iio/humidity/dht11.c
> @@ -22,8 +22,7 @@
> #include <linux/completion.h>
> #include <linux/mutex.h>
> #include <linux/delay.h>
> -#include <linux/gpio.h>
> -#include <linux/of_gpio.h>
> +#include <linux/gpio/consumer.h>
> #include <linux/timekeeping.h>
>
> #include <linux/iio/iio.h>
> @@ -72,7 +71,7 @@
> struct dht11 {
> struct device *dev;
>
> - int gpio;
> + struct gpio_desc *gpiod;
> int irq;
>
> struct completion completion;
> @@ -179,7 +178,7 @@ static irqreturn_t dht11_handle_irq(int irq, void *data)
> if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) {
> dht11->edges[dht11->num_edges].ts = ktime_get_boot_ns();
> dht11->edges[dht11->num_edges++].value =
> - gpio_get_value(dht11->gpio);
> + gpiod_get_value(dht11->gpiod);
>
> if (dht11->num_edges >= DHT11_EDGES_PER_READ)
> complete(&dht11->completion);
> @@ -217,12 +216,12 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
> reinit_completion(&dht11->completion);
>
> dht11->num_edges = 0;
> - ret = gpio_direction_output(dht11->gpio, 0);
> + ret = gpiod_direction_output(dht11->gpiod, 0);
> if (ret)
> goto err;
> usleep_range(DHT11_START_TRANSMISSION_MIN,
> DHT11_START_TRANSMISSION_MAX);
> - ret = gpio_direction_input(dht11->gpio);
> + ret = gpiod_direction_input(dht11->gpiod);
> if (ret)
> goto err;
>
> @@ -294,10 +293,8 @@ MODULE_DEVICE_TABLE(of, dht11_dt_ids);
> static int dht11_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> - struct device_node *node = dev->of_node;
> struct dht11 *dht11;
> struct iio_dev *iio;
> - int ret;
>
> iio = devm_iio_device_alloc(dev, sizeof(*dht11));
> if (!iio) {
> @@ -307,18 +304,13 @@ static int dht11_probe(struct platform_device *pdev)
>
> dht11 = iio_priv(iio);
> dht11->dev = dev;
> + dht11->gpiod = devm_gpiod_get(dev, NULL, GPIOD_IN);
> + if (IS_ERR(dht11->gpiod))
> + return PTR_ERR(dht11->gpiod);
>
> - ret = of_get_gpio(node, 0);
> - if (ret < 0)
> - return ret;
> - dht11->gpio = ret;
> - ret = devm_gpio_request_one(dev, dht11->gpio, GPIOF_IN, pdev->name);
> - if (ret)
> - return ret;
> -
> - dht11->irq = gpio_to_irq(dht11->gpio);
> + dht11->irq = gpiod_to_irq(dht11->gpiod);
> if (dht11->irq < 0) {
> - dev_err(dev, "GPIO %d has no interrupt\n", dht11->gpio);
> + dev_err(dev, "GPIO %d has no interrupt\n", desc_to_gpio(dht11->gpiod));
> return -EINVAL;
> }
>
> --
> 2.7.4
>
--
If you want to support my work:
see http://friends.ccbib.org/harald/supporting/
or donate via CLAM to xASPBtezLNqj4cUe8MT5nZjthRSEjrRQXN
or via peercoin to P98LRdhit3gZbHDBe7ta5jtXrMJUms4p7w
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: humidity: Replace older GPIO APIs with GPIO Consumer APIs for the dht11 sensor
2019-06-11 11:30 ` Harald Geyer
@ 2019-06-16 15:18 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2019-06-16 15:18 UTC (permalink / raw)
To: Harald Geyer
Cc: Shobhit Kukreti, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, linux-iio, linux-kernel
On Tue, 11 Jun 2019 13:30:42 +0200
Harald Geyer <harald@ccbib.org> wrote:
> Shobhit Kukreti writes:
> > The dht11 driver uses a single gpio to make measurements. It was
> > using the older global gpio numberspace. The patch replaces the
> > old gpio api with the new gpio descriptor based api.
> >
> > Removed header files "linux/gpio.h" and "linux/of_gpio.h"
> >
> > Signed-off-by: Shobhit Kukreti <shobhitkukreti@gmail.com>
>
> Acked-by: Harald Geyer <harald@ccbib.org>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.
thanks,
Jonathan
>
> > ---
> > drivers/iio/humidity/dht11.c | 28 ++++++++++------------------
> > 1 file changed, 10 insertions(+), 18 deletions(-)
> >
> > diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
> > index c815920..f5128d8 100644
> > --- a/drivers/iio/humidity/dht11.c
> > +++ b/drivers/iio/humidity/dht11.c
> > @@ -22,8 +22,7 @@
> > #include <linux/completion.h>
> > #include <linux/mutex.h>
> > #include <linux/delay.h>
> > -#include <linux/gpio.h>
> > -#include <linux/of_gpio.h>
> > +#include <linux/gpio/consumer.h>
> > #include <linux/timekeeping.h>
> >
> > #include <linux/iio/iio.h>
> > @@ -72,7 +71,7 @@
> > struct dht11 {
> > struct device *dev;
> >
> > - int gpio;
> > + struct gpio_desc *gpiod;
> > int irq;
> >
> > struct completion completion;
> > @@ -179,7 +178,7 @@ static irqreturn_t dht11_handle_irq(int irq, void *data)
> > if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) {
> > dht11->edges[dht11->num_edges].ts = ktime_get_boot_ns();
> > dht11->edges[dht11->num_edges++].value =
> > - gpio_get_value(dht11->gpio);
> > + gpiod_get_value(dht11->gpiod);
> >
> > if (dht11->num_edges >= DHT11_EDGES_PER_READ)
> > complete(&dht11->completion);
> > @@ -217,12 +216,12 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
> > reinit_completion(&dht11->completion);
> >
> > dht11->num_edges = 0;
> > - ret = gpio_direction_output(dht11->gpio, 0);
> > + ret = gpiod_direction_output(dht11->gpiod, 0);
> > if (ret)
> > goto err;
> > usleep_range(DHT11_START_TRANSMISSION_MIN,
> > DHT11_START_TRANSMISSION_MAX);
> > - ret = gpio_direction_input(dht11->gpio);
> > + ret = gpiod_direction_input(dht11->gpiod);
> > if (ret)
> > goto err;
> >
> > @@ -294,10 +293,8 @@ MODULE_DEVICE_TABLE(of, dht11_dt_ids);
> > static int dht11_probe(struct platform_device *pdev)
> > {
> > struct device *dev = &pdev->dev;
> > - struct device_node *node = dev->of_node;
> > struct dht11 *dht11;
> > struct iio_dev *iio;
> > - int ret;
> >
> > iio = devm_iio_device_alloc(dev, sizeof(*dht11));
> > if (!iio) {
> > @@ -307,18 +304,13 @@ static int dht11_probe(struct platform_device *pdev)
> >
> > dht11 = iio_priv(iio);
> > dht11->dev = dev;
> > + dht11->gpiod = devm_gpiod_get(dev, NULL, GPIOD_IN);
> > + if (IS_ERR(dht11->gpiod))
> > + return PTR_ERR(dht11->gpiod);
> >
> > - ret = of_get_gpio(node, 0);
> > - if (ret < 0)
> > - return ret;
> > - dht11->gpio = ret;
> > - ret = devm_gpio_request_one(dev, dht11->gpio, GPIOF_IN, pdev->name);
> > - if (ret)
> > - return ret;
> > -
> > - dht11->irq = gpio_to_irq(dht11->gpio);
> > + dht11->irq = gpiod_to_irq(dht11->gpiod);
> > if (dht11->irq < 0) {
> > - dev_err(dev, "GPIO %d has no interrupt\n", dht11->gpio);
> > + dev_err(dev, "GPIO %d has no interrupt\n", desc_to_gpio(dht11->gpiod));
> > return -EINVAL;
> > }
> >
> > --
> > 2.7.4
> >
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-16 15:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-11 3:55 [PATCH] iio: humidity: Replace older GPIO APIs with GPIO Consumer APIs for the dht11 sensor Shobhit Kukreti
2019-06-11 11:30 ` Harald Geyer
2019-06-16 15:18 ` Jonathan Cameron
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).