Commit | Line | Data |
---|---|---|
550a7375 FB |
1 | /* |
2 | * Copyright (C) 2005-2007 by Texas Instruments | |
3 | * Some code has been taken from tusb6010.c | |
4 | * Copyrights for that are attributable to: | |
5 | * Copyright (C) 2006 Nokia Corporation | |
550a7375 FB |
6 | * Tony Lindgren <tony@atomide.com> |
7 | * | |
8 | * This file is part of the Inventra Controller Driver for Linux. | |
9 | * | |
10 | * The Inventra Controller Driver for Linux is free software; you | |
11 | * can redistribute it and/or modify it under the terms of the GNU | |
12 | * General Public License version 2 as published by the Free Software | |
13 | * Foundation. | |
14 | * | |
15 | * The Inventra Controller Driver for Linux is distributed in | |
16 | * the hope that it will be useful, but WITHOUT ANY WARRANTY; | |
17 | * without even the implied warranty of MERCHANTABILITY or | |
18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | |
19 | * License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with The Inventra Controller Driver for Linux ; if not, | |
23 | * write to the Free Software Foundation, Inc., 59 Temple Place, | |
24 | * Suite 330, Boston, MA 02111-1307 USA | |
25 | * | |
26 | */ | |
27 | #include <linux/module.h> | |
28 | #include <linux/kernel.h> | |
29 | #include <linux/sched.h> | |
550a7375 FB |
30 | #include <linux/init.h> |
31 | #include <linux/list.h> | |
550a7375 | 32 | #include <linux/io.h> |
00a0b1d5 | 33 | #include <linux/of.h> |
dc09886b FB |
34 | #include <linux/platform_device.h> |
35 | #include <linux/dma-mapping.h> | |
207b0e1f HH |
36 | #include <linux/pm_runtime.h> |
37 | #include <linux/err.h> | |
12a19b5f | 38 | #include <linux/delay.h> |
c9721438 | 39 | #include <linux/usb/musb-omap.h> |
ca784be3 | 40 | #include <linux/usb/omap_control_usb.h> |
8934d3e4 | 41 | #include <linux/of_platform.h> |
550a7375 | 42 | |
550a7375 FB |
43 | #include "musb_core.h" |
44 | #include "omap2430.h" | |
45 | ||
a3cee12a FB |
46 | struct omap2430_glue { |
47 | struct device *dev; | |
48 | struct platform_device *musb; | |
c9721438 | 49 | enum omap_musb_vbus_id_status status; |
1e5acb8d | 50 | struct work_struct omap_musb_mailbox_work; |
ca784be3 | 51 | struct device *control_otghs; |
a3cee12a | 52 | }; |
c20aebb9 | 53 | #define glue_to_musb(g) platform_get_drvdata(g->musb) |
a3cee12a | 54 | |
4b58ed11 | 55 | static struct omap2430_glue *_glue; |
c9721438 | 56 | |
550a7375 FB |
57 | static struct timer_list musb_idle_timer; |
58 | ||
59 | static void musb_do_idle(unsigned long _musb) | |
60 | { | |
61 | struct musb *musb = (void *)_musb; | |
62 | unsigned long flags; | |
63 | u8 power; | |
64 | u8 devctl; | |
65 | ||
550a7375 FB |
66 | spin_lock_irqsave(&musb->lock, flags); |
67 | ||
84e250ff | 68 | switch (musb->xceiv->state) { |
550a7375 | 69 | case OTG_STATE_A_WAIT_BCON: |
550a7375 FB |
70 | |
71 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | |
72 | if (devctl & MUSB_DEVCTL_BDEVICE) { | |
84e250ff | 73 | musb->xceiv->state = OTG_STATE_B_IDLE; |
550a7375 FB |
74 | MUSB_DEV_MODE(musb); |
75 | } else { | |
84e250ff | 76 | musb->xceiv->state = OTG_STATE_A_IDLE; |
550a7375 FB |
77 | MUSB_HST_MODE(musb); |
78 | } | |
79 | break; | |
550a7375 FB |
80 | case OTG_STATE_A_SUSPEND: |
81 | /* finish RESUME signaling? */ | |
82 | if (musb->port1_status & MUSB_PORT_STAT_RESUME) { | |
83 | power = musb_readb(musb->mregs, MUSB_POWER); | |
84 | power &= ~MUSB_POWER_RESUME; | |
5c8a86e1 | 85 | dev_dbg(musb->controller, "root port resume stopped, power %02x\n", power); |
550a7375 FB |
86 | musb_writeb(musb->mregs, MUSB_POWER, power); |
87 | musb->is_active = 1; | |
88 | musb->port1_status &= ~(USB_PORT_STAT_SUSPEND | |
89 | | MUSB_PORT_STAT_RESUME); | |
90 | musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; | |
8b125df5 | 91 | usb_hcd_poll_rh_status(musb->hcd); |
550a7375 | 92 | /* NOTE: it might really be A_WAIT_BCON ... */ |
84e250ff | 93 | musb->xceiv->state = OTG_STATE_A_HOST; |
550a7375 FB |
94 | } |
95 | break; | |
550a7375 FB |
96 | case OTG_STATE_A_HOST: |
97 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | |
98 | if (devctl & MUSB_DEVCTL_BDEVICE) | |
84e250ff | 99 | musb->xceiv->state = OTG_STATE_B_IDLE; |
550a7375 | 100 | else |
84e250ff | 101 | musb->xceiv->state = OTG_STATE_A_WAIT_BCON; |
550a7375 FB |
102 | default: |
103 | break; | |
104 | } | |
105 | spin_unlock_irqrestore(&musb->lock, flags); | |
106 | } | |
107 | ||
108 | ||
743411b3 | 109 | static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout) |
550a7375 FB |
110 | { |
111 | unsigned long default_timeout = jiffies + msecs_to_jiffies(3); | |
112 | static unsigned long last_timer; | |
113 | ||
114 | if (timeout == 0) | |
115 | timeout = default_timeout; | |
116 | ||
117 | /* Never idle if active, or when VBUS timeout is not set as host */ | |
118 | if (musb->is_active || ((musb->a_wait_bcon == 0) | |
84e250ff | 119 | && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { |
5c8a86e1 | 120 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
42c0bf1c | 121 | usb_otg_state_string(musb->xceiv->state)); |
550a7375 FB |
122 | del_timer(&musb_idle_timer); |
123 | last_timer = jiffies; | |
124 | return; | |
125 | } | |
126 | ||
127 | if (time_after(last_timer, timeout)) { | |
128 | if (!timer_pending(&musb_idle_timer)) | |
129 | last_timer = timeout; | |
130 | else { | |
5c8a86e1 | 131 | dev_dbg(musb->controller, "Longer idle timer already pending, ignoring\n"); |
550a7375 FB |
132 | return; |
133 | } | |
134 | } | |
135 | last_timer = timeout; | |
136 | ||
5c8a86e1 | 137 | dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", |
42c0bf1c | 138 | usb_otg_state_string(musb->xceiv->state), |
550a7375 FB |
139 | (unsigned long)jiffies_to_msecs(timeout - jiffies)); |
140 | mod_timer(&musb_idle_timer, timeout); | |
141 | } | |
142 | ||
743411b3 | 143 | static void omap2430_musb_set_vbus(struct musb *musb, int is_on) |
550a7375 | 144 | { |
d445b6da | 145 | struct usb_otg *otg = musb->xceiv->otg; |
550a7375 | 146 | u8 devctl; |
594632ef | 147 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
550a7375 FB |
148 | /* HDRC controls CPEN, but beware current surges during device |
149 | * connect. They can trigger transient overcurrent conditions | |
150 | * that must be ignored. | |
151 | */ | |
152 | ||
153 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | |
154 | ||
155 | if (is_on) { | |
594632ef | 156 | if (musb->xceiv->state == OTG_STATE_A_IDLE) { |
12a19b5f | 157 | int loops = 100; |
594632ef HH |
158 | /* start the session */ |
159 | devctl |= MUSB_DEVCTL_SESSION; | |
160 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | |
161 | /* | |
162 | * Wait for the musb to set as A device to enable the | |
163 | * VBUS | |
164 | */ | |
165 | while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) { | |
166 | ||
12a19b5f | 167 | mdelay(5); |
594632ef HH |
168 | cpu_relax(); |
169 | ||
12a19b5f N |
170 | if (time_after(jiffies, timeout) |
171 | || loops-- <= 0) { | |
594632ef HH |
172 | dev_err(musb->controller, |
173 | "configured as A device timeout"); | |
594632ef HH |
174 | break; |
175 | } | |
176 | } | |
177 | ||
bb467cf5 | 178 | otg_set_vbus(otg, 1); |
594632ef HH |
179 | } else { |
180 | musb->is_active = 1; | |
d445b6da | 181 | otg->default_a = 1; |
594632ef HH |
182 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; |
183 | devctl |= MUSB_DEVCTL_SESSION; | |
184 | MUSB_HST_MODE(musb); | |
185 | } | |
550a7375 FB |
186 | } else { |
187 | musb->is_active = 0; | |
188 | ||
189 | /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and | |
190 | * jumping right to B_IDLE... | |
191 | */ | |
192 | ||
d445b6da | 193 | otg->default_a = 0; |
84e250ff | 194 | musb->xceiv->state = OTG_STATE_B_IDLE; |
550a7375 FB |
195 | devctl &= ~MUSB_DEVCTL_SESSION; |
196 | ||
197 | MUSB_DEV_MODE(musb); | |
198 | } | |
199 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | |
200 | ||
5c8a86e1 | 201 | dev_dbg(musb->controller, "VBUS %s, devctl %02x " |
550a7375 | 202 | /* otg %3x conf %08x prcm %08x */ "\n", |
42c0bf1c | 203 | usb_otg_state_string(musb->xceiv->state), |
550a7375 FB |
204 | musb_readb(musb->mregs, MUSB_DEVCTL)); |
205 | } | |
550a7375 | 206 | |
743411b3 | 207 | static int omap2430_musb_set_mode(struct musb *musb, u8 musb_mode) |
550a7375 FB |
208 | { |
209 | u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | |
210 | ||
211 | devctl |= MUSB_DEVCTL_SESSION; | |
212 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | |
213 | ||
96a274d1 | 214 | return 0; |
550a7375 FB |
215 | } |
216 | ||
c20aebb9 FB |
217 | static inline void omap2430_low_level_exit(struct musb *musb) |
218 | { | |
219 | u32 l; | |
220 | ||
221 | /* in any role */ | |
222 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); | |
223 | l |= ENABLEFORCE; /* enable MSTANDBY */ | |
224 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); | |
c20aebb9 FB |
225 | } |
226 | ||
227 | static inline void omap2430_low_level_init(struct musb *musb) | |
228 | { | |
229 | u32 l; | |
230 | ||
c20aebb9 FB |
231 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); |
232 | l &= ~ENABLEFORCE; /* disable MSTANDBY */ | |
233 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); | |
234 | } | |
235 | ||
c9721438 | 236 | void omap_musb_mailbox(enum omap_musb_vbus_id_status status) |
594632ef | 237 | { |
c9721438 | 238 | struct omap2430_glue *glue = _glue; |
712d8efa | 239 | |
f8c4b0e7 AK |
240 | if (!glue) { |
241 | pr_err("%s: musb core is not yet initialized\n", __func__); | |
242 | return; | |
243 | } | |
244 | glue->status = status; | |
245 | ||
246 | if (!glue_to_musb(glue)) { | |
80ab72e1 | 247 | pr_err("%s: musb core is not yet ready\n", __func__); |
c9721438 KVA |
248 | return; |
249 | } | |
712d8efa | 250 | |
c9721438 | 251 | schedule_work(&glue->omap_musb_mailbox_work); |
712d8efa | 252 | } |
c9721438 | 253 | EXPORT_SYMBOL_GPL(omap_musb_mailbox); |
712d8efa | 254 | |
c9721438 | 255 | static void omap_musb_set_mailbox(struct omap2430_glue *glue) |
712d8efa | 256 | { |
1e5acb8d | 257 | struct musb *musb = glue_to_musb(glue); |
594632ef | 258 | struct device *dev = musb->controller; |
c1a7d67c | 259 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev); |
594632ef | 260 | struct omap_musb_board_data *data = pdata->board_data; |
c83a8542 | 261 | struct usb_otg *otg = musb->xceiv->otg; |
594632ef | 262 | |
c9721438 KVA |
263 | switch (glue->status) { |
264 | case OMAP_MUSB_ID_GROUND: | |
265 | dev_dbg(dev, "ID GND\n"); | |
594632ef | 266 | |
c83a8542 KVA |
267 | otg->default_a = true; |
268 | musb->xceiv->state = OTG_STATE_A_IDLE; | |
c9721438 | 269 | musb->xceiv->last_event = USB_EVENT_ID; |
032ec49f | 270 | if (musb->gadget_driver) { |
c9721438 | 271 | pm_runtime_get_sync(dev); |
ca784be3 KVA |
272 | omap_control_usb_set_mode(glue->control_otghs, |
273 | USB_MODE_HOST); | |
70045c57 | 274 | omap2430_musb_set_vbus(musb, 1); |
594632ef HH |
275 | } |
276 | break; | |
277 | ||
c9721438 KVA |
278 | case OMAP_MUSB_VBUS_VALID: |
279 | dev_dbg(dev, "VBUS Connect\n"); | |
594632ef | 280 | |
c83a8542 KVA |
281 | otg->default_a = false; |
282 | musb->xceiv->state = OTG_STATE_B_IDLE; | |
c9721438 | 283 | musb->xceiv->last_event = USB_EVENT_VBUS; |
7acc6197 | 284 | if (musb->gadget_driver) |
c9721438 | 285 | pm_runtime_get_sync(dev); |
ca784be3 | 286 | omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE); |
594632ef HH |
287 | break; |
288 | ||
c9721438 KVA |
289 | case OMAP_MUSB_ID_FLOAT: |
290 | case OMAP_MUSB_VBUS_OFF: | |
291 | dev_dbg(dev, "VBUS Disconnect\n"); | |
594632ef | 292 | |
c9721438 | 293 | musb->xceiv->last_event = USB_EVENT_NONE; |
032ec49f | 294 | if (musb->gadget_driver) { |
2c1fe89d | 295 | omap2430_musb_set_vbus(musb, 0); |
032ec49f FB |
296 | pm_runtime_mark_last_busy(dev); |
297 | pm_runtime_put_autosuspend(dev); | |
298 | } | |
7acc6197 | 299 | |
bb467cf5 KVA |
300 | if (data->interface_type == MUSB_INTERFACE_UTMI) |
301 | otg_set_vbus(musb->xceiv->otg, 0); | |
302 | ||
ca784be3 KVA |
303 | omap_control_usb_set_mode(glue->control_otghs, |
304 | USB_MODE_DISCONNECT); | |
594632ef HH |
305 | break; |
306 | default: | |
c9721438 | 307 | dev_dbg(dev, "ID float\n"); |
594632ef | 308 | } |
6fa7178c PR |
309 | |
310 | atomic_notifier_call_chain(&musb->xceiv->notifier, | |
311 | musb->xceiv->last_event, NULL); | |
594632ef HH |
312 | } |
313 | ||
c9721438 KVA |
314 | |
315 | static void omap_musb_mailbox_work(struct work_struct *mailbox_work) | |
316 | { | |
317 | struct omap2430_glue *glue = container_of(mailbox_work, | |
318 | struct omap2430_glue, omap_musb_mailbox_work); | |
319 | omap_musb_set_mailbox(glue); | |
320 | } | |
321 | ||
baef653a PDS |
322 | static irqreturn_t omap2430_musb_interrupt(int irq, void *__hci) |
323 | { | |
324 | unsigned long flags; | |
325 | irqreturn_t retval = IRQ_NONE; | |
326 | struct musb *musb = __hci; | |
327 | ||
328 | spin_lock_irqsave(&musb->lock, flags); | |
329 | ||
330 | musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); | |
331 | musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); | |
332 | musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); | |
333 | ||
334 | if (musb->int_usb || musb->int_tx || musb->int_rx) | |
335 | retval = musb_interrupt(musb); | |
336 | ||
337 | spin_unlock_irqrestore(&musb->lock, flags); | |
338 | ||
339 | return retval; | |
340 | } | |
341 | ||
743411b3 | 342 | static int omap2430_musb_init(struct musb *musb) |
550a7375 | 343 | { |
ad579699 S |
344 | u32 l; |
345 | int status = 0; | |
ea65df57 | 346 | struct device *dev = musb->controller; |
c9721438 | 347 | struct omap2430_glue *glue = dev_get_drvdata(dev->parent); |
c1a7d67c | 348 | struct musb_hdrc_platform_data *plat = dev_get_platdata(dev); |
ea65df57 | 349 | struct omap_musb_board_data *data = plat->board_data; |
550a7375 | 350 | |
84e250ff DB |
351 | /* We require some kind of external transceiver, hooked |
352 | * up through ULPI. TWL4030-family PMICs include one, | |
353 | * which needs a driver, drivers aren't always needed. | |
354 | */ | |
3e3101d5 KVA |
355 | if (dev->parent->of_node) { |
356 | musb->phy = devm_phy_get(dev->parent, "usb2-phy"); | |
357 | ||
358 | /* We can't totally remove musb->xceiv as of now because | |
359 | * musb core uses xceiv.state and xceiv.otg. Once we have | |
360 | * a separate state machine to handle otg, these can be moved | |
361 | * out of xceiv and then we can start using the generic PHY | |
362 | * framework | |
363 | */ | |
b16604f2 KVA |
364 | musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent, |
365 | "usb-phy", 0); | |
3e3101d5 | 366 | } else { |
b16604f2 | 367 | musb->xceiv = devm_usb_get_phy_dev(dev, 0); |
3e3101d5 KVA |
368 | musb->phy = devm_phy_get(dev, "usb"); |
369 | } | |
b16604f2 | 370 | |
a90199bb FB |
371 | if (IS_ERR(musb->xceiv)) { |
372 | status = PTR_ERR(musb->xceiv); | |
373 | ||
374 | if (status == -ENXIO) | |
375 | return status; | |
376 | ||
84e250ff | 377 | pr_err("HS USB OTG: no transceiver configured\n"); |
25736e0c | 378 | return -EPROBE_DEFER; |
84e250ff DB |
379 | } |
380 | ||
3e3101d5 KVA |
381 | if (IS_ERR(musb->phy)) { |
382 | pr_err("HS USB OTG: no PHY configured\n"); | |
383 | return PTR_ERR(musb->phy); | |
384 | } | |
baef653a PDS |
385 | musb->isr = omap2430_musb_interrupt; |
386 | ||
7acc6197 HH |
387 | status = pm_runtime_get_sync(dev); |
388 | if (status < 0) { | |
ad579699 | 389 | dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status); |
7acc6197 HH |
390 | goto err1; |
391 | } | |
550a7375 | 392 | |
8573e6a6 | 393 | l = musb_readl(musb->mregs, OTG_INTERFSEL); |
de2e1b0c MM |
394 | |
395 | if (data->interface_type == MUSB_INTERFACE_UTMI) { | |
396 | /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */ | |
397 | l &= ~ULPI_12PIN; /* Disable ULPI */ | |
398 | l |= UTMI_8BIT; /* Enable UTMI */ | |
399 | } else { | |
400 | l |= ULPI_12PIN; | |
401 | } | |
402 | ||
8573e6a6 | 403 | musb_writel(musb->mregs, OTG_INTERFSEL, l); |
550a7375 FB |
404 | |
405 | pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, " | |
406 | "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n", | |
8573e6a6 FB |
407 | musb_readl(musb->mregs, OTG_REVISION), |
408 | musb_readl(musb->mregs, OTG_SYSCONFIG), | |
409 | musb_readl(musb->mregs, OTG_SYSSTATUS), | |
410 | musb_readl(musb->mregs, OTG_INTERFSEL), | |
411 | musb_readl(musb->mregs, OTG_SIMENABLE)); | |
550a7375 | 412 | |
550a7375 FB |
413 | setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); |
414 | ||
c9721438 KVA |
415 | if (glue->status != OMAP_MUSB_UNKNOWN) |
416 | omap_musb_set_mailbox(glue); | |
417 | ||
3e3101d5 | 418 | phy_init(musb->phy); |
3bf6db9b | 419 | |
c04352a5 | 420 | pm_runtime_put_noidle(musb->controller); |
550a7375 | 421 | return 0; |
7acc6197 HH |
422 | |
423 | err1: | |
7acc6197 | 424 | return status; |
550a7375 FB |
425 | } |
426 | ||
002eda13 HH |
427 | static void omap2430_musb_enable(struct musb *musb) |
428 | { | |
429 | u8 devctl; | |
430 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); | |
431 | struct device *dev = musb->controller; | |
c9721438 | 432 | struct omap2430_glue *glue = dev_get_drvdata(dev->parent); |
c1a7d67c | 433 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev); |
002eda13 HH |
434 | struct omap_musb_board_data *data = pdata->board_data; |
435 | ||
c9721438 | 436 | switch (glue->status) { |
002eda13 | 437 | |
c9721438 | 438 | case OMAP_MUSB_ID_GROUND: |
ca784be3 | 439 | omap_control_usb_set_mode(glue->control_otghs, USB_MODE_HOST); |
08dec56e FC |
440 | if (data->interface_type != MUSB_INTERFACE_UTMI) |
441 | break; | |
442 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | |
443 | /* start the session */ | |
444 | devctl |= MUSB_DEVCTL_SESSION; | |
445 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | |
446 | while (musb_readb(musb->mregs, MUSB_DEVCTL) & | |
447 | MUSB_DEVCTL_BDEVICE) { | |
448 | cpu_relax(); | |
449 | ||
450 | if (time_after(jiffies, timeout)) { | |
451 | dev_err(dev, "configured as A device timeout"); | |
452 | break; | |
002eda13 HH |
453 | } |
454 | } | |
455 | break; | |
456 | ||
c9721438 | 457 | case OMAP_MUSB_VBUS_VALID: |
ca784be3 | 458 | omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE); |
002eda13 HH |
459 | break; |
460 | ||
461 | default: | |
462 | break; | |
463 | } | |
464 | } | |
465 | ||
466 | static void omap2430_musb_disable(struct musb *musb) | |
467 | { | |
c9721438 KVA |
468 | struct device *dev = musb->controller; |
469 | struct omap2430_glue *glue = dev_get_drvdata(dev->parent); | |
470 | ||
ca784be3 KVA |
471 | if (glue->status != OMAP_MUSB_UNKNOWN) |
472 | omap_control_usb_set_mode(glue->control_otghs, | |
473 | USB_MODE_DISCONNECT); | |
550a7375 FB |
474 | } |
475 | ||
743411b3 | 476 | static int omap2430_musb_exit(struct musb *musb) |
550a7375 | 477 | { |
19b9a83e | 478 | del_timer_sync(&musb_idle_timer); |
550a7375 | 479 | |
c20aebb9 | 480 | omap2430_low_level_exit(musb); |
3e3101d5 | 481 | phy_exit(musb->phy); |
c20aebb9 | 482 | |
550a7375 FB |
483 | return 0; |
484 | } | |
743411b3 | 485 | |
f7ec9437 | 486 | static const struct musb_platform_ops omap2430_ops = { |
743411b3 FB |
487 | .init = omap2430_musb_init, |
488 | .exit = omap2430_musb_exit, | |
489 | ||
743411b3 FB |
490 | .set_mode = omap2430_musb_set_mode, |
491 | .try_idle = omap2430_musb_try_idle, | |
492 | ||
493 | .set_vbus = omap2430_musb_set_vbus, | |
002eda13 HH |
494 | |
495 | .enable = omap2430_musb_enable, | |
496 | .disable = omap2430_musb_disable, | |
743411b3 | 497 | }; |
dc09886b FB |
498 | |
499 | static u64 omap2430_dmamask = DMA_BIT_MASK(32); | |
500 | ||
41ac7b3a | 501 | static int omap2430_probe(struct platform_device *pdev) |
dc09886b | 502 | { |
c1f01be4 | 503 | struct resource musb_resources[3]; |
c1a7d67c | 504 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); |
00a0b1d5 | 505 | struct omap_musb_board_data *data; |
dc09886b | 506 | struct platform_device *musb; |
a3cee12a | 507 | struct omap2430_glue *glue; |
00a0b1d5 KVA |
508 | struct device_node *np = pdev->dev.of_node; |
509 | struct musb_hdrc_config *config; | |
dc09886b FB |
510 | int ret = -ENOMEM; |
511 | ||
b1183c24 | 512 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
a3cee12a FB |
513 | if (!glue) { |
514 | dev_err(&pdev->dev, "failed to allocate glue context\n"); | |
515 | goto err0; | |
516 | } | |
517 | ||
2f771164 | 518 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); |
dc09886b FB |
519 | if (!musb) { |
520 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | |
2f771164 | 521 | goto err0; |
dc09886b FB |
522 | } |
523 | ||
524 | musb->dev.parent = &pdev->dev; | |
525 | musb->dev.dma_mask = &omap2430_dmamask; | |
526 | musb->dev.coherent_dma_mask = omap2430_dmamask; | |
527 | ||
a3cee12a FB |
528 | glue->dev = &pdev->dev; |
529 | glue->musb = musb; | |
c9721438 | 530 | glue->status = OMAP_MUSB_UNKNOWN; |
8934d3e4 | 531 | glue->control_otghs = ERR_PTR(-ENODEV); |
a3cee12a | 532 | |
00a0b1d5 | 533 | if (np) { |
8934d3e4 RQ |
534 | struct device_node *control_node; |
535 | struct platform_device *control_pdev; | |
536 | ||
00a0b1d5 KVA |
537 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
538 | if (!pdata) { | |
539 | dev_err(&pdev->dev, | |
8b513d0c | 540 | "failed to allocate musb platform data\n"); |
2f771164 | 541 | goto err2; |
00a0b1d5 KVA |
542 | } |
543 | ||
544 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | |
545 | if (!data) { | |
546 | dev_err(&pdev->dev, | |
8df4ce75 | 547 | "failed to allocate musb board data\n"); |
2f771164 | 548 | goto err2; |
00a0b1d5 KVA |
549 | } |
550 | ||
551 | config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL); | |
b37457d8 | 552 | if (!config) { |
00a0b1d5 KVA |
553 | dev_err(&pdev->dev, |
554 | "failed to allocate musb hdrc config\n"); | |
2f771164 | 555 | goto err2; |
00a0b1d5 KVA |
556 | } |
557 | ||
558 | of_property_read_u32(np, "mode", (u32 *)&pdata->mode); | |
eee44da0 | 559 | of_property_read_u32(np, "interface-type", |
00a0b1d5 | 560 | (u32 *)&data->interface_type); |
eee44da0 KVA |
561 | of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps); |
562 | of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits); | |
00a0b1d5 KVA |
563 | of_property_read_u32(np, "power", (u32 *)&pdata->power); |
564 | config->multipoint = of_property_read_bool(np, "multipoint"); | |
565 | ||
566 | pdata->board_data = data; | |
567 | pdata->config = config; | |
00a0b1d5 | 568 | |
8934d3e4 RQ |
569 | control_node = of_parse_phandle(np, "ctrl-module", 0); |
570 | if (control_node) { | |
571 | control_pdev = of_find_device_by_node(control_node); | |
572 | if (!control_pdev) { | |
573 | dev_err(&pdev->dev, "Failed to get control device\n"); | |
574 | ret = -EINVAL; | |
575 | goto err2; | |
576 | } | |
577 | glue->control_otghs = &control_pdev->dev; | |
ca784be3 | 578 | } |
ca784be3 | 579 | } |
f7ec9437 FB |
580 | pdata->platform_ops = &omap2430_ops; |
581 | ||
a3cee12a | 582 | platform_set_drvdata(pdev, glue); |
dc09886b | 583 | |
c9721438 KVA |
584 | /* |
585 | * REVISIT if we ever have two instances of the wrapper, we will be | |
586 | * in big trouble | |
587 | */ | |
588 | _glue = glue; | |
589 | ||
1e5acb8d KVA |
590 | INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work); |
591 | ||
3a0ddc71 | 592 | memset(musb_resources, 0x00, sizeof(*musb_resources) * |
09fc7d22 FB |
593 | ARRAY_SIZE(musb_resources)); |
594 | ||
595 | musb_resources[0].name = pdev->resource[0].name; | |
596 | musb_resources[0].start = pdev->resource[0].start; | |
597 | musb_resources[0].end = pdev->resource[0].end; | |
598 | musb_resources[0].flags = pdev->resource[0].flags; | |
599 | ||
600 | musb_resources[1].name = pdev->resource[1].name; | |
601 | musb_resources[1].start = pdev->resource[1].start; | |
602 | musb_resources[1].end = pdev->resource[1].end; | |
603 | musb_resources[1].flags = pdev->resource[1].flags; | |
604 | ||
c1f01be4 KVA |
605 | musb_resources[2].name = pdev->resource[2].name; |
606 | musb_resources[2].start = pdev->resource[2].start; | |
607 | musb_resources[2].end = pdev->resource[2].end; | |
608 | musb_resources[2].flags = pdev->resource[2].flags; | |
609 | ||
09fc7d22 FB |
610 | ret = platform_device_add_resources(musb, musb_resources, |
611 | ARRAY_SIZE(musb_resources)); | |
dc09886b FB |
612 | if (ret) { |
613 | dev_err(&pdev->dev, "failed to add resources\n"); | |
65b3d52d | 614 | goto err2; |
dc09886b FB |
615 | } |
616 | ||
617 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | |
618 | if (ret) { | |
619 | dev_err(&pdev->dev, "failed to add platform_data\n"); | |
65b3d52d | 620 | goto err2; |
dc09886b FB |
621 | } |
622 | ||
3006dc8c KVA |
623 | pm_runtime_enable(&pdev->dev); |
624 | ||
dc09886b FB |
625 | ret = platform_device_add(musb); |
626 | if (ret) { | |
627 | dev_err(&pdev->dev, "failed to register musb device\n"); | |
65b3d52d | 628 | goto err2; |
dc09886b FB |
629 | } |
630 | ||
207b0e1f | 631 | return 0; |
03491761 | 632 | |
65b3d52d | 633 | err2: |
b1183c24 | 634 | platform_device_put(musb); |
a3cee12a | 635 | |
dc09886b FB |
636 | err0: |
637 | return ret; | |
638 | } | |
639 | ||
fb4e98ab | 640 | static int omap2430_remove(struct platform_device *pdev) |
dc09886b | 641 | { |
a3cee12a | 642 | struct omap2430_glue *glue = platform_get_drvdata(pdev); |
dc09886b | 643 | |
1e5acb8d | 644 | cancel_work_sync(&glue->omap_musb_mailbox_work); |
f039df58 | 645 | platform_device_unregister(glue->musb); |
dc09886b FB |
646 | |
647 | return 0; | |
648 | } | |
649 | ||
c20aebb9 | 650 | #ifdef CONFIG_PM |
c20aebb9 | 651 | |
7acc6197 | 652 | static int omap2430_runtime_suspend(struct device *dev) |
c20aebb9 FB |
653 | { |
654 | struct omap2430_glue *glue = dev_get_drvdata(dev); | |
655 | struct musb *musb = glue_to_musb(glue); | |
656 | ||
afb76df1 VZ |
657 | if (musb) { |
658 | musb->context.otg_interfsel = musb_readl(musb->mregs, | |
659 | OTG_INTERFSEL); | |
e25bec16 | 660 | |
afb76df1 | 661 | omap2430_low_level_exit(musb); |
afb76df1 | 662 | } |
c20aebb9 FB |
663 | |
664 | return 0; | |
665 | } | |
666 | ||
7acc6197 | 667 | static int omap2430_runtime_resume(struct device *dev) |
c20aebb9 FB |
668 | { |
669 | struct omap2430_glue *glue = dev_get_drvdata(dev); | |
670 | struct musb *musb = glue_to_musb(glue); | |
c20aebb9 | 671 | |
afb76df1 VZ |
672 | if (musb) { |
673 | omap2430_low_level_init(musb); | |
674 | musb_writel(musb->mregs, OTG_INTERFSEL, | |
675 | musb->context.otg_interfsel); | |
afb76df1 | 676 | } |
c20aebb9 FB |
677 | |
678 | return 0; | |
679 | } | |
680 | ||
681 | static struct dev_pm_ops omap2430_pm_ops = { | |
7acc6197 HH |
682 | .runtime_suspend = omap2430_runtime_suspend, |
683 | .runtime_resume = omap2430_runtime_resume, | |
c20aebb9 FB |
684 | }; |
685 | ||
686 | #define DEV_PM_OPS (&omap2430_pm_ops) | |
687 | #else | |
688 | #define DEV_PM_OPS NULL | |
689 | #endif | |
690 | ||
00a0b1d5 KVA |
691 | #ifdef CONFIG_OF |
692 | static const struct of_device_id omap2430_id_table[] = { | |
693 | { | |
694 | .compatible = "ti,omap4-musb" | |
695 | }, | |
696 | { | |
697 | .compatible = "ti,omap3-musb" | |
698 | }, | |
699 | {}, | |
700 | }; | |
701 | MODULE_DEVICE_TABLE(of, omap2430_id_table); | |
702 | #endif | |
703 | ||
dc09886b | 704 | static struct platform_driver omap2430_driver = { |
e9e8c85e | 705 | .probe = omap2430_probe, |
7690417d | 706 | .remove = omap2430_remove, |
dc09886b FB |
707 | .driver = { |
708 | .name = "musb-omap2430", | |
c20aebb9 | 709 | .pm = DEV_PM_OPS, |
00a0b1d5 | 710 | .of_match_table = of_match_ptr(omap2430_id_table), |
dc09886b FB |
711 | }, |
712 | }; | |
713 | ||
714 | MODULE_DESCRIPTION("OMAP2PLUS MUSB Glue Layer"); | |
715 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); | |
716 | MODULE_LICENSE("GPL v2"); | |
717 | ||
718 | static int __init omap2430_init(void) | |
719 | { | |
e9e8c85e | 720 | return platform_driver_register(&omap2430_driver); |
dc09886b | 721 | } |
c9721438 | 722 | subsys_initcall(omap2430_init); |
dc09886b FB |
723 | |
724 | static void __exit omap2430_exit(void) | |
725 | { | |
726 | platform_driver_unregister(&omap2430_driver); | |
727 | } | |
728 | module_exit(omap2430_exit); |