blob: 488d401942e90c784e02d687087773324b178b8a [file] [log] [blame]
Vladimir Barinov91bc4d32007-12-30 15:21:11 -08001/*
2 * IXP4XX EHCI Host Controller Driver
3 *
Vladimir Barinovd6b52032008-09-29 23:14:11 +04004 * Author: Vladimir Barinov <vbarinov@embeddedalley.com>
Vladimir Barinov91bc4d32007-12-30 15:21:11 -08005 *
6 * Based on "ehci-fsl.c" by Randy Vinson <rvinson@mvista.com>
7 *
8 * 2007 (c) MontaVista Software, Inc. This file is licensed under
9 * the terms of the GNU General Public License version 2. This program
10 * is licensed "as is" without any warranty of any kind, whether express
11 * or implied.
12 */
13
14#include <linux/platform_device.h>
15
16static int ixp4xx_ehci_init(struct usb_hcd *hcd)
17{
18 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
19 int retval = 0;
20
21 ehci->big_endian_desc = 1;
22 ehci->big_endian_mmio = 1;
23
24 ehci->caps = hcd->regs + 0x100;
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080025
Alan Sterna8e51772008-05-20 16:58:11 -040026 hcd->has_tt = 1;
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080027
Alan Stern1a49e2a2012-07-09 15:55:14 -040028 retval = ehci_setup(hcd);
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080029 if (retval)
30 return retval;
31
32 ehci_port_power(ehci, 0);
33
34 return retval;
35}
36
37static const struct hc_driver ixp4xx_ehci_hc_driver = {
38 .description = hcd_name,
39 .product_desc = "IXP4XX EHCI Host Controller",
40 .hcd_priv_size = sizeof(struct ehci_hcd),
41 .irq = ehci_irq,
42 .flags = HCD_MEMORY | HCD_USB2,
43 .reset = ixp4xx_ehci_init,
44 .start = ehci_run,
45 .stop = ehci_stop,
46 .shutdown = ehci_shutdown,
47 .urb_enqueue = ehci_urb_enqueue,
48 .urb_dequeue = ehci_urb_dequeue,
49 .endpoint_disable = ehci_endpoint_disable,
Alan Sternb18ffd42009-05-27 18:21:56 -040050 .endpoint_reset = ehci_endpoint_reset,
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080051 .get_frame_number = ehci_get_frame,
52 .hub_status_data = ehci_hub_status_data,
53 .hub_control = ehci_hub_control,
54#if defined(CONFIG_PM)
55 .bus_suspend = ehci_bus_suspend,
56 .bus_resume = ehci_bus_resume,
57#endif
Alan Sterna8e51772008-05-20 16:58:11 -040058 .relinquish_port = ehci_relinquish_port,
Alan Stern3a311552008-05-20 16:58:29 -040059 .port_handed_over = ehci_port_handed_over,
Alan Stern914b7012009-06-29 10:47:30 -040060
61 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080062};
63
64static int ixp4xx_ehci_probe(struct platform_device *pdev)
65{
66 struct usb_hcd *hcd;
67 const struct hc_driver *driver = &ixp4xx_ehci_hc_driver;
68 struct resource *res;
69 int irq;
70 int retval;
71
72 if (usb_disabled())
73 return -ENODEV;
74
75 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
76 if (!res) {
77 dev_err(&pdev->dev,
78 "Found HC with no IRQ. Check %s setup!\n",
Kay Sievers7071a3c2008-05-02 06:02:41 +020079 dev_name(&pdev->dev));
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080080 return -ENODEV;
81 }
82 irq = res->start;
83
Kay Sievers7071a3c2008-05-02 06:02:41 +020084 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080085 if (!hcd) {
86 retval = -ENOMEM;
87 goto fail_create_hcd;
88 }
89
90 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
91 if (!res) {
92 dev_err(&pdev->dev,
93 "Found HC with no register addr. Check %s setup!\n",
Kay Sievers7071a3c2008-05-02 06:02:41 +020094 dev_name(&pdev->dev));
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080095 retval = -ENODEV;
96 goto fail_request_resource;
97 }
98 hcd->rsrc_start = res->start;
Joe Perches28f65c112011-06-09 09:13:32 -070099 hcd->rsrc_len = resource_size(res);
Vladimir Barinov91bc4d32007-12-30 15:21:11 -0800100
101 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
102 driver->description)) {
103 dev_dbg(&pdev->dev, "controller already in use\n");
104 retval = -EBUSY;
105 goto fail_request_resource;
106 }
107
108 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
109 if (hcd->regs == NULL) {
110 dev_dbg(&pdev->dev, "error mapping memory\n");
111 retval = -EFAULT;
112 goto fail_ioremap;
113 }
114
115 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
116 if (retval)
117 goto fail_add_hcd;
118
119 return retval;
120
121fail_add_hcd:
122 iounmap(hcd->regs);
123fail_ioremap:
124 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
125fail_request_resource:
126 usb_put_hcd(hcd);
127fail_create_hcd:
Kay Sievers7071a3c2008-05-02 06:02:41 +0200128 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
Vladimir Barinov91bc4d32007-12-30 15:21:11 -0800129 return retval;
130}
131
132static int ixp4xx_ehci_remove(struct platform_device *pdev)
133{
134 struct usb_hcd *hcd = platform_get_drvdata(pdev);
135
136 usb_remove_hcd(hcd);
137 iounmap(hcd->regs);
138 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
139 usb_put_hcd(hcd);
140
141 return 0;
142}
143
David Brownell135db042008-02-11 18:40:46 -0800144MODULE_ALIAS("platform:ixp4xx-ehci");
Vladimir Barinov91bc4d32007-12-30 15:21:11 -0800145
146static struct platform_driver ixp4xx_ehci_driver = {
147 .probe = ixp4xx_ehci_probe,
148 .remove = ixp4xx_ehci_remove,
149 .driver = {
150 .name = "ixp4xx-ehci",
Vladimir Barinov91bc4d32007-12-30 15:21:11 -0800151 },
152};