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