Re: [PATCH 0/4] usb: chipidea: imx: add HSIC support

2018-10-17 Thread Frieder Schrempf

Hi Peter,

On 16.10.18 07:01, Peter Chen wrote:

Most of NXP (Freescale) i.mx USB part has HSIC support, in this series,
we add support for them, it should cover all imx6 and imx7d. I have
no HSIC interface board which is supported by upstream kernel, so this
patches are only compiled ok, Frieder Schrempf, would you please
help me test it on your board? Thanks.


Thank you for providing the patch!
I applied it to v4.19-rc8 and tested and the LAN9730 comes up and works 
just fine.


Here is how my devicetree looks like:

usbphy_dummy: usbphy_dummy@1 {
compatible = "usb-nop-xceiv";
};

[...]

&usbh2 {
vbus-supply = <®_usb_h2_vbus>;
pinctrl-names = "idle", "active";
pinctrl-0 = <&pinctrl_usbh2_idle>;
pinctrl-1 = <&pinctrl_usbh2_active>;
fsl,usbphy = <&usbphy_dummy>;
phy_type = "hsic";
status = "okay";
#address-cells = <1>;
#size-cells = <0>;

usbnet: smsc@1 {
compatible = "usb424,9730";
/* Filled in by U-Boot */
mac-address = [00 00 00 00 00 00];
reg = <1>;
};
};

[...]

pinctrl_usbh2_idle: usbh2grp-idle {
  fsl,pins = <
MX6QDL_PAD_RGMII_TXC__USB_H2_DATA   0x40013030
MX6QDL_PAD_RGMII_TX_CTL__USB_H2_STROBE  0x40013030
  >;
};

pinctrl_usbh2_active: usbh2grp-active {
  fsl,pins = <
MX6QDL_PAD_RGMII_TXC__USB_H2_DATA   0x40013030
MX6QDL_PAD_RGMII_TX_CTL__USB_H2_STROBE  0x40017030
  >;
};


Are there any test cases I should try?
How can I test suspend/resume?

I also have some suggestions for your patch. Please see the separate email.

Thanks,
Frieder



Peter Chen (4):
   usb: chipidea: add flag for imx hsic implementation
   usb: chipidea: imx: add HSIC support
   usb: chipidea: host: override ehci->hub_control
   doc: usb: ci-hdrc-usb2: Add pinctrl properties for HSIC pin groups

  .../devicetree/bindings/usb/ci-hdrc-usb2.txt   |   1 +
  drivers/usb/chipidea/ci_hdrc_imx.c | 153 ++---
  drivers/usb/chipidea/ci_hdrc_imx.h |   9 +-
  drivers/usb/chipidea/host.c|  98 +
  drivers/usb/chipidea/usbmisc_imx.c | 131 ++
  include/linux/usb/chipidea.h   |   3 +
  6 files changed, 376 insertions(+), 19 deletions(-)



Re: [PATCH 2/4] usb: chipidea: imx: add HSIC support

2018-10-17 Thread Frieder Schrempf

Hi Peter,

please see my comments below. For reference I also pushed the changes 
here: https://github.com/fschrempf/linux/commits/usb-hsic-test


On 16.10.18 07:01, Peter Chen wrote:

To support imx HSIC, there are some special requirement:
- The HSIC pad is 1.2v, it may need to supply from external
- The data/strobe pin needs to be pulled down first, and after
   host mode is initialized, the strobe pin needs to be pulled up
- During the USB suspend/resume, special setting is needed

Signed-off-by: Peter Chen 
---
  drivers/usb/chipidea/ci_hdrc_imx.c | 153 +
  drivers/usb/chipidea/ci_hdrc_imx.h |   9 ++-
  drivers/usb/chipidea/usbmisc_imx.c | 131 +++
  3 files changed, 274 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
b/drivers/usb/chipidea/ci_hdrc_imx.c
index 09b37c0d075d..d566771fc77a 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -85,6 +85,9 @@ struct ci_hdrc_imx_data {
bool supports_runtime_pm;
bool override_phy_control;
bool in_lpm;
+   struct pinctrl *pinctrl;
+   struct pinctrl_state *pinctrl_hsic_active;
+   struct regulator *hsic_pad_regulator;
/* SoC before i.mx6 (except imx23/imx28) needs three clks */
bool need_three_clks;
struct clk *clk_ipg;
@@ -245,19 +248,58 @@ static void imx_disable_unprepare_clks(struct device *dev)
}
  }
  
+static int ci_hdrc_imx_notify_event(struct ci_hdrc *ci, unsigned int event)

+{
+   struct device *dev = ci->dev->parent;
+   struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
+   int ret = 0;
+
+   switch (event) {
+   case CI_HDRC_IMX_HSIC_ACTIVE_EVENT:
+   if (!IS_ERR(data->pinctrl) &&
+   !IS_ERR(data->pinctrl_hsic_active)) {


If we make the pinctrl mandatory in case of HSIC as proposed below, we 
don't need the checks here.



+   ret = pinctrl_select_state(data->pinctrl,
+   data->pinctrl_hsic_active);
+   if (ret)
+   dev_err(dev,
+   "hsic_active select failed, err=%d\n",
+   ret);
+   return ret;
+   }
+   break;
+   case CI_HDRC_IMX_HSIC_SUSPEND_EVENT:
+   if (data->usbmisc_data) {
+   ret = imx_usbmisc_hsic_set_connect(data->usbmisc_data);
+   if (ret)
+   dev_err(dev,
+   "hsic_set_connect failed, err=%d\n",
+   ret);
+   return ret;
+   }
+   break;
+   default:
+   break;
+   }
+
+   return ret;
+}
+
  static int ci_hdrc_imx_probe(struct platform_device *pdev)
  {
struct ci_hdrc_imx_data *data;
struct ci_hdrc_platform_data pdata = {
.name   = dev_name(&pdev->dev),
.capoffset  = DEF_CAPOFFSET,
+   .notify_event   = ci_hdrc_imx_notify_event,
};
int ret;
const struct of_device_id *of_id;
const struct ci_hdrc_imx_platform_flag *imx_platform_flag;
struct device_node *np = pdev->dev.of_node;
+   struct device *dev = &pdev->dev;
+   struct pinctrl_state *pinctrl_hsic_idle;
  
-	of_id = of_match_device(ci_hdrc_imx_dt_ids, &pdev->dev);

+   of_id = of_match_device(ci_hdrc_imx_dt_ids, dev);
if (!of_id)
return -ENODEV;
  
@@ -268,19 +310,48 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)

return -ENOMEM;
  
  	platform_set_drvdata(pdev, data);

-   data->usbmisc_data = usbmisc_get_init_data(&pdev->dev);
+   data->usbmisc_data = usbmisc_get_init_data(dev);
if (IS_ERR(data->usbmisc_data))
return PTR_ERR(data->usbmisc_data);
  
-	ret = imx_get_clks(&pdev->dev);

+   data->pinctrl = devm_pinctrl_get(dev);
+   if (IS_ERR(data->pinctrl)) {
+   dev_dbg(dev, "pinctrl get failed, err=%ld\n",
+   PTR_ERR(data->pinctrl));
+   } else {
+   pinctrl_hsic_idle = pinctrl_lookup_state(data->pinctrl, "idle");
+   if (IS_ERR(pinctrl_hsic_idle)) {
+   dev_dbg(dev,
+   "pinctrl_hsic_idle lookup failed, err=%ld\n",
+   PTR_ERR(pinctrl_hsic_idle));
+   } else {
+   ret = pinctrl_select_state(data->pinctrl,
+   pinctrl_hsic_idle);
+   if (ret) {
+   dev_err(dev,
+   "hsic_idle select failed, err=%d\n",
+  

RE: [PATCH 0/4] usb: chipidea: imx: add HSIC support

2018-10-17 Thread Peter Chen
 
> On 16.10.18 07:01, Peter Chen wrote:
> > Most of NXP (Freescale) i.mx USB part has HSIC support, in this
> > series, we add support for them, it should cover all imx6 and imx7d. I
> > have no HSIC interface board which is supported by upstream kernel, so
> > this patches are only compiled ok, Frieder Schrempf, would you please
> > help me test it on your board? Thanks.
> 
> Thank you for providing the patch!
> I applied it to v4.19-rc8 and tested and the LAN9730 comes up and works just 
> fine.
> 
> Here is how my devicetree looks like:
> 
> usbphy_dummy: usbphy_dummy@1 {
>   compatible = "usb-nop-xceiv";
> };
> 
> [...]
> 
> &usbh2 {
>   vbus-supply = <®_usb_h2_vbus>;
>   pinctrl-names = "idle", "active";
>   pinctrl-0 = <&pinctrl_usbh2_idle>;
>   pinctrl-1 = <&pinctrl_usbh2_active>;
>   fsl,usbphy = <&usbphy_dummy>;
>   phy_type = "hsic";
>   status = "okay";
>   #address-cells = <1>;
>   #size-cells = <0>;
> 
>   usbnet: smsc@1 {
>   compatible = "usb424,9730";
>   /* Filled in by U-Boot */
>   mac-address = [00 00 00 00 00 00];
>   reg = <1>;
>   };
> };
> 
> [...]
> 
> pinctrl_usbh2_idle: usbh2grp-idle {
>fsl,pins = <
>  MX6QDL_PAD_RGMII_TXC__USB_H2_DATA   0x40013030
>  MX6QDL_PAD_RGMII_TX_CTL__USB_H2_STROBE  0x40013030
>>;
> };
> 
> pinctrl_usbh2_active: usbh2grp-active {
>fsl,pins = <
>  MX6QDL_PAD_RGMII_TXC__USB_H2_DATA   0x40013030
>  MX6QDL_PAD_RGMII_TX_CTL__USB_H2_STROBE  0x40017030
>>;
> };
> 
> 
> Are there any test cases I should try?
> How can I test suspend/resume?
> 

- System suspend/resume
1. Enable USB wakeup
for i in $(find /sys -name wakeup | grep usb);do echo enabled  > $i;echo "echo 
enabled > $i";done;
2. Let the system enter suspend using below command 
echo mem > /sys/power/state
3. And see if there is a wakeup block system entering suspend, and check if USB 
HSIC works ok
after system resume

- Runtime suspend
1. Enable auto suspend for all USB devices, and check if USBOH3 clock is closed,
make sure do not plug any ethernet cable on the RJ45 port.

/* Enable auto suspend */
for i in $(find /sys -name control | grep usb);do echo auto  > $i;echo "echo 
auto > $i";done;

/* Scripts to see USB clock */
root@imx8qxpmek:~# cat uclk.sh 
/home/root/dump-clocks.sh | grep usb
root@imx8qxpmek:~# cat /home/root/dump-clocks.sh 
#!/bin/bash

if ! mount|grep -sq '/sys/kernel/debug'; then
mount -t debugfs none /sys/kernel/debug
fi

cat /sys/kernel/debug/clk/clk_summary

2. If USB OH3 clock can close successfully, it means USB HSIC can enter suspend 
successfully.

3. Plug ethernet cable to see if the link can be on.

The purpose of above two tests is to see if USB HSIC can be suspended.

Thanks.

Peter


> I also have some suggestions for your patch. Please see the separate email.
> 
> Thanks,
> Frieder
> 
> >
> > Peter Chen (4):
> >usb: chipidea: add flag for imx hsic implementation
> >usb: chipidea: imx: add HSIC support
> >usb: chipidea: host: override ehci->hub_control
> >doc: usb: ci-hdrc-usb2: Add pinctrl properties for HSIC pin groups
> >
> >   .../devicetree/bindings/usb/ci-hdrc-usb2.txt   |   1 +
> >   drivers/usb/chipidea/ci_hdrc_imx.c | 153 
> > ++---
> >   drivers/usb/chipidea/ci_hdrc_imx.h |   9 +-
> >   drivers/usb/chipidea/host.c|  98 +
> >   drivers/usb/chipidea/usbmisc_imx.c | 131 
> > ++
> >   include/linux/usb/chipidea.h   |   3 +
> >   6 files changed, 376 insertions(+), 19 deletions(-)
> >


Re: [PATCH 0/4] usb: chipidea: imx: add HSIC support

2018-10-17 Thread Frieder Schrempf

Hi Peter,

On 17.10.18 09:23, Peter Chen wrote:
  

On 16.10.18 07:01, Peter Chen wrote:

Most of NXP (Freescale) i.mx USB part has HSIC support, in this
series, we add support for them, it should cover all imx6 and imx7d. I
have no HSIC interface board which is supported by upstream kernel, so
this patches are only compiled ok, Frieder Schrempf, would you please
help me test it on your board? Thanks.


Thank you for providing the patch!
I applied it to v4.19-rc8 and tested and the LAN9730 comes up and works just 
fine.

Here is how my devicetree looks like:

usbphy_dummy: usbphy_dummy@1 {
compatible = "usb-nop-xceiv";
};

[...]

&usbh2 {
vbus-supply = <®_usb_h2_vbus>;
pinctrl-names = "idle", "active";
pinctrl-0 = <&pinctrl_usbh2_idle>;
pinctrl-1 = <&pinctrl_usbh2_active>;
fsl,usbphy = <&usbphy_dummy>;
phy_type = "hsic";
status = "okay";
#address-cells = <1>;
#size-cells = <0>;

usbnet: smsc@1 {
compatible = "usb424,9730";
/* Filled in by U-Boot */
mac-address = [00 00 00 00 00 00];
reg = <1>;
};
};

[...]

pinctrl_usbh2_idle: usbh2grp-idle {
fsl,pins = <
  MX6QDL_PAD_RGMII_TXC__USB_H2_DATA   0x40013030
  MX6QDL_PAD_RGMII_TX_CTL__USB_H2_STROBE  0x40013030
>;
};

pinctrl_usbh2_active: usbh2grp-active {
fsl,pins = <
  MX6QDL_PAD_RGMII_TXC__USB_H2_DATA   0x40013030
  MX6QDL_PAD_RGMII_TX_CTL__USB_H2_STROBE  0x40017030
>;
};


Are there any test cases I should try?
How can I test suspend/resume?



- System suspend/resume
1. Enable USB wakeup
for i in $(find /sys -name wakeup | grep usb);do echo enabled  > $i;echo "echo enabled 
> $i";done;
2. Let the system enter suspend using below command
echo mem > /sys/power/state
3. And see if there is a wakeup block system entering suspend, and check if USB 
HSIC works ok
after system resume


System suspend/resume seems to work fine. After resume the ethernet 
controller works.


root@imxceet-solo-s-43:~# echo mem > /sys/power/state
PM: suspend entry (deep)
PM: Syncing filesystems ... done.
Freezing user space processes ... (elapsed 0.001 seconds) done.
OOM killer disabled.
Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
smsc95xx 3-1:1.0 eth1: entering SUSPEND2 mode
PM: suspend devices took 0.050 seconds
Disabling non-boot CPUs ...
usb 3-1: reset high-speed USB device number 2 using ci_hdrc
PM: resume devices took 0.590 seconds
OOM killer enabled.
Restarting tasks ... done.
PM: suspend exit
smsc95xx 3-1:1.0 eth1: link up, 100Mbps, full-duplex, lpa 0x4DE1
fec 2188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx



- Runtime suspend
1. Enable auto suspend for all USB devices, and check if USBOH3 clock is closed,
make sure do not plug any ethernet cable on the RJ45 port.

/* Enable auto suspend */
for i in $(find /sys -name control | grep usb);do echo auto  > $i;echo "echo auto > 
$i";done;


This doesn't work. When the port is suspended it gets into a loop of 
suspending/resuming endlessly. If i put two logs in 
ci_hdrc_imx_runtime_suspend() and ci_hdrc_imx_runtime_resume(), I get this:


[...]
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
[...]

Any ideas how to debug?

Thanks,
Frieder



/* Scripts to see USB clock */
root@imx8qxpmek:~# cat uclk.sh
/home/root/dump-clocks.sh | grep usb
root@imx8qxpmek:~# cat /home/root/dump-clocks.sh
#!/bin/bash

if ! mount|grep -sq '/sys/kernel/debug'; then
 mount -t debugfs none /sys/kernel/debug
fi

cat /sys/kernel/debug/clk/clk_summary

2. If USB OH3 clock can close successfully, it means USB HSIC can enter suspend 
successfully.

3. Plug ethernet cable to see if the link can be on.

The purpose of above two tests is to see if USB HSIC can be suspended.

Thanks.

Peter



I also have some suggestions for your patch. Please see the separate email.

Thanks,
Frieder



Peter Chen (4):
usb: chipidea: add flag for imx hsic implementation
usb: chipidea: imx: add HSIC support
usb: chipidea: host: override ehci->hub_control
doc: usb: ci-hdrc-usb2: Add pinctrl properties for HSIC pin groups

   .../devicetree/bindings/usb/ci-hdrc-usb2.txt   |   1 +
   drivers/usb/chipidea/ci_hdrc_imx.c | 153 
++---
   drivers/usb/chipidea/ci_hdrc_imx.h |   9 +-
   drivers/usb/chipidea/host.c|  98 +
   drivers/usb/chipidea/usbmisc_imx.c | 131 ++
   include/linux/usb/chipidea.h   |   3 +
   6 files changed, 376 insertions(+), 19 deletions(-)



Re: Query on usb/core/devio.c

2018-10-17 Thread Oliver Neukum
On Di, 2018-10-16 at 10:46 -0400, Alan Stern wrote:
> On Tue, 16 Oct 2018, Mayuresh Kulkarni wrote:
> 
> > 1. User space decides when it is time to suspend the device and calls
> > this ioctl. The implmentation takes care to ensure, no URB is in
> > flight from this caller to this device. Then proceed with suspend.
> 
> Well, I did not imagine the ioctl would try to ensure that no URBs are 
> in flight.  The user would be responsible for that.

Well, we have to check for URBs in flight. In fact we would have to
"plug" the device against new URBs. Now, we could use a new counter.
But if we check asynclist, we may just as well walk it and kill the
URBs. It just seems a bit silly not to do that.

> Also, proceeding with the suspend is difficult, as Oliver has pointed 
> out.  There is no guarantee that the device will go into suspend, 
> merely because the userspace driver isn't accessing it.  (In fact, 
> there's no guarantee that the device will _ever_ go into suspend.)  The 
> ioctl would probably have to include some sort of timeout; it would 
> return early if the timeout expired before the device was suspended.

Exactly. The alternative is to have an ioctl() to just allow or block
suspend, more or less just exporting autopm_get/put(). The disadvantage
is that

1. The kernel has to cancel URBs in flight
2. There needs to be a mechanism to notify user space about events

> > 2. In an another thread, the user-space calls poll(USB-device-fd).
> > When poll() returns, that means the device is active now. User space
> > can then request an URB to read out the async notification, if any.
> 
> No; no other thread or polling is needed.  The ioctl call returns when
> the device resumes.  At that point the user program can check whether
> there is an async notification pending.

This is problematic. For example, what do we do if a signal needs
to be delivered? The obvious solution of just repeating the call will
not work. It races with wakeup. You'd need to restart IO to query
the device. But the device may be suspended. Or do you want a signal
to up the PM counter again? Making Ctrl-C wake up an unrelated device?

What do we do in case of a failed suspend or resume?
How about reset_resume?

> > If this is correct interpretation, what will happen when USB device
> > sends remote-wake to host, but the reason is not async notification
> > but something other than that (e.g.: something standard UAC or HID)?
> 
> The reason for the wakeup won't make any difference; the behavior would 
> be the same regardless.

Exactly. Anything else is a race that can drop events.

Regards
Oliver




Re: [PATCH 0/4] usb: chipidea: imx: add HSIC support

2018-10-17 Thread Frieder Schrempf

On 17.10.18 11:56, Frieder Schrempf wrote:

Hi Peter,

On 17.10.18 09:23, Peter Chen wrote:

On 16.10.18 07:01, Peter Chen wrote:

Most of NXP (Freescale) i.mx USB part has HSIC support, in this
series, we add support for them, it should cover all imx6 and imx7d. I
have no HSIC interface board which is supported by upstream kernel, so
this patches are only compiled ok, Frieder Schrempf, would you please
help me test it on your board? Thanks.


Thank you for providing the patch!
I applied it to v4.19-rc8 and tested and the LAN9730 comes up and 
works just fine.


Here is how my devicetree looks like:

usbphy_dummy: usbphy_dummy@1 {
compatible = "usb-nop-xceiv";
};

[...]

&usbh2 {
vbus-supply = <®_usb_h2_vbus>;
pinctrl-names = "idle", "active";
pinctrl-0 = <&pinctrl_usbh2_idle>;
pinctrl-1 = <&pinctrl_usbh2_active>;
fsl,usbphy = <&usbphy_dummy>;
phy_type = "hsic";
status = "okay";
#address-cells = <1>;
#size-cells = <0>;

usbnet: smsc@1 {
    compatible = "usb424,9730";
    /* Filled in by U-Boot */
    mac-address = [00 00 00 00 00 00];
    reg = <1>;
};
};

[...]

pinctrl_usbh2_idle: usbh2grp-idle {
    fsl,pins = <
  MX6QDL_PAD_RGMII_TXC__USB_H2_DATA   0x40013030
  MX6QDL_PAD_RGMII_TX_CTL__USB_H2_STROBE  0x40013030
    >;
};

pinctrl_usbh2_active: usbh2grp-active {
    fsl,pins = <
  MX6QDL_PAD_RGMII_TXC__USB_H2_DATA   0x40013030
  MX6QDL_PAD_RGMII_TX_CTL__USB_H2_STROBE  0x40017030
    >;
};


Are there any test cases I should try?
How can I test suspend/resume?



- System suspend/resume
1. Enable USB wakeup
for i in $(find /sys -name wakeup | grep usb);do echo enabled  > 
$i;echo "echo enabled > $i";done;

2. Let the system enter suspend using below command
echo mem > /sys/power/state
3. And see if there is a wakeup block system entering suspend, and 
check if USB HSIC works ok

after system resume


System suspend/resume seems to work fine. After resume the ethernet 
controller works.


root@imxceet-solo-s-43:~# echo mem > /sys/power/state
PM: suspend entry (deep)
PM: Syncing filesystems ... done.
Freezing user space processes ... (elapsed 0.001 seconds) done.
OOM killer disabled.
Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
smsc95xx 3-1:1.0 eth1: entering SUSPEND2 mode
PM: suspend devices took 0.050 seconds
Disabling non-boot CPUs ...
usb 3-1: reset high-speed USB device number 2 using ci_hdrc
PM: resume devices took 0.590 seconds
OOM killer enabled.
Restarting tasks ... done.
PM: suspend exit
smsc95xx 3-1:1.0 eth1: link up, 100Mbps, full-duplex, lpa 0x4DE1
fec 2188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx



- Runtime suspend
1. Enable auto suspend for all USB devices, and check if USBOH3 clock 
is closed,

make sure do not plug any ethernet cable on the RJ45 port.

/* Enable auto suspend */
for i in $(find /sys -name control | grep usb);do echo auto  > $i;echo 
"echo auto > $i";done;


This doesn't work. When the port is suspended it gets into a loop of 
suspending/resuming endlessly. If i put two logs in 
ci_hdrc_imx_runtime_suspend() and ci_hdrc_imx_runtime_resume(), I get this:


[...]
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
[...]


Ok, forget about the loop, this was caused by one of the other ports, 
that had issues with overcurrent detection.


But still it doesn't work for the HSIC port.

The HSIC device is stuck in status "suspending" (note: "suspending" and 
not "suspended"):


~# cat /sys/bus/usb/devices/usb1/power/runtime_status
suspended
~# cat /sys/bus/usb/devices/usb2/power/runtime_status
suspended
~# cat /sys/bus/usb/devices/usb3/power/runtime_status
active
~# cat /sys/bus/usb/devices/usb3/3-1/power/runtime_status
suspending


Re: Query on usb/core/devio.c

2018-10-17 Thread Alan Stern
On Wed, 17 Oct 2018, Oliver Neukum wrote:

> On Di, 2018-10-16 at 10:46 -0400, Alan Stern wrote:
> > On Tue, 16 Oct 2018, Mayuresh Kulkarni wrote:
> > 
> > > 1. User space decides when it is time to suspend the device and calls
> > > this ioctl. The implmentation takes care to ensure, no URB is in
> > > flight from this caller to this device. Then proceed with suspend.
> > 
> > Well, I did not imagine the ioctl would try to ensure that no URBs are 
> > in flight.  The user would be responsible for that.
> 
> Well, we have to check for URBs in flight. In fact we would have to
> "plug" the device against new URBs. Now, we could use a new counter.
> But if we check asynclist, we may just as well walk it and kill the
> URBs. It just seems a bit silly not to do that.

In fact, the USB core already flushes outstanding URBs when a device
gets suspended.

I don't know that "plugging" is needed.  We could simply let new URBs
fail (the core prevents URBs from being sent to a suspended device).

> > Also, proceeding with the suspend is difficult, as Oliver has pointed 
> > out.  There is no guarantee that the device will go into suspend, 
> > merely because the userspace driver isn't accessing it.  (In fact, 
> > there's no guarantee that the device will _ever_ go into suspend.)  The 
> > ioctl would probably have to include some sort of timeout; it would 
> > return early if the timeout expired before the device was suspended.
> 
> Exactly. The alternative is to have an ioctl() to just allow or block
> suspend, more or less just exporting autopm_get/put(). The disadvantage
> is that
> 
> 1. The kernel has to cancel URBs in flight
> 2. There needs to be a mechanism to notify user space about events
> 
> > > 2. In an another thread, the user-space calls poll(USB-device-fd).
> > > When poll() returns, that means the device is active now. User space
> > > can then request an URB to read out the async notification, if any.
> > 
> > No; no other thread or polling is needed.  The ioctl call returns when
> > the device resumes.  At that point the user program can check whether
> > there is an async notification pending.
> 
> This is problematic. For example, what do we do if a signal needs
> to be delivered? The obvious solution of just repeating the call will
> not work. It races with wakeup. You'd need to restart IO to query
> the device. But the device may be suspended. Or do you want a signal
> to up the PM counter again?

The only way to make the ioctl work properly is to have it do a 
runtime-PM put at the start and then a runtime-PM get before it 
returns.  This is true regardless of the reason for returning: normal 
termination, timeout, signal, whatever.  Nothing else would be safe.

> Making Ctrl-C wake up an unrelated device?

I don't follow.

> What do we do in case of a failed suspend or resume?

The ioctl returns when the usbfs runtime-resume callback is invoked.  
This may or may not happen after a failed suspend.  But if the device 
doesn't go into suspend within the ioctl's timeout period, the ioctl 
will return in any case.

In case of a failed resume, what _can_ we do?

> How about reset_resume?

Indeed, what happens if a device in use by usbfs gets reset even while
it isn't suspended?  We should do the same thing as much as possible, 
regardless of the device's state when the reset occurred.

Alan Stern



Logitech G27 leds no more supported

2018-10-17 Thread elrondo46



Hi,

No more leds subdirectory for this wheel, someone reports me G29 leds stays 
supported correctly.

No more path: /sys/class/leds/logitechwheelpath, just my keyboard leds are 
detected. Force feedback are correctly supported.

Please fix this

Cheer

Elrondo

INFO: Kernel 4.18 and older affected

Sending this according to Greg Kroah-Hartmann

On Wed, Oct 17, 2018 at 11:58:29AM +, bugzilla-dae...@bugzilla.kernel.org 
wrote:
> https://bugzilla.kernel.org/show_bug.cgi?id=201457
>
> Bug ID: 201457
>Summary: Logitech G27 leds no more supported
>Product: Drivers
>Version: 2.5
> Kernel Version: 4.18 and oldest

All USB bugs should be sent to the linux-usb@vger.kernel.org mailing
list, and not entered into bugzilla.  Please bring this issue up there,
if it is still a problem in the latest kernel release.






Re: [PATCH 0/4] usb: chipidea: imx: add HSIC support

2018-10-17 Thread Frieder Schrempf

On 17.10.18 13:04, Frieder Schrempf wrote:

On 17.10.18 11:56, Frieder Schrempf wrote:

[...]

- System suspend/resume
1. Enable USB wakeup
for i in $(find /sys -name wakeup | grep usb);do echo enabled  > 
$i;echo "echo enabled > $i";done;

2. Let the system enter suspend using below command
echo mem > /sys/power/state
3. And see if there is a wakeup block system entering suspend, and 
check if USB HSIC works ok

after system resume


System suspend/resume seems to work fine. After resume the ethernet 
controller works.


root@imxceet-solo-s-43:~# echo mem > /sys/power/state
PM: suspend entry (deep)
PM: Syncing filesystems ... done.
Freezing user space processes ... (elapsed 0.001 seconds) done.
OOM killer disabled.
Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
smsc95xx 3-1:1.0 eth1: entering SUSPEND2 mode
PM: suspend devices took 0.050 seconds
Disabling non-boot CPUs ...
usb 3-1: reset high-speed USB device number 2 using ci_hdrc
PM: resume devices took 0.590 seconds
OOM killer enabled.
Restarting tasks ... done.
PM: suspend exit
smsc95xx 3-1:1.0 eth1: link up, 100Mbps, full-duplex, lpa 0x4DE1
fec 2188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx



- Runtime suspend
1. Enable auto suspend for all USB devices, and check if USBOH3 clock 
is closed,

make sure do not plug any ethernet cable on the RJ45 port.

/* Enable auto suspend */
for i in $(find /sys -name control | grep usb);do echo auto  > 
$i;echo "echo auto > $i";done;


This doesn't work. When the port is suspended it gets into a loop of 
suspending/resuming endlessly. If i put two logs in 
ci_hdrc_imx_runtime_suspend() and ci_hdrc_imx_runtime_resume(), I get 
this:


[...]
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
ci_hdrc_imx_runtime_resume:603
ci_hdrc_imx_runtime_suspend:574
[...]


Ok, forget about the loop, this was caused by one of the other ports, 
that had issues with overcurrent detection.


But still it doesn't work for the HSIC port.

The HSIC device is stuck in status "suspending" (note: "suspending" and 
not "suspended"):


~# cat /sys/bus/usb/devices/usb1/power/runtime_status
suspended
~# cat /sys/bus/usb/devices/usb2/power/runtime_status
suspended
~# cat /sys/bus/usb/devices/usb3/power/runtime_status
active
~# cat /sys/bus/usb/devices/usb3/3-1/power/runtime_status
suspending


It seems like this is a problem with the smsc95xx driver. I fixed this 
and now the device is suspending properly, when the network interface is 
down and resumes when it comes up.


I also checked the USBOH3 clock and its properly switched on and off.

What didn't work is auto suspend and resume on ethernet link down/up, 
but this seems to be a restriction of the smsc95xx/usbnet driver.


So all in all this looks good to me. Please let me know if you need any 
more information or tests.


Thanks,
Frieder




For your photos 25

2018-10-17 Thread Jenny

We provide photoshop services to some of the companies from around the
world.

Some online stores use our services for retouching portraits, jewelry,
apparels, furnitures etc.

Here are the details of what we provide:
Clipping path
Deep etching
Image masking
Portrait retouching
Jewelry retouching
Fashion retouching

Please reply back for further info.
We can provide testing for your photos if needed.

Thanks,
Jenny



For your photos 25

2018-10-17 Thread Jenny

We provide photoshop services to some of the companies from around the
world.

Some online stores use our services for retouching portraits, jewelry,
apparels, furnitures etc.

Here are the details of what we provide:
Clipping path
Deep etching
Image masking
Portrait retouching
Jewelry retouching
Fashion retouching

Please reply back for further info.
We can provide testing for your photos if needed.

Thanks,
Jenny



[PATCH] HID: hiddev: fix potential Spectre v1

2018-10-17 Thread Breno Leitao
uref->usage_index can be indirectly controlled by userspace, hence leading
to a potential exploitation of the Spectre variant 1 vulnerability.

This problem might show up in the cmd = HIDIOCGCOLLECTIONINDEX flow at function
hiddev_ioctl_usage(), where uref->usage_index is compared to field->maxusage
and then used as an index to dereference field->usage array.

This is a summary of the current flow, which matches the traditional
Spectre V1 issue:

copy_from_user(uref, user_arg, sizeof(*uref))
if (uref->usage_index >= field->maxusage)
goto inval;
i = field->usage[uref->usage_index].collection_index;
return i;

This patch fixes this by sanitizing field uref->usage_index before using it to
index field->usage, thus, avoiding speculation in the first load.

Signed-off-by: Breno Leitao 
---
 drivers/hid/usbhid/hiddev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index 23872d08308c..8829cbc1f6b1 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -512,6 +512,9 @@ static noinline int hiddev_ioctl_usage(struct hiddev 
*hiddev, unsigned int cmd,
if (cmd == HIDIOCGCOLLECTIONINDEX) {
if (uref->usage_index >= field->maxusage)
goto inval;
+   uref->usage_index =
+   array_index_nospec(uref->usage_index,
+  field->maxusage);
} else if (uref->usage_index >= field->report_count)
goto inval;
}
-- 
2.17.1



Re: [PATCH] HID: hiddev: fix potential Spectre v1

2018-10-17 Thread Gustavo A. R. Silva


Hi Breno,

On 10/17/18 9:47 PM, Breno Leitao wrote:
> uref->usage_index can be indirectly controlled by userspace, hence leading
> to a potential exploitation of the Spectre variant 1 vulnerability.
> 
> This problem might show up in the cmd = HIDIOCGCOLLECTIONINDEX flow at 
> function
> hiddev_ioctl_usage(), where uref->usage_index is compared to field->maxusage
> and then used as an index to dereference field->usage array.
> 
> This is a summary of the current flow, which matches the traditional
> Spectre V1 issue:
> 
>   copy_from_user(uref, user_arg, sizeof(*uref))
>   if (uref->usage_index >= field->maxusage)
>   goto inval;
>   i = field->usage[uref->usage_index].collection_index;
>   return i;
> 
> This patch fixes this by sanitizing field uref->usage_index before using it to
> index field->usage, thus, avoiding speculation in the first load.
> 
> Signed-off-by: Breno Leitao 
> ---
>  drivers/hid/usbhid/hiddev.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
> index 23872d08308c..8829cbc1f6b1 100644
> --- a/drivers/hid/usbhid/hiddev.c
> +++ b/drivers/hid/usbhid/hiddev.c
> @@ -512,6 +512,9 @@ static noinline int hiddev_ioctl_usage(struct hiddev 
> *hiddev, unsigned int cmd,
>   if (cmd == HIDIOCGCOLLECTIONINDEX) {
>   if (uref->usage_index >= field->maxusage)
>   goto inval;
> + uref->usage_index =
> + array_index_nospec(uref->usage_index,
> +field->maxusage);

Good catch.

>   } else if (uref->usage_index >= field->report_count)
>   goto inval;

Although, notice that this is the same index, and it can be used to index 
field->value[]
at lines 526 and 532.

Thanks
--
Gustavo


RE: [PATCH 2/4] usb: chipidea: imx: add HSIC support

2018-10-17 Thread Peter Chen
 
 
> > +static int ci_hdrc_imx_notify_event(struct ci_hdrc *ci, unsigned int
> > +event) {
> > +   struct device *dev = ci->dev->parent;
> > +   struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
> > +   int ret = 0;
> > +
> > +   switch (event) {
> > +   case CI_HDRC_IMX_HSIC_ACTIVE_EVENT:
> > +   if (!IS_ERR(data->pinctrl) &&
> > +   !IS_ERR(data->pinctrl_hsic_active)) {
> 
> If we make the pinctrl mandatory in case of HSIC as proposed below, we don't 
> need
> the checks here.
> 

Will delete them

 
> > +
> > +   data->pinctrl_hsic_active = pinctrl_lookup_state(data->pinctrl,
> > +   "active");
> > +   if (IS_ERR(data->pinctrl_hsic_active))
> > +   dev_dbg(dev,
> > +   "pinctrl_hsic_active lookup failed, err=%ld\n",
> > +   PTR_ERR(data->pinctrl_hsic_active));
> > +   }
> 
> In the paragraph above, I think we should make the pinctrl settings mandatory 
> in
> case of HSIC and error out if one of them is missing.
> 
> Also I think we could make the code more readable by removing the nested
> conditions.
> 
> Maybe something like this would be better?
> 
> if (of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC)
> {
>   data->pinctrl = devm_pinctrl_get(dev);
>   if (IS_ERR(data->pinctrl)) {
>   dev_err(dev, "failed to get HSIC pinctrl, err=%ld\n",
>   PTR_ERR(data->pinctrl));
>   return PTR_ERR(data->pinctrl);
>   }
> 
>   pinctrl_hsic_idle = pinctrl_lookup_state(data->pinctrl, "idle");
>   if (IS_ERR(pinctrl_hsic_idle)) {
>   dev_err(dev, "failed to get HSIC idle pinctrl,"
>"err=%ld\n", PTR_ERR(pinctrl_hsic_idle));
>   return PTR_ERR(pinctrl_hsic_idle);
>   }
> 
>   ret = pinctrl_select_state(data->pinctrl, pinctrl_hsic_idle);
>   if (ret) {
>   dev_err(dev, "failed to select HSIC idle pinctrl,"
>"err=%d\n", ret);
>   return ret;
>   }
> 
>   data->pinctrl_hsic_active = pinctrl_lookup_state(data->pinctrl,
>"active");
>   if (IS_ERR(data->pinctrl_hsic_active)) {
>   dev_err(dev, "failed to get HSIC active pinctrl,"
>"err=%ld\n",
>PTR_ERR(data->pinctrl_hsic_active));
>   return PTR_ERR(data->pinctrl_hsic_active);
>   }
> }
> 

Good idea.

 
> >   }
> > @@ -367,9 +470,19 @@ static void ci_hdrc_imx_shutdown(struct
> platform_device *pdev)
> >   static int __maybe_unused imx_controller_suspend(struct device *dev)
> >   {
> > struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
> > +   int ret = 0;
> >
> > dev_dbg(dev, "at %s\n", __func__);
> >
> > +   if (data->usbmisc_data) {
> 
> Why do we have this check here, but not in imx_controller_resume()?
> 

I will delete check here since there is NULL point check at 
imx_usbmisc_hsic_set_clk too.

> > +   ret = imx_usbmisc_hsic_set_clk(data->usbmisc_data, false);
> > +   if (ret) {
> > +   dev_err(dev,
> > +   "usbmisc hsic_set_clk failed, ret=%d\n", ret);
> > +   return ret;
> > +   }
> > +   }
> > +
> > imx_disable_unprepare_clks(dev);
> > data->in_lpm = true;
> >
> > @@ -400,8 +513,16 @@ static int __maybe_unused
> imx_controller_resume(struct device *dev)
> > goto clk_disable;
> > }
> >
> 
> Why don't we have a check for data->usbmisc_data here, but in
> imx_controller_suspend() we have one?
> 

Yes, not need.

> > +   ret = imx_usbmisc_hsic_set_clk(data->usbmisc_data, true);
> > +   if (ret) {
> > +   dev_err(dev, "usbmisc hsic_set_clk failed, ret=%d\n", ret);
> > +   goto hsic_set_clk_fail;
> > +   }
> > +
> > return 0;
> >
> > +hsic_set_clk_fail:
> > +   imx_usbmisc_set_wakeup(data->usbmisc_data, true);
> >   clk_disable:
> > imx_disable_unprepare_clks(dev);
> > return ret;
> > diff --git a/drivers/usb/chipidea/ci_hdrc_imx.h
> > b/drivers/usb/chipidea/ci_hdrc_imx.h
> > index 204275f47573..fcecab478934 100644
> > --- a/drivers/usb/chipidea/ci_hdrc_imx.h
> > +++ b/drivers/usb/chipidea/ci_hdrc_imx.h
> > @@ -14,10 +14,13 @@ struct imx_usbmisc_data {
> > unsigned int oc_polarity:1; /* over current polarity if oc enabled */
> > unsigned int evdo:1; /* set external vbus divider option */
> > unsigned int ulpi:1; /* connected to an ULPI phy */
> > +   unsigned int hsic:1; /* HSIC controlller */
> >   };
> >
> > -int imx_usbmisc_init(struct imx_usbmisc_data *); -int
> > imx_usbmisc_init_post(struct imx_usbmisc_data *); -int
> > imx_usbmisc_set_wakeup(struct imx_usbmisc_data *, bool);
> > +int imx_usbmisc_init(struct imx_usbmisc_data *data); int
> > +imx_usbmisc_init_post(struct imx_usbmisc_data *data); int
> 

RE: [PATCH 0/4] usb: chipidea: imx: add HSIC support

2018-10-17 Thread Peter Chen
 
> >>> - System suspend/resume
> >>> 1. Enable USB wakeup
> >>> for i in $(find /sys -name wakeup | grep usb);do echo enabled  >
> >>> $i;echo "echo enabled > $i";done; 2. Let the system enter suspend
> >>> using below command echo mem > /sys/power/state 3. And see if there
> >>> is a wakeup block system entering suspend, and check if USB HSIC
> >>> works ok after system resume
> >>
> >> System suspend/resume seems to work fine. After resume the ethernet
> >> controller works.
> >>
> >> root@imxceet-solo-s-43:~# echo mem > /sys/power/state
> >> PM: suspend entry (deep)
> >> PM: Syncing filesystems ... done.
> >> Freezing user space processes ... (elapsed 0.001 seconds) done.
> >> OOM killer disabled.
> >> Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
> >> smsc95xx 3-1:1.0 eth1: entering SUSPEND2 mode
> >> PM: suspend devices took 0.050 seconds Disabling non-boot CPUs ...
> >> usb 3-1: reset high-speed USB device number 2 using ci_hdrc
> >> PM: resume devices took 0.590 seconds OOM killer enabled.
> >> Restarting tasks ... done.
> >> PM: suspend exit
> >> smsc95xx 3-1:1.0 eth1: link up, 100Mbps, full-duplex, lpa 0x4DE1 fec
> >> 2188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
> >>
> >>>
> >>> - Runtime suspend
> >>> 1. Enable auto suspend for all USB devices, and check if USBOH3
> >>> clock is closed, make sure do not plug any ethernet cable on the
> >>> RJ45 port.
> >>>
> >>> /* Enable auto suspend */
> >>> for i in $(find /sys -name control | grep usb);do echo auto  >
> >>> $i;echo "echo auto > $i";done;
> >>
> >> This doesn't work. When the port is suspended it gets into a loop of
> >> suspending/resuming endlessly. If i put two logs in
> >> ci_hdrc_imx_runtime_suspend() and ci_hdrc_imx_runtime_resume(), I get
> >> this:
> >>
> >> [...]
> >> ci_hdrc_imx_runtime_resume:603
> >> ci_hdrc_imx_runtime_suspend:574
> >> ci_hdrc_imx_runtime_resume:603
> >> ci_hdrc_imx_runtime_suspend:574
> >> ci_hdrc_imx_runtime_resume:603
> >> ci_hdrc_imx_runtime_suspend:574
> >> ci_hdrc_imx_runtime_resume:603
> >> ci_hdrc_imx_runtime_suspend:574
> >> [...]
> >
> > Ok, forget about the loop, this was caused by one of the other ports,
> > that had issues with overcurrent detection.
> >
> > But still it doesn't work for the HSIC port.
> >
> > The HSIC device is stuck in status "suspending" (note: "suspending"
> > and not "suspended"):
> >
> > ~# cat /sys/bus/usb/devices/usb1/power/runtime_status
> > suspended
> > ~# cat /sys/bus/usb/devices/usb2/power/runtime_status
> > suspended
> > ~# cat /sys/bus/usb/devices/usb3/power/runtime_status
> > active
> > ~# cat /sys/bus/usb/devices/usb3/3-1/power/runtime_status
> > suspending
> 
> It seems like this is a problem with the smsc95xx driver. I fixed this and 
> now the
> device is suspending properly, when the network interface is down and resumes
> when it comes up.
> 
> I also checked the USBOH3 clock and its properly switched on and off.
> 
> What didn't work is auto suspend and resume on ethernet link down/up, but this
> seems to be a restriction of the smsc95xx/usbnet driver.
> 
> So all in all this looks good to me. Please let me know if you need any more
> information or tests.
> 

Thanks, Frieder, no more tests are needed.
You could send me your dts changes as patches, I will append it at my v2 patch 
series.

Peter


Re: Logitech G27 leds no more supported

2018-10-17 Thread Greg KH
On Wed, Oct 17, 2018 at 02:44:51PM +, elrond...@protonmail.com wrote:
> 
> 
> Hi,
> 
> No more leds subdirectory for this wheel, someone reports me G29 leds stays 
> supported correctly.
> 
> No more path: /sys/class/leds/logitechwheelpath, just my keyboard leds are 
> detected. Force feedback are correctly supported.
> 
> Please fix this
> 
> Cheer
> 
> Elrondo
> 
> INFO: Kernel 4.18 and older affected

What kernel version did this work properly on?

And I think the linux-input mailing list would want to know about this,
this isn't a usb-core specific issue.  I've added them to the cc: here.
thanks,

greg k-h


my subject

2018-10-17 Thread test
I am Peter Wong director of operations, Hong Kong and Shanghai Banking
Corporation Limited Hong Kong. I have a very confidential business
proposition involving transfer of $18.350.000.00 that will be of great
benefit for both of us. Reply for more details as regards this
transaction

Best Regards
Peter Wong
ec


SMSC9730 Autosuspend/Resume Questions

2018-10-17 Thread Frieder Schrempf

Hi,

I recently tested a board with SMSC9730 connected via USB HSIC to an 
i.MX6S SOC. I used these patches on top of v4.14-rc8 for the USB HSIC 
support: [1].


When I turned on autosuspend, the smsc95xx stopped in the middle of the 
suspending routine and 
/sys/bus/usb/devices/usb3/3-1/power/runtime_status reported "suspending" 
forever.


With some debug logs I found out, that the last line of code that was 
executed is [2], after that I didn't get any further messages.


Then I applied the following diff and the suspend/resume started to work 
reliably:


@@ -1382,10 +1385,11 @@ static int smsc95xx_link_ok_nopm(struct usbnet *dev)
ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
if (ret < 0)
return ret;
-
+   /*
ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
if (ret < 0)
return ret;
+   */

return !!(ret & BMSR_LSTATUS);
 }

So it seems like the dummy read, that is commented with "first, a dummy 
read, needed to latch some MII phys" causes problems in my setup. Do you 
have an idea what could be the reason? Is this a proper fix?


Thanks,
Frieder

[1] https://patchwork.kernel.org/cover/10643089/
[2] 
https://github.com/torvalds/linux/blob/bab5c80b211035739997ebd361a679fa85b39465/drivers/net/usb/smsc95xx.c#L1382


[PATCH v1 1/1] usb: dwc3: Fix NULL pointer exception in dwc3_pci_remove()

2018-10-17 Thread Kuppuswamy Sathyanarayanan
In dwc3_pci_quirks() function, gpiod lookup table is only registered for
baytrail SOC. But in dwc3_pci_remove(), we try to unregistered it
without any checks. This leads to NULL pointer de-reference exception in
gpiod_remove_lookup_table() when unloading the module for non baytrail
SOCs. This patch fixes this issue.

Fixes: 5741022cbdf3 ("usb: dwc3: pci: Add GPIO lookup table on platforms
without ACPI GPIO resources")
Cc: 
Signed-off-by: Kuppuswamy Sathyanarayanan 

Reviewed-by: Heikki Krogerus 
---
 drivers/usb/dwc3/dwc3-pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 1286076a8890..842795856bf4 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -283,8 +283,10 @@ static int dwc3_pci_probe(struct pci_dev *pci, const 
struct pci_device_id *id)
 static void dwc3_pci_remove(struct pci_dev *pci)
 {
struct dwc3_pci *dwc = pci_get_drvdata(pci);
+   struct pci_dev  *pdev = dwc->pci;
 
-   gpiod_remove_lookup_table(&platform_bytcr_gpios);
+   if (pdev->device == PCI_DEVICE_ID_INTEL_BYT)
+   gpiod_remove_lookup_table(&platform_bytcr_gpios);
 #ifdef CONFIG_PM
cancel_work_sync(&dwc->wakeup_work);
 #endif
-- 
2.7.4



[PATCH V2 0/6] Add XHCI, EHCI and OHCI support for Broadcom STB SoS's

2018-10-17 Thread Al Cooper
V2 - Based on feedback, the functionality for XHCI and OHCI was
 moved from Broadcom platform drivers into the standard XHCI
 and OHCI platform drivers. The EHCI functionality still uses
 a Broadcom EHCI driver because of the workarounds needed for
 bugs in the EHCI controller.

This adds support for the XHCI, EHCI and OHCI host controllers found
in Broadcom STB SoC's. These drivers depend on getting access to the
new Broadcom STB USB PHY driver through a device-tree phandle and
will fail if the driver is not available.

Al Cooper (6):
  dt-bindings: Add Broadcom STB OHCI, EHCI and XHCI binding document
  usb: core: Add ability to skip phy exit on suspend and init on resume
  usb: xhci: xhci-plat: Add support for Broadcom STB SoC's
  usb: ohci-platform: Add support for Broadcom STB SoC's
  usb: ehci: Add new EHCI driver for Broadcom STB SoC's
  usb: host: Add ability to build new Broadcom STB USB drivers

 .../devicetree/bindings/usb/brcm,bcm7445-ehci.txt  |  22 ++
 .../devicetree/bindings/usb/brcm,bcm7445-ohci.txt  |  22 ++
 .../devicetree/bindings/usb/brcm,bcm7445-xhci.txt  |  23 ++
 MAINTAINERS|   9 +
 drivers/usb/core/hcd.c |   8 +-
 drivers/usb/core/phy.c |  18 +-
 drivers/usb/core/phy.h |   9 +-
 drivers/usb/host/Kconfig   |  29 ++
 drivers/usb/host/Makefile  |  18 +-
 drivers/usb/host/ehci-brcm.c   | 291 +
 drivers/usb/host/ohci-platform.c   |  35 ++-
 drivers/usb/host/xhci-brcm.c   |  17 ++
 drivers/usb/host/xhci-brcm.h   |  16 ++
 drivers/usb/host/xhci-plat.c   |   8 +
 include/linux/usb/hcd.h|   3 +
 include/linux/usb/ohci_pdriver.h   |   1 +
 16 files changed, 504 insertions(+), 25 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-ehci.txt
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-ohci.txt
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-xhci.txt
 create mode 100644 drivers/usb/host/ehci-brcm.c
 create mode 100644 drivers/usb/host/xhci-brcm.c
 create mode 100644 drivers/usb/host/xhci-brcm.h

-- 
1.9.0.138.g2de3478



[PATCH V2 3/6] usb: xhci: xhci-plat: Add support for Broadcom STB SoC's

2018-10-17 Thread Al Cooper
Add support for Broadcom STB SoC's to the xhci platform driver

Signed-off-by: Al Cooper 
---
 drivers/usb/host/xhci-brcm.c | 17 +
 drivers/usb/host/xhci-brcm.h | 16 
 drivers/usb/host/xhci-plat.c |  8 
 3 files changed, 41 insertions(+)
 create mode 100644 drivers/usb/host/xhci-brcm.c
 create mode 100644 drivers/usb/host/xhci-brcm.h

diff --git a/drivers/usb/host/xhci-brcm.c b/drivers/usb/host/xhci-brcm.c
new file mode 100644
index ..a7220126f6af
--- /dev/null
+++ b/drivers/usb/host/xhci-brcm.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2018, Broadcom */
+
+#include 
+#include 
+
+#include "xhci.h"
+
+int xhci_plat_brcm_init_quirk(struct usb_hcd *hcd)
+{
+   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+
+   xhci->quirks |= XHCI_RESET_ON_RESUME;
+   hcd->suspend_without_phy_exit = 1;
+   return 0;
+}
+
diff --git a/drivers/usb/host/xhci-brcm.h b/drivers/usb/host/xhci-brcm.h
new file mode 100644
index ..a39d1b807a4c
--- /dev/null
+++ b/drivers/usb/host/xhci-brcm.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2018, Broadcom */
+
+#ifndef _XHCI_BRCM_H
+#define _XHCI_BRCM_H
+
+#if IS_ENABLED(CONFIG_USB_XHCI_BRCM)
+int xhci_plat_brcm_init_quirk(struct usb_hcd *hcd);
+#else
+static inline int xhci_brcm_init_quirk(struct usb_hcd *hcd)
+{
+   return 0;
+}
+#endif
+#endif /* _XHCI_BRCM_H */
+
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 94e939249b2b..1de22928e862 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -23,6 +23,7 @@
 #include "xhci-plat.h"
 #include "xhci-mvebu.h"
 #include "xhci-rcar.h"
+#include "xhci-brcm.h"
 
 static struct hc_driver __read_mostly xhci_plat_hc_driver;
 
@@ -111,6 +112,10 @@ static int xhci_plat_start(struct usb_hcd *hcd)
.resume_quirk = xhci_rcar_resume_quirk,
 };
 
+static const struct xhci_plat_priv xhci_plat_brcm = {
+   .init_quirk = xhci_plat_brcm_init_quirk
+};
+
 static const struct of_device_id usb_xhci_of_match[] = {
{
.compatible = "generic-xhci",
@@ -143,6 +148,9 @@ static int xhci_plat_start(struct usb_hcd *hcd)
}, {
.compatible = "renesas,rcar-gen3-xhci",
.data = &xhci_plat_renesas_rcar_gen3,
+   }, {
+   .compatible = "brcm,bcm7445-xhci",
+   .data = &xhci_plat_brcm,
},
{},
 };
-- 
1.9.0.138.g2de3478



[PATCH V2 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

2018-10-17 Thread Al Cooper
Add support for Broadcom STB SoC's to the ohci platform driver.

Signed-off-by: Al Cooper 
---
 drivers/usb/host/ohci-platform.c | 35 +--
 include/linux/usb/ohci_pdriver.h |  1 +
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
index 65a1c3fdc88c..363d6fa676a5 100644
--- a/drivers/usb/host/ohci-platform.c
+++ b/drivers/usb/host/ohci-platform.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -99,12 +100,24 @@ static int ohci_platform_probe(struct platform_device *dev)
if (usb_disabled())
return -ENODEV;
 
-   /*
-* Use reasonable defaults so platforms don't have to provide these
-* with DT probing on ARM.
-*/
-   if (!pdata)
-   pdata = &ohci_platform_defaults;
+   if (!pdata) {
+   const struct usb_ohci_pdata *match_pdata;
+
+   match_pdata = of_device_get_match_data(&dev->dev);
+   if (match_pdata) {
+   pdata = devm_kzalloc(&dev->dev, sizeof(*pdata),
+GFP_KERNEL);
+   if (!pdata)
+   return -ENOMEM;
+   *pdata = *match_pdata;
+   } else {
+   /*
+* Use reasonable defaults so platforms don't have
+* to provide these with DT probing on ARM.
+*/
+   pdata = &ohci_platform_defaults;
+   }
+   }
 
err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
if (err)
@@ -177,6 +190,8 @@ static int ohci_platform_probe(struct platform_device *dev)
ohci->flags |= OHCI_QUIRK_FRAME_NO;
if (pdata->num_ports)
ohci->num_ports = pdata->num_ports;
+   if (pdata->suspend_without_phy_exit)
+   hcd->suspend_without_phy_exit = 1;
 
 #ifndef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
if (ohci->flags & OHCI_QUIRK_BE_MMIO) {
@@ -305,10 +320,18 @@ static int ohci_platform_resume(struct device *dev)
 }
 #endif /* CONFIG_PM_SLEEP */
 
+static const struct usb_ohci_pdata ohci_plat_brcm_bcm7445_ohci = {
+   .power_on = ohci_platform_power_on,
+   .power_suspend =ohci_platform_power_off,
+   .power_off =ohci_platform_power_off,
+   .suspend_without_phy_exit = 1,
+};
+
 static const struct of_device_id ohci_platform_ids[] = {
{ .compatible = "generic-ohci", },
{ .compatible = "cavium,octeon-6335-ohci", },
{ .compatible = "ti,ohci-omap3", },
+   { .compatible = "brcm,bcm7445-ohci", &ohci_plat_brcm_bcm7445_ohci},
{ }
 };
 MODULE_DEVICE_TABLE(of, ohci_platform_ids);
diff --git a/include/linux/usb/ohci_pdriver.h b/include/linux/usb/ohci_pdriver.h
index 7eb16cf587ee..16b24ea1e3bb 100644
--- a/include/linux/usb/ohci_pdriver.h
+++ b/include/linux/usb/ohci_pdriver.h
@@ -35,6 +35,7 @@ struct usb_ohci_pdata {
unsignedbig_endian_desc:1;
unsignedbig_endian_mmio:1;
unsignedno_big_frame_no:1;
+   unsignedsuspend_without_phy_exit:1;
unsigned intnum_ports;
 
/* Turn on all power and clocks */
-- 
1.9.0.138.g2de3478



[PATCH V2 2/6] usb: core: Add ability to skip phy exit on suspend and init on resume

2018-10-17 Thread Al Cooper
Add the ability to skip calling the PHY's exit routine on suspend
and the PHY's init routine on resume. This is to handle a USB PHY
that should have it's power_off function called on suspend but cannot
have it's exit function called because on exit it will disable the
PHY to the point where register accesses to the Host Controllers
using the PHY will be disabled and the host drivers will crash.

This is enabled with the HCD flag "suspend_without_phy_exit" which
can be set from any HCD driver.

Signed-off-by: Al Cooper 
---
 drivers/usb/core/hcd.c  |  8 
 drivers/usb/core/phy.c  | 18 --
 drivers/usb/core/phy.h  |  9 ++---
 include/linux/usb/hcd.h |  3 +++
 4 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 1c21955fe7c0..e67e4d6b3d21 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2263,7 +2263,7 @@ int hcd_bus_suspend(struct usb_device *rhdev, 
pm_message_t msg)
hcd->state = HC_STATE_SUSPENDED;
 
if (!PMSG_IS_AUTO(msg))
-   usb_phy_roothub_suspend(hcd->self.sysdev,
+   usb_phy_roothub_suspend(hcd,
hcd->phy_roothub);
 
/* Did we race with a root-hub wakeup event? */
@@ -2304,7 +2304,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t 
msg)
}
 
if (!PMSG_IS_AUTO(msg)) {
-   status = usb_phy_roothub_resume(hcd->self.sysdev,
+   status = usb_phy_roothub_resume(hcd,
hcd->phy_roothub);
if (status)
return status;
@@ -2347,7 +2347,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t 
msg)
}
} else {
hcd->state = old_state;
-   usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub);
+   usb_phy_roothub_suspend(hcd, hcd->phy_roothub);
dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
"resume", status);
if (status != -ESHUTDOWN)
@@ -2744,7 +2744,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
struct usb_device *rhdev;
 
if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
-   hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
+   hcd->phy_roothub = usb_phy_roothub_alloc(hcd);
if (IS_ERR(hcd->phy_roothub))
return PTR_ERR(hcd->phy_roothub);
 
diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
index 9879767452a2..b54db39eee4c 100644
--- a/drivers/usb/core/phy.c
+++ b/drivers/usb/core/phy.c
@@ -45,10 +45,11 @@ static int usb_phy_roothub_add_phy(struct device *dev, int 
index,
return 0;
 }
 
-struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
+struct usb_phy_roothub *usb_phy_roothub_alloc(struct usb_hcd *hcd)
 {
struct usb_phy_roothub *phy_roothub;
int i, num_phys, err;
+   struct device *dev = hcd->self.sysdev;
 
if (!IS_ENABLED(CONFIG_GENERIC_PHY))
return NULL;
@@ -161,26 +162,30 @@ void usb_phy_roothub_power_off(struct usb_phy_roothub 
*phy_roothub)
 }
 EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off);
 
-int usb_phy_roothub_suspend(struct device *controller_dev,
+int usb_phy_roothub_suspend(struct usb_hcd *hcd,
struct usb_phy_roothub *phy_roothub)
 {
+   struct device *controller_dev = hcd->self.sysdev;
+
usb_phy_roothub_power_off(phy_roothub);
 
/* keep the PHYs initialized so the device can wake up the system */
-   if (device_may_wakeup(controller_dev))
+   if (device_may_wakeup(controller_dev) || hcd->suspend_without_phy_exit)
return 0;
 
return usb_phy_roothub_exit(phy_roothub);
 }
 EXPORT_SYMBOL_GPL(usb_phy_roothub_suspend);
 
-int usb_phy_roothub_resume(struct device *controller_dev,
+int usb_phy_roothub_resume(struct usb_hcd *hcd,
   struct usb_phy_roothub *phy_roothub)
 {
+   struct device *controller_dev = hcd->self.sysdev;
int err;
 
/* if the device can't wake up the system _exit was called */
-   if (!device_may_wakeup(controller_dev)) {
+   if (!device_may_wakeup(controller_dev) &&
+   !hcd->suspend_without_phy_exit) {
err = usb_phy_roothub_init(phy_roothub);
if (err)
return err;
@@ -189,7 +194,8 @@ int usb_phy_roothub_resume(struct device *controller_dev,
err = usb_phy_roothub_power_on(phy_roothub);
 
/* undo _init if _power_on failed */
-   if (err && !device_may_wakeup(controller_dev))
+   if (err && !device_may_wakeup(controller_dev)
+   && !hcd->suspend_without_phy_exit)
usb_phy_roothub_exit(phy_roothub);
 
return err;
diff --git a/drivers/usb/core/phy.h b/drivers/u

[PATCH V2 5/6] usb: ehci: Add new EHCI driver for Broadcom STB SoC's

2018-10-17 Thread Al Cooper
Add a new EHCI driver for Broadcom STB SoC's. A new EHCI driver
was created instead of adding support to the existing ehci platform
driver because of the code required to workaround bugs in the EHCI
controller.

Signed-off-by: Al Cooper 
---
 drivers/usb/host/ehci-brcm.c | 291 +++
 1 file changed, 291 insertions(+)
 create mode 100644 drivers/usb/host/ehci-brcm.c

diff --git a/drivers/usb/host/ehci-brcm.c b/drivers/usb/host/ehci-brcm.c
new file mode 100644
index ..b2a100698bf5
--- /dev/null
+++ b/drivers/usb/host/ehci-brcm.c
@@ -0,0 +1,291 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2018, Broadcom */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ehci.h"
+
+#define BRCM_DRIVER_DESC "EHCI Broadcom STB driver"
+
+#define hcd_to_ehci_priv(h) ((struct brcm_priv *)hcd_to_ehci(h)->priv)
+
+struct brcm_priv {
+   struct clk *clk;
+};
+
+static const char brcm_hcd_name[] = "ehci-brcm";
+
+static int (*org_hub_control)(struct usb_hcd *hcd,
+   u16 typeReq, u16 wValue, u16 wIndex,
+   char *buf, u16 wLength);
+
+/* ehci_brcm_wait_for_sof
+ * Wait for start of next microframe, then wait extra delay microseconds
+ */
+static inline void ehci_brcm_wait_for_sof(struct ehci_hcd *ehci, u32 delay)
+{
+   int frame_idx = ehci_readl(ehci, &ehci->regs->frame_index);
+
+   while (frame_idx == ehci_readl(ehci, &ehci->regs->frame_index))
+   ;
+   udelay(delay);
+}
+
+/*
+ * ehci_brcm_hub_control
+ * Intercept echi-hcd request to complete RESUME and align it to the start
+ * of the next microframe.
+ * If RESUME is complete too late in the microframe, host controller
+ * detects babble on suspended port and resets the port afterwards.
+ * This s/w workaround allows to avoid this problem.
+ * See SWLINUX-1909 for more details
+ */
+static int ehci_brcm_hub_control(
+   struct usb_hcd  *hcd,
+   u16 typeReq,
+   u16 wValue,
+   u16 wIndex,
+   char*buf,
+   u16 wLength)
+{
+   struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+   int ports = HCS_N_PORTS(ehci->hcs_params);
+   u32 __iomem *status_reg = &ehci->regs->port_status[
+   (wIndex & 0xff) - 1];
+   unsigned long flags;
+   int retval, irq_disabled = 0;
+
+   /*
+* RESUME is cleared when GetPortStatus() is called 20ms after start
+* of RESUME
+*/
+   if ((typeReq == GetPortStatus) &&
+   (wIndex && wIndex <= ports) &&
+   ehci->reset_done[wIndex-1] &&
+   time_after_eq(jiffies, ehci->reset_done[wIndex-1]) &&
+   (ehci_readl(ehci, status_reg) & PORT_RESUME)) {
+
+   /*
+* to make sure we are not interrupted until RESUME bit
+* is cleared, disable interrupts on current CPU
+*/
+   ehci_dbg(ehci, "SOF alignment workaround\n");
+   irq_disabled = 1;
+   local_irq_save(flags);
+   ehci_brcm_wait_for_sof(ehci, 5);
+   }
+   retval = (*org_hub_control)(hcd, typeReq, wValue, wIndex, buf, wLength);
+   if (irq_disabled)
+   local_irq_restore(flags);
+   return retval;
+}
+
+static int ehci_brcm_reset(struct usb_hcd *hcd)
+{
+   struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+
+   ehci->big_endian_mmio = 1;
+   hcd->suspend_without_phy_exit = 1;
+
+   ehci->caps = (struct ehci_caps *) hcd->regs;
+   ehci->regs = (struct ehci_regs *) (hcd->regs +
+   HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)));
+
+   /* This fixes the lockup during reboot due to prior interrupts */
+   ehci_writel(ehci, CMD_RESET, &ehci->regs->command);
+   mdelay(10);
+
+   /*
+* SWLINUX-1705: Avoid OUT packet underflows during high memory
+*   bus usage
+* port_status[0x0f] = Broadcom-proprietary USB_EHCI_INSNREG00 @ 0x90
+*/
+   ehci_writel(ehci, 0x00800040, &ehci->regs->port_status[0x10]);
+   ehci_writel(ehci, 0x0001, &ehci->regs->port_status[0x12]);
+
+   return ehci_setup(hcd);
+}
+
+static struct hc_driver __read_mostly ehci_brcm_hc_driver;
+
+static const struct ehci_driver_overrides brcm_overrides __initconst = {
+
+   .reset =ehci_brcm_reset,
+   .extra_priv_size = sizeof(struct brcm_priv),
+};
+
+static int ehci_brcm_probe(struct platform_device *pdev)
+{
+   struct usb_hcd *hcd;
+   struct resource *res_mem;
+   struct brcm_priv *priv;
+   int irq;
+   int err;
+
+   if (usb_disabled())
+   return -ENODEV;
+
+   err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+   if (err)
+   return err;
+
+   irq = platform_get_irq(pdev, 0);
+   if (irq < 0) {
+  

[PATCH V2 6/6] usb: host: Add ability to build new Broadcom STB USB drivers

2018-10-17 Thread Al Cooper
Add the build system changes needed to get the Broadcom STB XHCI,
EHCI and OHCI functionality working. The link order for XHCI was
changed in the Makefile because of the way STB XHCI, EHCI and OHCI
controllers share a port which requires that the XHCI driver be
initialized first. Also update MAINTAINERS.

Signed-off-by: Al Cooper 
---
 MAINTAINERS   |  9 +
 drivers/usb/host/Kconfig  | 29 +
 drivers/usb/host/Makefile | 18 --
 3 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 6ac000cc006d..7e062dcbe173 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3006,6 +3006,15 @@ S:   Supported
 F: drivers/gpio/gpio-brcmstb.c
 F: Documentation/devicetree/bindings/gpio/brcm,brcmstb-gpio.txt
 
+BROADCOM BRCMSTB USB XHCI, EHCI and OHCI DRIVERS
+M: Al Cooper 
+L: linux-usb@vger.kernel.org
+L: bcm-kernel-feedback-l...@broadcom.com
+S: Maintained
+F: drivers/usb/host/xhci-brcm.*
+F: drivers/usb/host/ohci-brcm.c
+F: Documentation/devicetree/bindings/usb/brcm,bcm7445-*.txt
+
 BROADCOM BRCMSTB USB2 and USB3 PHY DRIVER
 M: Al Cooper 
 L: linux-ker...@vger.kernel.org
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 1a4ea98cac2a..112de3334389 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -94,6 +94,35 @@ config USB_XHCI_TEGRA
  Say 'Y' to enable the support for the xHCI host controller
  found in NVIDIA Tegra124 and later SoCs.
 
+config USB_OHCI_BRCM
+   tristate
+
+config USB_EHCI_BRCM
+   tristate
+
+config USB_XHCI_BRCM
+   tristate
+
+config BRCM_USB_PHY
+   tristate
+
+config USB_BRCM
+   tristate "Broadcom STB USB support"
+   depends on ARCH_BRCMSTB
+   select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
+   select USB_EHCI_BRCM if USB_EHCI_HCD
+   select USB_XHCI_BRCM if USB_XHCI_HCD
+   select USB_XHCI_PLATFORM if USB_XHCI_HCD
+   select BRCM_USB_PHY if USB_OHCI_HCD || USB_EHCI_HCD || USB_XHCI_HCD
+   select GENERIC_PHY if BRCM_USB_PHY
+   default ARCH_BRCMSTB
+   help
+ Say Y to enable support for XHCI, EHCI and OHCI host controllers
+ found in Broadcom STB SoC's.
+
+ Disabling this will keep the controllers and corresponding
+ PHYs powered down.
+
 endif # USB_XHCI_HCD
 
 config USB_EHCI_HCD
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index e6235269c151..2a16226f0916 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -31,6 +31,10 @@ ifneq ($(CONFIG_USB_XHCI_RCAR), )
xhci-plat-hcd-y += xhci-rcar.o
 endif
 
+ifneq ($(CONFIG_USB_XHCI_BRCM), )
+   xhci-plat-hcd-y += xhci-brcm.o
+endif
+
 ifneq ($(CONFIG_DEBUG_FS),)
xhci-hcd-y  += xhci-debugfs.o
 endif
@@ -39,6 +43,13 @@ obj-$(CONFIG_USB_WHCI_HCD)   += whci/
 
 obj-$(CONFIG_USB_PCI)  += pci-quirks.o
 
+obj-$(CONFIG_USB_XHCI_HCD) += xhci-hcd.o
+obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
+obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o
+obj-$(CONFIG_USB_XHCI_HISTB)   += xhci-histb.o
+obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk.o
+obj-$(CONFIG_USB_XHCI_TEGRA)   += xhci-tegra.o
+
 obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o
 obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o
 obj-$(CONFIG_USB_EHCI_HCD_PLATFORM)+= ehci-platform.o
@@ -52,6 +63,7 @@ obj-$(CONFIG_USB_EHCI_EXYNOS) += ehci-exynos.o
 obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o
 obj-$(CONFIG_USB_EHCI_TEGRA)   += ehci-tegra.o
 obj-$(CONFIG_USB_W90X900_EHCI) += ehci-w90x900.o
+obj-$(CONFIG_USB_EHCI_BRCM)+= ehci-brcm.o
 
 obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o
 obj-$(CONFIG_USB_ISP116X_HCD)  += isp116x-hcd.o
@@ -72,12 +84,6 @@ obj-$(CONFIG_USB_OHCI_HCD_DAVINCI)   += ohci-da8xx.o
 
 obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
 obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
-obj-$(CONFIG_USB_XHCI_HCD) += xhci-hcd.o
-obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
-obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o
-obj-$(CONFIG_USB_XHCI_HISTB)   += xhci-histb.o
-obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk.o
-obj-$(CONFIG_USB_XHCI_TEGRA)   += xhci-tegra.o
 obj-$(CONFIG_USB_SL811_HCD)+= sl811-hcd.o
 obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o
 obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o
-- 
1.9.0.138.g2de3478



[PATCH V2 1/6] dt-bindings: Add Broadcom STB OHCI, EHCI and XHCI binding document

2018-10-17 Thread Al Cooper
Add DT bindings document for Broadcom STB USB OHCI, EHCI and
XHCI drivers.

Signed-off-by: Al Cooper 
---
 .../devicetree/bindings/usb/brcm,bcm7445-ehci.txt  | 22 +
 .../devicetree/bindings/usb/brcm,bcm7445-ohci.txt  | 22 +
 .../devicetree/bindings/usb/brcm,bcm7445-xhci.txt  | 23 ++
 3 files changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-ehci.txt
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-ohci.txt
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-xhci.txt

diff --git a/Documentation/devicetree/bindings/usb/brcm,bcm7445-ehci.txt 
b/Documentation/devicetree/bindings/usb/brcm,bcm7445-ehci.txt
new file mode 100644
index ..824f4bf5d07c
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/brcm,bcm7445-ehci.txt
@@ -0,0 +1,22 @@
+Broadcom STB USB EHCI controller
+
+Required properties:
+- compatible: should be "brcm,bcm7445-ehci"
+- reg: should contain one register range i.e. start and length
+- interrupts: description of the interrupt line
+- phys: phandle + phy specifier pair
+  The specifier should be 0 for the OHCI/EHCI PHY
+
+Optional properties:
+- clocks: A phandle for the EHCI clock
+
+Example:
+
+ehci@f0b00300 {
+   compatible = "brcm,bcm7445-ehci";
+   reg = <0xf0b00300 0xa8>;
+   interrupts = <0x0 0x5a 0x0>;
+   interrupt-names = "usb0_ehci_0";
+   phys = <&usbphy_0 0x0>;
+   clocks = <&usb20>
+};
diff --git a/Documentation/devicetree/bindings/usb/brcm,bcm7445-ohci.txt 
b/Documentation/devicetree/bindings/usb/brcm,bcm7445-ohci.txt
new file mode 100644
index ..de5a22b3d138
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/brcm,bcm7445-ohci.txt
@@ -0,0 +1,22 @@
+Broadcom STB USB OHCI controller
+
+Required properties:
+- compatible: should be "brcm,bcm7445-ohci"
+- reg: should contain one register range i.e. start and length
+- interrupts: description of the interrupt line
+- phys: phandle + phy specifier pair
+  The specifier should be 0 for the OHCI/EHCI PHY
+
+Optional properties:
+- clocks: A phandle for the OHCI clock
+
+Example:
+
+ohci@f0b00400 {
+   compatible = "brcm,bcm7445-ohci";
+   reg = <0xf0b00400 0x58>;
+   interrupts = <0x0 0x5b 0x0>;
+   interrupt-names = "usb0_ohci_0";
+   phys = <&usbphy_0 0x0>;
+   clocks = <&usb20>;
+};
diff --git a/Documentation/devicetree/bindings/usb/brcm,bcm7445-xhci.txt 
b/Documentation/devicetree/bindings/usb/brcm,bcm7445-xhci.txt
new file mode 100644
index ..c41f3f8d836d
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/brcm,bcm7445-xhci.txt
@@ -0,0 +1,23 @@
+Broadcom STB USB XHCI controller
+
+Required properties:
+- compatible: should be "brcm,bcm7445-xhci"
+- reg: should contain one register range i.e. start and length
+- interrupts: description of the interrupt line
+- phys: phandle + phy specifier pair
+  The specifier should be 1 for the XHCI PHY
+
+Optional properties:
+- clocks: A phandle for the XHCI clock
+- usb3-lpm-capable: determines if platform is USB3 LPM capable
+
+Example:
+
+xhci_0_0: xhci@f0b01000 {
+   compatible = "brcm,bcm7445-xhci";
+   reg = <0xf0b01000 0x1000>;
+   interrupts = <0x0 0x5c 0x0>;
+   interrupt-names = "usb0_xhci_0";
+   phys = <&usbphy_0 0x1>;
+   clocks = <&usb30>;
+};
-- 
1.9.0.138.g2de3478



Re: [PATCH 0/6] usb: gadget: add mechanism to asynchronously validate data stage of ctrl out request

2018-10-17 Thread Laurent Pinchart
Hi Bin,

On Thursday, 11 October 2018 22:31:42 EEST Bin Liu wrote:
> On Tue, Oct 09, 2018 at 10:48:57PM -0400, Paul Elder wrote:
> > This patch series adds a mechanism to allow asynchronously validating
> > the data stage of a control out request, and for stalling or suceeding
> > the request accordingly. This mechanism is implemented for MUSB, and is
> > used by UVC. At the same time, UVC packages the setup stage and data
> 
> Why is this for MUSB only? Other UDC such as DWC3 doesn't need this?

Unfortunately, the asynchronous control request data stage validation 
mechanism must be implemented by every UDC. This patch series only addresses 
MUSB as this is Paul's main test platform. Once the core patches get reviewed 
and the API accepted (possibly in a modified form), we plan to update the DWC2 
and DWC3.

-- 
Regards,

Laurent Pinchart





Re: [PATCH 4/6] usb: gadget: add functions to signal udc driver to delay status stage

2018-10-17 Thread Laurent Pinchart
Hi Bin,

On Thursday, 11 October 2018 19:10:21 EEST Bin Liu wrote:
> On Tue, Oct 09, 2018 at 10:49:01PM -0400, Paul Elder wrote:
> > A usb gadget function driver may or may not want to delay the status
> > stage of a control OUT request. An instance it might want to is to
> > asynchronously validate the data of a class-specific request.
> > 
> > Add a function usb_ep_delay_status to allow function drivers to choose
> > to delay the status stage in the request completion handler. The UDC
> > should then check the usb_ep->delayed_status flag and act accordingly to
> > delay the status stage.
> > 
> > Also add a function usb_ep_send_response as a wrapper for
> > usb_ep->ops->send_response, whose prototype is added as well. This
> > function should be called by function drivers to tell the UDC what to
> > reply in the status stage that it has requested to be delayed.
> > 
> > Signed-off-by: Paul Elder 
> > Reviewed-by: Laurent Pinchart 
> > ---
> > 
> >  drivers/usb/gadget/udc/core.c | 35 +++
> >  include/linux/usb/gadget.h| 11 +++
> >  2 files changed, 46 insertions(+)
> > 
> > diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
> > index af88b48c1cea..1ec5ce6b43cd 100644
> > --- a/drivers/usb/gadget/udc/core.c
> > +++ b/drivers/usb/gadget/udc/core.c
> > @@ -443,6 +443,41 @@ void usb_ep_fifo_flush(struct usb_ep *ep)
> >  }
> >  EXPORT_SYMBOL_GPL(usb_ep_fifo_flush);
> > 
> > +/**
> > + * usb_ep_ep_delay_status - set delay_status flag
> > + * @ep: the endpoint whose delay_status flag is being set
> > + *
> > + * This function instructs the UDC to delay the status stage of a control
> > + * request. It can only be called from the request completion handler of
> > a
> > + * control request.
> > + */
> > +void usb_ep_delay_status(struct usb_ep *ep)
> > +{
> > +   ep->delayed_status = true;
> > +}
> > +EXPORT_SYMBOL_GPL(usb_ep_delay_status);
> 
> Is usb_ep_set_delay_status() better? I thought it implies get/return
> action if a verb is missing in the function name.

For what it's worth, I understand the function name as "delay the status 
stage", with "delay" being a verb. Maybe the short description could be 
updated accordingly.

-- 
Regards,

Laurent Pinchart





Re: [PATCH V2 2/6] usb: core: Add ability to skip phy exit on suspend and init on resume

2018-10-17 Thread Chunfeng Yun
hi,

On Wed, 2018-10-17 at 18:29 -0400, Al Cooper wrote:
> Add the ability to skip calling the PHY's exit routine on suspend
> and the PHY's init routine on resume. This is to handle a USB PHY
> that should have it's power_off function called on suspend but cannot
> have it's exit function called because on exit it will disable the
> PHY to the point where register accesses to the Host Controllers
> using the PHY will be disabled and the host drivers will crash.
> 
> This is enabled with the HCD flag "suspend_without_phy_exit" which
> can be set from any HCD driver.
> 
> Signed-off-by: Al Cooper 
> ---
>  drivers/usb/core/hcd.c  |  8 
>  drivers/usb/core/phy.c  | 18 --
>  drivers/usb/core/phy.h  |  9 ++---
>  include/linux/usb/hcd.h |  3 +++
>  4 files changed, 25 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index 1c21955fe7c0..e67e4d6b3d21 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -2263,7 +2263,7 @@ int hcd_bus_suspend(struct usb_device *rhdev, 
> pm_message_t msg)
>   hcd->state = HC_STATE_SUSPENDED;
>  
>   if (!PMSG_IS_AUTO(msg))
> - usb_phy_roothub_suspend(hcd->self.sysdev,
> + usb_phy_roothub_suspend(hcd,
>   hcd->phy_roothub);
>  
>   /* Did we race with a root-hub wakeup event? */
> @@ -2304,7 +2304,7 @@ int hcd_bus_resume(struct usb_device *rhdev, 
> pm_message_t msg)
>   }
>  
>   if (!PMSG_IS_AUTO(msg)) {
> - status = usb_phy_roothub_resume(hcd->self.sysdev,
> + status = usb_phy_roothub_resume(hcd,
>   hcd->phy_roothub);
>   if (status)
>   return status;
> @@ -2347,7 +2347,7 @@ int hcd_bus_resume(struct usb_device *rhdev, 
> pm_message_t msg)
>   }
>   } else {
>   hcd->state = old_state;
> - usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub);
> + usb_phy_roothub_suspend(hcd, hcd->phy_roothub);
>   dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
>   "resume", status);
>   if (status != -ESHUTDOWN)
> @@ -2744,7 +2744,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
>   struct usb_device *rhdev;
>  
>   if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
> - hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
> + hcd->phy_roothub = usb_phy_roothub_alloc(hcd);
>   if (IS_ERR(hcd->phy_roothub))
>   return PTR_ERR(hcd->phy_roothub);
>  
> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> index 9879767452a2..b54db39eee4c 100644
> --- a/drivers/usb/core/phy.c
> +++ b/drivers/usb/core/phy.c
> @@ -45,10 +45,11 @@ static int usb_phy_roothub_add_phy(struct device *dev, 
> int index,
>   return 0;
>  }
>  
> -struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
> +struct usb_phy_roothub *usb_phy_roothub_alloc(struct usb_hcd *hcd)
>  {
>   struct usb_phy_roothub *phy_roothub;
>   int i, num_phys, err;
> + struct device *dev = hcd->self.sysdev;
>  
>   if (!IS_ENABLED(CONFIG_GENERIC_PHY))
>   return NULL;
> @@ -161,26 +162,30 @@ void usb_phy_roothub_power_off(struct usb_phy_roothub 
> *phy_roothub)
>  }
>  EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off);
>  
> -int usb_phy_roothub_suspend(struct device *controller_dev,
> +int usb_phy_roothub_suspend(struct usb_hcd *hcd,
>   struct usb_phy_roothub *phy_roothub)
>  {
> + struct device *controller_dev = hcd->self.sysdev;
> +
>   usb_phy_roothub_power_off(phy_roothub);
>  
>   /* keep the PHYs initialized so the device can wake up the system */
> - if (device_may_wakeup(controller_dev))
> + if (device_may_wakeup(controller_dev) || hcd->suspend_without_phy_exit)
>   return 0;
>  
>   return usb_phy_roothub_exit(phy_roothub);
>  }
>  EXPORT_SYMBOL_GPL(usb_phy_roothub_suspend);
>  
> -int usb_phy_roothub_resume(struct device *controller_dev,
> +int usb_phy_roothub_resume(struct usb_hcd *hcd,
>  struct usb_phy_roothub *phy_roothub)
>  {
> + struct device *controller_dev = hcd->self.sysdev;
>   int err;
>  
>   /* if the device can't wake up the system _exit was called */
> - if (!device_may_wakeup(controller_dev)) {
> + if (!device_may_wakeup(controller_dev) &&
> + !hcd->suspend_without_phy_exit) {
>   err = usb_phy_roothub_init(phy_roothub);
>   if (err)
>   return err;
> @@ -189,7 +194,8 @@ int usb_phy_roothub_resume(struct device *controller_dev,
>   err = usb_phy_roothub_power_on(phy_roothub);
>  
>   /* undo _init if _power_on failed */
> - if (err && !device_may_wakeup(controller_dev))
> + if (err && !device_may_w