mtk-phy.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef __MTK_PHY_NEW_H
  2. #define __MTK_PHY_NEW_H
  3. #define CONFIG_U3D_HAL_SUPPORT
  4. /* U3D_PHY_REF_CK = U3D_MAC_REF_CK on ASIC */
  5. /* On FPGA, these two clocks are separated */
  6. #ifdef CONFIG_U3D_HAL_SUPPORT
  7. #define REF_CK 48
  8. #else
  9. #define REF_CK 25
  10. #endif
  11. /* include system library */
  12. #include <linux/slab.h>
  13. #include <linux/delay.h>
  14. /* BASE ADDRESS DEFINE, should define this on ASIC */
  15. #define PHY_BASE 0x0
  16. #define SIFSLV_SPLLC_BASE (PHY_BASE+0x0)
  17. #define SIFSLV_FM_FEG_BASE (PHY_BASE+0x100)
  18. #define SIFSLV_CHIP_BASE (PHY_BASE+0x700)
  19. #define U2_PHY_BASE (PHY_BASE+0x800)
  20. #define U3_PHYD_BASE (PHY_BASE+0x900)
  21. #define U3_PHYD_B2_BASE (PHY_BASE+0xa00)
  22. #define U3_PHYA_BASE (PHY_BASE+0xb00)
  23. #define U3_PHYA_DA_BASE (PHY_BASE+0xc00)
  24. /* TYPE DEFINE */
  25. typedef unsigned int PHY_UINT32;
  26. typedef int PHY_INT32;
  27. typedef unsigned short PHY_UINT16;
  28. typedef short PHY_INT16;
  29. typedef unsigned char PHY_UINT8;
  30. typedef char PHY_INT8;
  31. typedef PHY_UINT32 __bitwise PHY_LE32;
  32. /* CONSTANT DEFINE */
  33. #define PHY_FALSE 0
  34. #define PHY_TRUE 1
  35. /* #define DRV_MDELAY mdelay */
  36. #define DRV_MSLEEP msleep
  37. #define DRV_UDELAY udelay
  38. /* #define DRV_USLEEP usleep */
  39. /* PHY FUNCTION DEFINE, implemented in platform files, ex. ahb, gpio */
  40. PHY_INT32 U3PhyWriteReg32(PHY_UINT32 addr, PHY_UINT32 data);
  41. PHY_INT32 U3PhyReadReg32(PHY_UINT32 addr);
  42. PHY_INT32 U3PhyWriteReg8(PHY_UINT32 addr, PHY_UINT8 data);
  43. PHY_INT8 U3PhyReadReg8(PHY_UINT32 addr);
  44. /* PHY GENERAL USAGE FUNC, implemented in mtk-phy.c */
  45. PHY_INT32 U3PhyWriteField8(PHY_INT32 addr, PHY_INT32 offset, PHY_INT32 mask, PHY_INT32 value);
  46. PHY_INT32 U3PhyWriteField32(PHY_INT32 addr, PHY_INT32 offset, PHY_INT32 mask, PHY_INT32 value);
  47. PHY_INT32 U3PhyReadField8(PHY_INT32 addr, PHY_INT32 offset, PHY_INT32 mask);
  48. PHY_INT32 U3PhyReadField32(PHY_INT32 addr, PHY_INT32 offset, PHY_INT32 mask);
  49. void u3phy_writel(void __iomem *base, u32 reg, u32 offset, u32 mask, u32 value);
  50. u32 u3phy_readl(void __iomem *base, u32 reg, u32 offset, u32 mask);
  51. struct u3phy_reg_base {
  52. void __iomem *sif_base;
  53. /* void __iomem *sif2_base; */
  54. int phy_num;
  55. };
  56. struct u3phy_operator;
  57. struct u3phy_info {
  58. /* used by non-project env. */
  59. PHY_INT32 phy_version;
  60. PHY_INT32 phyd_version_addr;
  61. /* used by project env. */
  62. struct u3phy_reg_base phy_regs;
  63. void *reg_info;
  64. const struct u3phy_operator *u3p_ops;
  65. };
  66. struct u3phy_operator {
  67. PHY_INT32 (*init)(struct u3phy_info *info);
  68. PHY_INT32 (*change_pipe_phase)(struct u3phy_info *info, PHY_INT32 phy_drv,
  69. PHY_INT32 pipe_phase);
  70. PHY_INT32 (*eyescan_init)(struct u3phy_info *info);
  71. PHY_INT32 (*eyescan)(struct u3phy_info *info, PHY_INT32 x_t1, PHY_INT32 y_t1,
  72. PHY_INT32 x_br, PHY_INT32 y_br, PHY_INT32 delta_x, PHY_INT32 delta_y,
  73. PHY_INT32 eye_cnt, PHY_INT32 num_cnt, PHY_INT32 PI_cal_en,
  74. PHY_INT32 num_ignore_cnt);
  75. PHY_INT32 (*u2_connect)(struct u3phy_info *info);
  76. PHY_INT32 (*u2_disconnect)(struct u3phy_info *info);
  77. PHY_INT32 (*u2_save_current_entry)(struct u3phy_info *info);
  78. PHY_INT32 (*u2_save_current_recovery)(struct u3phy_info *info);
  79. PHY_INT32 (*u2_slew_rate_calibration)(struct u3phy_info *info);
  80. void (*usb_phy_savecurrent)(struct u3phy_info *info, unsigned int clk_on);
  81. void (*usb_phy_recover)(struct u3phy_info *info, unsigned int clk_on);
  82. };
  83. #undef EXTERN
  84. #ifdef U3_PHY_LIB
  85. #define EXTERN
  86. #else
  87. #define EXTERN /*extern */
  88. #endif
  89. #ifdef U3_PHY_LIB
  90. struct u3phy_info *u3phy;
  91. #else
  92. extern struct u3phy_info *u3phy;
  93. #endif
  94. /*********eye scan required*********/
  95. #define LO_BYTE(x) ((PHY_UINT8)((x) & 0xFF))
  96. #define HI_BYTE(x) ((PHY_UINT8)(((x) & 0xFF00) >> 8))
  97. typedef enum {
  98. SCAN_UP,
  99. SCAN_DN
  100. } enumScanDir;
  101. struct strucScanRegion {
  102. PHY_INT8 bX_tl;
  103. PHY_INT8 bY_tl;
  104. PHY_INT8 bX_br;
  105. PHY_INT8 bY_br;
  106. PHY_INT8 bDeltaX;
  107. PHY_INT8 bDeltaY;
  108. };
  109. struct strucTestCycle {
  110. PHY_UINT16 wEyeCnt;
  111. PHY_INT8 bNumOfEyeCnt;
  112. PHY_INT8 bPICalEn;
  113. PHY_INT8 bNumOfIgnoreCnt;
  114. };
  115. #define ERRCNT_MAX 128
  116. #define CYCLE_COUNT_MAX 15
  117. /* / the map resolution is 128 x 128 pts */
  118. #define MAX_X 127
  119. #define MAX_Y 127
  120. #define MIN_X 0
  121. #define MIN_Y 0
  122. PHY_INT32 u3phy_init(struct u3phy_reg_base *regs);
  123. void u3phy_exit(struct u3phy_reg_base *regs);
  124. extern struct strucScanRegion _rEye1;
  125. extern struct strucScanRegion _rEye2;
  126. extern struct strucTestCycle _rTestCycle;
  127. extern PHY_UINT8 _bXcurr;
  128. extern PHY_UINT8 _bYcurr;
  129. extern enumScanDir _eScanDir;
  130. extern PHY_INT8 _fgXChged;
  131. extern unsigned int _bPIResult;
  132. extern PHY_UINT32 pwErrCnt0[CYCLE_COUNT_MAX][ERRCNT_MAX][ERRCNT_MAX];
  133. extern PHY_UINT32 pwErrCnt1[CYCLE_COUNT_MAX][ERRCNT_MAX][ERRCNT_MAX];
  134. /***********************************/
  135. #endif