[PATCH 2/3] usb: host: xhci: return -ESHUTDOWN when removing hcd

2018-09-20 Thread Peter Chen
When we are removing HCD, the xhci_configure_endpoint may be timeout.
To get rid of timeout, we'd better return before issue command.
The related log message when removing HCD like below:

[66.736633] usb 3-1: USB disconnect, device number 2
[66.737003] hub 3-1:1.0: hub_ext_port_status failed (err = -71)
[66.737054] usb 3-1.1: USB disconnect, device number 3
[66.759910] xhci-hcd xhci-hcd.1.auto: remove, state 4
[66.765043] usb usb4: USB disconnect, device number 1
[66.770169] usb 4-1: USB disconnect, device number 2
[74.008294] xhci-hcd xhci-hcd.1.auto: Timeout while waiting for
configure endpoint command
[74.018737] xhci-hcd xhci-hcd.1.auto: USB bus 4 deregistered
[74.024446] xhci-hcd xhci-hcd.1.auto: remove, state 1
[74.029594] usb usb3: USB disconnect, device number 1
[74.062310] xhci-hcd xhci-hcd.1.auto: USB bus 3 deregistered

Signed-off-by: Peter Chen 
---
 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 0420eefa647a..3113938063fd 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -2698,7 +2698,8 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
 
spin_lock_irqsave(>lock, flags);
 
-   if (xhci->xhc_state & XHCI_STATE_DYING) {
+   if (xhci->xhc_state & XHCI_STATE_DYING ||
+   xhci->xhc_state & XHCI_STATE_REMOVING) {
spin_unlock_irqrestore(>lock, flags);
return -ESHUTDOWN;
}
-- 
2.14.1



[PATCH 3/3] usb: host: xhci: return early for xhci_urb_dequeue when removing hcd

2018-09-20 Thread Peter Chen
When we are removing hcd, the stop endpoint command may be timeout.
To eliminate the timeout, we'd better return early. The related log
for this timeout like below:

[31.208933] hub 3-1:1.0: hub_ext_port_status failed (err = -71)
[31.214972] usb 3-1-port2: cannot reset (err = -71)
[31.219962] usb 3-1-port2: cannot reset (err = -71)
[31.225069] usb 3-1-port2: cannot reset (err = -71)
[31.230018] usb 3-1-port2: Cannot enable. Maybe the USB cable is bad?
[31.236566] usb 3-1-port2: cannot disable (err = -71)
[31.241745] usb 3-1-port2: unable to enumerate USB device
[31.247255] usb 3-1-port2: cannot disable (err = -71)
[31.252422] hub 3-1:1.0: hub_ext_port_status failed (err = -71)
[31.258486] hub 3-1:1.0: hub_ext_port_status failed (err = -71)
[31.264518] hub 3-1:1.0: hub_ext_port_status failed (err = -71)
[31.270649] hub 3-1:1.0: hub_ext_port_status failed (err = -71)
[31.276723] hub 3-1:1.0: hub_ext_port_status failed (err = -71)
[31.282809] usb 3-1: USB disconnect, device number 2
[31.287859] usb 3-1.1: USB disconnect, device number 3
[31.293076] usb 3-1.1: unregistering device
[31.299292] xhci-hcd xhci-hcd.1.auto: remove, state 4
[31.304416] usb usb4: USB disconnect, device number 1
[31.309566] usb 4-1: USB disconnect, device number 2
[31.314589] usb 4-1: unregistering device
[31.316389] usb 3-1: unregistering device
[31.331131] usb usb4: unregistering device
[31.339809] xhci-hcd xhci-hcd.1.auto: USB bus 4 deregistered
[31.345534] xhci-hcd xhci-hcd.1.auto: remove, state 1
[31.350668] usb usb3: USB disconnect, device number 1
[36.407457] xhci-hcd xhci-hcd.1.auto: xHCI host not responding to stop endpoint 
command.
[36.423638] xhci-hcd xhci-hcd.1.auto: xHCI host controller not responding, 
assume dead
[36.436502] usb usb3: unregistering device
[36.445429] xhci-hcd xhci-hcd.1.auto: USB bus 3 deregistered

Signed-off-by: Peter Chen 
---
 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 3113938063fd..1bcf27a9737d 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1601,7 +1601,8 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct 
urb *urb, int status)
goto err_giveback;
}
 
-   if (xhci->xhc_state & XHCI_STATE_HALTED) {
+   if (xhci->xhc_state & XHCI_STATE_HALTED ||
+   xhci->xhc_state & XHCI_STATE_REMOVING) {
xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
"HC halted, freeing TD manually.");
for (i = urb_priv->num_tds_done;
-- 
2.14.1



[PATCH 1/3] usb: host: xhci: fix oops when removing hcd

2018-09-20 Thread Peter Chen
The USB3 HCD structure (xhci->shared_hcd) may be NULL when the USB3
interrupt occurs, the typical use case is we plug out Type-C-to-A cable,
and there is a USB device at the port. The platform controller driver
(eg, dwc3) unregisters xhci platform driver, and remove hcd accordingly.
It is very easy to reproduce if there is a USB3 HUB on the port, and there
is no USB3 device on HUB's port, the controller is at U3, it performs
a far-end receiver termination detection every 100 ms, so the USB3 port
change interrupt may be occurs 100ms maximum later when we plug out
Type-C-to-A cable, and the USB3 HCD has already been NULL at that time.
The oops log like below:

[681.782288] xhci-hcd xhci-hcd.1.auto: remove, state 1
[681.787490] usb usb4: USB disconnect, device number 1
[681.792808] usb 4-1: USB disconnect, device number 2
[681.818089] xhci-hcd xhci-hcd.1.auto: USB bus 4 deregistered
[681.823803] Unable to handle kernel NULL pointer dereference at virtual 
address 00a0
[681.823806] Mem abort info:
[681.823809]   Exception class = DABT (current EL), IL = 32 bits
[681.823811]   SET = 0, FnV = 0
[681.823813]   EA = 0, S1PTW = 0
[681.823814] Data abort info:
[681.823816]   ISV = 0, ISS = 0x0004
[681.823818]   CM = 0, WnR = 0
[681.823822] user pgtable: 4k pages, 48-bit VAs, pgd = 8000ae3fd000
[681.823824] [00a0] *pgd=
[681.823829] Internal error: Oops: 9604 [#1] PREEMPT SMP
[681.823832] Modules linked in: 8021q garp stp mrp crc32_ce qca6174(O) 
crct10dif_ce galcore(O)
[681.823849] CPU: 0 PID: 94 Comm: kworker/0:1 Tainted: G   O
4.14.62-imx_4.14.y+gcd63def #1
[681.823851] Hardware name: Freescale i.MX8MQ EVK (DT)
[681.823862] Workqueue: events_freezable __dwc3_set_mode
[681.823865] task: 8000b8a18000 task.stack: 0a01
[681.823872] PC is at xhci_irq+0x5fc/0x14b8
[681.823875] LR is at xhci_irq+0x3c/0x14b8
[681.823878] pc : [] lr : [] pstate: 
81c5
[681.823880] sp : 08003b20
[681.823882] x29: 08003b20 x28: 0a53df10
[681.823886] x27: 8000ae3c0238 x26: 01c0
[681.823890] x25: 8000ae3c x24: 0a53df10
[681.823893] x23:  x22: 09297db8
[681.823897] x21: 08f3f0e8 x20: 0001
[681.823901] x19: 8000ae3c0284 x18: 0010
[681.823904] x17: 00427268 x16: 00f1
[681.823908] x15:  x14: 
[681.823911] x13: 08db0500 x12: 0001
[681.823915] x11: 08db0508 x10: 0040
[681.823918] x9 : 094e4088 x8 : 8000b602
[681.823922] x7 : 8000b6020028 x6 : 0001
[681.823925] x5 : 0001 x4 : 
[681.823928] x3 : 0003 x2 : 0002
[681.823932] x1 : 8000ae3c x0 : 8000b48b8c00
[681.823936] Process kworker/0:1 (pid: 94, stack limit = 0x0a01)
[681.823938] Call trace:
[681.823942] Exception stack(0x080039e0 to 0x08003b20)
[681.823946] 39e0: 8000b48b8c00 8000ae3c 0002 
0003
[681.823950] 3a00:  0001 0001 
8000b6020028
[681.823953] 3a20: 8000b602 094e4088 0040 
08db0508
[681.823957] 3a40: 0001 08db0500  

[681.823960] 3a60: 00f1 00427268 0010 
8000ae3c0284
[681.823964] 3a80: 0001 08f3f0e8 09297db8 

[681.823968] 3aa0: 0a53df10 8000ae3c 01c0 
8000ae3c0238
[681.823972] 3ac0: 0a53df10 08003b20 088fec44 
08003b20
[681.823975] 3ae0: 088ff204 81c5 7e0002d0bb40 
8000b42ed880
[681.823979] 3b00:  081fd2b4 08003b20 
088ff204
[681.823984] [] xhci_irq+0x5fc/0x14b8
[681.823991] [] usb_hcd_irq+0x2c/0x48
[681.823997] [] __handle_irq_event_percpu+0x5c/0x148
[681.824000] [] handle_irq_event_percpu+0x1c/0x58
[681.824003] [] handle_irq_event+0x48/0x78
[681.824008] [] handle_fasteoi_irq+0xa8/0x180
[681.824014] [] generic_handle_irq+0x24/0x38
[681.824018] [] __handle_domain_irq+0x5c/0xb8
[681.824023] [] gic_handle_irq+0x78/0x17c
[681.824026] Exception stack(0x08003d90 to 0x08003ed0)
[681.824029] 3d80:    
09667700
[681.824032] 3da0: 0708  0016 
00ff
[681.824036] 3dc0: 363b4285 7fff 8000bdf62db8 
0004
[681.824039] 3de0: 00f1 08db0508 0001 
08db0500
[681.824043] 3e00:   00f1 
00427268
[681.824047] 3e20: 0010 8000b8a18000 0003 
09667700
[681.824051] 3e40: 094b0018 8000b8006c00 09664000 
0001000174c1
[681.824055] 3e60: 

[PATCH 0/3] usb: host: xhci: fix oops and timeout when removing hcd

2018-09-20 Thread Peter Chen
Hi Mathias,

I have run out this issue for v4.14 kernel, but the problem should exist
at mainline kernel too, the USB3 interrupt may occur after USB3 HCD
structure has removed, and cause oops at xhci_irq. The 2nd and 3rd
patches are needed if we return early at xhci_irq when we are removing
HCD.

Peter Chen (3):
  usb: host: xhci: fix oops when removing hcd
  usb: host: xhci: return -ESHUTDOWN when removing hcd
  usb: host: xhci: return early for xhci_urb_dequeue when removing hcd

 drivers/usb/host/xhci-ring.c | 3 ++-
 drivers/usb/host/xhci.c  | 6 --
 2 files changed, 6 insertions(+), 3 deletions(-)

-- 
2.14.1



Re: usb typec not doing handling in-kernel

2018-09-20 Thread Guenter Roeck
On Thu, Sep 20, 2018 at 10:21:59AM +0200, Heiko Stuebner wrote:
> Hi Guenter,
> 
> Am Montag, 13. August 2018, 14:29:15 CEST schrieb Guenter Roeck:
> > On 08/13/2018 03:36 AM, Heiko Stuebner wrote:
> > > Hi,
> > > 
> > > I'm currently trying to wrap my head around the new typec subsystem and
> > > also how to do it correctly on Rockchip rk3399 devices.
> > > 
> > > The issue (and Guenter might know quite a bit about that) is that on
> > > ChromeOS devices the embedded controller hides the whole tcpm/vdm
> > > logic from the operating system and just provides a custom interface to
> > > query things like cable state, display-port hotplug status and so on.
> > > 
> > > So right now the rk3399-typec-phy uses that extcon-based interface to
> > > get all status changes but that of course leaves out all systems directly
> > > talking to a fusb302. I did a small drawing to showcase that:
> > > 
> > > ---
> > > | typec-phy || extcon-cros-ec |\
> > > --- \
> > >   |\  \
> > > -  \ --   \ ---
> > > |  cdn-dp   |   \| ?  |-| fusb302 |
> > > --- ---
> > > 
> > > So to bring everything on the same page, I guess the cros-ec extcon
> > > (drivers/extcon/extcon-usbc-cros-ec.c) should somehow use the typec
> > > functions instead of implementing an extcon? But from reading into the
> > > typec code, it somehow looks like the typec framework expects to be in
> > > control of things like altmode negotiations, or am I misreading something?
> > > 
> > I used to have a patch for the cros-ec extcon driver which ties it into the
> > typec subsystem. Let me see if I can dig it up.
> 
> were your archeological skills working in finding said old patch?
> 

Not very well :-(

Guenter


Re: [PATCH v3] usb: core: added uevent for over-current

2018-09-20 Thread Jon Flatley
On Thu, Sep 20, 2018 at 10:58 AM Greg KH  wrote:
>
> On Thu, Sep 20, 2018 at 10:17:54AM -0700, Jon Flatley wrote:
> > After commit 1cbd53c8cd85 ("usb: core: introduce per-port over-current
> > counters") usb ports expose a sysfs value 'over_current_count'
> > to user space. This value on its own is not very useful as it requires
> > manual polling.
> >
> > As a solution, fire a udev event from the usb hub device that specifies
> > the values 'OVER_CURRENT_PORT' and 'OVER_CURRENT_COUNT' that indicate
> > the path of the usb port where the over-current event occurred and the
> > value of 'over_current_count' in sysfs. Additionally, call
> > sysfs_notify() so the sysfs value supports poll().
> >
> > Signed-off-by: Jon Flatley 
> > ---
> >  Documentation/ABI/testing/sysfs-bus-usb |  9 ++-
> >  drivers/usb/core/hub.c  | 36 +
> >  2 files changed, 44 insertions(+), 1 deletion(-)
>
> You should always put the "what changed in this version" below the ---
> line so that people know what happened.
>
> I am guess you just rebased this?  Any other change?
>
> thanks,
>
> greg k-h

Apologies, I'll make sure to do that in the future.

Yes, this is just a rebase onto v4.19-rc4, no other changes.
I checked to be sure this applies to usb-next without conflict.

Thanks,
Jon


Re: [PATCH v3] usb: core: added uevent for over-current

2018-09-20 Thread Greg KH
On Thu, Sep 20, 2018 at 10:17:54AM -0700, Jon Flatley wrote:
> After commit 1cbd53c8cd85 ("usb: core: introduce per-port over-current
> counters") usb ports expose a sysfs value 'over_current_count'
> to user space. This value on its own is not very useful as it requires
> manual polling.
> 
> As a solution, fire a udev event from the usb hub device that specifies
> the values 'OVER_CURRENT_PORT' and 'OVER_CURRENT_COUNT' that indicate
> the path of the usb port where the over-current event occurred and the
> value of 'over_current_count' in sysfs. Additionally, call
> sysfs_notify() so the sysfs value supports poll().
> 
> Signed-off-by: Jon Flatley 
> ---
>  Documentation/ABI/testing/sysfs-bus-usb |  9 ++-
>  drivers/usb/core/hub.c  | 36 +
>  2 files changed, 44 insertions(+), 1 deletion(-)

You should always put the "what changed in this version" below the ---
line so that people know what happened.

I am guess you just rebased this?  Any other change?

thanks,

greg k-h


[PATCH v3] usb: core: added uevent for over-current

2018-09-20 Thread Jon Flatley
After commit 1cbd53c8cd85 ("usb: core: introduce per-port over-current
counters") usb ports expose a sysfs value 'over_current_count'
to user space. This value on its own is not very useful as it requires
manual polling.

As a solution, fire a udev event from the usb hub device that specifies
the values 'OVER_CURRENT_PORT' and 'OVER_CURRENT_COUNT' that indicate
the path of the usb port where the over-current event occurred and the
value of 'over_current_count' in sysfs. Additionally, call
sysfs_notify() so the sysfs value supports poll().

Signed-off-by: Jon Flatley 
---
 Documentation/ABI/testing/sysfs-bus-usb |  9 ++-
 drivers/usb/core/hub.c  | 36 +
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/sysfs-bus-usb 
b/Documentation/ABI/testing/sysfs-bus-usb
index 08d456e07b53..c4a70f532ec3 100644
--- a/Documentation/ABI/testing/sysfs-bus-usb
+++ b/Documentation/ABI/testing/sysfs-bus-usb
@@ -219,7 +219,14 @@ Description:
ports and report them to the kernel. This attribute is to expose
the number of over-current situation occurred on a specific port
to user space. This file will contain an unsigned 32 bit value
-   which wraps to 0 after its maximum is reached.
+   which wraps to 0 after its maximum is reached. This file 
supports
+   poll() for monitoring changes to this value in user space.
+
+   Any time this value changes the corresponding hub device will 
send a
+   udev event with the following attributes:
+
+   OVER_CURRENT_PORT=/sys/bus/usb/devices/.../(hub interface)/portX
+   OVER_CURRENT_COUNT=[current value of this sysfs attribute]
 
 What:  /sys/bus/usb/devices/.../(hub interface)/portX/usb3_lpm_permit
 Date:  November 2015
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 462ce49f683a..7801bb30bdba 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -5147,6 +5148,40 @@ static void hub_port_connect_change(struct usb_hub *hub, 
int port1,
usb_lock_port(port_dev);
 }
 
+/* Handle notifying userspace about hub over-current events */
+static void port_over_current_notify(struct usb_port *port_dev)
+{
+   static char *envp[] = { NULL, NULL, NULL };
+   struct device *hub_dev;
+   char *port_dev_path;
+
+   sysfs_notify(_dev->dev.kobj, NULL, "over_current_count");
+
+   hub_dev = port_dev->dev.parent;
+
+   if (!hub_dev)
+   return;
+
+   port_dev_path = kobject_get_path(_dev->dev.kobj, GFP_KERNEL);
+   if (!port_dev_path)
+   return;
+
+   envp[0] = kasprintf(GFP_KERNEL, "OVER_CURRENT_PORT=%s", port_dev_path);
+   if (!envp[0])
+   return;
+
+   envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u",
+   port_dev->over_current_count);
+   if (!envp[1])
+   goto exit;
+
+   kobject_uevent_env(_dev->kobj, KOBJ_CHANGE, envp);
+
+   kfree(envp[1]);
+exit:
+   kfree(envp[0]);
+}
+
 static void port_event(struct usb_hub *hub, int port1)
__must_hold(_dev->status_lock)
 {
@@ -5189,6 +5224,7 @@ static void port_event(struct usb_hub *hub, int port1)
if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
u16 status = 0, unused;
port_dev->over_current_count++;
+   port_over_current_notify(port_dev);
 
dev_dbg(_dev->dev, "over-current change #%u\n",
port_dev->over_current_count);
-- 
2.19.0.444.g18242da7ef-goog



Re: some question about ehci-sched.c

2018-09-20 Thread Alan Stern
On Fri, 21 Sep 2018, yoma sophian wrote:

> hi all:
> in iso_stream_schedule of ehci-sched.c, why we have to add the "-" in
> (-(++ehci->random_frame))  to calculate the start uframe?
> thanks for ur help in advance.
> 
> if (stream->ps.phase == NO_FRAME) {
> int done = 0;
> struct ehci_tt  *tt = find_tt(stream->ps.udev);
> 
> if (IS_ERR(tt)) {
> status = PTR_ERR(tt);
> goto fail;
> }
> compute_tt_budget(ehci->tt_budget, tt);
> 
> start = ((-(++ehci->random_frame)) << 3) & (period - 
> 1);
>   ^^ Here it is.

We don't _have_ to do it.  It is a small optimization; an attempt to
avoid schedule collisions between interrupt transactions and
isochronous transactions.  The effect of the "-" is that the code tries
frames in backward order when it is scheduling isochronous URBs -- as
opposed to trying frames in forward order when scheduling periodic
URBs.

It isn't important.

Alan Stern



[PATCH v2 07/10] xhci: Use soft retry to recover faster from transaction errors

2018-09-20 Thread Mathias Nyman
Use soft retry to recover from a USB Transaction Errors that are caused by
temporary error conditions. The USB device is not aware that the xHC
has halted the endpoint, and will be waiting for another retry

A Soft Retry perform additional retries and recover from an error which has
caused the xHC to halt an endpoint.

Soft retry has some limitations:
Soft Retry attempts shall not be performed on Isoch endpoints
Soft Retry attempts shall not be performed if the device is behind a TT in
a HS Hub

Software shall limit the number of unsuccessful Soft Retry attempts to
prevent an infinite loop.

For more details on Soft retry see xhci specs  4.6.8.1

Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-ring.c | 19 +++
 drivers/usb/host/xhci.h  |  2 ++
 2 files changed, 21 insertions(+)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index f0a99aa..c41341e 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1155,6 +1155,10 @@ static void xhci_handle_cmd_reset_ep(struct xhci_hcd 
*xhci, int slot_id,
/* Clear our internal halted state */
xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_HALTED;
}
+
+   /* if this was a soft reset, then restart */
+   if ((le32_to_cpu(trb->generic.field[3])) & TRB_TSP)
+   ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
 }
 
 static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id,
@@ -2132,10 +2136,16 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, 
struct xhci_td *td,
union xhci_trb *ep_trb, struct xhci_transfer_event *event,
struct xhci_virt_ep *ep, int *status)
 {
+   struct xhci_slot_ctx *slot_ctx;
struct xhci_ring *ep_ring;
u32 trb_comp_code;
u32 remaining, requested, ep_trb_len;
+   unsigned int slot_id;
+   int ep_index;
 
+   slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags));
+   slot_ctx = xhci_get_slot_ctx(xhci, xhci->devs[slot_id]->out_ctx);
+   ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1;
ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer));
trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len));
remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
@@ -2144,6 +2154,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, 
struct xhci_td *td,
 
switch (trb_comp_code) {
case COMP_SUCCESS:
+   ep_ring->err_count = 0;
/* handle success with untransferred data as short packet */
if (ep_trb != td->last_trb || remaining) {
xhci_warn(xhci, "WARN Successful completion on short 
TX\n");
@@ -2167,6 +2178,14 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, 
struct xhci_td *td,
ep_trb_len  = 0;
remaining   = 0;
break;
+   case COMP_USB_TRANSACTION_ERROR:
+   if ((ep_ring->err_count++ > MAX_SOFT_RETRY) ||
+   le32_to_cpu(slot_ctx->tt_info) & TT_SLOT)
+   break;
+   *status = 0;
+   xhci_cleanup_halted_endpoint(xhci, slot_id, ep_index,
+   ep_ring->stream_id, td, EP_SOFT_RESET);
+   return 0;
default:
/* do nothing */
break;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 6230a57..b635785 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1496,6 +1496,7 @@ static inline const char *xhci_trb_type_string(u8 type)
 /* How much data is left before the 64KB boundary? */
 #define TRB_BUFF_LEN_UP_TO_BOUNDARY(addr)  (TRB_MAX_BUFF_SIZE - \
(addr & (TRB_MAX_BUFF_SIZE - 1)))
+#define MAX_SOFT_RETRY 3
 
 struct xhci_segment {
union xhci_trb  *trbs;
@@ -1583,6 +1584,7 @@ struct xhci_ring {
 * if we own the TRB (if we are the consumer).  See section 4.9.1.
 */
u32 cycle_state;
+   unsigned interr_count;
unsigned intstream_id;
unsigned intnum_segs;
unsigned intnum_trbs_free;
-- 
2.7.4



[PATCH v2 03/10] usb: xhci-mtk: improve bandwidth scheduling

2018-09-20 Thread Mathias Nyman
From: Chunfeng Yun 

Mainly improve SuperSpeed ISOC bandwidth in last microframe,
and LowSpeed/FullSpeed IN INT/ISOC bandwidth in split and
idle microframes by introduing a bandwidth budget table;

Signed-off-by: Chunfeng Yun 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-mtk-sch.c | 162 +---
 drivers/usb/host/xhci-mtk.h |   2 +
 2 files changed, 104 insertions(+), 60 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
index 057f453..7efd890 100644
--- a/drivers/usb/host/xhci-mtk-sch.c
+++ b/drivers/usb/host/xhci-mtk-sch.c
@@ -18,6 +18,11 @@
 #define HS_BW_BOUNDARY 6144
 /* usb2 spec section11.18.1: at most 188 FS bytes per microframe */
 #define FS_PAYLOAD_MAX 188
+/*
+ * max number of microframes for split transfer,
+ * for fs isoc in : 1 ss + 1 idle + 7 cs
+ */
+#define TT_MICROFRAMES_MAX 9
 
 /* mtk scheduler bitmasks */
 #define EP_BPKTS(p)((p) & 0x3f)
@@ -64,20 +69,57 @@ static int get_bw_index(struct xhci_hcd *xhci, struct 
usb_device *udev,
return bw_index;
 }
 
+static u32 get_esit(struct xhci_ep_ctx *ep_ctx)
+{
+   u32 esit;
+
+   esit = 1 << CTX_TO_EP_INTERVAL(le32_to_cpu(ep_ctx->ep_info));
+   if (esit > XHCI_MTK_MAX_ESIT)
+   esit = XHCI_MTK_MAX_ESIT;
+
+   return esit;
+}
+
+static struct mu3h_sch_ep_info *create_sch_ep(struct usb_device *udev,
+   struct usb_host_endpoint *ep, struct xhci_ep_ctx *ep_ctx)
+{
+   struct mu3h_sch_ep_info *sch_ep;
+   u32 len_bw_budget_table;
+   size_t mem_size;
+
+   if (is_fs_or_ls(udev->speed))
+   len_bw_budget_table = TT_MICROFRAMES_MAX;
+   else if ((udev->speed == USB_SPEED_SUPER)
+   && usb_endpoint_xfer_isoc(>desc))
+   len_bw_budget_table = get_esit(ep_ctx);
+   else
+   len_bw_budget_table = 1;
+
+   mem_size = sizeof(struct mu3h_sch_ep_info) +
+   len_bw_budget_table * sizeof(u32);
+   sch_ep = kzalloc(mem_size, GFP_KERNEL);
+   if (!sch_ep)
+   return ERR_PTR(-ENOMEM);
+
+   sch_ep->ep = ep;
+
+   return sch_ep;
+}
+
 static void setup_sch_info(struct usb_device *udev,
struct xhci_ep_ctx *ep_ctx, struct mu3h_sch_ep_info *sch_ep)
 {
u32 ep_type;
-   u32 ep_interval;
-   u32 max_packet_size;
+   u32 maxpkt;
u32 max_burst;
u32 mult;
u32 esit_pkts;
u32 max_esit_payload;
+   u32 *bwb_table = sch_ep->bw_budget_table;
+   int i;
 
ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2));
-   ep_interval = CTX_TO_EP_INTERVAL(le32_to_cpu(ep_ctx->ep_info));
-   max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2));
+   maxpkt = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2));
max_burst = CTX_TO_MAX_BURST(le32_to_cpu(ep_ctx->ep_info2));
mult = CTX_TO_EP_MULT(le32_to_cpu(ep_ctx->ep_info));
max_esit_payload =
@@ -85,9 +127,10 @@ static void setup_sch_info(struct usb_device *udev,
le32_to_cpu(ep_ctx->ep_info)) << 16) |
 CTX_TO_MAX_ESIT_PAYLOAD(le32_to_cpu(ep_ctx->tx_info));
 
-   sch_ep->esit = 1 << ep_interval;
+   sch_ep->esit = get_esit(ep_ctx);
sch_ep->offset = 0;
sch_ep->burst_mode = 0;
+   sch_ep->repeat = 0;
 
if (udev->speed == USB_SPEED_HIGH) {
sch_ep->cs_count = 0;
@@ -98,7 +141,6 @@ static void setup_sch_info(struct usb_device *udev,
 * in a interval
 */
sch_ep->num_budget_microframes = 1;
-   sch_ep->repeat = 0;
 
/*
 * xHCI spec section6.2.3.4
@@ -106,26 +148,30 @@ static void setup_sch_info(struct usb_device *udev,
 * opportunities per microframe
 */
sch_ep->pkts = max_burst + 1;
-   sch_ep->bw_cost_per_microframe = max_packet_size * sch_ep->pkts;
+   sch_ep->bw_cost_per_microframe = maxpkt * sch_ep->pkts;
+   bwb_table[0] = sch_ep->bw_cost_per_microframe;
} else if (udev->speed == USB_SPEED_SUPER) {
/* usb3_r1 spec section4.4.7 & 4.4.8 */
sch_ep->cs_count = 0;
+   sch_ep->burst_mode = 1;
/*
 * some device's (d)wBytesPerInterval is set as 0,
 * then max_esit_payload is 0, so evaluate esit_pkts from
 * mult and burst
 */
-   esit_pkts = DIV_ROUND_UP(max_esit_payload, max_packet_size);
+   esit_pkts = DIV_ROUND_UP(max_esit_payload, maxpkt);
if (esit_pkts == 0)
esit_pkts = (mult + 1) * (max_burst + 1);
 
if (ep_type == INT_IN_EP || ep_type == INT_OUT_EP) {
sch_ep->pkts = esit_pkts;
sch_ep->num_budget_microframes = 1;
-

[PATCH v2 00/10] xhci features for usb-next

2018-09-20 Thread Mathias Nyman
Hi Greg

Second try, shuffling patches.

A few new features for xhci, among others better transaction error
handling, default runtime PM allowing for Intel Alpine and Tiran Ridge
xhci controllers, and Mediatek isoc transfer related xhci improvements.

Changes since v1

- moved following patches from this series to for-usb-linus (4.19)
  usb: xhci-mtk: resume USB3 roothub first
  usb: typec: pci: Enable Intel USB role mux on Apollo Lake platforms

- added patches to this series from for-usb-linus queue:
  xhci: Avoid USB autosuspend when resuming USB2 ports.
  usb: xhci: tegra: Firmware header is little endian

-Mathias

Anshuman Gupta (1):
  xhci: Avoid USB autosuspend when resuming USB2 ports.

Chunfeng Yun (5):
  usb: xhci-mtk: use maximum ESIT payload of endpiont context
  usb: xhci-mtk: fix ISOC error when interval is zero
  usb: xhci-mtk: improve bandwidth scheduling
  usb: xhci-mtk: supports bandwidth scheduling with multi-TT
  usb: xhci-mtk: supports SSP without external USB3 gen2 hub

Mathias Nyman (2):
  xhci: Use soft retry to recover faster from transaction errors
  xhci-pci: allow host runtime PM as default for Intel Alpine and Titan
Ridge

Peter Chen (1):
  usb: host: xhci-plat: add platform TPL support

Thierry Reding (1):
  usb: xhci: tegra: Firmware header is little endian

 drivers/usb/host/xhci-hub.c |   5 +
 drivers/usb/host/xhci-mtk-sch.c | 429 +---
 drivers/usb/host/xhci-mtk.h |  23 +++
 drivers/usb/host/xhci-pci.c |  24 +++
 drivers/usb/host/xhci-plat.c|   3 +
 drivers/usb/host/xhci-ring.c|  20 ++
 drivers/usb/host/xhci-tegra.c   |  52 ++---
 drivers/usb/host/xhci.h |   3 +
 8 files changed, 463 insertions(+), 96 deletions(-)

-- 
2.7.4



[PATCH v2 09/10] usb: xhci: tegra: Firmware header is little endian

2018-09-20 Thread Mathias Nyman
From: Thierry Reding 

The XUSB firmware header is in little endian byte order, so make the
fields __le32 and __le16 instead of u32 and u16 to avoid warnings from
sparse when the fields are used with the endian-aware __le32_to_cpu()
and __le16_to_cpu() accessors, respectively.

Signed-off-by: Thierry Reding 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-tegra.c | 52 +--
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c
index 4b463e5..4ee510a 100644
--- a/drivers/usb/host/xhci-tegra.c
+++ b/drivers/usb/host/xhci-tegra.c
@@ -107,35 +107,35 @@
 #define IMEM_BLOCK_SIZE256
 
 struct tegra_xusb_fw_header {
-   u32 boot_loadaddr_in_imem;
-   u32 boot_codedfi_offset;
-   u32 boot_codetag;
-   u32 boot_codesize;
-   u32 phys_memaddr;
-   u16 reqphys_memsize;
-   u16 alloc_phys_memsize;
-   u32 rodata_img_offset;
-   u32 rodata_section_start;
-   u32 rodata_section_end;
-   u32 main_fnaddr;
-   u32 fwimg_cksum;
-   u32 fwimg_created_time;
-   u32 imem_resident_start;
-   u32 imem_resident_end;
-   u32 idirect_start;
-   u32 idirect_end;
-   u32 l2_imem_start;
-   u32 l2_imem_end;
-   u32 version_id;
+   __le32 boot_loadaddr_in_imem;
+   __le32 boot_codedfi_offset;
+   __le32 boot_codetag;
+   __le32 boot_codesize;
+   __le32 phys_memaddr;
+   __le16 reqphys_memsize;
+   __le16 alloc_phys_memsize;
+   __le32 rodata_img_offset;
+   __le32 rodata_section_start;
+   __le32 rodata_section_end;
+   __le32 main_fnaddr;
+   __le32 fwimg_cksum;
+   __le32 fwimg_created_time;
+   __le32 imem_resident_start;
+   __le32 imem_resident_end;
+   __le32 idirect_start;
+   __le32 idirect_end;
+   __le32 l2_imem_start;
+   __le32 l2_imem_end;
+   __le32 version_id;
u8 init_ddirect;
u8 reserved[3];
-   u32 phys_addr_log_buffer;
-   u32 total_log_entries;
-   u32 dequeue_ptr;
-   u32 dummy_var[2];
-   u32 fwimg_len;
+   __le32 phys_addr_log_buffer;
+   __le32 total_log_entries;
+   __le32 dequeue_ptr;
+   __le32 dummy_var[2];
+   __le32 fwimg_len;
u8 magic[8];
-   u32 ss_low_power_entry_timeout;
+   __le32 ss_low_power_entry_timeout;
u8 num_hsic_port;
u8 padding[139]; /* Pad to 256 bytes */
 };
-- 
2.7.4



[PATCH v2 01/10] usb: xhci-mtk: use maximum ESIT payload of endpiont context

2018-09-20 Thread Mathias Nyman
From: Chunfeng Yun 

Make use of maximum ESIT payload of endpoint context to calculate
the number of packets to send in each ESIT

Signed-off-by: Chunfeng Yun 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-mtk-sch.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
index fa33d6e..46fe0a2 100644
--- a/drivers/usb/host/xhci-mtk-sch.c
+++ b/drivers/usb/host/xhci-mtk-sch.c
@@ -73,12 +73,17 @@ static void setup_sch_info(struct usb_device *udev,
u32 max_burst;
u32 mult;
u32 esit_pkts;
+   u32 max_esit_payload;
 
ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2));
ep_interval = CTX_TO_EP_INTERVAL(le32_to_cpu(ep_ctx->ep_info));
max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2));
max_burst = CTX_TO_MAX_BURST(le32_to_cpu(ep_ctx->ep_info2));
mult = CTX_TO_EP_MULT(le32_to_cpu(ep_ctx->ep_info));
+   max_esit_payload =
+   (CTX_TO_MAX_ESIT_PAYLOAD_HI(
+   le32_to_cpu(ep_ctx->ep_info)) << 16) |
+CTX_TO_MAX_ESIT_PAYLOAD(le32_to_cpu(ep_ctx->tx_info));
 
sch_ep->esit = 1 << ep_interval;
sch_ep->offset = 0;
@@ -105,7 +110,15 @@ static void setup_sch_info(struct usb_device *udev,
} else if (udev->speed == USB_SPEED_SUPER) {
/* usb3_r1 spec section4.4.7 & 4.4.8 */
sch_ep->cs_count = 0;
-   esit_pkts = (mult + 1) * (max_burst + 1);
+   /*
+* some device's (d)wBytesPerInterval is set as 0,
+* then max_esit_payload is 0, so evaluate esit_pkts from
+* mult and burst
+*/
+   esit_pkts = DIV_ROUND_UP(max_esit_payload, max_packet_size);
+   if (esit_pkts == 0)
+   esit_pkts = (mult + 1) * (max_burst + 1);
+
if (ep_type == INT_IN_EP || ep_type == INT_OUT_EP) {
sch_ep->pkts = esit_pkts;
sch_ep->num_budget_microframes = 1;
-- 
2.7.4



[PATCH v2 10/10] xhci: Avoid USB autosuspend when resuming USB2 ports.

2018-09-20 Thread Mathias Nyman
From: Anshuman Gupta 

When USB bus host controller root hub resumes from autosuspend,
it immediately tries to enter auto-suspend, but there can be a
scenario when root hub is resuming its usb2 ports, in that particular
case USB host controller auto suspend fails since it is busy
to resuming its usb2 ports.

This makes multiple failed cycles of auto-suspend until all usb2
ports of host controller root hub do not resume.

This patch uses USB core framework usb_hcd_start_port_resume,
usb_hcd_end_port_resume API's in order to  autoresume/autosuspend
root hub properly.

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

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 7e2a531..12eea73 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -900,6 +900,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
set_bit(wIndex, _state->resuming_ports);
bus_state->resume_done[wIndex] = timeout;
mod_timer(>rh_timer, timeout);
+   usb_hcd_start_port_resume(>self, wIndex);
}
/* Has resume been signalled for USB_RESUME_TIME yet? */
} else if (time_after_eq(jiffies,
@@ -940,6 +941,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
clear_bit(wIndex, _state->rexit_ports);
}
 
+   usb_hcd_end_port_resume(>self, wIndex);
bus_state->port_c_suspend |= 1 << wIndex;
bus_state->suspended_ports &= ~(1 << wIndex);
} else {
@@ -962,6 +964,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
(raw_port_status & PORT_PLS_MASK) != XDEV_RESUME) {
bus_state->resume_done[wIndex] = 0;
clear_bit(wIndex, _state->resuming_ports);
+   usb_hcd_end_port_resume(>self, wIndex);
}
 
 
@@ -1337,6 +1340,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, 
u16 wValue,
goto error;
 
set_bit(wIndex, _state->resuming_ports);
+   usb_hcd_start_port_resume(>self, wIndex);
xhci_set_link_state(xhci, ports[wIndex],
XDEV_RESUME);
spin_unlock_irqrestore(>lock, flags);
@@ -1345,6 +1349,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, 
u16 wValue,
xhci_set_link_state(xhci, ports[wIndex],
XDEV_U0);
clear_bit(wIndex, _state->resuming_ports);
+   usb_hcd_end_port_resume(>self, wIndex);
}
bus_state->port_c_suspend |= 1 << wIndex;
 
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index c41341e..a8d92c9 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1606,6 +1606,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
set_bit(HCD_FLAG_POLL_RH, >flags);
mod_timer(>rh_timer,
  bus_state->resume_done[hcd_portnum]);
+   usb_hcd_start_port_resume(>self, hcd_portnum);
bogus_port_status = true;
}
}
-- 
2.7.4



[PATCH v2 08/10] xhci-pci: allow host runtime PM as default for Intel Alpine and Titan Ridge

2018-09-20 Thread Mathias Nyman
The xhci controller on Alpine and Titan Ridge keeps the whole thunderbolt
awake if the host controller is not allowed tp sleep.
This is the case even if no USB devices are connected to the host.

Because of this bigger impact, allow runtime pm as default for these xhci
controllers in the driver.

Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-pci.c | 24 
 drivers/usb/host/xhci.h |  1 +
 2 files changed, 25 insertions(+)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 6372edf..9433e70 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -41,6 +41,13 @@
 #define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI 0x1aa8
 #define PCI_DEVICE_ID_INTEL_APL_XHCI   0x5aa8
 #define PCI_DEVICE_ID_INTEL_DNV_XHCI   0x19d0
+#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI   0x15b5
+#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI   0x15b6
+#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI 0x15db
+#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI 0x15d4
+#define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI0x15e9
+#define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI0x15ec
+#define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI0x15f0
 
 #define PCI_DEVICE_ID_AMD_PROMONTORYA_40x43b9
 #define PCI_DEVICE_ID_AMD_PROMONTORYA_30x43ba
@@ -189,6 +196,16 @@ static void xhci_pci_quirks(struct device *dev, struct 
xhci_hcd *xhci)
 pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI))
xhci->quirks |= XHCI_MISSING_CAS;
 
+   if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+   (pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI ||
+pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI ||
+pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI ||
+pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI ||
+pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI ||
+pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI ||
+pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI))
+   xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
+
if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
pdev->device == PCI_DEVICE_ID_EJ168) {
xhci->quirks |= XHCI_RESET_ON_RESUME;
@@ -332,6 +349,9 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct 
pci_device_id *id)
/* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */
pm_runtime_put_noidle(>dev);
 
+   if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
+   pm_runtime_allow(>dev);
+
return 0;
 
 put_usb3_hcd:
@@ -349,6 +369,10 @@ static void xhci_pci_remove(struct pci_dev *dev)
 
xhci = hcd_to_xhci(pci_get_drvdata(dev));
xhci->xhc_state |= XHCI_STATE_REMOVING;
+
+   if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
+   pm_runtime_forbid(>dev);
+
if (xhci->shared_hcd) {
usb_remove_hcd(xhci->shared_hcd);
usb_put_hcd(xhci->shared_hcd);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index b635785..bf0b369 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1848,6 +1848,7 @@ struct xhci_hcd {
 #define XHCI_SUSPEND_DELAY BIT_ULL(30)
 #define XHCI_INTEL_USB_ROLE_SW BIT_ULL(31)
 #define XHCI_ZERO_64B_REGS BIT_ULL(32)
+#define XHCI_DEFAULT_PM_RUNTIME_ALLOW  BIT_ULL(33)
 
unsigned intnum_active_eps;
unsigned intlimit_active_eps;
-- 
2.7.4



[PATCH v2 02/10] usb: xhci-mtk: fix ISOC error when interval is zero

2018-09-20 Thread Mathias Nyman
From: Chunfeng Yun 

If the interval equal zero, needn't round up to power of two
for the number of packets in each ESIT, so fix it.

Signed-off-by: Chunfeng Yun 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-mtk-sch.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
index 46fe0a2..057f453 100644
--- a/drivers/usb/host/xhci-mtk-sch.c
+++ b/drivers/usb/host/xhci-mtk-sch.c
@@ -126,7 +126,9 @@ static void setup_sch_info(struct usb_device *udev,
}
 
if (ep_type == ISOC_IN_EP || ep_type == ISOC_OUT_EP) {
-   if (esit_pkts <= sch_ep->esit)
+   if (sch_ep->esit == 1)
+   sch_ep->pkts = esit_pkts;
+   else if (esit_pkts <= sch_ep->esit)
sch_ep->pkts = 1;
else
sch_ep->pkts = roundup_pow_of_two(esit_pkts)
-- 
2.7.4



[PATCH v2 06/10] usb: host: xhci-plat: add platform TPL support

2018-09-20 Thread Mathias Nyman
From: Peter Chen 

The TPL support is used to identify targeted devices during
EH2.0 and EH3.0 certification test, the user can add "tpl-support"
at dts to enable this feature.

Signed-off-by: Peter Chen 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-plat.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 94e9392..32b5574 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "xhci.h"
 #include "xhci-plat.h"
@@ -305,6 +306,8 @@ static int xhci_plat_probe(struct platform_device *pdev)
hcd->skip_phy_initialization = 1;
}
 
+   hcd->tpl_support = of_usb_host_tpl_support(sysdev->of_node);
+   xhci->shared_hcd->tpl_support = hcd->tpl_support;
ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
if (ret)
goto disable_usb_phy;
-- 
2.7.4



[PATCH v2 04/10] usb: xhci-mtk: supports bandwidth scheduling with multi-TT

2018-09-20 Thread Mathias Nyman
From: Chunfeng Yun 

Supports LowSpeed and FullSpeed INT/ISOC bandwidth scheduling
with USB multi-TT

Signed-off-by: Chunfeng Yun 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-mtk-sch.c | 247 ++--
 drivers/usb/host/xhci-mtk.h |  21 
 2 files changed, 258 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
index 7efd890..36050a1 100644
--- a/drivers/usb/host/xhci-mtk-sch.c
+++ b/drivers/usb/host/xhci-mtk-sch.c
@@ -80,10 +80,98 @@ static u32 get_esit(struct xhci_ep_ctx *ep_ctx)
return esit;
 }
 
+static struct mu3h_sch_tt *find_tt(struct usb_device *udev)
+{
+   struct usb_tt *utt = udev->tt;
+   struct mu3h_sch_tt *tt, **tt_index, **ptt;
+   unsigned int port;
+   bool allocated_index = false;
+
+   if (!utt)
+   return NULL;/* Not below a TT */
+
+   /*
+* Find/create our data structure.
+* For hubs with a single TT, we get it directly.
+* For hubs with multiple TTs, there's an extra level of pointers.
+*/
+   tt_index = NULL;
+   if (utt->multi) {
+   tt_index = utt->hcpriv;
+   if (!tt_index) {/* Create the index array */
+   tt_index = kcalloc(utt->hub->maxchild,
+   sizeof(*tt_index), GFP_KERNEL);
+   if (!tt_index)
+   return ERR_PTR(-ENOMEM);
+   utt->hcpriv = tt_index;
+   allocated_index = true;
+   }
+   port = udev->ttport - 1;
+   ptt = _index[port];
+   } else {
+   port = 0;
+   ptt = (struct mu3h_sch_tt **) >hcpriv;
+   }
+
+   tt = *ptt;
+   if (!tt) {  /* Create the mu3h_sch_tt */
+   tt = kzalloc(sizeof(*tt), GFP_KERNEL);
+   if (!tt) {
+   if (allocated_index) {
+   utt->hcpriv = NULL;
+   kfree(tt_index);
+   }
+   return ERR_PTR(-ENOMEM);
+   }
+   INIT_LIST_HEAD(>ep_list);
+   tt->usb_tt = utt;
+   tt->tt_port = port;
+   *ptt = tt;
+   }
+
+   return tt;
+}
+
+/* Release the TT above udev, if it's not in use */
+static void drop_tt(struct usb_device *udev)
+{
+   struct usb_tt *utt = udev->tt;
+   struct mu3h_sch_tt *tt, **tt_index, **ptt;
+   int i, cnt;
+
+   if (!utt || !utt->hcpriv)
+   return; /* Not below a TT, or never allocated */
+
+   cnt = 0;
+   if (utt->multi) {
+   tt_index = utt->hcpriv;
+   ptt = _index[udev->ttport - 1];
+   /*  How many entries are left in tt_index? */
+   for (i = 0; i < utt->hub->maxchild; ++i)
+   cnt += !!tt_index[i];
+   } else {
+   tt_index = NULL;
+   ptt = (struct mu3h_sch_tt **)>hcpriv;
+   }
+
+   tt = *ptt;
+   if (!tt || !list_empty(>ep_list))
+   return; /* never allocated , or still in use*/
+
+   *ptt = NULL;
+   kfree(tt);
+
+   if (cnt == 1) {
+   utt->hcpriv = NULL;
+   kfree(tt_index);
+   }
+}
+
 static struct mu3h_sch_ep_info *create_sch_ep(struct usb_device *udev,
struct usb_host_endpoint *ep, struct xhci_ep_ctx *ep_ctx)
 {
struct mu3h_sch_ep_info *sch_ep;
+   struct mu3h_sch_tt *tt = NULL;
u32 len_bw_budget_table;
size_t mem_size;
 
@@ -101,6 +189,15 @@ static struct mu3h_sch_ep_info *create_sch_ep(struct 
usb_device *udev,
if (!sch_ep)
return ERR_PTR(-ENOMEM);
 
+   if (is_fs_or_ls(udev->speed)) {
+   tt = find_tt(udev);
+   if (IS_ERR(tt)) {
+   kfree(sch_ep);
+   return ERR_PTR(-ENOMEM);
+   }
+   }
+
+   sch_ep->sch_tt = tt;
sch_ep->ep = ep;
 
return sch_ep;
@@ -128,6 +225,8 @@ static void setup_sch_info(struct usb_device *udev,
 CTX_TO_MAX_ESIT_PAYLOAD(le32_to_cpu(ep_ctx->tx_info));
 
sch_ep->esit = get_esit(ep_ctx);
+   sch_ep->ep_type = ep_type;
+   sch_ep->maxpkt = maxpkt;
sch_ep->offset = 0;
sch_ep->burst_mode = 0;
sch_ep->repeat = 0;
@@ -197,8 +296,13 @@ static void setup_sch_info(struct usb_device *udev,
}
} else if (is_fs_or_ls(udev->speed)) {
sch_ep->pkts = 1; /* at most one packet for each microframe */
+
+   /*
+* num_budget_microframes and cs_count will be updated when
+* check TT for INT_OUT_EP, ISOC/INT_IN_EP type
+*/
sch_ep->cs_count = DIV_ROUND_UP(maxpkt, FS_PAYLOAD_MAX);
-   

[PATCH v2 05/10] usb: xhci-mtk: supports SSP without external USB3 gen2 hub

2018-09-20 Thread Mathias Nyman
From: Chunfeng Yun 

Supports SSP scheduling only for SSP device directly connected
to root hub but not through external USB3 gen2 hub which need
use a new scheduling way.

Signed-off-by: Chunfeng Yun 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-mtk-sch.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
index 36050a1..fea 100644
--- a/drivers/usb/host/xhci-mtk-sch.c
+++ b/drivers/usb/host/xhci-mtk-sch.c
@@ -13,6 +13,7 @@
 #include "xhci.h"
 #include "xhci-mtk.h"
 
+#define SSP_BW_BOUNDARY13
 #define SS_BW_BOUNDARY 51000
 /* table 5-5. High-speed Isoc Transaction Limits in usb_20 spec */
 #define HS_BW_BOUNDARY 6144
@@ -25,7 +26,7 @@
 #define TT_MICROFRAMES_MAX 9
 
 /* mtk scheduler bitmasks */
-#define EP_BPKTS(p)((p) & 0x3f)
+#define EP_BPKTS(p)((p) & 0x7f)
 #define EP_BCSCOUNT(p) (((p) & 0x7) << 8)
 #define EP_BBM(p)  ((p) << 11)
 #define EP_BOFFSET(p)  ((p) & 0x3fff)
@@ -56,7 +57,7 @@ static int get_bw_index(struct xhci_hcd *xhci, struct 
usb_device *udev,
 
virt_dev = xhci->devs[udev->slot_id];
 
-   if (udev->speed == USB_SPEED_SUPER) {
+   if (udev->speed >= USB_SPEED_SUPER) {
if (usb_endpoint_dir_out(>desc))
bw_index = (virt_dev->real_port - 1) * 2;
else
@@ -177,7 +178,7 @@ static struct mu3h_sch_ep_info *create_sch_ep(struct 
usb_device *udev,
 
if (is_fs_or_ls(udev->speed))
len_bw_budget_table = TT_MICROFRAMES_MAX;
-   else if ((udev->speed == USB_SPEED_SUPER)
+   else if ((udev->speed >= USB_SPEED_SUPER)
&& usb_endpoint_xfer_isoc(>desc))
len_bw_budget_table = get_esit(ep_ctx);
else
@@ -249,7 +250,7 @@ static void setup_sch_info(struct usb_device *udev,
sch_ep->pkts = max_burst + 1;
sch_ep->bw_cost_per_microframe = maxpkt * sch_ep->pkts;
bwb_table[0] = sch_ep->bw_cost_per_microframe;
-   } else if (udev->speed == USB_SPEED_SUPER) {
+   } else if (udev->speed >= USB_SPEED_SUPER) {
/* usb3_r1 spec section4.4.7 & 4.4.8 */
sch_ep->cs_count = 0;
sch_ep->burst_mode = 1;
@@ -511,8 +512,12 @@ static int check_sch_bw(struct usb_device *udev,
break;
}
 
-   bw_boundary = (udev->speed == USB_SPEED_SUPER)
-   ? SS_BW_BOUNDARY : HS_BW_BOUNDARY;
+   if (udev->speed == USB_SPEED_SUPER_PLUS)
+   bw_boundary = SSP_BW_BOUNDARY;
+   else if (udev->speed == USB_SPEED_SUPER)
+   bw_boundary = SS_BW_BOUNDARY;
+   else
+   bw_boundary = HS_BW_BOUNDARY;
 
/* check bandwidth */
if (min_bw > bw_boundary)
-- 
2.7.4



some question about ehci-sched.c

2018-09-20 Thread yoma sophian
hi all:
in iso_stream_schedule of ehci-sched.c, why we have to add the "-" in
(-(++ehci->random_frame))  to calculate the start uframe?
thanks for ur help in advance.

if (stream->ps.phase == NO_FRAME) {
int done = 0;
struct ehci_tt  *tt = find_tt(stream->ps.udev);

if (IS_ERR(tt)) {
status = PTR_ERR(tt);
goto fail;
}
compute_tt_budget(ehci->tt_budget, tt);

start = ((-(++ehci->random_frame)) << 3) & (period - 1);
  ^^ Here it is.


[PATCH v2 3/3] usb: typec: pci: Enable Intel USB role mux on Apollo Lake platforms

2018-09-20 Thread Mathias Nyman
From: Heikki Krogerus 

Intel Apollo Lake has the same internal USB role mux as
Intel Cherry Trail.

Cc: 
Signed-off-by: Heikki Krogerus 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-pci.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 722860e..51dd8e0 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -179,10 +179,12 @@ static void xhci_pci_quirks(struct device *dev, struct 
xhci_hcd *xhci)
xhci->quirks |= XHCI_PME_STUCK_QUIRK;
}
if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
-pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI) {
+   pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI)
xhci->quirks |= XHCI_SSIC_PORT_UNUSED;
+   if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+   (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
+pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI))
xhci->quirks |= XHCI_INTEL_USB_ROLE_SW;
-   }
if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
(pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
-- 
2.7.4



[PATCH v2 0/3] xhci fixes for usb-linus

2018-09-20 Thread Mathias Nyman
Hi Greg

Second try, shuffling patches between for-usb-linus and for-usb-next

A few patches that makes sure USB3 devices enumerate to correct speed
after resume on Mediatek hosts, enables role mux on Apollo lake platforms,
and adds the missing cold attach status (CAS) bit quirk to Intel Sunrise
Point xhci controllers.

Changes since v1

- Moved following patches from this series to for-usb-next (4.20)
  xhci: Avoid USB autosuspend when resuming USB2 ports.
  usb: xhci: tegra: Firmware header is little endian

- Added patches to this series from for-usb-next queue:
  usb: xhci-mtk: resume USB3 roothub first
  usb: typec: pci: Enable Intel USB role mux on Apollo Lake platforms

- Added stable tags

Chunfeng Yun (1):
  usb: xhci-mtk: resume USB3 roothub first

Heikki Krogerus (1):
  usb: typec: pci: Enable Intel USB role mux on Apollo Lake platforms

Mathias Nyman (1):
  xhci: Add missing CAS workaround for Intel Sunrise Point xHCI

 drivers/usb/host/xhci-mtk.c | 4 ++--
 drivers/usb/host/xhci-pci.c | 8 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

-- 
2.7.4



[PATCH v2 2/3] usb: xhci-mtk: resume USB3 roothub first

2018-09-20 Thread Mathias Nyman
From: Chunfeng Yun 

Give USB3 devices a better chance to enumerate at USB3 speeds if
they are connected to a suspended host.
Porting from "671ffdff5b13 xhci: resume USB 3 roothub first"

Cc: 
Signed-off-by: Chunfeng Yun 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-mtk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 7334da9..71d0d33 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -642,10 +642,10 @@ static int __maybe_unused xhci_mtk_resume(struct device 
*dev)
xhci_mtk_host_enable(mtk);
 
xhci_dbg(xhci, "%s: restart port polling\n", __func__);
-   set_bit(HCD_FLAG_POLL_RH, >flags);
-   usb_hcd_poll_rh_status(hcd);
set_bit(HCD_FLAG_POLL_RH, >shared_hcd->flags);
usb_hcd_poll_rh_status(xhci->shared_hcd);
+   set_bit(HCD_FLAG_POLL_RH, >flags);
+   usb_hcd_poll_rh_status(hcd);
return 0;
 }
 
-- 
2.7.4



[PATCH v2 1/3] xhci: Add missing CAS workaround for Intel Sunrise Point xHCI

2018-09-20 Thread Mathias Nyman
The workaround for missing CAS bit is also needed for xHC on Intel
sunrisepoint PCH. For more details see:

Intel 100/c230 series PCH specification update Doc #332692-006 Errata #8

Cc: 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-pci.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 6372edf..722860e 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -185,6 +185,8 @@ static void xhci_pci_quirks(struct device *dev, struct 
xhci_hcd *xhci)
}
if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
(pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
+pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
+pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
 pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI ||
 pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI))
xhci->quirks |= XHCI_MISSING_CAS;
-- 
2.7.4



Re: Kernel memory leak on CDC-ACM device plug/unplug

2018-09-20 Thread Romain Izard
2018-09-19 22:32 GMT+02:00 Greg KH :
> On Wed, Sep 19, 2018 at 04:11:55PM +0200, Romain Izard wrote:
>> While trying to debug a memory leak problem, I encountered the following
>> problem:
>>
>> After plugging/unplugging an USB CDC-ACM device, kmemleak reports multiple
>> copies of the following leak. It is not necessary to open the port for the
>> leak to happen.
>>
>> unreferenced object 0xddbfd500 (size 128):
>>   comm "kworker/0:3", pid 675, jiffies 69734 (age 916.580s)
>>   hex dump (first 32 bytes):
>> 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
>> 00 00 00 00 00 00 00 00 00 00 00 00 1c d5 bf dd  
>>   backtrace:
>> [] acm_probe+0x868/0xc3c
>> [] usb_probe_interface+0x11c/0x274
>> [] driver_probe_device+0x22c/0x320
>> [<544a5b43>] bus_for_each_drv+0x58/0xb8
>> [] __device_attach+0xd0/0x138
>> [] bus_probe_device+0x84/0x8c
>> [<16645f2c>] device_add+0x3cc/0x5c0
>> [<80c11c88>] usb_set_configuration+0x448/0x7b0
>> [<76bdbcdf>] generic_probe+0x2c/0x78
>> [] driver_probe_device+0x22c/0x320
>> [<544a5b43>] bus_for_each_drv+0x58/0xb8
>> [] __device_attach+0xd0/0x138
>> [] bus_probe_device+0x84/0x8c
>> [<16645f2c>] device_add+0x3cc/0x5c0
>> [<02a49898>] usb_new_device+0x264/0x424
>> [<865a481b>] hub_event+0xa20/0x1154
>>
>> For each additional plug/unplug cycle, around 30 such new leaks are created.
>>
>> Tested on a SAMA5D2 Xplained demo board, with a v4.18.8 kernel.
>> The CDC-ACM device was another SAMA5D2 device, with a composite profile
>> including a CDC-ACM port implemented with configfs.
>
> Have you come up with any patches that might resolve this?  It's hard to
> see what exactly is "leaking" here.
>

I finally found that Linux v4.9 was not affected.
git-bisect gives the following output:

ba8c931ded8d96c8923662099416bc2096644eab is the first bad commit
commit ba8c931ded8d96c8923662099416bc2096644eab
Author: Ladislav Michl 
Date:   Fri Nov 18 19:07:08 2016 +0100

cdc-acm: refactor killing urbs

Move urb killing code into separate function and use it
instead of copying that code pattern over.

Signed-off-by: Ladislav Michl 
Acked-by: Oliver Neukum 
Signed-off-by: Greg Kroah-Hartman 

:04 04 bb64a6003aa575fb459cd64cb63ff0189134db8f
68ad7dc597533eaff2d33c9ac2b23d49906f6551 M  drivers

I found a bug in that commit, I'm sending a fix for it.

Best regards
-- 
Romain Izard


Re: [PATCH] usb: dwc2: Fix HiKey regression caused by power_down feature

2018-09-20 Thread Artur Petrosyan
Hi John,

On 5/23/2018 01:57, John Stultz wrote:
> On Tue, May 22, 2018 at 7:24 AM, Minas Harutyunyan
>  wrote:
>> Hi John,
>>
>> Please provide log with debug enabled configuration.
> 
> Ok. Attached.
> For dmesg-broken.log:  OTG removed at 77, and OTG plugged in at 82
> For dmesg-with-patch.log: OTG removed at 31, OTG plugged in at 38.
> 
> Note with the dmesg-with-patch (using my patch), things seem to be
> working ok. Though in the example above it may look odd, as usually it
> switches to to host mode, then when it detects a low speed device (a
> mouse which I had plugged in), it will reset to switch to low-speed,
> but I didn't wait long enough for the reset to complete and the mouse
> to be detected before re-plugging in the OTG port.
> 
>> On 5/21/2018 11:41 PM, John Stultz wrote:
>>> On Mon, May 21, 2018 at 1:45 AM, Minas Harutyunyan
>>>  wrote:
 Hi John,

 On 5/19/2018 4:49 AM, John Stultz wrote:
> In 4.17-rc, commit 03ea6d6e9e1f ("usb: dwc2: Enable power down")
> caused the HiKey board to not correctly handle switching between
> usb-gadget and usb-host mode.
>
> Unplugging the OTG port would result in:
>> OTG port you mean MicroAB, Correct?
> 
> Correct.
> 
>> dwc2 driver loaded when some device connected to OTG port?
> 
> Yes, I normally boot with the board plugged in to OTG as a
> peripheral/gadget for adb.
> 
>> And below message printed after disconnect the device from OTG port?
>>
> [   42.240973] dwc2 f72c.usb: dwc2_restore_host_registers: no host 
> registers to restore
> [   42.249066] dwc2 f72c.usb: dwc2_host_exit_hibernation: failed to 
> restore host registers
> 
> Correct.
> 
> And the USB-host ports would not function.
>> USB-host ports - you mean 2 USB A-ports, connected to TS3USB221 HUB?
> 
> Correct.
> 
>> Switching ports between OTG and Host ports via TS3USB221 Switch
>> performing automatically or by some SW tool?
> 
> Its done automatically, when the OTG cable is detected it the host
> ports are disabled and when the OTG port is empty the host ports are
> enabled.
> 
> Let me know if you need anything else!
> 
> thanks
> -john
> 

Please apply the patch set with this cover letter "[PATCH 0/3] usb: 
dwc2: Fix hibernation for switching between host and device modes."

Enable the power down on his devices. Let me know if you still see any 
issue. If there is no issue, please provide Tested-by tag.


Regards,
Artur


Set reference clock for onboard hub in DT

2018-09-20 Thread Frieder Schrempf

Hi,

I have a question concerning the setup for a board with an onboard USB 
hub. The SoC (i.MX6S) is expected to provide a 12 MHz clock on one of 
the clock output pins as a reference for the USB hub.


Now I was looking for a way to configure this in the DT, which works 
fine up to the point, that there doesn't seem to be a way to set a 
reference clock for a generic USB device.


Would it make sense to implement the enabling/disabling of the clock in 
the generic USB device driver?
It doesn't seem right to write a separate driver for the hub only to 
turn the clock on and off.


My intended DT setup would look something like this:

 {
vbus-supply = <_usb_h1_vbus>;
pinctrl-names = "default";
pinctrl-0 = <_usbh1>;
dr_mode = "host";
status = "okay";
#address-cells = <1>;
#size-cells = <0>;

hub@1 {
compatible = "usb4b4,6570";
reg = <1>;
clocks = < IMX6QDL_CLK_CKO>;
assigned-clocks = < IMX6QDL_CLK_CKO>,
  < IMX6QDL_CLK_CKO2_SEL>,
  < IMX6QDL_CLK_CKO2>;
assigned-clock-parents = < IMX6QDL_CLK_CKO2>,
 < IMX6QDL_CLK_OSC>,
 < IMX6QDL_CLK_CKO2_PODF>;
assigned-clock-rates = <0 0 1200>;
}
};

Thanks,
Frieder


[PATCH 1/3] usb: dwc2: Add default param to control power optimization.

2018-09-20 Thread Artur Petrosyan
- Added a default param "power_saving" to enable or
  disable hibernation or partial power down features.

- Printed hibernation param in hw_params_show and
  power_saving param in params_show.

Signed-off-by: Artur Petrosyan 
Signed-off-by: Minas Harutyunyan 
---
 drivers/usb/dwc2/core.h|  3 +++
 drivers/usb/dwc2/debugfs.c |  2 ++
 drivers/usb/dwc2/params.c  | 19 +--
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index cc9c93affa14..2cf5e128cb75 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -373,6 +373,8 @@ enum dwc2_ep0_state {
  *  case.
  *  0 - No (default)
  *  1 - Yes
+ * @power_saving:  Specifies if power saving is enabled or not. If it is
+ * enabled power_down functionality will be enabled.
  * @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
@@ -452,6 +454,7 @@ struct dwc2_core_params {
bool uframe_sched;
bool external_id_pin_ctl;
 
+   unsigned int power_saving:1;
int power_down;
 #define DWC2_POWER_DOWN_PARAM_NONE 0
 #define DWC2_POWER_DOWN_PARAM_PARTIAL  1
diff --git a/drivers/usb/dwc2/debugfs.c b/drivers/usb/dwc2/debugfs.c
index 22d015b0424f..9f663d42dfe8 100644
--- a/drivers/usb/dwc2/debugfs.c
+++ b/drivers/usb/dwc2/debugfs.c
@@ -695,6 +695,7 @@ static int params_show(struct seq_file *seq, void *v)
print_param_hex(seq, p, ahbcfg);
print_param(seq, p, uframe_sched);
print_param(seq, p, external_id_pin_ctl);
+   print_param(seq, p, power_saving);
print_param(seq, p, power_down);
print_param(seq, p, lpm);
print_param(seq, p, lpm_clock_gating);
@@ -745,6 +746,7 @@ static int hw_params_show(struct seq_file *seq, void *v)
print_param(seq, hw, num_dev_perio_in_ep);
print_param(seq, hw, total_fifo_size);
print_param(seq, hw, power_optimized);
+   print_param(seq, hw, hibernation);
print_param(seq, hw, utmi_phy_data_width);
print_param_hex(seq, hw, snpsid);
print_param_hex(seq, hw, dev_ep_dirs);
diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index bf7052e037d6..f51b3659511b 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -253,12 +253,18 @@ 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;
+   if (!hsotg->params.power_saving) {
+   val = DWC2_POWER_DOWN_PARAM_NONE;
+   dev_dbg(hsotg->dev, "%s: Power saving is disabled.\n",
+   __func__);
+   } else {
+   if (hsotg->hw_params.hibernation)
+   val = DWC2_POWER_DOWN_PARAM_HIBERNATION;
+   else if (hsotg->hw_params.power_optimized)
+   val = DWC2_POWER_DOWN_PARAM_PARTIAL;
+   else
+   val = DWC2_POWER_DOWN_PARAM_NONE;
+   }
 
hsotg->params.power_down = val;
 }
@@ -280,6 +286,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);
+   p->power_saving = true;
dwc2_set_param_power_down(hsotg);
p->phy_ulpi_ddr = false;
p->phy_ulpi_ext_vbus = false;
-- 
2.11.0



[PATCH 2/3] usb: dwc2: Update dwc2_handle_usb_suspend_intr function.

2018-09-20 Thread Artur Petrosyan
To avoid working in two modes (partial power down
and hibernation) changed conditions for entering
partial power down or hibernation.

Instead of checking hw_params.power_optimized and
hw_params.hibernation now checking power_down
param which already set to one of the options
(Hibernation or Partial Power Down) based on
OTG_EN_PWROPT.

Signed-off-by: Artur Petrosyan 
Signed-off-by: Minas Harutyunyan 
---
 drivers/usb/dwc2/core_intr.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index 19ae2595f1c3..3602aca3316b 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -498,14 +498,15 @@ static void dwc2_handle_usb_suspend_intr(struct 
dwc2_hsotg *hsotg)
return;
}
if (dsts & DSTS_SUSPSTS) {
-   if (hsotg->hw_params.power_optimized) {
+   switch (hsotg->params.power_down) {
+   case DWC2_POWER_DOWN_PARAM_PARTIAL:
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;
+   break;
}
 
udelay(100);
@@ -513,16 +514,16 @@ static void dwc2_handle_usb_suspend_intr(struct 
dwc2_hsotg *hsotg)
/* Ask phy to be suspended */
if (!IS_ERR_OR_NULL(hsotg->uphy))
usb_phy_set_suspend(hsotg->uphy, true);
-   }
-
-   if (hsotg->hw_params.hibernation) {
+   break;
+   case DWC2_POWER_DOWN_PARAM_HIBERNATION:
ret = dwc2_enter_hibernation(hsotg, 0);
if (ret && ret != -ENOTSUPP)
dev_err(hsotg->dev,
"%s: enter hibernation 
failed\n",
__func__);
+   break;
}
-skip_power_saving:
+
/*
 * Change to L2 (suspend) state before releasing
 * spinlock
-- 
2.11.0



[PATCH 0/3] usb: dwc2: Fix hibernation for switching between host and device modes.

2018-09-20 Thread Artur Petrosyan
This patch set, fixes and improves hibernation flow. Mainly, fixes
hibernation for switching between host and device modes.

Adds enabling/disabling of power optimization parameter.


Artur Petrosyan (3):
  usb: dwc2: Add default param to control power optimization.
  usb: dwc2: Update dwc2_handle_usb_suspend_intr function.
  usb: dwc2: Fix hibernation between host and device modes.

 drivers/usb/dwc2/core.h  |  3 +++
 drivers/usb/dwc2/core_intr.c | 32 
 drivers/usb/dwc2/debugfs.c   |  2 ++
 drivers/usb/dwc2/hcd.c   |  3 +++
 drivers/usb/dwc2/params.c| 19 +--
 5 files changed, 37 insertions(+), 22 deletions(-)

-- 
2.11.0



[PATCH 3/3] usb: dwc2: Fix hibernation between host and device modes.

2018-09-20 Thread Artur Petrosyan
- After entering hibernation both in host and
  device modes saved GPWRDN register.

- In handling status change interrupt checking if
  current mode differs from the mode when entered
  hibernation.
  In case when mode is not changed, exiting device
  hibernation without remote wake up.
  On the other hand, if there is device hibernation
  and changed to host, then exiting hibernation
  for device mode with remote wake up.

- Removed workaround for ignore suspend interrupt before
  enumeration.

Signed-off-by: Artur Petrosyan 
Signed-off-by: Minas Harutyunyan 
---
 drivers/usb/dwc2/core_intr.c | 19 +--
 drivers/usb/dwc2/hcd.c   |  3 +++
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index 3602aca3316b..47e7dc4100af 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -491,12 +491,6 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg 
*hsotg)
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) {
switch (hsotg->params.power_down) {
case DWC2_POWER_DOWN_PARAM_PARTIAL:
@@ -733,21 +727,26 @@ static void dwc2_handle_gpwrdn_intr(struct dwc2_hsotg 
*hsotg)
}
}
}
+
if ((gpwrdn & GPWRDN_RST_DET) && (gpwrdn & GPWRDN_RST_DET_MSK)) {
dev_dbg(hsotg->dev, "%s: GPWRDN_RST_DET\n", __func__);
if (!linestate && (gpwrdn & GPWRDN_BSESSVLD))
dwc2_exit_hibernation(hsotg, 0, 1, 0);
}
+
if ((gpwrdn & GPWRDN_STS_CHGINT) &&
-   (gpwrdn & GPWRDN_STS_CHGINT_MSK) && linestate) {
+   (gpwrdn & GPWRDN_STS_CHGINT_MSK)) {
dev_dbg(hsotg->dev, "%s: GPWRDN_STS_CHGINT\n", __func__);
if (hsotg->hw_params.hibernation &&
hsotg->hibernated) {
-   if (gpwrdn & GPWRDN_IDSTS) {
+   if ((gpwrdn & GPWRDN_IDSTS) &
+   (hsotg->gr_backup.gpwrdn & GPWRDN_IDSTS) &&
+linestate) {
dwc2_exit_hibernation(hsotg, 0, 0, 0);
call_gadget(hsotg, resume);
-   } else {
-   dwc2_exit_hibernation(hsotg, 1, 0, 1);
+   } else if (!(gpwrdn & GPWRDN_IDSTS) && !linestate) {
+   dwc2_exit_hibernation(hsotg, 1, 0, 0);
+   call_gadget(hsotg, resume);
}
}
}
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 2bd6e6bfc241..0e29b4c4e87b 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -5582,6 +5582,9 @@ int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg)
gpwrdn |= GPWRDN_PWRDNSWTCH;
dwc2_writel(hsotg, gpwrdn, GPWRDN);
 
+   /* Save gpwrdn register for further usage if stschng interrupt */
+   hsotg->gr_backup.gpwrdn = dwc2_readl(hsotg, GPWRDN);
+
hsotg->hibernated = 1;
hsotg->bus_suspended = 1;
dev_dbg(hsotg->dev, "Host hibernation completed\n");
-- 
2.11.0



Re: Embedded USB Debug

2018-09-20 Thread Felipe Balbi


Hi,

Muni Sekhar  writes:
> Hi All,
>
> Can someone clarify me on the Embedded USB Debug(EUD):
>
> What is Embedded USB Debug(EUD)?

A quick google search returned this:

https://patents.google.com/patent/US20160124822

> What Embedded USB Debug(EUD) is going to be used for?

JTAG/UART/SWD/etc according to the patent

> Does Linux main tree has any drivers to support this?

not afaict

-- 
balbi


Re: [PATCH 1/2] usb: typec: mux: Take care of driver module reference counting

2018-09-20 Thread Greg KH
On Thu, Sep 20, 2018 at 02:26:28PM +0300, Heikki Krogerus wrote:
> On Thu, Sep 20, 2018 at 01:20:03PM +0200, Greg KH wrote:
> > On Wed, Sep 19, 2018 at 10:58:04AM +0300, Heikki Krogerus wrote:
> > > Functions typec_mux_get() and typec_switch_get() already
> > > make sure that the mux device reference count is
> > > incremented, but the same must be done to the driver module
> > > as well to prevent the drivers from being unloaded in the
> > > middle of operation.
> > > 
> > > This fixes a potential "BUG: unable to handle kernel paging
> > > request at ..." from happening.
> > > 
> > > Fixes: 93dd2112c7b2 ("usb: typec: mux: Get the mux identifier from 
> > > function parameter")
> > > Cc: 
> > 
> > Why is this flagged for stable? 93dd2112c7b2 went into 4.19-rc1 and has
> > not been backported anywhere else.
> > 
> > confused,
> 
> Sorry, it should not have the stable tag. Shall I resend these?

No need, I'll handle it, thanks.

greg k-h


[PATCH 12/12] usb: typec: Group all TCPCI/TCPM code together

2018-09-20 Thread Heikki Krogerus
Moving all the drivers that depend on the Port Controller
Manager under a new directory drivers/usb/typec/tcpm/ and
making Guenter Roeck the designated reviewer of that code.

Acked-by: Guenter Roeck 
Signed-off-by: Heikki Krogerus 
---
 MAINTAINERS   |  6 +++
 drivers/usb/typec/Kconfig | 45 +---
 drivers/usb/typec/Makefile|  6 +--
 drivers/usb/typec/fusb302/Kconfig |  7 ---
 drivers/usb/typec/fusb302/Makefile|  2 -
 drivers/usb/typec/tcpm/Kconfig| 52 +++
 drivers/usb/typec/tcpm/Makefile   |  7 +++
 drivers/usb/typec/{fusb302 => tcpm}/fusb302.c |  0
 .../usb/typec/{fusb302 => tcpm}/fusb302_reg.h |  0
 drivers/usb/typec/{ => tcpm}/tcpci.c  |  0
 drivers/usb/typec/{ => tcpm}/tcpci.h  |  0
 drivers/usb/typec/{ => tcpm}/tcpci_rt1711h.c  |  0
 drivers/usb/typec/{ => tcpm}/tcpm.c   |  0
 .../usb/typec/{typec_wcove.c => tcpm/wcove.c} |  0
 14 files changed, 67 insertions(+), 58 deletions(-)
 delete mode 100644 drivers/usb/typec/fusb302/Kconfig
 delete mode 100644 drivers/usb/typec/fusb302/Makefile
 create mode 100644 drivers/usb/typec/tcpm/Kconfig
 create mode 100644 drivers/usb/typec/tcpm/Makefile
 rename drivers/usb/typec/{fusb302 => tcpm}/fusb302.c (100%)
 rename drivers/usb/typec/{fusb302 => tcpm}/fusb302_reg.h (100%)
 rename drivers/usb/typec/{ => tcpm}/tcpci.c (100%)
 rename drivers/usb/typec/{ => tcpm}/tcpci.h (100%)
 rename drivers/usb/typec/{ => tcpm}/tcpci_rt1711h.c (100%)
 rename drivers/usb/typec/{ => tcpm}/tcpm.c (100%)
 rename drivers/usb/typec/{typec_wcove.c => tcpm/wcove.c} (100%)

diff --git a/MAINTAINERS b/MAINTAINERS
index 9ad052aeac39..8edc920b29e3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15269,6 +15269,12 @@ F: Documentation/driver-api/usb/typec_bus.rst
 F: drivers/usb/typec/altmodes/
 F: include/linux/usb/typec_altmode.h
 
+USB TYPEC PORT CONTROLLER DRIVERS
+M: Guenter Roeck 
+L: linux-usb@vger.kernel.org
+S: Maintained
+F: drivers/usb/typec/tcpm/
+
 USB UHCI DRIVER
 M: Alan Stern 
 L: linux-usb@vger.kernel.org
diff --git a/drivers/usb/typec/Kconfig b/drivers/usb/typec/Kconfig
index 00878c386dd0..30a847c2089d 100644
--- a/drivers/usb/typec/Kconfig
+++ b/drivers/usb/typec/Kconfig
@@ -45,50 +45,7 @@ menuconfig TYPEC
 
 if TYPEC
 
-config TYPEC_TCPM
-   tristate "USB Type-C Port Controller Manager"
-   depends on USB
-   select USB_ROLE_SWITCH
-   select POWER_SUPPLY
-   help
- The Type-C Port Controller Manager provides a USB PD and USB Type-C
- state machine for use with Type-C Port Controllers.
-
-if TYPEC_TCPM
-
-config TYPEC_TCPCI
-   tristate "Type-C Port Controller Interface driver"
-   depends on I2C
-   select REGMAP_I2C
-   help
- Type-C Port Controller driver for TCPCI-compliant controller.
-
-config TYPEC_RT1711H
-   tristate "Richtek RT1711H Type-C chip driver"
-   depends on I2C
-   select TYPEC_TCPCI
-   help
- Richtek RT1711H Type-C chip driver that works with
- Type-C Port Controller Manager to provide USB PD and USB
- Type-C functionalities.
-
-source "drivers/usb/typec/fusb302/Kconfig"
-
-config TYPEC_WCOVE
-   tristate "Intel WhiskeyCove PMIC USB Type-C PHY driver"
-   depends on ACPI
-   depends on INTEL_SOC_PMIC
-   depends on INTEL_PMC_IPC
-   depends on BXT_WC_PMIC_OPREGION
-   help
- This driver adds support for USB Type-C detection on Intel Broxton
- platforms that have Intel Whiskey Cove PMIC. The driver can detect the
- role and cable orientation.
-
- To compile this driver as module, choose M here: the module will be
- called typec_wcove
-
-endif # TYPEC_TCPM
+source "drivers/usb/typec/tcpm/Kconfig"
 
 source "drivers/usb/typec/ucsi/Kconfig"
 
diff --git a/drivers/usb/typec/Makefile b/drivers/usb/typec/Makefile
index 45b0aef428a8..6696b7263d61 100644
--- a/drivers/usb/typec/Makefile
+++ b/drivers/usb/typec/Makefile
@@ -2,11 +2,7 @@
 obj-$(CONFIG_TYPEC)+= typec.o
 typec-y:= class.o mux.o bus.o
 obj-$(CONFIG_TYPEC)+= altmodes/
-obj-$(CONFIG_TYPEC_TCPM)   += tcpm.o
-obj-y  += fusb302/
-obj-$(CONFIG_TYPEC_WCOVE)  += typec_wcove.o
+obj-$(CONFIG_TYPEC_TCPM)   += tcpm/
 obj-$(CONFIG_TYPEC_UCSI)   += ucsi/
 obj-$(CONFIG_TYPEC_TPS6598X)   += tps6598x.o
 obj-$(CONFIG_TYPEC)+= mux/
-obj-$(CONFIG_TYPEC_TCPCI)  += tcpci.o
-obj-$(CONFIG_TYPEC_RT1711H)+= tcpci_rt1711h.o
diff --git a/drivers/usb/typec/fusb302/Kconfig 
b/drivers/usb/typec/fusb302/Kconfig
deleted file mode 100644
index fce099ff39fe..
--- a/drivers/usb/typec/fusb302/Kconfig
+++ /dev/null
@@ -1,7 +0,0 @@
-config TYPEC_FUSB302
-   tristate "Fairchild FUSB302 Type-C chip driver"
-   depends on I2C
-   help
- 

Re: [PATCH 1/2] usb: typec: mux: Take care of driver module reference counting

2018-09-20 Thread Heikki Krogerus
On Thu, Sep 20, 2018 at 01:20:03PM +0200, Greg KH wrote:
> On Wed, Sep 19, 2018 at 10:58:04AM +0300, Heikki Krogerus wrote:
> > Functions typec_mux_get() and typec_switch_get() already
> > make sure that the mux device reference count is
> > incremented, but the same must be done to the driver module
> > as well to prevent the drivers from being unloaded in the
> > middle of operation.
> > 
> > This fixes a potential "BUG: unable to handle kernel paging
> > request at ..." from happening.
> > 
> > Fixes: 93dd2112c7b2 ("usb: typec: mux: Get the mux identifier from function 
> > parameter")
> > Cc: 
> 
> Why is this flagged for stable? 93dd2112c7b2 went into 4.19-rc1 and has
> not been backported anywhere else.
> 
> confused,

Sorry, it should not have the stable tag. Shall I resend these?

Thanks,

-- 
heikki


[PATCH 11/12] usb: typec: fusb302: reorganizing the probe function a little

2018-09-20 Thread Heikki Krogerus
The debugfs needs to be initialized as the last step in
probe in this case. The struct dentry *rootdir can't be
pointing to anything unless driver probe really finishes
successfully.

It is also not necessary to clear the i2c clientdata if the
probe fails, so removing the extra label used for that.

Acked-by: Hans de Goede 
Tested-by: Hans de Goede 
Signed-off-by: Heikki Krogerus 
---
 drivers/usb/typec/fusb302/fusb302.c | 25 +
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/typec/fusb302/fusb302.c 
b/drivers/usb/typec/fusb302/fusb302.c
index 1b464c948d76..7cf6ee4ce862 100644
--- a/drivers/usb/typec/fusb302/fusb302.c
+++ b/drivers/usb/typec/fusb302/fusb302.c
@@ -1730,7 +1730,6 @@ static int fusb302_probe(struct i2c_client *client,
return -ENOMEM;
 
chip->i2c_client = client;
-   i2c_set_clientdata(client, chip);
chip->dev = >dev;
chip->tcpc_config = fusb302_tcpc_config;
chip->tcpc_dev.config = >tcpc_config;
@@ -1759,22 +1758,17 @@ static int fusb302_probe(struct i2c_client *client,
return -EPROBE_DEFER;
}
 
-   fusb302_debugfs_init(chip);
+   chip->vbus = devm_regulator_get(chip->dev, "vbus");
+   if (IS_ERR(chip->vbus))
+   return PTR_ERR(chip->vbus);
 
chip->wq = create_singlethread_workqueue(dev_name(chip->dev));
-   if (!chip->wq) {
-   ret = -ENOMEM;
-   goto clear_client_data;
-   }
+   if (!chip->wq)
+   return -ENOMEM;
+
INIT_DELAYED_WORK(>bc_lvl_handler, fusb302_bc_lvl_handler_work);
init_tcpc_dev(>tcpc_dev);
 
-   chip->vbus = devm_regulator_get(chip->dev, "vbus");
-   if (IS_ERR(chip->vbus)) {
-   ret = PTR_ERR(chip->vbus);
-   goto destroy_workqueue;
-   }
-
if (client->irq) {
chip->gpio_int_n_irq = client->irq;
} else {
@@ -1800,15 +1794,15 @@ static int fusb302_probe(struct i2c_client *client,
goto tcpm_unregister_port;
}
enable_irq_wake(chip->gpio_int_n_irq);
+   fusb302_debugfs_init(chip);
+   i2c_set_clientdata(client, chip);
+
return ret;
 
 tcpm_unregister_port:
tcpm_unregister_port(chip->tcpm_port);
 destroy_workqueue:
destroy_workqueue(chip->wq);
-clear_client_data:
-   i2c_set_clientdata(client, NULL);
-   fusb302_debugfs_exit(chip);
 
return ret;
 }
@@ -1819,7 +1813,6 @@ static int fusb302_remove(struct i2c_client *client)
 
tcpm_unregister_port(chip->tcpm_port);
destroy_workqueue(chip->wq);
-   i2c_set_clientdata(client, NULL);
fusb302_debugfs_exit(chip);
 
return 0;
-- 
2.18.0



[PATCH 02/12] dt-bindings: usb: fusb302: Use usb-connector bindings for configuration

2018-09-20 Thread Heikki Krogerus
From: Adam Thomson 

There are now generic usb-connector bindings which can be used
to define a port controllers configuration for USB-PD, so device
specific bindings are no longer necessary.

This update deprecates 'fcs,operating-sink-microwatt', and references
the 'usb-connector' bindings instead to achieve the required port
config.

Signed-off-by: Adam Thomson 
Reviewed-by: Rob Herring 
Signed-off-by: Heikki Krogerus 
---
 .../devicetree/bindings/usb/fcs,fusb302.txt   | 32 +++
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/fcs,fusb302.txt 
b/Documentation/devicetree/bindings/usb/fcs,fusb302.txt
index 6087dc7f209e..a5d011d2efc8 100644
--- a/Documentation/devicetree/bindings/usb/fcs,fusb302.txt
+++ b/Documentation/devicetree/bindings/usb/fcs,fusb302.txt
@@ -5,10 +5,19 @@ Required properties :
 - reg: I2C slave address
 - interrupts : Interrupt specifier
 
-Optional properties :
-- fcs,operating-sink-microwatt :
-  Minimum amount of power accepted from a sink
-  when negotiating
+Required sub-node:
+- connector : The "usb-c-connector" attached to the FUSB302 IC. The bindings
+  of the connector node are specified in:
+
+   Documentation/devicetree/bindings/connector/usb-connector.txt
+
+Deprecated properties :
+- fcs,max-sink-microvolt : Maximum sink voltage accepted by port controller
+- fcs,max-sink-microamp : Maximum sink current accepted by port controller
+- fcs,max-sink-microwatt : Maximum sink power accepted by port controller
+- fcs,operating-sink-microwatt : Minimum amount of power accepted from a sink
+  when negotiating
+
 
 Example:
 
@@ -17,7 +26,16 @@ fusb302: typec-portc@54 {
reg = <0x54>;
interrupt-parent = <_intc>;
interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
-   fcs,max-sink-microvolt = <1200>;
-   fcs,max-sink-microamp = <300>;
-   fcs,max-sink-microwatt = <3600>;
+
+   usb_con: connector {
+   compatible = "usb-c-connector";
+   label = "USB-C";
+   power-role = "dual";
+   try-power-role = "sink";
+   source-pdos = ;
+   sink-pdos = ;
+   op-sink-microwatt = <1000>;
+   };
 };
-- 
2.18.0



[PATCH 07/12] platform: x86: intel_cht_int33fe: Add connection for the DP alt mode

2018-09-20 Thread Heikki Krogerus
Adding a connection for the DisplayPort alternate mode.
PI3USB30532 is used for muxing the port to DisplayPort on
CHT platforms. The connection allows the alternate mode
device to get handle to the mux, and therefore make it
possible to use the USB Type-C connector as DisplayPort.

Acked-by: Andy Shevchenko 
Acked-by: Hans de Goede 
Tested-by: Hans de Goede 
Signed-off-by: Heikki Krogerus 
---
 drivers/platform/x86/intel_cht_int33fe.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/intel_cht_int33fe.c 
b/drivers/platform/x86/intel_cht_int33fe.c
index b0cef48f77af..424064187124 100644
--- a/drivers/platform/x86/intel_cht_int33fe.c
+++ b/drivers/platform/x86/intel_cht_int33fe.c
@@ -34,7 +34,7 @@ struct cht_int33fe_data {
struct i2c_client *fusb302;
struct i2c_client *pi3usb30532;
/* Contain a list-head must be per device */
-   struct device_connection connections[4];
+   struct device_connection connections[5];
 };
 
 /*
@@ -181,8 +181,11 @@ static int cht_int33fe_probe(struct i2c_client *client)
data->connections[1].endpoint[1] = "i2c-pi3usb30532";
data->connections[1].id = "typec-mux";
data->connections[2].endpoint[0] = "i2c-fusb302";
-   data->connections[2].endpoint[1] = "intel_xhci_usb_sw-role-switch";
-   data->connections[2].id = "usb-role-switch";
+   data->connections[2].endpoint[1] = "i2c-pi3usb30532";
+   data->connections[2].id = "idff01m01";
+   data->connections[3].endpoint[0] = "i2c-fusb302";
+   data->connections[3].endpoint[1] = "intel_xhci_usb_sw-role-switch";
+   data->connections[3].id = "usb-role-switch";
 
device_connections_add(data->connections);
 
-- 
2.18.0



[PATCH 09/12] usb: typec: class: Don't use port parent for getting mux handles

2018-09-20 Thread Heikki Krogerus
It is not possible to use the parent of the port device when
requesting mux handles as the parent may be a multiport USB
Type-C or PD controller. The muxes must be assigned to the
ports, not the controllers.

This will also move the requesting of the muxes after the
port device is initialized.

Acked-by: Hans de Goede 
Tested-by: Hans de Goede 
Signed-off-by: Heikki Krogerus 
---
 drivers/usb/typec/class.c | 38 +++---
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index c202975f8097..5b969339d1b3 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -1501,7 +1501,7 @@ typec_port_register_altmode(struct typec_port *port,
 
sprintf(id, "id%04xm%02x", desc->svid, desc->mode);
 
-   mux = typec_mux_get(port->dev.parent, id);
+   mux = typec_mux_get(>dev, id);
if (IS_ERR(mux))
return ERR_CAST(mux);
 
@@ -1541,18 +1541,6 @@ struct typec_port *typec_register_port(struct device 
*parent,
return ERR_PTR(id);
}
 
-   port->sw = typec_switch_get(cap->fwnode ? >dev : parent);
-   if (IS_ERR(port->sw)) {
-   ret = PTR_ERR(port->sw);
-   goto err_switch;
-   }
-
-   port->mux = typec_mux_get(parent, "typec-mux");
-   if (IS_ERR(port->mux)) {
-   ret = PTR_ERR(port->mux);
-   goto err_mux;
-   }
-
switch (cap->type) {
case TYPEC_PORT_SRC:
port->pwr_role = TYPEC_SOURCE;
@@ -1593,13 +1581,26 @@ struct typec_port *typec_register_port(struct device 
*parent,
port->port_type = cap->type;
port->prefer_role = cap->prefer_role;
 
+   device_initialize(>dev);
port->dev.class = typec_class;
port->dev.parent = parent;
port->dev.fwnode = cap->fwnode;
port->dev.type = _port_dev_type;
dev_set_name(>dev, "port%d", id);
 
-   ret = device_register(>dev);
+   port->sw = typec_switch_get(>dev);
+   if (IS_ERR(port->sw)) {
+   put_device(>dev);
+   return ERR_CAST(port->sw);
+   }
+
+   port->mux = typec_mux_get(>dev, "typec-mux");
+   if (IS_ERR(port->mux)) {
+   put_device(>dev);
+   return ERR_CAST(port->mux);
+   }
+
+   ret = device_add(>dev);
if (ret) {
dev_err(parent, "failed to register port (%d)\n", ret);
put_device(>dev);
@@ -1607,15 +1608,6 @@ struct typec_port *typec_register_port(struct device 
*parent,
}
 
return port;
-
-err_mux:
-   typec_switch_put(port->sw);
-
-err_switch:
-   ida_simple_remove(_index_ida, port->id);
-   kfree(port);
-
-   return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(typec_register_port);
 
-- 
2.18.0



[PATCH 04/12] platform: x86: intel_cht_int33fe: Add dependency on muxes

2018-09-20 Thread Heikki Krogerus
The connections create clear dependency on the muxes.
fusb302 fails to probe unless we have the mux drivers
available.

Acked-by: Andy Shevchenko 
Acked-by: Hans de Goede 
Tested-by: Hans de Goede 
Signed-off-by: Heikki Krogerus 
---
 drivers/platform/x86/Kconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 0c1aa6c314f5..bdac939de223 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -867,6 +867,8 @@ config INTEL_CHT_INT33FE
tristate "Intel Cherry Trail ACPI INT33FE Driver"
depends on X86 && ACPI && I2C && REGULATOR
depends on CHARGER_BQ24190=y || (CHARGER_BQ24190=m && m)
+   depends on USB_ROLES_INTEL_XHCI=y || (USB_ROLES_INTEL_XHCI=m && m)
+   depends on TYPEC_MUX_PI3USB30532=y || (TYPEC_MUX_PI3USB30532=m && m)
---help---
  This driver add support for the INT33FE ACPI device found on
  some Intel Cherry Trail devices.
-- 
2.18.0



[PATCH 03/12] usb: typec: fusb302: Populate tcpc fwnode for TCPM property handling

2018-09-20 Thread Heikki Krogerus
From: Adam Thomson 

This update populates the tcpc handle's fwnode pointer with the
child usb-connector node, if it exists, so that TCPM can perform
generic property handling to define the ports capabilities.

Signed-off-by: Adam Thomson 
Reviewed-by: Guenter Roeck 
Signed-off-by: Heikki Krogerus 
---
 drivers/usb/typec/fusb302/fusb302.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/typec/fusb302/fusb302.c 
b/drivers/usb/typec/fusb302/fusb302.c
index 82bed9810be6..1b464c948d76 100644
--- a/drivers/usb/typec/fusb302/fusb302.c
+++ b/drivers/usb/typec/fusb302/fusb302.c
@@ -1736,6 +1736,9 @@ static int fusb302_probe(struct i2c_client *client,
chip->tcpc_dev.config = >tcpc_config;
mutex_init(>lock);
 
+   chip->tcpc_dev.fwnode =
+   device_get_named_child_node(dev, "connector");
+
if (!device_property_read_u32(dev, "fcs,operating-sink-microwatt", ))
chip->tcpc_config.operating_snk_mw = v / 1000;
 
-- 
2.18.0



[PATCH 10/12] platform: x86: intel_cht_int33fe: Remove the old connections for the muxes

2018-09-20 Thread Heikki Krogerus
USB Type-C class driver now expects the muxes to be always
assigned to the ports and not controllers, so the
connections for the mux and fusb302 can be removed.

Acked-by: Andy Shevchenko 
Acked-by: Hans de Goede 
Tested-by: Hans de Goede 
Signed-off-by: Heikki Krogerus 
---
 drivers/platform/x86/intel_cht_int33fe.c | 18 --
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/platform/x86/intel_cht_int33fe.c 
b/drivers/platform/x86/intel_cht_int33fe.c
index 419ce8c8ffb5..a26f410800c2 100644
--- a/drivers/platform/x86/intel_cht_int33fe.c
+++ b/drivers/platform/x86/intel_cht_int33fe.c
@@ -34,7 +34,7 @@ struct cht_int33fe_data {
struct i2c_client *fusb302;
struct i2c_client *pi3usb30532;
/* Contain a list-head must be per device */
-   struct device_connection connections[8];
+   struct device_connection connections[5];
 };
 
 /*
@@ -174,29 +174,19 @@ static int cht_int33fe_probe(struct i2c_client *client)
return -EPROBE_DEFER; /* Wait for i2c-adapter to load */
}
 
-   data->connections[0].endpoint[0] = "i2c-fusb302";
+   data->connections[0].endpoint[0] = "port0";
data->connections[0].endpoint[1] = "i2c-pi3usb30532";
data->connections[0].id = "typec-switch";
-   data->connections[1].endpoint[0] = "i2c-fusb302";
+   data->connections[1].endpoint[0] = "port0";
data->connections[1].endpoint[1] = "i2c-pi3usb30532";
data->connections[1].id = "typec-mux";
-   data->connections[2].endpoint[0] = "i2c-fusb302";
+   data->connections[2].endpoint[0] = "port0";
data->connections[2].endpoint[1] = "i2c-pi3usb30532";
data->connections[2].id = "idff01m01";
data->connections[3].endpoint[0] = "i2c-fusb302";
data->connections[3].endpoint[1] = "intel_xhci_usb_sw-role-switch";
data->connections[3].id = "usb-role-switch";
 
-   data->connections[4].endpoint[0] = "port0";
-   data->connections[4].endpoint[1] = "i2c-pi3usb30532";
-   data->connections[4].id = "typec-switch";
-   data->connections[5].endpoint[0] = "port0";
-   data->connections[5].endpoint[1] = "i2c-pi3usb30532";
-   data->connections[5].id = "typec-mux";
-   data->connections[6].endpoint[0] = "port0";
-   data->connections[6].endpoint[1] = "i2c-pi3usb30532";
-   data->connections[6].id = "idff01m01";
-
device_connections_add(data->connections);
 
memset(_info, 0, sizeof(board_info));
-- 
2.18.0



[PATCH 05/12] drivers: base: Helpers for adding device connection descriptions

2018-09-20 Thread Heikki Krogerus
Introducing helpers for adding and removing multiple device
connection descriptions at once.

Acked-by: Hans de Goede 
Tested-by: Hans de Goede 
Signed-off-by: Heikki Krogerus 
---
 include/linux/device.h | 24 
 1 file changed, 24 insertions(+)

diff --git a/include/linux/device.h b/include/linux/device.h
index 8f882549edee..3f1066a9e1c3 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -773,6 +773,30 @@ struct device *device_connection_find(struct device *dev, 
const char *con_id);
 void device_connection_add(struct device_connection *con);
 void device_connection_remove(struct device_connection *con);
 
+/**
+ * device_connections_add - Add multiple device connections at once
+ * @cons: Zero terminated array of device connection descriptors
+ */
+static inline void device_connections_add(struct device_connection *cons)
+{
+   struct device_connection *c;
+
+   for (c = cons; c->endpoint[0]; c++)
+   device_connection_add(c);
+}
+
+/**
+ * device_connections_remove - Remove multiple device connections at once
+ * @cons: Zero terminated array of device connection descriptors
+ */
+static inline void device_connections_remove(struct device_connection *cons)
+{
+   struct device_connection *c;
+
+   for (c = cons; c->endpoint[0]; c++)
+   device_connection_remove(c);
+}
+
 /**
  * enum device_link_state - Device link states.
  * @DL_STATE_NONE: The presence of the drivers is not being tracked.
-- 
2.18.0



[PATCH 06/12] platform: x86: intel_cht_int33fe: Register all connections at once

2018-09-20 Thread Heikki Krogerus
We can register all device connection descriptors with a
single call to device_connections_add().

Acked-by: Andy Shevchenko 
Acked-by: Hans de Goede 
Tested-by: Hans de Goede 
Signed-off-by: Heikki Krogerus 
---
 drivers/platform/x86/intel_cht_int33fe.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/platform/x86/intel_cht_int33fe.c 
b/drivers/platform/x86/intel_cht_int33fe.c
index 39d4100c60a2..b0cef48f77af 100644
--- a/drivers/platform/x86/intel_cht_int33fe.c
+++ b/drivers/platform/x86/intel_cht_int33fe.c
@@ -34,7 +34,7 @@ struct cht_int33fe_data {
struct i2c_client *fusb302;
struct i2c_client *pi3usb30532;
/* Contain a list-head must be per device */
-   struct device_connection connections[3];
+   struct device_connection connections[4];
 };
 
 /*
@@ -184,9 +184,7 @@ static int cht_int33fe_probe(struct i2c_client *client)
data->connections[2].endpoint[1] = "intel_xhci_usb_sw-role-switch";
data->connections[2].id = "usb-role-switch";
 
-   device_connection_add(>connections[0]);
-   device_connection_add(>connections[1]);
-   device_connection_add(>connections[2]);
+   device_connections_add(data->connections);
 
memset(_info, 0, sizeof(board_info));
strlcpy(board_info.type, "typec_fusb302", I2C_NAME_SIZE);
@@ -217,9 +215,7 @@ static int cht_int33fe_probe(struct i2c_client *client)
if (data->max17047)
i2c_unregister_device(data->max17047);
 
-   device_connection_remove(>connections[2]);
-   device_connection_remove(>connections[1]);
-   device_connection_remove(>connections[0]);
+   device_connections_remove(data->connections);
 
return -EPROBE_DEFER; /* Wait for the i2c-adapter to load */
 }
@@ -233,9 +229,7 @@ static int cht_int33fe_remove(struct i2c_client *i2c)
if (data->max17047)
i2c_unregister_device(data->max17047);
 
-   device_connection_remove(>connections[2]);
-   device_connection_remove(>connections[1]);
-   device_connection_remove(>connections[0]);
+   device_connections_remove(data->connections);
 
return 0;
 }
-- 
2.18.0



[PATCH 00/12] Type-C changes for usb-next

2018-09-20 Thread Heikki Krogerus
Hi Greg,

I took the liberty of collecting the Type-C patches, and sending all of them to
you together this time. I hope that's OK.

Since all the Type-C port controller drivers and port manager code is now out of
staging, the final patch will group them all together under a new directory
drivers/usb/typec/tcpm/ and make Guenter the designated reviewer/maintainer of
if.

All the other changes are related to the fusb302 port controller driver. There
are also some changes to the Intel Cherry Trail board file that populates the
fusb302 device.

Let me know if there is anything you want me to change.

Thanks,

--
heikki

Adam Thomson (3):
  dt-bindings: connector: Add support for USB-PD PPS APDOs to bindings
  dt-bindings: usb: fusb302: Use usb-connector bindings for
configuration
  usb: typec: fusb302: Populate tcpc fwnode for TCPM property handling

Heikki Krogerus (9):
  platform: x86: intel_cht_int33fe: Add dependency on muxes
  drivers: base: Helpers for adding device connection descriptions
  platform: x86: intel_cht_int33fe: Register all connections at once
  platform: x86: intel_cht_int33fe: Add connection for the DP alt mode
  platform: x86: intel_cht_int33fe: Add connections for the USB Type-C
port
  usb: typec: class: Don't use port parent for getting mux handles
  platform: x86: intel_cht_int33fe: Remove the old connections for the
muxes
  usb: typec: fusb302: reorganizing the probe function a little
  usb: typec: Group all TCPCI/TCPM code together

 .../bindings/connector/usb-connector.txt  |  8 +--
 .../devicetree/bindings/usb/fcs,fusb302.txt   | 32 +---
 MAINTAINERS   |  6 +++
 drivers/platform/x86/Kconfig  |  2 +
 drivers/platform/x86/intel_cht_int33fe.c  | 27 +-
 drivers/usb/typec/Kconfig | 45 +---
 drivers/usb/typec/Makefile|  6 +--
 drivers/usb/typec/class.c | 38 ++
 drivers/usb/typec/fusb302/Kconfig |  7 ---
 drivers/usb/typec/fusb302/Makefile|  2 -
 drivers/usb/typec/tcpm/Kconfig| 52 +++
 drivers/usb/typec/tcpm/Makefile   |  7 +++
 drivers/usb/typec/{fusb302 => tcpm}/fusb302.c | 28 +-
 .../usb/typec/{fusb302 => tcpm}/fusb302_reg.h |  0
 drivers/usb/typec/{ => tcpm}/tcpci.c  |  0
 drivers/usb/typec/{ => tcpm}/tcpci.h  |  0
 drivers/usb/typec/{ => tcpm}/tcpci_rt1711h.c  |  0
 drivers/usb/typec/{ => tcpm}/tcpm.c   |  0
 .../usb/typec/{typec_wcove.c => tcpm/wcove.c} |  0
 include/dt-bindings/usb/pd.h  | 26 ++
 include/linux/device.h| 24 +
 21 files changed, 187 insertions(+), 123 deletions(-)
 delete mode 100644 drivers/usb/typec/fusb302/Kconfig
 delete mode 100644 drivers/usb/typec/fusb302/Makefile
 create mode 100644 drivers/usb/typec/tcpm/Kconfig
 create mode 100644 drivers/usb/typec/tcpm/Makefile
 rename drivers/usb/typec/{fusb302 => tcpm}/fusb302.c (99%)
 rename drivers/usb/typec/{fusb302 => tcpm}/fusb302_reg.h (100%)
 rename drivers/usb/typec/{ => tcpm}/tcpci.c (100%)
 rename drivers/usb/typec/{ => tcpm}/tcpci.h (100%)
 rename drivers/usb/typec/{ => tcpm}/tcpci_rt1711h.c (100%)
 rename drivers/usb/typec/{ => tcpm}/tcpm.c (100%)
 rename drivers/usb/typec/{typec_wcove.c => tcpm/wcove.c} (100%)

-- 
2.18.0



[PATCH 08/12] platform: x86: intel_cht_int33fe: Add connections for the USB Type-C port

2018-09-20 Thread Heikki Krogerus
Assigning the mux to the USB Type-C port on top of fusb302.
That will prepare this driver for the change in the USB
Type-C class code, where the class driver will assume the
muxes to be always assigned to the ports and not the
controllers.

Once the USB Type-C class driver has been updated, the
connections between the mux and fusb302 can be dropped.

Acked-by: Andy Shevchenko 
Acked-by: Hans de Goede 
Tested-by: Hans de Goede 
Signed-off-by: Heikki Krogerus 
---
 drivers/platform/x86/intel_cht_int33fe.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/intel_cht_int33fe.c 
b/drivers/platform/x86/intel_cht_int33fe.c
index 424064187124..419ce8c8ffb5 100644
--- a/drivers/platform/x86/intel_cht_int33fe.c
+++ b/drivers/platform/x86/intel_cht_int33fe.c
@@ -34,7 +34,7 @@ struct cht_int33fe_data {
struct i2c_client *fusb302;
struct i2c_client *pi3usb30532;
/* Contain a list-head must be per device */
-   struct device_connection connections[5];
+   struct device_connection connections[8];
 };
 
 /*
@@ -187,6 +187,16 @@ static int cht_int33fe_probe(struct i2c_client *client)
data->connections[3].endpoint[1] = "intel_xhci_usb_sw-role-switch";
data->connections[3].id = "usb-role-switch";
 
+   data->connections[4].endpoint[0] = "port0";
+   data->connections[4].endpoint[1] = "i2c-pi3usb30532";
+   data->connections[4].id = "typec-switch";
+   data->connections[5].endpoint[0] = "port0";
+   data->connections[5].endpoint[1] = "i2c-pi3usb30532";
+   data->connections[5].id = "typec-mux";
+   data->connections[6].endpoint[0] = "port0";
+   data->connections[6].endpoint[1] = "i2c-pi3usb30532";
+   data->connections[6].id = "idff01m01";
+
device_connections_add(data->connections);
 
memset(_info, 0, sizeof(board_info));
-- 
2.18.0



[PATCH 01/12] dt-bindings: connector: Add support for USB-PD PPS APDOs to bindings

2018-09-20 Thread Heikki Krogerus
From: Adam Thomson 

Add support for PPS APDOs to connector bindings so a port controller
can specify support for PPS, as per existing FIXED/BATT/VAR PDOs.

Signed-off-by: Adam Thomson 
Reviewed-by: Rob Herring 
Signed-off-by: Heikki Krogerus 
---
 .../bindings/connector/usb-connector.txt  |  8 +++---
 include/dt-bindings/usb/pd.h  | 26 +++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/connector/usb-connector.txt 
b/Documentation/devicetree/bindings/connector/usb-connector.txt
index 8855bfcfd778..d90e17e2428b 100644
--- a/Documentation/devicetree/bindings/connector/usb-connector.txt
+++ b/Documentation/devicetree/bindings/connector/usb-connector.txt
@@ -29,15 +29,15 @@ Required properties for usb-c-connector with power delivery 
support:
   in "Universal Serial Bus Power Delivery Specification" chapter 6.4.1.2
   Source_Capabilities Message, the order of each entry(PDO) should follow
   the PD spec chapter 6.4.1. Required for power source and power dual role.
-  User can specify the source PDO array via PDO_FIXED/BATT/VAR() defined in
-  dt-bindings/usb/pd.h.
+  User can specify the source PDO array via PDO_FIXED/BATT/VAR/PPS_APDO()
+  defined in dt-bindings/usb/pd.h.
 - sink-pdos: An array of u32 with each entry providing supported power
   sink data object(PDO), the detailed bit definitions of PDO can be found
   in "Universal Serial Bus Power Delivery Specification" chapter 6.4.1.3
   Sink Capabilities Message, the order of each entry(PDO) should follow
   the PD spec chapter 6.4.1. Required for power sink and power dual role.
-  User can specify the sink PDO array via PDO_FIXED/BATT/VAR() defined in
-  dt-bindings/usb/pd.h.
+  User can specify the sink PDO array via PDO_FIXED/BATT/VAR/PPS_APDO() defined
+  in dt-bindings/usb/pd.h.
 - op-sink-microwatt: Sink required operating power in microwatt, if source
   can't offer the power, Capability Mismatch is set. Required for power
   sink and power dual role.
diff --git a/include/dt-bindings/usb/pd.h b/include/dt-bindings/usb/pd.h
index 7b7a92fefa0a..985f2bbd4d24 100644
--- a/include/dt-bindings/usb/pd.h
+++ b/include/dt-bindings/usb/pd.h
@@ -59,4 +59,30 @@
(PDO_TYPE(PDO_TYPE_VAR) | PDO_VAR_MIN_VOLT(min_mv) |\
 PDO_VAR_MAX_VOLT(max_mv) | PDO_VAR_MAX_CURR(max_ma))
 
+#define APDO_TYPE_PPS  0
+
+#define PDO_APDO_TYPE_SHIFT28  /* Only valid value currently is 0x0 - 
PPS */
+#define PDO_APDO_TYPE_MASK 0x3
+
+#define PDO_APDO_TYPE(t)   ((t) << PDO_APDO_TYPE_SHIFT)
+
+#define PDO_PPS_APDO_MAX_VOLT_SHIFT17  /* 100mV units */
+#define PDO_PPS_APDO_MIN_VOLT_SHIFT8   /* 100mV units */
+#define PDO_PPS_APDO_MAX_CURR_SHIFT0   /* 50mA units */
+
+#define PDO_PPS_APDO_VOLT_MASK 0xff
+#define PDO_PPS_APDO_CURR_MASK 0x7f
+
+#define PDO_PPS_APDO_MIN_VOLT(mv)  \
+   mv) / 100) & PDO_PPS_APDO_VOLT_MASK) << PDO_PPS_APDO_MIN_VOLT_SHIFT)
+#define PDO_PPS_APDO_MAX_VOLT(mv)  \
+   mv) / 100) & PDO_PPS_APDO_VOLT_MASK) << PDO_PPS_APDO_MAX_VOLT_SHIFT)
+#define PDO_PPS_APDO_MAX_CURR(ma)  \
+   ma) / 50) & PDO_PPS_APDO_CURR_MASK) << PDO_PPS_APDO_MAX_CURR_SHIFT)
+
+#define PDO_PPS_APDO(min_mv, max_mv, max_ma)   
\
+   (PDO_TYPE(PDO_TYPE_APDO) | PDO_APDO_TYPE(APDO_TYPE_PPS) |   
\
+PDO_PPS_APDO_MIN_VOLT(min_mv) | PDO_PPS_APDO_MAX_VOLT(max_mv) |
\
+PDO_PPS_APDO_MAX_CURR(max_ma))
+
  #endif /* __DT_POWER_DELIVERY_H */
-- 
2.18.0



Re: [PATCH 1/2] usb: typec: mux: Take care of driver module reference counting

2018-09-20 Thread Greg KH
On Wed, Sep 19, 2018 at 10:58:04AM +0300, Heikki Krogerus wrote:
> Functions typec_mux_get() and typec_switch_get() already
> make sure that the mux device reference count is
> incremented, but the same must be done to the driver module
> as well to prevent the drivers from being unloaded in the
> middle of operation.
> 
> This fixes a potential "BUG: unable to handle kernel paging
> request at ..." from happening.
> 
> Fixes: 93dd2112c7b2 ("usb: typec: mux: Get the mux identifier from function 
> parameter")
> Cc: 

Why is this flagged for stable? 93dd2112c7b2 went into 4.19-rc1 and has
not been backported anywhere else.

confused,

greg k-h


Re: [PATCH v4 00/10] usb: typec: A few more improvements for Intel CHT

2018-09-20 Thread Greg Kroah-Hartman
On Wed, Sep 12, 2018 at 11:00:55AM +0300, Heikki Krogerus wrote:
> Hi,
> 
> On Tue, Sep 11, 2018 at 07:36:34PM +0200, Hans de Goede wrote:
> > On 11-09-18 12:10, Heikki Krogerus wrote:
> > > This is fourth version of this series. There was one bug in patch 2/10
> > > that Hans noticed. It should be fixed now.
> > > 
> > > The commit message from v3:
> > > 
> > > These patches will introduce a few improvements to the USB Type-C
> > > support on Intel CHT platform. In this series I'm preparing Intel CHT
> > > mux handling for DisplayPort Alt Mode support, but please note that,
> > > after these patches the DisplayPort alternate mode will still not work
> > > out of the box on CHT platform. Changes to the fusb302.c, and possibly
> > > tcpm.c are still needed.
> > > 
> > > This version will only fix the issue Hans pointed out in v2. Instead
> > > of replacing the connection that assigned the mux to the USB Type-C
> > > port with a connection that assigns the mux to the alternate mode
> > > device, we keep all the existing connections and add a new one for the
> > > alternate mode device. That way USB3 devices continue to be enumerated
> > > as USB3 devices instead of USB2 devices.
> > > 
> > > The origin thread can be read here:
> > > https://www.spinics.net/lists/linux-usb/msg172033.html
> > 
> > Thanks, the entire series looks good to me and has been tested by
> > me on a GPD win with a fusb302 tcpm controller:
> > 
> > Acked-by: Hans de Goede 
> > Tested-by: Hans de Goede 
> > 
> > Greg, the previous version of this series also was:
> > 
> > "
> > Acked-by: Andy Shevchenko 
> > 
> > for PDx86 bits on condition that Hans is fine with them.
> > "
> > 
> > With the intend that the entire series would be merged
> > through the USB tree with Andy's ack for the
> > "platform: x86: ..." patches.
> 
> Thanks Hans!
> 
> I've now applied these to my tree:
> https://github.com/krohei/linux/commits/typec-next
> 
> I will resend them together with the other Type-C patches I've
> collected next week after v4.19-rc4 unless Greg takes the patches
> himself before that. The idea is to take care of a conflict for Greg.

That would be great if you could do that.

thanks,

greg k-h


Re: [PATCH v2] usb: core: added uevent for over-current

2018-09-20 Thread Greg KH
On Tue, Sep 11, 2018 at 10:43:10AM -0700, Jon Flatley wrote:
> After commit 1cbd53c8cd85 ("usb: core: introduce per-port over-current
> counters") usb ports expose a sysfs value 'over_current_count'
> to user space. This value on its own is not very useful as it requires
> manual polling.
> 
> As a solution, fire a udev event from the usb hub device that specifies
> the values 'OVER_CURRENT_PORT' and 'OVER_CURRENT_COUNT' that indicate
> the path of the usb port where the over-current event occurred and the
> value of 'over_current_count' in sysfs. Additionally, call
> sysfs_notify() so the sysfs value supports poll().
> 
> Signed-off-by: Jon Flatley 
> ---
>  Documentation/ABI/testing/sysfs-bus-usb |  9 ++-
>  drivers/usb/core/hub.c  | 36 +
>  2 files changed, 44 insertions(+), 1 deletion(-)

This patch doesn't apply against my usb-next branch at the moment.

Can you rebase it and resend?

thanks,

greg k-h


Re: [PATCH v6 01/22] usb: usbtmc: Add ioctl for generic requests on control

2018-09-20 Thread Greg KH
On Thu, Sep 20, 2018 at 01:00:35PM +0200, Greg KH wrote:
> On Wed, Sep 12, 2018 at 10:50:51AM +0200, Guido Kiener wrote:
> > --- a/include/uapi/linux/usb/tmc.h
> > +++ b/include/uapi/linux/usb/tmc.h
> > @@ -4,6 +4,7 @@
> >   * Copyright (C) 2008 Novell, Inc.
> >   * Copyright (C) 2008 Greg Kroah-Hartman 
> >   * Copyright (C) 2015 Dave Penkler 
> > + * Copyright (C) 2018 IVI Foundation, Inc.
> >   *
> >   * This file holds USB constants defined by the USB Device Class
> >   * and USB488 Subclass Definitions for Test and Measurement devices
> > @@ -40,6 +41,19 @@
> >  #define USBTMC488_REQUEST_GOTO_LOCAL   161
> >  #define USBTMC488_REQUEST_LOCAL_LOCKOUT162
> >  
> > +struct usbtmc_request {
> > +   __u8 bRequestType;
> > +   __u8 bRequest;
> > +   __u16 wValue;
> > +   __u16 wIndex;
> > +   __u16 wLength;
> > +} __attribute__ ((packed));
> 
> This really is just 'struct usb_ctrlrequest', right?  That's already
> defined in our uapi files.  Why not use that?
> 
> Bonus is, if you use that, you get the proper endian notation, which you
> don't have here, which means this is broken on big endian machines :(
> 
> Try doing that, and fix up the endian issue.

Ah, nevermind, you are passing this to the hardware properly.  This
should be just fine, I'll take it as-is, sorry for the noise.

greg k-h


Re: [PATCHv2] usb: typec: Group all TCPCI/TCPM code together

2018-09-20 Thread Heikki Krogerus
On Thu, Sep 20, 2018 at 12:52:35PM +0200, Greg Kroah-Hartman wrote:
> On Tue, Sep 11, 2018 at 05:51:36PM +0300, Heikki Krogerus wrote:
> > On Mon, Sep 10, 2018 at 06:21:04AM -0700, Guenter Roeck wrote:
> > > On 09/10/2018 04:58 AM, Heikki Krogerus wrote:
> > > > Moving all the drivers that depend on the Port Controller
> > > > Manager under a new directory drivers/usb/typec/tcpm/ and
> > > > making Guenter Roeck the designated reviewer of that code.
> > > > 
> > > > Signed-off-by: Heikki Krogerus 
> > > 
> > > Acked-by: Guenter Roeck 
> > 
> > Thanks!
> > 
> > To avoid the little conflict this patch will cause, I'll resend it
> > together with the other Type-C patches I've collected next week to
> > Greg (assuming he does not pick them himself before that).
> > 
> > I have all the patches here:
> > https://github.com/krohei/linux/commits/typec-next
> 
> Yes, please send all of the patches in the correct order as I am
> confused as to what needs to be applied where at the moment.

I was just about to send them :-).


Thanks,

-- 
heikki


Re: [PATCH v6 02/22] usb: usbtmc: Add ioctl for vendor specific write

2018-09-20 Thread Greg KH
On Wed, Sep 12, 2018 at 10:50:52AM +0200, Guido Kiener wrote:
> +/*
> + * usbtmc_message->flags:
> + */
> +#define USBTMC_FLAG_ASYNC0x0001
> +#define USBTMC_FLAG_APPEND   0x0002
> +
> +struct usbtmc_message {
> + __u32 transfer_size; /* size of bytes to transfer */
> + __u32 transferred; /* size of received/written bytes */
> + __u32 flags; /* bit 0: 0 = synchronous; 1 = asynchronous */

endian?  Native or are these properly transferred to the hardware in the
correct way?

thanks,

greg k-h


Re: [PATCH v6 01/22] usb: usbtmc: Add ioctl for generic requests on control

2018-09-20 Thread Greg KH
On Wed, Sep 12, 2018 at 10:50:51AM +0200, Guido Kiener wrote:
> --- a/include/uapi/linux/usb/tmc.h
> +++ b/include/uapi/linux/usb/tmc.h
> @@ -4,6 +4,7 @@
>   * Copyright (C) 2008 Novell, Inc.
>   * Copyright (C) 2008 Greg Kroah-Hartman 
>   * Copyright (C) 2015 Dave Penkler 
> + * Copyright (C) 2018 IVI Foundation, Inc.
>   *
>   * This file holds USB constants defined by the USB Device Class
>   * and USB488 Subclass Definitions for Test and Measurement devices
> @@ -40,6 +41,19 @@
>  #define USBTMC488_REQUEST_GOTO_LOCAL 161
>  #define USBTMC488_REQUEST_LOCAL_LOCKOUT  162
>  
> +struct usbtmc_request {
> + __u8 bRequestType;
> + __u8 bRequest;
> + __u16 wValue;
> + __u16 wIndex;
> + __u16 wLength;
> +} __attribute__ ((packed));

This really is just 'struct usb_ctrlrequest', right?  That's already
defined in our uapi files.  Why not use that?

Bonus is, if you use that, you get the proper endian notation, which you
don't have here, which means this is broken on big endian machines :(

Try doing that, and fix up the endian issue.

thanks,

greg k-h


Re: [PATCHv2] usb: typec: Group all TCPCI/TCPM code together

2018-09-20 Thread Greg Kroah-Hartman
On Tue, Sep 11, 2018 at 05:51:36PM +0300, Heikki Krogerus wrote:
> On Mon, Sep 10, 2018 at 06:21:04AM -0700, Guenter Roeck wrote:
> > On 09/10/2018 04:58 AM, Heikki Krogerus wrote:
> > > Moving all the drivers that depend on the Port Controller
> > > Manager under a new directory drivers/usb/typec/tcpm/ and
> > > making Guenter Roeck the designated reviewer of that code.
> > > 
> > > Signed-off-by: Heikki Krogerus 
> > 
> > Acked-by: Guenter Roeck 
> 
> Thanks!
> 
> To avoid the little conflict this patch will cause, I'll resend it
> together with the other Type-C patches I've collected next week to
> Greg (assuming he does not pick them himself before that).
> 
> I have all the patches here:
> https://github.com/krohei/linux/commits/typec-next

Yes, please send all of the patches in the correct order as I am
confused as to what needs to be applied where at the moment.

thanks,

greg k-h


Re: [PATCH 2/2] USB: usbdevfs: restore warning for nonsensical flags

2018-09-20 Thread Greg KH
On Thu, Sep 06, 2018 at 11:34:04AM -0400, Alan Stern wrote:
> On Thu, 6 Sep 2018, Oliver Neukum wrote:
> 
> > On Mi, 2018-09-05 at 15:07 +0200, Greg KH wrote:
> > > On Wed, Sep 05, 2018 at 03:02:48PM +0200, Oliver Neukum wrote:
> > > > On Mi, 2018-09-05 at 14:19 +0200, Greg KH wrote:
> > > > > On Wed, Sep 05, 2018 at 12:07:03PM +0200, Oliver Neukum wrote:
> > 
> > > > > > +   if (!allow_short && uurb->flags & USBDEVFS_URB_SHORT_NOT_OK)
> > > > > > +   dev_warn(>dev->dev, "Requested nonsensical 
> > > > > > USBDEVFS_URB_SHORT_NOT_OK.\n");
> > > > > > +   if (!allow_zero && uurb->flags & USBDEVFS_URB_ZERO_PACKET)
> > > > > > +   dev_warn(>dev->dev, "Requested nonsensical 
> > > > > > USBDEVFS_URB_ZERO_PACKET.\n");
> > > > > 
> > > > > We should not make it trivial for userspace to spam the kernel log if 
> > > > > at
> > > > > all possible.  Returning an error is probably the better thing to do
> > > > > here, not just silently fix it up or ignore it.
> > > > 
> > > > That means a change in the API in a way that makes orking systems fail.
> > > 
> > > Ah, good point.
> > 
> > Well, but do we want to do this in the next major release even if we
> > cannot do it in a stable release?
> > 
> > >   I guess they were hitting the same dev_WARN() messages
> > > today anyway, right?
> > 
> > Yes. And for a kernel problem you really want the stack traces.
> > Still, that does not tell us that we want to print a message if
> > user space messes up. So dev_warn() or nothing?
> 
> An alternative is for usbfs to silently fix the flags when they are
> wrong.  Would that be any better?

Probably not.  I'll take the original patches now and see if there is
any complaints by users.

thanks,

greg k-h


Re: [PATCH 01/10] usb: xhci-mtk: resume USB3 roothub first

2018-09-20 Thread Greg KH
On Mon, Sep 17, 2018 at 10:35:46AM +0300, Mathias Nyman wrote:
> On 14.09.2018 16:27, Greg KH wrote:
> > On Thu, Sep 13, 2018 at 03:23:54PM +0300, Mathias Nyman wrote:
> > > From: Chunfeng Yun 
> > > 
> > > Give USB3 devices a better chance to enumerate at USB3 speeds if
> > > they are connected to a suspended host.
> > > Porting from "671ffdff5b13 xhci: resume USB 3 roothub first"
> > > 
> > > Signed-off-by: Chunfeng Yun 
> > > Signed-off-by: Mathias Nyman 
> > > ---
> > >   drivers/usb/host/xhci-mtk.c | 4 ++--
> > >   1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > Isn't this a bugfix for 4.19-final?  And maybe for stable?
> > 
> 
> This was part of a 6 patch series that mostly contained mediatek
> bandwidth scheduling improvements.
> 
> But I agree, this first one could go to 4.19 with stable flag.

Ok, can you redo this whole series, and the 4.19-final series, so we get
these all straightened out as to which patch goes where, and resend?

I've dropped all of your pending patches from my queue now.

thanks,

greg k-h


Re: [PATCH 1/3] usb: xhci: tegra: Firmware header is little endian

2018-09-20 Thread Greg KH
On Mon, Sep 17, 2018 at 08:40:44AM +0200, Thierry Reding wrote:
> On Fri, Sep 14, 2018 at 03:01:22PM +0200, Greg KH wrote:
> > On Fri, Sep 14, 2018 at 03:33:29PM +0300, Mathias Nyman wrote:
> > > From: Thierry Reding 
> > > 
> > > The XUSB firmware header is in little endian byte order, so make the
> > > fields __le32 and __le16 instead of u32 and u16 to avoid warnings from
> > > sparse when the fields are used with the endian-aware __le32_to_cpu()
> > > and __le16_to_cpu() accessors, respectively.
> > 
> > This isn't a "bug" in that no code is changed, so why is it needed for
> > 4.19-final?
> > 
> > Shouldn't this be fine to merge in 4.20-rc1?
> 
> Yeah, I don't think there's a need to rush this. It's only to fix a
> warning from sparse, but it shouldn't impact any code since the code
> itself already properly parses the firmware in little endian byte
> order.

Thanks for confirming.  Mathias, I'll wait for you to resend this as
part of a 4.20-rc1 submission.

thanks,

greg k-h


Re: [PATCH 2/3] xhci: Avoid USB autosuspend when resuming USB2 ports.

2018-09-20 Thread Greg KH
On Wed, Sep 19, 2018 at 10:54:45AM +0530, Anshuman Gupta wrote:
> On Mon, Sep 17, 2018 at 11:24:20AM +0300, Mathias Nyman wrote:
> > On 14.09.2018 16:00, Greg KH wrote:
> > > On Fri, Sep 14, 2018 at 03:33:30PM +0300, Mathias Nyman wrote:
> > > > From: Anshuman Gupta 
> > > > 
> > > > When USB bus host controller root hub resumes from autosuspend,
> > > > it immediately tries to enter auto-suspend, but there can be a
> > > > scenario when root hub is resuming its usb2 ports, in that particular
> > > > case USB host controller auto suspend fails since it is busy
> > > > to resuming its usb2 ports.
> > > > 
> > > > This makes multiple failed cycles of auto-suspend until all usb2
> > > > ports of host controller root hub do not resume.
> > > > 
> > > > This patch uses USB core framework usb_hcd_start_port_resume,
> > > > usb_hcd_end_port_resume API's in order to  autoresume/autosuspend
> > > > root hub properly.
> > > > 
> > > > Signed-off-by: Anshuman Gupta 
> > > > Signed-off-by: Mathias Nyman 
> > > 
> > > Not needed in stable?  Does this fix a specific commit?
> > > 
> > > thanks,
> > > 
> > > greg k-h
> > > 
> > 
> > This improves a bad initial design that prevented autosuspend by
> > returning -EBUSY in xhci_bus_suspend() if a usb2 port was resuming.
> > 
> > Instead increment usage count on the roothub to prevent pm from polling
> > xhci_bus_suspend(). This is also what EHCI does.
> > 
> > I'm not sure If this fixes a actual bug for Anshuman Gupta caused by
> > the -EBUSY polling,(4.19 +stable), or if this is just a improvement in
> > suspend/resume code for xhci (4.20).
> > 
> > Anshuman Gupta, any comments?
> This patch is not fixing any bug. 
> This patch provide improvement in runtime suspend/resume path of xhci.

Great, then it shouldn't go into 4.19-final :)

Mathias, can you redo this patch series and resend?

thanks,

greg k-h


Re: [PATCH] usb: dwc2: Disable all EP's on disconnect

2018-09-20 Thread Dan Carpenter
On Thu, Sep 20, 2018 at 10:21:26AM +, Minas Harutyunyan wrote:
> Hi Dan,
> 
> On 9/20/2018 1:49 PM, Dan Carpenter wrote:
> > is is obviously deliberate that we drop the other thread's lock and
> > then take it ourselves.  But I don't think that can be right at all.
> > How do we know that it's safe for the other thread to drop the lock?
> > 
> > There should at least be a long comment in front of the code explaining
> > why it's safe to steal the lock like this.
> 
> Please review patch version 2: "[PATCH v2] usb: dwc2: Disable all EP's 
> on disconnect"

These are automated emails from the kbuild bot.  I just review them and
forward them.  I'm not on the list.

I'm going to trust that you fixed it in an appropriate way.  :)

regards,
dan carpenter



Re: [PATCH] usb: dwc2: Disable all EP's on disconnect

2018-09-20 Thread Minas Harutyunyan
Hi Dan,

On 9/20/2018 1:49 PM, Dan Carpenter wrote:
> is is obviously deliberate that we drop the other thread's lock and
> then take it ourselves.  But I don't think that can be right at all.
> How do we know that it's safe for the other thread to drop the lock?
> 
> There should at least be a long comment in front of the code explaining
> why it's safe to steal the lock like this.

Please review patch version 2: "[PATCH v2] usb: dwc2: Disable all EP's 
on disconnect"
Thanks,
Minas


Re: [PATCH] usb: dwc2: Disable all EP's on disconnect

2018-09-20 Thread Dan Carpenter
Hi Minas,

url:
https://github.com/0day-ci/linux/commits/Minas-Harutyunyan/usb-dwc2-Disable-all-EP-s-on-disconnect/20180919-104259
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next

smatch warnings:
drivers/usb/dwc2/gadget.c:4024 dwc2_hsotg_ep_disable() error: double unlock 
'spin_lock:>lock'
drivers/usb/dwc2/gadget.c:4350 dwc2_hsotg_udc_stop() error: double unlock 
'spin_lock:>lock'

# 
https://github.com/0day-ci/linux/commit/a4705c3fee2053e95791210eb435a04b665f6dc3
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout a4705c3fee2053e95791210eb435a04b665f6dc3
vim +4024 drivers/usb/dwc2/gadget.c

5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  3993  
8b9bc4608 drivers/usb/gadget/s3c-hsotg.c Lukasz Majewski2012-05-04  3994  
/**
1f91b4cc0 drivers/usb/dwc2/gadget.c  Felipe Balbi   2015-08-06  3995   
* dwc2_hsotg_ep_disable - disable given endpoint
8b9bc4608 drivers/usb/gadget/s3c-hsotg.c Lukasz Majewski2012-05-04  3996   
* @ep: The endpoint to disable.
8b9bc4608 drivers/usb/gadget/s3c-hsotg.c Lukasz Majewski2012-05-04  3997   
*/
1f91b4cc0 drivers/usb/dwc2/gadget.c  Felipe Balbi   2015-08-06  3998  
static int dwc2_hsotg_ep_disable(struct usb_ep *ep)
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  3999  {
1f91b4cc0 drivers/usb/dwc2/gadget.c  Felipe Balbi   2015-08-06  4000
struct dwc2_hsotg_ep *hs_ep = our_ep(ep);
941fcce4f drivers/usb/dwc2/gadget.c  Dinh Nguyen2014-11-11  4001
struct dwc2_hsotg *hsotg = hs_ep->parent;
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4002
int dir_in = hs_ep->dir_in;
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4003
int index = hs_ep->index;
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4004
unsigned long flags;
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4005
u32 epctrl_reg;
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4006
u32 ctrl;
a4705c3fe drivers/usb/dwc2/gadget.c  Minas Harutyunyan  2018-09-18  4007
int locked;
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4008  
1e0112937 drivers/usb/dwc2/gadget.c  Marek Szyprowski   2014-09-09  4009
dev_dbg(hsotg->dev, "%s(ep %p)\n", __func__, ep);
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4010  
c6f5c050e drivers/usb/dwc2/gadget.c  Mian Yousaf Kaukab 2015-01-09  4011
if (ep == >eps_out[0]->ep) {
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4012
dev_err(hsotg->dev, "%s: called for ep0\n", __func__);
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4013
return -EINVAL;
9b481092c drivers/usb/dwc2/gadget.c  John Stultz2017-10-23  4014
}
9b481092c drivers/usb/dwc2/gadget.c  John Stultz2017-10-23  4015  
9b481092c drivers/usb/dwc2/gadget.c  John Stultz2017-10-23  4016
if (hsotg->op_state != OTG_STATE_B_PERIPHERAL) {
9b481092c drivers/usb/dwc2/gadget.c  John Stultz2017-10-23  4017
dev_err(hsotg->dev, "%s: called in host mode?\n", __func__);
9b481092c drivers/usb/dwc2/gadget.c  John Stultz2017-10-23  4018
return -EINVAL;
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4019
}
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4020  
94cb8fd63 drivers/usb/gadget/s3c-hsotg.c Lukasz Majewski2012-05-04  4021
epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index);
5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4022  
a4705c3fe drivers/usb/dwc2/gadget.c  Minas Harutyunyan  2018-09-18  4023
locked = spin_trylock(>lock);
a4705c3fe drivers/usb/dwc2/gadget.c  Minas Harutyunyan  2018-09-18 @4024
spin_unlock(>lock);
5ad1d3160 drivers/usb/gadget/s3c-hsotg.c Lukasz Majewski2012-06-14  4025
spin_lock_irqsave(>lock, flags);


This is obviously deliberate that we drop the other thread's lock and
then take it ourselves.  But I don't think that can be right at all.
How do we know that it's safe for the other thread to drop the lock?

There should at least be a long comment in front of the code explaining
why it's safe to steal the lock like this.


5b7d70c6d drivers/usb/gadget/s3c-hsotg.c Ben Dooks  2009-06-02  4026  
f25c42b8d drivers/usb/dwc2/gadget.c  Gevorg Sahakyan2018-07-26  4027
ctrl = dwc2_readl(hsotg, epctrl_reg);
a4f827714 drivers/usb/dwc2/gadget.c  Vahram Aharonyan   2016-11-14  4028  
a4f827714 drivers/usb/dwc2/gadget.c  Vahram Aharonyan   2016-11-14  4029
if (ctrl & DXEPCTL_EPENA)
a4f827714 drivers/usb/dwc2/gadget.c  Vahram Aharonyan   2016-11-14  4030
dwc2_hsotg_ep_stop_xfr(hsotg, hs_ep);
a4f827714 drivers/usb/dwc2/gadget.c 

Embedded USB Debug

2018-09-20 Thread Muni Sekhar
Hi All,

Can someone clarify me on the Embedded USB Debug(EUD):

What is Embedded USB Debug(EUD)?
What Embedded USB Debug(EUD) is going to be used for?
Does Linux main tree has any drivers to support this?

-- 
Thanks,
Sekhar


Re: usb typec not doing handling in-kernel

2018-09-20 Thread Heiko Stuebner
Hi Guenter,

Am Montag, 13. August 2018, 14:29:15 CEST schrieb Guenter Roeck:
> On 08/13/2018 03:36 AM, Heiko Stuebner wrote:
> > Hi,
> > 
> > I'm currently trying to wrap my head around the new typec subsystem and
> > also how to do it correctly on Rockchip rk3399 devices.
> > 
> > The issue (and Guenter might know quite a bit about that) is that on
> > ChromeOS devices the embedded controller hides the whole tcpm/vdm
> > logic from the operating system and just provides a custom interface to
> > query things like cable state, display-port hotplug status and so on.
> > 
> > So right now the rk3399-typec-phy uses that extcon-based interface to
> > get all status changes but that of course leaves out all systems directly
> > talking to a fusb302. I did a small drawing to showcase that:
> > 
> > ---
> > | typec-phy || extcon-cros-ec |\
> > --- \
> >   |\  \
> > -  \ --   \ ---
> > |  cdn-dp   |   \| ?  |-| fusb302 |
> > --- ---
> > 
> > So to bring everything on the same page, I guess the cros-ec extcon
> > (drivers/extcon/extcon-usbc-cros-ec.c) should somehow use the typec
> > functions instead of implementing an extcon? But from reading into the
> > typec code, it somehow looks like the typec framework expects to be in
> > control of things like altmode negotiations, or am I misreading something?
> > 
> I used to have a patch for the cros-ec extcon driver which ties it into the
> typec subsystem. Let me see if I can dig it up.

were your archeological skills working in finding said old patch?

Thanks
Heiko