2 * SAMSUNG S5P USB HOST EHCI Controller
4 * Copyright (C) 2011 Samsung Electronics Co.Ltd
5 * Author: Jingoo Han <jg1.han@samsung.com>
6 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
15 #include <linux/clk.h>
16 #include <linux/platform_device.h>
17 #include <plat/ehci.h>
18 #include <plat/usb-phy.h>
20 #define EHCI_INSNREG00(base) (base + 0x90)
21 #define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25)
22 #define EHCI_INSNREG00_ENA_INCR8 (0x1 << 24)
23 #define EHCI_INSNREG00_ENA_INCR4 (0x1 << 23)
24 #define EHCI_INSNREG00_ENA_INCRX_ALIGN (0x1 << 22)
25 #define EHCI_INSNREG00_ENABLE_DMA_BURST \
26 (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \
27 EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN)
35 static const struct hc_driver s5p_ehci_hc_driver = {
36 .description = hcd_name,
37 .product_desc = "S5P EHCI Host Controller",
38 .hcd_priv_size = sizeof(struct ehci_hcd),
41 .flags = HCD_MEMORY | HCD_USB2,
46 .shutdown = ehci_shutdown,
48 .get_frame_number = ehci_get_frame,
50 .urb_enqueue = ehci_urb_enqueue,
51 .urb_dequeue = ehci_urb_dequeue,
52 .endpoint_disable = ehci_endpoint_disable,
53 .endpoint_reset = ehci_endpoint_reset,
55 .hub_status_data = ehci_hub_status_data,
56 .hub_control = ehci_hub_control,
57 .bus_suspend = ehci_bus_suspend,
58 .bus_resume = ehci_bus_resume,
60 .relinquish_port = ehci_relinquish_port,
61 .port_handed_over = ehci_port_handed_over,
63 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
66 static int __devinit s5p_ehci_probe(struct platform_device *pdev)
68 struct s5p_ehci_platdata *pdata;
69 struct s5p_ehci_hcd *s5p_ehci;
71 struct ehci_hcd *ehci;
76 pdata = pdev->dev.platform_data;
78 dev_err(&pdev->dev, "No platform data defined\n");
82 s5p_ehci = kzalloc(sizeof(struct s5p_ehci_hcd), GFP_KERNEL);
86 s5p_ehci->dev = &pdev->dev;
88 hcd = usb_create_hcd(&s5p_ehci_hc_driver, &pdev->dev,
89 dev_name(&pdev->dev));
91 dev_err(&pdev->dev, "Unable to create HCD\n");
97 s5p_ehci->clk = clk_get(&pdev->dev, "usbhost");
99 if (IS_ERR(s5p_ehci->clk)) {
100 dev_err(&pdev->dev, "Failed to get usbhost clock\n");
101 err = PTR_ERR(s5p_ehci->clk);
105 err = clk_enable(s5p_ehci->clk);
109 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
111 dev_err(&pdev->dev, "Failed to get I/O memory\n");
116 hcd->rsrc_start = res->start;
117 hcd->rsrc_len = resource_size(res);
118 hcd->regs = ioremap(res->start, resource_size(res));
120 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
125 irq = platform_get_irq(pdev, 0);
127 dev_err(&pdev->dev, "Failed to get IRQ\n");
133 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
135 ehci = hcd_to_ehci(hcd);
136 ehci->caps = hcd->regs;
137 ehci->regs = hcd->regs +
138 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
140 /* DMA burst Enable */
141 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
143 dbg_hcs_params(ehci, "reset");
144 dbg_hcc_params(ehci, "reset");
146 /* cache this readonly data; minimize chip reads */
147 ehci->hcs_params = readl(&ehci->caps->hcs_params);
151 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
153 dev_err(&pdev->dev, "Failed to add USB HCD\n");
157 platform_set_drvdata(pdev, s5p_ehci);
164 clk_disable(s5p_ehci->clk);
166 clk_put(s5p_ehci->clk);
174 static int __devexit s5p_ehci_remove(struct platform_device *pdev)
176 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
177 struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
178 struct usb_hcd *hcd = s5p_ehci->hcd;
182 if (pdata && pdata->phy_exit)
183 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
187 clk_disable(s5p_ehci->clk);
188 clk_put(s5p_ehci->clk);
196 static void s5p_ehci_shutdown(struct platform_device *pdev)
198 struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
199 struct usb_hcd *hcd = s5p_ehci->hcd;
201 if (hcd->driver->shutdown)
202 hcd->driver->shutdown(hcd);
206 static int s5p_ehci_suspend(struct device *dev)
208 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
209 struct usb_hcd *hcd = s5p_ehci->hcd;
210 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
211 struct platform_device *pdev = to_platform_device(dev);
212 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
216 if (time_before(jiffies, ehci->next_statechange))
220 * Root hub was already suspended. Disable irq emission and
221 * mark HW unaccessible. The PM and USB cores make sure that
222 * the root hub is either suspended or stopped.
224 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
225 spin_lock_irqsave(&ehci->lock, flags);
226 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
227 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
229 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
230 spin_unlock_irqrestore(&ehci->lock, flags);
232 if (pdata && pdata->phy_exit)
233 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
235 clk_disable(s5p_ehci->clk);
240 static int s5p_ehci_resume(struct device *dev)
242 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
243 struct usb_hcd *hcd = s5p_ehci->hcd;
244 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
245 struct platform_device *pdev = to_platform_device(dev);
246 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
248 clk_enable(s5p_ehci->clk);
250 if (pdata && pdata->phy_init)
251 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
253 /* DMA burst Enable */
254 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
256 if (time_before(jiffies, ehci->next_statechange))
259 /* Mark hardware accessible again as we are out of D3 state by now */
260 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
262 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
263 int mask = INTR_MASK;
265 ehci_prepare_ports_for_controller_resume(ehci);
266 if (!hcd->self.root_hub->do_remote_wakeup)
268 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
269 ehci_readl(ehci, &ehci->regs->intr_enable);
273 usb_root_hub_lost_power(hcd->self.root_hub);
275 (void) ehci_halt(ehci);
276 (void) ehci_reset(ehci);
278 /* emptying the schedule aborts any urbs */
279 spin_lock_irq(&ehci->lock);
281 end_unlink_async(ehci);
283 spin_unlock_irq(&ehci->lock);
285 ehci_writel(ehci, ehci->command, &ehci->regs->command);
286 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
287 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
289 /* here we "know" root ports should always stay powered */
290 ehci_port_power(ehci, 1);
292 ehci->rh_state = EHCI_RH_SUSPENDED;
297 #define s5p_ehci_suspend NULL
298 #define s5p_ehci_resume NULL
301 static const struct dev_pm_ops s5p_ehci_pm_ops = {
302 .suspend = s5p_ehci_suspend,
303 .resume = s5p_ehci_resume,
306 static struct platform_driver s5p_ehci_driver = {
307 .probe = s5p_ehci_probe,
308 .remove = __devexit_p(s5p_ehci_remove),
309 .shutdown = s5p_ehci_shutdown,
312 .owner = THIS_MODULE,
313 .pm = &s5p_ehci_pm_ops,
317 MODULE_ALIAS("platform:s5p-ehci");