Commit | Line | Data |
---|---|---|
80cb9aee | 1 | /* |
80cb9aee RV |
2 | * Copyright (c) 2005 MontaVista Software |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU General Public License as published by the | |
6 | * Free Software Foundation; either version 2 of the License, or (at your | |
7 | * option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but | |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 | * for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software Foundation, | |
16 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
17 | * | |
18 | * Ported to 834x by Randy Vinson <rvinson@mvista.com> using code provided | |
19 | * by Hunter Wu. | |
20 | */ | |
21 | ||
22 | #include <linux/platform_device.h> | |
23 | #include <linux/fsl_devices.h> | |
24 | ||
25 | #include "ehci-fsl.h" | |
26 | ||
dc0d5c1e | 27 | /* FIXME: Power Management is un-ported so temporarily disable it */ |
80cb9aee RV |
28 | #undef CONFIG_PM |
29 | ||
80cb9aee RV |
30 | |
31 | /* configure so an HC device and id are always provided */ | |
32 | /* always called with process context; sleeping is OK */ | |
33 | ||
34 | /** | |
35 | * usb_hcd_fsl_probe - initialize FSL-based HCDs | |
36 | * @drvier: Driver to be used for this HCD | |
37 | * @pdev: USB Host Controller being probed | |
38 | * Context: !in_interrupt() | |
39 | * | |
40 | * Allocates basic resources for this USB host controller. | |
41 | * | |
42 | */ | |
43 | int usb_hcd_fsl_probe(const struct hc_driver *driver, | |
44 | struct platform_device *pdev) | |
45 | { | |
46 | struct fsl_usb2_platform_data *pdata; | |
47 | struct usb_hcd *hcd; | |
48 | struct resource *res; | |
49 | int irq; | |
50 | int retval; | |
51 | unsigned int temp; | |
52 | ||
53 | pr_debug("initializing FSL-SOC USB Controller\n"); | |
54 | ||
55 | /* Need platform data for setup */ | |
56 | pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data; | |
57 | if (!pdata) { | |
58 | dev_err(&pdev->dev, | |
7071a3ce | 59 | "No platform data for %s.\n", dev_name(&pdev->dev)); |
80cb9aee RV |
60 | return -ENODEV; |
61 | } | |
62 | ||
63 | /* | |
64 | * This is a host mode driver, verify that we're supposed to be | |
65 | * in host mode. | |
66 | */ | |
67 | if (!((pdata->operating_mode == FSL_USB2_DR_HOST) || | |
ba02978a LY |
68 | (pdata->operating_mode == FSL_USB2_MPH_HOST) || |
69 | (pdata->operating_mode == FSL_USB2_DR_OTG))) { | |
80cb9aee RV |
70 | dev_err(&pdev->dev, |
71 | "Non Host Mode configured for %s. Wrong driver linked.\n", | |
7071a3ce | 72 | dev_name(&pdev->dev)); |
80cb9aee RV |
73 | return -ENODEV; |
74 | } | |
75 | ||
76 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | |
77 | if (!res) { | |
78 | dev_err(&pdev->dev, | |
79 | "Found HC with no IRQ. Check %s setup!\n", | |
7071a3ce | 80 | dev_name(&pdev->dev)); |
80cb9aee RV |
81 | return -ENODEV; |
82 | } | |
83 | irq = res->start; | |
84 | ||
7071a3ce | 85 | hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); |
80cb9aee RV |
86 | if (!hcd) { |
87 | retval = -ENOMEM; | |
88 | goto err1; | |
89 | } | |
90 | ||
91 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
92 | if (!res) { | |
93 | dev_err(&pdev->dev, | |
94 | "Found HC with no register addr. Check %s setup!\n", | |
7071a3ce | 95 | dev_name(&pdev->dev)); |
80cb9aee RV |
96 | retval = -ENODEV; |
97 | goto err2; | |
98 | } | |
99 | hcd->rsrc_start = res->start; | |
100 | hcd->rsrc_len = res->end - res->start + 1; | |
101 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, | |
102 | driver->description)) { | |
103 | dev_dbg(&pdev->dev, "controller already in use\n"); | |
104 | retval = -EBUSY; | |
105 | goto err2; | |
106 | } | |
107 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | |
108 | ||
109 | if (hcd->regs == NULL) { | |
110 | dev_dbg(&pdev->dev, "error mapping memory\n"); | |
111 | retval = -EFAULT; | |
112 | goto err3; | |
113 | } | |
114 | ||
115 | /* Enable USB controller */ | |
116 | temp = in_be32(hcd->regs + 0x500); | |
117 | out_be32(hcd->regs + 0x500, temp | 0x4); | |
118 | ||
119 | /* Set to Host mode */ | |
120 | temp = in_le32(hcd->regs + 0x1a8); | |
121 | out_le32(hcd->regs + 0x1a8, temp | 0x3); | |
122 | ||
442258e2 | 123 | retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); |
80cb9aee RV |
124 | if (retval != 0) |
125 | goto err4; | |
126 | return retval; | |
127 | ||
128 | err4: | |
129 | iounmap(hcd->regs); | |
130 | err3: | |
131 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | |
132 | err2: | |
133 | usb_put_hcd(hcd); | |
134 | err1: | |
7071a3ce | 135 | dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval); |
80cb9aee RV |
136 | return retval; |
137 | } | |
138 | ||
139 | /* may be called without controller electrically present */ | |
140 | /* may be called with controller, bus, and devices active */ | |
141 | ||
142 | /** | |
143 | * usb_hcd_fsl_remove - shutdown processing for FSL-based HCDs | |
144 | * @dev: USB Host Controller being removed | |
145 | * Context: !in_interrupt() | |
146 | * | |
147 | * Reverses the effect of usb_hcd_fsl_probe(). | |
148 | * | |
149 | */ | |
150 | void usb_hcd_fsl_remove(struct usb_hcd *hcd, struct platform_device *pdev) | |
151 | { | |
152 | usb_remove_hcd(hcd); | |
153 | iounmap(hcd->regs); | |
154 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | |
155 | usb_put_hcd(hcd); | |
156 | } | |
157 | ||
158 | static void mpc83xx_setup_phy(struct ehci_hcd *ehci, | |
159 | enum fsl_usb2_phy_modes phy_mode, | |
160 | unsigned int port_offset) | |
161 | { | |
499003e8 | 162 | u32 portsc = 0; |
80cb9aee RV |
163 | switch (phy_mode) { |
164 | case FSL_USB2_PHY_ULPI: | |
165 | portsc |= PORT_PTS_ULPI; | |
166 | break; | |
167 | case FSL_USB2_PHY_SERIAL: | |
168 | portsc |= PORT_PTS_SERIAL; | |
169 | break; | |
170 | case FSL_USB2_PHY_UTMI_WIDE: | |
171 | portsc |= PORT_PTS_PTW; | |
172 | /* fall through */ | |
173 | case FSL_USB2_PHY_UTMI: | |
174 | portsc |= PORT_PTS_UTMI; | |
175 | break; | |
176 | case FSL_USB2_PHY_NONE: | |
177 | break; | |
178 | } | |
083522d7 | 179 | ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]); |
80cb9aee RV |
180 | } |
181 | ||
182 | static void mpc83xx_usb_setup(struct usb_hcd *hcd) | |
183 | { | |
184 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | |
185 | struct fsl_usb2_platform_data *pdata; | |
186 | void __iomem *non_ehci = hcd->regs; | |
ba02978a | 187 | u32 temp; |
80cb9aee RV |
188 | |
189 | pdata = | |
190 | (struct fsl_usb2_platform_data *)hcd->self.controller-> | |
191 | platform_data; | |
192 | /* Enable PHY interface in the control reg. */ | |
ba02978a LY |
193 | temp = in_be32(non_ehci + FSL_SOC_USB_CTRL); |
194 | out_be32(non_ehci + FSL_SOC_USB_CTRL, temp | 0x00000004); | |
80cb9aee RV |
195 | out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b); |
196 | ||
40acc095 LY |
197 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
198 | /* | |
199 | * Turn on cache snooping hardware, since some PowerPC platforms | |
200 | * wholly rely on hardware to deal with cache coherent | |
201 | */ | |
202 | ||
203 | /* Setup Snooping for all the 4GB space */ | |
204 | /* SNOOP1 starts from 0x0, size 2G */ | |
205 | out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0 | SNOOP_SIZE_2GB); | |
206 | /* SNOOP2 starts from 0x80000000, size 2G */ | |
207 | out_be32(non_ehci + FSL_SOC_USB_SNOOP2, 0x80000000 | SNOOP_SIZE_2GB); | |
208 | #endif | |
209 | ||
ba02978a LY |
210 | if ((pdata->operating_mode == FSL_USB2_DR_HOST) || |
211 | (pdata->operating_mode == FSL_USB2_DR_OTG)) | |
80cb9aee RV |
212 | mpc83xx_setup_phy(ehci, pdata->phy_mode, 0); |
213 | ||
214 | if (pdata->operating_mode == FSL_USB2_MPH_HOST) { | |
8cd42e97 KG |
215 | unsigned int chip, rev, svr; |
216 | ||
217 | svr = mfspr(SPRN_SVR); | |
218 | chip = svr >> 16; | |
219 | rev = (svr >> 4) & 0xf; | |
220 | ||
221 | /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */ | |
222 | if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055)) | |
223 | ehci->has_fsl_port_bug = 1; | |
224 | ||
80cb9aee RV |
225 | if (pdata->port_enables & FSL_USB2_PORT0_ENABLED) |
226 | mpc83xx_setup_phy(ehci, pdata->phy_mode, 0); | |
227 | if (pdata->port_enables & FSL_USB2_PORT1_ENABLED) | |
228 | mpc83xx_setup_phy(ehci, pdata->phy_mode, 1); | |
229 | } | |
230 | ||
231 | /* put controller in host mode. */ | |
083522d7 | 232 | ehci_writel(ehci, 0x00000003, non_ehci + FSL_SOC_USB_USBMODE); |
4f534258 SS |
233 | #ifdef CONFIG_PPC_85xx |
234 | out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x00000008); | |
235 | out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000080); | |
236 | #else | |
80cb9aee RV |
237 | out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c); |
238 | out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040); | |
4f534258 | 239 | #endif |
80cb9aee RV |
240 | out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001); |
241 | } | |
242 | ||
243 | /* called after powerup, by probe or system-pm "wakeup" */ | |
244 | static int ehci_fsl_reinit(struct ehci_hcd *ehci) | |
245 | { | |
246 | mpc83xx_usb_setup(ehci_to_hcd(ehci)); | |
247 | ehci_port_power(ehci, 0); | |
248 | ||
249 | return 0; | |
250 | } | |
251 | ||
252 | /* called during probe() after chip reset completes */ | |
253 | static int ehci_fsl_setup(struct usb_hcd *hcd) | |
254 | { | |
255 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | |
256 | int retval; | |
257 | ||
258 | /* EHCI registers start at offset 0x100 */ | |
259 | ehci->caps = hcd->regs + 0x100; | |
260 | ehci->regs = hcd->regs + 0x100 + | |
083522d7 | 261 | HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); |
80cb9aee RV |
262 | dbg_hcs_params(ehci, "reset"); |
263 | dbg_hcc_params(ehci, "reset"); | |
264 | ||
265 | /* cache this readonly data; minimize chip reads */ | |
083522d7 | 266 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
80cb9aee RV |
267 | |
268 | retval = ehci_halt(ehci); | |
269 | if (retval) | |
270 | return retval; | |
271 | ||
272 | /* data structure init */ | |
273 | retval = ehci_init(hcd); | |
274 | if (retval) | |
275 | return retval; | |
276 | ||
a8e51775 | 277 | hcd->has_tt = 1; |
80cb9aee RV |
278 | |
279 | ehci->sbrn = 0x20; | |
280 | ||
281 | ehci_reset(ehci); | |
282 | ||
283 | retval = ehci_fsl_reinit(ehci); | |
284 | return retval; | |
285 | } | |
286 | ||
287 | static const struct hc_driver ehci_fsl_hc_driver = { | |
288 | .description = hcd_name, | |
289 | .product_desc = "Freescale On-Chip EHCI Host Controller", | |
290 | .hcd_priv_size = sizeof(struct ehci_hcd), | |
291 | ||
292 | /* | |
293 | * generic hardware linkage | |
294 | */ | |
295 | .irq = ehci_irq, | |
296 | .flags = HCD_USB2, | |
297 | ||
298 | /* | |
299 | * basic lifecycle operations | |
300 | */ | |
301 | .reset = ehci_fsl_setup, | |
302 | .start = ehci_run, | |
80cb9aee | 303 | .stop = ehci_stop, |
64a21d02 | 304 | .shutdown = ehci_shutdown, |
80cb9aee RV |
305 | |
306 | /* | |
307 | * managing i/o requests and associated device resources | |
308 | */ | |
309 | .urb_enqueue = ehci_urb_enqueue, | |
310 | .urb_dequeue = ehci_urb_dequeue, | |
311 | .endpoint_disable = ehci_endpoint_disable, | |
b18ffd49 | 312 | .endpoint_reset = ehci_endpoint_reset, |
80cb9aee RV |
313 | |
314 | /* | |
315 | * scheduling support | |
316 | */ | |
317 | .get_frame_number = ehci_get_frame, | |
318 | ||
319 | /* | |
320 | * root hub support | |
321 | */ | |
322 | .hub_status_data = ehci_hub_status_data, | |
323 | .hub_control = ehci_hub_control, | |
324 | .bus_suspend = ehci_bus_suspend, | |
325 | .bus_resume = ehci_bus_resume, | |
90da096e | 326 | .relinquish_port = ehci_relinquish_port, |
3a31155c | 327 | .port_handed_over = ehci_port_handed_over, |
80cb9aee RV |
328 | }; |
329 | ||
330 | static int ehci_fsl_drv_probe(struct platform_device *pdev) | |
331 | { | |
332 | if (usb_disabled()) | |
333 | return -ENODEV; | |
334 | ||
135db048 | 335 | /* FIXME we only want one one probe() not two */ |
80cb9aee RV |
336 | return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev); |
337 | } | |
338 | ||
339 | static int ehci_fsl_drv_remove(struct platform_device *pdev) | |
340 | { | |
341 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | |
342 | ||
135db048 | 343 | /* FIXME we only want one one remove() not two */ |
80cb9aee | 344 | usb_hcd_fsl_remove(hcd, pdev); |
80cb9aee RV |
345 | return 0; |
346 | } | |
347 | ||
135db048 | 348 | MODULE_ALIAS("platform:fsl-ehci"); |
80cb9aee | 349 | |
01cced25 | 350 | static struct platform_driver ehci_fsl_driver = { |
80cb9aee RV |
351 | .probe = ehci_fsl_drv_probe, |
352 | .remove = ehci_fsl_drv_remove, | |
64a21d02 | 353 | .shutdown = usb_hcd_platform_shutdown, |
80cb9aee | 354 | .driver = { |
01cced25 | 355 | .name = "fsl-ehci", |
135db048 | 356 | }, |
80cb9aee | 357 | }; |