Skip to content

Commit 2e2aa1b

Browse files
wenyouyagregkh
authored andcommitted
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: Wenyou Yang <wenyou.yang@atmel.com> Reviewed-by: Alexandre Belloni <alexandre.belloni@free-electrons.com> Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fc8b690 commit 2e2aa1b

2 files changed

Lines changed: 82 additions & 1 deletion

File tree

‎drivers/usb/host/ohci-at91.c‎

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
#include <linux/io.h>
2222
#include <linux/kernel.h>
2323
#include <linux/module.h>
24+
#include <linux/mfd/syscon.h>
25+
#include <linux/regmap.h>
2426
#include <linux/usb.h>
2527
#include <linux/usb/hcd.h>
28+
#include <soc/at91/atmel-sfr.h>
2629

2730
#include "ohci.h"
2831

@@ -51,6 +54,7 @@ struct ohci_at91_priv {
5154
struct clk *hclk;
5255
bool clocked;
5356
bool wakeup; /* Saved wake-up state for resume */
57+
struct regmap *sfr_regmap;
5458
};
5559
/* interface and function clocks; sometimes also an AHB clock */
5660

@@ -134,6 +138,17 @@ static void at91_stop_hc(struct platform_device *pdev)
134138

135139
static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
136140

141+
struct regmap *at91_dt_syscon_sfr(void)
142+
{
143+
struct regmap *regmap;
144+
145+
regmap = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr");
146+
if (IS_ERR(regmap))
147+
regmap = NULL;
148+
149+
return regmap;
150+
}
151+
137152
/* configure so an HC device and id are always provided */
138153
/* always called with process context; sleeping is OK */
139154

@@ -197,6 +212,10 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
197212
goto err;
198213
}
199214

215+
ohci_at91->sfr_regmap = at91_dt_syscon_sfr();
216+
if (!ohci_at91->sfr_regmap)
217+
dev_warn(dev, "failed to find sfr node\n");
218+
200219
board = hcd->self.controller->platform_data;
201220
ohci = hcd_to_ohci(hcd);
202221
ohci->num_ports = board->ports;
@@ -282,13 +301,36 @@ static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
282301
return length;
283302
}
284303

304+
static int ohci_at91_port_suspend(struct regmap *regmap, u8 set)
305+
{
306+
u32 regval;
307+
int ret;
308+
309+
if (!regmap)
310+
return 0;
311+
312+
ret = regmap_read(regmap, AT91_SFR_OHCIICR, &regval);
313+
if (ret)
314+
return ret;
315+
316+
if (set)
317+
regval |= AT91_OHCIICR_USB_SUSPEND;
318+
else
319+
regval &= ~AT91_OHCIICR_USB_SUSPEND;
320+
321+
regmap_write(regmap, AT91_SFR_OHCIICR, regval);
322+
323+
return 0;
324+
}
325+
285326
/*
286327
* Look at the control requests to the root hub and see if we need to override.
287328
*/
288329
static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
289330
u16 wIndex, char *buf, u16 wLength)
290331
{
291332
struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller);
333+
struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
292334
struct usb_hub_descriptor *desc;
293335
int ret = -EINVAL;
294336
u32 *data = (u32 *)buf;
@@ -301,14 +343,24 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
301343

302344
switch (typeReq) {
303345
case SetPortFeature:
304-
if (wValue == USB_PORT_FEAT_POWER) {
346+
switch (wValue) {
347+
case USB_PORT_FEAT_POWER:
305348
dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
306349
if (valid_port(wIndex)) {
307350
ohci_at91_usb_set_power(pdata, wIndex, 1);
308351
ret = 0;
309352
}
310353

311354
goto out;
355+
356+
case USB_PORT_FEAT_SUSPEND:
357+
dev_dbg(hcd->self.controller, "SetPortFeat: SUSPEND\n");
358+
if (valid_port(wIndex)) {
359+
ohci_at91_port_suspend(ohci_at91->sfr_regmap,
360+
1);
361+
return 0;
362+
}
363+
break;
312364
}
313365
break;
314366

@@ -342,6 +394,16 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
342394
ohci_at91_usb_set_power(pdata, wIndex, 0);
343395
return 0;
344396
}
397+
break;
398+
399+
case USB_PORT_FEAT_SUSPEND:
400+
dev_dbg(hcd->self.controller, "ClearPortFeature: SUSPEND\n");
401+
if (valid_port(wIndex)) {
402+
ohci_at91_port_suspend(ohci_at91->sfr_regmap,
403+
0);
404+
return 0;
405+
}
406+
break;
345407
}
346408
break;
347409
}
@@ -599,6 +661,8 @@ ohci_hcd_at91_drv_suspend(struct device *dev)
599661
if (ohci_at91->wakeup)
600662
enable_irq_wake(hcd->irq);
601663

664+
ohci_at91_port_suspend(ohci_at91->sfr_regmap, 1);
665+
602666
ret = ohci_suspend(hcd, ohci_at91->wakeup);
603667
if (ret) {
604668
if (ohci_at91->wakeup)
@@ -638,6 +702,9 @@ ohci_hcd_at91_drv_resume(struct device *dev)
638702
at91_start_clock(ohci_at91);
639703

640704
ohci_resume(hcd, false);
705+
706+
ohci_at91_port_suspend(ohci_at91->sfr_regmap, 0);
707+
641708
return 0;
642709
}
643710

‎include/soc/at91/atmel-sfr.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
#ifndef _LINUX_MFD_SYSCON_ATMEL_SFR_H
1414
#define _LINUX_MFD_SYSCON_ATMEL_SFR_H
1515

16+
#define AT91_SFR_DDRCFG 0x04 /* DDR Configuration Register */
17+
/* 0x08 ~ 0x0c: Reserved */
18+
#define AT91_SFR_OHCIICR 0x10 /* OHCI INT Configuration Register */
19+
#define AT91_SFR_OHCIISR 0x14 /* OHCI INT Status Register */
1620
#define AT91_SFR_I2SCLKSEL 0x90 /* I2SC Register */
1721

22+
/* Field definitions */
23+
#define AT91_OHCIICR_SUSPEND_A BIT(8)
24+
#define AT91_OHCIICR_SUSPEND_B BIT(9)
25+
#define AT91_OHCIICR_SUSPEND_C BIT(10)
26+
27+
#define AT91_OHCIICR_USB_SUSPEND (AT91_OHCIICR_SUSPEND_A | \
28+
AT91_OHCIICR_SUSPEND_B | \
29+
AT91_OHCIICR_SUSPEND_C)
30+
31+
1832
#endif /* _LINUX_MFD_SYSCON_ATMEL_SFR_H */

0 commit comments

Comments
 (0)