blob: 585e53eabff6220257e55a61193685a40655cb19 [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
David Brownelldd9048a2006-12-05 03:18:31 -08007 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * SA1111 Bus Glue
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 * This file is licenced under the GPL.
14 */
David Brownelldd9048a2006-12-05 03:18:31 -080015
Russell Kinga09e64f2008-08-05 16:14:15 +010016#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/mach-types.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010018#include <mach/assabet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/hardware/sa1111.h>
20
21#ifndef CONFIG_SA1111
22#error "This file is SA-1111 bus glue. CONFIG_SA1111 must be defined."
23#endif
24
Russell King22135362012-01-16 11:37:03 +000025#define USB_STATUS 0x0118
26#define USB_RESET 0x011c
27#define USB_IRQTEST 0x0120
28
29#define USB_RESET_FORCEIFRESET (1 << 0)
30#define USB_RESET_FORCEHCRESET (1 << 1)
31#define USB_RESET_CLKGENRESET (1 << 2)
32#define USB_RESET_SIMSCALEDOWN (1 << 3)
33#define USB_RESET_USBINTTEST (1 << 4)
34#define USB_RESET_SLEEPSTBYEN (1 << 5)
35#define USB_RESET_PWRSENSELOW (1 << 6)
36#define USB_RESET_PWRCTRLLOW (1 << 7)
37
38#define USB_STATUS_IRQHCIRMTWKUP (1 << 7)
39#define USB_STATUS_IRQHCIBUFFACC (1 << 8)
40#define USB_STATUS_NIRQHCIM (1 << 9)
41#define USB_STATUS_NHCIMFCLR (1 << 10)
42#define USB_STATUS_USBPWRSENSE (1 << 11)
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044extern int usb_disabled(void);
45
46/*-------------------------------------------------------------------------*/
47
Russell Kingae99ddb2012-01-26 13:25:47 +000048static int sa1111_start_hc(struct sa1111_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 unsigned int usb_rst = 0;
Russell Kingae99ddb2012-01-26 13:25:47 +000051 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Joe Perchesf45ba772010-02-05 17:51:13 -080053 printk(KERN_DEBUG "%s: starting SA-1111 OHCI USB Controller\n",
54 __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 if (machine_is_xp860() ||
57 machine_has_neponset() ||
58 machine_is_pfs168() ||
59 machine_is_badge4())
60 usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW;
61
62 /*
63 * Configure the power sense and control lines. Place the USB
64 * host controller in reset.
65 */
66 sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
Russell King22135362012-01-16 11:37:03 +000067 dev->mapbase + USB_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 /*
70 * Now, carefully enable the USB clock, and take
71 * the USB host controller out of reset.
72 */
Russell Kingae99ddb2012-01-26 13:25:47 +000073 ret = sa1111_enable_device(dev);
74 if (ret == 0) {
75 udelay(11);
Russell King22135362012-01-16 11:37:03 +000076 sa1111_writel(usb_rst, dev->mapbase + USB_RESET);
Russell Kingae99ddb2012-01-26 13:25:47 +000077 }
78
79 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
82static void sa1111_stop_hc(struct sa1111_dev *dev)
83{
84 unsigned int usb_rst;
Joe Perchesf45ba772010-02-05 17:51:13 -080085 printk(KERN_DEBUG "%s: stopping SA-1111 OHCI USB Controller\n",
86 __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 /*
89 * Put the USB host controller into reset.
90 */
Russell King22135362012-01-16 11:37:03 +000091 usb_rst = sa1111_readl(dev->mapbase + USB_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
Russell King22135362012-01-16 11:37:03 +000093 dev->mapbase + USB_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 /*
96 * Stop the USB clock.
97 */
98 sa1111_disable_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
101
102/*-------------------------------------------------------------------------*/
103
104#if 0
105static void dump_hci_status(struct usb_hcd *hcd, const char *label)
106{
Russell King22135362012-01-16 11:37:03 +0000107 unsigned long status = sa1111_readl(hcd->regs + USB_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109 dbg ("%s USB_STATUS = { %s%s%s%s%s}", label,
110 ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""),
111 ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""),
112 ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "),
113 ((status & USB_STATUS_NHCIMFCLR) ? "" : "HCIMFCLR "),
114 ((status & USB_STATUS_USBPWRSENSE) ? "USBPWRSENSE " : ""));
115}
116#endif
117
118/*-------------------------------------------------------------------------*/
119
120/* configure so an HC device and id are always provided */
121/* always called with process context; sleeping is OK */
122
123
124/**
125 * usb_hcd_sa1111_probe - initialize SA-1111-based HCDs
126 * Context: !in_interrupt()
127 *
128 * Allocates basic resources for this USB host controller, and
129 * then invokes the start() method for the HCD associated with it
130 * through the hotplug entry's driver_data.
131 *
132 * Store this function in the HCD's struct pci_driver as probe().
133 */
134int usb_hcd_sa1111_probe (const struct hc_driver *driver,
135 struct sa1111_dev *dev)
136{
137 struct usb_hcd *hcd;
138 int retval;
139
140 hcd = usb_create_hcd (driver, &dev->dev, "sa1111");
141 if (!hcd)
142 return -ENOMEM;
143 hcd->rsrc_start = dev->res.start;
Joe Perches28f65c112011-06-09 09:13:32 -0700144 hcd->rsrc_len = resource_size(&dev->res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
147 dbg("request_mem_region failed");
148 retval = -EBUSY;
149 goto err1;
150 }
151 hcd->regs = dev->mapbase;
152
Russell Kingae99ddb2012-01-26 13:25:47 +0000153 ret = sa1111_start_hc(dev);
154 if (ret)
155 goto err2;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 ohci_hcd_init(hcd_to_ohci(hcd));
158
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800159 retval = usb_add_hcd(hcd, dev->irq[1], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 if (retval == 0)
161 return retval;
162
163 sa1111_stop_hc(dev);
Russell Kingae99ddb2012-01-26 13:25:47 +0000164 err2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
166 err1:
167 usb_put_hcd(hcd);
168 return retval;
169}
170
171
172/* may be called without controller electrically present */
173/* may be called with controller, bus, and devices active */
174
175/**
176 * usb_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
177 * @dev: USB Host Controller being removed
178 * Context: !in_interrupt()
179 *
180 * Reverses the effect of usb_hcd_sa1111_probe(), first invoking
181 * the HCD's stop() method. It is always called from a thread
182 * context, normally "rmmod", "apmd", or something similar.
183 *
184 */
185void usb_hcd_sa1111_remove (struct usb_hcd *hcd, struct sa1111_dev *dev)
186{
187 usb_remove_hcd(hcd);
188 sa1111_stop_hc(dev);
189 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
190 usb_put_hcd(hcd);
191}
192
193/*-------------------------------------------------------------------------*/
194
195static int __devinit
196ohci_sa1111_start (struct usb_hcd *hcd)
197{
198 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
199 int ret;
200
201 if ((ret = ohci_init(ohci)) < 0)
202 return ret;
203
204 if ((ret = ohci_run (ohci)) < 0) {
205 err ("can't start %s", hcd->self.bus_name);
206 ohci_stop (hcd);
207 return ret;
208 }
209 return 0;
210}
211
212/*-------------------------------------------------------------------------*/
213
214static const struct hc_driver ohci_sa1111_hc_driver = {
215 .description = hcd_name,
216 .product_desc = "SA-1111 OHCI",
217 .hcd_priv_size = sizeof(struct ohci_hcd),
218
219 /*
220 * generic hardware linkage
221 */
222 .irq = ohci_irq,
223 .flags = HCD_USB11 | HCD_MEMORY,
224
225 /*
226 * basic lifecycle operations
227 */
228 .start = ohci_sa1111_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 .stop = ohci_stop,
230
231 /*
232 * managing i/o requests and associated device resources
233 */
234 .urb_enqueue = ohci_urb_enqueue,
235 .urb_dequeue = ohci_urb_dequeue,
236 .endpoint_disable = ohci_endpoint_disable,
237
238 /*
239 * scheduling support
240 */
241 .get_frame_number = ohci_get_frame,
242
243 /*
244 * root hub support
245 */
246 .hub_status_data = ohci_hub_status_data,
247 .hub_control = ohci_hub_control,
David Brownell8ad7fe12005-09-13 19:59:11 -0700248#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -0400249 .bus_suspend = ohci_bus_suspend,
250 .bus_resume = ohci_bus_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#endif
David Brownell92936772005-09-22 22:32:11 -0700252 .start_port_reset = ohci_start_port_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253};
254
255/*-------------------------------------------------------------------------*/
256
257static int ohci_hcd_sa1111_drv_probe(struct sa1111_dev *dev)
258{
259 int ret;
260
261 if (usb_disabled())
262 return -ENODEV;
263
264 ret = usb_hcd_sa1111_probe(&ohci_sa1111_hc_driver, dev);
265 return ret;
266}
267
268static int ohci_hcd_sa1111_drv_remove(struct sa1111_dev *dev)
269{
270 struct usb_hcd *hcd = sa1111_get_drvdata(dev);
271
272 usb_hcd_sa1111_remove(hcd, dev);
273 return 0;
274}
275
276static struct sa1111_driver ohci_hcd_sa1111_driver = {
277 .drv = {
278 .name = "sa1111-ohci",
Russell King1ebcd762012-01-26 11:19:48 +0000279 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 },
281 .devid = SA1111_DEVID_USB,
282 .probe = ohci_hcd_sa1111_drv_probe,
283 .remove = ohci_hcd_sa1111_drv_remove,
284};
285