blob: 40d886adff536374a3c81808532199f3be8eb524 [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
7 *
8 * Bus Glue for AMD Alchemy Au1xxx
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 * 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>
17 *
18 * This file is licenced under the GPL.
19 */
20
Russell Kingd052d1b2005-10-29 19:07:23 +010021#include <linux/platform_device.h>
Tim Schmielaude259682006-01-08 01:02:05 -080022#include <linux/signal.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/mach-au1x00/au1000.h>
25
Jordan Croused5fb7f12006-01-20 14:09:54 -080026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027extern int usb_disabled(void);
28
Manuel Lauss53c81a32008-06-23 09:08:29 +020029static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Manuel Lauss53c81a32008-06-23 09:08:29 +020031 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
32 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Manuel Lauss53c81a32008-06-23 09:08:29 +020034 ohci_dbg(ohci, "ohci_au1xxx_start, ohci:%p", ohci);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Manuel Lauss53c81a32008-06-23 09:08:29 +020036 if ((ret = ohci_init(ohci)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 return ret;
38
Manuel Lauss53c81a32008-06-23 09:08:29 +020039 if ((ret = ohci_run(ohci)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 err ("can't start %s", hcd->self.bus_name);
Manuel Lauss53c81a32008-06-23 09:08:29 +020041 ohci_stop(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 return ret;
43 }
44
45 return 0;
46}
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048static const struct hc_driver ohci_au1xxx_hc_driver = {
49 .description = hcd_name,
50 .product_desc = "Au1xxx OHCI",
51 .hcd_priv_size = sizeof(struct ohci_hcd),
52
53 /*
54 * generic hardware linkage
55 */
56 .irq = ohci_irq,
57 .flags = HCD_USB11 | HCD_MEMORY,
58
59 /*
60 * basic lifecycle operations
61 */
62 .start = ohci_au1xxx_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 .stop = ohci_stop,
David Brownelldd9048a2006-12-05 03:18:31 -080064 .shutdown = ohci_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 /*
67 * managing i/o requests and associated device resources
68 */
69 .urb_enqueue = ohci_urb_enqueue,
70 .urb_dequeue = ohci_urb_dequeue,
71 .endpoint_disable = ohci_endpoint_disable,
72
73 /*
74 * scheduling support
75 */
76 .get_frame_number = ohci_get_frame,
77
78 /*
79 * root hub support
80 */
81 .hub_status_data = ohci_hub_status_data,
82 .hub_control = ohci_hub_control,
David Brownell92936772005-09-22 22:32:11 -070083#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -040084 .bus_suspend = ohci_bus_suspend,
85 .bus_resume = ohci_bus_resume,
David Brownell92936772005-09-22 22:32:11 -070086#endif
87 .start_port_reset = ohci_start_port_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -070088};
89
Russell King3ae5eae2005-11-09 22:32:44 +000090static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 int ret;
Manuel Lauss53c81a32008-06-23 09:08:29 +020093 struct usb_hcd *hcd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 if (usb_disabled())
96 return -ENODEV;
97
Manuel Lauss53c81a32008-06-23 09:08:29 +020098 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
99 pr_debug("resource[1] is not IORESOURCE_IRQ\n");
100 return -ENOMEM;
101 }
102
103 hcd = usb_create_hcd(&ohci_au1xxx_hc_driver, &pdev->dev, "au1xxx");
104 if (!hcd)
105 return -ENOMEM;
106
107 hcd->rsrc_start = pdev->resource[0].start;
108 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
109
110 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
111 pr_debug("request_mem_region failed\n");
112 ret = -EBUSY;
113 goto err1;
114 }
115
116 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
117 if (!hcd->regs) {
118 pr_debug("ioremap failed\n");
119 ret = -ENOMEM;
120 goto err2;
121 }
122
Manuel Laussce6bc922011-08-12 20:12:33 +0200123 if (alchemy_usb_control(ALCHEMY_USB_OHCI0, 1)) {
124 printk(KERN_INFO "%s: controller init failed!\n", pdev->name);
125 ret = -ENODEV;
126 goto err3;
127 }
128
Manuel Lauss53c81a32008-06-23 09:08:29 +0200129 ohci_hcd_init(hcd_to_ohci(hcd));
130
131 ret = usb_add_hcd(hcd, pdev->resource[1].start,
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800132 IRQF_SHARED);
Manuel Lauss53c81a32008-06-23 09:08:29 +0200133 if (ret == 0) {
134 platform_set_drvdata(pdev, hcd);
135 return ret;
136 }
137
Manuel Laussce6bc922011-08-12 20:12:33 +0200138 alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
139err3:
Manuel Lauss53c81a32008-06-23 09:08:29 +0200140 iounmap(hcd->regs);
141err2:
142 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
143err1:
144 usb_put_hcd(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return ret;
146}
147
Russell King3ae5eae2005-11-09 22:32:44 +0000148static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Russell King3ae5eae2005-11-09 22:32:44 +0000150 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Manuel Lauss53c81a32008-06-23 09:08:29 +0200152 usb_remove_hcd(hcd);
Manuel Laussce6bc922011-08-12 20:12:33 +0200153 alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
Manuel Lauss53c81a32008-06-23 09:08:29 +0200154 iounmap(hcd->regs);
155 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
156 usb_put_hcd(hcd);
157 platform_set_drvdata(pdev, NULL);
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 return 0;
160}
Manuel Lauss53c81a32008-06-23 09:08:29 +0200161
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200162#ifdef CONFIG_PM
Manuel Lauss807fcb52009-07-29 19:13:13 +0200163static int ohci_hcd_au1xxx_drv_suspend(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Manuel Lauss807fcb52009-07-29 19:13:13 +0200165 struct usb_hcd *hcd = dev_get_drvdata(dev);
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200166 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
167 unsigned long flags;
168 int rc;
169
170 rc = 0;
171
172 /* Root hub was already suspended. Disable irq emission and
173 * mark HW unaccessible, bail out if RH has been resumed. Use
174 * the spinlock to properly synchronize with possible pending
175 * RH suspend or resume activity.
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200176 */
177 spin_lock_irqsave(&ohci->lock, flags);
Alan Sternb7463c72011-11-17 16:41:56 -0500178 if (ohci->rh_state != OHCI_RH_SUSPENDED) {
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200179 rc = -EINVAL;
180 goto bail;
181 }
182 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
183 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
184
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200185 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
186
Manuel Laussce6bc922011-08-12 20:12:33 +0200187 alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200188bail:
189 spin_unlock_irqrestore(&ohci->lock, flags);
190
191 return rc;
192}
193
Manuel Lauss807fcb52009-07-29 19:13:13 +0200194static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200195{
Manuel Lauss807fcb52009-07-29 19:13:13 +0200196 struct usb_hcd *hcd = dev_get_drvdata(dev);
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200197
Manuel Laussce6bc922011-08-12 20:12:33 +0200198 alchemy_usb_control(ALCHEMY_USB_OHCI0, 1);
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200199
200 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
201 ohci_finish_controller_resume(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 return 0;
204}
Manuel Lauss807fcb52009-07-29 19:13:13 +0200205
Alexey Dobriyan47145212009-12-14 18:00:08 -0800206static const struct dev_pm_ops au1xxx_ohci_pmops = {
Manuel Lauss807fcb52009-07-29 19:13:13 +0200207 .suspend = ohci_hcd_au1xxx_drv_suspend,
208 .resume = ohci_hcd_au1xxx_drv_resume,
209};
210
211#define AU1XXX_OHCI_PMOPS &au1xxx_ohci_pmops
212
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200213#else
Manuel Lauss807fcb52009-07-29 19:13:13 +0200214#define AU1XXX_OHCI_PMOPS NULL
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200215#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Russell King3ae5eae2005-11-09 22:32:44 +0000217static struct platform_driver ohci_hcd_au1xxx_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 .probe = ohci_hcd_au1xxx_drv_probe,
219 .remove = ohci_hcd_au1xxx_drv_remove,
David Brownelldd9048a2006-12-05 03:18:31 -0800220 .shutdown = usb_hcd_platform_shutdown,
Russell King3ae5eae2005-11-09 22:32:44 +0000221 .driver = {
222 .name = "au1xxx-ohci",
223 .owner = THIS_MODULE,
Manuel Lauss807fcb52009-07-29 19:13:13 +0200224 .pm = AU1XXX_OHCI_PMOPS,
Russell King3ae5eae2005-11-09 22:32:44 +0000225 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226};
227
Kay Sieversf4fce612008-04-10 21:29:22 -0700228MODULE_ALIAS("platform:au1xxx-ohci");