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-ohci-exynos.h>
18 #include <linux/usb/phy.h>
19 #include <linux/usb/samsung_usb_phy.h>
21 struct exynos_ohci_hcd {
27 struct exynos4_ohci_platdata *pdata;
30 static void exynos_ohci_phy_enable(struct exynos_ohci_hcd *exynos_ohci)
32 struct platform_device *pdev = to_platform_device(exynos_ohci->dev);
35 usb_phy_init(exynos_ohci->phy);
36 else if (exynos_ohci->pdata && exynos_ohci->pdata->phy_init)
37 exynos_ohci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
40 static void exynos_ohci_phy_disable(struct exynos_ohci_hcd *exynos_ohci)
42 struct platform_device *pdev = to_platform_device(exynos_ohci->dev);
45 usb_phy_shutdown(exynos_ohci->phy);
46 else if (exynos_ohci->pdata && exynos_ohci->pdata->phy_exit)
47 exynos_ohci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
50 static int ohci_exynos_reset(struct usb_hcd *hcd)
52 return ohci_init(hcd_to_ohci(hcd));
55 static int ohci_exynos_start(struct usb_hcd *hcd)
57 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
60 ohci_dbg(ohci, "ohci_exynos_start, ohci:%p", ohci);
64 dev_err(hcd->self.controller, "can't start %s\n",
73 static const struct hc_driver exynos_ohci_hc_driver = {
74 .description = hcd_name,
75 .product_desc = "EXYNOS OHCI Host Controller",
76 .hcd_priv_size = sizeof(struct ohci_hcd),
79 .flags = HCD_MEMORY|HCD_USB11,
81 .reset = ohci_exynos_reset,
82 .start = ohci_exynos_start,
84 .shutdown = ohci_shutdown,
86 .get_frame_number = ohci_get_frame,
88 .urb_enqueue = ohci_urb_enqueue,
89 .urb_dequeue = ohci_urb_dequeue,
90 .endpoint_disable = ohci_endpoint_disable,
92 .hub_status_data = ohci_hub_status_data,
93 .hub_control = ohci_hub_control,
95 .bus_suspend = ohci_bus_suspend,
96 .bus_resume = ohci_bus_resume,
98 .start_port_reset = ohci_start_port_reset,
101 static int exynos_ohci_probe(struct platform_device *pdev)
103 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
104 struct exynos_ohci_hcd *exynos_ohci;
106 struct ohci_hcd *ohci;
107 struct resource *res;
113 * Right now device-tree probed devices don't get dma_mask set.
114 * Since shared usb code relies on it, set it here for now.
115 * Once we move to full device tree support this will vanish off.
117 if (!pdev->dev.dma_mask)
118 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
119 if (!pdev->dev.coherent_dma_mask)
120 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
122 exynos_ohci = devm_kzalloc(&pdev->dev, sizeof(struct exynos_ohci_hcd),
127 if (of_device_is_compatible(pdev->dev.of_node,
128 "samsung,exynos5440-ohci"))
131 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
133 /* Fallback to pdata */
135 dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
136 return -EPROBE_DEFER;
138 exynos_ohci->pdata = pdata;
141 exynos_ohci->phy = phy;
142 exynos_ohci->otg = phy->otg;
147 exynos_ohci->dev = &pdev->dev;
149 hcd = usb_create_hcd(&exynos_ohci_hc_driver, &pdev->dev,
150 dev_name(&pdev->dev));
152 dev_err(&pdev->dev, "Unable to create HCD\n");
156 exynos_ohci->hcd = hcd;
157 exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost");
159 if (IS_ERR(exynos_ohci->clk)) {
160 dev_err(&pdev->dev, "Failed to get usbhost clock\n");
161 err = PTR_ERR(exynos_ohci->clk);
165 err = clk_prepare_enable(exynos_ohci->clk);
169 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
171 dev_err(&pdev->dev, "Failed to get I/O memory\n");
176 hcd->rsrc_start = res->start;
177 hcd->rsrc_len = resource_size(res);
178 hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len);
180 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
185 irq = platform_get_irq(pdev, 0);
187 dev_err(&pdev->dev, "Failed to get IRQ\n");
192 if (exynos_ohci->otg)
193 exynos_ohci->otg->set_host(exynos_ohci->otg,
194 &exynos_ohci->hcd->self);
196 exynos_ohci_phy_enable(exynos_ohci);
198 ohci = hcd_to_ohci(hcd);
201 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
203 dev_err(&pdev->dev, "Failed to add USB HCD\n");
207 platform_set_drvdata(pdev, exynos_ohci);
212 exynos_ohci_phy_disable(exynos_ohci);
214 clk_disable_unprepare(exynos_ohci->clk);
220 static int exynos_ohci_remove(struct platform_device *pdev)
222 struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev);
223 struct usb_hcd *hcd = exynos_ohci->hcd;
227 if (exynos_ohci->otg)
228 exynos_ohci->otg->set_host(exynos_ohci->otg,
229 &exynos_ohci->hcd->self);
231 exynos_ohci_phy_disable(exynos_ohci);
233 clk_disable_unprepare(exynos_ohci->clk);
240 static void exynos_ohci_shutdown(struct platform_device *pdev)
242 struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev);
243 struct usb_hcd *hcd = exynos_ohci->hcd;
245 if (hcd->driver->shutdown)
246 hcd->driver->shutdown(hcd);
250 static int exynos_ohci_suspend(struct device *dev)
252 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev);
253 struct usb_hcd *hcd = exynos_ohci->hcd;
254 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
259 * Root hub was already suspended. Disable irq emission and
260 * mark HW unaccessible, bail out if RH has been resumed. Use
261 * the spinlock to properly synchronize with possible pending
262 * RH suspend or resume activity.
264 spin_lock_irqsave(&ohci->lock, flags);
265 if (ohci->rh_state != OHCI_RH_SUSPENDED &&
266 ohci->rh_state != OHCI_RH_HALTED) {
271 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
273 if (exynos_ohci->otg)
274 exynos_ohci->otg->set_host(exynos_ohci->otg,
275 &exynos_ohci->hcd->self);
277 exynos_ohci_phy_disable(exynos_ohci);
279 clk_disable_unprepare(exynos_ohci->clk);
282 spin_unlock_irqrestore(&ohci->lock, flags);
287 static int exynos_ohci_resume(struct device *dev)
289 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev);
290 struct usb_hcd *hcd = exynos_ohci->hcd;
292 clk_prepare_enable(exynos_ohci->clk);
294 if (exynos_ohci->otg)
295 exynos_ohci->otg->set_host(exynos_ohci->otg,
296 &exynos_ohci->hcd->self);
298 exynos_ohci_phy_enable(exynos_ohci);
300 ohci_resume(hcd, false);
305 #define exynos_ohci_suspend NULL
306 #define exynos_ohci_resume NULL
309 static const struct dev_pm_ops exynos_ohci_pm_ops = {
310 .suspend = exynos_ohci_suspend,
311 .resume = exynos_ohci_resume,
315 static const struct of_device_id exynos_ohci_match[] = {
316 { .compatible = "samsung,exynos4210-ohci" },
317 { .compatible = "samsung,exynos5440-ohci" },
320 MODULE_DEVICE_TABLE(of, exynos_ohci_match);
323 static struct platform_driver exynos_ohci_driver = {
324 .probe = exynos_ohci_probe,
325 .remove = exynos_ohci_remove,
326 .shutdown = exynos_ohci_shutdown,
328 .name = "exynos-ohci",
329 .owner = THIS_MODULE,
330 .pm = &exynos_ohci_pm_ops,
331 .of_match_table = of_match_ptr(exynos_ohci_match),
335 MODULE_ALIAS("platform:exynos-ohci");
336 MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");