am35x.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * Texas Instruments AM35x "glue layer"
  3. *
  4. * Copyright (c) 2010, by Texas Instruments
  5. *
  6. * Based on the DA8xx "glue layer" code.
  7. * Copyright (c) 2008-2009, MontaVista Software, Inc. <source@mvista.com>
  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 <plat/control.h>
  34. #include <plat/usb.h>
  35. #include "musb_core.h"
  36. /*
  37. * AM35x specific definitions
  38. */
  39. /* USB 2.0 OTG module registers */
  40. #define USB_REVISION_REG 0x00
  41. #define USB_CTRL_REG 0x04
  42. #define USB_STAT_REG 0x08
  43. #define USB_EMULATION_REG 0x0c
  44. /* 0x10 Reserved */
  45. #define USB_AUTOREQ_REG 0x14
  46. #define USB_SRP_FIX_TIME_REG 0x18
  47. #define USB_TEARDOWN_REG 0x1c
  48. #define EP_INTR_SRC_REG 0x20
  49. #define EP_INTR_SRC_SET_REG 0x24
  50. #define EP_INTR_SRC_CLEAR_REG 0x28
  51. #define EP_INTR_MASK_REG 0x2c
  52. #define EP_INTR_MASK_SET_REG 0x30
  53. #define EP_INTR_MASK_CLEAR_REG 0x34
  54. #define EP_INTR_SRC_MASKED_REG 0x38
  55. #define CORE_INTR_SRC_REG 0x40
  56. #define CORE_INTR_SRC_SET_REG 0x44
  57. #define CORE_INTR_SRC_CLEAR_REG 0x48
  58. #define CORE_INTR_MASK_REG 0x4c
  59. #define CORE_INTR_MASK_SET_REG 0x50
  60. #define CORE_INTR_MASK_CLEAR_REG 0x54
  61. #define CORE_INTR_SRC_MASKED_REG 0x58
  62. /* 0x5c Reserved */
  63. #define USB_END_OF_INTR_REG 0x60
  64. /* Control register bits */
  65. #define AM35X_SOFT_RESET_MASK 1
  66. /* USB interrupt register bits */
  67. #define AM35X_INTR_USB_SHIFT 16
  68. #define AM35X_INTR_USB_MASK (0x1ff << AM35X_INTR_USB_SHIFT)
  69. #define AM35X_INTR_DRVVBUS 0x100
  70. #define AM35X_INTR_RX_SHIFT 16
  71. #define AM35X_INTR_TX_SHIFT 0
  72. #define AM35X_TX_EP_MASK 0xffff /* EP0 + 15 Tx EPs */
  73. #define AM35X_RX_EP_MASK 0xfffe /* 15 Rx EPs */
  74. #define AM35X_TX_INTR_MASK (AM35X_TX_EP_MASK << AM35X_INTR_TX_SHIFT)
  75. #define AM35X_RX_INTR_MASK (AM35X_RX_EP_MASK << AM35X_INTR_RX_SHIFT)
  76. #define USB_MENTOR_CORE_OFFSET 0x400
  77. static inline void phy_on(void)
  78. {
  79. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  80. u32 devconf2;
  81. /*
  82. * Start the on-chip PHY and its PLL.
  83. */
  84. devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  85. devconf2 &= ~(CONF2_RESET | CONF2_PHYPWRDN | CONF2_OTGPWRDN);
  86. devconf2 |= CONF2_PHY_PLLON;
  87. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  88. DBG(1, "Waiting for PHY clock good...\n");
  89. while (!(omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2)
  90. & CONF2_PHYCLKGD)) {
  91. cpu_relax();
  92. if (time_after(jiffies, timeout)) {
  93. DBG(1, "musb PHY clock good timed out\n");
  94. break;
  95. }
  96. }
  97. }
  98. static inline void phy_off(void)
  99. {
  100. u32 devconf2;
  101. /*
  102. * Power down the on-chip PHY.
  103. */
  104. devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  105. devconf2 &= ~CONF2_PHY_PLLON;
  106. devconf2 |= CONF2_PHYPWRDN | CONF2_OTGPWRDN;
  107. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  108. }
  109. /*
  110. * am35x_musb_enable - enable interrupts
  111. */
  112. static void am35x_musb_enable(struct musb *musb)
  113. {
  114. void __iomem *reg_base = musb->ctrl_base;
  115. u32 epmask;
  116. /* Workaround: setup IRQs through both register sets. */
  117. epmask = ((musb->epmask & AM35X_TX_EP_MASK) << AM35X_INTR_TX_SHIFT) |
  118. ((musb->epmask & AM35X_RX_EP_MASK) << AM35X_INTR_RX_SHIFT);
  119. musb_writel(reg_base, EP_INTR_MASK_SET_REG, epmask);
  120. musb_writel(reg_base, CORE_INTR_MASK_SET_REG, AM35X_INTR_USB_MASK);
  121. /* Force the DRVVBUS IRQ so we can start polling for ID change. */
  122. if (is_otg_enabled(musb))
  123. musb_writel(reg_base, CORE_INTR_SRC_SET_REG,
  124. AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT);
  125. }
  126. /*
  127. * am35x_musb_disable - disable HDRC and flush interrupts
  128. */
  129. static void am35x_musb_disable(struct musb *musb)
  130. {
  131. void __iomem *reg_base = musb->ctrl_base;
  132. musb_writel(reg_base, CORE_INTR_MASK_CLEAR_REG, AM35X_INTR_USB_MASK);
  133. musb_writel(reg_base, EP_INTR_MASK_CLEAR_REG,
  134. AM35X_TX_INTR_MASK | AM35X_RX_INTR_MASK);
  135. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  136. musb_writel(reg_base, USB_END_OF_INTR_REG, 0);
  137. }
  138. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  139. #define portstate(stmt) stmt
  140. #else
  141. #define portstate(stmt)
  142. #endif
  143. static void am35x_musb_set_vbus(struct musb *musb, int is_on)
  144. {
  145. WARN_ON(is_on && is_peripheral_active(musb));
  146. }
  147. #define POLL_SECONDS 2
  148. static struct timer_list otg_workaround;
  149. static void otg_timer(unsigned long _musb)
  150. {
  151. struct musb *musb = (void *)_musb;
  152. void __iomem *mregs = musb->mregs;
  153. u8 devctl;
  154. unsigned long flags;
  155. /*
  156. * We poll because AM35x's won't expose several OTG-critical
  157. * status change events (from the transceiver) otherwise.
  158. */
  159. devctl = musb_readb(mregs, MUSB_DEVCTL);
  160. DBG(7, "Poll devctl %02x (%s)\n", devctl, otg_state_string(musb));
  161. spin_lock_irqsave(&musb->lock, flags);
  162. switch (musb->xceiv->state) {
  163. case OTG_STATE_A_WAIT_BCON:
  164. devctl &= ~MUSB_DEVCTL_SESSION;
  165. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  166. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  167. if (devctl & MUSB_DEVCTL_BDEVICE) {
  168. musb->xceiv->state = OTG_STATE_B_IDLE;
  169. MUSB_DEV_MODE(musb);
  170. } else {
  171. musb->xceiv->state = OTG_STATE_A_IDLE;
  172. MUSB_HST_MODE(musb);
  173. }
  174. break;
  175. case OTG_STATE_A_WAIT_VFALL:
  176. musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
  177. musb_writel(musb->ctrl_base, CORE_INTR_SRC_SET_REG,
  178. MUSB_INTR_VBUSERROR << AM35X_INTR_USB_SHIFT);
  179. break;
  180. case OTG_STATE_B_IDLE:
  181. if (!is_peripheral_enabled(musb))
  182. break;
  183. devctl = musb_readb(mregs, MUSB_DEVCTL);
  184. if (devctl & MUSB_DEVCTL_BDEVICE)
  185. mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
  186. else
  187. musb->xceiv->state = OTG_STATE_A_IDLE;
  188. break;
  189. default:
  190. break;
  191. }
  192. spin_unlock_irqrestore(&musb->lock, flags);
  193. }
  194. static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
  195. {
  196. static unsigned long last_timer;
  197. if (!is_otg_enabled(musb))
  198. return;
  199. if (timeout == 0)
  200. timeout = jiffies + msecs_to_jiffies(3);
  201. /* Never idle if active, or when VBUS timeout is not set as host */
  202. if (musb->is_active || (musb->a_wait_bcon == 0 &&
  203. musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
  204. DBG(4, "%s active, deleting timer\n", otg_state_string(musb));
  205. del_timer(&otg_workaround);
  206. last_timer = jiffies;
  207. return;
  208. }
  209. if (time_after(last_timer, timeout) && timer_pending(&otg_workaround)) {
  210. DBG(4, "Longer idle timer already pending, ignoring...\n");
  211. return;
  212. }
  213. last_timer = timeout;
  214. DBG(4, "%s inactive, starting idle timer for %u ms\n",
  215. otg_state_string(musb), jiffies_to_msecs(timeout - jiffies));
  216. mod_timer(&otg_workaround, timeout);
  217. }
  218. static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
  219. {
  220. struct musb *musb = hci;
  221. void __iomem *reg_base = musb->ctrl_base;
  222. unsigned long flags;
  223. irqreturn_t ret = IRQ_NONE;
  224. u32 epintr, usbintr, lvl_intr;
  225. spin_lock_irqsave(&musb->lock, flags);
  226. /* Get endpoint interrupts */
  227. epintr = musb_readl(reg_base, EP_INTR_SRC_MASKED_REG);
  228. if (epintr) {
  229. musb_writel(reg_base, EP_INTR_SRC_CLEAR_REG, epintr);
  230. musb->int_rx =
  231. (epintr & AM35X_RX_INTR_MASK) >> AM35X_INTR_RX_SHIFT;
  232. musb->int_tx =
  233. (epintr & AM35X_TX_INTR_MASK) >> AM35X_INTR_TX_SHIFT;
  234. }
  235. /* Get usb core interrupts */
  236. usbintr = musb_readl(reg_base, CORE_INTR_SRC_MASKED_REG);
  237. if (!usbintr && !epintr)
  238. goto eoi;
  239. if (usbintr) {
  240. musb_writel(reg_base, CORE_INTR_SRC_CLEAR_REG, usbintr);
  241. musb->int_usb =
  242. (usbintr & AM35X_INTR_USB_MASK) >> AM35X_INTR_USB_SHIFT;
  243. }
  244. /*
  245. * DRVVBUS IRQs are the only proxy we have (a very poor one!) for
  246. * AM35x's missing ID change IRQ. We need an ID change IRQ to
  247. * switch appropriately between halves of the OTG state machine.
  248. * Managing DEVCTL.SESSION per Mentor docs requires that we know its
  249. * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
  250. * Also, DRVVBUS pulses for SRP (but not at 5V) ...
  251. */
  252. if (usbintr & (AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT)) {
  253. int drvvbus = musb_readl(reg_base, USB_STAT_REG);
  254. void __iomem *mregs = musb->mregs;
  255. u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
  256. int err;
  257. err = is_host_enabled(musb) && (musb->int_usb &
  258. MUSB_INTR_VBUSERROR);
  259. if (err) {
  260. /*
  261. * The Mentor core doesn't debounce VBUS as needed
  262. * to cope with device connect current spikes. This
  263. * means it's not uncommon for bus-powered devices
  264. * to get VBUS errors during enumeration.
  265. *
  266. * This is a workaround, but newer RTL from Mentor
  267. * seems to allow a better one: "re"-starting sessions
  268. * without waiting for VBUS to stop registering in
  269. * devctl.
  270. */
  271. musb->int_usb &= ~MUSB_INTR_VBUSERROR;
  272. musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
  273. mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
  274. WARNING("VBUS error workaround (delay coming)\n");
  275. } else if (is_host_enabled(musb) && drvvbus) {
  276. MUSB_HST_MODE(musb);
  277. musb->xceiv->default_a = 1;
  278. musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
  279. portstate(musb->port1_status |= USB_PORT_STAT_POWER);
  280. del_timer(&otg_workaround);
  281. } else {
  282. musb->is_active = 0;
  283. MUSB_DEV_MODE(musb);
  284. musb->xceiv->default_a = 0;
  285. musb->xceiv->state = OTG_STATE_B_IDLE;
  286. portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
  287. }
  288. /* NOTE: this must complete power-on within 100 ms. */
  289. DBG(2, "VBUS %s (%s)%s, devctl %02x\n",
  290. drvvbus ? "on" : "off",
  291. otg_state_string(musb),
  292. err ? " ERROR" : "",
  293. devctl);
  294. ret = IRQ_HANDLED;
  295. }
  296. if (musb->int_tx || musb->int_rx || musb->int_usb)
  297. ret |= musb_interrupt(musb);
  298. eoi:
  299. /* EOI needs to be written for the IRQ to be re-asserted. */
  300. if (ret == IRQ_HANDLED || epintr || usbintr) {
  301. /* clear level interrupt */
  302. lvl_intr = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  303. lvl_intr |= AM35XX_USBOTGSS_INT_CLR;
  304. omap_ctrl_writel(lvl_intr, AM35XX_CONTROL_LVL_INTR_CLEAR);
  305. /* write EOI */
  306. musb_writel(reg_base, USB_END_OF_INTR_REG, 0);
  307. }
  308. /* Poll for ID change */
  309. if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE)
  310. mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
  311. spin_unlock_irqrestore(&musb->lock, flags);
  312. return ret;
  313. }
  314. static int am35x_musb_set_mode(struct musb *musb, u8 musb_mode)
  315. {
  316. u32 devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  317. devconf2 &= ~CONF2_OTGMODE;
  318. switch (musb_mode) {
  319. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  320. case MUSB_HOST: /* Force VBUS valid, ID = 0 */
  321. devconf2 |= CONF2_FORCE_HOST;
  322. break;
  323. #endif
  324. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  325. case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */
  326. devconf2 |= CONF2_FORCE_DEVICE;
  327. break;
  328. #endif
  329. #ifdef CONFIG_USB_MUSB_OTG
  330. case MUSB_OTG: /* Don't override the VBUS/ID comparators */
  331. devconf2 |= CONF2_NO_OVERRIDE;
  332. break;
  333. #endif
  334. default:
  335. DBG(2, "Trying to set unsupported mode %u\n", musb_mode);
  336. }
  337. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  338. return 0;
  339. }
  340. static int am35x_musb_init(struct musb *musb)
  341. {
  342. void __iomem *reg_base = musb->ctrl_base;
  343. u32 rev, lvl_intr, sw_reset;
  344. int status;
  345. musb->mregs += USB_MENTOR_CORE_OFFSET;
  346. clk_enable(musb->clock);
  347. DBG(2, "musb->clock=%lud\n", clk_get_rate(musb->clock));
  348. musb->phy_clock = clk_get(musb->controller, "fck");
  349. if (IS_ERR(musb->phy_clock)) {
  350. status = PTR_ERR(musb->phy_clock);
  351. goto exit0;
  352. }
  353. clk_enable(musb->phy_clock);
  354. DBG(2, "musb->phy_clock=%lud\n", clk_get_rate(musb->phy_clock));
  355. /* Returns zero if e.g. not clocked */
  356. rev = musb_readl(reg_base, USB_REVISION_REG);
  357. if (!rev) {
  358. status = -ENODEV;
  359. goto exit1;
  360. }
  361. usb_nop_xceiv_register();
  362. musb->xceiv = otg_get_transceiver();
  363. if (!musb->xceiv) {
  364. status = -ENODEV;
  365. goto exit1;
  366. }
  367. if (is_host_enabled(musb))
  368. setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
  369. musb->board_set_vbus = am35x_musb_set_vbus;
  370. /* Global reset */
  371. sw_reset = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  372. sw_reset |= AM35XX_USBOTGSS_SW_RST;
  373. omap_ctrl_writel(sw_reset, AM35XX_CONTROL_IP_SW_RESET);
  374. sw_reset &= ~AM35XX_USBOTGSS_SW_RST;
  375. omap_ctrl_writel(sw_reset, AM35XX_CONTROL_IP_SW_RESET);
  376. /* Reset the controller */
  377. musb_writel(reg_base, USB_CTRL_REG, AM35X_SOFT_RESET_MASK);
  378. /* Start the on-chip PHY and its PLL. */
  379. phy_on();
  380. msleep(5);
  381. musb->isr = am35x_musb_interrupt;
  382. /* clear level interrupt */
  383. lvl_intr = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  384. lvl_intr |= AM35XX_USBOTGSS_INT_CLR;
  385. omap_ctrl_writel(lvl_intr, AM35XX_CONTROL_LVL_INTR_CLEAR);
  386. return 0;
  387. exit1:
  388. clk_disable(musb->phy_clock);
  389. clk_put(musb->phy_clock);
  390. exit0:
  391. clk_disable(musb->clock);
  392. return status;
  393. }
  394. static int am35x_musb_exit(struct musb *musb)
  395. {
  396. if (is_host_enabled(musb))
  397. del_timer_sync(&otg_workaround);
  398. phy_off();
  399. otg_put_transceiver(musb->xceiv);
  400. usb_nop_xceiv_unregister();
  401. clk_disable(musb->clock);
  402. clk_disable(musb->phy_clock);
  403. clk_put(musb->phy_clock);
  404. return 0;
  405. }
  406. #ifdef CONFIG_PM
  407. void musb_platform_save_context(struct musb *musb,
  408. struct musb_context_registers *musb_context)
  409. {
  410. phy_off();
  411. }
  412. void musb_platform_restore_context(struct musb *musb,
  413. struct musb_context_registers *musb_context)
  414. {
  415. phy_on();
  416. }
  417. #endif
  418. /* AM35x supports only 32bit read operation */
  419. void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
  420. {
  421. void __iomem *fifo = hw_ep->fifo;
  422. u32 val;
  423. int i;
  424. /* Read for 32bit-aligned destination address */
  425. if (likely((0x03 & (unsigned long) dst) == 0) && len >= 4) {
  426. readsl(fifo, dst, len >> 2);
  427. dst += len & ~0x03;
  428. len &= 0x03;
  429. }
  430. /*
  431. * Now read the remaining 1 to 3 byte or complete length if
  432. * unaligned address.
  433. */
  434. if (len > 4) {
  435. for (i = 0; i < (len >> 2); i++) {
  436. *(u32 *) dst = musb_readl(fifo, 0);
  437. dst += 4;
  438. }
  439. len &= 0x03;
  440. }
  441. if (len > 0) {
  442. val = musb_readl(fifo, 0);
  443. memcpy(dst, &val, len);
  444. }
  445. }
  446. const struct musb_platform_ops musb_ops = {
  447. .init = am35x_musb_init,
  448. .exit = am35x_musb_exit,
  449. .enable = am35x_musb_enable,
  450. .disable = am35x_musb_disable,
  451. .set_mode = am35x_musb_set_mode,
  452. .try_idle = am35x_musb_try_idle,
  453. .set_vbus = am35x_musb_set_vbus,
  454. };
  455. static u64 am35x_dmamask = DMA_BIT_MASK(32);
  456. static int __init am35x_probe(struct platform_device *pdev)
  457. {
  458. struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
  459. struct platform_device *musb;
  460. int ret = -ENOMEM;
  461. musb = platform_device_alloc("musb-hdrc", -1);
  462. if (!musb) {
  463. dev_err(&pdev->dev, "failed to allocate musb device\n");
  464. goto err0;
  465. }
  466. musb->dev.parent = &pdev->dev;
  467. musb->dev.dma_mask = &am35x_dmamask;
  468. musb->dev.coherent_dma_mask = am35x_dmamask;
  469. platform_set_drvdata(pdev, musb);
  470. ret = platform_device_add_resources(musb, pdev->resource,
  471. pdev->num_resources);
  472. if (ret) {
  473. dev_err(&pdev->dev, "failed to add resources\n");
  474. goto err1;
  475. }
  476. ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
  477. if (ret) {
  478. dev_err(&pdev->dev, "failed to add platform_data\n");
  479. goto err1;
  480. }
  481. ret = platform_device_add(musb);
  482. if (ret) {
  483. dev_err(&pdev->dev, "failed to register musb device\n");
  484. goto err1;
  485. }
  486. return 0;
  487. err1:
  488. platform_device_put(musb);
  489. err0:
  490. return ret;
  491. }
  492. static int __exit am35x_remove(struct platform_device *pdev)
  493. {
  494. struct platform_device *musb = platform_get_drvdata(pdev);
  495. platform_device_del(musb);
  496. platform_device_put(musb);
  497. return 0;
  498. }
  499. static struct platform_driver am35x_driver = {
  500. .remove = __exit_p(am35x_remove),
  501. .driver = {
  502. .name = "musb-am35x",
  503. },
  504. };
  505. MODULE_DESCRIPTION("AM35x MUSB Glue Layer");
  506. MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>");
  507. MODULE_LICENSE("GPL v2");
  508. static int __init am35x_init(void)
  509. {
  510. return platform_driver_probe(&am35x_driver, am35x_probe);
  511. }
  512. subsys_initcall(am35x_init);
  513. static void __exit am35x_exit(void)
  514. {
  515. platform_driver_unregister(&am35x_driver);
  516. }
  517. module_exit(am35x_exit);