]>
Commit | Line | Data |
---|---|---|
7e8d5cd9 DM |
1 | /* |
2 | * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix | |
3 | * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the | |
7 | * Free Software Foundation; either version 2 of the License, or (at your | |
8 | * option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 | * for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software Foundation, | |
17 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 | */ | |
19 | ||
20 | #include <linux/platform_device.h> | |
21 | #include <linux/clk.h> | |
22 | #include <linux/delay.h> | |
23 | #include <linux/usb/otg.h> | |
a464dc4d | 24 | #include <linux/usb/ulpi.h> |
5a0e3ad6 | 25 | #include <linux/slab.h> |
7e8d5cd9 | 26 | |
03a1d6bf | 27 | #include <mach/hardware.h> |
82906b13 | 28 | #include <linux/platform_data/usb-ehci-mxc.h> |
7e8d5cd9 | 29 | |
a464dc4d AP |
30 | #include <asm/mach-types.h> |
31 | ||
7e8d5cd9 | 32 | #define ULPI_VIEWPORT_OFFSET 0x170 |
7e8d5cd9 DM |
33 | |
34 | struct ehci_mxc_priv { | |
c943740c | 35 | struct clk *usbclk, *ahbclk, *phyclk; |
7e8d5cd9 DM |
36 | struct usb_hcd *hcd; |
37 | }; | |
38 | ||
39 | /* called during probe() after chip reset completes */ | |
40 | static int ehci_mxc_setup(struct usb_hcd *hcd) | |
41 | { | |
65fd4272 MC |
42 | hcd->has_tt = 1; |
43 | ||
c73cee71 | 44 | return ehci_setup(hcd); |
7e8d5cd9 DM |
45 | } |
46 | ||
47 | static const struct hc_driver ehci_mxc_hc_driver = { | |
48 | .description = hcd_name, | |
49 | .product_desc = "Freescale On-Chip EHCI Host Controller", | |
50 | .hcd_priv_size = sizeof(struct ehci_hcd), | |
51 | ||
52 | /* | |
53 | * generic hardware linkage | |
54 | */ | |
55 | .irq = ehci_irq, | |
56 | .flags = HCD_USB2 | HCD_MEMORY, | |
57 | ||
58 | /* | |
59 | * basic lifecycle operations | |
60 | */ | |
61 | .reset = ehci_mxc_setup, | |
62 | .start = ehci_run, | |
63 | .stop = ehci_stop, | |
64 | .shutdown = ehci_shutdown, | |
65 | ||
66 | /* | |
67 | * managing i/o requests and associated device resources | |
68 | */ | |
69 | .urb_enqueue = ehci_urb_enqueue, | |
70 | .urb_dequeue = ehci_urb_dequeue, | |
71 | .endpoint_disable = ehci_endpoint_disable, | |
b48d7f50 | 72 | .endpoint_reset = ehci_endpoint_reset, |
7e8d5cd9 DM |
73 | |
74 | /* | |
75 | * scheduling support | |
76 | */ | |
77 | .get_frame_number = ehci_get_frame, | |
78 | ||
79 | /* | |
80 | * root hub support | |
81 | */ | |
82 | .hub_status_data = ehci_hub_status_data, | |
83 | .hub_control = ehci_hub_control, | |
84 | .bus_suspend = ehci_bus_suspend, | |
85 | .bus_resume = ehci_bus_resume, | |
86 | .relinquish_port = ehci_relinquish_port, | |
87 | .port_handed_over = ehci_port_handed_over, | |
b48d7f50 PM |
88 | |
89 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | |
7e8d5cd9 DM |
90 | }; |
91 | ||
92 | static int ehci_mxc_drv_probe(struct platform_device *pdev) | |
93 | { | |
94 | struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data; | |
95 | struct usb_hcd *hcd; | |
96 | struct resource *res; | |
724c8525 | 97 | int irq, ret; |
a464dc4d | 98 | unsigned int flags; |
7e8d5cd9 DM |
99 | struct ehci_mxc_priv *priv; |
100 | struct device *dev = &pdev->dev; | |
0247a7bc | 101 | struct ehci_hcd *ehci; |
7e8d5cd9 DM |
102 | |
103 | dev_info(&pdev->dev, "initializing i.MX USB Controller\n"); | |
104 | ||
105 | if (!pdata) { | |
106 | dev_err(dev, "No platform data given, bailing out.\n"); | |
107 | return -EINVAL; | |
108 | } | |
109 | ||
110 | irq = platform_get_irq(pdev, 0); | |
111 | ||
112 | hcd = usb_create_hcd(&ehci_mxc_hc_driver, dev, dev_name(dev)); | |
113 | if (!hcd) | |
114 | return -ENOMEM; | |
115 | ||
af09c060 | 116 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
7e8d5cd9 DM |
117 | if (!priv) { |
118 | ret = -ENOMEM; | |
119 | goto err_alloc; | |
120 | } | |
121 | ||
122 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
123 | if (!res) { | |
124 | dev_err(dev, "Found HC with no register addr. Check setup!\n"); | |
125 | ret = -ENODEV; | |
af09c060 | 126 | goto err_alloc; |
7e8d5cd9 DM |
127 | } |
128 | ||
129 | hcd->rsrc_start = res->start; | |
130 | hcd->rsrc_len = resource_size(res); | |
131 | ||
af09c060 | 132 | hcd->regs = devm_request_and_ioremap(&pdev->dev, res); |
7e8d5cd9 DM |
133 | if (!hcd->regs) { |
134 | dev_err(dev, "error mapping memory\n"); | |
135 | ret = -EFAULT; | |
af09c060 | 136 | goto err_alloc; |
7e8d5cd9 DM |
137 | } |
138 | ||
139 | /* enable clocks */ | |
af09c060 | 140 | priv->usbclk = devm_clk_get(&pdev->dev, "ipg"); |
7e8d5cd9 DM |
141 | if (IS_ERR(priv->usbclk)) { |
142 | ret = PTR_ERR(priv->usbclk); | |
af09c060 | 143 | goto err_alloc; |
7e8d5cd9 | 144 | } |
198ad2ce | 145 | clk_prepare_enable(priv->usbclk); |
7e8d5cd9 | 146 | |
af09c060 | 147 | priv->ahbclk = devm_clk_get(&pdev->dev, "ahb"); |
c943740c SH |
148 | if (IS_ERR(priv->ahbclk)) { |
149 | ret = PTR_ERR(priv->ahbclk); | |
150 | goto err_clk_ahb; | |
7e8d5cd9 | 151 | } |
c943740c | 152 | clk_prepare_enable(priv->ahbclk); |
7e8d5cd9 | 153 | |
3bb8029a | 154 | /* "dr" device has its own clock on i.MX51 */ |
af09c060 | 155 | priv->phyclk = devm_clk_get(&pdev->dev, "phy"); |
c943740c SH |
156 | if (IS_ERR(priv->phyclk)) |
157 | priv->phyclk = NULL; | |
158 | if (priv->phyclk) | |
159 | clk_prepare_enable(priv->phyclk); | |
711669e5 AP |
160 | |
161 | ||
162 | /* call platform specific init function */ | |
163 | if (pdata->init) { | |
164 | ret = pdata->init(pdev); | |
165 | if (ret) { | |
166 | dev_err(dev, "platform init failed\n"); | |
167 | goto err_init; | |
168 | } | |
169 | /* platforms need some time to settle changed IO settings */ | |
170 | mdelay(10); | |
171 | } | |
172 | ||
0247a7bc FE |
173 | ehci = hcd_to_ehci(hcd); |
174 | ||
175 | /* EHCI registers start at offset 0x100 */ | |
176 | ehci->caps = hcd->regs + 0x100; | |
177 | ehci->regs = hcd->regs + 0x100 + | |
c430131a | 178 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
0247a7bc FE |
179 | |
180 | /* set up the PORTSCx register */ | |
181 | ehci_writel(ehci, pdata->portsc, &ehci->regs->port_status[0]); | |
182 | ||
183 | /* is this really needed? */ | |
184 | msleep(10); | |
185 | ||
7e8d5cd9 DM |
186 | /* Initialize the transceiver */ |
187 | if (pdata->otg) { | |
188 | pdata->otg->io_priv = hcd->regs + ULPI_VIEWPORT_OFFSET; | |
b96d3b08 | 189 | ret = usb_phy_init(pdata->otg); |
4c9715de WS |
190 | if (ret) { |
191 | dev_err(dev, "unable to init transceiver, probably missing\n"); | |
192 | ret = -ENODEV; | |
193 | goto err_add; | |
194 | } | |
6e13c650 | 195 | ret = otg_set_vbus(pdata->otg->otg, 1); |
4c9715de | 196 | if (ret) { |
7e8d5cd9 | 197 | dev_err(dev, "unable to enable vbus on transceiver\n"); |
4c9715de WS |
198 | goto err_add; |
199 | } | |
7e8d5cd9 DM |
200 | } |
201 | ||
202 | priv->hcd = hcd; | |
203 | platform_set_drvdata(pdev, priv); | |
204 | ||
b5dd18d8 | 205 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
7e8d5cd9 DM |
206 | if (ret) |
207 | goto err_add; | |
208 | ||
a464dc4d AP |
209 | if (pdata->otg) { |
210 | /* | |
211 | * efikamx and efikasb have some hardware bug which is | |
212 | * preventing usb to work unless CHRGVBUS is set. | |
213 | * It's in violation of USB specs | |
214 | */ | |
215 | if (machine_is_mx51_efikamx() || machine_is_mx51_efikasb()) { | |
b96d3b08 HK |
216 | flags = usb_phy_io_read(pdata->otg, |
217 | ULPI_OTG_CTRL); | |
a464dc4d | 218 | flags |= ULPI_OTG_CTRL_CHRGVBUS; |
b96d3b08 HK |
219 | ret = usb_phy_io_write(pdata->otg, flags, |
220 | ULPI_OTG_CTRL); | |
a464dc4d AP |
221 | if (ret) { |
222 | dev_err(dev, "unable to set CHRVBUS\n"); | |
223 | goto err_add; | |
224 | } | |
225 | } | |
226 | } | |
227 | ||
7e8d5cd9 DM |
228 | return 0; |
229 | ||
230 | err_add: | |
231 | if (pdata && pdata->exit) | |
232 | pdata->exit(pdev); | |
233 | err_init: | |
af09c060 | 234 | if (priv->phyclk) |
c943740c | 235 | clk_disable_unprepare(priv->phyclk); |
c943740c SH |
236 | |
237 | clk_disable_unprepare(priv->ahbclk); | |
7e8d5cd9 | 238 | err_clk_ahb: |
198ad2ce | 239 | clk_disable_unprepare(priv->usbclk); |
7e8d5cd9 DM |
240 | err_alloc: |
241 | usb_put_hcd(hcd); | |
242 | return ret; | |
243 | } | |
244 | ||
245 | static int __exit ehci_mxc_drv_remove(struct platform_device *pdev) | |
246 | { | |
247 | struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data; | |
248 | struct ehci_mxc_priv *priv = platform_get_drvdata(pdev); | |
249 | struct usb_hcd *hcd = priv->hcd; | |
250 | ||
251 | if (pdata && pdata->exit) | |
252 | pdata->exit(pdev); | |
253 | ||
254 | if (pdata->otg) | |
b96d3b08 | 255 | usb_phy_shutdown(pdata->otg); |
7e8d5cd9 DM |
256 | |
257 | usb_remove_hcd(hcd); | |
7e8d5cd9 DM |
258 | usb_put_hcd(hcd); |
259 | platform_set_drvdata(pdev, NULL); | |
260 | ||
198ad2ce | 261 | clk_disable_unprepare(priv->usbclk); |
c943740c | 262 | clk_disable_unprepare(priv->ahbclk); |
c943740c | 263 | |
af09c060 | 264 | if (priv->phyclk) |
c943740c | 265 | clk_disable_unprepare(priv->phyclk); |
7e8d5cd9 DM |
266 | |
267 | return 0; | |
268 | } | |
269 | ||
270 | static void ehci_mxc_drv_shutdown(struct platform_device *pdev) | |
271 | { | |
272 | struct ehci_mxc_priv *priv = platform_get_drvdata(pdev); | |
273 | struct usb_hcd *hcd = priv->hcd; | |
274 | ||
275 | if (hcd->driver->shutdown) | |
276 | hcd->driver->shutdown(hcd); | |
277 | } | |
278 | ||
279 | MODULE_ALIAS("platform:mxc-ehci"); | |
280 | ||
281 | static struct platform_driver ehci_mxc_driver = { | |
282 | .probe = ehci_mxc_drv_probe, | |
283 | .remove = __exit_p(ehci_mxc_drv_remove), | |
284 | .shutdown = ehci_mxc_drv_shutdown, | |
285 | .driver = { | |
286 | .name = "mxc-ehci", | |
287 | }, | |
288 | }; |