am35x.c 17 KB

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