2 * SAMSUNG EXYNOS USB HOST OHCI Controller
4 * Copyright (C) 2011 Samsung Electronics Co.Ltd
5 * Author: Jingoo Han <jg1.han@samsung.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
14 #include <linux/clk.h>
15 #include <linux/platform_device.h>
16 #include <mach/ohci.h>
17 #include <plat/usb-phy.h>
19 struct exynos_ohci_hcd {
25 static int ohci_exynos_start(struct usb_hcd *hcd)
27 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
30 ohci_dbg(ohci, "ohci_exynos_start, ohci:%p", ohci);
32 ret = ohci_init(ohci);
38 dev_err(hcd->self.controller, "can't start %s\n",
47 static const struct hc_driver exynos_ohci_hc_driver = {
48 .description = hcd_name,
49 .product_desc = "EXYNOS OHCI Host Controller",
50 .hcd_priv_size = sizeof(struct ohci_hcd),
53 .flags = HCD_MEMORY|HCD_USB11,
55 .start = ohci_exynos_start,
57 .shutdown = ohci_shutdown,
59 .get_frame_number = ohci_get_frame,
61 .urb_enqueue = ohci_urb_enqueue,
62 .urb_dequeue = ohci_urb_dequeue,
63 .endpoint_disable = ohci_endpoint_disable,
65 .hub_status_data = ohci_hub_status_data,
66 .hub_control = ohci_hub_control,
68 .bus_suspend = ohci_bus_suspend,
69 .bus_resume = ohci_bus_resume,
71 .start_port_reset = ohci_start_port_reset,
74 static int __devinit exynos_ohci_probe(struct platform_device *pdev)
76 struct exynos4_ohci_platdata *pdata;
77 struct exynos_ohci_hcd *exynos_ohci;
79 struct ohci_hcd *ohci;
84 pdata = pdev->dev.platform_data;
86 dev_err(&pdev->dev, "No platform data defined\n");
90 exynos_ohci = kzalloc(sizeof(struct exynos_ohci_hcd), GFP_KERNEL);
94 exynos_ohci->dev = &pdev->dev;
96 hcd = usb_create_hcd(&exynos_ohci_hc_driver, &pdev->dev,
97 dev_name(&pdev->dev));
99 dev_err(&pdev->dev, "Unable to create HCD\n");
104 exynos_ohci->hcd = hcd;
105 exynos_ohci->clk = clk_get(&pdev->dev, "usbhost");
107 if (IS_ERR(exynos_ohci->clk)) {
108 dev_err(&pdev->dev, "Failed to get usbhost clock\n");
109 err = PTR_ERR(exynos_ohci->clk);
113 err = clk_enable(exynos_ohci->clk);
117 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
119 dev_err(&pdev->dev, "Failed to get I/O memory\n");
124 hcd->rsrc_start = res->start;
125 hcd->rsrc_len = resource_size(res);
126 hcd->regs = ioremap(res->start, resource_size(res));
128 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
133 irq = platform_get_irq(pdev, 0);
135 dev_err(&pdev->dev, "Failed to get IRQ\n");
141 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
143 ohci = hcd_to_ohci(hcd);
146 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
148 dev_err(&pdev->dev, "Failed to add USB HCD\n");
152 platform_set_drvdata(pdev, exynos_ohci);
159 clk_disable(exynos_ohci->clk);
161 clk_put(exynos_ohci->clk);
169 static int __devexit exynos_ohci_remove(struct platform_device *pdev)
171 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
172 struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev);
173 struct usb_hcd *hcd = exynos_ohci->hcd;
177 if (pdata && pdata->phy_exit)
178 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
182 clk_disable(exynos_ohci->clk);
183 clk_put(exynos_ohci->clk);
191 static void exynos_ohci_shutdown(struct platform_device *pdev)
193 struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev);
194 struct usb_hcd *hcd = exynos_ohci->hcd;
196 if (hcd->driver->shutdown)
197 hcd->driver->shutdown(hcd);
201 static int exynos_ohci_suspend(struct device *dev)
203 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev);
204 struct usb_hcd *hcd = exynos_ohci->hcd;
205 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
206 struct platform_device *pdev = to_platform_device(dev);
207 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
212 * Root hub was already suspended. Disable irq emission and
213 * mark HW unaccessible, bail out if RH has been resumed. Use
214 * the spinlock to properly synchronize with possible pending
215 * RH suspend or resume activity.
217 spin_lock_irqsave(&ohci->lock, flags);
218 if (ohci->rh_state != OHCI_RH_SUSPENDED &&
219 ohci->rh_state != OHCI_RH_HALTED) {
224 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
226 if (pdata && pdata->phy_exit)
227 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
229 spin_unlock_irqrestore(&ohci->lock, flags);
234 static int exynos_ohci_resume(struct device *dev)
236 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev);
237 struct usb_hcd *hcd = exynos_ohci->hcd;
238 struct platform_device *pdev = to_platform_device(dev);
239 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
241 if (pdata && pdata->phy_init)
242 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
244 /* Mark hardware accessible again as we are out of D3 state by now */
245 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
247 ohci_finish_controller_resume(hcd);
252 #define exynos_ohci_suspend NULL
253 #define exynos_ohci_resume NULL
256 static const struct dev_pm_ops exynos_ohci_pm_ops = {
257 .suspend = exynos_ohci_suspend,
258 .resume = exynos_ohci_resume,
261 static struct platform_driver exynos_ohci_driver = {
262 .probe = exynos_ohci_probe,
263 .remove = __devexit_p(exynos_ohci_remove),
264 .shutdown = exynos_ohci_shutdown,
266 .name = "exynos-ohci",
267 .owner = THIS_MODULE,
268 .pm = &exynos_ohci_pm_ops,
272 MODULE_ALIAS("platform:exynos-ohci");
273 MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");