Gabor Juhos | 502fa84 | 2011-04-13 10:54:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Bus Glue for Atheros AR7XXX/AR9XXX built-in EHCI controller. |
| 3 | * |
| 4 | * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org> |
| 5 | * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org> |
| 6 | * |
| 7 | * Parts of this file are based on Atheros' 2.6.15 BSP |
| 8 | * Copyright (C) 2007 Atheros Communications, Inc. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License version 2 as published |
| 12 | * by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/platform_device.h> |
| 16 | |
| 17 | enum { |
| 18 | EHCI_ATH79_IP_V1 = 0, |
| 19 | EHCI_ATH79_IP_V2, |
| 20 | }; |
| 21 | |
| 22 | static const struct platform_device_id ehci_ath79_id_table[] = { |
| 23 | { |
| 24 | .name = "ar71xx-ehci", |
| 25 | .driver_data = EHCI_ATH79_IP_V1, |
| 26 | }, |
| 27 | { |
| 28 | .name = "ar724x-ehci", |
| 29 | .driver_data = EHCI_ATH79_IP_V2, |
| 30 | }, |
| 31 | { |
| 32 | .name = "ar913x-ehci", |
| 33 | .driver_data = EHCI_ATH79_IP_V2, |
| 34 | }, |
| 35 | { |
| 36 | /* terminating entry */ |
| 37 | }, |
| 38 | }; |
| 39 | |
| 40 | MODULE_DEVICE_TABLE(platform, ehci_ath79_id_table); |
| 41 | |
| 42 | static int ehci_ath79_init(struct usb_hcd *hcd) |
| 43 | { |
| 44 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 45 | struct platform_device *pdev = to_platform_device(hcd->self.controller); |
| 46 | const struct platform_device_id *id; |
| 47 | int ret; |
| 48 | |
| 49 | id = platform_get_device_id(pdev); |
| 50 | if (!id) { |
| 51 | dev_err(hcd->self.controller, "missing device id\n"); |
| 52 | return -EINVAL; |
| 53 | } |
| 54 | |
| 55 | switch (id->driver_data) { |
| 56 | case EHCI_ATH79_IP_V1: |
Gabor Juhos | 2f7ac6c | 2011-04-13 10:54:23 +0200 | [diff] [blame] | 57 | ehci->has_synopsys_hc_bug = 1; |
| 58 | |
Gabor Juhos | 502fa84 | 2011-04-13 10:54:22 +0200 | [diff] [blame] | 59 | ehci->caps = hcd->regs; |
Gabor Juhos | c27d536 | 2011-06-20 17:22:36 +0200 | [diff] [blame] | 60 | ehci->regs = hcd->regs + |
| 61 | HC_LENGTH(ehci, |
| 62 | ehci_readl(ehci, &ehci->caps->hc_capbase)); |
Gabor Juhos | 502fa84 | 2011-04-13 10:54:22 +0200 | [diff] [blame] | 63 | break; |
| 64 | |
| 65 | case EHCI_ATH79_IP_V2: |
| 66 | hcd->has_tt = 1; |
| 67 | |
| 68 | ehci->caps = hcd->regs + 0x100; |
Gabor Juhos | c27d536 | 2011-06-20 17:22:36 +0200 | [diff] [blame] | 69 | ehci->regs = hcd->regs + 0x100 + |
| 70 | HC_LENGTH(ehci, |
| 71 | ehci_readl(ehci, &ehci->caps->hc_capbase)); |
Gabor Juhos | 502fa84 | 2011-04-13 10:54:22 +0200 | [diff] [blame] | 72 | break; |
| 73 | |
| 74 | default: |
| 75 | BUG(); |
| 76 | } |
| 77 | |
| 78 | dbg_hcs_params(ehci, "reset"); |
| 79 | dbg_hcc_params(ehci, "reset"); |
| 80 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
| 81 | ehci->sbrn = 0x20; |
| 82 | |
| 83 | ehci_reset(ehci); |
| 84 | |
| 85 | ret = ehci_init(hcd); |
| 86 | if (ret) |
| 87 | return ret; |
| 88 | |
| 89 | ehci_port_power(ehci, 0); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static const struct hc_driver ehci_ath79_hc_driver = { |
| 95 | .description = hcd_name, |
| 96 | .product_desc = "Atheros built-in EHCI controller", |
| 97 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 98 | .irq = ehci_irq, |
| 99 | .flags = HCD_MEMORY | HCD_USB2, |
| 100 | |
| 101 | .reset = ehci_ath79_init, |
| 102 | .start = ehci_run, |
| 103 | .stop = ehci_stop, |
| 104 | .shutdown = ehci_shutdown, |
| 105 | |
| 106 | .urb_enqueue = ehci_urb_enqueue, |
| 107 | .urb_dequeue = ehci_urb_dequeue, |
| 108 | .endpoint_disable = ehci_endpoint_disable, |
| 109 | .endpoint_reset = ehci_endpoint_reset, |
| 110 | |
| 111 | .get_frame_number = ehci_get_frame, |
| 112 | |
| 113 | .hub_status_data = ehci_hub_status_data, |
| 114 | .hub_control = ehci_hub_control, |
| 115 | |
| 116 | .relinquish_port = ehci_relinquish_port, |
| 117 | .port_handed_over = ehci_port_handed_over, |
| 118 | |
| 119 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 120 | }; |
| 121 | |
| 122 | static int ehci_ath79_probe(struct platform_device *pdev) |
| 123 | { |
| 124 | struct usb_hcd *hcd; |
| 125 | struct resource *res; |
| 126 | int irq; |
| 127 | int ret; |
| 128 | |
| 129 | if (usb_disabled()) |
| 130 | return -ENODEV; |
| 131 | |
| 132 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 133 | if (!res) { |
| 134 | dev_dbg(&pdev->dev, "no IRQ specified\n"); |
| 135 | return -ENODEV; |
| 136 | } |
| 137 | irq = res->start; |
| 138 | |
| 139 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 140 | if (!res) { |
| 141 | dev_dbg(&pdev->dev, "no base address specified\n"); |
| 142 | return -ENODEV; |
| 143 | } |
| 144 | |
| 145 | hcd = usb_create_hcd(&ehci_ath79_hc_driver, &pdev->dev, |
| 146 | dev_name(&pdev->dev)); |
| 147 | if (!hcd) |
| 148 | return -ENOMEM; |
| 149 | |
| 150 | hcd->rsrc_start = res->start; |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 151 | hcd->rsrc_len = resource_size(res); |
Gabor Juhos | 502fa84 | 2011-04-13 10:54:22 +0200 | [diff] [blame] | 152 | |
| 153 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 154 | dev_dbg(&pdev->dev, "controller already in use\n"); |
| 155 | ret = -EBUSY; |
| 156 | goto err_put_hcd; |
| 157 | } |
| 158 | |
| 159 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 160 | if (!hcd->regs) { |
| 161 | dev_dbg(&pdev->dev, "error mapping memory\n"); |
| 162 | ret = -EFAULT; |
| 163 | goto err_release_region; |
| 164 | } |
| 165 | |
| 166 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); |
| 167 | if (ret) |
| 168 | goto err_iounmap; |
| 169 | |
| 170 | return 0; |
| 171 | |
| 172 | err_iounmap: |
| 173 | iounmap(hcd->regs); |
| 174 | |
| 175 | err_release_region: |
| 176 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 177 | err_put_hcd: |
| 178 | usb_put_hcd(hcd); |
| 179 | return ret; |
| 180 | } |
| 181 | |
| 182 | static int ehci_ath79_remove(struct platform_device *pdev) |
| 183 | { |
| 184 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 185 | |
| 186 | usb_remove_hcd(hcd); |
| 187 | iounmap(hcd->regs); |
| 188 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 189 | usb_put_hcd(hcd); |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | static struct platform_driver ehci_ath79_driver = { |
| 195 | .probe = ehci_ath79_probe, |
| 196 | .remove = ehci_ath79_remove, |
| 197 | .id_table = ehci_ath79_id_table, |
| 198 | .driver = { |
| 199 | .owner = THIS_MODULE, |
| 200 | .name = "ath79-ehci", |
| 201 | } |
| 202 | }; |
| 203 | |
| 204 | MODULE_ALIAS(PLATFORM_MODULE_PREFIX "ath79-ehci"); |