am35x.c 16 KB

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