omap2430.c 17 KB

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