mediatek-ge.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <linux/bitfield.h>
  3. #include <linux/module.h>
  4. #include <linux/phy.h>
  5. #define MTK_EXT_PAGE_ACCESS 0x1f
  6. #define MTK_PHY_PAGE_STANDARD 0x0000
  7. #define MTK_PHY_PAGE_EXTENDED 0x0001
  8. #define MTK_PHY_PAGE_EXTENDED_2 0x0002
  9. #define MTK_PHY_PAGE_EXTENDED_3 0x0003
  10. #define MTK_PHY_PAGE_EXTENDED_2A30 0x2a30
  11. #define MTK_PHY_PAGE_EXTENDED_52B5 0x52b5
  12. static int mtk_gephy_read_page(struct phy_device *phydev)
  13. {
  14. return __phy_read(phydev, MTK_EXT_PAGE_ACCESS);
  15. }
  16. static int mtk_gephy_write_page(struct phy_device *phydev, int page)
  17. {
  18. return __phy_write(phydev, MTK_EXT_PAGE_ACCESS, page);
  19. }
  20. static void mtk_gephy_config_init(struct phy_device *phydev)
  21. {
  22. /* Enable HW auto downshift */
  23. phy_modify_paged(phydev, MTK_PHY_PAGE_EXTENDED, 0x14, 0, BIT(4));
  24. /* Increase SlvDPSready time */
  25. phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);
  26. __phy_write(phydev, 0x10, 0xafae);
  27. __phy_write(phydev, 0x12, 0x2f);
  28. __phy_write(phydev, 0x10, 0x8fae);
  29. phy_restore_page(phydev, MTK_PHY_PAGE_STANDARD, 0);
  30. /* Adjust 100_mse_threshold */
  31. phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x123, 0xffff);
  32. /* Disable mcc */
  33. phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xa6, 0x300);
  34. }
  35. static int mt7530_phy_config_init(struct phy_device *phydev)
  36. {
  37. mtk_gephy_config_init(phydev);
  38. /* Increase post_update_timer */
  39. phy_write_paged(phydev, MTK_PHY_PAGE_EXTENDED_3, 0x11, 0x4b);
  40. return 0;
  41. }
  42. static int mt7531_phy_config_init(struct phy_device *phydev)
  43. {
  44. mtk_gephy_config_init(phydev);
  45. /* PHY link down power saving enable */
  46. phy_set_bits(phydev, 0x17, BIT(4));
  47. phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, 0xc6, 0x300);
  48. /* Set TX Pair delay selection */
  49. phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x13, 0x404);
  50. phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x14, 0x404);
  51. return 0;
  52. }
  53. static struct phy_driver mtk_gephy_driver[] = {
  54. {
  55. PHY_ID_MATCH_EXACT(0x03a29412),
  56. .name = "MediaTek MT7530 PHY",
  57. .config_init = mt7530_phy_config_init,
  58. /* Interrupts are handled by the switch, not the PHY
  59. * itself.
  60. */
  61. .config_intr = genphy_no_config_intr,
  62. .handle_interrupt = genphy_handle_interrupt_no_ack,
  63. .suspend = genphy_suspend,
  64. .resume = genphy_resume,
  65. .read_page = mtk_gephy_read_page,
  66. .write_page = mtk_gephy_write_page,
  67. },
  68. {
  69. PHY_ID_MATCH_EXACT(0x03a29441),
  70. .name = "MediaTek MT7531 PHY",
  71. .config_init = mt7531_phy_config_init,
  72. /* Interrupts are handled by the switch, not the PHY
  73. * itself.
  74. */
  75. .config_intr = genphy_no_config_intr,
  76. .handle_interrupt = genphy_handle_interrupt_no_ack,
  77. .suspend = genphy_suspend,
  78. .resume = genphy_resume,
  79. .read_page = mtk_gephy_read_page,
  80. .write_page = mtk_gephy_write_page,
  81. },
  82. };
  83. module_phy_driver(mtk_gephy_driver);
  84. static struct mdio_device_id __maybe_unused mtk_gephy_tbl[] = {
  85. { PHY_ID_MATCH_EXACT(0x03a29441) },
  86. { PHY_ID_MATCH_EXACT(0x03a29412) },
  87. { }
  88. };
  89. MODULE_DESCRIPTION("MediaTek Gigabit Ethernet PHY driver");
  90. MODULE_AUTHOR("DENG, Qingfang <dqfext@gmail.com>");
  91. MODULE_LICENSE("GPL");
  92. MODULE_DEVICE_TABLE(mdio, mtk_gephy_tbl);