Merge tag 'remoteproc-for-3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/ohad...
[linux-2.6-block.git] / drivers / usb / host / ehci-sh.c
CommitLineData
63c84552
PM
1/*
2 * SuperH EHCI host controller driver
3 *
4 * Copyright (C) 2010 Paul Mundt
5 *
6 * Based on ohci-sh.c and ehci-atmel.c.
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#include <linux/platform_device.h>
13#include <linux/clk.h>
3e0c70d0 14#include <linux/platform_data/ehci-sh.h>
63c84552
PM
15
16struct ehci_sh_priv {
17 struct clk *iclk, *fclk;
18 struct usb_hcd *hcd;
19};
20
21static int ehci_sh_reset(struct usb_hcd *hcd)
22{
23 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
24 int ret;
25
26 ehci->caps = hcd->regs;
63c84552 27
1a49e2ac 28 ret = ehci_setup(hcd);
63c84552
PM
29 if (unlikely(ret))
30 return ret;
31
63c84552
PM
32 ehci_port_power(ehci, 0);
33
34 return ret;
35}
36
37static const struct hc_driver ehci_sh_hc_driver = {
38 .description = hcd_name,
39 .product_desc = "SuperH EHCI",
40 .hcd_priv_size = sizeof(struct ehci_hcd),
41
42 /*
43 * generic hardware linkage
44 */
45 .irq = ehci_irq,
46 .flags = HCD_USB2 | HCD_MEMORY,
47
48 /*
49 * basic lifecycle operations
50 */
51 .reset = ehci_sh_reset,
52 .start = ehci_run,
53 .stop = ehci_stop,
54 .shutdown = ehci_shutdown,
55
56 /*
57 * managing i/o requests and associated device resources
58 */
59 .urb_enqueue = ehci_urb_enqueue,
60 .urb_dequeue = ehci_urb_dequeue,
61 .endpoint_disable = ehci_endpoint_disable,
6e9d4476 62 .endpoint_reset = ehci_endpoint_reset,
63c84552
PM
63
64 /*
65 * scheduling support
66 */
67 .get_frame_number = ehci_get_frame,
68
69 /*
70 * root hub support
71 */
72 .hub_status_data = ehci_hub_status_data,
73 .hub_control = ehci_hub_control,
74
75#ifdef CONFIG_PM
76 .bus_suspend = ehci_bus_suspend,
77 .bus_resume = ehci_bus_resume,
78#endif
79
80 .relinquish_port = ehci_relinquish_port,
81 .port_handed_over = ehci_port_handed_over,
6e9d4476 82 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
63c84552
PM
83};
84
85static int ehci_hcd_sh_probe(struct platform_device *pdev)
86{
87 const struct hc_driver *driver = &ehci_sh_hc_driver;
88 struct resource *res;
89 struct ehci_sh_priv *priv;
3e0c70d0 90 struct ehci_sh_platdata *pdata;
63c84552
PM
91 struct usb_hcd *hcd;
92 int irq, ret;
93
94 if (usb_disabled())
95 return -ENODEV;
96
97 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
98 if (!res) {
99 dev_err(&pdev->dev,
100 "Found HC with no register addr. Check %s setup!\n",
101 dev_name(&pdev->dev));
102 ret = -ENODEV;
103 goto fail_create_hcd;
104 }
105
106 irq = platform_get_irq(pdev, 0);
107 if (irq <= 0) {
108 dev_err(&pdev->dev,
109 "Found HC with no IRQ. Check %s setup!\n",
110 dev_name(&pdev->dev));
111 ret = -ENODEV;
112 goto fail_create_hcd;
113 }
114
5897b038 115 pdata = pdev->dev.platform_data;
3e0c70d0 116
63c84552
PM
117 /* initialize hcd */
118 hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev,
119 dev_name(&pdev->dev));
120 if (!hcd) {
121 ret = -ENOMEM;
122 goto fail_create_hcd;
123 }
124
125 hcd->rsrc_start = res->start;
126 hcd->rsrc_len = resource_size(res);
127
128 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
129 driver->description)) {
130 dev_dbg(&pdev->dev, "controller already in use\n");
131 ret = -EBUSY;
132 goto fail_request_resource;
133 }
134
135 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
136 if (hcd->regs == NULL) {
137 dev_dbg(&pdev->dev, "error mapping memory\n");
138 ret = -ENXIO;
139 goto fail_ioremap;
140 }
141
142 priv = kmalloc(sizeof(struct ehci_sh_priv), GFP_KERNEL);
143 if (!priv) {
144 dev_dbg(&pdev->dev, "error allocating priv data\n");
145 ret = -ENOMEM;
146 goto fail_alloc;
147 }
148
149 /* These are optional, we don't care if they fail */
150 priv->fclk = clk_get(&pdev->dev, "usb_fck");
151 if (IS_ERR(priv->fclk))
152 priv->fclk = NULL;
153
154 priv->iclk = clk_get(&pdev->dev, "usb_ick");
155 if (IS_ERR(priv->iclk))
156 priv->iclk = NULL;
157
158 clk_enable(priv->fclk);
159 clk_enable(priv->iclk);
160
3e0c70d0
NI
161 if (pdata && pdata->phy_init)
162 pdata->phy_init();
163
b5dd18d8 164 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
63c84552
PM
165 if (ret != 0) {
166 dev_err(&pdev->dev, "Failed to add hcd");
167 goto fail_add_hcd;
168 }
169
170 priv->hcd = hcd;
171 platform_set_drvdata(pdev, priv);
172
173 return ret;
174
175fail_add_hcd:
176 clk_disable(priv->iclk);
177 clk_disable(priv->fclk);
178
179 clk_put(priv->iclk);
180 clk_put(priv->fclk);
181
182 kfree(priv);
183fail_alloc:
184 iounmap(hcd->regs);
185fail_ioremap:
186 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
187fail_request_resource:
188 usb_put_hcd(hcd);
189fail_create_hcd:
190 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
191
192 return ret;
193}
194
195static int __exit ehci_hcd_sh_remove(struct platform_device *pdev)
196{
197 struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
198 struct usb_hcd *hcd = priv->hcd;
199
200 usb_remove_hcd(hcd);
201 iounmap(hcd->regs);
202 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
203 usb_put_hcd(hcd);
204 platform_set_drvdata(pdev, NULL);
205
206 clk_disable(priv->fclk);
207 clk_disable(priv->iclk);
208
209 clk_put(priv->fclk);
210 clk_put(priv->iclk);
211
212 kfree(priv);
213
214 return 0;
215}
216
c1e0774d
PM
217static void ehci_hcd_sh_shutdown(struct platform_device *pdev)
218{
219 struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
220 struct usb_hcd *hcd = priv->hcd;
221
222 if (hcd->driver->shutdown)
223 hcd->driver->shutdown(hcd);
224}
225
63c84552
PM
226static struct platform_driver ehci_hcd_sh_driver = {
227 .probe = ehci_hcd_sh_probe,
228 .remove = __exit_p(ehci_hcd_sh_remove),
c1e0774d 229 .shutdown = ehci_hcd_sh_shutdown,
63c84552
PM
230 .driver = {
231 .name = "sh_ehci",
232 .owner = THIS_MODULE,
233 },
234};
235
236MODULE_ALIAS("platform:sh_ehci");