blob: 13c179fb2ee2280a2b8ab9abe346d212c2b73149 [file] [log] [blame]
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +09001/*
2 * SAMSUNG S5P USB HOST EHCI Controller
3 *
4 * Copyright (C) 2011 Samsung Electronics Co.Ltd
5 * Author: Jingoo Han <jg1.han@samsung.com>
6 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
7 *
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.
12 *
13 */
14
15#include <linux/clk.h>
16#include <linux/platform_device.h>
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +090017#include <plat/ehci.h>
18#include <plat/usb-phy.h>
19
Jingoo Han88555a62012-03-05 10:40:14 +090020#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)
28
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +090029struct s5p_ehci_hcd {
30 struct device *dev;
31 struct usb_hcd *hcd;
32 struct clk *clk;
33};
34
35static 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),
39
40 .irq = ehci_irq,
41 .flags = HCD_MEMORY | HCD_USB2,
42
Alan Stern1a49e2a2012-07-09 15:55:14 -040043 .reset = ehci_setup,
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +090044 .start = ehci_run,
45 .stop = ehci_stop,
46 .shutdown = ehci_shutdown,
47
48 .get_frame_number = ehci_get_frame,
49
50 .urb_enqueue = ehci_urb_enqueue,
51 .urb_dequeue = ehci_urb_dequeue,
52 .endpoint_disable = ehci_endpoint_disable,
53 .endpoint_reset = ehci_endpoint_reset,
54
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,
59
60 .relinquish_port = ehci_relinquish_port,
61 .port_handed_over = ehci_port_handed_over,
62
63 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
64};
65
Jingoo Han27362d42011-05-09 15:28:39 +090066static int __devinit s5p_ehci_probe(struct platform_device *pdev)
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +090067{
68 struct s5p_ehci_platdata *pdata;
69 struct s5p_ehci_hcd *s5p_ehci;
70 struct usb_hcd *hcd;
71 struct ehci_hcd *ehci;
72 struct resource *res;
73 int irq;
74 int err;
75
76 pdata = pdev->dev.platform_data;
77 if (!pdata) {
78 dev_err(&pdev->dev, "No platform data defined\n");
79 return -EINVAL;
80 }
81
Jingoo Han9cb07562012-06-28 16:29:46 +090082 s5p_ehci = devm_kzalloc(&pdev->dev, sizeof(struct s5p_ehci_hcd),
83 GFP_KERNEL);
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +090084 if (!s5p_ehci)
85 return -ENOMEM;
86
87 s5p_ehci->dev = &pdev->dev;
88
89 hcd = usb_create_hcd(&s5p_ehci_hc_driver, &pdev->dev,
90 dev_name(&pdev->dev));
91 if (!hcd) {
92 dev_err(&pdev->dev, "Unable to create HCD\n");
Jingoo Han9cb07562012-06-28 16:29:46 +090093 return -ENOMEM;
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +090094 }
95
Yulgon Kime5d3d442011-08-18 14:02:45 +090096 s5p_ehci->hcd = hcd;
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +090097 s5p_ehci->clk = clk_get(&pdev->dev, "usbhost");
98
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);
102 goto fail_clk;
103 }
104
105 err = clk_enable(s5p_ehci->clk);
106 if (err)
107 goto fail_clken;
108
109 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
110 if (!res) {
111 dev_err(&pdev->dev, "Failed to get I/O memory\n");
112 err = -ENXIO;
113 goto fail_io;
114 }
115
116 hcd->rsrc_start = res->start;
117 hcd->rsrc_len = resource_size(res);
Jingoo Han9cb07562012-06-28 16:29:46 +0900118 hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len);
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900119 if (!hcd->regs) {
120 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
121 err = -ENOMEM;
122 goto fail_io;
123 }
124
125 irq = platform_get_irq(pdev, 0);
126 if (!irq) {
127 dev_err(&pdev->dev, "Failed to get IRQ\n");
128 err = -ENODEV;
Jingoo Han9cb07562012-06-28 16:29:46 +0900129 goto fail_io;
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900130 }
131
132 if (pdata->phy_init)
133 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
134
135 ehci = hcd_to_ehci(hcd);
136 ehci->caps = hcd->regs;
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900137
Jingoo Han88555a62012-03-05 10:40:14 +0900138 /* DMA burst Enable */
139 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
140
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800141 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900142 if (err) {
143 dev_err(&pdev->dev, "Failed to add USB HCD\n");
Jingoo Han9cb07562012-06-28 16:29:46 +0900144 goto fail_io;
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900145 }
146
147 platform_set_drvdata(pdev, s5p_ehci);
148
149 return 0;
150
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900151fail_io:
152 clk_disable(s5p_ehci->clk);
153fail_clken:
154 clk_put(s5p_ehci->clk);
155fail_clk:
156 usb_put_hcd(hcd);
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900157 return err;
158}
159
Jingoo Han27362d42011-05-09 15:28:39 +0900160static int __devexit s5p_ehci_remove(struct platform_device *pdev)
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900161{
162 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
163 struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
164 struct usb_hcd *hcd = s5p_ehci->hcd;
165
166 usb_remove_hcd(hcd);
167
168 if (pdata && pdata->phy_exit)
169 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
170
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900171 clk_disable(s5p_ehci->clk);
172 clk_put(s5p_ehci->clk);
173
174 usb_put_hcd(hcd);
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900175
176 return 0;
177}
178
179static void s5p_ehci_shutdown(struct platform_device *pdev)
180{
181 struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
182 struct usb_hcd *hcd = s5p_ehci->hcd;
183
184 if (hcd->driver->shutdown)
185 hcd->driver->shutdown(hcd);
186}
187
Jingoo Han1acb30e2011-05-20 20:48:33 +0900188#ifdef CONFIG_PM
189static int s5p_ehci_suspend(struct device *dev)
190{
191 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
192 struct usb_hcd *hcd = s5p_ehci->hcd;
Alan Sternc5cf9212012-06-28 11:19:02 -0400193 bool do_wakeup = device_may_wakeup(dev);
Jingoo Han1acb30e2011-05-20 20:48:33 +0900194 struct platform_device *pdev = to_platform_device(dev);
195 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
Alan Sternc5cf9212012-06-28 11:19:02 -0400196 int rc;
Jingoo Han1acb30e2011-05-20 20:48:33 +0900197
Alan Sternc5cf9212012-06-28 11:19:02 -0400198 rc = ehci_suspend(hcd, do_wakeup);
Jingoo Han1acb30e2011-05-20 20:48:33 +0900199
200 if (pdata && pdata->phy_exit)
201 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
202
Jingoo Han8b4fc8c2012-04-13 11:06:36 +0900203 clk_disable(s5p_ehci->clk);
204
Jingoo Han1acb30e2011-05-20 20:48:33 +0900205 return rc;
206}
207
208static int s5p_ehci_resume(struct device *dev)
209{
210 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
211 struct usb_hcd *hcd = s5p_ehci->hcd;
Jingoo Han1acb30e2011-05-20 20:48:33 +0900212 struct platform_device *pdev = to_platform_device(dev);
213 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
214
Jingoo Han8b4fc8c2012-04-13 11:06:36 +0900215 clk_enable(s5p_ehci->clk);
216
Jingoo Han1acb30e2011-05-20 20:48:33 +0900217 if (pdata && pdata->phy_init)
218 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
219
Jingoo Han88555a62012-03-05 10:40:14 +0900220 /* DMA burst Enable */
221 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
222
Alan Sternc5cf9212012-06-28 11:19:02 -0400223 ehci_resume(hcd, false);
Jingoo Han1acb30e2011-05-20 20:48:33 +0900224 return 0;
225}
226#else
227#define s5p_ehci_suspend NULL
228#define s5p_ehci_resume NULL
229#endif
230
231static const struct dev_pm_ops s5p_ehci_pm_ops = {
232 .suspend = s5p_ehci_suspend,
233 .resume = s5p_ehci_resume,
234};
235
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900236static struct platform_driver s5p_ehci_driver = {
237 .probe = s5p_ehci_probe,
Jingoo Han27362d42011-05-09 15:28:39 +0900238 .remove = __devexit_p(s5p_ehci_remove),
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900239 .shutdown = s5p_ehci_shutdown,
240 .driver = {
241 .name = "s5p-ehci",
242 .owner = THIS_MODULE,
Jingoo Han1acb30e2011-05-20 20:48:33 +0900243 .pm = &s5p_ehci_pm_ops,
Joonyoung Shim1bcc5aa2011-04-08 14:08:50 +0900244 }
245};
246
247MODULE_ALIAS("platform:s5p-ehci");