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/slab.h>
26 #include <mach/mxc_ehci.h>
28 #define ULPI_VIEWPORT_OFFSET 0x170
29 #define PORTSC_OFFSET 0x184
30 #define USBMODE_OFFSET 0x1a8
31 #define USBMODE_CM_HOST 3
33 struct ehci_mxc_priv
{
34 struct clk
*usbclk
, *ahbclk
;
38 /* called during probe() after chip reset completes */
39 static int ehci_mxc_setup(struct usb_hcd
*hcd
)
41 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
44 /* EHCI registers start at offset 0x100 */
45 ehci
->caps
= hcd
->regs
+ 0x100;
46 ehci
->regs
= hcd
->regs
+ 0x100 +
47 HC_LENGTH(ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
48 dbg_hcs_params(ehci
, "reset");
49 dbg_hcc_params(ehci
, "reset");
51 /* cache this readonly data; minimize chip reads */
52 ehci
->hcs_params
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
54 retval
= ehci_halt(ehci
);
58 /* data structure init */
59 retval
= ehci_init(hcd
);
69 ehci_port_power(ehci
, 0);
73 static const struct hc_driver ehci_mxc_hc_driver
= {
74 .description
= hcd_name
,
75 .product_desc
= "Freescale On-Chip EHCI Host Controller",
76 .hcd_priv_size
= sizeof(struct ehci_hcd
),
79 * generic hardware linkage
82 .flags
= HCD_USB2
| HCD_MEMORY
,
85 * basic lifecycle operations
87 .reset
= ehci_mxc_setup
,
90 .shutdown
= ehci_shutdown
,
93 * managing i/o requests and associated device resources
95 .urb_enqueue
= ehci_urb_enqueue
,
96 .urb_dequeue
= ehci_urb_dequeue
,
97 .endpoint_disable
= ehci_endpoint_disable
,
102 .get_frame_number
= ehci_get_frame
,
107 .hub_status_data
= ehci_hub_status_data
,
108 .hub_control
= ehci_hub_control
,
109 .bus_suspend
= ehci_bus_suspend
,
110 .bus_resume
= ehci_bus_resume
,
111 .relinquish_port
= ehci_relinquish_port
,
112 .port_handed_over
= ehci_port_handed_over
,
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
;
121 struct ehci_mxc_priv
*priv
;
122 struct device
*dev
= &pdev
->dev
;
124 dev_info(&pdev
->dev
, "initializing i.MX USB Controller\n");
127 dev_err(dev
, "No platform data given, bailing out.\n");
131 irq
= platform_get_irq(pdev
, 0);
133 hcd
= usb_create_hcd(&ehci_mxc_hc_driver
, dev
, dev_name(dev
));
137 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
143 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
145 dev_err(dev
, "Found HC with no register addr. Check setup!\n");
147 goto err_get_resource
;
150 hcd
->rsrc_start
= res
->start
;
151 hcd
->rsrc_len
= resource_size(res
);
153 if (!request_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
, hcd_name
)) {
154 dev_dbg(dev
, "controller already in use\n");
156 goto err_request_mem
;
159 hcd
->regs
= ioremap(hcd
->rsrc_start
, hcd
->rsrc_len
);
161 dev_err(dev
, "error mapping memory\n");
166 /* call platform specific init function */
168 ret
= pdata
->init(pdev
);
170 dev_err(dev
, "platform init failed\n");
173 /* platforms need some time to settle changed IO settings */
178 priv
->usbclk
= clk_get(dev
, "usb");
179 if (IS_ERR(priv
->usbclk
)) {
180 ret
= PTR_ERR(priv
->usbclk
);
183 clk_enable(priv
->usbclk
);
185 if (!cpu_is_mx35() && !cpu_is_mx25()) {
186 priv
->ahbclk
= clk_get(dev
, "usb_ahb");
187 if (IS_ERR(priv
->ahbclk
)) {
188 ret
= PTR_ERR(priv
->ahbclk
);
191 clk_enable(priv
->ahbclk
);
194 /* set USBMODE to host mode */
195 temp
= readl(hcd
->regs
+ USBMODE_OFFSET
);
196 writel(temp
| USBMODE_CM_HOST
, hcd
->regs
+ USBMODE_OFFSET
);
198 /* set up the PORTSCx register */
199 writel(pdata
->portsc
, hcd
->regs
+ PORTSC_OFFSET
);
202 /* setup specific usb hw */
203 ret
= mxc_initialize_usb_hw(pdev
->id
, pdata
->flags
);
207 /* Initialize the transceiver */
209 pdata
->otg
->io_priv
= hcd
->regs
+ ULPI_VIEWPORT_OFFSET
;
210 ret
= otg_init(pdata
->otg
);
212 dev_err(dev
, "unable to init transceiver, probably missing\n");
216 ret
= otg_set_vbus(pdata
->otg
, 1);
218 dev_err(dev
, "unable to enable vbus on transceiver\n");
224 platform_set_drvdata(pdev
, priv
);
226 ret
= usb_add_hcd(hcd
, irq
, IRQF_DISABLED
| IRQF_SHARED
);
233 if (pdata
&& pdata
->exit
)
237 clk_disable(priv
->ahbclk
);
238 clk_put(priv
->ahbclk
);
241 clk_disable(priv
->usbclk
);
242 clk_put(priv
->usbclk
);
246 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
255 static int __exit
ehci_mxc_drv_remove(struct platform_device
*pdev
)
257 struct mxc_usbh_platform_data
*pdata
= pdev
->dev
.platform_data
;
258 struct ehci_mxc_priv
*priv
= platform_get_drvdata(pdev
);
259 struct usb_hcd
*hcd
= priv
->hcd
;
261 if (pdata
&& pdata
->exit
)
265 otg_shutdown(pdata
->otg
);
269 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
271 platform_set_drvdata(pdev
, NULL
);
273 clk_disable(priv
->usbclk
);
274 clk_put(priv
->usbclk
);
276 clk_disable(priv
->ahbclk
);
277 clk_put(priv
->ahbclk
);
285 static void ehci_mxc_drv_shutdown(struct platform_device
*pdev
)
287 struct ehci_mxc_priv
*priv
= platform_get_drvdata(pdev
);
288 struct usb_hcd
*hcd
= priv
->hcd
;
290 if (hcd
->driver
->shutdown
)
291 hcd
->driver
->shutdown(hcd
);
294 MODULE_ALIAS("platform:mxc-ehci");
296 static struct platform_driver ehci_mxc_driver
= {
297 .probe
= ehci_mxc_drv_probe
,
298 .remove
= __exit_p(ehci_mxc_drv_remove
),
299 .shutdown
= ehci_mxc_drv_shutdown
,