[1/2] power: sysfs: Add link to wakeup class device.
diff mbox series

Message ID 20190724174355.255314-2-ravisadineni@chromium.org
State New
Headers show
Series
  • Add wakeup_source symlink and update documentation.
Related show

Commit Message

Ravi Chandra Sadineni July 24, 2019, 5:43 p.m. UTC
https://patchwork.kernel.org/patch/11045069/ creates a virtual device
under wakeup class for each wake capable device exposing all related
sysfs attributes. But there isn't a symlink from the actual device
node to these virtual devices. This patch creates a symlink from the
actual device to the corresponding wakeup_source device under wakeup
class.

Signed-off-by: Ravi Chandra Sadineni <ravisadineni@chromium.org>
---
 drivers/base/power/power.h  |  2 ++
 drivers/base/power/sysfs.c  | 25 +++++++++++++++++++++++++
 drivers/base/power/wakeup.c |  2 ++
 3 files changed, 29 insertions(+)

Patch
diff mbox series

diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index c511def48b48..32b0f5c080a9 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -67,6 +67,8 @@  extern void dpm_sysfs_remove(struct device *dev);
 extern void rpm_sysfs_remove(struct device *dev);
 extern int wakeup_sysfs_add(struct device *dev);
 extern void wakeup_sysfs_remove(struct device *dev);
+extern void wakeup_source_sysfs_link_add(struct device *dev);
+extern void wakeup_source_sysfs_link_remove(struct device *dev);
 extern int pm_qos_sysfs_add_resume_latency(struct device *dev);
 extern void pm_qos_sysfs_remove_resume_latency(struct device *dev);
 extern int pm_qos_sysfs_add_flags(struct device *dev);
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index d713738ce796..fbbdb7b16ac5 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -95,6 +95,7 @@ 
 const char power_group_name[] = "power";
 EXPORT_SYMBOL_GPL(power_group_name);
 
+static const char wakeup_source_symlink_name[] = "wakeup_source";
 static const char ctrl_auto[] = "auto";
 static const char ctrl_on[] = "on";
 
@@ -679,6 +680,30 @@  int dpm_sysfs_add(struct device *dev)
 	return rc;
 }
 
+void wakeup_source_sysfs_link_add(struct device *dev)
+{
+	struct wakeup_source *ws;
+	int err;
+
+	ws = dev->power.wakeup;
+	if (ws && ws->dev) {
+		err = sysfs_add_link_to_group(&dev->kobj, power_group_name,
+			&ws->dev->kobj, wakeup_source_symlink_name);
+		if (err) {
+			dev_err(dev,
+				"could not add %s symlink err %d\n",
+				wakeup_source_symlink_name,
+				err);
+		}
+	}
+}
+
+void wakeup_source_sysfs_link_remove(struct device *dev)
+{
+	sysfs_remove_link_from_group(&dev->kobj, power_group_name,
+		wakeup_source_symlink_name);
+}
+
 int wakeup_sysfs_add(struct device *dev)
 {
 	return sysfs_merge_group(&dev->kobj, &pm_wakeup_attr_group);
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index fe779fe13a7f..87dfe401b035 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -270,6 +270,7 @@  static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws)
 	if (dev->power.wakeirq)
 		device_wakeup_attach_irq(dev, dev->power.wakeirq);
 	spin_unlock_irq(&dev->power.lock);
+	wakeup_source_sysfs_link_add(dev);
 	return 0;
 }
 
@@ -391,6 +392,7 @@  static struct wakeup_source *device_wakeup_detach(struct device *dev)
 	ws = dev->power.wakeup;
 	dev->power.wakeup = NULL;
 	spin_unlock_irq(&dev->power.lock);
+	wakeup_source_sysfs_link_remove(dev);
 	return ws;
 }