blob: f61f4f90529edd80847c5752bafbd977b961c73b [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>
19#include <mach/badge4.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/hardware/sa1111.h>
21
22#ifndef CONFIG_SA1111
23#error "This file is SA-1111 bus glue. CONFIG_SA1111 must be defined."
24#endif
25
26extern int usb_disabled(void);
27
28/*-------------------------------------------------------------------------*/
29
Russell Kingae99ddb2012-01-26 13:25:47 +000030static int sa1111_start_hc(struct sa1111_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
32 unsigned int usb_rst = 0;
Russell Kingae99ddb2012-01-26 13:25:47 +000033 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Joe Perchesf45ba772010-02-05 17:51:13 -080035 printk(KERN_DEBUG "%s: starting SA-1111 OHCI USB Controller\n",
36 __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#ifdef CONFIG_SA1100_BADGE4
39 if (machine_is_badge4()) {
40 badge4_set_5V(BADGE4_5V_USB, 1);
41 }
42#endif
43
44 if (machine_is_xp860() ||
45 machine_has_neponset() ||
46 machine_is_pfs168() ||
47 machine_is_badge4())
48 usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW;
49
50 /*
51 * Configure the power sense and control lines. Place the USB
52 * host controller in reset.
53 */
54 sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
55 dev->mapbase + SA1111_USB_RESET);
56
57 /*
58 * Now, carefully enable the USB clock, and take
59 * the USB host controller out of reset.
60 */
Russell Kingae99ddb2012-01-26 13:25:47 +000061 ret = sa1111_enable_device(dev);
62 if (ret == 0) {
63 udelay(11);
64 sa1111_writel(usb_rst, dev->mapbase + SA1111_USB_RESET);
65 }
66
67 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
70static void sa1111_stop_hc(struct sa1111_dev *dev)
71{
72 unsigned int usb_rst;
Joe Perchesf45ba772010-02-05 17:51:13 -080073 printk(KERN_DEBUG "%s: stopping SA-1111 OHCI USB Controller\n",
74 __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 /*
77 * Put the USB host controller into reset.
78 */
79 usb_rst = sa1111_readl(dev->mapbase + SA1111_USB_RESET);
80 sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
81 dev->mapbase + SA1111_USB_RESET);
82
83 /*
84 * Stop the USB clock.
85 */
86 sa1111_disable_device(dev);
87
88#ifdef CONFIG_SA1100_BADGE4
89 if (machine_is_badge4()) {
90 /* Disable power to the USB bus */
91 badge4_set_5V(BADGE4_5V_USB, 0);
92 }
93#endif
94}
95
96
97/*-------------------------------------------------------------------------*/
98
99#if 0
100static void dump_hci_status(struct usb_hcd *hcd, const char *label)
101{
102 unsigned long status = sa1111_readl(hcd->regs + SA1111_USB_STATUS);
103
104 dbg ("%s USB_STATUS = { %s%s%s%s%s}", label,
105 ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""),
106 ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""),
107 ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "),
108 ((status & USB_STATUS_NHCIMFCLR) ? "" : "HCIMFCLR "),
109 ((status & USB_STATUS_USBPWRSENSE) ? "USBPWRSENSE " : ""));
110}
111#endif
112
113/*-------------------------------------------------------------------------*/
114
115/* configure so an HC device and id are always provided */
116/* always called with process context; sleeping is OK */
117
118
119/**
120 * usb_hcd_sa1111_probe - initialize SA-1111-based HCDs
121 * Context: !in_interrupt()
122 *
123 * Allocates basic resources for this USB host controller, and
124 * then invokes the start() method for the HCD associated with it
125 * through the hotplug entry's driver_data.
126 *
127 * Store this function in the HCD's struct pci_driver as probe().
128 */
129int usb_hcd_sa1111_probe (const struct hc_driver *driver,
130 struct sa1111_dev *dev)
131{
132 struct usb_hcd *hcd;
133 int retval;
134
135 hcd = usb_create_hcd (driver, &dev->dev, "sa1111");
136 if (!hcd)
137 return -ENOMEM;
138 hcd->rsrc_start = dev->res.start;
Joe Perches28f65c112011-06-09 09:13:32 -0700139 hcd->rsrc_len = resource_size(&dev->res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
142 dbg("request_mem_region failed");
143 retval = -EBUSY;
144 goto err1;
145 }
146 hcd->regs = dev->mapbase;
147
Russell Kingae99ddb2012-01-26 13:25:47 +0000148 ret = sa1111_start_hc(dev);
149 if (ret)
150 goto err2;
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 ohci_hcd_init(hcd_to_ohci(hcd));
153
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800154 retval = usb_add_hcd(hcd, dev->irq[1], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 if (retval == 0)
156 return retval;
157
158 sa1111_stop_hc(dev);
Russell Kingae99ddb2012-01-26 13:25:47 +0000159 err2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
161 err1:
162 usb_put_hcd(hcd);
163 return retval;
164}
165
166
167/* may be called without controller electrically present */
168/* may be called with controller, bus, and devices active */
169
170/**
171 * usb_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
172 * @dev: USB Host Controller being removed
173 * Context: !in_interrupt()
174 *
175 * Reverses the effect of usb_hcd_sa1111_probe(), first invoking
176 * the HCD's stop() method. It is always called from a thread
177 * context, normally "rmmod", "apmd", or something similar.
178 *
179 */
180void usb_hcd_sa1111_remove (struct usb_hcd *hcd, struct sa1111_dev *dev)
181{
182 usb_remove_hcd(hcd);
183 sa1111_stop_hc(dev);
184 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
185 usb_put_hcd(hcd);
186}
187
188/*-------------------------------------------------------------------------*/
189
190static int __devinit
191ohci_sa1111_start (struct usb_hcd *hcd)
192{
193 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
194 int ret;
195
196 if ((ret = ohci_init(ohci)) < 0)
197 return ret;
198
199 if ((ret = ohci_run (ohci)) < 0) {
200 err ("can't start %s", hcd->self.bus_name);
201 ohci_stop (hcd);
202 return ret;
203 }
204 return 0;
205}
206
207/*-------------------------------------------------------------------------*/
208
209static const struct hc_driver ohci_sa1111_hc_driver = {
210 .description = hcd_name,
211 .product_desc = "SA-1111 OHCI",
212 .hcd_priv_size = sizeof(struct ohci_hcd),
213
214 /*
215 * generic hardware linkage
216 */
217 .irq = ohci_irq,
218 .flags = HCD_USB11 | HCD_MEMORY,
219
220 /*
221 * basic lifecycle operations
222 */
223 .start = ohci_sa1111_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 .stop = ohci_stop,
225
226 /*
227 * managing i/o requests and associated device resources
228 */
229 .urb_enqueue = ohci_urb_enqueue,
230 .urb_dequeue = ohci_urb_dequeue,
231 .endpoint_disable = ohci_endpoint_disable,
232
233 /*
234 * scheduling support
235 */
236 .get_frame_number = ohci_get_frame,
237
238 /*
239 * root hub support
240 */
241 .hub_status_data = ohci_hub_status_data,
242 .hub_control = ohci_hub_control,
David Brownell8ad7fe12005-09-13 19:59:11 -0700243#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -0400244 .bus_suspend = ohci_bus_suspend,
245 .bus_resume = ohci_bus_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246#endif
David Brownell92936772005-09-22 22:32:11 -0700247 .start_port_reset = ohci_start_port_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248};
249
250/*-------------------------------------------------------------------------*/
251
252static int ohci_hcd_sa1111_drv_probe(struct sa1111_dev *dev)
253{
254 int ret;
255
256 if (usb_disabled())
257 return -ENODEV;
258
259 ret = usb_hcd_sa1111_probe(&ohci_sa1111_hc_driver, dev);
260 return ret;
261}
262
263static int ohci_hcd_sa1111_drv_remove(struct sa1111_dev *dev)
264{
265 struct usb_hcd *hcd = sa1111_get_drvdata(dev);
266
267 usb_hcd_sa1111_remove(hcd, dev);
268 return 0;
269}
270
271static struct sa1111_driver ohci_hcd_sa1111_driver = {
272 .drv = {
273 .name = "sa1111-ohci",
Russell King1ebcd762012-01-26 11:19:48 +0000274 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 },
276 .devid = SA1111_DEVID_USB,
277 .probe = ohci_hcd_sa1111_drv_probe,
278 .remove = ohci_hcd_sa1111_drv_remove,
279};
280