60f955279df75313bef658e010acd34fec984a20
[openwrt/svn-archive/archive.git] / target / linux / adm5120 / files / drivers / usb / host / adm5120-drv.c
1 /*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company
7 *
8 * Bus Glue for AMD Alchemy Au1xxx
9 *
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Rusell King et al.
12 *
13 * Modified for LH7A404 from ahcd-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
15 * Modified for AMD Alchemy Au1xxx
16 * by Matt Porter <mporter@kernel.crashing.org>
17 *
18 * This file is licenced under the GPL.
19 */
20
21 #include <linux/platform_device.h>
22 #include <linux/signal.h>
23
24 #include <asm/bootinfo.h>
25 #include <asm/mach-adm5120/adm5120_defs.h>
26
27 #ifdef DEBUG
28 #define HCD_DBG(f, a...) printk(KERN_DEBUG "%s: " f, hcd_name, ## a)
29 #else
30 #define HCD_DBG(f, a...) do {} while (0)
31 #endif
32 #define HCD_ERR(f, a...) printk(KERN_ERR "%s: " f, hcd_name, ## a)
33 #define HCD_INFO(f, a...) printk(KERN_INFO "%s: " f, hcd_name, ## a)
34
35 /*-------------------------------------------------------------------------*/
36
37 static int admhc_adm5120_probe(const struct hc_driver *driver,
38 struct platform_device *dev)
39 {
40 int retval;
41 struct usb_hcd *hcd;
42 int irq;
43 struct resource *regs;
44
45 /* sanity checks */
46 regs = platform_get_resource(dev, IORESOURCE_MEM, 0);
47 if (!regs) {
48 HCD_DBG("no IOMEM resource found\n");
49 return -ENODEV;
50 }
51
52 irq = platform_get_irq(dev, 0);
53 if (irq < 0) {
54 HCD_DBG("no IRQ resource found\n");
55 return -ENODEV;
56 }
57
58 hcd = usb_create_hcd(driver, &dev->dev, "ADM5120");
59 if (!hcd)
60 return -ENOMEM;
61
62 hcd->rsrc_start = regs->start;
63 hcd->rsrc_len = regs->end - regs->start + 1;
64
65 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
66 HCD_DBG("request_mem_region failed\n");
67 retval = -EBUSY;
68 goto err_dev;
69 }
70
71 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
72 if (!hcd->regs) {
73 HCD_DBG("ioremap failed\n");
74 retval = -ENOMEM;
75 goto err_mem;
76 }
77
78 admhc_hcd_init(hcd_to_admhcd(hcd));
79
80 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED);
81 if (retval)
82 goto err_io;
83
84 return 0;
85
86 err_io:
87 iounmap(hcd->regs);
88 err_mem:
89 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
90 err_dev:
91 usb_put_hcd(hcd);
92 return retval;
93 }
94
95
96 /* may be called without controller electrically present */
97 /* may be called with controller, bus, and devices active */
98
99 static void admhc_adm5120_remove(struct usb_hcd *hcd,
100 struct platform_device *dev)
101 {
102 usb_remove_hcd(hcd);
103 iounmap(hcd->regs);
104 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
105 usb_put_hcd(hcd);
106 }
107
108 /*-------------------------------------------------------------------------*/
109
110 static int __devinit
111 admhc_adm5120_start(struct usb_hcd *hcd)
112 {
113 struct admhcd *ahcd = hcd_to_admhcd (hcd);
114 int ret;
115
116 ret = admhc_init(ahcd);
117 if (ret < 0) {
118 HCD_ERR("unable to init %s\n", hcd->self.bus_name);
119 goto err;
120 }
121
122 ret = admhc_run(ahcd);
123 if (ret < 0) {
124 HCD_ERR("unable to run %s\n", hcd->self.bus_name);
125 goto err_stop;
126 }
127
128 return 0;
129
130 err_stop:
131 admhc_stop(hcd);
132 err:
133 return ret;
134 }
135
136 /*-------------------------------------------------------------------------*/
137
138 static const struct hc_driver adm5120_hc_driver = {
139 .description = hcd_name,
140 .product_desc = "ADM5120 built-in USB 1.1 Host Controller",
141 .hcd_priv_size = sizeof(struct admhcd),
142
143 /*
144 * generic hardware linkage
145 */
146 .irq = admhc_irq,
147 .flags = HCD_USB11 | HCD_MEMORY,
148
149 /*
150 * basic lifecycle operations
151 */
152 .start = admhc_adm5120_start,
153 .stop = admhc_stop,
154 .shutdown = admhc_shutdown,
155
156 /*
157 * managing i/o requests and associated device resources
158 */
159 .urb_enqueue = admhc_urb_enqueue,
160 .urb_dequeue = admhc_urb_dequeue,
161 .endpoint_disable = admhc_endpoint_disable,
162
163 /*
164 * scheduling support
165 */
166 .get_frame_number = admhc_get_frame_number,
167
168 /*
169 * root hub support
170 */
171 .hub_status_data = admhc_hub_status_data,
172 .hub_control = admhc_hub_control,
173 .hub_irq_enable = admhc_hub_irq_enable,
174 #ifdef CONFIG_PM
175 .bus_suspend = admhc_bus_suspend,
176 .bus_resume = admhc_bus_resume,
177 #endif
178 .start_port_reset = admhc_start_port_reset,
179 };
180
181 /*-------------------------------------------------------------------------*/
182
183 static int usb_hcd_adm5120_probe(struct platform_device *pdev)
184 {
185 int ret;
186
187 if (mips_machgroup != MACH_GROUP_ADM5120)
188 return -ENODEV;
189
190 ret = admhc_adm5120_probe(&adm5120_hc_driver, pdev);
191
192 return ret;
193 }
194
195 static int usb_hcd_adm5120_remove(struct platform_device *pdev)
196 {
197 struct usb_hcd *hcd = platform_get_drvdata(pdev);
198
199 admhc_adm5120_remove(hcd, pdev);
200
201 return 0;
202 }
203
204 #ifdef CONFIG_PM
205 static int usb_hcd_adm5120_suspend(struct platform_device *dev)
206 {
207 struct usb_hcd *hcd = platform_get_drvdata(dev);
208
209 return 0;
210 }
211
212 static int usb_hcd_adm5120_resume(struct platform_device *dev)
213 {
214 struct usb_hcd *hcd = platform_get_drvdata(dev);
215
216 return 0;
217 }
218 #else
219 #define usb_hcd_adm5120_suspend NULL
220 #define usb_hcd_adm5120_resume NULL
221 #endif /* CONFIG_PM */
222
223 static struct platform_driver usb_hcd_adm5120_driver = {
224 .probe = usb_hcd_adm5120_probe,
225 .remove = usb_hcd_adm5120_remove,
226 .shutdown = usb_hcd_platform_shutdown,
227 .suspend = usb_hcd_adm5120_suspend,
228 .resume = usb_hcd_adm5120_resume,
229 .driver = {
230 .name = "adm5120-hcd",
231 .owner = THIS_MODULE,
232 },
233 };
234