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 <linux/platform_data/usb-ehci-mxc.h>
29 #include <asm/mach-types.h>
31 #define ULPI_VIEWPORT_OFFSET 0x170
33 struct ehci_mxc_priv
{
34 struct clk
*usbclk
, *ahbclk
, *phyclk
;
38 /* called during probe() after chip reset completes */
39 static int ehci_mxc_setup(struct usb_hcd
*hcd
)
43 return ehci_setup(hcd
);
46 static const struct hc_driver ehci_mxc_hc_driver
= {
47 .description
= hcd_name
,
48 .product_desc
= "Freescale On-Chip EHCI Host Controller",
49 .hcd_priv_size
= sizeof(struct ehci_hcd
),
52 * generic hardware linkage
55 .flags
= HCD_USB2
| HCD_MEMORY
,
58 * basic lifecycle operations
60 .reset
= ehci_mxc_setup
,
63 .shutdown
= ehci_shutdown
,
66 * managing i/o requests and associated device resources
68 .urb_enqueue
= ehci_urb_enqueue
,
69 .urb_dequeue
= ehci_urb_dequeue
,
70 .endpoint_disable
= ehci_endpoint_disable
,
71 .endpoint_reset
= ehci_endpoint_reset
,
76 .get_frame_number
= ehci_get_frame
,
81 .hub_status_data
= ehci_hub_status_data
,
82 .hub_control
= ehci_hub_control
,
83 .bus_suspend
= ehci_bus_suspend
,
84 .bus_resume
= ehci_bus_resume
,
85 .relinquish_port
= ehci_relinquish_port
,
86 .port_handed_over
= ehci_port_handed_over
,
88 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
91 static int ehci_mxc_drv_probe(struct platform_device
*pdev
)
93 struct mxc_usbh_platform_data
*pdata
= pdev
->dev
.platform_data
;
97 struct ehci_mxc_priv
*priv
;
98 struct device
*dev
= &pdev
->dev
;
99 struct ehci_hcd
*ehci
;
101 dev_info(&pdev
->dev
, "initializing i.MX USB Controller\n");
104 dev_err(dev
, "No platform data given, bailing out.\n");
108 irq
= platform_get_irq(pdev
, 0);
110 hcd
= usb_create_hcd(&ehci_mxc_hc_driver
, dev
, dev_name(dev
));
114 priv
= devm_kzalloc(&pdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
120 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
122 dev_err(dev
, "Found HC with no register addr. Check setup!\n");
127 hcd
->rsrc_start
= res
->start
;
128 hcd
->rsrc_len
= resource_size(res
);
130 hcd
->regs
= devm_request_and_ioremap(&pdev
->dev
, res
);
132 dev_err(dev
, "error mapping memory\n");
138 priv
->usbclk
= devm_clk_get(&pdev
->dev
, "ipg");
139 if (IS_ERR(priv
->usbclk
)) {
140 ret
= PTR_ERR(priv
->usbclk
);
143 clk_prepare_enable(priv
->usbclk
);
145 priv
->ahbclk
= devm_clk_get(&pdev
->dev
, "ahb");
146 if (IS_ERR(priv
->ahbclk
)) {
147 ret
= PTR_ERR(priv
->ahbclk
);
150 clk_prepare_enable(priv
->ahbclk
);
152 /* "dr" device has its own clock on i.MX51 */
153 priv
->phyclk
= devm_clk_get(&pdev
->dev
, "phy");
154 if (IS_ERR(priv
->phyclk
))
157 clk_prepare_enable(priv
->phyclk
);
160 /* call platform specific init function */
162 ret
= pdata
->init(pdev
);
164 dev_err(dev
, "platform init failed\n");
167 /* platforms need some time to settle changed IO settings */
171 ehci
= hcd_to_ehci(hcd
);
173 /* EHCI registers start at offset 0x100 */
174 ehci
->caps
= hcd
->regs
+ 0x100;
175 ehci
->regs
= hcd
->regs
+ 0x100 +
176 HC_LENGTH(ehci
, ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
178 /* set up the PORTSCx register */
179 ehci_writel(ehci
, pdata
->portsc
, &ehci
->regs
->port_status
[0]);
181 /* is this really needed? */
184 /* Initialize the transceiver */
186 pdata
->otg
->io_priv
= hcd
->regs
+ ULPI_VIEWPORT_OFFSET
;
187 ret
= usb_phy_init(pdata
->otg
);
189 dev_err(dev
, "unable to init transceiver, probably missing\n");
193 ret
= otg_set_vbus(pdata
->otg
->otg
, 1);
195 dev_err(dev
, "unable to enable vbus on transceiver\n");
201 platform_set_drvdata(pdev
, priv
);
203 ret
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
210 if (pdata
&& pdata
->exit
)
214 clk_disable_unprepare(priv
->phyclk
);
216 clk_disable_unprepare(priv
->ahbclk
);
218 clk_disable_unprepare(priv
->usbclk
);
224 static int __exit
ehci_mxc_drv_remove(struct platform_device
*pdev
)
226 struct mxc_usbh_platform_data
*pdata
= pdev
->dev
.platform_data
;
227 struct ehci_mxc_priv
*priv
= platform_get_drvdata(pdev
);
228 struct usb_hcd
*hcd
= priv
->hcd
;
230 if (pdata
&& pdata
->exit
)
234 usb_phy_shutdown(pdata
->otg
);
238 platform_set_drvdata(pdev
, NULL
);
240 clk_disable_unprepare(priv
->usbclk
);
241 clk_disable_unprepare(priv
->ahbclk
);
244 clk_disable_unprepare(priv
->phyclk
);
249 static void ehci_mxc_drv_shutdown(struct platform_device
*pdev
)
251 struct ehci_mxc_priv
*priv
= platform_get_drvdata(pdev
);
252 struct usb_hcd
*hcd
= priv
->hcd
;
254 if (hcd
->driver
->shutdown
)
255 hcd
->driver
->shutdown(hcd
);
258 MODULE_ALIAS("platform:mxc-ehci");
260 static struct platform_driver ehci_mxc_driver
= {
261 .probe
= ehci_mxc_drv_probe
,
262 .remove
= __exit_p(ehci_mxc_drv_remove
),
263 .shutdown
= ehci_mxc_drv_shutdown
,