]>
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 | { | |
42 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | |
43 | int retval; | |
44 | ||
65fd4272 MC |
45 | hcd->has_tt = 1; |
46 | ||
1a49e2ac | 47 | retval = ehci_setup(hcd); |
7e8d5cd9 DM |
48 | if (retval) |
49 | return retval; | |
50 | ||
7e8d5cd9 DM |
51 | ehci_port_power(ehci, 0); |
52 | return 0; | |
53 | } | |
54 | ||
55 | static const struct hc_driver ehci_mxc_hc_driver = { | |
56 | .description = hcd_name, | |
57 | .product_desc = "Freescale On-Chip EHCI Host Controller", | |
58 | .hcd_priv_size = sizeof(struct ehci_hcd), | |
59 | ||
60 | /* | |
61 | * generic hardware linkage | |
62 | */ | |
63 | .irq = ehci_irq, | |
64 | .flags = HCD_USB2 | HCD_MEMORY, | |
65 | ||
66 | /* | |
67 | * basic lifecycle operations | |
68 | */ | |
69 | .reset = ehci_mxc_setup, | |
70 | .start = ehci_run, | |
71 | .stop = ehci_stop, | |
72 | .shutdown = ehci_shutdown, | |
73 | ||
74 | /* | |
75 | * managing i/o requests and associated device resources | |
76 | */ | |
77 | .urb_enqueue = ehci_urb_enqueue, | |
78 | .urb_dequeue = ehci_urb_dequeue, | |
79 | .endpoint_disable = ehci_endpoint_disable, | |
b48d7f50 | 80 | .endpoint_reset = ehci_endpoint_reset, |
7e8d5cd9 DM |
81 | |
82 | /* | |
83 | * scheduling support | |
84 | */ | |
85 | .get_frame_number = ehci_get_frame, | |
86 | ||
87 | /* | |
88 | * root hub support | |
89 | */ | |
90 | .hub_status_data = ehci_hub_status_data, | |
91 | .hub_control = ehci_hub_control, | |
92 | .bus_suspend = ehci_bus_suspend, | |
93 | .bus_resume = ehci_bus_resume, | |
94 | .relinquish_port = ehci_relinquish_port, | |
95 | .port_handed_over = ehci_port_handed_over, | |
b48d7f50 PM |
96 | |
97 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | |
7e8d5cd9 DM |
98 | }; |
99 | ||
100 | static int ehci_mxc_drv_probe(struct platform_device *pdev) | |
101 | { | |
102 | struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data; | |
103 | struct usb_hcd *hcd; | |
104 | struct resource *res; | |
724c8525 | 105 | int irq, ret; |
a464dc4d | 106 | unsigned int flags; |
7e8d5cd9 DM |
107 | struct ehci_mxc_priv *priv; |
108 | struct device *dev = &pdev->dev; | |
0247a7bc | 109 | struct ehci_hcd *ehci; |
7e8d5cd9 DM |
110 | |
111 | dev_info(&pdev->dev, "initializing i.MX USB Controller\n"); | |
112 | ||
113 | if (!pdata) { | |
114 | dev_err(dev, "No platform data given, bailing out.\n"); | |
115 | return -EINVAL; | |
116 | } | |
117 | ||
118 | irq = platform_get_irq(pdev, 0); | |
119 | ||
120 | hcd = usb_create_hcd(&ehci_mxc_hc_driver, dev, dev_name(dev)); | |
121 | if (!hcd) | |
122 | return -ENOMEM; | |
123 | ||
af09c060 | 124 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
7e8d5cd9 DM |
125 | if (!priv) { |
126 | ret = -ENOMEM; | |
127 | goto err_alloc; | |
128 | } | |
129 | ||
130 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
131 | if (!res) { | |
132 | dev_err(dev, "Found HC with no register addr. Check setup!\n"); | |
133 | ret = -ENODEV; | |
af09c060 | 134 | goto err_alloc; |
7e8d5cd9 DM |
135 | } |
136 | ||
137 | hcd->rsrc_start = res->start; | |
138 | hcd->rsrc_len = resource_size(res); | |
139 | ||
af09c060 | 140 | hcd->regs = devm_request_and_ioremap(&pdev->dev, res); |
7e8d5cd9 DM |
141 | if (!hcd->regs) { |
142 | dev_err(dev, "error mapping memory\n"); | |
143 | ret = -EFAULT; | |
af09c060 | 144 | goto err_alloc; |
7e8d5cd9 DM |
145 | } |
146 | ||
147 | /* enable clocks */ | |
af09c060 | 148 | priv->usbclk = devm_clk_get(&pdev->dev, "ipg"); |
7e8d5cd9 DM |
149 | if (IS_ERR(priv->usbclk)) { |
150 | ret = PTR_ERR(priv->usbclk); | |
af09c060 | 151 | goto err_alloc; |
7e8d5cd9 | 152 | } |
198ad2ce | 153 | clk_prepare_enable(priv->usbclk); |
7e8d5cd9 | 154 | |
af09c060 | 155 | priv->ahbclk = devm_clk_get(&pdev->dev, "ahb"); |
c943740c SH |
156 | if (IS_ERR(priv->ahbclk)) { |
157 | ret = PTR_ERR(priv->ahbclk); | |
158 | goto err_clk_ahb; | |
7e8d5cd9 | 159 | } |
c943740c | 160 | clk_prepare_enable(priv->ahbclk); |
7e8d5cd9 | 161 | |
3bb8029a | 162 | /* "dr" device has its own clock on i.MX51 */ |
af09c060 | 163 | priv->phyclk = devm_clk_get(&pdev->dev, "phy"); |
c943740c SH |
164 | if (IS_ERR(priv->phyclk)) |
165 | priv->phyclk = NULL; | |
166 | if (priv->phyclk) | |
167 | clk_prepare_enable(priv->phyclk); | |
711669e5 AP |
168 | |
169 | ||
170 | /* call platform specific init function */ | |
171 | if (pdata->init) { | |
172 | ret = pdata->init(pdev); | |
173 | if (ret) { | |
174 | dev_err(dev, "platform init failed\n"); | |
175 | goto err_init; | |
176 | } | |
177 | /* platforms need some time to settle changed IO settings */ | |
178 | mdelay(10); | |
179 | } | |
180 | ||
0247a7bc FE |
181 | ehci = hcd_to_ehci(hcd); |
182 | ||
183 | /* EHCI registers start at offset 0x100 */ | |
184 | ehci->caps = hcd->regs + 0x100; | |
185 | ehci->regs = hcd->regs + 0x100 + | |
c430131a | 186 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
0247a7bc FE |
187 | |
188 | /* set up the PORTSCx register */ | |
189 | ehci_writel(ehci, pdata->portsc, &ehci->regs->port_status[0]); | |
190 | ||
191 | /* is this really needed? */ | |
192 | msleep(10); | |
193 | ||
7e8d5cd9 DM |
194 | /* Initialize the transceiver */ |
195 | if (pdata->otg) { | |
196 | pdata->otg->io_priv = hcd->regs + ULPI_VIEWPORT_OFFSET; | |
b96d3b08 | 197 | ret = usb_phy_init(pdata->otg); |
4c9715de WS |
198 | if (ret) { |
199 | dev_err(dev, "unable to init transceiver, probably missing\n"); | |
200 | ret = -ENODEV; | |
201 | goto err_add; | |
202 | } | |
6e13c650 | 203 | ret = otg_set_vbus(pdata->otg->otg, 1); |
4c9715de | 204 | if (ret) { |
7e8d5cd9 | 205 | dev_err(dev, "unable to enable vbus on transceiver\n"); |
4c9715de WS |
206 | goto err_add; |
207 | } | |
7e8d5cd9 DM |
208 | } |
209 | ||
210 | priv->hcd = hcd; | |
211 | platform_set_drvdata(pdev, priv); | |
212 | ||
b5dd18d8 | 213 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
7e8d5cd9 DM |
214 | if (ret) |
215 | goto err_add; | |
216 | ||
a464dc4d AP |
217 | if (pdata->otg) { |
218 | /* | |
219 | * efikamx and efikasb have some hardware bug which is | |
220 | * preventing usb to work unless CHRGVBUS is set. | |
221 | * It's in violation of USB specs | |
222 | */ | |
223 | if (machine_is_mx51_efikamx() || machine_is_mx51_efikasb()) { | |
b96d3b08 HK |
224 | flags = usb_phy_io_read(pdata->otg, |
225 | ULPI_OTG_CTRL); | |
a464dc4d | 226 | flags |= ULPI_OTG_CTRL_CHRGVBUS; |
b96d3b08 HK |
227 | ret = usb_phy_io_write(pdata->otg, flags, |
228 | ULPI_OTG_CTRL); | |
a464dc4d AP |
229 | if (ret) { |
230 | dev_err(dev, "unable to set CHRVBUS\n"); | |
231 | goto err_add; | |
232 | } | |
233 | } | |
234 | } | |
235 | ||
7e8d5cd9 DM |
236 | return 0; |
237 | ||
238 | err_add: | |
239 | if (pdata && pdata->exit) | |
240 | pdata->exit(pdev); | |
241 | err_init: | |
af09c060 | 242 | if (priv->phyclk) |
c943740c | 243 | clk_disable_unprepare(priv->phyclk); |
c943740c SH |
244 | |
245 | clk_disable_unprepare(priv->ahbclk); | |
7e8d5cd9 | 246 | err_clk_ahb: |
198ad2ce | 247 | clk_disable_unprepare(priv->usbclk); |
7e8d5cd9 DM |
248 | err_alloc: |
249 | usb_put_hcd(hcd); | |
250 | return ret; | |
251 | } | |
252 | ||
253 | static int __exit ehci_mxc_drv_remove(struct platform_device *pdev) | |
254 | { | |
255 | struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data; | |
256 | struct ehci_mxc_priv *priv = platform_get_drvdata(pdev); | |
257 | struct usb_hcd *hcd = priv->hcd; | |
258 | ||
259 | if (pdata && pdata->exit) | |
260 | pdata->exit(pdev); | |
261 | ||
262 | if (pdata->otg) | |
b96d3b08 | 263 | usb_phy_shutdown(pdata->otg); |
7e8d5cd9 DM |
264 | |
265 | usb_remove_hcd(hcd); | |
7e8d5cd9 DM |
266 | usb_put_hcd(hcd); |
267 | platform_set_drvdata(pdev, NULL); | |
268 | ||
198ad2ce | 269 | clk_disable_unprepare(priv->usbclk); |
c943740c | 270 | clk_disable_unprepare(priv->ahbclk); |
c943740c | 271 | |
af09c060 | 272 | if (priv->phyclk) |
c943740c | 273 | clk_disable_unprepare(priv->phyclk); |
7e8d5cd9 DM |
274 | |
275 | return 0; | |
276 | } | |
277 | ||
278 | static void ehci_mxc_drv_shutdown(struct platform_device *pdev) | |
279 | { | |
280 | struct ehci_mxc_priv *priv = platform_get_drvdata(pdev); | |
281 | struct usb_hcd *hcd = priv->hcd; | |
282 | ||
283 | if (hcd->driver->shutdown) | |
284 | hcd->driver->shutdown(hcd); | |
285 | } | |
286 | ||
287 | MODULE_ALIAS("platform:mxc-ehci"); | |
288 | ||
289 | static struct platform_driver ehci_mxc_driver = { | |
290 | .probe = ehci_mxc_drv_probe, | |
291 | .remove = __exit_p(ehci_mxc_drv_remove), | |
292 | .shutdown = ehci_mxc_drv_shutdown, | |
293 | .driver = { | |
294 | .name = "mxc-ehci", | |
295 | }, | |
296 | }; |