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/kernel.h>
21 #include <linux/module.h>
23 #include <linux/platform_device.h>
24 #include <linux/clk.h>
25 #include <linux/delay.h>
26 #include <linux/usb/otg.h>
27 #include <linux/usb/ulpi.h>
28 #include <linux/slab.h>
29 #include <linux/usb.h>
30 #include <linux/usb/hcd.h>
32 #include <linux/platform_data/usb-ehci-mxc.h>
34 #include <asm/mach-types.h>
38 #define DRIVER_DESC "Freescale On-Chip EHCI Host driver"
40 static const char hcd_name
[] = "ehci-mxc";
42 #define ULPI_VIEWPORT_OFFSET 0x170
44 struct ehci_mxc_priv
{
45 struct clk
*usbclk
, *ahbclk
, *phyclk
;
48 static struct hc_driver __read_mostly ehci_mxc_hc_driver
;
50 static const struct ehci_driver_overrides ehci_mxc_overrides __initdata
= {
51 .extra_priv_size
= sizeof(struct ehci_mxc_priv
),
54 static int ehci_mxc_drv_probe(struct platform_device
*pdev
)
56 struct mxc_usbh_platform_data
*pdata
= pdev
->dev
.platform_data
;
60 struct ehci_mxc_priv
*priv
;
61 struct device
*dev
= &pdev
->dev
;
62 struct ehci_hcd
*ehci
;
64 dev_info(&pdev
->dev
, "initializing i.MX USB Controller\n");
67 dev_err(dev
, "No platform data given, bailing out.\n");
71 irq
= platform_get_irq(pdev
, 0);
73 hcd
= usb_create_hcd(&ehci_mxc_hc_driver
, dev
, dev_name(dev
));
77 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
79 dev_err(dev
, "Found HC with no register addr. Check setup!\n");
84 hcd
->rsrc_start
= res
->start
;
85 hcd
->rsrc_len
= resource_size(res
);
87 hcd
->regs
= devm_ioremap_resource(&pdev
->dev
, res
);
88 if (IS_ERR(hcd
->regs
)) {
89 ret
= PTR_ERR(hcd
->regs
);
94 ehci
= hcd_to_ehci(hcd
);
95 priv
= (struct ehci_mxc_priv
*) ehci
->priv
;
98 priv
->usbclk
= devm_clk_get(&pdev
->dev
, "ipg");
99 if (IS_ERR(priv
->usbclk
)) {
100 ret
= PTR_ERR(priv
->usbclk
);
103 clk_prepare_enable(priv
->usbclk
);
105 priv
->ahbclk
= devm_clk_get(&pdev
->dev
, "ahb");
106 if (IS_ERR(priv
->ahbclk
)) {
107 ret
= PTR_ERR(priv
->ahbclk
);
110 clk_prepare_enable(priv
->ahbclk
);
112 /* "dr" device has its own clock on i.MX51 */
113 priv
->phyclk
= devm_clk_get(&pdev
->dev
, "phy");
114 if (IS_ERR(priv
->phyclk
))
117 clk_prepare_enable(priv
->phyclk
);
120 /* call platform specific init function */
122 ret
= pdata
->init(pdev
);
124 dev_err(dev
, "platform init failed\n");
127 /* platforms need some time to settle changed IO settings */
131 /* EHCI registers start at offset 0x100 */
132 ehci
->caps
= hcd
->regs
+ 0x100;
133 ehci
->regs
= hcd
->regs
+ 0x100 +
134 HC_LENGTH(ehci
, ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
136 /* set up the PORTSCx register */
137 ehci_writel(ehci
, pdata
->portsc
, &ehci
->regs
->port_status
[0]);
139 /* is this really needed? */
142 /* Initialize the transceiver */
144 pdata
->otg
->io_priv
= hcd
->regs
+ ULPI_VIEWPORT_OFFSET
;
145 ret
= usb_phy_init(pdata
->otg
);
147 dev_err(dev
, "unable to init transceiver, probably missing\n");
151 ret
= otg_set_vbus(pdata
->otg
->otg
, 1);
153 dev_err(dev
, "unable to enable vbus on transceiver\n");
158 platform_set_drvdata(pdev
, hcd
);
160 ret
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
167 if (pdata
&& pdata
->exit
)
171 clk_disable_unprepare(priv
->phyclk
);
173 clk_disable_unprepare(priv
->ahbclk
);
175 clk_disable_unprepare(priv
->usbclk
);
181 static int __exit
ehci_mxc_drv_remove(struct platform_device
*pdev
)
183 struct mxc_usbh_platform_data
*pdata
= pdev
->dev
.platform_data
;
184 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
185 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
186 struct ehci_mxc_priv
*priv
= (struct ehci_mxc_priv
*) ehci
->priv
;
190 if (pdata
&& pdata
->exit
)
194 usb_phy_shutdown(pdata
->otg
);
196 clk_disable_unprepare(priv
->usbclk
);
197 clk_disable_unprepare(priv
->ahbclk
);
200 clk_disable_unprepare(priv
->phyclk
);
203 platform_set_drvdata(pdev
, NULL
);
207 static void ehci_mxc_drv_shutdown(struct platform_device
*pdev
)
209 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
211 if (hcd
->driver
->shutdown
)
212 hcd
->driver
->shutdown(hcd
);
215 MODULE_ALIAS("platform:mxc-ehci");
217 static struct platform_driver ehci_mxc_driver
= {
218 .probe
= ehci_mxc_drv_probe
,
219 .remove
= ehci_mxc_drv_remove
,
220 .shutdown
= ehci_mxc_drv_shutdown
,
226 static int __init
ehci_mxc_init(void)
231 pr_info("%s: " DRIVER_DESC
"\n", hcd_name
);
233 ehci_init_driver(&ehci_mxc_hc_driver
, &ehci_mxc_overrides
);
234 return platform_driver_register(&ehci_mxc_driver
);
236 module_init(ehci_mxc_init
);
238 static void __exit
ehci_mxc_cleanup(void)
240 platform_driver_unregister(&ehci_mxc_driver
);
242 module_exit(ehci_mxc_cleanup
);
244 MODULE_DESCRIPTION(DRIVER_DESC
);
245 MODULE_AUTHOR("Sascha Hauer");
246 MODULE_LICENSE("GPL");