da8xx.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * da8xx.c - TI's DA8xx platform specific usb wrapper functions.
  3. *
  4. * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
  5. *
  6. * Based on drivers/usb/musb/davinci.c
  7. *
  8. * Copyright (C) 2009 Texas Instruments Incorporated
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include "musb_core.h"
  14. #include <asm/arch/da8xx-usb.h>
  15. /* MUSB platform configuration */
  16. struct musb_config musb_cfg = {
  17. .regs = (struct musb_regs *)DA8XX_USB_OTG_CORE_BASE,
  18. .timeout = DA8XX_USB_OTG_TIMEOUT,
  19. .musb_speed = 0,
  20. };
  21. /*
  22. * This function enables VBUS by driving the GPIO Bank4 Pin 15 high.
  23. */
  24. static void enable_vbus(void)
  25. {
  26. u32 value;
  27. /* configure GPIO bank4 pin 15 in output direction */
  28. value = readl(&davinci_gpio_bank45->dir);
  29. writel((value & (~DA8XX_USB_VBUS_GPIO)), &davinci_gpio_bank45->dir);
  30. /* set GPIO bank4 pin 15 high to drive VBUS */
  31. value = readl(&davinci_gpio_bank45->set_data);
  32. writel((value | DA8XX_USB_VBUS_GPIO), &davinci_gpio_bank45->set_data);
  33. }
  34. /*
  35. * Enable the usb0 phy. This initialization procedure is explained in
  36. * the DA8xx USB user guide document.
  37. */
  38. static u8 phy_on(void)
  39. {
  40. u32 timeout;
  41. u32 cfgchip2;
  42. cfgchip2 = readl(&davinci_syscfg_regs->cfgchip2);
  43. cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN |
  44. CFGCHIP2_OTGMODE | CFGCHIP2_REFFREQ);
  45. cfgchip2 |= CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN | CFGCHIP2_PHY_PLLON |
  46. CFGCHIP2_REFFREQ_24MHZ;
  47. writel(cfgchip2, &davinci_syscfg_regs->cfgchip2);
  48. /* wait until the usb phy pll locks */
  49. timeout = musb_cfg.timeout;
  50. while (timeout--)
  51. if (readl(&davinci_syscfg_regs->cfgchip2) & CFGCHIP2_PHYCLKGD)
  52. return 1;
  53. /* USB phy was not turned on */
  54. return 0;
  55. }
  56. /*
  57. * Disable the usb phy
  58. */
  59. static void phy_off(void)
  60. {
  61. u32 cfgchip2;
  62. /*
  63. * Power down the on-chip PHY.
  64. */
  65. cfgchip2 = readl(&davinci_syscfg_regs->cfgchip2);
  66. cfgchip2 &= ~CFGCHIP2_PHY_PLLON;
  67. cfgchip2 |= CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN;
  68. writel(cfgchip2, &davinci_syscfg_regs->cfgchip2);
  69. }
  70. /*
  71. * This function performs DA8xx platform specific initialization for usb0.
  72. */
  73. int musb_platform_init(void)
  74. {
  75. u32 revision;
  76. /* enable psc for usb2.0 */
  77. lpsc_on(33);
  78. /* enable usb vbus */
  79. enable_vbus();
  80. /* reset the controller */
  81. writel(0x1, &da8xx_usb_regs->control);
  82. udelay(5000);
  83. /* start the on-chip usb phy and its pll */
  84. if (phy_on() == 0)
  85. return -1;
  86. /* Returns zero if e.g. not clocked */
  87. revision = readl(&da8xx_usb_regs->revision);
  88. if (revision == 0)
  89. return -1;
  90. /* Disable all interrupts */
  91. writel((DA8XX_USB_USBINT_MASK | DA8XX_USB_TXINT_MASK |
  92. DA8XX_USB_RXINT_MASK), &da8xx_usb_regs->intmsk_set);
  93. return 0;
  94. }
  95. /*
  96. * This function performs DA8xx platform specific deinitialization for usb0.
  97. */
  98. void musb_platform_deinit(void)
  99. {
  100. /* Turn of the phy */
  101. phy_off();
  102. /* flush any interrupts */
  103. writel((DA8XX_USB_USBINT_MASK | DA8XX_USB_TXINT_MASK |
  104. DA8XX_USB_RXINT_MASK), &da8xx_usb_regs->intmsk_clr);
  105. writel(0, &da8xx_usb_regs->eoi);
  106. }