davinci.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * TI's Davinci platform specific USB wrapper functions.
  3. *
  4. * Copyright (c) 2008 Texas Instruments
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. *
  8. * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments
  9. */
  10. #include <common.h>
  11. #include <asm/io.h>
  12. #include "davinci.h"
  13. #include <asm/arch/hardware.h>
  14. #if !defined(CONFIG_DV_USBPHY_CTL)
  15. #define CONFIG_DV_USBPHY_CTL (USBPHY_SESNDEN | USBPHY_VBDTCTEN)
  16. #endif
  17. /* MUSB platform configuration */
  18. struct musb_config musb_cfg = {
  19. .regs = (struct musb_regs *)MENTOR_USB0_BASE,
  20. .timeout = DAVINCI_USB_TIMEOUT,
  21. .musb_speed = 0,
  22. };
  23. /* MUSB module register overlay */
  24. struct davinci_usb_regs *dregs;
  25. /*
  26. * Enable the USB phy
  27. */
  28. static u8 phy_on(void)
  29. {
  30. u32 timeout;
  31. #ifdef DAVINCI_DM365EVM
  32. u32 val;
  33. #endif
  34. /* Wait until the USB phy is turned on */
  35. #ifdef DAVINCI_DM365EVM
  36. writel(USBPHY_PHY24MHZ | USBPHY_SESNDEN |
  37. USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
  38. #else
  39. writel(CONFIG_DV_USBPHY_CTL, USBPHY_CTL_PADDR);
  40. #endif
  41. timeout = musb_cfg.timeout;
  42. #ifdef DAVINCI_DM365EVM
  43. /* Set the ownership of GIO33 to USB */
  44. val = readl(PINMUX4);
  45. val &= ~(PINMUX4_USBDRVBUS_BITCLEAR);
  46. val |= PINMUX4_USBDRVBUS_BITSET;
  47. writel(val, PINMUX4);
  48. #endif
  49. while (timeout--)
  50. if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD)
  51. return 1;
  52. /* USB phy was not turned on */
  53. return 0;
  54. }
  55. /*
  56. * Disable the USB phy
  57. */
  58. static void phy_off(void)
  59. {
  60. /* powerdown the on-chip PHY and its oscillator */
  61. writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR);
  62. }
  63. void __enable_vbus(void)
  64. {
  65. /*
  66. * nothing to do, vbus is handled through the cpu.
  67. * Define this function in board code, if it is
  68. * different on your board.
  69. */
  70. }
  71. void enable_vbus(void)
  72. __attribute__((weak, alias("__enable_vbus")));
  73. /*
  74. * This function performs Davinci platform specific initialization for usb0.
  75. */
  76. int musb_platform_init(void)
  77. {
  78. u32 revision;
  79. /* enable USB VBUS */
  80. enable_vbus();
  81. /* start the on-chip USB phy and its pll */
  82. if (!phy_on())
  83. return -1;
  84. /* reset the controller */
  85. dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE;
  86. writel(1, &dregs->ctrlr);
  87. udelay(5000);
  88. /* Returns zero if e.g. not clocked */
  89. revision = readl(&dregs->version);
  90. if (!revision)
  91. return -1;
  92. /* Disable all interrupts */
  93. writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK |
  94. DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr);
  95. return 0;
  96. }
  97. /*
  98. * This function performs Davinci platform specific deinitialization for usb0.
  99. */
  100. void musb_platform_deinit(void)
  101. {
  102. /* Turn of the phy */
  103. phy_off();
  104. /* flush any interrupts */
  105. writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK |
  106. DAVINCI_USB_RXINT_MASK , &dregs->intclrr);
  107. }