Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[linux-2.6] / drivers / usb / host / ehci-ixp4xx.c
1 /*
2  * IXP4XX EHCI Host Controller Driver
3  *
4  * Author: Vladimir Barinov <vbarinov@embeddedalley.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
16 static 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
29         hcd->has_tt = 1;
30         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
41 static 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         .endpoint_reset         = ehci_endpoint_reset,
55         .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
62         .relinquish_port        = ehci_relinquish_port,
63         .port_handed_over       = ehci_port_handed_over,
64 };
65
66 static int ixp4xx_ehci_probe(struct platform_device *pdev)
67 {
68         struct usb_hcd *hcd;
69         const struct hc_driver *driver = &ixp4xx_ehci_hc_driver;
70         struct resource *res;
71         int irq;
72         int retval;
73
74         if (usb_disabled())
75                 return -ENODEV;
76
77         res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
78         if (!res) {
79                 dev_err(&pdev->dev,
80                         "Found HC with no IRQ. Check %s setup!\n",
81                         dev_name(&pdev->dev));
82                 return -ENODEV;
83         }
84         irq = res->start;
85
86         hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
87         if (!hcd) {
88                 retval = -ENOMEM;
89                 goto fail_create_hcd;
90         }
91
92         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
93         if (!res) {
94                 dev_err(&pdev->dev,
95                         "Found HC with no register addr. Check %s setup!\n",
96                         dev_name(&pdev->dev));
97                 retval = -ENODEV;
98                 goto fail_request_resource;
99         }
100         hcd->rsrc_start = res->start;
101         hcd->rsrc_len = res->end - res->start + 1;
102
103         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
104                                 driver->description)) {
105                 dev_dbg(&pdev->dev, "controller already in use\n");
106                 retval = -EBUSY;
107                 goto fail_request_resource;
108         }
109
110         hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
111         if (hcd->regs == NULL) {
112                 dev_dbg(&pdev->dev, "error mapping memory\n");
113                 retval = -EFAULT;
114                 goto fail_ioremap;
115         }
116
117         retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
118         if (retval)
119                 goto fail_add_hcd;
120
121         return retval;
122
123 fail_add_hcd:
124         iounmap(hcd->regs);
125 fail_ioremap:
126         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
127 fail_request_resource:
128         usb_put_hcd(hcd);
129 fail_create_hcd:
130         dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
131         return retval;
132 }
133
134 static int ixp4xx_ehci_remove(struct platform_device *pdev)
135 {
136         struct usb_hcd *hcd = platform_get_drvdata(pdev);
137
138         usb_remove_hcd(hcd);
139         iounmap(hcd->regs);
140         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
141         usb_put_hcd(hcd);
142
143         return 0;
144 }
145
146 MODULE_ALIAS("platform:ixp4xx-ehci");
147
148 static struct platform_driver ixp4xx_ehci_driver = {
149         .probe = ixp4xx_ehci_probe,
150         .remove = ixp4xx_ehci_remove,
151         .driver = {
152                 .name = "ixp4xx-ehci",
153         },
154 };