da8xx.c 17 KB

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