Re: problem with resume after s2ram

2014-04-04 Thread Peter Münster
On Tue, Apr 01 2014, Alan Stern wrote:

>> > Also, I'd like to track down the problem when both devices are plugged
>> > into front ports.  Can you try that as well, again without the new
>> > diagnostic patch?
>> 
>> The system hangs...
>
> Do you have a netconsole log?

Hi Alan,

Yes, here:

[ 4694.420213] PM: Syncing filesystems ... done.
[ 4694.591736] PM: Preparing system for mem sleep
[ 4694.756151] Freezing user space processes ... (elapsed 0.002 seconds) done.
[ 4694.758468] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) 
done.
[ 4694.759870] PM: Entering mem sleep
[ 4694.760313] usb 6-3: usb suspend, wakeup 0
[ 4694.760464] usb 2-3: usb suspend, wakeup 0
[ 4694.760520] usb usb7: usb auto-resume
[ 4694.760578] ohci-pci :00:14.5: resume root hub
[ 4694.760753] usb usb5: usb auto-resume
[ 4694.760813] ohci-pci :00:13.0: resume root hub
[ 4694.760908] usb usb4: usb auto-resume
[ 4694.760961] ohci-pci :00:12.1: resume root hub
[ 4694.761058] usb usb3: usb auto-resume
[ 4694.761086] ohci-pci :00:12.0: resume root hub
[ 4694.761300] hub 2-0:1.0: hub_suspend
[ 4694.761340] usb usb1: usb auto-resume
[ 4694.761396] ehci-pci :00:12.2: resume root hub
[ 4694.761422] usb usb2: bus suspend, wakeup 0
[ 4694.761481] ehci-pci :00:13.2: suspend root hub
[ 4694.761554] sd 2:0:0:0: [sdb] Synchronizing SCSI cache
[ 4694.761720] sd 2:0:0:0: [sdb] Stopping disk
[ 4694.761862] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[ 4694.762063] sd 0:0:0:0: [sda] Stopping disk
[ 4694.762223] usb 6-2: usb suspend, wakeup 1
[ 4697.508604] r8169 :02:00.0 eth0: link up
[ 4699.733189] ata3: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[ 4699.763610] ata3.00: configured for UDMA/133
[ 4699.768070] sd 2:0:0:0: [sdb] Starting disk
[ 4701.366082] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[ 4701.383352] ata1.00: configured for UDMA/133
[ 4701.387815] sd 0:0:0:0: [sda] Starting disk


>> Should I do another git-bisect?
>
> Yes, that would be a good idea.

Ok, but this will take some time. I can only do 1 or 2 reboots per day.

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


MUSB/OMAP: gadget does not start when cable is plugged after the driver is started

2014-04-04 Thread Stefan Roese

Hi!

I'm currently seeing a problem on an OMAP3530 based board (Technexion 
TAO3530). Where the MUSB is configured as device/peripheral and the 
ethernet gadget is compiled into the kernel. This works without any 
problems and usb0 is available when the USB cable is connected to a PC 
upon startup. But when the cable is disconnected when the driver is 
started (doesn't matter if the gadget is included in the kernel or if 
the gadget driver module is loaded) and the cable is plugged in later, 
the ethernet gadget does not start up. This is 100% reproducible.


Before digging deeper into this, I wanted to check here if this is a 
known issue. And if anybody already has a solution/hint for it.


FYI: I'm using v3.14 right now.

Thanks,
Stefan
--
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 07/11] usb: chipidea: OTG HNP and SRP fsm implementation.

2014-04-04 Thread Peter Chen
On Fri, Apr 04, 2014 at 11:31:16AM +0800, Li Jun wrote:
> From: Li Jun 
> 
> USB OTG interrupt handling and fsm transitions according to USB OTG
> and EH 2.0.
> 
> Signed-off-by: Li Jun 
> ---
>  drivers/usb/chipidea/core.c|   13 ++-
>  drivers/usb/chipidea/otg.c |9 +-
>  drivers/usb/chipidea/otg_fsm.c |  228 
> 
>  drivers/usb/chipidea/otg_fsm.h |   18 
>  drivers/usb/chipidea/udc.c |6 ++
>  5 files changed, 270 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
> index ff38cf3..e63b9fa 100644
> --- a/drivers/usb/chipidea/core.c
> +++ b/drivers/usb/chipidea/core.c
> @@ -42,7 +42,6 @@
>   * - Not Supported: 15 & 16 (ISO)
>   *
>   * TODO List
> - * - OTG
>   * - Interrupt Traffic
>   * - GET_STATUS(device) - always reports 0
>   * - Gadget API (majority of optional features)
> @@ -74,6 +73,7 @@
>  #include "host.h"
>  #include "debug.h"
>  #include "otg.h"
> +#include "otg_fsm.h"
>  
>  /* Controller register map */
>  static const u8 ci_regs_nolpm[] = {
> @@ -412,8 +412,14 @@ static irqreturn_t ci_irq(int irq, void *data)
>   irqreturn_t ret = IRQ_NONE;
>   u32 otgsc = 0;
>  
> - if (ci->is_otg)
> + if (ci->is_otg) {
>   otgsc = hw_read_otgsc(ci, ~0);
> + if (ci_otg_is_fsm_mode(ci)) {
> + ret = ci_otg_fsm_irq(ci);
> + if (ret == IRQ_HANDLED)
> + return ret;
> + }
> + }
>  
>   /*
>* Handle id change interrupt, it indicates device/host function
> @@ -697,6 +703,9 @@ static int ci_hdrc_probe(struct platform_device *pdev)
>   goto stop;
>   }
>  
> + if (ci_otg_is_fsm_mode(ci))
> + ci_hdrc_otg_fsm_start(ci);
> +
>   platform_set_drvdata(pdev, ci);
>   ret = request_irq(ci->irq, ci_irq, IRQF_SHARED, ci->platdata->name,
> ci);
> diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
> index 200784e..b054d0b 100644
> --- a/drivers/usb/chipidea/otg.c
> +++ b/drivers/usb/chipidea/otg.c
> @@ -11,8 +11,8 @@
>   */
>  
>  /*
> - * This file mainly handles otgsc register, it may include OTG operation
> - * in the future.
> + * This file mainly handles otgsc register, OTG fsm operations for HNP and 
> SRP
> + * are also included.
>   */
>  
>  #include 
> @@ -91,6 +91,11 @@ static void ci_otg_work(struct work_struct *work)
>  {
>   struct ci_hdrc *ci = container_of(work, struct ci_hdrc, work);
>  
> + if (ci_otg_is_fsm_mode(ci) && !ci_otg_fsm_work(ci)) {
> + enable_irq(ci->irq);
> + return;
> + }
> +
>   if (ci->id_event) {
>   ci->id_event = false;
>   ci_handle_id_switch(ci);
> diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
> index 721994b..6e4ad80 100644
> --- a/drivers/usb/chipidea/otg_fsm.c
> +++ b/drivers/usb/chipidea/otg_fsm.c
> @@ -13,6 +13,10 @@
>  /*
>   * This file mainly handles OTG fsm, it includes OTG fsm operations
>   * for HNP and SRP.
> + *
> + * TODO List
> + * - ADP
> + * - OTG test device
>   */
>  
>  #include 
> @@ -92,6 +96,33 @@ static void ci_otg_del_timer(struct ci_hdrc *ci, enum 
> ci_otg_fsm_timer_index t)
>   hw_write_otgsc(ci, OTGSC_1MSIE, 0);
>  }
>  
> +/*
> + * Reduce timer count by 1, and find timeout conditions.
> + * Called by otg 1ms timer interrupt
> + */
> +static inline int ci_otg_tick_timer(struct ci_hdrc *ci)
> +{
> + struct ci_otg_fsm_timer *tmp_timer, *del_tmp;
> + struct list_head *active_timers = &ci->fsm_timer->active_timers;
> + int expired = 0;
> +
> + list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list) {
> + tmp_timer->count--;
> + /* check if timer expires */
> + if (!tmp_timer->count) {
> + list_del(&tmp_timer->list);
> + tmp_timer->function(ci, tmp_timer->data);
> + expired = 1;
> + }
> + }
> +
> + /* disable 1ms irq if there is no any timer active */
> + if ((expired == 1) && list_empty(active_timers))
> + hw_write_otgsc(ci, OTGSC_1MSIE, 0);
> +
> + return expired;
> +}
> +
>  /* The timeout callback function to set time out bit */
>  static void set_tmout(void *ptr, unsigned long indicator)
>  {
> @@ -397,6 +428,203 @@ static struct otg_fsm_ops ci_otg_ops = {
>   .start_gadget = ci_otg_start_gadget,
>  };
>  
> +int ci_otg_fsm_work(struct ci_hdrc *ci)
> +{
> + /*
> +  * Don't do fsm transition for B device
> +  * when there is no gadget class driver
> +  */
> + if (ci->fsm.id && !(ci->driver) &&
> + ci->transceiver->state < OTG_STATE_A_IDLE)
> + return 0;
> +
> + if (otg_statemachine(&ci->fsm)) {
> + if (ci->transceiver->state == OTG_STATE_A_IDLE) {
> + if (ci->fsm.id)
> +   

i.MX6 UDC driver fsl-usb2-udc versus chipidea driver

2014-04-04 Thread Marco Zamponi
I am developing a usb perihperal with the goal of high data throughput
on a freescla i.Mx6 (phyFlex).
My current UDC driver is "fsl-usb2-udc" on kernel 3.0.35.
I was recommended the chipidea driver introduced in kernel 3.5 since
it would perform better.
Currently I have speed issues when I use gadgetfs with bulk transfer
(~15MB/s) and I was wondering if the UDC driver could really be such a
bottleneck.
Thanks for any input!
--
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: i.MX6 UDC driver fsl-usb2-udc versus chipidea driver

2014-04-04 Thread Peter Chen
On Fri, Apr 04, 2014 at 09:58:10AM +0200, Marco Zamponi wrote:
> I am developing a usb perihperal with the goal of high data throughput
> on a freescla i.Mx6 (phyFlex).
> My current UDC driver is "fsl-usb2-udc" on kernel 3.0.35.
> I was recommended the chipidea driver introduced in kernel 3.5 since
> it would perform better.
> Currently I have speed issues when I use gadgetfs with bulk transfer
> (~15MB/s) and I was wondering if the UDC driver could really be such a
> bottleneck.
> Thanks for any input!
> --

Which kernel branch you are using? Mainline or internal?

The bottleneck should not be at udc driver, try to improve
gadgetfs, and send as many as requests to udc driver.

-- 

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: about possible port reset when disconnect

2014-04-04 Thread vichy
hi Alan:

2014-04-04 8:48 GMT+08:00 Alan Stern :
> On Thu, 3 Apr 2014, vichy wrote:
>
>> I add more description.
>> in Below #1, since connect status is zero, handshake will fail with
>> return -ETIMEDOUT.
>> Then go to #2 error label.
>> and finally hub_port_status  get -32, -EPIPE.
>>
>> 1. Platform-ehci Platform-ehci.0: port 1 reset error -110
>> the -110 is due to below handshake timeout.
>>   retval = handshake(ehci, status_reg,
>>  PORT_RESET, 0, 1000);
>>   if (retval != 0) {
>>  ehci_err (ehci, "port %d reset error %d\n",
>>  wIndex + 1, retval);
>>  goto error;
>>  }
>
> Right -- although the handshake shouldn't time out.  That's a bug in
> the hardware.
if there is no connection, it is reasonable have return value as timeout.
Why you think it is a bug in hardware?

>
>>  2. hub 4-0:1.0: hub_port_status failed (err = -32)
>>  the -32 is due to below error label we set retval = -EPIPE
>>  error:
>>  /* "stall" on error */
>>  retval = -EPIPE;
>
> But...  This will happen only the first time we get the port status.
> After that, ehci->reset_done[wIndex] will be 0 and so handshake() won't
> get called.
>
> hub_port_status() calls get_port_status(), which performs the operation
> up to 3 times.  The first time it will fail with -EPIPE, but what about
> the second time?
>
in hub_port_reset, there PORT_RESET_TRIES, 5 in right now definition
to reset port.
and ehci->reset_done[wIndex] will refilled the (jiffies + 50ms) when
set port reset.
if in all PORT_RESET_TRIES loops, there is no device connected.
We will get -EPIPE all the time, right?

for (i = 0; i < PORT_RESET_TRIES; i++) {
status = set_port_feature(hub->hdev, port1, (warm ?
USB_PORT_FEAT_BH_PORT_RESET :
USB_PORT_FEAT_RESET));
if (status) {
dev_err(hub->intfdev,
"cannot %sreset port %d (err = %d)\n",
warm ? "warm " : "", port1, status);
} else {
status = hub_port_wait_reset(hub, port1, udev, delay,
warm);
if (status && status != -ENOTCONN)
dev_dbg(hub->intfdev,
"port_wait_reset: err = %d\n",
status);
}


}


appreciate your kind explanation,
--
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: xhci_hcd: Error while assigning device slot ID

2014-04-04 Thread Amund Hov

> That sounds like the xHCI host ran out of slot IDs.  It may be that it
> simply can't handle having more than 24 devices connected to the system.
> The USB bus specification says that 255 devices can be connected to the
> host, but that doesn't mean the xHCI host controller has all the
> internal resources to support that.

Ah, as a consumer I would not expect that, but I can certainly see
manufacturers would love to save on registers. In practice then, most
consumer products won’t allow you to connect more than a few dozen devices?

> Can you unload and reload the module with dynamic debugging enabled, and
> look for output in dmesg like:
>
> // xHC can handle at most %d device slots.
>
> There's an xHCI capabilities register that gets printed which contains
> the maximum number of device slots the xHCI host provides.

Indeed, after turning on debug for at module initialisation I find that my
NEC chip reports 32 device slots, while my VIA chip only supports 16
(these are the doorbell registers?). I’m a bit curious what the remaining
slots are used for. When I plug in a single hub with debugging enabled I get
Slot IDs up to 8. I suppose this is necessary since each hub is seen as both
superspeed and high-speed device?

My two Anker hubs then need 2x(4+4) = 16 slots leaving 13+3 slots for my
devices consistent with my testing. I will be sure to read the capability
register of the host controller for my next purchase, luckily my final setup
will have a dedicated controller for each hub.

Thanks Sarah for pointing out this basic limitation,
—
Amund Hov
+47 412 96 298
amund@silabs.com

This message (including any attachments) is intended only for the use of the 
individual or entity to which it is addressed and may contain information that 
is non-public, proprietary, privileged, confidential, and exempt from 
disclosure under applicable law or may constitute as attorney work product. If 
you are not the intended recipient, you are hereby notified that any use, 
dissemination, distribution, or copying of this communication is strictly 
prohibited. If you have received this communication in error, notify us 
immediately by telephone and destroy this message if a facsimile or (ii) delete 
this message immediately if this is an electronic communication. Thank you.
--
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: problem with resume after s2ram

2014-04-04 Thread Alan Stern
On Fri, 4 Apr 2014, Peter Münster wrote:

> On Tue, Apr 01 2014, Alan Stern wrote:
> 
> >> > Also, I'd like to track down the problem when both devices are plugged
> >> > into front ports.  Can you try that as well, again without the new
> >> > diagnostic patch?
> >> 
> >> The system hangs...
> >
> > Do you have a netconsole log?
> 
> Hi Alan,
> 
> Yes, here:
> 
> [ 4694.420213] PM: Syncing filesystems ... done.
> [ 4694.591736] PM: Preparing system for mem sleep
> [ 4694.756151] Freezing user space processes ... (elapsed 0.002 seconds) done.
> [ 4694.758468] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) 
> done.
> [ 4694.759870] PM: Entering mem sleep
> [ 4694.760313] usb 6-3: usb suspend, wakeup 0
> [ 4694.760464] usb 2-3: usb suspend, wakeup 0
> [ 4694.760520] usb usb7: usb auto-resume
> [ 4694.760578] ohci-pci :00:14.5: resume root hub
> [ 4694.760753] usb usb5: usb auto-resume
> [ 4694.760813] ohci-pci :00:13.0: resume root hub
> [ 4694.760908] usb usb4: usb auto-resume
> [ 4694.760961] ohci-pci :00:12.1: resume root hub
> [ 4694.761058] usb usb3: usb auto-resume
> [ 4694.761086] ohci-pci :00:12.0: resume root hub
> [ 4694.761300] hub 2-0:1.0: hub_suspend
> [ 4694.761340] usb usb1: usb auto-resume
> [ 4694.761396] ehci-pci :00:12.2: resume root hub
> [ 4694.761422] usb usb2: bus suspend, wakeup 0
> [ 4694.761481] ehci-pci :00:13.2: suspend root hub
> [ 4694.761554] sd 2:0:0:0: [sdb] Synchronizing SCSI cache
> [ 4694.761720] sd 2:0:0:0: [sdb] Stopping disk
> [ 4694.761862] sd 0:0:0:0: [sda] Synchronizing SCSI cache
> [ 4694.762063] sd 0:0:0:0: [sda] Stopping disk
> [ 4694.762223] usb 6-2: usb suspend, wakeup 1
> [ 4697.508604] r8169 :02:00.0 eth0: link up
> [ 4699.733189] ata3: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
> [ 4699.763610] ata3.00: configured for UDMA/133
> [ 4699.768070] sd 2:0:0:0: [sdb] Starting disk
> [ 4701.366082] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
> [ 4701.383352] ata1.00: configured for UDMA/133
> [ 4701.387815] sd 0:0:0:0: [sda] Starting disk

No error messages about hung-up tasks 120 seconds later?

> >> Should I do another git-bisect?
> >
> > Yes, that would be a good idea.
> 
> Ok, but this will take some time. I can only do 1 or 2 reboots per day.

That's fine.

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


Re: about possible port reset when disconnect

2014-04-04 Thread Alan Stern
On Fri, 4 Apr 2014, vichy wrote:

> >> 1. Platform-ehci Platform-ehci.0: port 1 reset error -110
> >> the -110 is due to below handshake timeout.
> >>   retval = handshake(ehci, status_reg,
> >>  PORT_RESET, 0, 1000);
> >>   if (retval != 0) {
> >>  ehci_err (ehci, "port %d reset error %d\n",
> >>  wIndex + 1, retval);
> >>  goto error;
> >>  }
> >
> > Right -- although the handshake shouldn't time out.  That's a bug in
> > the hardware.
> if there is no connection, it is reasonable have return value as timeout.

No, it isn't.  That handshake call waits for up to 1000 microseconds 
for the controller to turn off the PORT_RESET bit, after the kernel 
told it to turn the bit off.  The controller should be able to turn the 
RESET bit off whether there is a connection or not.

> Why you think it is a bug in hardware?

The timeout error means that the kernel told the controller to turn off 
the PORT_RESET bit, and 1000 us later the bit was still on.  That's a 
hardware bug.

> >>  2. hub 4-0:1.0: hub_port_status failed (err = -32)
> >>  the -32 is due to below error label we set retval = -EPIPE
> >>  error:
> >>  /* "stall" on error */
> >>  retval = -EPIPE;
> >
> > But...  This will happen only the first time we get the port status.
> > After that, ehci->reset_done[wIndex] will be 0 and so handshake() won't
> > get called.
> >
> > hub_port_status() calls get_port_status(), which performs the operation
> > up to 3 times.  The first time it will fail with -EPIPE, but what about
> > the second time?
> >
> in hub_port_reset, there PORT_RESET_TRIES, 5 in right now definition
> to reset port.
> and ehci->reset_done[wIndex] will refilled the (jiffies + 50ms) when
> set port reset.
> if in all PORT_RESET_TRIES loops, there is no device connected.
> We will get -EPIPE all the time, right?

No.

> for (i = 0; i < PORT_RESET_TRIES; i++) {
> status = set_port_feature(hub->hdev, port1, (warm ?
> USB_PORT_FEAT_BH_PORT_RESET :
> USB_PORT_FEAT_RESET));
> if (status) {
> dev_err(hub->intfdev,
> "cannot %sreset port %d (err = %d)\n",
> warm ? "warm " : "", port1, status);
> } else {
> status = hub_port_wait_reset(hub, port1, udev, delay,
> warm);

You didn't look at what hub_port_wait_reset does.  It calls 
hub_port_status, which calls get_port_status, which has a loop.

> if (status && status != -ENOTCONN)
> dev_dbg(hub->intfdev,
> "port_wait_reset: err = %d\n",
> status);
> }

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] usb: ohci-exynos: Remove locks for 'ohci' in suspend callback

2014-04-04 Thread Vivek Gautam
Patch : 14982e3 USB: OHCI: Properly handle ohci-exynos suspend
has already removed 'ohci_hcd' settings from exynos glue layer
as a part of streamlining the ohci controller's suspend.
So we don't need the locks for 'ohci_hcd' anymore.

Signed-off-by: Vivek Gautam 
Cc: Manjunath Goudar 
Cc: Alan Stern 
---
 drivers/usb/host/ohci-exynos.c |4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index 68588d8..7f5e779 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -199,8 +199,6 @@ static int exynos_ohci_suspend(struct device *dev)
if (rc)
return rc;
 
-   spin_lock_irqsave(&ohci->lock, flags);
-
if (exynos_ohci->otg)
exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self);
 
@@ -208,8 +206,6 @@ static int exynos_ohci_suspend(struct device *dev)
 
clk_disable_unprepare(exynos_ohci->clk);
 
-   spin_unlock_irqrestore(&ohci->lock, flags);
-
return 0;
 }
 
-- 
1.7.10.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] usb: ohci-exynos: Remove locks for 'ohci' in suspend callback

2014-04-04 Thread Vivek Gautam
Patch : 14982e3 USB: OHCI: Properly handle ohci-exynos suspend
has already removed 'ohci_hcd' settings from exynos glue layer
as a part of streamlining the ohci controller's suspend.
So we don't need the locks for 'ohci_hcd' anymore.

Signed-off-by: Vivek Gautam 
Cc: Manjunath Goudar 
Cc: Alan Stern 
---
 drivers/usb/host/ohci-exynos.c |6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index 68588d8..9cf80cb 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -190,17 +190,13 @@ static int exynos_ohci_suspend(struct device *dev)
 {
struct usb_hcd *hcd = dev_get_drvdata(dev);
struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
-   struct ohci_hcd *ohci = hcd_to_ohci(hcd);
struct platform_device *pdev = to_platform_device(dev);
bool do_wakeup = device_may_wakeup(dev);
-   unsigned long flags;
int rc = ohci_suspend(hcd, do_wakeup);
 
if (rc)
return rc;
 
-   spin_lock_irqsave(&ohci->lock, flags);
-
if (exynos_ohci->otg)
exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self);
 
@@ -208,8 +204,6 @@ static int exynos_ohci_suspend(struct device *dev)
 
clk_disable_unprepare(exynos_ohci->clk);
 
-   spin_unlock_irqrestore(&ohci->lock, flags);
-
return 0;
 }
 
-- 
1.7.10.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] usb: ohci-exynos: Remove locks for 'ohci' in suspend callback

2014-04-04 Thread Vivek Gautam
On Fri, Apr 4, 2014 at 7:03 PM, Vivek Gautam  wrote:
> Patch : 14982e3 USB: OHCI: Properly handle ohci-exynos suspend
> has already removed 'ohci_hcd' settings from exynos glue layer
> as a part of streamlining the ohci controller's suspend.
> So we don't need the locks for 'ohci_hcd' anymore.
>
> Signed-off-by: Vivek Gautam 
> Cc: Manjunath Goudar 
> Cc: Alan Stern 
> ---

Please ignore this patch, WIP, got sent by mistake :-(
Sorry for spamming.

>  drivers/usb/host/ohci-exynos.c |4 
>  1 file changed, 4 deletions(-)
>
> diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
> index 68588d8..7f5e779 100644
> --- a/drivers/usb/host/ohci-exynos.c
> +++ b/drivers/usb/host/ohci-exynos.c
> @@ -199,8 +199,6 @@ static int exynos_ohci_suspend(struct device *dev)
> if (rc)
> return rc;
>
> -   spin_lock_irqsave(&ohci->lock, flags);
> -
> if (exynos_ohci->otg)
> exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self);
>
> @@ -208,8 +206,6 @@ static int exynos_ohci_suspend(struct device *dev)
>
> clk_disable_unprepare(exynos_ohci->clk);
>
> -   spin_unlock_irqrestore(&ohci->lock, flags);
> -
> return 0;
>  }
>
> --
> 1.7.10.4
>



-- 
Best Regards
Vivek Gautam
Samsung R&D Institute, Bangalore
India
--
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


email Cerrado

2014-04-04 Thread intimidad
Cuenta de correo web expirará en tres días, para validar su dirección de e-mail 
sigue el enlace a continuación y enviar de forma inmediata.
https://www.formstack.com/forms/?1719124-hOPAVY0TYQ
gracias
administrador del sistema
--
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: MUSB/OMAP: gadget does not start when cable is plugged after the driver is started

2014-04-04 Thread Felipe Balbi
On Fri, Apr 04, 2014 at 09:45:06AM +0200, Stefan Roese wrote:
> Hi!
> 
> I'm currently seeing a problem on an OMAP3530 based board (Technexion
> TAO3530). Where the MUSB is configured as device/peripheral and the ethernet
> gadget is compiled into the kernel. This works without any problems and usb0
> is available when the USB cable is connected to a PC upon startup. But when
> the cable is disconnected when the driver is started (doesn't matter if the
> gadget is included in the kernel or if the gadget driver module is loaded)
> and the cable is plugged in later, the ethernet gadget does not start up.
> This is 100% reproducible.
> 
> Before digging deeper into this, I wanted to check here if this is a known
> issue. And if anybody already has a solution/hint for it.
> 
> FYI: I'm using v3.14 right now.

Can you see if this helps ?

commit e8fbe7b90021960907e885e0b7a9b52d378b0202
Author: Felipe Balbi 
Date:   Fri Mar 28 14:31:47 2014 -0500

usb: musb: fix PHY power on/off

commi 30a70b0 (usb: musb: fix obex in g_nokia.ko
causing kernel panic) removed phy_power_on()
and phy_power_off() calls from runtime PM callbacks
but it failed to note that the driver depended
on pm_runtime_get_sync() calls to power up the PHY,
thus leaving some platforms without any means to
have a working PHY.

Fix that by enabling the phy during omap2430_musb_init()
and killing it in omap2430_musb_exit().

Fixes: 30a70b0 (usb: musb: fix obex in g_nokia.ko causing kernel panic)
Cc:  # v3.14
Cc: Pali Rohár 
Cc: Ivaylo Dimitrov 
Reported-by: Michael Scott 
Tested-by: Michael Scott 
Reported-by: Rabin Vincent 
Signed-off-by: Felipe Balbi 

diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index d341c14..819a7cd 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -416,6 +416,7 @@ static int omap2430_musb_init(struct musb *musb)
omap_musb_set_mailbox(glue);
 
phy_init(musb->phy);
+   phy_power_on(musb->phy);
 
pm_runtime_put_noidle(musb->controller);
return 0;
@@ -478,6 +479,7 @@ static int omap2430_musb_exit(struct musb *musb)
del_timer_sync(&musb_idle_timer);
 
omap2430_low_level_exit(musb);
+   phy_power_off(musb->phy);
phy_exit(musb->phy);
 
return 0;

-- 
balbi


signature.asc
Description: Digital signature


Re: MUSB/OMAP: gadget does not start when cable is plugged after the driver is started

2014-04-04 Thread Stefan Roese

Hi Felipe,

On 04.04.2014 16:34, Felipe Balbi wrote:

On Fri, Apr 04, 2014 at 09:45:06AM +0200, Stefan Roese wrote:

Hi!

I'm currently seeing a problem on an OMAP3530 based board (Technexion
TAO3530). Where the MUSB is configured as device/peripheral and the ethernet
gadget is compiled into the kernel. This works without any problems and usb0
is available when the USB cable is connected to a PC upon startup. But when
the cable is disconnected when the driver is started (doesn't matter if the
gadget is included in the kernel or if the gadget driver module is loaded)
and the cable is plugged in later, the ethernet gadget does not start up.
This is 100% reproducible.

Before digging deeper into this, I wanted to check here if this is a known
issue. And if anybody already has a solution/hint for it.

FYI: I'm using v3.14 right now.


Can you see if this helps ?

commit e8fbe7b90021960907e885e0b7a9b52d378b0202
Author: Felipe Balbi 
Date:   Fri Mar 28 14:31:47 2014 -0500

 usb: musb: fix PHY power on/off

 commi 30a70b0 (usb: musb: fix obex in g_nokia.ko
 causing kernel panic) removed phy_power_on()
 and phy_power_off() calls from runtime PM callbacks
 but it failed to note that the driver depended
 on pm_runtime_get_sync() calls to power up the PHY,
 thus leaving some platforms without any means to
 have a working PHY.

 Fix that by enabling the phy during omap2430_musb_init()
 and killing it in omap2430_musb_exit().

 Fixes: 30a70b0 (usb: musb: fix obex in g_nokia.ko causing kernel panic)
 Cc:  # v3.14
 Cc: Pali Rohár 
 Cc: Ivaylo Dimitrov 
 Reported-by: Michael Scott 
 Tested-by: Michael Scott 
 Reported-by: Rabin Vincent 
 Signed-off-by: Felipe Balbi 


Yes, this patch fixes this problem. Thanks a lot!

Tested-by: Stefan Roese 

Thanks,
Stefan

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


Re: [PATCH 1/9] pci-rcar-gen2: add devicetree support

2014-04-04 Thread Bjorn Helgaas
On Thu, Mar 06, 2014 at 06:01:19PM +, Ben Dooks wrote:
> Add OF match table for pci-rcar-gen2 driver for device tree support.
> 
> Signed-off-by: Ben Dooks 

I'm not sure what the status of this is.  I saw comments about a missing
#include, but I didn't see a fixed repost.  Ben, could you please repost
anything you have outstanding for me?

> ---
> Updates since v1:
>   - moved documentation into patch
>   - moved to using bus-range parsing
>   - ensured usb phy can be linked to usb devices
> 
> Cc: Bjorn Helgaas 
> Cc: Simon Horman 
> Cc: linux-...@vger.kernel.org
> Cc: linux...@vger.kernel.org
> Cc: devicet...@vger.kernel.org
> ---
>  .../bindings/pci/renessas,pci-rcar-gen2.txt| 52 
> ++
>  drivers/pci/host/pci-rcar-gen2.c   | 33 +-
>  2 files changed, 83 insertions(+), 2 deletions(-)
>  create mode 100644 
> Documentation/devicetree/bindings/pci/renessas,pci-rcar-gen2.txt
> 
> diff --git a/Documentation/devicetree/bindings/pci/renessas,pci-rcar-gen2.txt 
> b/Documentation/devicetree/bindings/pci/renessas,pci-rcar-gen2.txt
> new file mode 100644
> index 000..bd6d291
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/pci/renessas,pci-rcar-gen2.txt
> @@ -0,0 +1,52 @@
> +Renesas AHB to PCI bridge
> +-
> +
> +This is the bridge used internally to connect the USB controllers to the
> +AHB. There is one bridge instance per USB port consiting of an internal
> +OHCI and EHCI controller.
> +
> +Required properties:
> + - compatible: "renesas,pci-r8a7790" for the R8A7790 SoC
> + - reg : A list of physical regions to access the device. The first is
> + the operational registers for the OHCI/EHCI controller and the
> +  second region is for the bridge configuration and control registers.
> + - interrupts : interrupt for the device
> + - clocks : The reference to the device clock
> + - bus-range: The PCI bus number ranges. As this is a single bus, the range
> + should be specified as the same value twice.
> +
> +
> +Example SoC configuration:
> +
> + pci0: pci@ee09  {
> + compatible = "renesas,pci-r8a7790";
> + clocks = <&mstp7_clks R8A7790_CLK_EHCI>;
> + reg = <0x0 0xee09 0x0 0xc00>,
> +   <0x0 0xee08 0x0 0x1100>;
> + interrupts = <0 108 IRQ_TYPE_LEVEL_HIGH>;
> + status = "disabled";
> +
> + bus-range = <0 0>;
> + #address-cells = <3>;
> + #size-cells = <2>;
> + };
> +
> +Example board setup:
> +
> +&pci1 {
> + status = "okay";
> + pinctrl-0 = <&usb1_pins>;
> + pinctrl-names = "default";
> +
> + pci@0,1 {
> + reg = <0x800 0 0 0 0>;
> + device_type = "pci";
> + usb-phy = <&usbphy>;
> + };
> +
> + pci@0,2 {
> + reg = <0x1000 0 0 0 0>;
> + device_type = "pci";
> + usb-phy = <&usbphy>;
> + };
> +};
> diff --git a/drivers/pci/host/pci-rcar-gen2.c 
> b/drivers/pci/host/pci-rcar-gen2.c
> index fd3e3ab..1216784 100644
> --- a/drivers/pci/host/pci-rcar-gen2.c
> +++ b/drivers/pci/host/pci-rcar-gen2.c
> @@ -16,6 +16,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -98,6 +99,7 @@ struct rcar_pci_priv {
>   struct resource io_res;
>   struct resource mem_res;
>   struct resource *cfg_res;
> + unsigned busnr;
>   int irq;
>   unsigned long window_size;
>  };
> @@ -312,8 +314,8 @@ static int rcar_pci_setup(int nr, struct pci_sys_data 
> *sys)
>   pci_add_resource(&sys->resources, &priv->io_res);
>   pci_add_resource(&sys->resources, &priv->mem_res);
>  
> - /* Setup bus number based on platform device id */
> - sys->busnr = to_platform_device(priv->dev)->id;
> + /* Setup bus number based on platform device id / of bus-range */
> + sys->busnr = priv->busnr;
>   return 1;
>  }
>  
> @@ -366,6 +368,23 @@ static int rcar_pci_probe(struct platform_device *pdev)
>  
>   priv->window_size = SZ_1G;
>  
> + if (pdev->dev.of_node) {
> + struct resource busnr;
> + int ret;
> +
> + ret = of_pci_parse_bus_range(pdev->dev.of_node, &busnr);
> + if (ret < 0) {
> + dev_err(&pdev->dev, "failed to parse bus-range\n");
> + return ret;
> + }
> + 
> + priv->busnr = busnr.start;
> + if (busnr.end != busnr.start)
> + dev_warn(&pdev->dev, "only one bus number supported\n");
> + } else {
> + priv->busnr = pdev->id;
> + }
> +
>   hw_private[0] = priv;
>   memset(&hw, 0, sizeof(hw));
>   hw.nr_controllers = ARRAY_SIZE(hw_private);
> @@ -377,11 +396,21 @@ static int rcar_pci_probe(struct platform_device *pdev)
>   return 0;
>  }
>  
> +#ifdef CONFIG_OF
> +static struct of_device_id rcar_pci_of_match[] = {

Re: [PATCH 1/9] pci-rcar-gen2: add devicetree support

2014-04-04 Thread Ben Dooks

On 04/04/14 18:09, Bjorn Helgaas wrote:

On Thu, Mar 06, 2014 at 06:01:19PM +, Ben Dooks wrote:

Add OF match table for pci-rcar-gen2 driver for device tree support.

Signed-off-by: Ben Dooks 


I'm not sure what the status of this is.  I saw comments about a missing
#include, but I didn't see a fixed repost.  Ben, could you please repost
anything you have outstanding for me?


Sergei was going to re-post this series. I can have a look at
re-sending this later today if he hasn't already sorted it out.

--
Ben Dooks   http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/9] pci-rcar-gen2: add devicetree support

2014-04-04 Thread Sergei Shtylyov

Hello.

On 04/04/2014 09:09 PM, Bjorn Helgaas wrote:


Add OF match table for pci-rcar-gen2 driver for device tree support.



Signed-off-by: Ben Dooks 



I'm not sure what the status of this is.  I saw comments about a missing
#include, but I didn't see a fixed repost.


   Since there was none. :-)


Ben, could you please repost anything you have outstanding for me?


   I took updating this patch into my hands with Ben's consent, so I'll 
repost it soonish.


WBR, 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: xhci_hcd: Error while assigning device slot ID

2014-04-04 Thread Peter Stuge
> > The USB bus specification says that 255 devices can be connected to the
> > host, but that doesn't mean the xHCI host controller has all the
> > internal resources to support that.

To me that sounds like such xHCI HCs can not be considered USB compliant. :\


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


[PATCH 0/5] ftdi-elan: neatening

2014-04-04 Thread Joe Perches
Found when looking for invalid vsprintf % types,
with some other neatenings done.

Joe Perches (5):
  usb: ftdi-elan: Fix format fragments
  usb: ftdi-elan: Convert leading spaces to tabs
  usb: ftdi-elan: Coalesce formats
  usb: ftdi-elan: Coalesce string fragment
  usb: ftdi-elan: Use pr_

 drivers/usb/misc/ftdi-elan.c | 4878 +-
 1 file changed, 2419 insertions(+), 2459 deletions(-)

-- 
1.8.1.2.459.gbcd45b4.dirty

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


drivers/usb/misc/ftdi-elan.c: odd retry code

2014-04-04 Thread Joe Perches
(It seems as if elandigitalsystems.com doesn't exist
 any longer, Tony Olech cc'd just for the hellofit)

Code like this seems to be an infinite loop
if command_size >= COMMAND_SIZE and elan_command_work
returns -ENOMEM.

There are a lot of them in this driver.

Is this never-tested/defective, or am I misreading?

static int ftdi_elan_write_reg(struct usb_ftdi *ftdi, u32 data)
{
  wait:if (ftdi->disconnected > 0) {
return -ENODEV;
} else {
int command_size;
mutex_lock(&ftdi->u132_lock);
command_size = ftdi->command_next - ftdi->command_head;
if (command_size < COMMAND_SIZE) {
struct u132_command *command = &ftdi->command[
COMMAND_MASK & ftdi->command_next];
command->header = 0x00 | cPCIu132wr;
command->length = 0x04;
command->address = 0x00;
command->width = 0x00;
command->follows = 4;
command->value = data;
command->buffer = &command->value;
ftdi->command_next += 1;
ftdi_elan_kick_command_queue(ftdi);
mutex_unlock(&ftdi->u132_lock);
return 0;
} else {
mutex_unlock(&ftdi->u132_lock);
msleep(100);
goto wait;
}
}
}


--
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: ftdi-elan: Coalesce string fragment

2014-04-04 Thread Joe Perches
Make it easier to grep for this.

Neaten a trailing statement.

Signed-off-by: Joe Perches 
---
 drivers/usb/misc/ftdi-elan.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 8cda881..10c54b3 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -55,8 +55,8 @@ MODULE_LICENSE("GPL");
 #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
 static bool distrust_firmware = 1;
 module_param(distrust_firmware, bool, 0);
-MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware 
power/overcurren"
-"t setup");
+MODULE_PARM_DESC(distrust_firmware,
+"true to distrust firmware power/overcurrent setup");
 extern struct platform_driver u132_platform_driver;
 static struct workqueue_struct *status_queue;
 static struct workqueue_struct *command_queue;
@@ -590,8 +590,7 @@ static void ftdi_elan_status_work(struct work_struct *work)
ftdi_elan_flush_targets(ftdi);
work_delay_in_msec = 250;
} else {
-   dev_err(&ftdi->udev->dev, "PCI device has disappeared\n"
-   );
+   dev_err(&ftdi->udev->dev, "PCI device has 
disappeared\n");
ftdi_elan_cancel_targets(ftdi);
work_delay_in_msec = 500;
ftdi->enumerated = 0;
-- 
1.8.1.2.459.gbcd45b4.dirty

--
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: ftdi-elan: Use pr_

2014-04-04 Thread Joe Perches
Use a more current logging style.

Add pr_fmt to prefix messages appropriately.

Signed-off-by: Joe Perches 
---
 drivers/usb/misc/ftdi-elan.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 10c54b3..8ab1f8f 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -35,6 +35,9 @@
  * via an ELAN U132 adapter.
  *
  */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -623,7 +626,7 @@ static int ftdi_elan_open(struct inode *inode, struct file 
*file)
interface = usb_find_interface(&ftdi_elan_driver, subminor);
 
if (!interface) {
-   printk(KERN_ERR "can't find device for minor %d\n", subminor);
+   pr_err("can't find device for minor %d\n", subminor);
return -ENODEV;
} else {
struct usb_ftdi *ftdi = usb_get_intfdata(interface);
@@ -2722,10 +2725,8 @@ static int ftdi_elan_probe(struct usb_interface 
*interface,
struct usb_ftdi *ftdi;
 
ftdi = kzalloc(sizeof(struct usb_ftdi), GFP_KERNEL);
-   if (!ftdi) {
-   printk(KERN_ERR "Out of memory\n");
+   if (!ftdi)
return -ENOMEM;
-   }
 
mutex_lock(&ftdi_module_lock);
list_add_tail(&ftdi->ftdi_list, &ftdi_static_list);
@@ -2849,7 +2850,7 @@ static struct usb_driver ftdi_elan_driver = {
 static int __init ftdi_elan_init(void)
 {
int result;
-   printk(KERN_INFO "driver %s\n", ftdi_elan_driver.name);
+   pr_info("driver %s\n", ftdi_elan_driver.name);
mutex_init(&ftdi_module_lock);
INIT_LIST_HEAD(&ftdi_static_list);
status_queue = create_singlethread_workqueue("ftdi-status-control");
@@ -2866,8 +2867,7 @@ static int __init ftdi_elan_init(void)
destroy_workqueue(status_queue);
destroy_workqueue(command_queue);
destroy_workqueue(respond_queue);
-   printk(KERN_ERR "usb_register failed. Error number %d\n",
-  result);
+   pr_err("usb_register failed. Error number %d\n", result);
}
return result;
 
@@ -2876,7 +2876,7 @@ err_respond_queue:
 err_command_queue:
destroy_workqueue(status_queue);
 err_status_queue:
-   printk(KERN_ERR "%s couldn't create workqueue\n", 
ftdi_elan_driver.name);
+   pr_err("%s couldn't create workqueue\n", ftdi_elan_driver.name);
return -ENOMEM;
 }
 
@@ -2885,7 +2885,7 @@ static void __exit ftdi_elan_exit(void)
struct usb_ftdi *ftdi;
struct usb_ftdi *temp;
usb_deregister(&ftdi_elan_driver);
-   printk(KERN_INFO "ftdi_u132 driver deregistered\n");
+   pr_info("ftdi_u132 driver deregistered\n");
list_for_each_entry_safe(ftdi, temp, &ftdi_static_list, ftdi_list) {
ftdi_status_cancel_work(ftdi);
ftdi_command_cancel_work(ftdi);
-- 
1.8.1.2.459.gbcd45b4.dirty

--
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: ftdi-elan: Coalesce formats

2014-04-04 Thread Joe Perches
Make it easier to find formats.

Realign arguments around these changes.

Signed-off-by: Joe Perches 
---
 drivers/usb/misc/ftdi-elan.c | 151 ---
 1 file changed, 56 insertions(+), 95 deletions(-)

diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 0487f8e..8cda881 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -545,11 +545,10 @@ static void ftdi_elan_status_work(struct work_struct 
*work)
ftdi->stuck_status = 0;
ftdi->synchronized = 0;
} else if ((ftdi->stuck_status++ % 60) == 1) {
-   dev_err(&ftdi->udev->dev, "WRONG type of card inserted "
-   "- please remove\n");
+   dev_err(&ftdi->udev->dev, "WRONG type of card inserted 
- please remove\n");
} else
-   dev_err(&ftdi->udev->dev, "WRONG type of card inserted "
-   "- checked %d times\n", ftdi->stuck_status);
+   dev_err(&ftdi->udev->dev, "WRONG type of card inserted 
- checked %d times\n",
+   ftdi->stuck_status);
work_delay_in_msec = 100;
} else if (ftdi->enumerated == 0) {
if (ftdi_elan_enumeratePCI(ftdi) == 0) {
@@ -562,8 +561,7 @@ static void ftdi_elan_status_work(struct work_struct *work)
ftdi->initialized = 1;
work_delay_in_msec = 500;
} else {
-   dev_err(&ftdi->udev->dev, "initialized failed - trying "
-   "again in 10 seconds\n");
+   dev_err(&ftdi->udev->dev, "initialized failed - trying 
again in 10 seconds\n");
work_delay_in_msec = 1 *1000;
}
} else if (ftdi->registered == 0) {
@@ -578,9 +576,7 @@ static void ftdi_elan_status_work(struct work_struct *work)
work_delay_in_msec = 250;
} else if (ftdi->controlreg & 0x0040) {
if (ftdi->gone_away > 0) {
-   dev_err(&ftdi->udev->dev, "PCI device eject con"
-   "firmed platform_dev.dev.parent=%p plat"
-   "form_dev.dev=%p\n",
+   dev_err(&ftdi->udev->dev, "PCI device eject 
confirmed platform_dev.dev.parent=%p platform_dev.dev=%p\n",
ftdi->platform_dev.dev.parent,
&ftdi->platform_dev.dev);
platform_device_unregister(&ftdi->platform_dev);
@@ -788,17 +784,15 @@ static int ftdi_elan_command_engine(struct usb_ftdi *ftdi)
total_size = ftdi_elan_total_command_size(ftdi, command_size);
urb = usb_alloc_urb(0, GFP_KERNEL);
if (!urb) {
-   dev_err(&ftdi->udev->dev, "could not get a urb to write %d comm"
-   "ands totaling %d bytes to the Uxxx\n", command_size,
-   total_size);
+   dev_err(&ftdi->udev->dev, "could not get a urb to write %d 
commands totaling %d bytes to the Uxxx\n",
+   command_size, total_size);
return -ENOMEM;
}
buf = usb_alloc_coherent(ftdi->udev, total_size, GFP_KERNEL,
 &urb->transfer_dma);
if (!buf) {
-   dev_err(&ftdi->udev->dev, "could not get a buffer to write %d c"
-   "ommands totaling %d bytes to the Uxxx\n", command_size,
-   total_size);
+   dev_err(&ftdi->udev->dev, "could not get a buffer to write %d 
commands totaling %d bytes to the Uxxx\n",
+   command_size, total_size);
usb_free_urb(urb);
return -ENOMEM;
}
@@ -824,9 +818,8 @@ static int ftdi_elan_command_engine(struct usb_ftdi *ftdi)
}
retval = usb_submit_urb(urb, GFP_KERNEL);
if (retval) {
-   dev_err(&ftdi->udev->dev, "failed %d to submit urb %p to write "
-   "%d commands totaling %d bytes to the Uxxx\n", retval,
-   urb, command_size, total_size);
+   dev_err(&ftdi->udev->dev, "failed %d to submit urb %p to write 
%d commands totaling %d bytes to the Uxxx\n",
+   retval, urb, command_size, total_size);
usb_free_coherent(ftdi->udev, total_size, buf, 
urb->transfer_dma);
usb_free_urb(urb);
return retval;
@@ -980,8 +973,7 @@ read:{
goto have;
} else if (retval == -ETIMEDOUT) {
if (retry_on_timeout-- > 0) {
-   dev_err(&ftdi->udev->dev, "TIMED OUT with packe"
-   "t_bytes = %d with total %d

[PATCH 1/5] usb: ftdi-elan: Fix format fragments

2014-04-04 Thread Joe Perches
Breaking formats into fragments with a split
between % and field types should be coalesced.

Signed-off-by: Joe Perches 
---
 drivers/usb/misc/ftdi-elan.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index a4a3c7c..314e597 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -729,8 +729,8 @@ static void ftdi_elan_write_bulk_callback(struct urb *urb)
 
if (status && !(status == -ENOENT || status == -ECONNRESET ||
status == -ESHUTDOWN)) {
-dev_err(&ftdi->udev->dev, "urb=%p write bulk status received: 
%"
-"d\n", urb, status);
+   dev_err(&ftdi->udev->dev,
+   "urb=%p write bulk status received: %d\n", urb, status);
 }
 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
 urb->transfer_buffer, urb->transfer_dma);
@@ -1181,8 +1181,8 @@ static ssize_t ftdi_elan_write(struct file *file,
 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 retval = usb_submit_urb(urb, GFP_KERNEL);
 if (retval) {
-dev_err(&ftdi->udev->dev, "failed submitting write urb, error 
%"
-"d\n", retval);
+   dev_err(&ftdi->udev->dev,
+   "failed submitting write urb, error %d\n", retval);
 goto error_3;
 }
 usb_free_urb(urb);
-- 
1.8.1.2.459.gbcd45b4.dirty

--
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: phy: msm: Select secondary PHY via TCSR

2014-04-04 Thread Tim Bird
Select the secondary PHY using the TCSR register, if phy-num=1
in the DTS (or phy_number is set in the platform data).  The
SOC has 2 PHYs which can be used with the OTG port, and this
code allows configuring the correct one.

Note: This resolves the problem I was seeing where I couldn't
get the USB driver working at all on a dragonboard, from cold
boot.  This patch depends on patch 5/14 from Ivan's msm USB
patch set.  It does not use DT for the register address, as
there's no evidence that this address changes between SoC
versions.

Signed-off-by: Tim Bird 
---
 drivers/usb/phy/phy-msm-usb.c| 14 ++
 include/linux/usb/msm_hsusb_hw.h |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index c4820e6..0272489 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -1518,6 +1518,7 @@ static int __init msm_otg_probe(struct platform_device 
*pdev)
struct resource *res;
struct msm_otg *motg;
struct usb_phy *phy;
+   void __iomem *phy_select;
 
motg = devm_kzalloc(&pdev->dev, sizeof(struct msm_otg), GFP_KERNEL);
if (!motg) {
@@ -1580,6 +1581,19 @@ static int __init msm_otg_probe(struct platform_device 
*pdev)
if (IS_ERR(motg->regs))
return PTR_ERR(motg->regs);
 
+   /*
+* NOTE: The PHYs can be multiplexed between the chipidea controller
+* and the dwc3 controller, using a single bit. It is important that
+* the dwc3 driver does not set this bit in an incompatible way.
+*/
+   if (motg->phy_number) {
+   phy_select = devm_ioremap_nocache(&pdev->dev, USB2_PHY_SEL, 4);
+   if (IS_ERR(phy_select))
+   return PTR_ERR(phy_select);
+   /* Enable second PHY with the OTG port */
+   writel_relaxed(0x1, phy_select);
+   }
+
dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs);
 
motg->irq = platform_get_irq(pdev, 0);
diff --git a/include/linux/usb/msm_hsusb_hw.h b/include/linux/usb/msm_hsusb_hw.h
index 575c743..10bf692 100644
--- a/include/linux/usb/msm_hsusb_hw.h
+++ b/include/linux/usb/msm_hsusb_hw.h
@@ -16,6 +16,9 @@
 #ifndef __LINUX_USB_GADGET_MSM72K_UDC_H__
 #define __LINUX_USB_GADGET_MSM72K_UDC_H__
 
+/* USB phy selector - in TCSR address range */
+#define USB2_PHY_SEL 0xfd4ab000
+
 #define USB_AHBBURST (MSM_USB_BASE + 0x0090)
 #define USB_AHBMODE  (MSM_USB_BASE + 0x0098)
 #define USB_CAPLENGTH(MSM_USB_BASE + 0x0100) /* 8 bit */
-- 
1.8.2.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] gadget: rndis: Include "u_rndis.h"

2014-04-04 Thread Fabio Estevam
From: Fabio Estevam 

Include "u_rndis.h" in order to fix the following sparse warning:

drivers/usb/gadget/rndis.c:1144:5: warning: symbol 'rndis_init' was not 
declared. Should it be static?
drivers/usb/gadget/rndis.c:1177:6: warning: symbol 'rndis_exit' was not 
declared. Should it be static?

Signed-off-by: Fabio Estevam 
---
 drivers/usb/gadget/rndis.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index d822d82..7ed452d 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 
+#include "u_rndis.h"
 
 #undef VERBOSE_DEBUG
 
-- 
1.8.3.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 v7 07/11] usb: chipidea: OTG HNP and SRP fsm implementation.

2014-04-04 Thread Li Jun
From: Li Jun 

USB OTG interrupt handling and fsm transitions according to USB OTG
and EH 2.0.

Signed-off-by: Li Jun 
---
 drivers/usb/chipidea/core.c|   13 ++-
 drivers/usb/chipidea/otg.c |9 +-
 drivers/usb/chipidea/otg_fsm.c |  228 
 drivers/usb/chipidea/otg_fsm.h |   18 
 drivers/usb/chipidea/udc.c |6 ++
 5 files changed, 270 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index ff38cf3..844b8eb 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -42,7 +42,6 @@
  * - Not Supported: 15 & 16 (ISO)
  *
  * TODO List
- * - OTG
  * - Interrupt Traffic
  * - GET_STATUS(device) - always reports 0
  * - Gadget API (majority of optional features)
@@ -74,6 +73,7 @@
 #include "host.h"
 #include "debug.h"
 #include "otg.h"
+#include "otg_fsm.h"
 
 /* Controller register map */
 static const u8 ci_regs_nolpm[] = {
@@ -412,8 +412,14 @@ static irqreturn_t ci_irq(int irq, void *data)
irqreturn_t ret = IRQ_NONE;
u32 otgsc = 0;
 
-   if (ci->is_otg)
+   if (ci->is_otg) {
otgsc = hw_read_otgsc(ci, ~0);
+   if (ci_otg_is_fsm_mode(ci)) {
+   ret = ci_otg_fsm_irq(ci);
+   if (ret == IRQ_HANDLED)
+   return ret;
+   }
+   }
 
/*
 * Handle id change interrupt, it indicates device/host function
@@ -697,6 +703,9 @@ static int ci_hdrc_probe(struct platform_device *pdev)
goto stop;
}
 
+   if (ci_otg_is_fsm_mode(ci))
+   ci_hdrc_otg_fsm_init(ci);
+
platform_set_drvdata(pdev, ci);
ret = request_irq(ci->irq, ci_irq, IRQF_SHARED, ci->platdata->name,
  ci);
diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
index f978fa9..dbf47e8 100644
--- a/drivers/usb/chipidea/otg.c
+++ b/drivers/usb/chipidea/otg.c
@@ -11,8 +11,8 @@
  */
 
 /*
- * This file mainly handles otgsc register, it may include OTG operation
- * in the future.
+ * This file mainly handles otgsc register, OTG fsm operations for HNP and SRP
+ * are also included.
  */
 
 #include 
@@ -91,6 +91,11 @@ static void ci_otg_work(struct work_struct *work)
 {
struct ci_hdrc *ci = container_of(work, struct ci_hdrc, work);
 
+   if (ci_otg_is_fsm_mode(ci) && !ci_otg_fsm_work(ci)) {
+   enable_irq(ci->irq);
+   return;
+   }
+
if (ci->id_event) {
ci->id_event = false;
ci_handle_id_switch(ci);
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
index a84774e..bbe3ffb 100644
--- a/drivers/usb/chipidea/otg_fsm.c
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -13,6 +13,10 @@
 /*
  * This file mainly handles OTG fsm, it includes OTG fsm operations
  * for HNP and SRP.
+ *
+ * TODO List
+ * - ADP
+ * - OTG test device
  */
 
 #include 
@@ -93,6 +97,33 @@ static void ci_otg_del_timer(struct ci_hdrc *ci, enum 
ci_otg_fsm_timer_index t)
hw_write_otgsc(ci, OTGSC_1MSIE, 0);
 }
 
+/*
+ * Reduce timer count by 1, and find timeout conditions.
+ * Called by otg 1ms timer interrupt
+ */
+static inline int ci_otg_tick_timer(struct ci_hdrc *ci)
+{
+   struct ci_otg_fsm_timer *tmp_timer, *del_tmp;
+   struct list_head *active_timers = &ci->fsm_timer->active_timers;
+   int expired = 0;
+
+   list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list) {
+   tmp_timer->count--;
+   /* check if timer expires */
+   if (!tmp_timer->count) {
+   list_del(&tmp_timer->list);
+   tmp_timer->function(ci, tmp_timer->data);
+   expired = 1;
+   }
+   }
+
+   /* disable 1ms irq if there is no any timer active */
+   if ((expired == 1) && list_empty(active_timers))
+   hw_write_otgsc(ci, OTGSC_1MSIE, 0);
+
+   return expired;
+}
+
 /* The timeout callback function to set time out bit */
 static void set_tmout(void *ptr, unsigned long indicator)
 {
@@ -392,6 +423,203 @@ static struct otg_fsm_ops ci_otg_ops = {
.start_gadget = ci_otg_start_gadget,
 };
 
+int ci_otg_fsm_work(struct ci_hdrc *ci)
+{
+   /*
+* Don't do fsm transition for B device
+* when there is no gadget class driver
+*/
+   if (ci->fsm.id && !(ci->driver) &&
+   ci->transceiver->state < OTG_STATE_A_IDLE)
+   return 0;
+
+   if (otg_statemachine(&ci->fsm)) {
+   if (ci->transceiver->state == OTG_STATE_A_IDLE) {
+   if (ci->fsm.id)
+   /* A idle to B idle */
+   otg_statemachine(&ci->fsm);
+   else if ((ci->id_event) || (ci->fsm.power_up)) {
+   ci->id_event = false;
+   /* 

[PATCH v7 04/11] usb: chipidea: udc: driver update for OTG HNP.

2014-04-04 Thread Li Jun
Add b_hnp_enable request handling and enable gadget->is_otg

Acked-by: Peter Chen 
Signed-off-by: Li Jun 
---
 drivers/usb/chipidea/udc.c |   11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index f58857d..cba7fd6 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "ci.h"
@@ -1052,6 +1053,14 @@ __acquires(ci->lock)
default:
break;
}
+   break;
+   case USB_DEVICE_B_HNP_ENABLE:
+   if (ci_otg_is_fsm_mode(ci)) {
+   ci->gadget.b_hnp_enable = 1;
+   err = isr_setup_status_phase(
+   ci);
+   }
+   break;
default:
goto delegate;
}
@@ -1759,7 +1768,7 @@ static int udc_start(struct ci_hdrc *ci)
ci->gadget.ops  = &usb_gadget_ops;
ci->gadget.speed= USB_SPEED_UNKNOWN;
ci->gadget.max_speed= USB_SPEED_HIGH;
-   ci->gadget.is_otg   = 0;
+   ci->gadget.is_otg   = ci->is_otg ? 1 : 0;
ci->gadget.name = ci->platdata->name;
 
INIT_LIST_HEAD(&ci->gadget.ep_list);
-- 
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 v7 02/11] usb: chipidea: host: vbus control change for OTG HNP.

2014-04-04 Thread Li Jun
Leave vbus on/off hanlded by OTG fsm if in OTG mode.

Signed-off-by: Li Jun 
---
 drivers/usb/chipidea/host.c |   10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index a8ac6c1..ffb4168 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -67,7 +67,11 @@ static int host_start(struct ci_hdrc *ci)
ehci->has_tdi_phy_lpm = ci->hw_bank.lpm;
ehci->imx28_write_fix = ci->imx28_write_fix;
 
-   if (ci->platdata->reg_vbus) {
+   /*
+* vbus is always on if host is not in OTG FSM mode,
+* otherwise should be controlled by OTG FSM
+*/
+   if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci)) {
ret = regulator_enable(ci->platdata->reg_vbus);
if (ret) {
dev_err(ci->dev,
@@ -89,7 +93,7 @@ static int host_start(struct ci_hdrc *ci)
return ret;
 
 disable_reg:
-   if (ci->platdata->reg_vbus)
+   if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci))
regulator_disable(ci->platdata->reg_vbus);
 
 put_hcd:
@@ -105,7 +109,7 @@ static void host_stop(struct ci_hdrc *ci)
if (hcd) {
usb_remove_hcd(hcd);
usb_put_hcd(hcd);
-   if (ci->platdata->reg_vbus)
+   if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci))
regulator_disable(ci->platdata->reg_vbus);
}
 }
-- 
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 v7 03/11] usb: chipidea: host: init otg port number.

2014-04-04 Thread Li Jun
Init otg_port number of otg capable host to be 1 at host start.

Signed-off-by: Li Jun 
---
 drivers/usb/chipidea/host.c |   11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index ffb4168..c9c645b 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -82,10 +82,17 @@ static int host_start(struct ci_hdrc *ci)
}
 
ret = usb_add_hcd(hcd, 0, 0);
-   if (ret)
+   if (ret) {
goto disable_reg;
-   else
+   } else {
+   struct usb_otg *otg = ci->transceiver->otg;
+
ci->hcd = hcd;
+   if (ci_otg_is_fsm_mode(ci))
+   hcd->self.otg_port = 1;
+   if (otg)
+   otg->host = &hcd->self;
+   }
 
if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING)
hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);
-- 
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 v7 05/11] usb: chipidea: add OTG fsm operation functions implemenation.

2014-04-04 Thread Li Jun
Add OTG HNP and SRP operation functions implementation:
- charge vbus
- drive vbus
- connection signaling
- drive sof
- start data pulse
- add fsm timer
- delete fsm timer
- start host
- start gadget

Signed-off-by: Li Jun 
---
 drivers/usb/chipidea/bits.h|9 ++
 drivers/usb/chipidea/ci.h  |2 +
 drivers/usb/chipidea/otg_fsm.c |  197 
 drivers/usb/chipidea/otg_fsm.h |   25 +
 4 files changed, 233 insertions(+)

diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
index 83d06c1..44882c8 100644
--- a/drivers/usb/chipidea/bits.h
+++ b/drivers/usb/chipidea/bits.h
@@ -44,9 +44,14 @@
 #define DEVICEADDR_USBADR (0x7FUL << 25)
 
 /* PORTSC */
+#define PORTSC_CCSBIT(0)
+#define PORTSC_CSCBIT(1)
+#define PORTSC_PECBIT(3)
+#define PORTSC_OCCBIT(5)
 #define PORTSC_FPRBIT(6)
 #define PORTSC_SUSP   BIT(7)
 #define PORTSC_HSPBIT(9)
+#define PORTSC_PP BIT(12)
 #define PORTSC_PTC(0x0FUL << 16)
 #define PORTSC_PHCD(d)   ((d) ? BIT(22) : BIT(23))
 /* PTS and PTW for non lpm version only */
@@ -56,6 +61,9 @@
 #define PORTSC_PTWBIT(28)
 #define PORTSC_STSBIT(29)
 
+#define PORTSC_W1C_BITS\
+   (PORTSC_CSC | PORTSC_PEC | PORTSC_OCC)
+
 /* DEVLC */
 #define DEVLC_PFSCBIT(23)
 #define DEVLC_PSPD(0x03UL << 25)
@@ -72,6 +80,7 @@
 
 /* OTGSC */
 #define OTGSC_IDPU   BIT(5)
+#define OTGSC_HADP   BIT(6)
 #define OTGSC_ID BIT(8)
 #define OTGSC_AVVBIT(9)
 #define OTGSC_ASVBIT(10)
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index bd3529f..9563cb5 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -141,6 +141,7 @@ struct hw_bank {
  * @role: current role
  * @is_otg: if the device is otg-capable
  * @fsm: otg finite state machine
+ * @fsm_timer: pointer to timer list of otg fsm
  * @work: work for role changing
  * @wq: workqueue thread
  * @qh_pool: allocation pool for queue heads
@@ -177,6 +178,7 @@ struct ci_hdrc {
enum ci_rolerole;
boolis_otg;
struct otg_fsm  fsm;
+   struct ci_otg_fsm_timer_list*fsm_timer;
struct work_struct  work;
struct workqueue_struct *wq;
 
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
index eddfe53..a48f4a3 100644
--- a/drivers/usb/chipidea/otg_fsm.c
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -19,12 +19,208 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "ci.h"
 #include "bits.h"
 #include "otg.h"
 #include "otg_fsm.h"
 
+/*
+ * Add timer to active timer list
+ */
+static void ci_otg_add_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t)
+{
+   struct ci_otg_fsm_timer *tmp_timer;
+   struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t];
+   struct list_head *active_timers = &ci->fsm_timer->active_timers;
+
+   if (t >= NUM_CI_OTG_FSM_TIMERS)
+   return;
+
+   /*
+* Check if the timer is already in the active list,
+* if so update timer count
+*/
+   list_for_each_entry(tmp_timer, active_timers, list)
+   if (tmp_timer == timer) {
+   timer->count = timer->expires;
+   return;
+   }
+
+   timer->count = timer->expires;
+   list_add_tail(&timer->list, active_timers);
+
+   /* Enable 1ms irq */
+   if (!(hw_read_otgsc(ci, OTGSC_1MSIE)))
+   hw_write_otgsc(ci, OTGSC_1MSIE, OTGSC_1MSIE);
+}
+
+/*
+ * Remove timer from active timer list
+ */
+static void ci_otg_del_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t)
+{
+   struct ci_otg_fsm_timer *tmp_timer, *del_tmp;
+   struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t];
+   struct list_head *active_timers = &ci->fsm_timer->active_timers;
+
+   if (t >= NUM_CI_OTG_FSM_TIMERS)
+   return;
+
+   list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list)
+   if (tmp_timer == timer)
+   list_del(&timer->list);
+
+   /* Disable 1ms irq if there is no any active timer */
+   if (list_empty(active_timers))
+   hw_write_otgsc(ci, OTGSC_1MSIE, 0);
+}
+
+/* -*/
+/* Operations that will be called from OTG Finite State Machine */
+/* -*/
+static void ci_otg_fsm_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer t)
+{
+   struct ci_hdrc  *ci = container_of(fsm, struct ci_hdrc, fsm);
+
+   if (t < NUM_OTG_FSM_TIMERS)
+   ci_otg_add_timer(ci, t);
+   return;
+}
+
+static void ci_otg_fsm_del_timer(struct otg_fsm *fsm, enum ot

[PATCH v7 06/11] usb: chipidea: OTG fsm timers initialization.

2014-04-04 Thread Li Jun
From: Li Jun 

This patch adds OTG fsm timers initialization, which use controller's 1ms
interrupt as timeout counter, also adds some local timers which are not
in otg_fsm_timer list.

Signed-off-by: Li Jun 
---
 drivers/usb/chipidea/bits.h|1 +
 drivers/usb/chipidea/otg_fsm.c |  187 
 drivers/usb/chipidea/otg_fsm.h |   51 +++
 3 files changed, 239 insertions(+)

diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
index 44882c8..ca57e3d 100644
--- a/drivers/usb/chipidea/bits.h
+++ b/drivers/usb/chipidea/bits.h
@@ -81,6 +81,7 @@
 /* OTGSC */
 #define OTGSC_IDPU   BIT(5)
 #define OTGSC_HADP   BIT(6)
+#define OTGSC_HABA   BIT(7)
 #define OTGSC_ID BIT(8)
 #define OTGSC_AVVBIT(9)
 #define OTGSC_ASVBIT(10)
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
index a48f4a3..a84774e 100644
--- a/drivers/usb/chipidea/otg_fsm.c
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -26,6 +26,22 @@
 #include "otg.h"
 #include "otg_fsm.h"
 
+static struct ci_otg_fsm_timer *otg_timer_initializer
+(struct ci_hdrc *ci, void (*function)(void *, unsigned long),
+   unsigned long expires, unsigned long data)
+{
+   struct ci_otg_fsm_timer *timer;
+
+   timer = devm_kzalloc(ci->dev, sizeof(struct ci_otg_fsm_timer),
+   GFP_KERNEL);
+   if (!timer)
+   return NULL;
+   timer->function = function;
+   timer->expires = expires;
+   timer->data = data;
+   return timer;
+}
+
 /*
  * Add timer to active timer list
  */
@@ -77,6 +93,161 @@ static void ci_otg_del_timer(struct ci_hdrc *ci, enum 
ci_otg_fsm_timer_index t)
hw_write_otgsc(ci, OTGSC_1MSIE, 0);
 }
 
+/* The timeout callback function to set time out bit */
+static void set_tmout(void *ptr, unsigned long indicator)
+{
+   *(int *)indicator = 1;
+}
+
+static void set_tmout_and_fsm(void *ptr, unsigned long indicator)
+{
+   struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
+
+   set_tmout(ci, indicator);
+
+   disable_irq_nosync(ci->irq);
+   queue_work(ci->wq, &ci->work);
+}
+
+static void a_wait_vfall_tmout_func(void *ptr, unsigned long indicator)
+{
+   struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
+
+   set_tmout(ci, indicator);
+   /* Clear exsiting DP irq */
+   hw_write_otgsc(ci, OTGSC_DPIS, OTGSC_DPIS);
+   /* Enable data pulse irq */
+   hw_write_otgsc(ci, OTGSC_DPIE, OTGSC_DPIE);
+   disable_irq_nosync(ci->irq);
+   queue_work(ci->wq, &ci->work);
+}
+
+static void b_ase0_brst_tmout_func(void *ptr, unsigned long indicator)
+{
+   struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
+
+   set_tmout(ci, indicator);
+   if (!hw_read_otgsc(ci, OTGSC_BSV))
+   ci->fsm.b_sess_vld = 0;
+
+   disable_irq_nosync(ci->irq);
+   queue_work(ci->wq, &ci->work);
+}
+
+static void b_ssend_srp_tmout_func(void *ptr, unsigned long indicator)
+{
+   struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
+
+   set_tmout(ci, indicator);
+
+   /* only vbus fall below B_sess_vld in b_idle state */
+   if (ci->transceiver->state == OTG_STATE_B_IDLE) {
+   disable_irq_nosync(ci->irq);
+   queue_work(ci->wq, &ci->work);
+   }
+}
+
+static void b_sess_vld_tmout_func(void *ptr, unsigned long indicator)
+{
+   struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
+
+   /* Check if A detached */
+   if (!(hw_read_otgsc(ci, OTGSC_BSV))) {
+   ci->fsm.b_sess_vld = 0;
+   ci_otg_add_timer(ci, B_SSEND_SRP);
+   disable_irq_nosync(ci->irq);
+   queue_work(ci->wq, &ci->work);
+   }
+}
+
+static void b_data_pulse_end(void *ptr, unsigned long indicator)
+{
+   struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
+
+   ci->fsm.b_srp_done = 1;
+   ci->fsm.b_bus_req = 0;
+   if (ci->fsm.power_up)
+   ci->fsm.power_up = 0;
+
+   hw_write_otgsc(ci, OTGSC_HABA, 0);
+
+   disable_irq_nosync(ci->irq);
+   queue_work(ci->wq, &ci->work);
+}
+
+/* Initialize timers */
+static int ci_otg_init_timers(struct ci_hdrc *ci)
+{
+   struct otg_fsm *fsm = &ci->fsm;
+
+   /* FSM used timers */
+   ci->fsm_timer->timer_list[A_WAIT_VRISE] =
+   otg_timer_initializer(ci, &set_tmout_and_fsm, TA_WAIT_VRISE,
+   (unsigned long)&fsm->a_wait_vrise_tmout);
+   if (ci->fsm_timer->timer_list[A_WAIT_VRISE] == NULL)
+   return -ENOMEM;
+
+   ci->fsm_timer->timer_list[A_WAIT_VFALL] =
+   otg_timer_initializer(ci, &a_wait_vfall_tmout_func,
+   TA_WAIT_VFALL, (unsigned long)&fsm->a_wait_vfall_tmout);
+   if (ci->fsm_timer->timer_list[A_WAIT_VFALL] == NULL)
+   return -ENOMEM;
+
+   ci->fsm_timer->timer_list[A_WAIT_BCON] =
+   otg_timer_initializer(ci, &set_tmout_and_f

[PATCH v7 11/11] Documentation: usb: add chipidea.txt for how to demo usb OTG HNP and SRP

2014-04-04 Thread Li Jun
From: Li Jun 

This patch adds a file chipidea.txt for how to demo chipidea usb OTG HNP and SRP
functions via sysfs input files, any other possible information should be
documented for chipidea usb driver in future can be added into this file.

Signed-off-by: Li Jun 
---
 Documentation/usb/chipidea.txt |   71 
 1 file changed, 71 insertions(+)

diff --git a/Documentation/usb/chipidea.txt b/Documentation/usb/chipidea.txt
new file mode 100644
index 000..4c0e2ea
--- /dev/null
+++ b/Documentation/usb/chipidea.txt
@@ -0,0 +1,71 @@
+1. How to test OTG FSM(HNP and SRP)
+---
+To show how to demo OTG HNP and SRP functions via sys input files
+with 2 Freescale i.MX6Q sabre SD boards.
+
+1.1 How to enable OTG FSM in menuconfig
+---
+Select CONFIG_USB_OTG_FSM.
+If you want to check some internal variables for otg fsm,
+select CONFIG_USB_CHIPIDEA_DEBUG, there are 2 files which
+can show otg fsm variables and some controller registers value:
+cat /sys/kernel/debug/ci_hdrc.0/otg
+cat /sys/kernel/debug/ci_hdrc.0/registers
+
+1.2 Test operations
+---
+1) Power up 2 Freescale i.MX6Q sabre SD boards with gadget class driver loaded
+   (e.g. g_mass_storage).
+
+2) Connect 2 boards with usb cable with one end is micro A plug, the other end
+   is micro B plug.
+
+   The A-device(with micro A plug inserted) should enumrate B-device.
+
+3) Role switch
+   On B-device:
+   echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req
+
+   if HNP polling is not supported, also need:
+   On A-device:
+   echo 0 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_req
+
+   B-device should take host role and enumrate A-device.
+
+4) A-device switch back to host.
+   On B-device:
+   echo 0 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req
+
+   A-device should switch back to host and enumrate B-device.
+
+5) Remove B-device(unplug micro B plug) and insert again in 10 seconds,
+   A-device should enumrate B-device again.
+
+6) Remove B-device(unplug micro B plug) and insert again after 10 seconds,
+   A-device should NOT enumrate B-device.
+
+   if A-device wants to use bus:
+   On A-device:
+   echo 0 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_drop
+   echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_req
+
+   if B-device wants to use bus:
+   On B-device:
+   echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req
+
+7) A-device power down the bus.
+   On A-device:
+   echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_drop
+
+   A-device should disconnect with B-device and power down the bus.
+
+8) B-device does data pulse for SRP.
+   On B-device:
+   echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req
+
+   A-device should resume usb bus and enumrate B-device.
+
+1.3 Reference document
+--
+"On-The-Go and Embedded Host Supplement to the USB Revision 2.0 Specification
+July 27, 2012 Revision 2.0 version 1.1a"
-- 
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 v7 00/11] Add USB OTG HNP and SRP support on Chipidea usb driver

2014-04-04 Thread Li Jun
From: Li Jun 

This patchset adds USB OTG HNP and SRP support on chipidea usb driver,
existing OTG port role swtich function by ID pin status kept unchanged,
based on that, if select CONFIG_USB_OTG_FSM, OTG HNP and SRP will be
supported.

Reference to:
"On-The-Go and Embedded Host Supplement to the USB Revision 2.0 Specification 
July 27, 2012
Revision 2.0 version 1.1a"

Changes since v6:
- Move ci_hdrc_otg_fsm_start() into ci_hdrc_otg_fsm_init()
- Call ci_hdrc_otg_fsm_init() in ci_hdrc_probe()
- Add fsm->protocol init in ci_hdrc_otg_fsm_init()
- Remove role check in start/stop host/gadget.
- Add ci_otg_is_fsm_mode() check when start fsm in ci_udc_start().
- Add struct usb_otg *otg in ci_hdrc_otg_fsm_init() for easy read when
  do init, set otg->host if host role start before otg fsm init(power up
  with ID is 0).
- set otg->host in host_start() if otg fsm init happens before host start
  (power up with ID is 1) in host.c
- Add comments of ci_hdrc structure for added fileds(fsm and fsm_timer)
  in ci.h

Changes since v5:
- Move ci_otg_is_fsm_mode() check into caller functions.
- Update comments alignment in otg_fsm.h
- Revert the ci_hdrc_otg_fsm_start() change to be v4
- Revert the role check removal of start host/gadget to be v4 since
  ci_start_role may be called out of otg fsm.
- Set controller to be device mode after stop host, to be able to
  generate data pulse correctly.
- Update some fsm variables to align with otg state.
- Update test documents for A device start new seesion in step 6):
  need set a_bus_drop to be 0 and set a_bus_req to be 1.
- Typo fix.

Changes since v4:
- Fix compile warnings if USB_OTG_FSM is not enabled.
- Add ci_otg_is_fsm_mode() to replace ci->is_otg for checking if ci is in
  OTG FSM mode.
- Move ci_hdrc_otg_fsm_start() at end of ci_hdrc_otg_fsm_init().
- Fix patch splict problem(a later patch changes a previous one).
- Remove unnecessary role check in start host/gadget.
- Add {} in start_host.c to fix Coding style problem and declar a variable
  equal to ci->transceiver->otg firstly when init otg port number.
- Update some driver comments of chipidea drivers if this patchset applied.

Changes since v3:
- Move out 2 patches from this patchset, as which are not directly related to
  otg fsm.
- Add a new file chipidea.txt under Documentation/usb/ to show how to test
  OTG HNP and SRP.
- Directly embed struct otg_fsm into ci_hdrc instead of pointer of otg_fsm.
- Remove flag check in ci_otg_del_timer().
- Remove ADP related code and comments since ADP is not supported by chip.
- Start OTG fsm before request_irq.
- For B-device, do not do OTG fsm transitions when gadget driver
  is not registered, and start OTG fsm in register gadget driver.
- Directly call ci_otg_fsm_work() in ci_hdrc_otg_fsm_start().
- Enable data pulse when a_wait_vfall timer time out.
- Update a_wait_vrise time out function.
- UPdate comments of OTG time macro definitions in otg_fsm.h according to
  OTG and EH 2.0.
- Some typo and comments format changes.

Changes since v2:
- Add ABI document for sysfs input files description:
  Documentation/ABI/testing/sysfs-platform-chipidea-usb-otg
- Add a debug file for show some USB registers value.
- Split host driver change to be 2 patches, one for otg_port number init;
  the other one for vbus control change.
- Export interrupt enable and status read functions from udc driver.
- Only enable AVV irq in otg fsm init.
- Remove duplicated USBSTS bits definitions.
- Add HowTo demo role switch with 2 Freescale i.MX6Q sabre SD boards
  in cover letter.
- typo correction.

Changes since v1:
- Move out HNP polling patch from this series, which will be a seperated 
patchset
  followed this one
- Change fsm timers global variables to be a structure embeded in ci_hdrc,
  to make multiple OTG instances can exist in one system
- Change some otg fsm functions to be static
- Re-split timer init patch to avoid a later patch changing a previous one
  in the same series
- Change timer structure memory allocation to be devm_kzalloc
- Update some format alignment and spelling errors

Li Jun (11):
  usb: chipidea: usb OTG fsm initialization.
  usb: chipidea: host: vbus control change for OTG HNP.
  usb: chipidea: host: init otg port number.
  usb: chipidea: udc: driver update for OTG HNP.
  usb: chipidea: add OTG fsm operation functions implemenation.
  usb: chipidea: OTG fsm timers initialization.
  usb: chipidea: OTG HNP and SRP fsm implementation.
  usb: chipidea: add sys inputs for OTG fsm input.
  usb: chipidea: debug: add debug file for OTG variables
  Documentation: ABI: usb: sysfs Description for chipidea USB OTG HNP
and SRP
  Documentation: usb: add chipidea.txt for how to demo usb OTG HNP and
SRP

 .../ABI/testing/sysfs-platform-chipidea-usb-otg|   56 ++
 Documentation/usb/chipidea.txt |   71 ++
 drivers/usb/chipidea/Makefile  |1 +
 drivers/usb/chipidea/bits.h|   10 +
 drivers/usb/chipidea/ci.h

[PATCH v7 09/11] usb: chipidea: debug: add debug file for OTG variables

2014-04-04 Thread Li Jun
From: Li Jun 

This patch adds a debug file for OTG vairables show.

Signed-off-by: Li Jun 
---
 drivers/usb/chipidea/debug.c |   84 ++
 1 file changed, 84 insertions(+)

diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c
index 5b890c1..7cccab6 100644
--- a/drivers/usb/chipidea/debug.c
+++ b/drivers/usb/chipidea/debug.c
@@ -7,6 +7,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include "ci.h"
 #include "udc.h"
@@ -205,6 +208,80 @@ static const struct file_operations ci_requests_fops = {
.release= single_release,
 };
 
+int ci_otg_show(struct seq_file *s, void *unused)
+{
+   struct ci_hdrc *ci = s->private;
+   struct otg_fsm *fsm;
+
+   if (!ci || !ci_otg_is_fsm_mode(ci))
+   return 0;
+
+   fsm = &ci->fsm;
+
+   /* -- State - */
+   seq_printf(s, "OTG state: %s\n\n",
+   usb_otg_state_string(ci->transceiver->state));
+
+   /* -- State Machine Variables - */
+   seq_printf(s, "a_bus_drop: %d\n", fsm->a_bus_drop);
+
+   seq_printf(s, "a_bus_req: %d\n", fsm->a_bus_req);
+
+   seq_printf(s, "a_srp_det: %d\n", fsm->a_srp_det);
+
+   seq_printf(s, "a_vbus_vld: %d\n", fsm->a_vbus_vld);
+
+   seq_printf(s, "b_conn: %d\n", fsm->b_conn);
+
+   seq_printf(s, "adp_change: %d\n", fsm->adp_change);
+
+   seq_printf(s, "power_up: %d\n", fsm->power_up);
+
+   seq_printf(s, "a_bus_resume: %d\n", fsm->a_bus_resume);
+
+   seq_printf(s, "a_bus_suspend: %d\n", fsm->a_bus_suspend);
+
+   seq_printf(s, "a_conn: %d\n", fsm->a_conn);
+
+   seq_printf(s, "b_bus_req: %d\n", fsm->b_bus_req);
+
+   seq_printf(s, "b_bus_suspend: %d\n", fsm->b_bus_suspend);
+
+   seq_printf(s, "b_se0_srp: %d\n", fsm->b_se0_srp);
+
+   seq_printf(s, "b_ssend_srp: %d\n", fsm->b_ssend_srp);
+
+   seq_printf(s, "b_sess_vld: %d\n", fsm->b_sess_vld);
+
+   seq_printf(s, "b_srp_done: %d\n", fsm->b_srp_done);
+
+   seq_printf(s, "drv_vbus: %d\n", fsm->drv_vbus);
+
+   seq_printf(s, "loc_conn: %d\n", fsm->loc_conn);
+
+   seq_printf(s, "loc_sof: %d\n", fsm->loc_sof);
+
+   seq_printf(s, "adp_prb: %d\n", fsm->adp_prb);
+
+   seq_printf(s, "id: %d\n", fsm->id);
+
+   seq_printf(s, "protocol: %d\n", fsm->protocol);
+
+   return 0;
+}
+
+static int ci_otg_open(struct inode *inode, struct file *file)
+{
+   return single_open(file, ci_otg_show, inode->i_private);
+}
+
+static const struct file_operations ci_otg_fops = {
+   .open   = ci_otg_open,
+   .read   = seq_read,
+   .llseek = seq_lseek,
+   .release= single_release,
+};
+
 static int ci_role_show(struct seq_file *s, void *data)
 {
struct ci_hdrc *ci = s->private;
@@ -332,6 +409,13 @@ int dbg_create_files(struct ci_hdrc *ci)
if (!dent)
goto err;
 
+   if (ci_otg_is_fsm_mode(ci)) {
+   dent = debugfs_create_file("otg", S_IRUGO, ci->debugfs, ci,
+   &ci_otg_fops);
+   if (!dent)
+   goto err;
+   }
+
dent = debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci,
   &ci_role_fops);
if (!dent)
-- 
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 v7 08/11] usb: chipidea: add sys inputs for OTG fsm input.

2014-04-04 Thread Li Jun
From: Li Jun 

This patch adds sys input to control and show OTG fsm inputs by application,
user can do host and preipheral role switch by change these inputs.

Signed-off-by: Li Jun 
---
 drivers/usb/chipidea/otg.c |2 +
 drivers/usb/chipidea/otg_fsm.c |  173 
 drivers/usb/chipidea/otg_fsm.h |6 ++
 3 files changed, 181 insertions(+)

diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
index dbf47e8..dc1d3a7 100644
--- a/drivers/usb/chipidea/otg.c
+++ b/drivers/usb/chipidea/otg.c
@@ -138,4 +138,6 @@ void ci_hdrc_otg_destroy(struct ci_hdrc *ci)
/* Disable all OTG irq and clear status */
hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS,
OTGSC_INT_STATUS_BITS);
+   if (ci_otg_is_fsm_mode(ci))
+   ci_hdrc_otg_fsm_remove(ci);
 }
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
index bbe3ffb..7bc2ecc 100644
--- a/drivers/usb/chipidea/otg_fsm.c
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -46,6 +46,167 @@ static struct ci_otg_fsm_timer *otg_timer_initializer
return timer;
 }
 
+/* Add for otg: interact with user space app */
+static ssize_t
+get_a_bus_req(struct device *dev, struct device_attribute *attr, char *buf)
+{
+   char*next;
+   unsignedsize, t;
+   struct ci_hdrc  *ci = dev_get_drvdata(dev);
+
+   next = buf;
+   size = PAGE_SIZE;
+   t = scnprintf(next, size, "%d\n", ci->fsm.a_bus_req);
+   size -= t;
+   next += t;
+
+   return PAGE_SIZE - size;
+}
+
+static ssize_t
+set_a_bus_req(struct device *dev, struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct ci_hdrc *ci = dev_get_drvdata(dev);
+
+   if (count > 2)
+   return -1;
+
+   mutex_lock(&ci->fsm.lock);
+   if (buf[0] == '0') {
+   ci->fsm.a_bus_req = 0;
+   } else if (buf[0] == '1') {
+   /* If a_bus_drop is TRUE, a_bus_req can't be set */
+   if (ci->fsm.a_bus_drop) {
+   mutex_unlock(&ci->fsm.lock);
+   return count;
+   }
+   ci->fsm.a_bus_req = 1;
+   }
+
+   disable_irq_nosync(ci->irq);
+   queue_work(ci->wq, &ci->work);
+   mutex_unlock(&ci->fsm.lock);
+
+   return count;
+}
+static DEVICE_ATTR(a_bus_req, S_IRUGO | S_IWUSR, get_a_bus_req, set_a_bus_req);
+
+static ssize_t
+get_a_bus_drop(struct device *dev, struct device_attribute *attr, char *buf)
+{
+   char*next;
+   unsignedsize, t;
+   struct ci_hdrc  *ci = dev_get_drvdata(dev);
+
+   next = buf;
+   size = PAGE_SIZE;
+   t = scnprintf(next, size, "%d\n", ci->fsm.a_bus_drop);
+   size -= t;
+   next += t;
+
+   return PAGE_SIZE - size;
+}
+
+static ssize_t
+set_a_bus_drop(struct device *dev, struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct ci_hdrc  *ci = dev_get_drvdata(dev);
+
+   if (count > 2)
+   return -1;
+
+   mutex_lock(&ci->fsm.lock);
+   if (buf[0] == '0') {
+   ci->fsm.a_bus_drop = 0;
+   } else if (buf[0] == '1') {
+   ci->fsm.a_bus_drop = 1;
+   ci->fsm.a_bus_req = 0;
+   }
+
+   disable_irq_nosync(ci->irq);
+   queue_work(ci->wq, &ci->work);
+   mutex_unlock(&ci->fsm.lock);
+
+   return count;
+}
+static DEVICE_ATTR(a_bus_drop, S_IRUGO | S_IWUSR, get_a_bus_drop,
+   set_a_bus_drop);
+
+static ssize_t
+get_b_bus_req(struct device *dev, struct device_attribute *attr, char *buf)
+{
+   char*next;
+   unsignedsize, t;
+   struct ci_hdrc  *ci = dev_get_drvdata(dev);
+
+   next = buf;
+   size = PAGE_SIZE;
+   t = scnprintf(next, size, "%d\n", ci->fsm.b_bus_req);
+   size -= t;
+   next += t;
+
+   return PAGE_SIZE - size;
+}
+
+static ssize_t
+set_b_bus_req(struct device *dev, struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct ci_hdrc  *ci = dev_get_drvdata(dev);
+
+   if (count > 2)
+   return -1;
+
+   mutex_lock(&ci->fsm.lock);
+   if (buf[0] == '0')
+   ci->fsm.b_bus_req = 0;
+   else if (buf[0] == '1')
+   ci->fsm.b_bus_req = 1;
+
+   disable_irq_nosync(ci->irq);
+   queue_work(ci->wq, &ci->work);
+   mutex_unlock(&ci->fsm.lock);
+
+   return count;
+}
+static DEVICE_ATTR(b_bus_req, S_IRUGO | S_IWUSR, get_b_bus_req, set_b_bus_req);
+
+static ssize_t
+set_a_clr_err(struct device *dev, struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct ci_hdrc  *ci = dev_get_drvdata(dev);
+
+   if (count > 2)
+   ret

[PATCH v7 10/11] Documentation: ABI: usb: sysfs Description for chipidea USB OTG HNP and SRP

2014-04-04 Thread Li Jun
From: Li Jun 

This patch adds sysfs interface description for chipidea USB OTG HNP and SRP.

Signed-off-by: Li Jun 
---
 .../ABI/testing/sysfs-platform-chipidea-usb-otg|   56 
 1 file changed, 56 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-platform-chipidea-usb-otg 
b/Documentation/ABI/testing/sysfs-platform-chipidea-usb-otg
new file mode 100644
index 000..151c595
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-chipidea-usb-otg
@@ -0,0 +1,56 @@
+What:  /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_req
+Date:  Feb 2014
+Contact:   Li Jun 
+Description:
+   Can be set and read.
+   Set a_bus_req(A-device bus request) input to be 1 if
+   the application running on the A-device wants to use the bus,
+   and to be 0 when the application no longer wants to use
+   the bus(or wants to work as peripheral). a_bus_req can also
+   be set to 1 by kernel in response to remote wakeup signaling
+   from the B-device, the A-device should decide to resume the bus.
+
+   Valid values are "1" and "0".
+
+   Reading: returns 1 if the application running on the A-device
+   is using the bus as host role, otherwise 0.
+
+What:  /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_drop
+Date:  Feb 2014
+Contact:   Li Jun 
+Description:
+   Can be set and read
+   The a_bus_drop(A-device bus drop) input is 1 when the
+   application running on the A-device wants to power down
+   the bus, and is 0 otherwise, When a_bus_drop is 1, then
+   the a_bus_req shall be 0.
+
+   Valid values are "1" and "0".
+
+   Reading: returns 1 if the bus is off(vbus is turned off) by
+A-device, otherwise 0.
+
+What:  /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req
+Date:  Feb 2014
+Contact:   Li Jun 
+Description:
+   Can be set and read.
+   The b_bus_req(B-device bus request) input is 1 during the time
+   that the application running on the B-device wants to use the
+   bus as host, and is 0 when the application no longer wants to
+   work as host and decides to switch back to be peripheral.
+
+   Valid values are "1" and "0".
+
+   Reading: returns if the application running on the B device
+   is using the bus as host role, otherwise 0.
+
+What:  /sys/bus/platform/devices/ci_hdrc.0/inputs/a_clr_err
+Date:  Feb 2014
+Contact:   Li Jun 
+Description:
+   Only can be set.
+   The a_clr_err(A-device Vbus error clear) input is used to clear
+   vbus error, then A-device will power down the bus.
+
+   Valid value is "1"
-- 
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 v7 01/11] usb: chipidea: usb OTG fsm initialization.

2014-04-04 Thread Li Jun
This patch adds OTG fsm related initialization when do otg init,
add a seperate file for OTG fsm related utilities.

Signed-off-by: Li Jun 
---
 drivers/usb/chipidea/Makefile  |1 +
 drivers/usb/chipidea/ci.h  |   17 ++
 drivers/usb/chipidea/otg.c |1 +
 drivers/usb/chipidea/otg_fsm.c |   68 
 drivers/usb/chipidea/otg_fsm.h |   29 +
 5 files changed, 116 insertions(+)

diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index 480bd4d..2f099c7 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -6,6 +6,7 @@ ci_hdrc-y   := core.o otg.o
 ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC) += udc.o
 ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST)+= host.o
 ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG)   += debug.o
+ci_hdrc-$(CONFIG_USB_OTG_FSM)  += otg_fsm.o
 
 # Glue/Bridge layers go here
 
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index 7ae8cb6..bd3529f 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * DEFINE
@@ -139,6 +140,7 @@ struct hw_bank {
  * @roles: array of supported roles for this controller
  * @role: current role
  * @is_otg: if the device is otg-capable
+ * @fsm: otg finite state machine
  * @work: work for role changing
  * @wq: workqueue thread
  * @qh_pool: allocation pool for queue heads
@@ -174,6 +176,7 @@ struct ci_hdrc {
struct ci_role_driver   *roles[CI_ROLE_END];
enum ci_rolerole;
boolis_otg;
+   struct otg_fsm  fsm;
struct work_struct  work;
struct workqueue_struct *wq;
 
@@ -319,6 +322,20 @@ static inline u32 hw_test_and_write(struct ci_hdrc *ci, 
enum ci_hw_regs reg,
return (val & mask) >> __ffs(mask);
 }
 
+/**
+ * ci_otg_is_fsm_mode: runtime check if otg controller
+ * is in otg fsm mode.
+ */
+static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci)
+{
+#ifdef CONFIG_USB_OTG_FSM
+   return ci->is_otg && ci->roles[CI_ROLE_HOST] &&
+   ci->roles[CI_ROLE_GADGET];
+#else
+   return false;
+#endif
+}
+
 u32 hw_read_intr_enable(struct ci_hdrc *ci);
 
 u32 hw_read_intr_status(struct ci_hdrc *ci);
diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
index c694340..f978fa9 100644
--- a/drivers/usb/chipidea/otg.c
+++ b/drivers/usb/chipidea/otg.c
@@ -22,6 +22,7 @@
 #include "ci.h"
 #include "bits.h"
 #include "otg.h"
+#include "otg_fsm.h"
 
 /**
  * hw_read_otgsc returns otgsc register bits value.
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
new file mode 100644
index 000..eddfe53
--- /dev/null
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -0,0 +1,68 @@
+/*
+ * otg_fsm.c - ChipIdea USB IP core OTG FSM driver
+ *
+ * Copyright (C) 2014 Freescale Semiconductor, Inc.
+ *
+ * Author: Jun Li
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+/*
+ * This file mainly handles OTG fsm, it includes OTG fsm operations
+ * for HNP and SRP.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "ci.h"
+#include "bits.h"
+#include "otg.h"
+#include "otg_fsm.h"
+
+int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci)
+{
+   struct usb_otg *otg;
+
+   otg = devm_kzalloc(ci->dev,
+   sizeof(struct usb_otg), GFP_KERNEL);
+   if (!otg) {
+   dev_err(ci->dev,
+   "Failed to allocate usb_otg structure for ci hdrc otg!\n");
+   return -ENOMEM;
+   }
+
+   otg->phy = ci->transceiver;
+   otg->gadget = &ci->gadget;
+   if (ci->hcd)
+   otg->host = &ci->hcd->self;
+   ci->fsm.otg = otg;
+   ci->transceiver->otg = ci->fsm.otg;
+   ci->fsm.power_up = 1;
+   ci->fsm.id = hw_read_otgsc(ci, OTGSC_ID) ? 1 : 0;
+   ci->transceiver->state = OTG_STATE_UNDEFINED;
+
+   mutex_init(&ci->fsm.lock);
+
+   /* Enable A vbus valid irq */
+   hw_write_otgsc(ci, OTGSC_AVVIE, OTGSC_AVVIE);
+
+   if (ci->fsm.id) {
+   ci->fsm.b_ssend_srp =
+   hw_read_otgsc(ci, OTGSC_BSV) ? 0 : 1;
+   ci->fsm.b_sess_vld =
+   hw_read_otgsc(ci, OTGSC_BSV) ? 1 : 0;
+   }
+
+   if (ci->role == CI_ROLE_HOST)
+   ci->fsm.protocol = PROTO_HOST;
+   else if (ci->role == CI_ROLE_GADGET)
+   ci->fsm.protocol = PROTO_GADGET;
+
+   return 0;
+}
diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h
new file mode 100644
index 000..bf20a85
--- /dev/null
+++ b/drivers/usb/chipidea/otg_fsm.h
@@ -0,0 +1,29 @@