da8xx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Texas Instruments DA8xx/OMAP-L1x "glue layer"
  4. *
  5. * Copyright (c) 2008-2009 MontaVista Software, Inc. <source@mvista.com>
  6. *
  7. * Based on the DaVinci "glue layer" code.
  8. * Copyright (C) 2005-2006 by Texas Instruments
  9. *
  10. * DT support
  11. * Copyright (c) 2016 Petr Kulhavy <petr@barix.com>
  12. *
  13. * This file is part of the Inventra Controller Driver for Linux.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/clk.h>
  17. #include <linux/err.h>
  18. #include <linux/io.h>
  19. #include <linux/of_platform.h>
  20. #include <linux/phy/phy.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/usb/usb_phy_generic.h>
  24. #include "musb_core.h"
  25. /*
  26. * DA8XX specific definitions
  27. */
  28. /* USB 2.0 OTG module registers */
  29. #define DA8XX_USB_REVISION_REG 0x00
  30. #define DA8XX_USB_CTRL_REG 0x04
  31. #define DA8XX_USB_STAT_REG 0x08
  32. #define DA8XX_USB_EMULATION_REG 0x0c
  33. #define DA8XX_USB_SRP_FIX_TIME_REG 0x18
  34. #define DA8XX_USB_INTR_SRC_REG 0x20
  35. #define DA8XX_USB_INTR_SRC_SET_REG 0x24
  36. #define DA8XX_USB_INTR_SRC_CLEAR_REG 0x28
  37. #define DA8XX_USB_INTR_MASK_REG 0x2c
  38. #define DA8XX_USB_INTR_MASK_SET_REG 0x30
  39. #define DA8XX_USB_INTR_MASK_CLEAR_REG 0x34
  40. #define DA8XX_USB_INTR_SRC_MASKED_REG 0x38
  41. #define DA8XX_USB_END_OF_INTR_REG 0x3c
  42. #define DA8XX_USB_GENERIC_RNDIS_EP_SIZE_REG(n) (0x50 + (((n) - 1) << 2))
  43. /* Control register bits */
  44. #define DA8XX_SOFT_RESET_MASK 1
  45. #define DA8XX_USB_TX_EP_MASK 0x1f /* EP0 + 4 Tx EPs */
  46. #define DA8XX_USB_RX_EP_MASK 0x1e /* 4 Rx EPs */
  47. /* USB interrupt register bits */
  48. #define DA8XX_INTR_USB_SHIFT 16
  49. #define DA8XX_INTR_USB_MASK (0x1ff << DA8XX_INTR_USB_SHIFT) /* 8 Mentor */
  50. /* interrupts and DRVVBUS interrupt */
  51. #define DA8XX_INTR_DRVVBUS 0x100
  52. #define DA8XX_INTR_RX_SHIFT 8
  53. #define DA8XX_INTR_RX_MASK (DA8XX_USB_RX_EP_MASK << DA8XX_INTR_RX_SHIFT)
  54. #define DA8XX_INTR_TX_SHIFT 0
  55. #define DA8XX_INTR_TX_MASK (DA8XX_USB_TX_EP_MASK << DA8XX_INTR_TX_SHIFT)
  56. #define DA8XX_MENTOR_CORE_OFFSET 0x400
  57. struct da8xx_glue {
  58. struct device *dev;
  59. struct platform_device *musb;
  60. struct platform_device *usb_phy;
  61. struct clk *clk;
  62. struct phy *phy;
  63. };
  64. /*
  65. * Because we don't set CTRL.UINT, it's "important" to:
  66. * - not read/write INTRUSB/INTRUSBE (except during
  67. * initial setup, as a workaround);
  68. * - use INTSET/INTCLR instead.
  69. */
  70. /**
  71. * da8xx_musb_enable - enable interrupts
  72. */
  73. static void da8xx_musb_enable(struct musb *musb)
  74. {
  75. void __iomem *reg_base = musb->ctrl_base;
  76. u32 mask;
  77. /* Workaround: setup IRQs through both register sets. */
  78. mask = ((musb->epmask & DA8XX_USB_TX_EP_MASK) << DA8XX_INTR_TX_SHIFT) |
  79. ((musb->epmask & DA8XX_USB_RX_EP_MASK) << DA8XX_INTR_RX_SHIFT) |
  80. DA8XX_INTR_USB_MASK;
  81. musb_writel(reg_base, DA8XX_USB_INTR_MASK_SET_REG, mask);
  82. /* Force the DRVVBUS IRQ so we can start polling for ID change. */
  83. musb_writel(reg_base, DA8XX_USB_INTR_SRC_SET_REG,
  84. DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT);
  85. }
  86. /**
  87. * da8xx_musb_disable - disable HDRC and flush interrupts
  88. */
  89. static void da8xx_musb_disable(struct musb *musb)
  90. {
  91. void __iomem *reg_base = musb->ctrl_base;
  92. musb_writel(reg_base, DA8XX_USB_INTR_MASK_CLEAR_REG,
  93. DA8XX_INTR_USB_MASK |
  94. DA8XX_INTR_TX_MASK | DA8XX_INTR_RX_MASK);
  95. musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0);
  96. }
  97. #define portstate(stmt) stmt
  98. static void da8xx_musb_set_vbus(struct musb *musb, int is_on)
  99. {
  100. WARN_ON(is_on && is_peripheral_active(musb));
  101. }
  102. #define POLL_SECONDS 2
  103. static void otg_timer(struct timer_list *t)
  104. {
  105. struct musb *musb = from_timer(musb, t, dev_timer);
  106. void __iomem *mregs = musb->mregs;
  107. u8 devctl;
  108. unsigned long flags;
  109. /*
  110. * We poll because DaVinci's won't expose several OTG-critical
  111. * status change events (from the transceiver) otherwise.
  112. */
  113. devctl = musb_readb(mregs, MUSB_DEVCTL);
  114. dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
  115. usb_otg_state_string(musb->xceiv->otg->state));
  116. spin_lock_irqsave(&musb->lock, flags);
  117. switch (musb->xceiv->otg->state) {
  118. case OTG_STATE_A_WAIT_BCON:
  119. devctl &= ~MUSB_DEVCTL_SESSION;
  120. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  121. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  122. if (devctl & MUSB_DEVCTL_BDEVICE) {
  123. musb->xceiv->otg->state = OTG_STATE_B_IDLE;
  124. MUSB_DEV_MODE(musb);
  125. } else {
  126. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  127. MUSB_HST_MODE(musb);
  128. }
  129. break;
  130. case OTG_STATE_A_WAIT_VFALL:
  131. /*
  132. * Wait till VBUS falls below SessionEnd (~0.2 V); the 1.3
  133. * RTL seems to mis-handle session "start" otherwise (or in
  134. * our case "recover"), in routine "VBUS was valid by the time
  135. * VBUSERR got reported during enumeration" cases.
  136. */
  137. if (devctl & MUSB_DEVCTL_VBUS) {
  138. mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
  139. break;
  140. }
  141. musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
  142. musb_writel(musb->ctrl_base, DA8XX_USB_INTR_SRC_SET_REG,
  143. MUSB_INTR_VBUSERROR << DA8XX_INTR_USB_SHIFT);
  144. break;
  145. case OTG_STATE_B_IDLE:
  146. /*
  147. * There's no ID-changed IRQ, so we have no good way to tell
  148. * when to switch to the A-Default state machine (by setting
  149. * the DEVCTL.Session bit).
  150. *
  151. * Workaround: whenever we're in B_IDLE, try setting the
  152. * session flag every few seconds. If it works, ID was
  153. * grounded and we're now in the A-Default state machine.
  154. *
  155. * NOTE: setting the session flag is _supposed_ to trigger
  156. * SRP but clearly it doesn't.
  157. */
  158. musb_writeb(mregs, MUSB_DEVCTL, devctl | MUSB_DEVCTL_SESSION);
  159. devctl = musb_readb(mregs, MUSB_DEVCTL);
  160. if (devctl & MUSB_DEVCTL_BDEVICE)
  161. mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
  162. else
  163. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  164. break;
  165. default:
  166. break;
  167. }
  168. spin_unlock_irqrestore(&musb->lock, flags);
  169. }
  170. static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout)
  171. {
  172. static unsigned long last_timer;
  173. if (timeout == 0)
  174. timeout = jiffies + msecs_to_jiffies(3);
  175. /* Never idle if active, or when VBUS timeout is not set as host */
  176. if (musb->is_active || (musb->a_wait_bcon == 0 &&
  177. musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) {
  178. dev_dbg(musb->controller, "%s active, deleting timer\n",
  179. usb_otg_state_string(musb->xceiv->otg->state));
  180. del_timer(&musb->dev_timer);
  181. last_timer = jiffies;
  182. return;
  183. }
  184. if (time_after(last_timer, timeout) && timer_pending(&musb->dev_timer)) {
  185. dev_dbg(musb->controller, "Longer idle timer already pending, ignoring...\n");
  186. return;
  187. }
  188. last_timer = timeout;
  189. dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
  190. usb_otg_state_string(musb->xceiv->otg->state),
  191. jiffies_to_msecs(timeout - jiffies));
  192. mod_timer(&musb->dev_timer, timeout);
  193. }
  194. static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
  195. {
  196. struct musb *musb = hci;
  197. void __iomem *reg_base = musb->ctrl_base;
  198. struct usb_otg *otg = musb->xceiv->otg;
  199. unsigned long flags;
  200. irqreturn_t ret = IRQ_NONE;
  201. u32 status;
  202. spin_lock_irqsave(&musb->lock, flags);
  203. /*
  204. * NOTE: DA8XX shadows the Mentor IRQs. Don't manage them through
  205. * the Mentor registers (except for setup), use the TI ones and EOI.
  206. */
  207. /* Acknowledge and handle non-CPPI interrupts */
  208. status = musb_readl(reg_base, DA8XX_USB_INTR_SRC_MASKED_REG);
  209. if (!status)
  210. goto eoi;
  211. musb_writel(reg_base, DA8XX_USB_INTR_SRC_CLEAR_REG, status);
  212. dev_dbg(musb->controller, "USB IRQ %08x\n", status);
  213. musb->int_rx = (status & DA8XX_INTR_RX_MASK) >> DA8XX_INTR_RX_SHIFT;
  214. musb->int_tx = (status & DA8XX_INTR_TX_MASK) >> DA8XX_INTR_TX_SHIFT;
  215. musb->int_usb = (status & DA8XX_INTR_USB_MASK) >> DA8XX_INTR_USB_SHIFT;
  216. /*
  217. * DRVVBUS IRQs are the only proxy we have (a very poor one!) for
  218. * DA8xx's missing ID change IRQ. We need an ID change IRQ to
  219. * switch appropriately between halves of the OTG state machine.
  220. * Managing DEVCTL.Session per Mentor docs requires that we know its
  221. * value but DEVCTL.BDevice is invalid without DEVCTL.Session set.
  222. * Also, DRVVBUS pulses for SRP (but not at 5 V)...
  223. */
  224. if (status & (DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT)) {
  225. int drvvbus = musb_readl(reg_base, DA8XX_USB_STAT_REG);
  226. void __iomem *mregs = musb->mregs;
  227. u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
  228. int err;
  229. err = musb->int_usb & MUSB_INTR_VBUSERROR;
  230. if (err) {
  231. /*
  232. * The Mentor core doesn't debounce VBUS as needed
  233. * to cope with device connect current spikes. This
  234. * means it's not uncommon for bus-powered devices
  235. * to get VBUS errors during enumeration.
  236. *
  237. * This is a workaround, but newer RTL from Mentor
  238. * seems to allow a better one: "re"-starting sessions
  239. * without waiting for VBUS to stop registering in
  240. * devctl.
  241. */
  242. musb->int_usb &= ~MUSB_INTR_VBUSERROR;
  243. musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL;
  244. mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
  245. WARNING("VBUS error workaround (delay coming)\n");
  246. } else if (drvvbus) {
  247. MUSB_HST_MODE(musb);
  248. otg->default_a = 1;
  249. musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
  250. portstate(musb->port1_status |= USB_PORT_STAT_POWER);
  251. del_timer(&musb->dev_timer);
  252. } else if (!(musb->int_usb & MUSB_INTR_BABBLE)) {
  253. /*
  254. * When babble condition happens, drvvbus interrupt
  255. * is also generated. Ignore this drvvbus interrupt
  256. * and let babble interrupt handler recovers the
  257. * controller; otherwise, the host-mode flag is lost
  258. * due to the MUSB_DEV_MODE() call below and babble
  259. * recovery logic will not be called.
  260. */
  261. musb->is_active = 0;
  262. MUSB_DEV_MODE(musb);
  263. otg->default_a = 0;
  264. musb->xceiv->otg->state = OTG_STATE_B_IDLE;
  265. portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
  266. }
  267. dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
  268. drvvbus ? "on" : "off",
  269. usb_otg_state_string(musb->xceiv->otg->state),
  270. err ? " ERROR" : "",
  271. devctl);
  272. ret = IRQ_HANDLED;
  273. }
  274. if (musb->int_tx || musb->int_rx || musb->int_usb)
  275. ret |= musb_interrupt(musb);
  276. eoi:
  277. /* EOI needs to be written for the IRQ to be re-asserted. */
  278. if (ret == IRQ_HANDLED || status)
  279. musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0);
  280. /* Poll for ID change */
  281. if (musb->xceiv->otg->state == OTG_STATE_B_IDLE)
  282. mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
  283. spin_unlock_irqrestore(&musb->lock, flags);
  284. return ret;
  285. }
  286. static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode)
  287. {
  288. struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
  289. enum phy_mode phy_mode;
  290. /*
  291. * The PHY has some issues when it is forced in device or host mode.
  292. * Unless the user request another mode, configure the PHY in OTG mode.
  293. */
  294. if (!musb->is_initialized)
  295. return phy_set_mode(glue->phy, PHY_MODE_USB_OTG);
  296. switch (musb_mode) {
  297. case MUSB_HOST: /* Force VBUS valid, ID = 0 */
  298. phy_mode = PHY_MODE_USB_HOST;
  299. break;
  300. case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */
  301. phy_mode = PHY_MODE_USB_DEVICE;
  302. break;
  303. case MUSB_OTG: /* Don't override the VBUS/ID comparators */
  304. phy_mode = PHY_MODE_USB_OTG;
  305. break;
  306. default:
  307. return -EINVAL;
  308. }
  309. return phy_set_mode(glue->phy, phy_mode);
  310. }
  311. static int da8xx_musb_init(struct musb *musb)
  312. {
  313. struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
  314. void __iomem *reg_base = musb->ctrl_base;
  315. u32 rev;
  316. int ret = -ENODEV;
  317. musb->mregs += DA8XX_MENTOR_CORE_OFFSET;
  318. ret = clk_prepare_enable(glue->clk);
  319. if (ret) {
  320. dev_err(glue->dev, "failed to enable clock\n");
  321. return ret;
  322. }
  323. /* Returns zero if e.g. not clocked */
  324. rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG);
  325. if (!rev)
  326. goto fail;
  327. musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
  328. if (IS_ERR_OR_NULL(musb->xceiv)) {
  329. ret = -EPROBE_DEFER;
  330. goto fail;
  331. }
  332. timer_setup(&musb->dev_timer, otg_timer, 0);
  333. /* Reset the controller */
  334. musb_writel(reg_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK);
  335. /* Start the on-chip PHY and its PLL. */
  336. ret = phy_init(glue->phy);
  337. if (ret) {
  338. dev_err(glue->dev, "Failed to init phy.\n");
  339. goto fail;
  340. }
  341. ret = phy_power_on(glue->phy);
  342. if (ret) {
  343. dev_err(glue->dev, "Failed to power on phy.\n");
  344. goto err_phy_power_on;
  345. }
  346. msleep(5);
  347. /* NOTE: IRQs are in mixed mode, not bypass to pure MUSB */
  348. pr_debug("DA8xx OTG revision %08x, control %02x\n", rev,
  349. musb_readb(reg_base, DA8XX_USB_CTRL_REG));
  350. musb->isr = da8xx_musb_interrupt;
  351. return 0;
  352. err_phy_power_on:
  353. phy_exit(glue->phy);
  354. fail:
  355. clk_disable_unprepare(glue->clk);
  356. return ret;
  357. }
  358. static int da8xx_musb_exit(struct musb *musb)
  359. {
  360. struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
  361. del_timer_sync(&musb->dev_timer);
  362. phy_power_off(glue->phy);
  363. phy_exit(glue->phy);
  364. clk_disable_unprepare(glue->clk);
  365. usb_put_phy(musb->xceiv);
  366. return 0;
  367. }
  368. static inline u8 get_vbus_power(struct device *dev)
  369. {
  370. struct regulator *vbus_supply;
  371. int current_uA;
  372. vbus_supply = regulator_get_optional(dev, "vbus");
  373. if (IS_ERR(vbus_supply))
  374. return 255;
  375. current_uA = regulator_get_current_limit(vbus_supply);
  376. regulator_put(vbus_supply);
  377. if (current_uA <= 0 || current_uA > 510000)
  378. return 255;
  379. return current_uA / 1000 / 2;
  380. }
  381. #ifdef CONFIG_USB_TI_CPPI41_DMA
  382. static void da8xx_dma_controller_callback(struct dma_controller *c)
  383. {
  384. struct musb *musb = c->musb;
  385. void __iomem *reg_base = musb->ctrl_base;
  386. musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0);
  387. }
  388. static struct dma_controller *
  389. da8xx_dma_controller_create(struct musb *musb, void __iomem *base)
  390. {
  391. struct dma_controller *controller;
  392. controller = cppi41_dma_controller_create(musb, base);
  393. if (IS_ERR_OR_NULL(controller))
  394. return controller;
  395. controller->dma_callback = da8xx_dma_controller_callback;
  396. return controller;
  397. }
  398. #endif
  399. static const struct musb_platform_ops da8xx_ops = {
  400. .quirks = MUSB_INDEXED_EP | MUSB_PRESERVE_SESSION |
  401. MUSB_DMA_CPPI41 | MUSB_DA8XX,
  402. .init = da8xx_musb_init,
  403. .exit = da8xx_musb_exit,
  404. .fifo_mode = 2,
  405. #ifdef CONFIG_USB_TI_CPPI41_DMA
  406. .dma_init = da8xx_dma_controller_create,
  407. .dma_exit = cppi41_dma_controller_destroy,
  408. #endif
  409. .enable = da8xx_musb_enable,
  410. .disable = da8xx_musb_disable,
  411. .set_mode = da8xx_musb_set_mode,
  412. .try_idle = da8xx_musb_try_idle,
  413. .set_vbus = da8xx_musb_set_vbus,
  414. };
  415. static const struct platform_device_info da8xx_dev_info = {
  416. .name = "musb-hdrc",
  417. .id = PLATFORM_DEVID_AUTO,
  418. .dma_mask = DMA_BIT_MASK(32),
  419. };
  420. static const struct musb_hdrc_config da8xx_config = {
  421. .ram_bits = 10,
  422. .num_eps = 5,
  423. .multipoint = 1,
  424. };
  425. static struct of_dev_auxdata da8xx_auxdata_lookup[] = {
  426. OF_DEV_AUXDATA("ti,da830-cppi41", 0x01e01000, "cppi41-dmaengine",
  427. NULL),
  428. {}
  429. };
  430. static int da8xx_probe(struct platform_device *pdev)
  431. {
  432. struct resource musb_resources[2];
  433. struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
  434. struct da8xx_glue *glue;
  435. struct platform_device_info pinfo;
  436. struct clk *clk;
  437. struct device_node *np = pdev->dev.of_node;
  438. int ret;
  439. glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
  440. if (!glue)
  441. return -ENOMEM;
  442. clk = devm_clk_get(&pdev->dev, NULL);
  443. if (IS_ERR(clk)) {
  444. dev_err(&pdev->dev, "failed to get clock\n");
  445. return PTR_ERR(clk);
  446. }
  447. glue->phy = devm_phy_get(&pdev->dev, "usb-phy");
  448. if (IS_ERR(glue->phy)) {
  449. if (PTR_ERR(glue->phy) != -EPROBE_DEFER)
  450. dev_err(&pdev->dev, "failed to get phy\n");
  451. return PTR_ERR(glue->phy);
  452. }
  453. glue->dev = &pdev->dev;
  454. glue->clk = clk;
  455. if (IS_ENABLED(CONFIG_OF) && np) {
  456. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  457. if (!pdata)
  458. return -ENOMEM;
  459. pdata->config = &da8xx_config;
  460. pdata->mode = musb_get_mode(&pdev->dev);
  461. pdata->power = get_vbus_power(&pdev->dev);
  462. }
  463. pdata->platform_ops = &da8xx_ops;
  464. glue->usb_phy = usb_phy_generic_register();
  465. ret = PTR_ERR_OR_ZERO(glue->usb_phy);
  466. if (ret) {
  467. dev_err(&pdev->dev, "failed to register usb_phy\n");
  468. return ret;
  469. }
  470. platform_set_drvdata(pdev, glue);
  471. ret = of_platform_populate(pdev->dev.of_node, NULL,
  472. da8xx_auxdata_lookup, &pdev->dev);
  473. if (ret)
  474. return ret;
  475. memset(musb_resources, 0x00, sizeof(*musb_resources) *
  476. ARRAY_SIZE(musb_resources));
  477. musb_resources[0].name = pdev->resource[0].name;
  478. musb_resources[0].start = pdev->resource[0].start;
  479. musb_resources[0].end = pdev->resource[0].end;
  480. musb_resources[0].flags = pdev->resource[0].flags;
  481. musb_resources[1].name = pdev->resource[1].name;
  482. musb_resources[1].start = pdev->resource[1].start;
  483. musb_resources[1].end = pdev->resource[1].end;
  484. musb_resources[1].flags = pdev->resource[1].flags;
  485. pinfo = da8xx_dev_info;
  486. pinfo.parent = &pdev->dev;
  487. pinfo.res = musb_resources;
  488. pinfo.num_res = ARRAY_SIZE(musb_resources);
  489. pinfo.data = pdata;
  490. pinfo.size_data = sizeof(*pdata);
  491. glue->musb = platform_device_register_full(&pinfo);
  492. ret = PTR_ERR_OR_ZERO(glue->musb);
  493. if (ret) {
  494. dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
  495. usb_phy_generic_unregister(glue->usb_phy);
  496. }
  497. return ret;
  498. }
  499. static int da8xx_remove(struct platform_device *pdev)
  500. {
  501. struct da8xx_glue *glue = platform_get_drvdata(pdev);
  502. platform_device_unregister(glue->musb);
  503. usb_phy_generic_unregister(glue->usb_phy);
  504. return 0;
  505. }
  506. #ifdef CONFIG_PM_SLEEP
  507. static int da8xx_suspend(struct device *dev)
  508. {
  509. int ret;
  510. struct da8xx_glue *glue = dev_get_drvdata(dev);
  511. ret = phy_power_off(glue->phy);
  512. if (ret)
  513. return ret;
  514. clk_disable_unprepare(glue->clk);
  515. return 0;
  516. }
  517. static int da8xx_resume(struct device *dev)
  518. {
  519. int ret;
  520. struct da8xx_glue *glue = dev_get_drvdata(dev);
  521. ret = clk_prepare_enable(glue->clk);
  522. if (ret)
  523. return ret;
  524. return phy_power_on(glue->phy);
  525. }
  526. #endif
  527. static SIMPLE_DEV_PM_OPS(da8xx_pm_ops, da8xx_suspend, da8xx_resume);
  528. #ifdef CONFIG_OF
  529. static const struct of_device_id da8xx_id_table[] = {
  530. {
  531. .compatible = "ti,da830-musb",
  532. },
  533. {},
  534. };
  535. MODULE_DEVICE_TABLE(of, da8xx_id_table);
  536. #endif
  537. static struct platform_driver da8xx_driver = {
  538. .probe = da8xx_probe,
  539. .remove = da8xx_remove,
  540. .driver = {
  541. .name = "musb-da8xx",
  542. .pm = &da8xx_pm_ops,
  543. .of_match_table = of_match_ptr(da8xx_id_table),
  544. },
  545. };
  546. MODULE_DESCRIPTION("DA8xx/OMAP-L1x MUSB Glue Layer");
  547. MODULE_AUTHOR("Sergei Shtylyov <sshtylyov@ru.mvista.com>");
  548. MODULE_LICENSE("GPL v2");
  549. module_platform_driver(da8xx_driver);