musb_dsps.c 21 KB

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