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 <[email protected]>
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 <[email protected]>
---
 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



_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Reply via email to