blob: e797f18acb3302fa2023be77aafc56921a436c28 [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
Russell King3f878db2012-01-26 10:39:57 +000051 dev_dbg(&dev->dev, "starting SA-1111 OHCI USB Controller\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 if (machine_is_xp860() ||
54 machine_has_neponset() ||
55 machine_is_pfs168() ||
56 machine_is_badge4())
57 usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW;
58
59 /*
60 * Configure the power sense and control lines. Place the USB
61 * host controller in reset.
62 */
63 sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
Russell King22135362012-01-16 11:37:03 +000064 dev->mapbase + USB_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 /*
67 * Now, carefully enable the USB clock, and take
68 * the USB host controller out of reset.
69 */
Russell Kingae99ddb2012-01-26 13:25:47 +000070 ret = sa1111_enable_device(dev);
71 if (ret == 0) {
72 udelay(11);
Russell King22135362012-01-16 11:37:03 +000073 sa1111_writel(usb_rst, dev->mapbase + USB_RESET);
Russell Kingae99ddb2012-01-26 13:25:47 +000074 }
75
76 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
79static void sa1111_stop_hc(struct sa1111_dev *dev)
80{
81 unsigned int usb_rst;
Russell King9cb0f812012-01-26 10:37:46 +000082
Russell King3f878db2012-01-26 10:39:57 +000083 dev_dbg(&dev->dev, "stopping SA-1111 OHCI USB Controller\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 /*
86 * Put the USB host controller into reset.
87 */
Russell King22135362012-01-16 11:37:03 +000088 usb_rst = sa1111_readl(dev->mapbase + USB_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
Russell King22135362012-01-16 11:37:03 +000090 dev->mapbase + USB_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 /*
93 * Stop the USB clock.
94 */
95 sa1111_disable_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
98
99/*-------------------------------------------------------------------------*/
100
101#if 0
102static void dump_hci_status(struct usb_hcd *hcd, const char *label)
103{
Russell King22135362012-01-16 11:37:03 +0000104 unsigned long status = sa1111_readl(hcd->regs + USB_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Russell King9cb0f812012-01-26 10:37:46 +0000106 dbg("%s USB_STATUS = { %s%s%s%s%s}", label,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""),
108 ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""),
109 ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "),
110 ((status & USB_STATUS_NHCIMFCLR) ? "" : "HCIMFCLR "),
111 ((status & USB_STATUS_USBPWRSENSE) ? "USBPWRSENSE " : ""));
112}
113#endif
114
115/*-------------------------------------------------------------------------*/
116
117/* configure so an HC device and id are always provided */
118/* always called with process context; sleeping is OK */
119
120
121/**
122 * usb_hcd_sa1111_probe - initialize SA-1111-based HCDs
123 * Context: !in_interrupt()
124 *
125 * Allocates basic resources for this USB host controller, and
126 * then invokes the start() method for the HCD associated with it
127 * through the hotplug entry's driver_data.
128 *
129 * Store this function in the HCD's struct pci_driver as probe().
130 */
Russell King9cb0f812012-01-26 10:37:46 +0000131static int usb_hcd_sa1111_probe(const struct hc_driver *driver,
132 struct sa1111_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
134 struct usb_hcd *hcd;
135 int retval;
136
Russell King9cb0f812012-01-26 10:37:46 +0000137 hcd = usb_create_hcd(driver, &dev->dev, "sa1111");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 if (!hcd)
139 return -ENOMEM;
Russell King9cb0f812012-01-26 10:37:46 +0000140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 hcd->rsrc_start = dev->res.start;
Joe Perches28f65c112011-06-09 09:13:32 -0700142 hcd->rsrc_len = resource_size(&dev->res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
145 dbg("request_mem_region failed");
146 retval = -EBUSY;
147 goto err1;
148 }
Russell King9cb0f812012-01-26 10:37:46 +0000149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 hcd->regs = dev->mapbase;
151
Russell Kingae99ddb2012-01-26 13:25:47 +0000152 ret = sa1111_start_hc(dev);
153 if (ret)
154 goto err2;
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 ohci_hcd_init(hcd_to_ohci(hcd));
157
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800158 retval = usb_add_hcd(hcd, dev->irq[1], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 if (retval == 0)
160 return retval;
161
162 sa1111_stop_hc(dev);
Russell Kingae99ddb2012-01-26 13:25:47 +0000163 err2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
165 err1:
166 usb_put_hcd(hcd);
167 return retval;
168}
169
170
171/* may be called without controller electrically present */
172/* may be called with controller, bus, and devices active */
173
174/**
175 * usb_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
176 * @dev: USB Host Controller being removed
177 * Context: !in_interrupt()
178 *
179 * Reverses the effect of usb_hcd_sa1111_probe(), first invoking
180 * the HCD's stop() method. It is always called from a thread
181 * context, normally "rmmod", "apmd", or something similar.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 */
Russell King9cb0f812012-01-26 10:37:46 +0000183static void usb_hcd_sa1111_remove(struct usb_hcd *hcd, struct sa1111_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
185 usb_remove_hcd(hcd);
186 sa1111_stop_hc(dev);
187 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
188 usb_put_hcd(hcd);
189}
190
191/*-------------------------------------------------------------------------*/
192
Russell King9cb0f812012-01-26 10:37:46 +0000193static int __devinit ohci_sa1111_start(struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Russell King9cb0f812012-01-26 10:37:46 +0000195 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
196 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Russell King9cb0f812012-01-26 10:37:46 +0000198 ret = ohci_init(ohci);
199 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 return ret;
201
Russell King9cb0f812012-01-26 10:37:46 +0000202 ret = ohci_run(ohci);
203 if (ret < 0) {
204 err("can't start %s", hcd->self.bus_name);
205 ohci_stop(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return ret;
207 }
208 return 0;
209}
210
211/*-------------------------------------------------------------------------*/
212
213static const struct hc_driver ohci_sa1111_hc_driver = {
214 .description = hcd_name,
215 .product_desc = "SA-1111 OHCI",
216 .hcd_priv_size = sizeof(struct ohci_hcd),
217
218 /*
219 * generic hardware linkage
220 */
221 .irq = ohci_irq,
222 .flags = HCD_USB11 | HCD_MEMORY,
223
224 /*
225 * basic lifecycle operations
226 */
227 .start = ohci_sa1111_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 .stop = ohci_stop,
229
230 /*
231 * managing i/o requests and associated device resources
232 */
233 .urb_enqueue = ohci_urb_enqueue,
234 .urb_dequeue = ohci_urb_dequeue,
235 .endpoint_disable = ohci_endpoint_disable,
236
237 /*
238 * scheduling support
239 */
240 .get_frame_number = ohci_get_frame,
241
242 /*
243 * root hub support
244 */
245 .hub_status_data = ohci_hub_status_data,
246 .hub_control = ohci_hub_control,
David Brownell8ad7fe12005-09-13 19:59:11 -0700247#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -0400248 .bus_suspend = ohci_bus_suspend,
249 .bus_resume = ohci_bus_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250#endif
David Brownell92936772005-09-22 22:32:11 -0700251 .start_port_reset = ohci_start_port_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252};
253
254/*-------------------------------------------------------------------------*/
255
256static int ohci_hcd_sa1111_drv_probe(struct sa1111_dev *dev)
257{
258 int ret;
259
260 if (usb_disabled())
261 return -ENODEV;
262
263 ret = usb_hcd_sa1111_probe(&ohci_sa1111_hc_driver, dev);
264 return ret;
265}
266
267static int ohci_hcd_sa1111_drv_remove(struct sa1111_dev *dev)
268{
269 struct usb_hcd *hcd = sa1111_get_drvdata(dev);
270
271 usb_hcd_sa1111_remove(hcd, dev);
272 return 0;
273}
274
275static struct sa1111_driver ohci_hcd_sa1111_driver = {
276 .drv = {
277 .name = "sa1111-ohci",
Russell King1ebcd762012-01-26 11:19:48 +0000278 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 },
280 .devid = SA1111_DEVID_USB,
281 .probe = ohci_hcd_sa1111_drv_probe,
282 .remove = ohci_hcd_sa1111_drv_remove,
283};
284