2
0

734-v6.8-net-phy-mediatek-ge-soc-sync-driver-with-MediaTek-SD.patch 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. From f2195279c234c0f618946424b8236026126bc595 Mon Sep 17 00:00:00 2001
  2. Message-ID: <f2195279c234c0f618946424b8236026126bc595.1706071311.git.daniel@makrotopia.org>
  3. From: Daniel Golle <[email protected]>
  4. Date: Wed, 24 Jan 2024 02:27:04 +0000
  5. Subject: [PATCH net] net: phy: mediatek-ge-soc: sync driver with MediaTek SDK
  6. To: Daniel Golle <[email protected]>,
  7. Qingfang Deng <[email protected]>,
  8. SkyLake Huang <[email protected]>,
  9. Andrew Lunn <[email protected]>,
  10. Heiner Kallweit <[email protected]>,
  11. Russell King <[email protected]>,
  12. David S. Miller <[email protected]>,
  13. Eric Dumazet <[email protected]>,
  14. Jakub Kicinski <[email protected]>,
  15. Paolo Abeni <[email protected]>,
  16. Matthias Brugger <[email protected]>,
  17. AngeloGioacchino Del Regno <[email protected]>,
  18. [email protected],
  19. [email protected],
  20. [email protected],
  21. [email protected]
  22. Sync initialization and calibration routines with MediaTek's reference
  23. driver. Improves compliance and resolves link stability issues with
  24. CH340 IoT devices connected to MT798x built-in PHYs.
  25. Fixes: 98c485eaf509 ("net: phy: add driver for MediaTek SoC built-in GE PHYs")
  26. Signed-off-by: Daniel Golle <[email protected]>
  27. ---
  28. drivers/net/phy/mediatek-ge-soc.c | 147 ++++++++++++++++--------------
  29. 1 file changed, 81 insertions(+), 66 deletions(-)
  30. --- a/drivers/net/phy/mediatek-ge-soc.c
  31. +++ b/drivers/net/phy/mediatek-ge-soc.c
  32. @@ -491,7 +491,7 @@ static int tx_r50_fill_result(struct phy
  33. u16 reg, val;
  34. if (phydev->drv->phy_id == MTK_GPHY_ID_MT7988)
  35. - bias = -2;
  36. + bias = -1;
  37. val = clamp_val(bias + tx_r50_cal_val, 0, 63);
  38. @@ -707,6 +707,11 @@ restore:
  39. static void mt798x_phy_common_finetune(struct phy_device *phydev)
  40. {
  41. phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);
  42. + /* SlvDSPreadyTime = 24, MasDSPreadyTime = 24 */
  43. + __phy_write(phydev, 0x11, 0xc71);
  44. + __phy_write(phydev, 0x12, 0xc);
  45. + __phy_write(phydev, 0x10, 0x8fae);
  46. +
  47. /* EnabRandUpdTrig = 1 */
  48. __phy_write(phydev, 0x11, 0x2f00);
  49. __phy_write(phydev, 0x12, 0xe);
  50. @@ -717,15 +722,56 @@ static void mt798x_phy_common_finetune(s
  51. __phy_write(phydev, 0x12, 0x0);
  52. __phy_write(phydev, 0x10, 0x83aa);
  53. - /* TrFreeze = 0 */
  54. + /* FfeUpdGainForce = 1(Enable), FfeUpdGainForceVal = 4 */
  55. + __phy_write(phydev, 0x11, 0x240);
  56. + __phy_write(phydev, 0x12, 0x0);
  57. + __phy_write(phydev, 0x10, 0x9680);
  58. +
  59. + /* TrFreeze = 0 (mt7988 default) */
  60. __phy_write(phydev, 0x11, 0x0);
  61. __phy_write(phydev, 0x12, 0x0);
  62. __phy_write(phydev, 0x10, 0x9686);
  63. + /* SSTrKp100 = 5 */
  64. + /* SSTrKf100 = 6 */
  65. + /* SSTrKp1000Mas = 5 */
  66. + /* SSTrKf1000Mas = 6 */
  67. /* SSTrKp1000Slv = 5 */
  68. + /* SSTrKf1000Slv = 6 */
  69. __phy_write(phydev, 0x11, 0xbaef);
  70. __phy_write(phydev, 0x12, 0x2e);
  71. __phy_write(phydev, 0x10, 0x968c);
  72. + phy_restore_page(phydev, MTK_PHY_PAGE_STANDARD, 0);
  73. +}
  74. +
  75. +static void mt7981_phy_finetune(struct phy_device *phydev)
  76. +{
  77. + u16 val[8] = { 0x01ce, 0x01c1,
  78. + 0x020f, 0x0202,
  79. + 0x03d0, 0x03c0,
  80. + 0x0013, 0x0005 };
  81. + int i, k;
  82. +
  83. + /* 100M eye finetune:
  84. + * Keep middle level of TX MLT3 shapper as default.
  85. + * Only change TX MLT3 overshoot level here.
  86. + */
  87. + for (k = 0, i = 1; i < 12; i++) {
  88. + if (i % 3 == 0)
  89. + continue;
  90. + phy_write_mmd(phydev, MDIO_MMD_VEND1, i, val[k++]);
  91. + }
  92. +
  93. + phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);
  94. + /* ResetSyncOffset = 6 */
  95. + __phy_write(phydev, 0x11, 0x600);
  96. + __phy_write(phydev, 0x12, 0x0);
  97. + __phy_write(phydev, 0x10, 0x8fc0);
  98. +
  99. + /* VgaDecRate = 1 */
  100. + __phy_write(phydev, 0x11, 0x4c2a);
  101. + __phy_write(phydev, 0x12, 0x3e);
  102. + __phy_write(phydev, 0x10, 0x8fa4);
  103. /* MrvlTrFix100Kp = 3, MrvlTrFix100Kf = 2,
  104. * MrvlTrFix1000Kp = 3, MrvlTrFix1000Kf = 2
  105. @@ -740,7 +786,7 @@ static void mt798x_phy_common_finetune(s
  106. __phy_write(phydev, 0x10, 0x8ec0);
  107. phy_restore_page(phydev, MTK_PHY_PAGE_STANDARD, 0);
  108. - /* TR_OPEN_LOOP_EN = 1, lpf_x_average = 9*/
  109. + /* TR_OPEN_LOOP_EN = 1, lpf_x_average = 9 */
  110. phy_modify_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DEV1E_REG234,
  111. MTK_PHY_TR_OPEN_LOOP_EN_MASK | MTK_PHY_LPF_X_AVERAGE_MASK,
  112. BIT(0) | FIELD_PREP(MTK_PHY_LPF_X_AVERAGE_MASK, 0x9));
  113. @@ -773,48 +819,6 @@ static void mt798x_phy_common_finetune(s
  114. phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_LDO_OUTPUT_V, 0x2222);
  115. }
  116. -static void mt7981_phy_finetune(struct phy_device *phydev)
  117. -{
  118. - u16 val[8] = { 0x01ce, 0x01c1,
  119. - 0x020f, 0x0202,
  120. - 0x03d0, 0x03c0,
  121. - 0x0013, 0x0005 };
  122. - int i, k;
  123. -
  124. - /* 100M eye finetune:
  125. - * Keep middle level of TX MLT3 shapper as default.
  126. - * Only change TX MLT3 overshoot level here.
  127. - */
  128. - for (k = 0, i = 1; i < 12; i++) {
  129. - if (i % 3 == 0)
  130. - continue;
  131. - phy_write_mmd(phydev, MDIO_MMD_VEND1, i, val[k++]);
  132. - }
  133. -
  134. - phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);
  135. - /* SlvDSPreadyTime = 24, MasDSPreadyTime = 24 */
  136. - __phy_write(phydev, 0x11, 0xc71);
  137. - __phy_write(phydev, 0x12, 0xc);
  138. - __phy_write(phydev, 0x10, 0x8fae);
  139. -
  140. - /* ResetSyncOffset = 6 */
  141. - __phy_write(phydev, 0x11, 0x600);
  142. - __phy_write(phydev, 0x12, 0x0);
  143. - __phy_write(phydev, 0x10, 0x8fc0);
  144. -
  145. - /* VgaDecRate = 1 */
  146. - __phy_write(phydev, 0x11, 0x4c2a);
  147. - __phy_write(phydev, 0x12, 0x3e);
  148. - __phy_write(phydev, 0x10, 0x8fa4);
  149. -
  150. - /* FfeUpdGainForce = 4 */
  151. - __phy_write(phydev, 0x11, 0x240);
  152. - __phy_write(phydev, 0x12, 0x0);
  153. - __phy_write(phydev, 0x10, 0x9680);
  154. -
  155. - phy_restore_page(phydev, MTK_PHY_PAGE_STANDARD, 0);
  156. -}
  157. -
  158. static void mt7988_phy_finetune(struct phy_device *phydev)
  159. {
  160. u16 val[12] = { 0x0187, 0x01cd, 0x01c8, 0x0182,
  161. @@ -829,17 +833,7 @@ static void mt7988_phy_finetune(struct p
  162. /* TCT finetune */
  163. phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_TX_FILTER, 0x5);
  164. - /* Disable TX power saving */
  165. - phy_modify_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RXADC_CTRL_RG7,
  166. - MTK_PHY_DA_AD_BUF_BIAS_LP_MASK, 0x3 << 8);
  167. -
  168. phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);
  169. -
  170. - /* SlvDSPreadyTime = 24, MasDSPreadyTime = 12 */
  171. - __phy_write(phydev, 0x11, 0x671);
  172. - __phy_write(phydev, 0x12, 0xc);
  173. - __phy_write(phydev, 0x10, 0x8fae);
  174. -
  175. /* ResetSyncOffset = 5 */
  176. __phy_write(phydev, 0x11, 0x500);
  177. __phy_write(phydev, 0x12, 0x0);
  178. @@ -847,13 +841,27 @@ static void mt7988_phy_finetune(struct p
  179. /* VgaDecRate is 1 at default on mt7988 */
  180. - phy_restore_page(phydev, MTK_PHY_PAGE_STANDARD, 0);
  181. + /* MrvlTrFix100Kp = 6, MrvlTrFix100Kf = 7,
  182. + * MrvlTrFix1000Kp = 6, MrvlTrFix1000Kf = 7
  183. + */
  184. + __phy_write(phydev, 0x11, 0xb90a);
  185. + __phy_write(phydev, 0x12, 0x6f);
  186. + __phy_write(phydev, 0x10, 0x8f82);
  187. +
  188. + /* RemAckCntLimitCtrl = 1 */
  189. + __phy_write(phydev, 0x11, 0xfbba);
  190. + __phy_write(phydev, 0x12, 0xc3);
  191. + __phy_write(phydev, 0x10, 0x87f8);
  192. - phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_2A30);
  193. - /* TxClkOffset = 2 */
  194. - __phy_modify(phydev, MTK_PHY_ANARG_RG, MTK_PHY_TCLKOFFSET_MASK,
  195. - FIELD_PREP(MTK_PHY_TCLKOFFSET_MASK, 0x2));
  196. phy_restore_page(phydev, MTK_PHY_PAGE_STANDARD, 0);
  197. +
  198. + /* TR_OPEN_LOOP_EN = 1, lpf_x_average = 10 */
  199. + phy_modify_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DEV1E_REG234,
  200. + MTK_PHY_TR_OPEN_LOOP_EN_MASK | MTK_PHY_LPF_X_AVERAGE_MASK,
  201. + BIT(0) | FIELD_PREP(MTK_PHY_LPF_X_AVERAGE_MASK, 0xa));
  202. +
  203. + /* rg_tr_lpf_cnt_val = 1023 */
  204. + phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_LPF_CNT_VAL, 0x3ff);
  205. }
  206. static void mt798x_phy_eee(struct phy_device *phydev)
  207. @@ -886,11 +894,11 @@ static void mt798x_phy_eee(struct phy_de
  208. MTK_PHY_LPI_SLV_SEND_TX_EN,
  209. FIELD_PREP(MTK_PHY_LPI_SLV_SEND_TX_TIMER_MASK, 0x120));
  210. - phy_modify_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DEV1E_REG239,
  211. - MTK_PHY_LPI_SEND_LOC_TIMER_MASK |
  212. - MTK_PHY_LPI_TXPCS_LOC_RCV,
  213. - FIELD_PREP(MTK_PHY_LPI_SEND_LOC_TIMER_MASK, 0x117));
  214. + /* Keep MTK_PHY_LPI_SEND_LOC_TIMER as 375 */
  215. + phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DEV1E_REG239,
  216. + MTK_PHY_LPI_TXPCS_LOC_RCV);
  217. + /* This also fixes some IoT issues, such as CH340 */
  218. phy_modify_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_DEV1E_REG2C7,
  219. MTK_PHY_MAX_GAIN_MASK | MTK_PHY_MIN_GAIN_MASK,
  220. FIELD_PREP(MTK_PHY_MAX_GAIN_MASK, 0x8) |
  221. @@ -924,7 +932,7 @@ static void mt798x_phy_eee(struct phy_de
  222. __phy_write(phydev, 0x12, 0x0);
  223. __phy_write(phydev, 0x10, 0x9690);
  224. - /* REG_EEE_st2TrKf1000 = 3 */
  225. + /* REG_EEE_st2TrKf1000 = 2 */
  226. __phy_write(phydev, 0x11, 0x114f);
  227. __phy_write(phydev, 0x12, 0x2);
  228. __phy_write(phydev, 0x10, 0x969a);
  229. @@ -949,7 +957,7 @@ static void mt798x_phy_eee(struct phy_de
  230. __phy_write(phydev, 0x12, 0x0);
  231. __phy_write(phydev, 0x10, 0x96b8);
  232. - /* REGEEE_wake_slv_tr_wait_dfesigdet_en = 1 */
  233. + /* REGEEE_wake_slv_tr_wait_dfesigdet_en = 0 */
  234. __phy_write(phydev, 0x11, 0x1463);
  235. __phy_write(phydev, 0x12, 0x0);
  236. __phy_write(phydev, 0x10, 0x96ca);
  237. @@ -1461,6 +1469,13 @@ static int mt7988_phy_probe(struct phy_d
  238. if (err)
  239. return err;
  240. + /* Disable TX power saving at probing to:
  241. + * 1. Meet common mode compliance test criteria
  242. + * 2. Make sure that TX-VCM calibration works fine
  243. + */
  244. + phy_modify_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_RXADC_CTRL_RG7,
  245. + MTK_PHY_DA_AD_BUF_BIAS_LP_MASK, 0x3 << 8);
  246. +
  247. return mt798x_phy_calibration(phydev);
  248. }