musb_dsps.c 20 KB

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