blob: 719ca48a471ac407ab68b2fa7892b20730bc2e34 [file] [log] [blame]
Deepak Sikric8c38de2010-11-10 14:33:18 +05301/*
2* Driver for EHCI HCD on SPEAR SOC
3*
4* Copyright (C) 2010 ST Micro Electronics,
5* Deepak Sikri <deepak.sikri@st.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
Deepak Sikric8c38de2010-11-10 14:33:18 +053014#include <linux/clk.h>
Deepak Sikri8c1b3692012-02-24 14:49:31 +053015#include <linux/jiffies.h>
Stefan Roese56fafb92012-04-16 09:08:08 +053016#include <linux/of.h>
Deepak Sikri8c1b3692012-02-24 14:49:31 +053017#include <linux/platform_device.h>
18#include <linux/pm.h>
Deepak Sikric8c38de2010-11-10 14:33:18 +053019
20struct spear_ehci {
21 struct ehci_hcd ehci;
22 struct clk *clk;
23};
24
25#define to_spear_ehci(hcd) (struct spear_ehci *)hcd_to_ehci(hcd)
26
27static void spear_start_ehci(struct spear_ehci *ehci)
28{
Viresh Kumar15c9d502012-04-17 17:08:50 +053029 clk_prepare_enable(ehci->clk);
Deepak Sikric8c38de2010-11-10 14:33:18 +053030}
31
32static void spear_stop_ehci(struct spear_ehci *ehci)
33{
Viresh Kumar15c9d502012-04-17 17:08:50 +053034 clk_disable_unprepare(ehci->clk);
Deepak Sikric8c38de2010-11-10 14:33:18 +053035}
36
37static int ehci_spear_setup(struct usb_hcd *hcd)
38{
39 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
Deepak Sikric8c38de2010-11-10 14:33:18 +053040
41 /* registers start at offset 0x0 */
42 ehci->caps = hcd->regs;
Alan Stern1a49e2a2012-07-09 15:55:14 -040043
Alan Sternc73cee72012-10-31 13:21:06 -040044 return ehci_setup(hcd);
Deepak Sikric8c38de2010-11-10 14:33:18 +053045}
46
47static const struct hc_driver ehci_spear_hc_driver = {
48 .description = hcd_name,
49 .product_desc = "SPEAr EHCI",
50 .hcd_priv_size = sizeof(struct spear_ehci),
51
52 /* generic hardware linkage */
53 .irq = ehci_irq,
54 .flags = HCD_MEMORY | HCD_USB2,
55
56 /* basic lifecycle operations */
57 .reset = ehci_spear_setup,
58 .start = ehci_run,
59 .stop = ehci_stop,
60 .shutdown = ehci_shutdown,
61
62 /* managing i/o requests and associated device resources */
63 .urb_enqueue = ehci_urb_enqueue,
64 .urb_dequeue = ehci_urb_dequeue,
65 .endpoint_disable = ehci_endpoint_disable,
66 .endpoint_reset = ehci_endpoint_reset,
67
68 /* scheduling support */
69 .get_frame_number = ehci_get_frame,
70
71 /* root hub support */
72 .hub_status_data = ehci_hub_status_data,
73 .hub_control = ehci_hub_control,
74 .bus_suspend = ehci_bus_suspend,
75 .bus_resume = ehci_bus_resume,
76 .relinquish_port = ehci_relinquish_port,
77 .port_handed_over = ehci_port_handed_over,
78 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
79};
80
Deepak Sikri8c1b3692012-02-24 14:49:31 +053081#ifdef CONFIG_PM
82static int ehci_spear_drv_suspend(struct device *dev)
83{
84 struct usb_hcd *hcd = dev_get_drvdata(dev);
Alan Sternc5cf9212012-06-28 11:19:02 -040085 bool do_wakeup = device_may_wakeup(dev);
Deepak Sikri8c1b3692012-02-24 14:49:31 +053086
Alan Sternc5cf9212012-06-28 11:19:02 -040087 return ehci_suspend(hcd, do_wakeup);
Deepak Sikri8c1b3692012-02-24 14:49:31 +053088}
89
90static int ehci_spear_drv_resume(struct device *dev)
91{
92 struct usb_hcd *hcd = dev_get_drvdata(dev);
Deepak Sikri8c1b3692012-02-24 14:49:31 +053093
Alan Sternc5cf9212012-06-28 11:19:02 -040094 ehci_resume(hcd, false);
Deepak Sikri8c1b3692012-02-24 14:49:31 +053095 return 0;
96}
97#endif /* CONFIG_PM */
98
99static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend,
100 ehci_spear_drv_resume);
101
Stefan Roese56fafb92012-04-16 09:08:08 +0530102static u64 spear_ehci_dma_mask = DMA_BIT_MASK(32);
103
Deepak Sikric8c38de2010-11-10 14:33:18 +0530104static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
105{
106 struct usb_hcd *hcd ;
107 struct spear_ehci *ehci;
108 struct resource *res;
109 struct clk *usbh_clk;
110 const struct hc_driver *driver = &ehci_spear_hc_driver;
Deepak Sikric8c38de2010-11-10 14:33:18 +0530111 int irq, retval;
112 char clk_name[20] = "usbh_clk";
Stefan Roese56fafb92012-04-16 09:08:08 +0530113 static int instance = -1;
Deepak Sikric8c38de2010-11-10 14:33:18 +0530114
115 if (usb_disabled())
116 return -ENODEV;
117
118 irq = platform_get_irq(pdev, 0);
119 if (irq < 0) {
120 retval = irq;
121 goto fail_irq_get;
122 }
123
Stefan Roese56fafb92012-04-16 09:08:08 +0530124 /*
125 * Right now device-tree probed devices don't get dma_mask set.
126 * Since shared usb code relies on it, set it here for now.
127 * Once we have dma capability bindings this can go away.
128 */
129 if (!pdev->dev.dma_mask)
130 pdev->dev.dma_mask = &spear_ehci_dma_mask;
131
132 /*
133 * Increment the device instance, when probing via device-tree
134 */
135 if (pdev->id < 0)
136 instance++;
137 else
138 instance = pdev->id;
139 sprintf(clk_name, "usbh.%01d_clk", instance);
Deepak Sikric8c38de2010-11-10 14:33:18 +0530140
141 usbh_clk = clk_get(NULL, clk_name);
142 if (IS_ERR(usbh_clk)) {
143 dev_err(&pdev->dev, "Error getting interface clock\n");
144 retval = PTR_ERR(usbh_clk);
145 goto fail_get_usbh_clk;
146 }
147
148 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
149 if (!hcd) {
150 retval = -ENOMEM;
151 goto fail_create_hcd;
152 }
153
154 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
155 if (!res) {
156 retval = -ENODEV;
157 goto fail_request_resource;
158 }
159
160 hcd->rsrc_start = res->start;
161 hcd->rsrc_len = resource_size(res);
162 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
163 driver->description)) {
164 retval = -EBUSY;
165 goto fail_request_resource;
166 }
167
168 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
169 if (hcd->regs == NULL) {
170 dev_dbg(&pdev->dev, "error mapping memory\n");
171 retval = -ENOMEM;
172 goto fail_ioremap;
173 }
174
175 ehci = (struct spear_ehci *)hcd_to_ehci(hcd);
176 ehci->clk = usbh_clk;
177
178 spear_start_ehci(ehci);
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800179 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
Deepak Sikric8c38de2010-11-10 14:33:18 +0530180 if (retval)
181 goto fail_add_hcd;
182
183 return retval;
184
185fail_add_hcd:
186 spear_stop_ehci(ehci);
187 iounmap(hcd->regs);
188fail_ioremap:
189 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
190fail_request_resource:
191 usb_put_hcd(hcd);
192fail_create_hcd:
193 clk_put(usbh_clk);
194fail_get_usbh_clk:
195fail_irq_get:
196 dev_err(&pdev->dev, "init fail, %d\n", retval);
197
198 return retval ;
199}
200
201static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
202{
203 struct usb_hcd *hcd = platform_get_drvdata(pdev);
204 struct spear_ehci *ehci_p = to_spear_ehci(hcd);
205
206 if (!hcd)
207 return 0;
208 if (in_interrupt())
209 BUG();
210 usb_remove_hcd(hcd);
211
212 if (ehci_p->clk)
213 spear_stop_ehci(ehci_p);
214 iounmap(hcd->regs);
215 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
216 usb_put_hcd(hcd);
217
218 if (ehci_p->clk)
219 clk_put(ehci_p->clk);
220
221 return 0;
222}
223
Stefan Roese56fafb92012-04-16 09:08:08 +0530224static struct of_device_id spear_ehci_id_table[] __devinitdata = {
225 { .compatible = "st,spear600-ehci", },
226 { },
227};
228
Deepak Sikric8c38de2010-11-10 14:33:18 +0530229static struct platform_driver spear_ehci_hcd_driver = {
230 .probe = spear_ehci_hcd_drv_probe,
231 .remove = spear_ehci_hcd_drv_remove,
232 .shutdown = usb_hcd_platform_shutdown,
233 .driver = {
234 .name = "spear-ehci",
Deepak Sikri8c1b3692012-02-24 14:49:31 +0530235 .bus = &platform_bus_type,
236 .pm = &ehci_spear_pm_ops,
Stefan Roese56fafb92012-04-16 09:08:08 +0530237 .of_match_table = of_match_ptr(spear_ehci_id_table),
Deepak Sikric8c38de2010-11-10 14:33:18 +0530238 }
239};
240
241MODULE_ALIAS("platform:spear-ehci");