Re: [PATCH] usb: gadget: uvc: Missing files for configfs interface

2017-03-31 Thread Petr Cvek
Dne 31.3.2017 v 11:01 Laurent Pinchart napsal(a):
> Hi Felipe and Petr,
> 
> On Tuesday 28 Mar 2017 16:48:46 Felipe Balbi wrote:
>> Petr Cvek  writes:
>>> Dne 7.3.2017 v 06:58 Laurent Pinchart napsal(a):
 On Tuesday 07 Mar 2017 00:57:20 Petr Cvek wrote:
> Commit 76e0da34c7ce ("usb-gadget/uvc: use per-attribute show and store
> methods") caused a stringification of an undefined macro argument
> "aname", so three UVC parameters (streaming_interval,
> streaming_maxpacket and streaming_maxburst) were named "aname".
>
> Add the definition of "aname" to the main macro and name the filenames
> as originaly intended.

 Why don't you just

 - UVC_ATTR(f_uvc_opts_, cname, aname)
 + UVC_ATTR(f_uvc_opts_, cname, cname)

 in the definition of the UVCG_OPTS_ATTR() macro ?
>>>
>>> Hi,
>>>
>>> In a fact I did it for my first testing version. But then I realized
>>> two things. First one is that someone may want to rename these three
>>> files (now or in the future). The second one is that this bug was
>>> caused by original author, who probably assumed the UVCG_OPTS_ATTR
>>> macro had "aname" argument as others UVCG_* macros and didn't check. I
>>> assumed that too and only after I saw three "aname" files with the
>>> same path I realized where is the problem.
>>>
>>> So it's more like a human error prone type of a code. But if you think
>>> "cname" is enough I can send PATCH v2.
> 
> I think it would be, otherwise we end up passing the same argument twice, 
> which seems a bit useless to me. If we ever need to rename those files we can 
> always change the code later.

... or if the variables, which need to be renamed (and userapi filenames to be 
kept).

> 
> It's no big deal, but I have a preference for my proposal.
> 

Any way I've sent your suggested version, you can choose whichever you like ;-).

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


[PATCH v2] usb: gadget: uvc: Missing files for configfs interface

2017-03-31 Thread Petr Cvek
Commit 76e0da34c7ce ("usb-gadget/uvc: use per-attribute show and store
methods") caused a stringification of an undefined macro argument "aname",
so three UVC parameters (streaming_interval, streaming_maxpacket and
streaming_maxburst) were named "aname".

Fix the definition to use "cname", name of variables.

Signed-off-by: Petr Cvek 
---
 drivers/usb/gadget/function/uvc_configfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/uvc_configfs.c 
b/drivers/usb/gadget/function/uvc_configfs.c
index 4e037d2a7a60..5ce2ef324346 100644
--- a/drivers/usb/gadget/function/uvc_configfs.c
+++ b/drivers/usb/gadget/function/uvc_configfs.c
@@ -2168,7 +2168,7 @@ end:  
\
return ret; \
 }  \
\
-UVC_ATTR(f_uvc_opts_, cname, aname)
+UVC_ATTR(f_uvc_opts_, cname, cname)
 
 #define identity_conv(x) (x)
 
-- 
2.11.0

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


[PATCH] usb: gadget: mv_u3d: fix error handling in mv_u3d_probe()

2017-03-31 Thread Alexey Khoroshilov
There are several inconsistencies in the error handling code.
1. If clk_get() fails, it goes to clk_put().
2. If pdata->phy_init() fails, it does not disable u3d->clk.
3. In case of failure after stopping u3d, it does pdata->phy_deinit() 
   and clk_disable(u3d->clk) twice.
4. It ignores failures in clk_enable().

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/usb/gadget/udc/mv_u3d_core.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c 
b/drivers/usb/gadget/udc/mv_u3d_core.c
index d365449a295a..772049afe166 100644
--- a/drivers/usb/gadget/udc/mv_u3d_core.c
+++ b/drivers/usb/gadget/udc/mv_u3d_core.c
@@ -1835,13 +1835,18 @@ static int mv_u3d_probe(struct platform_device *dev)
}
 
/* we will access controller register, so enable the u3d controller */
-   clk_enable(u3d->clk);
+   retval = clk_enable(u3d->clk);
+   if (retval) {
+   dev_err(&dev->dev, "clk_enable error %d\n", retval);
+   goto err_u3d_enable;
+   }
 
if (pdata->phy_init) {
retval = pdata->phy_init(u3d->phy_regs);
if (retval) {
dev_err(&dev->dev, "init phy error %d\n", retval);
-   goto err_u3d_enable;
+   clk_disable(u3d->clk);
+   goto err_phy_init;
}
}
 
@@ -1974,15 +1979,13 @@ static int mv_u3d_probe(struct platform_device *dev)
dma_free_coherent(&dev->dev, u3d->ep_context_size,
u3d->ep_context, u3d->ep_context_dma);
 err_alloc_ep_context:
-   if (pdata->phy_deinit)
-   pdata->phy_deinit(u3d->phy_regs);
-   clk_disable(u3d->clk);
+err_phy_init:
 err_u3d_enable:
iounmap(u3d->cap_regs);
 err_map_cap_regs:
 err_get_cap_regs:
-err_get_clk:
clk_put(u3d->clk);
+err_get_clk:
kfree(u3d);
 err_alloc_private:
 err_pdata:
-- 
2.7.4

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


Re: [PATCH v6 00/15] Replace PCI pool by DMA pool API

2017-03-31 Thread Romain Perier
ping


Le 19/03/2017 à 18:03, Romain Perier a écrit :
> The current PCI pool API are simple macro functions direct expanded to
> the appropriate dma pool functions. The prototypes are almost the same
> and semantically, they are very similar. I propose to use the DMA pool
> API directly and get rid of the old API.
>
> This set of patches, replaces the old API by the dma pool API
> and remove the defines.
>
> Changes in v6:
> - Fixed an issue reported by kbuild test robot about changes in DAC960
> - Removed patches 15/19,16/19,17/19,18/19. They have been merged by Greg
> - Added Acked-by Tags
>
> Changes in v5:
> - Re-worded the cover letter (remove sentence about checkpatch.pl)
> - Rebased series onto next-20170308
> - Fix typos in commit message
> - Added Acked-by Tags
>
> Changes in v4:
> - Rebased series onto next-20170301
> - Removed patch 20/20: checks done by checkpath.pl, no longer required.
>   Thanks to Peter and Joe for their feedbacks.
> - Added Reviewed-by tags
>
> Changes in v3:
> - Rebased series onto next-20170224
> - Fix checkpath.pl reports for patch 11/20 and patch 12/20
> - Remove prefix RFC
> Changes in v2:
> - Introduced patch 18/20
> - Fixed cosmetic changes: spaces before brace, live over 80 characters
> - Removed some of the check for NULL pointers before calling dma_pool_destroy
> - Improved the regexp in checkpatch for pci_pool, thanks to Joe Perches
> - Added Tested-by and Acked-by tags
>
> Romain Perier (15):
>   block: DAC960: Replace PCI pool old API
>   dmaengine: pch_dma: Replace PCI pool old API
>   IB/mthca: Replace PCI pool old API
>   net: e100: Replace PCI pool old API
>   mlx4: Replace PCI pool old API
>   mlx5: Replace PCI pool old API
>   wireless: ipw2200: Replace PCI pool old API
>   scsi: be2iscsi: Replace PCI pool old API
>   scsi: csiostor: Replace PCI pool old API
>   scsi: lpfc: Replace PCI pool old API
>   scsi: megaraid: Replace PCI pool old API
>   scsi: mpt3sas: Replace PCI pool old API
>   scsi: mvsas: Replace PCI pool old API
>   scsi: pmcraid: Replace PCI pool old API
>   PCI: Remove PCI pool macro functions
>
>  drivers/block/DAC960.c|  38 +
>  drivers/block/DAC960.h|   4 +-
>  drivers/dma/pch_dma.c |  12 +--
>  drivers/infiniband/hw/mthca/mthca_av.c|  10 +--
>  drivers/infiniband/hw/mthca/mthca_cmd.c   |   8 +-
>  drivers/infiniband/hw/mthca/mthca_dev.h   |   4 +-
>  drivers/net/ethernet/intel/e100.c |  12 +--
>  drivers/net/ethernet/mellanox/mlx4/cmd.c  |  10 +--
>  drivers/net/ethernet/mellanox/mlx4/mlx4.h |   2 +-
>  drivers/net/ethernet/mellanox/mlx5/core/cmd.c |  11 +--
>  drivers/net/wireless/intel/ipw2x00/ipw2200.c  |  13 ++--
>  drivers/scsi/be2iscsi/be_iscsi.c  |   6 +-
>  drivers/scsi/be2iscsi/be_main.c   |   6 +-
>  drivers/scsi/be2iscsi/be_main.h   |   2 +-
>  drivers/scsi/csiostor/csio_hw.h   |   2 +-
>  drivers/scsi/csiostor/csio_init.c |  11 +--
>  drivers/scsi/csiostor/csio_scsi.c |   6 +-
>  drivers/scsi/lpfc/lpfc.h  |  14 ++--
>  drivers/scsi/lpfc/lpfc_init.c |  16 ++--
>  drivers/scsi/lpfc/lpfc_mem.c  | 106 
> +-
>  drivers/scsi/lpfc/lpfc_nvme.c |   6 +-
>  drivers/scsi/lpfc/lpfc_nvmet.c|   4 +-
>  drivers/scsi/lpfc/lpfc_scsi.c |  12 +--
>  drivers/scsi/megaraid/megaraid_mbox.c |  33 
>  drivers/scsi/megaraid/megaraid_mm.c   |  32 
>  drivers/scsi/megaraid/megaraid_sas_base.c |  29 +++
>  drivers/scsi/megaraid/megaraid_sas_fusion.c   |  66 
>  drivers/scsi/mpt3sas/mpt3sas_base.c   |  73 +-
>  drivers/scsi/mvsas/mv_init.c  |   6 +-
>  drivers/scsi/mvsas/mv_sas.c   |   6 +-
>  drivers/scsi/pmcraid.c|  10 +--
>  drivers/scsi/pmcraid.h|   2 +-
>  include/linux/mlx5/driver.h   |   2 +-
>  include/linux/pci.h   |   9 ---
>  34 files changed, 280 insertions(+), 303 deletions(-)
>

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


Re: [PATCH 02/22] docs-rst: convert usb docbooks to ReST

2017-03-31 Thread Jonathan Corbet
On Thu, 30 Mar 2017 11:20:14 +0200
Markus Heiser  wrote:

> @Jon: what do you think about a bulk conversion?

I'm a bit leery of it, to tell the truth.  We're trying to create a
better set of kernel docs, and I'm far from convinced that dumping a
bunch of unloved stuff there in a mechanical way will get us there.

Each of those docs needs to be looked at, and, first of all, we need to
decide whether it's worth keeping or not.  Nobody wants to delete docs,
but old and unmaintained stuff doesn't help our users, IMO.  For the
stuff we want to keep, we need to look at how it fits into the new
scheme, probably split it up, etc.

It's a lot slower, but we've been getting rid of 3-6 template files in
each of the last few cycles, so we are getting there.  I don't think we
need to just give up on the rest.

Thanks,

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


Re: [PATCH 22/22] usb: document that URB transfer_buffer should be aligned

2017-03-31 Thread Alan Stern
On Thu, 30 Mar 2017, Oliver Neukum wrote:

> Am Donnerstag, den 30.03.2017, 11:55 -0400 schrieb Alan Stern:
> > 
> > I'm pretty sure that usb-storage does not do this, at least, not when 
> > operating in its normal Bulk-Only-Transport mode.  It never tries to 
> > read the results of an earlier transfer after carrying out a later 
> > transfer to any part of the same buffer.
> 
> The storage driver takes buffers as the block layer (or sg) provide
> them, does it not?

Yes.  But it does not read the data from an earlier transfer after 
carrying out a later transfer on the same buffer.

The only possible example would be if the sense buffer for a command 
occupied part of the same block as the data buffer.  But this can't 
happen, because the sense buffer is allocated separately by its own 
kzalloc_node() call in scsi_init_request().

Alan Stern

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


[PATCH 2/3] usb: dwc3: debugfs: return strings that match tracepoints

2017-03-31 Thread Felipe Balbi
In order to improve usability a tiny bit, we will return strings that
match what our tracepoints return.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/debugfs.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index d77eac7b239d..3606c28be580 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -650,13 +650,13 @@ static inline const char *dwc3_trb_type_string(struct 
dwc3_trb *trb)
case DWC3_TRBCTL_NORMAL:
return "normal";
case DWC3_TRBCTL_CONTROL_SETUP:
-   return "control-setup";
+   return "setup";
case DWC3_TRBCTL_CONTROL_STATUS2:
-   return "control-status2";
+   return "status2";
case DWC3_TRBCTL_CONTROL_STATUS3:
-   return "control-status3";
+   return "status3";
case DWC3_TRBCTL_CONTROL_DATA:
-   return "control-data";
+   return "data";
case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
return "isoc-first";
case DWC3_TRBCTL_ISOCHRONOUS:
-- 
2.11.0.295.gd7dffce1ce

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


[PATCH 3/3] usb: dwc3: expose dwc3_trb_type_string()

2017-03-31 Thread Felipe Balbi
That helper can be used from our tracepoint interface with very minor
edits. Let's do so.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/debug.h   | 28 
 drivers/usb/dwc3/debugfs.c | 27 ++-
 drivers/usb/dwc3/trace.h   | 31 +--
 3 files changed, 31 insertions(+), 55 deletions(-)

diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index eeed4ffd8131..cb2d8d3f7f3d 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -124,6 +124,34 @@ dwc3_gadget_link_string(enum dwc3_link_state link_state)
}
 }
 
+/**
+ * dwc3_trb_type_string - returns TRB type as a string
+ * @type: the type of the TRB
+ */
+static inline const char *dwc3_trb_type_string(unsigned int type)
+{
+   switch (type) {
+   case DWC3_TRBCTL_NORMAL:
+   return "normal";
+   case DWC3_TRBCTL_CONTROL_SETUP:
+   return "setup";
+   case DWC3_TRBCTL_CONTROL_STATUS2:
+   return "status2";
+   case DWC3_TRBCTL_CONTROL_STATUS3:
+   return "status3";
+   case DWC3_TRBCTL_CONTROL_DATA:
+   return "data";
+   case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
+   return "isoc-first";
+   case DWC3_TRBCTL_ISOCHRONOUS:
+   return "isoc";
+   case DWC3_TRBCTL_LINK_TRB:
+   return "link";
+   default:
+   return "UNKNOWN";
+   }
+}
+
 static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
 {
switch (state) {
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 3606c28be580..b53ca3b0171a 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -644,30 +644,6 @@ static int dwc3_ep_transfer_type_show(struct seq_file *s, 
void *unused)
return 0;
 }
 
-static inline const char *dwc3_trb_type_string(struct dwc3_trb *trb)
-{
-   switch (DWC3_TRBCTL_TYPE(trb->ctrl)) {
-   case DWC3_TRBCTL_NORMAL:
-   return "normal";
-   case DWC3_TRBCTL_CONTROL_SETUP:
-   return "setup";
-   case DWC3_TRBCTL_CONTROL_STATUS2:
-   return "status2";
-   case DWC3_TRBCTL_CONTROL_STATUS3:
-   return "status3";
-   case DWC3_TRBCTL_CONTROL_DATA:
-   return "data";
-   case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
-   return "isoc-first";
-   case DWC3_TRBCTL_ISOCHRONOUS:
-   return "isoc";
-   case DWC3_TRBCTL_LINK_TRB:
-   return "link";
-   default:
-   return "UNKNOWN";
-   }
-}
-
 static int dwc3_ep_trb_ring_show(struct seq_file *s, void *unused)
 {
struct dwc3_ep  *dep = s->private;
@@ -688,10 +664,11 @@ static int dwc3_ep_trb_ring_show(struct seq_file *s, void 
*unused)
 
for (i = 0; i < DWC3_TRB_NUM; i++) {
struct dwc3_trb *trb = &dep->trb_pool[i];
+   unsigned int type = DWC3_TRBCTL_TYPE(trb->ctrl);
 
seq_printf(s, "%08x%08x,%d,%s,%d,%d,%d,%d,%d,%d\n",
trb->bph, trb->bpl, trb->size,
-   dwc3_trb_type_string(trb),
+   dwc3_trb_type_string(type),
!!(trb->ctrl & DWC3_TRB_CTRL_IOC),
!!(trb->ctrl & DWC3_TRB_CTRL_ISP_IMI),
!!(trb->ctrl & DWC3_TRB_CTRL_CSP),
diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
index fd5fc91fa9a0..f1bd444d22a3 100644
--- a/drivers/usb/dwc3/trace.h
+++ b/drivers/usb/dwc3/trace.h
@@ -273,36 +273,7 @@ DECLARE_EVENT_CLASS(dwc3_log_trb,
__entry->ctrl & DWC3_TRB_CTRL_CSP ? 'S' : 's',
__entry->ctrl & DWC3_TRB_CTRL_ISP_IMI ? 'S' : 's',
__entry->ctrl & DWC3_TRB_CTRL_IOC ? 'C' : 'c',
-   ({char *s;
-   switch (__entry->ctrl & 0x3f0) {
-   case DWC3_TRBCTL_NORMAL:
-   s = "normal";
-   break;
-   case DWC3_TRBCTL_CONTROL_SETUP:
-   s = "setup";
-   break;
-   case DWC3_TRBCTL_CONTROL_STATUS2:
-   s = "status2";
-   break;
-   case DWC3_TRBCTL_CONTROL_STATUS3:
-   s = "status3";
-   break;
-   case DWC3_TRBCTL_CONTROL_DATA:
-   s = "data";
-   break;
-   case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
-   s = "isoc-first";
-   break;
-   case DWC3_TRBCTL_ISOCHRONOUS:
-   s = "isoc";
-   break;
-   case DWC3_TRBCTL_LINK_TRB:
-   s = "link";
-   break;
-   default:
-   s = "UNKNOWN";
-   break;
-   } s; })
+ 

[PATCH 1/3] usb: dwc3: debugfs: make use of dwc3_gadget_link_string()

2017-03-31 Thread Felipe Balbi
Instead of redecoding link state into a string, use our helper.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/debugfs.c | 47 +-
 1 file changed, 1 insertion(+), 46 deletions(-)

diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 2cda6e0dd7fa..d77eac7b239d 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -446,52 +446,7 @@ static int dwc3_link_state_show(struct seq_file *s, void 
*unused)
state = DWC3_DSTS_USBLNKST(reg);
spin_unlock_irqrestore(&dwc->lock, flags);
 
-   switch (state) {
-   case DWC3_LINK_STATE_U0:
-   seq_printf(s, "U0\n");
-   break;
-   case DWC3_LINK_STATE_U1:
-   seq_printf(s, "U1\n");
-   break;
-   case DWC3_LINK_STATE_U2:
-   seq_printf(s, "U2\n");
-   break;
-   case DWC3_LINK_STATE_U3:
-   seq_printf(s, "U3\n");
-   break;
-   case DWC3_LINK_STATE_SS_DIS:
-   seq_printf(s, "SS.Disabled\n");
-   break;
-   case DWC3_LINK_STATE_RX_DET:
-   seq_printf(s, "Rx.Detect\n");
-   break;
-   case DWC3_LINK_STATE_SS_INACT:
-   seq_printf(s, "SS.Inactive\n");
-   break;
-   case DWC3_LINK_STATE_POLL:
-   seq_printf(s, "Poll\n");
-   break;
-   case DWC3_LINK_STATE_RECOV:
-   seq_printf(s, "Recovery\n");
-   break;
-   case DWC3_LINK_STATE_HRESET:
-   seq_printf(s, "HRESET\n");
-   break;
-   case DWC3_LINK_STATE_CMPLY:
-   seq_printf(s, "Compliance\n");
-   break;
-   case DWC3_LINK_STATE_LPBK:
-   seq_printf(s, "Loopback\n");
-   break;
-   case DWC3_LINK_STATE_RESET:
-   seq_printf(s, "Reset\n");
-   break;
-   case DWC3_LINK_STATE_RESUME:
-   seq_printf(s, "Resume\n");
-   break;
-   default:
-   seq_printf(s, "UNKNOWN %d\n", state);
-   }
+   seq_printf(s, "%s\n", dwc3_gadget_link_string(state));
 
return 0;
 }
-- 
2.11.0.295.gd7dffce1ce

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


Re: [PATCHv3] net: usbnet: support 64bit stats in qmi_wwan driver

2017-03-31 Thread Bjørn Mork


On March 31, 2017 3:27:59 PM CEST, Greg Ungerer  wrote:
>On 31/03/17 18:48, Bjørn Mork wrote:
>
>>> +void usbnet_get_stats64(struct net_device *net, struct
>rtnl_link_stats64 *stats)
>>> +{
>>> +   struct usbnet *dev = netdev_priv(net);
>>> +   unsigned int start;
>>> +   int cpu;
>>> +
>>> +   netdev_stats_to_stats64(stats, &net->stats);
>>> +
>>> +   for_each_possible_cpu(cpu) {
>>> +   struct pcpu_sw_netstats *stats64;
>>> +   u64 rx_packets, rx_bytes;
>>> +   u64 tx_packets, tx_bytes;
>>> +
>>> +   stats64 = per_cpu_ptr(dev->stats64, cpu);
>>> +
>>> +   do {
>>> +   start = u64_stats_fetch_begin_irq(&stats64->syncp);
>>> +   rx_packets = stats64->rx_packets;
>>> +   rx_bytes = stats64->rx_bytes;
>>> +   tx_packets = stats64->tx_packets;
>>> +   tx_bytes = stats64->tx_bytes;
>>> +   } while (u64_stats_fetch_retry_irq(&stats64->syncp, start));
>>> +
>>> +   stats->rx_packets += rx_packets;
>>> +   stats->rx_bytes += rx_bytes;
>>> +   stats->tx_packets += tx_packets;
>>> +   stats->tx_bytes += tx_bytes;
>>> +   }
>>> +}
>>
>> So we only count packets and bytes.  No errors.  Why?
>
>All stats are counted. That call to netdev_stats_to_stats64() transfers
>all other stats struct fields (errors, etc) to the stats64 struct.
>No error counts are lost (though they are only stored as 32bits values
>on 32bit machines).


Ah, right. Thanks for explaining and sorry for being so slow. Then I have no 
objection to the patch as it is.


Bjørn

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


Re: [PATCHv3] net: usbnet: support 64bit stats in qmi_wwan driver

2017-03-31 Thread Greg Ungerer

Hi Oliver,

On 31/03/17 19:39, Oliver Neukum wrote:

Am Freitag, den 31.03.2017, 10:48 +0200 schrieb Bjørn Mork:

You get *all* the "0" line drivers for free, not only "qmi_wwan".  No
code changes needed, except for adding the single .ndo line to drivers
overriding the usbnet default net_device_ops. And even that only applies
to a few of them.  Most will be OK if you just change the usbnet
default.

I don't think the size of a complete series will be terrifying to
anyone.


It would really be nice to do that.
However, if you really don't want to do it, well you wrote
a patch. But I am afraid dropping the error count is not acceptable.


Of course dropping error counts would be, but that doesn't happen.

I will generate a patch that converts all usbnet users in one go.

Regards
Greg





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


Re: [PATCHv3] net: usbnet: support 64bit stats in qmi_wwan driver

2017-03-31 Thread Greg Ungerer

Hi Bjorn,

On 31/03/17 18:48, Bjørn Mork wrote:

Greg Ungerer  writes:

Add support for the net stats64 counters to the usbnet core and then to
the qmi_wwan driver.

This is a strait forward addition of 64bit counters for RX and TX packets
and byte counts. It is done in the same style as for the other net drivers
that support stats64.

The bulk of the change is to the usbnet core. Then it is trivial to use
that in the qmi_wwan.c driver. It would be very simple to extend this
support to other usbnet based drivers.


Sorry, but I am starting to have my doubts about this partial conversion
of the usbnet stats.  I don't have any problem with doing incremental
changes.  But in this case it means running duplicate code. And I see no
reasons to justify doing this incrementally.  As you say: It is very
simple to extend it to all usbnet drivers when the basic infrastructure
is in place.

You alreay do most of that work. So why not just update the other
drivers too, allowing us to drop the legacy counters?  Deleting code is
always good :)


Ok.



+void usbnet_get_stats64(struct net_device *net, struct rtnl_link_stats64 
*stats)
+{
+   struct usbnet *dev = netdev_priv(net);
+   unsigned int start;
+   int cpu;
+
+   netdev_stats_to_stats64(stats, &net->stats);
+
+   for_each_possible_cpu(cpu) {
+   struct pcpu_sw_netstats *stats64;
+   u64 rx_packets, rx_bytes;
+   u64 tx_packets, tx_bytes;
+
+   stats64 = per_cpu_ptr(dev->stats64, cpu);
+
+   do {
+   start = u64_stats_fetch_begin_irq(&stats64->syncp);
+   rx_packets = stats64->rx_packets;
+   rx_bytes = stats64->rx_bytes;
+   tx_packets = stats64->tx_packets;
+   tx_bytes = stats64->tx_bytes;
+   } while (u64_stats_fetch_retry_irq(&stats64->syncp, start));
+
+   stats->rx_packets += rx_packets;
+   stats->rx_bytes += rx_bytes;
+   stats->tx_packets += tx_packets;
+   stats->tx_bytes += tx_bytes;
+   }
+}


So we only count packets and bytes.  No errors.  Why?


All stats are counted. That call to netdev_stats_to_stats64() transfers
all other stats struct fields (errors, etc) to the stats64 struct.
No error counts are lost (though they are only stored as 32bits values
on 32bit machines).



@@ -1212,8 +1249,15 @@ static void tx_complete (struct urb *urb)
struct usbnet   *dev = entry->dev;

if (urb->status == 0) {
+   struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->stats64);
+
dev->net->stats.tx_packets += entry->packets;
dev->net->stats.tx_bytes += entry->length;
+
+   u64_stats_update_begin(&stats64->syncp);
+   stats64->tx_packets += entry->packets;
+   stats64->tx_bytes += entry->length;
+   u64_stats_update_end(&stats64->syncp);
} else {
dev->net->stats.tx_errors++;




This is one place where the old stats counted errors too.  But there are more:

bjorn@miraculix:/usr/local/src/git/linux$ git grep -E -- '->stats.*\+' 
drivers/net/usb/usbnet.c|grep -Ev '(bytes|packet)'
drivers/net/usb/usbnet.c:   dev->net->stats.rx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_length_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_over_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.tx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.tx_dropped++;


Personally, I'd rather have incorrect byte counters than losing these


Luckily we can have all values correct :-)



error counters. They are valuable debugging aids. I don't see why they
cannot be converted to 64bit stats right away.  Except that it makes the
amount of double accounting much more obvious...

Which is why I have landed on on a request to convert all the usbnet
drivers in one go.  There aren't that many of them, and even fewer
touching the stats outside of usbnet.c.  Among those few, none have more
than 6 lines currently touching "stats":

bjorn@miraculix:/usr/local/src/git/linux$ for f in `git grep -l -- 'usbnet_probe' 
drivers/net/usb/`; do grep -Hc -- '->stats' $f; done
drivers/net/usb/asix_devices.c:0
drivers/net/usb/ax88179_178a.c:0
drivers/net/usb/cdc_eem.c:1
drivers/net/usb/cdc_ether.c:0
drivers/net/usb/cdc_mbim.c:0
drivers/net/usb/cdc_ncm.c:4
drivers/net/usb/cdc_subset.c:0
drivers/net/usb/ch9200.c:0
drivers/net/usb/cx82310_eth.c:0
drivers/net/usb/dm9601.c:5
drivers/net/usb/gl620a.c:0
drivers/net/usb/huawei_cdc_ncm.c:0
drivers/net/usb/int51x1.c:0
drivers/net/

[RESEND PATCH v3 0/7] Platform driver support for 'amd5536udc' driver

2017-03-31 Thread Raviteja Garimella
Resending PATCH v3 after rebasing with testing/next branch in 
Felipe Balbi's git tree. Resolved few merge conflicts. 
Tested applying all patches. Patch 1/7 can be ignored since it's
already applied.

Changes in PATCH v3:
===
1. Updated bindings documentation and platform driver to add
   "brcm,iproc-udc" compatibility string.

2. Added a patch to replace references of struct pci_pool with
   struct dma_pool so that it is compatibile with non-pci drivers.

Changes in PATCH v2:
===
1. Updated bindings documentation:
   -- compatibility string for each supported SoC
   -- removed extcon node
   -- rename the file name to just iproc-udc.txt

2. Modified comptability strings in platform driver file
   to reflect the change made in 1.

3 Kconfig
   -- Resolved warnings shown by kbuild-test-robot  

The changes are being submitted as PATCH this time. Below are the
details of main changes with respect to previous RFC versions.

Changes in PATCH v1:
===
Patch 1/6 now splits the driver into amd5536udc_pci_.c (which
contains only the PCI device registration part), and amd5536udc.c
will still be driver that does the rest of UDC driver functionality.

Patch 2/6 renames amd5536udc.c to snps_udc_core.c.

The DT compatibilty string is changed to "brcm,iproc-snps-udc"
as per review comments for RFCv2. The driver and bindings
documentation is modified to reflect this.

This is RFC for the changes made as per the review comments made for
the previous version. I would like to know  if this approach (the way
the driver is split and the naming and all)looks good to be submitted.


Changes in RFC v2:
=
1. Split the driver into platform/pci specific drivers with a core driver
   file that handles the common driver routines that are exported.

2. Split the driver into number of patches as suggested in previous
   review comments.

3. Added the devicetree bindings documentation for Synopsys platform
   driver.

Introduction (RFC v1):
=
This patch adds platform device support to the existing 'amd5536udc'
driver.

The UDC is based on Synopsys Designware core USB (2.0) Device controller
IP.

The driver so far supports UDCs that are a part of AMD southbridge
and is connected through PCI bus.

The same driver can be used with UDCs that are integrated into SoCs
like Broadcom's Northstar2/Cygnus platforms by adding platform device
suooprt.

This patch contains all the changes that were required to get the driver
functional on Broadcom's Northstar2 platform. 

This is a request for comments from maintainers/others regarding approach
on whether to have 2 different drivers (one each for AMD and Broadcom)
with a common library (3 files in total), or have a single driver like
it's done in this patch and have the driver filename changed to some
common name based on ther underlying IP, like snps_udc.c.

Below are the main changes done:

1. Added OF based platform device registration -- so that the driver gets
   probed based on the device tree entry. Like wise, remove routine and
   platform PM ops are supported.

2. Modified debug prints to be compatible with both pci and platform
   devices.

3. Added members to 'struct udc' in header file for extcon and phy support.
   This is required if the UDC is connected to a Dual Role Device Phy
   where the Phy can be configured to be in Device mode or Host mode based
   on the type of external cable that is connected to the port.
 
4. Added checks in udc connect/disconnect routines so as to return if the
   routine is already called.

5. Modified the arguments passed to dma_pool_create routine -- which
   expects struct device, whereas NULL is passed in the existing version.
 
6. Kconfig changes are done so that the driver now depends on either of
   CONFIG_OF or CONFIG_PCI. More description about the Synopsys IP is
   provided.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: snps_udc_v3

Raviteja Garimella (7):
  usb: gadget: udc: amd5536: split core and PCI layer
  UDC: Rename amd5536udc driver file based on IP
  UDC: make debug prints compatible with both pci and platform devices
  UDC: Provide correct arguments for 'dma_pool_create'
  UDC: Use struct dma_pool instead of pci_pool
  DT bindings documentation for Broadcom IPROC USB Device controller.
  UDC: Add Synopsys UDC Platform driver

 .../devicetree/bindings/usb/iproc-udc.txt  |   21 +
 drivers/usb/gadget/udc/Kconfig |   32 +
 drivers/usb/gadget/udc/Makefile|4 +-
 drivers/usb/gadget/udc/amd5536udc.c| 3409 
 drivers/usb/gadget/udc/amd5536udc.h|   54 +-
 drivers/usb/gadget/udc/amd5536udc_pci.c|  218 ++
 drivers/usb/gadget/udc/snps_udc_core.c | 3235 +++
 drivers/usb/gadget/udc/snps_udc_plat.c |  344 ++
 8 files changed, 3906 insertions(+), 3411 deletions(-)
 create mode 100644 Documentation/devicet

Re: [PATCH v3 2/7] UDC: Rename amd5536udc driver file based on IP

2017-03-31 Thread Raviteja Garimella
Hi Felipe,

On Fri, Mar 31, 2017 at 3:19 PM, Felipe Balbi  wrote:
>
> Hi,
>
> Raviteja Garimella  writes:
>
>> This patch renames the amd5536udc.c that has the core driver
>> functionality of Synopsys UDC to snps_udc_core.c
>>
>> The symbols exported here can be used by any UDC driver that uses
>> the same Synopsys IP.
>>
>> Signed-off-by: Raviteja Garimella 
>
> unfortunately, this patch doesn't apply:
>
> Applying: UDC: Rename amd5536udc driver file based on IP
> error: corrupt patch at line 235
> Patch failed at 0001 UDC: Rename amd5536udc driver file based on IP
> The copy of the patch that failed is found in: .git/rebase-apply/patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".
>
> Can you rebase on testing/next and resend?

I rebased my patches against testing/next branch, resolved the merge conflicts.
Just resent the patches 2/7 to 7/7. Please use them. I verified they are getting
applied without issues now.

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


[RESEND PATCH v3 7/7] UDC: Add Synopsys UDC Platform driver

2017-03-31 Thread Raviteja Garimella
This patch adds platform driver support for Synopsys UDC.

A new driver file (snps_udc_plat.c) is created for this purpose
where the platform driver registration is done based on OF
node.

Currently, UDC integrated into Broadcom's iProc SoCs (Northstar2
and Cygnus) work with this driver.

New members are added to the UDC data structure for having platform
device support along with extcon and phy support.

Kconfig and Makefiles are modified to select platform driver for
compilation.

Signed-off-by: Raviteja Garimella 
---
 drivers/usb/gadget/udc/Kconfig |  16 +-
 drivers/usb/gadget/udc/Makefile|   1 +
 drivers/usb/gadget/udc/amd5536udc.h|  14 ++
 drivers/usb/gadget/udc/snps_udc_core.c |  54 --
 drivers/usb/gadget/udc/snps_udc_plat.c | 344 +
 5 files changed, 409 insertions(+), 20 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 707814d..b788caf 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -255,7 +255,7 @@ config USB_MV_U3D
  controller, which support super speed USB peripheral.
 
 config USB_SNP_CORE
-   depends on USB_AMD5536UDC
+   depends on (USB_AMD5536UDC || USB_SNP_UDC_PLAT)
tristate
help
  This enables core driver support for Synopsys USB 2.0 Device
@@ -268,6 +268,20 @@ config USB_SNP_CORE
  This IP is different to the High Speed OTG IP that can be enabled
  by selecting USB_DWC2 or USB_DWC3 options.
 
+config USB_SNP_UDC_PLAT
+   tristate "Synopsys USB 2.0 Device controller"
+   depends on (USB_GADGET && OF)
+   select USB_GADGET_DUALSPEED
+   select USB_SNP_CORE
+   default ARCH_BCM_IPROC
+   help
+ This adds Platform Device support for Synopsys Designware core
+ AHB subsystem USB2.0 Device Controller (UDC).
+
+ This driver works with UDCs integrated into Broadcom's Northstar2
+ and Cygnus SoCs.
+
+ If unsure, say N.
 #
 # Controllers available in both integrated and discrete versions
 #
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 4f4fd62..ea9e1c7 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -37,4 +37,5 @@ obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
 obj-$(CONFIG_USB_MV_U3D)   += mv_u3d_core.o
 obj-$(CONFIG_USB_GR_UDC)   += gr_udc.o
 obj-$(CONFIG_USB_GADGET_XILINX)+= udc-xilinx.o
+obj-$(CONFIG_USB_SNP_UDC_PLAT) += snps_udc_plat.o
 obj-$(CONFIG_USB_BDC_UDC)  += bdc/
diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index c252457..7884281 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -16,6 +16,7 @@
 /* debug control */
 /* #define UDC_VERBOSE */
 
+#include 
 #include 
 #include 
 
@@ -28,6 +29,9 @@
 #define UDC_HSA0_REV 1
 #define UDC_HSB1_REV 2
 
+/* Broadcom chip rev. */
+#define UDC_BCM_REV 10
+
 /*
  * SETUP usb commands
  * needed, because some SETUP's are handled in hw, but must be passed to
@@ -112,6 +116,7 @@
 #define UDC_DEVCTL_BRLEN_MASK  0x00ff
 #define UDC_DEVCTL_BRLEN_OFS   16
 
+#define UDC_DEVCTL_SRX_FLUSH   14
 #define UDC_DEVCTL_CSR_DONE13
 #define UDC_DEVCTL_DEVNAK  12
 #define UDC_DEVCTL_SD  10
@@ -564,7 +569,15 @@ struct udc {
u16 cur_intf;
u16 cur_alt;
 
+   /* for platform device and extcon support */
struct device   *dev;
+   struct phy  *udc_phy;
+   struct extcon_dev   *edev;
+   struct extcon_specific_cable_nb extcon_nb;
+   struct notifier_block   nb;
+   struct delayed_work drd_work;
+   struct workqueue_struct *drd_wq;
+   u32 conn_type;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -580,6 +593,7 @@ int udc_enable_dev_setup_interrupts(struct udc *dev);
 int udc_mask_unused_interrupts(struct udc *dev);
 irqreturn_t udc_irq(int irq, void *pdev);
 void gadget_release(struct device *pdev);
+void empty_req_queue(struct udc_ep *ep);
 void udc_basic_init(struct udc *dev);
 void free_dma_pools(struct udc *dev);
 int init_dma_pools(struct udc *dev);
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index d592f77..38a165d 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -41,7 +41,6 @@
 #include "amd5536udc.h"
 
 static void udc_tasklet_disconnect(unsigned long);
-static void empty_req_queue(struct udc_ep *);
 static void udc_setup_endpoints(struct udc *dev);
 static void udc_soft_reset(struct udc *dev);
 static struct udc_re

[RESEND PATCH v3 5/7] UDC: Use struct dma_pool instead of pci_pool

2017-03-31 Thread Raviteja Garimella
Using dma_pool instead of pci_pool will make snps_udc_core driver
to be compatible with non-pci platforms.

Signed-off-by: Raviteja Garimella 
---
 drivers/usb/gadget/udc/snps_udc_core.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 5ca8b7b..d592f77 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -543,7 +543,7 @@ udc_alloc_request(struct usb_ep *usbep, gfp_t gfp)
 
if (ep->dma) {
/* ep0 in requests are allocated from data pool here */
-   dma_desc = pci_pool_alloc(ep->dev->data_requests, gfp,
+   dma_desc = dma_pool_alloc(ep->dev->data_requests, gfp,
&req->td_phys);
if (!dma_desc) {
kfree(req);
@@ -582,7 +582,7 @@ static void udc_free_dma_chain(struct udc *dev, struct 
udc_request *req)
for (i = 1; i < req->chain_len; i++) {
td = phys_to_virt(addr);
addr_next = (dma_addr_t)td->next;
-   pci_pool_free(dev->data_requests, td, addr);
+   dma_pool_free(dev->data_requests, td, addr);
addr = addr_next;
}
 }
@@ -608,7 +608,7 @@ udc_free_request(struct usb_ep *usbep, struct usb_request 
*usbreq)
if (req->chain_len > 1)
udc_free_dma_chain(ep->dev, req);
 
-   pci_pool_free(ep->dev->data_requests, req->td_data,
+   dma_pool_free(ep->dev->data_requests, req->td_data,
req->td_phys);
}
kfree(req);
@@ -803,7 +803,7 @@ static int udc_create_dma_chain(
for (i = buf_len; i < bytes; i += buf_len) {
/* create or determine next desc. */
if (create_new_chain) {
-   td = pci_pool_alloc(ep->dev->data_requests,
+   td = dma_pool_alloc(ep->dev->data_requests,
gfp_flags, &dma_addr);
if (!td)
return -ENOMEM;
-- 
2.1.0

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


[RESEND PATCH v3 6/7] DT bindings documentation for Broadcom IPROC USB Device controller.

2017-03-31 Thread Raviteja Garimella
The device node is used for UDCs integrated into Broadcom's
iProc family of SoCs'. The UDC is based on Synopsys Designware
Cores AHB Subsystem USB Device Controller IP.

Signed-off-by: Raviteja Garimella 
---
 Documentation/devicetree/bindings/usb/iproc-udc.txt | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/iproc-udc.txt

diff --git a/Documentation/devicetree/bindings/usb/iproc-udc.txt 
b/Documentation/devicetree/bindings/usb/iproc-udc.txt
new file mode 100644
index 000..272d7fa
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/iproc-udc.txt
@@ -0,0 +1,21 @@
+Broadcom IPROC USB Device controller.
+
+The device node is used for UDCs integrated into Broadcom's
+iProc family (Northstar2, Cygnus) of SoCs'. The UDC is based
+on Synopsys Designware Cores AHB Subsystem Device Controller
+IP.
+
+Required properties:
+ - compatible: Add the compatibility strings for supported platforms.
+   For Broadcom NS2 platform, add "brcm,ns2-udc","brcm,iproc-udc".
+   For Broadcom Cygnus platform, add "brcm,cygnus-udc", "brcm,iproc-udc".
+ - reg: Offset and length of UDC register set
+ - interrupts: description of interrupt line
+ - phys: phandle to phy node.
+
+Example:
+   udc_dwc: usb@664e {
+   compatible = "brcm,ns2-udc", "brcm,iproc-udc";
+   reg = <0x664e 0x2000>;
+   interrupts = ;
+   phys = <&usbdrd_phy>;
-- 
2.1.0

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


[RESEND PATCH v3 3/7] UDC: make debug prints compatible with both pci and platform devices

2017-03-31 Thread Raviteja Garimella
This patch adds a struct device member to UDC data structure and
makes changes to the arguments of dev_err and dev_dbg calls so that
the debug prints work for both pci and platform devices.

Signed-off-by: Raviteja Garimella 
---
 drivers/usb/gadget/udc/amd5536udc.h |  4 +++-
 drivers/usb/gadget/udc/amd5536udc_pci.c |  1 +
 drivers/usb/gadget/udc/snps_udc_core.c  | 28 ++--
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index bd2a18e..c252457 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -563,6 +563,8 @@ struct udc {
u16 cur_config;
u16 cur_intf;
u16 cur_alt;
+
+   struct device   *dev;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -639,7 +641,7 @@ MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only");
 
 /* debug macros */
 
-#define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args)
+#define DBG(udc , args...) dev_dbg(udc->dev, args)
 
 #ifdef UDC_VERBOSE
 #define VDBG   DBG
diff --git a/drivers/usb/gadget/udc/amd5536udc_pci.c 
b/drivers/usb/gadget/udc/amd5536udc_pci.c
index 2a2d0a9..57a13f0 100644
--- a/drivers/usb/gadget/udc/amd5536udc_pci.c
+++ b/drivers/usb/gadget/udc/amd5536udc_pci.c
@@ -168,6 +168,7 @@ static int udc_pci_probe(
dev->phys_addr = resource;
dev->irq = pdev->irq;
dev->pdev = pdev;
+   dev->dev = &pdev->dev;
 
/* general probing */
if (udc_probe(dev)) {
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 91d0f1a..a35fef9 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -209,18 +209,18 @@ static void print_regs(struct udc *dev)
if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBNDU (packet per buffer "
"WITHOUT desc. update)\n");
-   dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBNDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBNDU");
} else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBDU (packet per buffer "
"WITH desc. update)\n");
-   dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBDU");
}
if (use_dma && use_dma_bufferfill_mode) {
DBG(dev, "DMA mode   = BF (buffer fill mode)\n");
-   dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "BF");
+   dev_info(dev->dev, "DMA mode (%s)\n", "BF");
}
if (!use_dma)
-   dev_info(&dev->pdev->dev, "FIFO mode\n");
+   dev_info(dev->dev, "FIFO mode\n");
DBG(dev, "---\n");
 }
 
@@ -1624,7 +1624,7 @@ static void udc_setup_endpoints(struct udc *dev)
 static void usb_connect(struct udc *dev)
 {
 
-   dev_info(&dev->pdev->dev, "USB Connect\n");
+   dev_info(dev->dev, "USB Connect\n");
 
dev->connected = 1;
 
@@ -1642,7 +1642,7 @@ static void usb_connect(struct udc *dev)
 static void usb_disconnect(struct udc *dev)
 {
 
-   dev_info(&dev->pdev->dev, "USB Disconnect\n");
+   dev_info(dev->dev, "USB Disconnect\n");
 
dev->connected = 0;
 
@@ -2106,7 +2106,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int 
ep_ix)
}
/* HE event ? */
if (tmp & AMD_BIT(UDC_EPSTS_HE)) {
-   dev_err(&dev->pdev->dev, "HE ep%dout occurred\n", ep->num);
+   dev_err(dev->dev, "HE ep%dout occurred\n", ep->num);
 
/* clear HE */
writel(tmp | AMD_BIT(UDC_EPSTS_HE), &ep->regs->sts);
@@ -2305,7 +2305,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int 
ep_ix)
if (use_dma) {
/* BNA ? */
if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
-   dev_err(&dev->pdev->dev,
+   dev_err(dev->dev,
"BNA ep%din occurred - DESPTR = %08lx\n",
ep->num,
(unsigned long) readl(&ep->regs->desptr));
@@ -2318,7 +2318,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int 
ep_ix)
}
/* HE event ? */
if (epsts & AMD_BIT(UDC_EPSTS_HE)) {
-   dev_err(&dev->pdev->dev,
+   dev_err(dev->dev,
"HE ep%dn occurred - DESPTR = %08lx\n",
ep->num, (unsigned long) readl(&ep->regs->desptr));
 
@@ -2956,7 +2956,7 @@ __acquires(dev->lock)
 
/* link up all endpoi

[RESEND PATCH v3 4/7] UDC: Provide correct arguments for 'dma_pool_create'

2017-03-31 Thread Raviteja Garimella
Change the argument from NULL to a struct device for the
dma_pool_create call during dma init.

Signed-off-by: Raviteja Garimella 
---
 drivers/usb/gadget/udc/snps_udc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index a35fef9..5ca8b7b 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -3097,7 +3097,7 @@ int init_dma_pools(struct udc *dev)
}
 
/* DMA setup */
-   dev->data_requests = dma_pool_create("data_requests", NULL,
+   dev->data_requests = dma_pool_create("data_requests", dev->dev,
sizeof(struct udc_data_dma), 0, 0);
if (!dev->data_requests) {
DBG(dev, "can't get request data pool\n");
@@ -3108,7 +3108,7 @@ int init_dma_pools(struct udc *dev)
dev->ep[UDC_EP0IN_IX].dma = &dev->regs->ctl;
 
/* dma desc for setup data */
-   dev->stp_requests = dma_pool_create("setup requests", NULL,
+   dev->stp_requests = dma_pool_create("setup requests", dev->dev,
sizeof(struct udc_stp_dma), 0, 0);
if (!dev->stp_requests) {
DBG(dev, "can't get stp request pool\n");
-- 
2.1.0

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


Re: [PATCH] usb: dwc3: debugfs: downcase OTG on 'mode' file

2017-03-31 Thread Sergei Shtylyov

Hello.

On 03/31/2017 02:12 PM, Felipe Balbi wrote:


When writing, we expect the "otg" string. When showing, we return
"OTG". Let's downcase that word to avoid confusion.


   Lowercase, maybe?



Signed-off-by: Felipe Balbi 

[...]

MBR, Sergei

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


Re: [PATCH v2 4/4] usb: dwc3: Workaround for super-speed host on dra7 in dual-role mode

2017-03-31 Thread Felipe Balbi

Hi,

Roger Quadros  writes:
> On 31/03/17 15:00, Felipe Balbi wrote:
>> 
>> Hi,
>> 
>> Roger Quadros  writes:
>> Your first implementation could be just that. Refactoring what needs to
>> be refactored, then patching "mode" debugfs to work properly in that
>> case. Only add otg.c/drd.c after "mode" debugfs file is stable, because
>> then you know what needs to be taken into consideration.
>>
>> Just to be clear, I'm not saying we should *ONLY* get the debugfs
>> interface for v4.12, I'm saying you should start with that and get that
>> stable and working properly (make an infinite loop constantly changing
>> modes and keep it running over the weekend) before you add support for
>> OTG interrupts, which could come in the same series ;-)
>>
>
> Just to clarify debugfs mode behaviour.
>
> Currently it is just changing PRTCAPDIR. What we need to do is that if
> dr_mode == "otg", then we call dwc3_host/gadget_init/exit() accordingly 
> as well.
>
> Does this make sense?

 it does.

>>>
>>> OK. Below is a patch that allows us to use debugfs/mode to do the role 
>>> switch.
>>> Switching from device to host worked fine but I get the following error when
>>> switching from host to device.
>>>
>>> https://hastebin.com/liluqosewe.xml
>>>
>>> cheers,
>>> -roger
>>>
>>> ---
>>> From 50c49f18474b388d10533eb9f6d04f454fabf687 Mon Sep 17 00:00:00 2001
>>> From: Roger Quadros 
>>> Date: Fri, 31 Mar 2017 12:54:13 +0300
>>> Subject: [PATCH] usb: dwc3: make role-switching work with debugfs/mode
>>>
>>> If dr_mode == "otg", we start by default in PERIPHERAL mode.
>>> Keep track of current role in "current_dr_role" whenever dwc3_set_mode()
>>> is called.
>>>
>>> When debugfs/mode is changed AND we're in dual-role mode,
>>> handle the switch by stopping and starting the respective
>>> host/gadget controllers.
>>>
>>> Signed-off-by: Roger Quadros 
>> 
>> I'm assuming you also plan on breaking this down further ;-)
>
> Did you mean I must split this patch into smaller ones?
>
>> 
>>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>>> index 369bab1..e2d36ba 100644
>>> --- a/drivers/usb/dwc3/core.c
>>> +++ b/drivers/usb/dwc3/core.c
>>> @@ -108,6 +108,8 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
>>> reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
>>> reg |= DWC3_GCTL_PRTCAPDIR(mode);
>>> dwc3_writel(dwc->regs, DWC3_GCTL, reg);
>>> +
>>> +   dwc->current_dr_role = mode;
>>>  }
>>>  
>>>  u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
>>> @@ -862,13 +864,8 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
>>> }
>>> break;
>>> case USB_DR_MODE_OTG:
>>> -   ret = dwc3_host_init(dwc);
>>> -   if (ret) {
>>> -   if (ret != -EPROBE_DEFER)
>>> -   dev_err(dev, "failed to initialize host\n");
>>> -   return ret;
>>> -   }
>>> -
>>> +   /* start in peripheral role by default */
>>> +   dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
>>> ret = dwc3_gadget_init(dwc);
>>> if (ret) {
>>> if (ret != -EPROBE_DEFER)
>>> @@ -894,8 +891,11 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
>>> dwc3_host_exit(dwc);
>>> break;
>>> case USB_DR_MODE_OTG:
>>> -   dwc3_host_exit(dwc);
>>> -   dwc3_gadget_exit(dwc);
>>> +   /* role might have changed since start */
>>> +   if (dwc->current_dr_role ==  DWC3_GCTL_PRTCAP_DEVICE)
>>> +   dwc3_gadget_exit(dwc);
>>> +   else if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST)
>>> +   dwc3_host_exit(dwc);
>> 
>> how about patching the respective exit/init functions with something
>> like:
>> 
>> if (dwc->current_dr_role != $my_expected_role)
>>  return 0;
>> 
>> then you can call them without any checks.
>
> OK.
>
>> 
>>> diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
>>> index 31926dd..a101b14 100644
>>> --- a/drivers/usb/dwc3/debugfs.c
>>> +++ b/drivers/usb/dwc3/debugfs.c
>>> @@ -327,19 +327,54 @@ static ssize_t dwc3_mode_write(struct file *file,
>>> return -EFAULT;
>>>  
>>> if (!strncmp(buf, "host", 4))
>>> -   mode |= DWC3_GCTL_PRTCAP_HOST;
>>> +   mode = DWC3_GCTL_PRTCAP_HOST;
>>>  
>>> if (!strncmp(buf, "device", 6))
>>> -   mode |= DWC3_GCTL_PRTCAP_DEVICE;
>>> +   mode = DWC3_GCTL_PRTCAP_DEVICE;
>>>  
>>> if (!strncmp(buf, "otg", 3))
>>> -   mode |= DWC3_GCTL_PRTCAP_OTG;
>>> +   mode = DWC3_GCTL_PRTCAP_OTG;
>>>  
>>> -   if (mode) {
>>> -   spin_lock_irqsave(&dwc->lock, flags);
>>> -   dwc3_set_mode(dwc, mode);
>>> -   spin_unlock_irqrestore(&dwc->lock, flags);
>>> +   if (!mode)
>>> +   return -EINVAL;
>>> +
>>> +   if (mode == dwc->current_dr_role)
>>> +   goto exit;
>>> +

Re: [PATCH v2 4/4] usb: dwc3: Workaround for super-speed host on dra7 in dual-role mode

2017-03-31 Thread Roger Quadros


On 31/03/17 15:00, Felipe Balbi wrote:
> 
> Hi,
> 
> Roger Quadros  writes:
> Your first implementation could be just that. Refactoring what needs to
> be refactored, then patching "mode" debugfs to work properly in that
> case. Only add otg.c/drd.c after "mode" debugfs file is stable, because
> then you know what needs to be taken into consideration.
>
> Just to be clear, I'm not saying we should *ONLY* get the debugfs
> interface for v4.12, I'm saying you should start with that and get that
> stable and working properly (make an infinite loop constantly changing
> modes and keep it running over the weekend) before you add support for
> OTG interrupts, which could come in the same series ;-)
>

 Just to clarify debugfs mode behaviour.

 Currently it is just changing PRTCAPDIR. What we need to do is that if
 dr_mode == "otg", then we call dwc3_host/gadget_init/exit() accordingly as 
 well.

 Does this make sense?
>>>
>>> it does.
>>>
>>
>> OK. Below is a patch that allows us to use debugfs/mode to do the role 
>> switch.
>> Switching from device to host worked fine but I get the following error when
>> switching from host to device.
>>
>> https://hastebin.com/liluqosewe.xml
>>
>> cheers,
>> -roger
>>
>> ---
>> From 50c49f18474b388d10533eb9f6d04f454fabf687 Mon Sep 17 00:00:00 2001
>> From: Roger Quadros 
>> Date: Fri, 31 Mar 2017 12:54:13 +0300
>> Subject: [PATCH] usb: dwc3: make role-switching work with debugfs/mode
>>
>> If dr_mode == "otg", we start by default in PERIPHERAL mode.
>> Keep track of current role in "current_dr_role" whenever dwc3_set_mode()
>> is called.
>>
>> When debugfs/mode is changed AND we're in dual-role mode,
>> handle the switch by stopping and starting the respective
>> host/gadget controllers.
>>
>> Signed-off-by: Roger Quadros 
> 
> I'm assuming you also plan on breaking this down further ;-)

Did you mean I must split this patch into smaller ones?

> 
>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>> index 369bab1..e2d36ba 100644
>> --- a/drivers/usb/dwc3/core.c
>> +++ b/drivers/usb/dwc3/core.c
>> @@ -108,6 +108,8 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
>>  reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
>>  reg |= DWC3_GCTL_PRTCAPDIR(mode);
>>  dwc3_writel(dwc->regs, DWC3_GCTL, reg);
>> +
>> +dwc->current_dr_role = mode;
>>  }
>>  
>>  u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
>> @@ -862,13 +864,8 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
>>  }
>>  break;
>>  case USB_DR_MODE_OTG:
>> -ret = dwc3_host_init(dwc);
>> -if (ret) {
>> -if (ret != -EPROBE_DEFER)
>> -dev_err(dev, "failed to initialize host\n");
>> -return ret;
>> -}
>> -
>> +/* start in peripheral role by default */
>> +dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
>>  ret = dwc3_gadget_init(dwc);
>>  if (ret) {
>>  if (ret != -EPROBE_DEFER)
>> @@ -894,8 +891,11 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
>>  dwc3_host_exit(dwc);
>>  break;
>>  case USB_DR_MODE_OTG:
>> -dwc3_host_exit(dwc);
>> -dwc3_gadget_exit(dwc);
>> +/* role might have changed since start */
>> +if (dwc->current_dr_role ==  DWC3_GCTL_PRTCAP_DEVICE)
>> +dwc3_gadget_exit(dwc);
>> +else if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST)
>> +dwc3_host_exit(dwc);
> 
> how about patching the respective exit/init functions with something
> like:
> 
> if (dwc->current_dr_role != $my_expected_role)
>   return 0;
> 
> then you can call them without any checks.

OK.

> 
>> diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
>> index 31926dd..a101b14 100644
>> --- a/drivers/usb/dwc3/debugfs.c
>> +++ b/drivers/usb/dwc3/debugfs.c
>> @@ -327,19 +327,54 @@ static ssize_t dwc3_mode_write(struct file *file,
>>  return -EFAULT;
>>  
>>  if (!strncmp(buf, "host", 4))
>> -mode |= DWC3_GCTL_PRTCAP_HOST;
>> +mode = DWC3_GCTL_PRTCAP_HOST;
>>  
>>  if (!strncmp(buf, "device", 6))
>> -mode |= DWC3_GCTL_PRTCAP_DEVICE;
>> +mode = DWC3_GCTL_PRTCAP_DEVICE;
>>  
>>  if (!strncmp(buf, "otg", 3))
>> -mode |= DWC3_GCTL_PRTCAP_OTG;
>> +mode = DWC3_GCTL_PRTCAP_OTG;
>>  
>> -if (mode) {
>> -spin_lock_irqsave(&dwc->lock, flags);
>> -dwc3_set_mode(dwc, mode);
>> -spin_unlock_irqrestore(&dwc->lock, flags);
>> +if (!mode)
>> +return -EINVAL;
>> +
>> +if (mode == dwc->current_dr_role)
>> +goto exit;
>> +
>> +/* prevent role switching if we're not dual-role */
>> +if (dwc->dr_mode != USB_DR_MODE_OTG)
>> +re

Re: [PATCH v2 4/4] usb: dwc3: Workaround for super-speed host on dra7 in dual-role mode

2017-03-31 Thread Felipe Balbi

Hi,

Roger Quadros  writes:
 Your first implementation could be just that. Refactoring what needs to
 be refactored, then patching "mode" debugfs to work properly in that
 case. Only add otg.c/drd.c after "mode" debugfs file is stable, because
 then you know what needs to be taken into consideration.

 Just to be clear, I'm not saying we should *ONLY* get the debugfs
 interface for v4.12, I'm saying you should start with that and get that
 stable and working properly (make an infinite loop constantly changing
 modes and keep it running over the weekend) before you add support for
 OTG interrupts, which could come in the same series ;-)

>>>
>>> Just to clarify debugfs mode behaviour.
>>>
>>> Currently it is just changing PRTCAPDIR. What we need to do is that if
>>> dr_mode == "otg", then we call dwc3_host/gadget_init/exit() accordingly as 
>>> well.
>>>
>>> Does this make sense?
>> 
>> it does.
>> 
>
> OK. Below is a patch that allows us to use debugfs/mode to do the role switch.
> Switching from device to host worked fine but I get the following error when
> switching from host to device.
>
> https://hastebin.com/liluqosewe.xml
>
> cheers,
> -roger
>
> ---
> From 50c49f18474b388d10533eb9f6d04f454fabf687 Mon Sep 17 00:00:00 2001
> From: Roger Quadros 
> Date: Fri, 31 Mar 2017 12:54:13 +0300
> Subject: [PATCH] usb: dwc3: make role-switching work with debugfs/mode
>
> If dr_mode == "otg", we start by default in PERIPHERAL mode.
> Keep track of current role in "current_dr_role" whenever dwc3_set_mode()
> is called.
>
> When debugfs/mode is changed AND we're in dual-role mode,
> handle the switch by stopping and starting the respective
> host/gadget controllers.
>
> Signed-off-by: Roger Quadros 

I'm assuming you also plan on breaking this down further ;-)

> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 369bab1..e2d36ba 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -108,6 +108,8 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
>   reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
>   reg |= DWC3_GCTL_PRTCAPDIR(mode);
>   dwc3_writel(dwc->regs, DWC3_GCTL, reg);
> +
> + dwc->current_dr_role = mode;
>  }
>  
>  u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
> @@ -862,13 +864,8 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
>   }
>   break;
>   case USB_DR_MODE_OTG:
> - ret = dwc3_host_init(dwc);
> - if (ret) {
> - if (ret != -EPROBE_DEFER)
> - dev_err(dev, "failed to initialize host\n");
> - return ret;
> - }
> -
> + /* start in peripheral role by default */
> + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
>   ret = dwc3_gadget_init(dwc);
>   if (ret) {
>   if (ret != -EPROBE_DEFER)
> @@ -894,8 +891,11 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
>   dwc3_host_exit(dwc);
>   break;
>   case USB_DR_MODE_OTG:
> - dwc3_host_exit(dwc);
> - dwc3_gadget_exit(dwc);
> + /* role might have changed since start */
> + if (dwc->current_dr_role ==  DWC3_GCTL_PRTCAP_DEVICE)
> + dwc3_gadget_exit(dwc);
> + else if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST)
> + dwc3_host_exit(dwc);

how about patching the respective exit/init functions with something
like:

if (dwc->current_dr_role != $my_expected_role)
return 0;

then you can call them without any checks.

> diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
> index 31926dd..a101b14 100644
> --- a/drivers/usb/dwc3/debugfs.c
> +++ b/drivers/usb/dwc3/debugfs.c
> @@ -327,19 +327,54 @@ static ssize_t dwc3_mode_write(struct file *file,
>   return -EFAULT;
>  
>   if (!strncmp(buf, "host", 4))
> - mode |= DWC3_GCTL_PRTCAP_HOST;
> + mode = DWC3_GCTL_PRTCAP_HOST;
>  
>   if (!strncmp(buf, "device", 6))
> - mode |= DWC3_GCTL_PRTCAP_DEVICE;
> + mode = DWC3_GCTL_PRTCAP_DEVICE;
>  
>   if (!strncmp(buf, "otg", 3))
> - mode |= DWC3_GCTL_PRTCAP_OTG;
> + mode = DWC3_GCTL_PRTCAP_OTG;
>  
> - if (mode) {
> - spin_lock_irqsave(&dwc->lock, flags);
> - dwc3_set_mode(dwc, mode);
> - spin_unlock_irqrestore(&dwc->lock, flags);
> + if (!mode)
> + return -EINVAL;
> +
> + if (mode == dwc->current_dr_role)
> + goto exit;
> +
> + /* prevent role switching if we're not dual-role */
> + if (dwc->dr_mode != USB_DR_MODE_OTG)
> + return -EINVAL;
> +
> + /* stop old role */
> + if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST)

is this your bug? This switch statement only executes when we're in host
mode. This means that when y

Re: [PATCH v2 4/4] usb: dwc3: Workaround for super-speed host on dra7 in dual-role mode

2017-03-31 Thread Roger Quadros
+Mathias

On 31/03/17 10:46, Felipe Balbi wrote:
> 
> Hi,
> 
> Roger Quadros  writes:
> Roger Quadros  writes:
>> dra7 OTG core limits the host controller to USB2.0 (high-speed) mode
>> when we're operating in dual-role.
>
> yeah, that's not a quirk. DRA7 supports OTGv2, not OTGv3. There was no
> USB3 when OTGv2 was written.
>
> DRA7 just shouldn't use OTG core altogether. In fact, this is the very
> thing I've been saying for a long time. Make the simplest implementation
> possible. The dead simple, does-one-thing-only sort of implementation.
>
> All we need for Dual-Role (without OTG extras) is some input for ID and
> VBUS, then we add/remove HCD/UDC conditionally and set PRTCAPDIR.
>

 The catch is that on AM437x there is no way to get ID and VBUS events other
 than the OTG controller so we have to rely on the OTG controller for that. 
 :(
>>>
>>> okay, so AM437x can get OTG interrupts properly. That's fine. We can
>>> still do everything we need using code that's already existing in dwc3
>>> if we refactor it a bit and hook it up to the OTG IRQ handler.
>>>
>>> Here's what we do:
>>>
>>> * First we re-factor all necessary code around so the API for OTG/DRD
>>>   is resumed to calling:
>>>
>>> dwc3_add_udc(dwc);
>>> dwc3_del_udc(dwc);
>>> dwc3_add_hcd(dwc);
>>> dwc3_del_hcd(dwc);
>>
>> Why do we need these new APIs? don't these suffice?
>>  dwc3_gadget_init(dwc);
>>  dwc3_gadget_exit(dwc);
>>  dwc3_host_init(dwc);
>>  dwc3_host_exit(dwc);
> 
> well, if they do what we want, sure. They suffice.
> 
>>> the semantics of these should be easy to understand and you can
>>> implement each in their respective host.c/gadget.c files.
>>>
>>> * Second step is to modify our dwc3_init_mode() (or whatever that
>>>   function was called, sorry, didn't check) to make sure we have
>>>   something like:
>>>
>>> case OTG:
>>> dwc3_add_udc(dwc);
>>> break;
>>>
>>> We should *not* add HCD in this case yet.
>>>
>>> * After that we add otg.c (or drd.c, no preference) and make that call
>>>   dwc3_add_udc(dwc) and, also, provide
>>>   dwc3_add_otg(dwc)/dwc3_del_otg(dwc) calls. Then patch the switch
>>>   statement above to:
>>>
>>> case OTG:
>>> dwc3_add_otg(dwc);
>>> break;
>>>
>>> Note that at this point, this is simply a direct replacement of
>>> dwc3_add_udc() to dwc3_add_otg(). This should maintain current behavior
>>> (which is starting with peripheral mode by default), but it should also
>>> add support for OTG interrupts to change the mode (from an interrupt
>>> thead)
>>>
>>> otg_isr()
>>> {
>>>
>>> /* don't forget to remove preivous mode if necessary */
>>> if (perimode)
>>> dwc3_add_udc(dwc);
>>> else
>>> dwc3_add_hcd(dwc);
>>> }
>>>
>>> * The next patch would be to choose default conditionally based on
>>>   PERIMODE or whatever.
>>>
>>> Of course, this is an oversimplified view of reality. You still need to
>>> poke around at PRTCAPDIR, etc. But all this can, actually, be prototyped
>>> using our "mode" debugfs file. Just make that call
>>> dwc3_add/del_udc/hcd() apart from fiddling with PRTCAPDIR in GCTL.
>>
>> We also need to ensure that system suspend/resume doesn't break.
>> Mainly if we suspend/resume with UDC removed.
> 
> right, why would it break in that case? I'm missing something...
> 
>>> Your first implementation could be just that. Refactoring what needs to
>>> be refactored, then patching "mode" debugfs to work properly in that
>>> case. Only add otg.c/drd.c after "mode" debugfs file is stable, because
>>> then you know what needs to be taken into consideration.
>>>
>>> Just to be clear, I'm not saying we should *ONLY* get the debugfs
>>> interface for v4.12, I'm saying you should start with that and get that
>>> stable and working properly (make an infinite loop constantly changing
>>> modes and keep it running over the weekend) before you add support for
>>> OTG interrupts, which could come in the same series ;-)
>>>
>>
>> Just to clarify debugfs mode behaviour.
>>
>> Currently it is just changing PRTCAPDIR. What we need to do is that if
>> dr_mode == "otg", then we call dwc3_host/gadget_init/exit() accordingly as 
>> well.
>>
>> Does this make sense?
> 
> it does.
> 

OK. Below is a patch that allows us to use debugfs/mode to do the role switch.
Switching from device to host worked fine but I get the following error when
switching from host to device.

https://hastebin.com/liluqosewe.xml

cheers,
-roger

---
>From 50c49f18474b388d10533eb9f6d04f454fabf687 Mon Sep 17 00:00:00 2001
From: Roger Quadros 
Date: Fri, 31 Mar 2017 12:54:13 +0300
Subject: [PATCH] usb: dwc3: make role-switching work with debugfs/mode

If dr_mode == "otg", we start by default in PERIPHERAL mode.
Keep track of current role in "current_dr_role" whenever dwc

[PATCH] usb: dwc3: debugfs: downcase OTG on 'mode' file

2017-03-31 Thread Felipe Balbi
When writing, we expect the "otg" string. When showing, we return
"OTG". Let's downcase that word to avoid confusion.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 7df45415ad70..2cda6e0dd7fa 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -300,7 +300,7 @@ static int dwc3_mode_show(struct seq_file *s, void *unused)
seq_printf(s, "device\n");
break;
case DWC3_GCTL_PRTCAP_OTG:
-   seq_printf(s, "OTG\n");
+   seq_printf(s, "otg\n");
break;
default:
seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg));
-- 
2.11.0.295.gd7dffce1ce

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


Re: [PATCH v3 2/7] UDC: Rename amd5536udc driver file based on IP

2017-03-31 Thread Felipe Balbi

Hi,

Raviteja Garimella  writes:

> This patch renames the amd5536udc.c that has the core driver
> functionality of Synopsys UDC to snps_udc_core.c
>
> The symbols exported here can be used by any UDC driver that uses
> the same Synopsys IP.
>
> Signed-off-by: Raviteja Garimella 

unfortunately, this patch doesn't apply:

Applying: UDC: Rename amd5536udc driver file based on IP
error: corrupt patch at line 235
Patch failed at 0001 UDC: Rename amd5536udc driver file based on IP
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

Can you rebase on testing/next and resend?

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCHv3] net: usbnet: support 64bit stats in qmi_wwan driver

2017-03-31 Thread Oliver Neukum
Am Freitag, den 31.03.2017, 10:48 +0200 schrieb Bjørn Mork:
> You get *all* the "0" line drivers for free, not only "qmi_wwan".  No
> code changes needed, except for adding the single .ndo line to drivers
> overriding the usbnet default net_device_ops. And even that only applies
> to a few of them.  Most will be OK if you just change the usbnet
> default.
> 
> I don't think the size of a complete series will be terrifying to
> anyone.

It would really be nice to do that.
However, if you really don't want to do it, well you wrote
a patch. But I am afraid dropping the error count is not acceptable.

Regards
Oliver

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


Re: [PATCH v3 4/4] cdc-acm: remove unused element of struct acm

2017-03-31 Thread Oliver Neukum
Am Donnerstag, den 30.03.2017, 22:15 +0200 schrieb Tobias Herzog:
> write_used was introduced with commit 884b600f63dc ("[PATCH] USB: fix acm
> trouble with terminals") but never used since.
> 
> Signed-off-by: Tobias Herzog 
Acked-by: Oliver Neukum 

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


Re: [PATCH v3 3/4] cdc-acm: log message for serial state notification

2017-03-31 Thread Oliver Neukum
Am Donnerstag, den 30.03.2017, 22:15 +0200 schrieb Tobias Herzog:
> Adds a similar log message to USB_CDC_NOTIFY_SERIAL_STATE as it is
> already done with USB_CDC_NOTIFY_NETWORK_CONNECTION.
> 
> Signed-off-by: Tobias Herzog 
Acked-by: Oliver Neukum 

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


Re: [PATCH v3 2/4] cdc-acm: reassemble fragmented notifications

2017-03-31 Thread Oliver Neukum
Am Donnerstag, den 30.03.2017, 22:15 +0200 schrieb Tobias Herzog:
> USB devices may have very limited endpoint packet sizes, so that
> notifications can not be transferred within one single usb packet.
> Reassembling of multiple packages may be necessary.
> 
> Signed-off-by: Tobias Herzog 
Acked-by: Oliver Neukum 
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 1/4] cdc-acm: fix possible invalid access when processing notification

2017-03-31 Thread Oliver Neukum
Am Donnerstag, den 30.03.2017, 22:15 +0200 schrieb Tobias Herzog:
> Notifications may only be 8 bytes long. Accessing the 9th and
> 10th byte of unimplemented/unknown notifications may be insecure.
> Also check the length of known notifications before accessing anything
> behind the 8th byte.
> 
> Signed-off-by: Tobias Herzog 
Acked-by: Oliver Neukum 

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


Re: [PATCH] usb: gadget: uvc: Missing files for configfs interface

2017-03-31 Thread Laurent Pinchart
Hi Felipe and Petr,

On Tuesday 28 Mar 2017 16:48:46 Felipe Balbi wrote:
> Petr Cvek  writes:
> > Dne 7.3.2017 v 06:58 Laurent Pinchart napsal(a):
> >> On Tuesday 07 Mar 2017 00:57:20 Petr Cvek wrote:
> >>> Commit 76e0da34c7ce ("usb-gadget/uvc: use per-attribute show and store
> >>> methods") caused a stringification of an undefined macro argument
> >>> "aname", so three UVC parameters (streaming_interval,
> >>> streaming_maxpacket and streaming_maxburst) were named "aname".
> >>> 
> >>> Add the definition of "aname" to the main macro and name the filenames
> >>> as originaly intended.
> >> 
> >> Why don't you just
> >> 
> >> - UVC_ATTR(f_uvc_opts_, cname, aname)
> >> + UVC_ATTR(f_uvc_opts_, cname, cname)
> >> 
> >> in the definition of the UVCG_OPTS_ATTR() macro ?
> > 
> > Hi,
> > 
> > In a fact I did it for my first testing version. But then I realized
> > two things. First one is that someone may want to rename these three
> > files (now or in the future). The second one is that this bug was
> > caused by original author, who probably assumed the UVCG_OPTS_ATTR
> > macro had "aname" argument as others UVCG_* macros and didn't check. I
> > assumed that too and only after I saw three "aname" files with the
> > same path I realized where is the problem.
> > 
> > So it's more like a human error prone type of a code. But if you think
> > "cname" is enough I can send PATCH v2.

I think it would be, otherwise we end up passing the same argument twice, 
which seems a bit useless to me. If we ever need to rename those files we can 
always change the code later.

It's no big deal, but I have a preference for my proposal.

> Laurent, any comments?

-- 
Regards,

Laurent Pinchart

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


Re: [PATCHv3] net: usbnet: support 64bit stats in qmi_wwan driver

2017-03-31 Thread Bjørn Mork
Greg Ungerer  writes:

> Add support for the net stats64 counters to the usbnet core and then to
> the qmi_wwan driver.
>
> This is a strait forward addition of 64bit counters for RX and TX packets
> and byte counts. It is done in the same style as for the other net drivers
> that support stats64.
>
> The bulk of the change is to the usbnet core. Then it is trivial to use
> that in the qmi_wwan.c driver. It would be very simple to extend this
> support to other usbnet based drivers.

Sorry, but I am starting to have my doubts about this partial conversion
of the usbnet stats.  I don't have any problem with doing incremental
changes.  But in this case it means running duplicate code. And I see no
reasons to justify doing this incrementally.  As you say: It is very
simple to extend it to all usbnet drivers when the basic infrastructure
is in place.

You alreay do most of that work. So why not just update the other
drivers too, allowing us to drop the legacy counters?  Deleting code is
always good :)


> +void usbnet_get_stats64(struct net_device *net, struct rtnl_link_stats64 
> *stats)
> +{
> + struct usbnet *dev = netdev_priv(net);
> + unsigned int start;
> + int cpu;
> +
> + netdev_stats_to_stats64(stats, &net->stats);
> +
> + for_each_possible_cpu(cpu) {
> + struct pcpu_sw_netstats *stats64;
> + u64 rx_packets, rx_bytes;
> + u64 tx_packets, tx_bytes;
> +
> + stats64 = per_cpu_ptr(dev->stats64, cpu);
> +
> + do {
> + start = u64_stats_fetch_begin_irq(&stats64->syncp);
> + rx_packets = stats64->rx_packets;
> + rx_bytes = stats64->rx_bytes;
> + tx_packets = stats64->tx_packets;
> + tx_bytes = stats64->tx_bytes;
> + } while (u64_stats_fetch_retry_irq(&stats64->syncp, start));
> +
> + stats->rx_packets += rx_packets;
> + stats->rx_bytes += rx_bytes;
> + stats->tx_packets += tx_packets;
> + stats->tx_bytes += tx_bytes;
> + }
> +}

So we only count packets and bytes.  No errors.  Why?

> @@ -1212,8 +1249,15 @@ static void tx_complete (struct urb *urb)
>   struct usbnet   *dev = entry->dev;
>  
>   if (urb->status == 0) {
> + struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->stats64);
> +
>   dev->net->stats.tx_packets += entry->packets;
>   dev->net->stats.tx_bytes += entry->length;
> +
> + u64_stats_update_begin(&stats64->syncp);
> + stats64->tx_packets += entry->packets;
> + stats64->tx_bytes += entry->length;
> + u64_stats_update_end(&stats64->syncp);
>   } else {
>   dev->net->stats.tx_errors++;
>  


This is one place where the old stats counted errors too.  But there are more:

bjorn@miraculix:/usr/local/src/git/linux$ git grep -E -- '->stats.*\+' 
drivers/net/usb/usbnet.c|grep -Ev '(bytes|packet)'
drivers/net/usb/usbnet.c:   dev->net->stats.rx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_length_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_over_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.rx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.tx_errors++;
drivers/net/usb/usbnet.c:   dev->net->stats.tx_dropped++;


Personally, I'd rather have incorrect byte counters than losing these
error counters. They are valuable debugging aids. I don't see why they
cannot be converted to 64bit stats right away.  Except that it makes the
amount of double accounting much more obvious...

Which is why I have landed on on a request to convert all the usbnet
drivers in one go.  There aren't that many of them, and even fewer
touching the stats outside of usbnet.c.  Among those few, none have more
than 6 lines currently touching "stats":

bjorn@miraculix:/usr/local/src/git/linux$ for f in `git grep -l -- 
'usbnet_probe' drivers/net/usb/`; do grep -Hc -- '->stats' $f; done
drivers/net/usb/asix_devices.c:0
drivers/net/usb/ax88179_178a.c:0
drivers/net/usb/cdc_eem.c:1
drivers/net/usb/cdc_ether.c:0
drivers/net/usb/cdc_mbim.c:0
drivers/net/usb/cdc_ncm.c:4
drivers/net/usb/cdc_subset.c:0
drivers/net/usb/ch9200.c:0
drivers/net/usb/cx82310_eth.c:0
drivers/net/usb/dm9601.c:5
drivers/net/usb/gl620a.c:0
drivers/net/usb/huawei_cdc_ncm.c:0
drivers/net/usb/int51x1.c:0
drivers/net/usb/kalmia.c:0
drivers/net/usb/lg-vl600.c:4
drivers/net/usb/mcs7830.c:4
drivers/net/usb/net1080.c:6
drivers/net/usb/plusb.c:0
drivers/net/usb/qmi_wwan.c:0
drivers/net/usb/rndis_host.c:1
drivers/net/usb/sierra_net.c:6
drivers/net/usb/smsc75xx.c:4
drivers/net/usb/smsc95xx.c:5
drivers/net/usb/sr9

[PATCH v2 6/6] usb: usbip tool: Remove empty lines

2017-03-31 Thread Yuyang Du
Signed-off-by: Yuyang Du 
---
 tools/usb/usbip/libsrc/vhci_driver.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index f596ef4..d34a482 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -36,8 +36,6 @@ imported_device_init(struct usbip_imported_device *idev, char 
*busid)
return NULL;
 }
 
-
-
 static int parse_status(const char *value)
 {
int ret = 0;
-- 
2.7.4

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


[PATCH v2 5/6] usb: usbip tool: Fix parse_status()

2017-03-31 Thread Yuyang Du
parse_status() reads the status file one by one, so it can only
update the available and according vhci_driver->idev's.

Signed-off-by: Yuyang Du 
---
 tools/usb/usbip/libsrc/vhci_driver.c | 36 +++-
 tools/usb/usbip/src/usbip_attach.c   |  2 ++
 2 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index 630b139..f596ef4 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -43,11 +43,6 @@ static int parse_status(const char *value)
int ret = 0;
char *c;
 
-
-   for (int i = 0; i < vhci_driver->nports; i++)
-   memset(&vhci_driver->idev[i], 0, sizeof(vhci_driver->idev[i]));
-
-
/* skip a header line */
c = strchr(value, '\n');
if (!c)
@@ -58,6 +53,7 @@ static int parse_status(const char *value)
int port, status, speed, devid;
unsigned long socket;
char lbusid[SYSFS_BUS_ID_SIZE];
+   struct usbip_imported_device *idev;
 
ret = sscanf(c, "%d %d %d %x %lx %31s\n",
&port, &status, &speed,
@@ -72,30 +68,28 @@ static int parse_status(const char *value)
port, status, speed, devid);
dbg("socket %lx lbusid %s", socket, lbusid);
 
-
/* if a device is connected, look at it */
-   {
-   struct usbip_imported_device *idev = 
&vhci_driver->idev[port];
+   idev = &vhci_driver->idev[port];
+
+   memset(idev, 0, sizeof(*idev));
 
-   idev->port  = port;
-   idev->status= status;
+   idev->port  = port;
+   idev->status= status;
 
-   idev->devid = devid;
+   idev->devid = devid;
 
-   idev->busnum= (devid >> 16);
-   idev->devnum= (devid & 0x);
+   idev->busnum= (devid >> 16);
+   idev->devnum= (devid & 0x);
 
-   if (idev->status != VDEV_ST_NULL
-   && idev->status != VDEV_ST_NOTASSIGNED) {
-   idev = imported_device_init(idev, lbusid);
-   if (!idev) {
-   dbg("imported_device_init failed");
-   return -1;
-   }
+   if (idev->status != VDEV_ST_NULL
+   && idev->status != VDEV_ST_NOTASSIGNED) {
+   idev = imported_device_init(idev, lbusid);
+   if (!idev) {
+   dbg("imported_device_init failed");
+   return -1;
}
}
 
-
/* go to the next line */
c = strchr(c, '\n');
if (!c)
diff --git a/tools/usb/usbip/src/usbip_attach.c 
b/tools/usb/usbip/src/usbip_attach.c
index 70a6b50..62a297f 100644
--- a/tools/usb/usbip/src/usbip_attach.c
+++ b/tools/usb/usbip/src/usbip_attach.c
@@ -108,6 +108,8 @@ static int import_device(int sockfd, struct 
usbip_usb_device *udev)
return -1;
}
 
+   dbg("got free port %d", port);
+
rc = usbip_vhci_attach_device(port, sockfd, udev->busnum,
  udev->devnum, udev->speed);
if (rc < 0) {
-- 
2.7.4

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


[PATCH v2 1/6] usb: usbip: Remove unnecessary get_vdev()

2017-03-31 Thread Yuyang Du
vhci_tx_urb() should be able to get the vhci_device from
its caller vhci_urb_enqueue(), instead of brutal-force
searching it.

Signed-off-by: Yuyang Du 
---
 drivers/usb/usbip/vhci_hcd.c | 32 ++--
 1 file changed, 2 insertions(+), 30 deletions(-)

diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index e4cb9f0..5d8b2c2 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -430,36 +430,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 
typeReq, u16 wValue,
return retval;
 }
 
-static struct vhci_device *get_vdev(struct usb_device *udev)
+static void vhci_tx_urb(struct urb *urb, struct vhci_device *vdev)
 {
-   struct platform_device *pdev;
-   struct usb_hcd *hcd;
-   struct vhci_hcd *vhci;
-   int pdev_nr, rhport;
-
-   if (!udev)
-   return NULL;
-
-   for (pdev_nr = 0; pdev_nr < vhci_num_controllers; pdev_nr++) {
-   pdev = *(vhci_pdevs + pdev_nr);
-   if (pdev == NULL)
-   continue;
-   hcd = platform_get_drvdata(pdev);
-   if (hcd == NULL)
-   continue;
-   vhci = hcd_to_vhci(hcd);
-   for (rhport = 0; rhport < VHCI_HC_PORTS; rhport++) {
-   if (vhci->vdev[rhport].udev == udev)
-   return &vhci->vdev[rhport];
-   }
-   }
-
-   return NULL;
-}
-
-static void vhci_tx_urb(struct urb *urb)
-{
-   struct vhci_device *vdev = get_vdev(urb->dev);
struct vhci_priv *priv;
struct vhci_hcd *vhci;
unsigned long flags;
@@ -601,7 +573,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb 
*urb,
}
 
 out:
-   vhci_tx_urb(urb);
+   vhci_tx_urb(urb, vdev);
spin_unlock_irqrestore(&vhci->lock, flags);
 
return 0;
-- 
2.7.4

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


[PATCH v2 4/6] usb: usbip tool: Fix refresh_imported_device_list()

2017-03-31 Thread Yuyang Du
The commit 0775a9cbc694e8c7 ("usbip: vhci extension: modifications
to vhci driver") introduced multiple controllers, but the status
of the ports are only extracted from the first status file, fix it.

Signed-off-by: Yuyang Du 
---
 tools/usb/usbip/libsrc/vhci_driver.c | 27 +--
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index ccecd47..630b139 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -108,18 +108,33 @@ static int parse_status(const char *value)
return 0;
 }
 
+#define MAX_STATUS_NAME 16
+
 static int refresh_imported_device_list(void)
 {
const char *attr_status;
+   char status[MAX_STATUS_NAME+1] = "status";
+   int i, ret;
 
-   attr_status = udev_device_get_sysattr_value(vhci_driver->hc_device,
-  "status");
-   if (!attr_status) {
-   err("udev_device_get_sysattr_value failed");
-   return -1;
+   for (i = 0; i < vhci_driver->ncontrollers; i++) {
+   if (i > 0)
+   snprintf(status, sizeof(status), "status.%d", i);
+
+   attr_status = 
udev_device_get_sysattr_value(vhci_driver->hc_device,
+   status);
+   if (!attr_status) {
+   err("udev_device_get_sysattr_value failed");
+   return -1;
+   }
+
+   dbg("controller %d", i);
+
+   ret = parse_status(attr_status);
+   if (ret != 0)
+   return ret;
}
 
-   return parse_status(attr_status);
+   return 0;
 }
 
 static int get_nports(void)
-- 
2.7.4

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


[PATCH v2 2/6] usb: usbip tool: Fix get_nports()

2017-03-31 Thread Yuyang Du
The commit 0775a9cbc694e8c72 ("usbip: vhci extension: modifications
to vhci driver") introduced multiple controllers, and nports as a sys
file, and claimed to read the nports from it, but it didn't.

In addition, the get_nports() has been so wrong that even with 8 port
lines for instance, it gets 7 (I am guessing it is due to a '\n' mess).
Nevertheless, we fix it by reading the nports attribute.

Reviewed-by: Krzysztof Opasiak 
Signed-off-by: Yuyang Du 
---
 tools/usb/usbip/libsrc/vhci_driver.c | 28 +---
 1 file changed, 5 insertions(+), 23 deletions(-)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index ad92047..f659c14 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -123,33 +123,15 @@ static int refresh_imported_device_list(void)
 
 static int get_nports(void)
 {
-   char *c;
-   int nports = 0;
-   const char *attr_status;
+   const char *attr_nports;
 
-   attr_status = udev_device_get_sysattr_value(vhci_driver->hc_device,
-  "status");
-   if (!attr_status) {
-   err("udev_device_get_sysattr_value failed");
+   attr_nports = udev_device_get_sysattr_value(vhci_driver->hc_device, 
"nports");
+   if (!attr_nports) {
+   err("udev_device_get_sysattr_value nports failed");
return -1;
}
 
-   /* skip a header line */
-   c = strchr(attr_status, '\n');
-   if (!c)
-   return 0;
-   c++;
-
-   while (*c != '\0') {
-   /* go to the next line */
-   c = strchr(c, '\n');
-   if (!c)
-   return nports;
-   c++;
-   nports += 1;
-   }
-
-   return nports;
+   return (int)strtoul(attr_nports, NULL, 10);
 }
 
 /*
-- 
2.7.4

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


[PATCH v2 0/6] usb: usbip: Fix ports and port status

2017-03-31 Thread Yuyang Du
The commit 0775a9cbc694e8c7 ("usbip: vhci extension: modifications
to vhci driver") introduced several bugs relating to the number of
ports amd the port status. In addition, a small improvement is made
to the vhci_hcd module.

v2:
 - Remove ncontrollers RO attr as suggested by Krzysztof
 - As a result, scandir vhci_hcd* dir in platform to learn how many we have as 
suggested by Krzysztof
 - Minor coding changes

Thanks,
Yuyang

--

Yuyang Du (6):
  usb: usbip: Remove unnecessary get_vdev()
  usb: usbip tool: Fix get_nports()
  usb: usbip tool: Add ncontrollers in vhci_driver structure
  usb: usbip tool: Fix refresh_imported_device_list()
  usb: usbip tool: Fix parse_status()
  usb: usbip tool: Remove empty lines

 drivers/usb/usbip/vhci_hcd.c |  32 +-
 tools/usb/usbip/libsrc/vhci_driver.c | 119 ---
 tools/usb/usbip/libsrc/vhci_driver.h |   1 +
 tools/usb/usbip/src/usbip_attach.c   |   2 +
 4 files changed, 74 insertions(+), 80 deletions(-)

-- 
2.7.4

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


[PATCH v2 3/6] usb: usbip tool: Add ncontrollers in vhci_driver structure

2017-03-31 Thread Yuyang Du
A new field ncontrollers is added to the vhci_driver structure.
And this field is stored by scanning the vhci_hcd* dirs in the
platform udev.

Suggested-by: Krzysztof Opasiak 
Signed-off-by: Yuyang Du 
---
 tools/usb/usbip/libsrc/vhci_driver.c | 32 +++-
 tools/usb/usbip/libsrc/vhci_driver.h |  1 +
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index f659c14..ccecd47 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "sysfs_utils.h"
 
 #undef  PROGNAME
@@ -134,6 +135,33 @@ static int get_nports(void)
return (int)strtoul(attr_nports, NULL, 10);
 }
 
+static int vhci_hcd_filter(const struct dirent *dirent)
+{
+   return strcmp(dirent->d_name, "vhci_hcd") >= 0 ? 1: 0;
+}
+
+static int get_ncontrollers(void)
+{
+   struct dirent **namelist;
+   struct udev_device *platform;
+   int n;
+
+   platform = udev_device_get_parent(vhci_driver->hc_device);
+   if (platform == NULL)
+   return -1;
+
+   n = scandir(udev_device_get_syspath(platform), &namelist, 
vhci_hcd_filter, NULL);
+   if (n < 0)
+   err("scandir failed");
+   else {
+   for (int i = 0; i < n; i++)
+   free(namelist[i]);
+   free(namelist);
+   }
+
+   return n;
+}
+
 /*
  * Read the given port's record.
  *
@@ -220,9 +248,11 @@ int usbip_vhci_driver_open(void)
}
 
vhci_driver->nports = get_nports();
-
dbg("available ports: %d", vhci_driver->nports);
 
+   vhci_driver->ncontrollers = get_ncontrollers();
+   dbg("available controllers: %d", vhci_driver->ncontrollers);
+
if (refresh_imported_device_list())
goto err;
 
diff --git a/tools/usb/usbip/libsrc/vhci_driver.h 
b/tools/usb/usbip/libsrc/vhci_driver.h
index fa2316c..33add14 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.h
+++ b/tools/usb/usbip/libsrc/vhci_driver.h
@@ -31,6 +31,7 @@ struct usbip_vhci_driver {
/* /sys/devices/platform/vhci_hcd */
struct udev_device *hc_device;
 
+   int ncontrollers;
int nports;
struct usbip_imported_device idev[MAXNPORT];
 };
-- 
2.7.4

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


Re: [PATCH 5/6] usb: usbip tool: Fix refresh_imported_device_list()

2017-03-31 Thread Yuyang Du
Hi Krzysztof,

On Mon, Mar 27, 2017 at 04:31:42PM +0200, Krzysztof Opasiak wrote:
> 
> 
> On 03/27/2017 07:25 AM, Yuyang Du wrote:
> >On Mon, Mar 27, 2017 at 09:07:50AM +0200, Krzysztof Opasiak wrote:
> >>
> >>As now we have multiple controllers I would be more than happy if we
> >>could fix functions like this one to take a controller as a
> >>parameter and invoke commands on it instead hardcoding loops like
> >>this one with some unclear conditions like if (i > 0).
> >
> >You mean something like this?
> >
> >int parse_controller_status(int controller) {
> >
> > if (controller > 0)
> > ...
> >
> > ...
> >
> >}
> >
> 
> Rather:
> 
> int parse_status(controller *ctrl)
> {
>   stat = get_status(ctrl->status_path);
> 
>   ...
> }

I hope I know how to get the status_path easily, but I don't. So I'll
post another version with this unaddressed. Please make it in detail
and I'll make another version.

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


Re: [PATCH v2 4/4] usb: dwc3: Workaround for super-speed host on dra7 in dual-role mode

2017-03-31 Thread Felipe Balbi

Hi,

Roger Quadros  writes:
 Roger Quadros  writes:
> dra7 OTG core limits the host controller to USB2.0 (high-speed) mode
> when we're operating in dual-role.

 yeah, that's not a quirk. DRA7 supports OTGv2, not OTGv3. There was no
 USB3 when OTGv2 was written.

 DRA7 just shouldn't use OTG core altogether. In fact, this is the very
 thing I've been saying for a long time. Make the simplest implementation
 possible. The dead simple, does-one-thing-only sort of implementation.

 All we need for Dual-Role (without OTG extras) is some input for ID and
 VBUS, then we add/remove HCD/UDC conditionally and set PRTCAPDIR.

>>>
>>> The catch is that on AM437x there is no way to get ID and VBUS events other
>>> than the OTG controller so we have to rely on the OTG controller for that. 
>>> :(
>> 
>> okay, so AM437x can get OTG interrupts properly. That's fine. We can
>> still do everything we need using code that's already existing in dwc3
>> if we refactor it a bit and hook it up to the OTG IRQ handler.
>> 
>> Here's what we do:
>> 
>> * First we re-factor all necessary code around so the API for OTG/DRD
>>   is resumed to calling:
>> 
>>  dwc3_add_udc(dwc);
>> dwc3_del_udc(dwc);
>> dwc3_add_hcd(dwc);
>> dwc3_del_hcd(dwc);
>
> Why do we need these new APIs? don't these suffice?
>   dwc3_gadget_init(dwc);
>   dwc3_gadget_exit(dwc);
>   dwc3_host_init(dwc);
>   dwc3_host_exit(dwc);

well, if they do what we want, sure. They suffice.

>> the semantics of these should be easy to understand and you can
>> implement each in their respective host.c/gadget.c files.
>> 
>> * Second step is to modify our dwc3_init_mode() (or whatever that
>>   function was called, sorry, didn't check) to make sure we have
>>   something like:
>> 
>>  case OTG:
>>  dwc3_add_udc(dwc);
>> break;
>> 
>> We should *not* add HCD in this case yet.
>> 
>> * After that we add otg.c (or drd.c, no preference) and make that call
>>   dwc3_add_udc(dwc) and, also, provide
>>   dwc3_add_otg(dwc)/dwc3_del_otg(dwc) calls. Then patch the switch
>>   statement above to:
>> 
>>  case OTG:
>>  dwc3_add_otg(dwc);
>> break;
>> 
>> Note that at this point, this is simply a direct replacement of
>> dwc3_add_udc() to dwc3_add_otg(). This should maintain current behavior
>> (which is starting with peripheral mode by default), but it should also
>> add support for OTG interrupts to change the mode (from an interrupt
>> thead)
>> 
>>  otg_isr()
>> {
>> 
>>  /* don't forget to remove preivous mode if necessary */
>>  if (perimode)
>>  dwc3_add_udc(dwc);
>> else
>>  dwc3_add_hcd(dwc);
>>  }
>> 
>> * The next patch would be to choose default conditionally based on
>>   PERIMODE or whatever.
>> 
>> Of course, this is an oversimplified view of reality. You still need to
>> poke around at PRTCAPDIR, etc. But all this can, actually, be prototyped
>> using our "mode" debugfs file. Just make that call
>> dwc3_add/del_udc/hcd() apart from fiddling with PRTCAPDIR in GCTL.
>
> We also need to ensure that system suspend/resume doesn't break.
> Mainly if we suspend/resume with UDC removed.

right, why would it break in that case? I'm missing something...

>> Your first implementation could be just that. Refactoring what needs to
>> be refactored, then patching "mode" debugfs to work properly in that
>> case. Only add otg.c/drd.c after "mode" debugfs file is stable, because
>> then you know what needs to be taken into consideration.
>> 
>> Just to be clear, I'm not saying we should *ONLY* get the debugfs
>> interface for v4.12, I'm saying you should start with that and get that
>> stable and working properly (make an infinite loop constantly changing
>> modes and keep it running over the weekend) before you add support for
>> OTG interrupts, which could come in the same series ;-)
>> 
>
> Just to clarify debugfs mode behaviour.
>
> Currently it is just changing PRTCAPDIR. What we need to do is that if
> dr_mode == "otg", then we call dwc3_host/gadget_init/exit() accordingly as 
> well.
>
> Does this make sense?

it does.

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH] USB: serial: drop obsolete open-race workaround

2017-03-31 Thread Greg KH
On Thu, Mar 30, 2017 at 03:46:30PM +0200, Johan Hovold wrote:
> Commit a65a6f14dc24 ("USB: serial: fix race between probe and open")
> fixed a race between probe and open, which could lead to crashes when a
> not yet fully initialised port was being opened.
> 
> This race was later incidentally closed by commit 7e73eca6a7b2 ("TTY:
> move cdev_add to tty_register_device") which moved character-device
> registration from tty_register_driver to tty_register_device, which
> isn't called until the port has been fully set up.
> 
> Remove the now redundant workaround which had the negative side effect
> of not allowing a port to be opened immediately after user space had
> been notified of a new tty device.
> 
> Signed-off-by: Johan Hovold 

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


Re: [PATCH v2 4/4] usb: dwc3: Workaround for super-speed host on dra7 in dual-role mode

2017-03-31 Thread Roger Quadros
Hi,

On 29/03/17 13:32, Felipe Balbi wrote:
> 
> Hi,
> 
> Roger Quadros  writes:
>>> Roger Quadros  writes:
 dra7 OTG core limits the host controller to USB2.0 (high-speed) mode
 when we're operating in dual-role.
>>>
>>> yeah, that's not a quirk. DRA7 supports OTGv2, not OTGv3. There was no
>>> USB3 when OTGv2 was written.
>>>
>>> DRA7 just shouldn't use OTG core altogether. In fact, this is the very
>>> thing I've been saying for a long time. Make the simplest implementation
>>> possible. The dead simple, does-one-thing-only sort of implementation.
>>>
>>> All we need for Dual-Role (without OTG extras) is some input for ID and
>>> VBUS, then we add/remove HCD/UDC conditionally and set PRTCAPDIR.
>>>
>>
>> The catch is that on AM437x there is no way to get ID and VBUS events other
>> than the OTG controller so we have to rely on the OTG controller for that. :(
> 
> okay, so AM437x can get OTG interrupts properly. That's fine. We can
> still do everything we need using code that's already existing in dwc3
> if we refactor it a bit and hook it up to the OTG IRQ handler.
> 
> Here's what we do:
> 
> * First we re-factor all necessary code around so the API for OTG/DRD
>   is resumed to calling:
> 
>   dwc3_add_udc(dwc);
> dwc3_del_udc(dwc);
> dwc3_add_hcd(dwc);
> dwc3_del_hcd(dwc);

Why do we need these new APIs? don't these suffice?
dwc3_gadget_init(dwc);
dwc3_gadget_exit(dwc);
dwc3_host_init(dwc);
dwc3_host_exit(dwc);
> 
> the semantics of these should be easy to understand and you can
> implement each in their respective host.c/gadget.c files.
> 
> * Second step is to modify our dwc3_init_mode() (or whatever that
>   function was called, sorry, didn't check) to make sure we have
>   something like:
> 
>   case OTG:
>   dwc3_add_udc(dwc);
> break;
> 
> We should *not* add HCD in this case yet.
> 
> * After that we add otg.c (or drd.c, no preference) and make that call
>   dwc3_add_udc(dwc) and, also, provide
>   dwc3_add_otg(dwc)/dwc3_del_otg(dwc) calls. Then patch the switch
>   statement above to:
> 
>   case OTG:
>   dwc3_add_otg(dwc);
> break;
> 
> Note that at this point, this is simply a direct replacement of
> dwc3_add_udc() to dwc3_add_otg(). This should maintain current behavior
> (which is starting with peripheral mode by default), but it should also
> add support for OTG interrupts to change the mode (from an interrupt
> thead)
> 
>   otg_isr()
> {
> 
>   /* don't forget to remove preivous mode if necessary */
>   if (perimode)
>   dwc3_add_udc(dwc);
> else
>   dwc3_add_hcd(dwc);
>   }
> 
> * The next patch would be to choose default conditionally based on
>   PERIMODE or whatever.
> 
> Of course, this is an oversimplified view of reality. You still need to
> poke around at PRTCAPDIR, etc. But all this can, actually, be prototyped
> using our "mode" debugfs file. Just make that call
> dwc3_add/del_udc/hcd() apart from fiddling with PRTCAPDIR in GCTL.

We also need to ensure that system suspend/resume doesn't break.
Mainly if we suspend/resume with UDC removed.
> 
> Your first implementation could be just that. Refactoring what needs to
> be refactored, then patching "mode" debugfs to work properly in that
> case. Only add otg.c/drd.c after "mode" debugfs file is stable, because
> then you know what needs to be taken into consideration.
> 
> Just to be clear, I'm not saying we should *ONLY* get the debugfs
> interface for v4.12, I'm saying you should start with that and get that
> stable and working properly (make an infinite loop constantly changing
> modes and keep it running over the weekend) before you add support for
> OTG interrupts, which could come in the same series ;-)
> 

Just to clarify debugfs mode behaviour.

Currently it is just changing PRTCAPDIR. What we need to do is that if
dr_mode == "otg", then we call dwc3_host/gadget_init/exit() accordingly as well.

Does this make sense?

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


[PATCH v5 3/9] phy: phy-mt65xx-usb3: split SuperSpeed port into two ones

2017-03-31 Thread Chunfeng Yun
Currently usb3 port in fact includes two sub-ports, but it is not
flexible for some cases, such as following one:
usb3 port0 includes u2port0 and u3port0;
usb2 port0 includes u2port1;
If wants to support only HS, we can use u2port0 or u2port1, when
select u2port0, u3port0 is not needed;
If wants to support SS, we can compound u2port0 and u3port0,
or u2port1 and u3port0, if select latter one, u2port0 is not needed.

So it's more flexible to split usb3 port into two ones and also try
best to save power by disabling unnecessary ports.

Signed-off-by: Chunfeng Yun 
---
 drivers/phy/phy-mt65xx-usb3.c |  149 +
 1 file changed, 75 insertions(+), 74 deletions(-)

diff --git a/drivers/phy/phy-mt65xx-usb3.c b/drivers/phy/phy-mt65xx-usb3.c
index 4fd47d0..7fff482 100644
--- a/drivers/phy/phy-mt65xx-usb3.c
+++ b/drivers/phy/phy-mt65xx-usb3.c
@@ -30,11 +30,11 @@
 #define SSUSB_SIFSLV_SPLLC 0x
 #define SSUSB_SIFSLV_U2FREQ0x0100
 
-/* offsets of sub-segment in each port registers */
+/* offsets of banks in each u2phy registers */
 #define SSUSB_SIFSLV_U2PHY_COM_BASE0x
-#define SSUSB_SIFSLV_U3PHYD_BASE   0x0100
-#define SSUSB_USB30_PHYA_SIV_B_BASE0x0300
-#define SSUSB_SIFSLV_U3PHYA_DA_BASE0x0400
+/* offsets of banks in each u3phy registers */
+#define SSUSB_SIFSLV_U3PHYD_BASE   0x
+#define SSUSB_SIFSLV_U3PHYA_BASE   0x0200
 
 #define U3P_USBPHYACR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x)
 #define PA0_RG_U2PLL_FORCE_ON  BIT(15)
@@ -49,7 +49,6 @@
 #define PA5_RG_U2_HS_100U_U3_ENBIT(11)
 
 #define U3P_USBPHYACR6 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018)
-#define PA6_RG_U2_ISO_EN   BIT(31)
 #define PA6_RG_U2_BC11_SW_EN   BIT(23)
 #define PA6_RG_U2_OTG_VBUSCMP_EN   BIT(20)
 #define PA6_RG_U2_SQTH GENMASK(3, 0)
@@ -91,18 +90,18 @@
 #define P2C_RG_SESSEND BIT(4)
 #define P2C_RG_AVALID  BIT(2)
 
-#define U3P_U3_PHYA_REG0   (SSUSB_USB30_PHYA_SIV_B_BASE + 0x)
+#define U3P_U3_PHYA_REG0   (SSUSB_SIFSLV_U3PHYA_BASE + 0x)
 #define P3A_RG_U3_VUSB10_ONBIT(5)
 
-#define U3P_U3_PHYA_REG6   (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0018)
+#define U3P_U3_PHYA_REG6   (SSUSB_SIFSLV_U3PHYA_BASE + 0x0018)
 #define P3A_RG_TX_EIDLE_CM GENMASK(31, 28)
 #define P3A_RG_TX_EIDLE_CM_VAL(x)  ((0xf & (x)) << 28)
 
-#define U3P_U3_PHYA_REG9   (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0024)
+#define U3P_U3_PHYA_REG9   (SSUSB_SIFSLV_U3PHYA_BASE + 0x0024)
 #define P3A_RG_RX_DAC_MUX  GENMASK(5, 1)
 #define P3A_RG_RX_DAC_MUX_VAL(x)   ((0x1f & (x)) << 1)
 
-#define U3P_U3PHYA_DA_REG0 (SSUSB_SIFSLV_U3PHYA_DA_BASE + 0x)
+#define U3P_U3PHYA_DA_REG0 (SSUSB_SIFSLV_U3PHYA_BASE + 0x0100)
 #define P3A_RG_XTAL_EXT_EN_U3  GENMASK(11, 10)
 #define P3A_RG_XTAL_EXT_EN_U3_VAL(x)   ((0x3 & (x)) << 10)
 
@@ -160,7 +159,7 @@ struct mt65xx_phy_instance {
 
 struct mt65xx_u3phy {
struct device *dev;
-   void __iomem *sif_base; /* include sif2, but exclude port's */
+   void __iomem *sif_base; /* only shared sif */
struct clk *u3phya_ref; /* reference clock of usb3 anolog phy */
const struct mt65xx_phy_pdata *pdata;
struct mt65xx_phy_instance **phys;
@@ -190,7 +189,7 @@ static void hs_slew_rate_calibrate(struct mt65xx_u3phy 
*u3phy,
tmp = readl(sif_base + U3P_U2FREQ_FMCR0);
tmp &= ~(P2F_RG_CYCLECNT | P2F_RG_MONCLK_SEL);
tmp |= P2F_RG_CYCLECNT_VAL(U3P_FM_DET_CYCLE_CNT);
-   tmp |= P2F_RG_MONCLK_SEL_VAL(instance->index);
+   tmp |= P2F_RG_MONCLK_SEL_VAL(instance->index >> 1);
writel(tmp, sif_base + U3P_U2FREQ_FMCR0);
 
/* enable frequency meter */
@@ -238,6 +237,56 @@ static void hs_slew_rate_calibrate(struct mt65xx_u3phy 
*u3phy,
writel(tmp, instance->port_base + U3P_USBPHYACR5);
 }
 
+static void u3_phy_instance_init(struct mt65xx_u3phy *u3phy,
+   struct mt65xx_phy_instance *instance)
+{
+   void __iomem *port_base = instance->port_base;
+   u32 tmp;
+
+   /* gating PCIe Analog XTAL clock */
+   tmp = readl(u3phy->sif_base + U3P_XTALCTL3);
+   tmp |= XC3_RG_U3_XTAL_RX_PWD | XC3_RG_U3_FRC_XTAL_RX_PWD;
+   writel(tmp, u3phy->sif_base + U3P_XTALCTL3);
+
+   /* gating XSQ */
+   tmp = readl(port_base + U3P_U3PHYA_DA_REG0);
+   tmp &= ~P3A_RG_XTAL_EXT_EN_U3;
+   tmp |= P3A_RG_XTAL_EXT_EN_U3_VAL(2);
+   writel(tmp, port_base + U3P_U3PHYA_DA_REG0);
+
+   tmp = readl(port_base + U3P_U3_PHYA_REG9);
+   tmp &= ~P3A_RG_RX_DAC_MUX;
+   tmp |= P3A_RG_RX_DAC_MUX_VAL(4);
+   writel(tmp, port_base + U3P_U3_PHYA_REG9);
+
+   tmp = readl(port_base + U3P_U3_PHYA_REG6);
+   tmp &= ~P3A_RG_TX_EIDLE_CM;
+   tmp |= P3A_RG_TX_EIDLE_CM_VAL(0xe);
+   writel(tmp, port_base + U3P_U3_PHYA_REG6);
+
+   tmp = readl(port_base + U3P_PHYD_CDR1);
+   tmp &= ~(P3

[PATCH v5 1/9] phy: phy-mt65xx-usb3: improve RX detection stable time

2017-03-31 Thread Chunfeng Yun
The default value of RX detection stable time is 10us, and this
margin is too big for some critical cases which cause U3 link fail
and link to U2(probability is about 1%). So change it to 5us.

Signed-off-by: Chunfeng Yun 
---
 drivers/phy/phy-mt65xx-usb3.c |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/phy/phy-mt65xx-usb3.c b/drivers/phy/phy-mt65xx-usb3.c
index d972067..fe2392a 100644
--- a/drivers/phy/phy-mt65xx-usb3.c
+++ b/drivers/phy/phy-mt65xx-usb3.c
@@ -112,6 +112,14 @@
 #define P3D_RG_CDR_BIR_LTD0GENMASK(12, 8)
 #define P3D_RG_CDR_BIR_LTD0_VAL(x) ((0x1f & (x)) << 8)
 
+#define U3P_U3_PHYD_RXDET1 (SSUSB_SIFSLV_U3PHYD_BASE + 0x128)
+#define P3D_RG_RXDET_STB2_SET  GENMASK(17, 9)
+#define P3D_RG_RXDET_STB2_SET_VAL(x)   ((0x1ff & (x)) << 9)
+
+#define U3P_U3_PHYD_RXDET2 (SSUSB_SIFSLV_U3PHYD_BASE + 0x12c)
+#define P3D_RG_RXDET_STB2_SET_P3   GENMASK(8, 0)
+#define P3D_RG_RXDET_STB2_SET_P3_VAL(x)(0x1ff & (x))
+
 #define U3P_XTALCTL3   (SSUSB_SIFSLV_SPLLC + 0x0018)
 #define XC3_RG_U3_XTAL_RX_PWD  BIT(9)
 #define XC3_RG_U3_FRC_XTAL_RX_PWD  BIT(8)
@@ -295,6 +303,16 @@ static void phy_instance_init(struct mt65xx_u3phy *u3phy,
tmp |= P3D_RG_CDR_BIR_LTD0_VAL(0xc) | P3D_RG_CDR_BIR_LTD1_VAL(0x3);
writel(tmp, port_base + U3P_PHYD_CDR1);
 
+   tmp = readl(port_base + U3P_U3_PHYD_RXDET1);
+   tmp &= ~P3D_RG_RXDET_STB2_SET;
+   tmp |= P3D_RG_RXDET_STB2_SET_VAL(0x10);
+   writel(tmp, port_base + U3P_U3_PHYD_RXDET1);
+
+   tmp = readl(port_base + U3P_U3_PHYD_RXDET2);
+   tmp &= ~P3D_RG_RXDET_STB2_SET_P3;
+   tmp |= P3D_RG_RXDET_STB2_SET_P3_VAL(0x10);
+   writel(tmp, port_base + U3P_U3_PHYD_RXDET2);
+
dev_dbg(u3phy->dev, "%s(%d)\n", __func__, index);
 }
 
-- 
1.7.9.5

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


[PATCH v5 4/9] phy: phy-mt65xx-usb3: move clock from phy node into port nodes

2017-03-31 Thread Chunfeng Yun
each port has its own reference clock, the HighSpeed port is 48M,
and the SuperSpeed port is usually 26M, put them into port node for
flexibility, this can close clock if the port is not used.

Signed-off-by: Chunfeng Yun 
---
 drivers/phy/phy-mt65xx-usb3.c |   27 +--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/phy-mt65xx-usb3.c b/drivers/phy/phy-mt65xx-usb3.c
index 7fff482..3403572 100644
--- a/drivers/phy/phy-mt65xx-usb3.c
+++ b/drivers/phy/phy-mt65xx-usb3.c
@@ -153,6 +153,7 @@ struct mt65xx_phy_pdata {
 struct mt65xx_phy_instance {
struct phy *phy;
void __iomem *port_base;
+   struct clk *ref_clk;/* reference clock of anolog phy */
u32 index;
u8 type;
 };
@@ -160,6 +161,7 @@ struct mt65xx_phy_instance {
 struct mt65xx_u3phy {
struct device *dev;
void __iomem *sif_base; /* only shared sif */
+   /* deprecated, use @ref_clk instead in phy instance */
struct clk *u3phya_ref; /* reference clock of usb3 anolog phy */
const struct mt65xx_phy_pdata *pdata;
struct mt65xx_phy_instance **phys;
@@ -455,6 +457,12 @@ static int mt65xx_phy_init(struct phy *phy)
return ret;
}
 
+   ret = clk_prepare_enable(instance->ref_clk);
+   if (ret) {
+   dev_err(u3phy->dev, "failed to enable ref_clk\n");
+   return ret;
+   }
+
if (instance->type == PHY_TYPE_USB2)
phy_instance_init(u3phy, instance);
else
@@ -494,6 +502,7 @@ static int mt65xx_phy_exit(struct phy *phy)
if (instance->type == PHY_TYPE_USB2)
phy_instance_exit(u3phy, instance);
 
+   clk_disable_unprepare(instance->ref_clk);
clk_disable_unprepare(u3phy->u3phya_ref);
return 0;
 }
@@ -594,10 +603,13 @@ static int mt65xx_u3phy_probe(struct platform_device 
*pdev)
return PTR_ERR(u3phy->sif_base);
}
 
+   /* it's deprecated, make it optional for backward compatibility */
u3phy->u3phya_ref = devm_clk_get(dev, "u3phya_ref");
if (IS_ERR(u3phy->u3phya_ref)) {
-   dev_err(dev, "error to get u3phya_ref\n");
-   return PTR_ERR(u3phy->u3phya_ref);
+   if (PTR_ERR(u3phy->u3phya_ref) == -EPROBE_DEFER)
+   return -EPROBE_DEFER;
+
+   u3phy->u3phya_ref = NULL;
}
 
port = 0;
@@ -638,6 +650,17 @@ static int mt65xx_u3phy_probe(struct platform_device *pdev)
instance->index = port;
phy_set_drvdata(phy, instance);
port++;
+
+   /* if deprecated clock is provided, ignore instance's one */
+   if (u3phy->u3phya_ref)
+   continue;
+
+   instance->ref_clk = devm_clk_get(&phy->dev, "ref");
+   if (IS_ERR(instance->ref_clk)) {
+   dev_err(dev, "failed to get ref_clk(id-%d)\n", port);
+   retval = PTR_ERR(instance->ref_clk);
+   goto put_child;
+   }
}
 
provider = devm_of_phy_provider_register(dev, mt65xx_phy_xlate);
-- 
1.7.9.5

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


[PATCH v5 5/9] phy: phy-mt65xx-usb3: add support for new version phy

2017-03-31 Thread Chunfeng Yun
There are some variations from mt2701 to mt2712:
1. banks shared by multiple ports are put back into each port,
such as SPLLC and U2FREQ;
2. add a new bank MISC for u2port, and CHIP for u3port;
3. bank's offset in each port are also rearranged;

Signed-off-by: Chunfeng Yun 
---
 drivers/phy/phy-mt65xx-usb3.c |  344 ++---
 1 file changed, 217 insertions(+), 127 deletions(-)

diff --git a/drivers/phy/phy-mt65xx-usb3.c b/drivers/phy/phy-mt65xx-usb3.c
index 3403572..5eea65c 100644
--- a/drivers/phy/phy-mt65xx-usb3.c
+++ b/drivers/phy/phy-mt65xx-usb3.c
@@ -23,46 +23,54 @@
 #include 
 #include 
 
-/*
- * for sifslv2 register, but exclude port's;
- * relative to USB3_SIF2_BASE base address
- */
-#define SSUSB_SIFSLV_SPLLC 0x
-#define SSUSB_SIFSLV_U2FREQ0x0100
-
-/* offsets of banks in each u2phy registers */
-#define SSUSB_SIFSLV_U2PHY_COM_BASE0x
-/* offsets of banks in each u3phy registers */
-#define SSUSB_SIFSLV_U3PHYD_BASE   0x
-#define SSUSB_SIFSLV_U3PHYA_BASE   0x0200
-
-#define U3P_USBPHYACR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x)
+/* version V1 sub-banks offset base address */
+/* banks shared by multiple phys */
+#define SSUSB_SIFSLV_V1_SPLLC  0x000   /* shared by u3 phys */
+#define SSUSB_SIFSLV_V1_U2FREQ 0x100   /* shared by u2 phys */
+/* u2 phy bank */
+#define SSUSB_SIFSLV_V1_U2PHY_COM  0x000
+/* u3 phy banks */
+#define SSUSB_SIFSLV_V1_U3PHYD 0x000
+#define SSUSB_SIFSLV_V1_U3PHYA 0x200
+
+/* version V2 sub-banks offset base address */
+/* u2 phy banks */
+#define SSUSB_SIFSLV_V2_MISC   0x000
+#define SSUSB_SIFSLV_V2_U2FREQ 0x100
+#define SSUSB_SIFSLV_V2_U2PHY_COM  0x300
+/* u3 phy banks */
+#define SSUSB_SIFSLV_V2_SPLLC  0x000
+#define SSUSB_SIFSLV_V2_CHIP   0x100
+#define SSUSB_SIFSLV_V2_U3PHYD 0x200
+#define SSUSB_SIFSLV_V2_U3PHYA 0x400
+
+#define U3P_USBPHYACR0 0x000
 #define PA0_RG_U2PLL_FORCE_ON  BIT(15)
 
-#define U3P_USBPHYACR2 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0008)
+#define U3P_USBPHYACR2 0x008
 #define PA2_RG_SIF_U2PLL_FORCE_EN  BIT(18)
 
-#define U3P_USBPHYACR5 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014)
+#define U3P_USBPHYACR5 0x014
 #define PA5_RG_U2_HSTX_SRCAL_ENBIT(15)
 #define PA5_RG_U2_HSTX_SRCTRL  GENMASK(14, 12)
 #define PA5_RG_U2_HSTX_SRCTRL_VAL(x)   ((0x7 & (x)) << 12)
 #define PA5_RG_U2_HS_100U_U3_ENBIT(11)
 
-#define U3P_USBPHYACR6 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018)
+#define U3P_USBPHYACR6 0x018
 #define PA6_RG_U2_BC11_SW_EN   BIT(23)
 #define PA6_RG_U2_OTG_VBUSCMP_EN   BIT(20)
 #define PA6_RG_U2_SQTH GENMASK(3, 0)
 #define PA6_RG_U2_SQTH_VAL(x)  (0xf & (x))
 
-#define U3P_U2PHYACR4  (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020)
+#define U3P_U2PHYACR4  0x020
 #define P2C_RG_USB20_GPIO_CTL  BIT(9)
 #define P2C_USB20_GPIO_MODEBIT(8)
 #define P2C_U2_GPIO_CTR_MSK(P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE)
 
-#define U3D_U2PHYDCR0  (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0060)
+#define U3D_U2PHYDCR0  0x060
 #define P2C_RG_SIF_U2PLL_FORCE_ON  BIT(24)
 
-#define U3P_U2PHYDTM0  (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0068)
+#define U3P_U2PHYDTM0  0x068
 #define P2C_FORCE_UART_EN  BIT(26)
 #define P2C_FORCE_DATAIN   BIT(23)
 #define P2C_FORCE_DM_PULLDOWN  BIT(21)
@@ -84,59 +92,56 @@
P2C_FORCE_TERMSEL | P2C_RG_DMPULLDOWN | \
P2C_RG_DPPULLDOWN | P2C_RG_TERMSEL)
 
-#define U3P_U2PHYDTM1  (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x006C)
+#define U3P_U2PHYDTM1  0x06C
 #define P2C_RG_UART_EN BIT(16)
 #define P2C_RG_VBUSVALID   BIT(5)
 #define P2C_RG_SESSEND BIT(4)
 #define P2C_RG_AVALID  BIT(2)
 
-#define U3P_U3_PHYA_REG0   (SSUSB_SIFSLV_U3PHYA_BASE + 0x)
-#define P3A_RG_U3_VUSB10_ONBIT(5)
-
-#define U3P_U3_PHYA_REG6   (SSUSB_SIFSLV_U3PHYA_BASE + 0x0018)
+#define U3P_U3_PHYA_REG6   0x018
 #define P3A_RG_TX_EIDLE_CM GENMASK(31, 28)
 #define P3A_RG_TX_EIDLE_CM_VAL(x)  ((0xf & (x)) << 28)
 
-#define U3P_U3_PHYA_REG9   (SSUSB_SIFSLV_U3PHYA_BASE + 0x0024)
+#define U3P_U3_PHYA_REG9   0x024
 #define P3A_RG_RX_DAC_MUX  GENMASK(5, 1)
 #define P3A_RG_RX_DAC_MUX_VAL(x)   ((0x1f & (x)) << 1)
 
-#define U3P_U3PHYA_DA_REG0 (SSUSB_SIFSLV_U3PHYA_BASE + 0x0100)
+#define U3P_U3_PHYA_DA_REG00x100
 #define P3A_RG_XTAL_EXT_EN_U3  GENMASK(11, 10)
 #define P3A_RG_XTAL_EXT_EN_U3_VAL(x)   ((0x3 & (x)) << 10)
 
-#define U3P_U3_PHYD_LFPS1  (SSUSB_SIFSLV_U3PHYD_BASE + 0x000c)
+#define U3P_U3_PHYD_LFPS1  0x00c
 #define P3D_RG_FWAKE_THGENMASK(21, 16)
 #define P3D_RG_FWAKE_TH_VAL(x) ((0x3f & (x)) << 16)
 
-#define U3P_PHYD_CDR1

[PATCH v5 9/9] dt-bindings: phy-mt65xx-usb: add support for new version phy

2017-03-31 Thread Chunfeng Yun
add a new compatible string for "mt2712", and move reference clock
into each port node;

Signed-off-by: Chunfeng Yun 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/phy/phy-mt65xx-usb.txt |   93 +---
 1 file changed, 80 insertions(+), 13 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/phy-mt65xx-usb.txt 
b/Documentation/devicetree/bindings/phy/phy-mt65xx-usb.txt
index 33a2b1e..0acc5a9 100644
--- a/Documentation/devicetree/bindings/phy/phy-mt65xx-usb.txt
+++ b/Documentation/devicetree/bindings/phy/phy-mt65xx-usb.txt
@@ -6,12 +6,11 @@ This binding describes a usb3.0 phy for mt65xx platforms of 
Medaitek SoC.
 Required properties (controller (parent) node):
  - compatible  : should be one of
  "mediatek,mt2701-u3phy"
+ "mediatek,mt2712-u3phy"
  "mediatek,mt8173-u3phy"
- - reg : offset and length of register for phy, exclude port's
- register.
- - clocks  : a list of phandle + clock-specifier pairs, one for each
- entry in clock-names
- - clock-names : must contain
+ - clocks  : (deprecated, use port's clocks instead) a list of phandle +
+ clock-specifier pairs, one for each entry in clock-names
+ - clock-names : (deprecated, use port's one instead) must contain
  "u3phya_ref": for reference clock of usb3.0 analog phy.
 
 Required nodes : a sub-node is required for each port the controller
@@ -19,8 +18,19 @@ Required nodes   : a sub-node is required for each port 
the controller
  'reg' property is used inside these nodes to describe
  the controller's topology.
 
+Optional properties (controller (parent) node):
+ - reg : offset and length of register shared by multiple ports,
+ exclude port's private register. It is needed on mt2701
+ and mt8173, but not on mt2712.
+
 Required properties (port (child) node):
 - reg  : address and length of the register set for the port.
+- clocks   : a list of phandle + clock-specifier pairs, one for each
+ entry in clock-names
+- clock-names  : must contain
+ "ref": 48M reference clock for HighSpeed analog phy; and 26M
+   reference clock for SuperSpeed analog phy, sometimes is
+   24M, 25M or 27M, depended on platform.
 - #phy-cells   : should be 1 (See second example)
  cell after port phandle is phy type from:
- PHY_TYPE_USB2
@@ -31,21 +41,31 @@ Example:
 u3phy: usb-phy@1129 {
compatible = "mediatek,mt8173-u3phy";
reg = <0 0x1129 0 0x800>;
-   clocks = <&apmixedsys CLK_APMIXED_REF2USB_TX>;
-   clock-names = "u3phya_ref";
#address-cells = <2>;
#size-cells = <2>;
ranges;
status = "okay";
 
-   phy_port0: port@11290800 {
-   reg = <0 0x11290800 0 0x800>;
+   u2port0: usb-phy@11290800 {
+   reg = <0 0x11290800 0 0x100>;
+   clocks = <&apmixedsys CLK_APMIXED_REF2USB_TX>;
+   clock-names = "ref";
#phy-cells = <1>;
status = "okay";
};
 
-   phy_port1: port@11291000 {
-   reg = <0 0x11291000 0 0x800>;
+   u3port0: usb-phy@11290900 {
+   reg = <0 0x11290800 0 0x700>;
+   clocks = <&clk26m>;
+   clock-names = "ref";
+   #phy-cells = <1>;
+   status = "okay";
+   };
+
+   u2port1: usb-phy@11291000 {
+   reg = <0 0x11291000 0 0x100>;
+   clocks = <&apmixedsys CLK_APMIXED_REF2USB_TX>;
+   clock-names = "ref";
#phy-cells = <1>;
status = "okay";
};
@@ -64,7 +84,54 @@ Example:
 
 usb30: usb@1127 {
...
-   phys = <&phy_port0 PHY_TYPE_USB3>;
-   phy-names = "usb3-0";
+   phys = <&u2port0 PHY_TYPE_USB2>, <&u3port0 PHY_TYPE_USB3>;
+   phy-names = "usb2-0", "usb3-0";
...
 };
+
+
+Layout differences of banks between mt8173/mt2701 and mt2712
+-
+mt8173 and mt2701:
+portoffsetbank
+shared  0xSPLLC
+0x0100FMREG
+u2 port00x0800U2PHY_COM
+u3 port00x0900U3PHYD
+0x0a00U3PHYD_BANK2
+0x0b00U3PHYA
+0x0c00U3PHYA_DA
+u2 port10x1000U2PHY_COM
+u3 port10x1100U3PHYD
+0x1200U3PHYD_BANK2
+0x1300U3PHYA
+0x1400U3PHYA_DA
+u2 port20x1800U2PHY_COM
+...
+
+mt2712:
+portoffsetbank
+u2 port00xMISC
+0x0100FMREG
+0x0300U2PHY_COM
+u3 port00x0700SPLLC
+0x0800CHIP
+0x0900U3PHYD
+0x0a00U3PHYD_BANK2
+0x0b00U3PHYA
+0x0c00U3PHY

[PATCH v5 7/9] arm64: dts: mt8173: split usb SuperSpeed port into two ports

2017-03-31 Thread Chunfeng Yun
split the old SuperSpeed port node into a HighSpeed one and a new
SuperSpeed one.

Signed-off-by: Chunfeng Yun 
---
 arch/arm64/boot/dts/mediatek/mt8173.dtsi |   19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 6922252..1dc4629 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -731,8 +731,9 @@
  <0 0x11280700 0 0x0100>;
reg-names = "mac", "ippc";
interrupts = ;
-   phys = <&phy_port0 PHY_TYPE_USB3>,
-  <&phy_port1 PHY_TYPE_USB2>;
+   phys = <&u2port0 PHY_TYPE_USB2>,
+  <&u3port0 PHY_TYPE_USB3>,
+  <&u2port1 PHY_TYPE_USB2>;
power-domains = <&scpsys MT8173_POWER_DOMAIN_USB>;
clocks = <&topckgen CLK_TOP_USB30_SEL>,
 <&clk26m>,
@@ -770,14 +771,20 @@
ranges;
status = "okay";
 
-   phy_port0: port@11290800 {
-   reg = <0 0x11290800 0 0x800>;
+   u2port0: usb-phy@11290800 {
+   reg = <0 0x11290800 0 0x100>;
#phy-cells = <1>;
status = "okay";
};
 
-   phy_port1: port@11291000 {
-   reg = <0 0x11291000 0 0x800>;
+   u3port0: usb-phy@11290900 {
+   reg = <0 0x11290900 0 0x700>;
+   #phy-cells = <1>;
+   status = "okay";
+   };
+
+   u2port1: usb-phy@11291000 {
+   reg = <0 0x11291000 0 0x100>;
#phy-cells = <1>;
status = "okay";
};
-- 
1.7.9.5

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


[PATCH v5 6/9] phy: phy-mt65xx-usb3: disable 100uA extraction from SS port to HS port

2017-03-31 Thread Chunfeng Yun
There will be a problem if SS port is diasbled and HS port extracts
100uA from SS port, so disable extract 100uA from SS port in the case,
when disable it, PA0_RG_USB20_INTR_EN should be set, otherwise HS port
only works on LS.

Signed-off-by: Chunfeng Yun 
---
 drivers/phy/phy-mt65xx-usb3.c |   24 ++--
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/phy/phy-mt65xx-usb3.c b/drivers/phy/phy-mt65xx-usb3.c
index 5eea65c..ee83d93 100644
--- a/drivers/phy/phy-mt65xx-usb3.c
+++ b/drivers/phy/phy-mt65xx-usb3.c
@@ -46,6 +46,7 @@
 
 #define U3P_USBPHYACR0 0x000
 #define PA0_RG_U2PLL_FORCE_ON  BIT(15)
+#define PA0_RG_USB20_INTR_EN   BIT(5)
 
 #define U3P_USBPHYACR2 0x008
 #define PA2_RG_SIF_U2PLL_FORCE_EN  BIT(18)
@@ -339,6 +340,15 @@ static void phy_instance_init(struct mt65xx_u3phy *u3phy,
tmp &= ~P2C_RG_UART_EN;
writel(tmp, com + U3P_U2PHYDTM1);
 
+   tmp = readl(com + U3P_USBPHYACR0);
+   tmp |= PA0_RG_USB20_INTR_EN;
+   writel(tmp, com + U3P_USBPHYACR0);
+
+   /* disable switch 100uA current to SSUSB */
+   tmp = readl(com + U3P_USBPHYACR5);
+   tmp &= ~PA5_RG_U2_HS_100U_U3_EN;
+   writel(tmp, com + U3P_USBPHYACR5);
+
if (!index) {
tmp = readl(com + U3P_U2PHYACR4);
tmp &= ~P2C_U2_GPIO_CTR_MSK;
@@ -393,13 +403,6 @@ static void phy_instance_power_on(struct mt65xx_u3phy 
*u3phy,
tmp |= PA6_RG_U2_OTG_VBUSCMP_EN;
writel(tmp, com + U3P_USBPHYACR6);
 
-   if (!index) {
-   /* switch 100uA current to SSUSB */
-   tmp = readl(com + U3P_USBPHYACR5);
-   tmp |= PA5_RG_U2_HS_100U_U3_EN;
-   writel(tmp, com + U3P_USBPHYACR5);
-   }
-
tmp = readl(com + U3P_U2PHYDTM1);
tmp |= P2C_RG_VBUSVALID | P2C_RG_AVALID;
tmp &= ~P2C_RG_SESSEND;
@@ -435,13 +438,6 @@ static void phy_instance_power_off(struct mt65xx_u3phy 
*u3phy,
tmp &= ~PA6_RG_U2_OTG_VBUSCMP_EN;
writel(tmp, com + U3P_USBPHYACR6);
 
-   if (!index) {
-   /* switch 100uA current back to USB2.0 */
-   tmp = readl(com + U3P_USBPHYACR5);
-   tmp &= ~PA5_RG_U2_HS_100U_U3_EN;
-   writel(tmp, com + U3P_USBPHYACR5);
-   }
-
/* let suspendm=0, set utmi into analog power down */
tmp = readl(com + U3P_U2PHYDTM0);
tmp &= ~P2C_RG_SUSPENDM;
-- 
1.7.9.5

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


[PATCH v5 8/9] arm64: dts: mt8173: move clock from phy node into port nodes

2017-03-31 Thread Chunfeng Yun
there is a reference clock for each port, HighSpeed port is 48M,
and SuperSpeed port is usually 26M. it is flexible to move it
into port node, then unused clock can be disabled.

Signed-off-by: Chunfeng Yun 
---
 arch/arm64/boot/dts/mediatek/mt8173.dtsi |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 1dc4629..1c9e0d5 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -764,8 +764,6 @@
u3phy: usb-phy@1129 {
compatible = "mediatek,mt8173-u3phy";
reg = <0 0x1129 0 0x800>;
-   clocks = <&apmixedsys CLK_APMIXED_REF2USB_TX>;
-   clock-names = "u3phya_ref";
#address-cells = <2>;
#size-cells = <2>;
ranges;
@@ -773,18 +771,24 @@
 
u2port0: usb-phy@11290800 {
reg = <0 0x11290800 0 0x100>;
+   clocks = <&apmixedsys CLK_APMIXED_REF2USB_TX>;
+   clock-names = "ref";
#phy-cells = <1>;
status = "okay";
};
 
u3port0: usb-phy@11290900 {
reg = <0 0x11290900 0 0x700>;
+   clocks = <&clk26m>;
+   clock-names = "ref";
#phy-cells = <1>;
status = "okay";
};
 
u2port1: usb-phy@11291000 {
reg = <0 0x11291000 0 0x100>;
+   clocks = <&apmixedsys CLK_APMIXED_REF2USB_TX>;
+   clock-names = "ref";
#phy-cells = <1>;
status = "okay";
};
-- 
1.7.9.5

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


[PATCH v5 2/9] phy: phy-mt65xx-usb3: increase LFPS filter threshold

2017-03-31 Thread Chunfeng Yun
Increase LFPS filter threshold to avoid some fake remote wakeup
signal which cause U3 link fail and link to U2 only at about
0.01% probability.

Signed-off-by: Chunfeng Yun 
---
 drivers/phy/phy-mt65xx-usb3.c |9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/phy/phy-mt65xx-usb3.c b/drivers/phy/phy-mt65xx-usb3.c
index fe2392a..4fd47d0 100644
--- a/drivers/phy/phy-mt65xx-usb3.c
+++ b/drivers/phy/phy-mt65xx-usb3.c
@@ -106,6 +106,10 @@
 #define P3A_RG_XTAL_EXT_EN_U3  GENMASK(11, 10)
 #define P3A_RG_XTAL_EXT_EN_U3_VAL(x)   ((0x3 & (x)) << 10)
 
+#define U3P_U3_PHYD_LFPS1  (SSUSB_SIFSLV_U3PHYD_BASE + 0x000c)
+#define P3D_RG_FWAKE_THGENMASK(21, 16)
+#define P3D_RG_FWAKE_TH_VAL(x) ((0x3f & (x)) << 16)
+
 #define U3P_PHYD_CDR1  (SSUSB_SIFSLV_U3PHYD_BASE + 0x005c)
 #define P3D_RG_CDR_BIR_LTD1GENMASK(28, 24)
 #define P3D_RG_CDR_BIR_LTD1_VAL(x) ((0x1f & (x)) << 24)
@@ -303,6 +307,11 @@ static void phy_instance_init(struct mt65xx_u3phy *u3phy,
tmp |= P3D_RG_CDR_BIR_LTD0_VAL(0xc) | P3D_RG_CDR_BIR_LTD1_VAL(0x3);
writel(tmp, port_base + U3P_PHYD_CDR1);
 
+   tmp = readl(port_base + U3P_U3_PHYD_LFPS1);
+   tmp &= ~P3D_RG_FWAKE_TH;
+   tmp |= P3D_RG_FWAKE_TH_VAL(0x34);
+   writel(tmp, port_base + U3P_U3_PHYD_LFPS1);
+
tmp = readl(port_base + U3P_U3_PHYD_RXDET1);
tmp &= ~P3D_RG_RXDET_STB2_SET;
tmp |= P3D_RG_RXDET_STB2_SET_VAL(0x10);
-- 
1.7.9.5

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