da8xx.c 16 KB

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