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>
25 #include <mach/mxc_ehci.h>
27 #define ULPI_VIEWPORT_OFFSET 0x170
28 #define PORTSC_OFFSET 0x184
29 #define USBMODE_OFFSET 0x1a8
30 #define USBMODE_CM_HOST 3
32 struct ehci_mxc_priv
{
33 struct clk
*usbclk
, *ahbclk
;
37 /* called during probe() after chip reset completes */
38 static int ehci_mxc_setup(struct usb_hcd
*hcd
)
40 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
43 /* EHCI registers start at offset 0x100 */
44 ehci
->caps
= hcd
->regs
+ 0x100;
45 ehci
->regs
= hcd
->regs
+ 0x100 +
46 HC_LENGTH(ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
47 dbg_hcs_params(ehci
, "reset");
48 dbg_hcc_params(ehci
, "reset");
50 /* cache this readonly data; minimize chip reads */
51 ehci
->hcs_params
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
53 retval
= ehci_halt(ehci
);
57 /* data structure init */
58 retval
= ehci_init(hcd
);
68 ehci_port_power(ehci
, 0);
72 static const struct hc_driver ehci_mxc_hc_driver
= {
73 .description
= hcd_name
,
74 .product_desc
= "Freescale On-Chip EHCI Host Controller",
75 .hcd_priv_size
= sizeof(struct ehci_hcd
),
78 * generic hardware linkage
81 .flags
= HCD_USB2
| HCD_MEMORY
,
84 * basic lifecycle operations
86 .reset
= ehci_mxc_setup
,
89 .shutdown
= ehci_shutdown
,
92 * managing i/o requests and associated device resources
94 .urb_enqueue
= ehci_urb_enqueue
,
95 .urb_dequeue
= ehci_urb_dequeue
,
96 .endpoint_disable
= ehci_endpoint_disable
,
101 .get_frame_number
= ehci_get_frame
,
106 .hub_status_data
= ehci_hub_status_data
,
107 .hub_control
= ehci_hub_control
,
108 .bus_suspend
= ehci_bus_suspend
,
109 .bus_resume
= ehci_bus_resume
,
110 .relinquish_port
= ehci_relinquish_port
,
111 .port_handed_over
= ehci_port_handed_over
,
114 static int ehci_mxc_drv_probe(struct platform_device
*pdev
)
116 struct mxc_usbh_platform_data
*pdata
= pdev
->dev
.platform_data
;
118 struct resource
*res
;
120 struct ehci_mxc_priv
*priv
;
121 struct device
*dev
= &pdev
->dev
;
123 dev_info(&pdev
->dev
, "initializing i.MX USB Controller\n");
126 dev_err(dev
, "No platform data given, bailing out.\n");
130 irq
= platform_get_irq(pdev
, 0);
132 hcd
= usb_create_hcd(&ehci_mxc_hc_driver
, dev
, dev_name(dev
));
136 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
142 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
144 dev_err(dev
, "Found HC with no register addr. Check setup!\n");
146 goto err_get_resource
;
149 hcd
->rsrc_start
= res
->start
;
150 hcd
->rsrc_len
= resource_size(res
);
152 if (!request_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
, hcd_name
)) {
153 dev_dbg(dev
, "controller already in use\n");
155 goto err_request_mem
;
158 hcd
->regs
= ioremap(hcd
->rsrc_start
, hcd
->rsrc_len
);
160 dev_err(dev
, "error mapping memory\n");
166 priv
->usbclk
= clk_get(dev
, "usb");
167 if (IS_ERR(priv
->usbclk
)) {
168 ret
= PTR_ERR(priv
->usbclk
);
171 clk_enable(priv
->usbclk
);
173 if (!cpu_is_mx35()) {
174 priv
->ahbclk
= clk_get(dev
, "usb_ahb");
175 if (IS_ERR(priv
->ahbclk
)) {
176 ret
= PTR_ERR(priv
->ahbclk
);
179 clk_enable(priv
->ahbclk
);
182 /* set USBMODE to host mode */
183 temp
= readl(hcd
->regs
+ USBMODE_OFFSET
);
184 writel(temp
| USBMODE_CM_HOST
, hcd
->regs
+ USBMODE_OFFSET
);
186 /* set up the PORTSCx register */
187 writel(pdata
->portsc
, hcd
->regs
+ PORTSC_OFFSET
);
190 /* setup USBCONTROL. */
191 ret
= mxc_set_usbcontrol(pdev
->id
, pdata
->flags
);
195 /* call platform specific init function */
197 ret
= pdata
->init(pdev
);
199 dev_err(dev
, "platform init failed\n");
204 /* most platforms need some time to settle changed IO settings */
207 /* Initialize the transceiver */
209 pdata
->otg
->io_priv
= hcd
->regs
+ ULPI_VIEWPORT_OFFSET
;
210 if (otg_init(pdata
->otg
) != 0)
211 dev_err(dev
, "unable to init transceiver\n");
212 else if (otg_set_vbus(pdata
->otg
, 1) != 0)
213 dev_err(dev
, "unable to enable vbus on transceiver\n");
217 platform_set_drvdata(pdev
, priv
);
219 ret
= usb_add_hcd(hcd
, irq
, IRQF_DISABLED
| IRQF_SHARED
);
226 if (pdata
&& pdata
->exit
)
230 clk_disable(priv
->ahbclk
);
231 clk_put(priv
->ahbclk
);
234 clk_disable(priv
->usbclk
);
235 clk_put(priv
->usbclk
);
239 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
248 static int __exit
ehci_mxc_drv_remove(struct platform_device
*pdev
)
250 struct mxc_usbh_platform_data
*pdata
= pdev
->dev
.platform_data
;
251 struct ehci_mxc_priv
*priv
= platform_get_drvdata(pdev
);
252 struct usb_hcd
*hcd
= priv
->hcd
;
254 if (pdata
&& pdata
->exit
)
258 otg_shutdown(pdata
->otg
);
262 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
264 platform_set_drvdata(pdev
, NULL
);
266 clk_disable(priv
->usbclk
);
267 clk_put(priv
->usbclk
);
269 clk_disable(priv
->ahbclk
);
270 clk_put(priv
->ahbclk
);
278 static void ehci_mxc_drv_shutdown(struct platform_device
*pdev
)
280 struct ehci_mxc_priv
*priv
= platform_get_drvdata(pdev
);
281 struct usb_hcd
*hcd
= priv
->hcd
;
283 if (hcd
->driver
->shutdown
)
284 hcd
->driver
->shutdown(hcd
);
287 MODULE_ALIAS("platform:mxc-ehci");
289 static struct platform_driver ehci_mxc_driver
= {
290 .probe
= ehci_mxc_drv_probe
,
291 .remove
= __exit_p(ehci_mxc_drv_remove
),
292 .shutdown
= ehci_mxc_drv_shutdown
,