2006-01-23 02:32:13 +08:00
|
|
|
/*
|
|
|
|
* OHCI HCD (Host Controller Driver) for USB.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 SAN People (Pty) Ltd.
|
|
|
|
* Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
|
|
|
|
*
|
2006-06-20 05:27:20 +08:00
|
|
|
* AT91 Bus Glue
|
2006-01-23 02:32:13 +08:00
|
|
|
*
|
|
|
|
* Based on fragments of 2.4 driver by Rick Bronson.
|
|
|
|
* Based on ohci-omap.c
|
|
|
|
*
|
|
|
|
* This file is licenced under the GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2008-08-05 23:14:15 +08:00
|
|
|
#include <mach/hardware.h>
|
2007-12-28 03:19:49 +08:00
|
|
|
#include <asm/gpio.h>
|
|
|
|
|
2008-08-05 23:14:15 +08:00
|
|
|
#include <mach/board.h>
|
|
|
|
#include <mach/cpu.h>
|
2006-01-23 02:32:13 +08:00
|
|
|
|
2006-06-20 05:27:20 +08:00
|
|
|
#ifndef CONFIG_ARCH_AT91
|
|
|
|
#error "CONFIG_ARCH_AT91 must be defined."
|
2006-01-23 02:32:13 +08:00
|
|
|
#endif
|
|
|
|
|
2007-02-17 02:18:58 +08:00
|
|
|
/* interface and function clocks; sometimes also an AHB clock */
|
|
|
|
static struct clk *iclk, *fclk, *hclk;
|
2006-06-20 05:27:20 +08:00
|
|
|
static int clocked;
|
2006-01-23 02:32:13 +08:00
|
|
|
|
|
|
|
extern int usb_disabled(void);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2007-02-17 02:18:58 +08:00
|
|
|
static void at91_start_clock(void)
|
|
|
|
{
|
2011-08-30 09:29:28 +08:00
|
|
|
clk_enable(hclk);
|
2007-02-17 02:18:58 +08:00
|
|
|
clk_enable(iclk);
|
|
|
|
clk_enable(fclk);
|
|
|
|
clocked = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void at91_stop_clock(void)
|
|
|
|
{
|
|
|
|
clk_disable(fclk);
|
|
|
|
clk_disable(iclk);
|
2011-08-30 09:29:28 +08:00
|
|
|
clk_disable(hclk);
|
2007-02-17 02:18:58 +08:00
|
|
|
clocked = 0;
|
|
|
|
}
|
|
|
|
|
2006-01-23 02:32:13 +08:00
|
|
|
static void at91_start_hc(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct usb_hcd *hcd = platform_get_drvdata(pdev);
|
|
|
|
struct ohci_regs __iomem *regs = hcd->regs;
|
|
|
|
|
2006-06-20 05:27:20 +08:00
|
|
|
dev_dbg(&pdev->dev, "start\n");
|
2006-01-23 02:32:13 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the USB clocks.
|
|
|
|
*/
|
2007-02-17 02:18:58 +08:00
|
|
|
at91_start_clock();
|
2006-01-23 02:32:13 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The USB host controller must remain in reset.
|
|
|
|
*/
|
|
|
|
writel(0, ®s->control);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void at91_stop_hc(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct usb_hcd *hcd = platform_get_drvdata(pdev);
|
|
|
|
struct ohci_regs __iomem *regs = hcd->regs;
|
|
|
|
|
2006-06-20 05:27:20 +08:00
|
|
|
dev_dbg(&pdev->dev, "stop\n");
|
2006-01-23 02:32:13 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the USB host controller into reset.
|
|
|
|
*/
|
|
|
|
writel(0, ®s->control);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the USB clocks.
|
|
|
|
*/
|
2007-02-17 02:18:58 +08:00
|
|
|
at91_stop_clock();
|
2006-01-23 02:32:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2008-06-02 05:38:43 +08:00
|
|
|
static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
|
2006-01-23 02:32:13 +08:00
|
|
|
|
|
|
|
/* configure so an HC device and id are always provided */
|
|
|
|
/* always called with process context; sleeping is OK */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-06-20 05:27:20 +08:00
|
|
|
* usb_hcd_at91_probe - initialize AT91-based HCDs
|
2006-01-23 02:32:13 +08:00
|
|
|
* Context: !in_interrupt()
|
|
|
|
*
|
|
|
|
* Allocates basic resources for this USB host controller, and
|
|
|
|
* then invokes the start() method for the HCD associated with it
|
|
|
|
* through the hotplug entry's driver_data.
|
|
|
|
*/
|
2006-06-20 05:27:20 +08:00
|
|
|
static int usb_hcd_at91_probe(const struct hc_driver *driver,
|
|
|
|
struct platform_device *pdev)
|
2006-01-23 02:32:13 +08:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
struct usb_hcd *hcd = NULL;
|
|
|
|
|
|
|
|
if (pdev->num_resources != 2) {
|
|
|
|
pr_debug("hcd probe: invalid num_resources");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2006-06-20 05:27:20 +08:00
|
|
|
if ((pdev->resource[0].flags != IORESOURCE_MEM)
|
|
|
|
|| (pdev->resource[1].flags != IORESOURCE_IRQ)) {
|
2006-01-23 02:32:13 +08:00
|
|
|
pr_debug("hcd probe: invalid resource type\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2006-06-20 05:27:20 +08:00
|
|
|
hcd = usb_create_hcd(driver, &pdev->dev, "at91");
|
2006-01-23 02:32:13 +08:00
|
|
|
if (!hcd)
|
|
|
|
return -ENOMEM;
|
|
|
|
hcd->rsrc_start = pdev->resource[0].start;
|
|
|
|
hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
|
|
|
|
|
|
|
|
if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
|
|
|
|
pr_debug("request_mem_region failed\n");
|
|
|
|
retval = -EBUSY;
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
|
|
|
hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
|
|
|
|
if (!hcd->regs) {
|
|
|
|
pr_debug("ioremap failed\n");
|
|
|
|
retval = -EIO;
|
|
|
|
goto err2;
|
|
|
|
}
|
|
|
|
|
|
|
|
iclk = clk_get(&pdev->dev, "ohci_clk");
|
2011-12-08 23:32:00 +08:00
|
|
|
if (IS_ERR(iclk)) {
|
|
|
|
dev_err(&pdev->dev, "failed to get ohci_clk\n");
|
|
|
|
retval = PTR_ERR(iclk);
|
|
|
|
goto err3;
|
|
|
|
}
|
2006-01-23 02:32:13 +08:00
|
|
|
fclk = clk_get(&pdev->dev, "uhpck");
|
2011-12-08 23:32:00 +08:00
|
|
|
if (IS_ERR(fclk)) {
|
|
|
|
dev_err(&pdev->dev, "failed to get uhpck\n");
|
|
|
|
retval = PTR_ERR(fclk);
|
|
|
|
goto err4;
|
|
|
|
}
|
2011-08-30 09:29:28 +08:00
|
|
|
hclk = clk_get(&pdev->dev, "hclk");
|
2011-12-08 23:32:00 +08:00
|
|
|
if (IS_ERR(hclk)) {
|
|
|
|
dev_err(&pdev->dev, "failed to get hclk\n");
|
|
|
|
retval = PTR_ERR(hclk);
|
|
|
|
goto err5;
|
|
|
|
}
|
2006-01-23 02:32:13 +08:00
|
|
|
|
|
|
|
at91_start_hc(pdev);
|
|
|
|
ohci_hcd_init(hcd_to_ohci(hcd));
|
|
|
|
|
2009-07-28 05:59:24 +08:00
|
|
|
retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
|
2006-01-23 02:32:13 +08:00
|
|
|
if (retval == 0)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* Error handling */
|
|
|
|
at91_stop_hc(pdev);
|
|
|
|
|
2011-08-30 09:29:28 +08:00
|
|
|
clk_put(hclk);
|
2011-12-08 23:32:00 +08:00
|
|
|
err5:
|
2006-01-23 02:32:13 +08:00
|
|
|
clk_put(fclk);
|
2011-12-08 23:32:00 +08:00
|
|
|
err4:
|
2006-01-23 02:32:13 +08:00
|
|
|
clk_put(iclk);
|
|
|
|
|
2011-12-08 23:32:00 +08:00
|
|
|
err3:
|
2006-01-23 02:32:13 +08:00
|
|
|
iounmap(hcd->regs);
|
|
|
|
|
|
|
|
err2:
|
|
|
|
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
|
|
|
|
|
|
|
|
err1:
|
|
|
|
usb_put_hcd(hcd);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* may be called with controller, bus, and devices active */
|
|
|
|
|
|
|
|
/**
|
2006-06-20 05:27:20 +08:00
|
|
|
* usb_hcd_at91_remove - shutdown processing for AT91-based HCDs
|
2006-01-23 02:32:13 +08:00
|
|
|
* @dev: USB Host Controller being removed
|
|
|
|
* Context: !in_interrupt()
|
|
|
|
*
|
|
|
|
* Reverses the effect of usb_hcd_at91_probe(), first invoking
|
|
|
|
* the HCD's stop() method. It is always called from a thread
|
2006-06-20 05:27:20 +08:00
|
|
|
* context, "rmmod" or something similar.
|
2006-01-23 02:32:13 +08:00
|
|
|
*
|
|
|
|
*/
|
2008-06-02 05:38:43 +08:00
|
|
|
static void usb_hcd_at91_remove(struct usb_hcd *hcd,
|
2006-06-20 05:27:20 +08:00
|
|
|
struct platform_device *pdev)
|
2006-01-23 02:32:13 +08:00
|
|
|
{
|
|
|
|
usb_remove_hcd(hcd);
|
|
|
|
at91_stop_hc(pdev);
|
|
|
|
iounmap(hcd->regs);
|
2006-04-03 12:26:21 +08:00
|
|
|
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
|
2008-06-02 05:38:43 +08:00
|
|
|
usb_put_hcd(hcd);
|
2006-01-23 02:32:13 +08:00
|
|
|
|
2011-08-30 09:29:28 +08:00
|
|
|
clk_put(hclk);
|
2006-04-03 12:26:21 +08:00
|
|
|
clk_put(fclk);
|
|
|
|
clk_put(iclk);
|
2007-02-17 02:18:58 +08:00
|
|
|
fclk = iclk = hclk = NULL;
|
2006-01-23 02:32:13 +08:00
|
|
|
|
|
|
|
dev_set_drvdata(&pdev->dev, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int __devinit
|
|
|
|
ohci_at91_start (struct usb_hcd *hcd)
|
|
|
|
{
|
2006-06-20 05:27:20 +08:00
|
|
|
struct at91_usbh_data *board = hcd->self.controller->platform_data;
|
2006-01-23 02:32:13 +08:00
|
|
|
struct ohci_hcd *ohci = hcd_to_ohci (hcd);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((ret = ohci_init(ohci)) < 0)
|
|
|
|
return ret;
|
|
|
|
|
2006-09-04 03:21:50 +08:00
|
|
|
ohci->num_ports = board->ports;
|
2006-06-20 05:27:20 +08:00
|
|
|
|
2006-01-23 02:32:13 +08:00
|
|
|
if ((ret = ohci_run(ohci)) < 0) {
|
|
|
|
err("can't start %s", hcd->self.bus_name);
|
|
|
|
ohci_stop(hcd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-13 17:29:17 +08:00
|
|
|
static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
|
|
|
|
{
|
|
|
|
if (port < 0 || port >= 2)
|
|
|
|
return;
|
|
|
|
|
2011-09-19 15:32:23 +08:00
|
|
|
if (!gpio_is_valid(pdata->vbus_pin[port]))
|
2011-11-12 23:46:13 +08:00
|
|
|
return;
|
|
|
|
|
2011-12-08 23:32:01 +08:00
|
|
|
gpio_set_value(pdata->vbus_pin[port],
|
|
|
|
!pdata->vbus_pin_active_low[port] ^ enable);
|
2011-07-13 17:29:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
|
|
|
|
{
|
|
|
|
if (port < 0 || port >= 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-09-19 15:32:23 +08:00
|
|
|
if (!gpio_is_valid(pdata->vbus_pin[port]))
|
2011-11-12 23:46:13 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2011-12-08 23:32:01 +08:00
|
|
|
return gpio_get_value(pdata->vbus_pin[port]) ^
|
|
|
|
!pdata->vbus_pin_active_low[port];
|
2011-07-13 17:29:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the status data from the hub with the over-current indicator change.
|
|
|
|
*/
|
|
|
|
static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
|
|
|
|
{
|
|
|
|
struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
|
|
|
|
int length = ohci_hub_status_data(hcd, buf);
|
|
|
|
int port;
|
|
|
|
|
|
|
|
for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) {
|
|
|
|
if (pdata->overcurrent_changed[port]) {
|
|
|
|
if (! length)
|
|
|
|
length = 1;
|
|
|
|
buf[0] |= 1 << (port + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look at the control requests to the root hub and see if we need to override.
|
|
|
|
*/
|
|
|
|
static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
|
|
|
|
u16 wIndex, char *buf, u16 wLength)
|
|
|
|
{
|
|
|
|
struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
|
|
|
|
struct usb_hub_descriptor *desc;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
u32 *data = (u32 *)buf;
|
|
|
|
|
|
|
|
dev_dbg(hcd->self.controller,
|
|
|
|
"ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
|
|
|
|
hcd, typeReq, wValue, wIndex, buf, wLength);
|
|
|
|
|
|
|
|
switch (typeReq) {
|
|
|
|
case SetPortFeature:
|
|
|
|
if (wValue == USB_PORT_FEAT_POWER) {
|
|
|
|
dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
|
|
|
|
ohci_at91_usb_set_power(pdata, wIndex - 1, 1);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ClearPortFeature:
|
|
|
|
switch (wValue) {
|
|
|
|
case USB_PORT_FEAT_C_OVER_CURRENT:
|
|
|
|
dev_dbg(hcd->self.controller,
|
|
|
|
"ClearPortFeature: C_OVER_CURRENT\n");
|
|
|
|
|
|
|
|
if (wIndex == 1 || wIndex == 2) {
|
|
|
|
pdata->overcurrent_changed[wIndex-1] = 0;
|
|
|
|
pdata->overcurrent_status[wIndex-1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
case USB_PORT_FEAT_OVER_CURRENT:
|
|
|
|
dev_dbg(hcd->self.controller,
|
|
|
|
"ClearPortFeature: OVER_CURRENT\n");
|
|
|
|
|
|
|
|
if (wIndex == 1 || wIndex == 2) {
|
|
|
|
pdata->overcurrent_status[wIndex-1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
case USB_PORT_FEAT_POWER:
|
|
|
|
dev_dbg(hcd->self.controller,
|
|
|
|
"ClearPortFeature: POWER\n");
|
|
|
|
|
|
|
|
if (wIndex == 1 || wIndex == 2) {
|
|
|
|
ohci_at91_usb_set_power(pdata, wIndex - 1, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
switch (typeReq) {
|
|
|
|
case GetHubDescriptor:
|
|
|
|
|
|
|
|
/* update the hub's descriptor */
|
|
|
|
|
|
|
|
desc = (struct usb_hub_descriptor *)buf;
|
|
|
|
|
|
|
|
dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
|
|
|
|
desc->wHubCharacteristics);
|
|
|
|
|
|
|
|
/* remove the old configurations for power-switching, and
|
|
|
|
* over-current protection, and insert our new configuration
|
|
|
|
*/
|
|
|
|
|
|
|
|
desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
|
|
|
|
desc->wHubCharacteristics |= cpu_to_le16(0x0001);
|
|
|
|
|
|
|
|
if (pdata->overcurrent_supported) {
|
|
|
|
desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM);
|
|
|
|
desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001);
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
|
|
|
|
desc->wHubCharacteristics);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
case GetPortStatus:
|
|
|
|
/* check port status */
|
|
|
|
|
|
|
|
dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
|
|
|
|
|
|
|
|
if (wIndex == 1 || wIndex == 2) {
|
|
|
|
if (! ohci_at91_usb_get_power(pdata, wIndex-1)) {
|
|
|
|
*data &= ~cpu_to_le32(RH_PS_PPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdata->overcurrent_changed[wIndex-1]) {
|
|
|
|
*data |= cpu_to_le32(RH_PS_OCIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdata->overcurrent_status[wIndex-1]) {
|
|
|
|
*data |= cpu_to_le32(RH_PS_POCI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-01-23 02:32:13 +08:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static const struct hc_driver ohci_at91_hc_driver = {
|
|
|
|
.description = hcd_name,
|
2006-06-20 05:27:20 +08:00
|
|
|
.product_desc = "AT91 OHCI",
|
2006-01-23 02:32:13 +08:00
|
|
|
.hcd_priv_size = sizeof(struct ohci_hcd),
|
|
|
|
|
|
|
|
/*
|
|
|
|
* generic hardware linkage
|
|
|
|
*/
|
|
|
|
.irq = ohci_irq,
|
|
|
|
.flags = HCD_USB11 | HCD_MEMORY,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* basic lifecycle operations
|
|
|
|
*/
|
|
|
|
.start = ohci_at91_start,
|
|
|
|
.stop = ohci_stop,
|
2006-12-05 19:18:31 +08:00
|
|
|
.shutdown = ohci_shutdown,
|
2006-01-23 02:32:13 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* managing i/o requests and associated device resources
|
|
|
|
*/
|
|
|
|
.urb_enqueue = ohci_urb_enqueue,
|
|
|
|
.urb_dequeue = ohci_urb_dequeue,
|
|
|
|
.endpoint_disable = ohci_endpoint_disable,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* scheduling support
|
|
|
|
*/
|
|
|
|
.get_frame_number = ohci_get_frame,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* root hub support
|
|
|
|
*/
|
2011-07-13 17:29:17 +08:00
|
|
|
.hub_status_data = ohci_at91_hub_status_data,
|
|
|
|
.hub_control = ohci_at91_hub_control,
|
2006-01-23 02:32:13 +08:00
|
|
|
#ifdef CONFIG_PM
|
2006-04-03 12:26:21 +08:00
|
|
|
.bus_suspend = ohci_bus_suspend,
|
|
|
|
.bus_resume = ohci_bus_resume,
|
2006-01-23 02:32:13 +08:00
|
|
|
#endif
|
|
|
|
.start_port_reset = ohci_start_port_reset,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2011-07-13 17:29:17 +08:00
|
|
|
static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = data;
|
|
|
|
struct at91_usbh_data *pdata = pdev->dev.platform_data;
|
|
|
|
int val, gpio, port;
|
|
|
|
|
|
|
|
/* From the GPIO notifying the over-current situation, find
|
|
|
|
* out the corresponding port */
|
|
|
|
gpio = irq_to_gpio(irq);
|
|
|
|
for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) {
|
|
|
|
if (pdata->overcurrent_pin[port] == gpio)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (port == ARRAY_SIZE(pdata->overcurrent_pin)) {
|
|
|
|
dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n");
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = gpio_get_value(gpio);
|
|
|
|
|
|
|
|
/* When notified of an over-current situation, disable power
|
|
|
|
on the corresponding port, and mark this port in
|
|
|
|
over-current. */
|
|
|
|
if (! val) {
|
|
|
|
ohci_at91_usb_set_power(pdata, port, 0);
|
|
|
|
pdata->overcurrent_status[port] = 1;
|
|
|
|
pdata->overcurrent_changed[port] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(& pdev->dev, "overcurrent situation %s\n",
|
|
|
|
val ? "exited" : "notified");
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2006-06-20 05:27:20 +08:00
|
|
|
static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
|
2006-01-23 02:32:13 +08:00
|
|
|
{
|
2007-12-28 03:19:49 +08:00
|
|
|
struct at91_usbh_data *pdata = pdev->dev.platform_data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (pdata) {
|
2009-04-04 04:06:53 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) {
|
2011-09-19 15:32:23 +08:00
|
|
|
if (!gpio_is_valid(pdata->vbus_pin[i]))
|
2007-12-28 03:19:49 +08:00
|
|
|
continue;
|
|
|
|
gpio_request(pdata->vbus_pin[i], "ohci_vbus");
|
2011-07-13 17:29:17 +08:00
|
|
|
ohci_at91_usb_set_power(pdata, i, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) {
|
|
|
|
int ret;
|
|
|
|
|
2011-09-19 15:32:23 +08:00
|
|
|
if (!gpio_is_valid(pdata->overcurrent_pin[i]))
|
2011-07-13 17:29:17 +08:00
|
|
|
continue;
|
|
|
|
gpio_request(pdata->overcurrent_pin[i], "ohci_overcurrent");
|
|
|
|
|
|
|
|
ret = request_irq(gpio_to_irq(pdata->overcurrent_pin[i]),
|
|
|
|
ohci_hcd_at91_overcurrent_irq,
|
|
|
|
IRQF_SHARED, "ohci_overcurrent", pdev);
|
|
|
|
if (ret) {
|
|
|
|
gpio_free(pdata->overcurrent_pin[i]);
|
|
|
|
dev_warn(& pdev->dev, "cannot get GPIO IRQ for overcurrent\n");
|
|
|
|
}
|
2007-12-28 03:19:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-20 05:27:20 +08:00
|
|
|
device_init_wakeup(&pdev->dev, 1);
|
|
|
|
return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
|
2006-01-23 02:32:13 +08:00
|
|
|
}
|
|
|
|
|
2006-06-20 05:27:20 +08:00
|
|
|
static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
|
2006-01-23 02:32:13 +08:00
|
|
|
{
|
2007-12-28 03:19:49 +08:00
|
|
|
struct at91_usbh_data *pdata = pdev->dev.platform_data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (pdata) {
|
2009-04-04 04:06:53 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) {
|
2011-09-19 15:32:23 +08:00
|
|
|
if (!gpio_is_valid(pdata->vbus_pin[i]))
|
2007-12-28 03:19:49 +08:00
|
|
|
continue;
|
2011-07-13 17:29:17 +08:00
|
|
|
ohci_at91_usb_set_power(pdata, i, 0);
|
2007-12-28 03:19:49 +08:00
|
|
|
gpio_free(pdata->vbus_pin[i]);
|
|
|
|
}
|
2011-07-13 17:29:17 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) {
|
2011-09-19 15:32:23 +08:00
|
|
|
if (!gpio_is_valid(pdata->overcurrent_pin[i]))
|
2011-07-13 17:29:17 +08:00
|
|
|
continue;
|
|
|
|
free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev);
|
|
|
|
gpio_free(pdata->overcurrent_pin[i]);
|
|
|
|
}
|
2007-12-28 03:19:49 +08:00
|
|
|
}
|
|
|
|
|
2006-06-20 05:27:20 +08:00
|
|
|
device_init_wakeup(&pdev->dev, 0);
|
2008-06-02 05:38:43 +08:00
|
|
|
usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
|
|
|
|
return 0;
|
2006-01-23 02:32:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
2006-04-03 12:26:21 +08:00
|
|
|
static int
|
2006-06-20 05:27:20 +08:00
|
|
|
ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
|
2006-04-03 12:26:21 +08:00
|
|
|
{
|
2006-06-20 05:27:20 +08:00
|
|
|
struct usb_hcd *hcd = platform_get_drvdata(pdev);
|
|
|
|
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
|
|
|
|
|
|
|
|
if (device_may_wakeup(&pdev->dev))
|
|
|
|
enable_irq_wake(hcd->irq);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The integrated transceivers seem unable to notice disconnect,
|
|
|
|
* reconnect, or wakeup without the 48 MHz clock active. so for
|
|
|
|
* correctness, always discard connection state (using reset).
|
|
|
|
*
|
|
|
|
* REVISIT: some boards will be able to turn VBUS off...
|
|
|
|
*/
|
|
|
|
if (at91_suspend_entering_slow_clock()) {
|
|
|
|
ohci_usb_reset (ohci);
|
2010-04-28 19:45:40 +08:00
|
|
|
/* flush the writes */
|
|
|
|
(void) ohci_readl (ohci, &ohci->regs->control);
|
2007-02-17 02:18:58 +08:00
|
|
|
at91_stop_clock();
|
2006-06-20 05:27:20 +08:00
|
|
|
}
|
2006-01-23 02:32:13 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-20 05:27:20 +08:00
|
|
|
static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
|
2006-01-23 02:32:13 +08:00
|
|
|
{
|
2007-01-10 06:00:11 +08:00
|
|
|
struct usb_hcd *hcd = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
if (device_may_wakeup(&pdev->dev))
|
|
|
|
disable_irq_wake(hcd->irq);
|
|
|
|
|
2007-02-17 02:18:58 +08:00
|
|
|
if (!clocked)
|
|
|
|
at91_start_clock();
|
2006-01-23 02:32:13 +08:00
|
|
|
|
2008-04-04 06:03:17 +08:00
|
|
|
ohci_finish_controller_resume(hcd);
|
2006-01-23 02:32:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define ohci_hcd_at91_drv_suspend NULL
|
|
|
|
#define ohci_hcd_at91_drv_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2008-04-11 12:29:22 +08:00
|
|
|
MODULE_ALIAS("platform:at91_ohci");
|
2006-04-03 12:26:21 +08:00
|
|
|
|
2006-01-23 02:32:13 +08:00
|
|
|
static struct platform_driver ohci_hcd_at91_driver = {
|
|
|
|
.probe = ohci_hcd_at91_drv_probe,
|
|
|
|
.remove = ohci_hcd_at91_drv_remove,
|
USB: Properly unregister reboot notifier in case of failure in ehci hcd
If some problem occurs during ehci startup, for instance, request_irq fails,
echi hcd driver tries it best to cleanup, but fails to unregister reboot
notifier, which in turn leads to crash on reboot/poweroff.
The following patch resolves this problem by not using reboot notifiers
anymore, but instead making ehci/ohci driver get its own shutdown method. For
PCI, it is done through pci glue, for everything else through platform driver
glue.
One downside: sa1111 does not use platform driver stuff, and does not have its
own shutdown hook, so no 'shutdown' is called for it now. I'm not sure if it
is really necessary on that platform, though.
Signed-off-by: Aleks Gorelov <dared1st@yahoo.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2006-08-09 08:24:08 +08:00
|
|
|
.shutdown = usb_hcd_platform_shutdown,
|
2006-01-23 02:32:13 +08:00
|
|
|
.suspend = ohci_hcd_at91_drv_suspend,
|
|
|
|
.resume = ohci_hcd_at91_drv_resume,
|
|
|
|
.driver = {
|
2006-06-20 05:27:20 +08:00
|
|
|
.name = "at91_ohci",
|
2006-01-23 02:32:13 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
};
|