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