blob: 411bb74152ebe2ba3b063fb0e5e3445626d61af1 [file] [log] [blame]
Nicolas Ferre501c9c02009-07-27 14:47:40 -07001/*
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 Ferre94753752012-03-27 18:23:31 +020016#include <linux/of.h>
Jean-Christophe PLAGNIOL-VILLARD9d843002011-11-22 12:11:13 +080017#include <linux/of_platform.h>
Nicolas Ferre501c9c02009-07-27 14:47:40 -070018
19/* interface and function clocks */
20static struct clk *iclk, *fclk;
21static int clocked;
22
23/*-------------------------------------------------------------------------*/
24
25static void atmel_start_clock(void)
26{
27 clk_enable(iclk);
28 clk_enable(fclk);
29 clocked = 1;
30}
31
32static void atmel_stop_clock(void)
33{
34 clk_disable(fclk);
35 clk_disable(iclk);
36 clocked = 0;
37}
38
39static void atmel_start_ehci(struct platform_device *pdev)
40{
41 dev_dbg(&pdev->dev, "start\n");
42 atmel_start_clock();
43}
44
45static void atmel_stop_ehci(struct platform_device *pdev)
46{
47 dev_dbg(&pdev->dev, "stop\n");
48 atmel_stop_clock();
49}
50
51/*-------------------------------------------------------------------------*/
52
53static int ehci_atmel_setup(struct usb_hcd *hcd)
54{
55 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
Alan Stern1a49e2a2012-07-09 15:55:14 -040056 int retval;
Nicolas Ferre501c9c02009-07-27 14:47:40 -070057
58 /* registers start at offset 0x0 */
59 ehci->caps = hcd->regs;
Nicolas Ferre501c9c02009-07-27 14:47:40 -070060
Alan Stern1a49e2a2012-07-09 15:55:14 -040061 retval = ehci_setup(hcd);
Nicolas Ferre501c9c02009-07-27 14:47:40 -070062 if (retval)
63 return retval;
64
Nicolas Ferre501c9c02009-07-27 14:47:40 -070065 ehci_port_power(ehci, 0);
66
67 return retval;
68}
69
70static const struct hc_driver ehci_atmel_hc_driver = {
71 .description = hcd_name,
72 .product_desc = "Atmel EHCI UHP HS",
73 .hcd_priv_size = sizeof(struct ehci_hcd),
74
75 /* generic hardware linkage */
76 .irq = ehci_irq,
77 .flags = HCD_MEMORY | HCD_USB2,
78
79 /* basic lifecycle operations */
80 .reset = ehci_atmel_setup,
81 .start = ehci_run,
82 .stop = ehci_stop,
83 .shutdown = ehci_shutdown,
84
85 /* managing i/o requests and associated device resources */
86 .urb_enqueue = ehci_urb_enqueue,
87 .urb_dequeue = ehci_urb_dequeue,
88 .endpoint_disable = ehci_endpoint_disable,
Paul Mundtb48d7f52010-11-30 17:57:02 +090089 .endpoint_reset = ehci_endpoint_reset,
Nicolas Ferre501c9c02009-07-27 14:47:40 -070090
91 /* scheduling support */
92 .get_frame_number = ehci_get_frame,
93
94 /* root hub support */
95 .hub_status_data = ehci_hub_status_data,
96 .hub_control = ehci_hub_control,
97 .bus_suspend = ehci_bus_suspend,
98 .bus_resume = ehci_bus_resume,
99 .relinquish_port = ehci_relinquish_port,
100 .port_handed_over = ehci_port_handed_over,
Paul Mundtb48d7f52010-11-30 17:57:02 +0900101
102 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700103};
104
Jean-Christophe PLAGNIOL-VILLARD9d843002011-11-22 12:11:13 +0800105static u64 at91_ehci_dma_mask = DMA_BIT_MASK(32);
106
Hubert Feurstein0dfeefb2011-03-10 10:06:37 +0100107static int __devinit ehci_atmel_drv_probe(struct platform_device *pdev)
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700108{
109 struct usb_hcd *hcd;
110 const struct hc_driver *driver = &ehci_atmel_hc_driver;
111 struct resource *res;
112 int irq;
113 int retval;
114
115 if (usb_disabled())
116 return -ENODEV;
117
118 pr_debug("Initializing Atmel-SoC USB Host Controller\n");
119
120 irq = platform_get_irq(pdev, 0);
121 if (irq <= 0) {
122 dev_err(&pdev->dev,
123 "Found HC with no IRQ. Check %s setup!\n",
124 dev_name(&pdev->dev));
125 retval = -ENODEV;
126 goto fail_create_hcd;
127 }
128
Jean-Christophe PLAGNIOL-VILLARD9d843002011-11-22 12:11:13 +0800129 /* Right now device-tree probed devices don't get dma_mask set.
130 * Since shared usb code relies on it, set it here for now.
131 * Once we have dma capability bindings this can go away.
132 */
133 if (!pdev->dev.dma_mask)
134 pdev->dev.dma_mask = &at91_ehci_dma_mask;
135
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700136 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
137 if (!hcd) {
138 retval = -ENOMEM;
139 goto fail_create_hcd;
140 }
141
142 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
143 if (!res) {
144 dev_err(&pdev->dev,
145 "Found HC with no register addr. Check %s setup!\n",
146 dev_name(&pdev->dev));
147 retval = -ENODEV;
148 goto fail_request_resource;
149 }
150 hcd->rsrc_start = res->start;
H Hartley Sweetenf65c3542009-12-14 18:15:35 -0500151 hcd->rsrc_len = resource_size(res);
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700152
Julia Lawall97983432012-07-29 21:46:05 +0200153 hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700154 if (hcd->regs == NULL) {
155 dev_dbg(&pdev->dev, "error mapping memory\n");
156 retval = -EFAULT;
Julia Lawall97983432012-07-29 21:46:05 +0200157 goto fail_request_resource;
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700158 }
159
Julia Lawall97983432012-07-29 21:46:05 +0200160 iclk = devm_clk_get(&pdev->dev, "ehci_clk");
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700161 if (IS_ERR(iclk)) {
162 dev_err(&pdev->dev, "Error getting interface clock\n");
163 retval = -ENOENT;
Julia Lawall97983432012-07-29 21:46:05 +0200164 goto fail_request_resource;
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700165 }
Julia Lawall97983432012-07-29 21:46:05 +0200166 fclk = devm_clk_get(&pdev->dev, "uhpck");
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700167 if (IS_ERR(fclk)) {
168 dev_err(&pdev->dev, "Error getting function clock\n");
169 retval = -ENOENT;
Julia Lawall97983432012-07-29 21:46:05 +0200170 goto fail_request_resource;
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700171 }
172
173 atmel_start_ehci(pdev);
174
175 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
176 if (retval)
177 goto fail_add_hcd;
178
179 return retval;
180
181fail_add_hcd:
182 atmel_stop_ehci(pdev);
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700183fail_request_resource:
184 usb_put_hcd(hcd);
185fail_create_hcd:
186 dev_err(&pdev->dev, "init %s fail, %d\n",
187 dev_name(&pdev->dev), retval);
188
189 return retval;
190}
191
Hubert Feurstein0dfeefb2011-03-10 10:06:37 +0100192static int __devexit ehci_atmel_drv_remove(struct platform_device *pdev)
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700193{
194 struct usb_hcd *hcd = platform_get_drvdata(pdev);
195
196 ehci_shutdown(hcd);
197 usb_remove_hcd(hcd);
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700198 usb_put_hcd(hcd);
199
200 atmel_stop_ehci(pdev);
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700201 fclk = iclk = NULL;
202
203 return 0;
204}
205
Jean-Christophe PLAGNIOL-VILLARD9d843002011-11-22 12:11:13 +0800206#ifdef CONFIG_OF
207static const struct of_device_id atmel_ehci_dt_ids[] = {
208 { .compatible = "atmel,at91sam9g45-ehci" },
209 { /* sentinel */ }
210};
211
212MODULE_DEVICE_TABLE(of, atmel_ehci_dt_ids);
213#endif
214
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700215static struct platform_driver ehci_atmel_driver = {
216 .probe = ehci_atmel_drv_probe,
Hubert Feurstein0dfeefb2011-03-10 10:06:37 +0100217 .remove = __devexit_p(ehci_atmel_drv_remove),
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700218 .shutdown = usb_hcd_platform_shutdown,
Jean-Christophe PLAGNIOL-VILLARD9d843002011-11-22 12:11:13 +0800219 .driver = {
220 .name = "atmel-ehci",
221 .of_match_table = of_match_ptr(atmel_ehci_dt_ids),
222 },
Nicolas Ferre501c9c02009-07-27 14:47:40 -0700223};