omap2430.c 18 KB

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