801-v6.4-07-net-phy-marvell-Add-software-control-of-the-LEDs.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. From 2d3960e58ef7c83fe1dbf952f056b9e906cb6df8 Mon Sep 17 00:00:00 2001
  2. From: Andrew Lunn <[email protected]>
  3. Date: Mon, 17 Apr 2023 17:17:29 +0200
  4. Subject: [PATCH 7/9] net: phy: marvell: Add software control of the LEDs
  5. Add a brightness function, so the LEDs can be controlled from
  6. software using the standard Linux LED infrastructure.
  7. Signed-off-by: Andrew Lunn <[email protected]>
  8. Signed-off-by: Christian Marangi <[email protected]>
  9. Reviewed-by: Florian Fainelli <[email protected]>
  10. Signed-off-by: David S. Miller <[email protected]>
  11. ---
  12. drivers/net/phy/marvell.c | 45 ++++++++++++++++++++++++++++++++++-----
  13. 1 file changed, 40 insertions(+), 5 deletions(-)
  14. --- a/drivers/net/phy/marvell.c
  15. +++ b/drivers/net/phy/marvell.c
  16. @@ -144,11 +144,13 @@
  17. /* WOL Event Interrupt Enable */
  18. #define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7)
  19. -/* LED Timer Control Register */
  20. -#define MII_88E1318S_PHY_LED_TCR 0x12
  21. -#define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
  22. -#define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
  23. -#define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
  24. +#define MII_88E1318S_PHY_LED_FUNC 0x10
  25. +#define MII_88E1318S_PHY_LED_FUNC_OFF (0x8)
  26. +#define MII_88E1318S_PHY_LED_FUNC_ON (0x9)
  27. +#define MII_88E1318S_PHY_LED_TCR 0x12
  28. +#define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
  29. +#define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
  30. +#define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
  31. /* Magic Packet MAC address registers */
  32. #define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17
  33. @@ -2832,6 +2834,34 @@ static int marvell_hwmon_probe(struct ph
  34. }
  35. #endif
  36. +static int m88e1318_led_brightness_set(struct phy_device *phydev,
  37. + u8 index, enum led_brightness value)
  38. +{
  39. + int reg;
  40. +
  41. + reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
  42. + MII_88E1318S_PHY_LED_FUNC);
  43. + if (reg < 0)
  44. + return reg;
  45. +
  46. + switch (index) {
  47. + case 0:
  48. + case 1:
  49. + case 2:
  50. + reg &= ~(0xf << (4 * index));
  51. + if (value == LED_OFF)
  52. + reg |= MII_88E1318S_PHY_LED_FUNC_OFF << (4 * index);
  53. + else
  54. + reg |= MII_88E1318S_PHY_LED_FUNC_ON << (4 * index);
  55. + break;
  56. + default:
  57. + return -EINVAL;
  58. + }
  59. +
  60. + return phy_write_paged(phydev, MII_MARVELL_LED_PAGE,
  61. + MII_88E1318S_PHY_LED_FUNC, reg);
  62. +}
  63. +
  64. static int marvell_probe(struct phy_device *phydev)
  65. {
  66. struct marvell_priv *priv;
  67. @@ -3081,6 +3111,7 @@ static struct phy_driver marvell_drivers
  68. .get_sset_count = marvell_get_sset_count,
  69. .get_strings = marvell_get_strings,
  70. .get_stats = marvell_get_stats,
  71. + .led_brightness_set = m88e1318_led_brightness_set,
  72. },
  73. {
  74. .phy_id = MARVELL_PHY_ID_88E1145,
  75. @@ -3187,6 +3218,7 @@ static struct phy_driver marvell_drivers
  76. .cable_test_start = marvell_vct7_cable_test_start,
  77. .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
  78. .cable_test_get_status = marvell_vct7_cable_test_get_status,
  79. + .led_brightness_set = m88e1318_led_brightness_set,
  80. },
  81. {
  82. .phy_id = MARVELL_PHY_ID_88E1540,
  83. @@ -3213,6 +3245,7 @@ static struct phy_driver marvell_drivers
  84. .cable_test_start = marvell_vct7_cable_test_start,
  85. .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
  86. .cable_test_get_status = marvell_vct7_cable_test_get_status,
  87. + .led_brightness_set = m88e1318_led_brightness_set,
  88. },
  89. {
  90. .phy_id = MARVELL_PHY_ID_88E1545,
  91. @@ -3239,6 +3272,7 @@ static struct phy_driver marvell_drivers
  92. .cable_test_start = marvell_vct7_cable_test_start,
  93. .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
  94. .cable_test_get_status = marvell_vct7_cable_test_get_status,
  95. + .led_brightness_set = m88e1318_led_brightness_set,
  96. },
  97. {
  98. .phy_id = MARVELL_PHY_ID_88E3016,
  99. @@ -3380,6 +3414,7 @@ static struct phy_driver marvell_drivers
  100. .get_stats = marvell_get_stats,
  101. .get_tunable = m88e1540_get_tunable,
  102. .set_tunable = m88e1540_set_tunable,
  103. + .led_brightness_set = m88e1318_led_brightness_set,
  104. },
  105. };