[PATCH] fsl/ehci: fix failure of checking PHY_CLK_VALID during reinitialization

2013-09-01 Thread Shengzhou Liu
In case of usb phy reinitialization:
e.g. insmod usb-module(usb works well) -> rmmod usb-module -> insmod usb-module
It found the PHY_CLK_VALID bit didn't work if it's not with the power-on reset.
So we just check PHY_CLK_VALID bit during the stage with POR, this can be met
by the tricky of checking FSL_SOC_USB_PRICTRL register.

Signed-off-by: Shengzhou Liu 
---
based on master branch of upstream, from sdk1.4

 drivers/usb/host/ehci-fsl.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index bd831ec..3156e12 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -270,8 +270,9 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
if (pdata->have_sysif_regs && pdata->controller_ver &&
(phy_mode == FSL_USB2_PHY_ULPI)) {
/* check PHY_CLK_VALID to get phy clk valid */
-   if (!spin_event_timeout(in_be32(non_ehci + FSL_SOC_USB_CTRL) &
-   PHY_CLK_VALID, FSL_USB_PHY_CLK_TIMEOUT, 0)) {
+   if (!(spin_event_timeout(in_be32(non_ehci + FSL_SOC_USB_CTRL) &
+   PHY_CLK_VALID, FSL_USB_PHY_CLK_TIMEOUT, 0) ||
+   in_be32(non_ehci + FSL_SOC_USB_PRICTRL))) {
printk(KERN_WARNING "fsl-ehci: USB PHY clock 
invalid\n");
return -EINVAL;
}
-- 
1.7.0.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 v3] powerpc/usb: fix bug of CPU hang when missing USB PHY clock

2012-09-18 Thread Shengzhou Liu
when missing USB PHY clock, kernel booting up will hang during USB
initialization. We should check USBGP[PHY_CLK_VALID] bit to avoid
CPU hanging in this case.

Signed-off-by: Shengzhou Liu 
---
v3 change: no check for UTMI PHY.
v2 change: use spin_event_timeout() instead.

 drivers/usb/host/ehci-fsl.c |   57 +-
 drivers/usb/host/ehci-fsl.h |1 +
 include/linux/fsl_devices.h |1 +
 3 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index b7451b2..9bfde82 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -210,11 +210,11 @@ static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
usb_put_hcd(hcd);
 }
 
-static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
+static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
   enum fsl_usb2_phy_modes phy_mode,
   unsigned int port_offset)
 {
-   u32 portsc, temp;
+   u32 portsc;
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
void __iomem *non_ehci = hcd->regs;
struct device *dev = hcd->self.controller;
@@ -232,9 +232,15 @@ static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
case FSL_USB2_PHY_ULPI:
if (pdata->controller_ver) {
/* controller version 1.6 or above */
-   temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
-   out_be32(non_ehci + FSL_SOC_USB_CTRL, temp |
-   USB_CTRL_USB_EN | ULPI_PHY_CLK_SEL);
+   setbits32(non_ehci + FSL_SOC_USB_CTRL,
+   ULPI_PHY_CLK_SEL);
+   /*
+* Due to controller issue of PHY_CLK_VALID in ULPI
+* mode, we set USB_CTRL_USB_EN before checking
+* PHY_CLK_VALID, otherwise PHY_CLK_VALID doesn't work.
+*/
+   clrsetbits_be32(non_ehci + FSL_SOC_USB_CTRL,
+   UTMI_PHY_EN, USB_CTRL_USB_EN);
}
portsc |= PORT_PTS_ULPI;
break;
@@ -247,9 +253,7 @@ static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
case FSL_USB2_PHY_UTMI:
if (pdata->controller_ver) {
/* controller version 1.6 or above */
-   temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
-   out_be32(non_ehci + FSL_SOC_USB_CTRL, temp |
-   UTMI_PHY_EN | USB_CTRL_USB_EN);
+   setbits32(non_ehci + FSL_SOC_USB_CTRL, UTMI_PHY_EN);
mdelay(FSL_UTMI_PHY_DLY);  /* Delay for UTMI PHY CLK to
become stable - 10ms*/
}
@@ -262,23 +266,33 @@ static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
case FSL_USB2_PHY_NONE:
break;
}
+
+   if (pdata->controller_ver && (phy_mode == FSL_USB2_PHY_ULPI)) {
+   /* check PHY_CLK_VALID to get phy clk valid */
+   if (!spin_event_timeout(in_be32(non_ehci + FSL_SOC_USB_CTRL) &
+   PHY_CLK_VALID, FSL_USB_PHY_CLK_TIMEOUT, 0)) {
+   printk(KERN_WARNING "fsl-ehci: USB PHY clock 
invalid\n");
+   return -EINVAL;
+   }
+   }
+
ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]);
+
+   if (phy_mode != FSL_USB2_PHY_ULPI)
+   setbits32(non_ehci + FSL_SOC_USB_CTRL, USB_CTRL_USB_EN);
+
+   return 0;
 }
 
-static void ehci_fsl_usb_setup(struct ehci_hcd *ehci)
+static int ehci_fsl_usb_setup(struct ehci_hcd *ehci)
 {
struct usb_hcd *hcd = ehci_to_hcd(ehci);
struct fsl_usb2_platform_data *pdata;
void __iomem *non_ehci = hcd->regs;
-   u32 temp;
 
pdata = hcd->self.controller->platform_data;
 
-   /* Enable PHY interface in the control reg. */
if (pdata->have_sysif_regs) {
-   temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
-   out_be32(non_ehci + FSL_SOC_USB_CTRL, temp | 0x0004);
-
/*
* Turn on cache snooping hardware, since some PowerPC platforms
* wholly rely on hardware to deal with cache coherent
@@ -293,7 +307,8 @@ static void ehci_fsl_usb_setup(struct ehci_hcd *ehci)
 
if ((pdata->operating_mode == FSL_USB2_DR_HOST) ||
(pdata->operating_mode == FSL_USB2_DR_OTG))
-   ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0);
+   if (ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0))
+   return -EINVAL;
 
if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
unsigned int chip, rev, svr;
@@ -307,9 +322,12 @@ sta

[PATCH] powerpc/usb: remove checking PHY_CLK_VALID for UTMI PHY

2012-09-24 Thread Shengzhou Liu
PHY_CLK_VALID bit doesn't work properly with UTMI PHY.
e.g. This bit is always zero on P5040, etc.
There is no need to check this bit for UTMI PHY, just keep
checking for ULPI PHY to prevent system hanging.

This patch should be squashed into previous commit 3735ba8db8e6e
"powerpc/usb: fix bug of CPU hang when missing USB PHY clock"

Signed-off-by: Shengzhou Liu 
---
 drivers/usb/host/ehci-fsl.c |3 +--
 include/linux/fsl_devices.h |2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 11ff4b4..9bfde82 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -267,8 +267,7 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
break;
}
 
-   if ((pdata->controller_ver) && ((phy_mode == FSL_USB2_PHY_ULPI) ||
-   (phy_mode == FSL_USB2_PHY_UTMI))) {
+   if (pdata->controller_ver && (phy_mode == FSL_USB2_PHY_ULPI)) {
/* check PHY_CLK_VALID to get phy clk valid */
if (!spin_event_timeout(in_be32(non_ehci + FSL_SOC_USB_CTRL) &
PHY_CLK_VALID, FSL_USB_PHY_CLK_TIMEOUT, 0)) {
diff --git a/include/linux/fsl_devices.h b/include/linux/fsl_devices.h
index ccfc4bb..700bf31 100644
--- a/include/linux/fsl_devices.h
+++ b/include/linux/fsl_devices.h
@@ -19,7 +19,7 @@
 
 #define FSL_UTMI_PHY_DLY   10  /*As per P1010RM, delay for UTMI
PHY CLK to become stable - 10ms*/
-#define FSL_USB_PHY_CLK_TIMEOUT1000/* uSec */
+#define FSL_USB_PHY_CLK_TIMEOUT1   /* uSec */
 #define FSL_USB_VER_OLD0
 #define FSL_USB_VER_1_61
 #define FSL_USB_VER_2_22
-- 
1.6.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 1/2] powerpc/p4080ds: dts - add usb controller version info and port0

2012-08-10 Thread Shengzhou Liu
Add the missing usb controller version info and port0, which is
required during setup usb phy.

Signed-off-by: Shengzhou Liu 
---
 arch/powerpc/boot/dts/fsl/p4080si-post.dtsi |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/boot/dts/fsl/p4080si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/p4080si-post.dtsi
index 8d35d2c..4f9c9f6 100644
--- a/arch/powerpc/boot/dts/fsl/p4080si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/p4080si-post.dtsi
@@ -345,6 +345,13 @@
 /include/ "qoriq-duart-1.dtsi"
 /include/ "qoriq-gpio-0.dtsi"
 /include/ "qoriq-usb2-mph-0.dtsi"
+   usb@21 {
+   compatible = "fsl-usb2-mph-v1.6", "fsl,mpc85xx-usb2-mph", 
"fsl-usb2-mph";
+   port0;
+   };
 /include/ "qoriq-usb2-dr-0.dtsi"
+   usb@211000 {
+   compatible = "fsl-usb2-dr-v1.6", "fsl,mpc85xx-usb2-dr", 
"fsl-usb2-dr";
+   };
 /include/ "qoriq-sec4.0-0.dtsi"
 };
-- 
1.6.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 2/2] powerpc/usb: fix bug of CPU hang when missing USB PHY clock

2012-08-10 Thread Shengzhou Liu
when missing USB PHY clock, kernel booting up will hang during USB
initialization. We should check USBGP[PHY_CLK_VALID] bit to avoid
CPU hanging in this case.

Signed-off-by: Shengzhou Liu 
---
 drivers/usb/host/ehci-fsl.c |   63 ++
 drivers/usb/host/ehci-fsl.h |1 +
 2 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index b7451b2..aeb6d03 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -210,11 +210,11 @@ static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
usb_put_hcd(hcd);
 }
 
-static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
+static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
   enum fsl_usb2_phy_modes phy_mode,
   unsigned int port_offset)
 {
-   u32 portsc, temp;
+   u32 portsc, timeout;
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
void __iomem *non_ehci = hcd->regs;
struct device *dev = hcd->self.controller;
@@ -232,9 +232,15 @@ static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
case FSL_USB2_PHY_ULPI:
if (pdata->controller_ver) {
/* controller version 1.6 or above */
-   temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
-   out_be32(non_ehci + FSL_SOC_USB_CTRL, temp |
-   USB_CTRL_USB_EN | ULPI_PHY_CLK_SEL);
+   setbits32(non_ehci + FSL_SOC_USB_CTRL,
+   ULPI_PHY_CLK_SEL);
+   /*
+* Due to controller issue of PHY_CLK_VALID in ULPI
+* mode, we set USB_CTRL_USB_EN before checking
+* PHY_CLK_VALID, otherwise PHY_CLK_VALID doesn't work.
+*/
+   clrsetbits_be32(non_ehci + FSL_SOC_USB_CTRL,
+   UTMI_PHY_EN, USB_CTRL_USB_EN);
}
portsc |= PORT_PTS_ULPI;
break;
@@ -247,9 +253,7 @@ static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
case FSL_USB2_PHY_UTMI:
if (pdata->controller_ver) {
/* controller version 1.6 or above */
-   temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
-   out_be32(non_ehci + FSL_SOC_USB_CTRL, temp |
-   UTMI_PHY_EN | USB_CTRL_USB_EN);
+   setbits32(non_ehci + FSL_SOC_USB_CTRL, UTMI_PHY_EN);
mdelay(FSL_UTMI_PHY_DLY);  /* Delay for UTMI PHY CLK to
become stable - 10ms*/
}
@@ -262,23 +266,39 @@ static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
case FSL_USB2_PHY_NONE:
break;
}
+
+   if ((pdata->controller_ver) && ((phy_mode == FSL_USB2_PHY_ULPI) ||
+   (phy_mode == FSL_USB2_PHY_UTMI))) {
+   for (timeout = 1000; timeout > 0; timeout--) {
+   /* check PHY_CLK_VALID to get phy clk valid */
+   if (in_be32(non_ehci + FSL_SOC_USB_CTRL)
+   & PHY_CLK_VALID)
+   break;
+   udelay(1);
+   }
+   if (timeout == 0) {
+   printk(KERN_WARNING "fsl-ehci: USB PHY clock 
invalid\n");
+   return -EINVAL;
+   }
+   }
+
ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]);
+
+   if (phy_mode != FSL_USB2_PHY_ULPI)
+   setbits32(non_ehci + FSL_SOC_USB_CTRL, USB_CTRL_USB_EN);
+
+   return 0;
 }
 
-static void ehci_fsl_usb_setup(struct ehci_hcd *ehci)
+static int ehci_fsl_usb_setup(struct ehci_hcd *ehci)
 {
struct usb_hcd *hcd = ehci_to_hcd(ehci);
struct fsl_usb2_platform_data *pdata;
void __iomem *non_ehci = hcd->regs;
-   u32 temp;
 
pdata = hcd->self.controller->platform_data;
 
-   /* Enable PHY interface in the control reg. */
if (pdata->have_sysif_regs) {
-   temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
-   out_be32(non_ehci + FSL_SOC_USB_CTRL, temp | 0x0004);
-
/*
* Turn on cache snooping hardware, since some PowerPC platforms
* wholly rely on hardware to deal with cache coherent
@@ -293,7 +313,8 @@ static void ehci_fsl_usb_setup(struct ehci_hcd *ehci)
 
if ((pdata->operating_mode == FSL_USB2_DR_HOST) ||
(pdata->operating_mode == FSL_USB2_DR_OTG))
-   ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0);
+   if (ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0))
+   return -EINVAL;
 
if (pdata

[PATCH v2] powerpc/usb: fix bug of CPU hang when missing USB PHY clock

2012-08-22 Thread Shengzhou Liu
when missing USB PHY clock, kernel booting up will hang during USB
initialization. We should check USBGP[PHY_CLK_VALID] bit to avoid
CPU hanging in this case.

Signed-off-by: Shengzhou Liu 
---
v2 changes: use spin_event_timeout() instead.

 drivers/usb/host/ehci-fsl.c |   58 +-
 drivers/usb/host/ehci-fsl.h |1 +
 include/linux/fsl_devices.h |1 +
 3 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index b7451b2..11ff4b4 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -210,11 +210,11 @@ static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
usb_put_hcd(hcd);
 }
 
-static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
+static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
   enum fsl_usb2_phy_modes phy_mode,
   unsigned int port_offset)
 {
-   u32 portsc, temp;
+   u32 portsc;
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
void __iomem *non_ehci = hcd->regs;
struct device *dev = hcd->self.controller;
@@ -232,9 +232,15 @@ static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
case FSL_USB2_PHY_ULPI:
if (pdata->controller_ver) {
/* controller version 1.6 or above */
-   temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
-   out_be32(non_ehci + FSL_SOC_USB_CTRL, temp |
-   USB_CTRL_USB_EN | ULPI_PHY_CLK_SEL);
+   setbits32(non_ehci + FSL_SOC_USB_CTRL,
+   ULPI_PHY_CLK_SEL);
+   /*
+* Due to controller issue of PHY_CLK_VALID in ULPI
+* mode, we set USB_CTRL_USB_EN before checking
+* PHY_CLK_VALID, otherwise PHY_CLK_VALID doesn't work.
+*/
+   clrsetbits_be32(non_ehci + FSL_SOC_USB_CTRL,
+   UTMI_PHY_EN, USB_CTRL_USB_EN);
}
portsc |= PORT_PTS_ULPI;
break;
@@ -247,9 +253,7 @@ static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
case FSL_USB2_PHY_UTMI:
if (pdata->controller_ver) {
/* controller version 1.6 or above */
-   temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
-   out_be32(non_ehci + FSL_SOC_USB_CTRL, temp |
-   UTMI_PHY_EN | USB_CTRL_USB_EN);
+   setbits32(non_ehci + FSL_SOC_USB_CTRL, UTMI_PHY_EN);
mdelay(FSL_UTMI_PHY_DLY);  /* Delay for UTMI PHY CLK to
become stable - 10ms*/
}
@@ -262,23 +266,34 @@ static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
case FSL_USB2_PHY_NONE:
break;
}
+
+   if ((pdata->controller_ver) && ((phy_mode == FSL_USB2_PHY_ULPI) ||
+   (phy_mode == FSL_USB2_PHY_UTMI))) {
+   /* check PHY_CLK_VALID to get phy clk valid */
+   if (!spin_event_timeout(in_be32(non_ehci + FSL_SOC_USB_CTRL) &
+   PHY_CLK_VALID, FSL_USB_PHY_CLK_TIMEOUT, 0)) {
+   printk(KERN_WARNING "fsl-ehci: USB PHY clock 
invalid\n");
+   return -EINVAL;
+   }
+   }
+
ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]);
+
+   if (phy_mode != FSL_USB2_PHY_ULPI)
+   setbits32(non_ehci + FSL_SOC_USB_CTRL, USB_CTRL_USB_EN);
+
+   return 0;
 }
 
-static void ehci_fsl_usb_setup(struct ehci_hcd *ehci)
+static int ehci_fsl_usb_setup(struct ehci_hcd *ehci)
 {
struct usb_hcd *hcd = ehci_to_hcd(ehci);
struct fsl_usb2_platform_data *pdata;
void __iomem *non_ehci = hcd->regs;
-   u32 temp;
 
pdata = hcd->self.controller->platform_data;
 
-   /* Enable PHY interface in the control reg. */
if (pdata->have_sysif_regs) {
-   temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
-   out_be32(non_ehci + FSL_SOC_USB_CTRL, temp | 0x0004);
-
/*
* Turn on cache snooping hardware, since some PowerPC platforms
* wholly rely on hardware to deal with cache coherent
@@ -293,7 +308,8 @@ static void ehci_fsl_usb_setup(struct ehci_hcd *ehci)
 
if ((pdata->operating_mode == FSL_USB2_DR_HOST) ||
(pdata->operating_mode == FSL_USB2_DR_OTG))
-   ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0);
+   if (ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0))
+   return -EINVAL;
 
if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
unsigned int chip, rev,

[PATCH] usb: remove redundant tdi_reset

2013-04-17 Thread Shengzhou Liu
We remove the redundant tdi_reset in ehci_setup since there
is already it in ehci_reset.
It was observed that the duplicated tdi_reset was causing
the PHY_CLK_VALID bit unstable.

Signed-off-by: Shengzhou Liu 
---
 drivers/usb/host/ehci-hcd.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 416a6dc..83b5a17 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -670,9 +670,6 @@ int ehci_setup(struct usb_hcd *hcd)
if (retval)
return retval;
 
-   if (ehci_is_TDI(ehci))
-   tdi_reset(ehci);
-
ehci_reset(ehci);
 
return 0;
-- 
1.7.0.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