Commit | Line | Data |
---|---|---|
1bcc5aa8 | 1 | /* |
29824c16 | 2 | * SAMSUNG EXYNOS USB HOST EHCI Controller |
1bcc5aa8 JS |
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> | |
7edb3daf MG |
16 | #include <linux/dma-mapping.h> |
17 | #include <linux/io.h> | |
18 | #include <linux/kernel.h> | |
19 | #include <linux/module.h> | |
2c026e2b | 20 | #include <linux/of.h> |
fd81d59c | 21 | #include <linux/of_gpio.h> |
7edb3daf | 22 | #include <linux/platform_device.h> |
d233c196 | 23 | #include <linux/usb/phy.h> |
b506eebc | 24 | #include <linux/usb/samsung_usb_phy.h> |
7edb3daf MG |
25 | #include <linux/usb.h> |
26 | #include <linux/usb/hcd.h> | |
27 | #include <linux/usb/otg.h> | |
28 | ||
29 | #include "ehci.h" | |
30 | ||
29824c16 | 31 | #define DRIVER_DESC "EHCI EXYNOS driver" |
1bcc5aa8 | 32 | |
88555a63 JH |
33 | #define EHCI_INSNREG00(base) (base + 0x90) |
34 | #define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25) | |
35 | #define EHCI_INSNREG00_ENA_INCR8 (0x1 << 24) | |
36 | #define EHCI_INSNREG00_ENA_INCR4 (0x1 << 23) | |
37 | #define EHCI_INSNREG00_ENA_INCRX_ALIGN (0x1 << 22) | |
38 | #define EHCI_INSNREG00_ENABLE_DMA_BURST \ | |
39 | (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \ | |
40 | EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN) | |
41 | ||
29824c16 JH |
42 | static const char hcd_name[] = "ehci-exynos"; |
43 | static struct hc_driver __read_mostly exynos_ehci_hc_driver; | |
7edb3daf | 44 | |
29824c16 | 45 | struct exynos_ehci_hcd { |
1bcc5aa8 | 46 | struct clk *clk; |
d233c196 VG |
47 | struct usb_phy *phy; |
48 | struct usb_otg *otg; | |
1bcc5aa8 JS |
49 | }; |
50 | ||
29824c16 | 51 | #define to_exynos_ehci(hcd) (struct exynos_ehci_hcd *)(hcd_to_ehci(hcd)->priv) |
d233c196 | 52 | |
29824c16 | 53 | static void exynos_setup_vbus_gpio(struct platform_device *pdev) |
fd81d59c | 54 | { |
3f3b55bf | 55 | struct device *dev = &pdev->dev; |
fd81d59c VG |
56 | int err; |
57 | int gpio; | |
58 | ||
3f3b55bf | 59 | if (!dev->of_node) |
fd81d59c VG |
60 | return; |
61 | ||
3f3b55bf | 62 | gpio = of_get_named_gpio(dev->of_node, "samsung,vbus-gpio", 0); |
fd81d59c VG |
63 | if (!gpio_is_valid(gpio)) |
64 | return; | |
65 | ||
3f3b55bf DA |
66 | err = devm_gpio_request_one(dev, gpio, GPIOF_OUT_INIT_HIGH, |
67 | "ehci_vbus_gpio"); | |
fd81d59c | 68 | if (err) |
3f3b55bf | 69 | dev_err(dev, "can't request ehci vbus gpio %d", gpio); |
fd81d59c VG |
70 | } |
71 | ||
29824c16 | 72 | static int exynos_ehci_probe(struct platform_device *pdev) |
1bcc5aa8 | 73 | { |
29824c16 | 74 | struct exynos_ehci_hcd *exynos_ehci; |
1bcc5aa8 JS |
75 | struct usb_hcd *hcd; |
76 | struct ehci_hcd *ehci; | |
77 | struct resource *res; | |
d233c196 | 78 | struct usb_phy *phy; |
1bcc5aa8 JS |
79 | int irq; |
80 | int err; | |
81 | ||
2c026e2b VG |
82 | /* |
83 | * Right now device-tree probed devices don't get dma_mask set. | |
84 | * Since shared usb code relies on it, set it here for now. | |
85 | * Once we move to full device tree support this will vanish off. | |
86 | */ | |
e1fd7341 | 87 | err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
22d9d8e8 RK |
88 | if (err) |
89 | return err; | |
2c026e2b | 90 | |
29824c16 | 91 | exynos_setup_vbus_gpio(pdev); |
fd81d59c | 92 | |
29824c16 | 93 | hcd = usb_create_hcd(&exynos_ehci_hc_driver, |
7edb3daf MG |
94 | &pdev->dev, dev_name(&pdev->dev)); |
95 | if (!hcd) { | |
96 | dev_err(&pdev->dev, "Unable to create HCD\n"); | |
1bcc5aa8 | 97 | return -ENOMEM; |
7edb3daf | 98 | } |
29824c16 | 99 | exynos_ehci = to_exynos_ehci(hcd); |
e6b0166f TA |
100 | |
101 | if (of_device_is_compatible(pdev->dev.of_node, | |
57ae1605 | 102 | "samsung,exynos5440-ehci")) |
e6b0166f | 103 | goto skip_phy; |
e6b0166f | 104 | |
d233c196 | 105 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
a16283e1 | 106 | if (IS_ERR(phy)) { |
57ae1605 JH |
107 | usb_put_hcd(hcd); |
108 | dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); | |
109 | return -EPROBE_DEFER; | |
d233c196 | 110 | } else { |
29824c16 JH |
111 | exynos_ehci->phy = phy; |
112 | exynos_ehci->otg = phy->otg; | |
d233c196 VG |
113 | } |
114 | ||
e6b0166f TA |
115 | skip_phy: |
116 | ||
29824c16 | 117 | exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); |
1bcc5aa8 | 118 | |
29824c16 | 119 | if (IS_ERR(exynos_ehci->clk)) { |
1bcc5aa8 | 120 | dev_err(&pdev->dev, "Failed to get usbhost clock\n"); |
29824c16 | 121 | err = PTR_ERR(exynos_ehci->clk); |
1bcc5aa8 JS |
122 | goto fail_clk; |
123 | } | |
124 | ||
29824c16 | 125 | err = clk_prepare_enable(exynos_ehci->clk); |
1bcc5aa8 | 126 | if (err) |
63fd0ae4 | 127 | goto fail_clk; |
1bcc5aa8 JS |
128 | |
129 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
130 | if (!res) { | |
131 | dev_err(&pdev->dev, "Failed to get I/O memory\n"); | |
132 | err = -ENXIO; | |
133 | goto fail_io; | |
134 | } | |
135 | ||
136 | hcd->rsrc_start = res->start; | |
137 | hcd->rsrc_len = resource_size(res); | |
9cb07563 | 138 | hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len); |
1bcc5aa8 JS |
139 | if (!hcd->regs) { |
140 | dev_err(&pdev->dev, "Failed to remap I/O memory\n"); | |
141 | err = -ENOMEM; | |
142 | goto fail_io; | |
143 | } | |
144 | ||
145 | irq = platform_get_irq(pdev, 0); | |
146 | if (!irq) { | |
147 | dev_err(&pdev->dev, "Failed to get IRQ\n"); | |
148 | err = -ENODEV; | |
9cb07563 | 149 | goto fail_io; |
1bcc5aa8 JS |
150 | } |
151 | ||
29824c16 JH |
152 | if (exynos_ehci->otg) |
153 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | |
d233c196 | 154 | |
29824c16 JH |
155 | if (exynos_ehci->phy) |
156 | usb_phy_init(exynos_ehci->phy); | |
1bcc5aa8 JS |
157 | |
158 | ehci = hcd_to_ehci(hcd); | |
159 | ehci->caps = hcd->regs; | |
1bcc5aa8 | 160 | |
88555a63 JH |
161 | /* DMA burst Enable */ |
162 | writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); | |
163 | ||
b5dd18d8 | 164 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
1bcc5aa8 JS |
165 | if (err) { |
166 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); | |
d233c196 | 167 | goto fail_add_hcd; |
1bcc5aa8 | 168 | } |
3c9740a1 | 169 | device_wakeup_enable(hcd->self.controller); |
1bcc5aa8 | 170 | |
bbcd85a0 | 171 | platform_set_drvdata(pdev, hcd); |
1bcc5aa8 JS |
172 | |
173 | return 0; | |
174 | ||
d233c196 | 175 | fail_add_hcd: |
29824c16 JH |
176 | if (exynos_ehci->phy) |
177 | usb_phy_shutdown(exynos_ehci->phy); | |
1bcc5aa8 | 178 | fail_io: |
29824c16 | 179 | clk_disable_unprepare(exynos_ehci->clk); |
1bcc5aa8 JS |
180 | fail_clk: |
181 | usb_put_hcd(hcd); | |
1bcc5aa8 JS |
182 | return err; |
183 | } | |
184 | ||
29824c16 | 185 | static int exynos_ehci_remove(struct platform_device *pdev) |
1bcc5aa8 | 186 | { |
7edb3daf | 187 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
29824c16 | 188 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
1bcc5aa8 JS |
189 | |
190 | usb_remove_hcd(hcd); | |
191 | ||
29824c16 JH |
192 | if (exynos_ehci->otg) |
193 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | |
d233c196 | 194 | |
29824c16 JH |
195 | if (exynos_ehci->phy) |
196 | usb_phy_shutdown(exynos_ehci->phy); | |
1bcc5aa8 | 197 | |
29824c16 | 198 | clk_disable_unprepare(exynos_ehci->clk); |
1bcc5aa8 JS |
199 | |
200 | usb_put_hcd(hcd); | |
1bcc5aa8 JS |
201 | |
202 | return 0; | |
203 | } | |
204 | ||
1acb30ef | 205 | #ifdef CONFIG_PM |
29824c16 | 206 | static int exynos_ehci_suspend(struct device *dev) |
1acb30ef | 207 | { |
7edb3daf | 208 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
29824c16 | 209 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
7edb3daf | 210 | |
c5cf9212 | 211 | bool do_wakeup = device_may_wakeup(dev); |
c5cf9212 | 212 | int rc; |
1acb30ef | 213 | |
c5cf9212 | 214 | rc = ehci_suspend(hcd, do_wakeup); |
d7217510 VG |
215 | if (rc) |
216 | return rc; | |
1acb30ef | 217 | |
29824c16 JH |
218 | if (exynos_ehci->otg) |
219 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | |
d233c196 | 220 | |
29824c16 JH |
221 | if (exynos_ehci->phy) |
222 | usb_phy_shutdown(exynos_ehci->phy); | |
1acb30ef | 223 | |
29824c16 | 224 | clk_disable_unprepare(exynos_ehci->clk); |
8b4fc8c7 | 225 | |
1acb30ef JH |
226 | return rc; |
227 | } | |
228 | ||
29824c16 | 229 | static int exynos_ehci_resume(struct device *dev) |
1acb30ef | 230 | { |
7edb3daf | 231 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
29824c16 | 232 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
1acb30ef | 233 | |
29824c16 | 234 | clk_prepare_enable(exynos_ehci->clk); |
8b4fc8c7 | 235 | |
29824c16 JH |
236 | if (exynos_ehci->otg) |
237 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | |
d233c196 | 238 | |
29824c16 JH |
239 | if (exynos_ehci->phy) |
240 | usb_phy_init(exynos_ehci->phy); | |
1acb30ef | 241 | |
88555a63 JH |
242 | /* DMA burst Enable */ |
243 | writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); | |
244 | ||
c5cf9212 | 245 | ehci_resume(hcd, false); |
1acb30ef JH |
246 | return 0; |
247 | } | |
248 | #else | |
29824c16 JH |
249 | #define exynos_ehci_suspend NULL |
250 | #define exynos_ehci_resume NULL | |
1acb30ef JH |
251 | #endif |
252 | ||
29824c16 JH |
253 | static const struct dev_pm_ops exynos_ehci_pm_ops = { |
254 | .suspend = exynos_ehci_suspend, | |
255 | .resume = exynos_ehci_resume, | |
1acb30ef JH |
256 | }; |
257 | ||
2c026e2b VG |
258 | #ifdef CONFIG_OF |
259 | static const struct of_device_id exynos_ehci_match[] = { | |
6e247777 | 260 | { .compatible = "samsung,exynos4210-ehci" }, |
e6b0166f | 261 | { .compatible = "samsung,exynos5440-ehci" }, |
2c026e2b VG |
262 | {}, |
263 | }; | |
264 | MODULE_DEVICE_TABLE(of, exynos_ehci_match); | |
265 | #endif | |
266 | ||
29824c16 JH |
267 | static struct platform_driver exynos_ehci_driver = { |
268 | .probe = exynos_ehci_probe, | |
269 | .remove = exynos_ehci_remove, | |
aaf6b52d | 270 | .shutdown = usb_hcd_platform_shutdown, |
1bcc5aa8 | 271 | .driver = { |
29824c16 | 272 | .name = "exynos-ehci", |
1bcc5aa8 | 273 | .owner = THIS_MODULE, |
29824c16 | 274 | .pm = &exynos_ehci_pm_ops, |
2c026e2b | 275 | .of_match_table = of_match_ptr(exynos_ehci_match), |
1bcc5aa8 JS |
276 | } |
277 | }; | |
29824c16 JH |
278 | static const struct ehci_driver_overrides exynos_overrides __initdata = { |
279 | .extra_priv_size = sizeof(struct exynos_ehci_hcd), | |
7edb3daf MG |
280 | }; |
281 | ||
29824c16 | 282 | static int __init ehci_exynos_init(void) |
7edb3daf MG |
283 | { |
284 | if (usb_disabled()) | |
285 | return -ENODEV; | |
286 | ||
287 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | |
29824c16 JH |
288 | ehci_init_driver(&exynos_ehci_hc_driver, &exynos_overrides); |
289 | return platform_driver_register(&exynos_ehci_driver); | |
7edb3daf | 290 | } |
29824c16 | 291 | module_init(ehci_exynos_init); |
7edb3daf | 292 | |
29824c16 | 293 | static void __exit ehci_exynos_cleanup(void) |
7edb3daf | 294 | { |
29824c16 | 295 | platform_driver_unregister(&exynos_ehci_driver); |
7edb3daf | 296 | } |
29824c16 | 297 | module_exit(ehci_exynos_cleanup); |
1bcc5aa8 | 298 | |
7edb3daf | 299 | MODULE_DESCRIPTION(DRIVER_DESC); |
29824c16 | 300 | MODULE_ALIAS("platform:exynos-ehci"); |
7edb3daf MG |
301 | MODULE_AUTHOR("Jingoo Han"); |
302 | MODULE_AUTHOR("Joonyoung Shim"); | |
303 | MODULE_LICENSE("GPL v2"); |