davinci.c 2.6 KB

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