blob: e9807cf73a2fac93b53a5608a906c763b8663e33 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Sharp LH7A404
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 ohci-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
15 *
16 * This file is licenced under the GPL.
17 */
18
Russell Kingd052d1b2005-10-29 19:07:23 +010019#include <linux/platform_device.h>
Tim Schmielaude259682006-01-08 01:02:05 -080020#include <linux/signal.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24
25extern int usb_disabled(void);
26
27/*-------------------------------------------------------------------------*/
28
29static void lh7a404_start_hc(struct platform_device *dev)
30{
31 printk(KERN_DEBUG __FILE__
32 ": starting LH7A404 OHCI USB Controller\n");
33
34 /*
35 * Now, carefully enable the USB clock, and take
36 * the USB host controller out of reset.
37 */
38 CSC_PWRCNT |= CSC_PWRCNT_USBH_EN; /* Enable clock */
39 udelay(1000);
40 USBH_CMDSTATUS = OHCI_HCR;
David Brownelldd9048a2006-12-05 03:18:31 -080041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 printk(KERN_DEBUG __FILE__
43 ": Clock to USB host has been enabled \n");
44}
45
46static void lh7a404_stop_hc(struct platform_device *dev)
47{
48 printk(KERN_DEBUG __FILE__
49 ": stopping LH7A404 OHCI USB Controller\n");
50
51 CSC_PWRCNT &= ~CSC_PWRCNT_USBH_EN; /* Disable clock */
52}
53
54
55/*-------------------------------------------------------------------------*/
56
57/* configure so an HC device and id are always provided */
58/* always called with process context; sleeping is OK */
59
60
61/**
62 * usb_hcd_lh7a404_probe - initialize LH7A404-based HCDs
63 * Context: !in_interrupt()
64 *
65 * Allocates basic resources for this USB host controller, and
66 * then invokes the start() method for the HCD associated with it
67 * through the hotplug entry's driver_data.
68 *
69 */
70int usb_hcd_lh7a404_probe (const struct hc_driver *driver,
71 struct platform_device *dev)
72{
73 int retval;
74 struct usb_hcd *hcd;
75
76 if (dev->resource[1].flags != IORESOURCE_IRQ) {
77 pr_debug("resource[1] is not IORESOURCE_IRQ");
78 return -ENOMEM;
79 }
80
81 hcd = usb_create_hcd(driver, &dev->dev, "lh7a404");
82 if (!hcd)
83 return -ENOMEM;
84 hcd->rsrc_start = dev->resource[0].start;
85 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
86
87 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
88 pr_debug("request_mem_region failed");
89 retval = -EBUSY;
90 goto err1;
91 }
David Brownelldd9048a2006-12-05 03:18:31 -080092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
94 if (!hcd->regs) {
95 pr_debug("ioremap failed");
96 retval = -ENOMEM;
97 goto err2;
98 }
99
100 lh7a404_start_hc(dev);
101 ohci_hcd_init(hcd_to_ohci(hcd));
102
Thomas Gleixnerd54b5ca2006-07-01 19:29:44 -0700103 retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 if (retval == 0)
105 return retval;
106
107 lh7a404_stop_hc(dev);
108 iounmap(hcd->regs);
109 err2:
110 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
111 err1:
112 usb_put_hcd(hcd);
113 return retval;
114}
115
116
117/* may be called without controller electrically present */
118/* may be called with controller, bus, and devices active */
119
120/**
121 * usb_hcd_lh7a404_remove - shutdown processing for LH7A404-based HCDs
122 * @dev: USB Host Controller being removed
123 * Context: !in_interrupt()
124 *
125 * Reverses the effect of usb_hcd_lh7a404_probe(), first invoking
126 * the HCD's stop() method. It is always called from a thread
127 * context, normally "rmmod", "apmd", or something similar.
128 *
129 */
130void usb_hcd_lh7a404_remove (struct usb_hcd *hcd, struct platform_device *dev)
131{
132 usb_remove_hcd(hcd);
133 lh7a404_stop_hc(dev);
134 iounmap(hcd->regs);
135 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
136 usb_put_hcd(hcd);
137}
138
139/*-------------------------------------------------------------------------*/
140
141static int __devinit
142ohci_lh7a404_start (struct usb_hcd *hcd)
143{
144 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
145 int ret;
146
147 ohci_dbg (ohci, "ohci_lh7a404_start, ohci:%p", ohci);
148 if ((ret = ohci_init(ohci)) < 0)
149 return ret;
150
151 if ((ret = ohci_run (ohci)) < 0) {
152 err ("can't start %s", hcd->self.bus_name);
153 ohci_stop (hcd);
154 return ret;
155 }
156 return 0;
157}
158
159/*-------------------------------------------------------------------------*/
160
161static const struct hc_driver ohci_lh7a404_hc_driver = {
162 .description = hcd_name,
163 .product_desc = "LH7A404 OHCI",
164 .hcd_priv_size = sizeof(struct ohci_hcd),
165
166 /*
167 * generic hardware linkage
168 */
169 .irq = ohci_irq,
170 .flags = HCD_USB11 | HCD_MEMORY,
171
172 /*
173 * basic lifecycle operations
174 */
175 .start = ohci_lh7a404_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 .stop = ohci_stop,
David Brownelldd9048a2006-12-05 03:18:31 -0800177 .shutdown = ohci_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 /*
180 * managing i/o requests and associated device resources
181 */
182 .urb_enqueue = ohci_urb_enqueue,
183 .urb_dequeue = ohci_urb_dequeue,
184 .endpoint_disable = ohci_endpoint_disable,
185
186 /*
187 * scheduling support
188 */
189 .get_frame_number = ohci_get_frame,
190
191 /*
192 * root hub support
193 */
194 .hub_status_data = ohci_hub_status_data,
195 .hub_control = ohci_hub_control,
David Brownelld4139842006-08-04 11:31:55 -0700196 .hub_irq_enable = ohci_rhsc_enable,
David Brownell92936772005-09-22 22:32:11 -0700197#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -0400198 .bus_suspend = ohci_bus_suspend,
199 .bus_resume = ohci_bus_resume,
David Brownell92936772005-09-22 22:32:11 -0700200#endif
201 .start_port_reset = ohci_start_port_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202};
203
204/*-------------------------------------------------------------------------*/
205
Russell King3ae5eae2005-11-09 22:32:44 +0000206static int ohci_hcd_lh7a404_drv_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 int ret;
209
210 pr_debug ("In ohci_hcd_lh7a404_drv_probe");
211
212 if (usb_disabled())
213 return -ENODEV;
214
215 ret = usb_hcd_lh7a404_probe(&ohci_lh7a404_hc_driver, pdev);
216 return ret;
217}
218
Russell King3ae5eae2005-11-09 22:32:44 +0000219static int ohci_hcd_lh7a404_drv_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Richard Purdie87cf2032005-11-17 09:47:57 -0800221 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 usb_hcd_lh7a404_remove(hcd, pdev);
224 return 0;
225}
226 /*TBD*/
Russell King3ae5eae2005-11-09 22:32:44 +0000227/*static int ohci_hcd_lh7a404_drv_suspend(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
Russell King3ae5eae2005-11-09 22:32:44 +0000229 struct usb_hcd *hcd = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 return 0;
232}
Russell King3ae5eae2005-11-09 22:32:44 +0000233static int ohci_hcd_lh7a404_drv_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Russell King3ae5eae2005-11-09 22:32:44 +0000235 struct usb_hcd *hcd = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237
238 return 0;
239}
240*/
241
Russell King3ae5eae2005-11-09 22:32:44 +0000242static struct platform_driver ohci_hcd_lh7a404_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 .probe = ohci_hcd_lh7a404_drv_probe,
244 .remove = ohci_hcd_lh7a404_drv_remove,
David Brownelldd9048a2006-12-05 03:18:31 -0800245 .shutdown = usb_hcd_platform_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 /*.suspend = ohci_hcd_lh7a404_drv_suspend, */
247 /*.resume = ohci_hcd_lh7a404_drv_resume, */
Russell King3ae5eae2005-11-09 22:32:44 +0000248 .driver = {
249 .name = "lh7a404-ohci",
250 .owner = THIS_MODULE,
251 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252};
253
254static int __init ohci_hcd_lh7a404_init (void)
255{
256 pr_debug (DRIVER_INFO " (LH7A404)");
257 pr_debug ("block sizes: ed %d td %d\n",
258 sizeof (struct ed), sizeof (struct td));
259
Russell King3ae5eae2005-11-09 22:32:44 +0000260 return platform_driver_register(&ohci_hcd_lh7a404_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
262
263static void __exit ohci_hcd_lh7a404_cleanup (void)
264{
Russell King3ae5eae2005-11-09 22:32:44 +0000265 platform_driver_unregister(&ohci_hcd_lh7a404_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266}
267
268module_init (ohci_hcd_lh7a404_init);
269module_exit (ohci_hcd_lh7a404_cleanup);