Re: [PATCH] tools: usb: testusb: update default vary for superspeed

2017-04-26 Thread Felipe Balbi

Hi,

Alan Stern  writes:
> On Tue, 25 Apr 2017, Felipe Balbi wrote:
>
>> Currently, default vary will not accomodate superspeed endpoints
>> causing unexpected babble errors in the IN direction. Let's update
>> default 'vary' parameter so that we can maintain a "short-less"
>> transfer as hinted at the comment.
>> 
>> Reported-by: Ammy Yi 
>> Signed-off-by: Felipe Balbi 
>> ---
>>  tools/usb/testusb.c | 6 --
>>  1 file changed, 4 insertions(+), 2 deletions(-)
>> 
>> diff --git a/tools/usb/testusb.c b/tools/usb/testusb.c
>> index 0692d99b6d8f..7c418fa87194 100644
>> --- a/tools/usb/testusb.c
>> +++ b/tools/usb/testusb.c
>> @@ -387,6 +387,8 @@ int main (int argc, char **argv)
>>  /* pick defaults that works with all speeds, without short packets.
>>   *
>>   * Best per-frame data rates:
>> + * super speed,bulk  1024 * 16 * 13 = 212992
>> + * interrupt 1024 *  3 * 8 = 24576
>>   * high speed, bulk   512 * 13 * 8 = 53248
>>   * interrupt 1024 *  3 * 8 = 24576
>>   * full speed, bulk/intr   64 * 19 =  1216
>
> The first new comment line looks a little weird.  The three numeric
> columns are: bytes/packet, packets/microframe, and microframes/frame.  
> So it should be:
>
>   *   super speed,bulk 1024 * 16 * 8 = 131072
>
> Yes?

indeed, I'll update it resend. thanks

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


Re: [PATCH] usb: chipidea: udc: fix NULL pointer dereference if udc_start failed

2017-04-26 Thread Jisheng Zhang
On Tue, 25 Apr 2017 17:21:59 +0200
Stefan Wahren  wrote:

> Am 25.04.2017 um 11:20 schrieb Peter Chen:
> >
>  diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
>  index f88e9157fad0..60a786c87c06 100644
>  --- a/drivers/usb/chipidea/udc.c
>  +++ b/drivers/usb/chipidea/udc.c
>  @@ -1984,6 +1984,7 @@ static void udc_id_switch_for_host(struct
>  ci_hdrc *ci)  int ci_hdrc_gadget_init(struct ci_hdrc *ci)  {
>   struct ci_role_driver *rdrv;
>  +int ret;
> 
>   if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DC))
>   return -ENXIO;
>  @@ -1996,7 +1997,10 @@ int ci_hdrc_gadget_init(struct ci_hdrc *ci)
>   rdrv->stop  = udc_id_switch_for_host;
>   rdrv->irq   = udc_irq;
>   rdrv->name  = "gadget";
>  -ci->roles[CI_ROLE_GADGET] = rdrv;
> 
>  -return udc_start(ci);
>  +ret = udc_start(ci);
>  +if (!ret)
>  +ci->roles[CI_ROLE_GADGET] = rdrv;
>  +
>  +return ret;
>   }
>  --  
> >>> Thanks for fixing it. In fact, we'd better return failure if ret &&
> >>> ret != -ENXIO at probe, it stands for initialization for host or
> >>> gadget has failed.
> >>>  
> >> I got your meaning. I'll cook v2. I don't have preference, since either 
> >> one can fix the
> >> issue.
> >>  
> > Both are needed, you don't need to send this one again. Only a new one, 
> > thanks.  
> 
> I'm not sure how easy it is to reproduce the issue.

It's easy to reproduce it (100%) on arm64 platforms after commit
1dccb598df549 ("arm64: simplify dma_get_ops"). This commit could
make all dma related operations failed, then udc_start() would fail
with -ENOMEM.

On other platforms, it's not easy.

> 
> Shouldn't make a Fixes tag sense at least?

maybe 3f124d233e97 ("usb: chipidea: add role init and destroy APIs"
--
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: chipidea: properly handle host or gadget initialization failure

2017-04-26 Thread Peter Chen
On Tue, Apr 25, 2017 at 05:43:11PM +0800, Jisheng Zhang wrote:
> If ci_hdrc_host_init() or ci_hdrc_gadget_init() returns error and the
> error != -ENXIO, as Peter pointed out, "it stands for initialization
> for host or gadget has failed", so we'd better return failure rather
> continue.
> 
> Signed-off-by: Jisheng Zhang 
> ---
>  drivers/usb/chipidea/core.c | 25 +++--
>  1 file changed, 19 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
> index 79ad8e91632e..047afdbb7049 100644
> --- a/drivers/usb/chipidea/core.c
> +++ b/drivers/usb/chipidea/core.c
> @@ -930,20 +930,28 @@ static int ci_hdrc_probe(struct platform_device *pdev)
>   /* initialize role(s) before the interrupt is requested */
>   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
>   ret = ci_hdrc_host_init(ci);
> - if (ret)
> - dev_info(dev, "doesn't support host\n");
> + if (ret) {
> + if (ret == -ENXIO)
> + dev_info(dev, "doesn't support host\n");
> + else
> + goto deinit_phy;
> + }
>   }
>  
>   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
>   ret = ci_hdrc_gadget_init(ci);
> - if (ret)
> - dev_info(dev, "doesn't support gadget\n");
> + if (ret) {
> + if (ret == -ENXIO)
> + dev_info(dev, "doesn't support gadget\n");
> + else
> + goto deinit_host;
> + }
>   }
>  
>   if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
>   dev_err(dev, "no supported roles\n");
>   ret = -ENODEV;
> - goto deinit_phy;
> + goto deinit_gadget;
>   }
>  
>   if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) {
> @@ -1013,7 +1021,12 @@ static int ci_hdrc_probe(struct platform_device *pdev)
>   return 0;
>  
>  stop:
> - ci_role_destroy(ci);
> + if (ci->is_otg)
> + ci_hdrc_otg_destroy(ci);
> +deinit_gadget:
> + ci_hdrc_gadget_destroy(ci);
> +deinit_host:
> + ci_hdrc_host_destroy(ci);
>  deinit_phy:
>   ci_usb_phy_exit(ci);
>  ulpi_exit:
> -- 
> 2.11.0
> 

You change is ok, there are more things need to change for this issue,
would you mind adding below changes to your patch, and send v2. Below
changes are based on your changes.

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index c55bcdd..4cad8a9 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -818,7 +818,7 @@ static inline void ci_role_destroy(struct ci_hdrc *ci)
 {
ci_hdrc_gadget_destroy(ci);
ci_hdrc_host_destroy(ci);
-   if (ci->is_otg)
+   if (ci->is_otg && ci->roles[CI_ROLE_GADGET])
ci_hdrc_otg_destroy(ci);
 }
 
@@ -1005,7 +1005,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
ret = ci_hdrc_otg_init(ci);
if (ret) {
dev_err(dev, "init otg fails, ret = %d\n", ret);
-   goto stop;
+   goto deinit_gadget;
}
}
 
@@ -1075,7 +1075,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
 remove_debug:
dbg_remove_files(ci);
 stop:
-   if (ci->is_otg)
+   if (ci->is_otg && ci->roles[CI_ROLE_GADGET])
ci_hdrc_otg_destroy(ci);
 deinit_gadget:
ci_hdrc_gadget_destroy(ci);

-- 

Best Regards,
Peter Chen
--
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] HID: usbhid: Add HID_QUIRK_NOGET for Aten CS-1758 KVM switch

2017-04-26 Thread Jiri Kosina
On Tue, 25 Apr 2017, Vasilis Liaskovitis wrote:

> Like other switches, the Aten CS-1758 KVM switch needs a quirk to avoid
> spewing errors:
> 
> [12599018.071059] usb 5-2: input irq status -75 received
> [12599018.079053] usb 5-2: input irq status -75 received

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs

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


Re: [RFC] usb: chipidea: set dma_ops for the created ci_hdrc platform_device

2017-04-26 Thread Jisheng Zhang

On Tue, 25 Apr 2017 13:09:27 +0200 Arnd Bergmann wrote:

> On Tue, Apr 25, 2017 at 12:01 PM, Jisheng Zhang  wrote:
> > Hi all,
> >
> > After commit 1dccb598df549 ("arm64: simplify dma_get_ops"), the chipidea
> > driver can't work any more on Marvell Berlin arm64 platforms, the reason
> > is the created ci_hdrc platform_device's dma_ops is dummy_dma_ops, so all
> > dma related operations will fail. The fix I can think of would be something
> > as below:
> >
> > And I noticed that dwc3 has the same issue[1], and as pointed out in its
> > discussion, the patch can't fix None-DT platforms, so could you please
> > guide me what's the proper fix which can be mainlined?  
> 
> I think the right solution is:
> 
> - Set the "sysdev" pointer tin the USB device o the device structure that
>   was created by DT or the legacy board file and remove the manual
>   setting of dma_mask,  parms and the dma_configure. This should
>   make everything work as expected in case of DT
> 

oh yeah! I see a proper fix in linux-next tree, thanks for fixing it.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: chipidea: udc: fix NULL pointer dereference if udc_start failed

2017-04-26 Thread Peter Chen
On Wed, Apr 26, 2017 at 04:25:26PM +0800, Jisheng Zhang wrote:
> On Tue, 25 Apr 2017 17:21:59 +0200
> Stefan Wahren  wrote:
> 
> > Am 25.04.2017 um 11:20 schrieb Peter Chen:
> > >
> >  diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> >  index f88e9157fad0..60a786c87c06 100644
> >  --- a/drivers/usb/chipidea/udc.c
> >  +++ b/drivers/usb/chipidea/udc.c
> >  @@ -1984,6 +1984,7 @@ static void udc_id_switch_for_host(struct
> >  ci_hdrc *ci)  int ci_hdrc_gadget_init(struct ci_hdrc *ci)  {
> > struct ci_role_driver *rdrv;
> >  +  int ret;
> > 
> > if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DC))
> > return -ENXIO;
> >  @@ -1996,7 +1997,10 @@ int ci_hdrc_gadget_init(struct ci_hdrc *ci)
> > rdrv->stop  = udc_id_switch_for_host;
> > rdrv->irq   = udc_irq;
> > rdrv->name  = "gadget";
> >  -  ci->roles[CI_ROLE_GADGET] = rdrv;
> > 
> >  -  return udc_start(ci);
> >  +  ret = udc_start(ci);
> >  +  if (!ret)
> >  +  ci->roles[CI_ROLE_GADGET] = rdrv;
> >  +
> >  +  return ret;
> >   }
> >  --  
> > >>> Thanks for fixing it. In fact, we'd better return failure if ret &&
> > >>> ret != -ENXIO at probe, it stands for initialization for host or
> > >>> gadget has failed.
> > >>>  
> > >> I got your meaning. I'll cook v2. I don't have preference, since either 
> > >> one can fix the
> > >> issue.
> > >>  
> > > Both are needed, you don't need to send this one again. Only a new one, 
> > > thanks.  
> > 
> > I'm not sure how easy it is to reproduce the issue.
> 
> It's easy to reproduce it (100%) on arm64 platforms after commit
> 1dccb598df549 ("arm64: simplify dma_get_ops"). This commit could
> make all dma related operations failed, then udc_start() would fail
> with -ENOMEM.
> 
> On other platforms, it's not easy.
> 
> > 
> > Shouldn't make a Fixes tag sense at least?
> 
> maybe 3f124d233e97 ("usb: chipidea: add role init and destroy APIs"

I will cc stable, thanks.

-- 

Best Regards,
Peter Chen
--
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: chipidea: properly handle host or gadget initialization failure

2017-04-26 Thread Jisheng Zhang
If ci_hdrc_host_init() or ci_hdrc_gadget_init() returns error and the
error != -ENXIO, as Peter pointed out, "it stands for initialization
for host or gadget has failed", so we'd better return failure rather
continue.

And before destroying the otg, i.e ci_hdrc_otg_destroy(ci), we should
also check ci->roles[CI_ROLE_GADGET].

Signed-off-by: Jisheng Zhang 
---
Since v1:
 - check ci->roles[CI_ROLE_GADGET] before destroying the otg, suggested
   by Peter.

 drivers/usb/chipidea/core.c | 29 +
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 79ad8e91632e..0192a26ec0f9 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -821,7 +821,7 @@ static inline void ci_role_destroy(struct ci_hdrc *ci)
 {
ci_hdrc_gadget_destroy(ci);
ci_hdrc_host_destroy(ci);
-   if (ci->is_otg)
+   if (ci->is_otg && ci->roles[CI_ROLE_GADGET])
ci_hdrc_otg_destroy(ci);
 }
 
@@ -930,27 +930,35 @@ static int ci_hdrc_probe(struct platform_device *pdev)
/* initialize role(s) before the interrupt is requested */
if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
ret = ci_hdrc_host_init(ci);
-   if (ret)
-   dev_info(dev, "doesn't support host\n");
+   if (ret) {
+   if (ret == -ENXIO)
+   dev_info(dev, "doesn't support host\n");
+   else
+   goto deinit_phy;
+   }
}
 
if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
ret = ci_hdrc_gadget_init(ci);
-   if (ret)
-   dev_info(dev, "doesn't support gadget\n");
+   if (ret) {
+   if (ret == -ENXIO)
+   dev_info(dev, "doesn't support gadget\n");
+   else
+   goto deinit_host;
+   }
}
 
if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
dev_err(dev, "no supported roles\n");
ret = -ENODEV;
-   goto deinit_phy;
+   goto deinit_gadget;
}
 
if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) {
ret = ci_hdrc_otg_init(ci);
if (ret) {
dev_err(dev, "init otg fails, ret = %d\n", ret);
-   goto stop;
+   goto deinit_gadget;
}
}
 
@@ -1013,7 +1021,12 @@ static int ci_hdrc_probe(struct platform_device *pdev)
return 0;
 
 stop:
-   ci_role_destroy(ci);
+   if (ci->is_otg && ci->roles[CI_ROLE_GADGET])
+   ci_hdrc_otg_destroy(ci);
+deinit_gadget:
+   ci_hdrc_gadget_destroy(ci);
+deinit_host:
+   ci_hdrc_host_destroy(ci);
 deinit_phy:
ci_usb_phy_exit(ci);
 ulpi_exit:
-- 
2.11.0

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


Re: [PATCH v2] usb: misc: legousbtower: Fix buffers on stack

2017-04-26 Thread Greg Kroah-Hartman
On Tue, Apr 25, 2017 at 10:28:42PM +0300, Maksim Salau wrote:
> On Tue, 25 Apr 2017 20:04:24 +0200
> Greg Kroah-Hartman  wrote:
> 
> > On Sat, Apr 22, 2017 at 07:24:37PM +0300, Maksim Salau wrote:
> > > Allocate buffers on HEAP instead of STACK for local structures
> > > that are to be received using usb_control_msg().
> > > 
> > > Signed-off-by: Maksim Salau 
> > > Tested-by: Alfredo Rafael Vicente Boix 
> > > Cc: sta...@vger.kernel.org  
> > 
> > This patch does not apply to usb-next, what did you make it against?
> > 
> > Can you rebase it and resend?
> > 
> > thanks,
> > 
> > greg k-h
> 
> Hi Greg,
> 
> I've created the patch against linux-stable v4.10.12. I've checked history 
> of the driver and it turns out that the patch conflicts with 
> 9b181166f17534a82b4b628b13e524a893715dfc
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/commit/drivers/usb/misc/legousbtower.c?h=usb-next&id=9b181166f17534a82b4b628b13e524a893715dfc
> 
> There are no conflicting changes, but context has changed.
> I'll rebase and resend shortly.
> 
> The same patch can't be used for stable and for usb-next anymore. Is there
> any chance to backport the fix for stable?

Yes, we can backport it, I'll mark it for stable and do the backport
when it hits Linus's tree after 4.12-rc1 is out.

thanks,

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


Re: [PATCH v3] usb: misc: legousbtower: Fix buffers on stack

2017-04-26 Thread Greg Kroah-Hartman
On Tue, Apr 25, 2017 at 10:49:21PM +0300, Maksim Salau wrote:
> Allocate buffers on HEAP instead of STACK for local structures
> that are to be received using usb_control_msg().
> 
> Signed-off-by: Maksim Salau 
> Tested-by: Alfredo Rafael Vicente Boix ;
> Cc: stable 
> 
> ---
>   Changes in v3:
>* rebased against usb-next;
>* removed Tested-by: Alfredo Rafael Vicente Boix ;

I added this back, as it matters, and your change from the previous
version was trivial.

>* removed Cc: sta...@vger.kernel.org
>  since this patch doesn't apply against v4.10.12

I added this back as well :)

thanks,

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


Re: [PATCH] usb: musb: don't mark of_dev_auxdata as initdata

2017-04-26 Thread Greg Kroah-Hartman
On Tue, Apr 25, 2017 at 10:04:53PM +0200, Arnd Bergmann wrote:
> The probe function is not __init since it can be called for deferred
> probing or when unbinding/rebinding the device, and therefore it must
> not reference objects in __initdata, as pointed out by this link
> time warning:
> 
> WARNING: drivers/usb/musb/da8xx.o(.text+0x9d4): Section mismatch in reference 
> from the function da8xx_probe() to the (unknown reference) 
> .init.data:(unknown)
> 
> This removes the annotation.
> 
> Reported-by: Olof's autobuilder 
> Fixes: d6299b6efbf6 ("usb: musb: Add support of CPPI 4.1 DMA controller to 
> DA8xx")
> Signed-off-by: Arnd Bergmann 

Now applied as I think Bin is offline for a bit.

thanks,

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


[PATCH v2] tools: usb: testusb: update default vary for superspeed

2017-04-26 Thread Felipe Balbi
Currently, default vary will not accomodate superspeed endpoints
causing unexpected babble errors in the IN direction. Let's update
default 'vary' parameter so that we can maintain a "short-less"
transfer as hinted at the comment.

Reported-by: Ammy Yi 
Signed-off-by: Felipe Balbi 
---

Changes since v1:
- fix data rate calculation per Alan Stern's suggestion
- align results to maintain previous consistency

 tools/usb/testusb.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/tools/usb/testusb.c b/tools/usb/testusb.c
index 0692d99b6d8f..2d89b5f686b1 100644
--- a/tools/usb/testusb.c
+++ b/tools/usb/testusb.c
@@ -387,15 +387,17 @@ int main (int argc, char **argv)
/* pick defaults that works with all speeds, without short packets.
 *
 * Best per-frame data rates:
-* high speed, bulk   512 * 13 * 8 = 53248
-* interrupt 1024 *  3 * 8 = 24576
-* full speed, bulk/intr   64 * 19 =  1216
-* interrupt   64 *  1 =64
-*  low speed, interrupt8 *  1 = 8
+* super speed,bulk  1024 * 16 * 8 = 131072
+* interrupt 1024 *  3 * 8 =  24576
+* high speed, bulk   512 * 13 * 8 =  53248
+* interrupt 1024 *  3 * 8 =  24576
+* full speed, bulk/intr   64 * 19 =   1216
+* interrupt   64 *  1 = 64
+*  low speed, interrupt8 *  1 =  8
 */
param.iterations = 1000;
param.length = 1024;
-   param.vary = 512;
+   param.vary = 1024;
param.sglen = 32;
 
/* for easy use when hotplugging */
@@ -457,7 +459,7 @@ int main (int argc, char **argv)
"\t-c iterationsdefault 1000\n"
"\t-s transfer length   default 1024\n"
"\t-g sglen default 32\n"
-   "\t-v vary  default 512\n",
+   "\t-v vary  default 1024\n",
argv[0]);
return 1;
}
-- 
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 v4] usb: typec: Don't prevent using constant typec_mode_desc initializers

2017-04-26 Thread Heikki Krogerus
Hi Mats,

On Tue, Apr 25, 2017 at 11:49:47PM +0200, Mats Karrman wrote:
> In some situations, e.g. when registering alternate modes for local typec
> ports, it may be handy to use constant mode descriptors. Allow this by
> changing the mode descriptor arguments of typec_port_register_altmode()
> et.al. to using const pointers.
> 
> Signed-off-by: Mats Karrman 
> Reviewed-by: Guenter Roeck 

This is OK by me. FWIW:

Acked-by: Heikki Krogerus 


FYI, in case you guys are interested, I'm collecting all the typec
stuff to my github tree [1] "typec" branch.

[1] git://github.com/krohei/linux


Thanks Mats,

> ---
>  drivers/usb/typec/typec.c | 11 ++-
>  include/linux/usb/typec.h |  6 +++---
>  2 files changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/typec/typec.c b/drivers/usb/typec/typec.c
> index 89e540b..db5ee73 100644
> --- a/drivers/usb/typec/typec.c
> +++ b/drivers/usb/typec/typec.c
> @@ -291,7 +291,7 @@ typec_altmode_roles_show(struct device *dev, struct 
> device_attribute *attr,
>  }
>  
>  static void typec_init_modes(struct typec_altmode *alt,
> -  struct typec_mode_desc *desc, bool is_port)
> +  const struct typec_mode_desc *desc, bool is_port)
>  {
>   int i;
>  
> @@ -378,7 +378,8 @@ static const struct device_type typec_altmode_dev_type = {
>  };
>  
>  static struct typec_altmode *
> -typec_register_altmode(struct device *parent, struct typec_altmode_desc 
> *desc)
> +typec_register_altmode(struct device *parent,
> +const struct typec_altmode_desc *desc)
>  {
>   struct typec_altmode *alt;
>   int ret;
> @@ -495,7 +496,7 @@ EXPORT_SYMBOL_GPL(typec_partner_set_identity);
>   */
>  struct typec_altmode *
>  typec_partner_register_altmode(struct typec_partner *partner,
> -struct typec_altmode_desc *desc)
> +const struct typec_altmode_desc *desc)
>  {
>   return typec_register_altmode(&partner->dev, desc);
>  }
> @@ -590,7 +591,7 @@ static const struct device_type typec_plug_dev_type = {
>   */
>  struct typec_altmode *
>  typec_plug_register_altmode(struct typec_plug *plug,
> - struct typec_altmode_desc *desc)
> + const struct typec_altmode_desc *desc)
>  {
>   return typec_register_altmode(&plug->dev, desc);
>  }
> @@ -1159,7 +1160,7 @@ EXPORT_SYMBOL_GPL(typec_set_pwr_opmode);
>   */
>  struct typec_altmode *
>  typec_port_register_altmode(struct typec_port *port,
> - struct typec_altmode_desc *desc)
> + const struct typec_altmode_desc *desc)
>  {
>   return typec_register_altmode(&port->dev, desc);
>  }
> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> index ec78204..d1d2ebc 100644
> --- a/include/linux/usb/typec.h
> +++ b/include/linux/usb/typec.h
> @@ -117,13 +117,13 @@ struct typec_altmode_desc {
>  
>  struct typec_altmode
>  *typec_partner_register_altmode(struct typec_partner *partner,
> - struct typec_altmode_desc *desc);
> + const struct typec_altmode_desc *desc);
>  struct typec_altmode
>  *typec_plug_register_altmode(struct typec_plug *plug,
> -  struct typec_altmode_desc *desc);
> +  const struct typec_altmode_desc *desc);
>  struct typec_altmode
>  *typec_port_register_altmode(struct typec_port *port,
> -  struct typec_altmode_desc *desc);
> +  const struct typec_altmode_desc *desc);
>  void typec_unregister_altmode(struct typec_altmode *altmode);
>  
>  struct typec_port *typec_altmode2port(struct typec_altmode *alt);
> -- 
> 2.1.4

-- 
heikki
--
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] staging: gdm724x: gdm_mux: fix use-after-free on module unload

2017-04-26 Thread Johan Hovold
Make sure to deregister the USB driver before releasing the tty driver
to avoid use-after-free in the USB disconnect callback where the tty
devices are deregistered.

Fixes: 61e121047645 ("staging: gdm7240: adding LTE USB driver")
Cc: stable  # 3.12
Cc: Won Kang 
Signed-off-by: Johan Hovold 
---
 drivers/staging/gdm724x/gdm_mux.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/gdm724x/gdm_mux.c 
b/drivers/staging/gdm724x/gdm_mux.c
index 400969170d1c..f03e43b1b5f6 100644
--- a/drivers/staging/gdm724x/gdm_mux.c
+++ b/drivers/staging/gdm724x/gdm_mux.c
@@ -664,9 +664,8 @@ static int __init gdm_usb_mux_init(void)
 
 static void __exit gdm_usb_mux_exit(void)
 {
-   unregister_lte_tty_driver();
-
usb_deregister(&gdm_mux_driver);
+   unregister_lte_tty_driver();
 }
 
 module_init(gdm_usb_mux_init);
-- 
2.12.2

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


[PATCH 4/5] usb: gadget: udc: renesas_usb3: Fix PN_INT_ENA disabling timing

2017-04-26 Thread Yoshihiro Shimoda
The PN_INT_ENA register should be used after usb3_pn_change() is called.
So, this patch moves the access from renesas_usb3_stop_controller() to
usb3_disable_pipe_n().

Fixes: 746bfe63bba3 ("usb: gadget: renesas_usb3: add support for Renesas USB3.0 
peripheral controller")
Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/gadget/udc/renesas_usb3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index c05097b..cd4c885 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -623,7 +623,6 @@ static void renesas_usb3_stop_controller(struct 
renesas_usb3 *usb3)
 {
usb3_disconnect(usb3);
usb3_write(usb3, 0, USB3_P0_INT_ENA);
-   usb3_write(usb3, 0, USB3_PN_INT_ENA);
usb3_write(usb3, 0, USB3_USB_OTG_INT_ENA);
usb3_write(usb3, 0, USB3_USB_INT_ENA_1);
usb3_write(usb3, 0, USB3_USB_INT_ENA_2);
@@ -1682,6 +1681,7 @@ static int usb3_disable_pipe_n(struct renesas_usb3_ep 
*usb3_ep)
 
spin_lock_irqsave(&usb3->lock, flags);
if (!usb3_pn_change(usb3, usb3_ep->num)) {
+   usb3_write(usb3, 0, USB3_PN_INT_ENA);
usb3_write(usb3, 0, USB3_PN_RAMMAP);
usb3_clear_bit(usb3, PN_CON_EN, USB3_PN_CON);
}
-- 
1.9.1

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


[PATCH 2/5] usb: gadget: udc: renesas_usb3: fix deadlock by spinlock

2017-04-26 Thread Yoshihiro Shimoda
This patch fixes an issue that this driver is possible to cause
deadlock by double-spinclocked in renesas_usb3_stop_controller().
So, this patch removes spinlock API calling in renesas_usb3_stop().
(In other words, the previous code had a redundant lock.)

Fixes: 746bfe63bba3 ("usb: gadget: renesas_usb3: add support for Renesas USB3.0 
peripheral controller")
Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/gadget/udc/renesas_usb3.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 10585da..e27d948 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -1810,14 +1810,11 @@ static int renesas_usb3_start(struct usb_gadget *gadget,
 static int renesas_usb3_stop(struct usb_gadget *gadget)
 {
struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget);
-   unsigned long flags;
 
-   spin_lock_irqsave(&usb3->lock, flags);
usb3->softconnect = false;
usb3->gadget.speed = USB_SPEED_UNKNOWN;
usb3->driver = NULL;
renesas_usb3_stop_controller(usb3);
-   spin_unlock_irqrestore(&usb3->lock, flags);
 
pm_runtime_put(usb3_to_dev(usb3));
pm_runtime_disable(usb3_to_dev(usb3));
-- 
1.9.1

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


[PATCH 5/5] usb: gadget: udc: renesas_usb3: add support for dedicated DMAC

2017-04-26 Thread Yoshihiro Shimoda
The USB3.0 peripheral controller on R-Car SoCs has a dedicated DMAC.
The DMAC needs a "PRD table" in system memory and the DMAC can have
four PRD tables. This patch adds support for the DMAC.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/gadget/udc/renesas_usb3.c | 393 ++
 1 file changed, 393 insertions(+)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index cd4c885..389051e 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -9,6 +9,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -27,6 +28,8 @@
 #define USB3_AXI_INT_ENA   0x00c
 #define USB3_DMA_INT_STA   0x010
 #define USB3_DMA_INT_ENA   0x014
+#define USB3_DMA_CH0_CON(n)(0x030 + ((n) - 1) * 0x10) /* n = 1 to 4 */
+#define USB3_DMA_CH0_PRD_ADR(n)(0x034 + ((n) - 1) * 0x10) /* n = 1 to 
4 */
 #define USB3_USB_COM_CON   0x200
 #define USB3_USB20_CON 0x204
 #define USB3_USB30_CON 0x208
@@ -64,6 +67,22 @@
 /* AXI_INT_ENA and AXI_INT_STA */
 #define AXI_INT_DMAINT BIT(31)
 #define AXI_INT_EPCINT BIT(30)
+/* PRD's n = from 1 to 4 */
+#define AXI_INT_PRDEN_CLR_STA_SHIFT(n) (16 + (n) - 1)
+#define AXI_INT_PRDERR_STA_SHIFT(n)(0 + (n) - 1)
+#define AXI_INT_PRDEN_CLR_STA(n)   (1 << AXI_INT_PRDEN_CLR_STA_SHIFT(n))
+#define AXI_INT_PRDERR_STA(n)  (1 << AXI_INT_PRDERR_STA_SHIFT(n))
+
+/* DMA_INT_ENA and DMA_INT_STA */
+#define DMA_INT(n) BIT(n)
+
+/* DMA_CH0_CONn */
+#define DMA_CON_PIPE_DIR   BIT(15) /* 1: In Transfer */
+#define DMA_CON_PIPE_NO_SHIFT  8
+#define DMA_CON_PIPE_NO_MASK   GENMASK(12, DMA_CON_PIPE_NO_SHIFT)
+#define DMA_COM_PIPE_NO(n) (((n) << DMA_CON_PIPE_NO_SHIFT) & \
+DMA_CON_PIPE_NO_MASK)
+#define DMA_CON_PRD_EN BIT(0)
 
 /* LCLKSEL */
 #define LCLKSEL_LSEL   BIT(18)
@@ -231,8 +250,50 @@
 #define USB3_EP0_BUF_SIZE  8
 #define USB3_MAX_NUM_PIPES 30
 #define USB3_WAIT_US   3
+#define USB3_DMA_NUM_SETTING_AREA  4
+/*
+ * To avoid double-meaning of "0" (xferred 65536 bytes or received zlp if
+ * buffer size is 65536), this driver uses the maximum size per a entry is
+ * 32768 bytes.
+ */
+#define USB3_DMA_MAX_XFER_SIZE 32768
+#define USB3_DMA_PRD_SIZE  4096
 
 struct renesas_usb3;
+
+/* Physical Region Descriptor Table */
+struct renesas_usb3_prd {
+   u32 word1;
+#define USB3_PRD1_EBIT(30) /* the end of chain */
+#define USB3_PRD1_UBIT(29) /* completion of transfer */
+#define USB3_PRD1_DBIT(28) /* Error occurred */
+#define USB3_PRD1_INT  BIT(27) /* Interrupt occurred */
+#define USB3_PRD1_LST  BIT(26) /* Last Packet */
+#define USB3_PRD1_B_INCBIT(24)
+#define USB3_PRD1_MPS_80
+#define USB3_PRD1_MPS_16   BIT(21)
+#define USB3_PRD1_MPS_32   BIT(22)
+#define USB3_PRD1_MPS_64   (BIT(22) | BIT(21))
+#define USB3_PRD1_MPS_512  BIT(23)
+#define USB3_PRD1_MPS_1024 (BIT(23) | BIT(21))
+#define USB3_PRD1_MPS_RESERVED (BIT(23) | BIT(22) | BIT(21))
+#define USB3_PRD1_SIZE_MASKGENMASK(15, 0)
+
+   u32 bap;
+};
+#define USB3_DMA_NUM_PRD_ENTRIES   (USB3_DMA_PRD_SIZE / \
+ sizeof(struct renesas_usb3_prd))
+#define USB3_DMA_MAX_XFER_SIZE_ALL_PRDS(USB3_DMA_PRD_SIZE / \
+sizeof(struct renesas_usb3_prd) * \
+USB3_DMA_MAX_XFER_SIZE)
+
+struct renesas_usb3_dma {
+   struct renesas_usb3_prd *prd;
+   dma_addr_t prd_dma;
+   int num;/* Setting area number (from 1 to 4) */
+   bool used;
+};
+
 struct renesas_usb3_request {
struct usb_request  req;
struct list_headqueue;
@@ -242,6 +303,7 @@ struct renesas_usb3_request {
 struct renesas_usb3_ep {
struct usb_ep ep;
struct renesas_usb3 *usb3;
+   struct renesas_usb3_dma *dma;
int num;
char ep_name[USB3_EP_NAME_SIZE];
struct list_head queue;
@@ -270,6 +332,8 @@ struct renesas_usb3 {
struct renesas_usb3_ep *usb3_ep;
int num_usb3_eps;
 
+   struct renesas_usb3_dma dma[USB3_DMA_NUM_SETTING_AREA];
+
spinlock_t lock;
int disabled_count;
 
@@ -298,8 +362,18 @@ struct renesas_usb3 {
 (i) < (usb3)->num_usb3_eps;\
 (i)++, usb3_ep = usb3_get_ep(usb3, (i)))
 
+#define usb3_get_dma(usb3, i)  (&(usb3)->dma[i])
+#define usb3_for_each_dma(usb3, dma, i)\
+   for ((i) = 0, dma = usb3_get_dma((usb3), (i));  \
+(i) < USB3_DMA_NUM_SETTING_AREA;   \
+(i)++, dma = usb3_get_dma((usb3), (i)))
+
 static const char udc_name[] = "r

[PATCH 1/5] usb: gadget: udc: renesas_usb3: fix pm_runtime functions calling

2017-04-26 Thread Yoshihiro Shimoda
This patch fixes an issue that this driver is possible to access
the registers before pm_runtime_get_sync() if a gadget driver is
installed first. After that, oops happens on R-Car Gen3 environment.
To avoid it, this patch changes the pm_runtime call timing from
probe/remove to udc_start/udc_stop.

Fixes: 746bfe63bba3 ("usb: gadget: renesas_usb3: add support for Renesas USB3.0 
peripheral controller")
Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/gadget/udc/renesas_usb3.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 5a2d845..10585da 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -1799,6 +1799,9 @@ static int renesas_usb3_start(struct usb_gadget *gadget,
/* hook up the driver */
usb3->driver = driver;
 
+   pm_runtime_enable(usb3_to_dev(usb3));
+   pm_runtime_get_sync(usb3_to_dev(usb3));
+
renesas_usb3_init_controller(usb3);
 
return 0;
@@ -1816,6 +1819,9 @@ static int renesas_usb3_stop(struct usb_gadget *gadget)
renesas_usb3_stop_controller(usb3);
spin_unlock_irqrestore(&usb3->lock, flags);
 
+   pm_runtime_put(usb3_to_dev(usb3));
+   pm_runtime_disable(usb3_to_dev(usb3));
+
return 0;
 }
 
@@ -1891,9 +1897,6 @@ static int renesas_usb3_remove(struct platform_device 
*pdev)
 
device_remove_file(&pdev->dev, &dev_attr_role);
 
-   pm_runtime_put(&pdev->dev);
-   pm_runtime_disable(&pdev->dev);
-
usb_del_gadget_udc(&usb3->gadget);
 
__renesas_usb3_ep_free_request(usb3->ep0_req);
@@ -2099,9 +2102,6 @@ static int renesas_usb3_probe(struct platform_device 
*pdev)
 
usb3->workaround_for_vbus = priv->workaround_for_vbus;
 
-   pm_runtime_enable(&pdev->dev);
-   pm_runtime_get_sync(&pdev->dev);
-
dev_info(&pdev->dev, "probed\n");
 
return 0;
-- 
1.9.1

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


[PATCH 0/5] usb: gadget: udc: renesas_usb3: add DMAC support

2017-04-26 Thread Yoshihiro Shimoda
This patch set is based on the latest Feribe's usb.git / testing/next branch
(the commit id = 28ea6be01e2cf244c461a40c8e9593816f894412.)

This patch set has 2 things:
 - Fixes some minor issues.
 - Add support for dedicated DMAC.

If possible, I want the patches [1/5] to [4/5] to be applied to v4.12-rcN.
I think the patch [5/5] will be applied to v4.13 (or later).
Should I submit them sepaletely?

Yoshihiro Shimoda (5):
  usb: gadget: udc: renesas_usb3: fix pm_runtime functions calling
  usb: gadget: udc: renesas_usb3: fix deadlock by spinlock
  usb: gadget: udc: renesas_usb3: lock for PN_ registers access
  usb: gadget: udc: renesas_usb3: Fix PN_INT_ENA disabling timing
  usb: gadget: udc: renesas_usb3: add support for dedicated DMAC

 drivers/usb/gadget/udc/renesas_usb3.c | 438 +-
 1 file changed, 425 insertions(+), 13 deletions(-)

-- 
1.9.1

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


[PATCH 3/5] usb: gadget: udc: renesas_usb3: lock for PN_ registers access

2017-04-26 Thread Yoshihiro Shimoda
This controller disallows to change the PIPE until reading/writing
a packet finishes. However. the previous code is not enough to hold
the lock in some functions. So, this patch fixes it.

Fixes: 746bfe63bba3 ("usb: gadget: renesas_usb3: add support for Renesas USB3.0 
peripheral controller")
Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/gadget/udc/renesas_usb3.c | 28 +---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index e27d948..c05097b 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -1475,7 +1475,13 @@ static void usb3_request_done_pipen(struct renesas_usb3 
*usb3,
struct renesas_usb3_request *usb3_req,
int status)
 {
-   usb3_pn_stop(usb3);
+   unsigned long flags;
+
+   spin_lock_irqsave(&usb3->lock, flags);
+   if (usb3_pn_change(usb3, usb3_ep->num))
+   usb3_pn_stop(usb3);
+   spin_unlock_irqrestore(&usb3->lock, flags);
+
usb3_disable_pipe_irq(usb3, usb3_ep->num);
usb3_request_done(usb3_ep, usb3_req, status);
 
@@ -1504,30 +1510,46 @@ static void usb3_irq_epc_pipen_bfrdy(struct 
renesas_usb3 *usb3, int num)
 {
struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num);
struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep);
+   bool done = false;
 
if (!usb3_req)
return;
 
+   spin_lock(&usb3->lock);
+   if (usb3_pn_change(usb3, num))
+   goto out;
+
if (usb3_ep->dir_in) {
/* Do not stop the IN pipe here to detect LSTTR interrupt */
if (!usb3_write_pipe(usb3_ep, usb3_req, USB3_PN_WRITE))
usb3_clear_bit(usb3, PN_INT_BFRDY, USB3_PN_INT_ENA);
} else {
if (!usb3_read_pipe(usb3_ep, usb3_req, USB3_PN_READ))
-   usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0);
+   done = true;
}
+
+out:
+   /* need to unlock because usb3_request_done_pipen() locks it */
+   spin_unlock(&usb3->lock);
+
+   if (done)
+   usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0);
 }
 
 static void usb3_irq_epc_pipen(struct renesas_usb3 *usb3, int num)
 {
u32 pn_int_sta;
 
-   if (usb3_pn_change(usb3, num) < 0)
+   spin_lock(&usb3->lock);
+   if (usb3_pn_change(usb3, num) < 0) {
+   spin_unlock(&usb3->lock);
return;
+   }
 
pn_int_sta = usb3_read(usb3, USB3_PN_INT_STA);
pn_int_sta &= usb3_read(usb3, USB3_PN_INT_ENA);
usb3_write(usb3, pn_int_sta, USB3_PN_INT_STA);
+   spin_unlock(&usb3->lock);
if (pn_int_sta & PN_INT_LSTTR)
usb3_irq_epc_pipen_lsttr(usb3, num);
if (pn_int_sta & PN_INT_BFRDY)
-- 
1.9.1

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


[PATCH] net: hso: register netdev later to avoid a race condition

2017-04-26 Thread Andreas Kemnade
If the netdev is accessed before the urbs are initialized,
there will be NULL pointer dereferences. That is avoided by
registering it when it is fully initialized.

This case occurs e.g. if dhcpcd is running in the background
and the device is probed, either after insmod hso or
when the device appears on the usb bus.

A backtrace is the following:

[ 1357.356048] usb 1-2: new high-speed USB device number 12 using ehci-omap
[ 1357.551177] usb 1-2: New USB device found, idVendor=0af0, idProduct=8800
[ 1357.558654] usb 1-2: New USB device strings: Mfr=3, Product=2, SerialNumber=0
[ 1357.568572] usb 1-2: Product: Globetrotter HSUPA Modem
[ 1357.574096] usb 1-2: Manufacturer: Option N.V.
[ 1357.685882] hso 1-2:1.5: Not our interface
[ 1460.886352] hso: unloaded
[ 1460.889984] usbcore: deregistering interface driver hso
[ 1513.769134] hso: ../drivers/net/usb/hso.c: Option Wireless
[ 1513.846771] Unable to handle kernel NULL pointer dereference at virtual 
address 0030
[ 1513.887664] hso 1-2:1.5: Not our interface
[ 1513.906890] usbcore: registered new interface driver hso
[ 1513.937988] pgd = ecdec000
[ 1513.949890] [0030] *pgd=acd15831, *pte=, *ppte=
[ 1513.956573] Internal error: Oops: 817 [#1] PREEMPT SMP ARM
[ 1513.962371] Modules linked in: hso usb_f_ecm omap2430 bnep bluetooth g_ether 
usb_f_rndis u_ether libcomposite configfs ipv6 arc4 wl18xx wlcore mac80211 
cfg80211 bq27xxx_battery panel_tpo_td028ttec1 omapdrm drm_kms_helper 
cfbfillrect snd_soc_simple_card syscopyarea cfbimgblt snd_soc_simple_card_utils 
sysfillrect sysimgblt fb_sys_fops snd_soc_omap_twl4030 cfbcopyarea 
encoder_opa362 drm twl4030_madc_hwmon wwan_on_off snd_soc_gtm601 
pwm_omap_dmtimer generic_adc_battery connector_analog_tv pwm_bl extcon_gpio 
omap3_isp wlcore_sdio videobuf2_dma_contig videobuf2_memops w1_bq27000 
videobuf2_v4l2 videobuf2_core omap_hdq snd_soc_omap_mcbsp ov9650 snd_soc_omap 
bmp280_i2c bmg160_i2c v4l2_common snd_pcm_dmaengine bmp280 bmg160_core at24 
bmc150_magn_i2c nvmem_core videodev phy_twl4030_usb bmc150_accel_i2c tsc2007
[ 1514.037384]  bmc150_magn bmc150_accel_core media leds_tca6507 bno055 
industrialio_triggered_buffer kfifo_buf gpio_twl4030 musb_hdrc snd_soc_twl4030 
twl4030_vibra twl4030_madc twl4030_pwrbutton twl4030_charger industrialio 
w2sg0004 ehci_omap omapdss [last unloaded: hso]
[ 1514.062622] CPU: 0 PID: 3433 Comm: dhcpcd Tainted: GW   
4.11.0-rc8-letux+ #1
[ 1514.071136] Hardware name: Generic OMAP36xx (Flattened Device Tree)
[ 1514.077758] task: ee748240 task.stack: ecdd6000
[ 1514.082580] PC is at hso_start_net_device+0x50/0xc0 [hso]
[ 1514.088287] LR is at hso_net_open+0x68/0x84 [hso]
[ 1514.093231] pc : []lr : []psr: a00f0013
sp : ecdd7e20  ip :   fp : 
[ 1514.105316] r10:   r9 : ed0e080c  r8 : ecd8fe2c
[ 1514.110839] r7 : bf79cef4  r6 : ecd8fe00  r5 :   r4 : ed0dbd80
[ 1514.117706] r3 :   r2 : c0020c80  r1 :   r0 : ecdb7800
[ 1514.124572] Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
[ 1514.132110] Control: 10c5387d  Table: acdec019  DAC: 0051
[ 1514.138153] Process dhcpcd (pid: 3433, stack limit = 0xecdd6218)
[ 1514.144470] Stack: (0xecdd7e20 to 0xecdd8000)
[ 1514.149078] 7e20: ed0dbd80 ecd8fe98 0001  ecd8f800 ecd8fe00 
ecd8fe60 
[ 1514.157714] 7e40: ed0e080c bf79ced8 bf79ce70 ecd8f800 0001 bf7a0258 
ecd8f830 c068d958
[ 1514.166320] 7e60: c068d8b8 ecd8f800 0001 1091 1090 c068dba4 
ecd8f800 1090
[ 1514.174926] 7e80: ecd8f940 ecd8f800  c068dc60  0001 
ed0e0800 ecd8f800
[ 1514.183563] 7ea0:  c06feaa8 c0ca39c2 beea57dc 0020  
306f7368 
[ 1514.192169] 7ec0:   1091    
 8914
[ 1514.200805] 7ee0: eaa9ab60 beea57dc c0c9bfc0 eaa9ab40 0006  
00046858 c066a948
[ 1514.209411] 7f00: beea57dc eaa9ab60 ecc6b0c0 c02837b0 0006 c0282c90 
c000 c0283654
[ 1514.218017] 7f20: c09b0c00 c098bc31 0001 c0c5e513 c0c5e513  
c0151354 c01a20c0
[ 1514.226654] 7f40: c0c5e513 c01a3134 ecdd6000 c01a3160 ee7487f0 600f0013 
 ee748240
[ 1514.235260] 7f60: ee748734  ecc6b0c0 ecc6b0c0 beea57dc 8914 
0006 
[ 1514.243896] 7f80: 00046858 c02837b0 1091 0003a1f0 00046608 0003a248 
0036 c01071e4
[ 1514.252502] 7fa0: ecdd6000 c0107040 0003a1f0 00046608 0006 8914 
beea57dc 1091
[ 1514.261108] 7fc0: 0003a1f0 00046608 0003a248 0036 0003ac0c 00046608 
00046610 00046858
[ 1514.269744] 7fe0: 0003a0ac beea57d4 000167eb b6f23106 400f0030 0006 
 
[ 1514.278411] [] (hso_start_net_device [hso]) from [] 
(hso_net_open+0x68/0x84 [hso])
[ 1514.288238] [] (hso_net_open [hso]) from [] 
(__dev_open+0xa0/0xf4)
[ 1514.296600] [] (__dev_open) from [] 
(__dev_change_flags+0x8c/0x130)
[ 1514.305023] [] (__dev_change_flags) from [] 
(dev_change_flags+0x18/0x48)
[ 1514.313934] [] (dev_change_flags) f

[PATCH 1/4] usb: dwc2: gadget: Fix in TX FIFO initialization flow.

2017-04-26 Thread Sevak Arakelyan
We need to update DPTXFSIZN even if the depth of
current TX FIFO is set to 0.
Loop only for needed TX FIFO count times. This will fix the issue with
wrong insufficient fifo memory WARN_ON.

Signed-off-by: Sevak Arakelyan 
---
 drivers/usb/dwc2/gadget.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index bc3b3fda5000..0b2d9bf43283 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -293,9 +293,13 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
unsigned int ep;
unsigned int addr;
int timeout;
+   int fifo_count;
u32 val;
u32 *txfsz = hsotg->params.g_tx_fifo_size;
 
+   if (!hsotg->params.enable_dynamic_fifo)
+   return;
+
/* Reset fifo map if not correctly cleared during previous session */
WARN_ON(hsotg->fifo_map);
hsotg->fifo_map = 0;
@@ -321,9 +325,9 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
 * them to endpoints dynamically according to maxpacket size value of
 * given endpoint.
 */
-   for (ep = 1; ep < MAX_EPS_CHANNELS; ep++) {
-   if (!txfsz[ep])
-   continue;
+   fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
+
+   for (ep = 1; ep <= fifo_count; ep++) {
val = addr;
val |= txfsz[ep] << FIFOSIZE_DEPTH_SHIFT;
WARN_ONCE(addr + txfsz[ep] > hsotg->fifo_mem,
-- 
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 3/4] usb: dwc2: gadget: Replace code with function calls.

2017-04-26 Thread Sevak Arakelyan
Replace TX and RX FIFO's flushing and waiting code in
dwc2_hsotg_init_fifo with dwc2_flush_tx_fifo
and dwc2_flush_rx_fifo function calls accordingly.

Signed-off-by: Sevak Arakelyan 
---
 drivers/usb/dwc2/gadget.c | 34 --
 1 file changed, 8 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 46f38604c3b2..574562a0286d 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -292,7 +292,6 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
 {
unsigned int ep;
unsigned int addr;
-   int timeout;
int fifo_count;
u32 val;
u32 *txfsz = hsotg->params.g_tx_fifo_size;
@@ -341,33 +340,16 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
dwc2_writel(hsotg->hw_params.total_fifo_size |
addr << GDFIFOCFG_EPINFOBASE_SHIFT,
hsotg->regs + GDFIFOCFG);
+
/*
-* according to p428 of the design guide, we need to ensure that
-* all fifos are flushed before continuing
+* Chapter 2.1.1 of the Programming Guide - The TxFIFOs and the RxFIFO
+* must be flushed after the RAM allocation is done, for proper FIFO
+* functioning.
+*
+* 0x10 - all TX FIFOs
 */
-
-   dwc2_writel(GRSTCTL_TXFNUM(0x10) | GRSTCTL_TXFFLSH |
-  GRSTCTL_RXFFLSH, hsotg->regs + GRSTCTL);
-
-   /* wait until the fifos are both flushed */
-   timeout = 100;
-   while (1) {
-   val = dwc2_readl(hsotg->regs + GRSTCTL);
-
-   if ((val & (GRSTCTL_TXFFLSH | GRSTCTL_RXFFLSH)) == 0)
-   break;
-
-   if (--timeout == 0) {
-   dev_err(hsotg->dev,
-   "%s: timeout flushing fifos (GRSTCTL=%08x)\n",
-   __func__, val);
-   break;
-   }
-
-   udelay(1);
-   }
-
-   dev_dbg(hsotg->dev, "FIFOs reset, timeout at %d\n", timeout);
+   dwc2_flush_tx_fifo(hsotg, 0x10);
+   dwc2_flush_rx_fifo(hsotg);
 }
 
 /**
-- 
2.11.0

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


[PATCH 2/4] usb: dwc2: gadget: Remove duplicated FIFO initialization.

2017-04-26 Thread Sevak Arakelyan
dwc2_hsotg_init is called in dwc2_hsotg_core_init_disconnected and
dwc2_hsotg_init functions. It should be in
dwc2_hsotg_core_init_disconnected and don't need to be called for
the second time, so remove the duplicated one from dwc2_hsotg_init.
Also, remove useless debug prints.

Signed-off-by: Sevak Arakelyan 
---
 drivers/usb/dwc2/gadget.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 0b2d9bf43283..46f38604c3b2 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -4214,14 +4214,6 @@ static void dwc2_hsotg_init(struct dwc2_hsotg *hsotg)
/* Be in disconnected state until gadget is registered */
__orr32(hsotg->regs + DCTL, DCTL_SFTDISCON);
 
-   /* setup fifos */
-
-   dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n",
-   dwc2_readl(hsotg->regs + GRXFSIZ),
-   dwc2_readl(hsotg->regs + GNPTXFSIZ));
-
-   dwc2_hsotg_init_fifo(hsotg);
-
/* keep other bits untouched (so e.g. forced modes are not lost) */
usbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
usbcfg &= ~(GUSBCFG_TOUTCAL_MASK | GUSBCFG_PHYIF16 | GUSBCFG_SRPCAP |
-- 
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 4/4] usb: dwc2: gadget: Separate non-periodic and periodic FIFO inits

2017-04-26 Thread Sevak Arakelyan
Separate dwc2_hsotg_init_fifo function into 2 different functions,
for periodic and non-periodic FIFOs. Initialization of non-periodic
FIFOs must be done after soft or USB resets, while initialization
of periodic FIFOs must be done only after soft reset.

Signed-off-by: Sevak Arakelyan 
---
 drivers/usb/dwc2/gadget.c | 46 --
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 574562a0286d..0bf42a0a3213 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -285,10 +285,9 @@ int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg 
*hsotg)
 }
 
 /**
- * dwc2_hsotg_init_fifo - initialise non-periodic FIFOs
- * @hsotg: The device instance.
+ * dwc2_hsotg_init_periodic_fifos - initialize periodic FIFOs
  */
-static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
+static void dwc2_hsotg_init_periodic_fifos(struct dwc2_hsotg *hsotg)
 {
unsigned int ep;
unsigned int addr;
@@ -303,27 +302,12 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
WARN_ON(hsotg->fifo_map);
hsotg->fifo_map = 0;
 
-   /* set RX/NPTX FIFO sizes */
-   dwc2_writel(hsotg->params.g_rx_fifo_size, hsotg->regs + GRXFSIZ);
-   dwc2_writel((hsotg->params.g_rx_fifo_size << FIFOSIZE_STARTADDR_SHIFT) |
-   (hsotg->params.g_np_tx_fifo_size << FIFOSIZE_DEPTH_SHIFT),
-   hsotg->regs + GNPTXFSIZ);
-
/*
-* arange all the rest of the TX FIFOs, as some versions of this
-* block have overlapping default addresses. This also ensures
-* that if the settings have been changed, then they are set to
-* known values.
+* Arange periodic TX FIFOs to correctly calculated values.
+* Start at the end of the GNPTXFSIZ.
 */
-
-   /* start at the end of the GNPTXFSIZ, rounded up */
addr = hsotg->params.g_rx_fifo_size + hsotg->params.g_np_tx_fifo_size;
 
-   /*
-* Configure fifos sizes from provided configuration and assign
-* them to endpoints dynamically according to maxpacket size value of
-* given endpoint.
-*/
fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
 
for (ep = 1; ep <= fifo_count; ep++) {
@@ -340,6 +324,21 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
dwc2_writel(hsotg->hw_params.total_fifo_size |
addr << GDFIFOCFG_EPINFOBASE_SHIFT,
hsotg->regs + GDFIFOCFG);
+}
+
+/**
+ * dwc2_hsotg_init_non_periodic_fifos - initialize non-periodic FIFOs
+ */
+static void dwc2_hsotg_init_non_periodic_fifos(struct dwc2_hsotg *hsotg)
+{
+   if (!hsotg->params.enable_dynamic_fifo)
+   return;
+
+   /* set RX/NPTX FIFO sizes */
+   dwc2_writel(hsotg->params.g_rx_fifo_size, hsotg->regs + GRXFSIZ);
+   dwc2_writel((hsotg->params.g_rx_fifo_size << FIFOSIZE_STARTADDR_SHIFT) |
+   (hsotg->params.g_np_tx_fifo_size << FIFOSIZE_DEPTH_SHIFT),
+   hsotg->regs + GNPTXFSIZ);
 
/*
 * Chapter 2.1.1 of the Programming Guide - The TxFIFOs and the RxFIFO
@@ -3269,10 +3268,13 @@ void dwc2_hsotg_core_init_disconnected(struct 
dwc2_hsotg *hsotg,
}
dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
 
-   dwc2_hsotg_init_fifo(hsotg);
+   dwc2_hsotg_init_non_periodic_fifos(hsotg);
+
+   if (!is_usb_reset) {
+   dwc2_hsotg_init_periodic_fifos(hsotg);
 
-   if (!is_usb_reset)
__orr32(hsotg->regs + DCTL, DCTL_SFTDISCON);
+   }
 
dcfg |= DCFG_EPMISCNT(1);
 
-- 
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 0/4] usb: dwc2: gadget: Fix dynamic FIFO initialization flow

2017-04-26 Thread Sevak Arakelyan
This series fixes FIFO initialization issue of getting wrong insufficent FIFO 
memory warning.
Fixes duplicate FIFO initialization issue, replaces FIFO flushing code with 
function calls.
Separates initialization of periodic and non-periodic FIFOs.

Tested on HAPS platform with DWC_hsotg IP version 3.30a.

Sevak Arakelyan (4):
  usb: dwc2: gadget: Fix in TX FIFO initialization flow.
  usb: dwc2: gadget: Remove duplicated FIFO initialization.
  usb: dwc2: gadget: Replace code with function calls.
  usb: dwc2: gadget: Separate non-periodic and periodic FIFO inits

 drivers/usb/dwc2/gadget.c | 96 +++
 1 file changed, 38 insertions(+), 58 deletions(-)

-- 
2.11.0

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


Re: [PATCH] usb: host: xhci: remove #ifdef around PM functions

2017-04-26 Thread Greg Kroah-Hartman
On Fri, Apr 21, 2017 at 11:42:54PM +0200, Arnd Bergmann wrote:
> The #ifdef is slightly wrong as it doesn't cover the xhci_priv_resume_quirk()
> function, causing a harmless warning:
> 
> drivers/usb/host/xhci-plat.c:58:12: error: 'xhci_priv_resume_quirk' defined 
> but not used [-Werror=unused-function]
>  static int xhci_priv_resume_quirk(struct usb_hcd *hcd)
> 
> A simpler way to do this correctly is to use __maybe_unused annotations
> that let the compiler silently drop the functions when there is no
> reference.
> 
> Fixes: b0c69b4bace3 ("usb: host: plat: Enable xHCI plat runtime PM")
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/usb/host/xhci-plat.c | 12 
>  drivers/usb/host/xhci.h  |  5 -
>  2 files changed, 4 insertions(+), 13 deletions(-)

Now applied, thanks.

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


[PATCH v6 1/2] usb: typec: USB Type-C Port Manager (tcpm)

2017-04-26 Thread Guenter Roeck
From: Guenter Roeck 

This driver implements the USB Type-C Power Delivery state machine
for both source and sink ports. Alternate mode support is not
fully implemented.

The driver attaches to the USB Type-C class code implemented in
the following patches.

usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY
usb: USB Type-C connector class

This driver only implements the state machine. Lower level drivers are
responsible for
- Reporting VBUS status and activating VBUS
- Setting CC lines and providing CC line status
- Setting line polarity
- Activating and deactivating VCONN
- Setting the current limit
- Activating and deactivating PD message transfers
- Sending and receiving PD messages

The driver provides both a functional API as well as callbacks for
lower level drivers.

Signed-off-by: Guenter Roeck 
Signed-off-by: Guenter Roeck 
---
v6:
- Move driver and include files to -staging
- Remove unused defines from include files
- Fix compile error seen when building on top of -next (include file change)
- Fix VDO log message
- Various endianness fixes
- Separate PDO logging into separate function
- Replace "SBZ" in include files with "Reserved; Shall be set to zero"
- Fix VDO_AMA macro
- Move pd_mode_data from pd_vdo.h to tcpm.c
- Add TODO file

v5:
- Adjust to infrastructure API changes
- Minor API change to low level driver
  [set_pd_header -> set_roles]
- Set default state depending on preferred role
- Improve Try.SRC and Try.SNK implementation
- Do not report stale identity information to infrastructure 
- Fix crash seen if a SVD message was received while disconnected
- Improve accessory handling
- If a role change is requested and the partner does not support PD,
  request a port reset
- Set state to SRC_READY after PD_N_CAPS_COUNT if the partner does not
  respond to capabilities messages
- Update PD_T_SEND_SOURCE_CAP to improve compatibility with slow partners
- Coding style fixes

v4:
- Source and sink capabilities can now change on the fly
- Introduced several new macros to identify CC states
- Determine RP value to set based on maximum current supported
  by a port configured as source
- Support for DRP toggling implemented in hardware (by Type-C port controller)
- Added MODULE_ macros

v3:
- Improve TCPM state machine resiliency if there are spurious CC line changes
  while the state machine is in a transient change (waiting for a timeout)
- Update current limit after CC voltage level changes on a port which is not
  PD capable.

v2:
- Only update polarity if setting it was successful
  If setting the CC line polarity in the driver was not successful,
  don't update the internal polarity state.
- All PD messages are little endian; convert to and from CPU endianness.
- Avoid comparisons against NULL.
- Use u8/u16/u32 instead of uint8_t/uint16_t/uint32_t consistently.
- Callbacks into tcpm need to be lockless to avoid timing problems
  in low level drivers.
- Simplify callbacks; tcpm can request the current state of cc/vbus
  when it is ready to use it.

 drivers/staging/Kconfig|2 +
 drivers/staging/Makefile   |2 +-
 drivers/staging/typec/Kconfig  |   10 +
 drivers/staging/typec/Makefile |1 +
 drivers/staging/typec/TODO |   12 +
 drivers/staging/typec/pd.h |  281 
 drivers/staging/typec/pd_bdo.h |   31 +
 drivers/staging/typec/pd_vdo.h |  249 +++
 drivers/staging/typec/tcpm.c   | 3464 
 drivers/staging/typec/tcpm.h   |  150 ++
 10 files changed, 4201 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/typec/Kconfig
 create mode 100644 drivers/staging/typec/Makefile
 create mode 100644 drivers/staging/typec/TODO
 create mode 100644 drivers/staging/typec/pd.h
 create mode 100644 drivers/staging/typec/pd_bdo.h
 create mode 100644 drivers/staging/typec/pd_vdo.h
 create mode 100644 drivers/staging/typec/tcpm.c
 create mode 100644 drivers/staging/typec/tcpm.h

diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 65440f675033..af81544091e3 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -104,4 +104,6 @@ source "drivers/staging/greybus/Kconfig"
 
 source "drivers/staging/vc04_services/Kconfig"
 
+source "drivers/staging/typec/Kconfig"
+
 endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 13ae7f899b21..077285c648e6 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -41,4 +41,4 @@ obj-$(CONFIG_MOST)+= most/
 obj-$(CONFIG_KS7010)   += ks7010/
 obj-$(CONFIG_GREYBUS)  += greybus/
 obj-$(CONFIG_BCM2835_VCHIQ)+= vc04_services/
-
+obj-y  += typec/
diff --git a/drivers/staging/typec/Kconfig b/drivers/staging/typec/Kconfig
new file mode 100644
index ..1aa0ffb856a4
--- /dev/null
+++ b/drivers/staging/typec/Kconfig
@@ -0,0 +1,10 @@
+menu "USB Power Delivery and Type-C drivers"
+
+config TYPEC_TCPM
+   tristate "USB Type-C Port Control

[PATCH v6 2/2] usb: typec: Type-C Port Controller Interface driver (tcpci)

2017-04-26 Thread Guenter Roeck
From: Guenter Roeck 

The port controller interface driver interconnects the Type-C Port
Manager with a Type-C Port Controller Interface (TCPCI) compliant
port controller.

Signed-off-by: Guenter Roeck 
Signed-off-by: Guenter Roeck 
---
v6:
- Move to drivers/staging
- Use PTR_ERR_OR_ZERO()
v5:
- API changes
  [set_pd_header -> set_roles]
v4:
- Fix RP value set for ports supporting 3A current
- Implement support for DRP toggling in hardware
- When setting VBUS, disable both source and sink before enabling anything
- Set correct byte count in tcpci_pd_transmit()
- Disable chip interrupts before registering interrupt handler
- Request IRQF_ONESHOT | IRQF_TRIGGER_LOW instead of IRQF_TRIGGER_FALLING
v3:
- No change
v2:
- Adjust to modified callbacks into tcpm code

 drivers/staging/typec/Kconfig  |   9 +
 drivers/staging/typec/Makefile |   1 +
 drivers/staging/typec/TODO |   3 +
 drivers/staging/typec/tcpci.c  | 526 +
 drivers/staging/typec/tcpci.h  | 133 +++
 5 files changed, 672 insertions(+)
 create mode 100644 drivers/staging/typec/tcpci.c
 create mode 100644 drivers/staging/typec/tcpci.h

diff --git a/drivers/staging/typec/Kconfig b/drivers/staging/typec/Kconfig
index 1aa0ffb856a4..0e73768ce74b 100644
--- a/drivers/staging/typec/Kconfig
+++ b/drivers/staging/typec/Kconfig
@@ -7,4 +7,13 @@ config TYPEC_TCPM
  The Type-C Port Controller Manager provides a USB PD and USB Type-C
  state machine for use with Type-C Port Controllers.
 
+if TYPEC_TCPM
+
+config TYPEC_TCPCI
+   tristate "Type-C Port Controller Interface driver"
+   help
+ Type-C Port Controller driver for TCPCI-compliant controller.
+
+endif
+
 endmenu
diff --git a/drivers/staging/typec/Makefile b/drivers/staging/typec/Makefile
index 4d82c2480fc2..144f7ae60a7b 100644
--- a/drivers/staging/typec/Makefile
+++ b/drivers/staging/typec/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_TYPEC_TCPM)   += tcpm.o
+obj-$(CONFIG_TYPEC_TCPCI)  += tcpci.o
diff --git a/drivers/staging/typec/TODO b/drivers/staging/typec/TODO
index a8db476704f0..bc1f97a2d1bf 100644
--- a/drivers/staging/typec/TODO
+++ b/drivers/staging/typec/TODO
@@ -8,5 +8,8 @@ tcpm:
 - Add support for USB PD 3.0. While not mandatory, at least fast role swap
   as well as authentication support would be very desirable.
 
+tcpci:
+- Test with real hardware
+
 Please send patches to Guenter Roeck  and copy
 Heikki Krogerus .
diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
new file mode 100644
index ..5e5be74c7850
--- /dev/null
+++ b/drivers/staging/typec/tcpci.c
@@ -0,0 +1,526 @@
+/*
+ * Copyright 2015-2017 Google, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * USB Type-C Port Controller Interface.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "pd.h"
+#include "tcpci.h"
+#include "tcpm.h"
+
+#define PD_RETRY_COUNT 3
+
+struct tcpci {
+   struct device *dev;
+   struct i2c_client *client;
+
+   struct tcpm_port *port;
+
+   struct regmap *regmap;
+
+   bool controls_vbus;
+
+   struct tcpc_dev tcpc;
+};
+
+static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc)
+{
+   return container_of(tcpc, struct tcpci, tcpc);
+}
+
+static int tcpci_read16(struct tcpci *tcpci, unsigned int reg,
+   unsigned int *val)
+{
+   return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16));
+}
+
+static int tcpci_write16(struct tcpci *tcpci, unsigned int reg, u16 val)
+{
+   return regmap_raw_write(tcpci->regmap, reg, &val, sizeof(u16));
+}
+
+static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
+{
+   struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+   unsigned int reg;
+   int ret;
+
+   switch (cc) {
+   case TYPEC_CC_RA:
+   reg = (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC1_SHIFT) |
+   (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC2_SHIFT);
+   break;
+   case TYPEC_CC_RD:
+   reg = (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) |
+   (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT);
+   break;
+   case TYPEC_CC_RP_DEF:
+   reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
+   (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) |
+   (TCPC_ROLE_CTRL_RP_VAL_DEF <<
+TCPC_ROLE_CTRL_RP_VAL_SHIFT);
+

Re: [PATCH v6 1/2] usb: typec: USB Type-C Port Manager (tcpm)

2017-04-26 Thread Guenter Roeck
On Wed, Apr 26, 2017 at 03:26:11PM -0700, Guenter Roeck wrote:
> From: Guenter Roeck 
> 
> This driver implements the USB Type-C Power Delivery state machine
> for both source and sink ports. Alternate mode support is not
> fully implemented.
> 
> The driver attaches to the USB Type-C class code implemented in
> the following patches.
> 
>   usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY
>   usb: USB Type-C connector class
> 
> This driver only implements the state machine. Lower level drivers are
> responsible for
> - Reporting VBUS status and activating VBUS
> - Setting CC lines and providing CC line status
> - Setting line polarity
> - Activating and deactivating VCONN
> - Setting the current limit
> - Activating and deactivating PD message transfers
> - Sending and receiving PD messages
> 
> The driver provides both a functional API as well as callbacks for
> lower level drivers.
> 
> Signed-off-by: Guenter Roeck 
> Signed-off-by: Guenter Roeck 

Of course this has missing dependencies and won't compile if CONFIG_DEBUG_FS
is not enabled. Greg, should I send v7 or follow-up patches ?

Thanks,
Guenter

> ---
> v6:
> - Move driver and include files to -staging
> - Remove unused defines from include files
> - Fix compile error seen when building on top of -next (include file change)
> - Fix VDO log message
> - Various endianness fixes
> - Separate PDO logging into separate function
> - Replace "SBZ" in include files with "Reserved; Shall be set to zero"
> - Fix VDO_AMA macro
> - Move pd_mode_data from pd_vdo.h to tcpm.c
> - Add TODO file
> 
> v5:
> - Adjust to infrastructure API changes
> - Minor API change to low level driver
>   [set_pd_header -> set_roles]
> - Set default state depending on preferred role
> - Improve Try.SRC and Try.SNK implementation
> - Do not report stale identity information to infrastructure 
> - Fix crash seen if a SVD message was received while disconnected
> - Improve accessory handling
> - If a role change is requested and the partner does not support PD,
>   request a port reset
> - Set state to SRC_READY after PD_N_CAPS_COUNT if the partner does not
>   respond to capabilities messages
> - Update PD_T_SEND_SOURCE_CAP to improve compatibility with slow partners
> - Coding style fixes
> 
> v4:
> - Source and sink capabilities can now change on the fly
> - Introduced several new macros to identify CC states
> - Determine RP value to set based on maximum current supported
>   by a port configured as source
> - Support for DRP toggling implemented in hardware (by Type-C port controller)
> - Added MODULE_ macros
> 
> v3:
> - Improve TCPM state machine resiliency if there are spurious CC line changes
>   while the state machine is in a transient change (waiting for a timeout)
> - Update current limit after CC voltage level changes on a port which is not
>   PD capable.
> 
> v2:
> - Only update polarity if setting it was successful
>   If setting the CC line polarity in the driver was not successful,
>   don't update the internal polarity state.
> - All PD messages are little endian; convert to and from CPU endianness.
> - Avoid comparisons against NULL.
> - Use u8/u16/u32 instead of uint8_t/uint16_t/uint32_t consistently.
> - Callbacks into tcpm need to be lockless to avoid timing problems
>   in low level drivers.
> - Simplify callbacks; tcpm can request the current state of cc/vbus
>   when it is ready to use it.
> 
>  drivers/staging/Kconfig|2 +
>  drivers/staging/Makefile   |2 +-
>  drivers/staging/typec/Kconfig  |   10 +
>  drivers/staging/typec/Makefile |1 +
>  drivers/staging/typec/TODO |   12 +
>  drivers/staging/typec/pd.h |  281 
>  drivers/staging/typec/pd_bdo.h |   31 +
>  drivers/staging/typec/pd_vdo.h |  249 +++
>  drivers/staging/typec/tcpm.c   | 3464 
> 
>  drivers/staging/typec/tcpm.h   |  150 ++
>  10 files changed, 4201 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/staging/typec/Kconfig
>  create mode 100644 drivers/staging/typec/Makefile
>  create mode 100644 drivers/staging/typec/TODO
>  create mode 100644 drivers/staging/typec/pd.h
>  create mode 100644 drivers/staging/typec/pd_bdo.h
>  create mode 100644 drivers/staging/typec/pd_vdo.h
>  create mode 100644 drivers/staging/typec/tcpm.c
>  create mode 100644 drivers/staging/typec/tcpm.h
> 
> diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
> index 65440f675033..af81544091e3 100644
> --- a/drivers/staging/Kconfig
> +++ b/drivers/staging/Kconfig
> @@ -104,4 +104,6 @@ source "drivers/staging/greybus/Kconfig"
>  
>  source "drivers/staging/vc04_services/Kconfig"
>  
> +source "drivers/staging/typec/Kconfig"
> +
>  endif # STAGING
> diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
> index 13ae7f899b21..077285c648e6 100644
> --- a/drivers/staging/Makefile
> +++ b/drivers/staging/Makefile
> @@ -41,4 +41,4 @@ obj-$(CONFIG_MOST)  += most/
>  obj-$(CONFIG_KS7010)

Re: [PATCH v17 2/3] usb: USB Type-C connector class

2017-04-26 Thread Rajaram R
On Tue, Apr 25, 2017 at 7:40 PM, Guenter Roeck  wrote:
> On 04/25/2017 01:26 AM, Rajaram R wrote:
>>
>> On Mon, Apr 24, 2017 at 11:20 PM, Badhri Jagan Sridharan
>>  wrote:
>>>
>>> On Sat, Apr 22, 2017 at 2:23 AM, Rajaram R 
>>> wrote:

 On Fri, Apr 21, 2017 at 10:13 PM, Guenter Roeck 
 wrote:
>
> On Fri, Apr 21, 2017 at 07:57:52PM +0530, Rajaram R wrote:
>>
>> On Fri, Apr 21, 2017 at 1:16 AM, Badhri Jagan Sridharan
>>  wrote:
>>>
>>> Thanks for the responses :)
>>>
>>> So seems like we have a plan.
>>>
>>> In Type-C connector class the checks for TYPEC_PWR_MODE_PD
>>> and pd_revision for both the port and the partner will be removed in
>>> power_role_store and the data_role_store and will be delegated
>>> to the low level drivers.
>>
>>
>> It is important to remember what USB Type-C provide is mechanisms for
>> "TRYing" to become a particular role and not guaranteeing.
>>
>> With what device combination do you fore see we could get the desired
>> role with this change ?
>>
>
> If the partner is not PD capable, if a preferred role is specified,
> if the current cole does not match the preferred role, and if the
> request
> is to set the role to match the preferred role, I think it is
> reasonable
> to expect that re-establishing the connection would accomplish that if
> the
> partner supports it.
>
 In this context I believe we have two different inputs as follows:

 /sys/class/typec//supported_power_roles
 /sys/class/typec//preferred_role

 The need of preferred role is required when DRP is set in
 supported_power_roles option.
 Ideally a battery powered device will TRY to be SNK and a a/c plugged
 device will TRY to be SRC

 We need to understand which non-PD device will set to DRP? In the
>>>
>>>
>>> Android Phones (actually it could be any phone which has a type-c port)
>>> since it can act as usb gadget (when connected to PC) or Usb host
>>> when connected to peripherals such as thumb drives, keyboard etc.
>>> Phones with smaller form factors might be thermally limited to charge
>>> above 15W, therefore supporting PD might be an overkill for them.
>>>
 current ecosystem all legacy devices
 will sit behind adapters which either present an Rp or Rd.

 If it is a power adapter in 5V range can either present Rp or DRP with
 TRY.SRC and there is no role swap requirement.

 If it is a laptop port or similar with non-PD (??) DRP  there is no
 guaranteed role swap in a non-PD mode.
>>>
>>>
>>> This is true, but following a Try.SRC or Try.SNK state machine can
>>> increase the chances of landing in the desired role/preferred role.
>>
>>
>> Agree and as indicated it increases only chances.
>>
>
> FWIW, this is pretty much the same as requesting a role change using PD.
> Based on my experience with various devices, the chance for that to succeed
> isn't really that high either.
>
> I am not really sure I understand your problem with using Try.{SRC,SNK}
> to trigger (or attempt to trigger) a role change. Can we take a step back,
> and can you explain ?

The parameters required for a type-c connection is defined as follows
and will have a default value.

/sys/class/typec//supported_power_roles
/sys/class/typec//preferred_role

When two DRP devices are connected and for which we have
preferred_role which provides input on the preference, In a DRP mode
we have randomness in the mode of connection and hence we require role
swap mechanisms. A Type-C only device cannot role swap as this is
valid only in PD operation.

#  Question was how to choose a particular role in non-PD mode. Only
way to have a deterministic role in a non-PD mode is to set expected
supported_role of choice rather than DRP.

# As part of the solution suggested, checking of roles and triggering
role swaps has to be done by the policy manager(PM) and delinked from
Policy Engine. I guess the policy manager is at user space?.

I do not have the complete git repo and may be i could be missing
something. If this is in any public git please let me know

>
> Thanks,
> Guenter
>
--
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 1/2] usb: typec: USB Type-C Port Manager (tcpm)

2017-04-26 Thread Greg Kroah-Hartman
On Wed, Apr 26, 2017 at 06:15:08PM -0700, Guenter Roeck wrote:
> On Wed, Apr 26, 2017 at 03:26:11PM -0700, Guenter Roeck wrote:
> > From: Guenter Roeck 
> > 
> > This driver implements the USB Type-C Power Delivery state machine
> > for both source and sink ports. Alternate mode support is not
> > fully implemented.
> > 
> > The driver attaches to the USB Type-C class code implemented in
> > the following patches.
> > 
> > usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY
> > usb: USB Type-C connector class
> > 
> > This driver only implements the state machine. Lower level drivers are
> > responsible for
> > - Reporting VBUS status and activating VBUS
> > - Setting CC lines and providing CC line status
> > - Setting line polarity
> > - Activating and deactivating VCONN
> > - Setting the current limit
> > - Activating and deactivating PD message transfers
> > - Sending and receiving PD messages
> > 
> > The driver provides both a functional API as well as callbacks for
> > lower level drivers.
> > 
> > Signed-off-by: Guenter Roeck 
> > Signed-off-by: Guenter Roeck 
> 
> Of course this has missing dependencies and won't compile if CONFIG_DEBUG_FS
> is not enabled. Greg, should I send v7 or follow-up patches ?

v7 would be good to keep the kbuild bot happy :)

thanks,

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


Re: [PATCH v3] usb: misc: legousbtower: Fix buffers on stack

2017-04-26 Thread Maksim Salau
> >* removed Tested-by: Alfredo Rafael Vicente Boix ;
> 
> I added this back, as it matters, and your change from the previous
> version was trivial.
>   
> >* removed Cc: sta...@vger.kernel.org
> >  since this patch doesn't apply against v4.10.12
> 
> I added this back as well :)  

Thanks, Greg!

I was not sure about how strict are the rules about these tags.

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