Commit 2e2aa1bc authored by Wenyou Yang's avatar Wenyou Yang Committed by Greg Kroah-Hartman

usb: ohci-at91: Forcibly suspend ports while USB suspend

The usb controller does not manage correctly the suspend mode for
the ehci. In echi mode, there is no way to suspend without any
device connected to it. This is why this specific control is added
to fix this issue. Since the suspend mode works in ohci mode, this
specific control works by suspend the usb controller in ohci mode.

This specific control is by setting the SUSPEND_A/B/C fields of
SFR_OHCIICR(OHCI Interrupt Configuration Register) in the SFR
while the OHCI USB suspend.

This set operation must be done before the USB clock disabled,
clear operation after the USB clock enabled.
Signed-off-by: default avatarWenyou Yang <wenyou.yang@atmel.com>
Reviewed-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: default avatarNicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fc8b690d
...@@ -21,8 +21,11 @@ ...@@ -21,8 +21,11 @@
#include <linux/io.h> #include <linux/io.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mfd/syscon.h>
#include <linux/regmap.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/usb/hcd.h> #include <linux/usb/hcd.h>
#include <soc/at91/atmel-sfr.h>
#include "ohci.h" #include "ohci.h"
...@@ -51,6 +54,7 @@ struct ohci_at91_priv { ...@@ -51,6 +54,7 @@ struct ohci_at91_priv {
struct clk *hclk; struct clk *hclk;
bool clocked; bool clocked;
bool wakeup; /* Saved wake-up state for resume */ bool wakeup; /* Saved wake-up state for resume */
struct regmap *sfr_regmap;
}; };
/* interface and function clocks; sometimes also an AHB clock */ /* interface and function clocks; sometimes also an AHB clock */
...@@ -134,6 +138,17 @@ static void at91_stop_hc(struct platform_device *pdev) ...@@ -134,6 +138,17 @@ static void at91_stop_hc(struct platform_device *pdev)
static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *); static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
struct regmap *at91_dt_syscon_sfr(void)
{
struct regmap *regmap;
regmap = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr");
if (IS_ERR(regmap))
regmap = NULL;
return regmap;
}
/* configure so an HC device and id are always provided */ /* configure so an HC device and id are always provided */
/* always called with process context; sleeping is OK */ /* always called with process context; sleeping is OK */
...@@ -197,6 +212,10 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver, ...@@ -197,6 +212,10 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
goto err; goto err;
} }
ohci_at91->sfr_regmap = at91_dt_syscon_sfr();
if (!ohci_at91->sfr_regmap)
dev_warn(dev, "failed to find sfr node\n");
board = hcd->self.controller->platform_data; board = hcd->self.controller->platform_data;
ohci = hcd_to_ohci(hcd); ohci = hcd_to_ohci(hcd);
ohci->num_ports = board->ports; ohci->num_ports = board->ports;
...@@ -282,6 +301,28 @@ static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) ...@@ -282,6 +301,28 @@ static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
return length; return length;
} }
static int ohci_at91_port_suspend(struct regmap *regmap, u8 set)
{
u32 regval;
int ret;
if (!regmap)
return 0;
ret = regmap_read(regmap, AT91_SFR_OHCIICR, &regval);
if (ret)
return ret;
if (set)
regval |= AT91_OHCIICR_USB_SUSPEND;
else
regval &= ~AT91_OHCIICR_USB_SUSPEND;
regmap_write(regmap, AT91_SFR_OHCIICR, regval);
return 0;
}
/* /*
* Look at the control requests to the root hub and see if we need to override. * Look at the control requests to the root hub and see if we need to override.
*/ */
...@@ -289,6 +330,7 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ...@@ -289,6 +330,7 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
u16 wIndex, char *buf, u16 wLength) u16 wIndex, char *buf, u16 wLength)
{ {
struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller); struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller);
struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
struct usb_hub_descriptor *desc; struct usb_hub_descriptor *desc;
int ret = -EINVAL; int ret = -EINVAL;
u32 *data = (u32 *)buf; u32 *data = (u32 *)buf;
...@@ -301,7 +343,8 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ...@@ -301,7 +343,8 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
switch (typeReq) { switch (typeReq) {
case SetPortFeature: case SetPortFeature:
if (wValue == USB_PORT_FEAT_POWER) { switch (wValue) {
case USB_PORT_FEAT_POWER:
dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
if (valid_port(wIndex)) { if (valid_port(wIndex)) {
ohci_at91_usb_set_power(pdata, wIndex, 1); ohci_at91_usb_set_power(pdata, wIndex, 1);
...@@ -309,6 +352,15 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ...@@ -309,6 +352,15 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
} }
goto out; goto out;
case USB_PORT_FEAT_SUSPEND:
dev_dbg(hcd->self.controller, "SetPortFeat: SUSPEND\n");
if (valid_port(wIndex)) {
ohci_at91_port_suspend(ohci_at91->sfr_regmap,
1);
return 0;
}
break;
} }
break; break;
...@@ -342,6 +394,16 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ...@@ -342,6 +394,16 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
ohci_at91_usb_set_power(pdata, wIndex, 0); ohci_at91_usb_set_power(pdata, wIndex, 0);
return 0; return 0;
} }
break;
case USB_PORT_FEAT_SUSPEND:
dev_dbg(hcd->self.controller, "ClearPortFeature: SUSPEND\n");
if (valid_port(wIndex)) {
ohci_at91_port_suspend(ohci_at91->sfr_regmap,
0);
return 0;
}
break;
} }
break; break;
} }
...@@ -599,6 +661,8 @@ ohci_hcd_at91_drv_suspend(struct device *dev) ...@@ -599,6 +661,8 @@ ohci_hcd_at91_drv_suspend(struct device *dev)
if (ohci_at91->wakeup) if (ohci_at91->wakeup)
enable_irq_wake(hcd->irq); enable_irq_wake(hcd->irq);
ohci_at91_port_suspend(ohci_at91->sfr_regmap, 1);
ret = ohci_suspend(hcd, ohci_at91->wakeup); ret = ohci_suspend(hcd, ohci_at91->wakeup);
if (ret) { if (ret) {
if (ohci_at91->wakeup) if (ohci_at91->wakeup)
...@@ -638,6 +702,9 @@ ohci_hcd_at91_drv_resume(struct device *dev) ...@@ -638,6 +702,9 @@ ohci_hcd_at91_drv_resume(struct device *dev)
at91_start_clock(ohci_at91); at91_start_clock(ohci_at91);
ohci_resume(hcd, false); ohci_resume(hcd, false);
ohci_at91_port_suspend(ohci_at91->sfr_regmap, 0);
return 0; return 0;
} }
......
...@@ -13,6 +13,20 @@ ...@@ -13,6 +13,20 @@
#ifndef _LINUX_MFD_SYSCON_ATMEL_SFR_H #ifndef _LINUX_MFD_SYSCON_ATMEL_SFR_H
#define _LINUX_MFD_SYSCON_ATMEL_SFR_H #define _LINUX_MFD_SYSCON_ATMEL_SFR_H
#define AT91_SFR_DDRCFG 0x04 /* DDR Configuration Register */
/* 0x08 ~ 0x0c: Reserved */
#define AT91_SFR_OHCIICR 0x10 /* OHCI INT Configuration Register */
#define AT91_SFR_OHCIISR 0x14 /* OHCI INT Status Register */
#define AT91_SFR_I2SCLKSEL 0x90 /* I2SC Register */ #define AT91_SFR_I2SCLKSEL 0x90 /* I2SC Register */
/* Field definitions */
#define AT91_OHCIICR_SUSPEND_A BIT(8)
#define AT91_OHCIICR_SUSPEND_B BIT(9)
#define AT91_OHCIICR_SUSPEND_C BIT(10)
#define AT91_OHCIICR_USB_SUSPEND (AT91_OHCIICR_SUSPEND_A | \
AT91_OHCIICR_SUSPEND_B | \
AT91_OHCIICR_SUSPEND_C)
#endif /* _LINUX_MFD_SYSCON_ATMEL_SFR_H */ #endif /* _LINUX_MFD_SYSCON_ATMEL_SFR_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment