kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* GPIO consumer interface and DT
@ 2018-08-15 22:11 Arkadiusz Lis
  2018-08-16  6:39 ` Linus Walleij
  0 siblings, 1 reply; 4+ messages in thread
From: Arkadiusz Lis @ 2018-08-15 22:11 UTC (permalink / raw)
  To: kernelnewbies

Hi guys,
I'd like emxx_udc driver to start using gpio consumer interface. I
prepared draft of a patch and I have a question regarding obtaining gpio
descriptor.
So I use this:
devm_gpiod_get(struct device *dev, const char *con_id,
enum gpiod_flags flags), the second argument is con_id. What I learned
from Documentation/driver-api/gpio/board.rst is this string should be
equal to <function> prefix in <function>-gpios node in device tree.
For example: in file drivers/i2c/busses/i2c-gpio.c author gets gpio
descriptor with con_ids 'sda' and 'scl'. They are described in
Documentation/devicetree/bindings/i2c/i2c-gpio.txt as required
properties. 
In my case I didn't find bindings for emxx_udc driver and I don't know
what string should I insert:
gpiod = devm_gpiod_get(udc->dev, "DT_GPIOS_NAME", GPIOD_IN); //
"DT_GPIOS_NAME" is a placeholder

Do you know who defines bindings or how can I solve this issue? Maybe
I'm searching in the wrong direction and this is not how it should be
done? Comments and hints are very welcome

Thanks,
Arek
---

>From 2afe158b9793f614518b1897d6f67d74f92bc95e Mon Sep 17 00:00:00 2001
From: Arkadiusz Lis <areklis909@gmail.com>
Date: Wed, 15 Aug 2018 23:34:12 +0200
Subject: [PATCH] Staging: emxx_udc: start using gpio consumer interface

Remove usages of old linux/gpio.h interface, instead prefer
new linux/gpio/consumer.h
Obtain gpio descriptor in probe(), port getting gpio value
to more recent interface.

Signed-off-by: Arkadiusz Lis <areklis909@gmail.com>
---
 drivers/staging/emxx_udc/emxx_udc.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/emxx_udc/emxx_udc.c b/drivers/staging/emxx_udc/emxx_udc.c
index 3e51476..fe8546a 100644
--- a/drivers/staging/emxx_udc/emxx_udc.c
+++ b/drivers/staging/emxx_udc/emxx_udc.c
@@ -27,7 +27,7 @@
 #include <linux/usb/gadget.h>
 
 #include <linux/irq.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 
 #include "emxx_udc.h"
 
@@ -57,7 +57,7 @@
 /*===========================================================================*/
 /* Global */
 struct nbu2ss_udc udc_controller;
-
+static struct gpio_desc *gpiod;
 /*-------------------------------------------------------------------------*/
 /* Read */
 static inline u32 _nbu2ss_readl(void *address)
@@ -2303,7 +2303,7 @@ static inline void _nbu2ss_check_vbus(struct nbu2ss_udc *udc)
 	mdelay(VBUS_CHATTERING_MDELAY);		/* wait (ms) */
 
 	/* VBUS ON Check*/
-	reg_dt = gpio_get_value(VBUS_VALUE);
+	reg_dt = gpiod_get_value(gpiod);
 	if (reg_dt == 0) {
 		udc->linux_suspended = 0;
 
@@ -2330,7 +2330,7 @@ static inline void _nbu2ss_check_vbus(struct nbu2ss_udc *udc)
 		}
 	} else {
 		mdelay(5);		/* wait (5ms) */
-		reg_dt = gpio_get_value(VBUS_VALUE);
+		reg_dt = gpiod_get_value(gpiod);
 		if (reg_dt == 0)
 			return;
 
@@ -2394,7 +2394,7 @@ static inline void _nbu2ss_int_usb_suspend(struct nbu2ss_udc *udc)
 	u32	reg_dt;
 
 	if (udc->usb_suspended == 0) {
-		reg_dt = gpio_get_value(VBUS_VALUE);
+		reg_dt = gpiod_get_value(gpiod);
 
 		if (reg_dt == 0)
 			return;
@@ -2434,7 +2434,7 @@ static irqreturn_t _nbu2ss_udc_irq(int irq, void *_udc)
 	struct nbu2ss_udc	*udc = (struct nbu2ss_udc *)_udc;
 	struct fc_regs	*preg = udc->p_regs;
 
-	if (gpio_get_value(VBUS_VALUE) == 0) {
+	if (gpiod_get_value(gpiod) == 0) {
 		_nbu2ss_writel(&preg->USB_INT_STA, ~USB_INT_STA_RW);
 		_nbu2ss_writel(&preg->USB_INT_ENA, 0);
 		return IRQ_HANDLED;
@@ -2443,7 +2443,7 @@ static irqreturn_t _nbu2ss_udc_irq(int irq, void *_udc)
 	spin_lock(&udc->lock);
 
 	for (;;) {
-		if (gpio_get_value(VBUS_VALUE) == 0) {
+		if (gpiod_get_value(gpiod) == 0) {
 			_nbu2ss_writel(&preg->USB_INT_STA, ~USB_INT_STA_RW);
 			_nbu2ss_writel(&preg->USB_INT_ENA, 0);
 			status = 0;
@@ -2852,7 +2852,7 @@ static int nbu2ss_ep_fifo_status(struct usb_ep *_ep)
 
 	preg = udc->p_regs;
 
-	data = gpio_get_value(VBUS_VALUE);
+	data = gpiod_get_value(gpiod);
 	if (data == 0)
 		return -EINVAL;
 
@@ -2896,7 +2896,7 @@ static void  nbu2ss_ep_fifo_flush(struct usb_ep *_ep)
 		return;
 	}
 
-	data = gpio_get_value(VBUS_VALUE);
+	data = gpiod_get_value(gpiod);
 	if (data == 0)
 		return;
 
@@ -2938,7 +2938,7 @@ static int nbu2ss_gad_get_frame(struct usb_gadget *pgadget)
 	}
 
 	udc = container_of(pgadget, struct nbu2ss_udc, gadget);
-	data = gpio_get_value(VBUS_VALUE);
+	data = gpiod_get_value(gpiod);
 	if (data == 0)
 		return -EINVAL;
 
@@ -2964,7 +2964,7 @@ static int nbu2ss_gad_wakeup(struct usb_gadget *pgadget)
 		return -EINVAL;
 	}
 
-	data = gpio_get_value(VBUS_VALUE);
+	data = gpiod_get_value(gpiod);
 	if (data == 0) {
 		dev_warn(&pgadget->dev, "VBUS LEVEL = %d\n", data);
 		return -EINVAL;
@@ -3224,6 +3224,11 @@ static int nbu2ss_drv_probe(struct platform_device *pdev)
 		return status;
 	}
 
+        gpiod = devm_gpiod_get(udc->dev, "DT_GPIOS_NAME", GPIOD_IN);
+        if(IS_ERR(gpiod)) {
+		dev_err(udc->dev, "failed to get gpio\n");
+		return PTR_ERR(gpiod);
+	}
 	/* Driver Initialization */
 	status = nbu2ss_drv_contest_init(pdev, udc);
 	if (status < 0) {
@@ -3314,7 +3319,7 @@ static int nbu2ss_drv_resume(struct platform_device *pdev)
 	if (!udc)
 		return 0;
 
-	data = gpio_get_value(VBUS_VALUE);
+	data = gpiod_get_value(gpiod);
 	if (data) {
 		udc->vbus_active = 1;
 		udc->devstate = USB_STATE_POWERED;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* GPIO consumer interface and DT
  2018-08-15 22:11 GPIO consumer interface and DT Arkadiusz Lis
@ 2018-08-16  6:39 ` Linus Walleij
  2018-08-16 19:07   ` Arkadiusz Lis
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2018-08-16  6:39 UTC (permalink / raw)
  To: kernelnewbies

On Thu, Aug 16, 2018 at 12:11 AM Arkadiusz Lis <areklis909@gmail.com> wrote:

> What I learned
> from Documentation/driver-api/gpio/board.rst is this string should be
> equal to <function> prefix in <function>-gpios node in device tree.
> For example: in file drivers/i2c/busses/i2c-gpio.c author gets gpio
> descriptor with con_ids 'sda' and 'scl'. They are described in
> Documentation/devicetree/bindings/i2c/i2c-gpio.txt as required
> properties.

You got it right.

> In my case I didn't find bindings for emxx_udc driver and I don't know
> what string should I insert:
> gpiod = devm_gpiod_get(udc->dev, "DT_GPIOS_NAME", GPIOD_IN); //
> "DT_GPIOS_NAME" is a placeholder

This driver is not yet converted to use device tree so there is
no way you can know this property name before bindings are
established.

You or someone else first need to define device tree bindings
in Documention/devicetree/bindings/usb/* somwhere, then augment
the driver to use these bindings, including the right name for
the GPIO line, when using the devm_gpiod_get().

Pretty certainly the chosen GPIO name will be "vbus-gpios" in this
case so you will pass "vbus" as name. But that needs to first
be discussed by the DT bindings mailing list.

I wonder how you're testing this though.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* GPIO consumer interface and DT
  2018-08-16  6:39 ` Linus Walleij
@ 2018-08-16 19:07   ` Arkadiusz Lis
  2018-08-20  7:30     ` Linus Walleij
  0 siblings, 1 reply; 4+ messages in thread
From: Arkadiusz Lis @ 2018-08-16 19:07 UTC (permalink / raw)
  To: kernelnewbies

> You or someone else first need to define device tree bindings
> in Documention/devicetree/bindings/usb/* somwhere, then augment
> the driver to use these bindings, including the right name for
> the GPIO line, when using the devm_gpiod_get().

OK, I will try to start a discussion about this.

> I wonder how you're testing this though.

I don't have this equipment to be honest. 
Once work is done I count on kindness of interested people who actually
have it and are able to test the patch on the target.
Is there any other way?

Thanks,
Arek

^ permalink raw reply	[flat|nested] 4+ messages in thread

* GPIO consumer interface and DT
  2018-08-16 19:07   ` Arkadiusz Lis
@ 2018-08-20  7:30     ` Linus Walleij
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2018-08-20  7:30 UTC (permalink / raw)
  To: kernelnewbies

On Thu, Aug 16, 2018 at 9:08 PM Arkadiusz Lis <areklis909@gmail.com> wrote:
> [Me]
> > I wonder how you're testing this though.
>
> I don't have this equipment to be honest.
> Once work is done I count on kindness of interested people who actually
> have it and are able to test the patch on the target.
> Is there any other way?

The other way is to have the equipment.

But your efforts are appreciated either way, just needs proper testing
and that can be hard to get right remotely. (A lot of mailing back
and forth.)

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-20  7:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-15 22:11 GPIO consumer interface and DT Arkadiusz Lis
2018-08-16  6:39 ` Linus Walleij
2018-08-16 19:07   ` Arkadiusz Lis
2018-08-20  7:30     ` Linus Walleij

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).