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