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> |
8055555f | 39 | #include <linux/usb/musb.h> |
14da699b | 40 | #include <linux/phy/omap_control_phy.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; | |
8055555f | 49 | enum musb_vbus_id_status status; |
1e5acb8d | 50 | struct work_struct omap_musb_mailbox_work; |
ca784be3 | 51 | struct device *control_otghs; |
21f77bee TL |
52 | bool cable_connected; |
53 | bool enabled; | |
54 | bool powered; | |
a3cee12a | 55 | }; |
c20aebb9 | 56 | #define glue_to_musb(g) platform_get_drvdata(g->musb) |
a3cee12a | 57 | |
4b58ed11 | 58 | static struct omap2430_glue *_glue; |
c9721438 | 59 | |
743411b3 | 60 | static void omap2430_musb_set_vbus(struct musb *musb, int is_on) |
550a7375 | 61 | { |
d445b6da | 62 | struct usb_otg *otg = musb->xceiv->otg; |
550a7375 | 63 | u8 devctl; |
594632ef | 64 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
550a7375 FB |
65 | /* HDRC controls CPEN, but beware current surges during device |
66 | * connect. They can trigger transient overcurrent conditions | |
67 | * that must be ignored. | |
68 | */ | |
69 | ||
70 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | |
71 | ||
72 | if (is_on) { | |
e47d9254 | 73 | if (musb->xceiv->otg->state == OTG_STATE_A_IDLE) { |
12a19b5f | 74 | int loops = 100; |
594632ef HH |
75 | /* start the session */ |
76 | devctl |= MUSB_DEVCTL_SESSION; | |
77 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | |
78 | /* | |
79 | * Wait for the musb to set as A device to enable the | |
80 | * VBUS | |
81 | */ | |
5a805309 SS |
82 | while (musb_readb(musb->mregs, MUSB_DEVCTL) & |
83 | MUSB_DEVCTL_BDEVICE) { | |
594632ef | 84 | |
12a19b5f | 85 | mdelay(5); |
594632ef HH |
86 | cpu_relax(); |
87 | ||
12a19b5f N |
88 | if (time_after(jiffies, timeout) |
89 | || loops-- <= 0) { | |
594632ef HH |
90 | dev_err(musb->controller, |
91 | "configured as A device timeout"); | |
594632ef HH |
92 | break; |
93 | } | |
94 | } | |
95 | ||
bb467cf5 | 96 | otg_set_vbus(otg, 1); |
594632ef HH |
97 | } else { |
98 | musb->is_active = 1; | |
d445b6da | 99 | otg->default_a = 1; |
e47d9254 | 100 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
594632ef HH |
101 | devctl |= MUSB_DEVCTL_SESSION; |
102 | MUSB_HST_MODE(musb); | |
103 | } | |
550a7375 FB |
104 | } else { |
105 | musb->is_active = 0; | |
106 | ||
107 | /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and | |
108 | * jumping right to B_IDLE... | |
109 | */ | |
110 | ||
d445b6da | 111 | otg->default_a = 0; |
e47d9254 | 112 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
550a7375 FB |
113 | devctl &= ~MUSB_DEVCTL_SESSION; |
114 | ||
115 | MUSB_DEV_MODE(musb); | |
116 | } | |
117 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | |
118 | ||
5c8a86e1 | 119 | dev_dbg(musb->controller, "VBUS %s, devctl %02x " |
550a7375 | 120 | /* otg %3x conf %08x prcm %08x */ "\n", |
e47d9254 | 121 | usb_otg_state_string(musb->xceiv->otg->state), |
550a7375 FB |
122 | musb_readb(musb->mregs, MUSB_DEVCTL)); |
123 | } | |
550a7375 | 124 | |
c20aebb9 FB |
125 | static inline void omap2430_low_level_exit(struct musb *musb) |
126 | { | |
127 | u32 l; | |
128 | ||
129 | /* in any role */ | |
130 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); | |
131 | l |= ENABLEFORCE; /* enable MSTANDBY */ | |
132 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); | |
c20aebb9 FB |
133 | } |
134 | ||
135 | static inline void omap2430_low_level_init(struct musb *musb) | |
136 | { | |
137 | u32 l; | |
138 | ||
c20aebb9 FB |
139 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); |
140 | l &= ~ENABLEFORCE; /* disable MSTANDBY */ | |
141 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); | |
142 | } | |
143 | ||
21f77bee TL |
144 | /* |
145 | * We can get multiple cable events so we need to keep track | |
146 | * of the power state. Only keep power enabled if USB cable is | |
147 | * connected and a gadget is started. | |
148 | */ | |
149 | static void omap2430_set_power(struct musb *musb, bool enabled, bool cable) | |
150 | { | |
151 | struct device *dev = musb->controller; | |
152 | struct omap2430_glue *glue = dev_get_drvdata(dev->parent); | |
153 | bool power_up; | |
154 | int res; | |
155 | ||
156 | if (glue->enabled != enabled) | |
157 | glue->enabled = enabled; | |
158 | ||
159 | if (glue->cable_connected != cable) | |
160 | glue->cable_connected = cable; | |
161 | ||
162 | power_up = glue->enabled && glue->cable_connected; | |
163 | if (power_up == glue->powered) { | |
164 | dev_warn(musb->controller, "power state already %i\n", | |
165 | power_up); | |
166 | return; | |
167 | } | |
168 | ||
169 | glue->powered = power_up; | |
170 | ||
171 | if (power_up) { | |
172 | res = pm_runtime_get_sync(musb->controller); | |
173 | if (res < 0) { | |
174 | dev_err(musb->controller, "could not enable: %i", res); | |
175 | glue->powered = false; | |
176 | } | |
177 | } else { | |
178 | pm_runtime_mark_last_busy(musb->controller); | |
179 | pm_runtime_put_autosuspend(musb->controller); | |
180 | } | |
181 | } | |
182 | ||
12b7db2b | 183 | static int omap2430_musb_mailbox(enum musb_vbus_id_status status) |
594632ef | 184 | { |
c9721438 | 185 | struct omap2430_glue *glue = _glue; |
712d8efa | 186 | |
f8c4b0e7 AK |
187 | if (!glue) { |
188 | pr_err("%s: musb core is not yet initialized\n", __func__); | |
12b7db2b | 189 | return -EPROBE_DEFER; |
f8c4b0e7 AK |
190 | } |
191 | glue->status = status; | |
192 | ||
193 | if (!glue_to_musb(glue)) { | |
80ab72e1 | 194 | pr_err("%s: musb core is not yet ready\n", __func__); |
12b7db2b | 195 | return -EPROBE_DEFER; |
c9721438 | 196 | } |
712d8efa | 197 | |
c9721438 | 198 | schedule_work(&glue->omap_musb_mailbox_work); |
12b7db2b TL |
199 | |
200 | return 0; | |
712d8efa VP |
201 | } |
202 | ||
c9721438 | 203 | static void omap_musb_set_mailbox(struct omap2430_glue *glue) |
712d8efa | 204 | { |
1e5acb8d | 205 | struct musb *musb = glue_to_musb(glue); |
594632ef | 206 | struct device *dev = musb->controller; |
c1a7d67c | 207 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev); |
594632ef | 208 | struct omap_musb_board_data *data = pdata->board_data; |
c83a8542 | 209 | struct usb_otg *otg = musb->xceiv->otg; |
21f77bee TL |
210 | bool cable_connected; |
211 | ||
212 | cable_connected = ((glue->status == MUSB_ID_GROUND) || | |
213 | (glue->status == MUSB_VBUS_VALID)); | |
214 | ||
215 | if (cable_connected) | |
216 | omap2430_set_power(musb, glue->enabled, cable_connected); | |
594632ef | 217 | |
c9721438 | 218 | switch (glue->status) { |
8055555f | 219 | case MUSB_ID_GROUND: |
c9721438 | 220 | dev_dbg(dev, "ID GND\n"); |
594632ef | 221 | |
c83a8542 | 222 | otg->default_a = true; |
e47d9254 | 223 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
c9721438 | 224 | musb->xceiv->last_event = USB_EVENT_ID; |
032ec49f | 225 | if (musb->gadget_driver) { |
ca784be3 KVA |
226 | omap_control_usb_set_mode(glue->control_otghs, |
227 | USB_MODE_HOST); | |
70045c57 | 228 | omap2430_musb_set_vbus(musb, 1); |
594632ef HH |
229 | } |
230 | break; | |
231 | ||
8055555f | 232 | case MUSB_VBUS_VALID: |
c9721438 | 233 | dev_dbg(dev, "VBUS Connect\n"); |
594632ef | 234 | |
c83a8542 | 235 | otg->default_a = false; |
e47d9254 | 236 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
c9721438 | 237 | musb->xceiv->last_event = USB_EVENT_VBUS; |
ca784be3 | 238 | omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE); |
594632ef HH |
239 | break; |
240 | ||
8055555f TL |
241 | case MUSB_ID_FLOAT: |
242 | case MUSB_VBUS_OFF: | |
c9721438 | 243 | dev_dbg(dev, "VBUS Disconnect\n"); |
594632ef | 244 | |
c9721438 | 245 | musb->xceiv->last_event = USB_EVENT_NONE; |
21f77bee | 246 | if (musb->gadget_driver) |
2c1fe89d | 247 | omap2430_musb_set_vbus(musb, 0); |
7acc6197 | 248 | |
bb467cf5 KVA |
249 | if (data->interface_type == MUSB_INTERFACE_UTMI) |
250 | otg_set_vbus(musb->xceiv->otg, 0); | |
251 | ||
ca784be3 KVA |
252 | omap_control_usb_set_mode(glue->control_otghs, |
253 | USB_MODE_DISCONNECT); | |
594632ef HH |
254 | break; |
255 | default: | |
c9721438 | 256 | dev_dbg(dev, "ID float\n"); |
594632ef | 257 | } |
6fa7178c | 258 | |
21f77bee TL |
259 | if (!cable_connected) |
260 | omap2430_set_power(musb, glue->enabled, cable_connected); | |
261 | ||
6fa7178c PR |
262 | atomic_notifier_call_chain(&musb->xceiv->notifier, |
263 | musb->xceiv->last_event, NULL); | |
594632ef HH |
264 | } |
265 | ||
c9721438 KVA |
266 | |
267 | static void omap_musb_mailbox_work(struct work_struct *mailbox_work) | |
268 | { | |
269 | struct omap2430_glue *glue = container_of(mailbox_work, | |
270 | struct omap2430_glue, omap_musb_mailbox_work); | |
8b2bc2c9 | 271 | |
c9721438 KVA |
272 | omap_musb_set_mailbox(glue); |
273 | } | |
274 | ||
baef653a PDS |
275 | static irqreturn_t omap2430_musb_interrupt(int irq, void *__hci) |
276 | { | |
277 | unsigned long flags; | |
278 | irqreturn_t retval = IRQ_NONE; | |
279 | struct musb *musb = __hci; | |
280 | ||
281 | spin_lock_irqsave(&musb->lock, flags); | |
282 | ||
283 | musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); | |
284 | musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); | |
285 | musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); | |
286 | ||
287 | if (musb->int_usb || musb->int_tx || musb->int_rx) | |
288 | retval = musb_interrupt(musb); | |
289 | ||
290 | spin_unlock_irqrestore(&musb->lock, flags); | |
291 | ||
292 | return retval; | |
293 | } | |
294 | ||
743411b3 | 295 | static int omap2430_musb_init(struct musb *musb) |
550a7375 | 296 | { |
ad579699 S |
297 | u32 l; |
298 | int status = 0; | |
ea65df57 | 299 | struct device *dev = musb->controller; |
c9721438 | 300 | struct omap2430_glue *glue = dev_get_drvdata(dev->parent); |
c1a7d67c | 301 | struct musb_hdrc_platform_data *plat = dev_get_platdata(dev); |
ea65df57 | 302 | struct omap_musb_board_data *data = plat->board_data; |
550a7375 | 303 | |
84e250ff DB |
304 | /* We require some kind of external transceiver, hooked |
305 | * up through ULPI. TWL4030-family PMICs include one, | |
306 | * which needs a driver, drivers aren't always needed. | |
307 | */ | |
3e3101d5 KVA |
308 | if (dev->parent->of_node) { |
309 | musb->phy = devm_phy_get(dev->parent, "usb2-phy"); | |
310 | ||
311 | /* We can't totally remove musb->xceiv as of now because | |
312 | * musb core uses xceiv.state and xceiv.otg. Once we have | |
313 | * a separate state machine to handle otg, these can be moved | |
314 | * out of xceiv and then we can start using the generic PHY | |
315 | * framework | |
316 | */ | |
b16604f2 KVA |
317 | musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent, |
318 | "usb-phy", 0); | |
3e3101d5 | 319 | } else { |
b16604f2 | 320 | musb->xceiv = devm_usb_get_phy_dev(dev, 0); |
3e3101d5 KVA |
321 | musb->phy = devm_phy_get(dev, "usb"); |
322 | } | |
b16604f2 | 323 | |
a90199bb FB |
324 | if (IS_ERR(musb->xceiv)) { |
325 | status = PTR_ERR(musb->xceiv); | |
326 | ||
327 | if (status == -ENXIO) | |
328 | return status; | |
329 | ||
84e250ff | 330 | pr_err("HS USB OTG: no transceiver configured\n"); |
25736e0c | 331 | return -EPROBE_DEFER; |
84e250ff DB |
332 | } |
333 | ||
3e3101d5 KVA |
334 | if (IS_ERR(musb->phy)) { |
335 | pr_err("HS USB OTG: no PHY configured\n"); | |
336 | return PTR_ERR(musb->phy); | |
337 | } | |
baef653a | 338 | musb->isr = omap2430_musb_interrupt; |
a83e17d0 | 339 | phy_init(musb->phy); |
baef653a | 340 | |
8573e6a6 | 341 | l = musb_readl(musb->mregs, OTG_INTERFSEL); |
de2e1b0c MM |
342 | |
343 | if (data->interface_type == MUSB_INTERFACE_UTMI) { | |
344 | /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */ | |
345 | l &= ~ULPI_12PIN; /* Disable ULPI */ | |
346 | l |= UTMI_8BIT; /* Enable UTMI */ | |
347 | } else { | |
348 | l |= ULPI_12PIN; | |
349 | } | |
350 | ||
8573e6a6 | 351 | musb_writel(musb->mregs, OTG_INTERFSEL, l); |
550a7375 FB |
352 | |
353 | pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, " | |
354 | "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n", | |
8573e6a6 FB |
355 | musb_readl(musb->mregs, OTG_REVISION), |
356 | musb_readl(musb->mregs, OTG_SYSCONFIG), | |
357 | musb_readl(musb->mregs, OTG_SYSSTATUS), | |
358 | musb_readl(musb->mregs, OTG_INTERFSEL), | |
359 | musb_readl(musb->mregs, OTG_SIMENABLE)); | |
550a7375 | 360 | |
8055555f | 361 | if (glue->status != MUSB_UNKNOWN) |
c9721438 KVA |
362 | omap_musb_set_mailbox(glue); |
363 | ||
550a7375 FB |
364 | return 0; |
365 | } | |
366 | ||
002eda13 HH |
367 | static void omap2430_musb_enable(struct musb *musb) |
368 | { | |
369 | u8 devctl; | |
370 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); | |
371 | struct device *dev = musb->controller; | |
c9721438 | 372 | struct omap2430_glue *glue = dev_get_drvdata(dev->parent); |
c1a7d67c | 373 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev); |
002eda13 HH |
374 | struct omap_musb_board_data *data = pdata->board_data; |
375 | ||
a83e17d0 TL |
376 | if (!WARN_ON(!musb->phy)) |
377 | phy_power_on(musb->phy); | |
378 | ||
21f77bee TL |
379 | omap2430_set_power(musb, true, glue->cable_connected); |
380 | ||
c9721438 | 381 | switch (glue->status) { |
002eda13 | 382 | |
8055555f | 383 | case MUSB_ID_GROUND: |
ca784be3 | 384 | omap_control_usb_set_mode(glue->control_otghs, USB_MODE_HOST); |
08dec56e FC |
385 | if (data->interface_type != MUSB_INTERFACE_UTMI) |
386 | break; | |
387 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | |
388 | /* start the session */ | |
389 | devctl |= MUSB_DEVCTL_SESSION; | |
390 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | |
391 | while (musb_readb(musb->mregs, MUSB_DEVCTL) & | |
392 | MUSB_DEVCTL_BDEVICE) { | |
393 | cpu_relax(); | |
394 | ||
395 | if (time_after(jiffies, timeout)) { | |
396 | dev_err(dev, "configured as A device timeout"); | |
397 | break; | |
002eda13 HH |
398 | } |
399 | } | |
400 | break; | |
401 | ||
8055555f | 402 | case MUSB_VBUS_VALID: |
ca784be3 | 403 | omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE); |
002eda13 HH |
404 | break; |
405 | ||
406 | default: | |
407 | break; | |
408 | } | |
409 | } | |
410 | ||
411 | static void omap2430_musb_disable(struct musb *musb) | |
412 | { | |
c9721438 KVA |
413 | struct device *dev = musb->controller; |
414 | struct omap2430_glue *glue = dev_get_drvdata(dev->parent); | |
415 | ||
a83e17d0 TL |
416 | if (!WARN_ON(!musb->phy)) |
417 | phy_power_off(musb->phy); | |
418 | ||
8055555f | 419 | if (glue->status != MUSB_UNKNOWN) |
ca784be3 KVA |
420 | omap_control_usb_set_mode(glue->control_otghs, |
421 | USB_MODE_DISCONNECT); | |
21f77bee TL |
422 | |
423 | omap2430_set_power(musb, false, glue->cable_connected); | |
550a7375 FB |
424 | } |
425 | ||
743411b3 | 426 | static int omap2430_musb_exit(struct musb *musb) |
550a7375 | 427 | { |
a83e17d0 TL |
428 | struct device *dev = musb->controller; |
429 | struct omap2430_glue *glue = dev_get_drvdata(dev->parent); | |
550a7375 | 430 | |
c20aebb9 | 431 | omap2430_low_level_exit(musb); |
3e3101d5 | 432 | phy_exit(musb->phy); |
a83e17d0 TL |
433 | musb->phy = NULL; |
434 | cancel_work_sync(&glue->omap_musb_mailbox_work); | |
c20aebb9 | 435 | |
550a7375 FB |
436 | return 0; |
437 | } | |
743411b3 | 438 | |
f7ec9437 | 439 | static const struct musb_platform_ops omap2430_ops = { |
f8e9f34f | 440 | .quirks = MUSB_DMA_INVENTRA, |
7f6283ed TL |
441 | #ifdef CONFIG_USB_INVENTRA_DMA |
442 | .dma_init = musbhs_dma_controller_create, | |
443 | .dma_exit = musbhs_dma_controller_destroy, | |
444 | #endif | |
743411b3 FB |
445 | .init = omap2430_musb_init, |
446 | .exit = omap2430_musb_exit, | |
447 | ||
743411b3 | 448 | .set_vbus = omap2430_musb_set_vbus, |
002eda13 HH |
449 | |
450 | .enable = omap2430_musb_enable, | |
451 | .disable = omap2430_musb_disable, | |
8055555f TL |
452 | |
453 | .phy_callback = omap2430_musb_mailbox, | |
743411b3 | 454 | }; |
dc09886b FB |
455 | |
456 | static u64 omap2430_dmamask = DMA_BIT_MASK(32); | |
457 | ||
41ac7b3a | 458 | static int omap2430_probe(struct platform_device *pdev) |
dc09886b | 459 | { |
c1f01be4 | 460 | struct resource musb_resources[3]; |
c1a7d67c | 461 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); |
00a0b1d5 | 462 | struct omap_musb_board_data *data; |
dc09886b | 463 | struct platform_device *musb; |
a3cee12a | 464 | struct omap2430_glue *glue; |
00a0b1d5 KVA |
465 | struct device_node *np = pdev->dev.of_node; |
466 | struct musb_hdrc_config *config; | |
606bf4d5 | 467 | int ret = -ENOMEM, val; |
dc09886b | 468 | |
b1183c24 | 469 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
af1bdfc9 | 470 | if (!glue) |
a3cee12a | 471 | goto err0; |
a3cee12a | 472 | |
2f771164 | 473 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); |
dc09886b FB |
474 | if (!musb) { |
475 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | |
2f771164 | 476 | goto err0; |
dc09886b FB |
477 | } |
478 | ||
479 | musb->dev.parent = &pdev->dev; | |
480 | musb->dev.dma_mask = &omap2430_dmamask; | |
481 | musb->dev.coherent_dma_mask = omap2430_dmamask; | |
482 | ||
a3cee12a FB |
483 | glue->dev = &pdev->dev; |
484 | glue->musb = musb; | |
8055555f | 485 | glue->status = MUSB_UNKNOWN; |
8934d3e4 | 486 | glue->control_otghs = ERR_PTR(-ENODEV); |
a3cee12a | 487 | |
00a0b1d5 | 488 | if (np) { |
8934d3e4 RQ |
489 | struct device_node *control_node; |
490 | struct platform_device *control_pdev; | |
491 | ||
00a0b1d5 | 492 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
af1bdfc9 | 493 | if (!pdata) |
2f771164 | 494 | goto err2; |
00a0b1d5 KVA |
495 | |
496 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | |
af1bdfc9 | 497 | if (!data) |
2f771164 | 498 | goto err2; |
00a0b1d5 KVA |
499 | |
500 | config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL); | |
af1bdfc9 | 501 | if (!config) |
2f771164 | 502 | goto err2; |
00a0b1d5 KVA |
503 | |
504 | of_property_read_u32(np, "mode", (u32 *)&pdata->mode); | |
eee44da0 | 505 | of_property_read_u32(np, "interface-type", |
00a0b1d5 | 506 | (u32 *)&data->interface_type); |
eee44da0 KVA |
507 | of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps); |
508 | of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits); | |
00a0b1d5 | 509 | of_property_read_u32(np, "power", (u32 *)&pdata->power); |
606bf4d5 TL |
510 | |
511 | ret = of_property_read_u32(np, "multipoint", &val); | |
512 | if (!ret && val) | |
513 | config->multipoint = true; | |
00a0b1d5 KVA |
514 | |
515 | pdata->board_data = data; | |
516 | pdata->config = config; | |
00a0b1d5 | 517 | |
8934d3e4 RQ |
518 | control_node = of_parse_phandle(np, "ctrl-module", 0); |
519 | if (control_node) { | |
520 | control_pdev = of_find_device_by_node(control_node); | |
521 | if (!control_pdev) { | |
522 | dev_err(&pdev->dev, "Failed to get control device\n"); | |
523 | ret = -EINVAL; | |
524 | goto err2; | |
525 | } | |
526 | glue->control_otghs = &control_pdev->dev; | |
ca784be3 | 527 | } |
ca784be3 | 528 | } |
f7ec9437 FB |
529 | pdata->platform_ops = &omap2430_ops; |
530 | ||
a3cee12a | 531 | platform_set_drvdata(pdev, glue); |
dc09886b | 532 | |
c9721438 KVA |
533 | /* |
534 | * REVISIT if we ever have two instances of the wrapper, we will be | |
535 | * in big trouble | |
536 | */ | |
537 | _glue = glue; | |
538 | ||
1e5acb8d KVA |
539 | INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work); |
540 | ||
3a0ddc71 | 541 | memset(musb_resources, 0x00, sizeof(*musb_resources) * |
09fc7d22 FB |
542 | ARRAY_SIZE(musb_resources)); |
543 | ||
544 | musb_resources[0].name = pdev->resource[0].name; | |
545 | musb_resources[0].start = pdev->resource[0].start; | |
546 | musb_resources[0].end = pdev->resource[0].end; | |
547 | musb_resources[0].flags = pdev->resource[0].flags; | |
548 | ||
549 | musb_resources[1].name = pdev->resource[1].name; | |
550 | musb_resources[1].start = pdev->resource[1].start; | |
551 | musb_resources[1].end = pdev->resource[1].end; | |
552 | musb_resources[1].flags = pdev->resource[1].flags; | |
553 | ||
c1f01be4 KVA |
554 | musb_resources[2].name = pdev->resource[2].name; |
555 | musb_resources[2].start = pdev->resource[2].start; | |
556 | musb_resources[2].end = pdev->resource[2].end; | |
557 | musb_resources[2].flags = pdev->resource[2].flags; | |
558 | ||
09fc7d22 FB |
559 | ret = platform_device_add_resources(musb, musb_resources, |
560 | ARRAY_SIZE(musb_resources)); | |
dc09886b FB |
561 | if (ret) { |
562 | dev_err(&pdev->dev, "failed to add resources\n"); | |
65b3d52d | 563 | goto err2; |
dc09886b FB |
564 | } |
565 | ||
566 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | |
567 | if (ret) { | |
568 | dev_err(&pdev->dev, "failed to add platform_data\n"); | |
65b3d52d | 569 | goto err2; |
dc09886b FB |
570 | } |
571 | ||
87326e85 TL |
572 | pm_runtime_enable(glue->dev); |
573 | pm_runtime_use_autosuspend(glue->dev); | |
574 | pm_runtime_set_autosuspend_delay(glue->dev, 500); | |
3006dc8c | 575 | |
dc09886b FB |
576 | ret = platform_device_add(musb); |
577 | if (ret) { | |
578 | dev_err(&pdev->dev, "failed to register musb device\n"); | |
65b3d52d | 579 | goto err2; |
dc09886b FB |
580 | } |
581 | ||
207b0e1f | 582 | return 0; |
03491761 | 583 | |
65b3d52d | 584 | err2: |
b1183c24 | 585 | platform_device_put(musb); |
a3cee12a | 586 | |
dc09886b FB |
587 | err0: |
588 | return ret; | |
589 | } | |
590 | ||
fb4e98ab | 591 | static int omap2430_remove(struct platform_device *pdev) |
dc09886b | 592 | { |
21f77bee TL |
593 | struct omap2430_glue *glue = platform_get_drvdata(pdev); |
594 | struct musb *musb = glue_to_musb(glue); | |
dc09886b | 595 | |
03e43528 | 596 | pm_runtime_get_sync(glue->dev); |
f039df58 | 597 | platform_device_unregister(glue->musb); |
21f77bee | 598 | omap2430_set_power(musb, false, false); |
03e43528 | 599 | pm_runtime_put_sync(glue->dev); |
87326e85 | 600 | pm_runtime_dont_use_autosuspend(glue->dev); |
03e43528 | 601 | pm_runtime_disable(glue->dev); |
dc09886b FB |
602 | |
603 | return 0; | |
604 | } | |
605 | ||
c20aebb9 | 606 | #ifdef CONFIG_PM |
c20aebb9 | 607 | |
7acc6197 | 608 | static int omap2430_runtime_suspend(struct device *dev) |
c20aebb9 FB |
609 | { |
610 | struct omap2430_glue *glue = dev_get_drvdata(dev); | |
611 | struct musb *musb = glue_to_musb(glue); | |
612 | ||
a83e17d0 TL |
613 | if (!musb) |
614 | return 0; | |
e25bec16 | 615 | |
a83e17d0 TL |
616 | musb->context.otg_interfsel = musb_readl(musb->mregs, |
617 | OTG_INTERFSEL); | |
618 | ||
619 | omap2430_low_level_exit(musb); | |
c20aebb9 FB |
620 | |
621 | return 0; | |
622 | } | |
623 | ||
7acc6197 | 624 | static int omap2430_runtime_resume(struct device *dev) |
c20aebb9 FB |
625 | { |
626 | struct omap2430_glue *glue = dev_get_drvdata(dev); | |
627 | struct musb *musb = glue_to_musb(glue); | |
c20aebb9 | 628 | |
8f2279d5 | 629 | if (!musb) |
a83e17d0 | 630 | return 0; |
8f2279d5 TL |
631 | |
632 | omap2430_low_level_init(musb); | |
633 | musb_writel(musb->mregs, OTG_INTERFSEL, | |
634 | musb->context.otg_interfsel); | |
c20aebb9 FB |
635 | |
636 | return 0; | |
637 | } | |
638 | ||
639 | static struct dev_pm_ops omap2430_pm_ops = { | |
7acc6197 HH |
640 | .runtime_suspend = omap2430_runtime_suspend, |
641 | .runtime_resume = omap2430_runtime_resume, | |
c20aebb9 FB |
642 | }; |
643 | ||
644 | #define DEV_PM_OPS (&omap2430_pm_ops) | |
645 | #else | |
646 | #define DEV_PM_OPS NULL | |
647 | #endif | |
648 | ||
00a0b1d5 KVA |
649 | #ifdef CONFIG_OF |
650 | static const struct of_device_id omap2430_id_table[] = { | |
651 | { | |
652 | .compatible = "ti,omap4-musb" | |
653 | }, | |
654 | { | |
655 | .compatible = "ti,omap3-musb" | |
656 | }, | |
657 | {}, | |
658 | }; | |
659 | MODULE_DEVICE_TABLE(of, omap2430_id_table); | |
660 | #endif | |
661 | ||
dc09886b | 662 | static struct platform_driver omap2430_driver = { |
e9e8c85e | 663 | .probe = omap2430_probe, |
7690417d | 664 | .remove = omap2430_remove, |
dc09886b FB |
665 | .driver = { |
666 | .name = "musb-omap2430", | |
c20aebb9 | 667 | .pm = DEV_PM_OPS, |
00a0b1d5 | 668 | .of_match_table = of_match_ptr(omap2430_id_table), |
dc09886b FB |
669 | }, |
670 | }; | |
671 | ||
aec373c1 TL |
672 | module_platform_driver(omap2430_driver); |
673 | ||
dc09886b FB |
674 | MODULE_DESCRIPTION("OMAP2PLUS MUSB Glue Layer"); |
675 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); | |
676 | MODULE_LICENSE("GPL v2"); |