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: |
| 57 | ehci->caps = hcd->regs; |
| 58 | ehci->regs = hcd->regs + |
| 59 | HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); |
| 60 | break; |
| 61 | |
| 62 | case EHCI_ATH79_IP_V2: |
| 63 | hcd->has_tt = 1; |
| 64 | |
| 65 | ehci->caps = hcd->regs + 0x100; |
| 66 | ehci->regs = hcd->regs + 0x100 + |
| 67 | HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); |
| 68 | break; |
| 69 | |
| 70 | default: |
| 71 | BUG(); |
| 72 | } |
| 73 | |
| 74 | dbg_hcs_params(ehci, "reset"); |
| 75 | dbg_hcc_params(ehci, "reset"); |
| 76 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
| 77 | ehci->sbrn = 0x20; |
| 78 | |
| 79 | ehci_reset(ehci); |
| 80 | |
| 81 | ret = ehci_init(hcd); |
| 82 | if (ret) |
| 83 | return ret; |
| 84 | |
| 85 | ehci_port_power(ehci, 0); |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static const struct hc_driver ehci_ath79_hc_driver = { |
| 91 | .description = hcd_name, |
| 92 | .product_desc = "Atheros built-in EHCI controller", |
| 93 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 94 | .irq = ehci_irq, |
| 95 | .flags = HCD_MEMORY | HCD_USB2, |
| 96 | |
| 97 | .reset = ehci_ath79_init, |
| 98 | .start = ehci_run, |
| 99 | .stop = ehci_stop, |
| 100 | .shutdown = ehci_shutdown, |
| 101 | |
| 102 | .urb_enqueue = ehci_urb_enqueue, |
| 103 | .urb_dequeue = ehci_urb_dequeue, |
| 104 | .endpoint_disable = ehci_endpoint_disable, |
| 105 | .endpoint_reset = ehci_endpoint_reset, |
| 106 | |
| 107 | .get_frame_number = ehci_get_frame, |
| 108 | |
| 109 | .hub_status_data = ehci_hub_status_data, |
| 110 | .hub_control = ehci_hub_control, |
| 111 | |
| 112 | .relinquish_port = ehci_relinquish_port, |
| 113 | .port_handed_over = ehci_port_handed_over, |
| 114 | |
| 115 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 116 | }; |
| 117 | |
| 118 | static int ehci_ath79_probe(struct platform_device *pdev) |
| 119 | { |
| 120 | struct usb_hcd *hcd; |
| 121 | struct resource *res; |
| 122 | int irq; |
| 123 | int ret; |
| 124 | |
| 125 | if (usb_disabled()) |
| 126 | return -ENODEV; |
| 127 | |
| 128 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 129 | if (!res) { |
| 130 | dev_dbg(&pdev->dev, "no IRQ specified\n"); |
| 131 | return -ENODEV; |
| 132 | } |
| 133 | irq = res->start; |
| 134 | |
| 135 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 136 | if (!res) { |
| 137 | dev_dbg(&pdev->dev, "no base address specified\n"); |
| 138 | return -ENODEV; |
| 139 | } |
| 140 | |
| 141 | hcd = usb_create_hcd(&ehci_ath79_hc_driver, &pdev->dev, |
| 142 | dev_name(&pdev->dev)); |
| 143 | if (!hcd) |
| 144 | return -ENOMEM; |
| 145 | |
| 146 | hcd->rsrc_start = res->start; |
| 147 | hcd->rsrc_len = res->end - res->start + 1; |
| 148 | |
| 149 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 150 | dev_dbg(&pdev->dev, "controller already in use\n"); |
| 151 | ret = -EBUSY; |
| 152 | goto err_put_hcd; |
| 153 | } |
| 154 | |
| 155 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 156 | if (!hcd->regs) { |
| 157 | dev_dbg(&pdev->dev, "error mapping memory\n"); |
| 158 | ret = -EFAULT; |
| 159 | goto err_release_region; |
| 160 | } |
| 161 | |
| 162 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); |
| 163 | if (ret) |
| 164 | goto err_iounmap; |
| 165 | |
| 166 | return 0; |
| 167 | |
| 168 | err_iounmap: |
| 169 | iounmap(hcd->regs); |
| 170 | |
| 171 | err_release_region: |
| 172 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 173 | err_put_hcd: |
| 174 | usb_put_hcd(hcd); |
| 175 | return ret; |
| 176 | } |
| 177 | |
| 178 | static int ehci_ath79_remove(struct platform_device *pdev) |
| 179 | { |
| 180 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 181 | |
| 182 | usb_remove_hcd(hcd); |
| 183 | iounmap(hcd->regs); |
| 184 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 185 | usb_put_hcd(hcd); |
| 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | static struct platform_driver ehci_ath79_driver = { |
| 191 | .probe = ehci_ath79_probe, |
| 192 | .remove = ehci_ath79_remove, |
| 193 | .id_table = ehci_ath79_id_table, |
| 194 | .driver = { |
| 195 | .owner = THIS_MODULE, |
| 196 | .name = "ath79-ehci", |
| 197 | } |
| 198 | }; |
| 199 | |
| 200 | MODULE_ALIAS(PLATFORM_MODULE_PREFIX "ath79-ehci"); |