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>
31 #include <linux/platform_data/usb-ehci-mxc.h>
34 #define DRIVER_DESC "Freescale On-Chip EHCI Host driver"
36 static const char hcd_name
[] = "ehci-mxc";
38 #define ULPI_VIEWPORT_OFFSET 0x170
40 struct ehci_mxc_priv
{
41 struct clk
*usbclk
, *ahbclk
, *phyclk
;
44 static struct hc_driver __read_mostly ehci_mxc_hc_driver
;
46 static const struct ehci_driver_overrides ehci_mxc_overrides __initconst
= {
47 .extra_priv_size
= sizeof(struct ehci_mxc_priv
),
50 static int ehci_mxc_drv_probe(struct platform_device
*pdev
)
52 struct mxc_usbh_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
56 struct ehci_mxc_priv
*priv
;
57 struct device
*dev
= &pdev
->dev
;
58 struct ehci_hcd
*ehci
;
61 dev_err(dev
, "No platform data given, bailing out.\n");
65 irq
= platform_get_irq(pdev
, 0);
67 hcd
= usb_create_hcd(&ehci_mxc_hc_driver
, dev
, dev_name(dev
));
71 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
73 dev_err(dev
, "Found HC with no register addr. Check setup!\n");
78 hcd
->rsrc_start
= res
->start
;
79 hcd
->rsrc_len
= resource_size(res
);
81 hcd
->regs
= devm_ioremap_resource(&pdev
->dev
, res
);
82 if (IS_ERR(hcd
->regs
)) {
83 ret
= PTR_ERR(hcd
->regs
);
88 ehci
= hcd_to_ehci(hcd
);
89 priv
= (struct ehci_mxc_priv
*) ehci
->priv
;
92 priv
->usbclk
= devm_clk_get(&pdev
->dev
, "ipg");
93 if (IS_ERR(priv
->usbclk
)) {
94 ret
= PTR_ERR(priv
->usbclk
);
97 clk_prepare_enable(priv
->usbclk
);
99 priv
->ahbclk
= devm_clk_get(&pdev
->dev
, "ahb");
100 if (IS_ERR(priv
->ahbclk
)) {
101 ret
= PTR_ERR(priv
->ahbclk
);
104 clk_prepare_enable(priv
->ahbclk
);
106 /* "dr" device has its own clock on i.MX51 */
107 priv
->phyclk
= devm_clk_get(&pdev
->dev
, "phy");
108 if (IS_ERR(priv
->phyclk
))
111 clk_prepare_enable(priv
->phyclk
);
114 /* call platform specific init function */
116 ret
= pdata
->init(pdev
);
118 dev_err(dev
, "platform init failed\n");
121 /* platforms need some time to settle changed IO settings */
125 /* EHCI registers start at offset 0x100 */
126 ehci
->caps
= hcd
->regs
+ 0x100;
127 ehci
->regs
= hcd
->regs
+ 0x100 +
128 HC_LENGTH(ehci
, ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
130 /* set up the PORTSCx register */
131 ehci_writel(ehci
, pdata
->portsc
, &ehci
->regs
->port_status
[0]);
133 /* is this really needed? */
136 /* Initialize the transceiver */
138 pdata
->otg
->io_priv
= hcd
->regs
+ ULPI_VIEWPORT_OFFSET
;
139 ret
= usb_phy_init(pdata
->otg
);
141 dev_err(dev
, "unable to init transceiver, probably missing\n");
145 ret
= otg_set_vbus(pdata
->otg
->otg
, 1);
147 dev_err(dev
, "unable to enable vbus on transceiver\n");
152 platform_set_drvdata(pdev
, hcd
);
154 ret
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
158 device_wakeup_enable(hcd
->self
.controller
);
162 if (pdata
&& pdata
->exit
)
166 clk_disable_unprepare(priv
->phyclk
);
168 clk_disable_unprepare(priv
->ahbclk
);
170 clk_disable_unprepare(priv
->usbclk
);
176 static int ehci_mxc_drv_remove(struct platform_device
*pdev
)
178 struct mxc_usbh_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
179 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
180 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
181 struct ehci_mxc_priv
*priv
= (struct ehci_mxc_priv
*) ehci
->priv
;
185 if (pdata
&& pdata
->exit
)
188 if (pdata
&& pdata
->otg
)
189 usb_phy_shutdown(pdata
->otg
);
191 clk_disable_unprepare(priv
->usbclk
);
192 clk_disable_unprepare(priv
->ahbclk
);
195 clk_disable_unprepare(priv
->phyclk
);
201 MODULE_ALIAS("platform:mxc-ehci");
203 static struct platform_driver ehci_mxc_driver
= {
204 .probe
= ehci_mxc_drv_probe
,
205 .remove
= ehci_mxc_drv_remove
,
206 .shutdown
= usb_hcd_platform_shutdown
,
212 static int __init
ehci_mxc_init(void)
217 pr_info("%s: " DRIVER_DESC
"\n", hcd_name
);
219 ehci_init_driver(&ehci_mxc_hc_driver
, &ehci_mxc_overrides
);
220 return platform_driver_register(&ehci_mxc_driver
);
222 module_init(ehci_mxc_init
);
224 static void __exit
ehci_mxc_cleanup(void)
226 platform_driver_unregister(&ehci_mxc_driver
);
228 module_exit(ehci_mxc_cleanup
);
230 MODULE_DESCRIPTION(DRIVER_DESC
);
231 MODULE_AUTHOR("Sascha Hauer");
232 MODULE_LICENSE("GPL");