2 * SAMSUNG S5P USB HOST EHCI Controller
4 * Copyright (C) 2011 Samsung Electronics Co.Ltd
5 * Author: Jingoo Han <jg1.han@samsung.com>
6 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
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.
15 #include <linux/clk.h>
16 #include <linux/dma-mapping.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include <linux/of_gpio.h>
22 #include <linux/platform_device.h>
23 #include <linux/platform_data/usb-ehci-s5p.h>
24 #include <linux/usb/phy.h>
25 #include <linux/usb/samsung_usb_phy.h>
26 #include <linux/usb.h>
27 #include <linux/usb/hcd.h>
28 #include <linux/usb/otg.h>
32 #define DRIVER_DESC "EHCI s5p driver"
34 #define EHCI_INSNREG00(base) (base + 0x90)
35 #define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25)
36 #define EHCI_INSNREG00_ENA_INCR8 (0x1 << 24)
37 #define EHCI_INSNREG00_ENA_INCR4 (0x1 << 23)
38 #define EHCI_INSNREG00_ENA_INCRX_ALIGN (0x1 << 22)
39 #define EHCI_INSNREG00_ENABLE_DMA_BURST \
40 (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \
41 EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN)
43 static const char hcd_name
[] = "ehci-s5p";
44 static struct hc_driver __read_mostly s5p_ehci_hc_driver
;
50 struct s5p_ehci_platdata
*pdata
;
53 static struct s5p_ehci_platdata empty_platdata
;
55 #define to_s5p_ehci(hcd) (struct s5p_ehci_hcd *)(hcd_to_ehci(hcd)->priv)
57 static void s5p_setup_vbus_gpio(struct platform_device
*pdev
)
59 struct device
*dev
= &pdev
->dev
;
66 gpio
= of_get_named_gpio(dev
->of_node
, "samsung,vbus-gpio", 0);
67 if (!gpio_is_valid(gpio
))
70 err
= devm_gpio_request_one(dev
, gpio
, GPIOF_OUT_INIT_HIGH
,
73 dev_err(dev
, "can't request ehci vbus gpio %d", gpio
);
76 static int s5p_ehci_probe(struct platform_device
*pdev
)
78 struct s5p_ehci_platdata
*pdata
= dev_get_platdata(&pdev
->dev
);
79 struct s5p_ehci_hcd
*s5p_ehci
;
81 struct ehci_hcd
*ehci
;
88 * Right now device-tree probed devices don't get dma_mask set.
89 * Since shared usb code relies on it, set it here for now.
90 * Once we move to full device tree support this will vanish off.
92 if (!pdev
->dev
.dma_mask
)
93 pdev
->dev
.dma_mask
= &pdev
->dev
.coherent_dma_mask
;
94 if (!pdev
->dev
.coherent_dma_mask
)
95 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
97 s5p_setup_vbus_gpio(pdev
);
99 hcd
= usb_create_hcd(&s5p_ehci_hc_driver
,
100 &pdev
->dev
, dev_name(&pdev
->dev
));
102 dev_err(&pdev
->dev
, "Unable to create HCD\n");
105 s5p_ehci
= to_s5p_ehci(hcd
);
107 if (of_device_is_compatible(pdev
->dev
.of_node
,
108 "samsung,exynos5440-ehci")) {
109 s5p_ehci
->pdata
= &empty_platdata
;
113 phy
= devm_usb_get_phy(&pdev
->dev
, USB_PHY_TYPE_USB2
);
115 /* Fallback to pdata */
118 dev_warn(&pdev
->dev
, "no platform data or transceiver defined\n");
119 return -EPROBE_DEFER
;
121 s5p_ehci
->pdata
= pdata
;
125 s5p_ehci
->otg
= phy
->otg
;
130 s5p_ehci
->clk
= devm_clk_get(&pdev
->dev
, "usbhost");
132 if (IS_ERR(s5p_ehci
->clk
)) {
133 dev_err(&pdev
->dev
, "Failed to get usbhost clock\n");
134 err
= PTR_ERR(s5p_ehci
->clk
);
138 err
= clk_prepare_enable(s5p_ehci
->clk
);
142 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
144 dev_err(&pdev
->dev
, "Failed to get I/O memory\n");
149 hcd
->rsrc_start
= res
->start
;
150 hcd
->rsrc_len
= resource_size(res
);
151 hcd
->regs
= devm_ioremap(&pdev
->dev
, res
->start
, hcd
->rsrc_len
);
153 dev_err(&pdev
->dev
, "Failed to remap I/O memory\n");
158 irq
= platform_get_irq(pdev
, 0);
160 dev_err(&pdev
->dev
, "Failed to get IRQ\n");
166 s5p_ehci
->otg
->set_host(s5p_ehci
->otg
, &hcd
->self
);
169 usb_phy_init(s5p_ehci
->phy
);
170 else if (s5p_ehci
->pdata
->phy_init
)
171 s5p_ehci
->pdata
->phy_init(pdev
, USB_PHY_TYPE_HOST
);
173 ehci
= hcd_to_ehci(hcd
);
174 ehci
->caps
= hcd
->regs
;
176 /* DMA burst Enable */
177 writel(EHCI_INSNREG00_ENABLE_DMA_BURST
, EHCI_INSNREG00(hcd
->regs
));
179 err
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
181 dev_err(&pdev
->dev
, "Failed to add USB HCD\n");
185 platform_set_drvdata(pdev
, hcd
);
191 usb_phy_shutdown(s5p_ehci
->phy
);
192 else if (s5p_ehci
->pdata
->phy_exit
)
193 s5p_ehci
->pdata
->phy_exit(pdev
, USB_PHY_TYPE_HOST
);
195 clk_disable_unprepare(s5p_ehci
->clk
);
201 static int s5p_ehci_remove(struct platform_device
*pdev
)
203 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
204 struct s5p_ehci_hcd
*s5p_ehci
= to_s5p_ehci(hcd
);
209 s5p_ehci
->otg
->set_host(s5p_ehci
->otg
, &hcd
->self
);
212 usb_phy_shutdown(s5p_ehci
->phy
);
213 else if (s5p_ehci
->pdata
->phy_exit
)
214 s5p_ehci
->pdata
->phy_exit(pdev
, USB_PHY_TYPE_HOST
);
216 clk_disable_unprepare(s5p_ehci
->clk
);
224 static int s5p_ehci_suspend(struct device
*dev
)
226 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
227 struct s5p_ehci_hcd
*s5p_ehci
= to_s5p_ehci(hcd
);
228 struct platform_device
*pdev
= to_platform_device(dev
);
230 bool do_wakeup
= device_may_wakeup(dev
);
233 rc
= ehci_suspend(hcd
, do_wakeup
);
236 s5p_ehci
->otg
->set_host(s5p_ehci
->otg
, &hcd
->self
);
239 usb_phy_shutdown(s5p_ehci
->phy
);
240 else if (s5p_ehci
->pdata
->phy_exit
)
241 s5p_ehci
->pdata
->phy_exit(pdev
, USB_PHY_TYPE_HOST
);
243 clk_disable_unprepare(s5p_ehci
->clk
);
248 static int s5p_ehci_resume(struct device
*dev
)
250 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
251 struct s5p_ehci_hcd
*s5p_ehci
= to_s5p_ehci(hcd
);
252 struct platform_device
*pdev
= to_platform_device(dev
);
254 clk_prepare_enable(s5p_ehci
->clk
);
257 s5p_ehci
->otg
->set_host(s5p_ehci
->otg
, &hcd
->self
);
260 usb_phy_init(s5p_ehci
->phy
);
261 else if (s5p_ehci
->pdata
->phy_init
)
262 s5p_ehci
->pdata
->phy_init(pdev
, USB_PHY_TYPE_HOST
);
264 /* DMA burst Enable */
265 writel(EHCI_INSNREG00_ENABLE_DMA_BURST
, EHCI_INSNREG00(hcd
->regs
));
267 ehci_resume(hcd
, false);
271 #define s5p_ehci_suspend NULL
272 #define s5p_ehci_resume NULL
275 static const struct dev_pm_ops s5p_ehci_pm_ops
= {
276 .suspend
= s5p_ehci_suspend
,
277 .resume
= s5p_ehci_resume
,
281 static const struct of_device_id exynos_ehci_match
[] = {
282 { .compatible
= "samsung,exynos4210-ehci" },
283 { .compatible
= "samsung,exynos5440-ehci" },
286 MODULE_DEVICE_TABLE(of
, exynos_ehci_match
);
289 static struct platform_driver s5p_ehci_driver
= {
290 .probe
= s5p_ehci_probe
,
291 .remove
= s5p_ehci_remove
,
292 .shutdown
= usb_hcd_platform_shutdown
,
295 .owner
= THIS_MODULE
,
296 .pm
= &s5p_ehci_pm_ops
,
297 .of_match_table
= of_match_ptr(exynos_ehci_match
),
300 static const struct ehci_driver_overrides s5p_overrides __initdata
= {
301 .extra_priv_size
= sizeof(struct s5p_ehci_hcd
),
304 static int __init
ehci_s5p_init(void)
309 pr_info("%s: " DRIVER_DESC
"\n", hcd_name
);
310 ehci_init_driver(&s5p_ehci_hc_driver
, &s5p_overrides
);
311 return platform_driver_register(&s5p_ehci_driver
);
313 module_init(ehci_s5p_init
);
315 static void __exit
ehci_s5p_cleanup(void)
317 platform_driver_unregister(&s5p_ehci_driver
);
319 module_exit(ehci_s5p_cleanup
);
321 MODULE_DESCRIPTION(DRIVER_DESC
);
322 MODULE_ALIAS("platform:s5p-ehci");
323 MODULE_AUTHOR("Jingoo Han");
324 MODULE_AUTHOR("Joonyoung Shim");
325 MODULE_LICENSE("GPL v2");