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/usb/ulpi.h>
25 #include <linux/slab.h>
27 #include <mach/hardware.h>
28 #include <linux/platform_data/usb-ehci-mxc.h>
30 #include <asm/mach-types.h>
32 #define ULPI_VIEWPORT_OFFSET 0x170
34 struct ehci_mxc_priv
{
35 struct clk
*usbclk
, *ahbclk
, *phyclk
;
39 /* called during probe() after chip reset completes */
40 static int ehci_mxc_setup(struct usb_hcd
*hcd
)
42 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
46 return ehci_setup(hcd
);
49 static const struct hc_driver ehci_mxc_hc_driver
= {
50 .description
= hcd_name
,
51 .product_desc
= "Freescale On-Chip EHCI Host Controller",
52 .hcd_priv_size
= sizeof(struct ehci_hcd
),
55 * generic hardware linkage
58 .flags
= HCD_USB2
| HCD_MEMORY
,
61 * basic lifecycle operations
63 .reset
= ehci_mxc_setup
,
66 .shutdown
= ehci_shutdown
,
69 * managing i/o requests and associated device resources
71 .urb_enqueue
= ehci_urb_enqueue
,
72 .urb_dequeue
= ehci_urb_dequeue
,
73 .endpoint_disable
= ehci_endpoint_disable
,
74 .endpoint_reset
= ehci_endpoint_reset
,
79 .get_frame_number
= ehci_get_frame
,
84 .hub_status_data
= ehci_hub_status_data
,
85 .hub_control
= ehci_hub_control
,
86 .bus_suspend
= ehci_bus_suspend
,
87 .bus_resume
= ehci_bus_resume
,
88 .relinquish_port
= ehci_relinquish_port
,
89 .port_handed_over
= ehci_port_handed_over
,
91 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
94 static int ehci_mxc_drv_probe(struct platform_device
*pdev
)
96 struct mxc_usbh_platform_data
*pdata
= pdev
->dev
.platform_data
;
101 struct ehci_mxc_priv
*priv
;
102 struct device
*dev
= &pdev
->dev
;
103 struct ehci_hcd
*ehci
;
105 dev_info(&pdev
->dev
, "initializing i.MX USB Controller\n");
108 dev_err(dev
, "No platform data given, bailing out.\n");
112 irq
= platform_get_irq(pdev
, 0);
114 hcd
= usb_create_hcd(&ehci_mxc_hc_driver
, dev
, dev_name(dev
));
118 priv
= devm_kzalloc(&pdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
124 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
126 dev_err(dev
, "Found HC with no register addr. Check setup!\n");
131 hcd
->rsrc_start
= res
->start
;
132 hcd
->rsrc_len
= resource_size(res
);
134 hcd
->regs
= devm_request_and_ioremap(&pdev
->dev
, res
);
136 dev_err(dev
, "error mapping memory\n");
142 priv
->usbclk
= devm_clk_get(&pdev
->dev
, "ipg");
143 if (IS_ERR(priv
->usbclk
)) {
144 ret
= PTR_ERR(priv
->usbclk
);
147 clk_prepare_enable(priv
->usbclk
);
149 priv
->ahbclk
= devm_clk_get(&pdev
->dev
, "ahb");
150 if (IS_ERR(priv
->ahbclk
)) {
151 ret
= PTR_ERR(priv
->ahbclk
);
154 clk_prepare_enable(priv
->ahbclk
);
156 /* "dr" device has its own clock on i.MX51 */
157 priv
->phyclk
= devm_clk_get(&pdev
->dev
, "phy");
158 if (IS_ERR(priv
->phyclk
))
161 clk_prepare_enable(priv
->phyclk
);
164 /* call platform specific init function */
166 ret
= pdata
->init(pdev
);
168 dev_err(dev
, "platform init failed\n");
171 /* platforms need some time to settle changed IO settings */
175 ehci
= hcd_to_ehci(hcd
);
177 /* EHCI registers start at offset 0x100 */
178 ehci
->caps
= hcd
->regs
+ 0x100;
179 ehci
->regs
= hcd
->regs
+ 0x100 +
180 HC_LENGTH(ehci
, ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
182 /* set up the PORTSCx register */
183 ehci_writel(ehci
, pdata
->portsc
, &ehci
->regs
->port_status
[0]);
185 /* is this really needed? */
188 /* Initialize the transceiver */
190 pdata
->otg
->io_priv
= hcd
->regs
+ ULPI_VIEWPORT_OFFSET
;
191 ret
= usb_phy_init(pdata
->otg
);
193 dev_err(dev
, "unable to init transceiver, probably missing\n");
197 ret
= otg_set_vbus(pdata
->otg
->otg
, 1);
199 dev_err(dev
, "unable to enable vbus on transceiver\n");
205 platform_set_drvdata(pdev
, priv
);
207 ret
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
213 * efikamx and efikasb have some hardware bug which is
214 * preventing usb to work unless CHRGVBUS is set.
215 * It's in violation of USB specs
217 if (machine_is_mx51_efikamx() || machine_is_mx51_efikasb()) {
218 flags
= usb_phy_io_read(pdata
->otg
,
220 flags
|= ULPI_OTG_CTRL_CHRGVBUS
;
221 ret
= usb_phy_io_write(pdata
->otg
, flags
,
224 dev_err(dev
, "unable to set CHRVBUS\n");
233 if (pdata
&& pdata
->exit
)
237 clk_disable_unprepare(priv
->phyclk
);
239 clk_disable_unprepare(priv
->ahbclk
);
241 clk_disable_unprepare(priv
->usbclk
);
247 static int __exit
ehci_mxc_drv_remove(struct platform_device
*pdev
)
249 struct mxc_usbh_platform_data
*pdata
= pdev
->dev
.platform_data
;
250 struct ehci_mxc_priv
*priv
= platform_get_drvdata(pdev
);
251 struct usb_hcd
*hcd
= priv
->hcd
;
253 if (pdata
&& pdata
->exit
)
257 usb_phy_shutdown(pdata
->otg
);
261 platform_set_drvdata(pdev
, NULL
);
263 clk_disable_unprepare(priv
->usbclk
);
264 clk_disable_unprepare(priv
->ahbclk
);
267 clk_disable_unprepare(priv
->phyclk
);
272 static void ehci_mxc_drv_shutdown(struct platform_device
*pdev
)
274 struct ehci_mxc_priv
*priv
= platform_get_drvdata(pdev
);
275 struct usb_hcd
*hcd
= priv
->hcd
;
277 if (hcd
->driver
->shutdown
)
278 hcd
->driver
->shutdown(hcd
);
281 MODULE_ALIAS("platform:mxc-ehci");
283 static struct platform_driver ehci_mxc_driver
= {
284 .probe
= ehci_mxc_drv_probe
,
285 .remove
= __exit_p(ehci_mxc_drv_remove
),
286 .shutdown
= ehci_mxc_drv_shutdown
,