2017-11-03 18:28:30 +08:00
|
|
|
// SPDX-License-Identifier: GPL-1.0+
|
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>
|
2013-09-21 19:08:42 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
2016-09-29 17:59:02 +08:00
|
|
|
#include <linux/gpio/consumer.h>
|
2011-11-21 06:55:18 +08:00
|
|
|
#include <linux/of_platform.h>
|
2013-09-21 19:08:42 +08:00
|
|
|
#include <linux/platform_device.h>
|
2012-10-30 05:12:23 +08:00
|
|
|
#include <linux/platform_data/atmel.h>
|
2013-09-21 19:08:42 +08:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2016-08-23 09:05:29 +08:00
|
|
|
#include <linux/mfd/syscon.h>
|
|
|
|
#include <linux/regmap.h>
|
2013-09-21 19:08:42 +08:00
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/usb/hcd.h>
|
2016-08-23 09:05:29 +08:00
|
|
|
#include <soc/at91/atmel-sfr.h>
|
2006-01-23 02:32:13 +08:00
|
|
|
|
2013-09-21 19:08:42 +08:00
|
|
|
#include "ohci.h"
|
2006-01-23 02:32:13 +08:00
|
|
|
|
2012-03-21 23:53:09 +08: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-02 01:09:13 +08:00
|
|
|
/* interface, function and usb clocks; sometimes also an AHB clock */
|
2015-01-20 21:39:02 +08:00
|
|
|
#define hcd_to_ohci_at91_priv(h) \
|
|
|
|
((struct ohci_at91_priv *)hcd_to_ohci(h)->priv)
|
|
|
|
|
2015-08-10 22:23:09 +08:00
|
|
|
#define AT91_MAX_USBH_PORTS 3
|
|
|
|
struct at91_usbh_data {
|
2016-09-29 17:59:02 +08:00
|
|
|
struct gpio_desc *vbus_pin[AT91_MAX_USBH_PORTS];
|
|
|
|
struct gpio_desc *overcurrent_pin[AT91_MAX_USBH_PORTS];
|
2015-08-10 22:23:09 +08:00
|
|
|
u8 ports; /* number of ports on root hub */
|
|
|
|
u8 overcurrent_supported;
|
|
|
|
u8 overcurrent_status[AT91_MAX_USBH_PORTS];
|
|
|
|
u8 overcurrent_changed[AT91_MAX_USBH_PORTS];
|
|
|
|
};
|
|
|
|
|
2015-01-20 21:39:02 +08:00
|
|
|
struct ohci_at91_priv {
|
|
|
|
struct clk *iclk;
|
|
|
|
struct clk *fclk;
|
|
|
|
struct clk *hclk;
|
|
|
|
bool clocked;
|
2015-01-20 21:39:04 +08:00
|
|
|
bool wakeup; /* Saved wake-up state for resume */
|
2016-08-23 09:05:29 +08:00
|
|
|
struct regmap *sfr_regmap;
|
2015-01-20 21:39:02 +08:00
|
|
|
};
|
2013-09-21 19:08:42 +08: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;
|
2015-01-20 21:39:02 +08:00
|
|
|
|
|
|
|
static const struct ohci_driver_overrides ohci_at91_drv_overrides __initconst = {
|
|
|
|
.extra_priv_size = sizeof(struct ohci_at91_priv),
|
|
|
|
};
|
2006-01-23 02:32:13 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2015-01-20 21:39:02 +08:00
|
|
|
static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
|
2007-02-17 02:18:58 +08:00
|
|
|
{
|
2015-01-20 21:39:04 +08:00
|
|
|
if (ohci_at91->clocked)
|
|
|
|
return;
|
2015-03-18 00:15:47 +08:00
|
|
|
|
|
|
|
clk_set_rate(ohci_at91->fclk, 48000000);
|
2015-01-20 21:39:02 +08:00
|
|
|
clk_prepare_enable(ohci_at91->hclk);
|
|
|
|
clk_prepare_enable(ohci_at91->iclk);
|
|
|
|
clk_prepare_enable(ohci_at91->fclk);
|
|
|
|
ohci_at91->clocked = true;
|
2007-02-17 02:18:58 +08:00
|
|
|
}
|
|
|
|
|
2015-01-20 21:39:02 +08:00
|
|
|
static void at91_stop_clock(struct ohci_at91_priv *ohci_at91)
|
2007-02-17 02:18:58 +08:00
|
|
|
{
|
2015-01-20 21:39:04 +08:00
|
|
|
if (!ohci_at91->clocked)
|
|
|
|
return;
|
2015-03-18 00:15:47 +08:00
|
|
|
|
2015-01-20 21:39:02 +08:00
|
|
|
clk_disable_unprepare(ohci_at91->fclk);
|
|
|
|
clk_disable_unprepare(ohci_at91->iclk);
|
|
|
|
clk_disable_unprepare(ohci_at91->hclk);
|
|
|
|
ohci_at91->clocked = false;
|
2007-02-17 02:18:58 +08:00
|
|
|
}
|
|
|
|
|
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;
|
2015-01-20 21:39:02 +08:00
|
|
|
struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
|
2006-01-23 02:32:13 +08:00
|
|
|
|
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.
|
|
|
|
*/
|
2015-01-20 21:39:02 +08:00
|
|
|
at91_start_clock(ohci_at91);
|
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;
|
2015-01-20 21:39:02 +08:00
|
|
|
struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
|
2006-01-23 02:32:13 +08:00
|
|
|
|
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.
|
|
|
|
*/
|
2015-01-20 21:39:02 +08:00
|
|
|
at91_stop_clock(ohci_at91);
|
2006-01-23 02:32:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2012-11-20 02:26:20 +08:00
|
|
|
static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
|
2006-01-23 02:32:13 +08:00
|
|
|
|
2016-09-10 19:53:42 +08:00
|
|
|
static struct regmap *at91_dt_syscon_sfr(void)
|
2016-08-23 09:05:29 +08:00
|
|
|
{
|
|
|
|
struct regmap *regmap;
|
|
|
|
|
|
|
|
regmap = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr");
|
|
|
|
if (IS_ERR(regmap))
|
|
|
|
regmap = NULL;
|
|
|
|
|
|
|
|
return regmap;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2012-11-20 02:21:48 +08:00
|
|
|
static int usb_hcd_at91_probe(const struct hc_driver *driver,
|
2006-06-20 05:27:20 +08:00
|
|
|
struct platform_device *pdev)
|
2006-01-23 02:32:13 +08:00
|
|
|
{
|
2013-09-21 19:08:42 +08:00
|
|
|
struct at91_usbh_data *board;
|
|
|
|
struct ohci_hcd *ohci;
|
2006-01-23 02:32:13 +08:00
|
|
|
int retval;
|
2015-01-20 21:39:03 +08:00
|
|
|
struct usb_hcd *hcd;
|
2015-01-20 21:39:02 +08:00
|
|
|
struct ohci_at91_priv *ohci_at91;
|
2013-12-08 22:59:59 +08: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-23 02:32:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 16:51:54 +08:00
|
|
|
hcd = usb_create_hcd(driver, dev, "at91");
|
2006-01-23 02:32:13 +08:00
|
|
|
if (!hcd)
|
|
|
|
return -ENOMEM;
|
2015-01-20 21:39:02 +08:00
|
|
|
ohci_at91 = hcd_to_ohci_at91_priv(hcd);
|
2006-01-23 02:32:13 +08:00
|
|
|
|
2014-11-04 10:21:12 +08:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2013-12-09 16:51:53 +08:00
|
|
|
hcd->regs = devm_ioremap_resource(dev, res);
|
|
|
|
if (IS_ERR(hcd->regs)) {
|
|
|
|
retval = PTR_ERR(hcd->regs);
|
|
|
|
goto err;
|
2006-01-23 02:32:13 +08:00
|
|
|
}
|
2014-11-04 10:21:12 +08:00
|
|
|
hcd->rsrc_start = res->start;
|
|
|
|
hcd->rsrc_len = resource_size(res);
|
2006-01-23 02:32:13 +08:00
|
|
|
|
2015-01-20 21:39:02 +08:00
|
|
|
ohci_at91->iclk = devm_clk_get(dev, "ohci_clk");
|
|
|
|
if (IS_ERR(ohci_at91->iclk)) {
|
2013-12-09 16:51:54 +08:00
|
|
|
dev_err(dev, "failed to get ohci_clk\n");
|
2015-01-20 21:39:02 +08:00
|
|
|
retval = PTR_ERR(ohci_at91->iclk);
|
2013-12-09 16:51:53 +08:00
|
|
|
goto err;
|
2011-12-08 23:32:00 +08:00
|
|
|
}
|
2015-01-20 21:39:02 +08:00
|
|
|
ohci_at91->fclk = devm_clk_get(dev, "uhpck");
|
|
|
|
if (IS_ERR(ohci_at91->fclk)) {
|
2013-12-09 16:51:54 +08:00
|
|
|
dev_err(dev, "failed to get uhpck\n");
|
2015-01-20 21:39:02 +08:00
|
|
|
retval = PTR_ERR(ohci_at91->fclk);
|
2013-12-09 16:51:55 +08:00
|
|
|
goto err;
|
2011-12-08 23:32:00 +08:00
|
|
|
}
|
2015-01-20 21:39:02 +08:00
|
|
|
ohci_at91->hclk = devm_clk_get(dev, "hclk");
|
|
|
|
if (IS_ERR(ohci_at91->hclk)) {
|
2013-12-09 16:51:54 +08:00
|
|
|
dev_err(dev, "failed to get hclk\n");
|
2015-01-20 21:39:02 +08:00
|
|
|
retval = PTR_ERR(ohci_at91->hclk);
|
2013-12-09 16:51:55 +08:00
|
|
|
goto err;
|
2011-12-08 23:32:00 +08:00
|
|
|
}
|
2006-01-23 02:32:13 +08:00
|
|
|
|
2016-08-23 09:05:29 +08:00
|
|
|
ohci_at91->sfr_regmap = at91_dt_syscon_sfr();
|
|
|
|
if (!ohci_at91->sfr_regmap)
|
|
|
|
dev_warn(dev, "failed to find sfr node\n");
|
|
|
|
|
2013-09-21 19:08:42 +08:00
|
|
|
board = hcd->self.controller->platform_data;
|
|
|
|
ohci = hcd_to_ohci(hcd);
|
|
|
|
ohci->num_ports = board->ports;
|
2006-01-23 02:32:13 +08:00
|
|
|
at91_start_hc(pdev);
|
|
|
|
|
2016-09-29 18:07:07 +08:00
|
|
|
/*
|
|
|
|
* The RemoteWakeupConnected bit has to be set explicitly
|
|
|
|
* before calling ohci_run. The reset value of this bit is 0.
|
|
|
|
*/
|
|
|
|
ohci->hc_control = OHCI_CTRL_RWC;
|
|
|
|
|
2013-12-08 22:59:59 +08:00
|
|
|
retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
|
2014-01-07 19:54:58 +08:00
|
|
|
if (retval == 0) {
|
2013-11-05 10:46:02 +08:00
|
|
|
device_wakeup_enable(hcd->self.controller);
|
2006-01-23 02:32:13 +08:00
|
|
|
return retval;
|
2013-11-05 10:46:02 +08:00
|
|
|
}
|
2006-01-23 02:32:13 +08:00
|
|
|
|
|
|
|
/* Error handling */
|
|
|
|
at91_stop_hc(pdev);
|
|
|
|
|
2013-12-09 16:51:53 +08:00
|
|
|
err:
|
2006-01-23 02:32:13 +08:00
|
|
|
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
|
|
|
*
|
|
|
|
*/
|
2012-11-20 02:26:20 +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);
|
2008-06-02 05:38:43 +08:00
|
|
|
usb_put_hcd(hcd);
|
2006-01-23 02:32:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
2011-07-13 17:29:17 +08:00
|
|
|
static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
|
|
|
|
{
|
2012-03-21 23:53:09 +08:00
|
|
|
if (!valid_port(port))
|
2011-07-13 17:29:17 +08:00
|
|
|
return;
|
|
|
|
|
2016-12-22 15:43:55 +08:00
|
|
|
gpiod_set_value(pdata->vbus_pin[port], enable);
|
2011-07-13 17:29:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
|
|
|
|
{
|
2012-03-21 23:53:09 +08:00
|
|
|
if (!valid_port(port))
|
2011-07-13 17:29:17 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-12-22 15:43:55 +08:00
|
|
|
return gpiod_get_value(pdata->vbus_pin[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)
|
|
|
|
{
|
2013-09-21 19:08:42 +08:00
|
|
|
struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
|
2014-04-17 00:00:09 +08:00
|
|
|
int length = ohci_hub_status_data(hcd, buf);
|
2011-07-13 17:29:17 +08:00
|
|
|
int port;
|
|
|
|
|
2012-03-21 23:53:09 +08:00
|
|
|
at91_for_each_port(port) {
|
2011-07-13 17:29:17 +08:00
|
|
|
if (pdata->overcurrent_changed[port]) {
|
2012-03-21 23:53:09 +08:00
|
|
|
if (!length)
|
2011-07-13 17:29:17 +08:00
|
|
|
length = 1;
|
|
|
|
buf[0] |= 1 << (port + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2016-08-23 09:05:29 +08:00
|
|
|
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, ®val);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-07-13 17:29:17 +08:00
|
|
|
/*
|
|
|
|
* 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 18:59:40 +08:00
|
|
|
struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller);
|
2016-08-23 09:05:29 +08:00
|
|
|
struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
|
2011-07-13 17:29:17 +08: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 23:53:09 +08:00
|
|
|
wIndex--;
|
|
|
|
|
2011-07-13 17:29:17 +08:00
|
|
|
switch (typeReq) {
|
|
|
|
case SetPortFeature:
|
2016-08-23 09:05:29 +08:00
|
|
|
switch (wValue) {
|
|
|
|
case USB_PORT_FEAT_POWER:
|
2011-07-13 17:29:17 +08:00
|
|
|
dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
|
2012-03-21 23:53:09 +08:00
|
|
|
if (valid_port(wIndex)) {
|
|
|
|
ohci_at91_usb_set_power(pdata, wIndex, 1);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
2011-07-13 17:29:17 +08:00
|
|
|
goto out;
|
2016-08-23 09:05:29 +08:00
|
|
|
|
|
|
|
case USB_PORT_FEAT_SUSPEND:
|
|
|
|
dev_dbg(hcd->self.controller, "SetPortFeat: SUSPEND\n");
|
2017-02-21 19:48:18 +08:00
|
|
|
if (valid_port(wIndex) && ohci_at91->sfr_regmap) {
|
2016-08-23 09:05:29 +08:00
|
|
|
ohci_at91_port_suspend(ohci_at91->sfr_regmap,
|
|
|
|
1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2011-07-13 17:29:17 +08:00
|
|
|
}
|
|
|
|
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 23:53:09 +08:00
|
|
|
if (valid_port(wIndex)) {
|
|
|
|
pdata->overcurrent_changed[wIndex] = 0;
|
|
|
|
pdata->overcurrent_status[wIndex] = 0;
|
2011-07-13 17:29:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
case USB_PORT_FEAT_OVER_CURRENT:
|
|
|
|
dev_dbg(hcd->self.controller,
|
|
|
|
"ClearPortFeature: OVER_CURRENT\n");
|
|
|
|
|
2012-03-21 23:53:09 +08:00
|
|
|
if (valid_port(wIndex))
|
|
|
|
pdata->overcurrent_status[wIndex] = 0;
|
2011-07-13 17:29:17 +08:00
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
case USB_PORT_FEAT_POWER:
|
|
|
|
dev_dbg(hcd->self.controller,
|
|
|
|
"ClearPortFeature: POWER\n");
|
|
|
|
|
2012-03-21 23:53:09 +08:00
|
|
|
if (valid_port(wIndex)) {
|
|
|
|
ohci_at91_usb_set_power(pdata, wIndex, 0);
|
2011-07-13 17:29:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2016-08-23 09:05:29 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_PORT_FEAT_SUSPEND:
|
|
|
|
dev_dbg(hcd->self.controller, "ClearPortFeature: SUSPEND\n");
|
2017-02-21 19:48:18 +08:00
|
|
|
if (valid_port(wIndex) && ohci_at91->sfr_regmap) {
|
2016-08-23 09:05:29 +08:00
|
|
|
ohci_at91_port_suspend(ohci_at91->sfr_regmap,
|
|
|
|
0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2011-07-13 17:29:17 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-17 00:00:09 +08:00
|
|
|
ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength);
|
2011-07-13 17:29:17 +08: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);
|
2015-01-19 06:39:44 +08:00
|
|
|
desc->wHubCharacteristics |=
|
|
|
|
cpu_to_le16(HUB_CHAR_INDV_PORT_LPSM);
|
2011-07-13 17:29:17 +08:00
|
|
|
|
|
|
|
if (pdata->overcurrent_supported) {
|
|
|
|
desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM);
|
2015-01-19 06:39:44 +08:00
|
|
|
desc->wHubCharacteristics |=
|
|
|
|
cpu_to_le16(HUB_CHAR_INDV_PORT_OCPM);
|
2011-07-13 17:29:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 23:53:09 +08:00
|
|
|
if (valid_port(wIndex)) {
|
|
|
|
if (!ohci_at91_usb_get_power(pdata, wIndex))
|
2011-07-13 17:29:17 +08:00
|
|
|
*data &= ~cpu_to_le32(RH_PS_PPS);
|
|
|
|
|
2012-03-21 23:53:09 +08:00
|
|
|
if (pdata->overcurrent_changed[wIndex])
|
2011-07-13 17:29:17 +08:00
|
|
|
*data |= cpu_to_le32(RH_PS_OCIC);
|
|
|
|
|
2012-03-21 23:53:09 +08:00
|
|
|
if (pdata->overcurrent_status[wIndex])
|
2011-07-13 17:29:17 +08:00
|
|
|
*data |= cpu_to_le32(RH_PS_POCI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-01-23 02:32:13 +08:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
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;
|
2013-07-30 18:59:40 +08:00
|
|
|
struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
|
2016-09-29 17:59:02 +08:00
|
|
|
int val, port;
|
2011-07-13 17:29:17 +08:00
|
|
|
|
|
|
|
/* From the GPIO notifying the over-current situation, find
|
|
|
|
* out the corresponding port */
|
2012-03-21 23:53:09 +08:00
|
|
|
at91_for_each_port(port) {
|
2016-09-29 17:59:02 +08:00
|
|
|
if (gpiod_to_irq(pdata->overcurrent_pin[port]) == irq)
|
2011-07-13 17:29:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-21 23:53:09 +08:00
|
|
|
if (port == AT91_MAX_USBH_PORTS) {
|
2011-07-13 17:29:17 +08:00
|
|
|
dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n");
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2016-09-29 17:59:02 +08:00
|
|
|
val = gpiod_get_value(pdata->overcurrent_pin[port]);
|
2011-07-13 17:29:17 +08:00
|
|
|
|
|
|
|
/* When notified of an over-current situation, disable power
|
|
|
|
on the corresponding port, and mark this port in
|
|
|
|
over-current. */
|
2012-03-21 23:53:09 +08:00
|
|
|
if (!val) {
|
2011-07-13 17:29:17 +08: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-21 06:55:18 +08:00
|
|
|
static const struct of_device_id at91_ohci_dt_ids[] = {
|
|
|
|
{ .compatible = "atmel,at91rm9200-ohci" },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(of, at91_ohci_dt_ids);
|
|
|
|
|
2015-08-10 22:23:11 +08:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
|
2011-11-21 06:55:18 +08:00
|
|
|
{
|
|
|
|
struct device_node *np = pdev->dev.of_node;
|
|
|
|
struct at91_usbh_data *pdata;
|
2015-08-10 22:23:11 +08:00
|
|
|
int i;
|
|
|
|
int ret;
|
2016-09-29 17:59:02 +08:00
|
|
|
int err;
|
2015-08-10 22:23:11 +08:00
|
|
|
u32 ports;
|
2011-11-21 06:55:18 +08:00
|
|
|
|
|
|
|
/* 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 19:36:37 +08:00
|
|
|
ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
|
2013-06-10 23:28:49 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-11-21 06:55:18 +08:00
|
|
|
|
|
|
|
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
|
|
|
|
if (!pdata)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-12-03 03:36:55 +08:00
|
|
|
pdev->dev.platform_data = pdata;
|
|
|
|
|
2011-11-21 06:55:18 +08:00
|
|
|
if (!of_property_read_u32(np, "num-ports", &ports))
|
|
|
|
pdata->ports = ports;
|
|
|
|
|
2015-08-10 22:23:11 +08:00
|
|
|
at91_for_each_port(i) {
|
2016-12-22 15:43:55 +08:00
|
|
|
if (i >= pdata->ports)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pdata->vbus_pin[i] =
|
|
|
|
devm_gpiod_get_index_optional(&pdev->dev, "atmel,vbus",
|
|
|
|
i, GPIOD_OUT_HIGH);
|
2016-09-29 17:59:02 +08:00
|
|
|
if (IS_ERR(pdata->vbus_pin[i])) {
|
|
|
|
err = PTR_ERR(pdata->vbus_pin[i]);
|
|
|
|
dev_err(&pdev->dev, "unable to claim gpio \"vbus\": %d\n", err);
|
2015-08-10 22:23:12 +08:00
|
|
|
continue;
|
2015-08-10 22:23:11 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-21 23:58:11 +08:00
|
|
|
|
2015-08-10 22:23:11 +08:00
|
|
|
at91_for_each_port(i) {
|
2015-12-03 03:36:55 +08:00
|
|
|
if (i >= pdata->ports)
|
|
|
|
break;
|
2015-08-10 22:23:12 +08:00
|
|
|
|
|
|
|
pdata->overcurrent_pin[i] =
|
2016-12-22 15:43:55 +08:00
|
|
|
devm_gpiod_get_index_optional(&pdev->dev, "atmel,oc",
|
|
|
|
i, GPIOD_IN);
|
2016-09-29 17:59:02 +08:00
|
|
|
if (IS_ERR(pdata->overcurrent_pin[i])) {
|
|
|
|
err = PTR_ERR(pdata->overcurrent_pin[i]);
|
|
|
|
dev_err(&pdev->dev, "unable to claim gpio \"overcurrent\": %d\n", err);
|
2015-08-10 22:23:11 +08:00
|
|
|
continue;
|
2011-07-13 17:29:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-29 17:59:02 +08:00
|
|
|
ret = devm_request_irq(&pdev->dev,
|
|
|
|
gpiod_to_irq(pdata->overcurrent_pin[i]),
|
|
|
|
ohci_hcd_at91_overcurrent_irq,
|
|
|
|
IRQF_SHARED,
|
|
|
|
"ohci_overcurrent", pdev);
|
|
|
|
if (ret)
|
|
|
|
dev_info(&pdev->dev, "failed to request gpio \"overcurrent\" IRQ\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
|
|
|
}
|
|
|
|
|
2012-11-20 02:26:20 +08:00
|
|
|
static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
|
2006-01-23 02:32:13 +08:00
|
|
|
{
|
2013-07-30 18:59:40 +08:00
|
|
|
struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
|
2007-12-28 03:19:49 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (pdata) {
|
2016-09-29 17:59:02 +08:00
|
|
|
at91_for_each_port(i)
|
2011-07-13 17:29:17 +08:00
|
|
|
ohci_at91_usb_set_power(pdata, i, 0);
|
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
|
|
|
}
|
|
|
|
|
2016-03-02 23:24:05 +08:00
|
|
|
static int __maybe_unused
|
2015-01-20 21:39:00 +08:00
|
|
|
ohci_hcd_at91_drv_suspend(struct device *dev)
|
2006-04-03 12:26:21 +08:00
|
|
|
{
|
2015-01-20 21:39:00 +08:00
|
|
|
struct usb_hcd *hcd = dev_get_drvdata(dev);
|
2006-06-20 05:27:20 +08:00
|
|
|
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
|
2015-01-20 21:39:02 +08:00
|
|
|
struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
|
2013-11-13 20:10:17 +08:00
|
|
|
int ret;
|
2006-06-20 05:27:20 +08:00
|
|
|
|
2015-01-20 21:39:04 +08:00
|
|
|
/*
|
|
|
|
* Disable wakeup if we are going to sleep with slow clock mode
|
|
|
|
* enabled.
|
|
|
|
*/
|
|
|
|
ohci_at91->wakeup = device_may_wakeup(dev)
|
|
|
|
&& !at91_suspend_entering_slow_clock();
|
|
|
|
|
|
|
|
if (ohci_at91->wakeup)
|
2006-06-20 05:27:20 +08:00
|
|
|
enable_irq_wake(hcd->irq);
|
|
|
|
|
2016-08-23 09:05:29 +08:00
|
|
|
ohci_at91_port_suspend(ohci_at91->sfr_regmap, 1);
|
|
|
|
|
2015-01-20 21:39:04 +08:00
|
|
|
ret = ohci_suspend(hcd, ohci_at91->wakeup);
|
2013-11-13 20:10:17 +08:00
|
|
|
if (ret) {
|
2015-01-20 21:39:04 +08:00
|
|
|
if (ohci_at91->wakeup)
|
|
|
|
disable_irq_wake(hcd->irq);
|
2013-11-13 20:10:17 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2006-06-20 05:27:20 +08: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...
|
|
|
|
*/
|
2015-01-20 21:39:04 +08:00
|
|
|
if (!ohci_at91->wakeup) {
|
2013-09-21 19:08:42 +08:00
|
|
|
ohci->rh_state = OHCI_RH_HALTED;
|
|
|
|
|
2010-04-28 19:45:40 +08:00
|
|
|
/* flush the writes */
|
|
|
|
(void) ohci_readl (ohci, &ohci->regs->control);
|
2015-01-20 21:39:02 +08:00
|
|
|
at91_stop_clock(ohci_at91);
|
2006-06-20 05:27:20 +08:00
|
|
|
}
|
2006-01-23 02:32:13 +08:00
|
|
|
|
2013-11-13 20:10:17 +08:00
|
|
|
return ret;
|
2006-01-23 02:32:13 +08:00
|
|
|
}
|
|
|
|
|
2016-03-02 23:24:05 +08:00
|
|
|
static int __maybe_unused
|
|
|
|
ohci_hcd_at91_drv_resume(struct device *dev)
|
2006-01-23 02:32:13 +08:00
|
|
|
{
|
2015-01-20 21:39:00 +08:00
|
|
|
struct usb_hcd *hcd = dev_get_drvdata(dev);
|
2015-01-20 21:39:02 +08:00
|
|
|
struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
|
2007-01-10 06:00:11 +08:00
|
|
|
|
2015-01-20 21:39:04 +08:00
|
|
|
if (ohci_at91->wakeup)
|
2007-01-10 06:00:11 +08:00
|
|
|
disable_irq_wake(hcd->irq);
|
|
|
|
|
2015-01-20 21:39:04 +08:00
|
|
|
at91_start_clock(ohci_at91);
|
2006-01-23 02:32:13 +08:00
|
|
|
|
2012-10-08 21:11:29 +08:00
|
|
|
ohci_resume(hcd, false);
|
2016-08-23 09:05:29 +08:00
|
|
|
|
|
|
|
ohci_at91_port_suspend(ohci_at91->sfr_regmap, 0);
|
|
|
|
|
2006-01-23 02:32:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-20 21:39:00 +08:00
|
|
|
static SIMPLE_DEV_PM_OPS(ohci_hcd_at91_pm_ops, ohci_hcd_at91_drv_suspend,
|
|
|
|
ohci_hcd_at91_drv_resume);
|
|
|
|
|
2006-01-23 02:32:13 +08:00
|
|
|
static struct platform_driver ohci_hcd_at91_driver = {
|
|
|
|
.probe = ohci_hcd_at91_drv_probe,
|
2012-11-20 02:21:08 +08: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 08:24:08 +08:00
|
|
|
.shutdown = usb_hcd_platform_shutdown,
|
2006-01-23 02:32:13 +08:00
|
|
|
.driver = {
|
2006-06-20 05:27:20 +08:00
|
|
|
.name = "at91_ohci",
|
2015-01-20 21:39:00 +08:00
|
|
|
.pm = &ohci_hcd_at91_pm_ops,
|
2015-08-10 22:23:10 +08:00
|
|
|
.of_match_table = at91_ohci_dt_ids,
|
2006-01-23 02:32:13 +08:00
|
|
|
},
|
|
|
|
};
|
2013-09-21 19:08:42 +08:00
|
|
|
|
|
|
|
static int __init ohci_at91_init(void)
|
|
|
|
{
|
|
|
|
if (usb_disabled())
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
pr_info("%s: " DRIVER_DESC "\n", hcd_name);
|
2015-01-20 21:39:02 +08:00
|
|
|
ohci_init_driver(&ohci_at91_hc_driver, &ohci_at91_drv_overrides);
|
2013-09-21 19:08:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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");
|