blob: f9575c4091240ef364a4ca0b2d1bfac5099ccf25 [file] [log] [blame]
Vladimir Barinov91bc4d32007-12-30 15:21:11 -08001/*
2 * IXP4XX EHCI Host Controller Driver
3 *
4 * Author: Vladimir Barinov <vbarinov@ru.mvista.com>
5 *
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
26 + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
27 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,
54 .get_frame_number = ehci_get_frame,
55 .hub_status_data = ehci_hub_status_data,
56 .hub_control = ehci_hub_control,
57#if defined(CONFIG_PM)
58 .bus_suspend = ehci_bus_suspend,
59 .bus_resume = ehci_bus_resume,
60#endif
Alan Sterna8e51772008-05-20 16:58:11 -040061 .relinquish_port = ehci_relinquish_port,
Alan Stern3a311552008-05-20 16:58:29 -040062 .port_handed_over = ehci_port_handed_over,
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080063};
64
65static int ixp4xx_ehci_probe(struct platform_device *pdev)
66{
67 struct usb_hcd *hcd;
68 const struct hc_driver *driver = &ixp4xx_ehci_hc_driver;
69 struct resource *res;
70 int irq;
71 int retval;
72
73 if (usb_disabled())
74 return -ENODEV;
75
76 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
77 if (!res) {
78 dev_err(&pdev->dev,
79 "Found HC with no IRQ. Check %s setup!\n",
Kay Sievers7071a3c2008-05-02 06:02:41 +020080 dev_name(&pdev->dev));
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080081 return -ENODEV;
82 }
83 irq = res->start;
84
Kay Sievers7071a3c2008-05-02 06:02:41 +020085 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080086 if (!hcd) {
87 retval = -ENOMEM;
88 goto fail_create_hcd;
89 }
90
91 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
92 if (!res) {
93 dev_err(&pdev->dev,
94 "Found HC with no register addr. Check %s setup!\n",
Kay Sievers7071a3c2008-05-02 06:02:41 +020095 dev_name(&pdev->dev));
Vladimir Barinov91bc4d32007-12-30 15:21:11 -080096 retval = -ENODEV;
97 goto fail_request_resource;
98 }
99 hcd->rsrc_start = res->start;
100 hcd->rsrc_len = res->end - res->start + 1;
101
102 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
103 driver->description)) {
104 dev_dbg(&pdev->dev, "controller already in use\n");
105 retval = -EBUSY;
106 goto fail_request_resource;
107 }
108
109 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
110 if (hcd->regs == NULL) {
111 dev_dbg(&pdev->dev, "error mapping memory\n");
112 retval = -EFAULT;
113 goto fail_ioremap;
114 }
115
116 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
117 if (retval)
118 goto fail_add_hcd;
119
120 return retval;
121
122fail_add_hcd:
123 iounmap(hcd->regs);
124fail_ioremap:
125 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
126fail_request_resource:
127 usb_put_hcd(hcd);
128fail_create_hcd:
Kay Sievers7071a3c2008-05-02 06:02:41 +0200129 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
Vladimir Barinov91bc4d32007-12-30 15:21:11 -0800130 return retval;
131}
132
133static int ixp4xx_ehci_remove(struct platform_device *pdev)
134{
135 struct usb_hcd *hcd = platform_get_drvdata(pdev);
136
137 usb_remove_hcd(hcd);
138 iounmap(hcd->regs);
139 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
140 usb_put_hcd(hcd);
141
142 return 0;
143}
144
David Brownell135db042008-02-11 18:40:46 -0800145MODULE_ALIAS("platform:ixp4xx-ehci");
Vladimir Barinov91bc4d32007-12-30 15:21:11 -0800146
147static struct platform_driver ixp4xx_ehci_driver = {
148 .probe = ixp4xx_ehci_probe,
149 .remove = ixp4xx_ehci_remove,
150 .driver = {
151 .name = "ixp4xx-ehci",
Vladimir Barinov91bc4d32007-12-30 15:21:11 -0800152 },
153};