Commit 69a0c69a authored by Serge Semin's avatar Serge Semin Committed by Greg Kroah-Hartman

usb: usb251xb: Use GPIO descriptor consumer interface

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: default avatarSerge Semin <fancer.lancer@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4ed466ae
...@@ -20,12 +20,11 @@ ...@@ -20,12 +20,11 @@
*/ */
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/gpio.h> #include <linux/gpio/consumer.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/nls.h> #include <linux/nls.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_gpio.h>
#include <linux/slab.h> #include <linux/slab.h>
/* Internal Register Set Addresses & Default Values acc. to DS00001692C */ /* Internal Register Set Addresses & Default Values acc. to DS00001692C */
...@@ -126,7 +125,7 @@ struct usb251xb { ...@@ -126,7 +125,7 @@ struct usb251xb {
struct device *dev; struct device *dev;
struct i2c_client *i2c; struct i2c_client *i2c;
u8 skip_config; u8 skip_config;
int gpio_reset; struct gpio_desc *gpio_reset;
u16 vendor_id; u16 vendor_id;
u16 product_id; u16 product_id;
u16 device_id; u16 device_id;
...@@ -234,13 +233,13 @@ static const struct usb251xb_data usb2517i_data = { ...@@ -234,13 +233,13 @@ static const struct usb251xb_data usb2517i_data = {
static void usb251xb_reset(struct usb251xb *hub, int state) static void usb251xb_reset(struct usb251xb *hub, int state)
{ {
if (!gpio_is_valid(hub->gpio_reset)) if (!hub->gpio_reset)
return; return;
gpio_set_value_cansleep(hub->gpio_reset, state); gpiod_set_value_cansleep(hub->gpio_reset, state);
/* wait for hub recovery/stabilization */ /* wait for hub recovery/stabilization */
if (state) if (!state)
usleep_range(500, 750); /* >=500us at power on */ usleep_range(500, 750); /* >=500us at power on */
else else
usleep_range(1, 10); /* >=1us at power down */ usleep_range(1, 10); /* >=1us at power down */
...@@ -259,7 +258,7 @@ static int usb251xb_connect(struct usb251xb *hub) ...@@ -259,7 +258,7 @@ static int usb251xb_connect(struct usb251xb *hub)
i2c_wb[0] = 0x01; i2c_wb[0] = 0x01;
i2c_wb[1] = USB251XB_STATUS_COMMAND_ATTACH; i2c_wb[1] = USB251XB_STATUS_COMMAND_ATTACH;
usb251xb_reset(hub, 1); usb251xb_reset(hub, 0);
err = i2c_smbus_write_i2c_block_data(hub->i2c, err = i2c_smbus_write_i2c_block_data(hub->i2c,
USB251XB_ADDR_STATUS_COMMAND, 2, i2c_wb); USB251XB_ADDR_STATUS_COMMAND, 2, i2c_wb);
...@@ -309,7 +308,7 @@ static int usb251xb_connect(struct usb251xb *hub) ...@@ -309,7 +308,7 @@ static int usb251xb_connect(struct usb251xb *hub)
i2c_wb[USB251XB_ADDR_PORT_MAP_7] = hub->port_map7; i2c_wb[USB251XB_ADDR_PORT_MAP_7] = hub->port_map7;
i2c_wb[USB251XB_ADDR_STATUS_COMMAND] = USB251XB_STATUS_COMMAND_ATTACH; i2c_wb[USB251XB_ADDR_STATUS_COMMAND] = USB251XB_STATUS_COMMAND_ATTACH;
usb251xb_reset(hub, 1); usb251xb_reset(hub, 0);
/* write registers */ /* write registers */
for (i = 0; i < (USB251XB_I2C_REG_SZ / USB251XB_I2C_WRITE_SZ); i++) { for (i = 0; i < (USB251XB_I2C_REG_SZ / USB251XB_I2C_WRITE_SZ); i++) {
...@@ -362,19 +361,13 @@ static int usb251xb_get_ofdata(struct usb251xb *hub, ...@@ -362,19 +361,13 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
else else
hub->skip_config = 0; hub->skip_config = 0;
hub->gpio_reset = of_get_named_gpio(np, "reset-gpios", 0); hub->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
if (hub->gpio_reset == -EPROBE_DEFER) if (PTR_ERR(hub->gpio_reset) == -EPROBE_DEFER) {
return -EPROBE_DEFER; return -EPROBE_DEFER;
if (gpio_is_valid(hub->gpio_reset)) { } else if (IS_ERR(hub->gpio_reset)) {
err = devm_gpio_request_one(dev, hub->gpio_reset, err = PTR_ERR(hub->gpio_reset);
GPIOF_OUT_INIT_LOW, dev_err(dev, "unable to request GPIO reset pin (%d)\n", err);
"usb251xb reset"); return err;
if (err) {
dev_err(dev,
"unable to request GPIO %d as reset pin (%d)\n",
hub->gpio_reset, err);
return err;
}
} }
if (of_property_read_u16_array(np, "vendor-id", &hub->vendor_id, 1)) if (of_property_read_u16_array(np, "vendor-id", &hub->vendor_id, 1))
......
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