722-net-phy-aquantia-enable-AQR112-and-AQR412.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. From 5f62951fba63a9f9cfff564209426bdea5fcc371 Mon Sep 17 00:00:00 2001
  2. From: Alex Marginean <alexandru.marginean@nxp.com>
  3. Date: Tue, 27 Aug 2019 15:16:56 +0300
  4. Subject: [PATCH] drivers: net: phy: aquantia: enable AQR112 and AQR412
  5. Adds support for AQR112 and AQR412 which is mostly based on existing code
  6. with the addition of code configuring the protocol on system side.
  7. This allows changing the system side protocol without having to deploy a
  8. different firmware on the PHY.
  9. Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
  10. ---
  11. drivers/net/phy/aquantia_main.c | 88 +++++++++++++++++++++++++++++++++++++++++
  12. 1 file changed, 88 insertions(+)
  13. --- a/drivers/net/phy/aquantia_main.c
  14. +++ b/drivers/net/phy/aquantia_main.c
  15. @@ -24,6 +24,8 @@
  16. #define PHY_ID_AQCS109 0x03a1b5c2
  17. #define PHY_ID_AQR405 0x03a1b4b0
  18. #define PHY_ID_AQR813 0x31c31cb2
  19. +#define PHY_ID_AQR112 0x03a1b662
  20. +#define PHY_ID_AQR412 0x03a1b712
  21. #define MDIO_PHYXS_VEND_IF_STATUS 0xe812
  22. #define MDIO_PHYXS_VEND_IF_STATUS_TYPE_MASK GENMASK(7, 3)
  23. @@ -135,6 +137,29 @@
  24. #define AQR107_OP_IN_PROG_SLEEP 1000
  25. #define AQR107_OP_IN_PROG_TIMEOUT 100000
  26. +/* registers in MDIO_MMD_VEND1 region */
  27. +#define AQUANTIA_VND1_GLOBAL_SC 0x000
  28. +#define AQUANTIA_VND1_GLOBAL_SC_LP BIT(0xb)
  29. +
  30. +/* global start rate, the protocol associated with this speed is used by default
  31. + * on SI.
  32. + */
  33. +#define AQUANTIA_VND1_GSTART_RATE 0x31a
  34. +#define AQUANTIA_VND1_GSTART_RATE_OFF 0
  35. +#define AQUANTIA_VND1_GSTART_RATE_100M 1
  36. +#define AQUANTIA_VND1_GSTART_RATE_1G 2
  37. +#define AQUANTIA_VND1_GSTART_RATE_10G 3
  38. +#define AQUANTIA_VND1_GSTART_RATE_2_5G 4
  39. +#define AQUANTIA_VND1_GSTART_RATE_5G 5
  40. +
  41. +/* SYSCFG registers for 100M, 1G, 2.5G, 5G, 10G */
  42. +#define AQUANTIA_VND1_GSYSCFG_BASE 0x31b
  43. +#define AQUANTIA_VND1_GSYSCFG_100M 0
  44. +#define AQUANTIA_VND1_GSYSCFG_1G 1
  45. +#define AQUANTIA_VND1_GSYSCFG_2_5G 2
  46. +#define AQUANTIA_VND1_GSYSCFG_5G 3
  47. +#define AQUANTIA_VND1_GSYSCFG_10G 4
  48. +
  49. struct aqr107_hw_stat {
  50. const char *name;
  51. int reg;
  52. @@ -266,6 +291,51 @@ static int aqr_config_aneg(struct phy_de
  53. return genphy_c45_check_and_restart_aneg(phydev, changed);
  54. }
  55. +static struct {
  56. + u16 syscfg;
  57. + int cnt;
  58. + u16 start_rate;
  59. +} aquantia_syscfg[PHY_INTERFACE_MODE_MAX] = {
  60. + [PHY_INTERFACE_MODE_SGMII] = {0x04b, AQUANTIA_VND1_GSYSCFG_1G,
  61. + AQUANTIA_VND1_GSTART_RATE_1G},
  62. + [PHY_INTERFACE_MODE_2500BASEX] = {0x144, AQUANTIA_VND1_GSYSCFG_2_5G,
  63. + AQUANTIA_VND1_GSTART_RATE_2_5G},
  64. + [PHY_INTERFACE_MODE_XGMII] = {0x100, AQUANTIA_VND1_GSYSCFG_10G,
  65. + AQUANTIA_VND1_GSTART_RATE_10G},
  66. + [PHY_INTERFACE_MODE_USXGMII] = {0x080, AQUANTIA_VND1_GSYSCFG_10G,
  67. + AQUANTIA_VND1_GSTART_RATE_10G},
  68. +};
  69. +
  70. +/* Sets up protocol on system side before calling aqr_config_aneg */
  71. +static int aqr_config_aneg_set_prot(struct phy_device *phydev)
  72. +{
  73. + int if_type = phydev->interface;
  74. + int i;
  75. +
  76. + if (!aquantia_syscfg[if_type].cnt)
  77. + return 0;
  78. +
  79. + /* set PHY in low power mode so we can configure protocols */
  80. + phy_write_mmd(phydev, MDIO_MMD_VEND1, AQUANTIA_VND1_GLOBAL_SC,
  81. + AQUANTIA_VND1_GLOBAL_SC_LP);
  82. + mdelay(10);
  83. +
  84. + /* set the default rate to enable the SI link */
  85. + phy_write_mmd(phydev, MDIO_MMD_VEND1, AQUANTIA_VND1_GSTART_RATE,
  86. + aquantia_syscfg[if_type].start_rate);
  87. +
  88. + for (i = 0; i <= aquantia_syscfg[if_type].cnt; i++)
  89. + phy_write_mmd(phydev, MDIO_MMD_VEND1,
  90. + AQUANTIA_VND1_GSYSCFG_BASE + i,
  91. + aquantia_syscfg[if_type].syscfg);
  92. +
  93. + /* wake PHY back up */
  94. + phy_write_mmd(phydev, MDIO_MMD_VEND1, AQUANTIA_VND1_GLOBAL_SC, 0);
  95. + mdelay(10);
  96. +
  97. + return aqr_config_aneg(phydev);
  98. +}
  99. +
  100. static int aqr_config_intr(struct phy_device *phydev)
  101. {
  102. bool en = phydev->interrupts == PHY_INTERRUPT_ENABLED;
  103. @@ -825,6 +895,30 @@ static struct phy_driver aqr_driver[] =
  104. .get_stats = aqr107_get_stats,
  105. .link_change_notify = aqr107_link_change_notify,
  106. },
  107. +{
  108. + PHY_ID_MATCH_MODEL(PHY_ID_AQR112),
  109. + .name = "Aquantia AQR112",
  110. + .probe = aqr107_probe,
  111. + .config_aneg = aqr_config_aneg_set_prot,
  112. + .config_intr = aqr_config_intr,
  113. + .handle_interrupt = aqr_handle_interrupt,
  114. + .read_status = aqr107_read_status,
  115. + .get_sset_count = aqr107_get_sset_count,
  116. + .get_strings = aqr107_get_strings,
  117. + .get_stats = aqr107_get_stats,
  118. +},
  119. +{
  120. + PHY_ID_MATCH_MODEL(PHY_ID_AQR412),
  121. + .name = "Aquantia AQR412",
  122. + .probe = aqr107_probe,
  123. + .config_aneg = aqr_config_aneg_set_prot,
  124. + .config_intr = aqr_config_intr,
  125. + .handle_interrupt = aqr_handle_interrupt,
  126. + .read_status = aqr107_read_status,
  127. + .get_sset_count = aqr107_get_sset_count,
  128. + .get_strings = aqr107_get_strings,
  129. + .get_stats = aqr107_get_stats,
  130. +},
  131. };
  132. module_phy_driver(aqr_driver);
  133. @@ -839,6 +933,8 @@ static struct mdio_device_id __maybe_unu
  134. { PHY_ID_MATCH_MODEL(PHY_ID_AQCS109) },
  135. { PHY_ID_MATCH_MODEL(PHY_ID_AQR405) },
  136. { PHY_ID_MATCH_MODEL(PHY_ID_AQR813) },
  137. + { PHY_ID_MATCH_MODEL(PHY_ID_AQR112) },
  138. + { PHY_ID_MATCH_MODEL(PHY_ID_AQR412) },
  139. { }
  140. };