am35x.c 3.0 KB

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