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
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/slab.h>
26 #include <mach/mxc_ehci.h>
28 #define ULPI_VIEWPORT_OFFSET 0x170
30 struct ehci_mxc_priv {
31 struct clk *usbclk, *ahbclk;
35 /* called during probe() after chip reset completes */
36 static int ehci_mxc_setup(struct usb_hcd *hcd)
38 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
41 dbg_hcs_params(ehci, "reset");
42 dbg_hcc_params(ehci, "reset");
44 /* cache this readonly data; minimize chip reads */
45 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
49 retval = ehci_halt(ehci);
53 /* data structure init */
54 retval = ehci_init(hcd);
62 ehci_port_power(ehci, 0);
66 static const struct hc_driver ehci_mxc_hc_driver = {
67 .description = hcd_name,
68 .product_desc = "Freescale On-Chip EHCI Host Controller",
69 .hcd_priv_size = sizeof(struct ehci_hcd),
72 * generic hardware linkage
75 .flags = HCD_USB2 | HCD_MEMORY,
78 * basic lifecycle operations
80 .reset = ehci_mxc_setup,
83 .shutdown = ehci_shutdown,
86 * managing i/o requests and associated device resources
88 .urb_enqueue = ehci_urb_enqueue,
89 .urb_dequeue = ehci_urb_dequeue,
90 .endpoint_disable = ehci_endpoint_disable,
91 .endpoint_reset = ehci_endpoint_reset,
96 .get_frame_number = ehci_get_frame,
101 .hub_status_data = ehci_hub_status_data,
102 .hub_control = ehci_hub_control,
103 .bus_suspend = ehci_bus_suspend,
104 .bus_resume = ehci_bus_resume,
105 .relinquish_port = ehci_relinquish_port,
106 .port_handed_over = ehci_port_handed_over,
108 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
111 static int ehci_mxc_drv_probe(struct platform_device *pdev)
113 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
115 struct resource *res;
117 struct ehci_mxc_priv *priv;
118 struct device *dev = &pdev->dev;
119 struct ehci_hcd *ehci;
121 dev_info(&pdev->dev, "initializing i.MX USB Controller\n");
124 dev_err(dev, "No platform data given, bailing out.\n");
128 irq = platform_get_irq(pdev, 0);
130 hcd = usb_create_hcd(&ehci_mxc_hc_driver, dev, dev_name(dev));
134 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
140 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
142 dev_err(dev, "Found HC with no register addr. Check setup!\n");
144 goto err_get_resource;
147 hcd->rsrc_start = res->start;
148 hcd->rsrc_len = resource_size(res);
150 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
151 dev_dbg(dev, "controller already in use\n");
153 goto err_request_mem;
156 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
158 dev_err(dev, "error mapping memory\n");
163 /* call platform specific init function */
165 ret = pdata->init(pdev);
167 dev_err(dev, "platform init failed\n");
170 /* platforms need some time to settle changed IO settings */
175 priv->usbclk = clk_get(dev, "usb");
176 if (IS_ERR(priv->usbclk)) {
177 ret = PTR_ERR(priv->usbclk);
180 clk_enable(priv->usbclk);
182 if (!cpu_is_mx35() && !cpu_is_mx25()) {
183 priv->ahbclk = clk_get(dev, "usb_ahb");
184 if (IS_ERR(priv->ahbclk)) {
185 ret = PTR_ERR(priv->ahbclk);
188 clk_enable(priv->ahbclk);
191 /* setup specific usb hw */
192 ret = mxc_initialize_usb_hw(pdev->id, pdata->flags);
196 ehci = hcd_to_ehci(hcd);
198 /* EHCI registers start at offset 0x100 */
199 ehci->caps = hcd->regs + 0x100;
200 ehci->regs = hcd->regs + 0x100 +
201 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
203 /* set up the PORTSCx register */
204 ehci_writel(ehci, pdata->portsc, &ehci->regs->port_status[0]);
206 /* is this really needed? */
209 /* Initialize the transceiver */
211 pdata->otg->io_priv = hcd->regs + ULPI_VIEWPORT_OFFSET;
212 ret = otg_init(pdata->otg);
214 dev_err(dev, "unable to init transceiver, probably missing\n");
218 ret = otg_set_vbus(pdata->otg, 1);
220 dev_err(dev, "unable to enable vbus on transceiver\n");
226 platform_set_drvdata(pdev, priv);
228 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
235 if (pdata && pdata->exit)
239 clk_disable(priv->ahbclk);
240 clk_put(priv->ahbclk);
243 clk_disable(priv->usbclk);
244 clk_put(priv->usbclk);
248 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
257 static int __exit ehci_mxc_drv_remove(struct platform_device *pdev)
259 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
260 struct ehci_mxc_priv *priv = platform_get_drvdata(pdev);
261 struct usb_hcd *hcd = priv->hcd;
263 if (pdata && pdata->exit)
267 otg_shutdown(pdata->otg);
271 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
273 platform_set_drvdata(pdev, NULL);
275 clk_disable(priv->usbclk);
276 clk_put(priv->usbclk);
278 clk_disable(priv->ahbclk);
279 clk_put(priv->ahbclk);
287 static void ehci_mxc_drv_shutdown(struct platform_device *pdev)
289 struct ehci_mxc_priv *priv = platform_get_drvdata(pdev);
290 struct usb_hcd *hcd = priv->hcd;
292 if (hcd->driver->shutdown)
293 hcd->driver->shutdown(hcd);
296 MODULE_ALIAS("platform:mxc-ehci");
298 static struct platform_driver ehci_mxc_driver = {
299 .probe = ehci_mxc_drv_probe,
300 .remove = __exit_p(ehci_mxc_drv_remove),
301 .shutdown = ehci_mxc_drv_shutdown,