[ar71xx] create platform data for the EHCI driver
[openwrt.git] / target / linux / ar71xx / files / drivers / usb / host / ehci-ar71xx.c
1 /*
2  *  Bus Glue for Atheros AR71xx built-in EHCI controller.
3  *
4  *  Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5  *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6  *
7  *  Parts of this file are based on Atheros' 2.6.15 BSP
8  *      Copyright (C) 2007 Atheros Communications, Inc.
9  *
10  *  This program is free software; you can redistribute it and/or modify it
11  *  under the terms of the GNU General Public License version 2 as published
12  *  by the Free Software Foundation.
13  */
14
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17
18 #include <asm/mach-ar71xx/platform.h>
19
20 extern int usb_disabled(void);
21
22 static void ehci_ar71xx_setup(void)
23 {
24         /*
25          * TODO: implement
26          */
27 }
28
29 static int ehci_ar71xx_probe(const struct hc_driver *driver,
30                              struct usb_hcd **hcd_out,
31                              struct platform_device *pdev)
32 {
33         struct usb_hcd *hcd;
34         struct ehci_hcd *ehci;
35         struct resource *res;
36         int irq;
37         int ret;
38
39         res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
40         if (!res) {
41                 dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
42                         pdev->dev.bus_id);
43                 return -ENODEV;
44         }
45         irq = res->start;
46
47         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
48         if (!res) {
49                 dev_dbg(&pdev->dev, "no base address specified for %s\n",
50                         pdev->dev.bus_id);
51                 return -ENODEV;
52         }
53
54         hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
55         if (!hcd)
56                 return -ENOMEM;
57
58         hcd->rsrc_start = res->start;
59         hcd->rsrc_len   = res->end - res->start + 1;
60
61         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
62                 dev_dbg(&pdev->dev, "controller already in use\n");
63                 ret = -EBUSY;
64                 goto err_put_hcd;
65         }
66
67         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
68         if (!hcd->regs) {
69                 dev_dbg(&pdev->dev, "error mapping memory\n");
70                 ret = -EFAULT;
71                 goto err_release_region;
72         }
73
74         ehci = hcd_to_ehci(hcd);
75         ehci->caps = hcd->regs;
76         ehci->regs = hcd->regs +
77                         HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
78         ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
79
80         ehci_ar71xx_setup();
81
82         ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
83         if (ret)
84                 goto err_iounmap;
85
86         return 0;
87
88  err_iounmap:
89         iounmap(hcd->regs);
90
91  err_release_region:
92         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
93  err_put_hcd:
94         usb_put_hcd(hcd);
95         return ret;
96 }
97
98 static void ehci_ar71xx_remove(struct usb_hcd *hcd,
99                                struct platform_device *pdev)
100 {
101         usb_remove_hcd(hcd);
102         iounmap(hcd->regs);
103         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
104         usb_put_hcd(hcd);
105 }
106
107 static const struct hc_driver ehci_ar71xx_hc_driver = {
108         .description            = hcd_name,
109         .product_desc           = "Atheros AR71xx built-in EHCI controller",
110         .hcd_priv_size          = sizeof(struct ehci_hcd),
111
112         /*
113          * generic hardware linkage
114          */
115         .irq                    = ehci_irq,
116         .flags                  = HCD_MEMORY | HCD_USB2,
117
118         /*
119          * basic lifecycle operations
120          */
121         .reset                  = ehci_init,
122         .start                  = ehci_run,
123         .stop                   = ehci_stop,
124         .shutdown               = ehci_shutdown,
125
126         /*
127          * managing i/o requests and associated device resources
128          */
129         .urb_enqueue            = ehci_urb_enqueue,
130         .urb_dequeue            = ehci_urb_dequeue,
131         .endpoint_disable       = ehci_endpoint_disable,
132
133         /*
134          * scheduling support
135          */
136         .get_frame_number       = ehci_get_frame,
137
138         /*
139          * root hub support
140          */
141         .hub_status_data        = ehci_hub_status_data,
142         .hub_control            = ehci_hub_control,
143 #ifdef CONFIG_PM
144         .hub_suspend            = ehci_hub_suspend,
145         .hub_resume             = ehci_hub_resume,
146 #endif
147 };
148
149 static int ehci_ar71xx_driver_probe(struct platform_device *pdev)
150 {
151         struct usb_hcd *hcd = NULL;
152
153         if (usb_disabled())
154                 return -ENODEV;
155
156         return ehci_ar71xx_probe(&ehci_ar71xx_hc_driver, &hcd, pdev);
157 }
158
159 static int ehci_ar71xx_driver_remove(struct platform_device *pdev)
160 {
161         struct usb_hcd *hcd = platform_get_drvdata(pdev);
162
163         ehci_ar71xx_remove(hcd, pdev);
164         return 0;
165 }
166
167 MODULE_ALIAS("platform:ar71xx-ehci");
168
169 static struct platform_driver ehci_ar71xx_driver = {
170         .probe          = ehci_ar71xx_driver_probe,
171         .remove         = ehci_ar71xx_driver_remove,
172         .driver = {
173                 .name   = "ar71xx-ehci",
174         }
175 };