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>
17 #include <linux/platform_device.h>
18 #include <plat/ehci.h>
19 #include <plat/usb-phy.h>
21 #define EHCI_INSNREG00(base) (base + 0x90)
22 #define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25)
23 #define EHCI_INSNREG00_ENA_INCR8 (0x1 << 24)
24 #define EHCI_INSNREG00_ENA_INCR4 (0x1 << 23)
25 #define EHCI_INSNREG00_ENA_INCRX_ALIGN (0x1 << 22)
26 #define EHCI_INSNREG00_ENABLE_DMA_BURST \
27 (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \
28 EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN)
36 static const struct hc_driver s5p_ehci_hc_driver
= {
37 .description
= hcd_name
,
38 .product_desc
= "S5P EHCI Host Controller",
39 .hcd_priv_size
= sizeof(struct ehci_hcd
),
42 .flags
= HCD_MEMORY
| HCD_USB2
,
47 .shutdown
= ehci_shutdown
,
49 .get_frame_number
= ehci_get_frame
,
51 .urb_enqueue
= ehci_urb_enqueue
,
52 .urb_dequeue
= ehci_urb_dequeue
,
53 .endpoint_disable
= ehci_endpoint_disable
,
54 .endpoint_reset
= ehci_endpoint_reset
,
56 .hub_status_data
= ehci_hub_status_data
,
57 .hub_control
= ehci_hub_control
,
58 .bus_suspend
= ehci_bus_suspend
,
59 .bus_resume
= ehci_bus_resume
,
61 .relinquish_port
= ehci_relinquish_port
,
62 .port_handed_over
= ehci_port_handed_over
,
64 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
67 static u64 ehci_s5p_dma_mask
= DMA_BIT_MASK(32);
69 static int __devinit
s5p_ehci_probe(struct platform_device
*pdev
)
71 struct s5p_ehci_platdata
*pdata
;
72 struct s5p_ehci_hcd
*s5p_ehci
;
74 struct ehci_hcd
*ehci
;
79 pdata
= pdev
->dev
.platform_data
;
81 dev_err(&pdev
->dev
, "No platform data defined\n");
86 * Right now device-tree probed devices don't get dma_mask set.
87 * Since shared usb code relies on it, set it here for now.
88 * Once we move to full device tree support this will vanish off.
90 if (!pdev
->dev
.dma_mask
)
91 pdev
->dev
.dma_mask
= &ehci_s5p_dma_mask
;
92 if (!pdev
->dev
.coherent_dma_mask
)
93 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
95 s5p_ehci
= devm_kzalloc(&pdev
->dev
, sizeof(struct s5p_ehci_hcd
),
100 s5p_ehci
->dev
= &pdev
->dev
;
102 hcd
= usb_create_hcd(&s5p_ehci_hc_driver
, &pdev
->dev
,
103 dev_name(&pdev
->dev
));
105 dev_err(&pdev
->dev
, "Unable to create HCD\n");
110 s5p_ehci
->clk
= clk_get(&pdev
->dev
, "usbhost");
112 if (IS_ERR(s5p_ehci
->clk
)) {
113 dev_err(&pdev
->dev
, "Failed to get usbhost clock\n");
114 err
= PTR_ERR(s5p_ehci
->clk
);
118 err
= clk_enable(s5p_ehci
->clk
);
122 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
124 dev_err(&pdev
->dev
, "Failed to get I/O memory\n");
129 hcd
->rsrc_start
= res
->start
;
130 hcd
->rsrc_len
= resource_size(res
);
131 hcd
->regs
= devm_ioremap(&pdev
->dev
, res
->start
, hcd
->rsrc_len
);
133 dev_err(&pdev
->dev
, "Failed to remap I/O memory\n");
138 irq
= platform_get_irq(pdev
, 0);
140 dev_err(&pdev
->dev
, "Failed to get IRQ\n");
146 pdata
->phy_init(pdev
, S5P_USB_PHY_HOST
);
148 ehci
= hcd_to_ehci(hcd
);
149 ehci
->caps
= hcd
->regs
;
151 /* DMA burst Enable */
152 writel(EHCI_INSNREG00_ENABLE_DMA_BURST
, EHCI_INSNREG00(hcd
->regs
));
154 err
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
156 dev_err(&pdev
->dev
, "Failed to add USB HCD\n");
160 platform_set_drvdata(pdev
, s5p_ehci
);
165 clk_disable(s5p_ehci
->clk
);
167 clk_put(s5p_ehci
->clk
);
173 static int __devexit
s5p_ehci_remove(struct platform_device
*pdev
)
175 struct s5p_ehci_platdata
*pdata
= pdev
->dev
.platform_data
;
176 struct s5p_ehci_hcd
*s5p_ehci
= platform_get_drvdata(pdev
);
177 struct usb_hcd
*hcd
= s5p_ehci
->hcd
;
181 if (pdata
&& pdata
->phy_exit
)
182 pdata
->phy_exit(pdev
, S5P_USB_PHY_HOST
);
184 clk_disable(s5p_ehci
->clk
);
185 clk_put(s5p_ehci
->clk
);
192 static void s5p_ehci_shutdown(struct platform_device
*pdev
)
194 struct s5p_ehci_hcd
*s5p_ehci
= platform_get_drvdata(pdev
);
195 struct usb_hcd
*hcd
= s5p_ehci
->hcd
;
197 if (hcd
->driver
->shutdown
)
198 hcd
->driver
->shutdown(hcd
);
202 static int s5p_ehci_suspend(struct device
*dev
)
204 struct s5p_ehci_hcd
*s5p_ehci
= dev_get_drvdata(dev
);
205 struct usb_hcd
*hcd
= s5p_ehci
->hcd
;
206 bool do_wakeup
= device_may_wakeup(dev
);
207 struct platform_device
*pdev
= to_platform_device(dev
);
208 struct s5p_ehci_platdata
*pdata
= pdev
->dev
.platform_data
;
211 rc
= ehci_suspend(hcd
, do_wakeup
);
213 if (pdata
&& pdata
->phy_exit
)
214 pdata
->phy_exit(pdev
, S5P_USB_PHY_HOST
);
216 clk_disable(s5p_ehci
->clk
);
221 static int s5p_ehci_resume(struct device
*dev
)
223 struct s5p_ehci_hcd
*s5p_ehci
= dev_get_drvdata(dev
);
224 struct usb_hcd
*hcd
= s5p_ehci
->hcd
;
225 struct platform_device
*pdev
= to_platform_device(dev
);
226 struct s5p_ehci_platdata
*pdata
= pdev
->dev
.platform_data
;
228 clk_enable(s5p_ehci
->clk
);
230 if (pdata
&& pdata
->phy_init
)
231 pdata
->phy_init(pdev
, S5P_USB_PHY_HOST
);
233 /* DMA burst Enable */
234 writel(EHCI_INSNREG00_ENABLE_DMA_BURST
, EHCI_INSNREG00(hcd
->regs
));
236 ehci_resume(hcd
, false);
240 #define s5p_ehci_suspend NULL
241 #define s5p_ehci_resume NULL
244 static const struct dev_pm_ops s5p_ehci_pm_ops
= {
245 .suspend
= s5p_ehci_suspend
,
246 .resume
= s5p_ehci_resume
,
250 static const struct of_device_id exynos_ehci_match
[] = {
251 { .compatible
= "samsung,exynos-ehci" },
254 MODULE_DEVICE_TABLE(of
, exynos_ehci_match
);
257 static struct platform_driver s5p_ehci_driver
= {
258 .probe
= s5p_ehci_probe
,
259 .remove
= __devexit_p(s5p_ehci_remove
),
260 .shutdown
= s5p_ehci_shutdown
,
263 .owner
= THIS_MODULE
,
264 .pm
= &s5p_ehci_pm_ops
,
265 .of_match_table
= of_match_ptr(exynos_ehci_match
),
269 MODULE_ALIAS("platform:s5p-ehci");