Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * OHCI HCD (Host Controller Driver) for USB. |
| 3 | * |
| 4 | * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> |
| 5 | * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> |
| 6 | * (C) Copyright 2002 Hewlett-Packard Company |
| 7 | * (C) Copyright 2003-2005 MontaVista Software Inc. |
| 8 | * |
| 9 | * Bus Glue for PPC On-Chip OHCI driver |
| 10 | * Tested on Freescale MPC5200 and IBM STB04xxx |
| 11 | * |
| 12 | * Modified by Dale Farnsworth <dale@farnsworth.org> from ohci-sa1111.c |
| 13 | * |
| 14 | * This file is licenced under the GPL. |
| 15 | */ |
| 16 | |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Tim Schmielau | de25968 | 2006-01-08 01:02:05 -0800 | [diff] [blame] | 18 | #include <linux/signal.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | /* configure so an HC device and id are always provided */ |
| 21 | /* always called with process context; sleeping is OK */ |
| 22 | |
| 23 | /** |
| 24 | * usb_hcd_ppc_soc_probe - initialize On-Chip HCDs |
| 25 | * Context: !in_interrupt() |
| 26 | * |
Dale Farnsworth | 4fbd55f | 2005-08-10 17:25:25 -0700 | [diff] [blame] | 27 | * Allocates basic resources for this USB host controller. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * |
| 29 | * Store this function in the HCD's struct pci_driver as probe(). |
| 30 | */ |
| 31 | static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver, |
| 32 | struct platform_device *pdev) |
| 33 | { |
| 34 | int retval; |
| 35 | struct usb_hcd *hcd; |
| 36 | struct ohci_hcd *ohci; |
| 37 | struct resource *res; |
| 38 | int irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | pr_debug("initializing PPC-SOC USB Controller\n"); |
| 41 | |
| 42 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 43 | if (!res) { |
| 44 | pr_debug(__FILE__ ": no irq\n"); |
| 45 | return -ENODEV; |
| 46 | } |
| 47 | irq = res->start; |
| 48 | |
| 49 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 50 | if (!res) { |
| 51 | pr_debug(__FILE__ ": no reg addr\n"); |
| 52 | return -ENODEV; |
| 53 | } |
| 54 | |
| 55 | hcd = usb_create_hcd(driver, &pdev->dev, "PPC-SOC USB"); |
| 56 | if (!hcd) |
| 57 | return -ENOMEM; |
| 58 | hcd->rsrc_start = res->start; |
| 59 | hcd->rsrc_len = res->end - res->start + 1; |
| 60 | |
| 61 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 62 | pr_debug(__FILE__ ": request_mem_region failed\n"); |
| 63 | retval = -EBUSY; |
| 64 | goto err1; |
| 65 | } |
| 66 | |
| 67 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 68 | if (!hcd->regs) { |
| 69 | pr_debug(__FILE__ ": ioremap failed\n"); |
| 70 | retval = -ENOMEM; |
| 71 | goto err2; |
| 72 | } |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | ohci = hcd_to_ohci(hcd); |
| 75 | ohci->flags |= OHCI_BIG_ENDIAN; |
| 76 | ohci_hcd_init(ohci); |
| 77 | |
Thomas Gleixner | d54b5ca | 2006-07-01 19:29:44 -0700 | [diff] [blame] | 78 | retval = usb_add_hcd(hcd, irq, IRQF_DISABLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | if (retval == 0) |
| 80 | return retval; |
| 81 | |
| 82 | pr_debug("Removing PPC-SOC USB Controller\n"); |
Dale Farnsworth | 4fbd55f | 2005-08-10 17:25:25 -0700 | [diff] [blame] | 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | iounmap(hcd->regs); |
| 85 | err2: |
| 86 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 87 | err1: |
| 88 | usb_put_hcd(hcd); |
| 89 | return retval; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | /* may be called without controller electrically present */ |
| 94 | /* may be called with controller, bus, and devices active */ |
| 95 | |
| 96 | /** |
| 97 | * usb_hcd_ppc_soc_remove - shutdown processing for On-Chip HCDs |
| 98 | * @pdev: USB Host Controller being removed |
| 99 | * Context: !in_interrupt() |
| 100 | * |
Dale Farnsworth | 4fbd55f | 2005-08-10 17:25:25 -0700 | [diff] [blame] | 101 | * Reverses the effect of usb_hcd_ppc_soc_probe(). |
| 102 | * It is always called from a thread |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | * context, normally "rmmod", "apmd", or something similar. |
| 104 | * |
| 105 | */ |
| 106 | static void usb_hcd_ppc_soc_remove(struct usb_hcd *hcd, |
| 107 | struct platform_device *pdev) |
| 108 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | usb_remove_hcd(hcd); |
| 110 | |
| 111 | pr_debug("stopping PPC-SOC USB Controller\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | iounmap(hcd->regs); |
| 114 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
Dale Farnsworth | e52b1d3 | 2005-08-09 12:13:35 -0700 | [diff] [blame] | 115 | usb_put_hcd(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static int __devinit |
| 119 | ohci_ppc_soc_start(struct usb_hcd *hcd) |
| 120 | { |
| 121 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 122 | int ret; |
| 123 | |
| 124 | if ((ret = ohci_init(ohci)) < 0) |
| 125 | return ret; |
| 126 | |
| 127 | if ((ret = ohci_run(ohci)) < 0) { |
| 128 | err("can't start %s", ohci_to_hcd(ohci)->self.bus_name); |
| 129 | ohci_stop(hcd); |
| 130 | return ret; |
| 131 | } |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static const struct hc_driver ohci_ppc_soc_hc_driver = { |
| 137 | .description = hcd_name, |
| 138 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 139 | |
| 140 | /* |
| 141 | * generic hardware linkage |
| 142 | */ |
| 143 | .irq = ohci_irq, |
| 144 | .flags = HCD_USB11 | HCD_MEMORY, |
| 145 | |
| 146 | /* |
| 147 | * basic lifecycle operations |
| 148 | */ |
| 149 | .start = ohci_ppc_soc_start, |
| 150 | .stop = ohci_stop, |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 151 | .shutdown = ohci_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * managing i/o requests and associated device resources |
| 155 | */ |
| 156 | .urb_enqueue = ohci_urb_enqueue, |
| 157 | .urb_dequeue = ohci_urb_dequeue, |
| 158 | .endpoint_disable = ohci_endpoint_disable, |
| 159 | |
| 160 | /* |
| 161 | * scheduling support |
| 162 | */ |
| 163 | .get_frame_number = ohci_get_frame, |
| 164 | |
| 165 | /* |
| 166 | * root hub support |
| 167 | */ |
| 168 | .hub_status_data = ohci_hub_status_data, |
| 169 | .hub_control = ohci_hub_control, |
David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 170 | .hub_irq_enable = ohci_rhsc_enable, |
David Brownell | 8ad7fe1 | 2005-09-13 19:59:11 -0700 | [diff] [blame] | 171 | #ifdef CONFIG_PM |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 172 | .bus_suspend = ohci_bus_suspend, |
| 173 | .bus_resume = ohci_bus_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | #endif |
| 175 | .start_port_reset = ohci_start_port_reset, |
| 176 | }; |
| 177 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 178 | static int ohci_hcd_ppc_soc_drv_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | int ret; |
| 181 | |
| 182 | if (usb_disabled()) |
| 183 | return -ENODEV; |
| 184 | |
| 185 | ret = usb_hcd_ppc_soc_probe(&ohci_ppc_soc_hc_driver, pdev); |
| 186 | return ret; |
| 187 | } |
| 188 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 189 | static int ohci_hcd_ppc_soc_drv_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
Andrey Volkov | 2463ade | 2005-11-18 01:10:48 -0800 | [diff] [blame] | 191 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | usb_hcd_ppc_soc_remove(hcd, pdev); |
| 194 | return 0; |
| 195 | } |
| 196 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 197 | static struct platform_driver ohci_hcd_ppc_soc_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | .probe = ohci_hcd_ppc_soc_drv_probe, |
| 199 | .remove = ohci_hcd_ppc_soc_drv_remove, |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 200 | .shutdown = usb_hcd_platform_shutdown, |
David Brownell | 8ad7fe1 | 2005-09-13 19:59:11 -0700 | [diff] [blame] | 201 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/ |
| 203 | /*.resume = ohci_hcd_ppc_soc_drv_resume,*/ |
| 204 | #endif |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 205 | .driver = { |
| 206 | .name = "ppc-soc-ohci", |
| 207 | .owner = THIS_MODULE, |
| 208 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | static int __init ohci_hcd_ppc_soc_init(void) |
| 212 | { |
| 213 | pr_debug(DRIVER_INFO " (PPC SOC)\n"); |
| 214 | pr_debug("block sizes: ed %d td %d\n", sizeof(struct ed), |
| 215 | sizeof(struct td)); |
| 216 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 217 | return platform_driver_register(&ohci_hcd_ppc_soc_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static void __exit ohci_hcd_ppc_soc_cleanup(void) |
| 221 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 222 | platform_driver_unregister(&ohci_hcd_ppc_soc_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | module_init(ohci_hcd_ppc_soc_init); |
| 226 | module_exit(ohci_hcd_ppc_soc_cleanup); |