Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for EHCI UHP on Atmel chips |
| 3 | * |
| 4 | * Copyright (C) 2009 Atmel Corporation, |
| 5 | * Nicolas Ferre <nicolas.ferre@atmel.com> |
| 6 | * |
| 7 | * Based on various ehci-*.c drivers |
| 8 | * |
| 9 | * This file is subject to the terms and conditions of the GNU General Public |
| 10 | * License. See the file COPYING in the main directory of this archive for |
| 11 | * more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/clk.h> |
| 15 | #include <linux/platform_device.h> |
Nicolas Ferre | 9475375 | 2012-03-27 18:23:31 +0200 | [diff] [blame] | 16 | #include <linux/of.h> |
Jean-Christophe PLAGNIOL-VILLARD | 9d84300 | 2011-11-22 12:11:13 +0800 | [diff] [blame] | 17 | #include <linux/of_platform.h> |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 18 | |
| 19 | /* interface and function clocks */ |
| 20 | static struct clk *iclk, *fclk; |
| 21 | static int clocked; |
| 22 | |
| 23 | /*-------------------------------------------------------------------------*/ |
| 24 | |
| 25 | static void atmel_start_clock(void) |
| 26 | { |
| 27 | clk_enable(iclk); |
| 28 | clk_enable(fclk); |
| 29 | clocked = 1; |
| 30 | } |
| 31 | |
| 32 | static void atmel_stop_clock(void) |
| 33 | { |
| 34 | clk_disable(fclk); |
| 35 | clk_disable(iclk); |
| 36 | clocked = 0; |
| 37 | } |
| 38 | |
| 39 | static void atmel_start_ehci(struct platform_device *pdev) |
| 40 | { |
| 41 | dev_dbg(&pdev->dev, "start\n"); |
| 42 | atmel_start_clock(); |
| 43 | } |
| 44 | |
| 45 | static void atmel_stop_ehci(struct platform_device *pdev) |
| 46 | { |
| 47 | dev_dbg(&pdev->dev, "stop\n"); |
| 48 | atmel_stop_clock(); |
| 49 | } |
| 50 | |
| 51 | /*-------------------------------------------------------------------------*/ |
| 52 | |
| 53 | static int ehci_atmel_setup(struct usb_hcd *hcd) |
| 54 | { |
| 55 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 56 | |
| 57 | /* registers start at offset 0x0 */ |
| 58 | ehci->caps = hcd->regs; |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 59 | |
Alan Stern | c73cee7 | 2012-10-31 13:21:06 -0400 | [diff] [blame] | 60 | return ehci_setup(hcd); |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static const struct hc_driver ehci_atmel_hc_driver = { |
| 64 | .description = hcd_name, |
| 65 | .product_desc = "Atmel EHCI UHP HS", |
| 66 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 67 | |
| 68 | /* generic hardware linkage */ |
| 69 | .irq = ehci_irq, |
| 70 | .flags = HCD_MEMORY | HCD_USB2, |
| 71 | |
| 72 | /* basic lifecycle operations */ |
| 73 | .reset = ehci_atmel_setup, |
| 74 | .start = ehci_run, |
| 75 | .stop = ehci_stop, |
| 76 | .shutdown = ehci_shutdown, |
| 77 | |
| 78 | /* managing i/o requests and associated device resources */ |
| 79 | .urb_enqueue = ehci_urb_enqueue, |
| 80 | .urb_dequeue = ehci_urb_dequeue, |
| 81 | .endpoint_disable = ehci_endpoint_disable, |
Paul Mundt | b48d7f5 | 2010-11-30 17:57:02 +0900 | [diff] [blame] | 82 | .endpoint_reset = ehci_endpoint_reset, |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 83 | |
| 84 | /* scheduling support */ |
| 85 | .get_frame_number = ehci_get_frame, |
| 86 | |
| 87 | /* root hub support */ |
| 88 | .hub_status_data = ehci_hub_status_data, |
| 89 | .hub_control = ehci_hub_control, |
| 90 | .bus_suspend = ehci_bus_suspend, |
| 91 | .bus_resume = ehci_bus_resume, |
| 92 | .relinquish_port = ehci_relinquish_port, |
| 93 | .port_handed_over = ehci_port_handed_over, |
Paul Mundt | b48d7f5 | 2010-11-30 17:57:02 +0900 | [diff] [blame] | 94 | |
| 95 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
Jean-Christophe PLAGNIOL-VILLARD | 9d84300 | 2011-11-22 12:11:13 +0800 | [diff] [blame] | 98 | static u64 at91_ehci_dma_mask = DMA_BIT_MASK(32); |
| 99 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 100 | static int ehci_atmel_drv_probe(struct platform_device *pdev) |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 101 | { |
| 102 | struct usb_hcd *hcd; |
| 103 | const struct hc_driver *driver = &ehci_atmel_hc_driver; |
| 104 | struct resource *res; |
| 105 | int irq; |
| 106 | int retval; |
| 107 | |
| 108 | if (usb_disabled()) |
| 109 | return -ENODEV; |
| 110 | |
| 111 | pr_debug("Initializing Atmel-SoC USB Host Controller\n"); |
| 112 | |
| 113 | irq = platform_get_irq(pdev, 0); |
| 114 | if (irq <= 0) { |
| 115 | dev_err(&pdev->dev, |
| 116 | "Found HC with no IRQ. Check %s setup!\n", |
| 117 | dev_name(&pdev->dev)); |
| 118 | retval = -ENODEV; |
| 119 | goto fail_create_hcd; |
| 120 | } |
| 121 | |
Jean-Christophe PLAGNIOL-VILLARD | 9d84300 | 2011-11-22 12:11:13 +0800 | [diff] [blame] | 122 | /* Right now device-tree probed devices don't get dma_mask set. |
| 123 | * Since shared usb code relies on it, set it here for now. |
| 124 | * Once we have dma capability bindings this can go away. |
| 125 | */ |
| 126 | if (!pdev->dev.dma_mask) |
| 127 | pdev->dev.dma_mask = &at91_ehci_dma_mask; |
| 128 | |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 129 | hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); |
| 130 | if (!hcd) { |
| 131 | retval = -ENOMEM; |
| 132 | goto fail_create_hcd; |
| 133 | } |
| 134 | |
| 135 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 136 | if (!res) { |
| 137 | dev_err(&pdev->dev, |
| 138 | "Found HC with no register addr. Check %s setup!\n", |
| 139 | dev_name(&pdev->dev)); |
| 140 | retval = -ENODEV; |
| 141 | goto fail_request_resource; |
| 142 | } |
| 143 | hcd->rsrc_start = res->start; |
H Hartley Sweeten | f65c354 | 2009-12-14 18:15:35 -0500 | [diff] [blame] | 144 | hcd->rsrc_len = resource_size(res); |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 145 | |
Julia Lawall | 9798343 | 2012-07-29 21:46:05 +0200 | [diff] [blame] | 146 | hcd->regs = devm_request_and_ioremap(&pdev->dev, res); |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 147 | if (hcd->regs == NULL) { |
| 148 | dev_dbg(&pdev->dev, "error mapping memory\n"); |
| 149 | retval = -EFAULT; |
Julia Lawall | 9798343 | 2012-07-29 21:46:05 +0200 | [diff] [blame] | 150 | goto fail_request_resource; |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Julia Lawall | 9798343 | 2012-07-29 21:46:05 +0200 | [diff] [blame] | 153 | iclk = devm_clk_get(&pdev->dev, "ehci_clk"); |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 154 | if (IS_ERR(iclk)) { |
| 155 | dev_err(&pdev->dev, "Error getting interface clock\n"); |
| 156 | retval = -ENOENT; |
Julia Lawall | 9798343 | 2012-07-29 21:46:05 +0200 | [diff] [blame] | 157 | goto fail_request_resource; |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 158 | } |
Julia Lawall | 9798343 | 2012-07-29 21:46:05 +0200 | [diff] [blame] | 159 | fclk = devm_clk_get(&pdev->dev, "uhpck"); |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 160 | if (IS_ERR(fclk)) { |
| 161 | dev_err(&pdev->dev, "Error getting function clock\n"); |
| 162 | retval = -ENOENT; |
Julia Lawall | 9798343 | 2012-07-29 21:46:05 +0200 | [diff] [blame] | 163 | goto fail_request_resource; |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | atmel_start_ehci(pdev); |
| 167 | |
| 168 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 169 | if (retval) |
| 170 | goto fail_add_hcd; |
| 171 | |
| 172 | return retval; |
| 173 | |
| 174 | fail_add_hcd: |
| 175 | atmel_stop_ehci(pdev); |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 176 | fail_request_resource: |
| 177 | usb_put_hcd(hcd); |
| 178 | fail_create_hcd: |
| 179 | dev_err(&pdev->dev, "init %s fail, %d\n", |
| 180 | dev_name(&pdev->dev), retval); |
| 181 | |
| 182 | return retval; |
| 183 | } |
| 184 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 185 | static int ehci_atmel_drv_remove(struct platform_device *pdev) |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 186 | { |
| 187 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 188 | |
| 189 | ehci_shutdown(hcd); |
| 190 | usb_remove_hcd(hcd); |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 191 | usb_put_hcd(hcd); |
| 192 | |
| 193 | atmel_stop_ehci(pdev); |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 194 | fclk = iclk = NULL; |
| 195 | |
| 196 | return 0; |
| 197 | } |
| 198 | |
Jean-Christophe PLAGNIOL-VILLARD | 9d84300 | 2011-11-22 12:11:13 +0800 | [diff] [blame] | 199 | #ifdef CONFIG_OF |
| 200 | static const struct of_device_id atmel_ehci_dt_ids[] = { |
| 201 | { .compatible = "atmel,at91sam9g45-ehci" }, |
| 202 | { /* sentinel */ } |
| 203 | }; |
| 204 | |
| 205 | MODULE_DEVICE_TABLE(of, atmel_ehci_dt_ids); |
| 206 | #endif |
| 207 | |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 208 | static struct platform_driver ehci_atmel_driver = { |
| 209 | .probe = ehci_atmel_drv_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 210 | .remove = ehci_atmel_drv_remove, |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 211 | .shutdown = usb_hcd_platform_shutdown, |
Jean-Christophe PLAGNIOL-VILLARD | 9d84300 | 2011-11-22 12:11:13 +0800 | [diff] [blame] | 212 | .driver = { |
| 213 | .name = "atmel-ehci", |
| 214 | .of_match_table = of_match_ptr(atmel_ehci_dt_ids), |
| 215 | }, |
Nicolas Ferre | 501c9c0 | 2009-07-27 14:47:40 -0700 | [diff] [blame] | 216 | }; |