blob: 89e670e38c106b79f8851563728280e5e442e744 [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 * (C) Copyright 2003-2005 MontaVista Software Inc.
David Brownelldd9048a2006-12-05 03:18:31 -08008 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Bus Glue for PPC On-Chip OHCI driver
10 * Tested on Freescale MPC5200 and IBM STB04xxx
11 *
12 * Modified by Dale Farnsworth <dale@farnsworth.org> from ohci-sa1111.c
13 *
14 * This file is licenced under the GPL.
15 */
16
Russell Kingd052d1b2005-10-29 19:07:23 +010017#include <linux/platform_device.h>
Tim Schmielaude259682006-01-08 01:02:05 -080018#include <linux/signal.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/* configure so an HC device and id are always provided */
21/* always called with process context; sleeping is OK */
22
23/**
24 * usb_hcd_ppc_soc_probe - initialize On-Chip HCDs
25 * Context: !in_interrupt()
26 *
Dale Farnsworth4fbd55f2005-08-10 17:25:25 -070027 * Allocates basic resources for this USB host controller.
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 *
29 * Store this function in the HCD's struct pci_driver as probe().
30 */
31static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
32 struct platform_device *pdev)
33{
34 int retval;
35 struct usb_hcd *hcd;
36 struct ohci_hcd *ohci;
37 struct resource *res;
38 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40 pr_debug("initializing PPC-SOC USB Controller\n");
41
42 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
43 if (!res) {
Joe Perchesf45ba772010-02-05 17:51:13 -080044 pr_debug("%s: no irq\n", __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 return -ENODEV;
46 }
47 irq = res->start;
48
49 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
50 if (!res) {
Joe Perchesf45ba772010-02-05 17:51:13 -080051 pr_debug("%s: no reg addr\n", __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 return -ENODEV;
53 }
54
55 hcd = usb_create_hcd(driver, &pdev->dev, "PPC-SOC USB");
56 if (!hcd)
57 return -ENOMEM;
58 hcd->rsrc_start = res->start;
59 hcd->rsrc_len = res->end - res->start + 1;
60
61 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
Joe Perchesf45ba772010-02-05 17:51:13 -080062 pr_debug("%s: request_mem_region failed\n", __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 retval = -EBUSY;
64 goto err1;
65 }
66
67 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
68 if (!hcd->regs) {
Joe Perchesf45ba772010-02-05 17:51:13 -080069 pr_debug("%s: ioremap failed\n", __FILE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 retval = -ENOMEM;
71 goto err2;
72 }
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 ohci = hcd_to_ohci(hcd);
Benjamin Herrenschmidt11d1a4a2006-12-15 06:54:03 +110075 ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
Valentine Barshak4f454262007-10-09 15:00:05 -070076
77#ifdef CONFIG_PPC_MPC52xx
78 /* MPC52xx doesn't need frame_no shift */
79 ohci->flags |= OHCI_QUIRK_FRAME_NO;
80#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 ohci_hcd_init(ohci);
82
Thomas Gleixnerd54b5ca2006-07-01 19:29:44 -070083 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 if (retval == 0)
85 return retval;
86
87 pr_debug("Removing PPC-SOC USB Controller\n");
Dale Farnsworth4fbd55f2005-08-10 17:25:25 -070088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 iounmap(hcd->regs);
90 err2:
91 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
92 err1:
David Brownelldd9048a2006-12-05 03:18:31 -080093 usb_put_hcd(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 return retval;
95}
96
97
98/* may be called without controller electrically present */
99/* may be called with controller, bus, and devices active */
100
101/**
102 * usb_hcd_ppc_soc_remove - shutdown processing for On-Chip HCDs
103 * @pdev: USB Host Controller being removed
104 * Context: !in_interrupt()
105 *
Dale Farnsworth4fbd55f2005-08-10 17:25:25 -0700106 * Reverses the effect of usb_hcd_ppc_soc_probe().
107 * It is always called from a thread
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 * context, normally "rmmod", "apmd", or something similar.
109 *
110 */
111static void usb_hcd_ppc_soc_remove(struct usb_hcd *hcd,
112 struct platform_device *pdev)
113{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 usb_remove_hcd(hcd);
115
116 pr_debug("stopping PPC-SOC USB Controller\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 iounmap(hcd->regs);
119 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
Dale Farnsworthe52b1d32005-08-09 12:13:35 -0700120 usb_put_hcd(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
123static int __devinit
124ohci_ppc_soc_start(struct usb_hcd *hcd)
125{
126 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
127 int ret;
128
129 if ((ret = ohci_init(ohci)) < 0)
130 return ret;
131
132 if ((ret = ohci_run(ohci)) < 0) {
133 err("can't start %s", ohci_to_hcd(ohci)->self.bus_name);
134 ohci_stop(hcd);
135 return ret;
136 }
137
138 return 0;
139}
140
141static const struct hc_driver ohci_ppc_soc_hc_driver = {
142 .description = hcd_name,
143 .hcd_priv_size = sizeof(struct ohci_hcd),
144
145 /*
146 * generic hardware linkage
147 */
148 .irq = ohci_irq,
149 .flags = HCD_USB11 | HCD_MEMORY,
150
151 /*
152 * basic lifecycle operations
153 */
154 .start = ohci_ppc_soc_start,
155 .stop = ohci_stop,
David Brownelldd9048a2006-12-05 03:18:31 -0800156 .shutdown = ohci_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 /*
159 * managing i/o requests and associated device resources
160 */
161 .urb_enqueue = ohci_urb_enqueue,
162 .urb_dequeue = ohci_urb_dequeue,
163 .endpoint_disable = ohci_endpoint_disable,
164
165 /*
166 * scheduling support
167 */
168 .get_frame_number = ohci_get_frame,
169
170 /*
171 * root hub support
172 */
173 .hub_status_data = ohci_hub_status_data,
174 .hub_control = ohci_hub_control,
David Brownell8ad7fe12005-09-13 19:59:11 -0700175#ifdef CONFIG_PM
Alan Stern0c0382e2005-10-13 17:08:02 -0400176 .bus_suspend = ohci_bus_suspend,
177 .bus_resume = ohci_bus_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178#endif
179 .start_port_reset = ohci_start_port_reset,
180};
181
Russell King3ae5eae2005-11-09 22:32:44 +0000182static int ohci_hcd_ppc_soc_drv_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 int ret;
185
186 if (usb_disabled())
187 return -ENODEV;
188
189 ret = usb_hcd_ppc_soc_probe(&ohci_ppc_soc_hc_driver, pdev);
190 return ret;
191}
192
Russell King3ae5eae2005-11-09 22:32:44 +0000193static int ohci_hcd_ppc_soc_drv_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Andrey Volkov2463ade2005-11-18 01:10:48 -0800195 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 usb_hcd_ppc_soc_remove(hcd, pdev);
198 return 0;
199}
200
Russell King3ae5eae2005-11-09 22:32:44 +0000201static struct platform_driver ohci_hcd_ppc_soc_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 .probe = ohci_hcd_ppc_soc_drv_probe,
203 .remove = ohci_hcd_ppc_soc_drv_remove,
David Brownelldd9048a2006-12-05 03:18:31 -0800204 .shutdown = usb_hcd_platform_shutdown,
David Brownell8ad7fe12005-09-13 19:59:11 -0700205#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/
207 /*.resume = ohci_hcd_ppc_soc_drv_resume,*/
208#endif
Russell King3ae5eae2005-11-09 22:32:44 +0000209 .driver = {
210 .name = "ppc-soc-ohci",
211 .owner = THIS_MODULE,
212 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213};
214
Kay Sieversf4fce612008-04-10 21:29:22 -0700215MODULE_ALIAS("platform:ppc-soc-ohci");