[PATCH] usb: always build usb/common/ targets; fixes extcon-axp288 build error

2018-04-16 Thread Randy Dunlap
From: Randy Dunlap 

The extcon-axp288 driver selects USB_ROLE_SWITCH, but the USB
Makefile does not currently build drivers/usb/common/ (where
USB_ROLE_SWITCH code is) unless USB_COMMON is set, so modify
the USB Makefile to always descend into drivers/usb/common/
to build its configured targets.

Fixes these build errors:

ERROR: "usb_role_switch_get" [drivers/extcon/extcon-axp288.ko] undefined!
ERROR: "usb_role_switch_set_role" [drivers/extcon/extcon-axp288.ko] undefined!
ERROR: "usb_role_switch_get_role" [drivers/extcon/extcon-axp288.ko] undefined!
ERROR: "usb_role_switch_put" [drivers/extcon/extcon-axp288.ko] undefined!

An alternative patch would be to select USB_COMMON in the EXTCON_AXP288
driver Kconfig entry, but this would build more code in
drivers/usb/common/ than is necessary.

Reported-by: Fengguang Wu 
Signed-off-by: Randy Dunlap 
Cc: MyungJoo Ham 
Cc: Chanwoo Choi 
Cc: Hans de Goede 
Cc: Greg Kroah-Hartman 
Cc: Andy Shevchenko 
Cc: Heikki Krogerus 
Cc: linux-usb@vger.kernel.org
---
 drivers/usb/Makefile |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- lnx-417-rc1.orig/drivers/usb/Makefile
+++ lnx-417-rc1/drivers/usb/Makefile
@@ -60,7 +60,7 @@ obj-$(CONFIG_USB_CHIPIDEA)+= chipidea/
 obj-$(CONFIG_USB_RENESAS_USBHS)+= renesas_usbhs/
 obj-$(CONFIG_USB_GADGET)   += gadget/
 
-obj-$(CONFIG_USB_COMMON)   += common/
+obj-y  += common/
 
 obj-$(CONFIG_USBIP_CORE)   += usbip/
 


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/3] dt-bindings: usb: Update documentation for Qualcomm DWC3 driver

2018-04-16 Thread Manu Gautam
Hi Rob,


On 4/17/2018 2:08 AM, Rob Herring wrote:
> On Fri, Apr 13, 2018 at 10:21:22PM +0530, Manu Gautam wrote:
>> Existing documentation has lot of incorrect information as it
>> was originally added for a driver that no longer exists.
>>
>> Signed-off-by: Manu Gautam 
>> ---
>>  .../devicetree/bindings/usb/qcom,dwc3.txt  | 78 
>> --
>>  1 file changed, 57 insertions(+), 21 deletions(-)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/qcom,dwc3.txt 
>> b/Documentation/devicetree/bindings/usb/qcom,dwc3.txt
>> index bc8a2fa..fdc574a 100644
>> --- a/Documentation/devicetree/bindings/usb/qcom,dwc3.txt
>> +++ b/Documentation/devicetree/bindings/usb/qcom,dwc3.txt
>> @@ -1,54 +1,90 @@
>>  Qualcomm SuperSpeed DWC3 USB SoC controller
>>  
>>  Required properties:
>> -- compatible:   should contain "qcom,dwc3"
>> +- compatible:   should contain "qcom,dwc3"
> Needs an SoC specific compatible string.

Thanks for review.
Sure. Will add that.

>
>> +- reg:  offset and length of register set for QSCRATCH 
>> wrapper
>> +- power-domains:specifies a phandle to PM domain provider node
>>  - clocks:   A list of phandle + clock-specifier pairs for the
>>  clocks listed in clock-names
>> -- clock-names:  Should contain the following:
>> +- clock-names:  Should contain the following:
>>"core"Master/Core clock, have to be >= 125 MHz for SS
>>  operation and >= 60MHz for HS operation
>> +  "mock_utmi"   Mock utmi clock needed for ITP/SOF generation in
>> +host mode. Its frequency should be 19.2MHz.
>> +  "sleep"   Sleep clock, used for wakeup when USB3 core goes
>> +into low power mode (U3).
>>  
>>  Optional clocks:
>>"iface"   System bus AXI clock.  Not present on all platforms
>> -  "sleep"   Sleep clock, used when USB3 core goes into low
>> -power mode (U3).
>> +  "cfg_noc" System Config NOC clock. Not present on all platforms
> These need to be specific as to which compatible properties have or 
> don't have these clocks.
ok

>
>> +- assigned-clocks:  should be:
>> +MOCK_UTMI_CLK
>> +MASTER_CLK
>> +- assigned-clock-rates: should be:
>> +19.2Mhz (19200) for MOCK_UTMI_CLK
>> +>=125Mhz (12500) for MASTER_CLK in SS 
>> mode
>> +>=60Mhz (6000) for MASTER_CLK in HS mode
>> +
>> +Optional properties:
>> +- resets:   list of phandle and reset specifier pairs
> How many?
I will provide exact detail for each compatible property.
>
>> +- interrupts:   specifies interrupts from controller wrapper 
>> used
>> +to wakeup from low power/susepnd state. Must contain
>> +one or more entry for interrupt-names property
>> +- interrupt-names:  Must include the following entries:
>> +- "hs_phy_irq": The interrupt that is asserted when a
>> +   wakeup event is received on USB2 bus
>> +- "ss_phy_irq": The interrupt that is asserted when a
>> +   wakeup event is received on USB3 bus
>> +- "dm_hs_phy_irq" and "dp_hs_phy_irq": Separate
>> +   interrupts for any wakeup event on DM and DP lines
> Sounds like the irqs are actually part of the PHYs? If so, then that's 
> where they should be in the DT.
No. These are actually part of controller wrapper called - qscratch which
has connectivity to phy outputs signals. Also, these are abstracted from PHY
and are present irrespective of type of phy present. I will add soc specific
info also in comments specifying which interrupts are not present on particular
soc/compatible.

>
>> +- qcom,select-utmi-as-pipe-clk: if present, disable USB3 pipe_clk 
>> requirement.
>> +Used when dwc3 operates without SSPHY and only
>> +HS/FS/LS modes are supported.
>>  
>>  Required child node:
>>  A child node must exist to represent the core DWC3 IP block. The name of
>>  the node is not important. The content of the node is defined in dwc3.txt.
>>  
>>  Phy documentation is provided in the following places:
>> -Documentation/devicetree/bindings/phy/qcom-dwc3-usb-phy.txt
>> +Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt   - USB3 QMP PHY
>> +Documentation/devicetree/bindings/phy/qcom-qusb2-phy.txt - USB2 QUSB2 PHY
>>  
>>  Example device nodes:
>>  
>>  hs_phy: phy@100f8800 {
>> -compatible = "qcom,dwc3-hs-usb-phy";
>> -reg = <0x100f8800 0x30>;
>> -clocks = < USB30_0_UTMI_CLK>;
>> -clock-names = "ref";
>> - 

refine xhci-plat-Fix-xhci_plat-shutdown-sequence

2018-04-16 Thread leiwan


xhci-plat Shutdown callback should check HCD_FLAG_HW_ACCESSIBLE
before accessing any register. This should avoid hung with access
controllers which support runtime suspend

This can fix for issue of https://patchwork.kernel.org/patch/10339317/
corresponding upload in CAF:
https://source.codeaurora.org/quic/la/kernel/msm-4.4/commit/?h=LV.HB.1.1.5-03810-8x96.0=a7a5307ee04ad349d365ad50f304605a9cd9bd0a

full patch refer attachment.
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 9b27798..bdf914d 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -702,6 +702,10 @@ static void xhci_shutdown(struct usb_hcd *hcd)
usb_disable_xhci_ports(to_pci_dev(hcd->self.sysdev));

spin_lock_irq(>lock);
+   if (!HCD_HW_ACCESSIBLE(hcd)) {
+   spin_unlock_irq(>lock);
+   return;
+   }
xhci_halt(xhci);
/* Workaround for spurious wakeups at shutdown with HSW */
if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)From 9b65acb64f1ad87d115fa147c9e947fb3d37471c Mon Sep 17 00:00:00 2001
From: Lei wang 
Date: Tue, 17 Apr 2018 10:55:35 +0800
Subject: [PATCH] xhci: plat: Fix xhci_plat shutdown hung

xhci-plat Shutdown callback should check HCD_FLAG_HW_ACCESSIBLE
before accessing any register. This should avoid hung with access
controllers which support runtime suspend

Signed-off-by: Lei wang 
---
 drivers/usb/host/xhci.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 9b27798..bdf914d 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -702,6 +702,10 @@ static void xhci_shutdown(struct usb_hcd *hcd)
 		usb_disable_xhci_ports(to_pci_dev(hcd->self.sysdev));
 
 	spin_lock_irq(>lock);
+	if (!HCD_HW_ACCESSIBLE(hcd)) {
+		spin_unlock_irq(>lock);
+		return;
+	}
 	xhci_halt(xhci);
 	/* Workaround for spurious wakeups at shutdown with HSW */
 	if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
-- 
1.9.1



ConfigFS, FunctionFS, and MS XInput

2018-04-16 Thread Daniel Hefti

Hey guys,

I've been banging my head against the wall for a couple of days trying 
to get a Raspberry Pi 0W to talk to Windows (8.1/10) as an XInput game 
controller using ConfigFS and FunctionFS, having little success.  I've 
tried to build both a generic XInput device and one that attempts to 
emulate an X360 controller.  The X360 controller seems to get "further", 
in that Windows says it recognizes the device and the drivers are 
working.  Whatever that means.  The generic version just shows up as an 
unrecognized device (with the name I've given it).  Neither are getting 
or able to send any data from/to their respective endpoints.  The X360 
version, I tested locally via loopback/dummy UDC, and the xboxdrv driver 
can detect and read controller state messages/reports I send it, so at 
least that much works.  Not sure what I could possibly be missing.


I can say I've successfully created HID USB game controller devices. 
Those are accessible from Windows, but, unfortunately, many Windows 
games don't support HID particularly well, and I'm trying to avoid 
someone having to use something like XOutput as a workaround to get this 
device to work.


I do have Wireshark with USBPCap installed, so I can at least capture 
some of the data, which I did, but  it wasn't really leading me 
anywhere, possibly due to my lack of knowledge in this particular 
subject.  Unfortunately, I didn't save my pcap results.  I'll likely end 
up doing it again once I've given my head some time to heal.


Any insights?  References?  Something you think could help guide me in 
the right direction?  There's plenty of documentation and example 
implementations out there for HID devices, but not so much for XInput 
devices and functionfs in general, so any help would be greatly appreciated!


Linux raspberrypi 4.14.33+ #1 Sat Apr 14 01:03:28 CDT 2018 armv6l 
GNU/Linux (recompiled Raspbian, because it didn't originally come with 
usb_f_fs.)


Thanks!

Dan Hefti
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/3] usb: gadget: f_fs: Only return delayed status when len is 0

2018-04-16 Thread Jerry Zhang
Commit 1b9ba000 ("Allow function drivers to pause control
transfers") states that USB_GADGET_DELAYED_STATUS is only
supported if data phase is 0 bytes.

It seems that when the length is not 0 bytes, there is no
need to explicitly delay the data stage since the transfer
is not completed until the user responds. However, when the
length is 0, there is no data stage and the transfer is
finished once setup() returns, hence there is a need to
explicitly delay completion.

This manifests as the following bugs:

Prior to 946ef68ad4e4 ('Let setup() return
USB_GADGET_DELAYED_STATUS'), when setup is 0 bytes, ffs
would require user to queue a 0 byte request in order to
clear setup state. However, that 0 byte request was actually
not needed and would hang and cause errors in other setup
requests.

After the above commit, 0 byte setups work since the gadget
now accepts empty queues to ep0 to clear the delay, but all
other setups hang.

Fixes: 946ef68ad4e4 ("Let setup() return USB_GADGET_DELAYED_STATUS")
Signed-off-by: Jerry Zhang 
---
 drivers/usb/gadget/function/f_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_fs.c 
b/drivers/usb/gadget/function/f_fs.c
index 7d5b1c448eb2..4b2cb9d93176 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -3271,7 +3271,7 @@ static int ffs_func_setup(struct usb_function *f,
__ffs_event_add(ffs, FUNCTIONFS_SETUP);
spin_unlock_irqrestore(>ev.waitq.lock, flags);
 
-   return USB_GADGET_DELAYED_STATUS;
+   return creq->wLength == 0 ? USB_GADGET_DELAYED_STATUS : 0;
 }
 
 static bool ffs_func_req_match(struct usb_function *f,
-- 
2.17.0.484.g0c8726318c-goog

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] Documentation: usb: Add docs for configfs control requests

2018-04-16 Thread Jerry Zhang
Signed-off-by: Jerry Zhang 
---
 Documentation/usb/gadget_configfs.txt | 32 +++
 1 file changed, 32 insertions(+)

diff --git a/Documentation/usb/gadget_configfs.txt 
b/Documentation/usb/gadget_configfs.txt
index 635e57493709..a50f16c8a4bb 100644
--- a/Documentation/usb/gadget_configfs.txt
+++ b/Documentation/usb/gadget_configfs.txt
@@ -285,6 +285,38 @@ e.g.:
 
 $ rmdir g1
 
+8. Handling control requests
+--
+
+A composite gadget with changing configurations may still want to handle
+vendor control requests in a centralized location. In particular, functionfs
+instances can pass control requests to user-space, but there is no
+guarantee that a functionfs is in the current config.
+
+To handle this there is a special config in the root of the gadget
+called control_config. Functions linked here do not appear in the
+configuration, but will receive control requests. To use it:
+
+Create a special instance of functionfs.
+
+$ mkdir functions/ffs.ctrl
+
+Mount the functionfs instance and write descriptors.
+
+mount functionfs ctrl /dev/ffs-ctrl
+# Write dummy functionfs descriptors to /dev/ffs-ctrl/ep0
+# Descriptors should include flag FUNCTIONFS_ALL_CTRL_RECIP
+
+Link the function into control config.
+
+$ ln -s functions/ffs.ctrl control_config/f1
+
+Link normal functions into the appropriate config, and enable the gadget.
+
+$ echo  > UDC
+
+Handle control requests in /dev/ffs-ctrl/ep0. See functionfs documentation on 
how to do this.
+
 
 
 
-- 
2.17.0.484.g0c8726318c-goog

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] usb: gadget: configfs: Create control_config group

2018-04-16 Thread Jerry Zhang
Control_config is a group under gadget that acts
as a normal config group, except it does not
appear in cdev->configs. Functions can be linked
into the config as normal, and those functions
are bound and unbound with the rest of the gadget.

Create configfs_setup(), which will first attempt
composite setup. If that fails, it will go through
functions in control_config and use req_match to
find one that can handle the control request.

This allows the user to create a functionfs instance
dedicated to handling non-standard control requests
no matter what functions or configurations are
currently active.

Signed-off-by: Jerry Zhang 
---
 drivers/usb/gadget/configfs.c | 86 +++
 1 file changed, 68 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index efba66ca0719..b3acddda24c1 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -44,12 +44,22 @@ int check_user_usb_string(const char *name,
 
 static const struct usb_descriptor_header *otg_desc[2];
 
+struct config_usb_cfg {
+   struct config_group group;
+   struct config_group strings_group;
+   struct list_head string_list;
+   struct usb_configuration c;
+   struct list_head func_list;
+   struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
+};
+
 struct gadget_info {
struct config_group group;
struct config_group functions_group;
struct config_group configs_group;
struct config_group strings_group;
struct config_group os_desc_group;
+   struct config_usb_cfg control_config;
 
struct mutex lock;
struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
@@ -68,15 +78,6 @@ static inline struct gadget_info *to_gadget_info(struct 
config_item *item)
 return container_of(to_config_group(item), struct gadget_info, group);
 }
 
-struct config_usb_cfg {
-   struct config_group group;
-   struct config_group strings_group;
-   struct list_head string_list;
-   struct usb_configuration c;
-   struct list_head func_list;
-   struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
-};
-
 static inline struct config_usb_cfg *to_config_usb_cfg(struct config_item 
*item)
 {
return container_of(to_config_group(item), struct config_usb_cfg,
@@ -1205,11 +1206,10 @@ int composite_os_desc_req_prepare(struct 
usb_composite_dev *cdev,
 static void purge_configs_funcs(struct gadget_info *gi)
 {
struct usb_configuration*c;
+   struct usb_function *f, *tmp;
+   struct config_usb_cfg *cfg;
 
list_for_each_entry(c, >cdev.configs, list) {
-   struct usb_function *f, *tmp;
-   struct config_usb_cfg *cfg;
-
cfg = container_of(c, struct config_usb_cfg, c);
 
list_for_each_entry_safe(f, tmp, >functions, list) {
@@ -1229,6 +1229,14 @@ static void purge_configs_funcs(struct gadget_info *gi)
c->highspeed = 0;
c->fullspeed = 0;
}
+
+   cfg = >control_config;
+   c = >c;
+   list_for_each_entry_safe(f, tmp, >functions, list) {
+   list_move_tail(>list, >func_list);
+   if (f->unbind)
+   f->unbind(c, f);
+   }
 }
 
 static int configfs_composite_bind(struct usb_gadget *gadget,
@@ -1242,6 +1250,9 @@ static int configfs_composite_bind(struct usb_gadget 
*gadget,
struct usb_string   *s;
unsignedi;
int ret;
+   struct config_usb_cfg *cfg;
+   struct usb_function *f;
+   struct usb_function *tmp;
 
/* the gi->lock is hold by the caller */
cdev->gadget = gadget;
@@ -1260,8 +1271,6 @@ static int configfs_composite_bind(struct usb_gadget 
*gadget,
 
 
list_for_each_entry(c, >cdev.configs, list) {
-   struct config_usb_cfg *cfg;
-
cfg = container_of(c, struct config_usb_cfg, c);
if (list_empty(>func_list)) {
pr_err("Config %s/%d of %s needs at least one 
function.\n",
@@ -1320,9 +1329,6 @@ static int configfs_composite_bind(struct usb_gadget 
*gadget,
 
/* Go through all configs, attach all functions */
list_for_each_entry(c, >cdev.configs, list) {
-   struct config_usb_cfg *cfg;
-   struct usb_function *f;
-   struct usb_function *tmp;
struct gadget_config_name *cn;
 
if (gadget_is_otg(gadget))
@@ -1362,6 +1368,16 @@ static int configfs_composite_bind(struct usb_gadget 
*gadget,
goto err_purge_funcs;
}
 
+   cfg = >control_config;
+   c = >c;
+   list_for_each_entry_safe(f, tmp, >func_list, list) {
+   if (f->req_match && f->setup) {
+   list_del(>list);
+   if 

[PATCH 0/3] Handle custom control requests in userspace

2018-04-16 Thread Jerry Zhang
Here is the patch set I proposed in 
https://www.spinics.net/lists/linux-usb/msg167533.html.

Vendor specific control requests are a significant category of
USB communications. With the current framework, it is difficult
for a composite gadget to handle these requests since any
function could be active. This patchset/feature allows all 
unhandled control requests to be passed to a singular
functionfs instance regardless of active configuration.

Patch 1 fixes an f_fs bug, patch 2 implements this feature,
and patch 3 adds user facing documentation and examples.

Tested on 4.9.

Jerry Zhang (3):
  usb: gadget: f_fs: Only return delayed status when len is 0
  usb: gadget: configfs: Create control_config group
  Documentation: usb: Add docs for configfs control requests

 Documentation/usb/gadget_configfs.txt | 32 ++
 drivers/usb/gadget/configfs.c | 86 +--
 drivers/usb/gadget/function/f_fs.c|  2 +-
 3 files changed, 101 insertions(+), 19 deletions(-)

-- 
2.17.0.484.g0c8726318c-goog

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Proposal

2018-04-16 Thread MS Zeliha Omer Faruk



Hello

Greeetings to you please did you get my previous email regarding my
investment proposal last week friday ?

MS.Zeliha ömer faruk
zeliha.omer.fa...@gmail.com

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/3] dt-bindings: usb: Update documentation for Qualcomm DWC3 driver

2018-04-16 Thread Rob Herring
On Fri, Apr 13, 2018 at 10:21:22PM +0530, Manu Gautam wrote:
> Existing documentation has lot of incorrect information as it
> was originally added for a driver that no longer exists.
> 
> Signed-off-by: Manu Gautam 
> ---
>  .../devicetree/bindings/usb/qcom,dwc3.txt  | 78 
> --
>  1 file changed, 57 insertions(+), 21 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/usb/qcom,dwc3.txt 
> b/Documentation/devicetree/bindings/usb/qcom,dwc3.txt
> index bc8a2fa..fdc574a 100644
> --- a/Documentation/devicetree/bindings/usb/qcom,dwc3.txt
> +++ b/Documentation/devicetree/bindings/usb/qcom,dwc3.txt
> @@ -1,54 +1,90 @@
>  Qualcomm SuperSpeed DWC3 USB SoC controller
>  
>  Required properties:
> -- compatible:should contain "qcom,dwc3"
> +- compatible:should contain "qcom,dwc3"

Needs an SoC specific compatible string.

> +- reg:   offset and length of register set for QSCRATCH 
> wrapper
> +- power-domains: specifies a phandle to PM domain provider node
>  - clocks:A list of phandle + clock-specifier pairs for the
>   clocks listed in clock-names
> -- clock-names:   Should contain the following:
> +- clock-names:   Should contain the following:
>"core" Master/Core clock, have to be >= 125 MHz for SS
>   operation and >= 60MHz for HS operation
> +  "mock_utmi"Mock utmi clock needed for ITP/SOF generation in
> + host mode. Its frequency should be 19.2MHz.
> +  "sleep"Sleep clock, used for wakeup when USB3 core goes
> + into low power mode (U3).
>  
>  Optional clocks:
>"iface"System bus AXI clock.  Not present on all platforms
> -  "sleep"Sleep clock, used when USB3 core goes into low
> - power mode (U3).
> +  "cfg_noc"  System Config NOC clock. Not present on all platforms

These need to be specific as to which compatible properties have or 
don't have these clocks.

> +- assigned-clocks:   should be:
> + MOCK_UTMI_CLK
> + MASTER_CLK
> +- assigned-clock-rates: should be:
> +19.2Mhz (19200) for MOCK_UTMI_CLK
> +>=125Mhz (12500) for MASTER_CLK in SS 
> mode
> +>=60Mhz (6000) for MASTER_CLK in HS mode
> +
> +Optional properties:
> +- resets:list of phandle and reset specifier pairs

How many? 

> +- interrupts:specifies interrupts from controller wrapper 
> used
> + to wakeup from low power/susepnd state. Must contain
> + one or more entry for interrupt-names property
> +- interrupt-names:   Must include the following entries:
> + - "hs_phy_irq": The interrupt that is asserted when a
> +wakeup event is received on USB2 bus
> + - "ss_phy_irq": The interrupt that is asserted when a
> +wakeup event is received on USB3 bus
> + - "dm_hs_phy_irq" and "dp_hs_phy_irq": Separate
> +interrupts for any wakeup event on DM and DP lines

Sounds like the irqs are actually part of the PHYs? If so, then that's 
where they should be in the DT.

> +- qcom,select-utmi-as-pipe-clk: if present, disable USB3 pipe_clk 
> requirement.
> + Used when dwc3 operates without SSPHY and only
> + HS/FS/LS modes are supported.
>  
>  Required child node:
>  A child node must exist to represent the core DWC3 IP block. The name of
>  the node is not important. The content of the node is defined in dwc3.txt.
>  
>  Phy documentation is provided in the following places:
> -Documentation/devicetree/bindings/phy/qcom-dwc3-usb-phy.txt
> +Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt   - USB3 QMP PHY
> +Documentation/devicetree/bindings/phy/qcom-qusb2-phy.txt - USB2 QUSB2 PHY
>  
>  Example device nodes:
>  
>   hs_phy: phy@100f8800 {
> - compatible = "qcom,dwc3-hs-usb-phy";
> - reg = <0x100f8800 0x30>;
> - clocks = < USB30_0_UTMI_CLK>;
> - clock-names = "ref";
> - #phy-cells = <0>;
> -
> + compatible = "qcom,qusb2-v2-phy";
> + ...
>   };
>  
>   ss_phy: phy@100f8830 {
> - compatible = "qcom,dwc3-ss-usb-phy";
> - reg = <0x100f8830 0x30>;
> - clocks = < USB30_0_MASTER_CLK>;
> - clock-names = "ref";
> - #phy-cells = <0>;
> -
> + compatible = "qcom,qmp-v3-usb3-phy";
> + ...
>  

Re: [PATCH 3/3] USB: musb: dsps: propagate device-tree node

2018-04-16 Thread Bin Liu
Johan,

On Fri, Apr 13, 2018 at 05:15:05PM +0200, Johan Hovold wrote:
> To be able to use DSPS-based controllers with device-tree descriptions
> of the USB topology, we need to associate the glue device's device-tree
> node with the child controller device.
> 
> Note that this can also be used to eventually let USB core manage
> generic phys.
> 
> Also note that the other glue drivers will require similar changes to be
> able to describe their buses in DT.
> 
> Signed-off-by: Johan Hovold 

I will take other two patches for v4.17 rc cycles, but is there any
problem if I take this patch for v4.18-rc1?

Regards,
-Bin.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/4] dt-bindings: Document the DT bindings for lan78xx

2018-04-16 Thread Rob Herring
On Thu, Apr 12, 2018 at 02:55:36PM +0100, Phil Elwell wrote:
> The Microchip LAN78XX family of devices are Ethernet controllers with
> a USB interface. Despite being discoverable devices it can be useful to
> be able to configure them from Device Tree, particularly in low-cost
> applications without an EEPROM or programmed OTP.
> 
> Document the supported properties in a bindings file, adding it to
> MAINTAINERS at the same time.
> 
> Signed-off-by: Phil Elwell 
> ---
>  .../devicetree/bindings/net/microchip,lan78xx.txt  | 44 
> ++
>  MAINTAINERS|  1 +
>  2 files changed, 45 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/net/microchip,lan78xx.txt
> 
> diff --git a/Documentation/devicetree/bindings/net/microchip,lan78xx.txt 
> b/Documentation/devicetree/bindings/net/microchip,lan78xx.txt
> new file mode 100644
> index 000..e7d7850
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/microchip,lan78xx.txt
> @@ -0,0 +1,44 @@
> +Microchip LAN78xx Gigabit Ethernet controller
> +
> +The LAN78XX devices are usually configured by programming their OTP or with
> +an external EEPROM, but some platforms (e.g. Raspberry Pi 3 B+) have neither.
> +
> +Please refer to ethernet.txt for a description of common Ethernet bindings.
> +
> +Optional properties:
> +- microchip,eee-enabled: if present, enable Energy Efficient Ethernet 
> support;

I see we have some flags for broken EEE, but nothing already defined to 
enable EEE. Seems like this should either be a user option (therefore 
not in DT) or we should use the broken EEE properties if this is h/w 
dependent.

> +- microchip,led-modes: a two-element vector, with each element configuring
> +  the operating mode of an LED. The values supported by the device are;
> +  0: Link/Activity
> +  1: Link1000/Activity
> +  2: Link100/Activity
> +  3: Link10/Activity
> +  4: Link100/1000/Activity
> +  5: Link10/1000/Activity
> +  6: Link10/100/Activity
> +  7: RESERVED
> +  8: Duplex/Collision
> +  9: Collision
> +  10: Activity
> +  11: RESERVED
> +  12: Auto-negotiation Fault
> +  13: RESERVED
> +  14: Off
> +  15: On
> +- microchip,tx-lpi-timer: the delay (in microseconds) between the TX fifo
> +  becoming empty and invoking Low Power Idles (default 600).

Needs a unit suffix as defined in property-units.txt.

> +
> +Example:
> +
> + /* Standard configuration for a Raspberry Pi 3 B+ */
> + ethernet: usbether@1 {
> + compatible = "usb424,7800";
> + reg = <1>;
> + microchip,eee-enabled;
> + microchip,tx-lpi-timer = <600>;
> + /*
> +  * led0 = 1:link1000/activity
> +  * led1 = 6:link10/100/activity
> +  */
> + microchip,led-modes = <1 6>;
> + };
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 2328eed..b637aad 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -14482,6 +14482,7 @@ M:Microchip Linux Driver Support 
> 
>  L:   net...@vger.kernel.org
>  S:   Maintained
>  F:   drivers/net/usb/lan78xx.*
> +F:   Documentation/devicetree/bindings/net/microchip,lan78xx.txt
>  
>  USB MASS STORAGE DRIVER
>  M:   Alan Stern 
> -- 
> 2.7.4
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 04/11] usb: musb: remove some register access wrapper functions

2018-04-16 Thread Bin Liu
The following wrappers were defined because of Blackfin support. Now
Blackfin support is removed, these wrappers are no longer needed, so
remove them.

musb_write_txfifosz
musb_write_txfifoadd
musb_write_rxfifosz
musb_write_rxfifoadd
musb_write_ulpi_buscontrol
musb_read_txfifosz
musb_read_txfifoadd
musb_read_rxfifosz
musb_read_rxfifoadd
musb_read_ulpi_buscontrol
musb_read_hwvers

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_core.c | 42 -
 drivers/usb/musb/musb_regs.h | 55 
 2 files changed, 21 insertions(+), 76 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 4ff6da1aa775..d3f9f7e5f353 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1240,25 +1240,25 @@ void musb_stop(struct musb *musb)
/* REVISIT error check:  be sure ep0 can both rx and tx ... */
switch (cfg->style) {
case FIFO_TX:
-   musb_write_txfifosz(mbase, c_size);
-   musb_write_txfifoadd(mbase, c_off);
+   musb_writeb(mbase, MUSB_TXFIFOSZ, c_size);
+   musb_writew(mbase, MUSB_TXFIFOADD, c_off);
hw_ep->tx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
hw_ep->max_packet_sz_tx = maxpacket;
break;
case FIFO_RX:
-   musb_write_rxfifosz(mbase, c_size);
-   musb_write_rxfifoadd(mbase, c_off);
+   musb_writeb(mbase, MUSB_RXFIFOSZ, c_size);
+   musb_writew(mbase, MUSB_RXFIFOADD, c_off);
hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
hw_ep->max_packet_sz_rx = maxpacket;
break;
case FIFO_RXTX:
-   musb_write_txfifosz(mbase, c_size);
-   musb_write_txfifoadd(mbase, c_off);
+   musb_writeb(mbase, MUSB_TXFIFOSZ, c_size);
+   musb_writew(mbase, MUSB_TXFIFOADD, c_off);
hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
hw_ep->max_packet_sz_rx = maxpacket;
 
-   musb_write_rxfifosz(mbase, c_size);
-   musb_write_rxfifoadd(mbase, c_off);
+   musb_writeb(mbase, MUSB_RXFIFOSZ, c_size);
+   musb_writew(mbase, MUSB_RXFIFOADD, c_off);
hw_ep->tx_double_buffered = hw_ep->rx_double_buffered;
hw_ep->max_packet_sz_tx = maxpacket;
 
@@ -1466,7 +1466,7 @@ static int musb_core_init(u16 musb_type, struct musb 
*musb)
}
 
/* log release info */
-   musb->hwvers = musb_read_hwvers(mbase);
+   musb->hwvers = musb_readw(mbase, MUSB_HWVERS);
pr_debug("%s: %sHDRC RTL version %d.%d%s\n",
 musb_driver_name, type, MUSB_HWVERS_MAJOR(musb->hwvers),
 MUSB_HWVERS_MINOR(musb->hwvers),
@@ -2311,9 +2311,9 @@ static void musb_deassert_reset(struct work_struct *work)
 
/* program PHY to use external vBus if required */
if (plat->extvbus) {
-   u8 busctl = musb_read_ulpi_buscontrol(musb->mregs);
+   u8 busctl = musb_readb(musb->mregs, MUSB_ULPI_BUSCONTROL);
busctl |= MUSB_ULPI_USE_EXTVBUS;
-   musb_write_ulpi_buscontrol(musb->mregs, busctl);
+   musb_writeb(musb->mregs, MUSB_ULPI_BUSCONTROL, busctl);
}
 
if (musb->xceiv->otg->default_a) {
@@ -2482,7 +2482,7 @@ static void musb_save_context(struct musb *musb)
 
musb->context.frame = musb_readw(musb_base, MUSB_FRAME);
musb->context.testmode = musb_readb(musb_base, MUSB_TESTMODE);
-   musb->context.busctl = musb_read_ulpi_buscontrol(musb->mregs);
+   musb->context.busctl = musb_readb(musb_base, MUSB_ULPI_BUSCONTROL);
musb->context.power = musb_readb(musb_base, MUSB_POWER);
musb->context.intrusbe = musb_readb(musb_base, MUSB_INTRUSBE);
musb->context.index = musb_readb(musb_base, MUSB_INDEX);
@@ -2511,13 +2511,13 @@ static void musb_save_context(struct musb *musb)
 
if (musb->dyn_fifo) {
musb->context.index_regs[i].txfifoadd =
-   musb_read_txfifoadd(musb_base);
+   musb_readw(musb_base, MUSB_TXFIFOADD);
musb->context.index_regs[i].rxfifoadd =
-   musb_read_rxfifoadd(musb_base);
+   musb_readw(musb_base, MUSB_RXFIFOADD);
musb->context.index_regs[i].txfifosz =
-   musb_read_txfifosz(musb_base);
+   musb_readb(musb_base, MUSB_TXFIFOSZ);
musb->context.index_regs[i].rxfifosz =
-   musb_read_rxfifosz(musb_base);
+

[PATCH 10/11] usb: musb: remove references to default_a of struct usb_otg

2018-04-16 Thread Bin Liu
musb drivers do not use the otg fsm framework, so referencing to
otg->default_a doesn't have any effect, so remove the references.

But tusb6010 glue driver uses it locally to control the vbus power, so
keep the references in tusb6010 only.

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/am35x.c   |  3 ---
 drivers/usb/musb/da8xx.c   |  2 --
 drivers/usb/musb/davinci.c | 49 --
 drivers/usb/musb/musb_core.c   |  9 ++--
 drivers/usb/musb/musb_dsps.c   |  2 --
 drivers/usb/musb/musb_gadget.c |  1 -
 drivers/usb/musb/musb_host.c   |  1 -
 drivers/usb/musb/omap2430.c|  5 -
 drivers/usb/musb/sunxi.c   |  2 --
 drivers/usb/musb/ux500.c   |  2 --
 10 files changed, 25 insertions(+), 51 deletions(-)

diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 0ad664efda6b..660641ab1545 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -201,7 +201,6 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
struct device *dev = musb->controller;
struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
struct omap_musb_board_data *data = plat->board_data;
-   struct usb_otg *otg = musb->xceiv->otg;
unsigned long flags;
irqreturn_t ret = IRQ_NONE;
u32 epintr, usbintr;
@@ -264,14 +263,12 @@ static irqreturn_t am35x_musb_interrupt(int irq, void 
*hci)
WARNING("VBUS error workaround (delay coming)\n");
} else if (drvvbus) {
MUSB_HST_MODE(musb);
-   otg->default_a = 1;
musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
portstate(musb->port1_status |= USB_PORT_STAT_POWER);
del_timer(>dev_timer);
} else {
musb->is_active = 0;
MUSB_DEV_MODE(musb);
-   otg->default_a = 0;
musb->xceiv->otg->state = OTG_STATE_B_IDLE;
portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
}
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index b8295ce7c4fe..0e5929e81d26 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -280,7 +280,6 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
WARNING("VBUS error workaround (delay coming)\n");
} else if (drvvbus) {
MUSB_HST_MODE(musb);
-   otg->default_a = 1;
musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
portstate(musb->port1_status |= USB_PORT_STAT_POWER);
del_timer(>dev_timer);
@@ -295,7 +294,6 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
 */
musb->is_active = 0;
MUSB_DEV_MODE(musb);
-   otg->default_a = 0;
musb->xceiv->otg->state = OTG_STATE_B_IDLE;
portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
}
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 2ad39dcd2f4c..fb6bbd254ab7 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -311,14 +311,12 @@ static irqreturn_t davinci_musb_interrupt(int irq, void 
*__hci)
WARNING("VBUS error workaround (delay coming)\n");
} else if (drvvbus) {
MUSB_HST_MODE(musb);
-   otg->default_a = 1;
musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
portstate(musb->port1_status |= USB_PORT_STAT_POWER);
del_timer(>dev_timer);
} else {
musb->is_active = 0;
MUSB_DEV_MODE(musb);
-   otg->default_a = 0;
musb->xceiv->otg->state = OTG_STATE_B_IDLE;
portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
}
@@ -425,6 +423,9 @@ static int davinci_musb_init(struct musb *musb)
 
 static int davinci_musb_exit(struct musb *musb)
 {
+   int maxdelay = 30;
+   u8  devctl, warn = 0;
+
del_timer_sync(>dev_timer);
 
/* force VBUS off */
@@ -438,31 +439,27 @@ static int davinci_musb_exit(struct musb *musb)
 
davinci_musb_source_power(musb, 0 /*off*/, 1);
 
-   /* delay, to avoid problems with module reload */
-   if (musb->xceiv->otg->default_a) {
-   int maxdelay = 30;
-   u8  devctl, warn = 0;
+   /*
+* delay, to avoid problems with module reload.
+* if there's no peripheral connected, this can take a
+* long time to fall, especially on EVM with huge C133.
+*/
+   do {
+

[PATCH 09/11] usb: musb: break the huge isr musb_stage0_irq() into small functions

2018-04-16 Thread Bin Liu
musb_stage0_irq() is 400+ lines long. Break its interrupt events
handling into each individual functions to make it easy to read.

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_core.c | 730 +++
 1 file changed, 384 insertions(+), 346 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index ce54f48314e1..a3a716197dc1 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -523,6 +523,383 @@ void musb_hnp_stop(struct musb *musb)
 
 static void musb_recover_from_babble(struct musb *musb);
 
+static void musb_handle_intr_resume(struct musb *musb, u8 devctl)
+{
+   musb_dbg(musb, "RESUME (%s)",
+   usb_otg_state_string(musb->xceiv->otg->state));
+
+   if (devctl & MUSB_DEVCTL_HM) {
+   switch (musb->xceiv->otg->state) {
+   case OTG_STATE_A_SUSPEND:
+   /* remote wakeup? */
+   musb->port1_status |=
+   (USB_PORT_STAT_C_SUSPEND << 16)
+   | MUSB_PORT_STAT_RESUME;
+   musb->rh_timer = jiffies
+   + msecs_to_jiffies(USB_RESUME_TIMEOUT);
+   musb->xceiv->otg->state = OTG_STATE_A_HOST;
+   musb->is_active = 1;
+   musb_host_resume_root_hub(musb);
+   schedule_delayed_work(>finish_resume_work,
+   msecs_to_jiffies(USB_RESUME_TIMEOUT));
+   break;
+   case OTG_STATE_B_WAIT_ACON:
+   musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
+   musb->is_active = 1;
+   MUSB_DEV_MODE(musb);
+   break;
+   default:
+   WARNING("bogus %s RESUME (%s)\n",
+   "host",
+   usb_otg_state_string(musb->xceiv->otg->state));
+   }
+   } else {
+   switch (musb->xceiv->otg->state) {
+   case OTG_STATE_A_SUSPEND:
+   /* possibly DISCONNECT is upcoming */
+   musb->xceiv->otg->state = OTG_STATE_A_HOST;
+   musb_host_resume_root_hub(musb);
+   break;
+   case OTG_STATE_B_WAIT_ACON:
+   case OTG_STATE_B_PERIPHERAL:
+   /* disconnect while suspended?  we may
+* not get a disconnect irq...
+*/
+   if ((devctl & MUSB_DEVCTL_VBUS)
+   != (3 << MUSB_DEVCTL_VBUS_SHIFT)
+   ) {
+   musb->int_usb |= MUSB_INTR_DISCONNECT;
+   musb->int_usb &= ~MUSB_INTR_SUSPEND;
+   break;
+   }
+   musb_g_resume(musb);
+   break;
+   case OTG_STATE_B_IDLE:
+   musb->int_usb &= ~MUSB_INTR_SUSPEND;
+   break;
+   default:
+   WARNING("bogus %s RESUME (%s)\n",
+   "peripheral",
+   usb_otg_state_string(musb->xceiv->otg->state));
+   }
+   }
+}
+
+/* return IRQ_HANDLED to tell the caller to return immediately */
+static irqreturn_t musb_handle_intr_sessreq(struct musb *musb, u8 devctl)
+{
+   void __iomem *mbase = musb->mregs;
+
+   if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS
+   && (devctl & MUSB_DEVCTL_BDEVICE)) {
+   musb_dbg(musb, "SessReq while on B state");
+   return IRQ_HANDLED;
+   }
+
+   musb_dbg(musb, "SESSION_REQUEST (%s)",
+   usb_otg_state_string(musb->xceiv->otg->state));
+
+   /* IRQ arrives from ID pin sense or (later, if VBUS power
+* is removed) SRP.  responses are time critical:
+*  - turn on VBUS (with silicon-specific mechanism)
+*  - go through A_WAIT_VRISE
+*  - ... to A_WAIT_BCON.
+* a_wait_vrise_tmout triggers VBUS_ERROR transitions
+*/
+   musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
+   musb->ep0_stage = MUSB_EP0_START;
+   musb->xceiv->otg->state = OTG_STATE_A_IDLE;
+   MUSB_HST_MODE(musb);
+   musb_platform_set_vbus(musb, 1);
+
+   return IRQ_NONE;
+}
+
+static void musb_handle_intr_vbuserr(struct musb *musb, u8 devctl)
+{
+   int ignore = 0;
+
+   /* During connection as an A-Device, we may see a short
+* current spikes causing voltage drop, because of cable
+* and peripheral capacitance combined with vbus draw.
+* (So: less common with truly self-powered devices, where
+* vbus doesn't act like a power supply.)
+   

[PATCH 11/11] usb: musb: disable otg protocol support

2018-04-16 Thread Bin Liu
As decided in the discussion [1] we are deleting the otg protocol
support from the musb drivers.

First this patch disables the flags for enabling the otg protocols. We
will later gradually delete the otg protocol code from the musb drivers.

[1] https://www.spinics.net/lists/linux-usb/msg167003.html

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_gadget.c | 5 +
 drivers/usb/musb/musb_host.c   | 3 ++-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 63e9d4a4395f..b0d86d895420 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1797,11 +1797,8 @@ int musb_gadget_setup(struct musb *musb)
 
/* this "gadget" abstracts/virtualizes the controller */
musb->g.name = musb_driver_name;
-#if IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE)
-   musb->g.is_otg = 1;
-#elif IS_ENABLED(CONFIG_USB_MUSB_GADGET)
+   /* don't support otg protocols */
musb->g.is_otg = 0;
-#endif
INIT_DELAYED_WORK(>gadget_work, musb_gadget_work);
musb_g_init_endpoints(musb);
 
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 34b97cae5ec1..e50438ae241e 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -2750,7 +2750,8 @@ int musb_host_setup(struct musb *musb, int power_budget)
musb->xceiv->otg->state = OTG_STATE_A_IDLE;
}
otg_set_host(musb->xceiv->otg, >self);
-   hcd->self.otg_port = 1;
+   /* don't support otg protocols */
+   hcd->self.otg_port = 0;
musb->xceiv->otg->host = >self;
hcd->power_budget = 2 * (power_budget ? : 250);
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/11] usb: musb: remove duplicated quirks flag

2018-04-16 Thread Bin Liu
Both musb_io and musb_platform_ops in struct musb define a quirks flag
for the same purpose.  Let's remove the one in struct musb_io, and use
that in struct musb_platform_ops instead.

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_core.c   | 10 --
 drivers/usb/musb/musb_cppi41.c |  4 ++--
 drivers/usb/musb/musb_dma.h| 10 +-
 drivers/usb/musb/musb_io.h |  2 --
 4 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index d3f9f7e5f353..84f25a2b078d 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1493,7 +1493,7 @@ static int musb_core_init(u16 musb_type, struct musb 
*musb)
 
hw_ep->fifo = musb->io.fifo_offset(i) + mbase;
 #if IS_ENABLED(CONFIG_USB_MUSB_TUSB6010)
-   if (musb->io.quirks & MUSB_IN_TUSB) {
+   if (musb->ops->quirks & MUSB_IN_TUSB) {
hw_ep->fifo_async = musb->async + 0x400 +
musb->io.fifo_offset(i);
hw_ep->fifo_sync = musb->sync + 0x400 +
@@ -2176,11 +2176,9 @@ static void musb_deassert_reset(struct work_struct *work)
goto fail2;
}
 
-   if (musb->ops->quirks)
-   musb->io.quirks = musb->ops->quirks;
 
/* Most devices use indexed offset or flat offset */
-   if (musb->io.quirks & MUSB_INDEXED_EP) {
+   if (musb->ops->quirks & MUSB_INDEXED_EP) {
musb->io.ep_offset = musb_indexed_ep_offset;
musb->io.ep_select = musb_indexed_ep_select;
} else {
@@ -2188,7 +2186,7 @@ static void musb_deassert_reset(struct work_struct *work)
musb->io.ep_select = musb_flat_ep_select;
}
 
-   if (musb->io.quirks & MUSB_G_NO_SKB_RESERVE)
+   if (musb->ops->quirks & MUSB_G_NO_SKB_RESERVE)
musb->g.quirk_avoids_skb_reserve = 1;
 
/* At least tusb6010 has its own offsets */
@@ -2647,7 +2645,7 @@ static int musb_suspend(struct device *dev)
;
musb->flush_irq_work = false;
 
-   if (!(musb->io.quirks & MUSB_PRESERVE_SESSION))
+   if (!(musb->ops->quirks & MUSB_PRESERVE_SESSION))
musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
 
WARN_ON(!list_empty(>pending_list));
diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c
index d0dd4f470bbe..7fbb8a307145 100644
--- a/drivers/usb/musb/musb_cppi41.c
+++ b/drivers/usb/musb/musb_cppi41.c
@@ -614,7 +614,7 @@ static int cppi41_dma_channel_abort(struct dma_channel 
*channel)
}
 
/* DA8xx Advisory 2.3.27: wait 250 ms before to start the teardown */
-   if (musb->io.quirks & MUSB_DA8XX)
+   if (musb->ops->quirks & MUSB_DA8XX)
mdelay(250);
 
tdbit = 1 << cppi41_channel->port_num;
@@ -773,7 +773,7 @@ struct dma_controller *
controller->controller.is_compatible = cppi41_is_compatible;
controller->controller.musb = musb;
 
-   if (musb->io.quirks & MUSB_DA8XX) {
+   if (musb->ops->quirks & MUSB_DA8XX) {
controller->tdown_reg = DA8XX_USB_TEARDOWN;
controller->autoreq_reg = DA8XX_USB_AUTOREQ;
controller->set_dma_mode = da8xx_set_dma_mode;
diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index 0fc8cd0c2a5c..8f60271c0a9d 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -44,31 +44,31 @@
 #endif
 
 #ifdef CONFIG_USB_UX500_DMA
-#define musb_dma_ux500(musb)   (musb->io.quirks & MUSB_DMA_UX500)
+#define musb_dma_ux500(musb)   (musb->ops->quirks & MUSB_DMA_UX500)
 #else
 #define musb_dma_ux500(musb)   0
 #endif
 
 #ifdef CONFIG_USB_TI_CPPI41_DMA
-#define musb_dma_cppi41(musb)  (musb->io.quirks & MUSB_DMA_CPPI41)
+#define musb_dma_cppi41(musb)  (musb->ops->quirks & MUSB_DMA_CPPI41)
 #else
 #define musb_dma_cppi41(musb)  0
 #endif
 
 #ifdef CONFIG_USB_TI_CPPI_DMA
-#define musb_dma_cppi(musb)(musb->io.quirks & MUSB_DMA_CPPI)
+#define musb_dma_cppi(musb)(musb->ops->quirks & MUSB_DMA_CPPI)
 #else
 #define musb_dma_cppi(musb)0
 #endif
 
 #ifdef CONFIG_USB_TUSB_OMAP_DMA
-#define tusb_dma_omap(musb)(musb->io.quirks & MUSB_DMA_TUSB_OMAP)
+#define tusb_dma_omap(musb)(musb->ops->quirks & MUSB_DMA_TUSB_OMAP)
 #else
 #define tusb_dma_omap(musb)0
 #endif
 
 #ifdef CONFIG_USB_INVENTRA_DMA
-#define musb_dma_inventra(musb)(musb->io.quirks & 
MUSB_DMA_INVENTRA)
+#define musb_dma_inventra(musb)(musb->ops->quirks & 
MUSB_DMA_INVENTRA)
 #else
 #define musb_dma_inventra(musb)0
 #endif
diff --git a/drivers/usb/musb/musb_io.h b/drivers/usb/musb/musb_io.h
index b4d870b836aa..8058a58092cf 100644
--- a/drivers/usb/musb/musb_io.h
+++ b/drivers/usb/musb/musb_io.h
@@ -16,7 +16,6 @@
 
 /**
  * struct musb_io - IO 

[PATCH 07/11] usb: musb: remove duplicated port mode enum

2018-04-16 Thread Bin Liu
include/linux/usb/musb.h already defines enum for musb port mode, so
remove the duplicate in musb_core.h and use the definition in musb.h.

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_core.c| 8 
 drivers/usb/musb/musb_core.h| 8 +---
 drivers/usb/musb/musb_dsps.c| 6 +++---
 drivers/usb/musb/musb_gadget.c  | 2 +-
 drivers/usb/musb/musb_host.c| 4 ++--
 drivers/usb/musb/musb_virthub.c | 2 +-
 drivers/usb/musb/sunxi.c| 8 
 7 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 84f25a2b078d..ce54f48314e1 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1038,7 +1038,7 @@ void musb_start(struct musb *musb)
 * (b) vbus present/connect IRQ, peripheral mode;
 * (c) peripheral initiates, using SRP
 */
-   if (musb->port_mode != MUSB_PORT_MODE_HOST &&
+   if (musb->port_mode != MUSB_HOST &&
musb->xceiv->otg->state != OTG_STATE_A_WAIT_BCON &&
(devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
musb->is_active = 1;
@@ -2323,19 +2323,19 @@ static void musb_deassert_reset(struct work_struct 
*work)
}
 
switch (musb->port_mode) {
-   case MUSB_PORT_MODE_HOST:
+   case MUSB_HOST:
status = musb_host_setup(musb, plat->power);
if (status < 0)
goto fail3;
status = musb_platform_set_mode(musb, MUSB_HOST);
break;
-   case MUSB_PORT_MODE_GADGET:
+   case MUSB_PERIPHERAL:
status = musb_gadget_setup(musb);
if (status < 0)
goto fail3;
status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
break;
-   case MUSB_PORT_MODE_DUAL_ROLE:
+   case MUSB_OTG:
status = musb_host_setup(musb, plat->power);
if (status < 0)
goto fail3;
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index f57323e50e44..04203b7126d5 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -53,12 +53,6 @@
 #define is_peripheral_active(m)(!(m)->is_host)
 #define is_host_active(m)  ((m)->is_host)
 
-enum {
-   MUSB_PORT_MODE_HOST = 1,
-   MUSB_PORT_MODE_GADGET,
-   MUSB_PORT_MODE_DUAL_ROLE,
-};
-
 /** CONSTANTS /
 
 #ifndef MUSB_C_NUM_EPS
@@ -351,7 +345,7 @@ struct musb {
 
u8  min_power;  /* vbus for periph, in mA/2 */
 
-   int port_mode;  /* MUSB_PORT_MODE_* */
+   enum musb_mode  port_mode;
boolsession;
unsigned long   quirk_retries;
boolis_host;
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index d077eefb5e2c..951ac63f3526 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -183,7 +183,7 @@ static void dsps_musb_enable(struct musb *musb)
musb_writel(reg_base, wrp->coreintr_set, coremask);
/* start polling for ID change in dual-role idle mode */
if (musb->xceiv->otg->state == OTG_STATE_B_IDLE &&
-   musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
+   musb->port_mode == MUSB_OTG)
dsps_mod_timer(glue, -1);
 }
 
@@ -231,7 +231,7 @@ static int dsps_check_status(struct musb *musb, void 
*unused)
break;
case OTG_STATE_A_WAIT_BCON:
/* keep VBUS on for host-only mode */
-   if (musb->port_mode == MUSB_PORT_MODE_HOST) {
+   if (musb->port_mode == MUSB_HOST) {
dsps_mod_timer_optional(glue);
break;
}
@@ -1030,7 +1030,7 @@ static int dsps_resume(struct device *dev)
musb_writel(mbase, wrp->tx_mode, glue->context.tx_mode);
musb_writel(mbase, wrp->rx_mode, glue->context.rx_mode);
if (musb->xceiv->otg->state == OTG_STATE_B_IDLE &&
-   musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
+   musb->port_mode == MUSB_OTG)
dsps_mod_timer(glue, -1);
 
pm_runtime_put(dev);
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index e564695c6c8d..967e8e2f6318 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1822,7 +1822,7 @@ int musb_gadget_setup(struct musb *musb)
 
 void musb_gadget_cleanup(struct musb *musb)
 {
-   if (musb->port_mode == MUSB_PORT_MODE_HOST)
+   if (musb->port_mode == MUSB_HOST)
return;
 
cancel_delayed_work_sync(>gadget_work);
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 3a8451a15f7f..e9954fbc9728 100644
--- 

[PATCH 08/11] usb: musb: remove unused members in struct musb_hdrc_config

2018-04-16 Thread Bin Liu
The following members in struct musb_hdrc_config are not used,
so remove them.

soft_con
utm_16
big_endian
mult_bulk_tx
mult_bulk_rx
high_iso_tx
high_iso_rx
dma
dma_channels
dyn_fifo_size
vendor_ctrl
vendor_stat
vendor_req
dma_req_chan
musb_hdrc_eps_bits

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/sunxi.c |  4 
 include/linux/usb/musb.h | 15 ---
 2 files changed, 19 deletions(-)

diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index 8f7d378b7e7e..62ab2ca03779 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -651,10 +651,8 @@ static void sunxi_musb_writew(void __iomem *addr, unsigned 
offset, u16 data)
.fifo_cfg_size  = ARRAY_SIZE(sunxi_musb_mode_cfg),
.multipoint = true,
.dyn_fifo   = true,
-   .soft_con   = true,
.num_eps= SUNXI_MUSB_MAX_EP_NUM,
.ram_bits   = SUNXI_MUSB_RAM_BITS,
-   .dma= 0,
 };
 
 static struct musb_hdrc_config sunxi_musb_hdrc_config_h3 = {
@@ -662,10 +660,8 @@ static void sunxi_musb_writew(void __iomem *addr, unsigned 
offset, u16 data)
.fifo_cfg_size  = ARRAY_SIZE(sunxi_musb_mode_cfg_h3),
.multipoint = true,
.dyn_fifo   = true,
-   .soft_con   = true,
.num_eps= SUNXI_MUSB_MAX_EP_NUM_H3,
.ram_bits   = SUNXI_MUSB_RAM_BITS,
-   .dma= 0,
 };
 
 
diff --git a/include/linux/usb/musb.h b/include/linux/usb/musb.h
index 9eb908a98033..fc6c77918481 100644
--- a/include/linux/usb/musb.h
+++ b/include/linux/usb/musb.h
@@ -67,28 +67,13 @@ struct musb_hdrc_config {
/* MUSB configuration-specific details */
unsignedmultipoint:1;   /* multipoint device */
unsigneddyn_fifo:1 __deprecated; /* supports dynamic fifo 
sizing */
-   unsignedsoft_con:1 __deprecated; /* soft connect required */
-   unsignedutm_16:1 __deprecated; /* utm data witdh is 16 bits */
-   unsignedbig_endian:1;   /* true if CPU uses big-endian */
-   unsignedmult_bulk_tx:1; /* Tx ep required for multbulk pkts */
-   unsignedmult_bulk_rx:1; /* Rx ep required for multbulk pkts */
-   unsignedhigh_iso_tx:1;  /* Tx ep required for HB iso */
-   unsignedhigh_iso_rx:1;  /* Rx ep required for HD iso */
-   unsigneddma:1 __deprecated; /* supports DMA */
-   unsignedvendor_req:1 __deprecated; /* vendor registers required 
*/
 
/* need to explicitly de-assert the port reset after resume? */
unsignedhost_port_deassert_reset_at_resume:1;
 
u8  num_eps;/* number of endpoints _with_ ep0 */
-   u8  dma_channels __deprecated; /* number of dma channels */
-   u8  dyn_fifo_size;  /* dynamic size in bytes */
-   u8  vendor_ctrl __deprecated; /* vendor control reg width */
-   u8  vendor_stat __deprecated; /* vendor status reg witdh */
-   u8  dma_req_chan __deprecated; /* bitmask for required dma 
channels */
u8  ram_bits;   /* ram address size */
 
-   struct musb_hdrc_eps_bits *eps_bits __deprecated;
u32 maximum_speed;
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/11] usb: musb: dsps: remove duplicated get_musb_port_mode()

2018-04-16 Thread Bin Liu
musb_core already has musb_get_mode(), so remove the duplicate from
musb_dsps.c.

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_dsps.c | 21 +
 1 file changed, 1 insertion(+), 20 deletions(-)

diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 05a679d5e3a2..d077eefb5e2c 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -731,25 +731,6 @@ static int get_int_prop(struct device_node *dn, const char 
*s)
return val;
 }
 
-static int get_musb_port_mode(struct device *dev)
-{
-   enum usb_dr_mode mode;
-
-   mode = usb_get_dr_mode(dev);
-   switch (mode) {
-   case USB_DR_MODE_HOST:
-   return MUSB_PORT_MODE_HOST;
-
-   case USB_DR_MODE_PERIPHERAL:
-   return MUSB_PORT_MODE_GADGET;
-
-   case USB_DR_MODE_UNKNOWN:
-   case USB_DR_MODE_OTG:
-   default:
-   return MUSB_PORT_MODE_DUAL_ROLE;
-   }
-}
-
 static int dsps_create_musb_pdev(struct dsps_glue *glue,
struct platform_device *parent)
 {
@@ -809,7 +790,7 @@ static int dsps_create_musb_pdev(struct dsps_glue *glue,
config->num_eps = get_int_prop(dn, "mentor,num-eps");
config->ram_bits = get_int_prop(dn, "mentor,ram-bits");
config->host_port_deassert_reset_at_resume = 1;
-   pdata.mode = get_musb_port_mode(dev);
+   pdata.mode = musb_get_mode(dev);
/* DT keeps this entry in mA, musb expects it as per USB spec */
pdata.power = get_int_prop(dn, "mentor,power") / 2;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 00/11] usb: musb: cleanup

2018-04-16 Thread Bin Liu
Hi,

Blackfin arch support is removed in v4.17-rc1, now some code in musb drivers,
which was used for Blackfin handling, can be cleaned up.

This series also removes some duplicated or dead code in musb drivers,
and disables OTG protocol support as well per discussion in [1].

[1] https://www.spinics.net/lists/linux-usb/msg167003.html

Regards,
-Bin.


Bin Liu (11):
  usb: musb: merge musbhsdma.h into musbhsdma.c
  usb: musb: remove readl/writel from struct musb_platform_ops
  usb: musb: remove adjust_channel_params() callback from musb_platform_ops
  usb: musb: remove some register access wrapper functions
  usb: musb: remove duplicated quirks flag
  usb: musb: dsps: remove duplicated get_musb_port_mode()
  usb: musb: remove duplicated port mode enum
  usb: musb: remove unused members in struct musb_hdrc_config
  usb: musb: break the huge isr musb_stage0_irq() into small functions
  usb: musb: remove references to default_a of struct usb_otg
  usb: musb: disable otg protocol support

 drivers/usb/musb/am35x.c|   3 -
 drivers/usb/musb/da8xx.c|   2 -
 drivers/usb/musb/davinci.c  |  49 ++-
 drivers/usb/musb/musb_core.c| 833 
 drivers/usb/musb/musb_core.h|  16 +-
 drivers/usb/musb/musb_cppi41.c  |   4 +-
 drivers/usb/musb/musb_dma.h |  10 +-
 drivers/usb/musb/musb_dsps.c|  29 +-
 drivers/usb/musb/musb_gadget.c  |   8 +-
 drivers/usb/musb/musb_host.c|   8 +-
 drivers/usb/musb/musb_io.h  |   6 +-
 drivers/usb/musb/musb_regs.h|  55 ---
 drivers/usb/musb/musb_virthub.c |   2 +-
 drivers/usb/musb/musbhsdma.c|  74 +++-
 drivers/usb/musb/musbhsdma.h|  72 
 drivers/usb/musb/omap2430.c |   5 -
 drivers/usb/musb/sunxi.c|  14 +-
 drivers/usb/musb/ux500.c|   2 -
 include/linux/usb/musb.h|  15 -
 19 files changed, 540 insertions(+), 667 deletions(-)
 delete mode 100644 drivers/usb/musb/musbhsdma.h

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/11] usb: musb: remove readl/writel from struct musb_platform_ops

2018-04-16 Thread Bin Liu
Now Blackfin support is removed, we no longer need function pointers for
musb_readl() and musb_writel().

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_core.c | 34 --
 drivers/usb/musb/musb_core.h |  4 
 drivers/usb/musb/musb_io.h   |  4 ++--
 3 files changed, 14 insertions(+), 28 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index fb5e4523dc28..4ff6da1aa775 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -274,20 +274,6 @@ static void musb_default_writew(void __iomem *addr, 
unsigned offset, u16 data)
__raw_writew(data, addr + offset);
 }
 
-static u32 musb_default_readl(const void __iomem *addr, unsigned offset)
-{
-   u32 data = __raw_readl(addr + offset);
-
-   trace_musb_readl(__builtin_return_address(0), addr, offset, data);
-   return data;
-}
-
-static void musb_default_writel(void __iomem *addr, unsigned offset, u32 data)
-{
-   trace_musb_writel(__builtin_return_address(0), addr, offset, data);
-   __raw_writel(data, addr + offset);
-}
-
 /*
  * Load an endpoint's FIFO
  */
@@ -390,10 +376,20 @@ static void musb_default_read_fifo(struct musb_hw_ep 
*hw_ep, u16 len, u8 *dst)
 void (*musb_writew)(void __iomem *addr, unsigned offset, u16 data);
 EXPORT_SYMBOL_GPL(musb_writew);
 
-u32 (*musb_readl)(const void __iomem *addr, unsigned offset);
+u32 musb_readl(const void __iomem *addr, unsigned offset)
+{
+   u32 data = __raw_readl(addr + offset);
+
+   trace_musb_readl(__builtin_return_address(0), addr, offset, data);
+   return data;
+}
 EXPORT_SYMBOL_GPL(musb_readl);
 
-void (*musb_writel)(void __iomem *addr, unsigned offset, u32 data);
+void musb_writel(void __iomem *addr, unsigned offset, u32 data)
+{
+   trace_musb_writel(__builtin_return_address(0), addr, offset, data);
+   __raw_writel(data, addr + offset);
+}
 EXPORT_SYMBOL_GPL(musb_writel);
 
 #ifndef CONFIG_MUSB_PIO_ONLY
@@ -2158,8 +2154,6 @@ static void musb_deassert_reset(struct work_struct *work)
musb_writeb = musb_default_writeb;
musb_readw = musb_default_readw;
musb_writew = musb_default_writew;
-   musb_readl = musb_default_readl;
-   musb_writel = musb_default_writel;
 
/* The musb_platform_init() call:
 *   - adjusts musb->mregs
@@ -2226,10 +2220,6 @@ static void musb_deassert_reset(struct work_struct *work)
musb_readw = musb->ops->readw;
if (musb->ops->writew)
musb_writew = musb->ops->writew;
-   if (musb->ops->readl)
-   musb_readl = musb->ops->readl;
-   if (musb->ops->writel)
-   musb_writel = musb->ops->writel;
 
 #ifndef CONFIG_MUSB_PIO_ONLY
if (!musb->ops->dma_init || !musb->ops->dma_exit) {
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 8a74cb2907f8..a4bf1e9e2d2c 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -127,8 +127,6 @@ enum musb_g_ep0_state {
  * @writeb:write 8 bits
  * @readw: read 16 bits
  * @writew:write 16 bits
- * @readl: read 32 bits
- * @writel:write 32 bits
  * @read_fifo: reads the fifo
  * @write_fifo:writes to fifo
  * @dma_init:  platform specific dma init function
@@ -174,8 +172,6 @@ struct musb_platform_ops {
void(*writeb)(void __iomem *addr, unsigned offset, u8 data);
u16 (*readw)(const void __iomem *addr, unsigned offset);
void(*writew)(void __iomem *addr, unsigned offset, u16 data);
-   u32 (*readl)(const void __iomem *addr, unsigned offset);
-   void(*writel)(void __iomem *addr, unsigned offset, u32 data);
void(*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf);
void(*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf);
struct dma_controller *
diff --git a/drivers/usb/musb/musb_io.h b/drivers/usb/musb/musb_io.h
index b7025b2e6e00..b4d870b836aa 100644
--- a/drivers/usb/musb/musb_io.h
+++ b/drivers/usb/musb/musb_io.h
@@ -39,7 +39,7 @@ struct musb_io {
 extern void (*musb_writeb)(void __iomem *addr, unsigned offset, u8 data);
 extern u16 (*musb_readw)(const void __iomem *addr, unsigned offset);
 extern void (*musb_writew)(void __iomem *addr, unsigned offset, u16 data);
-extern u32 (*musb_readl)(const void __iomem *addr, unsigned offset);
-extern void (*musb_writel)(void __iomem *addr, unsigned offset, u32 data);
+extern u32 musb_readl(const void __iomem *addr, unsigned offset);
+extern void musb_writel(void __iomem *addr, unsigned offset, u32 data);
 
 #endif
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/11] usb: musb: remove adjust_channel_params() callback from musb_platform_ops

2018-04-16 Thread Bin Liu
Now Blackfin support is removed, nobody uses adjust_channel_params() any
more, so remove it from struct musb_platform_ops.

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_core.h | 4 
 drivers/usb/musb/musbhsdma.c | 8 
 2 files changed, 12 deletions(-)

diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index a4bf1e9e2d2c..f57323e50e44 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -138,7 +138,6 @@ enum musb_g_ep0_state {
  * @recover:   platform-specific babble recovery
  * @vbus_status: returns vbus status if possible
  * @set_vbus:  forces vbus status
- * @adjust_channel_params: pre check for standard dma channel_program func
  * @pre_root_reset_end: called before the root usb port reset flag gets cleared
  * @post_root_reset_end: called after the root usb port reset flag gets cleared
  * @phy_callback: optional callback function for the phy to call
@@ -184,9 +183,6 @@ struct musb_platform_ops {
int (*vbus_status)(struct musb *musb);
void(*set_vbus)(struct musb *musb, int on);
 
-   int (*adjust_channel_params)(struct dma_channel *channel,
-   u16 packet_sz, u8 *mode,
-   dma_addr_t *dma_addr, u32 *len);
void(*pre_root_reset_end)(struct musb *musb);
void(*post_root_reset_end)(struct musb *musb);
int (*phy_callback)(enum musb_vbus_id_status status);
diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c
index 57d416a110a5..a688f7f87829 100644
--- a/drivers/usb/musb/musbhsdma.c
+++ b/drivers/usb/musb/musbhsdma.c
@@ -199,14 +199,6 @@ static int dma_channel_program(struct dma_channel *channel,
BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN ||
channel->status == MUSB_DMA_STATUS_BUSY);
 
-   /* Let targets check/tweak the arguments */
-   if (musb->ops->adjust_channel_params) {
-   int ret = musb->ops->adjust_channel_params(channel,
-   packet_sz, , _addr, );
-   if (ret)
-   return ret;
-   }
-
/*
 * The DMA engine in RTL1.8 and above cannot handle
 * DMA addresses that are not aligned to a 4 byte boundary.
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/11] usb: musb: merge musbhsdma.h into musbhsdma.c

2018-04-16 Thread Bin Liu
Now Blackfin support is removed, header musbhsdma.h is only included in
musbhsdma.c. So let's merge the content in musbhsdma.h to musbhsdma.c
and delete musbhsdma.h.

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musbhsdma.c | 66 +++-
 drivers/usb/musb/musbhsdma.h | 72 
 2 files changed, 65 insertions(+), 73 deletions(-)
 delete mode 100644 drivers/usb/musb/musbhsdma.h

diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c
index 4389fc3422bd..57d416a110a5 100644
--- a/drivers/usb/musb/musbhsdma.c
+++ b/drivers/usb/musb/musbhsdma.c
@@ -10,7 +10,71 @@
 #include 
 #include 
 #include "musb_core.h"
-#include "musbhsdma.h"
+
+#define MUSB_HSDMA_BASE0x200
+#define MUSB_HSDMA_INTR(MUSB_HSDMA_BASE + 0)
+#define MUSB_HSDMA_CONTROL 0x4
+#define MUSB_HSDMA_ADDRESS 0x8
+#define MUSB_HSDMA_COUNT   0xc
+
+#define MUSB_HSDMA_CHANNEL_OFFSET(_bchannel, _offset)  \
+   (MUSB_HSDMA_BASE + (_bchannel << 4) + _offset)
+
+#define musb_read_hsdma_addr(mbase, bchannel)  \
+   musb_readl(mbase,   \
+  MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS))
+
+#define musb_write_hsdma_addr(mbase, bchannel, addr) \
+   musb_writel(mbase, \
+   MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS), \
+   addr)
+
+#define musb_read_hsdma_count(mbase, bchannel) \
+   musb_readl(mbase,   \
+  MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT))
+
+#define musb_write_hsdma_count(mbase, bchannel, len) \
+   musb_writel(mbase, \
+   MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT), \
+   len)
+/* control register (16-bit): */
+#define MUSB_HSDMA_ENABLE_SHIFT0
+#define MUSB_HSDMA_TRANSMIT_SHIFT  1
+#define MUSB_HSDMA_MODE1_SHIFT 2
+#define MUSB_HSDMA_IRQENABLE_SHIFT 3
+#define MUSB_HSDMA_ENDPOINT_SHIFT  4
+#define MUSB_HSDMA_BUSERROR_SHIFT  8
+#define MUSB_HSDMA_BURSTMODE_SHIFT 9
+#define MUSB_HSDMA_BURSTMODE   (3 << MUSB_HSDMA_BURSTMODE_SHIFT)
+#define MUSB_HSDMA_BURSTMODE_UNSPEC0
+#define MUSB_HSDMA_BURSTMODE_INCR4 1
+#define MUSB_HSDMA_BURSTMODE_INCR8 2
+#define MUSB_HSDMA_BURSTMODE_INCR163
+
+#define MUSB_HSDMA_CHANNELS8
+
+struct musb_dma_controller;
+
+struct musb_dma_channel {
+   struct dma_channel  channel;
+   struct musb_dma_controller  *controller;
+   u32 start_addr;
+   u32 len;
+   u16 max_packet_sz;
+   u8  idx;
+   u8  epnum;
+   u8  transmit;
+};
+
+struct musb_dma_controller {
+   struct dma_controller   controller;
+   struct musb_dma_channel channel[MUSB_HSDMA_CHANNELS];
+   void*private_data;
+   void __iomem*base;
+   u8  channel_count;
+   u8  used_channels;
+   int irq;
+};
 
 static void dma_channel_release(struct dma_channel *channel);
 
diff --git a/drivers/usb/musb/musbhsdma.h b/drivers/usb/musb/musbhsdma.h
deleted file mode 100644
index 93665135aff1..
--- a/drivers/usb/musb/musbhsdma.h
+++ /dev/null
@@ -1,72 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * MUSB OTG driver - support for Mentor's DMA controller
- *
- * Copyright 2005 Mentor Graphics Corporation
- * Copyright (C) 2005-2007 by Texas Instruments
- */
-
-#define MUSB_HSDMA_BASE0x200
-#define MUSB_HSDMA_INTR(MUSB_HSDMA_BASE + 0)
-#define MUSB_HSDMA_CONTROL 0x4
-#define MUSB_HSDMA_ADDRESS 0x8
-#define MUSB_HSDMA_COUNT   0xc
-
-#define MUSB_HSDMA_CHANNEL_OFFSET(_bchannel, _offset)  \
-   (MUSB_HSDMA_BASE + (_bchannel << 4) + _offset)
-
-#define musb_read_hsdma_addr(mbase, bchannel)  \
-   musb_readl(mbase,   \
-  MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS))
-
-#define musb_write_hsdma_addr(mbase, bchannel, addr) \
-   musb_writel(mbase, \
-   MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS), \
-   addr)
-
-#define musb_read_hsdma_count(mbase, bchannel) \
-   musb_readl(mbase,   \
-  MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT))
-
-#define musb_write_hsdma_count(mbase, bchannel, len) \
-   musb_writel(mbase, \
-   MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT), \
-   len)
-/* control register (16-bit): */
-#define MUSB_HSDMA_ENABLE_SHIFT0
-#define MUSB_HSDMA_TRANSMIT_SHIFT  1
-#define 

Re: [PATCH v1 1/1] usb: core: Add quirk for HP v222w 16GB Mini

2018-04-16 Thread sathyanarayanan kuppuswamy

Hi Segei,


On 04/14/2018 01:35 AM, Sergei Shtylyov wrote:
Please indent with tabs (as above and below), not spaces. 

Thanks for the comments. I will fix it in v2.

--
Sathyanarayanan Kuppuswamy
Linux kernel developer

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Add udev-md-raid-safe-timeouts.rules

2018-04-16 Thread Alan Stern
On Mon, 16 Apr 2018, Chris Murphy wrote:

> Adding linux-usb@ and linux-scsi@
> (This email does contain the thread initiating email, but some replies
> are on the other lists.)
> 
> On Mon, Apr 16, 2018 at 5:43 AM, Austin S. Hemmelgarn
>  wrote:
> > On 2018-04-15 21:04, Chris Murphy wrote:
> >>
> >> I just ran into this:
> >>
> >> https://github.com/neilbrown/mdadm/pull/32/commits/af1ddca7d5311dfc9ed60a5eb6497db1296f1bec
> >>
> >> This solution is inadequate, can it be made more generic? This isn't
> >> an md specific problem, it affects Btrfs and LVM as well. And in fact
> >> raid0, and even none raid setups.
> >>
> >> There is no good reason to prevent deep recovery, which is what
> >> happens with the default command timer of 30 seconds, with this class
> >> of drive. Basically that value is going to cause data loss for the
> >> single device and also raid0 case, where the reset happens before deep
> >> recovery has a chance. And even if deep recovery fails to return user
> >> data, what we need to see is the proper error message: read error UNC,
> >> rather than a link reset message which just obfuscates the problem.
> >
> >
> > This has been discussed at least once here before (probably more times, hard
> > to be sure since it usually comes up as a side discussion in an only
> > marginally related thread).  Last I knew, the consensus here was that it
> > needs to be changed upstream in the kernel, not by adding a udev rule
> > because while the value is technically system policy, the default policy is
> > brain-dead for anything but the original disks it was i9ntended for (30
> > seconds works perfectly fine for actual SCSI devices because they behave
> > sanely in the face of media errors, but it's horribly inadequate for ATA
> > devices).
> >
> > To re-iterate what I've said before on the subject:
> >
> > For ATA drives it should probably be 150 seconds.  That's 30 seconds beyond
> > the typical amount of time most consumer drives will keep retrying a sector,
> > so even if it goes the full time to try and recover a sector this shouldn't
> > trigger.  The only people this change should negatively impact are those who
> > have failing drives which support SCT ERC and have it enabled, but aren't
> > already adjusting this timeout.
> >
> > For physical SCSI devices, it should continue to be 30 seconds.  SCSI disks
> > are sensible here and don't waste your time trying to recover a sector.  For
> > PV-SCSI devices, it should probably be adjusted too, but I don't know what a
> > reasonable value is.
> >
> > For USB devices it should probably be higher than 30 seconds, but again I
> > have no idea what a reasonable value is.
> 
> I don't know how all of this is designed but it seems like there's
> only one location for the command timer, and the SCSI driver owns it,
> and then everyone else (ATA and USB and for all I know SAN) are on top
> of that and lack any ability to have separate timeouts.

As far as mass-storage is concerned, USB is merely a transport.  It 
doesn't impose any timeout rules; the appropriate timeout value is 
whatever the device at the end of the USB link needs.  Thus, a SCSI 
drive connected over USB could use a 30-second timeout, an ATA drive 
could use 150 seconds, and so on.

Unfortunately, the only way to tell what sort of drive you've got is by
looking at the Vendor/Product IDs or other information provided by the
drive itself.  You can't tell anything just from knowing what sort of
bus it's on.

Alan Stern

> The nice thing about the udev rule is that it tests for SCT ERC before
> making a change. There certainly are enterprise and almost enterprise
> "NAS" SATA drives that have short SCT ERC times enabled out of the box
> - and the udev method makes them immune to the change.

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Add udev-md-raid-safe-timeouts.rules

2018-04-16 Thread Chris Murphy
Adding linux-usb@ and linux-scsi@
(This email does contain the thread initiating email, but some replies
are on the other lists.)

On Mon, Apr 16, 2018 at 5:43 AM, Austin S. Hemmelgarn
 wrote:
> On 2018-04-15 21:04, Chris Murphy wrote:
>>
>> I just ran into this:
>>
>> https://github.com/neilbrown/mdadm/pull/32/commits/af1ddca7d5311dfc9ed60a5eb6497db1296f1bec
>>
>> This solution is inadequate, can it be made more generic? This isn't
>> an md specific problem, it affects Btrfs and LVM as well. And in fact
>> raid0, and even none raid setups.
>>
>> There is no good reason to prevent deep recovery, which is what
>> happens with the default command timer of 30 seconds, with this class
>> of drive. Basically that value is going to cause data loss for the
>> single device and also raid0 case, where the reset happens before deep
>> recovery has a chance. And even if deep recovery fails to return user
>> data, what we need to see is the proper error message: read error UNC,
>> rather than a link reset message which just obfuscates the problem.
>
>
> This has been discussed at least once here before (probably more times, hard
> to be sure since it usually comes up as a side discussion in an only
> marginally related thread).  Last I knew, the consensus here was that it
> needs to be changed upstream in the kernel, not by adding a udev rule
> because while the value is technically system policy, the default policy is
> brain-dead for anything but the original disks it was i9ntended for (30
> seconds works perfectly fine for actual SCSI devices because they behave
> sanely in the face of media errors, but it's horribly inadequate for ATA
> devices).
>
> To re-iterate what I've said before on the subject:
>
> For ATA drives it should probably be 150 seconds.  That's 30 seconds beyond
> the typical amount of time most consumer drives will keep retrying a sector,
> so even if it goes the full time to try and recover a sector this shouldn't
> trigger.  The only people this change should negatively impact are those who
> have failing drives which support SCT ERC and have it enabled, but aren't
> already adjusting this timeout.
>
> For physical SCSI devices, it should continue to be 30 seconds.  SCSI disks
> are sensible here and don't waste your time trying to recover a sector.  For
> PV-SCSI devices, it should probably be adjusted too, but I don't know what a
> reasonable value is.
>
> For USB devices it should probably be higher than 30 seconds, but again I
> have no idea what a reasonable value is.

I don't know how all of this is designed but it seems like there's
only one location for the command timer, and the SCSI driver owns it,
and then everyone else (ATA and USB and for all I know SAN) are on top
of that and lack any ability to have separate timeouts.

The nice thing about the udev rule is that it tests for SCT ERC before
making a change. There certainly are enterprise and almost enterprise
"NAS" SATA drives that have short SCT ERC times enabled out of the box
- and the udev method makes them immune to the change.


-- 
Chris Murphy
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


dwc2 ff540000.usb: dwc2_hc_chhltd_intr_dma: Channel 11 - ChHltd set, but reason is unknown

2018-04-16 Thread Rodrigo Stuffs
Hi there Minas / linux-usb ;

I have a good ole APC Back-UPS ES 600N that from time to time resolves
that it should stop talking to my SBCs.

This issue happened in my Raspberry Pi, and when it stopped I had the
following printk:

Apr 11 14:10:15 localhost kernel: [9416331.806123] hid-generic
0003:051D:0002.000A: usb_submit_urb(ctrl) failed: -1

All I had to do is monitor the graphics and when it flatlined, unplug
and plug the UPS usb port. Until the next occurrence. Well, I lived
with it for some good years.

Last weekend I changed the Raspberry Pi with a TinkerBoard. And the
cranky UPS is also tickling TinkerBoard's USB port. Now the issue
manifests in a slightly different way:

== DEVICE ENUMERATION ==
[56529.462106] usb 1-1.1.3: new low-speed USB device number 9 using dwc2
[56530.222538] usb 1-1.1.3: New USB device found, idVendor=051d, idProduct=0002
[56530.222638] usb 1-1.1.3: New USB device strings: Mfr=3, Product=1,
SerialNumber=2
[56530.222697] usb 1-1.1.3: Product: Back-UPS ES 600N FW:876.Q1j.D USB FW:Q1j
[56530.222772] usb 1-1.1.3: Manufacturer: APC
[56530.222821] usb 1-1.1.3: SerialNumber: 5B1017T20483
[56535.075030] hid-generic 0003:051D:0002.0003: hiddev0,hidraw1: USB
HID v1.10 Device [APC Back-UPS ES 600N FW:876.Q1j.D USB FW:Q1j] on
usb-ff54.usb-1.1.3/input0

== KERNEL WHINES ==
[105243.156331] dwc2 ff54.usb: dwc2_hc_chhltd_intr_dma: Channel 11
- ChHltd set, but reason is unknown
[105243.156414] dwc2 ff54.usb: hcint 0x0002, intsts 0x06600029
[105273.536188] dwc2 ff54.usb: dwc2_hc_chhltd_intr_dma: Channel 13
- ChHltd set, but reason is unknown
[105273.536268] dwc2 ff54.usb: hcint 0x0002, intsts 0x06600029

Well, in spirit to getting things going nicely in the new system, I
have found the thread:
https://www.spinics.net/lists/linux-usb/msg161854.html

Where Minas suggests a patch to tackle it.

I tried to backport the patch to my 4.4 Kernel and it was not really
happy about it:

== COMPILE BARFS ==
  CC  drivers/usb/dwc2/hcd.o
drivers/usb/dwc2/hcd.c: In function ‘dwc2_core_init’:
drivers/usb/dwc2/hcd.c:2191:22: error: ‘trdtrim’ undeclared (first use
in this function); did you mean ‘strstrip’?
  u32 usbcfg, otgctl; trdtrim;
  ^~~
  strstrip
drivers/usb/dwc2/hcd.c:2191:22: note: each undeclared identifier is
reported only once for each function it appears in
drivers/usb/dwc2/hcd.c:2192:2: warning: ISO C90 forbids mixed
declarations and code [-Wdeclaration-after-statement]
error, forbidden warning: hcd.c:2192
scripts/Makefile.build:277: recipe for target 'drivers/usb/dwc2/hcd.o' failed
make[3]: *** [drivers/usb/dwc2/hcd.o] Error 1
scripts/Makefile.build:484: recipe for target 'drivers/usb/dwc2' failed
make[2]: *** [drivers/usb/dwc2] Error 2
scripts/Makefile.build:484: recipe for target 'drivers/usb' failed
make[1]: *** [drivers/usb] Error 2
Makefile:1016: recipe for target 'drivers' failed
make: *** [drivers] Error 2



Patchset: https://pastebin.com/v1ink6fJ

== QUESTIONS ==
1. What are the odds that the OP patchset will also help my issue?
2. IF 1 == true ; then what am I doing wrong in my patch? :-)

Appreciate your time.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: mon: Change return type to vm_fault_t

2018-04-16 Thread Greg KH
On Mon, Apr 16, 2018 at 05:18:35PM +0530, Souptick Joarder wrote:
> On Mon, Apr 16, 2018 at 1:17 PM, Greg KH  wrote:
> > On Sun, Apr 15, 2018 at 04:10:08AM -0700, Matthew Wilcox wrote:
> >> On Sun, Apr 15, 2018 at 07:49:16AM +0200, Greg KH wrote:
> >> > On Sun, Apr 15, 2018 at 12:36:02AM +0530, Souptick Joarder wrote:
> >> > > Use new return type vm_fault_t for fault handler
> >> > > in struct vm_operations_struct.
> >> >
> >> > Why?
> >>
> >> commit 1c8f422059ae5da07db7406ab916203f9417e396
> >> Author: Souptick Joarder 
> >> Date:   Thu Apr 5 16:25:23 2018 -0700
> >>
> >> mm: change return type to vm_fault_t
> >>
> >> The plan for these patches is to introduce the typedef, initially just
> >> as documentation ("These functions should return a VM_FAULT_ status").
> >> We'll trickle the patches to individual drivers/filesystems in through
> >> the maintainers, as far as possible.  Then we'll change the typedef to
> >> an unsigned int and break the compilation of any unconverted
> >> drivers/filesystems.
> >>
> >> vmf_insert_page(), vmf_insert_mixed() and vmf_insert_pfn() are three
> >> newly added functions.  The various drivers/filesystems where return
> >> value of fault(), huge_fault(), page_mkwrite() and pfn_mkwrite() get
> >> converted, will need them.  These functions will return correct
> >> VM_FAULT_ code based on err value.
> >>
> >> We've had bugs before where drivers returned -EFOO.  And we have this
> >> silly inefficiency where vm_insert_xxx() return an errno which (afaict)
> >> every driver then converts into a VM_FAULT code.  In many cases drivers
> >> failed to return correct VM_FAULT code value despite of vm_insert_xxx()
> >> fails.  We have indentified and clean up all those existing bugs and
> >> silly inefficiencies in driver/filesystems by adding these three new
> >> inline wrappers.  As mentioned above, we will trickle those patches to
> >> individual drivers/filesystems in through maintainers after these three
> >> wrapper functions are merged.
> >
> > Then put a summary of this type of thing in the original patch please!
> 
> Ok, I will add it in change log and send v2.
> >
> > When a maintainer gets a patch with no context at all, the first
> > reaction is to just reject it (especially as many of these patches were
> > sent privately and did not go on any public mailing list, those all got
> > automatically dropped...)
> 
> For few drivers only maintainers name is mentioned without any mailing list
> in Maintainer file. Not sure which mailing list to add for the same.

get_maintainers.pl will always tell you a mailing list to cc: for any
file/patch.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Fwd: usb: uas: device reset most the time while enumeration- usb3.0

2018-04-16 Thread Oliver Neukum
Am Montag, den 16.04.2018, 10:23 -0400 schrieb Alan Stern:
> > > > > [57246.701096] sd 1:0:0:0: tag#0 uas_eh_abort_handler 0 uas-tag 1
> > > > > inflight: CMD IN
> > > > > [57246.701130] sd 1:0:0:0: tag#0 CDB: opcode=0x1a 1a 00 3f 00 04 00
> > 
> > URB is canceled, maybe that URB never finished?
> 
> No doubt.  Perhaps the device doesn't support this particular command.

Then we should expect the enumeration to always fail.
Possibly the lower layers swallow the transfer.

Regards
Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] usb: mon: Change return type to vm_fault_t

2018-04-16 Thread Souptick Joarder
Use new return type vm_fault_t for the fault handler
in struct vm_operations_struct. For now, this is just
documenting that the function returns a VM_FAULT value
rather than an errno. Once all instances are converted,
vm_fault_t will become a distinct type.

Reference commit id->
1c8f422059ae5da07db7406ab916203f9417e396

Signed-off-by: Souptick Joarder 
Reviewed-by: Matthew Wilcox 
---
v2: Modified the change logs.

 drivers/usb/mon/mon_bin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 2761fad..34e866ad 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -1227,7 +1227,7 @@ static void mon_bin_vma_close(struct vm_area_struct *vma)
 /*
  * Map ring pages to user space.
  */
-static int mon_bin_vma_fault(struct vm_fault *vmf)
+static vm_fault_t mon_bin_vma_fault(struct vm_fault *vmf)
 {
struct mon_reader_bin *rp = vmf->vma->vm_private_data;
unsigned long offset, chunk_idx;
--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 02/13] dt-bindings: usb: add documentation for typec port controller(TCPCI)

2018-04-16 Thread Rob Herring
On Mon, Apr 16, 2018 at 6:54 AM, Jun Li  wrote:
> Hi
>> -Original Message-
>> From: Rob Herring [mailto:r...@kernel.org]
>> Sent: 2018年4月10日 4:04
>> To: Jun Li 
>> Cc: gre...@linuxfoundation.org; heikki.kroge...@linux.intel.com;
>> li...@roeck-us.net; a.ha...@samsung.com; shufan_...@richtek.com; Peter
>> Chen ; devicet...@vger.kernel.org;
>> linux-usb@vger.kernel.org; dl-linux-imx ;
>> de...@driverdev.osuosl.org
>> Subject: Re: [PATCH v4 02/13] dt-bindings: usb: add documentation for typec
>> port controller(TCPCI)
>>
>> On Thu, Mar 29, 2018 at 12:06:07AM +0800, Li Jun wrote:

[...]

>> > +ptn5110@50 {
>> > +   compatible = "usb-tcpci,ptn5110";
>> > +   reg = <0x50>;
>> > +   interrupt-parent = <>;
>> > +   interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
>> > +
>> > +   usb_con: connector {
>>
>> How is the OF graph done in this case? You need some link to the USB 
>> controller.
>
> The platform(i.MX8MQ EVK) for this is still on the way of start upstream, I 
> was
> Planning to add this part with enabling USB3 function, as of how this will be 
> done,
> I only have usb3 ss data(no display port or Sideband), is something like 
> below OK?
>
> typec: ptn5110@50 {
> compatible = "nxp,ptn5110";
> ...
>
> usb_con: connector {
> compatible = "usb-c-connector";
> label = "USB-C";
> ...
>
> ports {
> #address-cells = <1>;
> #size-cells = <0>;
>
> port@1 {
> reg = <1>;
> usb_con_ss: endpoint {
> remote-endpoint = <_phy_ss>;
> };
> };
> };
> };
> };
>
> _phy0 {
> status = "okay";
>
> port {
> usb3_phy_ss: endpoint {

Normally, the graph connection would be to the USB controller, not the
phy as the phy is just referred to with a "phys" property.

> remote-endpoint = <_con_ss>;
> };
> };
> }
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Fwd: usb: uas: device reset most the time while enumeration- usb3.0

2018-04-16 Thread Alan Stern
On Mon, 16 Apr 2018, Mathias Nyman wrote:

> On 16.04.2018 13:20, Tushar Nimkar wrote:
> > On 2018-04-05 11:31, Felipe Balbi wrote:
> >> Hi,
> >>
> >> it would help if you would Cc XHCI's maintainer :-)
> >>
> >> tnim...@codeaurora.org writes:
> >>
> >>> On 2018-04-04 19:28, Greg KH wrote:
>  On Wed, Apr 04, 2018 at 06:41:41PM +0530, tnim...@codeaurora.org wrote:
> > On 2018-04-04 18:07, Greg KH wrote:
> > > On Wed, Apr 04, 2018 at 05:14:50PM +0530, tnim...@codeaurora.org 
> > > wrote:
> > > > Hi Oliver/Greg,
> > > >
> > > > I am able to duplicated the UAS issue on 4.16 as well.
> > > > The behavior is same new usb device detects and reset after aprox 30
> > > > sec(SD_TIMEOUT)
> > > > Logs are already shared below.
> > > >
> > > > We are using Synopsys dwc3 as host controller, May I know have
> > > > tested it
> > > > with dwc3?
> > > > I have tried it on Linux PC (x86 Ubuntu machine) I could not see the
> > > > issue.
> > > > It enumerates well.
> > >
> > > Great, stick with an x86 platform!  :)
> > >
> > > Looks like a dwc3 host controller issue, try enabling tracing and
> > > debugging in that driver when this happens to see what is going on.
> >
> > Oh if so let me enable the trace for that. I will respond you on this.
> >>>
> >>> I did not get much clue, Greg.  sometime this device enumerates well,
> >>> attached both working and non working case logs.
> >>> following is not working case
> >>> root@OpenWrt:/# dmesg
> 
> ...
> 
> >>> [57214.172683] xhci-hcd xhci-hcd.0.auto: ep 0x83 - asked for 112 bytes,
> >>> 96 bytes untransferred
> >>> [57214.172809] xhci-hcd xhci-hcd.0.auto: ep 0x83 - asked for 112 bytes,
> >>> 96 bytes untransferred
> >>> [57214.172840] sd 1:0:0:0: [sdb] 976773168 512-byte logical blocks: (500
> >>> GB/466 GiB)
> >>> [57214.172843] xhci-hcd xhci-hcd.0.auto: ep 0x81 - asked for 4096 bytes,
> >>> 4080 bytes untransferred
> >>> [57214.172851] xhci-hcd xhci-hcd.0.auto: ep 0x83 - asked for 112 bytes,
> >>> 96 bytes untransferred
> >>> [57214.253085] xhci-hcd xhci-hcd.0.auto: xhci_hub_status_data: stopping
> >>> port polling.
> 
> Huge gap before uas_eh_abort_eh_handler is called.

This 30-second gap is typical for mass-storage.  It's the default 
length of time before the higher layers give up on a request and tell 
the driver to cancel it.

> >>> [57246.701096] sd 1:0:0:0: tag#0 uas_eh_abort_handler 0 uas-tag 1
> >>> inflight: CMD IN
> >>> [57246.701130] sd 1:0:0:0: tag#0 CDB: opcode=0x1a 1a 00 3f 00 04 00
> 
> URB is canceled, maybe that URB never finished?

No doubt.  Perhaps the device doesn't support this particular command.

> >>> [57246.707583] xhci-hcd xhci-hcd.0.auto: Cancel URB 07b523f0,
> >>> dev 1, ep 0x81, starting at offset 0
> >>> [57246.707594] xhci-hcd xhci-hcd.0.auto: // Ding dong!
> >>> [57246.707616] xhci-hcd xhci-hcd.0.auto: Stopped on No-op or Link TRB
> >>> for slot 1 ep 2
> >>> [57246.707625] xhci-hcd xhci-hcd.0.auto: Removing canceled TD starting
> >>> at 0x7f0cd0a0 (dma).
> >>> [57246.707630] xhci-hcd xhci-hcd.0.auto: Finding endpoint context
> >>> [57246.707634] xhci-hcd xhci-hcd.0.auto: Cycle state = 0x1
> >>> [57246.707637] xhci-hcd xhci-hcd.0.auto: New dequeue segment =
> >>> 890c7dc4 (virtual)
> >>> [57246.707641] xhci-hcd xhci-hcd.0.auto: New dequeue pointer =
> >>> 0x7f0cd0b0 (DMA)
> >>> [57246.707646] xhci-hcd xhci-hcd.0.auto: Set TR Deq Ptr cmd, new deq seg
> >>> = 890c7dc4 (0x7f0cd000 dmeq ptr = 0ce7faa0 (0x7f0cd0b0
> >>> dma), new cycle = 1
> >>> [57246.707651] xhci-hcd xhci-hcd.0.auto: // Ding dong!
> >>> [57246.707671] xhci-hcd xhci-hcd.0.auto: Successful Set TR Deq Ptr cmd,
> >>> deq = @7f0cd0b0
> >>> [57246.721090] scsi host1: uas_eh_device_reset_handler start
> >>> [57246.721114] xhci-hcd xhci-hcd.0.auto: Cancel URB 279f06a2,
> >>> dev 1, ep 0x83, starting at offset 0
> >>> [57246.721120] xhci-hcd xhci-hcd.0.auto: // Ding dong!
> >>> [57246.721135] xhci-hcd xhci-hcd.0.auto: ERROR Transfer event for
> >>> unknown stream ring slot 1 ep 6
> >>> [57246.725463] xhci-hcd xhci-hcd.0.auto: @7f044780 
> >>>  1b00 01078001
> 
> Stop -Length invalid transfer event. That is normal when canceling a URB,
> but it should point to the TRB xhc was working on when stopped.
> Here it just points to 0. That part looks like some issue with this specific
> controller.
> 
> Some other errors may return 0 as their TRB pointer, but not this event.
>   
> But this is not the cause, just a detail while handling the real cause.
> Nothing in this log shows why the URB was canceled in the first place.

Presumably because the URB never completed, and therefore the transfer 
timed out and was cancelled by the SCSI layer.

Alan Stern

> usbmon and xhci traces could help, xhci traces:
> 
> mount -t debugfs none /sys/kernel/debug
> echo 81920 > /sys/kernel/debug/tracing/buffer_size_kb
> echo 1 > 

Re: [RFC PATCH] usb: hcd: complete URBs in threaded-IRQ context instead of tasklet

2018-04-16 Thread Sebastian Andrzej Siewior
On 2018-03-08 10:57:39 [+0100], To Mauro Carvalho Chehab wrote:
> On 2018-02-27 14:39:34 [-0300], Mauro Carvalho Chehab wrote:
> > Hi Sebastian,
> Hi Mauro,
> 
> > Sorry for taking some time to test it, has been busy those days...
> :)
> 
> > Anyway, I tested it today. Didn't work. It keep losing data.
> 
> Okay, this was unexpected. What I learned from the thread is that you
> use the dwc2 controller and once upgrade to a kernel which completes the
> URBs in BH context then you starting losing data from your DVB-s USB
> device. And it was assumed that this is because BH/ksoftirq is getting
> "paused" if it is running for too long. If that is the case then a
> revert of "let us complete the URB in BH context" should get it working
> again. Is that so?

ping

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: mon: Change return type to vm_fault_t

2018-04-16 Thread Matthew Wilcox
On Mon, Apr 16, 2018 at 05:18:35PM +0530, Souptick Joarder wrote:
> On Mon, Apr 16, 2018 at 1:17 PM, Greg KH  wrote:
> > When a maintainer gets a patch with no context at all, the first
> > reaction is to just reject it (especially as many of these patches were
> > sent privately and did not go on any public mailing list, those all got
> > automatically dropped...)
> 
> For few drivers only maintainers name is mentioned without any mailing list
> in Maintainer file. Not sure which mailing list to add for the same.

I thought you were using scripts/get_maintainer.pl to get the maintainers;
I didn't realise you were going through MAINTAINERS manually.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 02/20] usb: host: xhci: check DYING state earlier

2018-04-16 Thread Mathias Nyman

On 16.04.2018 15:29, Felipe Balbi wrote:

Instead of allocating urb priv and, maybe, bail out due to xhci being
in DYING state, we can move the check earlier and avoid the memory
allocation altogether.


This also moves checking for DYING outside the lock.

Most cases set DYING with lock held, so if we first get the lock before
checking DYING we have a better chance of not being in the process of dying.

Small thing, but so is this cleanup, so not sure its worth the change

-Mathias



While at that, also remove an unnecessary empty line.

Signed-off-by: Felipe Balbi 
---
  drivers/usb/host/xhci.c | 13 ++---
  1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 65c454b94165..39e67b7bece1 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1299,6 +1299,12 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
true, true, __func__) <= 0)
return -EINVAL;
  
+	if (xhci->xhc_state & XHCI_STATE_DYING) {

+   xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI 
host.\n",
+urb->ep->desc.bEndpointAddress, urb);
+   return -ESHUTDOWN;
+   }
+
slot_id = urb->dev->slot_id;
ep_index = xhci_get_endpoint_index(>ep->desc);
ep_state = >devs[slot_id]->eps[ep_index].ep_state;
@@ -1347,12 +1353,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
  
  	spin_lock_irqsave(>lock, flags);
  
-	if (xhci->xhc_state & XHCI_STATE_DYING) {

-   xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI 
host.\n",
-urb->ep->desc.bEndpointAddress, urb);
-   ret = -ESHUTDOWN;
-   goto free_priv;
-   }
if (*ep_state & EP_SOFT_CLEAR_TOGGLE) {
xhci_warn(xhci, "Can't enqueue URB while manually clearing 
toggle\n");
ret = -EINVAL;
@@ -1360,7 +1360,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
}
  
  	switch (usb_endpoint_type(>ep->desc)) {

-
case USB_ENDPOINT_XFER_CONTROL:
ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb,
 slot_id, ep_index);



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Fwd: usb: uas: device reset most the time while enumeration- usb3.0

2018-04-16 Thread Mathias Nyman

On 16.04.2018 13:20, Tushar Nimkar wrote:

On 2018-04-05 11:31, Felipe Balbi wrote:

Hi,

it would help if you would Cc XHCI's maintainer :-)

tnim...@codeaurora.org writes:


On 2018-04-04 19:28, Greg KH wrote:

On Wed, Apr 04, 2018 at 06:41:41PM +0530, tnim...@codeaurora.org wrote:

On 2018-04-04 18:07, Greg KH wrote:
> On Wed, Apr 04, 2018 at 05:14:50PM +0530, tnim...@codeaurora.org wrote:
> > Hi Oliver/Greg,
> >
> > I am able to duplicated the UAS issue on 4.16 as well.
> > The behavior is same new usb device detects and reset after aprox 30
> > sec(SD_TIMEOUT)
> > Logs are already shared below.
> >
> > We are using Synopsys dwc3 as host controller, May I know have
> > tested it
> > with dwc3?
> > I have tried it on Linux PC (x86 Ubuntu machine) I could not see the
> > issue.
> > It enumerates well.
>
> Great, stick with an x86 platform!  :)
>
> Looks like a dwc3 host controller issue, try enabling tracing and
> debugging in that driver when this happens to see what is going on.

Oh if so let me enable the trace for that. I will respond you on this.


I did not get much clue, Greg.  sometime this device enumerates well,
attached both working and non working case logs.
following is not working case
root@OpenWrt:/# dmesg


...


[57214.172683] xhci-hcd xhci-hcd.0.auto: ep 0x83 - asked for 112 bytes,
96 bytes untransferred
[57214.172809] xhci-hcd xhci-hcd.0.auto: ep 0x83 - asked for 112 bytes,
96 bytes untransferred
[57214.172840] sd 1:0:0:0: [sdb] 976773168 512-byte logical blocks: (500
GB/466 GiB)
[57214.172843] xhci-hcd xhci-hcd.0.auto: ep 0x81 - asked for 4096 bytes,
4080 bytes untransferred
[57214.172851] xhci-hcd xhci-hcd.0.auto: ep 0x83 - asked for 112 bytes,
96 bytes untransferred
[57214.253085] xhci-hcd xhci-hcd.0.auto: xhci_hub_status_data: stopping
port polling.


Huge gap before uas_eh_abort_eh_handler is called.


[57246.701096] sd 1:0:0:0: tag#0 uas_eh_abort_handler 0 uas-tag 1
inflight: CMD IN
[57246.701130] sd 1:0:0:0: tag#0 CDB: opcode=0x1a 1a 00 3f 00 04 00


URB is canceled, maybe that URB never finished?


[57246.707583] xhci-hcd xhci-hcd.0.auto: Cancel URB 07b523f0,
dev 1, ep 0x81, starting at offset 0
[57246.707594] xhci-hcd xhci-hcd.0.auto: // Ding dong!
[57246.707616] xhci-hcd xhci-hcd.0.auto: Stopped on No-op or Link TRB
for slot 1 ep 2
[57246.707625] xhci-hcd xhci-hcd.0.auto: Removing canceled TD starting
at 0x7f0cd0a0 (dma).
[57246.707630] xhci-hcd xhci-hcd.0.auto: Finding endpoint context
[57246.707634] xhci-hcd xhci-hcd.0.auto: Cycle state = 0x1
[57246.707637] xhci-hcd xhci-hcd.0.auto: New dequeue segment =
890c7dc4 (virtual)
[57246.707641] xhci-hcd xhci-hcd.0.auto: New dequeue pointer =
0x7f0cd0b0 (DMA)
[57246.707646] xhci-hcd xhci-hcd.0.auto: Set TR Deq Ptr cmd, new deq seg
= 890c7dc4 (0x7f0cd000 dmeq ptr = 0ce7faa0 (0x7f0cd0b0
dma), new cycle = 1
[57246.707651] xhci-hcd xhci-hcd.0.auto: // Ding dong!
[57246.707671] xhci-hcd xhci-hcd.0.auto: Successful Set TR Deq Ptr cmd,
deq = @7f0cd0b0
[57246.721090] scsi host1: uas_eh_device_reset_handler start
[57246.721114] xhci-hcd xhci-hcd.0.auto: Cancel URB 279f06a2,
dev 1, ep 0x83, starting at offset 0
[57246.721120] xhci-hcd xhci-hcd.0.auto: // Ding dong!
[57246.721135] xhci-hcd xhci-hcd.0.auto: ERROR Transfer event for
unknown stream ring slot 1 ep 6
[57246.725463] xhci-hcd xhci-hcd.0.auto: @7f044780 
 1b00 01078001


Stop -Length invalid transfer event. That is normal when canceling a URB,
but it should point to the TRB xhc was working on when stopped.
Here it just points to 0. That part looks like some issue with this specific
controller.

Some other errors may return 0 as their TRB pointer, but not this event.
 
But this is not the cause, just a detail while handling the real cause.

Nothing in this log shows why the URB was canceled in the first place.

usbmon and xhci traces could help, xhci traces:

mount -t debugfs none /sys/kernel/debug
echo 81920 > /sys/kernel/debug/tracing/buffer_size_kb
echo 1 > /sys/kernel/debug/tracing/events/xhci-hcd/enable

then send /sys/kernel/debug/tracing/trace after issue triggered.

-Mathias

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] usb: dwc2: WA for Full speed ISOC IN in DDMA mode.

2018-04-16 Thread Artur Petrosyan
By clearing NAK status of EP, core will send ZLP
to IN token and assert NAK interrupt relying
on TxFIFO status only.

The WA applies only to core versions from 2.72a
to 4.00a (including both). Also for FS_IOT_1.00a
and HS_IOT_1.00a.

Signed-off-by: Artur Petrosyan 
Signed-off-by: Minas Harutyunyan 
---
 drivers/usb/dwc2/core.h   |  2 ++
 drivers/usb/dwc2/gadget.c | 21 +
 2 files changed, 23 insertions(+)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index d83be5651f87..a666e0758a99 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -985,6 +985,7 @@ struct dwc2_hsotg {
 
/* DWC OTG HW Release versions */
 #define DWC2_CORE_REV_2_71a0x4f54271a
+#define DWC2_CORE_REV_2_72a 0x4f54272a
 #define DWC2_CORE_REV_2_80a0x4f54280a
 #define DWC2_CORE_REV_2_90a0x4f54290a
 #define DWC2_CORE_REV_2_91a0x4f54291a
@@ -992,6 +993,7 @@ struct dwc2_hsotg {
 #define DWC2_CORE_REV_2_94a0x4f54294a
 #define DWC2_CORE_REV_3_00a0x4f54300a
 #define DWC2_CORE_REV_3_10a0x4f54310a
+#define DWC2_CORE_REV_4_00a0x4f54400a
 #define DWC2_FS_IOT_REV_1_00a  0x5531100a
 #define DWC2_HS_IOT_REV_1_00a  0x5532100a
 
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 6c32bf26e48e..83cb5577a52f 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3928,6 +3928,27 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
if (index && !hs_ep->isochronous)
epctrl |= DXEPCTL_SETD0PID;
 
+   /* WA for Full speed ISOC IN in DDMA mode.
+* By Clear NAK status of EP, core will send ZLP
+* to IN token and assert NAK interrupt relying
+* on TxFIFO status only
+*/
+
+   if (hsotg->gadget.speed == USB_SPEED_FULL &&
+   hs_ep->isochronous && dir_in) {
+   /* The WA applies only to core versions from 2.72a
+* to 4.00a (including both). Also for FS_IOT_1.00a
+* and HS_IOT_1.00a.
+*/
+   u32 gsnpsid = dwc2_readl(hsotg->regs + GSNPSID);
+
+   if ((gsnpsid >= DWC2_CORE_REV_2_72a &&
+gsnpsid <= DWC2_CORE_REV_4_00a) ||
+gsnpsid == DWC2_FS_IOT_REV_1_00a ||
+gsnpsid == DWC2_HS_IOT_REV_1_00a)
+   epctrl |= DXEPCTL_CNAK;
+   }
+
dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n",
__func__, epctrl);
 
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/20] usb: host: xhci: rename queue_bulk_tx() to queue_bulk_intr_tx()

2018-04-16 Thread Felipe Balbi
That function is used for both Bulk and Interrupt transfer types,
let's make it clear on the function name and provide one extra helper
for queueing bulk transfers.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci-ring.c | 23 +--
 drivers/usb/host/xhci.c  |  6 --
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 91a1a824673d..e9c6053f90c5 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3064,6 +3064,9 @@ static void check_interval(struct xhci_hcd *xhci, struct 
urb *urb,
}
 }
 
+static int xhci_queue_bulk_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+   struct urb *urb, int slot_id, unsigned int ep_index);
+
 /*
  * xHCI uses normal TRBs for both bulk and interrupt.  When the interrupt
  * endpoint is to be serviced, the xHC will consume (at most) one TD.  A TD
@@ -3078,7 +3081,23 @@ int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t 
mem_flags,
ep_ctx = xhci_get_ep_ctx(xhci, xhci->devs[slot_id]->out_ctx, ep_index);
check_interval(xhci, urb, ep_ctx);
 
-   return xhci_queue_bulk_tx(xhci, mem_flags, urb, slot_id, ep_index);
+   return xhci_queue_bulk_intr_tx(xhci, mem_flags, urb, slot_id, ep_index);
+}
+
+int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+   struct urb *urb, int slot_id, unsigned int ep_index)
+{
+   unsigned int ep_state;
+
+   ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
+
+   if (ep_state & (EP_GETTING_STREAMS | EP_GETTING_NO_STREAMS)) {
+   xhci_warn(xhci, "WARN: Can't enqueue URB, ep in streams 
transition state %x\n",
+   ep_state);
+   return -EINVAL;
+   }
+
+   return xhci_queue_bulk_intr_tx(xhci, mem_flags, urb, slot_id, ep_index);
 }
 
 /*
@@ -3189,7 +3208,7 @@ static int xhci_align_td(struct xhci_hcd *xhci, struct 
urb *urb, u32 enqd_len,
 }
 
 /* This is very similar to what ehci-q.c qtd_fill() does */
-int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+static int xhci_queue_bulk_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
struct urb *urb, int slot_id, unsigned int ep_index)
 {
struct xhci_ring *ring;
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 9b27798ecce5..65c454b94165 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1353,12 +1353,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
ret = -ESHUTDOWN;
goto free_priv;
}
-   if (*ep_state & (EP_GETTING_STREAMS | EP_GETTING_NO_STREAMS)) {
-   xhci_warn(xhci, "WARN: Can't enqueue URB, ep in streams 
transition state %x\n",
- *ep_state);
-   ret = -EINVAL;
-   goto free_priv;
-   }
if (*ep_state & EP_SOFT_CLEAR_TOGGLE) {
xhci_warn(xhci, "Can't enqueue URB while manually clearing 
toggle\n");
ret = -EINVAL;
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 17/20] usb: host: xhci: reorder variable declaration

2018-04-16 Thread Felipe Balbi
no functional changes. Cleanup only

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 4c2bc9d1678e..cd5b6bf4c867 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3692,13 +3692,15 @@ static int 
xhci_reserve_host_control_ep_resources(struct xhci_hcd *xhci)
  */
 int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
 {
-   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
-   struct xhci_virt_device *vdev;
struct xhci_slot_ctx *slot_ctx;
-   unsigned long flags;
-   int ret, slot_id;
+   struct xhci_virt_device *vdev;
struct xhci_command *command;
+   struct xhci_hcd *xhci;
+   unsigned long flags;
+   int slot_id;
+   int ret;
 
+   xhci = hcd_to_xhci(hcd);
command = xhci_alloc_command(xhci, true, GFP_KERNEL);
if (!command)
return 0;
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 20/20] usb: host: xhci: free priv outside of locked region

2018-04-16 Thread Felipe Balbi
In case we have any errors, we can free_priv with locks released and
interrupts enabled.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 0fab051f06fc..32aef7c9a677 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1376,12 +1376,13 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
ret = xhci_queue_isoc_tx(xhci, GFP_ATOMIC, urb,
slot_id, ep_index);
}
+   spin_unlock_irqrestore(>lock, flags);
 
if (ret) {
xhci_urb_free_priv(urb_priv);
urb->hcpriv = NULL;
}
-   spin_unlock_irqrestore(>lock, flags);
+
return ret;
 }
 
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 18/20] usb: host: xhci: make ep_state a value, not a reference

2018-04-16 Thread Felipe Balbi
This is now the single use of ep_state inside urb_enqueue(). We don't
need it to be a pointer anymore.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index cd5b6bf4c867..bff4f506035d 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1303,7 +1303,7 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
struct urb_priv *urb_priv;
unsigned long flags;
-   unsigned int *ep_state;
+   unsigned int ep_state;
unsigned int ep_index;
unsigned int slot_id;
int num_tds;
@@ -1327,7 +1327,7 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
 
slot_id = urb->dev->slot_id;
ep_index = xhci_get_endpoint_index(>ep->desc);
-   ep_state = >devs[slot_id]->eps[ep_index].ep_state;
+   ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
 
if (usb_endpoint_xfer_control(>ep->desc)) {
/* Check to see if the max packet size for the default control
@@ -1355,7 +1355,7 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
 
spin_lock_irqsave(>lock, flags);
 
-   if (*ep_state & EP_SOFT_CLEAR_TOGGLE) {
+   if (ep_state & EP_SOFT_CLEAR_TOGGLE) {
xhci_warn(xhci, "Can't enqueue URB while manually clearing 
toggle\n");
ret = -EINVAL;
goto free_priv;
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 19/20] usb: host: xhci: check CLEAR_TOGGLE earlier

2018-04-16 Thread Felipe Balbi
There's not need to delay check for CLEAR_TOGGLE until after we have
allocated urbpriv. Let's move it earlier and, finally, remove the
free_priv goto label.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index bff4f506035d..0fab051f06fc 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1329,6 +1329,11 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
ep_index = xhci_get_endpoint_index(>ep->desc);
ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
 
+   if (ep_state & EP_SOFT_CLEAR_TOGGLE) {
+   xhci_warn(xhci, "Can't enqueue URB while manually clearing 
toggle\n");
+   return -EINVAL;
+   }
+
if (usb_endpoint_xfer_control(>ep->desc)) {
/* Check to see if the max packet size for the default control
 * endpoint changed during FS device enumeration
@@ -1354,13 +1359,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
trace_xhci_urb_enqueue(urb);
 
spin_lock_irqsave(>lock, flags);
-
-   if (ep_state & EP_SOFT_CLEAR_TOGGLE) {
-   xhci_warn(xhci, "Can't enqueue URB while manually clearing 
toggle\n");
-   ret = -EINVAL;
-   goto free_priv;
-   }
-
switch (usb_endpoint_type(>ep->desc)) {
case USB_ENDPOINT_XFER_CONTROL:
ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb,
@@ -1380,7 +1378,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
}
 
if (ret) {
-free_priv:
xhci_urb_free_priv(urb_priv);
urb->hcpriv = NULL;
}
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/20] usb: host: xhci: introduce xhci_num_tds_for_urb() helper

2018-04-16 Thread Felipe Balbi
This helper computes the number of TDs for a given urb. Cleanup only,
no functional changes.

Note that while at that we've replaced an alignment check with the
IS_ALIGNED() macro which makes the code slightly clearer about its
intention.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 26 --
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index dba4c61f5cf6..f2733f717568 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1281,6 +1281,21 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, 
unsigned int slot_id,
return ret;
 }
 
+static int xhci_num_tds_for_urb(struct urb *urb)
+{
+   if (usb_endpoint_xfer_isoc(>ep->desc))
+   return urb->number_of_packets;
+
+   if (usb_endpoint_is_bulk_out(>ep->desc) &&
+   urb->transfer_buffer_length > 0 &&
+   urb->transfer_flags & URB_ZERO_PACKET &&
+   IS_ALIGNED(urb->transfer_buffer_length,
+   usb_endpoint_maxp(>ep->desc)))
+   return 2;
+
+   return 1;
+}
+
 /*
  * non-error returns are a promise to giveback() the urb later
  * we drop ownership so next owner (or urb unlink) can get it
@@ -1327,16 +1342,7 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
}
}
 
-   if (usb_endpoint_xfer_isoc(>ep->desc))
-   num_tds = urb->number_of_packets;
-   else if (usb_endpoint_is_bulk_out(>ep->desc) &&
-   urb->transfer_buffer_length > 0 &&
-   urb->transfer_flags & URB_ZERO_PACKET &&
-   !(urb->transfer_buffer_length % usb_endpoint_maxp(>ep->desc)))
-   num_tds = 2;
-   else
-   num_tds = 1;
-
+   num_tds = xhci_num_tds_for_urb(urb);
urb_priv = kzalloc(sizeof(struct urb_priv) +
   num_tds * sizeof(struct xhci_td), mem_flags);
if (!urb_priv)
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 04/20] usb: host: xhci: check HCD_HW_ACCESSIBLE earlier

2018-04-16 Thread Felipe Balbi
This is the last check that can be done earlier. No functional
changes.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 284dc6c10189..dba4c61f5cf6 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1305,6 +1305,12 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
return -ESHUTDOWN;
}
 
+   if (!HCD_HW_ACCESSIBLE(hcd)) {
+   if (!in_interrupt())
+   xhci_dbg(xhci, "urb submitted during PCI suspend\n");
+   return -ESHUTDOWN;
+   }
+
slot_id = urb->dev->slot_id;
ep_index = xhci_get_endpoint_index(>ep->desc);
ep_state = >devs[slot_id]->eps[ep_index].ep_state;
@@ -1321,12 +1327,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
}
}
 
-   if (!HCD_HW_ACCESSIBLE(hcd)) {
-   if (!in_interrupt())
-   xhci_dbg(xhci, "urb submitted during PCI suspend\n");
-   return -ESHUTDOWN;
-   }
-
if (usb_endpoint_xfer_isoc(>ep->desc))
num_tds = urb->number_of_packets;
else if (usb_endpoint_is_bulk_out(>ep->desc) &&
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 15/20] usb: host: xhci: rename xhci_queue_isoc_tx_prepare()

2018-04-16 Thread Felipe Balbi
cleanup only, no functional changes.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci-ring.c | 6 +++---
 drivers/usb/host/xhci.c  | 2 +-
 drivers/usb/host/xhci.h  | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index e9c6053f90c5..c2726f02e927 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3627,7 +3627,7 @@ static int xhci_get_isoc_frame_id(struct xhci_hcd *xhci,
 }
 
 /* This is for isoc transfer */
-static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
+static int __xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
struct urb *urb, int slot_id, unsigned int ep_index)
 {
struct xhci_ring *ep_ring;
@@ -3822,7 +3822,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, 
gfp_t mem_flags,
  * update urb->start_frame if URB_ISO_ASAP is set in transfer_flags or
  * Contiguous Frame ID is not supported by HC.
  */
-int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
+int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
struct urb *urb, int slot_id, unsigned int ep_index)
 {
struct xhci_virt_device *xdev;
@@ -3894,7 +3894,7 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, 
gfp_t mem_flags,
 skip_start_over:
ep_ring->num_trbs_free_temp = ep_ring->num_trbs_free;
 
-   return xhci_queue_isoc_tx(xhci, mem_flags, urb, slot_id, ep_index);
+   return __xhci_queue_isoc_tx(xhci, mem_flags, urb, slot_id, ep_index);
 }
 
 /  Command Ring Operations /
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 7d5f5cfd14eb..eefb748c2cb9 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1375,7 +1375,7 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
slot_id, ep_index);
break;
case USB_ENDPOINT_XFER_ISOC:
-   ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb,
+   ret = xhci_queue_isoc_tx(xhci, GFP_ATOMIC, urb,
slot_id, ep_index);
}
 
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index d2d30cbbf53d..039c6ccc0c2b 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -2059,7 +2059,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t 
mem_flags, struct urb *urb,
int slot_id, unsigned int ep_index);
 int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
int slot_id, unsigned int ep_index);
-int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
+int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
struct urb *urb, int slot_id, unsigned int ep_index);
 int xhci_queue_configure_endpoint(struct xhci_hcd *xhci,
struct xhci_command *cmd, dma_addr_t in_ctx_ptr, u32 slot_id,
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 13/20] usb: host: xhci: extract xhci_maybe_stop_endpoint()

2018-04-16 Thread Felipe Balbi
This new helper is only here to aid readability. It handles the
details about only queueing stop endpoint on the first URB
cancellation.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 40 +++-
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index a62f5d34eab7..a573c3a444ed 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1407,6 +1407,28 @@ static void xhci_manually_free_td(struct xhci_hcd *xhci, 
struct urb *urb)
}
 }
 
+static int xhci_maybe_stop_endpoint(struct xhci_hcd *xhci,
+   struct xhci_virt_ep *ep, struct urb *urb, unsigned int ep_index)
+{
+   struct xhci_command *command;
+
+   if (ep->ep_state & EP_STOP_CMD_PENDING)
+   return 0;
+
+   command = xhci_alloc_command(xhci, false, GFP_ATOMIC);
+   if (!command)
+   return -ENOMEM;
+
+   ep->ep_state |= EP_STOP_CMD_PENDING;
+   mod_timer(>stop_cmd_timer, jiffies +
+   XHCI_STOP_EP_CMD_TIMEOUT);
+   xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id,
+   ep_index, 0);
+   xhci_ring_cmd_db(xhci);
+
+   return 0;
+}
+
 /*
  * Remove the URB's TD from the endpoint ring.  This may cause the HC to stop
  * USB transfers, potentially stopping in the middle of a TRB buffer.  The HC
@@ -1441,7 +1463,6 @@ static void xhci_manually_free_td(struct xhci_hcd *xhci, 
struct urb *urb)
 static int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
 {
struct xhci_virt_device *vdev;
-   struct xhci_command *command;
struct xhci_ring *ep_ring;
struct urb_priv *urb_priv;
struct xhci_virt_ep *ep;
@@ -1491,23 +1512,8 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct 
urb *urb, int status)
td = _priv->td[i];
list_add_tail(>cancelled_td_list, >cancelled_td_list);
}
+   ret = xhci_maybe_stop_endpoint(xhci, ep, urb, ep_index);
 
-   /* Queue a stop endpoint command, but only if this is
-* the first cancellation to be handled.
-*/
-   if (!(ep->ep_state & EP_STOP_CMD_PENDING)) {
-   command = xhci_alloc_command(xhci, false, GFP_ATOMIC);
-   if (!command) {
-   ret = -ENOMEM;
-   goto done;
-   }
-   ep->ep_state |= EP_STOP_CMD_PENDING;
-   mod_timer(>stop_cmd_timer, jiffies +
-   XHCI_STOP_EP_CMD_TIMEOUT);
-   xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id,
-ep_index, 0);
-   xhci_ring_cmd_db(xhci);
-   }
 done:
spin_unlock_irqrestore(>lock, flags);
return ret;
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/20] usb: host: xhci: check full speed MPS change earlier

2018-04-16 Thread Felipe Balbi
By moving Full Speed max packet size change earlier, the code becomes
a little more straight forward to read.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 27 ---
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 39e67b7bece1..284dc6c10189 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1309,6 +1309,18 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
ep_index = xhci_get_endpoint_index(>ep->desc);
ep_state = >devs[slot_id]->eps[ep_index].ep_state;
 
+   if (usb_endpoint_xfer_control(>ep->desc)) {
+   /* Check to see if the max packet size for the default control
+* endpoint changed during FS device enumeration
+*/
+   if (urb->dev->speed == USB_SPEED_FULL) {
+   ret = xhci_check_maxpacket(xhci, slot_id,
+   ep_index, urb);
+   if (ret < 0)
+   return ret;
+   }
+   }
+
if (!HCD_HW_ACCESSIBLE(hcd)) {
if (!in_interrupt())
xhci_dbg(xhci, "urb submitted during PCI suspend\n");
@@ -1336,21 +1348,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
 
trace_xhci_urb_enqueue(urb);
 
-   if (usb_endpoint_xfer_control(>ep->desc)) {
-   /* Check to see if the max packet size for the default control
-* endpoint changed during FS device enumeration
-*/
-   if (urb->dev->speed == USB_SPEED_FULL) {
-   ret = xhci_check_maxpacket(xhci, slot_id,
-   ep_index, urb);
-   if (ret < 0) {
-   xhci_urb_free_priv(urb_priv);
-   urb->hcpriv = NULL;
-   return ret;
-   }
-   }
-   }
-
spin_lock_irqsave(>lock, flags);
 
if (*ep_state & EP_SOFT_CLEAR_TOGGLE) {
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 16/20] usb: host: xhci: remove unnecessary NULL check

2018-04-16 Thread Felipe Balbi
xhci_urb_free_priv() is a simple wrapper around kfree() and kfree() is
safe against NULL pointers.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index eefb748c2cb9..4c2bc9d1678e 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1525,8 +1525,7 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct 
urb *urb, int status)
return ret;
 
 err_giveback:
-   if (urb_priv)
-   xhci_urb_free_priv(urb_priv);
+   xhci_urb_free_priv(urb_priv);
usb_hcd_unlink_urb_from_ep(hcd, urb);
spin_unlock_irqrestore(>lock, flags);
usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN);
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 14/20] usb: host: xhci: extract xhci_cancel_td()

2018-04-16 Thread Felipe Balbi
This little helper is here for readability. It handles the details
about how to cancel a TD due to an urb being dequeued.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index a573c3a444ed..7d5f5cfd14eb 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1429,6 +1429,17 @@ static int xhci_maybe_stop_endpoint(struct xhci_hcd 
*xhci,
return 0;
 }
 
+static void xhci_cancel_td(struct xhci_virt_ep *ep, struct urb *urb)
+{
+   struct urb_priv *urb_priv = urb->hcpriv;
+   int i;
+
+   for (i = urb_priv->num_tds_done; i < urb_priv->num_tds; i++) {
+   struct xhci_td *td = _priv->td[i];
+   list_add_tail(>cancelled_td_list, >cancelled_td_list);
+   }
+}
+
 /*
  * Remove the URB's TD from the endpoint ring.  This may cause the HC to stop
  * USB transfers, potentially stopping in the middle of a TRB buffer.  The HC
@@ -1467,12 +1478,10 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct 
urb *urb, int status)
struct urb_priv *urb_priv;
struct xhci_virt_ep *ep;
struct xhci_hcd *xhci;
-   struct xhci_td *td;
unsigned long flags;
unsigned int ep_index;
u32 temp;
int ret;
-   int i;
 
xhci = hcd_to_xhci(hcd);
spin_lock_irqsave(>lock, flags);
@@ -1508,10 +1517,7 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct 
urb *urb, int status)
goto err_giveback;
}
 
-   for (i = urb_priv->num_tds_done; i < urb_priv->num_tds; i++) {
-   td = _priv->td[i];
-   list_add_tail(>cancelled_td_list, >cancelled_td_list);
-   }
+   xhci_cancel_td(ep, urb);
ret = xhci_maybe_stop_endpoint(xhci, ep, urb, ep_index);
 
 done:
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 08/20] usb: host: xhci: convert add_timer() to mod_timer() calls

2018-04-16 Thread Felipe Balbi
Instead of initializing t->expires and calling add_timer(t) right
after, we can rely on mod_timer(t, expires) to handle the details for
us.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 663eac3c8a1b..64eb50115fac 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -446,10 +446,8 @@ static void compliance_mode_recovery_timer_init(struct 
xhci_hcd *xhci)
xhci->port_status_u0 = 0;
timer_setup(>comp_mode_recovery_timer, compliance_mode_recovery,
0);
-   xhci->comp_mode_recovery_timer.expires = jiffies +
-   msecs_to_jiffies(COMP_MODE_RCVRY_MSECS);
-
-   add_timer(>comp_mode_recovery_timer);
+   mod_timer(>comp_mode_recovery_timer, jiffies +
+   msecs_to_jiffies(COMP_MODE_RCVRY_MSECS));
xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
"Compliance mode recovery timer initialized");
 }
@@ -1505,8 +1503,8 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct 
urb *urb, int status)
goto done;
}
ep->ep_state |= EP_STOP_CMD_PENDING;
-   ep->stop_cmd_timer.expires = jiffies + XHCI_STOP_EP_CMD_TIMEOUT;
-   add_timer(>stop_cmd_timer);
+   mod_timer(>stop_cmd_timer, jiffies +
+   XHCI_STOP_EP_CMD_TIMEOUT);
xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id,
 ep_index, 0);
xhci_ring_cmd_db(xhci);
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 12/20] usb: host: xhci: remove pointless trace message

2018-04-16 Thread Felipe Balbi
That message doesn't bring a lot of extra information. What it prints
can be understood from the existing tracepoints.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 13 +
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 5d2c24f58b34..a62f5d34eab7 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1487,18 +1487,7 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct 
urb *urb, int status)
goto err_giveback;
}
 
-   i = urb_priv->num_tds_done;
-   if (i < urb_priv->num_tds)
-   xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
-   "Cancel URB %p, dev %s, ep 0x%x, "
-   "starting at offset 0x%llx",
-   urb, urb->dev->devpath,
-   urb->ep->desc.bEndpointAddress,
-   (unsigned long long) xhci_trb_virt_to_dma(
-   urb_priv->td[i].start_seg,
-   urb_priv->td[i].first_trb));
-
-   for (; i < urb_priv->num_tds; i++) {
+   for (i = urb_priv->num_tds_done; i < urb_priv->num_tds; i++) {
td = _priv->td[i];
list_add_tail(>cancelled_td_list, >cancelled_td_list);
}
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/20] usb: host: xhci: check DYING state earlier

2018-04-16 Thread Felipe Balbi
in case where xHCI dies, we can bail out a little earlier. Not really
a functional change, just making the code follow a more
straight-forward order.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 3b19444aa1f3..6be3eb721157 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1444,6 +1444,13 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct 
urb *urb, int status)
if (ret)
goto done;
 
+   /* If xHC is dead take it down and return ALL URBs in xhci_hc_died() */
+   temp = readl(>op_regs->status);
+   if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) {
+   xhci_hc_died(xhci);
+   goto done;
+   }
+
/* give back URB now if we can't queue it for cancel */
vdev = xhci->devs[urb->dev->slot_id];
urb_priv = urb->hcpriv;
@@ -1456,13 +1463,6 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct 
urb *urb, int status)
if (!ep || !ep_ring)
goto err_giveback;
 
-   /* If xHC is dead take it down and return ALL URBs in xhci_hc_died() */
-   temp = readl(>op_regs->status);
-   if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) {
-   xhci_hc_died(xhci);
-   goto done;
-   }
-
if (xhci->xhc_state & XHCI_STATE_HALTED) {
xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
"HC halted, freeing TD manually.");
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/20] usb: host: xhci: reorder variable declarations

2018-04-16 Thread Felipe Balbi
cleanup only, no functional changes

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 64eb50115fac..3b19444aa1f3 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1421,17 +1421,18 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
  */
 static int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
 {
-   unsigned long flags;
-   int ret, i;
-   u32 temp;
-   struct xhci_hcd *xhci;
+   struct xhci_virt_device *vdev;
+   struct xhci_command *command;
+   struct xhci_ring *ep_ring;
struct urb_priv *urb_priv;
+   struct xhci_virt_ep *ep;
+   struct xhci_hcd *xhci;
struct xhci_td *td;
+   unsigned long flags;
unsigned int ep_index;
-   struct xhci_ring *ep_ring;
-   struct xhci_virt_ep *ep;
-   struct xhci_command *command;
-   struct xhci_virt_device *vdev;
+   u32 temp;
+   int ret;
+   int i;
 
xhci = hcd_to_xhci(hcd);
spin_lock_irqsave(>lock, flags);
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/20] usb: host: xhci: extract xhci_manually_free_td() helper

2018-04-16 Thread Felipe Balbi
Cleanup only, no functional changes.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 6be3eb721157..5d2c24f58b34 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1388,6 +1388,25 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
return ret;
 }
 
+static void xhci_manually_free_td(struct xhci_hcd *xhci, struct urb *urb)
+{
+   struct urb_priv *urb_priv = urb->hcpriv;
+   int i;
+
+   xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
+   "HC halted, freeing TD manually.");
+
+   for (i = urb_priv->num_tds_done; i < urb_priv->num_tds; i++) {
+   struct xhci_td *td = _priv->td[i];
+
+   if (!list_empty(>td_list))
+   list_del_init(>td_list);
+
+   if (!list_empty(>cancelled_td_list))
+   list_del_init(>cancelled_td_list);
+   }
+}
+
 /*
  * Remove the URB's TD from the endpoint ring.  This may cause the HC to stop
  * USB transfers, potentially stopping in the middle of a TRB buffer.  The HC
@@ -1464,17 +1483,7 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct 
urb *urb, int status)
goto err_giveback;
 
if (xhci->xhc_state & XHCI_STATE_HALTED) {
-   xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
-   "HC halted, freeing TD manually.");
-   for (i = urb_priv->num_tds_done;
-i < urb_priv->num_tds;
-i++) {
-   td = _priv->td[i];
-   if (!list_empty(>td_list))
-   list_del_init(>td_list);
-   if (!list_empty(>cancelled_td_list))
-   list_del_init(>cancelled_td_list);
-   }
+   xhci_manually_free_td(xhci, urb);
goto err_giveback;
}
 
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/20] usb: host: xhci: check DYING state earlier

2018-04-16 Thread Felipe Balbi
Instead of allocating urb priv and, maybe, bail out due to xhci being
in DYING state, we can move the check earlier and avoid the memory
allocation altogether.

While at that, also remove an unnecessary empty line.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 65c454b94165..39e67b7bece1 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1299,6 +1299,12 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
true, true, __func__) <= 0)
return -EINVAL;
 
+   if (xhci->xhc_state & XHCI_STATE_DYING) {
+   xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive 
xHCI host.\n",
+urb->ep->desc.bEndpointAddress, urb);
+   return -ESHUTDOWN;
+   }
+
slot_id = urb->dev->slot_id;
ep_index = xhci_get_endpoint_index(>ep->desc);
ep_state = >devs[slot_id]->eps[ep_index].ep_state;
@@ -1347,12 +1353,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
 
spin_lock_irqsave(>lock, flags);
 
-   if (xhci->xhc_state & XHCI_STATE_DYING) {
-   xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive 
xHCI host.\n",
-urb->ep->desc.bEndpointAddress, urb);
-   ret = -ESHUTDOWN;
-   goto free_priv;
-   }
if (*ep_state & EP_SOFT_CLEAR_TOGGLE) {
xhci_warn(xhci, "Can't enqueue URB while manually clearing 
toggle\n");
ret = -EINVAL;
@@ -1360,7 +1360,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct 
urb *urb, gfp_t mem_flag
}
 
switch (usb_endpoint_type(>ep->desc)) {
-
case USB_ENDPOINT_XFER_CONTROL:
ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb,
 slot_id, ep_index);
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/20] usb: host: xhci: use msecs_to_jiffies() instead of HZ

2018-04-16 Thread Felipe Balbi
HZ can change based on CPUFreq. We should use msecs_to_jiffies()
instead.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci.c | 3 +--
 drivers/usb/host/xhci.h | 6 +++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index eec9e0c0b7c9..663eac3c8a1b 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1505,8 +1505,7 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct 
urb *urb, int status)
goto done;
}
ep->ep_state |= EP_STOP_CMD_PENDING;
-   ep->stop_cmd_timer.expires = jiffies +
-   XHCI_STOP_EP_CMD_TIMEOUT * HZ;
+   ep->stop_cmd_timer.expires = jiffies + XHCI_STOP_EP_CMD_TIMEOUT;
add_timer(>stop_cmd_timer);
xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id,
 ep_index, 0);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 05c909b04f14..d2d30cbbf53d 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1518,7 +1518,7 @@ struct xhci_td {
 };
 
 /* xHCI command default timeout value */
-#define XHCI_CMD_DEFAULT_TIMEOUT   (5 * HZ)
+#define XHCI_CMD_DEFAULT_TIMEOUT   (msecs_to_jiffies(5000))
 
 /* command descriptor */
 struct xhci_cd {
@@ -1630,8 +1630,8 @@ struct urb_priv {
 #defineERST_ENTRIES1
 /* Poll every 60 seconds */
 #definePOLL_TIMEOUT60
-/* Stop endpoint command timeout (secs) for URB cancellation watchdog timer */
-#define XHCI_STOP_EP_CMD_TIMEOUT   5
+/* Stop endpoint command timeout (jiffies) for URB cancellation watchdog timer 
*/
+#define XHCI_STOP_EP_CMD_TIMEOUT   (msecs_to_jiffies(5000))
 /* XXX: Make these module parameters */
 
 struct s3_save {
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v4 02/13] dt-bindings: usb: add documentation for typec port controller(TCPCI)

2018-04-16 Thread Jun Li
Hi
> -Original Message-
> From: Rob Herring [mailto:r...@kernel.org]
> Sent: 2018年4月10日 4:04
> To: Jun Li 
> Cc: gre...@linuxfoundation.org; heikki.kroge...@linux.intel.com;
> li...@roeck-us.net; a.ha...@samsung.com; shufan_...@richtek.com; Peter
> Chen ; devicet...@vger.kernel.org;
> linux-usb@vger.kernel.org; dl-linux-imx ;
> de...@driverdev.osuosl.org
> Subject: Re: [PATCH v4 02/13] dt-bindings: usb: add documentation for typec
> port controller(TCPCI)
> 
> On Thu, Mar 29, 2018 at 12:06:07AM +0800, Li Jun wrote:
> > TCPCI stands for typec port controller interface, its implementation
> > has full typec port control with power delivery support, it's a
> > standard i2c slave with GPIO input as irq interface, detail see spec
> > "Universal Serial Bus Type-C Port Controller Interface Specification
> > Revision 1.0, Version 1.1"
> >
> > Signed-off-by: Li Jun 
> > ---
> >  .../devicetree/bindings/usb/typec-tcpci.txt| 33
> ++
> >  1 file changed, 33 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/usb/typec-tcpci.txt
> > b/Documentation/devicetree/bindings/usb/typec-tcpci.txt
> > new file mode 100644
> > index 000..7a7a8e0
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/usb/typec-tcpci.txt
> > @@ -0,0 +1,33 @@
> > +TCPCI(Typec port cotroller interface) binding
> > +-
> > +
> > +Required properties:
> > +- compatible:   should be "usb-tcpci,chip-specific-string".
> 
> Compatible strings should be in the form of ","
> 

OK, I will list the specific compatible string here and change
my example case to be "nxp,ptn5110".

> > +- reg:  the i2c slave address of typec port controller device.
> > +- interrupt-parent: the phandle to the interrupt controller which provides
> > +the interrupt.
> > +- interrupts:   interrupt specification for tcpci alert.
> > +
> > +Required sub-node:
> > +- connector: The "usb-c-connector" attached to the tcpci chip, the
> > +bindings
> > +  of connector node are specified in
> > +  Documentation/devicetree/bindings/connector/usb-connector.txt
> > +
> > +Example:
> > +
> > +ptn5110@50 {
> > +   compatible = "usb-tcpci,ptn5110";
> > +   reg = <0x50>;
> > +   interrupt-parent = <>;
> > +   interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
> > +
> > +   usb_con: connector {
> 
> How is the OF graph done in this case? You need some link to the USB 
> controller.

The platform(i.MX8MQ EVK) for this is still on the way of start upstream, I was
Planning to add this part with enabling USB3 function, as of how this will be 
done,
I only have usb3 ss data(no display port or Sideband), is something like below 
OK?

typec: ptn5110@50 {
compatible = "nxp,ptn5110";
...

usb_con: connector {
compatible = "usb-c-connector";
label = "USB-C";
...

ports {
#address-cells = <1>;
#size-cells = <0>;

port@1 {
reg = <1>;
usb_con_ss: endpoint {
remote-endpoint = <_phy_ss>;
};
};
};
};
};

_phy0 {
status = "okay";

port {
usb3_phy_ss: endpoint {
remote-endpoint = <_con_ss>;
};
};
}

Thanks
Jun
> 
> > +   compatible = "usb-c-connector";
> > +   label = "USB-C";
> > +   port-type = "dual";
> > +   try-power-role = "sink"
> > +   source-pdos = <0x380190c8>;
> > +   sink-pdos = <0x380190c8 0x3802d0c8>;
> > +   op-sink-microwatt-hours = <900>;
> > +   };
> > +};
> > --
> > 2.7.4
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe devicetree"
> > in the body of a message to majord...@vger.kernel.org More majordomo
> > info at
> > https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fvger
> > .kernel.org%2Fmajordomo-info.html=02%7C01%7Cjun.li%40nxp.com%7C
> 86
> >
> a7c0da18204df434d208d59e550c27%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0
> %
> >
> 7C0%7C636589010562193065=0%2FmoDrqWn9YghWGucWYnMd1YK0BO2
> dVgp%2Fa
> > KNZZZ%2BXE%3D=0


Re: Since Linux 4.13 tlp or powertop usage cause "xHCI host controller not responding, assume dead" on Dell 5855

2018-04-16 Thread Mathias Nyman

On 10.04.2018 12:15, russianneuroman...@ya.ru wrote:

Hello!

On Dell Venue 8 Pro 5855 tablet installing tlp or running "powertop --
auto-tune" cause "xHCI host controller not responding, assume dead"
error, when error happen two integrated USB devices (Bluetooth adapter
and LTE modem) disappear until reboot. First time this issue was
observer in Linux 4.13 and still present in Linux 4.16. Blacklisting
both "Linux Foundation 3.0 root hub" from autosuspend in tlp
configuration is workaround for this issue, however on other devices
tlp works fine without blacklisting usb hub autosuspend, and on this
tablet there was no such issue before (at least in Linux ~4.8-4.12
range) so I assume there is regression somewhere.

Is there any related commits between 4.12 and 4.13 that I could try to
revert?



In 4.12 there was a added sensitivity to react to hotplug removed
xhc controllers, i.e. if we read 0x from a xhci register
we assume host is removed and start cleaning up.

commit d9f11ba9f107aa335091ab8d7ba5eea714e46e8b
xhci: Rework how we handle unresponsive or hoptlug removed hosts

You can try to revert that, but as a final solution we should
find the real rootcause


How issue looks like in logs:

[  227.258385] xhci_hcd :00:14.0: xHC is not running.
[  329.671544] xhci_hcd :00:14.0: xHC is not running.
[  416.695796] xhci_hcd :00:14.0: xHC is not running.


The "xHC is not running" is the xhci driver handing a port event
interrupt for a resuming port, but whole host controller is not running.
We stop the host controller in xhci_suspend(), and start it in xhci_resume()

Attaching a patch that improves preventing xhci host suspend during
USB2 resume signaling.
Could help, worth a shot.


[  416.695862] xhci_hcd :00:14.0: xHCI host controller not
responding, assume dead


This means xhci_hc_died() was called, many possible places.
Adding the code below could give a hint:

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index daa94c3..51fb3d0 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -900,7 +900,8 @@ void xhci_hc_died(struct xhci_hcd *xhci)
if (xhci->xhc_state & XHCI_STATE_DYING)
return;
 
-   xhci_err(xhci, "xHCI host controller not responding, assume dead\n");

+   xhci_err(xhci, "%ps: xHCI host controller not responding, assume 
dead\n",
+__builtin_return_address(0));
xhci->xhc_state |= XHCI_STATE_DYING;
 
xhci_cleanup_command_queue(xhci);



[  416.695900] xhci_hcd :00:14.0: HC died; cleaning up
[  416.696052] usb 1-3: USB disconnect, device number 2
[  416.815610] cdc_mbim 1-3:1.12 wwp0s20u3i12: unregister 'cdc_mbim'
usb-:00:14.0-3, CDC MBIM
[  416.847934] usb 1-4: USB disconnect, device number 3

After that Bluetooth adapter and LTE modem disappear from lsusb output,
while xHCI controller itself remain visible.


we stop the host activity in xhci_hc_died(), no usb devices under this host 
will work.


Complete dmesg: https://paste.fedoraproject.org/paste/7aMpVGLfZ82zppdGs
56Oqg
lsusb -v: https://paste.fedoraproject.org/paste/c7y8GisC13YdzcYE9B-JIw
dsdt.dsl: https://paste.fedoraproject.org/paste/8g6mp2dafypUkFT4sa43iA


xhci traces and dynamic debug could help:

mount -t debugfs none /sys/kernel/debug
echo 81920 > /sys/kernel/debug/tracing/buffer_size_kb
echo 1 > /sys/kernel/debug/tracing/events/xhci-hcd/enable

echo -n 'module xhci_hcd =p' > /sys/kernel/debug/dynamic_debug/control

-Mathias
>From 090b13a6df3f489a9781223dd959e03c2f81347b Mon Sep 17 00:00:00 2001
From: Mathias Nyman 
Date: Thu, 1 Mar 2018 18:48:32 +0200
Subject: [PATCH] xhci: prevent USB 2 roothub autosuspend during port resume
 signaling

xhci USB 2 roothub tries to autosuspended itself again immediately after
being resumed by a remote wake. This can be avoided by calling the
usb_hcd_start_port_resume() and usb_hcd_end_port_resume() implemented
especially for this purpose.

Use them, and prevent roothub autosuspend during resume signaling.

Suggested-by: Anshuman Gupta 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-hub.c  | 3 +++
 drivers/usb/host/xhci-ring.c | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 72ebbc9..671a336 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -905,6 +905,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
 
 set_bit(wIndex, _state->resuming_ports);
 bus_state->resume_done[wIndex] = timeout;
+usb_hcd_start_port_resume(>self, wIndex);
 mod_timer(>rh_timer, timeout);
 			}
 		/* Has resume been signalled for USB_RESUME_TIME yet? */
@@ -930,6 +931,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
 	msecs_to_jiffies(
 		XHCI_MAX_REXIT_TIMEOUT));
 			spin_lock_irqsave(>lock, flags);
+			usb_hcd_end_port_resume(>self, wIndex);
 

Re: [PATCH] usb: mon: Change return type to vm_fault_t

2018-04-16 Thread Souptick Joarder
On Mon, Apr 16, 2018 at 1:17 PM, Greg KH  wrote:
> On Sun, Apr 15, 2018 at 04:10:08AM -0700, Matthew Wilcox wrote:
>> On Sun, Apr 15, 2018 at 07:49:16AM +0200, Greg KH wrote:
>> > On Sun, Apr 15, 2018 at 12:36:02AM +0530, Souptick Joarder wrote:
>> > > Use new return type vm_fault_t for fault handler
>> > > in struct vm_operations_struct.
>> >
>> > Why?
>>
>> commit 1c8f422059ae5da07db7406ab916203f9417e396
>> Author: Souptick Joarder 
>> Date:   Thu Apr 5 16:25:23 2018 -0700
>>
>> mm: change return type to vm_fault_t
>>
>> The plan for these patches is to introduce the typedef, initially just
>> as documentation ("These functions should return a VM_FAULT_ status").
>> We'll trickle the patches to individual drivers/filesystems in through
>> the maintainers, as far as possible.  Then we'll change the typedef to
>> an unsigned int and break the compilation of any unconverted
>> drivers/filesystems.
>>
>> vmf_insert_page(), vmf_insert_mixed() and vmf_insert_pfn() are three
>> newly added functions.  The various drivers/filesystems where return
>> value of fault(), huge_fault(), page_mkwrite() and pfn_mkwrite() get
>> converted, will need them.  These functions will return correct
>> VM_FAULT_ code based on err value.
>>
>> We've had bugs before where drivers returned -EFOO.  And we have this
>> silly inefficiency where vm_insert_xxx() return an errno which (afaict)
>> every driver then converts into a VM_FAULT code.  In many cases drivers
>> failed to return correct VM_FAULT code value despite of vm_insert_xxx()
>> fails.  We have indentified and clean up all those existing bugs and
>> silly inefficiencies in driver/filesystems by adding these three new
>> inline wrappers.  As mentioned above, we will trickle those patches to
>> individual drivers/filesystems in through maintainers after these three
>> wrapper functions are merged.
>
> Then put a summary of this type of thing in the original patch please!

Ok, I will add it in change log and send v2.
>
> When a maintainer gets a patch with no context at all, the first
> reaction is to just reject it (especially as many of these patches were
> sent privately and did not go on any public mailing list, those all got
> automatically dropped...)

For few drivers only maintainers name is mentioned without any mailing list
in Maintainer file. Not sure which mailing list to add for the same.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] usb: gadget: udc: atmel: Remove obsolete include

2018-04-16 Thread Ludovic Desroches
On Mon, Apr 16, 2018 at 11:34:04AM +0200, Romain Izard wrote:
> The include defines the private platform_data structure used with AVR
> platforms. It has no user since 7c55984e191f. Remove it.
> 
> Signed-off-by: Romain Izard 
Acked-by: Ludovic Desroches 
> ---
>  drivers/usb/gadget/udc/atmel_usba_udc.c |  1 -
>  include/linux/usb/atmel_usba_udc.h  | 24 
>  2 files changed, 25 deletions(-)
>  delete mode 100644 include/linux/usb/atmel_usba_udc.h
> 
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index 0fe3d0feb8f7..b9623e228609 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -20,7 +20,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> diff --git a/include/linux/usb/atmel_usba_udc.h 
> b/include/linux/usb/atmel_usba_udc.h
> deleted file mode 100644
> index 9bb00df3b53f..
> --- a/include/linux/usb/atmel_usba_udc.h
> +++ /dev/null
> @@ -1,24 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -/*
> - * Platform data definitions for Atmel USBA gadget driver.
> - */
> -#ifndef __LINUX_USB_USBA_H
> -#define __LINUX_USB_USBA_H
> -
> -struct usba_ep_data {
> - char*name;
> - int index;
> - int fifo_size;
> - int nr_banks;
> - int can_dma;
> - int can_isoc;
> -};
> -
> -struct usba_platform_data {
> - int vbus_pin;
> - int vbus_pin_inverted;
> - int num_ep;
> - struct usba_ep_data ep[0];
> -};
> -
> -#endif /* __LINUX_USB_USBA_H */
> -- 
> 2.14.1
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] usb: gadget: udc: atmel: Fix indenting

2018-04-16 Thread Ludovic Desroches
On Mon, Apr 16, 2018 at 11:34:05AM +0200, Romain Izard wrote:
> Fix the fallout of the conversion to GPIO descriptors in 3df034081021.
> 
> Signed-off-by: Romain Izard 
Acked-by: Ludovic Desroches 
> ---
>  drivers/usb/gadget/udc/atmel_usba_udc.c | 18 +-
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index b9623e228609..2f586f2bda7e 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -2277,15 +2277,15 @@ static int usba_udc_probe(struct platform_device 
> *pdev)
>   if (udc->vbus_pin) {
>   irq_set_status_flags(gpiod_to_irq(udc->vbus_pin), IRQ_NOAUTOEN);
>   ret = devm_request_threaded_irq(>dev,
> - gpiod_to_irq(udc->vbus_pin), NULL,
> - usba_vbus_irq_thread, 
> USBA_VBUS_IRQFLAGS,
> - "atmel_usba_udc", udc);
> - if (ret) {
> - udc->vbus_pin = NULL;
> - dev_warn(>pdev->dev,
> -  "failed to request vbus irq; "
> -  "assuming always on\n");
> - }
> + gpiod_to_irq(udc->vbus_pin), NULL,
> + usba_vbus_irq_thread, USBA_VBUS_IRQFLAGS,
> + "atmel_usba_udc", udc);
> + if (ret) {
> + udc->vbus_pin = NULL;
> + dev_warn(>pdev->dev,
> +  "failed to request vbus irq; "
> +  "assuming always on\n");
> + }
>   }
>  
>   ret = usb_add_gadget_udc(>dev, >gadget);
> -- 
> 2.14.1
> 
> 
> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3] usb: gadget: udc: atmel: GPIO inversion is handled by gpiod

2018-04-16 Thread Ludovic Desroches
On Mon, Apr 16, 2018 at 11:34:03AM +0200, Romain Izard wrote:
> When converting to GPIO descriptors, gpiod_get_value automatically
> handles the line inversion flags from the device tree.

Thanks, I totally missed it.

Regards

> 
> Do not invert the line twice.
> 
> Fixes: 3df034081021fa4b6967ce3364bc7d867ec1c870
> 
> Signed-off-by: Romain Izard 
Acked-by: Ludovic Desroches 

> ---
>  drivers/usb/gadget/udc/atmel_usba_udc.c | 3 +--
>  drivers/usb/gadget/udc/atmel_usba_udc.h | 1 -
>  2 files changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index 27c16399c7e8..0fe3d0feb8f7 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -417,7 +417,7 @@ static inline void usba_int_enb_set(struct usba_udc *udc, 
> u32 val)
>  static int vbus_is_present(struct usba_udc *udc)
>  {
>   if (udc->vbus_pin)
> - return gpiod_get_value(udc->vbus_pin) ^ udc->vbus_pin_inverted;
> + return gpiod_get_value(udc->vbus_pin);
>  
>   /* No Vbus detection: Assume always present */
>   return 1;
> @@ -2076,7 +2076,6 @@ static struct usba_ep * atmel_udc_of_init(struct 
> platform_device *pdev,
>  
>   udc->vbus_pin = devm_gpiod_get_optional(>dev, "atmel,vbus",
>   GPIOD_IN);
> - udc->vbus_pin_inverted = gpiod_is_active_low(udc->vbus_pin);
>  
>   if (fifo_mode == 0) {
>   pp = NULL;
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.h 
> b/drivers/usb/gadget/udc/atmel_usba_udc.h
> index 969ce8f3c3e2..d7eb7cf4fd5c 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.h
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.h
> @@ -326,7 +326,6 @@ struct usba_udc {
>   const struct usba_udc_errata *errata;
>   int irq;
>   struct gpio_desc *vbus_pin;
> - int vbus_pin_inverted;
>   int num_ep;
>   int configured_ep;
>   struct usba_fifo_cfg *fifo_cfg;
> -- 
> 2.14.1
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Fwd: usb: uas: device reset most the time while enumeration- usb3.0

2018-04-16 Thread Tushar Nimkar

On 2018-04-05 11:31, Felipe Balbi wrote:

Hi,

it would help if you would Cc XHCI's maintainer :-)

tnim...@codeaurora.org writes:


On 2018-04-04 19:28, Greg KH wrote:
On Wed, Apr 04, 2018 at 06:41:41PM +0530, tnim...@codeaurora.org 
wrote:

On 2018-04-04 18:07, Greg KH wrote:
> On Wed, Apr 04, 2018 at 05:14:50PM +0530, tnim...@codeaurora.org wrote:
> > Hi Oliver/Greg,
> >
> > I am able to duplicated the UAS issue on 4.16 as well.
> > The behavior is same new usb device detects and reset after aprox 30
> > sec(SD_TIMEOUT)
> > Logs are already shared below.
> >
> > We are using Synopsys dwc3 as host controller, May I know have
> > tested it
> > with dwc3?
> > I have tried it on Linux PC (x86 Ubuntu machine) I could not see the
> > issue.
> > It enumerates well.
>
> Great, stick with an x86 platform!  :)
>
> Looks like a dwc3 host controller issue, try enabling tracing and
> debugging in that driver when this happens to see what is going on.

Oh if so let me enable the trace for that. I will respond you on 
this.


I did not get much clue, Greg.  sometime this device enumerates well,
attached both working and non working case logs.
following is not working case
root@OpenWrt:/# dmesg
[57213.906164] xhci-hcd xhci-hcd.0.auto: Port Status Change Event for
port 2
[57213.906172] xhci-hcd xhci-hcd.0.auto: resume root hub
[57213.906183] xhci-hcd xhci-hcd.0.auto: handle_port_status: starting
port polling.
[57213.906243] xhci-hcd xhci-hcd.0.auto: get port status, actual port 
0

status  = 0x21203
[57213.906246] xhci-hcd xhci-hcd.0.auto: Get port status returned
0x10203
[57213.906275] xhci-hcd xhci-hcd.0.auto: clear port connect change,
actual port 0 status  = 0x1203
[57214.005073] xhci-hcd xhci-hcd.0.auto: xhci_hub_status_data: 
stopping

port polling.
[57214.013094] xhci-hcd xhci-hcd.0.auto: get port status, actual port 
0

status  = 0x1203
[57214.013098] xhci-hcd xhci-hcd.0.auto: Get port status returned 
0x203

[57214.013117] xhci-hcd xhci-hcd.0.auto: // Ding dong!
[57214.013142] xhci-hcd xhci-hcd.0.auto: Slot 1 output ctx = 
0x7f0d8000

(dma)
[57214.013147] xhci-hcd xhci-hcd.0.auto: Slot 1 input ctx = 0x7f097000
(dma)
[57214.013160] xhci-hcd xhci-hcd.0.auto: Set slot id 1 dcbaa entry
9c24453d to 0x7f0d8000
[57214.013215] xhci-hcd xhci-hcd.0.auto: get port status, actual port 
0

status  = 0x1203
[57214.013218] xhci-hcd xhci-hcd.0.auto: Get port status returned 
0x203

[57214.013232] xhci-hcd xhci-hcd.0.auto: set port reset, actual port 0
status  = 0x1311
[57214.013240] xhci-hcd xhci-hcd.0.auto: Port Status Change Event for
port 2
[57214.013243] xhci-hcd xhci-hcd.0.auto: handle_port_status: starting
port polling.
[57214.081080] xhci-hcd xhci-hcd.0.auto: get port status, actual port 
0

status  = 0x201203
[57214.081084] xhci-hcd xhci-hcd.0.auto: Get port status returned
0x100203
[57214.081097] xhci-hcd xhci-hcd.0.auto: clear port reset change, 
actual

port 0 status  = 0x1203
[57214.081109] xhci-hcd xhci-hcd.0.auto: clear port warm(BH) reset
change, actual port 0 status  = 0x1203
[57214.081120] xhci-hcd xhci-hcd.0.auto: clear port link state change,
actual port 0 status  = 0x1203
[57214.081131] xhci-hcd xhci-hcd.0.auto: clear port connect change,
actual port 0 status  = 0x1203
[57214.081141] xhci-hcd xhci-hcd.0.auto: get port status, actual port 
0

status  = 0x1203
[57214.081144] xhci-hcd xhci-hcd.0.auto: Get port status returned 
0x203

[57214.141084] xhci-hcd xhci-hcd.0.auto: Set root hub portnum to 2
[57214.141087] xhci-hcd xhci-hcd.0.auto: Set fake root hub portnum to 
1

[57214.141091] xhci-hcd xhci-hcd.0.auto: udev->tt =   (null)
[57214.141094] xhci-hcd xhci-hcd.0.auto: udev->ttport = 0x0
[57214.141098] xhci-hcd xhci-hcd.0.auto: // Ding dong!
[57214.141131] xhci-hcd xhci-hcd.0.auto: Successful setup address
command
[57214.141136] xhci-hcd xhci-hcd.0.auto: Op regs DCBAA ptr =
0x007f041000
[57214.141140] xhci-hcd xhci-hcd.0.auto: Slot ID 1 dcbaa entry
@9c24453d = 0x007f0d8000
[57214.141144] xhci-hcd xhci-hcd.0.auto: Output Context DMA address =
0x7f0d8000
[57214.141147] xhci-hcd xhci-hcd.0.auto: Internal device address = 0
[57214.141153] xhci-hcd xhci-hcd.0.auto: Endpoint 0x0 ep reset 
callback

called
[57214.141157] usb 2-1: new SuperSpeed USB device number 12 using
xhci-hcd
[57214.167026] xhci-hcd xhci-hcd.0.auto: Waiting for status stage 
event
[57214.167123] xhci-hcd xhci-hcd.0.auto: Waiting for status stage 
event
[57214.167214] xhci-hcd xhci-hcd.0.auto: Waiting for status stage 
event
[57214.167311] xhci-hcd xhci-hcd.0.auto: Waiting for status stage 
event

[57214.167635] xhci-hcd xhci-hcd.0.auto: add ep 0x81, slot id 1, new
drop flags = 0x0, new add flags = 0x8
[57214.167659] xhci-hcd xhci-hcd.0.auto: add ep 0x2, slot id 1, new 
drop

flags = 0x0, new add flags = 0x18
[57214.167665] xhci-hcd xhci-hcd.0.auto: xhci_check_bandwidth called 
for

udev 3ae473f7
[57214.167676] xhci-hcd xhci-hcd.0.auto: // Ding dong!
[57214.167708] xhci-hcd xhci-hcd.0.auto: Successful 

Re: Fwd: usb: uas: device reset most the time while enumeration- usb3.0

2018-04-16 Thread Tushar Nimkar

On 2018-04-05 12:39, Felipe Balbi wrote:

Hi,

tnim...@codeaurora.org writes:

On 2018-04-05 11:24, Felipe Balbi wrote:

Hi,

Greg KH  writes:

On Wed, Apr 04, 2018 at 05:14:50PM +0530, tnim...@codeaurora.org
wrote:

Hi Oliver/Greg,

I am able to duplicated the UAS issue on 4.16 as well.
The behavior is same new usb device detects and reset after aprox 
30

sec(SD_TIMEOUT)
Logs are already shared below.

We are using Synopsys dwc3 as host controller, May I know have 
tested

it
with dwc3?
I have tried it on Linux PC (x86 Ubuntu machine) I could not see 
the

issue.
It enumerates well.


Great, stick with an x86 platform!  :)

Looks like a dwc3 host controller issue, try enabling tracing and
debugging in that driver when this happens to see what is going on.
Also look at all of the recent dwc3 patches that were just sent to
Linus
for 4.17-rc1 to verify if that solves the issue.


dwc3's host side is xhci compliant :-) Some revisions have some 
quirks

which may not all be supported.


Felipe, "not all be supported" do u mean some xhci compliant host do
not support uas? and they have such quirks already defined?


No. I mean that some of dwc3's host side quirks may not have 
workarounds

implemented


Tushar, which dwc3 revision are you using? Have you gotten in touch
with

it is DWC3_REVISION_300A   ..3.0a


that's rather recent...


your HW designers to ask for Errata List? A run with xhci tracepoints

will response you, let me cross check once again with errata list.


okay

there is no uas related stuff in errata list, Felipe.


--
Best Regards,
Tushar R Nimkar

QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a 
member of Code Aurora Forum, hosted by The Linux Foundation


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] usb: dwc2: gadget: Fix memory leak in dwc2_gadget_init()

2018-04-16 Thread Grigor Tovmasyan
In dwc2_gadget_init() we allocate EP0 request via
dwc2_hsotg_ep_alloc_request(). After that there are
usb_add_gadget_udc() call and if it failed, then
ctrl_req will not be freed and will cause memory leak.

Reordered function calls in gadget_init: moved up usb_add_gadget_udc()
before dwc2_hsotg_ep_alloc_request().

Tested using kmemleak.

Cc: Stefan Wahren 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/gadget.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 6c32bf26e48e..24000bda5c20 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -4679,6 +4679,10 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
INIT_LIST_HEAD(>gadget.ep_list);
hsotg->gadget.ep0 = >eps_out[0]->ep;
 
+   ret = usb_add_gadget_udc(dev, >gadget);
+   if (ret)
+   return ret;
+
/* allocate EP0 request */
 
hsotg->ctrl_req = dwc2_hsotg_ep_alloc_request(>eps_out[0]->ep,
@@ -4698,10 +4702,6 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
  epnum, 0);
}
 
-   ret = usb_add_gadget_udc(dev, >gadget);
-   if (ret)
-   return ret;
-
dwc2_hsotg_dump(hsotg);
 
return 0;
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/3] usb: gadget: udc: atmel: GPIO inversion is handled by gpiod

2018-04-16 Thread Romain Izard
When converting to GPIO descriptors, gpiod_get_value automatically
handles the line inversion flags from the device tree.

Do not invert the line twice.

Fixes: 3df034081021fa4b6967ce3364bc7d867ec1c870

Signed-off-by: Romain Izard 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 3 +--
 drivers/usb/gadget/udc/atmel_usba_udc.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 27c16399c7e8..0fe3d0feb8f7 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -417,7 +417,7 @@ static inline void usba_int_enb_set(struct usba_udc *udc, 
u32 val)
 static int vbus_is_present(struct usba_udc *udc)
 {
if (udc->vbus_pin)
-   return gpiod_get_value(udc->vbus_pin) ^ udc->vbus_pin_inverted;
+   return gpiod_get_value(udc->vbus_pin);
 
/* No Vbus detection: Assume always present */
return 1;
@@ -2076,7 +2076,6 @@ static struct usba_ep * atmel_udc_of_init(struct 
platform_device *pdev,
 
udc->vbus_pin = devm_gpiod_get_optional(>dev, "atmel,vbus",
GPIOD_IN);
-   udc->vbus_pin_inverted = gpiod_is_active_low(udc->vbus_pin);
 
if (fifo_mode == 0) {
pp = NULL;
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.h 
b/drivers/usb/gadget/udc/atmel_usba_udc.h
index 969ce8f3c3e2..d7eb7cf4fd5c 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.h
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.h
@@ -326,7 +326,6 @@ struct usba_udc {
const struct usba_udc_errata *errata;
int irq;
struct gpio_desc *vbus_pin;
-   int vbus_pin_inverted;
int num_ep;
int configured_ep;
struct usba_fifo_cfg *fifo_cfg;
-- 
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] usb: gadget: udc: atmel: Fix indenting

2018-04-16 Thread Romain Izard
Fix the fallout of the conversion to GPIO descriptors in 3df034081021.

Signed-off-by: Romain Izard 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index b9623e228609..2f586f2bda7e 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -2277,15 +2277,15 @@ static int usba_udc_probe(struct platform_device *pdev)
if (udc->vbus_pin) {
irq_set_status_flags(gpiod_to_irq(udc->vbus_pin), IRQ_NOAUTOEN);
ret = devm_request_threaded_irq(>dev,
-   gpiod_to_irq(udc->vbus_pin), NULL,
-   usba_vbus_irq_thread, 
USBA_VBUS_IRQFLAGS,
-   "atmel_usba_udc", udc);
-   if (ret) {
-   udc->vbus_pin = NULL;
-   dev_warn(>pdev->dev,
-"failed to request vbus irq; "
-"assuming always on\n");
-   }
+   gpiod_to_irq(udc->vbus_pin), NULL,
+   usba_vbus_irq_thread, USBA_VBUS_IRQFLAGS,
+   "atmel_usba_udc", udc);
+   if (ret) {
+   udc->vbus_pin = NULL;
+   dev_warn(>pdev->dev,
+"failed to request vbus irq; "
+"assuming always on\n");
+   }
}
 
ret = usb_add_gadget_udc(>dev, >gadget);
-- 
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] usb: gadget: udc: atmel: Remove obsolete include

2018-04-16 Thread Romain Izard
The include defines the private platform_data structure used with AVR
platforms. It has no user since 7c55984e191f. Remove it.

Signed-off-by: Romain Izard 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c |  1 -
 include/linux/usb/atmel_usba_udc.h  | 24 
 2 files changed, 25 deletions(-)
 delete mode 100644 include/linux/usb/atmel_usba_udc.h

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 0fe3d0feb8f7..b9623e228609 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -20,7 +20,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/include/linux/usb/atmel_usba_udc.h 
b/include/linux/usb/atmel_usba_udc.h
deleted file mode 100644
index 9bb00df3b53f..
--- a/include/linux/usb/atmel_usba_udc.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Platform data definitions for Atmel USBA gadget driver.
- */
-#ifndef __LINUX_USB_USBA_H
-#define __LINUX_USB_USBA_H
-
-struct usba_ep_data {
-   char*name;
-   int index;
-   int fifo_size;
-   int nr_banks;
-   int can_dma;
-   int can_isoc;
-};
-
-struct usba_platform_data {
-   int vbus_pin;
-   int vbus_pin_inverted;
-   int num_ep;
-   struct usba_ep_data ep[0];
-};
-
-#endif /* __LINUX_USB_USBA_H */
-- 
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/3] Fix an Atmel USBA UDC issue introducted in 4.17-rc1

2018-04-16 Thread Romain Izard
The use of GPIO descriptors takes care of inversion flags declared in
the device tree. The conversion of the Atmel USBA UDC driver introduced
in 4.17-rc1 missed it, and as a result the inversion will not work.

In addition, cleanup the code to remove an include left behind after
the suppression of the support of platform_data to declare USBA
controllers.

These changes have not been tested on any hardware, as I do not have
a board that needs to use inverted GPIOs.

Romain Izard (3):
  usb: gadget: udc: atmel: GPIO inversion is handled by gpiod
  usb: gadget: udc: atmel: Remove obsolete include
  usb: gadget: udc: atmel: Fix indenting

 drivers/usb/gadget/udc/atmel_usba_udc.c | 22 ++
 drivers/usb/gadget/udc/atmel_usba_udc.h |  1 -
 include/linux/usb/atmel_usba_udc.h  | 24 
 3 files changed, 10 insertions(+), 37 deletions(-)
 delete mode 100644 include/linux/usb/atmel_usba_udc.h

-- 
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1 0/2] usb: dwc2: gadget: Fixes for LPM

2018-04-16 Thread Minas Harutyunyan
On 4/10/2018 2:21 PM, Grigor Tovmasyan wrote:
> Here are two little fixes for LPM feature.
> 
> First one is coverity warning fix.
> 
> The Second one was asserted by Stefan Wahren.
> 
> Changes from version 0:
> 
> 1/2:
> - Instead of converting parameter in the CHECK_RANGE macro
>   to int, changed hird_threshold type from u8 to int.
> 
> 
> Grigor Tovmasyan (2):
>usb: dwc2: gadget: Fix coverity issue
>usb: dwc2: gadget: Change LPM default values
> 
>   drivers/usb/dwc2/core.h   | 2 +-
>   drivers/usb/dwc2/params.c | 8 
>   2 files changed, 5 insertions(+), 5 deletions(-)
> 

Acked-by: Minas Harutyunyan 
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: mon: Change return type to vm_fault_t

2018-04-16 Thread Greg KH
On Sun, Apr 15, 2018 at 04:10:08AM -0700, Matthew Wilcox wrote:
> On Sun, Apr 15, 2018 at 07:49:16AM +0200, Greg KH wrote:
> > On Sun, Apr 15, 2018 at 12:36:02AM +0530, Souptick Joarder wrote:
> > > Use new return type vm_fault_t for fault handler
> > > in struct vm_operations_struct.
> > 
> > Why?
> 
> commit 1c8f422059ae5da07db7406ab916203f9417e396
> Author: Souptick Joarder 
> Date:   Thu Apr 5 16:25:23 2018 -0700
> 
> mm: change return type to vm_fault_t
> 
> The plan for these patches is to introduce the typedef, initially just
> as documentation ("These functions should return a VM_FAULT_ status").
> We'll trickle the patches to individual drivers/filesystems in through
> the maintainers, as far as possible.  Then we'll change the typedef to
> an unsigned int and break the compilation of any unconverted
> drivers/filesystems.
> 
> vmf_insert_page(), vmf_insert_mixed() and vmf_insert_pfn() are three
> newly added functions.  The various drivers/filesystems where return
> value of fault(), huge_fault(), page_mkwrite() and pfn_mkwrite() get
> converted, will need them.  These functions will return correct
> VM_FAULT_ code based on err value.
> 
> We've had bugs before where drivers returned -EFOO.  And we have this
> silly inefficiency where vm_insert_xxx() return an errno which (afaict)
> every driver then converts into a VM_FAULT code.  In many cases drivers
> failed to return correct VM_FAULT code value despite of vm_insert_xxx()
> fails.  We have indentified and clean up all those existing bugs and
> silly inefficiencies in driver/filesystems by adding these three new
> inline wrappers.  As mentioned above, we will trickle those patches to
> individual drivers/filesystems in through maintainers after these three
> wrapper functions are merged.

Then put a summary of this type of thing in the original patch please!

When a maintainer gets a patch with no context at all, the first
reaction is to just reject it (especially as many of these patches were
sent privately and did not go on any public mailing list, those all got
automatically dropped...)  Make it trivial for a reviewer to understand
what the patch is for and why it needs to be applied.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] USB: ftdi_sio: Use jtag quirk for Arrow USB Blaster

2018-04-16 Thread Johan Hovold
On Wed, Apr 11, 2018 at 05:05:13PM +0300, Vasyl Vavrychuk wrote:
> Arrow USB Blaster integrated on MAX1000 board uses the same vendor ID
> (0x0403) and product ID (0x6010) as the "original" FTDI device.
> 
> This patch avoids picking up by ftdi_sio of the first interface of this
> USB device. After that this device can be used by Arrow user-space JTAG
> driver.
> 
> Signed-off-by: Vasyl Vavrychuk 
> ---
>  drivers/usb/serial/ftdi_sio.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
> index 87202ad5a50d..3bab6f83f6de 100644
> --- a/drivers/usb/serial/ftdi_sio.c
> +++ b/drivers/usb/serial/ftdi_sio.c
> @@ -1899,7 +1899,8 @@ static int ftdi_8u2232c_probe(struct usb_serial *serial)
>  
>   if (udev->product &&
>   (!strcmp(udev->product, "BeagleBone/XDS100V2") ||
> -  !strcmp(udev->product, "SNAP Connect E10")))
> +  !strcmp(udev->product, "SNAP Connect E10") ||
> +  !strcmp(udev->product, "Arrow USB Blaster")))

I reordered these alphabetically before applying.

Thanks,
Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] USB: serial: cp210x: Add ID for NI USB serial console

2018-04-16 Thread Johan Hovold
On Mon, Apr 09, 2018 at 10:23:55AM -0500, Kyle Roeschley wrote:
> Added the USB VID and PID for the USB serial console on some National
> Instruments devices.
> 
> Signed-off-by: Kyle Roeschley 

Now applied, thanks.

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] USB: serial: simple: add libtransistor console

2018-04-16 Thread Johan Hovold
On Sat, Apr 07, 2018 at 02:32:48PM -0700, Collin May wrote:
> Add simple driver for libtransistor USB console.
> This device is implemented in software:
> https://github.com/reswitched/libtransistor/blob/development/lib/usb_serial.c
> 
> Signed-off-by: Collin May 
> Tested-by: Collin May 

No need to add your own Test-by-tag as it's assumed that you as the
author has tested your own code.

Now applied for 4.17-rc with a stable tag.

Thanks,
Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 3/5] dt-bindings: usb: fusb302: remove max-sink-* properties

2018-04-16 Thread Li Jun
Remove max-sink-* properties since they are deprecated.

Reviewed-by: Rob Herring 
Reviewed-by: Hans de Goede 
Signed-off-by: Li Jun 
---
 Documentation/devicetree/bindings/usb/fcs,fusb302.txt | 6 --
 1 file changed, 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/fcs,fusb302.txt 
b/Documentation/devicetree/bindings/usb/fcs,fusb302.txt
index 472facf..6087dc7 100644
--- a/Documentation/devicetree/bindings/usb/fcs,fusb302.txt
+++ b/Documentation/devicetree/bindings/usb/fcs,fusb302.txt
@@ -6,12 +6,6 @@ Required properties :
 - interrupts : Interrupt specifier
 
 Optional properties :
-- fcs,max-sink-microvolt : Maximum voltage to negotiate when configured as sink
-- fcs,max-sink-microamp  : Maximum current to negotiate when configured as sink
-- fcs,max-sink-microwatt : Maximum power to negotiate when configured as sink
-  If this is less then max-sink-microvolt *
-  max-sink-microamp then the configured current will
-  be clamped.
 - fcs,operating-sink-microwatt :
   Minimum amount of power accepted from a sink
   when negotiating
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 1/5] usb: typec: tcpm: pdo matching optimization

2018-04-16 Thread Li Jun
This patch is a combination of commit 57e6f0d7b804
("typec: tcpm: Only request matching pdos") and source
pdo selection optimization based on it, instead of only
compare between the same pdo type of sink and source,
we should check source pdo voltage range is within the
voltage range of one sink pdo.

Reviewed-by: Hans de Goede 
Signed-off-by: Li Jun 
---
 drivers/usb/typec/tcpm.c | 105 ++-
 1 file changed, 67 insertions(+), 38 deletions(-)

diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
index 677d121..048b953 100644
--- a/drivers/usb/typec/tcpm.c
+++ b/drivers/usb/typec/tcpm.c
@@ -1772,39 +1772,63 @@ static int tcpm_pd_check_request(struct tcpm_port *port)
return 0;
 }
 
-static int tcpm_pd_select_pdo(struct tcpm_port *port)
+#define min_power(x, y) min(pdo_max_power(x), pdo_max_power(y))
+#define min_current(x, y) min(pdo_max_current(x), pdo_max_current(y))
+
+static int tcpm_pd_select_pdo(struct tcpm_port *port, int *sink_pdo,
+ int *src_pdo)
 {
-   unsigned int i, max_mw = 0, max_mv = 0;
+   unsigned int i, j, max_src_mv = 0, min_src_mv = 0, max_mw = 0,
+max_mv = 0, src_mw = 0, src_ma = 0, max_snk_mv = 0,
+min_snk_mv = 0;
int ret = -EINVAL;
 
/*
-* Select the source PDO providing the most power while staying within
-* the board's voltage limits. Prefer PDO providing exp
+* Select the source PDO providing the most power which has a
+* matchig sink cap.
 */
for (i = 0; i < port->nr_source_caps; i++) {
u32 pdo = port->source_caps[i];
enum pd_pdo_type type = pdo_type(pdo);
-   unsigned int mv, ma, mw;
 
-   if (type == PDO_TYPE_FIXED)
-   mv = pdo_fixed_voltage(pdo);
-   else
-   mv = pdo_min_voltage(pdo);
+   if (type == PDO_TYPE_FIXED) {
+   max_src_mv = pdo_fixed_voltage(pdo);
+   min_src_mv = max_src_mv;
+   } else {
+   max_src_mv = pdo_max_voltage(pdo);
+   min_src_mv = pdo_min_voltage(pdo);
+   }
 
if (type == PDO_TYPE_BATT) {
-   mw = pdo_max_power(pdo);
+   src_mw = pdo_max_power(pdo);
} else {
-   ma = min(pdo_max_current(pdo),
-port->max_snk_ma);
-   mw = ma * mv / 1000;
+   src_ma = pdo_max_current(pdo);
+   src_mw = src_ma * min_src_mv / 1000;
}
 
-   /* Perfer higher voltages if available */
-   if ((mw > max_mw || (mw == max_mw && mv > max_mv)) &&
-   mv <= port->max_snk_mv) {
-   ret = i;
-   max_mw = mw;
-   max_mv = mv;
+   for (j = 0; j < port->nr_snk_pdo; j++) {
+   pdo = port->snk_pdo[j];
+
+   if (pdo_type(pdo) == PDO_TYPE_FIXED) {
+   min_snk_mv = pdo_fixed_voltage(pdo);
+   max_snk_mv = pdo_fixed_voltage(pdo);
+   } else {
+   min_snk_mv = pdo_min_voltage(pdo);
+   max_snk_mv = pdo_max_voltage(pdo);
+   }
+
+   if (max_src_mv <= max_snk_mv &&
+   min_src_mv >= min_snk_mv) {
+   /* Prefer higher voltages if available */
+   if ((src_mw == max_mw && min_src_mv > max_mv) ||
+   src_mw > max_mw) {
+   *src_pdo = i;
+   *sink_pdo = j;
+   max_mw = src_mw;
+   max_mv = min_src_mv;
+   ret = 0;
+   }
+   }
}
}
 
@@ -1816,13 +1840,16 @@ static int tcpm_pd_build_request(struct tcpm_port 
*port, u32 *rdo)
unsigned int mv, ma, mw, flags;
unsigned int max_ma, max_mw;
enum pd_pdo_type type;
-   int index;
-   u32 pdo;
+   int src_pdo_index, snk_pdo_index;
+   u32 pdo, matching_snk_pdo;
+   int ret;
 
-   index = tcpm_pd_select_pdo(port);
-   if (index < 0)
-   return -EINVAL;
-   pdo = port->source_caps[index];
+   ret = tcpm_pd_select_pdo(port, _pdo_index, _pdo_index);
+   if (ret < 0)
+   return ret;
+
+   pdo = port->source_caps[src_pdo_index];
+   matching_snk_pdo = port->snk_pdo[snk_pdo_index];
type = pdo_type(pdo);
 
if 

[PATCH v5 5/5] usb: typec: tcpm: remove max_snk_mv/ma/mw

2018-04-16 Thread Li Jun
Since there is no user of max_snk_*, so we can remove them from tcpm.

Reviewed-by: Hans de Goede 
Signed-off-by: Li Jun 
---
 drivers/usb/typec/tcpm.c | 12 
 include/linux/usb/tcpm.h |  9 -
 2 files changed, 21 deletions(-)

diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
index 048b953..27192083 100644
--- a/drivers/usb/typec/tcpm.c
+++ b/drivers/usb/typec/tcpm.c
@@ -257,9 +257,6 @@ struct tcpm_port {
u32 snk_vdo[VDO_MAX_OBJECTS];
unsigned int nr_snk_vdo;
 
-   unsigned int max_snk_mv;
-   unsigned int max_snk_ma;
-   unsigned int max_snk_mw;
unsigned int operating_snk_mw;
 
/* Requested current / voltage */
@@ -3598,9 +3595,6 @@ EXPORT_SYMBOL_GPL(tcpm_update_source_capabilities);
 
 int tcpm_update_sink_capabilities(struct tcpm_port *port, const u32 *pdo,
  unsigned int nr_pdo,
- unsigned int max_snk_mv,
- unsigned int max_snk_ma,
- unsigned int max_snk_mw,
  unsigned int operating_snk_mw)
 {
if (tcpm_validate_caps(port, pdo, nr_pdo))
@@ -3608,9 +3602,6 @@ int tcpm_update_sink_capabilities(struct tcpm_port *port, 
const u32 *pdo,
 
mutex_lock(>lock);
port->nr_snk_pdo = tcpm_copy_pdos(port->snk_pdo, pdo, nr_pdo);
-   port->max_snk_mv = max_snk_mv;
-   port->max_snk_ma = max_snk_ma;
-   port->max_snk_mw = max_snk_mw;
port->operating_snk_mw = operating_snk_mw;
 
switch (port->state) {
@@ -3676,9 +3667,6 @@ struct tcpm_port *tcpm_register_port(struct device *dev, 
struct tcpc_dev *tcpc)
port->nr_snk_vdo = tcpm_copy_vdos(port->snk_vdo, tcpc->config->snk_vdo,
  tcpc->config->nr_snk_vdo);
 
-   port->max_snk_mv = tcpc->config->max_snk_mv;
-   port->max_snk_ma = tcpc->config->max_snk_ma;
-   port->max_snk_mw = tcpc->config->max_snk_mw;
port->operating_snk_mw = tcpc->config->operating_snk_mw;
if (!tcpc->config->try_role_hw)
port->try_role = tcpc->config->default_role;
diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
index f0d839d..f5bda9a 100644
--- a/include/linux/usb/tcpm.h
+++ b/include/linux/usb/tcpm.h
@@ -62,9 +62,6 @@ enum tcpm_transmit_type {
  * @snk_pdo:   PDO parameters sent to partner as response to
  * PD_CTRL_GET_SINK_CAP message
  * @nr_snk_pdo:Number of entries in @snk_pdo
- * @max_snk_mv:Maximum acceptable sink voltage in mV
- * @max_snk_ma:Maximum sink current in mA
- * @max_snk_mw:Maximum required sink power in mW
  * @operating_snk_mw:
  * Required operating sink power in mW
  * @type:  Port type (TYPEC_PORT_DFP, TYPEC_PORT_UFP, or
@@ -85,9 +82,6 @@ struct tcpc_config {
const u32 *snk_vdo;
unsigned int nr_snk_vdo;
 
-   unsigned int max_snk_mv;
-   unsigned int max_snk_ma;
-   unsigned int max_snk_mw;
unsigned int operating_snk_mw;
 
enum typec_port_type type;
@@ -174,9 +168,6 @@ int tcpm_update_source_capabilities(struct tcpm_port *port, 
const u32 *pdo,
unsigned int nr_pdo);
 int tcpm_update_sink_capabilities(struct tcpm_port *port, const u32 *pdo,
  unsigned int nr_pdo,
- unsigned int max_snk_mv,
- unsigned int max_snk_ma,
- unsigned int max_snk_mw,
  unsigned int operating_snk_mw);
 
 void tcpm_vbus_change(struct tcpm_port *port);
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 2/5] usb: typec: fusb302: remove max_snk_* for sink config

2018-04-16 Thread Li Jun
Since max_snk_* is to be deprecated, so remove max_snk_* by adding a
variable PDO for sink config.

Reviewed-by: Hans de Goede 
Signed-off-by: Li Jun 
---
 drivers/usb/typec/fusb302/fusb302.c | 42 -
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/typec/fusb302/fusb302.c 
b/drivers/usb/typec/fusb302/fusb302.c
index 7036171..664463d 100644
--- a/drivers/usb/typec/fusb302/fusb302.c
+++ b/drivers/usb/typec/fusb302/fusb302.c
@@ -120,6 +120,7 @@ struct fusb302_chip {
enum typec_cc_polarity cc_polarity;
enum typec_cc_status cc1;
enum typec_cc_status cc2;
+   u32 snk_pdo[PDO_MAX_OBJECTS];
 
 #ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
@@ -1212,11 +1213,6 @@ static const u32 snk_pdo[] = {
 static const struct tcpc_config fusb302_tcpc_config = {
.src_pdo = src_pdo,
.nr_src_pdo = ARRAY_SIZE(src_pdo),
-   .snk_pdo = snk_pdo,
-   .nr_snk_pdo = ARRAY_SIZE(snk_pdo),
-   .max_snk_mv = 5000,
-   .max_snk_ma = 3000,
-   .max_snk_mw = 15000,
.operating_snk_mw = 2500,
.type = TYPEC_PORT_DRP,
.data = TYPEC_PORT_DRD,
@@ -1756,6 +1752,29 @@ static int init_gpio(struct fusb302_chip *chip)
return 0;
 }
 
+static int fusb302_composite_snk_pdo_array(struct fusb302_chip *chip)
+{
+   struct device *dev = chip->dev;
+   u32 max_uv, max_ua;
+
+   chip->snk_pdo[0] = PDO_FIXED(5000, 400, PDO_FIXED_FLAGS);
+
+   /*
+* As max_snk_ma/mv/mw is not needed for tcpc_config,
+* those settings should be passed in via sink PDO, so
+* "fcs, max-sink-*" properties will be deprecated, to
+* perserve compatibility with existing users of them,
+* we read those properties to convert them to be a var
+* PDO.
+*/
+   if (device_property_read_u32(dev, "fcs,max-sink-microvolt", _uv) ||
+   device_property_read_u32(dev, "fcs,max-sink-microamp", _ua))
+   return 1;
+
+   chip->snk_pdo[1] = PDO_VAR(5000, max_uv / 1000, max_ua / 1000);
+   return 2;
+}
+
 static int fusb302_probe(struct i2c_client *client,
 const struct i2c_device_id *id)
 {
@@ -1784,18 +1803,13 @@ static int fusb302_probe(struct i2c_client *client,
chip->tcpc_dev.config = >tcpc_config;
mutex_init(>lock);
 
-   if (!device_property_read_u32(dev, "fcs,max-sink-microvolt", ))
-   chip->tcpc_config.max_snk_mv = v / 1000;
-
-   if (!device_property_read_u32(dev, "fcs,max-sink-microamp", ))
-   chip->tcpc_config.max_snk_ma = v / 1000;
-
-   if (!device_property_read_u32(dev, "fcs,max-sink-microwatt", ))
-   chip->tcpc_config.max_snk_mw = v / 1000;
-
if (!device_property_read_u32(dev, "fcs,operating-sink-microwatt", ))
chip->tcpc_config.operating_snk_mw = v / 1000;
 
+   /* Composite sink PDO */
+   chip->tcpc_config.nr_snk_pdo = fusb302_composite_snk_pdo_array(chip);
+   chip->tcpc_config.snk_pdo = chip->snk_pdo;
+
/*
 * Devicetree platforms should get extcon via phandle (not yet
 * supported). On ACPI platforms, we get the name from a device prop.
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 4/5] usb: typec: wcove: remove max_snk_* for sink config

2018-04-16 Thread Li Jun
Since max_snk_* is to be deprecated, so remove max_snk_* by adding a
variable PDO for sink config.

Reviewed-by: Hans de Goede 
Signed-off-by: Li Jun 
---
 drivers/usb/typec/typec_wcove.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/typec/typec_wcove.c b/drivers/usb/typec/typec_wcove.c
index 19cca7f..39cff11 100644
--- a/drivers/usb/typec/typec_wcove.c
+++ b/drivers/usb/typec/typec_wcove.c
@@ -558,6 +558,7 @@ static const u32 src_pdo[] = {
 static const u32 snk_pdo[] = {
PDO_FIXED(5000, 500, PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |
  PDO_FIXED_USB_COMM),
+   PDO_VAR(5000, 12000, 3000),
 };
 
 static struct tcpc_config wcove_typec_config = {
@@ -566,9 +567,6 @@ static struct tcpc_config wcove_typec_config = {
.snk_pdo = snk_pdo,
.nr_snk_pdo = ARRAY_SIZE(snk_pdo),
 
-   .max_snk_mv = 12000,
-   .max_snk_ma = 3000,
-   .max_snk_mw = 36000,
.operating_snk_mw = 15000,
 
.type = TYPEC_PORT_DRP,
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 0/5] usb: typec: remove max_snk_mv/ma/mw

2018-04-16 Thread Li Jun
This patch set is to remove max_snk_mv/ma/mw configs, as we should
define the sink capability by sink PDOs, the first patch update
the source PDO match policy by compare the voltage range between
source and sink PDOs no matter what type they are, the following
patchs remove those 3 variables from 2 existing users by adding
a variable PDO, then finial patch remove the max_snk_* from tcpm.

Change for v5:
- Fix ret = 0 missing when found matching source pdo, and add
  a variable to get the return value of tcpm_pd_select_pdo()
  in patch 1/5, tested on my platform.
- Add document in fusb302_composite_snk_pdo_array() to explain
  why use deprecated properties in patch 2/5.
 
Change for v4:
- Add Hans's reviewed-by tag for the whole patch set.

Changes for v3:
- Remove 3 variables: nr_fxied, nr_var and nr_batt from tcpm_port;
  so nr_type_pdos() is not needed and removed.
- Simplify fusb302_composite_snk_pdo_array() by only considering
  existing setting as Hans suggested.
- Add Rob's reviewed-by for dt-binding patch.

Changes for v2:
- rebase the 1st patch to be based on commit 6f566af34628
  ("Revert "typec: tcpm: Only request matching pdos"").
- Convert the device properties passing max_snk_* to be a
  variable sink pdo for fusb302.

Li Jun (5):
  usb: typec: tcpm: pdo matching optimization
  usb: typec: fusb302: remove max_snk_* for sink config
  dt-bindings: usb: fusb302: remove max-sink-* properties
  usb: typec: wcove: remove max_snk_* for sink config
  usb: typec: tcpm: remove max_snk_mv/ma/mw

 .../devicetree/bindings/usb/fcs,fusb302.txt|   6 --
 drivers/usb/typec/fusb302/fusb302.c|  42 +---
 drivers/usb/typec/tcpm.c   | 117 -
 drivers/usb/typec/typec_wcove.c|   4 +-
 include/linux/usb/tcpm.h   |   9 --
 5 files changed, 96 insertions(+), 82 deletions(-)

-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html