2006-01-22 18:32:13 +00: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-19 21:27:20 +00:00
|
|
|
* AT91 Bus Glue
|
2006-01-22 18:32:13 +00: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>
|
2013-09-21 11:08:42 +00:00
|
|
|
#include <linux/dma-mapping.h>
|
2011-11-20 22:55:18 +00:00
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/of_gpio.h>
|
2013-09-21 11:08:42 +00:00
|
|
|
#include <linux/platform_device.h>
|
2012-10-29 21:12:23 +00:00
|
|
|
#include <linux/platform_data/atmel.h>
|
2013-09-21 11:08:42 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/usb/hcd.h>
|
2006-01-22 18:32:13 +00:00
|
|
|
|
2007-12-27 19:19:49 +00:00
|
|
|
#include <asm/gpio.h>
|
|
|
|
|
2013-09-21 11:08:42 +00:00
|
|
|
#include "ohci.h"
|
2006-01-22 18:32:13 +00:00
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
#define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS)
|
|
|
|
#define at91_for_each_port(index) \
|
|
|
|
for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
|
|
|
|
|
2013-08-01 17:09:13 +00:00
|
|
|
/* interface, function and usb clocks; sometimes also an AHB clock */
|
|
|
|
static struct clk *iclk, *fclk, *uclk, *hclk;
|
2013-09-21 11:08:42 +00:00
|
|
|
/* interface and function clocks; sometimes also an AHB clock */
|
|
|
|
|
|
|
|
#define DRIVER_DESC "OHCI Atmel driver"
|
|
|
|
|
|
|
|
static const char hcd_name[] = "ohci-atmel";
|
|
|
|
|
|
|
|
static struct hc_driver __read_mostly ohci_at91_hc_driver;
|
2006-06-19 21:27:20 +00:00
|
|
|
static int clocked;
|
2006-01-22 18:32:13 +00:00
|
|
|
|
|
|
|
extern int usb_disabled(void);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2007-02-16 18:18:58 +00:00
|
|
|
static void at91_start_clock(void)
|
|
|
|
{
|
2013-08-01 17:09:13 +00:00
|
|
|
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
|
|
|
|
clk_set_rate(uclk, 48000000);
|
|
|
|
clk_prepare_enable(uclk);
|
|
|
|
}
|
2013-06-19 11:21:08 +00:00
|
|
|
clk_prepare_enable(hclk);
|
|
|
|
clk_prepare_enable(iclk);
|
|
|
|
clk_prepare_enable(fclk);
|
2007-02-16 18:18:58 +00:00
|
|
|
clocked = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void at91_stop_clock(void)
|
|
|
|
{
|
2013-06-19 11:21:08 +00:00
|
|
|
clk_disable_unprepare(fclk);
|
|
|
|
clk_disable_unprepare(iclk);
|
|
|
|
clk_disable_unprepare(hclk);
|
2013-08-01 17:09:13 +00:00
|
|
|
if (IS_ENABLED(CONFIG_COMMON_CLK))
|
|
|
|
clk_disable_unprepare(uclk);
|
2007-02-16 18:18:58 +00:00
|
|
|
clocked = 0;
|
|
|
|
}
|
|
|
|
|
2006-01-22 18:32:13 +00: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-19 21:27:20 +00:00
|
|
|
dev_dbg(&pdev->dev, "start\n");
|
2006-01-22 18:32:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the USB clocks.
|
|
|
|
*/
|
2007-02-16 18:18:58 +00:00
|
|
|
at91_start_clock();
|
2006-01-22 18:32:13 +00: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-19 21:27:20 +00:00
|
|
|
dev_dbg(&pdev->dev, "stop\n");
|
2006-01-22 18:32:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the USB host controller into reset.
|
|
|
|
*/
|
|
|
|
writel(0, ®s->control);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the USB clocks.
|
|
|
|
*/
|
2007-02-16 18:18:58 +00:00
|
|
|
at91_stop_clock();
|
2006-01-22 18:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2012-11-19 18:26:20 +00:00
|
|
|
static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
|
2006-01-22 18:32:13 +00:00
|
|
|
|
|
|
|
/* configure so an HC device and id are always provided */
|
|
|
|
/* always called with process context; sleeping is OK */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-06-19 21:27:20 +00:00
|
|
|
* usb_hcd_at91_probe - initialize AT91-based HCDs
|
2006-01-22 18:32:13 +00: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.
|
|
|
|
*/
|
2012-11-19 18:21:48 +00:00
|
|
|
static int usb_hcd_at91_probe(const struct hc_driver *driver,
|
2006-06-19 21:27:20 +00:00
|
|
|
struct platform_device *pdev)
|
2006-01-22 18:32:13 +00:00
|
|
|
{
|
2013-09-21 11:08:42 +00:00
|
|
|
struct at91_usbh_data *board;
|
|
|
|
struct ohci_hcd *ohci;
|
2006-01-22 18:32:13 +00:00
|
|
|
int retval;
|
|
|
|
struct usb_hcd *hcd = NULL;
|
2013-12-08 14:59:59 +00:00
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct resource *res;
|
|
|
|
int irq;
|
|
|
|
|
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
if (irq < 0) {
|
|
|
|
dev_dbg(dev, "hcd probe: missing irq resource\n");
|
|
|
|
return irq;
|
2006-01-22 18:32:13 +00:00
|
|
|
}
|
|
|
|
|
2013-12-09 08:51:54 +00:00
|
|
|
hcd = usb_create_hcd(driver, dev, "at91");
|
2006-01-22 18:32:13 +00:00
|
|
|
if (!hcd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-11-04 02:21:12 +00:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2013-12-09 08:51:53 +00:00
|
|
|
hcd->regs = devm_ioremap_resource(dev, res);
|
|
|
|
if (IS_ERR(hcd->regs)) {
|
|
|
|
retval = PTR_ERR(hcd->regs);
|
|
|
|
goto err;
|
2006-01-22 18:32:13 +00:00
|
|
|
}
|
2014-11-04 02:21:12 +00:00
|
|
|
hcd->rsrc_start = res->start;
|
|
|
|
hcd->rsrc_len = resource_size(res);
|
2006-01-22 18:32:13 +00:00
|
|
|
|
2013-12-09 08:51:55 +00:00
|
|
|
iclk = devm_clk_get(dev, "ohci_clk");
|
2011-12-08 15:32:00 +00:00
|
|
|
if (IS_ERR(iclk)) {
|
2013-12-09 08:51:54 +00:00
|
|
|
dev_err(dev, "failed to get ohci_clk\n");
|
2011-12-08 15:32:00 +00:00
|
|
|
retval = PTR_ERR(iclk);
|
2013-12-09 08:51:53 +00:00
|
|
|
goto err;
|
2011-12-08 15:32:00 +00:00
|
|
|
}
|
2013-12-09 08:51:55 +00:00
|
|
|
fclk = devm_clk_get(dev, "uhpck");
|
2011-12-08 15:32:00 +00:00
|
|
|
if (IS_ERR(fclk)) {
|
2013-12-09 08:51:54 +00:00
|
|
|
dev_err(dev, "failed to get uhpck\n");
|
2011-12-08 15:32:00 +00:00
|
|
|
retval = PTR_ERR(fclk);
|
2013-12-09 08:51:55 +00:00
|
|
|
goto err;
|
2011-12-08 15:32:00 +00:00
|
|
|
}
|
2013-12-09 08:51:55 +00:00
|
|
|
hclk = devm_clk_get(dev, "hclk");
|
2011-12-08 15:32:00 +00:00
|
|
|
if (IS_ERR(hclk)) {
|
2013-12-09 08:51:54 +00:00
|
|
|
dev_err(dev, "failed to get hclk\n");
|
2011-12-08 15:32:00 +00:00
|
|
|
retval = PTR_ERR(hclk);
|
2013-12-09 08:51:55 +00:00
|
|
|
goto err;
|
2011-12-08 15:32:00 +00:00
|
|
|
}
|
2013-08-01 17:09:13 +00:00
|
|
|
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
|
2013-12-09 08:51:55 +00:00
|
|
|
uclk = devm_clk_get(dev, "usb_clk");
|
2013-08-01 17:09:13 +00:00
|
|
|
if (IS_ERR(uclk)) {
|
2013-12-09 08:51:54 +00:00
|
|
|
dev_err(dev, "failed to get uclk\n");
|
2013-08-01 17:09:13 +00:00
|
|
|
retval = PTR_ERR(uclk);
|
2013-12-09 08:51:55 +00:00
|
|
|
goto err;
|
2013-08-01 17:09:13 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-22 18:32:13 +00:00
|
|
|
|
2013-09-21 11:08:42 +00:00
|
|
|
board = hcd->self.controller->platform_data;
|
|
|
|
ohci = hcd_to_ohci(hcd);
|
|
|
|
ohci->num_ports = board->ports;
|
2006-01-22 18:32:13 +00:00
|
|
|
at91_start_hc(pdev);
|
|
|
|
|
2013-12-08 14:59:59 +00:00
|
|
|
retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
|
2014-01-07 11:54:58 +00:00
|
|
|
if (retval == 0) {
|
2013-11-05 02:46:02 +00:00
|
|
|
device_wakeup_enable(hcd->self.controller);
|
2006-01-22 18:32:13 +00:00
|
|
|
return retval;
|
2013-11-05 02:46:02 +00:00
|
|
|
}
|
2006-01-22 18:32:13 +00:00
|
|
|
|
|
|
|
/* Error handling */
|
|
|
|
at91_stop_hc(pdev);
|
|
|
|
|
2013-12-09 08:51:53 +00:00
|
|
|
err:
|
2006-01-22 18:32:13 +00:00
|
|
|
usb_put_hcd(hcd);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* may be called with controller, bus, and devices active */
|
|
|
|
|
|
|
|
/**
|
2006-06-19 21:27:20 +00:00
|
|
|
* usb_hcd_at91_remove - shutdown processing for AT91-based HCDs
|
2006-01-22 18:32:13 +00: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-19 21:27:20 +00:00
|
|
|
* context, "rmmod" or something similar.
|
2006-01-22 18:32:13 +00:00
|
|
|
*
|
|
|
|
*/
|
2012-11-19 18:26:20 +00:00
|
|
|
static void usb_hcd_at91_remove(struct usb_hcd *hcd,
|
2006-06-19 21:27:20 +00:00
|
|
|
struct platform_device *pdev)
|
2006-01-22 18:32:13 +00:00
|
|
|
{
|
|
|
|
usb_remove_hcd(hcd);
|
|
|
|
at91_stop_hc(pdev);
|
2008-06-01 21:38:43 +00:00
|
|
|
usb_put_hcd(hcd);
|
2006-01-22 18:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
2011-07-13 09:29:17 +00:00
|
|
|
static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
|
|
|
|
{
|
2012-03-21 15:53:09 +00:00
|
|
|
if (!valid_port(port))
|
2011-07-13 09:29:17 +00:00
|
|
|
return;
|
|
|
|
|
2011-09-19 07:32:23 +00:00
|
|
|
if (!gpio_is_valid(pdata->vbus_pin[port]))
|
2011-11-12 15:46:13 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-08 15:32:01 +00:00
|
|
|
gpio_set_value(pdata->vbus_pin[port],
|
2012-03-21 13:38:55 +00:00
|
|
|
pdata->vbus_pin_active_low[port] ^ enable);
|
2011-07-13 09:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
|
|
|
|
{
|
2012-03-21 15:53:09 +00:00
|
|
|
if (!valid_port(port))
|
2011-07-13 09:29:17 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2011-09-19 07:32:23 +00:00
|
|
|
if (!gpio_is_valid(pdata->vbus_pin[port]))
|
2011-11-12 15:46:13 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2011-12-08 15:32:01 +00:00
|
|
|
return gpio_get_value(pdata->vbus_pin[port]) ^
|
2012-03-21 13:38:55 +00:00
|
|
|
pdata->vbus_pin_active_low[port];
|
2011-07-13 09:29:17 +00: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)
|
|
|
|
{
|
2013-09-21 11:08:42 +00:00
|
|
|
struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
|
2014-04-16 16:00:09 +00:00
|
|
|
int length = ohci_hub_status_data(hcd, buf);
|
2011-07-13 09:29:17 +00:00
|
|
|
int port;
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
at91_for_each_port(port) {
|
2011-07-13 09:29:17 +00:00
|
|
|
if (pdata->overcurrent_changed[port]) {
|
2012-03-21 15:53:09 +00:00
|
|
|
if (!length)
|
2011-07-13 09:29:17 +00:00
|
|
|
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)
|
|
|
|
{
|
2013-07-30 10:59:40 +00:00
|
|
|
struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller);
|
2011-07-13 09:29:17 +00:00
|
|
|
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);
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
wIndex--;
|
|
|
|
|
2011-07-13 09:29:17 +00:00
|
|
|
switch (typeReq) {
|
|
|
|
case SetPortFeature:
|
|
|
|
if (wValue == USB_PORT_FEAT_POWER) {
|
|
|
|
dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
|
2012-03-21 15:53:09 +00:00
|
|
|
if (valid_port(wIndex)) {
|
|
|
|
ohci_at91_usb_set_power(pdata, wIndex, 1);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
2011-07-13 09:29:17 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ClearPortFeature:
|
|
|
|
switch (wValue) {
|
|
|
|
case USB_PORT_FEAT_C_OVER_CURRENT:
|
|
|
|
dev_dbg(hcd->self.controller,
|
|
|
|
"ClearPortFeature: C_OVER_CURRENT\n");
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
if (valid_port(wIndex)) {
|
|
|
|
pdata->overcurrent_changed[wIndex] = 0;
|
|
|
|
pdata->overcurrent_status[wIndex] = 0;
|
2011-07-13 09:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
case USB_PORT_FEAT_OVER_CURRENT:
|
|
|
|
dev_dbg(hcd->self.controller,
|
|
|
|
"ClearPortFeature: OVER_CURRENT\n");
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
if (valid_port(wIndex))
|
|
|
|
pdata->overcurrent_status[wIndex] = 0;
|
2011-07-13 09:29:17 +00:00
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
case USB_PORT_FEAT_POWER:
|
|
|
|
dev_dbg(hcd->self.controller,
|
|
|
|
"ClearPortFeature: POWER\n");
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
if (valid_port(wIndex)) {
|
|
|
|
ohci_at91_usb_set_power(pdata, wIndex, 0);
|
2011-07-13 09:29:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-16 16:00:09 +00:00
|
|
|
ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength);
|
2011-07-13 09:29:17 +00:00
|
|
|
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);
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
if (valid_port(wIndex)) {
|
|
|
|
if (!ohci_at91_usb_get_power(pdata, wIndex))
|
2011-07-13 09:29:17 +00:00
|
|
|
*data &= ~cpu_to_le32(RH_PS_PPS);
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
if (pdata->overcurrent_changed[wIndex])
|
2011-07-13 09:29:17 +00:00
|
|
|
*data |= cpu_to_le32(RH_PS_OCIC);
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
if (pdata->overcurrent_status[wIndex])
|
2011-07-13 09:29:17 +00:00
|
|
|
*data |= cpu_to_le32(RH_PS_POCI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-01-22 18:32:13 +00:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2011-07-13 09:29:17 +00:00
|
|
|
static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = data;
|
2013-07-30 10:59:40 +00:00
|
|
|
struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
|
2011-07-13 09:29:17 +00:00
|
|
|
int val, gpio, port;
|
|
|
|
|
|
|
|
/* From the GPIO notifying the over-current situation, find
|
|
|
|
* out the corresponding port */
|
2012-03-21 15:53:09 +00:00
|
|
|
at91_for_each_port(port) {
|
2012-09-23 20:56:00 +00:00
|
|
|
if (gpio_is_valid(pdata->overcurrent_pin[port]) &&
|
|
|
|
gpio_to_irq(pdata->overcurrent_pin[port]) == irq) {
|
2012-02-11 13:23:06 +00:00
|
|
|
gpio = pdata->overcurrent_pin[port];
|
2011-07-13 09:29:17 +00:00
|
|
|
break;
|
2012-02-11 13:23:06 +00:00
|
|
|
}
|
2011-07-13 09:29:17 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
if (port == AT91_MAX_USBH_PORTS) {
|
2011-07-13 09:29:17 +00:00
|
|
|
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. */
|
2012-03-21 15:53:09 +00:00
|
|
|
if (!val) {
|
2011-07-13 09:29:17 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-20 22:55:18 +00:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static const struct of_device_id at91_ohci_dt_ids[] = {
|
|
|
|
{ .compatible = "atmel,at91rm9200-ohci" },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(of, at91_ohci_dt_ids);
|
|
|
|
|
2012-11-19 18:21:48 +00:00
|
|
|
static int ohci_at91_of_init(struct platform_device *pdev)
|
2011-11-20 22:55:18 +00:00
|
|
|
{
|
|
|
|
struct device_node *np = pdev->dev.of_node;
|
2013-06-10 15:28:49 +00:00
|
|
|
int i, gpio, ret;
|
2011-11-20 22:55:18 +00:00
|
|
|
enum of_gpio_flags flags;
|
|
|
|
struct at91_usbh_data *pdata;
|
|
|
|
u32 ports;
|
|
|
|
|
|
|
|
if (!np)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Right now device-tree probed devices don't get dma_mask set.
|
|
|
|
* Since shared usb code relies on it, set it here for now.
|
|
|
|
* Once we have dma capability bindings this can go away.
|
|
|
|
*/
|
2013-06-27 11:36:37 +00:00
|
|
|
ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
|
2013-06-10 15:28:49 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-11-20 22:55:18 +00:00
|
|
|
|
|
|
|
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
|
|
|
|
if (!pdata)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (!of_property_read_u32(np, "num-ports", &ports))
|
|
|
|
pdata->ports = ports;
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
at91_for_each_port(i) {
|
2011-11-20 22:55:18 +00:00
|
|
|
gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i, &flags);
|
|
|
|
pdata->vbus_pin[i] = gpio;
|
|
|
|
if (!gpio_is_valid(gpio))
|
|
|
|
continue;
|
|
|
|
pdata->vbus_pin_active_low[i] = flags & OF_GPIO_ACTIVE_LOW;
|
|
|
|
}
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
at91_for_each_port(i)
|
2012-03-21 15:58:11 +00:00
|
|
|
pdata->overcurrent_pin[i] =
|
|
|
|
of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags);
|
2011-11-20 22:55:18 +00:00
|
|
|
|
|
|
|
pdev->dev.platform_data = pdata;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
2012-11-19 18:21:48 +00:00
|
|
|
static int ohci_at91_of_init(struct platform_device *pdev)
|
2011-11-20 22:55:18 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-07-13 09:29:17 +00:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2012-11-19 18:21:48 +00:00
|
|
|
static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
|
2006-01-22 18:32:13 +00:00
|
|
|
{
|
2011-11-20 22:55:18 +00:00
|
|
|
struct at91_usbh_data *pdata;
|
2007-12-27 19:19:49 +00:00
|
|
|
int i;
|
2012-03-21 15:58:11 +00:00
|
|
|
int gpio;
|
|
|
|
int ret;
|
2007-12-27 19:19:49 +00:00
|
|
|
|
2012-03-28 09:49:01 +00:00
|
|
|
ret = ohci_at91_of_init(pdev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-11-20 22:55:18 +00:00
|
|
|
|
2013-07-30 10:59:40 +00:00
|
|
|
pdata = dev_get_platdata(&pdev->dev);
|
2011-11-20 22:55:18 +00:00
|
|
|
|
2007-12-27 19:19:49 +00:00
|
|
|
if (pdata) {
|
2012-03-21 15:53:09 +00:00
|
|
|
at91_for_each_port(i) {
|
2012-08-29 09:49:18 +00:00
|
|
|
/*
|
|
|
|
* do not configure PIO if not in relation with
|
|
|
|
* real USB port on board
|
|
|
|
*/
|
|
|
|
if (i >= pdata->ports) {
|
|
|
|
pdata->vbus_pin[i] = -EINVAL;
|
|
|
|
pdata->overcurrent_pin[i] = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-19 07:32:23 +00:00
|
|
|
if (!gpio_is_valid(pdata->vbus_pin[i]))
|
2007-12-27 19:19:49 +00:00
|
|
|
continue;
|
2012-03-21 15:58:11 +00:00
|
|
|
gpio = pdata->vbus_pin[i];
|
|
|
|
|
|
|
|
ret = gpio_request(gpio, "ohci_vbus");
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"can't request vbus gpio %d\n", gpio);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ret = gpio_direction_output(gpio,
|
|
|
|
!pdata->vbus_pin_active_low[i]);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"can't put vbus gpio %d as output %d\n",
|
|
|
|
gpio, !pdata->vbus_pin_active_low[i]);
|
|
|
|
gpio_free(gpio);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-07-13 09:29:17 +00:00
|
|
|
ohci_at91_usb_set_power(pdata, i, 1);
|
|
|
|
}
|
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
at91_for_each_port(i) {
|
2011-09-19 07:32:23 +00:00
|
|
|
if (!gpio_is_valid(pdata->overcurrent_pin[i]))
|
2011-07-13 09:29:17 +00:00
|
|
|
continue;
|
2012-03-21 15:58:11 +00:00
|
|
|
gpio = pdata->overcurrent_pin[i];
|
|
|
|
|
|
|
|
ret = gpio_request(gpio, "ohci_overcurrent");
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"can't request overcurrent gpio %d\n",
|
|
|
|
gpio);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gpio_direction_input(gpio);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"can't configure overcurrent gpio %d as input\n",
|
|
|
|
gpio);
|
|
|
|
gpio_free(gpio);
|
|
|
|
continue;
|
|
|
|
}
|
2011-07-13 09:29:17 +00:00
|
|
|
|
2012-03-21 15:58:11 +00:00
|
|
|
ret = request_irq(gpio_to_irq(gpio),
|
2011-07-13 09:29:17 +00:00
|
|
|
ohci_hcd_at91_overcurrent_irq,
|
|
|
|
IRQF_SHARED, "ohci_overcurrent", pdev);
|
|
|
|
if (ret) {
|
2012-03-21 15:58:11 +00:00
|
|
|
gpio_free(gpio);
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"can't get gpio IRQ for overcurrent\n");
|
2011-07-13 09:29:17 +00:00
|
|
|
}
|
2007-12-27 19:19:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-19 21:27:20 +00:00
|
|
|
device_init_wakeup(&pdev->dev, 1);
|
|
|
|
return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
|
2006-01-22 18:32:13 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:20 +00:00
|
|
|
static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
|
2006-01-22 18:32:13 +00:00
|
|
|
{
|
2013-07-30 10:59:40 +00:00
|
|
|
struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
|
2007-12-27 19:19:49 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (pdata) {
|
2012-03-21 15:53:09 +00:00
|
|
|
at91_for_each_port(i) {
|
2011-09-19 07:32:23 +00:00
|
|
|
if (!gpio_is_valid(pdata->vbus_pin[i]))
|
2007-12-27 19:19:49 +00:00
|
|
|
continue;
|
2011-07-13 09:29:17 +00:00
|
|
|
ohci_at91_usb_set_power(pdata, i, 0);
|
2007-12-27 19:19:49 +00:00
|
|
|
gpio_free(pdata->vbus_pin[i]);
|
|
|
|
}
|
2011-07-13 09:29:17 +00:00
|
|
|
|
2012-03-21 15:53:09 +00:00
|
|
|
at91_for_each_port(i) {
|
2011-09-19 07:32:23 +00:00
|
|
|
if (!gpio_is_valid(pdata->overcurrent_pin[i]))
|
2011-07-13 09:29:17 +00:00
|
|
|
continue;
|
|
|
|
free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev);
|
|
|
|
gpio_free(pdata->overcurrent_pin[i]);
|
|
|
|
}
|
2007-12-27 19:19:49 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 21:27:20 +00:00
|
|
|
device_init_wakeup(&pdev->dev, 0);
|
2008-06-01 21:38:43 +00:00
|
|
|
usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
|
|
|
|
return 0;
|
2006-01-22 18:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
2006-04-03 04:26:21 +00:00
|
|
|
static int
|
2006-06-19 21:27:20 +00:00
|
|
|
ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
|
2006-04-03 04:26:21 +00:00
|
|
|
{
|
2006-06-19 21:27:20 +00:00
|
|
|
struct usb_hcd *hcd = platform_get_drvdata(pdev);
|
|
|
|
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
|
2013-11-13 12:10:17 +00:00
|
|
|
bool do_wakeup = device_may_wakeup(&pdev->dev);
|
|
|
|
int ret;
|
2006-06-19 21:27:20 +00:00
|
|
|
|
2013-11-13 12:10:17 +00:00
|
|
|
if (do_wakeup)
|
2006-06-19 21:27:20 +00:00
|
|
|
enable_irq_wake(hcd->irq);
|
|
|
|
|
2013-11-13 12:10:17 +00:00
|
|
|
ret = ohci_suspend(hcd, do_wakeup);
|
|
|
|
if (ret) {
|
|
|
|
disable_irq_wake(hcd->irq);
|
|
|
|
return ret;
|
|
|
|
}
|
2006-06-19 21:27:20 +00:00
|
|
|
/*
|
|
|
|
* 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()) {
|
2013-09-21 11:08:42 +00:00
|
|
|
ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
|
|
|
|
ohci->hc_control &= OHCI_CTRL_RWC;
|
|
|
|
ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
|
|
|
|
ohci->rh_state = OHCI_RH_HALTED;
|
|
|
|
|
2010-04-28 11:45:40 +00:00
|
|
|
/* flush the writes */
|
|
|
|
(void) ohci_readl (ohci, &ohci->regs->control);
|
2007-02-16 18:18:58 +00:00
|
|
|
at91_stop_clock();
|
2006-06-19 21:27:20 +00:00
|
|
|
}
|
2006-01-22 18:32:13 +00:00
|
|
|
|
2013-11-13 12:10:17 +00:00
|
|
|
return ret;
|
2006-01-22 18:32:13 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 21:27:20 +00:00
|
|
|
static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
|
2006-01-22 18:32:13 +00:00
|
|
|
{
|
2007-01-09 22:00:11 +00:00
|
|
|
struct usb_hcd *hcd = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
if (device_may_wakeup(&pdev->dev))
|
|
|
|
disable_irq_wake(hcd->irq);
|
|
|
|
|
2007-02-16 18:18:58 +00:00
|
|
|
if (!clocked)
|
|
|
|
at91_start_clock();
|
2006-01-22 18:32:13 +00:00
|
|
|
|
2012-10-08 13:11:29 +00:00
|
|
|
ohci_resume(hcd, false);
|
2006-01-22 18:32:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define ohci_hcd_at91_drv_suspend NULL
|
|
|
|
#define ohci_hcd_at91_drv_resume NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct platform_driver ohci_hcd_at91_driver = {
|
|
|
|
.probe = ohci_hcd_at91_drv_probe,
|
2012-11-19 18:21:08 +00:00
|
|
|
.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 00:24:08 +00:00
|
|
|
.shutdown = usb_hcd_platform_shutdown,
|
2006-01-22 18:32:13 +00:00
|
|
|
.suspend = ohci_hcd_at91_drv_suspend,
|
|
|
|
.resume = ohci_hcd_at91_drv_resume,
|
|
|
|
.driver = {
|
2006-06-19 21:27:20 +00:00
|
|
|
.name = "at91_ohci",
|
2011-11-20 22:55:18 +00:00
|
|
|
.of_match_table = of_match_ptr(at91_ohci_dt_ids),
|
2006-01-22 18:32:13 +00:00
|
|
|
},
|
|
|
|
};
|
2013-09-21 11:08:42 +00:00
|
|
|
|
|
|
|
static int __init ohci_at91_init(void)
|
|
|
|
{
|
|
|
|
if (usb_disabled())
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
pr_info("%s: " DRIVER_DESC "\n", hcd_name);
|
|
|
|
ohci_init_driver(&ohci_at91_hc_driver, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The Atmel HW has some unusual quirks, which require Atmel-specific
|
|
|
|
* workarounds. We override certain hc_driver functions here to
|
|
|
|
* achieve that. We explicitly do not enhance ohci_driver_overrides to
|
|
|
|
* allow this more easily, since this is an unusual case, and we don't
|
|
|
|
* want to encourage others to override these functions by making it
|
|
|
|
* too easy.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ohci_at91_hc_driver.hub_status_data = ohci_at91_hub_status_data;
|
|
|
|
ohci_at91_hc_driver.hub_control = ohci_at91_hub_control;
|
|
|
|
|
|
|
|
return platform_driver_register(&ohci_hcd_at91_driver);
|
|
|
|
}
|
|
|
|
module_init(ohci_at91_init);
|
|
|
|
|
|
|
|
static void __exit ohci_at91_cleanup(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&ohci_hcd_at91_driver);
|
|
|
|
}
|
|
|
|
module_exit(ohci_at91_cleanup);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:at91_ohci");
|