blob: c4460f3d009fdb6595e0566b19a70a6302f3fd10 [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;
25 ehci->regs = hcd->regs + 0x100
Jan Anderssonc4301312011-05-03 20:11:57 +020026 + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080027 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
28
Alan Sterna8e51772008-05-20 16:58:11 -040029 hcd->has_tt = 1;
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080030 ehci_reset(ehci);
31
32 retval = ehci_init(hcd);
33 if (retval)
34 return retval;
35
36 ehci_port_power(ehci, 0);
37
38 return retval;
39}
40
41static const struct hc_driver ixp4xx_ehci_hc_driver = {
42 .description = hcd_name,
43 .product_desc = "IXP4XX EHCI Host Controller",
44 .hcd_priv_size = sizeof(struct ehci_hcd),
45 .irq = ehci_irq,
46 .flags = HCD_MEMORY | HCD_USB2,
47 .reset = ixp4xx_ehci_init,
48 .start = ehci_run,
49 .stop = ehci_stop,
50 .shutdown = ehci_shutdown,
51 .urb_enqueue = ehci_urb_enqueue,
52 .urb_dequeue = ehci_urb_dequeue,
53 .endpoint_disable = ehci_endpoint_disable,
Alan Sternb18ffd42009-05-27 18:21:56 -040054 .endpoint_reset = ehci_endpoint_reset,
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080055 .get_frame_number = ehci_get_frame,
56 .hub_status_data = ehci_hub_status_data,
57 .hub_control = ehci_hub_control,
58#if defined(CONFIG_PM)
59 .bus_suspend = ehci_bus_suspend,
60 .bus_resume = ehci_bus_resume,
61#endif
Alan Sterna8e51772008-05-20 16:58:11 -040062 .relinquish_port = ehci_relinquish_port,
Alan Stern3a311552008-05-20 16:58:29 -040063 .port_handed_over = ehci_port_handed_over,
Alan Stern914b7012009-06-29 10:47:30 -040064
65 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080066};
67
68static int ixp4xx_ehci_probe(struct platform_device *pdev)
69{
70 struct usb_hcd *hcd;
71 const struct hc_driver *driver = &ixp4xx_ehci_hc_driver;
72 struct resource *res;
73 int irq;
74 int retval;
75
76 if (usb_disabled())
77 return -ENODEV;
78
79 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
80 if (!res) {
81 dev_err(&pdev->dev,
82 "Found HC with no IRQ. Check %s setup!\n",
Kay Sievers7071a3c2008-05-02 06:02:41 +020083 dev_name(&pdev->dev));
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080084 return -ENODEV;
85 }
86 irq = res->start;
87
Kay Sievers7071a3c2008-05-02 06:02:41 +020088 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080089 if (!hcd) {
90 retval = -ENOMEM;
91 goto fail_create_hcd;
92 }
93
94 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
95 if (!res) {
96 dev_err(&pdev->dev,
97 "Found HC with no register addr. Check %s setup!\n",
Kay Sievers7071a3c2008-05-02 06:02:41 +020098 dev_name(&pdev->dev));
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080099 retval = -ENODEV;
100 goto fail_request_resource;
101 }
102 hcd->rsrc_start = res->start;
Joe Perches28f65c112011-06-09 09:13:32 -0700103 hcd->rsrc_len = resource_size(res);
Vladimir Barinov91bc4d32007-12-30 15:21:11 -0800104
105 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
106 driver->description)) {
107 dev_dbg(&pdev->dev, "controller already in use\n");
108 retval = -EBUSY;
109 goto fail_request_resource;
110 }
111
112 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
113 if (hcd->regs == NULL) {
114 dev_dbg(&pdev->dev, "error mapping memory\n");
115 retval = -EFAULT;
116 goto fail_ioremap;
117 }
118
119 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
120 if (retval)
121 goto fail_add_hcd;
122
123 return retval;
124
125fail_add_hcd:
126 iounmap(hcd->regs);
127fail_ioremap:
128 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
129fail_request_resource:
130 usb_put_hcd(hcd);
131fail_create_hcd:
Kay Sievers7071a3c2008-05-02 06:02:41 +0200132 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
Vladimir Barinov91bc4d32007-12-30 15:21:11 -0800133 return retval;
134}
135
136static int ixp4xx_ehci_remove(struct platform_device *pdev)
137{
138 struct usb_hcd *hcd = platform_get_drvdata(pdev);
139
140 usb_remove_hcd(hcd);
141 iounmap(hcd->regs);
142 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
143 usb_put_hcd(hcd);
144
145 return 0;
146}
147
David Brownell135db042008-02-11 18:40:46 -0800148MODULE_ALIAS("platform:ixp4xx-ehci");
Vladimir Barinov91bc4d32007-12-30 15:21:11 -0800149
150static struct platform_driver ixp4xx_ehci_driver = {
151 .probe = ixp4xx_ehci_probe,
152 .remove = ixp4xx_ehci_remove,
153 .driver = {
154 .name = "ixp4xx-ehci",
Vladimir Barinov91bc4d32007-12-30 15:21:11 -0800155 },
156};