715-01-v6.2-net-fman-memac-Add-serdes-support.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. From affa013f494486079c3c5ad2d00cebc41a3d7445 Mon Sep 17 00:00:00 2001
  2. From: Sean Anderson <[email protected]>
  3. Date: Mon, 17 Oct 2022 16:22:36 -0400
  4. Subject: [PATCH 01/21] net: fman: memac: Add serdes support
  5. This adds support for using a serdes which has to be configured. This is
  6. primarly in preparation for phylink conversion, which will then change the
  7. serdes mode dynamically.
  8. Signed-off-by: Sean Anderson <[email protected]>
  9. Signed-off-by: David S. Miller <[email protected]>
  10. ---
  11. .../net/ethernet/freescale/fman/fman_memac.c | 49 ++++++++++++++++++-
  12. 1 file changed, 47 insertions(+), 2 deletions(-)
  13. --- a/drivers/net/ethernet/freescale/fman/fman_memac.c
  14. +++ b/drivers/net/ethernet/freescale/fman/fman_memac.c
  15. @@ -13,6 +13,7 @@
  16. #include <linux/io.h>
  17. #include <linux/phy.h>
  18. #include <linux/phy_fixed.h>
  19. +#include <linux/phy/phy.h>
  20. #include <linux/of_mdio.h>
  21. /* PCS registers */
  22. @@ -324,6 +325,7 @@ struct fman_mac {
  23. void *fm;
  24. struct fman_rev_info fm_rev_info;
  25. bool basex_if;
  26. + struct phy *serdes;
  27. struct phy_device *pcsphy;
  28. bool allmulti_enabled;
  29. };
  30. @@ -1203,17 +1205,56 @@ int memac_initialization(struct mac_devi
  31. }
  32. }
  33. + memac->serdes = devm_of_phy_get(mac_dev->dev, mac_node, "serdes");
  34. + err = PTR_ERR(memac->serdes);
  35. + if (err == -ENODEV || err == -ENOSYS) {
  36. + dev_dbg(mac_dev->dev, "could not get (optional) serdes\n");
  37. + memac->serdes = NULL;
  38. + } else if (IS_ERR(memac->serdes)) {
  39. + dev_err_probe(mac_dev->dev, err, "could not get serdes\n");
  40. + goto _return_fm_mac_free;
  41. + } else {
  42. + err = phy_init(memac->serdes);
  43. + if (err) {
  44. + dev_err_probe(mac_dev->dev, err,
  45. + "could not initialize serdes\n");
  46. + goto _return_fm_mac_free;
  47. + }
  48. +
  49. + err = phy_power_on(memac->serdes);
  50. + if (err) {
  51. + dev_err_probe(mac_dev->dev, err,
  52. + "could not power on serdes\n");
  53. + goto _return_phy_exit;
  54. + }
  55. +
  56. + if (memac->phy_if == PHY_INTERFACE_MODE_SGMII ||
  57. + memac->phy_if == PHY_INTERFACE_MODE_1000BASEX ||
  58. + memac->phy_if == PHY_INTERFACE_MODE_2500BASEX ||
  59. + memac->phy_if == PHY_INTERFACE_MODE_QSGMII ||
  60. + memac->phy_if == PHY_INTERFACE_MODE_XGMII) {
  61. + err = phy_set_mode_ext(memac->serdes, PHY_MODE_ETHERNET,
  62. + memac->phy_if);
  63. + if (err) {
  64. + dev_err_probe(mac_dev->dev, err,
  65. + "could not set serdes mode to %s\n",
  66. + phy_modes(memac->phy_if));
  67. + goto _return_phy_power_off;
  68. + }
  69. + }
  70. + }
  71. +
  72. if (!mac_dev->phy_node && of_phy_is_fixed_link(mac_node)) {
  73. struct phy_device *phy;
  74. err = of_phy_register_fixed_link(mac_node);
  75. if (err)
  76. - goto _return_fm_mac_free;
  77. + goto _return_phy_power_off;
  78. fixed_link = kzalloc(sizeof(*fixed_link), GFP_KERNEL);
  79. if (!fixed_link) {
  80. err = -ENOMEM;
  81. - goto _return_fm_mac_free;
  82. + goto _return_phy_power_off;
  83. }
  84. mac_dev->phy_node = of_node_get(mac_node);
  85. @@ -1242,6 +1283,10 @@ int memac_initialization(struct mac_devi
  86. goto _return;
  87. +_return_phy_power_off:
  88. + phy_power_off(memac->serdes);
  89. +_return_phy_exit:
  90. + phy_exit(memac->serdes);
  91. _return_fixed_link_free:
  92. kfree(fixed_link);
  93. _return_fm_mac_free: