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>
16 #include <linux/platform_device.h>
17 #include <linux/platform_data/usb-exynos.h>
18 #include <plat/usb-phy.h>
20 struct exynos_ohci_hcd {
26 static int ohci_exynos_reset(struct usb_hcd *hcd)
28 return ohci_init(hcd_to_ohci(hcd));
31 static int ohci_exynos_start(struct usb_hcd *hcd)
33 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
36 ohci_dbg(ohci, "ohci_exynos_start, ohci:%p", ohci);
40 dev_err(hcd->self.controller, "can't start %s\n",
49 static const struct hc_driver exynos_ohci_hc_driver = {
50 .description = hcd_name,
51 .product_desc = "EXYNOS OHCI Host Controller",
52 .hcd_priv_size = sizeof(struct ohci_hcd),
55 .flags = HCD_MEMORY|HCD_USB11,
57 .reset = ohci_exynos_reset,
58 .start = ohci_exynos_start,
60 .shutdown = ohci_shutdown,
62 .get_frame_number = ohci_get_frame,
64 .urb_enqueue = ohci_urb_enqueue,
65 .urb_dequeue = ohci_urb_dequeue,
66 .endpoint_disable = ohci_endpoint_disable,
68 .hub_status_data = ohci_hub_status_data,
69 .hub_control = ohci_hub_control,
71 .bus_suspend = ohci_bus_suspend,
72 .bus_resume = ohci_bus_resume,
74 .start_port_reset = ohci_start_port_reset,
77 static u64 ohci_exynos_dma_mask = DMA_BIT_MASK(32);
79 static int exynos_ohci_probe(struct platform_device *pdev)
81 struct exynos4_ohci_platdata *pdata;
82 struct exynos_ohci_hcd *exynos_ohci;
84 struct ohci_hcd *ohci;
89 pdata = pdev->dev.platform_data;
91 dev_err(&pdev->dev, "No platform data defined\n");
96 * Right now device-tree probed devices don't get dma_mask set.
97 * Since shared usb code relies on it, set it here for now.
98 * Once we move to full device tree support this will vanish off.
100 if (!pdev->dev.dma_mask)
101 pdev->dev.dma_mask = &ohci_exynos_dma_mask;
102 if (!pdev->dev.coherent_dma_mask)
103 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
105 exynos_ohci = devm_kzalloc(&pdev->dev, sizeof(struct exynos_ohci_hcd),
110 exynos_ohci->dev = &pdev->dev;
112 hcd = usb_create_hcd(&exynos_ohci_hc_driver, &pdev->dev,
113 dev_name(&pdev->dev));
115 dev_err(&pdev->dev, "Unable to create HCD\n");
119 exynos_ohci->hcd = hcd;
120 exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost");
122 if (IS_ERR(exynos_ohci->clk)) {
123 dev_err(&pdev->dev, "Failed to get usbhost clock\n");
124 err = PTR_ERR(exynos_ohci->clk);
128 err = clk_prepare_enable(exynos_ohci->clk);
132 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
134 dev_err(&pdev->dev, "Failed to get I/O memory\n");
139 hcd->rsrc_start = res->start;
140 hcd->rsrc_len = resource_size(res);
141 hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len);
143 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
148 irq = platform_get_irq(pdev, 0);
150 dev_err(&pdev->dev, "Failed to get IRQ\n");
156 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
158 ohci = hcd_to_ohci(hcd);
161 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
163 dev_err(&pdev->dev, "Failed to add USB HCD\n");
167 platform_set_drvdata(pdev, exynos_ohci);
172 clk_disable_unprepare(exynos_ohci->clk);
178 static int exynos_ohci_remove(struct platform_device *pdev)
180 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
181 struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev);
182 struct usb_hcd *hcd = exynos_ohci->hcd;
186 if (pdata && pdata->phy_exit)
187 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
189 clk_disable_unprepare(exynos_ohci->clk);
196 static void exynos_ohci_shutdown(struct platform_device *pdev)
198 struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev);
199 struct usb_hcd *hcd = exynos_ohci->hcd;
201 if (hcd->driver->shutdown)
202 hcd->driver->shutdown(hcd);
206 static int exynos_ohci_suspend(struct device *dev)
208 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev);
209 struct usb_hcd *hcd = exynos_ohci->hcd;
210 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
211 struct platform_device *pdev = to_platform_device(dev);
212 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
217 * Root hub was already suspended. Disable irq emission and
218 * mark HW unaccessible, bail out if RH has been resumed. Use
219 * the spinlock to properly synchronize with possible pending
220 * RH suspend or resume activity.
222 spin_lock_irqsave(&ohci->lock, flags);
223 if (ohci->rh_state != OHCI_RH_SUSPENDED &&
224 ohci->rh_state != OHCI_RH_HALTED) {
229 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
231 if (pdata && pdata->phy_exit)
232 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
234 clk_disable_unprepare(exynos_ohci->clk);
237 spin_unlock_irqrestore(&ohci->lock, flags);
242 static int exynos_ohci_resume(struct device *dev)
244 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev);
245 struct usb_hcd *hcd = exynos_ohci->hcd;
246 struct platform_device *pdev = to_platform_device(dev);
247 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
249 clk_prepare_enable(exynos_ohci->clk);
251 if (pdata && pdata->phy_init)
252 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
254 ohci_resume(hcd, false);
259 #define exynos_ohci_suspend NULL
260 #define exynos_ohci_resume NULL
263 static const struct dev_pm_ops exynos_ohci_pm_ops = {
264 .suspend = exynos_ohci_suspend,
265 .resume = exynos_ohci_resume,
269 static const struct of_device_id exynos_ohci_match[] = {
270 { .compatible = "samsung,exynos-ohci" },
273 MODULE_DEVICE_TABLE(of, exynos_ohci_match);
276 static struct platform_driver exynos_ohci_driver = {
277 .probe = exynos_ohci_probe,
278 .remove = exynos_ohci_remove,
279 .shutdown = exynos_ohci_shutdown,
281 .name = "exynos-ohci",
282 .owner = THIS_MODULE,
283 .pm = &exynos_ohci_pm_ops,
284 .of_match_table = of_match_ptr(exynos_ohci_match),
288 MODULE_ALIAS("platform:exynos-ohci");
289 MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");