USB: ehci-mxc: remove Efika MX-specific CHRGVBUS hack
[linux-2.6/btrfs-unstable.git] / drivers / usb / host / ehci-mxc.c
blob6b8c1584065f5609c6a3396026dd571de6d69877
1 /*
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
13 * for more details.
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;
35 struct usb_hcd *hcd;
38 /* called during probe() after chip reset completes */
39 static int ehci_mxc_setup(struct usb_hcd *hcd)
41 hcd->has_tt = 1;
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
54 .irq = ehci_irq,
55 .flags = HCD_USB2 | HCD_MEMORY,
58 * basic lifecycle operations
60 .reset = ehci_mxc_setup,
61 .start = ehci_run,
62 .stop = ehci_stop,
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,
74 * scheduling support
76 .get_frame_number = ehci_get_frame,
79 * root hub support
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;
94 struct usb_hcd *hcd;
95 struct resource *res;
96 int irq, ret;
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");
103 if (!pdata) {
104 dev_err(dev, "No platform data given, bailing out.\n");
105 return -EINVAL;
108 irq = platform_get_irq(pdev, 0);
110 hcd = usb_create_hcd(&ehci_mxc_hc_driver, dev, dev_name(dev));
111 if (!hcd)
112 return -ENOMEM;
114 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
115 if (!priv) {
116 ret = -ENOMEM;
117 goto err_alloc;
120 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
121 if (!res) {
122 dev_err(dev, "Found HC with no register addr. Check setup!\n");
123 ret = -ENODEV;
124 goto err_alloc;
127 hcd->rsrc_start = res->start;
128 hcd->rsrc_len = resource_size(res);
130 hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
131 if (!hcd->regs) {
132 dev_err(dev, "error mapping memory\n");
133 ret = -EFAULT;
134 goto err_alloc;
137 /* enable clocks */
138 priv->usbclk = devm_clk_get(&pdev->dev, "ipg");
139 if (IS_ERR(priv->usbclk)) {
140 ret = PTR_ERR(priv->usbclk);
141 goto err_alloc;
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);
148 goto err_clk_ahb;
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))
155 priv->phyclk = NULL;
156 if (priv->phyclk)
157 clk_prepare_enable(priv->phyclk);
160 /* call platform specific init function */
161 if (pdata->init) {
162 ret = pdata->init(pdev);
163 if (ret) {
164 dev_err(dev, "platform init failed\n");
165 goto err_init;
167 /* platforms need some time to settle changed IO settings */
168 mdelay(10);
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? */
182 msleep(10);
184 /* Initialize the transceiver */
185 if (pdata->otg) {
186 pdata->otg->io_priv = hcd->regs + ULPI_VIEWPORT_OFFSET;
187 ret = usb_phy_init(pdata->otg);
188 if (ret) {
189 dev_err(dev, "unable to init transceiver, probably missing\n");
190 ret = -ENODEV;
191 goto err_add;
193 ret = otg_set_vbus(pdata->otg->otg, 1);
194 if (ret) {
195 dev_err(dev, "unable to enable vbus on transceiver\n");
196 goto err_add;
200 priv->hcd = hcd;
201 platform_set_drvdata(pdev, priv);
203 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
204 if (ret)
205 goto err_add;
207 return 0;
209 err_add:
210 if (pdata && pdata->exit)
211 pdata->exit(pdev);
212 err_init:
213 if (priv->phyclk)
214 clk_disable_unprepare(priv->phyclk);
216 clk_disable_unprepare(priv->ahbclk);
217 err_clk_ahb:
218 clk_disable_unprepare(priv->usbclk);
219 err_alloc:
220 usb_put_hcd(hcd);
221 return ret;
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)
231 pdata->exit(pdev);
233 if (pdata->otg)
234 usb_phy_shutdown(pdata->otg);
236 usb_remove_hcd(hcd);
237 usb_put_hcd(hcd);
238 platform_set_drvdata(pdev, NULL);
240 clk_disable_unprepare(priv->usbclk);
241 clk_disable_unprepare(priv->ahbclk);
243 if (priv->phyclk)
244 clk_disable_unprepare(priv->phyclk);
246 return 0;
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,
264 .driver = {
265 .name = "mxc-ehci",