r8169_phy_config.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * r8169_phy_config.c: RealTek 8169/8168/8101 ethernet driver.
  4. *
  5. * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw>
  6. * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
  7. * Copyright (c) a lot of people too. Please respect their work.
  8. *
  9. * See MAINTAINERS file for support contact information.
  10. */
  11. #include <linux/delay.h>
  12. #include <linux/phy.h>
  13. #include "r8169.h"
  14. typedef void (*rtl_phy_cfg_fct)(struct rtl8169_private *tp,
  15. struct phy_device *phydev);
  16. static void r8168d_modify_extpage(struct phy_device *phydev, int extpage,
  17. int reg, u16 mask, u16 val)
  18. {
  19. int oldpage = phy_select_page(phydev, 0x0007);
  20. __phy_write(phydev, 0x1e, extpage);
  21. __phy_modify(phydev, reg, mask, val);
  22. phy_restore_page(phydev, oldpage, 0);
  23. }
  24. static void r8168d_phy_param(struct phy_device *phydev, u16 parm,
  25. u16 mask, u16 val)
  26. {
  27. int oldpage = phy_select_page(phydev, 0x0005);
  28. __phy_write(phydev, 0x05, parm);
  29. __phy_modify(phydev, 0x06, mask, val);
  30. phy_restore_page(phydev, oldpage, 0);
  31. }
  32. static void r8168g_phy_param(struct phy_device *phydev, u16 parm,
  33. u16 mask, u16 val)
  34. {
  35. int oldpage = phy_select_page(phydev, 0x0a43);
  36. __phy_write(phydev, 0x13, parm);
  37. __phy_modify(phydev, 0x14, mask, val);
  38. phy_restore_page(phydev, oldpage, 0);
  39. }
  40. struct phy_reg {
  41. u16 reg;
  42. u16 val;
  43. };
  44. static void __rtl_writephy_batch(struct phy_device *phydev,
  45. const struct phy_reg *regs, int len)
  46. {
  47. phy_lock_mdio_bus(phydev);
  48. while (len-- > 0) {
  49. __phy_write(phydev, regs->reg, regs->val);
  50. regs++;
  51. }
  52. phy_unlock_mdio_bus(phydev);
  53. }
  54. #define rtl_writephy_batch(p, a) __rtl_writephy_batch(p, a, ARRAY_SIZE(a))
  55. static void rtl8168f_config_eee_phy(struct phy_device *phydev)
  56. {
  57. r8168d_modify_extpage(phydev, 0x0020, 0x15, 0, BIT(8));
  58. r8168d_phy_param(phydev, 0x8b85, 0, BIT(13));
  59. }
  60. static void rtl8168g_config_eee_phy(struct phy_device *phydev)
  61. {
  62. phy_modify_paged(phydev, 0x0a43, 0x11, 0, BIT(4));
  63. }
  64. static void rtl8168h_config_eee_phy(struct phy_device *phydev)
  65. {
  66. rtl8168g_config_eee_phy(phydev);
  67. phy_modify_paged(phydev, 0xa4a, 0x11, 0x0000, 0x0200);
  68. phy_modify_paged(phydev, 0xa42, 0x14, 0x0000, 0x0080);
  69. }
  70. static void rtl8125a_config_eee_phy(struct phy_device *phydev)
  71. {
  72. rtl8168h_config_eee_phy(phydev);
  73. phy_modify_paged(phydev, 0xa6d, 0x12, 0x0001, 0x0000);
  74. phy_modify_paged(phydev, 0xa6d, 0x14, 0x0010, 0x0000);
  75. }
  76. static void rtl8125b_config_eee_phy(struct phy_device *phydev)
  77. {
  78. phy_modify_paged(phydev, 0xa6d, 0x12, 0x0001, 0x0000);
  79. phy_modify_paged(phydev, 0xa6d, 0x14, 0x0010, 0x0000);
  80. phy_modify_paged(phydev, 0xa42, 0x14, 0x0080, 0x0000);
  81. phy_modify_paged(phydev, 0xa4a, 0x11, 0x0200, 0x0000);
  82. }
  83. static void rtl8169s_hw_phy_config(struct rtl8169_private *tp,
  84. struct phy_device *phydev)
  85. {
  86. static const struct phy_reg phy_reg_init[] = {
  87. { 0x1f, 0x0001 },
  88. { 0x06, 0x006e },
  89. { 0x08, 0x0708 },
  90. { 0x15, 0x4000 },
  91. { 0x18, 0x65c7 },
  92. { 0x1f, 0x0001 },
  93. { 0x03, 0x00a1 },
  94. { 0x02, 0x0008 },
  95. { 0x01, 0x0120 },
  96. { 0x00, 0x1000 },
  97. { 0x04, 0x0800 },
  98. { 0x04, 0x0000 },
  99. { 0x03, 0xff41 },
  100. { 0x02, 0xdf60 },
  101. { 0x01, 0x0140 },
  102. { 0x00, 0x0077 },
  103. { 0x04, 0x7800 },
  104. { 0x04, 0x7000 },
  105. { 0x03, 0x802f },
  106. { 0x02, 0x4f02 },
  107. { 0x01, 0x0409 },
  108. { 0x00, 0xf0f9 },
  109. { 0x04, 0x9800 },
  110. { 0x04, 0x9000 },
  111. { 0x03, 0xdf01 },
  112. { 0x02, 0xdf20 },
  113. { 0x01, 0xff95 },
  114. { 0x00, 0xba00 },
  115. { 0x04, 0xa800 },
  116. { 0x04, 0xa000 },
  117. { 0x03, 0xff41 },
  118. { 0x02, 0xdf20 },
  119. { 0x01, 0x0140 },
  120. { 0x00, 0x00bb },
  121. { 0x04, 0xb800 },
  122. { 0x04, 0xb000 },
  123. { 0x03, 0xdf41 },
  124. { 0x02, 0xdc60 },
  125. { 0x01, 0x6340 },
  126. { 0x00, 0x007d },
  127. { 0x04, 0xd800 },
  128. { 0x04, 0xd000 },
  129. { 0x03, 0xdf01 },
  130. { 0x02, 0xdf20 },
  131. { 0x01, 0x100a },
  132. { 0x00, 0xa0ff },
  133. { 0x04, 0xf800 },
  134. { 0x04, 0xf000 },
  135. { 0x1f, 0x0000 },
  136. { 0x0b, 0x0000 },
  137. { 0x00, 0x9200 }
  138. };
  139. rtl_writephy_batch(phydev, phy_reg_init);
  140. }
  141. static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp,
  142. struct phy_device *phydev)
  143. {
  144. phy_write_paged(phydev, 0x0002, 0x01, 0x90d0);
  145. }
  146. static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp,
  147. struct phy_device *phydev)
  148. {
  149. static const struct phy_reg phy_reg_init[] = {
  150. { 0x1f, 0x0001 },
  151. { 0x04, 0x0000 },
  152. { 0x03, 0x00a1 },
  153. { 0x02, 0x0008 },
  154. { 0x01, 0x0120 },
  155. { 0x00, 0x1000 },
  156. { 0x04, 0x0800 },
  157. { 0x04, 0x9000 },
  158. { 0x03, 0x802f },
  159. { 0x02, 0x4f02 },
  160. { 0x01, 0x0409 },
  161. { 0x00, 0xf099 },
  162. { 0x04, 0x9800 },
  163. { 0x04, 0xa000 },
  164. { 0x03, 0xdf01 },
  165. { 0x02, 0xdf20 },
  166. { 0x01, 0xff95 },
  167. { 0x00, 0xba00 },
  168. { 0x04, 0xa800 },
  169. { 0x04, 0xf000 },
  170. { 0x03, 0xdf01 },
  171. { 0x02, 0xdf20 },
  172. { 0x01, 0x101a },
  173. { 0x00, 0xa0ff },
  174. { 0x04, 0xf800 },
  175. { 0x04, 0x0000 },
  176. { 0x1f, 0x0000 },
  177. { 0x1f, 0x0001 },
  178. { 0x10, 0xf41b },
  179. { 0x14, 0xfb54 },
  180. { 0x18, 0xf5c7 },
  181. { 0x1f, 0x0000 },
  182. { 0x1f, 0x0001 },
  183. { 0x17, 0x0cc0 },
  184. { 0x1f, 0x0000 }
  185. };
  186. rtl_writephy_batch(phydev, phy_reg_init);
  187. }
  188. static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp,
  189. struct phy_device *phydev)
  190. {
  191. static const struct phy_reg phy_reg_init[] = {
  192. { 0x1f, 0x0001 },
  193. { 0x04, 0x0000 },
  194. { 0x03, 0x00a1 },
  195. { 0x02, 0x0008 },
  196. { 0x01, 0x0120 },
  197. { 0x00, 0x1000 },
  198. { 0x04, 0x0800 },
  199. { 0x04, 0x9000 },
  200. { 0x03, 0x802f },
  201. { 0x02, 0x4f02 },
  202. { 0x01, 0x0409 },
  203. { 0x00, 0xf099 },
  204. { 0x04, 0x9800 },
  205. { 0x04, 0xa000 },
  206. { 0x03, 0xdf01 },
  207. { 0x02, 0xdf20 },
  208. { 0x01, 0xff95 },
  209. { 0x00, 0xba00 },
  210. { 0x04, 0xa800 },
  211. { 0x04, 0xf000 },
  212. { 0x03, 0xdf01 },
  213. { 0x02, 0xdf20 },
  214. { 0x01, 0x101a },
  215. { 0x00, 0xa0ff },
  216. { 0x04, 0xf800 },
  217. { 0x04, 0x0000 },
  218. { 0x1f, 0x0000 },
  219. { 0x1f, 0x0001 },
  220. { 0x0b, 0x8480 },
  221. { 0x1f, 0x0000 },
  222. { 0x1f, 0x0001 },
  223. { 0x18, 0x67c7 },
  224. { 0x04, 0x2000 },
  225. { 0x03, 0x002f },
  226. { 0x02, 0x4360 },
  227. { 0x01, 0x0109 },
  228. { 0x00, 0x3022 },
  229. { 0x04, 0x2800 },
  230. { 0x1f, 0x0000 },
  231. { 0x1f, 0x0001 },
  232. { 0x17, 0x0cc0 },
  233. { 0x1f, 0x0000 }
  234. };
  235. rtl_writephy_batch(phydev, phy_reg_init);
  236. }
  237. static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp,
  238. struct phy_device *phydev)
  239. {
  240. phy_write(phydev, 0x1f, 0x0001);
  241. phy_set_bits(phydev, 0x16, BIT(0));
  242. phy_write(phydev, 0x10, 0xf41b);
  243. phy_write(phydev, 0x1f, 0x0000);
  244. }
  245. static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp,
  246. struct phy_device *phydev)
  247. {
  248. phy_write_paged(phydev, 0x0001, 0x10, 0xf41b);
  249. }
  250. static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp,
  251. struct phy_device *phydev)
  252. {
  253. phy_write(phydev, 0x1d, 0x0f00);
  254. phy_write_paged(phydev, 0x0002, 0x0c, 0x1ec8);
  255. }
  256. static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp,
  257. struct phy_device *phydev)
  258. {
  259. phy_set_bits(phydev, 0x14, BIT(5));
  260. phy_set_bits(phydev, 0x0d, BIT(5));
  261. phy_write_paged(phydev, 0x0001, 0x1d, 0x3d98);
  262. }
  263. static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp,
  264. struct phy_device *phydev)
  265. {
  266. static const struct phy_reg phy_reg_init[] = {
  267. { 0x1f, 0x0001 },
  268. { 0x12, 0x2300 },
  269. { 0x1f, 0x0002 },
  270. { 0x00, 0x88d4 },
  271. { 0x01, 0x82b1 },
  272. { 0x03, 0x7002 },
  273. { 0x08, 0x9e30 },
  274. { 0x09, 0x01f0 },
  275. { 0x0a, 0x5500 },
  276. { 0x0c, 0x00c8 },
  277. { 0x1f, 0x0003 },
  278. { 0x12, 0xc096 },
  279. { 0x16, 0x000a },
  280. { 0x1f, 0x0000 },
  281. { 0x1f, 0x0000 },
  282. { 0x09, 0x2000 },
  283. { 0x09, 0x0000 }
  284. };
  285. rtl_writephy_batch(phydev, phy_reg_init);
  286. phy_set_bits(phydev, 0x14, BIT(5));
  287. phy_set_bits(phydev, 0x0d, BIT(5));
  288. }
  289. static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp,
  290. struct phy_device *phydev)
  291. {
  292. static const struct phy_reg phy_reg_init[] = {
  293. { 0x1f, 0x0001 },
  294. { 0x12, 0x2300 },
  295. { 0x03, 0x802f },
  296. { 0x02, 0x4f02 },
  297. { 0x01, 0x0409 },
  298. { 0x00, 0xf099 },
  299. { 0x04, 0x9800 },
  300. { 0x04, 0x9000 },
  301. { 0x1d, 0x3d98 },
  302. { 0x1f, 0x0002 },
  303. { 0x0c, 0x7eb8 },
  304. { 0x06, 0x0761 },
  305. { 0x1f, 0x0003 },
  306. { 0x16, 0x0f0a },
  307. { 0x1f, 0x0000 }
  308. };
  309. rtl_writephy_batch(phydev, phy_reg_init);
  310. phy_set_bits(phydev, 0x16, BIT(0));
  311. phy_set_bits(phydev, 0x14, BIT(5));
  312. phy_set_bits(phydev, 0x0d, BIT(5));
  313. }
  314. static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp,
  315. struct phy_device *phydev)
  316. {
  317. static const struct phy_reg phy_reg_init[] = {
  318. { 0x1f, 0x0001 },
  319. { 0x12, 0x2300 },
  320. { 0x1d, 0x3d98 },
  321. { 0x1f, 0x0002 },
  322. { 0x0c, 0x7eb8 },
  323. { 0x06, 0x5461 },
  324. { 0x1f, 0x0003 },
  325. { 0x16, 0x0f0a },
  326. { 0x1f, 0x0000 }
  327. };
  328. rtl_writephy_batch(phydev, phy_reg_init);
  329. phy_set_bits(phydev, 0x16, BIT(0));
  330. phy_set_bits(phydev, 0x14, BIT(5));
  331. phy_set_bits(phydev, 0x0d, BIT(5));
  332. }
  333. static const struct phy_reg rtl8168d_1_phy_reg_init_0[] = {
  334. /* Channel Estimation */
  335. { 0x1f, 0x0001 },
  336. { 0x06, 0x4064 },
  337. { 0x07, 0x2863 },
  338. { 0x08, 0x059c },
  339. { 0x09, 0x26b4 },
  340. { 0x0a, 0x6a19 },
  341. { 0x0b, 0xdcc8 },
  342. { 0x10, 0xf06d },
  343. { 0x14, 0x7f68 },
  344. { 0x18, 0x7fd9 },
  345. { 0x1c, 0xf0ff },
  346. { 0x1d, 0x3d9c },
  347. { 0x1f, 0x0003 },
  348. { 0x12, 0xf49f },
  349. { 0x13, 0x070b },
  350. { 0x1a, 0x05ad },
  351. { 0x14, 0x94c0 },
  352. /*
  353. * Tx Error Issue
  354. * Enhance line driver power
  355. */
  356. { 0x1f, 0x0002 },
  357. { 0x06, 0x5561 },
  358. { 0x1f, 0x0005 },
  359. { 0x05, 0x8332 },
  360. { 0x06, 0x5561 },
  361. /*
  362. * Can not link to 1Gbps with bad cable
  363. * Decrease SNR threshold form 21.07dB to 19.04dB
  364. */
  365. { 0x1f, 0x0001 },
  366. { 0x17, 0x0cc0 },
  367. { 0x1f, 0x0000 },
  368. { 0x0d, 0xf880 }
  369. };
  370. static void rtl8168d_apply_firmware_cond(struct rtl8169_private *tp,
  371. struct phy_device *phydev,
  372. u16 val)
  373. {
  374. u16 reg_val;
  375. phy_write(phydev, 0x1f, 0x0005);
  376. phy_write(phydev, 0x05, 0x001b);
  377. reg_val = phy_read(phydev, 0x06);
  378. phy_write(phydev, 0x1f, 0x0000);
  379. if (reg_val != val)
  380. phydev_warn(phydev, "chipset not ready for firmware\n");
  381. else
  382. r8169_apply_firmware(tp);
  383. }
  384. static void rtl8168d_1_common(struct phy_device *phydev)
  385. {
  386. u16 val;
  387. phy_write_paged(phydev, 0x0002, 0x05, 0x669a);
  388. r8168d_phy_param(phydev, 0x8330, 0xffff, 0x669a);
  389. phy_write(phydev, 0x1f, 0x0002);
  390. val = phy_read(phydev, 0x0d);
  391. if ((val & 0x00ff) != 0x006c) {
  392. static const u16 set[] = {
  393. 0x0065, 0x0066, 0x0067, 0x0068,
  394. 0x0069, 0x006a, 0x006b, 0x006c
  395. };
  396. int i;
  397. val &= 0xff00;
  398. for (i = 0; i < ARRAY_SIZE(set); i++)
  399. phy_write(phydev, 0x0d, val | set[i]);
  400. }
  401. }
  402. static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp,
  403. struct phy_device *phydev)
  404. {
  405. rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_0);
  406. /*
  407. * Rx Error Issue
  408. * Fine Tune Switching regulator parameter
  409. */
  410. phy_write(phydev, 0x1f, 0x0002);
  411. phy_modify(phydev, 0x0b, 0x00ef, 0x0010);
  412. phy_modify(phydev, 0x0c, 0x5d00, 0xa200);
  413. if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
  414. rtl8168d_1_common(phydev);
  415. } else {
  416. phy_write_paged(phydev, 0x0002, 0x05, 0x6662);
  417. r8168d_phy_param(phydev, 0x8330, 0xffff, 0x6662);
  418. }
  419. /* RSET couple improve */
  420. phy_write(phydev, 0x1f, 0x0002);
  421. phy_set_bits(phydev, 0x0d, 0x0300);
  422. phy_set_bits(phydev, 0x0f, 0x0010);
  423. /* Fine tune PLL performance */
  424. phy_write(phydev, 0x1f, 0x0002);
  425. phy_modify(phydev, 0x02, 0x0600, 0x0100);
  426. phy_clear_bits(phydev, 0x03, 0xe000);
  427. phy_write(phydev, 0x1f, 0x0000);
  428. rtl8168d_apply_firmware_cond(tp, phydev, 0xbf00);
  429. }
  430. static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp,
  431. struct phy_device *phydev)
  432. {
  433. rtl_writephy_batch(phydev, rtl8168d_1_phy_reg_init_0);
  434. if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
  435. rtl8168d_1_common(phydev);
  436. } else {
  437. phy_write_paged(phydev, 0x0002, 0x05, 0x2642);
  438. r8168d_phy_param(phydev, 0x8330, 0xffff, 0x2642);
  439. }
  440. /* Fine tune PLL performance */
  441. phy_write(phydev, 0x1f, 0x0002);
  442. phy_modify(phydev, 0x02, 0x0600, 0x0100);
  443. phy_clear_bits(phydev, 0x03, 0xe000);
  444. phy_write(phydev, 0x1f, 0x0000);
  445. /* Switching regulator Slew rate */
  446. phy_modify_paged(phydev, 0x0002, 0x0f, 0x0000, 0x0017);
  447. rtl8168d_apply_firmware_cond(tp, phydev, 0xb300);
  448. }
  449. static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp,
  450. struct phy_device *phydev)
  451. {
  452. phy_write_paged(phydev, 0x0001, 0x17, 0x0cc0);
  453. r8168d_modify_extpage(phydev, 0x002d, 0x18, 0xffff, 0x0040);
  454. phy_set_bits(phydev, 0x0d, BIT(5));
  455. }
  456. static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp,
  457. struct phy_device *phydev)
  458. {
  459. static const struct phy_reg phy_reg_init[] = {
  460. /* Channel estimation fine tune */
  461. { 0x1f, 0x0001 },
  462. { 0x0b, 0x6c20 },
  463. { 0x07, 0x2872 },
  464. { 0x1c, 0xefff },
  465. { 0x1f, 0x0003 },
  466. { 0x14, 0x6420 },
  467. { 0x1f, 0x0000 },
  468. };
  469. r8169_apply_firmware(tp);
  470. /* Enable Delay cap */
  471. r8168d_phy_param(phydev, 0x8b80, 0xffff, 0xc896);
  472. rtl_writephy_batch(phydev, phy_reg_init);
  473. /* Update PFM & 10M TX idle timer */
  474. r8168d_modify_extpage(phydev, 0x002f, 0x15, 0xffff, 0x1919);
  475. r8168d_modify_extpage(phydev, 0x00ac, 0x18, 0xffff, 0x0006);
  476. /* DCO enable for 10M IDLE Power */
  477. r8168d_modify_extpage(phydev, 0x0023, 0x17, 0x0000, 0x0006);
  478. /* For impedance matching */
  479. phy_modify_paged(phydev, 0x0002, 0x08, 0x7f00, 0x8000);
  480. /* PHY auto speed down */
  481. r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0050);
  482. phy_set_bits(phydev, 0x14, BIT(15));
  483. r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001);
  484. r8168d_phy_param(phydev, 0x8b85, 0x2000, 0x0000);
  485. r8168d_modify_extpage(phydev, 0x0020, 0x15, 0x1100, 0x0000);
  486. phy_write_paged(phydev, 0x0006, 0x00, 0x5a00);
  487. phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0000);
  488. }
  489. static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp,
  490. struct phy_device *phydev)
  491. {
  492. r8169_apply_firmware(tp);
  493. /* Enable Delay cap */
  494. r8168d_modify_extpage(phydev, 0x00ac, 0x18, 0xffff, 0x0006);
  495. /* Channel estimation fine tune */
  496. phy_write_paged(phydev, 0x0003, 0x09, 0xa20f);
  497. /* Green Setting */
  498. r8168d_phy_param(phydev, 0x8b5b, 0xffff, 0x9222);
  499. r8168d_phy_param(phydev, 0x8b6d, 0xffff, 0x8000);
  500. r8168d_phy_param(phydev, 0x8b76, 0xffff, 0x8000);
  501. /* For 4-corner performance improve */
  502. phy_write(phydev, 0x1f, 0x0005);
  503. phy_write(phydev, 0x05, 0x8b80);
  504. phy_set_bits(phydev, 0x17, 0x0006);
  505. phy_write(phydev, 0x1f, 0x0000);
  506. /* PHY auto speed down */
  507. r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0010);
  508. phy_set_bits(phydev, 0x14, BIT(15));
  509. /* improve 10M EEE waveform */
  510. r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001);
  511. /* Improve 2-pair detection performance */
  512. r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000);
  513. rtl8168f_config_eee_phy(phydev);
  514. /* Green feature */
  515. phy_write(phydev, 0x1f, 0x0003);
  516. phy_set_bits(phydev, 0x19, BIT(0));
  517. phy_set_bits(phydev, 0x10, BIT(10));
  518. phy_write(phydev, 0x1f, 0x0000);
  519. phy_modify_paged(phydev, 0x0005, 0x01, 0, BIT(8));
  520. }
  521. static void rtl8168f_hw_phy_config(struct rtl8169_private *tp,
  522. struct phy_device *phydev)
  523. {
  524. /* For 4-corner performance improve */
  525. r8168d_phy_param(phydev, 0x8b80, 0x0000, 0x0006);
  526. /* PHY auto speed down */
  527. r8168d_modify_extpage(phydev, 0x002d, 0x18, 0x0000, 0x0010);
  528. phy_set_bits(phydev, 0x14, BIT(15));
  529. /* Improve 10M EEE waveform */
  530. r8168d_phy_param(phydev, 0x8b86, 0x0000, 0x0001);
  531. rtl8168f_config_eee_phy(phydev);
  532. }
  533. static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp,
  534. struct phy_device *phydev)
  535. {
  536. r8169_apply_firmware(tp);
  537. /* Channel estimation fine tune */
  538. phy_write_paged(phydev, 0x0003, 0x09, 0xa20f);
  539. /* Modify green table for giga & fnet */
  540. r8168d_phy_param(phydev, 0x8b55, 0xffff, 0x0000);
  541. r8168d_phy_param(phydev, 0x8b5e, 0xffff, 0x0000);
  542. r8168d_phy_param(phydev, 0x8b67, 0xffff, 0x0000);
  543. r8168d_phy_param(phydev, 0x8b70, 0xffff, 0x0000);
  544. r8168d_modify_extpage(phydev, 0x0078, 0x17, 0xffff, 0x0000);
  545. r8168d_modify_extpage(phydev, 0x0078, 0x19, 0xffff, 0x00fb);
  546. /* Modify green table for 10M */
  547. r8168d_phy_param(phydev, 0x8b79, 0xffff, 0xaa00);
  548. /* Disable hiimpedance detection (RTCT) */
  549. phy_write_paged(phydev, 0x0003, 0x01, 0x328a);
  550. rtl8168f_hw_phy_config(tp, phydev);
  551. /* Improve 2-pair detection performance */
  552. r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000);
  553. }
  554. static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp,
  555. struct phy_device *phydev)
  556. {
  557. r8169_apply_firmware(tp);
  558. rtl8168f_hw_phy_config(tp, phydev);
  559. }
  560. static void rtl8411_hw_phy_config(struct rtl8169_private *tp,
  561. struct phy_device *phydev)
  562. {
  563. r8169_apply_firmware(tp);
  564. rtl8168f_hw_phy_config(tp, phydev);
  565. /* Improve 2-pair detection performance */
  566. r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x4000);
  567. /* Channel estimation fine tune */
  568. phy_write_paged(phydev, 0x0003, 0x09, 0xa20f);
  569. /* Modify green table for giga & fnet */
  570. r8168d_phy_param(phydev, 0x8b55, 0xffff, 0x0000);
  571. r8168d_phy_param(phydev, 0x8b5e, 0xffff, 0x0000);
  572. r8168d_phy_param(phydev, 0x8b67, 0xffff, 0x0000);
  573. r8168d_phy_param(phydev, 0x8b70, 0xffff, 0x0000);
  574. r8168d_modify_extpage(phydev, 0x0078, 0x17, 0xffff, 0x0000);
  575. r8168d_modify_extpage(phydev, 0x0078, 0x19, 0xffff, 0x00aa);
  576. /* Modify green table for 10M */
  577. r8168d_phy_param(phydev, 0x8b79, 0xffff, 0xaa00);
  578. /* Disable hiimpedance detection (RTCT) */
  579. phy_write_paged(phydev, 0x0003, 0x01, 0x328a);
  580. /* Modify green table for giga */
  581. r8168d_phy_param(phydev, 0x8b54, 0x0800, 0x0000);
  582. r8168d_phy_param(phydev, 0x8b5d, 0x0800, 0x0000);
  583. r8168d_phy_param(phydev, 0x8a7c, 0x0100, 0x0000);
  584. r8168d_phy_param(phydev, 0x8a7f, 0x0000, 0x0100);
  585. r8168d_phy_param(phydev, 0x8a82, 0x0100, 0x0000);
  586. r8168d_phy_param(phydev, 0x8a85, 0x0100, 0x0000);
  587. r8168d_phy_param(phydev, 0x8a88, 0x0100, 0x0000);
  588. /* uc same-seed solution */
  589. r8168d_phy_param(phydev, 0x8b85, 0x0000, 0x8000);
  590. /* Green feature */
  591. phy_write(phydev, 0x1f, 0x0003);
  592. phy_clear_bits(phydev, 0x19, BIT(0));
  593. phy_clear_bits(phydev, 0x10, BIT(10));
  594. phy_write(phydev, 0x1f, 0x0000);
  595. }
  596. static void rtl8168g_disable_aldps(struct phy_device *phydev)
  597. {
  598. phy_modify_paged(phydev, 0x0a43, 0x10, BIT(2), 0);
  599. }
  600. static void rtl8168g_enable_gphy_10m(struct phy_device *phydev)
  601. {
  602. phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(11));
  603. }
  604. static void rtl8168g_phy_adjust_10m_aldps(struct phy_device *phydev)
  605. {
  606. phy_modify_paged(phydev, 0x0bcc, 0x14, BIT(8), 0);
  607. phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(7) | BIT(6));
  608. r8168g_phy_param(phydev, 0x8084, 0x6000, 0x0000);
  609. phy_modify_paged(phydev, 0x0a43, 0x10, 0x0000, 0x1003);
  610. }
  611. static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp,
  612. struct phy_device *phydev)
  613. {
  614. int ret;
  615. r8169_apply_firmware(tp);
  616. ret = phy_read_paged(phydev, 0x0a46, 0x10);
  617. if (ret & BIT(8))
  618. phy_modify_paged(phydev, 0x0bcc, 0x12, BIT(15), 0);
  619. else
  620. phy_modify_paged(phydev, 0x0bcc, 0x12, 0, BIT(15));
  621. ret = phy_read_paged(phydev, 0x0a46, 0x13);
  622. if (ret & BIT(8))
  623. phy_modify_paged(phydev, 0x0c41, 0x15, 0, BIT(1));
  624. else
  625. phy_modify_paged(phydev, 0x0c41, 0x15, BIT(1), 0);
  626. /* Enable PHY auto speed down */
  627. phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(3) | BIT(2));
  628. rtl8168g_phy_adjust_10m_aldps(phydev);
  629. /* EEE auto-fallback function */
  630. phy_modify_paged(phydev, 0x0a4b, 0x11, 0, BIT(2));
  631. /* Enable UC LPF tune function */
  632. r8168g_phy_param(phydev, 0x8012, 0x0000, 0x8000);
  633. phy_modify_paged(phydev, 0x0c42, 0x11, BIT(13), BIT(14));
  634. /* Improve SWR Efficiency */
  635. phy_write(phydev, 0x1f, 0x0bcd);
  636. phy_write(phydev, 0x14, 0x5065);
  637. phy_write(phydev, 0x14, 0xd065);
  638. phy_write(phydev, 0x1f, 0x0bc8);
  639. phy_write(phydev, 0x11, 0x5655);
  640. phy_write(phydev, 0x1f, 0x0bcd);
  641. phy_write(phydev, 0x14, 0x1065);
  642. phy_write(phydev, 0x14, 0x9065);
  643. phy_write(phydev, 0x14, 0x1065);
  644. phy_write(phydev, 0x1f, 0x0000);
  645. rtl8168g_disable_aldps(phydev);
  646. rtl8168g_config_eee_phy(phydev);
  647. }
  648. static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp,
  649. struct phy_device *phydev)
  650. {
  651. r8169_apply_firmware(tp);
  652. rtl8168g_config_eee_phy(phydev);
  653. }
  654. static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp,
  655. struct phy_device *phydev)
  656. {
  657. u16 ioffset, rlen;
  658. u32 data;
  659. r8169_apply_firmware(tp);
  660. /* CHIN EST parameter update */
  661. r8168g_phy_param(phydev, 0x808a, 0x003f, 0x000a);
  662. /* enable R-tune & PGA-retune function */
  663. r8168g_phy_param(phydev, 0x0811, 0x0000, 0x0800);
  664. phy_modify_paged(phydev, 0x0a42, 0x16, 0x0000, 0x0002);
  665. rtl8168g_enable_gphy_10m(phydev);
  666. ioffset = rtl8168h_2_get_adc_bias_ioffset(tp);
  667. if (ioffset != 0xffff)
  668. phy_write_paged(phydev, 0x0bcf, 0x16, ioffset);
  669. /* Modify rlen (TX LPF corner frequency) level */
  670. data = phy_read_paged(phydev, 0x0bcd, 0x16);
  671. data &= 0x000f;
  672. rlen = 0;
  673. if (data > 3)
  674. rlen = data - 3;
  675. data = rlen | (rlen << 4) | (rlen << 8) | (rlen << 12);
  676. phy_write_paged(phydev, 0x0bcd, 0x17, data);
  677. /* disable phy pfm mode */
  678. phy_modify_paged(phydev, 0x0a44, 0x11, BIT(7), 0);
  679. /* disable 10m pll off */
  680. phy_modify_paged(phydev, 0x0a43, 0x10, BIT(0), 0);
  681. rtl8168g_disable_aldps(phydev);
  682. rtl8168g_config_eee_phy(phydev);
  683. }
  684. static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp,
  685. struct phy_device *phydev)
  686. {
  687. rtl8168g_phy_adjust_10m_aldps(phydev);
  688. /* Enable UC LPF tune function */
  689. r8168g_phy_param(phydev, 0x8012, 0x0000, 0x8000);
  690. /* Set rg_sel_sdm_rate */
  691. phy_modify_paged(phydev, 0x0c42, 0x11, BIT(13), BIT(14));
  692. /* Channel estimation parameters */
  693. r8168g_phy_param(phydev, 0x80f3, 0xff00, 0x8b00);
  694. r8168g_phy_param(phydev, 0x80f0, 0xff00, 0x3a00);
  695. r8168g_phy_param(phydev, 0x80ef, 0xff00, 0x0500);
  696. r8168g_phy_param(phydev, 0x80f6, 0xff00, 0x6e00);
  697. r8168g_phy_param(phydev, 0x80ec, 0xff00, 0x6800);
  698. r8168g_phy_param(phydev, 0x80ed, 0xff00, 0x7c00);
  699. r8168g_phy_param(phydev, 0x80f2, 0xff00, 0xf400);
  700. r8168g_phy_param(phydev, 0x80f4, 0xff00, 0x8500);
  701. r8168g_phy_param(phydev, 0x8110, 0xff00, 0xa800);
  702. r8168g_phy_param(phydev, 0x810f, 0xff00, 0x1d00);
  703. r8168g_phy_param(phydev, 0x8111, 0xff00, 0xf500);
  704. r8168g_phy_param(phydev, 0x8113, 0xff00, 0x6100);
  705. r8168g_phy_param(phydev, 0x8115, 0xff00, 0x9200);
  706. r8168g_phy_param(phydev, 0x810e, 0xff00, 0x0400);
  707. r8168g_phy_param(phydev, 0x810c, 0xff00, 0x7c00);
  708. r8168g_phy_param(phydev, 0x810b, 0xff00, 0x5a00);
  709. r8168g_phy_param(phydev, 0x80d1, 0xff00, 0xff00);
  710. r8168g_phy_param(phydev, 0x80cd, 0xff00, 0x9e00);
  711. r8168g_phy_param(phydev, 0x80d3, 0xff00, 0x0e00);
  712. r8168g_phy_param(phydev, 0x80d5, 0xff00, 0xca00);
  713. r8168g_phy_param(phydev, 0x80d7, 0xff00, 0x8400);
  714. /* Force PWM-mode */
  715. phy_write(phydev, 0x1f, 0x0bcd);
  716. phy_write(phydev, 0x14, 0x5065);
  717. phy_write(phydev, 0x14, 0xd065);
  718. phy_write(phydev, 0x1f, 0x0bc8);
  719. phy_write(phydev, 0x12, 0x00ed);
  720. phy_write(phydev, 0x1f, 0x0bcd);
  721. phy_write(phydev, 0x14, 0x1065);
  722. phy_write(phydev, 0x14, 0x9065);
  723. phy_write(phydev, 0x14, 0x1065);
  724. phy_write(phydev, 0x1f, 0x0000);
  725. rtl8168g_disable_aldps(phydev);
  726. rtl8168g_config_eee_phy(phydev);
  727. }
  728. static void rtl8117_hw_phy_config(struct rtl8169_private *tp,
  729. struct phy_device *phydev)
  730. {
  731. /* CHN EST parameters adjust - fnet */
  732. r8168g_phy_param(phydev, 0x808e, 0xff00, 0x4800);
  733. r8168g_phy_param(phydev, 0x8090, 0xff00, 0xcc00);
  734. r8168g_phy_param(phydev, 0x8092, 0xff00, 0xb000);
  735. r8168g_phy_param(phydev, 0x8088, 0xff00, 0x6000);
  736. r8168g_phy_param(phydev, 0x808b, 0x3f00, 0x0b00);
  737. r8168g_phy_param(phydev, 0x808d, 0x1f00, 0x0600);
  738. r8168g_phy_param(phydev, 0x808c, 0xff00, 0xb000);
  739. r8168g_phy_param(phydev, 0x80a0, 0xff00, 0x2800);
  740. r8168g_phy_param(phydev, 0x80a2, 0xff00, 0x5000);
  741. r8168g_phy_param(phydev, 0x809b, 0xf800, 0xb000);
  742. r8168g_phy_param(phydev, 0x809a, 0xff00, 0x4b00);
  743. r8168g_phy_param(phydev, 0x809d, 0x3f00, 0x0800);
  744. r8168g_phy_param(phydev, 0x80a1, 0xff00, 0x7000);
  745. r8168g_phy_param(phydev, 0x809f, 0x1f00, 0x0300);
  746. r8168g_phy_param(phydev, 0x809e, 0xff00, 0x8800);
  747. r8168g_phy_param(phydev, 0x80b2, 0xff00, 0x2200);
  748. r8168g_phy_param(phydev, 0x80ad, 0xf800, 0x9800);
  749. r8168g_phy_param(phydev, 0x80af, 0x3f00, 0x0800);
  750. r8168g_phy_param(phydev, 0x80b3, 0xff00, 0x6f00);
  751. r8168g_phy_param(phydev, 0x80b1, 0x1f00, 0x0300);
  752. r8168g_phy_param(phydev, 0x80b0, 0xff00, 0x9300);
  753. r8168g_phy_param(phydev, 0x8011, 0x0000, 0x0800);
  754. rtl8168g_enable_gphy_10m(phydev);
  755. r8168g_phy_param(phydev, 0x8016, 0x0000, 0x0400);
  756. rtl8168g_disable_aldps(phydev);
  757. rtl8168h_config_eee_phy(phydev);
  758. }
  759. static void rtl8102e_hw_phy_config(struct rtl8169_private *tp,
  760. struct phy_device *phydev)
  761. {
  762. static const struct phy_reg phy_reg_init[] = {
  763. { 0x1f, 0x0003 },
  764. { 0x08, 0x441d },
  765. { 0x01, 0x9100 },
  766. { 0x1f, 0x0000 }
  767. };
  768. phy_set_bits(phydev, 0x11, BIT(12));
  769. phy_set_bits(phydev, 0x19, BIT(13));
  770. phy_set_bits(phydev, 0x10, BIT(15));
  771. rtl_writephy_batch(phydev, phy_reg_init);
  772. }
  773. static void rtl8401_hw_phy_config(struct rtl8169_private *tp,
  774. struct phy_device *phydev)
  775. {
  776. phy_set_bits(phydev, 0x11, BIT(12));
  777. phy_modify_paged(phydev, 0x0002, 0x0f, 0x0000, 0x0003);
  778. }
  779. static void rtl8105e_hw_phy_config(struct rtl8169_private *tp,
  780. struct phy_device *phydev)
  781. {
  782. /* Disable ALDPS before ram code */
  783. phy_write(phydev, 0x18, 0x0310);
  784. msleep(100);
  785. r8169_apply_firmware(tp);
  786. phy_write_paged(phydev, 0x0005, 0x1a, 0x0000);
  787. phy_write_paged(phydev, 0x0004, 0x1c, 0x0000);
  788. phy_write_paged(phydev, 0x0001, 0x15, 0x7701);
  789. }
  790. static void rtl8402_hw_phy_config(struct rtl8169_private *tp,
  791. struct phy_device *phydev)
  792. {
  793. /* Disable ALDPS before setting firmware */
  794. phy_write(phydev, 0x18, 0x0310);
  795. msleep(20);
  796. r8169_apply_firmware(tp);
  797. /* EEE setting */
  798. phy_write(phydev, 0x1f, 0x0004);
  799. phy_write(phydev, 0x10, 0x401f);
  800. phy_write(phydev, 0x19, 0x7030);
  801. phy_write(phydev, 0x1f, 0x0000);
  802. }
  803. static void rtl8106e_hw_phy_config(struct rtl8169_private *tp,
  804. struct phy_device *phydev)
  805. {
  806. static const struct phy_reg phy_reg_init[] = {
  807. { 0x1f, 0x0004 },
  808. { 0x10, 0xc07f },
  809. { 0x19, 0x7030 },
  810. { 0x1f, 0x0000 }
  811. };
  812. /* Disable ALDPS before ram code */
  813. phy_write(phydev, 0x18, 0x0310);
  814. msleep(100);
  815. r8169_apply_firmware(tp);
  816. rtl_writephy_batch(phydev, phy_reg_init);
  817. }
  818. static void rtl8125_legacy_force_mode(struct phy_device *phydev)
  819. {
  820. phy_modify_paged(phydev, 0xa5b, 0x12, BIT(15), 0);
  821. }
  822. static void rtl8125a_2_hw_phy_config(struct rtl8169_private *tp,
  823. struct phy_device *phydev)
  824. {
  825. int i;
  826. phy_modify_paged(phydev, 0xad4, 0x17, 0x0000, 0x0010);
  827. phy_modify_paged(phydev, 0xad1, 0x13, 0x03ff, 0x03ff);
  828. phy_modify_paged(phydev, 0xad3, 0x11, 0x003f, 0x0006);
  829. phy_modify_paged(phydev, 0xac0, 0x14, 0x1100, 0x0000);
  830. phy_modify_paged(phydev, 0xacc, 0x10, 0x0003, 0x0002);
  831. phy_modify_paged(phydev, 0xad4, 0x10, 0x00e7, 0x0044);
  832. phy_modify_paged(phydev, 0xac1, 0x12, 0x0080, 0x0000);
  833. phy_modify_paged(phydev, 0xac8, 0x10, 0x0300, 0x0000);
  834. phy_modify_paged(phydev, 0xac5, 0x17, 0x0007, 0x0002);
  835. phy_write_paged(phydev, 0xad4, 0x16, 0x00a8);
  836. phy_write_paged(phydev, 0xac5, 0x16, 0x01ff);
  837. phy_modify_paged(phydev, 0xac8, 0x15, 0x00f0, 0x0030);
  838. phy_write(phydev, 0x1f, 0x0b87);
  839. phy_write(phydev, 0x16, 0x80a2);
  840. phy_write(phydev, 0x17, 0x0153);
  841. phy_write(phydev, 0x16, 0x809c);
  842. phy_write(phydev, 0x17, 0x0153);
  843. phy_write(phydev, 0x1f, 0x0000);
  844. phy_write(phydev, 0x1f, 0x0a43);
  845. phy_write(phydev, 0x13, 0x81B3);
  846. phy_write(phydev, 0x14, 0x0043);
  847. phy_write(phydev, 0x14, 0x00A7);
  848. phy_write(phydev, 0x14, 0x00D6);
  849. phy_write(phydev, 0x14, 0x00EC);
  850. phy_write(phydev, 0x14, 0x00F6);
  851. phy_write(phydev, 0x14, 0x00FB);
  852. phy_write(phydev, 0x14, 0x00FD);
  853. phy_write(phydev, 0x14, 0x00FF);
  854. phy_write(phydev, 0x14, 0x00BB);
  855. phy_write(phydev, 0x14, 0x0058);
  856. phy_write(phydev, 0x14, 0x0029);
  857. phy_write(phydev, 0x14, 0x0013);
  858. phy_write(phydev, 0x14, 0x0009);
  859. phy_write(phydev, 0x14, 0x0004);
  860. phy_write(phydev, 0x14, 0x0002);
  861. for (i = 0; i < 25; i++)
  862. phy_write(phydev, 0x14, 0x0000);
  863. phy_write(phydev, 0x1f, 0x0000);
  864. r8168g_phy_param(phydev, 0x8257, 0xffff, 0x020F);
  865. r8168g_phy_param(phydev, 0x80ea, 0xffff, 0x7843);
  866. r8169_apply_firmware(tp);
  867. phy_modify_paged(phydev, 0xd06, 0x14, 0x0000, 0x2000);
  868. r8168g_phy_param(phydev, 0x81a2, 0x0000, 0x0100);
  869. phy_modify_paged(phydev, 0xb54, 0x16, 0xff00, 0xdb00);
  870. phy_modify_paged(phydev, 0xa45, 0x12, 0x0001, 0x0000);
  871. phy_modify_paged(phydev, 0xa5d, 0x12, 0x0000, 0x0020);
  872. phy_modify_paged(phydev, 0xad4, 0x17, 0x0010, 0x0000);
  873. phy_modify_paged(phydev, 0xa86, 0x15, 0x0001, 0x0000);
  874. rtl8168g_enable_gphy_10m(phydev);
  875. rtl8168g_disable_aldps(phydev);
  876. rtl8125a_config_eee_phy(phydev);
  877. }
  878. static void rtl8125b_hw_phy_config(struct rtl8169_private *tp,
  879. struct phy_device *phydev)
  880. {
  881. r8169_apply_firmware(tp);
  882. phy_modify_paged(phydev, 0xa44, 0x11, 0x0000, 0x0800);
  883. phy_modify_paged(phydev, 0xac4, 0x13, 0x00f0, 0x0090);
  884. phy_modify_paged(phydev, 0xad3, 0x10, 0x0003, 0x0001);
  885. phy_write(phydev, 0x1f, 0x0b87);
  886. phy_write(phydev, 0x16, 0x80f5);
  887. phy_write(phydev, 0x17, 0x760e);
  888. phy_write(phydev, 0x16, 0x8107);
  889. phy_write(phydev, 0x17, 0x360e);
  890. phy_write(phydev, 0x16, 0x8551);
  891. phy_modify(phydev, 0x17, 0xff00, 0x0800);
  892. phy_write(phydev, 0x1f, 0x0000);
  893. phy_modify_paged(phydev, 0xbf0, 0x10, 0xe000, 0xa000);
  894. phy_modify_paged(phydev, 0xbf4, 0x13, 0x0f00, 0x0300);
  895. r8168g_phy_param(phydev, 0x8044, 0xffff, 0x2417);
  896. r8168g_phy_param(phydev, 0x804a, 0xffff, 0x2417);
  897. r8168g_phy_param(phydev, 0x8050, 0xffff, 0x2417);
  898. r8168g_phy_param(phydev, 0x8056, 0xffff, 0x2417);
  899. r8168g_phy_param(phydev, 0x805c, 0xffff, 0x2417);
  900. r8168g_phy_param(phydev, 0x8062, 0xffff, 0x2417);
  901. r8168g_phy_param(phydev, 0x8068, 0xffff, 0x2417);
  902. r8168g_phy_param(phydev, 0x806e, 0xffff, 0x2417);
  903. r8168g_phy_param(phydev, 0x8074, 0xffff, 0x2417);
  904. r8168g_phy_param(phydev, 0x807a, 0xffff, 0x2417);
  905. phy_modify_paged(phydev, 0xa4c, 0x15, 0x0000, 0x0040);
  906. phy_modify_paged(phydev, 0xbf8, 0x12, 0xe000, 0xa000);
  907. rtl8125_legacy_force_mode(phydev);
  908. rtl8168g_disable_aldps(phydev);
  909. rtl8125b_config_eee_phy(phydev);
  910. }
  911. static void rtl8125d_hw_phy_config(struct rtl8169_private *tp,
  912. struct phy_device *phydev)
  913. {
  914. r8169_apply_firmware(tp);
  915. rtl8125_legacy_force_mode(phydev);
  916. rtl8168g_disable_aldps(phydev);
  917. rtl8125b_config_eee_phy(phydev);
  918. }
  919. static void rtl8126a_hw_phy_config(struct rtl8169_private *tp,
  920. struct phy_device *phydev)
  921. {
  922. r8169_apply_firmware(tp);
  923. }
  924. void r8169_hw_phy_config(struct rtl8169_private *tp, struct phy_device *phydev,
  925. enum mac_version ver)
  926. {
  927. static const rtl_phy_cfg_fct phy_configs[] = {
  928. /* PCI devices. */
  929. [RTL_GIGA_MAC_VER_02] = rtl8169s_hw_phy_config,
  930. [RTL_GIGA_MAC_VER_03] = rtl8169s_hw_phy_config,
  931. [RTL_GIGA_MAC_VER_04] = rtl8169sb_hw_phy_config,
  932. [RTL_GIGA_MAC_VER_05] = rtl8169scd_hw_phy_config,
  933. [RTL_GIGA_MAC_VER_06] = rtl8169sce_hw_phy_config,
  934. /* PCI-E devices. */
  935. [RTL_GIGA_MAC_VER_07] = rtl8102e_hw_phy_config,
  936. [RTL_GIGA_MAC_VER_08] = rtl8102e_hw_phy_config,
  937. [RTL_GIGA_MAC_VER_09] = rtl8102e_hw_phy_config,
  938. [RTL_GIGA_MAC_VER_10] = NULL,
  939. [RTL_GIGA_MAC_VER_11] = rtl8168bb_hw_phy_config,
  940. [RTL_GIGA_MAC_VER_14] = rtl8401_hw_phy_config,
  941. [RTL_GIGA_MAC_VER_17] = rtl8168bef_hw_phy_config,
  942. [RTL_GIGA_MAC_VER_18] = rtl8168cp_1_hw_phy_config,
  943. [RTL_GIGA_MAC_VER_19] = rtl8168c_1_hw_phy_config,
  944. [RTL_GIGA_MAC_VER_20] = rtl8168c_2_hw_phy_config,
  945. [RTL_GIGA_MAC_VER_21] = rtl8168c_3_hw_phy_config,
  946. [RTL_GIGA_MAC_VER_22] = rtl8168c_3_hw_phy_config,
  947. [RTL_GIGA_MAC_VER_23] = rtl8168cp_2_hw_phy_config,
  948. [RTL_GIGA_MAC_VER_24] = rtl8168cp_2_hw_phy_config,
  949. [RTL_GIGA_MAC_VER_25] = rtl8168d_1_hw_phy_config,
  950. [RTL_GIGA_MAC_VER_26] = rtl8168d_2_hw_phy_config,
  951. [RTL_GIGA_MAC_VER_28] = rtl8168d_4_hw_phy_config,
  952. [RTL_GIGA_MAC_VER_29] = rtl8105e_hw_phy_config,
  953. [RTL_GIGA_MAC_VER_30] = rtl8105e_hw_phy_config,
  954. [RTL_GIGA_MAC_VER_31] = NULL,
  955. [RTL_GIGA_MAC_VER_32] = rtl8168e_1_hw_phy_config,
  956. [RTL_GIGA_MAC_VER_33] = rtl8168e_1_hw_phy_config,
  957. [RTL_GIGA_MAC_VER_34] = rtl8168e_2_hw_phy_config,
  958. [RTL_GIGA_MAC_VER_35] = rtl8168f_1_hw_phy_config,
  959. [RTL_GIGA_MAC_VER_36] = rtl8168f_2_hw_phy_config,
  960. [RTL_GIGA_MAC_VER_37] = rtl8402_hw_phy_config,
  961. [RTL_GIGA_MAC_VER_38] = rtl8411_hw_phy_config,
  962. [RTL_GIGA_MAC_VER_39] = rtl8106e_hw_phy_config,
  963. [RTL_GIGA_MAC_VER_40] = rtl8168g_1_hw_phy_config,
  964. [RTL_GIGA_MAC_VER_42] = rtl8168g_2_hw_phy_config,
  965. [RTL_GIGA_MAC_VER_43] = rtl8168g_2_hw_phy_config,
  966. [RTL_GIGA_MAC_VER_44] = rtl8168g_2_hw_phy_config,
  967. [RTL_GIGA_MAC_VER_46] = rtl8168h_2_hw_phy_config,
  968. [RTL_GIGA_MAC_VER_48] = rtl8168h_2_hw_phy_config,
  969. [RTL_GIGA_MAC_VER_51] = rtl8168ep_2_hw_phy_config,
  970. [RTL_GIGA_MAC_VER_52] = rtl8117_hw_phy_config,
  971. [RTL_GIGA_MAC_VER_53] = rtl8117_hw_phy_config,
  972. [RTL_GIGA_MAC_VER_61] = rtl8125a_2_hw_phy_config,
  973. [RTL_GIGA_MAC_VER_63] = rtl8125b_hw_phy_config,
  974. [RTL_GIGA_MAC_VER_64] = rtl8125d_hw_phy_config,
  975. [RTL_GIGA_MAC_VER_65] = rtl8126a_hw_phy_config,
  976. [RTL_GIGA_MAC_VER_66] = rtl8126a_hw_phy_config,
  977. };
  978. if (phy_configs[ver])
  979. phy_configs[ver](tp, phydev);
  980. }