2 * Driver for EHCI HCD on SPEAR SOC
4 * Copyright (C) 2010 ST Micro Electronics,
5 * Deepak Sikri <deepak.sikri@st.com>
7 * Based on various ehci-*.c drivers
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive for
14 #include <linux/clk.h>
15 #include <linux/jiffies.h>
16 #include <linux/platform_device.h>
24 #define to_spear_ehci(hcd) (struct spear_ehci *)hcd_to_ehci(hcd)
26 static void spear_start_ehci(struct spear_ehci *ehci)
28 clk_enable(ehci->clk);
31 static void spear_stop_ehci(struct spear_ehci *ehci)
33 clk_disable(ehci->clk);
36 static int ehci_spear_setup(struct usb_hcd *hcd)
38 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
41 /* registers start at offset 0x0 */
42 ehci->caps = hcd->regs;
43 ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
44 &ehci->caps->hc_capbase));
45 /* cache this readonly data; minimize chip reads */
46 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
47 retval = ehci_halt(ehci);
51 retval = ehci_init(hcd);
56 ehci_port_power(ehci, 0);
61 static const struct hc_driver ehci_spear_hc_driver = {
62 .description = hcd_name,
63 .product_desc = "SPEAr EHCI",
64 .hcd_priv_size = sizeof(struct spear_ehci),
66 /* generic hardware linkage */
68 .flags = HCD_MEMORY | HCD_USB2,
70 /* basic lifecycle operations */
71 .reset = ehci_spear_setup,
74 .shutdown = ehci_shutdown,
76 /* managing i/o requests and associated device resources */
77 .urb_enqueue = ehci_urb_enqueue,
78 .urb_dequeue = ehci_urb_dequeue,
79 .endpoint_disable = ehci_endpoint_disable,
80 .endpoint_reset = ehci_endpoint_reset,
82 /* scheduling support */
83 .get_frame_number = ehci_get_frame,
85 /* root hub support */
86 .hub_status_data = ehci_hub_status_data,
87 .hub_control = ehci_hub_control,
88 .bus_suspend = ehci_bus_suspend,
89 .bus_resume = ehci_bus_resume,
90 .relinquish_port = ehci_relinquish_port,
91 .port_handed_over = ehci_port_handed_over,
92 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
96 static int ehci_spear_drv_suspend(struct device *dev)
98 struct usb_hcd *hcd = dev_get_drvdata(dev);
99 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
103 if (time_before(jiffies, ehci->next_statechange))
107 * Root hub was already suspended. Disable irq emission and mark HW
108 * unaccessible. The PM and USB cores make sure that the root hub is
109 * either suspended or stopped.
111 spin_lock_irqsave(&ehci->lock, flags);
112 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
113 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
114 ehci_readl(ehci, &ehci->regs->intr_enable);
115 spin_unlock_irqrestore(&ehci->lock, flags);
120 static int ehci_spear_drv_resume(struct device *dev)
122 struct usb_hcd *hcd = dev_get_drvdata(dev);
123 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
125 if (time_before(jiffies, ehci->next_statechange))
128 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
129 int mask = INTR_MASK;
131 ehci_prepare_ports_for_controller_resume(ehci);
133 if (!hcd->self.root_hub->do_remote_wakeup)
136 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
137 ehci_readl(ehci, &ehci->regs->intr_enable);
141 usb_root_hub_lost_power(hcd->self.root_hub);
144 * Else reset, to cope with power loss or flush-to-storage style
145 * "resume" having let BIOS kick in during reboot.
150 /* emptying the schedule aborts any urbs */
151 spin_lock_irq(&ehci->lock);
153 end_unlink_async(ehci);
156 spin_unlock_irq(&ehci->lock);
158 ehci_writel(ehci, ehci->command, &ehci->regs->command);
159 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
160 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
162 /* here we "know" root ports should always stay powered */
163 ehci_port_power(ehci, 1);
166 #endif /* CONFIG_PM */
168 static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend,
169 ehci_spear_drv_resume);
171 static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
173 struct usb_hcd *hcd ;
174 struct spear_ehci *ehci;
175 struct resource *res;
176 struct clk *usbh_clk;
177 const struct hc_driver *driver = &ehci_spear_hc_driver;
178 int *pdata = pdev->dev.platform_data;
180 char clk_name[20] = "usbh_clk";
188 irq = platform_get_irq(pdev, 0);
195 sprintf(clk_name, "usbh.%01d_clk", *pdata);
197 usbh_clk = clk_get(NULL, clk_name);
198 if (IS_ERR(usbh_clk)) {
199 dev_err(&pdev->dev, "Error getting interface clock\n");
200 retval = PTR_ERR(usbh_clk);
201 goto fail_get_usbh_clk;
204 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
207 goto fail_create_hcd;
210 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
213 goto fail_request_resource;
216 hcd->rsrc_start = res->start;
217 hcd->rsrc_len = resource_size(res);
218 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
219 driver->description)) {
221 goto fail_request_resource;
224 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
225 if (hcd->regs == NULL) {
226 dev_dbg(&pdev->dev, "error mapping memory\n");
231 ehci = (struct spear_ehci *)hcd_to_ehci(hcd);
232 ehci->clk = usbh_clk;
234 spear_start_ehci(ehci);
235 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
242 spear_stop_ehci(ehci);
245 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
246 fail_request_resource:
252 dev_err(&pdev->dev, "init fail, %d\n", retval);
257 static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
259 struct usb_hcd *hcd = platform_get_drvdata(pdev);
260 struct spear_ehci *ehci_p = to_spear_ehci(hcd);
269 spear_stop_ehci(ehci_p);
271 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
275 clk_put(ehci_p->clk);
280 static struct platform_driver spear_ehci_hcd_driver = {
281 .probe = spear_ehci_hcd_drv_probe,
282 .remove = spear_ehci_hcd_drv_remove,
283 .shutdown = usb_hcd_platform_shutdown,
285 .name = "spear-ehci",
286 .bus = &platform_bus_type,
287 .pm = &ehci_spear_pm_ops,
291 MODULE_ALIAS("platform:spear-ehci");