omap2430.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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->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->state = OTG_STATE_B_IDLE;
  66. MUSB_DEV_MODE(musb);
  67. } else {
  68. musb->xceiv->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->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->state = OTG_STATE_B_IDLE;
  92. else
  93. musb->xceiv->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->state == OTG_STATE_A_WAIT_BCON))) {
  108. dev_dbg(musb->controller, "%s active, deleting timer\n",
  109. usb_otg_state_string(musb->xceiv->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->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->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) & 0x80) {
  149. mdelay(5);
  150. cpu_relax();
  151. if (time_after(jiffies, timeout)
  152. || loops-- <= 0) {
  153. dev_err(musb->controller,
  154. "configured as A device timeout");
  155. break;
  156. }
  157. }
  158. otg_set_vbus(otg, 1);
  159. } else {
  160. musb->is_active = 1;
  161. otg->default_a = 1;
  162. musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
  163. devctl |= MUSB_DEVCTL_SESSION;
  164. MUSB_HST_MODE(musb);
  165. }
  166. } else {
  167. musb->is_active = 0;
  168. /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and
  169. * jumping right to B_IDLE...
  170. */
  171. otg->default_a = 0;
  172. musb->xceiv->state = OTG_STATE_B_IDLE;
  173. devctl &= ~MUSB_DEVCTL_SESSION;
  174. MUSB_DEV_MODE(musb);
  175. }
  176. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  177. dev_dbg(musb->controller, "VBUS %s, devctl %02x "
  178. /* otg %3x conf %08x prcm %08x */ "\n",
  179. usb_otg_state_string(musb->xceiv->state),
  180. musb_readb(musb->mregs, MUSB_DEVCTL));
  181. }
  182. static int omap2430_musb_set_mode(struct musb *musb, u8 musb_mode)
  183. {
  184. u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  185. devctl |= MUSB_DEVCTL_SESSION;
  186. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  187. return 0;
  188. }
  189. static inline void omap2430_low_level_exit(struct musb *musb)
  190. {
  191. u32 l;
  192. /* in any role */
  193. l = musb_readl(musb->mregs, OTG_FORCESTDBY);
  194. l |= ENABLEFORCE; /* enable MSTANDBY */
  195. musb_writel(musb->mregs, OTG_FORCESTDBY, l);
  196. }
  197. static inline void omap2430_low_level_init(struct musb *musb)
  198. {
  199. u32 l;
  200. l = musb_readl(musb->mregs, OTG_FORCESTDBY);
  201. l &= ~ENABLEFORCE; /* disable MSTANDBY */
  202. musb_writel(musb->mregs, OTG_FORCESTDBY, l);
  203. }
  204. void omap_musb_mailbox(enum omap_musb_vbus_id_status status)
  205. {
  206. struct omap2430_glue *glue = _glue;
  207. if (!glue) {
  208. pr_err("%s: musb core is not yet initialized\n", __func__);
  209. return;
  210. }
  211. glue->status = status;
  212. if (!glue_to_musb(glue)) {
  213. pr_err("%s: musb core is not yet ready\n", __func__);
  214. return;
  215. }
  216. schedule_work(&glue->omap_musb_mailbox_work);
  217. }
  218. EXPORT_SYMBOL_GPL(omap_musb_mailbox);
  219. static void omap_musb_set_mailbox(struct omap2430_glue *glue)
  220. {
  221. struct musb *musb = glue_to_musb(glue);
  222. struct device *dev = musb->controller;
  223. struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev);
  224. struct omap_musb_board_data *data = pdata->board_data;
  225. struct usb_otg *otg = musb->xceiv->otg;
  226. switch (glue->status) {
  227. case OMAP_MUSB_ID_GROUND:
  228. dev_dbg(dev, "ID GND\n");
  229. otg->default_a = true;
  230. musb->xceiv->state = OTG_STATE_A_IDLE;
  231. musb->xceiv->last_event = USB_EVENT_ID;
  232. if (musb->gadget_driver) {
  233. pm_runtime_get_sync(dev);
  234. omap_control_usb_set_mode(glue->control_otghs,
  235. USB_MODE_HOST);
  236. omap2430_musb_set_vbus(musb, 1);
  237. }
  238. break;
  239. case OMAP_MUSB_VBUS_VALID:
  240. dev_dbg(dev, "VBUS Connect\n");
  241. otg->default_a = false;
  242. musb->xceiv->state = OTG_STATE_B_IDLE;
  243. musb->xceiv->last_event = USB_EVENT_VBUS;
  244. if (musb->gadget_driver)
  245. pm_runtime_get_sync(dev);
  246. omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
  247. break;
  248. case OMAP_MUSB_ID_FLOAT:
  249. case OMAP_MUSB_VBUS_OFF:
  250. dev_dbg(dev, "VBUS Disconnect\n");
  251. musb->xceiv->last_event = USB_EVENT_NONE;
  252. if (musb->gadget_driver) {
  253. omap2430_musb_set_vbus(musb, 0);
  254. pm_runtime_mark_last_busy(dev);
  255. pm_runtime_put_autosuspend(dev);
  256. }
  257. if (data->interface_type == MUSB_INTERFACE_UTMI)
  258. otg_set_vbus(musb->xceiv->otg, 0);
  259. omap_control_usb_set_mode(glue->control_otghs,
  260. USB_MODE_DISCONNECT);
  261. break;
  262. default:
  263. dev_dbg(dev, "ID float\n");
  264. }
  265. atomic_notifier_call_chain(&musb->xceiv->notifier,
  266. musb->xceiv->last_event, NULL);
  267. }
  268. static void omap_musb_mailbox_work(struct work_struct *mailbox_work)
  269. {
  270. struct omap2430_glue *glue = container_of(mailbox_work,
  271. struct omap2430_glue, omap_musb_mailbox_work);
  272. struct musb *musb = glue_to_musb(glue);
  273. struct device *dev = musb->controller;
  274. pm_runtime_get_sync(dev);
  275. omap_musb_set_mailbox(glue);
  276. pm_runtime_mark_last_busy(dev);
  277. pm_runtime_put_autosuspend(dev);
  278. }
  279. static irqreturn_t omap2430_musb_interrupt(int irq, void *__hci)
  280. {
  281. unsigned long flags;
  282. irqreturn_t retval = IRQ_NONE;
  283. struct musb *musb = __hci;
  284. spin_lock_irqsave(&musb->lock, flags);
  285. musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
  286. musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
  287. musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX);
  288. if (musb->int_usb || musb->int_tx || musb->int_rx)
  289. retval = musb_interrupt(musb);
  290. spin_unlock_irqrestore(&musb->lock, flags);
  291. return retval;
  292. }
  293. static int omap2430_musb_init(struct musb *musb)
  294. {
  295. u32 l;
  296. int status = 0;
  297. struct device *dev = musb->controller;
  298. struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
  299. struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
  300. struct omap_musb_board_data *data = plat->board_data;
  301. /* We require some kind of external transceiver, hooked
  302. * up through ULPI. TWL4030-family PMICs include one,
  303. * which needs a driver, drivers aren't always needed.
  304. */
  305. if (dev->parent->of_node) {
  306. musb->phy = devm_phy_get(dev->parent, "usb2-phy");
  307. /* We can't totally remove musb->xceiv as of now because
  308. * musb core uses xceiv.state and xceiv.otg. Once we have
  309. * a separate state machine to handle otg, these can be moved
  310. * out of xceiv and then we can start using the generic PHY
  311. * framework
  312. */
  313. musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent,
  314. "usb-phy", 0);
  315. } else {
  316. musb->xceiv = devm_usb_get_phy_dev(dev, 0);
  317. musb->phy = devm_phy_get(dev, "usb");
  318. }
  319. if (IS_ERR(musb->xceiv)) {
  320. status = PTR_ERR(musb->xceiv);
  321. if (status == -ENXIO)
  322. return status;
  323. pr_err("HS USB OTG: no transceiver configured\n");
  324. return -EPROBE_DEFER;
  325. }
  326. if (IS_ERR(musb->phy)) {
  327. pr_err("HS USB OTG: no PHY configured\n");
  328. return PTR_ERR(musb->phy);
  329. }
  330. musb->isr = omap2430_musb_interrupt;
  331. status = pm_runtime_get_sync(dev);
  332. if (status < 0) {
  333. dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status);
  334. goto err1;
  335. }
  336. l = musb_readl(musb->mregs, OTG_INTERFSEL);
  337. if (data->interface_type == MUSB_INTERFACE_UTMI) {
  338. /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
  339. l &= ~ULPI_12PIN; /* Disable ULPI */
  340. l |= UTMI_8BIT; /* Enable UTMI */
  341. } else {
  342. l |= ULPI_12PIN;
  343. }
  344. musb_writel(musb->mregs, OTG_INTERFSEL, l);
  345. pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
  346. "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n",
  347. musb_readl(musb->mregs, OTG_REVISION),
  348. musb_readl(musb->mregs, OTG_SYSCONFIG),
  349. musb_readl(musb->mregs, OTG_SYSSTATUS),
  350. musb_readl(musb->mregs, OTG_INTERFSEL),
  351. musb_readl(musb->mregs, OTG_SIMENABLE));
  352. setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
  353. if (glue->status != OMAP_MUSB_UNKNOWN)
  354. omap_musb_set_mailbox(glue);
  355. phy_init(musb->phy);
  356. phy_power_on(musb->phy);
  357. pm_runtime_put_noidle(musb->controller);
  358. return 0;
  359. err1:
  360. return status;
  361. }
  362. static void omap2430_musb_enable(struct musb *musb)
  363. {
  364. u8 devctl;
  365. unsigned long timeout = jiffies + msecs_to_jiffies(1000);
  366. struct device *dev = musb->controller;
  367. struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
  368. struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev);
  369. struct omap_musb_board_data *data = pdata->board_data;
  370. switch (glue->status) {
  371. case OMAP_MUSB_ID_GROUND:
  372. omap_control_usb_set_mode(glue->control_otghs, USB_MODE_HOST);
  373. if (data->interface_type != MUSB_INTERFACE_UTMI)
  374. break;
  375. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  376. /* start the session */
  377. devctl |= MUSB_DEVCTL_SESSION;
  378. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  379. while (musb_readb(musb->mregs, MUSB_DEVCTL) &
  380. MUSB_DEVCTL_BDEVICE) {
  381. cpu_relax();
  382. if (time_after(jiffies, timeout)) {
  383. dev_err(dev, "configured as A device timeout");
  384. break;
  385. }
  386. }
  387. break;
  388. case OMAP_MUSB_VBUS_VALID:
  389. omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
  390. break;
  391. default:
  392. break;
  393. }
  394. }
  395. static void omap2430_musb_disable(struct musb *musb)
  396. {
  397. struct device *dev = musb->controller;
  398. struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
  399. if (glue->status != OMAP_MUSB_UNKNOWN)
  400. omap_control_usb_set_mode(glue->control_otghs,
  401. USB_MODE_DISCONNECT);
  402. }
  403. static int omap2430_musb_exit(struct musb *musb)
  404. {
  405. del_timer_sync(&musb_idle_timer);
  406. omap2430_low_level_exit(musb);
  407. phy_power_off(musb->phy);
  408. phy_exit(musb->phy);
  409. return 0;
  410. }
  411. static const struct musb_platform_ops omap2430_ops = {
  412. .init = omap2430_musb_init,
  413. .exit = omap2430_musb_exit,
  414. .set_mode = omap2430_musb_set_mode,
  415. .try_idle = omap2430_musb_try_idle,
  416. .set_vbus = omap2430_musb_set_vbus,
  417. .enable = omap2430_musb_enable,
  418. .disable = omap2430_musb_disable,
  419. };
  420. static u64 omap2430_dmamask = DMA_BIT_MASK(32);
  421. static int omap2430_probe(struct platform_device *pdev)
  422. {
  423. struct resource musb_resources[3];
  424. struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
  425. struct omap_musb_board_data *data;
  426. struct platform_device *musb;
  427. struct omap2430_glue *glue;
  428. struct device_node *np = pdev->dev.of_node;
  429. struct musb_hdrc_config *config;
  430. int ret = -ENOMEM;
  431. glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
  432. if (!glue) {
  433. dev_err(&pdev->dev, "failed to allocate glue context\n");
  434. goto err0;
  435. }
  436. musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
  437. if (!musb) {
  438. dev_err(&pdev->dev, "failed to allocate musb device\n");
  439. goto err0;
  440. }
  441. musb->dev.parent = &pdev->dev;
  442. musb->dev.dma_mask = &omap2430_dmamask;
  443. musb->dev.coherent_dma_mask = omap2430_dmamask;
  444. glue->dev = &pdev->dev;
  445. glue->musb = musb;
  446. glue->status = OMAP_MUSB_UNKNOWN;
  447. glue->control_otghs = ERR_PTR(-ENODEV);
  448. if (np) {
  449. struct device_node *control_node;
  450. struct platform_device *control_pdev;
  451. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  452. if (!pdata) {
  453. dev_err(&pdev->dev,
  454. "failed to allocate musb platform data\n");
  455. goto err2;
  456. }
  457. data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
  458. if (!data) {
  459. dev_err(&pdev->dev,
  460. "failed to allocate musb board data\n");
  461. goto err2;
  462. }
  463. config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
  464. if (!config) {
  465. dev_err(&pdev->dev,
  466. "failed to allocate musb hdrc config\n");
  467. goto err2;
  468. }
  469. of_property_read_u32(np, "mode", (u32 *)&pdata->mode);
  470. of_property_read_u32(np, "interface-type",
  471. (u32 *)&data->interface_type);
  472. of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps);
  473. of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits);
  474. of_property_read_u32(np, "power", (u32 *)&pdata->power);
  475. config->multipoint = of_property_read_bool(np, "multipoint");
  476. pdata->board_data = data;
  477. pdata->config = config;
  478. control_node = of_parse_phandle(np, "ctrl-module", 0);
  479. if (control_node) {
  480. control_pdev = of_find_device_by_node(control_node);
  481. if (!control_pdev) {
  482. dev_err(&pdev->dev, "Failed to get control device\n");
  483. ret = -EINVAL;
  484. goto err2;
  485. }
  486. glue->control_otghs = &control_pdev->dev;
  487. }
  488. }
  489. pdata->platform_ops = &omap2430_ops;
  490. platform_set_drvdata(pdev, glue);
  491. /*
  492. * REVISIT if we ever have two instances of the wrapper, we will be
  493. * in big trouble
  494. */
  495. _glue = glue;
  496. INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work);
  497. memset(musb_resources, 0x00, sizeof(*musb_resources) *
  498. ARRAY_SIZE(musb_resources));
  499. musb_resources[0].name = pdev->resource[0].name;
  500. musb_resources[0].start = pdev->resource[0].start;
  501. musb_resources[0].end = pdev->resource[0].end;
  502. musb_resources[0].flags = pdev->resource[0].flags;
  503. musb_resources[1].name = pdev->resource[1].name;
  504. musb_resources[1].start = pdev->resource[1].start;
  505. musb_resources[1].end = pdev->resource[1].end;
  506. musb_resources[1].flags = pdev->resource[1].flags;
  507. musb_resources[2].name = pdev->resource[2].name;
  508. musb_resources[2].start = pdev->resource[2].start;
  509. musb_resources[2].end = pdev->resource[2].end;
  510. musb_resources[2].flags = pdev->resource[2].flags;
  511. ret = platform_device_add_resources(musb, musb_resources,
  512. ARRAY_SIZE(musb_resources));
  513. if (ret) {
  514. dev_err(&pdev->dev, "failed to add resources\n");
  515. goto err2;
  516. }
  517. ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
  518. if (ret) {
  519. dev_err(&pdev->dev, "failed to add platform_data\n");
  520. goto err2;
  521. }
  522. pm_runtime_enable(&pdev->dev);
  523. ret = platform_device_add(musb);
  524. if (ret) {
  525. dev_err(&pdev->dev, "failed to register musb device\n");
  526. goto err2;
  527. }
  528. return 0;
  529. err2:
  530. platform_device_put(musb);
  531. err0:
  532. return ret;
  533. }
  534. static int omap2430_remove(struct platform_device *pdev)
  535. {
  536. struct omap2430_glue *glue = platform_get_drvdata(pdev);
  537. cancel_work_sync(&glue->omap_musb_mailbox_work);
  538. platform_device_unregister(glue->musb);
  539. return 0;
  540. }
  541. #ifdef CONFIG_PM
  542. static int omap2430_runtime_suspend(struct device *dev)
  543. {
  544. struct omap2430_glue *glue = dev_get_drvdata(dev);
  545. struct musb *musb = glue_to_musb(glue);
  546. if (musb) {
  547. musb->context.otg_interfsel = musb_readl(musb->mregs,
  548. OTG_INTERFSEL);
  549. omap2430_low_level_exit(musb);
  550. }
  551. return 0;
  552. }
  553. static int omap2430_runtime_resume(struct device *dev)
  554. {
  555. struct omap2430_glue *glue = dev_get_drvdata(dev);
  556. struct musb *musb = glue_to_musb(glue);
  557. if (musb) {
  558. omap2430_low_level_init(musb);
  559. musb_writel(musb->mregs, OTG_INTERFSEL,
  560. musb->context.otg_interfsel);
  561. }
  562. return 0;
  563. }
  564. static struct dev_pm_ops omap2430_pm_ops = {
  565. .runtime_suspend = omap2430_runtime_suspend,
  566. .runtime_resume = omap2430_runtime_resume,
  567. };
  568. #define DEV_PM_OPS (&omap2430_pm_ops)
  569. #else
  570. #define DEV_PM_OPS NULL
  571. #endif
  572. #ifdef CONFIG_OF
  573. static const struct of_device_id omap2430_id_table[] = {
  574. {
  575. .compatible = "ti,omap4-musb"
  576. },
  577. {
  578. .compatible = "ti,omap3-musb"
  579. },
  580. {},
  581. };
  582. MODULE_DEVICE_TABLE(of, omap2430_id_table);
  583. #endif
  584. static struct platform_driver omap2430_driver = {
  585. .probe = omap2430_probe,
  586. .remove = omap2430_remove,
  587. .driver = {
  588. .name = "musb-omap2430",
  589. .pm = DEV_PM_OPS,
  590. .of_match_table = of_match_ptr(omap2430_id_table),
  591. },
  592. };
  593. MODULE_DESCRIPTION("OMAP2PLUS MUSB Glue Layer");
  594. MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
  595. MODULE_LICENSE("GPL v2");
  596. static int __init omap2430_init(void)
  597. {
  598. return platform_driver_register(&omap2430_driver);
  599. }
  600. subsys_initcall(omap2430_init);
  601. static void __exit omap2430_exit(void)
  602. {
  603. platform_driver_unregister(&omap2430_driver);
  604. }
  605. module_exit(omap2430_exit);