am35x.c 2.9 KB

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