Commit | Line | Data |
---|---|---|
7e8d5cd9 DM |
1 | /* |
2 | * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix | |
3 | * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de> | |
4 | * | |
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. | |
9 | * | |
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. | |
14 | * | |
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. | |
18 | */ | |
19 | ||
dba63b2f AS |
20 | #include <linux/kernel.h> |
21 | #include <linux/module.h> | |
22 | #include <linux/io.h> | |
7e8d5cd9 DM |
23 | #include <linux/platform_device.h> |
24 | #include <linux/clk.h> | |
25 | #include <linux/delay.h> | |
26 | #include <linux/usb/otg.h> | |
a464dc4d | 27 | #include <linux/usb/ulpi.h> |
5a0e3ad6 | 28 | #include <linux/slab.h> |
dba63b2f AS |
29 | #include <linux/usb.h> |
30 | #include <linux/usb/hcd.h> | |
82906b13 | 31 | #include <linux/platform_data/usb-ehci-mxc.h> |
dba63b2f AS |
32 | #include "ehci.h" |
33 | ||
34 | #define DRIVER_DESC "Freescale On-Chip EHCI Host driver" | |
35 | ||
36 | static const char hcd_name[] = "ehci-mxc"; | |
37 | ||
7e8d5cd9 | 38 | #define ULPI_VIEWPORT_OFFSET 0x170 |
7e8d5cd9 DM |
39 | |
40 | struct ehci_mxc_priv { | |
c943740c | 41 | struct clk *usbclk, *ahbclk, *phyclk; |
7e8d5cd9 DM |
42 | }; |
43 | ||
dba63b2f | 44 | static struct hc_driver __read_mostly ehci_mxc_hc_driver; |
7e8d5cd9 | 45 | |
62d08a11 | 46 | static const struct ehci_driver_overrides ehci_mxc_overrides __initconst = { |
dba63b2f | 47 | .extra_priv_size = sizeof(struct ehci_mxc_priv), |
7e8d5cd9 DM |
48 | }; |
49 | ||
50 | static int ehci_mxc_drv_probe(struct platform_device *pdev) | |
51 | { | |
d4f09e28 | 52 | struct mxc_usbh_platform_data *pdata = dev_get_platdata(&pdev->dev); |
7e8d5cd9 DM |
53 | struct usb_hcd *hcd; |
54 | struct resource *res; | |
724c8525 | 55 | int irq, ret; |
7e8d5cd9 DM |
56 | struct ehci_mxc_priv *priv; |
57 | struct device *dev = &pdev->dev; | |
0247a7bc | 58 | struct ehci_hcd *ehci; |
7e8d5cd9 | 59 | |
7e8d5cd9 DM |
60 | if (!pdata) { |
61 | dev_err(dev, "No platform data given, bailing out.\n"); | |
62 | return -EINVAL; | |
63 | } | |
64 | ||
65 | irq = platform_get_irq(pdev, 0); | |
66 | ||
67 | hcd = usb_create_hcd(&ehci_mxc_hc_driver, dev, dev_name(dev)); | |
68 | if (!hcd) | |
69 | return -ENOMEM; | |
70 | ||
7e8d5cd9 | 71 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
148e1134 TR |
72 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
73 | if (IS_ERR(hcd->regs)) { | |
74 | ret = PTR_ERR(hcd->regs); | |
af09c060 | 75 | goto err_alloc; |
7e8d5cd9 | 76 | } |
d6e269ae VB |
77 | hcd->rsrc_start = res->start; |
78 | hcd->rsrc_len = resource_size(res); | |
7e8d5cd9 | 79 | |
dba63b2f AS |
80 | hcd->has_tt = 1; |
81 | ehci = hcd_to_ehci(hcd); | |
82 | priv = (struct ehci_mxc_priv *) ehci->priv; | |
83 | ||
7e8d5cd9 | 84 | /* enable clocks */ |
af09c060 | 85 | priv->usbclk = devm_clk_get(&pdev->dev, "ipg"); |
7e8d5cd9 DM |
86 | if (IS_ERR(priv->usbclk)) { |
87 | ret = PTR_ERR(priv->usbclk); | |
af09c060 | 88 | goto err_alloc; |
7e8d5cd9 | 89 | } |
198ad2ce | 90 | clk_prepare_enable(priv->usbclk); |
7e8d5cd9 | 91 | |
af09c060 | 92 | priv->ahbclk = devm_clk_get(&pdev->dev, "ahb"); |
c943740c SH |
93 | if (IS_ERR(priv->ahbclk)) { |
94 | ret = PTR_ERR(priv->ahbclk); | |
95 | goto err_clk_ahb; | |
7e8d5cd9 | 96 | } |
c943740c | 97 | clk_prepare_enable(priv->ahbclk); |
7e8d5cd9 | 98 | |
3bb8029a | 99 | /* "dr" device has its own clock on i.MX51 */ |
af09c060 | 100 | priv->phyclk = devm_clk_get(&pdev->dev, "phy"); |
c943740c SH |
101 | if (IS_ERR(priv->phyclk)) |
102 | priv->phyclk = NULL; | |
103 | if (priv->phyclk) | |
104 | clk_prepare_enable(priv->phyclk); | |
711669e5 APR |
105 | |
106 | ||
107 | /* call platform specific init function */ | |
108 | if (pdata->init) { | |
109 | ret = pdata->init(pdev); | |
110 | if (ret) { | |
111 | dev_err(dev, "platform init failed\n"); | |
112 | goto err_init; | |
113 | } | |
114 | /* platforms need some time to settle changed IO settings */ | |
115 | mdelay(10); | |
116 | } | |
117 | ||
0247a7bc FE |
118 | /* EHCI registers start at offset 0x100 */ |
119 | ehci->caps = hcd->regs + 0x100; | |
120 | ehci->regs = hcd->regs + 0x100 + | |
c430131a | 121 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
0247a7bc FE |
122 | |
123 | /* set up the PORTSCx register */ | |
124 | ehci_writel(ehci, pdata->portsc, &ehci->regs->port_status[0]); | |
125 | ||
126 | /* is this really needed? */ | |
127 | msleep(10); | |
128 | ||
7e8d5cd9 DM |
129 | /* Initialize the transceiver */ |
130 | if (pdata->otg) { | |
131 | pdata->otg->io_priv = hcd->regs + ULPI_VIEWPORT_OFFSET; | |
b96d3b08 | 132 | ret = usb_phy_init(pdata->otg); |
4c9715de WS |
133 | if (ret) { |
134 | dev_err(dev, "unable to init transceiver, probably missing\n"); | |
135 | ret = -ENODEV; | |
136 | goto err_add; | |
137 | } | |
6e13c650 | 138 | ret = otg_set_vbus(pdata->otg->otg, 1); |
4c9715de | 139 | if (ret) { |
7e8d5cd9 | 140 | dev_err(dev, "unable to enable vbus on transceiver\n"); |
4c9715de WS |
141 | goto err_add; |
142 | } | |
7e8d5cd9 DM |
143 | } |
144 | ||
dba63b2f | 145 | platform_set_drvdata(pdev, hcd); |
7e8d5cd9 | 146 | |
b5dd18d8 | 147 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
7e8d5cd9 DM |
148 | if (ret) |
149 | goto err_add; | |
150 | ||
3c9740a1 | 151 | device_wakeup_enable(hcd->self.controller); |
7e8d5cd9 DM |
152 | return 0; |
153 | ||
154 | err_add: | |
155 | if (pdata && pdata->exit) | |
156 | pdata->exit(pdev); | |
157 | err_init: | |
af09c060 | 158 | if (priv->phyclk) |
c943740c | 159 | clk_disable_unprepare(priv->phyclk); |
c943740c SH |
160 | |
161 | clk_disable_unprepare(priv->ahbclk); | |
7e8d5cd9 | 162 | err_clk_ahb: |
198ad2ce | 163 | clk_disable_unprepare(priv->usbclk); |
7e8d5cd9 DM |
164 | err_alloc: |
165 | usb_put_hcd(hcd); | |
166 | return ret; | |
167 | } | |
168 | ||
39d35681 | 169 | static int ehci_mxc_drv_remove(struct platform_device *pdev) |
7e8d5cd9 | 170 | { |
d4f09e28 | 171 | struct mxc_usbh_platform_data *pdata = dev_get_platdata(&pdev->dev); |
dba63b2f AS |
172 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
173 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | |
174 | struct ehci_mxc_priv *priv = (struct ehci_mxc_priv *) ehci->priv; | |
175 | ||
176 | usb_remove_hcd(hcd); | |
7e8d5cd9 DM |
177 | |
178 | if (pdata && pdata->exit) | |
179 | pdata->exit(pdev); | |
180 | ||
f375fc52 | 181 | if (pdata && pdata->otg) |
b96d3b08 | 182 | usb_phy_shutdown(pdata->otg); |
7e8d5cd9 | 183 | |
198ad2ce | 184 | clk_disable_unprepare(priv->usbclk); |
c943740c | 185 | clk_disable_unprepare(priv->ahbclk); |
c943740c | 186 | |
af09c060 | 187 | if (priv->phyclk) |
c943740c | 188 | clk_disable_unprepare(priv->phyclk); |
7e8d5cd9 | 189 | |
dba63b2f | 190 | usb_put_hcd(hcd); |
7e8d5cd9 DM |
191 | return 0; |
192 | } | |
193 | ||
7e8d5cd9 DM |
194 | MODULE_ALIAS("platform:mxc-ehci"); |
195 | ||
196 | static struct platform_driver ehci_mxc_driver = { | |
197 | .probe = ehci_mxc_drv_probe, | |
dba63b2f | 198 | .remove = ehci_mxc_drv_remove, |
aaf6b52d | 199 | .shutdown = usb_hcd_platform_shutdown, |
7e8d5cd9 DM |
200 | .driver = { |
201 | .name = "mxc-ehci", | |
202 | }, | |
203 | }; | |
dba63b2f AS |
204 | |
205 | static int __init ehci_mxc_init(void) | |
206 | { | |
207 | if (usb_disabled()) | |
208 | return -ENODEV; | |
209 | ||
210 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | |
211 | ||
212 | ehci_init_driver(&ehci_mxc_hc_driver, &ehci_mxc_overrides); | |
213 | return platform_driver_register(&ehci_mxc_driver); | |
214 | } | |
215 | module_init(ehci_mxc_init); | |
216 | ||
217 | static void __exit ehci_mxc_cleanup(void) | |
218 | { | |
219 | platform_driver_unregister(&ehci_mxc_driver); | |
220 | } | |
221 | module_exit(ehci_mxc_cleanup); | |
222 | ||
223 | MODULE_DESCRIPTION(DRIVER_DESC); | |
224 | MODULE_AUTHOR("Sascha Hauer"); | |
225 | MODULE_LICENSE("GPL"); |