Commit 3fc87cb9 authored by Tristram Ha's avatar Tristram Ha Committed by Jakub Kicinski
Browse files

net: dsa: microchip: Add suspend/resume support to KSZ DSA driver



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: default avatarTristram Ha <tristram.ha@microchip.com>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20241218020311.70628-1-Tristram.Ha@microchip.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d5872aa2
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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,
+37 −0
Original line number Diff line number Diff line
@@ -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 <Woojung.Huh@microchip.com>");
MODULE_DESCRIPTION("Microchip KSZ Series Switch DSA Driver");
MODULE_LICENSE("GPL");
+2 −0
Original line number Diff line number Diff line
@@ -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);
+4 −0
Original line number Diff line number Diff line
@@ -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,