mt_usbphy_d60802.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright (c) 2012 MediaTek Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <debug.h>
  24. #include <reg.h>
  25. #include <platform/bitops.h>
  26. #include <platform/mt_reg_base.h>
  27. #include <platform/mt_typedefs.h>
  28. #include <platform/timer.h>
  29. #include <mt_ssusb_sifslv_ippc.h>
  30. #include <mt_ssusb.h>
  31. #include <mt_ssusbphy.h>
  32. #include <mt_usbphy_d60802.h>
  33. #include <mt_ssusb_usb3_mac_csr.h>
  34. #ifdef MACH_FPGA
  35. #define CFG_FPGA_PLATFORM (1)
  36. #else
  37. #define DBG_PHY_CALIBRATION 1
  38. #endif
  39. #ifdef DBG_USB_PHY
  40. #define PHY_LOG(x...) dprintf(INFO, "[USB][PHY] " x)
  41. #else
  42. #define PHY_LOG(x...) do{} while(0)
  43. #endif
  44. #define PHY_DRV_SHIFT 3
  45. #define PHY_PHASE_SHIFT 3
  46. #define PHY_PHASE_DRV_SHIFT 1
  47. #if CFG_FPGA_PLATFORM
  48. u32 u2_slew_rate_calibration_d60802(struct u3phy_info *info)
  49. {
  50. u32 i = 0;
  51. u32 ret = 0;
  52. u32 u4fmout = 0;
  53. u32 u4tmp = 0;
  54. #ifdef DBG_USB_PHY
  55. volatile u32 chkvalue;
  56. #endif
  57. PHY_LOG("[USBPHY] %s starts\n", __func__);
  58. /* => RG_USB20_HSTX_SRCAL_EN = 1 */
  59. /* enable HS TX SR calibration */
  60. u3_phy_write_field32(((u32)&info->u2phy_regs_d->usbphyacr5),
  61. D60802_RG_USB20_HSTX_SRCAL_EN_OFST, D60802_RG_USB20_HSTX_SRCAL_EN, 1);
  62. mdelay(1);
  63. #ifdef DBG_USB_PHY
  64. chkvalue = u3_phy_read_reg32(((u32)&info->u2phy_regs_d->usbphyacr5));
  65. PHY_LOG("chkvalue: %d\n", chkvalue);
  66. #endif
  67. /* => RG_FRCK_EN = 1 */
  68. /* Enable free run clock */
  69. u3_phy_write_field32(((u32)&info->sifslv_fm_regs_d->fmmonr1),
  70. D60802_RG_FRCK_EN_OFST, D60802_RG_FRCK_EN, 0x1);
  71. /* => RG_CYCLECNT = 4 */
  72. /* Setting cyclecnt = 4 */
  73. u3_phy_write_field32(((u32)&info->sifslv_fm_regs_d->fmcr0),
  74. D60802_RG_CYCLECNT_OFST, D60802_RG_CYCLECNT, 0x4);
  75. /* => RG_FREQDET_EN = 1 */
  76. /* Enable frequency meter */
  77. u3_phy_write_field32(((u32)&info->sifslv_fm_regs_d->fmcr0),
  78. D60802_RG_FREQDET_EN_OFST, D60802_RG_FREQDET_EN, 0x1);
  79. /* wait for FM detection done, set 10ms timeout */
  80. for (i = 0; i < 10; i++) {
  81. /* => u4fmout = USB_FM_OUT */
  82. /* read FM_OUT */
  83. u4fmout = u3_phy_read_reg32(((u32)&info->sifslv_fm_regs_d->fmmonr0));
  84. PHY_LOG("FM_OUT value: u4fmout = %d(0x%08X)\n", u4fmout, u4fmout);
  85. /* check if FM detection done */
  86. if (u4fmout != 0) {
  87. ret = 0;
  88. PHY_LOG("FM detection done! loop = %d\n", i);
  89. break;
  90. }
  91. ret = 1;
  92. mdelay(1);
  93. }
  94. /* => RG_FREQDET_EN = 0 */
  95. /* disable frequency meter */
  96. u3_phy_write_field32(((u32)&info->sifslv_fm_regs_d->fmcr0),
  97. D60802_RG_FREQDET_EN_OFST, D60802_RG_FREQDET_EN, 0);
  98. /* => RG_FRCK_EN = 0 */
  99. /* disable free run clock */
  100. u3_phy_write_field32(((u32)&info->sifslv_fm_regs_d->fmmonr1),
  101. D60802_RG_FRCK_EN_OFST, D60802_RG_FRCK_EN, 0);
  102. /* => RG_USB20_HSTX_SRCAL_EN = 0 */
  103. /* disable HS TX SR calibration */
  104. u3_phy_write_field32(((u32)&info->u2phy_regs_d->usbphyacr0),
  105. D60802_RG_USB20_HSTX_SRCAL_EN_OFST, D60802_RG_USB20_HSTX_SRCAL_EN, 0);
  106. mdelay(1);
  107. if (u4fmout == 0) {
  108. u3_phy_write_field32(((u32)&info->u2phy_regs_d->usbphyacr5),
  109. D60802_RG_USB20_HSTX_SRCTRL_OFST, D60802_RG_USB20_HSTX_SRCTRL, 0x4);
  110. ret = 1;
  111. } else {
  112. /* set reg = (1024/FM_OUT) * 25 * 0.028 (round to the nearest digits) */
  113. u4tmp = (((1024 * 25 * U2_SR_COEF_D60802) / u4fmout) + 500) / 1000;
  114. PHY_LOG("SR calibration value u1SrCalVal = %d\n", (u8)u4tmp);
  115. u3_phy_write_field32(((u32)&info->u2phy_regs_d->usbphyacr5),
  116. D60802_RG_USB20_HSTX_SRCTRL_OFST, D60802_RG_USB20_HSTX_SRCTRL, u4tmp);
  117. }
  118. PHY_LOG("[USBPHY] %s ends\n", __func__);
  119. return ret;
  120. }
  121. int phy_change_pipe_phase_d60802(struct u3phy_info *info, int phy_drv, int pipe_phase)
  122. {
  123. int drv_reg_value;
  124. int phase_reg_value;
  125. int temp;
  126. drv_reg_value = phy_drv << PHY_DRV_SHIFT;
  127. phase_reg_value = (pipe_phase << PHY_PHASE_SHIFT) | (phy_drv << PHY_PHASE_DRV_SHIFT);
  128. temp = u3_phy_read_reg8(((u32)&info->sifslv_chip_regs_d->gpio_ctla)+2);
  129. temp &= ~(0x3 << PHY_DRV_SHIFT);
  130. temp |= drv_reg_value;
  131. u3_phy_write_reg8(((u32)&info->sifslv_chip_regs_d->gpio_ctla)+2, temp);
  132. temp = u3_phy_read_reg8(((u32)&info->sifslv_chip_regs_d->gpio_ctla)+3);
  133. temp &= ~((0x3 << PHY_PHASE_DRV_SHIFT) | (0x1f << PHY_PHASE_SHIFT));
  134. temp |= phase_reg_value;
  135. u3_phy_write_reg8(((u32)&info->sifslv_chip_regs_d->gpio_ctla)+3, temp);
  136. return TRUE;
  137. }
  138. void phy_init_d60802(struct u3phy_info *info)
  139. {
  140. //char temp;
  141. //volatile u32 chkvalue = 0;
  142. /* u2phy part */
  143. /* manual set U2 slew rate ctrl = 4 */
  144. u3_phy_write_field32(((u32)&info->u2phy_regs_d->usbphyacr5),
  145. D60802_RG_USB20_HSTX_SRCTRL_OFST, D60802_RG_USB20_HSTX_SRCTRL, 0x4);
  146. /* fine tune SQTH to gain margin in U2 Rx sensitivity compliance test */
  147. u3_phy_write_field32(((u32)&info->u2phy_regs_d->usbphyacr6),
  148. D60802_RG_USB20_SQTH_OFST, D60802_RG_USB20_SQTH, 0x4);
  149. /* disable VBUS CMP to save power since no OTG function */
  150. u3_phy_write_field32(((u32)&info->u2phy_regs_d->usbphyacr6),
  151. D60802_RG_USB20_OTG_VBUSCMP_EN_OFST, D60802_RG_USB20_OTG_VBUSCMP_EN, 1);
  152. /* phyd part */
  153. /* shorten Tx drive stable delay time from 82us -> 25us */
  154. u3_phy_write_field32(((u32)&info->u3phyd_regs_d->phyd_mix1),
  155. D60802_RG_SSUSB_TX_DRV_DLY_OFST, D60802_RG_SSUSB_TX_DRV_DLY, 0x13);
  156. /* The same Rx LFPS detect period rxlfps_upb as A ver */
  157. u3_phy_write_field32(((u32)&info->u3phyd_regs_d->phyd_lfps0),
  158. D60802_RG_SSUSB_RXLFPS_UPB_OFST, D60802_RG_SSUSB_RXLFPS_UPB, 0x19);
  159. /* No switch to Lock 5g @tx_lfps enable */
  160. u3_phy_write_field32(((u32)&info->u3phyd_regs_d->phyd_lfps0),
  161. D60802_RG_SSUSB_LOCK5G_BLOCK_OFST, D60802_RG_SSUSB_LOCK5G_BLOCK, 0x1);
  162. /* disable DFE to improve Rx JT */
  163. u3_phy_write_field32(((u32)&info->u3phyd_regs_d->phyd_rx0),
  164. D60802_RG_SSUSB_RX_DFE_RST_OFST, D60802_RG_SSUSB_RX_DFE_RST, 0);
  165. /* calibrate CDR offset every time enter TSEQ */
  166. u3_phy_write_field32(((u32)&info->u3phyd_regs_d->phyd_mix2),
  167. D60802_RG_SSUSB_CDROS_EN_OFST, D60802_RG_SSUSB_CDROS_EN, 0x1);
  168. /* Re-Calibration after exit P3 state */
  169. u3_phy_write_field32(((u32)&info->u3phyd_regs_d->phyd_pll_0),
  170. D60802_RG_SSUSB_PLLBAND_RECAL_OFST, D60802_RG_SSUSB_PLLBAND_RECAL, 0x1);
  171. /* phyd bank2 part */
  172. /* Disable E-Idle Low power mode */
  173. u3_phy_write_field32(((u32)&info->u3phyd_bank2_regs_d->b2_phyd_top1),
  174. D60802_RG_SSUSB_FORCE_TX_EIDLE_LP_EN_OFST , D60802_RG_SSUSB_FORCE_TX_EIDLE_LP_EN, 0x1);
  175. u3_phy_write_field32(((u32)&info->u3phyd_bank2_regs_d->b2_phyd_top1),
  176. D60802_RG_SSUSB_TX_EIDLE_LP_EN_OFST, D60802_RG_SSUSB_TX_EIDLE_LP_EN, 0);
  177. /* phya part */
  178. /* modify Tx det Rx Vth to work around the threshold back to 200mV */
  179. u3_phy_write_field32(((u32)&info->u3phya_regs_d->reg5),
  180. D60802_REG5_FLD_RG_SSUSB_RXDET_VTHSEL_L_OFST, D60802_REG5_FLD_RG_SSUSB_RXDET_VTHSEL_L,0x2);
  181. /* modify Tx det Rx Vth to work around the threshold back to 200mV */
  182. u3_phy_write_field32(((u32)&info->u3phya_regs_d->reg5),
  183. D60802_REG5_FLD_RG_SSUSB_RXDET_VTHSEL_H_OFST, D60802_REG5_FLD_RG_SSUSB_RXDET_VTHSEL_H,0x2);
  184. /* phya da part */
  185. /* set to pass SSC min in electrical compliance */
  186. u3_phy_write_field32(((u32)&info->u3phya_da_regs_d->reg21),
  187. D60802_REG21_FLD_RG_SSUSB_PLL_SSC_DELTA_U3_OFST, D60802_REG21_FLD_RG_SSUSB_PLL_SSC_DELTA_U3,0x47);
  188. /* set R step 1 = 2 to improve Rx JT */
  189. u3_phy_write_field32(((u32)&info->u3phya_da_regs_d->reg32),
  190. D60802_REG32_FLD_RG_SSUSB_EQ_RSTEP1_U3_OFST, D60802_REG32_FLD_RG_SSUSB_EQ_RSTEP1_U3, 0x2);
  191. /* phy chip part */
  192. /* Power down bias at P3, p3 bias _pwd */
  193. u3_phy_write_field32(((u32)&info->sifslv_chip_regs_d->syspll1),
  194. (24), (0x1<<24), 0x1);
  195. /* PIPE drv = 2 */
  196. u3_phy_write_reg8(((u32)&info->sifslv_chip_regs_d->gpio_ctla+2), 0x10);
  197. /* PIPE phase */
  198. //u3_phy_write_reg8(((u32)&info->sifslv_chip_regs_d->gpio_ctla+3), 0x44);
  199. /* for 3.0 */
  200. //u3_phy_write_reg8(((u32)&info->sifslv_chip_regs_d->gpio_ctla+3), 0x8c);
  201. //u3_phy_write_reg8(((u32)&info->sifslv_chip_regs_d->gpio_ctla+3), 0x3D);
  202. u3_phy_write_reg8(((u32)&info->sifslv_chip_regs_d->gpio_ctla+3), 0x75);
  203. mdelay(1000);
  204. /* scan proper phase for ssusb */
  205. //mu3d_hal_phy_scan(info, 1);
  206. //mu3d_hal_phy_scan(info, 0);
  207. }
  208. #endif