da8xx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0);
  115. }
  116. #define portstate(stmt) stmt
  117. static void da8xx_musb_set_vbus(struct musb *musb, int is_on)
  118. {
  119. WARN_ON(is_on && is_peripheral_active(musb));
  120. }
  121. #define POLL_SECONDS 2
  122. static struct timer_list otg_workaround;
  123. static void otg_timer(unsigned long _musb)
  124. {
  125. struct musb *musb = (void *)_musb;
  126. void __iomem *mregs = musb->mregs;
  127. u8 devctl;
  128. unsigned long flags;
  129. /*
  130. * We poll because DaVinci's won't expose several OTG-critical
  131. * status change events (from the transceiver) otherwise.
  132. */
  133. devctl = musb_readb(mregs, MUSB_DEVCTL);
  134. dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
  135. usb_otg_state_string(musb->xceiv->otg->state));
  136. spin_lock_irqsave(&musb->lock, flags);
  137. switch (musb->xceiv->otg->state) {
  138. case OTG_STATE_A_WAIT_BCON:
  139. devctl &= ~MUSB_DEVCTL_SESSION;
  140. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  141. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  142. if (devctl & MUSB_DEVCTL_BDEVICE) {
  143. musb->xceiv->otg->state = OTG_STATE_B_IDLE;
  144. MUSB_DEV_MODE(musb);
  145. } else {
  146. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  147. MUSB_HST_MODE(musb);
  148. }
  149. break;
  150. case OTG_STATE_A_WAIT_VFALL:
  151. /*
  152. * Wait till VBUS falls below SessionEnd (~0.2 V); the 1.3
  153. * RTL seems to mis-handle session "start" otherwise (or in
  154. * our case "recover"), in routine "VBUS was valid by the time
  155. * VBUSERR got reported during enumeration" cases.
  156. */
  157. if (devctl & MUSB_DEVCTL_VBUS) {
  158. mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
  159. break;
  160. }
  161. musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
  162. musb_writel(musb->ctrl_base, DA8XX_USB_INTR_SRC_SET_REG,
  163. MUSB_INTR_VBUSERROR << DA8XX_INTR_USB_SHIFT);
  164. break;
  165. case OTG_STATE_B_IDLE:
  166. /*
  167. * There's no ID-changed IRQ, so we have no good way to tell
  168. * when to switch to the A-Default state machine (by setting
  169. * the DEVCTL.Session bit).
  170. *
  171. * Workaround: whenever we're in B_IDLE, try setting the
  172. * session flag every few seconds. If it works, ID was
  173. * grounded and we're now in the A-Default state machine.
  174. *
  175. * NOTE: setting the session flag is _supposed_ to trigger
  176. * SRP but clearly it doesn't.
  177. */
  178. musb_writeb(mregs, MUSB_DEVCTL, devctl | MUSB_DEVCTL_SESSION);
  179. devctl = musb_readb(mregs, MUSB_DEVCTL);
  180. if (devctl & MUSB_DEVCTL_BDEVICE)
  181. mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
  182. else
  183. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  184. break;
  185. default:
  186. break;
  187. }
  188. spin_unlock_irqrestore(&musb->lock, flags);
  189. }
  190. static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout)
  191. {
  192. static unsigned long last_timer;
  193. if (timeout == 0)
  194. timeout = jiffies + msecs_to_jiffies(3);
  195. /* Never idle if active, or when VBUS timeout is not set as host */
  196. if (musb->is_active || (musb->a_wait_bcon == 0 &&
  197. musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) {
  198. dev_dbg(musb->controller, "%s active, deleting timer\n",
  199. usb_otg_state_string(musb->xceiv->otg->state));
  200. del_timer(&otg_workaround);
  201. last_timer = jiffies;
  202. return;
  203. }
  204. if (time_after(last_timer, timeout) && timer_pending(&otg_workaround)) {
  205. dev_dbg(musb->controller, "Longer idle timer already pending, ignoring...\n");
  206. return;
  207. }
  208. last_timer = timeout;
  209. dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
  210. usb_otg_state_string(musb->xceiv->otg->state),
  211. jiffies_to_msecs(timeout - jiffies));
  212. mod_timer(&otg_workaround, timeout);
  213. }
  214. static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
  215. {
  216. struct musb *musb = hci;
  217. void __iomem *reg_base = musb->ctrl_base;
  218. struct usb_otg *otg = musb->xceiv->otg;
  219. unsigned long flags;
  220. irqreturn_t ret = IRQ_NONE;
  221. u32 status;
  222. spin_lock_irqsave(&musb->lock, flags);
  223. /*
  224. * NOTE: DA8XX shadows the Mentor IRQs. Don't manage them through
  225. * the Mentor registers (except for setup), use the TI ones and EOI.
  226. */
  227. /* Acknowledge and handle non-CPPI interrupts */
  228. status = musb_readl(reg_base, DA8XX_USB_INTR_SRC_MASKED_REG);
  229. if (!status)
  230. goto eoi;
  231. musb_writel(reg_base, DA8XX_USB_INTR_SRC_CLEAR_REG, status);
  232. dev_dbg(musb->controller, "USB IRQ %08x\n", status);
  233. musb->int_rx = (status & DA8XX_INTR_RX_MASK) >> DA8XX_INTR_RX_SHIFT;
  234. musb->int_tx = (status & DA8XX_INTR_TX_MASK) >> DA8XX_INTR_TX_SHIFT;
  235. musb->int_usb = (status & DA8XX_INTR_USB_MASK) >> DA8XX_INTR_USB_SHIFT;
  236. /*
  237. * DRVVBUS IRQs are the only proxy we have (a very poor one!) for
  238. * DA8xx's missing ID change IRQ. We need an ID change IRQ to
  239. * switch appropriately between halves of the OTG state machine.
  240. * Managing DEVCTL.Session per Mentor docs requires that we know its
  241. * value but DEVCTL.BDevice is invalid without DEVCTL.Session set.
  242. * Also, DRVVBUS pulses for SRP (but not at 5 V)...
  243. */
  244. if (status & (DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT)) {
  245. int drvvbus = musb_readl(reg_base, DA8XX_USB_STAT_REG);
  246. void __iomem *mregs = musb->mregs;
  247. u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
  248. int err;
  249. err = musb->int_usb & MUSB_INTR_VBUSERROR;
  250. if (err) {
  251. /*
  252. * The Mentor core doesn't debounce VBUS as needed
  253. * to cope with device connect current spikes. This
  254. * means it's not uncommon for bus-powered devices
  255. * to get VBUS errors during enumeration.
  256. *
  257. * This is a workaround, but newer RTL from Mentor
  258. * seems to allow a better one: "re"-starting sessions
  259. * without waiting for VBUS to stop registering in
  260. * devctl.
  261. */
  262. musb->int_usb &= ~MUSB_INTR_VBUSERROR;
  263. musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL;
  264. mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
  265. WARNING("VBUS error workaround (delay coming)\n");
  266. } else if (drvvbus) {
  267. MUSB_HST_MODE(musb);
  268. otg->default_a = 1;
  269. musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
  270. portstate(musb->port1_status |= USB_PORT_STAT_POWER);
  271. del_timer(&otg_workaround);
  272. } else {
  273. musb->is_active = 0;
  274. MUSB_DEV_MODE(musb);
  275. otg->default_a = 0;
  276. musb->xceiv->otg->state = OTG_STATE_B_IDLE;
  277. portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
  278. }
  279. dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
  280. drvvbus ? "on" : "off",
  281. usb_otg_state_string(musb->xceiv->otg->state),
  282. err ? " ERROR" : "",
  283. devctl);
  284. ret = IRQ_HANDLED;
  285. }
  286. if (musb->int_tx || musb->int_rx || musb->int_usb)
  287. ret |= musb_interrupt(musb);
  288. eoi:
  289. /* EOI needs to be written for the IRQ to be re-asserted. */
  290. if (ret == IRQ_HANDLED || status)
  291. musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0);
  292. /* Poll for ID change */
  293. if (musb->xceiv->otg->state == OTG_STATE_B_IDLE)
  294. mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
  295. spin_unlock_irqrestore(&musb->lock, flags);
  296. return ret;
  297. }
  298. static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode)
  299. {
  300. struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
  301. enum phy_mode phy_mode;
  302. /*
  303. * The PHY has some issues when it is forced in device or host mode.
  304. * Unless the user request another mode, configure the PHY in OTG mode.
  305. */
  306. if (!musb->is_initialized)
  307. return phy_set_mode(glue->phy, PHY_MODE_USB_OTG);
  308. switch (musb_mode) {
  309. case MUSB_HOST: /* Force VBUS valid, ID = 0 */
  310. phy_mode = PHY_MODE_USB_HOST;
  311. break;
  312. case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */
  313. phy_mode = PHY_MODE_USB_DEVICE;
  314. break;
  315. case MUSB_OTG: /* Don't override the VBUS/ID comparators */
  316. phy_mode = PHY_MODE_USB_OTG;
  317. break;
  318. default:
  319. return -EINVAL;
  320. }
  321. return phy_set_mode(glue->phy, phy_mode);
  322. }
  323. static int da8xx_musb_init(struct musb *musb)
  324. {
  325. struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
  326. void __iomem *reg_base = musb->ctrl_base;
  327. u32 rev;
  328. int ret = -ENODEV;
  329. musb->mregs += DA8XX_MENTOR_CORE_OFFSET;
  330. ret = clk_prepare_enable(glue->clk);
  331. if (ret) {
  332. dev_err(glue->dev, "failed to enable clock\n");
  333. return ret;
  334. }
  335. /* Returns zero if e.g. not clocked */
  336. rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG);
  337. if (!rev)
  338. goto fail;
  339. musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
  340. if (IS_ERR_OR_NULL(musb->xceiv)) {
  341. ret = -EPROBE_DEFER;
  342. goto fail;
  343. }
  344. setup_timer(&otg_workaround, otg_timer, (unsigned long)musb);
  345. /* Reset the controller */
  346. musb_writel(reg_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK);
  347. /* Start the on-chip PHY and its PLL. */
  348. ret = phy_init(glue->phy);
  349. if (ret) {
  350. dev_err(glue->dev, "Failed to init phy.\n");
  351. goto fail;
  352. }
  353. ret = phy_power_on(glue->phy);
  354. if (ret) {
  355. dev_err(glue->dev, "Failed to power on phy.\n");
  356. goto err_phy_power_on;
  357. }
  358. msleep(5);
  359. /* NOTE: IRQs are in mixed mode, not bypass to pure MUSB */
  360. pr_debug("DA8xx OTG revision %08x, control %02x\n", rev,
  361. musb_readb(reg_base, DA8XX_USB_CTRL_REG));
  362. musb->isr = da8xx_musb_interrupt;
  363. return 0;
  364. err_phy_power_on:
  365. phy_exit(glue->phy);
  366. fail:
  367. clk_disable_unprepare(glue->clk);
  368. return ret;
  369. }
  370. static int da8xx_musb_exit(struct musb *musb)
  371. {
  372. struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
  373. del_timer_sync(&otg_workaround);
  374. phy_power_off(glue->phy);
  375. phy_exit(glue->phy);
  376. clk_disable_unprepare(glue->clk);
  377. usb_put_phy(musb->xceiv);
  378. return 0;
  379. }
  380. static inline u8 get_vbus_power(struct device *dev)
  381. {
  382. struct regulator *vbus_supply;
  383. int current_uA;
  384. vbus_supply = regulator_get_optional(dev, "vbus");
  385. if (IS_ERR(vbus_supply))
  386. return 255;
  387. current_uA = regulator_get_current_limit(vbus_supply);
  388. regulator_put(vbus_supply);
  389. if (current_uA <= 0 || current_uA > 510000)
  390. return 255;
  391. return current_uA / 1000 / 2;
  392. }
  393. #ifdef CONFIG_USB_TI_CPPI41_DMA
  394. static void da8xx_dma_controller_callback(struct dma_controller *c)
  395. {
  396. struct musb *musb = c->musb;
  397. void __iomem *reg_base = musb->ctrl_base;
  398. musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0);
  399. }
  400. static struct dma_controller *
  401. da8xx_dma_controller_create(struct musb *musb, void __iomem *base)
  402. {
  403. struct dma_controller *controller;
  404. controller = cppi41_dma_controller_create(musb, base);
  405. if (IS_ERR_OR_NULL(controller))
  406. return controller;
  407. controller->dma_callback = da8xx_dma_controller_callback;
  408. return controller;
  409. }
  410. #endif
  411. static const struct musb_platform_ops da8xx_ops = {
  412. .quirks = MUSB_INDEXED_EP | MUSB_PRESERVE_SESSION |
  413. MUSB_DMA_CPPI41 | MUSB_DA8XX,
  414. .init = da8xx_musb_init,
  415. .exit = da8xx_musb_exit,
  416. .fifo_mode = 2,
  417. #ifdef CONFIG_USB_TI_CPPI41_DMA
  418. .dma_init = da8xx_dma_controller_create,
  419. .dma_exit = cppi41_dma_controller_destroy,
  420. #endif
  421. .enable = da8xx_musb_enable,
  422. .disable = da8xx_musb_disable,
  423. .set_mode = da8xx_musb_set_mode,
  424. .try_idle = da8xx_musb_try_idle,
  425. .set_vbus = da8xx_musb_set_vbus,
  426. };
  427. static const struct platform_device_info da8xx_dev_info = {
  428. .name = "musb-hdrc",
  429. .id = PLATFORM_DEVID_AUTO,
  430. .dma_mask = DMA_BIT_MASK(32),
  431. };
  432. static const struct musb_hdrc_config da8xx_config = {
  433. .ram_bits = 10,
  434. .num_eps = 5,
  435. .multipoint = 1,
  436. };
  437. static struct of_dev_auxdata da8xx_auxdata_lookup[] = {
  438. OF_DEV_AUXDATA("ti,da830-cppi41", 0x01e01000, "cppi41-dmaengine",
  439. NULL),
  440. {}
  441. };
  442. static int da8xx_probe(struct platform_device *pdev)
  443. {
  444. struct resource musb_resources[2];
  445. struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
  446. struct da8xx_glue *glue;
  447. struct platform_device_info pinfo;
  448. struct clk *clk;
  449. struct device_node *np = pdev->dev.of_node;
  450. int ret;
  451. glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
  452. if (!glue)
  453. return -ENOMEM;
  454. clk = devm_clk_get(&pdev->dev, "usb20");
  455. if (IS_ERR(clk)) {
  456. dev_err(&pdev->dev, "failed to get clock\n");
  457. return PTR_ERR(clk);
  458. }
  459. glue->phy = devm_phy_get(&pdev->dev, "usb-phy");
  460. if (IS_ERR(glue->phy)) {
  461. if (PTR_ERR(glue->phy) != -EPROBE_DEFER)
  462. dev_err(&pdev->dev, "failed to get phy\n");
  463. return PTR_ERR(glue->phy);
  464. }
  465. glue->dev = &pdev->dev;
  466. glue->clk = clk;
  467. if (IS_ENABLED(CONFIG_OF) && np) {
  468. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  469. if (!pdata)
  470. return -ENOMEM;
  471. pdata->config = &da8xx_config;
  472. pdata->mode = musb_get_mode(&pdev->dev);
  473. pdata->power = get_vbus_power(&pdev->dev);
  474. }
  475. pdata->platform_ops = &da8xx_ops;
  476. glue->usb_phy = usb_phy_generic_register();
  477. ret = PTR_ERR_OR_ZERO(glue->usb_phy);
  478. if (ret) {
  479. dev_err(&pdev->dev, "failed to register usb_phy\n");
  480. return ret;
  481. }
  482. platform_set_drvdata(pdev, glue);
  483. ret = of_platform_populate(pdev->dev.of_node, NULL,
  484. da8xx_auxdata_lookup, &pdev->dev);
  485. if (ret)
  486. return ret;
  487. memset(musb_resources, 0x00, sizeof(*musb_resources) *
  488. ARRAY_SIZE(musb_resources));
  489. musb_resources[0].name = pdev->resource[0].name;
  490. musb_resources[0].start = pdev->resource[0].start;
  491. musb_resources[0].end = pdev->resource[0].end;
  492. musb_resources[0].flags = pdev->resource[0].flags;
  493. musb_resources[1].name = pdev->resource[1].name;
  494. musb_resources[1].start = pdev->resource[1].start;
  495. musb_resources[1].end = pdev->resource[1].end;
  496. musb_resources[1].flags = pdev->resource[1].flags;
  497. pinfo = da8xx_dev_info;
  498. pinfo.parent = &pdev->dev;
  499. pinfo.res = musb_resources;
  500. pinfo.num_res = ARRAY_SIZE(musb_resources);
  501. pinfo.data = pdata;
  502. pinfo.size_data = sizeof(*pdata);
  503. glue->musb = platform_device_register_full(&pinfo);
  504. ret = PTR_ERR_OR_ZERO(glue->musb);
  505. if (ret) {
  506. dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
  507. usb_phy_generic_unregister(glue->usb_phy);
  508. }
  509. return ret;
  510. }
  511. static int da8xx_remove(struct platform_device *pdev)
  512. {
  513. struct da8xx_glue *glue = platform_get_drvdata(pdev);
  514. platform_device_unregister(glue->musb);
  515. usb_phy_generic_unregister(glue->usb_phy);
  516. return 0;
  517. }
  518. #ifdef CONFIG_PM_SLEEP
  519. static int da8xx_suspend(struct device *dev)
  520. {
  521. int ret;
  522. struct da8xx_glue *glue = dev_get_drvdata(dev);
  523. ret = phy_power_off(glue->phy);
  524. if (ret)
  525. return ret;
  526. clk_disable_unprepare(glue->clk);
  527. return 0;
  528. }
  529. static int da8xx_resume(struct device *dev)
  530. {
  531. int ret;
  532. struct da8xx_glue *glue = dev_get_drvdata(dev);
  533. ret = clk_prepare_enable(glue->clk);
  534. if (ret)
  535. return ret;
  536. return phy_power_on(glue->phy);
  537. }
  538. #endif
  539. static SIMPLE_DEV_PM_OPS(da8xx_pm_ops, da8xx_suspend, da8xx_resume);
  540. #ifdef CONFIG_OF
  541. static const struct of_device_id da8xx_id_table[] = {
  542. {
  543. .compatible = "ti,da830-musb",
  544. },
  545. {},
  546. };
  547. MODULE_DEVICE_TABLE(of, da8xx_id_table);
  548. #endif
  549. static struct platform_driver da8xx_driver = {
  550. .probe = da8xx_probe,
  551. .remove = da8xx_remove,
  552. .driver = {
  553. .name = "musb-da8xx",
  554. .pm = &da8xx_pm_ops,
  555. .of_match_table = of_match_ptr(da8xx_id_table),
  556. },
  557. };
  558. MODULE_DESCRIPTION("DA8xx/OMAP-L1x MUSB Glue Layer");
  559. MODULE_AUTHOR("Sergei Shtylyov <sshtylyov@ru.mvista.com>");
  560. MODULE_LICENSE("GPL v2");
  561. module_platform_driver(da8xx_driver);