blob: ebec9a7699e34767ffbe1de5115c8226c475f92f [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-1.0+
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * OHCI HCD (Host Controller Driver) for USB.
4 *
5 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
6 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
7 * (C) Copyright 2002 Hewlett-Packard Company
David Brownelldd9048a2006-12-05 03:18:31 -08008 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * SA1111 Bus Glue
10 *
11 * Written by Christopher Hoover <ch@hpl.hp.com>
Uwe Kleine-Königac310bb2008-07-10 17:30:46 -070012 * Based on fragments of previous driver by Russell King et al.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
14 * This file is licenced under the GPL.
15 */
David Brownelldd9048a2006-12-05 03:18:31 -080016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/hardware/sa1111.h>
19
20#ifndef CONFIG_SA1111
21#error "This file is SA-1111 bus glue. CONFIG_SA1111 must be defined."
22#endif
23
Russell King22135362012-01-16 11:37:03 +000024#define USB_STATUS 0x0118
25#define USB_RESET 0x011c
26#define USB_IRQTEST 0x0120
27
28#define USB_RESET_FORCEIFRESET (1 << 0)
29#define USB_RESET_FORCEHCRESET (1 << 1)
30#define USB_RESET_CLKGENRESET (1 << 2)
31#define USB_RESET_SIMSCALEDOWN (1 << 3)
32#define USB_RESET_USBINTTEST (1 << 4)
33#define USB_RESET_SLEEPSTBYEN (1 << 5)
34#define USB_RESET_PWRSENSELOW (1 << 6)
35#define USB_RESET_PWRCTRLLOW (1 << 7)
36
37#define USB_STATUS_IRQHCIRMTWKUP (1 << 7)
38#define USB_STATUS_IRQHCIBUFFACC (1 << 8)
39#define USB_STATUS_NIRQHCIM (1 << 9)
40#define USB_STATUS_NHCIMFCLR (1 << 10)
41#define USB_STATUS_USBPWRSENSE (1 << 11)
42
Russell King132db992012-01-26 10:52:34 +000043#if 0
44static void dump_hci_status(struct usb_hcd *hcd, const char *label)
45{
Russell King263bf612017-09-26 15:16:25 +010046 unsigned long status = readl_relaxed(hcd->regs + USB_STATUS);
Russell King132db992012-01-26 10:52:34 +000047
Greg Kroah-Hartman3879e302012-05-01 21:33:39 -070048 printk(KERN_DEBUG "%s USB_STATUS = { %s%s%s%s%s}\n", label,
Russell King132db992012-01-26 10:52:34 +000049 ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""),
50 ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""),
51 ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "),
52 ((status & USB_STATUS_NHCIMFCLR) ? "" : "HCIMFCLR "),
53 ((status & USB_STATUS_USBPWRSENSE) ? "USBPWRSENSE " : ""));
54}
55#endif
56
Russell King81e6ca32012-01-26 11:45:27 +000057static int ohci_sa1111_reset(struct usb_hcd *hcd)
58{
59 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
60
61 ohci_hcd_init(ohci);
62 return ohci_init(ohci);
63}
64
Bill Pemberton41ac7b32012-11-19 13:21:48 -050065static int ohci_sa1111_start(struct usb_hcd *hcd)
Russell King132db992012-01-26 10:52:34 +000066{
67 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
68 int ret;
69
Russell King132db992012-01-26 10:52:34 +000070 ret = ohci_run(ohci);
71 if (ret < 0) {
Russell King81e6ca32012-01-26 11:45:27 +000072 ohci_err(ohci, "can't start\n");
Russell King132db992012-01-26 10:52:34 +000073 ohci_stop(hcd);
Russell King132db992012-01-26 10:52:34 +000074 }
Russell King81e6ca32012-01-26 11:45:27 +000075 return ret;
Russell King132db992012-01-26 10:52:34 +000076}
77
78static const struct hc_driver ohci_sa1111_hc_driver = {
79 .description = hcd_name,
80 .product_desc = "SA-1111 OHCI",
81 .hcd_priv_size = sizeof(struct ohci_hcd),
82
83 /*
84 * generic hardware linkage
85 */
86 .irq = ohci_irq,
87 .flags = HCD_USB11 | HCD_MEMORY,
88
89 /*
90 * basic lifecycle operations
91 */
Russell King81e6ca32012-01-26 11:45:27 +000092 .reset = ohci_sa1111_reset,
Russell King132db992012-01-26 10:52:34 +000093 .start = ohci_sa1111_start,
94 .stop = ohci_stop,
Russell King846a7042012-01-26 11:10:20 +000095 .shutdown = ohci_shutdown,
Russell King132db992012-01-26 10:52:34 +000096
97 /*
98 * managing i/o requests and associated device resources
99 */
100 .urb_enqueue = ohci_urb_enqueue,
101 .urb_dequeue = ohci_urb_dequeue,
102 .endpoint_disable = ohci_endpoint_disable,
103
104 /*
105 * scheduling support
106 */
107 .get_frame_number = ohci_get_frame,
108
109 /*
110 * root hub support
111 */
112 .hub_status_data = ohci_hub_status_data,
113 .hub_control = ohci_hub_control,
114#ifdef CONFIG_PM
115 .bus_suspend = ohci_bus_suspend,
116 .bus_resume = ohci_bus_resume,
117#endif
118 .start_port_reset = ohci_start_port_reset,
119};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Russell Kingae99ddb2012-01-26 13:25:47 +0000121static int sa1111_start_hc(struct sa1111_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123 unsigned int usb_rst = 0;
Russell Kingae99ddb2012-01-26 13:25:47 +0000124 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Russell King3f878db2012-01-26 10:39:57 +0000126 dev_dbg(&dev->dev, "starting SA-1111 OHCI USB Controller\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 if (machine_is_xp860() ||
Russell King6ebb8f02016-08-26 17:41:32 +0100129 machine_is_assabet() ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 machine_is_pfs168() ||
131 machine_is_badge4())
132 usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW;
133
134 /*
135 * Configure the power sense and control lines. Place the USB
136 * host controller in reset.
137 */
Russell King263bf612017-09-26 15:16:25 +0100138 writel_relaxed(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
Russell King22135362012-01-16 11:37:03 +0000139 dev->mapbase + USB_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 /*
142 * Now, carefully enable the USB clock, and take
143 * the USB host controller out of reset.
144 */
Russell Kingae99ddb2012-01-26 13:25:47 +0000145 ret = sa1111_enable_device(dev);
146 if (ret == 0) {
147 udelay(11);
Russell King263bf612017-09-26 15:16:25 +0100148 writel_relaxed(usb_rst, dev->mapbase + USB_RESET);
Russell Kingae99ddb2012-01-26 13:25:47 +0000149 }
150
151 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
154static void sa1111_stop_hc(struct sa1111_dev *dev)
155{
156 unsigned int usb_rst;
Russell King9cb0f812012-01-26 10:37:46 +0000157
Russell King3f878db2012-01-26 10:39:57 +0000158 dev_dbg(&dev->dev, "stopping SA-1111 OHCI USB Controller\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160 /*
161 * Put the USB host controller into reset.
162 */
Russell King263bf612017-09-26 15:16:25 +0100163 usb_rst = readl_relaxed(dev->mapbase + USB_RESET);
164 writel_relaxed(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
Russell King22135362012-01-16 11:37:03 +0000165 dev->mapbase + USB_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 /*
168 * Stop the USB clock.
169 */
170 sa1111_disable_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/**
Russell King132db992012-01-26 10:52:34 +0000174 * ohci_hcd_sa1111_probe - initialize SA-1111-based HCDs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 *
176 * Allocates basic resources for this USB host controller, and
Russell King132db992012-01-26 10:52:34 +0000177 * then invokes the start() method for the HCD associated with it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 */
Russell King132db992012-01-26 10:52:34 +0000179static int ohci_hcd_sa1111_probe(struct sa1111_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 struct usb_hcd *hcd;
Russell King78655192017-09-26 11:12:12 +0100182 int ret, irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Russell King132db992012-01-26 10:52:34 +0000184 if (usb_disabled())
185 return -ENODEV;
186
Russell King4ffb4312013-06-27 11:10:40 +0100187 /*
188 * We don't call dma_set_mask_and_coherent() here because the
189 * DMA mask has already been appropraitely setup by the core
190 * SA-1111 bus code (which includes bug workarounds.)
191 */
192
Russell King132db992012-01-26 10:52:34 +0000193 hcd = usb_create_hcd(&ohci_sa1111_hc_driver, &dev->dev, "sa1111");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 if (!hcd)
195 return -ENOMEM;
Russell King9cb0f812012-01-26 10:37:46 +0000196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 hcd->rsrc_start = dev->res.start;
Joe Perches28f65c112011-06-09 09:13:32 -0700198 hcd->rsrc_len = resource_size(&dev->res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Russell King78655192017-09-26 11:12:12 +0100200 irq = sa1111_get_irq(dev, 1);
201 if (irq <= 0) {
202 ret = irq ? : -ENXIO;
203 goto err1;
204 }
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
Greg Kroah-Hartman3879e302012-05-01 21:33:39 -0700207 dev_dbg(&dev->dev, "request_mem_region failed\n");
Russell King132db992012-01-26 10:52:34 +0000208 ret = -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 goto err1;
210 }
Russell King9cb0f812012-01-26 10:37:46 +0000211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 hcd->regs = dev->mapbase;
213
Russell Kingae99ddb2012-01-26 13:25:47 +0000214 ret = sa1111_start_hc(dev);
215 if (ret)
216 goto err2;
217
Russell King78655192017-09-26 11:12:12 +0100218 ret = usb_add_hcd(hcd, irq, 0);
Peter Chen3c9740a2013-11-05 10:46:02 +0800219 if (ret == 0) {
220 device_wakeup_enable(hcd->self.controller);
Russell King132db992012-01-26 10:52:34 +0000221 return ret;
Peter Chen3c9740a2013-11-05 10:46:02 +0800222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 sa1111_stop_hc(dev);
Russell Kingae99ddb2012-01-26 13:25:47 +0000225 err2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
227 err1:
228 usb_put_hcd(hcd);
Russell King132db992012-01-26 10:52:34 +0000229 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230}
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232/**
Russell King132db992012-01-26 10:52:34 +0000233 * ohci_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 * @dev: USB Host Controller being removed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 *
Russell King132db992012-01-26 10:52:34 +0000236 * Reverses the effect of ohci_hcd_sa1111_probe(), first invoking
237 * the HCD's stop() method.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 */
Russell King132db992012-01-26 10:52:34 +0000239static int ohci_hcd_sa1111_remove(struct sa1111_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
Russell King132db992012-01-26 10:52:34 +0000241 struct usb_hcd *hcd = sa1111_get_drvdata(dev);
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 usb_remove_hcd(hcd);
244 sa1111_stop_hc(dev);
245 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
246 usb_put_hcd(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 return 0;
249}
250
Russell King6c771d32017-09-26 11:12:39 +0100251static void ohci_hcd_sa1111_shutdown(struct device *_dev)
Russell King846a7042012-01-26 11:10:20 +0000252{
Russell King6c771d32017-09-26 11:12:39 +0100253 struct sa1111_dev *dev = to_sa1111_device(_dev);
Russell King846a7042012-01-26 11:10:20 +0000254 struct usb_hcd *hcd = sa1111_get_drvdata(dev);
255
256 if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
257 hcd->driver->shutdown(hcd);
258 sa1111_stop_hc(dev);
259 }
260}
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262static struct sa1111_driver ohci_hcd_sa1111_driver = {
263 .drv = {
264 .name = "sa1111-ohci",
Russell King1ebcd762012-01-26 11:19:48 +0000265 .owner = THIS_MODULE,
Russell King6c771d32017-09-26 11:12:39 +0100266 .shutdown = ohci_hcd_sa1111_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 },
268 .devid = SA1111_DEVID_USB,
Russell King132db992012-01-26 10:52:34 +0000269 .probe = ohci_hcd_sa1111_probe,
270 .remove = ohci_hcd_sa1111_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271};