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