omap2430.c 19 KB

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