ocfs2: Make the left masklogs compat.
[taoma-kernel.git] / drivers / usb / host / ehci-mxc.c
blobc8e360d7d9759dbde4eff329781c252d5d27e806
1 /*
2 * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
3 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
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.
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.
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.
20 #include <linux/platform_device.h>
21 #include <linux/clk.h>
22 #include <linux/delay.h>
23 #include <linux/usb/otg.h>
24 #include <linux/usb/ulpi.h>
25 #include <linux/slab.h>
27 #include <mach/mxc_ehci.h>
29 #include <asm/mach-types.h>
31 #define ULPI_VIEWPORT_OFFSET 0x170
33 struct ehci_mxc_priv {
34 struct clk *usbclk, *ahbclk, *phy1clk;
35 struct usb_hcd *hcd;
38 /* called during probe() after chip reset completes */
39 static int ehci_mxc_setup(struct usb_hcd *hcd)
41 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
42 int retval;
44 dbg_hcs_params(ehci, "reset");
45 dbg_hcc_params(ehci, "reset");
47 /* cache this readonly data; minimize chip reads */
48 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
50 hcd->has_tt = 1;
52 retval = ehci_halt(ehci);
53 if (retval)
54 return retval;
56 /* data structure init */
57 retval = ehci_init(hcd);
58 if (retval)
59 return retval;
61 ehci->sbrn = 0x20;
63 ehci_reset(ehci);
65 ehci_port_power(ehci, 0);
66 return 0;
69 static const struct hc_driver ehci_mxc_hc_driver = {
70 .description = hcd_name,
71 .product_desc = "Freescale On-Chip EHCI Host Controller",
72 .hcd_priv_size = sizeof(struct ehci_hcd),
75 * generic hardware linkage
77 .irq = ehci_irq,
78 .flags = HCD_USB2 | HCD_MEMORY,
81 * basic lifecycle operations
83 .reset = ehci_mxc_setup,
84 .start = ehci_run,
85 .stop = ehci_stop,
86 .shutdown = ehci_shutdown,
89 * managing i/o requests and associated device resources
91 .urb_enqueue = ehci_urb_enqueue,
92 .urb_dequeue = ehci_urb_dequeue,
93 .endpoint_disable = ehci_endpoint_disable,
94 .endpoint_reset = ehci_endpoint_reset,
97 * scheduling support
99 .get_frame_number = ehci_get_frame,
102 * root hub support
104 .hub_status_data = ehci_hub_status_data,
105 .hub_control = ehci_hub_control,
106 .bus_suspend = ehci_bus_suspend,
107 .bus_resume = ehci_bus_resume,
108 .relinquish_port = ehci_relinquish_port,
109 .port_handed_over = ehci_port_handed_over,
111 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
114 static int ehci_mxc_drv_probe(struct platform_device *pdev)
116 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
117 struct usb_hcd *hcd;
118 struct resource *res;
119 int irq, ret;
120 unsigned int flags;
121 struct ehci_mxc_priv *priv;
122 struct device *dev = &pdev->dev;
123 struct ehci_hcd *ehci;
125 dev_info(&pdev->dev, "initializing i.MX USB Controller\n");
127 if (!pdata) {
128 dev_err(dev, "No platform data given, bailing out.\n");
129 return -EINVAL;
132 irq = platform_get_irq(pdev, 0);
134 hcd = usb_create_hcd(&ehci_mxc_hc_driver, dev, dev_name(dev));
135 if (!hcd)
136 return -ENOMEM;
138 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
139 if (!priv) {
140 ret = -ENOMEM;
141 goto err_alloc;
144 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
145 if (!res) {
146 dev_err(dev, "Found HC with no register addr. Check setup!\n");
147 ret = -ENODEV;
148 goto err_get_resource;
151 hcd->rsrc_start = res->start;
152 hcd->rsrc_len = resource_size(res);
154 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
155 dev_dbg(dev, "controller already in use\n");
156 ret = -EBUSY;
157 goto err_request_mem;
160 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
161 if (!hcd->regs) {
162 dev_err(dev, "error mapping memory\n");
163 ret = -EFAULT;
164 goto err_ioremap;
167 /* enable clocks */
168 priv->usbclk = clk_get(dev, "usb");
169 if (IS_ERR(priv->usbclk)) {
170 ret = PTR_ERR(priv->usbclk);
171 goto err_clk;
173 clk_enable(priv->usbclk);
175 if (!cpu_is_mx35() && !cpu_is_mx25()) {
176 priv->ahbclk = clk_get(dev, "usb_ahb");
177 if (IS_ERR(priv->ahbclk)) {
178 ret = PTR_ERR(priv->ahbclk);
179 goto err_clk_ahb;
181 clk_enable(priv->ahbclk);
184 /* "dr" device has its own clock on i.MX51 */
185 if (cpu_is_mx51() && (pdev->id == 0)) {
186 priv->phy1clk = clk_get(dev, "usb_phy1");
187 if (IS_ERR(priv->phy1clk)) {
188 ret = PTR_ERR(priv->phy1clk);
189 goto err_clk_phy;
191 clk_enable(priv->phy1clk);
195 /* call platform specific init function */
196 if (pdata->init) {
197 ret = pdata->init(pdev);
198 if (ret) {
199 dev_err(dev, "platform init failed\n");
200 goto err_init;
202 /* platforms need some time to settle changed IO settings */
203 mdelay(10);
206 /* setup specific usb hw */
207 ret = mxc_initialize_usb_hw(pdev->id, pdata->flags);
208 if (ret < 0)
209 goto err_init;
211 ehci = hcd_to_ehci(hcd);
213 /* EHCI registers start at offset 0x100 */
214 ehci->caps = hcd->regs + 0x100;
215 ehci->regs = hcd->regs + 0x100 +
216 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
218 /* set up the PORTSCx register */
219 ehci_writel(ehci, pdata->portsc, &ehci->regs->port_status[0]);
221 /* is this really needed? */
222 msleep(10);
224 /* Initialize the transceiver */
225 if (pdata->otg) {
226 pdata->otg->io_priv = hcd->regs + ULPI_VIEWPORT_OFFSET;
227 ret = otg_init(pdata->otg);
228 if (ret) {
229 dev_err(dev, "unable to init transceiver, probably missing\n");
230 ret = -ENODEV;
231 goto err_add;
233 ret = otg_set_vbus(pdata->otg, 1);
234 if (ret) {
235 dev_err(dev, "unable to enable vbus on transceiver\n");
236 goto err_add;
240 priv->hcd = hcd;
241 platform_set_drvdata(pdev, priv);
243 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
244 if (ret)
245 goto err_add;
247 if (pdata->otg) {
249 * efikamx and efikasb have some hardware bug which is
250 * preventing usb to work unless CHRGVBUS is set.
251 * It's in violation of USB specs
253 if (machine_is_mx51_efikamx() || machine_is_mx51_efikasb()) {
254 flags = otg_io_read(pdata->otg, ULPI_OTG_CTRL);
255 flags |= ULPI_OTG_CTRL_CHRGVBUS;
256 ret = otg_io_write(pdata->otg, flags, ULPI_OTG_CTRL);
257 if (ret) {
258 dev_err(dev, "unable to set CHRVBUS\n");
259 goto err_add;
264 return 0;
266 err_add:
267 if (pdata && pdata->exit)
268 pdata->exit(pdev);
269 err_init:
270 if (priv->phy1clk) {
271 clk_disable(priv->phy1clk);
272 clk_put(priv->phy1clk);
274 err_clk_phy:
275 if (priv->ahbclk) {
276 clk_disable(priv->ahbclk);
277 clk_put(priv->ahbclk);
279 err_clk_ahb:
280 clk_disable(priv->usbclk);
281 clk_put(priv->usbclk);
282 err_clk:
283 iounmap(hcd->regs);
284 err_ioremap:
285 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
286 err_request_mem:
287 err_get_resource:
288 kfree(priv);
289 err_alloc:
290 usb_put_hcd(hcd);
291 return ret;
294 static int __exit ehci_mxc_drv_remove(struct platform_device *pdev)
296 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
297 struct ehci_mxc_priv *priv = platform_get_drvdata(pdev);
298 struct usb_hcd *hcd = priv->hcd;
300 if (pdata && pdata->exit)
301 pdata->exit(pdev);
303 if (pdata->otg)
304 otg_shutdown(pdata->otg);
306 usb_remove_hcd(hcd);
307 iounmap(hcd->regs);
308 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
309 usb_put_hcd(hcd);
310 platform_set_drvdata(pdev, NULL);
312 clk_disable(priv->usbclk);
313 clk_put(priv->usbclk);
314 if (priv->ahbclk) {
315 clk_disable(priv->ahbclk);
316 clk_put(priv->ahbclk);
318 if (priv->phy1clk) {
319 clk_disable(priv->phy1clk);
320 clk_put(priv->phy1clk);
323 kfree(priv);
325 return 0;
328 static void ehci_mxc_drv_shutdown(struct platform_device *pdev)
330 struct ehci_mxc_priv *priv = platform_get_drvdata(pdev);
331 struct usb_hcd *hcd = priv->hcd;
333 if (hcd->driver->shutdown)
334 hcd->driver->shutdown(hcd);
337 MODULE_ALIAS("platform:mxc-ehci");
339 static struct platform_driver ehci_mxc_driver = {
340 .probe = ehci_mxc_drv_probe,
341 .remove = __exit_p(ehci_mxc_drv_remove),
342 .shutdown = ehci_mxc_drv_shutdown,
343 .driver = {
344 .name = "mxc-ehci",