musb_dsps.c 18 KB

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