Re: [PATCH] usb: misc: usb3503: Use gpio descriptor interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Pavel,

On 23.01.2020 15:42, Pavel Löbl wrote:
> Move gpio related code to descriptor-based interface. This makes
> driver to respect active physical level as specified in DT. Existing
> DT nodes are adjusted to reflect the former behaviour.
>
> Signed-off-by: Pavel Löbl <pavel@xxxxxxxx>

This is a duplicate of https://patchwork.kernel.org/cover/11285261/ 
which has been already applied to current linux-next.

> ---
>   arch/arm/boot/dts/exynos5250-arndale.dts      |  4 +-
>   .../boot/dts/sun8i-a83t-cubietruck-plus.dts   |  2 +-
>   arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi     |  2 +-
>   drivers/usb/misc/usb3503.c                    | 79 +++++++------------
>   include/linux/platform_data/usb3503.h         |  6 +-
>   5 files changed, 35 insertions(+), 58 deletions(-)
>
> diff --git a/arch/arm/boot/dts/exynos5250-arndale.dts b/arch/arm/boot/dts/exynos5250-arndale.dts
> index d6c85efdb465..344e15a4c959 100644
> --- a/arch/arm/boot/dts/exynos5250-arndale.dts
> +++ b/arch/arm/boot/dts/exynos5250-arndale.dts
> @@ -153,8 +153,8 @@ xxti {
>   	usb_hub: usb-hub {
>   		compatible = "smsc,usb3503a";
>   
> -		reset-gpios = <&gpx3 5 GPIO_ACTIVE_LOW>;
> -		connect-gpios = <&gpd1 7 GPIO_ACTIVE_LOW>;
> +		reset-gpios = <&gpx3 5 GPIO_ACTIVE_HIGH>;
> +		connect-gpios = <&gpd1 7 GPIO_ACTIVE_HIGH>;
>   	};
>   };
>   
> diff --git a/arch/arm/boot/dts/sun8i-a83t-cubietruck-plus.dts b/arch/arm/boot/dts/sun8i-a83t-cubietruck-plus.dts
> index d9be511f054f..fb928503ad45 100644
> --- a/arch/arm/boot/dts/sun8i-a83t-cubietruck-plus.dts
> +++ b/arch/arm/boot/dts/sun8i-a83t-cubietruck-plus.dts
> @@ -101,7 +101,7 @@ usb-hub {
>   		initial-mode = <1>; /* initialize in HUB mode */
>   		disabled-ports = <1>;
>   		intn-gpios = <&pio 7 5 GPIO_ACTIVE_HIGH>; /* PH5 */
> -		reset-gpios = <&pio 4 16 GPIO_ACTIVE_LOW>; /* PE16 */
> +		reset-gpios = <&pio 4 16 GPIO_ACTIVE_HIGH>; /* PE16 */
>   		connect-gpios = <&pio 4 17 GPIO_ACTIVE_HIGH>; /* PE17 */
>   		refclk-frequency = <19200000>;
>   	};
> diff --git a/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi b/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi
> index e12a36ce5d93..a1d3575edb39 100644
> --- a/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi
> +++ b/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi
> @@ -498,7 +498,7 @@ wcnss@a21b000 {
>   
>   	usb2513 {
>   		compatible = "smsc,usb3503";
> -		reset-gpios = <&pm8916_gpios 3 GPIO_ACTIVE_LOW>;
> +		reset-gpios = <&pm8916_gpios 3 GPIO_ACTIVE_HIGH>;
>   		initial-mode = <1>;
>   	};
>   
> diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c
> index 72f39a9751b5..d9ffb2d5c318 100644
> --- a/drivers/usb/misc/usb3503.c
> +++ b/drivers/usb/misc/usb3503.c
> @@ -47,19 +47,19 @@ struct usb3503 {
>   	struct device		*dev;
>   	struct clk		*clk;
>   	u8	port_off_mask;
> -	int	gpio_intn;
> -	int	gpio_reset;
> -	int	gpio_connect;
> +	struct gpio_desc	*gpio_intn;
> +	struct gpio_desc	*gpio_reset;
> +	struct gpio_desc	*gpio_connect;
>   	bool	secondary_ref_clk;
>   };
>   
>   static int usb3503_reset(struct usb3503 *hub, int state)
>   {
> -	if (!state && gpio_is_valid(hub->gpio_connect))
> -		gpio_set_value_cansleep(hub->gpio_connect, 0);
> +	if (!state && hub->gpio_connect)
> +		gpiod_set_value_cansleep(hub->gpio_connect, 0);
>   
> -	if (gpio_is_valid(hub->gpio_reset))
> -		gpio_set_value_cansleep(hub->gpio_reset, state);
> +	if (hub->gpio_reset)
> +		gpiod_set_value_cansleep(hub->gpio_reset, state);
>   
>   	/* Wait T_HUBINIT == 4ms for hub logic to stabilize */
>   	if (state)
> @@ -115,8 +115,8 @@ static int usb3503_connect(struct usb3503 *hub)
>   		}
>   	}
>   
> -	if (gpio_is_valid(hub->gpio_connect))
> -		gpio_set_value_cansleep(hub->gpio_connect, 1);
> +	if (hub->gpio_connect)
> +		gpiod_set_value_cansleep(hub->gpio_connect, 1);
>   
>   	hub->mode = USB3503_MODE_HUB;
>   	dev_info(dev, "switched to HUB mode\n");
> @@ -164,6 +164,7 @@ static int usb3503_probe(struct usb3503 *hub)
>   	u32 mode = USB3503_MODE_HUB;
>   	const u32 *property;
>   	int len;
> +	int intn_level;
>   
>   	if (pdata) {
>   		hub->port_off_mask	= pdata->port_off_mask;
> @@ -230,59 +231,35 @@ static int usb3503_probe(struct usb3503 *hub)
>   			}
>   		}
>   
> -		hub->gpio_intn	= of_get_named_gpio(np, "intn-gpios", 0);
> -		if (hub->gpio_intn == -EPROBE_DEFER)
> -			return -EPROBE_DEFER;
> -		hub->gpio_connect = of_get_named_gpio(np, "connect-gpios", 0);
> -		if (hub->gpio_connect == -EPROBE_DEFER)
> -			return -EPROBE_DEFER;
> -		hub->gpio_reset = of_get_named_gpio(np, "reset-gpios", 0);
> -		if (hub->gpio_reset == -EPROBE_DEFER)
> -			return -EPROBE_DEFER;
> -		of_property_read_u32(np, "initial-mode", &mode);
> -		hub->mode = mode;
> -	}
> -
> -	if (hub->port_off_mask && !hub->regmap)
> -		dev_err(dev, "Ports disabled with no control interface\n");
> -
> -	if (gpio_is_valid(hub->gpio_intn)) {
> -		int val = hub->secondary_ref_clk ? GPIOF_OUT_INIT_LOW :
> -						   GPIOF_OUT_INIT_HIGH;
> -		err = devm_gpio_request_one(dev, hub->gpio_intn, val,
> -					    "usb3503 intn");
> +		intn_level = hub->secondary_ref_clk ? GPIOD_OUT_LOW : GPIOD_OUT_HIGH;
> +		hub->gpio_intn	= devm_gpiod_get_optional(dev, "intn", intn_level);
> +		err = PTR_ERR_OR_ZERO(hub->gpio_intn);
>   		if (err) {
> -			dev_err(dev,
> -				"unable to request GPIO %d as interrupt pin (%d)\n",
> -				hub->gpio_intn, err);
> +			if (err != -EPROBE_DEFER)
> +				dev_err(dev, "failed to get interrupt GPIO");
>   			return err;
>   		}
> -	}
> -
> -	if (gpio_is_valid(hub->gpio_connect)) {
> -		err = devm_gpio_request_one(dev, hub->gpio_connect,
> -				GPIOF_OUT_INIT_LOW, "usb3503 connect");
> +		hub->gpio_connect = devm_gpiod_get_optional(dev, "connect", GPIOD_OUT_LOW);
> +		err = PTR_ERR_OR_ZERO(hub->gpio_connect);
>   		if (err) {
> -			dev_err(dev,
> -				"unable to request GPIO %d as connect pin (%d)\n",
> -				hub->gpio_connect, err);
> +			if (err != -EPROBE_DEFER)
> +				dev_err(dev, "failed to get GPIO for connect");
>   			return err;
>   		}
> -	}
> -
> -	if (gpio_is_valid(hub->gpio_reset)) {
> -		err = devm_gpio_request_one(dev, hub->gpio_reset,
> -				GPIOF_OUT_INIT_LOW, "usb3503 reset");
> -		/* Datasheet defines a hardware reset to be at least 100us */
> -		usleep_range(100, 10000);
> +		hub->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
> +		err = PTR_ERR_OR_ZERO(hub->gpio_reset);
>   		if (err) {
> -			dev_err(dev,
> -				"unable to request GPIO %d as reset pin (%d)\n",
> -				hub->gpio_reset, err);
> +			if (err != -EPROBE_DEFER)
> +				dev_err(dev, "failed to get reset GPIO");
>   			return err;
>   		}
> +		of_property_read_u32(np, "initial-mode", &mode);
> +		hub->mode = mode;
>   	}
>   
> +	if (hub->port_off_mask && !hub->regmap)
> +		dev_err(dev, "Ports disabled with no control interface\n");
> +
>   	usb3503_switch_mode(hub, hub->mode);
>   
>   	dev_info(dev, "%s: probed in %s mode\n", __func__,
> diff --git a/include/linux/platform_data/usb3503.h b/include/linux/platform_data/usb3503.h
> index e049d51c1353..3e966a62277e 100644
> --- a/include/linux/platform_data/usb3503.h
> +++ b/include/linux/platform_data/usb3503.h
> @@ -17,9 +17,9 @@ enum usb3503_mode {
>   struct usb3503_platform_data {
>   	enum usb3503_mode	initial_mode;
>   	u8	port_off_mask;
> -	int	gpio_intn;
> -	int	gpio_connect;
> -	int	gpio_reset;
> +	struct gpio_desc	*gpio_intn;
> +	struct gpio_desc	*gpio_connect;
> +	struct gpio_desc	*gpio_reset;
>   };
>   
>   #endif

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux