am35x.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * am35x.c - TI's AM35x platform specific usb wrapper functions.
  3. *
  4. * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
  5. *
  6. * Based on drivers/usb/musb/da8xx.c
  7. *
  8. * Copyright (c) 2010 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 "am35x.h"
  26. /* MUSB platform configuration */
  27. struct musb_config musb_cfg = {
  28. .regs = (struct musb_regs *)AM35X_USB_OTG_CORE_BASE,
  29. .timeout = AM35X_USB_OTG_TIMEOUT,
  30. .musb_speed = 0,
  31. };
  32. /*
  33. * Enable the USB phy
  34. */
  35. static u8 phy_on(void)
  36. {
  37. u32 devconf2;
  38. u32 timeout;
  39. devconf2 = readl(&am35x_scm_general_regs->devconf2);
  40. devconf2 &= ~(DEVCONF2_RESET | DEVCONF2_PHYPWRDN | DEVCONF2_OTGPWRDN |
  41. DEVCONF2_OTGMODE | DEVCONF2_REFFREQ |
  42. DEVCONF2_PHY_GPIOMODE);
  43. devconf2 |= DEVCONF2_SESENDEN | DEVCONF2_VBDTCTEN | DEVCONF2_PHY_PLLON |
  44. DEVCONF2_REFFREQ_13MHZ | DEVCONF2_DATPOL;
  45. writel(devconf2, &am35x_scm_general_regs->devconf2);
  46. /* wait until the USB phy is turned on */
  47. timeout = musb_cfg.timeout;
  48. while (timeout--)
  49. if (readl(&am35x_scm_general_regs->devconf2) & DEVCONF2_PHYCKGD)
  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. u32 devconf2;
  60. /*
  61. * Power down the on-chip PHY.
  62. */
  63. devconf2 = readl(&am35x_scm_general_regs->devconf2);
  64. devconf2 &= ~DEVCONF2_PHY_PLLON;
  65. devconf2 |= DEVCONF2_PHYPWRDN | DEVCONF2_OTGPWRDN;
  66. writel(devconf2, &am35x_scm_general_regs->devconf2);
  67. }
  68. /*
  69. * This function performs platform specific initialization for usb0.
  70. */
  71. int musb_platform_init(void)
  72. {
  73. u32 revision;
  74. u32 sw_reset;
  75. /* global usb reset */
  76. sw_reset = readl(&am35x_scm_general_regs->ip_sw_reset);
  77. sw_reset |= (1 << 0);
  78. writel(sw_reset, &am35x_scm_general_regs->ip_sw_reset);
  79. sw_reset &= ~(1 << 0);
  80. writel(sw_reset, &am35x_scm_general_regs->ip_sw_reset);
  81. /* reset the controller */
  82. writel(0x1, &am35x_usb_regs->control);
  83. udelay(5000);
  84. /* start the on-chip usb phy and its pll */
  85. if (phy_on() == 0)
  86. return -1;
  87. /* Returns zero if e.g. not clocked */
  88. revision = readl(&am35x_usb_regs->revision);
  89. if (revision == 0)
  90. return -1;
  91. return 0;
  92. }
  93. /*
  94. * This function performs platform specific deinitialization for usb0.
  95. */
  96. void musb_platform_deinit(void)
  97. {
  98. /* Turn off the phy */
  99. phy_off();
  100. }
  101. /*
  102. * This function reads data from endpoint fifo for AM35x
  103. * which supports only 32bit read operation.
  104. *
  105. * ep - endpoint number
  106. * length - number of bytes to read from FIFO
  107. * fifo_data - pointer to data buffer into which data is read
  108. */
  109. __attribute__((weak))
  110. void read_fifo(u8 ep, u32 length, void *fifo_data)
  111. {
  112. u8 *data = (u8 *)fifo_data;
  113. u32 val;
  114. int i;
  115. /* select the endpoint index */
  116. writeb(ep, &musbr->index);
  117. if (length > 4) {
  118. for (i = 0; i < (length >> 2); i++) {
  119. val = readl(&musbr->fifox[ep]);
  120. memcpy(data, &val, 4);
  121. data += 4;
  122. }
  123. length %= 4;
  124. }
  125. if (length > 0) {
  126. val = readl(&musbr->fifox[ep]);
  127. memcpy(data, &val, length);
  128. }
  129. }