]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/usb/host/ehci-s5p.c
USB: ehci-s5p: Add support for device tree
[mirror_ubuntu-jammy-kernel.git] / drivers / usb / host / ehci-s5p.c
1 /*
2 * SAMSUNG S5P USB HOST EHCI Controller
3 *
4 * Copyright (C) 2011 Samsung Electronics Co.Ltd
5 * Author: Jingoo Han <jg1.han@samsung.com>
6 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 */
14
15 #include <linux/clk.h>
16 #include <linux/of.h>
17 #include <linux/platform_device.h>
18 #include <plat/ehci.h>
19 #include <plat/usb-phy.h>
20
21 #define EHCI_INSNREG00(base) (base + 0x90)
22 #define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25)
23 #define EHCI_INSNREG00_ENA_INCR8 (0x1 << 24)
24 #define EHCI_INSNREG00_ENA_INCR4 (0x1 << 23)
25 #define EHCI_INSNREG00_ENA_INCRX_ALIGN (0x1 << 22)
26 #define EHCI_INSNREG00_ENABLE_DMA_BURST \
27 (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \
28 EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN)
29
30 struct s5p_ehci_hcd {
31 struct device *dev;
32 struct usb_hcd *hcd;
33 struct clk *clk;
34 };
35
36 static const struct hc_driver s5p_ehci_hc_driver = {
37 .description = hcd_name,
38 .product_desc = "S5P EHCI Host Controller",
39 .hcd_priv_size = sizeof(struct ehci_hcd),
40
41 .irq = ehci_irq,
42 .flags = HCD_MEMORY | HCD_USB2,
43
44 .reset = ehci_setup,
45 .start = ehci_run,
46 .stop = ehci_stop,
47 .shutdown = ehci_shutdown,
48
49 .get_frame_number = ehci_get_frame,
50
51 .urb_enqueue = ehci_urb_enqueue,
52 .urb_dequeue = ehci_urb_dequeue,
53 .endpoint_disable = ehci_endpoint_disable,
54 .endpoint_reset = ehci_endpoint_reset,
55
56 .hub_status_data = ehci_hub_status_data,
57 .hub_control = ehci_hub_control,
58 .bus_suspend = ehci_bus_suspend,
59 .bus_resume = ehci_bus_resume,
60
61 .relinquish_port = ehci_relinquish_port,
62 .port_handed_over = ehci_port_handed_over,
63
64 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
65 };
66
67 static u64 ehci_s5p_dma_mask = DMA_BIT_MASK(32);
68
69 static int __devinit s5p_ehci_probe(struct platform_device *pdev)
70 {
71 struct s5p_ehci_platdata *pdata;
72 struct s5p_ehci_hcd *s5p_ehci;
73 struct usb_hcd *hcd;
74 struct ehci_hcd *ehci;
75 struct resource *res;
76 int irq;
77 int err;
78
79 pdata = pdev->dev.platform_data;
80 if (!pdata) {
81 dev_err(&pdev->dev, "No platform data defined\n");
82 return -EINVAL;
83 }
84
85 /*
86 * Right now device-tree probed devices don't get dma_mask set.
87 * Since shared usb code relies on it, set it here for now.
88 * Once we move to full device tree support this will vanish off.
89 */
90 if (!pdev->dev.dma_mask)
91 pdev->dev.dma_mask = &ehci_s5p_dma_mask;
92 if (!pdev->dev.coherent_dma_mask)
93 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
94
95 s5p_ehci = devm_kzalloc(&pdev->dev, sizeof(struct s5p_ehci_hcd),
96 GFP_KERNEL);
97 if (!s5p_ehci)
98 return -ENOMEM;
99
100 s5p_ehci->dev = &pdev->dev;
101
102 hcd = usb_create_hcd(&s5p_ehci_hc_driver, &pdev->dev,
103 dev_name(&pdev->dev));
104 if (!hcd) {
105 dev_err(&pdev->dev, "Unable to create HCD\n");
106 return -ENOMEM;
107 }
108
109 s5p_ehci->hcd = hcd;
110 s5p_ehci->clk = clk_get(&pdev->dev, "usbhost");
111
112 if (IS_ERR(s5p_ehci->clk)) {
113 dev_err(&pdev->dev, "Failed to get usbhost clock\n");
114 err = PTR_ERR(s5p_ehci->clk);
115 goto fail_clk;
116 }
117
118 err = clk_enable(s5p_ehci->clk);
119 if (err)
120 goto fail_clken;
121
122 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
123 if (!res) {
124 dev_err(&pdev->dev, "Failed to get I/O memory\n");
125 err = -ENXIO;
126 goto fail_io;
127 }
128
129 hcd->rsrc_start = res->start;
130 hcd->rsrc_len = resource_size(res);
131 hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len);
132 if (!hcd->regs) {
133 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
134 err = -ENOMEM;
135 goto fail_io;
136 }
137
138 irq = platform_get_irq(pdev, 0);
139 if (!irq) {
140 dev_err(&pdev->dev, "Failed to get IRQ\n");
141 err = -ENODEV;
142 goto fail_io;
143 }
144
145 if (pdata->phy_init)
146 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
147
148 ehci = hcd_to_ehci(hcd);
149 ehci->caps = hcd->regs;
150
151 /* DMA burst Enable */
152 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
153
154 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
155 if (err) {
156 dev_err(&pdev->dev, "Failed to add USB HCD\n");
157 goto fail_io;
158 }
159
160 platform_set_drvdata(pdev, s5p_ehci);
161
162 return 0;
163
164 fail_io:
165 clk_disable(s5p_ehci->clk);
166 fail_clken:
167 clk_put(s5p_ehci->clk);
168 fail_clk:
169 usb_put_hcd(hcd);
170 return err;
171 }
172
173 static int __devexit s5p_ehci_remove(struct platform_device *pdev)
174 {
175 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
176 struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
177 struct usb_hcd *hcd = s5p_ehci->hcd;
178
179 usb_remove_hcd(hcd);
180
181 if (pdata && pdata->phy_exit)
182 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
183
184 clk_disable(s5p_ehci->clk);
185 clk_put(s5p_ehci->clk);
186
187 usb_put_hcd(hcd);
188
189 return 0;
190 }
191
192 static void s5p_ehci_shutdown(struct platform_device *pdev)
193 {
194 struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
195 struct usb_hcd *hcd = s5p_ehci->hcd;
196
197 if (hcd->driver->shutdown)
198 hcd->driver->shutdown(hcd);
199 }
200
201 #ifdef CONFIG_PM
202 static int s5p_ehci_suspend(struct device *dev)
203 {
204 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
205 struct usb_hcd *hcd = s5p_ehci->hcd;
206 bool do_wakeup = device_may_wakeup(dev);
207 struct platform_device *pdev = to_platform_device(dev);
208 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
209 int rc;
210
211 rc = ehci_suspend(hcd, do_wakeup);
212
213 if (pdata && pdata->phy_exit)
214 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
215
216 clk_disable(s5p_ehci->clk);
217
218 return rc;
219 }
220
221 static int s5p_ehci_resume(struct device *dev)
222 {
223 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
224 struct usb_hcd *hcd = s5p_ehci->hcd;
225 struct platform_device *pdev = to_platform_device(dev);
226 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
227
228 clk_enable(s5p_ehci->clk);
229
230 if (pdata && pdata->phy_init)
231 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
232
233 /* DMA burst Enable */
234 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
235
236 ehci_resume(hcd, false);
237 return 0;
238 }
239 #else
240 #define s5p_ehci_suspend NULL
241 #define s5p_ehci_resume NULL
242 #endif
243
244 static const struct dev_pm_ops s5p_ehci_pm_ops = {
245 .suspend = s5p_ehci_suspend,
246 .resume = s5p_ehci_resume,
247 };
248
249 #ifdef CONFIG_OF
250 static const struct of_device_id exynos_ehci_match[] = {
251 { .compatible = "samsung,exynos-ehci" },
252 {},
253 };
254 MODULE_DEVICE_TABLE(of, exynos_ehci_match);
255 #endif
256
257 static struct platform_driver s5p_ehci_driver = {
258 .probe = s5p_ehci_probe,
259 .remove = __devexit_p(s5p_ehci_remove),
260 .shutdown = s5p_ehci_shutdown,
261 .driver = {
262 .name = "s5p-ehci",
263 .owner = THIS_MODULE,
264 .pm = &s5p_ehci_pm_ops,
265 .of_match_table = of_match_ptr(exynos_ehci_match),
266 }
267 };
268
269 MODULE_ALIAS("platform:s5p-ehci");