da8xx.c 17 KB

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