omap2430.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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/usb/omap_control_usb.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. omap_musb_set_mailbox(glue);
  273. }
  274. static irqreturn_t omap2430_musb_interrupt(int irq, void *__hci)
  275. {
  276. unsigned long flags;
  277. irqreturn_t retval = IRQ_NONE;
  278. struct musb *musb = __hci;
  279. spin_lock_irqsave(&musb->lock, flags);
  280. musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
  281. musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
  282. musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX);
  283. if (musb->int_usb || musb->int_tx || musb->int_rx)
  284. retval = musb_interrupt(musb);
  285. spin_unlock_irqrestore(&musb->lock, flags);
  286. return retval;
  287. }
  288. static int omap2430_musb_init(struct musb *musb)
  289. {
  290. u32 l;
  291. int status = 0;
  292. struct device *dev = musb->controller;
  293. struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
  294. struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
  295. struct omap_musb_board_data *data = plat->board_data;
  296. /* We require some kind of external transceiver, hooked
  297. * up through ULPI. TWL4030-family PMICs include one,
  298. * which needs a driver, drivers aren't always needed.
  299. */
  300. if (dev->parent->of_node) {
  301. musb->phy = devm_phy_get(dev->parent, "usb2-phy");
  302. /* We can't totally remove musb->xceiv as of now because
  303. * musb core uses xceiv.state and xceiv.otg. Once we have
  304. * a separate state machine to handle otg, these can be moved
  305. * out of xceiv and then we can start using the generic PHY
  306. * framework
  307. */
  308. musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent,
  309. "usb-phy", 0);
  310. } else {
  311. musb->xceiv = devm_usb_get_phy_dev(dev, 0);
  312. musb->phy = devm_phy_get(dev, "usb");
  313. }
  314. if (IS_ERR(musb->xceiv)) {
  315. status = PTR_ERR(musb->xceiv);
  316. if (status == -ENXIO)
  317. return status;
  318. pr_err("HS USB OTG: no transceiver configured\n");
  319. return -EPROBE_DEFER;
  320. }
  321. if (IS_ERR(musb->phy)) {
  322. pr_err("HS USB OTG: no PHY configured\n");
  323. return PTR_ERR(musb->phy);
  324. }
  325. musb->isr = omap2430_musb_interrupt;
  326. status = pm_runtime_get_sync(dev);
  327. if (status < 0) {
  328. dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status);
  329. goto err1;
  330. }
  331. l = musb_readl(musb->mregs, OTG_INTERFSEL);
  332. if (data->interface_type == MUSB_INTERFACE_UTMI) {
  333. /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
  334. l &= ~ULPI_12PIN; /* Disable ULPI */
  335. l |= UTMI_8BIT; /* Enable UTMI */
  336. } else {
  337. l |= ULPI_12PIN;
  338. }
  339. musb_writel(musb->mregs, OTG_INTERFSEL, l);
  340. pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
  341. "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n",
  342. musb_readl(musb->mregs, OTG_REVISION),
  343. musb_readl(musb->mregs, OTG_SYSCONFIG),
  344. musb_readl(musb->mregs, OTG_SYSSTATUS),
  345. musb_readl(musb->mregs, OTG_INTERFSEL),
  346. musb_readl(musb->mregs, OTG_SIMENABLE));
  347. setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
  348. if (glue->status != OMAP_MUSB_UNKNOWN)
  349. omap_musb_set_mailbox(glue);
  350. phy_init(musb->phy);
  351. pm_runtime_put_noidle(musb->controller);
  352. return 0;
  353. err1:
  354. return status;
  355. }
  356. static void omap2430_musb_enable(struct musb *musb)
  357. {
  358. u8 devctl;
  359. unsigned long timeout = jiffies + msecs_to_jiffies(1000);
  360. struct device *dev = musb->controller;
  361. struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
  362. struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev);
  363. struct omap_musb_board_data *data = pdata->board_data;
  364. switch (glue->status) {
  365. case OMAP_MUSB_ID_GROUND:
  366. omap_control_usb_set_mode(glue->control_otghs, USB_MODE_HOST);
  367. if (data->interface_type != MUSB_INTERFACE_UTMI)
  368. break;
  369. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  370. /* start the session */
  371. devctl |= MUSB_DEVCTL_SESSION;
  372. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  373. while (musb_readb(musb->mregs, MUSB_DEVCTL) &
  374. MUSB_DEVCTL_BDEVICE) {
  375. cpu_relax();
  376. if (time_after(jiffies, timeout)) {
  377. dev_err(dev, "configured as A device timeout");
  378. break;
  379. }
  380. }
  381. break;
  382. case OMAP_MUSB_VBUS_VALID:
  383. omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
  384. break;
  385. default:
  386. break;
  387. }
  388. }
  389. static void omap2430_musb_disable(struct musb *musb)
  390. {
  391. struct device *dev = musb->controller;
  392. struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
  393. if (glue->status != OMAP_MUSB_UNKNOWN)
  394. omap_control_usb_set_mode(glue->control_otghs,
  395. USB_MODE_DISCONNECT);
  396. }
  397. static int omap2430_musb_exit(struct musb *musb)
  398. {
  399. del_timer_sync(&musb_idle_timer);
  400. omap2430_low_level_exit(musb);
  401. phy_exit(musb->phy);
  402. return 0;
  403. }
  404. static const struct musb_platform_ops omap2430_ops = {
  405. .init = omap2430_musb_init,
  406. .exit = omap2430_musb_exit,
  407. .set_mode = omap2430_musb_set_mode,
  408. .try_idle = omap2430_musb_try_idle,
  409. .set_vbus = omap2430_musb_set_vbus,
  410. .enable = omap2430_musb_enable,
  411. .disable = omap2430_musb_disable,
  412. };
  413. static u64 omap2430_dmamask = DMA_BIT_MASK(32);
  414. static int omap2430_probe(struct platform_device *pdev)
  415. {
  416. struct resource musb_resources[3];
  417. struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
  418. struct omap_musb_board_data *data;
  419. struct platform_device *musb;
  420. struct omap2430_glue *glue;
  421. struct device_node *np = pdev->dev.of_node;
  422. struct musb_hdrc_config *config;
  423. int ret = -ENOMEM;
  424. glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
  425. if (!glue) {
  426. dev_err(&pdev->dev, "failed to allocate glue context\n");
  427. goto err0;
  428. }
  429. musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
  430. if (!musb) {
  431. dev_err(&pdev->dev, "failed to allocate musb device\n");
  432. goto err0;
  433. }
  434. musb->dev.parent = &pdev->dev;
  435. musb->dev.dma_mask = &omap2430_dmamask;
  436. musb->dev.coherent_dma_mask = omap2430_dmamask;
  437. glue->dev = &pdev->dev;
  438. glue->musb = musb;
  439. glue->status = OMAP_MUSB_UNKNOWN;
  440. glue->control_otghs = ERR_PTR(-ENODEV);
  441. if (np) {
  442. struct device_node *control_node;
  443. struct platform_device *control_pdev;
  444. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  445. if (!pdata) {
  446. dev_err(&pdev->dev,
  447. "failed to allocate musb platform data\n");
  448. goto err2;
  449. }
  450. data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
  451. if (!data) {
  452. dev_err(&pdev->dev,
  453. "failed to allocate musb board data\n");
  454. goto err2;
  455. }
  456. config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
  457. if (!config) {
  458. dev_err(&pdev->dev,
  459. "failed to allocate musb hdrc config\n");
  460. goto err2;
  461. }
  462. of_property_read_u32(np, "mode", (u32 *)&pdata->mode);
  463. of_property_read_u32(np, "interface-type",
  464. (u32 *)&data->interface_type);
  465. of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps);
  466. of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits);
  467. of_property_read_u32(np, "power", (u32 *)&pdata->power);
  468. config->multipoint = of_property_read_bool(np, "multipoint");
  469. pdata->board_data = data;
  470. pdata->config = config;
  471. control_node = of_parse_phandle(np, "ctrl-module", 0);
  472. if (control_node) {
  473. control_pdev = of_find_device_by_node(control_node);
  474. if (!control_pdev) {
  475. dev_err(&pdev->dev, "Failed to get control device\n");
  476. ret = -EINVAL;
  477. goto err2;
  478. }
  479. glue->control_otghs = &control_pdev->dev;
  480. }
  481. }
  482. pdata->platform_ops = &omap2430_ops;
  483. platform_set_drvdata(pdev, glue);
  484. /*
  485. * REVISIT if we ever have two instances of the wrapper, we will be
  486. * in big trouble
  487. */
  488. _glue = glue;
  489. INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work);
  490. memset(musb_resources, 0x00, sizeof(*musb_resources) *
  491. ARRAY_SIZE(musb_resources));
  492. musb_resources[0].name = pdev->resource[0].name;
  493. musb_resources[0].start = pdev->resource[0].start;
  494. musb_resources[0].end = pdev->resource[0].end;
  495. musb_resources[0].flags = pdev->resource[0].flags;
  496. musb_resources[1].name = pdev->resource[1].name;
  497. musb_resources[1].start = pdev->resource[1].start;
  498. musb_resources[1].end = pdev->resource[1].end;
  499. musb_resources[1].flags = pdev->resource[1].flags;
  500. musb_resources[2].name = pdev->resource[2].name;
  501. musb_resources[2].start = pdev->resource[2].start;
  502. musb_resources[2].end = pdev->resource[2].end;
  503. musb_resources[2].flags = pdev->resource[2].flags;
  504. ret = platform_device_add_resources(musb, musb_resources,
  505. ARRAY_SIZE(musb_resources));
  506. if (ret) {
  507. dev_err(&pdev->dev, "failed to add resources\n");
  508. goto err2;
  509. }
  510. ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
  511. if (ret) {
  512. dev_err(&pdev->dev, "failed to add platform_data\n");
  513. goto err2;
  514. }
  515. pm_runtime_enable(&pdev->dev);
  516. ret = platform_device_add(musb);
  517. if (ret) {
  518. dev_err(&pdev->dev, "failed to register musb device\n");
  519. goto err2;
  520. }
  521. return 0;
  522. err2:
  523. platform_device_put(musb);
  524. err0:
  525. return ret;
  526. }
  527. static int omap2430_remove(struct platform_device *pdev)
  528. {
  529. struct omap2430_glue *glue = platform_get_drvdata(pdev);
  530. cancel_work_sync(&glue->omap_musb_mailbox_work);
  531. platform_device_unregister(glue->musb);
  532. return 0;
  533. }
  534. #ifdef CONFIG_PM
  535. static int omap2430_runtime_suspend(struct device *dev)
  536. {
  537. struct omap2430_glue *glue = dev_get_drvdata(dev);
  538. struct musb *musb = glue_to_musb(glue);
  539. if (musb) {
  540. musb->context.otg_interfsel = musb_readl(musb->mregs,
  541. OTG_INTERFSEL);
  542. omap2430_low_level_exit(musb);
  543. phy_power_off(musb->phy);
  544. }
  545. return 0;
  546. }
  547. static int omap2430_runtime_resume(struct device *dev)
  548. {
  549. struct omap2430_glue *glue = dev_get_drvdata(dev);
  550. struct musb *musb = glue_to_musb(glue);
  551. if (musb) {
  552. omap2430_low_level_init(musb);
  553. musb_writel(musb->mregs, OTG_INTERFSEL,
  554. musb->context.otg_interfsel);
  555. phy_power_on(musb->phy);
  556. }
  557. return 0;
  558. }
  559. static struct dev_pm_ops omap2430_pm_ops = {
  560. .runtime_suspend = omap2430_runtime_suspend,
  561. .runtime_resume = omap2430_runtime_resume,
  562. };
  563. #define DEV_PM_OPS (&omap2430_pm_ops)
  564. #else
  565. #define DEV_PM_OPS NULL
  566. #endif
  567. #ifdef CONFIG_OF
  568. static const struct of_device_id omap2430_id_table[] = {
  569. {
  570. .compatible = "ti,omap4-musb"
  571. },
  572. {
  573. .compatible = "ti,omap3-musb"
  574. },
  575. {},
  576. };
  577. MODULE_DEVICE_TABLE(of, omap2430_id_table);
  578. #endif
  579. static struct platform_driver omap2430_driver = {
  580. .probe = omap2430_probe,
  581. .remove = omap2430_remove,
  582. .driver = {
  583. .name = "musb-omap2430",
  584. .pm = DEV_PM_OPS,
  585. .of_match_table = of_match_ptr(omap2430_id_table),
  586. },
  587. };
  588. MODULE_DESCRIPTION("OMAP2PLUS MUSB Glue Layer");
  589. MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
  590. MODULE_LICENSE("GPL v2");
  591. static int __init omap2430_init(void)
  592. {
  593. return platform_driver_register(&omap2430_driver);
  594. }
  595. subsys_initcall(omap2430_init);
  596. static void __exit omap2430_exit(void)
  597. {
  598. platform_driver_unregister(&omap2430_driver);
  599. }
  600. module_exit(omap2430_exit);