@@ -1154,6 +1154,24 @@ static int phy_poll_reset(struct phy_device *phydev)
return 0;
}
+static void phy_save_led(struct phy_device *phydev)
+{
+ if (!phydev->use_firmware_led)
+ return;
+
+ if (phydev->drv->get_led_config)
+ phydev->led_config = phydev->drv->get_led_config(phydev);
+}
+
+static void phy_restore_led(struct phy_device *phydev)
+{
+ if (!phydev->use_firmware_led)
+ return;
+
+ if (phydev->drv->set_led_config && phydev->led_config)
+ phydev->drv->set_led_config(phydev, phydev->led_config);
+}
+
int phy_init_hw(struct phy_device *phydev)
{
int ret = 0;
@@ -1463,6 +1481,8 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
if (dev)
netif_carrier_off(phydev->attached_dev);
+ phy_save_led(phydev);
+
/* Do initial configuration here, now that
* we have certain key parameters
* (dev_flags and interface)
@@ -1803,6 +1823,8 @@ int __phy_resume(struct phy_device *phydev)
if (!ret)
phydev->suspended = false;
+ phy_restore_led(phydev);
+
return ret;
}
EXPORT_SYMBOL(__phy_resume);
@@ -657,6 +657,7 @@ struct phy_device {
u32 eee_broken_modes;
bool use_firmware_led;
+ int led_config;
#ifdef CONFIG_LED_TRIGGER_PHY
struct phy_led_trigger *phy_led_triggers;
unsigned int phy_num_led_triggers;
@@ -933,6 +934,9 @@ struct phy_driver {
int (*get_sqi)(struct phy_device *dev);
/** @get_sqi_max: Get the maximum signal quality indication */
int (*get_sqi_max)(struct phy_device *dev);
+
+ int (*get_led_config)(struct phy_device *dev);
+ void (*set_led_config)(struct phy_device *dev, int led_config);
};
#define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
struct phy_driver, mdiodrv)
PHY drivers may set hardcoded LED config in phy_init_hw(), so to preserve the firmware LED after init or system sleep, it needs to be saved before init and be restored after. To do so, create helpers and driver callbacks to access and save LED config for the need. Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com> --- drivers/net/phy/phy_device.c | 22 ++++++++++++++++++++++ include/linux/phy.h | 4 ++++ 2 files changed, 26 insertions(+)