musb_dsps.c 21 KB

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