USB: ehci-fsl: Resume from deep sleep
cover USB: ehci-fsl: Resume from deep sleep
Hi all,
A few patches needed to support FSL EHCI resuming after deep sleep.
Without these patches MPC8315E-RDB boards hang on resume (USB PHY settings aren't preserved after deep sleep so USB controller becomes confused on resume, and hangs).
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
PATCH 1/3 powerpc/fsl: Make fsl_deep_sleep() usable w/ modules and non-83xx builds
Export is needed for modular builds, and a static inline stub is needed for non-MPC83xx builds.
--- arch/powerpc/platforms/83xx/suspend.c | 1 + include/linux/fsl_devices.h | 4 ++++ 2 files changed, 5 insertions(+), 0 deletions(-)
arch/powerpc/platforms/83xx/suspend.c +1 -0
@@ -96,6 +96,7 @@ int fsl_deep_sleep(void) {return deep_sleeping; } +EXPORT_SYMBOL (fsl_deep_sleep);static int mpc83xx_change_state (void ) {
include/linux/fsl_devices.h +4 -0
@@ -90,6 +90,10 @@ struct mpc8xx_pcmcia_ops {* lead to a deep sleep (i.e. power removed from the core, * instead of just the clock). */ +#if defined(CONFIG_PPC_83xx) && defined(CONFIG_SUSPEND )int fsl_deep_sleep (void ); +#else +static inline int fsl_deep_sleep (void ) {return 0 ; } +#endif #endif /* _FSL_DEVICE_H_ */
Signature · 1 line
1.6.3.3
PATCH 2/3 USB: ehci-fsl: Fix sparse warnings
In reply to Anton VorontsovThis patch fixes following warnings:
ehci-fsl.c:43:5: warning: symbol 'usb_hcd_fsl_probe' was not declared. Should it be static? ehci-fsl.c:150:6: warning: symbol 'usb_hcd_fsl_remove' was not declared. Should it be static?
--- drivers/usb/host/ehci-fsl.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/usb/host/ehci-fsl.c +4 -3
@@ -40,8 +40,8 @@* Allocates basic resources for this USB host controller. * */ -int usb_hcd_fsl_probe (const struct hc_driver *driver, -struct platform_device *pdev) +static int usb_hcd_fsl_probe (const struct hc_driver *driver, +struct platform_device *pdev) {struct fsl_usb2_platform_data *pdata;struct usb_hcd *hcd;
@@ -147,7 +147,8 @@ int usb_hcd_fsl_probe(const struct hc_driver *driver,* Reverses the effect of usb_hcd_fsl_probe(). * */ -void usb_hcd_fsl_remove (struct usb_hcd *hcd,struct platform_device *pdev) +static void usb_hcd_fsl_remove (struct usb_hcd *hcd, +struct platform_device *pdev) {usb_remove_hcd (hcd);iounmap (hcd->regs);
Signature · 1 line
1.6.3.3
PATCH 3/3 USB: ehci-fsl: Add power management support (resume after deep sleep)
In reply to Anton VorontsovEHCI FSL controller preserve its state during sleep mode, so nothing fancy needs to be done.
Though, during 'deep sleep' mode (as found in MPC831x CPUs) the controller turns off and needs to be reinitialized upon resume.
This patch adds support for resuming after deep sleep. Based on Dave Liu and Jerry Huang's work.
--- drivers/usb/host/ehci-fsl.c | 88 +++++++++++++++++++++++++++++++++++++++--- 1 files changed, 81 insertions(+), 7 deletions(-)
drivers/usb/host/ehci-fsl.c +81 -7
@@ -1,5 +1,6 @@/* -* Copyright (c) 2005 MontaVista Software +* Copyright 2005-2009 MontaVista Software, Inc. +* Copyright 2008 Freescale Semiconductor, Inc. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the
@@ -17,17 +18,18 @@* * Ported to 834x by Randy Vinson <[email protected]> using code provided * by Hunter Wu. +* Power Management support by Dave Liu <[email protected]> and +* Jerry Huang <[email protected]>. */ +#include <linux/kernel.h> +#include <linux/types.h> +#include <linux/delay.h> #include <linux/platform_device.h> #include <linux/fsl_devices.h> #include "ehci-fsl.h" -/* FIXME: Power Management is un-ported so temporarily disable it */ -#undef CONFIG_PM - -/* configure so an HC device and id are always provided */ /* always called with process context; sleeping is OK */
@@ -285,10 +287,81 @@ static int ehci_fsl_setup(struct usb_hcd *hcd)return retval; } +#ifdef CONFIG_SUSPEND +struct ehci_fsl { +struct ehci_hcd ehci; + +/* Saved USB PHY settings, need to restore after deep sleep. */ +u32 usb_ctrl; +}; + +static struct ehci_fsl *hcd_to_ehci_fsl (struct usb_hcd *hcd) +{ +struct ehci_hcd *ehci =hcd_to_ehci (hcd); + + return container_of(ehci, struct ehci_fsl, ehci); +} + +static int ehci_fsl_drv_suspend (struct device *dev) +{ +struct usb_hcd *hcd =dev_get_drvdata (dev); +struct ehci_fsl *ehci_fsl =hcd_to_ehci_fsl (hcd); +void __iomem *non_ehci = hcd->regs; + +if (!fsl_deep_sleep ()) +return 0 ; + + ehci_fsl->usb_ctrl =in_be32 (non_ehci +FSL_SOC_USB_CTRL ); +return 0 ; +} + +static int ehci_fsl_drv_resume (struct device *dev) +{ +struct usb_hcd *hcd =dev_get_drvdata (dev); +struct ehci_fsl *ehci_fsl =hcd_to_ehci_fsl (hcd); +struct ehci_hcd *ehci =hcd_to_ehci (hcd); +void __iomem *non_ehci = hcd->regs; +int port_nm; + +if (!fsl_deep_sleep ()) +return 0 ; + +/* Restore USB PHY settings and enable the controller. */ +out_be32 (non_ehci +FSL_SOC_USB_CTRL , ehci_fsl->usb_ctrl); + +ehci_reset (ehci); +ehci_fsl_reinit (ehci); + +/* Power up ports (avoids devices disconnect). */ + port_nm =HCS_N_PORTS (ehci->hcs_params); +while (port_nm--) { +u32 port_sc; + + port_sc =ehci_readl (ehci, &ehci->regs->port_status[port_nm]); + port_sc |=PORT_POWER ; +ehci_writel (ehci, port_sc, &ehci->regs->port_status[port_nm]); + } +mdelay (30 ); + +return 0 ; +} + +static struct dev_pm_ops ehci_fsl_pm_ops = { + .suspend = ehci_fsl_drv_suspend, + .resume = ehci_fsl_drv_resume, +}; + +#define EHCI_FSL_PRIV_SIZE sizeof(struct ehci_fsl) +#define EHCI_FSL_PM_OPS (&ehci_fsl_pm_ops) +#else +#define EHCI_FSL_PRIV_SIZE sizeof(struct ehci_hcd) +#define EHCI_FSL_PM_OPS NULL +#endif /* CONFIG_SUSPEND */ +static const struct hc_driver ehci_fsl_hc_driver = { .description = hcd_name, .product_desc ="Freescale On-Chip EHCI Host Controller" , - .hcd_priv_size =sizeof (struct ehci_hcd ), + .hcd_priv_size =EHCI_FSL_PRIV_SIZE ,/* * generic hardware linkage
@@ -355,6 +428,7 @@ static struct platform_driver ehci_fsl_driver = { .remove = ehci_fsl_drv_remove, .shutdown = usb_hcd_platform_shutdown, .driver = { - .name = "fsl-ehci", + .name = "fsl-ehci", + .pm = EHCI_FSL_PM_OPS, }, };
Signature · 1 line
1.6.3.3
Re: [PATCH 3/3] USB: ehci-fsl: Add power management support (resume after deep sleep)
On Wed, Sep 23, 2009 at 10:52:44PM +0400, Anton Vorontsov wrote:
+#ifdef CONFIG_SUSPEND
+struct ehci_fsl {
+ struct ehci_hcd ehci;
+
+ /* Saved USB PHY settings, need to restore after deep sleep. */
+ u32 usb_ctrl;
+};
This doesn't seem like the right place to define this... what if we later need something else that isn't for suspend? And you could get rid of EHCI_FSL_PRIV_SIZE.
drivers/usb/host/ehci-fsl.c static int ehci_fsl_setup(struct usb_hcd *hcd) · line 312
Quoted 8 lines
drivers/usb/host/ehci-fsl.c +8
-0+static int ehci_fsl_drv_suspend (struct device *dev) +{ +struct usb_hcd *hcd =dev_get_drvdata (dev); +struct ehci_fsl *ehci_fsl =hcd_to_ehci_fsl (hcd); +void __iomem *non_ehci = hcd->regs; + +if (!fsl_deep_sleep ()) +return 0 ;
We'll also need to do this if we support suspend to disk... is there any good way for the driver to determine that that's what's being done? Or more generally, for the platform to communicate to the drivers which ones are going to lose state without one-off hacks like fsl_deep_sleep().
drivers/usb/host/ehci-fsl.c static int ehci_fsl_setup(struct usb_hcd *hcd) · line 344
Quoted 10 lines
drivers/usb/host/ehci-fsl.c +10
-0+/* Power up ports (avoids devices disconnect). */ + port_nm =HCS_N_PORTS (ehci->hcs_params); +while (port_nm--) { +u32 port_sc; + + port_sc =ehci_readl (ehci, &ehci->regs->port_status[port_nm]); + port_sc |=PORT_POWER ; +ehci_writel (ehci, port_sc, &ehci->regs->port_status[port_nm]); + } +mdelay (30 );
Instead of mdelay, can we somehow hold off any USB operations for a while?
-Scott
Kumar Gala
AppliedRe: [PATCH 1/3] powerpc/fsl: Make fsl_deep_sleep() usable w/ modules and non-83xx builds
In reply to Anton VorontsovQuoted 8 lines · Anton Vorontsov
Export is needed for modular builds, and a static inline stub is needed for non-MPC83xx builds.
Signed-off-by Anton Vorontsov <[email protected]>---
arch/powerpc/platforms/83xx/suspend.c | 1 + include/linux/fsl_devices.h | 4 ++++ 2 files changed, 5 insertions(+), 0 deletions(-)
applied to next
- k