fsl/usb: Workarourd for USB erratum-A005697
Subsystems (2)
PATCH v3 1/1 fsl/usb: Workarourd for USB erratum-A005697
The EHCI specification states the following in the SUSP bit description:
In the Suspend state, the port is sensitive to resume detection. Note that the bit status does not change until the port is suspended and that there may be a delay in suspending a port if there is a transaction currently in progress on the USB.
However, in NXP USBDR controller, the PORTSCx[SUSP] bit changes immediately when the application sets it and not when the port is actually suspended.
So the application must wait for at least 10 milliseconds after a port indicates that it is suspended, to make sure this port has entered suspended state before initiating this port resume using the Force Port Resume bit. This bit is for NXP controller, not EHCI compatible.
---
Changes in v3:
- add 10ms delay in function ehci_hub_control
- fix typos
Changes in v2:
- move sleep out of spin-lock
- add more comment for this workaround
drivers/usb/host/ehci-fsl.c | 3 +++ drivers/usb/host/ehci-hub.c | 11 +++++++++++ drivers/usb/host/ehci.h | 8 ++++++++ drivers/usb/host/fsl-mph-dr-of.c | 2 ++ include/linux/fsl_devices.h | 1 + 5 files changed, 25 insertions(+)
drivers/usb/host/ehci-fsl.c +3 -0
@@ -286,6 +286,9 @@ static int ehci_fsl_usb_setup(struct ehci_hcd *ehci)if (pdata->has_fsl_erratum_a005275 ==1 ) ehci->has_fsl_hs_errata =1 ; +if (pdata->has_fsl_erratum_a005697 ==1 ) + ehci->has_fsl_susp_errata =1 ; +if ((pdata->operating_mode ==FSL_USB2_DR_HOST ) || (pdata->operating_mode ==FSL_USB2_DR_OTG ))if (ehci_fsl_setup_phy (hcd, pdata->phy_mode,0 ))
drivers/usb/host/ehci-hub.c +11 -0
@@ -310,6 +310,14 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) }spin_unlock_irq (&ehci->lock); +if (changed &&ehci_has_fsl_susp_errata (ehci)) +/* +* Wait for at least 10 millisecondes to ensure the controller +* enter the suspend status before initiating a port resume +* using the Force Port Resume bit (Not-EHCI compatible). +*/ +usleep_range (10000 ,20000 ); +if ((changed && ehci->has_tdi_phy_lpm) || fs_idle_delay) {/* * Wait for HCD to enter low-power mode or for the bus
@@ -1200,6 +1208,9 @@ int ehci_hub_control( wIndex, (temp1 &HOSTPC_PHCD ) ? "succeeded" : "failed"); } +if (ehci_has_fsl_susp_errata (ehci)) +/* 10ms for HCD enter suspend */ +usleep_range (10000 ,20000 );set_bit (wIndex, &ehci->suspended_ports);break ;case USB_PORT_FEAT_POWER :
drivers/usb/host/ehci.h +8 -0
@@ -219,6 +219,7 @@ struct ehci_hcd { /* one per controller */ unsigned no_selective_suspend:1; unsigned has_fsl_port_bug:1; /* FreeScale */ unsigned has_fsl_hs_errata:1; /* Freescale HS quirk */ + unsigned has_fsl_susp_errata:1; /* NXP SUSP quirk */ unsigned big_endian_mmio:1; unsigned big_endian_desc:1; unsigned big_endian_capbase:1;
@@ -710,6 +711,13 @@ struct ehci_tt {#endif /* +* Some Freescale/NXP processors have an erratum (USB A-005697) +* in which we need to wait for 10ms for bus to enter suspend mode +* after setting SUSP bit. +*/ +#define ehci_has_fsl_susp_errata (e) ((e)->has_fsl_susp_errata) + +/* * While most USB host controllers implement their registers in * little-endian format, a minority (celleb companion chip) implement * them in big endian format.
drivers/usb/host/fsl-mph-dr-of.c +2 -0
@@ -226,6 +226,8 @@ static int fsl_usb2_mph_dr_of_probe(struct platform_device *ofdev)of_property_read_bool (np,"fsl,usb-erratum-a007792" ); pdata->has_fsl_erratum_a005275 =of_property_read_bool (np,"fsl,usb-erratum-a005275" ); + pdata->has_fsl_erratum_a005697 = +of_property_read_bool (np,"fsl,usb_erratum-a005697" );/* * Determine whether phy_clk_valid needs to be checked
include/linux/fsl_devices.h +1 -0
@@ -100,6 +100,7 @@ struct fsl_usb2_platform_data { unsigned already_suspended:1; unsigned has_fsl_erratum_a007792:1; unsigned has_fsl_erratum_a005275:1; + unsigned has_fsl_erratum_a005697:1; unsigned check_phy_clk_valid:1;/* register save area for suspend/resume */
Signature · 1 line
1.7.9.5
Alan Stern
maintainerQuoted 42 lines · Changming Huang
The EHCI specification states the following in the SUSP bit description:
In the Suspend state, the port is sensitive to resume detection. Note that the bit status does not change until the port is suspended and that there may be a delay in suspending a port if there is a transaction currently in progress on the USB.However, in NXP USBDR controller, the PORTSCx[SUSP] bit changes immediately when the application sets it and not when the port is actually suspended.
So the application must wait for at least 10 milliseconds after a port indicates that it is suspended, to make sure this port has entered suspended state before initiating this port resume using the Force Port Resume bit. This bit is for NXP controller, not EHCI compatible.
Signed-off-by Changming Huang <[email protected]>Signed-off-by Ramneek Mehresh <[email protected]>---
Changes in v3:
- add 10ms delay in functionehci_hub_control
- fix typos
Changes in v2:
- move sleep out of spin-lock
- add more comment for this workarounddrivers/usb/host/ehci-hub.c +8
-0@@ -310,6 +310,14 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) }spin_unlock_irq (&ehci->lock); +if (changed &&ehci_has_fsl_susp_errata (ehci)) +/* +* Wait for at least 10 millisecondes to ensure the controller +* enter the suspend status before initiating a port resume +* using the Force Port Resume bit (Not-EHCI compatible). +*/ +usleep_range (10000 ,20000 ); +if ((changed && ehci->has_tdi_phy_lpm) || fs_idle_delay) {/* * Wait for HCD to enter low-power mode or for the bus
drivers/usb/host/ehci-hub.c int ehci_hub_control( · line 1215
Quoted 8 lines
drivers/usb/host/ehci-hub.c +3
-0@@ -1200,6 +1208,9 @@ int ehci_hub_control( wIndex, (temp1 &HOSTPC_PHCD ) ? "succeeded" : "failed"); } +if (ehci_has_fsl_susp_errata (ehci)) +/* 10ms for HCD enter suspend */ +usleep_range (10000 ,20000 );set_bit (wIndex, &ehci->suspended_ports);break ;
Just like before, you have to release the spinlock before sleeping. Look at the code 10 lines above this.
Alan Stern
Thanks a lot, Alan.
That is my fault, will fix it and send one new version.
Best Regards
Jerry Huang
-----Original Message-----
From: Alan Stern [mailto:[email protected]]
Sent: Monday, November 28, 2016 11:58 PM
To: Jerry Huang <[email protected]>
Cc: [email protected]; Ramneek Mehresh <[email protected]>; [email protected]; Sriram Dash <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v3] fsl/usb: Workarourd for USB erratum-A005697
Quoted 40 lines · Changming Huang
The EHCI specification states the following in the SUSP bit description:
In the Suspend state, the port is sensitive to resume detection. Note that the bit status does not change until the port is suspended and that there may be a delay in suspending a port if there is a transaction currently in progress on the USB.However, in NXP USBDR controller, the PORTSCx[SUSP] bit changes immediately when the application sets it and not when the port is actually suspended.
So the application must wait for at least 10 milliseconds after a port indicates that it is suspended, to make sure this port has entered suspended state before initiating this port resume using the Force Port Resume bit. This bit is for NXP controller, not EHCI compatible.
Signed-off-by Changming Huang <[email protected]>Signed-off-by Ramneek Mehresh <[email protected]>---
Changes in v3:
- add 10ms delay in functionehci_hub_control
- fix typos
Changes in v2:
- move sleep out of spin-lock
- add more comment for this workarounddrivers/usb/host/ehci-hub.c +8
-0@@ -310,6 +310,14 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) }spin_unlock_irq (&ehci->lock); +if (changed &&ehci_has_fsl_susp_errata (ehci)) +/* +* Wait for at least 10 millisecondes to ensure the controller +* enter the suspend status before initiating a port resume +* using the Force Port Resume bit (Not-EHCI compatible). +*/ +usleep_range (10000 ,20000 ); +if ((changed && ehci->has_tdi_phy_lpm) || fs_idle_delay) {/*
drivers/usb/host/ehci-hub.c static int ehci_bus_suspend (struct usb_hcd *hcd)
Quoted 10 lines
drivers/usb/host/ehci-hub.c +4
-0* Wait for HCD to enter low-power mode or for the bus @@ -1200,6 +1208,9 @@ int ehci_hub_control( wIndex, (temp1 & HOSTPC_PHCD) ? "succeeded" : "failed"); } +if (ehci_has_fsl_susp_errata (ehci)) +/* 10ms for HCD enter suspend */ +usleep_range (10000 ,20000 );set_bit (wIndex, &ehci->suspended_ports);break ;
Just like before, you have to release the spinlock before sleeping. Look at the code 10 lines above this.
Alan Stern