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 <mach/mxc_ehci.h>
30 #include <asm/mach-types.h>
32 #define ULPI_VIEWPORT_OFFSET 0x170
34 struct ehci_mxc_priv
{
35 struct clk
*usbclk
, *ahbclk
, *phy1clk
;
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
);
45 dbg_hcs_params(ehci
, "reset");
46 dbg_hcc_params(ehci
, "reset");
48 /* cache this readonly data; minimize chip reads */
49 ehci
->hcs_params
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
53 retval
= ehci_halt(ehci
);
57 /* data structure init */
58 retval
= ehci_init(hcd
);
66 ehci_port_power(ehci
, 0);
70 static const struct hc_driver ehci_mxc_hc_driver
= {
71 .description
= hcd_name
,
72 .product_desc
= "Freescale On-Chip EHCI Host Controller",
73 .hcd_priv_size
= sizeof(struct ehci_hcd
),
76 * generic hardware linkage
79 .flags
= HCD_USB2
| HCD_MEMORY
,
82 * basic lifecycle operations
84 .reset
= ehci_mxc_setup
,
87 .shutdown
= ehci_shutdown
,
90 * managing i/o requests and associated device resources
92 .urb_enqueue
= ehci_urb_enqueue
,
93 .urb_dequeue
= ehci_urb_dequeue
,
94 .endpoint_disable
= ehci_endpoint_disable
,
95 .endpoint_reset
= ehci_endpoint_reset
,
100 .get_frame_number
= ehci_get_frame
,
105 .hub_status_data
= ehci_hub_status_data
,
106 .hub_control
= ehci_hub_control
,
107 .bus_suspend
= ehci_bus_suspend
,
108 .bus_resume
= ehci_bus_resume
,
109 .relinquish_port
= ehci_relinquish_port
,
110 .port_handed_over
= ehci_port_handed_over
,
112 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
115 static int ehci_mxc_drv_probe(struct platform_device
*pdev
)
117 struct mxc_usbh_platform_data
*pdata
= pdev
->dev
.platform_data
;
119 struct resource
*res
;
122 struct ehci_mxc_priv
*priv
;
123 struct device
*dev
= &pdev
->dev
;
124 struct ehci_hcd
*ehci
;
126 dev_info(&pdev
->dev
, "initializing i.MX USB Controller\n");
129 dev_err(dev
, "No platform data given, bailing out.\n");
133 irq
= platform_get_irq(pdev
, 0);
135 hcd
= usb_create_hcd(&ehci_mxc_hc_driver
, dev
, dev_name(dev
));
139 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
145 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
147 dev_err(dev
, "Found HC with no register addr. Check setup!\n");
149 goto err_get_resource
;
152 hcd
->rsrc_start
= res
->start
;
153 hcd
->rsrc_len
= resource_size(res
);
155 if (!request_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
, hcd_name
)) {
156 dev_dbg(dev
, "controller already in use\n");
158 goto err_request_mem
;
161 hcd
->regs
= ioremap(hcd
->rsrc_start
, hcd
->rsrc_len
);
163 dev_err(dev
, "error mapping memory\n");
169 priv
->usbclk
= clk_get(dev
, "usb");
170 if (IS_ERR(priv
->usbclk
)) {
171 ret
= PTR_ERR(priv
->usbclk
);
174 clk_enable(priv
->usbclk
);
176 if (!cpu_is_mx35() && !cpu_is_mx25()) {
177 priv
->ahbclk
= clk_get(dev
, "usb_ahb");
178 if (IS_ERR(priv
->ahbclk
)) {
179 ret
= PTR_ERR(priv
->ahbclk
);
182 clk_enable(priv
->ahbclk
);
185 /* "dr" device has its own clock on i.MX51 */
186 if (cpu_is_mx51() && (pdev
->id
== 0)) {
187 priv
->phy1clk
= clk_get(dev
, "usb_phy1");
188 if (IS_ERR(priv
->phy1clk
)) {
189 ret
= PTR_ERR(priv
->phy1clk
);
192 clk_enable(priv
->phy1clk
);
196 /* call platform specific init function */
198 ret
= pdata
->init(pdev
);
200 dev_err(dev
, "platform init failed\n");
203 /* platforms need some time to settle changed IO settings */
207 ehci
= hcd_to_ehci(hcd
);
209 /* EHCI registers start at offset 0x100 */
210 ehci
->caps
= hcd
->regs
+ 0x100;
211 ehci
->regs
= hcd
->regs
+ 0x100 +
212 HC_LENGTH(ehci
, ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
214 /* set up the PORTSCx register */
215 ehci_writel(ehci
, pdata
->portsc
, &ehci
->regs
->port_status
[0]);
217 /* is this really needed? */
220 /* Initialize the transceiver */
222 pdata
->otg
->io_priv
= hcd
->regs
+ ULPI_VIEWPORT_OFFSET
;
223 ret
= otg_init(pdata
->otg
);
225 dev_err(dev
, "unable to init transceiver, probably missing\n");
229 ret
= otg_set_vbus(pdata
->otg
, 1);
231 dev_err(dev
, "unable to enable vbus on transceiver\n");
237 platform_set_drvdata(pdev
, priv
);
239 ret
= usb_add_hcd(hcd
, irq
, IRQF_DISABLED
| IRQF_SHARED
);
245 * efikamx and efikasb have some hardware bug which is
246 * preventing usb to work unless CHRGVBUS is set.
247 * It's in violation of USB specs
249 if (machine_is_mx51_efikamx() || machine_is_mx51_efikasb()) {
250 flags
= otg_io_read(pdata
->otg
, ULPI_OTG_CTRL
);
251 flags
|= ULPI_OTG_CTRL_CHRGVBUS
;
252 ret
= otg_io_write(pdata
->otg
, flags
, ULPI_OTG_CTRL
);
254 dev_err(dev
, "unable to set CHRVBUS\n");
263 if (pdata
&& pdata
->exit
)
267 clk_disable(priv
->phy1clk
);
268 clk_put(priv
->phy1clk
);
272 clk_disable(priv
->ahbclk
);
273 clk_put(priv
->ahbclk
);
276 clk_disable(priv
->usbclk
);
277 clk_put(priv
->usbclk
);
281 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
290 static int __exit
ehci_mxc_drv_remove(struct platform_device
*pdev
)
292 struct mxc_usbh_platform_data
*pdata
= pdev
->dev
.platform_data
;
293 struct ehci_mxc_priv
*priv
= platform_get_drvdata(pdev
);
294 struct usb_hcd
*hcd
= priv
->hcd
;
296 if (pdata
&& pdata
->exit
)
300 otg_shutdown(pdata
->otg
);
304 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
306 platform_set_drvdata(pdev
, NULL
);
308 clk_disable(priv
->usbclk
);
309 clk_put(priv
->usbclk
);
311 clk_disable(priv
->ahbclk
);
312 clk_put(priv
->ahbclk
);
315 clk_disable(priv
->phy1clk
);
316 clk_put(priv
->phy1clk
);
324 static void ehci_mxc_drv_shutdown(struct platform_device
*pdev
)
326 struct ehci_mxc_priv
*priv
= platform_get_drvdata(pdev
);
327 struct usb_hcd
*hcd
= priv
->hcd
;
329 if (hcd
->driver
->shutdown
)
330 hcd
->driver
->shutdown(hcd
);
333 MODULE_ALIAS("platform:mxc-ehci");
335 static struct platform_driver ehci_mxc_driver
= {
336 .probe
= ehci_mxc_drv_probe
,
337 .remove
= __exit_p(ehci_mxc_drv_remove
),
338 .shutdown
= ehci_mxc_drv_shutdown
,