mt_usbphy_e60802.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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_usb.h>
  31. #include <mt_usbphy.h>
  32. #include <mt_usbphy_e60802.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. void phy_init_e60802(struct u3phy_info *info)
  49. {
  50. /* u2phy part */
  51. /* enabe VBUS CMP to save power since cause 6593 will use OTG */
  52. u3_phy_write_field32(((u32)&info->u2phy_regs_e->usbphyacr6),
  53. E60802_RG_USB20_OTG_VBUSCMP_EN_OFST, E60802_RG_USB20_OTG_VBUSCMP_EN, 0x1);
  54. /* phyd part */
  55. /* disable ssusb_p3_entry to work around resume from P3 */
  56. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->phyd_lfps0),
  57. E60802_RG_SSUSB_P3_ENTRY_OFST, E60802_RG_SSUSB_P3_ENTRY, 0x0);
  58. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->phyd_lfps0),
  59. E60802_RG_SSUSB_P3_ENTRY_SEL_OFST, E60802_RG_SSUSB_P3_ENTRY_SEL, 0x1);
  60. /* phya part */
  61. /* Enable internal VRT to bypass bandgap voltage too high issue */
  62. u3_phy_write_field32(((u32)&info->u3phya_regs_e->reg0),
  63. E60802_RG_SSUSB_INTR_EN_OFST, E60802_RG_SSUSB_INTR_EN, 0x1);
  64. /* RG_SSUSB_XTAL_TOP_RESERVE<15:11> =10001 */
  65. u3_phy_write_field32(((u32)&info->u3phya_regs_e->reg1),
  66. E60802_RG_SSUSB_XTAL_TOP_RESERVE_OFST, E60802_RG_SSUSB_XTAL_TOP_RESERVE,
  67. (0x11 << 11));
  68. /* phya da part */
  69. /* fine tune SSC delta1 to let SSC min average ~0ppm */
  70. u3_phy_write_field32(((u32)&info->u3phya_da_regs_e->reg19),
  71. E60802_RG_SSUSB_PLL_SSC_DELTA1_U3_OFST, E60802_RG_SSUSB_PLL_SSC_DELTA1_U3, 0x42);
  72. /* fine tune SSC delta to let SSC min average ~0ppm */
  73. u3_phy_write_field32(((u32)&info->u3phya_da_regs_e->reg21),
  74. E60802_RG_SSUSB_PLL_SSC_DELTA_U3_OFST, E60802_RG_SSUSB_PLL_SSC_DELTA_U3, 0x3e);
  75. /* Fine tune SYSPLL to improve phase noise */
  76. u3_phy_write_field32(((u32)&info->u3phya_da_regs_e->reg4),
  77. E60802_RG_SSUSB_PLL_BC_U3_OFST, E60802_RG_SSUSB_PLL_BC_U3, 0x3);
  78. u3_phy_write_field32(((u32)&info->u3phya_da_regs_e->reg4),
  79. E60802_RG_SSUSB_PLL_DIVEN_U3_OFST, E60802_RG_SSUSB_PLL_DIVEN_U3, 0x2);
  80. u3_phy_write_field32(((u32)&info->u3phya_da_regs_e->reg5),
  81. E60802_RG_SSUSB_PLL_IC_U3_OFST, E60802_RG_SSUSB_PLL_IC_U3, 0x1);
  82. u3_phy_write_field32(((u32)&info->u3phya_da_regs_e->reg5),
  83. E60802_RG_SSUSB_PLL_BR_U3_OFST, E60802_RG_SSUSB_PLL_BR_U3, 0x0);
  84. u3_phy_write_field32(((u32)&info->u3phya_da_regs_e->reg6),
  85. E60802_RG_SSUSB_PLL_IR_U3_OFST, E60802_RG_SSUSB_PLL_IR_U3, 0x1);
  86. u3_phy_write_field32(((u32)&info->u3phya_da_regs_e->reg7),
  87. E60802_RG_SSUSB_PLL_BP_U3_OFST, E60802_RG_SSUSB_PLL_BP_U3, 0xf);
  88. /* disable ssusb_p3_bias_pwd to work around resume from P3 */
  89. u3_phy_write_field32(((u32)&info->spllc_regs_e->u3d_xtalctl_2),
  90. E60802_RG_SSUSB_P3_BIAS_PWD_OFST, E60802_RG_SSUSB_P3_BIAS_PWD, 0x0);
  91. /* PIPE drv = 2 */
  92. u3_phy_write_reg8(((u32)&info->sifslv_chip_regs_e->gpio_ctla+2), 0x10);
  93. /* PIPE phase */
  94. u3_phy_write_reg8(((u32)&info->sifslv_chip_regs_e->gpio_ctla+3), 0x44);
  95. /* scan proper phase for ssusb */
  96. //mu3d_hal_phy_scan(info, 1);
  97. //mu3d_hal_phy_scan(info, 0);
  98. }
  99. int phy_change_pipe_phase_e60802(struct u3phy_info *info, int phy_drv, int pipe_phase)
  100. {
  101. int drv_reg_value;
  102. int phase_reg_value;
  103. int temp;
  104. drv_reg_value = phy_drv << PHY_DRV_SHIFT;
  105. phase_reg_value = (pipe_phase << PHY_PHASE_SHIFT) | (phy_drv << PHY_PHASE_DRV_SHIFT);
  106. temp = u3_phy_read_reg8(((u32)&info->sifslv_chip_regs_e->gpio_ctla)+2);
  107. temp &= ~(0x3 << PHY_DRV_SHIFT);
  108. temp |= drv_reg_value;
  109. u3_phy_write_reg8(((u32)&info->sifslv_chip_regs_e->gpio_ctla)+2, temp);
  110. temp = u3_phy_read_reg8(((u32)&info->sifslv_chip_regs_e->gpio_ctla)+3);
  111. temp &= ~((0x3 << PHY_PHASE_DRV_SHIFT) | (0x1f << PHY_PHASE_SHIFT));
  112. temp |= phase_reg_value;
  113. u3_phy_write_reg8(((u32)&info->sifslv_chip_regs_e->gpio_ctla)+3, temp);
  114. return true;
  115. }
  116. #if 0
  117. //--------------------------------------------------------
  118. // Function : fgEyeScanHelper_CheckPtInRegion()
  119. // Description : Check if the test point is in a rectangle region.
  120. // If it is in the rectangle, also check if this point
  121. // is on the multiple of deltaX and deltaY.
  122. // Parameter : strucScanRegion * prEye - the region
  123. // BYTE bX
  124. // BYTE bY
  125. // Return : BYTE - TRUE : This point needs to be tested
  126. // FALSE: This point will be omitted
  127. // Note : First check within the rectangle.
  128. // Secondly, use modulous to check if the point will be tested.
  129. //--------------------------------------------------------
  130. static char fgEyeScanHelper_CheckPtInRegion(struct strucScanRegion * prEye, char bX, char bY)
  131. {
  132. char fgValid = true;
  133. /// Be careful, the axis origin is on the TOP-LEFT corner.
  134. /// Therefore the top-left point has the minimum X and Y
  135. /// Botton-right point is the maximum X and Y
  136. if ( (prEye->bX_tl <= bX) && (bX <= prEye->bX_br)
  137. && (prEye->bY_tl <= bY) && (bY <= prEye->bX_br)) {
  138. // With the region, now check whether or not the input test point is
  139. // on the multiples of X and Y
  140. // Do not have to worry about negative value, because we have already
  141. // check the input bX, and bY is within the region.
  142. if ( ((bX - prEye->bX_tl) % (prEye->bDeltaX))
  143. || ((bY - prEye->bY_tl) % (prEye->bDeltaY)) ) {
  144. // if the division will have remainder, that means
  145. // the input test point is on the multiples of X and Y
  146. fgValid = false;
  147. } else {
  148. }
  149. } else {
  150. fgValid = false;
  151. }
  152. return fgValid;
  153. }
  154. //--------------------------------------------------------
  155. // Function : EyeScanHelper_RunTest()
  156. // Description : Enable the test, and wait til it is completed
  157. // Parameter : None
  158. // Return : None
  159. // Note : None
  160. //--------------------------------------------------------
  161. static void EyeScanHelper_RunTest(struct u3phy_info *info)
  162. {
  163. // Disable the test
  164. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  165. , E60802_RG_SSUSB_EQ_EYE_CNT_EN_OFST, E60802_RG_SSUSB_EQ_EYE_CNT_EN, 0); //RG_SSUSB_RX_EYE_CNT_EN = 0
  166. // Run the test
  167. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  168. , E60802_RG_SSUSB_EQ_EYE_CNT_EN_OFST, E60802_RG_SSUSB_EQ_EYE_CNT_EN, 1); //RG_SSUSB_RX_EYE_CNT_EN = 1
  169. // Wait til it's done
  170. //RGS_SSUSB_RX_EYE_CNT_RDY
  171. while (!U3PhyReadField32(((u32)&info->u3phyd_regs_e->phya_rx_mon5)
  172. , E60802_RGS_SSUSB_EQ_EYE_CNT_RDY_OFST, E60802_RGS_SSUSB_EQ_EYE_CNT_RDY));
  173. }
  174. //--------------------------------------------------------
  175. // Function : fgEyeScanHelper_CalNextPoint()
  176. // Description : Calcualte the test point for the measurement
  177. // Parameter : None
  178. // Return : BOOL - TRUE : the next point is within the
  179. // boundaryof HW limit
  180. // FALSE: the next point is out of the HW limit
  181. // Note : The next point is obtained by calculating
  182. // from the bottom left of the region rectangle
  183. // and then scanning up until it reaches the upper
  184. // limit. At this time, the x will increment, and
  185. // start scanning downwards until the y hits the
  186. // zero.
  187. //--------------------------------------------------------
  188. static char fgEyeScanHelper_CalNextPoint(void)
  189. {
  190. if ( ((_bYcurr == MAX_Y) && (_eScanDir == SCAN_DN))
  191. || ((_bYcurr == MIN_Y) && (_eScanDir == SCAN_UP))
  192. ) {
  193. /// Reaches the limit of Y axis
  194. /// Increment X
  195. _bXcurr++;
  196. _fgXChged = true;
  197. _eScanDir = (_eScanDir == SCAN_UP) ? SCAN_DN : SCAN_UP;
  198. if (_bXcurr > MAX_X) {
  199. return false;
  200. }
  201. } else {
  202. _bYcurr = (_eScanDir == SCAN_DN) ? _bYcurr + 1 : _bYcurr - 1;
  203. _fgXChged = false;
  204. }
  205. return PHY_TRUE;
  206. }
  207. int eyescan_init_e60802 (struct u3phy_info *info)
  208. {
  209. //initial PHY setting
  210. u3_phy_write_field32(((u32)&info->u3phya_regs_e->reg9)
  211. , E60802_RG_SSUSB_CDR_EPEN_OFST, E60802_RG_SSUSB_CDR_EPEN, 1);
  212. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->phyd_mix3)
  213. , E60802_RG_SSUSB_FORCE_CDR_PI_PWD_OFST, E60802_RG_SSUSB_FORCE_CDR_PI_PWD, 1);
  214. return PHY_TRUE;
  215. }
  216. int phy_eyescan_e60802(struct u3phy_info *info, int x_t1, int y_t1, int x_br, int y_br, int delta_x, int delta_y
  217. , int eye_cnt, int num_cnt, int PI_cal_en, int num_ignore_cnt)
  218. {
  219. int cOfst = 0;
  220. u8 bIdxX = 0;
  221. u8 bIdxY = 0;
  222. char bCnt = 0;
  223. char bIdxCycCnt = 0;
  224. char fgValid;
  225. char cX;
  226. char cY;
  227. char bExtendCnt;
  228. char isContinue;
  229. char isBreak;
  230. u32 wErr0 = 0, wErr1 = 0;
  231. u32 temp;
  232. _rEye1.bX_tl = x_t1;
  233. _rEye1.bY_tl = y_t1;
  234. _rEye1.bX_br = x_br;
  235. _rEye1.bY_br = y_br;
  236. _rEye1.bDeltaX = delta_x;
  237. _rEye1.bDeltaY = delta_y;
  238. _rEye2.bX_tl = x_t1;
  239. _rEye2.bY_tl = y_t1;
  240. _rEye2.bX_br = x_br;
  241. _rEye2.bY_br = y_br;
  242. _rEye2.bDeltaX = delta_x;
  243. _rEye2.bDeltaY = delta_y;
  244. _rTestCycle.wEyeCnt = eye_cnt;
  245. _rTestCycle.bNumOfEyeCnt = num_cnt;
  246. _rTestCycle.bNumOfIgnoreCnt = num_ignore_cnt;
  247. _rTestCycle.bPICalEn = PI_cal_en;
  248. _bXcurr = 0;
  249. _bYcurr = 0;
  250. _eScanDir = SCAN_DN;
  251. _fgXChged = false;
  252. PHY_LOG("x_t1: %x, y_t1: %x, x_br: %x, y_br: %x, delta_x: %x, delta_y: %x, \
  253. eye_cnt: %x, num_cnt: %x, PI_cal_en: %x, num_ignore_cnt: %x\n", \
  254. x_t1, y_t1, x_br, y_br, delta_x, delta_y, eye_cnt, num_cnt, PI_cal_en, num_ignore_cnt);
  255. //force SIGDET to OFF
  256. u3_phy_write_field32(((u32)&info->u3phyd_bank2_regs_e->b2_phyd_misc0)
  257. , E60802_RG_SSUSB_RX_SIGDET_EN_SEL_OFST, E60802_RG_SSUSB_RX_SIGDET_EN_SEL, 1); //RG_SSUSB_RX_SIGDET_SEL = 1
  258. u3_phy_write_field32(((u32)&info->u3phyd_bank2_regs_e->b2_phyd_misc0)
  259. , E60802_RG_SSUSB_RX_SIGDET_EN_OFST, E60802_RG_SSUSB_RX_SIGDET_EN, 0); //RG_SSUSB_RX_SIGDET_EN = 0
  260. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye1)
  261. , E60802_RG_SSUSB_EQ_SIGDET_OFST, E60802_RG_SSUSB_EQ_SIGDET, 0); //RG_SSUSB_RX_SIGDET = 0
  262. // RX_TRI_DET_EN to Disable
  263. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq3)
  264. , E60802_RG_SSUSB_EQ_TRI_DET_EN_OFST, E60802_RG_SSUSB_EQ_TRI_DET_EN, 0); //RG_SSUSB_RX_TRI_DET_EN = 0
  265. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  266. , E60802_RG_SSUSB_EQ_EYE_MON_EN_OFST, E60802_RG_SSUSB_EQ_EYE_MON_EN, 1); //RG_SSUSB_EYE_MON_EN = 1
  267. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  268. , E60802_RG_SSUSB_EQ_EYE_XOFFSET_OFST, E60802_RG_SSUSB_EQ_EYE_XOFFSET, 0); //RG_SSUSB_RX_EYE_XOFFSET = 0
  269. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  270. , E60802_RG_SSUSB_EQ_EYE0_Y_OFST, E60802_RG_SSUSB_EQ_EYE0_Y, 0); //RG_SSUSB_RX_EYE0_Y = 0
  271. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  272. , E60802_RG_SSUSB_EQ_EYE1_Y_OFST, E60802_RG_SSUSB_EQ_EYE1_Y, 0); //RG_SSUSB_RX_EYE1_Y = 0
  273. if (PI_cal_en) {
  274. // PI Calibration
  275. u3_phy_write_field32(((u32)&info->u3phyd_bank2_regs_e->b2_phyd_misc0)
  276. , E60802_RG_SSUSB_RX_PI_CAL_EN_SEL_OFST, E60802_RG_SSUSB_RX_PI_CAL_EN_SEL, 1); //RG_SSUSB_RX_PI_CAL_MANUAL_SEL = 1
  277. u3_phy_write_field32(((u32)&info->u3phyd_bank2_regs_e->b2_phyd_misc0)
  278. , E60802_RG_SSUSB_RX_PI_CAL_EN_OFST, E60802_RG_SSUSB_RX_PI_CAL_EN, 0); //RG_SSUSB_RX_PI_CAL_MANUAL_EN = 0
  279. u3_phy_write_field32(((u32)&info->u3phyd_bank2_regs_e->b2_phyd_misc0)
  280. , E60802_RG_SSUSB_RX_PI_CAL_EN_OFST, E60802_RG_SSUSB_RX_PI_CAL_EN, 1); //RG_SSUSB_RX_PI_CAL_MANUAL_EN = 1
  281. udelay(20);
  282. u3_phy_write_field32(((u32)&info->u3phyd_bank2_regs_e->b2_phyd_misc0)
  283. , E60802_RG_SSUSB_RX_PI_CAL_EN_OFST, E60802_RG_SSUSB_RX_PI_CAL_EN, 0); //RG_SSUSB_RX_PI_CAL_MANUAL_EN = 0
  284. _bPIResult = U3PhyReadField32(((u32)&info->u3phyd_regs_e->phya_rx_mon5)
  285. , E60802_RGS_SSUSB_EQ_PILPO_OFST, E60802_RGS_SSUSB_EQ_PILPO); //read RGS_SSUSB_RX_PILPO
  286. PHY_LOG(KERN_ERR "PI result: %d\n", _bPIResult);
  287. }
  288. // Read Initial DAC
  289. // Set CYCLE
  290. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye3)
  291. ,E60802_RG_SSUSB_EQ_EYE_CNT_OFST, E60802_RG_SSUSB_EQ_EYE_CNT, eye_cnt); //RG_SSUSB_RX_EYE_CNT
  292. // Eye Monitor Feature
  293. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye1)
  294. , E60802_RG_SSUSB_EQ_EYE_MASK_OFST, E60802_RG_SSUSB_EQ_EYE_MASK, 0x3ff); //RG_SSUSB_RX_EYE_MASK = 0x3ff
  295. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  296. , E60802_RG_SSUSB_EQ_EYE_MON_EN_OFST, E60802_RG_SSUSB_EQ_EYE_MON_EN, 1); //RG_SSUSB_EYE_MON_EN = 1
  297. // Move X,Y to the top-left corner
  298. for (cOfst = 0; cOfst >= -64; cOfst--) {
  299. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  300. ,E60802_RG_SSUSB_EQ_EYE_XOFFSET_OFST, E60802_RG_SSUSB_EQ_EYE_XOFFSET, cOfst); //RG_SSUSB_RX_EYE_XOFFSET
  301. }
  302. for (cOfst = 0; cOfst < 64; cOfst++) {
  303. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  304. , E60802_RG_SSUSB_EQ_EYE0_Y_OFST, E60802_RG_SSUSB_EQ_EYE0_Y, cOfst); //RG_SSUSB_RX_EYE0_Y
  305. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  306. , E60802_RG_SSUSB_EQ_EYE1_Y_OFST, E60802_RG_SSUSB_EQ_EYE1_Y, cOfst); //RG_SSUSB_RX_EYE1_Y
  307. }
  308. //ClearErrorResult
  309. for (bIdxCycCnt = 0; bIdxCycCnt < CYCLE_COUNT_MAX; bIdxCycCnt++) {
  310. for (bIdxX = 0; bIdxX < ERRCNT_MAX; bIdxX++) {
  311. for (bIdxY = 0; bIdxY < ERRCNT_MAX; bIdxY++) {
  312. pwErrCnt0[bIdxCycCnt][bIdxX][bIdxY] = 0;
  313. pwErrCnt1[bIdxCycCnt][bIdxX][bIdxY] = 0;
  314. }
  315. }
  316. }
  317. isContinue = true;
  318. while (isContinue) {
  319. PHY_LOG(KERN_ERR "_bXcurr: %d, _bYcurr: %d\n", _bXcurr, _bYcurr);
  320. // The point is within the boundary, then let's check if it is within
  321. // the testing region.
  322. // The point is only test-able if one of the eye region
  323. // includes this point.
  324. fgValid = fgEyeScanHelper_CheckPtInRegion(&_rEye1, _bXcurr, _bYcurr)
  325. || fgEyeScanHelper_CheckPtInRegion(&_rEye2, _bXcurr, _bYcurr);
  326. // Translate bX and bY to 2's complement from where the origin was on the
  327. // top left corner.
  328. // 0x40 and 0x3F needs a bit of thinking!!!! >"<
  329. cX = (_bXcurr ^ 0x40);
  330. cY = (_bYcurr ^ 0x3F);
  331. // Set X if necessary
  332. if (_fgXChged == true) {
  333. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  334. , E60802_RG_SSUSB_EQ_EYE_XOFFSET_OFST, E60802_RG_SSUSB_EQ_EYE_XOFFSET, cX); //RG_SSUSB_RX_EYE_XOFFSET
  335. }
  336. // Set Y
  337. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  338. , E60802_RG_SSUSB_EQ_EYE0_Y_OFST, E60802_RG_SSUSB_EQ_EYE0_Y, cY); //RG_SSUSB_RX_EYE0_Y
  339. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  340. , E60802_RG_SSUSB_EQ_EYE1_Y_OFST, E60802_RG_SSUSB_EQ_EYE1_Y, cY); //RG_SSUSB_RX_EYE1_Y
  341. /// Test this point!
  342. if (fgValid) {
  343. for (bExtendCnt = 0; bExtendCnt < num_ignore_cnt; bExtendCnt++) {
  344. //run test
  345. EyeScanHelper_RunTest(info);
  346. }
  347. for (bExtendCnt = 0; bExtendCnt < num_cnt; bExtendCnt++) {
  348. EyeScanHelper_RunTest(info);
  349. wErr0 = U3PhyReadField32(((u32)&info->u3phyd_regs_e->phya_rx_mon3)
  350. , E60802_RGS_SSUSB_EQ_EYE_MONITOR_ERRCNT_0_OFST, E60802_RGS_SSUSB_EQ_EYE_MONITOR_ERRCNT_0);
  351. wErr1 = U3PhyReadField32(((u32)&info->u3phyd_regs_e->phya_rx_mon4)
  352. , E60802_RGS_SSUSB_EQ_EYE_MONITOR_ERRCNT_1_OFST, E60802_RGS_SSUSB_EQ_EYE_MONITOR_ERRCNT_1);
  353. pwErrCnt0[bExtendCnt][_bXcurr][_bYcurr] = wErr0;
  354. pwErrCnt1[bExtendCnt][_bXcurr][_bYcurr] = wErr1;
  355. //EyeScanHelper_GetResult(&_rRes.pwErrCnt0[bCnt], &_rRes.pwErrCnt1[bCnt]);
  356. // PHY_LOG(KERN_ERR "cnt[%d] cur_x,y [0x%x][0x%x], cX,cY [0x%x][0x%x], ErrCnt[%d][%d]\n"
  357. // , bExtendCnt, _bXcurr, _bYcurr, cX, cY, pwErrCnt0[bExtendCnt][_bXcurr][_bYcurr], pwErrCnt1[bExtendCnt][_bXcurr][_bYcurr]);
  358. }
  359. //PHY_LOG(KERN_ERR "cur_x,y [0x%x][0x%x], cX,cY [0x%x][0x%x], ErrCnt[%d][%d]\n", _bXcurr, _bYcurr, cX, cY, pwErrCnt0[0][_bXcurr][_bYcurr], pwErrCnt1[0][_bXcurr][_bYcurr]);
  360. } else {
  361. }
  362. if (fgEyeScanHelper_CalNextPoint() == false) {
  363. #if 1
  364. PHY_LOG(KERN_ERR "Xcurr [0x%x] Ycurr [0x%x]\n", _bXcurr, _bYcurr);
  365. PHY_LOG(KERN_ERR "XcurrREG [0x%x] YcurrREG [0x%x]\n", cX, cY);
  366. #endif
  367. PHY_LOG(KERN_ERR "end of eye scan\n");
  368. isContinue = false;
  369. }
  370. }
  371. PHY_LOG(KERN_ERR "CurX [0x%x] CurY [0x%x]\n"
  372. , U3PhyReadField32(((u32)&info->u3phyd_regs_e->eq_eye0), E60802_RG_SSUSB_EQ_EYE_XOFFSET_OFST, E60802_RG_SSUSB_EQ_EYE_XOFFSET)
  373. , U3PhyReadField32(((u32)&info->u3phyd_regs_e->eq_eye0), E60802_RG_SSUSB_EQ_EYE0_Y_OFST, E60802_RG_SSUSB_EQ_EYE0_Y));
  374. // Move X,Y to the top-left corner
  375. for (cOfst = 63; cOfst >= 0; cOfst--) {
  376. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  377. , E60802_RG_SSUSB_EQ_EYE_XOFFSET_OFST, E60802_RG_SSUSB_EQ_EYE_XOFFSET, cOfst); //RG_SSUSB_RX_EYE_XOFFSET
  378. }
  379. for (cOfst = 63; cOfst >= 0; cOfst--) {
  380. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  381. , E60802_RG_SSUSB_EQ_EYE0_Y_OFST, E60802_RG_SSUSB_EQ_EYE0_Y, cOfst);
  382. u3_phy_write_field32(((u32)&info->u3phyd_regs_e->eq_eye0)
  383. , E60802_RG_SSUSB_EQ_EYE1_Y_OFST, E60802_RG_SSUSB_EQ_EYE1_Y, cOfst);
  384. }
  385. PHY_LOG(KERN_ERR "CurX [0x%x] CurY [0x%x]\n"
  386. , U3PhyReadField32(((u32)&info->u3phyd_regs_e->eq_eye0), E60802_RG_SSUSB_EQ_EYE_XOFFSET_OFST, E60802_RG_SSUSB_EQ_EYE_XOFFSET)
  387. , U3PhyReadField32(((u32)&info->u3phyd_regs_e->eq_eye0), E60802_RG_SSUSB_EQ_EYE0_Y_OFST, E60802_RG_SSUSB_EQ_EYE0_Y));
  388. PHY_LOG(KERN_ERR "PI result: %d\n", _bPIResult);
  389. PHY_LOG(KERN_ERR "pwErrCnt0 addr: 0x%x\n", pwErrCnt0);
  390. PHY_LOG(KERN_ERR "pwErrCnt1 addr: 0x%x\n", pwErrCnt1);
  391. return PHY_TRUE;
  392. }
  393. #endif
  394. void u2_connect_e60802(struct u3phy_info *info)
  395. {
  396. /* for better LPM BESL value */
  397. u3_phy_write_field32(((u32)&info->u2phy_regs_e->u2phydcr1),
  398. E60802_RG_USB20_SW_PLLMODE_OFST, E60802_RG_USB20_SW_PLLMODE, 0x1);
  399. }
  400. void u2_disconnect_e60802(struct u3phy_info *info)
  401. {
  402. /* for better LPM BESL value */
  403. u3_phy_write_field32(((u32)&info->u2phy_regs_e->u2phydcr1),
  404. E60802_RG_USB20_SW_PLLMODE_OFST, E60802_RG_USB20_SW_PLLMODE, 0x0);
  405. }
  406. void u2_save_cur_en_e60802(struct u3phy_info *info)
  407. {
  408. }
  409. void u2_save_cur_re_e60802(struct u3phy_info *info)
  410. {
  411. }
  412. int u2_slew_rate_calibration_e60802(struct u3phy_info *info)
  413. {
  414. int i = 0;
  415. int fgret = 0;
  416. int u4fmout = 0;
  417. int u4tmp = 0;
  418. /* => RG_USB20_HSTX_SRCAL_EN = 1 */
  419. /* enable HS TX SR calibration */
  420. u3_phy_write_field32(((u32)&info->u2phy_regs_e->usbphyacr5),
  421. E60802_RG_USB20_HSTX_SRCAL_EN_OFST, E60802_RG_USB20_HSTX_SRCAL_EN, 1);
  422. mdelay(1);
  423. /* => RG_FRCK_EN = 1 */
  424. /* Enable free run clock */
  425. u3_phy_write_field32(((u32)&info->sifslv_fm_regs_e->fmmonr1),
  426. E60802_RG_FRCK_EN_OFST, E60802_RG_FRCK_EN, 0x1);
  427. /* => RG_CYCLECNT = 0x400 */
  428. /* Setting cyclecnt = 0x400 */
  429. u3_phy_write_field32(((u32)&info->sifslv_fm_regs_e->fmcr0),
  430. E60802_RG_CYCLECNT_OFST, E60802_RG_CYCLECNT, 0x400);
  431. /* => RG_FREQDET_EN = 1 */
  432. /* Enable frequency meter */
  433. u3_phy_write_field32(((u32)&info->sifslv_fm_regs_e->fmcr0),
  434. E60802_RG_FREQDET_EN_OFST, E60802_RG_FREQDET_EN, 0x1);
  435. /* wait for FM detection done, set 10ms timeout */
  436. for (i = 0; i < 10; i++) {
  437. /* => u4fmout = USB_FM_OUT */
  438. /* read FM_OUT */
  439. u4fmout = u3_phy_read_reg32(((u32)&info->sifslv_fm_regs_e->fmmonr0));
  440. PHY_LOG("FM_OUT value: u4fmout = %d(0x%08X)\n", u4fmout, u4fmout);
  441. /* check if FM detection done */
  442. if (u4fmout != 0) {
  443. fgret = 0;
  444. PHY_LOG("FM detection done! loop = %d\n", i);
  445. break;
  446. }
  447. fgret = 1;
  448. mdelay(1);
  449. }
  450. /* => RG_FREQDET_EN = 0 */
  451. /* disable frequency meter */
  452. u3_phy_write_field32(((u32)&info->sifslv_fm_regs_e->fmcr0),
  453. E60802_RG_FREQDET_EN_OFST, E60802_RG_FREQDET_EN, 0);
  454. /* => RG_FRCK_EN = 0 */
  455. /* disable free run clock */
  456. u3_phy_write_field32(((u32)&info->sifslv_fm_regs_e->fmmonr1),
  457. E60802_RG_FRCK_EN_OFST, E60802_RG_FRCK_EN, 0);
  458. /* => RG_USB20_HSTX_SRCAL_EN = 0 */
  459. /* disable HS TX SR calibration */
  460. u3_phy_write_field32(((u32)&info->u2phy_regs_e->usbphyacr5),
  461. E60802_RG_USB20_HSTX_SRCAL_EN_OFST, E60802_RG_USB20_HSTX_SRCAL_EN, 0);
  462. mdelay(1);
  463. if (u4fmout == 0) {
  464. u3_phy_write_field32(((u32)&info->u2phy_regs_e->usbphyacr5),
  465. E60802_RG_USB20_HSTX_SRCTRL_OFST, E60802_RG_USB20_HSTX_SRCTRL, 0x4);
  466. fgret = 1;
  467. } else {
  468. // set reg = (1024/FM_OUT) * REF_CK * U2_SR_COEF_E60802 / 1000 (round to the nearest digits)
  469. //u4tmp = (((1024 * REF_CK * U2_SR_COEF_E60802) / u4fmout) + 500) / 1000;
  470. u4tmp = (((1024 * 25 * U2_SR_COEF_E60802) / u4fmout) + 500) / 1000;
  471. PHY_LOG("SR calibration value u1SrCalVal = %d\n", (u8)u4tmp);
  472. u3_phy_write_field32(((u32)&info->u2phy_regs_e->usbphyacr5),
  473. E60802_RG_USB20_HSTX_SRCTRL_OFST, E60802_RG_USB20_HSTX_SRCTRL, u4tmp);
  474. }
  475. return fgret;
  476. }
  477. #endif