Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [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 | * |
| 8 | * Bus Glue for ep93xx. |
| 9 | * |
| 10 | * Written by Christopher Hoover <ch@hpl.hp.com> |
| 11 | * Based on fragments of previous driver by Russell King et al. |
| 12 | * |
| 13 | * Modified for LH7A404 from ohci-sa1111.c |
| 14 | * by Durgesh Pattamatta <pattamattad@sharpsec.com> |
| 15 | * |
| 16 | * Modified for pxa27x from ohci-lh7a404.c |
| 17 | * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004 |
| 18 | * |
| 19 | * Modified for ep93xx from ohci-pxa27x.c |
| 20 | * by Lennert Buytenhek <buytenh@wantstofly.org> 28-2-2006 |
| 21 | * Based on an earlier driver by Ray Lehtiniemi |
| 22 | * |
| 23 | * This file is licenced under the GPL. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/clk.h> |
| 27 | #include <linux/device.h> |
| 28 | #include <linux/signal.h> |
| 29 | #include <linux/platform_device.h> |
| 30 | |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 31 | static struct clk *usb_host_clock; |
| 32 | |
| 33 | static void ep93xx_start_hc(struct device *dev) |
| 34 | { |
| 35 | clk_enable(usb_host_clock); |
| 36 | } |
| 37 | |
| 38 | static void ep93xx_stop_hc(struct device *dev) |
| 39 | { |
| 40 | clk_disable(usb_host_clock); |
| 41 | } |
| 42 | |
| 43 | static int usb_hcd_ep93xx_probe(const struct hc_driver *driver, |
| 44 | struct platform_device *pdev) |
| 45 | { |
| 46 | int retval; |
| 47 | struct usb_hcd *hcd; |
| 48 | |
| 49 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { |
Greg Kroah-Hartman | 1f550c1 | 2012-05-01 21:33:38 -0700 | [diff] [blame] | 50 | dev_dbg(&pdev->dev, "resource[1] is not IORESOURCE_IRQ\n"); |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 51 | return -ENOMEM; |
| 52 | } |
| 53 | |
| 54 | hcd = usb_create_hcd(driver, &pdev->dev, "ep93xx"); |
| 55 | if (hcd == NULL) |
| 56 | return -ENOMEM; |
| 57 | |
| 58 | hcd->rsrc_start = pdev->resource[0].start; |
| 59 | hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; |
| 60 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 61 | usb_put_hcd(hcd); |
| 62 | retval = -EBUSY; |
| 63 | goto err1; |
| 64 | } |
| 65 | |
| 66 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 67 | if (hcd->regs == NULL) { |
Greg Kroah-Hartman | 1f550c1 | 2012-05-01 21:33:38 -0700 | [diff] [blame] | 68 | dev_dbg(&pdev->dev, "ioremap failed\n"); |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 69 | retval = -ENOMEM; |
| 70 | goto err2; |
| 71 | } |
| 72 | |
Hartley Sweeten | e3a6d01 | 2009-05-28 19:56:11 +0100 | [diff] [blame] | 73 | usb_host_clock = clk_get(&pdev->dev, NULL); |
| 74 | if (IS_ERR(usb_host_clock)) { |
Greg Kroah-Hartman | 1f550c1 | 2012-05-01 21:33:38 -0700 | [diff] [blame] | 75 | dev_dbg(&pdev->dev, "clk_get failed\n"); |
Hartley Sweeten | e3a6d01 | 2009-05-28 19:56:11 +0100 | [diff] [blame] | 76 | retval = PTR_ERR(usb_host_clock); |
| 77 | goto err3; |
| 78 | } |
| 79 | |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 80 | ep93xx_start_hc(&pdev->dev); |
| 81 | |
| 82 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 83 | |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 84 | retval = usb_add_hcd(hcd, pdev->resource[1].start, 0); |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 85 | if (retval == 0) |
| 86 | return retval; |
| 87 | |
| 88 | ep93xx_stop_hc(&pdev->dev); |
Hartley Sweeten | e3a6d01 | 2009-05-28 19:56:11 +0100 | [diff] [blame] | 89 | err3: |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 90 | iounmap(hcd->regs); |
| 91 | err2: |
| 92 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 93 | err1: |
| 94 | usb_put_hcd(hcd); |
| 95 | |
| 96 | return retval; |
| 97 | } |
| 98 | |
| 99 | static void usb_hcd_ep93xx_remove(struct usb_hcd *hcd, |
| 100 | struct platform_device *pdev) |
| 101 | { |
| 102 | usb_remove_hcd(hcd); |
| 103 | ep93xx_stop_hc(&pdev->dev); |
| 104 | clk_put(usb_host_clock); |
| 105 | iounmap(hcd->regs); |
| 106 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 107 | usb_put_hcd(hcd); |
| 108 | } |
| 109 | |
| 110 | static int __devinit ohci_ep93xx_start(struct usb_hcd *hcd) |
| 111 | { |
| 112 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| 113 | int ret; |
| 114 | |
| 115 | if ((ret = ohci_init(ohci)) < 0) |
| 116 | return ret; |
| 117 | |
| 118 | if ((ret = ohci_run(ohci)) < 0) { |
Greg Kroah-Hartman | 8d6c85e | 2012-04-27 11:24:40 -0700 | [diff] [blame] | 119 | dev_err(hcd->self.controller, "can't start %s\n", |
| 120 | hcd->self.bus_name); |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 121 | ohci_stop(hcd); |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static struct hc_driver ohci_ep93xx_hc_driver = { |
| 129 | .description = hcd_name, |
| 130 | .product_desc = "EP93xx OHCI", |
| 131 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 132 | .irq = ohci_irq, |
| 133 | .flags = HCD_USB11 | HCD_MEMORY, |
| 134 | .start = ohci_ep93xx_start, |
| 135 | .stop = ohci_stop, |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 136 | .shutdown = ohci_shutdown, |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 137 | .urb_enqueue = ohci_urb_enqueue, |
| 138 | .urb_dequeue = ohci_urb_dequeue, |
| 139 | .endpoint_disable = ohci_endpoint_disable, |
| 140 | .get_frame_number = ohci_get_frame, |
| 141 | .hub_status_data = ohci_hub_status_data, |
| 142 | .hub_control = ohci_hub_control, |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 143 | #ifdef CONFIG_PM |
| 144 | .bus_suspend = ohci_bus_suspend, |
| 145 | .bus_resume = ohci_bus_resume, |
| 146 | #endif |
| 147 | .start_port_reset = ohci_start_port_reset, |
| 148 | }; |
| 149 | |
| 150 | extern int usb_disabled(void); |
| 151 | |
| 152 | static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev) |
| 153 | { |
| 154 | int ret; |
| 155 | |
| 156 | ret = -ENODEV; |
| 157 | if (!usb_disabled()) |
| 158 | ret = usb_hcd_ep93xx_probe(&ohci_ep93xx_hc_driver, pdev); |
| 159 | |
| 160 | return ret; |
| 161 | } |
| 162 | |
| 163 | static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev) |
| 164 | { |
| 165 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 166 | |
| 167 | usb_hcd_ep93xx_remove(hcd, pdev); |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | #ifdef CONFIG_PM |
| 173 | static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state) |
| 174 | { |
| 175 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Petr Stetiar | caaf263 | 2007-01-17 06:30:39 -0800 | [diff] [blame] | 176 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 177 | |
| 178 | if (time_before(jiffies, ohci->next_statechange)) |
| 179 | msleep(5); |
| 180 | ohci->next_statechange = jiffies; |
| 181 | |
| 182 | ep93xx_stop_hc(&pdev->dev); |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev) |
| 187 | { |
| 188 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 189 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 190 | |
| 191 | if (time_before(jiffies, ohci->next_statechange)) |
| 192 | msleep(5); |
| 193 | ohci->next_statechange = jiffies; |
| 194 | |
| 195 | ep93xx_start_hc(&pdev->dev); |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 196 | |
Alan Stern | 43bbb7e | 2008-04-03 18:03:17 -0400 | [diff] [blame] | 197 | ohci_finish_controller_resume(hcd); |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | #endif |
| 201 | |
| 202 | |
| 203 | static struct platform_driver ohci_hcd_ep93xx_driver = { |
| 204 | .probe = ohci_hcd_ep93xx_drv_probe, |
| 205 | .remove = ohci_hcd_ep93xx_drv_remove, |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 206 | .shutdown = usb_hcd_platform_shutdown, |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 207 | #ifdef CONFIG_PM |
| 208 | .suspend = ohci_hcd_ep93xx_drv_suspend, |
| 209 | .resume = ohci_hcd_ep93xx_drv_resume, |
| 210 | #endif |
| 211 | .driver = { |
| 212 | .name = "ep93xx-ohci", |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 213 | .owner = THIS_MODULE, |
Lennert Buytenhek | a5b7474 | 2006-06-23 23:02:01 +0200 | [diff] [blame] | 214 | }, |
| 215 | }; |
| 216 | |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 217 | MODULE_ALIAS("platform:ep93xx-ohci"); |