From 20d58dc7804cc65cc3b5468e838d6788c7c3a1e0 Mon Sep 17 00:00:00 2001 From: Zongmin Zhou Date: Thu, 3 Jul 2025 10:10:17 +0800 Subject: [PATCH] driver core: add pm hook on faux bus Some devices based on faux bus may have to do something during suspend/resume. So add pm hook to let it use its own suspend/resume hooks if had. Signed-off-by: Zongmin Zhou --- drivers/base/faux.c | 33 +++++++++++++++++++++++++++++++++ drivers/usb/usbip/vhci_hcd.c | 2 ++ include/linux/device/faux.h | 2 ++ 3 files changed, 37 insertions(+) diff --git a/drivers/base/faux.c b/drivers/base/faux.c index 407c1d1aad50..cbaf265e9b6c 100644 --- a/drivers/base/faux.c +++ b/drivers/base/faux.c @@ -61,11 +61,44 @@ static void faux_remove(struct device *dev) faux_ops->remove(faux_dev); } +#ifdef CONFIG_PM +static int faux_pm_suspend(struct device *dev, pm_message_t state) +{ + struct faux_object *faux_obj = to_faux_object(dev); + struct faux_device *faux_dev = &faux_obj->faux_dev; + const struct faux_device_ops *faux_ops = faux_obj->faux_ops; + int ret = 0; + + if (faux_ops && faux_ops->suspend) + ret = faux_ops->suspend(faux_dev, state); + + return ret; +} + +static int faux_pm_resume(struct device *dev) +{ + struct faux_object *faux_obj = to_faux_object(dev); + struct faux_device *faux_dev = &faux_obj->faux_dev; + const struct faux_device_ops *faux_ops = faux_obj->faux_ops; + int ret = 0; + + if (faux_ops && faux_ops->suspend) + ret = faux_ops->resume(faux_dev); + + return ret; +} +#else +#define faux_pm_suspend NULL +#define faux_pm_resume NULL +#endif + static const struct bus_type faux_bus_type = { .name = "faux", .match = faux_match, .probe = faux_probe, .remove = faux_remove, + .suspend = faux_pm_suspend, + .resume = faux_pm_resume, }; static struct device_driver faux_driver = { diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c index 4e6d7d23e915..79c026108d7b 100644 --- a/drivers/usb/usbip/vhci_hcd.c +++ b/drivers/usb/usbip/vhci_hcd.c @@ -1483,6 +1483,8 @@ static int vhci_hcd_resume(struct faux_device *fdev) static struct faux_device_ops vhci_driver = { .remove = vhci_hcd_remove, + .suspend = vhci_hcd_suspend, + .resume = vhci_hcd_resume, }; static void del_faux_devices(void) diff --git a/include/linux/device/faux.h b/include/linux/device/faux.h index 9f43c0e46aa4..9dc4b81c672c 100644 --- a/include/linux/device/faux.h +++ b/include/linux/device/faux.h @@ -45,6 +45,8 @@ struct faux_device { struct faux_device_ops { int (*probe)(struct faux_device *faux_dev); void (*remove)(struct faux_device *faux_dev); + int (*suspend)(struct faux_device *faux_dev, pm_message_t state); + int (*resume)(struct faux_device *faux_dev); }; struct faux_device *faux_device_create(const char *name, -- 2.25.1