blob: 529590eb40374c4dc024088a2e13a2ced6a38cea [file] [log] [blame]
Stefan Roesefc65a152007-05-04 11:38:17 -07001/*
2 * EHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 2006-2007 Stefan Roese <sr@denx.de>, DENX Software Engineering
5 *
6 * Bus Glue for PPC On-Chip EHCI driver
7 * Tested on AMCC 440EPx
8 *
Mike Nussc907d3b2007-08-20 18:21:15 -07009 * Based on "ehci-au1xxx.c" by K.Boge <karsten.boge@amd.com>
Stefan Roesefc65a152007-05-04 11:38:17 -070010 *
11 * This file is licenced under the GPL.
12 */
13
14#include <linux/platform_device.h>
15
16extern int usb_disabled(void);
17
Mike Nussc907d3b2007-08-20 18:21:15 -070018/* called during probe() after chip reset completes */
19static int ehci_ppc_soc_setup(struct usb_hcd *hcd)
20{
21 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
22 int retval;
23
24 retval = ehci_halt(ehci);
25 if (retval)
26 return retval;
27
28 retval = ehci_init(hcd);
29 if (retval)
30 return retval;
31
32 ehci->sbrn = 0x20;
33 return ehci_reset(ehci);
34}
35
Stefan Roesefc65a152007-05-04 11:38:17 -070036/**
37 * usb_ehci_ppc_soc_probe - initialize PPC-SoC-based HCDs
38 * Context: !in_interrupt()
39 *
40 * Allocates basic resources for this USB host controller, and
41 * then invokes the start() method for the HCD associated with it
42 * through the hotplug entry's driver_data.
43 *
44 */
45int usb_ehci_ppc_soc_probe(const struct hc_driver *driver,
46 struct usb_hcd **hcd_out,
47 struct platform_device *dev)
48{
49 int retval;
50 struct usb_hcd *hcd;
51 struct ehci_hcd *ehci;
52
53 if (dev->resource[1].flags != IORESOURCE_IRQ) {
54 pr_debug("resource[1] is not IORESOURCE_IRQ");
55 retval = -ENOMEM;
56 }
57 hcd = usb_create_hcd(driver, &dev->dev, "PPC-SOC EHCI");
58 if (!hcd)
59 return -ENOMEM;
60 hcd->rsrc_start = dev->resource[0].start;
61 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
62
63 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
64 pr_debug("request_mem_region failed");
65 retval = -EBUSY;
66 goto err1;
67 }
68
69 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
70 if (!hcd->regs) {
71 pr_debug("ioremap failed");
72 retval = -ENOMEM;
73 goto err2;
74 }
75
76 ehci = hcd_to_ehci(hcd);
77 ehci->big_endian_mmio = 1;
78 ehci->big_endian_desc = 1;
79 ehci->caps = hcd->regs;
80 ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
81
82 /* cache this readonly data; minimize chip reads */
83 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
84
85#if defined(CONFIG_440EPX)
86 /*
87 * 440EPx Errata USBH_3
88 * Fix: Enable Break Memory Transfer (BMT) in INSNREG3
89 */
90 out_be32((void *)((ulong)(&ehci->regs->command) + 0x8c), (1 << 0));
91 ehci_dbg(ehci, "Break Memory Transfer (BMT) has beed enabled!\n");
92#endif
93
94 retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
95 if (retval == 0)
96 return retval;
97
98 iounmap(hcd->regs);
99err2:
100 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
101err1:
102 usb_put_hcd(hcd);
103 return retval;
104}
105
106/* may be called without controller electrically present */
107/* may be called with controller, bus, and devices active */
108
109/**
110 * usb_ehci_hcd_ppc_soc_remove - shutdown processing for PPC-SoC-based HCDs
111 * @dev: USB Host Controller being removed
112 * Context: !in_interrupt()
113 *
114 * Reverses the effect of usb_ehci_hcd_ppc_soc_probe(), first invoking
115 * the HCD's stop() method. It is always called from a thread
116 * context, normally "rmmod", "apmd", or something similar.
117 *
118 */
119void usb_ehci_ppc_soc_remove(struct usb_hcd *hcd, struct platform_device *dev)
120{
121 usb_remove_hcd(hcd);
122 iounmap(hcd->regs);
123 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
124 usb_put_hcd(hcd);
125}
126
127static const struct hc_driver ehci_ppc_soc_hc_driver = {
128 .description = hcd_name,
129 .product_desc = "PPC-SOC EHCI",
130 .hcd_priv_size = sizeof(struct ehci_hcd),
131
132 /*
133 * generic hardware linkage
134 */
135 .irq = ehci_irq,
136 .flags = HCD_MEMORY | HCD_USB2,
137
138 /*
139 * basic lifecycle operations
140 */
Mike Nussc907d3b2007-08-20 18:21:15 -0700141 .reset = ehci_ppc_soc_setup,
Stefan Roesefc65a152007-05-04 11:38:17 -0700142 .start = ehci_run,
143 .stop = ehci_stop,
144 .shutdown = ehci_shutdown,
145
146 /*
147 * managing i/o requests and associated device resources
148 */
149 .urb_enqueue = ehci_urb_enqueue,
150 .urb_dequeue = ehci_urb_dequeue,
151 .endpoint_disable = ehci_endpoint_disable,
152
153 /*
154 * scheduling support
155 */
156 .get_frame_number = ehci_get_frame,
157
158 /*
159 * root hub support
160 */
161 .hub_status_data = ehci_hub_status_data,
162 .hub_control = ehci_hub_control,
David Brownellb24896c2007-10-09 22:04:16 -0700163 .bus_suspend = ehci_bus_suspend,
164 .bus_resume = ehci_bus_resume,
Balaji Rao90da0962007-11-22 01:58:14 +0530165 .relinquish_port = ehci_relinquish_port,
Alan Stern3a311552008-05-20 16:58:29 -0400166 .port_handed_over = ehci_port_handed_over,
Stefan Roesefc65a152007-05-04 11:38:17 -0700167};
168
169static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev)
170{
171 struct usb_hcd *hcd = NULL;
172 int ret;
173
174 pr_debug("In ehci_hcd_ppc_soc_drv_probe\n");
175
176 if (usb_disabled())
177 return -ENODEV;
178
David Brownell135db042008-02-11 18:40:46 -0800179 /* FIXME we only want one one probe() not two */
Stefan Roesefc65a152007-05-04 11:38:17 -0700180 ret = usb_ehci_ppc_soc_probe(&ehci_ppc_soc_hc_driver, &hcd, pdev);
181 return ret;
182}
183
184static int ehci_hcd_ppc_soc_drv_remove(struct platform_device *pdev)
185{
186 struct usb_hcd *hcd = platform_get_drvdata(pdev);
187
David Brownell135db042008-02-11 18:40:46 -0800188 /* FIXME we only want one one remove() not two */
Stefan Roesefc65a152007-05-04 11:38:17 -0700189 usb_ehci_ppc_soc_remove(hcd, pdev);
190 return 0;
191}
192
David Brownell135db042008-02-11 18:40:46 -0800193MODULE_ALIAS("platform:ppc-soc-ehci");
Stefan Roesefc65a152007-05-04 11:38:17 -0700194static struct platform_driver ehci_ppc_soc_driver = {
195 .probe = ehci_hcd_ppc_soc_drv_probe,
196 .remove = ehci_hcd_ppc_soc_drv_remove,
197 .shutdown = usb_hcd_platform_shutdown,
198 .driver = {
199 .name = "ppc-soc-ehci",
Stefan Roesefc65a152007-05-04 11:38:17 -0700200 }
201};