Commit | Line | Data |
---|---|---|
fc65a15f SR |
1 | /* |
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 | * | |
c907d3b0 | 9 | * Based on "ehci-au1xxx.c" by K.Boge <karsten.boge@amd.com> |
fc65a15f SR |
10 | * |
11 | * This file is licenced under the GPL. | |
12 | */ | |
13 | ||
14 | #include <linux/platform_device.h> | |
15 | ||
16 | extern int usb_disabled(void); | |
17 | ||
c907d3b0 MN |
18 | /* called during probe() after chip reset completes */ |
19 | static 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 | ||
fc65a15f SR |
36 | /** |
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 | */ | |
45 | int 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); | |
99 | err2: | |
100 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | |
101 | err1: | |
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 | */ | |
119 | void 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 | ||
127 | static 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 | */ | |
c907d3b0 | 141 | .reset = ehci_ppc_soc_setup, |
fc65a15f SR |
142 | .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, | |
163 | #ifdef CONFIG_PM | |
164 | .hub_suspend = ehci_hub_suspend, | |
165 | .hub_resume = ehci_hub_resume, | |
166 | #endif | |
167 | }; | |
168 | ||
169 | static 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 | ||
179 | ret = usb_ehci_ppc_soc_probe(&ehci_ppc_soc_hc_driver, &hcd, pdev); | |
180 | return ret; | |
181 | } | |
182 | ||
183 | static int ehci_hcd_ppc_soc_drv_remove(struct platform_device *pdev) | |
184 | { | |
185 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | |
186 | ||
187 | usb_ehci_ppc_soc_remove(hcd, pdev); | |
188 | return 0; | |
189 | } | |
190 | ||
191 | MODULE_ALIAS("ppc-soc-ehci"); | |
192 | static struct platform_driver ehci_ppc_soc_driver = { | |
193 | .probe = ehci_hcd_ppc_soc_drv_probe, | |
194 | .remove = ehci_hcd_ppc_soc_drv_remove, | |
195 | .shutdown = usb_hcd_platform_shutdown, | |
196 | .driver = { | |
197 | .name = "ppc-soc-ehci", | |
198 | .bus = &platform_bus_type | |
199 | } | |
200 | }; |