davinci_usb.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * TI's Davinci platform specific USB wrapper functions.
  3. *
  4. * Copyright (c) 2008 Texas Instruments
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. *
  21. * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments
  22. */
  23. #include <common.h>
  24. #include <asm/io.h>
  25. #include "davinci_usb.h"
  26. /* MUSB platform configuration */
  27. struct musb_config musb_cfg = {
  28. (struct musb_regs *)MENTOR_USB0_BASE,
  29. DAVINCI_USB_TIMEOUT,
  30. 0
  31. };
  32. /* MUSB module register overlay */
  33. struct davinci_usb_regs *dregs;
  34. /*
  35. * Enable the USB phy
  36. */
  37. static u8 phy_on(void)
  38. {
  39. u32 timeout;
  40. /* Wait until the USB phy is turned on */
  41. writel(USBPHY_SESNDEN | USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
  42. timeout = musb_cfg.timeout;
  43. while (timeout--)
  44. if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD)
  45. return 1;
  46. /* USB phy was not turned on */
  47. return 0;
  48. }
  49. /*
  50. * Disable the USB phy
  51. */
  52. static void phy_off(void)
  53. {
  54. /* powerdown the on-chip PHY and its oscillator */
  55. writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR);
  56. }
  57. /*
  58. * This function performs Davinci platform specific initialization for usb0.
  59. */
  60. int musb_platform_init(void)
  61. {
  62. u32 revision;
  63. /* enable USB VBUS */
  64. enable_vbus();
  65. /* start the on-chip USB phy and its pll */
  66. if (!phy_on())
  67. return -1;
  68. /* reset the controller */
  69. dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE;
  70. writel(1, &dregs->ctrlr);
  71. udelay(5000);
  72. /* Returns zero if e.g. not clocked */
  73. revision = readl(&dregs->version);
  74. if (!revision)
  75. return -1;
  76. /* Disable all interrupts */
  77. writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK |
  78. DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr);
  79. return 0;
  80. }
  81. /*
  82. * This function performs Davinci platform specific deinitialization for usb0.
  83. */
  84. void musb_platform_deinit(void)
  85. {
  86. /* Turn of the phy */
  87. phy_off();
  88. /* flush any interrupts */
  89. writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK |
  90. DAVINCI_USB_RXINT_MASK , &dregs->intclrr);
  91. }