devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Serge Semin <fancer.lancer@gmail.com>
To: richard.leitner@skidata.com, gregkh@linuxfoundation.org,
	robh+dt@kernel.org, mark.rutland@arm.com
Cc: Sergey.Semin@t-platforms.ru, linux-usb@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Serge Semin <fancer.lancer@gmail.com>
Subject: [PATCH 4/5] usb: usb251xb: Use GPIO descriptor consumer interface
Date: Sat, 16 Sep 2017 02:31:12 +0300	[thread overview]
Message-ID: <20170915233113.17855-5-fancer.lancer@gmail.com> (raw)
In-Reply-To: <20170915233113.17855-1-fancer.lancer@gmail.com>

The driver used to be developed with legacy GPIO API support. It's
better to use descriptor-based interface for several reasons. First
of all the legacy API doesn't support the ACTIVE_LOW/HIGH flag of dts
nodes, which is essential since different hardware may have different
GPIOs connectivity including the logical value inversion. Secondly,
by requesting the reset GPIO descriptor the driver prevent the other
applications from changing its value. And last but not least the
legacy GPIO interface should be avoided in the new code due to it
obsolescence.

Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
---
 Documentation/devicetree/bindings/usb/usb251xb.txt |  2 +-
 drivers/usb/misc/usb251xb.c                        | 33 +++++++++-------------
 2 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/usb251xb.txt b/Documentation/devicetree/bindings/usb/usb251xb.txt
index dd59a32e7..7c981d556 100644
--- a/Documentation/devicetree/bindings/usb/usb251xb.txt
+++ b/Documentation/devicetree/bindings/usb/usb251xb.txt
@@ -8,10 +8,10 @@ Required properties :
 	"microchip,usb2512b", "microchip,usb2512bi", "microchip,usb2513b",
 	"microchip,usb2513bi", "microchip,usb2514b", "microchip,usb2514bi",
 	"microchip,usb2517", "microchip,usb2517i"
- - reset-gpios : Should specify the gpio for hub reset
  - reg : I2C address on the selected bus (default is <0x2C>)
 
 Optional properties :
+ - reset-gpios : Should specify the gpio for hub reset
  - skip-config : Skip Hub configuration, but only send the USB-Attach command
  - vendor-id : Set USB Vendor ID of the hub (16 bit, default is 0x0424)
  - product-id : Set USB Product ID of the hub (16 bit, default depends on type)
diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
index d6a0ff4ec..1d47acd09 100644
--- a/drivers/usb/misc/usb251xb.c
+++ b/drivers/usb/misc/usb251xb.c
@@ -20,12 +20,11 @@
  */
 
 #include <linux/delay.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/nls.h>
 #include <linux/of_device.h>
-#include <linux/of_gpio.h>
 #include <linux/slab.h>
 
 /* Internal Register Set Addresses & Default Values acc. to DS00001692C */
@@ -127,7 +126,7 @@ struct usb251xb {
 	struct device *dev;
 	struct i2c_client *i2c;
 	u8 skip_config;
-	int gpio_reset;
+	struct gpio_desc *gpio_reset;
 	u16 vendor_id;
 	u16 product_id;
 	u16 device_id;
@@ -235,13 +234,13 @@ static const struct usb251xb_data usb2517i_data = {
 
 static void usb251xb_reset(struct usb251xb *hub, int state)
 {
-	if (!gpio_is_valid(hub->gpio_reset))
+	if (!hub->gpio_reset)
 		return;
 
-	gpio_set_value_cansleep(hub->gpio_reset, state);
+	gpiod_set_value_cansleep(hub->gpio_reset, state);
 
 	/* wait for hub recovery/stabilization */
-	if (state)
+	if (!state)
 		usleep_range(500, 750);	/* >=500us at power on */
 	else
 		usleep_range(1, 10);	/* >=1us at power down */
@@ -260,7 +259,7 @@ static int usb251xb_connect(struct usb251xb *hub)
 		i2c_wb[0] = 0x01;
 		i2c_wb[1] = USB251XB_STATUS_COMMAND_ATTACH;
 
-		usb251xb_reset(hub, 1);
+		usb251xb_reset(hub, 0);
 
 		err = i2c_smbus_write_i2c_block_data(hub->i2c,
 				USB251XB_ADDR_STATUS_COMMAND, 2, i2c_wb);
@@ -310,7 +309,7 @@ static int usb251xb_connect(struct usb251xb *hub)
 	i2c_wb[USB251XB_ADDR_PORT_MAP_7]        = hub->port_map7;
 	i2c_wb[USB251XB_ADDR_STATUS_COMMAND] = USB251XB_STATUS_COMMAND_ATTACH;
 
-	usb251xb_reset(hub, 1);
+	usb251xb_reset(hub, 0);
 
 	/* write registers */
 	for (i = 0; i < (USB251XB_I2C_REG_SZ / USB251XB_I2C_WRITE_SZ); i++) {
@@ -363,19 +362,13 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
 	else
 		hub->skip_config = 0;
 
-	hub->gpio_reset = of_get_named_gpio(np, "reset-gpios", 0);
-	if (hub->gpio_reset == -EPROBE_DEFER)
+	hub->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+	if (PTR_ERR(hub->gpio_reset) == -EPROBE_DEFER) {
 		return -EPROBE_DEFER;
-	if (gpio_is_valid(hub->gpio_reset)) {
-		err = devm_gpio_request_one(dev, hub->gpio_reset,
-					    GPIOF_OUT_INIT_LOW,
-					    "usb251xb reset");
-		if (err) {
-			dev_err(dev,
-				"unable to request GPIO %d as reset pin (%d)\n",
-				hub->gpio_reset, err);
-			return err;
-		}
+	} else if (IS_ERR(hub->gpio_reset)) {
+		err = PTR_ERR(hub->gpio_reset);
+		dev_err(dev, "unable to request GPIO reset pin (%d)\n", err);
+		return err;
 	}
 
 	if (of_property_read_u16_array(np, "vendor-id", &hub->vendor_id, 1))
-- 
2.12.0

  parent reply	other threads:[~2017-09-15 23:31 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-15 23:31 [PATCH 0/5] usb: usb251xb: Add USB2517i hub support and fix some bugs Serge Semin
2017-09-15 23:31 ` [PATCH 1/5] usb: usb251xb: Add USB2517/i hub support Serge Semin
2017-09-15 23:45   ` Greg KH
     [not found]     ` <20170915234514.GA8407-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2017-09-15 23:55       ` Serge Semin
2017-09-20 20:52   ` Rob Herring
2017-09-20 21:15     ` Serge Semin
2017-09-21 16:53       ` Rob Herring
     [not found]         ` <CAL_Jsq+8RqmOzwrH7U=F7Fh9aUHALK-SpJQWfdOR-0J8Pna23g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-09-21 17:40           ` Serge Semin
2017-09-15 23:31 ` [PATCH 2/5] usb: usb251xb: Fix property_u32 NULL pointer dereference Serge Semin
2017-09-15 23:31 ` [PATCH 3/5] usb: usb251xb: Add max power/current dts nodes Serge Semin
2017-09-15 23:31 ` Serge Semin [this message]
2017-09-15 23:31 ` [PATCH 5/5] usb: usb251xb: Add copyrights Serge Semin
     [not found]   ` <20170915233113.17855-6-fancer.lancer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-09-15 23:40     ` Greg KH
     [not found]       ` <20170915234028.GA7681-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2017-09-15 23:42         ` Greg KH
2017-09-15 23:45         ` Serge Semin
2017-09-15 23:53           ` Greg KH
2017-09-16  0:11             ` Serge Semin
     [not found] ` <20170915233113.17855-1-fancer.lancer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-09-16 10:42   ` [PATCH 0/9 v2] usb: usb251xb: Add USB2517i hub support and fix some bugs Serge Semin
2017-09-16 10:42     ` [PATCH 1/9 v2] usb: usb251xb: Add USB2517i specific struct and IDs Serge Semin
     [not found]       ` <20170916104220.3742-2-fancer.lancer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-04  7:39         ` Richard Leitner
2017-09-16 10:42     ` [PATCH 2/9 v2] usb: usb251xb: Add USB251x specific port count setting Serge Semin
     [not found]       ` <20170916104220.3742-3-fancer.lancer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-04  7:27         ` Richard Leitner
2017-09-16 10:42     ` [PATCH 3/9 v2] usb: usb251xb: Add 5,6,7 ports mapping def setting Serge Semin
2017-10-04  7:51       ` Richard Leitner
2017-09-16 10:42     ` [PATCH 5/9 v2] usb: usb251xb: Add battery enable setting flag Serge Semin
2017-09-16 10:42     ` [PATCH 6/9 v2] usb: usb251xb: Add USB2517 LED settings Serge Semin
2017-09-16 10:42     ` [PATCH 7/9 v2] usb: usb251xb: Fix property_u32 NULL pointer dereference Serge Semin
2017-09-16 10:42     ` [PATCH 9/9 v2] usb: usb251xb: Use GPIO descriptor consumer interface Serge Semin
2017-09-20 20:52       ` Rob Herring
2017-09-20 21:29         ` Serge Semin
2017-09-21  8:23       ` Greg KH
     [not found]         ` <20170921082338.GA30669-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2017-09-21 14:51           ` Serge Semin
2017-09-21 15:07             ` Greg KH
     [not found]               ` <20170921150714.GA7791-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2017-09-22 15:26                 ` Serge Semin
2017-09-22 16:05                   ` Greg KH
     [not found]     ` <20170916104220.3742-1-fancer.lancer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-09-16 10:42       ` [PATCH 4/9 v2] usb: usb251xb: Add 5,6,7 ports boost settings Serge Semin
     [not found]         ` <20170916104220.3742-5-fancer.lancer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-04  7:57           ` Richard Leitner
2017-09-16 10:42       ` [PATCH 8/9 v2] usb: usb251xb: Add max power/current dts property support Serge Semin
2017-09-20 20:52         ` Rob Herring
2017-09-20 21:27           ` Serge Semin
2017-09-21 16:26             ` Rob Herring
     [not found]               ` <CAL_Jsq+ftbGSQOOor_1L9NO9h7rjYm9nB26PxNOPgyHU6k3j_A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-09-21 17:10                 ` Serge Semin
2017-10-04  8:12                   ` Richard Leitner
     [not found]                     ` <53559bc4-5faa-6797-7c12-f635049f1411-WcANXNA0UjBBDgjK7y7TUQ@public.gmane.org>
2017-10-04 13:44                       ` Rob Herring
2017-10-22 20:38       ` [PATCH 00/10 v3] usb: usb251xb: Add USB2517i hub support and fix some bugs Serge Semin
2017-10-22 20:38         ` [PATCH 01/10 v3] usb: usb251xb: Update usb251xb bindings Serge Semin
     [not found]           ` <20171022203812.9379-2-fancer.lancer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-27  3:21             ` Rob Herring
2017-10-22 20:38         ` [PATCH 02/10 v3] usb: usb251xb: Add USB2517i specific struct and IDs Serge Semin
     [not found]           ` <20171022203812.9379-3-fancer.lancer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-23 21:47             ` Richard Leitner
     [not found]         ` <20171022203812.9379-1-fancer.lancer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-22 20:38           ` [PATCH 03/10 v3] usb: usb251xb: Add USB251x specific port count setting Serge Semin
     [not found]             ` <20171022203812.9379-4-fancer.lancer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-23 21:36               ` Richard Leitner
2017-10-22 20:38           ` [PATCH 10/10 v3] usb: usb251xb: Use GPIO descriptor consumer interface Serge Semin
2017-10-22 20:38         ` [PATCH 04/10 v3] usb: usb251xb: Add 5,6,7 ports mapping def setting Serge Semin
2017-10-22 20:38         ` [PATCH 05/10 v3] usb: usb251xb: Add 5,6,7 ports boost settings Serge Semin
2017-10-22 20:38         ` [PATCH 06/10 v3] usb: usb251xb: Add battery enable setting flag Serge Semin
2017-10-22 20:38         ` [PATCH 07/10 v3] usb: usb251xb: Add USB2517 LED settings Serge Semin
2017-10-22 20:38         ` [PATCH 08/10 v3] usb: usb251xb: Fix property_u32 NULL pointer dereference Serge Semin
2017-10-22 20:38         ` [PATCH 09/10 v3] usb: usb251xb: Add max power/current dts property support Serge Semin
     [not found]           ` <20171022203812.9379-10-fancer.lancer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-23 21:55             ` Richard Leitner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170915233113.17855-5-fancer.lancer@gmail.com \
    --to=fancer.lancer@gmail.com \
    --cc=Sergey.Semin@t-platforms.ru \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=richard.leitner@skidata.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).