am35x.c 17 KB

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