da8xx.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #include <common.h>
  25. #include "da8xx.h"
  26. /* MUSB platform configuration */
  27. struct musb_config musb_cfg = {
  28. .regs = (struct musb_regs *)DA8XX_USB_OTG_CORE_BASE,
  29. .timeout = DA8XX_USB_OTG_TIMEOUT,
  30. .musb_speed = 0,
  31. };
  32. /*
  33. * This function enables VBUS by driving the GPIO Bank4 Pin 15 high.
  34. */
  35. static void enable_vbus(void)
  36. {
  37. u32 value;
  38. /* configure GPIO bank4 pin 15 in output direction */
  39. value = readl(&davinci_gpio_bank45->dir);
  40. writel((value & (~DA8XX_USB_VBUS_GPIO)), &davinci_gpio_bank45->dir);
  41. /* set GPIO bank4 pin 15 high to drive VBUS */
  42. value = readl(&davinci_gpio_bank45->set_data);
  43. writel((value | DA8XX_USB_VBUS_GPIO), &davinci_gpio_bank45->set_data);
  44. }
  45. /*
  46. * Enable the usb0 phy. This initialization procedure is explained in
  47. * the DA8xx USB user guide document.
  48. */
  49. static u8 phy_on(void)
  50. {
  51. u32 timeout;
  52. u32 cfgchip2;
  53. cfgchip2 = readl(&davinci_syscfg_regs->cfgchip2);
  54. cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN |
  55. CFGCHIP2_OTGMODE | CFGCHIP2_REFFREQ);
  56. cfgchip2 |= CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN | CFGCHIP2_PHY_PLLON |
  57. CFGCHIP2_REFFREQ_24MHZ;
  58. writel(cfgchip2, &davinci_syscfg_regs->cfgchip2);
  59. /* wait until the usb phy pll locks */
  60. timeout = musb_cfg.timeout;
  61. while (timeout--)
  62. if (readl(&davinci_syscfg_regs->cfgchip2) & CFGCHIP2_PHYCLKGD)
  63. return 1;
  64. /* USB phy was not turned on */
  65. return 0;
  66. }
  67. /*
  68. * Disable the usb phy
  69. */
  70. static void phy_off(void)
  71. {
  72. u32 cfgchip2;
  73. /*
  74. * Power down the on-chip PHY.
  75. */
  76. cfgchip2 = readl(&davinci_syscfg_regs->cfgchip2);
  77. cfgchip2 &= ~CFGCHIP2_PHY_PLLON;
  78. cfgchip2 |= CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN;
  79. writel(cfgchip2, &davinci_syscfg_regs->cfgchip2);
  80. }
  81. /*
  82. * This function performs DA8xx platform specific initialization for usb0.
  83. */
  84. int musb_platform_init(void)
  85. {
  86. u32 revision;
  87. /* enable psc for usb2.0 */
  88. lpsc_on(33);
  89. /* enable usb vbus */
  90. enable_vbus();
  91. /* reset the controller */
  92. writel(0x1, &da8xx_usb_regs->control);
  93. udelay(5000);
  94. /* start the on-chip usb phy and its pll */
  95. if (phy_on() == 0)
  96. return -1;
  97. /* Returns zero if e.g. not clocked */
  98. revision = readl(&da8xx_usb_regs->revision);
  99. if (revision == 0)
  100. return -1;
  101. /* Disable all interrupts */
  102. writel((DA8XX_USB_USBINT_MASK | DA8XX_USB_TXINT_MASK |
  103. DA8XX_USB_RXINT_MASK), &da8xx_usb_regs->intmsk_set);
  104. return 0;
  105. }
  106. /*
  107. * This function performs DA8xx platform specific deinitialization for usb0.
  108. */
  109. void musb_platform_deinit(void)
  110. {
  111. /* Turn of the phy */
  112. phy_off();
  113. /* flush any interrupts */
  114. writel((DA8XX_USB_USBINT_MASK | DA8XX_USB_TXINT_MASK |
  115. DA8XX_USB_RXINT_MASK), &da8xx_usb_regs->intmsk_clr);
  116. writel(0, &da8xx_usb_regs->eoi);
  117. }