blob: 18d39f0463ee4f4dac4f5122f2d6670be99ad7c1 [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>
Uwe Kleine-Königac310bb2008-07-10 17:30:46 -070011 * Based on fragments of previous driver by Russell King et al.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
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
Russell Kinga09e64f2008-08-05 16:14:15 +010022#include <mach/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{
Joe Perchesf45ba772010-02-05 17:51:13 -080031 printk(KERN_DEBUG "%s: starting LH7A404 OHCI USB Controller\n",
32 __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
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
Joe Perchesf45ba772010-02-05 17:51:13 -080042 printk(KERN_DEBUG "%s: Clock to USB host has been enabled \n", __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
45static void lh7a404_stop_hc(struct platform_device *dev)
46{
Joe Perchesf45ba772010-02-05 17:51:13 -080047 printk(KERN_DEBUG "%s: stopping LH7A404 OHCI USB Controller\n",
48 __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 CSC_PWRCNT &= ~CSC_PWRCNT_USBH_EN; /* Disable clock */
51}
52
53
54/*-------------------------------------------------------------------------*/
55
56/* configure so an HC device and id are always provided */
57/* always called with process context; sleeping is OK */
58
59
60/**
61 * usb_hcd_lh7a404_probe - initialize LH7A404-based HCDs
62 * Context: !in_interrupt()
63 *
64 * Allocates basic resources for this USB host controller, and
65 * then invokes the start() method for the HCD associated with it
66 * through the hotplug entry's driver_data.
67 *
68 */
69int usb_hcd_lh7a404_probe (const struct hc_driver *driver,
70 struct platform_device *dev)
71{
72 int retval;
73 struct usb_hcd *hcd;
74
75 if (dev->resource[1].flags != IORESOURCE_IRQ) {
76 pr_debug("resource[1] is not IORESOURCE_IRQ");
77 return -ENOMEM;
78 }
79
80 hcd = usb_create_hcd(driver, &dev->dev, "lh7a404");
81 if (!hcd)
82 return -ENOMEM;
83 hcd->rsrc_start = dev->resource[0].start;
84 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
85
86 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
87 pr_debug("request_mem_region failed");
88 retval = -EBUSY;
89 goto err1;
90 }
David Brownelldd9048a2006-12-05 03:18:31 -080091
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
93 if (!hcd->regs) {
94 pr_debug("ioremap failed");
95 retval = -ENOMEM;
96 goto err2;
97 }
98
99 lh7a404_start_hc(dev);
100 ohci_hcd_init(hcd_to_ohci(hcd));
101
Thomas Gleixnerd54b5ca2006-07-01 19:29:44 -0700102 retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 if (retval == 0)
104 return retval;
105
106 lh7a404_stop_hc(dev);
107 iounmap(hcd->regs);
108 err2:
109 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
110 err1:
111 usb_put_hcd(hcd);
112 return retval;
113}
114
115
116/* may be called without controller electrically present */
117/* may be called with controller, bus, and devices active */
118
119/**
120 * usb_hcd_lh7a404_remove - shutdown processing for LH7A404-based HCDs
121 * @dev: USB Host Controller being removed
122 * Context: !in_interrupt()
123 *
124 * Reverses the effect of usb_hcd_lh7a404_probe(), first invoking
125 * the HCD's stop() method. It is always called from a thread
126 * context, normally "rmmod", "apmd", or something similar.
127 *
128 */
129void usb_hcd_lh7a404_remove (struct usb_hcd *hcd, struct platform_device *dev)
130{
131 usb_remove_hcd(hcd);
132 lh7a404_stop_hc(dev);
133 iounmap(hcd->regs);
134 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
135 usb_put_hcd(hcd);
136}
137
138/*-------------------------------------------------------------------------*/
139
140static int __devinit
141ohci_lh7a404_start (struct usb_hcd *hcd)
142{
143 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
144 int ret;
145
146 ohci_dbg (ohci, "ohci_lh7a404_start, ohci:%p", ohci);
147 if ((ret = ohci_init(ohci)) < 0)
148 return ret;
149
150 if ((ret = ohci_run (ohci)) < 0) {
151 err ("can't start %s", hcd->self.bus_name);
152 ohci_stop (hcd);
153 return ret;
154 }
155 return 0;
156}
157
158/*-------------------------------------------------------------------------*/
159
160static const struct hc_driver ohci_lh7a404_hc_driver = {
161 .description = hcd_name,
162 .product_desc = "LH7A404 OHCI",
163 .hcd_priv_size = sizeof(struct ohci_hcd),
164
165 /*
166 * generic hardware linkage
167 */
168 .irq = ohci_irq,
169 .flags = HCD_USB11 | HCD_MEMORY,
170
171 /*
172 * basic lifecycle operations
173 */
174 .start = ohci_lh7a404_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 .stop = ohci_stop,
David Brownelldd9048a2006-12-05 03:18:31 -0800176 .shutdown = ohci_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 /*
179 * managing i/o requests and associated device resources
180 */
181 .urb_enqueue = ohci_urb_enqueue,
182 .urb_dequeue = ohci_urb_dequeue,
183 .endpoint_disable = ohci_endpoint_disable,
184
185 /*
186 * scheduling support
187 */
188 .get_frame_number = ohci_get_frame,
189
190 /*
191 * root hub support
192 */
193 .hub_status_data = ohci_hub_status_data,
194 .hub_control = ohci_hub_control,
David Brownell92936772005-09-22 22:32:11 -0700195#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -0400196 .bus_suspend = ohci_bus_suspend,
197 .bus_resume = ohci_bus_resume,
David Brownell92936772005-09-22 22:32:11 -0700198#endif
199 .start_port_reset = ohci_start_port_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200};
201
202/*-------------------------------------------------------------------------*/
203
Russell King3ae5eae2005-11-09 22:32:44 +0000204static int ohci_hcd_lh7a404_drv_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 int ret;
207
208 pr_debug ("In ohci_hcd_lh7a404_drv_probe");
209
210 if (usb_disabled())
211 return -ENODEV;
212
213 ret = usb_hcd_lh7a404_probe(&ohci_lh7a404_hc_driver, pdev);
214 return ret;
215}
216
Russell King3ae5eae2005-11-09 22:32:44 +0000217static int ohci_hcd_lh7a404_drv_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Richard Purdie87cf2032005-11-17 09:47:57 -0800219 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 usb_hcd_lh7a404_remove(hcd, pdev);
222 return 0;
223}
224 /*TBD*/
Russell King3ae5eae2005-11-09 22:32:44 +0000225/*static int ohci_hcd_lh7a404_drv_suspend(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
Russell King3ae5eae2005-11-09 22:32:44 +0000227 struct usb_hcd *hcd = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 return 0;
230}
Russell King3ae5eae2005-11-09 22:32:44 +0000231static int ohci_hcd_lh7a404_drv_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Russell King3ae5eae2005-11-09 22:32:44 +0000233 struct usb_hcd *hcd = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235
236 return 0;
237}
238*/
239
Russell King3ae5eae2005-11-09 22:32:44 +0000240static struct platform_driver ohci_hcd_lh7a404_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 .probe = ohci_hcd_lh7a404_drv_probe,
242 .remove = ohci_hcd_lh7a404_drv_remove,
David Brownelldd9048a2006-12-05 03:18:31 -0800243 .shutdown = usb_hcd_platform_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 /*.suspend = ohci_hcd_lh7a404_drv_suspend, */
245 /*.resume = ohci_hcd_lh7a404_drv_resume, */
Russell King3ae5eae2005-11-09 22:32:44 +0000246 .driver = {
247 .name = "lh7a404-ohci",
248 .owner = THIS_MODULE,
249 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250};
251
Kay Sieversf4fce612008-04-10 21:29:22 -0700252MODULE_ALIAS("platform:lh7a404-ohci");