815-v6.4-08-net-phy-phy_device-Call-into-the-PHY-driver-to-set-L.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From 4e901018432e38eab35d2a352661ce4727795be1 Mon Sep 17 00:00:00 2001
  2. From: Andrew Lunn <[email protected]>
  3. Date: Mon, 17 Apr 2023 17:17:30 +0200
  4. Subject: [PATCH 8/9] net: phy: phy_device: Call into the PHY driver to set LED
  5. blinking
  6. Linux LEDs can be requested to perform hardware accelerated
  7. blinking. Pass this to the PHY driver, if it implements the op.
  8. Signed-off-by: Andrew Lunn <[email protected]>
  9. Signed-off-by: Christian Marangi <[email protected]>
  10. Reviewed-by: Florian Fainelli <[email protected]>
  11. Signed-off-by: David S. Miller <[email protected]>
  12. ---
  13. drivers/net/phy/phy_device.c | 18 ++++++++++++++++++
  14. include/linux/phy.h | 12 ++++++++++++
  15. 2 files changed, 30 insertions(+)
  16. --- a/drivers/net/phy/phy_device.c
  17. +++ b/drivers/net/phy/phy_device.c
  18. @@ -2959,6 +2959,22 @@ static int phy_led_set_brightness(struct
  19. return err;
  20. }
  21. +static int phy_led_blink_set(struct led_classdev *led_cdev,
  22. + unsigned long *delay_on,
  23. + unsigned long *delay_off)
  24. +{
  25. + struct phy_led *phyled = to_phy_led(led_cdev);
  26. + struct phy_device *phydev = phyled->phydev;
  27. + int err;
  28. +
  29. + mutex_lock(&phydev->lock);
  30. + err = phydev->drv->led_blink_set(phydev, phyled->index,
  31. + delay_on, delay_off);
  32. + mutex_unlock(&phydev->lock);
  33. +
  34. + return err;
  35. +}
  36. +
  37. static int of_phy_led(struct phy_device *phydev,
  38. struct device_node *led)
  39. {
  40. @@ -2981,6 +2997,8 @@ static int of_phy_led(struct phy_device
  41. if (phydev->drv->led_brightness_set)
  42. cdev->brightness_set_blocking = phy_led_set_brightness;
  43. + if (phydev->drv->led_blink_set)
  44. + cdev->blink_set = phy_led_blink_set;
  45. cdev->max_brightness = 1;
  46. init_data.devicename = dev_name(&phydev->mdio.dev);
  47. init_data.fwnode = of_fwnode_handle(led);
  48. --- a/include/linux/phy.h
  49. +++ b/include/linux/phy.h
  50. @@ -966,6 +966,18 @@ struct phy_driver {
  51. */
  52. int (*led_brightness_set)(struct phy_device *dev,
  53. u8 index, enum led_brightness value);
  54. +
  55. + /**
  56. + * @led_blink_set: Set a PHY LED brightness. Index indicates
  57. + * which of the PHYs led should be configured to blink. Delays
  58. + * are in milliseconds and if both are zero then a sensible
  59. + * default should be chosen. The call should adjust the
  60. + * timings in that case and if it can't match the values
  61. + * specified exactly.
  62. + */
  63. + int (*led_blink_set)(struct phy_device *dev, u8 index,
  64. + unsigned long *delay_on,
  65. + unsigned long *delay_off);
  66. };
  67. #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
  68. struct phy_driver, mdiodrv)