musb_dsps.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /*
  2. * Texas Instruments DSPS platforms "glue layer"
  3. *
  4. * Copyright (C) 2012, by Texas Instruments
  5. *
  6. * Based on the am35x "glue layer" code.
  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. * musb_dsps.c will be a common file for all the TI DSPS platforms
  27. * such as dm64x, dm36x, dm35x, da8x, am35x and ti81x.
  28. * For now only ti81x is using this and in future davinci.c, am35x.c
  29. * da8xx.c would be merged to this file after testing.
  30. */
  31. #define __UBOOT__
  32. #ifndef __UBOOT__
  33. #include <linux/init.h>
  34. #include <linux/io.h>
  35. #include <linux/err.h>
  36. #include <linux/platform_device.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/pm_runtime.h>
  39. #include <linux/module.h>
  40. #include <linux/of.h>
  41. #include <linux/of_device.h>
  42. #include <linux/of_address.h>
  43. #include <plat/usb.h>
  44. #else
  45. #include <common.h>
  46. #include <asm/omap_musb.h>
  47. #include "linux-compat.h"
  48. #endif
  49. #include "musb_core.h"
  50. /**
  51. * avoid using musb_readx()/musb_writex() as glue layer should not be
  52. * dependent on musb core layer symbols.
  53. */
  54. static inline u8 dsps_readb(const void __iomem *addr, unsigned offset)
  55. { return __raw_readb(addr + offset); }
  56. static inline u32 dsps_readl(const void __iomem *addr, unsigned offset)
  57. { return __raw_readl(addr + offset); }
  58. static inline void dsps_writeb(void __iomem *addr, unsigned offset, u8 data)
  59. { __raw_writeb(data, addr + offset); }
  60. static inline void dsps_writel(void __iomem *addr, unsigned offset, u32 data)
  61. { __raw_writel(data, addr + offset); }
  62. /**
  63. * DSPS musb wrapper register offset.
  64. * FIXME: This should be expanded to have all the wrapper registers from TI DSPS
  65. * musb ips.
  66. */
  67. struct dsps_musb_wrapper {
  68. u16 revision;
  69. u16 control;
  70. u16 status;
  71. u16 eoi;
  72. u16 epintr_set;
  73. u16 epintr_clear;
  74. u16 epintr_status;
  75. u16 coreintr_set;
  76. u16 coreintr_clear;
  77. u16 coreintr_status;
  78. u16 phy_utmi;
  79. u16 mode;
  80. /* bit positions for control */
  81. unsigned reset:5;
  82. /* bit positions for interrupt */
  83. unsigned usb_shift:5;
  84. u32 usb_mask;
  85. u32 usb_bitmap;
  86. unsigned drvvbus:5;
  87. unsigned txep_shift:5;
  88. u32 txep_mask;
  89. u32 txep_bitmap;
  90. unsigned rxep_shift:5;
  91. u32 rxep_mask;
  92. u32 rxep_bitmap;
  93. /* bit positions for phy_utmi */
  94. unsigned otg_disable:5;
  95. /* bit positions for mode */
  96. unsigned iddig:5;
  97. /* miscellaneous stuff */
  98. u32 musb_core_offset;
  99. u8 poll_seconds;
  100. };
  101. static const struct dsps_musb_wrapper ti81xx_driver_data __devinitconst = {
  102. .revision = 0x00,
  103. .control = 0x14,
  104. .status = 0x18,
  105. .eoi = 0x24,
  106. .epintr_set = 0x38,
  107. .epintr_clear = 0x40,
  108. .epintr_status = 0x30,
  109. .coreintr_set = 0x3c,
  110. .coreintr_clear = 0x44,
  111. .coreintr_status = 0x34,
  112. .phy_utmi = 0xe0,
  113. .mode = 0xe8,
  114. .reset = 0,
  115. .otg_disable = 21,
  116. .iddig = 8,
  117. .usb_shift = 0,
  118. .usb_mask = 0x1ff,
  119. .usb_bitmap = (0x1ff << 0),
  120. .drvvbus = 8,
  121. .txep_shift = 0,
  122. .txep_mask = 0xffff,
  123. .txep_bitmap = (0xffff << 0),
  124. .rxep_shift = 16,
  125. .rxep_mask = 0xfffe,
  126. .rxep_bitmap = (0xfffe << 16),
  127. .musb_core_offset = 0x400,
  128. .poll_seconds = 2,
  129. };
  130. /**
  131. * DSPS glue structure.
  132. */
  133. struct dsps_glue {
  134. struct device *dev;
  135. struct platform_device *musb; /* child musb pdev */
  136. const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */
  137. struct timer_list timer; /* otg_workaround timer */
  138. };
  139. /**
  140. * dsps_musb_enable - enable interrupts
  141. */
  142. static void dsps_musb_enable(struct musb *musb)
  143. {
  144. #ifndef __UBOOT__
  145. struct device *dev = musb->controller;
  146. struct platform_device *pdev = to_platform_device(dev->parent);
  147. struct dsps_glue *glue = platform_get_drvdata(pdev);
  148. const struct dsps_musb_wrapper *wrp = glue->wrp;
  149. #else
  150. const struct dsps_musb_wrapper *wrp = &ti81xx_driver_data;
  151. #endif
  152. void __iomem *reg_base = musb->ctrl_base;
  153. u32 epmask, coremask;
  154. /* Workaround: setup IRQs through both register sets. */
  155. epmask = ((musb->epmask & wrp->txep_mask) << wrp->txep_shift) |
  156. ((musb->epmask & wrp->rxep_mask) << wrp->rxep_shift);
  157. coremask = (wrp->usb_bitmap & ~MUSB_INTR_SOF);
  158. dsps_writel(reg_base, wrp->epintr_set, epmask);
  159. dsps_writel(reg_base, wrp->coreintr_set, coremask);
  160. /* Force the DRVVBUS IRQ so we can start polling for ID change. */
  161. #ifndef __UBOOT__
  162. if (is_otg_enabled(musb))
  163. dsps_writel(reg_base, wrp->coreintr_set,
  164. (1 << wrp->drvvbus) << wrp->usb_shift);
  165. #endif
  166. }
  167. /**
  168. * dsps_musb_disable - disable HDRC and flush interrupts
  169. */
  170. static void dsps_musb_disable(struct musb *musb)
  171. {
  172. #ifndef __UBOOT__
  173. struct device *dev = musb->controller;
  174. struct platform_device *pdev = to_platform_device(dev->parent);
  175. struct dsps_glue *glue = platform_get_drvdata(pdev);
  176. const struct dsps_musb_wrapper *wrp = glue->wrp;
  177. void __iomem *reg_base = musb->ctrl_base;
  178. dsps_writel(reg_base, wrp->coreintr_clear, wrp->usb_bitmap);
  179. dsps_writel(reg_base, wrp->epintr_clear,
  180. wrp->txep_bitmap | wrp->rxep_bitmap);
  181. dsps_writeb(musb->mregs, MUSB_DEVCTL, 0);
  182. dsps_writel(reg_base, wrp->eoi, 0);
  183. #endif
  184. }
  185. #ifndef __UBOOT__
  186. static void otg_timer(unsigned long _musb)
  187. {
  188. struct musb *musb = (void *)_musb;
  189. void __iomem *mregs = musb->mregs;
  190. struct device *dev = musb->controller;
  191. struct platform_device *pdev = to_platform_device(dev->parent);
  192. struct dsps_glue *glue = platform_get_drvdata(pdev);
  193. const struct dsps_musb_wrapper *wrp = glue->wrp;
  194. u8 devctl;
  195. unsigned long flags;
  196. /*
  197. * We poll because DSPS IP's won't expose several OTG-critical
  198. * status change events (from the transceiver) otherwise.
  199. */
  200. devctl = dsps_readb(mregs, MUSB_DEVCTL);
  201. dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
  202. otg_state_string(musb->xceiv->state));
  203. spin_lock_irqsave(&musb->lock, flags);
  204. switch (musb->xceiv->state) {
  205. case OTG_STATE_A_WAIT_BCON:
  206. devctl &= ~MUSB_DEVCTL_SESSION;
  207. dsps_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  208. devctl = dsps_readb(musb->mregs, MUSB_DEVCTL);
  209. if (devctl & MUSB_DEVCTL_BDEVICE) {
  210. musb->xceiv->state = OTG_STATE_B_IDLE;
  211. MUSB_DEV_MODE(musb);
  212. } else {
  213. musb->xceiv->state = OTG_STATE_A_IDLE;
  214. MUSB_HST_MODE(musb);
  215. }
  216. break;
  217. case OTG_STATE_A_WAIT_VFALL:
  218. musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
  219. dsps_writel(musb->ctrl_base, wrp->coreintr_set,
  220. MUSB_INTR_VBUSERROR << wrp->usb_shift);
  221. break;
  222. case OTG_STATE_B_IDLE:
  223. if (!is_peripheral_enabled(musb))
  224. break;
  225. devctl = dsps_readb(mregs, MUSB_DEVCTL);
  226. if (devctl & MUSB_DEVCTL_BDEVICE)
  227. mod_timer(&glue->timer,
  228. jiffies + wrp->poll_seconds * HZ);
  229. else
  230. musb->xceiv->state = OTG_STATE_A_IDLE;
  231. break;
  232. default:
  233. break;
  234. }
  235. spin_unlock_irqrestore(&musb->lock, flags);
  236. }
  237. static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
  238. {
  239. struct device *dev = musb->controller;
  240. struct platform_device *pdev = to_platform_device(dev->parent);
  241. struct dsps_glue *glue = platform_get_drvdata(pdev);
  242. static unsigned long last_timer;
  243. if (!is_otg_enabled(musb))
  244. return;
  245. if (timeout == 0)
  246. timeout = jiffies + msecs_to_jiffies(3);
  247. /* Never idle if active, or when VBUS timeout is not set as host */
  248. if (musb->is_active || (musb->a_wait_bcon == 0 &&
  249. musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
  250. dev_dbg(musb->controller, "%s active, deleting timer\n",
  251. otg_state_string(musb->xceiv->state));
  252. del_timer(&glue->timer);
  253. last_timer = jiffies;
  254. return;
  255. }
  256. if (time_after(last_timer, timeout) && timer_pending(&glue->timer)) {
  257. dev_dbg(musb->controller,
  258. "Longer idle timer already pending, ignoring...\n");
  259. return;
  260. }
  261. last_timer = timeout;
  262. dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
  263. otg_state_string(musb->xceiv->state),
  264. jiffies_to_msecs(timeout - jiffies));
  265. mod_timer(&glue->timer, timeout);
  266. }
  267. #endif
  268. static irqreturn_t dsps_interrupt(int irq, void *hci)
  269. {
  270. struct musb *musb = hci;
  271. void __iomem *reg_base = musb->ctrl_base;
  272. #ifndef __UBOOT__
  273. struct device *dev = musb->controller;
  274. struct platform_device *pdev = to_platform_device(dev->parent);
  275. struct dsps_glue *glue = platform_get_drvdata(pdev);
  276. const struct dsps_musb_wrapper *wrp = glue->wrp;
  277. #else
  278. const struct dsps_musb_wrapper *wrp = &ti81xx_driver_data;
  279. #endif
  280. unsigned long flags;
  281. irqreturn_t ret = IRQ_NONE;
  282. u32 epintr, usbintr;
  283. spin_lock_irqsave(&musb->lock, flags);
  284. /* Get endpoint interrupts */
  285. epintr = dsps_readl(reg_base, wrp->epintr_status);
  286. musb->int_rx = (epintr & wrp->rxep_bitmap) >> wrp->rxep_shift;
  287. musb->int_tx = (epintr & wrp->txep_bitmap) >> wrp->txep_shift;
  288. if (epintr)
  289. dsps_writel(reg_base, wrp->epintr_status, epintr);
  290. /* Get usb core interrupts */
  291. usbintr = dsps_readl(reg_base, wrp->coreintr_status);
  292. if (!usbintr && !epintr)
  293. goto eoi;
  294. musb->int_usb = (usbintr & wrp->usb_bitmap) >> wrp->usb_shift;
  295. if (usbintr)
  296. dsps_writel(reg_base, wrp->coreintr_status, usbintr);
  297. dev_dbg(musb->controller, "usbintr (%x) epintr(%x)\n",
  298. usbintr, epintr);
  299. #ifndef __UBOOT__
  300. /*
  301. * DRVVBUS IRQs are the only proxy we have (a very poor one!) for
  302. * DSPS IP's missing ID change IRQ. We need an ID change IRQ to
  303. * switch appropriately between halves of the OTG state machine.
  304. * Managing DEVCTL.SESSION per Mentor docs requires that we know its
  305. * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
  306. * Also, DRVVBUS pulses for SRP (but not at 5V) ...
  307. */
  308. if ((usbintr & MUSB_INTR_BABBLE) && is_host_enabled(musb))
  309. pr_info("CAUTION: musb: Babble Interrupt Occured\n");
  310. if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) {
  311. int drvvbus = dsps_readl(reg_base, wrp->status);
  312. void __iomem *mregs = musb->mregs;
  313. u8 devctl = dsps_readb(mregs, MUSB_DEVCTL);
  314. int err;
  315. err = is_host_enabled(musb) && (musb->int_usb &
  316. MUSB_INTR_VBUSERROR);
  317. if (err) {
  318. /*
  319. * The Mentor core doesn't debounce VBUS as needed
  320. * to cope with device connect current spikes. This
  321. * means it's not uncommon for bus-powered devices
  322. * to get VBUS errors during enumeration.
  323. *
  324. * This is a workaround, but newer RTL from Mentor
  325. * seems to allow a better one: "re"-starting sessions
  326. * without waiting for VBUS to stop registering in
  327. * devctl.
  328. */
  329. musb->int_usb &= ~MUSB_INTR_VBUSERROR;
  330. musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
  331. mod_timer(&glue->timer,
  332. jiffies + wrp->poll_seconds * HZ);
  333. WARNING("VBUS error workaround (delay coming)\n");
  334. } else if (is_host_enabled(musb) && drvvbus) {
  335. musb->is_active = 1;
  336. MUSB_HST_MODE(musb);
  337. musb->xceiv->otg->default_a = 1;
  338. musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
  339. del_timer(&glue->timer);
  340. } else {
  341. musb->is_active = 0;
  342. MUSB_DEV_MODE(musb);
  343. musb->xceiv->otg->default_a = 0;
  344. musb->xceiv->state = OTG_STATE_B_IDLE;
  345. }
  346. /* NOTE: this must complete power-on within 100 ms. */
  347. dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
  348. drvvbus ? "on" : "off",
  349. otg_state_string(musb->xceiv->state),
  350. err ? " ERROR" : "",
  351. devctl);
  352. ret = IRQ_HANDLED;
  353. }
  354. #endif
  355. if (musb->int_tx || musb->int_rx || musb->int_usb)
  356. ret |= musb_interrupt(musb);
  357. eoi:
  358. /* EOI needs to be written for the IRQ to be re-asserted. */
  359. if (ret == IRQ_HANDLED || epintr || usbintr)
  360. dsps_writel(reg_base, wrp->eoi, 1);
  361. #ifndef __UBOOT__
  362. /* Poll for ID change */
  363. if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE)
  364. mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ);
  365. #endif
  366. spin_unlock_irqrestore(&musb->lock, flags);
  367. return ret;
  368. }
  369. static int dsps_musb_init(struct musb *musb)
  370. {
  371. #ifndef __UBOOT__
  372. struct device *dev = musb->controller;
  373. struct musb_hdrc_platform_data *plat = dev->platform_data;
  374. struct platform_device *pdev = to_platform_device(dev->parent);
  375. struct dsps_glue *glue = platform_get_drvdata(pdev);
  376. const struct dsps_musb_wrapper *wrp = glue->wrp;
  377. struct omap_musb_board_data *data = plat->board_data;
  378. #else
  379. struct omap_musb_board_data *data =
  380. (struct omap_musb_board_data *)musb->controller;
  381. const struct dsps_musb_wrapper *wrp = &ti81xx_driver_data;
  382. #endif
  383. void __iomem *reg_base = musb->ctrl_base;
  384. u32 rev, val;
  385. int status;
  386. /* mentor core register starts at offset of 0x400 from musb base */
  387. musb->mregs += wrp->musb_core_offset;
  388. #ifndef __UBOOT__
  389. /* NOP driver needs change if supporting dual instance */
  390. usb_nop_xceiv_register();
  391. musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
  392. if (IS_ERR_OR_NULL(musb->xceiv))
  393. return -ENODEV;
  394. #endif
  395. /* Returns zero if e.g. not clocked */
  396. rev = dsps_readl(reg_base, wrp->revision);
  397. if (!rev) {
  398. status = -ENODEV;
  399. goto err0;
  400. }
  401. #ifndef __UBOOT__
  402. if (is_host_enabled(musb))
  403. setup_timer(&glue->timer, otg_timer, (unsigned long) musb);
  404. #endif
  405. /* Reset the musb */
  406. dsps_writel(reg_base, wrp->control, (1 << wrp->reset));
  407. /* Start the on-chip PHY and its PLL. */
  408. if (data->set_phy_power)
  409. data->set_phy_power(1);
  410. musb->isr = dsps_interrupt;
  411. /* reset the otgdisable bit, needed for host mode to work */
  412. val = dsps_readl(reg_base, wrp->phy_utmi);
  413. val &= ~(1 << wrp->otg_disable);
  414. dsps_writel(musb->ctrl_base, wrp->phy_utmi, val);
  415. /* clear level interrupt */
  416. dsps_writel(reg_base, wrp->eoi, 0);
  417. return 0;
  418. err0:
  419. #ifndef __UBOOT__
  420. usb_put_phy(musb->xceiv);
  421. usb_nop_xceiv_unregister();
  422. #endif
  423. return status;
  424. }
  425. static int dsps_musb_exit(struct musb *musb)
  426. {
  427. #ifndef __UBOOT__
  428. struct device *dev = musb->controller;
  429. struct musb_hdrc_platform_data *plat = dev->platform_data;
  430. struct omap_musb_board_data *data = plat->board_data;
  431. struct platform_device *pdev = to_platform_device(dev->parent);
  432. struct dsps_glue *glue = platform_get_drvdata(pdev);
  433. #else
  434. struct omap_musb_board_data *data =
  435. (struct omap_musb_board_data *)musb->controller;
  436. #endif
  437. #ifndef __UBOOT__
  438. if (is_host_enabled(musb))
  439. del_timer_sync(&glue->timer);
  440. #endif
  441. /* Shutdown the on-chip PHY and its PLL. */
  442. if (data->set_phy_power)
  443. data->set_phy_power(0);
  444. #ifndef __UBOOT__
  445. /* NOP driver needs change if supporting dual instance */
  446. usb_put_phy(musb->xceiv);
  447. usb_nop_xceiv_unregister();
  448. #endif
  449. return 0;
  450. }
  451. #ifndef __UBOOT__
  452. static struct musb_platform_ops dsps_ops = {
  453. #else
  454. struct musb_platform_ops musb_dsps_ops = {
  455. #endif
  456. .init = dsps_musb_init,
  457. .exit = dsps_musb_exit,
  458. .enable = dsps_musb_enable,
  459. .disable = dsps_musb_disable,
  460. #ifndef __UBOOT__
  461. .try_idle = dsps_musb_try_idle,
  462. #endif
  463. };
  464. #ifndef __UBOOT__
  465. static u64 musb_dmamask = DMA_BIT_MASK(32);
  466. #endif
  467. #ifndef __UBOOT__
  468. static int __devinit dsps_create_musb_pdev(struct dsps_glue *glue, u8 id)
  469. {
  470. struct device *dev = glue->dev;
  471. struct platform_device *pdev = to_platform_device(dev);
  472. struct musb_hdrc_platform_data *pdata = dev->platform_data;
  473. struct platform_device *musb;
  474. struct resource *res;
  475. struct resource resources[2];
  476. char res_name[10];
  477. int ret;
  478. /* get memory resource */
  479. sprintf(res_name, "musb%d", id);
  480. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, res_name);
  481. if (!res) {
  482. dev_err(dev, "%s get mem resource failed\n", res_name);
  483. ret = -ENODEV;
  484. goto err0;
  485. }
  486. res->parent = NULL;
  487. resources[0] = *res;
  488. /* get irq resource */
  489. sprintf(res_name, "musb%d-irq", id);
  490. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, res_name);
  491. if (!res) {
  492. dev_err(dev, "%s get irq resource failed\n", res_name);
  493. ret = -ENODEV;
  494. goto err0;
  495. }
  496. res->parent = NULL;
  497. resources[1] = *res;
  498. resources[1].name = "mc";
  499. /* allocate the child platform device */
  500. musb = platform_device_alloc("musb-hdrc", -1);
  501. if (!musb) {
  502. dev_err(dev, "failed to allocate musb device\n");
  503. ret = -ENOMEM;
  504. goto err0;
  505. }
  506. musb->dev.parent = dev;
  507. musb->dev.dma_mask = &musb_dmamask;
  508. musb->dev.coherent_dma_mask = musb_dmamask;
  509. glue->musb = musb;
  510. pdata->platform_ops = &dsps_ops;
  511. ret = platform_device_add_resources(musb, resources, 2);
  512. if (ret) {
  513. dev_err(dev, "failed to add resources\n");
  514. goto err1;
  515. }
  516. ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
  517. if (ret) {
  518. dev_err(dev, "failed to add platform_data\n");
  519. goto err1;
  520. }
  521. ret = platform_device_add(musb);
  522. if (ret) {
  523. dev_err(dev, "failed to register musb device\n");
  524. goto err1;
  525. }
  526. return 0;
  527. err1:
  528. platform_device_put(musb);
  529. err0:
  530. return ret;
  531. }
  532. static void __devexit dsps_delete_musb_pdev(struct dsps_glue *glue)
  533. {
  534. platform_device_del(glue->musb);
  535. platform_device_put(glue->musb);
  536. }
  537. static int __devinit dsps_probe(struct platform_device *pdev)
  538. {
  539. const struct platform_device_id *id = platform_get_device_id(pdev);
  540. const struct dsps_musb_wrapper *wrp =
  541. (struct dsps_musb_wrapper *)id->driver_data;
  542. struct dsps_glue *glue;
  543. struct resource *iomem;
  544. int ret;
  545. /* allocate glue */
  546. glue = kzalloc(sizeof(*glue), GFP_KERNEL);
  547. if (!glue) {
  548. dev_err(&pdev->dev, "unable to allocate glue memory\n");
  549. ret = -ENOMEM;
  550. goto err0;
  551. }
  552. /* get memory resource */
  553. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  554. if (!iomem) {
  555. dev_err(&pdev->dev, "failed to get usbss mem resourse\n");
  556. ret = -ENODEV;
  557. goto err1;
  558. }
  559. glue->dev = &pdev->dev;
  560. glue->wrp = kmemdup(wrp, sizeof(*wrp), GFP_KERNEL);
  561. if (!glue->wrp) {
  562. dev_err(&pdev->dev, "failed to duplicate wrapper struct memory\n");
  563. ret = -ENOMEM;
  564. goto err1;
  565. }
  566. platform_set_drvdata(pdev, glue);
  567. /* enable the usbss clocks */
  568. pm_runtime_enable(&pdev->dev);
  569. ret = pm_runtime_get_sync(&pdev->dev);
  570. if (ret < 0) {
  571. dev_err(&pdev->dev, "pm_runtime_get_sync FAILED");
  572. goto err2;
  573. }
  574. /* create the child platform device for first instances of musb */
  575. ret = dsps_create_musb_pdev(glue, 0);
  576. if (ret != 0) {
  577. dev_err(&pdev->dev, "failed to create child pdev\n");
  578. goto err3;
  579. }
  580. return 0;
  581. err3:
  582. pm_runtime_put(&pdev->dev);
  583. err2:
  584. pm_runtime_disable(&pdev->dev);
  585. kfree(glue->wrp);
  586. err1:
  587. kfree(glue);
  588. err0:
  589. return ret;
  590. }
  591. static int __devexit dsps_remove(struct platform_device *pdev)
  592. {
  593. struct dsps_glue *glue = platform_get_drvdata(pdev);
  594. /* delete the child platform device */
  595. dsps_delete_musb_pdev(glue);
  596. /* disable usbss clocks */
  597. pm_runtime_put(&pdev->dev);
  598. pm_runtime_disable(&pdev->dev);
  599. kfree(glue->wrp);
  600. kfree(glue);
  601. return 0;
  602. }
  603. #ifdef CONFIG_PM_SLEEP
  604. static int dsps_suspend(struct device *dev)
  605. {
  606. struct musb_hdrc_platform_data *plat = dev->platform_data;
  607. struct omap_musb_board_data *data = plat->board_data;
  608. /* Shutdown the on-chip PHY and its PLL. */
  609. if (data->set_phy_power)
  610. data->set_phy_power(0);
  611. return 0;
  612. }
  613. static int dsps_resume(struct device *dev)
  614. {
  615. struct musb_hdrc_platform_data *plat = dev->platform_data;
  616. struct omap_musb_board_data *data = plat->board_data;
  617. /* Start the on-chip PHY and its PLL. */
  618. if (data->set_phy_power)
  619. data->set_phy_power(1);
  620. return 0;
  621. }
  622. #endif
  623. static SIMPLE_DEV_PM_OPS(dsps_pm_ops, dsps_suspend, dsps_resume);
  624. #endif
  625. #ifndef __UBOOT__
  626. static const struct platform_device_id musb_dsps_id_table[] __devinitconst = {
  627. {
  628. .name = "musb-ti81xx",
  629. .driver_data = (kernel_ulong_t) &ti81xx_driver_data,
  630. },
  631. { }, /* Terminating Entry */
  632. };
  633. MODULE_DEVICE_TABLE(platform, musb_dsps_id_table);
  634. static const struct of_device_id musb_dsps_of_match[] __devinitconst = {
  635. { .compatible = "musb-ti81xx", },
  636. { .compatible = "ti,ti81xx-musb", },
  637. { .compatible = "ti,am335x-musb", },
  638. { },
  639. };
  640. MODULE_DEVICE_TABLE(of, musb_dsps_of_match);
  641. static struct platform_driver dsps_usbss_driver = {
  642. .probe = dsps_probe,
  643. .remove = __devexit_p(dsps_remove),
  644. .driver = {
  645. .name = "musb-dsps",
  646. .pm = &dsps_pm_ops,
  647. .of_match_table = musb_dsps_of_match,
  648. },
  649. .id_table = musb_dsps_id_table,
  650. };
  651. MODULE_DESCRIPTION("TI DSPS MUSB Glue Layer");
  652. MODULE_AUTHOR("Ravi B <ravibabu@ti.com>");
  653. MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>");
  654. MODULE_LICENSE("GPL v2");
  655. static int __init dsps_init(void)
  656. {
  657. return platform_driver_register(&dsps_usbss_driver);
  658. }
  659. subsys_initcall(dsps_init);
  660. static void __exit dsps_exit(void)
  661. {
  662. platform_driver_unregister(&dsps_usbss_driver);
  663. }
  664. module_exit(dsps_exit);
  665. #endif