Skip to content

Commit 3fc87cb

Browse files
triha2workkuba-moo
authored andcommitted
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: Tristram Ha <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d5872aa commit 3fc87cb

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

drivers/net/dsa/microchip/ksz9477_i2c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,14 @@ static const struct of_device_id ksz9477_dt_ids[] = {
127127
};
128128
MODULE_DEVICE_TABLE(of, ksz9477_dt_ids);
129129

130+
static DEFINE_SIMPLE_DEV_PM_OPS(ksz_i2c_pm_ops,
131+
ksz_switch_suspend, ksz_switch_resume);
132+
130133
static struct i2c_driver ksz9477_i2c_driver = {
131134
.driver = {
132135
.name = "ksz9477-switch",
133136
.of_match_table = ksz9477_dt_ids,
137+
.pm = &ksz_i2c_pm_ops,
134138
},
135139
.probe = ksz9477_i2c_probe,
136140
.remove = ksz9477_i2c_remove,

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4586,6 +4586,23 @@ static int ksz_hsr_leave(struct dsa_switch *ds, int port,
45864586
return 0;
45874587
}
45884588

4589+
static int ksz_suspend(struct dsa_switch *ds)
4590+
{
4591+
struct ksz_device *dev = ds->priv;
4592+
4593+
cancel_delayed_work_sync(&dev->mib_read);
4594+
return 0;
4595+
}
4596+
4597+
static int ksz_resume(struct dsa_switch *ds)
4598+
{
4599+
struct ksz_device *dev = ds->priv;
4600+
4601+
if (dev->mib_read_interval)
4602+
schedule_delayed_work(&dev->mib_read, dev->mib_read_interval);
4603+
return 0;
4604+
}
4605+
45894606
static const struct dsa_switch_ops ksz_switch_ops = {
45904607
.get_tag_protocol = ksz_get_tag_protocol,
45914608
.connect_tag_protocol = ksz_connect_tag_protocol,
@@ -4626,6 +4643,8 @@ static const struct dsa_switch_ops ksz_switch_ops = {
46264643
.port_max_mtu = ksz_max_mtu,
46274644
.get_wol = ksz_get_wol,
46284645
.set_wol = ksz_set_wol,
4646+
.suspend = ksz_suspend,
4647+
.resume = ksz_resume,
46294648
.get_ts_info = ksz_get_ts_info,
46304649
.port_hwtstamp_get = ksz_hwtstamp_get,
46314650
.port_hwtstamp_set = ksz_hwtstamp_set,
@@ -5126,6 +5145,24 @@ void ksz_switch_remove(struct ksz_device *dev)
51265145
}
51275146
EXPORT_SYMBOL(ksz_switch_remove);
51285147

5148+
#ifdef CONFIG_PM_SLEEP
5149+
int ksz_switch_suspend(struct device *dev)
5150+
{
5151+
struct ksz_device *priv = dev_get_drvdata(dev);
5152+
5153+
return dsa_switch_suspend(priv->ds);
5154+
}
5155+
EXPORT_SYMBOL(ksz_switch_suspend);
5156+
5157+
int ksz_switch_resume(struct device *dev)
5158+
{
5159+
struct ksz_device *priv = dev_get_drvdata(dev);
5160+
5161+
return dsa_switch_resume(priv->ds);
5162+
}
5163+
EXPORT_SYMBOL(ksz_switch_resume);
5164+
#endif
5165+
51295166
MODULE_AUTHOR("Woojung Huh <[email protected]>");
51305167
MODULE_DESCRIPTION("Microchip KSZ Series Switch DSA Driver");
51315168
MODULE_LICENSE("GPL");

drivers/net/dsa/microchip/ksz_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ struct ksz_dev_ops {
444444
struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
445445
int ksz_switch_register(struct ksz_device *dev);
446446
void ksz_switch_remove(struct ksz_device *dev);
447+
int ksz_switch_suspend(struct device *dev);
448+
int ksz_switch_resume(struct device *dev);
447449

448450
void ksz_init_mib_timer(struct ksz_device *dev);
449451
bool ksz_is_port_mac_global_usable(struct dsa_switch *ds, int port);

drivers/net/dsa/microchip/ksz_spi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,14 @@ static const struct spi_device_id ksz_spi_ids[] = {
239239
};
240240
MODULE_DEVICE_TABLE(spi, ksz_spi_ids);
241241

242+
static DEFINE_SIMPLE_DEV_PM_OPS(ksz_spi_pm_ops,
243+
ksz_switch_suspend, ksz_switch_resume);
244+
242245
static struct spi_driver ksz_spi_driver = {
243246
.driver = {
244247
.name = "ksz-switch",
245248
.of_match_table = ksz_dt_ids,
249+
.pm = &ksz_spi_pm_ops,
246250
},
247251
.id_table = ksz_spi_ids,
248252
.probe = ksz_spi_probe,

0 commit comments

Comments
 (0)