[PATCH 3/21] ACPI / PM: Make acpi_bus_type use driver struct dev_pm_ops callbacks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From: Rafael J. Wysocki <rjw@xxxxxxx>

Modify acpi_bus_type so that it executes PM callbacks provided
by drivers through their struct dev_pm_ops objects, if present,
while still allowing the legacy ACPI PM callbacks to take precedence.
This will make it possible to convert ACPI drivers one by one to
handling PM through struct dev_pm_ops instead of the legacy way.

The code added by this change is temporary and will be removed
when all of the drivers in question have been switched over to
the PM handling based on struct dev_pm_ops.

Signed-off-by: Rafael J. Wysocki <rjw@xxxxxxx>
 drivers/acpi/scan.c |   60 ++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 47 insertions(+), 13 deletions(-)

Index: linux/drivers/acpi/scan.c
--- linux.orig/drivers/acpi/scan.c
+++ linux/drivers/acpi/scan.c
@@ -290,27 +290,61 @@ static void acpi_device_release(struct d
-static int acpi_device_suspend(struct device *dev)
+#define ACPI_DEV_PM_CALLBACK(dev, callback, legacy_cb)		\
+({								\
+	struct acpi_device *__acpi_dev = to_acpi_device(dev);	\
+	struct acpi_driver *__acpi_drv = __acpi_dev->driver;	\
+	struct device_driver *__drv = dev->driver;		\
+	int __ret;						\
+								\
+	if (__acpi_drv && __acpi_drv->ops.legacy_cb)		\
+		__ret = __acpi_drv->ops.legacy_cb(__acpi_dev);	\
+	else if (__drv && __drv->pm && __drv->pm->callback)	\
+		__ret = __drv->pm->callback(dev);		\
+	else							\
+		__ret = 0;					\
+								\
+	__ret;							\
+static int acpi_pm_suspend(struct device *dev)
-	struct acpi_device *acpi_dev = to_acpi_device(dev);
-	struct acpi_driver *acpi_drv = acpi_dev->driver;
+	return ACPI_DEV_PM_CALLBACK(dev, suspend, suspend);
-	if (acpi_drv && acpi_drv->ops.suspend)
-		return acpi_drv->ops.suspend(acpi_dev);
-	return 0;
+static int acpi_pm_resume(struct device *dev)
+	return ACPI_DEV_PM_CALLBACK(dev, resume, resume);
-static int acpi_device_resume(struct device *dev)
+static int acpi_pm_freeze(struct device *dev)
-	struct acpi_device *acpi_dev = to_acpi_device(dev);
-	struct acpi_driver *acpi_drv = acpi_dev->driver;
+	return ACPI_DEV_PM_CALLBACK(dev, freeze, suspend);
-	if (acpi_drv && acpi_drv->ops.resume)
-		return acpi_drv->ops.resume(acpi_dev);
-	return 0;
+static int acpi_pm_thaw(struct device *dev)
+	return ACPI_DEV_PM_CALLBACK(dev, thaw, resume);
+static int acpi_pm_poweroff(struct device *dev)
+	return ACPI_DEV_PM_CALLBACK(dev, poweroff, suspend);
+static int acpi_pm_restore(struct device *dev)
+	return ACPI_DEV_PM_CALLBACK(dev, restore, resume);
-static SIMPLE_DEV_PM_OPS(acpi_bus_pm, acpi_device_suspend, acpi_device_resume);
+static const struct dev_pm_ops acpi_bus_pm = {
+	.suspend = acpi_pm_suspend,
+	.resume = acpi_pm_resume,
+	.freeze = acpi_pm_freeze,
+	.thaw = acpi_pm_thaw,
+	.poweroff = acpi_pm_poweroff,
+	.restore = acpi_pm_restore,
 static int acpi_bus_match(struct device *dev, struct device_driver *drv)

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Other Archives]     [Linux Kernel Newbies]     [Linux Driver Development]     [Linux Kbuild]     [Fedora Kernel]     [Linux Kernel Testers]     [Linux SH]     [Linux Omap]     [Linux Tape]     [Linux Input]     [Linux Kernel Janitors]     [Linux Kernel Packagers]     [Linux Doc]     [Linux Man Pages]     [Linux API]     [Linux Memory Management]     [Linux Modules]     [Linux Standards]     [Kernel Announce]     [Netdev]     [Git]     [Linux PCI]     Linux CAN Development     [Linux I2C]     [Linux RDMA]     [Linux NUMA]     [Netfilter]     [Netfilter Devel]     [SELinux]     [Bugtraq]     [FIO]     [Linux Perf Users]     [Linux Serial]     [Linux PPP]     [Linux ISDN]     [Linux Next]     [Kernel Stable Commits]     [Linux Tip Commits]     [Kernel MM Commits]     [Linux Security Module]     [AutoFS]     [Filesystem Development]     [Ext3 Filesystem]     [Linux bcache]     [Ext4 Filesystem]     [Linux BTRFS]     [Linux CEPH Filesystem]     [Linux XFS]     [XFS]     [Linux NFS]     [Linux CIFS]     [Ecryptfs]     [Linux NILFS]     [Linux Cachefs]     [Reiser FS]     [Initramfs]     [Linux FB Devel]     [Linux OpenGL]     [DRI Devel]     [Fastboot]     [Linux RT Users]     [Linux RT Stable]     [eCos]     [Corosync]     [Linux Clusters]     [LVS Devel]     [Hot Plug]     [Linux Virtualization]     [KVM]     [KVM PPC]     [KVM ia64]     [Linux Containers]     [Linux Hexagon]     [Linux Cgroups]     [Util Linux]     [Wireless]     [Linux Bluetooth]     [Bluez Devel]     [Ethernet Bridging]     [Embedded Linux]     [Barebox]     [Linux MMC]     [Linux IIO]     [Sparse]     [Smatch]     [Linux Arch]     [x86 Platform Driver]     [Linux ACPI]     [Linux IBM ACPI]     [LM Sensors]     [CPU Freq]     [Linux Power Management]     [Linmodems]     [Linux DCCP]     [Linux SCTP]     [ALSA Devel]     [Linux USB]     [Linux PA RISC]     [Linux Samsung SOC]     [MIPS Linux]     [IBM S/390 Linux]     [ARM Linux]     [ARM Kernel]     [ARM MSM]     [Tegra Devel]     [Sparc Linux]     [Linux Security]     [Linux Sound]     [Linux Media]     [Video 4 Linux]     [Linux IRDA Users]     [Linux for the blind]     [Linux RAID]     [Linux ATA RAID]     [Device Mapper]     [Linux SCSI]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Linux IDE]     [Linux SMP]     [Linux AXP]     [Linux Alpha]     [Linux M68K]     [Linux ia64]     [Linux 8086]     [Linux x86_64]     [Linux Config]     [Linux Apps]     [Linux MSDOS]     [Linux X.25]     [Linux Crypto]     [DM Crypt]     [Linux Trace Users]     [Linux Btrace]     [Linux Watchdog]     [Utrace Devel]     [Linux C Programming]     [Linux Assembly]     [Dash]     [DWARVES]     [Hail Devel]     [Linux Kernel Debugger]     [Linux gcc]     [Gcc Help]     [X.Org]     [Wine]

Add to Google Powered by Linux

[Older Kernel Discussion]     [Yosemite National Park Forum]     [Large Format Photos]     [Gimp]     [Yosemite Photos]     [Stuff]