blob: 50ebeb310fda1ad303938fcf28d31e44914a3ba7 [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 -070044/*-------------------------------------------------------------------------*/
45
Russell Kingae99ddb2012-01-26 13:25:47 +000046static int sa1111_start_hc(struct sa1111_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
48 unsigned int usb_rst = 0;
Russell Kingae99ddb2012-01-26 13:25:47 +000049 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Joe Perchesf45ba772010-02-05 17:51:13 -080051 printk(KERN_DEBUG "%s: starting SA-1111 OHCI USB Controller\n",
52 __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 if (machine_is_xp860() ||
55 machine_has_neponset() ||
56 machine_is_pfs168() ||
57 machine_is_badge4())
58 usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW;
59
60 /*
61 * Configure the power sense and control lines. Place the USB
62 * host controller in reset.
63 */
64 sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
Russell King22135362012-01-16 11:37:03 +000065 dev->mapbase + USB_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 /*
68 * Now, carefully enable the USB clock, and take
69 * the USB host controller out of reset.
70 */
Russell Kingae99ddb2012-01-26 13:25:47 +000071 ret = sa1111_enable_device(dev);
72 if (ret == 0) {
73 udelay(11);
Russell King22135362012-01-16 11:37:03 +000074 sa1111_writel(usb_rst, dev->mapbase + USB_RESET);
Russell Kingae99ddb2012-01-26 13:25:47 +000075 }
76
77 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
80static void sa1111_stop_hc(struct sa1111_dev *dev)
81{
82 unsigned int usb_rst;
Russell King9cb0f812012-01-26 10:37:46 +000083
Joe Perchesf45ba772010-02-05 17:51:13 -080084 printk(KERN_DEBUG "%s: stopping SA-1111 OHCI USB Controller\n",
85 __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 /*
88 * Put the USB host controller into reset.
89 */
Russell King22135362012-01-16 11:37:03 +000090 usb_rst = sa1111_readl(dev->mapbase + USB_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
Russell King22135362012-01-16 11:37:03 +000092 dev->mapbase + USB_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 /*
95 * Stop the USB clock.
96 */
97 sa1111_disable_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
100
101/*-------------------------------------------------------------------------*/
102
103#if 0
104static void dump_hci_status(struct usb_hcd *hcd, const char *label)
105{
Russell King22135362012-01-16 11:37:03 +0000106 unsigned long status = sa1111_readl(hcd->regs + USB_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Russell King9cb0f812012-01-26 10:37:46 +0000108 dbg("%s USB_STATUS = { %s%s%s%s%s}", label,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""),
110 ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""),
111 ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "),
112 ((status & USB_STATUS_NHCIMFCLR) ? "" : "HCIMFCLR "),
113 ((status & USB_STATUS_USBPWRSENSE) ? "USBPWRSENSE " : ""));
114}
115#endif
116
117/*-------------------------------------------------------------------------*/
118
119/* configure so an HC device and id are always provided */
120/* always called with process context; sleeping is OK */
121
122
123/**
124 * usb_hcd_sa1111_probe - initialize SA-1111-based HCDs
125 * Context: !in_interrupt()
126 *
127 * Allocates basic resources for this USB host controller, and
128 * then invokes the start() method for the HCD associated with it
129 * through the hotplug entry's driver_data.
130 *
131 * Store this function in the HCD's struct pci_driver as probe().
132 */
Russell King9cb0f812012-01-26 10:37:46 +0000133static int usb_hcd_sa1111_probe(const struct hc_driver *driver,
134 struct sa1111_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
136 struct usb_hcd *hcd;
137 int retval;
138
Russell King9cb0f812012-01-26 10:37:46 +0000139 hcd = usb_create_hcd(driver, &dev->dev, "sa1111");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if (!hcd)
141 return -ENOMEM;
Russell King9cb0f812012-01-26 10:37:46 +0000142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 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 }
Russell King9cb0f812012-01-26 10:37:46 +0000151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 hcd->regs = dev->mapbase;
153
Russell Kingae99ddb2012-01-26 13:25:47 +0000154 ret = sa1111_start_hc(dev);
155 if (ret)
156 goto err2;
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 ohci_hcd_init(hcd_to_ohci(hcd));
159
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800160 retval = usb_add_hcd(hcd, dev->irq[1], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 if (retval == 0)
162 return retval;
163
164 sa1111_stop_hc(dev);
Russell Kingae99ddb2012-01-26 13:25:47 +0000165 err2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
167 err1:
168 usb_put_hcd(hcd);
169 return retval;
170}
171
172
173/* may be called without controller electrically present */
174/* may be called with controller, bus, and devices active */
175
176/**
177 * usb_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
178 * @dev: USB Host Controller being removed
179 * Context: !in_interrupt()
180 *
181 * Reverses the effect of usb_hcd_sa1111_probe(), first invoking
182 * the HCD's stop() method. It is always called from a thread
183 * context, normally "rmmod", "apmd", or something similar.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 */
Russell King9cb0f812012-01-26 10:37:46 +0000185static void usb_hcd_sa1111_remove(struct usb_hcd *hcd, struct sa1111_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
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
Russell King9cb0f812012-01-26 10:37:46 +0000195static int __devinit ohci_sa1111_start(struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Russell King9cb0f812012-01-26 10:37:46 +0000197 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
198 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Russell King9cb0f812012-01-26 10:37:46 +0000200 ret = ohci_init(ohci);
201 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return ret;
203
Russell King9cb0f812012-01-26 10:37:46 +0000204 ret = ohci_run(ohci);
205 if (ret < 0) {
206 err("can't start %s", hcd->self.bus_name);
207 ohci_stop(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return ret;
209 }
210 return 0;
211}
212
213/*-------------------------------------------------------------------------*/
214
215static const struct hc_driver ohci_sa1111_hc_driver = {
216 .description = hcd_name,
217 .product_desc = "SA-1111 OHCI",
218 .hcd_priv_size = sizeof(struct ohci_hcd),
219
220 /*
221 * generic hardware linkage
222 */
223 .irq = ohci_irq,
224 .flags = HCD_USB11 | HCD_MEMORY,
225
226 /*
227 * basic lifecycle operations
228 */
229 .start = ohci_sa1111_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 .stop = ohci_stop,
231
232 /*
233 * managing i/o requests and associated device resources
234 */
235 .urb_enqueue = ohci_urb_enqueue,
236 .urb_dequeue = ohci_urb_dequeue,
237 .endpoint_disable = ohci_endpoint_disable,
238
239 /*
240 * scheduling support
241 */
242 .get_frame_number = ohci_get_frame,
243
244 /*
245 * root hub support
246 */
247 .hub_status_data = ohci_hub_status_data,
248 .hub_control = ohci_hub_control,
David Brownell8ad7fe12005-09-13 19:59:11 -0700249#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -0400250 .bus_suspend = ohci_bus_suspend,
251 .bus_resume = ohci_bus_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252#endif
David Brownell92936772005-09-22 22:32:11 -0700253 .start_port_reset = ohci_start_port_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254};
255
256/*-------------------------------------------------------------------------*/
257
258static int ohci_hcd_sa1111_drv_probe(struct sa1111_dev *dev)
259{
260 int ret;
261
262 if (usb_disabled())
263 return -ENODEV;
264
265 ret = usb_hcd_sa1111_probe(&ohci_sa1111_hc_driver, dev);
266 return ret;
267}
268
269static int ohci_hcd_sa1111_drv_remove(struct sa1111_dev *dev)
270{
271 struct usb_hcd *hcd = sa1111_get_drvdata(dev);
272
273 usb_hcd_sa1111_remove(hcd, dev);
274 return 0;
275}
276
277static struct sa1111_driver ohci_hcd_sa1111_driver = {
278 .drv = {
279 .name = "sa1111-ohci",
Russell King1ebcd762012-01-26 11:19:48 +0000280 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 },
282 .devid = SA1111_DEVID_USB,
283 .probe = ohci_hcd_sa1111_drv_probe,
284 .remove = ohci_hcd_sa1111_drv_remove,
285};
286