2
0

801-v6.4-06-net-phy-phy_device-Call-into-the-PHY-driver-to-set-L.patch 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. From 684818189b04b095b34964ed4a3ea5249a840eab Mon Sep 17 00:00:00 2001
  2. From: Andrew Lunn <[email protected]>
  3. Date: Mon, 17 Apr 2023 17:17:28 +0200
  4. Subject: [PATCH 6/9] net: phy: phy_device: Call into the PHY driver to set LED
  5. brightness
  6. Linux LEDs can be software controlled via the brightness file in /sys.
  7. LED drivers need to implement a brightness_set function which the core
  8. will call. Implement an intermediary in phy_device, which will call
  9. into the phy driver if it implements the necessary function.
  10. Signed-off-by: Andrew Lunn <[email protected]>
  11. Signed-off-by: Christian Marangi <[email protected]>
  12. Reviewed-by: Florian Fainelli <[email protected]>
  13. Signed-off-by: David S. Miller <[email protected]>
  14. ---
  15. drivers/net/phy/phy_device.c | 15 ++++++++++++---
  16. include/linux/phy.h | 13 +++++++++++++
  17. 2 files changed, 25 insertions(+), 3 deletions(-)
  18. --- a/drivers/net/phy/phy_device.c
  19. +++ b/drivers/net/phy/phy_device.c
  20. @@ -2934,11 +2934,18 @@ static bool phy_drv_supports_irq(struct
  21. return phydrv->config_intr && phydrv->handle_interrupt;
  22. }
  23. -/* Dummy implementation until calls into PHY driver are added */
  24. static int phy_led_set_brightness(struct led_classdev *led_cdev,
  25. enum led_brightness value)
  26. {
  27. - return 0;
  28. + struct phy_led *phyled = to_phy_led(led_cdev);
  29. + struct phy_device *phydev = phyled->phydev;
  30. + int err;
  31. +
  32. + mutex_lock(&phydev->lock);
  33. + err = phydev->drv->led_brightness_set(phydev, phyled->index, value);
  34. + mutex_unlock(&phydev->lock);
  35. +
  36. + return err;
  37. }
  38. static int of_phy_led(struct phy_device *phydev,
  39. @@ -2955,12 +2962,14 @@ static int of_phy_led(struct phy_device
  40. return -ENOMEM;
  41. cdev = &phyled->led_cdev;
  42. + phyled->phydev = phydev;
  43. err = of_property_read_u8(led, "reg", &phyled->index);
  44. if (err)
  45. return err;
  46. - cdev->brightness_set_blocking = phy_led_set_brightness;
  47. + if (phydev->drv->led_brightness_set)
  48. + cdev->brightness_set_blocking = phy_led_set_brightness;
  49. cdev->max_brightness = 1;
  50. init_data.devicename = dev_name(&phydev->mdio.dev);
  51. init_data.fwnode = of_fwnode_handle(led);
  52. --- a/include/linux/phy.h
  53. +++ b/include/linux/phy.h
  54. @@ -765,15 +765,19 @@ struct phy_tdr_config {
  55. * struct phy_led: An LED driven by the PHY
  56. *
  57. * @list: List of LEDs
  58. + * @phydev: PHY this LED is attached to
  59. * @led_cdev: Standard LED class structure
  60. * @index: Number of the LED
  61. */
  62. struct phy_led {
  63. struct list_head list;
  64. + struct phy_device *phydev;
  65. struct led_classdev led_cdev;
  66. u8 index;
  67. };
  68. +#define to_phy_led(d) container_of(d, struct phy_led, led_cdev)
  69. +
  70. /**
  71. * struct phy_driver - Driver structure for a particular PHY type
  72. *
  73. @@ -988,6 +992,15 @@ struct phy_driver {
  74. int (*get_sqi)(struct phy_device *dev);
  75. /** @get_sqi_max: Get the maximum signal quality indication */
  76. int (*get_sqi_max)(struct phy_device *dev);
  77. +
  78. + /**
  79. + * @led_brightness_set: Set a PHY LED brightness. Index
  80. + * indicates which of the PHYs led should be set. Value
  81. + * follows the standard LED class meaning, e.g. LED_OFF,
  82. + * LED_HALF, LED_FULL.
  83. + */
  84. + int (*led_brightness_set)(struct phy_device *dev,
  85. + u8 index, enum led_brightness value);
  86. };
  87. #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
  88. struct phy_driver, mdiodrv)