musb_dsps.c 19 KB

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