2 * OHCI HCD (Host Controller Driver) for USB.
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
8 * Bus Glue for AMD Alchemy Au1xxx
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
13 * Modified for LH7A404 from ohci-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
15 * Modified for AMD Alchemy Au1xxx
16 * by Matt Porter <mporter@kernel.crashing.org>
18 * This file is licenced under the GPL.
21 #include <linux/platform_device.h>
22 #include <linux/signal.h>
24 #include <asm/mach-au1x00/au1000.h>
26 #ifndef CONFIG_SOC_AU1200
28 #define USBH_ENABLE_BE (1<<0)
29 #define USBH_ENABLE_C (1<<1)
30 #define USBH_ENABLE_E (1<<2)
31 #define USBH_ENABLE_CE (1<<3)
32 #define USBH_ENABLE_RD (1<<4)
34 #ifdef __LITTLE_ENDIAN
35 #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
37 #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | \
40 #error not byte order defined
45 #define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
46 #define USB_MCFG_PFEN (1<<31)
47 #define USB_MCFG_RDCOMB (1<<30)
48 #define USB_MCFG_SSDEN (1<<23)
49 #define USB_MCFG_OHCCLKEN (1<<16)
50 #ifdef CONFIG_DMA_COHERENT
51 #define USB_MCFG_UCAM (1<<7)
53 #define USB_MCFG_UCAM (0)
55 #define USB_MCFG_OBMEN (1<<1)
56 #define USB_MCFG_OMEMEN (1<<0)
58 #define USBH_ENABLE_CE USB_MCFG_OHCCLKEN
60 #define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \
61 USBH_ENABLE_CE | USB_MCFG_SSDEN | \
63 USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
65 #define USBH_DISABLE (USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
69 extern int usb_disabled(void);
71 static void au1xxx_start_ohc(void)
73 /* enable host controller */
74 #ifndef CONFIG_SOC_AU1200
75 au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
79 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
83 /* wait for reset complete (read register twice; see au1500 errata) */
84 while (au_readl(USB_HOST_CONFIG),
85 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
89 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
93 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
99 static void au1xxx_stop_ohc(void)
101 #ifdef CONFIG_SOC_AU1200
103 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
108 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
112 static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd)
114 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
117 ohci_dbg(ohci, "ohci_au1xxx_start, ohci:%p", ohci);
119 if ((ret = ohci_init(ohci)) < 0)
122 if ((ret = ohci_run(ohci)) < 0) {
123 err ("can't start %s", hcd->self.bus_name);
131 static const struct hc_driver ohci_au1xxx_hc_driver = {
132 .description = hcd_name,
133 .product_desc = "Au1xxx OHCI",
134 .hcd_priv_size = sizeof(struct ohci_hcd),
137 * generic hardware linkage
140 .flags = HCD_USB11 | HCD_MEMORY,
143 * basic lifecycle operations
145 .start = ohci_au1xxx_start,
147 .shutdown = ohci_shutdown,
150 * managing i/o requests and associated device resources
152 .urb_enqueue = ohci_urb_enqueue,
153 .urb_dequeue = ohci_urb_dequeue,
154 .endpoint_disable = ohci_endpoint_disable,
159 .get_frame_number = ohci_get_frame,
164 .hub_status_data = ohci_hub_status_data,
165 .hub_control = ohci_hub_control,
166 .hub_irq_enable = ohci_rhsc_enable,
168 .bus_suspend = ohci_bus_suspend,
169 .bus_resume = ohci_bus_resume,
171 .start_port_reset = ohci_start_port_reset,
174 static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
182 #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
183 /* Au1200 AB USB does not support coherent memory */
184 if (!(read_c0_prid() & 0xff)) {
185 printk(KERN_INFO "%s: this is chip revision AB !!\n",
187 printk(KERN_INFO "%s: update your board or re-configure "
188 "the kernel\n", pdev->name);
193 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
194 pr_debug("resource[1] is not IORESOURCE_IRQ\n");
198 hcd = usb_create_hcd(&ohci_au1xxx_hc_driver, &pdev->dev, "au1xxx");
202 hcd->rsrc_start = pdev->resource[0].start;
203 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
205 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
206 pr_debug("request_mem_region failed\n");
211 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
213 pr_debug("ioremap failed\n");
219 ohci_hcd_init(hcd_to_ohci(hcd));
221 ret = usb_add_hcd(hcd, pdev->resource[1].start,
222 IRQF_DISABLED | IRQF_SHARED);
224 platform_set_drvdata(pdev, hcd);
231 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
237 static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
239 struct usb_hcd *hcd = platform_get_drvdata(pdev);
244 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
246 platform_set_drvdata(pdev, NULL);
252 static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *pdev,
253 pm_message_t message)
255 struct usb_hcd *hcd = platform_get_drvdata(pdev);
256 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
262 /* Root hub was already suspended. Disable irq emission and
263 * mark HW unaccessible, bail out if RH has been resumed. Use
264 * the spinlock to properly synchronize with possible pending
265 * RH suspend or resume activity.
267 * This is still racy as hcd->state is manipulated outside of
268 * any locks =P But that will be a different fix.
270 spin_lock_irqsave(&ohci->lock, flags);
271 if (hcd->state != HC_STATE_SUSPENDED) {
275 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
276 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
278 /* make sure snapshot being resumed re-enumerates everything */
279 if (message.event == PM_EVENT_PRETHAW)
280 ohci_usb_reset(ohci);
282 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
286 spin_unlock_irqrestore(&ohci->lock, flags);
291 static int ohci_hcd_au1xxx_drv_resume(struct platform_device *pdev)
293 struct usb_hcd *hcd = platform_get_drvdata(pdev);
297 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
298 ohci_finish_controller_resume(hcd);
303 #define ohci_hcd_au1xxx_drv_suspend NULL
304 #define ohci_hcd_au1xxx_drv_resume NULL
307 static struct platform_driver ohci_hcd_au1xxx_driver = {
308 .probe = ohci_hcd_au1xxx_drv_probe,
309 .remove = ohci_hcd_au1xxx_drv_remove,
310 .shutdown = usb_hcd_platform_shutdown,
311 .suspend = ohci_hcd_au1xxx_drv_suspend,
312 .resume = ohci_hcd_au1xxx_drv_resume,
314 .name = "au1xxx-ohci",
315 .owner = THIS_MODULE,
319 MODULE_ALIAS("platform:au1xxx-ohci");