net: dsa: microchip: Add suspend/resume support to KSZ DSA driver
PATCH 1/1 net: dsa: microchip: Add suspend/resume support to KSZ DSA driver
From: Tristram Ha <[email protected]>
The KSZ DSA driver starts a timer to read MIB counters periodically to avoid count overrun. During system suspend this will give an error for not able to write to register as the SPI system returns an error when it is in suspend state. This implementation stops the timer when the system goes into suspend and restarts it when resumed.
--- drivers/net/dsa/microchip/ksz9477_i2c.c | 4 +++ drivers/net/dsa/microchip/ksz_common.c | 37 +++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 2 ++ drivers/net/dsa/microchip/ksz_spi.c | 4 +++ 4 files changed, 47 insertions(+)
drivers/net/dsa/microchip/ksz9477_i2c.c +4 -0
@@ -127,10 +127,14 @@ static const struct of_device_id ksz9477_dt_ids[] = { };MODULE_DEVICE_TABLE (of, ksz9477_dt_ids); +static DEFINE_SIMPLE_DEV_PM_OPS(ksz_i2c_pm_ops, + ksz_switch_suspend, ksz_switch_resume); +static struct i2c_driver ksz9477_i2c_driver = { .driver = { .name ="ksz9477-switch" , .of_match_table = ksz9477_dt_ids, + .pm = &ksz_i2c_pm_ops, }, .probe = ksz9477_i2c_probe, .remove = ksz9477_i2c_remove,
drivers/net/dsa/microchip/ksz_common.c +37 -0
@@ -4586,6 +4586,23 @@ static int ksz_hsr_leave(struct dsa_switch *ds, int port,return 0 ; } +static int ksz_suspend (struct dsa_switch *ds) +{ +struct ksz_device *dev = ds->priv; + +cancel_delayed_work_sync (&dev->mib_read); +return 0 ; +} + +static int ksz_resume (struct dsa_switch *ds) +{ +struct ksz_device *dev = ds->priv; + +if (dev->mib_read_interval) +schedule_delayed_work (&dev->mib_read, dev->mib_read_interval); +return 0 ; +} +static const struct dsa_switch_ops ksz_switch_ops = { .get_tag_protocol = ksz_get_tag_protocol, .connect_tag_protocol = ksz_connect_tag_protocol,
@@ -4626,6 +4643,8 @@ static const struct dsa_switch_ops ksz_switch_ops = { .port_max_mtu = ksz_max_mtu, .get_wol = ksz_get_wol, .set_wol = ksz_set_wol, + .suspend = ksz_suspend, + .resume = ksz_resume, .get_ts_info = ksz_get_ts_info, .port_hwtstamp_get = ksz_hwtstamp_get, .port_hwtstamp_set = ksz_hwtstamp_set,
@@ -5126,6 +5145,24 @@ void ksz_switch_remove(struct ksz_device *dev) }EXPORT_SYMBOL (ksz_switch_remove); +#ifdef CONFIG_PM_SLEEP +int ksz_switch_suspend (struct device *dev) +{ +struct ksz_device *priv =dev_get_drvdata (dev); + +return dsa_switch_suspend (priv->ds); +} +EXPORT_SYMBOL (ksz_switch_suspend); + +int ksz_switch_resume (struct device *dev) +{ +struct ksz_device *priv =dev_get_drvdata (dev); + +return dsa_switch_resume (priv->ds); +} +EXPORT_SYMBOL (ksz_switch_resume); +#endif +MODULE_AUTHOR ("Woojung Huh <[email protected]>" );MODULE_DESCRIPTION ("Microchip KSZ Series Switch DSA Driver" );MODULE_LICENSE ("GPL" );
drivers/net/dsa/microchip/ksz_common.h +2 -0
@@ -444,6 +444,8 @@ struct ksz_dev_ops {struct ksz_device *ksz_switch_alloc (struct device *base,void *priv);int ksz_switch_register (struct ksz_device *dev);void ksz_switch_remove (struct ksz_device *dev); +int ksz_switch_suspend (struct device *dev); +int ksz_switch_resume (struct device *dev);void ksz_init_mib_timer (struct ksz_device *dev);bool ksz_is_port_mac_global_usable (struct dsa_switch *ds,int port);
drivers/net/dsa/microchip/ksz_spi.c +4 -0
@@ -239,10 +239,14 @@ static const struct spi_device_id ksz_spi_ids[] = { };MODULE_DEVICE_TABLE (spi, ksz_spi_ids); +static DEFINE_SIMPLE_DEV_PM_OPS(ksz_spi_pm_ops, + ksz_switch_suspend, ksz_switch_resume); +static struct spi_driver ksz_spi_driver = { .driver = { .name ="ksz-switch" , .of_match_table = ksz_dt_ids, + .pm = &ksz_spi_pm_ops, }, .id_table = ksz_spi_ids, .probe = ksz_spi_probe,
Signature · 1 line
2.34.1
Quoted 9 lines · On Tue, Dec 17, 2024 at 06:03:11PM -0800, [email protected] wrote:
From: Tristram Ha <[email protected]>
The KSZ DSA driver starts a timer to read MIB counters periodically to avoid count overrun. During system suspend this will give an error for not able to write to register as the SPI system returns an error when it is in suspend state. This implementation stops the timer when the system goes into suspend and restarts it when resumed.
Signed-off-by Tristram Ha <[email protected]>
Andrew
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Tue, 17 Dec 2024 18:03:11 -0800 you wrote:
From: Tristram Ha <[email protected]>
The KSZ DSA driver starts a timer to read MIB counters periodically to avoid count overrun. During system suspend this will give an error for not able to write to register as the SPI system returns an error when it is in suspend state. This implementation stops the timer when the system goes into suspend and restarts it when resumed.
[...]
Here is the summary with links:
- [net-next] net: dsa: microchip: Add suspend/resume support to KSZ DSA driver
https://git.kernel.org/netdev/net-next/c/3fc87cb94f5f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html