am35x.c 17 KB

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