2008-07-21 17:08:14 +00:00
|
|
|
/*
|
2008-11-30 20:09:43 +00:00
|
|
|
* Bus Glue for Atheros AR71xx built-in EHCI controller.
|
2008-07-21 17:08:14 +00:00
|
|
|
*
|
2010-02-06 17:00:16 +00:00
|
|
|
* Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
|
2008-11-30 20:09:43 +00:00
|
|
|
* Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
|
2008-07-21 17:08:14 +00:00
|
|
|
*
|
2008-11-30 20:09:43 +00:00
|
|
|
* Parts of this file are based on Atheros' 2.6.15 BSP
|
|
|
|
* Copyright (C) 2007 Atheros Communications, Inc.
|
2008-07-21 17:08:14 +00:00
|
|
|
*
|
2008-11-30 20:09:43 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published
|
|
|
|
* by the Free Software Foundation.
|
2008-07-21 17:08:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
|
2008-12-03 15:54:08 +00:00
|
|
|
#include <asm/mach-ar71xx/platform.h>
|
|
|
|
|
2008-07-21 17:08:14 +00:00
|
|
|
extern int usb_disabled(void);
|
|
|
|
|
2008-12-04 18:16:05 +00:00
|
|
|
static int ehci_ar71xx_init(struct usb_hcd *hcd)
|
2008-07-21 17:08:14 +00:00
|
|
|
{
|
2008-12-04 18:16:05 +00:00
|
|
|
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ehci->caps = hcd->regs;
|
|
|
|
ehci->regs = hcd->regs +
|
|
|
|
HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
|
|
|
|
ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
|
|
|
|
|
|
|
|
ehci->sbrn = 0x20;
|
2009-04-23 12:25:49 +00:00
|
|
|
ehci->has_synopsys_hc_bug = 1;
|
2008-12-04 18:16:05 +00:00
|
|
|
|
|
|
|
ehci_reset(ehci);
|
|
|
|
|
|
|
|
ret = ehci_init(hcd);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ehci_port_power(ehci, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ehci_ar91xx_init(struct usb_hcd *hcd)
|
|
|
|
{
|
|
|
|
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ehci->caps = hcd->regs + 0x100;
|
|
|
|
ehci->regs = hcd->regs + 0x100 +
|
|
|
|
HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
|
|
|
|
ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
|
|
|
|
|
|
|
|
hcd->has_tt = 1;
|
|
|
|
ehci->sbrn = 0x20;
|
|
|
|
|
|
|
|
ehci_reset(ehci);
|
|
|
|
|
|
|
|
ret = ehci_init(hcd);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ehci_port_power(ehci, 0);
|
|
|
|
|
|
|
|
return 0;
|
2008-07-21 17:08:14 +00:00
|
|
|
}
|
|
|
|
|
2008-11-30 20:09:43 +00:00
|
|
|
static int ehci_ar71xx_probe(const struct hc_driver *driver,
|
|
|
|
struct usb_hcd **hcd_out,
|
|
|
|
struct platform_device *pdev)
|
2008-07-21 17:08:14 +00:00
|
|
|
{
|
|
|
|
struct usb_hcd *hcd;
|
|
|
|
struct resource *res;
|
|
|
|
int irq;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
|
|
|
if (!res) {
|
|
|
|
dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
|
2009-05-05 19:21:39 +00:00
|
|
|
dev_name(&pdev->dev));
|
2008-07-21 17:08:14 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
irq = res->start;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res) {
|
|
|
|
dev_dbg(&pdev->dev, "no base address specified for %s\n",
|
2009-05-05 19:21:39 +00:00
|
|
|
dev_name(&pdev->dev));
|
2008-11-30 20:09:43 +00:00
|
|
|
return -ENODEV;
|
2008-07-21 17:08:14 +00:00
|
|
|
}
|
2008-11-30 20:09:43 +00:00
|
|
|
|
2009-05-05 19:21:39 +00:00
|
|
|
hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
|
2008-11-30 20:09:43 +00:00
|
|
|
if (!hcd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2008-07-21 17:08:14 +00:00
|
|
|
hcd->rsrc_start = res->start;
|
|
|
|
hcd->rsrc_len = res->end - res->start + 1;
|
|
|
|
|
|
|
|
if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
|
|
|
|
dev_dbg(&pdev->dev, "controller already in use\n");
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto err_put_hcd;
|
|
|
|
}
|
|
|
|
|
|
|
|
hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
|
|
|
|
if (!hcd->regs) {
|
|
|
|
dev_dbg(&pdev->dev, "error mapping memory\n");
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err_release_region;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
|
|
|
|
if (ret)
|
2008-11-30 11:07:22 +00:00
|
|
|
goto err_iounmap;
|
2008-07-21 17:08:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2010-11-12 18:50:29 +00:00
|
|
|
err_iounmap:
|
2008-07-21 17:08:14 +00:00
|
|
|
iounmap(hcd->regs);
|
|
|
|
|
2010-11-12 18:50:29 +00:00
|
|
|
err_release_region:
|
2008-07-21 17:08:14 +00:00
|
|
|
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
|
2010-11-12 18:50:29 +00:00
|
|
|
err_put_hcd:
|
2008-07-21 17:08:14 +00:00
|
|
|
usb_put_hcd(hcd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-30 20:09:43 +00:00
|
|
|
static void ehci_ar71xx_remove(struct usb_hcd *hcd,
|
|
|
|
struct platform_device *pdev)
|
2008-07-21 17:08:14 +00:00
|
|
|
{
|
|
|
|
usb_remove_hcd(hcd);
|
|
|
|
iounmap(hcd->regs);
|
|
|
|
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
|
|
|
|
usb_put_hcd(hcd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct hc_driver ehci_ar71xx_hc_driver = {
|
2008-11-30 11:07:22 +00:00
|
|
|
.description = hcd_name,
|
|
|
|
.product_desc = "Atheros AR71xx built-in EHCI controller",
|
|
|
|
.hcd_priv_size = sizeof(struct ehci_hcd),
|
|
|
|
|
|
|
|
.irq = ehci_irq,
|
|
|
|
.flags = HCD_MEMORY | HCD_USB2,
|
2008-07-21 17:08:14 +00:00
|
|
|
|
2008-12-04 18:16:05 +00:00
|
|
|
.reset = ehci_ar71xx_init,
|
2008-11-30 11:07:22 +00:00
|
|
|
.start = ehci_run,
|
|
|
|
.stop = ehci_stop,
|
|
|
|
.shutdown = ehci_shutdown,
|
2008-07-21 17:08:14 +00:00
|
|
|
|
|
|
|
.urb_enqueue = ehci_urb_enqueue,
|
|
|
|
.urb_dequeue = ehci_urb_dequeue,
|
|
|
|
.endpoint_disable = ehci_endpoint_disable,
|
2010-02-06 17:00:16 +00:00
|
|
|
.endpoint_reset = ehci_endpoint_reset,
|
2008-07-21 17:08:14 +00:00
|
|
|
|
2008-11-30 11:07:22 +00:00
|
|
|
.get_frame_number = ehci_get_frame,
|
2008-07-21 17:08:14 +00:00
|
|
|
|
|
|
|
.hub_status_data = ehci_hub_status_data,
|
|
|
|
.hub_control = ehci_hub_control,
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.hub_suspend = ehci_hub_suspend,
|
|
|
|
.hub_resume = ehci_hub_resume,
|
|
|
|
#endif
|
2008-12-04 18:16:05 +00:00
|
|
|
.relinquish_port = ehci_relinquish_port,
|
|
|
|
.port_handed_over = ehci_port_handed_over,
|
2010-02-06 17:00:16 +00:00
|
|
|
|
|
|
|
.clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
|
2008-12-04 18:16:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct hc_driver ehci_ar91xx_hc_driver = {
|
|
|
|
.description = hcd_name,
|
|
|
|
.product_desc = "Atheros AR91xx built-in EHCI controller",
|
|
|
|
.hcd_priv_size = sizeof(struct ehci_hcd),
|
|
|
|
.irq = ehci_irq,
|
|
|
|
.flags = HCD_MEMORY | HCD_USB2,
|
|
|
|
|
|
|
|
.reset = ehci_ar91xx_init,
|
|
|
|
.start = ehci_run,
|
|
|
|
.stop = ehci_stop,
|
|
|
|
.shutdown = ehci_shutdown,
|
|
|
|
|
|
|
|
.urb_enqueue = ehci_urb_enqueue,
|
|
|
|
.urb_dequeue = ehci_urb_dequeue,
|
|
|
|
.endpoint_disable = ehci_endpoint_disable,
|
2010-02-06 17:00:16 +00:00
|
|
|
.endpoint_reset = ehci_endpoint_reset,
|
2008-12-04 18:16:05 +00:00
|
|
|
|
|
|
|
.get_frame_number = ehci_get_frame,
|
|
|
|
|
|
|
|
.hub_status_data = ehci_hub_status_data,
|
|
|
|
.hub_control = ehci_hub_control,
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.hub_suspend = ehci_hub_suspend,
|
|
|
|
.hub_resume = ehci_hub_resume,
|
|
|
|
#endif
|
|
|
|
.relinquish_port = ehci_relinquish_port,
|
|
|
|
.port_handed_over = ehci_port_handed_over,
|
2010-02-06 17:00:16 +00:00
|
|
|
|
|
|
|
.clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
|
2008-07-21 17:08:14 +00:00
|
|
|
};
|
|
|
|
|
2008-11-30 20:09:43 +00:00
|
|
|
static int ehci_ar71xx_driver_probe(struct platform_device *pdev)
|
2008-07-21 17:08:14 +00:00
|
|
|
{
|
2008-12-04 18:16:05 +00:00
|
|
|
struct ar71xx_ehci_platform_data *pdata;
|
2008-07-21 17:08:14 +00:00
|
|
|
struct usb_hcd *hcd = NULL;
|
2008-12-04 18:16:05 +00:00
|
|
|
int ret;
|
2008-07-21 17:08:14 +00:00
|
|
|
|
2008-11-30 20:09:43 +00:00
|
|
|
if (usb_disabled())
|
|
|
|
return -ENODEV;
|
2008-07-21 17:08:14 +00:00
|
|
|
|
2008-12-04 18:16:05 +00:00
|
|
|
pdata = pdev->dev.platform_data;
|
|
|
|
if (!pdata) {
|
|
|
|
dev_err(&pdev->dev, "no platform data specified for %s\n",
|
2009-05-05 19:21:39 +00:00
|
|
|
dev_name(&pdev->dev));
|
2008-12-04 18:16:05 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdata->is_ar91xx)
|
|
|
|
ret = ehci_ar71xx_probe(&ehci_ar91xx_hc_driver, &hcd, pdev);
|
|
|
|
else
|
|
|
|
ret = ehci_ar71xx_probe(&ehci_ar71xx_hc_driver, &hcd, pdev);
|
|
|
|
|
|
|
|
return ret;
|
2008-07-21 17:08:14 +00:00
|
|
|
}
|
|
|
|
|
2008-11-30 20:09:43 +00:00
|
|
|
static int ehci_ar71xx_driver_remove(struct platform_device *pdev)
|
2008-07-21 17:08:14 +00:00
|
|
|
{
|
|
|
|
struct usb_hcd *hcd = platform_get_drvdata(pdev);
|
|
|
|
|
2008-11-30 20:09:43 +00:00
|
|
|
ehci_ar71xx_remove(hcd, pdev);
|
2008-07-21 17:08:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-30 20:09:43 +00:00
|
|
|
MODULE_ALIAS("platform:ar71xx-ehci");
|
|
|
|
|
|
|
|
static struct platform_driver ehci_ar71xx_driver = {
|
|
|
|
.probe = ehci_ar71xx_driver_probe,
|
|
|
|
.remove = ehci_ar71xx_driver_remove,
|
2008-07-21 17:08:14 +00:00
|
|
|
.driver = {
|
|
|
|
.name = "ar71xx-ehci",
|
|
|
|
}
|
|
|
|
};
|