Merge branch 'block-dir' of git://brick.kernel.dk/data/git/linux-2.6-block
[linux-2.6] / drivers / usb / host / ohci-ppc-soc.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  * (C) Copyright 2003-2005 MontaVista Software Inc.
8  * 
9  * Bus Glue for PPC On-Chip OHCI driver
10  * Tested on Freescale MPC5200 and IBM STB04xxx
11  *
12  * Modified by Dale Farnsworth <dale@farnsworth.org> from ohci-sa1111.c
13  *
14  * This file is licenced under the GPL.
15  */
16
17 #include <linux/platform_device.h>
18
19 /* configure so an HC device and id are always provided */
20 /* always called with process context; sleeping is OK */
21
22 /**
23  * usb_hcd_ppc_soc_probe - initialize On-Chip HCDs
24  * Context: !in_interrupt()
25  *
26  * Allocates basic resources for this USB host controller.
27  *
28  * Store this function in the HCD's struct pci_driver as probe().
29  */
30 static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
31                           struct platform_device *pdev)
32 {
33         int retval;
34         struct usb_hcd *hcd;
35         struct ohci_hcd *ohci;
36         struct resource *res;
37         int irq;
38
39         pr_debug("initializing PPC-SOC USB Controller\n");
40
41         res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
42         if (!res) {
43                 pr_debug(__FILE__ ": no irq\n");
44                 return -ENODEV;
45         }
46         irq = res->start;
47
48         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
49         if (!res) {
50                 pr_debug(__FILE__ ": no reg addr\n");
51                 return -ENODEV;
52         }
53
54         hcd = usb_create_hcd(driver, &pdev->dev, "PPC-SOC USB");
55         if (!hcd)
56                 return -ENOMEM;
57         hcd->rsrc_start = res->start;
58         hcd->rsrc_len = res->end - res->start + 1;
59
60         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
61                 pr_debug(__FILE__ ": request_mem_region failed\n");
62                 retval = -EBUSY;
63                 goto err1;
64         }
65
66         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
67         if (!hcd->regs) {
68                 pr_debug(__FILE__ ": ioremap failed\n");
69                 retval = -ENOMEM;
70                 goto err2;
71         }
72
73         ohci = hcd_to_ohci(hcd);
74         ohci->flags |= OHCI_BIG_ENDIAN;
75         ohci_hcd_init(ohci);
76
77         retval = usb_add_hcd(hcd, irq, SA_INTERRUPT);
78         if (retval == 0)
79                 return retval;
80
81         pr_debug("Removing PPC-SOC USB Controller\n");
82
83         iounmap(hcd->regs);
84  err2:
85         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
86  err1:
87         usb_put_hcd(hcd);
88         return retval;
89 }
90
91
92 /* may be called without controller electrically present */
93 /* may be called with controller, bus, and devices active */
94
95 /**
96  * usb_hcd_ppc_soc_remove - shutdown processing for On-Chip HCDs
97  * @pdev: USB Host Controller being removed
98  * Context: !in_interrupt()
99  *
100  * Reverses the effect of usb_hcd_ppc_soc_probe().
101  * It is always called from a thread
102  * context, normally "rmmod", "apmd", or something similar.
103  *
104  */
105 static void usb_hcd_ppc_soc_remove(struct usb_hcd *hcd,
106                 struct platform_device *pdev)
107 {
108         usb_remove_hcd(hcd);
109
110         pr_debug("stopping PPC-SOC USB Controller\n");
111
112         iounmap(hcd->regs);
113         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
114         usb_put_hcd(hcd);
115 }
116
117 static int __devinit
118 ohci_ppc_soc_start(struct usb_hcd *hcd)
119 {
120         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
121         int             ret;
122
123         if ((ret = ohci_init(ohci)) < 0)
124                 return ret;
125
126         if ((ret = ohci_run(ohci)) < 0) {
127                 err("can't start %s", ohci_to_hcd(ohci)->self.bus_name);
128                 ohci_stop(hcd);
129                 return ret;
130         }
131
132         return 0;
133 }
134
135 static const struct hc_driver ohci_ppc_soc_hc_driver = {
136         .description =          hcd_name,
137         .hcd_priv_size =        sizeof(struct ohci_hcd),
138
139         /*
140          * generic hardware linkage
141          */
142         .irq =                  ohci_irq,
143         .flags =                HCD_USB11 | HCD_MEMORY,
144
145         /*
146          * basic lifecycle operations
147          */
148         .start =                ohci_ppc_soc_start,
149         .stop =                 ohci_stop,
150
151         /*
152          * managing i/o requests and associated device resources
153          */
154         .urb_enqueue =          ohci_urb_enqueue,
155         .urb_dequeue =          ohci_urb_dequeue,
156         .endpoint_disable =     ohci_endpoint_disable,
157
158         /*
159          * scheduling support
160          */
161         .get_frame_number =     ohci_get_frame,
162
163         /*
164          * root hub support
165          */
166         .hub_status_data =      ohci_hub_status_data,
167         .hub_control =          ohci_hub_control,
168 #ifdef  CONFIG_PM
169         .bus_suspend =          ohci_bus_suspend,
170         .bus_resume =           ohci_bus_resume,
171 #endif
172         .start_port_reset =     ohci_start_port_reset,
173 };
174
175 static int ohci_hcd_ppc_soc_drv_probe(struct device *dev)
176 {
177         struct platform_device *pdev = to_platform_device(dev);
178         int ret;
179
180         if (usb_disabled())
181                 return -ENODEV;
182
183         ret = usb_hcd_ppc_soc_probe(&ohci_ppc_soc_hc_driver, pdev);
184         return ret;
185 }
186
187 static int ohci_hcd_ppc_soc_drv_remove(struct device *dev)
188 {
189         struct platform_device *pdev = to_platform_device(dev);
190         struct usb_hcd *hcd = dev_get_drvdata(dev);
191
192         usb_hcd_ppc_soc_remove(hcd, pdev);
193         return 0;
194 }
195
196 static struct device_driver ohci_hcd_ppc_soc_driver = {
197         .name           = "ppc-soc-ohci",
198         .owner          = THIS_MODULE,
199         .bus            = &platform_bus_type,
200         .probe          = ohci_hcd_ppc_soc_drv_probe,
201         .remove         = ohci_hcd_ppc_soc_drv_remove,
202 #ifdef  CONFIG_PM
203         /*.suspend      = ohci_hcd_ppc_soc_drv_suspend,*/
204         /*.resume       = ohci_hcd_ppc_soc_drv_resume,*/
205 #endif
206 };
207
208 static int __init ohci_hcd_ppc_soc_init(void)
209 {
210         pr_debug(DRIVER_INFO " (PPC SOC)\n");
211         pr_debug("block sizes: ed %d td %d\n", sizeof(struct ed),
212                                                         sizeof(struct td));
213
214         return driver_register(&ohci_hcd_ppc_soc_driver);
215 }
216
217 static void __exit ohci_hcd_ppc_soc_cleanup(void)
218 {
219         driver_unregister(&ohci_hcd_ppc_soc_driver);
220 }
221
222 module_init(ohci_hcd_ppc_soc_init);
223 module_exit(ohci_hcd_ppc_soc_cleanup);