omap2430.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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
  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>
  30. #include <linux/init.h>
  31. #include <linux/list.h>
  32. #include <linux/io.h>
  33. #include <linux/of.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/pm_runtime.h>
  37. #include <linux/err.h>
  38. #include <linux/delay.h>
  39. #include <linux/usb/musb-omap.h>
  40. #include <linux/phy/omap_control_phy.h>
  41. #include <linux/of_platform.h>
  42. #include "musb_core.h"
  43. #include "omap2430.h"
  44. struct omap2430_glue {
  45. struct device *dev;
  46. struct platform_device *musb;
  47. enum omap_musb_vbus_id_status status;
  48. struct work_struct omap_musb_mailbox_work;
  49. struct device *control_otghs;
  50. };
  51. #define glue_to_musb(g) platform_get_drvdata(g->musb)
  52. static struct omap2430_glue *_glue;
  53. static struct timer_list musb_idle_timer;
  54. static void musb_do_idle(unsigned long _musb)
  55. {
  56. struct musb *musb = (void *)_musb;
  57. unsigned long flags;
  58. u8 power;
  59. u8 devctl;
  60. spin_lock_irqsave(&musb->lock, flags);
  61. switch (musb->xceiv->otg->state) {
  62. case OTG_STATE_A_WAIT_BCON:
  63. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  64. if (devctl & MUSB_DEVCTL_BDEVICE) {
  65. musb->xceiv->otg->state = OTG_STATE_B_IDLE;
  66. MUSB_DEV_MODE(musb);
  67. } else {
  68. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  69. MUSB_HST_MODE(musb);
  70. }
  71. break;
  72. case OTG_STATE_A_SUSPEND:
  73. /* finish RESUME signaling? */
  74. if (musb->port1_status & MUSB_PORT_STAT_RESUME) {
  75. power = musb_readb(musb->mregs, MUSB_POWER);
  76. power &= ~MUSB_POWER_RESUME;
  77. dev_dbg(musb->controller, "root port resume stopped, power %02x\n", power);
  78. musb_writeb(musb->mregs, MUSB_POWER, power);
  79. musb->is_active = 1;
  80. musb->port1_status &= ~(USB_PORT_STAT_SUSPEND
  81. | MUSB_PORT_STAT_RESUME);
  82. musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16;
  83. usb_hcd_poll_rh_status(musb->hcd);
  84. /* NOTE: it might really be A_WAIT_BCON ... */
  85. musb->xceiv->otg->state = OTG_STATE_A_HOST;
  86. }
  87. break;
  88. case OTG_STATE_A_HOST:
  89. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  90. if (devctl & MUSB_DEVCTL_BDEVICE)
  91. musb->xceiv->otg->state = OTG_STATE_B_IDLE;
  92. else
  93. musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON;
  94. default:
  95. break;
  96. }
  97. spin_unlock_irqrestore(&musb->lock, flags);
  98. }
  99. static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout)
  100. {
  101. unsigned long default_timeout = jiffies + msecs_to_jiffies(3);
  102. static unsigned long last_timer;
  103. if (timeout == 0)
  104. timeout = default_timeout;
  105. /* Never idle if active, or when VBUS timeout is not set as host */
  106. if (musb->is_active || ((musb->a_wait_bcon == 0)
  107. && (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON))) {
  108. dev_dbg(musb->controller, "%s active, deleting timer\n",
  109. usb_otg_state_string(musb->xceiv->otg->state));
  110. del_timer(&musb_idle_timer);
  111. last_timer = jiffies;
  112. return;
  113. }
  114. if (time_after(last_timer, timeout)) {
  115. if (!timer_pending(&musb_idle_timer))
  116. last_timer = timeout;
  117. else {
  118. dev_dbg(musb->controller, "Longer idle timer already pending, ignoring\n");
  119. return;
  120. }
  121. }
  122. last_timer = timeout;
  123. dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n",
  124. usb_otg_state_string(musb->xceiv->otg->state),
  125. (unsigned long)jiffies_to_msecs(timeout - jiffies));
  126. mod_timer(&musb_idle_timer, timeout);
  127. }
  128. static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
  129. {
  130. struct usb_otg *otg = musb->xceiv->otg;
  131. u8 devctl;
  132. unsigned long timeout = jiffies + msecs_to_jiffies(1000);
  133. /* HDRC controls CPEN, but beware current surges during device
  134. * connect. They can trigger transient overcurrent conditions
  135. * that must be ignored.
  136. */
  137. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  138. if (is_on) {
  139. if (musb->xceiv->otg->state == OTG_STATE_A_IDLE) {
  140. int loops = 100;
  141. /* start the session */
  142. devctl |= MUSB_DEVCTL_SESSION;
  143. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  144. /*
  145. * Wait for the musb to set as A device to enable the
  146. * VBUS
  147. */
  148. while (musb_readb(musb->mregs, MUSB_DEVCTL) &
  149. MUSB_DEVCTL_BDEVICE) {
  150. mdelay(5);
  151. cpu_relax();
  152. if (time_after(jiffies, timeout)
  153. || loops-- <= 0) {
  154. dev_err(musb->controller,
  155. "configured as A device timeout");
  156. break;
  157. }
  158. }
  159. otg_set_vbus(otg, 1);
  160. } else {
  161. musb->is_active = 1;
  162. otg->default_a = 1;
  163. musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
  164. devctl |= MUSB_DEVCTL_SESSION;
  165. MUSB_HST_MODE(musb);
  166. }
  167. } else {
  168. musb->is_active = 0;
  169. /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and
  170. * jumping right to B_IDLE...
  171. */
  172. otg->default_a = 0;
  173. musb->xceiv->otg->state = OTG_STATE_B_IDLE;
  174. devctl &= ~MUSB_DEVCTL_SESSION;
  175. MUSB_DEV_MODE(musb);
  176. }
  177. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  178. dev_dbg(musb->controller, "VBUS %s, devctl %02x "
  179. /* otg %3x conf %08x prcm %08x */ "\n",
  180. usb_otg_state_string(musb->xceiv->otg->state),
  181. musb_readb(musb->mregs, MUSB_DEVCTL));
  182. }
  183. static int omap2430_musb_set_mode(struct musb *musb, u8 musb_mode)
  184. {
  185. u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  186. devctl |= MUSB_DEVCTL_SESSION;
  187. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  188. return 0;
  189. }
  190. static inline void omap2430_low_level_exit(struct musb *musb)
  191. {
  192. u32 l;
  193. /* in any role */
  194. l = musb_readl(musb->mregs, OTG_FORCESTDBY);
  195. l |= ENABLEFORCE; /* enable MSTANDBY */
  196. musb_writel(musb->mregs, OTG_FORCESTDBY, l);
  197. }
  198. static inline void omap2430_low_level_init(struct musb *musb)
  199. {
  200. u32 l;
  201. l = musb_readl(musb->mregs, OTG_FORCESTDBY);
  202. l &= ~ENABLEFORCE; /* disable MSTANDBY */
  203. musb_writel(musb->mregs, OTG_FORCESTDBY, l);
  204. }
  205. void omap_musb_mailbox(enum omap_musb_vbus_id_status status)
  206. {
  207. struct omap2430_glue *glue = _glue;
  208. if (!glue) {
  209. pr_err("%s: musb core is not yet initialized\n", __func__);
  210. return;
  211. }
  212. glue->status = status;
  213. if (!glue_to_musb(glue)) {
  214. pr_err("%s: musb core is not yet ready\n", __func__);
  215. return;
  216. }
  217. schedule_work(&glue->omap_musb_mailbox_work);
  218. }
  219. EXPORT_SYMBOL_GPL(omap_musb_mailbox);
  220. static void omap_musb_set_mailbox(struct omap2430_glue *glue)
  221. {
  222. struct musb *musb = glue_to_musb(glue);
  223. struct device *dev = musb->controller;
  224. struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev);
  225. struct omap_musb_board_data *data = pdata->board_data;
  226. struct usb_otg *otg = musb->xceiv->otg;
  227. switch (glue->status) {
  228. case OMAP_MUSB_ID_GROUND:
  229. dev_dbg(dev, "ID GND\n");
  230. otg->default_a = true;
  231. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  232. musb->xceiv->last_event = USB_EVENT_ID;
  233. if (musb->gadget_driver) {
  234. pm_runtime_get_sync(dev);
  235. omap_control_usb_set_mode(glue->control_otghs,
  236. USB_MODE_HOST);
  237. omap2430_musb_set_vbus(musb, 1);
  238. }
  239. break;
  240. case OMAP_MUSB_VBUS_VALID:
  241. dev_dbg(dev, "VBUS Connect\n");
  242. otg->default_a = false;
  243. musb->xceiv->otg->state = OTG_STATE_B_IDLE;
  244. musb->xceiv->last_event = USB_EVENT_VBUS;
  245. if (musb->gadget_driver)
  246. pm_runtime_get_sync(dev);
  247. omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
  248. break;
  249. case OMAP_MUSB_ID_FLOAT:
  250. case OMAP_MUSB_VBUS_OFF:
  251. dev_dbg(dev, "VBUS Disconnect\n");
  252. musb->xceiv->last_event = USB_EVENT_NONE;
  253. if (musb->gadget_driver) {
  254. omap2430_musb_set_vbus(musb, 0);
  255. pm_runtime_mark_last_busy(dev);
  256. pm_runtime_put_autosuspend(dev);
  257. }
  258. if (data->interface_type == MUSB_INTERFACE_UTMI)
  259. otg_set_vbus(musb->xceiv->otg, 0);
  260. omap_control_usb_set_mode(glue->control_otghs,
  261. USB_MODE_DISCONNECT);
  262. break;
  263. default:
  264. dev_dbg(dev, "ID float\n");
  265. }
  266. atomic_notifier_call_chain(&musb->xceiv->notifier,
  267. musb->xceiv->last_event, NULL);
  268. }
  269. static void omap_musb_mailbox_work(struct work_struct *mailbox_work)
  270. {
  271. struct omap2430_glue *glue = container_of(mailbox_work,
  272. struct omap2430_glue, omap_musb_mailbox_work);
  273. struct musb *musb = glue_to_musb(glue);
  274. struct device *dev = musb->controller;
  275. pm_runtime_get_sync(dev);
  276. omap_musb_set_mailbox(glue);
  277. pm_runtime_mark_last_busy(dev);
  278. pm_runtime_put_autosuspend(dev);
  279. }
  280. static irqreturn_t omap2430_musb_interrupt(int irq, void *__hci)
  281. {
  282. unsigned long flags;
  283. irqreturn_t retval = IRQ_NONE;
  284. struct musb *musb = __hci;
  285. spin_lock_irqsave(&musb->lock, flags);
  286. musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
  287. musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
  288. musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX);
  289. if (musb->int_usb || musb->int_tx || musb->int_rx)
  290. retval = musb_interrupt(musb);
  291. spin_unlock_irqrestore(&musb->lock, flags);
  292. return retval;
  293. }
  294. static int omap2430_musb_init(struct musb *musb)
  295. {
  296. u32 l;
  297. int status = 0;
  298. struct device *dev = musb->controller;
  299. struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
  300. struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
  301. struct omap_musb_board_data *data = plat->board_data;
  302. /* We require some kind of external transceiver, hooked
  303. * up through ULPI. TWL4030-family PMICs include one,
  304. * which needs a driver, drivers aren't always needed.
  305. */
  306. if (dev->parent->of_node) {
  307. musb->phy = devm_phy_get(dev->parent, "usb2-phy");
  308. /* We can't totally remove musb->xceiv as of now because
  309. * musb core uses xceiv.state and xceiv.otg. Once we have
  310. * a separate state machine to handle otg, these can be moved
  311. * out of xceiv and then we can start using the generic PHY
  312. * framework
  313. */
  314. musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent,
  315. "usb-phy", 0);
  316. } else {
  317. musb->xceiv = devm_usb_get_phy_dev(dev, 0);
  318. musb->phy = devm_phy_get(dev, "usb");
  319. }
  320. if (IS_ERR(musb->xceiv)) {
  321. status = PTR_ERR(musb->xceiv);
  322. if (status == -ENXIO)
  323. return status;
  324. pr_err("HS USB OTG: no transceiver configured\n");
  325. return -EPROBE_DEFER;
  326. }
  327. if (IS_ERR(musb->phy)) {
  328. pr_err("HS USB OTG: no PHY configured\n");
  329. return PTR_ERR(musb->phy);
  330. }
  331. musb->isr = omap2430_musb_interrupt;
  332. /*
  333. * Enable runtime PM for musb parent (this driver). We can't
  334. * do it earlier as struct musb is not yet allocated and we
  335. * need to touch the musb registers for runtime PM.
  336. */
  337. pm_runtime_enable(glue->dev);
  338. status = pm_runtime_get_sync(glue->dev);
  339. if (status < 0)
  340. goto err1;
  341. status = pm_runtime_get_sync(dev);
  342. if (status < 0) {
  343. dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status);
  344. pm_runtime_put_sync(glue->dev);
  345. goto err1;
  346. }
  347. l = musb_readl(musb->mregs, OTG_INTERFSEL);
  348. if (data->interface_type == MUSB_INTERFACE_UTMI) {
  349. /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
  350. l &= ~ULPI_12PIN; /* Disable ULPI */
  351. l |= UTMI_8BIT; /* Enable UTMI */
  352. } else {
  353. l |= ULPI_12PIN;
  354. }
  355. musb_writel(musb->mregs, OTG_INTERFSEL, l);
  356. pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
  357. "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n",
  358. musb_readl(musb->mregs, OTG_REVISION),
  359. musb_readl(musb->mregs, OTG_SYSCONFIG),
  360. musb_readl(musb->mregs, OTG_SYSSTATUS),
  361. musb_readl(musb->mregs, OTG_INTERFSEL),
  362. musb_readl(musb->mregs, OTG_SIMENABLE));
  363. setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
  364. if (glue->status != OMAP_MUSB_UNKNOWN)
  365. omap_musb_set_mailbox(glue);
  366. phy_init(musb->phy);
  367. phy_power_on(musb->phy);
  368. pm_runtime_put_noidle(musb->controller);
  369. pm_runtime_put_noidle(glue->dev);
  370. return 0;
  371. err1:
  372. return status;
  373. }
  374. static void omap2430_musb_enable(struct musb *musb)
  375. {
  376. u8 devctl;
  377. unsigned long timeout = jiffies + msecs_to_jiffies(1000);
  378. struct device *dev = musb->controller;
  379. struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
  380. struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev);
  381. struct omap_musb_board_data *data = pdata->board_data;
  382. switch (glue->status) {
  383. case OMAP_MUSB_ID_GROUND:
  384. omap_control_usb_set_mode(glue->control_otghs, USB_MODE_HOST);
  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. if (time_after(jiffies, timeout)) {
  395. dev_err(dev, "configured as A device timeout");
  396. break;
  397. }
  398. }
  399. break;
  400. case OMAP_MUSB_VBUS_VALID:
  401. omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
  402. break;
  403. default:
  404. break;
  405. }
  406. }
  407. static void omap2430_musb_disable(struct musb *musb)
  408. {
  409. struct device *dev = musb->controller;
  410. struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
  411. if (glue->status != OMAP_MUSB_UNKNOWN)
  412. omap_control_usb_set_mode(glue->control_otghs,
  413. USB_MODE_DISCONNECT);
  414. }
  415. static int omap2430_musb_exit(struct musb *musb)
  416. {
  417. del_timer_sync(&musb_idle_timer);
  418. omap2430_low_level_exit(musb);
  419. phy_power_off(musb->phy);
  420. phy_exit(musb->phy);
  421. return 0;
  422. }
  423. static const struct musb_platform_ops omap2430_ops = {
  424. .quirks = MUSB_DMA_INVENTRA,
  425. #ifdef CONFIG_USB_INVENTRA_DMA
  426. .dma_init = musbhs_dma_controller_create,
  427. .dma_exit = musbhs_dma_controller_destroy,
  428. #endif
  429. .init = omap2430_musb_init,
  430. .exit = omap2430_musb_exit,
  431. .set_mode = omap2430_musb_set_mode,
  432. .try_idle = omap2430_musb_try_idle,
  433. .set_vbus = omap2430_musb_set_vbus,
  434. .enable = omap2430_musb_enable,
  435. .disable = omap2430_musb_disable,
  436. };
  437. static u64 omap2430_dmamask = DMA_BIT_MASK(32);
  438. static int omap2430_probe(struct platform_device *pdev)
  439. {
  440. struct resource musb_resources[3];
  441. struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
  442. struct omap_musb_board_data *data;
  443. struct platform_device *musb;
  444. struct omap2430_glue *glue;
  445. struct device_node *np = pdev->dev.of_node;
  446. struct musb_hdrc_config *config;
  447. int ret = -ENOMEM, val;
  448. glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
  449. if (!glue)
  450. goto err0;
  451. musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
  452. if (!musb) {
  453. dev_err(&pdev->dev, "failed to allocate musb device\n");
  454. goto err0;
  455. }
  456. musb->dev.parent = &pdev->dev;
  457. musb->dev.dma_mask = &omap2430_dmamask;
  458. musb->dev.coherent_dma_mask = omap2430_dmamask;
  459. glue->dev = &pdev->dev;
  460. glue->musb = musb;
  461. glue->status = OMAP_MUSB_UNKNOWN;
  462. glue->control_otghs = ERR_PTR(-ENODEV);
  463. if (np) {
  464. struct device_node *control_node;
  465. struct platform_device *control_pdev;
  466. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  467. if (!pdata)
  468. goto err2;
  469. data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
  470. if (!data)
  471. goto err2;
  472. config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
  473. if (!config)
  474. goto err2;
  475. of_property_read_u32(np, "mode", (u32 *)&pdata->mode);
  476. of_property_read_u32(np, "interface-type",
  477. (u32 *)&data->interface_type);
  478. of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps);
  479. of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits);
  480. of_property_read_u32(np, "power", (u32 *)&pdata->power);
  481. ret = of_property_read_u32(np, "multipoint", &val);
  482. if (!ret && val)
  483. config->multipoint = true;
  484. pdata->board_data = data;
  485. pdata->config = config;
  486. control_node = of_parse_phandle(np, "ctrl-module", 0);
  487. if (control_node) {
  488. control_pdev = of_find_device_by_node(control_node);
  489. if (!control_pdev) {
  490. dev_err(&pdev->dev, "Failed to get control device\n");
  491. ret = -EINVAL;
  492. goto err2;
  493. }
  494. glue->control_otghs = &control_pdev->dev;
  495. }
  496. }
  497. pdata->platform_ops = &omap2430_ops;
  498. platform_set_drvdata(pdev, glue);
  499. /*
  500. * REVISIT if we ever have two instances of the wrapper, we will be
  501. * in big trouble
  502. */
  503. _glue = glue;
  504. INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work);
  505. memset(musb_resources, 0x00, sizeof(*musb_resources) *
  506. ARRAY_SIZE(musb_resources));
  507. musb_resources[0].name = pdev->resource[0].name;
  508. musb_resources[0].start = pdev->resource[0].start;
  509. musb_resources[0].end = pdev->resource[0].end;
  510. musb_resources[0].flags = pdev->resource[0].flags;
  511. musb_resources[1].name = pdev->resource[1].name;
  512. musb_resources[1].start = pdev->resource[1].start;
  513. musb_resources[1].end = pdev->resource[1].end;
  514. musb_resources[1].flags = pdev->resource[1].flags;
  515. musb_resources[2].name = pdev->resource[2].name;
  516. musb_resources[2].start = pdev->resource[2].start;
  517. musb_resources[2].end = pdev->resource[2].end;
  518. musb_resources[2].flags = pdev->resource[2].flags;
  519. ret = platform_device_add_resources(musb, musb_resources,
  520. ARRAY_SIZE(musb_resources));
  521. if (ret) {
  522. dev_err(&pdev->dev, "failed to add resources\n");
  523. goto err2;
  524. }
  525. ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
  526. if (ret) {
  527. dev_err(&pdev->dev, "failed to add platform_data\n");
  528. goto err2;
  529. }
  530. /*
  531. * Note that we cannot enable PM runtime yet for this
  532. * driver as we need struct musb initialized first.
  533. * See omap2430_musb_init above.
  534. */
  535. ret = platform_device_add(musb);
  536. if (ret) {
  537. dev_err(&pdev->dev, "failed to register musb device\n");
  538. goto err2;
  539. }
  540. return 0;
  541. err2:
  542. platform_device_put(musb);
  543. err0:
  544. return ret;
  545. }
  546. static int omap2430_remove(struct platform_device *pdev)
  547. {
  548. struct omap2430_glue *glue = platform_get_drvdata(pdev);
  549. cancel_work_sync(&glue->omap_musb_mailbox_work);
  550. platform_device_unregister(glue->musb);
  551. return 0;
  552. }
  553. #ifdef CONFIG_PM
  554. static int omap2430_runtime_suspend(struct device *dev)
  555. {
  556. struct omap2430_glue *glue = dev_get_drvdata(dev);
  557. struct musb *musb = glue_to_musb(glue);
  558. if (musb) {
  559. musb->context.otg_interfsel = musb_readl(musb->mregs,
  560. OTG_INTERFSEL);
  561. omap2430_low_level_exit(musb);
  562. }
  563. return 0;
  564. }
  565. static int omap2430_runtime_resume(struct device *dev)
  566. {
  567. struct omap2430_glue *glue = dev_get_drvdata(dev);
  568. struct musb *musb = glue_to_musb(glue);
  569. if (!musb)
  570. return -EPROBE_DEFER;
  571. omap2430_low_level_init(musb);
  572. musb_writel(musb->mregs, OTG_INTERFSEL,
  573. musb->context.otg_interfsel);
  574. return 0;
  575. }
  576. static struct dev_pm_ops omap2430_pm_ops = {
  577. .runtime_suspend = omap2430_runtime_suspend,
  578. .runtime_resume = omap2430_runtime_resume,
  579. };
  580. #define DEV_PM_OPS (&omap2430_pm_ops)
  581. #else
  582. #define DEV_PM_OPS NULL
  583. #endif
  584. #ifdef CONFIG_OF
  585. static const struct of_device_id omap2430_id_table[] = {
  586. {
  587. .compatible = "ti,omap4-musb"
  588. },
  589. {
  590. .compatible = "ti,omap3-musb"
  591. },
  592. {},
  593. };
  594. MODULE_DEVICE_TABLE(of, omap2430_id_table);
  595. #endif
  596. static struct platform_driver omap2430_driver = {
  597. .probe = omap2430_probe,
  598. .remove = omap2430_remove,
  599. .driver = {
  600. .name = "musb-omap2430",
  601. .pm = DEV_PM_OPS,
  602. .of_match_table = of_match_ptr(omap2430_id_table),
  603. },
  604. };
  605. MODULE_DESCRIPTION("OMAP2PLUS MUSB Glue Layer");
  606. MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
  607. MODULE_LICENSE("GPL v2");
  608. static int __init omap2430_init(void)
  609. {
  610. return platform_driver_register(&omap2430_driver);
  611. }
  612. subsys_initcall(omap2430_init);
  613. static void __exit omap2430_exit(void)
  614. {
  615. platform_driver_unregister(&omap2430_driver);
  616. }
  617. module_exit(omap2430_exit);