1 // SPDX-License-Identifier: GPL-2.0
3 * OHCI HCD (Host Controller Driver) for USB.
5 * Copyright (C) 2010 ST Microelectronics.
6 * Deepak Sikri<deepak.sikri@st.com>
8 * Based on various ohci-*.c drivers
10 * This file is licensed under the terms of the GNU General Public
11 * License version 2. This program is licensed "as is" without any
12 * warranty of any kind, whether express or implied.
15 #include <linux/clk.h>
16 #include <linux/dma-mapping.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 #include <linux/signal.h>
23 #include <linux/usb.h>
24 #include <linux/usb/hcd.h>
28 #define DRIVER_DESC "OHCI SPEAr driver"
30 static const char hcd_name[] = "SPEAr-ohci";
35 #define to_spear_ohci(hcd) (struct spear_ohci *)(hcd_to_ohci(hcd)->priv)
37 static struct hc_driver __read_mostly ohci_spear_hc_driver;
39 static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
41 const struct hc_driver *driver = &ohci_spear_hc_driver;
42 struct ohci_hcd *ohci;
43 struct usb_hcd *hcd = NULL;
45 struct spear_ohci *sohci_p;
49 irq = platform_get_irq(pdev, 0);
56 * Right now device-tree probed devices don't get dma_mask set.
57 * Since shared usb code relies on it, set it here for now.
58 * Once we have dma capability bindings this can go away.
60 retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
64 usbh_clk = devm_clk_get(&pdev->dev, NULL);
65 if (IS_ERR(usbh_clk)) {
66 dev_err(&pdev->dev, "Error getting interface clock\n");
67 retval = PTR_ERR(usbh_clk);
71 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
77 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
78 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
79 if (IS_ERR(hcd->regs)) {
80 retval = PTR_ERR(hcd->regs);
84 hcd->rsrc_start = pdev->resource[0].start;
85 hcd->rsrc_len = resource_size(res);
87 sohci_p = to_spear_ohci(hcd);
88 sohci_p->clk = usbh_clk;
90 clk_prepare_enable(sohci_p->clk);
92 ohci = hcd_to_ohci(hcd);
94 retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0);
96 device_wakeup_enable(hcd->self.controller);
100 clk_disable_unprepare(sohci_p->clk);
104 dev_err(&pdev->dev, "init fail, %d\n", retval);
109 static int spear_ohci_hcd_drv_remove(struct platform_device *pdev)
111 struct usb_hcd *hcd = platform_get_drvdata(pdev);
112 struct spear_ohci *sohci_p = to_spear_ohci(hcd);
116 clk_disable_unprepare(sohci_p->clk);
122 #if defined(CONFIG_PM)
123 static int spear_ohci_hcd_drv_suspend(struct platform_device *pdev,
124 pm_message_t message)
126 struct usb_hcd *hcd = platform_get_drvdata(pdev);
127 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
128 struct spear_ohci *sohci_p = to_spear_ohci(hcd);
129 bool do_wakeup = device_may_wakeup(&pdev->dev);
132 if (time_before(jiffies, ohci->next_statechange))
134 ohci->next_statechange = jiffies;
136 ret = ohci_suspend(hcd, do_wakeup);
140 clk_disable_unprepare(sohci_p->clk);
145 static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
147 struct usb_hcd *hcd = platform_get_drvdata(dev);
148 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
149 struct spear_ohci *sohci_p = to_spear_ohci(hcd);
151 if (time_before(jiffies, ohci->next_statechange))
153 ohci->next_statechange = jiffies;
155 clk_prepare_enable(sohci_p->clk);
156 ohci_resume(hcd, false);
161 static const struct of_device_id spear_ohci_id_table[] = {
162 { .compatible = "st,spear600-ohci", },
165 MODULE_DEVICE_TABLE(of, spear_ohci_id_table);
167 /* Driver definition to register with the platform bus */
168 static struct platform_driver spear_ohci_hcd_driver = {
169 .probe = spear_ohci_hcd_drv_probe,
170 .remove = spear_ohci_hcd_drv_remove,
172 .suspend = spear_ohci_hcd_drv_suspend,
173 .resume = spear_ohci_hcd_drv_resume,
176 .name = "spear-ohci",
177 .of_match_table = spear_ohci_id_table,
181 static const struct ohci_driver_overrides spear_overrides __initconst = {
182 .extra_priv_size = sizeof(struct spear_ohci),
184 static int __init ohci_spear_init(void)
189 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
191 ohci_init_driver(&ohci_spear_hc_driver, &spear_overrides);
192 return platform_driver_register(&spear_ohci_hcd_driver);
194 module_init(ohci_spear_init);
196 static void __exit ohci_spear_cleanup(void)
198 platform_driver_unregister(&spear_ohci_hcd_driver);
200 module_exit(ohci_spear_cleanup);
202 MODULE_DESCRIPTION(DRIVER_DESC);
203 MODULE_AUTHOR("Deepak Sikri");
204 MODULE_LICENSE("GPL v2");
205 MODULE_ALIAS("platform:spear-ohci");