davinci.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.h"
  26. #include <asm/arch/hardware.h>
  27. #if !defined(CONFIG_DV_USBPHY_CTL)
  28. #define CONFIG_DV_USBPHY_CTL (USBPHY_SESNDEN | USBPHY_VBDTCTEN)
  29. #endif
  30. /* MUSB platform configuration */
  31. struct musb_config musb_cfg = {
  32. .regs = (struct musb_regs *)MENTOR_USB0_BASE,
  33. .timeout = DAVINCI_USB_TIMEOUT,
  34. .musb_speed = 0,
  35. };
  36. /* MUSB module register overlay */
  37. struct davinci_usb_regs *dregs;
  38. /*
  39. * Enable the USB phy
  40. */
  41. static u8 phy_on(void)
  42. {
  43. u32 timeout;
  44. #ifdef DAVINCI_DM365EVM
  45. u32 val;
  46. #endif
  47. /* Wait until the USB phy is turned on */
  48. #ifdef DAVINCI_DM365EVM
  49. writel(USBPHY_PHY24MHZ | USBPHY_SESNDEN |
  50. USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
  51. #else
  52. writel(CONFIG_DV_USBPHY_CTL, USBPHY_CTL_PADDR);
  53. #endif
  54. timeout = musb_cfg.timeout;
  55. #ifdef DAVINCI_DM365EVM
  56. /* Set the ownership of GIO33 to USB */
  57. val = readl(PINMUX4);
  58. val &= ~(PINMUX4_USBDRVBUS_BITCLEAR);
  59. val |= PINMUX4_USBDRVBUS_BITSET;
  60. writel(val, PINMUX4);
  61. #endif
  62. while (timeout--)
  63. if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD)
  64. return 1;
  65. /* USB phy was not turned on */
  66. return 0;
  67. }
  68. /*
  69. * Disable the USB phy
  70. */
  71. static void phy_off(void)
  72. {
  73. /* powerdown the on-chip PHY and its oscillator */
  74. writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR);
  75. }
  76. void __enable_vbus(void)
  77. {
  78. /*
  79. * nothing to do, vbus is handled through the cpu.
  80. * Define this function in board code, if it is
  81. * different on your board.
  82. */
  83. }
  84. void enable_vbus(void)
  85. __attribute__((weak, alias("__enable_vbus")));
  86. /*
  87. * This function performs Davinci platform specific initialization for usb0.
  88. */
  89. int musb_platform_init(void)
  90. {
  91. u32 revision;
  92. /* enable USB VBUS */
  93. enable_vbus();
  94. /* start the on-chip USB phy and its pll */
  95. if (!phy_on())
  96. return -1;
  97. /* reset the controller */
  98. dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE;
  99. writel(1, &dregs->ctrlr);
  100. udelay(5000);
  101. /* Returns zero if e.g. not clocked */
  102. revision = readl(&dregs->version);
  103. if (!revision)
  104. return -1;
  105. /* Disable all interrupts */
  106. writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK |
  107. DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr);
  108. return 0;
  109. }
  110. /*
  111. * This function performs Davinci platform specific deinitialization for usb0.
  112. */
  113. void musb_platform_deinit(void)
  114. {
  115. /* Turn of the phy */
  116. phy_off();
  117. /* flush any interrupts */
  118. writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK |
  119. DAVINCI_USB_RXINT_MASK , &dregs->intclrr);
  120. }