da8xx.c 18 KB

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