Re: [PATCH] USB: wusbcore: remove redundant re-assignment to pointer 'dev'

2018-01-26 Thread Johan Hovold
On Fri, Jan 26, 2018 at 03:07:12PM +, Colin King wrote:
> From: Colin Ian King 
> 
> Pointer dev is initialized and then re-assigned with the same value
> a little later, hence the second assignment is redundant and can be
> removed.
> 
> Cleans up clang warning:
> drivers/usb/wusbcore/wa-nep.c:88:17: warning: Value stored to 'dev'
> during its initialization is never read
> 
> Signed-off-by: Colin Ian King 

Reviewed-by: Johan Hovold 
--
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: [RFC/RFT usb-next v1 5/6] usb: chipidea: do not set the "phy" field in struct usb_hcd

2018-01-26 Thread Martin Blumenstingl
Hi Peter,

On Fri, Jan 26, 2018 at 10:06 AM, Peter Chen  wrote:
>
>>
>> Now that usb_add_hcd parses all generic PHYs anyways the code which skips
>> initialization of a single PHY will go away.
>> Remove the code which sets struct usb_hcd's phy field from the chipidea 
>> driver as
>> this field will go away soon.
>>
>> Signed-off-by: Martin Blumenstingl 
>> ---
>>  drivers/usb/chipidea/host.c | 4 +---
>>  1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index
>> 19d60ed7e41f..fc324767cb0f 100644
>> --- a/drivers/usb/chipidea/host.c
>> +++ b/drivers/usb/chipidea/host.c
>> @@ -124,9 +124,7 @@ static int host_start(struct ci_hdrc *ci)
>>
>>   hcd->power_budget = ci->platdata->power_budget;
>>   hcd->tpl_support = ci->platdata->tpl_support;
>> - if (ci->phy)
>> - hcd->phy = ci->phy;
>> - else
>> + if (!ci->phy)
>>   hcd->usb_phy = ci->usb_phy;
>>
>
> The reason hcd->phy is initialized by chipidea core is we do not need HCD 
> core to
> touch PHY, and PHY operation is shared for both device and host mode for 
> chipidea.
Chunfeng wanted me to drop the mtu3 patch because I forgot about
device mode in the mtu3 driver.
however, the chipidea driver seems to be different because I'm not
dropping the whole phy_{init,power_on,power_off,exit} code from it,
but only a "flag" that tells the HCD core to skip managing the USB PHY

> If I understand correct, your HCD core PHY wrapper patch set will do PHY 
> operation if
> there is a "phy" node under controller's? If it is correct, you may supply 
> one way to let
> the HCD core bypass phy operations for some USB controllers, eg dual-role 
> controllers.
> Thanks.
could you please explain why the HCD core should not manage the the
PHYs when the chipidea driver is used?

my understanding is that all phy_{init,power_on,power_off,exit}
operations are ref-counted internally in the PHY framework
this means that if the chipidea driver calls phy_{init,power_on} first
then the same functions called from within the HCD core are no-ops
(except for the ref-counting)
so I think it should not change anything - however, I have no hardware
to actually prove that.
it would be great if you could explain the issue behind this (and
thereby answer the question: why we would not want the HCD core to
manage the PHY states)!


Regards
Martin
--
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: dvb usb issues since kernel 4.9

2018-01-26 Thread Mauro Carvalho Chehab
Em Fri, 26 Jan 2018 12:17:37 -0200
Mauro Carvalho Chehab  escreveu:

> Hi Alan,
> 
> Em Mon, 8 Jan 2018 14:15:35 -0500 (EST)
> Alan Stern  escreveu:
> 
> > On Mon, 8 Jan 2018, Linus Torvalds wrote:
> >   
> > > Can somebody tell which softirq it is that dvb/usb cares about?
> > 
> > I don't know about the DVB part.  The USB part is a little difficult to
> > analyze, mostly because the bug reports I've seen are mostly from
> > people running non-vanilla kernels.   
> 
> I suspect that the main reason for people not using non-vanilla Kernels
> is that, among other bugs, the dwc2 upstream driver has serious troubles
> handling ISOCH traffic.
> 
> Using Kernel 4.15-rc7 from this git tree:
>   https://git.linuxtv.org/mchehab/experimental.git/log/?h=softirq_fixup
> 
> (e. g. with the softirq bug partially reverted with Linux patch, and
>  the DWC2 deferred probe fixed)
> 
> With a PCTV 461e device, with uses em28xx driver + Montage frontend
> (with is the same used on dvbsky hardware - except for em28xx).
> 
> This device doesn't support bulk for DVB, just ISOCH. The drivers work 
> fine on x86.
> 
> Using a test signal at the bit rate of 56698,4 Kbits/s, that's what
> happens, when capturing less than one second of data:
> 
> $ dvbv5-zap -c ~/dvb_channel.conf "tv brasil" -l universal -X 100 -m 
> -t2dvbv5-zap -c ~/dvb_channel.conf "tv brasil" -l universal -X 100 -m -t2
> Using LNBf UNIVERSAL
>   Universal, Europe
>   Freqs : 10800 to 11800 MHz, LO: 9750 MHz
>   Freqs : 11600 to 12700 MHz, LO: 10600 MHz
> using demux 'dvb0.demux0'
> reading channels from file '/home/mchehab/dvb_channel.conf'
> tuning to 11468000 Hz
>(0x00) Signal= -33.90dBm
> Lock   (0x1f) Signal= -33.90dBm C/N= 30.28dB postBER= 2.33x10^-6
> dvb_dev_set_bufsize: buffer set to 6160384
>   dvb_set_pesfilter to 0x2000
> 354.08s: Starting capture
> 354.73s: only read 59220 bytes
> 354.73s: Stopping capture
> 
> [  354.000827] dwc2 3f98.usb: DWC OTG HCD EP DISABLE: 
> bEndpointAddress=0x84, ep->hcpriv=116f41b2
> [  354.000859] dwc2 3f98.usb: DWC OTG HCD EP RESET: bEndpointAddress=0x84
> [  354.010744] dwc2 3f98.usb: --Host Channel 5 Interrupt: Frame Overrun--
> ... (hundreds of thousands of Frame Overrun messages)
> [  354.660857] dwc2 3f98.usb: --Host Channel 5 Interrupt: Frame Overrun--
> [  354.660935] dwc2 3f98.usb: DWC OTG HCD URB Dequeue
> [  354.660959] dwc2 3f98.usb: Called usb_hcd_giveback_urb()
> [  354.660966] dwc2 3f98.usb:   urb->status = 0
> [  354.660992] dwc2 3f98.usb: DWC OTG HCD URB Dequeue
> [  354.661001] dwc2 3f98.usb: Called usb_hcd_giveback_urb()
> [  354.661008] dwc2 3f98.usb:   urb->status = 0
> [  354.661054] dwc2 3f98.usb: DWC OTG HCD URB Dequeue
> [  354.661065] dwc2 3f98.usb: Called usb_hcd_giveback_urb()
> [  354.661072] dwc2 3f98.usb:   urb->status = 0
> [  354.661107] dwc2 3f98.usb: DWC OTG HCD URB Dequeue
> [  354.661120] dwc2 3f98.usb: Called usb_hcd_giveback_urb()
> [  354.661127] dwc2 3f98.usb:   urb->status = 0
> [  354.661146] dwc2 3f98.usb: DWC OTG HCD URB Dequeue
> [  354.661158] dwc2 3f98.usb: Called usb_hcd_giveback_urb()
> [  354.661165] dwc2 3f98.usb:   urb->status = 0

Btw, 

Just in case, I also applied all recent pending dwc2 patches I found at
linux-usb (even trivial unrelated ones) at:

https://git.linuxtv.org/mchehab/experimental.git/log/?h=dwc2_patches

No differences. ISOCH is still broken.

If anyone wants to see the full logs, it is there:
https://pastebin.com/XJYyTwPv


Cheers,
Mauro
--
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] usbip: keep usbip_device sockfd state in sync with tcp_socket

2018-01-26 Thread Shuah Khan
Keep usbip_device sockfd state in sync with tcp_socket. When tcp_socket
is reset to null, reset sockfd to -1 to keep it in sync.

Signed-off-by: Shuah Khan 
Cc: sta...@vger.kernel.org
---
 drivers/usb/usbip/stub_dev.c | 3 +++
 drivers/usb/usbip/vhci_hcd.c | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
index e31a6f204397..86037e5b1101 100644
--- a/drivers/usb/usbip/stub_dev.c
+++ b/drivers/usb/usbip/stub_dev.c
@@ -73,6 +73,7 @@ static ssize_t store_sockfd(struct device *dev, struct 
device_attribute *attr,
goto err;
 
sdev->ud.tcp_socket = socket;
+   sdev->ud.sockfd = sockfd;
 
spin_unlock_irq(>ud.lock);
 
@@ -172,6 +173,7 @@ static void stub_shutdown_connection(struct usbip_device 
*ud)
if (ud->tcp_socket) {
sockfd_put(ud->tcp_socket);
ud->tcp_socket = NULL;
+   ud->sockfd = -1;
}
 
/* 3. free used data */
@@ -266,6 +268,7 @@ static struct stub_device *stub_device_alloc(struct 
usb_device *udev)
sdev->ud.status = SDEV_ST_AVAILABLE;
spin_lock_init(>ud.lock);
sdev->ud.tcp_socket = NULL;
+   sdev->ud.sockfd = -1;
 
INIT_LIST_HEAD(>priv_init);
INIT_LIST_HEAD(>priv_tx);
diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index c3e1008aa491..20e3d4609583 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -984,6 +984,7 @@ static void vhci_shutdown_connection(struct usbip_device 
*ud)
if (vdev->ud.tcp_socket) {
sockfd_put(vdev->ud.tcp_socket);
vdev->ud.tcp_socket = NULL;
+   vdev->ud.sockfd = -1;
}
pr_info("release socket\n");
 
@@ -1030,6 +1031,7 @@ static void vhci_device_reset(struct usbip_device *ud)
if (ud->tcp_socket) {
sockfd_put(ud->tcp_socket);
ud->tcp_socket = NULL;
+   ud->sockfd = -1;
}
ud->status = VDEV_ST_NULL;
 
-- 
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 4.4] usbip: vhci_hcd: clear just the USB_PORT_STAT_POWER bit

2018-01-26 Thread Shuah Khan
Upstream commit 1c9de5bf4286 ("usbip: vhci-hcd: Add USB3 SuperSpeed
support")

vhci_hcd clears all the bits port_status bits instead of clearing
just the USB_PORT_STAT_POWER bit when it handles ClearPortFeature:
USB_PORT_FEAT_POWER. This causes vhci_hcd attach to fail in a bad
state, leaving device unusable by the client. The device is still
attached and however client can't use it.

The problem was fixed as part of larger change to add  USB3 Super
Speed support. This patch backports just the change to clear the
USB_PORT_STAT_POWER.

In addition, a minor formatting error in status file is fixed.

Signed-off-by: Shuah Khan 
---
 drivers/usb/usbip/vhci_hcd.c   | 2 +-
 drivers/usb/usbip/vhci_sysfs.c | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index 00d68945548e..2d96bfd34138 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -285,7 +285,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 
typeReq, u16 wValue,
case USB_PORT_FEAT_POWER:
usbip_dbg_vhci_rh(
" ClearPortFeature: USB_PORT_FEAT_POWER\n");
-   dum->port_status[rhport] = 0;
+   dum->port_status[rhport] &= ~USB_PORT_STAT_POWER;
dum->resuming = 0;
break;
case USB_PORT_FEAT_C_RESET:
diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c
index 1c7f41a65565..ebf133c9eea3 100644
--- a/drivers/usb/usbip/vhci_sysfs.c
+++ b/drivers/usb/usbip/vhci_sysfs.c
@@ -53,7 +53,7 @@ static ssize_t status_show(struct device *dev, struct 
device_attribute *attr,
 * a security hole, the change is made to use sockfd instead.
 */
out += sprintf(out,
-  "prt sta spd bus dev sockfd local_busid\n");
+  "prt sta spd dev  sockfd local_busid\n");
 
for (i = 0; i < VHCI_NPORTS; i++) {
struct vhci_device *vdev = port_to_vdev(i);
@@ -64,8 +64,7 @@ static ssize_t status_show(struct device *dev, struct 
device_attribute *attr,
if (vdev->ud.status == VDEV_ST_USED) {
out += sprintf(out, "%03u %08x ",
   vdev->speed, vdev->devid);
-   out += sprintf(out, "%16p ", vdev->ud.tcp_socket);
-   out += sprintf(out, "%06u", vdev->ud.sockfd);
+   out += sprintf(out, "%06u ", vdev->ud.sockfd);
out += sprintf(out, "%s", dev_name(>udev->dev));
 
} else
-- 
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


how to disable a xhci logical port?

2018-01-26 Thread Bin Liu
Hi,

A xHCI controller has two logical ports, hs and ss port. Is it
possible to disable one port, for example the ss port? If so, how?

By disable, I meant the xHCI driver doesn't see the port when the xHCI
driver is loaded and doesn't create that usb bus.

Thanks,
-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


[PATCH 4.9] usbip: vhci_hcd: clear just the USB_PORT_STAT_POWER bit

2018-01-26 Thread Shuah Khan
Upstream commit 1c9de5bf4286 ("usbip: vhci-hcd: Add USB3 SuperSpeed
support")

vhci_hcd clears all the bits port_status bits instead of clearing
just the USB_PORT_STAT_POWER bit when it handles ClearPortFeature:
USB_PORT_FEAT_POWER. This causes vhci_hcd attach to fail in a bad
state, leaving device unusable by the client. The device is still
attached and however client can't use it.

The problem was fixed as part of larger change to add  USB3 Super
Speed support. This patch backports just the change to clear the
USB_PORT_STAT_POWER.

Signed-off-by: Shuah Khan 
---
 drivers/usb/usbip/vhci_hcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index 7f161b095176..dbe615ba07c9 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -300,7 +300,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 
typeReq, u16 wValue,
case USB_PORT_FEAT_POWER:
usbip_dbg_vhci_rh(
" ClearPortFeature: USB_PORT_FEAT_POWER\n");
-   dum->port_status[rhport] = 0;
+   dum->port_status[rhport] &= ~USB_PORT_STAT_POWER;
dum->resuming = 0;
break;
case USB_PORT_FEAT_C_RESET:
-- 
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] USB: gadget: function: remove redundant initialization of 'tv_nexus'

2018-01-26 Thread Colin King
From: Colin Ian King 

Pointer tv_nexus is being initialized a value and this is never read
and is later being updated with the same value. Remove the redundant
initialization so that the assignment to tv_nexus is performed later
and more local to when it is being read.

Cleans up clang warning:
drivers/usb/gadget/function/f_tcm.c:1097:25: warning: Value stored to
'tv_nexus' during its initialization is never read

Signed-off-by: Colin Ian King 
---
 drivers/usb/gadget/function/f_tcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_tcm.c 
b/drivers/usb/gadget/function/f_tcm.c
index da81cf16b850..d78dbb73bde8 100644
--- a/drivers/usb/gadget/function/f_tcm.c
+++ b/drivers/usb/gadget/function/f_tcm.c
@@ -1094,7 +1094,7 @@ static int usbg_submit_command(struct f_uas *fu,
struct command_iu *cmd_iu = cmdbuf;
struct usbg_cmd *cmd;
struct usbg_tpg *tpg = fu->tpg;
-   struct tcm_usbg_nexus *tv_nexus = tpg->tpg_nexus;
+   struct tcm_usbg_nexus *tv_nexus;
u32 cmd_len;
u16 scsi_tag;
 
-- 
2.15.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] USB: wusbcore: remove redundant re-assignment to pointer 'dev'

2018-01-26 Thread Colin King
From: Colin Ian King 

Pointer dev is initialized and then re-assigned with the same value
a little later, hence the second assignment is redundant and can be
removed.

Cleans up clang warning:
drivers/usb/wusbcore/wa-nep.c:88:17: warning: Value stored to 'dev'
during its initialization is never read

Signed-off-by: Colin Ian King 
---
 drivers/usb/wusbcore/wa-nep.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/usb/wusbcore/wa-nep.c b/drivers/usb/wusbcore/wa-nep.c
index 9fdcb6b84abf..5f0656db5482 100644
--- a/drivers/usb/wusbcore/wa-nep.c
+++ b/drivers/usb/wusbcore/wa-nep.c
@@ -93,7 +93,6 @@ static void wa_notif_dispatch(struct work_struct *ws)
goto out;   /* screw it */
 #endif
atomic_dec(>notifs_queued); /* Throttling ctl */
-   dev = >usb_iface->dev;
size = nw->size;
itr = nw->data;
 
-- 
2.15.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: dvb usb issues since kernel 4.9

2018-01-26 Thread Mauro Carvalho Chehab
Hi Alan,

Em Mon, 8 Jan 2018 14:15:35 -0500 (EST)
Alan Stern  escreveu:

> On Mon, 8 Jan 2018, Linus Torvalds wrote:
> 
> > Can somebody tell which softirq it is that dvb/usb cares about?  
> 
> I don't know about the DVB part.  The USB part is a little difficult to
> analyze, mostly because the bug reports I've seen are mostly from
> people running non-vanilla kernels. 

I suspect that the main reason for people not using non-vanilla Kernels
is that, among other bugs, the dwc2 upstream driver has serious troubles
handling ISOCH traffic.

Using Kernel 4.15-rc7 from this git tree:
https://git.linuxtv.org/mchehab/experimental.git/log/?h=softirq_fixup

(e. g. with the softirq bug partially reverted with Linux patch, and
 the DWC2 deferred probe fixed)

With a PCTV 461e device, with uses em28xx driver + Montage frontend
(with is the same used on dvbsky hardware - except for em28xx).

This device doesn't support bulk for DVB, just ISOCH. The drivers work 
fine on x86.

Using a test signal at the bit rate of 56698,4 Kbits/s, that's what
happens, when capturing less than one second of data:

$ dvbv5-zap -c ~/dvb_channel.conf "tv brasil" -l universal -X 100 -m 
-t2dvbv5-zap -c ~/dvb_channel.conf "tv brasil" -l universal -X 100 -m -t2
Using LNBf UNIVERSAL
Universal, Europe
Freqs : 10800 to 11800 MHz, LO: 9750 MHz
Freqs : 11600 to 12700 MHz, LO: 10600 MHz
using demux 'dvb0.demux0'
reading channels from file '/home/mchehab/dvb_channel.conf'
tuning to 11468000 Hz
   (0x00) Signal= -33.90dBm
Lock   (0x1f) Signal= -33.90dBm C/N= 30.28dB postBER= 2.33x10^-6
dvb_dev_set_bufsize: buffer set to 6160384
  dvb_set_pesfilter to 0x2000
354.08s: Starting capture
354.73s: only read 59220 bytes
354.73s: Stopping capture

[  354.000827] dwc2 3f98.usb: DWC OTG HCD EP DISABLE: 
bEndpointAddress=0x84, ep->hcpriv=116f41b2
[  354.000859] dwc2 3f98.usb: DWC OTG HCD EP RESET: bEndpointAddress=0x84
[  354.010744] dwc2 3f98.usb: --Host Channel 5 Interrupt: Frame Overrun--
... (hundreds of thousands of Frame Overrun messages)
[  354.660857] dwc2 3f98.usb: --Host Channel 5 Interrupt: Frame Overrun--
[  354.660935] dwc2 3f98.usb: DWC OTG HCD URB Dequeue
[  354.660959] dwc2 3f98.usb: Called usb_hcd_giveback_urb()
[  354.660966] dwc2 3f98.usb:   urb->status = 0
[  354.660992] dwc2 3f98.usb: DWC OTG HCD URB Dequeue
[  354.661001] dwc2 3f98.usb: Called usb_hcd_giveback_urb()
[  354.661008] dwc2 3f98.usb:   urb->status = 0
[  354.661054] dwc2 3f98.usb: DWC OTG HCD URB Dequeue
[  354.661065] dwc2 3f98.usb: Called usb_hcd_giveback_urb()
[  354.661072] dwc2 3f98.usb:   urb->status = 0
[  354.661107] dwc2 3f98.usb: DWC OTG HCD URB Dequeue
[  354.661120] dwc2 3f98.usb: Called usb_hcd_giveback_urb()
[  354.661127] dwc2 3f98.usb:   urb->status = 0
[  354.661146] dwc2 3f98.usb: DWC OTG HCD URB Dequeue
[  354.661158] dwc2 3f98.usb: Called usb_hcd_giveback_urb()
[  354.661165] dwc2 3f98.usb:   urb->status = 0

Kernel was compiled with:

CONFIG_USB_DWC2=y
CONFIG_USB_DWC2_HOST=y
# CONFIG_USB_DWC2_PERIPHERAL is not set
# CONFIG_USB_DWC2_DUAL_ROLE is not set
# CONFIG_USB_DWC2_PCI is not set
CONFIG_USB_DWC2_DEBUG=y
# CONFIG_USB_DWC2_VERBOSE is not set
# CONFIG_USB_DWC2_TRACK_MISSED_SOFS is not set
CONFIG_USB_DWC2_DEBUG_PERIODIC=y

As reference, that's the output of lsusb for the PCTV usb hardware:

$ lsusb -v -d 2013:0258

Bus 001 Device 005: ID 2013:0258 PCTV Systems 
Couldn't open device, some information will be missing
Device Descriptor:
  bLength18
  bDescriptorType 1
  bcdUSB   2.00
  bDeviceClass0 (Defined at Interface level)
  bDeviceSubClass 0 
  bDeviceProtocol 0 
  bMaxPacketSize064
  idVendor   0x2013 PCTV Systems
  idProduct  0x0258 
  bcdDevice1.00
  iManufacturer   3 
  iProduct1 
  iSerial 2 
  bNumConfigurations  1
  Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength   41
bNumInterfaces  1
bConfigurationValue 1
iConfiguration  0 
bmAttributes 0x80
  (Bus Powered)
MaxPower  500mA
Interface Descriptor:
  bLength 9
  bDescriptorType 4
  bInterfaceNumber0
  bAlternateSetting   0
  bNumEndpoints   1
  bInterfaceClass   255 Vendor Specific Class
  bInterfaceSubClass  0 
  bInterfaceProtocol  0 
  iInterface  0 
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x84  EP 4 IN
bmAttributes1
  Transfer TypeIsochronous
  Synch Type   None
  Usage Type   Data
wMaxPacketSize 0x  

[PATCH 14/14] usb: dwc2: Enable power down

2018-01-26 Thread Grigor Tovmasyan
From: John Youn 

Enable the power down option based on the core capability.

Signed-off-by: John Youn 
Signed-off-by: Vardan Mikayelyan 
Signed-off-by: Artur Petrosyan 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/params.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index 8c4ede8a4eea..c21a4c82614c 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -252,6 +252,20 @@ static void dwc2_set_param_tx_fifo_sizes(struct dwc2_hsotg 
*hsotg)
p->g_tx_fifo_size[i] = depth_average;
 }
 
+static void dwc2_set_param_power_down(struct dwc2_hsotg *hsotg)
+{
+   int val;
+
+   if (hsotg->hw_params.hibernation)
+   val = 2;
+   else if (hsotg->hw_params.power_optimized)
+   val = 1;
+   else
+   val = 0;
+
+   hsotg->params.power_down = val;
+}
+
 /**
  * dwc2_set_default_params() - Set all core parameters to their
  * auto-detected default values.
@@ -266,6 +280,7 @@ static void dwc2_set_default_params(struct dwc2_hsotg 
*hsotg)
dwc2_set_param_phy_type(hsotg);
dwc2_set_param_speed(hsotg);
dwc2_set_param_phy_utmi_width(hsotg);
+   dwc2_set_param_power_down(hsotg);
p->phy_ulpi_ddr = false;
p->phy_ulpi_ext_vbus = false;
 
@@ -278,7 +293,6 @@ static void dwc2_set_default_params(struct dwc2_hsotg 
*hsotg)
p->reload_ctl = (hw->snpsid >= DWC2_CORE_REV_2_92a);
p->uframe_sched = true;
p->external_id_pin_ctl = false;
-   p->power_down = false;
p->lpm = true;
p->lpm_clock_gating = true;
p->besl = true;
-- 
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 13/14] usb: dwc2: Change hub-control to allow hibernation

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

Affected cases:
ClearPortFeature's
 USB_PORT_FEAT_SUSPEND

SetPortFeature's
 USB_PORT_FEAT_SUSPEND
 USB_PORT_FEAT_RESET

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/hcd.c | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 248edc6f621b..682a1a2345d8 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -3501,8 +3501,12 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg 
*hsotg, u16 typereq,
dev_dbg(hsotg->dev,
"ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
 
-   if (hsotg->bus_suspended)
-   dwc2_port_resume(hsotg);
+   if (hsotg->bus_suspended) {
+   if (hsotg->hibernated)
+   dwc2_exit_hibernation(hsotg, 0, 0, 1);
+   else
+   dwc2_port_resume(hsotg);
+   }
break;
 
case USB_PORT_FEAT_POWER:
@@ -3710,7 +3714,10 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg 
*hsotg, u16 typereq,
"SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
if (windex != hsotg->otg_port)
goto error;
-   dwc2_port_suspend(hsotg, windex);
+   if (hsotg->params.power_down == 2)
+   dwc2_enter_hibernation(hsotg, 1);
+   else
+   dwc2_port_suspend(hsotg, windex);
break;
 
case USB_PORT_FEAT_POWER:
@@ -3722,6 +3729,9 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, 
u16 typereq,
break;
 
case USB_PORT_FEAT_RESET:
+   if (hsotg->params.power_down == 2 &&
+   hsotg->hibernated)
+   dwc2_exit_hibernation(hsotg, 0, 1, 1);
hprt0 = dwc2_read_hprt0(hsotg);
dev_dbg(hsotg->dev,
"SetPortFeature - USB_PORT_FEAT_RESET\n");
-- 
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 12/14] usb: dwc2: Add dwc2_handle_gpwrdn_intr() handler

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

The GPWRDN interrupts are those that occur in both Host and
Device mode while core is in hibernated state.

Export dwc2_core_init to be able to use it in GPWRDN_IDSTS
interrupt handler.

Here we have duplicated init functions in host and gadget sides
so I have left things as it was(used corresponing functions for
host and gadget), maybe in the future we'll resolve this problem
and will use dwc2_core_init for both sides.

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Artur Petrosyan 
Signed-off-by: Minas Harutyunyan 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core.h  |   3 ++
 drivers/usb/dwc2/core_intr.c | 117 +++
 drivers/usb/dwc2/hcd.c   |   2 +-
 3 files changed, 121 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index beb830acf8ba..5e8199693861 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -1270,6 +1270,7 @@ int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg 
*hsotg, int us);
 void dwc2_hcd_connect(struct dwc2_hsotg *hsotg);
 void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force);
 void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
+int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup);
 int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg);
 int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg);
 int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg);
@@ -1285,6 +1286,8 @@ static inline void dwc2_hcd_connect(struct dwc2_hsotg 
*hsotg) {}
 static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {}
 static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
 static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
+static inline int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup)
+{ return 0; }
 static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
 { return 0; }
 static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index d01581594ce5..2982a155734d 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -642,6 +642,116 @@ static u32 dwc2_read_common_intr(struct dwc2_hsotg *hsotg)
return 0;
 }
 
+/*
+ * GPWRDN interrupt handler.
+ *
+ * The GPWRDN interrupts are those that occur in both Host and
+ * Device mode while core is in hibernated state.
+ */
+static void dwc2_handle_gpwrdn_intr(struct dwc2_hsotg *hsotg)
+{
+   u32 gpwrdn;
+   int linestate;
+
+   gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
+   /* clear all interrupt */
+   dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
+   linestate = (gpwrdn & GPWRDN_LINESTATE_MASK) >> GPWRDN_LINESTATE_SHIFT;
+   dev_dbg(hsotg->dev,
+   "%s: dwc2_handle_gpwrdwn_intr called gpwrdn= %08x\n", __func__,
+   gpwrdn);
+
+   if ((gpwrdn & GPWRDN_DISCONN_DET) &&
+   (gpwrdn & GPWRDN_DISCONN_DET_MSK) && !linestate) {
+   u32 gpwrdn_tmp;
+
+   dev_dbg(hsotg->dev, "%s: GPWRDN_DISCONN_DET\n", __func__);
+
+   /* Switch-on voltage to the core */
+   gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn_tmp &= ~GPWRDN_PWRDNSWTCH;
+   dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
+   udelay(10);
+
+   /* Reset core */
+   gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn_tmp &= ~GPWRDN_PWRDNRSTN;
+   dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
+   udelay(10);
+
+   /* Disable Power Down Clamp */
+   gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn_tmp &= ~GPWRDN_PWRDNCLMP;
+   dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
+   udelay(10);
+
+   /* Deassert reset core */
+   gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn_tmp |= GPWRDN_PWRDNRSTN;
+   dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
+   udelay(10);
+
+   /* Disable PMU interrupt */
+   gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn_tmp &= ~GPWRDN_PMUINTSEL;
+   dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
+
+   /* De-assert Wakeup Logic */
+   gpwrdn_tmp = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn_tmp &= ~GPWRDN_PMUACTV;
+   dwc2_writel(gpwrdn_tmp, hsotg->regs + GPWRDN);
+
+   hsotg->hibernated = 0;
+
+   if (gpwrdn & GPWRDN_IDSTS) {
+   hsotg->op_state = OTG_STATE_B_PERIPHERAL;
+   dwc2_core_init(hsotg, false);
+   dwc2_enable_global_interrupts(hsotg);

[PATCH 10/14] usb: dwc2: Add dwc2_enter_hibernation(), dwc2_exit_hibernation()

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

These are wrapper functions which are calling device or host
enter/exit hibernation functions.

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core.c | 38 ++
 drivers/usb/dwc2/core.h |  3 +++
 2 files changed, 41 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 0218a37acc80..18a0a1771289 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -448,6 +448,44 @@ static bool dwc2_iddig_filter_enabled(struct dwc2_hsotg 
*hsotg)
return true;
 }
 
+/*
+ * dwc2_enter_hibernation() - Common function to enter hibernation.
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ * @is_host: True if core is in host mode.
+ *
+ * Return: 0 if successful, negative error code otherwise
+ */
+int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg, int is_host)
+{
+   if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_HIBERNATION)
+   return -ENOTSUPP;
+
+   if (is_host)
+   return dwc2_host_enter_hibernation(hsotg);
+   else
+   return dwc2_gadget_enter_hibernation(hsotg);
+}
+
+/*
+ * dwc2_exit_hibernation() - Common function to exit from hibernation.
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ * @rem_wakeup: Remote-wakeup, enabled in case of remote-wakeup.
+ * @reset: Enabled in case of restore with reset.
+ * @is_host: True if core is in host mode.
+ *
+ * Return: 0 if successful, negative error code otherwise
+ */
+int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup,
+ int reset, int is_host)
+{
+   if (is_host)
+   return dwc2_host_exit_hibernation(hsotg, rem_wakeup, reset);
+   else
+   return dwc2_gadget_exit_hibernation(hsotg, rem_wakeup, reset);
+}
+
 /*
  * Do core a soft reset of the core.  Be careful with this because it
  * resets all the internal state machines of the core.
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index d15e704986e1..beb830acf8ba 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -1127,6 +1127,9 @@ static inline bool dwc2_is_hs_iot(struct dwc2_hsotg 
*hsotg)
 int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait);
 int dwc2_enter_partial_power_down(struct dwc2_hsotg *hsotg);
 int dwc2_exit_partial_power_down(struct dwc2_hsotg *hsotg, bool restore);
+int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg, int is_host);
+int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup,
+ int reset, int is_host);
 
 void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host);
 void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg);
-- 
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 11/14] usb: dwc2: Allow entering hibernation from USB_SUSPEND interrupt

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

Do changes to allow entering hibernated state from USB_SUSPEND
interrupt. All code is added under if conditions and mustn't impact
existing functionality.

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core_intr.c | 52 +++-
 1 file changed, 32 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index 41d7dda40cb1..d01581594ce5 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -484,32 +484,44 @@ static void dwc2_handle_usb_suspend_intr(struct 
dwc2_hsotg *hsotg)
 * state is active
 */
dsts = dwc2_readl(hsotg->regs + DSTS);
-   dev_dbg(hsotg->dev, "DSTS=0x%0x\n", dsts);
+   dev_dbg(hsotg->dev, "%s: DSTS=0x%0x\n", __func__, dsts);
dev_dbg(hsotg->dev,
-   "DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d\n",
+   "DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d 
HWCFG4.Hibernation=%d\n",
!!(dsts & DSTS_SUSPSTS),
-   hsotg->hw_params.power_optimized);
-   if ((dsts & DSTS_SUSPSTS) && hsotg->hw_params.power_optimized) {
-   /* Ignore suspend request before enumeration */
-   if (!dwc2_is_device_connected(hsotg)) {
-   dev_dbg(hsotg->dev,
-   "ignore suspend request before 
enumeration\n");
-   return;
+   hsotg->hw_params.power_optimized,
+   hsotg->hw_params.hibernation);
+
+   /* Ignore suspend request before enumeration */
+   if (!dwc2_is_device_connected(hsotg)) {
+   dev_dbg(hsotg->dev,
+   "ignore suspend request before enumeration\n");
+   return;
+   }
+   if (dsts & DSTS_SUSPSTS) {
+   if (hsotg->hw_params.power_optimized) {
+   ret = dwc2_enter_partial_power_down(hsotg);
+   if (ret) {
+   if (ret != -ENOTSUPP)
+   dev_err(hsotg->dev,
+   "%s: enter 
partial_power_down failed\n",
+   __func__);
+   goto skip_power_saving;
+   }
+
+   udelay(100);
+
+   /* Ask phy to be suspended */
+   if (!IS_ERR_OR_NULL(hsotg->uphy))
+   usb_phy_set_suspend(hsotg->uphy, true);
}
 
-   ret = dwc2_enter_partial_power_down(hsotg);
-   if (ret) {
-   if (ret != -ENOTSUPP)
+   if (hsotg->hw_params.hibernation) {
+   ret = dwc2_enter_hibernation(hsotg, 0);
+   if (ret && ret != -ENOTSUPP)
dev_err(hsotg->dev,
-   "enter power_down failed\n");
-   goto skip_power_saving;
+   "%s: enter hibernation 
failed\n",
+   __func__);
}
-
-   udelay(100);
-
-   /* Ask phy to be suspended */
-   if (!IS_ERR_OR_NULL(hsotg->uphy))
-   usb_phy_set_suspend(hsotg->uphy, true);
 skip_power_saving:
/*
 * Change to L2 (suspend) state before releasing
-- 
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 09/14] usb: dwc2: Add host/device hibernation functions

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

Add host/device hibernation functions which must be wrapped
by core's  dwc2_enter_hibernation()/dwc2_exit_hibernation()
functions.

Make dwc2_backup_global_registers dwc2_restore_global_register
non-static to use them in both host/gadget sides.

Added function names:
dwc2_gadget_enter_hibernation()
dwc2_gadget_exit_hibernation()
dwc2_host_enter_hibernation()
dwc2_host_exit_hibernation()

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Artur Petrosyan 
Signed-off-by: Minas Harutyunyan 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core.c   |   4 +-
 drivers/usb/dwc2/core.h   |  18 
 drivers/usb/dwc2/gadget.c | 176 
 drivers/usb/dwc2/hcd.c| 223 ++
 4 files changed, 419 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 441b5d73f339..0218a37acc80 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -64,7 +64,7 @@
  *
  * @hsotg: Programming view of the DWC_otg controller
  */
-static int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg)
+int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg)
 {
struct dwc2_gregs_backup *gr;
 
@@ -96,7 +96,7 @@ static int dwc2_backup_global_registers(struct dwc2_hsotg 
*hsotg)
  *
  * @hsotg: Programming view of the DWC_otg controller
  */
-static int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg)
+int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg)
 {
struct dwc2_gregs_backup *gr;
 
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index c9b90046794b..d15e704986e1 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -1147,6 +1147,8 @@ void dwc2_disable_global_interrupts(struct dwc2_hsotg 
*hcd);
 
 void dwc2_hib_restore_common(struct dwc2_hsotg *hsotg, int rem_wakeup,
 int is_host);
+int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg);
+int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg);
 
 void dwc2_enable_acg(struct dwc2_hsotg *hsotg);
 
@@ -1216,6 +1218,9 @@ int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, 
int testmode);
 #define dwc2_is_device_connected(hsotg) (hsotg->connected)
 int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg);
 int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup);
+int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg);
+int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
+int rem_wakeup, int reset);
 int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg);
 int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg);
 int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg);
@@ -1242,6 +1247,11 @@ static inline int dwc2_backup_device_registers(struct 
dwc2_hsotg *hsotg)
 static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg,
int remote_wakeup)
 { return 0; }
+static inline int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg)
+{ return 0; }
+static inline int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
+  int rem_wakeup, int reset)
+{ return 0; }
 static inline int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
 { return 0; }
 static inline int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
@@ -1259,6 +1269,9 @@ void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool 
force);
 void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
 int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg);
 int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg);
+int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg);
+int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg,
+  int rem_wakeup, int reset);
 #else
 static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
 { return 0; }
@@ -1275,6 +1288,11 @@ static inline int dwc2_backup_host_registers(struct 
dwc2_hsotg *hsotg)
 { return 0; }
 static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
 { return 0; }
+static inline int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg)
+{ return 0; }
+static inline int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg,
+int rem_wakeup, int reset)
+{ return 0; }
 
 #endif
 
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 6aa0f2f3ac31..82dc971ddf59 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -4951,3 +4951,179 @@ void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg)
dev_dbg(hsotg->dev, "GLPMCFG=0x%08x\n", dwc2_readl(hsotg->regs
+ GLPMCFG));
 }
+
+/**
+ * dwc2_gadget_enter_hibernation() - Put controller in 

[PATCH 08/14] usb: dwc2: Add helper functions for restore routine

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

Add common (host/device) helper functions, which will be called while
exiting from hibernation, from both sides.

dwc2_restore_essential_regs()
dwc2_hib_restore_common()

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Artur Petrosyan 
Signed-off-by: Minas Harutyunyan 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core.c | 136 
 drivers/usb/dwc2/core.h |   3 ++
 2 files changed, 139 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 8647e2a26eee..441b5d73f339 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -241,6 +241,142 @@ int dwc2_enter_partial_power_down(struct dwc2_hsotg 
*hsotg)
return ret;
 }
 
+/**
+ * dwc2_restore_essential_regs() - Restore essiential regs of core.
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ * @rmode: Restore mode, enabled in case of remote-wakeup.
+ * @is_host: Host or device mode.
+ */
+static void dwc2_restore_essential_regs(struct dwc2_hsotg *hsotg, int rmode,
+   int is_host)
+{
+   u32 pcgcctl;
+   struct dwc2_gregs_backup *gr;
+   struct dwc2_dregs_backup *dr;
+   struct dwc2_hregs_backup *hr;
+
+   gr = >gr_backup;
+   dr = >dr_backup;
+   hr = >hr_backup;
+
+   dev_dbg(hsotg->dev, "%s: restoring essential regs\n", __func__);
+
+   /* Load restore values for [31:14] bits */
+   pcgcctl = (gr->pcgcctl & 0xc000);
+   /* If High Speed */
+   if (is_host) {
+   if (!(pcgcctl & PCGCTL_P2HD_PRT_SPD_MASK))
+   pcgcctl |= BIT(17);
+   } else {
+   if (!(pcgcctl & PCGCTL_P2HD_DEV_ENUM_SPD_MASK))
+   pcgcctl |= BIT(17);
+   }
+   dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
+
+   /* Umnask global Interrupt in GAHBCFG and restore it */
+   dwc2_writel(gr->gahbcfg | GAHBCFG_GLBL_INTR_EN, hsotg->regs + GAHBCFG);
+
+   /* Clear all pending interupts */
+   dwc2_writel(0x, hsotg->regs + GINTSTS);
+
+   /* Unmask restore done interrupt */
+   dwc2_writel(GINTSTS_RESTOREDONE, hsotg->regs + GINTMSK);
+
+   /* Restore GUSBCFG and HCFG/DCFG */
+   dwc2_writel(gr->gusbcfg, hsotg->regs + GUSBCFG);
+
+   if (is_host) {
+   dwc2_writel(hr->hcfg, hsotg->regs + HCFG);
+   if (rmode)
+   pcgcctl |= PCGCTL_RESTOREMODE;
+   dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
+   udelay(10);
+
+   pcgcctl |= PCGCTL_ESS_REG_RESTORED;
+   dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
+   udelay(10);
+   } else {
+   dwc2_writel(dr->dcfg, hsotg->regs + DCFG);
+   if (!rmode)
+   pcgcctl |= PCGCTL_RESTOREMODE | PCGCTL_RSTPDWNMODULE;
+   dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
+   udelay(10);
+
+   pcgcctl |= PCGCTL_ESS_REG_RESTORED;
+   dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
+   udelay(10);
+   }
+}
+
+/**
+ * dwc2_hib_restore_common() - Common part of restore routine.
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ * @rem_wakeup: Remote-wakeup, enabled in case of remote-wakeup.
+ * @is_host: Host or device mode.
+ */
+void dwc2_hib_restore_common(struct dwc2_hsotg *hsotg, int rem_wakeup,
+int is_host)
+{
+   u32 gpwrdn;
+
+   /* Switch-on voltage to the core */
+   gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn &= ~GPWRDN_PWRDNSWTCH;
+   dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
+   udelay(10);
+
+   /* Reset core */
+   gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn &= ~GPWRDN_PWRDNRSTN;
+   dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
+   udelay(10);
+
+   /* Enable restore from PMU */
+   gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn |= GPWRDN_RESTORE;
+   dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
+   udelay(10);
+
+   /* Disable Power Down Clamp */
+   gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn &= ~GPWRDN_PWRDNCLMP;
+   dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
+   udelay(50);
+
+   if (!is_host && rem_wakeup)
+   udelay(70);
+
+   /* Deassert reset core */
+   gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn |= GPWRDN_PWRDNRSTN;
+   dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
+   udelay(10);
+
+   /* Disable PMU interrupt */
+   gpwrdn = dwc2_readl(hsotg->regs + GPWRDN);
+   gpwrdn &= ~GPWRDN_PMUINTSEL;
+   dwc2_writel(gpwrdn, hsotg->regs + GPWRDN);
+   udelay(10);
+
+   /* Set Restore Essential Regs bit in PCGCCTL register */
+   

[PATCH 07/14] usb: dwc2: Changes in registers backup/restore functions

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

Move hptxfsiz to host register's backup/restore functions, not
needed to have it in global register's backup/restore functions.

Add backup for glpmcfg, and read/write for gi2cctl and pcgcctl.
As requires programming guide.

Affected functions:
dwc2_backup_host_registers()
dwc2_restore_host_registers()
dwc2_backup_global_registers()
dwc2_restore_global_registers()

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core.c | 8 ++--
 drivers/usb/dwc2/core.h | 6 --
 drivers/usb/dwc2/hcd.c  | 2 ++
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 53f0eb61d3b2..8647e2a26eee 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -79,9 +79,11 @@ static int dwc2_backup_global_registers(struct dwc2_hsotg 
*hsotg)
gr->gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
gr->grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ);
gr->gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
-   gr->hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ);
gr->gdfifocfg = dwc2_readl(hsotg->regs + GDFIFOCFG);
gr->pcgcctl1 = dwc2_readl(hsotg->regs + PCGCCTL1);
+   gr->glpmcfg = dwc2_readl(hsotg->regs + GLPMCFG);
+   gr->gi2cctl = dwc2_readl(hsotg->regs + GI2CCTL);
+   gr->pcgcctl = dwc2_readl(hsotg->regs + PCGCTL);
 
gr->valid = true;
return 0;
@@ -116,9 +118,11 @@ static int dwc2_restore_global_registers(struct dwc2_hsotg 
*hsotg)
dwc2_writel(gr->gahbcfg, hsotg->regs + GAHBCFG);
dwc2_writel(gr->grxfsiz, hsotg->regs + GRXFSIZ);
dwc2_writel(gr->gnptxfsiz, hsotg->regs + GNPTXFSIZ);
-   dwc2_writel(gr->hptxfsiz, hsotg->regs + HPTXFSIZ);
dwc2_writel(gr->gdfifocfg, hsotg->regs + GDFIFOCFG);
dwc2_writel(gr->pcgcctl1, hsotg->regs + PCGCCTL1);
+   dwc2_writel(gr->glpmcfg, hsotg->regs + GLPMCFG);
+   dwc2_writel(gr->pcgcctl, hsotg->regs + PCGCTL);
+   dwc2_writel(gr->gi2cctl, hsotg->regs + GI2CCTL);
 
return 0;
 }
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 49834a7be78a..d83fafcee95c 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -636,7 +636,7 @@ struct dwc2_hw_params {
  * @grxfsiz:   Backup of GRXFSIZ register
  * @gnptxfsiz: Backup of GNPTXFSIZ register
  * @gi2cctl:   Backup of GI2CCTL register
- * @hptxfsiz:  Backup of HPTXFSIZ register
+ * @glpmcfg:   Backup of GLPMCFG register
  * @gdfifocfg: Backup of GDFIFOCFG register
  * @gpwrdn:Backup of GPWRDN register
  */
@@ -648,7 +648,7 @@ struct dwc2_gregs_backup {
u32 grxfsiz;
u32 gnptxfsiz;
u32 gi2cctl;
-   u32 hptxfsiz;
+   u32 glpmcfg;
u32 pcgcctl;
u32 pcgcctl1;
u32 gdfifocfg;
@@ -696,6 +696,7 @@ struct dwc2_dregs_backup {
  * @hcintmsk:  Backup of HCINTMSK register
  * @hptr0: Backup of HPTR0 register
  * @hfir:  Backup of HFIR register
+ * @hptxfsiz:  Backup of HPTXFSIZ register
  */
 struct dwc2_hregs_backup {
u32 hcfg;
@@ -703,6 +704,7 @@ struct dwc2_hregs_backup {
u32 hcintmsk[MAX_EPS_CHANNELS];
u32 hprt0;
u32 hfir;
+   u32 hptxfsiz;
bool valid;
 };
 
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 050e01e193c8..badd3a571977 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -5311,6 +5311,7 @@ int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
 
hr->hprt0 = dwc2_read_hprt0(hsotg);
hr->hfir = dwc2_readl(hsotg->regs + HFIR);
+   hr->hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ);
hr->valid = true;
 
return 0;
@@ -5347,6 +5348,7 @@ int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
 
dwc2_writel(hr->hprt0, hsotg->regs + HPRT0);
dwc2_writel(hr->hfir, hsotg->regs + HFIR);
+   dwc2_writel(hr->hptxfsiz, hsotg->regs + HPTXFSIZ);
hsotg->frame_number = 0;
 
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 05/14] usb: dwc2: core: Add hibernated flag

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

Added a flag to indicate that core is in hibernation,
it is used to determine the hibernation state of the core.

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core.h | 2 ++
 drivers/usb/dwc2/platform.c | 1 +
 2 files changed, 3 insertions(+)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 3935cce636ae..1b33977f97b4 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -806,6 +806,7 @@ struct dwc2_hregs_backup {
  * @hcd_enabledHost mode sub-driver initialization indicator.
  * @gadget_enabled Peripheral mode sub-driver initialization indicator.
  * @ll_hw_enabled  Status of low-level hardware resources.
+ * @hibernated:True if core is hibernated
  * @phy:The otg phy transceiver structure for phy control.
  * @uphy:   The otg phy transceiver structure for old USB phy
  *  control.
@@ -943,6 +944,7 @@ struct dwc2_hsotg {
unsigned int hcd_enabled:1;
unsigned int gadget_enabled:1;
unsigned int ll_hw_enabled:1;
+   unsigned int hibernated:1;
 
struct phy *phy;
struct usb_phy *uphy;
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 1a733b9ddab0..808dda374652 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -453,6 +453,7 @@ static int dwc2_driver_probe(struct platform_device *dev)
}
 
platform_set_drvdata(dev, hsotg);
+   hsotg->hibernated = 0;
 
dwc2_debugfs_init(hsotg);
 
-- 
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 06/14] usb: dwc2: gadget: Add remote_wakeup_allowed flag

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

It will be set once corresponding set_feature command comes.

True if device is allowed to wake-up host by remote-wakeup
signalling.

This is preparation for remote wake-up support implementation,
it will not be implemented until gadget stack provide interface
for bringing remote wake-up signalling.

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core.h   | 3 +++
 drivers/usb/dwc2/gadget.c | 5 +
 2 files changed, 8 insertions(+)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 1b33977f97b4..49834a7be78a 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -924,6 +924,8 @@ struct dwc2_hregs_backup {
  * @ctrl_req:   Request for EP0 control packets.
  * @ep0_state:  EP0 control transfers state
  * @test_mode:  USB test mode requested by the host
+ * @remote_wakeup_allowed: True if device is allowed to wake-up host by
+ *  remote-wakeup signalling
  * @setup_desc_dma:EP0 setup stage desc chain DMA address
  * @setup_desc:EP0 setup stage desc chain pointer
  * @ctrl_in_desc_dma:  EP0 IN data phase desc chain DMA address
@@ -1076,6 +1078,7 @@ struct dwc2_hsotg {
struct usb_gadget gadget;
unsigned int enabled:1;
unsigned int connected:1;
+   unsigned int remote_wakeup_allowed:1;
struct dwc2_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
struct dwc2_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
 #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 7adbfeea3461..6aa0f2f3ac31 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -1678,6 +1678,10 @@ static int dwc2_hsotg_process_req_feature(struct 
dwc2_hsotg *hsotg,
switch (recip) {
case USB_RECIP_DEVICE:
switch (wValue) {
+   case USB_DEVICE_REMOTE_WAKEUP:
+   hsotg->remote_wakeup_allowed = 1;
+   break;
+
case USB_DEVICE_TEST_MODE:
if ((wIndex & 0xff) != 0)
return -EINVAL;
@@ -4662,6 +4666,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
hsotg->gadget.max_speed = USB_SPEED_HIGH;
hsotg->gadget.ops = _hsotg_gadget_ops;
hsotg->gadget.name = dev_name(dev);
+   hsotg->remote_wakeup_allowed = 0;
 
if (hsotg->params.lpm)
hsotg->gadget.lpm_capable = true;
-- 
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 03/14] usb: dwc2: gadget: Moved dtxfsiz backup array place

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

Moved dtxfsiz from dwc2_gregs_backup to dwc2_dregs_backup,
because it is device register.

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core.c   | 8 ++--
 drivers/usb/dwc2/core.h   | 4 ++--
 drivers/usb/dwc2/gadget.c | 2 ++
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index ebe5a291f1a3..3d1d7bc2eb99 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -67,7 +67,8 @@
 static int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg)
 {
struct dwc2_gregs_backup *gr;
-   int i;
+
+   dev_dbg(hsotg->dev, "%s\n", __func__);
 
/* Backup global regs */
gr = >gr_backup;
@@ -81,8 +82,6 @@ static int dwc2_backup_global_registers(struct dwc2_hsotg 
*hsotg)
gr->hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ);
gr->gdfifocfg = dwc2_readl(hsotg->regs + GDFIFOCFG);
gr->pcgcctl1 = dwc2_readl(hsotg->regs + PCGCCTL1);
-   for (i = 0; i < MAX_EPS_CHANNELS; i++)
-   gr->dtxfsiz[i] = dwc2_readl(hsotg->regs + DPTXFSIZN(i));
 
gr->valid = true;
return 0;
@@ -98,7 +97,6 @@ static int dwc2_backup_global_registers(struct dwc2_hsotg 
*hsotg)
 static int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg)
 {
struct dwc2_gregs_backup *gr;
-   int i;
 
dev_dbg(hsotg->dev, "%s\n", __func__);
 
@@ -121,8 +119,6 @@ static int dwc2_restore_global_registers(struct dwc2_hsotg 
*hsotg)
dwc2_writel(gr->hptxfsiz, hsotg->regs + HPTXFSIZ);
dwc2_writel(gr->gdfifocfg, hsotg->regs + GDFIFOCFG);
dwc2_writel(gr->pcgcctl1, hsotg->regs + PCGCCTL1);
-   for (i = 0; i < MAX_EPS_CHANNELS; i++)
-   dwc2_writel(gr->dtxfsiz[i], hsotg->regs + DPTXFSIZN(i));
 
return 0;
 }
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index aab080bf8ef5..2946dcf475ac 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -638,7 +638,6 @@ struct dwc2_hw_params {
  * @gi2cctl:   Backup of GI2CCTL register
  * @hptxfsiz:  Backup of HPTXFSIZ register
  * @gdfifocfg: Backup of GDFIFOCFG register
- * @dtxfsiz:   Backup of DTXFSIZ registers for each endpoint
  * @gpwrdn:Backup of GPWRDN register
  */
 struct dwc2_gregs_backup {
@@ -653,7 +652,6 @@ struct dwc2_gregs_backup {
u32 pcgcctl;
u32 pcgcctl1;
u32 gdfifocfg;
-   u32 dtxfsiz[MAX_EPS_CHANNELS];
u32 gpwrdn;
bool valid;
 };
@@ -672,6 +670,7 @@ struct dwc2_gregs_backup {
  * @doepctl:   Backup of DOEPCTL register
  * @doeptsiz:  Backup of DOEPTSIZ register
  * @doepdma:   Backup of DOEPDMA register
+ * @dtxfsiz:   Backup of DTXFSIZ registers for each endpoint
  */
 struct dwc2_dregs_backup {
u32 dcfg;
@@ -685,6 +684,7 @@ struct dwc2_dregs_backup {
u32 doepctl[MAX_EPS_CHANNELS];
u32 doeptsiz[MAX_EPS_CHANNELS];
u32 doepdma[MAX_EPS_CHANNELS];
+   u32 dtxfsiz[MAX_EPS_CHANNELS];
bool valid;
 };
 
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 0d1cf29a5d0d..40af872e1013 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -4853,6 +4853,7 @@ int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
 
dr->doeptsiz[i] = dwc2_readl(hsotg->regs + DOEPTSIZ(i));
dr->doepdma[i] = dwc2_readl(hsotg->regs + DOEPDMA(i));
+   dr->dtxfsiz[i] = dwc2_readl(hsotg->regs + DPTXFSIZN(i));
}
dr->valid = true;
return 0;
@@ -4893,6 +4894,7 @@ int dwc2_restore_device_registers(struct dwc2_hsotg 
*hsotg)
dwc2_writel(dr->diepctl[i], hsotg->regs + DIEPCTL(i));
dwc2_writel(dr->dieptsiz[i], hsotg->regs + DIEPTSIZ(i));
dwc2_writel(dr->diepdma[i], hsotg->regs + DIEPDMA(i));
+   dwc2_writel(dr->dtxfsiz[i], hsotg->regs + DPTXFSIZN(i));
 
/* Restore OUT EPs */
dwc2_writel(dr->doepctl[i], hsotg->regs + DOEPCTL(i));
-- 
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 04/14] usb: dwc2: gadget: Fix dwc2_restore_device_registers

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

Add parameter remote_wakeup to dwc2_restore_device_registers()
to be able to restore device registers according to programming
guide for dwc-otg. It says that in case of rem_wakeup DCTL must not
be restored here.

Remove setting of DCTL_PWRONPRGDONE from this function, because it
will be done in function responsible for exiting from hibernation.

WA for enabled EPx's IN and OUT in DDMA mode. On entering to
hibernation wrong value read and saved from DIEPDMAx,
as result BNA interrupt asserted on hibernation exit
by restoring from saved area.

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Artur Petrosyan 
Signed-off-by: Minas Harutyunyan 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core.c   |  2 +-
 drivers/usb/dwc2/core.h   |  5 +++--
 drivers/usb/dwc2/gadget.c | 38 ++
 3 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 3d1d7bc2eb99..53f0eb61d3b2 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -165,7 +165,7 @@ int dwc2_exit_partial_power_down(struct dwc2_hsotg *hsotg, 
bool restore)
return ret;
}
} else {
-   ret = dwc2_restore_device_registers(hsotg);
+   ret = dwc2_restore_device_registers(hsotg, 0);
if (ret) {
dev_err(hsotg->dev, "%s: failed to restore 
device registers\n",
__func__);
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 2946dcf475ac..3935cce636ae 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -1205,7 +1205,7 @@ void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
 int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
 #define dwc2_is_device_connected(hsotg) (hsotg->connected)
 int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg);
-int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg);
+int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup);
 int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg);
 int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg);
 int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg);
@@ -1229,7 +1229,8 @@ static inline int dwc2_hsotg_set_test_mode(struct 
dwc2_hsotg *hsotg,
 #define dwc2_is_device_connected(hsotg) (0)
 static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
 { return 0; }
-static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg)
+static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg,
+   int remote_wakeup)
 { return 0; }
 static inline int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
 { return 0; }
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 40af872e1013..7adbfeea3461 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -4865,11 +4865,13 @@ int dwc2_backup_device_registers(struct dwc2_hsotg 
*hsotg)
  * if controller power were disabled.
  *
  * @hsotg: Programming view of the DWC_otg controller
+ * @remote_wakeup: Indicates whether resume is initiated by Device or Host.
+ *
+ * Return: 0 if successful, negative error code otherwise
  */
-int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg)
+int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup)
 {
struct dwc2_dregs_backup *dr;
-   u32 dctl;
int i;
 
dev_dbg(hsotg->dev, "%s\n", __func__);
@@ -4883,30 +4885,42 @@ int dwc2_restore_device_registers(struct dwc2_hsotg 
*hsotg)
}
dr->valid = false;
 
-   dwc2_writel(dr->dcfg, hsotg->regs + DCFG);
-   dwc2_writel(dr->dctl, hsotg->regs + DCTL);
+   if (!remote_wakeup)
+   dwc2_writel(dr->dctl, hsotg->regs + DCTL);
+
dwc2_writel(dr->daintmsk, hsotg->regs + DAINTMSK);
dwc2_writel(dr->diepmsk, hsotg->regs + DIEPMSK);
dwc2_writel(dr->doepmsk, hsotg->regs + DOEPMSK);
 
for (i = 0; i < hsotg->num_of_eps; i++) {
/* Restore IN EPs */
-   dwc2_writel(dr->diepctl[i], hsotg->regs + DIEPCTL(i));
dwc2_writel(dr->dieptsiz[i], hsotg->regs + DIEPTSIZ(i));
dwc2_writel(dr->diepdma[i], hsotg->regs + DIEPDMA(i));
+   dwc2_writel(dr->doeptsiz[i], hsotg->regs + DOEPTSIZ(i));
+   /** WA for enabled EPx's IN in DDMA mode. On entering to
+* hibernation wrong value read and saved from DIEPDMAx,
+* as result BNA interrupt asserted on hibernation exit
+* by restoring from saved area.
+*/
+   if 

[PATCH 01/14] usb: dwc2: Rename hibernation to partial_power_down

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

No-op change, only rename.

This code was misnamed originally. It was only responsible for partial
power down and not for hibernation.

Rename core_params->hibernation to core_params->power_down,
dwc2_set_param_hibernation() to dwc2_set_param_power_down().

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core.c  | 14 +++---
 drivers/usb/dwc2/core.h  | 12 ++--
 drivers/usb/dwc2/core_intr.c | 14 +++---
 drivers/usb/dwc2/debugfs.c   |  2 +-
 drivers/usb/dwc2/gadget.c|  6 +++---
 drivers/usb/dwc2/hcd.c   | 26 +-
 drivers/usb/dwc2/params.c|  2 +-
 7 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 7a236e61e2e2..e26aeda29bba 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -128,17 +128,17 @@ static int dwc2_restore_global_registers(struct 
dwc2_hsotg *hsotg)
 }
 
 /**
- * dwc2_exit_hibernation() - Exit controller from Partial Power Down.
+ * dwc2_exit_partial_power_down() - Exit controller from Partial Power Down.
  *
  * @hsotg: Programming view of the DWC_otg controller
  * @restore: Controller registers need to be restored
  */
-int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore)
+int dwc2_exit_partial_power_down(struct dwc2_hsotg *hsotg, bool restore)
 {
u32 pcgcctl;
int ret = 0;
 
-   if (!hsotg->params.hibernation)
+   if (!hsotg->params.power_down)
return -ENOTSUPP;
 
pcgcctl = dwc2_readl(hsotg->regs + PCGCTL);
@@ -182,16 +182,16 @@ int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool 
restore)
 }
 
 /**
- * dwc2_enter_hibernation() - Put controller in Partial Power Down.
+ * dwc2_enter_partial_power_down() - Put controller in Partial Power Down.
  *
  * @hsotg: Programming view of the DWC_otg controller
  */
-int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg)
+int dwc2_enter_partial_power_down(struct dwc2_hsotg *hsotg)
 {
u32 pcgcctl;
int ret = 0;
 
-   if (!hsotg->params.hibernation)
+   if (!hsotg->params.power_down)
return -ENOTSUPP;
 
/* Backup all registers */
@@ -220,7 +220,7 @@ int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg)
 
/*
 * Clear any pending interrupts since dwc2 will not be able to
-* clear them after entering hibernation.
+* clear them after entering partial_power_down.
 */
dwc2_writel(0x, hsotg->regs + GINTSTS);
 
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 5c17cf0482b9..93c58a4175c3 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -421,9 +421,9 @@ enum dwc2_ep0_state {
  *  case.
  *  0 - No (default)
  *  1 - Yes
- * @hibernation:   Specifies whether the controller support hibernation.
- * If hibernation is enabled, the controller will enter
- * hibernation in both peripheral and host mode when
+ * @power_down: Specifies whether the controller support power_down.
+ * If power_down is enabled, the controller will enter
+ * power_down in both peripheral and host mode when
  * needed.
  * 0 - No (default)
  * 1 - Yes
@@ -498,7 +498,7 @@ struct dwc2_core_params {
bool reload_ctl;
bool uframe_sched;
bool external_id_pin_ctl;
-   bool hibernation;
+   bool power_down;
bool lpm;
bool lpm_clock_gating;
bool besl;
@@ -1110,8 +1110,8 @@ static inline bool dwc2_is_hs_iot(struct dwc2_hsotg 
*hsotg)
  * and the DWC_otg controller
  */
 int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait);
-int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
-int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
+int dwc2_enter_partial_power_down(struct dwc2_hsotg *hsotg);
+int dwc2_exit_partial_power_down(struct dwc2_hsotg *hsotg, bool restore);
 
 void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host);
 void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg);
diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index 46b32ec7d343..41d7dda40cb1 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -321,10 +321,10 @@ static void dwc2_handle_session_req_intr(struct 
dwc2_hsotg *hsotg)
 
if (dwc2_is_device_mode(hsotg)) {
if (hsotg->lx_state == DWC2_L2) {
-   ret = dwc2_exit_hibernation(hsotg, true);
+   ret = dwc2_exit_partial_power_down(hsotg, true);
if (ret && (ret != -ENOTSUPP))
dev_err(hsotg->dev,
- 

[PATCH 02/14] usb: dwc2: Add hibernation field into dwc2_hw_params

2018-01-26 Thread Grigor Tovmasyan
From: Vardan Mikayelyan 

Add parameter and it's initialization, needed for hibernation.

Reimplement dwc2_set_param_power_down() to support hibernation too.
Now 'power_down' parameter can be initialized with 0, 1 or 2.
0 - No
1 - Partial power down
2 - Hibernation

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
Signed-off-by: Grigor Tovmasyan 
---
 drivers/usb/dwc2/core.c   |  2 +-
 drivers/usb/dwc2/core.h   | 12 ++--
 drivers/usb/dwc2/hcd.c|  4 ++--
 drivers/usb/dwc2/params.c | 34 ++
 4 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index e26aeda29bba..ebe5a291f1a3 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -138,7 +138,7 @@ int dwc2_exit_partial_power_down(struct dwc2_hsotg *hsotg, 
bool restore)
u32 pcgcctl;
int ret = 0;
 
-   if (!hsotg->params.power_down)
+   if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL)
return -ENOTSUPP;
 
pcgcctl = dwc2_readl(hsotg->regs + PCGCTL);
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 93c58a4175c3..aab080bf8ef5 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -426,7 +426,8 @@ enum dwc2_ep0_state {
  * power_down in both peripheral and host mode when
  * needed.
  * 0 - No (default)
- * 1 - Yes
+ * 1 - Partial power down
+ * 2 - Hibernation
  * @lpm:   Enable LPM support.
  * 0 - No
  * 1 - Yes
@@ -498,7 +499,12 @@ struct dwc2_core_params {
bool reload_ctl;
bool uframe_sched;
bool external_id_pin_ctl;
-   bool power_down;
+
+   int power_down;
+#define DWC2_POWER_DOWN_PARAM_NONE 0
+#define DWC2_POWER_DOWN_PARAM_PARTIAL  1
+#define DWC2_POWER_DOWN_PARAM_HIBERNATION  2
+
bool lpm;
bool lpm_clock_gating;
bool besl;
@@ -578,6 +584,7 @@ struct dwc2_core_params {
  *   2 - FS pins shared with UTMI+ pins
  *   3 - FS pins shared with ULPI pins
  * @total_fifo_size:Total internal RAM for FIFOs (bytes)
+ * @hibernationIs hibernation enabled?
  * @utmi_phy_data_width UTMI+ PHY data width
  *   0 - 8 bits
  *   1 - 16 bits
@@ -609,6 +616,7 @@ struct dwc2_hw_params {
unsigned num_dev_perio_in_ep:4;
unsigned total_fifo_size:16;
unsigned power_optimized:1;
+   unsigned hibernation:1;
unsigned utmi_phy_data_width:2;
unsigned lpm_mode:1;
u32 snpsid;
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 96a751d927d1..050e01e193c8 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -4359,7 +4359,7 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
if (hsotg->op_state == OTG_STATE_B_PERIPHERAL)
goto unlock;
 
-   if (!hsotg->params.power_down)
+   if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL)
goto skip_power_saving;
 
/*
@@ -4414,7 +4414,7 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
if (hsotg->lx_state != DWC2_L2)
goto unlock;
 
-   if (!hsotg->params.power_down) {
+   if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL) {
hsotg->lx_state = DWC2_L0;
goto unlock;
}
diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index c472e93de350..8c4ede8a4eea 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -469,6 +469,38 @@ static void dwc2_check_param_phy_utmi_width(struct 
dwc2_hsotg *hsotg)
dwc2_set_param_phy_utmi_width(hsotg);
 }
 
+static void dwc2_check_param_power_down(struct dwc2_hsotg *hsotg)
+{
+   int param = hsotg->params.power_down;
+
+   switch (param) {
+   case DWC2_POWER_DOWN_PARAM_NONE:
+   break;
+   case DWC2_POWER_DOWN_PARAM_PARTIAL:
+   if (hsotg->hw_params.power_optimized)
+   break;
+   dev_dbg(hsotg->dev,
+   "Partial power down isn't supported by HW\n");
+   param = DWC2_POWER_DOWN_PARAM_NONE;
+   break;
+   case DWC2_POWER_DOWN_PARAM_HIBERNATION:
+   if (hsotg->hw_params.hibernation)
+   break;
+   dev_dbg(hsotg->dev,
+   "Hibernation isn't supported by HW\n");
+   param = DWC2_POWER_DOWN_PARAM_NONE;
+   break;
+   default:
+   dev_err(hsotg->dev,
+   "%s: Invalid parameter power_down=%d\n",
+   __func__, param);
+   param 

[PATCH 00/14] usb: dwc2: Add hibernation support

2018-01-26 Thread Grigor Tovmasyan
This series contains patches which are already have been sent in
"usb: dwc2: fixes, enhancements and new features" series.

That patch series was too large, and based on community feedbacks decided to 
split that series into small pieces. This is a fourth and last part.

In this series we included only patches related with hibernation. 

All patches were tested on HAPS-DX7 platform.

Changes after first submission:

usb: dwc2: Add hibernation feature support (Hibernation):
   
usb: dwc2: gadget: Fix dwc2_restore_device_registers
- Added WA in dwc2_restore_device_registers() function for enabled 
EPx's IN
  in DDMA mode for not to get BNA Interrupt asserted on hibernation 
exit. 

usb: dwc2: Add helper functions for restore routine 
- Added argument is_host to determine if core is in host mode or not 
and 
  changed some udelay values in dwc2_hib_restore_common() function. 
- Added is_host function parameter to determine being in host mode, 
checking
  host mode to set pcgcctl properly and changed hard coded numbers to 
  defined values also changed the logic of loading restore values for 
  [31:14] bits in dwc2_restore_essential_regs() function.
   
usb: dwc2: Add dwc2_handle_gpwrdn_intr() handler
- Fixed a minor bug: added checks for determine hibernation exiting 
flows 
  in dwc2_handle_gpwrdn_intr() function. Also changed the way of 
clearing 
  all interrupts. 

usb: dwc2: Add host/device hibernation functions   
- dwc2_gadget_enter_hibernation() fixed some minor bugs, phy clock now 
  remains not stopped. Added unmasking of GPWRDN_STS_CHGINT_MSK device
  mode interrupts in GPWRDN.
- dwc2_host_enter_hibernation() added a udelay after writing in gpwrdn 
register.



John Youn (1):
  usb: dwc2: Enable power down

Vardan Mikayelyan (13):
  usb: dwc2: Rename hibernation to partial_power_down
  usb: dwc2: Add hibernation field into dwc2_hw_params
  usb: dwc2: gadget: Moved dtxfsiz backup array place
  usb: dwc2: gadget: Fix dwc2_restore_device_registers
  usb: dwc2: core: Add hibernated flag
  usb: dwc2: gadget: Add remote_wakeup_allowed flag
  usb: dwc2: Changes in registers backup/restore functions
  usb: dwc2: Add helper functions for restore routine
  usb: dwc2: Add host/device hibernation functions
  usb: dwc2: Add dwc2_enter_hibernation(), dwc2_exit_hibernation()
  usb: dwc2: Allow entering hibernation from USB_SUSPEND interrupt
  usb: dwc2: Add dwc2_handle_gpwrdn_intr() handler
  usb: dwc2: Change hub-control to allow hibernation

 drivers/usb/dwc2/core.c  | 210 ++---
 drivers/usb/dwc2/core.h  |  69 ---
 drivers/usb/dwc2/core_intr.c | 179 
 drivers/usb/dwc2/debugfs.c   |   2 +-
 drivers/usb/dwc2/gadget.c| 227 +---
 drivers/usb/dwc2/hcd.c   | 269 ---
 drivers/usb/dwc2/params.c|  50 +++-
 drivers/usb/dwc2/platform.c  |   1 +
 8 files changed, 917 insertions(+), 90 deletions(-)

-- 
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


Re: uvcvideo: Failed to resubmit video URB (-1).

2018-01-26 Thread Greg KH
On Thu, Jan 25, 2018 at 01:37:45PM -0300, Cristian wrote:
> Hello,
> 
> Open bug in bugzilla.kernel.org
> https://bugzilla.kernel.org/show_bug.cgi?id=198575
> 
> dmesg:
> [ 6529.509530] uvcvideo: Failed to resubmit video URB (-1).

Does that mean the device does not work?  What happened when this
message showed up?

We need a bit more information than just one kernel log message :)

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: [PATCHv2] musb_host: fix lockup on rxcsr_h_error

2018-01-26 Thread Tomas Paukrt

Hi Maxim,

unfortunately we cannot test the latest kernel right now, because we 
have custom drivers and additional changes that need to be ported, but 
the MUSB driver in our kernel should contain all fixes from 
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/log/drivers/usb/musb


Best regards

Tomas


Dne 25.1.2018 v 17:24 Maxim Uvarov napsal(a):

[1] says that issue is with back ported driver to 3.12.10. Can the
latest kernel be tested on the same hw?

Maxim.

2018-01-25 18:45 GMT+03:00 Bin Liu :

Hi Yegor and Max,

On Tue, May 03, 2016 at 04:25:58PM +0200, Yegor Yefremov wrote:

On Tue, May 3, 2016 at 3:48 PM, Bin Liu  wrote:

Hi,

On Tue, May 03, 2016 at 12:03:52PM +0200, Yegor Yefremov wrote:

On Thu, Apr 28, 2016 at 4:37 PM, Bin Liu  wrote:

Hi,

On Thu, Apr 28, 2016 at 09:51:37AM +0300, Maxim Uvarov wrote:

[snip]


Hello Bin,

yes, it also works with that reset and go to finish:

diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index c3d5fc9..8cd98e7 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -1599,6 +1599,10 @@ void musb_host_rx(struct musb *musb, u8 epnum)
 status = -EPROTO;
 musb_writeb(epio, MUSB_RXINTERVAL, 0);

+   rx_csr &= ~MUSB_RXCSR_H_ERROR;
+   musb_writew(epio, MUSB_RXCSR, rx_csr);
+
+   goto finish;
 } else if (rx_csr & MUSB_RXCSR_DATAERROR) {

 if (USB_ENDPOINT_XFER_ISOC != qh->type) {


Thanks for testing it.

Have tested your patch and now both FT4232 and Huawei don't freeze on removal.

Bin, Max thanks for fixing this issue.

Tested-by: Yegor Yefremov 

Thanks for testing.

Can you please test the patch [1] instead? I'd like to use it as the
fix.

[1] http://marc.info/?l=linux-usb=146222355213935=2

The patch behaves the same as the previous one.

Sorry for bringing up this old thread, but it seems to be too aggressive
to stop scheduling further urbs on errors [1]. So is it possible for you
to re-test your usecase by reverting commit

 dbac5d07d13e ("usb: musb: host: don't start next rx urb if current one 
failed")

to see if only commit

 b5801212229f ("usb: musb: host: clear rxcsr error bit if set")

itself solves your issue?

I know you have tested the patch in [2], which is similar to commit
b5801212229f, but tha latter doesn't have 'goto finish' which does dma
cleanup on errors, it makes more sense to me. But I'd like to have you
tested with reverting dbac5d07d13e to be sure.

[1] https://marc.info/?l=linux-usb=151689238420622=2
[2] https://marc.info/?l=linux-kernel=146185425805967=2

thanks,
-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: USB-C Devices only show up if connected at boot

2018-01-26 Thread Mike Lothian
On 26 January 2018 at 08:31, Mika Westerberg
 wrote:
> On Fri, Jan 26, 2018 at 08:07:56AM +, Mike Lothian wrote:
>> Whether CONFIG_HOTPLUG_PCI_ACPI=y or CONFIG_HOTPLUG_PCI_ACPI=n the
>> device doesn't show unless echo 1 > /sys/bus/pci/rescan is issued
>
> That's not how it is supposed to work. Please send me full dmesg and in
> addition acpidump of the system (or attach it to the bugzilla bug). Also
> share your .config.

I've attached my full dmesg and .config to the bug. The acpidump info
can be found at https://bugzilla.kernel.org/show_bug.cgi?id=198051,
the current kernel has the attached patch to enable
AcpiGbl_ParseTableAsTermList, the bug also contains a dmesg without it
--
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 0/4] Backport missing sccurity and deadlock fix

2018-01-26 Thread Greg KH
On Thu, Jan 25, 2018 at 11:37:40AM -0700, Shuah Khan wrote:
> As I started backporting security fixes, I found a deadlock bug that was
> fixed in a later release. This patch series contains backports for all
> these problems.

All now queued up, thanks for the backports.

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: [PATCHv2] musb_host: fix lockup on rxcsr_h_error

2018-01-26 Thread Maxim Uvarov
Bin,

I looked to my local git and code does not have this latest line "goto
finish".  It was tested without it and everything worked. Right now I
can not get access to that hardware to check with and without. But
only can confirm that without "goto finish" function works with bunch
of drivers (usb ethernet, hids, hdd).

Best regards,
Maxim.

2018-01-25 19:31 GMT+03:00 Bin Liu :
> Maxim,
>
> On Thu, Jan 25, 2018 at 07:24:02PM +0300, Maxim Uvarov wrote:
>> [1] says that issue is with back ported driver to 3.12.10. Can the
>> latest kernel be tested on the same hw?
>
> Agreed that it should be tested with the latest kernel. But my concern
> now is if stopping scheduling urbs on errors is a right thing to do,
> that is why I asked if you can re-test your usecase with reverting the
> commit. I am unable to reproduce the original issue you had.
>
> Thanks,
> -Bin.



-- 
Best regards,
Maxim Uvarov
--
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: [RFC/RFT usb-next v1 5/6] usb: chipidea: do not set the "phy" field in struct usb_hcd

2018-01-26 Thread Peter Chen
 
> 
> Now that usb_add_hcd parses all generic PHYs anyways the code which skips
> initialization of a single PHY will go away.
> Remove the code which sets struct usb_hcd's phy field from the chipidea 
> driver as
> this field will go away soon.
> 
> Signed-off-by: Martin Blumenstingl 
> ---
>  drivers/usb/chipidea/host.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index
> 19d60ed7e41f..fc324767cb0f 100644
> --- a/drivers/usb/chipidea/host.c
> +++ b/drivers/usb/chipidea/host.c
> @@ -124,9 +124,7 @@ static int host_start(struct ci_hdrc *ci)
> 
>   hcd->power_budget = ci->platdata->power_budget;
>   hcd->tpl_support = ci->platdata->tpl_support;
> - if (ci->phy)
> - hcd->phy = ci->phy;
> - else
> + if (!ci->phy)
>   hcd->usb_phy = ci->usb_phy;
> 

The reason hcd->phy is initialized by chipidea core is we do not need HCD core 
to
touch PHY, and PHY operation is shared for both device and host mode for 
chipidea.

If I understand correct, your HCD core PHY wrapper patch set will do PHY 
operation if
there is a "phy" node under controller's? If it is correct, you may supply one 
way to let
the HCD core bypass phy operations for some USB controllers, eg dual-role 
controllers.
Thanks.

Peter

--
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: USB-C Devices only show up if connected at boot

2018-01-26 Thread Mika Westerberg
On Fri, Jan 26, 2018 at 08:07:56AM +, Mike Lothian wrote:
> Whether CONFIG_HOTPLUG_PCI_ACPI=y or CONFIG_HOTPLUG_PCI_ACPI=n the
> device doesn't show unless echo 1 > /sys/bus/pci/rescan is issued

That's not how it is supposed to work. Please send me full dmesg and in
addition acpidump of the system (or attach it to the bugzilla bug). Also
share your .config.
--
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: USB-C Devices only show up if connected at boot

2018-01-26 Thread Mike Lothian
On 26 January 2018 at 06:33, Mika Westerberg
 wrote:
> On Thu, Jan 25, 2018 at 10:20:02PM +, Mike Lothian wrote:
>> I've just tried this and the USB-C device was detected :D This is the
>> first time it's ever been detected after boot
>>
>> 02:00.0 PCI bridge: Intel Corporation DSL6340 Thunderbolt 3 Bridge
>> [Alpine Ridge 2C 2015]
>>Kernel driver in use: pcieport
>> 03:00.0 PCI bridge: Intel Corporation DSL6340 Thunderbolt 3 Bridge
>> [Alpine Ridge 2C 2015]
>>Kernel driver in use: pcieport
>> 03:01.0 PCI bridge: Intel Corporation DSL6340 Thunderbolt 3 Bridge
>> [Alpine Ridge 2C 2015]
>>Kernel driver in use: pcieport
>> 03:02.0 PCI bridge: Intel Corporation DSL6340 Thunderbolt 3 Bridge
>> [Alpine Ridge 2C 2015]
>>Kernel driver in use: pcieport
>> 39:00.0 USB controller: Intel Corporation DSL6340 USB 3.1 Controller
>> [Alpine Ridge]
>>Subsystem: Device :
>>Kernel driver in use: xhci_hcd
>
> Yes, this is how it should work. All those PCI bridges + xHCI are
> hotplugged when you plug in a USB-C device.
> --
> 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

Whether CONFIG_HOTPLUG_PCI_ACPI=y or CONFIG_HOTPLUG_PCI_ACPI=n the
device doesn't show unless echo 1 > /sys/bus/pci/rescan is issued
--
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