blob: 593a7e76cffa94327bf0cf6ab0893649e55439e0 [file] [log] [blame]
Randy Vinson80cb9ae2006-01-20 13:53:38 -08001/*
Randy Vinson80cb9ae2006-01-20 13:53:38 -08002 * 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
Joe Perchesdc0d5c12007-12-17 11:40:18 -080027/* FIXME: Power Management is un-ported so temporarily disable it */
Randy Vinson80cb9ae2006-01-20 13:53:38 -080028#undef CONFIG_PM
29
Randy Vinson80cb9ae2006-01-20 13:53:38 -080030
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 */
Anton Vorontsovdad38432009-12-14 18:41:05 +030043static int usb_hcd_fsl_probe(const struct hc_driver *driver,
44 struct platform_device *pdev)
Randy Vinson80cb9ae2006-01-20 13:53:38 -080045{
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,
Kay Sievers7071a3c2008-05-02 06:02:41 +020059 "No platform data for %s.\n", dev_name(&pdev->dev));
Randy Vinson80cb9ae2006-01-20 13:53:38 -080060 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) ||
Li Yangba029782007-05-11 17:09:55 +080068 (pdata->operating_mode == FSL_USB2_MPH_HOST) ||
69 (pdata->operating_mode == FSL_USB2_DR_OTG))) {
Randy Vinson80cb9ae2006-01-20 13:53:38 -080070 dev_err(&pdev->dev,
71 "Non Host Mode configured for %s. Wrong driver linked.\n",
Kay Sievers7071a3c2008-05-02 06:02:41 +020072 dev_name(&pdev->dev));
Randy Vinson80cb9ae2006-01-20 13:53:38 -080073 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",
Kay Sievers7071a3c2008-05-02 06:02:41 +020080 dev_name(&pdev->dev));
Randy Vinson80cb9ae2006-01-20 13:53:38 -080081 return -ENODEV;
82 }
83 irq = res->start;
84
Kay Sievers7071a3c2008-05-02 06:02:41 +020085 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
Randy Vinson80cb9ae2006-01-20 13:53:38 -080086 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",
Kay Sievers7071a3c2008-05-02 06:02:41 +020095 dev_name(&pdev->dev));
Randy Vinson80cb9ae2006-01-20 13:53:38 -080096 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
Alan Stern442258e2007-12-06 14:47:08 -0500123 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800124 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:
Kay Sievers7071a3c2008-05-02 06:02:41 +0200135 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800136 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 */
Anton Vorontsovdad38432009-12-14 18:41:05 +0300150static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
151 struct platform_device *pdev)
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800152{
153 usb_remove_hcd(hcd);
154 iounmap(hcd->regs);
155 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
156 usb_put_hcd(hcd);
157}
158
159static void mpc83xx_setup_phy(struct ehci_hcd *ehci,
160 enum fsl_usb2_phy_modes phy_mode,
161 unsigned int port_offset)
162{
Kumar Gala499003e82006-01-24 08:11:27 -0800163 u32 portsc = 0;
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800164 switch (phy_mode) {
165 case FSL_USB2_PHY_ULPI:
166 portsc |= PORT_PTS_ULPI;
167 break;
168 case FSL_USB2_PHY_SERIAL:
169 portsc |= PORT_PTS_SERIAL;
170 break;
171 case FSL_USB2_PHY_UTMI_WIDE:
172 portsc |= PORT_PTS_PTW;
173 /* fall through */
174 case FSL_USB2_PHY_UTMI:
175 portsc |= PORT_PTS_UTMI;
176 break;
177 case FSL_USB2_PHY_NONE:
178 break;
179 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100180 ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]);
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800181}
182
183static void mpc83xx_usb_setup(struct usb_hcd *hcd)
184{
185 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
186 struct fsl_usb2_platform_data *pdata;
187 void __iomem *non_ehci = hcd->regs;
Li Yangba029782007-05-11 17:09:55 +0800188 u32 temp;
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800189
190 pdata =
191 (struct fsl_usb2_platform_data *)hcd->self.controller->
192 platform_data;
193 /* Enable PHY interface in the control reg. */
Li Yangba029782007-05-11 17:09:55 +0800194 temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
195 out_be32(non_ehci + FSL_SOC_USB_CTRL, temp | 0x00000004);
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800196 out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b);
197
Li Yang40acc092007-05-23 13:58:17 -0700198#if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
199 /*
200 * Turn on cache snooping hardware, since some PowerPC platforms
201 * wholly rely on hardware to deal with cache coherent
202 */
203
204 /* Setup Snooping for all the 4GB space */
205 /* SNOOP1 starts from 0x0, size 2G */
206 out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0 | SNOOP_SIZE_2GB);
207 /* SNOOP2 starts from 0x80000000, size 2G */
208 out_be32(non_ehci + FSL_SOC_USB_SNOOP2, 0x80000000 | SNOOP_SIZE_2GB);
209#endif
210
Li Yangba029782007-05-11 17:09:55 +0800211 if ((pdata->operating_mode == FSL_USB2_DR_HOST) ||
212 (pdata->operating_mode == FSL_USB2_DR_OTG))
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800213 mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
214
215 if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
Kumar Gala8cd42e92006-01-20 13:57:52 -0800216 unsigned int chip, rev, svr;
217
218 svr = mfspr(SPRN_SVR);
219 chip = svr >> 16;
220 rev = (svr >> 4) & 0xf;
221
222 /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
223 if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
224 ehci->has_fsl_port_bug = 1;
225
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800226 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
227 mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
228 if (pdata->port_enables & FSL_USB2_PORT1_ENABLED)
229 mpc83xx_setup_phy(ehci, pdata->phy_mode, 1);
230 }
231
232 /* put controller in host mode. */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100233 ehci_writel(ehci, 0x00000003, non_ehci + FSL_SOC_USB_USBMODE);
Srikanth Srinivasan4f534252008-07-02 02:14:33 -0500234#ifdef CONFIG_PPC_85xx
235 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x00000008);
236 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000080);
237#else
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800238 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c);
239 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040);
Srikanth Srinivasan4f534252008-07-02 02:14:33 -0500240#endif
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800241 out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001);
242}
243
244/* called after powerup, by probe or system-pm "wakeup" */
245static int ehci_fsl_reinit(struct ehci_hcd *ehci)
246{
247 mpc83xx_usb_setup(ehci_to_hcd(ehci));
248 ehci_port_power(ehci, 0);
249
250 return 0;
251}
252
253/* called during probe() after chip reset completes */
254static int ehci_fsl_setup(struct usb_hcd *hcd)
255{
256 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
257 int retval;
258
259 /* EHCI registers start at offset 0x100 */
260 ehci->caps = hcd->regs + 0x100;
261 ehci->regs = hcd->regs + 0x100 +
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100262 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800263 dbg_hcs_params(ehci, "reset");
264 dbg_hcc_params(ehci, "reset");
265
266 /* cache this readonly data; minimize chip reads */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100267 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800268
269 retval = ehci_halt(ehci);
270 if (retval)
271 return retval;
272
273 /* data structure init */
274 retval = ehci_init(hcd);
275 if (retval)
276 return retval;
277
Alan Sterna8e51772008-05-20 16:58:11 -0400278 hcd->has_tt = 1;
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800279
280 ehci->sbrn = 0x20;
281
282 ehci_reset(ehci);
283
284 retval = ehci_fsl_reinit(ehci);
285 return retval;
286}
287
288static const struct hc_driver ehci_fsl_hc_driver = {
289 .description = hcd_name,
290 .product_desc = "Freescale On-Chip EHCI Host Controller",
291 .hcd_priv_size = sizeof(struct ehci_hcd),
292
293 /*
294 * generic hardware linkage
295 */
296 .irq = ehci_irq,
297 .flags = HCD_USB2,
298
299 /*
300 * basic lifecycle operations
301 */
302 .reset = ehci_fsl_setup,
303 .start = ehci_run,
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800304 .stop = ehci_stop,
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700305 .shutdown = ehci_shutdown,
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800306
307 /*
308 * managing i/o requests and associated device resources
309 */
310 .urb_enqueue = ehci_urb_enqueue,
311 .urb_dequeue = ehci_urb_dequeue,
312 .endpoint_disable = ehci_endpoint_disable,
Alan Sternb18ffd42009-05-27 18:21:56 -0400313 .endpoint_reset = ehci_endpoint_reset,
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800314
315 /*
316 * scheduling support
317 */
318 .get_frame_number = ehci_get_frame,
319
320 /*
321 * root hub support
322 */
323 .hub_status_data = ehci_hub_status_data,
324 .hub_control = ehci_hub_control,
325 .bus_suspend = ehci_bus_suspend,
326 .bus_resume = ehci_bus_resume,
Balaji Rao90da0962007-11-22 01:58:14 +0530327 .relinquish_port = ehci_relinquish_port,
Alan Stern3a311552008-05-20 16:58:29 -0400328 .port_handed_over = ehci_port_handed_over,
Alan Stern914b7012009-06-29 10:47:30 -0400329
330 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800331};
332
333static int ehci_fsl_drv_probe(struct platform_device *pdev)
334{
335 if (usb_disabled())
336 return -ENODEV;
337
David Brownell135db042008-02-11 18:40:46 -0800338 /* FIXME we only want one one probe() not two */
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800339 return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev);
340}
341
342static int ehci_fsl_drv_remove(struct platform_device *pdev)
343{
344 struct usb_hcd *hcd = platform_get_drvdata(pdev);
345
David Brownell135db042008-02-11 18:40:46 -0800346 /* FIXME we only want one one remove() not two */
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800347 usb_hcd_fsl_remove(hcd, pdev);
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800348 return 0;
349}
350
David Brownell135db042008-02-11 18:40:46 -0800351MODULE_ALIAS("platform:fsl-ehci");
Kumar Gala01cced22006-04-11 10:07:16 -0500352
353static struct platform_driver ehci_fsl_driver = {
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800354 .probe = ehci_fsl_drv_probe,
355 .remove = ehci_fsl_drv_remove,
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700356 .shutdown = usb_hcd_platform_shutdown,
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800357 .driver = {
Kumar Gala01cced22006-04-11 10:07:16 -0500358 .name = "fsl-ehci",
David Brownell135db042008-02-11 18:40:46 -0800359 },
Randy Vinson80cb9ae2006-01-20 13:53:38 -0800360};