omap2430.c 18 KB

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