1 // SPDX-License-Identifier: GPL-1.0+
3 * OHCI HCD (Host Controller Driver) for USB.
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
11 * Written by Christopher Hoover <ch@hpl.hp.com>
12 * Based on fragments of previous driver by Russell King et al.
14 * This file is licenced under the GPL.
17 #include <asm/mach-types.h>
18 #include <asm/hardware/sa1111.h>
21 #error "This file is SA-1111 bus glue. CONFIG_SA1111 must be defined."
24 #define USB_STATUS 0x0118
25 #define USB_RESET 0x011c
26 #define USB_IRQTEST 0x0120
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)
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)
44 static void dump_hci_status(struct usb_hcd
*hcd
, const char *label
)
46 unsigned long status
= readl_relaxed(hcd
->regs
+ USB_STATUS
);
48 printk(KERN_DEBUG
"%s USB_STATUS = { %s%s%s%s%s}\n", label
,
49 ((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 " : ""));
57 static int ohci_sa1111_reset(struct usb_hcd
*hcd
)
59 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
62 return ohci_init(ohci
);
65 static int ohci_sa1111_start(struct usb_hcd
*hcd
)
67 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
72 ohci_err(ohci
, "can't start\n");
78 static 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
),
84 * generic hardware linkage
87 .flags
= HCD_USB11
| HCD_DMA
| HCD_MEMORY
,
90 * basic lifecycle operations
92 .reset
= ohci_sa1111_reset
,
93 .start
= ohci_sa1111_start
,
95 .shutdown
= ohci_shutdown
,
98 * managing i/o requests and associated device resources
100 .urb_enqueue
= ohci_urb_enqueue
,
101 .urb_dequeue
= ohci_urb_dequeue
,
102 .endpoint_disable
= ohci_endpoint_disable
,
107 .get_frame_number
= ohci_get_frame
,
112 .hub_status_data
= ohci_hub_status_data
,
113 .hub_control
= ohci_hub_control
,
115 .bus_suspend
= ohci_bus_suspend
,
116 .bus_resume
= ohci_bus_resume
,
118 .start_port_reset
= ohci_start_port_reset
,
121 static int sa1111_start_hc(struct sa1111_dev
*dev
)
123 unsigned int usb_rst
= 0;
126 dev_dbg(&dev
->dev
, "starting SA-1111 OHCI USB Controller\n");
128 if (machine_is_xp860() ||
129 machine_is_assabet() ||
130 machine_is_pfs168() ||
132 usb_rst
= USB_RESET_PWRSENSELOW
| USB_RESET_PWRCTRLLOW
;
135 * Configure the power sense and control lines. Place the USB
136 * host controller in reset.
138 writel_relaxed(usb_rst
| USB_RESET_FORCEIFRESET
| USB_RESET_FORCEHCRESET
,
139 dev
->mapbase
+ USB_RESET
);
142 * Now, carefully enable the USB clock, and take
143 * the USB host controller out of reset.
145 ret
= sa1111_enable_device(dev
);
148 writel_relaxed(usb_rst
, dev
->mapbase
+ USB_RESET
);
154 static void sa1111_stop_hc(struct sa1111_dev
*dev
)
156 unsigned int usb_rst
;
158 dev_dbg(&dev
->dev
, "stopping SA-1111 OHCI USB Controller\n");
161 * Put the USB host controller into reset.
163 usb_rst
= readl_relaxed(dev
->mapbase
+ USB_RESET
);
164 writel_relaxed(usb_rst
| USB_RESET_FORCEIFRESET
| USB_RESET_FORCEHCRESET
,
165 dev
->mapbase
+ USB_RESET
);
168 * Stop the USB clock.
170 sa1111_disable_device(dev
);
174 * ohci_hcd_sa1111_probe - initialize SA-1111-based HCDs
176 * Allocates basic resources for this USB host controller, and
177 * then invokes the start() method for the HCD associated with it.
179 static int ohci_hcd_sa1111_probe(struct sa1111_dev
*dev
)
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.)
193 hcd
= usb_create_hcd(&ohci_sa1111_hc_driver
, &dev
->dev
, "sa1111");
197 hcd
->rsrc_start
= dev
->res
.start
;
198 hcd
->rsrc_len
= resource_size(&dev
->res
);
200 irq
= sa1111_get_irq(dev
, 1);
202 ret
= irq
? : -ENXIO
;
206 if (!request_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
, hcd_name
)) {
207 dev_dbg(&dev
->dev
, "request_mem_region failed\n");
212 hcd
->regs
= dev
->mapbase
;
214 ret
= sa1111_start_hc(dev
);
218 ret
= usb_add_hcd(hcd
, irq
, 0);
220 device_wakeup_enable(hcd
->self
.controller
);
226 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
233 * ohci_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
234 * @dev: USB Host Controller being removed
236 * Reverses the effect of ohci_hcd_sa1111_probe(), first invoking
237 * the HCD's stop() method.
239 static int ohci_hcd_sa1111_remove(struct sa1111_dev
*dev
)
241 struct usb_hcd
*hcd
= sa1111_get_drvdata(dev
);
245 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
251 static void ohci_hcd_sa1111_shutdown(struct device
*_dev
)
253 struct sa1111_dev
*dev
= to_sa1111_device(_dev
);
254 struct usb_hcd
*hcd
= sa1111_get_drvdata(dev
);
256 if (test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
)) {
257 hcd
->driver
->shutdown(hcd
);
262 static struct sa1111_driver ohci_hcd_sa1111_driver
= {
264 .name
= "sa1111-ohci",
265 .owner
= THIS_MODULE
,
266 .shutdown
= ohci_hcd_sa1111_shutdown
,
268 .devid
= SA1111_DEVID_USB
,
269 .probe
= ohci_hcd_sa1111_probe
,
270 .remove
= ohci_hcd_sa1111_remove
,